src/Pure/more_thm.ML
author wenzelm
Sat Apr 14 17:36:10 2007 +0200 (2007-04-14)
changeset 22682 92448396c9d9
parent 22378 8e02a61b401f
child 22695 17073e9b94f2
permissions -rw-r--r--
added read_def_cterms, read_cterm (from thm.ML);
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@22682
    30
  val read_def_cterms:
wenzelm@22682
    31
    theory * (indexname -> typ option) * (indexname -> sort option) ->
wenzelm@22682
    32
    string list -> bool -> (string * typ)list
wenzelm@22682
    33
    -> cterm list * (indexname * typ)list
wenzelm@22682
    34
  val read_cterm: theory -> string * typ -> cterm
wenzelm@22362
    35
end;
wenzelm@22362
    36
wenzelm@22362
    37
structure Thm: THM =
wenzelm@22362
    38
struct
wenzelm@22362
    39
wenzelm@22682
    40
(** compare theorems **)
wenzelm@22362
    41
wenzelm@22682
    42
(* order: ignores theory context! *)
wenzelm@22682
    43
wenzelm@22362
    44
fun thm_ord (th1, th2) =
wenzelm@22362
    45
  let
wenzelm@22362
    46
    val {shyps = shyps1, hyps = hyps1, tpairs = tpairs1, prop = prop1, ...} = Thm.rep_thm th1;
wenzelm@22362
    47
    val {shyps = shyps2, hyps = hyps2, tpairs = tpairs2, prop = prop2, ...} = Thm.rep_thm th2;
wenzelm@22362
    48
  in
wenzelm@22362
    49
    (case Term.fast_term_ord (prop1, prop2) of
wenzelm@22362
    50
      EQUAL =>
wenzelm@22362
    51
        (case list_ord (prod_ord Term.fast_term_ord Term.fast_term_ord) (tpairs1, tpairs2) of
wenzelm@22362
    52
          EQUAL =>
wenzelm@22362
    53
            (case list_ord Term.fast_term_ord (hyps1, hyps2) of
wenzelm@22362
    54
              EQUAL => list_ord Term.sort_ord (shyps1, shyps2)
wenzelm@22362
    55
            | ord => ord)
wenzelm@22362
    56
        | ord => ord)
wenzelm@22362
    57
    | ord => ord)
wenzelm@22362
    58
  end;
wenzelm@22362
    59
wenzelm@22682
    60
wenzelm@22682
    61
(* equality *)
wenzelm@22682
    62
wenzelm@22362
    63
fun eq_thm ths =
wenzelm@22362
    64
  Context.joinable (pairself Thm.theory_of_thm ths) andalso
wenzelm@22362
    65
  thm_ord ths = EQUAL;
wenzelm@22362
    66
wenzelm@22362
    67
val eq_thms = eq_list eq_thm;
wenzelm@22362
    68
wenzelm@22362
    69
val eq_thm_thy = eq_thy o pairself Thm.theory_of_thm;
wenzelm@22362
    70
val eq_thm_prop = op aconv o pairself Thm.full_prop_of;
wenzelm@22362
    71
wenzelm@22682
    72
wenzelm@22682
    73
(* pattern equivalence *)
wenzelm@22682
    74
wenzelm@22362
    75
fun equiv_thm ths =
wenzelm@22362
    76
  Pattern.equiv (Theory.merge (pairself Thm.theory_of_thm ths)) (pairself Thm.full_prop_of ths);
wenzelm@22362
    77
wenzelm@22362
    78
wenzelm@22682
    79
wenzelm@22682
    80
(** theorem kinds **)
wenzelm@22362
    81
wenzelm@22362
    82
val axiomK = "axiom";
wenzelm@22362
    83
val assumptionK = "assumption";
wenzelm@22362
    84
val definitionK = "definition";
wenzelm@22362
    85
val theoremK = "theorem";
wenzelm@22362
    86
val lemmaK = "lemma";
wenzelm@22362
    87
val corollaryK = "corollary";
wenzelm@22362
    88
val internalK = "internal";
wenzelm@22362
    89
wenzelm@22362
    90
wenzelm@22682
    91
wenzelm@22682
    92
(** attributes **)
wenzelm@22362
    93
wenzelm@22362
    94
fun rule_attribute f (x, th) = (x, f x th);
wenzelm@22362
    95
fun declaration_attribute f (x, th) = (f th x, th);
wenzelm@22362
    96
wenzelm@22362
    97
fun apply_attributes mk dest =
wenzelm@22362
    98
  let
wenzelm@22362
    99
    fun app [] = I
wenzelm@22362
   100
      | app ((f: attribute) :: fs) = fn (x, th) => f (mk x, th) |>> dest |> app fs;
wenzelm@22362
   101
  in app end;
wenzelm@22362
   102
wenzelm@22362
   103
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
wenzelm@22362
   104
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
wenzelm@22362
   105
wenzelm@22362
   106
fun no_attributes x = (x, []);
wenzelm@22362
   107
fun simple_fact x = [(x, [])];
wenzelm@22362
   108
wenzelm@22362
   109
wenzelm@22682
   110
(** read/certify terms (obsolete) **)    (*exception ERROR*)
wenzelm@22682
   111
wenzelm@22682
   112
fun read_def_cterms (thy, types, sorts) used freeze sTs =
wenzelm@22682
   113
  let
wenzelm@22682
   114
    val (ts', tye) = Sign.read_def_terms (thy, types, sorts) used freeze sTs;
wenzelm@22682
   115
    val cts = map (Thm.cterm_of thy) ts'
wenzelm@22682
   116
      handle TYPE (msg, _, _) => error msg
wenzelm@22682
   117
           | TERM (msg, _) => error msg;
wenzelm@22682
   118
  in (cts, tye) end;
wenzelm@22682
   119
wenzelm@22682
   120
fun read_cterm thy sT =
wenzelm@22682
   121
  let val ([ct], _) = read_def_cterms (thy, K NONE, K NONE) [] true [sT]
wenzelm@22682
   122
  in ct end;
wenzelm@22682
   123
wenzelm@22682
   124
wenzelm@22362
   125
open Thm;
wenzelm@22362
   126
wenzelm@22362
   127
end;
wenzelm@22362
   128
wenzelm@22362
   129
structure Thmtab = TableFun(type key = thm val ord = Thm.thm_ord);