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