On Thu, 14 May 2020 at 08:01, David Bailey <d...@dbailey.co.uk> wrote:
>
>
> Well I assumed all along that Poly objects were a much more efficient way of 
> representing  polynomials - presumably an array of tuples of coefficients and 
> exponents where the coefficient is non-zero. If these things are all 
> converted back before the user gets the result, that is just fine. The 
> comparison with Mathematica is interesting, but maybe lead me astray. There 
> there are multiple types of objects (e.g. integers, integer arrays, etc) that 
> behave and display identically to users but have a different internal 
> structures and iner-rconvert silently as required.

I'm not familiar with Mathematica myself but the way this works in
sympy is that an expression will be converted to Poly internally by
algorithms that need it. For example when calling factor(expr) the
expression will be converted to a Poly and the factorisation algorithm
is performed with the resulting Poly. This happens internally though
so that from the user perspective factor is called with Expr and
returns Expr. The Poly class is available to users for doing efficient
calculations with polynomials but to get the advantages of the
efficient calculations you need to be clear that you are using Poly
and not mix it up with Expr.

This is similar to the way in Python that you need to be careful not
to mix floats into a calculation that involves ints. Provided you
don't input any floats most operations with int will give int. There
is one exception though in Python 3 which is that dividing two ints
gives a float so division is the operation to be careful about. This
is done because in general the ratio of two integers is not an
integer. Sometimes it is an integer but it's important that the type
of the output be predictable so a float is always returned even if the
result could be an int. Likewise with Poly most operations will give
Poly e.g. Poly+Poly->Poly but division will always give Expr:
Poly/Poly->Expr.

--
Oscar

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxT-CPASgNJ4Dooj%2BA2dr-m5bJA-D-gzJK_CAt7WJuK-Yw%40mail.gmail.com.

Reply via email to