src/Pure/pure_thy.ML
author blanchet
Mon May 19 23:43:53 2014 +0200 (2014-05-19)
changeset 57008 10f68b83b474
parent 56436 30ccec1e82fb
child 58421 37cbbd8eb460
permissions -rw-r--r--
use E 1.8's auto scheduler option
wenzelm@3987
     1
(*  Title:      Pure/pure_thy.ML
wenzelm@3987
     2
    Author:     Markus Wenzel, TU Muenchen
wenzelm@3987
     3
wenzelm@39557
     4
Pure theory syntax and further logical content.
wenzelm@3987
     5
*)
wenzelm@3987
     6
wenzelm@3987
     7
signature PURE_THY =
wenzelm@3987
     8
sig
wenzelm@26959
     9
  val old_appl_syntax: theory -> bool
wenzelm@26959
    10
  val old_appl_syntax_setup: theory -> theory
wenzelm@52160
    11
  val token_markers: string list
wenzelm@3987
    12
end;
wenzelm@3987
    13
wenzelm@39557
    14
structure Pure_Thy: PURE_THY =
wenzelm@3987
    15
struct
wenzelm@3987
    16
wenzelm@33384
    17
val typ = Simple_Syntax.read_typ;
wenzelm@33384
    18
val prop = Simple_Syntax.read_prop;
wenzelm@35429
    19
wenzelm@42290
    20
val tycon = Lexicon.mark_type;
wenzelm@42290
    21
val const = Lexicon.mark_const;
wenzelm@24243
    22
wenzelm@56234
    23
val qualify = Binding.qualify true Context.PureN;
wenzelm@56234
    24
wenzelm@26959
    25
wenzelm@26959
    26
(* application syntax variants *)
wenzelm@26959
    27
wenzelm@26959
    28
