tame/design/tpl/sec/class.tex

151 lines
4.9 KiB
TeX
Raw Normal View History

\section{Classification System}\seclabel{class}
\index{classification}
A \emph{classification} is a user-defined abstraction that describes
(``classifies'') arbitrary data.
Classifications can be used as predicates, generating functions, and can be
composed into more complex classifications.
Nearly all conditions in \tame{} are specified using classifications.
\index{first-order logic!sentence}
\index{classification!coupling}
All classifications represent \emph{first-order sentences}---%
that is,
they contain no \emph{free variables}.
Intuitively,
this means that all variables within a~classification are
\emph{tightly coupled} to the classification itself.
This limitation is mitigated through use of the template system.
\index{classification!conjunctive}
\begin{definition}[\logand-Classification]\dfnlabel{classu}
A conjunctive\footnote{%
Conjunctive and disjunctive classifications used to be referred to,
respectively,
as \emph{universal} and \emph{existential},
referring to fact that
$\forall\Set{a_0,\ldots,a_n}(a) \equiv a_0\logand\ldots\logand a_n$,
and similarly for $\exists$.
This terminology has changed since all classifications are in fact
existential over their matches' index sets,
and so the terminology would otherwise lead to confusion.
}
classification~$c$ performs conjunction on its match expressions
$M_0\ldots M_n$.
\begin{align*}
&\xml{<classify as="$c$" yields="$\gamma$" desc="$\ldots$">} \\
&\quad M_0 \\
&\quad \vdots \\
&\quad M_n \\
&\xml{</classify>}
\equiv \Classify^c_\gamma M_0 \logand \ldots \logand M_n.
\end{align*}
\end{definition}
\index{classification!disjunctive}
\begin{definition}[\logor-Classification]\dfnlabel{classe}
A disjunctive classification~$d$ with \xpath{@any="true"}
performs disjunction on its match expressions
$M_0\ldots M_n$.\footnote{%
It is notationally convenient that~$c$ is a common prefix for both
\underline{c}lassification \emph{and} \underline{c}onjunction,
and also that~$d$ happens to follow~$c$ \emph{and} be the prefix for
\underline{d}isjunction.
This notation will only be used where such a distinction is relevant,
and $c$~will otherwise refer generically to any type of
classification.}
\begin{align*}
&\xml{<classify as="$d$" yields="$\gamma$" any="true" desc="$\ldots$">} \\
&\quad M_0 \\
&\quad \vdots \\
&\quad M_n \\
&\texttt{</classify>}
\equiv \Classify^d_\gamma M_0 \logor \ldots \logor M_n.
\end{align*}
\end{definition}
\todo{$\Classify$ itself has not yet been defined.}
For example,
consider the following classification $\Classify^\texttt{cost-exceeded}$.
Let~\tameparam{cost} be a scalar parameter.
\index{classification!classify@\xmlnode{classify}}
\begin{lstlisting}
<classify as="cost-exceeded" desc="Cost of item is too expensive">
<t:match-gt on="cost" value="100.00" />
</classify>
\end{lstlisting}
\noindent
is then equivalent to the proposition
\begin{equation*}
\tameclass{cost-exceeded} \equiv \tameparam{cost} > 100.00.
\end{equation*}
\index{classification!domain}
A classification is either \true or~\false.
Let $\tameparam{cost}=150.00$.
Then,
\begin{align*}
\tameclass{cost-exceeded} & \equiv \tameparam{cost} > 100.00 \\
& \equiv 150.00 > 100.00 \\
& \equiv \true.
\end{align*}
Each \xmlnode{match} of a classification is a~\emph{predicate}.
Multiple predicates are by default joined by conjunction:
\begin{lstlisting}
<classify as="pool-hazard" desc="Hazardous pool">
<match on="diving_board" />
<t:match-lt on="pool_depth_ft" value="8" />
</classify>
\end{lstlisting}
\noindent
is equivalent to the proposition
\begin{equation*}
\tameclass{pool-hazard} \equiv \tameparam{diving\_board}
\logand \tameparam{pool\_depth\_ft} < 8.
\end{equation*}
\subsection{Matches}
\begin{definition}[Match Equality]
\begin{equation*}
\xml{<match on="$x$" value="$y$" />} \equiv x = y.
\end{equation*}
\end{definition}
\begin{definition}[Match Equality Short Form]
\begin{equation*}
\xml{<match on="$x$" />}
\equiv \xml{<match on="$x$" value="TRUE" />}.
\end{equation*}
\end{definition}
\begin{definition}[Match Equality Long Form]
\begin{alignat*}{2}
\xml{<match on="$x$" value="$y$" />}
&\equiv {}&&\xml{<match on="$x$">} \\
& &&\quad \xml{<c:eq>} \\
& &&\quad\quad \xml{<c:value-of name="$y$">} \\
& &&\quad \xml{</c:eq>} \\
& &&\xml{</match>} \\
&\equiv {}&&\xml{<t:match-eq on="$x$" value="$y$" />}.
\end{alignat*}
\end{definition}
\begin{definition}[Match Membership Equivalence]
When $T$ is a type defined with \xmlnode{typedef},
\begin{equation*}
\xml{<match on="$x$" anyOf="$T$" />} \equiv x \in T.
\end{equation*}
\end{definition}