author | haftmann |
Sun, 27 Jul 2025 17:52:06 +0200 | |
changeset 82909 | e4fae2227594 |
parent 80866 | 8c67b14fdd48 |
permissions | -rw-r--r-- |
37134 | 1 |
(* Title: FOL/ex/Locale_Test/Locale_Test1.thy |
2 |
Author: Clemens Ballarin, TU Muenchen |
|
3 |
||
4 |
Test environment for the locale implementation. |
|
5 |
*) |
|
6 |
||
7 |
theory Locale_Test1 |
|
8 |
imports FOL |
|
9 |
begin |
|
10 |
||
55380
4de48353034e
prefer vacuous definitional type classes over axiomatic ones;
wenzelm
parents:
53367
diff
changeset
|
11 |
typedecl int |
69590 | 12 |
instance int :: \<open>term\<close> .. |
55380
4de48353034e
prefer vacuous definitional type classes over axiomatic ones;
wenzelm
parents:
53367
diff
changeset
|
13 |
|
69590 | 14 |
consts plus :: \<open>int => int => int\<close> (infixl \<open>+\<close> 60) |
15 |
zero :: \<open>int\<close> (\<open>0\<close>) |
|
16 |
minus :: \<open>int => int\<close> (\<open>- _\<close>) |
|
37134 | 17 |
|
41779 | 18 |
axiomatization where |
69590 | 19 |
int_assoc: \<open>(x + y::int) + z = x + (y + z)\<close> and |
20 |
int_zero: \<open>0 + x = x\<close> and |
|
21 |
int_minus: \<open>(-x) + x = 0\<close> and |
|
22 |
int_minus2: \<open>-(-x) = x\<close> |
|
37134 | 23 |
|
60770 | 24 |
section \<open>Inference of parameter types\<close> |
37134 | 25 |
|
26 |
locale param1 = fixes p |
|
27 |
print_locale! param1 |
|
28 |
||
69590 | 29 |
locale param2 = fixes p :: \<open>'b\<close> |
37134 | 30 |
print_locale! param2 |
31 |
||
32 |
(* |
|
33 |
locale param_top = param2 r for r :: "'b :: {}" |
|
34 |
Fails, cannot generalise parameter. |
|
35 |
*) |
|
36 |
||
69587 | 37 |
locale param3 = fixes p (infix \<open>..\<close> 50) |
37134 | 38 |
print_locale! param3 |
39 |
||
69590 | 40 |
locale param4 = fixes p :: \<open>'a => 'a => 'a\<close> (infix \<open>..\<close> 50) |
37134 | 41 |
print_locale! param4 |
42 |
||
43 |
||
60770 | 44 |
subsection \<open>Incremental type constraints\<close> |
37134 | 45 |
|
46 |
locale constraint1 = |
|
69587 | 47 |
fixes prod (infixl \<open>**\<close> 65) |
69590 | 48 |
assumes l_id: \<open>x ** y = x\<close> |
49 |
assumes assoc: \<open>(x ** y) ** z = x ** (y ** z)\<close> |
|
37134 | 50 |
print_locale! constraint1 |
51 |
||
52 |
locale constraint2 = |
|
53 |
fixes p and q |
|
69590 | 54 |
assumes \<open>p = q\<close> |
37134 | 55 |
print_locale! constraint2 |
56 |
||
57 |
||
60770 | 58 |
section \<open>Inheritance\<close> |
37134 | 59 |
|
60 |
locale semi = |
|
69587 | 61 |
fixes prod (infixl \<open>**\<close> 65) |
69590 | 62 |
assumes assoc: \<open>(x ** y) ** z = x ** (y ** z)\<close> |
37134 | 63 |
print_locale! semi thm semi_def |
64 |
||
65 |
locale lgrp = semi + |
|
66 |
fixes one and inv |
|
69590 | 67 |
assumes lone: \<open>one ** x = x\<close> |
68 |
and linv: \<open>inv(x) ** x = one\<close> |
|
37134 | 69 |
print_locale! lgrp thm lgrp_def lgrp_axioms_def |
70 |
||
69590 | 71 |
locale add_lgrp = semi \<open>(++)\<close> for sum (infixl \<open>++\<close> 60) + |
37134 | 72 |
fixes zero and neg |
69590 | 73 |
assumes lzero: \<open>zero ++ x = x\<close> |
74 |
and lneg: \<open>neg(x) ++ x = zero\<close> |
|
37134 | 75 |
print_locale! add_lgrp thm add_lgrp_def add_lgrp_axioms_def |
76 |
||
69590 | 77 |
locale rev_lgrp = semi \<open>%x y. y ++ x\<close> for sum (infixl \<open>++\<close> 60) |
37134 | 78 |
print_locale! rev_lgrp thm rev_lgrp_def |
79 |
||
69590 | 80 |
locale hom = f: semi \<open>f\<close> + g: semi \<open>g\<close> for f and g |
37134 | 81 |
print_locale! hom thm hom_def |
82 |
||
69590 | 83 |
locale perturbation = semi + d: semi \<open>%x y. delta(x) ** delta(y)\<close> for delta |
37134 | 84 |
print_locale! perturbation thm perturbation_def |
85 |
||
69590 | 86 |
locale pert_hom = d1: perturbation \<open>f\<close> \<open>d1\<close> + d2: perturbation \<open>f\<close> \<open>d2\<close> for f d1 d2 |
37134 | 87 |
print_locale! pert_hom thm pert_hom_def |
88 |
||
62020 | 89 |
text \<open>Alternative expression, obtaining nicer names in \<open>semi f\<close>.\<close> |
69590 | 90 |
locale pert_hom' = semi \<open>f\<close> + d1: perturbation \<open>f\<close> \<open>d1\<close> + d2: perturbation \<open>f\<close> \<open>d2\<close> for f d1 d2 |
37134 | 91 |
print_locale! pert_hom' thm pert_hom'_def |
92 |
||
93 |
||
60770 | 94 |
section \<open>Syntax declarations\<close> |
37134 | 95 |
|
96 |
locale logic = |
|
69587 | 97 |
fixes land (infixl \<open>&&\<close> 55) |
98 |
and lnot (\<open>-- _\<close> [60] 60) |
|
69590 | 99 |
assumes assoc: \<open>(x && y) && z = x && (y && z)\<close> |
100 |
and notnot: \<open>-- (-- x) = x\<close> |
|
37134 | 101 |
begin |
102 |
||
69587 | 103 |
definition lor (infixl \<open>||\<close> 50) where |
69590 | 104 |
\<open>x || y = --(-- x && -- y)\<close> |
37134 | 105 |
|
106 |
end |
|
107 |
print_locale! logic |
|
108 |
||
69590 | 109 |
locale use_decl = l: logic + semi \<open>(||)\<close> |
37134 | 110 |
print_locale! use_decl thm use_decl_def |
111 |
||
112 |
locale extra_type = |
|
69590 | 113 |
fixes a :: \<open>'a\<close> |
114 |
and P :: \<open>'a => 'b => o\<close> |
|
37134 | 115 |
begin |
116 |
||
69590 | 117 |
definition test :: \<open>'a => o\<close> |
118 |
where \<open>test(x) \<longleftrightarrow> (\<forall>b. P(x, b))\<close> |
|
37134 | 119 |
|
120 |
end |
|
121 |
||
69590 | 122 |
term \<open>extra_type.test\<close> thm extra_type.test_def |
37134 | 123 |
|
69590 | 124 |
interpretation var?: extra_type \<open>0\<close> \<open>%x y. x = 0\<close> . |
37134 | 125 |
|
126 |
thm var.test_def |
|
127 |
||
128 |
||
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
129 |
text \<open>Under which circumstances notation remains active.\<close> |
37134 | 130 |
|
60770 | 131 |
ML \<open> |
37134 | 132 |
fun check_syntax ctxt thm expected = |
133 |
let |
|
56036 | 134 |
val obtained = |
80866
8c67b14fdd48
clarified internal tool output: prefer Pretty.pure_string_of over manipulation of print_mode;
wenzelm
parents:
78031
diff
changeset
|
135 |
Pretty.pure_string_of (Thm.pretty_thm (Config.put show_markup false ctxt) thm); |
37134 | 136 |
in |
137 |
if obtained <> expected |
|
138 |
then error ("Theorem syntax '" ^ obtained ^ "' obtained, but '" ^ expected ^ "' expected.") |
|
139 |
else () |
|
140 |
end; |
|
60770 | 141 |
\<close> |
37134 | 142 |
|
41305
42967939ea81
actually enable show_hyps option, unlike local_setup in 6da953d30f48 which merely affects the (temporary) auxiliary context;
wenzelm
parents:
41272
diff
changeset
|
143 |
declare [[show_hyps]] |
41271
6da953d30f48
Enable show_hyps, which appears to be set in batch mode but in an interactive session.
ballarin
parents:
39557
diff
changeset
|
144 |
|
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
145 |
locale "syntax" = |
69590 | 146 |
fixes p1 :: \<open>'a => 'b\<close> |
147 |
and p2 :: \<open>'b => o\<close> |
|
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
148 |
begin |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
149 |
|
69590 | 150 |
definition d1 :: \<open>'a => o\<close> (\<open>D1'(_')\<close>) where \<open>d1(x) \<longleftrightarrow> \<not> p2(p1(x))\<close> |
151 |
definition d2 :: \<open>'b => o\<close> (\<open>D2'(_')\<close>) where \<open>d2(x) \<longleftrightarrow> \<not> p2(x)\<close> |
|
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
152 |
|
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
153 |
thm d1_def d2_def |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
154 |
|
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
155 |
end |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
156 |
|
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
157 |
thm syntax.d1_def syntax.d2_def |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
158 |
|
69590 | 159 |
locale syntax' = "syntax" \<open>p1\<close> \<open>p2\<close> for p1 :: \<open>'a => 'a\<close> and p2 :: \<open>'a => o\<close> |
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
160 |
begin |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
161 |
|
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
162 |
thm d1_def d2_def (* should print as "D1(?x) <-> ..." and "D2(?x) <-> ..." *) |
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
163 |
|
60770 | 164 |
ML \<open> |
69593 | 165 |
check_syntax \<^context> @{thm d1_def} "D1(?x) \<longleftrightarrow> \<not> p2(p1(?x))"; |
166 |
check_syntax \<^context> @{thm d2_def} "D2(?x) \<longleftrightarrow> \<not> p2(?x)"; |
|
60770 | 167 |
\<close> |
37134 | 168 |
|
169 |
end |
|
170 |
||
69590 | 171 |
locale syntax'' = "syntax" \<open>p3\<close> \<open>p2\<close> for p3 :: \<open>'a => 'b\<close> and p2 :: \<open>'b => o\<close> |
37134 | 172 |
begin |
173 |
||
174 |
thm d1_def d2_def |
|
61701
e89cfc004f18
Refine the supression of abbreviations for morphisms that are not identities.
ballarin
parents:
61605
diff
changeset
|
175 |
(* should print as "d1(?x) <-> ..." and "D2(?x) <-> ..." *) |
37134 | 176 |
|
60770 | 177 |
ML \<open> |
69593 | 178 |
check_syntax \<^context> @{thm d1_def} "d1(?x) \<longleftrightarrow> \<not> p2(p3(?x))"; |
179 |
check_syntax \<^context> @{thm d2_def} "D2(?x) \<longleftrightarrow> \<not> p2(?x)"; |
|
60770 | 180 |
\<close> |
37134 | 181 |
|
182 |
end |
|
183 |
||
184 |
||
60770 | 185 |
section \<open>Foundational versions of theorems\<close> |
37134 | 186 |
|
187 |
thm logic.assoc |
|
188 |
thm logic.lor_def |
|
189 |
||
190 |
||
60770 | 191 |
section \<open>Defines\<close> |
37134 | 192 |
|
193 |
locale logic_def = |
|
69587 | 194 |
fixes land (infixl \<open>&&\<close> 55) |
195 |
and lor (infixl \<open>||\<close> 50) |
|
196 |
and lnot (\<open>-- _\<close> [60] 60) |
|
69590 | 197 |
assumes assoc: \<open>(x && y) && z = x && (y && z)\<close> |
198 |
and notnot: \<open>-- (-- x) = x\<close> |
|
199 |
defines \<open>x || y == --(-- x && -- y)\<close> |
|
37134 | 200 |
begin |
201 |
||
202 |
thm lor_def |
|
203 |
||
69590 | 204 |
lemma \<open>x || y = --(-- x && --y)\<close> |
37134 | 205 |
by (unfold lor_def) (rule refl) |
206 |
||
207 |
end |
|
208 |
||
209 |
(* Inheritance of defines *) |
|
210 |
||
211 |
locale logic_def2 = logic_def |
|
212 |
begin |
|
213 |
||
69590 | 214 |
lemma \<open>x || y = --(-- x && --y)\<close> |
37134 | 215 |
by (unfold lor_def) (rule refl) |
216 |
||
217 |
end |
|
218 |
||
219 |
||
60770 | 220 |
section \<open>Notes\<close> |
37134 | 221 |
|
222 |
(* A somewhat arcane homomorphism example *) |
|
223 |
||
224 |
definition semi_hom where |
|
69590 | 225 |
\<open>semi_hom(prod, sum, h) \<longleftrightarrow> (\<forall>x y. h(prod(x, y)) = sum(h(x), h(y)))\<close> |
37134 | 226 |
|
227 |
lemma semi_hom_mult: |
|
69590 | 228 |
\<open>semi_hom(prod, sum, h) \<Longrightarrow> h(prod(x, y)) = sum(h(x), h(y))\<close> |
37134 | 229 |
by (simp add: semi_hom_def) |
230 |
||
69590 | 231 |
locale semi_hom_loc = prod: semi \<open>prod\<close> + sum: semi \<open>sum\<close> |
37134 | 232 |
for prod and sum and h + |
69590 | 233 |
assumes semi_homh: \<open>semi_hom(prod, sum, h)\<close> |
37134 | 234 |
notes semi_hom_mult = semi_hom_mult [OF semi_homh] |
235 |
||
236 |
thm semi_hom_loc.semi_hom_mult |
|
78031 | 237 |
(* unspecified, attribute not applied in background theory !!! *) |
37134 | 238 |
|
69590 | 239 |
lemma (in semi_hom_loc) \<open>h(prod(x, y)) = sum(h(x), h(y))\<close> |
37134 | 240 |
by (rule semi_hom_mult) |
241 |
||
242 |
(* Referring to facts from within a context specification *) |
|
243 |
||
244 |
lemma |
|
69590 | 245 |
assumes x: \<open>P \<longleftrightarrow> P\<close> |
37134 | 246 |
notes y = x |
69590 | 247 |
shows \<open>True\<close> .. |
37134 | 248 |
|
249 |
||
60770 | 250 |
section \<open>Theorem statements\<close> |
37134 | 251 |
|
252 |
lemma (in lgrp) lcancel: |
|
69590 | 253 |
\<open>x ** y = x ** z \<longleftrightarrow> y = z\<close> |
37134 | 254 |
proof |
69590 | 255 |
assume \<open>x ** y = x ** z\<close> |
256 |
then have \<open>inv(x) ** x ** y = inv(x) ** x ** z\<close> by (simp add: assoc) |
|
257 |
then show \<open>y = z\<close> by (simp add: lone linv) |
|
37134 | 258 |
qed simp |
259 |
print_locale! lgrp |
|
260 |
||
261 |
||
262 |
locale rgrp = semi + |
|
263 |
fixes one and inv |
|
69590 | 264 |
assumes rone: \<open>x ** one = x\<close> |
265 |
and rinv: \<open>x ** inv(x) = one\<close> |
|
37134 | 266 |
begin |
267 |
||
268 |
lemma rcancel: |
|
69590 | 269 |
\<open>y ** x = z ** x \<longleftrightarrow> y = z\<close> |
37134 | 270 |
proof |
69590 | 271 |
assume \<open>y ** x = z ** x\<close> |
272 |
then have \<open>y ** (x ** inv(x)) = z ** (x ** inv(x))\<close> |
|
37134 | 273 |
by (simp add: assoc [symmetric]) |
69590 | 274 |
then show \<open>y = z\<close> by (simp add: rone rinv) |
37134 | 275 |
qed simp |
276 |
||
277 |
end |
|
278 |
print_locale! rgrp |
|
279 |
||
280 |
||
60770 | 281 |
subsection \<open>Patterns\<close> |
37134 | 282 |
|
283 |
lemma (in rgrp) |
|
69590 | 284 |
assumes \<open>y ** x = z ** x\<close> (is \<open>?a\<close>) |
285 |
shows \<open>y = z\<close> (is \<open>?t\<close>) |
|
37134 | 286 |
proof - |
60770 | 287 |
txt \<open>Weird proof involving patterns from context element and conclusion.\<close> |
37134 | 288 |
{ |
69590 | 289 |
assume \<open>?a\<close> |
290 |
then have \<open>y ** (x ** inv(x)) = z ** (x ** inv(x))\<close> |
|
37134 | 291 |
by (simp add: assoc [symmetric]) |
69590 | 292 |
then have \<open>?t\<close> by (simp add: rone rinv) |
37134 | 293 |
} |
294 |
note x = this |
|
69590 | 295 |
show \<open>?t\<close> by (rule x [OF \<open>?a\<close>]) |
37134 | 296 |
qed |
297 |
||
298 |
||
60770 | 299 |
section \<open>Interpretation between locales: sublocales\<close> |
37134 | 300 |
|
61565
352c73a689da
Qualifiers in locale expressions default to mandatory regardless of the command.
ballarin
parents:
61489
diff
changeset
|
301 |
sublocale lgrp < right?: rgrp |
37134 | 302 |
print_facts |
303 |
proof unfold_locales |
|
304 |
{ |
|
305 |
fix x |
|
69590 | 306 |
have \<open>inv(x) ** x ** one = inv(x) ** x\<close> by (simp add: linv lone) |
307 |
then show \<open>x ** one = x\<close> by (simp add: assoc lcancel) |
|
37134 | 308 |
} |
309 |
note rone = this |
|
310 |
{ |
|
311 |
fix x |
|
69590 | 312 |
have \<open>inv(x) ** x ** inv(x) = inv(x) ** one\<close> |
37134 | 313 |
by (simp add: linv lone rone) |
69590 | 314 |
then show \<open>x ** inv(x) = one\<close> by (simp add: assoc lcancel) |
37134 | 315 |
} |
316 |
qed |
|
317 |
||
318 |
(* effect on printed locale *) |
|
319 |
||
320 |
print_locale! lgrp |
|
321 |
||
322 |
(* use of derived theorem *) |
|
323 |
||
324 |
lemma (in lgrp) |
|
69590 | 325 |
\<open>y ** x = z ** x \<longleftrightarrow> y = z\<close> |
37134 | 326 |
apply (rule rcancel) |
327 |
done |
|
328 |
||
329 |
(* circular interpretation *) |
|
330 |
||
331 |
sublocale rgrp < left: lgrp |
|
332 |
proof unfold_locales |
|
333 |
{ |
|
334 |
fix x |
|
69590 | 335 |
have \<open>one ** (x ** inv(x)) = x ** inv(x)\<close> by (simp add: rinv rone) |
336 |
then show \<open>one ** x = x\<close> by (simp add: assoc [symmetric] rcancel) |
|
37134 | 337 |
} |
338 |
note lone = this |
|
339 |
{ |
|
340 |
fix x |
|
69590 | 341 |
have \<open>inv(x) ** (x ** inv(x)) = one ** inv(x)\<close> |
37134 | 342 |
by (simp add: rinv lone rone) |
69590 | 343 |
then show \<open>inv(x) ** x = one\<close> by (simp add: assoc [symmetric] rcancel) |
37134 | 344 |
} |
345 |
qed |
|
346 |
||
347 |
(* effect on printed locale *) |
|
348 |
||
349 |
print_locale! rgrp |
|
350 |
print_locale! lgrp |
|
351 |
||
352 |
||
353 |
(* Duality *) |
|
354 |
||
355 |
locale order = |
|
69590 | 356 |
fixes less :: \<open>'a => 'a => o\<close> (infix \<open><<\<close> 50) |
357 |
assumes refl: \<open>x << x\<close> |
|
358 |
and trans: \<open>[| x << y; y << z |] ==> x << z\<close> |
|
37134 | 359 |
|
69590 | 360 |
sublocale order < dual: order \<open>%x y. y << x\<close> |
37134 | 361 |
apply unfold_locales apply (rule refl) apply (blast intro: trans) |
362 |
done |
|
363 |
||
364 |
print_locale! order (* Only two instances of order. *) |
|
365 |
||
366 |
locale order' = |
|
69590 | 367 |
fixes less :: \<open>'a => 'a => o\<close> (infix \<open><<\<close> 50) |
368 |
assumes refl: \<open>x << x\<close> |
|
369 |
and trans: \<open>[| x << y; y << z |] ==> x << z\<close> |
|
37134 | 370 |
|
371 |
locale order_with_def = order' |
|
372 |
begin |
|
373 |
||
69590 | 374 |
definition greater :: \<open>'a => 'a => o\<close> (infix \<open>>>\<close> 50) where |
375 |
\<open>x >> y \<longleftrightarrow> y << x\<close> |
|
37134 | 376 |
|
377 |
end |
|
378 |
||
69590 | 379 |
sublocale order_with_def < dual: order' \<open>(>>)\<close> |
37134 | 380 |
apply unfold_locales |
381 |
unfolding greater_def |
|
382 |
apply (rule refl) apply (blast intro: trans) |
|
383 |
done |
|
384 |
||
385 |
print_locale! order_with_def |
|
386 |
(* Note that decls come after theorems that make use of them. *) |
|
387 |
||
388 |
||
389 |
(* locale with many parameters --- |
|
390 |
interpretations generate alternating group A5 *) |
|
391 |
||
392 |
||
393 |
locale A5 = |
|
394 |
fixes A and B and C and D and E |
|
69590 | 395 |
assumes eq: \<open>A \<longleftrightarrow> B \<longleftrightarrow> C \<longleftrightarrow> D \<longleftrightarrow> E\<close> |
37134 | 396 |
|
69590 | 397 |
sublocale A5 < 1: A5 _ _ \<open>D\<close> \<open>E\<close> \<open>C\<close> |
37134 | 398 |
print_facts |
399 |
using eq apply (blast intro: A5.intro) done |
|
400 |
||
69590 | 401 |
sublocale A5 < 2: A5 \<open>C\<close> _ \<open>E\<close> _ \<open>A\<close> |
37134 | 402 |
print_facts |
403 |
using eq apply (blast intro: A5.intro) done |
|
404 |
||
69590 | 405 |
sublocale A5 < 3: A5 \<open>B\<close> \<open>C\<close> \<open>A\<close> _ _ |
37134 | 406 |
print_facts |
407 |
using eq apply (blast intro: A5.intro) done |
|
408 |
||
409 |
(* Any even permutation of parameters is subsumed by the above. *) |
|
410 |
||
411 |
print_locale! A5 |
|
412 |
||
413 |
||
414 |
(* Free arguments of instance *) |
|
415 |
||
416 |
locale trivial = |
|
69590 | 417 |
fixes P and Q :: \<open>o\<close> |
418 |
assumes Q: \<open>P \<longleftrightarrow> P \<longleftrightarrow> Q\<close> |
|
37134 | 419 |
begin |
420 |
||
69590 | 421 |
lemma Q_triv: \<open>Q\<close> using Q by fast |
37134 | 422 |
|
423 |
end |
|
424 |
||
69590 | 425 |
sublocale trivial < x: trivial \<open>x\<close> _ |
37134 | 426 |
apply unfold_locales using Q by fast |
427 |
||
428 |
print_locale! trivial |
|
429 |
||
69054 | 430 |
context trivial |
431 |
begin |
|
69590 | 432 |
thm x.Q [where ?x = \<open>True\<close>] |
69054 | 433 |
end |
37134 | 434 |
|
69590 | 435 |
sublocale trivial < y: trivial \<open>Q\<close> \<open>Q\<close> |
37134 | 436 |
by unfold_locales |
437 |
(* Succeeds since previous interpretation is more general. *) |
|
438 |
||
439 |
print_locale! trivial (* No instance for y created (subsumed). *) |
|
440 |
||
441 |
||
60770 | 442 |
subsection \<open>Sublocale, then interpretation in theory\<close> |
37134 | 443 |
|
69590 | 444 |
interpretation int?: lgrp \<open>(+)\<close> \<open>0\<close> \<open>minus\<close> |
37134 | 445 |
proof unfold_locales |
446 |
qed (rule int_assoc int_zero int_minus)+ |
|
447 |
||
448 |
thm int.assoc int.semi_axioms |
|
449 |
||
69590 | 450 |
interpretation int2?: semi \<open>(+)\<close> |
37134 | 451 |
by unfold_locales (* subsumed, thm int2.assoc not generated *) |
452 |
||
69593 | 453 |
ML \<open>(Global_Theory.get_thms \<^theory> "int2.assoc"; |
56138 | 454 |
raise Fail "thm int2.assoc was generated") |
60770 | 455 |
handle ERROR _ => ([]:thm list);\<close> |
37134 | 456 |
|
457 |
thm int.lone int.right.rone |
|
458 |
(* the latter comes through the sublocale relation *) |
|
459 |
||
460 |
||
60770 | 461 |
subsection \<open>Interpretation in theory, then sublocale\<close> |
37134 | 462 |
|
69590 | 463 |
interpretation fol: logic \<open>(+)\<close> \<open>minus\<close> |
37134 | 464 |
by unfold_locales (rule int_assoc int_minus2)+ |
465 |
||
466 |
locale logic2 = |
|
69587 | 467 |
fixes land (infixl \<open>&&\<close> 55) |
468 |
and lnot (\<open>-- _\<close> [60] 60) |
|
69590 | 469 |
assumes assoc: \<open>(x && y) && z = x && (y && z)\<close> |
470 |
and notnot: \<open>-- (-- x) = x\<close> |
|
37134 | 471 |
begin |
472 |
||
69587 | 473 |
definition lor (infixl \<open>||\<close> 50) where |
69590 | 474 |
\<open>x || y = --(-- x && -- y)\<close> |
37134 | 475 |
|
476 |
end |
|
477 |
||
478 |
sublocale logic < two: logic2 |
|
479 |
by unfold_locales (rule assoc notnot)+ |
|
480 |
||
481 |
thm fol.two.assoc |
|
482 |
||
483 |
||
60770 | 484 |
subsection \<open>Declarations and sublocale\<close> |
37134 | 485 |
|
486 |
locale logic_a = logic |
|
487 |
locale logic_b = logic |
|
488 |
||
489 |
sublocale logic_a < logic_b |
|
490 |
by unfold_locales |
|
491 |
||
492 |
||
60770 | 493 |
subsection \<open>Interpretation\<close> |
53366 | 494 |
|
60770 | 495 |
subsection \<open>Rewrite morphism\<close> |
37134 | 496 |
|
497 |
locale logic_o = |
|
69587 | 498 |
fixes land (infixl \<open>&&\<close> 55) |
499 |
and lnot (\<open>-- _\<close> [60] 60) |
|
69590 | 500 |
assumes assoc_o: \<open>(x && y) && z \<longleftrightarrow> x && (y && z)\<close> |
501 |
and notnot_o: \<open>-- (-- x) \<longleftrightarrow> x\<close> |
|
37134 | 502 |
begin |
503 |
||
69587 | 504 |
definition lor_o (infixl \<open>||\<close> 50) where |
69590 | 505 |
\<open>x || y \<longleftrightarrow> --(-- x && -- y)\<close> |
37134 | 506 |
|
507 |
end |
|
508 |
||
69590 | 509 |
interpretation x: logic_o \<open>(\<and>)\<close> \<open>Not\<close> |
510 |
rewrites bool_logic_o: \<open>x.lor_o(x, y) \<longleftrightarrow> x \<or> y\<close> |
|
37134 | 511 |
proof - |
69590 | 512 |
show bool_logic_o: \<open>PROP logic_o((\<and>), Not)\<close> by unfold_locales fast+ |
513 |
show \<open>logic_o.lor_o((\<and>), Not, x, y) \<longleftrightarrow> x \<or> y\<close> |
|
37134 | 514 |
by (unfold logic_o.lor_o_def [OF bool_logic_o]) fast |
515 |
qed |
|
516 |
||
517 |
thm x.lor_o_def bool_logic_o |
|
518 |
||
69590 | 519 |
lemma lor_triv: \<open>z \<longleftrightarrow> z\<close> .. |
37134 | 520 |
|
69590 | 521 |
lemma (in logic_o) lor_triv: \<open>x || y \<longleftrightarrow> x || y\<close> by fast |
37134 | 522 |
|
69590 | 523 |
thm lor_triv [where z = \<open>True\<close>] (* Check strict prefix. *) |
37134 | 524 |
x.lor_triv |
525 |
||
526 |
||
67450
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
527 |
subsection \<open>Rewrite morphisms in expressions\<close> |
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
528 |
|
69590 | 529 |
interpretation y: logic_o \<open>(\<or>)\<close> \<open>Not\<close> rewrites bool_logic_o2: \<open>logic_o.lor_o((\<or>), Not, x, y) \<longleftrightarrow> x \<and> y\<close> |
67450
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
530 |
proof - |
69590 | 531 |
show bool_logic_o: \<open>PROP logic_o((\<or>), Not)\<close> by unfold_locales fast+ |
532 |
show \<open>logic_o.lor_o((\<or>), Not, x, y) \<longleftrightarrow> x \<and> y\<close> unfolding logic_o.lor_o_def [OF bool_logic_o] by fast |
|
67450
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
533 |
qed |
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
534 |
|
b0ae74b86ef3
Experimental support for rewrite morphisms in locale instances.
ballarin
parents:
67443
diff
changeset
|
535 |
|
60770 | 536 |
subsection \<open>Inheritance of rewrite morphisms\<close> |
37134 | 537 |
|
538 |
locale reflexive = |
|
69590 | 539 |
fixes le :: \<open>'a => 'a => o\<close> (infix \<open>\<sqsubseteq>\<close> 50) |
540 |
assumes refl: \<open>x \<sqsubseteq> x\<close> |
|
37134 | 541 |
begin |
542 |
||
69590 | 543 |
definition less (infix \<open>\<sqsubset>\<close> 50) where \<open>x \<sqsubset> y \<longleftrightarrow> x \<sqsubseteq> y \<and> x \<noteq> y\<close> |
37134 | 544 |
|
545 |
end |
|
546 |
||
41779 | 547 |
axiomatization |
69590 | 548 |
gle :: \<open>'a => 'a => o\<close> and gless :: \<open>'a => 'a => o\<close> and |
549 |
gle' :: \<open>'a => 'a => o\<close> and gless' :: \<open>'a => 'a => o\<close> |
|
41779 | 550 |
where |
69590 | 551 |
grefl: \<open>gle(x, x)\<close> and gless_def: \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> and |
552 |
grefl': \<open>gle'(x, x)\<close> and gless'_def: \<open>gless'(x, y) \<longleftrightarrow> gle'(x, y) \<and> x \<noteq> y\<close> |
|
37134 | 553 |
|
60770 | 554 |
text \<open>Setup\<close> |
37134 | 555 |
|
556 |
locale mixin = reflexive |
|
557 |
begin |
|
558 |
lemmas less_thm = less_def |
|
559 |
end |
|
560 |
||
69590 | 561 |
interpretation le: mixin \<open>gle\<close> rewrites \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 562 |
proof - |
69590 | 563 |
show \<open>mixin(gle)\<close> by unfold_locales (rule grefl) |
37134 | 564 |
note reflexive = this[unfolded mixin_def] |
69590 | 565 |
show \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 566 |
by (simp add: reflexive.less_def[OF reflexive] gless_def) |
567 |
qed |
|
568 |
||
60770 | 569 |
text \<open>Rewrite morphism propagated along the locale hierarchy\<close> |
37134 | 570 |
|
571 |
locale mixin2 = mixin |
|
572 |
begin |
|
573 |
lemmas less_thm2 = less_def |
|
574 |
end |
|
575 |
||
69590 | 576 |
interpretation le: mixin2 \<open>gle\<close> |
37134 | 577 |
by unfold_locales |
578 |
||
53366 | 579 |
thm le.less_thm2 (* rewrite morphism applied *) |
69590 | 580 |
lemma \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 581 |
by (rule le.less_thm2) |
582 |
||
60770 | 583 |
text \<open>Rewrite morphism does not leak to a side branch.\<close> |
37134 | 584 |
|
585 |
locale mixin3 = reflexive |
|
586 |
begin |
|
587 |
lemmas less_thm3 = less_def |
|
588 |
end |
|
589 |
||
69590 | 590 |
interpretation le: mixin3 \<open>gle\<close> |
37134 | 591 |
by unfold_locales |
592 |
||
53366 | 593 |
thm le.less_thm3 (* rewrite morphism not applied *) |
69590 | 594 |
lemma \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> by (rule le.less_thm3) |
37134 | 595 |
|
60770 | 596 |
text \<open>Rewrite morphism only available in original context\<close> |
37134 | 597 |
|
598 |
locale mixin4_base = reflexive |
|
599 |
||
600 |
locale mixin4_mixin = mixin4_base |
|
601 |
||
69590 | 602 |
interpretation le: mixin4_mixin \<open>gle\<close> |
603 |
rewrites \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
|
37134 | 604 |
proof - |
69590 | 605 |
show \<open>mixin4_mixin(gle)\<close> by unfold_locales (rule grefl) |
37134 | 606 |
note reflexive = this[unfolded mixin4_mixin_def mixin4_base_def mixin_def] |
69590 | 607 |
show \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 608 |
by (simp add: reflexive.less_def[OF reflexive] gless_def) |
609 |
qed |
|
610 |
||
611 |
locale mixin4_copy = mixin4_base |
|
612 |
begin |
|
613 |
lemmas less_thm4 = less_def |
|
614 |
end |
|
615 |
||
69590 | 616 |
locale mixin4_combined = le1?: mixin4_mixin \<open>le'\<close> + le2?: mixin4_copy \<open>le\<close> for le' le |
37134 | 617 |
begin |
618 |
lemmas less_thm4' = less_def |
|
619 |
end |
|
620 |
||
69590 | 621 |
interpretation le4: mixin4_combined \<open>gle'\<close> \<open>gle\<close> |
37134 | 622 |
by unfold_locales (rule grefl') |
623 |
||
53366 | 624 |
thm le4.less_thm4' (* rewrite morphism not applied *) |
69590 | 625 |
lemma \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 626 |
by (rule le4.less_thm4') |
627 |
||
60770 | 628 |
text \<open>Inherited rewrite morphism applied to new theorem\<close> |
37134 | 629 |
|
630 |
locale mixin5_base = reflexive |
|
631 |
||
632 |
locale mixin5_inherited = mixin5_base |
|
633 |
||
69590 | 634 |
interpretation le5: mixin5_base \<open>gle\<close> |
635 |
rewrites \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
|
37134 | 636 |
proof - |
69590 | 637 |
show \<open>mixin5_base(gle)\<close> by unfold_locales |
37134 | 638 |
note reflexive = this[unfolded mixin5_base_def mixin_def] |
69590 | 639 |
show \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 640 |
by (simp add: reflexive.less_def[OF reflexive] gless_def) |
641 |
qed |
|
642 |
||
69590 | 643 |
interpretation le5: mixin5_inherited \<open>gle\<close> |
37134 | 644 |
by unfold_locales |
645 |
||
646 |
lemmas (in mixin5_inherited) less_thm5 = less_def |
|
647 |
||
53366 | 648 |
thm le5.less_thm5 (* rewrite morphism applied *) |
69590 | 649 |
lemma \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 650 |
by (rule le5.less_thm5) |
651 |
||
60770 | 652 |
text \<open>Rewrite morphism pushed down to existing inherited locale\<close> |
37134 | 653 |
|
654 |
locale mixin6_base = reflexive |
|
655 |
||
656 |
locale mixin6_inherited = mixin5_base |
|
657 |
||
69590 | 658 |
interpretation le6: mixin6_base \<open>gle\<close> |
37134 | 659 |
by unfold_locales |
69590 | 660 |
interpretation le6: mixin6_inherited \<open>gle\<close> |
37134 | 661 |
by unfold_locales |
69590 | 662 |
interpretation le6: mixin6_base \<open>gle\<close> |
663 |
rewrites \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
|
37134 | 664 |
proof - |
69590 | 665 |
show \<open>mixin6_base(gle)\<close> by unfold_locales |
37134 | 666 |
note reflexive = this[unfolded mixin6_base_def mixin_def] |
69590 | 667 |
show \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 668 |
by (simp add: reflexive.less_def[OF reflexive] gless_def) |
669 |
qed |
|
670 |
||
671 |
lemmas (in mixin6_inherited) less_thm6 = less_def |
|
672 |
||
673 |
thm le6.less_thm6 (* mixin applied *) |
|
69590 | 674 |
lemma \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 675 |
by (rule le6.less_thm6) |
676 |
||
60770 | 677 |
text \<open>Existing rewrite morphism inherited through sublocale relation\<close> |
37134 | 678 |
|
679 |
locale mixin7_base = reflexive |
|
680 |
||
681 |
locale mixin7_inherited = reflexive |
|
682 |
||
69590 | 683 |
interpretation le7: mixin7_base \<open>gle\<close> |
684 |
rewrites \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
|
37134 | 685 |
proof - |
69590 | 686 |
show \<open>mixin7_base(gle)\<close> by unfold_locales |
37134 | 687 |
note reflexive = this[unfolded mixin7_base_def mixin_def] |
69590 | 688 |
show \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gless(x, y)\<close> |
37134 | 689 |
by (simp add: reflexive.less_def[OF reflexive] gless_def) |
690 |
qed |
|
691 |
||
69590 | 692 |
interpretation le7: mixin7_inherited \<open>gle\<close> |
37134 | 693 |
by unfold_locales |
694 |
||
695 |
lemmas (in mixin7_inherited) less_thm7 = less_def |
|
696 |
||
53366 | 697 |
thm le7.less_thm7 (* before, rewrite morphism not applied *) |
69590 | 698 |
lemma \<open>reflexive.less(gle, x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 699 |
by (rule le7.less_thm7) |
700 |
||
701 |
sublocale mixin7_inherited < mixin7_base |
|
702 |
by unfold_locales |
|
703 |
||
704 |
lemmas (in mixin7_inherited) less_thm7b = less_def |
|
705 |
||
706 |
thm le7.less_thm7b (* after, mixin applied *) |
|
69590 | 707 |
lemma \<open>gless(x, y) \<longleftrightarrow> gle(x, y) \<and> x \<noteq> y\<close> |
37134 | 708 |
by (rule le7.less_thm7b) |
709 |
||
710 |
||
60770 | 711 |
text \<open>This locale will be interpreted in later theories.\<close> |
37134 | 712 |
|
69590 | 713 |
locale mixin_thy_merge = le: reflexive \<open>le\<close> + le': reflexive \<open>le'\<close> for le le' |
37134 | 714 |
|
715 |
||
60770 | 716 |
subsection \<open>Rewrite morphisms in sublocale\<close> |
41272 | 717 |
|
60770 | 718 |
text \<open>Simulate a specification of left groups where unit and inverse are defined |
41272 | 719 |
rather than specified. This is possible, but not in FOL, due to the lack of a |
60770 | 720 |
selection operator.\<close> |
41272 | 721 |
|
722 |
axiomatization glob_one and glob_inv |
|
69590 | 723 |
where glob_lone: \<open>prod(glob_one(prod), x) = x\<close> |
724 |
and glob_linv: \<open>prod(glob_inv(prod, x), x) = glob_one(prod)\<close> |
|
41272 | 725 |
|
726 |
locale dgrp = semi |
|
727 |
begin |
|
728 |
||
69590 | 729 |
definition one where \<open>one = glob_one(prod)\<close> |
41272 | 730 |
|
69590 | 731 |
lemma lone: \<open>one ** x = x\<close> |
41272 | 732 |
unfolding one_def by (rule glob_lone) |
733 |
||
69590 | 734 |
definition inv where \<open>inv(x) = glob_inv(prod, x)\<close> |
41272 | 735 |
|
69590 | 736 |
lemma linv: \<open>inv(x) ** x = one\<close> |
41272 | 737 |
unfolding one_def inv_def by (rule glob_linv) |
738 |
||
739 |
end |
|
740 |
||
67119 | 741 |
sublocale lgrp < def?: dgrp |
69590 | 742 |
rewrites one_equation: \<open>dgrp.one(prod) = one\<close> and inv_equation: \<open>dgrp.inv(prod, x) = inv(x)\<close> |
41272 | 743 |
proof - |
69590 | 744 |
show \<open>dgrp(prod)\<close> by unfold_locales |
41272 | 745 |
from this interpret d: dgrp . |
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
67399
diff
changeset
|
746 |
\<comment> \<open>Unit\<close> |
69590 | 747 |
have \<open>dgrp.one(prod) = glob_one(prod)\<close> by (rule d.one_def) |
748 |
also have \<open>... = glob_one(prod) ** one\<close> by (simp add: rone) |
|
749 |
also have \<open>... = one\<close> by (simp add: glob_lone) |
|
750 |
finally show \<open>dgrp.one(prod) = one\<close> . |
|
67443
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents:
67399
diff
changeset
|
751 |
\<comment> \<open>Inverse\<close> |
69590 | 752 |
then have \<open>dgrp.inv(prod, x) ** x = inv(x) ** x\<close> by (simp add: glob_linv d.linv linv) |
753 |
then show \<open>dgrp.inv(prod, x) = inv(x)\<close> by (simp add: rcancel) |
|
41272 | 754 |
qed |
755 |
||
756 |
print_locale! lgrp |
|
757 |
||
69054 | 758 |
context lgrp |
759 |
begin |
|
41272 | 760 |
|
60770 | 761 |
text \<open>Equations stored in target\<close> |
41272 | 762 |
|
69590 | 763 |
lemma \<open>dgrp.one(prod) = one\<close> by (rule one_equation) |
764 |
lemma \<open>dgrp.inv(prod, x) = inv(x)\<close> by (rule inv_equation) |
|
41272 | 765 |
|
60770 | 766 |
text \<open>Rewrite morphisms applied\<close> |
41272 | 767 |
|
69590 | 768 |
lemma \<open>one = glob_one(prod)\<close> by (rule one_def) |
769 |
lemma \<open>inv(x) = glob_inv(prod, x)\<close> by (rule inv_def) |
|
41272 | 770 |
|
771 |
end |
|
772 |
||
60770 | 773 |
text \<open>Interpreted versions\<close> |
41272 | 774 |
|
69590 | 775 |
lemma \<open>0 = glob_one ((+))\<close> by (rule int.def.one_def) |
776 |
lemma \<open>- x = glob_inv((+), x)\<close> by (rule int.def.inv_def) |
|
41272 | 777 |
|
60770 | 778 |
text \<open>Roundup applies rewrite morphisms at declaration level in DFS tree\<close> |
51515 | 779 |
|
69590 | 780 |
locale roundup = fixes x assumes true: \<open>x \<longleftrightarrow> True\<close> |
51515 | 781 |
|
69590 | 782 |
sublocale roundup \<subseteq> sub: roundup \<open>x\<close> rewrites \<open>x \<longleftrightarrow> True \<and> True\<close> |
51515 | 783 |
apply unfold_locales apply (simp add: true) done |
69590 | 784 |
lemma (in roundup) \<open>True \<and> True \<longleftrightarrow> True\<close> by (rule sub.true) |
51515 | 785 |
|
41272 | 786 |
|
60770 | 787 |
section \<open>Interpretation in named contexts\<close> |
53367
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
788 |
|
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
789 |
locale container |
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
790 |
begin |
69590 | 791 |
interpretation "private": roundup \<open>True\<close> by unfold_locales rule |
53367
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
792 |
lemmas true_copy = private.true |
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
793 |
end |
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
794 |
|
69054 | 795 |
context container |
796 |
begin |
|
60770 | 797 |
ML \<open>(Context.>> (fn generic => let val context = Context.proof_of generic |
53367
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
798 |
val _ = Proof_Context.get_thms context "private.true" in generic end); |
56138 | 799 |
raise Fail "thm private.true was persisted") |
60770 | 800 |
handle ERROR _ => ([]:thm list);\<close> |
53367
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
801 |
thm true_copy |
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
802 |
end |
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
803 |
|
1f383542226b
New test case: interpretation in named contexts is not persistent.
ballarin
parents:
53366
diff
changeset
|
804 |
|
60770 | 805 |
section \<open>Interpretation in proofs\<close> |
37134 | 806 |
|
69054 | 807 |
notepad |
808 |
begin |
|
69590 | 809 |
interpret "local": lgrp \<open>(+)\<close> \<open>0\<close> \<open>minus\<close> |
37134 | 810 |
by unfold_locales (* subsumed *) |
811 |
{ |
|
69590 | 812 |
fix zero :: \<open>int\<close> |
813 |
assume \<open>!!x. zero + x = x\<close> \<open>!!x. (-x) + x = zero\<close> |
|
814 |
then interpret local_fixed: lgrp \<open>(+)\<close> \<open>zero\<close> \<open>minus\<close> |
|
37134 | 815 |
by unfold_locales |
816 |
thm local_fixed.lone |
|
817 |
} |
|
69590 | 818 |
assume \<open>!!x zero. zero + x = x\<close> \<open>!!x zero. (-x) + x = zero\<close> |
819 |
then interpret local_free: lgrp \<open>(+)\<close> \<open>zero\<close> \<open>minus\<close> for zero |
|
37134 | 820 |
by unfold_locales |
69590 | 821 |
thm local_free.lone [where ?zero = \<open>0\<close>] |
69054 | 822 |
end |
37134 | 823 |
|
69054 | 824 |
notepad |
825 |
begin |
|
38108 | 826 |
{ |
827 |
fix pand and pnot and por |
|
69590 | 828 |
assume passoc: \<open>\<And>x y z. pand(pand(x, y), z) \<longleftrightarrow> pand(x, pand(y, z))\<close> |
829 |
and pnotnot: \<open>\<And>x. pnot(pnot(x)) \<longleftrightarrow> x\<close> |
|
830 |
and por_def: \<open>\<And>x y. por(x, y) \<longleftrightarrow> pnot(pand(pnot(x), pnot(y)))\<close> |
|
831 |
interpret loc: logic_o \<open>pand\<close> \<open>pnot\<close> |
|
832 |
rewrites por_eq: \<open>\<And>x y. logic_o.lor_o(pand, pnot, x, y) \<longleftrightarrow> por(x, y)\<close> (* FIXME *) |
|
38108 | 833 |
proof - |
69590 | 834 |
show logic_o: \<open>PROP logic_o(pand, pnot)\<close> using passoc pnotnot by unfold_locales |
38108 | 835 |
fix x y |
69590 | 836 |
show \<open>logic_o.lor_o(pand, pnot, x, y) \<longleftrightarrow> por(x, y)\<close> |
38108 | 837 |
by (unfold logic_o.lor_o_def [OF logic_o]) (rule por_def [symmetric]) |
838 |
qed |
|
38109 | 839 |
print_interps logic_o |
69590 | 840 |
have \<open>\<And>x y. por(x, y) \<longleftrightarrow> pnot(pand(pnot(x), pnot(y)))\<close> by (rule loc.lor_o_def) |
38108 | 841 |
} |
69054 | 842 |
end |
38108 | 843 |
|
37134 | 844 |
end |