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