Skip to content

Commit af3b139

Browse files
committed
add and fill in some more examples
1 parent 78e4582 commit af3b139

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

docs/src/nondiff_points.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,59 @@ gr(framestyle=:origin, legend=false)
3232
plot(x->x^3)
3333
```
3434
This is the standard case, one can returned the derivative that is defined according to school room calculus.
35-
An interesting thing a bout `x->x^3` is that at `x=0` the derivative is defined,
36-
but neither the sub-derivative nor super-derivative is defined.
35+
Here we would reasonably say that at `x=0` the derivative is `3*0^2=0`.
36+
37+
38+
An interesting thing about `x->x^3` is that at `x=0` the derivative is defined, but neither the sub-derivative nor super-derivative is defined.
3739

3840
### Local Minima / Maxima
3941

4042
```@example nondiff
4143
plot(abs)
4244
```
4345

46+
`abs` is the classic example of a function where the derivative is not defines as the limit from above is not equal to the limit from below
47+
48+
$$\mathrm{abs}'(0) = \lim_{h->0^-} \dfrac{\mathrm{abs}(0)-\mathrm{abs}(0-h)}{0-h} = -1$$
49+
$$\mathrm{abs}'(0) = \lim_{h->0^+} \dfrac{abs(0)-\mathrm{abs}(0-h)}{0-h} = 1$$
50+
51+
Now, as discussed in the introduction the AD system would on it's own choose either 1 or -1, depending on implementation.
52+
53+
We however have a potentially much nicer answer available to use: 0.
54+
55+
This has a number of advantages.
56+
- It follows the rule that derivatives are zero at local minima (and maxima).
57+
- If you leave a gradient decent optimizer running it will eventually actually converge absolutely to the point -- where as with it being 1 or -1 it would never outright converge it would always flee.
58+
59+
Further:
60+
- It is a perfectly nice member of the [subderivative](https://en.wikipedia.org/wiki/Subderivative).
61+
- It is the mean of the derivative on each side; which means that it will agree with central finite differencing at the point.
4462
### Piecewise slope change
4563
```@example nondiff
4664
plot(x-> x < 0 ? x : 5x)
4765
```
4866

49-
### Zero almost everywhere
67+
### Derivative zero almost everywhere
68+
69+
```@example nondiff
70+
plot(ceil)
71+
```
72+
73+
### Primal finite, and derivative nonfinite and same on both sides
5074

5175
```@example nondiff
52-
plot(round)
76+
plot(cbrt)
5377
```
5478

55-
### Non-finite and same on both sides
79+
80+
(derivative nonfinite and different on each side is not possible with a finite and defined primal.)
81+
### Primal and derivative Non-finite and same on both sides
5682
```@example nondiff
5783
plot(x->inv(x^2))
5884
plot!(; xlims=(-1,1), ylims=(-100,100)) #hide
5985
```
6086

61-
### Non-finite and differing on both sides
87+
### Primal and gradient Non-finite and differing on both sides
6288
```@example nondiff
6389
plot(inv)
6490
plot!(; xlims=(-1,1), ylims=(-100,100)) #hide

0 commit comments

Comments
 (0)