src/Pure/Pure.thy
author wenzelm
Sun Nov 02 15:27:37 2014 +0100 (2014-11-02)
changeset 58868 c5e1cce7ace3
parent 58860 fee7cfa69c50
child 58918 8d36bc5eaed3
permissions -rw-r--r--
uniform heading commands work in any context, even in theory header;
discontinued obsolete 'sect', 'subsect', 'subsubsect';
marked obsolete 'header' as legacy;
wenzelm@48929
     1
(*  Title:      Pure/Pure.thy
wenzelm@48929
     2
    Author:     Makarius
wenzelm@48929
     3
wenzelm@48929
     4
Final stage of bootstrapping Pure, based on implicit background theory.
wenzelm@48929
     5
*)
wenzelm@48929
     6
wenzelm@48638
     7
theory Pure
wenzelm@48641
     8
  keywords
wenzelm@48641
     9
    "!!" "!" "%" "(" ")" "+" "," "--" ":" "::" ";" "<" "<=" "=" "=="
wenzelm@48641
    10
    "=>" "?" "[" "\<equiv>" "\<leftharpoondown>" "\<rightharpoonup>"
wenzelm@52143
    11
    "\<rightleftharpoons>" "\<subseteq>" "]" "and" "assumes"
wenzelm@48641
    12
    "attach" "begin" "binder" "constrains" "defines" "fixes" "for"
wenzelm@48641
    13
    "identifier" "if" "imports" "in" "includes" "infix" "infixl"
wenzelm@48641
    14
    "infixr" "is" "keywords" "notes" "obtains" "open" "output"
wenzelm@51293
    15
    "overloaded" "pervasive" "shows" "structure" "unchecked" "where" "|"
wenzelm@52449
    16
  and "theory" :: thy_begin % "theory"
wenzelm@58868
    17
  and "header" :: heading
wenzelm@58868
    18
  and "chapter" :: heading
wenzelm@58868
    19
  and "section" :: heading
wenzelm@58868
    20
  and "subsection" :: heading
wenzelm@58868
    21
  and "subsubsection" :: heading
wenzelm@48641
    22
  and "text" "text_raw" :: thy_decl
wenzelm@48641
    23
  and "txt" "txt_raw" :: prf_decl % "proof"
wenzelm@57506
    24
  and "default_sort" :: thy_decl == ""
wenzelm@57506
    25
  and "typedecl" "type_synonym" "nonterminal" "judgment"
wenzelm@55385
    26
    "consts" "syntax" "no_syntax" "translations" "no_translations" "defs"
wenzelm@55385
    27
    "definition" "abbreviation" "type_notation" "no_type_notation" "notation"
wenzelm@48641
    28
    "no_notation" "axiomatization" "theorems" "lemmas" "declare"
wenzelm@48641
    29
    "hide_class" "hide_type" "hide_const" "hide_fact" :: thy_decl
wenzelm@56618
    30
  and "SML_file" "ML_file" :: thy_load % "ML"
wenzelm@56618
    31
  and "SML_import" "SML_export" :: thy_decl % "ML"
wenzelm@51295
    32
  and "ML" :: thy_decl % "ML"
wenzelm@48641
    33
  and "ML_prf" :: prf_decl % "proof"  (* FIXME % "ML" ?? *)
wenzelm@48641
    34
  and "ML_val" "ML_command" :: diag % "ML"
wenzelm@55762
    35
  and "simproc_setup" :: thy_decl % "ML" == ""
wenzelm@48641
    36
  and "setup" "local_setup" "attribute_setup" "method_setup"
wenzelm@55762
    37
    "declaration" "syntax_declaration"
wenzelm@48641
    38
    "parse_ast_translation" "parse_translation" "print_translation"
wenzelm@48641
    39
    "typed_print_translation" "print_ast_translation" "oracle" :: thy_decl % "ML"
wenzelm@48641
    40
  and "bundle" :: thy_decl
