src/Pure/more_thm.ML
author wenzelm
Fri, 26 Apr 2024 13:25:44 +0200
changeset 80150 96f60533ec1d
parent 79436 253d86888e84
permissions -rw-r--r--
update Windows test machines;
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
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
    12
  val show_consts: bool Config.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
    13
  val show_hyps: bool Config.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
    14
  val show_tags: bool Config.T
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    15
  val aconvc: cterm * cterm -> bool
45375
7fe19930dfc9 more explicit representation of rule_attribute vs. declaration_attribute vs. mixed_attribute;
wenzelm
parents: 43780
diff changeset
    16
  type attribute = Context.generic * thm -> Context.generic option * thm option
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    17
end;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
    18
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    19
signature THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    20
sig
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    21
  include THM
60952
762cb38a3147 produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60951
diff changeset
    22
  val eq_ctyp: ctyp * ctyp -> bool
24948
wenzelm
parents: 24775
diff changeset
    23
  val aconvc: cterm * cterm -> bool
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    24
  val add_tvars: thm -> ctyp TVars.table -> ctyp TVars.table
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
    25
  val add_vars: thm -> cterm Vars.table -> cterm Vars.table
70159
57503fe1b0ff tuned signature;
wenzelm
parents: 70155
diff changeset
    26
  val dest_funT: ctyp -> ctyp * ctyp
70152
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
    27
  val strip_type: ctyp -> ctyp list * ctyp
74566
8e0f0317e266 ML antiquotations to instantiate types/terms/props;
wenzelm
parents: 74561
diff changeset
    28
  val instantiate_ctyp: ctyp TVars.table -> ctyp -> ctyp
60938
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
    29
  val all_name: Proof.context -> string * cterm -> cterm -> cterm
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
    30
  val all: Proof.context -> cterm -> cterm -> cterm
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    31
  val mk_binop: cterm -> cterm -> cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    32
  val dest_binop: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    33
  val dest_implies: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    34
  val dest_equals: cterm -> cterm * cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    35
  val dest_equals_lhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    36
  val dest_equals_rhs: cterm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    37
  val lhs_of: thm -> cterm
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
    38
  val rhs_of: thm -> cterm
23599
d889725b0d8a added is_reflexive;
wenzelm
parents: 23491
diff changeset
    39
  val is_reflexive: thm -> bool
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    40
  val eq_thm: thm * thm -> bool
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    41
  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
    42
  val eq_thm_strict: thm * thm -> bool
60817
3f38ed5a02c1 clarified context;
wenzelm
parents: 60805
diff changeset
    43
  val equiv_thm: theory -> thm * thm -> bool
31944
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
    44
  val class_triv: theory -> class -> thm
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
    45
  val of_sort: ctyp * sort -> thm list
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
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
    47
  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
    48
  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
    49
  val merge_thms: thm list * thm list -> thm list
74152
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
    50
  val item_net: thm Item_Net.T
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
    51
  val item_net_intro: thm Item_Net.T
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
    52
  val item_net_elim: thm Item_Net.T
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
    53
  val declare_hyps: cterm -> Proof.context -> Proof.context
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
    54
  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
    55
  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
    56
  val restore_hyps: Proof.context -> Proof.context -> Proof.context
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
    57
  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
    58
  val check_hyps: Context.generic -> thm -> thm
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
    59
  val declare_term_sorts: term -> Proof.context -> Proof.context
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
    60
  val extra_shyps': Proof.context -> thm -> sort list
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
    61
  val check_shyps: Proof.context -> thm -> thm
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
    62
  val weaken_sorts': Proof.context -> cterm -> cterm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    63
  val elim_implies: thm -> thm -> thm
61339
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
    64
  val forall_intr_name: string * cterm -> thm -> thm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    65
  val forall_elim_var: int -> thm -> thm
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    66
  val forall_elim_vars: int -> thm -> thm
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
    67
  val instantiate_frees: ctyp TFrees.table * cterm Frees.table -> thm -> thm
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
    68
  val instantiate': ctyp option list -> cterm option 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
    69
  val forall_intr_frees: thm -> thm
74245
282cd3aa6cc6 clarified modules;
wenzelm
parents: 74244
diff changeset
    70
  val forall_intr_vars: thm -> thm
60825
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
    71
  val unvarify_global: theory -> thm -> thm
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
    72
  val unvarify_axiom: theory -> string -> thm
59969
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
    73
  val rename_params_rule: string list * int -> thm -> thm
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
    74
  val rename_boundvars: term -> term -> thm -> thm
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    75
  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
    76
  val add_axiom_global: binding * term -> theory -> (string * thm) * theory
61261
ddb2da7cb2e4 more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents: 61059
diff changeset
    77
  val add_def: Defs.context -> bool -> bool -> binding * term -> theory -> (string * thm) * theory
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
    78
  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
    79
  type attribute = Context.generic * thm -> Context.generic option * thm option
30210
225fa48756b2 added type binding and val empty_binding;
wenzelm
parents: 29579
diff changeset
    80
  type binding = binding * attribute list
46830
224d01fec36d tuned signature;
wenzelm
parents: 46775
diff changeset
    81
  val tag_rule: string * string -> thm -> thm
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    82
  val untag_rule: string -> thm -> thm
61852
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
    83
  val is_free_dummy: thm -> bool
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
    84
  val tag_free_dummy: thm -> thm
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
    85
  val def_name: string -> string
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
    86
  val def_name_optional: string -> string -> string
35238
18ae6ef02fe0 Thm.def_binding;
wenzelm
parents: 33713
diff changeset
    87
  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
    88
  val def_binding_optional: Binding.binding -> Binding.binding -> Binding.binding
62093
bd73a2279fcd more uniform treatment of package internals;
wenzelm
parents: 61853
diff changeset
    89
  val make_def_binding: bool -> Binding.binding -> Binding.binding
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    90
  val has_name_hint: thm -> bool
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    91
  val get_name_hint: thm -> string
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    92
  val put_name_hint: string -> thm -> thm
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
    93
  val theoremK: string
