src/Pure/more_thm.ML
author wenzelm
Mon, 27 Jul 2015 17:44:55 +0200
changeset 60801 7664e0916eec
parent 60642 48dd1cefb4ae
child 60805 4cc49ead6e75
permissions -rw-r--r--
tuned signature;
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
    Author:     Makarius
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
     3
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
     4
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
     5
*)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
     6
23169
37091da05d8e moved aconvc to more_thm.ML;
wenzelm
parents: 22907
diff changeset
     7
infix aconvc;
37091da05d8e moved aconvc to more_thm.ML;
wenzelm
parents: 22907
diff changeset
     8
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
     9
signature BASIC_THM =
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    10
sig
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    11
  include BASIC_THM
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    12
  structure Ctermtab: TABLE
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    13
  structure Thmtab: TABLE
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    14
  val aconvc: cterm * cterm -> bool
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
    15
  type attribute = Context.generic * thm -> Context.generic option * thm option
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    16
end;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    17
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    18
signature THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    19
sig
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    20
  include THM
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    21
  structure Ctermtab: TABLE
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    22
  structure Thmtab: TABLE
24948
wenzelm
parents: 24775
diff changeset
    23
  val aconvc: cterm * cterm -> bool
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
    24
  val add_cterm_frees: cterm -> cterm list -> cterm list
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
    25
  val all_name: string * cterm -> cterm -> cterm
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
    26
  val all: cterm -> cterm -> cterm
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    27
  val mk_binop: cterm -> cterm -> cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    28
  val dest_binop: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    29
  val dest_implies: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    30
  val dest_equals: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    31
  val dest_equals_lhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    32
  val dest_equals_rhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    33
  val lhs_of: thm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    34
  val rhs_of: thm -> cterm
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    35
  val thm_ord: thm * thm -> order
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    36
  val cterm_cache: (cterm -> 'a) -> cterm -> 'a
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    37
  val thm_cache: (thm -> 'a) -> thm -> 'a
23599
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
    38
  val is_reflexive: thm -> bool
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    39
  val eq_thm: thm * thm -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    40
  val eq_thm_prop: thm * thm -> bool
52683
fb028440473e more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents: 51316
diff changeset
    41
  val eq_thm_strict: thm * thm -> bool
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    42
  val equiv_thm: thm * thm -> bool
31944
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
    43
  val class_triv: theory -> class -> thm
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
    44
  val of_sort: ctyp * sort -> thm list
28621
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
    45
  val check_shyps: sort list -> thm -> thm
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    46
  val is_dummy: thm -> bool
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
    47
  val plain_prop_of: thm -> term
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    48
  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
    49
  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
    50
  val merge_thms: thm list * thm list -> thm list
33453
fe551dc9d4bd scalable version of Named_Thms, using Item_Net;
wenzelm
parents: 33373
diff changeset
    51
  val full_rules: thm Item_Net.T
30560
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
    52
  val intro_rules: thm Item_Net.T
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
    53
  val elim_rules: thm Item_Net.T
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
    54
  val declare_hyps: cterm -> Proof.context -> Proof.context
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
    55
  val assume_hyps: cterm -> Proof.context -> thm * Proof.context
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
    56
  val unchecked_hyps: Proof.context -> Proof.context
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
    57
  val restore_hyps: Proof.context -> Proof.context -> Proof.context
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
    58
  val undeclared_hyps: Context.generic -> thm -> term list
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
    59
  val check_hyps: Context.generic -> thm -> thm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    60
  val elim_implies: thm -> thm -> thm
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    61
  val forall_elim_var: int -> thm -> thm
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    62
  val forall_elim_vars: int -> thm -> thm
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
    63
  val instantiate': ctyp option list -> cterm option list -> thm -> thm
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    64
  val global_certify_inst: theory ->
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
    65
    ((indexname * sort) * typ) list * ((indexname * typ) * term) list ->
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
    66
    ((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    67
  val global_certify_instantiate: theory ->
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    68
    ((indexname * sort) * typ) list * ((indexname * typ) * term) list -> thm -> thm
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    69
  val certify_inst: Proof.context ->
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    70
    ((indexname * sort) * typ) list * ((indexname * typ) * term) list ->
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
    71
    ((indexname * sort) * ctyp) list * ((indexname * typ) * cterm) list
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
    72
  val certify_instantiate: Proof.context ->
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
    73
    ((indexname * sort) * typ) list * ((indexname * typ) * term) list -> thm -> thm
35985
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
    74
  val forall_intr_frees: thm -> thm
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 35715
diff changeset
    75
  val unvarify_global: thm -> thm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    76
  val close_derivation: thm -> thm
59969
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
    77
  val rename_params_rule: string list * int -> thm -> thm
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
    78
  val rename_boundvars: term -> term -> thm -> thm
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    79
  val add_axiom: Proof.context -> binding * term -> theory -> (string * thm) * theory
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    80
  val add_axiom_global: binding * term -> theory -> (string * thm) * theory
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    81
  val add_def: Proof.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    82
  val add_def_global: bool -> bool -> binding * term -> theory -> (string * thm) * theory
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
    83
  type attribute = Context.generic * thm -> Context.generic option * thm option
30210
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
    84
  type binding = binding * attribute list
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
    85
  val empty_binding: binding
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    86
  val rule_attribute: (Context.generic -> thm -> thm) -> attribute
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    87
  val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
    88
  val mixed_attribute: (Context.generic * thm -> Context.generic * thm) -> attribute
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
    89
  val apply_attribute: attribute -> thm -> Context.generic -> thm * Context.generic
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
    90
  val attribute_declaration: attribute -> thm -> Context.generic -> Context.generic
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
    91
  val theory_attributes: attribute list -> thm -> theory -> thm * theory
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
    92
  val proof_attributes: attribute list -> thm -> Proof.context -> thm * Proof.context
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    93
  val no_attributes: 'a -> 'a * 'b list
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    94
  val simple_fact: 'a -> ('a * 'b list) list
46830
224d01fec36d tuned signature;
wenzelm
parents: 46775
diff changeset
    95
  val tag_rule: string * string -> thm -> thm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    96
  val untag_rule: string -> thm -> thm
46830
224d01fec36d tuned signature;
wenzelm
parents: 46775
diff changeset
    97
  val tag: string * string -> attribute
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    98
  val untag: string -> attribute
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
    99
  val def_name: string -> string
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   100
  val def_name_optional: string -> string -> string
35238
18ae6ef02fe0 Thm.def_binding;
wenzelm
parents: 33713
diff changeset
   101
  val def_binding: Binding.binding -> Binding.binding
30433
ce5138c92ca7 added def_binding_optional -- robust version of def_name_optional for bindings;
wenzelm
parents: 30342
diff changeset
   102
  val def_binding_optional: Binding.binding -> Binding.binding -> Binding.binding
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   103
  val has_name_hint: thm -> bool
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   104
  val get_name_hint: thm -> string
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   105
  val put_name_hint: string -> thm -> thm
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   106
  val theoremK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   107
  val lemmaK: string
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   108
  val corollaryK: string
42473
aca720fb3936 mark thm tag "kind" as legacy;
wenzelm
parents: 42440
diff changeset
   109
  val legacy_get_kind: thm -> string
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   110
  val kind_rule: string -> thm -> thm
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   111
  val kind: string -> attribute
49062
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   112
  val register_proofs: thm list -> theory -> theory
49011
9c68e43502ce some support for registering forked proofs within Proof.state, using its bottom context;
wenzelm
parents: 49010
diff changeset
   113
  val join_theory_proofs: theory -> unit
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   114
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   115
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   116
structure Thm: THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   117
struct
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   118
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   119
(** basic operations **)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   120
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   121
(* collecting cterms *)
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   122
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   123
val op aconvc = op aconv o apply2 Thm.term_of;
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   124
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   125
fun add_cterm_frees ct =
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   126
  let
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59586
diff changeset
   127
    val thy = Thm.theory_of_cterm ct;
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   128
    val t = Thm.term_of ct;
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   129
  in
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   130
    Term.fold_aterms (fn v as Free _ => insert (op aconvc) (Thm.global_cterm_of thy v) | _ => I) t
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   131
  end;
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   132
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   133
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   134
(* cterm constructors and destructors *)
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   135
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   136
fun all_name (x, t) A =
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   137
  let
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59586
diff changeset
   138
    val thy = Thm.theory_of_cterm t;
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   139
    val T = Thm.typ_of_cterm t;
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59586
diff changeset
   140
  in
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   141
    Thm.apply (Thm.global_cterm_of thy (Const ("Pure.all", (T --> propT) --> propT)))
59616
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59586
diff changeset
   142
      (Thm.lambda_name (x, t) A)
eb59c6968219 tuned -- more explicit use of context;
wenzelm
parents: 59586
diff changeset
   143
  end;
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   144
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   145
fun all t A = all_name ("", t) A;
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   146
46497
89ccf66aa73d renamed Thm.capply to Thm.apply, and Thm.cabs to Thm.lambda in conformance with similar operations in structure Term and Logic;
wenzelm
parents: 45382
diff changeset
   147
fun mk_binop c a b = Thm.apply (Thm.apply c a) b;
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   148
fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct);
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   149
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   150
fun dest_implies ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   151
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   152
    Const ("Pure.imp", _) $ _ $ _ => dest_binop ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   153
  | _ => raise TERM ("dest_implies", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   154
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   155
fun dest_equals ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   156
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   157
    Const ("Pure.eq", _) $ _ $ _ => dest_binop ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   158
  | _ => raise TERM ("dest_equals", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   159
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   160
fun dest_equals_lhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   161
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   162
    Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg1 ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   163
  | _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   164
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   165
fun dest_equals_rhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   166
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   167
    Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   168
  | _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   169
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   170
val lhs_of = dest_equals_lhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   171
val rhs_of = dest_equals_rhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   172
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   173
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   174
(* thm order: ignores theory context! *)
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   175
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   176
fun thm_ord (th1, th2) =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   177
  let
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   178
    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
   179
    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
   180
  in
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35238
diff changeset
   181
    (case Term_Ord.fast_term_ord (prop1, prop2) of
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   182
      EQUAL =>
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35238
diff changeset
   183
        (case list_ord (prod_ord Term_Ord.fast_term_ord Term_Ord.fast_term_ord) (tpairs1, tpairs2) of
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   184
          EQUAL =>
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35238
diff changeset
   185
            (case list_ord Term_Ord.fast_term_ord (hyps1, hyps2) of
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35238
diff changeset
   186
              EQUAL => list_ord Term_Ord.sort_ord (shyps1, shyps2)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   187
            | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   188
        | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   189
    | ord => ord)
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   190
  end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   191
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   192
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   193
(* tables and caches *)
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   194
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   195
structure Ctermtab = Table(type key = cterm val ord = Term_Ord.fast_term_ord o apply2 Thm.term_of);
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   196
structure Thmtab = Table(type key = thm val ord = thm_ord);
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   197
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   198
fun cterm_cache f = Cache.create Ctermtab.empty Ctermtab.lookup Ctermtab.update f;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   199
fun thm_cache f = Cache.create Thmtab.empty Thmtab.lookup Thmtab.update f;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   200
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   201
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   202
(* equality *)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   203
23599
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   204
fun is_reflexive th = op aconv (Logic.dest_equals (Thm.prop_of th))
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   205
  handle TERM _ => false;
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
   206
55547
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   207
val eq_thm = is_equal o thm_ord;
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   208
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   209
val eq_thm_prop = op aconv o apply2 Thm.full_prop_of;
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   210
52683
fb028440473e more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents: 51316
diff changeset
   211
fun eq_thm_strict ths =
55547
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   212
  eq_thm ths andalso
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   213
    let val (rep1, rep2) = apply2 Thm.rep_thm ths in
55547
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   214
      Theory.eq_thy (#thy rep1, #thy rep2) andalso
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   215
      #maxidx rep1 = #maxidx rep2 andalso
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   216
      #tags rep1 = #tags rep2
384bfd19ee61 subtle change of semantics of Thm.eq_thm, e.g. relevant for merge of src/HOL/Tools/Predicate_Compile/core_data.ML (cf. HOL-IMP);
wenzelm
parents: 54996
diff changeset
   217
    end;
52683
fb028440473e more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents: 51316
diff changeset
   218
22682
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
(* pattern equivalence *)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   221
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   222
fun equiv_thm ths =
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   223
  Pattern.equiv (Theory.merge (apply2 Thm.theory_of_thm ths)) (apply2 Thm.full_prop_of ths);
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   224
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   225
31904
a86896359ca4 renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents: 31177
diff changeset
   226
(* type classes and sorts *)
a86896359ca4 renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents: 31177
diff changeset
   227
31944
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
   228
fun class_triv thy c =
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   229
  Thm.of_class (Thm.global_ctyp_of thy (TVar ((Name.aT, 0), [c])), c);
31944
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
   230
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
   231
fun of_sort (T, S) = map (fn c => Thm.of_class (T, c)) S;
28621
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   232
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   233
fun check_shyps sorts raw_th =
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   234
  let
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   235
    val th = Thm.strip_shyps raw_th;
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   236
    val prt_sort = Syntax.pretty_sort_global (Thm.theory_of_thm th);
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   237
    val pending = Sorts.subtract sorts (Thm.extra_shyps th);
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   238
  in
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   239
    if null pending then th
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   240
    else error (Pretty.string_of (Pretty.block (Pretty.str "Pending sort hypotheses:" ::
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   241
      Pretty.brk 1 :: Pretty.commas (map prt_sort pending))))
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   242
  end;
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   243
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   244
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   245
(* misc operations *)
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   246
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   247
fun is_dummy thm =
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   248
  (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
   249
    NONE => false
58001
934d85f14d1d more general dummy: may contain "parked arguments", for example;
wenzelm
parents: 56245
diff changeset
   250
  | SOME t => Term.is_dummy_pattern (Term.head_of t));
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   251
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   252
fun plain_prop_of raw_thm =
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   253
  let
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   254
    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
   255
    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
   256
    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
   257
  in
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   258
    if not (null hyps) then
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   259
      err "theorem may not contain hypotheses"
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   260
    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
   261
      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
   262
    else if not (null tpairs) then
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   263
      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
   264
    else prop
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   265
  end;
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   266
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   267
30564
deddb8a1516f tuned comment;
wenzelm
parents: 30560
diff changeset
   268
(* collections of theorems in canonical order *)
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   269
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   270
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
   271
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
   272
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
   273
33453
fe551dc9d4bd scalable version of Named_Thms, using Item_Net;
wenzelm
parents: 33373
diff changeset
   274
val full_rules = Item_Net.init eq_thm_prop (single o Thm.full_prop_of);
33373
674df68d4df0 adapted Item_Net;
wenzelm
parents: 33315
diff changeset
   275
val intro_rules = Item_Net.init eq_thm_prop (single o Thm.concl_of);
674df68d4df0 adapted Item_Net;
wenzelm
parents: 33315
diff changeset
   276
val elim_rules = Item_Net.init eq_thm_prop (single o Thm.major_prem_of);
30560
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
   277
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
   278
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   279
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   280
(** declared hyps **)
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   281
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   282
structure Hyps = Proof_Data
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   283
(
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   284
  type T = Termtab.set * bool;
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   285
  fun init _ : T = (Termtab.empty, true);
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   286
);
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   287
60324
wenzelm
parents: 59969
diff changeset
   288
fun declare_hyps raw_ct ctxt =
wenzelm
parents: 59969
diff changeset
   289
  let val ct = Thm.transfer_cterm (Proof_Context.theory_of ctxt) raw_ct
wenzelm
parents: 59969
diff changeset
   290
  in (Hyps.map o apfst) (Termtab.update (Thm.term_of ct, ())) ctxt end;
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   291
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   292
fun assume_hyps ct ctxt = (Thm.assume ct, declare_hyps ct ctxt);
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   293
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   294
val unchecked_hyps = (Hyps.map o apsnd) (K false);
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   295
fun restore_hyps ctxt = (Hyps.map o apsnd) (K (#2 (Hyps.get ctxt)));
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   296
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   297
fun undeclared_hyps context th =
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   298
  Thm.hyps_of th
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   299
  |> filter_out
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   300
    (case context of
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   301
      Context.Theory _ => K false
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   302
    | Context.Proof ctxt =>
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   303
        (case Hyps.get ctxt of
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   304
          (_, false) => K true
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   305
        | (hyps, _) => Termtab.defined hyps));
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   306
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   307
fun check_hyps context th =
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   308
  (case undeclared_hyps context th of
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   309
    [] => th
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   310
  | undeclared =>
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   311
      let
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   312
        val ctxt = Context.cases Syntax.init_pretty_global I context;
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   313
      in
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   314
        error (Pretty.string_of (Pretty.big_list "Undeclared hyps:"
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   315
          (map (Pretty.item o single o Syntax.pretty_term ctxt) undeclared)))
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   316
      end);
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   317
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   318
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   319
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   320
(** basic derived rules **)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   321
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   322
(*Elimination of implication
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   323
  A    A ==> B
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   324
  ------------
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   325
        B
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   326
*)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   327
fun elim_implies thA thAB = Thm.implies_elim thAB thA;
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   328
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   329
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   330
(* forall_elim_var(s) *)
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   331
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   332
local
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   333
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   334
fun forall_elim_vars_aux strip_vars i th =
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   335
  let
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   336
    val thy = Thm.theory_of_thm th;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   337
    val {tpairs, prop, ...} = Thm.rep_thm th;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   338
    val add_used = Term.fold_aterms
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   339
      (fn Var ((x, j), _) => if i = j then insert (op =) x else I | _ => I);
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   340
    val used = fold (fn (t, u) => add_used t o add_used u) tpairs (add_used prop []);
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   341
    val vars = strip_vars prop;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   342
    val cvars = (Name.variant_list used (map #1 vars), vars)
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   343
      |> ListPair.map (fn (x, (_, T)) => Thm.global_cterm_of thy (Var ((x, i), T)));
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   344
  in fold Thm.forall_elim cvars th end;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   345
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   346
in
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   347
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   348
val forall_elim_vars = forall_elim_vars_aux Term.strip_all_vars;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   349
33697
wenzelm
parents: 33666
diff changeset
   350
fun forall_elim_var i th =
wenzelm
parents: 33666
diff changeset
   351
  forall_elim_vars_aux
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   352
    (fn Const ("Pure.all", _) $ Abs (a, T, _) => [(a, T)]
33697
wenzelm
parents: 33666
diff changeset
   353
      | _ => raise THM ("forall_elim_vars", i, [th])) i th;
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   354
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   355
end;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   356
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   357
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   358
(* instantiate by left-to-right occurrence of variables *)
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   359
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   360
fun instantiate' cTs cts thm =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   361
  let
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   362
    fun err msg =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   363
      raise TYPE ("instantiate': " ^ msg,
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   364
        map_filter (Option.map Thm.typ_of) cTs,
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   365
        map_filter (Option.map Thm.term_of) cts);
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   366
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   367
    fun zip_vars xs ys =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   368
      zip_options xs ys handle ListPair.UnequalLengths =>
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   369
        err "more instantiations than variables in thm";
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   370
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   371
    val thm' =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   372
      Thm.instantiate ((zip_vars (rev (Thm.fold_terms Term.add_tvars thm [])) cTs), []) thm;
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   373
    val thm'' =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   374
      Thm.instantiate ([], zip_vars (rev (Thm.fold_terms Term.add_vars thm' [])) cts) thm';
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   375
  in thm'' end;
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   376
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   377
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   378
(* certify_instantiate *)
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   379
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   380
fun global_certify_inst thy (instT, inst) =
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   381
 (map (apsnd (Thm.global_ctyp_of thy)) instT,
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   382
  map (apsnd (Thm.global_cterm_of thy)) inst);
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   383
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   384
fun global_certify_instantiate thy insts th =
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   385
  Thm.instantiate (global_certify_inst thy insts) th;
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   386
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   387
fun certify_inst ctxt (instT, inst) =
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   388
 (map (apsnd (Thm.ctyp_of ctxt)) instT,
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   389
  map (apsnd (Thm.cterm_of ctxt)) inst);
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   390
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   391
fun certify_instantiate ctxt insts th =
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   392
  Thm.instantiate (certify_inst ctxt insts) th;
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   393
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   394
35985
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   395
(* forall_intr_frees: generalization over all suitable Free variables *)
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   396
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   397
fun forall_intr_frees th =
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   398
  let
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   399
    val thy = Thm.theory_of_thm th;
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   400
    val {prop, hyps, tpairs, ...} = Thm.rep_thm th;
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   401
    val fixed = fold Term.add_frees (Thm.terms_of_tpairs tpairs @ hyps) [];
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   402
    val frees = Term.fold_aterms (fn Free v =>
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   403
      if member (op =) fixed v then I else insert (op =) v | _ => I) prop [];
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   404
  in fold (Thm.forall_intr o Thm.global_cterm_of thy o Free) frees th end;
35985
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   405
0bbf0d2348f9 moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
wenzelm
parents: 35857
diff changeset
   406
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 35715
diff changeset
   407
(* unvarify_global: global schematic variables *)
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   408
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 35715
diff changeset
   409
fun unvarify_global th =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   410
  let
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   411
    val thy = Thm.theory_of_thm th;
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   412
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   413
    val prop = Thm.full_prop_of th;
35845
e5980f0ad025 renamed varify/unvarify operations to varify_global/unvarify_global to emphasize that these only work in a global situation;
wenzelm
parents: 35715
diff changeset
   414
    val _ = map Logic.unvarify_global (prop :: Thm.hyps_of th)
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   415
      handle TERM (msg, _) => raise THM (msg, 0, [th]);
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   416
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   417
    val instT = rev (Term.add_tvars prop []) |> map (fn v as ((a, _), S) => (v, TFree (a, S)));
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   418
    val inst = rev (Term.add_vars prop []) |> map (fn ((a, i), T) =>
32279
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   419
      let val T' = Term_Subst.instantiateT instT T
e40563627419 added certify_inst, certify_instantiate;
wenzelm
parents: 32198
diff changeset
   420
      in (((a, i), T'), Free ((a, T'))) end);
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   421
  in global_certify_instantiate thy (instT, inst) th end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   422
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   423
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   424
(* close_derivation *)
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   425
26628
63306cb94313 replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents: 25518
diff changeset
   426
fun close_derivation thm =
36744
6e1f3d609a68 renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
wenzelm
parents: 36106
diff changeset
   427
  if Thm.derivation_name thm = "" then Thm.name_derivation "" thm
26628
63306cb94313 replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents: 25518
diff changeset
   428
  else thm;
63306cb94313 replaced Drule.close_derivation/Goal.close_result by Thm.close_derivation (removed obsolete compression);
wenzelm
parents: 25518
diff changeset
   429
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   430
59969
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   431
(* user renaming of parameters in a subgoal *)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   432
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   433
(*The names, if distinct, are used for the innermost parameters of subgoal i;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   434
  preceding parameters may be renamed to make all parameters distinct.*)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   435
fun rename_params_rule (names, i) st =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   436
  let
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   437
    val (_, Bs, Bi, C) = Thm.dest_state (st, i);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   438
    val params = map #1 (Logic.strip_params Bi);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   439
    val short = length params - length names;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   440
    val names' =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   441
      if short < 0 then error "More names than parameters in subgoal!"
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   442
      else Name.variant_list names (take short params) @ names;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   443
    val free_names = Term.fold_aterms (fn Free (x, _) => insert (op =) x | _ => I) Bi [];
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   444
    val Bi' = Logic.list_rename_params names' Bi;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   445
  in
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   446
    (case duplicates (op =) names of
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   447
      a :: _ => (warning ("Can't rename.  Bound variables not distinct: " ^ a); st)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   448
    | [] =>
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   449
      (case inter (op =) names free_names of
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   450
        a :: _ => (warning ("Can't rename.  Bound/Free variable clash: " ^ a); st)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   451
      | [] => Thm.renamed_prop (Logic.list_implies (Bs @ [Bi'], C)) st))
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   452
  end;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   453
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   454
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   455
(* preservation of bound variable names *)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   456
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   457
fun rename_boundvars pat obj th =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   458
  (case Term.rename_abs pat obj (Thm.prop_of th) of
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   459
    NONE => th
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   460
  | SOME prop' => Thm.renamed_prop prop' th);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   461
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   462
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   463
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   464
(** specification primitives **)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   465
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   466
(* rules *)
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   467
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   468
fun stripped_sorts thy t =
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   469
  let
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   470
    val tfrees = rev (Term.add_tfrees t []);
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   471
    val tfrees' = map (fn a => (a, [])) (Name.invent Name.context Name.aT (length tfrees));
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   472
    val recover =
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   473
      map2 (fn (a', S') => fn (a, S) => (((a', 0), S'), Thm.global_ctyp_of thy (TVar ((a, 0), S))))
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   474
        tfrees' tfrees;
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60367
diff changeset
   475
    val strip = map (apply2 TFree) (tfrees ~~ tfrees');
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   476
    val t' = Term.map_types (Term.map_atyps (perhaps (AList.lookup (op =) strip))) t;
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   477
  in (strip, recover, t') end;
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   478
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   479
fun add_axiom ctxt (b, prop) thy =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   480
  let
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   481
    val _ = Sign.no_vars ctxt prop;
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   482
    val (strip, recover, prop') = stripped_sorts thy prop;
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   483
    val constraints = map (fn (TFree (_, S), T) => (T, S)) strip;
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   484
    val of_sorts = maps (fn (T as TFree (_, S), _) => of_sort (Thm.ctyp_of ctxt T, S)) strip;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   485
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   486
    val thy' = thy
51316
dfe469293eb4 discontinued empty name bindings in 'axiomatization';
wenzelm
parents: 49062
diff changeset
   487
      |> Theory.add_axiom ctxt (b, Logic.list_implies (maps Logic.mk_of_sort constraints, prop'));
dfe469293eb4 discontinued empty name bindings in 'axiomatization';
wenzelm
parents: 49062
diff changeset
   488
    val axm_name = Sign.full_name thy' b;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   489
    val axm' = Thm.axiom thy' axm_name;
35988
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   490
    val thm =
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   491
      Thm.instantiate (recover, []) axm'
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   492
      |> unvarify_global
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   493
      |> fold elim_implies of_sorts;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   494
  in ((axm_name, thm), thy') end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   495
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   496
fun add_axiom_global arg thy = add_axiom (Syntax.init_pretty_global thy) arg thy;
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   497
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   498
fun add_def ctxt unchecked overloaded (b, prop) thy =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   499
  let
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   500
    val _ = Sign.no_vars ctxt prop;
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   501
    val prems = map (Thm.cterm_of ctxt) (Logic.strip_imp_prems prop);
35988
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   502
    val (_, recover, concl') = stripped_sorts thy (Logic.strip_imp_concl prop);
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   503
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   504
    val thy' = Theory.add_def ctxt unchecked overloaded (b, concl') thy;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   505
    val axm_name = Sign.full_name thy' b;
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   506
    val axm' = Thm.axiom thy' axm_name;
35988
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   507
    val thm =
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   508
      Thm.instantiate (recover, []) axm'
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   509
      |> unvarify_global
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   510
      |> fold_rev Thm.implies_intr prems;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   511
  in ((axm_name, thm), thy') end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   512
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   513
fun add_def_global unchecked overloaded arg thy =
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   514
  add_def (Syntax.init_pretty_global thy) unchecked overloaded arg thy;
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   515
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   516
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   517
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   518
(** attributes **)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   519
40238
edcdecd55655 type attribute is derived concept outside the kernel;
wenzelm
parents: 39133
diff changeset
   520
(*attributes subsume any kind of rules or context modifiers*)
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   521
type attribute = Context.generic * thm -> Context.generic option * thm option;
40238
edcdecd55655 type attribute is derived concept outside the kernel;
wenzelm
parents: 39133
diff changeset
   522
30210
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
   523
type binding = binding * attribute list;
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
   524
val empty_binding: binding = (Binding.empty, []);
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
   525
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   526
fun rule_attribute f (x, th) = (NONE, SOME (f x th));
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   527
fun declaration_attribute f (x, th) = (SOME (f th x), NONE);
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   528
fun mixed_attribute f (x, th) = let val (x', th') = f (x, th) in (SOME x', SOME th') end;
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   529
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
   530
fun apply_attribute (att: attribute) th x =
54996
aee15e11ee73 check_hyps when attributes are applied;
wenzelm
parents: 54993
diff changeset
   531
  let val (x', th') = att (x, check_hyps x (Thm.transfer (Context.theory_of x) th))
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
   532
  in (the_default th th', the_default x x') end;
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   533
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
   534
fun attribute_declaration att th x = #2 (apply_attribute att th x);
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   535
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   536
fun apply_attributes mk dest =
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   537
  let
46775
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
   538
    fun app [] th x = (th, x)
6287653e63ec canonical argument order for attribute application;
wenzelm
parents: 46497
diff changeset
   539
      | app (att :: atts) th x = apply_attribute att th (mk x) ||> dest |-> app atts;
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   540
  in app end;
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   541
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   542
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   543
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   544
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   545
fun no_attributes x = (x, []);
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   546
fun simple_fact x = [(x, [])];
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   547
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   548
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   549
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   550
(*** theorem tags ***)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   551
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   552
(* add / delete tags *)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   553
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   554
fun tag_rule tg = Thm.map_tags (insert (op =) tg);
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   555
fun untag_rule s = Thm.map_tags (filter_out (fn (s', _) => s = s'));
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   556
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   557
fun tag tg = rule_attribute (K (tag_rule tg));
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   558
fun untag s = rule_attribute (K (untag_rule s));
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   559
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   560
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   561
(* def_name *)
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   562
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   563
fun def_name c = c ^ "_def";
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   564
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   565
fun def_name_optional c "" = def_name c
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   566
  | def_name_optional _ name = name;
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   567
35238
18ae6ef02fe0 Thm.def_binding;
wenzelm
parents: 33713
diff changeset
   568
val def_binding = Binding.map_name def_name;
18ae6ef02fe0 Thm.def_binding;
wenzelm
parents: 33713
diff changeset
   569
30433
ce5138c92ca7 added def_binding_optional -- robust version of def_name_optional for bindings;
wenzelm
parents: 30342
diff changeset
   570
fun def_binding_optional b name =
35238
18ae6ef02fe0 Thm.def_binding;
wenzelm
parents: 33713
diff changeset
   571
  if Binding.is_empty name then def_binding b else name;
30433
ce5138c92ca7 added def_binding_optional -- robust version of def_name_optional for bindings;
wenzelm
parents: 30342
diff changeset
   572
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   573
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   574
(* unofficial theorem names *)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   575
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   576
fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN);
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   577
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   578
val has_name_hint = can the_name_hint;
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   579
val get_name_hint = the_default "??.unknown" o try the_name_hint;
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   580
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   581
fun put_name_hint name = untag_rule Markup.nameN #> tag_rule (Markup.nameN, name);
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   582
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   583
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   584
(* theorem kinds *)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   585
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   586
val theoremK = "theorem";
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   587
val lemmaK = "lemma";
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   588
val corollaryK = "corollary";
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   589
42473
aca720fb3936 mark thm tag "kind" as legacy;
wenzelm
parents: 42440
diff changeset
   590
fun legacy_get_kind thm = the_default "" (Properties.get (Thm.get_tags thm) Markup.kindN);
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   591
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   592
fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
   593
fun kind k = rule_attribute (K (k <> "" ? kind_rule k));
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   594
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   595
49011
9c68e43502ce some support for registering forked proofs within Proof.state, using its bottom context;
wenzelm
parents: 49010
diff changeset
   596
(* forked proofs *)
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   597
49062
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   598
structure Proofs = Theory_Data
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   599
(
49062
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   600
  type T = thm list;
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   601
  val empty = [];
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   602
  fun extend _ = empty;
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   603
  fun merge _ = empty;
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   604
);
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   605
49062
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   606
fun register_proofs more_thms = Proofs.map (fn thms => fold cons more_thms thms);
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   607
val join_theory_proofs = Thm.join_proofs o rev o Proofs.get;
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   608
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   609
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   610
open Thm;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   611
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   612
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   613
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   614
structure Basic_Thm: BASIC_THM = Thm;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   615
open Basic_Thm;
23170
94e9413bd7fc made aconvc pervasive;
wenzelm
parents: 23169
diff changeset
   616