wenzelm@48641
    41
  and "include" "including" :: prf_decl
wenzelm@48641
    42
  and "print_bundles" :: diag
wenzelm@58800
    43
  and "context" "locale" :: thy_decl_block
wenzelm@51224
    44
  and "sublocale" "interpretation" :: thy_goal
wenzelm@51224
    45
  and "interpret" :: prf_goal % "proof"
wenzelm@58800
    46
  and "class" :: thy_decl_block
wenzelm@48641
    47
  and "subclass" :: thy_goal
wenzelm@58800
    48
  and "instantiation" :: thy_decl_block
wenzelm@48641
    49
  and "instance" :: thy_goal
wenzelm@58800
    50
  and "overloading" :: thy_decl_block
wenzelm@48641
    51
  and "code_datatype" :: thy_decl
wenzelm@48641
    52
  and "theorem" "lemma" "corollary" :: thy_goal
wenzelm@51274
    53
  and "schematic_theorem" "schematic_lemma" "schematic_corollary" :: thy_goal
wenzelm@58800
    54
  and "notepad" :: thy_decl_block
wenzelm@50128
    55
  and "have" :: prf_goal % "proof"
wenzelm@50128
    56
  and "hence" :: prf_goal % "proof" == "then have"
wenzelm@50128
    57
  and "show" :: prf_asm_goal % "proof"
wenzelm@50128
    58
  and "thus" :: prf_asm_goal % "proof" == "then show"
wenzelm@48641
    59
  and "then" "from" "with" :: prf_chain % "proof"
wenzelm@48641
    60
  and "note" "using" "unfolding" :: prf_decl % "proof"
wenzelm@48641
    61
  and "fix" "assume" "presume" "def" :: prf_asm % "proof"
wenzelm@53371
    62
  and "obtain" :: prf_asm_goal % "proof"
wenzelm@53371
    63
  and "guess" :: prf_asm_goal_script % "proof"
wenzelm@48641
    64
  and "let" "write" :: prf_decl % "proof"
wenzelm@48641
    65
  and "case" :: prf_asm % "proof"
wenzelm@48641
    66
  and "{" :: prf_open % "proof"
wenzelm@48641
    67
  and "}" :: prf_close % "proof"
wenzelm@48641
    68
  and "next" :: prf_block % "proof"
wenzelm@48641
    69
  and "qed" :: qed_block % "proof"
wenzelm@53571
    70
  and "by" ".." "." "sorry" :: "qed" % "proof"
wenzelm@53571
    71
  and "done" :: "qed_script" % "proof"
wenzelm@48641
    72
  and "oops" :: qed_global % "proof"
wenzelm@50128
    73
  and "defer" "prefer" "apply" :: prf_script % "proof"
wenzelm@50128
    74
  and "apply_end" :: prf_script % "proof" == ""
wenzelm@48641
    75
  and "proof" :: prf_block % "proof"
wenzelm@48641
    76
  and "also" "moreover" :: prf_decl % "proof"
wenzelm@48641
    77
  and "finally" "ultimately" :: prf_chain % "proof"
wenzelm@48641
    78
  and "back" :: prf_script % "proof"
wenzelm@56069
    79
  and "help" "print_commands" "print_options" "print_context"
wenzelm@56069
    80
    "print_theory" "print_syntax" "print_abbrevs" "print_defn_rules"
wenzelm@48641
    81
    "print_theorems" "print_locales" "print_classes" "print_locale"
wenzelm@48641
    82
    "print_interps" "print_dependencies" "print_attributes"
wenzelm@48641
    83
    "print_simpset" "print_rules" "print_trans_rules" "print_methods"
wenzelm@56069
    84
    "print_antiquotations" "print_ML_antiquotations" "thy_deps"
wenzelm@58845
    85
    "locale_deps" "class_deps" "thm_deps" "print_term_bindings"
wenzelm@57415
    86
    "print_facts" "print_cases" "print_statement" "thm" "prf" "full_prf"
