src/Pure/pure_thy.ML
author wenzelm
Tue Sep 22 14:32:23 2015 +0200 (2015-09-22)
changeset 61246 077b88f9ec16
parent 61143 5f898411ce87
child 61255 15865e0c5598
permissions -rw-r--r--
HOL typedef with explicit dependency checks according to Ondrey Kuncar, 07-Jul-2015, 16-Jul-2015, 30-Jul-2015;
defs.ML: track dependencies also for type constructors;
typedef.ML: add type defined by typedef to dependencies, Abs and Rep now depend on the type;
Pure types and typedecls are final -- no dependencies;
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@61246
    69
  #> Theory.add_deps_global "fun" (Theory.DType ("fun", [typ "'a", typ "'b"])) []
wenzelm@61246
    70
  #> Theory.add_deps_global "prop" (Theory.DType ("prop", [])) []
wenzelm@61246
    71
  #> Theory.add_deps_global "itself" (Theory.DType ("itself", [typ "'a"])) []
wenzelm@61246
    72
  #> Theory.add_deps_global "dummy" (Theory.DType ("dummy", [])) []
wenzelm@52160
    73
  #> Sign.add_nonterminals_global
wenzelm@56436
    74
    (map (fn name => Binding.make (name, @{here}))
wenzelm@52160
    75
      (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
wenzelm@52160
    76
        "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
wenzelm@58421
    77
        "any", "prop'", "num_const", "float_const", "num_position",
wenzelm@58421
    78
        "float_position", "index", "struct", "tid_position",
wenzelm@55108
    79
        "tvar_position", "id_position", "longid_position", "var_position",
wenzelm@55108
    80
        "str_position", "string_position", "cartouche_position", "type_name",
wenzelm@55108
    81
        "class_name"]))
wenzelm@56240
    82
  #> Sign.add_syntax Syntax.mode_default (map (fn x => (x, typ "'a", NoSyn)) token_markers)
wenzelm@56240
    83
  #> Sign.add_syntax Syntax.mode_default
wenzelm@42294
    84
   [("",            typ "prop' => prop",               Delimfix "_"),
wenzelm@42294
    85
    ("",            typ "logic => any",                Delimfix "_"),
wenzelm@42294
    86
    ("",            typ "prop' => any",                Delimfix "_"),
wenzelm@42294
    87
    ("",            typ "logic => logic",              Delimfix "'(_')"),
wenzelm@42294
    88
    ("",            typ "prop' => prop'",              Delimfix "'(_')"),
wenzelm@42294
    89
    ("_constrain",  typ "logic => type => logic",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@42294
    90
    ("_constrain",  typ "prop' => type => prop'",      Mixfix ("_::_", [4, 0], 3)),
wenzelm@52211
    91
    ("_ignore_type", typ "'a",                         NoSyn),
wenzelm@49674
    92
    ("",            typ "tid_position => type",        Delimfix "_"),
wenzelm@49674
    93
    ("",            typ "tvar_position => type",       Delimfix "_"),
wenzelm@42263
    94
    ("",            typ "type_name => type",           Delimfix "_"),
wenzelm@42263
    95
    ("_type_name",  typ "id => type_name",             Delimfix "_"),
wenzelm@42263
    96
    ("_type_name",  typ "longid => type_name",         Delimfix "_"),
wenzelm@49685
    97
    ("_ofsort",     typ "tid_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@49685
    98
    ("_ofsort",     typ "tvar_position => sort => type", Mixfix ("_::_", [1000, 0], 1000)),
wenzelm@42297
    99
    ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], 1000)),
wenzelm@42263
   100
    ("",            typ "class_name => sort",          Delimfix "_"),
wenzelm@42263
   101
    ("_class_name", typ "id => class_name",            Delimfix "_"),
wenzelm@42263
   102
    ("_class_name", typ "longid => class_name",        Delimfix "_"),
wenzelm@42263
   103
    ("_topsort",    typ "sort",                        Delimfix "{}"),
wenzelm@42263
   104
    ("_sort",       typ "classes => sort",             Delimfix "{_}"),
