17456
|
1 |
(* Title: CCL/Trancl.ML
|
0
|
2 |
ID: $Id$
|
|
3 |
*)
|
|
4 |
|
|
5 |
(** Natural deduction for trans(r) **)
|
|
6 |
|
17456
|
7 |
val prems = goalw (the_context ()) [trans_def]
|
0
|
8 |
"(!! x y z. [| <x,y>:r; <y,z>:r |] ==> <x,z>:r) ==> trans(r)";
|
|
9 |
by (REPEAT (ares_tac (prems@[allI,impI]) 1));
|
757
|
10 |
qed "transI";
|
0
|
11 |
|
17456
|
12 |
val major::prems = goalw (the_context ()) [trans_def]
|
0
|
13 |
"[| trans(r); <a,b>:r; <b,c>:r |] ==> <a,c>:r";
|
|
14 |
by (cut_facts_tac [major] 1);
|
|
15 |
by (fast_tac (FOL_cs addIs prems) 1);
|
757
|
16 |
qed "transD";
|
0
|
17 |
|
|
18 |
(** Identity relation **)
|
|
19 |
|
17456
|
20 |
Goalw [id_def] "<a,a> : id";
|
0
|
21 |
by (rtac CollectI 1);
|
|
22 |
by (rtac exI 1);
|
|
23 |
by (rtac refl 1);
|
757
|
24 |
qed "idI";
|
0
|
25 |
|
17456
|
26 |
val major::prems = goalw (the_context ()) [id_def]
|
0
|
27 |
"[| p: id; !!x.[| p = <x,x> |] ==> P \
|
17456
|
28 |
\ |] ==> P";
|
0
|
29 |
by (rtac (major RS CollectE) 1);
|
|
30 |
by (etac exE 1);
|
|
31 |
by (eresolve_tac prems 1);
|
757
|
32 |
qed "idE";
|
0
|
33 |
|
|
34 |
(** Composition of two relations **)
|
|
35 |
|
17456
|
36 |
val prems = goalw (the_context ()) [comp_def]
|
0
|
37 |
"[| <a,b>:s; <b,c>:r |] ==> <a,c> : r O s";
|
|
38 |
by (fast_tac (set_cs addIs prems) 1);
|
757
|
39 |
qed "compI";
|
0
|
40 |
|
|
41 |
(*proof requires higher-level assumptions or a delaying of hyp_subst_tac*)
|
17456
|
42 |
val prems = goalw (the_context ()) [comp_def]
|
0
|
43 |
"[| xz : r O s; \
|
|
44 |
\ !!x y z. [| xz = <x,z>; <x,y>:s; <y,z>:r |] ==> P \
|
|
45 |
\ |] ==> P";
|
|
46 |
by (cut_facts_tac prems 1);
|
|
47 |
by (REPEAT (eresolve_tac [CollectE, exE, conjE] 1 ORELSE ares_tac prems 1));
|
757
|
48 |
qed "compE";
|
0
|
49 |
|
17456
|
50 |
val prems = goal (the_context ())
|
0
|
51 |
"[| <a,c> : r O s; \
|
|
52 |
\ !!y. [| <a,y>:s; <y,c>:r |] ==> P \
|
|
53 |
\ |] ==> P";
|
|
54 |
by (rtac compE 1);
|
|
55 |
by (REPEAT (ares_tac prems 1 ORELSE eresolve_tac [pair_inject,ssubst] 1));
|
757
|
56 |
qed "compEpair";
|
0
|
57 |
|
17456
|
58 |
val comp_cs = set_cs addIs [compI,idI]
|
|
59 |
addEs [compE,idE]
|
1459
|
60 |
addSEs [pair_inject];
|
0
|
61 |
|
17456
|
62 |
val prems = goal (the_context ())
|
0
|
63 |
"[| r'<=r; s'<=s |] ==> (r' O s') <= (r O s)";
|
|
64 |
by (cut_facts_tac prems 1);
|
|
65 |
by (fast_tac comp_cs 1);
|
757
|
66 |
qed "comp_mono";
|
0
|
67 |
|
|
68 |
(** The relation rtrancl **)
|
|
69 |
|
5062
|
70 |
Goal "mono(%s. id Un (r O s))";
|
0
|
71 |
by (rtac monoI 1);
|
|
72 |
by (REPEAT (ares_tac [monoI, subset_refl, comp_mono, Un_mono] 1));
|
757
|
73 |
qed "rtrancl_fun_mono";
|
0
|
74 |
|
|
75 |
val rtrancl_unfold = rtrancl_fun_mono RS (rtrancl_def RS def_lfp_Tarski);
|
|
76 |
|
|
77 |
(*Reflexivity of rtrancl*)
|
5062
|
78 |
Goal "<a,a> : r^*";
|
2035
|
79 |
by (stac rtrancl_unfold 1);
|
0
|
80 |
by (fast_tac comp_cs 1);
|
757
|
81 |
qed "rtrancl_refl";
|
0
|
82 |
|
|
83 |
(*Closure under composition with r*)
|
17456
|
84 |
val prems = goal (the_context ())
|
0
|
85 |
"[| <a,b> : r^*; <b,c> : r |] ==> <a,c> : r^*";
|
2035
|
86 |
by (stac rtrancl_unfold 1);
|
0
|
87 |
by (fast_tac (comp_cs addIs prems) 1);
|
757
|
88 |
qed "rtrancl_into_rtrancl";
|
0
|
89 |
|
|
90 |
(*rtrancl of r contains r*)
|
17456
|
91 |
val [prem] = goal (the_context ()) "[| <a,b> : r |] ==> <a,b> : r^*";
|
0
|
92 |
by (rtac (rtrancl_refl RS rtrancl_into_rtrancl) 1);
|
|
93 |
by (rtac prem 1);
|
757
|
94 |
qed "r_into_rtrancl";
|
0
|
95 |
|
|
96 |
|
|
97 |
(** standard induction rule **)
|
|
98 |
|
17456
|
99 |
val major::prems = goal (the_context ())
|
0
|
100 |
"[| <a,b> : r^*; \
|
|
101 |
\ !!x. P(<x,x>); \
|
|
102 |
\ !!x y z.[| P(<x,y>); <x,y>: r^*; <y,z>: r |] ==> P(<x,z>) |] \
|
|
103 |
\ ==> P(<a,b>)";
|
|
104 |
by (rtac (major RS (rtrancl_def RS def_induct)) 1);
|
|
105 |
by (rtac rtrancl_fun_mono 1);
|
|
106 |
by (fast_tac (comp_cs addIs prems) 1);
|
757
|
107 |
qed "rtrancl_full_induct";
|
0
|
108 |
|
|
109 |
(*nice induction rule*)
|
17456
|
110 |
val major::prems = goal (the_context ())
|
0
|
111 |
"[| <a,b> : r^*; \
|
|
112 |
\ P(a); \
|
1459
|
113 |
\ !!y z.[| <a,y> : r^*; <y,z> : r; P(y) |] ==> P(z) |] \
|
0
|
114 |
\ ==> P(b)";
|
|
115 |
(*by induction on this formula*)
|
|
116 |
by (subgoal_tac "ALL y. <a,b> = <a,y> --> P(y)" 1);
|
|
117 |
(*now solve first subgoal: this formula is sufficient*)
|
|
118 |
by (fast_tac FOL_cs 1);
|
|
119 |
(*now do the induction*)
|
|
120 |
by (resolve_tac [major RS rtrancl_full_induct] 1);
|
|
121 |
by (fast_tac (comp_cs addIs prems) 1);
|
|
122 |
by (fast_tac (comp_cs addIs prems) 1);
|
757
|
123 |
qed "rtrancl_induct";
|
0
|
124 |
|
|
125 |
(*transitivity of transitive closure!! -- by induction.*)
|
5062
|
126 |
Goal "trans(r^*)";
|
0
|
127 |
by (rtac transI 1);
|
|
128 |
by (res_inst_tac [("b","z")] rtrancl_induct 1);
|
|
129 |
by (DEPTH_SOLVE (eresolve_tac [asm_rl, rtrancl_into_rtrancl] 1));
|
757
|
130 |
qed "trans_rtrancl";
|
0
|
131 |
|
|
132 |
(*elimination of rtrancl -- by induction on a special formula*)
|
17456
|
133 |
val major::prems = goal (the_context ())
|
0
|
134 |
"[| <a,b> : r^*; (a = b) ==> P; \
|
1459
|
135 |
\ !!y.[| <a,y> : r^*; <y,b> : r |] ==> P |] \
|
0
|
136 |
\ ==> P";
|
|
137 |
by (subgoal_tac "a = b | (EX y. <a,y> : r^* & <y,b> : r)" 1);
|
|
138 |
by (rtac (major RS rtrancl_induct) 2);
|
|
139 |
by (fast_tac (set_cs addIs prems) 2);
|
|
140 |
by (fast_tac (set_cs addIs prems) 2);
|
|
141 |
by (REPEAT (eresolve_tac ([asm_rl,exE,disjE,conjE]@prems) 1));
|
757
|
142 |
qed "rtranclE";
|
0
|
143 |
|
|
144 |
|
|
145 |
(**** The relation trancl ****)
|
|
146 |
|
|
147 |
(** Conversions between trancl and rtrancl **)
|
|
148 |
|
17456
|
149 |
val [major] = goalw (the_context ()) [trancl_def]
|
0
|
150 |
"[| <a,b> : r^+ |] ==> <a,b> : r^*";
|
|
151 |
by (resolve_tac [major RS compEpair] 1);
|
|
152 |
by (REPEAT (ares_tac [rtrancl_into_rtrancl] 1));
|
757
|
153 |
qed "trancl_into_rtrancl";
|
0
|
154 |
|
|
155 |
(*r^+ contains r*)
|
17456
|
156 |
val [prem] = goalw (the_context ()) [trancl_def]
|
0
|
157 |
"[| <a,b> : r |] ==> <a,b> : r^+";
|
|
158 |
by (REPEAT (ares_tac [prem,compI,rtrancl_refl] 1));
|
757
|
159 |
qed "r_into_trancl";
|
0
|
160 |
|
|
161 |
(*intro rule by definition: from rtrancl and r*)
|
17456
|
162 |
val prems = goalw (the_context ()) [trancl_def]
|
0
|
163 |
"[| <a,b> : r^*; <b,c> : r |] ==> <a,c> : r^+";
|
|
164 |
by (REPEAT (resolve_tac ([compI]@prems) 1));
|
757
|
165 |
qed "rtrancl_into_trancl1";
|
0
|
166 |
|
|
167 |
(*intro rule from r and rtrancl*)
|
17456
|
168 |
val prems = goal (the_context ())
|
0
|
169 |
"[| <a,b> : r; <b,c> : r^* |] ==> <a,c> : r^+";
|
|
170 |
by (resolve_tac (prems RL [rtranclE]) 1);
|
|
171 |
by (etac subst 1);
|
|
172 |
by (resolve_tac (prems RL [r_into_trancl]) 1);
|
|
173 |
by (rtac (trans_rtrancl RS transD RS rtrancl_into_trancl1) 1);
|
|
174 |
by (REPEAT (ares_tac (prems@[r_into_rtrancl]) 1));
|
757
|
175 |
qed "rtrancl_into_trancl2";
|
0
|
176 |
|
|
177 |
(*elimination of r^+ -- NOT an induction rule*)
|
17456
|
178 |
val major::prems = goal (the_context ())
|
0
|
179 |
"[| <a,b> : r^+; \
|
|
180 |
\ <a,b> : r ==> P; \
|
1459
|
181 |
\ !!y.[| <a,y> : r^+; <y,b> : r |] ==> P \
|
0
|
182 |
\ |] ==> P";
|
|
183 |
by (subgoal_tac "<a,b> : r | (EX y. <a,y> : r^+ & <y,b> : r)" 1);
|
|
184 |
by (REPEAT (eresolve_tac ([asm_rl,disjE,exE,conjE]@prems) 1));
|
|
185 |
by (rtac (rewrite_rule [trancl_def] major RS compEpair) 1);
|
|
186 |
by (etac rtranclE 1);
|
|
187 |
by (fast_tac comp_cs 1);
|
|
188 |
by (fast_tac (comp_cs addSIs [rtrancl_into_trancl1]) 1);
|
757
|
189 |
qed "tranclE";
|
0
|
190 |
|
|
191 |
(*Transitivity of r^+.
|
|
192 |
Proved by unfolding since it uses transitivity of rtrancl. *)
|
5062
|
193 |
Goalw [trancl_def] "trans(r^+)";
|
0
|
194 |
by (rtac transI 1);
|
|
195 |
by (REPEAT (etac compEpair 1));
|
|
196 |
by (rtac (rtrancl_into_rtrancl RS (trans_rtrancl RS transD RS compI)) 1);
|
|
197 |
by (REPEAT (assume_tac 1));
|
757
|
198 |
qed "trans_trancl";
|
0
|
199 |
|
17456
|
200 |
val prems = goal (the_context ())
|
0
|
201 |
"[| <a,b> : r; <b,c> : r^+ |] ==> <a,c> : r^+";
|
|
202 |
by (rtac (r_into_trancl RS (trans_trancl RS transD)) 1);
|
|
203 |
by (resolve_tac prems 1);
|
|
204 |
by (resolve_tac prems 1);
|
757
|
205 |
qed "trancl_into_trancl2";
|