python - Multivariate polynomial division in sage -


i try simple division of polynomials in 2 variables using sage. unfortunately, unexpected result, illustrated in code below. tried several different ways instantiate ring , variables, result stays same. using %-operator rest of division yields same results. ideas?

r, (x, y) = polynomialring(rationalfield(), 2, 'xy').objgens() t = x^2*y^2 + x^2*y - y + 1 f1 = x*y^2 + x f2 = x*y - y^3  (q, r) = t.quo_rem(f1) print "quotient:", q, "reminder:", r assert q == x , r == x^2*y-x^2-y+1  (q, r) = r.quo_rem(f2) # error, expected q = x, r = -x^2+x*y^3-y+1 print "quotient:", q, "reminder:", r assert q == x , r == -x^2+x*y^3-y+1 

output:

quotient: x reminder: x^2*y - x^2 - y + 1 quotient: 0 reminder: x^2*y - x^2 - y + 1  --------------------------------------------------------------------------- assertionerror                            traceback (most recent call last) <ipython-input-8-861e8a9d1112> in <module>()      10 (q, r) = r.quo_rem(f2) # error, expected q = x, r = -x^2+x*y^3-y+1      11 print "quotient:", q, "reminder:", r ---> 12 assert q == x , r == -x**integer(2)+x*y**integer(3)-y+integer(1)  assertionerror:  

division of multivariate polynomials: term orders

the result of division of multivariable polynomials depends on chosen order of monomials, explained in wikipedia. present, suffices quotient dividing p q nonzero if , if p contains monomial divisible leading monomial of q with respect chosen order.

by default, polynomial rings in sage use degree-reverse lexicographic order (degrevlex short), in monomials first sorted total degree, , lexicographically within each degree. can check using r.term_order(). , here the list of term orders.

in degrevlex order, y^3 precedes x*y because has higher total degree. , since x^2*y-x^2-y+1 not have monomial divisible y^3, 0 quotient.

buggy quo_rem

your expected results consistent lexicographic (lex) order of monomials. so, seem fix prescribe lexicographic term order when constructing r:

r.<x,y> = polynomialring(qq, 2, 'xy', order='lex')  

unfortunately, quo_rem ignores term order of r , still uses degrevlex. appears bug, either in way sage communicates singular, or in singular (the quotient command deprecated).

workaround

meanwhile, there workaround: use reduce command instead of quo_rem, respects term order of r. example:

r.<x,y> = polynomialring(qq, 2, 'xy', order='lex') = x^2*y-x^2-y+1 f2 = x*y-y^3 r = a.reduce(ideal([f2])) q = (a-r)/f2  

this returns r = -x^2 + x*y^3 - y + 1 , q = x.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -