src/HOL/HOL.thy
author paulson
Fri May 30 15:19:58 1997 +0200 (1997-05-30)
changeset 3370 5c5fdce3a4e4
parent 3320 3a5e4930fb77
child 3820 46b255e140dc
permissions -rw-r--r--
Overloading of "^" requires new type class "power", with types "nat" and
"set" in that class. The operator itself is declared in Nat.thy
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
wenzelm@3230
    28
syntax ("" output)
wenzelm@3230
    29
  "op ="        :: ['a, 'a] => bool                 ("(_ =/ _)" [51, 51] 50)
wenzelm@3230
    30
  "op ~="       :: ['a, 'a] => bool                 ("(_ ~=/ _)" [51, 51] 50)
wenzelm@3230
    31
clasohm@923
    32
consts
clasohm@923
    33
clasohm@923
    34
  (* Constants *)
clasohm@923
    35
clasohm@1370
    36
  Trueprop      :: bool => prop                     ("(_)" 5)
paulson@2720
    37
  Not           :: bool => bool                     ("~ _" [40] 40)
clasohm@1370
    38
  True, False   :: bool
clasohm@1370
    39
  If            :: [bool, 'a, 'a] => 'a   ("(if (_)/ then (_)/ else (_))" 10)
clasohm@923
    40
clasohm@923
    41
  (* Binders *)
clasohm@923
    42
