16 |
16 |
17 (*** TF_rec -- by Vset recursion ***) |
17 (*** TF_rec -- by Vset recursion ***) |
18 |
18 |
19 (** conversion rules **) |
19 (** conversion rules **) |
20 |
20 |
21 goal TF_Fn.thy "TF_rec(Tcons(a,tf), b, c, d) = b(a, tf, TF_rec(tf,b,c,d))"; |
21 goal TF_Fn.thy "TF_rec(Tcons(a,f), b, c, d) = b(a, f, TF_rec(f,b,c,d))"; |
22 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
22 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
23 by (rewrite_goals_tac TF.con_defs); |
23 by (rewrite_goals_tac TF.con_defs); |
24 by (simp_tac rank_ss 1); |
24 by (simp_tac rank_ss 1); |
25 val TF_rec_Tcons = result(); |
25 val TF_rec_Tcons = result(); |
26 |
26 |
28 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
28 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
29 by (rewrite_goals_tac TF.con_defs); |
29 by (rewrite_goals_tac TF.con_defs); |
30 by (simp_tac rank_ss 1); |
30 by (simp_tac rank_ss 1); |
31 val TF_rec_Fnil = result(); |
31 val TF_rec_Fnil = result(); |
32 |
32 |
33 goal TF_Fn.thy "TF_rec(Fcons(t,tf), b, c, d) = \ |
33 goal TF_Fn.thy "TF_rec(Fcons(t,f), b, c, d) = \ |
34 \ d(t, tf, TF_rec(t, b, c, d), TF_rec(tf, b, c, d))"; |
34 \ d(t, f, TF_rec(t, b, c, d), TF_rec(f, b, c, d))"; |
35 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
35 by (rtac (TF_rec_def RS def_Vrec RS trans) 1); |
36 by (rewrite_goals_tac TF.con_defs); |
36 by (rewrite_goals_tac TF.con_defs); |
37 by (simp_tac rank_ss 1); |
37 by (simp_tac rank_ss 1); |
38 val TF_rec_Fcons = result(); |
38 val TF_rec_Fcons = result(); |
39 |
39 |
43 |
43 |
44 (** Type checking **) |
44 (** Type checking **) |
45 |
45 |
46 val major::prems = goal TF_Fn.thy |
46 val major::prems = goal TF_Fn.thy |
47 "[| z: tree_forest(A); \ |
47 "[| z: tree_forest(A); \ |
48 \ !!x tf r. [| x: A; tf: forest(A); r: C(tf) \ |
48 \ !!x f r. [| x: A; f: forest(A); r: C(f) \ |
49 \ |] ==> b(x,tf,r): C(Tcons(x,tf)); \ |
49 \ |] ==> b(x,f,r): C(Tcons(x,f)); \ |
50 \ c : C(Fnil); \ |
50 \ c : C(Fnil); \ |
51 \ !!t tf r1 r2. [| t: tree(A); tf: forest(A); r1: C(t); r2: C(tf) \ |
51 \ !!t f r1 r2. [| t: tree(A); f: forest(A); r1: C(t); r2: C(f) \ |
52 \ |] ==> d(t,tf,r1,r2): C(Fcons(t,tf)) \ |
52 \ |] ==> d(t,f,r1,r2): C(Fcons(t,f)) \ |
53 \ |] ==> TF_rec(z,b,c,d) : C(z)"; |
53 \ |] ==> TF_rec(z,b,c,d) : C(z)"; |
54 by (rtac (major RS TF.induct) 1); |
54 by (rtac (major RS TF.induct) 1); |
55 by (ALLGOALS (asm_simp_tac (TF_rec_ss addsimps prems))); |
55 by (ALLGOALS (asm_simp_tac (TF_rec_ss addsimps prems))); |
56 val TF_rec_type = result(); |
56 val TF_rec_type = result(); |
57 |
57 |
58 (*Mutually recursive version*) |
58 (*Mutually recursive version*) |
59 val prems = goal TF_Fn.thy |
59 val prems = goal TF_Fn.thy |
60 "[| !!x tf r. [| x: A; tf: forest(A); r: D(tf) \ |
60 "[| !!x f r. [| x: A; f: forest(A); r: D(f) \ |
61 \ |] ==> b(x,tf,r): C(Tcons(x,tf)); \ |
61 \ |] ==> b(x,f,r): C(Tcons(x,f)); \ |
62 \ c : D(Fnil); \ |
62 \ c : D(Fnil); \ |
63 \ !!t tf r1 r2. [| t: tree(A); tf: forest(A); r1: C(t); r2: D(tf) \ |
63 \ !!t f r1 r2. [| t: tree(A); f: forest(A); r1: C(t); r2: D(f) \ |
64 \ |] ==> d(t,tf,r1,r2): D(Fcons(t,tf)) \ |
64 \ |] ==> d(t,f,r1,r2): D(Fcons(t,f)) \ |
65 \ |] ==> (ALL t:tree(A). TF_rec(t,b,c,d) : C(t)) & \ |
65 \ |] ==> (ALL t:tree(A). TF_rec(t,b,c,d) : C(t)) & \ |
66 \ (ALL tf: forest(A). TF_rec(tf,b,c,d) : D(tf))"; |
66 \ (ALL f: forest(A). TF_rec(f,b,c,d) : D(f))"; |
67 by (rewtac Ball_def); |
67 by (rewtac Ball_def); |
68 by (rtac TF.mutual_induct 1); |
68 by (rtac TF.mutual_induct 1); |
69 by (ALLGOALS (asm_simp_tac (TF_rec_ss addsimps prems))); |
69 by (ALLGOALS (asm_simp_tac (TF_rec_ss addsimps prems))); |
70 val tree_forest_rec_type = result(); |
70 val tree_forest_rec_type = result(); |
71 |
71 |
72 |
72 |
73 (** Versions for use with definitions **) |
73 (** Versions for use with definitions **) |
74 |
74 |
75 val [rew] = goal TF_Fn.thy |
75 val [rew] = goal TF_Fn.thy |
76 "[| !!z. j(z)==TF_rec(z,b,c,d) |] ==> j(Tcons(a,tf)) = b(a,tf,j(tf))"; |
76 "[| !!z. j(z)==TF_rec(z,b,c,d) |] ==> j(Tcons(a,f)) = b(a,f,j(f))"; |
77 by (rewtac rew); |
77 by (rewtac rew); |
78 by (rtac TF_rec_Tcons 1); |
78 by (rtac TF_rec_Tcons 1); |
79 val def_TF_rec_Tcons = result(); |
79 val def_TF_rec_Tcons = result(); |
80 |
80 |
81 val [rew] = goal TF_Fn.thy |
81 val [rew] = goal TF_Fn.thy |
83 by (rewtac rew); |
83 by (rewtac rew); |
84 by (rtac TF_rec_Fnil 1); |
84 by (rtac TF_rec_Fnil 1); |
85 val def_TF_rec_Fnil = result(); |
85 val def_TF_rec_Fnil = result(); |
86 |
86 |
87 val [rew] = goal TF_Fn.thy |
87 val [rew] = goal TF_Fn.thy |
88 "[| !!z. j(z)==TF_rec(z,b,c,d) |] ==> j(Fcons(t,tf)) = d(t,tf,j(t),j(tf))"; |
88 "[| !!z. j(z)==TF_rec(z,b,c,d) |] ==> j(Fcons(t,f)) = d(t,f,j(t),j(f))"; |
89 by (rewtac rew); |
89 by (rewtac rew); |
90 by (rtac TF_rec_Fcons 1); |
90 by (rtac TF_rec_Fcons 1); |
91 val def_TF_rec_Fcons = result(); |
91 val def_TF_rec_Fcons = result(); |
92 |
92 |
93 fun TF_recs def = map standard |
93 fun TF_recs def = map standard |
117 val [TF_map_Tcons, TF_map_Fnil, TF_map_Fcons] = TF_recs TF_map_def; |
117 val [TF_map_Tcons, TF_map_Fnil, TF_map_Fcons] = TF_recs TF_map_def; |
118 |
118 |
119 val prems = goalw TF_Fn.thy [TF_map_def] |
119 val prems = goalw TF_Fn.thy [TF_map_def] |
120 "[| !!x. x: A ==> h(x): B |] ==> \ |
120 "[| !!x. x: A ==> h(x): B |] ==> \ |
121 \ (ALL t:tree(A). TF_map(h,t) : tree(B)) & \ |
121 \ (ALL t:tree(A). TF_map(h,t) : tree(B)) & \ |
122 \ (ALL tf: forest(A). TF_map(h,tf) : forest(B))"; |
122 \ (ALL f: forest(A). TF_map(h,f) : forest(B))"; |
123 by (REPEAT |
123 by (REPEAT |
124 (ares_tac ([tree_forest_rec_type, TconsI, FnilI, FconsI] @ prems) 1)); |
124 (ares_tac ([tree_forest_rec_type, TconsI, FnilI, FconsI] @ prems) 1)); |
125 val TF_map_type = result(); |
125 val TF_map_type = result(); |
126 |
126 |
127 |
127 |
168 |
168 |
169 (** theorems about list_of_TF and TF_of_list **) |
169 (** theorems about list_of_TF and TF_of_list **) |
170 |
170 |
171 (*essentially the same as list induction*) |
171 (*essentially the same as list induction*) |
172 val major::prems = goal TF_Fn.thy |
172 val major::prems = goal TF_Fn.thy |
173 "[| tf: forest(A); \ |
173 "[| f: forest(A); \ |
174 \ R(Fnil); \ |
174 \ R(Fnil); \ |
175 \ !!t tf. [| t: tree(A); tf: forest(A); R(tf) |] ==> R(Fcons(t,tf)) \ |
175 \ !!t f. [| t: tree(A); f: forest(A); R(f) |] ==> R(Fcons(t,f)) \ |
176 \ |] ==> R(tf)"; |
176 \ |] ==> R(f)"; |
177 by (rtac (major RS (TF.mutual_induct RS conjunct2 RS spec RSN (2,rev_mp))) 1); |
177 by (rtac (major RS (TF.mutual_induct RS conjunct2 RS spec RSN (2,rev_mp))) 1); |
178 by (REPEAT (ares_tac (TrueI::prems) 1)); |
178 by (REPEAT (ares_tac (TrueI::prems) 1)); |
179 val forest_induct = result(); |
179 val forest_induct = result(); |
180 |
180 |
181 goal TF_Fn.thy "!!tf A. tf: forest(A) ==> TF_of_list(list_of_TF(tf)) = tf"; |
181 goal TF_Fn.thy "!!f A. f: forest(A) ==> TF_of_list(list_of_TF(f)) = f"; |
182 by (etac forest_induct 1); |
182 by (etac forest_induct 1); |
183 by (ALLGOALS (asm_simp_tac TF_ss)); |
183 by (ALLGOALS (asm_simp_tac TF_ss)); |
184 val forest_iso = result(); |
184 val forest_iso = result(); |
185 |
185 |
186 goal TF_Fn.thy |
186 goal TF_Fn.thy |