![我如何以这种方式显示命题逻辑的验证?](https://linux22.com/image/326011/%E6%88%91%E5%A6%82%E4%BD%95%E4%BB%A5%E8%BF%99%E7%A7%8D%E6%96%B9%E5%BC%8F%E6%98%BE%E7%A4%BA%E5%91%BD%E9%A2%98%E9%80%BB%E8%BE%91%E7%9A%84%E9%AA%8C%E8%AF%81%EF%BC%9F.png)
答案1
不幸的是,LaTeX 对逻辑的支持并不好。至少,如果支持的话,我还没有找到支持。一切似乎总是涉及到针对其他问题的解决方案,并让它做其他事情。
如果您有耐心,可以使用类似的东西。我发现它tabular
比数学环境麻烦少,因为无论如何,所有的 Ts、Fs、Ps、Qs 等都需要使用本质上是文本字体的东西。(至少如果您的文本字体也用于数学模式下的运算符等,这是很常见的。)并且切换到数学模式进行其他操作比\text{}
一直输入文本模式要轻松得多。
\documentclass[oneside,12pt]{article}
\usepackage{microtype}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{*{4}{c}|r@{}ccc@{\thinspace}r@{}*{3}{c}@{\thinspace}c@{}lcr@{}*{3}{c}@{\thinspace}c@{\thinspace}c@{}l}
P&Q&R&S&$(\{$&S&$\land$&$\lnot$&$($&Q &$\land$& $\lnot$&P&$)\}$&$\lor$&$\{$&R&$\lor$&$\lnot$&$\lnot$&Q&$\})$\\\hline
T&F&F&F& &F&F&T&& F&F&F&T &&F &&F&F&F&T&F\\
\end{tabular}
\end{document}
有些脚本可以为你生成表格,但是如果你正在学习逻辑学,那就没用了,因为你需要自己弄清楚表格。另一方面,如果你正在教逻辑学,它们会非常有用。它们也不会进行我在这里提到的间距调整。至少,我使用的那个没有。
答案2
只要完成一些幕后工作,您就可以用相当自然的语法输入真值表。
\documentclass{article}
\usepackage{xparse,array}
\ExplSyntaxOn
\NewDocumentCommand{\truthtable}{mm}
{
\group_begin:
\setlength{\arraycolsep}{0pt}
\crocket_truth_make_preamble:n { #1 }
\crocket_truth_make_body:n { #2 }
\crocket_truth_make:
\group_end:
}
% variables
\tl_new:N \l__crocket_truth_preamble_tl
\tl_new:N \l__crocket_truth_first_tl
\tl_new:N \l__crocket_truth_body_tl
\seq_new:N \l__crocket_truth_rows_seq
% internal functions
\cs_new_protected:Nn \crocket_truth_make_preamble:n
{
\tl_clear:N \l__crocket_truth_preamble_tl
\tl_clear:N \l__crocket_truth_first_tl
% examine the first argument in order to build the table
% preamble and the first row
\tl_map_inline:nn { #1 }
{
\tl_if_in:VnTF \c_crocket_truth_delims_tl { ##1 }
{% a delimiter is inserted in @{...} as a phantom (almost)
% and not taken into account for the first row
\tl_put_right:Nn \l__crocket_truth_preamble_tl { @{ \__crocket_truth_delim:n {##1} } }
}
{
\tl_if_eq:nnTF { | } { ##1 }
{% vertical bar is ignored in the rows, but it gives a | in
% the table preamble (actually, quad | quad)
\tl_put_right:Nn \l__crocket_truth_preamble_tl { @{\hspace{1em}}|@{\hspace{1em}} }
}
{% otherwise, c is added to the table preamble and
% the item to the first row
\tl_put_right:Nn \l__crocket_truth_preamble_tl { c }
\tl_put_right:Nn \l__crocket_truth_first_tl { ##1 & }
}
}
}
% since rows will end with &, we add a dummy trailing column
\tl_put_right:Nn \l__crocket_truth_preamble_tl { c } % empty last column
}
\cs_new_protected:Nn \crocket_truth_make_body:n
{% start building the table body
\tl_clear:N \l__crocket_truth_body_tl
% split the argument at \\
\seq_set_split:Nnn \l__crocket_truth_rows_seq { \\ } { #1 }
% and map it
\seq_map_inline:Nn \l__crocket_truth_rows_seq
{% each item is a row; map it to add &
\tl_map_inline:nn { ##1 }
{% but ignoring |
\tl_if_eq:nnF { | } { ####1 }
{
\tl_put_right:Nn \l__crocket_truth_body_tl { \crocket_truth_tf:n { ####1 } & }
}
}
% append the row terminator
\tl_put_right:Nn \l__crocket_truth_body_tl { \\ }
}
}
\cs_new_protected:Nn \crocket_truth_make:
{% make the table
\exp_args:NnV \begin {array} \l__crocket_truth_preamble_tl
% temporary define \__crocket_truth_delim:n to produce its argument
\noalign { \cs_gset_eq:NN \__crocket_truth_delim:n \use:n }
% output the first row
\tl_use:N \l__crocket_truth_first_tl \\
\hline
% make \__crocket_truth_delim:n to deliver a phantom
\noalign { \cs_gset_eq:NN \__crocket_truth_delim:n \hphantom }
\tl_use:N \l__crocket_truth_body_tl
\end{array}
}
\cs_new_protected:Nn \crocket_truth_tf:n { \makebox[1.2em]{ $ \mathrm { #1 }$ } }
\tl_const:Nn \c_crocket_truth_delims_tl { ()[]\{\} }
\ExplSyntaxOff
\begin{document}
\[
\truthtable{
P Q | (P \land Q)\lor P
}{
T T | T T T T T\\
T F | T F F T T
}
\]
\[
\truthtable{
P Q R S | (\{ S \land \lnot ( Q \land \lnot P )\} \lor \{ R \lor \lnot \lnot Q \})
}{
T F F F | F F T F F F T F F F F T F\\
T F F F | F F T F F F T F F F F T F\\
T F F F | F F T F F F T F F F F T F\\
T F F F | F F T F F F T F F F F T F
}
\]
\end{document}
答案3
另一种方法。在运算符后立即写入逻辑值:
\def\use#1#2{\kern-1.2pt
{\kern2pt#1\kern2pt\over{\ifx^#2^\else\rm\ifcase#2 F\or T\fi\fi}}\kern-1.2pt }
\def\n#1{\use #1{}}
\def\P#1{\use P#1} \def\Q#1{\use Q#1} \def\R#1{\use R#1} \def\S#1{\use S#1}
\def\formula{\use{}{}\vrule\use{}{}}
\def\And#1{\use \wedge#1} \def\Or#1{\use \vee#1} \def\Not#1{\use\neg#1}
$$
\P1 \Q0 \R0 \S0
\formula
\n(\n\{ \S0 \And0 \Not1 \n(\Q0 \And0 \Not0 \P1 \n)\n\}
\Or0
\n\{ \R0 \Or0 \Not0 \Not1 \Q0 \n\}\n)
$$
\bye