1221 which associates to the right and has a lower priority than $*$: $\tau@1 + |
1221 which associates to the right and has a lower priority than $*$: $\tau@1 + |
1222 \tau@2 + \tau@3*\tau@4$ means $\tau@1 + (\tau@2 + (\tau@3*\tau@4))$. |
1222 \tau@2 + \tau@3*\tau@4$ means $\tau@1 + (\tau@2 + (\tau@3*\tau@4))$. |
1223 |
1223 |
1224 The definition of products and sums in terms of existing types is not |
1224 The definition of products and sums in terms of existing types is not |
1225 shown. The constructions are fairly standard and can be found in the |
1225 shown. The constructions are fairly standard and can be found in the |
1226 respective theory files. |
1226 respective theory files. Although the sum and product types are |
|
1227 constructed manually for foundational reasons, they are represented as |
|
1228 actual datatypes later (see \S\ref{subsec:datatype:rep_datatype}). |
|
1229 Therefore, the theory \texttt{Datatype} should be used instead of |
|
1230 \texttt{Sum} or \texttt{Prod}. |
1227 |
1231 |
1228 \begin{figure} |
1232 \begin{figure} |
1229 \begin{constants} |
1233 \begin{constants} |
1230 \it symbol & \it meta-type & & \it description \\ |
1234 \it symbol & \it meta-type & & \it description \\ |
1231 \cdx{Inl} & $\alpha \To \alpha+\beta$ & & first injection\\ |
1235 \cdx{Inl} & $\alpha \To \alpha+\beta$ & & first injection\\ |
1232 \cdx{Inr} & $\beta \To \alpha+\beta$ & & second injection\\ |
1236 \cdx{Inr} & $\beta \To \alpha+\beta$ & & second injection\\ |
1233 \cdx{sum_case} & $[\alpha\To\gamma, \beta\To\gamma, \alpha+\beta] \To\gamma$ |
1237 \cdx{sum_case} & $[\alpha\To\gamma, \beta\To\gamma, \alpha+\beta] \To\gamma$ |
1234 & & conditional |
1238 & & conditional |
1235 \end{constants} |
1239 \end{constants} |
1236 \begin{ttbox}\makeatletter |
1240 \begin{ttbox}\makeatletter |
1237 %\tdx{sum_case_def} sum_case == (\%f g p. @z. (!x. p=Inl x --> z=f x) & |
|
1238 % (!y. p=Inr y --> z=g y)) |
|
1239 % |
|
1240 \tdx{Inl_not_Inr} Inl a ~= Inr b |
1241 \tdx{Inl_not_Inr} Inl a ~= Inr b |
1241 |
1242 |
1242 \tdx{inj_Inl} inj Inl |
1243 \tdx{inj_Inl} inj Inl |
1243 \tdx{inj_Inr} inj Inr |
1244 \tdx{inj_Inr} inj Inr |
1244 |
1245 |
1246 |
1247 |
1247 \tdx{sum_case_Inl} sum_case f g (Inl x) = f x |
1248 \tdx{sum_case_Inl} sum_case f g (Inl x) = f x |
1248 \tdx{sum_case_Inr} sum_case f g (Inr x) = g x |
1249 \tdx{sum_case_Inr} sum_case f g (Inr x) = g x |
1249 |
1250 |
1250 \tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s |
1251 \tdx{surjective_sum} sum_case (\%x. f(Inl x)) (\%y. f(Inr y)) s = f s |
1251 \tdx{split_sum_case} R(sum_case f g s) = ((! x. s = Inl(x) --> R(f(x))) & |
1252 \tdx{sum.split_case} R(sum_case f g s) = ((! x. s = Inl(x) --> R(f(x))) & |
1252 (! y. s = Inr(y) --> R(g(y)))) |
1253 (! y. s = Inr(y) --> R(g(y)))) |
1253 \end{ttbox} |
1254 \end{ttbox} |
1254 \caption{Type $\alpha+\beta$}\label{hol-sum} |
1255 \caption{Type $\alpha+\beta$}\label{hol-sum} |
1255 \end{figure} |
1256 \end{figure} |
1256 |
1257 |
1348 case \(e\) of 0 => \(a\) | Suc \(m\) => \(b\) |
1349 case \(e\) of 0 => \(a\) | Suc \(m\) => \(b\) |
1349 \end{ttbox} |
1350 \end{ttbox} |
1350 Note that Isabelle insists on precisely this format; you may not even change |
1351 Note that Isabelle insists on precisely this format; you may not even change |
1351 the order of the two cases. |
1352 the order of the two cases. |
1352 Both \texttt{primrec} and \texttt{case} are realized by a recursion operator |
1353 Both \texttt{primrec} and \texttt{case} are realized by a recursion operator |
1353 \cdx{nat_rec}, the details of which can be found in theory \texttt{NatDef}. |
1354 \cdx{nat_rec}, which is available because \textit{nat} is represented as |
|
1355 a datatype (see \S\ref{subsec:datatype:rep_datatype}). |
1354 |
1356 |
1355 %The predecessor relation, \cdx{pred_nat}, is shown to be well-founded. |
1357 %The predecessor relation, \cdx{pred_nat}, is shown to be well-founded. |
1356 %Recursion along this relation resembles primitive recursion, but is |
1358 %Recursion along this relation resembles primitive recursion, but is |
1357 %stronger because we are in higher-order logic; using primitive recursion to |
1359 %stronger because we are in higher-order logic; using primitive recursion to |
1358 %define a higher-order function, we can easily Ackermann's function, which |
1360 %define a higher-order function, we can easily Ackermann's function, which |
2223 distinct}, \texttt{inject} and \texttt{cases} are combined in \texttt{simps}. |
2225 distinct}, \texttt{inject} and \texttt{cases} are combined in \texttt{simps}. |
2224 In case of mutually recursive datatypes, \texttt{recs}, \texttt{size}, \texttt{induct} |
2226 In case of mutually recursive datatypes, \texttt{recs}, \texttt{size}, \texttt{induct} |
2225 and \texttt{simps} are contained in a separate structure named $t@1_\ldots_t@n$. |
2227 and \texttt{simps} are contained in a separate structure named $t@1_\ldots_t@n$. |
2226 |
2228 |
2227 |
2229 |
2228 \subsection{Representing existing types as datatypes} |
2230 \subsection{Representing existing types as datatypes}\label{subsec:datatype:rep_datatype} |
2229 |
2231 |
2230 For foundational reasons, some basic types such as \texttt{nat}, \texttt{*}, {\tt |
2232 For foundational reasons, some basic types such as \texttt{nat}, \texttt{*}, {\tt |
2231 +}, \texttt{bool} and \texttt{unit} are not defined in a \texttt{datatype} section, |
2233 +}, \texttt{bool} and \texttt{unit} are not defined in a \texttt{datatype} section, |
2232 but by more primitive means using \texttt{typedef}. To be able to use the |
2234 but by more primitive means using \texttt{typedef}. To be able to use the |
2233 tactics \texttt{induct_tac} and \texttt{exhaust_tac} and to define functions by |
2235 tactics \texttt{induct_tac} and \texttt{exhaust_tac} and to define functions by |