src/HOL/Tools/Metis/metis_generate.ML
changeset 52031 9a9238342963
parent 51998 f732a674db1b
child 52150 41c885784e04
equal deleted inserted replaced
52030:9f6f0a89d16b 52031:9a9238342963
   136 
   136 
   137 val proxy_defs = map (fst o snd o snd) proxy_table
   137 val proxy_defs = map (fst o snd o snd) proxy_table
   138 val prepare_helper =
   138 val prepare_helper =
   139   Meson.make_meta_clause #> rewrite_rule (map safe_mk_meta_eq proxy_defs)
   139   Meson.make_meta_clause #> rewrite_rule (map safe_mk_meta_eq proxy_defs)
   140 
   140 
   141 fun metis_term_from_atp type_enc (ATerm ((s, []), tms)) =
   141 fun metis_term_of_atp type_enc (ATerm ((s, []), tms)) =
   142   if is_tptp_variable s then
   142   if is_tptp_variable s then
   143     Metis_Term.Var (Metis_Name.fromString s)
   143     Metis_Term.Var (Metis_Name.fromString s)
   144   else
   144   else
   145     (case AList.lookup (op =) metis_name_table (s, length tms) of
   145     (case AList.lookup (op =) metis_name_table (s, length tms) of
   146        SOME (f, swap) => (f type_enc, swap)
   146        SOME (f, swap) => (f type_enc, swap)
   147      | NONE => (s, false))
   147      | NONE => (s, false))
   148     |> (fn (s, swap) =>
   148     |> (fn (s, swap) =>
   149            Metis_Term.Fn (Metis_Name.fromString s,
   149            Metis_Term.Fn (Metis_Name.fromString s,
   150                           tms |> map (metis_term_from_atp type_enc)
   150                           tms |> map (metis_term_of_atp type_enc)
   151                               |> swap ? rev))
   151                               |> swap ? rev))
   152 fun metis_atom_from_atp type_enc (AAtom tm) =
   152 fun metis_atom_of_atp type_enc (AAtom tm) =
   153     (case metis_term_from_atp type_enc tm of
   153     (case metis_term_of_atp type_enc tm of
   154        Metis_Term.Fn x => x
   154        Metis_Term.Fn x => x
   155      | _ => raise Fail "non CNF -- expected function")
   155      | _ => raise Fail "non CNF -- expected function")
   156   | metis_atom_from_atp _ _ = raise Fail "not CNF -- expected atom"
   156   | metis_atom_of_atp _ _ = raise Fail "not CNF -- expected atom"
   157 fun metis_literal_from_atp type_enc (AConn (ANot, [phi])) =
   157 fun metis_literal_of_atp type_enc (AConn (ANot, [phi])) =
   158     (false, metis_atom_from_atp type_enc phi)
   158     (false, metis_atom_of_atp type_enc phi)
   159   | metis_literal_from_atp type_enc phi =
   159   | metis_literal_of_atp type_enc phi = (true, metis_atom_of_atp type_enc phi)
   160     (true, metis_atom_from_atp type_enc phi)
   160 fun metis_literals_of_atp type_enc (AConn (AOr, phis)) =
   161 fun metis_literals_from_atp type_enc (AConn (AOr, phis)) =
   161     maps (metis_literals_of_atp type_enc) phis
   162     maps (metis_literals_from_atp type_enc) phis
   162   | metis_literals_of_atp type_enc phi = [metis_literal_of_atp type_enc phi]
   163   | metis_literals_from_atp type_enc phi = [metis_literal_from_atp type_enc phi]
   163 fun metis_axiom_of_atp type_enc clauses (Formula ((ident, _), _, phi, _, _)) =
   164 fun metis_axiom_from_atp type_enc clauses (Formula ((ident, _), _, phi, _, _)) =
       
   165     let
   164     let
   166       fun some isa =
   165       fun some isa =
   167         SOME (phi |> metis_literals_from_atp type_enc
   166         SOME (phi |> metis_literals_of_atp type_enc
   168                   |> Metis_LiteralSet.fromList
   167                   |> Metis_LiteralSet.fromList
   169                   |> Metis_Thm.axiom, isa)
   168                   |> Metis_Thm.axiom, isa)
   170     in
   169     in
   171       if String.isPrefix tags_sym_formula_prefix ident then
   170       if String.isPrefix tags_sym_formula_prefix ident then
   172         Isa_Reflexive_or_Trivial |> some
   171         Isa_Reflexive_or_Trivial |> some
   195             else
   194             else
   196               raise Fail ("malformed fact identifier " ^ quote ident)
   195               raise Fail ("malformed fact identifier " ^ quote ident)
   197         end
   196         end
   198       | NONE => TrueI |> Isa_Raw |> some
   197       | NONE => TrueI |> Isa_Raw |> some
   199     end
   198     end
   200   | metis_axiom_from_atp _ _ _ = raise Fail "not CNF -- expected formula"
   199   | metis_axiom_of_atp _ _ _ = raise Fail "not CNF -- expected formula"
   201 
   200 
   202 fun eliminate_lam_wrappers (Const (@{const_name Metis.lambda}, _) $ t) =
   201 fun eliminate_lam_wrappers (Const (@{const_name Metis.lambda}, _) $ t) =
   203     eliminate_lam_wrappers t
   202     eliminate_lam_wrappers t
   204   | eliminate_lam_wrappers (t $ u) =
   203   | eliminate_lam_wrappers (t $ u) =
   205     eliminate_lam_wrappers t $ eliminate_lam_wrappers u
   204     eliminate_lam_wrappers t $ eliminate_lam_wrappers u
   249                      cat_lines (lines_of_atp_problem CNF atp_problem))
   248                      cat_lines (lines_of_atp_problem CNF atp_problem))
   250     *)
   249     *)
   251     (* "rev" is for compatibility with existing proof scripts. *)
   250     (* "rev" is for compatibility with existing proof scripts. *)
   252     val axioms =
   251     val axioms =
   253       atp_problem
   252       atp_problem
   254       |> maps (map_filter (metis_axiom_from_atp type_enc clauses) o snd) |> rev
   253       |> maps (map_filter (metis_axiom_of_atp type_enc clauses) o snd) |> rev
   255     fun ord_info () = atp_problem_term_order_info atp_problem
   254     fun ord_info () = atp_problem_term_order_info atp_problem
   256   in (sym_tab, axioms, ord_info, (lifted, old_skolems)) end
   255   in (sym_tab, axioms, ord_info, (lifted, old_skolems)) end
   257 
   256 
   258 end;
   257 end;