gnu-octave / symbolic

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

laplace wrong answer in t*sin() or t*cos() transforms #1295

Closed Ale-AR closed 5 months ago

Ale-AR commented 6 months ago
# Package symbolic v.3.1.1 in GNU Octave Version: 9.1.0
pkg load symbolic
syms t s

laplace(3*t*sin(4*t))
##
##ans = (sym)
##
##        8⋅s
##  ────────────────
##   4       2
##  s  + 32⋅s  + 256

# ERROR - The answer is for laplace(t*sin(4*t))
#         (24·s) was expected in the numerator.

# Now let's edit it and recalculate:

laplace(5*t*sin(4*t))
##
##ans = (sym)
##
##        8⋅s
##  ────────────────
##   4       2
##  s  + 32⋅s  + 256

# ERROR - Same previous answer is repeated.
#         (40·s) was expected in the numerator.

# Same behavior is observed in t*cos():

laplace(5*t*cos(2*t))
##
##ans = (sym)
##
##       2
##      s  - 4
##  ──────────────
##   4      2
##  s  + 8⋅s  + 16

# ERROR - The answer is for laplace(t*cos(2*t))
#         (5·s²-20) was expected in the numerator.

laplace(2*t*cos(2*t))
##
##ans = (sym)
##
##       2
##      s  - 4
##  ──────────────
##   4      2
##  s  + 8⋅s  + 16

# ERROR - Same previous answer is repeated.
#         (2·s²-8) was expected in the numerator.`
cbm755 commented 5 months ago

I cannot reproduce any of these, at least on SymPy v1.12. Perhaps its a bug in an earlier SymPy?

>> syms t s
Symbolic pkg v3.1.1+: Python communication link active, SymPy v1.12.

>> simplify(laplace(3*t*sin(4*t)))
ans = (sym)
        24⋅s      
  ────────────────
   4       2      
  s  + 32⋅s  + 256

>> simplify(laplace(5*t*sin(4*t)))
ans = (sym)
        40⋅s      
  ────────────────
   4       2      
  s  + 32⋅s  + 256

I'll see if I can get these running on our CI tests, which will test over a wider range of versions... but I suspect you'll need to upgrade SymPy, Octave, and/or Symbolic (most likely the first)

cbm755 commented 5 months ago

I see you gave your Octave and Symbolic versions so most likely its SymPy that is too old...

cbm755 commented 5 months ago

Seems it was broken in SymPy 1.10 and 1.11. I figure you were using one of those.

image

Tests in place so it shouldn't happen again! Thanks for the note. "Fixed" in #1298.

Ale-AR commented 5 months ago

You are correct, Octave seems to use Sympy version 1.10.1:

>> pkg load symbolic
>> syms t s
Symbolic pkg v3.1.1: Python communication link active, SymPy v1.10.1.

However, I have version 1.12 installed on my system:

$ pip show sympy
Name: sympy
Version: 1.12

I guess the problem is that I use Flatpak's Octave.