I define a function with a condition like that.
ClearAll[foo]; foo[expr_] /; FreeQ[expr, bar] := expr
foo[12 bar] returns not evaluated as
Why is it when I take the derivative
D[foo[12 bar], x] or
D[foo[12 bar], bar] it acts as if the condition is not present, returning
The expected and desired behavior is that the derivative cannot be evaluated. I consider that the result that Mathematica gives is false. My function does not have this output when this condition is not met, and therefore it is not a valid derivative.
I found this specifying in addition that catch everything
foo[_] := 0 means that
D takes the condition into account and uses this definition instead when appropriate, but without it, the condition is ignored as shown above. Move condition to
foo[expr_] /; FreeQ[expr, bar] := expr has no effect on behavior.
I suppose this line of documentation may be relevant: "D returns generic results which may not take discontinuities, cusps or other special points into consideration" Is my condition treated as a special point? I don't want that, I just want it to behave like other functions that cannot be evaluated for an entry.