0
+ − 1
theory QuotList
600
+ − 2
imports QuotMain List
0
+ − 3
begin
+ − 4
+ − 5
fun
537
+ − 6
list_rel
0
+ − 7
where
537
+ − 8
"list_rel R [] [] = True"
+ − 9
| "list_rel R (x#xs) [] = False"
+ − 10
| "list_rel R [] (x#xs) = False"
+ − 11
| "list_rel R (x#xs) (y#ys) = (R x y \<and> list_rel R xs ys)"
0
+ − 12
600
+ − 13
declare [[map list = (map, list_rel)]]
+ − 14
636
+ − 15
lemma list_equivp[quot_equiv]:
529
+ − 16
assumes a: "equivp R"
537
+ − 17
shows "equivp (list_rel R)"
539
+ − 18
unfolding equivp_def
+ − 19
apply(rule allI)+
+ − 20
apply(induct_tac x y rule: list_induct2')
+ − 21
apply(simp_all add: expand_fun_eq)
+ − 22
apply(metis list_rel.simps(1) list_rel.simps(2))
+ − 23
apply(metis list_rel.simps(1) list_rel.simps(2))
+ − 24
apply(rule iffI)
+ − 25
apply(rule allI)
+ − 26
apply(case_tac x)
+ − 27
apply(simp_all)
+ − 28
using a
+ − 29
apply(unfold equivp_def)
+ − 30
apply(auto)[1]
+ − 31
apply(metis list_rel.simps(4))
+ − 32
done
0
+ − 33
539
+ − 34
lemma list_rel_rel:
529
+ − 35
assumes q: "Quotient R Abs Rep"
537
+ − 36
shows "list_rel R r s = (list_rel R r r \<and> list_rel R s s \<and> (map Abs r = map Abs s))"
539
+ − 37
apply(induct r s rule: list_induct2')
+ − 38
apply(simp_all)
+ − 39
using Quotient_rel[OF q]
+ − 40
apply(metis)
+ − 41
done
0
+ − 42
636
+ − 43
lemma list_quotient[quot_thm]:
529
+ − 44
assumes q: "Quotient R Abs Rep"
537
+ − 45
shows "Quotient (list_rel R) (map Abs) (map Rep)"
539
+ − 46
unfolding Quotient_def
+ − 47
apply(rule conjI)
+ − 48
apply(rule allI)
+ − 49
apply(induct_tac a)
+ − 50
apply(simp)
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 51
apply(simp add: Quotient_abs_rep[OF q])
539
+ − 52
apply(rule conjI)
+ − 53
apply(rule allI)
+ − 54
apply(induct_tac a)
+ − 55
apply(simp)
+ − 56
apply(simp)
541
+ − 57
apply(simp add: Quotient_rep_reflp[OF q])
539
+ − 58
apply(rule allI)+
+ − 59
apply(rule list_rel_rel[OF q])
+ − 60
done
+ − 61
768
e9e205b904e2
get_fun needed change to cope with "('a fset) fset" types...this needs composition (op o); now id_simps contains also id_o and o_id, and map_id is also added in QuotList.thy; regularize and cleaning needed to be hacked (indicated by "HACK")...THIS NEEDS ATTENTION!!!; except two lemmas in IntEx, all examples go through; added considerable material to FSet3; tuned FIXME-TODO
Christian Urban <urbanc@in.tum.de>
diff
changeset
+ − 62
lemma map_id[id_simps]: "map id \<equiv> id"
600
+ − 63
apply (rule eq_reflection)
+ − 64
apply (rule ext)
+ − 65
apply (rule_tac list="x" in list.induct)
+ − 66
apply (simp_all)
+ − 67
done
+ − 68
644
+ − 69
lemma cons_prs_aux:
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 70
assumes q: "Quotient R Abs Rep"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 71
shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 72
by (induct t) (simp_all add: Quotient_abs_rep[OF q])
539
+ − 73
644
+ − 74
lemma cons_prs[quot_preserve]:
+ − 75
assumes q: "Quotient R Abs Rep"
+ − 76
shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
+ − 77
by (simp only: expand_fun_eq fun_map.simps cons_prs_aux[OF q])
+ − 78
(simp)
+ − 79
636
+ − 80
lemma cons_rsp[quot_respect]:
529
+ − 81
assumes q: "Quotient R Abs Rep"
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 82
shows "(R ===> list_rel R ===> list_rel R) op # op #"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 83
by (auto)
0
+ − 84
644
+ − 85
lemma nil_prs[quot_preserve]:
529
+ − 86
assumes q: "Quotient R Abs Rep"
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 87
shows "map Abs [] \<equiv> []"
0
+ − 88
by (simp)
+ − 89
636
+ − 90
lemma nil_rsp[quot_respect]:
529
+ − 91
assumes q: "Quotient R Abs Rep"
537
+ − 92
shows "list_rel R [] []"
0
+ − 93
by simp
+ − 94
645
+ − 95
lemma map_prs_aux:
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 96
assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 97
and b: "Quotient R2 abs2 rep2"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 98
shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 99
by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
0
+ − 100
645
+ − 101
+ − 102
lemma map_prs[quot_preserve]:
+ − 103
assumes a: "Quotient R1 abs1 rep1"
+ − 104
and b: "Quotient R2 abs2 rep2"
+ − 105
shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
+ − 106
by (simp only: expand_fun_eq fun_map.simps map_prs_aux[OF a b])
+ − 107
(simp)
+ − 108
+ − 109
636
+ − 110
lemma map_rsp[quot_respect]:
529
+ − 111
assumes q1: "Quotient R1 Abs1 Rep1"
+ − 112
and q2: "Quotient R2 Abs2 Rep2"
565
+ − 113
shows "((R1 ===> R2) ===> (list_rel R1) ===> list_rel R2) map map"
+ − 114
apply(simp)
+ − 115
apply(rule allI)+
+ − 116
apply(rule impI)
+ − 117
apply(rule allI)+
+ − 118
apply (induct_tac xa ya rule: list_induct2')
+ − 119
apply simp_all
+ − 120
done
+ − 121
645
+ − 122
lemma foldr_prs_aux:
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 123
assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 124
and b: "Quotient R2 abs2 rep2"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 125
shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 126
by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 127
796
+ − 128
lemma foldr_prs[quot_preserve]:
645
+ − 129
assumes a: "Quotient R1 abs1 rep1"
+ − 130
and b: "Quotient R2 abs2 rep2"
+ − 131
shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
+ − 132
by (simp only: expand_fun_eq fun_map.simps foldr_prs_aux[OF a b])
+ − 133
(simp)
+ − 134
+ − 135
lemma foldl_prs_aux:
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 136
assumes a: "Quotient R1 abs1 rep1"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 137
and b: "Quotient R2 abs2 rep2"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 138
shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 139
by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
0
+ − 140
645
+ − 141
+ − 142
lemma foldl_prs[quot_preserve]:
+ − 143
assumes a: "Quotient R1 abs1 rep1"
+ − 144
and b: "Quotient R2 abs2 rep2"
+ − 145
shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
+ − 146
by (simp only: expand_fun_eq fun_map.simps foldl_prs_aux[OF a b])
+ − 147
(simp)
+ − 148
565
+ − 149
lemma list_rel_empty: "list_rel R [] b \<Longrightarrow> length b = 0"
+ − 150
by (induct b) (simp_all)
0
+ − 151
565
+ − 152
lemma list_rel_len: "list_rel R a b \<Longrightarrow> length a = length b"
+ − 153
apply (induct a arbitrary: b)
+ − 154
apply (simp add: list_rel_empty)
+ − 155
apply (case_tac b)
+ − 156
apply simp_all
+ − 157
done
0
+ − 158
668
+ − 159
(* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
636
+ − 160
lemma foldl_rsp[quot_respect]:
565
+ − 161
assumes q1: "Quotient R1 Abs1 Rep1"
+ − 162
and q2: "Quotient R2 Abs2 Rep2"
+ − 163
shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_rel R2 ===> R1) foldl foldl"
+ − 164
apply auto
+ − 165
apply (subgoal_tac "R1 xa ya \<longrightarrow> list_rel R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
+ − 166
apply simp
+ − 167
apply (rule_tac x="xa" in spec)
+ − 168
apply (rule_tac x="ya" in spec)
+ − 169
apply (rule_tac xs="xb" and ys="yb" in list_induct2)
+ − 170
apply (rule list_rel_len)
+ − 171
apply (simp_all)
+ − 172
done
+ − 173
666
+ − 174
lemma foldr_rsp[quot_respect]:
+ − 175
assumes q1: "Quotient R1 Abs1 Rep1"
+ − 176
and q2: "Quotient R2 Abs2 Rep2"
+ − 177
shows "((R1 ===> R2 ===> R2) ===> list_rel R1 ===> R2 ===> R2) foldr foldr"
+ − 178
apply auto
+ − 179
apply(subgoal_tac "R2 xb yb \<longrightarrow> list_rel R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
+ − 180
apply simp
+ − 181
apply (rule_tac xs="xa" and ys="ya" in list_induct2)
+ − 182
apply (rule list_rel_len)
+ − 183
apply (simp_all)
+ − 184
done
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 185
666
+ − 186
(* Rest are unused *)
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 187
541
+ − 188
lemma list_rel_eq:
539
+ − 189
shows "list_rel (op =) \<equiv> (op =)"
+ − 190
apply(rule eq_reflection)
+ − 191
unfolding expand_fun_eq
+ − 192
apply(rule allI)+
+ − 193
apply(induct_tac x xa rule: list_induct2')
+ − 194
apply(simp_all)
+ − 195
done
0
+ − 196
541
+ − 197
lemma list_rel_refl:
539
+ − 198
assumes a: "\<And>x y. R x y = (R x = R y)"
+ − 199
shows "list_rel R x x"
+ − 200
by (induct x) (auto simp add: a)
0
+ − 201
539
+ − 202
end