63 struct |
67 struct |
64 |
68 |
65 open Data; |
69 open Data; |
66 |
70 |
67 (* FIXME: only test! *) |
71 (* FIXME: only test! *) |
68 fun def eq = case dest_eq eq of |
72 fun def xs eq = |
|
73 let val n = length xs |
|
74 in case dest_eq eq of |
69 Some(c,s,t) => |
75 Some(c,s,t) => |
70 s = Bound 0 andalso not(loose_bvar1(t,0)) orelse |
76 s = Bound n andalso not(loose_bvar1(t,n)) orelse |
71 t = Bound 0 andalso not(loose_bvar1(s,0)) |
77 t = Bound n andalso not(loose_bvar1(s,n)) |
72 | None => false; |
78 | None => false |
|
79 end; |
73 |
80 |
74 fun extract_conj t = case dest_conj t of None => None |
81 fun extract_conj xs t = case dest_conj t of None => None |
75 | Some(conj,P,Q) => |
82 | Some(conj,P,Q) => |
76 (if def P then Some(P,Q) else |
83 (if def xs P then Some(xs,P,Q) else |
77 if def Q then Some(Q,P) else |
84 if def xs Q then Some(xs,Q,P) else |
78 (case extract_conj P of |
85 (case extract_conj xs P of |
79 Some(eq,P') => Some(eq, conj $ P' $ Q) |
86 Some(xs,eq,P') => Some(xs,eq, conj $ P' $ Q) |
80 | None => (case extract_conj Q of |
87 | None => (case extract_conj xs Q of |
81 Some(eq,Q') => Some(eq,conj $ P $ Q') |
88 Some(xs,eq,Q') => Some(xs,eq,conj $ P $ Q') |
82 | None => None))); |
89 | None => None))); |
83 |
90 |
84 fun extract_imp t = case dest_imp t of None => None |
91 fun extract_imp xs t = case dest_imp t of None => None |
85 | Some(imp,P,Q) => if def P then Some(P,Q) |
92 | Some(imp,P,Q) => if def xs P then Some(xs,P,Q) |
86 else (case extract_conj P of |
93 else (case extract_conj xs P of |
87 Some(eq,P') => Some(eq, imp $ P' $ Q) |
94 Some(xs,eq,P') => Some(xs, eq, imp $ P' $ Q) |
88 | None => (case extract_imp Q of |
95 | None => (case extract_imp xs Q of |
89 None => None |
96 None => None |
90 | Some(eq,Q') => Some(eq, imp$P$Q'))); |
97 | Some(xs,eq,Q') => |
91 |
98 Some(xs,eq,imp$P$Q'))); |
|
99 |
|
100 fun extract_quant extract q = |
|
101 let fun exqu xs ((qC as Const(qa,_)) $ Abs(x,T,Q)) = |
|
102 if qa = q then exqu ((qC,x,T)::xs) Q else None |
|
103 | exqu xs P = extract xs P |
|
104 in exqu end; |
92 |
105 |
93 fun prove_conv tac sg tu = |
106 fun prove_conv tac sg tu = |
94 let val meta_eq = cterm_of sg (Logic.mk_equals tu) |
107 let val meta_eq = cterm_of sg (Logic.mk_equals tu) |
95 in prove_goalw_cterm [] meta_eq (K [rtac iff_reflection 1, tac]) |
108 in prove_goalw_cterm [] meta_eq (K [rtac iff_reflection 1, tac]) |
96 handle ERROR => |
109 handle ERROR => |
97 error("The error(s) above occurred while trying to prove " ^ |
110 error("The error(s) above occurred while trying to prove " ^ |
98 string_of_cterm meta_eq) |
111 string_of_cterm meta_eq) |
99 end; |
112 end; |
100 |
113 |
101 (* Proves (? x. ... & x = t & ...) = (? x. x = t & ... & ...) |
114 fun qcomm_tac qcomm qI i = REPEAT_DETERM (rtac qcomm i THEN rtac qI i) |
|
115 |
|
116 (* Proves (? x0..xn. ... & x0 = t & ...) = (? x1..xn x0. x0 = t & ... & ...) |
102 Better: instantiate exI |
117 Better: instantiate exI |
103 *) |
118 *) |
104 val prove_one_point_ex_tac = rtac iffI 1 THEN |
119 local |
|
120 val excomm = ex_comm RS iff_trans |
|
121 in |
|
122 val prove_one_point_ex_tac = qcomm_tac excomm iff_exI 1 THEN rtac iffI 1 THEN |
105 ALLGOALS(EVERY'[etac exE, REPEAT_DETERM o (etac conjE), rtac exI, |
123 ALLGOALS(EVERY'[etac exE, REPEAT_DETERM o (etac conjE), rtac exI, |
106 DEPTH_SOLVE_1 o (ares_tac [conjI])]); |
124 DEPTH_SOLVE_1 o (ares_tac [conjI])]) |
|
125 end; |
107 |
126 |
108 (* Proves (! x. (... & x = t & ...) --> P x) = |
127 (* Proves (! x0..xn. (... & x0 = t & ...) --> P x0) = |
109 (! x. x = t --> (... & ...) --> P x) |
128 (! x1..xn x0. x0 = t --> (... & ...) --> P x0) |
110 *) |
129 *) |
111 local |
130 local |
112 val tac = SELECT_GOAL |
131 val tac = SELECT_GOAL |
113 (EVERY1[REPEAT o (dtac uncurry), REPEAT o (rtac impI), etac mp, |
132 (EVERY1[REPEAT o (dtac uncurry), REPEAT o (rtac impI), etac mp, |
114 REPEAT o (etac conjE), REPEAT o (ares_tac [conjI])]) |
133 REPEAT o (etac conjE), REPEAT o (ares_tac [conjI])]) |
|
134 val allcomm = all_comm RS iff_trans |
115 in |
135 in |
116 val prove_one_point_all_tac = EVERY1[rtac iff_allI, rtac iffI, tac, tac] |
136 val prove_one_point_all_tac = |
|
137 EVERY1[qcomm_tac allcomm iff_allI,rtac iff_allI, rtac iffI, tac, tac] |
117 end |
138 end |
118 |
139 |
119 fun rearrange_all sg _ (F as all $ Abs(x,T, P)) = |
140 fun renumber l u (Bound i) = Bound(if i < l orelse i > u then i else |
120 (case extract_imp P of |
141 if i=u then l else i+1) |
|
142 | renumber l u (s$t) = renumber l u s $ renumber l u t |
|
143 | renumber l u (Abs(x,T,t)) = Abs(x,T,renumber (l+1) (u+1) t) |
|
144 | renumber _ _ atom = atom; |
|
145 |
|
146 fun quantify qC x T xs P = |
|
147 let fun quant [] P = P |
|
148 | quant ((qC,x,T)::xs) P = quant xs (qC $ Abs(x,T,P)) |
|
149 val n = length xs |
|
150 val Q = if n=0 then P else renumber 0 n P |
|
151 in quant xs (qC $ Abs(x,T,Q)) end; |
|
152 |
|
153 fun rearrange_all sg _ (F as (all as Const(q,_)) $ Abs(x,T, P)) = |
|
154 (case extract_quant extract_imp q [] P of |
121 None => None |
155 None => None |
122 | Some(eq,Q) => |
156 | Some(xs,eq,Q) => |
123 let val R = imp $ eq $ Q |
157 let val R = quantify all x T xs (imp $ eq $ Q) |
124 in Some(prove_conv prove_one_point_all_tac sg (F,all$Abs(x,T,R))) end) |
158 in Some(prove_conv prove_one_point_all_tac sg (F,R)) end) |
125 | rearrange_all _ _ _ = None; |
159 | rearrange_all _ _ _ = None; |
126 |
160 |
127 fun rearrange_ball tac sg _ (F as Ball $ A $ Abs(x,T,P)) = |
161 fun rearrange_ball tac sg _ (F as Ball $ A $ Abs(x,T,P)) = |
128 (case extract_imp P of |
162 (case extract_imp [] P of |
129 None => None |
163 None => None |
130 | Some(eq,Q) => |
164 | Some(xs,eq,Q) => if not(null xs) then None else |
131 let val R = imp $ eq $ Q |
165 let val R = imp $ eq $ Q |
132 in Some(prove_conv tac sg (F,Ball $ A $ Abs(x,T,R))) end) |
166 in Some(prove_conv tac sg (F,Ball $ A $ Abs(x,T,R))) end) |
133 | rearrange_ball _ _ _ _ = None; |
167 | rearrange_ball _ _ _ _ = None; |
134 |
168 |
135 fun rearrange_ex sg _ (F as ex $ Abs(x,T,P)) = |
169 fun rearrange_ex sg _ (F as (ex as Const(q,_)) $ Abs(x,T,P)) = |
136 (case extract_conj P of |
170 (case extract_quant extract_conj q [] P of |
137 None => None |
171 None => None |
138 | Some(eq,Q) => |
172 | Some(xs,eq,Q) => |
139 Some(prove_conv prove_one_point_ex_tac sg (F,ex $ Abs(x,T,conj$eq$Q)))) |
173 let val R = quantify ex x T xs (conj $ eq $ Q) |
|
174 in Some(prove_conv prove_one_point_ex_tac sg (F,R)) end) |
140 | rearrange_ex _ _ _ = None; |
175 | rearrange_ex _ _ _ = None; |
141 |
176 |
142 fun rearrange_bex tac sg _ (F as Bex $ A $ Abs(x,T,P)) = |
177 fun rearrange_bex tac sg _ (F as Bex $ A $ Abs(x,T,P)) = |
143 (case extract_conj P of |
178 (case extract_conj [] P of |
144 None => None |
179 None => None |
145 | Some(eq,Q) => |
180 | Some(xs,eq,Q) => if not(null xs) then None else |
146 Some(prove_conv tac sg (F,Bex $ A $ Abs(x,T,conj$eq$Q)))) |
181 Some(prove_conv tac sg (F,Bex $ A $ Abs(x,T,conj$eq$Q)))) |
147 | rearrange_bex _ _ _ _ = None; |
182 | rearrange_bex _ _ _ _ = None; |
148 |
183 |
149 end; |
184 end; |