Hi Jatin,
thanks, this looks very promising. I haven’t used polynomials much yet, since
simple symbolic expressions do everything I need, and it looks like I have a
deficit there. Here is my current code:
from sympy.polys.domains import QQ
from sympy.polys.rings import ring
from sympy.polys.ring_series import rs_asin
R, m = ring('HillSeries2.m', domain='QQ')
α = rs_asin(α, HillSeries2.m, 3) # should be 11
Exception in the last line:
'Add' object has no attribute 'ring'
It looks like my expression needs to be a polynomial
I added a line
α = α.as_poly(domain='QQ')
but that didn’t help.
In the sample code
R, m = ring('HillSeries2.m', domain='QQ')
is not documented very well. It looks like it is defining a ring R, but not
using it, but my IDE doesn’t give me a warning for that.
I am using documentation
https://docs.sympy.org/latest/modules/polys/ringseries.html#rs-series
Tom
(Dr. Thomas S. Ligon)
<mailto:[email protected]> [email protected]
Frohnloher Str. 6a
81475 Muenchen
Germany
Tel. +49(89)74575075
Von: [email protected] <[email protected]> Im Auftrag von Jatin
Bhardwaj
Gesendet: Montag, 24. Februar 2025 22:08
An: sympy <[email protected]>
Betreff: [sympy] Re: sympy process out of memory calculating series of asin
Hi Tom,
Instead of series(asin(α)), you can use SymPy’s ring_series.rs_asin, which is
optimized for power series manipulations and significantly reduces memory usage.
```
from sympy.polys.rings import ring
from sympy.polys.ring_series import rs_asin
R, x = ring('x', domain='QQ')
asin_series = rs_asin(x, 11)
print(asin_series)
```
This method is much more efficient and avoids the heavy symbolic
differentiation that series() performs.
You can also check out the documentation for the rs_series
<https://docs.sympy.org/latest/modules/polys/ringseries.html#rs-series> in
`ring series` module.
Jatin Bhardwaj
On Monday, 24 February 2025 at 13:52:57 UTC+5:30 [email protected]
<mailto:[email protected]> wrote:
I am using sympy to analyze and run some code involving power series. In
general, the code is always running on a partial sum of a power series, and
this is a normal sympy symbolic expression. After doing certain calculations,
the data is no longer a series, and I need to run a Taylor expansion in order
to get a series. For example, if I calculate the quotient of two partial sums,
I need Taylor in order to get another partial sum. In sympy, it is very
convenient to call series() to do this.
Now it is clear that this can use a lot of memory, because every additional
derivative makes the expression more complex and longer. It appears as though
series() does not use parallel processing, so the result is 100% usage of one
CPU and increasing use of memory. On my laptop (running Windows 11 and Visual
Studio), I have 16GB RAM and have sometimes run into memory issues.
To solve this problem, I have allocated an Ubuntu Linux virtual machine on the
Internet (Microsoft Azure). The machine has 2 virtual CPUs and 218GB RAM. With
this, I have successfully calculated partial sums up to order 24 or 31. This
sometimes runs at 100% CPU allocation for more than 24 hours and completes
successfully.
Up to now, I have used series() for algebraic expressions of partial sums
(quotient, square root, etc.) but recently started applying this to a
trigonometric expression. This is because I need to calculate the solution of a
cubic equation and the Cardano formula has run into unpleasant situations
involving complex numbers, and I have been given a recommendation to try the
trigonometric formula instead. Up to now, it looks very good, since the primary
solution is real and does not require complex components. By the way, solving a
cubic equation worked will with both the standard formula and via solve(). For
the cubic equation, I have started with the formula because I can see if each
individual step success before proceeding to the next one.
Specifically, my code is
α = asin(α)
α = series(α, m, n=maxK+1) # calculate series up to maxK
On my laptop, the series statement runs for some time and hits the memory limit
of my PC, so I tried running this on the VM, which has more memory and does not
have the overhead of Windows or Visual Studio.
This first attempt ran for somewhere between 24 and 30 hours and the VM was
stopped. This is presumably because the VM is configured to use a “spot price”,
meaning that the administrators can stop it at any time they need additional
capacity for something else.
The second attempt ran for somewhere between 30 and 48 hours and my output file
ended in the statement killed. Running dmesg gave me this information:
[144763.491084]
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-1.scope,task=python3.9,pid=1699,uid=1000
[144763.491101] Out of memory: Killed process 1699 (python3.9)
total-vm:226036448kB, anon-rss:223754920kB, file-rss:2740kB, shmem-rss:0kB,
UID:1000 pgtables:438192kB oom_score_adj:0
[144772.062513] oom_reaper: reaped process 1699 (python3.9), now anon-rss:0kB,
file-rss:0kB, shmem-rss:0kB
In this case, my partial sum is of order 11, and it would be very valuable for
me to achieve this solution, but I don’t need to go past 11.
Is this to be expected? Since the derivative of arcsin is 1/sqrt(1-x**2), I
expect the calculations to be no worse than what I have done in the past.
Is there any reason why series(asin(α)) would be expected to fail?
Should I try anything else?
Tom
(Dr. Thomas S. Ligon)
[email protected] <mailto:[email protected]>
Frohnloher Str. 6a
81475 Muenchen
Germany
Tel. +49(89)74575075 <tel:+49%2089%2074575075>
--
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 [email protected]
<mailto:[email protected]> .
To view this discussion visit
https://groups.google.com/d/msgid/sympy/86f0738d-851f-48e3-9793-f1709a9f1c24n%40googlegroups.com
<https://groups.google.com/d/msgid/sympy/86f0738d-851f-48e3-9793-f1709a9f1c24n%40googlegroups.com?utm_medium=email&utm_source=footer>
.
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/sympy/000a01db882b%2451820b90%24f48622b0%24%40gmail.com.