42473
aca720fb3936 mark thm tag "kind" as legacy;
wenzelm
parents: 42440
diff changeset
    94
  val legacy_get_kind: thm -> string
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
    95
  val kind_rule: string -> thm -> thm
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
    96
  val rule_attribute: thm list -> (Context.generic -> thm -> thm) -> attribute
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
    97
  val declaration_attribute: (thm -> Context.generic -> Context.generic) -> attribute
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
    98
  val mixed_attribute: (Context.generic * thm -> Context.generic * thm) -> attribute
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
    99
  val apply_attribute: attribute -> thm -> Context.generic -> thm * Context.generic
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   100
  val attribute_declaration: attribute -> thm -> Context.generic -> Context.generic
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   101
  val theory_attributes: attribute list -> thm -> theory -> thm * theory
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   102
  val proof_attributes: attribute list -> thm -> Proof.context -> thm * Proof.context
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   103
  val no_attributes: 'a -> 'a * 'b list
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   104
  val simple_fact: 'a -> ('a * 'b list) list
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   105
  val tag: string * string -> attribute
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   106
  val untag: string -> attribute
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   107
  val kind: string -> attribute
67671
857da80611ab support for lazy notes in global/local context and Element.Lazy_Notes: name binding and fact without attributes;
wenzelm
parents: 67649
diff changeset
   108
  val register_proofs: thm list lazy -> theory -> theory
64574
1134e4d5e5b7 consolidate nested thms with persistent result, for improved performance;
wenzelm
parents: 64568
diff changeset
   109
  val consolidate_theory: theory -> unit
71023
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   110
  val expose_theory: theory -> unit
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   111
  val show_consts: bool Config.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   112
  val show_hyps: bool Config.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   113
  val show_tags: bool Config.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   114
  val pretty_thm_raw: Proof.context -> {quote: bool, show_hyps: bool} -> thm -> Pretty.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   115
  val pretty_thm: Proof.context -> thm -> Pretty.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   116
  val pretty_thm_item: Proof.context -> thm -> Pretty.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   117
  val pretty_thm_global: theory -> thm -> Pretty.T
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   118
  val string_of_thm: Proof.context -> thm -> string
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   119
  val string_of_thm_global: theory -> thm -> string
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   120
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   121
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   122
structure Thm: THM =
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   123
struct
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   124
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   125
(** basic operations **)
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   126
60952
762cb38a3147 produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60951
diff changeset
   127
(* collecting ctyps and cterms *)
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   128
60952
762cb38a3147 produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60951
diff changeset
   129
val eq_ctyp = op = o apply2 Thm.typ_of;
59058
a78612c67ec0 renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents: 58001
diff changeset
   130
val op aconvc = op aconv o apply2 Thm.term_of;
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   131
74241
eb265f54e3ce more efficient operations: traverse hyps only when required;
wenzelm
parents: 74239
diff changeset
   132
val add_tvars =
74244
12dac3698efd clarified signature;
wenzelm
parents: 74243
diff changeset
   133
  Thm.fold_atomic_ctyps {hyps = false} Term.is_TVar (fn cT => fn tab =>
12dac3698efd clarified signature;
wenzelm
parents: 74243
diff changeset
   134
    let val v = Term.dest_TVar (Thm.typ_of cT)
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   135
    in tab |> not (TVars.defined tab v) ? TVars.add (v, cT) end);
74243
de383840425f more scalable operations;
wenzelm
parents: 74242
diff changeset
   136
74241
eb265f54e3ce more efficient operations: traverse hyps only when required;
wenzelm
parents: 74239
diff changeset
   137
val add_vars =
74244
12dac3698efd clarified signature;
wenzelm
parents: 74243
diff changeset
   138
  Thm.fold_atomic_cterms {hyps = false} Term.is_Var (fn ct => fn tab =>
12dac3698efd clarified signature;
wenzelm
parents: 74243
diff changeset
   139
    let val v = Term.dest_Var (Thm.term_of ct)
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   140
    in tab |> not (Vars.defined tab v) ? Vars.add (v, ct) end);
23491
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   141
c13ca04303de added reasonably efficient add_cterm_frees;
wenzelm
parents: 23170
diff changeset
   142
70155
wenzelm
parents: 70152
diff changeset
   143
(* ctyp operations *)
70152
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   144
70159
57503fe1b0ff tuned signature;
wenzelm
parents: 70155
diff changeset
   145
fun dest_funT cT =
70155
wenzelm
parents: 70152
diff changeset
   146
  (case Thm.typ_of cT of
wenzelm
parents: 70152
diff changeset
   147
    Type ("fun", _) => let val [A, B] = Thm.dest_ctyp cT in (A, B) end
70159
57503fe1b0ff tuned signature;
wenzelm
parents: 70155
diff changeset
   148
  | T => raise TYPE ("dest_funT", [T], []));
