From 669376a9cc69f9ff264711056f7e1066a4c44e46 Mon Sep 17 00:00:00 2001 From: King Date: Tue, 2 Jan 2024 04:18:11 +0100 Subject: [PATCH] Update Derivative.md * Update the mathematical expressions for easy comprehension * Add a note on for variables `con` & `var` for non-technical people to understand * made some grammatical fixes --- .../Recipes/Common/Derivative/Derivative.md | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/courses/Recipes/Common/Derivative/Derivative.md b/courses/Recipes/Common/Derivative/Derivative.md index 8322608b0..55d4f7b69 100644 --- a/courses/Recipes/Common/Derivative/Derivative.md +++ b/courses/Recipes/Common/Derivative/Derivative.md @@ -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 @@ -65,12 +64,16 @@ 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`: @@ -78,7 +81,7 @@ Let's differentiate the example expression `E`: 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)))); ```