src/Pure/more_thm.ML
author paulson
Fri, 05 Oct 2007 09:59:03 +0200
changeset 24854 0ebcd575d3c6
parent 24775 4f86d3384111
child 24948 c12c16a680a0
permissions -rw-r--r--
filtering out some package theorems
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
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
     5
Further operations on type ctyp/cterm/thm, outside the inference kernel.
22362
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
23169
37091da05d8e moved aconvc to more_thm.ML;
wenzelm
parents: 22907
diff changeset
     8
infix aconvc;
37091da05d8e moved aconvc to more_thm.ML;
wenzelm
parents: 22907
diff changeset
     9
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    10
signature THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    11
sig
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    12
  include THM
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    13
  val aconvc : cterm * cterm -> bool
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    14
  val add_cterm_frees: cterm -> cterm list -> cterm list
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    15
  val mk_binop: cterm -> cterm -> cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    16
  val dest_binop: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    17
  val dest_implies: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    18
  val dest_equals: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    19
  val dest_equals_lhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    20
  val dest_equals_rhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    21
  val lhs_of: thm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    22
  val rhs_of: thm -> cterm
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    23
  val thm_ord: thm * thm -> order
23599
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
    24
  val is_reflexive: thm -> bool
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    25
  val eq_thm: thm * thm -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    26
  val eq_thms: thm list * thm list -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    27
  val eq_thm_thy: thm * thm -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    28
  val eq_thm_prop: thm * thm -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    29
  val equiv_thm: thm * thm -> bool
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    30
  val is_dummy: thm -> bool
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
    31
  val plain_prop_of: thm -> term
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
    32
  val fold_terms: (term -> 'a -> 'a) -> thm -> 'a -> 'a
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    33
  val add_thm: thm -> thm list -> thm list
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    34
  val del_thm: thm -> thm list -> thm list
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    35
  val merge_thms: thm list * thm list -> thm list
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    36
  val axiomK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    37
  val assumptionK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    38
  val definitionK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    39
  val theoremK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    40
  val lemmaK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    41
  val corollaryK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    42
  val internalK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    43
  val rule_attribute: (Context.generic -> thm -> thm) -> attribute
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    44
  val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    45
  val theory_attributes: attribute list -> theory * thm -> theory * thm
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    46
  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
    47
  val no_attributes: 'a -> 'a * 'b list
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    48
  val simple_fact: 'a -> ('a * 'b list) list
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
    49
  val read_def_cterms:
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
    50
    theory * (indexname -> typ option) * (indexname -> sort option) ->
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
    51
    string list -> bool -> (string * typ)list
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
    52
    -> cterm list * (indexname * typ)list
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
    53
  val read_cterm: theory -> string * typ -> cterm
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    54
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    55
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    56
structure Thm: THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    57
struct
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    58
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
    59
