Jan-28-2019, 09:49 PM
import math
import random
def simili(a,b):
r=True
if(len(a.l)!=len(b.l)):
r=False
else:
g=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(len(a.l)):
for j in range(len(b.l)):
if(a.l[i]==b.l[j] and a.p[i]==b.p[j]): g[i]=1
tot=0
for i in g: tot+=i
if(tot!=len(a.l)): r=False
return r
class polinomio():
def __init__(self,p):
self.p=p
def sc(self):
r=self.p[0].pri()
for i in range(1,len(self.p)): r+=self.p[i].den()
return r
class poly:
def __init__(self,l,n,p):
self.n=n
self.p=p
self.l=l
def pri(self):
r=""
h=str(self.n)
if(self.n==1): h=""
if(self.n==-1): h="-"
r=h
for i in range(len(self.l)):
if(self.p[i]==0): r+=""
else:
if(self.p[i]==1): r+=self.l[i]
else: r+=self.l[i]+"<sup>"+str(self.p[i])+"</sup>"
if(self.n==0): r=""
return r
def den(self):
r=""
h=str(self.n)
if(self.n>0): h="+"+str(self.n)
if(self.n==1): h="+"
if(self.n==-1): h="-"
r=h
for i in range(len(self.l)):
if(self.p[i]==0): r+=""
else:
if(self.p[i]==1): r+=self.l[i]
else: r+=self.l[i]+"<sup>"+str(self.p[i])+"</sup>"
if(self.n==0): r=""
return r
def sim(self,n):
return poly(self.l,n,self.p)
def men(mon):
return mono(mon.l,-mon.n,mon.p)
def bino(a,b):
return "("+a.pri()+b.den()+")"
def trino(a,b,c):
return "("+a.pri()+b.den()+c.den()+")"
def po():
return random.randint(2,6)
def nu():
n=(random.randint(1,9))
if(random.randint(0,9999)<5000): n=-n
return n
def let():
l=["a","b","c","d","e","f","g","h","m","n","p","q","r","t","u","v","z"]
return l[random.randint(0,len(l))]
def pp(n):
return "<sup>"+str(n)+"</sup>"
def semplifica(ss):
a=ss.p
j=0
nn=[]
m=[]
for i in range(20):
nn+=[True]
for i in range(len(a)-1):
j+=1
for h in range (j,len(a)-1):
if(simili(a[i],a[h])==True):
a[i].n=a[i].n+a[h].n
a[h]=[]
nn[h]=False
print len(a)
for i in range(len(a)):
if(nn[i]==True): m+=[a[i]]
print len(m)
return polinomio(m)
verifica=open("test.html","w")
c=polinomio([poly(["s"],2,[2]),poly(["s"],2,[2]),poly(["d","m"],3,[1,-1])])
e=polinomio([poly(["s"],2,[2]),poly(["s"],2,[2]),poly(["d","m"],3,[1,-1])])
d=semplifica(e)
verifica.write(e.sc())
verifica.close()Hallo everyoneI'm trying to make a polynomial class and it work, but i tried to make a simplifying the polynomial whit a function and the class stop to work correctly, and i don't understand why....
It's so frustrating
Anyone can help me? Thank you very much...
