1 (* Title: FOL/ex/LocaleInst.thy
3 Author: Clemens Ballarin
4 Copyright (c) 2004 by Clemens Ballarin
6 Test of locale instantiation mechanism, also provides a few examples.
9 header {* Test of Locale instantiation *}
11 theory LocaleInst = FOL:
13 ML {* set show_hyps *}
15 section {* Locale without assumptions *}
17 locale L1 = notes rev_conjI [intro] = conjI [THEN iffD1 [OF conj_commute]]
19 lemma "[| A; B |] ==> A & B"
21 instantiate my: L1 txt {* No chained fact required. *}
22 assume B and A txt {* order reversed *}
24 txt {* Applies @{thm my.rev_conjI}. *}
27 section {* Simple locale with assumptions *}
32 consts bin :: "[i, i] => i" (infixl "#" 60)
34 axioms i_assoc: "(x # y) # z = x # (y # z)"
35 i_comm: "x # y = y # x"
38 fixes OP (infixl "+" 60)
39 assumes assoc: "(x + y) + z = x + (y + z)"
40 and comm: "x + y = y + x"
42 lemma (in L2) lcomm: "x + (y + z) = y + (x + z)"
44 have "x + (y + z) = (x + y) + z" by (simp add: assoc)
45 also have "... = (y + x) + z" by (simp add: comm)
46 also have "... = y + (x + z)" by (simp add: assoc)
47 finally show ?thesis .
50 lemmas (in L2) AC = comm assoc lcomm
52 lemma "(x::i) # y # z # w = y # x # w # z"
54 have "L2 (op #)" by (rule L2.intro [of "op #", OF i_assoc i_comm])
55 then instantiate my: L2
56 txt {* Chained fact required to discharge assumptions of @{text L2}
57 and instantiate parameters. *}
58 show ?thesis by (simp only: my.OP.AC) (* or simply AC *)
61 section {* Nested locale with assumptions *}
64 fixes OP (infixl "+" 60)
65 assumes assoc: "(x + y) + z = x + (y + z)"
68 assumes comm: "x + y = y + x"
70 lemma (in L4) lcomm: "x + (y + z) = y + (x + z)"
72 have "x + (y + z) = (x + y) + z" by (simp add: assoc)
73 also have "... = (y + x) + z" by (simp add: comm)
74 also have "... = y + (x + z)" by (simp add: assoc)
75 finally show ?thesis .
78 lemmas (in L4) AC = comm assoc lcomm
80 text {* Conceptually difficult locale:
81 2nd context fragment contains facts with differing metahyps. *}
84 fixes OP (infixl "+" 60)
85 assumes assoc: "!!x y z. (x + y) + z = x + (y + z)"
86 and comm: "!!x y. x + y = y + x"
88 by (blast intro: L4.intro L3.intro assoc L4_axioms.intro comm)
90 lemma "(x::i) # y # z # w = y # x # w # z"
92 have "L4 (op #)" by (rule L4_intro [of "op #", OF i_assoc i_comm])
93 then instantiate my: L4
94 show ?thesis by (simp only: my.OP.AC) (* or simply AC *)
97 section {* Locale with definition *}
99 text {* This example is admittedly not very creative :-) *}
101 locale L5 = L4 + var A +
102 defines A_def: "A == True"
105 by (unfold A_def) rule
107 lemma "L5(op #) ==> True"
110 then instantiate my: L5
111 show ?thesis by (rule lem) (* lem instantiated to True *)