wenzelm@57415
    87
    "prop" "term" "typ" "print_codesetup" "unused_thms" :: diag
wenzelm@58845
    88
  and "display_drafts" "print_state" :: diag
wenzelm@48646
    89
  and "welcome" :: diag
wenzelm@48641
    90
  and "end" :: thy_end % "theory"
wenzelm@56797
    91
  and "realizers" :: thy_decl == ""
wenzelm@56797
    92
  and "realizability" :: thy_decl == ""
wenzelm@56797
    93
  and "extract_type" "extract" :: thy_decl
wenzelm@48646
    94
  and "find_theorems" "find_consts" :: diag
wenzelm@57886
    95
  and "named_theorems" :: thy_decl
wenzelm@48638
    96
begin
wenzelm@15803
    97
wenzelm@56205
    98
ML_file "ML/ml_antiquotations.ML"
wenzelm@55516
    99
ML_file "ML/ml_thms.ML"
wenzelm@56864
   100
ML_file "Tools/print_operation.ML"
wenzelm@48891
   101
ML_file "Isar/isar_syn.ML"
wenzelm@55141
   102
ML_file "Isar/calculation.ML"
wenzelm@58544
   103
ML_file "Tools/bibtex.ML"
wenzelm@55030
   104
ML_file "Tools/rail.ML"
wenzelm@58860
   105
ML_file "Tools/rule_insts.ML"
wenzelm@58860
   106
ML_file "Tools/thm_deps.ML"
haftmann@58201
   107
ML_file "Tools/class_deps.ML"
wenzelm@48891
   108
ML_file "Tools/find_theorems.ML"
wenzelm@48891
   109
ML_file "Tools/find_consts.ML"
wenzelm@54730
   110
ML_file "Tools/simplifier_trace.ML"
wenzelm@57886
   111
ML_file "Tools/named_theorems.ML"
wenzelm@48891
   112
wenzelm@48891
   113
wenzelm@58611
   114
section \<open>Basic attributes\<close>
wenzelm@55140
   115
wenzelm@55140
   116
attribute_setup tagged =
wenzelm@58611
   117
  \<open>Scan.lift (Args.name -- Args.name) >> Thm.tag\<close>
wenzelm@55140
   118
  "tagged theorem"
wenzelm@55140
   119
wenzelm@55140
   120
attribute_setup untagged =
wenzelm@58611
   121
  \<open>Scan.lift Args.name >> Thm.untag\<close>
wenzelm@55140
   122
  "untagged theorem"
wenzelm@55140
   123
wenzelm@55140
   124
attribute_setup kind =
wenzelm@58611
   125
  \<open>Scan.lift Args.name >> Thm.kind\<close>
wenzelm@55140
   126
  "theorem kind"
wenzelm@55140
   127
wenzelm@55140
   128
attribute_setup THEN =
wenzelm@58611
   129
  \<open>Scan.lift (Scan.optional (Args.bracks Parse.nat) 1) -- Attrib.thm
wenzelm@58611
   130
    >> (fn (i, B) => Thm.rule_attribute (fn _ => fn A => A RSN (i, B)))\<close>
wenzelm@55140
   131
  "resolution with rule"
wenzelm@55140
   132
wenzelm@55140
   133
attribute_setup OF =
wenzelm@58611
   134
  \<open>Attrib.thms >> (fn Bs => Thm.rule_attribute (fn _ => fn A => A OF Bs))\<close>
wenzelm@55140
   135
  "rule resolved with facts"
wenzelm@55140
   136
wenzelm@55140
   137
