src/Pure/pure_thy.ML
author wenzelm
Fri Apr 08 17:45:37 2011 +0200 (2011-04-08)
changeset 42293 6cca0343ea48
parent 42290 b1f544c84040
child 42294 0f4372a2d2e4
permissions -rw-r--r--
renamed sprop "prop#" to "prop'" -- proper identifier;
eliminated spurious symbolic string bindings (logic, any etc.);
hardwired special "prop" vs. "prop'" conversion;
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@3987
    11
end;
wenzelm@3987
    12
wenzelm@39557
    13
structure Pure_Thy: PURE_THY =
wenzelm@3987
    14
struct
wenzelm@3987
    15
wenzelm@33384
    16
val typ = Simple_Syntax.read_typ;
wenzelm@33384
    17
val prop = Simple_Syntax.read_prop;
wenzelm@35429
    18
wenzelm@42290
    19
val tycon = Lexicon.mark_type;
wenzelm@42290
    20
val const = Lexicon.mark_const;
wenzelm@24243
    21
wenzelm@26959
    22
wenzelm@26959
    23
(* application syntax variants *)
wenzelm@26959
    24
wenzelm@26959
    25
val appl_syntax =
wenzelm@26959
    26
 [("_appl", typ "('b => 'a) => args => logic", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
wenzelm@26959
    27
  ("_appl", typ "('b => 'a) => args => aprop", Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
wenzelm@26959
    28
wenzelm@26959
    29
val applC_syntax =
wenzelm@26959
    30
 [("",       typ "'a => cargs",                  Delimfix "_"),
wenzelm@26959
    31
  ("_cargs", typ "'a => cargs => cargs",         Mixfix ("_/ _", [1000, 1000], 1000)),
wenzelm@26959
    32
  ("_applC", typ "('b => 'a) => cargs => logic", Mixfix ("(1_/ _)", [1000, 1000], 999)),
wenzelm@26959
    33
  ("_applC", typ "('b => 'a) => cargs => aprop", Mixfix ("(1_/ _)", [1000, 1000], 999))];
wenzelm@26959
    34
wenzelm@37216
    35
structure Old_Appl_Syntax = Theory_Data
wenzelm@26959
    36
(
wenzelm@26959
    37
  type T = bool;
wenzelm@26959
    38
  val empty = false;
wenzelm@26959
    39
  val extend = I;
wenzelm@33522
    40
  fun merge (b1, b2) : T =
wenzelm@26959
    41
    if b1 = b2 then b1
wenzelm@26959
    42
    else error "Cannot merge theories with different application syntax";
wenzelm@26959
    43
);
wenzelm@26959
    44
wenzelm@37216
    45
val old_appl_syntax = Old_Appl_Syntax.get;
wenzelm@26959
    46
wenzelm@26959
    47
val old_appl_syntax_setup =
wenzelm@37216
    48
  Old_Appl_Syntax.put true #>
wenzelm@26959
    49
  Sign.del_modesyntax_i Syntax.mode_default applC_syntax #>
wenzelm@26959
    50
  Sign.add_syntax_i appl_syntax;
wenzelm@26959
    51
wenzelm@26959
    52
wenzelm@26959
    53
(* main content *)
wenzelm@26959
    54
wenzelm@26463
    55
val _ = Context.>> (Context.map_theory
haftmann@33365
    56
  (Sign.map_naming (Name_Space.set_theory_name Context.PureN) #>
wenzelm@37216
    57
   Old_Appl_Syntax.put false #>
wenzelm@26959
    58
   Sign.add_types
wenzelm@30344
    59
   [(Binding.name "fun", 2, NoSyn),
wenzelm@30344
    60
    (Binding.name "prop", 0, NoSyn),
wenzelm@30344
    61
    (Binding.name "itself", 1, NoSyn),
wenzelm@30344
    62
    (Binding.name "dummy", 0, NoSyn)]
wenzelm@30344
    63
  #> Sign.add_nonterminals (map Binding.name Syntax.basic_nonterms)
wenzelm@26430
    64
  #> Sign.add_syntax_i
wenzelm@42263
    65
   [("",            typ "tid => type",                 Delimfix "_"),
wenzelm@42263
    66
    ("",            typ "tvar => type",                Delimfix "_"),
wenzelm@42263
    67
    ("",            typ "type_name => type",           Delimfix "_"),
wenzelm@42263
    68
    ("_type_name",  typ "id => type_name",             Delimfix "_"),
wenzelm@42263
    69
    ("_type_name",  typ "longid => type_name",         Delimfix "_"),
wenzelm@42263
    70
    ("_ofsort",     typ "tid => sort => type",         Mixfix ("_::_", [Syntax.max_pri, 0], Syntax.max_pri)),
wenzelm@42263
    71
    ("_ofsort",     typ "tvar => sort => type",        Mixfix ("_::_", [Syntax.max_pri, 0], Syntax.max_pri)),
wenzelm@42263
    72
    ("_dummy_ofsort", typ "sort => type",              Mixfix ("'_()::_", [0], Syntax.max_pri)),
wenzelm@42263
    73
    ("",            typ "class_name => sort",          Delimfix "_"),
wenzelm@42263
    74
    ("_class_name", typ "id => class_name",            Delimfix "_"),
wenzelm@42263
    75
    ("_class_name", typ "longid => class_name",        Delimfix "_"),
wenzelm@42263
    76
    ("_topsort",    typ "sort",                        Delimfix "{}"),
wenzelm@42263
    77
    ("_sort",       typ "classes => sort",             Delimfix "{_}"),
wenzelm@42263
    78
    ("",            typ "class_name => classes",       Delimfix "_"),
wenzelm@42263
    79
    ("_classes",    typ "class_name => classes => classes", Delimfix "_,_"),
wenzelm@42263
    80
    ("_tapp",       typ "type => type_name => type",   Mixfix ("_ _", [Syntax.max_pri, 0], Syntax.max_pri)),
wenzelm@42263
    81
    ("_tappl",      typ "type => types => type_name => type", Delimfix "((1'(_,/ _')) _)"),
wenzelm@42263
    82
    ("",            typ "type => types",               Delimfix "_"),
wenzelm@42263
    83
    ("_types",      typ "type => types => types",      Delimfix "_,/ _"),
wenzelm@42263
    84
    ("\\<^type>fun", typ "type => type => type",       Mixfix ("(_/ => _)", [1, 0], 0)),
wenzelm@42263
    85
    ("_bracket",    typ "types => type => type",       Mixfix ("([_]/ => _)", [0, 0], 0)),
wenzelm@42263
    86
    ("",            typ "type => type",                Delimfix "'(_')"),
wenzelm@42263
    87
    ("\\<^type>dummy", typ "type",                     Delimfix "'_"),
wenzelm@42263
    88
    ("_type_prop",  typ "'a",                          NoSyn),
wenzelm@42263
    89
    ("_lambda",     typ "pttrns => 'a => logic",       Mixfix ("(3%_./ _)", [0, 3], 3)),
wenzelm@26436
    90
    ("_abs",        typ "'a",                          NoSyn),
wenzelm@26436
    91
    ("",            typ "'a => args",                  Delimfix "_"),
wenzelm@26436
    92
    ("_args",       typ "'a => args => args",          Delimfix "_,/ _"),
wenzelm@42048
    93
    ("",            typ "id_position => idt",          Delimfix "_"),
wenzelm@26436
    94
    ("_idtdummy",   typ "idt",                         Delimfix "'_"),
wenzelm@42048
    95
    ("_idtyp",      typ "id_position => type => idt",  Mixfix ("_::_", [], 0)),
wenzelm@26436
    96
    ("_idtypdummy", typ "type => idt",                 Mixfix ("'_()::_", [], 0)),
wenzelm@26436
    97
    ("",            typ "idt => idt",                  Delimfix "'(_')"),
wenzelm@26436
    98
    ("",            typ "idt => idts",                 Delimfix "_"),
wenzelm@26436
    99
    ("_idts",       typ "idt => idts => idts",         Mixfix ("_/ _", [1, 0], 0)),
wenzelm@26436
   100
    ("",            typ "idt => pttrn",                Delimfix "_"),
wenzelm@26436
   101
    ("",            typ "pttrn => pttrns",             Delimfix "_"),
wenzelm@26436
   102
    ("_pttrns",     typ "pttrn => pttrns => pttrns",   Mixfix ("_/ _", [1, 0], 0)),
wenzelm@28856
   103
    ("",            typ "aprop => aprop",              Delimfix "'(_')"),
wenzelm@42048
   104
    ("",            typ "id_position => aprop",        Delimfix "_"),
wenzelm@42048
   105
    ("",            typ "longid_position => aprop",    Delimfix "_"),
wenzelm@26436
   106
    ("",            typ "var => aprop",                Delimfix "_"),
wenzelm@26436
   107
    ("_DDDOT",      typ "aprop",                       Delimfix "..."),
wenzelm@26436
   108
    ("_aprop",      typ "aprop => prop",               Delimfix "PROP _"),
wenzelm@26436
   109
    ("_asm",        typ "prop => asms",                Delimfix "_"),
wenzelm@26436
   110
    ("_asms",       typ "prop => asms => asms",        Delimfix "_;/ _"),
wenzelm@26436
   111
    ("_bigimpl",    typ "asms => prop => prop",        Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)),
wenzelm@26436
   112
    ("_ofclass",    typ "type => logic => prop",       Delimfix "(1OFCLASS/(1'(_,/ _')))"),
wenzelm@26436
   113
    ("_mk_ofclass", typ "dummy",                       NoSyn),
wenzelm@26436
   114
    ("_TYPE",       typ "type => logic",               Delimfix "(1TYPE/(1'(_')))"),
wenzelm@42048
   115
    ("",            typ "id_position => logic",        Delimfix "_"),
wenzelm@42048
   116
    ("",            typ "longid_position => logic",    Delimfix "_"),
wenzelm@26436
   117
    ("",            typ "var => logic",                Delimfix "_"),
wenzelm@26436
   118
    ("_DDDOT",      typ "logic",                       Delimfix "..."),
wenzelm@42057
   119
    ("_strip_positions", typ "'a", NoSyn),
wenzelm@26436
   120
    ("_constify",   typ "num => num_const",            Delimfix "_"),
wenzelm@29156
   121
    ("_constify",   typ "float_token => float_const",  Delimfix "_"),
wenzelm@26436
   122
    ("_indexnum",   typ "num_const => index",          Delimfix "\\<^sub>_"),
wenzelm@26436
   123
    ("_index",      typ "logic => index",              Delimfix "(00\\<^bsub>_\\<^esub>)"),
wenzelm@26436
   124
    ("_indexdefault", typ "index",                     Delimfix ""),
wenzelm@26436
   125
    ("_indexvar",   typ "index",                       Delimfix "'\\<index>"),
wenzelm@26436
   126
    ("_struct",     typ "index => logic",              Mixfix ("\\<struct>_", [1000], 1000)),
wenzelm@35145
   127
    ("_update_name", typ "idt",                        NoSyn),
wenzelm@42284
   128
    ("_constrainAbs", typ "'a",                       NoSyn),
wenzelm@42048
   129
    ("_constrain_position", typ "id => id_position",   Delimfix "_"),
wenzelm@42048
   130
    ("_constrain_position", typ "longid => longid_position", Delimfix "_"),
wenzelm@42048
   131
    ("_type_constraint_", typ "'a",                    NoSyn),
wenzelm@35255
   132
    (const "==>",   typ "prop => prop => prop",        Delimfix "op ==>"),
wenzelm@35255
   133
    (const Term.dummy_patternN, typ "aprop",           Delimfix "'_"),
wenzelm@28856
   134
    ("_sort_constraint", typ "type => prop",           Delimfix "(1SORT'_CONSTRAINT/(1'(_')))"),
wenzelm@35255
   135
    (const "Pure.term", typ "logic => prop",           Delimfix "TERM _"),
wenzelm@35255
   136
    (const "Pure.conjunction", typ "prop => prop => prop", Infixr ("&&&", 2))]
wenzelm@26959
   137
  #> Sign.add_syntax_i applC_syntax
wenzelm@26430
   138
  #> Sign.add_modesyntax_i (Symbol.xsymbolsN, true)
wenzelm@35429
   139
   [(tycon "fun",         typ "type => type => type",   Mixfix ("(_/ \\<Rightarrow> _)", [1, 0], 0)),
wenzelm@35429
   140
    ("_bracket",          typ "types => type => type",  Mixfix ("([_]/ \\<Rightarrow> _)", [0, 0], 0)),
wenzelm@35429
   141
    ("_ofsort",           typ "tid => sort => type",    Mixfix ("_\\<Colon>_", [1000, 0], 1000)),
wenzelm@35429
   142
    ("_constrain",        typ "logic => type => logic", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42293
   143
    ("_constrain",        typ "prop' => type => prop'", Mixfix ("_\\<Colon>_", [4, 0], 3)),
wenzelm@42048
   144
    ("_idtyp",            typ "id_position => type => idt", Mixfix ("_\\<Colon>_", [], 0)),
wenzelm@35429
   145
    ("_idtypdummy",       typ "type => idt",            Mixfix ("'_()\\<Colon>_", [], 0)),
wenzelm@35429
   146
    ("_lambda",           typ "pttrns => 'a => logic",  Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3)),
wenzelm@35429
   147
    (const "==",          typ "'a => 'a => prop",       Infixr ("\\<equiv>", 2)),
wenzelm@35429
   148
    (const "all_binder",  typ "idts => prop => prop",   Mixfix ("(3\\<And>_./ _)", [0, 0], 0)),
wenzelm@35429
   149
    (const "==>",         typ "prop => prop => prop",   Infixr ("\\<Longrightarrow>", 1)),
wenzelm@35429
   150
    ("_DDDOT",            typ "aprop",                  Delimfix "\\<dots>"),
wenzelm@35429
   151
    ("_bigimpl",          typ "asms => prop => prop",   Mixfix ("((1\\<lbrakk>_\\<rbrakk>)/ \\<Longrightarrow> _)", [0, 1], 1)),
wenzelm@35429
   152
    ("_DDDOT",            typ "logic",                  Delimfix "\\<dots>")]
wenzelm@26430
   153
  #> Sign.add_modesyntax_i ("", false)
wenzelm@35255
   154
   [(const "prop", typ "prop => prop", Mixfix ("_", [0], 0))]
wenzelm@26430
   155
  #> Sign.add_modesyntax_i ("HTML", false)
wenzelm@24243
   156
   [("_lambda", typ "pttrns => 'a => logic", Mixfix ("(3\\<lambda>_./ _)", [0, 3], 3))]
wenzelm@26430
   157
  #> Sign.add_consts_i
wenzelm@35130
   158
   [(Binding.name "==", typ "'a => 'a => prop", Infixr ("==", 2)),
wenzelm@30344
   159
    (Binding.name "==>", typ "prop => prop => prop", Mixfix ("(_/ ==> _)", [2, 1], 1)),
wenzelm@30344
   160
    (Binding.name "all", typ "('a => prop) => prop", Binder ("!!", 0, 0)),
wenzelm@30344
   161
    (Binding.name "prop", typ "prop => prop", NoSyn),
wenzelm@30344
   162
    (Binding.name "TYPE", typ "'a itself", NoSyn),
wenzelm@30344
   163
    (Binding.name Term.dummy_patternN, typ "'a", Delimfix "'_")]
wenzelm@26430
   164
  #> Theory.add_deps "==" ("==", typ "'a => 'a => prop") []
wenzelm@26430
   165
  #> Theory.add_deps "==>" ("==>", typ "prop => prop => prop") []
wenzelm@26430
   166
  #> Theory.add_deps "all" ("all", typ "('a => prop) => prop") []
wenzelm@26430
   167
  #> Theory.add_deps "TYPE" ("TYPE", typ "'a itself") []
wenzelm@26430
   168
  #> Theory.add_deps Term.dummy_patternN (Term.dummy_patternN, typ "'a") []
wenzelm@42284
   169
  #> Sign.add_trfuns Syntax_Trans.pure_trfuns
wenzelm@26430
   170
  #> Sign.local_path
wenzelm@26430
   171
  #> Sign.add_consts_i
wenzelm@30344
   172
   [(Binding.name "term", typ "'a => prop", NoSyn),
wenzelm@30344
   173
    (Binding.name "sort_constraint", typ "'a itself => prop", NoSyn),
wenzelm@30344
   174
    (Binding.name "conjunction", typ "prop => prop => prop", NoSyn)]
wenzelm@39557
   175
  #> (Global_Theory.add_defs false o map Thm.no_attributes)
haftmann@29579
   176
   [(Binding.name "prop_def", prop "(CONST prop :: prop => prop) (A::prop) == A::prop"),
haftmann@29579
   177
    (Binding.name "term_def", prop "(CONST Pure.term :: 'a => prop) (x::'a) == (!!A::prop. A ==> A)"),
haftmann@29579
   178
    (Binding.name "sort_constraint_def",
wenzelm@28622
   179
      prop "(CONST Pure.sort_constraint :: 'a itself => prop) (CONST TYPE :: 'a itself) ==\
wenzelm@28622
   180
      \ (CONST Pure.term :: 'a itself => prop) (CONST TYPE :: 'a itself)"),
haftmann@29579
   181
    (Binding.name "conjunction_def", prop "(A &&& B) == (!!C::prop. (A ==> B ==> C) ==> C)")] #> snd
wenzelm@28622
   182
  #> Sign.hide_const false "Pure.term"
wenzelm@28622
   183
  #> Sign.hide_const false "Pure.sort_constraint"
wenzelm@26666
   184
  #> Sign.hide_const false "Pure.conjunction"
wenzelm@39557
   185
  #> Global_Theory.add_thmss [((Binding.name "nothing", []), [])] #> snd
wenzelm@35856
   186
  #> fold (fn (a, prop) => snd o Thm.add_axiom (Binding.name a, prop)) Proofterm.equality_axms));
wenzelm@3987
   187
wenzelm@3987
   188
end;