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