如何实现DebateTree算法?

如何实现DebateTree算法?

DebateTree 算法(以前称为辩证算法)是一种递归算法,用于根据辩论树的结构计算任何论点的状态(已维持或已驳斥)。该算法抓住了直观的想法,即当论点有无可辩驳的反对意见时,应将其视为已驳斥,否则应视为已维持。——维基百科

如何在 LaTeX 中实现该算法(最好不要使用 LuaLaTeX)?

这是我一直在思考的结构,答案不必符合它才能被接受,它只是为了提供灵感。

\argument{First argument}{
    \objection{First objection}{
        \objection{Counter objection}{}}
    \objection{Second objection}{}}

输出可能如下:

(+) F̶i̶r̶s̶t̶ ̶a̶r̶g̶u̶m̶e̶n̶t̶
    (!) F̶i̶r̶s̶t̶ ̶o̶b̶j̶e̶c̶t̶i̶o̶n̶
        (!) Counter-objection
    (!) Second objection

答案1

在此处输入图片描述

\documentclass{article}

% Typesetting Debates with the Debate Tree Algorithm
% https://en.wikiversity.org/wiki/DebateTree_algorithm
\newcommand\DBTsustained{sustained}% define \DBTsustained and \DBTrefuted to be any
\newcommand\DBTrefuted{refuted}    %   two different values, like "sustained" and "refuted"
% \DBTevaluate{ignored}{list of objections}
\newcommand\DBTevaluate[2]{%       % evaluate the objections in #2
  \begingroup                      %
  \let\DBTResult\DBTrefuted        %   assume that all objections can be refuted
  #2%                              %   iterate through the objections, sustained ones will set \DBTResult to \DBTsustained
  \global\let\DBTtmp\DBTResult     %   move the result of the evaluation outside of the group
  \endgroup                        %
  \ifx\DBTtmp\DBTrefuted           %   If all sub-objections have been refuted then
    \let\DBTResult\DBTsustained    %     this argument/objection can be sustained
  \fi                              %   otherwise the status in \DBTResult remains unchanged
}
% \DBTtypeset{\typesetSustained}{\typesetRefuted}{argument}{list of objections}
\newcommand\DBTtypeset[4]{%        % evaluate objections, typeset argument, and then typeset sub-debate
  \let\objection\DBTevaluate       %   set \objection to evaluation mode
  \let\DBTResult\DBTrefuted        %   assume that all objections can be refuted
  #4%                              %   evaluate objections
  \ifx\DBTResult\DBTrefuted        %   if all objections have been refuted
    #1{#3}%                        %     \typesetSustained{argument}
  \else                            %   else
    #2{#3}%                        %     \typesetRefuted{argument}
  \fi                              %   endif
  \def\objection{\DBTtypeset\ObjSustained\ObjRefuted}% set \objection to typesetting mode
  \begin{debate}                   %   typeset sub-debate
    #4%                            %   typeset objections
  \end{debate}
}
\newcommand\objection{}
\newcommand\argument{\DBTtypeset\ArgSustained\ArgRefuted}

% typesetting of sub-debates (= list of objections)
\newenvironment{debate}{%
  \advance\leftskip 2em%
}{}
% typesetinng of arguments and objections, sustained or refuted
\usepackage{soul}
\newcommand\ArgSustained[1]{\noindent(+) \textbf{Argument:} #1\par}
\newcommand\ArgRefuted  [1]{\noindent(+) \st{\textbf{Argument:} #1}\par}
\newcommand\ObjSustained[1]{\noindent(!) \textbf{Objection:} #1\par}
\newcommand\ObjRefuted  [1]{\noindent(!) \st{\textbf{Objection:} #1}\par}

\begin{document}

\section*{The debate from the original posting}

\argument{First argument}{
  \objection{First objection}{
    \objection{Counter objection}{}
  }
  \objection{Second objection}{}
}

\section*{The sample debate from Wikiversity}

\argument{Causing unnecessary suffering on animals is morally wrong. Eating or otherwise exploiting animals is unnecessary and causes much suffering. Therefore, eating or otherwise exploiting animals is morally wrong and should be abolished.}{
  \objection{Non-human animals have no feelings and suffer no pain.}{
    \objection{Non-human animals behave very similar to us humans under circumstances that would cause us pain: they scream (or produce other loud noises), shake, contort, run, try to avoid the source of pain, etc.}{}
    \objection{Non-human animals, especially mammals and birds, have a nervous system very similar to our own.}{}
  }
  \objection{Animals in the wild suffer more, as starvation and predation is a constant threat to them. For a natural equilibrium, all animal species living in the wild live at the brink of starvation, as an excess of food leads to their numbers increasing, then collapsing.}{
    \objection{Animals in factory farms suffer guaranteed predation at a fraction of their natural life span. They don't lack food, true, but they are systematically mutilated, exploited, denied of basic freedom of movement, electrocuted, kicked, and many, many, many other atrocities. In traditional farms, animals are denied freedom of movement and reproduction, and also suffer guaranteed predation at a fraction of their natural life span.}{}
  }
}
    
\end{document}

相关内容