1715 let |
1715 let |
1716 val (out_ts'', (names', eqs')) = |
1716 val (out_ts'', (names', eqs')) = |
1717 fold_map (collect_non_invertible_subterms ctxt) out_ts' (names, []); |
1717 fold_map (collect_non_invertible_subterms ctxt) out_ts' (names, []); |
1718 val (out_ts''', (names'', constr_vs)) = fold_map distinct_v |
1718 val (out_ts''', (names'', constr_vs)) = fold_map distinct_v |
1719 out_ts'' (names', map (rpair []) vs); |
1719 out_ts'' (names', map (rpair []) vs); |
|
1720 val processed_out_ts = map (compile_arg compilation_modifiers additional_arguments |
|
1721 ctxt param_modes) out_ts |
1720 in |
1722 in |
1721 compile_match constr_vs (eqs @ eqs') out_ts''' |
1723 compile_match constr_vs (eqs @ eqs') out_ts''' |
1722 (mk_single compfuns (HOLogic.mk_tuple out_ts)) |
1724 (mk_single compfuns (HOLogic.mk_tuple processed_out_ts)) |
1723 end |
1725 end |
1724 | compile_prems out_ts vs names ((p, deriv) :: ps) = |
1726 | compile_prems out_ts vs names ((p, deriv) :: ps) = |
1725 let |
1727 let |
1726 val vs' = distinct (op =) (flat (vs :: map term_vs out_ts)); |
1728 val vs' = distinct (op =) (flat (vs :: map term_vs out_ts)); |
1727 val (out_ts', (names', eqs)) = |
1729 val (out_ts', (names', eqs)) = |
2272 | valid_expr _ = false |
2274 | valid_expr _ = false |
2273 in |
2275 in |
2274 if valid_expr expr then |
2276 if valid_expr expr then |
2275 ((*tracing "expression is valid";*) Seq.single st) |
2277 ((*tracing "expression is valid";*) Seq.single st) |
2276 else |
2278 else |
2277 ((*tracing "expression is not valid";*) Seq.empty) (*error "check_format: wrong format"*) |
2279 ((*tracing "expression is not valid";*) Seq.empty) (* error "check_format: wrong format" *) |
2278 end |
2280 end |
2279 |
2281 |
2280 fun prove_match options ctxt out_ts = |
2282 fun prove_match options ctxt nargs out_ts = |
2281 let |
2283 let |
2282 val thy = ProofContext.theory_of ctxt |
2284 val thy = ProofContext.theory_of ctxt |
|
2285 val eval_if_P = |
|
2286 @{lemma "P ==> Predicate.eval x z ==> Predicate.eval (if P then x else y) z" by simp} |
2283 fun get_case_rewrite t = |
2287 fun get_case_rewrite t = |
2284 if (is_constructor thy t) then let |
2288 if (is_constructor thy t) then let |
2285 val case_rewrites = (#case_rewrites (Datatype.the_info thy |
2289 val case_rewrites = (#case_rewrites (Datatype.the_info thy |
2286 ((fst o dest_Type o fastype_of) t))) |
2290 ((fst o dest_Type o fastype_of) t))) |
2287 in fold (union Thm.eq_thm) (case_rewrites :: map get_case_rewrite (snd (strip_comb t))) [] end |
2291 in fold (union Thm.eq_thm) (case_rewrites :: map get_case_rewrite (snd (strip_comb t))) [] end |
2291 (* replace TRY by determining if it necessary - are there equations when calling compile match? *) |
2295 (* replace TRY by determining if it necessary - are there equations when calling compile match? *) |
2292 in |
2296 in |
2293 (* make this simpset better! *) |
2297 (* make this simpset better! *) |
2294 asm_full_simp_tac (HOL_basic_ss' addsimps simprules) 1 |
2298 asm_full_simp_tac (HOL_basic_ss' addsimps simprules) 1 |
2295 THEN print_tac options "after prove_match:" |
2299 THEN print_tac options "after prove_match:" |
2296 THEN (DETERM (TRY (EqSubst.eqsubst_tac ctxt [0] [@{thm HOL.if_P}] 1 |
2300 THEN (DETERM (TRY (rtac eval_if_P 1 |
2297 THEN (REPEAT_DETERM (rtac @{thm conjI} 1 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1)))) |
2301 THEN (REPEAT_DETERM (rtac @{thm conjI} 1 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1)))) |
2298 THEN print_tac options "if condition to be solved:" |
2302 THEN print_tac options "if condition to be solved:" |
2299 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1 THEN print_tac options "after if simp; in SOLVED:")) |
2303 THEN (SOLVED (asm_simp_tac HOL_basic_ss' 1 |
|
2304 THEN Subgoal.FOCUS_PREMS |
|
2305 (fn {context = ctxt, params = params, prems, asms, concl, schematics} => |
|
2306 let |
|
2307 val prems' = maps dest_conjunct_prem (take nargs prems) |
|
2308 in |
|
2309 MetaSimplifier.rewrite_goal_tac |
|
2310 (map (fn th => th RS @{thm sym} RS @{thm eq_reflection}) prems') 1 |
|
2311 end) ctxt 1 |
|
2312 THEN REPEAT_DETERM (rtac @{thm refl} 1) |
|
2313 THEN print_tac options "after if simp; in SOLVED:")) |
2300 THEN check_format thy |
2314 THEN check_format thy |
2301 THEN print_tac options "after if simplification - a TRY block"))) |
2315 THEN print_tac options "after if simplification - a TRY block"))) |
2302 THEN print_tac options "after if simplification" |
2316 THEN print_tac options "after if simplification" |
2303 end; |
2317 end; |
2304 |
2318 |
2324 |
2338 |
2325 fun prove_clause options ctxt nargs mode (_, clauses) (ts, moded_ps) = |
2339 fun prove_clause options ctxt nargs mode (_, clauses) (ts, moded_ps) = |
2326 let |
2340 let |
2327 val (in_ts, clause_out_ts) = split_mode mode ts; |
2341 val (in_ts, clause_out_ts) = split_mode mode ts; |
2328 fun prove_prems out_ts [] = |
2342 fun prove_prems out_ts [] = |
2329 (prove_match options ctxt out_ts) |
2343 (prove_match options ctxt nargs out_ts) |
2330 THEN print_tac options "before simplifying assumptions" |
2344 THEN print_tac options "before simplifying assumptions" |
2331 THEN asm_full_simp_tac HOL_basic_ss' 1 |
2345 THEN asm_full_simp_tac HOL_basic_ss' 1 |
2332 THEN print_tac options "before single intro rule" |
2346 THEN print_tac options "before single intro rule" |
|
2347 THEN Subgoal.FOCUS_PREMS |
|
2348 (fn {context = ctxt, params = params, prems, asms, concl, schematics} => |
|
2349 let |
|
2350 val prems' = maps dest_conjunct_prem (take nargs prems) |
|
2351 in |
|
2352 MetaSimplifier.rewrite_goal_tac |
|
2353 (map (fn th => th RS @{thm sym} RS @{thm eq_reflection}) prems') 1 |
|
2354 end) ctxt 1 |
2333 THEN (rtac (if null clause_out_ts then @{thm singleI_unit} else @{thm singleI}) 1) |
2355 THEN (rtac (if null clause_out_ts then @{thm singleI_unit} else @{thm singleI}) 1) |
2334 | prove_prems out_ts ((p, deriv) :: ps) = |
2356 | prove_prems out_ts ((p, deriv) :: ps) = |
2335 let |
2357 let |
2336 val premposition = (find_index (equal p) clauses) + nargs |
2358 val premposition = (find_index (equal p) clauses) + nargs |
2337 val mode = head_mode_of deriv |
2359 val mode = head_mode_of deriv |
2386 rtac @{thm if_predI} 1 |
2408 rtac @{thm if_predI} 1 |
2387 THEN print_tac options "before sidecond:" |
2409 THEN print_tac options "before sidecond:" |
2388 THEN prove_sidecond ctxt t |
2410 THEN prove_sidecond ctxt t |
2389 THEN print_tac options "after sidecond:" |
2411 THEN print_tac options "after sidecond:" |
2390 THEN prove_prems [] ps) |
2412 THEN prove_prems [] ps) |
2391 in (prove_match options ctxt out_ts) |
2413 in (prove_match options ctxt nargs out_ts) |
2392 THEN rest_tac |
2414 THEN rest_tac |
2393 end; |
2415 end; |
2394 val prems_tac = prove_prems in_ts moded_ps |
2416 val prems_tac = prove_prems in_ts moded_ps |
2395 in |
2417 in |
2396 print_tac options "Proving clause..." |
2418 print_tac options "Proving clause..." |