TFL/post.sml
changeset 6524 13410ecfce0b
parent 6498 1ebbe18fe236
child 6554 5be3f13193d7
equal deleted inserted replaced
6523:c84935821ba0 6524:13410ecfce0b
     7 *)
     7 *)
     8 
     8 
     9 signature TFL = 
     9 signature TFL = 
    10   sig
    10   sig
    11    structure Prim : TFL_sig
    11    structure Prim : TFL_sig
       
    12    val quiet_mode : bool ref
       
    13    val message : string -> unit
    12 
    14 
    13    val tgoalw : theory -> thm list -> thm list -> thm list
    15    val tgoalw : theory -> thm list -> thm list -> thm list
    14    val tgoal: theory -> thm list -> thm list
    16    val tgoal: theory -> thm list -> thm list
    15 
    17 
    16    val std_postprocessor : simpset -> theory 
    18    val std_postprocessor : simpset -> theory 
    40 
    42 
    41 structure Tfl: TFL =
    43 structure Tfl: TFL =
    42 struct
    44 struct
    43  structure Prim = Prim
    45  structure Prim = Prim
    44  structure S = USyntax
    46  structure S = USyntax
       
    47 
       
    48 
       
    49  (* messages *)
       
    50 
       
    51  val quiet_mode = ref false;
       
    52  fun message s = if ! quiet_mode then () else writeln s;
    45 
    53 
    46  val trace = Prim.trace
    54  val trace = Prim.trace
    47 
    55 
    48  (*---------------------------------------------------------------------------
    56  (*---------------------------------------------------------------------------
    49   * Extract termination goals so that they can be put it into a goalstack, or 
    57   * Extract termination goals so that they can be put it into a goalstack, or 
   139 	  (rewrite (map (R.ASSUME o tych) cntxt) (R.SPEC_ALL th)))
   147 	  (rewrite (map (R.ASSUME o tych) cntxt) (R.SPEC_ALL th)))
   140    end
   148    end
   141    val gen_all = S.gen_all
   149    val gen_all = S.gen_all
   142  in
   150  in
   143  fun proof_stage ss theory {f, R, rules, full_pats_TCs, TCs} =
   151  fun proof_stage ss theory {f, R, rules, full_pats_TCs, TCs} =
   144    let val dummy = writeln "Proving induction theorem..  "
   152    let val dummy = message "Proving induction theorem ..."
   145        val ind = Prim.mk_induction theory 
   153        val ind = Prim.mk_induction theory 
   146                     {fconst=f, R=R, SV=[], pat_TCs_list=full_pats_TCs}
   154                     {fconst=f, R=R, SV=[], pat_TCs_list=full_pats_TCs}
   147        val dummy = writeln "Proved induction theorem.\nPostprocessing..  "
   155        val dummy = (message "Proved induction theorem."; message "Postprocessing ...");
   148        val {rules, induction, nested_tcs} = 
   156        val {rules, induction, nested_tcs} = 
   149 	   std_postprocessor ss theory {rules=rules, induction=ind, TCs=TCs}
   157 	   std_postprocessor ss theory {rules=rules, induction=ind, TCs=TCs}
   150    in
   158    in
   151    case nested_tcs
   159    case nested_tcs
   152    of [] => (writeln "Postprocessing done.";
   160    of [] => (message "Postprocessing done.";
   153 	     {induction=induction, rules=rules,tcs=[]})
   161 	     {induction=induction, rules=rules,tcs=[]})
   154    | L  => let val dummy = writeln "Simplifying nested TCs..  "
   162    | L  => let val dummy = message "Simplifying nested TCs ..."
   155 	       val (solved,simplified,stubborn) =
   163 	       val (solved,simplified,stubborn) =
   156 		U.itlist (fn th => fn (So,Si,St) =>
   164 		U.itlist (fn th => fn (So,Si,St) =>
   157 		      if (id_thm th) then (So, Si, th::St) else
   165 		      if (id_thm th) then (So, Si, th::St) else
   158 		      if (solved th) then (th::So, Si, St) 
   166 		      if (solved th) then (th::So, Si, St) 
   159 		      else (So, th::Si, St)) nested_tcs ([],[],[])
   167 		      else (So, th::Si, St)) nested_tcs ([],[],[])
   160 	       val simplified' = map join_assums simplified
   168 	       val simplified' = map join_assums simplified
   161 	       val rewr = full_simplify (ss addsimps (solved @ simplified'));
   169 	       val rewr = full_simplify (ss addsimps (solved @ simplified'));
   162 	       val induction' = rewr induction
   170 	       val induction' = rewr induction
   163 	       and rules'     = rewr rules
   171 	       and rules'     = rewr rules
   164 	       val dummy = writeln "Postprocessing done."
   172 	       val dummy = message "Postprocessing done."
   165 	   in
   173 	   in
   166 	   {induction = induction',
   174 	   {induction = induction',
   167 		rules = rules',
   175 		rules = rules',
   168 		  tcs = map (gen_all o S.rhs o #2 o S.strip_forall o concl)
   176 		  tcs = map (gen_all o S.rhs o #2 o S.strip_forall o concl)
   169 			    (simplified@stubborn)}
   177 			    (simplified@stubborn)}
   236  fun function_i thy fid congs eqs = 
   244  fun function_i thy fid congs eqs = 
   237   let val dum = Theory.requires thy "WF_Rel" "recursive function definitions"
   245   let val dum = Theory.requires thy "WF_Rel" "recursive function definitions"
   238       val {rules,R,theory,full_pats_TCs,SV,...} = 
   246       val {rules,R,theory,full_pats_TCs,SV,...} = 
   239 	      Prim.lazyR_def thy fid congs eqs
   247 	      Prim.lazyR_def thy fid congs eqs
   240       val f = func_of_cond_eqn (concl(R.CONJUNCT1 rules handle _ => rules))
   248       val f = func_of_cond_eqn (concl(R.CONJUNCT1 rules handle _ => rules))
   241       val dummy = writeln "Definition made.\nProving induction theorem..  "
   249       val dummy = (message "Definition made."; message "Proving induction theorem ...");
   242       val induction = Prim.mk_induction theory 
   250       val induction = Prim.mk_induction theory 
   243                          {fconst=f, R=R, SV=SV, pat_TCs_list=full_pats_TCs}
   251                          {fconst=f, R=R, SV=SV, pat_TCs_list=full_pats_TCs}
   244       val dummy = writeln "Induction theorem proved."
   252       val dummy = message "Induction theorem proved."
   245   in (theory, 
   253   in (theory, 
   246       (*return the conjoined induction rule and recursion equations, 
   254       (*return the conjoined induction rule and recursion equations, 
   247 	with assumptions remaining to discharge*)
   255 	with assumptions remaining to discharge*)
   248       standard (induction RS (rules RS conjI)))
   256       standard (induction RS (rules RS conjI)))
   249   end
   257   end
   250 
   258 
   251  fun function thy fid congs seqs = 
   259  fun function thy fid congs seqs = 
   252    let val _ =  writeln ("Deferred recursive function " ^ fid)
   260    let val _ =  message ("Deferred recursive function " ^ fid)
   253        fun read thy = readtm (Theory.sign_of thy) (TVar(("DUMMY",0),[])) 
   261        fun read thy = readtm (Theory.sign_of thy) (TVar(("DUMMY",0),[])) 
   254    in  function_i thy fid congs (map (read thy) seqs)  end
   262    in  function_i thy fid congs (map (read thy) seqs)  end
   255    handle Utils.ERR {mesg,...} => error mesg;
   263    handle Utils.ERR {mesg,...} => error mesg;
   256 
   264 
   257  end;
   265  end;