|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "## The Basis of Symbolic-Numeric Integration" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "In this section, we informally introduce the symbolic-numeric integration algorithm, as implemented by **SymbolicNumericIntegraion.jl**." |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "markdown", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
| 21 | + "Let's start with a simple example, $f(x) = x \\sin x$, and show how to integrate it using the *method of indeterminate coefficients*. The main idea is to write the solution, i.e., $S = \\int x \\sin x\\,dx$, as a sum of multiple possible terms with unknown coefficients,\n", |
| 22 | + "\n", |
| 23 | + "\\begin{equation}\n", |
| 24 | + " S = \\sum_i q_i \\mathbb{T}_i(x)\n", |
| 25 | + " \\,,\n", |
| 26 | + " \\tag{1}\n", |
| 27 | + "\\end{equation}\n", |
| 28 | + "\n", |
| 29 | + "where $q_i$ are constant coefficients and $\\mathbb{T}_i(x)$ are *reasonable candidate* terms. For our first example, and considering that $(\\sin x)' = \\cos x$ and $(\\cos x)' = -\\sin x$, a reasonable set of terms is $\\mathbb{T} = \\{x, \\sin x, \\cos x, x\\sin x, x\\cos x\\}$. Of course, we need a better method to find $\\mathbb{T}$ than saying it should be a reasonable set! In fact, we will discuss this problem is details later, but for now assume that an oracle provides $\\mathbb{T}$. We have\n", |
| 30 | + "\n", |
| 31 | + "\\begin{equation}\n", |
| 32 | + " S = q_1 x + q_2 \\sin x + q_3 \\cos x + q_4 x \\sin x + q_5 x \\cos x\n", |
| 33 | + " \\,.\n", |
| 34 | + " \\tag{2}\n", |
| 35 | + "\\end{equation}" |
| 36 | + ] |
| 37 | + }, |
| 38 | + { |
| 39 | + "cell_type": "markdown", |
| 40 | + "metadata": {}, |
| 41 | + "source": [ |
| 42 | + "Differentiating with respect to $x$,\n", |
| 43 | + "\n", |
| 44 | + "\\begin{equation}\n", |
| 45 | + " S' = q_1 + (q_4 - q_3) \\sin x + (q_2 + q_5) \\cos x - q_5 x \\sin x + q_4 x \\cos x\n", |
| 46 | + " \\,.\n", |
| 47 | + " \\tag{3}\n", |
| 48 | + "\\end{equation}\n", |
| 49 | + "\n", |
| 50 | + "By definition, $\\int S\\,dx = f$; therefore, $S' = f = x \\sin x$ (note that, as it is customary in symbolic integration, we ignore the constant inegration term). We obtain the following linear system,\n", |
| 51 | + "\n", |
| 52 | + "\\begin{equation}\n", |
| 53 | + " \\begin{array}{ll}\n", |
| 54 | + " q_1 = 0 \\\\\n", |
| 55 | + " q_4 - q_3 = 0 \\\\\n", |
| 56 | + " q_2 + q_5 = 0 \\\\\n", |
| 57 | + " -q_5 = 1 \\\\\n", |
| 58 | + " q_4 = 0 \n", |
| 59 | + " \\end{array} \n", |
| 60 | + " \\tag{4}\n", |
| 61 | + "\\end{equation}\n" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "markdown", |
| 66 | + "metadata": {}, |
| 67 | + "source": [ |
| 68 | + "Solving the linear the system, we find $q_5 = -1$, $q_2 = 1$, and $q_1 = q_3 = q_4 = 0$. Therefore,\n", |
| 69 | + "\n", |
| 70 | + "\\begin{equation}\n", |
| 71 | + " S = \\int x \\sin x\\,dx = \\sin x - x \\cos x \n", |
| 72 | + " \\,.\n", |
| 73 | + " \\tag{5}\n", |
| 74 | + "\\end{equation}\n", |
| 75 | + "\n", |
| 76 | + "As it should be." |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "markdown", |
| 81 | + "metadata": {}, |
| 82 | + "source": [ |
| 83 | + "Note that the preceding calculations were all essentially symbolic and there was no need for numerical computation. However, this is not always the case. Let's look at another example. This time, let $f(x) = \\sin^2 x$. We assume that the oracle, who knows the correct answer $\\int \\sin^2 x = (x - \\sin x\\cos x)/2$, gives us $\\mathbb{T} = \\{x, \\sin x\\cos x\\}$ (in practice, the list will be longer, but we use the abbreviated one to reduce clutter). Following the same process as before,\n", |
| 84 | + "\n", |
| 85 | + "\\begin{equation}\n", |
| 86 | + " S = q_1 x + q_2 \\sin x\\cos x\n", |
| 87 | + " \\,,\n", |
| 88 | + " \\tag{6}\n", |
| 89 | + "\\end{equation}\n", |
| 90 | + "\n", |
| 91 | + "and,\n", |
| 92 | + "\n", |
| 93 | + "\\begin{equation}\n", |
| 94 | + " S' = q_1 + q_2 \\cos^2 x - q_2\\sin^2 x\n", |
| 95 | + " \\,.\n", |
| 96 | + " \\tag{7}\n", |
| 97 | + "\\end{equation}\n", |
| 98 | + "\n", |
| 99 | + "Equating $S'$ to $\\sin^2 x$, we get\n", |
| 100 | + "\n", |
| 101 | + "\\begin{equation}\n", |
| 102 | + " \\begin{array}{ll}\n", |
| 103 | + " q_1 = 0 \\\\\n", |
| 104 | + " q_2 = 0 \\\\\n", |
| 105 | + " q_2 = -1\n", |
| 106 | + " \\end{array} \n", |
| 107 | + " \\tag{8}\n", |
| 108 | + "\\end{equation}\n", |
| 109 | + "\n", |
| 110 | + "which is a contradiction. We can resolve this problem by using $\\sin^2 x + \\cos^2 x = 1$ to write\n", |
| 111 | + "\n", |
| 112 | + "\\begin{equation}\n", |
| 113 | + " S' = q_1 + q_2 (1 - \\sin^2 x) - q_2\\sin^2 x =\n", |
| 114 | + " (q_1 + q_2) - 2q_2 \\sin^2 x\n", |
| 115 | + " \\,.\n", |
| 116 | + " \\tag{9}\n", |
| 117 | + "\\end{equation}\n", |
| 118 | + "\n", |
| 119 | + "Therefore,\n", |
| 120 | + "\n", |
| 121 | + "\\begin{equation}\n", |
| 122 | + " \\begin{array}{ll}\n", |
| 123 | + " q_1 + q_2 = 0 \\\\\n", |
| 124 | + " -2q_2 = 1\n", |
| 125 | + " \\end{array} \n", |
| 126 | + " \\tag{10}\n", |
| 127 | + "\\end{equation}\n", |
| 128 | + "\n", |
| 129 | + "Finally, we have the correct answer $q_1 = 1/2$ and $q_2 = -1/2$." |
| 130 | + ] |
| 131 | + }, |
| 132 | + { |
| 133 | + "cell_type": "markdown", |
| 134 | + "metadata": {}, |
| 135 | + "source": [ |
| 136 | + "Numerical computation becomes necessary partly due to the limitations of **JuliaSymbolics** in converting expressions into unique *canonical* forms. Therefore, identities like $\\sin^2 x + \\cos^2 x = 1$ (and may more, some subtle and some complex) may not be correctly applied. In fact, the problem is more fundamental and according to the Richardson's theorem, the problem of finding canonical forms of transcendental expressions is undecided. \n", |
| 137 | + "\n", |
| 138 | + "Another reason for using numerical computation is that the list of candidates may not be (and usually is not) linearly-independent. Finding a linearly-independent subset of a set of expressions using symbolical computation is a very difficult problem but can be done numerically. " |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "markdown", |
| 143 | + "metadata": {}, |
| 144 | + "source": [ |
| 145 | + "The next example show cases the problems of linear dependence. Let $f(x) = \\sinh x\\cosh x$. Assume that the oracle returns the following candidate list (which is typical of such lists),\n", |
| 146 | + "\n", |
| 147 | + "\\begin{equation}\n", |
| 148 | + " \\mathbb{T} = \\{\\cosh^2 x, \\cosh x\\sinh x, \\sinh2 x, x\\cosh^2 x, x\\cosh x\\sinh x, x\\sinh^2 x\\}\n", |
| 149 | + " \\,.\n", |
| 150 | + " \\tag{14}\n", |
| 151 | + "\\end{equation}\n", |
| 152 | + "\n", |
| 153 | + "If we follow the same procedure described above, a singular matrix error occurs. The reason is the fact that $\\cosh^2 x - \\sinh^2 x = 1$; therefore, $x\\cosh^2 x$ and $x\\sinh^2 x$ are linearly dependent. The solution is to prune $\\mathbb{T}$ to a linearly-independent subset,\n", |
| 154 | + "\n", |
| 155 | + "\\begin{equation}\n", |
| 156 | + " \\mathbb{T} = \\{\\cosh^2 x, \\cosh x\\sinh x, x\\cosh^2 x, x\\cosh x\\sinh x\\}\n", |
| 157 | + " \\,,\n", |
| 158 | + " \\tag{15}\n", |
| 159 | + "\\end{equation}\n", |
| 160 | + "\n", |
| 161 | + "Now, we can calculate the correct answer $\\int \\sinh x\\cosh\\,dx = \\frac{1}{2}\\cosh^2 x$." |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": null, |
| 167 | + "metadata": {}, |
| 168 | + "outputs": [], |
| 169 | + "source": [] |
| 170 | + } |
| 171 | + ], |
| 172 | + "metadata": { |
| 173 | + "kernelspec": { |
| 174 | + "display_name": "Julia 1.6.0", |
| 175 | + "language": "julia", |
| 176 | + "name": "julia-1.6" |
| 177 | + }, |
| 178 | + "language_info": { |
| 179 | + "file_extension": ".jl", |
| 180 | + "mimetype": "application/julia", |
| 181 | + "name": "julia", |
| 182 | + "version": "1.6.0" |
| 183 | + } |
| 184 | + }, |
| 185 | + "nbformat": 4, |
| 186 | + "nbformat_minor": 2 |
| 187 | +} |
0 commit comments