Bug with O(f) if f is a Function
jbarber-phys opened this issue · comments
Jonah Barber commented
The order function sympy.O(f) breaks if the type of f is a Function (but works fine for symbols); it throws out all terms, even lower order ones.
Example:
import sympy as sym
x = sym.symbols("x")
print((x+x**2+x**3+sym.O(x**3)))#will print: x + x**2 + O(x**3)
f = sym.Function("f")(x)
print((f+f**2+f**3+sym.O(f**3)))#will print: O(f(x)**3)
This was on Windows 11 python 3.12.1 (x64), sympy 1.12 .
Oscar Benjamin commented
The use of free symbols here means that variables is x rather than f(x):
Line 139 in 8ae2a54
It seems that Order thinks that
O(f(x)**3)
should be understood as a function of x
rather than a function of f(x)
.Jonah Barber commented
I see. Unfortunately though, sym.O is not setup to accept functions as free symbols.
I have found a workaround involving replacing the function with a dummy symbol (and undoing this after calling O and removeO ).
Thank you.