src/HOL/HOL.thy
author paulson
Mon Feb 22 10:20:25 1999 +0100 (1999-02-22)
changeset 6289 062aa156a300
parent 6027 9dd06eeda95c
child 6340 7d5cbd5819a0
permissions -rw-r--r--
added a commment on the "ext" rule
     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 global
    15 
    16 classes
    17   term < logic
    18 
    19 default
    20   term
    21 
    22 types
    23   bool
    24 
    25 arities
    26   fun :: (term, term) term
    27   bool :: term
    28 
    29 
    30 consts
    31 
    32   (* Constants *)
    33 
    34   Trueprop      :: bool => prop                     ("(_)" 5)
    35   Not           :: bool => bool                     ("~ _" [40] 40)
    36   True, False   :: bool
    37   If            :: [bool, 'a, 'a] => 'a   ("(if (_)/ then (_)/ else (_))" 10)
    38   arbitrary     :: 'a
    39 
    40   (* Binders *)
    41 
    42   Eps           :: ('a => bool) => 'a
    43   All           :: ('a => bool) => bool             (binder "! " 10)
    44   Ex            :: ('a => bool) => bool             (binder "? " 10)
    45   Ex1           :: ('a => bool) => bool             (binder "?! " 10)
    46   Let           :: ['a, 'a => 'b] => 'b
    47 
    48   (* Infixes *)
    49 
    50   "="           :: ['a, 'a] => bool                 (infixl 50)
    51   "&"           :: [bool, bool] => bool             (infixr 35)
    52   "|"           :: [bool, bool] => bool             (infixr 30)
    53   "-->"         :: [bool, bool] => bool             (infixr 25)
    54 
    55 
    56 (* Overloaded Constants *)
    57 
    58 axclass
    59   plus < term
    60 
    61 axclass
    62   minus < term
    63 
    64 axclass
    65   times < term
    66 
    67 axclass
    68   power < term
    69 
    70 consts
    71   "+"           :: ['a::plus, 'a]  => 'a            (infixl 65)
    72   "-"           :: ['a::minus, 'a] => 'a            (infixl 65)
    73   uminus        :: ['a::minus] => 'a                ("- _" [100] 100)
    74   "*"           :: ['a::times, 'a] => 'a            (infixl 70)
    75   (*See Nat.thy for "^"*)
    76 
    77 
    78 (** Additional concrete syntax **)
    79 
    80 nonterminals
    81   letbinds  letbind
    82   case_syn  cases_syn
    83 
    84 syntax
    85 
    86   "~="          :: ['a, 'a] => bool                 (infixl 50)
    87 
    88   "@Eps"        :: [pttrn, bool] => 'a              ("(3@ _./ _)" [0, 10] 10)
    89 
    90   (* Alternative Quantifiers *)
    91 
    92   "*All"        :: [idts, bool] => bool             ("(3ALL _./ _)" [0, 10] 10)
    93   "*Ex"         :: [idts, bool] => bool             ("(3EX _./ _)" [0, 10] 10)
    94   "*Ex1"        :: [idts, bool] => bool             ("(3EX! _./ _)" [0, 10] 10)
    95 
    96   (* Let expressions *)
    97 
    98   "_bind"       :: [pttrn, 'a] => letbind           ("(2_ =/ _)" 10)
    99   ""            :: letbind => letbinds              ("_")
   100   "_binds"      :: [letbind, letbinds] => letbinds  ("_;/ _")
   101   "_Let"        :: [letbinds, 'a] => 'a             ("(let (_)/ in (_))" 10)
   102 
   103   (* Case expressions *)
   104 
   105   "@case"       :: ['a, cases_syn] => 'b            ("(case _ of/ _)" 10)
   106   "@case1"      :: ['a, 'b] => case_syn             ("(2_ =>/ _)" 10)
   107   ""            :: case_syn => cases_syn            ("_")
   108   "@case2"      :: [case_syn, cases_syn] => cases_syn   ("_/ | _")
   109 
   110 translations
   111   "x ~= y"      == "~ (x = y)"
   112   "@ x. b"      == "Eps (%x. b)"
   113   "ALL xs. P"   => "! xs. P"
   114   "EX xs. P"    => "? xs. P"
   115   "EX! xs. P"   => "?! xs. P"
   116   "_Let (_binds b bs) e"  == "_Let b (_Let bs e)"
   117   "let x = a in e"        == "Let a (%x. e)"
   118 
   119 syntax ("" output)
   120   "op ="        :: ['a, 'a] => bool                 ("(_ =/ _)" [51, 51] 50)
   121   "op ~="       :: ['a, 'a] => bool                 ("(_ ~=/ _)" [51, 51] 50)
   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 syntax (symbols output)
   138   "op ~="       :: ['a, 'a] => bool                 ("(_ \\<noteq>/ _)" [51, 51] 50)
   139   "*All"        :: [idts, bool] => bool             ("(3\\<forall>_./ _)" [0, 10] 10)
   140   "*Ex"         :: [idts, bool] => bool             ("(3\\<exists>_./ _)" [0, 10] 10)
   141   "*Ex1"        :: [idts, bool] => bool             ("(3\\<exists>!_./ _)" [0, 10] 10)
   142 
   143 
   144 syntax (xsymbols)
   145   "op -->"      :: [bool, bool] => bool             (infixr "\\<longrightarrow>" 25)
   146 
   147 (** Rules and definitions **)
   148 
   149 local
   150 
   151 rules
   152 
   153   eq_reflection "(x=y) ==> (x==y)"
   154 
   155   (* Basic Rules *)
   156 
   157   refl          "t = (t::'a)"
   158   subst         "[| s = t; P(s) |] ==> P(t::'a)"
   159 
   160   (*Extensionality is built into the meta-logic, and this rule expresses
   161     a related property.  It is an eta-expanded version of the traditional
   162     rule, and similar to the ABS rule of HOL.*)
   163   ext           "(!!x::'a. (f x ::'b) = g x) ==> (%x. f x) = (%x. g x)"
   164 
   165   selectI       "P (x::'a) ==> P (@x. P x)"
   166 
   167   impI          "(P ==> Q) ==> P-->Q"
   168   mp            "[| P-->Q;  P |] ==> Q"
   169 
   170 defs
   171 
   172   True_def      "True      == ((%x::bool. x) = (%x. x))"
   173   All_def       "All(P)    == (P = (%x. True))"
   174   Ex_def        "Ex(P)     == P(@x. P(x))"
   175   False_def     "False     == (!P. P)"
   176   not_def       "~ P       == P-->False"
   177   and_def       "P & Q     == !R. (P-->Q-->R) --> R"
   178   or_def        "P | Q     == !R. (P-->R) --> (Q-->R) --> R"
   179   Ex1_def       "Ex1(P)    == ? x. P(x) & (! y. P(y) --> y=x)"
   180 
   181 rules
   182   (* Axioms *)
   183 
   184   iff           "(P-->Q) --> (Q-->P) --> (P=Q)"
   185   True_or_False "(P=True) | (P=False)"
   186 
   187 defs
   188   (*misc definitions*)
   189   Let_def       "Let s f == f(s)"
   190   if_def        "If P x y == @z::'a. (P=True --> z=x) & (P=False --> z=y)"
   191 
   192   (*arbitrary is completely unspecified, but is made to appear as a
   193     definition syntactically*)
   194   arbitrary_def "False ==> arbitrary == (@x. False)"
   195 
   196 
   197 
   198 (** initial HOL theory setup **)
   199 
   200 setup Simplifier.setup
   201 setup ClasetThyData.setup
   202 
   203 
   204 end
   205 
   206 
   207 ML
   208 
   209 
   210 (** Choice between the HOL and Isabelle style of quantifiers **)
   211 
   212 val HOL_quantifiers = ref true;
   213 
   214 fun alt_ast_tr' (name, alt_name) =
   215   let
   216     fun ast_tr' (*name*) args =
   217       if ! HOL_quantifiers then raise Match
   218       else Syntax.mk_appl (Syntax.Constant alt_name) args;
   219   in
   220     (name, ast_tr')
   221   end;
   222 
   223 
   224 val print_ast_translation =
   225   map alt_ast_tr' [("! ", "*All"), ("? ", "*Ex"), ("?! ", "*Ex1")];