src/Pure/pure_thy.ML
author wenzelm
Tue Sep 26 20:54:40 2017 +0200 (21 months ago)
changeset 66695 91500c024c7f
parent 64556 851ae0e7b09c
child 67718 17874d43d3b3
permissions -rw-r--r--
tuned;
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@62752
    25
fun mixfix (sy, ps, p) = Mixfix (Input.string sy, ps, p, Position.no_range);
wenzelm@62752
    26
fun infix_ (sy, p) = Infix (Input.string sy, p, Position.no_range);
wenzelm@62752
    27
fun infixr_ (sy, p) = Infixr (Input.string sy, p, Position.no_range);
wenzelm@62752
    28
fun binder (sy, p, q) = Binder (Input.string sy, p, q, Position.no_range);
wenzelm@62752
    29
wenzelm@26959
    30
wenzelm@26959
    31
(* application syntax variants *)
wenzelm@26959
    32
wenzelm@26959
    33
val appl_syntax =
wenzelm@62752
    34
 [("_appl", typ "('b => 'a) => args => logic", mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@62752
    35
  ("_appl", typ "('b => 'a) => args => aprop", mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    36
wenzelm@26959
    37
val applC_syntax =
wenzelm@62761
    38
 [("",       typ "'a => cargs",                  Mixfix.mixfix "_"),
wenzelm@62752
    39
  ("_cargs", typ "'a => cargs => cargs",         mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@62752
    40
  ("_applC", typ "('b => 'a) => cargs => logic", mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@62752
    41
  ("_applC", typ "('b => 'a) => cargs => aprop", mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    42
wenzelm@37216
    43
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    44
(
wenzelm@26959
    45
  type T = bool;
wenzelm@26959
    46
  val empty = false;
wenzelm@26959
    47
  val extend = I;
wenzelm@33522
    48
  fun merge (b1, b2) : T =
wenzelm@26959
    49
    if b1 = b2 then b1
wenzelm@26959
    50
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    51
);
wenzelm@26959
    52
wenzelm@37216
    53
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    54
wenzelm@26959
    55
val old_appl_syntax_setup =
wenzelm@37216
    56
  Old_Appl_Syntax.put true #>
wenzelm@56240
    57
  Sign.del_syntax Syntax.mode_default applC_syntax #>
wenzelm@56240
    58
  Sign.add_syntax Syntax.mode_default appl_syntax;
wenzelm@26959
    59
wenzelm@26959
    60
wenzelm@26959
    61
(* main content *)
wenzelm@26959
    62
wenzelm@52160
    63
val token_markers =
wenzelm@52160
    64
  ["_tfree", "_tvar", "_free", "_bound", "_loose", "_var", "_numeral", "_inner_string"];
wenzelm@52160
    65
wenzelm@53171
    66
val _ = Theory.setup
haftmann@33365
    67
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    68
   Old_Appl_Syntax.put false #>
wenzelm@42375
    69
   Sign.add_types_global
wenzelm@64556
    70
   [(Binding.make ("fun", \<^here>), 2, NoSyn),
wenzelm@64556
    71
    (Binding.make ("prop", \<^here>), 0, NoSyn),
wenzelm@64556
    72
    (Binding.make ("itself", \<^here>), 1, NoSyn),
wenzelm@64556
    73
    (Binding.make ("dummy", \<^here>), 0, NoSyn)]
wenzelm@61255
    74
  #> Theory.add_deps_global "fun" ((Defs.Type, "fun"), [typ "'a", typ "'b"]) []
wenzelm@61255
    75
  #> Theory.add_deps_global "prop" ((Defs.Type, "prop"), []) []
wenzelm@61255
    76
  #> Theory.add_deps_global "itself" ((Defs.Type, "itself"), [typ "'a"]) []
wenzelm@61255
    77
  #> Theory.add_deps_global "dummy" ((Defs.Type, "dummy"), []) []
wenzelm@52160
    78
  #> Sign.add_nonterminals_global
wenzelm@64556
    79
    (map (fn name => Binding.make (name, \<^here>))
wenzelm@52160
    80
      (Lexicon.terminals @ ["logic", "type", "types", "sort", "classes",
wenzelm@52160
    81
        "args", "cargs", "pttrn", "pttrns", "idt", "idts", "aprop", "asms",
wenzelm@58421
    82
        "any", "prop'", "num_const", "float_const", "num_position",
wenzelm@58421
    83
        "float_position", "index", "struct", "tid_position",
wenzelm@55108
    84
        "tvar_position", "id_position", "longid_position", "var_position",
wenzelm@55108
    85
        "str_position", "string_position", "cartouche_position", "type_name",
wenzelm@55108
    86
        "class_name"]))
wenzelm@56240
    87
  #> Sign.add_syntax Syntax.mode_default (map (fn x => (x, typ "'a", NoSyn)) token_markers)
wenzelm@56240
    88
  #> Sign.add_syntax Syntax.mode_default
wenzelm@62761
    89
   [("",            typ "prop' => prop",               Mixfix.mixfix "_"),
wenzelm@62761
    90
    ("",            typ "logic => any",                Mixfix.mixfix "_"),
wenzelm@62761
    91
    ("",            typ "prop' => any",                Mixfix.mixfix "_"),
wenzelm@62761
    92
    ("",            typ "logic => logic",              Mixfix.mixfix "'(_')"),
wenzelm@62761
    93
    ("",            typ "prop' => prop'",              Mixfix.mixfix "'(_')"),
wenzelm@62752
    94
    ("_constrain",  typ "logic => type => logic",      mixfix ("_::_", [4, 0], 3)),
wenzelm@62752
    95
    ("_constrain",  typ "prop' => type => prop'",      mixfix ("_::_", [4, 0], 3)),
wenzelm@52211
    96
    ("_ignore_type", typ "'a",                         NoSyn),
wenzelm@62761
    97
    ("",            typ "tid_position => type",        Mixfix.mixfix "_"),
wenzelm@62761
    98
    ("",            typ "tvar_position => type",       Mixfix.mixfix "_"),
wenzelm@62761
    99
    ("",            typ "type_name => type",           Mixfix.mixfix "_"),
wenzelm@62761
   100
    ("_type_name",  typ "id => type_name",             Mixfix.mixfix "_"),
wenzelm@62761
   101
    ("_type_name",  typ "longid => type_name",         Mixfix.mixfix "_"),
wenzelm@62752
   102
    ("_ofsort",     typ "tid_position => sort => type", mixfix ("_::_", [1000, 0], 1000)),
wenzelm@62752
   103
    ("_ofsort",     typ "tvar_position => sort => type", mixfix ("_::_", [1000, 0], 1000)),
wenzelm@62752
   104
    ("_dummy_ofsort", typ "sort => type",              mixfix ("'_()::_", [0], 1000)),
wenzelm@62761
   105
    ("",            typ "class_name => sort",          Mixfix.mixfix "_"),
wenzelm@62761
   106
    ("_class_name", typ "id => class_name",            Mixfix.mixfix "_"),
wenzelm@62761
   107
    ("_class_name", typ "longid => class_name",        Mixfix.mixfix "_"),
wenzelm@62761
   108
    ("_topsort",    typ "sort",                        Mixfix.mixfix "{}"),
wenzelm@62761
   109
    ("_sort",       typ "classes => sort",             Mixfix.mixfix "{_}"),
wenzelm@62761
   110
    ("",            typ "class_name => classes",       Mixfix.mixfix "_"),
wenzelm@62761
   111
    ("_classes",    typ "class_name => classes => classes", Mixfix.mixfix "_,_"),
wenzelm@62752
   112
    ("_tapp",       typ "type => type_name => type",   mixfix ("_ _", [1000, 0], 1000)),
wenzelm@62761
   113
    ("_tappl",      typ "type => types => type_name => type", Mixfix.mixfix "((1'(_,/ _')) _)"),
wenzelm@62761
   114
    ("",            typ "type => types",               Mixfix.mixfix "_"),
wenzelm@62761
   115
    ("_types",      typ "type => types => types",      Mixfix.mixfix "_,/ _"),
wenzelm@62752
   116
    ("\<^type>fun", typ "type => type => type",        mixfix ("(_/ \<Rightarrow> _)", [1, 0], 0)),
wenzelm@62752
   117
    ("_bracket",    typ "types => type => type",       mixfix ("([_]/ \<Rightarrow> _)", [0, 0], 0)),
wenzelm@62761
   118
    ("",            typ "type => type",                Mixfix.mixfix "'(_')"),
wenzelm@62761
   119
    ("\<^type>dummy", typ "type",                      Mixfix.mixfix "'_"),
wenzelm@42263
   120
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@62752
   121
    ("_lambda",     typ "pttrns => 'a => logic",       mixfix ("(3\<lambda>_./ _)", [0, 3], 3)),
wenzelm@26436
   122
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@62761
   123
    ("",            typ "'a => args",                  Mixfix.mixfix "_"),
wenzelm@62761
   124
    ("_args",       typ "'a => args => args",          Mixfix.mixfix "_,/ _"),
wenzelm@62761
   125
    ("",            typ "id_position => idt",          Mixfix.mixfix "_"),
wenzelm@62761
   126
    ("_idtdummy",   typ "idt",                         Mixfix.mixfix "'_"),
wenzelm@62752
   127
    ("_idtyp",      typ "id_position => type => idt",  mixfix ("_::_", [], 0)),
wenzelm@62752
   128
    ("_idtypdummy", typ "type => idt",                 mixfix ("'_()::_", [], 0)),
wenzelm@62761
   129
    ("",            typ "idt => idt",                  Mixfix.mixfix "'(_')"),
wenzelm@62761
   130
    ("",            typ "idt => idts",                 Mixfix.mixfix "_"),
wenzelm@62752
   131
    ("_idts",       typ "idt => idts => idts",         mixfix ("_/ _", [1, 0], 0)),
wenzelm@62761
   132
    ("",            typ "idt => pttrn",                Mixfix.mixfix "_"),
wenzelm@62761
   133
    ("",            typ "pttrn => pttrns",             Mixfix.mixfix "_"),
wenzelm@62752
   134
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   mixfix ("_/ _", [1, 0], 0)),
wenzelm@62761
   135
    ("",            typ "aprop => aprop",              Mixfix.mixfix "'(_')"),
wenzelm@62761
   136
    ("",            typ "id_position => aprop",        Mixfix.mixfix "_"),
wenzelm@62761
   137
    ("",            typ "longid_position => aprop",    Mixfix.mixfix "_"),
wenzelm@62761
   138
    ("",            typ "var_position => aprop",       Mixfix.mixfix "_"),
wenzelm@62761
   139
    ("_DDDOT",      typ "aprop",                       Mixfix.mixfix "\<dots>"),
wenzelm@62761
   140
    ("_aprop",      typ "aprop => prop",               Mixfix.mixfix "PROP _"),
wenzelm@62761
   141
    ("_asm",        typ "prop => asms",                Mixfix.mixfix "_"),
wenzelm@62761
   142
    ("_asms",       typ "prop => asms => asms",        Mixfix.mixfix "_;/ _"),
wenzelm@62752
   143
    ("_bigimpl",    typ "asms => prop => prop",        mixfix ("((1\<lbrakk>_\<rbrakk>)/ \<Longrightarrow> _)", [0, 1], 1)),
wenzelm@62761
   144
    ("_ofclass",    typ "type => logic => prop",       Mixfix.mixfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   145
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@62761
   146
    ("_TYPE",       typ "type => logic",               Mixfix.mixfix "(1TYPE/(1'(_')))"),
wenzelm@62761
   147
    ("",            typ "id_position => logic",        Mixfix.mixfix "_"),
wenzelm@62761
   148
    ("",            typ "longid_position => logic",    Mixfix.mixfix "_"),
wenzelm@62761
   149
    ("",            typ "var_position => logic",       Mixfix.mixfix "_"),
wenzelm@62761
   150
    ("_DDDOT",      typ "logic",                       Mixfix.mixfix "\<dots>"),
wenzelm@42057
   151
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@62761
   152
    ("_position",   typ "num_token => num_position",   Mixfix.mixfix "_"),
wenzelm@62761
   153
    ("_position",   typ "float_token => float_position", Mixfix.mixfix "_"),
wenzelm@62761
   154
    ("_constify",   typ "num_position => num_const",   Mixfix.mixfix "_"),
wenzelm@62761
   155
    ("_constify",   typ "float_position => float_const", Mixfix.mixfix "_"),
wenzelm@62789
   156
    ("_index",      typ "logic => index",              Mixfix.mixfix "(\<open>unbreakable\<close>\<^bsub>_\<^esub>)"),
wenzelm@62761
   157
    ("_indexdefault", typ "index",                     Mixfix.mixfix ""),
wenzelm@62761
   158
    ("_indexvar",   typ "index",                       Mixfix.mixfix "'\<index>"),
wenzelm@62107
   159
    ("_struct",     typ "index => logic",              NoSyn),
wenzelm@35145
   160
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42295
   161
    ("_constrainAbs", typ "'a",                        NoSyn),
wenzelm@62761
   162
    ("_position_sort", typ "tid => tid_position",      Mixfix.mixfix "_"),
wenzelm@62761
   163
    ("_position_sort", typ "tvar => tvar_position",    Mixfix.mixfix "_"),
wenzelm@62761
   164
    ("_position",   typ "id => id_position",           Mixfix.mixfix "_"),
wenzelm@62761
   165
    ("_position",   typ "longid => longid_position",   Mixfix.mixfix "_"),
wenzelm@62761
   166
    ("_position",   typ "var => var_position",         Mixfix.mixfix "_"),
wenzelm@62761
   167
    ("_position",   typ "str_token => str_position",   Mixfix.mixfix "_"),
wenzelm@62761
   168
    ("_position",   typ "string_token => string_position", Mixfix.mixfix "_"),
wenzelm@62761
   169
    ("_position",   typ "cartouche => cartouche_position", Mixfix.mixfix "_"),
wenzelm@42048
   170
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@62761
   171
    ("_context_const", typ "id_position => logic",     Mixfix.mixfix "CONST _"),
wenzelm@62761
   172
    ("_context_const", typ "id_position => aprop",     Mixfix.mixfix "CONST _"),
wenzelm@62761
   173
    ("_context_const", typ "longid_position => logic", Mixfix.mixfix "CONST _"),
wenzelm@62761
   174
    ("_context_const", typ "longid_position => aprop", Mixfix.mixfix "CONST _"),
wenzelm@62761
   175
    ("_context_xconst", typ "id_position => logic",    Mixfix.mixfix "XCONST _"),
wenzelm@62761
   176
    ("_context_xconst", typ "id_position => aprop",    Mixfix.mixfix "XCONST _"),
wenzelm@62761
   177
    ("_context_xconst", typ "longid_position => logic", Mixfix.mixfix "XCONST _"),
wenzelm@62761
   178
    ("_context_xconst", typ "longid_position => aprop", Mixfix.mixfix "XCONST _"),
wenzelm@62761
   179
    (const "Pure.dummy_pattern", typ "aprop",          Mixfix.mixfix "'_"),
wenzelm@62761
   180
    ("_sort_constraint", typ "type => prop",           Mixfix.mixfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@62761
   181
    (const "Pure.term", typ "logic => prop",           Mixfix.mixfix "TERM _"),
wenzelm@62752
   182
    (const "Pure.conjunction", typ "prop => prop => prop", infixr_ ("&&&", 2))]
wenzelm@56240
   183
  #> Sign.add_syntax Syntax.mode_default applC_syntax
wenzelm@61957
   184
  #> Sign.add_syntax (Print_Mode.ASCII, true)
wenzelm@62752
   185
   [(tycon "fun",         typ "type => type => type",   mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@62752
   186
    ("_bracket",          typ "types => type => type",  mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@62752
   187
    ("_lambda",           typ "pttrns => 'a => logic",  mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@62752
   188
    (const "Pure.eq",     typ "'a => 'a => prop",       infix_ ("==", 2)),
wenzelm@62752
   189
    (const "Pure.all_binder", typ "idts => prop => prop", mixfix ("(3!!_./ _)", [0, 0], 0)),
wenzelm@62752
   190
    (const "Pure.imp",    typ "prop => prop => prop",   infixr_ ("==>", 1)),
wenzelm@62761
   191
    ("_DDDOT",            typ "aprop",                  Mixfix.mixfix "..."),
wenzelm@62752
   192
    ("_bigimpl",          typ "asms => prop => prop",   mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@62761
   193
    ("_DDDOT",            typ "logic",                  Mixfix.mixfix "...")]
wenzelm@56240
   194
  #> Sign.add_syntax ("", false)
wenzelm@62752
   195
   [(const "Pure.prop", typ "prop => prop", mixfix ("_", [0], 0))]
wenzelm@56239
   196
  #> Sign.add_consts
wenzelm@64556
   197
   [(qualify (Binding.make ("eq", \<^here>)), typ "'a => 'a => prop", infix_ ("\<equiv>", 2)),
wenzelm@64556
   198
    (qualify (Binding.make ("imp", \<^here>)), typ "prop => prop => prop", infixr_ ("\<Longrightarrow>", 1)),
wenzelm@64556
   199
    (qualify (Binding.make ("all", \<^here>)), typ "('a => prop) => prop", binder ("\<And>", 0, 0)),
wenzelm@64556
   200
    (qualify (Binding.make ("prop", \<^here>)), typ "prop => prop", NoSyn),
wenzelm@64556
   201
    (qualify (Binding.make ("type", \<^here>)), typ "'a itself", NoSyn),
wenzelm@64556
   202
    (qualify (Binding.make ("dummy_pattern", \<^here>)), typ "'a", Mixfix.mixfix "'_")]
wenzelm@61256
   203
  #> Theory.add_deps_global "Pure.eq" ((Defs.Const, "Pure.eq"), [typ "'a"]) []
wenzelm@61256
   204
  #> Theory.add_deps_global "Pure.imp" ((Defs.Const, "Pure.imp"), []) []
wenzelm@61256
   205
  #> Theory.add_deps_global "Pure.all" ((Defs.Const, "Pure.all"), [typ "'a"]) []
wenzelm@61256
   206
  #> Theory.add_deps_global "Pure.type" ((Defs.Const, "Pure.type"), [typ "'a"]) []
wenzelm@61256
   207
  #> Theory.add_deps_global "Pure.dummy_pattern" ((Defs.Const, "Pure.dummy_pattern"), [typ "'a"]) []
wenzelm@52143
   208
  #> Sign.parse_ast_translation Syntax_Trans.pure_parse_ast_translation
wenzelm@52143
   209
  #> Sign.parse_translation Syntax_Trans.pure_parse_translation
wenzelm@52143
   210
  #> Sign.print_ast_translation Syntax_Trans.pure_print_ast_translation
wenzelm@56239
   211
  #> Sign.add_consts
wenzelm@64556
   212
   [(qualify (Binding.make ("term", \<^here>)), typ "'a => prop", NoSyn),
wenzelm@64556
   213
    (qualify (Binding.make ("sort_constraint", \<^here>)), typ "'a itself => prop", NoSyn),
wenzelm@64556
   214
    (qualify (Binding.make ("conjunction", \<^here>)), typ "prop => prop => prop", NoSyn)]
wenzelm@26430
   215
  #> Sign.local_path
wenzelm@39557
   216
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
wenzelm@64556
   217
   [(Binding.make ("prop_def", \<^here>),
wenzelm@56436
   218
      prop "(CONST Pure.prop :: prop => prop) (A::prop) == A::prop"),
wenzelm@64556
   219
    (Binding.make ("term_def", \<^here>),
wenzelm@56436
   220
      prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
wenzelm@64556
   221
    (Binding.make ("sort_constraint_def", \<^here>),
wenzelm@56243
   222
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST Pure.type :: 'a itself) ==\
wenzelm@56243
   223
      \ (CONST Pure.term :: 'a itself => prop) (CONST Pure.type :: 'a itself)"),
wenzelm@64556
   224
    (Binding.make ("conjunction_def", \<^here>),
wenzelm@56436
   225
      prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@42375
   226
  #> fold (fn (a, prop) =>
wenzelm@64556
   227
      snd o Thm.add_axiom_global (Binding.make (a, \<^here>), prop)) Proofterm.equality_axms);
wenzelm@3987
   228
wenzelm@3987
   229
end;