diff options
Diffstat (limited to 'macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_methods/ref_calculus_methods.tex')
-rw-r--r-- | macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_methods/ref_calculus_methods.tex | 473 |
1 files changed, 473 insertions, 0 deletions
diff --git a/macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_methods/ref_calculus_methods.tex b/macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_methods/ref_calculus_methods.tex new file mode 100644 index 0000000000..c64baa5934 --- /dev/null +++ b/macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_methods/ref_calculus_methods.tex @@ -0,0 +1,473 @@ +\documentclass{article} + +\usepackage{luacas} +\usepackage{amsmath} +\usepackage{amssymb} + +\usepackage[margin=1in]{geometry} +\usepackage[shortlabels]{enumitem} + +\usepackage{pgfplots} +\pgfplotsset{compat=1.18} +\usetikzlibrary{positioning,calc} +\usepackage{forest} +\usepackage{minted} +\usemintedstyle{pastie} +\usepackage[hidelinks]{hyperref} +\usepackage{parskip} +\usepackage{multicol} +\usepackage[most]{tcolorbox} + \tcbuselibrary{xparse,documentation} +\usepackage{microtype} +\usepackage{makeidx} +\usepackage{fontawesome5} + +\usepackage[ +backend=biber, +style=numeric, +]{biblatex} +\addbibresource{sources.bib} + +\definecolor{rose}{RGB}{128,0,0} +\definecolor{roseyellow}{RGB}{222,205,99} +\definecolor{roseblue}{RGB}{167,188,214} +\definecolor{rosenavy}{RGB}{79,117,139} +\definecolor{roseorange}{RGB}{232,119,34} +\definecolor{rosegreen}{RGB}{61,68,30} +\definecolor{rosewhite}{RGB}{223,209,167} +\definecolor{rosebrown}{RGB}{108,87,27} +\definecolor{rosegray}{RGB}{84,88,90} + +\definecolor{codegreen}{HTML}{49BE25} + +\newtcolorbox{codebox}[1][sidebyside]{ + enhanced,skin=bicolor, + #1, + arc=1pt, + colframe=brown, + colback=brown!15,colbacklower=white, + boxrule=1pt, + notitle +} + +\newtcolorbox{codehead}[1][]{ + enhanced, + frame hidden, + colback=rosegray!15, + boxrule=0mm, + leftrule=5mm, + rightrule=5mm, + boxsep=0mm, + arc=0mm, + outer arc=0mm, + left=3mm, + right=3mm, + top=1mm, + bottom=1mm, + toptitle=1mm, + bottomtitle=1mm, + oversize, + #1 +} + +\DeclareTotalTCBox{\lilcoderef}{O{} m m}{ + enhanced, + frame hidden, + colback=rosegray!15, + enhanced, + nobeforeafter, + tcbox raise base, + boxrule=0mm, + leftrule=5mm, + rightrule=5mm, + boxsep=0mm, + arc=0mm, + outer arc=0mm, + left=1mm, + right=1mm, + top=1mm, + bottom=1mm, + oversize, + #1 +}{\mintinline{lua}{#2} \mintinline{lua}{#3}} + +\usepackage{varwidth} + +\newtcolorbox{newcodehead}[2][]{ + enhanced, + frame hidden, + colback=rosegray!15, + boxrule=0mm, + leftrule=5mm, + rightrule=5mm, + boxsep=0mm, + arc=0mm, + outer arc=0mm, + left=3mm, + right=3mm, + top=1mm, + bottom=1mm, + toptitle=1mm, + bottomtitle=1mm, + oversize, + #1, + fonttitle=\bfseries\ttfamily\footnotesize, + coltitle=rosegray, + attach boxed title to top text right, + boxed title style={frame hidden,size=small,bottom=-1mm, + interior style={fill=none, + top color=white, + bottom color=white}}, + title={#2} +} + +\makeindex + +\newcommand{\coderef}[2]{% +\begin{codehead}[sidebyside,segmentation hidden]% + \mintinline{lua}{#1}% + \tcblower% + \begin{flushright}% + \mintinline{lua}{#2}% + \end{flushright}% +\end{codehead}% +} + +\newcommand{\newcoderef}[3]{% +\begin{newcodehead}[sidebyside,segmentation hidden]{#3}% + \mintinline{lua}{#1}% + \tcblower% + \begin{flushright}% + \mintinline{lua}{#2}% + \end{flushright}% +\end{newcodehead}% +} +\usepackage{marginnote} + +\begin{document} +\setdescription{style=multiline, + topsep=10pt, + leftmargin=6.5cm, + } + +\subsection{Calculus Methods} + +\newcoderef{function IntegralExpression.table(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.table} + +Attempts to integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} by checking a table of basic integrals; returns nil if the integrand isn't in the table. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = int(cos(x),x) + f = f:table() + g = int(x*cos(x),x) + g = g:table() +\end{CAS} +\[ f = \print{f} \qquad g = \print{g} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = int(cos(x),x) + f = f:table() + g = int(x*cos(x),x) + g = g:table() + \end{CAS} +\[ f = \print{f} \qquad g = \print{g} \] +\end{codebox} +The table of integrals consists of power functions, exponentials, logarithms, trigonometric, and inverse trigonometric functions. + +\newcoderef{function IntegralExpression.linearproperties(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.linearproperties} + +Attempts to integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} by using linearity properties (e.g. the integral of a sum/difference is the sum/difference of integrals); returns nil if any individual component cannot be integrated using \mintinline{lua}{IntegralExpression:integrate()}. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = int(sin(x) + e^x,x) + g = f:table() + f = f:linearproperties() +\end{CAS} +\[ f = \print*{f} \qquad g = \print*{g} \] +\end{minted} +\tcblower +\begin{CAS} + f = int(sin(x) + e^x,x) + g = f:table() + f = f:linearproperties() +\end{CAS} +\[ f = \print*{f} \qquad g = \print*{g} \] +\end{codebox} + +\newcoderef{function IntegralExpression.substitutionmethod(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.substitutionmethod} + +Attempts to integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} via $u$-substitution; returns nil if no suitable substitution is found to be successful. + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = int(x*e^(x^2),x) + g = int(x*e^x,x) + f = f:substitutionmethod() + g = g:substitutionmethod() +\end{CAS} +\[ f = \print*{f} \qquad g = \print*{g}.\] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = int(x*e^(x^2),x) + g = int(x*e^x,x) + f = f:substitutionmethod() + g = g:substitutionmethod() +\end{CAS} +\[ f = \print*{f} \qquad g = \print*{g}.\] +\end{codebox} + +\newcoderef{function IntegralExpression.enhancedsubstitutionmethod(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.enhancedsubstitutionmethod} + +Attempts integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} via $u$-substitutions. This method distinguishes itself from the \mintinline{lua}{.substitutionmethod} by attempted to solve $u= g(x)$ for the original variable and then substituting the result into the expression. This behavior is not included in \mintinline{lua}{.substitutionmethod} due to speed concerns. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = int(x^5*sqrt(x^3+1),x) + g = f:substitutionmethod() + h = f:enhancedsubstitutionmethod() +\end{CAS} +\[ g= \print*{g} \] +\[ h= \print*{h} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = int(x^5*sqrt(x^3+1),x) + g = f:substitutionmethod() + h = f:enhancedsubstitutionmethod() +\end{CAS} +\[ g= \print*{g} \] +\[ h= \print*{h} \] +\end{codebox} + + +\newcoderef{function IntegralExpression.trialsubstitutions(Expression)}{return table<number, Expression}{} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.trialsubstitutions} + +Generates a list of possible $u$-substitutions to attempt in \texttt{substitutionmethod()} and \texttt{enhancedsubstitutionmethod()}. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = cos(x)/(1+sin(x)) + f = f:autosimplify() + l = IntegralExpression.trialsubstitutions(f) +\end{CAS} +$\left\{ \lprint{l} \right\}$. +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = cos(x)/(1+sin(x)) + f = f:autosimplify() + l = IntegralExpression.trialsubstitutions(f) +\end{CAS} +$ \left\{ \lprint{l} \right\}$. +\end{codebox} + + +\newcoderef{function IntegralExpression.rationalfunction(IntegralExpression)}{return Expression|nil}{} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.rationalfunction} + +Integrates \texttt{integrand} with respect to \texttt{symbol} via Lazard, Rioboo, Rothstein, and Trager's method in the case when \texttt{expression} is a rational function in the variable \texttt{symbol}. If \texttt{integrand} is not a rational function, then nil is returned. + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = (x^2+2*x+2)/(x^2+3*x+2) + f = f:autosimplify() + g = int(f,x):rationalfunction() +\end{CAS} +\[ \int \print{f}\ dx = \print*{g} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = (x^2+2*x+2)/(x^2+3*x+2) + f = f:autosimplify() + g = int(f,x):rationalfunction() +\end{CAS} +\[ \int \print{f}\ dx = \print*{g} \] +\end{codebox} + +In some cases, the \mintinline{lua}{.rationalfunction} method returns non-standard results. For example: +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + num = x^2 + den = ((x+1)*(x^2+2*x+2)):expand() + f = (num/den):autosimplify() + f = int(f,x):rationalfunction() +\end{CAS} +\[ \print{simplify(f)} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + num = x^2 + den = ((x+1)*(x^2+2*x+2)):expand() + f = (num/den):autosimplify() + f = int(f,x):rationalfunction() +\end{CAS} +\[ \print{simplify(f)} \] +\end{codebox} +On the other hand: +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + pfrac = parfrac(num,den) +\end{CAS} +\[ \print*{int(pfrac,x)} \] +\end{minted} +\tcblower +\begin{CAS} + pfrac = parfrac(num,den) + \end{CAS} +\[ \print*{int(pfrac,x)} \] +\end{codebox} + +\newcoderef{function IntegralExpression.partsmethod(IntegralExpression)}{return Expression|nil}{} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.partsmethod} + +Attempts to integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} via \emph{integration by parts}; returns nil if no suitable application of IBP is found. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + a = int(x*e^x,x) + b = a:partsmethod() + c = int(e^(x^2),x) + d = c:partsmethod() +\end{CAS} +\[ b=\print*{b} \] +\[ d=\print*{d} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + a = int(x*e^x,x) + b = a:partsmethod() + c = int(e^(x^2),x) + d = c:partsmethod() +\end{CAS} +\[ b= \print*{b} \] +\[ d= \print*{d} \] +\end{codebox} + + +\newcoderef{function IntegralExpression.eulersformula(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.eulersformula} + +Attempts to integrate \texttt{integral.expression} with respect to \texttt{integral.symbol} by using the Euler formulas: +\[ \cos x = \frac{e^{ix} + e^{-ix}}{2} \qquad \sin x = \frac{e^{ix} - e^{-ix}}{2i}.\] +Per usual, this method returns nil if such a method is unsuccessful (or if the integrand is unchanged after applying the above substitutions). This can often be used as an alternative for integration by parts. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + a = int(e^x*sin(x),x) + b = int(x^2,x) + c = a:eulersformula() + d = b:eulersformula() +\end{CAS} +\[ c= \print*{c} \] +\[ d= \print*{d} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + a = int(e^x*sin(x),x) + b = int(x^2,x) + c = a:eulersformula() + d = b:eulersformula() +\end{CAS} +\[ c= \print*{c} \] +\[ d= \print*{d} \] +\end{codebox} + +\newcoderef{function IntegralExpression.integrate(integral)}{return Expression|nil}{integral IntegralExpression} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.integrate} + +Recursive part of the indefinite integral operator; returns nil if the expression could not be integrated. The methods above get called (roughly) in the following order: +\begin{enumerate}[(i)] + \item \mintinline{lua}{.table} + \item \mintinline{lua}{.linearproperties} + \item \mintinline{lua}{.substitutionmethod} + \item \mintinline{lua}{.rationalfunction} + \item \mintinline{lua}{.partsmethod} + \item \mintinline{lua}{.eulersformula} + \item \mintinline{lua}{.enhancedsubstitutionmethod} +\end{enumerate} +Between (vi) and (vii), the \mintinline{lua}{.integrate} method will attempt to expand the integrand and retry. The method is recursive in the sense that (most) of the methods listed above will call \mintinline{lua}{.integrate} at some point. For example, after a list of trial substitutions is created, the method \mintinline{lua}{.substitutionmethod} will call \mintinline{lua}{.integrate} to determine whether the new integrand can be integrated via the methods in the above list. + +\subsubsection*{Parsing} + +Recall the function \mintinline{lua}{int()} which acts as a shortcut for \mintinline{lua}{IntegralExpression:new()}. When \mintinline{lua}{:autosimplify()} is called upon an \texttt{IntegralExpression}, then \mintinline{lua}{IntegralExpression.integrate} is applied. If \mintinline{lua}{nil} is returned, then \mintinline{lua}{:autosimplify()} returns \mintinline{lua}{self}; otherwise the result of \mintinline{lua}{.integrate} is returned and evaluated over the bounds, if any are given. For example: + +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = cos(x)*e^(sin(x)) + f = int(f,x,0,pi/2) +\end{CAS} +\[ \print{f} = \print*{f}\] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = cos(x)*e^(sin(x)) + f = int(f,x,0,pi/2) +\end{CAS} +\[ \print{f} = \print*{f}\] +\end{codebox} + +On the other hand: +\begin{codebox} + \begin{minted}[fontsize=\small]{latex} +\begin{CAS} + vars('x') + f = e^(e^x) + f = int(f,x,0,1) +\end{CAS} +\[ \print{f} = \print*{f} \] +\end{minted} +\tcblower +\begin{CAS} + vars('x') + f = e^(e^x) + f = int(f,x,0,1) +\end{CAS} +\[ \print{f} = \print*{f} \] +\end{codebox} + +\coderef{function IntegralExpression:isdefinite()}{return bool} +\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression.isdefinite} + +Returns \mintinline{lua}{true} of \texttt{IntegralExpression} is definite (i.e. if \texttt{.upper} and \texttt{.lower} are defined fields), otherwise returns \mintinline{lua}{false}. + + +\end{document}
\ No newline at end of file |