src/Pure/Isar/isar_thy.ML
author ballarin
Wed, 09 Mar 2005 18:44:52 +0100
changeset 15596 8665d08085df
parent 15570 8d8c70b41bab
child 15598 4ab52355bb53
permissions -rw-r--r--
First version of global registration command.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/isar_thy.ML
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     4
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
     5
Pure/Isar derived theory operations.
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     6
*)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     7
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     8
signature ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     9
sig
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    10
  val hide_space: string * xstring list -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    11
  val hide_space_i: string * string list -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    12
  val add_axioms: ((bstring * string) * Args.src list) list -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    13
  val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    14
  val add_defs: bool * ((bstring * string) * Args.src list) list -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    15
  val add_defs_i: bool * ((bstring * term) * theory attribute list) list -> theory -> theory
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    16
  val theorems: string -> ((bstring * Args.src list) * (thmref * Args.src list) list) list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    17
    -> theory -> theory * (string * thm list) list
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    18
  val theorems_i: string ->
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    19
    ((bstring * theory attribute list) * (thm list * theory attribute list) list) list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    20
    -> theory -> theory * (string * thm list) list
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    21
  val locale_theorems: string -> xstring ->
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    22
    ((bstring * Args.src list) * (thmref * Args.src list) list) list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    23
    -> theory -> theory * (bstring * thm list) list
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    24
  val locale_theorems_i: string -> string ->
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    25
    ((bstring * Locale.multi_attribute list)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    26
      * (thm list * Locale.multi_attribute list) list) list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    27
    -> theory -> theory * (string * thm list) list
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    28
  val smart_theorems: string -> xstring option ->
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    29
    ((bstring * Args.src list) * (thmref * Args.src list) list) list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    30
    -> theory -> theory * (string * thm list) list
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    31
  val declare_theorems: xstring option -> (thmref * Args.src list) list -> theory -> theory
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    32
  val apply_theorems: (thmref * Args.src list) list -> theory -> theory * thm list
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
    33
  val apply_theorems_i: (thm list * theory attribute list) list -> theory -> theory * thm list
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    34
  val have_facts: ((string * Args.src list) * (thmref * Args.src list) list) list
10464
b7b916a82dca tuned statement args;
wenzelm
parents: 10449
diff changeset
    35
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    36
  val have_facts_i: ((string * Proof.context attribute list) *
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    37
    (thm * Proof.context attribute list) list) list -> ProofHistory.T -> ProofHistory.T
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    38
  val from_facts: (thmref * Args.src list) list list -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    39
  val from_facts_i: (thm * Proof.context attribute list) list list
6728
b51b25db7bc6 added formal comment arguments almost everywhere (still ignored);
wenzelm
parents: 6688
diff changeset
    40
    -> ProofHistory.T -> ProofHistory.T
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    41
  val with_facts: (thmref * Args.src list) list list -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    42
  val with_facts_i: (thm * Proof.context attribute list) list list
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
    43
    -> ProofHistory.T -> ProofHistory.T
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
    44
  val using_facts: (thmref * Args.src list) list list -> ProofHistory.T -> ProofHistory.T
12929
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
    45
  val using_facts_i: (thm * Proof.context attribute list) list list
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
    46
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    47
  val chain: ProofHistory.T -> ProofHistory.T
14528
1457584110ac Locale instantiation: label parameter optional, new attribute paramter.
ballarin
parents: 14508
diff changeset
    48
  val instantiate_locale: (string * Args.src list) * string -> ProofHistory.T
1457584110ac Locale instantiation: label parameter optional, new attribute paramter.
ballarin
parents: 14508
diff changeset
    49
    -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    50
  val fix: (string list * string option) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    51
  val fix_i: (string list * typ option) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    52
  val let_bind: (string list * string) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    53
  val let_bind_i: (term list * term) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    54
  val invoke_case: string * string option list * Args.src list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    55
  val invoke_case_i: string * string option list * Proof.context attribute list
11793
5f0ab6f5c280 support impromptu terminology of cases parameters;
wenzelm
parents: 11764
diff changeset
    56
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    57
  val theorem: string -> (bstring * Args.src list) * (string * (string list * string list))
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
    58
    -> bool -> theory -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    59
  val theorem_i: string -> (bstring * theory attribute list) *
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    60
    (term * (term list * term list)) -> bool -> theory -> ProofHistory.T
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    61
  val multi_theorem: string -> (theory -> theory) -> bstring * Args.src list
15206
09d78ec709c7 Modified locales: improved implementation of "includes".
ballarin
parents: 15127
diff changeset
    62
    -> Args.src Locale.element Locale.elem_expr list
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
    63
    -> ((bstring * Args.src list) * (string * (string list * string list)) list) list
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    64
    -> bool -> theory -> ProofHistory.T
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    65
  val multi_theorem_i: string -> (theory -> theory) -> bstring * theory attribute list
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    66
    -> Locale.multi_attribute Locale.element_i Locale.elem_expr list
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
    67
    -> ((bstring * theory attribute list) * (term * (term list * term list)) list) list
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    68
    -> bool -> theory -> ProofHistory.T
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
    69
  val locale_multi_theorem: string -> xstring
15206
09d78ec709c7 Modified locales: improved implementation of "includes".
ballarin
parents: 15127
diff changeset
    70
    -> bstring * Args.src list -> Args.src Locale.element Locale.elem_expr list
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
    71
    -> ((bstring * Args.src list) * (string * (string list * string list)) list) list
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    72
    -> bool -> theory -> ProofHistory.T
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    73
  val locale_multi_theorem_i: string -> string -> bstring * Locale.multi_attribute list
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    74
    -> Locale.multi_attribute Locale.element_i Locale.elem_expr list
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    75
    -> ((bstring * Locale.multi_attribute list) * (term * (term list * term list)) list) list
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    76
    -> bool -> theory -> ProofHistory.T
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
    77
  val smart_multi_theorem: string -> xstring option
