src/HOL/Tools/Sledgehammer/sledgehammer_proof_reconstruct.ML
changeset 36478 1aba777a367f
parent 36477 71cc00ea5768
child 36479 fcbf412c560f
equal deleted inserted replaced
36477:71cc00ea5768 36478:1aba777a367f
    31 end;
    31 end;
    32 
    32 
    33 structure Sledgehammer_Proof_Reconstruct : SLEDGEHAMMER_PROOF_RECONSTRUCT =
    33 structure Sledgehammer_Proof_Reconstruct : SLEDGEHAMMER_PROOF_RECONSTRUCT =
    34 struct
    34 struct
    35 
    35 
       
    36 open Sledgehammer_Util
    36 open Sledgehammer_FOL_Clause
    37 open Sledgehammer_FOL_Clause
    37 open Sledgehammer_Fact_Preprocessor
    38 open Sledgehammer_Fact_Preprocessor
    38 
    39 
    39 type minimize_command = string list -> string
    40 type minimize_command = string list -> string
    40 
    41 
   478   (union (op =) ls1 ls2, union (op =) ss1 ss2)
   479   (union (op =) ls1 ls2, union (op =) ss1 ss2)
   479 
   480 
   480 datatype qualifier = Show | Then | Moreover | Ultimately
   481 datatype qualifier = Show | Then | Moreover | Ultimately
   481 
   482 
   482 datatype step =
   483 datatype step =
   483   Fix of term list |
   484   Fix of (string * typ) list |
   484   Assume of label * term |
   485   Assume of label * term |
   485   Have of qualifier list * label * term * byline
   486   Have of qualifier list * label * term * byline
   486 and byline =
   487 and byline =
   487   Facts of facts |
   488   Facts of facts |
   488   CaseSplit of step list list * facts
   489   CaseSplit of step list list * facts
   714 
   715 
   715 fun kill_useless_labels_in_proof proof =
   716 fun kill_useless_labels_in_proof proof =
   716   let
   717   let
   717     val used_ls = using_of proof
   718     val used_ls = using_of proof
   718     fun do_label l = if member (op =) used_ls l then l else no_label
   719     fun do_label l = if member (op =) used_ls l then l else no_label
   719     fun kill (Fix ts) = Fix ts
   720     fun kill (Fix xs) = Fix xs
   720       | kill (Assume (l, t)) = Assume (do_label l, t)
   721       | kill (Assume (l, t)) = Assume (do_label l, t)
   721       | kill (Have (qs, l, t, by)) =
   722       | kill (Have (qs, l, t, by)) =
   722         Have (qs, do_label l, t,
   723         Have (qs, do_label l, t,
   723               case by of
   724               case by of
   724                 CaseSplit (proofs, facts) =>
   725                 CaseSplit (proofs, facts) =>
   763         end
   764         end
   764   in aux [] 0 (1, 1) end
   765   in aux [] 0 (1, 1) end
   765 
   766 
   766 fun string_for_proof ctxt sorts i n =
   767 fun string_for_proof ctxt sorts i n =
   767   let
   768   let
       
   769     fun fix_print_mode f =
       
   770       PrintMode.setmp (filter (curry (op =) Symbol.xsymbolsN)
       
   771                       (print_mode_value ())) f
   768     fun do_indent ind = replicate_string (ind * indent_size) " "
   772     fun do_indent ind = replicate_string (ind * indent_size) " "
       
   773     fun do_free (s, T) =
       
   774       maybe_quote s ^ " :: " ^
       
   775       maybe_quote (fix_print_mode (Syntax.string_of_typ ctxt) T)
   769     fun do_raw_label (s, j) = s ^ string_of_int j
   776     fun do_raw_label (s, j) = s ^ string_of_int j
   770     fun do_label l = if l = no_label then "" else do_raw_label l ^ ": "
   777     fun do_label l = if l = no_label then "" else do_raw_label l ^ ": "
   771     fun do_have qs =
   778     fun do_have qs =
   772       (if member (op =) qs Moreover then "moreover " else "") ^
   779       (if member (op =) qs Moreover then "moreover " else "") ^
   773       (if member (op =) qs Ultimately then "ultimately " else "") ^
   780       (if member (op =) qs Ultimately then "ultimately " else "") ^
   774       (if member (op =) qs Then then
   781       (if member (op =) qs Then then
   775          if member (op =) qs Show then "thus" else "hence"
   782          if member (op =) qs Show then "thus" else "hence"
   776        else
   783        else
   777          if member (op =) qs Show then "show" else "have")
   784          if member (op =) qs Show then "show" else "have")
   778     val do_term =
   785     val do_term = maybe_quote o fix_print_mode (Syntax.string_of_term ctxt)
   779       quote o PrintMode.setmp (filter (curry (op =) Symbol.xsymbolsN)
       
   780                                       (print_mode_value ()))
       
   781                               (Syntax.string_of_term ctxt)
       
   782     fun do_using [] = ""
   786     fun do_using [] = ""
   783       | do_using ls = "using " ^ (space_implode " " (map do_raw_label ls)) ^ " "
   787       | do_using ls = "using " ^ (space_implode " " (map do_raw_label ls)) ^ " "
   784     fun do_by_facts [] [] = "by blast"
   788     fun do_by_facts [] [] = "by blast"
   785       | do_by_facts _ [] = "by metis"
   789       | do_by_facts _ [] = "by metis"
   786       | do_by_facts _ ss = "by (metis " ^ space_implode " " ss ^ ")"
   790       | do_by_facts _ ss = "by (metis " ^ space_implode " " ss ^ ")"
   787     fun do_facts ind (ls, ss) =
   791     fun do_facts (ls, ss) = do_using ls ^ do_by_facts ls ss
   788       do_indent (ind + 1) ^ do_using ls ^ do_by_facts ls ss
   792     and do_step ind (Fix xs) =
   789     and do_step ind (Fix ts) =
   793         do_indent ind ^ "fix " ^ space_implode " and " (map do_free xs) ^ "\n"
   790         do_indent ind ^ "fix " ^ space_implode " and " (map do_term ts) ^ "\n"
       
   791       | do_step ind (Assume (l, t)) =
   794       | do_step ind (Assume (l, t)) =
   792         do_indent ind ^ "assume " ^ do_label l ^ do_term t ^ "\n"
   795         do_indent ind ^ "assume " ^ do_label l ^ do_term t ^ "\n"
   793       | do_step ind (Have (qs, l, t, Facts facts)) =
   796       | do_step ind (Have (qs, l, t, Facts facts)) =
   794         do_indent ind ^ do_have qs ^ " " ^
   797         do_indent ind ^ do_have qs ^ " " ^
   795         do_label l ^ do_term t ^ "\n" ^ do_facts ind facts ^ "\n"
   798         do_label l ^ do_term t ^ do_facts facts ^ "\n"
   796       | do_step ind (Have (qs, l, t, CaseSplit (proofs, facts))) =
   799       | do_step ind (Have (qs, l, t, CaseSplit (proofs, facts))) =
   797         space_implode (do_indent ind ^ "moreover\n")
   800         space_implode (do_indent ind ^ "moreover\n")
   798                       (map (do_block ind) proofs) ^
   801                       (map (do_block ind) proofs) ^
   799         do_indent ind ^ do_have qs ^ " " ^ do_label l ^ do_term t ^ "\n" ^
   802         do_indent ind ^ do_have qs ^ " " ^ do_label l ^ do_term t ^
   800         do_facts ind facts ^ "\n"
   803         do_facts facts ^ "\n"
   801     and do_steps prefix suffix ind steps =
   804     and do_steps prefix suffix ind steps =
   802       let val s = implode (map (do_step ind) steps) in
   805       let val s = implode (map (do_step ind) steps) in
   803         replicate_string (ind * indent_size - size prefix) " " ^ prefix ^
   806         replicate_string (ind * indent_size - size prefix) " " ^ prefix ^
   804         String.extract (s, ind * indent_size,
   807         String.extract (s, ind * indent_size,
   805                         SOME (size s - ind * indent_size - 1)) ^
   808                         SOME (size s - ind * indent_size - 1)) ^