src/Pure/Pure.thy
author wenzelm
Thu Jun 09 15:41:49 2016 +0200 (2016-06-09)
changeset 63270 7dd3ee7ee422
parent 63180 ddfd021884b4
child 63271 ecaa677d20bc
permissions -rw-r--r--
support for bundle definition via target;
wenzelm@48929
     1
(*  Title:      Pure/Pure.thy
wenzelm@48929
     2
    Author:     Makarius
wenzelm@48929
     3
wenzelm@62944
     4
The Pure theory, with definitions of Isar commands and some lemmas.
wenzelm@48929
     5
*)
wenzelm@48929
     6
wenzelm@48638
     7
theory Pure
wenzelm@62859
     8
keywords
wenzelm@61579
     9
    "!!" "!" "+" "--" ":" ";" "<" "<=" "=" "=>" "?" "[" "\<comment>" "\<equiv>"
wenzelm@58928
    10
    "\<leftharpoondown>" "\<rightharpoonup>" "\<rightleftharpoons>"
wenzelm@58928
    11
    "\<subseteq>" "]" "assumes" "attach" "binder" "constrains"
wenzelm@62913
    12
    "defines" "rewrites" "fixes" "for" "if" "in" "includes" "infix"
wenzelm@58928
    13
    "infixl" "infixr" "is" "notes" "obtains" "open" "output"
ballarin@61566
    14
    "overloaded" "pervasive" "premises" "private" "qualified" "rewrites"
ballarin@61566
    15
    "shows" "structure" "unchecked" "where" "when" "|"
wenzelm@58999
    16
  and "text" "txt" :: document_body
wenzelm@58999
    17
  and "text_raw" :: document_raw
wenzelm@57506
    18
  and "default_sort" :: thy_decl == ""
wenzelm@57506
    19
  and "typedecl" "type_synonym" "nonterminal" "judgment"
wenzelm@62169
    20
    "consts" "syntax" "no_syntax" "translations" "no_translations"
wenzelm@55385
    21
    "definition" "abbreviation" "type_notation" "no_type_notation" "notation"
wenzelm@61337
    22
    "no_notation" "axiomatization" "lemmas" "declare"
wenzelm@48641
    23
    "hide_class" "hide_type" "hide_const" "hide_fact" :: thy_decl
wenzelm@62849
    24
  and "ML_file" "ML_file_debug" "ML_file_no_debug" :: thy_load % "ML"
wenzelm@60957
    25
  and "SML_file" "SML_file_debug" "SML_file_no_debug" :: thy_load % "ML"
wenzelm@56618
    26
  and "SML_import" "SML_export" :: thy_decl % "ML"
wenzelm@48641
    27
  and "ML_prf" :: prf_decl % "proof"  (* FIXME % "ML" ?? *)
wenzelm@48641
    28
  and "ML_val" "ML_command" :: diag % "ML"
wenzelm@55762
    29
  and "simproc_setup" :: thy_decl % "ML" == ""
wenzelm@48641
    30
  and "setup" "local_setup" "attribute_setup" "method_setup"
wenzelm@55762
    31
    "declaration" "syntax_declaration"
wenzelm@48641
    32
    "parse_ast_translation" "parse_translation" "print_translation"
wenzelm@48641
    33
    "typed_print_translation" "print_ast_translation" "oracle" :: thy_decl % "ML"
wenzelm@48641
    34
  and "bundle" :: thy_decl
wenzelm@63270
    35
  and "bundle_target" :: thy_decl_block
wenzelm@48641
    36
  and "include" "including" :: prf_decl
wenzelm@48641
    37
  and "print_bundles" :: diag
wenzelm@59901
    38
  and "context" "locale" "experiment" :: thy_decl_block
wenzelm@51224
    39
  and "interpret" :: prf_goal % "proof"
haftmann@61890
    40
  and "interpretation" "global_interpretation" "sublocale" :: thy_goal
wenzelm@58800
    41
  and "class" :: thy_decl_block
wenzelm@48641
    42
  and "subclass" :: thy_goal
wenzelm@58800
    43
  and "instantiation" :: thy_decl_block
wenzelm@48641
    44
  and "instance" :: thy_goal
wenzelm@58800
    45
  and "overloading" :: thy_decl_block
wenzelm@48641
    46
  and "code_datatype" :: thy_decl
wenzelm@61338
    47
  and "theorem" "lemma" "corollary" "proposition" :: thy_goal
wenzelm@61337
    48
  and "schematic_goal" :: thy_goal
wenzelm@58800
    49
  and "notepad" :: thy_decl_block
wenzelm@50128
    50
  and "have" :: prf_goal % "proof"
wenzelm@50128
    51
  and "hence" :: prf_goal % "proof" == "then have"
wenzelm@50128
    52
  and "show" :: prf_asm_goal % "proof"
wenzelm@50128
    53
  and "thus" :: prf_asm_goal % "proof" == "then show"
wenzelm@48641
    54
  and "then" "from" "with" :: prf_chain % "proof"
wenzelm@60371
    55
  and "note" :: prf_decl % "proof"
wenzelm@60371
    56
  and "supply" :: prf_script % "proof"
wenzelm@60371
    57
  and "using" "unfolding" :: prf_decl % "proof"
wenzelm@63039
    58
  and "fix" "assume" "presume" "define" "def" :: prf_asm % "proof"
wenzelm@60448
    59
  and "consider" :: prf_goal % "proof"
wenzelm@53371
    60
  and "obtain" :: prf_asm_goal % "proof"
wenzelm@60624
    61
  and "guess" :: prf_script_asm_goal % "proof"
wenzelm@48641
    62
  and "let" "write" :: prf_decl % "proof"
wenzelm@48641
    63
  and "case" :: prf_asm % "proof"
wenzelm@48641
    64
  and "{" :: prf_open % "proof"
wenzelm@48641
    65
  and "}" :: prf_close % "proof"
wenzelm@60694
    66
  and "next" :: next_block % "proof"
wenzelm@48641
    67
  and "qed" :: qed_block % "proof"
wenzelm@62312
    68
  and "by" ".." "." "sorry" "\<proof>" :: "qed" % "proof"
wenzelm@53571
    69
  and "done" :: "qed_script" % "proof"
wenzelm@48641
    70
  and "oops" :: qed_global % "proof"
wenzelm@50128
    71
  and "defer" "prefer" "apply" :: prf_script % "proof"
wenzelm@50128
    72
  and "apply_end" :: prf_script % "proof" == ""
wenzelm@60624
    73
  and "subgoal" :: prf_script_goal % "proof"
wenzelm@48641
    74
  and "proof" :: prf_block % "proof"
wenzelm@48641
    75
  and "also" "moreover" :: prf_decl % "proof"
wenzelm@48641
    76
  and "finally" "ultimately" :: prf_chain % "proof"
wenzelm@48641
    77
  and "back" :: prf_script % "proof"
wenzelm@61252
    78
  and "help" "print_commands" "print_options" "print_context" "print_theory"
wenzelm@61252
    79
    "print_definitions" "print_syntax" "print_abbrevs" "print_defn_rules"
wenzelm@48641
    80
    "print_theorems" "print_locales" "print_classes" "print_locale"
wenzelm@48641
    81
    "print_interps" "print_dependencies" "print_attributes"
wenzelm@48641
    82
    "print_simpset" "print_rules" "print_trans_rules" "print_methods"
wenzelm@56069
    83
    "print_antiquotations" "print_ML_antiquotations" "thy_deps"
wenzelm@58845
    84
    "locale_deps" "class_deps" "thm_deps" "print_term_bindings"
wenzelm@57415
    85
    "print_facts" "print_cases" "print_statement" "thm" "prf" "full_prf"
wenzelm@57415
    86
    "prop" "term" "typ" "print_codesetup" "unused_thms" :: diag
wenzelm@58845
    87
  and "display_drafts" "print_state" :: diag
wenzelm@48646
    88
  and "welcome" :: diag
wenzelm@48641
    89
  and "end" :: thy_end % "theory"
wenzelm@56797
    90
  and "realizers" :: thy_decl == ""
wenzelm@56797
    91
  and "realizability" :: thy_decl == ""
wenzelm@56797
    92
  and "extract_type" "extract" :: thy_decl
wenzelm@48646
    93
  and "find_theorems" "find_consts" :: diag
wenzelm@57886
    94
  and "named_theorems" :: thy_decl
wenzelm@48638
    95
begin
wenzelm@15803
    96
wenzelm@62849
    97
section \<open>Isar commands\<close>
wenzelm@62849
    98
wenzelm@62856
    99
subsection \<open>Embedded ML text\<close>
wenzelm@62849
   100
wenzelm@62856
   101
ML \<open>
wenzelm@62849
   102
local
wenzelm@62849
   103
wenzelm@62902
   104
val semi = Scan.option @{keyword ";"};
wenzelm@62902
   105
wenzelm@62849
   106
val _ =
wenzelm@62867
   107
  Outer_Syntax.command @{command_keyword ML_file} "read and evaluate Isabelle/ML file"
wenzelm@62902
   108
    (Resources.parse_files "ML_file" --| semi >> ML_File.ML NONE);
wenzelm@62849
   109
wenzelm@62849
   110
val _ =
wenzelm@62867
   111
  Outer_Syntax.command @{command_keyword ML_file_debug}
wenzelm@62849
   112
    "read and evaluate Isabelle/ML file (with debugger information)"
wenzelm@62902
   113
    (Resources.parse_files "ML_file_debug" --| semi >> ML_File.ML (SOME true));
wenzelm@62849
   114
wenzelm@62849
   115
val _ =
wenzelm@62867
   116
  Outer_Syntax.command @{command_keyword ML_file_no_debug}
wenzelm@62849
   117
    "read and evaluate Isabelle/ML file (no debugger information)"
wenzelm@62902
   118
    (Resources.parse_files "ML_file_no_debug" --| semi >> ML_File.ML (SOME false));
wenzelm@62849
   119
wenzelm@62849
   120
val _ =
wenzelm@62849
   121
  Outer_Syntax.command @{command_keyword SML_file} "read and evaluate Standard ML file"
wenzelm@62902
   122
    (Resources.parse_files "SML_file" --| semi >> ML_File.SML NONE);
wenzelm@62849
   123
wenzelm@62849
   124
val _ =
wenzelm@62849
   125
  Outer_Syntax.command @{command_keyword SML_file_debug}
wenzelm@62849
   126
    "read and evaluate Standard ML file (with debugger information)"
wenzelm@62902
   127
    (Resources.parse_files "SML_file_debug" --| semi >> ML_File.SML (SOME true));
wenzelm@62849
   128
wenzelm@62849
   129
val _ =
wenzelm@62849
   130
  Outer_Syntax.command @{command_keyword SML_file_no_debug}
wenzelm@62849
   131
    "read and evaluate Standard ML file (no debugger information)"
wenzelm@62902
   132
    (Resources.parse_files "SML_file_no_debug" --| semi >> ML_File.SML (SOME false));
wenzelm@62849
   133
wenzelm@62849
   134
val _ =
wenzelm@62849
   135
  Outer_Syntax.command @{command_keyword SML_export} "evaluate SML within Isabelle/ML environment"
wenzelm@62849
   136
    (Parse.ML_source >> (fn source =>
wenzelm@62849
   137
      let
wenzelm@62849
   138
        val flags: ML_Compiler.flags =
wenzelm@62902
   139
          {SML = true, exchange = true, redirect = false, verbose = true,
wenzelm@62902
   140
            debug = NONE, writeln = writeln, warning = warning};
wenzelm@62849
   141
      in
wenzelm@62849
   142
        Toplevel.theory
wenzelm@62849
   143
          (Context.theory_map (ML_Context.exec (fn () => ML_Context.eval_source flags source)))
wenzelm@62849
   144
      end));
wenzelm@62849
   145
wenzelm@62849
   146
val _ =
wenzelm@62849
   147
  Outer_Syntax.command @{command_keyword SML_import} "evaluate Isabelle/ML within SML environment"
wenzelm@62849
   148
    (Parse.ML_source >> (fn source =>
wenzelm@62849
   149
      let
wenzelm@62849
   150
        val flags: ML_Compiler.flags =
wenzelm@62902
   151
          {SML = false, exchange = true, redirect = false, verbose = true,
wenzelm@62902
   152
            debug = NONE, writeln = writeln, warning = warning};
wenzelm@62849
   153
      in
wenzelm@62849
   154
        Toplevel.generic_theory
wenzelm@62849
   155
          (ML_Context.exec (fn () => ML_Context.eval_source flags source) #>
wenzelm@62849
   156
            Local_Theory.propagate_ml_env)
wenzelm@62849
   157
      end));
