Dear Group,
It seems unfortunate that Python evaluates fractions such as 1/2
to 0.5, whereas SymPy recognises that in algebraic expressions
fractions should rarely be evaluated to a decimal number. This
means that if, for example, you input 3*x**2/2, you get a nice
algebraic expression, but if you enter
(3/2)*x**2
you get
1.5*x^2
This problem is particularly unfortunate if you cut and paste expressions a lot, as I tend to do.
I wonder if any thought has been given to this - I know you can always input Rational(3/2), but that seems very clumsy.
David
If you are using the Jupyter notebook you can run from sympy import init_session init_session(auto_int_to_Integer=True) This also works in IPython in the terminal, or you can use isympy -i. This will automatically wrap integer literals with Integer() so that 1/2 produces Integer(1)/Integer(2).
Just be aware that this could break non-SymPy things if they don't work properly with Integer, for example, numpy will create arrays with dtype=object when passed Integer.
If the issue is only for copy-pasting, I would just use sympify() to convert the input as a string.
David
There is some discussion about this behavior here and in linked issues
https://github.com/sympy/sympy/issues/16378 (possibly other places as
well, it's hard to search the issue tracker for this).
Even so, it does seem reasonable to me that simplify(1.0*x) should
return x, even if 1.0*x stays as it is without simplification.
Aaron Meurer
On Mon, Jun 1, 2020 at 6:10 AM Oscar Benjamin
<oscar.j...@gmail.com> wrote:
>
> On Mon, 1 Jun 2020 at 10:36, Garth Snyder <ga...@garthsnyder.com> wrote:
> >
> > I believe 1.0 is a floating-point value that's distinct from 1 and presumed to be inexact. If you change the 1.0s and 2.0s to 1 and 2, they will be dropped or cancelled appropriately.
>
> There is a function nsimplify which can do this for you.
> https://docs.sympy.org/latest/modules/simplify/simplify.html#nsimplify
>
> --
> 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 sy...@googlegroups.com.