commit 26118be87f0a9b4001c88c3bca7832b3693cf6aa Author: Jan-Niclas Loosen Date: Thu Apr 17 18:08:18 2025 +0200 optimize ux diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Computational-Analysis.iml b/.idea/Computational-Analysis.iml new file mode 100644 index 0000000..8c69470 --- /dev/null +++ b/.idea/Computational-Analysis.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..e084a03 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,27 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..045fd63 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3ae40bc --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/chapter-03/binseq/binseq.py b/chapter-03/binseq/binseq.py new file mode 100644 index 0000000..dea2445 --- /dev/null +++ b/chapter-03/binseq/binseq.py @@ -0,0 +1,11 @@ +from collections.abc import Callable + +class REAL: + def __init__(self, f: Callable[[int], str]) -> None: + self.binseq = f + + def as_string(self, w: int) -> str: + s = "" + for n in range(w): + s += self.binseq(n) + return s \ No newline at end of file diff --git a/chapter-03/binseq/main.py b/chapter-03/binseq/main.py new file mode 100644 index 0000000..b068190 --- /dev/null +++ b/chapter-03/binseq/main.py @@ -0,0 +1,20 @@ +from binseq import REAL +from math import isqrt # integer sqrt + + +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)) \ No newline at end of file diff --git a/chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc b/chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc new file mode 100644 index 0000000..4ab8701 Binary files /dev/null and b/chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc differ diff --git a/chapter-03/dedekint/dedekint.py b/chapter-03/dedekint/dedekint.py new file mode 100644 index 0000000..bb6aadb --- /dev/null +++ b/chapter-03/dedekint/dedekint.py @@ -0,0 +1,6 @@ +from collections.abc import Callable +from gmpy2 import mpq + + +class REAL: + def __init__(self, f: Callable[[mpq], bool]): self.smaller=f \ No newline at end of file diff --git a/chapter-03/dedekint/main.py b/chapter-03/dedekint/main.py new file mode 100644 index 0000000..8944d2c --- /dev/null +++ b/chapter-03/dedekint/main.py @@ -0,0 +1,26 @@ +from dedekint import REAL +# mpq for rational numbers +from gmpy2 import mpq + + +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 \ No newline at end of file