src/HOL/HOL.thy
author nipkow
Fri Apr 04 16:33:28 1997 +0200 (1997-04-04)
changeset 2912 3fac3e8d5d3e
parent 2762 2ade3a141934
child 3066 3c548f92e032
permissions -rw-r--r--
moved inj and surj from Set to Fun and Inv -> inv.
clasohm@923
     1
(*  Title:      HOL/HOL.thy
clasohm@923
     2
    ID:         $Id$
clasohm@923
     3
    Author:     Tobias Nipkow
clasohm@923
     4
    Copyright   1993  University of Cambridge
clasohm@923
     5
wenzelm@2260
     6
Higher-Order Logic.
clasohm@923
     7
*)
clasohm@923
     8
clasohm@923
     9
HOL = CPure +
clasohm@923
    10
wenzelm@2260
    11
wenzelm@2260
    12
(** Core syntax **)
wenzelm@2260
    13
clasohm@923
    14
classes
clasohm@923
    15
  term < logic
clasohm@923
    16
clasohm@923
    17
default
clasohm@923
    18
  term
clasohm@923
    19
clasohm@923
    20
types
clasohm@923
    21
  bool
clasohm@923
    22
clasohm@923
    23
arities
clasohm@923
    24
  fun :: (term, term) term
clasohm@923
    25
  bool :: term
clasohm@923
    26
clasohm@923
    27
clasohm@923
    28
consts
clasohm@923
    29
clasohm@923
    30
  (* Constants *)
clasohm@923
    31
clasohm@1370
    32
  Trueprop      :: bool => prop                     ("(_)" 5)
paulson@2720
    33
  Not           :: bool => bool                     ("~ _" [40] 40)
clasohm@1370
    34
  True, False   :: bool
clasohm@1370
    35
  If            :: [bool, 'a, 'a] => 'a   ("(if (_)/ then (_)/ else (_))" 10)
clasohm@923
    36
clasohm@923
    37
  (* Binders *)
clasohm@923
    38
