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

28 lines
583 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 dedekint import REAL
# mpq for rational numbers
from gmpy2 import mpq
# Theorem 3.1 (4)
# Die Menge {q ∈ Q | q < x} ist eine entscheidbare Menge rationaler Zahlen (Dedekindscher Schnitt)
def sqrt_two(q):
if q <= 0 or q * q < 2: return True
return False
x = REAL(sqrt_two)
print("1.41422 is smaller:", x.smaller(mpq(141422, 100000)))
print("1.41421 is smaller:", x.smaller(mpq(141421, 100000)))
k = 0
n = 1
z = 0
for k in range(100):
if x.smaller(mpq(z, n)):
z = z + 1
else:
print(z, "/", n)
z = (z - 1) * 10
n = n * 10