attribute_setup rename_abs =
wenzelm@58611
   138
  \<open>Scan.lift (Scan.repeat (Args.maybe Args.name)) >> (fn vs =>
wenzelm@58611
   139
    Thm.rule_attribute (K (Drule.rename_bvars' vs)))\<close>
wenzelm@55140
   140
  "rename bound variables in abstractions"
wenzelm@55140
   141
wenzelm@55140
   142
attribute_setup unfolded =
wenzelm@58611
   143
  \<open>Attrib.thms >> (fn ths =>
wenzelm@58611
   144
    Thm.rule_attribute (fn context => Local_Defs.unfold (Context.proof_of context) ths))\<close>
wenzelm@55140
   145
  "unfolded definitions"
wenzelm@55140
   146
wenzelm@55140
   147
attribute_setup folded =
wenzelm@58611
   148
  \<open>Attrib.thms >> (fn ths =>
wenzelm@58611
   149
    Thm.rule_attribute (fn context => Local_Defs.fold (Context.proof_of context) ths))\<close>
wenzelm@55140
   150
  "folded definitions"
wenzelm@55140
   151
wenzelm@55140
   152
attribute_setup consumes =
wenzelm@58611
   153
  \<open>Scan.lift (Scan.optional Parse.int 1) >> Rule_Cases.consumes\<close>
wenzelm@55140
   154
  "number of consumed facts"
wenzelm@55140
   155
wenzelm@55140
   156
attribute_setup constraints =
wenzelm@58611
   157
  \<open>Scan.lift Parse.nat >> Rule_Cases.constraints\<close>
wenzelm@55140
   158
  "number of equality constraints"
wenzelm@55140
   159
wenzelm@58611
   160
attribute_setup case_names =
wenzelm@58611
   161
  \<open>Scan.lift (Scan.repeat1 (Args.name --
wenzelm@55140
   162
    Scan.optional (@{keyword "["} |-- Scan.repeat1 (Args.maybe Args.name) --| @{keyword "]"}) []))
wenzelm@58611
   163
    >> (fn cs =>
wenzelm@55140
   164
      Rule_Cases.cases_hyp_names
wenzelm@55140
   165
        (map #1 cs)
wenzelm@58611
   166
        (map (map (the_default Rule_Cases.case_hypsN) o #2) cs))\<close>
wenzelm@58611
   167
  "named rule cases"
wenzelm@55140
   168
wenzelm@55140
   169
attribute_setup case_conclusion =
wenzelm@58611
   170
  \<open>Scan.lift (Args.name -- Scan.repeat Args.name) >> Rule_Cases.case_conclusion\<close>
wenzelm@55140
   171
  "named conclusion of rule cases"
wenzelm@55140
   172
wenzelm@55140
   173
attribute_setup params =
wenzelm@58611
   174
  \<open>Scan.lift (Parse.and_list1 (Scan.repeat Args.name)) >> Rule_Cases.params\<close>
wenzelm@55140
   175
  "named rule parameters"
wenzelm@55140
   176
wenzelm@58611
   177
attribute_setup rule_format =
wenzelm@58611
   178
  \<open>Scan.lift (Args.mode "no_asm")
wenzelm@58611
   179
    >> (fn true => Object_Logic.rule_format_no_asm | false => Object_Logic.rule_format)\<close>
wenzelm@58611
   180
  "result put into canonical rule format"
wenzelm@55140
   181
wenzelm@55140
   182
attribute_setup elim_format =
wenzelm@58611
   183
  \<open>Scan.succeed (Thm.rule_attribute (K Tactic.make_elim))\<close>
wenzelm@55140
   184
  "destruct rule turned into elimination rule format"
wenzelm@55140
   185
wenzelm@58611
   186
attribute_setup no_vars =
wenzelm@58611
   187
  \<open>Scan.succeed (Thm.rule_attribute (fn context => fn th =>
wenzelm@55140
   188
    let
wenzelm@55140
   189
      val ctxt = Variable.set_body false (Context.proof_of context);
wenzelm@55140
   190
      val ((_, [th']), _) = Variable.import true [th] ctxt;
wenzelm@58611
   191
    in th' end))\<close>
wenzelm@58611
   192
  "imported schematic variables"
wenzelm@55140
   193
wenzelm@55140
   194
attribute_setup eta_long =
wenzelm@58611
   195
  \<open>Scan.succeed (Thm.rule_attribute (fn _ => Conv.fconv_rule Drule.eta_long_conversion))\<close>
wenzelm@55140
   196
  "put theorem into eta long beta normal form"
wenzelm@55140
   197
wenzelm@55140
   198
attribute_setup atomize =
wenzelm@58611
   199
  \<open>Scan.succeed Object_Logic.declare_atomize\<close>
wenzelm@55140
   200
  "declaration of atomize rule"
wenzelm@55140
   201
wenzelm@55140
   202
attribute_setup rulify =
wenzelm@58611
   203
  \<open>Scan.succeed Object_Logic.declare_rulify\<close>
wenzelm@55140
   204
  "declaration of rulify rule"
wenzelm@55140
   205
wenzelm@55140
   206
attribute_setup rotated =
wenzelm@58611
   207
  \<open>Scan.lift (Scan.optional Parse.int 1
wenzelm@58611
   208
    >> (fn n => Thm.rule_attribute (fn _ => rotate_prems n)))\<close>
wenzelm@55140
   209
  "rotated theorem premises"
wenzelm@55140
   210
wenzelm@55140
   211
attribute_setup defn =
wenzelm@58611
   212
  \<open>Attrib.add_del Local_Defs.defn_add Local_Defs.defn_del\<close>
wenzelm@55140
   213
  "declaration of definitional transformations"
wenzelm@55140
   214
wenzelm@55140
   215
attribute_setup abs_def =
wenzelm@58611
   216
  \<open>Scan.succeed (Thm.rule_attribute (fn context =>
wenzelm@58611
   217
    Local_Defs.meta_rewrite_rule (Context.proof_of context) #> Drule.abs_def))\<close>
wenzelm@55140
   218
  "abstract over free variables of definitional theorem"
wenzelm@55140
   219
wenzelm@55140
   220
wenzelm@58611
   221
section \<open>Further content for the Pure theory\<close>
wenzelm@20627
   222
wenzelm@58611
   223
subsection \<open>Meta-level connectives in assumptions\<close>
wenzelm@15803
   224
wenzelm@15803
   225
lemma meta_mp:
wenzelm@58612
   226
  assumes "PROP P \<Longrightarrow> PROP Q" and "PROP P"
wenzelm@15803
   227
  shows "PROP Q"
wenzelm@58612
   228
    by (rule \<open>PROP P \<Longrightarrow> PROP Q\<close> [OF \<open>PROP P\<close>])
wenzelm@15803
   229
nipkow@23432
   230
lemmas meta_impE = meta_mp [elim_format]
nipkow@23432
   231
wenzelm@15803
   232
lemma meta_spec:
wenzelm@58612
   233
  assumes "\<And>x. PROP P x"
wenzelm@26958
   234
  shows "PROP P x"
wenzelm@58612
   235
    by (rule \<open>\<And>x. PROP P x\<close>)
wenzelm@15803
   236
wenzelm@15803
   237
lemmas meta_allE = meta_spec [elim_format]
wenzelm@15803
   238
wenzelm@26570
   239
lemma swap_params:
wenzelm@58612
   240
  "(\<And>x y. PROP P x y) \<equiv> (\<And>y x. PROP P x y)" ..
wenzelm@26570
   241
wenzelm@18466
   242
wenzelm@58611
   243
subsection \<open>Meta-level conjunction\<close>
wenzelm@18466
   244
wenzelm@18466
   245
lemma all_conjunction:
wenzelm@58612
   246
  "(\<And>x. PROP A x &&& PROP B x) \<equiv> ((\<And>x. PROP A x) &&& (\<And>x. PROP B x))"
wenzelm@18466
   247
proof
wenzelm@58612
   248
  assume conj: "\<And>x. PROP A x &&& PROP B x"
wenzelm@58612
   249
  show "(\<And>x. PROP A x) &&& (\<And>x. PROP B x)"
wenzelm@19121
   250
  proof -
wenzelm@18466
   251
    fix x
wenzelm@26958
   252
    from conj show "PROP A x" by (rule conjunctionD1)
wenzelm@26958
   253
    from conj show "PROP B x" by (rule conjunctionD2)
wenzelm@18466
   254
  qed
wenzelm@18466
   255
next
wenzelm@58612
   256
  assume conj: "(\<And>x. PROP A x) &&& (\<And>x. PROP B x)"
wenzelm@18466
   257
  fix x
wenzelm@28856
   258
  show "PROP A x &&& PROP B x"
wenzelm@19121
   259
  proof -
wenzelm@26958
   260
    show "PROP A x" by (rule conj [THEN conjunctionD1, rule_format])
wenzelm@26958
   261
    show "PROP B x" by (rule conj [THEN conjunctionD2, rule_format])
wenzelm@18466
   262
  qed
wenzelm@18466
   263
qed
wenzelm@18466
   264
wenzelm@19121
   265
lemma imp_conjunction:
wenzelm@58612
   266
  "(PROP A \<Longrightarrow> PROP B &&& PROP C) \<equiv> ((PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C))"
wenzelm@18836
   267
proof
wenzelm@58612
   268
  assume conj: "PROP A \<Longrightarrow> PROP B &&& PROP C"
wenzelm@58612
   269
  show "(PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C)"
wenzelm@19121
   270
  proof -
wenzelm@18466
   271
    assume "PROP A"
wenzelm@58611
   272
    from conj [OF \<open>PROP A\<close>] show "PROP B" by (rule conjunctionD1)
wenzelm@58611
   273
    from conj [OF \<open>PROP A\<close>] show "PROP C" by (rule conjunctionD2)
wenzelm@18466
   274
  qed
wenzelm@18466
   275
next
wenzelm@58612
   276
  assume conj: "(PROP A \<Longrightarrow> PROP B) &&& (PROP A \<Longrightarrow> PROP C)"
wenzelm@18466
   277
  assume "PROP A"
wenzelm@28856
   278
  show "PROP B &&& PROP C"
wenzelm@19121
   279
  proof -
wenzelm@58611
   280
    from \<open>PROP A\<close> show "PROP B" by (rule conj [THEN conjunctionD1])
wenzelm@58611
   281
    from \<open>PROP A\<close> show "PROP C" by (rule conj [THEN conjunctionD2])
wenzelm@18466
   282
  qed
wenzelm@18466
   283
qed
wenzelm@18466
   284
wenzelm@18466
   285
lemma conjunction_imp:
wenzelm@58612
   286
  "(PROP A &&& PROP B \<Longrightarrow> PROP C) \<equiv> (PROP A \<Longrightarrow> PROP B \<Longrightarrow> PROP C)"
wenzelm@18466
   287
proof
wenzelm@58612
   288
  assume r: "PROP A &&& PROP B \<Longrightarrow> PROP C"
wenzelm@22933
   289
  assume ab: "PROP A" "PROP B"
wenzelm@22933
   290
  show "PROP C"
wenzelm@22933
   291
  proof (rule r)
wenzelm@28856
   292
    from ab show "PROP A &&& PROP B" .
wenzelm@22933
   293
  qed
wenzelm@18466
   294
next
wenzelm@58612
   295
  assume r: "PROP A \<Longrightarrow> PROP B \<Longrightarrow> PROP C"
wenzelm@28856
   296
  assume conj: "PROP A &&& PROP B"
wenzelm@18466
   297
  show "PROP C"
wenzelm@18466
   298
  proof (rule r)
wenzelm@19121
   299
    from conj show "PROP A" by (rule conjunctionD1)
wenzelm@19121
   300
    from conj show "PROP B" by (rule conjunctionD2)
wenzelm@18466
   301
  qed
wenzelm@18466
   302
qed
wenzelm@18466
   303
wenzelm@48638
   304
end
wenzelm@48638
   305