author | ballarin |
Mon, 25 Apr 2005 17:58:41 +0200 | |
changeset 15837 | 7a567dcd4cda |
parent 15763 | b901a127ac73 |
child 16102 | c5f6726d9bb1 |
permissions | -rw-r--r-- |
15596 | 1 |
(* Title: FOL/ex/LocaleTest.thy |
2 |
ID: $Id$ |
|
3 |
Author: Clemens Ballarin |
|
4 |
Copyright (c) 2005 by Clemens Ballarin |
|
5 |
||
6 |
Collection of regression tests for locales. |
|
7 |
*) |
|
8 |
||
9 |
header {* Test of Locale instantiation *} |
|
10 |
||
11 |
theory LocaleTest = FOL: |
|
12 |
||
15696 | 13 |
ML {* set quick_and_dirty *} (* allow for thm command in batch mode *) |
14 |
ML {* set Toplevel.debug *} |
|
15 |
ML {* set show_hyps *} |
|
16 |
ML {* set show_sorts *} |
|
17 |
||
18 |
section {* interpretation *} |
|
19 |
||
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
20 |
(* interpretation input syntax *) |
15596 | 21 |
|
22 |
locale L |
|
23 |
locale M = fixes a and b and c |
|
24 |
||
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
25 |
interpretation test [simp]: L + M a b c [x y z] . |
15596 | 26 |
|
15837 | 27 |
print_interps L (* output: test *) |
28 |
print_interps M (* output: test *) |
|
15596 | 29 |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
30 |
interpretation test [simp]: L print_interps M . |
15596 | 31 |
|
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
32 |
interpretation L . |
15596 | 33 |
|
34 |
(* processing of locale expression *) |
|
35 |
||
36 |
locale A = fixes a assumes asm_A: "a = a" |
|
37 |
||
38 |
locale (open) B = fixes b assumes asm_B [simp]: "b = b" |
|
39 |
||
40 |
locale C = A + B + assumes asm_C: "c = c" |
|
41 |
(* TODO: independent type var in c, prohibit locale declaration *) |
|
42 |
||
43 |
locale D = A + B + fixes d defines def_D: "d == (a = b)" |
|
44 |
||
15696 | 45 |
theorem (in A) |
46 |
includes D |
|
47 |
shows True .. |
|
48 |
||
49 |
theorem (in D) True .. |
|
15596 | 50 |
|
51 |
typedecl i |
|
52 |
arities i :: "term" |
|
53 |
||
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
54 |
|
15837 | 55 |
interpretation p1: C ["X::i" "Y::i"] by (auto intro: A.intro C_axioms.intro) |
15596 | 56 |
|
15837 | 57 |
print_interps A (* output: p1 *) |
15596 | 58 |
|
15696 | 59 |
(* possible accesses *) |
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
60 |
thm p1.a.asm_A thm LocaleTest.p1.a.asm_A |
15763
b901a127ac73
Interpretation supports statically scoped attributes; documentation.
ballarin
parents:
15696
diff
changeset
|
61 |
thm p1.asm_A thm LocaleTest.p1.asm_A |
15696 | 62 |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
63 |
|
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
64 |
(* without prefix *) |
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
65 |
|
15837 | 66 |
interpretation C ["W::i" "Z::i"] . (* subsumed by p1: C *) |
67 |
interpretation C ["W::'a" "Z::i"] by (auto intro: A.intro C_axioms.intro) |
|
68 |
(* subsumes p1: A and p1: C *) |
|
15696 | 69 |
|
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
70 |
|
15837 | 71 |
print_interps A (* output: <no prefix>, p1 *) |
15596 | 72 |
|
15837 | 73 |
(* possible accesses *) |
74 |
thm asm_C thm a_b.asm_C thm LocaleTest.a_b.asm_C thm LocaleTest.a_b.asm_C |
|
15696 | 75 |
|
15596 | 76 |
|
15837 | 77 |
interpretation p2: D [X "Y::i" "Y = X"] by (simp add: eq_commute) |
78 |
||
79 |
print_interps A (* output: <no prefix>, p1 *) |
|
80 |
print_interps D (* output: p2 *) |
|
81 |
||
82 |
||
83 |
interpretation p3: D [X "Y::i"] . |
|
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
84 |
|
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
85 |
(* duplicate: not registered *) |
15696 | 86 |
|
87 |
(* thm p3.a.asm_A *) |
|
88 |
||
15596 | 89 |
|
15837 | 90 |
print_interps A (* output: <no prefix>, p1 *) |
91 |
print_interps B (* output: p1 *) |
|
92 |
print_interps C (* output: <no name>, p1 *) |
|
93 |
print_interps D (* output: p2, p3 *) |
|
15596 | 94 |
|
15837 | 95 |
(* schematic vars in instantiation not permitted *) |
96 |
(* |
|
15696 | 97 |
interpretation p4: A ["?x::?'a1"] apply (rule A.intro) apply rule done |
15598
4ab52355bb53
Registrations of global locale interpretations: improved, better naming.
ballarin
parents:
15596
diff
changeset
|
98 |
print_interps A |
15696 | 99 |
*) |
15596 | 100 |
|
15837 | 101 |
interpretation p10: D + D a' b' d' [X "Y::i" _ U "V::i" _] . |
15696 | 102 |
|
103 |
corollary (in D) th_x: True .. |
|
104 |
||
105 |
(* possible accesses: for each registration *) |
|
106 |
||
15837 | 107 |
thm p2.th_x thm p3.th_x |
15696 | 108 |
|
109 |
lemma (in D) th_y: "d == (a = b)" . |
|
110 |
||
15837 | 111 |
thm p2.th_y thm p3.th_y |
15696 | 112 |
|
113 |
lemmas (in D) th_z = th_y |
|
114 |
||
115 |
thm p2.th_z |
|
116 |
||
117 |
section {* Interpretation in proof contexts *} |
|
15596 | 118 |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
119 |
theorem True |
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
120 |
proof - |
15837 | 121 |
fix alpha::i and beta::'a and gamma::i |
122 |
(* FIXME: omitting type of beta leads to error later at interpret p6 *) |
|
15696 | 123 |
have alpha_A: "A(alpha)" by (auto intro: A.intro) |
15837 | 124 |
interpret p5: A [alpha] . (* subsumed *) |
125 |
print_interps A (* output: <no prefix>, p1 *) |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
126 |
interpret p6: C [alpha beta] by (auto intro: C_axioms.intro) |
15837 | 127 |
print_interps A (* output: <no prefix>, p1 *) |
128 |
print_interps C (* output: <no prefix>, p1, p6 *) |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
129 |
qed rule |
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
130 |
|
15696 | 131 |
theorem (in A) True |
132 |
proof - |
|
133 |
print_interps A |
|
134 |
fix beta and gamma |
|
135 |
interpret p9: D [a beta _] |
|
136 |
(* no proof obligation for A !!! *) |
|
137 |
apply - apply (rule refl) apply assumption done |
|
138 |
qed rule |
|
15624
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
139 |
|
484178635bd8
Further work on interpretation commands. New command `interpret' for
ballarin
parents:
15598
diff
changeset
|
140 |
|
15696 | 141 |
(* Definition involving free variable *) |
142 |
||
143 |
ML {* reset show_sorts *} |
|
144 |
||
145 |
locale E = fixes e defines e_def: "e(x) == x & x" |
|
146 |
notes e_def2 = e_def |
|
147 |
||
148 |
lemma (in E) True thm e_def by fast |
|
149 |
||
150 |
interpretation p7: E ["(%x. x)"] by simp |
|
151 |
||
152 |
(* TODO: goal mustn't be beta-reduced here, is doesn't match meta-hyp *) |
|
153 |
||
154 |
thm p7.e_def2 |
|
155 |
||
156 |
locale E' = fixes e defines e_def: "e == (%x. x & x)" |
|
157 |
notes e_def2 = e_def |
|
158 |
||
159 |
interpretation p7': E' ["(%x. x)"] by simp |
|
160 |
||
161 |
thm p7'.e_def2 |
|
162 |
||
163 |
(* Definition involving free variable in assm *) |
|
164 |
||
165 |
locale (open) F = fixes f assumes asm_F: "f --> x" |
|
166 |
notes asm_F2 = asm_F |
|
167 |
||
168 |
interpretation p8: F ["False"] by fast |
|
169 |
||
170 |
thm p8.asm_F2 |
|
171 |
||
172 |
subsection {* Locale without assumptions *} |
|
173 |
||
174 |
locale L1 = notes rev_conjI [intro] = conjI [THEN iffD1 [OF conj_commute]] |
|
175 |
||
176 |
lemma "[| P; Q |] ==> P & Q" |
|
177 |
proof - |
|
178 |
interpret my: L1 . txt {* No chained fact required. *} |
|
179 |
assume Q and P txt {* order reversed *} |
|
180 |
then show "P & Q" .. txt {* Applies @{thm my.rev_conjI}. *} |
|
181 |
qed |
|
182 |
||
183 |
locale L11 = notes rev_conjI = conjI [THEN iffD1 [OF conj_commute]] |
|
184 |
||
185 |
lemma "[| P; Q |] ==> P & Q" |
|
186 |
proof - |
|
187 |
interpret [intro]: L11 . txt {* Attribute supplied at instantiation. *} |
|
188 |
assume Q and P |
|
189 |
then show "P & Q" .. |
|
190 |
qed |
|
191 |
||
192 |
subsection {* Simple locale with assumptions *} |
|
193 |
||
194 |
consts bin :: "[i, i] => i" (infixl "#" 60) |
|
195 |
||
196 |
axioms i_assoc: "(x # y) # z = x # (y # z)" |
|
197 |
i_comm: "x # y = y # x" |
|
198 |
||
199 |
locale L2 = |
|
200 |
fixes OP (infixl "+" 60) |
|
201 |
assumes assoc: "(x + y) + z = x + (y + z)" |
|
202 |
and comm: "x + y = y + x" |
|
203 |
||
204 |
lemma (in L2) lcomm: "x + (y + z) = y + (x + z)" |
|
205 |
proof - |
|
206 |
have "x + (y + z) = (x + y) + z" by (simp add: assoc) |
|
207 |
also have "... = (y + x) + z" by (simp add: comm) |
|
208 |
also have "... = y + (x + z)" by (simp add: assoc) |
|
209 |
finally show ?thesis . |
|
210 |
qed |
|
211 |
||
212 |
lemmas (in L2) AC = comm assoc lcomm |
|
213 |
||
214 |
lemma "(x::i) # y # z # w = y # x # w # z" |
|
215 |
proof - |
|
216 |
interpret my: L2 ["op #"] by (rule L2.intro [of "op #", OF i_assoc i_comm]) |
|
217 |
txt {* Chained fact required to discharge assumptions of @{text L2} |
|
218 |
and instantiate parameters. *} |
|
219 |
show ?thesis by (simp only: my.OP.AC) (* or simply AC *) |
|
220 |
qed |
|
221 |
||
222 |
subsection {* Nested locale with assumptions *} |
|
223 |
||
224 |
locale L3 = |
|
225 |
fixes OP (infixl "+" 60) |
|
226 |
assumes assoc: "(x + y) + z = x + (y + z)" |
|
227 |
||
228 |
locale L4 = L3 + |
|
229 |
assumes comm: "x + y = y + x" |
|
230 |
||
231 |
lemma (in L4) lcomm: "x + (y + z) = y + (x + z)" |
|
232 |
proof - |
|
233 |
have "x + (y + z) = (x + y) + z" by (simp add: assoc) |
|
234 |
also have "... = (y + x) + z" by (simp add: comm) |
|
235 |
also have "... = y + (x + z)" by (simp add: assoc) |
|
236 |
finally show ?thesis . |
|
237 |
qed |
|
238 |
||
239 |
lemmas (in L4) AC = comm assoc lcomm |
|
240 |
||
241 |
lemma "(x::i) # y # z # w = y # x # w # z" |
|
242 |
proof - |
|
243 |
interpret my: L4 ["op #"] |
|
244 |
by (auto intro: L3.intro L4_axioms.intro i_assoc i_comm) |
|
245 |
show ?thesis by (simp only: my.OP.AC) (* or simply AC *) |
|
246 |
qed |
|
247 |
||
248 |
subsection {* Locale with definition *} |
|
249 |
||
250 |
text {* This example is admittedly not very creative :-) *} |
|
251 |
||
252 |
locale L5 = L4 + var A + |
|
253 |
defines A_def: "A == True" |
|
254 |
||
255 |
lemma (in L5) lem: A |
|
256 |
by (unfold A_def) rule |
|
257 |
||
258 |
lemma "L5(op #) ==> True" |
|
259 |
proof - |
|
260 |
assume "L5(op #)" |
|
261 |
then interpret L5 ["op #"] by (auto intro: L5.axioms) |
|
262 |
show ?thesis by (rule lem) (* lem instantiated to True *) |
|
263 |
qed |
|
264 |
||
265 |
subsection {* Instantiation in a context with target *} |
|
266 |
||
267 |
lemma (in L4) |
|
268 |
fixes A (infixl "$" 60) |
|
269 |
assumes A: "L4(A)" |
|
270 |
shows "(x::i) $ y $ z $ w = y $ x $ w $ z" |
|
271 |
proof - |
|
272 |
from A interpret A: L4 ["A"] by (auto intro: L4.axioms) |
|
273 |
show ?thesis by (simp only: A.OP.AC) |
|
274 |
qed |
|
275 |
||
15596 | 276 |
end |