1117610Sdes\chapter{Syntax} 2117610Sdes{ 3117610Sdes \newcommand{\term} {\mbox{\it term}} 4117610Sdes \newcommand{\IMP} {\mbox{\tt ==>}} 5117610Sdes \newcommand{\ALL} {\mbox{\tt !}} 6117610Sdes \newcommand{\EXISTS} {\mbox{\tt ?}} 7117610Sdes \newcommand{\CHOOSE} {\mbox{\tt @}} 8117610Sdes \newcommand{\EXISTSONE} {\mbox{\tt ?!}} 9117610Sdes \newcommand{\LET} {\mbox{\tt let}} 10117610Sdes \newcommand{\und} {\mbox{\tt and}} 11117610Sdes \newcommand{\IN} {\mbox{\tt in}} 12117610Sdes \newcommand{\CONS} {\mbox{\tt CONS}} 13117610Sdes \newcommand{\INSERT} {\mbox{\tt INSERT}} 14117610Sdes \newcommand{\SUC} {\mbox{\tt SUC}} 15117610Sdes \newcommand{\vstr} {\mbox{\it vstr}} 16117610Sdes \newcommand{\numeral} {\mbox{\it numeral}} 17117610Sdes \newcommand{\charseq} {\mbox{\it charseq}} 18117610Sdes 19117610SdesThe HOL logic is a classical higher-order predicate calculus. Its 20117610Sdessyntax enjoys two main differences from the syntax of standard first 21117610Sdesorder logic.\footnote{We assume the reader is familiar with first 22117610Sdes order logic.} First, there is no distinction in HOL between terms 23117610Sdesand formulas: HOL has only terms. Second, each term has a type: types 24117610Sdesare used in order to build well-formed terms. There are two ways to 25117610Sdesconstruct types and terms in HOL: by use of a parser, or by use of the 26117610Sdesprogrammer's interface. In this chapter, we will focus on the concrete 27117610Sdessyntax accepted by the parsers. 28117610Sdes 29117610Sdes 30117610Sdes\section{Types} 31117610Sdes 32117610SdesA HOL type can be a variable, a constant, or a compound type, which is 33117610Sdesa constant of arity $n$ applied to a list of $n$ types. 34117610Sdes\[ 35117610Sdes\begin{array}{rclr} 36117610Sdes \type & ::= & \mbox{\bf '}\ident & \mbox{(type variable)} \\ 37117610Sdes & | & \verb+bool+ & \mbox{(type of truth values)} \\ 38117610Sdes & | & \verb+ind+ & \mbox{(type of individuals)} \\ 39117610Sdes & | & \type\ \verb+->+\ \type & \mbox{(function arrow)} \\ 40117610Sdes & | & \type\ \ident\ \type\ & \mbox{(binary compound type)}\\ 41117610Sdes & | & \ident & \mbox{(nullary type constant)} \\ 42117610Sdes & | & \type\; \ident & \mbox{(unary compound type)} \\ 43117610Sdes & | & (\type_1,\ldots,\type_n) \ident & \mbox{(compound type)} 44117610Sdes\end{array} 45117610Sdes\] 46117610SdesType constants are also known as type operators. They must be 47117610Sdesalphanumeric. Type variables are alphanumerics written with a leading 48117610Sdesprime ('). In \HOL{}, the type constants {\tt bool}, {\tt fun}, and 49117610Sdes{\tt ind} are primitive. The introduction of new type constants is 50117610Sdesdescribed in Section~\ref{type-defs}. {\tt bool} is the two element type 51117610Sdesof truth values. The binary operator {\tt fun} is used to denote 52117610Sdesfunction types; it can be written with an infix arrow. The nullary 53117610Sdestype constant {\tt ind} denotes an infinite set of individuals; it is 54117610Sdesused for a few highly technical developments in the system and can be 55117610Sdesignored by beginners. Thus 56117610Sdes\begin{verbatim} 57117610Sdes 'a -> 'b 58117610Sdes (bool -> 'a) -> ind 59117610Sdes\end{verbatim} 60117610Sdesare both well-formed types. The function arrow is ``right associative'', 61117610Sdeswhich means that ambiguous uses of the arrow in types are resolved by 62117610Sdesadding parentheses in a right-to-left sweep: thus the type expression 63117610Sdes\begin{verbatim} 64117610Sdes ind -> ind -> ind -> ind 65117610Sdes\end{verbatim} 66117610Sdesis identical to 67117610Sdes\begin{verbatim} 68117610Sdes ind -> (ind -> (ind -> ind)). 69117610Sdes\end{verbatim} 70117610SdesThe product (\verb+#+) and sum (\verb!+!) are other infix type 71117610Sdesoperators, also right associative; however, they are not loaded by 72117610Sdesdefault in \HOL{}. How to load in useful logical context is described 73117610Sdesin Section~\ref{theoryfns}. 74117610Sdes 75117610Sdes\section{Terms} 76117610Sdes 77117610SdesUltimately, a HOL term can only be a variable, a constant, an 78117610Sdesapplication, or a lambda term. 79117610Sdes\[ 80117610Sdes\begin{array}{rclr} 81117610Sdes \term & ::= & \ident & \mbox{(variable or constant)} \\ 82117610Sdes & | & \term\ \term & \mbox{(combination)} \\ 83117610Sdes & | & \bs\ident.\ \term & 84117610Sdes \mbox{(lambda abstraction)} 85117610Sdes\end{array} 86117610Sdes\] 87117610SdesIn the system, the usual logical operators have already been defined, 88117610Sdesincluding truth (\verb+T+), falsity (\verb+F+), negation (\verb+~+), 89117610Sdesequality (\verb+=+), conjunction (\verb+/\+), disjunction (\verb+\/+), 90117610Sdesimplication (\verb+==>+), universal (\verb+!+) and existential 91117610Sdes(\verb+?+) quantification, and an indefinite description operator 92117610Sdes(\verb+@+). As well, the basis includes conditional, lambda, and `let' 93117610Sdesexpressions. Thus the set of terms available is, in general, an 94117610Sdesextension of the following grammar: 95117610Sdes\[ 96117610Sdes\begin{array}{rclr} 97117610Sdes \mbox{\it term} & ::= & \term : \type & \mbox{(type constraint)} \\ 98117610Sdes & | & \term\ \term & \mbox{(application)} \\ 99117610Sdes & | & \verb+~+ \term & \mbox{(negation)} \\ 100117610Sdes & | & \term\ =\ \term & \mbox{(equality)} \\ 101117610Sdes & | & \term\ \IMP\ \term & \mbox{(implication)} \\ 102117610Sdes & | & \term\ \verb+\/+\ \term & \mbox{(disjunction)} \\ 103117610Sdes & | & \term\ \verb+/\+\ \term & \mbox{(conjunction)} \\ 104117610Sdes & | & \texttt{if}\ \term\ \texttt{then}\ \term\ \texttt{else}\ \term & 105117610Sdes \mbox{(conditional)} \\ 106117610Sdes & | & \bs\ident_1\ldots\ident_n.\ \term & \mbox{(lambda abstraction)} \\ 107117610Sdes & | & \ALL \ident_1\ldots\ident_n.\ \term & \mbox{(forall)} \\ 108117610Sdes & | & \EXISTS \ident_1\ldots\ident_n.\ \term & \mbox{(exists)} \\ 109117610Sdes & | & \CHOOSE \ident_1\ldots\ident_n.\ \term & \mbox{(choose)} \\ 110117610Sdes & | & \EXISTSONE \ident_1\ldots\ident_n.\ \term &\mbox{(exists-unique)} \\ 111117610Sdes & | & \LET\; \ident = \term & \\ 112117610Sdes & & [\und\ \ident = \term]^{*}\ \IN\ \term & \mbox{(let expression)} \\ 113117610Sdes & | & \verb+T+ & \mbox{(truth)} \\ 114117610Sdes & | & \verb+F+ & \mbox{(falsity)} \\ 115117610Sdes & | & \ident & \mbox{(constant or variable)} \\ 116117610Sdes & | & \verb+(+ \term \verb+)+ & \mbox{(parenthesized term)} 117117610Sdes\end{array} 118117610Sdes\] 119117610Sdes 120117610SdesSome examples may be found in Table \ref{syntaxExamples}. Term 121117610Sdesapplication can be iterated. Application is left associative so that 122117610Sdes$\term\ \term\ \term \ldots \term$ is equivalent in the eyes of the 123117610Sdesparser to $(\ldots((\term\ \term)\ \term) \ldots)\ \term$. 124117610Sdes 125117610SdesThe lexical structure for term identifiers is much like that for 126117610SdesML: identifiers can be alphanumeric or symbolic. Variables must be 127117610Sdesalphanumeric. A symbolic identifier is any concatenation of the characters 128117610Sdesin the following list: 129117610Sdes\begin{verbatim} 130117610Sdes #?+*/\=<>&%@!,:;_|~- 131117610Sdes\end{verbatim} 132117610Sdeswith the exception of the keywords \verb+\+, \verb+;+, \verb+=>+, 133117610Sdes\verb+|+, and \verb+:+ (colon). Any alphanumeric can be a constant except the 134117610Sdeskeywords \verb+let+, \verb+in+, \verb+and+, and \verb+of+. 135117610Sdes 136117610Sdes \begin{table}[h] 137117610Sdes\begin{center} 138117610Sdes \begin{tabular}{|r|l|} \hline 139117610Sdes \verb+x = T+ & {\it x is equal to true.} \\ 140117610Sdes \verb+!x. Person x ==> Mortal x+ & {\it All persons are mortal.} \\ 141117610Sdes \verb+!x y z. (x ==> y) /\ (y ==> z) ==> x ==> z+ & {\it Implication is 142117610Sdes transitive.} \\ 143117610Sdes \verb+!x. P x ==> Q x+ & {\it P is a subset of Q} \\ 144117610Sdes \verb+S = \f g x. f x (g x)+ & {\it Definition of a famous combinator.} \\ \hline 145117610Sdes \end{tabular} 146117610Sdes \caption{Concrete Syntax Examples}\label{syntaxExamples} 147117610Sdes\end{center} 148117610Sdes \end{table} 149117610Sdes 150117610Sdes 151117610Sdes%%% Local Variables: 152117610Sdes%%% mode: latex 153117610Sdes%%% TeX-master: "description" 154117610Sdes%%% End: 155117610Sdes