doc-src/Logics/CTT-eg.txt
author wenzelm
Wed Jul 25 12:38:54 2012 +0200 (2012-07-25)
changeset 48497 ba61aceaa18a
parent 5151 1e944fe5ce96
permissions -rw-r--r--
some updates on "Building a repository version of Isabelle";
lcp@104
     1
(**** CTT examples -- process using Doc/tout CTT-eg.txt  ****)
lcp@104
     2
lcp@104
     3
Pretty.setmargin 72;  (*existing macros just allow this margin*)
lcp@104
     4
print_depth 0;
lcp@104
     5
lcp@104
     6
lcp@104
     7
(*** Type inference, from CTT/ex/typechk.ML ***)
lcp@104
     8
paulson@5151
     9
Goal "lam n. rec(n, 0, %x y. x) : ?A";
lcp@104
    10
by (resolve_tac [ProdI] 1);
lcp@104
    11
by (eresolve_tac [NE] 2);
lcp@104
    12
by (resolve_tac [NI0] 2);
lcp@104
    13
by (assume_tac 2);
lcp@104
    14
by (resolve_tac [NF] 1);
lcp@104
    15
lcp@104
    16
lcp@104
    17
lcp@104
    18
(*** Logical reasoning, from CTT/ex/elim.ML ***)
lcp@104
    19
paulson@5151
    20
val prems = Goal
lcp@104
    21
    "[| A type;  \
lcp@104
    22
\       !!x. x:A ==> B(x) type;       \
lcp@104
    23
\       !!x. x:A ==> C(x) type;       \
lcp@104
    24
\       p: SUM x:A. B(x) + C(x)       \
lcp@104
    25
\    |] ==>  ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))";
lcp@104
    26
by (resolve_tac (prems RL [SumE]) 1);
lcp@104
    27
by (eresolve_tac [PlusE] 1);
lcp@104
    28
by (resolve_tac [PlusI_inl] 1);
lcp@104
    29
by (resolve_tac [SumI] 1);
lcp@104
    30
by (assume_tac 1);
lcp@104
    31
by (assume_tac 1);
lcp@104
    32
by (typechk_tac prems);
lcp@104
    33
by (pc_tac prems 1);
lcp@104
    34
lcp@104
    35
lcp@104
    36
(*** Currying, from CTT/ex/elim.ML ***)
lcp@104
    37
paulson@5151
    38
val prems = Goal
paulson@5151
    39
    "[| A type; !!x. x:A ==> B(x) type;                         \
paulson@5151
    40
\               !!z. z: (SUM x:A. B(x)) ==> C(z) type           \
paulson@5151
    41
\    |] ==> ?a : PROD f: (PROD z : (SUM x:A . B(x)) . C(z)).    \
lcp@359
    42
\                     (PROD x:A . PROD y:B(x) . C(<x,y>))";
lcp@104
    43
by (intr_tac prems);
lcp@104
    44
by (eresolve_tac [ProdE] 1);
lcp@104
    45
by (intr_tac prems);
lcp@104
    46
lcp@104
    47
lcp@104
    48
(*** Axiom of Choice ***)
lcp@104
    49
paulson@5151
    50
val prems = Goal   
lcp@104
    51
    "[| A type;  !!x. x:A ==> B(x) type;  \
lcp@104
    52
\       !!x y.[| x:A;  y:B(x) |] ==> C(x,y) type  \
lcp@359
    53
\    |] ==> ?a : PROD h: (PROD x:A. SUM y:B(x). C(x,y)).    \
lcp@359
    54
