Automatic simplification leads to wrong results in domain determination

55 views
Skip to first unread message

Kshitij Saraogi

unread,
Jun 23, 2016, 6:27:33 AM6/23/16
to sympy
While developing the methods for determining the domain and range of the given function, 
I stumbled across the following particular case:

In []: x = symbols('x')

In []: x/x
Out[]: 1

In []: (x-1)**2/(x-1)
Out[]: x - 1

In []: (x**2 - 2*x + 1)/(x-1)
Out[]: (x**2 - 2*x + 1)/(x - 1)

Having read this wiki, I know that automatic simplification is a known issue.

In the case of determining domains, this leads to incorrect results.
For example, 

In []: continuous_domain(x/x, x,S.Reals)
Out[]:
(-oo, 0) U (0, oo)

However, with the automatic simplification, this is not quite the case.
The function `x/x` gets automatically simplified to `1` which does not take into account the singularity at x = 0.

The same situation arises with the case of `(x - 1)^2/ (x - 1)` which simplifies to `x - 1`.

I would like some inputs on handling these issues.

Aaron Meurer

unread,
Jun 23, 2016, 12:23:42 PM6/23/16
to sy...@googlegroups.com
Combining exponents is such a common operation that not doing so would
be a huge burden on the whole system. I think you'll just have to put
a note in the continuous_domain docstring that this sort of thing
happens.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/65fc3b03-cdb9-450b-b2f9-2e4cd402d846%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Richard Fateman

unread,
Jun 26, 2016, 10:40:18 AM6/26/16
to sympy
Maybe you are mischaracterizing what you are doing, but in my view you don't  determine the domain and range of
a function by looking at its defining expression.  That is something that is part of the definition of the function.
What is the domain of sin()?   Well, it could be the reals, it could be complex numbers, or maybe for your
particular problem it might be 0 to 2*pi.

If you are interested in locating singularities of a function, then you might need to distinguish
removable singularities from non-removable ones.  Sometimes the simplifier will simplify away
the removable singularities.   (There are also regular and irregular singularities in the context
of differential equations, if you are looking at them.)

As for how to find singularities of  E(x),  maybe solve 1/E(x)=0.  That will find some of them
but not all.  What methods did you have in mind?

RJF
Reply all
Reply to author
Forward
0 new messages