src/HOL/Tools/ATP/atp_reconstruct.ML
changeset 43184 b16693484c5d
parent 43183 faece9668bce
child 43191 0a72c0527111
equal deleted inserted replaced
43183:faece9668bce 43184:b16693484c5d
   554                   |> map Var
   554                   |> map Var
   555   in fold_rev quant_of vars t end
   555   in fold_rev quant_of vars t end
   556 
   556 
   557 (* Interpret an ATP formula as a HOL term, extracting sort constraints as they
   557 (* Interpret an ATP formula as a HOL term, extracting sort constraints as they
   558    appear in the formula. *)
   558    appear in the formula. *)
   559 fun raw_prop_from_atp ctxt textual sym_tab phi =
   559 fun prop_from_atp ctxt textual sym_tab phi =
   560   let
   560   let
   561     fun do_formula pos phi =
   561     fun do_formula pos phi =
   562       case phi of
   562       case phi of
   563         AQuant (_, [], phi) => do_formula pos phi
   563         AQuant (_, [], phi) => do_formula pos phi
   564       | AQuant (q, (s, _) :: xs, phi') =>
   564       | AQuant (q, (s, _) :: xs, phi') =>
   585 fun infer_formula_types ctxt =
   585 fun infer_formula_types ctxt =
   586   Type.constraint HOLogic.boolT
   586   Type.constraint HOLogic.boolT
   587   #> Syntax.check_term
   587   #> Syntax.check_term
   588          (Proof_Context.set_mode Proof_Context.mode_schematic ctxt)
   588          (Proof_Context.set_mode Proof_Context.mode_schematic ctxt)
   589 
   589 
   590 fun prop_from_atp ctxt textual sym_tab =
   590 fun uncombined_etc_prop_from_atp ctxt textual sym_tab =
   591   let val thy = Proof_Context.theory_of ctxt in
   591   let val thy = Proof_Context.theory_of ctxt in
   592     raw_prop_from_atp ctxt textual sym_tab
   592     prop_from_atp ctxt textual sym_tab
   593     #> textual ? uncombine_term thy #> infer_formula_types ctxt
   593     #> textual ? uncombine_term thy #> infer_formula_types ctxt
   594   end
   594   end
   595 
   595 
   596 (**** Translation of TSTP files to Isar proofs ****)
   596 (**** Translation of TSTP files to Isar proofs ****)
   597 
   597 
   599   | unvarify_term t = raise TERM ("unvarify_term: non-Var", [t])
   599   | unvarify_term t = raise TERM ("unvarify_term: non-Var", [t])
   600 
   600 
   601 fun decode_line sym_tab (Definition (name, phi1, phi2)) ctxt =
   601 fun decode_line sym_tab (Definition (name, phi1, phi2)) ctxt =
   602     let
   602     let
   603       val thy = Proof_Context.theory_of ctxt
   603       val thy = Proof_Context.theory_of ctxt
   604       (* FIXME: prop or term? *)
   604       val t1 = prop_from_atp ctxt true sym_tab phi1
   605       val t1 = raw_prop_from_atp ctxt true sym_tab phi1
       
   606       val vars = snd (strip_comb t1)
   605       val vars = snd (strip_comb t1)
   607       val frees = map unvarify_term vars
   606       val frees = map unvarify_term vars
   608       val unvarify_args = subst_atomic (vars ~~ frees)
   607       val unvarify_args = subst_atomic (vars ~~ frees)
   609       val t2 = raw_prop_from_atp ctxt true sym_tab phi2
   608       val t2 = prop_from_atp ctxt true sym_tab phi2
   610       val (t1, t2) =
   609       val (t1, t2) =
   611         HOLogic.eq_const HOLogic.typeT $ t1 $ t2
   610         HOLogic.eq_const HOLogic.typeT $ t1 $ t2
   612         |> unvarify_args |> uncombine_term thy |> infer_formula_types ctxt
   611         |> unvarify_args |> uncombine_term thy |> infer_formula_types ctxt
   613         |> HOLogic.dest_eq
   612         |> HOLogic.dest_eq
   614     in
   613     in
   615       (Definition (name, t1, t2),
   614       (Definition (name, t1, t2),
   616        fold Variable.declare_term (maps OldTerm.term_frees [t1, t2]) ctxt)
   615        fold Variable.declare_term (maps OldTerm.term_frees [t1, t2]) ctxt)
   617     end
   616     end
   618   | decode_line sym_tab (Inference (name, u, deps)) ctxt =
   617   | decode_line sym_tab (Inference (name, u, deps)) ctxt =
   619     let val t = u |> prop_from_atp ctxt true sym_tab in
   618     let val t = u |> uncombined_etc_prop_from_atp ctxt true sym_tab in
   620       (Inference (name, t, deps),
   619       (Inference (name, t, deps),
   621        fold Variable.declare_term (OldTerm.term_frees t) ctxt)
   620        fold Variable.declare_term (OldTerm.term_frees t) ctxt)
   622     end
   621     end
   623 fun decode_lines ctxt sym_tab lines =
   622 fun decode_lines ctxt sym_tab lines =
   624   fst (fold_map (decode_line sym_tab) lines ctxt)
   623   fst (fold_map (decode_line sym_tab) lines ctxt)