wenzelm@62849
   158
wenzelm@62849
   159
val _ =
wenzelm@62849
   160
  Outer_Syntax.command @{command_keyword ML_prf} "ML text within proof"
wenzelm@62849
   161
    (Parse.ML_source >> (fn source =>
wenzelm@62849
   162
      Toplevel.proof (Proof.map_context (Context.proof_map
wenzelm@62849
   163
        (ML_Context.exec (fn () =>
wenzelm@62849
   164
            ML_Context.eval_source (ML_Compiler.verbose true ML_Compiler.flags) source))) #>
wenzelm@62849
   165
          Proof.propagate_ml_env)));
wenzelm@62849
   166
wenzelm@62849
   167
val _ =
wenzelm@62849
   168
  Outer_Syntax.command @{command_keyword ML_val} "diagnostic ML text"
wenzelm@62849
   169
    (Parse.ML_source >> Isar_Cmd.ml_diag true);
wenzelm@62849
   170
wenzelm@62849
   171
val _ =
wenzelm@62849
   172
  Outer_Syntax.command @{command_keyword ML_command} "diagnostic ML text (silent)"
wenzelm@62849
   173
    (Parse.ML_source >> Isar_Cmd.ml_diag false);
wenzelm@62849
   174
wenzelm@62849
   175
val _ =
wenzelm@62849
   176
  Outer_Syntax.command @{command_keyword setup} "ML setup for global theory"
wenzelm@62849
   177
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.setup));
wenzelm@62849
   178
wenzelm@62849
   179
val _ =
wenzelm@62849
   180
  Outer_Syntax.local_theory @{command_keyword local_setup} "ML setup for local theory"
wenzelm@62849
   181
    (Parse.ML_source >> Isar_Cmd.local_setup);
wenzelm@62849
   182
wenzelm@62849
   183
val _ =
wenzelm@62856
   184
  Outer_Syntax.command @{command_keyword oracle} "declare oracle"
wenzelm@62856
   185
    (Parse.range Parse.name -- (@{keyword "="} |-- Parse.ML_source) >>
wenzelm@62856
   186
      (fn (x, y) => Toplevel.theory (Isar_Cmd.oracle x y)));
wenzelm@62856
   187
wenzelm@62856
   188
val _ =
wenzelm@62849
   189
  Outer_Syntax.local_theory @{command_keyword attribute_setup} "define attribute in ML"
wenzelm@62849
   190
    (Parse.position Parse.name --
wenzelm@62849
   191
        Parse.!!! (@{keyword "="} |-- Parse.ML_source -- Scan.optional Parse.text "")
wenzelm@62849
   192
      >> (fn (name, (txt, cmt)) => Attrib.attribute_setup name txt cmt));
wenzelm@62849
   193
wenzelm@62849
   194
val _ =
wenzelm@62849
   195
  Outer_Syntax.local_theory @{command_keyword method_setup} "define proof method in ML"
wenzelm@62849
   196
    (Parse.position Parse.name --
wenzelm@62849
   197
        Parse.!!! (@{keyword "="} |-- Parse.ML_source -- Scan.optional Parse.text "")
wenzelm@62849
   198
      >> (fn (name, (txt, cmt)) => Method.method_setup name txt cmt));
wenzelm@62849
   199
wenzelm@62849
   200
val _ =
wenzelm@62849
   201
  Outer_Syntax.local_theory @{command_keyword declaration} "generic ML declaration"
wenzelm@62849
   202
    (Parse.opt_keyword "pervasive" -- Parse.ML_source
wenzelm@62849
   203
      >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = false, pervasive = pervasive} txt));
wenzelm@62849
   204
wenzelm@62849
   205
val _ =
wenzelm@62849
   206
  Outer_Syntax.local_theory @{command_keyword syntax_declaration} "generic ML syntax declaration"
wenzelm@62849
   207
    (Parse.opt_keyword "pervasive" -- Parse.ML_source
wenzelm@62849
   208
      >> (fn (pervasive, txt) => Isar_Cmd.declaration {syntax = true, pervasive = pervasive} txt));
wenzelm@62849
   209
wenzelm@62849
   210
val _ =
wenzelm@62849
   211
  Outer_Syntax.local_theory @{command_keyword simproc_setup} "define simproc in ML"
wenzelm@62849
   212
    (Parse.position Parse.name --
wenzelm@62849
   213
      (@{keyword "("} |-- Parse.enum1 "|" Parse.term --| @{keyword ")"} --| @{keyword "="}) --
wenzelm@62913
   214
      Parse.ML_source >> (fn ((a, b), c) => Isar_Cmd.simproc_setup a b c));
wenzelm@62849
   215
wenzelm@62856
   216
in end\<close>
wenzelm@62849
   217
wenzelm@62856
   218
wenzelm@62856
   219
subsection \<open>Theory commands\<close>
wenzelm@62856
   220
wenzelm@62856
   221
subsubsection \<open>Sorts and types\<close>
wenzelm@62856
   222
wenzelm@62856
   223
ML \<open>
wenzelm@62856
   224
local
wenzelm@62856
   225
wenzelm@62856
   226
val _ =
wenzelm@62856
   227
  Outer_Syntax.local_theory @{command_keyword default_sort}
wenzelm@62856
   228
    "declare default sort for explicit type variables"
wenzelm@62856
   229
    (Parse.sort >> (fn s => fn lthy => Local_Theory.set_defsort (Syntax.read_sort lthy s) lthy));
wenzelm@62856
   230
wenzelm@62856
   231
val _ =
wenzelm@62856
   232
  Outer_Syntax.local_theory @{command_keyword typedecl} "type declaration"
wenzelm@62856
   233
    (Parse.type_args -- Parse.binding -- Parse.opt_mixfix
wenzelm@62856
   234
      >> (fn ((args, a), mx) =>
wenzelm@62856
   235
          Typedecl.typedecl {final = true} (a, map (rpair dummyS) args, mx) #> snd));
wenzelm@62856
   236
wenzelm@62856
   237
val _ =
wenzelm@62856
   238
  Outer_Syntax.local_theory @{command_keyword type_synonym} "declare type abbreviation"
wenzelm@62856
   239
    (Parse.type_args -- Parse.binding --
wenzelm@62856
   240
      (@{keyword "="} |-- Parse.!!! (Parse.typ -- Parse.opt_mixfix'))
wenzelm@62856
   241
      >> (fn ((args, a), (rhs, mx)) => snd o Typedecl.abbrev_cmd (a, args, mx) rhs));
wenzelm@62856
   242
wenzelm@62856
   243
in end\<close>
wenzelm@62856
   244
wenzelm@62856
   245
wenzelm@62856
   246
subsubsection \<open>Consts\<close>
wenzelm@62856
   247
wenzelm@62856
   248
ML \<open>
wenzelm@62856
   249
local
wenzelm@62856
   250
wenzelm@62856
   251
val _ =
wenzelm@62856
   252
  Outer_Syntax.command @{command_keyword judgment} "declare object-logic judgment"
wenzelm@62856
   253
    (Parse.const_binding >> (Toplevel.theory o Object_Logic.add_judgment_cmd));
wenzelm@62856
   254
wenzelm@62856
   255
val _ =
wenzelm@62856
   256
  Outer_Syntax.command @{command_keyword consts} "declare constants"
wenzelm@62856
   257
    (Scan.repeat1 Parse.const_binding >> (Toplevel.theory o Sign.add_consts_cmd));
wenzelm@62856
   258
wenzelm@62856
   259
in end\<close>
wenzelm@62856
   260
wenzelm@62856
   261
wenzelm@62856
   262
subsubsection \<open>Syntax and translations\<close>
wenzelm@62856
   263
wenzelm@62856
   264
ML \<open>
wenzelm@62856
   265
local
wenzelm@62856
   266
wenzelm@62856
   267
val _ =
wenzelm@62856
   268
  Outer_Syntax.command @{command_keyword nonterminal}
wenzelm@62856
   269
    "declare syntactic type constructors (grammar nonterminal symbols)"
wenzelm@62856
   270
    (Parse.and_list1 Parse.binding >> (Toplevel.theory o Sign.add_nonterminals_global));
wenzelm@62856
   271
wenzelm@62856
   272
val _ =
wenzelm@62856
   273
  Outer_Syntax.command @{command_keyword syntax} "add raw syntax clauses"
wenzelm@62856
   274
    (Parse.syntax_mode -- Scan.repeat1 Parse.const_decl
wenzelm@62856
   275
      >> (Toplevel.theory o uncurry Sign.add_syntax_cmd));
wenzelm@62856
   276
wenzelm@62856
   277
val _ =
wenzelm@62856
   278
  Outer_Syntax.command @{command_keyword no_syntax} "delete raw syntax clauses"
wenzelm@62856
   279
    (Parse.syntax_mode -- Scan.repeat1 Parse.const_decl
wenzelm@62856
   280
      >> (Toplevel.theory o uncurry Sign.del_syntax_cmd));
wenzelm@62856
   281
wenzelm@62856
   282
val trans_pat =
wenzelm@62856
   283
  Scan.optional
wenzelm@62969
   284
    (@{keyword "("} |-- Parse.!!! (Parse.inner_syntax Parse.name --| @{keyword ")"})) "logic"
wenzelm@62856
   285
    -- Parse.inner_syntax Parse.string;
wenzelm@62856
   286
wenzelm@62856
   287
fun trans_arrow toks =
wenzelm@62856
   288
  ((@{keyword "\<rightharpoonup>"} || @{keyword "=>"}) >> K Syntax.Parse_Rule ||
wenzelm@62856
   289
    (@{keyword "\<leftharpoondown>"} || @{keyword "<="}) >> K Syntax.Print_Rule ||
wenzelm@62856
   290
    (@{keyword "\<rightleftharpoons>"} || @{keyword "=="}) >> K Syntax.Parse_Print_Rule) toks;
wenzelm@62856
   291
wenzelm@62856
   292
val trans_line =
wenzelm@62856
   293
  trans_pat -- Parse.!!! (trans_arrow -- trans_pat)
wenzelm@62856
   294
    >> (fn (left, (arr, right)) => arr (left, right));
wenzelm@62856
   295
wenzelm@62856
   296
val _ =
wenzelm@62856
   297
  Outer_Syntax.command @{command_keyword translations} "add syntax translation rules"
wenzelm@62856
   298
    (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.translations));
wenzelm@62856
   299
wenzelm@62856
   300
val _ =
wenzelm@62856
   301
  Outer_Syntax.command @{command_keyword no_translations} "delete syntax translation rules"
wenzelm@62856
   302
    (Scan.repeat1 trans_line >> (Toplevel.theory o Isar_Cmd.no_translations));
wenzelm@62856
   303
wenzelm@62856
   304
in end\<close>
wenzelm@62856
   305
wenzelm@62856
   306
wenzelm@62856
   307
subsubsection \<open>Translation functions\<close>
wenzelm@62856
   308
wenzelm@62856
   309
ML \<open>
wenzelm@62856
   310
local
wenzelm@62849
   311
wenzelm@62849
   312
val _ =
wenzelm@62849
   313
  Outer_Syntax.command @{command_keyword parse_ast_translation}
wenzelm@62849
   314
    "install parse ast translation functions"
wenzelm@62849
   315
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.parse_ast_translation));
wenzelm@62849
   316
wenzelm@62849
   317
val _ =
wenzelm@62849
   318
  Outer_Syntax.command @{command_keyword parse_translation}
wenzelm@62849
   319
    "install parse translation functions"
wenzelm@62849
   320
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.parse_translation));
wenzelm@62849
   321
wenzelm@62849
   322
val _ =
wenzelm@62849
   323
  Outer_Syntax.command @{command_keyword print_translation}
wenzelm@62849
   324
    "install print translation functions"
wenzelm@62849
   325
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.print_translation));
wenzelm@62849
   326
wenzelm@62849
   327
val _ =
wenzelm@62849
   328
  Outer_Syntax.command @{command_keyword typed_print_translation}
wenzelm@62849
   329
    "install typed print translation functions"
wenzelm@62849
   330
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.typed_print_translation));
wenzelm@62849
   331
wenzelm@62849
   332
val _ =
wenzelm@62849
   333
  Outer_Syntax.command @{command_keyword print_ast_translation}
