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