Ask Your Question
3

LCM of 3 polynomials

asked 2022-03-16 03:20:43 +0100

anonymous user

Anonymous

updated 2023-01-09 23:59:56 +0100

tmonteil gravatar image

why changing the order of the parameters gives different reults ?

sage: x,y = var('x y')  
sage: LCM([x^2 - y^2, x^2 + 2*x*y + y^2, x^3 + y^3])
(x^3 + y^3)*(x^2 + 2*x*y + y^2)*(x^2 - y^2)/(x + y)^2
sage: LCM([x^2 - y^2, x^3 + y^3, x^2 + 2*x*y + y^2])
(x^3 + y^3)*(x^2 + 2*x*y + y^2)*(x^2 - y^2)/(x + y)^3
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2022-03-16 13:32:35 +0100

eric_g gravatar image

updated 2022-03-16 13:45:53 +0100

This is clearly a bug in the lcm method of symbolic expressions. Note that there is no bug if you use a proper polynomial ring instead of mere symbolic expressions:

sage: P.<x, y> = QQ[]
sage: P
Multivariate Polynomial Ring in x, y over Rational Field
sage: a, b, c = x^2 - y^2, x^2 + 2*x*y + y^2, x^3 + y^3
sage: LCM([a, b, c])
x^5 - x^3*y^2 + x^2*y^3 - y^5
sage: LCM([a, c, b])
x^5 - x^3*y^2 + x^2*y^3 - y^5

With the symbolic ring (i.e. with x and y being symbolic variables created via var()), there appears the bug that you pointed out:

sage: x, y = var('x y')
sage: a, b, c = x^2 - y^2, x^2 + 2*x*y + y^2, x^3 + y^3
sage: LCM([a, b, c]).simplify_rational()  # correct answer
x^5 - x^3*y^2 + x^2*y^3 - y^5
sage: LCM([a, c, b]).simplify_rational()  # wrong answer!
x^4 - x^3*y + x*y^3 - y^4

Looking at Sage's source code, this bug can be traced back to

sage: s = a.lcm(c)
sage: s
(x^3 + y^3)*(x^2 - y^2)/(x + y)
sage: s.gcd(b) 
(x + y)^2
sage: s.simplify_rational().gcd(b)
x + y

A fix consists in modifying the code of Expression.lcm in line 8097 of src∕sage/symbolic/expression.pyx from

return 0 if sb.is_trivial_zero() else sb / self.gcd(b)

to

return 0 if sb.is_trivial_zero() else sb / self.simplify_rational().gcd(b)

I've opened https://trac.sagemath.org/ticket/33509 for this.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-03-16 03:20:43 +0100

Seen: 253 times

Last updated: Mar 16 '22