src/Pure/more_thm.ML
author wenzelm
Mon Feb 26 23:18:27 2007 +0100 (2007-02-26)
changeset 22362 6470ce514b6e
child 22378 8e02a61b401f
permissions -rw-r--r--
Further operations on type thm, outside the inference kernel.
wenzelm@22362
     1
(*  Title:      Pure/more_thm.ML
wenzelm@22362
     2
    ID:         $Id$
wenzelm@22362
     3
    Author:     Makarius
wenzelm@22362
     4
wenzelm@22362
     5
Further operations on type thm, outside the inference kernel.
wenzelm@22362
     6
*)
wenzelm@22362
     7
wenzelm@22362
     8
signature THM =
wenzelm@22362
     9
sig
wenzelm@22362
    10
  include THM
wenzelm@22362
    11
  val thm_ord: thm * thm -> order
wenzelm@22362
    12
  val eq_thm: thm * thm -> bool
wenzelm@22362
    13
  val eq_thms: thm list * thm list -> bool
wenzelm@22362
    14
  val eq_thm_thy: thm * thm -> bool
wenzelm@22362
    15
  val eq_thm_prop: thm * thm -> bool
wenzelm@22362
    16
  val equiv_thm: thm * thm -> bool
wenzelm@22362
    17
  val axiomK: string
wenzelm@22362
    18
  val assumptionK: string
wenzelm@22362
    19
  val definitionK: string
wenzelm@22362
    20
  val theoremK: string
wenzelm@22362
    21
  val lemmaK: string
wenzelm@22362
    22
  val corollaryK: string
wenzelm@22362
    23
  val internalK: string
wenzelm@22362
    24
  val rule_attribute: (Context.generic -> thm -> thm) -> attribute
wenzelm@22362
    25
  val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
wenzelm@22362
    26
  val theory_attributes: attribute list -> theory * thm -> theory * thm
wenzelm@22362
    27
  val proof_attributes: attribute list -> Proof.context * thm -> Proof.context * thm
wenzelm@22362
    28
  val no_attributes: 'a -> 'a * 'b list
wenzelm@22362
    29
  val simple_fact: 'a -> ('a * 'b list) list
wenzelm@22362
    30
end;
wenzelm@22362
    31
wenzelm@22362
    32
structure Thm: THM =
wenzelm@22362
    33
struct
wenzelm@22362
    34
wenzelm@22362
    35
(* compare theorems *)
wenzelm@22362
    36
wenzelm@22362
    37
(*order: ignores theory context!*)
wenzelm@22362
    38
fun thm_ord (th1, th2) =
wenzelm@22362
    39
  let
wenzelm@22362
    40
    val {shyps = shyps1, hyps = hyps1, tpairs = tpairs1, prop = prop1, ...} = Thm.rep_thm th1;
wenzelm@22362
    41
    val {shyps = shyps2, hyps = hyps2, tpairs = tpairs2, prop = prop2, ...} = Thm.rep_thm th2;
wenzelm@22362
    42
  in
wenzelm@22362
    43
    (case Term.fast_term_ord (prop1, prop2) of
wenzelm@22362
    44
      EQUAL =>
wenzelm@22362
    45
        (case list_ord (prod_ord Term.fast_term_ord Term.fast_term_ord) (tpairs1, tpairs2) of
wenzelm@22362
    46
          EQUAL =>
wenzelm@22362
    47
            (case list_ord Term.fast_term_ord (hyps1, hyps2) of
wenzelm@22362
    48
              EQUAL => list_ord Term.sort_ord (shyps1, shyps2)
wenzelm@22362
    49
            | ord => ord)
wenzelm@22362
    50
        | ord => ord)
wenzelm@22362
    51
    | ord => ord)
wenzelm@22362
    52
  end;
wenzelm@22362
    53
wenzelm@22362
    54
fun eq_thm ths =
wenzelm@22362
    55
  Context.joinable (pairself Thm.theory_of_thm ths) andalso
wenzelm@22362
    56
  thm_ord ths = EQUAL;
wenzelm@22362
    57
wenzelm@22362
    58
val eq_thms = eq_list eq_thm;
wenzelm@22362
    59
wenzelm@22362
    60
val eq_thm_thy = eq_thy o pairself Thm.theory_of_thm;
wenzelm@22362
    61
val eq_thm_prop = op aconv o pairself Thm.full_prop_of;
wenzelm@22362
    62
wenzelm@22362
    63
(*pattern equivalence*)
wenzelm@22362
    64
fun equiv_thm ths =
wenzelm@22362
    65
  Pattern.equiv (Theory.merge (pairself Thm.theory_of_thm ths)) (pairself Thm.full_prop_of ths);
wenzelm@22362
    66
wenzelm@22362
    67
wenzelm@22362
    68
(* theorem kinds *)
wenzelm@22362
    69
wenzelm@22362
    70
val axiomK = "axiom";
wenzelm@22362
    71
val assumptionK = "assumption";
wenzelm@22362
    72
val definitionK = "definition";
wenzelm@22362
    73
val theoremK = "theorem";
wenzelm@22362
    74
val lemmaK = "lemma";
wenzelm@22362
    75
val corollaryK = "corollary";
wenzelm@22362
    76
val internalK = "internal";
wenzelm@22362
    77
wenzelm@22362
    78
wenzelm@22362
    79
wenzelm@22362
    80
(* attributes *)
wenzelm@22362
    81
wenzelm@22362
    82
fun rule_attribute f (x, th) = (x, f x th);
wenzelm@22362
    83
fun declaration_attribute f (x, th) = (f th x, th);
wenzelm@22362
    84
wenzelm@22362
    85
fun apply_attributes mk dest =
wenzelm@22362
    86
  let
wenzelm@22362
    87
    fun app [] = I
wenzelm@22362
    88
      | app ((f: attribute) :: fs) = fn (x, th) => f (mk x, th) |>> dest |> app fs;
wenzelm@22362
    89
  in app end;
wenzelm@22362
    90
wenzelm@22362
    91
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
wenzelm@22362
    92
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
wenzelm@22362
    93
wenzelm@22362
    94
fun no_attributes x = (x, []);
wenzelm@22362
    95
fun simple_fact x = [(x, [])];
wenzelm@22362
    96
wenzelm@22362
    97
wenzelm@22362
    98
open Thm;
wenzelm@22362
    99
wenzelm@22362
   100
end;
wenzelm@22362
   101
wenzelm@22362
   102
structure Thmtab = TableFun(type key = thm val ord = Thm.thm_ord);