src/HOL/ex/SList.ML
changeset 1465 5d7a7e439cec
parent 1266 3ae9fe3c0f68
child 1476 608483c2122a
equal deleted inserted replaced
1464:a608f83e3421 1465:5d7a7e439cec
     1 (*  Title: 	HOL/ex/SList.ML
     1 (*  Title:      HOL/ex/SList.ML
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
     3     Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
     4     Copyright   1993  University of Cambridge
     4     Copyright   1993  University of Cambridge
     5 
     5 
     6 Definition of type 'a list by a least fixed point
     6 Definition of type 'a list by a least fixed point
     7 *)
     7 *)
     8 
     8 
    43 qed "list_induct2";
    43 qed "list_induct2";
    44 
    44 
    45 (*Perform induction on xs. *)
    45 (*Perform induction on xs. *)
    46 fun list_ind_tac a M = 
    46 fun list_ind_tac a M = 
    47     EVERY [res_inst_tac [("l",a)] list_induct2 M,
    47     EVERY [res_inst_tac [("l",a)] list_induct2 M,
    48 	   rename_last_tac a ["1"] (M+1)];
    48            rename_last_tac a ["1"] (M+1)];
    49 
    49 
    50 (*** Isomorphisms ***)
    50 (*** Isomorphisms ***)
    51 
    51 
    52 goal SList.thy "inj(Rep_list)";
    52 goal SList.thy "inj(Rep_list)";
    53 by (rtac inj_inverseI 1);
    53 by (rtac inj_inverseI 1);
    87 
    87 
    88 bind_thm ("CONS_inject", (CONS_CONS_eq RS iffD1 RS conjE));
    88 bind_thm ("CONS_inject", (CONS_CONS_eq RS iffD1 RS conjE));
    89 
    89 
    90 (*For reasoning about abstract list constructors*)
    90 (*For reasoning about abstract list constructors*)
    91 val list_cs = set_cs addIs [Rep_list] @ list.intrs
    91 val list_cs = set_cs addIs [Rep_list] @ list.intrs
    92 	             addSEs [CONS_neq_NIL,NIL_neq_CONS,CONS_inject]
    92                      addSEs [CONS_neq_NIL,NIL_neq_CONS,CONS_inject]
    93 		     addSDs [inj_onto_Abs_list RS inj_ontoD,
    93                      addSDs [inj_onto_Abs_list RS inj_ontoD,
    94 			     inj_Rep_list RS injD, Leaf_inject];
    94                              inj_Rep_list RS injD, Leaf_inject];
    95 
    95 
    96 goalw SList.thy [Cons_def] "(x#xs=y#ys) = (x=y & xs=ys)";
    96 goalw SList.thy [Cons_def] "(x#xs=y#ys) = (x=y & xs=ys)";
    97 by (fast_tac list_cs 1);
    97 by (fast_tac list_cs 1);
    98 qed "Cons_Cons_eq";
    98 qed "Cons_Cons_eq";
    99 bind_thm ("Cons_inject2", (Cons_Cons_eq RS iffD1 RS conjE));
    99 bind_thm ("Cons_inject2", (Cons_Cons_eq RS iffD1 RS conjE));
   165 
   165 
   166 val [prem] = goal SList.thy
   166 val [prem] = goal SList.thy
   167     "(CONS M1 M2, N) : pred_sexp^+ ==> \
   167     "(CONS M1 M2, N) : pred_sexp^+ ==> \
   168 \    (M1,N) : pred_sexp^+ & (M2,N) : pred_sexp^+";
   168 \    (M1,N) : pred_sexp^+ & (M2,N) : pred_sexp^+";
   169 by (rtac (prem RS (pred_sexp_subset_Sigma RS trancl_subset_Sigma RS 
   169 by (rtac (prem RS (pred_sexp_subset_Sigma RS trancl_subset_Sigma RS 
   170 		   subsetD RS SigmaE2)) 1);
   170                    subsetD RS SigmaE2)) 1);
   171 by (etac (sexp_CONS_D RS conjE) 1);
   171 by (etac (sexp_CONS_D RS conjE) 1);
   172 by (REPEAT (ares_tac [conjI, pred_sexp_CONS_I1, pred_sexp_CONS_I2,
   172 by (REPEAT (ares_tac [conjI, pred_sexp_CONS_I1, pred_sexp_CONS_I2,
   173 		      prem RSN (2, trans_trancl RS transD)] 1));
   173                       prem RSN (2, trans_trancl RS transD)] 1));
   174 qed "pred_sexp_CONS_D";
   174 qed "pred_sexp_CONS_D";
   175 
   175 
   176 (** Conversion rules for List_rec **)
   176 (** Conversion rules for List_rec **)
   177 
   177 
   178 goal SList.thy "List_rec NIL c h = c";
   178 goal SList.thy "List_rec NIL c h = c";
   209 Addsimps [List_rec_NIL, List_rec_CONS, list_rec_Nil, list_rec_Cons];
   209 Addsimps [List_rec_NIL, List_rec_CONS, list_rec_Nil, list_rec_Cons];
   210 
   210 
   211 
   211 
   212 (*Type checking.  Useful?*)
   212 (*Type checking.  Useful?*)
   213 val major::A_subset_sexp::prems = goal SList.thy
   213 val major::A_subset_sexp::prems = goal SList.thy
   214     "[| M: list(A);    	\
   214     "[| M: list(A);     \
   215 \       A<=sexp;      	\
   215 \       A<=sexp;        \
   216 \       c: C(NIL);      \
   216 \       c: C(NIL);      \
   217 \       !!x y r. [| x: A;  y: list(A);  r: C(y) |] ==> h x y r: C(CONS x y) \
   217 \       !!x y r. [| x: A;  y: list(A);  r: C(y) |] ==> h x y r: C(CONS x y) \
   218 \    |] ==> List_rec M c h : C(M :: 'a item)";
   218 \    |] ==> List_rec M c h : C(M :: 'a item)";
   219 val sexp_ListA_I = A_subset_sexp RS list_subset_sexp RS subsetD;
   219 val sexp_ListA_I = A_subset_sexp RS list_subset_sexp RS subsetD;
   220 val sexp_A_I = A_subset_sexp RS subsetD;
   220 val sexp_A_I = A_subset_sexp RS subsetD;
   371 by (list_ind_tac "xs" 1);
   371 by (list_ind_tac "xs" 1);
   372 by (ALLGOALS Asm_simp_tac);
   372 by (ALLGOALS Asm_simp_tac);
   373 qed "map_compose2";
   373 qed "map_compose2";
   374 
   374 
   375 goal SList.thy "!!f. (!!x. f(x): sexp) ==> \
   375 goal SList.thy "!!f. (!!x. f(x): sexp) ==> \
   376 \	Abs_map g (Rep_map f xs) = map (%t. g(f(t))) xs";
   376 \       Abs_map g (Rep_map f xs) = map (%t. g(f(t))) xs";
   377 by (list_ind_tac "xs" 1);
   377 by (list_ind_tac "xs" 1);
   378 by(ALLGOALS(asm_simp_tac(!simpset addsimps
   378 by(ALLGOALS(asm_simp_tac(!simpset addsimps
   379        [Rep_map_type,list_sexp RS subsetD])));
   379        [Rep_map_type,list_sexp RS subsetD])));
   380 qed "Abs_Rep_map";
   380 qed "Abs_Rep_map";
   381 
   381