author | blanchet |
Fri, 20 May 2011 17:16:13 +0200 | |
changeset 42893 | fd4babefe3f2 |
parent 42880 | 221af561ebf9 |
child 42894 | ce269ee43800 |
permissions | -rw-r--r-- |
39958 | 1 |
(* Title: HOL/Tools/Metis/metis_translate.ML |
38027 | 2 |
Author: Jia Meng, Cambridge University Computer Laboratory and NICTA |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
3 |
Author: Kong W. Susanto, Cambridge University Computer Laboratory |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
4 |
Author: Lawrence C. Paulson, Cambridge University Computer Laboratory |
36393
be73a2b2443b
support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents:
36378
diff
changeset
|
5 |
Author: Jasmin Blanchette, TU Muenchen |
15347 | 6 |
|
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
7 |
Translation of HOL to FOL for Metis. |
15347 | 8 |
*) |
9 |
||
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
10 |
signature METIS_TRANSLATE = |
24310 | 11 |
sig |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
12 |
type name = string * string |
42650
552eae49f97d
reintroduce this idea of running "metisFT" after a failed "metis" -- I took it out in e85ce10cef1a because I couldn't think of a reasonable use case, but now that ATPs use sound encodings and include dangerous facts (e.g. True_or_False) it makes more sense than ever to run "metisFT" after "metis"
blanchet
parents:
42572
diff
changeset
|
13 |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
14 |
datatype type_literal = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
15 |
TyLitVar of name * name | |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
16 |
TyLitFree of name * name |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
17 |
datatype arLit = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
18 |
TConsLit of name * name * name list | |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
19 |
TVarLit of name * name |
38028 | 20 |
datatype arity_clause = |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
21 |
ArityClause of {name: string, conclLit: arLit, premLits: arLit list} |
38028 | 22 |
datatype class_rel_clause = |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
23 |
ClassRelClause of {name: string, subclass: name, superclass: name} |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
24 |
datatype combterm = |
42562 | 25 |
CombConst of name * typ * typ list (* Const and Free *) | |
26 |
CombVar of name * typ | |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
27 |
CombApp of combterm * combterm |
37923 | 28 |
datatype fol_literal = FOLLiteral of bool * combterm |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
29 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
30 |
datatype mode = FO | HO | FT |
40157 | 31 |
type metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
32 |
{axioms: (Metis_Thm.thm * thm) list, |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
33 |
tfrees: type_literal list, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
34 |
old_skolems: (string * term) list} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
35 |
|
42098
f978caf60bbe
more robust handling of variables in new Skolemizer
blanchet
parents:
41491
diff
changeset
|
36 |
val metis_generated_var_prefix : string |
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
37 |
val type_tag_name : string |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
38 |
val bound_var_prefix : string |
24310 | 39 |
val schematic_var_prefix: string |
40 |
val fixed_var_prefix: string |
|
41 |
val tvar_prefix: string |
|
42 |
val tfree_prefix: string |
|
43 |
val const_prefix: string |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
44 |
val type_const_prefix: string |
24310 | 45 |
val class_prefix: string |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
46 |
val new_skolem_const_prefix : string |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
47 |
val proxify_const : string -> (string * string) option |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
48 |
val invert_const: string -> string |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
49 |
val unproxify_const: string -> string |
24310 | 50 |
val ascii_of: string -> string |
38748 | 51 |
val unascii_of: string -> string |
52 |
val strip_prefix_and_unascii: string -> string -> string option |
|
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
53 |
val make_bound_var : string -> string |
24310 | 54 |
val make_schematic_var : string * int -> string |
18868 | 55 |
val make_fixed_var : string -> string |
56 |
val make_schematic_type_var : string * int -> string |
|
24310 | 57 |
val make_fixed_type_var : string -> string |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
58 |
val make_fixed_const : string -> string |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
59 |
val make_fixed_type_const : string -> string |
18868 | 60 |
val make_type_class : string -> string |
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
61 |
val num_type_args: theory -> string -> int |
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
62 |
val new_skolem_var_name_from_const : string -> string |
36966
adc11fb3f3aa
generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents:
36692
diff
changeset
|
63 |
val type_literals_for_types : typ list -> type_literal list |
39499 | 64 |
val make_class_rel_clauses : |
65 |
theory -> class list -> class list -> class_rel_clause list |
|
66 |
val make_arity_clauses : |
|
67 |
theory -> string list -> class list -> class list * arity_clause list |
|
42562 | 68 |
val combtyp_of : combterm -> typ |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
69 |
val strip_combterm_comb : combterm -> combterm * combterm list |
42727
f365f5138771
ensure type class predicates are generated in symbol declarations (for "poly_preds" and similar)
blanchet
parents:
42650
diff
changeset
|
70 |
val atyps_of : typ -> typ list |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
71 |
val combterm_from_term : |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
72 |
theory -> (string * typ) list -> term -> combterm * typ list |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
73 |
val reveal_old_skolem_terms : (string * term) list -> term -> term |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
74 |
val tfree_classes_of_terms : term list -> string list |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
75 |
val tvar_classes_of_terms : term list -> string list |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
76 |
val type_consts_of_terms : theory -> term list -> string list |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
77 |
val string_of_mode : mode -> string |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
78 |
val metis_helpers : (string * (bool * bool * thm list)) list |
40157 | 79 |
val prepare_metis_problem : |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
80 |
mode -> Proof.context -> bool -> thm list -> thm list list |
40157 | 81 |
-> mode * metis_problem |
24310 | 82 |
end |
15347 | 83 |
|
39494
bf7dd4902321
rename "Metis_Clauses" to "Metis_Translate" for consistency with "Sledgehammer_Translate"
blanchet
parents:
39355
diff
changeset
|
84 |
structure Metis_Translate : METIS_TRANSLATE = |
15347 | 85 |
struct |
86 |
||
42098
f978caf60bbe
more robust handling of variables in new Skolemizer
blanchet
parents:
41491
diff
changeset
|
87 |
val metis_generated_var_prefix = "_" |
f978caf60bbe
more robust handling of variables in new Skolemizer
blanchet
parents:
41491
diff
changeset
|
88 |
|
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
89 |
val type_tag_name = "ti" |
37509
f39464d971c4
factor out TPTP format output into file of its own, to facilitate further changes
blanchet
parents:
37500
diff
changeset
|
90 |
|
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
91 |
val bound_var_prefix = "B_" |
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
92 |
val schematic_var_prefix = "V_" |
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
93 |
val fixed_var_prefix = "v_" |
15347 | 94 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
95 |
val tvar_prefix = "T_"; |
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
96 |
val tfree_prefix = "t_"; |
15347 | 97 |
|
17230
77e93bf303a5
fixed arities and restored changes that had gone missing
paulson
parents:
17150
diff
changeset
|
98 |
val const_prefix = "c_"; |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
99 |
val type_const_prefix = "tc_"; |
24310 | 100 |
val class_prefix = "class_"; |
15347 | 101 |
|
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
102 |
val skolem_const_prefix = "Sledgehammer" ^ Long_Name.separator ^ "Sko" |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
103 |
val old_skolem_const_prefix = skolem_const_prefix ^ "o" |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
104 |
val new_skolem_const_prefix = skolem_const_prefix ^ "n" |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
105 |
|
36218
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
106 |
fun union_all xss = fold (union (op =)) xss [] |
17775 | 107 |
|
42563 | 108 |
val metis_proxies = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
109 |
[("c_False", (@{const_name False}, ("fFalse", @{const_name Metis.fFalse}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
110 |
("c_True", (@{const_name True}, ("fTrue", @{const_name Metis.fTrue}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
111 |
("c_Not", (@{const_name Not}, ("fNot", @{const_name Metis.fNot}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
112 |
("c_conj", (@{const_name conj}, ("fconj", @{const_name Metis.fconj}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
113 |
("c_disj", (@{const_name disj}, ("fdisj", @{const_name Metis.fdisj}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
114 |
("c_implies", (@{const_name implies}, |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
115 |
("fimplies", @{const_name Metis.fimplies}))), |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
116 |
("equal", (@{const_name HOL.eq}, ("fequal", @{const_name Metis.fequal})))] |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
117 |
|
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
118 |
val proxify_const = AList.lookup (op =) metis_proxies #> Option.map snd |
42563 | 119 |
|
36493
a3357a631b96
reintroduced short names for HOL->FOL constants; other parts of the code rely on these
blanchet
parents:
36491
diff
changeset
|
120 |
(* Readable names for the more common symbolic functions. Do not mess with the |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
121 |
table unless you know what you are doing. *) |
15347 | 122 |
val const_trans_table = |
42563 | 123 |
[(@{type_name Product_Type.prod}, "prod"), |
124 |
(@{type_name Sum_Type.sum}, "sum"), |
|
125 |
(@{const_name False}, "False"), |
|
126 |
(@{const_name True}, "True"), |
|
127 |
(@{const_name Not}, "Not"), |
|
128 |
(@{const_name conj}, "conj"), |
|
129 |
(@{const_name disj}, "disj"), |
|
130 |
(@{const_name implies}, "implies"), |
|
131 |
(@{const_name HOL.eq}, "equal"), |
|
132 |
(@{const_name If}, "If"), |
|
133 |
(@{const_name Set.member}, "member"), |
|
134 |
(@{const_name Meson.COMBI}, "COMBI"), |
|
135 |
(@{const_name Meson.COMBK}, "COMBK"), |
|
136 |
(@{const_name Meson.COMBB}, "COMBB"), |
|
137 |
(@{const_name Meson.COMBC}, "COMBC"), |
|
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
138 |
(@{const_name Meson.COMBS}, "COMBS")] |
42563 | 139 |
|> Symtab.make |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
140 |
|> fold (Symtab.update o swap o snd o snd) metis_proxies |
15347 | 141 |
|
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
142 |
(* Invert the table of translations between Isabelle and Metis. *) |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
143 |
val const_trans_table_inv = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
144 |
const_trans_table |> Symtab.dest |> map swap |> Symtab.make |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
145 |
val const_trans_table_unprox = |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
146 |
Symtab.empty |
42572
0c9a947b43fc
drop "fequal" type args for unmangled type systems
blanchet
parents:
42570
diff
changeset
|
147 |
|> fold (fn (_, (isa, (_, metis))) => Symtab.update (metis, isa)) |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
148 |
metis_proxies |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
149 |
|
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
150 |
val invert_const = perhaps (Symtab.lookup const_trans_table_inv) |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
151 |
val unproxify_const = perhaps (Symtab.lookup const_trans_table_unprox) |
15347 | 152 |
|
15610 | 153 |
(*Escaping of special characters. |
154 |
Alphanumeric characters are left unchanged. |
|
155 |
The character _ goes to __ |
|
156 |
Characters in the range ASCII space to / go to _A to _P, respectively. |
|
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38653
diff
changeset
|
157 |
Other characters go to _nnn where nnn is the decimal ASCII code.*) |
24183 | 158 |
val A_minus_space = Char.ord #"A" - Char.ord #" "; |
15610 | 159 |
|
24183 | 160 |
fun stringN_of_int 0 _ = "" |
41491 | 161 |
| stringN_of_int k n = stringN_of_int (k-1) (n div 10) ^ string_of_int (n mod 10); |
15610 | 162 |
|
15347 | 163 |
fun ascii_of_c c = |
15610 | 164 |
if Char.isAlphaNum c then String.str c |
165 |
else if c = #"_" then "__" |
|
24310 | 166 |
else if #" " <= c andalso c <= #"/" |
15610 | 167 |
then "_" ^ String.str (Char.chr (Char.ord c + A_minus_space)) |
38738
0ce517c1970f
make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents:
38653
diff
changeset
|
168 |
else ("_" ^ stringN_of_int 3 (Char.ord c)) (*fixed width, in case more digits follow*) |
15347 | 169 |
|
15610 | 170 |
val ascii_of = String.translate ascii_of_c; |
171 |
||
24183 | 172 |
(** Remove ASCII armouring from names in proof files **) |
173 |
||
174 |
(*We don't raise error exceptions because this code can run inside the watcher. |
|
175 |
Also, the errors are "impossible" (hah!)*) |
|
38748 | 176 |
fun unascii_aux rcs [] = String.implode(rev rcs) |
177 |
| unascii_aux rcs [#"_"] = unascii_aux (#"_"::rcs) [] (*ERROR*) |
|
24183 | 178 |
(*Three types of _ escapes: __, _A to _P, _nnn*) |
38748 | 179 |
| unascii_aux rcs (#"_" :: #"_" :: cs) = unascii_aux (#"_"::rcs) cs |
180 |
| unascii_aux rcs (#"_" :: c :: cs) = |
|
24183 | 181 |
if #"A" <= c andalso c<= #"P" (*translation of #" " to #"/"*) |
38748 | 182 |
then unascii_aux (Char.chr(Char.ord c - A_minus_space) :: rcs) cs |
24310 | 183 |
else |
24183 | 184 |
let val digits = List.take (c::cs, 3) handle Subscript => [] |
24310 | 185 |
in |
24183 | 186 |
case Int.fromString (String.implode digits) of |
38748 | 187 |
NONE => unascii_aux (c:: #"_"::rcs) cs (*ERROR*) |
188 |
| SOME n => unascii_aux (Char.chr n :: rcs) (List.drop (cs, 2)) |
|
24183 | 189 |
end |
38748 | 190 |
| unascii_aux rcs (c::cs) = unascii_aux (c::rcs) cs |
191 |
val unascii_of = unascii_aux [] o String.explode |
|
15347 | 192 |
|
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
193 |
(* If string s has the prefix s1, return the result of deleting it, |
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
194 |
un-ASCII'd. *) |
38748 | 195 |
fun strip_prefix_and_unascii s1 s = |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
196 |
if String.isPrefix s1 s then |
38748 | 197 |
SOME (unascii_of (String.extract (s, size s1, NONE))) |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
198 |
else |
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
199 |
NONE |
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
200 |
|
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
201 |
(*Remove the initial ' character from a type variable, if it is present*) |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
202 |
fun trim_type_var s = |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
203 |
if s <> "" andalso String.sub(s,0) = #"'" then String.extract(s,1,NONE) |
42650
552eae49f97d
reintroduce this idea of running "metisFT" after a failed "metis" -- I took it out in e85ce10cef1a because I couldn't think of a reasonable use case, but now that ATPs use sound encodings and include dangerous facts (e.g. True_or_False) it makes more sense than ever to run "metisFT" after "metis"
blanchet
parents:
42572
diff
changeset
|
204 |
else raise Fail ("trim_type: Malformed type variable encountered: " ^ s) |
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
205 |
|
16903 | 206 |
fun ascii_of_indexname (v,0) = ascii_of v |
41491 | 207 |
| ascii_of_indexname (v,i) = ascii_of v ^ "_" ^ string_of_int i; |
15347 | 208 |
|
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
209 |
fun make_bound_var x = bound_var_prefix ^ ascii_of x |
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
210 |
fun make_schematic_var v = schematic_var_prefix ^ ascii_of_indexname v |
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
211 |
fun make_fixed_var x = fixed_var_prefix ^ ascii_of x |
15347 | 212 |
|
24310 | 213 |
fun make_schematic_type_var (x,i) = |
16925
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
214 |
tvar_prefix ^ (ascii_of_indexname (trim_type_var x,i)); |
0fd7b1438d28
simpler variable names, and no types for monomorphic constants
paulson
parents:
16903
diff
changeset
|
215 |
fun make_fixed_type_var x = tfree_prefix ^ (ascii_of (trim_type_var x)); |
15347 | 216 |
|
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
217 |
fun lookup_const c = |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
218 |
case Symtab.lookup const_trans_table c of |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
219 |
SOME c' => c' |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
220 |
| NONE => ascii_of c |
23075 | 221 |
|
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38795
diff
changeset
|
222 |
(* HOL.eq MUST BE "equal" because it's built into ATPs. *) |
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38795
diff
changeset
|
223 |
fun make_fixed_const @{const_name HOL.eq} = "equal" |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
224 |
| make_fixed_const c = const_prefix ^ lookup_const c |
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
225 |
|
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
226 |
fun make_fixed_type_const c = type_const_prefix ^ lookup_const c |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
227 |
|
17261 | 228 |
fun make_type_class clas = class_prefix ^ ascii_of clas; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
229 |
|
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
230 |
(* The number of type arguments of a constant, zero if it's monomorphic. For |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
231 |
(instances of) Skolem pseudoconstants, this information is encoded in the |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
232 |
constant name. *) |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
233 |
fun num_type_args thy s = |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
234 |
if String.isPrefix skolem_const_prefix s then |
39499 | 235 |
s |> space_explode Long_Name.separator |> List.last |> Int.fromString |> the |
37618
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
236 |
else |
fa57a87f92a0
get rid of Skolem cache by performing CNF-conversion after fact selection
blanchet
parents:
37616
diff
changeset
|
237 |
(s, Sign.the_const_type thy s) |> Sign.const_typargs thy |> length |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
238 |
|
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
239 |
fun new_skolem_var_name_from_const s = |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
240 |
let val ss = s |> space_explode Long_Name.separator in |
40259
c0e34371c2e2
prevent type errors because of inconsistent skolem Var types by giving fresh indices to Skolems
blanchet
parents:
40157
diff
changeset
|
241 |
nth ss (length ss - 2) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
242 |
end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
243 |
|
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
244 |
|
37624 | 245 |
(**** Definitions and functions for FOL clauses for TPTP format output ****) |
36169
27b1cc58715e
store nonmangled names along with mangled type names in Sledgehammer for debugging purposes
blanchet
parents:
36168
diff
changeset
|
246 |
|
37624 | 247 |
type name = string * string |
15347 | 248 |
|
249 |
(**** Isabelle FOL clauses ****) |
|
250 |
||
36556
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36493
diff
changeset
|
251 |
(* The first component is the type class; the second is a TVar or TFree. *) |
81dc2c20f052
use readable names in "debug" mode for type vars + don't pipe facts using "using" but rather give them directly to metis (works better with type variables)
blanchet
parents:
36493
diff
changeset
|
252 |
datatype type_literal = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
253 |
TyLitVar of name * name | |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
254 |
TyLitFree of name * name |
15347 | 255 |
|
24310 | 256 |
(*Make literals for sorted type variables*) |
24940 | 257 |
fun sorts_on_typs_aux (_, []) = [] |
258 |
| sorts_on_typs_aux ((x,i), s::ss) = |
|
259 |
let val sorts = sorts_on_typs_aux ((x,i), ss) |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
260 |
in |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
261 |
if s = the_single @{sort HOL.type} then sorts |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
262 |
else if i = ~1 then TyLitFree (`make_type_class s, `make_fixed_type_var x) :: sorts |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
263 |
else TyLitVar (`make_type_class s, (make_schematic_type_var (x,i), x)) :: sorts |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
264 |
end; |
17150
ce2a1aeb42aa
DFG output now works for untyped rules (ML "ResClause.untyped();")
quigley
parents:
16976
diff
changeset
|
265 |
|
24940 | 266 |
fun sorts_on_typs (TFree (a,s)) = sorts_on_typs_aux ((a,~1),s) |
267 |
| sorts_on_typs (TVar (v,s)) = sorts_on_typs_aux (v,s); |
|
268 |
||
24937
340523598914
context-based treatment of generalization; also handling TFrees in axiom clauses
paulson
parents:
24322
diff
changeset
|
269 |
(*Given a list of sorted type variables, return a list of type literals.*) |
36966
adc11fb3f3aa
generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents:
36692
diff
changeset
|
270 |
fun type_literals_for_types Ts = |
adc11fb3f3aa
generate proper arity declarations for TFrees for SPASS's DFG format;
blanchet
parents:
36692
diff
changeset
|
271 |
fold (union (op =)) (map sorts_on_typs Ts) [] |
20015
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
272 |
|
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
273 |
(** make axiom and conjecture clauses. **) |
1ffcf4802802
Literals aren't sorted any more. Output overloaded constants' type var instantiations.
mengj
parents:
19719
diff
changeset
|
274 |
|
15347 | 275 |
(**** Isabelle arities ****) |
276 |
||
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
277 |
datatype arLit = |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
278 |
TConsLit of name * name * name list | |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
279 |
TVarLit of name * name |
24310 | 280 |
|
35865 | 281 |
datatype arity_clause = |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
282 |
ArityClause of {name: string, conclLit: arLit, premLits: arLit list} |
15347 | 283 |
|
284 |
||
18798 | 285 |
fun gen_TVars 0 = [] |
41491 | 286 |
| gen_TVars n = ("T_" ^ string_of_int n) :: gen_TVars (n-1); |
15347 | 287 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
288 |
fun pack_sort(_,[]) = [] |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
289 |
| pack_sort(tvar, "HOL.type"::srt) = pack_sort (tvar, srt) (*IGNORE sort "type"*) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
290 |
| pack_sort(tvar, cls::srt) = |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
291 |
(`make_type_class cls, (tvar, tvar)) :: pack_sort (tvar, srt) |
24310 | 292 |
|
18411
2d3165a0fb40
No axiom, arity or classrel clauses contain HOL.type. Negative occurrences are
paulson
parents:
18409
diff
changeset
|
293 |
(*Arity of type constructor tcon :: (arg1,...,argN)res*) |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
294 |
fun make_axiom_arity_clause (tcons, name, (cls,args)) = |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
295 |
let |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
296 |
val tvars = gen_TVars (length args) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
297 |
val tvars_srts = ListPair.zip (tvars, args) |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
298 |
in |
39318 | 299 |
ArityClause {name = name, |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
300 |
conclLit = TConsLit (`make_type_class cls, |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
301 |
`make_fixed_type_const tcons, |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
302 |
tvars ~~ tvars), |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
303 |
premLits = map TVarLit (union_all (map pack_sort tvars_srts))} |
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
304 |
end |
15347 | 305 |
|
306 |
||
307 |
(**** Isabelle class relations ****) |
|
308 |
||
37925 | 309 |
datatype class_rel_clause = |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
310 |
ClassRelClause of {name: string, subclass: name, superclass: name} |
24310 | 311 |
|
21290
33b6bb5d6ab8
Improvement to classrel clauses: now outputs the minimum needed.
paulson
parents:
21254
diff
changeset
|
312 |
(*Generate all pairs (sub,super) such that sub is a proper subclass of super in theory thy.*) |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
313 |
fun class_pairs _ [] _ = [] |
21432
625797c592b2
Optimized class_pairs for the common case of no subclasses
paulson
parents:
21416
diff
changeset
|
314 |
| class_pairs thy subs supers = |
36218
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
315 |
let |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
316 |
val class_less = Sorts.class_less (Sign.classes_of thy) |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
317 |
fun add_super sub super = class_less (sub, super) ? cons (sub, super) |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
318 |
fun add_supers sub = fold (add_super sub) supers |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
319 |
in fold add_supers subs [] end |
15347 | 320 |
|
37925 | 321 |
fun make_class_rel_clause (sub,super) = |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
322 |
ClassRelClause {name = sub ^ "_" ^ super, |
37643
f576af716aa6
rewrote the TPTP problem generation code more or less from scratch;
blanchet
parents:
37632
diff
changeset
|
323 |
subclass = `make_type_class sub, |
38105
373351f5f834
don't choke on synonyms when parsing SPASS's Flotter output + renamings;
blanchet
parents:
38028
diff
changeset
|
324 |
superclass = `make_type_class super} |
15347 | 325 |
|
37925 | 326 |
fun make_class_rel_clauses thy subs supers = |
327 |
map make_class_rel_clause (class_pairs thy subs supers); |
|
18868 | 328 |
|
329 |
||
330 |
(** Isabelle arities **) |
|
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
331 |
|
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
332 |
fun arity_clause _ _ (_, []) = [] |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
333 |
| arity_clause seen n (tcons, ("HOL.type",_)::ars) = (*ignore*) |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
334 |
arity_clause seen n (tcons,ars) |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
335 |
| arity_clause seen n (tcons, (ar as (class,_)) :: ars) = |
36692
54b64d4ad524
farewell to old-style mem infixes -- type inference in situations with mem_int and mem_string should provide enough information to resolve the type of (op =)
haftmann
parents:
36556
diff
changeset
|
336 |
if member (op =) seen class then (*multiple arities for the same tycon, class pair*) |
41491 | 337 |
make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class ^ "_" ^ string_of_int n, ar) :: |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
338 |
arity_clause seen (n+1) (tcons,ars) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
339 |
else |
37572
a899f9506f39
more intra-module dependency cleanup + merge "const" and "type_const" tables, since this is safe
blanchet
parents:
37570
diff
changeset
|
340 |
make_axiom_arity_clause (tcons, lookup_const tcons ^ "_" ^ class, ar) :: |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
341 |
arity_clause (class::seen) n (tcons,ars) |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
342 |
|
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
343 |
fun multi_arity_clause [] = [] |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
344 |
| multi_arity_clause ((tcons, ars) :: tc_arlists) = |
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
345 |
arity_clause [] 1 (tcons, ars) @ multi_arity_clause tc_arlists |
17845
1438291d57f0
deletion of Tools/res_types_sorts; removal of absolute numbering of clauses
paulson
parents:
17775
diff
changeset
|
346 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
347 |
(*Generate all pairs (tycon,class,sorts) such that tycon belongs to class in theory thy |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
348 |
provided its arguments have the corresponding sorts.*) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
349 |
fun type_class_pairs thy tycons classes = |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
350 |
let val alg = Sign.classes_of thy |
36218
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
351 |
fun domain_sorts tycon = Sorts.mg_domain alg tycon o single |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
352 |
fun add_class tycon class = |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
353 |
cons (class, domain_sorts tycon class) |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
354 |
handle Sorts.CLASS_ERROR _ => I |
0e4a01f3e7d3
get rid of "List.foldl" + add timestamp to SPASS
blanchet
parents:
36170
diff
changeset
|
355 |
fun try_classes tycon = (tycon, fold (add_class tycon) classes []) |
21373
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
356 |
in map try_classes tycons end; |
18f519614978
Arity clauses are now produced only for types and type classes actually used.
paulson
parents:
21290
diff
changeset
|
357 |
|
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
358 |
(*Proving one (tycon, class) membership may require proving others, so iterate.*) |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
359 |
fun iter_type_class_pairs _ _ [] = ([], []) |
22643
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
360 |
| iter_type_class_pairs thy tycons classes = |
bc3bb8e9594a
Improved and simplified the treatment of classrel/arity clauses
paulson
parents:
22383
diff
changeset
|
361 |
let val cpairs = type_class_pairs thy tycons classes |
33040 | 362 |
val newclasses = union_all (union_all (union_all (map (map #2 o #2) cpairs))) |
363 |
|> subtract (op =) classes |> subtract (op =) HOLogic.typeS |
|
24310 | 364 |
val (classes', cpairs') = iter_type_class_pairs thy tycons newclasses |
33042 | 365 |
in (union (op =) classes' classes, union (op =) cpairs' cpairs) end; |
24310 | 366 |
|
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
367 |
fun make_arity_clauses thy tycons classes = |
24310 | 368 |
let val (classes', cpairs) = iter_type_class_pairs thy tycons classes |
37498
b426cbdb5a23
removed Sledgehammer's support for the DFG syntax;
blanchet
parents:
37479
diff
changeset
|
369 |
in (classes', multi_arity_clause cpairs) end; |
18863 | 370 |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
371 |
datatype combterm = |
42562 | 372 |
CombConst of name * typ * typ list (* Const and Free *) | |
373 |
CombVar of name * typ | |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
374 |
CombApp of combterm * combterm |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
375 |
|
37923 | 376 |
datatype fol_literal = FOLLiteral of bool * combterm |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
377 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
378 |
(*********************************************************************) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
379 |
(* convert a clause with type Term.term to a clause with type clause *) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
380 |
(*********************************************************************) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
381 |
|
42562 | 382 |
fun combtyp_of (CombConst (_, T, _)) = T |
383 |
| combtyp_of (CombVar (_, T)) = T |
|
384 |
| combtyp_of (CombApp (t1, _)) = snd (dest_funT (combtyp_of t1)) |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
385 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
386 |
(*gets the head of a combinator application, along with the list of arguments*) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
387 |
fun strip_combterm_comb u = |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
388 |
let fun stripc (CombApp(t,u), ts) = stripc (t, u::ts) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
389 |
| stripc x = x |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
390 |
in stripc(u,[]) end |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
391 |
|
42562 | 392 |
fun atyps_of T = fold_atyps (insert (op =)) T [] |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
393 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
394 |
fun new_skolem_const_name s num_T_args = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
395 |
[new_skolem_const_prefix, s, string_of_int num_T_args] |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
396 |
|> space_implode Long_Name.separator |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
397 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
398 |
(* Converts a term (with combinators) into a combterm. Also accumulates sort |
37995
06f02b15ef8a
generate full first-order formulas (FOF) in Sledgehammer
blanchet
parents:
37994
diff
changeset
|
399 |
infomation. *) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
400 |
fun combterm_from_term thy bs (P $ Q) = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
401 |
let |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
402 |
val (P', P_atomics_Ts) = combterm_from_term thy bs P |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
403 |
val (Q', Q_atomics_Ts) = combterm_from_term thy bs Q |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
404 |
in (CombApp (P', Q'), union (op =) P_atomics_Ts Q_atomics_Ts) end |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
405 |
| combterm_from_term thy _ (Const (c, T)) = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
406 |
let |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
407 |
val tvar_list = |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
408 |
(if String.isPrefix old_skolem_const_prefix c then |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
409 |
[] |> Term.add_tvarsT T |> map TVar |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
410 |
else |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
411 |
(c, T) |> Sign.const_typargs thy) |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
412 |
val c' = CombConst (`make_fixed_const c, T, tvar_list) |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
413 |
in (c', atyps_of T) end |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
414 |
| combterm_from_term _ _ (Free (v, T)) = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
415 |
(CombConst (`make_fixed_var v, T, []), atyps_of T) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
416 |
| combterm_from_term _ _ (Var (v as (s, _), T)) = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
417 |
(if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
418 |
let |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
419 |
val Ts = T |> strip_type |> swap |> op :: |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
420 |
val s' = new_skolem_const_name s (length Ts) |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
421 |
in CombConst (`make_fixed_const s', T, Ts) end |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
422 |
else |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
423 |
CombVar ((make_schematic_var v, s), T), atyps_of T) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
424 |
| combterm_from_term _ bs (Bound j) = |
42570
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
425 |
nth bs j |
77f94ac04f32
cleanup proxification/unproxification and make sure that "num_atp_type_args" is called on the proxy in the reconstruction code, since "c_fequal" has one type arg but the unproxified equal has 0
blanchet
parents:
42563
diff
changeset
|
426 |
|> (fn (s, T) => (CombConst (`make_bound_var s, T, []), atyps_of T)) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
427 |
| combterm_from_term _ _ (Abs _) = raise Fail "HOL clause: Abs" |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
428 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
429 |
fun predicate_of thy ((@{const Not} $ P), pos) = predicate_of thy (P, not pos) |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
430 |
| predicate_of thy (t, pos) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
431 |
(combterm_from_term thy [] (Envir.eta_contract t), pos) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
432 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
433 |
fun literals_of_term1 args thy (@{const Trueprop} $ P) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
434 |
literals_of_term1 args thy P |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
435 |
| literals_of_term1 args thy (@{const HOL.disj} $ P $ Q) = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
436 |
literals_of_term1 (literals_of_term1 args thy P) thy Q |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
437 |
| literals_of_term1 (lits, ts) thy P = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
438 |
let val ((pred, ts'), pol) = predicate_of thy (P, true) in |
37923 | 439 |
(FOLLiteral (pol, pred) :: lits, union (op =) ts ts') |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
440 |
end |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
441 |
val literals_of_term = literals_of_term1 ([], []) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
442 |
|
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
443 |
fun old_skolem_const_name i j num_T_args = |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
444 |
old_skolem_const_prefix ^ Long_Name.separator ^ |
41491 | 445 |
(space_implode Long_Name.separator (map string_of_int [i, j, num_T_args])) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
446 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
447 |
fun conceal_old_skolem_terms i old_skolems t = |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39946
diff
changeset
|
448 |
if exists_Const (curry (op =) @{const_name Meson.skolem} o fst) t then |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
449 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
450 |
fun aux old_skolems |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39946
diff
changeset
|
451 |
(t as (Const (@{const_name Meson.skolem}, Type (_, [_, T])) $ _)) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
452 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
453 |
val (old_skolems, s) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
454 |
if i = ~1 then |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
455 |
(old_skolems, @{const_name undefined}) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
456 |
else case AList.find (op aconv) old_skolems t of |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
457 |
s :: _ => (old_skolems, s) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
458 |
| [] => |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
459 |
let |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
460 |
val s = old_skolem_const_name i (length old_skolems) |
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
461 |
(length (Term.add_tvarsT T [])) |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
462 |
in ((s, t) :: old_skolems, s) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
463 |
in (old_skolems, Const (s, T)) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
464 |
| aux old_skolems (t1 $ t2) = |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
465 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
466 |
val (old_skolems, t1) = aux old_skolems t1 |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
467 |
val (old_skolems, t2) = aux old_skolems t2 |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
468 |
in (old_skolems, t1 $ t2) end |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
469 |
| aux old_skolems (Abs (s, T, t')) = |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
470 |
let val (old_skolems, t') = aux old_skolems t' in |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
471 |
(old_skolems, Abs (s, T, t')) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
472 |
end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
473 |
| aux old_skolems t = (old_skolems, t) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
474 |
in aux old_skolems t end |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
475 |
else |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
476 |
(old_skolems, t) |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
477 |
|
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
478 |
fun reveal_old_skolem_terms old_skolems = |
37632 | 479 |
map_aterms (fn t as Const (s, _) => |
39896
13b3a2ba9ea7
encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents:
39890
diff
changeset
|
480 |
if String.isPrefix old_skolem_const_prefix s then |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
481 |
AList.lookup (op =) old_skolems s |> the |
37632 | 482 |
|> map_types Type_Infer.paramify_vars |
483 |
else |
|
484 |
t |
|
485 |
| t => t) |
|
486 |
||
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
487 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
488 |
(***************************************************************) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
489 |
(* Type Classes Present in the Axiom or Conjecture Clauses *) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
490 |
(***************************************************************) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
491 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
492 |
fun set_insert (x, s) = Symtab.update (x, ()) s |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
493 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
494 |
fun add_classes (sorts, cset) = List.foldl set_insert cset (flat sorts) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
495 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
496 |
(*Remove this trivial type class*) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
497 |
fun delete_type cset = Symtab.delete_safe (the_single @{sort HOL.type}) cset; |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
498 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
499 |
fun tfree_classes_of_terms ts = |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
500 |
let val sorts_list = map (map #2 o OldTerm.term_tfrees) ts |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
501 |
in Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list)) end; |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
502 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
503 |
fun tvar_classes_of_terms ts = |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
504 |
let val sorts_list = map (map #2 o OldTerm.term_tvars) ts |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
505 |
in Symtab.keys (delete_type (List.foldl add_classes Symtab.empty sorts_list)) end; |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
506 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
507 |
(*fold type constructors*) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
508 |
fun fold_type_consts f (Type (a, Ts)) x = fold (fold_type_consts f) Ts (f (a,x)) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
509 |
| fold_type_consts _ _ x = x; |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
510 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
511 |
(*Type constructors used to instantiate overloaded constants are the only ones needed.*) |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
512 |
fun add_type_consts_in_term thy = |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
513 |
let |
38748 | 514 |
fun aux (Const x) = |
515 |
fold (fold_type_consts set_insert) (Sign.const_typargs thy x) |
|
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
516 |
| aux (Abs (_, _, u)) = aux u |
39953
aa54f347e5e2
hide uninteresting MESON/Metis constants and facts and remove "meson_" prefix to (now hidden) fact names
blanchet
parents:
39946
diff
changeset
|
517 |
| aux (Const (@{const_name Meson.skolem}, _) $ _) = I |
37577
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
518 |
| aux (t $ u) = aux t #> aux u |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
519 |
| aux _ = I |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
520 |
in aux end |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
521 |
|
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
522 |
fun type_consts_of_terms thy ts = |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
523 |
Symtab.keys (fold (add_type_consts_in_term thy) ts Symtab.empty); |
5379f41a1322
merge "Sledgehammer_{F,H}OL_Clause", as requested by a FIXME
blanchet
parents:
37575
diff
changeset
|
524 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
525 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
526 |
(* HOL to FOL (Isabelle to Metis) *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
527 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
528 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
529 |
datatype mode = FO | HO | FT (* first-order, higher-order, fully-typed *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
530 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
531 |
fun string_of_mode FO = "FO" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
532 |
| string_of_mode HO = "HO" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
533 |
| string_of_mode FT = "FT" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
534 |
|
42745
b817c6f91a98
reenabled equality proxy in Metis for higher-order reasoning
blanchet
parents:
42727
diff
changeset
|
535 |
fun fn_isa_to_met_sublevel "equal" = "c_fequal" |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
536 |
| fn_isa_to_met_sublevel "c_False" = "c_fFalse" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
537 |
| fn_isa_to_met_sublevel "c_True" = "c_fTrue" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
538 |
| fn_isa_to_met_sublevel "c_Not" = "c_fNot" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
539 |
| fn_isa_to_met_sublevel "c_conj" = "c_fconj" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
540 |
| fn_isa_to_met_sublevel "c_disj" = "c_fdisj" |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
541 |
| fn_isa_to_met_sublevel "c_implies" = "c_fimplies" |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
542 |
| fn_isa_to_met_sublevel x = x |
42758
865ce93ce025
handle equality proxy in a more backward-compatible way
blanchet
parents:
42745
diff
changeset
|
543 |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
544 |
fun fn_isa_to_met_toplevel "equal" = "=" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
545 |
| fn_isa_to_met_toplevel x = x |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
546 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
547 |
fun metis_lit b c args = (b, (c, args)); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
548 |
|
42562 | 549 |
fun metis_term_from_typ (Type (s, Ts)) = |
550 |
Metis_Term.Fn (make_fixed_type_const s, map metis_term_from_typ Ts) |
|
551 |
| metis_term_from_typ (TFree (s, _)) = |
|
552 |
Metis_Term.Fn (make_fixed_type_var s, []) |
|
553 |
| metis_term_from_typ (TVar (x, _)) = |
|
554 |
Metis_Term.Var (make_schematic_type_var x) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
555 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
556 |
(*These two functions insert type literals before the real literals. That is the |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
557 |
opposite order from TPTP linkup, but maybe OK.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
558 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
559 |
fun hol_term_to_fol_FO tm = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
560 |
case strip_combterm_comb tm of |
42562 | 561 |
(CombConst ((c, _), _, Ts), tms) => |
562 |
let val tyargs = map metis_term_from_typ Ts |
|
563 |
val args = map hol_term_to_fol_FO tms |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
564 |
in Metis_Term.Fn (c, tyargs @ args) end |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
565 |
| (CombVar ((v, _), _), []) => Metis_Term.Var v |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
566 |
| _ => raise Fail "non-first-order combterm" |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
567 |
|
42562 | 568 |
fun hol_term_to_fol_HO (CombConst ((a, _), _, Ts)) = |
569 |
Metis_Term.Fn (fn_isa_to_met_sublevel a, map metis_term_from_typ Ts) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
570 |
| hol_term_to_fol_HO (CombVar ((s, _), _)) = Metis_Term.Var s |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
571 |
| hol_term_to_fol_HO (CombApp (tm1, tm2)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
572 |
Metis_Term.Fn (".", map hol_term_to_fol_HO [tm1, tm2]); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
573 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
574 |
(*The fully-typed translation, to avoid type errors*) |
42562 | 575 |
fun tag_with_type tm T = |
576 |
Metis_Term.Fn (type_tag_name, [tm, metis_term_from_typ T]) |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
577 |
|
41138
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
578 |
fun hol_term_to_fol_FT (CombVar ((s, _), ty)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
579 |
tag_with_type (Metis_Term.Var s) ty |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
580 |
| hol_term_to_fol_FT (CombConst ((a, _), ty, _)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
581 |
tag_with_type (Metis_Term.Fn (fn_isa_to_met_sublevel a, [])) ty |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
582 |
| hol_term_to_fol_FT (tm as CombApp (tm1,tm2)) = |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
583 |
tag_with_type (Metis_Term.Fn (".", map hol_term_to_fol_FT [tm1, tm2])) |
eb80538166b6
implemented partially-typed "tags" type encoding
blanchet
parents:
40259
diff
changeset
|
584 |
(combtyp_of tm) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
585 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
586 |
fun hol_literal_to_fol FO (FOLLiteral (pos, tm)) = |
42562 | 587 |
let |
588 |
val (CombConst((p, _), _, Ts), tms) = strip_combterm_comb tm |
|
589 |
val tylits = if p = "equal" then [] else map metis_term_from_typ Ts |
|
590 |
val lits = map hol_term_to_fol_FO tms |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
591 |
in metis_lit pos (fn_isa_to_met_toplevel p) (tylits @ lits) end |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
592 |
| hol_literal_to_fol HO (FOLLiteral (pos, tm)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
593 |
(case strip_combterm_comb tm of |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
594 |
(CombConst(("equal", _), _, _), tms) => |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
595 |
metis_lit pos "=" (map hol_term_to_fol_HO tms) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
596 |
| _ => metis_lit pos "{}" [hol_term_to_fol_HO tm]) (*hBOOL*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
597 |
| hol_literal_to_fol FT (FOLLiteral (pos, tm)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
598 |
(case strip_combterm_comb tm of |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
599 |
(CombConst(("equal", _), _, _), tms) => |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
600 |
metis_lit pos "=" (map hol_term_to_fol_FT tms) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
601 |
| _ => metis_lit pos "{}" [hol_term_to_fol_FT tm]) (*hBOOL*); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
602 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
603 |
fun literals_of_hol_term thy mode t = |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
604 |
let val (lits, types_sorts) = literals_of_term thy t in |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
605 |
(map (hol_literal_to_fol mode) lits, types_sorts) |
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
606 |
end |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
607 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
608 |
(*Sign should be "true" for conjecture type constraints, "false" for type lits in clauses.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
609 |
fun metis_of_type_literals pos (TyLitVar ((s, _), (s', _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
610 |
metis_lit pos s [Metis_Term.Var s'] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
611 |
| metis_of_type_literals pos (TyLitFree ((s, _), (s', _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
612 |
metis_lit pos s [Metis_Term.Fn (s',[])] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
613 |
|
42352 | 614 |
fun has_default_sort _ (TVar _) = false |
615 |
| has_default_sort ctxt (TFree (x, s)) = |
|
616 |
(s = the_default [] (Variable.def_sort ctxt (x, ~1))); |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
617 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
618 |
fun metis_of_tfree tf = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
619 |
Metis_Thm.axiom (Metis_LiteralSet.singleton (metis_of_type_literals true tf)); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
620 |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
621 |
fun hol_thm_to_fol is_conjecture ctxt type_lits mode j old_skolems th = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
622 |
let |
42361 | 623 |
val thy = Proof_Context.theory_of ctxt |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
624 |
val (old_skolems, (mlits, types_sorts)) = |
39888 | 625 |
th |> prop_of |> Logic.strip_imp_concl |
626 |
|> conceal_old_skolem_terms j old_skolems |
|
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
627 |
||> (HOLogic.dest_Trueprop #> literals_of_hol_term thy mode) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
628 |
in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
629 |
if is_conjecture then |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
630 |
(Metis_Thm.axiom (Metis_LiteralSet.fromList mlits), |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
631 |
type_literals_for_types types_sorts, old_skolems) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
632 |
else |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
633 |
let |
42352 | 634 |
val tylits = types_sorts |> filter_out (has_default_sort ctxt) |
635 |
|> type_literals_for_types |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
636 |
val mtylits = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
637 |
if type_lits then map (metis_of_type_literals false) tylits else [] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
638 |
in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
639 |
(Metis_Thm.axiom (Metis_LiteralSet.fromList(mtylits @ mlits)), [], |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
640 |
old_skolems) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
641 |
end |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
642 |
end; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
643 |
|
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
644 |
(* The first Boolean indicates that a fairly sound type encoding is needed. |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
645 |
The second Boolean indicates whether the helper should be kept in |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
646 |
polymorphic encodings that erase most of the types. (The K combinator is |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
647 |
then omitted to prevent finding a contradiction with "Suc n ~= n".) *) |
41140
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
648 |
val metis_helpers = |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
649 |
[("COMBI", (false, true, @{thms Meson.COMBI_def})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
650 |
("COMBK", (false, false, @{thms Meson.COMBK_def})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
651 |
("COMBB", (false, true, @{thms Meson.COMBB_def})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
652 |
("COMBC", (false, true, @{thms Meson.COMBC_def})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
653 |
("COMBS", (false, true, @{thms Meson.COMBS_def})), |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
654 |
("fequal", |
42758
865ce93ce025
handle equality proxy in a more backward-compatible way
blanchet
parents:
42745
diff
changeset
|
655 |
(* This is a lie: Higher-order equality doesn't need a sound type encoding. |
865ce93ce025
handle equality proxy in a more backward-compatible way
blanchet
parents:
42745
diff
changeset
|
656 |
However, this is done so for backward compatibility: Including the |
865ce93ce025
handle equality proxy in a more backward-compatible way
blanchet
parents:
42745
diff
changeset
|
657 |
equality helpers by default in Metis breaks a few existing proofs. *) |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
658 |
(true, true, @{thms fequal_def [THEN Meson.iff_to_disjD, THEN conjunct1] |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
659 |
fequal_def [THEN Meson.iff_to_disjD, THEN conjunct2]})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
660 |
("fFalse", (true, true, @{thms True_or_False})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
661 |
("fFalse", (false, true, [@{lemma "~ fFalse" by (unfold fFalse_def) fast}])), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
662 |
("fTrue", (true, true, @{thms True_or_False})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
663 |
("fTrue", (false, true, [@{lemma "fTrue" by (unfold fTrue_def) fast}])), |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
664 |
("fNot", |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
665 |
(false, true, @{thms fNot_def [THEN Meson.iff_to_disjD, THEN conjunct1] |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
666 |
fNot_def [THEN Meson.iff_to_disjD, THEN conjunct2]})), |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
667 |
("fconj", |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
668 |
(false, true, |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
669 |
@{lemma "~ P | ~ Q | fconj P Q" "~ fconj P Q | P" "~ fconj P Q | Q" |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
670 |
by (unfold fconj_def) fast+})), |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
671 |
("fdisj", |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
672 |
(false, true, |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
673 |
@{lemma "~ P | fdisj P Q" "~ Q | fdisj P Q" "~ fdisj P Q | P | Q" |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
674 |
by (unfold fdisj_def) fast+})), |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
675 |
("fimplies", |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
676 |
(false, true, @{lemma "P | fimplies P Q" "~ Q | fimplies P Q" |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
677 |
"~ fimplies P Q | ~ P | Q" |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
678 |
by (unfold fimplies_def) fast+})), |
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
679 |
("If", (true, true, @{thms if_True if_False True_or_False}))] |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
680 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
681 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
682 |
(* Logic maps manage the interface between HOL and first-order logic. *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
683 |
(* ------------------------------------------------------------------------- *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
684 |
|
40157 | 685 |
type metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
686 |
{axioms: (Metis_Thm.thm * thm) list, |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
687 |
tfrees: type_literal list, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
688 |
old_skolems: (string * term) list} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
689 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
690 |
fun is_quasi_fol_clause thy = |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
691 |
Meson.is_fol_term thy o snd o conceal_old_skolem_terms ~1 [] o prop_of |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
692 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
693 |
(*Extract TFree constraints from context to include as conjecture clauses*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
694 |
fun init_tfrees ctxt = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
695 |
let fun add ((a,i),s) Ts = if i = ~1 then TFree(a,s) :: Ts else Ts in |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
696 |
Vartab.fold add (#2 (Variable.constraints_of ctxt)) [] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
697 |
|> type_literals_for_types |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
698 |
end; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
699 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
700 |
(*Insert non-logical axioms corresponding to all accumulated TFrees*) |
40157 | 701 |
fun add_tfrees {axioms, tfrees, old_skolems} : metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
702 |
{axioms = map (rpair TrueI o metis_of_tfree) (distinct (op =) tfrees) @ |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
703 |
axioms, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
704 |
tfrees = tfrees, old_skolems = old_skolems} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
705 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
706 |
(*transform isabelle type / arity clause to metis clause *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
707 |
fun add_type_thm [] lmap = lmap |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
708 |
| add_type_thm ((ith, mth) :: cls) {axioms, tfrees, old_skolems} = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
709 |
add_type_thm cls {axioms = (mth, ith) :: axioms, tfrees = tfrees, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
710 |
old_skolems = old_skolems} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
711 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
712 |
fun const_in_metis c (pred, tm_list) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
713 |
let |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
714 |
fun in_mterm (Metis_Term.Var _) = false |
41156 | 715 |
| in_mterm (Metis_Term.Fn (nm, tm_list)) = |
716 |
c = nm orelse exists in_mterm tm_list |
|
717 |
in c = pred orelse exists in_mterm tm_list end |
|
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
718 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
719 |
(* ARITY CLAUSE *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
720 |
fun m_arity_cls (TConsLit ((c, _), (t, _), args)) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
721 |
metis_lit true c [Metis_Term.Fn(t, map (Metis_Term.Var o fst) args)] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
722 |
| m_arity_cls (TVarLit ((c, _), (s, _))) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
723 |
metis_lit false c [Metis_Term.Var s] |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
724 |
(*TrueI is returned as the Isabelle counterpart because there isn't any.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
725 |
fun arity_cls (ArityClause {conclLit, premLits, ...}) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
726 |
(TrueI, |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
727 |
Metis_Thm.axiom (Metis_LiteralSet.fromList (map m_arity_cls (conclLit :: premLits)))); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
728 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
729 |
(* CLASSREL CLAUSE *) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
730 |
fun m_class_rel_cls (subclass, _) (superclass, _) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
731 |
[metis_lit false subclass [Metis_Term.Var "T"], metis_lit true superclass [Metis_Term.Var "T"]]; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
732 |
fun class_rel_cls (ClassRelClause {subclass, superclass, ...}) = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
733 |
(TrueI, Metis_Thm.axiom (Metis_LiteralSet.fromList (m_class_rel_cls subclass superclass))); |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
734 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
735 |
fun type_ext thy tms = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
736 |
let val subs = tfree_classes_of_terms tms |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
737 |
val supers = tvar_classes_of_terms tms |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
738 |
and tycons = type_consts_of_terms thy tms |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
739 |
val (supers', arity_clauses) = make_arity_clauses thy tycons supers |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
740 |
val class_rel_clauses = make_class_rel_clauses thy subs supers' |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
741 |
in map class_rel_cls class_rel_clauses @ map arity_cls arity_clauses |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
742 |
end; |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
743 |
|
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
744 |
(* Function to generate metis clauses, including comb and type clauses *) |
40157 | 745 |
fun prepare_metis_problem mode0 ctxt type_lits cls thss = |
42361 | 746 |
let val thy = Proof_Context.theory_of ctxt |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
747 |
(*The modes FO and FT are sticky. HO can be downgraded to FO.*) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
748 |
fun set_mode FO = FO |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
749 |
| set_mode HO = |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
750 |
if forall (forall (is_quasi_fol_clause thy)) (cls :: thss) then FO |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
751 |
else HO |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
752 |
| set_mode FT = FT |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
753 |
val mode = set_mode mode0 |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
754 |
(*transform isabelle clause to metis clause *) |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
755 |
fun add_thm is_conjecture (isa_ith, metis_ith) |
40157 | 756 |
{axioms, tfrees, old_skolems} : metis_problem = |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
757 |
let |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
758 |
val (mth, tfree_lits, old_skolems) = |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
759 |
hol_thm_to_fol is_conjecture ctxt type_lits mode (length axioms) |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
760 |
old_skolems metis_ith |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
761 |
in |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
762 |
{axioms = (mth, isa_ith) :: axioms, |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
763 |
tfrees = union (op =) tfree_lits tfrees, old_skolems = old_skolems} |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
764 |
end; |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
765 |
val lmap = {axioms = [], tfrees = init_tfrees ctxt, old_skolems = []} |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
766 |
|> fold (add_thm true o `Meson.make_meta_clause) cls |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
767 |
|> add_tfrees |
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
768 |
|> fold (fold (add_thm false o `Meson.make_meta_clause)) thss |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
769 |
val clause_lists = map (Metis_Thm.clause o #1) (#axioms lmap) |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
770 |
fun is_used c = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
771 |
exists (Metis_LiteralSet.exists (const_in_metis c o #2)) clause_lists |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
772 |
val lmap = |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
773 |
if mode = FO then |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
774 |
lmap |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
775 |
else |
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
776 |
let |
41156 | 777 |
val fdefs = @{thms fFalse_def fTrue_def fNot_def fconj_def fdisj_def |
778 |
fimplies_def fequal_def} |
|
41139
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
779 |
val prepare_helper = |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
780 |
zero_var_indexes |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
781 |
#> `(Meson.make_meta_clause |
cb1cbae54dbf
add Metis support for higher-order propositional reasoning
blanchet
parents:
41138
diff
changeset
|
782 |
#> rewrite_rule (map safe_mk_meta_eq fdefs)) |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
783 |
val helper_ths = |
41140
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
784 |
metis_helpers |
42561
23ddc4e3d19c
have properly type-instantiated helper facts (combinators and If)
blanchet
parents:
42544
diff
changeset
|
785 |
|> filter (is_used o prefix const_prefix o fst) |
42893
fd4babefe3f2
prevent unsound combinator proofs in partially typed polymorphic type systems
blanchet
parents:
42880
diff
changeset
|
786 |
|> maps (fn (_, (needs_full_types, _, thms)) => |
41140
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
787 |
if needs_full_types andalso mode <> FT then [] |
9c68004b8c9d
added Sledgehammer support for higher-order propositional reasoning
blanchet
parents:
41139
diff
changeset
|
788 |
else map prepare_helper thms) |
40145
04a05b2a7a36
no need to encode theorem number twice in skolem names
blanchet
parents:
39962
diff
changeset
|
789 |
in lmap |> fold (add_thm false) helper_ths end |
39886
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
790 |
in |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
791 |
(mode, add_type_thm (type_ext thy (maps (map prop_of) (cls :: thss))) lmap) |
8a9f0c97d550
first step towards a new skolemizer that doesn't require "Eps"
blanchet
parents:
39720
diff
changeset
|
792 |
end |
39497
fa16349939b7
complete refactoring of Metis along the lines of Sledgehammer
blanchet
parents:
39494
diff
changeset
|
793 |
|
15347 | 794 |
end; |