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