Modular operation in multivariate polynomials

32 views
Skip to first unread message

Oleksandr Kazymyrov

unread,
Feb 16, 2012, 8:09:33 AM2/16/12
to sage-s...@googlegroups.com
Hi All,

Code:

sage: bits=3
sage: 
sage: k=GF(2^bits,'a')
sage: P=PolynomialRing(k,1+bits+bits+bits-1+(1<<bits),['y'] + ['a{0}'.format(g) for g in xrange(bits)] + ['b{0}'.format(g) for g in xrange(bits)] + ['c{0}'.format(g) for g in xrange(1,bits)] + ['p{0}'.format(g) for g in xrange(1<<bits)])
sage: 
sage: A1=sum([P('(a{0})*y^{0}'.format(g)) for g in xrange(bits)])
sage: A2=sum([P('(b{0})*y^{0}'.format(g)) for g in xrange(bits)])
sage: A3=sum([P('(c{0})*y^{0}'.format(g)) for g in xrange(1,bits)])
sage: pol = sum([P('(p{0})*y^{0}'.format(g)) for g in xrange(1<<bits)])
sage: 
sage: pol=pol.subs({P("y"):A2})
sage: pol=A1.subs({P("y"):pol})
sage: pol=pol+A3
sage: 
sage: print "pol = {0}".format(pol)
sage: print "~"*20
sage: pol=pol.mod(P("y^{0}+y".format(1<<bits)))
sage: print "pol = {0}".format(pol)

Output: 
pol = y^28*a2*b2^14*p7^2 + y^26*a2*b1^2*b2^12*p7^2 + y^24*a2*b1^4*b2^10*p7^2 + y^24*a2*b0^2*b2^12*p7^2 + y^24*a2*b2^12*p6^2 + y^22*a2*b1^6*b2^8*p7^2 + y^20*a2*b1^8*b2^6*p7^2 + y^20*a2*b0^2*b1^4*b2^8*p7^2 + y^20*a2*b0^4*b2^10*p7^2 + y^20*a2*b1^4*b2^8*p6^2 + y^18*a2*b1^10*b2^4*p7^2 + y^18*a2*b0^4*b1^2*b2^8*p7^2 + y^20*a2*b2^10*p5^2 + y^16*a2*b1^12*b2^2*p7^2 + y^16*a2*b0^2*b1^8*b2^4*p7^2 + y^16*a2*b0^6*b2^8*p7^2 + y^18*a2*b1^2*b2^8*p5^2 + y^16*a2*b1^8*b2^4*p6^2 + y^16*a2*b0^4*b2^8*p6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a2*b0^4*b1^2*p3^2 + a2*b0^8*p4^2 + y^4*a1*b0*b1^4*p5 + y^2*a1*b0^5*b1^2*p7 + y^2*a1*b0^6*b2*p7 + y^5*a1*b1*b2^2*p3 + y^4*a1*b1^4*p4 + y^2*a1*b0^4*b1^2*p6 + y*a1*b0^6*b1*p7 + y^4*a2*b2^2*p1^2 + y^4*a1*b1^2*b2*p3 + y^4*a1*b0*b2^2*p3 + a2*b0^6*p3^2 + y^2*a1*b0^4*b2*p5 + a1*b0^7*p7 + y^4*a1*b2^2*p2 + y^3*a1*b1^3*p3 + y*a1*b0^4*b1*p5 + a1*b0^6*p6 + y^2*a2*b1^2*p1^2 + a2*b0^4*p2^2 + y^2*a1*b0*b1^2*p3 + y^2*a1*b0^2*b2*p3 + a1*b0^5*p5 + y^2*a1*b1^2*p2 + y*a1*b0^2*b1*p3 + a1*b0^4*p4 + y^2*a1*b2*p1 + a2*b0^2*p1^2 + a1*b0^3*p3 + y*a1*b1*p1 + a1*b0^2*p2 + y^2*c2 + a2*p0^2 + a1*b0*p1 + y*c1 + a1*p0 + a0

I expect that the degree of the polynomial will be less than 2^bits=8. However, for the third monomial (y^10*a2*b1^10*p5^2) degree is equal to 10 and the largest is 12. Moreover:

sage: pol=P("y^10*a2*b1^10*p5^2").mod(P("y^{0}+y".format(1<<bits)))
sage: print "pol = {0}".format(pol)

Output:
pol = y^3*a2*b1^10*p5^2

Where is the problem?

Machine:
linux: Linux pcen 3.0.0-16-generic #28-Ubuntu SMP Fri Jan 27 17:44:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
sage: 'Sage Version 4.8, Release Date: 2012-01-20'

Oleksandr
Polynomial.sage

Simon King

unread,
Feb 16, 2012, 10:23:01 AM2/16/12
to sage-support
Hi Oleksandr,

On 16 Feb., 14:09, Oleksandr Kazymyrov <vrona.aka.ham...@gmail.com>
wrote:
> I expect that the degree of the polynomial will be less than 2^bits=8.

Why do you expect this? There is a difference between a polynomial
(i.e., an element of a polynomial ring) and a polynomial function.
Polynomials can be of arbitrary degree, over any coefficient field.

Over a finite field, it is just normal that a polynomial constantly
evaluates as zero, but is not zero:
sage: P.<x,y> = GF(3)[]
sage: p = x^3 - x + y^3 - y
sage: p.degree()
3
sage: p == 0
False
sage: [p(x=a,y=b) for a,b in cartesian_product_iterator([list(GF(3)),
list(GF(3))])]
[0, 0, 0, 0, 0, 0, 0, 0, 0]

Sorry if I misunderstood the problem.

Best regards,
Simon

Oleksandr Kazymyrov