wenzelm@42263
   105
    ("",            typ "class_name => classes",       Delimfix "_"),
wenzelm@42263
   106
    ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
wenzelm@42297
   107
    ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [1000, 0], 1000)),
wenzelm@42263
   108
    ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
wenzelm@42263
   109
    ("",            typ "type => types",               Delimfix "_"),
wenzelm@42263
   110
    ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
wenzelm@42263
   111
    ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@42263
   112
    ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@42263
   113
    ("",            typ "type => type",                Delimfix "'(_')"),
wenzelm@42263
   114
    ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
wenzelm@42263
   115
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@42263
   116
    ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
   117
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
   118
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
   119
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
   120
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
   121
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
   122
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
   123
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
   124
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
   125
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
   126
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
   127
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
   128
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
   129
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
   130
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
   131
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
   132
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@51612
   133
    ("",            typ "var_position => aprop",       Delimfix "_"),
wenzelm@26436
   134
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
   135
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
   136
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
   137
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
   138
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
   139
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   140
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
   141
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
   142
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
   143
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@51612
   144
    ("",            typ "var_position => logic",       Delimfix "_"),
wenzelm@26436
   145
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@42057
   146
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@46236
   147
    ("_position",   typ "num_token => num_position",   Delimfix "_"),
wenzelm@46236
   148
    ("_position",   typ "float_token => float_position", Delimfix "_"),
wenzelm@46236
   149
    ("_constify",   typ "num_position => num_const",   Delimfix "_"),
wenzelm@46236
   150
    ("_constify",   typ "float_position => float_const", Delimfix "_"),
wenzelm@26436
   151
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   152
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   153
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   154
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   155
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42295
   156
    ("_constrainAbs", typ "'a",                        NoSyn),
wenzelm@49674
   157
    ("_position_sort", typ "tid => tid_position",      Delimfix "_"),
wenzelm@49674
   158
    ("_position_sort", typ "tvar => tvar_position",    Delimfix "_"),
wenzelm@42410
   159
    ("_position",   typ "id => id_position",           Delimfix "_"),
wenzelm@42410
   160
    ("_position",   typ "longid => longid_position",   Delimfix "_"),
wenzelm@51612
   161
    ("_position",   typ "var => var_position",         Delimfix "_"),
wenzelm@46483
   162
    ("_position",   typ "str_token => str_position",   Delimfix "_"),
wenzelm@55108
   163
    ("_position",   typ "string_token => string_position", Delimfix "_"),
wenzelm@55033
   164
    ("_position",   typ "cartouche => cartouche_position", Delimfix "_"),
wenzelm@42048
   165
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@42296
   166
    ("_context_const", typ "id_position => logic",     Delimfix "CONST _"),
wenzelm@42296
   167
    ("_context_const", typ "id_position => aprop",     Delimfix "CONST _"),
wenzelm@42296
   168
    ("_context_const", typ "longid_position => logic", Delimfix "CONST _"),
wenzelm@42296
   169
    ("_context_const", typ "longid_position => aprop", Delimfix "CONST _"),
wenzelm@42296
   170
    ("_context_xconst", typ "id_position => logic",    Delimfix "XCONST _"),
wenzelm@42296
   171
    ("_context_xconst", typ "id_position => aprop",    Delimfix "XCONST _"),
wenzelm@42296
   172
    ("_context_xconst", typ "longid_position => logic", Delimfix "XCONST _"),
wenzelm@42296
   173
    ("_context_xconst", typ "longid_position => aprop", Delimfix "XCONST _"),
wenzelm@56245
   174
    (const "Pure.imp",  typ "prop => prop => prop",     Delimfix "op ==>"),
wenzelm@56241
   175
    (const "Pure.dummy_pattern", typ "aprop",          Delimfix "'_"),
wenzelm@28856
   176
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   177
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   178
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@56240
   179
  #> Sign.add_syntax Syntax.mode_default applC_syntax
wenzelm@56240
   180
  #> Sign.add_syntax (Symbol.xsymbolsN, true)
