Hello ,
can you explain me what does this function ( class ) do ? - class Doublet:
-
def __init__(self,referenceMonome,refSuiv):
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
def __repr__(self):
-
res=''
-
cour=self
-
while cour!=None:
-
res+=str(cour.refMon)
-
cour=cour.suiv
-
if res[0]=='+':
-
return res[1:]
-
return res
thank you
24 2592
Hello ,
can you explain me what does this function ( class ) do ? - class Doublet:
-
def __init__(self,referenceMonome,refSuiv):
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
def __repr__(self):
-
res=''
-
cour=self
-
while cour!=None:
-
res+=str(cour.refMon)
-
cour=cour.suiv
-
if res[0]=='+':
-
return res[1:]
-
return res
thank you
I don't know French and don't know many who do, and much of this lacks any context, but:
If suiv is "next" then this it looks like this is a linked list of some type and when this object's repr() is called, it returns referenceMonome from each member in the chain. It then removes the "+" from the head of the result.
It would be very helpful if you could translate your posts for us (non-bilingual) experts. Thanks,
Barton
bvdet 2,851
Expert Mod 2GB
Hello ,
can you explain me what does this function ( class ) do ? - class Doublet:
-
def __init__(self,referenceMonome,refSuiv):
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
def __repr__(self):
-
res=''
-
cour=self
-
while cour!=None:
-
res+=str(cour.refMon)
-
cour=cour.suiv
-
if res[0]=='+':
-
return res[1:]
-
return res
thank you
Monome - Monomial? Like Barton, I don't know French.
It looks like the class is accumulating a series of monomials - similar to another of your threads. A monomial is an algebraic expression containing only one term as in:
Just guessing.
Monome - Monomial? Like Barton, I don't know French.
It looks like the class is accumulating a series of monomials - similar to another of your threads. A monomial is an algebraic expression containing only one term as in:
Just guessing.
I thought maybe it's collecting friends. Could be.
Hello
i'm sorry , I had not given many details which could have
helped you to better include/understand my question
here is my problem the framed functions are given
# Polynomials with two variables:
# the choices:
# the monomials which make a polynomial make only this polynomial:
# they do not compose of another polynomial
# if two polynomials contain the same monomial, this monomial exists in two specimens
# the monomials of a polynomial NEVER have null coefficient
__________________________________________________ _______________ -
class Monome: # monome =monomial
-
def __init__(self, coefficient, exposantX, exposantY): #exposant = power
-
self.coeff = coefficient
-
self.expoX = exposantX
-
self.expoY = exposantY
-
def __repr__(self):
-
s=str(self.coeff)+"*x^"+str(self.expoX)+"*y^"+str(self.expoY)
-
if self.coeff<0: return s
-
return "+"+s
-
def __lt__(self, autre): #autre=other
-
return (self.expoX < autre.expoX) or ((self.expoX ==
-
autre.expoX) and (self.expoY < autre.expoY))
-
def __gt__(self,autre):
-
return (self.expoX > autre.expoX) or ((self.expoX ==
-
autre.expoX) and (self.expoY >autre.expoY))
__________________________________________________ _______________
__________________________________________________ _______________ -
class Doublet:
-
def __init__(self,referenceMonome,refSuiv): # suiv=next
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
def __repr__(self):
-
res='' # res=result
-
cour=self # cour = current
-
while cour!=None:
-
res+=str(cour.refMon)
-
cour=cour.suiv
-
if res[0]=='+':
-
return res[1:]
-
return res
__________________________________________________ _______________
__________________________________________________ _______________ -
def degre(mon): #degré = degree
-
return(mon.expoX + mon.expoY)
__________________________________________________ _______________
__________________________________________________ _______________ -
def degreX (mon):
-
return mon.expoX
__________________________________________________ _______________
the functions which follow, I must correct them and/or supplement them -
def insereMonome(coefficient, exposantX, exposantY, doublett) : #insere=insert
-
# to seek the last monomial before this new monomial
-
# to make insertion by creating the monomial which will be placed
-
# placed well for the ascending order "
-
newRefMon = Monome(coefficient, exposantX, exposantY)
-
print "nouveau monome : ",newRefMon
-
# nouveau monome = new monomial
-
return None
-
-
-
def insereCopieMonome( refMon, doublett):
-
#DO NOT modify this function
-
return insereMonome(refMon.coeff, refMon.expoX, refMon.expoY,
-
doublett)
-
-
-
def ajouteDoubletsRec(listeDoublet1, listeDoublet2): #ajoute=add
-
# returns a new list of doublets obtained by
-
# fusion of the two lists in new one
-
# ATTENTION: not to forget to treat the case where two opposite
-
# monomials are added!!!!!
-
# in this case, not to reveal a monomial with a null coefficient.
-
return None
-
-
-
def multMonomeMonome(refMon1, refMon2): #mult=multiply
-
return Monome(refMon1.coeff * refMon2.coeff, refMon1.expoX +
-
refMon2.expoX, refMon1.expoY + refMon2.expoY)
-
def multMonomeListeDoublets(refMon, listeDoublets):
-
res = None
-
return res
-
-
-
def multDeuxListesDoublets(ld1, ld2):
-
# multDeuxListesDoublets = mulitply 2 lists of doublets
-
# doublet = list of monomials
-
res = None
-
return res
-
__________________________________________________ _______________ -
class Polynome: #polynome =polynomial
-
def __init__(self,listePrincipale): #liste pricipale=main list
-
self.lp = listePrincipale
-
self.lDegre = creerListeDegre(listePrincipale) creerListe=create list
-
triDegre(self.lDegre) # tri =sorting
-
-
def __repr__(self):
-
doub = self.lp
-
res = " liste pour l'ordre < \n" #l ist for the order
-
res = res + str(doub)
-
res = res + "\n \n "
-
res = res + " liste pour l'ordre du degré total \n"
-
#list for the order of the total degree
-
doub = self.lDegre
-
res = res + str(doub)
-
return res
__________________________________________________ _______________
__________________________________________________ _______________ -
def creerListeDegre(ld):
-
if ld == None:
-
return None
-
else:
-
return Doublet(ld.refMon, creerListeDegre(ld.suiv))
__________________________________________________ _________________________*__ -
def triDegre(doublett): #tri =sorting
-
# we modify by exchange the values of the fields "refMon"of the listdoublett,
-
# so that the list doublett is increasing for the order of the degree
-
-
return ...
-
-
-
def add(pol1, pol2):
-
return None
-
-
-
def mul(pol1, pol2):
-
return None
-
-
-
-
# END of the definition of the functions and methods
-
# --------------------------------------------------------------
-
#tests on the monomials
-
#m1 = Monome(5,2,6)
-
#m2 = Monome(6,2,8)
-
#m3 = Monome(-4,3,1)
-
#m4 = Monome(-6,0,1)
-
#print "m1 : ",m1, " m2 : ",m2
-
#print "m3 : ",m3, " m4 : ",m4
-
#print m1 < m2
-
#print m3 < m4
-
#print
-
#tests on the doublets
-
#d1 = Doublet(m1,None)
-
#print "doublet d1 : ",d1
-
#doublet1 = Doublet(Monome(-4,7,1),Doublet(Monome(2,4,3),None))
-
#doublet2 = Doublet(m1,Doublet(m2,None))
-
#print
-
#print"doublet1 : ",doublet1, " doublet2 : ",doublet2
-
#print
-
# tests of the function insereMonome
-
#doub1 = insereMonome(5, 2, 6, None)
-
#doub1 = insereMonome(6,3,8, doub1)
-
#doub2 = insereMonome(5,10,3, None)
-
#doub2 = insereMonome(4,2,6, doub2)
-
#doub2 = insereMonome(-3,11,7, doub2)
-
#doub2 = insereMonome(-6, 3,8, doub2)
-
#doub2 = insereMonome(2,3,0, doub2)
-
#print "doub1 : ",doub1
-
#print" doub2 : ",doub2
-
# tests of the function ajouteDoubletsRec
-
#listeAjout = ajouteDoubletsRec(doub1, doub2)
-
#print "sum of 2 lists : ", listeAjout
-
-
-
# tests of the function multMonomeListeDoublets
-
# TESTS TO BE BUILT ( we must write some tests of this
-
# function ( multMonomeListeDoublets)
-
-
# tests of the function multDeuxListesDoublets
-
# TESTS TO BE BUILT ( we must write some tests of this
-
# function ( multDeuxListesDoublets)
-
-
# tests of the function creerListeDegre
-
#TESTS TO BE BUILT ( we must write some tests of this
-
# function ( creerListeDegre)
-
-
# tests of the function triDegre
-
#TESTS TO BE BUILT ( we must write some tests of this
-
# function ( triDegre )
-
-
# tests of polynomials: representation, addition, multiplication
-
# TESTS TO BE BUILT ( we must write some tests )
-
-
#pol1 = Polynome(doublet1)
-
#pol2 = Polynome(doublet2)
-
#som = add(pol1, pol2)
-
#prod = mult(pol1, pol2)
-
#print som
-
#print prod
-
for example , the calss Doublet causes problems to me -
>If, for example, I write
-
-
> >>> a=Monome(2,7,11)
-
> >>> a
-
> +2*x^7*y^11
-
> >>> b=Monome(-1,17,35)
-
> >>> b
-
> -1*x^17*y^35
-
> >>> c=Doublet(a,b)
-
> >>> t
-
> Traceback (most recent call last):
-
> File "<pyshell#5>", line 1, in <module>
-
> t
-
> File "C:\...\polynomesXY2_DEVOIR_Enonce.py", line 36, in __repr__
-
> res+=str(cour.refMon)
-
> AttributeError: Monome instance has no attribute 'refMon'
-
this returns an error message
could you help me PLEASE?
thank you in advance and I hope to have been clear ( understood )
thank you
I've added [ code] [ /code] tags. I'll take a look now. In the mean time, please learn to use these (without spaces) in "Posting Guidelines" in several places on this forum.
Hello bartonc ,
can you change the title please ?
thanks
bvdet 2,851
Expert Mod 2GB
I added spaces at the plus and minus signs so the polynomial is easier to read. - m1 = Monome(5,2,6)
-
m2 = Monome(6,2,8)
-
print "\nm1 : ", m1
-
print "m2 : ", m2
-
d2 = Doublet(m1,Doublet(m2, Doublet(Monome(4,7,1), None)))
-
print "Doublet(m1,Doublet(m2, Doublet(Monome(-4,7,1), None))): ", d2
Output: - m1 : + 5*x^2*y^6
-
m2 : + 6*x^2*y^8
-
Doublet(m1,Doublet(m2, Doublet(Monome(-4,7,1), None))): + 5*x^2*y^6 + 6*x^2*y^8 + 4*x^7*y^1
The first argument to Doublet is a Monome object and the second is None or a Doublet object
bvdet 2,851
Expert Mod 2GB
badech,
I was playing with an instance of your Doublet class and noticed there was no iteration method. I have never used ' yield' in code before: - # Doublet iterator
-
def iterDoub(d):
-
while d:
-
yield d.refMon
-
d = d.suiv
Example: - >>> print "Doublet 'd1':", d1
-
Doublet 'd1': + 9*x^2*y^6 + 2*x^3*y^0 + 5*x^3*y^9 - 2*x^4*y^2 + 5*x^10*y^3 - 3*x^11*y^7
-
>>> for d in iterDoub(d1):
-
... print d
-
...
-
+ 9*x^2*y^6
-
+ 2*x^3*y^0
-
+ 5*x^3*y^9
-
- 2*x^4*y^2
-
+ 5*x^10*y^3
-
- 3*x^11*y^7
-
>>>
It seems interestingly simple. Maybe you can use it.
badech,
I was playing with an instance of your Doublet class and noticed there was no iteration method. I have never used 'yield' in code before: - # Doublet iterator
-
def iterDoub(d):
-
while d:
-
yield d.refMon
-
d = d.suiv
Example: - >>> print "Doublet 'd1':", d1
-
Doublet 'd1': + 9*x^2*y^6 + 2*x^3*y^0 + 5*x^3*y^9 - 2*x^4*y^2 + 5*x^10*y^3 - 3*x^11*y^7
-
>>> for d in iterDoub(d1):
-
... print d
-
...
-
+ 9*x^2*y^6
-
+ 2*x^3*y^0
-
+ 5*x^3*y^9
-
- 2*x^4*y^2
-
+ 5*x^10*y^3
-
- 3*x^11*y^7
-
>>>
It seems interestingly simple. Maybe you can use it.
Great post, B.V.! It's awesome that you are finding inspiration from members' questions.
bvdet 2,851
Expert Mod 2GB
Great post, B.V.! It's awesome that you are finding inspiration from members' questions.
Thanks Barton. I am learning new things regularly by following threads and participating where I can.
badech - Have you made any progress on your assignment? Show us what you have accomplished. Try to solve it one step at a time. We should not write it for you, but I am sure we can help if you are having problems with your code.
bvdet 2,851
Expert Mod 2GB
I did not care for the way the multinomials were represented, so I reworked special methods '__repr__': - class Monome: # monome = monomial
-
def __init__(self, coefficient, exposantX, exposantY): #exposant = power
-
self.coeff = coefficient
-
self.expoX = exposantX
-
self.expoY = exposantY
-
-
def __repr__(self):
-
if abs(self.coeff) == 1:
-
coeffStr = "("
-
else:
-
coeffStr = '%s(' % (abs(self.coeff))
-
if self.coeff < 0:
-
preStr = "-"
-
else:
-
preStr = "+"
-
return '%s%sx^%s*y^%s)' % (preStr, coeffStr, self.expoX, self.expoY)
-
-
def __lt__(self, autre): #autre=other
-
return (self.expoX < autre.expoX) or ((self.expoX == autre.expoX) and (self.expoY < autre.expoY))
-
def __gt__(self,autre):
-
return (self.expoX > autre.expoX) or ((self.expoX == autre.expoX) and (self.expoY >autre.expoY))
-
-
class Doublet:
-
def __init__(self,referenceMonome,refSuiv): # suiv=next
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
-
def __repr__(self):
-
res = str(self.refMon)
-
a = self.suiv
-
while a:
-
res += str(a.refMon)
-
a = a.suiv
-
if res[0] == '+':
-
return res[1:]
-
return res
This is what it looks like now: - Doublet 'd1': 9(x^2*y^6)+2(x^3*y^0)+5(x^3*y^9)-2(x^4*y^2)+5(x^10*y^3)-3(x^11*y^7)
-
Iteration over Doublet 'd1':
-
+9(x^2*y^6)
-
+2(x^3*y^0)
-
+5(x^3*y^9)
-
-2(x^4*y^2)
-
+5(x^10*y^3)
-
-3(x^11*y^7)
-
-
6(x^3*y^8)+5(x^3*y^9)-2(x^4*y^2)
-
4(x^2*y^6)+2(x^3*y^0)-6(x^3*y^8)+5(x^10*y^3)-3(x^11*y^7)
-
-(x^-2*y^-3)+7(x^4*y^12)+4(x^5*y^6)+6(x^7*y^1)
Thanks Barton. I am learning new things regularly by following threads and participating where I can.
badech - Have you made any progress on your assignment? Show us what you have accomplished. Try to solve it one step at a time. We should not write it for you, but I am sure we can help if you are having problems with your code.
I often wish that I had more time to play with some of these exercises. I'm right in the middle of good sized project with a deadline looming.
Maybe no progress, maybe just (less that avid poster) - I know that he checked in this morning.
Hello
I am blocked on the first question, I do not manage to write the function insereMonome because I do not understand how the "calss" function.
can you help me to write this first function , and then i'll do the others
thank you
Hello
I am blocked on the first question, I do not manage to write the function insereMonome because I do not understand how the "calss" function.
can you help me to write this first function , and then i'll do the others
thank you
Perhaps this is what you are looking for? - class Monome: # monome = monomial
-
def __init__(self, coefficient, exposantX, exposantY): #exposant = power
-
self.coeff = coefficient
-
self.expoX = exposantX
-
self.expoY = exposantY
-
-
def __repr__(self):
-
if abs(self.coeff) == 1:
-
coeffStr = "("
-
else:
-
coeffStr = '%s(' % (abs(self.coeff))
-
if self.coeff < 0:
-
preStr = "-"
-
else:
-
preStr = "+"
-
return '%s%sx^%s*y^%s)' % (preStr, coeffStr, self.expoX, self.expoY)
-
-
def __lt__(self, autre): #autre=other
-
return (self.expoX < autre.expoX) or ((self.expoX == autre.expoX) and (self.expoY < autre.expoY))
-
def __gt__(self,autre):
-
return (self.expoX > autre.expoX) or ((self.expoX == autre.expoX) and (self.expoY >autre.expoY))
-
-
class Doublet:
-
def __init__(self,referenceMonome,refSuiv): # suiv=next
-
self.refMon = referenceMonome
-
self.suiv = refSuiv
-
-
def __repr__(self):
-
res = str(self.refMon)
-
a = self.suiv
-
while a:
-
res += str(a.refMon)
-
a = a.suiv
-
if res[0] == '+':
-
return res[1:]
-
return res
-
-
-
m1 = Monome(5,2,6)
-
m2 = Monome(6,2,8)
-
print "\nm1 : ", m1
-
print "m2 : ", m2
-
d2 = Doublet(m1,Doublet(m2, Doublet(Monome(4,7,1), None)))
-
print "Doublet(m1,Doublet(m2, Doublet(Monome(-4,7,1), None))): ", d2
-
bvdet 2,851
Expert Mod 2GB
Hello
I am blocked on the first question, I do not manage to write the function insereMonome because I do not understand how the "calss" function.
can you help me to write this first function , and then i'll do the others
thank you
The sort function acts like a bubble sort. I learned this from a thread a couple of weeks ago. Function ' insereMonome' is a wrapper for the ' Doublet' class and returns a sorted Doublet object. - # sort function on Doublet object in ascending order
-
def sortDoub(d):
-
while d != None:
-
if d.suiv != None:
-
d2 = d.suiv
-
while d2 != None:
-
if d.refMon > d2.refMon:
-
d.refMon, d2.refMon = d2.refMon, d.refMon
-
d2 = d2.suiv
-
d = d.suiv
-
-
# Add new Monome object to existing Doublet object and sort in ascending order
-
def insereMonome(coefficient, exposantX, exposantY, d=None): #insere=insert
-
newDoub = Doublet(Monome(coefficient, exposantX, exposantY), d)
-
sortDoub(newDoub)
-
return newDoub
Sample output: - doub1 = insereMonome(6,3,8, doub1): 5(x^2*y^6)+6(x^3*y^8)-2(x^4*y^2)
-
doub2 = insereMonome(2,3,0, doub2): 4(x^2*y^6)+2(x^3*y^0)-6(x^3*y^8)+5(x^10*y^3)-3(x^11*y^7)
-
Combine and simplify 2 Doublet objects: 9(x^2*y^6)+2(x^3*y^0)-2(x^4*y^2)+5(x^10*y^3)-3(x^11*y^7)
Here's a hint to simplify a multinomial Doublet object:
Iterate on the object and create a dictionary where you can sum coefficients with like exponents. From the dictionary, create and return a new and simplified Doublet object, skipping a monomial with a coeffieient of 0.
euh...
no
these functions are given
i want to write a function which allows to insert a monomial in a polynomial
for example , if
P=2*X^5*Y^3+5*X^3*Y^7-2
and M= -7*X^4Y^6
then
insereMonome(M,P) returns
2*X^5*Y^3 -7*X^4Y^6 +5*X^3*Y^7-2
perfect ...
thank you very much bvdet :)
bvdet 2,851
Expert Mod 2GB
I often wish that I had more time to play with some of these exercises. I'm right in the middle of good sized project with a deadline looming.
Maybe no progress, maybe just (less that avid poster) - I know that he checked in this morning.
I understand about deadlines. I will have some coming up in the near future. Now you know where I will be if I disappear for a few days.
what do you think about this one ? - def ajouteDoubletsRec(listeDoublet1, listeDoublet2):
-
# renvoie une nouvelle liste de doublets obtenue par
-
# fusion des deux listes en une nouvelle
-
# ATTENTION : ne pas oublier de traîter le cas où l'on additionne deux monomes opposés !!!!!
-
# dans ce cas, NE PAS faire apparaître un monome avec un coefficient nul.
-
if listeDoublet1==None :
-
return listeDoublet2
-
elif listeDoublet2==None :
-
return listeDoublet1
-
else :
-
listeDoublet1.suiv=ajouteDoubletsRec(listeDoublet1.suiv, listeDoublet2)
-
sortDoub(listeDoublet1)
-
return listeDoublet1
def ajouteDoubletsRec(listeDoublet1, listeDoublet2): #ajoute=add
... # ATTENTION: not to forget to treat the case where two opposite
# monomials are added!!!!!
# in this case, not to reveal a monomial with a null coefficient.
return None
...this part is missing
bvdet 2,851
Expert Mod 2GB
what do you think about this one ? - def ajouteDoubletsRec(listeDoublet1, listeDoublet2):
-
# renvoie une nouvelle liste de doublets obtenue par
-
# fusion des deux listes en une nouvelle
-
# ATTENTION : ne pas oublier de traîter le cas où l'on additionne deux monomes opposés !!!!!
-
# dans ce cas, NE PAS faire apparaître un monome avec un coefficient nul.
-
if listeDoublet1==None :
-
return listeDoublet2
-
elif listeDoublet2==None :
-
return listeDoublet1
-
else :
-
listeDoublet1.suiv=ajouteDoubletsRec(listeDoublet1.suiv, listeDoublet2)
-
sortDoub(listeDoublet1)
-
return listeDoublet1
badech,
The function creates a never ending loop. You need to test your code in an IDE such as Pythonwin or Idle.
Remember that a Doublet is a combination of a Monome and another Doublet. I suggest that you iterate on one of the Doublets and combine each iteration Monome with the other Doublet. - outDoub = d1
-
for m in iterDoub(d2):
-
outDoub = Doublet(m, outDoub)
-
return simplify_and_sort(outDoub)
You will need to write the simplification function. See my earlier post for suggestions. Test your code, and it should look something like this (Pythonwin): - >>> d4
-
2(x^2*y^3)+16(x^2*y^6)+2(x^4*y^6)+14(x^8*y^9)+(x^9*y^3)
-
>>> d2
-
-7(x^9*y^3)+8(x^9*y^3)+(x^2*y^3)+4(x^2*y^6)+4(x^2*y^6)+(x^4*y^6)-4(x^5*y^7)+4(x^5*y^7)+7(x^8*y^9)
-
>>> d11 = ajouteDoubletsRec(d4, d2)
-
>>> d11
-
3(x^2*y^3)+24(x^2*y^6)+3(x^4*y^6)+21(x^8*y^9)+2(x^9*y^3)
-
>>>
bvdet 2,851
Expert Mod 2GB
I have another improvement (in my mind) for the displayed representation of a Monome object: - class Monome: # monome = monomial
-
def __init__(self, coefficient, exposantX, exposantY): #exposant = power
-
self.coeff = coefficient
-
self.expoX = exposantX
-
self.expoY = exposantY
-
-
def __repr__(self):
-
if abs(self.coeff) == 1:
-
coeffStr = "("
-
else:
-
coeffStr = '%s(' % (abs(self.coeff))
-
if self.coeff < 0:
-
preStr = "-"
-
else:
-
preStr = "+"
-
if self.expoX == 0:
-
return '%s%sy^%s)' % (preStr, coeffStr, self.expoY)
-
elif self.expoY == 0:
-
return '%s%sx^%s)' % (preStr, coeffStr, self.expoX)
-
return '%s%sx^%s*y^%s)' % (preStr, coeffStr, self.expoX, self.expoY)
Since a number raised to the '0' power == 1, it need not be included in the representation: - Doublet 'd1': 5(y^6)+4(x^2*y^6)+2(x^3)+5(x^3*y^9)-2(x^4*y^2)+5(x^10*y^3)-3(x^11*y^7)
-
Iteration over Doublet 'd1':
-
+5(y^6)
-
+4(x^2*y^6)
-
+2(x^3)
-
+5(x^3*y^9)
-
-2(x^4*y^2)
-
+5(x^10*y^3)
-
-3(x^11*y^7)
bvdet 2,851
Expert Mod 2GB
Here is another function for sorting a Doublet object. The sort itself should be much faster because it uses the built-in list.sort() method, but the sort list is created by iteration. List items can be deleted or moved around to change the sort results. It returns a sorted Doublet object, so the object can be passed directly to a return statement or assigned to a variable. - # Doublet iterator
-
def iterDoub(d):
-
while d:
-
yield d.refMon
-
d = d.suiv
-
-
# return a sorted Doublet object in descending order of degree
-
def cmpDoub(d):
-
mList = []
-
for m in iterDoub(d):
-
mList.append((m.expoX+m.expoY, m.expoX, m.expoY, m.coeff, m))
-
mList.sort()
-
outDoub = None
-
for item in mList:
-
outDoub = Doublet(Monome(item[3], item[1], item[2]), outDoub)
-
return outDoub
-
-
# Add new Monome object to existing Doublet object and sort in descending order of degree
-
def insereMonome(coefficient, exposantX, exposantY, d=None): #insere=insert
-
return cmpDoub(Doublet(Monome(coefficient, exposantX, exposantY), d))
Sample output: - doub2 = insereMonome(5,10,3, None): 5(x^10*y^3)
-
doub2 = insereMonome(4,2,6, doub2): 5(x^10*y^3)+4(x^2*y^6)
-
doub2 = insereMonome(-3,11,7, doub2): -3(x^11*y^7)+5(x^10*y^3)+4(x^2*y^6)
-
doub2 = insereMonome(-6,3,8, doub2): -3(x^11*y^7)+5(x^10*y^3)-6(x^3*y^8)+4(x^2*y^6)
-
doub2 = insereMonome(2,3,0, doub2): -3(x^11*y^7)+5(x^10*y^3)-6(x^3*y^8)+4(x^2*y^6)+2(x^3)
-
doub2 = insereMonome(2,10,3, doub2): -3(x^11*y^7)+5(x^10*y^3)+2(x^10*y^3)-6(x^3*y^8)+4(x^2*y^6)+2(x^3)
-
doub2 = insereMonome(4,3,0, doub2): -3(x^11*y^7)+5(x^10*y^3)+2(x^10*y^3)-6(x^3*y^8)+4(x^2*y^6)+4(x^3)+2(x^3)
-
doub2 = insereMonome(2,2,6, doub2): -3(x^11*y^7)+5(x^10*y^3)+2(x^10*y^3)-6(x^3*y^8)+4(x^2*y^6)+2(x^2*y^6)+4(x^3)+2(x^3)
HTH
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chris |
last post by:
Does anyone know of a good standalone implementation of multivariable
polynomials in python?
Thanks,
Chris
|
by: adrin |
last post by:
hi,
anyone knows how does an algorithm for calculating GCD of two polynomials
look like ?
please help me if you can, or give some relevant links :)
|
by: thirtyseven |
last post by:
I was wondering if anyone knew of some public code for a c++ class that
represents a value, but can preserve fractions and powers and such
without just turning the value into a float.
Hard to...
|
by: Joe |
last post by:
I have several classes which I need serialized. Here is their class
definitions:
public class TopContainer
{
private LevelTwoType m_levelTwo;
public LevelTwoType LevelTwo
{
get
{
|
by: beck2 |
last post by:
hello i am angela and i would like if its kind of anyone to help me by writing me the code of adding 2 oplynomials?
polynomials should be entered as where 3,5 and 1 are coefficients of X to the...
|
by: Matthias |
last post by:
how do i make a program that gets numbers from a user. and then stores
it into an array. using polynomials
if the user entered 7 5 4 3 2
the polynomial would be 7x^4+5x^3+4x^2+3x+2
the program...
|
by: Motanyane Tlotliso |
last post by:
I wish someone to help me in creating a programm in C++ that can be able to sum two polynomials, subtract one from the other and multiply both polynomials together using a ADT's(struct term).
I...
|
by: =?ISO-8859-1?Q?J=FCrgen_B=F6hm?= |
last post by:
Hello,
(I already posted this at comp.lang.c++.moderated, but received no
answers, maybe it is better placed here?):
to implement a little symbolic computation system, dealing with...
|
by: madman228 |
last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial
in which i need a derivative method I have everything, just dont know how to start the derivative method. Any...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |