Lennart Nullstellen Skript

This commit is contained in:
Hanno Reents 2023-12-26 17:59:43 +01:00
commit 66116fa13d
5 changed files with 93 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.sobj
*.sage.py

12
Dockerfile Executable file
View File

@ -0,0 +1,12 @@
# Verwende das SageMath-Image als Basis
FROM sagemath/sagemath:latest
# Setze das Arbeitsverzeichnis im Container
WORKDIR /usr/src/app
RUN chmod -R 777 /usr/src/app
# Kopiere den gesamten Inhalt in das Arbeitsverzeichnis
COPY . .
# Führe das Sage-Skript aus
CMD ["sage nullstellen.sage"]

37
bak-nullstellen.sage Executable file
View File

@ -0,0 +1,37 @@
import os
def coeffGenerator(deg=1):
if deg==1:
return[[1]]
else:
l=[]
p=coeffGenerator(deg-1)
for i in p:
a=i+[1]
b=i+[-1]
l.append(a)
l.append(b)
return l
def polyGenerator(deg=1):
var('x')
l=[]
for p in coeffGenerator(deg):
l.append(sum([b*x^a for (a,b) in enumerate(p)]))
return l
def numericalSolutionsWithSaves(deg=1,batch_sz=10000):
path="polynomials"+str(deg)
if os.path.isfile(path+".sobj") is False:
polynomials=polyGenerator(deg)
save(polynomials,path)
polynomials=load(path)
while len(polynomials)!=0:
solutions=[]
for p in polynomials[:batch_sz]:
solutions.append([s[x].n(20) for s in solve(p,var('x'),solution_dict=True,to_polysolve=True)])
save(solutions,"deg"+str(deg)+""+str(floor(len(polynomials)/batch_sz)))
polynomials=polynomials[batch_sz:]
save(polynomials,path)
numericalSolutionsWithSaves(22,50000)

5
commands.txt Normal file
View File

@ -0,0 +1,5 @@
# BUILD
sudo docker build ./ -t sage-container
# RUN
sudo docker run -v "$(pwd):/usr/src/app" -t -d sage-container

37
nullstellen.sage Executable file
View File

@ -0,0 +1,37 @@
import os
def coeffGenerator(deg=1):
if deg==1:
return[[1]]
else:
l=[]
p=coeffGenerator(deg-1)
for i in p:
a=i+[1]
b=i+[-1]
l.append(a)
l.append(b)
return l
def polyGenerator(deg=1):
var('x')
l=[]
for p in coeffGenerator(deg):
l.append(sum([b*x^a for (a,b) in enumerate(p)]))
return l
def numericalSolutionsWithSaves(deg=1,batch_sz=10000):
path="polynomials"+str(deg)
if os.path.isfile(path+".sobj") is False:
polynomials=polyGenerator(deg)
save(polynomials,path)
polynomials=load(path)
while len(polynomials)!=0:
solutions=[]
for p in polynomials[:batch_sz]:
solutions.append([s[x].n(20) for s in solve(p, var('x'), solution_dict=True, to_polysolve=True) if x in s])
save(solutions,"deg"+str(deg)+""+str(floor(len(polynomials)/batch_sz)))
polynomials=polynomials[batch_sz:]
save(polynomials,path)
numericalSolutionsWithSaves(22,50000)