\documentstyle[makeidx]{article}
\makeindex
%\setlength{\oddsidemargin}{.5in}
%\setlength{\evensidemargin}{.5in}
%\setlength{\textwidth}{5.8in}
\begin{document}
%\setlength{\parindent}{0pt}
%\newcounter{bean}
%\begin{list}{\arabic{bean}.}{\usecounter{bean}\setlength{\leftmargin}{0pt}\setlength{\rightmargin}{0pt}\setlength{\listparindent}{20pt}\setlength{\parsep}{5pt}}
%\item[]

\begin{verbatim}#|

 Copyright (C) 1994 by Computational Logic, Inc.  All Rights Reserved.

 This script is hereby placed in the public domain, and therefore unlimited
 editing and redistribution is permitted.

 NO WARRANTY

 Computational Logic, Inc. PROVIDES ABSOLUTELY NO WARRANTY.  THE EVENT SCRIPT
 IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY AND
 FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND
 PERFORMANCE OF THE SCRIPT IS WITH YOU.  SHOULD THE SCRIPT PROVE DEFECTIVE, YOU
 ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

 IN NO EVENT WILL Computational Logic, Inc. BE LIABLE TO YOU FOR ANY DAMAGES,
 ANY LOST PROFITS, LOST MONIES, OR OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL
 DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THIS SCRIPT (INCLUDING BUT
 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
 SUSTAINED BY THIRD PARTIES), EVEN IF YOU HAVE ADVISED US OF THE POSSIBILITY OF
 SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
|#

;; Matt Kaufmann

\end{verbatim}
\noindent{\sc Event}:   Start with the initial {\bf nqthm} theory.

\addvspace{18pt}


