Another way of explaining this is to say that sympy (and all its
competitors) implement arithmetic in a field of fractions, in
which that cancellation is valid.  The perspective of
abstract algebra provides a computational framework for
polynomials and rational functions.  See for example
https://en.wikipedia.org/wiki/Field_of_fractions

Just because we were told to never divide by zero
doesn't mean something like it is illegal in some other context.

You might argue  ...  but but  I don't even know what
a Field of Fractions is!   

And yet, you've (and sympy) have been using it...

Also, Aaron's point below is another, somewhat different
explanation, which is an argument from analysis, heuristically,
rather than algebra, formally.
RJF

On Wednesday, October 18, 2017 at 12:23:48 PM UTC-7, Aaron Meurer wrote:
>
> Cancellation of removable singularities is useful enough that it's 
> included in the default simplify() heuristics. Without it, it would be 
> quite annoying to most use cases. It's also not uncommon that in the 
> process of creating an expression a removable singularity is created, 
> through multiplying and dividing by some term. 
>
> Some functions are more careful about this. For instance, solve((x**2 
> + x)/((x - 1)*(x + 1)), x) returns [0], not [-1, 0]. 
>
> But also be aware that, for instance, x/x always automatically reduces 
> to 1. This is due to the way the internal representation works in 
> SymPy. a/b is treated like a*b**-1, and exponents on terms with common 
> bases always combine automatically. 
>
> Aaron Meurer 
>
> On Wed, Oct 18, 2017 at 6:28 AM, Kalevi Suominen <[email protected] 
> <javascript:>> wrote: 
> > 
> > 
> > On Wednesday, October 18, 2017 at 3:08:32 AM UTC+3, EKW wrote: 
> >> 
> >> >>> from sympy import * 
> >> >>> x = Symbol('x') 
> >> 
> >> >>> p = (x**2 + x) / ((x - 1)*(x + 1)) 
> >> >>> print(p) 
> >> (x**2 + x)/((x - 1)*(x + 1)) 
> >> >>> p = simplify(p) 
> >> >>> print(p) 
> >> x/(x - 1) 
> >> 
> >> 
> >> This simplification is only valid for x != -1, and I haven't specified 
> any 
> >> restrictions on the range of x. Was this done on purpose, and if so 
> why? 
> > 
> > 
> > Defining x as a Symbol makes it different from any number. 
> > 
> >>>> from sympy import * 
> >>>> x = Symbol('x') 
> >>>> x != -1 
> > True 
> > 
> > It is possible to substitute a number for x, but then then the 
> expression 
> > will also be different. 
> > 
> > Kalevi Suominen 
> > 
> > -- 
> > 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 [email protected] <javascript:>. 
> > To post to this group, send email to [email protected] 
> <javascript:>. 
> > 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/c8ec5e5d-56db-45cd-9ec5-013d7074cac8%40googlegroups.com.
>  
>
> > 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/365da193-f1ec-45d5-87c1-6b4860fca333%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to