153 |> String.translate (fn c => if Char.isPrint c then str c else "") |
153 |> String.translate (fn c => if Char.isPrint c then str c else "") |
154 |> simplify_spaces |
154 |> simplify_spaces |
155 |
155 |
156 (** Structural induction rules **) |
156 (** Structural induction rules **) |
157 |
157 |
158 fun induct_rule_on th = |
158 fun struct_induct_rule_on th = |
159 case Logic.strip_horn (prop_of th) of |
159 case Logic.strip_horn (prop_of th) of |
160 (prems, @{const Trueprop} |
160 (prems, @{const Trueprop} |
161 $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) => |
161 $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) => |
162 if not (is_TVar ind_T) andalso length prems > 1 andalso |
162 if not (is_TVar ind_T) andalso length prems > 1 andalso |
163 exists (exists_subterm (curry (op aconv) p)) prems andalso |
163 exists (exists_subterm (curry (op aconv) p)) prems andalso |
185 fun type_match thy (T1, T2) = |
185 fun type_match thy (T1, T2) = |
186 (Sign.typ_match thy (T2, T1) Vartab.empty; true) |
186 (Sign.typ_match thy (T2, T1) Vartab.empty; true) |
187 handle Type.TYPE_MATCH => false |
187 handle Type.TYPE_MATCH => false |
188 |
188 |
189 fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, (_, th))) = |
189 fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, (_, th))) = |
190 case induct_rule_on th of |
190 case struct_induct_rule_on th of |
191 SOME (p_name, ind_T) => |
191 SOME (p_name, ind_T) => |
192 let val thy = ProofContext.theory_of ctxt in |
192 let val thy = ProofContext.theory_of ctxt in |
193 stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T)) |
193 stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T)) |
194 |> map_filter (try (instantiate_induct_rule ctxt stmt p_name ax)) |
194 |> map_filter (try (instantiate_induct_rule ctxt stmt p_name ax)) |
195 end |
195 end |
333 | _ => do_term t |
333 | _ => do_term t |
334 in Symtab.empty |> fold (do_formula pos) ts end |
334 in Symtab.empty |> fold (do_formula pos) ts end |
335 |
335 |
336 (*Inserts a dummy "constant" referring to the theory name, so that relevance |
336 (*Inserts a dummy "constant" referring to the theory name, so that relevance |
337 takes the given theory into account.*) |
337 takes the given theory into account.*) |
338 fun theory_const_prop_of ({theory_const_rel_weight, |
338 fun theory_constify ({theory_const_rel_weight, theory_const_irrel_weight, ...} |
339 theory_const_irrel_weight, ...} : relevance_fudge) |
339 : relevance_fudge) thy_name t = |
340 th = |
|
341 if exists (curry (op <) 0.0) [theory_const_rel_weight, |
340 if exists (curry (op <) 0.0) [theory_const_rel_weight, |
342 theory_const_irrel_weight] then |
341 theory_const_irrel_weight] then |
343 let |
342 Const (thy_name ^ theory_const_suffix, @{typ bool}) $ t |
344 val name = Context.theory_name (theory_of_thm th) |
|
345 val t = Const (name ^ theory_const_suffix, @{typ bool}) |
|
346 in t $ prop_of th end |
|
347 else |
343 else |
348 prop_of th |
344 t |
|
345 |
|
346 fun theory_const_prop_of fudge th = |
|
347 theory_constify fudge (Context.theory_name (theory_of_thm th)) (prop_of th) |
349 |
348 |
350 (**** Constant / Type Frequencies ****) |
349 (**** Constant / Type Frequencies ****) |
351 |
350 |
352 (* A two-dimensional symbol table counts frequencies of constants. It's keyed |
351 (* A two-dimensional symbol table counts frequencies of constants. It's keyed |
353 first by constant name and second by its list of type instantiations. For the |
352 first by constant name and second by its list of type instantiations. For the |
873 |
872 |
874 fun relevant_facts ctxt no_dangerous_types (threshold0, threshold1) |
873 fun relevant_facts ctxt no_dangerous_types (threshold0, threshold1) |
875 max_relevant is_built_in_const fudge |
874 max_relevant is_built_in_const fudge |
876 (override as {add, only, ...}) chained_ths hyp_ts concl_t = |
875 (override as {add, only, ...}) chained_ths hyp_ts concl_t = |
877 let |
876 let |
|
877 val thy = ProofContext.theory_of ctxt |
878 val decay = Math.pow ((1.0 - threshold1) / (1.0 - threshold0), |
878 val decay = Math.pow ((1.0 - threshold1) / (1.0 - threshold0), |
879 1.0 / Real.fromInt (max_relevant + 1)) |
879 1.0 / Real.fromInt (max_relevant + 1)) |
880 val add_ths = Attrib.eval_thms ctxt add |
880 val add_ths = Attrib.eval_thms ctxt add |
881 val reserved = reserved_isar_keyword_table () |
881 val reserved = reserved_isar_keyword_table () |
882 val ind_stmt = |
882 val ind_stmt = |
899 facts |
899 facts |
900 else if threshold0 > 1.0 orelse threshold0 > threshold1 orelse |
900 else if threshold0 > 1.0 orelse threshold0 > threshold1 orelse |
901 max_relevant = 0 then |
901 max_relevant = 0 then |
902 [] |
902 [] |
903 else |
903 else |
904 relevance_filter ctxt threshold0 decay max_relevant is_built_in_const |
904 ((concl_t |> theory_constify fudge (Context.theory_name thy)) :: hyp_ts) |
905 fudge override facts (concl_t :: hyp_ts)) |
905 |> relevance_filter ctxt threshold0 decay max_relevant is_built_in_const |
|
906 fudge override facts) |
906 |> map (apfst (apfst (fn f => f ()))) |
907 |> map (apfst (apfst (fn f => f ()))) |
907 end |
908 end |
908 |
909 |
909 end; |
910 end; |