我尝试使用sage在两个变量中进行简单的多项式除法。 不幸的是,我得到了一个意想不到的结果,如下面的代码所示。 我尝试了几种不同的方法来实例化环及其变量,但是 结果保持不变。使用%-operator获得除法的其余部分会产生相同的结果。有什么想法吗?
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 and 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 and r == -x^2+x*y^3-y+1
输出:
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 and r == -x**Integer(2)+x*y**Integer(3)-y+Integer(1)
AssertionError:
答案 0 :(得分:1)
多元多项式的除法结果取决于单项式的选择顺序,explained in Wikipedia也是如此。就目前而言,当P并且仅当P包含可被Q 的前导单项相对于所选择的顺序整除的单项时,足以说P除以Q的商是非零的。
默认情况下,Sage中的多项式环使用度 - 反向词典顺序(简称为degrevlex),其中单项式首先按总度排序,然后按字典顺序在每个度数内。您可以使用R.term_order()
进行检查。这是the list of term orders。
在degrevlex顺序中,y ^ 3在x * y之前,因为它具有更高的总度。并且由于x ^ 2 * y-x ^ 2-y + 1没有可被y ^ 3整除的单项式,因此得到零商。
您的预期结果与单项式的词典(lex)顺序一致。因此,似乎修复是在构造R时规定词典术语顺序:
R.<x,y> = PolynomialRing(QQ, 2, 'xy', order='lex')
不幸的是,quo_rem
忽略了R的术语顺序,仍然使用degrevlex。这似乎是一个错误,无论是Sage与Singular通信的方式,还是Singular本身(the Quotient command is deprecated)。
同时,有一种解决方法:使用reduce
命令而不是quo_rem
,因为它尊重R的术语顺序。例如:
R.<x,y> = PolynomialRing(QQ, 2, 'xy', order='lex')
a = x^2*y-x^2-y+1
f2 = x*y-y^3
r = a.reduce(Ideal([f2]))
q = (a-r)/f2
返回r = -x ^ 2 + x * y ^ 3 - y + 1和q = x。