8906
|
1 |
|
|
2 |
header {* Defining natural numbers in FOL \label{sec:ex-natclass} *};
|
|
3 |
|
8890
|
4 |
theory NatClass = FOL:;
|
|
5 |
|
8906
|
6 |
text {*
|
|
7 |
\medskip\noindent Axiomatic type classes abstract over exactly one
|
|
8 |
type argument. Thus, any \emph{axiomatic} theory extension where each
|
|
9 |
axiom refers to at most one type variable, may be trivially turned
|
|
10 |
into a \emph{definitional} one.
|
|
11 |
|
|
12 |
We illustrate this with the natural numbers in
|
|
13 |
Isabelle/FOL.\footnote{See also
|
|
14 |
\url{http://isabelle.in.tum.de/library/FOL/ex/NatClass.html}}
|
|
15 |
*};
|
|
16 |
|
8890
|
17 |
consts
|
|
18 |
zero :: 'a ("0")
|
|
19 |
Suc :: "'a \\<Rightarrow> 'a"
|
|
20 |
rec :: "'a \\<Rightarrow> 'a \\<Rightarrow> ('a \\<Rightarrow> 'a \\<Rightarrow> 'a) \\<Rightarrow> 'a";
|
|
21 |
|
|
22 |
axclass
|
|
23 |
nat < "term"
|
|
24 |
induct: "P(0) \\<Longrightarrow> (\\<And>x. P(x) \\<Longrightarrow> P(Suc(x))) \\<Longrightarrow> P(n)"
|
|
25 |
Suc_inject: "Suc(m) = Suc(n) \\<Longrightarrow> m = n"
|
|
26 |
Suc_neq_0: "Suc(m) = 0 \\<Longrightarrow> R"
|
|
27 |
rec_0: "rec(0, a, f) = a"
|
|
28 |
rec_Suc: "rec(Suc(m), a, f) = f(m, rec(m, a, f))";
|
|
29 |
|
|
30 |
constdefs
|
|
31 |
add :: "'a::nat \\<Rightarrow> 'a \\<Rightarrow> 'a" (infixl "+" 60)
|
|
32 |
"m + n \\<equiv> rec(m, n, \\<lambda>x y. Suc(y))";
|
|
33 |
|
8906
|
34 |
text {*
|
|
35 |
This is an abstract version of the plain $Nat$ theory in
|
|
36 |
FOL.\footnote{See
|
|
37 |
\url{http://isabelle.in.tum.de/library/FOL/ex/Nat.html}}
|
|
38 |
|
|
39 |
Basically, we have just replaced all occurrences of type $nat$ by
|
|
40 |
$\alpha$ and used the natural number axioms to define class $nat$.
|
|
41 |
There is only a minor snag, that the original recursion operator
|
|
42 |
$rec$ had to be made monomorphic, in a sense. Thus class $nat$
|
|
43 |
contains exactly those types $\tau$ that are isomorphic to ``the''
|
|
44 |
natural numbers (with signature $0$, $Suc$, $rec$).
|
|
45 |
|
|
46 |
\medskip What we have done here can be also viewed as \emph{type
|
|
47 |
specification}. Of course, it still remains open if there is some
|
|
48 |
type at all that meets the class axioms. Now a very nice property of
|
|
49 |
axiomatic type classes is, that abstract reasoning is always possible
|
|
50 |
--- independent of satisfiability. The meta-logic won't break, even
|
|
51 |
if some classes (or general sorts) turns out to be empty
|
|
52 |
(``inconsistent'') later.
|
|
53 |
|
|
54 |
Theorems of the abstract natural numbers may be derived in the same
|
|
55 |
way as for the concrete version. The original proof scripts may be
|
|
56 |
used with some trivial changes only (mostly adding some type
|
|
57 |
constraints).
|
|
58 |
*};
|
|
59 |
|
8890
|
60 |
end; |