symbolic manipulation -- insufficient simplification

31 views
Skip to first unread message

Robert Samal

unread,
Nov 1, 2019, 6:40:28 PM11/1/19
to sage-support
I observed the following weird behavior of the symbolic engine.

sage: x/x
1
sage
: x^2/x
x
sage
: (x^2+x)/x
(x^2 + x)/x
sage
: assume(x>0)
sage
: assume(x,'real')
sage
: assumptions()
[x > 0, x is real]
sage
: (x^2+x)/x
(x^2 + x)/x

To clarify: first, I consider the first two simplifications slightly incorrect (x/x is undefined if x=0, or possibly if x is in some weird algebraic structure). However, if x/x==1 and x^2/x==x then I wonder why simplification of (x^2+x)/x is not done?

In this case, .simplify() does not help, .full_simplify() does. In my original example though, .full_simplify() did something crazy, so I was led to this.

In general, is there some explanation regarding which simplifications one can expect to be done automatically and which by the two simplify-functions?

Thanks!



Emmanuel Charpentier

unread,
Nov 3, 2019, 5:58:25 AM11/3/19
to sage-support
From the docstrings:

sage: x.simplify?
   Return a simplified version of this symbolic expression.

   Note: Currently, this just sends the expression to Maxima and
     converts it back to Sage.

   See also: "simplify_full()", "simplify_trig()",
     "simplify_rational()", "simplify_rectform()"
     "simplify_factorial()", "simplify_log()", "simplify_real()",
     "simplify_hypergeometric()", "canonicalize_radical()"

Not very informative, ... and Maxima's simplifications are numerous, complex and somewhat difficult to follow.

sage: x.simplify_full?
   Apply "simplify_factorial()", "simplify_rectform()",
   "simplify_trig()", "simplify_rational()", and then "expand_sum()"
   to self (in that order).


Note that you have also:

sage: assumptions()
[]
sage: ((x^2+x)/x).collect_common_factors()
x + 1
sage: x.collect_common_factors?
   This function does not perform a full factorization but only looks
   for factors which are already explicitly present.

   Polynomials can often be brought into a more compact form by
   collecting common factors from the terms of sums. This is
   accomplished by this function.

and

sage: ((x^2+x)/x).canonicalize_radical()
x + 1
sage: x.collect_common_factors?
   This function does not perform a full factorization but only looks
   for factors which are already explicitly present.

   Polynomials can often be brought into a more compact form by
   collecting common factors from the terms of sums. This is
   accomplished by this function.

And, indeed, these functions do more or less undocumented assumptions...

HTH,
Reply all
Reply to author
Forward
0 new messages