Computational-Analysis/chapter-03/binseq/main.py
Jan-Niclas Loosen 719f5816e9 init repo
2025-05-07 10:48:37 +02:00

24 lines
553 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from binseq import REAL
from math import isqrt # integer sqrt
# Theorem 3.1 (2)
# Es gibt eine berechenbare Folge (qn)n∈N rationaler Zahlen, die schnell gegen x konvergiert.
# d.h. |x qi| < 2^(i) für alle i ∈ N.
# bin_seq(1/3) = 0.010101...
def one_third(n):
if n == 1: return "."
if n % 2 == 0: return "0"
return "1"
def irrational(n):
if n == 1: return "."
if n != isqrt(n) * isqrt(n): return "1"
return "0"
x = REAL(one_third)
y = REAL(irrational)
print("x: " + x.as_string(50) + "\ny: " + y.as_string(50))