1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> match exp(x) with
exp(x) : (1)
sin(x) : (2)
default : (3);
1
>
> match sin(x) with
exp(x) : (1)
sin(x) : (2)
default : (3);
2
>
> match exp(sin(x)) with
exp(x) : ("Exponential of x")
exp(sin(x)) : ("Exponential of sine of x")
default : ("Something else");
Exponential of sine of x
>
> match exp(sin(x)) with
exp(x) : ("Exponential of x")
exp(a) : ("Exponential of " @ a)
default : ("Something else");
Exponential of sin(x)
>
>
> procedure differentiate(f) {
return match f with
g + h : (differentiate(g) + differentiate(h))
g * h : (differentiate(g) * h + differentiate(h) * g)
g / h : ((differentiate(g) * h - differentiate(h) * g) / (h^2))
exp(_x_) : (exp(_x_))
sin(_x_) : (cos(_x_))
cos(_x_) : (-sin(_x_))
g(h) : ((differentiate(g))(h) * differentiate(h))
_x_ : (1)
h(_x_) : (NaN)
c : (0);
};
>
> rename(x,y);
Information: the free variable has been renamed from "x" to "y".
> differentiate(exp(sin(y + y)));
exp(sin(y * 2)) * cos(y * 2) * 2
> diff(exp(sin(y + y)));
exp(sin(y * 2)) * cos(y * 2) * 2
>
\end{Verbatim}
\end{minipage}\end{center}
|