src/HOL/Tools/try0_util.ML
changeset 82577 f3b3d49d84d7
parent 82368 ef3ec45ded4d
child 82578 cf21066637d7
equal deleted inserted replaced
82576:a310d5b6c696 82577:f3b3d49d84d7
     8 
     8 
     9 signature TRY0_UTIL =
     9 signature TRY0_UTIL =
    10 sig
    10 sig
    11   val string_of_xref : Try0.xref -> string
    11   val string_of_xref : Try0.xref -> string
    12 
    12 
    13   type facts_prefixes =
    13   type facts_config =
    14     {simps : string option,
    14     {simps_prefix : string option,
    15      intros : string option,
    15      intros_prefix : string option,
    16      elims : string option,
    16      elims_prefix : string option,
    17      dests : string option}
    17      dests_prefix : string option}
    18   val full_attrs : facts_prefixes
    18   val full_attrs : facts_config
    19   val clas_attrs : facts_prefixes
    19   val clas_attrs : facts_config
    20   val simp_attrs : facts_prefixes
    20   val simp_attrs : facts_config
    21   val metis_attrs : facts_prefixes
    21   val metis_attrs : facts_config
    22   val no_attrs : facts_prefixes
    22   val no_attrs : facts_config
    23   val apply_raw_named_method : string -> bool -> facts_prefixes ->
    23   val apply_raw_named_method : string -> bool -> facts_config ->
    24     (Proof.context -> Proof.context) -> Time.time option -> Try0.facts -> Proof.state ->
    24     (Proof.context -> Proof.context) -> Time.time option -> Try0.facts -> Proof.state ->
    25     Try0.result option
    25     Try0.result option
    26 end
    26 end
    27 
    27 
    28 structure Try0_Util : TRY0_UTIL = struct
    28 structure Try0_Util : TRY0_UTIL = struct
    32     Facts.Fact literal => literal |> Symbol_Pos.explode0 |> Symbol_Pos.implode |> cartouche
    32     Facts.Fact literal => literal |> Symbol_Pos.explode0 |> Symbol_Pos.implode |> cartouche
    33   | _ =>
    33   | _ =>
    34       Facts.string_of_ref xref) ^ implode
    34       Facts.string_of_ref xref) ^ implode
    35         (map (enclose "[" "]" o Pretty.unformatted_string_of o Token.pretty_src \<^context>) args)
    35         (map (enclose "[" "]" o Pretty.unformatted_string_of o Token.pretty_src \<^context>) args)
    36 
    36 
       
    37 type facts_config =
       
    38   {simps_prefix : string option,
       
    39    intros_prefix : string option,
       
    40    elims_prefix : string option,
       
    41    dests_prefix : string option}
    37 
    42 
    38 type facts_prefixes =
    43 val no_attrs : facts_config =
    39   {simps : string option,
    44   {simps_prefix = NONE,
    40    intros : string option,
    45    intros_prefix = NONE,
    41    elims : string option,
    46    elims_prefix = NONE,
    42    dests : string option}
    47    dests_prefix = NONE}
    43 
    48 val full_attrs : facts_config =
    44 val no_attrs : facts_prefixes =
    49   {simps_prefix = SOME "simp: ",
    45   {simps = NONE, intros = NONE, elims = NONE, dests = NONE}
    50    intros_prefix = SOME "intro: ",
    46 val full_attrs : facts_prefixes =
    51    elims_prefix = SOME "elim: ",
    47   {simps = SOME "simp: ", intros = SOME "intro: ", elims = SOME "elim: ", dests = SOME "dest: "}
    52    dests_prefix = SOME "dest: "}
    48 val clas_attrs : facts_prefixes =
    53 val clas_attrs : facts_config =
    49   {simps = NONE, intros = SOME "intro: ", elims = SOME "elim: ", dests = SOME "dest: "}
    54   {simps_prefix = NONE,
    50 val simp_attrs : facts_prefixes =
    55    intros_prefix = SOME "intro: ",
    51   {simps = SOME "add: ", intros = NONE, elims = NONE, dests = NONE}
    56    elims_prefix = SOME "elim: ",
    52 val metis_attrs : facts_prefixes =
    57    dests_prefix = SOME "dest: "}
    53   {simps = SOME "", intros = SOME "", elims = SOME "", dests = SOME ""}
    58 val simp_attrs : facts_config =
       
    59   {simps_prefix = SOME "add: ",
       
    60    intros_prefix = NONE,
       
    61    elims_prefix = NONE,
       
    62    dests_prefix = NONE}
       
    63 val metis_attrs : facts_config =
       
    64   {simps_prefix = SOME "",
       
    65    intros_prefix = SOME "",
       
    66    elims_prefix = SOME "",
       
    67    dests_prefix = SOME ""}
    54 
    68 
    55 local
    69 local
    56 
    70 
    57 fun parse_method ctxt s =
    71 fun parse_method ctxt s =
    58   enclose "(" ")" s
    72   enclose "(" ")" s
    77       else (elapsed0 + elapsed, st')
    91       else (elapsed0 + elapsed, st')
    78    |_ => (elapsed0, st))
    92    |_ => (elapsed0, st))
    79 
    93 
    80 in
    94 in
    81 
    95 
    82 fun apply_raw_named_method (name : string) all_goals (prefixes: facts_prefixes)
    96 fun apply_raw_named_method (name : string) all_goals (facts_config: facts_config)
    83   (silence_methods : Proof.context -> Proof.context) timeout_opt (facts : Try0.facts)
    97   (silence_methods : Proof.context -> Proof.context) timeout_opt (facts : Try0.facts)
    84   (st : Proof.state) : Try0.result option =
    98   (st : Proof.state) : Try0.result option =
    85   let
    99   let
    86     val st = Proof.map_contexts silence_methods st
   100     val st = Proof.map_contexts silence_methods st
    87     val ctxt = Proof.context_of st
   101     val ctxt = Proof.context_of st
    88 
   102 
    89     val (unused_simps, simps_attrs) =
   103     val (unused_simps, simps_attrs) =
    90        if null (#simps facts) then
   104        if null (#simps facts) then
    91         ([], "")
   105         ([], "")
    92       else
   106       else
    93         (case #simps prefixes of
   107         (case #simps_prefix facts_config of
    94           NONE =>  (#simps facts, "")
   108           NONE =>  (#simps facts, "")
    95         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#simps facts))))
   109         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#simps facts))))
    96 
   110 
    97     val (unused_intros, intros_attrs) =
   111     val (unused_intros, intros_attrs) =
    98       if null (#intros facts) then
   112       if null (#intros facts) then
    99         ([], "")
   113         ([], "")
   100       else
   114       else
   101         (case #intros prefixes of
   115         (case #intros_prefix facts_config of
   102           NONE =>  (#intros facts, "")
   116           NONE =>  (#intros facts, "")
   103         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#intros facts))))
   117         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#intros facts))))
   104 
   118 
   105     val (unused_elims, elims_attrs) =
   119     val (unused_elims, elims_attrs) =
   106       if null (#elims facts) then
   120       if null (#elims facts) then
   107         ([], "")
   121         ([], "")
   108       else
   122       else
   109         (case #elims prefixes of
   123         (case #elims_prefix facts_config of
   110           NONE =>  (#elims facts, "")
   124           NONE =>  (#elims facts, "")
   111         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#elims facts))))
   125         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#elims facts))))
   112 
   126 
   113     val (unused_dests, dests_attrs) =
   127     val (unused_dests, dests_attrs) =
   114       if null (#dests facts) then
   128       if null (#dests facts) then
   115         ([], "")
   129         ([], "")
   116       else
   130       else
   117         (case #dests prefixes of
   131         (case #dests_prefix facts_config of
   118           NONE =>  (#dests facts, "")
   132           NONE =>  (#dests facts, "")
   119         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#dests facts))))
   133         | SOME prefix => ([], " " ^ prefix ^ space_implode "" (map string_of_xref (#dests facts))))
   120 
   134 
   121     val unused = #usings facts @ unused_simps @ unused_intros @ unused_elims @ unused_dests
   135     val unused = #usings facts @ unused_simps @ unused_intros @ unused_elims @ unused_dests
   122 
   136