wenzelm@62849
   334
    "install print ast translation functions"
wenzelm@62849
   335
    (Parse.ML_source >> (Toplevel.theory o Isar_Cmd.print_ast_translation));
wenzelm@62849
   336
wenzelm@62856
   337
in end\<close>
wenzelm@62849
   338
wenzelm@62856
   339
wenzelm@62856
   340
subsubsection \<open>Specifications\<close>
wenzelm@62856
   341
wenzelm@62856
   342
ML \<open>
wenzelm@62856
   343
local
wenzelm@62856
   344
wenzelm@62856
   345
val _ =
wenzelm@62856
   346
  Outer_Syntax.local_theory' @{command_keyword definition} "constant definition"
wenzelm@63180
   347
    (Scan.option Parse_Spec.constdecl -- (Parse_Spec.opt_thm_name ":" -- Parse.prop) --
wenzelm@63180
   348
      Parse_Spec.if_assumes -- Parse.for_fixes >> (fn (((decl, spec), prems), params) =>
wenzelm@63180
   349
        #2 oo Specification.definition_cmd decl params prems spec));
wenzelm@62856
   350
wenzelm@62856
   351
val _ =
wenzelm@62856
   352
  Outer_Syntax.local_theory' @{command_keyword abbreviation} "constant abbreviation"
wenzelm@63180
   353
    (Parse.syntax_mode -- Scan.option Parse_Spec.constdecl -- Parse.prop -- Parse.for_fixes
wenzelm@63180
   354
      >> (fn (((mode, decl), spec), params) => Specification.abbreviation_cmd mode decl params spec));
wenzelm@62856
   355
wenzelm@63178
   356
val axiomatization =
wenzelm@63178
   357
  Parse.and_list1 (Parse_Spec.thm_name ":" -- Parse.prop) --
wenzelm@63178
   358
  Parse_Spec.if_assumes -- Parse.for_fixes >> (fn ((a, b), c) => (c, b, a));
wenzelm@63178
   359
wenzelm@62856
   360
val _ =
wenzelm@62856
   361
  Outer_Syntax.command @{command_keyword axiomatization} "axiomatic constant specification"
wenzelm@62856
   362
    (Scan.optional Parse.fixes [] --
wenzelm@63178
   363
      Scan.optional (Parse.where_ |-- Parse.!!! axiomatization) ([], [], [])
wenzelm@63178
   364
      >> (fn (a, (b, c, d)) => Toplevel.theory (#2 o Specification.axiomatization_cmd a b c d)));
wenzelm@62856
   365
wenzelm@62856
   366
in end\<close>
wenzelm@62856
   367
wenzelm@62856
   368
wenzelm@62856
   369
subsubsection \<open>Notation\<close>
wenzelm@62856
   370
wenzelm@62856
   371
ML \<open>
wenzelm@62856
   372
local
wenzelm@62856
   373
wenzelm@62856
   374
val _ =
wenzelm@62856
   375
  Outer_Syntax.local_theory @{command_keyword type_notation}
wenzelm@62856
   376
    "add concrete syntax for type constructors"
wenzelm@62856
   377
    (Parse.syntax_mode -- Parse.and_list1 (Parse.type_const -- Parse.mixfix)
wenzelm@62856
   378
      >> (fn (mode, args) => Specification.type_notation_cmd true mode args));
wenzelm@62856
   379
wenzelm@62856
   380
val _ =
wenzelm@62856
   381
  Outer_Syntax.local_theory @{command_keyword no_type_notation}
wenzelm@62856
   382
    "delete concrete syntax for type constructors"
wenzelm@62856
   383
    (Parse.syntax_mode -- Parse.and_list1 (Parse.type_const -- Parse.mixfix)
wenzelm@62856
   384
      >> (fn (mode, args) => Specification.type_notation_cmd false mode args));
wenzelm@62856
   385
wenzelm@62856
   386
val _ =
wenzelm@62856
   387
  Outer_Syntax.local_theory @{command_keyword notation}
wenzelm@62856
   388
    "add concrete syntax for constants / fixed variables"
wenzelm@62856
   389
    (Parse.syntax_mode -- Parse.and_list1 (Parse.const -- Parse.mixfix)
wenzelm@62856
   390
      >> (fn (mode, args) => Specification.notation_cmd true mode args));
wenzelm@62849
   391
wenzelm@62849
   392
val _ =
wenzelm@62856
   393
  Outer_Syntax.local_theory @{command_keyword no_notation}
wenzelm@62856
   394
    "delete concrete syntax for constants / fixed variables"
wenzelm@62856
   395
    (Parse.syntax_mode -- Parse.and_list1 (Parse.const -- Parse.mixfix)
wenzelm@62856
   396
      >> (fn (mode, args) => Specification.notation_cmd false mode args));
wenzelm@62856
   397
wenzelm@62856
   398
in end\<close>
wenzelm@62856
   399
wenzelm@62856
   400
wenzelm@62856
   401
subsubsection \<open>Theorems\<close>
wenzelm@62856
   402
wenzelm@62856
   403
ML \<open>
wenzelm@62856
   404
local
wenzelm@62856
   405
wenzelm@63094
   406
val long_keyword =
wenzelm@63094
   407
  Parse_Spec.includes >> K "" ||
wenzelm@63094
   408
  Parse_Spec.long_statement_keyword;
wenzelm@63094
   409
wenzelm@63094
   410
val long_statement =
wenzelm@63094
   411
  Scan.optional (Parse_Spec.opt_thm_name ":" --| Scan.ahead long_keyword) Attrib.empty_binding --
wenzelm@63094
   412
  Scan.optional Parse_Spec.includes [] -- Parse_Spec.long_statement
wenzelm@63094
   413
    >> (fn ((binding, includes), (elems, concl)) => (true, binding, includes, elems, concl));
wenzelm@63094
   414
wenzelm@63094
   415
val short_statement =
wenzelm@63094
   416
  Parse_Spec.statement -- Parse_Spec.if_statement -- Parse.for_fixes
wenzelm@63094
   417
    >> (fn ((shows, assumes), fixes) =>
wenzelm@63094
   418
      (false, Attrib.empty_binding, [], [Element.Fixes fixes, Element.Assumes assumes],
wenzelm@63094
   419
        Element.Shows shows));
wenzelm@63094
   420
wenzelm@63094
   421
fun theorem spec schematic descr =
wenzelm@63094
   422
  Outer_Syntax.local_theory_to_proof' spec ("state " ^ descr)
wenzelm@63094
   423
    ((long_statement || short_statement) >> (fn (long, binding, includes, elems, concl) =>
wenzelm@63094
   424
      ((if schematic then Specification.schematic_theorem_cmd else Specification.theorem_cmd)
wenzelm@63094
   425
        long Thm.theoremK NONE (K I) binding includes elems concl)));
wenzelm@63094
   426
wenzelm@63094
   427
val _ = theorem @{command_keyword theorem} false "theorem";
wenzelm@63094
   428
val _ = theorem @{command_keyword lemma} false "lemma";
wenzelm@63094
   429
val _ = theorem @{command_keyword corollary} false "corollary";
wenzelm@63094
   430
val _ = theorem @{command_keyword proposition} false "proposition";
wenzelm@63094
   431
val _ = theorem @{command_keyword schematic_goal} true "schematic goal";
wenzelm@63094
   432
wenzelm@63094
   433
in end\<close>
wenzelm@63094
   434
wenzelm@63094
   435
ML \<open>
wenzelm@63094
   436
local
wenzelm@63094
   437
wenzelm@62856
   438
val _ =
wenzelm@62856
   439
  Outer_Syntax.local_theory' @{command_keyword lemmas} "define theorems"
wenzelm@62856
   440
    (Parse_Spec.name_facts -- Parse.for_fixes >>
wenzelm@62856
   441
      (fn (facts, fixes) => #2 oo Specification.theorems_cmd Thm.theoremK facts fixes));
wenzelm@62856
   442
wenzelm@62856
   443
val _ =
wenzelm@62856
   444
  Outer_Syntax.local_theory' @{command_keyword declare} "declare theorems"
wenzelm@62969
   445
    (Parse.and_list1 Parse.thms1 -- Parse.for_fixes
wenzelm@62856
   446
      >> (fn (facts, fixes) =>
wenzelm@62856
   447
          #2 oo Specification.theorems_cmd "" [(Attrib.empty_binding, flat facts)] fixes));
wenzelm@62856
   448
wenzelm@62856
   449
val _ =
wenzelm@62856
   450
  Outer_Syntax.local_theory @{command_keyword named_theorems}
wenzelm@62856
   451
    "declare named collection of theorems"
wenzelm@62856
   452
    (Parse.and_list1 (Parse.binding -- Scan.optional Parse.text "") >>
wenzelm@62856
   453
      fold (fn (b, descr) => snd o Named_Theorems.declare b descr));
wenzelm@62856
   454
wenzelm@62856
   455
in end\<close>
wenzelm@62849
   456
wenzelm@62849
   457
wenzelm@62856
   458
subsubsection \<open>Hide names\<close>
wenzelm@62856
   459
wenzelm@62856
   460
ML \<open>
wenzelm@62856
   461
local
wenzelm@62856
   462
wenzelm@62856
   463
fun hide_names command_keyword what hide parse prep =
wenzelm@62856
   464
  Outer_Syntax.command command_keyword ("hide " ^ what ^ " from name space")
wenzelm@62856
   465
    ((Parse.opt_keyword "open" >> not) -- Scan.repeat1 parse >> (fn (fully, args) =>
wenzelm@62856
   466
      (Toplevel.theory (fn thy =>
wenzelm@62856
   467
        let val ctxt = Proof_Context.init_global thy
wenzelm@62856
   468
        in fold (hide fully o prep ctxt) args thy end))));
wenzelm@62856
   469
wenzelm@62856
   470
val _ =
wenzelm@62856
   471
  hide_names @{command_keyword hide_class} "classes" Sign.hide_class Parse.class
wenzelm@62856
   472
    Proof_Context.read_class;
wenzelm@62856
   473
wenzelm@62856
   474
val _ =
wenzelm@62856
   475
  hide_names @{command_keyword hide_type} "types" Sign.hide_type Parse.type_const
wenzelm@62856
   476
    ((#1 o dest_Type) oo Proof_Context.read_type_name {proper = true, strict = false});
wenzelm@62856
   477
wenzelm@62856
   478
val _ =
wenzelm@62856
   479
  hide_names @{command_keyword hide_const} "consts" Sign.hide_const Parse.const
wenzelm@62856
   480
    ((#1 o dest_Const) oo Proof_Context.read_const {proper = true, strict = false});
wenzelm@62856
   481
wenzelm@62856
   482
val _ =
wenzelm@62856
   483
  hide_names @{command_keyword hide_fact} "facts" Global_Theory.hide_fact
wenzelm@62969
   484
    (Parse.position Parse.name) (Global_Theory.check_fact o Proof_Context.theory_of);
wenzelm@62856
   485
wenzelm@62856
   486
in end\<close>
wenzelm@62856
   487
wenzelm@62856
   488
wenzelm@62856
   489
subsection \<open>Bundled declarations\<close>
wenzelm@62856
   490
wenzelm@62856
   491
ML \<open>
wenzelm@62856
   492
local
wenzelm@62849
   493
wenzelm@62849
   494
val _ =
wenzelm@62849
   495
  Outer_Syntax.local_theory @{command_keyword bundle} "define bundle of declarations"
wenzelm@62969
   496
    ((Parse.binding --| @{keyword "="}) -- Parse.thms1 -- Parse.for_fixes
wenzelm@62849
   497
      >> (uncurry Bundle.bundle_cmd));
wenzelm@62849
   498
wenzelm@62849
   499
val _ =
wenzelm@63270
   500
  Outer_Syntax.command @{command_keyword bundle_target} "define bundle of declarations"
wenzelm@63270
   501
    (Parse.binding --| Parse.begin >> (Toplevel.begin_local_theory true o Bundle.init));
wenzelm@63270
   502
wenzelm@63270
   503
val _ =
wenzelm@62849
   504
  Outer_Syntax.command @{command_keyword include}
wenzelm@62849
   505
    "include declarations from bundle in proof body"
wenzelm@62969
   506
    (Scan.repeat1 (Parse.position Parse.name) >> (Toplevel.proof o Bundle.include_cmd));
wenzelm@62849
   507
wenzelm@62849
   508
val _ =
wenzelm@62849
   509
  Outer_Syntax.command @{command_keyword including}
wenzelm@62849
   510
    "include declarations from bundle in goal refinement"
wenzelm@62969
   511
    (Scan.repeat1 (Parse.position Parse.name) >> (Toplevel.proof o Bundle.including_cmd));
wenzelm@62849
   512
wenzelm@62849
   513
val _ =
wenzelm@62849
   514
  Outer_Syntax.command @{command_keyword print_bundles}
wenzelm@62849
   515
    "print bundles of declarations"
wenzelm@62849
   516
    (Parse.opt_bang >> (fn b => Toplevel.keep (Bundle.print_bundles b o Toplevel.context_of)));
wenzelm@62849
   517
wenzelm@62856
   518
in end\<close>
wenzelm@62849
   519
wenzelm@62856
   520
wenzelm@62856
   521
subsection \<open>Local theory specifications\<close>
wenzelm@62856
   522
wenzelm@62856
   523
subsubsection \<open>Specification context\<close>
wenzelm@62856
   524
wenzelm@62856
   525
ML \<open>
wenzelm@62856
   526
local
wenzelm@62849
   527
wenzelm@62849
   528
val _ =
wenzelm@62849
   529
  Outer_Syntax.command @{command_keyword context} "begin local theory context"
wenzelm@62969
   530
    ((Parse.position Parse.name >> (fn name =>
wenzelm@62849
   531
        Toplevel.begin_local_theory true (Named_Target.begin name)) ||
wenzelm@62849
   532
      Scan.optional Parse_Spec.includes [] -- Scan.repeat Parse_Spec.context_element
wenzelm@62849
   533
        >> (fn (incls, elems) => Toplevel.open_target (#2 o Bundle.context_cmd incls elems)))
wenzelm@62849
   534
      --| Parse.begin);
wenzelm@62849
   535
wenzelm@62856
   536
val _ =
wenzelm@62856
   537
  Outer_Syntax.command @{command_keyword end} "end context"
wenzelm@62856
   538
    (Scan.succeed
wenzelm@62856
   539
      (Toplevel.exit o Toplevel.end_local_theory o Toplevel.close_target o
wenzelm@62856
   540
        Toplevel.end_proof (K Proof.end_notepad)));
wenzelm@62849
   541
wenzelm@62856
   542
in end\<close>
wenzelm@62856
   543
wenzelm@62856
   544
wenzelm@62856
   545
subsubsection \<open>Locales and interpretation\<close>
wenzelm@62856
   546
wenzelm@62856
   547
ML \<open>
wenzelm@62856
   548
local
wenzelm@62849
   549
wenzelm@62849
   550
val locale_val =
wenzelm@62849
   551
  Parse_Spec.locale_expression --
wenzelm@62849
   552
    Scan.optional (@{keyword "+"} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
wenzelm@62849
   553
  Scan.repeat1 Parse_Spec.context_element >> pair ([], []);
wenzelm@62849
   554
wenzelm@62849
   555
val _ =
wenzelm@62849
   556
  Outer_Syntax.command @{command_keyword locale} "define named specification context"
wenzelm@62849
   557
    (Parse.binding --
wenzelm@62849
   558
      Scan.optional (@{keyword "="} |-- Parse.!!! locale_val) (([], []), []) -- Parse.opt_begin
wenzelm@62849
   559
      >> (fn ((name, (expr, elems)), begin) =>
wenzelm@62849
   560
          Toplevel.begin_local_theory begin
wenzelm@62849
   561
            (Expression.add_locale_cmd name Binding.empty expr elems #> snd)));
wenzelm@62849
   562
wenzelm@62849
   563
val _ =
wenzelm@62849
   564
  Outer_Syntax.command @{command_keyword experiment} "open private specification context"
wenzelm@62849
   565
    (Scan.repeat Parse_Spec.context_element --| Parse.begin
wenzelm@62849
   566
      >> (fn elems =>
wenzelm@62849
   567
          Toplevel.begin_local_theory true (Experiment.experiment_cmd elems #> snd)));
wenzelm@62849
   568
wenzelm@62849
   569
val interpretation_args =
wenzelm@62849
   570
  Parse.!!! Parse_Spec.locale_expression --
wenzelm@62849
   571
    Scan.optional
wenzelm@62849
   572
      (@{keyword "rewrites"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) [];
wenzelm@62849
   573
wenzelm@62849
   574
val _ =
wenzelm@62849
   575
  Outer_Syntax.command @{command_keyword interpret}
wenzelm@62849
   576
    "prove interpretation of locale expression in proof context"
wenzelm@62849
   577
    (interpretation_args >> (fn (expr, equations) =>
wenzelm@62849
   578
      Toplevel.proof (Interpretation.interpret_cmd expr equations)));
wenzelm@62849
   579
wenzelm@62849
   580
val interpretation_args_with_defs =
wenzelm@62849
   581
  Parse.!!! Parse_Spec.locale_expression --
wenzelm@62849
   582
    (Scan.optional (@{keyword "defines"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":"
wenzelm@62849
   583
      -- ((Parse.binding -- Parse.opt_mixfix') --| @{keyword "="} -- Parse.term))) [] --
wenzelm@62849
   584
    Scan.optional
wenzelm@62849
   585
      (@{keyword "rewrites"} |-- Parse.and_list1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)) []);
wenzelm@62849
   586
wenzelm@62849
   587
val _ =
wenzelm@62849
   588
  Outer_Syntax.local_theory_to_proof @{command_keyword global_interpretation}
wenzelm@62849
   589
    "prove interpretation of locale expression into global theory"
wenzelm@62856
   590
    (interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
wenzelm@62856
   591
      Interpretation.global_interpretation_cmd expr defs equations));
wenzelm@62849
   592
wenzelm@62849
   593
val _ =
wenzelm@62849
   594
  Outer_Syntax.command @{command_keyword sublocale}
wenzelm@62849
   595
    "prove sublocale relation between a locale and a locale expression"
wenzelm@62969
   596
    ((Parse.position Parse.name --| (@{keyword "\<subseteq>"} || @{keyword "<"}) --
wenzelm@62849
   597
      interpretation_args_with_defs >> (fn (loc, (expr, (defs, equations))) =>
wenzelm@62849
   598
        Toplevel.theory_to_proof (Interpretation.global_sublocale_cmd loc expr defs equations)))
wenzelm@62849
   599
    || interpretation_args_with_defs >> (fn (expr, (defs, equations)) =>
wenzelm@62849
   600
        Toplevel.local_theory_to_proof NONE NONE (Interpretation.sublocale_cmd expr defs equations)));
wenzelm@62849
   601
wenzelm@62849
   602
val _ =
wenzelm@62849
   603
  Outer_Syntax.command @{command_keyword interpretation}
wenzelm@62849
   604
    "prove interpretation of locale expression in local theory or into global theory"
wenzelm@62849
   605
    (interpretation_args >> (fn (expr, equations) =>
wenzelm@62856
   606
      Toplevel.local_theory_to_proof NONE NONE
wenzelm@62856
   607
        (Interpretation.isar_interpretation_cmd expr equations)));
wenzelm@62856
   608
wenzelm@62856
   609
in end\<close>
wenzelm@62849
   610
wenzelm@62849
   611
wenzelm@62856
   612
subsubsection \<open>Type classes\<close>
wenzelm@62849
   613
wenzelm@62856
   614
ML \<open>
wenzelm@62856
   615
local
wenzelm@62849
   616
wenzelm@62849
   617
val class_val =
wenzelm@62849
   618
  Parse_Spec.class_expression --
wenzelm@62849
   619
    Scan.optional (@{keyword "+"} |-- Parse.!!! (Scan.repeat1 Parse_Spec.context_element)) [] ||
wenzelm@62849
   620
  Scan.repeat1 Parse_Spec.context_element >> pair [];
wenzelm@62849
   621
wenzelm@62849
   622
val _ =
wenzelm@62849
   623
  Outer_Syntax.command @{command_keyword class} "define type class"
wenzelm@62849
   624
   (Parse.binding -- Scan.optional (@{keyword "="} |-- class_val) ([], []) -- Parse.opt_begin
wenzelm@62849
   625
    >> (fn ((name, (supclasses, elems)), begin) =>
wenzelm@62849
   626
        Toplevel.begin_local_theory begin
wenzelm@62849
   627
          (Class_Declaration.class_cmd name supclasses elems #> snd)));
wenzelm@62849
   628
wenzelm@62849
   629
val _ =
wenzelm@62849
   630
  Outer_Syntax.local_theory_to_proof @{command_keyword subclass} "prove a subclass relation"
wenzelm@62849
   631
    (Parse.class >> Class_Declaration.subclass_cmd);
wenzelm@62849
   632
wenzelm@62849
   633
val _ =
wenzelm@62849
   634
  Outer_Syntax.command @{command_keyword instantiation} "instantiate and prove type arity"
wenzelm@62849
   635
   (Parse.multi_arity --| Parse.begin
wenzelm@62849
   636
     >> (fn arities => Toplevel.begin_local_theory true (Class.instantiation_cmd arities)));
wenzelm@62849
   637
wenzelm@62849
   638
val _ =
wenzelm@62849
   639
  Outer_Syntax.command @{command_keyword instance} "prove type arity or subclass relation"
wenzelm@62849
   640
  ((Parse.class --
wenzelm@62849
   641
    ((@{keyword "\<subseteq>"} || @{keyword "<"}) |-- Parse.!!! Parse.class) >> Class.classrel_cmd ||
wenzelm@62849
   642
    Parse.multi_arity >> Class.instance_arity_cmd) >> Toplevel.theory_to_proof ||
wenzelm@62849
   643
    Scan.succeed (Toplevel.local_theory_to_proof NONE NONE (Class.instantiation_instance I)));
wenzelm@62849
   644
wenzelm@62856
   645
in end\<close>
wenzelm@62849
   646
wenzelm@62856
   647
wenzelm@62856
   648
subsubsection \<open>Arbitrary overloading\<close>
wenzelm@62856
   649
wenzelm@62856
   650
ML \<open>
wenzelm@62856
   651
local
wenzelm@62849
   652
wenzelm@62849
   653
val _ =
wenzelm@62849
   654
  Outer_Syntax.command @{command_keyword overloading} "overloaded definitions"
wenzelm@62849
   655
   (Scan.repeat1 (Parse.name --| (@{keyword "=="} || @{keyword "\<equiv>"}) -- Parse.term --
wenzelm@62849
   656
      Scan.optional (@{keyword "("} |-- (@{keyword "unchecked"} >> K false) --| @{keyword ")"}) true
wenzelm@62849
   657
      >> Scan.triple1) --| Parse.begin
wenzelm@62849
   658
   >> (fn operations => Toplevel.begin_local_theory true (Overloading.overloading_cmd operations)));
wenzelm@62849
   659
wenzelm@62856
   660
in end\<close>
wenzelm@62849
   661
wenzelm@62849
   662
wenzelm@62856
   663
subsection \<open>Proof commands\<close>
wenzelm@62849
   664
wenzelm@62856
   665
ML \<open>
wenzelm@62856
   666
local
wenzelm@62849
   667
wenzelm@62849
   668
val _ =
wenzelm@62849
   669
  Outer_Syntax.local_theory_to_proof @{command_keyword notepad} "begin proof context"
wenzelm@62849
   670
    (Parse.begin >> K Proof.begin_notepad);
wenzelm@62849
   671
wenzelm@62856
   672
in end\<close>
wenzelm@62849
   673
wenzelm@62856
   674
wenzelm@62856
   675
subsubsection \<open>Statements\<close>
wenzelm@62856
   676
wenzelm@62856
   677
ML \<open>
wenzelm@62856
   678
local
wenzelm@62849
   679
wenzelm@62849
   680
val structured_statement =
wenzelm@62849
   681
  Parse_Spec.statement -- Parse_Spec.cond_statement -- Parse.for_fixes
wenzelm@62849
   682
    >> (fn ((shows, (strict, assumes)), fixes) => (strict, fixes, assumes, shows));
wenzelm@62849
   683
wenzelm@62849
   684
val _ =
wenzelm@62849
   685
  Outer_Syntax.command @{command_keyword have} "state local goal"
wenzelm@62849
   686
    (structured_statement >> (fn (a, b, c, d) =>
wenzelm@62849
   687
      Toplevel.proof' (fn int => Proof.have_cmd a NONE (K I) b c d int #> #2)));
wenzelm@62849
   688
wenzelm@62849
   689
val _ =
wenzelm@62849
   690
  Outer_Syntax.command @{command_keyword show} "state local goal, to refine pending subgoals"
wenzelm@62849
   691
    (structured_statement >> (fn (a, b, c, d) =>
wenzelm@62849
   692
      Toplevel.proof' (fn int => Proof.show_cmd a NONE (K I) b c d int #> #2)));
wenzelm@62849
   693
wenzelm@62849
   694
val _ =
wenzelm@62849
   695
  Outer_Syntax.command @{command_keyword hence} "old-style alias of \"then have\""
wenzelm@62849
   696
    (structured_statement >> (fn (a, b, c, d) =>
wenzelm@62849
   697
      Toplevel.proof' (fn int => Proof.chain #> Proof.have_cmd a NONE (K I) b c d int #> #2)));
wenzelm@62849
   698
wenzelm@62849
   699
val _ =
wenzelm@62849
   700
  Outer_Syntax.command @{command_keyword thus} "old-style alias of  \"then show\""
wenzelm@62849
   701
    (structured_statement >> (fn (a, b, c, d) =>
wenzelm@62849
   702
      Toplevel.proof' (fn int => Proof.chain #> Proof.show_cmd a NONE (K I) b c d int #> #2)));
wenzelm@62849
   703
wenzelm@62856
   704
in end\<close>
wenzelm@62849
   705
wenzelm@62856
   706
wenzelm@62856
   707
subsubsection \<open>Local facts\<close>
wenzelm@62856
   708
wenzelm@62856
   709
ML \<open>
wenzelm@62856
   710
local
wenzelm@62849
   711
wenzelm@62969
   712
val facts = Parse.and_list1 Parse.thms1;
wenzelm@62849
   713
wenzelm@62849
   714
val _ =
wenzelm@62849
   715
  Outer_Syntax.command @{command_keyword then} "forward chaining"
wenzelm@62849
   716
    (Scan.succeed (Toplevel.proof Proof.chain));
wenzelm@62849
   717
wenzelm@62849
   718
val _ =
wenzelm@62849
   719
  Outer_Syntax.command @{command_keyword from} "forward chaining from given facts"
wenzelm@62849
   720
    (facts >> (Toplevel.proof o Proof.from_thmss_cmd));
wenzelm@62849
   721
wenzelm@62849
   722
val _ =
wenzelm@62849
   723
  Outer_Syntax.command @{command_keyword with} "forward chaining from given and current facts"
wenzelm@62849
   724
    (facts >> (Toplevel.proof o Proof.with_thmss_cmd));
wenzelm@62849
   725
wenzelm@62849
   726
val _ =
wenzelm@62849
   727
  Outer_Syntax.command @{command_keyword note} "define facts"
wenzelm@62849
   728
    (Parse_Spec.name_facts >> (Toplevel.proof o Proof.note_thmss_cmd));
wenzelm@62849
   729
wenzelm@62849
   730
val _ =
wenzelm@62849
   731
  Outer_Syntax.command @{command_keyword supply} "define facts during goal refinement (unstructured)"
wenzelm@62849
   732
    (Parse_Spec.name_facts >> (Toplevel.proof o Proof.supply_cmd));
wenzelm@62849
   733
wenzelm@62849
   734
val _ =
wenzelm@62849
   735
  Outer_Syntax.command @{command_keyword using} "augment goal facts"
wenzelm@62849
   736
    (facts >> (Toplevel.proof o Proof.using_cmd));
wenzelm@62849
   737
wenzelm@62849
   738
val _ =
wenzelm@62849
   739
  Outer_Syntax.command @{command_keyword unfolding} "unfold definitions in goal and facts"
wenzelm@62849
   740
    (facts >> (Toplevel.proof o Proof.unfolding_cmd));
wenzelm@62849
   741
wenzelm@62856
   742
in end\<close>
wenzelm@62849
   743
wenzelm@62856
   744
wenzelm@62856
   745
subsubsection \<open>Proof context\<close>
wenzelm@62856
   746
wenzelm@62856
   747
ML \<open>
wenzelm@62856
   748
local
wenzelm@62856
   749
wenzelm@62856
   750
val structured_statement =
wenzelm@62856
   751
  Parse_Spec.statement -- Parse_Spec.if_statement' -- Parse.for_fixes
wenzelm@62856
   752
    >> (fn ((shows, assumes), fixes) => (fixes, assumes, shows));
wenzelm@62849
   753
wenzelm@62849
   754
val _ =
wenzelm@62849
   755
  Outer_Syntax.command @{command_keyword fix} "fix local variables (Skolem constants)"
wenzelm@62849
   756
    (Parse.fixes >> (Toplevel.proof o Proof.fix_cmd));
wenzelm@62849
   757
wenzelm@62849
   758
val _ =
wenzelm@62849
   759
  Outer_Syntax.command @{command_keyword assume} "assume propositions"
wenzelm@62856
   760
    (structured_statement >> (fn (a, b, c) => Toplevel.proof (Proof.assume_cmd a b c)));
wenzelm@62849
   761
wenzelm@62849
   762
val _ =
wenzelm@62849
   763
  Outer_Syntax.command @{command_keyword presume} "assume propositions, to be established later"
wenzelm@62856
   764
    (structured_statement >> (fn (a, b, c) => Toplevel.proof (Proof.presume_cmd a b c)));
wenzelm@62849
   765
wenzelm@62849
   766
val _ =
wenzelm@63039
   767
  Outer_Syntax.command @{command_keyword define} "local definition (non-polymorphic)"
wenzelm@63039
   768
    ((Parse.fixes --| Parse.where_) -- Parse_Spec.statement -- Parse.for_fixes
wenzelm@63039
   769
      >> (fn ((a, b), c) => Toplevel.proof (Proof.define_cmd a c b)));
wenzelm@63039
   770
wenzelm@63039
   771
val _ =
wenzelm@62849
   772
  Outer_Syntax.command @{command_keyword def} "local definition (non-polymorphic)"
wenzelm@62849
   773
    (Parse.and_list1
wenzelm@62849
   774
      (Parse_Spec.opt_thm_name ":" --
wenzelm@62849
   775
        ((Parse.binding -- Parse.opt_mixfix) --
wenzelm@62849
   776
          ((@{keyword "\<equiv>"} || @{keyword "=="}) |-- Parse.!!! Parse.termp)))
wenzelm@63043
   777
    >> (fn args => Toplevel.proof (fn state =>
wenzelm@63043
   778
        (legacy_feature "Old 'def' command -- use 'define' instead"; Proof.def_cmd args state))));
wenzelm@62849
   779
wenzelm@62849
   780
val _ =
wenzelm@62849
   781
  Outer_Syntax.command @{command_keyword consider} "state cases rule"
wenzelm@62849
   782
    (Parse_Spec.obtains >> (Toplevel.proof' o Obtain.consider_cmd));
wenzelm@62849
   783
wenzelm@62849
   784
val _ =
wenzelm@62849
   785
  Outer_Syntax.command @{command_keyword obtain} "generalized elimination"
wenzelm@63059
   786
    (Parse.parbinding -- Scan.optional (Parse.fixes --| Parse.where_) [] -- structured_statement
wenzelm@63059
   787
      >> (fn ((a, b), (c, d, e)) => Toplevel.proof' (Obtain.obtain_cmd a b c d e)));
wenzelm@62849
   788
wenzelm@62849
   789
val _ =
wenzelm@62849
   790
  Outer_Syntax.command @{command_keyword guess} "wild guessing (unstructured)"
wenzelm@62849
   791
    (Scan.optional Parse.fixes [] >> (Toplevel.proof' o Obtain.guess_cmd));
wenzelm@62849
   792
wenzelm@62849
   793
val _ =
wenzelm@62849
   794
  Outer_Syntax.command @{command_keyword let} "bind text variables"
wenzelm@62849
   795
    (Parse.and_list1 (Parse.and_list1 Parse.term -- (@{keyword "="} |-- Parse.term))
wenzelm@62849
   796
      >> (Toplevel.proof o Proof.let_bind_cmd));
wenzelm@62849
   797
wenzelm@62849
   798
val _ =
wenzelm@62849
   799
  Outer_Syntax.command @{command_keyword write} "add concrete syntax for constants / fixed variables"
wenzelm@62856
   800
    (Parse.syntax_mode -- Parse.and_list1 (Parse.const -- Parse.mixfix)
wenzelm@62849
   801
    >> (fn (mode, args) => Toplevel.proof (Proof.write_cmd mode args)));
wenzelm@62849
   802
wenzelm@62849
   803
val _ =
wenzelm@62849
   804
  Outer_Syntax.command @{command_keyword case} "invoke local context"
wenzelm@62849
   805
    (Parse_Spec.opt_thm_name ":" --
wenzelm@62849
   806
      (@{keyword "("} |--
wenzelm@62969
   807
        Parse.!!! (Parse.position Parse.name -- Scan.repeat (Parse.maybe Parse.binding)
wenzelm@62849
   808
          --| @{keyword ")"}) ||
wenzelm@62969
   809
        Parse.position Parse.name >> rpair []) >> (Toplevel.proof o Proof.case_cmd));
wenzelm@62849
   810
wenzelm@62856
   811
in end\<close>
wenzelm@62849
   812
wenzelm@62856
   813
wenzelm@62856
   814
subsubsection \<open>Proof structure\<close>
wenzelm@62856
   815
wenzelm@62856
   816
ML \<open>
wenzelm@62856
   817
local
wenzelm@62849
   818
wenzelm@62849
   819
val _ =
wenzelm@62849
   820
  Outer_Syntax.command @{command_keyword "{"} "begin explicit proof block"
wenzelm@62849
   821
    (Scan.succeed (Toplevel.proof Proof.begin_block));
wenzelm@62849
   822
wenzelm@62849
   823
val _ =
wenzelm@62849
   824
  Outer_Syntax.command @{command_keyword "}"} "end explicit proof block"
wenzelm@62849
   825
    (Scan.succeed (Toplevel.proof Proof.end_block));
wenzelm@62849
   826
wenzelm@62849
   827
val _ =
wenzelm@62849
   828
  Outer_Syntax.command @{command_keyword next} "enter next proof block"
wenzelm@62849
   829
    (Scan.succeed (Toplevel.proof Proof.next_block));
wenzelm@62849
   830
wenzelm@62856
   831
in end\<close>
wenzelm@62849
   832
wenzelm@62856
   833
wenzelm@62856
   834
subsubsection \<open>End proof\<close>
wenzelm@62856
   835
wenzelm@62856
   836
ML \<open>
wenzelm@62856
   837
local
wenzelm@62849
   838
wenzelm@62849
   839
val _ =
wenzelm@62849
   840
  Outer_Syntax.command @{command_keyword qed} "conclude proof"
wenzelm@62849
   841
    (Scan.option Method.parse >> (fn m =>
wenzelm@62849
   842
     (Option.map Method.report m;
wenzelm@62849
   843
      Isar_Cmd.qed m)));
wenzelm@62849
   844
wenzelm@62849
   845
val _ =
wenzelm@62849
   846
  Outer_Syntax.command @{command_keyword by} "terminal backward proof"
wenzelm@62849
   847
    (Method.parse -- Scan.option Method.parse >> (fn (m1, m2) =>
wenzelm@62849
   848
     (Method.report m1;
wenzelm@62849
   849
      Option.map Method.report m2;
wenzelm@62849
   850
      Isar_Cmd.terminal_proof (m1, m2))));
wenzelm@62849
   851
wenzelm@62849
   852
val _ =
wenzelm@62849
   853
  Outer_Syntax.command @{command_keyword ".."} "default proof"
wenzelm@62849
   854
    (Scan.succeed Isar_Cmd.default_proof);
wenzelm@62849
   855
wenzelm@62849
   856
val _ =
wenzelm@62849
   857
  Outer_Syntax.command @{command_keyword "."} "immediate proof"
wenzelm@62849
   858
    (Scan.succeed Isar_Cmd.immediate_proof);
wenzelm@62849
   859
wenzelm@62849
   860
val _ =
wenzelm@62849
   861
  Outer_Syntax.command @{command_keyword done} "done proof"
wenzelm@62849
   862
    (Scan.succeed Isar_Cmd.done_proof);
wenzelm@62849
   863
wenzelm@62849
   864
val _ =
wenzelm@62849
   865
  Outer_Syntax.command @{command_keyword sorry} "skip proof (quick-and-dirty mode only!)"
wenzelm@62849
   866
    (Scan.succeed Isar_Cmd.skip_proof);
wenzelm@62849
   867
wenzelm@62849
   868
val _ =
wenzelm@62849
   869
  Outer_Syntax.command @{command_keyword "\<proof>"} "dummy proof (quick-and-dirty mode only!)"
wenzelm@62849
   870
    (Scan.succeed Isar_Cmd.skip_proof);
wenzelm@62849
   871
wenzelm@62849
   872
val _ =
wenzelm@62849
   873
  Outer_Syntax.command @{command_keyword oops} "forget proof"
wenzelm@62849
   874
    (Scan.succeed (Toplevel.forget_proof true));
wenzelm@62849
   875
wenzelm@62856
   876
in end\<close>
wenzelm@62849
   877
wenzelm@62856
   878
wenzelm@62856
   879
subsubsection \<open>Proof steps\<close>
wenzelm@62856
   880
wenzelm@62856
   881
ML \<open>
wenzelm@62856
   882
local
wenzelm@62849
   883
wenzelm@62849
   884
val _ =
wenzelm@62849
   885
  Outer_Syntax.command @{command_keyword defer} "shuffle internal proof state"
wenzelm@62849
   886
    (Scan.optional Parse.nat 1 >> (Toplevel.proof o Proof.defer));
wenzelm@62849
   887
wenzelm@62849
   888
val _ =
wenzelm@62849
   889
  Outer_Syntax.command @{command_keyword prefer} "shuffle internal proof state"
wenzelm@62849
   890
    (Parse.nat >> (Toplevel.proof o Proof.prefer));
wenzelm@62849
   891
wenzelm@62849
   892
val _ =
wenzelm@62849
   893
  Outer_Syntax.command @{command_keyword apply} "initial goal refinement step (unstructured)"
wenzelm@62849
   894
    (Method.parse >> (fn m => (Method.report m; Toplevel.proofs (Proof.apply m))));
wenzelm@62849
   895
wenzelm@62849
   896
val _ =
wenzelm@62849
   897
  Outer_Syntax.command @{command_keyword apply_end} "terminal goal refinement step (unstructured)"
wenzelm@62849
   898
    (Method.parse >> (fn m => (Method.report m; Toplevel.proofs (Proof.apply_end m))));
wenzelm@62849
   899
wenzelm@62849
   900
val _ =
wenzelm@62849
   901
  Outer_Syntax.command @{command_keyword proof} "backward proof step"
wenzelm@62849
   902
    (Scan.option Method.parse >> (fn m =>
wenzelm@62849
   903
      (Option.map Method.report m; Toplevel.proofs (Proof.proof m))));
wenzelm@62849
   904
wenzelm@62856
   905
in end\<close>
wenzelm@62849
   906
wenzelm@62849
   907
wenzelm@62856
   908
subsubsection \<open>Subgoal focus\<close>
wenzelm@62856
   909
wenzelm@62856
   910
ML \<open>
wenzelm@62849
   911
local
wenzelm@62849
   912
wenzelm@62849
   913
val opt_fact_binding =
wenzelm@62849
   914
  Scan.optional (Parse.binding -- Parse.opt_attribs || Parse.attribs >> pair Binding.empty)
wenzelm@62849
   915
    Attrib.empty_binding;
wenzelm@62849
   916
wenzelm@62849
   917
val for_params =
wenzelm@62849
   918
  Scan.optional
wenzelm@62849
   919
    (@{keyword "for"} |--
wenzelm@62849
   920
      Parse.!!! ((Scan.option Parse.dots >> is_some) --
wenzelm@62849
   921
        (Scan.repeat1 (Parse.position (Parse.maybe Parse.name)))))
wenzelm@62849
   922
    (false, []);
wenzelm@62849
   923
wenzelm@62849
   924
val _ =
wenzelm@62849
   925
  Outer_Syntax.command @{command_keyword subgoal}
wenzelm@62849
   926
    "focus on first subgoal within backward refinement"
wenzelm@62849
   927
    (opt_fact_binding -- (Scan.option (@{keyword "premises"} |-- Parse.!!! opt_fact_binding)) --
wenzelm@62849
   928
      for_params >> (fn ((a, b), c) =>
wenzelm@62849
   929
        Toplevel.proofs (Seq.make_results o Seq.single o #2 o Subgoal.subgoal_cmd a b c)));
wenzelm@62849
   930
wenzelm@62856
   931
in end\<close>
wenzelm@62849
   932
wenzelm@62849
   933
wenzelm@62856
   934
subsubsection \<open>Calculation\<close>
wenzelm@62856
   935
wenzelm@62856
   936
ML \<open>
wenzelm@62856
   937
local
wenzelm@62849
   938
wenzelm@62849
   939
val calculation_args =
wenzelm@62969
   940
  Scan.option (@{keyword "("} |-- Parse.!!! ((Parse.thms1 --| @{keyword ")"})));
wenzelm@62849
   941
wenzelm@62849
   942
val _ =
wenzelm@62849
   943
  Outer_Syntax.command @{command_keyword also} "combine calculation and current facts"
wenzelm@62849
   944
    (calculation_args >> (Toplevel.proofs' o Calculation.also_cmd));
wenzelm@62849
   945
wenzelm@62849
   946
val _ =
wenzelm@62849
   947
  Outer_Syntax.command @{command_keyword finally}
wenzelm@62849
   948
    "combine calculation and current facts, exhibit result"
wenzelm@62849
   949
    (calculation_args >> (Toplevel.proofs' o Calculation.finally_cmd));
wenzelm@62849
   950
wenzelm@62849
   951
val _ =
wenzelm@62849
   952
  Outer_Syntax.command @{command_keyword moreover} "augment calculation by current facts"
wenzelm@62849
   953
    (Scan.succeed (Toplevel.proof' Calculation.moreover));
wenzelm@62849
   954
wenzelm@62849
   955
val _ =
wenzelm@62849
   956
  Outer_Syntax.command @{command_keyword ultimately}
wenzelm@62849
   957
    "augment calculation by current facts, exhibit result"
wenzelm@62849
   958
    (Scan.succeed (Toplevel.proof' Calculation.ultimately));
wenzelm@62849
   959
wenzelm@62849
   960
val _ =
wenzelm@62849
   961
  Outer_Syntax.command @{command_keyword print_trans_rules} "print transitivity rules"
wenzelm@62849
   962
    (Scan.succeed (Toplevel.keep (Calculation.print_rules o Toplevel.context_of)));
wenzelm@62849
   963
wenzelm@62856
   964
in end\<close>
wenzelm@62849
   965
wenzelm@62856
   966
wenzelm@62856
   967
subsubsection \<open>Proof navigation\<close>
wenzelm@62856
   968
wenzelm@62856
   969
ML \<open>
wenzelm@62856
   970
local
wenzelm@62849
   971
wenzelm@62849
   972
fun report_back () =
wenzelm@62849
   973
  Output.report [Markup.markup Markup.bad "Explicit backtracking"];
wenzelm@62849
   974
wenzelm@62849
   975
val _ =
wenzelm@62849
   976
  Outer_Syntax.command @{command_keyword back} "explicit backtracking of proof command"
wenzelm@62849
   977
    (Scan.succeed
wenzelm@62849
   978
     (Toplevel.actual_proof (fn prf => (report_back (); Proof_Node.back prf)) o
wenzelm@62849
   979
      Toplevel.skip_proof report_back));
wenzelm@62849
   980
wenzelm@62856
   981
in end\<close>
wenzelm@62849
   982
wenzelm@62849
   983
wenzelm@62856
   984
subsection \<open>Diagnostic commands (for interactive mode only)\<close>
wenzelm@62856
   985
wenzelm@62856
   986
ML \<open>
wenzelm@62856
   987
local
wenzelm@62849
   988
wenzelm@62849
   989
val opt_modes =
wenzelm@62969
   990
  Scan.optional (@{keyword "("} |-- Parse.!!! (Scan.repeat1 Parse.name --| @{keyword ")"})) [];
wenzelm@62849
   991
wenzelm@62849
   992
val _ =
wenzelm@62849
   993
  Outer_Syntax.command @{command_keyword help}
wenzelm@62849
   994
    "retrieve outer syntax commands according to name patterns"
wenzelm@62849
   995
    (Scan.repeat Parse.name >>
wenzelm@62849
   996
      (fn pats => Toplevel.keep (fn st => Outer_Syntax.help (Toplevel.theory_of st) pats)));
wenzelm@62849
   997
wenzelm@62849
   998
val _ =
wenzelm@62849
   999
  Outer_Syntax.command @{command_keyword print_commands} "print outer syntax commands"
wenzelm@62849
  1000
    (Scan.succeed (Toplevel.keep (Outer_Syntax.print_commands o Toplevel.theory_of)));
wenzelm@62849
  1001
wenzelm@62849
  1002
val _ =
wenzelm@62849
  1003
  Outer_Syntax.command @{command_keyword print_options} "print configuration options"
wenzelm@62849
  1004
    (Parse.opt_bang >> (fn b => Toplevel.keep (Attrib.print_options b o Toplevel.context_of)));
wenzelm@62849
  1005
wenzelm@62849
  1006
val _ =
wenzelm@62849
  1007
  Outer_Syntax.command @{command_keyword print_context}
wenzelm@62849
  1008
    "print context of local theory target"
wenzelm@62849
  1009
    (Scan.succeed (Toplevel.keep (Pretty.writeln_chunks o Toplevel.pretty_context)));
wenzelm@62849
  1010
wenzelm@62849
  1011
val _ =
wenzelm@62849
  1012
  Outer_Syntax.command @{command_keyword print_theory}
wenzelm@62849
  1013
    "print logical theory contents"
wenzelm@62849
  1014
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1015
      Toplevel.keep (Pretty.writeln o Proof_Display.pretty_theory b o Toplevel.context_of)));
wenzelm@62849
  1016
wenzelm@62849
  1017
val _ =
wenzelm@62849
  1018
  Outer_Syntax.command @{command_keyword print_definitions}
wenzelm@62849
  1019
    "print dependencies of definitional theory content"
wenzelm@62849
  1020
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1021
      Toplevel.keep (Pretty.writeln o Proof_Display.pretty_definitions b o Toplevel.context_of)));
wenzelm@62849
  1022
wenzelm@62849
  1023
val _ =
wenzelm@62849
  1024
  Outer_Syntax.command @{command_keyword print_syntax}
wenzelm@62849
  1025
    "print inner syntax of context"
wenzelm@62849
  1026
    (Scan.succeed (Toplevel.keep (Proof_Context.print_syntax o Toplevel.context_of)));
wenzelm@62849
  1027
wenzelm@62849
  1028
val _ =
wenzelm@62849
  1029
  Outer_Syntax.command @{command_keyword print_defn_rules}
wenzelm@62849
  1030
    "print definitional rewrite rules of context"
wenzelm@62849
  1031
    (Scan.succeed (Toplevel.keep (Local_Defs.print_rules o Toplevel.context_of)));
wenzelm@62849
  1032
wenzelm@62849
  1033
val _ =
wenzelm@62849
  1034
  Outer_Syntax.command @{command_keyword print_abbrevs}
wenzelm@62849
  1035
    "print constant abbreviations of context"
wenzelm@62849
  1036
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1037
      Toplevel.keep (Proof_Context.print_abbrevs b o Toplevel.context_of)));
wenzelm@62849
  1038
wenzelm@62849
  1039
val _ =
wenzelm@62849
  1040
  Outer_Syntax.command @{command_keyword print_theorems}
wenzelm@62849
  1041
    "print theorems of local theory or proof context"
wenzelm@62849
  1042
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1043
      Toplevel.keep (Pretty.writeln o Pretty.chunks o Isar_Cmd.pretty_theorems b)));
wenzelm@62849
  1044
wenzelm@62849
  1045
val _ =
wenzelm@62849
  1046
  Outer_Syntax.command @{command_keyword print_locales}
wenzelm@62849
  1047
    "print locales of this theory"
wenzelm@62849
  1048
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1049
      Toplevel.keep (Locale.print_locales b o Toplevel.theory_of)));
wenzelm@62849
  1050
wenzelm@62849
  1051
val _ =
wenzelm@62849
  1052
  Outer_Syntax.command @{command_keyword print_classes}
wenzelm@62849
  1053
    "print classes of this theory"
wenzelm@62849
  1054
    (Scan.succeed (Toplevel.keep (Class.print_classes o Toplevel.context_of)));
wenzelm@62849
  1055
wenzelm@62849
  1056
val _ =
wenzelm@62849
  1057
  Outer_Syntax.command @{command_keyword print_locale}
wenzelm@62849
  1058
    "print locale of this theory"
wenzelm@62969
  1059
    (Parse.opt_bang -- Parse.position Parse.name >> (fn (b, name) =>
wenzelm@62849
  1060
      Toplevel.keep (fn state => Locale.print_locale (Toplevel.theory_of state) b name)));
wenzelm@62849
  1061
wenzelm@62849
  1062
val _ =
wenzelm@62849
  1063
  Outer_Syntax.command @{command_keyword print_interps}
wenzelm@62849
  1064
    "print interpretations of locale for this theory or proof context"
wenzelm@62969
  1065
    (Parse.position Parse.name >> (fn name =>
wenzelm@62849
  1066
      Toplevel.keep (fn state => Locale.print_registrations (Toplevel.context_of state) name)));
wenzelm@62849
  1067
wenzelm@62849
  1068
val _ =
wenzelm@62849
  1069
  Outer_Syntax.command @{command_keyword print_dependencies}
wenzelm@62849
  1070
    "print dependencies of locale expression"
wenzelm@62849
  1071
    (Parse.opt_bang -- Parse_Spec.locale_expression >> (fn (b, expr) =>
wenzelm@62849
  1072
      Toplevel.keep (fn state => Expression.print_dependencies (Toplevel.context_of state) b expr)));
wenzelm@62849
  1073
wenzelm@62849
  1074
val _ =
wenzelm@62849
  1075
  Outer_Syntax.command @{command_keyword print_attributes}
wenzelm@62849
  1076
    "print attributes of this theory"
wenzelm@62849
  1077
    (Parse.opt_bang >> (fn b => Toplevel.keep (Attrib.print_attributes b o Toplevel.context_of)));
wenzelm@62849
  1078
wenzelm@62849
  1079
val _ =
wenzelm@62849
  1080
  Outer_Syntax.command @{command_keyword print_simpset}
wenzelm@62849
  1081
    "print context of Simplifier"
wenzelm@62849
  1082
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1083
      Toplevel.keep (Pretty.writeln o Simplifier.pretty_simpset b o Toplevel.context_of)));
wenzelm@62849
  1084
wenzelm@62849
  1085
val _ =
wenzelm@62849
  1086
  Outer_Syntax.command @{command_keyword print_rules} "print intro/elim rules"
wenzelm@62849
  1087
    (Scan.succeed (Toplevel.keep (Context_Rules.print_rules o Toplevel.context_of)));
wenzelm@62849
  1088
wenzelm@62849
  1089
val _ =
wenzelm@62849
  1090
  Outer_Syntax.command @{command_keyword print_methods} "print methods of this theory"
wenzelm@62849
  1091
    (Parse.opt_bang >> (fn b => Toplevel.keep (Method.print_methods b o Toplevel.context_of)));
wenzelm@62849
  1092
wenzelm@62849
  1093
val _ =
wenzelm@62849
  1094
  Outer_Syntax.command @{command_keyword print_antiquotations}
wenzelm@62849
  1095
    "print document antiquotations"
wenzelm@62849
  1096
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1097
      Toplevel.keep (Thy_Output.print_antiquotations b o Toplevel.context_of)));
wenzelm@62849
  1098
wenzelm@62849
  1099
val _ =
wenzelm@62849
  1100
  Outer_Syntax.command @{command_keyword print_ML_antiquotations}
wenzelm@62849
  1101
    "print ML antiquotations"
wenzelm@62849
  1102
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1103
      Toplevel.keep (ML_Context.print_antiquotations b o Toplevel.context_of)));
wenzelm@62849
  1104
wenzelm@62849
  1105
val _ =
wenzelm@62849
  1106
  Outer_Syntax.command @{command_keyword locale_deps} "visualize locale dependencies"
wenzelm@62849
  1107
    (Scan.succeed
wenzelm@62849
  1108
      (Toplevel.keep (Toplevel.theory_of #> (fn thy =>
wenzelm@62849
  1109
        Locale.pretty_locale_deps thy
wenzelm@62849
  1110
        |> map (fn {name, parents, body} =>
wenzelm@62849
  1111
          ((name, Graph_Display.content_node (Locale.extern thy name) [body]), parents))
wenzelm@62849
  1112
        |> Graph_Display.display_graph_old))));
wenzelm@62849
  1113
wenzelm@62849
  1114
val _ =
wenzelm@62849
  1115
  Outer_Syntax.command @{command_keyword print_term_bindings}
wenzelm@62849
  1116
    "print term bindings of proof context"
wenzelm@62849
  1117
    (Scan.succeed
wenzelm@62849
  1118
      (Toplevel.keep
wenzelm@62849
  1119
        (Pretty.writeln_chunks o Proof_Context.pretty_term_bindings o Toplevel.context_of)));
wenzelm@62849
  1120
wenzelm@62849
  1121
val _ =
wenzelm@62849
  1122
  Outer_Syntax.command @{command_keyword print_facts} "print facts of proof context"
wenzelm@62849
  1123
    (Parse.opt_bang >> (fn b =>
wenzelm@62849
  1124
      Toplevel.keep (Proof_Context.print_local_facts b o Toplevel.context_of)));
wenzelm@62849
  1125
wenzelm@62849
  1126
val _ =
wenzelm@62849
  1127
  Outer_Syntax.command @{command_keyword print_cases} "print cases of proof context"
wenzelm@62849
  1128
    (Scan.succeed
wenzelm@62849
  1129
      (Toplevel.keep (Pretty.writeln_chunks o Proof_Context.pretty_cases o Toplevel.context_of)));
wenzelm@62849
  1130
wenzelm@62849
  1131
val _ =
wenzelm@62849
  1132
  Outer_Syntax.command @{command_keyword print_statement}
wenzelm@62849
  1133
    "print theorems as long statements"
wenzelm@62969
  1134
    (opt_modes -- Parse.thms1 >> Isar_Cmd.print_stmts);
wenzelm@62849
  1135
wenzelm@62849
  1136
val _ =
wenzelm@62849
  1137
  Outer_Syntax.command @{command_keyword thm} "print theorems"
wenzelm@62969
  1138
    (opt_modes -- Parse.thms1 >> Isar_Cmd.print_thms);
wenzelm@62849
  1139
wenzelm@62849
  1140
val _ =
wenzelm@62849
  1141
  Outer_Syntax.command @{command_keyword prf} "print proof terms of theorems"
wenzelm@62969
  1142
    (opt_modes -- Scan.option Parse.thms1 >> Isar_Cmd.print_prfs false);
wenzelm@62849
  1143
wenzelm@62849
  1144
val _ =
wenzelm@62849
  1145
  Outer_Syntax.command @{command_keyword full_prf} "print full proof terms of theorems"
wenzelm@62969
  1146
    (opt_modes -- Scan.option Parse.thms1 >> Isar_Cmd.print_prfs true);
wenzelm@62849
  1147
wenzelm@62849
  1148
val _ =
wenzelm@62849
  1149
  Outer_Syntax.command @{command_keyword prop} "read and print proposition"
wenzelm@62849
  1150
    (opt_modes -- Parse.term >> Isar_Cmd.print_prop);
wenzelm@62849
  1151
wenzelm@62849
  1152
val _ =
wenzelm@62849
  1153
  Outer_Syntax.command @{command_keyword term} "read and print term"
wenzelm@62849
  1154
    (opt_modes -- Parse.term >> Isar_Cmd.print_term);
wenzelm@62849
  1155
wenzelm@62849
  1156
val _ =
wenzelm@62849
  1157
  Outer_Syntax.command @{command_keyword typ} "read and print type"
wenzelm@62849
  1158
    (opt_modes -- (Parse.typ -- Scan.option (@{keyword "::"} |-- Parse.!!! Parse.sort))
wenzelm@62849
  1159
      >> Isar_Cmd.print_type);
wenzelm@62849
  1160
wenzelm@62849
  1161
val _ =
wenzelm@62849
  1162
  Outer_Syntax.command @{command_keyword print_codesetup} "print code generator setup"
wenzelm@62849
  1163
    (Scan.succeed (Toplevel.keep (Code.print_codesetup o Toplevel.theory_of)));
wenzelm@62849
  1164
wenzelm@62849
  1165
val _ =
wenzelm@62849
  1166
  Outer_Syntax.command @{command_keyword print_state}
wenzelm@62849
  1167
    "print current proof state (if present)"
wenzelm@62849
  1168
    (opt_modes >> (fn modes =>
wenzelm@62849
  1169
      Toplevel.keep (Print_Mode.with_modes modes (Output.state o Toplevel.string_of_state))));
wenzelm@62849
  1170
wenzelm@62849
  1171
val _ =
wenzelm@62849
  1172
  Outer_Syntax.command @{command_keyword welcome} "print welcome message"
wenzelm@62849
  1173
    (Scan.succeed (Toplevel.keep (fn _ => writeln (Session.welcome ()))));
wenzelm@62849
  1174
wenzelm@62849
  1175
val _ =
wenzelm@62849
  1176
  Outer_Syntax.command @{command_keyword display_drafts}
wenzelm@62849
  1177
    "display raw source files with symbols"
wenzelm@62849
  1178
    (Scan.repeat1 Parse.path >> (fn names =>
wenzelm@62849
  1179
      Toplevel.keep (fn _ => ignore (Present.display_drafts (map Path.explode names)))));
wenzelm@62849
  1180
wenzelm@62856
  1181
in end\<close>
wenzelm@62849
  1182
wenzelm@62849
  1183
wenzelm@62856
  1184
subsection \<open>Dependencies\<close>
wenzelm@62856
  1185
wenzelm@62856
  1186
ML \<open>
wenzelm@62849
  1187
local
wenzelm@62856
  1188
wenzelm@62856
  1189
val theory_bounds =
wenzelm@62969
  1190
  Parse.position Parse.theory_name >> single ||
wenzelm@62969
  1191
  (@{keyword "("} |-- Parse.enum "|" (Parse.position Parse.theory_name) --| @{keyword ")"});
wenzelm@62849
  1192
wenzelm@62849
  1193
val _ =
wenzelm@62849
  1194
  Outer_Syntax.command @{command_keyword thy_deps} "visualize theory dependencies"
wenzelm@62849
  1195
    (Scan.option theory_bounds -- Scan.option theory_bounds >>
wenzelm@62849
  1196
      (fn args => Toplevel.keep (fn st => Thy_Deps.thy_deps_cmd (Toplevel.context_of st) args)));
wenzelm@62849
  1197
wenzelm@62849
  1198
wenzelm@62856
  1199
val class_bounds =
wenzelm@62856
  1200
  Parse.sort >> single ||
wenzelm@62856
  1201
  (@{keyword "("} |-- Parse.enum "|" Parse.sort --| @{keyword ")"});
wenzelm@62849
  1202
wenzelm@62849
  1203
val _ =
wenzelm@62849
  1204
  Outer_Syntax.command @{command_keyword class_deps} "visualize class dependencies"
wenzelm@62849
  1205
    (Scan.option class_bounds -- Scan.option class_bounds >> (fn args =>
wenzelm@62849
  1206
      Toplevel.keep (fn st => Class_Deps.class_deps_cmd (Toplevel.context_of st) args)));
wenzelm@62849
  1207
wenzelm@62849
  1208
wenzelm@62849
  1209
val _ =
wenzelm@62849
  1210
  Outer_Syntax.command @{command_keyword thm_deps} "visualize theorem dependencies"
wenzelm@62969
  1211
    (Parse.thms1 >> (fn args =>
wenzelm@62849
  1212
      Toplevel.keep (fn st =>
wenzelm@62849
  1213
        Thm_Deps.thm_deps (Toplevel.theory_of st)
wenzelm@62849
  1214
          (Attrib.eval_thms (Toplevel.context_of st) args))));
wenzelm@62849
  1215
wenzelm@62856
  1216
wenzelm@62856
  1217
val thy_names =
wenzelm@62969
  1218
  Scan.repeat1 (Scan.unless Parse.minus (Parse.position Parse.theory_name));
wenzelm@62849
  1219
wenzelm@62849
  1220
val _ =
wenzelm@62849
  1221
  Outer_Syntax.command @{command_keyword unused_thms} "find unused theorems"
wenzelm@62849
  1222
    (Scan.option ((thy_names --| Parse.minus) -- Scan.option thy_names) >> (fn opt_range =>
wenzelm@62849
  1223
        Toplevel.keep (fn st =>
wenzelm@62849
  1224
          let
wenzelm@62849
  1225
            val thy = Toplevel.theory_of st;
wenzelm@62849
  1226
            val ctxt = Toplevel.context_of st;
wenzelm@62849
  1227
            fun pretty_thm (a, th) = Proof_Context.pretty_fact ctxt (a, [th]);
wenzelm@62849
  1228
            val check = Theory.check ctxt;
wenzelm@62849
  1229
          in
wenzelm@62849
  1230
            Thm_Deps.unused_thms
wenzelm@62849
  1231
              (case opt_range of
wenzelm@62849
  1232
                NONE => (Theory.parents_of thy, [thy])
wenzelm@62849
  1233
              | SOME (xs, NONE) => (map check xs, [thy])
wenzelm@62849
  1234
              | SOME (xs, SOME ys) => (map check xs, map check ys))
wenzelm@62849
  1235
            |> map pretty_thm |> Pretty.writeln_chunks
wenzelm@62849
  1236
          end)));
wenzelm@62849
  1237
wenzelm@62856
  1238
in end\<close>
wenzelm@62849
  1239
wenzelm@62849
  1240
wenzelm@62856
  1241
subsubsection \<open>Find consts and theorems\<close>
wenzelm@62856
  1242
wenzelm@62856
  1243
ML \<open>
wenzelm@62856
  1244
local
wenzelm@62849
  1245
wenzelm@62849
  1246
val _ =
wenzelm@62849
  1247
  Outer_Syntax.command @{command_keyword find_consts}
wenzelm@62849
  1248
    "find constants by name / type patterns"
wenzelm@62849
  1249
    (Find_Consts.query_parser >> (fn spec =>
wenzelm@62849
  1250
      Toplevel.keep (fn st =>
wenzelm@62849
  1251
        Pretty.writeln (Find_Consts.pretty_consts (Toplevel.context_of st) spec))));
wenzelm@62849
  1252
wenzelm@62856
  1253
val options =
wenzelm@62856
  1254
  Scan.optional
wenzelm@62856
  1255
    (Parse.$$$ "(" |--
wenzelm@62856
  1256
      Parse.!!! (Scan.option Parse.nat --
wenzelm@62856
  1257
        Scan.optional (Parse.reserved "with_dups" >> K false) true --| Parse.$$$ ")"))
wenzelm@62856
  1258
    (NONE, true);
wenzelm@62849
  1259
wenzelm@62849
  1260
val _ =
wenzelm@62849
  1261
  Outer_Syntax.command @{command_keyword find_theorems}
wenzelm@62849
  1262
    "find theorems meeting specified criteria"
wenzelm@62849
  1263
    (options -- Find_Theorems.query_parser >> (fn ((opt_lim, rem_dups), spec) =>
wenzelm@62849
  1264
      Toplevel.keep (fn st =>
wenzelm@62849
  1265
        Pretty.writeln
wenzelm@62849
  1266
          (Find_Theorems.pretty_theorems (Find_Theorems.proof_state st) opt_lim rem_dups spec))));
wenzelm@62849
  1267
wenzelm@62856
  1268
in end\<close>
wenzelm@62849
  1269
wenzelm@62849
  1270
wenzelm@62856
  1271
subsection \<open>Code generation\<close>
wenzelm@62849
  1272
wenzelm@62856
  1273
ML \<open>
wenzelm@62856
  1274
local
wenzelm@62856
  1275
wenzelm@62856
  1276
val _ =
wenzelm@62856
  1277
  Outer_Syntax.command @{command_keyword code_datatype}
wenzelm@62856
  1278
    "define set of code datatype constructors"
wenzelm@62856
  1279
    (Scan.repeat1 Parse.term >> (Toplevel.theory o Code.add_datatype_cmd));
wenzelm@62856
  1280
wenzelm@62856
  1281
in end\<close>
wenzelm@62856
  1282
wenzelm@62856
  1283
wenzelm@62856
  1284
subsection \<open>Extraction of programs from proofs\<close>
wenzelm@62856
  1285
wenzelm@62856
  1286
ML \<open>
wenzelm@62856
  1287
local
wenzelm@62849
  1288
wenzelm@62849
  1289
val parse_vars = Scan.optional (Parse.$$$ "(" |-- Parse.list1 Parse.name --| Parse.$$$ ")") [];
wenzelm@62849
  1290
wenzelm@62849
  1291
val _ =
wenzelm@62849
  1292
  Outer_Syntax.command @{command_keyword realizers}
wenzelm@62849
  1293
    "specify realizers for primitive axioms / theorems, together with correctness proof"
wenzelm@62969
  1294
    (Scan.repeat1 (Parse.name -- parse_vars --| Parse.$$$ ":" -- Parse.string -- Parse.string) >>
wenzelm@62849
  1295
     (fn xs => Toplevel.theory (fn thy => Extraction.add_realizers
wenzelm@62849
  1296
       (map (fn (((a, vs), s1), s2) => (Global_Theory.get_thm thy a, (vs, s1, s2))) xs) thy)));
wenzelm@62849
  1297
wenzelm@62849
  1298
val _ =
wenzelm@62849
  1299
  Outer_Syntax.command @{command_keyword realizability}
wenzelm@62849
  1300
    "add equations characterizing realizability"
wenzelm@62849
  1301
    (Scan.repeat1 Parse.string >> (Toplevel.theory o Extraction.add_realizes_eqns));
wenzelm@62849
  1302
wenzelm@62849
  1303
val _ =
wenzelm@62849
  1304
  Outer_Syntax.command @{command_keyword extract_type}
wenzelm@62849
  1305
    "add equations characterizing type of extracted program"
wenzelm@62849
  1306
    (Scan.repeat1 Parse.string >> (Toplevel.theory o Extraction.add_typeof_eqns));
wenzelm@62849
  1307
wenzelm@62849
  1308
val _ =
wenzelm@62849
  1309
  Outer_Syntax.command @{command_keyword extract} "extract terms from proofs"
wenzelm@62969
  1310
    (Scan.repeat1 (Parse.name -- parse_vars) >> (fn xs => Toplevel.theory (fn thy =>
wenzelm@62849
  1311
      Extraction.extract (map (apfst (Global_Theory.get_thm thy)) xs) thy)));
wenzelm@62849
  1312
wenzelm@62856
  1313
in end\<close>
wenzelm@62849
  1314
wenzelm@62849
  1315
wenzelm@62944
  1316
section \<open>Auxiliary lemmas\<close>
wenzelm@20627
  1317
wenzelm@58611
  1318
subsection \<open>Meta-level connectives in assumptions\<close>
wenzelm@15803
  1319
wenzelm@15803
  1320
lemma meta_mp:
wenzelm@58612
  1321
  assumes "PROP P \<Longrightarrow> PROP Q" and "PROP P"
wenzelm@15803
  1322
  shows "PROP Q"
wenzelm@58612
  1323
    by (rule \<open>PROP P \<Longrightarrow> PROP Q\<close> [OF \<open>PROP P\<close>])
wenzelm@15803
  1324
nipkow@23432
  1325
lemmas meta_impE = meta_mp [elim_format]
nipkow@23432
  1326
wenzelm@15803
  1327
lemma meta_spec:
wenzelm@58612
  1328
  assumes "\<And>x. PROP P x"
wenzelm@26958
  1329
  shows "PROP P x"
wenzelm@58612
  1330
    by (rule \<open>\<And>x. PROP P x\<close>)
wenzelm@15803
  1331
wenzelm@15803
  1332
lemmas meta_allE = meta_spec [elim_format]
wenzelm@15803
  1333
wenzelm@26570
  1334
lemma swap_params:
wenzelm@58612
  1335
  "(\<And>x y. PROP P x y) \<equiv> (\<And>y x. PROP P x y)" ..
wenzelm@26570
  1336
wenzelm@18466
  1337
wenzelm@58611
  1338
subsection \<open>Meta-level conjunction\<close>
wenzelm@18466
  1339
wenzelm@18466
  1340
lemma all_conjunction:
wenzelm@58612
  1341
  "(\<And>x. PROP A x &&& PROP B x) \<equiv> ((\<And>x. PROP A x) &&& (\<And>x. PROP B x))"
wenzelm@18466
  1342
proof
wenzelm@58612
  1343
  assume conj: "\<And>x. PROP A x &&& PROP B x"
wenzelm@58612
  1344
  show "(\<And>x. PROP A x) &&& (\<And>x. PROP B x)"
wenzelm@19121
  1345
  proof -
wenzelm@18466
  1346
    fix x
wenzelm@26958
  1347
    from conj show "PROP A x" by (rule conjunctionD1)
wenzelm@26958
  1348
    from conj show "PROP B x" by (rule conjunctionD2)
wenzelm@18466
  1349
  qed
wenzelm@18466
  1350
next
wenzelm@58612
  1351
  assume conj: "(\<And>x. PROP A x) &&& (\<And>x. PROP B x)"
wenzelm@18466
  1352
  fix x
wenzelm@28856
  1353
  show "PROP A x &&& PROP B x"
wenzelm@19121
  1354
  proof -
wenzelm@26958
  1355
    show "PROP A x" by (rule conj [THEN conjunctionD1, rule_format])
wenzelm@26958
  1356
    show "PROP B x" by (rule conj [THEN conjunctionD2, rule_format])
wenzelm@18466
  1357
  qed
wenzelm@18466
  1358
qed
wenzelm@18466
  1359
wenzelm@19121
  1360
lemma imp_conjunction:
wenzelm@58612
  1361
  "(PROP A \<Longrightarrow> PROP B &&& PROP C) \<equiv> ((PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C))"
wenzelm@18836
  1362
proof
wenzelm@58612
  1363
  assume conj: "PROP A \<Longrightarrow> PROP B &&& PROP C"
wenzelm@58612
  1364
  show "(PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C)"
wenzelm@19121
  1365
  proof -
wenzelm@18466
  1366
    assume "PROP A"
wenzelm@58611
  1367
    from conj [OF \<open>PROP A\<close>] show "PROP B" by (rule conjunctionD1)
wenzelm@58611
  1368
    from conj [OF \<open>PROP A\<close>] show "PROP C" by (rule conjunctionD2)
wenzelm@18466
  1369
  qed
wenzelm@18466
  1370
next
wenzelm@58612
  1371
  assume conj: "(PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C)"
wenzelm@18466
  1372
  assume "PROP A"
wenzelm@28856
  1373
  show "PROP B &&& PROP C"
wenzelm@19121
  1374
  proof -
wenzelm@58611
  1375
    from \<open>PROP A\<close> show "PROP B" by (rule conj [THEN conjunctionD1])
wenzelm@58611
  1376
    from \<open>PROP A\<close> show "PROP C" by (rule conj [THEN conjunctionD2])
wenzelm@18466
  1377
  qed
wenzelm@18466
  1378
qed
wenzelm@18466
  1379
wenzelm@18466
  1380
lemma conjunction_imp:
wenzelm@58612
  1381
  "(PROP A &&& PROP B \<Longrightarrow> PROP C) \<equiv> (PROP A \<Longrightarrow> PROP B \<Longrightarrow> PROP C)"
wenzelm@18466
  1382
proof
wenzelm@58612
  1383
  assume r: "PROP A &&& PROP B \<Longrightarrow> PROP C"
wenzelm@22933
  1384
  assume ab: "PROP A" "PROP B"
wenzelm@22933
  1385
  show "PROP C"
wenzelm@22933
  1386
  proof (rule r)
wenzelm@28856
  1387
    from ab show "PROP A &&& PROP B" .
wenzelm@22933
  1388
  qed
wenzelm@18466
  1389
next
wenzelm@58612
  1390
  assume r: "PROP A \<Longrightarrow> PROP B \<Longrightarrow> PROP C"
wenzelm@28856
  1391
  assume conj: "PROP A &&& PROP B"
wenzelm@18466
  1392
  show "PROP C"
wenzelm@18466
  1393
  proof (rule r)
wenzelm@19121
  1394
    from conj show "PROP A" by (rule conjunctionD1)
wenzelm@19121
  1395
    from conj show "PROP B" by (rule conjunctionD2)
wenzelm@18466
  1396
  qed
wenzelm@18466
  1397
qed
wenzelm@18466
  1398
wenzelm@48638
  1399
end