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