From f2fa99b4533e6ef7ab5455d5b5f0337005a0993b Mon Sep 17 00:00:00 2001 From: Martin Bauer <martin.bauer@fau.de> Date: Wed, 22 Aug 2018 07:34:49 +0100 Subject: [PATCH] Functional derivative: support for piecewise functions --- fd/derivative.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fd/derivative.py b/fd/derivative.py index 902bda803..cd74b0fe5 100644 --- a/fd/derivative.py +++ b/fd/derivative.py @@ -304,6 +304,8 @@ def expand_diff_full(expr, functions=None, constants=None): processed_diff = normalize_diff_order(Diff(dependent_term, **diff_args)) result += independent_terms * prod(other_dependent_terms) * processed_diff return result + elif isinstance(e, sp.Piecewise): + return sp.Piecewise(*((expand_diff_full(a, functions, constants), b) for a, b in e.args)) else: new_args = [visit(arg) for arg in e.args] return e.func(*new_args) if new_args else e @@ -341,6 +343,8 @@ def expand_diff_linear(expr, functions=None, constants=None): return 0 else: return diff.split_linear(functions) + elif isinstance(expr, sp.Piecewise): + return sp.Piecewise(*((expand_diff_linear(a, functions, constants), b) for a, b in expr.args)) else: new_args = [expand_diff_linear(e, functions) for e in expr.args] result = sp.expand(expr.func(*new_args) if new_args else expr) -- GitLab