src/CTT/CTT.thy
author wenzelm
Fri Sep 16 23:01:29 2005 +0200 (2005-09-16)
changeset 17441 5b5feca0344a
parent 14854 61bdf2ae4dc5
child 17782 b3846df9d643
permissions -rw-r--r--
converted to Isar theory format;
     1 (*  Title:      CTT/CTT.thy
     2     ID:         $Id$
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     5 *)
     6 
     7 header {* Constructive Type Theory *}
     8 
     9 theory CTT
    10 imports Pure
    11 begin
    12 
    13 typedecl i
    14 typedecl t
    15 typedecl o
    16 
    17 consts
    18   (*Types*)
    19   F         :: "t"
    20   T         :: "t"          (*F is empty, T contains one element*)
    21   contr     :: "i=>i"
    22   tt        :: "i"
    23   (*Natural numbers*)
    24   N         :: "t"
    25   succ      :: "i=>i"
    26   rec       :: "[i, i, [i,i]=>i] => i"
    27   (*Unions*)
    28   inl       :: "i=>i"
    29   inr       :: "i=>i"
    30   when      :: "[i, i=>i, i=>i]=>i"
    31   (*General Sum and Binary Product*)
    32   Sum       :: "[t, i=>t]=>t"
    33   fst       :: "i=>i"
    34   snd       :: "i=>i"
    35   split     :: "[i, [i,i]=>i] =>i"
    36   (*General Product and Function Space*)
    37   Prod      :: "[t, i=>t]=>t"
    38   (*Types*)
    39   "+"       :: "[t,t]=>t"           (infixr 40)
    40   (*Equality type*)
    41   Eq        :: "[t,i,i]=>t"
    42   eq        :: "i"
    43   (*Judgements*)
    44   Type      :: "t => prop"          ("(_ type)" [10] 5)
    45   Eqtype    :: "[t,t]=>prop"        ("(_ =/ _)" [10,10] 5)
    46   Elem      :: "[i, t]=>prop"       ("(_ /: _)" [10,10] 5)
    47   Eqelem    :: "[i,i,t]=>prop"      ("(_ =/ _ :/ _)" [10,10,10] 5)
    48   Reduce    :: "[i,i]=>prop"        ("Reduce[_,_]")
    49   (*Types*)
    50 
    51   (*Functions*)
    52   lambda    :: "(i => i) => i"      (binder "lam " 10)
    53   "`"       :: "[i,i]=>i"           (infixl 60)
    54   (*Natural numbers*)
    55   "0"       :: "i"                  ("0")
    56   (*Pairing*)
    57   pair      :: "[i,i]=>i"           ("(1<_,/_>)")
    58 
    59 syntax
    60   "@PROD"   :: "[idt,t,t]=>t"       ("(3PROD _:_./ _)" 10)
    61   "@SUM"    :: "[idt,t,t]=>t"       ("(3SUM _:_./ _)" 10)
    62   "@-->"    :: "[t,t]=>t"           ("(_ -->/ _)" [31,30] 30)
    63   "@*"      :: "[t,t]=>t"           ("(_ */ _)" [51,50] 50)
    64 
    65 translations
    66   "PROD x:A. B" => "Prod(A, %x. B)"
    67   "A --> B"     => "Prod(A, _K(B))"
    68   "SUM x:A. B"  => "Sum(A, %x. B)"
    69   "A * B"       => "Sum(A, _K(B))"
    70 
    71 print_translation {*
    72   [("Prod", dependent_tr' ("@PROD", "@-->")),
    73    ("Sum", dependent_tr' ("@SUM", "@*"))]
    74 *}
    75 
    76 
    77 syntax (xsymbols)
    78   "@-->"    :: "[t,t]=>t"           ("(_ \<longrightarrow>/ _)" [31,30] 30)
    79   "@*"      :: "[t,t]=>t"           ("(_ \<times>/ _)"          [51,50] 50)
    80   Elem      :: "[i, t]=>prop"       ("(_ /\<in> _)" [10,10] 5)
    81   Eqelem    :: "[i,i,t]=>prop"      ("(2_ =/ _ \<in>/ _)" [10,10,10] 5)
    82   "@SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
    83   "@PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
    84   "lam "    :: "[idts, i] => i"     ("(3\<lambda>\<lambda>_./ _)" 10)
    85 
    86 syntax (HTML output)
    87   "@*"      :: "[t,t]=>t"           ("(_ \<times>/ _)"          [51,50] 50)
    88   Elem      :: "[i, t]=>prop"       ("(_ /\<in> _)" [10,10] 5)
    89   Eqelem    :: "[i,i,t]=>prop"      ("(2_ =/ _ \<in>/ _)" [10,10,10] 5)
    90   "@SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
    91   "@PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
    92   "lam "    :: "[idts, i] => i"     ("(3\<lambda>\<lambda>_./ _)" 10)
    93 
    94 axioms
    95 
    96   (*Reduction: a weaker notion than equality;  a hack for simplification.
    97     Reduce[a,b] means either that  a=b:A  for some A or else that "a" and "b"
    98     are textually identical.*)
    99 
   100   (*does not verify a:A!  Sound because only trans_red uses a Reduce premise
   101     No new theorems can be proved about the standard judgements.*)
   102   refl_red: "Reduce[a,a]"
   103   red_if_equal: "a = b : A ==> Reduce[a,b]"
   104   trans_red: "[| a = b : A;  Reduce[b,c] |] ==> a = c : A"
   105 
   106   (*Reflexivity*)
   107 
   108   refl_type: "A type ==> A = A"
   109   refl_elem: "a : A ==> a = a : A"
   110 
   111   (*Symmetry*)
   112 
   113   sym_type:  "A = B ==> B = A"
   114   sym_elem:  "a = b : A ==> b = a : A"
   115 
   116   (*Transitivity*)
   117 
   118   trans_type:   "[| A = B;  B = C |] ==> A = C"
   119   trans_elem:   "[| a = b : A;  b = c : A |] ==> a = c : A"
   120 
   121   equal_types:  "[| a : A;  A = B |] ==> a : B"
   122   equal_typesL: "[| a = b : A;  A = B |] ==> a = b : B"
   123 
   124   (*Substitution*)
   125 
   126   subst_type:   "[| a : A;  !!z. z:A ==> B(z) type |] ==> B(a) type"
   127   subst_typeL:  "[| a = c : A;  !!z. z:A ==> B(z) = D(z) |] ==> B(a) = D(c)"
   128 
   129   subst_elem:   "[| a : A;  !!z. z:A ==> b(z):B(z) |] ==> b(a):B(a)"
   130   subst_elemL:
   131     "[| a=c : A;  !!z. z:A ==> b(z)=d(z) : B(z) |] ==> b(a)=d(c) : B(a)"
   132 
   133 
   134   (*The type N -- natural numbers*)
   135 
   136   NF: "N type"
   137   NI0: "0 : N"
   138   NI_succ: "a : N ==> succ(a) : N"
   139   NI_succL:  "a = b : N ==> succ(a) = succ(b) : N"
   140 
   141   NE:
   142    "[| p: N;  a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
   143    ==> rec(p, a, %u v. b(u,v)) : C(p)"
   144 
   145   NEL:
   146    "[| p = q : N;  a = c : C(0);
   147       !!u v. [| u: N; v: C(u) |] ==> b(u,v) = d(u,v): C(succ(u)) |]
   148    ==> rec(p, a, %u v. b(u,v)) = rec(q,c,d) : C(p)"
   149 
   150   NC0:
   151    "[| a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
   152    ==> rec(0, a, %u v. b(u,v)) = a : C(0)"
   153 
   154   NC_succ:
   155    "[| p: N;  a: C(0);
   156        !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] ==>
   157    rec(succ(p), a, %u v. b(u,v)) = b(p, rec(p, a, %u v. b(u,v))) : C(succ(p))"
   158 
   159   (*The fourth Peano axiom.  See page 91 of Martin-Lof's book*)
   160   zero_ne_succ:
   161     "[| a: N;  0 = succ(a) : N |] ==> 0: F"
   162 
   163 
   164   (*The Product of a family of types*)
   165 
   166   ProdF:  "[| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A. B(x) type"
   167 
   168   ProdFL:
   169    "[| A = C;  !!x. x:A ==> B(x) = D(x) |] ==>
   170    PROD x:A. B(x) = PROD x:C. D(x)"
   171 
   172   ProdI:
   173    "[| A type;  !!x. x:A ==> b(x):B(x)|] ==> lam x. b(x) : PROD x:A. B(x)"
   174 
   175   ProdIL:
   176    "[| A type;  !!x. x:A ==> b(x) = c(x) : B(x)|] ==>
   177    lam x. b(x) = lam x. c(x) : PROD x:A. B(x)"
   178 
   179   ProdE:  "[| p : PROD x:A. B(x);  a : A |] ==> p`a : B(a)"
   180   ProdEL: "[| p=q: PROD x:A. B(x);  a=b : A |] ==> p`a = q`b : B(a)"
   181 
   182   ProdC:
   183    "[| a : A;  !!x. x:A ==> b(x) : B(x)|] ==>
   184    (lam x. b(x)) ` a = b(a) : B(a)"
   185 
   186   ProdC2:
   187    "p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x)"
   188 
   189 
   190   (*The Sum of a family of types*)
   191 
   192   SumF:  "[| A type;  !!x. x:A ==> B(x) type |] ==> SUM x:A. B(x) type"
   193   SumFL:
   194     "[| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> SUM x:A. B(x) = SUM x:C. D(x)"
   195 
   196   SumI:  "[| a : A;  b : B(a) |] ==> <a,b> : SUM x:A. B(x)"
   197   SumIL: "[| a=c:A;  b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A. B(x)"
   198 
   199   SumE:
   200     "[| p: SUM x:A. B(x);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
   201     ==> split(p, %x y. c(x,y)) : C(p)"
   202 
   203   SumEL:
   204     "[| p=q : SUM x:A. B(x);
   205        !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>)|]
   206     ==> split(p, %x y. c(x,y)) = split(q, % x y. d(x,y)) : C(p)"
   207 
   208   SumC:
   209     "[| a: A;  b: B(a);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
   210     ==> split(<a,b>, %x y. c(x,y)) = c(a,b) : C(<a,b>)"
   211 
   212   fst_def:   "fst(a) == split(a, %x y. x)"
   213   snd_def:   "snd(a) == split(a, %x y. y)"
   214 
   215 
   216   (*The sum of two types*)
   217 
   218   PlusF:   "[| A type;  B type |] ==> A+B type"
   219   PlusFL:  "[| A = C;  B = D |] ==> A+B = C+D"
   220 
   221   PlusI_inl:   "[| a : A;  B type |] ==> inl(a) : A+B"
   222   PlusI_inlL: "[| a = c : A;  B type |] ==> inl(a) = inl(c) : A+B"
   223 
   224   PlusI_inr:   "[| A type;  b : B |] ==> inr(b) : A+B"
   225   PlusI_inrL: "[| A type;  b = d : B |] ==> inr(b) = inr(d) : A+B"
   226 
   227   PlusE:
   228     "[| p: A+B;  !!x. x:A ==> c(x): C(inl(x));
   229                 !!y. y:B ==> d(y): C(inr(y)) |]
   230     ==> when(p, %x. c(x), %y. d(y)) : C(p)"
   231 
   232   PlusEL:
   233     "[| p = q : A+B;  !!x. x: A ==> c(x) = e(x) : C(inl(x));
   234                      !!y. y: B ==> d(y) = f(y) : C(inr(y)) |]
   235     ==> when(p, %x. c(x), %y. d(y)) = when(q, %x. e(x), %y. f(y)) : C(p)"
   236 
   237   PlusC_inl:
   238     "[| a: A;  !!x. x:A ==> c(x): C(inl(x));
   239               !!y. y:B ==> d(y): C(inr(y)) |]
   240     ==> when(inl(a), %x. c(x), %y. d(y)) = c(a) : C(inl(a))"
   241 
   242   PlusC_inr:
   243     "[| b: B;  !!x. x:A ==> c(x): C(inl(x));
   244               !!y. y:B ==> d(y): C(inr(y)) |]
   245     ==> when(inr(b), %x. c(x), %y. d(y)) = d(b) : C(inr(b))"
   246 
   247 
   248   (*The type Eq*)
   249 
   250   EqF:    "[| A type;  a : A;  b : A |] ==> Eq(A,a,b) type"
   251   EqFL: "[| A=B;  a=c: A;  b=d : A |] ==> Eq(A,a,b) = Eq(B,c,d)"
   252   EqI: "a = b : A ==> eq : Eq(A,a,b)"
   253   EqE: "p : Eq(A,a,b) ==> a = b : A"
   254 
   255   (*By equality of types, can prove C(p) from C(eq), an elimination rule*)
   256   EqC: "p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)"
   257 
   258   (*The type F*)
   259 
   260   FF: "F type"
   261   FE: "[| p: F;  C type |] ==> contr(p) : C"
   262   FEL:  "[| p = q : F;  C type |] ==> contr(p) = contr(q) : C"
   263 
   264   (*The type T
   265      Martin-Lof's book (page 68) discusses elimination and computation.
   266      Elimination can be derived by computation and equality of types,
   267      but with an extra premise C(x) type x:T.
   268      Also computation can be derived from elimination. *)
   269 
   270   TF: "T type"
   271   TI: "tt : T"
   272   TE: "[| p : T;  c : C(tt) |] ==> c : C(p)"
   273   TEL: "[| p = q : T;  c = d : C(tt) |] ==> c = d : C(p)"
   274   TC: "p : T ==> p = tt : T"
   275 
   276 ML {* use_legacy_bindings (the_context ()) *}
   277 
   278 end