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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sympy
Try follow from `Numbers.__add__`
/c
David Bailey
unread,
Jun 5, 2021, 6:06:09 PM6/5/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.