wenzelm@35429
   181
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   182
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@35429
   183
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@56245
   184
    (const "Pure.eq",     typ "'a => 'a => prop",       Infix ("\\<equiv>", 2)),
wenzelm@56245
   185
    (const "Pure.all_binder", typ "idts => prop => prop", Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@56245
   186
    (const "Pure.imp",    typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   187
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   188
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   189
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@56240
   190
  #> Sign.add_syntax ("", false)
wenzelm@56244
   191
   [(const "Pure.prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@56240
   192
  #> Sign.add_syntax ("HTML", false)
wenzelm@24243
   193
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@56239
   194
  #> Sign.add_consts
wenzelm@56436
   195
   [(qualify (Binding.make ("eq", @{here})), typ "'a => 'a => prop", Infix ("==", 2)),
wenzelm@56436
   196
    (qualify (Binding.make ("imp", @{here})), typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@56436
   197
    (qualify (Binding.make ("all", @{here})), typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@56436
   198
    (qualify (Binding.make ("prop", @{here})), typ "prop => prop", NoSyn),
wenzelm@56436
   199
    (qualify (Binding.make ("type", @{here})), typ "'a itself", NoSyn),
wenzelm@56436
   200
    (qualify (Binding.make ("dummy_pattern", @{here})), typ "'a", Delimfix "'_")]
wenzelm@61246
   201
  #> Theory.add_deps_global "Pure.eq" (Theory.DConst ("Pure.eq", typ "'a => 'a => prop")) []
wenzelm@61246
   202
  #> Theory.add_deps_global "Pure.imp" (Theory.DConst ("Pure.imp", typ "prop => prop => prop")) []
wenzelm@61246
   203
  #> Theory.add_deps_global "Pure.all" (Theory.DConst ("Pure.all", typ "('a => prop) => prop")) []
wenzelm@61246
   204
  #> Theory.add_deps_global "Pure.type" (Theory.DConst ("Pure.type", typ "'a itself")) []
wenzelm@61246
   205
  #> Theory.add_deps_global "Pure.dummy_pattern" (Theory.DConst ("Pure.dummy_pattern", typ "'a")) []
wenzelm@52143
   206
  #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
wenzelm@52143
   207
  #> Sign.parse_translation Syntax_Trans.pure_parse_translation
wenzelm@52143
   208
  #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
wenzelm@56239
   209
  #> Sign.add_consts
wenzelm@56436
   210
   [(qualify (Binding.make ("term", @{here})), typ "'a => prop", NoSyn),
wenzelm@56436
   211
    (qualify (Binding.make ("sort_constraint", @{here})), typ "'a itself => prop", NoSyn),
wenzelm@56436
   212
    (qualify (Binding.make ("conjunction", @{here})), typ "prop => prop => prop", NoSyn)]
wenzelm@26430
   213
  #> Sign.local_path
wenzelm@39557
   214
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
wenzelm@56436
   215
   [(Binding.make ("prop_def", @{here}),
wenzelm@56436
   216
      prop "(CONST Pure.prop :: prop => prop) (A::prop) == A::prop"),
wenzelm@56436
   217
    (Binding.make ("term_def", @{here}),
wenzelm@56436
   218
      prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
wenzelm@56436
   219
    (Binding.make ("sort_constraint_def", @{here}),
wenzelm@56243
   220
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST Pure.type :: 'a itself) ==\
wenzelm@56243
   221
      \ (CONST Pure.term :: 'a itself => prop) (CONST Pure.type :: 'a itself)"),
wenzelm@56436
   222
    (Binding.make ("conjunction_def", @{here}),
wenzelm@56436
   223
      prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@56436
   224
  #> Global_Theory.add_thmss [((Binding.make ("nothing", @{here}), []), [])] #> snd
wenzelm@42375
   225
  #> fold (fn (a, prop) =>
wenzelm@56436
   226
      snd o Thm.add_axiom_global (Binding.make (a, @{here}), prop)) Proofterm.equality_axms);
wenzelm@3987
   227
wenzelm@3987
   228
end;