src/CTT/CTT.thy
changeset 0 a5a9c433f639
child 23 1cd377c2f7c6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/CTT/CTT.thy	Thu Sep 16 12:20:38 1993 +0200
     1.3 @@ -0,0 +1,253 @@
     1.4 +(*  Title:      CTT/ctt.thy
     1.5 +    ID:         $Id$
     1.6 +    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     1.7 +    Copyright   1993  University of Cambridge
     1.8 +
     1.9 +Constructive Type Theory
    1.10 +*)
    1.11 +
    1.12 +CTT = Pure +
    1.13 +
    1.14 +types i,t,o 0
    1.15 +
    1.16 +arities i,t,o :: logic
    1.17 +
    1.18 +consts
    1.19 +  (*Types*)
    1.20 +  F,T       :: "t"          (*F is empty, T contains one element*)
    1.21 +  contr     :: "i=>i"
    1.22 +  tt        :: "i"
    1.23 +  (*Natural numbers*)
    1.24 +  N         :: "t"
    1.25 +  succ      :: "i=>i"
    1.26 +  rec       :: "[i, i, [i,i]=>i] => i"
    1.27 +  (*Unions*)
    1.28 +  inl,inr   :: "i=>i"
    1.29 +  when      :: "[i, i=>i, i=>i]=>i"
    1.30 +  (*General Sum and Binary Product*)
    1.31 +  Sum       :: "[t, i=>t]=>t"
    1.32 +  fst,snd   :: "i=>i"
    1.33 +  split     :: "[i, [i,i]=>i] =>i"
    1.34 +  (*General Product and Function Space*)
    1.35 +  Prod      :: "[t, i=>t]=>t"
    1.36 +  (*Equality type*)
    1.37 +  Eq        :: "[t,i,i]=>t"
    1.38 +  eq        :: "i"
    1.39 +  (*Judgements*)
    1.40 +  Type      :: "t => prop"          ("(_ type)" [10] 5)
    1.41 +  Eqtype    :: "[t,t]=>prop"        ("(3_ =/ _)" [10,10] 5)
    1.42 +  Elem      :: "[i, t]=>prop"       ("(_ /: _)" [10,10] 5)
    1.43 +  Eqelem    :: "[i,i,t]=>prop"      ("(3_ =/ _ :/ _)" [10,10,10] 5)
    1.44 +  Reduce    :: "[i,i]=>prop"        ("Reduce[_,_]")
    1.45 +  (*Types*)
    1.46 +  "@PROD"   :: "[id,t,t]=>t"        ("(3PROD _:_./ _)" 10)
    1.47 +  "@SUM"    :: "[id,t,t]=>t"        ("(3SUM _:_./ _)" 10)
    1.48 +  "+"       :: "[t,t]=>t"           (infixr 40)
    1.49 +  (*Invisible infixes!*)
    1.50 +  "@-->"    :: "[t,t]=>t"           ("(_ -->/ _)" [31,30] 30)
    1.51 +  "@*"      :: "[t,t]=>t"           ("(_ */ _)" [51,50] 50)
    1.52 +  (*Functions*)
    1.53 +  lambda    :: "(i => i) => i"      (binder "lam " 10)
    1.54 +  "`"       :: "[i,i]=>i"           (infixl 60)
    1.55 +  (*Natural numbers*)
    1.56 +  "0"       :: "i"                  ("0")
    1.57 +  (*Pairing*)
    1.58 +  pair      :: "[i,i]=>i"           ("(1<_,/_>)")
    1.59 +
    1.60 +translations
    1.61 +  "PROD x:A. B" => "Prod(A, %x. B)"
    1.62 +  "SUM x:A. B"  => "Sum(A, %x. B)"
    1.63 +
    1.64 +rules
    1.65 +
    1.66 +  (*Reduction: a weaker notion than equality;  a hack for simplification.
    1.67 +    Reduce[a,b] means either that  a=b:A  for some A or else that "a" and "b"
    1.68 +    are textually identical.*)
    1.69 +
    1.70 +  (*does not verify a:A!  Sound because only trans_red uses a Reduce premise
    1.71 +    No new theorems can be proved about the standard judgements.*)
    1.72 +  refl_red "Reduce[a,a]"
    1.73 +  red_if_equal "a = b : A ==> Reduce[a,b]"
    1.74 +  trans_red "[| a = b : A;  Reduce[b,c] |] ==> a = c : A"
    1.75 +
    1.76 +  (*Reflexivity*)
    1.77 +
    1.78 +  refl_type "A type ==> A = A"
    1.79 +  refl_elem "a : A ==> a = a : A"
    1.80 +
    1.81 +  (*Symmetry*)
    1.82 +
    1.83 +  sym_type  "A = B ==> B = A"
    1.84 +  sym_elem  "a = b : A ==> b = a : A"
    1.85 +
    1.86 +  (*Transitivity*)
    1.87 +
    1.88 +  trans_type   "[| A = B;  B = C |] ==> A = C"
    1.89 +  trans_elem   "[| a = b : A;  b = c : A |] ==> a = c : A"
    1.90 +
    1.91 +  equal_types  "[| a : A;  A = B |] ==> a : B"
    1.92 +  equal_typesL "[| a = b : A;  A = B |] ==> a = b : B"
    1.93 +
    1.94 +  (*Substitution*)
    1.95 +
    1.96 +  subst_type   "[| a : A;  !!z. z:A ==> B(z) type |] ==> B(a) type"
    1.97 +  subst_typeL  "[| a = c : A;  !!z. z:A ==> B(z) = D(z) |] ==> B(a) = D(c)"
    1.98 +
    1.99 +  subst_elem   "[| a : A;  !!z. z:A ==> b(z):B(z) |] ==> b(a):B(a)"
   1.100 +  subst_elemL
   1.101 +    "[| a=c : A;  !!z. z:A ==> b(z)=d(z) : B(z) |] ==> b(a)=d(c) : B(a)"
   1.102 +
   1.103 +
   1.104 +  (*The type N -- natural numbers*)
   1.105 +
   1.106 +  NF "N type"
   1.107 +  NI0 "0 : N"
   1.108 +  NI_succ "a : N ==> succ(a) : N"
   1.109 +  NI_succL  "a = b : N ==> succ(a) = succ(b) : N"
   1.110 +
   1.111 +  NE
   1.112 +   "[| p: N;  a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] \
   1.113 +\   ==> rec(p, a, %u v.b(u,v)) : C(p)"
   1.114 +
   1.115 +  NEL
   1.116 +   "[| p = q : N;  a = c : C(0);  \
   1.117 +\      !!u v. [| u: N; v: C(u) |] ==> b(u,v) = d(u,v): C(succ(u)) |] \
   1.118 +\   ==> rec(p, a, %u v.b(u,v)) = rec(q,c,d) : C(p)"
   1.119 +
   1.120 +  NC0
   1.121 +   "[| a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] \
   1.122 +\   ==> rec(0, a, %u v.b(u,v)) = a : C(0)"
   1.123 +
   1.124 +  NC_succ
   1.125 +   "[| p: N;  a: C(0);  \
   1.126 +\       !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] ==>  \
   1.127 +\   rec(succ(p), a, %u v.b(u,v)) = b(p, rec(p, a, %u v.b(u,v))) : C(succ(p))"
   1.128 +
   1.129 +  (*The fourth Peano axiom.  See page 91 of Martin-Lof's book*)
   1.130 +  zero_ne_succ
   1.131 +    "[| a: N;  0 = succ(a) : N |] ==> 0: F"
   1.132 +
   1.133 +
   1.134 +  (*The Product of a family of types*)
   1.135 +
   1.136 +  ProdF  "[| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A.B(x) type"
   1.137 +
   1.138 +  ProdFL
   1.139 +   "[| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> \
   1.140 +\   PROD x:A.B(x) = PROD x:C.D(x)"
   1.141 +
   1.142 +  ProdI
   1.143 +   "[| A type;  !!x. x:A ==> b(x):B(x)|] ==> lam x.b(x) : PROD x:A.B(x)"
   1.144 +
   1.145 +  ProdIL
   1.146 +   "[| A type;  !!x. x:A ==> b(x) = c(x) : B(x)|] ==> \
   1.147 +\   lam x.b(x) = lam x.c(x) : PROD x:A.B(x)"
   1.148 +
   1.149 +  ProdE  "[| p : PROD x:A.B(x);  a : A |] ==> p`a : B(a)"
   1.150 +  ProdEL "[| p=q: PROD x:A.B(x);  a=b : A |] ==> p`a = q`b : B(a)"
   1.151 +
   1.152 +  ProdC
   1.153 +   "[| a : A;  !!x. x:A ==> b(x) : B(x)|] ==> \
   1.154 +\   (lam x.b(x)) ` a = b(a) : B(a)"
   1.155 +
   1.156 +  ProdC2
   1.157 +   "p : PROD x:A.B(x) ==> (lam x. p`x) = p : PROD x:A.B(x)"
   1.158 +
   1.159 +
   1.160 +  (*The Sum of a family of types*)
   1.161 +
   1.162 +  SumF  "[| A type;  !!x. x:A ==> B(x) type |] ==> SUM x:A.B(x) type"
   1.163 +  SumFL
   1.164 +    "[| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> SUM x:A.B(x) = SUM x:C.D(x)"
   1.165 +
   1.166 +  SumI  "[| a : A;  b : B(a) |] ==> <a,b> : SUM x:A.B(x)"
   1.167 +  SumIL "[| a=c:A;  b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A.B(x)"
   1.168 +
   1.169 +  SumE
   1.170 +    "[| p: SUM x:A.B(x);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |] \
   1.171 +\    ==> split(p, %x y.c(x,y)) : C(p)"
   1.172 +
   1.173 +  SumEL
   1.174 +    "[| p=q : SUM x:A.B(x); \
   1.175 +\       !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>)|] \
   1.176 +\    ==> split(p, %x y.c(x,y)) = split(q, % x y.d(x,y)) : C(p)"
   1.177 +
   1.178 +  SumC
   1.179 +    "[| a: A;  b: B(a);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |] \
   1.180 +\    ==> split(<a,b>, %x y.c(x,y)) = c(a,b) : C(<a,b>)"
   1.181 +
   1.182 +  fst_def   "fst(a) == split(a, %x y.x)"
   1.183 +  snd_def   "snd(a) == split(a, %x y.y)"
   1.184 +
   1.185 +
   1.186 +  (*The sum of two types*)
   1.187 +
   1.188 +  PlusF   "[| A type;  B type |] ==> A+B type"
   1.189 +  PlusFL  "[| A = C;  B = D |] ==> A+B = C+D"
   1.190 +
   1.191 +  PlusI_inl   "[| a : A;  B type |] ==> inl(a) : A+B"
   1.192 +  PlusI_inlL "[| a = c : A;  B type |] ==> inl(a) = inl(c) : A+B"
   1.193 +
   1.194 +  PlusI_inr   "[| A type;  b : B |] ==> inr(b) : A+B"
   1.195 +  PlusI_inrL "[| A type;  b = d : B |] ==> inr(b) = inr(d) : A+B"
   1.196 +
   1.197 +  PlusE
   1.198 +    "[| p: A+B;  !!x. x:A ==> c(x): C(inl(x));  \
   1.199 +\                !!y. y:B ==> d(y): C(inr(y)) |] \
   1.200 +\    ==> when(p, %x.c(x), %y.d(y)) : C(p)"
   1.201 +
   1.202 +  PlusEL
   1.203 +    "[| p = q : A+B;  !!x. x: A ==> c(x) = e(x) : C(inl(x));   \
   1.204 +\                     !!y. y: B ==> d(y) = f(y) : C(inr(y)) |] \
   1.205 +\    ==> when(p, %x.c(x), %y.d(y)) = when(q, %x.e(x), %y.f(y)) : C(p)"
   1.206 +
   1.207 +  PlusC_inl
   1.208 +    "[| a: A;  !!x. x:A ==> c(x): C(inl(x));  \
   1.209 +\              !!y. y:B ==> d(y): C(inr(y)) |] \
   1.210 +\    ==> when(inl(a), %x.c(x), %y.d(y)) = c(a) : C(inl(a))"
   1.211 +
   1.212 +  PlusC_inr
   1.213 +    "[| b: B;  !!x. x:A ==> c(x): C(inl(x));  \
   1.214 +\              !!y. y:B ==> d(y): C(inr(y)) |] \
   1.215 +\    ==> when(inr(b), %x.c(x), %y.d(y)) = d(b) : C(inr(b))"
   1.216 +
   1.217 +
   1.218 +  (*The type Eq*)
   1.219 +
   1.220 +  EqF    "[| A type;  a : A;  b : A |] ==> Eq(A,a,b) type"
   1.221 +  EqFL "[| A=B;  a=c: A;  b=d : A |] ==> Eq(A,a,b) = Eq(B,c,d)"
   1.222 +  EqI "a = b : A ==> eq : Eq(A,a,b)"
   1.223 +  EqE "p : Eq(A,a,b) ==> a = b : A"
   1.224 +
   1.225 +  (*By equality of types, can prove C(p) from C(eq), an elimination rule*)
   1.226 +  EqC "p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)"
   1.227 +
   1.228 +  (*The type F*)
   1.229 +
   1.230 +  FF "F type"
   1.231 +  FE "[| p: F;  C type |] ==> contr(p) : C"
   1.232 +  FEL  "[| p = q : F;  C type |] ==> contr(p) = contr(q) : C"
   1.233 +
   1.234 +  (*The type T
   1.235 +     Martin-Lof's book (page 68) discusses elimination and computation.
   1.236 +     Elimination can be derived by computation and equality of types,
   1.237 +     but with an extra premise C(x) type x:T.
   1.238 +     Also computation can be derived from elimination. *)
   1.239 +
   1.240 +  TF "T type"
   1.241 +  TI "tt : T"
   1.242 +  TE "[| p : T;  c : C(tt) |] ==> c : C(p)"
   1.243 +  TEL "[| p = q : T;  c = d : C(tt) |] ==> c = d : C(p)"
   1.244 +  TC "p : T ==> p = tt : T"
   1.245 +end
   1.246 +
   1.247 +
   1.248 +ML
   1.249 +
   1.250 +val parse_translation =
   1.251 +  [("@-->", ndependent_tr "Prod"), ("@*", ndependent_tr "Sum")];
   1.252 +
   1.253 +val print_translation =
   1.254 +  [("Prod", dependent_tr' ("@PROD", "@-->")),
   1.255 +   ("Sum", dependent_tr' ("@SUM", "@*"))];
   1.256 +