clasohm@1370
    39
  Eps           :: ('a => bool) => 'a
clasohm@1370
    40
  All           :: ('a => bool) => bool             (binder "! " 10)
clasohm@1370
    41
  Ex            :: ('a => bool) => bool             (binder "? " 10)
clasohm@1370
    42
  Ex1           :: ('a => bool) => bool             (binder "?! " 10)
clasohm@1370
    43
  Let           :: ['a, 'a => 'b] => 'b
clasohm@923
    44
clasohm@923
    45
  (* Infixes *)
clasohm@923
    46
clasohm@1370
    47
  o             :: ['b => 'c, 'a => 'b, 'a] => 'c   (infixl 55)
clasohm@1370
    48
  "="           :: ['a, 'a] => bool                 (infixl 50)
clasohm@1370
    49
  "&"           :: [bool, bool] => bool             (infixr 35)
clasohm@1370
    50
  "|"           :: [bool, bool] => bool             (infixr 30)
clasohm@1370
    51
  "-->"         :: [bool, bool] => bool             (infixr 25)
clasohm@923
    52
wenzelm@2260
    53
wenzelm@2260
    54
(* Overloaded Constants *)
wenzelm@2260
    55
wenzelm@2260
    56
axclass
wenzelm@2260
    57
  plus < term
clasohm@923
    58
wenzelm@2260
    59
axclass
wenzelm@2260
    60
  minus < term
wenzelm@2260
    61
wenzelm@2260
    62
axclass
wenzelm@2260
    63
  times < term
wenzelm@2260
    64
wenzelm@2260
    65
consts
clasohm@1370
    66
  "+"           :: ['a::plus, 'a] => 'a             (infixl 65)
clasohm@1370
    67
  "-"           :: ['a::minus, 'a] => 'a            (infixl 65)
clasohm@1370
    68
  "*"           :: ['a::times, 'a] => 'a            (infixl 70)
clasohm@923
    69
clasohm@923
    70
wenzelm@2260
    71
wenzelm@2260
    72
(** Additional concrete syntax **)
wenzelm@2260
    73
clasohm@923
    74
types
clasohm@923
    75
  letbinds  letbind
clasohm@923
    76
  case_syn  cases_syn
clasohm@923
    77
clasohm@923
    78
syntax
clasohm@923
    79
clasohm@1370
    80
  "~="          :: ['a, 'a] => bool                 (infixl 50)
clasohm@923
    81
wenzelm@2368
    82
  "@Eps"        :: [pttrn, bool] => 'a              ("(3@ _./ _)" [0, 10] 10)
nipkow@1068
    83
clasohm@923
    84
  (* Alternative Quantifiers *)
clasohm@923
    85
wenzelm@2368
    86
  "*All"        :: [idts, bool] => bool             ("(3ALL _./ _)" [0, 10] 10)
wenzelm@2368
    87
  "*Ex"         :: [idts, bool] => bool             ("(3EX _./ _)" [0, 10] 10)
wenzelm@2368
    88
  "*Ex1"        :: [idts, bool] => bool             ("(3EX! _./ _)" [0, 10] 10)
clasohm@923
    89
clasohm@923
    90
  (* Let expressions *)
clasohm@923
    91
clasohm@1370
    92
  "_bind"       :: [pttrn, 'a] => letbind           ("(2_ =/ _)" 10)
clasohm@1370
    93
  ""            :: letbind => letbinds              ("_")
clasohm@1370
    94
  "_binds"      :: [letbind, letbinds] => letbinds  ("_;/ _")
clasohm@1370
    95
  "_Let"        :: [letbinds, 'a] => 'a             ("(let (_)/ in (_))" 10)
clasohm@923
    96
clasohm@923
    97
  (* Case expressions *)
clasohm@923
    98
clasohm@1370
    99
  "@case"       :: ['a, cases_syn] => 'b            ("(case _ of/ _)" 10)
clasohm@1370
   100
  "@case1"      :: ['a, 'b] => case_syn             ("(2_ =>/ _)" 10)
clasohm@1370
   101
  ""            :: case_syn => cases_syn            ("_")
clasohm@1370
   102
  "@case2"      :: [case_syn, cases_syn] => cases_syn   ("_/ | _")
clasohm@923
   103
clasohm@923
   104
translations
clasohm@923
   105
  "x ~= y"      == "~ (x = y)"
wenzelm@2260
   106
  "@ x.b"       == "Eps (%x. b)"
clasohm@923
   107
  "ALL xs. P"   => "! xs. P"
clasohm@923
   108
  "EX xs. P"    => "? xs. P"
clasohm@923
   109
  "EX! xs. P"   => "?! xs. P"
clasohm@923
   110
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
   111
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
   112
wenzelm@2260
   113
wenzelm@2260
   114
syntax (symbols)
wenzelm@2762
   115
  Not           :: bool => bool                     ("\\<not> _" [40] 40)
wenzelm@2260
   116
  "op &"        :: [bool, bool] => bool             (infixr "\\<and>" 35)
wenzelm@2260
   117
  "op |"        :: [bool, bool] => bool             (infixr "\\<or>" 30)
wenzelm@2260
   118
  "op -->"      :: [bool, bool] => bool             (infixr "\\<midarrow>\\<rightarrow>" 25)
wenzelm@2260
   119
  "op o"        :: ['b => 'c, 'a => 'b, 'a] => 'c   (infixl "\\<circ>" 55)
wenzelm@2260
   120
  "op ~="       :: ['a, 'a] => bool                 (infixl "\\<noteq>" 50)
wenzelm@2368
   121
  "@Eps"        :: [pttrn, bool] => 'a              ("(3\\<epsilon>_./ _)" [0, 10] 10)
wenzelm@2368
   122
  "! "          :: [idts, bool] => bool             ("(3\\<forall>_./ _)" [0, 10] 10)
wenzelm@2368
   123
  "? "          :: [idts, bool] => bool             ("(3\\<exists>_./ _)" [0, 10] 10)
wenzelm@2368
   124
  "?! "         :: [idts, bool] => bool             ("(3\\<exists>!_./ _)" [0, 10] 10)
wenzelm@2552
   125
  "@case1"      :: ['a, 'b] => case_syn             ("(2_ \\<Rightarrow>/ _)" 10)
wenzelm@2372
   126
wenzelm@2372
   127
syntax (symbols output)
wenzelm@2368
   128
  "*All"        :: [idts, bool] => bool             ("(3\\<forall>_./ _)" [0, 10] 10)
wenzelm@2368
   129
  "*Ex"         :: [idts, bool] => bool             ("(3\\<exists>_./ _)" [0, 10] 10)
wenzelm@2368
   130
  "*Ex1"        :: [idts, bool] => bool             ("(3\\<exists>!_./ _)" [0, 10] 10)
wenzelm@2372
   131
wenzelm@2260
   132
wenzelm@2260
   133
wenzelm@2260
   134
wenzelm@2260
   135
(** Rules and definitions **)
wenzelm@2260
   136
clasohm@923
   137
rules
clasohm@923
   138
clasohm@923
   139
  eq_reflection "(x=y) ==> (x==y)"
clasohm@923
   140
clasohm@923
   141
  (* Basic Rules *)
clasohm@923
   142
clasohm@923
   143
  refl          "t = (t::'a)"
clasohm@923
   144
  subst         "[| s = t; P(s) |] ==> P(t::'a)"
clasohm@923
   145
  ext           "(!!x::'a. (f(x)::'b) = g(x)) ==> (%x.f(x)) = (%x.g(x))"
clasohm@923
   146
  selectI       "P(x::'a) ==> P(@x.P(x))"
clasohm@923
   147
clasohm@923
   148
  impI          "(P ==> Q) ==> P-->Q"
clasohm@923
   149
  mp            "[| P-->Q;  P |] ==> Q"
clasohm@923
   150
clasohm@923
   151
defs
clasohm@923
   152
clasohm@923
   153
  True_def      "True      == ((%x::bool.x)=(%x.x))"
clasohm@923
   154
  All_def       "All(P)    == (P = (%x.True))"
clasohm@923
   155
  Ex_def        "Ex(P)     == P(@x.P(x))"
clasohm@923
   156
  False_def     "False     == (!P.P)"
clasohm@923
   157
  not_def       "~ P       == P-->False"
clasohm@923
   158
  and_def       "P & Q     == !R. (P-->Q-->R) --> R"
clasohm@923
   159
  or_def        "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
clasohm@923
   160
  Ex1_def       "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   161
clasohm@923
   162
rules
clasohm@923
   163
  (* Axioms *)
clasohm@923
   164
clasohm@923
   165
  iff           "(P-->Q) --> (Q-->P) --> (P=Q)"
clasohm@923
   166
  True_or_False "(P=True) | (P=False)"
clasohm@923
   167
clasohm@923
   168
defs
clasohm@923
   169
  (* Misc Definitions *)
clasohm@923
   170
clasohm@923
   171
  Let_def       "Let s f == f(s)"
clasohm@923
   172
  o_def         "(f::'b=>'c) o g == (%(x::'a). f(g(x)))"
nipkow@973
   173
  if_def        "If P x y == @z::'a. (P=True --> z=x) & (P=False --> z=y)"
clasohm@923
   174
clasohm@923
   175
end
clasohm@923
   176
wenzelm@2260
   177
clasohm@923
   178
ML
clasohm@923
   179
clasohm@923
   180
(** Choice between the HOL and Isabelle style of quantifiers **)
clasohm@923
   181
clasohm@923
   182
val HOL_quantifiers = ref true;
clasohm@923
   183
clasohm@923
   184
fun alt_ast_tr' (name, alt_name) =
clasohm@923
   185
  let
clasohm@923
   186
    fun ast_tr' (*name*) args =
clasohm@923
   187
      if ! HOL_quantifiers then raise Match
clasohm@923
   188
      else Syntax.mk_appl (Syntax.Constant alt_name) args;
clasohm@923
   189
  in
clasohm@923
   190
    (name, ast_tr')
clasohm@923
   191
  end;
clasohm@923
   192
clasohm@923
   193
clasohm@923
   194
val print_ast_translation =
clasohm@923
   195
  map alt_ast_tr' [("! ", "*All"), ("? ", "*Ex"), ("?! ", "*Ex1")];