val appl_syntax =
wenzelm@26959
    29
 [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@26959
    30
  ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    31
wenzelm@26959
    32
val applC_syntax =
wenzelm@26959
    33
 [("",       typ "'a => cargs",                  Delimfix "_"),
wenzelm@26959
    34
  ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@26959
    35
  ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@26959
    36
  ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    37
wenzelm@37216
    38
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    39
(
wenzelm@26959
    40
  type T = bool;
wenzelm@26959
    41
  val empty = false;
wenzelm@26959
    42
  val extend = I;
wenzelm@33522
    43
  fun merge (b1, b2) : T =
wenzelm@26959
    44
    if b1 = b2 then b1
wenzelm@26959
    45
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    46
);
wenzelm@26959
    47
wenzelm@37216
    48
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    49
wenzelm@26959
    50
val old_appl_syntax_setup =
wenzelm@37216
    51
  Old_Appl_Syntax.put true #>
wenzelm@56240
    52
  Sign.del_syntax Syntax.mode_default applC_syntax #>
wenzelm@56240
    53
  Sign.add_syntax Syntax.mode_default appl_syntax;
wenzelm@26959
    54
wenzelm@26959
    55
wenzelm@26959
    56
(* main content *)
wenzelm@26959
    57
wenzelm@52160
    58
val token_markers =
wenzelm@52160
    59
  ["_tfree", "_tvar", "_free", "_bound", "_loose", "_var", "_numeral", "_inner_string"];
wenzelm@52160
    60
wenzelm@53171
    61
val _ = Theory.setup
haftmann@33365
    62
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    63
   Old_Appl_Syntax.put false #>
wenzelm@42375
    64
   Sign.add_types_global
wenzelm@56436
    65
   [(Binding.make ("fun", @{here}), 2, NoSyn),
wenzelm@56436
    66
    (Binding.make ("prop", @{here}), 0, NoSyn),
wenzelm@56436
    67
    (Binding.make ("itself", @{here}), 1, NoSyn),
wenzelm@56436
    68
    (Binding.make ("dummy", @{here}), 0, NoSyn)]
wenzelm@52160
    69
  #> Sign.add_nonterminals_global
wenzelm@56436
    70
    (map (fn name => Binding.make (name, @{here}))
wenzelm@52160
    71
      (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
wenzelm@52160
    72
        "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
wenzelm@52160
    73
        "any", "prop'", "num_const", "float_const", "xnum_const", "num_position",
wenzelm@52160
    74
        "float_position", "xnum_position", "index", "struct", "tid_position",
wenzelm@55108
    75
        "tvar_position", "id_position", "longid_position", "var_position",
wenzelm@55108
    76
        "str_position", "string_position", "cartouche_position", "type_name",
wenzelm@55108
    77
        "class_name"]))
wenzelm@56240
    78
  #> Sign.add_syntax Syntax.mode_default (map (fn x => (x, typ "'a", NoSyn)) token_markers)
wenzelm@56240
    79
  #> Sign.add_syntax Syntax.mode_default
wenzelm@42294
    80
   [("",            typ "prop' => prop",               Delimfix "_"),
wenzelm@42294
    81
    ("",            typ "logic => any",                Delimfix "_"),
wenzelm@42294
    82
    ("",            typ "prop' => any",                Delimfix "_"),
wenzelm@42294
    83
    ("",            typ "logic => logic",              Delimfix "'(_')"),
wenzelm@42294
    84
    ("",            typ "prop' => prop'",              Delimfix "'(_')"),
wenzelm@42294
    85
    ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@42294
    86
    ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@52211
    87
    ("_ignore_type", typ "'a",                         NoSyn),
wenzelm@49674
    88
    ("",            typ "tid_position => type",        Delimfix "_"),
wenzelm@49674
    89
    ("",            typ "tvar_position => type",       Delimfix "_"),
wenzelm@42263
    90
    ("",            typ "type_name => type",           Delimfix "_"),
wenzelm@42263
    91
    ("_type_name",  typ "id => type_name",             Delimfix "_"),
wenzelm@42263
    92
    ("_type_name",  typ "longid => type_name",         Delimfix "_"),
wenzelm@49685
    93
    ("_ofsort",     typ "tid_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@49685
    94
    ("_ofsort",     typ "tvar_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@42297
    95
    ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
wenzelm@42263
    96
    ("",            typ "class_name => sort",          Delimfix "_"),
wenzelm@42263
    97
    ("_class_name", typ "id => class_name",            Delimfix "_"),
wenzelm@42263
    98
    ("_class_name", typ "longid => class_name",        Delimfix "_"),
wenzelm@42263
    99
    ("_topsort",    typ "sort",                        Delimfix "{}"),
wenzelm@42263
   100
    ("_sort",       typ "classes => sort",             Delimfix "{_}"),
wenzelm@42263
   101
    ("",            typ "class_name => classes",       Delimfix "_"),
wenzelm@42263
   102
    ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
wenzelm@42297
   103
    ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
wenzelm@42263
   104
    ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
wenzelm@42263
   105
    ("",            typ "type => types",               Delimfix "_"),
wenzelm@42263
   106
    ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
wenzelm@42263
   107
    ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@42263
   108
    ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@42263
   109
    ("",            typ "type => type",                Delimfix "'(_')"),
wenzelm@42263
   110
    ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
wenzelm@42263
   111
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@42263
   112
    ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
   113
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
   114
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
   115
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
   116
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
   117
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
   118
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
   119
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
   120
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
   121
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
   122
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
   123
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
   124
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
   125
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
   126
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
   127
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
   128
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@51612
   129
    ("",            typ "var_position => aprop",       Delimfix "_"),
wenzelm@26436
   130
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
   131
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
   132
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
   133
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
   134
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
   135
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   136
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
   137
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
   138
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
   139
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@51612
   140
    ("",            typ "var_position => logic",       Delimfix "_"),
wenzelm@26436
   141
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@42057
   142
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@46236
   143
    ("_position",   typ "num_token => num_position",   Delimfix "_"),
wenzelm@46236
   144
    ("_position",   typ "float_token => float_position", Delimfix "_"),
wenzelm@46236
   145
    ("_position",   typ "xnum_token => xnum_position", Delimfix "_"),
wenzelm@46236
   146
    ("_constify",   typ "num_position => num_const",   Delimfix "_"),
wenzelm@46236
   147
    ("_constify",   typ "float_position => float_const", Delimfix "_"),
wenzelm@46236
   148
    ("_constify",   typ "xnum_position => xnum_const", Delimfix "_"),
wenzelm@26436
   149
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   150
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   151
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   152
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   153
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42295
   154
    ("_constrainAbs", typ "'a",                        NoSyn),
wenzelm@49674
   155
    ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
wenzelm@49674
   156
    ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
wenzelm@42410
   157
    ("_position",   typ "id => id_position",           Delimfix "_"),
wenzelm@42410
   158
    ("_position",   typ "longid => longid_position",   Delimfix "_"),
wenzelm@51612
   159
    ("_position",   typ "var => var_position",         Delimfix "_"),
wenzelm@46483
   160
    ("_position",   typ "str_token => str_position",   Delimfix "_"),
wenzelm@55108
   161
    ("_position",   typ "string_token => string_position", Delimfix "_"),
wenzelm@55033
   162
    ("_position",   typ "cartouche => cartouche_position", Delimfix "_"),
wenzelm@42048
   163
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@42296
   164
    ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
wenzelm@42296
   165
    ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
wenzelm@42296
   166
    ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
wenzelm@42296
   167
    ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
wenzelm@42296
   168
    ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
wenzelm@42296
   169
    ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
wenzelm@42296
   170
    ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
wenzelm@42296
   171
    ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
wenzelm@56245
   172
    (const "Pure.imp",  typ "prop => prop => prop",     Delimfix "op ==>"),
wenzelm@56241
   173
    (const "Pure.dummy_pattern", typ "aprop",          Delimfix "'_"),
wenzelm@28856
   174
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   175
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   176
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@56240
   177
  #> Sign.add_syntax Syntax.mode_default applC_syntax
wenzelm@56240
   178
  #> Sign.add_syntax (Symbol.xsymbolsN, true)
wenzelm@35429
   179
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   180
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@49685
   181
    ("_ofsort",           typ "tid_position => sort => type", Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
wenzelm@35429
   182
    ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42293
   183
    ("_constrain",        typ "prop' => type => prop'", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42048
   184
    ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
wenzelm@35429
   185
    ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
wenzelm@35429
   186
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@56245
   187
    (const "Pure.eq",     typ "'a => 'a => prop",       Infix ("\\<equiv>", 2)),
wenzelm@56245
   188
    (const "Pure.all_binder", typ "idts => prop => prop", Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@56245
   189
    (const "Pure.imp",    typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   190
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   191
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   192
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@56240
   193
  #> Sign.add_syntax ("", false)
wenzelm@56244
   194
   [(const "Pure.prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@56240
   195
  #> Sign.add_syntax ("HTML", false)
wenzelm@24243
   196
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@56239
   197
  #> Sign.add_consts
wenzelm@56436
   198
   [(qualify (Binding.make ("eq", @{here})), typ "'a => 'a => prop", Infix ("==", 2)),
wenzelm@56436
   199
    (qualify (Binding.make ("imp", @{here})), typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@56436
   200
    (qualify (Binding.make ("all", @{here})), typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@56436
   201
    (qualify (Binding.make ("prop", @{here})), typ "prop => prop", NoSyn),
wenzelm@56436
   202
    (qualify (Binding.make ("type", @{here})), typ "'a itself", NoSyn),
wenzelm@56436
   203
    (qualify (Binding.make ("dummy_pattern", @{here})), typ "'a", Delimfix "'_")]
wenzelm@56245
   204
  #> Theory.add_deps_global "Pure.eq" ("Pure.eq", typ "'a => 'a => prop") []
wenzelm@56245
   205
  #> Theory.add_deps_global "Pure.imp" ("Pure.imp", typ "prop => prop => prop") []
wenzelm@56245
   206
  #> Theory.add_deps_global "Pure.all" ("Pure.all", typ "('a => prop) => prop") []
wenzelm@56243
   207
  #> Theory.add_deps_global "Pure.type" ("Pure.type", typ "'a itself") []
wenzelm@56241
   208
  #> Theory.add_deps_global "Pure.dummy_pattern" ("Pure.dummy_pattern", typ "'a") []
wenzelm@52143
   209
  #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
wenzelm@52143
   210
  #> Sign.parse_translation Syntax_Trans.pure_parse_translation
wenzelm@52143
   211
  #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
wenzelm@56239
   212
  #> Sign.add_consts
wenzelm@56436
   213
   [(qualify (Binding.make ("term", @{here})), typ "'a => prop", NoSyn),
wenzelm@56436
   214
    (qualify (Binding.make ("sort_constraint", @{here})), typ "'a itself => prop", NoSyn),
wenzelm@56436
   215
    (qualify (Binding.make ("conjunction", @{here})), typ "prop => prop => prop", NoSyn)]
wenzelm@26430
   216
  #> Sign.local_path
wenzelm@39557
   217
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
wenzelm@56436
   218
   [(Binding.make ("prop_def", @{here}),
wenzelm@56436
   219
      prop "(CONST Pure.prop :: prop => prop) (A::prop) == A::prop"),
wenzelm@56436
   220
    (Binding.make ("term_def", @{here}),
wenzelm@56436
   221
      prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
wenzelm@56436
   222
    (Binding.make ("sort_constraint_def", @{here}),
wenzelm@56243
   223
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST Pure.type :: 'a itself) ==\
wenzelm@56243
   224
      \ (CONST Pure.term :: 'a itself => prop) (CONST Pure.type :: 'a itself)"),
wenzelm@56436
   225
    (Binding.make ("conjunction_def", @{here}),
wenzelm@56436
   226
      prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@56436
   227
  #> Global_Theory.add_thmss [((Binding.make ("nothing", @{here}), []), [])] #> snd
wenzelm@42375
   228
  #> fold (fn (a, prop) =>
wenzelm@56436
   229
      snd o Thm.add_axiom_global (Binding.make (a, @{here}), prop)) Proofterm.equality_axms);
wenzelm@3987
   230
wenzelm@3987
   231
end;