17128
|
1 |
%
|
|
2 |
\begin{isabellebody}%
|
|
3 |
\def\isabellecontext{NatClass}%
|
|
4 |
%
|
|
5 |
\isamarkupheader{Defining natural numbers in FOL \label{sec:ex-natclass}%
|
|
6 |
}
|
17175
|
7 |
\isamarkuptrue%
|
17128
|
8 |
%
|
|
9 |
\isadelimtheory
|
|
10 |
%
|
|
11 |
\endisadelimtheory
|
|
12 |
%
|
|
13 |
\isatagtheory
|
17175
|
14 |
\isacommand{theory}\isamarkupfalse%
|
|
15 |
\ NatClass\ \isakeyword{imports}\ FOL\ \isakeyword{begin}%
|
17128
|
16 |
\endisatagtheory
|
|
17 |
{\isafoldtheory}%
|
|
18 |
%
|
|
19 |
\isadelimtheory
|
|
20 |
%
|
|
21 |
\endisadelimtheory
|
|
22 |
%
|
|
23 |
\begin{isamarkuptext}%
|
|
24 |
\medskip\noindent Axiomatic type classes abstract over exactly one
|
|
25 |
type argument. Thus, any \emph{axiomatic} theory extension where each
|
|
26 |
axiom refers to at most one type variable, may be trivially turned
|
|
27 |
into a \emph{definitional} one.
|
|
28 |
|
|
29 |
We illustrate this with the natural numbers in
|
|
30 |
Isabelle/FOL.\footnote{See also
|
|
31 |
\url{http://isabelle.in.tum.de/library/FOL/ex/NatClass.html}}%
|
|
32 |
\end{isamarkuptext}%
|
17175
|
33 |
\isamarkuptrue%
|
|
34 |
\isacommand{consts}\isamarkupfalse%
|
|
35 |
\isanewline
|
|
36 |
\ \ zero\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ \ \ \ {\isacharparenleft}{\isachardoublequoteopen}{\isasymzero}{\isachardoublequoteclose}{\isacharparenright}\isanewline
|
|
37 |
\ \ Suc\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\isanewline
|
|
38 |
\ \ rec\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\isanewline
|
17128
|
39 |
\isanewline
|
17175
|
40 |
\isacommand{axclass}\isamarkupfalse%
|
|
41 |
\ nat\ {\isasymsubseteq}\ {\isachardoublequoteopen}term{\isachardoublequoteclose}\isanewline
|
|
42 |
\ \ induct{\isacharcolon}\ {\isachardoublequoteopen}P{\isacharparenleft}{\isasymzero}{\isacharparenright}\ {\isasymLongrightarrow}\ {\isacharparenleft}{\isasymAnd}x{\isachardot}\ P{\isacharparenleft}x{\isacharparenright}\ {\isasymLongrightarrow}\ P{\isacharparenleft}Suc{\isacharparenleft}x{\isacharparenright}{\isacharparenright}{\isacharparenright}\ {\isasymLongrightarrow}\ P{\isacharparenleft}n{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
|
43 |
\ \ Suc{\isacharunderscore}inject{\isacharcolon}\ {\isachardoublequoteopen}Suc{\isacharparenleft}m{\isacharparenright}\ {\isacharequal}\ Suc{\isacharparenleft}n{\isacharparenright}\ {\isasymLongrightarrow}\ m\ {\isacharequal}\ n{\isachardoublequoteclose}\isanewline
|
|
44 |
\ \ Suc{\isacharunderscore}neq{\isacharunderscore}{\isadigit{0}}{\isacharcolon}\ {\isachardoublequoteopen}Suc{\isacharparenleft}m{\isacharparenright}\ {\isacharequal}\ {\isasymzero}\ {\isasymLongrightarrow}\ R{\isachardoublequoteclose}\isanewline
|
|
45 |
\ \ rec{\isacharunderscore}{\isadigit{0}}{\isacharcolon}\ {\isachardoublequoteopen}rec{\isacharparenleft}{\isasymzero}{\isacharcomma}\ a{\isacharcomma}\ f{\isacharparenright}\ {\isacharequal}\ a{\isachardoublequoteclose}\isanewline
|
|
46 |
\ \ rec{\isacharunderscore}Suc{\isacharcolon}\ {\isachardoublequoteopen}rec{\isacharparenleft}Suc{\isacharparenleft}m{\isacharparenright}{\isacharcomma}\ a{\isacharcomma}\ f{\isacharparenright}\ {\isacharequal}\ f{\isacharparenleft}m{\isacharcomma}\ rec{\isacharparenleft}m{\isacharcomma}\ a{\isacharcomma}\ f{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}\isanewline
|
17128
|
47 |
\isanewline
|
17175
|
48 |
\isacommand{constdefs}\isamarkupfalse%
|
|
49 |
\isanewline
|
|
50 |
\ \ add\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a{\isacharcolon}{\isacharcolon}nat\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequoteopen}{\isacharplus}{\isachardoublequoteclose}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
|
|
51 |
\ \ {\isachardoublequoteopen}m\ {\isacharplus}\ n\ {\isasymequiv}\ rec{\isacharparenleft}m{\isacharcomma}\ n{\isacharcomma}\ {\isasymlambda}x\ y{\isachardot}\ Suc{\isacharparenleft}y{\isacharparenright}{\isacharparenright}{\isachardoublequoteclose}%
|
17128
|
52 |
\begin{isamarkuptext}%
|
|
53 |
This is an abstract version of the plain \isa{Nat} theory in
|
|
54 |
FOL.\footnote{See
|
|
55 |
\url{http://isabelle.in.tum.de/library/FOL/ex/Nat.html}} Basically,
|
|
56 |
we have just replaced all occurrences of type \isa{nat} by \isa{{\isacharprime}a} and used the natural number axioms to define class \isa{nat}.
|
|
57 |
There is only a minor snag, that the original recursion operator
|
|
58 |
\isa{rec} had to be made monomorphic.
|
|
59 |
|
|
60 |
Thus class \isa{nat} contains exactly those types \isa{{\isasymtau}} that
|
|
61 |
are isomorphic to ``the'' natural numbers (with signature \isa{{\isasymzero}}, \isa{Suc}, \isa{rec}).
|
|
62 |
|
|
63 |
\medskip What we have done here can be also viewed as \emph{type
|
|
64 |
specification}. Of course, it still remains open if there is some
|
|
65 |
type at all that meets the class axioms. Now a very nice property of
|
|
66 |
axiomatic type classes is that abstract reasoning is always possible
|
|
67 |
--- independent of satisfiability. The meta-logic won't break, even
|
|
68 |
if some classes (or general sorts) turns out to be empty later ---
|
|
69 |
``inconsistent'' class definitions may be useless, but do not cause
|
|
70 |
any harm.
|
|
71 |
|
|
72 |
Theorems of the abstract natural numbers may be derived in the same
|
|
73 |
way as for the concrete version. The original proof scripts may be
|
|
74 |
re-used with some trivial changes only (mostly adding some type
|
|
75 |
constraints).%
|
|
76 |
\end{isamarkuptext}%
|
17175
|
77 |
\isamarkuptrue%
|
17128
|
78 |
%
|
25988
|
79 |
\isadelimproof
|
|
80 |
%
|
|
81 |
\endisadelimproof
|
|
82 |
%
|
|
83 |
\isatagproof
|
|
84 |
%
|
|
85 |
\endisatagproof
|
|
86 |
{\isafoldproof}%
|
|
87 |
%
|
|
88 |
\isadelimproof
|
|
89 |
%
|
|
90 |
\endisadelimproof
|
|
91 |
%
|
|
92 |
\isadelimproof
|
|
93 |
%
|
|
94 |
\endisadelimproof
|
|
95 |
%
|
|
96 |
\isatagproof
|
|
97 |
%
|
|
98 |
\endisatagproof
|
|
99 |
{\isafoldproof}%
|
|
100 |
%
|
|
101 |
\isadelimproof
|
|
102 |
%
|
|
103 |
\endisadelimproof
|
|
104 |
%
|
|
105 |
\isadelimproof
|
|
106 |
%
|
|
107 |
\endisadelimproof
|
|
108 |
%
|
|
109 |
\isatagproof
|
|
110 |
%
|
|
111 |
\endisatagproof
|
|
112 |
{\isafoldproof}%
|
|
113 |
%
|
|
114 |
\isadelimproof
|
|
115 |
%
|
|
116 |
\endisadelimproof
|
|
117 |
%
|
|
118 |
\isadelimproof
|
|
119 |
%
|
|
120 |
\endisadelimproof
|
|
121 |
%
|
|
122 |
\isatagproof
|
|
123 |
%
|
|
124 |
\endisatagproof
|
|
125 |
{\isafoldproof}%
|
|
126 |
%
|
|
127 |
\isadelimproof
|
|
128 |
%
|
|
129 |
\endisadelimproof
|
|
130 |
%
|
|
131 |
\isadelimproof
|
|
132 |
%
|
|
133 |
\endisadelimproof
|
|
134 |
%
|
|
135 |
\isatagproof
|
|
136 |
%
|
|
137 |
\endisatagproof
|
|
138 |
{\isafoldproof}%
|
|
139 |
%
|
|
140 |
\isadelimproof
|
|
141 |
%
|
|
142 |
\endisadelimproof
|
|
143 |
%
|
|
144 |
\isadelimproof
|
|
145 |
%
|
|
146 |
\endisadelimproof
|
|
147 |
%
|
|
148 |
\isatagproof
|
|
149 |
%
|
|
150 |
\endisatagproof
|
|
151 |
{\isafoldproof}%
|
|
152 |
%
|
|
153 |
\isadelimproof
|
|
154 |
%
|
|
155 |
\endisadelimproof
|
|
156 |
%
|
|
157 |
\isadelimproof
|
|
158 |
%
|
|
159 |
\endisadelimproof
|
|
160 |
%
|
|
161 |
\isatagproof
|
|
162 |
%
|
|
163 |
\endisatagproof
|
|
164 |
{\isafoldproof}%
|
|
165 |
%
|
|
166 |
\isadelimproof
|
|
167 |
%
|
|
168 |
\endisadelimproof
|
|
169 |
%
|
|
170 |
\isadelimproof
|
|
171 |
%
|
|
172 |
\endisadelimproof
|
|
173 |
%
|
|
174 |
\isatagproof
|
|
175 |
%
|
|
176 |
\endisatagproof
|
|
177 |
{\isafoldproof}%
|
|
178 |
%
|
|
179 |
\isadelimproof
|
|
180 |
\isanewline
|
|
181 |
%
|
|
182 |
\endisadelimproof
|
|
183 |
%
|
17128
|
184 |
\isadelimtheory
|
|
185 |
%
|
|
186 |
\endisadelimtheory
|
|
187 |
%
|
|
188 |
\isatagtheory
|
17175
|
189 |
\isacommand{end}\isamarkupfalse%
|
|
190 |
%
|
17128
|
191 |
\endisatagtheory
|
|
192 |
{\isafoldtheory}%
|
|
193 |
%
|
|
194 |
\isadelimtheory
|
|
195 |
%
|
|
196 |
\endisadelimtheory
|
|
197 |
\end{isabellebody}%
|
|
198 |
%%% Local Variables:
|
|
199 |
%%% mode: latex
|
|
200 |
%%% TeX-master: "root"
|
|
201 |
%%% End:
|