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