{ "hash": "00e65a8e8895b92263e299d8d429a885", "result": { "markdown": "# Fundamental Theorem or Calculus\n\n\n\nThis section uses these add-on packages:\n\n``` {.julia .cell-code}\nusing CalculusWithJulia\nusing Plots\nusing SymPy\nusing Roots\nusing QuadGK\n```\n\n\n\n\n---\n\n\nWe refer to the example from the section on [transformations](../precalc/transformations.html#two_operators_D_S) where two operators on functions were defined:\n\n\n\n$$\nD(f)(k) = f(k) - f(k-1), \\quad S(f)(k) = f(1) + f(2) + \\cdots + f(k).\n$$\n\n\nIt was remarked that these relationships hold: $D(S(f))(k) = f(k)$ and $S(D(f))(k) = f(k) - f(0)$. These being a consequence of the inverse relationship between addition and subtraction. These two relationships are examples of a more general pair of relationships known as the [Fundamental theorem of calculus](http://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus) or FTC.\n\n\nWe will see that with suitable rewriting, the derivative of a function is related to a certain limit of `D(f)` and the definite integral of a function is related to a certain limit of `S(f)`. The addition and subtraction rules encapsulated in the relations of $D(S(f))(k) = f(k)$ and $S(D(f))(k) = f(k) - f(0)$ then generalize to these calculus counterparts.\n\n\nThe FTC details the interconnectivity between the operations of integration and differentiation.\n\n\nFor example:\n\n\n> What is the definite integral of the derivative?\n\n\n\nThat is, what is $A = \\int_a^b f'(x) dx$? (Assume $f'$ is continuous.)\n\n\nTo investigate, we begin with the right Riemann sum using $h = (b-a)/n$:\n\n\n\n$$\nA \\approx S_n = \\sum_{i=1}^n f'(a + ih) \\cdot h.\n$$\n\n\nBut the mean value theorem says that for small $h$ we have $f'(x) \\approx (f(x) - f(x-h))/h$. Using this approximation with $x=a+ih$ gives:\n\n\n\n$$\nA \\approx\n\\sum_{i=1}^n \\left(f(a + ih) - f(a + (i-1)h)\\right).\n$$\n\n\nIf we let $g(i) = f(a + ih)$, then the summand above is just $g(i) - g(i-1) = D(g)(i)$ and the above then is just the sum of the $D(g)(i)$s, or:\n\n\n\n$$\nA \\approx S(D(g))(n) = g(n) - g(0).\n$$\n\n\nBut $g(n) - g(0) = f(a + nh) - f(a + 0h) = f(b) - f(a)$. That is, we expect that the $\\approx$ in the limit becomes $=$, or:\n\n\n\n$$\n\\int_a^b f'(x) dx = f(b) - f(a).\n$$\n\n\nThis is indeed the case.\n\n\nThe other question would be\n\n\n> What is the derivative of the integral?\n\n\n\nThat is, can we find the derivative of $\\int_0^x f(u) du$? (The derivative in $x$, the variable $u$ is a dummy variable of integration.)\n\n\nLet's look first at the integral using the right-Riemann sum, again using $h=(b-a)/n$:\n\n\n\n$$\n\\int_a^b f(u) du \\approx f(a + 1h)h + f(a + 2h)h + \\cdots f(a +nh)h = S(g)(n),\n$$\n\n\nwhere we define $g(i) = f(a + ih)h$. In the above, $n$ relates to $b$, but we could have stopped accumulating at any value. The analog for $S(g)(k)$ would be $\\int_a^x f(u) du$ where $x = a + kh$. That is we can make a function out of integration by considering the mapping $(x, \\int_a^x f(u) du)$. This might be written as $F(x) = \\int_a^x f(u)du$. With this definition, can we take a derivative in $x$?\n\n\nAgain, we fix a large $n$ and let $h=(b-a)/n$. And suppose $x = a + Mh$ for some $M$. Then writing out the approximations to both the definite integral and the derivative we have\n\n\n\n$$\n\\begin{align*}\nF'(x) = & \\frac{d}{dx} \\int_a^x f(u) du \\\\\n& \\approx \\frac{F(x) - F(x-h)}{h} \\\\\n&= \\frac{\\int_a^x f(u) du - \\int_a^{x-h} f(u) du}{h}\\\\\n& \\approx \\frac{\\left(f(a + 1h)h + f(a + 2h)h + \\cdots + f(a + (M-1)h)h + f(a + Mh)h\\right)}{h}\\\\\n&- \\quad\n\\frac{\\left(f(a + 1h)h + f(a + 2h)h + \\cdots + f(a + (M-1)h)h \\right)}{h} \\\\\n& = \\left(f(a + 1h) + \\quad f(a + 2h) + \\cdots + f(a + (M-1)h) + f(a + Mh)\\right)\\\\\n&- \\quad\n\\left(f(a + 1h) + f(a + 2h) + \\cdots + f(a + (M-1)h) \\right) \\\\\n&= f(a + Mh).\n\\end{align*}\n$$\n\n\nIf $g(i) = f(a + ih)$, then the above becomes\n\n\n\n$$\n\\begin{align*}\nF'(x) & \\approx D(S(g))(M) \\\\\n&= f(a + Mh)\\\\\n&= f(x).\n\\end{align*}\n$$\n\n\nThat is $F'(x) \\approx f(x)$.\n\n\nIn the limit, then, we would expect that\n\n\n\n$$\n\\frac{d}{dx} \\int_a^x f(u) du = f(x).\n$$\n\n\nWith these heuristics, we now have:\n\n\n> **The fundamental theorem of calculus**\n>\n> Part 1: Let $f$ be a continuous function on a closed interval $[a,b]$ and define $F(x) = \\int_a^x f(u) du$ for $a \\leq x \\leq b$. Then $F$ is continuous on $[a,b]$, differentiable on $(a,b)$ and moreover, $F'(x) =f(x)$.\n>\n> Part 2: Now suppose $f$ is any integrable function on a closed interval $[a,b]$ and $F(x)$ is *any* differentiable function on $[a,b]$ with $F'(x) = f(x)$. Then $\\int_a^b f(x)dx=F(b)-F(a)$.\n\n\n\n:::{.callout-note}\n## Note\nIn Part 1, the integral $F(x) = \\int_a^x f(u) du$ is defined for any Riemann integrable function, $f$. If the function is not continuous, then it is true the $F$ will be continuous, but it need not be true that it is differentiable at all points in $(a,b)$. Forming $F$ from $f$ is a form of *smoothing*. It makes a continuous function out of an integrable one, a differentiable function from a continuous one, and a $k+1$-times differentiable function from a $k$-times differentiable one.\n\n:::\n\n## Using the fundamental theorem of calculus to evaluate definite integrals\n\n\nThe major use of the FTC is the computation of $\\int_a^b f(x) dx$. Rather then resort to Riemann sums or geometric arguments, there is an alternative - *when possible*, find a function $F$ with $F'(x) = f(x)$ and compute $F(b) - F(a)$.\n\n\nSome examples:\n\n\n * Consider the problem of Archimedes, $\\int_0^1 x^2 dx$. Clearly, we have with $f(x) = x^2$ that $F(x)=x^3/3$ will satisfy the assumptions of the FTC, so that:\n\n\n\n$$\n\\int_0^1 x^2 dx = F(1) - F(0) = \\frac{1^3}{3} - \\frac{0^3}{3} = \\frac{1}{3}.\n$$\n\n\n * More generally, we know if $n\\neq-1$ that if $f(x) = x^{n}$, that\n\n\n\n$$\nF(x) = x^{n+1}/(n+1)\n$$\n\n\nwill satisfy $F'(x)=f(x)$, so that\n\n\n\n$$\n\\int_a^b x^n dx = \\frac{b^{n+1} - a^{n+1}}{n+1}, \\quad n\\neq -1.\n$$\n\n\n(Well almost! We must be careful to know that $a \\cdot b > 0$, as otherwise we will encounter a place where $f(x)$ may not be integrable.)\n\n\nWe note that the above includes the case of a constant, or $n=0$.\n\n\nWhat about the case $n=-1$, or $f(x) = 1/x$, that is not covered by the above? For this special case, it is known that $F(x) = \\log(x)$ (natural log) will have $F'(x) = 1/x$. This gives for $0 < a < b$:\n\n\n\n$$\n\\int_a^b \\frac{1}{x} dx = \\log(b) - \\log(a).\n$$\n\n\n * Let $f(x) = \\cos(x)$. How much area is between $-\\pi/2$ and $\\pi/2$? We have that $F(x) = \\sin(x)$ will have $F'(x) = f(x)$, so:\n\n\n\n$$\n\\int_{-\\pi/2}^{\\pi/2} \\cos(x) dx = F(\\pi/2) - F(-\\pi/2) = 1 - (-1) = 2.\n$$\n\n\n### An alternate notation for $F(b) - F(a)$\n\n\nThe expression $F(b) - F(a)$ is often written in this more compact form:\n\n\n\n$$\n\\int_a^b f(x) dx = F(b) - F(a) = F(x)\\big|_{x=a}^b, \\text{ or just expr}\\big|_{x=a}^b.\n$$\n\n\nThe vertical bar is used for the *evaluation* step, in this case the $a$ and $b$ mirror that of the definite integral. This notation lends itself to working inline, as we illustrate with this next problem where we \"know\" a function \"$F$\", so just express it \"inline\":\n\n\n\n$$\n\\int_0^{\\pi/4} \\sec^2(x) dx = \\tan(x) \\big|_{x=0}^{\\pi/4} = 1 - 0 = 1.\n$$\n\n\nA consequence of this notation is:\n\n\n\n$$\nF(x) \\big|_{x=a}^b = -F(x) \\big|_{x=b}^a.\n$$\n\n\nThis says nothing more than $F(b)-F(a) = -F(a) - (-F(b))$, though more compactly.\n\n\n## The indefinite integral\n\n\nA function $F(x)$ with $F'(x) = f(x)$ is known as an *antiderivative* of $f$. For a given $f$, there are infinitely many antiderivatives: if $F(x)$ is one, then so is $G(x) = F(x) + C$. But - due to the mean value theorem - all antiderivatives for $f$ differ at most by a constant.\n\n\nThe **indefinite integral** of $f(x)$ is denoted by:\n\n\n\n$$\n\\int f(x) dx.\n$$\n\n\n(There are no limits of integration.) There are two possible definitions: this refers to the set of *all* antiderivatives, or is just one of the set of all antiderivatives for $f$. The former gives rise to expressions such as\n\n\n\n$$\n\\int x^2 dx = \\frac{x^3}{3} + C\n$$\n\n\nwhere $C$ is the *constant of integration* and isn't really a fixed constant, but any possible constant. These notes will follow the lead of `SymPy` and not give a $C$ in the expression, but instead rely on the reader to understand that there could be many other possible expressions given, though all differ by no more than a constant. This means, that $\\int f(x) dx$ refers to *an* antiderivative, not *the* collection of all antiderivatives.\n\n\n### The `integrate` function from `SymPy`\n\n\n`SymPy` provides the `integrate` function to perform integration. There are two usages:\n\n\n * `integrate(ex, var)` to find an antiderivative\n * `integrate(ex, (var, a, b))` to find the definite integral. This integrates the expression in the variable `var` from `a` to `b`.\n\n\nTo illustrate, we have, this call finds an antiderivative:\n\n::: {.cell execution_count=4}\n``` {.julia .cell-code}\n@syms x\nintegrate(sin(x),x)\n```\n\n::: {.cell-output .cell-output-display execution_count=5}\n```{=html}\n \n\\[\n- \\cos{\\left(x \\right)}\n\\]\n\n```\n:::\n:::\n\n\nWhereas this call computes the \"area\" under $f(x)$ between `a` and `b`:\n\n::: {.cell execution_count=5}\n``` {.julia .cell-code}\nintegrate(sin(x), (x, 0, pi))\n```\n\n::: {.cell-output .cell-output-display execution_count=6}\n```{=html}\n \n\\[\n2.0\n\\]\n\n```\n:::\n:::\n\n\nAs does this for a different function:\n\n::: {.cell execution_count=6}\n``` {.julia .cell-code}\nintegrate(acos(1-x), (x, 0, 2))\n```\n\n::: {.cell-output .cell-output-display execution_count=7}\n```{=html}\n \n\\[\n\\pi\n\\]\n\n```\n:::\n:::\n\n\nAnswers may depend on conditions, as here, where the case $n=-1$ breaks a pattern:\n\n::: {.cell hold='true' execution_count=7}\n``` {.julia .cell-code}\n@syms x::real n::real\nintegrate(x^n, x) # indefinite integral\n```\n\n::: {.cell-output .cell-output-display execution_count=8}\n```{=html}\n \n\\[\n\\begin{cases} \\frac{x^{n + 1}}{n + 1} & \\text{for}\\: n \\neq -1 \\\\\\log{\\left(x \\right)} & \\text{otherwise} \\end{cases}\n\\]\n\n```\n:::\n:::\n\n\nAnswers may depend on specific assumptions:\n\n::: {.cell hold='true' execution_count=8}\n``` {.julia .cell-code}\n@syms u\nintegrate(abs(u),u)\n```\n\n::: {.cell-output .cell-output-display execution_count=9}\n```{=html}\n \n\\[\n\\int \\left|{u}\\right|\\, du\n\\]\n\n```\n:::\n:::\n\n\nYet\n\n::: {.cell hold='true' execution_count=9}\n``` {.julia .cell-code}\n@syms u::real\nintegrate(abs(u),u)\n```\n\n::: {.cell-output .cell-output-display execution_count=10}\n```{=html}\n \n\\[\n\\begin{cases} - \\frac{u^{2}}{2} & \\text{for}\\: u \\leq 0 \\\\\\frac{u^{2}}{2} & \\text{otherwise} \\end{cases}\n\\]\n\n```\n:::\n:::\n\n\nAnswers may not be available as elementary functions, but there may be special functions that have special cases.\n\n::: {.cell hold='true' execution_count=10}\n``` {.julia .cell-code}\n@syms x::real\nintegrate(x / sqrt(1-x^3), x)\n```\n\n::: {.cell-output .cell-output-display execution_count=11}\n```{=html}\n \n\\[\n\\frac{x^{2} \\Gamma\\left(\\frac{2}{3}\\right) {{}_{2}F_{1}\\left(\\begin{matrix} \\frac{1}{2}, \\frac{2}{3} \\\\ \\frac{5}{3} \\end{matrix}\\middle| {x^{3} e^{2 i \\pi}} \\right)}}{3 \\Gamma\\left(\\frac{5}{3}\\right)}\n\\]\n\n```\n:::\n:::\n\n\nThe different cases explored by `integrate` are after the questions.\n\n\n## Rules of integration\n\n\nThere are some \"rules\" of integration that allow integrals to be re-expressed. These follow from the rules of derivatives.\n\n\n * The integral of a constant times a function:\n\n\n\n$$\n\\int c \\cdot f(x) dx = c \\cdot \\int f(x) dx.\n$$\n\n\nThis follows as if $F(x)$ is an antiderivative of $f(x)$, then $[cF(x)]' = c f(x)$ by rules of derivatives.\n\n\n * The integral of a sum of functions:\n\n\n\n$$\n\\int (f(x) + g(x)) dx = \\int f(x) dx + \\int g(x) dx.\n$$\n\n\nThis follows immediately as if $F(x)$ and $G(x)$ are antiderivatives of $f(x)$ and $g(x)$, then $[F(x) + G(x)]' = f(x) + g(x)$, so the right hand side will have a derivative of $f(x) + g(x)$.\n\n\nIn fact, this more general form where $c$ and $d$ are constants covers both cases:\n\n\n\n$$\n\\int (cf(x) + dg(x)) dx = c \\int f(x) dx + d \\int g(x) dx.\n$$\n\n\nThis statement is nothing more than the derivative formula $[cf(x) + dg(x)]' = cf'(x) + dg'(x)$. The product rule gives rise to a technique called *integration by parts* and the chain rule gives rise to a technique of *integration by substitution*, but we defer those discussions to other sections.\n\n\n##### Examples\n\n\n * The antiderivative of the polynomial $p(x) = a_n x^n + \\cdots a_1 x + a_0$ follows from the linearity of the integral and the general power rule:\n\n\n\n$$\n\\begin{align}\n\\int (a_n x^n + \\cdots a_1 x + a_0) dx\n&= \\int a_nx^n dx + \\cdots \\int a_1 x dx + \\int a_0 dx \\\\\n&= a_n \\int x^n dx + \\cdots + a_1 \\int x dx + a_0 \\int dx \\\\\n&= a_n\\frac{x^{n+1}}{n+1} + \\cdots + a_1 \\frac{x^2}{2} + a_0 \\frac{x}{1}.\n\\end{align}\n$$\n\n\n * More generally, a [Laurent](https://en.wikipedia.org/wiki/Laurent_polynomial) polynomial allows for terms with negative powers. These too can be handled by the above. For example\n\n\n\n$$\n\\begin{align}\n\\int (\\frac{2}{x} + 2 + 2x) dx\n&= \\int \\frac{2}{x} dx + \\int 2 dx + \\int 2x dx \\\\\n&= 2\\int \\frac{1}{x} dx + 2 \\int dx + 2 \\int xdx\\\\\n&= 2\\log(x) + 2x + 2\\frac{x^2}{2}.\n\\end{align}\n$$\n\n\n * Consider this integral:\n\n\n\n$$\n\\int_0^\\pi 100 \\sin(x) dx = F(\\pi) - F(0),\n$$\n\n\nwhere $F(x)$ is an antiderivative of $100\\sin(x)$. But:\n\n\n\n$$\n\\int 100 \\sin(x) dx = 100 \\int \\sin(x) dx = 100 (-\\cos(x)).\n$$\n\n\nSo the answer to the question is\n\n\n\n$$\n\\int_0^\\pi 100 \\sin(x) dx = (100 (-\\cos(\\pi))) - (100(-\\cos(0))) = (100(-(-1))) - (100(-1)) = 200.\n$$\n\n\nThis seems like a lot of work, and indeed it is more than is needed. The following would be more typical once the rules are learned:\n\n\n\n$$\n\\int_0^\\pi 100 \\sin(x) dx = 100(-\\cos(x)) \\big|_0^{\\pi} = 100 \\cos(x) \\big|_{\\pi}^0 = 100(1) - 100(-1) = 200.\n$$\n\n\n## The derivative of the integral\n\n\nThe relationship that $[\\int_a^x f(u) du]' = f(x)$ is a bit harder to appreciate, as it doesn't help answer many ready made questions. Here we give some examples of its use.\n\n\nFirst, the expression defining an antiderivative, or indefinite integral, is given in term of a definite integral:\n\n\n\n$$\nF(x) = \\int_a^x f(u) du.\n$$\n\n\nThe value of $a$ does not matter, as long as the integral is defined.\n\n::: {.cell cache='true' hold='true' execution_count=11}\n\n::: {.cell-output .cell-output-display execution_count=12}\n```{=html}\n
Illustration showing \\(F(x) = \\int_a^x f(u) du\\) is a function that accumulates area. The value of \\(A\\) is the area over \\([x_{n-1}, x_n]\\) and also the difference \\(F(x_n) - F(x_{n-1})\\).
\n