\                        (SUM f: (PROD x:A. B(x)). PROD x:A. C(x, f`x))";
lcp@104
    55
by (intr_tac prems);
lcp@104
    56
by (eresolve_tac [ProdE RS SumE_fst] 1);
lcp@104
    57
by (assume_tac 1);
lcp@104
    58
by (resolve_tac [replace_type] 1);
lcp@104
    59
by (resolve_tac [subst_eqtyparg] 1);
lcp@104
    60
by (resolve_tac [ProdC] 1);
lcp@104
    61
by (typechk_tac (SumE_fst::prems));
lcp@104
    62
by (eresolve_tac [ProdE RS SumE_snd] 1);
lcp@104
    63
by (typechk_tac prems);
lcp@104
    64
lcp@104
    65
lcp@104
    66
lcp@104
    67
paulson@5151
    68
paulson@5151
    69
STOP_HERE;
lcp@104
    70
lcp@104
    71
paulson@5151
    72
> val prems = Goal
lcp@104
    73
#     "[| A type;  \
lcp@104
    74
# \       !!x. x:A ==> B(x) type;       \
lcp@104
    75
# \       !!x. x:A ==> C(x) type;       \
lcp@104
    76
# \       p: SUM x:A. B(x) + C(x)       \
lcp@104
    77
# \    |] ==>  ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))";
lcp@104
    78
Level 0
lcp@104
    79
?a : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    80
 1. ?a : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    81
> by (resolve_tac (prems RL [SumE]) 1);
lcp@104
    82
Level 1
lcp@104
    83
split(p,?c1) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    84
 1. !!x y.
lcp@104
    85
       [| x : A; y : B(x) + C(x) |] ==>
lcp@104
    86
       ?c1(x,y) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    87
> by (eresolve_tac [PlusE] 1);
lcp@104
    88
Level 2
lcp@104
    89
split(p,%x y. when(y,?c2(x,y),?d2(x,y)))
lcp@104
    90
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    91
 1. !!x y xa.
lcp@104
    92
       [| x : A; xa : B(x) |] ==>
lcp@104
    93
       ?c2(x,y,xa) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    94
 2. !!x y ya.
lcp@104
    95
       [| x : A; ya : C(x) |] ==>
lcp@104
    96
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
    97
> by (resolve_tac [PlusI_inl] 1);
lcp@104
    98
Level 3
lcp@104
    99
split(p,%x y. when(y,%xa. inl(?a3(x,y,xa)),?d2(x,y)))
lcp@104
   100
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   101
 1. !!x y xa. [| x : A; xa : B(x) |] ==> ?a3(x,y,xa) : SUM x:A. B(x)
lcp@104
   102
 2. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type
lcp@104
   103
 3. !!x y ya.
lcp@104
   104
       [| x : A; ya : C(x) |] ==>
lcp@104
   105
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   106
> by (resolve_tac [SumI] 1);
lcp@104
   107
Level 4
lcp@104
   108
split(p,%x y. when(y,%xa. inl(<?a4(x,y,xa),?b4(x,y,xa)>),?d2(x,y)))
lcp@104
   109
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   110
 1. !!x y xa. [| x : A; xa : B(x) |] ==> ?a4(x,y,xa) : A
lcp@104
   111
 2. !!x y xa. [| x : A; xa : B(x) |] ==> ?b4(x,y,xa) : B(?a4(x,y,xa))
lcp@104
   112
 3. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type
lcp@104
   113
 4. !!x y ya.
lcp@104
   114
       [| x : A; ya : C(x) |] ==>
lcp@104
   115
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   116
> by (assume_tac 1);
lcp@104
   117
Level 5
lcp@104
   118
split(p,%x y. when(y,%xa. inl(<x,?b4(x,y,xa)>),?d2(x,y)))
lcp@104
   119
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   120
 1. !!x y xa. [| x : A; xa : B(x) |] ==> ?b4(x,y,xa) : B(x)
lcp@104
   121
 2. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type
lcp@104
   122
 3. !!x y ya.
lcp@104
   123
       [| x : A; ya : C(x) |] ==>
lcp@104
   124
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   125
> by (assume_tac 1);
lcp@104
   126
Level 6
lcp@104
   127
split(p,%x y. when(y,%xa. inl(<x,xa>),?d2(x,y)))
lcp@104
   128
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   129
 1. !!x y xa. [| x : A; xa : B(x) |] ==> SUM x:A. C(x) type
lcp@104
   130
 2. !!x y ya.
lcp@104
   131
       [| x : A; ya : C(x) |] ==>
lcp@104
   132
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   133
> by (typechk_tac prems);
lcp@104
   134
Level 7
lcp@104
   135
split(p,%x y. when(y,%xa. inl(<x,xa>),?d2(x,y)))
lcp@104
   136
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   137
 1. !!x y ya.
lcp@104
   138
       [| x : A; ya : C(x) |] ==>
lcp@104
   139
       ?d2(x,y,ya) : (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   140
> by (pc_tac prems 1);
lcp@104
   141
Level 8
lcp@104
   142
split(p,%x y. when(y,%xa. inl(<x,xa>),%y. inr(<x,y>)))
lcp@104
   143
: (SUM x:A. B(x)) + (SUM x:A. C(x))
lcp@104
   144
No subgoals!
lcp@104
   145
lcp@104
   146
lcp@104
   147
lcp@104
   148
paulson@5151
   149
> val prems = Goal
lcp@104
   150
#     "[| A type; !!x. x:A ==> B(x) type; \
lcp@104
   151
# \               !!z. z: (SUM x:A. B(x)) ==> C(z) type |] \
lcp@104
   152
# \    ==> ?a : (PROD z : (SUM x:A . B(x)) . C(z)) \
lcp@104
   153
# \         --> (PROD x:A . PROD y:B(x) . C(<x,y>))";
lcp@104
   154
Level 0
lcp@104
   155
?a : (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))
lcp@104
   156
 1. ?a : (PROD z:SUM x:A. B(x). C(z)) -->
lcp@104
   157
         (PROD x:A. PROD y:B(x). C(<x,y>))
lcp@104
   158
> by (intr_tac prems);
lcp@104
   159
Level 1
lcp@104
   160
lam x xa xb. ?b7(x,xa,xb)
lcp@104
   161
: (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))
lcp@104
   162
 1. !!uu x y.
lcp@104
   163
       [| uu : PROD z:SUM x:A. B(x). C(z); x : A; y : B(x) |] ==>
lcp@104
   164
       ?b7(uu,x,y) : C(<x,y>)
lcp@104
   165
> by (eresolve_tac [ProdE] 1);
lcp@104
   166
Level 2
lcp@104
   167
lam x xa xb. x ` <xa,xb>
lcp@104
   168
: (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))
lcp@104
   169
 1. !!uu x y. [| x : A; y : B(x) |] ==> <x,y> : SUM x:A. B(x)
lcp@104
   170
> by (intr_tac prems);
lcp@104
   171
Level 3
lcp@104
   172
lam x xa xb. x ` <xa,xb>
lcp@104
   173
: (PROD z:SUM x:A. B(x). C(z)) --> (PROD x:A. PROD y:B(x). C(<x,y>))
lcp@104
   174
No subgoals!
lcp@104
   175
lcp@104
   176
lcp@104
   177
lcp@104
   178
paulson@5151
   179
> val prems = Goal
lcp@104
   180
#     "[| A type;  !!x. x:A ==> B(x) type;  \
lcp@104
   181
# \       !!x y.[| x:A;  y:B(x) |] ==> C(x,y) type  \
lcp@104
   182
# \    |] ==> ?a :    (PROD x:A. SUM y:B(x). C(x,y))    \
lcp@104
   183
# \               --> (SUM f: (PROD x:A. B(x)). PROD x:A. C(x, f`x))";
lcp@104
   184
