Where can I find code, that evaluates add and multiplication operations?

23 views
Skip to first unread message

Michał Pawłowski

unread,
Jun 5, 2021, 4:18:06 AM6/5/21
to sympy
Hi.

Where can I find code, that evaluates Add and Mul operations on real numbers? I've found the code in Pow file (sympy/core/power.py). I know that there are move files in that dir:

(sympy/core/add.py)
(sympy/core/mul.py)

But I cannot find the line of evaluation.

I.E. where is code that evaluates expressions such as "2*3"?

Thanks

Chris Smith

unread,
Jun 5, 2021, 8:01:46 AM6/5/21
to sympy
processing of args, I believe, is handled in Add.flatten and Mul.flatten

/c

Michał Pawłowski

unread,
Jun 5, 2021, 8:21:57 AM6/5/21
to sympy
Hey, thank you. But flatten is executed only then, when argument is symbol, like 2 * x * x (i.e.). But where is code of numbers eval?

Chris Smith

unread,
Jun 5, 2021, 12:09:51 PM6/5/21
to sympy
Try follow from `Numbers.__add__`

/c

David Bailey

unread,
Jun 5, 2021, 6:06:09 PM6/5/21
to sy...@googlegroups.com
On 05/06/2021 17:09, Chris Smith wrote:
> Try follow from `Numbers.__add__`
>
Since Python can handle arbitrary precision numbers, doesn't the final
evaluation happen in Python? I have always assumed that to be the case. 
E.g. 3*4*x*x is converted into 12*x*x by Python (where x is an instance
of a class) and then SymPy does the rest. Surely that is exactly why
there are problems with expressions such as 2/3x**2 because the
coefficient gets turned into a floating point quantity by Python.

David

Aaron Meurer

unread,
Jun 5, 2021, 11:14:06 PM6/5/21
to sympy
If you are talking about numerical evaluation, in SymPy, integers wrap
Python integers, so the operations are done in Python itself. Floating
point numbers wrap mpmath, so the code for those will be in the mpmath
library.

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 view this discussion on the web visit https://groups.google.com/d/msgid/sympy/deac503a-7a72-642e-2cbe-57cba920d30d%40dbailey.co.uk.
Reply all
Reply to author
Forward
0 new messages