\begin{verbatim};; Here's a little note showing a method for proving (in some cases)
;; permutation-independence of list functions that are generated by
;; associative-commutative binary functions.  For example, we'd like to
;; know that if SUMLIST is a function that adds up the elements of a
;; given list, then permuting a list X doesn't change the value of
;; SUMLIST(X).  The method is as follows.  First, we introduce a name
;; AC-FN for an arbitrary associative-commutative binary function, along
;; with the axioms saying so (and a "witness" for the consistency of this
;; axiom, namely PLUS).  This is followed by the definition of a function
;; FOLDR, which is defined in terms of AC-FN by applying it repeatedly to
;; the members of a given list.  After defining PERMUTATION-P and proving
;; some useful rewrite rules, I prove the main lemma FOLDR-PERMUTATION-P,
;; which says (informally speaking, here) that FOLDR gives the same value
;; when you permute its list argument.  Then, using the "functional
;; instantiation" mechanism in the Boyer-Moore system, I apply this
;; "generic" lemma (that is, FOLDR-PERMUTATION-P) to three examples:  the
;; sum of the elements of a list, the product of the elements of a list,
;; and the WIRED-OR of the elements of a list (in a four-valued logic,
;; intuitively speaking, though I don't actually ever need to say so).
;; 
;; As usual, this is all in Lisp syntax.  Everything from a semicolon to
;; the end of a line is a comment, and I try to use lots of those in
;; order to explain what's going on.  Without further ado, then, here is
;; the annotated list of Boyer-Moore events (i.e. input).
;; 
;; By the way, it took about two hours for me to do this exercise
;; (including documentation).  Replay time (real time) was about a minute
;; and a quarter on a Sun 3/60; run time reported was 24.8 secs.  In case
;; it's not clear.... the text below is all input to the Boyer-Moore
;; prover.
;; 
;; ============================================================

;; Add a new function declaring that the function ac-fn is
;; an associative-commutative binary function.

\end{verbatim}\begin{tabbing}{\sc Conservative Axiom}:  ac-fn-intro \\ \index{ac-fn-intro}
\=\+({\rm{ac-fn}}\,({\it{x\/}}, {\it{y\/}})\index{ac-fn} $=$ {\rm{ac-fn}}\,({\it{y\/}}, {\it{x\/}})\index{ac-fn}) \\ 
$\wedge$$\;\;\;\;$({\rm{ac-fn}}\,({\rm{ac-fn}}\,({\it{x\/}}, {\it{y\/}})\index{ac-fn}, {\it{z\/}})\index{ac-fn} $=$ {\rm{ac-fn}}\,({\it{x\/}}, {\rm{ac-fn}}\,({\it{y\/}}, {\it{z\/}})\index{ac-fn})\index{ac-fn})\-
\end{tabbing}\noindent Simultaneously, we introduce the new function symbol {\it ac-fn\/}.

\begin{verbatim};; Next, recursively define a function that continually applies the
;; binary function AC-FN to the elements of a list.  This is a
;; "fold-right" function; an analogous "fold-left" function exists,
;; and should be easy to prove equivalent to foldr; maybe I'll do that
;; later.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{foldr} \\  
\=\+{\rm{foldr}}\,({\it{lst\/}}, {\it{root\/}})\index{foldr} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{lst\/}})$\;\;${\bf then }{\rm{ac-fn}}\,({\rm{car}}\,({\it{lst\/}}), {\rm{foldr}}\,({\rm{cdr}}\,({\it{lst\/}}), {\it{root\/}})\index{foldr})\index{ac-fn} \\ 
{\bf else }{\it{root\/}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; The following function removes the first occurrence of the element
;; a from the list x; it's auxiliary to the definition of permutation-p.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{remove1} \\  
\=\+{\rm{remove1}}\,({\it{a\/}}, {\it{x\/}})\index{remove1} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{x\/}}) \\ 
{\bf then }\=\+{\bf if }{\it{a\/}} $=$ {\rm{car}}\,({\it{x\/}})$\;\;${\bf then }{\rm{cdr}}\,({\it{x\/}}) \\ 
{\bf else }{\rm{cons}}\,({\rm{car}}\,({\it{x\/}}), {\rm{remove1}}\,({\it{a\/}}, {\rm{cdr}}\,({\it{x\/}}))\index{remove1})$\;${\bf  endif}\- \\ 
{\bf else }{\it{x\/}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; Here is the usual recursive definition of permutation-p.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{permutation-p} \\  
\=\+{\rm{permutation-p}}\,({\it{x1\/}}, {\it{x2\/}})\index{permutation-p} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{x1\/}}) \\ 
{\bf then }({\rm{car}}\,({\it{x1\/}}) $\in$ {\it{x2\/}}) $\wedge$ {\rm{permutation-p}}\,({\rm{cdr}}\,({\it{x1\/}}), {\rm{remove1}}\,({\rm{car}}\,({\it{x1\/}}), {\it{x2\/}})\index{remove1})\index{permutation-p} \\ 
{\bf else }{\it{x2\/}} $\simeq\;${{\bf{nil}}}${}$$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; The strategy below is as follows.  I wanted to prove that foldr is
;; preserved under permutations of its (first) argument; that's the
;; lemma called FOLDR-PERMUTATION-P below.  The proof attempt led me
;; to prove a lemma called FOLDR-REMOVE1, which occurs just above
;; FOLDR-PERMUTATION-P.  In order to prove FOLDR-REMOVE1, though, I
;; found that I needed a property of associative-commutative
;; functions, stated in the lemma AC-FN-COMMUTATIVITY-2 below.

;; The following two lemmas are used in the proof of the lemma named
;; AC-FN-COMMUTATIVITY-2 below, which is key to FOLDR-REMOVE1, which
;; in turn is crucial for FOLDR-PERMUTATION-P.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  ac-fn-assoc-reversed \\ \index{ac-fn-assoc-reversed}
{\rm{ac-fn}}\,({\it{x\/}}, {\rm{ac-fn}}\,({\it{y\/}}, {\it{z\/}})\index{ac-fn})\index{ac-fn} $=$ {\rm{ac-fn}}\,({\rm{ac-fn}}\,({\it{x\/}}, {\it{y\/}})\index{ac-fn}, {\it{z\/}})\index{ac-fn}
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  ac-fn-comm \\ \index{ac-fn-comm}
{\rm{ac-fn}}\,({\it{x\/}}, {\it{z\/}})\index{ac-fn} $=$ {\rm{ac-fn}}\,({\it{z\/}}, {\it{x\/}})\index{ac-fn}
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  ac-fn-commutativity-2 \\ \index{ac-fn-commutativity-2}
{\rm{ac-fn}}\,({\it{z\/}}, {\rm{ac-fn}}\,({\it{x\/}}, {\it{a\/}})\index{ac-fn})\index{ac-fn} $=$ {\rm{ac-fn}}\,({\it{x\/}}, {\rm{ac-fn}}\,({\it{z\/}}, {\it{a\/}})\index{ac-fn})\index{ac-fn}
\end{tabbing}

