TFL/tfl.ML
changeset 14240 d3843feb9de7
parent 14219 9fdea25f9ebb
child 14820 3f80d6510ee9
equal deleted inserted replaced
14239:af2a9e68bea9 14240:d3843feb9de7
     7 *)
     7 *)
     8 
     8 
     9 signature PRIM =
     9 signature PRIM =
    10 sig
    10 sig
    11   val trace: bool ref
    11   val trace: bool ref
       
    12   val trace_thms: string -> thm list -> unit
       
    13   val trace_cterms: string -> cterm list -> unit
    12   type pattern
    14   type pattern
    13   val mk_functional: theory -> term list -> {functional: term, pats: pattern list}
    15   val mk_functional: theory -> term list -> {functional: term, pats: pattern list}
    14   val wfrec_definition0: theory -> string -> term -> term -> theory * thm
    16   val wfrec_definition0: theory -> string -> term -> term -> theory * thm
    15   val post_definition: thm list -> theory * (thm * pattern list) ->
    17   val post_definition: thm list -> theory * (thm * pattern list) ->
    16    {theory: theory,
    18    {theory: theory,
   912  *---------------------------------------------------------------------------*)
   914  *---------------------------------------------------------------------------*)
   913 fun elim_tc tcthm (rule,induction) =
   915 fun elim_tc tcthm (rule,induction) =
   914    (R.MP rule tcthm, R.PROVE_HYP tcthm induction)
   916    (R.MP rule tcthm, R.PROVE_HYP tcthm induction)
   915 
   917 
   916 
   918 
       
   919 fun trace_thms s L =
       
   920   if !trace then writeln (cat_lines (s :: map string_of_thm L))
       
   921   else ();
       
   922 
       
   923 fun trace_cterms s L =
       
   924   if !trace then writeln (cat_lines (s :: map string_of_cterm L))
       
   925   else ();;
       
   926 
       
   927 
   917 fun postprocess strict {wf_tac, terminator, simplifier} theory {rules,induction,TCs} =
   928 fun postprocess strict {wf_tac, terminator, simplifier} theory {rules,induction,TCs} =
   918 let val tych = Thry.typecheck theory
   929 let val tych = Thry.typecheck theory
   919     val prove = R.prove strict;
   930     val prove = R.prove strict;
   920 
   931 
   921    (*---------------------------------------------------------------------
   932    (*---------------------------------------------------------------------
   935     *   1. if |- tc = T, then eliminate it with eqT; otherwise,
   946     *   1. if |- tc = T, then eliminate it with eqT; otherwise,
   936     *   2. apply the terminator to tc'. If |- tc' = T then eliminate; else
   947     *   2. apply the terminator to tc'. If |- tc' = T then eliminate; else
   937     *   3. replace tc by tc' in both the rules and the induction theorem.
   948     *   3. replace tc by tc' in both the rules and the induction theorem.
   938     *---------------------------------------------------------------------*)
   949     *---------------------------------------------------------------------*)
   939 
   950 
   940    fun print_thms s L =
       
   941      if !trace then writeln (cat_lines (s :: map string_of_thm L))
       
   942      else ();
       
   943 
       
   944    fun print_cterms s L =
       
   945      if !trace then writeln (cat_lines (s :: map string_of_cterm L))
       
   946      else ();;
       
   947 
       
   948    fun simplify_tc tc (r,ind) =
   951    fun simplify_tc tc (r,ind) =
   949        let val tc1 = tych tc
   952        let val tc1 = tych tc
   950            val _ = print_cterms "TC before simplification: " [tc1]
   953            val _ = trace_cterms "TC before simplification: " [tc1]
   951            val tc_eq = simplifier tc1
   954            val tc_eq = simplifier tc1
   952            val _ = print_thms "result: " [tc_eq]
   955            val _ = trace_thms "result: " [tc_eq]
   953        in
   956        in
   954        elim_tc (R.MATCH_MP Thms.eqT tc_eq) (r,ind)
   957        elim_tc (R.MATCH_MP Thms.eqT tc_eq) (r,ind)
   955        handle U.ERR _ =>
   958        handle U.ERR _ =>
   956         (elim_tc (R.MATCH_MP(R.MATCH_MP Thms.rev_eq_mp tc_eq)
   959         (elim_tc (R.MATCH_MP(R.MATCH_MP Thms.rev_eq_mp tc_eq)
   957                   (prove(tych(HOLogic.mk_Trueprop(S.rhs(concl tc_eq))),
   960                   (prove(tych(HOLogic.mk_Trueprop(S.rhs(concl tc_eq))),