15206
09d78ec709c7 Modified locales: improved implementation of "includes".
ballarin
parents: 15127
diff changeset
    78
    -> bstring * Args.src list -> Args.src Locale.element Locale.elem_expr list
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
    79
    -> ((bstring * Args.src list) * (string * (string list * string list)) list) list
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    80
    -> bool -> theory -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    81
  val assume: ((string * Args.src list) * (string * (string list * string list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
    82
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    83
  val assume_i:
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    84
    ((string * Proof.context attribute list) * (term * (term list * term list)) list) list
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    85
    -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    86
  val presume: ((string * Args.src list) * (string * (string list * string list)) list) list
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    87
    -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    88
  val presume_i:
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    89
    ((string * Proof.context attribute list) * (term * (term list * term list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
    90
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    91
  val have: ((string * Args.src list) * (string * (string list * string list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
    92
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    93
  val have_i: ((string * Proof.context attribute list) *
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    94
    (term * (term list * term list)) list) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    95
  val hence: ((string * Args.src list) * (string * (string list * string list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
    96
    -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    97
  val hence_i: ((string * Proof.context attribute list) *
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    98
    (term * (term list * term list)) list) list -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
    99
  val show: ((string * Args.src list) * (string * (string list * string list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   100
    -> bool -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   101
  val show_i: ((string * Proof.context attribute list) *
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   102
    (term * (term list * term list)) list) list -> bool -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   103
  val thus: ((string * Args.src list) * (string * (string list * string list)) list) list
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   104
    -> bool -> ProofHistory.T -> ProofHistory.T
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   105
  val thus_i: ((string * Proof.context attribute list)
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   106
    * (term * (term list * term list)) list) list -> bool -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   107
  val local_def: (string * Args.src list) * (string * (string * string list))
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   108
    -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   109
  val local_def_i: (string * Args.src list) * (string * (term * term list))
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   110
    -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   111
  val obtain: (string list * string option) list
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   112
    * ((string * Args.src list) * (string * (string list * string list)) list) list
12969
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   113
    -> Toplevel.transition -> Toplevel.transition
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   114
  val obtain_i: (string list * typ option) list
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   115
    * ((string * Proof.context attribute list) * (term * (term list * term list)) list) list
12969
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   116
    -> Toplevel.transition -> Toplevel.transition
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   117
  val begin_block: ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   118
  val next_block: ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   119
  val end_block: ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   120
  val defer: int option -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   121
  val prefer: int -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   122
  val apply: Method.text -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   123
  val apply_end: Method.text -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   124
  val proof: Method.text option -> ProofHistory.T -> ProofHistory.T
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   125
  val qed: Method.text option -> Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   126
  val terminal_proof: Method.text * Method.text option
6937
d9e3e2b30bee added export_chain;
wenzelm
parents: 6904
diff changeset
   127
    -> Toplevel.transition -> Toplevel.transition
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   128
  val default_proof: Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   129
  val immediate_proof: Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   130
  val done_proof: Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   131
  val skip_proof: Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   132
  val forget_proof: Toplevel.transition -> Toplevel.transition
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
   133
  val get_thmss: (thmref * Args.src list) list -> Proof.state -> thm list
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
   134
  val also: (thmref * Args.src list) list option -> Toplevel.transition -> Toplevel.transition
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   135
  val also_i: thm list option -> Toplevel.transition -> Toplevel.transition
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15237
diff changeset
   136
  val finally: (thmref * Args.src list) list option -> Toplevel.transition -> Toplevel.transition
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   137
  val finally_i: thm list option -> Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   138
  val moreover: Toplevel.transition -> Toplevel.transition
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   139
  val ultimately: Toplevel.transition -> Toplevel.transition
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   140
  val parse_ast_translation: bool * string -> theory -> theory
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   141
  val parse_translation: bool * string -> theory -> theory
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   142
  val print_translation: bool * string -> theory -> theory
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   143
  val typed_print_translation: bool * string -> theory -> theory
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   144
  val print_ast_translation: bool * string -> theory -> theory
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   145
  val token_translation: string -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   146
  val method_setup: bstring * string * string -> theory -> theory
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   147
  val add_oracle: bstring * string -> theory -> theory
13393
bd976af8bf18 adapted add_locale;
wenzelm
parents: 13374
diff changeset
   148
  val add_locale: bool * bstring * Locale.expr * Args.src Locale.element list -> theory -> theory
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   149
  val begin_theory: string -> string list -> (string * bool) list -> theory
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   150
  val end_theory: theory -> theory
7932
92df50fb89ca export kill_theory;
wenzelm
parents: 7909
diff changeset
   151
  val kill_theory: string -> unit
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   152
  val theory: string * string list * (string * bool) list
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   153
    -> Toplevel.transition -> Toplevel.transition
7960
d5c91c131070 improved IsarThy.init_context;
wenzelm
parents: 7953
diff changeset
   154
  val init_context: ('a -> unit) -> 'a -> Toplevel.transition -> Toplevel.transition
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   155
  val context: string -> Toplevel.transition -> Toplevel.transition
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   156
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   157
  val register_globally:
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   158
    ((string * Args.src list) * Locale.expr) * string option list ->
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   159
    bool -> theory -> ProofHistory.T
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   160
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   161
end;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   162
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   163
structure IsarThy: ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   164
struct
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   165
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   166
(** derived theory and proof operations **)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   167
8724
ef7efded8fdc global/local_path: comment;
wenzelm
parents: 8681
diff changeset
   168
(* name spaces *)
ef7efded8fdc global/local_path: comment;
wenzelm
parents: 8681
diff changeset
   169
8885
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   170
local
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   171
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   172
val kinds =
10449
088aa7bd3154 hide_space(_i): use Sign.certify_tycon, Sign.certify_tyabbr, Sign.certify_const;
wenzelm
parents: 9903
diff changeset
   173
 [(Sign.classK, can o Sign.certify_class),
14778
69cafc301399 Sign.certify_tyname;
wenzelm
parents: 14649
diff changeset
   174
  (Sign.typeK, can o Sign.certify_tyname),
10449
088aa7bd3154 hide_space(_i): use Sign.certify_tycon, Sign.certify_tyabbr, Sign.certify_const;
wenzelm
parents: 9903
diff changeset
   175
  (Sign.constK, can o Sign.certify_const)];
8724
ef7efded8fdc global/local_path: comment;
wenzelm
parents: 8681
diff changeset
   176
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   177
fun gen_hide intern (kind, xnames) thy =
8885
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   178
  (case assoc (kinds, kind) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   179
    SOME check =>
8885
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   180
      let
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   181
        val sg = Theory.sign_of thy;
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   182
        val names = map (intern sg kind) xnames;
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   183
        val bads = filter_out (check sg) names;
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   184
      in
12589
afc6ffffeb11 Theory.hide_space_i true;
wenzelm
parents: 12318
diff changeset
   185
        if null bads then Theory.hide_space_i true (kind, names) thy
8885
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   186
        else error ("Attempt to hide undeclared item(s): " ^ commas_quote bads)
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   187
      end
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   188
  | NONE => error ("Bad name space specification: " ^ quote kind));
8885
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   189
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   190
in
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   191
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   192
fun hide_space x = gen_hide Sign.intern x;
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   193
fun hide_space_i x = gen_hide (K (K I)) x;
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   194
19ab913a6a6a hide: check declared;
wenzelm
parents: 8881
diff changeset
   195
end;
8724
ef7efded8fdc global/local_path: comment;
wenzelm
parents: 8681
diff changeset
   196
ef7efded8fdc global/local_path: comment;
wenzelm
parents: 8681
diff changeset
   197
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   198
(* axioms and defs *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   199
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   200
fun add_axms f args thy =
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   201
  f (map (fn (x, srcs) => (x, map (Attrib.global_attribute thy) srcs)) args) thy;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   202
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   203
val add_axioms = add_axms (#1 oo PureThy.add_axioms);
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   204
val add_axioms_i = #1 oo PureThy.add_axioms_i;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   205
fun add_defs (x, args) = add_axms (#1 oo PureThy.add_defs x) args;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   206
fun add_defs_i (x, args) = (#1 oo PureThy.add_defs_i x) args;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   207
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   208
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   209
(* attributes *)
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   210
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   211
local
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   212
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   213
fun prep_attribs f = map (fn ((name, more_srcs), th_srcs) =>
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   214
  ((name, map f more_srcs), map (apsnd (map f)) th_srcs));
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   215
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   216
in
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   217
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   218
fun global_attribs thy = prep_attribs (Attrib.global_attribute thy);
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   219
fun local_attribs thy = prep_attribs (Attrib.local_attribute thy);
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   220
fun multi_attribs thy = prep_attribs (Attrib.multi_attribute thy);
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   221
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   222
end;
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   223
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   224
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   225
(* theorems *)
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   226
12705
wenzelm
parents: 12701
diff changeset
   227
local
wenzelm
parents: 12701
diff changeset
   228
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   229
fun present_thmss kind (thy, named_thmss) =
13529
49a0ad8f175e check_goal: produce error instead of warning;
wenzelm
parents: 13393
diff changeset
   230
 (conditional (kind <> "" andalso kind <> Drule.internalK) (fn () =>
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   231
    Context.setmp (SOME thy) (Present.results (kind ^ "s")) named_thmss);
13529
49a0ad8f175e check_goal: produce error instead of warning;
wenzelm
parents: 13393
diff changeset
   232
  (thy, named_thmss));
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   233
12705
wenzelm
parents: 12701
diff changeset
   234
in
wenzelm
parents: 12701
diff changeset
   235
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   236
fun theorems_i k = present_thmss k oo PureThy.note_thmss_i (Drule.kind k);
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   237
fun locale_theorems_i k loc = present_thmss k oo Locale.note_thmss_i k loc;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   238
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   239
fun theorems k args thy = thy
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   240
  |> PureThy.note_thmss (Drule.kind k) (global_attribs thy args)
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   241
  |> present_thmss k;
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   242
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   243
fun locale_theorems k loc args thy = thy
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   244
  |> Locale.note_thmss k loc (multi_attribs thy args)
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   245
  |> present_thmss k;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   246
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   247
fun smart_theorems k opt_loc args thy = thy
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   248
  |> (case opt_loc of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   249
    NONE => PureThy.note_thmss (Drule.kind k) (global_attribs thy args)
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   250
  | SOME loc => Locale.note_thmss k loc (multi_attribs thy args))
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   251
  |> present_thmss k;
9590
52e71612e42f added declare_theorems(_i);
wenzelm
parents: 9466
diff changeset
   252
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   253
fun declare_theorems opt_loc args = #1 o smart_theorems "" opt_loc [(("", []), args)];
9590
52e71612e42f added declare_theorems(_i);
wenzelm
parents: 9466
diff changeset
   254
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   255
fun apply_theorems args = apsnd (List.concat o map snd) o theorems "" [(("", []), args)];
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   256
fun apply_theorems_i args = apsnd (List.concat o map snd) o theorems_i "" [(("", []), args)];
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   257
12705
wenzelm
parents: 12701
diff changeset
   258
end;
wenzelm
parents: 12701
diff changeset
   259
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   260
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   261
(* facts and forward chaining *)
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   262
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   263
fun local_thmss f args state = f (local_attribs (Proof.theory_of state) args) state;
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   264
fun local_thmss_i f args = f (map (fn ((name, more_atts), th_atts) =>
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   265
  ((name, more_atts), map (apfst single) th_atts)) args);
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   266
12713
c9e3e34dbc45 clarified/added theorems(_i) vs. locale_theorems(_i);
wenzelm
parents: 12705
diff changeset
   267
fun chain_thmss f args = ProofHistory.apply (Proof.chain o f (map (pair ("", [])) args));
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   268
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   269
val have_facts = ProofHistory.apply o local_thmss Proof.note_thmss;
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   270
val have_facts_i = ProofHistory.apply o local_thmss_i Proof.note_thmss_i;
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   271
val from_facts = chain_thmss (local_thmss Proof.note_thmss);
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   272
val from_facts_i = chain_thmss (local_thmss_i Proof.note_thmss_i);
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   273
val with_facts = chain_thmss (local_thmss Proof.with_thmss);
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   274
val with_facts_i = chain_thmss (local_thmss_i Proof.with_thmss_i);
12929
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   275
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   276
fun using_facts args = ProofHistory.apply (fn state =>
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   277
  Proof.using_thmss (map (map (apsnd (map
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   278
    (Attrib.local_attribute (Proof.theory_of state))))) args) state);
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   279
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   280
val using_facts_i = ProofHistory.apply o Proof.using_thmss_i o map (map (apfst single));
dbac8831d954 added using_facts;
wenzelm
parents: 12876
diff changeset
   281
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   282
val chain = ProofHistory.apply Proof.chain;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   283
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   284
14508
859b11514537 Experimental command for instantiation of locales in proof contexts:
ballarin
parents: 14503
diff changeset
   285
(* locale instantiation *)
859b11514537 Experimental command for instantiation of locales in proof contexts:
ballarin
parents: 14503
diff changeset
   286
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   287
fun instantiate_locale ((name, atts), loc) =
14528
1457584110ac Locale instantiation: label parameter optional, new attribute paramter.
ballarin
parents: 14508
diff changeset
   288
  ProofHistory.apply (fn state =>
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   289
    Proof.instantiate_locale (loc,
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   290
        (name, map (Attrib.local_attribute (Proof.theory_of state)) atts)) state);
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   291
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   292
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   293
(* context *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   294
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   295
val fix = ProofHistory.apply o Proof.fix;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   296
val fix_i = ProofHistory.apply o Proof.fix_i;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   297
val let_bind = ProofHistory.apply o Proof.let_bind;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   298
val let_bind_i = ProofHistory.apply o Proof.let_bind_i;
8450
dc44d6533f0f invoke_case: include attributes;
wenzelm
parents: 8428
diff changeset
   299
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   300
fun invoke_case (name, xs, src) = ProofHistory.apply (fn state =>
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   301
  Proof.invoke_case (name, xs,
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   302
    map (Attrib.local_attribute (Proof.theory_of state)) src) state);
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   303
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   304
val invoke_case_i = ProofHistory.apply o Proof.invoke_case;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   305
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   306
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   307
(* local results *)
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   308
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   309
local
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   310
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   311
fun prt_facts ctxt =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   312
  List.concat o (separate [Pretty.fbrk, Pretty.str "and "]) o
13276
a02ee4fec6b7 ProofContext.pretty_fact;
wenzelm
parents: 12969
diff changeset
   313
    map (single o ProofContext.pretty_fact ctxt);
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   314
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   315
fun pretty_results ctxt ((kind, ""), facts) =
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   316
      Pretty.block (Pretty.str kind :: Pretty.brk 1 :: prt_facts ctxt facts)
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   317
  | pretty_results ctxt ((kind, name), facts) = Pretty.blk (1,
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   318
      [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk,
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   319
        Pretty.blk (1, Pretty.str "(" :: prt_facts ctxt facts @ [Pretty.str ")"])]);
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   320
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   321
fun pretty_rule s ctxt thm =
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   322
  Pretty.block [Pretty.str (s ^ " to solve goal by exported rule:"),
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   323
    Pretty.fbrk, ProofContext.pretty_thm ctxt thm];
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   324
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   325
in
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   326
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   327
val print_result = Pretty.writeln oo pretty_results;
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   328
fun print_result' ctxt (k, res) = print_result ctxt ((k, ""), res);
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   329
13686
bc63c3b2b3e7 modified msg
nipkow
parents: 13529
diff changeset
   330
fun cond_print_result_rule int = if int
bc63c3b2b3e7 modified msg
nipkow
parents: 13529
diff changeset
   331
  then (print_result',
bc63c3b2b3e7 modified msg
nipkow
parents: 13529
diff changeset
   332
        priority oo (Pretty.string_of oo pretty_rule "Successful attempt"))
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   333
  else (K (K ()), K (K ()));
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   334
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   335
fun proof'' f = Toplevel.proof' (f o cond_print_result_rule);
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   336
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   337
fun check_goal false state = state
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   338
  | check_goal true state =
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   339
      let
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   340
        val rule = ref (NONE: thm option);
13529
49a0ad8f175e check_goal: produce error instead of warning;
wenzelm
parents: 13393
diff changeset
   341
        fun fail exn =
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   342
          (["Problem! Local statement will fail to solve any pending goal"] @
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   343
          (case exn of NONE => [] | SOME e => [Toplevel.exn_message e]) @
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   344
          (case ! rule of NONE => [] | SOME thm =>
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   345
            [Pretty.string_of (pretty_rule "Failed attempt" (Proof.context_of state) thm)]))
13529
49a0ad8f175e check_goal: produce error instead of warning;
wenzelm
parents: 13393
diff changeset
   346
          |> cat_lines |> error;
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   347
        val check =
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   348
          (fn () => Seq.pull (SkipProof.local_skip_proof (K (K ()),
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   349
            fn _ => fn thm => rule := SOME thm) true state))
14836
ba0fc27a6c7e transform_error;
wenzelm
parents: 14778
diff changeset
   350
          |> setmp proofs 0
ba0fc27a6c7e transform_error;
wenzelm
parents: 14778
diff changeset
   351
          |> transform_error;
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   352
        val result = (check (), NONE) handle Interrupt => raise Interrupt | e => (NONE, SOME e);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   353
      in (case result of (SOME _, NONE) => () | (_, exn) => fail exn); state end;
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   354
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   355
end;
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   356
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   357
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   358
(* statements *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   359
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7242
diff changeset
   360
local
442456b2a8bb assume: multiple args;
wenzelm
parents: 7242
diff changeset
   361
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   362
fun global_attributes thy ((name, src), s) = ((name, map (Attrib.global_attribute thy) src), s);
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   363
fun local_attributes thy ((name, src), s) = ((name, map (Attrib.local_attribute thy) src), s);
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   364
fun local_attributes' state = local_attributes (Proof.theory_of state);
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   365
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   366
fun global_statement f args int thy =
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   367
  ProofHistory.init (Toplevel.undo_limit int) (f (map (global_attributes thy) args) thy);
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   368
fun global_statement_i f args int thy = ProofHistory.init (Toplevel.undo_limit int) (f args thy);
10935
808e9dbc68c4 show/thus: check_goal;
wenzelm
parents: 10464
diff changeset
   369
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   370
fun local_statement' f g args int = ProofHistory.apply (fn state =>
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   371
  f (map (local_attributes' state) args) int (g state));
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   372
fun local_statement_i' f g args int = ProofHistory.apply (f args int o g);
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   373
fun local_statement f g args = local_statement' (K o f) g args ();
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   374
fun local_statement_i f g args = local_statement_i' (K o f) g args ();
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7242
diff changeset
   375
12701
77ac6d8451ea export multi_theorem(_i), locale_multi_theorem(_i);
wenzelm
parents: 12697
diff changeset
   376
in
77ac6d8451ea export multi_theorem(_i), locale_multi_theorem(_i);
wenzelm
parents: 12697
diff changeset
   377
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   378
fun multi_theorem k thy_mod a elems concl int thy =
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   379
  global_statement (Proof.multi_theorem k thy_mod NONE (apsnd (map (Attrib.global_attribute thy)) a)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   380
    (map (Locale.map_attrib_elem_or_expr (Attrib.multi_attribute thy)) elems)) concl int thy;
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   381
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   382
fun multi_theorem_i k thy_mod a = global_statement_i o Proof.multi_theorem_i k thy_mod NONE a;
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   383
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
   384
fun locale_multi_theorem k locale (name, atts) elems concl int thy =
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   385
  global_statement (Proof.multi_theorem k I
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   386
      (SOME (locale, (map (Attrib.multi_attribute thy) atts,
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   387
          map (map (Attrib.multi_attribute thy) o snd o fst) concl)))
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   388
      (name, []) (map (Locale.map_attrib_elem_or_expr (Attrib.multi_attribute thy)) elems))
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
   389
      (map (apfst (apsnd (K []))) concl) int thy;
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   390
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
   391
fun locale_multi_theorem_i k locale (name, atts) elems concl =
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   392
  global_statement_i (Proof.multi_theorem_i k I (SOME (locale, (atts, map (snd o fst) concl)))
12957
6b169f497a01 clarified multi statements;
wenzelm
parents: 12941
diff changeset
   393
      (name, []) elems) (map (apfst (apsnd (K []))) concl);
12697
a81fbd9787cf simplified theorem(_i);
wenzelm
parents: 12601
diff changeset
   394
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   395
fun theorem k (a, t) = multi_theorem k I a [] [(("", []), [t])];
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   396
fun theorem_i k (a, t) = multi_theorem_i k I a [] [(("", []), [t])];
11742
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   397
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   398
fun smart_multi_theorem k NONE a elems = multi_theorem k I a elems
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   399
  | smart_multi_theorem k (SOME locale) a elems = locale_multi_theorem k locale a elems;
11742
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   400
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   401
val assume      = local_statement Proof.assume I;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   402
val assume_i    = local_statement_i Proof.assume_i I;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   403
val presume     = local_statement Proof.presume I;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   404
val presume_i   = local_statement_i Proof.presume_i I;
12969
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   405
val have        = local_statement (Proof.have Seq.single true) I;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   406
val have_i      = local_statement_i (Proof.have_i Seq.single true) I;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   407
val hence       = local_statement (Proof.have Seq.single true) Proof.chain;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   408
val hence_i     = local_statement_i (Proof.have_i Seq.single true) Proof.chain;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   409
val show        = local_statement' (Proof.show check_goal Seq.single true) I;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   410
val show_i      = local_statement_i' (Proof.show_i check_goal Seq.single true) I;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   411
val thus        = local_statement' (Proof.show check_goal Seq.single true) Proof.chain;
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   412
val thus_i      = local_statement_i' (Proof.show_i check_goal Seq.single true) Proof.chain;
12141
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   413
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   414
fun gen_def f ((name, srcs), def) = ProofHistory.apply (fn state =>
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   415
  f name (map (Attrib.local_attribute (Proof.theory_of state)) srcs) def state);
d8445053eee0 theorem, have, show etc: multiple statements;
wenzelm
parents: 12062
diff changeset
   416
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   417
val local_def = gen_def Proof.def;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   418
val local_def_i = gen_def Proof.def_i;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   419
12969
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   420
fun obtain (xs, asms) = proof'' (ProofHistory.applys o (fn print => fn state =>
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   421
  Obtain.obtain xs (map (local_attributes' state) asms) print state));
11890
28e42a90bea8 improved source arrangement of obtain;
wenzelm
parents: 11793
diff changeset
   422
12969
d860fa102386 tuned local goal forms;
wenzelm
parents: 12957
diff changeset
   423
fun obtain_i (xs, asms) = proof'' (ProofHistory.applys o Obtain.obtain_i xs asms);
11890
28e42a90bea8 improved source arrangement of obtain;
wenzelm
parents: 11793
diff changeset
   424
7271
442456b2a8bb assume: multiple args;
wenzelm
parents: 7242
diff changeset
   425
end;
442456b2a8bb assume: multiple args;
wenzelm
parents: 7242
diff changeset
   426
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   427
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   428
(* blocks *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   429
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   430
val begin_block = ProofHistory.apply Proof.begin_block;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   431
val next_block = ProofHistory.apply Proof.next_block;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   432
val end_block = ProofHistory.applys Proof.end_block;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   433
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   434
8165
651b006d7eb8 added defer, prefer;
wenzelm
parents: 8090
diff changeset
   435
(* shuffle state *)
651b006d7eb8 added defer, prefer;
wenzelm
parents: 8090
diff changeset
   436
8236
df3f983f5858 apply: observe facts;
wenzelm
parents: 8227
diff changeset
   437
fun shuffle meth i = Method.refine (Method.Basic (K (meth i))) o Proof.assert_no_chain;
8204
b2a4a3d86b73 tuned prefer/defer;
wenzelm
parents: 8165
diff changeset
   438
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   439
fun defer i = ProofHistory.applys (shuffle Method.defer i);
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   440
fun prefer i = ProofHistory.applys (shuffle Method.prefer i);
8165
651b006d7eb8 added defer, prefer;
wenzelm
parents: 8090
diff changeset
   441
651b006d7eb8 added defer, prefer;
wenzelm
parents: 8090
diff changeset
   442
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   443
(* backward steps *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   444
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   445
fun apply m = ProofHistory.applys
8881
0467dd0d66ff 'apply' consumes facts;
wenzelm
parents: 8804
diff changeset
   446
  (Seq.map (Proof.goal_facts (K [])) o Method.refine m o Proof.assert_backward);
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   447
fun apply_end m = ProofHistory.applys (Method.refine_end m o Proof.assert_forward);
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   448
val proof = ProofHistory.applys o Method.proof;
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   449
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   450
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   451
(* local endings *)
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   452
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   453
val local_qed = proof'' o (ProofHistory.applys oo Method.local_qed true);
15237
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   454
val skip_local_qed =
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   455
  Toplevel.skip_proof (History.apply (fn i => if i > 1 then i - 1 else raise Toplevel.UNDEF));
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   456
val local_terminal_proof = proof'' o (ProofHistory.applys oo Method.local_terminal_proof);
8966
916966f68907 added "done" proof;
wenzelm
parents: 8897
diff changeset
   457
val local_default_proof = proof'' (ProofHistory.applys o Method.local_default_proof);
6904
4125d6b6d8f9 removed proof history nesting commands (not useful);
wenzelm
parents: 6890
diff changeset
   458
val local_immediate_proof = proof'' (ProofHistory.applys o Method.local_immediate_proof);
8966
916966f68907 added "done" proof;
wenzelm
parents: 8897
diff changeset
   459
val local_done_proof = proof'' (ProofHistory.applys o Method.local_done_proof);
12318
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   460
val local_skip_proof = Toplevel.proof' (fn int =>
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   461
  ProofHistory.applys (SkipProof.local_skip_proof (cond_print_result_rule int) int));
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   462
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   463
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   464
(* global endings *)
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   465
12318
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   466
fun global_result finish = Toplevel.proof_to_theory' (fn int => fn prf =>
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   467
  let
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   468
    val state = ProofHistory.current prf;
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   469
    val _ = if Proof.at_bottom state then () else raise Toplevel.UNDEF;
12318
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   470
    val (thy, ((kind, name), res)) = finish int state;
11742
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   471
  in
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   472
    if kind = "" orelse kind = Drule.internalK then ()
12244
179f142ffb03 improved treatment of common result name;
wenzelm
parents: 12242
diff changeset
   473
    else (print_result (Proof.context_of state) ((kind, name), res);
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   474
      Context.setmp (SOME thy) (Present.results kind) res);
11742
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   475
    thy
44034a6474e5 generic theorem kinds;
wenzelm
parents: 11717
diff changeset
   476
  end);
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   477
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   478
fun global_qed m = global_result (K (Method.global_qed true m));
15237
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   479
val skip_global_qed = Toplevel.skip_proof_to_theory (equal 1 o History.current);
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   480
fun global_terminal_proof m = global_result (K (Method.global_terminal_proof m));
12318
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   481
val global_default_proof = global_result (K Method.global_default_proof);
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   482
val global_immediate_proof = global_result (K Method.global_immediate_proof);
6888
d0c68ebdabc5 skip_proof feature 'sorry' (for quick_and_dirty mode only);
wenzelm
parents: 6885
diff changeset
   483
val global_skip_proof = global_result SkipProof.global_skip_proof;
12318
72348ff7d4a0 skip_proof: do not require quick_and_dirty in interactive mode;
wenzelm
parents: 12271
diff changeset
   484
val global_done_proof = global_result (K Method.global_done_proof);
6404
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   485
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   486
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   487
(* common endings *)
2daaf2943c79 common qed and end of proofs;
wenzelm
parents: 6371
diff changeset
   488
15237
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   489
fun qed meth = local_qed meth o global_qed meth o skip_local_qed o skip_global_qed;
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   490
fun terminal_proof meths = local_terminal_proof meths o global_terminal_proof meths;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   491
val default_proof = local_default_proof o global_default_proof;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   492
val immediate_proof = local_immediate_proof o global_immediate_proof;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   493
val done_proof = local_done_proof o global_done_proof;
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   494
val skip_proof = local_skip_proof o global_skip_proof;
15237
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   495
val forget_proof = Toplevel.proof_to_theory (Proof.theory_of o ProofHistory.current) o
250e9be7a09d Some changes to allow skipping of proof scripts.
berghofe
parents: 15206
diff changeset
   496
  Toplevel.skip_proof_to_theory (K true);
8210
ca3997312f47 added forget_proof;
wenzelm
parents: 8204
diff changeset
   497
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   498
6774
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   499
(* calculational proof commands *)
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   500
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   501
local
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   502
12055
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   503
fun cond_print_calc int ctxt thms =
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   504
  if int then
a9c44895cc8c pretty/print functions with context;
wenzelm
parents: 12045
diff changeset
   505
    Pretty.writeln (Pretty.big_list "calculation:" (map (ProofContext.pretty_thm ctxt) thms))
6774
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   506
  else ();
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   507
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   508
fun proof''' f = Toplevel.proof' (f o cond_print_calc);
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   509
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   510
fun gen_calc get f args prt state =
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   511
  f (Option.map (fn srcs => get srcs state) args) prt state;
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   512
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   513
in
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   514
14564
3667b4616e9a renamed have_thms to note_thms;
wenzelm
parents: 14528
diff changeset
   515
fun get_thmss srcs = Proof.the_facts o local_thmss Proof.note_thmss [(("", []), srcs)];
7012
ae9dac5af9d1 improved print_thms;
wenzelm
parents: 7002
diff changeset
   516
fun get_thmss_i thms _ = thms;
ae9dac5af9d1 improved print_thms;
wenzelm
parents: 7002
diff changeset
   517
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   518
fun also x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.also x);
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   519
fun also_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.also x);
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   520
fun finally x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.finally x);
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   521
fun finally_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.finally x);
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   522
val moreover = proof''' (ProofHistory.apply o Calculation.moreover);
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   523
val ultimately = proof''' (ProofHistory.apply o Calculation.ultimately);
6879
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   524
70f8c0c34b8d added with_facts(_i);
wenzelm
parents: 6850
diff changeset
   525
end;
6774
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   526
dec73900168b added also, finally;
wenzelm
parents: 6732
diff changeset
   527
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   528
(* translation functions *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   529
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   530
fun advancedT false = ""
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   531
  | advancedT true = "Sign.sg -> ";
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   532
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   533
fun advancedN false = ""
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   534
  | advancedN true = "advanced_";
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   535
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   536
fun parse_ast_translation (a, txt) =
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   537
  txt |> Context.use_let ("val parse_ast_translation: (string * (" ^ advancedT a ^
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   538
      "Syntax.ast list -> Syntax.ast)) list")
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   539
    ("Theory.add_" ^ advancedN a ^ "trfuns (parse_ast_translation, [], [], [])");
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   540
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   541
fun parse_translation (a, txt) =
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   542
  txt |> Context.use_let ("val parse_translation: (string * (" ^ advancedT a ^
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   543
      "term list -> term)) list")
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   544
    ("Theory.add_" ^ advancedN a ^ "trfuns ([], parse_translation, [], [])");
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   545
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   546
fun print_translation (a, txt) =
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   547
  txt |> Context.use_let ("val print_translation: (string * (" ^ advancedT a ^
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   548
      "term list -> term)) list")
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   549
    ("Theory.add_" ^ advancedN a ^ "trfuns ([], [], print_translation, [])");
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   550
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   551
fun print_ast_translation (a, txt) =
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   552
  txt |> Context.use_let ("val print_ast_translation: (string * (" ^ advancedT a ^
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   553
      "Syntax.ast list -> Syntax.ast)) list")
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   554
    ("Theory.add_" ^ advancedN a ^ "trfuns ([], [], [], print_ast_translation)");
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   555
14649
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   556
fun typed_print_translation (a, txt) =
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   557
  txt |> Context.use_let ("val typed_print_translation: (string * (" ^ advancedT a ^
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   558
      "bool -> typ -> term list -> term)) list")
8ad41d25c152 removed add_constdefs(_i), see constdefs.ML for improved version; advanced translation functions;
wenzelm
parents: 14598
diff changeset
   559
    ("Theory.add_" ^ advancedN a ^ "trfunsT typed_print_translation");
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   560
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   561
val token_translation =
11717
d808005e6e08 Fixed erroneous type constraint in token_translation function.
berghofe
parents: 11048
diff changeset
   562
  Context.use_let "val token_translation: (string * string * (string -> string * real)) list"
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   563
    "Theory.add_tokentrfuns token_translation";
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   564
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   565
9193
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   566
(* add method *)
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   567
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   568
fun method_setup (name, txt, cmt) =
9193
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   569
  Context.use_let
9810
7e785df2b76a method_setup: thms closure;
wenzelm
parents: 9590
diff changeset
   570
    "val thm = PureThy.get_thm_closure (Context.the_context ());\n\
7e785df2b76a method_setup: thms closure;
wenzelm
parents: 9590
diff changeset
   571
    \val thms = PureThy.get_thms_closure (Context.the_context ());\n\
7e785df2b76a method_setup: thms closure;
wenzelm
parents: 9590
diff changeset
   572
    \val method: bstring * (Args.src -> Proof.context -> Proof.method) * string"
9193
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   573
    "PureIsar.Method.add_method method"
14598
7009f59711e3 Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents: 14564
diff changeset
   574
    ("(" ^ Library.quote name ^ ", " ^ txt ^ ", " ^ Library.quote cmt ^ ")");
9193
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   575
4f4936582889 have_theorems etc.: handle multiple lists of arguments;
wenzelm
parents: 9032
diff changeset
   576
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   577
(* add_oracle *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   578
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12848
diff changeset
   579
fun add_oracle (name, txt) =
8349
611342539639 moved use_mltext, use_mltext_theory, use_let, use_setup to context.ML;
wenzelm
parents: 8236
diff changeset
   580
  Context.use_let
9590
52e71612e42f added declare_theorems(_i);
wenzelm
parents: 9466
diff changeset
   581
    "val oracle: bstring * (Sign.sg * Object.T -> term)"
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   582
    "Theory.add_oracle oracle"
14598
7009f59711e3 Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents: 14564
diff changeset
   583
    ("(" ^ Library.quote name ^ ", " ^ txt ^ ")");
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   584
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   585
12062
feed7bb2a607 theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   586
(* add_locale *)
feed7bb2a607 theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   587
13393
bd976af8bf18 adapted add_locale;
wenzelm
parents: 13374
diff changeset
   588
fun add_locale (do_pred, name, import, body) thy =
bd976af8bf18 adapted add_locale;
wenzelm
parents: 13374
diff changeset
   589
  Locale.add_locale do_pred name import
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   590
    (map (Locale.map_attrib_element (Attrib.multi_attribute thy)) body) thy;
12062
feed7bb2a607 theorem(_i): locale atts;
wenzelm
parents: 12055
diff changeset
   591
6688
f33c89103fb4 cleaned comments;
wenzelm
parents: 6650
diff changeset
   592
(* theory init and exit *)
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   593
8804
wenzelm
parents: 8731
diff changeset
   594
fun gen_begin_theory upd name parents files =
14503
255ad604e08e Added check that Theory.ML does not occur in the files section of the theory
skalberg
parents: 13686
diff changeset
   595
  let val ml_filename = Path.pack (ThyLoad.ml_path name);
255ad604e08e Added check that Theory.ML does not occur in the files section of the theory
skalberg
parents: 13686
diff changeset
   596
      val () = if exists (equal ml_filename o #1) files
255ad604e08e Added check that Theory.ML does not occur in the files section of the theory
skalberg
parents: 13686
diff changeset
   597
               then error ((quote ml_filename) ^ " not allowed in files section for theory " ^ name)
255ad604e08e Added check that Theory.ML does not occur in the files section of the theory
skalberg
parents: 13686
diff changeset
   598
               else ()
255ad604e08e Added check that Theory.ML does not occur in the files section of the theory
skalberg
parents: 13686
diff changeset
   599
  in ThyInfo.begin_theory Present.begin_theory upd name parents (map (apfst Path.unpack) files) end;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   600
8804
wenzelm
parents: 8731
diff changeset
   601
val begin_theory = gen_begin_theory false;
7909
824ea50b8dbb end/kill_theory: check_known_thy;
wenzelm
parents: 7862
diff changeset
   602
824ea50b8dbb end/kill_theory: check_known_thy;
wenzelm
parents: 7862
diff changeset
   603
fun end_theory thy =
7932
92df50fb89ca export kill_theory;
wenzelm
parents: 7909
diff changeset
   604
  if ThyInfo.check_known_thy (PureThy.get_name thy) then ThyInfo.end_theory thy
7909
824ea50b8dbb end/kill_theory: check_known_thy;
wenzelm
parents: 7862
diff changeset
   605
  else thy;
824ea50b8dbb end/kill_theory: check_known_thy;
wenzelm
parents: 7862
diff changeset
   606
7932
92df50fb89ca export kill_theory;
wenzelm
parents: 7909
diff changeset
   607
val kill_theory = ThyInfo.if_known_thy ThyInfo.remove_thy;
6688
f33c89103fb4 cleaned comments;
wenzelm
parents: 6650
diff changeset
   608
7103
1c44df10a7bc removed update_context;
wenzelm
parents: 7012
diff changeset
   609
8804
wenzelm
parents: 8731
diff changeset
   610
fun bg_theory (name, parents, files) int = gen_begin_theory int name parents files;
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   611
fun en_theory thy = (end_theory thy; ());
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   612
7932
92df50fb89ca export kill_theory;
wenzelm
parents: 7909
diff changeset
   613
fun theory spec = Toplevel.init_theory (bg_theory spec) en_theory (kill_theory o PureThy.get_name);
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   614
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   615
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   616
(* context switch *)
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   617
7960
d5c91c131070 improved IsarThy.init_context;
wenzelm
parents: 7953
diff changeset
   618
fun fetch_context f x =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   619
  (case Context.pass NONE f x of
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   620
    ((), NONE) => raise Toplevel.UNDEF
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   621
  | ((), SOME thy) => thy);
7960
d5c91c131070 improved IsarThy.init_context;
wenzelm
parents: 7953
diff changeset
   622
d5c91c131070 improved IsarThy.init_context;
wenzelm
parents: 7953
diff changeset
   623
fun init_context f x = Toplevel.init_theory (fn _ => fetch_context f x) (K ()) (K ());
7953
955fde69fa7b added init_context;
wenzelm
parents: 7932
diff changeset
   624
955fde69fa7b added init_context;
wenzelm
parents: 7932
diff changeset
   625
val context = init_context (ThyInfo.quiet_update_thy true);
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   626
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   627
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   628
(* global locale registration *)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   629
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   630
fun register_globally (((prfx, atts), expr), insts) b (* bool *) thy =
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   631
  let
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   632
    val (thy', propss, activate) =
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   633
          Locale.prep_registration (prfx, []) expr insts thy;
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   634
(* TODO: convert atts *)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   635
    fun register id (thy, thm) = let
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   636
        val thm' = Drule.freeze_all thm;
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   637
      in
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   638
        (Locale.global_activate_thm id thm' thy, thm')
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   639
      end;
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   640
  in
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   641
    multi_theorem_i Drule.internalK activate ("", []) [] 
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   642
      (map (fn (id as (n, _), props) => ((NameSpace.base n, [register id]), 
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   643
        map (fn prop => (prop, ([], []))) props)) propss) b thy'
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   644
  end;
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   645
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
   646
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   647
end;