0

Michael E2 solves the problem of differentiability of multivariate functions.

ClearAll[differentiableQ, dLimit];
differentiableQ[f_, spec : (v_ -> v0_)] := With[{jac = D[f, {v}]},
   Module[{f0, jac0, res},
     {f0, jac0} = {f, jac} /. Thread[spec];
     If[VectorQ[Flatten@{f0, jac0}, NumericQ],
      res = 
       Limit[(f - f0 - jac0.(v - v0))/Sqrt@Total[(v - v0)^2], spec] /.
          HoldPattern[Limit[df_, s_]] /; ! FreeQ[df, Piecewise] :> 
         With[{L = dLimit[df, s]}, L /; FreeQ[L, dLimit]];
      res = FreeQ[res, Indeterminate] &&
         And @@ Thread[Flatten@{res} == 0],
      res = False
      ]] /; VectorQ[jac]
   ];
dLimit[df_, spec_] := Module[{f0, jac0, pcs = {}, z, res},
   pcs = Replace[
     (* Solve[.., Reals] separates PW fn *)
     z /. Solve[z == df, z, Reals],
     {ConditionalExpression[y_, c_] :> {y, c}, y_ :> {y, True}},
     1];
   If[ListQ[pcs],
    res = (Limit[Piecewise[{#}], spec] /.
         HoldPattern[Limit[Piecewise[{{y_, _}}, 0], s_]] :> 
          With[{L = Limit[y, s]}, L /; FreeQ[L, Limit]]
        & /@ pcs)
    ];
   res /; ListQ[pcs]
   ];

But when I applied it to the following univariate function problem, I encountered a problem:

$$\begin{array}{c} (A)\; f(x)=|x| \sin |x| \qquad (B)\; f(x)=|x| \sin \sqrt{|x|} \\ (C)\; f(x)=\cos |x| \qquad (D)\; f(x)=\cos \sqrt{|x|} \end{array}$$

differentiableQ[RealAbs[x] Sin[RealAbs[x]], {x} -> {0}]
differentiableQ[RealAbs[x] Sin[Sqrt[RealAbs[x]]], {x} -> {0}]
differentiableQ[Cos[RealAbs[x]], {x} -> {0}]
differentiableQ[Cos[Sqrt[RealAbs[x]]], {x} -> {0}]

enter image description here

The three functions A, B and C are differentiable at the point x=0, so the judgment result of the function differentiableQ is wrong.

How can I write a general user-defined function that can judge whether piecewise function, univariate function and multivariable function are differentiable at a certain point?

Mathematical analysis process:

$A: \quad f_{+}^{\prime}(0)=\lim _{x \rightarrow 0^{+}} \frac{|x| \sin |x|}{x}=0, f_{-}^{\prime}(0)=\lim _{x \rightarrow 0^{-}} \frac{-x \sin (-x)}{x}=0, \text { So } f^{\prime}(0)=0$

$B: \quad f_{+}^{\prime}(0)=\lim _{x \rightarrow 0^{+}} \frac{x \sin (\sqrt{x})}{x}=0, f_{-}^{\prime}(0)=\lim _{x \rightarrow 0^{-}} \frac{-x \sin (\sqrt{-x})}{x}=0, \Rightarrow f^{\prime}(0)=0$

$C: f_{+}^{\prime}(0)=\lim _{x \rightarrow 0^{+}} \frac{\cos x-1}{x}=\lim _{x \rightarrow 0^{+}} \frac{-\frac{1}{2} x^{2}}{x}=0, f_{-}^{\prime}(0)=\lim _{x \rightarrow 0^{-}} \frac{\cos (-x)-1}{x}=0, \Rightarrow f^{\prime}(0)=0$

$D: \begin{aligned} f_{+}^{\prime}(0)=\lim _{x \rightarrow 0^{+}} \frac{\cos \sqrt{x}-1}{x}=\lim _{x \rightarrow 0^{+}} \frac{-\frac{1}{2} x}{x}=-\frac{1}{2}\\ f_{-}^{\prime}(0)=\lim _{x \rightarrow 0^{-}} \frac{\cos (\sqrt{-x})-1}{x}=\lim _{x \rightarrow 0^{-}} \frac{-\frac{1}{2}(-x)}{x}=\frac{1}{2} \end{aligned}$

  • 1
    In these cases, a simple Limit[D[f[x],x],x->0] already shows whether the function is differentiable - the issue with the "more robust" solution is that inserting 0 into the Jacobian does not work without taking the limit. But since the whole point of this function is to work around the shortcomings on Limit, I'm not sure how to best fix this – Lukas Lang Aug 03 '20 at 08:31
  • @LukasLang Limit[D[f[x],x],x->0] will show whether the derivative is continuous. It fails to show Piecewise[{{x^2 Sin[1/x], x != 0}}] is differentiable at x = 0. – Michael E2 Aug 03 '20 at 12:27
  • 2
    As I mentioned elsewhere, differentiableQ assumes D[] can compute the Jacobian strictly correctly, which it fails to do in these cases. Theoretically, you could replace D[] in jac = D[f, {v}] by the limits for each partial derivative. Of course, Limit is not completely reliable, either. – Michael E2 Aug 03 '20 at 19:14
  • 1
    @MichaelE2 thanks for pointing that out, you're of course correct. When I saw that that method produces the "correct" result (i.e. Indeterminate for only the last example), I didn't think twice about the actual meaning of that limit – Lukas Lang Aug 03 '20 at 20:44

0 Answers0