src/CTT/CTT.thy
author wenzelm
Thu, 28 Feb 2013 14:10:54 +0100
changeset 52445 51e158e988a5
parent 49906 c0eafbd55de3
child 57592 2c9f841f36b8
permissions -rw-r--r--
eliminated legacy 'axioms';
     1 (*  Title:      CTT/CTT.thy
     2     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Copyright   1993  University of Cambridge
     4 *)
     5 
     6 header {* Constructive Type Theory *}
     7 
     8 theory CTT
     9 imports Pure
    10 begin
    11 
    12 ML_file "~~/src/Provers/typedsimp.ML"
    13 setup Pure_Thy.old_appl_syntax_setup
    14 
    15 typedecl i
    16 typedecl t
    17 typedecl o
    18 
    19 consts
    20   (*Types*)
    21   F         :: "t"
    22   T         :: "t"          (*F is empty, T contains one element*)
    23   contr     :: "i=>i"
    24   tt        :: "i"
    25   (*Natural numbers*)
    26   N         :: "t"
    27   succ      :: "i=>i"
    28   rec       :: "[i, i, [i,i]=>i] => i"
    29   (*Unions*)
    30   inl       :: "i=>i"
    31   inr       :: "i=>i"
    32   when      :: "[i, i=>i, i=>i]=>i"
    33   (*General Sum and Binary Product*)
    34   Sum       :: "[t, i=>t]=>t"
    35   fst       :: "i=>i"
    36   snd       :: "i=>i"
    37   split     :: "[i, [i,i]=>i] =>i"
    38   (*General Product and Function Space*)
    39   Prod      :: "[t, i=>t]=>t"
    40   (*Types*)
    41   Plus      :: "[t,t]=>t"           (infixr "+" 40)
    42   (*Equality type*)
    43   Eq        :: "[t,i,i]=>t"
    44   eq        :: "i"
    45   (*Judgements*)
    46   Type      :: "t => prop"          ("(_ type)" [10] 5)
    47   Eqtype    :: "[t,t]=>prop"        ("(_ =/ _)" [10,10] 5)
    48   Elem      :: "[i, t]=>prop"       ("(_ /: _)" [10,10] 5)
    49   Eqelem    :: "[i,i,t]=>prop"      ("(_ =/ _ :/ _)" [10,10,10] 5)
    50   Reduce    :: "[i,i]=>prop"        ("Reduce[_,_]")
    51   (*Types*)
    52 
    53   (*Functions*)
    54   lambda    :: "(i => i) => i"      (binder "lam " 10)
    55   app       :: "[i,i]=>i"           (infixl "`" 60)
    56   (*Natural numbers*)
    57   Zero      :: "i"                  ("0")
    58   (*Pairing*)
    59   pair      :: "[i,i]=>i"           ("(1<_,/_>)")
    60 
    61 syntax
    62   "_PROD"   :: "[idt,t,t]=>t"       ("(3PROD _:_./ _)" 10)
    63   "_SUM"    :: "[idt,t,t]=>t"       ("(3SUM _:_./ _)" 10)
    64 translations
    65   "PROD x:A. B" == "CONST Prod(A, %x. B)"
    66   "SUM x:A. B"  == "CONST Sum(A, %x. B)"
    67 
    68 abbreviation
    69   Arrow     :: "[t,t]=>t"  (infixr "-->" 30) where
    70   "A --> B == PROD _:A. B"
    71 abbreviation
    72   Times     :: "[t,t]=>t"  (infixr "*" 50) where
    73   "A * B == SUM _:A. B"
    74 
    75 notation (xsymbols)
    76   lambda  (binder "\<lambda>\<lambda>" 10) and
    77   Elem  ("(_ /\<in> _)" [10,10] 5) and
    78   Eqelem  ("(2_ =/ _ \<in>/ _)" [10,10,10] 5) and
    79   Arrow  (infixr "\<longrightarrow>" 30) and
    80   Times  (infixr "\<times>" 50)
    81 
    82 notation (HTML output)
    83   lambda  (binder "\<lambda>\<lambda>" 10) and
    84   Elem  ("(_ /\<in> _)" [10,10] 5) and
    85   Eqelem  ("(2_ =/ _ \<in>/ _)" [10,10,10] 5) and
    86   Times  (infixr "\<times>" 50)
    87 
    88 syntax (xsymbols)
    89   "_PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
    90   "_SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
    91 
    92 syntax (HTML output)
    93   "_PROD"   :: "[idt,t,t] => t"     ("(3\<Pi> _\<in>_./ _)"    10)
    94   "_SUM"    :: "[idt,t,t] => t"     ("(3\<Sigma> _\<in>_./ _)" 10)
    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 axiomatization where
   103   refl_red: "\<And>a. Reduce[a,a]" and
   104   red_if_equal: "\<And>a b A. a = b : A ==> Reduce[a,b]" and
   105   trans_red: "\<And>a b c A. [| a = b : A;  Reduce[b,c] |] ==> a = c : A" and
   106 
   107   (*Reflexivity*)
   108 
   109   refl_type: "\<And>A. A type ==> A = A" and
   110   refl_elem: "\<And>a A. a : A ==> a = a : A" and
   111 
   112   (*Symmetry*)
   113 
   114   sym_type:  "\<And>A B. A = B ==> B = A" and
   115   sym_elem:  "\<And>a b A. a = b : A ==> b = a : A" and
   116 
   117   (*Transitivity*)
   118 
   119   trans_type:   "\<And>A B C. [| A = B;  B = C |] ==> A = C" and
   120   trans_elem:   "\<And>a b c A. [| a = b : A;  b = c : A |] ==> a = c : A" and
   121 
   122   equal_types:  "\<And>a A B. [| a : A;  A = B |] ==> a : B" and
   123   equal_typesL: "\<And>a b A B. [| a = b : A;  A = B |] ==> a = b : B" and
   124 
   125   (*Substitution*)
   126 
   127   subst_type:   "\<And>a A B. [| a : A;  !!z. z:A ==> B(z) type |] ==> B(a) type" and
   128   subst_typeL:  "\<And>a c A B D. [| a = c : A;  !!z. z:A ==> B(z) = D(z) |] ==> B(a) = D(c)" and
   129 
   130   subst_elem:   "\<And>a b A B. [| a : A;  !!z. z:A ==> b(z):B(z) |] ==> b(a):B(a)" and
   131   subst_elemL:
   132     "\<And>a b c d A B. [| a=c : A;  !!z. z:A ==> b(z)=d(z) : B(z) |] ==> b(a)=d(c) : B(a)" and
   133 
   134 
   135   (*The type N -- natural numbers*)
   136 
   137   NF: "N type" and
   138   NI0: "0 : N" and
   139   NI_succ: "\<And>a. a : N ==> succ(a) : N" and
   140   NI_succL:  "\<And>a b. a = b : N ==> succ(a) = succ(b) : N" and
   141 
   142   NE:
   143    "\<And>p a b C. [| p: N;  a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
   144    ==> rec(p, a, %u v. b(u,v)) : C(p)" and
   145 
   146   NEL:
   147    "\<And>p q a b c d C. [| p = q : N;  a = c : C(0);
   148       !!u v. [| u: N; v: C(u) |] ==> b(u,v) = d(u,v): C(succ(u)) |]
   149    ==> rec(p, a, %u v. b(u,v)) = rec(q,c,d) : C(p)" and
   150 
   151   NC0:
   152    "\<And>a b C. [| a: C(0);  !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |]
   153    ==> rec(0, a, %u v. b(u,v)) = a : C(0)" and
   154 
   155   NC_succ:
   156    "\<And>p a b C. [| p: N;  a: C(0);
   157        !!u v. [| u: N; v: C(u) |] ==> b(u,v): C(succ(u)) |] ==>
   158    rec(succ(p), a, %u v. b(u,v)) = b(p, rec(p, a, %u v. b(u,v))) : C(succ(p))" and
   159 
   160   (*The fourth Peano axiom.  See page 91 of Martin-Lof's book*)
   161   zero_ne_succ:
   162     "\<And>a. [| a: N;  0 = succ(a) : N |] ==> 0: F" and
   163 
   164 
   165   (*The Product of a family of types*)
   166 
   167   ProdF:  "\<And>A B. [| A type; !!x. x:A ==> B(x) type |] ==> PROD x:A. B(x) type" and
   168 
   169   ProdFL:
   170    "\<And>A B C D. [| A = C;  !!x. x:A ==> B(x) = D(x) |] ==>
   171    PROD x:A. B(x) = PROD x:C. D(x)" and
   172 
   173   ProdI:
   174    "\<And>b A B. [| A type;  !!x. x:A ==> b(x):B(x)|] ==> lam x. b(x) : PROD x:A. B(x)" and
   175 
   176   ProdIL:
   177    "\<And>b c A B. [| A type;  !!x. x:A ==> b(x) = c(x) : B(x)|] ==>
   178    lam x. b(x) = lam x. c(x) : PROD x:A. B(x)" and
   179 
   180   ProdE:  "\<And>p a A B. [| p : PROD x:A. B(x);  a : A |] ==> p`a : B(a)" and
   181   ProdEL: "\<And>p q a b A B. [| p=q: PROD x:A. B(x);  a=b : A |] ==> p`a = q`b : B(a)" and
   182 
   183   ProdC:
   184    "\<And>a b A B. [| a : A;  !!x. x:A ==> b(x) : B(x)|] ==>
   185    (lam x. b(x)) ` a = b(a) : B(a)" and
   186 
   187   ProdC2:
   188    "\<And>p A B. p : PROD x:A. B(x) ==> (lam x. p`x) = p : PROD x:A. B(x)" and
   189 
   190 
   191   (*The Sum of a family of types*)
   192 
   193   SumF:  "\<And>A B. [| A type;  !!x. x:A ==> B(x) type |] ==> SUM x:A. B(x) type" and
   194   SumFL:
   195     "\<And>A B C D. [| A = C;  !!x. x:A ==> B(x) = D(x) |] ==> SUM x:A. B(x) = SUM x:C. D(x)" and
   196 
   197   SumI:  "\<And>a b A B. [| a : A;  b : B(a) |] ==> <a,b> : SUM x:A. B(x)" and
   198   SumIL: "\<And>a b c d A B. [| a=c:A;  b=d:B(a) |] ==> <a,b> = <c,d> : SUM x:A. B(x)" and
   199 
   200   SumE:
   201     "\<And>p c A B C. [| p: SUM x:A. B(x);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
   202     ==> split(p, %x y. c(x,y)) : C(p)" and
   203 
   204   SumEL:
   205     "\<And>p q c d A B C. [| p=q : SUM x:A. B(x);
   206        !!x y. [| x:A; y:B(x) |] ==> c(x,y)=d(x,y): C(<x,y>)|]
   207     ==> split(p, %x y. c(x,y)) = split(q, % x y. d(x,y)) : C(p)" and
   208 
   209   SumC:
   210     "\<And>a b c A B C. [| a: A;  b: B(a);  !!x y. [| x:A; y:B(x) |] ==> c(x,y): C(<x,y>) |]
   211     ==> split(<a,b>, %x y. c(x,y)) = c(a,b) : C(<a,b>)" and
   212 
   213   fst_def:   "\<And>a. fst(a) == split(a, %x y. x)" and
   214   snd_def:   "\<And>a. snd(a) == split(a, %x y. y)" and
   215 
   216 
   217   (*The sum of two types*)
   218 
   219   PlusF:   "\<And>A B. [| A type;  B type |] ==> A+B type" and
   220   PlusFL:  "\<And>A B C D. [| A = C;  B = D |] ==> A+B = C+D" and
   221 
   222   PlusI_inl:   "\<And>a A B. [| a : A;  B type |] ==> inl(a) : A+B" and
   223   PlusI_inlL: "\<And>a c A B. [| a = c : A;  B type |] ==> inl(a) = inl(c) : A+B" and
   224 
   225   PlusI_inr:   "\<And>b A B. [| A type;  b : B |] ==> inr(b) : A+B" and
   226   PlusI_inrL: "\<And>b d A B. [| A type;  b = d : B |] ==> inr(b) = inr(d) : A+B" and
   227 
   228   PlusE:
   229     "\<And>p c d A B C. [| p: A+B;  !!x. x:A ==> c(x): C(inl(x));
   230                 !!y. y:B ==> d(y): C(inr(y)) |]
   231     ==> when(p, %x. c(x), %y. d(y)) : C(p)" and
   232 
   233   PlusEL:
   234     "\<And>p q c d e f A B C. [| p = q : A+B;  !!x. x: A ==> c(x) = e(x) : C(inl(x));
   235                      !!y. y: B ==> d(y) = f(y) : C(inr(y)) |]
   236     ==> when(p, %x. c(x), %y. d(y)) = when(q, %x. e(x), %y. f(y)) : C(p)" and
   237 
   238   PlusC_inl:
   239     "\<And>a c d A C. [| a: A;  !!x. x:A ==> c(x): C(inl(x));
   240               !!y. y:B ==> d(y): C(inr(y)) |]
   241     ==> when(inl(a), %x. c(x), %y. d(y)) = c(a) : C(inl(a))" and
   242 
   243   PlusC_inr:
   244     "\<And>b c d A B C. [| b: B;  !!x. x:A ==> c(x): C(inl(x));
   245               !!y. y:B ==> d(y): C(inr(y)) |]
   246     ==> when(inr(b), %x. c(x), %y. d(y)) = d(b) : C(inr(b))" and
   247 
   248 
   249   (*The type Eq*)
   250 
   251   EqF:    "\<And>a b A. [| A type;  a : A;  b : A |] ==> Eq(A,a,b) type" and
   252   EqFL: "\<And>a b c d A B. [| A=B;  a=c: A;  b=d : A |] ==> Eq(A,a,b) = Eq(B,c,d)" and
   253   EqI: "\<And>a b A. a = b : A ==> eq : Eq(A,a,b)" and
   254   EqE: "\<And>p a b A. p : Eq(A,a,b) ==> a = b : A" and
   255 
   256   (*By equality of types, can prove C(p) from C(eq), an elimination rule*)
   257   EqC: "\<And>p a b A. p : Eq(A,a,b) ==> p = eq : Eq(A,a,b)" and
   258 
   259   (*The type F*)
   260 
   261   FF: "F type" and
   262   FE: "\<And>p C. [| p: F;  C type |] ==> contr(p) : C" and
   263   FEL:  "\<And>p q C. [| p = q : F;  C type |] ==> contr(p) = contr(q) : C" and
   264 
   265   (*The type T
   266      Martin-Lof's book (page 68) discusses elimination and computation.
   267      Elimination can be derived by computation and equality of types,
   268      but with an extra premise C(x) type x:T.
   269      Also computation can be derived from elimination. *)
   270 
   271   TF: "T type" and
   272   TI: "tt : T" and
   273   TE: "\<And>p c C. [| p : T;  c : C(tt) |] ==> c : C(p)" and
   274   TEL: "\<And>p q c d C. [| p = q : T;  c = d : C(tt) |] ==> c = d : C(p)" and
   275   TC: "\<And>p. p : T ==> p = tt : T"
   276 
   277 
   278 subsection "Tactics and derived rules for Constructive Type Theory"
   279 
   280 (*Formation rules*)
   281 lemmas form_rls = NF ProdF SumF PlusF EqF FF TF
   282   and formL_rls = ProdFL SumFL PlusFL EqFL
   283 
   284 (*Introduction rules
   285   OMITTED: EqI, because its premise is an eqelem, not an elem*)
   286 lemmas intr_rls = NI0 NI_succ ProdI SumI PlusI_inl PlusI_inr TI
   287   and intrL_rls = NI_succL ProdIL SumIL PlusI_inlL PlusI_inrL
   288 
   289 (*Elimination rules
   290   OMITTED: EqE, because its conclusion is an eqelem,  not an elem
   291            TE, because it does not involve a constructor *)
   292 lemmas elim_rls = NE ProdE SumE PlusE FE
   293   and elimL_rls = NEL ProdEL SumEL PlusEL FEL
   294 
   295 (*OMITTED: eqC are TC because they make rewriting loop: p = un = un = ... *)
   296 lemmas comp_rls = NC0 NC_succ ProdC SumC PlusC_inl PlusC_inr
   297 
   298 (*rules with conclusion a:A, an elem judgement*)
   299 lemmas element_rls = intr_rls elim_rls
   300 
   301 (*Definitions are (meta)equality axioms*)
   302 lemmas basic_defs = fst_def snd_def
   303 
   304 (*Compare with standard version: B is applied to UNSIMPLIFIED expression! *)
   305 lemma SumIL2: "[| c=a : A;  d=b : B(a) |] ==> <c,d> = <a,b> : Sum(A,B)"
   306 apply (rule sym_elem)
   307 apply (rule SumIL)
   308 apply (rule_tac [!] sym_elem)
   309 apply assumption+
   310 done
   311 
   312 lemmas intrL2_rls = NI_succL ProdIL SumIL2 PlusI_inlL PlusI_inrL
   313 
   314 (*Exploit p:Prod(A,B) to create the assumption z:B(a).
   315   A more natural form of product elimination. *)
   316 lemma subst_prodE:
   317   assumes "p: Prod(A,B)"
   318     and "a: A"
   319     and "!!z. z: B(a) ==> c(z): C(z)"
   320   shows "c(p`a): C(p`a)"
   321 apply (rule assms ProdE)+
   322 done
   323 
   324 
   325 subsection {* Tactics for type checking *}
   326 
   327 ML {*
   328 
   329 local
   330 
   331 fun is_rigid_elem (Const("CTT.Elem",_) $ a $ _) = not(is_Var (head_of a))
   332   | is_rigid_elem (Const("CTT.Eqelem",_) $ a $ _ $ _) = not(is_Var (head_of a))
   333   | is_rigid_elem (Const("CTT.Type",_) $ a) = not(is_Var (head_of a))
   334   | is_rigid_elem _ = false
   335 
   336 in
   337 
   338 (*Try solving a:A or a=b:A by assumption provided a is rigid!*)
   339 val test_assume_tac = SUBGOAL(fn (prem,i) =>
   340     if is_rigid_elem (Logic.strip_assums_concl prem)
   341     then  assume_tac i  else  no_tac)
   342 
   343 fun ASSUME tf i = test_assume_tac i  ORELSE  tf i
   344 
   345 end;
   346 
   347 *}
   348 
   349 (*For simplification: type formation and checking,
   350   but no equalities between terms*)
   351 lemmas routine_rls = form_rls formL_rls refl_type element_rls
   352 
   353 ML {*
   354 local
   355   val equal_rls = @{thms form_rls} @ @{thms element_rls} @ @{thms intrL_rls} @
   356     @{thms elimL_rls} @ @{thms refl_elem}
   357 in
   358 
   359 fun routine_tac rls prems = ASSUME (filt_resolve_tac (prems @ rls) 4);
   360 
   361 (*Solve all subgoals "A type" using formation rules. *)
   362 val form_tac = REPEAT_FIRST (ASSUME (filt_resolve_tac @{thms form_rls} 1));
   363 
   364 (*Type checking: solve a:A (a rigid, A flexible) by intro and elim rules. *)
   365 fun typechk_tac thms =
   366   let val tac = filt_resolve_tac (thms @ @{thms form_rls} @ @{thms element_rls}) 3
   367   in  REPEAT_FIRST (ASSUME tac)  end
   368 
   369 (*Solve a:A (a flexible, A rigid) by introduction rules.
   370   Cannot use stringtrees (filt_resolve_tac) since
   371   goals like ?a:SUM(A,B) have a trivial head-string *)
   372 fun intr_tac thms =
   373   let val tac = filt_resolve_tac(thms @ @{thms form_rls} @ @{thms intr_rls}) 1
   374   in  REPEAT_FIRST (ASSUME tac)  end
   375 
   376 (*Equality proving: solve a=b:A (where a is rigid) by long rules. *)
   377 fun equal_tac thms =
   378   REPEAT_FIRST (ASSUME (filt_resolve_tac (thms @ equal_rls) 3))
   379 
   380 end
   381 
   382 *}
   383 
   384 
   385 subsection {* Simplification *}
   386 
   387 (*To simplify the type in a goal*)
   388 lemma replace_type: "[| B = A;  a : A |] ==> a : B"
   389 apply (rule equal_types)
   390 apply (rule_tac [2] sym_type)
   391 apply assumption+
   392 done
   393 
   394 (*Simplify the parameter of a unary type operator.*)
   395 lemma subst_eqtyparg:
   396   assumes 1: "a=c : A"
   397     and 2: "!!z. z:A ==> B(z) type"
   398   shows "B(a)=B(c)"
   399 apply (rule subst_typeL)
   400 apply (rule_tac [2] refl_type)
   401 apply (rule 1)
   402 apply (erule 2)
   403 done
   404 
   405 (*Simplification rules for Constructive Type Theory*)
   406 lemmas reduction_rls = comp_rls [THEN trans_elem]
   407 
   408 ML {*
   409 (*Converts each goal "e : Eq(A,a,b)" into "a=b:A" for simplification.
   410   Uses other intro rules to avoid changing flexible goals.*)
   411 val eqintr_tac = REPEAT_FIRST (ASSUME (filt_resolve_tac (@{thm EqI} :: @{thms intr_rls}) 1))
   412 
   413 (** Tactics that instantiate CTT-rules.
   414     Vars in the given terms will be incremented!
   415     The (rtac EqE i) lets them apply to equality judgements. **)
   416 
   417 fun NE_tac ctxt sp i =
   418   TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm NE} i
   419 
   420 fun SumE_tac ctxt sp i =
   421   TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm SumE} i
   422 
   423 fun PlusE_tac ctxt sp i =
   424   TRY (rtac @{thm EqE} i) THEN res_inst_tac ctxt [(("p", 0), sp)] @{thm PlusE} i
   425 
   426 (** Predicate logic reasoning, WITH THINNING!!  Procedures adapted from NJ. **)
   427 
   428 (*Finds f:Prod(A,B) and a:A in the assumptions, concludes there is z:B(a) *)
   429 fun add_mp_tac i =
   430     rtac @{thm subst_prodE} i  THEN  assume_tac i  THEN  assume_tac i
   431 
   432 (*Finds P-->Q and P in the assumptions, replaces implication by Q *)
   433 fun mp_tac i = etac @{thm subst_prodE} i  THEN  assume_tac i
   434 
   435 (*"safe" when regarded as predicate calculus rules*)
   436 val safe_brls = sort (make_ord lessb)
   437     [ (true, @{thm FE}), (true,asm_rl),
   438       (false, @{thm ProdI}), (true, @{thm SumE}), (true, @{thm PlusE}) ]
   439 
   440 val unsafe_brls =
   441     [ (false, @{thm PlusI_inl}), (false, @{thm PlusI_inr}), (false, @{thm SumI}),
   442       (true, @{thm subst_prodE}) ]
   443 
   444 (*0 subgoals vs 1 or more*)
   445 val (safe0_brls, safep_brls) =
   446     List.partition (curry (op =) 0 o subgoals_of_brl) safe_brls
   447 
   448 fun safestep_tac thms i =
   449     form_tac  ORELSE
   450     resolve_tac thms i  ORELSE
   451     biresolve_tac safe0_brls i  ORELSE  mp_tac i  ORELSE
   452     DETERM (biresolve_tac safep_brls i)
   453 
   454 fun safe_tac thms i = DEPTH_SOLVE_1 (safestep_tac thms i)
   455 
   456 fun step_tac thms = safestep_tac thms  ORELSE'  biresolve_tac unsafe_brls
   457 
   458 (*Fails unless it solves the goal!*)
   459 fun pc_tac thms = DEPTH_SOLVE_1 o (step_tac thms)
   460 *}
   461 
   462 ML_file "rew.ML"
   463 
   464 
   465 subsection {* The elimination rules for fst/snd *}
   466 
   467 lemma SumE_fst: "p : Sum(A,B) ==> fst(p) : A"
   468 apply (unfold basic_defs)
   469 apply (erule SumE)
   470 apply assumption
   471 done
   472 
   473 (*The first premise must be p:Sum(A,B) !!*)
   474 lemma SumE_snd:
   475   assumes major: "p: Sum(A,B)"
   476     and "A type"
   477     and "!!x. x:A ==> B(x) type"
   478   shows "snd(p) : B(fst(p))"
   479   apply (unfold basic_defs)
   480   apply (rule major [THEN SumE])
   481   apply (rule SumC [THEN subst_eqtyparg, THEN replace_type])
   482   apply (tactic {* typechk_tac @{thms assms} *})
   483   done
   484 
   485 end