36 end |
36 end |
37 |
37 |
38 structure ScnpReconstruct : SCNP_RECONSTRUCT = |
38 structure ScnpReconstruct : SCNP_RECONSTRUCT = |
39 struct |
39 struct |
40 |
40 |
41 val PROFILE = FundefCommon.PROFILE |
41 val PROFILE = Function_Common.PROFILE |
42 fun TRACE x = if ! FundefCommon.profile then tracing x else () |
42 fun TRACE x = if ! Function_Common.profile then tracing x else () |
43 |
43 |
44 open ScnpSolve |
44 open ScnpSolve |
45 |
45 |
46 val natT = HOLogic.natT |
46 val natT = HOLogic.natT |
47 val nat_pairT = HOLogic.mk_prodT (natT, natT) |
47 val nat_pairT = HOLogic.mk_prodT (natT, natT) |
62 wmsI2'' : thm, |
62 wmsI2'' : thm, |
63 wmsI1 : thm, |
63 wmsI1 : thm, |
64 reduction_pair : thm |
64 reduction_pair : thm |
65 } |
65 } |
66 |
66 |
67 structure MultisetSetup = TheoryDataFun |
67 structure Multiset_Setup = TheoryDataFun |
68 ( |
68 ( |
69 type T = multiset_setup option |
69 type T = multiset_setup option |
70 val empty = NONE |
70 val empty = NONE |
71 val copy = I; |
71 val copy = I; |
72 val extend = I; |
72 val extend = I; |
73 fun merge _ (v1, v2) = if is_some v2 then v2 else v1 |
73 fun merge _ (v1, v2) = if is_some v2 then v2 else v1 |
74 ) |
74 ) |
75 |
75 |
76 val multiset_setup = MultisetSetup.put o SOME |
76 val multiset_setup = Multiset_Setup.put o SOME |
77 |
77 |
78 fun undef x = error "undef" |
78 fun undef x = error "undef" |
79 fun get_multiset_setup thy = MultisetSetup.get thy |
79 fun get_multiset_setup thy = Multiset_Setup.get thy |
80 |> the_default (Multiset |
80 |> the_default (Multiset |
81 { msetT = undef, mk_mset=undef, |
81 { msetT = undef, mk_mset=undef, |
82 mset_regroup_conv=undef, mset_member_tac = undef, |
82 mset_regroup_conv=undef, mset_member_tac = undef, |
83 mset_nonempty_tac = undef, mset_pwleq_tac = undef, |
83 mset_nonempty_tac = undef, mset_pwleq_tac = undef, |
84 set_of_simps = [],reduction_pair = refl, |
84 set_of_simps = [],reduction_pair = refl, |
285 map_index pt_lev lev |
285 map_index pt_lev lev |
286 |> Termination.mk_sumcases D (setT nat_pairT) |
286 |> Termination.mk_sumcases D (setT nat_pairT) |
287 |> cterm_of thy |
287 |> cterm_of thy |
288 in |
288 in |
289 PROFILE "Proof Reconstruction" |
289 PROFILE "Proof Reconstruction" |
290 (CONVERSION (Conv.arg_conv (Conv.arg_conv (FundefLib.regroup_union_conv sl))) 1 |
290 (CONVERSION (Conv.arg_conv (Conv.arg_conv (Function_Lib.regroup_union_conv sl))) 1 |
291 THEN (rtac @{thm reduction_pair_lemma} 1) |
291 THEN (rtac @{thm reduction_pair_lemma} 1) |
292 THEN (rtac @{thm rp_inv_image_rp} 1) |
292 THEN (rtac @{thm rp_inv_image_rp} 1) |
293 THEN (rtac (order_rpair ms_rp label) 1) |
293 THEN (rtac (order_rpair ms_rp label) 1) |
294 THEN PRIMITIVE (instantiate' [] [SOME level_mapping]) |
294 THEN PRIMITIVE (instantiate' [] [SOME level_mapping]) |
295 THEN unfold_tac @{thms rp_inv_image_def} (simpset_of ctxt) |
295 THEN unfold_tac @{thms rp_inv_image_def} (simpset_of ctxt) |
348 end |
348 end |
349 |
349 |
350 |
350 |
351 fun single_scnp_tac use_tags orders ctxt cont err_cont D = Termination.CALLS (fn (cs, i) => |
351 fun single_scnp_tac use_tags orders ctxt cont err_cont D = Termination.CALLS (fn (cs, i) => |
352 let |
352 let |
353 val ms_configured = is_some (MultisetSetup.get (ProofContext.theory_of ctxt)) |
353 val ms_configured = is_some (Multiset_Setup.get (ProofContext.theory_of ctxt)) |
354 val orders' = if ms_configured then orders |
354 val orders' = if ms_configured then orders |
355 else filter_out (curry op = MS) orders |
355 else filter_out (curry op = MS) orders |
356 val gp = gen_probl D cs |
356 val gp = gen_probl D cs |
357 (* val _ = TRACE ("SCNP instance: " ^ makestring gp)*) |
357 (* val _ = TRACE ("SCNP instance: " ^ makestring gp)*) |
358 val certificate = generate_certificate use_tags orders' gp |
358 val certificate = generate_certificate use_tags orders' gp |
393 in |
393 in |
394 TERMINATION ctxt (strategy err_cont err_cont) |
394 TERMINATION ctxt (strategy err_cont err_cont) |
395 end |
395 end |
396 |
396 |
397 fun gen_sizechange_tac orders autom_tac ctxt err_cont = |
397 fun gen_sizechange_tac orders autom_tac ctxt err_cont = |
398 TRY (FundefCommon.apply_termination_rule ctxt 1) |
398 TRY (Function_Common.apply_termination_rule ctxt 1) |
399 THEN TRY (Termination.wf_union_tac ctxt) |
399 THEN TRY (Termination.wf_union_tac ctxt) |
400 THEN |
400 THEN |
401 (rtac @{thm wf_empty} 1 |
401 (rtac @{thm wf_empty} 1 |
402 ORELSE gen_decomp_scnp_tac orders autom_tac ctxt err_cont 1) |
402 ORELSE gen_decomp_scnp_tac orders autom_tac ctxt err_cont 1) |
403 |
403 |
404 fun sizechange_tac ctxt autom_tac = |
404 fun sizechange_tac ctxt autom_tac = |
405 gen_sizechange_tac [MAX, MS, MIN] autom_tac ctxt (K (K all_tac)) |
405 gen_sizechange_tac [MAX, MS, MIN] autom_tac ctxt (K (K all_tac)) |
406 |
406 |
407 fun decomp_scnp orders ctxt = |
407 fun decomp_scnp orders ctxt = |
408 let |
408 let |
409 val extra_simps = FundefCommon.Termination_Simps.get ctxt |
409 val extra_simps = Function_Common.Termination_Simps.get ctxt |
410 val autom_tac = auto_tac (clasimpset_of ctxt addsimps2 extra_simps) |
410 val autom_tac = auto_tac (clasimpset_of ctxt addsimps2 extra_simps) |
411 in |
411 in |
412 SIMPLE_METHOD |
412 SIMPLE_METHOD |
413 (gen_sizechange_tac orders autom_tac ctxt (print_error ctxt)) |
413 (gen_sizechange_tac orders autom_tac ctxt (print_error ctxt)) |
414 end |
414 end |