optimize ux
This commit is contained in:
commit
26118be87f
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -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
|
10
.idea/Computational-Analysis.iml
Normal file
10
.idea/Computational-Analysis.iml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.13 (Computational-Analysis)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
27
.idea/inspectionProfiles/Project_Default.xml
Normal file
27
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="true" level="INFORMATION" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="E302" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N802" />
|
||||||
|
<option value="N806" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredIdentifiers">
|
||||||
|
<list>
|
||||||
|
<option value="dict.*" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13 (The-smell-of-Stars)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (Computational-Analysis)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/Computational-Analysis.iml" filepath="$PROJECT_DIR$/.idea/Computational-Analysis.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
11
chapter-03/binseq/binseq.py
Normal file
11
chapter-03/binseq/binseq.py
Normal file
@ -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
|
20
chapter-03/binseq/main.py
Normal file
20
chapter-03/binseq/main.py
Normal file
@ -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))
|
BIN
chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc
Normal file
BIN
chapter-03/dedekint/__pycache__/dedekint.cpython-313.pyc
Normal file
Binary file not shown.
6
chapter-03/dedekint/dedekint.py
Normal file
6
chapter-03/dedekint/dedekint.py
Normal file
@ -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
|
26
chapter-03/dedekint/main.py
Normal file
26
chapter-03/dedekint/main.py
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user