WOLFRAM|DEMONSTRATIONS PROJECT

Automatic Differentiation

​
x
0
2
y
0
3
a0
1
b0
2
c0
3
enter var
x
y
x + e
x + h e
y + k e
con
a
b
c
op
-
+
*
/
1/x
ln
e^x
y^x
log
10^x
x^2
sin
cos
tan
x^(1/2)
asin
acos
atan
x ⟷ y
chs
pop
clear
generic ops
f
g
F
G
memory
sto1
sto2
sto3
rcl1
rcl2
rcl3
lastx
list of clicked items, expression pile, value pile, at
x
0
= 2, or (
x
0
,
y
0
) = (2,3)and (
a
0
,
b
0
,
c
0
) = (1,2,3)
{}
​
​
sto1
sto2
sto3
This is a dual number expression RPN (reverse Polish notation) calculator for automatic differentiation, modeled on an old-style scientific calculator. Dual numbers are numbers of the form
a+bϵ
, where
a
,
b
are real and
2
ϵ
=0
. (
a+bϵ
is displayed with
a
and
b
in adjacent boxes. Use the calculator to calculate an arithmetic expression in
x+ϵ
and reals
a
,
b
, and
c
). Clicking a value puts the value on top of a pile. Clicking an "op" applies the "op" to the top member(s) of the pile as argument(s), and replaces them on the pile with its value. This is the RPN method of evaluation. The list of buttons clicked will be the reverse Polish notation for the expression. If the result is
f(x+ϵ)
for a function
f
, its value will be
f(x)+f'(x)ϵ
. Thus,
f'(x)
is calculated "automatically". Moreover, this will be the result if
f
is any function computable by the calculator. In fact,
f(x+hϵ)=f(x)+hf'(x)ϵ
. It is as if
f(x+hϵ)
were expanded in a Maclaurin series in
ϵ
, since
2
ϵ
=0
.
Click "x + e", "x + e", "*" to get
2
x
+2xϵ
.
Click "x + e", "x + e", *, "a", +, "x + e", "*" to get
(
2
x
+a)x+(3
2
x
+a)ϵ
.
Click "x + e", "x^2", "x + e", "1/x", "sin", "*" to get
2
x
sin
1
x
+2xsin
1
x
-cos
1
x
ϵ
.
Click "x + h e", "cos", "x^2" to get
2
cos
(x)-2hsin(x)cos(x)ϵ
.
Calculating an expression
f(x+hϵ,y+kϵ)
in dual numbers
x+hϵ
and
y+hϵ
results in
f(x,y)+(h
f
1
(x,y)+k
f
2
(x,y))ϵ
.
For example, to compute the partial derivatives of
x
2
y
2
x
+
2
y
, click "x + h e", "y + k e", "x^2", "*", "x + h e", "x^2", "y + k e", "x^2", "+", "/". The partial derivatives are the coefficients of
h
and
k
in the second box.
Built-in generic functions
f
and
g
of one variable and
F
and
G
of two variables can be used to derive general differentiation formulas.
For example, compute the formula for the derivative of
f(x)
g(x)
by clicking "x + e", "f", "x + e", "g", "/" and for
f(ax)
by clicking "a", "x + e", "*", "f".
The expression pile contains symbolic expressions and the value pile contains these expressions evaluated at
x=
x
0
,
y=
y
0
,
a=
a
0
,
b=
b
0
, and
c=
c
0
. (To get decimal values, set an involved slider to a decimal value.) Click "clear" to start a new calculation. The calculator can also be used to calculate real expressions and their values in
x
,
y
,
a
,
b
, and
c
.