src/Pure/Tools/find_theorems.ML
changeset 74525 c960bfcb91db
parent 70545 b93ba98e627a
child 74555 3ba399ecdfaf
equal deleted inserted replaced
74524:8ee3d5d3c1bf 74525:c960bfcb91db
   229   in betapplys (t, ts) end;
   229   in betapplys (t, ts) end;
   230 
   230 
   231 fun get_names t = Term.add_const_names t (Term.add_free_names t []);
   231 fun get_names t = Term.add_const_names t (Term.add_free_names t []);
   232 
   232 
   233 (* Does pat match a subterm of obj? *)
   233 (* Does pat match a subterm of obj? *)
   234 fun matches_subterm thy (pat, obj) =
   234 fun matches_subterm ctxt (pat, obj) =
   235   let
   235   let
   236     fun msub bounds obj = Pattern.matches thy (pat, obj) orelse
   236     val thy = Proof_Context.theory_of ctxt;
       
   237     fun matches obj ctxt' = Pattern.matches thy (pat, obj) orelse
   237       (case obj of
   238       (case obj of
   238         Abs (_, T, t) => msub (bounds + 1) (snd (Term.dest_abs (Name.bound bounds, T, t)))
   239         Abs (_, T, t) =>
   239       | t $ u => msub bounds t orelse msub bounds u
   240           let val ((_, t'), ctxt'') = Variable.dest_abs obj ctxt'
   240       | _ => false)
   241           in matches t' ctxt'' end
   241   in msub 0 obj end;
   242       | t $ u => matches t ctxt' orelse matches u ctxt'
       
   243       | _ => false);
       
   244   in matches obj ctxt end;
   242 
   245 
   243 (*Including all constants and frees is only sound because matching
   246 (*Including all constants and frees is only sound because matching
   244   uses higher-order patterns. If full matching were used, then
   247   uses higher-order patterns. If full matching were used, then
   245   constants that may be subject to beta-reduction after substitution
   248   constants that may be subject to beta-reduction after substitution
   246   of frees should not be included for LHS set because they could be
   249   of frees should not be included for LHS set because they could be
   253     val pat' = (expand_abs o Envir.eta_contract) pat;
   256     val pat' = (expand_abs o Envir.eta_contract) pat;
   254     val pat_consts = get_names pat';
   257     val pat_consts = get_names pat';
   255     fun check ((x, thm), NONE) = check ((x, thm), SOME (get_names (Thm.full_prop_of thm)))
   258     fun check ((x, thm), NONE) = check ((x, thm), SOME (get_names (Thm.full_prop_of thm)))
   256       | check ((_, thm), c as SOME thm_consts) =
   259       | check ((_, thm), c as SOME thm_consts) =
   257          (if subset (op =) (pat_consts, thm_consts) andalso
   260          (if subset (op =) (pat_consts, thm_consts) andalso
   258             matches_subterm (Proof_Context.theory_of ctxt) (pat', Thm.full_prop_of thm)
   261             matches_subterm ctxt (pat', Thm.full_prop_of thm)
   259           then SOME (size_of_term (Thm.prop_of thm), Thm.nprems_of thm, 0) else NONE, c);
   262           then SOME (size_of_term (Thm.prop_of thm), Thm.nprems_of thm, 0) else NONE, c);
   260   in check end;
   263   in check end;
   261 
   264 
   262 
   265 
   263 (* interpret criteria as filters *)
   266 (* interpret criteria as filters *)