(** basic operations **)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    60
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    61
(* collecting cterms *)
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    62
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    63
val op aconvc = op aconv o pairself Thm.term_of;
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    64
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    65
fun add_cterm_frees ct =
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    66
  let
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    67
    val cert = Thm.cterm_of (Thm.theory_of_cterm ct);
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    68
    val t = Thm.term_of ct;
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    69
  in Term.fold_aterms (fn v as Free _ => insert (op aconvc) (cert v) | _ => I) t end;
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    70
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    71
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    72
(* cterm constructors and destructors *)
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    73
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    74
fun mk_binop c a b = Thm.capply (Thm.capply c a) b;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    75
fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct);
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    76
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    77
fun dest_implies ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    78
  (case Thm.term_of ct of
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    79
    Const ("==>", _) $ _ $ _ => dest_binop ct
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    80
  | _ => raise TERM ("dest_implies", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    81
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    82
fun dest_equals ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    83
  (case Thm.term_of ct of
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    84
    Const ("==", _) $ _ $ _ => dest_binop ct
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    85
  | _ => raise TERM ("dest_equals", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    86
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    87
fun dest_equals_lhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    88
  (case Thm.term_of ct of
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    89
    Const ("==", _) $ _ $ _ => Thm.dest_arg1 ct
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    90
  | _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    91
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    92
fun dest_equals_rhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    93
  (case Thm.term_of ct of
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    94
    Const ("==", _) $ _ $ _ => Thm.dest_arg ct
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    95
  | _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    96
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    97
val lhs_of = dest_equals_lhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    98
val rhs_of = dest_equals_rhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    99
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   100
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   101
(* thm order: ignores theory context! *)
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   102
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   103
fun thm_ord (th1, th2) =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   104
  let
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   105
    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
   106
    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
   107
  in
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   108
    (case Term.fast_term_ord (prop1, prop2) of
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   109
      EQUAL =>
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   110
        (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
   111
          EQUAL =>
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   112
            (case list_ord Term.fast_term_ord (hyps1, hyps2) of
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   113
              EQUAL => list_ord Term.sort_ord (shyps1, shyps2)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   114
            | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   115
        | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   116
    | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   117
  end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   118
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   119
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   120
(* equality *)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   121
23599
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   122
fun is_reflexive th = op aconv (Logic.dest_equals (Thm.prop_of th))
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   123
  handle TERM _ => false;
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   124
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   125
fun eq_thm ths =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   126
  Context.joinable (pairself Thm.theory_of_thm ths) andalso
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   127
  thm_ord ths = EQUAL;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   128
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   129
val eq_thms = eq_list eq_thm;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   130
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   131
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
   132
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
   133
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   134
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   135
(* pattern equivalence *)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   136
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   137
fun equiv_thm ths =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   138
  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
   139
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   140
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   141
(* misc operations *)
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   142
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   143
fun is_dummy thm =
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   144
  (case try Logic.dest_term (Thm.concl_of thm) of
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   145
    NONE => false
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   146
  | SOME t => Term.is_dummy_pattern t);
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   147
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   148
fun plain_prop_of raw_thm =
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   149
  let
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   150
    val thm = Thm.strip_shyps raw_thm;
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   151
    fun err msg = raise THM ("plain_prop_of: " ^ msg, 0, [thm]);
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   152
    val {hyps, prop, tpairs, ...} = Thm.rep_thm thm;
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   153
  in
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   154
    if not (null hyps) then
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   155
      err "theorem may not contain hypotheses"
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   156
    else if not (null (Thm.extra_shyps thm)) then
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   157
      err "theorem may not contain sort hypotheses"
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   158
    else if not (null tpairs) then
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   159
      err "theorem may not contain flex-flex pairs"
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   160
    else prop
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   161
  end;
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   162
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   163
fun fold_terms f th =
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   164
  let val {tpairs, prop, hyps, ...} = Thm.rep_thm th
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   165
  in fold (fn (t, u) => f t #> f u) tpairs #> f prop #> fold f hyps end;
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   166
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   167
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   168
(* lists of theorems in canonical order *)
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   169
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   170
val add_thm = update eq_thm_prop;
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   171
val del_thm = remove eq_thm_prop;
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   172
val merge_thms = merge eq_thm_prop;
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   173
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   174
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   175
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   176
(** theorem kinds **)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   177
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   178
val axiomK = "axiom";
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   179
val assumptionK = "assumption";
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   180
val definitionK = "definition";
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   181
val theoremK = "theorem";
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   182
val lemmaK = "lemma";
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   183
val corollaryK = "corollary";
24775
4f86d3384111 Markup.internalK;
wenzelm
parents: 24048
diff changeset
   184
val internalK = Markup.internalK;
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   185
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   186
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   187
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   188
(** attributes **)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   189
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   190
fun rule_attribute f (x, th) = (x, f x th);
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   191
fun declaration_attribute f (x, th) = (f th x, th);
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   192
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   193
fun apply_attributes mk dest =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   194
  let
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   195
    fun app [] = I
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   196
      | 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
   197
  in app end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   198
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   199
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   200
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   201
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   202
fun no_attributes x = (x, []);
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   203
fun simple_fact x = [(x, [])];
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   204
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   205
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   206
(** read/certify terms (obsolete) **)    (*exception ERROR*)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   207
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   208
fun read_def_cterms (thy, types, sorts) used freeze sTs =
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   209
  let
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   210
    val (ts', tye) = Sign.read_def_terms (thy, types, sorts) used freeze sTs;
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   211
    val cts = map (Thm.cterm_of thy) ts'
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   212
      handle TYPE (msg, _, _) => error msg
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   213
           | TERM (msg, _) => error msg;
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   214
  in (cts, tye) end;
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   215
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   216
fun read_cterm thy sT =
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   217
  let val ([ct], _) = read_def_cterms (thy, K NONE, K NONE) [] true [sT]
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   218
  in ct end;
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   219
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   220
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   221
open Thm;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   222
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   223
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   224
23170
94e9413bd7fc made aconvc pervasive;
wenzelm
parents: 23169
diff changeset
   225
val op aconvc = Thm.aconvc;
94e9413bd7fc made aconvc pervasive;
wenzelm
parents: 23169
diff changeset
   226
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   227
structure Thmtab = TableFun(type key = thm val ord = Thm.thm_ord);