gnu-octave / symbolic

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

prevent "pi" or any selected symbol being used when evaluating statements, when calculating pi itself #1050

Open goofyseeker311 opened 3 years ago

goofyseeker311 commented 3 years ago

somehow the below statement should not produce or use "pi" internally in its calculation, how to make a "prevent using list"

sympref digits 100;theta_O = vpa ('10^-100');sind(theta_O)*180/theta_O ans = (sym)

1.8e+102sin(5.555555555555555555555555555555555555555555555555555555555555555555555555555555555555555 555555555556e-103pi)

cbm755 commented 2 years ago

Another example:

sympref digits 64
a = sym(2) / 3
b = vpa(a)
c = b * pi
c = (sym) 0.6666666666666666666666666666666666666666666666666666666666666667⋅π

And as in @goofyseeker311's example, we probably expected that pi to muliple explicitly.

One way to force this is to wrap the result in vpa, as in:

vpa(c)
ans = (sym) 2.094395102393195492308428922186335256131446266250070547316629728

Trying this in the example given above:

>> Y = sind(theta_O)*180/theta_O
Y = (sym) 1.8e+102⋅sin(5.555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555556e-103⋅π)

>> vpa(Y)
ans = (sym) 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068

>> vpa(Y) - pi
ans = (sym) 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068 - π

>> vpa(ans)
ans = (sym) -2.868892801759637438498898060495711247819338484968719192807696702690606067300137497850281208367846969e-102

Not sure what could be easily done about this except trying to make upstream SymPy's Float to be more greedy about combining with other numbers.