unread,
Feb 16, 2012, 5:58:29 PM2/16/12
to sage-s...@googlegroups.com
Dear Simon,

>> There is a difference between a polynomial (i.e., an element of a polynomial ring) and a polynomial function. Polynomials can be of arbitrary degree, over any coefficient field.

Yes I know this. But I think there is no difference between defining of PolynomialRing and PolynomialQuotientRing, assuming that you independently perform the operation by modulus. I am forcing the call of a function pol.mod(P("y^8+y")) to obtain the remainder by modulus. And I expect that monomial "y^10*a2*b1^10*p5^2" will has degree 3 (y^3*a2*b1^10*p5^2) after operation pol.mod(P("y^8+y")) in the polynomial.

KInd regards,
Oleksandr

Simon King

unread,
Feb 17, 2012, 1:22:04 AM2/17/12
to sage-support
Hi Oleksandr,

On 16 Feb., 17:58, Oleksandr Kazymyrov <vrona.aka.ham...@gmail.com>
wrote:
> I am forcing the call of a function
> pol.mod(P("y^8+y")) to obtain the remainder by modulus.

Sorry, I had missed that (the example was quite long, and thus I had
the impression that you had merely constructed a polynomial over a
finite field, but no modulus except the modulus of the finite field).

> And I expect that
> monomial "y^10*a2*b1^10*p5^2" will has degree 3 (y^3*a2*b1^10*p5^2) after
> operation pol.mod(P("y^8+y")) in the polynomial.

Right. That sounds like a bug to me.

Starting with your definitions, it seems to me that the bug is in
libSingular (which is used for polynomial arithmetic in Sage), whereas
Singular itself computes it correctly:

sage: polS = singular(pol)
sage: IS = singular(I)
sage: singular("NF(%s,std(%s))"%(polS.name(), IS.name()))
y^7*a2*b1^14*p7^2+y^7*a2*b2^14*p7^2+y^6*a2*b0^8*b1^6*p7^2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*b0^4*b1*p5+y*a1*b0*b2^4*p5+a1*b0^6*p6+y^2*a2*b1^2*p1^2+a2*b0^4*p2^2+y^2*a1*b0*b1^2*p3+y^2*a1*b0^2*b2*p3+y*a1*b2^4*p4+a1*b0^5*p5+y^2*a1*b1^2*p2+y*a1*b0^2*b1*p3+a1*b0^4*p4+y^2*a1*b2*p1+a2*b0^2*p1^2+a1*b0^3*p3+y*a1*b1*p1+a1*b0^2*p2+y^2*c2+a2*p0^2+a1*b0*p1+y*c1+a1*p0+a0
sage: pol.reduce(I)
The strange thing is that everything is alright if just the single
monomial is considered:

sage: singular("NF(y^10*a2*b1^10*p5^2,std(%s))"%(IS.name()))
y^3*a2*b1^10*p5^2
sage: P('y^10*a2*b1^10*p5^2').reduce(I)
y^3*a2*b1^10*p5^2
sage: I.reduce(P('y^10*a2*b1^10*p5^2'))
y^3*a2*b1^10*p5^2

Do you have a trac account, or shall I open a trac ticket myself?

Best regards,
Simon

Oleksandr Kazymyrov

unread,
Feb 17, 2012, 4:33:24 AM2/17/12
to sage-s...@googlegroups.com
Hi Simon,

>> Do you have a trac account, or shall I open a trac ticket myself? 
No, I havn't. If this is not a problem for you then open.

At the moment I use the following code:

pol=sum([g.mod(P("y^{0}+y".format(1<<bits)))  for g in pol.monomials()])

Maybe it will help.

Best regards,
Oleksandr

Simon King

unread,
Feb 17, 2012, 4:53:51 AM2/17/12
to sage-support
Hi Oleksandr,

On 17 Feb., 10:33, Oleksandr Kazymyrov <vrona.aka.ham...@gmail.com>
wrote:
> No, I havn't. If this is not a problem for you then open.

OK, I'll do so later today.

> At the moment I use the following code:
>
> pol=sum([g.mod(P("y^{0}+y".format(1<<bits)))  for g in pol.monomials()])

No, that won't do the right thing.

The literature uses the words "monomial" and "term" in a confusing
way, namely in two opposite points of view: Some say that a polynomial
is a sum of monomials (i.e., a monomial comprises a coefficient) and a
term is without the coefficient. Others say that a monomial is an
element of the commutative monoid that the polynomial ring is
constructed from: They say that a monomial has no coefficient, whereas
a term is the product of a monomial with its coefficient (i.e., a
polynomial is a sum of terms).

Sage follows the second convention:
sage: P.<x,y> = GF(3)[]
sage: p = P.random_element()
sage: p
x^2 + x*y - 1
sage: p.monomials()
[x^2, x*y, 1]
sage: p.coefficients()
[1, 1, 2]
sage: sum(p.monomials()) == p
False

So, you must not forget to multiply each monomial with its
coefficient, for example:
sage: sum([c*m for c,m in zip(p.coefficients(),p.monomials())]) == p
True

Best regards,
Simon

Oleksandr Kazymyrov

unread,
Feb 17, 2012, 5:10:32 AM2/17/12
to sage-s...@googlegroups.com
Hi Simon,

I agree with you. My previous message is true only for GF(2^n).

Best regards,
Oleksandr

Simon King

unread,
Feb 17, 2012, 7:56:33 AM2/17/12
to sage-support
Hi all,

On 17 Feb., 10:53, Simon King <simon.k...@uni-jena.de> wrote:
> > No, I havn't. If this is not a problem for you then open.
>
> OK, I'll do so later today.

I opened http://trac.sagemath.org/sage_trac/ticket/12529

Best regards,
Simon
Reply all
Reply to author
Forward
0 new messages