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