27 val trace_msg : Proof.context -> (unit -> string) -> unit |
27 val trace_msg : Proof.context -> (unit -> string) -> unit |
28 val verbose_warning : Proof.context -> string -> unit |
28 val verbose_warning : Proof.context -> string -> unit |
29 val metis_name_table : ((string * int) * ((type_enc -> string) * bool)) list |
29 val metis_name_table : ((string * int) * ((type_enc -> string) * bool)) list |
30 val reveal_old_skolem_terms : (string * term) list -> term -> term |
30 val reveal_old_skolem_terms : (string * term) list -> term -> term |
31 val reveal_lam_lifted : (string * term) list -> term -> term |
31 val reveal_lam_lifted : (string * term) list -> term -> term |
32 val prepare_metis_problem : |
32 val generate_metis_problem : Proof.context -> type_enc -> string -> thm list -> thm list -> |
33 Proof.context -> type_enc -> string -> thm list -> thm list |
33 int Symtab.table * (Metis_Thm.thm * isa_thm) list * (unit -> (string * int) list) |
34 -> int Symtab.table * (Metis_Thm.thm * isa_thm) list |
34 * ((string * term) list * (string * term) list) |
35 * (unit -> (string * int) list) |
|
36 * ((string * term) list * (string * term) list) |
|
37 end |
35 end |
38 |
36 |
39 structure Metis_Generate : METIS_GENERATE = |
37 structure Metis_Generate : METIS_GENERATE = |
40 struct |
38 struct |
41 |
39 |
170 if String.isPrefix tags_sym_formula_prefix ident then |
168 if String.isPrefix tags_sym_formula_prefix ident then |
171 Isa_Reflexive_or_Trivial |> some |
169 Isa_Reflexive_or_Trivial |> some |
172 else if String.isPrefix conjecture_prefix ident then |
170 else if String.isPrefix conjecture_prefix ident then |
173 NONE |
171 NONE |
174 else if String.isPrefix helper_prefix ident then |
172 else if String.isPrefix helper_prefix ident then |
175 case (String.isSuffix typed_helper_suffix ident, |
173 case (String.isSuffix typed_helper_suffix ident, space_explode "_" ident) of |
176 space_explode "_" ident) of |
|
177 (needs_fairly_sound, _ :: const :: j :: _) => |
174 (needs_fairly_sound, _ :: const :: j :: _) => |
178 nth (AList.lookup (op =) helper_table (const, needs_fairly_sound) |
175 nth (AList.lookup (op =) helper_table (const, needs_fairly_sound) |> the) |
179 |> the) |
176 (the (Int.fromString j) - 1) |
180 (the (Int.fromString j) - 1) |
|
181 |> snd |> prepare_helper ctxt |
177 |> snd |> prepare_helper ctxt |
182 |> Isa_Raw |> some |
178 |> Isa_Raw |> some |
183 | _ => raise Fail ("malformed helper identifier " ^ quote ident) |
179 | _ => raise Fail ("malformed helper identifier " ^ quote ident) |
184 else case try (unprefix fact_prefix) ident of |
180 else case try (unprefix fact_prefix) ident of |
185 SOME s => |
181 SOME s => |
186 let val s = s |> space_explode "_" |> tl |> space_implode "_" |
182 let val s = s |> space_explode "_" |> tl |> space_implode "_" in |
187 in |
|
188 case Int.fromString s of |
183 case Int.fromString s of |
189 SOME j => |
184 SOME j => Meson.make_meta_clause (snd (nth clauses j)) |> Isa_Raw |> some |
190 Meson.make_meta_clause (snd (nth clauses j)) |> Isa_Raw |> some |
|
191 | NONE => |
185 | NONE => |
192 if String.isPrefix lam_fact_prefix (unascii_of s) then |
186 if String.isPrefix lam_fact_prefix (unascii_of s) then Isa_Lambda_Lifted |> some |
193 Isa_Lambda_Lifted |> some |
187 else raise Fail ("malformed fact identifier " ^ quote ident) |
194 else |
|
195 raise Fail ("malformed fact identifier " ^ quote ident) |
|
196 end |
188 end |
197 | NONE => TrueI |> Isa_Raw |> some |
189 | NONE => TrueI |> Isa_Raw |> some |
198 end |
190 end |
199 | metis_axiom_of_atp _ _ _ _ = raise Fail "not CNF -- expected formula" |
191 | metis_axiom_of_atp _ _ _ _ = raise Fail "not CNF -- expected formula" |
200 |
192 |
201 fun eliminate_lam_wrappers (Const (@{const_name Metis.lambda}, _) $ t) = |
193 fun eliminate_lam_wrappers (Const (@{const_name Metis.lambda}, _) $ t) = eliminate_lam_wrappers t |
202 eliminate_lam_wrappers t |
194 | eliminate_lam_wrappers (t $ u) = eliminate_lam_wrappers t $ eliminate_lam_wrappers u |
203 | eliminate_lam_wrappers (t $ u) = |
195 | eliminate_lam_wrappers (Abs (s, T, t)) = Abs (s, T, eliminate_lam_wrappers t) |
204 eliminate_lam_wrappers t $ eliminate_lam_wrappers u |
|
205 | eliminate_lam_wrappers (Abs (s, T, t)) = |
|
206 Abs (s, T, eliminate_lam_wrappers t) |
|
207 | eliminate_lam_wrappers t = t |
196 | eliminate_lam_wrappers t = t |
208 |
197 |
209 (* Function to generate metis clauses, including comb and type clauses *) |
198 (* Function to generate metis clauses, including comb and type clauses *) |
210 fun prepare_metis_problem ctxt type_enc lam_trans conj_clauses fact_clauses = |
199 fun generate_metis_problem ctxt type_enc lam_trans conj_clauses fact_clauses = |
211 let |
200 let |
212 val (conj_clauses, fact_clauses) = |
201 val (conj_clauses, fact_clauses) = |
213 if is_type_enc_polymorphic type_enc then |
202 if is_type_enc_polymorphic type_enc then |
214 (conj_clauses, fact_clauses) |
203 (conj_clauses, fact_clauses) |
215 else |
204 else |
219 |> chop (length conj_clauses) |
208 |> chop (length conj_clauses) |
220 |> pairself (maps (map (zero_var_indexes o snd))) |
209 |> pairself (maps (map (zero_var_indexes o snd))) |
221 val num_conjs = length conj_clauses |
210 val num_conjs = length conj_clauses |
222 (* Pretend every clause is a "simp" rule, to guide the term ordering. *) |
211 (* Pretend every clause is a "simp" rule, to guide the term ordering. *) |
223 val clauses = |
212 val clauses = |
224 map2 (fn j => pair (Int.toString j, (Local, Simp))) |
213 map2 (fn j => pair (Int.toString j, (Local, Simp))) (0 upto num_conjs - 1) conj_clauses @ |
225 (0 upto num_conjs - 1) conj_clauses @ |
|
226 map2 (fn j => pair (Int.toString (num_conjs + j), (Local, Simp))) |
214 map2 (fn j => pair (Int.toString (num_conjs + j), (Local, Simp))) |
227 (0 upto length fact_clauses - 1) fact_clauses |
215 (0 upto length fact_clauses - 1) fact_clauses |
228 val (old_skolems, props) = |
216 val (old_skolems, props) = |
229 fold_rev (fn (name, th) => fn (old_skolems, props) => |
217 fold_rev (fn (name, th) => fn (old_skolems, props) => |
230 th |> prop_of |> Logic.strip_imp_concl |
218 th |> prop_of |> Logic.strip_imp_concl |
231 |> conceal_old_skolem_terms (length clauses) old_skolems |
219 |> conceal_old_skolem_terms (length clauses) old_skolems |
232 ||> (lam_trans = liftingN orelse lam_trans = lam_liftingN) |
220 ||> (lam_trans = liftingN orelse lam_trans = lam_liftingN) ? eliminate_lam_wrappers |
233 ? eliminate_lam_wrappers |
221 ||> (fn prop => (name, prop) :: props)) |
234 ||> (fn prop => (name, prop) :: props)) |
222 clauses ([], []) |
235 clauses ([], []) |
|
236 (* |
223 (* |
237 val _ = |
224 val _ = |
238 tracing ("PROPS:\n" ^ |
225 tracing ("PROPS:\n" ^ |
239 cat_lines (map (Syntax.string_of_term ctxt o snd) props)) |
226 cat_lines (map (Syntax.string_of_term ctxt o snd) props)) |
240 *) |
227 *) |
241 val lam_trans = if lam_trans = combsN then no_lamsN else lam_trans |
228 val lam_trans = if lam_trans = combsN then no_lamsN else lam_trans |
242 val (atp_problem, _, _, lifted, sym_tab) = |
229 val (atp_problem, _, lifted, sym_tab) = |
243 prepare_atp_problem ctxt CNF Hypothesis type_enc Metis lam_trans false |
230 generate_atp_problem ctxt CNF Hypothesis type_enc Metis lam_trans false false false [] |
244 false false [] @{prop False} props |
231 @{prop False} props |
245 (* |
232 (* |
246 val _ = tracing ("ATP PROBLEM: " ^ |
233 val _ = tracing ("ATP PROBLEM: " ^ |
247 cat_lines (lines_of_atp_problem CNF atp_problem)) |
234 cat_lines (lines_of_atp_problem CNF atp_problem)) |
248 *) |
235 *) |
249 (* "rev" is for compatibility with existing proof scripts. *) |
236 (* "rev" is for compatibility with existing proof scripts. *) |
250 val axioms = |
237 val axioms = atp_problem |
251 atp_problem |
|
252 |> maps (map_filter (metis_axiom_of_atp ctxt type_enc clauses) o snd) |> rev |
238 |> maps (map_filter (metis_axiom_of_atp ctxt type_enc clauses) o snd) |> rev |
253 fun ord_info () = atp_problem_term_order_info atp_problem |
239 fun ord_info () = atp_problem_term_order_info atp_problem |
254 in (sym_tab, axioms, ord_info, (lifted, old_skolems)) end |
240 in (sym_tab, axioms, ord_info, (lifted, old_skolems)) end |
255 |
241 |
256 end; |
242 end; |