Skip to content

Commit

Permalink
Merge pull request #42 from tdadadavid/patch-2
Browse files Browse the repository at this point in the history
Update Derivative.md
  • Loading branch information
jurgenvinju authored Jan 5, 2024
2 parents 986f331 + 669376a commit 8d98667
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions courses/Recipes/Common/Derivative/Derivative.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ Symbolic differentiation.

#### Description

Computing the [derivative](http://en.wikipedia.org/wiki/Differentiation_(mathematics)) of an expression with respect to some variable is a classical calculus problem. Loosely speaking, a derivative can be thought of as how much one quantity is changing in response to changes in some other quantity; for example, the derivative of the position of a moving object with respect to time is the object's instantaneous velocity.
Computing the [derivative](http://en.wikipedia.org/wiki/Differentiation_(mathematics)) of an expression with respect to some variable is a classical calculus problem. Loosely speaking, a derivative can be thought of as how much one quantity changes in response to changes in some other quantity; for example, the derivative of the position of a moving object with respect to time is the object's instantaneous velocity.

We present here rules for determining the derivative `dE/dX` of simple expressions `E` for a given variable `X`. Recall that for number `N`, variables `X` and `Y`, and expressions `E1` and `E2` the following rules apply:

* `dN / dX = 0`.
* `dX / dX = 1`.
* `dX / dY = 0`, when `X != Y`.
* `d(E1 + E2) /dX = dE1 / dX + d E2 /dX`.
* `d(E1 * E2) / dX = (d E1 / dX * E2) + (E1 * d E2 /dX)`.
We present here rules for determining the derivative `dE/dX` of simple expressions `E` for a given variable `X`. Recall that for the number `N`, variables `X` and `Y`, and expressions `E1` and `E2` the following rules apply:

* $\frac{dN}{dX} = 0$
* $\frac{dX}{dX} = 1$
* $\frac{dX}{dY} = 0$, when $X \neq Y$
* $\frac{d(E1 + E2)}{dX} = \frac{dE1}{dX} + \frac{dE2}{dX}$
* $\frac{d(E1 \cdot E2)}{dX} = \frac{dE1}{dX} \cdot E2 + E1 \cdot \frac{dE2}{dX}$

#### Examples

Expand Down Expand Up @@ -65,20 +64,24 @@ test bool tstSimplity1() = simplify(mul(var("x"), add(con(3), con(5)))) == mul(v
test bool tstSimplity2() = simplify(dd(E, var("x"))) == con(5);
```

NOTE:
* `con` stands for `constant` for example 1, 10, 99.
* `var` stands for `variable` for example y, x, m.

<1> Define a data type `Exp` to represent expressions.
<2> Introduce an example expression `E` for later use.
<3> Define the actual differentiation function `dd`. Observe that this definition depends on the use of patterns in function declarations, see [Rascal:Function].
<4> Define simplification rules.
<5> A default rule is given for the case that no simplification applies.
<6> Define the actual simplication function `simplify` that performs a bottom up traversal of the expression, applying simplification rules on ascend.
<6> Define the actual simplification function `simplify` that performs a bottom-up traversal of the expression, applying simplification rules on ascending.

Let's differentiate the example expression `E`:
```rascal-shell,continue
dd(E, var("x"));
```
As you can see, we managed to compute a derivative, but the result is far more complex than we would like.
This is where simplification comes in. First try a simple case:
This is where simplification comes in. First, try a simple case:
```rascal-shell,continue
simplify(mul(var("x"), add(con(3), con(5))));
```
Expand Down

0 comments on commit 8d98667

Please sign in to comment.