doc-src/Logics/HOL.tex
changeset 4591 f88e466c43fa
parent 4503 5ed72705c201
child 4803 8428d4699d58
equal deleted inserted replaced
4590:9f8f931e0089 4591:f88e466c43fa
  1983     "fib 0 = 0"
  1983     "fib 0 = 0"
  1984     "fib 1 = 1"
  1984     "fib 1 = 1"
  1985     "fib (Suc(Suc x)) = (fib x + fib (Suc x))"
  1985     "fib (Suc(Suc x)) = (fib x + fib (Suc x))"
  1986 \end{ttbox}
  1986 \end{ttbox}
  1987 
  1987 
       
  1988 With \texttt{recdef}, function definitions may be incomplete, and patterns may
       
  1989 overlap, as in functional programming.  The \texttt{recdef} package
       
  1990 disambiguates overlapping patterns by taking the order of rules into account.
       
  1991 For missing patterns, the function is defined to return an arbitrary value.
       
  1992 
  1988 The well-founded relation defines a notion of ``smaller'' for the function's
  1993 The well-founded relation defines a notion of ``smaller'' for the function's
  1989 argument type.  The relation $\prec$ is \textbf{well-founded} provided it
  1994 argument type.  The relation $\prec$ is \textbf{well-founded} provided it
  1990 admits no infinitely decreasing chains
  1995 admits no infinitely decreasing chains
  1991 \[ \cdots\prec x@n\prec\cdots\prec x@1. \]
  1996 \[ \cdots\prec x@n\prec\cdots\prec x@1. \]
  1992 If the function's argument has type~$\tau$, then $\prec$ should be a relation
  1997 If the function's argument has type~$\tau$, then $\prec$ should be a relation
  2026 \begin{ttbox}
  2031 \begin{ttbox}
  2027 recdef gcd "measure ((\%(m,n).n) ::nat*nat=>nat)"
  2032 recdef gcd "measure ((\%(m,n).n) ::nat*nat=>nat)"
  2028     "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
  2033     "gcd (m, n) = (if n=0 then m else gcd(n, m mod n))"
  2029 \end{ttbox}
  2034 \end{ttbox}
  2030 
  2035 
  2031 The general form of a primitive recursive definition is
  2036 The general form of a well-founded recursive definition is
  2032 \begin{ttbox}
  2037 \begin{ttbox}
  2033 recdef {\it function} {\it rel}
  2038 recdef {\it function} {\it rel}
  2034     congs   {\it congruence rules}      {\bf(optional)}
  2039     congs   {\it congruence rules}      {\bf(optional)}
  2035     simpset {\it simplification set}      {\bf(optional)}
  2040     simpset {\it simplification set}      {\bf(optional)}
  2036    {\it reduction rules}
  2041    {\it reduction rules}
  2055   
  2060   
  2056 \item \textit{reduction rules} specify one or more recursion equations.  Each
  2061 \item \textit{reduction rules} specify one or more recursion equations.  Each
  2057   left-hand side must have the form $f\,t$, where $f$ is the function and $t$
  2062   left-hand side must have the form $f\,t$, where $f$ is the function and $t$
  2058   is a tuple of distinct variables.  If more than one equation is present then
  2063   is a tuple of distinct variables.  If more than one equation is present then
  2059   $f$ is defined by pattern-matching on components of its argument whose type
  2064   $f$ is defined by pattern-matching on components of its argument whose type
  2060   is a \texttt{datatype}.  The patterns must be exhaustive and
  2065   is a \texttt{datatype}.  
  2061   non-overlapping.  
  2066 
  2062   
       
  2063   Unlike with \texttt{primrec}, the reduction rules are not added to the
  2067   Unlike with \texttt{primrec}, the reduction rules are not added to the
  2064   default simpset, and individual rules may not be labelled with identifiers.
  2068   default simpset, and individual rules may not be labelled with identifiers.
  2065   However, the identifier $f$\texttt{.rules} is visible at the \ML\ level
  2069   However, the identifier $f$\texttt{.rules} is visible at the \ML\ level
  2066   as a list of theorems.
  2070   as a list of theorems.
  2067 \end{itemize}
  2071 \end{itemize}