70152
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   149
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   150
(* ctyp version of strip_type: maps  [T1,...,Tn]--->T  to   ([T1,T2,...,Tn], T) *)
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   151
fun strip_type cT =
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   152
  (case Thm.typ_of cT of
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   153
    Type ("fun", _) =>
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   154
      let
70159
57503fe1b0ff tuned signature;
wenzelm
parents: 70155
diff changeset
   155
        val (cT1, cT2) = dest_funT cT;
70152
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   156
        val (cTs, cT') = strip_type cT2
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   157
      in (cT1 :: cTs, cT') end
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   158
  | _ => ([], cT));
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   159
74566
8e0f0317e266 ML antiquotations to instantiate types/terms/props;
wenzelm
parents: 74561
diff changeset
   160
fun instantiate_ctyp instT cT =
8e0f0317e266 ML antiquotations to instantiate types/terms/props;
wenzelm
parents: 74561
diff changeset
   161
  Thm.instantiate_cterm (instT, Vars.empty) (Thm.var (("x", 0), cT))
8e0f0317e266 ML antiquotations to instantiate types/terms/props;
wenzelm
parents: 74561
diff changeset
   162
  |> Thm.ctyp_of_cterm;
8e0f0317e266 ML antiquotations to instantiate types/terms/props;
wenzelm
parents: 74561
diff changeset
   163
70152
6218698851b9 tuned signature -- more ctyp operations;
wenzelm
parents: 69575
diff changeset
   164
70155
wenzelm
parents: 70152
diff changeset
   165
(* cterm operations *)
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   166
60938
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
   167
fun all_name ctxt (x, t) A =
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   168
  let
59586
ddf6deaadfe8 clarified signature;
wenzelm
parents: 59582
diff changeset
   169
    val T = Thm.typ_of_cterm t;
60938
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
   170
    val all_const = Thm.cterm_of ctxt (Const ("Pure.all", (T --> propT) --> propT));
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
   171
  in Thm.apply all_const (Thm.lambda_name (x, t) A) end;
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   172
60938
b316f218ef34 clarified context;
wenzelm
parents: 60825
diff changeset
   173
fun all ctxt t A = all_name ctxt ("", t) A;
32198
9bdd47909ea8 lambda/cabs/all: named variants;
wenzelm
parents: 31977
diff changeset
   174
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
   175
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
   176
fun dest_binop ct = (Thm.dest_arg1 ct, Thm.dest_arg ct);
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   177
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   178
fun dest_implies ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   179
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   180
    Const ("Pure.imp", _) $ _ $ _ => dest_binop ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   181
  | _ => raise TERM ("dest_implies", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   182
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   183
fun dest_equals ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   184
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   185
    Const ("Pure.eq", _) $ _ $ _ => dest_binop ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   186
  | _ => raise TERM ("dest_equals", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   187
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   188
fun dest_equals_lhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   189
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   190
    Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg1 ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   191
  | _ => raise TERM ("dest_equals_lhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   192
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   193
fun dest_equals_rhs ct =
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   194
  (case Thm.term_of ct of
56245
84fc7dfa3cd4 more qualified names;
wenzelm
parents: 55633
diff changeset
   195
    Const ("Pure.eq", _) $ _ $ _ => Thm.dest_arg ct
22907
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   196
  | _ => raise TERM ("dest_equals_rhs", [Thm.term_of ct]));
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   197
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   198
val lhs_of = dest_equals_lhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   199
val rhs_of = dest_equals_rhs o Thm.cprop_of;
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
diff changeset
   200
dccd0763ae37 added destructors from drule.ML;
wenzelm
parents: 22695
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
74270
ad2899cdd528 clarified modules;
wenzelm
parents: 74269
diff changeset
   207
val eq_thm = is_equal o Thm.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
65458
cf504b7a7aa7 tuned signature;
wenzelm
parents: 64574
diff changeset
   213
  Context.eq_thy_id (apply2 Thm.theory_id ths) andalso
61040
wenzelm
parents: 61039
diff changeset
   214
  op = (apply2 Thm.maxidx_of ths) andalso
wenzelm
parents: 61039
diff changeset
   215
  op = (apply2 Thm.get_tags ths);
52683
fb028440473e more official Thm.eq_thm_strict, without demanding ML equality type;
wenzelm
parents: 51316
diff changeset
   216
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   217
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   218
(* pattern equivalence *)
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   219
60817
3f38ed5a02c1 clarified context;
wenzelm
parents: 60805
diff changeset
   220
fun equiv_thm thy ths =
3f38ed5a02c1 clarified context;
wenzelm
parents: 60805
diff changeset
   221
  Pattern.equiv thy (apply2 (Thm.full_prop_of o Thm.transfer thy) ths);
22362
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
31904
a86896359ca4 renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents: 31177
diff changeset
   224
(* type classes and sorts *)
a86896359ca4 renamed Drule.sort_triv to Thm.sort_triv (cf. more_thm.ML);
wenzelm
parents: 31177
diff changeset
   225
31944
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
   226
fun class_triv thy c =
59621
291934bac95e Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents: 59616
diff changeset
   227
  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
   228
c8a35979a5bc clarified Thm.of_class/of_sort/class_triv;
wenzelm
parents: 31904
diff changeset
   229
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
   230
a60164e8fff0 added check_shyps, which reject pending sort hypotheses;
wenzelm
parents: 28116
diff changeset
   231
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   232
(* misc operations *)
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   233
24048
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   234
fun is_dummy thm =
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   235
  (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
   236
    NONE => false
58001
934d85f14d1d more general dummy: may contain "parked arguments", for example;
wenzelm
parents: 56245
diff changeset
   237
  | 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
   238
22695
17073e9b94f2 moved Drule.plain_prop_of, Drule.fold_terms to more_thm.ML;
wenzelm
parents: 22682
diff changeset
   239
30564
deddb8a1516f tuned comment;
wenzelm
parents: 30560
diff changeset
   240
(* 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
   241
a12b4faff474 moved Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 23599
diff changeset
   242
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
   243
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
   244
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
   245
74152
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
   246
val item_net = Item_Net.init eq_thm_prop (single o Thm.full_prop_of);
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
   247
val item_net_intro = Item_Net.init eq_thm_prop (single o Thm.concl_of);
069f6b2c5a07 tuned signature;
wenzelm
parents: 73860
diff changeset
   248
val item_net_elim = Item_Net.init eq_thm_prop (single o Thm.major_prem_of);
30560
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
   249
0cc3b7f03ade adapted to general Item_Net;
wenzelm
parents: 30433
diff changeset
   250
22682
92448396c9d9 added read_def_cterms, read_cterm (from thm.ML);
wenzelm
parents: 22378
diff changeset
   251
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   252
(** declared hyps and sort hyps **)
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   253
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   254
structure Hyps = Proof_Data
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   255
(
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   256
  type T = {checked_hyps: bool, hyps: Termset.T, shyps: sort Ord_List.T};
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   257
  fun init _ : T = {checked_hyps = true, hyps = Termset.empty, shyps = []};
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   258
);
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   259
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   260
fun map_hyps f = Hyps.map (fn {checked_hyps, hyps, shyps} =>
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   261
  let val (checked_hyps', hyps', shyps') = f (checked_hyps, hyps, shyps)
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   262
  in {checked_hyps = checked_hyps', hyps = hyps', shyps = shyps'} end);
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   263
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   264
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   265
(* hyps *)
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   266
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   267
fun declare_hyps raw_ct ctxt = ctxt |> map_hyps (fn (checked_hyps, hyps, shyps) =>
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   268
  let
78136
wenzelm
parents: 77869
diff changeset
   269
    val ct = Thm.transfer_cterm' ctxt raw_ct;
77723
b761c91c2447 performance tuning: prefer functor Set() over Table();
wenzelm
parents: 76082
diff changeset
   270
    val hyps' = Termset.insert (Thm.term_of ct) hyps;
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   271
  in (checked_hyps, hyps', shyps) end);
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   272
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   273
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
   274
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   275
val unchecked_hyps = map_hyps (fn (_, hyps, shyps) => (false, hyps, shyps));
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   276
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   277
fun restore_hyps ctxt =
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   278
  map_hyps (fn (_, hyps, shyps) => (#checked_hyps (Hyps.get ctxt), hyps, shyps));
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   279
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   280
fun undeclared_hyps context th =
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   281
  Thm.hyps_of th
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   282
  |> filter_out
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   283
    (case context of
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   284
      Context.Theory _ => K false
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   285
    | Context.Proof ctxt =>
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   286
        (case Hyps.get ctxt of
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   287
          {checked_hyps = false, ...} => K true
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   288
        | {hyps, ...} => Termset.member hyps));
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   289
54993
625370769fc0 check_hyps for attribute application (still inactive, due to non-compliant tools);
wenzelm
parents: 54984
diff changeset
   290
fun check_hyps context th =
55633
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   291
  (case undeclared_hyps context th of
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   292
    [] => th
460f4801b5cb clarified printing of undeclared hyps;
wenzelm
parents: 55547
diff changeset
   293
  | undeclared =>
61263
wenzelm
parents: 61262
diff changeset
   294
      error (Pretty.string_of (Pretty.big_list "Undeclared hyps:"
wenzelm
parents: 61262
diff changeset
   295
        (map (Pretty.item o single o Syntax.pretty_term (Syntax.init_pretty context)) undeclared))));
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   296
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   297
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   298
(* shyps *)
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   299
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   300
fun declare_term_sorts t =
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   301
  map_hyps (fn (checked_hyps, hyps, shyps) =>
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   302
    (checked_hyps, hyps, Sorts.insert_term t shyps));
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   303
61509
358dfae15d83 print thm wrt. local shyps (from full proof context);
wenzelm
parents: 61508
diff changeset
   304
fun extra_shyps' ctxt th =
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   305
  Sorts.subtract (#shyps (Hyps.get ctxt)) (Thm.extra_shyps th);
61509
358dfae15d83 print thm wrt. local shyps (from full proof context);
wenzelm
parents: 61508
diff changeset
   306
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   307
fun check_shyps ctxt raw_th =
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   308
  let
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   309
    val th = Thm.strip_shyps raw_th;
61509
358dfae15d83 print thm wrt. local shyps (from full proof context);
wenzelm
parents: 61508
diff changeset
   310
    val extra_shyps = extra_shyps' ctxt th;
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   311
  in
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   312
    if null extra_shyps then th
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   313
    else error (Pretty.string_of (Pretty.block (Pretty.str "Pending sort hypotheses:" ::
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   314
      Pretty.brk 1 :: Pretty.commas (map (Syntax.pretty_sort ctxt) extra_shyps))))
61508
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   315
  end;
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   316
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   317
val weaken_sorts' = Thm.weaken_sorts o #shyps o Hyps.get;
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   318
2c7e2ae6173d clarified modules;
wenzelm
parents: 61339
diff changeset
   319
54984
da70ab8531f4 more elementary management of declared hyps, below structure Assumption;
wenzelm
parents: 53206
diff changeset
   320
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   321
(** basic derived rules **)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   322
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   323
(*Elimination of implication
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 67698
diff changeset
   324
  A    A \<Longrightarrow> B
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   325
  ------------
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   326
        B
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   327
*)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   328
fun elim_implies thA thAB = Thm.implies_elim thAB thA;
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   329
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   330
61339
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   331
(* forall_intr_name *)
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   332
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   333
fun forall_intr_name (a, x) th =
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   334
  let
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   335
    val th' = Thm.forall_intr x th;
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   336
    val prop' = (case Thm.prop_of th' of all $ Abs (_, T, b) => all $ Abs (a, T, b));
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   337
  in Thm.renamed_prop prop' th' end;
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   338
93883c825062 added Thm.forall_intr_name;
wenzelm
parents: 61336
diff changeset
   339
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   340
(* forall_elim_var(s) *)
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   341
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   342
local
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   343
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   344
val used_frees =
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   345
  Name.build_context o
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   346
    Thm.fold_terms {hyps = true} Term.declare_term_frees;
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   347
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   348
fun used_vars i =
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   349
  Name.build_context o
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   350
    (Thm.fold_terms {hyps = false} o Term.fold_aterms)
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   351
      (fn Var ((x, j), _) => i = j ? Name.declare x | _ => I);
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   352
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   353
fun dest_all ct used =
60951
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   354
  (case Thm.term_of ct of
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   355
    Const ("Pure.all", _) $ Abs (x, _, _) =>
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   356
      let
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   357
        val (x', used') = Name.variant x used;
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   358
        val (v, ct') = Thm.dest_abs_fresh x' (Thm.dest_arg ct);
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   359
      in SOME ((x, Thm.ctyp_of_cterm v), (ct', used')) end
60951
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   360
  | _ => NONE);
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   361
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   362
fun dest_all_list ct used =
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   363
  (case dest_all ct used of
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   364
    NONE => ([], used)
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   365
  | SOME (v, (ct', used')) =>
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   366
      let val (vs, used'') = dest_all_list ct' used'
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   367
      in (v :: vs, used'') end);
60951
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   368
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   369
fun forall_elim_vars_list vars i th =
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   370
  let
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   371
    val (vars', _) =
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   372
      (vars, used_vars i th) |-> fold_map (fn (x, T) => fn used =>
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   373
        let val (x', used') = Name.variant x used
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   374
        in (Thm.var ((x', i), T), used') end);
60951
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   375
  in fold Thm.forall_elim vars' th end;
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   376
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   377
in
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   378
60950
wenzelm
parents: 60948
diff changeset
   379
fun forall_elim_vars i th =
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   380
  forall_elim_vars_list (#1 (dest_all_list (Thm.cprop_of th) (used_frees th))) i th;
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   381
33697
wenzelm
parents: 33666
diff changeset
   382
fun forall_elim_var i th =
60950
wenzelm
parents: 60948
diff changeset
   383
  let
wenzelm
parents: 60948
diff changeset
   384
    val vars =
74525
c960bfcb91db discontinued Term.dest_abs / Logic.dest_all, which are officially superseded by Variable.dest_abs etc., but there are also Term.dest_abs_global to recover existing tools easily;
wenzelm
parents: 74518
diff changeset
   385
      (case dest_all (Thm.cprop_of th) (used_frees th) of
60951
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   386
        SOME (v, _) => [v]
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   387
      | NONE => raise THM ("forall_elim_var", i, [th]));
b70c4db3874f produce certified vars without access to theory_of_thm, and without context;
wenzelm
parents: 60950
diff changeset
   388
  in forall_elim_vars_list vars i th end;
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   389
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   390
end;
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   391
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   392
67698
67caf783b9ee explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents: 67671
diff changeset
   393
(* instantiate frees *)
67caf783b9ee explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents: 67671
diff changeset
   394
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   395
fun instantiate_frees (instT, inst) th =
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   396
  if TFrees.is_empty instT andalso Frees.is_empty inst then th
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   397
  else
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   398
    let
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   399
      val idx = Thm.maxidx_of th + 1;
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   400
      fun index ((a, A), b) = (((a, idx), A), b);
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   401
      val insts =
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   402
        (TVars.build (TFrees.fold (TVars.add o index) instT),
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   403
         Vars.build (Frees.fold (Vars.add o index) inst));
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   404
      val tfrees = Names.build (TFrees.fold (Names.add_set o #1 o #1) instT);
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   405
      val frees = Names.build (Frees.fold (Names.add_set o #1 o #1) inst);
67698
67caf783b9ee explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents: 67671
diff changeset
   406
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   407
      val hyps = Thm.chyps_of th;
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   408
      val inst_cterm =
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   409
        Thm.generalize_cterm (tfrees, frees) idx #>
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   410
        Thm.instantiate_cterm insts;
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   411
    in
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   412
      th
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   413
      |> fold_rev Thm.implies_intr hyps
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   414
      |> Thm.generalize (tfrees, frees) idx
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   415
      |> Thm.instantiate insts
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   416
      |> fold (elim_implies o Thm.assume o inst_cterm) hyps
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   417
    end;
67698
67caf783b9ee explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents: 67671
diff changeset
   418
67caf783b9ee explicit operations to instantiate frees: typ, term, thm, morphism;
wenzelm
parents: 67671
diff changeset
   419
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   420
(* instantiate by left-to-right occurrence of variables *)
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   421
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   422
fun instantiate' cTs cts thm =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   423
  let
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   424
    fun err msg =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   425
      raise TYPE ("instantiate': " ^ msg,
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   426
        map_filter (Option.map Thm.typ_of) cTs,
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   427
        map_filter (Option.map Thm.term_of) cts);
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   428
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   429
    fun zip_vars xs ys =
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   430
      zip_options xs ys handle ListPair.UnequalLengths =>
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   431
        err "more instantiations than variables in thm";
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   432
74241
eb265f54e3ce more efficient operations: traverse hyps only when required;
wenzelm
parents: 74239
diff changeset
   433
    val instT = zip_vars (build_rev (Thm.fold_terms {hyps = false} Term.add_tvars thm)) cTs;
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   434
    val thm' = Thm.instantiate (TVars.make instT, Vars.empty) thm;
74241
eb265f54e3ce more efficient operations: traverse hyps only when required;
wenzelm
parents: 74239
diff changeset
   435
    val inst = zip_vars (build_rev (Thm.fold_terms {hyps = false} Term.add_vars thm')) cts;
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   436
  in Thm.instantiate (TVars.empty, Vars.make inst) thm' end;
60801
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   437
7664e0916eec tuned signature;
wenzelm
parents: 60642
diff changeset
   438
74245
282cd3aa6cc6 clarified modules;
wenzelm
parents: 74244
diff changeset
   439
(* implicit generalization over variables -- canonical order *)
282cd3aa6cc6 clarified modules;
wenzelm
parents: 74244
diff changeset
   440
282cd3aa6cc6 clarified modules;
wenzelm
parents: 74244
diff changeset
   441
fun forall_intr_vars th =
74271
64be5f224462 clarified signature;
wenzelm
parents: 74270
diff changeset
   442
  let val vars = Cterms.build (Cterms.add_vars th)
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   443
  in fold_rev Thm.forall_intr (Cterms.list_set vars) 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
   444
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
   445
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
   446
  let
74246
wenzelm
parents: 74245
diff changeset
   447
    val fixed =
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   448
      Frees.build
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   449
       (fold Frees.add_frees (Thm.terms_of_tpairs (Thm.tpairs_of th)) #>
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   450
        fold Frees.add_frees (Thm.hyps_of th));
74269
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   451
    val is_fixed = Frees.defined fixed o Term.dest_Free o Thm.term_of;
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   452
    val frees =
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   453
      Cterms.build (th |> Thm.fold_atomic_cterms {hyps = false} Term.is_Free
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   454
        (fn ct => not (is_fixed ct) ? Cterms.add_set ct));
f084d599bb44 clarified set of items with order of addition;
wenzelm
parents: 74266
diff changeset
   455
  in fold_rev Thm.forall_intr (Cterms.list_set 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
   456
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
   457
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
   458
(* unvarify_global: global schematic variables *)
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   459
60825
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
   460
fun unvarify_global thy th =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   461
  let
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   462
    val prop = Thm.full_prop_of th;
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   463
    val _ = map Logic.unvarify_global (prop :: Thm.hyps_of th)
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   464
      handle TERM (msg, _) => raise THM (msg, 0, [th]);
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   465
74230
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   466
    val cert = Thm.global_cterm_of thy;
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   467
    val certT = Thm.global_ctyp_of thy;
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   468
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   469
    val instT =
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   470
      TVars.build (prop |> (Term.fold_types o Term.fold_atyps)
74230
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   471
        (fn T => fn instT =>
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   472
          (case T of
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   473
            TVar (v as ((a, _), S)) =>
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   474
              if TVars.defined instT v then instT
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   475
              else TVars.add (v, TFree (a, S)) instT
74232
1091880266e5 clarified signature;
wenzelm
parents: 74230
diff changeset
   476
          | _ => instT)));
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   477
    val cinstT = TVars.map (K certT) instT;
74230
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   478
    val cinst =
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   479
      Vars.build (prop |> Term.fold_aterms
74230
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   480
        (fn t => fn inst =>
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   481
          (case t of
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   482
            Var ((x, i), T) =>
d637611b41bd more scalable operations;
wenzelm
parents: 74220
diff changeset
   483
              let val T' = Term_Subst.instantiateT instT T
74266
612b7e0d6721 clarified signature;
wenzelm
parents: 74265
diff changeset
   484
              in Vars.add (((x, i), T'), cert (Free ((x, T')))) inst end
74232
1091880266e5 clarified signature;
wenzelm
parents: 74230
diff changeset
   485
          | _ => inst)));
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   486
  in Thm.instantiate (cinstT, cinst) th end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   487
60825
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
   488
fun unvarify_axiom thy = unvarify_global thy o Thm.axiom thy;
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
   489
26653
60e0cf6bef89 Thm.forall_elim_var(s);
wenzelm
parents: 26628
diff changeset
   490
59969
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   491
(* user renaming of parameters in a subgoal *)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   492
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   493
(*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
   494
  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
   495
fun rename_params_rule (names, i) st =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   496
  let
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   497
    val (_, Bs, Bi, C) = Thm.dest_state (st, i);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   498
    val params = map #1 (Logic.strip_params Bi);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   499
    val short = length params - length names;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   500
    val names' =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   501
      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
   502
      else Name.variant_list names (take short params) @ names;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   503
    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
   504
    val Bi' = Logic.list_rename_params names' Bi;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   505
  in
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   506
    (case duplicates (op =) names of
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   507
      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
   508
    | [] =>
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   509
      (case inter (op =) names free_names of
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   510
        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
   511
      | [] => 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
   512
  end;
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   513
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   514
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   515
(* preservation of bound variable names *)
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   516
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   517
fun rename_boundvars pat obj th =
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   518
  (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
   519
    NONE => th
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   520
  | SOME prop' => Thm.renamed_prop prop' th);
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   521
bcccad156236 explicitly checked alpha conversion -- actual renaming happens outside kernel;
wenzelm
parents: 59623
diff changeset
   522
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   523
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   524
(** specification primitives **)
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   525
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   526
(* rules *)
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   527
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   528
fun stripped_sorts thy t =
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   529
  let
74235
dbaed92fd8af tuned signature;
wenzelm
parents: 74232
diff changeset
   530
    val tfrees = build_rev (Term.add_tfrees t);
70922
539dfd4c166b more conservative type names, e.g. relevant for Isabelle/MMT export;
wenzelm
parents: 70915
diff changeset
   531
    val tfrees' = map (fn a => (a, [])) (Name.variant_list [] (map #1 tfrees));
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
   532
    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
   533
      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
   534
        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
   535
    val strip = map (apply2 TFree) (tfrees ~~ tfrees');
79436
253d86888e84 minor performance tuning;
wenzelm
parents: 78462
diff changeset
   536
    val t' =
253d86888e84 minor performance tuning;
wenzelm
parents: 78462
diff changeset
   537
      (Term.map_types o Term.map_atyps_same)
253d86888e84 minor performance tuning;
wenzelm
parents: 78462
diff changeset
   538
        (Same.function_eq (op =) (perhaps (AList.lookup (op =) strip))) t;
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   539
  in (strip, recover, t') end;
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   540
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   541
fun add_axiom ctxt (b, prop) thy =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   542
  let
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   543
    val _ = Sign.no_vars ctxt prop;
35855
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   544
    val (strip, recover, prop') = stripped_sorts thy prop;
e7d004b89ca8 add_axiom: axiomatize "unconstrained" version, with explicit of_class premises;
wenzelm
parents: 35853
diff changeset
   545
    val constraints = map (fn (TFree (_, S), T) => (T, S)) strip;
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   546
    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
   547
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   548
    val thy' = thy
51316
dfe469293eb4 discontinued empty name bindings in 'axiomatization';
wenzelm
parents: 49062
diff changeset
   549
      |> 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
   550
    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
   551
    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
   552
    val thm =
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   553
      Thm.instantiate (TVars.make recover, Vars.empty) axm'
60825
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
   554
      |> unvarify_global thy'
35988
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   555
      |> fold elim_implies of_sorts;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   556
  in ((axm_name, thm), thy') end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   557
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   558
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
   559
61261
ddb2da7cb2e4 more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents: 61059
diff changeset
   560
fun add_def (context as (ctxt, _)) unchecked overloaded (b, prop) thy =
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   561
  let
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   562
    val _ = Sign.no_vars ctxt prop;
60367
e201bd8973db clarified context;
wenzelm
parents: 60324
diff changeset
   563
    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
   564
    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
   565
61261
ddb2da7cb2e4 more explicit Defs.context: use proper name spaces as far as possible;
wenzelm
parents: 61059
diff changeset
   566
    val thy' = Theory.add_def context unchecked overloaded (b, concl') thy;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   567
    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
   568
    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
   569
    val thm =
74282
c2ee8d993d6a clarified signature: more scalable operations;
wenzelm
parents: 74271
diff changeset
   570
      Thm.instantiate (TVars.make recover, Vars.empty) axm'
60825
bacfb7c45d81 more explicit context;
wenzelm
parents: 60824
diff changeset
   571
      |> unvarify_global thy'
35988
76ca601c941e disallow premises in primitive Theory.add_def -- handle in Thm.add_def;
wenzelm
parents: 35985
diff changeset
   572
      |> fold_rev Thm.implies_intr prems;
36106
19deea200358 Thm.add_axiom/add_def: return internal name of foundational axiom;
wenzelm
parents: 35988
diff changeset
   573
  in ((axm_name, thm), thy') end;
24980
16a74cfca971 added elim_implies (more convenient argument order);
wenzelm
parents: 24948
diff changeset
   574
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   575
fun add_def_global unchecked overloaded arg thy =
61262
7bd1eb4b056e tuned signature: eliminated pointless type Context.pretty;
wenzelm
parents: 61261
diff changeset
   576
  add_def (Defs.global_context thy) unchecked overloaded arg thy;
42375
774df7c59508 report Name_Space.declare/define, relatively to context;
wenzelm
parents: 40238
diff changeset
   577
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   578
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   579
70443
a21a96eda033 clarified modules;
wenzelm
parents: 70404
diff changeset
   580
(** theorem tags **)
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   581
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   582
(* add / delete tags *)
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
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
   585
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
   586
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   587
61852
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   588
(* free dummy thm -- for abstract closure *)
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   589
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   590
val free_dummyN = "free_dummy";
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   591
fun is_free_dummy thm = Properties.defined (Thm.get_tags thm) free_dummyN;
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   592
val tag_free_dummy = tag_rule (free_dummyN, "");
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   593
d273c24b5776 tuned signature -- clarified modules;
wenzelm
parents: 61509
diff changeset
   594
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   595
(* def_name *)
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   596
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   597
fun def_name c = c ^ "_def";
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   598
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   599
fun def_name_optional c "" = def_name c
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   600
  | def_name_optional _ name = name;
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   601
63041
cb495c4807b3 clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents: 62093
diff changeset
   602
val def_binding = Binding.map_name def_name #> Binding.reset_pos;
cb495c4807b3 clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents: 62093
diff changeset
   603
fun def_binding_optional b name = if Binding.is_empty name then def_binding b else name;
cb495c4807b3 clarified def binding position: reset for implicit/derived binding, keep for explicit binding;
wenzelm
parents: 62093
diff changeset
   604
fun make_def_binding cond b = if cond then def_binding b else Binding.empty;
62093
bd73a2279fcd more uniform treatment of package internals;
wenzelm
parents: 61853
diff changeset
   605
30342
d32daa6aba3c moved Thm.def_name(_optional) to more_thm.ML;
wenzelm
parents: 30210
diff changeset
   606
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   607
(* unofficial theorem names *)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   608
68036
4c9e79aeadf0 tuned -- avoid spurious exception trace for "the";
wenzelm
parents: 67778
diff changeset
   609
fun has_name_hint thm = AList.defined (op =) (Thm.get_tags thm) Markup.nameN;
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   610
fun the_name_hint thm = the (AList.lookup (op =) (Thm.get_tags thm) Markup.nameN);
68036
4c9e79aeadf0 tuned -- avoid spurious exception trace for "the";
wenzelm
parents: 67778
diff changeset
   611
fun get_name_hint thm = if has_name_hint thm then the_name_hint thm else "??.unknown";
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   612
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   613
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
   614
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   615
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   616
(* theorem kinds *)
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   617
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   618
val theoremK = "theorem";
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   619
78462
wenzelm
parents: 78136
diff changeset
   620
fun legacy_get_kind thm = Properties.get_string (Thm.get_tags thm) Markup.kindN;
27866
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   621
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   622
fun kind_rule k = tag_rule (Markup.kindN, k) o untag_rule Markup.kindN;
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   623
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   624
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   625
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   626
(** attributes **)
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   627
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   628
(*attributes subsume any kind of rules or context modifiers*)
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   629
type attribute = Context.generic * thm -> Context.generic option * thm option;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   630
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   631
type binding = binding * attribute list;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   632
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   633
fun rule_attribute ths f (x, th) =
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   634
  (NONE,
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   635
    (case find_first is_free_dummy (th :: ths) of
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   636
      SOME th' => SOME th'
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   637
    | NONE => SOME (f x th)));
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   638
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   639
fun declaration_attribute f (x, th) =
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   640
  (if is_free_dummy th then NONE else SOME (f th x), NONE);
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   641
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   642
fun mixed_attribute f (x, th) =
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   643
  let val (x', th') = f (x, th) in (SOME x', SOME th') end;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   644
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   645
fun apply_attribute (att: attribute) th x =
67649
1e1782c1aedf tuned signature;
wenzelm
parents: 67559
diff changeset
   646
  let val (x', th') = att (x, check_hyps x (Thm.transfer'' x th))
61853
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   647
  in (the_default th th', the_default x x') end;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   648
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   649
fun attribute_declaration att th x = #2 (apply_attribute att th x);
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   650
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   651
fun apply_attributes mk dest =
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   652
  let
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   653
    fun app [] th x = (th, x)
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   654
      | app (att :: atts) th x = apply_attribute att th (mk x) ||> dest |-> app atts;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   655
  in app end;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   656
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   657
val theory_attributes = apply_attributes Context.Theory Context.the_theory;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   658
val proof_attributes = apply_attributes Context.Proof Context.the_proof;
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   659
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   660
fun no_attributes x = (x, []);
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   661
fun simple_fact x = [(x, [])];
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   662
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   663
fun tag tg = rule_attribute [] (K (tag_rule tg));
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   664
fun untag s = rule_attribute [] (K (untag_rule s));
fb7756087101 rule_attribute and declaration_attribute implicitly support abstract closure, but mixed_attribute implementations need to be aware of Thm.is_free_dummy;
wenzelm
parents: 61852
diff changeset
   665
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
   666
c721ea6e0eb4 moved basic thm operations from structure PureThy to Thm;
wenzelm
parents: 27255
diff changeset
   667
70443
a21a96eda033 clarified modules;
wenzelm
parents: 70404
diff changeset
   668
a21a96eda033 clarified modules;
wenzelm
parents: 70404
diff changeset
   669
(** forked proofs **)
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   670
49062
7e31dfd99ce7 discontinued complicated/unreliable notion of recent proofs within context;
wenzelm
parents: 49058
diff changeset
   671
structure Proofs = Theory_Data
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   672
(
72048
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   673
  type T = thm list lazy Inttab.table;
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   674
  val empty = Inttab.empty;
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   675
  val merge = Inttab.merge (K true);
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   676
);
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   677
72048
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   678
fun reset_proofs thy =
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   679
  if Inttab.is_empty (Proofs.get thy) then NONE
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   680
  else SOME (Proofs.put Inttab.empty thy);
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   681
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   682
val _ = Theory.setup (Theory.at_begin reset_proofs);
61059
0306e209fa9e trim context for persistent storage;
wenzelm
parents: 61041
diff changeset
   683
72048
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   684
fun register_proofs ths thy =
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   685
  let val entry = (serial (), Lazy.map_finished (map Thm.trim_context) ths)
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   686
  in (Proofs.map o Inttab.update) entry thy end;
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   687
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   688
fun force_proofs thy =
d3b8c8b2d1fc more thorough extend/merge (for Theory.join_theory);
wenzelm
parents: 71088
diff changeset
   689
  Proofs.get thy |> Inttab.dest |> maps (map (Thm.transfer thy) o Lazy.force o #2);
71023
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   690
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   691
val consolidate_theory = Thm.consolidate o force_proofs;
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   692
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   693
fun expose_theory thy =
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   694
  if Proofterm.export_enabled ()
35a8e15b7e03 more robust Thm.expose_theory -- ensure that PIDE export happens in the proper theory context;
wenzelm
parents: 71018
diff changeset
   695
  then Thm.expose_proofs thy (force_proofs thy) else ();
49010
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   696
72808e956879 tuned signature;
wenzelm
parents: 46861
diff changeset
   697
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   698
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   699
(** print theorems **)
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   700
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   701
(* options *)
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   702
69575
f77cc54f6d47 clarified signature: more types;
wenzelm
parents: 68036
diff changeset
   703
val show_consts = Config.declare_option_bool ("show_consts", \<^here>);
f77cc54f6d47 clarified signature: more types;
wenzelm
parents: 68036
diff changeset
   704
val show_hyps = Config.declare_bool ("show_hyps", \<^here>) (K false);
f77cc54f6d47 clarified signature: more types;
wenzelm
parents: 68036
diff changeset
   705
val show_tags = Config.declare_bool ("show_tags", \<^here>) (K false);
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   706
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   707
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   708
(* pretty_thm etc. *)
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   709
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   710
fun pretty_tag (name, arg) = Pretty.strs [name, quote arg];
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   711
val pretty_tags = Pretty.list "[" "]" o map pretty_tag;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   712
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   713
fun pretty_thm_raw ctxt {quote, show_hyps = show_hyps'} raw_th =
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   714
  let
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   715
    val show_tags = Config.get ctxt show_tags;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   716
    val show_hyps = Config.get ctxt show_hyps;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   717
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   718
    val th = raw_th
67649
1e1782c1aedf tuned signature;
wenzelm
parents: 67559
diff changeset
   719
      |> perhaps (try (Thm.transfer' ctxt))
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   720
      |> perhaps (try Thm.strip_shyps);
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   721
77863
760515c45864 revert b43ee37926a9 due to problems with AFP/PAPP_Impossibility;
wenzelm
parents: 77808
diff changeset
   722
    val hyps = if show_hyps then Thm.hyps_of th else undeclared_hyps (Context.Proof ctxt) th;
77869
1156aa9db7f5 backout 4a174bea55e2;
wenzelm
parents: 77863
diff changeset
   723
    val extra_shyps = extra_shyps' ctxt th;
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   724
    val tags = Thm.get_tags th;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   725
    val tpairs = Thm.tpairs_of th;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   726
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   727
    val q = if quote then Pretty.quote else I;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   728
    val prt_term = q o Syntax.pretty_term ctxt;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   729
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   730
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   731
    val hlen = length extra_shyps + length hyps + length tpairs;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   732
    val hsymbs =
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   733
      if hlen = 0 then []
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   734
      else if show_hyps orelse show_hyps' then
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   735
        [Pretty.brk 2, Pretty.list "[" "]"
76082
1202e29798a4 tuned signature;
wenzelm
parents: 74566
diff changeset
   736
          (map (q o Pretty.block o Syntax.pretty_flexpair ctxt) tpairs @ map prt_term hyps @
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   737
           map (Syntax.pretty_sort ctxt) extra_shyps)]
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   738
      else [Pretty.brk 2, Pretty.str ("[" ^ replicate_string hlen "." ^ "]")];
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   739
    val tsymbs =
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   740
      if null tags orelse not show_tags then []
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   741
      else [Pretty.brk 1, pretty_tags tags];
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   742
  in Pretty.block (prt_term (Thm.prop_of th) :: (hsymbs @ tsymbs)) end;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   743
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   744
fun pretty_thm ctxt = pretty_thm_raw ctxt {quote = false, show_hyps = true};
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   745
fun pretty_thm_item ctxt th = Pretty.item [pretty_thm ctxt th];
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   746
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   747
fun pretty_thm_global thy =
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   748
  pretty_thm_raw (Syntax.init_pretty_global thy) {quote = false, show_hyps = false};
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   749
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   750
val string_of_thm = Pretty.string_of oo pretty_thm;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   751
val string_of_thm_global = Pretty.string_of oo pretty_thm_global;
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   752
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61263
diff changeset
   753
22362
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   754
open Thm;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   755
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   756
end;
6470ce514b6e Further operations on type thm, outside the inference kernel.
wenzelm
parents:
diff changeset
   757
32842
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   758
structure Basic_Thm: BASIC_THM = Thm;
98702c579ad0 added Ctermtab, cterm_cache, thm_cache;
wenzelm
parents: 32279
diff changeset
   759
open Basic_Thm;