gnu-octave / symbolic

A Symbolic Package for Octave using SymPy
https://octave.sourceforge.io/symbolic/
GNU General Public License v3.0
161 stars 37 forks source link

Error: Simple expressions can yield outputs with more than 4300 characters #1304

Open RandomDude4 opened 4 months ago

RandomDude4 commented 4 months ago

The bug seems to be related to the relatively new addition to python "sys.set_int_max_str_digits()" which I am not sure if it is possible to change within Octave. See example 3 below for something that is easily calculated without symbolic package, but fails in the symbolic package due to incorrect generation of too many digits.

Simple example 1:

sym('0.001^10000')

error: Python exception: ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit occurred while copying variables from Python.

Because it tries to type out "1/100000000000000000000000000..." which would be more than 4300 characters.

Using just the string directly in vpa() works without issues, example 2:

vpa('0.001^10000')

ans = (sym) 1.0000000000000000000000000000000e-30000

This causes a problem when trying to use such expressions in functions, example 3:

syms F(p,k)
F(p,k) = p^k;
vpa(F(0.9999, 10000))

error: Python exception: ValueError: Exceeds the limit (4300 digits) for integer string conversion; use sys.set_int_max_str_digits() to increase the limit occurred while copying variables from Python.

My understanding is that it is not the vpa() command that throws the error, just the evaluation of the F() function that tries to output an equation (text string?) that has more than 4300 characters.

Notes: These are all very simple examples, I actually ran into issues when trying to calculate a real combinatoric problem with many factorials and exponents that in the end cancel out to some realistic number, but it required high precision in the intermediate steps.

The final example of 0.9999^10000 = 0.3679 and can be easily calculated without the symbolic package, but the first example with 1e-3000 cannot.

RandomDude4 commented 4 months ago

I forgot to mention that this was tested in the latest version of Octave (9.2.0), and Symbolic Package (3.2.1).