src/Pure/Isar/isar_thy.ML
author wenzelm
Wed, 17 Mar 1999 13:36:23 +0100
changeset 6371 8469852acbc0
parent 6354 a4c75cbd2fbf
child 6404 2daaf2943c79
permissions -rw-r--r--
added '_i' versions; add_constdefs; apply_theorems; fixed assume block nest;
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
TODO:
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
     8
  - 'methods' section (proof macros, ML method defs) (!?);
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
     9
  - next_block: ProofHistory open / close (!?);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    10
*)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    11
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    12
signature ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    13
sig
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    14
  val add_text: string -> theory -> theory
6354
a4c75cbd2fbf add_title;
wenzelm
parents: 6331
diff changeset
    15
  val add_title: string -> string -> string -> theory -> theory
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    16
  val add_chapter: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    17
  val add_section: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    18
  val add_subsection: string -> theory -> theory
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
    19
  val add_subsubsection: string -> theory -> theory
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    20
  val add_axioms: ((bstring * string) * Args.src list) list -> theory -> theory
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    21
  val add_axioms_i: ((bstring * term) * theory attribute list) list -> theory -> theory
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    22
  val add_defs: ((bstring * string) * Args.src list) list -> theory -> theory
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    23
  val add_defs_i: ((bstring * term) * theory attribute list) list -> theory -> theory
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    24
  val add_constdefs: ((bstring * string * mixfix) * string) list -> theory -> theory
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    25
  val add_constdefs_i: ((bstring * typ * mixfix) * term) list -> theory -> theory
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    26
  val apply_theorems: (xstring * Args.src list) list -> theory -> theory * thm list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    27
  val apply_theorems_i: (thm * theory attribute list) list -> theory -> theory * thm list
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    28
  val have_theorems: (bstring * Args.src list) * (xstring * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    29
    -> theory -> theory
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    30
  val have_theorems_i: (bstring * theory attribute list) * (thm * theory attribute list) list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    31
    -> theory -> theory
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    32
  val have_lemmas: (bstring * Args.src list) * (xstring * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    33
    -> theory -> theory
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    34
  val have_lemmas_i: (bstring * theory attribute list) * (thm * theory attribute list) list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    35
    -> theory -> theory
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    36
  val have_facts: (string * Args.src list) * (string * Args.src list) list
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
    37
    -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    38
  val have_facts_i: (string * Proof.context attribute list) *
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    39
    (thm * Proof.context attribute list) list -> ProofHistory.T -> ProofHistory.T
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    40
  val from_facts: (string * Args.src list) list -> ProofHistory.T -> ProofHistory.T
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    41
  val from_facts_i: (thm * Proof.context attribute list) list -> ProofHistory.T -> ProofHistory.T
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    42
  val chain: ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    43
  val fix: (string * string option) list -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    44
  val fix_i: (string * typ) list -> ProofHistory.T -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    45
  val match_bind: (string list * string) list -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    46
  val match_bind_i: (term list * term) list -> ProofHistory.T -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    47
  val theorem: string -> Args.src list -> string * string list -> theory -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    48
  val theorem_i: bstring -> theory attribute list -> term * term list -> theory -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    49
  val lemma: string -> Args.src list -> string * string list -> theory -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    50
  val lemma_i: bstring -> theory attribute list -> term * term list -> theory -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    51
  val assume: string -> Args.src list -> (string * string list) list
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    52
    -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    53
  val assume_i: string -> Proof.context attribute list -> (term * term list) list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    54
    -> ProofHistory.T -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    55
  val show: string -> Args.src list -> string * string list -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    56
  val show_i: string -> Proof.context attribute list -> term * term list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    57
    -> ProofHistory.T -> ProofHistory.T
5938
fe7640933a47 match_bind: 'as' patterns;
wenzelm
parents: 5925
diff changeset
    58
  val have: string -> Args.src list -> string * string list -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    59
  val have_i: string -> Proof.context attribute list -> term * term list
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    60
    -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    61
  val begin_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    62
  val next_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    63
  val end_block: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    64
  val qed_with: bstring option * Args.src list option -> ProofHistory.T -> theory
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    65
  val qed_with_i: bstring option * theory attribute list option -> ProofHistory.T -> theory
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    66
  val qed: ProofHistory.T -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    67
  val kill_proof: ProofHistory.T -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    68
  val tac: Method.text -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    69
  val tac_i: (Proof.context -> Proof.method) -> ProofHistory.T -> ProofHistory.T
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
    70
  val then_tac: Method.text -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    71
  val then_tac_i: (Proof.context -> Proof.method) -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    72
  val proof: Method.text option -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    73
  val proof_i: (Proof.context -> Proof.method) option -> ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    74
  val terminal_proof: Method.text -> ProofHistory.T -> ProofHistory.T
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
    75
  val terminal_proof_i: (Proof.context -> Proof.method) -> ProofHistory.T -> ProofHistory.T
6108
2c9ed58c30ba 'same' method, 'immediate' proof;
wenzelm
parents: 6091
diff changeset
    76
  val immediate_proof: ProofHistory.T -> ProofHistory.T
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    77
  val default_proof: ProofHistory.T -> ProofHistory.T
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    78
  val use_mltext: string -> theory option -> theory option
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    79
  val use_mltext_theory: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    80
  val use_setup: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    81
  val parse_ast_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    82
  val parse_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    83
  val print_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    84
  val typed_print_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    85
  val print_ast_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    86
  val token_translation: string -> theory -> theory
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    87
  val add_oracle: bstring * string -> theory -> theory
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
    88
  val begin_theory: string -> string list -> (string * bool) list -> theory
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
    89
  val end_theory: theory -> theory
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    90
  val theory: string * string list * (string * bool) list
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    91
    -> Toplevel.transition -> Toplevel.transition
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    92
  val context: string -> Toplevel.transition -> Toplevel.transition
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
    93
  val update_context: string -> Toplevel.transition -> Toplevel.transition
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    94
end;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    95
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    96
structure IsarThy: ISAR_THY =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    97
struct
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    98
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
    99
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   100
(** derived theory and proof operations **)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   101
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   102
(* formal comments *)   (* FIXME dummy *)
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   103
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   104
fun add_text (txt:string) (thy:theory) = thy;
6354
a4c75cbd2fbf add_title;
wenzelm
parents: 6331
diff changeset
   105
fun add_title title author date thy = thy;
5959
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   106
val add_chapter = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   107
val add_section = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   108
val add_subsection = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   109
val add_subsubsection = add_text;
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   110
7af99477751b add_text, add_chapter etc.: dummy;
wenzelm
parents: 5938
diff changeset
   111
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   112
(* axioms and defs *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   113
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   114
fun add_axms f args thy =
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   115
  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
   116
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   117
val add_axioms = add_axms PureThy.add_axioms;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   118
val add_axioms_i = PureThy.add_axioms_i;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   119
val add_defs = add_axms PureThy.add_defs;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   120
val add_defs_i = PureThy.add_defs_i;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   121
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   122
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   123
(* constdefs *)
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   124
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   125
fun gen_add_constdefs consts defs args thy =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   126
  thy
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   127
  |> consts (map fst args)
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   128
  |> defs (map (fn ((c, _, mx), s) => ((Thm.def_name (Syntax.const_name c mx), s), [])) args);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   129
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   130
val add_constdefs = gen_add_constdefs Theory.add_consts add_defs;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   131
val add_constdefs_i = gen_add_constdefs Theory.add_consts_i add_defs_i;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   132
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   133
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   134
(* theorems *)
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   135
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   136
fun gen_have_thmss get attrib f ((name, more_srcs), th_srcs) x =
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   137
  f name (map (attrib x) more_srcs)
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   138
    (map (fn (s, srcs) => (get x s, map (attrib x) srcs)) th_srcs) x;
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   139
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   140
fun global_have_thmss x = gen_have_thmss PureThy.get_thms Attrib.global_attribute x;
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   141
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   142
fun local_have_thmss x =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   143
  gen_have_thmss (ProofContext.get_thms o Proof.context_of)
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   144
    (Attrib.local_attribute o Proof.theory_of) x;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   145
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   146
fun have_thmss_i f ((name, more_atts), th_atts) =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   147
  f name more_atts (map (apfst single) th_atts);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   148
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   149
fun have_lemss name atts = PureThy.have_thmss name (atts @ [Drule.tag_lemma]);
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   150
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   151
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   152
fun apply_theorems th_srcs = global_have_thmss PureThy.have_thmss ((None, []), th_srcs);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   153
fun apply_theorems_i th_srcs = have_thmss_i PureThy.have_thmss ((None, []), th_srcs);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   154
val have_theorems = #1 oo global_have_thmss (PureThy.have_thmss o Some);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   155
val have_theorems_i = #1 oo have_thmss_i (PureThy.have_thmss o Some);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   156
val have_lemmas = #1 oo global_have_thmss (have_lemss o Some);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   157
val have_lemmas_i = #1 oo have_thmss_i (have_lemss o Some);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   158
val have_facts = ProofHistory.apply o local_have_thmss Proof.have_thmss;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   159
val have_facts_i = ProofHistory.apply o have_thmss_i Proof.have_thmss;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   160
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   161
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   162
(* forward chaining *)
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   163
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   164
val from_facts =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   165
  ProofHistory.apply o (Proof.chain oo curry (local_have_thmss Proof.have_thmss) ("", []));
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   166
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   167
val from_facts_i =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   168
  ProofHistory.apply o (Proof.chain oo curry (have_thmss_i Proof.have_thmss) ("", []));
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   169
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   170
val chain = ProofHistory.apply Proof.chain;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   171
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   172
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   173
(* context *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   174
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   175
val fix = ProofHistory.apply o Proof.fix;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   176
val fix_i = ProofHistory.apply o Proof.fix_i;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   177
val match_bind = ProofHistory.apply o Proof.match_bind;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   178
val match_bind_i = ProofHistory.apply o Proof.match_bind_i;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   179
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   180
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   181
(* statements *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   182
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   183
fun global_statement f name src s thy =
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   184
  ProofHistory.init (f name (map (Attrib.global_attribute thy) src) s thy);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   185
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   186
fun local_statement do_open f name src s = ProofHistory.apply_cond_open do_open (fn state =>
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   187
  f name (map (Attrib.local_attribute (Proof.theory_of state)) src) s state);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   188
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   189
fun global_statement_i f name atts t thy = ProofHistory.init (f name atts t thy);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   190
fun local_statement_i do_open f name atts t = ProofHistory.apply_cond_open do_open (f name atts t);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   191
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   192
val theorem = global_statement Proof.theorem;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   193
val theorem_i = global_statement_i Proof.theorem_i;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   194
val lemma = global_statement Proof.lemma;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   195
val lemma_i = global_statement_i Proof.lemma_i;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   196
val assume = local_statement false Proof.assume;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   197
val assume_i = local_statement_i false Proof.assume_i;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   198
val show = local_statement true Proof.show;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   199
val show_i = local_statement_i true Proof.show_i;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   200
val have = local_statement true Proof.have;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   201
val have_i = local_statement_i true Proof.have_i;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   202
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   203
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   204
(* end proof *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   205
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   206
fun gen_qed_with prep_att (alt_name, raw_atts) prf =
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   207
  let
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   208
    val state = ProofHistory.current prf;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   209
    val thy = Proof.theory_of state;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   210
    val alt_atts = apsome (map (prep_att thy)) raw_atts;
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   211
    val (thy', (kind, name, thm)) = Method.qed alt_name alt_atts state;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   212
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   213
    val prt_result = Pretty.block
6091
e3cdbd929a24 eliminated tthm type and Attribute structure;
wenzelm
parents: 5959
diff changeset
   214
      [Pretty.str (kind ^ " " ^ name ^ ":"), Pretty.fbrk, Display.pretty_thm thm];
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   215
  in Pretty.writeln prt_result; thy end;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   216
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   217
val qed_with = gen_qed_with Attrib.global_attribute;
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   218
val qed_with_i = gen_qed_with (K I);
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   219
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   220
val qed = qed_with (None, None);
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   221
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   222
val kill_proof = Proof.theory_of o ProofHistory.current;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   223
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   224
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   225
(* blocks *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   226
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   227
val begin_block = ProofHistory.apply_open Proof.begin_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   228
val next_block = ProofHistory.apply Proof.next_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   229
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   230
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   231
(* backward steps *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   232
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   233
val tac = ProofHistory.applys o Method.tac;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   234
val tac_i = tac o Method.Basic;
5882
c8096461f5c8 renamed tac / etac to refine / then_refine;
wenzelm
parents: 5830
diff changeset
   235
val then_tac = ProofHistory.applys o Method.then_tac;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   236
val then_tac_i = then_tac o Method.Basic;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   237
val proof = ProofHistory.applys o Method.proof;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   238
val proof_i = proof o apsome Method.Basic;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   239
val end_block = ProofHistory.applys_close Method.end_block;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   240
val terminal_proof = ProofHistory.applys_close o Method.terminal_proof;
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   241
val terminal_proof_i = terminal_proof o Method.Basic;
6108
2c9ed58c30ba 'same' method, 'immediate' proof;
wenzelm
parents: 6091
diff changeset
   242
val immediate_proof = ProofHistory.applys_close Method.immediate_proof;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   243
val default_proof = ProofHistory.applys_close Method.default_proof;
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   244
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   245
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   246
(* use ML text *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   247
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   248
fun use_mltext txt opt_thy = #2 (Context.pass opt_thy (use_text false) txt);
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   249
fun use_mltext_theory txt thy = #2 (Context.pass_theory thy (use_text false) txt);
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   250
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   251
fun use_context txt = use_mltext_theory ("Context.>> (" ^ txt ^ ");");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   252
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   253
fun use_let name body txt =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   254
  use_context ("let val " ^ name ^ " = " ^ txt ^ " in\n" ^ body ^ " end");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   255
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   256
val use_setup =
5915
66f4bde4c6e7 added have_theorems, have_lemmas, have_facts;
wenzelm
parents: 5882
diff changeset
   257
  use_let "setup: (theory -> theory) list" "Library.apply setup";
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   258
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   259
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   260
(* translation functions *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   261
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   262
val parse_ast_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   263
  use_let "parse_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   264
    "Theory.add_trfuns (parse_ast_translation, [], [], [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   265
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   266
val parse_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   267
  use_let "parse_translation: (string * (term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   268
    "Theory.add_trfuns ([], parse_translation, [], [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   269
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   270
val print_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   271
  use_let "print_translation: (string * (term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   272
    "Theory.add_trfuns ([], [], print_translation, [])";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   273
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   274
val print_ast_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   275
  use_let "print_ast_translation: (string * (Syntax.ast list -> Syntax.ast)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   276
    "Theory.add_trfuns ([], [], [], print_ast_translation)";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   277
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   278
val typed_print_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   279
  use_let "typed_print_translation: (string * (bool -> typ -> term list -> term)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   280
    "Theory.add_trfunsT typed_print_translation";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   281
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   282
val token_translation =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   283
  use_let "token_translation: (string * string * (string -> string * int)) list"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   284
    "Theory.add_tokentrfuns token_translation";
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   285
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   286
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   287
(* add_oracle *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   288
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   289
fun add_oracle (name, txt) =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   290
  use_let
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   291
    "oracle: bstring * (Sign.sg * Object.T -> term)"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   292
    "Theory.add_oracle oracle"
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   293
    ("(" ^ quote name ^ ", " ^ txt ^ ")");
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   294
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   295
6371
8469852acbc0 added '_i' versions;
wenzelm
parents: 6354
diff changeset
   296
(* theory init and exit *)      (* FIXME move? rearrange? *)
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   297
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   298
fun begin_theory name parents files =
6266
a5f9fa6b6d7c Context.fetch, Context.setmp;
wenzelm
parents: 6253
diff changeset
   299
  let
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   300
    val paths = map (apfst Path.unpack) files;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   301
    val thy = ThyInfo.begin_theory name parents paths;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   302
  in Present.begin_theory name parents paths; thy end;
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   303
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   304
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   305
(* FIXME
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   306
fun end_theory thy =
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   307
  let val thy' = PureThy.end_theory thy in
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   308
    Present.end_theory (PureThy.get_name thy');
6198
7fa2deb92b39 ThyInfo.begin_theory;
wenzelm
parents: 6108
diff changeset
   309
    transform_error ThyInfo.put_theory thy'
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   310
      handle exn => raise PureThy.ROLLBACK (thy', Some exn)     (* FIXME !!?? *)
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   311
  end;
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   312
*)
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   313
6331
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   314
fun end_theory thy =
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   315
  (Present.end_theory (PureThy.get_name thy); ThyInfo.end_theory thy);
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   316
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   317
fun bg_theory (name, parents, files) () = begin_theory name parents files;
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   318
fun en_theory thy = (end_theory thy; ());
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   319
fb7b8d6c2bd1 begin/end_theory: presentation;
wenzelm
parents: 6266
diff changeset
   320
fun theory spec = Toplevel.init_theory (bg_theory spec) en_theory;
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   321
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   322
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   323
(* context switch *)
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   324
6253
dbaf79ac2ff9 made MLWorks happy;
wenzelm
parents: 6246
diff changeset
   325
fun switch_theory load name =
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   326
  Toplevel.init_theory
6253
dbaf79ac2ff9 made MLWorks happy;
wenzelm
parents: 6246
diff changeset
   327
    (fn () => (Context.save load name; ThyInfo.get_theory name)) (K ());
6246
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   328
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   329
val context = switch_theory ThyInfo.use_thy;
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   330
val update_context = switch_theory ThyInfo.update_thy;
0aa2e536bc20 improved theory, context, update_context;
wenzelm
parents: 6198
diff changeset
   331
5830
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   332
95b619c7289b Derived theory operations.
wenzelm
parents:
diff changeset
   333
end;