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