src/HOL/Tools/ATP/atp_proof_reconstruct.ML
changeset 57263 2b6a96cc64c9
parent 57258 67d85a8aa6cc
child 57267 8b87114357bd
equal deleted inserted replaced
57262:b2c629647a14 57263:2b6a96cc64c9
    36     bool -> int Symtab.table -> typ option -> (string, string atp_type) atp_term -> term
    36     bool -> int Symtab.table -> typ option -> (string, string atp_type) atp_term -> term
    37   val prop_of_atp : Proof.context -> ATP_Problem.atp_format -> ATP_Problem_Generate.type_enc ->
    37   val prop_of_atp : Proof.context -> ATP_Problem.atp_format -> ATP_Problem_Generate.type_enc ->
    38     bool -> int Symtab.table ->
    38     bool -> int Symtab.table ->
    39     (string, string, (string, string atp_type) atp_term, string) atp_formula -> term
    39     (string, string, (string, string atp_type) atp_term, string) atp_formula -> term
    40 
    40 
    41   val used_facts_in_atp_proof :
    41   val used_facts_in_atp_proof : Proof.context -> (string * stature) list -> string atp_proof ->
    42     Proof.context -> (string * stature) list vector -> string atp_proof -> (string * stature) list
    42     (string * stature) list
    43   val used_facts_in_unsound_atp_proof : Proof.context -> (string * stature) list vector ->
    43   val used_facts_in_unsound_atp_proof : Proof.context -> (string * stature) list -> 'a atp_proof ->
    44     'a atp_proof -> string list option
    44     string list option
    45   val atp_proof_prefers_lifting : string atp_proof -> bool
    45   val atp_proof_prefers_lifting : string atp_proof -> bool
    46   val is_typed_helper_used_in_atp_proof : string atp_proof -> bool
    46   val is_typed_helper_used_in_atp_proof : string atp_proof -> bool
    47   val replace_dependencies_in_line : atp_step_name * atp_step_name list -> ('a, 'b) atp_step ->
    47   val replace_dependencies_in_line : atp_step_name * atp_step_name list -> ('a, 'b) atp_step ->
    48     ('a, 'b) atp_step
    48     ('a, 'b) atp_step
    49   val termify_atp_proof : Proof.context -> string -> ATP_Problem.atp_format ->
    49   val termify_atp_proof : Proof.context -> string -> ATP_Problem.atp_format ->
    50     ATP_Problem_Generate.type_enc -> string Symtab.table -> (string * term) list ->
    50     ATP_Problem_Generate.type_enc -> string Symtab.table -> (string * term) list ->
    51     int Symtab.table -> string atp_proof -> (term, string) atp_step list
    51     int Symtab.table -> string atp_proof -> (term, string) atp_step list
    52   val introduce_spass_skolem : (term, string) atp_step list -> (term, string) atp_step list
    52   val introduce_spass_skolem : (term, string) atp_step list -> (term, string) atp_step list
    53   val factify_atp_proof : (string * 'a) list vector -> term list -> term ->
    53   val factify_atp_proof : (string * 'a) list -> term list -> term -> (term, string) atp_step list ->
    54     (term, string) atp_step list -> (term, string) atp_step list
    54     (term, string) atp_step list
    55 end;
    55 end;
    56 
    56 
    57 structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT =
    57 structure ATP_Proof_Reconstruct : ATP_PROOF_RECONSTRUCT =
    58 struct
    58 struct
    59 
    59 
   450       | _ => raise ATP_FORMULA [phi])
   450       | _ => raise ATP_FORMULA [phi])
   451   in
   451   in
   452     repair_tvar_sorts (do_formula true phi Vartab.empty)
   452     repair_tvar_sorts (do_formula true phi Vartab.empty)
   453   end
   453   end
   454 
   454 
   455 fun find_first_in_list_vector vec key =
       
   456   Vector.foldl (fn (ps, NONE) => AList.lookup (op =) ps key
       
   457                  | (_, value) => value) NONE vec
       
   458 
       
   459 val unprefix_fact_number = space_implode "_" o tl o space_explode "_"
   455 val unprefix_fact_number = space_implode "_" o tl o space_explode "_"
   460 
   456 
   461 fun resolve_one_named_fact fact_names s =
   457 fun resolve_fact facts s =
   462   (case try (unprefix fact_prefix) s of
   458   (case try (unprefix fact_prefix) s of
   463     SOME s' =>
   459     SOME s' =>
   464     let val s' = s' |> unprefix_fact_number |> unascii_of in
   460     let val s' = s' |> unprefix_fact_number |> unascii_of in
   465       s' |> find_first_in_list_vector fact_names |> Option.map (pair s')
   461       AList.lookup (op =) facts s' |> Option.map (pair s')
   466     end
   462     end
   467   | NONE => NONE)
   463   | NONE => NONE)
   468 
   464 
   469 fun resolve_fact fact_names = map_filter (resolve_one_named_fact fact_names)
   465 fun resolve_conjecture s =
   470 
       
   471 fun resolve_one_named_conjecture s =
       
   472   (case try (unprefix conjecture_prefix) s of
   466   (case try (unprefix conjecture_prefix) s of
   473     SOME s' => Int.fromString s'
   467     SOME s' => Int.fromString s'
   474   | NONE => NONE)
   468   | NONE => NONE)
   475 
   469 
   476 val resolve_conjecture = map_filter resolve_one_named_conjecture
   470 fun resolve_facts facts = map_filter (resolve_fact facts)
       
   471 val resolve_conjectures = map_filter resolve_conjecture
   477 
   472 
   478 fun is_axiom_used_in_proof pred =
   473 fun is_axiom_used_in_proof pred =
   479   exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false)
   474   exists (fn ((_, ss), _, _, _, []) => exists pred ss | _ => false)
   480 
   475 
   481 fun add_non_rec_defs fact_names accum =
   476 fun add_non_rec_defs facts =
   482   Vector.foldl (fn (facts, facts') =>
   477   fold (fn fact as (_, (_, status)) => status = Non_Rec_Def ? insert (op =) fact) facts
   483       union (op =) (filter (fn (_, (_, status)) => status = Non_Rec_Def) facts) facts')
       
   484     accum fact_names
       
   485 
   478 
   486 val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg"
   479 val leo2_extcnf_equal_neg_rule = "extcnf_equal_neg"
   487 val leo2_unfold_def_rule = "unfold_def"
   480 val leo2_unfold_def_rule = "unfold_def"
   488 
   481 
   489 fun add_fact ctxt fact_names ((_, ss), _, _, rule, deps) =
   482 fun add_fact ctxt facts ((_, ss), _, _, rule, deps) =
   490   (if rule = leo2_extcnf_equal_neg_rule then
   483   (if rule = leo2_extcnf_equal_neg_rule then
   491      insert (op =) (short_thm_name ctxt ext, (Global, General))
   484      insert (op =) (short_thm_name ctxt ext, (Global, General))
   492    else if rule = leo2_unfold_def_rule then
   485    else if rule = leo2_unfold_def_rule then
   493      (* LEO 1.3.3 does not record definitions properly, leading to missing dependencies in the TSTP
   486      (* LEO 1.3.3 does not record definitions properly, leading to missing dependencies in the TSTP
   494         proof. Remove the next line once this is fixed. *)
   487         proof. Remove the next line once this is fixed. *)
   495      add_non_rec_defs fact_names
   488      add_non_rec_defs facts
   496    else if rule = agsyhol_core_rule orelse rule = satallax_core_rule then
   489    else if rule = agsyhol_core_rule orelse rule = satallax_core_rule then
   497      (fn [] =>
   490      (fn [] =>
   498          (* agsyHOL and Satallax don't include definitions in their unsatisfiable cores, so we
   491          (* agsyHOL and Satallax don't include definitions in their unsatisfiable cores, so we
   499             assume the worst and include them all here. *)
   492             assume the worst and include them all here. *)
   500          [(short_thm_name ctxt ext, (Global, General))] |> add_non_rec_defs fact_names
   493          [(short_thm_name ctxt ext, (Global, General))] |> add_non_rec_defs facts
   501        | facts => facts)
   494        | facts => facts)
   502    else
   495    else
   503      I)
   496      I)
   504   #> (if null deps then union (op =) (resolve_fact fact_names ss) else I)
   497   #> (if null deps then union (op =) (resolve_facts facts ss) else I)
   505 
   498 
   506 fun used_facts_in_atp_proof ctxt fact_names atp_proof =
   499 fun used_facts_in_atp_proof ctxt facts atp_proof =
   507   if null atp_proof then Vector.foldl (uncurry (union (op =))) [] fact_names
   500   if null atp_proof then facts else fold (add_fact ctxt facts) atp_proof []
   508   else fold (add_fact ctxt fact_names) atp_proof []
       
   509 
   501 
   510 fun used_facts_in_unsound_atp_proof _ _ [] = NONE
   502 fun used_facts_in_unsound_atp_proof _ _ [] = NONE
   511   | used_facts_in_unsound_atp_proof ctxt fact_names atp_proof =
   503   | used_facts_in_unsound_atp_proof ctxt facts atp_proof =
   512     let val used_facts = used_facts_in_atp_proof ctxt fact_names atp_proof in
   504     let val used_facts = used_facts_in_atp_proof ctxt facts atp_proof in
   513       if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso
   505       if forall (fn (_, (sc, _)) => sc = Global) used_facts andalso
   514          not (is_axiom_used_in_proof (not o null o resolve_conjecture o single) atp_proof) then
   506          not (is_axiom_used_in_proof (is_some o resolve_conjecture) atp_proof) then
   515         SOME (map fst used_facts)
   507         SOME (map fst used_facts)
   516       else
   508       else
   517         NONE
   509         NONE
   518     end
   510     end
   519 
   511 
   714         input_steps @ sko_steps @ map repair_deps other_steps
   706         input_steps @ sko_steps @ map repair_deps other_steps
   715       end
   707       end
   716   else
   708   else
   717     proof
   709     proof
   718 
   710 
   719 fun factify_atp_proof fact_names hyp_ts concl_t atp_proof =
   711 fun factify_atp_proof facts hyp_ts concl_t atp_proof =
   720   let
   712   let
   721     fun factify_step ((num, ss), _, t, rule, deps) =
   713     fun factify_step ((num, ss), _, t, rule, deps) =
   722       let
   714       let
   723         val (ss', role', t') =
   715         val (ss', role', t') =
   724           (case resolve_conjecture ss of
   716           (case resolve_conjectures ss of
   725             [j] =>
   717             [j] =>
   726             if j = length hyp_ts then ([], Conjecture, concl_t) else ([], Hypothesis, nth hyp_ts j)
   718             if j = length hyp_ts then ([], Conjecture, concl_t) else ([], Hypothesis, nth hyp_ts j)
   727           | _ =>
   719           | _ =>
   728             (case resolve_fact fact_names ss of
   720             (case resolve_facts facts ss of
   729               [] => (ss, Plain, t)
   721               [] => (ss, Plain, t)
   730             | facts => (map fst facts, Axiom, t)))
   722             | facts => (map fst facts, Axiom, t)))
   731       in
   723       in
   732         ((num, ss'), role', t', rule, deps)
   724         ((num, ss'), role', t', rule, deps)
   733       end
   725       end