\begin{verbatim};; The lemma AC-FN-ASSOC-REVERSED was used in the proof of the lemma
;; immediately above, but now we want to turn it off as a rewrite rule
;; so that it doesn't loop in combination with the associativity rule
;; introduced at the outset.
\end{verbatim}
\noindent{\sc Event}:   Disable ac-fn-assoc-reversed.

\addvspace{18pt}

\begin{tabbing}{\sc Theorem}:  foldr-remove1 \\ \index{foldr-remove1}
({\it{z\/}} $\in$ {\it{x2\/}}) $\rightarrow$ ({\rm{ac-fn}}\,({\it{z\/}}, {\rm{foldr}}\,({\rm{remove1}}\,({\it{z\/}}, {\it{x2\/}})\index{remove1}, {\it{root\/}})\index{foldr})\index{ac-fn} $=$ {\rm{foldr}}\,({\it{x2\/}}, {\it{root\/}})\index{foldr})
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  foldr-permutation-p \\ \index{foldr-permutation-p}
{\rm{permutation-p}}\,({\it{x1\/}}, {\it{x2\/}})\index{permutation-p} $\rightarrow$ ({\rm{foldr}}\,({\it{x1\/}}, {\it{root\/}})\index{foldr} $=$ {\rm{foldr}}\,({\it{x2\/}}, {\it{root\/}})\index{foldr})
\end{tabbing}

\begin{verbatim};; Having proved this general fact about foldr, let us apply it to
;; three examples:  the sum of the elements of a list, the product
;; of the elements of a list, and a wired-or function.

;;;;;;;;;; SUMLIST ;;;;;;;;;;