Level 0
lcp@104
   185
?a : (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   186
     (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   187
 1. ?a : (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   188
         (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   189
> by (intr_tac prems);
lcp@104
   190
Level 1
lcp@104
   191
lam x. <lam xa. ?b7(x,xa),lam xa. ?b8(x,xa)>
lcp@104
   192
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   193
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   194
 1. !!uu x.
lcp@104
   195
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   196
       ?b7(uu,x) : B(x)
lcp@104
   197
 2. !!uu x.
lcp@104
   198
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   199
       ?b8(uu,x) : C(x,(lam x. ?b7(uu,x)) ` x)
lcp@104
   200
> by (eresolve_tac [ProdE RS SumE_fst] 1);
lcp@104
   201
Level 2
lcp@104
   202
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   203
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   204
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   205
 1. !!uu x. x : A ==> x : A
lcp@104
   206
 2. !!uu x.
lcp@104
   207
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   208
       ?b8(uu,x) : C(x,(lam x. fst(uu ` x)) ` x)
lcp@104
   209
> by (assume_tac 1);
lcp@104
   210
Level 3
lcp@104
   211
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   212
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   213
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   214
 1. !!uu x.
lcp@104
   215
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   216
       ?b8(uu,x) : C(x,(lam x. fst(uu ` x)) ` x)
lcp@104
   217
> by (resolve_tac [replace_type] 1);
lcp@104
   218
Level 4
lcp@104
   219
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   220
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   221
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   222
 1. !!uu x.
lcp@104
   223
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   224
       C(x,(lam x. fst(uu ` x)) ` x) = ?A13(uu,x)
lcp@104
   225
 2. !!uu x.
lcp@104
   226
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   227
       ?b8(uu,x) : ?A13(uu,x)
lcp@104
   228
> by (resolve_tac [subst_eqtyparg] 1);
lcp@104
   229
Level 5
lcp@104
   230
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   231
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   232
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   233
 1. !!uu x.
lcp@104
   234
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   235
       (lam x. fst(uu ` x)) ` x = ?c14(uu,x) : ?A14(uu,x)
lcp@104
   236
 2. !!uu x z.
lcp@104
   237
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A;
lcp@104
   238
          z : ?A14(uu,x) |] ==>
lcp@104
   239
       C(x,z) type
lcp@104
   240
 3. !!uu x.
lcp@104
   241
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   242
       ?b8(uu,x) : C(x,?c14(uu,x))
lcp@104
   243
> by (resolve_tac [ProdC] 1);
lcp@104
   244
Level 6
lcp@104
   245
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   246
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   247
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   248
 1. !!uu x.
lcp@104
   249
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==> x : ?A15(uu,x)
lcp@104
   250
 2. !!uu x xa.
lcp@104
   251
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A;
lcp@104
   252
          xa : ?A15(uu,x) |] ==>
lcp@104
   253
       fst(uu ` xa) : ?B15(uu,x,xa)
