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