991 |
991 |
992 lemma list_all2_rev [iff]: |
992 lemma list_all2_rev [iff]: |
993 "list_all2 P (rev xs) (rev ys) = list_all2 P xs ys" |
993 "list_all2 P (rev xs) (rev ys) = list_all2 P xs ys" |
994 by (simp add: list_all2_def zip_rev cong: conj_cong) |
994 by (simp add: list_all2_def zip_rev cong: conj_cong) |
995 |
995 |
|
996 lemma list_all2_rev1: |
|
997 "list_all2 P (rev xs) ys = list_all2 P xs (rev ys)" |
|
998 by (subst list_all2_rev [symmetric]) simp |
|
999 |
996 lemma list_all2_append1: |
1000 lemma list_all2_append1: |
997 "list_all2 P (xs @ ys) zs = |
1001 "list_all2 P (xs @ ys) zs = |
998 (EX us vs. zs = us @ vs \<and> length us = length xs \<and> length vs = length ys \<and> |
1002 (EX us vs. zs = us @ vs \<and> length us = length xs \<and> length vs = length ys \<and> |
999 list_all2 P xs us \<and> list_all2 P ys vs)" |
1003 list_all2 P xs us \<and> list_all2 P ys vs)" |
1000 apply (simp add: list_all2_def zip_append1) |
1004 apply (simp add: list_all2_def zip_append1) |
1017 apply (force split: nat_diff_split simp add: min_def) |
1021 apply (force split: nat_diff_split simp add: min_def) |
1018 apply clarify |
1022 apply clarify |
1019 apply (simp add: ball_Un) |
1023 apply (simp add: ball_Un) |
1020 done |
1024 done |
1021 |
1025 |
|
1026 lemma list_all2_append: |
|
1027 "\<And>b. length a = length b \<Longrightarrow> |
|
1028 list_all2 P (a@c) (b@d) = (list_all2 P a b \<and> list_all2 P c d)" |
|
1029 apply (induct a) |
|
1030 apply simp |
|
1031 apply (case_tac b) |
|
1032 apply auto |
|
1033 done |
|
1034 |
|
1035 lemma list_all2_appendI [intro?, trans]: |
|
1036 "\<lbrakk> list_all2 P a b; list_all2 P c d \<rbrakk> \<Longrightarrow> list_all2 P (a@c) (b@d)" |
|
1037 by (simp add: list_all2_append list_all2_lengthD) |
|
1038 |
1022 lemma list_all2_conv_all_nth: |
1039 lemma list_all2_conv_all_nth: |
1023 "list_all2 P xs ys = |
1040 "list_all2 P xs ys = |
1024 (length xs = length ys \<and> (\<forall>i < length xs. P (xs!i) (ys!i)))" |
1041 (length xs = length ys \<and> (\<forall>i < length xs. P (xs!i) (ys!i)))" |
1025 by (force simp add: list_all2_def set_zip) |
1042 by (force simp add: list_all2_def set_zip) |
1026 |
1043 |
|
1044 lemma list_all2_all_nthI [intro?]: |
|
1045 "length a = length b \<Longrightarrow> (\<And>n. n < length a \<Longrightarrow> P (a!n) (b!n)) \<Longrightarrow> list_all2 P a b" |
|
1046 by (simp add: list_all2_conv_all_nth) |
|
1047 |
|
1048 lemma list_all2_nthD [dest?]: |
|
1049 "\<lbrakk> list_all2 P xs ys; p < size xs \<rbrakk> \<Longrightarrow> P (xs!p) (ys!p)" |
|
1050 by (simp add: list_all2_conv_all_nth) |
|
1051 |
|
1052 lemma list_all2_map1: |
|
1053 "list_all2 P (map f as) bs = list_all2 (\<lambda>x y. P (f x) y) as bs" |
|
1054 by (simp add: list_all2_conv_all_nth) |
|
1055 |
|
1056 lemma list_all2_map2: |
|
1057 "list_all2 P as (map f bs) = list_all2 (\<lambda>x y. P x (f y)) as bs" |
|
1058 by (auto simp add: list_all2_conv_all_nth) |
|
1059 |
1027 lemma list_all2_trans[rule_format]: |
1060 lemma list_all2_trans[rule_format]: |
1028 "\<forall>a b c. P1 a b --> P2 b c --> P3 a c ==> |
1061 "\<forall>a b c. P1 a b --> P2 b c --> P3 a c ==> |
1029 \<forall>bs cs. list_all2 P1 as bs --> list_all2 P2 bs cs --> list_all2 P3 as cs" |
1062 \<forall>bs cs. list_all2 P1 as bs --> list_all2 P2 bs cs --> list_all2 P3 as cs" |
1030 apply(induct_tac as) |
1063 apply(induct_tac as) |
1031 apply simp |
1064 apply simp |
1034 apply simp |
1067 apply simp |
1035 apply(rule allI) |
1068 apply(rule allI) |
1036 apply(induct_tac cs) |
1069 apply(induct_tac cs) |
1037 apply auto |
1070 apply auto |
1038 done |
1071 done |
|
1072 |
|
1073 lemma list_all2_refl: |
|
1074 "(\<And>x. P x x) \<Longrightarrow> list_all2 P xs xs" |
|
1075 by (simp add: list_all2_conv_all_nth) |
|
1076 |
|
1077 lemma list_all2_update_cong: |
|
1078 "\<lbrakk> i<size xs; list_all2 P xs ys; P x y \<rbrakk> \<Longrightarrow> list_all2 P (xs[i:=x]) (ys[i:=y])" |
|
1079 by (simp add: list_all2_conv_all_nth nth_list_update) |
|
1080 |
|
1081 lemma list_all2_update_cong2: |
|
1082 "\<lbrakk>list_all2 P xs ys; P x y; i < length ys\<rbrakk> \<Longrightarrow> list_all2 P (xs[i:=x]) (ys[i:=y])" |
|
1083 by (simp add: list_all2_lengthD list_all2_update_cong) |
|
1084 |
|
1085 lemma list_all2_dropI [intro?]: |
|
1086 "\<And>n bs. list_all2 P as bs \<Longrightarrow> list_all2 P (drop n as) (drop n bs)" |
|
1087 apply (induct as) |
|
1088 apply simp |
|
1089 apply (clarsimp simp add: list_all2_Cons1) |
|
1090 apply (case_tac n) |
|
1091 apply simp |
|
1092 apply simp |
|
1093 done |
|
1094 |
|
1095 lemma list_all2_mono [intro?]: |
|
1096 "\<And>y. list_all2 P x y \<Longrightarrow> (\<And>x y. P x y \<Longrightarrow> Q x y) \<Longrightarrow> list_all2 Q x y" |
|
1097 apply (induct x) |
|
1098 apply simp |
|
1099 apply (case_tac y) |
|
1100 apply auto |
|
1101 done |
1039 |
1102 |
1040 |
1103 |
1041 subsection {* @{text foldl} *} |
1104 subsection {* @{text foldl} *} |
1042 |
1105 |
1043 lemma foldl_append [simp]: |
1106 lemma foldl_append [simp]: |
1132 lemma nth_equalityI: |
1195 lemma nth_equalityI: |
1133 "[| length xs = length ys; ALL i < length xs. xs!i = ys!i |] ==> xs = ys" |
1196 "[| length xs = length ys; ALL i < length xs. xs!i = ys!i |] ==> xs = ys" |
1134 apply (frule nth_take_lemma [OF le_refl eq_imp_le]) |
1197 apply (frule nth_take_lemma [OF le_refl eq_imp_le]) |
1135 apply (simp_all add: take_all) |
1198 apply (simp_all add: take_all) |
1136 done |
1199 done |
|
1200 |
|
1201 (* needs nth_equalityI *) |
|
1202 lemma list_all2_antisym: |
|
1203 "\<lbrakk> (\<And>x y. \<lbrakk>P x y; Q y x\<rbrakk> \<Longrightarrow> x = y); list_all2 P xs ys; list_all2 Q ys xs \<rbrakk> |
|
1204 \<Longrightarrow> xs = ys" |
|
1205 apply (simp add: list_all2_conv_all_nth) |
|
1206 apply (rule nth_equalityI) |
|
1207 apply blast |
|
1208 apply simp |
|
1209 done |
1137 |
1210 |
1138 lemma take_equalityI: "(\<forall>i. take i xs = take i ys) ==> xs = ys" |
1211 lemma take_equalityI: "(\<forall>i. take i xs = take i ys) ==> xs = ys" |
1139 -- {* The famous take-lemma. *} |
1212 -- {* The famous take-lemma. *} |
1140 apply (drule_tac x = "max (length xs) (length ys)" in spec) |
1213 apply (drule_tac x = "max (length xs) (length ys)" in spec) |
1141 apply (simp add: le_max_iff_disj take_all) |
1214 apply (simp add: le_max_iff_disj take_all) |