lcp@104
   254
 3. !!uu x z.
lcp@104
   255
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A;
lcp@104
   256
          z : ?B15(uu,x,x) |] ==>
lcp@104
   257
       C(x,z) type
lcp@104
   258
 4. !!uu x.
lcp@104
   259
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   260
       ?b8(uu,x) : C(x,fst(uu ` x))
lcp@104
   261
> by (typechk_tac (SumE_fst::prems));
lcp@104
   262
Level 7
lcp@104
   263
lam x. <lam xa. fst(x ` xa),lam xa. ?b8(x,xa)>
lcp@104
   264
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   265
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   266
 1. !!uu x.
lcp@104
   267
       [| uu : PROD x:A. SUM y:B(x). C(x,y); x : A |] ==>
lcp@104
   268
       ?b8(uu,x) : C(x,fst(uu ` x))
lcp@104
   269
> by (eresolve_tac [ProdE RS SumE_snd] 1);
lcp@104
   270
Level 8
lcp@104
   271
lam x. <lam xa. fst(x ` xa),lam xa. snd(x ` xa)>
lcp@104
   272
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   273
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   274
 1. !!uu x. x : A ==> x : A
lcp@104
   275
 2. !!uu x. x : A ==> B(x) type
lcp@104
   276
 3. !!uu x xa. [| x : A; xa : B(x) |] ==> C(x,xa) type
lcp@104
   277
> by (typechk_tac prems);
lcp@104
   278
Level 9
lcp@104
   279
lam x. <lam xa. fst(x ` xa),lam xa. snd(x ` xa)>
lcp@104
   280
: (PROD x:A. SUM y:B(x). C(x,y)) -->
lcp@104
   281
  (SUM f:PROD x:A. B(x). PROD x:A. C(x,f ` x))
lcp@104
   282
No subgoals!