Future of SymPy part 2: polynomials

74 views
Skip to first unread message

Oscar Benjamin

unread,
Sep 6, 2023, 7:08:17 PM9/6/23
to sympy
Hi all,

I have a new blog post following the last one:
https://oscarbenjamin.github.io/blog/czi/post2.html

This one discusses SymPy's polynomial system, improvements that can be
made and in particular how to make use of python-flint to speed up
polynomial operations in SymPy.

--
Oscar

peter.st...@gmail.com

unread,
Sep 7, 2023, 6:14:52 AM9/7/23
to sy...@googlegroups.com
Dear Oscar,

While 99% is way above my head (I studied engineering 40+ years ago), it is fascinating reading!
I had no idea, how much 'math' was in sympy.

In your post you write:

if gmpy2 is installed then SymPy will use it and will be a lot faster for some operations but with no other observable change in behaviour.

I only use sympy through symy.physics.mechanics, to pass my time doing simulations, and I do it on Jupyter notebook.
Would gmpy2 potentially speed up the formation of Kane's equation of motion?

Thanks & take care!

Peter
--
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/CAHVvXxR%3DPJen0wgMm%3D%2BOWEyOQ%3DhaCHMVtcqSdbCcwQZ1adxW8w%40mail.gmail.com.

Oscar Benjamin

unread,
Sep 7, 2023, 6:41:37 AM9/7/23
to sy...@googlegroups.com
On Thu, 7 Sept 2023 at 11:14, <peter.st...@gmail.com> wrote:
>
> Dear Oscar,
>
> While 99% is way above my head (I studied engineering 40+ years ago), it is fascinating reading!
> I had no idea, how much 'math' was in sympy.
>
> In your post you write:
>
> if gmpy2 is installed then SymPy will use it and will be a lot faster for some operations but with no other observable change in behaviour.
>
> I only use sympy through symy.physics.mechanics, to pass my time doing simulations, and I do it on Jupyter notebook.
> Would gmpy2 potentially speed up the formation of Kane's equation of motion?

It is very easy to install gmpy2 (pip install gmpy2) to see if it does
speed anything up.

I don't think that the mechanics module explicitly uses any of the
low-level polynomial code so the question would be whether something
like cancel or factor is being used somewhere. My expectation is that
things like that would be avoided in mechanics. The next post will
talk about matrices which is more relevant for the mechanics module
although the matrices would be matrices of polynomials so having fast
polynomials also makes a big difference to linear algebra. This would
be very relevant to our previous discussion here:
https://github.com/sympy/sympy/issues/24679

--
Oscar

Aaron Meurer

unread,
Sep 8, 2023, 3:10:17 AM9/8/23
to sy...@googlegroups.com
I posted this to Hacker News, where it got some comments.
https://news.ycombinator.com/item?id=37426080

Aaron Meurer

peter.st...@gmail.com

unread,
Sep 8, 2023, 3:13:52 AM9/8/23
to sy...@googlegroups.com
Dear Oscar,

Thanks!
I installed it (I used anaconda, rather than pip), all went well.
As you predicted, I did not find any difference so far, will keep on observing.

Thanks again!

Peter

-----Original Message-----
From: sy...@googlegroups.com <sy...@googlegroups.com> On Behalf Of Oscar Benjamin
--
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/CAHVvXxQWcQNG9Fyb6_aZx4jOOZKjR11RN7mTfppSGdoVLns_MQ%40mail.gmail.com.

Aaron Meurer

unread,
Sep 8, 2023, 3:15:33 AM9/8/23
to sy...@googlegroups.com
By the way, if you install SymPy from conda-forge, they gmpy2 will be installed automatically. If you use conda-forge chances are you've already been using it this whole time. 

Aaron Meurer 

peter.st...@gmail.com

unread,
Sep 8, 2023, 3:20:33 AM9/8/23
to sy...@googlegroups.com

Dear Aaron,

 

Thanks!

YES, I installed sympy from anaconda.

But when I installed gmpy2 yesterday, I did not get a message like ‘exists already in the environment’ or similar.

(I know nothing about anaconda, just follow the installation instructions given to me by my son)

 

Thanks!

 

Peter

Aaron Meurer

unread,
Sep 8, 2023, 2:49:57 PM9/8/23
to sy...@googlegroups.com
Also I resubmitted part 1 at the request of the HN mods and it has
some comments as well https://news.ycombinator.com/item?id=37430759

Aaron Meurer

David Bailey

unread,
Sep 10, 2023, 11:37:28 AM9/10/23
to sy...@googlegroups.com
Many thanks for that Oscar ,

For me, it started out easy, but went above my head at some point -
which is probably ideal for learning something new.

I was amazed that converting an integer to a decimal string could cause
a denial of service problem. Is that because it is used for public key
encryption (RSA or similar), or just because a server processing
mathematical problems online might be crashed in this way?

Best wishes, David



Oscar Benjamin

unread,
Sep 10, 2023, 12:13:48 PM9/10/23
to sy...@googlegroups.com
The worry is that you might have say a website where a user clicks on
some buttons and that sends some data to a server like

{
username: david
bonus_points: 100000000000000000
}

Then the server would parse the data like

bonus_points = int(data['bonus_points']) # convert the string to an integer

Then if an attacker sends many requests with long strings for
bonus_points the slow calls to int() might lock up the server. Of
course the server code could do something like:

if len(balance_string) > 100:
return Error("Absurd balance")

balance = int(balance_string)

The CPython folks decided that there were likely to be too many places
in too many codebases that used int() without considering this problem
and so it was not practical to fix them all.

--
Oscar
Reply all
Reply to author
Forward
0 new messages