Skip to content

Commit

Permalink
Trac #33640: sage fails to factor some easy expressions
Browse files Browse the repository at this point in the history
As reported on [https://groups.google.com/g/sage-
devel/c/Ca661TP_3Ug/m/f2lZtUXLAwAJ sage-devel], sage fails to factor
expressions that expand to something very easy, such as `x^2` or `0`.
Instead, it returns the original expression.
{{{
sage: ((x + 1)^2 - 2*x - 1).factor()  # bad (should be x^2)
(x + 1)^2 - 2*x - 1
sage: ((x + 1)^2 - x^2 - 2*x - 1).factor()  # bad (should be 0)
(x + 1)^2 - x^2 - 2*x - 1
sage: ((x + 2)^2 - 2*x - 3).factor()  # good
(x + 1)^2
}}}

URL: https://trac.sagemath.org/33640
Reported by: gh-DaveWitteMorris
Ticket author(s): Frédéric Chapoton
Reviewer(s): David Lowry-Duda
  • Loading branch information
Release Manager committed Sep 19, 2022
2 parents 700a1f5 + b41c93f commit 787b4be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11898,6 +11898,11 @@ cdef class Expression(Expression_abc):
x + sqrt(x)
sage: factor((x + sqrt(x))/(x - sqrt(x)))
(x + sqrt(x))/(x - sqrt(x))
Check that :trac:`33640` is fixed::
sage: ((x + 1)^2 - 2*x - 1).factor()
x^2
"""
from sage.calculus.calculus import symbolic_expression_from_maxima_string
cdef GEx x
Expand Down
2 changes: 0 additions & 2 deletions src/sage/symbolic/ginac/normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,6 @@ bool factor(const ex& the_ex, ex& res_ex)
den = normalized.op(1);
ex res_den;
bool dres = factorpoly(den, res_den);
if (not nres and not dres)
return false;
if (not nres)
res_ex = num;
if (not dres)
Expand Down

0 comments on commit 787b4be

Please sign in to comment.