Debian Codegraph @

texmf-dist/doc/lualatex/luatruthtable/luatruthtable.tex

raw
1 \documentclass{article}
2 \usepackage{listings,color,booktabs,longtable,array,
3 hyperref,multirow,multicol,luatruthtable, enumitem}
4 \usepackage[top=1.1in, bottom=1.1in, left=1in, right=1in]{geometry}
5 \renewcommand{\arraystretch}{1.2}
6 \hypersetup{colorlinks,urlcolor=blue}
7 \lstset{frame=none,
8 language=[LaTeX]{TeX},
9 aboveskip=3mm,
10 belowskip=3mm,
11 showstringspaces=false,
12 columns=flexible,
13 basicstyle={\ttfamily},
14 numbers=none,
15 numberstyle=\tiny\color{gray},
16 stringstyle=\color{mauve},
17 breaklines=true,
18 breakatwhitespace=true,
19 tabsize=1
20 }
21 \usepackage[backend=bibtex]{biblatex}
22 \addbibresource{luatruthtable}
23 \begin{document}
24 \title{The luatruthtable Package}
25 \author{Chetan Shirore\thanks{Email id: [email protected]} \space and Ajit Kumar}
26 \maketitle
27 \section{The luatruthtable Package}
28 The \verb|luatruthtable| package is developed to generate Truth Tables of boolean values in LaTeX. It provides an easy way for generating truth tables in LaTeX . There is no need of special environment in the package for generation of Truth Tables. It is written in lua and tex file is to be compiled with LuaLatex engine. The time required for operations is no issue while compiling with LuaLaTeX. There is no need to install lua on users system as tex distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It is useful for generation of Truth Tables in tex file itself. The package supports nesting of commands for multiple operations. It can be modified or extended by writing custom lua programs.
29
30 The programming capabilities of Lua are effectively used in the development of pacakage. The other approaches of generating Truth Table in LaTeX get weired \cite{online.latextruthtable} and probably without using Lua it can't be done in an easier way in LaTeX. The \emph{xkeyval} package is used in its development apart from the \emph{luacode*} package.
31
32 \section{License} The \verb|luatruthtable| package is released under the LaTeX Project Public License v1.3c or later. The complete license text is available at \url{http://www.latex-project.org/lppl.txt}.
33 It is developed in lua. Lua is certified open source software available. Its license is simple and liberal which is compatible with GPL.
34 \section{Installation and Inclusion}
35 The installation of \verb|luatruthtable| package is similar to plain latex package where \texttt{.sty} file is in LaTeX directory of texmf tree. The package can be used by including the command \verb|\luatruthtable| in the preamble of latex document. The tex file is to be compiled using the LuaLaTeX engine.
36 \section{Core Ideas used in the development of the package} The function \verb|toBinary(x,y)| is used to produce sequence of \emph{True} and \emph{False} values of boolean variables. This function converts the decimal number \verb|x| to a binary number by adding \verb|y| number of leading zeroes. The result of this is stored in a table in Lua. Here \verb|y| corresponds to number of boolean variables. As \(2^y\) permutations of boolean variables are to be produced, the function \verb|toBinary(x,y)| runs inside a loop where \verb|x| takes values from \(1\) to \(y\). The splitting of variables and expressions is done using string methods available in Lua. The nested \emph{metamethods} in Lua are used to define several logical operators. The \emph{load} function in Lua is used to evaluate logical expressions.
37 \section{The luaTruthTable command}
38 The \verb|\luaTruthTable| command is the main command in the \emph{luatruthtable} package which generates truth tables. It has the following syntax.
39 \begin{lstlisting}[caption={[]}]
40 \luaTruthTable[trtext,fltext]{list of boolean/logical variables}
41 {list of expressions}
42 \end{lstlisting}
43 The command has two mandatory arguments. \\
44 i) \verb|list of boolean / logical variables| : The list of boolean or logical variables should be separated by a comma. \\
45 ii) \verb|list of expressions| : The list of logical expressions that are to be evaluated should be separated by a comma. \\
46 The command has two optional arguments. \\
47 i) \verb|trtext| : The \verb|trtext| is the display value for the boolean value \emph{True}. It has the default value \verb|$T$| in the package. It can be any string or number. Assigning value \(0\) should be avoided to \verb|trtext| variable. \\
48 ii) \verb|fltext| : The \verb|fltext| is the display value for the boolean value \emph{False}. It has the default value \verb|$F$| in the package. It can be any string or number. Assigning value \(1\) should be avoided to \verb|fltext| variable.
49
50 The \verb|\luaTruthTable| command should be used within in the environment \verb|\begin{tabular} ... \end{tabular}| or any other environment in LaTeX for tables. The sequence of column heads should be same as sequence of \verb|list of boolean/logical variables| and \verb|list of expressions|. Without these correct inputs, the command \verb|\luaTruthTable| can not produce the desired output.
51
52 \section{Operations in the luatruthtable package}
53 \begin{enumerate}[label=\alph*)]
54 \item \emph{not}: The value of \emph{ not p} is False when \(p\) is True and it is True when \(p\) is False.
55 \begin{center}
56 \begin{tabular}{|c|c|}
57 \hline
58 \(p\) & not \(p\) \\
59 \hline
60 \luaTruthTable{p}{lognot*p} \\
61 \hline
62 \end{tabular}
63 \end{center}
64
65 The command \verb|lognot*| is used in the package to generate truth table for \emph{not} operation.
66 \item \emph{and}: The value of \emph{p AND q} is True if and only if both \(p\) and \(q\) are True.
67 \begin{center}
68 \begin{tabular}{|cc|c|}
69 \hline
70 \(p\) & \(q\) & \(p\) and \(q\) \\
71 \hline
72 \luaTruthTable{p,q}{p*logand*q} \\
73 \hline
74 \end{tabular}
75 \end{center}
76 The command \verb|*logand*| is used in the package to generate truth table for \emph{and} operation .
77 \item \emph{or}: The value of \emph{p or q} is False if and only if both \(p\) and \(q\) are False.
78 \begin{center}
79 \begin{tabular}{|cc|c|}
80 \hline
81 \(p\) & \(q\) & \(p\) or \(q\) \\
82 \hline
83 \luaTruthTable{p,q}{p*logor*q} \\
84 \hline
85 \end{tabular}
86 \end{center}
87 The command \verb|*logor*| is used in the package to generate truth table for \emph{or} operation.
88 \item \emph{implies}: The value of \emph{p implies q} is False if and only if \(p\) is True and \(q\) is False.
89 \begin{center}
90 \begin{tabular}{|cc|c|}
91 \hline
92 \(p\) & \(q\) & \(p\) implies \(q\) \\
93 \hline
94 \luaTruthTable{p,q}{p*imp*q} \\
95 \hline
96 \end{tabular}
97 \end{center}
98
99 The command \verb|*imp*| is used in the package to generate truth table for \emph{implies} operation.
100 \item \emph{if and only if} : The value of \emph{p if and only if q} is True if and only if both \(p\) and \(q\) have same truth values.
101 \begin{center}
102 \begin{tabular}{|cc|c|}
103 \hline
104 \(p\) & \(q\) & \(p\) iff \(q\) \\
105 \hline
106 \luaTruthTable{p,q}{p*iff*q} \\
107 \hline
108 \end{tabular}
109 \end{center}
110
111 The command \verb|*iff*| is used in the package to generate truth table for \emph{if and only if} operation.
112 \item \emph{NAND} : The value of \emph{p NAND q} is \(0\) if and only if both \(p\) and \(q\) have value \(1\).
113 \begin{center}
114 \begin{tabular}{|cc|c|}
115 \hline
116 \(p\) & \(q\) & \(p\) NAND \(q\) \\
117 \hline
118 \luaTruthTable[trtext=$1$,fltext=$0$]{p,q}{p*lognand*q} \\
119 \hline
120 \end{tabular}
121 \end{center}
122
123 The command \verb|*lognand*| is used in the package to generate truth table for \emph{NAND} operation.
124 \item \emph{XOR} : The value of \emph{p XOR q} is \(0\) if and only if \(p\) and \(q\) have same values.
125 \begin{center}
126 \begin{tabular}{|cc|c|}
127 \hline
128 \(p\) & \(q\) & \(p\) XOR \(q\) \\
129 \hline
130 \luaTruthTable[trtext=$1$,fltext=$0$]{p,q}{p*logxor*q} \\
131 \hline
132 \end{tabular}
133 \end{center}
134
135
136 The command \verb|*logxor*| is used in the package to generate truth table for \emph{XOR} operation.
137 \item \emph{NOR}: The value of \emph{p NOR q} is \(1\) if and only if both \(p\) and \(q\) have value \(0\).
138 \begin{center}
139 \begin{tabular}{|cc|c|}
140 \hline
141 \(p\) & \(q\) & \(p\) NOR \(q\) \\
142 \hline
143 \luaTruthTable[trtext=$1$,fltext=$0$]{p,q}{p*lognor*q} \\
144 \hline
145 \end{tabular}
146 \end{center}
147
148 The command \verb|*lognor*| is used in the package to generate truth table for \emph{NOR} operation.
149 \item \emph{XNOR}: The value of \emph{p XNOR q} is \(1\) if and only if both \(p\) and \(q\) have same values.
150 \begin{center}
151 \begin{tabular}{|cc|c|}
152 \hline
153 \(p\) & \(q\) & \(p\) XNOR \(q\) \\
154 \hline
155 \luaTruthTable[trtext=$1$,fltext=$0$]{p,q}{p*logxnor*q} \\
156 \hline
157 \end{tabular}
158 \end{center}
159
160 The command \verb|*logxnor*| is used in the package to generate truth table for \emph{XNOR} operation.
161 \end{enumerate}
162 Table \ref{tbl:truthop} describes operators in the \verb|luatruthtable| package.
163 \begin{center}
164 \begin{longtable}{llm{9cm}}
165 \toprule
166 \multicolumn{1}{c}{\textcolor{blue}{Operator}} & \multicolumn{1}{l}{\textcolor{blue}{Syntax}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\
167 \toprule
168 \begin{lstlisting}[caption={[]}]
169 lognot*
170 \end{lstlisting} &
171 \begin{lstlisting}[caption={[]}]
172 lognot*p
173 \end{lstlisting} & Negates the boolean variable \(p\).\\
174 \midrule
175 \begin{lstlisting}[caption={[]}]
176 *logand*
177 \end{lstlisting} &
178 \begin{lstlisting}[caption={[]}]
179 p*logand*q
180 \end{lstlisting} & Gives the truth value of the expression \emph{p and q}.\\
181 \midrule
182 \begin{lstlisting}[caption={[]}]
183 *logor*
184 \end{lstlisting} &
185 \begin{lstlisting}[caption={[]}]
186 p*logor*q
187 \end{lstlisting} & Gives the truth value of the expression \emph{p or q}.\\
188 \midrule
189 \begin{lstlisting}[caption={[]}]
190 *imp*
191 \end{lstlisting} &
192 \begin{lstlisting}[caption={[]}]
193 p*imp*q
194 \end{lstlisting} & Gives the truth value of the expression \emph{if p then q}.\\
195 \midrule
196 \begin{lstlisting}[caption={[]}]
197 *iff*
198 \end{lstlisting} &
199 \begin{lstlisting}[caption={[]}]
200 p*iff*q
201 \end{lstlisting} & Gives the truth value of the expression \emph{p if and only if q}.\\
202 \midrule
203 \begin{lstlisting}[caption={[]}]
204 *lognand*
205 \end{lstlisting} &
206 \begin{lstlisting}[caption={[]}]
207 p*lognand*q
208 \end{lstlisting} & Gives the truth value of the expression \emph{ p NAND q}.\\
209 \midrule
210 \begin{lstlisting}[caption={[]}]
211 *logxor*
212 \end{lstlisting} &
213 \begin{lstlisting}[caption={[]}]
214 p*logxor*q
215 \end{lstlisting} & Gives the truth value of the expression \emph{ p XOR q}.\\
216 \midrule
217 \begin{lstlisting}[caption={[]}]
218 *lognor*
219 \end{lstlisting} &
220 \begin{lstlisting}[caption={[]}]
221 p*lognor*q
222 \end{lstlisting} & Gives the truth value of the expression \emph{ p NOR q}.\\
223 \midrule
224 \begin{lstlisting}[caption={[]}]
225 *logxnor*
226 \end{lstlisting} &
227 \begin{lstlisting}[caption={[]}]
228 p*logxnor*q
229 \end{lstlisting} & Gives the truth value of the expression \emph{ p XNOR q}.\\
230 \bottomrule \\
231 \caption{Operators in the luatruthtable package}
232 \label{tbl:truthop}
233 \end{longtable}
234 \end{center}
235
236 \section{Illustrations of commands in the luatruthtable package}\label{illtruth}
237
238 The \emph{luatruthtable} package can accept a finite number of variables. It supports a finite number of variables that one would need.
239
240 \begin{lstlisting}[label={code:illluatruth}, caption={LaTeX document with luatruthtable package}]
241 \begin{tabular}{|cc|c|c|c|c|c|c|c|c|c|}
242 \hline
243 \(p\) & \(q\) & \(\neg p\) & \(p \land q\) & \(p\lor q\) & \(p \rightarrow q\)
244 & \(p \leftrightarrow q\) & \( p\) nand \(q\) & \(p\) xor \(q\) & \( p\) nor \(q\) & \(p\) xnor \(q\) \\
245 \hline
246 \luaTruthTable{p,q}{lognot*p, p*logand*q, p*logor*q, p*imp*q, p*iff*q,
247 p*lognand*q, p*logxor*q, p*lognor*q, p*logxnor*q } \\
248 \hline
249 \end{tabular}
250 \end{lstlisting}
251
252 The LaTeX code (Listing \ref{code:illluatruth}) generates the output shown in Table \ref{tbl:luatruthtbl}.
253 \begin{table}[h]
254 \centering
255 \begin{tabular}{|cc|c|c|c|c|c|c|c|c|c|}
256 \hline
257 \(p\) & \(q\) & \(\neg p\) & \(p \land q\) & \(p\lor q\) & \(p \rightarrow q\)
258 & \(p \leftrightarrow q\) & \( p\) nand \(q\) & \(p\) xor \(q\) & \( p\) nor \(q\) & \(p\) xnor \(q\) \\
259 \hline
260 \luaTruthTable{p,q}{lognot*p, p*logand*q, p*logor*q, p*imp*q, p*iff*q,
261 p*lognand*q, p*logxor*q, p*lognor*q, p*logxnor*q } \\
262 \hline
263 \end{tabular}
264 \caption{Example 1}
265 \label{tbl:luatruthtbl}
266 \end{table}
267
268
269 \begin{lstlisting}[label={code:illluatruth2}, caption={LaTeX document with luatruthtable package}]
270 \begin{tabular}{|cccc|c|}
271 \hline
272 \(p\) & \(q\) & \( r\) & \(s\) & \(((p\land q) \rightarrow \neg r) \land s \) \\
273 \hline
274 \luaTruthTable{p,q,r,s}{((p*logand*q)*imp*(lognot*r))*logand*s } \\
275 \hline
276 \end{tabular}
277 \end{lstlisting}
278
279 The LaTeX code (Listing \ref{code:illluatruth2}) generates the output shown in Table \ref{tbl:luatruthtbl2}.
280 \begin{table}[h]
281 \centering
282 \begin{tabular}{|cccc|c|}
283 \hline
284 \(p\) & \(q\) & \( r\) & \(s\) & \(((p\land q) \rightarrow \neg r) \land s \) \\
285 \hline
286 \luaTruthTable{p,q,r,s}{((p*logand*q)*imp*(lognot*r))*logand*s } \\
287 \hline
288 \end{tabular}
289 \caption{Example 2}
290 \label{tbl:luatruthtbl2}
291 \end{table}
292
293
294
295
296
297 \section{Known Issues, Limitations and Scope of the package} The associativity and precedence of operator is not yet supported. The package can give appropriate results only when parentheses are used for each of the operation. It gives eraneous result when parentheses are not used. This point is of utmost importance in using the package. These issues are there is no native way of defining custom operations in Lua \cite{online.luacustomoperator}. However some metamethods can be nested in a way to glimpse the operators. All operators defined in this package are instances of such nestings. The question may be raised that is there better way of accomplishing this in Lua. The answer to the point is that there are alternative ways of doing this. They may be better in some or other sense. For example, instead of defining \emph{*logand*} operator and using it in the fashion \emph{p*logand*q}, one could define function \emph{logand} that takes two arguments and use it in a way \emph{logand(p,q)}. But when it comes to embedding it in LaTeX, again one has to use more and more nested parentheses as number of statements and operations increase. This is the exact reason why such approach is not used in the development of package. Instead of using \emph{implies(logand(p,logor(q,r)),s)} it sounds more natural to use \emph{(p *logand* (q*logor*r) )*implies* s}.
298
299 Apart from these issues, there is no error handling mechanism used in the package. It relies on the error handling of Lua and TeX itself. The package currently supports 9 operations viz. \emph{not,and,nand,or, xor, implies, iff, nor, xnor}. The error handling and extending number of operations may be considered in future versions of the package.
300
301 \printbibliography
302 \end{document}