clasohm@1370
    43
  Eps           :: ('a => bool) => 'a
clasohm@1370
    44
  All           :: ('a => bool) => bool             (binder "! " 10)
clasohm@1370
    45
  Ex            :: ('a => bool) => bool             (binder "? " 10)
clasohm@1370
    46
  Ex1           :: ('a => bool) => bool             (binder "?! " 10)
clasohm@1370
    47
  Let           :: ['a, 'a => 'b] => 'b
clasohm@923
    48
clasohm@923
    49
  (* Infixes *)
clasohm@923
    50
clasohm@1370
    51
  o             :: ['b => 'c, 'a => 'b, 'a] => 'c   (infixl 55)
clasohm@1370
    52
  "="           :: ['a, 'a] => bool                 (infixl 50)
clasohm@1370
    53
  "&"           :: [bool, bool] => bool             (infixr 35)
clasohm@1370
    54
  "|"           :: [bool, bool] => bool             (infixr 30)
clasohm@1370
    55
  "-->"         :: [bool, bool] => bool             (infixr 25)
clasohm@923
    56
wenzelm@2260
    57
wenzelm@2260
    58
(* Overloaded Constants *)
wenzelm@2260
    59
wenzelm@2260
    60
axclass
wenzelm@2260
    61
  plus < term
clasohm@923
    62
wenzelm@2260
    63
axclass
wenzelm@2260
    64
  minus < term
wenzelm@2260
    65
wenzelm@2260
    66
axclass
wenzelm@2260
    67
  times < term
wenzelm@2260
    68
paulson@3370
    69
axclass
paulson@3370
    70
  power < term
paulson@3370
    71
wenzelm@2260
    72
consts
paulson@3370
    73
  "+"           :: ['a::plus, 'a]  => 'a            (infixl 65)
clasohm@1370
    74
  "-"           :: ['a::minus, 'a] => 'a            (infixl 65)
clasohm@1370
    75
  "*"           :: ['a::times, 'a] => 'a            (infixl 70)
paulson@3370
    76
  (*See Nat.thy for "^"*)
wenzelm@2260
    77
wenzelm@2260
    78
(** Additional concrete syntax **)
wenzelm@2260
    79
clasohm@923
    80
types
clasohm@923
    81
  letbinds  letbind
clasohm@923
    82
  case_syn  cases_syn
clasohm@923
    83
clasohm@923
    84
syntax
clasohm@923
    85
clasohm@1370
    86
  "~="          :: ['a, 'a] => bool                 (infixl 50)
clasohm@923
    87
wenzelm@2368
    88
  "@Eps"        :: [pttrn, bool] => 'a              ("(3@ _./ _)" [0, 10] 10)
nipkow@1068
    89
clasohm@923
    90
  (* Alternative Quantifiers *)
clasohm@923
    91
wenzelm@2368
    92
  "*All"        :: [idts, bool] => bool             ("(3ALL _./ _)" [0, 10] 10)
wenzelm@2368
    93
  "*Ex"         :: [idts, bool] => bool             ("(3EX _./ _)" [0, 10] 10)
wenzelm@2368
    94
  "*Ex1"        :: [idts, bool] => bool             ("(3EX! _./ _)" [0, 10] 10)
clasohm@923
    95
clasohm@923
    96
  (* Let expressions *)
clasohm@923
    97
clasohm@1370
    98
  "_bind"       :: [pttrn, 'a] => letbind           ("(2_ =/ _)" 10)
clasohm@1370
    99
  ""            :: letbind => letbinds              ("_")
clasohm@1370
   100
  "_binds"      :: [letbind, letbinds] => letbinds  ("_;/ _")
clasohm@1370
   101
  "_Let"        :: [letbinds, 'a] => 'a             ("(let (_)/ in (_))" 10)
clasohm@923
   102
clasohm@923
   103
  (* Case expressions *)
clasohm@923
   104
clasohm@1370
   105
  "@case"       :: ['a, cases_syn] => 'b            ("(case _ of/ _)" 10)
clasohm@1370
   106
  "@case1"      :: ['a, 'b] => case_syn             ("(2_ =>/ _)" 10)
clasohm@1370
   107
  ""            :: case_syn => cases_syn            ("_")
clasohm@1370
   108
  "@case2"      :: [case_syn, cases_syn] => cases_syn   ("_/ | _")
clasohm@923
   109
clasohm@923
   110
translations
clasohm@923
   111
  "x ~= y"      == "~ (x = y)"
wenzelm@2260
   112
  "@ x.b"       == "Eps (%x. b)"
clasohm@923
   113
  "ALL xs. P"   => "! xs. P"
clasohm@923
   114
  "EX xs. P"    => "? xs. P"
clasohm@923
   115
  "EX! xs. P"   => "?! xs. P"
clasohm@923
   116
  "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
nipkow@1114
   117
  "let x = a in e"        == "Let a (%x. e)"
clasohm@923
   118
wenzelm@3230
   119
syntax (symbols output)
wenzelm@3230
   120
  "op ~="       :: ['a, 'a] => bool                 ("(_ \\<noteq>/ _)" [51, 51] 50)
wenzelm@3248
   121
  "*All"        :: [idts, bool] => bool             ("(3\\<forall>_./ _)" [0, 10] 10)
wenzelm@3248
   122
  "*Ex"         :: [idts, bool] => bool             ("(3\\<exists>_./ _)" [0, 10] 10)
wenzelm@3248
   123
  "*Ex1"        :: [idts, bool] => bool             ("(3\\<exists>!_./ _)" [0, 10] 10)
wenzelm@2260
   124
wenzelm@2260
   125
syntax (symbols)
wenzelm@2762
   126
  Not           :: bool => bool                     ("\\<not> _" [40] 40)
wenzelm@2260
   127
  "op &"        :: [bool, bool] => bool             (infixr "\\<and>" 35)
wenzelm@2260
   128
  "op |"        :: [bool, bool] => bool             (infixr "\\<or>" 30)
wenzelm@2260
   129
  "op -->"      :: [bool, bool] => bool             (infixr "\\<midarrow>\\<rightarrow>" 25)
wenzelm@2260
   130
  "op o"        :: ['b => 'c, 'a => 'b, 'a] => 'c   (infixl "\\<circ>" 55)
wenzelm@2260
   131
  "op ~="       :: ['a, 'a] => bool                 (infixl "\\<noteq>" 50)
wenzelm@2368
   132
  "@Eps"        :: [pttrn, bool] => 'a              ("(3\\<epsilon>_./ _)" [0, 10] 10)
wenzelm@2368
   133
  "! "          :: [idts, bool] => bool             ("(3\\<forall>_./ _)" [0, 10] 10)
wenzelm@2368
   134
  "? "          :: [idts, bool] => bool             ("(3\\<exists>_./ _)" [0, 10] 10)
wenzelm@2368
   135
  "?! "         :: [idts, bool] => bool             ("(3\\<exists>!_./ _)" [0, 10] 10)
wenzelm@2552
   136
  "@case1"      :: ['a, 'b] => case_syn             ("(2_ \\<Rightarrow>/ _)" 10)
wenzelm@3068
   137
(*"@case2"      :: [case_syn, cases_syn] => cases_syn   ("_/ \\<orelse> _")*)
wenzelm@2372
   138
wenzelm@2260
   139
wenzelm@2260
   140
wenzelm@2260
   141
(** Rules and definitions **)
wenzelm@2260
   142
clasohm@923
   143
rules
clasohm@923
   144
clasohm@923
   145
  eq_reflection "(x=y) ==> (x==y)"
clasohm@923
   146
clasohm@923
   147
  (* Basic Rules *)
clasohm@923
   148
clasohm@923
   149
  refl          "t = (t::'a)"
clasohm@923
   150
  subst         "[| s = t; P(s) |] ==> P(t::'a)"
clasohm@923
   151
  ext           "(!!x::'a. (f(x)::'b) = g(x)) ==> (%x.f(x)) = (%x.g(x))"
clasohm@923
   152
  selectI       "P(x::'a) ==> P(@x.P(x))"
clasohm@923
   153
clasohm@923
   154
  impI          "(P ==> Q) ==> P-->Q"
clasohm@923
   155
  mp            "[| P-->Q;  P |] ==> Q"
clasohm@923
   156
clasohm@923
   157
defs
clasohm@923
   158
clasohm@923
   159
  True_def      "True      == ((%x::bool.x)=(%x.x))"
clasohm@923
   160
  All_def       "All(P)    == (P = (%x.True))"
clasohm@923
   161
  Ex_def        "Ex(P)     == P(@x.P(x))"
clasohm@923
   162
  False_def     "False     == (!P.P)"
clasohm@923
   163
  not_def       "~ P       == P-->False"
clasohm@923
   164
  and_def       "P & Q     == !R. (P-->Q-->R) --> R"
clasohm@923
   165
  or_def        "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
clasohm@923
   166
  Ex1_def       "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
clasohm@923
   167
clasohm@923
   168
rules
clasohm@923
   169
  (* Axioms *)
clasohm@923
   170
clasohm@923
   171
  iff           "(P-->Q) --> (Q-->P) --> (P=Q)"
clasohm@923
   172
  True_or_False "(P=True) | (P=False)"
clasohm@923
   173
clasohm@923
   174
defs
clasohm@923
   175
  (* Misc Definitions *)
clasohm@923
   176
clasohm@923
   177
  Let_def       "Let s f == f(s)"
clasohm@923
   178
  o_def         "(f::'b=>'c) o g == (%(x::'a). f(g(x)))"
nipkow@973
   179
  if_def        "If P x y == @z::'a. (P=True --> z=x) & (P=False --> z=y)"
clasohm@923
   180
nipkow@3320
   181
constdefs arbitrary :: 'a
nipkow@3320
   182
         "arbitrary == @x.False"
nipkow@3320
   183
clasohm@923
   184
end
clasohm@923
   185
wenzelm@2260
   186
clasohm@923
   187
ML
clasohm@923
   188
clasohm@923
   189
(** Choice between the HOL and Isabelle style of quantifiers **)
clasohm@923
   190
clasohm@923
   191
val HOL_quantifiers = ref true;
clasohm@923
   192
clasohm@923
   193
fun alt_ast_tr' (name, alt_name) =
clasohm@923
   194
  let
clasohm@923
   195
    fun ast_tr' (*name*) args =
clasohm@923
   196
      if ! HOL_quantifiers then raise Match
clasohm@923
   197
      else Syntax.mk_appl (Syntax.Constant alt_name) args;
clasohm@923
   198
  in
clasohm@923
   199
    (name, ast_tr')
clasohm@923
   200
  end;
clasohm@923
   201
clasohm@923
   202
clasohm@923
   203
val print_ast_translation =
clasohm@923
   204
  map alt_ast_tr' [("! ", "*All"), ("? ", "*Ex"), ("?! ", "*Ex1")];