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