53 RSN (2, rev_mp)); |
53 RSN (2, rev_mp)); |
54 in |
54 in |
55 Goal.prove_sorry_global thy [] |
55 Goal.prove_sorry_global thy [] |
56 (Logic.strip_imp_prems t) |
56 (Logic.strip_imp_prems t) |
57 (Logic.strip_imp_concl t) |
57 (Logic.strip_imp_concl t) |
58 (fn {prems, ...} => |
58 (fn {context = ctxt, prems, ...} => |
59 EVERY |
59 EVERY |
60 [resolve_tac [induct'] 1, |
60 [resolve_tac ctxt [induct'] 1, |
61 REPEAT (resolve_tac [TrueI] 1), |
61 REPEAT (resolve_tac ctxt [TrueI] 1), |
62 REPEAT ((resolve_tac [impI] 1) THEN (eresolve_tac prems 1)), |
62 REPEAT ((resolve_tac ctxt [impI] 1) THEN (eresolve_tac ctxt prems 1)), |
63 REPEAT (resolve_tac [TrueI] 1)]) |
63 REPEAT (resolve_tac ctxt [TrueI] 1)]) |
64 end; |
64 end; |
65 |
65 |
66 val casedist_thms = |
66 val casedist_thms = |
67 map_index prove_casedist_thm (newTs ~~ Old_Datatype_Prop.make_casedists descr); |
67 map_index prove_casedist_thm (newTs ~~ Old_Datatype_Prop.make_casedists descr); |
68 in |
68 in |
174 let |
174 let |
175 val k = length (filter Old_Datatype_Aux.is_rec_type cargs); |
175 val k = length (filter Old_Datatype_Aux.is_rec_type cargs); |
176 in |
176 in |
177 (EVERY |
177 (EVERY |
178 [DETERM tac, |
178 [DETERM tac, |
179 REPEAT (eresolve_tac @{thms ex1E} 1), resolve_tac @{thms ex1I} 1, |
179 REPEAT (eresolve_tac ctxt @{thms ex1E} 1), resolve_tac ctxt @{thms ex1I} 1, |
180 DEPTH_SOLVE_1 (ares_tac [intr] 1), |
180 DEPTH_SOLVE_1 (ares_tac [intr] 1), |
181 REPEAT_DETERM_N k (eresolve_tac [thin_rl] 1 THEN rotate_tac 1 1), |
181 REPEAT_DETERM_N k (eresolve_tac ctxt [thin_rl] 1 THEN rotate_tac 1 1), |
182 eresolve_tac [elim] 1, |
182 eresolve_tac ctxt [elim] 1, |
183 REPEAT_DETERM_N j distinct_tac, |
183 REPEAT_DETERM_N j distinct_tac, |
184 TRY (dresolve_tac inject 1), |
184 TRY (dresolve_tac ctxt inject 1), |
185 REPEAT (eresolve_tac [conjE] 1), hyp_subst_tac ctxt 1, |
185 REPEAT (eresolve_tac ctxt [conjE] 1), hyp_subst_tac ctxt 1, |
186 REPEAT (EVERY [eresolve_tac [allE] 1, dresolve_tac [mp] 1, assume_tac ctxt 1]), |
186 REPEAT |
|
187 (EVERY [eresolve_tac ctxt [allE] 1, dresolve_tac ctxt [mp] 1, assume_tac ctxt 1]), |
187 TRY (hyp_subst_tac ctxt 1), |
188 TRY (hyp_subst_tac ctxt 1), |
188 resolve_tac [refl] 1, |
189 resolve_tac ctxt [refl] 1, |
189 REPEAT_DETERM_N (n - j - 1) distinct_tac], |
190 REPEAT_DETERM_N (n - j - 1) distinct_tac], |
190 intrs, j + 1) |
191 intrs, j + 1) |
191 end; |
192 end; |
192 |
193 |
193 val (tac', intrs', _) = |
194 val (tac', intrs', _) = |
209 in |
210 in |
210 Old_Datatype_Aux.split_conj_thm (Goal.prove_sorry_global thy1 [] [] |
211 Old_Datatype_Aux.split_conj_thm (Goal.prove_sorry_global thy1 [] [] |
211 (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj rec_unique_ts)) |
212 (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj rec_unique_ts)) |
212 (fn {context = ctxt, ...} => |
213 (fn {context = ctxt, ...} => |
213 #1 (fold (mk_unique_tac ctxt) (descr' ~~ rec_elims ~~ recTs ~~ rec_result_Ts) |
214 #1 (fold (mk_unique_tac ctxt) (descr' ~~ rec_elims ~~ recTs ~~ rec_result_Ts) |
214 (((resolve_tac [induct'] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1 THEN |
215 (((resolve_tac ctxt [induct'] THEN_ALL_NEW Object_Logic.atomize_prems_tac ctxt) 1 THEN |
215 rewrite_goals_tac ctxt [mk_meta_eq @{thm choice_eq}], rec_intrs))))) |
216 rewrite_goals_tac ctxt [mk_meta_eq @{thm choice_eq}], rec_intrs))))) |
216 end; |
217 end; |
217 |
218 |
218 val rec_total_thms = map (fn r => r RS @{thm theI'}) rec_unique_thms; |
219 val rec_total_thms = map (fn r => r RS @{thm theI'}) rec_unique_thms; |
219 |
220 |
252 val rec_thms = |
253 val rec_thms = |
253 map (fn t => |
254 map (fn t => |
254 Goal.prove_sorry_global thy2 [] [] t |
255 Goal.prove_sorry_global thy2 [] [] t |
255 (fn {context = ctxt, ...} => EVERY |
256 (fn {context = ctxt, ...} => EVERY |
256 [rewrite_goals_tac ctxt reccomb_defs, |
257 [rewrite_goals_tac ctxt reccomb_defs, |
257 resolve_tac @{thms the1_equality} 1, |
258 resolve_tac ctxt @{thms the1_equality} 1, |
258 resolve_tac rec_unique_thms 1, |
259 resolve_tac ctxt rec_unique_thms 1, |
259 resolve_tac rec_intrs 1, |
260 resolve_tac ctxt rec_intrs 1, |
260 REPEAT (resolve_tac [allI] 1 ORELSE resolve_tac rec_total_thms 1)])) |
261 REPEAT (resolve_tac ctxt [allI] 1 ORELSE resolve_tac ctxt rec_total_thms 1)])) |
261 (Old_Datatype_Prop.make_primrecs reccomb_names descr thy2); |
262 (Old_Datatype_Prop.make_primrecs reccomb_names descr thy2); |
262 in |
263 in |
263 thy2 |
264 thy2 |
264 |> Sign.add_path (space_implode "_" new_type_names) |
265 |> Sign.add_path (space_implode "_" new_type_names) |
265 |> Global_Theory.note_thmss "" |
266 |> Global_Theory.note_thmss "" |
337 ([], thy1); |
338 ([], thy1); |
338 |
339 |
339 fun prove_case t = |
340 fun prove_case t = |
340 Goal.prove_sorry_global thy2 [] [] t (fn {context = ctxt, ...} => |
341 Goal.prove_sorry_global thy2 [] [] t (fn {context = ctxt, ...} => |
341 EVERY [rewrite_goals_tac ctxt (case_defs @ map mk_meta_eq primrec_thms), |
342 EVERY [rewrite_goals_tac ctxt (case_defs @ map mk_meta_eq primrec_thms), |
342 resolve_tac [refl] 1]); |
343 resolve_tac ctxt [refl] 1]); |
343 |
344 |
344 fun prove_cases (Type (Tcon, _)) ts = |
345 fun prove_cases (Type (Tcon, _)) ts = |
345 (case Ctr_Sugar.ctr_sugar_of ctxt Tcon of |
346 (case Ctr_Sugar.ctr_sugar_of ctxt Tcon of |
346 SOME {case_thms, ...} => case_thms |
347 SOME {case_thms, ...} => case_thms |
347 | NONE => map prove_case ts); |
348 | NONE => map prove_case ts); |
378 let |
379 let |
379 val cert = cterm_of thy; |
380 val cert = cterm_of thy; |
380 val _ $ (_ $ lhs $ _) = hd (Logic.strip_assums_hyp (hd (prems_of exhaustion))); |
381 val _ $ (_ $ lhs $ _) = hd (Logic.strip_assums_hyp (hd (prems_of exhaustion))); |
381 val exhaustion' = cterm_instantiate [(cert lhs, cert (Free ("x", T)))] exhaustion; |
382 val exhaustion' = cterm_instantiate [(cert lhs, cert (Free ("x", T)))] exhaustion; |
382 fun tac ctxt = |
383 fun tac ctxt = |
383 EVERY [resolve_tac [exhaustion'] 1, |
384 EVERY [resolve_tac ctxt [exhaustion'] 1, |
384 ALLGOALS (asm_simp_tac |
385 ALLGOALS (asm_simp_tac |
385 (put_simpset HOL_ss ctxt addsimps (dist_rewrites' @ inject @ case_thms')))]; |
386 (put_simpset HOL_ss ctxt addsimps (dist_rewrites' @ inject @ case_thms')))]; |
386 in |
387 in |
387 (Goal.prove_sorry_global thy [] [] t1 (tac o #context), |
388 (Goal.prove_sorry_global thy [] [] t1 (tac o #context), |
388 Goal.prove_sorry_global thy [] [] t2 (tac o #context)) |
389 Goal.prove_sorry_global thy [] [] t2 (tac o #context)) |
404 |
405 |
405 fun prove_case_cong_weaks new_type_names case_names descr thy = |
406 fun prove_case_cong_weaks new_type_names case_names descr thy = |
406 let |
407 let |
407 fun prove_case_cong_weak t = |
408 fun prove_case_cong_weak t = |
408 Goal.prove_sorry_global thy [] (Logic.strip_imp_prems t) (Logic.strip_imp_concl t) |
409 Goal.prove_sorry_global thy [] (Logic.strip_imp_prems t) (Logic.strip_imp_concl t) |
409 (fn {prems, ...} => EVERY [resolve_tac [hd prems RS arg_cong] 1]); |
410 (fn {context = ctxt, prems, ...} => |
|
411 EVERY [resolve_tac ctxt [hd prems RS arg_cong] 1]); |
410 |
412 |
411 val case_cong_weaks = |
413 val case_cong_weaks = |
412 map prove_case_cong_weak (Old_Datatype_Prop.make_case_cong_weaks case_names descr thy); |
414 map prove_case_cong_weak (Old_Datatype_Prop.make_case_cong_weaks case_names descr thy); |
413 |
415 |
414 in thy |> Old_Datatype_Aux.store_thms "case_cong_weak" new_type_names case_cong_weaks end; |
416 in thy |> Old_Datatype_Aux.store_thms "case_cong_weak" new_type_names case_cong_weaks end; |
422 |
424 |
423 fun prove_nchotomy (t, exhaustion) = |
425 fun prove_nchotomy (t, exhaustion) = |
424 let |
426 let |
425 (* For goal i, select the correct disjunct to attack, then prove it *) |
427 (* For goal i, select the correct disjunct to attack, then prove it *) |
426 fun tac ctxt i 0 = |
428 fun tac ctxt i 0 = |
427 EVERY [TRY (resolve_tac [disjI1] i), hyp_subst_tac ctxt i, |
429 EVERY [TRY (resolve_tac ctxt [disjI1] i), hyp_subst_tac ctxt i, |
428 REPEAT (resolve_tac [exI] i), resolve_tac [refl] i] |
430 REPEAT (resolve_tac ctxt [exI] i), resolve_tac ctxt [refl] i] |
429 | tac ctxt i n = resolve_tac [disjI2] i THEN tac ctxt i (n - 1); |
431 | tac ctxt i n = resolve_tac ctxt [disjI2] i THEN tac ctxt i (n - 1); |
430 in |
432 in |
431 Goal.prove_sorry_global thy [] [] t |
433 Goal.prove_sorry_global thy [] [] t |
432 (fn {context = ctxt, ...} => |
434 (fn {context = ctxt, ...} => |
433 EVERY [resolve_tac [allI] 1, |
435 EVERY [resolve_tac ctxt [allI] 1, |
434 Old_Datatype_Aux.exh_tac ctxt (K exhaustion) 1, |
436 Old_Datatype_Aux.exh_tac ctxt (K exhaustion) 1, |
435 ALLGOALS (fn i => tac ctxt i (i - 1))]) |
437 ALLGOALS (fn i => tac ctxt i (i - 1))]) |
436 end; |
438 end; |
437 |
439 |
438 val nchotomys = |
440 val nchotomys = |
457 val simplify = asm_simp_tac (put_simpset HOL_ss ctxt addsimps (prems @ case_rewrites)) |
459 val simplify = asm_simp_tac (put_simpset HOL_ss ctxt addsimps (prems @ case_rewrites)) |
458 in |
460 in |
459 EVERY [ |
461 EVERY [ |
460 simp_tac (put_simpset HOL_ss ctxt addsimps [hd prems]) 1, |
462 simp_tac (put_simpset HOL_ss ctxt addsimps [hd prems]) 1, |
461 cut_tac nchotomy'' 1, |
463 cut_tac nchotomy'' 1, |
462 REPEAT (eresolve_tac [disjE] 1 THEN REPEAT (eresolve_tac [exE] 1) THEN simplify 1), |
464 REPEAT (eresolve_tac ctxt [disjE] 1 THEN |
463 REPEAT (eresolve_tac [exE] 1) THEN simplify 1 (* Get last disjunct *)] |
465 REPEAT (eresolve_tac ctxt [exE] 1) THEN simplify 1), |
|
466 REPEAT (eresolve_tac ctxt [exE] 1) THEN simplify 1 (* Get last disjunct *)] |
464 end) |
467 end) |
465 end; |
468 end; |
466 |
469 |
467 val case_congs = |
470 val case_congs = |
468 map prove_case_cong |
471 map prove_case_cong |