Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import matplotlib.pyplot as plt
- import fractions
- def p_valuation(p, n):
- if n == 0:
- return math.inf
- result = 0
- while n % p == 0: # Note that "%" is the modulo operation
- n = n / p
- result += 1
- return result
- def p_norm(p, z):
- return p ** (p_valuation(p, z.denominator) - p_valuation(p, z.numerator)) # Note that "**" is exponentiation
- def one_plus_square_approximate(x, N):
- s = 1
- for i in range(1, N + 1):
- numerator = (-1)**(i + 1) * math.factorial(2 * i) * (x ** i)
- denominator = (4 ** i) * (math.factorial(i) ** 2) * (2 * i - 1)
- s += fractions.Fraction(numerator, denominator)
- return s
- for N in range(1, 10):
- approximation = int(one_plus_square_approximate(-8, N))
- square = approximation ** 2
- diff = square + 7
- diff_norm = p_norm(2, diff)
- print("{:15d} & {:15d} & {:15d} & {:15d} & {:15f} \\\\".format(N, approximation, square, diff, diff_norm))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement