10370
|
1 |
(* ID: $Id$ *)
|
10426
|
2 |
theory Advanced = Even:
|
|
3 |
|
10468
|
4 |
|
|
5 |
datatype 'f gterm = Apply 'f "'f gterm list"
|
|
6 |
|
|
7 |
datatype integer_op = Number int | UnaryMinus | Plus;
|
|
8 |
|
|
9 |
consts gterms :: "'f set \<Rightarrow> 'f gterm set"
|
|
10 |
inductive "gterms F"
|
|
11 |
intros
|
|
12 |
step[intro!]: "\<lbrakk>\<forall>t \<in> set args. t \<in> gterms F; f \<in> F\<rbrakk>
|
|
13 |
\<Longrightarrow> (Apply f args) \<in> gterms F"
|
|
14 |
|
|
15 |
lemma gterms_mono: "F\<subseteq>G \<Longrightarrow> gterms F \<subseteq> gterms G"
|
|
16 |
apply clarify
|
|
17 |
apply (erule gterms.induct)
|
10882
|
18 |
txt{*
|
|
19 |
@{subgoals[display,indent=0,margin=65]}
|
|
20 |
*};
|
10468
|
21 |
apply blast
|
|
22 |
done
|
|
23 |
|
10882
|
24 |
|
10468
|
25 |
text{*
|
|
26 |
@{thm[display] even.cases[no_vars]}
|
|
27 |
\rulename{even.cases}
|
|
28 |
|
|
29 |
Just as a demo I include
|
|
30 |
the two forms that Markus has made available. First the one for binding the
|
|
31 |
result to a name
|
|
32 |
|
|
33 |
*}
|
|
34 |
|
|
35 |
inductive_cases Suc_Suc_cases [elim!]:
|
10426
|
36 |
"Suc(Suc n) \<in> even"
|
|
37 |
|
10468
|
38 |
thm Suc_Suc_cases;
|
|
39 |
|
|
40 |
text{*
|
|
41 |
@{thm[display] Suc_Suc_cases[no_vars]}
|
|
42 |
\rulename{Suc_Suc_cases}
|
|
43 |
|
|
44 |
and now the one for local usage:
|
|
45 |
*}
|
|
46 |
|
|
47 |
lemma "Suc(Suc n) \<in> even \<Longrightarrow> P n";
|
|
48 |
apply (ind_cases "Suc(Suc n) \<in> even");
|
|
49 |
oops
|
|
50 |
|
|
51 |
inductive_cases gterm_Apply_elim [elim!]: "Apply f args \<in> gterms F"
|
|
52 |
|
|
53 |
text{*this is what we get:
|
|
54 |
|
|
55 |
@{thm[display] gterm_Apply_elim[no_vars]}
|
|
56 |
\rulename{gterm_Apply_elim}
|
|
57 |
*}
|
10426
|
58 |
|
10468
|
59 |
lemma gterms_IntI [rule_format]:
|
|
60 |
"t \<in> gterms F \<Longrightarrow> t \<in> gterms G \<longrightarrow> t \<in> gterms (F\<inter>G)"
|
|
61 |
apply (erule gterms.induct)
|
10882
|
62 |
txt{*
|
|
63 |
@{subgoals[display,indent=0,margin=65]}
|
|
64 |
*};
|
10468
|
65 |
apply blast
|
|
66 |
done
|
|
67 |
|
|
68 |
|
|
69 |
text{*
|
|
70 |
@{thm[display] mono_Int[no_vars]}
|
|
71 |
\rulename{mono_Int}
|
|
72 |
*}
|
10426
|
73 |
|
10468
|
74 |
lemma gterms_Int_eq [simp]:
|
|
75 |
"gterms (F\<inter>G) = gterms F \<inter> gterms G"
|
|
76 |
apply (rule equalityI)
|
|
77 |
apply (blast intro!: mono_Int monoI gterms_mono)
|
|
78 |
apply (blast intro!: gterms_IntI)
|
|
79 |
done
|
|
80 |
|
|
81 |
|
|
82 |
consts integer_arity :: "integer_op \<Rightarrow> nat"
|
|
83 |
primrec
|
|
84 |
"integer_arity (Number n) = #0"
|
|
85 |
"integer_arity UnaryMinus = #1"
|
|
86 |
"integer_arity Plus = #2"
|
|
87 |
|
|
88 |
consts well_formed_gterm :: "('f \<Rightarrow> nat) \<Rightarrow> 'f gterm set"
|
|
89 |
inductive "well_formed_gterm arity"
|
|
90 |
intros
|
|
91 |
step[intro!]: "\<lbrakk>\<forall>t \<in> set args. t \<in> well_formed_gterm arity;
|
|
92 |
length args = arity f\<rbrakk>
|
|
93 |
\<Longrightarrow> (Apply f args) \<in> well_formed_gterm arity"
|
|
94 |
|
10426
|
95 |
|
10468
|
96 |
consts well_formed_gterm' :: "('f \<Rightarrow> nat) \<Rightarrow> 'f gterm set"
|
|
97 |
inductive "well_formed_gterm' arity"
|
|
98 |
intros
|
|
99 |
step[intro!]: "\<lbrakk>args \<in> lists (well_formed_gterm' arity);
|
|
100 |
length args = arity f\<rbrakk>
|
|
101 |
\<Longrightarrow> (Apply f args) \<in> well_formed_gterm' arity"
|
|
102 |
monos lists_mono
|
|
103 |
|
|
104 |
lemma "well_formed_gterm arity \<subseteq> well_formed_gterm' arity"
|
|
105 |
apply clarify
|
10882
|
106 |
txt{*
|
|
107 |
The situation after clarify
|
|
108 |
@{subgoals[display,indent=0,margin=65]}
|
|
109 |
*};
|
10468
|
110 |
apply (erule well_formed_gterm.induct)
|
10882
|
111 |
txt{*
|
|
112 |
note the induction hypothesis!
|
|
113 |
@{subgoals[display,indent=0,margin=65]}
|
|
114 |
*};
|
10468
|
115 |
apply auto
|
|
116 |
done
|
|
117 |
|
10426
|
118 |
|
10370
|
119 |
|
10468
|
120 |
lemma "well_formed_gterm' arity \<subseteq> well_formed_gterm arity"
|
|
121 |
apply clarify
|
10882
|
122 |
txt{*
|
|
123 |
The situation after clarify
|
|
124 |
@{subgoals[display,indent=0,margin=65]}
|
|
125 |
*};
|
10468
|
126 |
apply (erule well_formed_gterm'.induct)
|
10882
|
127 |
txt{*
|
|
128 |
note the induction hypothesis!
|
|
129 |
@{subgoals[display,indent=0,margin=65]}
|
|
130 |
*};
|
10468
|
131 |
apply auto
|
|
132 |
done
|
10370
|
133 |
|
|
134 |
|
10468
|
135 |
text{*
|
|
136 |
@{thm[display] lists_Int_eq[no_vars]}
|
|
137 |
*}
|
|
138 |
|
|
139 |
text{* the rest isn't used: too complicated. OK for an exercise though.*}
|
|
140 |
|
|
141 |
consts integer_signature :: "(integer_op * (unit list * unit)) set"
|
|
142 |
inductive "integer_signature"
|
10370
|
143 |
intros
|
10468
|
144 |
Number: "(Number n, ([], ())) \<in> integer_signature"
|
|
145 |
UnaryMinus: "(UnaryMinus, ([()], ())) \<in> integer_signature"
|
|
146 |
Plus: "(Plus, ([(),()], ())) \<in> integer_signature"
|
|
147 |
|
10370
|
148 |
|
10468
|
149 |
consts well_typed_gterm :: "('f \<Rightarrow> 't list * 't) \<Rightarrow> ('f gterm * 't)set"
|
|
150 |
inductive "well_typed_gterm sig"
|
10370
|
151 |
intros
|
10468
|
152 |
step[intro!]:
|
|
153 |
"\<lbrakk>\<forall>pair \<in> set args. pair \<in> well_typed_gterm sig;
|
|
154 |
sig f = (map snd args, rtype)\<rbrakk>
|
|
155 |
\<Longrightarrow> (Apply f (map fst args), rtype)
|
|
156 |
\<in> well_typed_gterm sig"
|
|
157 |
|
|
158 |
consts well_typed_gterm' :: "('f \<Rightarrow> 't list * 't) \<Rightarrow> ('f gterm * 't)set"
|
|
159 |
inductive "well_typed_gterm' sig"
|
|
160 |
intros
|
|
161 |
step[intro!]:
|
|
162 |
"\<lbrakk>args \<in> lists(well_typed_gterm' sig);
|
|
163 |
sig f = (map snd args, rtype)\<rbrakk>
|
|
164 |
\<Longrightarrow> (Apply f (map fst args), rtype)
|
|
165 |
\<in> well_typed_gterm' sig"
|
10370
|
166 |
monos lists_mono
|
|
167 |
|
|
168 |
|
10468
|
169 |
lemma "well_typed_gterm sig \<subseteq> well_typed_gterm' sig"
|
10370
|
170 |
apply clarify
|
10468
|
171 |
apply (erule well_typed_gterm.induct)
|
10370
|
172 |
apply auto
|
|
173 |
done
|
|
174 |
|
10468
|
175 |
lemma "well_typed_gterm' sig \<subseteq> well_typed_gterm sig"
|
10370
|
176 |
apply clarify
|
10468
|
177 |
apply (erule well_typed_gterm'.induct)
|
10370
|
178 |
apply auto
|
|
179 |
done
|
|
180 |
|
10468
|
181 |
|
10370
|
182 |
end
|
|
183 |
|