sympy / sympy

A computer algebra system written in pure Python
https://sympy.org/
Other
12.98k stars 4.43k forks source link

NotImplementedError: Improve MV Derivative support #26028

Open ShrohanMohapatra opened 10 months ago

ShrohanMohapatra commented 10 months ago
from sympy import symbols, Function, diff, collect, simplify

# Define symbols
x, t = symbols('x t')
u2 = Function('u2')(x, t)
phi = Function('phi')(x, t)

# Define the expression
expr = diff(diff(phi, x, t) + diff(phi, x, x) * u2 + diff(phi, (x, 4)), x)

# Attempt to simplify the expression
simplified_expr = simplify(expr)

# Apply collect to the simplified expression
collected_expr = collect(simplified_expr, x)

# Display the collected expression
print("Collected Expression:", collected_expr)

This leads to the following error:

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in collect(expr, syms, func, evaluate, exact, distribute_order_term) 358 if expr.is_Add: 359 o = expr.getO() or 0 --> 360 expr = expr.func(*[ 361 collect(a, syms, func, True, exact, distribute_order_term) 362 for a in expr.args if a != o]) + o

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in (.0) 359 o = expr.getO() or 0 360 expr = expr.func(*[ --> 361 collect(a, syms, func, True, exact, distribute_order_term) 362 for a in expr.args if a != o]) + o 363 elif expr.is_Mul:

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in collect(expr, syms, func, evaluate, exact, distribute_order_term) 389 c, nc = product.args_cnc(split_1=False) 390 args = list(ordered(c)) + nc --> 391 terms = [parse_term(i) for i in args] 392 small_first = True 393

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in (.0) 389 c, nc = product.args_cnc(split_1=False) 390 args = list(ordered(c)) + nc --> 391 terms = [parse_term(i) for i in args] 392 small_first = True 393

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in parse_term(expr) 279 sexpr, rat_expo = exp(tail), coeff 280 elif isinstance(expr, Derivative): --> 281 sexpr, deriv = parse_derivative(expr) 282 283 return sexpr, rat_expo, sym_expo, deriv

/usr/local/lib/python3.9/site-packages/sympy/simplify/radsimp.py in parse_derivative(deriv) 215 order += 1 216 else: --> 217 raise NotImplementedError( 218 'Improve MV Derivative support in collect') 219

NotImplementedError: Improve MV Derivative support in collect

oscarbenjamin commented 10 months ago

A simpler demonstration is:

In [8]: f(x, y).diff(x, y).collect(x)
---------------------------------------------------------------------------
NotImplementedError: Improve MV Derivative support in collect