src/Pure/goals.ML
changeset 1928 3d1d73e3d185
parent 1628 60136fdd80c4
child 2126 d927beecedf8
equal deleted inserted replaced
1927:6f97cb16e453 1928:3d1d73e3d185
    59   val push_proof	: unit -> unit
    59   val push_proof	: unit -> unit
    60   val read		: string -> term
    60   val read		: string -> term
    61   val ren		: string -> int -> unit
    61   val ren		: string -> int -> unit
    62   val restore_proof	: proof -> thm list
    62   val restore_proof	: proof -> thm list
    63   val result		: unit -> thm  
    63   val result		: unit -> thm  
       
    64   val result_error_ref  : (thm -> string -> thm) ref
    64   val rotate_proof	: unit -> thm list
    65   val rotate_proof	: unit -> thm list
    65   val uresult		: unit -> thm  
    66   val uresult		: unit -> thm  
    66   val save_proof	: unit -> proof
    67   val save_proof	: unit -> proof
    67   val topthm		: unit -> thm
    68   val topthm		: unit -> thm
    68   val undo		: unit -> unit
    69   val undo		: unit -> unit
   113   in  case stamps of
   114   in  case stamps of
   114         [stamp] => "\nNew theory: " ^ !stamp
   115         [stamp] => "\nNew theory: " ^ !stamp
   115       | _       => "\nNew theories: " ^ space_implode ", " (map ! stamps)
   116       | _       => "\nNew theories: " ^ space_implode ", " (map ! stamps)
   116   end;
   117   end;
   117 
   118 
       
   119 (*Default action is to print an error message; could be suppressed for
       
   120   special applications.*)
       
   121 fun result_error_default state msg : thm = 
       
   122   (writeln ("Bad final proof state:");
       
   123    !print_goals_ref (!goals_limit) state;
       
   124    error msg);
       
   125 
       
   126 val result_error_ref = ref result_error_default;
       
   127 
   118 (*Common treatment of "goal" and "prove_goal":
   128 (*Common treatment of "goal" and "prove_goal":
   119   Return assumptions, initial proof state, and function to make result. *)
   129   Return assumptions, initial proof state, and function to make result. *)
   120 fun prepare_proof rths chorn =
   130 fun prepare_proof rths chorn =
   121   let val {sign, t=horn,...} = rep_cterm chorn;
   131   let val {sign, t=horn,...} = rep_cterm chorn;
   122       val (_,As,B) = Logic.strip_horn(horn);
   132       val (_,As,B) = Logic.strip_horn(horn);
   123       val cAs = map (cterm_of sign) As;
   133       val cAs = map (cterm_of sign) As;
   124       val prems = map (rewrite_rule rths o forall_elim_vars(0) o assume) cAs
   134       val prems = map (rewrite_rule rths o forall_elim_vars(0) o assume) cAs
   125       and st0 = (rewrite_goals_rule rths o trivial) (cterm_of sign B)
   135       and st0 = (rewrite_goals_rule rths o trivial) (cterm_of sign B)
   126       fun result_error state msg = 
       
   127         (writeln ("Bad final proof state:");
       
   128  	 !print_goals_ref (!goals_limit) state;
       
   129 	 error msg)
       
   130       (*discharges assumptions from state in the order they appear in goal;
   136       (*discharges assumptions from state in the order they appear in goal;
   131 	checks (if requested) that resulting theorem is equivalent to goal. *)
   137 	checks (if requested) that resulting theorem is equivalent to goal. *)
   132       fun mkresult (check,state) =
   138       fun mkresult (check,state) =
   133         let val state = Sequence.hd (flexflex_rule state)
   139         let val state = Sequence.hd (flexflex_rule state)
   134 	    		handle THM _ => state   (*smash flexflex pairs*)
   140 	    		handle THM _ => state   (*smash flexflex pairs*)
   135 	    val ngoals = nprems_of state
   141 	    val ngoals = nprems_of state
   136             val th = strip_shyps (implies_intr_list cAs state)
   142             val th = strip_shyps (implies_intr_list cAs state)
   137             val {hyps,prop,sign=sign',...} = rep_thm th
   143             val {hyps,prop,sign=sign',...} = rep_thm th
   138             val xshyps = extra_shyps th;
   144             val xshyps = extra_shyps th;
   139         in  if not check then standard th
   145         in  if not check then standard th
   140 	    else if not (Sign.eq_sg(sign,sign')) then result_error state
   146 	    else if not (Sign.eq_sg(sign,sign')) then !result_error_ref state
   141 		("Signature of proof state has changed!" ^
   147 		("Signature of proof state has changed!" ^
   142 		 sign_error (sign,sign'))
   148 		 sign_error (sign,sign'))
   143             else if ngoals>0 then result_error state
   149             else if ngoals>0 then !result_error_ref state
   144 		(string_of_int ngoals ^ " unsolved goals!")
   150 		(string_of_int ngoals ^ " unsolved goals!")
   145             else if not (null hyps) then result_error state
   151             else if not (null hyps) then !result_error_ref state
   146                 ("Additional hypotheses:\n" ^ 
   152                 ("Additional hypotheses:\n" ^ 
   147                  cat_lines (map (Sign.string_of_term sign) hyps))
   153                  cat_lines (map (Sign.string_of_term sign) hyps))
   148 	    else if not (null xshyps) then result_error state
   154 	    else if not (null xshyps) then !result_error_ref state
   149                 ("Extra sort hypotheses: " ^
   155                 ("Extra sort hypotheses: " ^
   150                  commas (map Type.str_of_sort xshyps))
   156                  commas (map Type.str_of_sort xshyps))
   151 	    else if Pattern.matches (#tsig(Sign.rep_sg sign)) 
   157 	    else if Pattern.matches (#tsig(Sign.rep_sg sign)) 
   152 			            (term_of chorn, prop)
   158 			            (term_of chorn, prop)
   153 		 then  standard th 
   159 		 then  standard th 
   154 	    else  result_error state "proved a different theorem"
   160 	    else  !result_error_ref state "proved a different theorem"
   155         end
   161         end
   156   in
   162   in
   157      if Sign.eq_sg(sign, #sign(rep_thm st0))
   163      if Sign.eq_sg(sign, #sign(rep_thm st0))
   158      then (prems, st0, mkresult)
   164      then (prems, st0, mkresult)
   159      else error ("Definitions would change the proof state's signature" ^
   165      else error ("Definitions would change the proof state's signature" ^