;; First, we give a natural recursive definition of the sum of the
;; elements of a list.  One could easily generate such definitions
;; automatically from the definition of foldr, by the way; for now,
;; I'll take each application as it comes.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{sumlist} \\  
\=\+{\rm{sumlist}}\,({\it{lst\/}})\index{sumlist} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{lst\/}})$\;\;${\bf then }{\rm{car}}\,({\it{lst\/}}) $+$ {\rm{sumlist}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{sumlist} \\ 
{\bf else }{\tt{0}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; Let us now instantiate the main result called FOLDR-PERMUTATION-P
;; above to the particular case in question, i.e. to the case of the
;; sum of the elements of a list.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  sumlist-permutation-p-lemma \\ \index{sumlist-permutation-p-lemma}
{\it{*auto*\/}}
\end{tabbing}

\begin{verbatim};; Finally, I'll use the lemma above as a hint so that the theorem that
;; SUMLIST is invariant under a permutation of its argument is immediate.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  sumlist-permutation-p \\ \index{sumlist-permutation-p}
{\rm{permutation-p}}\,({\it{x1\/}}, {\it{x2\/}})\index{permutation-p} $\rightarrow$ ({\rm{sumlist}}\,({\it{x1\/}})\index{sumlist} $=$ {\rm{sumlist}}\,({\it{x2\/}})\index{sumlist})
\end{tabbing}

\begin{verbatim};;;;;;;;;; TIMESLIST ;;;;;;;;;;

;; Now let's repeat the exercise above for TIMES.  This case proceeds
;; similarly to the PLUS case, except we need a few lemmas about TIMES
;; because less is built into the prover about TIMES than for PLUS.
;; In practice, many users of the prover at CLInc would load a
;; standard arithmetic library that has these facts about TIMES, any
;; many others, included in it.  (Such a library will have already
;; been proved correct, so such an inclusion is sound.)

\end{verbatim}\begin{tabbing}{\sc Theorem}:  times-assoc \\ \index{times-assoc}
(({\it{x\/}} $*$ {\it{y\/}}) $*$ {\it{z\/}}) $=$ ({\it{x\/}} $*$ ({\it{y\/}} $*$ {\it{z\/}}))
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  times-1 \\ \index{times-1}
({\it{x\/}} $*$ {\tt{1}}) $=$ {\rm{fix}}\,({\it{x\/}})
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  times-comm \\ \index{times-comm}
({\it{x\/}} $*$ {\it{z\/}}) $=$ ({\it{z\/}} $*$ {\it{x\/}})
\end{tabbing}

\begin{verbatim};; Now we repeat the three main events that we did for PLUS:
;; definition of the n-ary version, the functional instantiation, and
;; the main result.  It turns out that we need the "commutativity-2"
;; property proved above for ac-fn as a lemma; the first
;; functionally-instantiate event below derives this property for
;; times as an immediate corollary.

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{timeslist} \\  
\=\+{\rm{timeslist}}\,({\it{lst\/}})\index{timeslist} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{lst\/}})$\;\;${\bf then }{\rm{car}}\,({\it{lst\/}}) $*$ {\rm{timeslist}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{timeslist} \\ 
{\bf else }{\tt{1}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; Need commutativity-2 as a lemma.....

\end{verbatim}\begin{tabbing}{\sc Theorem}:  times-commutativity-2 \\ \index{times-commutativity-2}
{\it{*auto*\/}}
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  timeslist-permutation-p-lemma \\ \index{timeslist-permutation-p-lemma}
{\it{*auto*\/}}
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  timeslist-permutation-p \\ \index{timeslist-permutation-p}
{\rm{permutation-p}}\,({\it{x1\/}}, {\it{x2\/}})\index{permutation-p} $\rightarrow$ ({\rm{timeslist}}\,({\it{x1\/}})\index{timeslist} $=$ {\rm{timeslist}}\,({\it{x2\/}})\index{timeslist})
\end{tabbing}

\begin{verbatim};;;;;;;;;; WIRED-OR ;;;;;;;;;;

;; Let's say that wired-or treats Z as an identity, and returns X if
;; either argument is not Z.  In particular, the OR of Z with itself
;; is Z.

;; First, the binary version.....

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{or2} \\  
\=\+{\rm{or2}}\,({\it{a\/}}, {\it{b\/}})\index{or2} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\it{a\/}} $=$ {\tt{'}}{\tt{z}}$\;\;${\bf then }{\it{b\/}} \\ 
{\bf elseif }{\it{b\/}} $=$ {\tt{'}}{\tt{z}}$\;\;${\bf then }{\it{a\/}} \\ 
{\bf else }{\tt{'}}{\tt{x}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; Now, the list version, defined analogously to FOLDR:

\end{verbatim}\begin{tabbing}{\sc Definition}:\index{wired-or} \\  
\=\+{\rm{wired-or}}\,({\it{lst\/}})\index{wired-or} \\ 
$=$$\;\;\;\;$\=\+{\bf if }{\rm{listp}}\,({\it{lst\/}})$\;\;${\bf then }{\rm{or2}}\,({\rm{car}}\,({\it{lst\/}}), {\rm{wired-or}}\,({\rm{cdr}}\,({\it{lst\/}}))\index{wired-or})\index{or2} \\ 
{\bf else }{\tt{'}}{\tt{z}}$\;${\bf  endif}\-\-
\end{tabbing}

\begin{verbatim};; Now we just copy the usual two events, using 'z for root.
;; Commutativity-2 should be trivial in this case, so I won't separate
;; it out as a separate lemma as I did for the TIMES version above.

\end{verbatim}\begin{tabbing}{\sc Theorem}:  wired-or-permutation-p-lemma \\ \index{wired-or-permutation-p-lemma}
{\it{*auto*\/}}
\end{tabbing}

\begin{tabbing}{\sc Theorem}:  wired-or-permutation-p \\ \index{wired-or-permutation-p}
{\rm{permutation-p}}\,({\it{x1\/}}, {\it{x2\/}})\index{permutation-p} $\rightarrow$ ({\rm{wired-or}}\,({\it{x1\/}})\index{wired-or} $=$ {\rm{wired-or}}\,({\it{x2\/}})\index{wired-or})
\end{tabbing}

%\end{list}
\printindex
\end{document}
