Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python3
- # Infinite square root: x = √(q + √(q + √(q + …)))
- # Basic equation: 0 = x² − x − q
- # Higher order equation: 0 = xᵃ − bx − c
- Q_MAX = 6 # highest q to calculate
- EXPONENT_MAX = 6 # highest log₂(a) to calculate
- LINEAR_MAX = 2 ** EXPONENT_MAX
- def exponential_next(q):
- return lambda a, b, c: (2 * a, b**2 + 2 * b * c, q * b**2 + c**2)
- def linear_next(q):
- return lambda a, b, c: (2 + a, b * (q + 1) + c, q * (b + c))
- def single_next(q):
- return lambda a, b, c: (1 + a, b + c, q * b)
- def typeset(a, b, c):
- n = ''.join('⁰¹²³⁴⁵⁶⁷⁸⁹'[ord(d) - ord('0')] for d in str(a))
- return f'0 = x{n} − {b if b != 1 else ""}x − {c}'
- def print_series(q, nsteps, step):
- a = (2, 1, q)
- next_a = step(q)
- while a[0] < nsteps:
- print(typeset(*a))
- a = next_a(*a)
- print(typeset(*a))
- def print_quotient(q):
- print(f'x = √({q} + √({q} + √({q} + …)))')
- print(f'x² = {q} + √({q} + √({q} + …))')
- print()
- for note, step in (('Exponential:', exponential_next),
- ('Linear by 2:', linear_next),
- ('Linear by single step:', single_next)):
- print(note)
- print_series(q, LINEAR_MAX, step)
- for q in range(1, Q_MAX):
- print_quotient(q)
- print()
- print_quotient(Q_MAX)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement