src/Pure/Tools/find_theorems.ML
changeset 33301 1fe9fc908ec3
parent 33290 6dcb0a970783
child 33381 81269c72321a
equal deleted inserted replaced
33300:939ca97f5a11 33301:1fe9fc908ec3
    16   val pretty_thm: Proof.context -> Facts.ref * thm -> Pretty.T
    16   val pretty_thm: Proof.context -> Facts.ref * thm -> Pretty.T
    17   val print_theorems: Proof.context -> thm option -> int option -> bool ->
    17   val print_theorems: Proof.context -> thm option -> int option -> bool ->
    18     (bool * string criterion) list -> unit
    18     (bool * string criterion) list -> unit
    19 end;
    19 end;
    20 
    20 
    21 structure FindTheorems: FIND_THEOREMS =
    21 structure Find_Theorems: FIND_THEOREMS =
    22 struct
    22 struct
    23 
    23 
    24 (** search criteria **)
    24 (** search criteria **)
    25 
    25 
    26 datatype 'term criterion =
    26 datatype 'term criterion =
    27   Name of string | Intro | IntroIff | Elim | Dest | Solves | Simp of 'term |
    27   Name of string | Intro | IntroIff | Elim | Dest | Solves | Simp of 'term |
    28   Pattern of 'term;
    28   Pattern of 'term;
    29 
    29 
    30 fun apply_dummies tm =
    30 fun apply_dummies tm =
    31   strip_abs tm
    31   let
    32   |> fst
    32     val (xs, _) = Term.strip_abs tm;
    33   |> map (Term.dummy_pattern o snd)
    33     val tm' = Term.betapplys (tm, map (Term.dummy_pattern o #2) xs);
    34   |> betapplys o pair tm
    34   in #1 (Term.replace_dummy_patterns tm' 1) end;
    35   |> (fn x => Term.replace_dummy_patterns x 1)
       
    36   |> fst;
       
    37 
    35 
    38 fun parse_pattern ctxt nm =
    36 fun parse_pattern ctxt nm =
    39   let
    37   let
    40     val nm' = case Syntax.parse_term ctxt nm of Const (n, _) => n | _ => nm;
       
    41     val consts = ProofContext.consts_of ctxt;
    38     val consts = ProofContext.consts_of ctxt;
    42   in
    39     val nm' =
    43     nm'
    40       (case Syntax.parse_term ctxt nm of
    44     |> Consts.intern consts
    41         Const (c, _) => c
    45     |> Consts.the_abbreviation consts
    42       | _ => Consts.intern consts nm);
    46     |> snd
    43   in
    47     |> apply_dummies
    44     (case try (Consts.the_abbreviation consts) nm' of
    48     handle TYPE _ => ProofContext.read_term_pattern ctxt nm
    45       SOME (_, rhs) => apply_dummies rhs
       
    46     | NONE => ProofContext.read_term_pattern ctxt nm)
    49   end;
    47   end;
    50 
    48 
    51 fun read_criterion _ (Name name) = Name name
    49 fun read_criterion _ (Name name) = Name name
    52   | read_criterion _ Intro = Intro
    50   | read_criterion _ Intro = Intro
    53   | read_criterion _ IntroIff = IntroIff
    51   | read_criterion _ IntroIff = IntroIff