109 sig |
109 sig |
110 |
110 |
111 val relevant : int ref |
111 val relevant : int ref |
112 val use_simpset: bool ref |
112 val use_simpset: bool ref |
113 val write_out_clasimp : string -> theory -> term -> |
113 val write_out_clasimp : string -> theory -> term -> |
114 (ResClause.clause * thm) Array.array * int * ResClause.clause list |
114 (ResClause.clause * thm) Array.array * int (* * ResClause.clause list *) |
115 |
115 |
116 end; |
116 end; |
117 |
117 |
118 structure ResClasimp : RES_CLASIMP = |
118 structure ResClasimp : RES_CLASIMP = |
119 struct |
119 struct |
120 val use_simpset = ref true; |
120 val use_simpset = ref true; |
121 (*Relevance filtering is off by default*) |
121 (*Relevance filtering is off by default*) |
122 val relevant = ref 0; |
122 val relevant = ref 0; |
123 |
123 |
124 fun has_name th = ((Thm.name_of_thm th) <> "") |
124 (*The "name" of a theorem is its statement, if nothing else is available.*) |
125 |
125 val plain_string_of_thm = |
126 fun has_name_pair (a,b) = (a <> ""); |
126 setmp show_question_marks false |
127 |
127 (setmp print_mode [] |
|
128 (Pretty.setmp_margin 999 string_of_thm)); |
|
129 |
|
130 fun put_name_pair ("",th) = (ResLib.trim_ends (plain_string_of_thm th), th) |
|
131 | put_name_pair (a,th) = (a,th); |
128 |
132 |
129 (* changed, now it also finds out the name of the theorem. *) |
133 (* changed, now it also finds out the name of the theorem. *) |
130 (* convert a theorem into CNF and then into Clause.clause format. *) |
134 (* convert a theorem into CNF and then into Clause.clause format. *) |
131 |
135 |
132 (* outputs a list of (thm,clause) pairs *) |
136 (* outputs a list of (thm,clause) pairs *) |
140 fun remove_symb str = |
144 fun remove_symb str = |
141 if String.isPrefix "List.op @." str |
145 if String.isPrefix "List.op @." str |
142 then ((String.substring(str,0,5)) ^ (String.extract (str, 10, NONE))) |
146 then ((String.substring(str,0,5)) ^ (String.extract (str, 10, NONE))) |
143 else str; |
147 else str; |
144 |
148 |
|
149 (*FIXME: this logic (especially concat_with_stop) needs to be replaced by code |
|
150 to invert the function ascii_of.*) |
145 fun remove_spaces str = |
151 fun remove_spaces str = |
146 let val strlist = String.tokens Char.isSpace str |
152 let val strlist = String.tokens Char.isSpace str |
147 val spaceless = concat strlist |
153 val spaceless = concat strlist |
148 val strlist' = String.tokens Char.isPunct spaceless |
154 val strlist' = String.tokens Char.isPunct spaceless |
149 in |
155 in |
188 (*Write out the claset and simpset rules of the supplied theory. |
194 (*Write out the claset and simpset rules of the supplied theory. |
189 FIXME: argument "goal" is a hack to allow relevance filtering. |
195 FIXME: argument "goal" is a hack to allow relevance filtering. |
190 To reduce the number of clauses produced, set ResClasimp.relevant:=1*) |
196 To reduce the number of clauses produced, set ResClasimp.relevant:=1*) |
191 fun write_out_clasimp filename thy goal = |
197 fun write_out_clasimp filename thy goal = |
192 let val claset_rules = |
198 let val claset_rules = |
193 ReduceAxiomsN.relevant_filter (!relevant) goal |
199 map put_name_pair |
194 (ResAxioms.claset_rules_of_thy thy); |
200 (ReduceAxiomsN.relevant_filter (!relevant) goal |
195 val named_claset = List.filter has_name_pair claset_rules; |
201 (ResAxioms.claset_rules_of_thy thy)); |
196 |
202 val claset_cls_thms = #1 (ResAxioms.clausify_rules_pairs claset_rules []); |
197 val claset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_claset []); |
|
198 |
203 |
199 val simpset_rules = |
204 val simpset_rules = |
200 ReduceAxiomsN.relevant_filter (!relevant) goal |
205 ReduceAxiomsN.relevant_filter (!relevant) goal |
201 (ResAxioms.simpset_rules_of_thy thy); |
206 (ResAxioms.simpset_rules_of_thy thy); |
202 val named_simpset = |
207 val named_simpset = |
203 map remove_spaces_pair (List.filter has_name_pair simpset_rules) |
208 map remove_spaces_pair (map put_name_pair simpset_rules) |
204 val justnames = map #1 named_simpset |
209 val justnames = map #1 named_simpset |
205 val namestring = concat_with "\n" justnames |
210 val namestring = concat_with "\n" justnames |
206 val _ = File.append (File.tmp_path (Path.basic "clasimp_names")) |
211 val _ = File.append (File.tmp_path (Path.basic "clasimp_names")) |
207 (namestring) |
212 (namestring) |
208 val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []); |
213 val simpset_cls_thms = #1 (ResAxioms.clausify_rules_pairs named_simpset []); |
231 val out = TextIO.openOut filename; |
236 val out = TextIO.openOut filename; |
232 val _= ResLib.writeln_strs out stick_clasrls; |
237 val _= ResLib.writeln_strs out stick_clasrls; |
233 val _= TextIO.flushOut out; |
238 val _= TextIO.flushOut out; |
234 val _= TextIO.closeOut out |
239 val _= TextIO.closeOut out |
235 in |
240 in |
236 (clause_arr, num_of_clauses, clauses) |
241 (clause_arr, num_of_clauses) |
237 end; |
242 end; |
238 |
243 |
239 |
244 |
240 end; |
245 end; |
241 |
246 |