src/HOL/Tools/function_package/scnp_reconstruct.ML
changeset 29877 867a0ed7a9b2
parent 29183 f1648e009dc1
child 30304 d8e4cd2ac2a1
equal deleted inserted replaced
29876:68e9a8d97475 29877:867a0ed7a9b2
     5 Proof reconstruction for SCNP
     5 Proof reconstruction for SCNP
     6 *)
     6 *)
     7 
     7 
     8 signature SCNP_RECONSTRUCT =
     8 signature SCNP_RECONSTRUCT =
     9 sig
     9 sig
       
    10 
       
    11   val sizechange_tac : Proof.context -> tactic -> tactic
    10 
    12 
    11   val decomp_scnp : ScnpSolve.label list -> Proof.context -> method
    13   val decomp_scnp : ScnpSolve.label list -> Proof.context -> method
    12 
    14 
    13   val setup : theory -> theory
    15   val setup : theory -> theory
    14 
    16 
   350 end
   352 end
   351 
   353 
   352 
   354 
   353 fun single_scnp_tac use_tags orders ctxt cont err_cont D = Termination.CALLS (fn (cs, i) =>
   355 fun single_scnp_tac use_tags orders ctxt cont err_cont D = Termination.CALLS (fn (cs, i) =>
   354   let
   356   let
       
   357     val ms_configured = is_some (MultisetSetup.get (ProofContext.theory_of ctxt))
       
   358     val orders' = if ms_configured then orders
       
   359                   else filter_out (curry op = MS) orders
   355     val gp = gen_probl D cs
   360     val gp = gen_probl D cs
   356 (*    val _ = TRACE ("SCNP instance: " ^ makestring gp)*)
   361 (*    val _ = TRACE ("SCNP instance: " ^ makestring gp)*)
   357     val certificate = generate_certificate use_tags orders gp
   362     val certificate = generate_certificate use_tags orders' gp
   358 (*    val _ = TRACE ("Certificate: " ^ makestring certificate)*)
   363 (*    val _ = TRACE ("Certificate: " ^ makestring certificate)*)
   359 
   364 
   360     val ms_configured = is_some (MultisetSetup.get (ProofContext.theory_of ctxt))
   365   in
   361     in
       
   362     case certificate
   366     case certificate
   363      of NONE => err_cont D i
   367      of NONE => err_cont D i
   364       | SOME cert =>
   368       | SOME cert =>
   365         if not ms_configured andalso #1 cert = MS
   369           SELECT_GOAL (reconstruct_tac ctxt D cs gp cert) i
   366         then err_cont D i
   370           THEN (rtac @{thm wf_empty} i ORELSE cont D i)
   367         else SELECT_GOAL (reconstruct_tac ctxt D cs gp cert) i
       
   368              THEN (rtac @{thm wf_empty} i ORELSE cont D i)
       
   369   end)
   371   end)
   370 
   372 
   371 fun decomp_scnp_tac orders autom_tac ctxt err_cont =
   373 fun gen_decomp_scnp_tac orders autom_tac ctxt err_cont =
   372   let
   374   let
   373     open Termination
   375     open Termination
   374     val derive_diag = Descent.derive_diag ctxt autom_tac
   376     val derive_diag = Descent.derive_diag ctxt autom_tac
   375     val derive_all = Descent.derive_all ctxt autom_tac
   377     val derive_all = Descent.derive_all ctxt autom_tac
   376     val decompose = Decompose.decompose_tac ctxt autom_tac
   378     val decompose = Decompose.decompose_tac ctxt autom_tac
   394 
   396 
   395   in
   397   in
   396     TERMINATION ctxt (strategy err_cont err_cont)
   398     TERMINATION ctxt (strategy err_cont err_cont)
   397   end
   399   end
   398 
   400 
       
   401 fun gen_sizechange_tac orders autom_tac ctxt err_cont =
       
   402   TRY (FundefCommon.apply_termination_rule ctxt 1)
       
   403   THEN TRY Termination.wf_union_tac
       
   404   THEN
       
   405    (rtac @{thm wf_empty} 1
       
   406     ORELSE gen_decomp_scnp_tac orders autom_tac ctxt err_cont 1)
       
   407 
       
   408 fun sizechange_tac ctxt autom_tac =
       
   409   gen_sizechange_tac [MAX, MS, MIN] autom_tac ctxt (K (K all_tac))
       
   410 
   399 fun decomp_scnp orders ctxt =
   411 fun decomp_scnp orders ctxt =
   400   let
   412   let
   401     val extra_simps = FundefCommon.TerminationSimps.get ctxt
   413     val extra_simps = FundefCommon.TerminationSimps.get ctxt
   402     val autom_tac = auto_tac (local_clasimpset_of ctxt addsimps2 extra_simps)
   414     val autom_tac = auto_tac (local_clasimpset_of ctxt addsimps2 extra_simps)
   403   in
   415   in
   404     Method.SIMPLE_METHOD
   416     Method.SIMPLE_METHOD
   405       (TRY (FundefCommon.apply_termination_rule ctxt 1)
   417       (gen_sizechange_tac orders autom_tac ctxt (print_error ctxt))
   406        THEN TRY Termination.wf_union_tac
       
   407        THEN
       
   408          (rtac @{thm wf_empty} 1
       
   409           ORELSE decomp_scnp_tac orders autom_tac ctxt (print_error ctxt) 1))
       
   410   end
   418   end
   411 
   419 
   412 
   420 
   413 (* Method setup *)
   421 (* Method setup *)
   414 
   422