src/HOL/Induct/LList.ML
author paulson
Mon, 02 Nov 1998 15:31:29 +0100
changeset 5788 e3a98a7c0634
parent 5278 a903b66822e2
child 5977 9f0c8869cf71
permissions -rw-r--r--
Domain r, Range r replace fst``r, snd``r
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5089
f95e0a6eb775 New rewrite unit_abs_eta_conv to compensate for unit_eq_proc
paulson
parents: 5086
diff changeset
     1
(*  Title:      HOL/Induct/LList
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     2
    ID:         $Id$
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     5
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     6
SHOULD LListD_Fun_CONS_I, etc., be equations (for rewriting)?
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     7
*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
     8
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
     9
bind_thm ("UN1_I", UNIV_I RS UN_I);
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    10
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    11
(** Simplification **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    12
5089
f95e0a6eb775 New rewrite unit_abs_eta_conv to compensate for unit_eq_proc
paulson
parents: 5086
diff changeset
    13
Addsplits [split_split, split_sum_case];
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    14
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    15
(*This justifies using llist in other recursive type definitions*)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5102
diff changeset
    16
Goalw llist.defs "A<=B ==> llist(A) <= llist(B)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    17
by (rtac gfp_mono 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    18
by (REPEAT (ares_tac basic_monos 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    19
qed "llist_mono";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    20
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    21
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    22
Goal "llist(A) = {Numb(0)} <+> (A <*> llist(A))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    23
let val rew = rewrite_rule [NIL_def, CONS_def] in  
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    24
by (fast_tac (claset() addSIs (map rew llist.intrs)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    25
                      addEs [rew llist.elim]) 1)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    26
end;
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    27
qed "llist_unfold";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    28
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    29
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    30
(*** Type checking by coinduction, using list_Fun 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    31
     THE COINDUCTIVE DEFINITION PACKAGE COULD DO THIS!
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    32
***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    33
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    34
Goalw [list_Fun_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
    35
    "[| M : X;  X <= list_Fun A (X Un llist(A)) |] ==>  M : llist(A)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    36
by (etac llist.coinduct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    37
by (etac (subsetD RS CollectD) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    38
by (assume_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    39
qed "llist_coinduct";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    40
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    41
Goalw [list_Fun_def, NIL_def] "NIL: list_Fun A X";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    42
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    43
qed "list_Fun_NIL_I";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
    44
AddIffs [list_Fun_NIL_I];
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    45
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    46
Goalw [list_Fun_def,CONS_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
    47
    "[| M: A;  N: X |] ==> CONS M N : list_Fun A X";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    48
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    49
qed "list_Fun_CONS_I";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
    50
Addsimps [list_Fun_CONS_I];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
    51
AddSIs   [list_Fun_CONS_I];
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    52
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    53
(*Utilise the "strong" part, i.e. gfp(f)*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    54
Goalw (llist.defs @ [list_Fun_def])
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
    55
    "M: llist(A) ==> M : list_Fun A (X Un llist(A))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    56
by (etac (llist.mono RS gfp_fun_UnI2) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    57
qed "list_Fun_llist_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    58
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    59
(*** LList_corec satisfies the desired recurion equation ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    60
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    61
(*A continuity result?*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    62
Goalw [CONS_def] "CONS M (UN x. f(x)) = (UN x. CONS M (f x))";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    63
by (simp_tac (simpset() addsimps [In1_UN1, Scons_UN1_y]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    64
qed "CONS_UN1";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    65
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    66
val prems = goalw LList.thy [CONS_def]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    67
    "[| M<=M';  N<=N' |] ==> CONS M N <= CONS M' N'";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    68
by (REPEAT (resolve_tac ([In1_mono,Scons_mono]@prems) 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    69
qed "CONS_mono";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    70
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    71
Addsimps [LList_corec_fun_def RS def_nat_rec_0,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    72
          LList_corec_fun_def RS def_nat_rec_Suc];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    73
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    74
(** The directions of the equality are proved separately **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    75
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    76
Goalw [LList_corec_def]
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
    77
    "LList_corec a f <= sum_case (%u. NIL) \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    78
\                          (split(%z w. CONS z (LList_corec w f))) (f a)";
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    79
by (rtac UN_least 1);
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    80
by (exhaust_tac "k" 1);
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    81
by (ALLGOALS Asm_simp_tac);
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    82
by (REPEAT (resolve_tac [allI, impI, subset_refl RS CONS_mono, 
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    83
			 UNIV_I RS UN_upper] 1));
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    84
qed "LList_corec_subset1";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    85
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
    86
Goalw [LList_corec_def]
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
    87
    "sum_case (%u. NIL) (split(%z w. CONS z (LList_corec w f))) (f a) <= \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    88
\    LList_corec a f";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
    89
by (simp_tac (simpset() addsimps [CONS_UN1]) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    90
by Safe_tac;
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    91
by (ALLGOALS (res_inst_tac [("a","Suc(?k)")] UN_I));
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
    92
by (ALLGOALS Asm_simp_tac);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    93
qed "LList_corec_subset2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    94
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    95
(*the recursion equation for LList_corec -- NOT SUITABLE FOR REWRITING!*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
    96
Goal "LList_corec a f = sum_case (%u. NIL) \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    97
\                           (split(%z w. CONS z (LList_corec w f))) (f a)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    98
by (REPEAT (resolve_tac [equalityI, LList_corec_subset1, 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
    99
                         LList_corec_subset2] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   100
qed "LList_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   101
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   102
(*definitional version of same*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   103
val [rew] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   104
    "[| !!x. h(x) == LList_corec x f |] ==>     \
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   105
\    h(a) = sum_case (%u. NIL) (split(%z w. CONS z (h w))) (f a)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   106
by (rewtac rew);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   107
by (rtac LList_corec 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   108
qed "def_LList_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   109
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   110
(*A typical use of co-induction to show membership in the gfp. 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   111
  Bisimulation is  range(%x. LList_corec x f) *)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   112
Goal "LList_corec a f : llist({u. True})";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   113
by (res_inst_tac [("X", "range(%x. LList_corec x ?g)")] llist_coinduct 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   114
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   115
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   116
by (stac LList_corec 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   117
by (Simp_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   118
qed "LList_corec_type";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   119
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   120
(*Lemma for the proof of llist_corec*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   121
Goal "LList_corec a (%z. sum_case Inl (split(%v w. Inr((Leaf(v),w)))) (f z)) : \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   122
\   llist(range Leaf)";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   123
by (res_inst_tac [("X", "range(%x. LList_corec x ?g)")] llist_coinduct 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   124
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   125
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   126
by (stac LList_corec 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   127
by (Asm_simp_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   128
qed "LList_corec_type2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   129
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   130
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   131
(**** llist equality as a gfp; the bisimulation principle ****)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   132
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   133
(*This theorem is actually used, unlike the many similar ones in ZF*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   134
Goal "LListD(r) = diag({Numb(0)}) <++> (r <**> LListD(r))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   135
let val rew = rewrite_rule [NIL_def, CONS_def] in  
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   136
by (fast_tac (claset() addSIs (map rew LListD.intrs)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   137
                      addEs [rew LListD.elim]) 1)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   138
end;
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   139
qed "LListD_unfold";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   140
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   141
Goal "!M N. (M,N) : LListD(diag A) --> ntrunc k M = ntrunc k N";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   142
by (res_inst_tac [("n", "k")] less_induct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   143
by (safe_tac ((claset_of Fun.thy) delrules [equalityI]));
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   144
by (etac LListD.elim 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   145
by (safe_tac (claset_of Prod.thy delrules [equalityI] addSEs [diagE]));
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   146
by (exhaust_tac "n" 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   147
by (Asm_simp_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   148
by (rename_tac "n'" 1);
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   149
by (exhaust_tac "n'" 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   150
by (asm_simp_tac (simpset() addsimps [CONS_def]) 1);
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   151
by (asm_simp_tac (simpset() addsimps [CONS_def, less_Suc_eq]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   152
qed "LListD_implies_ntrunc_equality";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   153
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   154
(*The domain of the LListD relation*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   155
Goalw (llist.defs @ [NIL_def, CONS_def])
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   156
    "Domain (LListD(diag A)) <= llist(A)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   157
by (rtac gfp_upperbound 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   158
(*avoids unfolding LListD on the rhs*)
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   159
by (res_inst_tac [("P", "%x. Domain x <= ?B")] (LListD_unfold RS ssubst) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   160
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   161
by (Fast_tac 1);
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   162
qed "Domain_LListD";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   163
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   164
(*This inclusion justifies the use of coinduction to show M=N*)
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   165
Goal "LListD(diag A) <= diag(llist(A))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   166
by (rtac subsetI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   167
by (res_inst_tac [("p","x")] PairE 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   168
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   169
by (rtac diag_eqI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   170
by (rtac (LListD_implies_ntrunc_equality RS spec RS spec RS mp RS 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   171
          ntrunc_equality) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   172
by (assume_tac 1);
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   173
by (etac (DomainI RS (Domain_LListD RS subsetD)) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   174
qed "LListD_subset_diag";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   175
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   176
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   177
(** Coinduction, using LListD_Fun
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   178
    THE COINDUCTIVE DEFINITION PACKAGE COULD DO THIS!
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   179
 **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   180
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5102
diff changeset
   181
Goalw [LListD_Fun_def] "A<=B ==> LListD_Fun r A <= LListD_Fun r B";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   182
by (REPEAT (ares_tac basic_monos 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   183
qed "LListD_Fun_mono";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   184
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   185
Goalw [LListD_Fun_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   186
    "[| M : X;  X <= LListD_Fun r (X Un LListD(r)) |] ==>  M : LListD(r)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   187
by (etac LListD.coinduct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   188
by (etac (subsetD RS CollectD) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   189
by (assume_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   190
qed "LListD_coinduct";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   191
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   192
Goalw [LListD_Fun_def,NIL_def] "(NIL,NIL) : LListD_Fun r s";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   193
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   194
qed "LListD_Fun_NIL_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   195
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   196
Goalw [LListD_Fun_def,CONS_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   197
 "[| x:A;  (M,N):s |] ==> (CONS x M, CONS x N) : LListD_Fun (diag A) s";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   198
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   199
qed "LListD_Fun_CONS_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   200
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   201
(*Utilise the "strong" part, i.e. gfp(f)*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   202
Goalw (LListD.defs @ [LListD_Fun_def])
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   203
    "M: LListD(r) ==> M : LListD_Fun r (X Un LListD(r))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   204
by (etac (LListD.mono RS gfp_fun_UnI2) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   205
qed "LListD_Fun_LListD_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   206
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   207
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   208
(*This converse inclusion helps to strengthen LList_equalityI*)
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   209
Goal "diag(llist(A)) <= LListD(diag A)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   210
by (rtac subsetI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   211
by (etac LListD_coinduct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   212
by (rtac subsetI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   213
by (etac diagE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   214
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   215
by (eresolve_tac [llist.elim] 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   216
by (ALLGOALS
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   217
    (asm_simp_tac (simpset() addsimps [diagI, LListD_Fun_NIL_I,
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   218
				       LListD_Fun_CONS_I])));
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   219
qed "diag_subset_LListD";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   220
5788
e3a98a7c0634 Domain r, Range r replace fst``r, snd``r
paulson
parents: 5278
diff changeset
   221
Goal "LListD(diag A) = diag(llist(A))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   222
by (REPEAT (resolve_tac [equalityI, LListD_subset_diag, 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   223
                         diag_subset_LListD] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   224
qed "LListD_eq_diag";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   225
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   226
Goal "M: llist(A) ==> (M,M) : LListD_Fun (diag A) (X Un diag(llist(A)))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   227
by (rtac (LListD_eq_diag RS subst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   228
by (rtac LListD_Fun_LListD_I 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   229
by (asm_simp_tac (simpset() addsimps [LListD_eq_diag, diagI]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   230
qed "LListD_Fun_diag_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   231
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   232
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   233
(** To show two LLists are equal, exhibit a bisimulation! 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   234
      [also admits true equality]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   235
   Replace "A" by some particular set, like {x.True}??? *)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   236
Goal "[| (M,N) : r;  r <= LListD_Fun (diag A) (r Un diag(llist(A))) \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   237
\         |] ==>  M=N";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   238
by (rtac (LListD_subset_diag RS subsetD RS diagE) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   239
by (etac LListD_coinduct 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   240
by (asm_simp_tac (simpset() addsimps [LListD_eq_diag]) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   241
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   242
qed "LList_equalityI";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   243
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   244
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   245
(*** Finality of llist(A): Uniqueness of functions defined by corecursion ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   246
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   247
(*We must remove Pair_eq because it may turn an instance of reflexivity
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   248
  (h1 b, h2 b) = (h1 ?x17, h2 ?x17) into a conjunction! 
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   249
  (or strengthen the Solver?) 
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   250
*)
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   251
Delsimps [Pair_eq];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   252
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   253
(*abstract proof using a bisimulation*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   254
val [prem1,prem2] = goal LList.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   255
 "[| !!x. h1(x) = sum_case (%u. NIL) (split(%z w. CONS z (h1 w))) (f x);  \
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   256
\    !!x. h2(x) = sum_case (%u. NIL) (split(%z w. CONS z (h2 w))) (f x) |]\
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   257
\ ==> h1=h2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   258
by (rtac ext 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   259
(*next step avoids an unknown (and flexflex pair) in simplification*)
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   260
by (res_inst_tac [("A", "{u. True}"),
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   261
                  ("r", "range(%u. (h1(u),h2(u)))")] LList_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   262
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   263
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   264
by (stac prem1 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   265
by (stac prem2 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   266
by (simp_tac (simpset() addsimps [LListD_Fun_NIL_I,
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   267
				  CollectI RS LListD_Fun_CONS_I]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   268
qed "LList_corec_unique";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   269
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   270
val [prem] = goal LList.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   271
 "[| !!x. h(x) = sum_case (%u. NIL) (split(%z w. CONS z (h w))) (f x) |] \
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   272
\ ==> h = (%x. LList_corec x f)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   273
by (rtac (LList_corec RS (prem RS LList_corec_unique)) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   274
qed "equals_LList_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   275
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   276
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   277
(** Obsolete LList_corec_unique proof: complete induction, not coinduction **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   278
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   279
Goalw [CONS_def] "ntrunc (Suc 0) (CONS M N) = {}";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   280
by (rtac ntrunc_one_In1 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   281
qed "ntrunc_one_CONS";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   282
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   283
Goalw [CONS_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   284
    "ntrunc (Suc(Suc(k))) (CONS M N) = CONS (ntrunc k M) (ntrunc k N)";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   285
by (Simp_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   286
qed "ntrunc_CONS";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   287
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   288
Addsimps [ntrunc_one_CONS, ntrunc_CONS];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   289
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   290
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   291
val [prem1,prem2] = goal LList.thy
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   292
 "[| !!x. h1(x) = sum_case (%u. NIL) (split(%z w. CONS z (h1 w))) (f x);  \
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   293
\    !!x. h2(x) = sum_case (%u. NIL) (split(%z w. CONS z (h2 w))) (f x) |]\
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   294
\ ==> h1=h2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   295
by (rtac (ntrunc_equality RS ext) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   296
by (rename_tac "x k" 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   297
by (res_inst_tac [("x", "x")] spec 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   298
by (res_inst_tac [("n", "k")] less_induct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   299
by (rename_tac "n" 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   300
by (rtac allI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   301
by (rename_tac "y" 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   302
by (stac prem1 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   303
by (stac prem2 1);
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4818
diff changeset
   304
by (Simp_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   305
by (strip_tac 1);
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   306
by (exhaust_tac "n" 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   307
by (rename_tac "m" 2);
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   308
by (exhaust_tac "m" 2);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   309
by (ALLGOALS (asm_simp_tac (simpset() addsimps [less_Suc_eq])));
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   310
result();
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   311
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   312
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   313
(*** Lconst -- defined directly using lfp, but equivalent to a LList_corec ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   314
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   315
Goal "mono(CONS(M))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   316
by (REPEAT (ares_tac [monoI, subset_refl, CONS_mono] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   317
qed "Lconst_fun_mono";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   318
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   319
(* Lconst(M) = CONS M (Lconst M) *)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   320
bind_thm ("Lconst", (Lconst_fun_mono RS (Lconst_def RS def_lfp_Tarski)));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   321
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   322
(*A typical use of co-induction to show membership in the gfp.
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   323
  The containing set is simply the singleton {Lconst(M)}. *)
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5102
diff changeset
   324
Goal "M:A ==> Lconst(M): llist(A)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   325
by (rtac (singletonI RS llist_coinduct) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   326
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   327
by (res_inst_tac [("P", "%u. u: ?A")] (Lconst RS ssubst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   328
by (REPEAT (ares_tac [list_Fun_CONS_I, singletonI, UnI1] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   329
qed "Lconst_type";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   330
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   331
Goal "Lconst(M) = LList_corec M (%x. Inr((x,x)))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   332
by (rtac (equals_LList_corec RS fun_cong) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   333
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   334
by (rtac Lconst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   335
qed "Lconst_eq_LList_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   336
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   337
(*Thus we could have used gfp in the definition of Lconst*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   338
Goal "gfp(%N. CONS M N) = LList_corec M (%x. Inr((x,x)))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   339
by (rtac (equals_LList_corec RS fun_cong) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   340
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   341
by (rtac (Lconst_fun_mono RS gfp_Tarski) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   342
qed "gfp_Lconst_eq_LList_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   343
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   344
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   345
(*** Isomorphisms ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   346
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   347
Goal "inj(Rep_llist)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   348
by (rtac inj_inverseI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   349
by (rtac Rep_llist_inverse 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   350
qed "inj_Rep_llist";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   351
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   352
Goal "inj_on Abs_llist (llist(range Leaf))";
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4818
diff changeset
   353
by (rtac inj_on_inverseI 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   354
by (etac Abs_llist_inverse 1);
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4818
diff changeset
   355
qed "inj_on_Abs_llist";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   356
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   357
(** Distinctness of constructors **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   358
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   359
Goalw [LNil_def,LCons_def] "~ LCons x xs = LNil";
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4818
diff changeset
   360
by (rtac (CONS_not_NIL RS (inj_on_Abs_llist RS inj_on_contraD)) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   361
by (REPEAT (resolve_tac (llist.intrs @ [rangeI, Rep_llist]) 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   362
qed "LCons_not_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   363
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   364
bind_thm ("LNil_not_LCons", LCons_not_LNil RS not_sym);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   365
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   366
AddIffs [LCons_not_LNil, LNil_not_LCons];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   367
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   368
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   369
(** llist constructors **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   370
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   371
Goalw [LNil_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   372
    "Rep_llist(LNil) = NIL";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   373
by (rtac (llist.NIL_I RS Abs_llist_inverse) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   374
qed "Rep_llist_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   375
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   376
Goalw [LCons_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   377
    "Rep_llist(LCons x l) = CONS (Leaf x) (Rep_llist l)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   378
by (REPEAT (resolve_tac [llist.CONS_I RS Abs_llist_inverse,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   379
                         rangeI, Rep_llist] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   380
qed "Rep_llist_LCons";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   381
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   382
(** Injectiveness of CONS and LCons **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   383
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   384
Goalw [CONS_def] "(CONS M N=CONS M' N') = (M=M' & N=N')";
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   385
by (fast_tac (claset() addSEs [Scons_inject]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   386
qed "CONS_CONS_eq2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   387
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   388
bind_thm ("CONS_inject", (CONS_CONS_eq RS iffD1 RS conjE));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   389
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   390
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   391
(*For reasoning about abstract llist constructors*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   392
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   393
AddIs ([Rep_llist]@llist.intrs);
4831
dae4d63a1318 Renamed expand_const -> split_const.
nipkow
parents: 4818
diff changeset
   394
AddSDs [inj_on_Abs_llist RS inj_onD,
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   395
        inj_Rep_llist RS injD, Leaf_inject];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   396
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   397
Goalw [LCons_def] "(LCons x xs=LCons y ys) = (x=y & xs=ys)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   398
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   399
qed "LCons_LCons_eq";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   400
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   401
AddIffs [LCons_LCons_eq];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   402
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   403
val [major] = goal LList.thy "CONS M N: llist(A) ==> M: A & N: llist(A)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   404
by (rtac (major RS llist.elim) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   405
by (etac CONS_neq_NIL 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   406
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   407
qed "CONS_D2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   408
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   409
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   410
(****** Reasoning about llist(A) ******)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   411
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   412
Addsimps [List_case_NIL, List_case_CONS];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   413
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   414
(*A special case of list_equality for functions over lazy lists*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   415
val [Mlist,gMlist,NILcase,CONScase] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   416
 "[| M: llist(A); g(NIL): llist(A);                             \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   417
\    f(NIL)=g(NIL);                                             \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   418
\    !!x l. [| x:A;  l: llist(A) |] ==>                         \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   419
\           (f(CONS x l),g(CONS x l)) :                         \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   420
\               LListD_Fun (diag A) ((%u.(f(u),g(u)))``llist(A) Un  \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   421
\                                   diag(llist(A)))             \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   422
\ |] ==> f(M) = g(M)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   423
by (rtac LList_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   424
by (rtac (Mlist RS imageI) 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   425
by (rtac image_subsetI 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   426
by (etac llist.elim 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   427
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   428
by (stac NILcase 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   429
by (rtac (gMlist RS LListD_Fun_diag_I) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   430
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   431
by (REPEAT (ares_tac [CONScase] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   432
qed "LList_fun_equalityI";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   433
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   434
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   435
(*** The functional "Lmap" ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   436
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   437
Goal "Lmap f NIL = NIL";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   438
by (rtac (Lmap_def RS def_LList_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   439
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   440
qed "Lmap_NIL";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   441
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   442
Goal "Lmap f (CONS M N) = CONS (f M) (Lmap f N)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   443
by (rtac (Lmap_def RS def_LList_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   444
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   445
qed "Lmap_CONS";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   446
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   447
Addsimps [Lmap_NIL, Lmap_CONS];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   448
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   449
(*Another type-checking proof by coinduction*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   450
val [major,minor] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   451
    "[| M: llist(A);  !!x. x:A ==> f(x):B |] ==> Lmap f M: llist(B)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   452
by (rtac (major RS imageI RS llist_coinduct) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   453
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   454
by (etac llist.elim 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   455
by (ALLGOALS Asm_simp_tac);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   456
by (REPEAT (ares_tac [list_Fun_NIL_I, list_Fun_CONS_I, 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   457
                      minor, imageI, UnI1] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   458
qed "Lmap_type";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   459
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   460
(*This type checking rule synthesises a sufficiently large set for f*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   461
val [major] = goal LList.thy  "M: llist(A) ==> Lmap f M: llist(f``A)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   462
by (rtac (major RS Lmap_type) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   463
by (etac imageI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   464
qed "Lmap_type2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   465
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   466
(** Two easy results about Lmap **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   467
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   468
val [prem] = goalw LList.thy [o_def]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   469
    "M: llist(A) ==> Lmap (f o g) M = Lmap f (Lmap g M)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   470
by (rtac (prem RS imageI RS LList_equalityI) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   471
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   472
by (etac llist.elim 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   473
by (ALLGOALS Asm_simp_tac);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   474
by (REPEAT (ares_tac [LListD_Fun_NIL_I, imageI, UnI1,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   475
                      rangeI RS LListD_Fun_CONS_I] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   476
qed "Lmap_compose";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   477
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   478
val [prem] = goal LList.thy "M: llist(A) ==> Lmap (%x. x) M = M";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   479
by (rtac (prem RS imageI RS LList_equalityI) 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   480
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   481
by (etac llist.elim 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   482
by (ALLGOALS Asm_simp_tac);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   483
by (REPEAT (ares_tac [LListD_Fun_NIL_I, imageI RS UnI1,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   484
                      rangeI RS LListD_Fun_CONS_I] 1));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   485
qed "Lmap_ident";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   486
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   487
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   488
(*** Lappend -- its two arguments cause some complications! ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   489
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   490
Goalw [Lappend_def] "Lappend NIL NIL = NIL";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   491
by (rtac (LList_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   492
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   493
qed "Lappend_NIL_NIL";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   494
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   495
Goalw [Lappend_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   496
    "Lappend NIL (CONS N N') = CONS N (Lappend NIL N')";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   497
by (rtac (LList_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   498
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   499
qed "Lappend_NIL_CONS";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   500
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   501
Goalw [Lappend_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   502
    "Lappend (CONS M M') N = CONS M (Lappend M' N)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   503
by (rtac (LList_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   504
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   505
qed "Lappend_CONS";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   506
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   507
Addsimps [llist.NIL_I, Lappend_NIL_NIL, Lappend_NIL_CONS,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   508
          Lappend_CONS, LListD_Fun_CONS_I, range_eqI, image_eqI];
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   509
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   510
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5102
diff changeset
   511
Goal "M: llist(A) ==> Lappend NIL M = M";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   512
by (etac LList_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   513
by (ALLGOALS Asm_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   514
qed "Lappend_NIL";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   515
5143
b94cd208f073 Removal of leading "\!\!..." from most Goal commands
paulson
parents: 5102
diff changeset
   516
Goal "M: llist(A) ==> Lappend M NIL = M";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   517
by (etac LList_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   518
by (ALLGOALS Asm_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   519
qed "Lappend_NIL2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   520
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   521
Addsimps [Lappend_NIL, Lappend_NIL2];
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   522
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   523
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   524
(** Alternative type-checking proofs for Lappend **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   525
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   526
(*weak co-induction: bisimulation and case analysis on both variables*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   527
Goal "[| M: llist(A); N: llist(A) |] ==> Lappend M N: llist(A)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   528
by (res_inst_tac
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   529
    [("X", "UN u:llist(A). UN v: llist(A). {Lappend u v}")] llist_coinduct 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   530
by (Fast_tac 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   531
by Safe_tac;
5102
8c782c25a11e Adapted to new inductive definition package.
berghofe
parents: 5089
diff changeset
   532
by (eres_inst_tac [("aa", "u")] llist.elim 1);
8c782c25a11e Adapted to new inductive definition package.
berghofe
parents: 5089
diff changeset
   533
by (eres_inst_tac [("aa", "v")] llist.elim 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   534
by (ALLGOALS Asm_simp_tac);
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   535
by (Blast_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   536
qed "Lappend_type";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   537
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   538
(*strong co-induction: bisimulation and case analysis on one variable*)
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   539
Goal "[| M: llist(A); N: llist(A) |] ==> Lappend M N: llist(A)";
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   540
by (res_inst_tac [("X", "(%u. Lappend u N)``llist(A)")] llist_coinduct 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   541
by (etac imageI 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   542
by (rtac image_subsetI 1);
5102
8c782c25a11e Adapted to new inductive definition package.
berghofe
parents: 5089
diff changeset
   543
by (eres_inst_tac [("aa", "x")] llist.elim 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   544
by (asm_simp_tac (simpset() addsimps [list_Fun_llist_I]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   545
by (Asm_simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   546
qed "Lappend_type";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   547
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   548
(**** Lazy lists as the type 'a llist -- strongly typed versions of above ****)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   549
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   550
(** llist_case: case analysis for 'a llist **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   551
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   552
Addsimps ([Abs_llist_inverse, Rep_llist_inverse,
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   553
           Rep_llist, rangeI, inj_Leaf, inv_f_f] @ llist.intrs);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   554
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   555
Goalw [llist_case_def,LNil_def]  "llist_case c d LNil = c";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   556
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   557
qed "llist_case_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   558
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   559
Goalw [llist_case_def,LCons_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   560
    "llist_case c d (LCons M N) = d M N";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   561
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   562
qed "llist_case_LCons";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   563
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   564
(*Elimination is case analysis, not induction.*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   565
val [prem1,prem2] = goalw LList.thy [NIL_def,CONS_def]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   566
    "[| l=LNil ==> P;  !!x l'. l=LCons x l' ==> P \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   567
\    |] ==> P";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   568
by (rtac (Rep_llist RS llist.elim) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   569
by (rtac (inj_Rep_llist RS injD RS prem1) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   570
by (stac Rep_llist_LNil 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   571
by (assume_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   572
by (etac rangeE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   573
by (rtac (inj_Rep_llist RS injD RS prem2) 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   574
by (asm_simp_tac (simpset() delsimps [CONS_CONS_eq] 
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   575
		            addsimps [Rep_llist_LCons]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   576
by (etac (Abs_llist_inverse RS ssubst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   577
by (rtac refl 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   578
qed "llistE";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   579
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   580
(** llist_corec: corecursion for 'a llist **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   581
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   582
Goalw [llist_corec_def,LNil_def,LCons_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   583
    "llist_corec a f = sum_case (%u. LNil) \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   584
\                           (split(%z w. LCons z (llist_corec w f))) (f a)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   585
by (stac LList_corec 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   586
by (res_inst_tac [("s","f(a)")] sumE 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   587
by (asm_simp_tac (simpset() addsimps [LList_corec_type2]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   588
by (res_inst_tac [("p","y")] PairE 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   589
by (asm_simp_tac (simpset() addsimps [LList_corec_type2]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   590
(*FIXME: correct case splits usd to be found automatically:
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   591
by (ASM_SIMP_TAC(simpset() addsimps [LList_corec_type2]) 1);*)
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   592
qed "llist_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   593
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   594
(*definitional version of same*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   595
val [rew] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   596
    "[| !!x. h(x) == llist_corec x f |] ==>     \
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   597
\    h(a) = sum_case (%u. LNil) (split(%z w. LCons z (h w))) (f a)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   598
by (rewtac rew);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   599
by (rtac llist_corec 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   600
qed "def_llist_corec";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   601
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   602
(**** Proofs about type 'a llist functions ****)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   603
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   604
(*** Deriving llist_equalityI -- llist equality is a bisimulation ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   605
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   606
Goalw [LListD_Fun_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   607
    "r <= (llist A) Times (llist A) ==> \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   608
\           LListD_Fun (diag A) r <= (llist A) Times (llist A)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   609
by (stac llist_unfold 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   610
by (simp_tac (simpset() addsimps [NIL_def, CONS_def]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   611
by (Fast_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   612
qed "LListD_Fun_subset_Sigma_llist";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   613
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   614
Goal "prod_fun Rep_llist Rep_llist `` r <= \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   615
\    (llist(range Leaf)) Times (llist(range Leaf))";
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   616
by (fast_tac (claset() delrules [image_subsetI]
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   617
		       addIs [Rep_llist]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   618
qed "subset_Sigma_llist";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   619
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   620
val [prem] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   621
    "r <= (llist(range Leaf)) Times (llist(range Leaf)) ==> \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   622
\    prod_fun (Rep_llist o Abs_llist) (Rep_llist o Abs_llist) `` r <= r";
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   623
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   624
by (rtac (prem RS subsetD RS SigmaE2) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   625
by (assume_tac 1);
4521
c7f56322a84b Tidied by adding more default simprules
paulson
parents: 4477
diff changeset
   626
by (asm_simp_tac (simpset() addsimps [Abs_llist_inverse]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   627
qed "prod_fun_lemma";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   628
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   629
Goal "prod_fun Rep_llist  Rep_llist `` range(%x. (x, x)) = \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   630
\    diag(llist(range Leaf))";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   631
by (rtac equalityI 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   632
by (fast_tac (claset() addIs [Rep_llist]) 1);
4818
90dab9f7d81e split_all_tac is now added to claset() _before_ other safe tactics
oheimb
parents: 4521
diff changeset
   633
by (fast_tac (claset() delSWrapper "split_all_tac"
90dab9f7d81e split_all_tac is now added to claset() _before_ other safe tactics
oheimb
parents: 4521
diff changeset
   634
		       addSEs [Abs_llist_inverse RS subst]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   635
qed "prod_fun_range_eq_diag";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   636
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   637
(*Surprisingly hard to prove.  Used with lfilter*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   638
Goalw [llistD_Fun_def, prod_fun_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   639
    "A<=B ==> llistD_Fun A <= llistD_Fun B";
4477
b3e5857d8d99 New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents: 4160
diff changeset
   640
by Auto_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   641
by (rtac image_eqI 1);
4089
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   642
by (fast_tac (claset() addss (simpset())) 1);
96fba19bcbe2 isatool fixclasimp;
wenzelm
parents: 3919
diff changeset
   643
by (blast_tac (claset() addIs [impOfSubs LListD_Fun_mono]) 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   644
qed "llistD_Fun_mono";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   645
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   646
(** To show two llists are equal, exhibit a bisimulation! 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   647
      [also admits true equality] **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   648
val [prem1,prem2] = goalw LList.thy [llistD_Fun_def]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   649
    "[| (l1,l2) : r;  r <= llistD_Fun(r Un range(%x.(x,x))) |] ==> l1=l2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   650
by (rtac (inj_Rep_llist RS injD) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   651
by (res_inst_tac [("r", "prod_fun Rep_llist Rep_llist ``r"),
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   652
                  ("A", "range(Leaf)")] 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   653
        LList_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   654
by (rtac (prem1 RS prod_fun_imageI) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   655
by (rtac (prem2 RS image_mono RS subset_trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   656
by (rtac (image_compose RS subst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   657
by (rtac (prod_fun_compose RS subst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   658
by (stac image_Un 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   659
by (stac prod_fun_range_eq_diag 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   660
by (rtac (LListD_Fun_subset_Sigma_llist RS prod_fun_lemma) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   661
by (rtac (subset_Sigma_llist RS Un_least) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   662
by (rtac diag_subset_Sigma 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   663
qed "llist_equalityI";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   664
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   665
(** Rules to prove the 2nd premise of llist_equalityI **)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   666
Goalw [llistD_Fun_def,LNil_def] "(LNil,LNil) : llistD_Fun(r)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   667
by (rtac (LListD_Fun_NIL_I RS prod_fun_imageI) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   668
qed "llistD_Fun_LNil_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   669
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   670
val [prem] = goalw LList.thy [llistD_Fun_def,LCons_def]
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   671
    "(l1,l2):r ==> (LCons x l1, LCons x l2) : llistD_Fun(r)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   672
by (rtac (rangeI RS LListD_Fun_CONS_I RS prod_fun_imageI) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   673
by (rtac (prem RS prod_fun_imageI) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   674
qed "llistD_Fun_LCons_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   675
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   676
(*Utilise the "strong" part, i.e. gfp(f)*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   677
Goalw [llistD_Fun_def]
5148
74919e8f221c More tidying and removal of "\!\!... from Goal commands
paulson
parents: 5143
diff changeset
   678
     "(l,l) : llistD_Fun(r Un range(%x.(x,x)))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   679
by (rtac (Rep_llist_inverse RS subst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   680
by (rtac prod_fun_imageI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   681
by (stac image_Un 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   682
by (stac prod_fun_range_eq_diag 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   683
by (rtac (Rep_llist RS LListD_Fun_diag_I) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   684
qed "llistD_Fun_range_I";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   685
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   686
(*A special case of list_equality for functions over lazy lists*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   687
val [prem1,prem2] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   688
    "[| f(LNil)=g(LNil);                                                \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   689
\       !!x l. (f(LCons x l),g(LCons x l)) :                            \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   690
\              llistD_Fun(range(%u. (f(u),g(u))) Un range(%v. (v,v)))   \
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   691
\    |] ==> f(l) = (g(l :: 'a llist) :: 'b llist)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   692
by (res_inst_tac [("r", "range(%u. (f(u),g(u)))")] llist_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   693
by (rtac rangeI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   694
by (rtac subsetI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   695
by (etac rangeE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   696
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   697
by (res_inst_tac [("l", "u")] llistE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   698
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   699
by (stac prem1 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   700
by (rtac llistD_Fun_range_I 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   701
by (etac ssubst 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   702
by (rtac prem2 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   703
qed "llist_fun_equalityI";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   704
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   705
(*simpset for llist bisimulations*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   706
Addsimps [llist_case_LNil, llist_case_LCons, 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   707
          llistD_Fun_LNil_I, llistD_Fun_LCons_I];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   708
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   709
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   710
(*** The functional "lmap" ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   711
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   712
Goal "lmap f LNil = LNil";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   713
by (rtac (lmap_def RS def_llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   714
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   715
qed "lmap_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   716
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   717
Goal "lmap f (LCons M N) = LCons (f M) (lmap f N)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   718
by (rtac (lmap_def RS def_llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   719
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   720
qed "lmap_LCons";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   721
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   722
Addsimps [lmap_LNil, lmap_LCons];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   723
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   724
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   725
(** Two easy results about lmap **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   726
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   727
Goal "lmap (f o g) l = lmap f (lmap g l)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   728
by (res_inst_tac [("l","l")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   729
by (ALLGOALS Simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   730
qed "lmap_compose";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   731
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   732
Goal "lmap (%x. x) l = l";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   733
by (res_inst_tac [("l","l")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   734
by (ALLGOALS Simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   735
qed "lmap_ident";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   736
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   737
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   738
(*** iterates -- llist_fun_equalityI cannot be used! ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   739
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   740
Goal "iterates f x = LCons x (iterates f (f x))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   741
by (rtac (iterates_def RS def_llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   742
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   743
qed "iterates";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   744
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   745
Goal "lmap f (iterates f x) = iterates f (f x)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   746
by (res_inst_tac [("r", "range(%u.(lmap f (iterates f u),iterates f (f u)))")] 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   747
    llist_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   748
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   749
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   750
by (res_inst_tac [("x1", "f(u)")] (iterates RS ssubst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   751
by (res_inst_tac [("x1", "u")] (iterates RS ssubst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   752
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   753
qed "lmap_iterates";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   754
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   755
Goal "iterates f x = LCons x (lmap f (iterates f x))";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   756
by (stac lmap_iterates 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   757
by (rtac iterates 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   758
qed "iterates_lmap";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   759
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   760
(*** A rather complex proof about iterates -- cf Andy Pitts ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   761
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   762
(** Two lemmas about natrec n x (%m.g), which is essentially (g^n)(x) **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   763
5278
a903b66822e2 even more tidying of Goal commands
paulson
parents: 5184
diff changeset
   764
Goal "nat_rec (LCons b l) (%m. lmap(f)) n =      \
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   765
\    LCons (nat_rec b (%m. f) n) (nat_rec l (%m. lmap(f)) n)";
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   766
by (induct_tac "n" 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   767
by (ALLGOALS Asm_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   768
qed "fun_power_lmap";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   769
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   770
goal Nat.thy "nat_rec (g x) (%m. g) n = nat_rec x (%m. g) (Suc n)";
5184
9b8547a9496a Adapted to new datatype package.
berghofe
parents: 5148
diff changeset
   771
by (induct_tac "n" 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   772
by (ALLGOALS Asm_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   773
qed "fun_power_Suc";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   774
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   775
val Pair_cong = read_instantiate_sg (sign_of Prod.thy)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   776
 [("f","Pair")] (standard(refl RS cong RS cong));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   777
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   778
(*The bisimulation consists of {(lmap(f)^n (h(u)), lmap(f)^n (iterates(f,u)))}
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   779
  for all u and all n::nat.*)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   780
val [prem] = goal LList.thy
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   781
    "(!!x. h(x) = LCons x (lmap f (h x))) ==> h = iterates(f)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   782
by (rtac ext 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   783
by (res_inst_tac [("r", 
3842
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   784
   "UN u. range(%n. (nat_rec (h u) (%m y. lmap f y) n, \
b55686a7b22c fixed dots;
wenzelm
parents: 3427
diff changeset
   785
\                    nat_rec (iterates f u) (%m y. lmap f y) n))")] 
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   786
    llist_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   787
by (REPEAT (resolve_tac [UN1_I, range_eqI, Pair_cong, nat_rec_0 RS sym] 1));
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   788
by (Clarify_tac 1);
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   789
by (stac iterates 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   790
by (stac prem 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   791
by (stac fun_power_lmap 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   792
by (stac fun_power_lmap 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   793
by (rtac llistD_Fun_LCons_I 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   794
by (rtac (lmap_iterates RS subst) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   795
by (stac fun_power_Suc 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   796
by (stac fun_power_Suc 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   797
by (rtac (UN1_I RS UnI1) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   798
by (rtac rangeI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   799
qed "iterates_equality";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   800
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   801
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   802
(*** lappend -- its two arguments cause some complications! ***)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   803
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   804
Goalw [lappend_def] "lappend LNil LNil = LNil";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   805
by (rtac (llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   806
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   807
qed "lappend_LNil_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   808
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   809
Goalw [lappend_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   810
    "lappend LNil (LCons l l') = LCons l (lappend LNil l')";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   811
by (rtac (llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   812
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   813
qed "lappend_LNil_LCons";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   814
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   815
Goalw [lappend_def]
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   816
    "lappend (LCons l l') N = LCons l (lappend l' N)";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   817
by (rtac (llist_corec RS trans) 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   818
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   819
qed "lappend_LCons";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   820
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   821
Addsimps [lappend_LNil_LNil, lappend_LNil_LCons, lappend_LCons];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   822
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   823
Goal "lappend LNil l = l";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   824
by (res_inst_tac [("l","l")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   825
by (ALLGOALS Simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   826
qed "lappend_LNil";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   827
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   828
Goal "lappend l LNil = l";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   829
by (res_inst_tac [("l","l")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   830
by (ALLGOALS Simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   831
qed "lappend_LNil2";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   832
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   833
Addsimps [lappend_LNil, lappend_LNil2];
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   834
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   835
(*The infinite first argument blocks the second*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   836
Goal "lappend (iterates f x) N = iterates f x";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   837
by (res_inst_tac [("r", "range(%u.(lappend (iterates f u) N,iterates f u))")] 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   838
    llist_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   839
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   840
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   841
by (stac iterates 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   842
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   843
qed "lappend_iterates";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   844
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   845
(** Two proofs that lmap distributes over lappend **)
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   846
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   847
(*Long proof requiring case analysis on both both arguments*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   848
Goal "lmap f (lappend l n) = lappend (lmap f l) (lmap f n)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   849
by (res_inst_tac 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   850
    [("r",  
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   851
      "UN n. range(%l.(lmap f (lappend l n),lappend (lmap f l) (lmap f n)))")] 
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   852
    llist_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   853
by (rtac UN1_I 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   854
by (rtac rangeI 1);
4160
59826ea67cba Adapted to removal of UN1_I, etc
paulson
parents: 4089
diff changeset
   855
by Safe_tac;
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   856
by (res_inst_tac [("l", "l")] llistE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   857
by (res_inst_tac [("l", "n")] llistE 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   858
by (ALLGOALS Asm_simp_tac);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   859
by (REPEAT_SOME (ares_tac [llistD_Fun_LCons_I, UN1_I RS UnI1, rangeI]));
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   860
qed "lmap_lappend_distrib";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   861
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   862
(*Shorter proof of theorem above using llist_equalityI as strong coinduction*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   863
Goal "lmap f (lappend l n) = lappend (lmap f l) (lmap f n)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   864
by (res_inst_tac [("l","l")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   865
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   866
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   867
qed "lmap_lappend_distrib";
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   868
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   869
(*Without strong coinduction, three case analyses might be needed*)
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4831
diff changeset
   870
Goal "lappend (lappend l1 l2) l3 = lappend l1 (lappend l2 l3)";
3120
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   871
by (res_inst_tac [("l","l1")] llist_fun_equalityI 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   872
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   873
by (Simp_tac 1);
c58423c20740 New directory to contain examples of (co)inductive definitions
paulson
parents:
diff changeset
   874
qed "lappend_assoc";