summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luacas/doc/reference/ref_calculus/ref_calculus_classes/ref_calculus_classes.tex
blob: b08a190625c2e4c901a8e56a09e94510c687f763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
\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{fontawesome}

\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
}

\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}%
}

\begin{document}
\setdescription{style=multiline,
        topsep=10pt,
        leftmargin=5cm,
        }

\subsection{Calculus Classes}

There are only a few classes (currently) in the calculus module all of which are concrete:
\begin{itemize}
    \item {\ttfamily DerivativeExpression}
    \item {\ttfamily DiffExpression}
    \item {\ttfamily IntegralExpression}
\end{itemize}

\newcoderef{function DerivativeExpression:new(expression, symbol)}{return DerivativeExpression}{expression Expression, symbol SymbolExpression} 
\addcontentsline{toc}{subsubsection}{\ttfamily DerivativeExpression}

Creates a new single-variable derivative operation of the given \texttt{expression} with respect to the given \texttt{symbol}. If \texttt{symbol} is omitted, then \texttt{symbol} takes the default value of \mintinline{lua}{SymbolExpression("x")}. For example:

\begin{codebox}
    \begin{minted}[fontsize=\small]{lua}
vars('x')
f = DerivativeExpression(sin(x)/x)
tex.print('\\[', f:tolatex(), '\\]')
\end{minted}
\tcblower
\luaexec{
    vars('x')
    f = DerivativeExpression(sin(x)/x)
    tex.print('\\[', f:tolatex(), '\\]')
}
\end{codebox}

\subsubsection*{Parsing}

The function \mintinline{lua}{DD()} shortcuts \mintinline{lua}{DerivativeExpression()}. 

\begin{codebox}
    \begin{minted}[fontsize=\small]{latex}
\begin{CAS}
    vars('x')
    f = DD(sin(x)/x)
\end{CAS}
\[ \print{f} \] 
\end{CAS}
\end{minted}
\tcblower
\begin{CAS}
    vars('x')
    f = DD(sin(x)/x)
\end{CAS}
\[ \print{f} \] 
\end{codebox}
Alternatively, one could also use \mintinline{lua}{diff()} (see below). 

\newcoderef{function DiffExpression:new(expression, symbols)}{return DiffExpression}{expression Expression, symbols table<number, Symbol>}
\addcontentsline{toc}{subsubsection}{\ttfamily DiffExpression}

Creates a new multi-variable higher-order derivative operation of the given \texttt{expression} with respect to the given \texttt{symbols}. As opposed to \texttt{DerivativeExpression}, the argument \texttt{symbols} cannot be omitted. For example:

\begin{codebox}
    \begin{minted}[fontsize=\small]{lua}
vars('x','y')
f = DiffExpression(sin(x*y)/y,{x,y})
tex.print('\\[', f:tolatex(), '\\]')
\end{minted}
\tcblower
\luaexec{
    vars('x','y')
    f = DiffExpression(sin(x*y)/y,{x,y})
    tex.print('\\[', f:tolatex(), '\\]')
}
\end{codebox}
We can also use \texttt{DiffExpression} to create higher-order single variable derivatives:

\begin{codebox}
    \begin{minted}[fontsize=\small]{lua}
vars('x')
f = DiffExpression(sin(x)/x,{x,x})
tex.print('\\[', f:tolatex(), '\\]')
\end{minted}
\tcblower
\luaexec{
    vars('x')
    f = DiffExpression(sin(x)/x,{x,x})
    tex.print('\\[', f:tolatex(), '\\]')
}
\end{codebox}

\subsubsection*{Parsing}

The function \mintinline{lua}{diff()} shortcuts \mintinline{lua}{DiffExpression()}. The arguments of \mintinline{lua}{diff()} can also be given in a more user-friendly, compact form. For example:

\begin{codebox}[]
    \begin{minted}[fontsize=\small]{latex}
\begin{CAS}
    vars('x','y')
    f = diff(sin(x)/x, {x,2})
    g = diff(sin(x*y)/y,x,{y,2})
\end{CAS}
\[ \print{f} = \print*{f} \qquad \print{g} = \print*{g} \]
\end{minted}
\tcblower
\begin{CAS}
    vars('x','y')
    f = diff(sin(x)/x, {x,2})
    g = diff(sin(x*y)/y,x,{y,2})
\end{CAS}
\[ \print{f} = \print*{f} \qquad \print{g} = \print*{g} \]
\end{codebox}

\newcoderef{function IntegralExpression:new(expression,symbol,lower,upper)}{return IntegralExpression}{expression Expression, symbol SymbolExpression, lower Expression, upper Expression} 
\addcontentsline{toc}{subsubsection}{\ttfamily IntegralExpression}

Creates a new integral operation of the given \texttt{expression} with respect to the given \texttt{symbol} over the given \texttt{lower} and \texttt{upper} bounds. If \texttt{lower} and \texttt{upper} are omitted, then an \emph{indefinite} \texttt{IntegralExpression} is constructed. For example:

\begin{codebox}
    \begin{minted}[fontsize=\small,breaklines]{lua}
vars('x')
f = IntegralExpression(sin(sqrt(x)), x)
g = IntegralExpression(sin(sqrt(x)), x, Integer.zero(), pi)
tex.print('\\[', f:tolatex(), '\\]')
tex.print('\\[', g:tolatex(), '\\]')
\end{minted}
\tcblower
\luaexec{
    vars('x')
    f = IntegralExpression(sin(sqrt(x)),x)
    g = IntegralExpression(sin(sqrt(x)),x,Integer.zero(),pi)
    tex.print('\\[', f:tolatex(), '\\]')
    tex.print('\\[', g:tolatex(), '\\]')
}
\end{codebox}

\subsubsection*{Parsing}

The function \mintinline{lua}{int()} shortcuts \mintinline{lua}{IntegralExpression()}. For example:
\begin{codebox}
    \begin{minted}[fontsize=\small]{latex}
\begin{CAS}
    g = int(sin(sqrt(x)),x,0,pi)
\end{CAS}
\[ \print{g} = \print*{g} \] 
\end{minted}
\tcblower
\begin{CAS}
    g = int(sin(sqrt(x)),x,0,pi)
\end{CAS}
\[ \print{g} = \print*{g} \]
\end{codebox} 

\end{document}