I define a function with a condition like so.
ClearAll[foo]; foo[expr_] /; FreeQ[expr, bar] := expr
foo[12 bar] returns unevaluated as
Why is it that when I take the derivative
D[foo[12 bar], x] or
D[foo[12 bar], bar] it acts as if the condition were not present, returning
The expected and desired behaviour is that the derivative is not able to be evaluated. I consider the result that Mathematica gives to be wrong. My function does not have that output when that condition is not met, and that is therefore not a valid derivative.
I've found that additionally specifying that catch all
foo[_] := 0 means that
D does take notice of the condition and uses that definition instead when appropriate, but without it the condition is ignored as shown above. Moving the condition to
foo[expr_] /; FreeQ[expr, bar] := expr has no effect on the behaviour.
I guess that this line from the documentation may be relevant: "D returns generic results that may not account for discontinuities, cusps or other special points" Is my condition being treated as a special point? I don't want that, I just want it to behave like other functions that can't be evaluated for some input.