| author | wenzelm | 
| Thu, 19 Dec 2019 15:29:48 +0100 | |
| changeset 71318 | 1be996d8bb98 | 
| parent 71258 | d67924987c34 | 
| child 71449 | 3cf130a896a3 | 
| permissions | -rw-r--r-- | 
| 47317 
432b29a96f61
modernized obsolete old-style theory name with proper new-style underscore
 huffman parents: 
47222diff
changeset | 1 | (* Title: HOL/Set_Interval.thy | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 2 | Author: Tobias Nipkow, Clemens Ballarin, Jeremy Avigad | 
| 8924 | 3 | |
| 13735 | 4 | lessThan, greaterThan, atLeast, atMost and two-sided intervals | 
| 51334 | 5 | |
| 6 | Modern convention: Ixy stands for an interval where x and y | |
| 7 | describe the lower and upper bound and x,y : {c,o,i}
 | |
| 8 | where c = closed, o = open, i = infinite. | |
| 9 | Examples: Ico = {_ ..< _} and Ici = {_ ..}
 | |
| 8924 | 10 | *) | 
| 11 | ||
| 60758 | 12 | section \<open>Set intervals\<close> | 
| 14577 | 13 | |
| 47317 
432b29a96f61
modernized obsolete old-style theory name with proper new-style underscore
 huffman parents: 
47222diff
changeset | 14 | theory Set_Interval | 
| 66836 | 15 | imports Divides | 
| 15131 | 16 | begin | 
| 8924 | 17 | |
| 24691 | 18 | context ord | 
| 19 | begin | |
| 44008 | 20 | |
| 24691 | 21 | definition | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32596diff
changeset | 22 |   lessThan    :: "'a => 'a set" ("(1{..<_})") where
 | 
| 25062 | 23 |   "{..<u} == {x. x < u}"
 | 
| 24691 | 24 | |
| 25 | definition | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32596diff
changeset | 26 |   atMost      :: "'a => 'a set" ("(1{.._})") where
 | 
| 25062 | 27 |   "{..u} == {x. x \<le> u}"
 | 
| 24691 | 28 | |
| 29 | definition | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32596diff
changeset | 30 |   greaterThan :: "'a => 'a set" ("(1{_<..})") where
 | 
| 25062 | 31 |   "{l<..} == {x. l<x}"
 | 
| 24691 | 32 | |
| 33 | definition | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32596diff
changeset | 34 |   atLeast     :: "'a => 'a set" ("(1{_..})") where
 | 
| 25062 | 35 |   "{l..} == {x. l\<le>x}"
 | 
| 24691 | 36 | |
| 37 | definition | |
| 25062 | 38 |   greaterThanLessThan :: "'a => 'a => 'a set"  ("(1{_<..<_})") where
 | 
| 39 |   "{l<..<u} == {l<..} Int {..<u}"
 | |
| 24691 | 40 | |
| 41 | definition | |
| 25062 | 42 |   atLeastLessThan :: "'a => 'a => 'a set"      ("(1{_..<_})") where
 | 
| 43 |   "{l..<u} == {l..} Int {..<u}"
 | |
| 24691 | 44 | |
| 45 | definition | |
| 25062 | 46 |   greaterThanAtMost :: "'a => 'a => 'a set"    ("(1{_<.._})") where
 | 
| 47 |   "{l<..u} == {l<..} Int {..u}"
 | |
| 24691 | 48 | |
| 49 | definition | |
| 25062 | 50 |   atLeastAtMost :: "'a => 'a => 'a set"        ("(1{_.._})") where
 | 
| 51 |   "{l..u} == {l..} Int {..u}"
 | |
| 24691 | 52 | |
| 53 | end | |
| 8924 | 54 | |
| 13735 | 55 | |
| 69593 | 56 | text\<open>A note of warning when using \<^term>\<open>{..<n}\<close> on type \<^typ>\<open>nat\<close>: it is equivalent to \<^term>\<open>{0::nat..<n}\<close> but some lemmas involving
 | 
| 57 | \<^term>\<open>{m..<n}\<close> may not exist in \<^term>\<open>{..<n}\<close>-form as well.\<close>
 | |
| 15048 | 58 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 59 | syntax (ASCII) | 
| 36364 
0e2679025aeb
fix syntax precedence declarations for UNION, INTER, SUP, INF
 huffman parents: 
36307diff
changeset | 60 |   "_UNION_le"   :: "'a => 'a => 'b set => 'b set"       ("(3UN _<=_./ _)" [0, 0, 10] 10)
 | 
| 
0e2679025aeb
fix syntax precedence declarations for UNION, INTER, SUP, INF
 huffman parents: 
36307diff
changeset | 61 |   "_UNION_less" :: "'a => 'a => 'b set => 'b set"       ("(3UN _<_./ _)" [0, 0, 10] 10)
 | 
| 
0e2679025aeb
fix syntax precedence declarations for UNION, INTER, SUP, INF
 huffman parents: 
36307diff
changeset | 62 |   "_INTER_le"   :: "'a => 'a => 'b set => 'b set"       ("(3INT _<=_./ _)" [0, 0, 10] 10)
 | 
| 
0e2679025aeb
fix syntax precedence declarations for UNION, INTER, SUP, INF
 huffman parents: 
36307diff
changeset | 63 |   "_INTER_less" :: "'a => 'a => 'b set => 'b set"       ("(3INT _<_./ _)" [0, 0, 10] 10)
 | 
| 14418 | 64 | |
| 30372 | 65 | syntax (latex output) | 
| 62789 | 66 |   "_UNION_le"   :: "'a \<Rightarrow> 'a => 'b set => 'b set"       ("(3\<Union>(\<open>unbreakable\<close>_ \<le> _)/ _)" [0, 0, 10] 10)
 | 
| 67 |   "_UNION_less" :: "'a \<Rightarrow> 'a => 'b set => 'b set"       ("(3\<Union>(\<open>unbreakable\<close>_ < _)/ _)" [0, 0, 10] 10)
 | |
| 68 |   "_INTER_le"   :: "'a \<Rightarrow> 'a => 'b set => 'b set"       ("(3\<Inter>(\<open>unbreakable\<close>_ \<le> _)/ _)" [0, 0, 10] 10)
 | |
| 69 |   "_INTER_less" :: "'a \<Rightarrow> 'a => 'b set => 'b set"       ("(3\<Inter>(\<open>unbreakable\<close>_ < _)/ _)" [0, 0, 10] 10)
 | |
| 14418 | 70 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 71 | syntax | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 72 |   "_UNION_le"   :: "'a => 'a => 'b set => 'b set"       ("(3\<Union>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 73 |   "_UNION_less" :: "'a => 'a => 'b set => 'b set"       ("(3\<Union>_<_./ _)" [0, 0, 10] 10)
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 74 |   "_INTER_le"   :: "'a => 'a => 'b set => 'b set"       ("(3\<Inter>_\<le>_./ _)" [0, 0, 10] 10)
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 75 |   "_INTER_less" :: "'a => 'a => 'b set => 'b set"       ("(3\<Inter>_<_./ _)" [0, 0, 10] 10)
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 76 | |
| 14418 | 77 | translations | 
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 78 |   "\<Union>i\<le>n. A" \<rightleftharpoons> "\<Union>i\<in>{..n}. A"
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 79 |   "\<Union>i<n. A" \<rightleftharpoons> "\<Union>i\<in>{..<n}. A"
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 80 |   "\<Inter>i\<le>n. A" \<rightleftharpoons> "\<Inter>i\<in>{..n}. A"
 | 
| 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 81 |   "\<Inter>i<n. A" \<rightleftharpoons> "\<Inter>i\<in>{..<n}. A"
 | 
| 14418 | 82 | |
| 83 | ||
| 60758 | 84 | subsection \<open>Various equivalences\<close> | 
| 13735 | 85 | |
| 67613 | 86 | lemma (in ord) lessThan_iff [iff]: "(i \<in> lessThan k) = (i<k)" | 
| 13850 | 87 | by (simp add: lessThan_def) | 
| 13735 | 88 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 89 | lemma Compl_lessThan [simp]: | 
| 13735 | 90 | "!!k:: 'a::linorder. -lessThan k = atLeast k" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 91 | by (auto simp add: lessThan_def atLeast_def) | 
| 13735 | 92 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 93 | lemma single_Diff_lessThan [simp]: "!!k:: 'a::preorder. {k} - lessThan k = {k}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 94 | by auto | 
| 13735 | 95 | |
| 67613 | 96 | lemma (in ord) greaterThan_iff [iff]: "(i \<in> greaterThan k) = (k<i)" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 97 | by (simp add: greaterThan_def) | 
| 13735 | 98 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 99 | lemma Compl_greaterThan [simp]: | 
| 13735 | 100 | "!!k:: 'a::linorder. -greaterThan k = atMost k" | 
| 26072 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
 haftmann parents: 
25919diff
changeset | 101 | by (auto simp add: greaterThan_def atMost_def) | 
| 13735 | 102 | |
| 13850 | 103 | lemma Compl_atMost [simp]: "!!k:: 'a::linorder. -atMost k = greaterThan k" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 104 | apply (subst Compl_greaterThan [symmetric]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 105 | apply (rule double_complement) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 106 | done | 
| 13735 | 107 | |
| 67613 | 108 | lemma (in ord) atLeast_iff [iff]: "(i \<in> atLeast k) = (k<=i)" | 
| 13850 | 109 | by (simp add: atLeast_def) | 
| 13735 | 110 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 111 | lemma Compl_atLeast [simp]: "!!k:: 'a::linorder. -atLeast k = lessThan k" | 
| 26072 
f65a7fa2da6c
<= and < on nat no longer depend on wellfounded relations
 haftmann parents: 
25919diff
changeset | 112 | by (auto simp add: lessThan_def atLeast_def) | 
| 13735 | 113 | |
| 67613 | 114 | lemma (in ord) atMost_iff [iff]: "(i \<in> atMost k) = (i<=k)" | 
| 13850 | 115 | by (simp add: atMost_def) | 
| 13735 | 116 | |
| 14485 | 117 | lemma atMost_Int_atLeast: "!!n:: 'a::order. atMost n Int atLeast n = {n}"
 | 
| 118 | by (blast intro: order_antisym) | |
| 13850 | 119 | |
| 50999 | 120 | lemma (in linorder) lessThan_Int_lessThan: "{ a <..} \<inter> { b <..} = { max a b <..}"
 | 
| 121 | by auto | |
| 122 | ||
| 123 | lemma (in linorder) greaterThan_Int_greaterThan: "{..< a} \<inter> {..< b} = {..< min a b}"
 | |
| 124 | by auto | |
| 13850 | 125 | |
| 60758 | 126 | subsection \<open>Logical Equivalences for Set Inclusion and Equality\<close> | 
| 13850 | 127 | |
| 63879 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 128 | lemma atLeast_empty_triv [simp]: "{{}..} = UNIV"
 | 
| 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 129 | by auto | 
| 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 130 | |
| 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 131 | lemma atMost_UNIV_triv [simp]: "{..UNIV} = UNIV"
 | 
| 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 132 | by auto | 
| 
15bbf6360339
simple new lemmas, mostly about sets
 paulson <lp15@cam.ac.uk> parents: 
63721diff
changeset | 133 | |
| 13850 | 134 | lemma atLeast_subset_iff [iff]: | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 135 | "(atLeast x \<subseteq> atLeast y) = (y \<le> (x::'a::preorder))" | 
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 136 | by (blast intro: order_trans) | 
| 13850 | 137 | |
| 138 | lemma atLeast_eq_iff [iff]: | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 139 | "(atLeast x = atLeast y) = (x = (y::'a::order))" | 
| 13850 | 140 | by (blast intro: order_antisym order_trans) | 
| 141 | ||
| 142 | lemma greaterThan_subset_iff [iff]: | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 143 | "(greaterThan x \<subseteq> greaterThan y) = (y \<le> (x::'a::linorder))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 144 | unfolding greaterThan_def by (auto simp: linorder_not_less [symmetric]) | 
| 13850 | 145 | |
| 146 | lemma greaterThan_eq_iff [iff]: | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 147 | "(greaterThan x = greaterThan y) = (x = (y::'a::linorder))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 148 | by (auto simp: elim!: equalityE) | 
| 13850 | 149 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 150 | lemma atMost_subset_iff [iff]: "(atMost x \<subseteq> atMost y) = (x \<le> (y::'a::preorder))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 151 | by (blast intro: order_trans) | 
| 13850 | 152 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 153 | lemma atMost_eq_iff [iff]: "(atMost x = atMost y) = (x = (y::'a::order))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 154 | by (blast intro: order_antisym order_trans) | 
| 13850 | 155 | |
| 156 | lemma lessThan_subset_iff [iff]: | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 157 | "(lessThan x \<subseteq> lessThan y) = (x \<le> (y::'a::linorder))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 158 | unfolding lessThan_def by (auto simp: linorder_not_less [symmetric]) | 
| 13850 | 159 | |
| 160 | lemma lessThan_eq_iff [iff]: | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 161 | "(lessThan x = lessThan y) = (x = (y::'a::linorder))" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 162 | by (auto simp: elim!: equalityE) | 
| 13735 | 163 | |
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 164 | lemma lessThan_strict_subset_iff: | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 165 | fixes m n :: "'a::linorder" | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 166 |   shows "{..<m} < {..<n} \<longleftrightarrow> m < n"
 | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 167 | by (metis leD lessThan_subset_iff linorder_linear not_less_iff_gr_or_eq psubset_eq) | 
| 13735 | 168 | |
| 57448 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 169 | lemma (in linorder) Ici_subset_Ioi_iff: "{a ..} \<subseteq> {b <..} \<longleftrightarrow> b < a"
 | 
| 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 170 | by auto | 
| 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 171 | |
| 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 172 | lemma (in linorder) Iic_subset_Iio_iff: "{.. a} \<subseteq> {..< b} \<longleftrightarrow> a < b"
 | 
| 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 173 | by auto | 
| 
159e45728ceb
more equalities of topological filters; strengthen dependent_nat_choice; tuned a couple of proofs
 hoelzl parents: 
57447diff
changeset | 174 | |
| 62369 | 175 | lemma (in preorder) Ioi_le_Ico: "{a <..} \<subseteq> {a ..}"
 | 
| 176 | by (auto intro: less_imp_le) | |
| 177 | ||
| 60758 | 178 | subsection \<open>Two-sided intervals\<close> | 
| 13735 | 179 | |
| 24691 | 180 | context ord | 
| 181 | begin | |
| 182 | ||
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 183 | lemma greaterThanLessThan_iff [simp]: "(i \<in> {l<..<u}) = (l < i \<and> i < u)"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 184 | by (simp add: greaterThanLessThan_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 185 | |
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 186 | lemma atLeastLessThan_iff [simp]: "(i \<in> {l..<u}) = (l \<le> i \<and> i < u)"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 187 | by (simp add: atLeastLessThan_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 188 | |
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 189 | lemma greaterThanAtMost_iff [simp]: "(i \<in> {l<..u}) = (l < i \<and> i \<le> u)"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 190 | by (simp add: greaterThanAtMost_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 191 | |
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 192 | lemma atLeastAtMost_iff [simp]: "(i \<in> {l..u}) = (l \<le> i \<and> i \<le> u)"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 193 | by (simp add: atLeastAtMost_def) | 
| 13735 | 194 | |
| 60758 | 195 | text \<open>The above four lemmas could be declared as iffs. Unfortunately this | 
| 52729 
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
 haftmann parents: 
52380diff
changeset | 196 | breaks many proofs. Since it only helps blast, it is better to leave them | 
| 60758 | 197 | alone.\<close> | 
| 32436 
10cd49e0c067
Turned "x <= y ==> sup x y = y" (and relatives) into simp rules
 nipkow parents: 
32408diff
changeset | 198 | |
| 50999 | 199 | lemma greaterThanLessThan_eq: "{ a <..< b} = { a <..} \<inter> {..< b }"
 | 
| 200 | by auto | |
| 201 | ||
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 202 | lemma (in order) atLeastLessThan_eq_atLeastAtMost_diff: | 
| 66936 | 203 |   "{a..<b} = {a..b} - {b}"
 | 
| 204 | by (auto simp add: atLeastLessThan_def atLeastAtMost_def) | |
| 205 | ||
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 206 | lemma (in order) greaterThanAtMost_eq_atLeastAtMost_diff: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 207 |   "{a<..b} = {a..b} - {a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 208 | by (auto simp add: greaterThanAtMost_def atLeastAtMost_def) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 209 | |
| 24691 | 210 | end | 
| 13735 | 211 | |
| 60758 | 212 | subsubsection\<open>Emptyness, singletons, subset\<close> | 
| 15554 | 213 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 214 | context preorder | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 215 | begin | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 216 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 217 | lemma atLeastatMost_empty_iff[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 218 |   "{a..b} = {} \<longleftrightarrow> (\<not> a \<le> b)"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 219 | by auto (blast intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 220 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 221 | lemma atLeastatMost_empty_iff2[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 222 |   "{} = {a..b} \<longleftrightarrow> (\<not> a \<le> b)"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 223 | by auto (blast intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 224 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 225 | lemma atLeastLessThan_empty_iff[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 226 |   "{a..<b} = {} \<longleftrightarrow> (\<not> a < b)"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 227 | by auto (blast intro: le_less_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 228 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 229 | lemma atLeastLessThan_empty_iff2[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 230 |   "{} = {a..<b} \<longleftrightarrow> (\<not> a < b)"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 231 | by auto (blast intro: le_less_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 232 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 233 | lemma greaterThanAtMost_empty_iff[simp]: "{k<..l} = {} \<longleftrightarrow> \<not> k < l"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 234 | by auto (blast intro: less_le_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 235 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 236 | lemma greaterThanAtMost_empty_iff2[simp]: "{} = {k<..l} \<longleftrightarrow> \<not> k < l"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 237 | by auto (blast intro: less_le_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 238 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 239 | lemma atLeastatMost_subset_iff[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 240 |   "{a..b} \<le> {c..d} \<longleftrightarrow> (\<not> a \<le> b) \<or> c \<le> a \<and> b \<le> d"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 241 | unfolding atLeastAtMost_def atLeast_def atMost_def | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 242 | by (blast intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 243 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 244 | lemma atLeastatMost_psubset_iff: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 245 |   "{a..b} < {c..d} \<longleftrightarrow>
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 246 | ((\<not> a \<le> b) \<or> c \<le> a \<and> b \<le> d \<and> (c < a \<or> b < d)) \<and> c \<le> d" | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 247 | by(simp add: psubset_eq set_eq_iff less_le_not_le)(blast intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 248 | |
| 70749 
5d06b7bb9d22
More type class generalisations. Note that linorder_antisym_conv1 and linorder_antisym_conv2 no longer exist.
 paulson <lp15@cam.ac.uk> parents: 
70746diff
changeset | 249 | lemma atLeastAtMost_subseteq_atLeastLessThan_iff: | 
| 
5d06b7bb9d22
More type class generalisations. Note that linorder_antisym_conv1 and linorder_antisym_conv2 no longer exist.
 paulson <lp15@cam.ac.uk> parents: 
70746diff
changeset | 250 |   "{a..b} \<subseteq> {c ..< d} \<longleftrightarrow> (a \<le> b \<longrightarrow> c \<le> a \<and> b < d)" 
 | 
| 
5d06b7bb9d22
More type class generalisations. Note that linorder_antisym_conv1 and linorder_antisym_conv2 no longer exist.
 paulson <lp15@cam.ac.uk> parents: 
70746diff
changeset | 251 | by auto (blast intro: local.order_trans local.le_less_trans elim: )+ | 
| 
5d06b7bb9d22
More type class generalisations. Note that linorder_antisym_conv1 and linorder_antisym_conv2 no longer exist.
 paulson <lp15@cam.ac.uk> parents: 
70746diff
changeset | 252 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 253 | lemma Icc_subset_Ici_iff[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 254 |   "{l..h} \<subseteq> {l'..} = (\<not> l\<le>h \<or> l\<ge>l')"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 255 | by(auto simp: subset_eq intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 256 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 257 | lemma Icc_subset_Iic_iff[simp]: | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 258 |   "{l..h} \<subseteq> {..h'} = (\<not> l\<le>h \<or> h\<le>h')"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 259 | by(auto simp: subset_eq intro: order_trans) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 260 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 261 | lemma not_Ici_eq_empty[simp]: "{l..} \<noteq> {}"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 262 | by(auto simp: set_eq_iff) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 263 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 264 | lemma not_Iic_eq_empty[simp]: "{..h} \<noteq> {}"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 265 | by(auto simp: set_eq_iff) | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 266 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 267 | lemmas not_empty_eq_Ici_eq_empty[simp] = not_Ici_eq_empty[symmetric] | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 268 | lemmas not_empty_eq_Iic_eq_empty[simp] = not_Iic_eq_empty[symmetric] | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 269 | |
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 270 | end | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 271 | |
| 24691 | 272 | context order | 
| 273 | begin | |
| 15554 | 274 | |
| 32400 | 275 | lemma atLeastatMost_empty[simp]: | 
| 276 |   "b < a \<Longrightarrow> {a..b} = {}"
 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 277 | by(auto simp: atLeastAtMost_def atLeast_def atMost_def) | 
| 32400 | 278 | |
| 279 | lemma atLeastLessThan_empty[simp]: | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 280 |   "b \<le> a \<Longrightarrow> {a..<b} = {}"
 | 
| 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 281 | by(auto simp: atLeastLessThan_def) | 
| 15554 | 282 | |
| 32400 | 283 | lemma greaterThanAtMost_empty[simp]: "l \<le> k ==> {k<..l} = {}"
 | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 284 | by(auto simp:greaterThanAtMost_def greaterThan_def atMost_def) | 
| 32400 | 285 | |
| 29709 | 286 | lemma greaterThanLessThan_empty[simp]:"l \<le> k ==> {k<..<l} = {}"
 | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 287 | by(auto simp:greaterThanLessThan_def greaterThan_def lessThan_def) | 
| 17719 | 288 | |
| 25062 | 289 | lemma atLeastAtMost_singleton [simp]: "{a..a} = {a}"
 | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 290 | by (auto simp add: atLeastAtMost_def atMost_def atLeast_def) | 
| 24691 | 291 | |
| 36846 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 292 | lemma atLeastAtMost_singleton': "a = b \<Longrightarrow> {a .. b} = {a}" by simp
 | 
| 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 293 | |
| 51334 | 294 | lemma Icc_eq_Icc[simp]: | 
| 295 |   "{l..h} = {l'..h'} = (l=l' \<and> h=h' \<or> \<not> l\<le>h \<and> \<not> l'\<le>h')"
 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 296 | by(simp add: order_class.eq_iff)(auto intro: order_trans) | 
| 51334 | 297 | |
| 36846 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 298 | lemma atLeastAtMost_singleton_iff[simp]: | 
| 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 299 |   "{a .. b} = {c} \<longleftrightarrow> a = b \<and> b = c"
 | 
| 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 300 | proof | 
| 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 301 |   assume "{a..b} = {c}"
 | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 302 | hence *: "\<not> (\<not> a \<le> b)" unfolding atLeastatMost_empty_iff[symmetric] by simp | 
| 60758 | 303 |   with \<open>{a..b} = {c}\<close> have "c \<le> a \<and> b \<le> c" by auto
 | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 304 | with * show "a = b \<and> b = c" by auto | 
| 36846 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 305 | qed simp | 
| 
0f67561ed5a6
Added atLeastAtMost_singleton_iff, atLeastAtMost_singleton'
 hoelzl parents: 
36755diff
changeset | 306 | |
| 24691 | 307 | end | 
| 14485 | 308 | |
| 51334 | 309 | context no_top | 
| 310 | begin | |
| 311 | ||
| 312 | (* also holds for no_bot but no_top should suffice *) | |
| 313 | lemma not_UNIV_le_Icc[simp]: "\<not> UNIV \<subseteq> {l..h}"
 | |
| 314 | using gt_ex[of h] by(auto simp: subset_eq less_le_not_le) | |
| 315 | ||
| 316 | lemma not_UNIV_le_Iic[simp]: "\<not> UNIV \<subseteq> {..h}"
 | |
| 317 | using gt_ex[of h] by(auto simp: subset_eq less_le_not_le) | |
| 318 | ||
| 319 | lemma not_Ici_le_Icc[simp]: "\<not> {l..} \<subseteq> {l'..h'}"
 | |
| 320 | using gt_ex[of h'] | |
| 321 | by(auto simp: subset_eq less_le)(blast dest:antisym_conv intro: order_trans) | |
| 322 | ||
| 323 | lemma not_Ici_le_Iic[simp]: "\<not> {l..} \<subseteq> {..h'}"
 | |
| 324 | using gt_ex[of h'] | |
| 325 | by(auto simp: subset_eq less_le)(blast dest:antisym_conv intro: order_trans) | |
| 326 | ||
| 327 | end | |
| 328 | ||
| 329 | context no_bot | |
| 330 | begin | |
| 331 | ||
| 332 | lemma not_UNIV_le_Ici[simp]: "\<not> UNIV \<subseteq> {l..}"
 | |
| 333 | using lt_ex[of l] by(auto simp: subset_eq less_le_not_le) | |
| 334 | ||
| 335 | lemma not_Iic_le_Icc[simp]: "\<not> {..h} \<subseteq> {l'..h'}"
 | |
| 336 | using lt_ex[of l'] | |
| 337 | by(auto simp: subset_eq less_le)(blast dest:antisym_conv intro: order_trans) | |
| 338 | ||
| 339 | lemma not_Iic_le_Ici[simp]: "\<not> {..h} \<subseteq> {l'..}"
 | |
| 340 | using lt_ex[of l'] | |
| 341 | by(auto simp: subset_eq less_le)(blast dest:antisym_conv intro: order_trans) | |
| 342 | ||
| 343 | end | |
| 344 | ||
| 345 | ||
| 346 | context no_top | |
| 347 | begin | |
| 348 | ||
| 349 | (* also holds for no_bot but no_top should suffice *) | |
| 350 | lemma not_UNIV_eq_Icc[simp]: "\<not> UNIV = {l'..h'}"
 | |
| 351 | using gt_ex[of h'] by(auto simp: set_eq_iff less_le_not_le) | |
| 352 | ||
| 353 | lemmas not_Icc_eq_UNIV[simp] = not_UNIV_eq_Icc[symmetric] | |
| 354 | ||
| 355 | lemma not_UNIV_eq_Iic[simp]: "\<not> UNIV = {..h'}"
 | |
| 356 | using gt_ex[of h'] by(auto simp: set_eq_iff less_le_not_le) | |
| 357 | ||
| 358 | lemmas not_Iic_eq_UNIV[simp] = not_UNIV_eq_Iic[symmetric] | |
| 359 | ||
| 360 | lemma not_Icc_eq_Ici[simp]: "\<not> {l..h} = {l'..}"
 | |
| 361 | unfolding atLeastAtMost_def using not_Ici_le_Iic[of l'] by blast | |
| 362 | ||
| 363 | lemmas not_Ici_eq_Icc[simp] = not_Icc_eq_Ici[symmetric] | |
| 364 | ||
| 365 | (* also holds for no_bot but no_top should suffice *) | |
| 366 | lemma not_Iic_eq_Ici[simp]: "\<not> {..h} = {l'..}"
 | |
| 367 | using not_Ici_le_Iic[of l' h] by blast | |
| 368 | ||
| 369 | lemmas not_Ici_eq_Iic[simp] = not_Iic_eq_Ici[symmetric] | |
| 370 | ||
| 371 | end | |
| 372 | ||
| 373 | context no_bot | |
| 374 | begin | |
| 375 | ||
| 376 | lemma not_UNIV_eq_Ici[simp]: "\<not> UNIV = {l'..}"
 | |
| 377 | using lt_ex[of l'] by(auto simp: set_eq_iff less_le_not_le) | |
| 378 | ||
| 379 | lemmas not_Ici_eq_UNIV[simp] = not_UNIV_eq_Ici[symmetric] | |
| 380 | ||
| 381 | lemma not_Icc_eq_Iic[simp]: "\<not> {l..h} = {..h'}"
 | |
| 382 | unfolding atLeastAtMost_def using not_Iic_le_Ici[of h'] by blast | |
| 383 | ||
| 384 | lemmas not_Iic_eq_Icc[simp] = not_Icc_eq_Iic[symmetric] | |
| 385 | ||
| 386 | end | |
| 387 | ||
| 388 | ||
| 53216 | 389 | context dense_linorder | 
| 42891 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 390 | begin | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 391 | |
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 392 | lemma greaterThanLessThan_empty_iff[simp]: | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 393 |   "{ a <..< b } = {} \<longleftrightarrow> b \<le> a"
 | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 394 | using dense[of a b] by (cases "a < b") auto | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 395 | |
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 396 | lemma greaterThanLessThan_empty_iff2[simp]: | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 397 |   "{} = { a <..< b } \<longleftrightarrow> b \<le> a"
 | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 398 | using dense[of a b] by (cases "a < b") auto | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 399 | |
| 42901 | 400 | lemma atLeastLessThan_subseteq_atLeastAtMost_iff: | 
| 401 |   "{a ..< b} \<subseteq> { c .. d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b \<le> d)"
 | |
| 402 | using dense[of "max a d" "b"] | |
| 403 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 404 | ||
| 405 | lemma greaterThanAtMost_subseteq_atLeastAtMost_iff: | |
| 406 |   "{a <.. b} \<subseteq> { c .. d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b \<le> d)"
 | |
| 407 | using dense[of "a" "min c b"] | |
| 408 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 409 | ||
| 410 | lemma greaterThanLessThan_subseteq_atLeastAtMost_iff: | |
| 411 |   "{a <..< b} \<subseteq> { c .. d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b \<le> d)"
 | |
| 412 | using dense[of "a" "min c b"] dense[of "max a d" "b"] | |
| 413 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 414 | ||
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 415 | lemma greaterThanLessThan_subseteq_greaterThanLessThan: | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 416 |   "{a <..< b} \<subseteq> {c <..< d} \<longleftrightarrow> (a < b \<longrightarrow> a \<ge> c \<and> b \<le> d)"
 | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 417 | using dense[of "a" "min c b"] dense[of "max a d" "b"] | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 418 | by (force simp: subset_eq Ball_def not_less[symmetric]) | 
| 43657 | 419 | |
| 420 | lemma greaterThanAtMost_subseteq_atLeastLessThan_iff: | |
| 421 |   "{a <.. b} \<subseteq> { c ..< d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b < d)"
 | |
| 422 | using dense[of "a" "min c b"] | |
| 423 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 424 | ||
| 425 | lemma greaterThanLessThan_subseteq_atLeastLessThan_iff: | |
| 426 |   "{a <..< b} \<subseteq> { c ..< d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b \<le> d)"
 | |
| 427 | using dense[of "a" "min c b"] dense[of "max a d" "b"] | |
| 428 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 429 | ||
| 56328 | 430 | lemma greaterThanLessThan_subseteq_greaterThanAtMost_iff: | 
| 431 |   "{a <..< b} \<subseteq> { c <.. d } \<longleftrightarrow> (a < b \<longrightarrow> c \<le> a \<and> b \<le> d)"
 | |
| 432 | using dense[of "a" "min c b"] dense[of "max a d" "b"] | |
| 433 | by (force simp: subset_eq Ball_def not_less[symmetric]) | |
| 434 | ||
| 42891 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 435 | end | 
| 
e2f473671937
simp rules for empty intervals on dense linear order
 hoelzl parents: 
40703diff
changeset | 436 | |
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 437 | context no_top | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 438 | begin | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 439 | |
| 51334 | 440 | lemma greaterThan_non_empty[simp]: "{x <..} \<noteq> {}"
 | 
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 441 | using gt_ex[of x] by auto | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 442 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 443 | end | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 444 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 445 | context no_bot | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 446 | begin | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 447 | |
| 51334 | 448 | lemma lessThan_non_empty[simp]: "{..< x} \<noteq> {}"
 | 
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 449 | using lt_ex[of x] by auto | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 450 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 451 | end | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 452 | |
| 32408 | 453 | lemma (in linorder) atLeastLessThan_subset_iff: | 
| 67091 | 454 |   "{a..<b} \<subseteq> {c..<d} \<Longrightarrow> b \<le> a \<or> c\<le>a \<and> b\<le>d"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 455 | apply (auto simp:subset_eq Ball_def not_le) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 456 | apply(frule_tac x=a in spec) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 457 | apply(erule_tac x=d in allE) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 458 | apply (auto simp: ) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 459 | done | 
| 32408 | 460 | |
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 461 | lemma atLeastLessThan_inj: | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 462 | fixes a b c d :: "'a::linorder" | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 463 |   assumes eq: "{a ..< b} = {c ..< d}" and "a < b" "c < d"
 | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 464 | shows "a = c" "b = d" | 
| 70749 
5d06b7bb9d22
More type class generalisations. Note that linorder_antisym_conv1 and linorder_antisym_conv2 no longer exist.
 paulson <lp15@cam.ac.uk> parents: 
70746diff
changeset | 465 | using assms by (metis atLeastLessThan_subset_iff eq less_le_not_le antisym_conv2 subset_refl)+ | 
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 466 | |
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 467 | lemma atLeastLessThan_eq_iff: | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 468 | fixes a b c d :: "'a::linorder" | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 469 | assumes "a < b" "c < d" | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 470 |   shows "{a ..< b} = {c ..< d} \<longleftrightarrow> a = c \<and> b = d"
 | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 471 | using atLeastLessThan_inj assms by auto | 
| 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 472 | |
| 57447 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 473 | lemma (in linorder) Ioc_inj: "{a <.. b} = {c <.. d} \<longleftrightarrow> (b \<le> a \<and> d \<le> c) \<or> a = c \<and> b = d"
 | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 474 | by (metis eq_iff greaterThanAtMost_empty_iff2 greaterThanAtMost_iff le_cases not_le) | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 475 | |
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 476 | lemma (in order) Iio_Int_singleton: "{..<k} \<inter> {x} = (if x < k then {x} else {})"
 | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 477 | by auto | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 478 | |
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 479 | lemma (in linorder) Ioc_subset_iff: "{a<..b} \<subseteq> {c<..d} \<longleftrightarrow> (b \<le> a \<or> c \<le> a \<and> b \<le> d)"
 | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 480 | by (auto simp: subset_eq Ball_def) (metis less_le not_less) | 
| 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 481 | |
| 52729 
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
 haftmann parents: 
52380diff
changeset | 482 | lemma (in order_bot) atLeast_eq_UNIV_iff: "{x..} = UNIV \<longleftrightarrow> x = bot"
 | 
| 51334 | 483 | by (auto simp: set_eq_iff intro: le_bot) | 
| 51328 
d63ec23c9125
move auxiliary lemmas from Library/Extended_Reals to HOL image
 hoelzl parents: 
51152diff
changeset | 484 | |
| 52729 
412c9e0381a1
factored syntactic type classes for bot and top (by Alessandro Coglio)
 haftmann parents: 
52380diff
changeset | 485 | lemma (in order_top) atMost_eq_UNIV_iff: "{..x} = UNIV \<longleftrightarrow> x = top"
 | 
| 51334 | 486 | by (auto simp: set_eq_iff intro: top_le) | 
| 51328 
d63ec23c9125
move auxiliary lemmas from Library/Extended_Reals to HOL image
 hoelzl parents: 
51152diff
changeset | 487 | |
| 51334 | 488 | lemma (in bounded_lattice) atLeastAtMost_eq_UNIV_iff: | 
| 489 |   "{x..y} = UNIV \<longleftrightarrow> (x = bot \<and> y = top)"
 | |
| 490 | by (auto simp: set_eq_iff intro: top_le le_bot) | |
| 51328 
d63ec23c9125
move auxiliary lemmas from Library/Extended_Reals to HOL image
 hoelzl parents: 
51152diff
changeset | 491 | |
| 56949 | 492 | lemma Iio_eq_empty_iff: "{..< n::'a::{linorder, order_bot}} = {} \<longleftrightarrow> n = bot"
 | 
| 493 | by (auto simp: set_eq_iff not_less le_bot) | |
| 494 | ||
| 68361 | 495 | lemma lessThan_empty_iff: "{..< n::nat} = {} \<longleftrightarrow> n = 0"
 | 
| 56949 | 496 | by (simp add: Iio_eq_empty_iff bot_nat_def) | 
| 497 | ||
| 58970 | 498 | lemma mono_image_least: | 
| 499 |   assumes f_mono: "mono f" and f_img: "f ` {m ..< n} = {m' ..< n'}" "m < n"
 | |
| 500 | shows "f m = m'" | |
| 501 | proof - | |
| 502 |   from f_img have "{m' ..< n'} \<noteq> {}"
 | |
| 503 | by (metis atLeastLessThan_empty_iff image_is_empty) | |
| 504 |   with f_img have "m' \<in> f ` {m ..< n}" by auto
 | |
| 505 | then obtain k where "f k = m'" "m \<le> k" by auto | |
| 506 | moreover have "m' \<le> f m" using f_img by auto | |
| 507 | ultimately show "f m = m'" | |
| 508 | using f_mono by (auto elim: monoE[where x=m and y=k]) | |
| 509 | qed | |
| 510 | ||
| 51328 
d63ec23c9125
move auxiliary lemmas from Library/Extended_Reals to HOL image
 hoelzl parents: 
51152diff
changeset | 511 | |
| 60758 | 512 | subsection \<open>Infinite intervals\<close> | 
| 56328 | 513 | |
| 514 | context dense_linorder | |
| 515 | begin | |
| 516 | ||
| 517 | lemma infinite_Ioo: | |
| 518 | assumes "a < b" | |
| 519 |   shows "\<not> finite {a<..<b}"
 | |
| 520 | proof | |
| 521 |   assume fin: "finite {a<..<b}"
 | |
| 522 |   moreover have ne: "{a<..<b} \<noteq> {}"
 | |
| 60758 | 523 | using \<open>a < b\<close> by auto | 
| 56328 | 524 |   ultimately have "a < Max {a <..< b}" "Max {a <..< b} < b"
 | 
| 525 |     using Max_in[of "{a <..< b}"] by auto
 | |
| 526 |   then obtain x where "Max {a <..< b} < x" "x < b"
 | |
| 527 |     using dense[of "Max {a<..<b}" b] by auto
 | |
| 528 |   then have "x \<in> {a <..< b}"
 | |
| 60758 | 529 |     using \<open>a < Max {a <..< b}\<close> by auto
 | 
| 56328 | 530 |   then have "x \<le> Max {a <..< b}"
 | 
| 531 | using fin by auto | |
| 60758 | 532 |   with \<open>Max {a <..< b} < x\<close> show False by auto
 | 
| 56328 | 533 | qed | 
| 534 | ||
| 535 | lemma infinite_Icc: "a < b \<Longrightarrow> \<not> finite {a .. b}"
 | |
| 536 | using greaterThanLessThan_subseteq_atLeastAtMost_iff[of a b a b] infinite_Ioo[of a b] | |
| 537 | by (auto dest: finite_subset) | |
| 538 | ||
| 539 | lemma infinite_Ico: "a < b \<Longrightarrow> \<not> finite {a ..< b}"
 | |
| 540 | using greaterThanLessThan_subseteq_atLeastLessThan_iff[of a b a b] infinite_Ioo[of a b] | |
| 541 | by (auto dest: finite_subset) | |
| 542 | ||
| 543 | lemma infinite_Ioc: "a < b \<Longrightarrow> \<not> finite {a <.. b}"
 | |
| 544 | using greaterThanLessThan_subseteq_greaterThanAtMost_iff[of a b a b] infinite_Ioo[of a b] | |
| 545 | by (auto dest: finite_subset) | |
| 546 | ||
| 63967 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 547 | lemma infinite_Ioo_iff [simp]: "infinite {a<..<b} \<longleftrightarrow> a < b"
 | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 548 | using not_less_iff_gr_or_eq by (fastforce simp: infinite_Ioo) | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 549 | |
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 550 | lemma infinite_Icc_iff [simp]: "infinite {a .. b} \<longleftrightarrow> a < b"
 | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 551 | using not_less_iff_gr_or_eq by (fastforce simp: infinite_Icc) | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 552 | |
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 553 | lemma infinite_Ico_iff [simp]: "infinite {a..<b} \<longleftrightarrow> a < b"
 | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 554 | using not_less_iff_gr_or_eq by (fastforce simp: infinite_Ico) | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 555 | |
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 556 | lemma infinite_Ioc_iff [simp]: "infinite {a<..b} \<longleftrightarrow> a < b"
 | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 557 | using not_less_iff_gr_or_eq by (fastforce simp: infinite_Ioc) | 
| 
2aa42596edc3
new material on paths, etc. Also rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63935diff
changeset | 558 | |
| 56328 | 559 | end | 
| 560 | ||
| 561 | lemma infinite_Iio: "\<not> finite {..< a :: 'a :: {no_bot, linorder}}"
 | |
| 562 | proof | |
| 563 |   assume "finite {..< a}"
 | |
| 564 |   then have *: "\<And>x. x < a \<Longrightarrow> Min {..< a} \<le> x"
 | |
| 565 | by auto | |
| 566 | obtain x where "x < a" | |
| 567 | using lt_ex by auto | |
| 568 | ||
| 569 |   obtain y where "y < Min {..< a}"
 | |
| 570 | using lt_ex by auto | |
| 571 |   also have "Min {..< a} \<le> x"
 | |
| 60758 | 572 | using \<open>x < a\<close> by fact | 
| 573 | also note \<open>x < a\<close> | |
| 56328 | 574 |   finally have "Min {..< a} \<le> y"
 | 
| 575 | by fact | |
| 60758 | 576 |   with \<open>y < Min {..< a}\<close> show False by auto
 | 
| 56328 | 577 | qed | 
| 578 | ||
| 579 | lemma infinite_Iic: "\<not> finite {.. a :: 'a :: {no_bot, linorder}}"
 | |
| 580 |   using infinite_Iio[of a] finite_subset[of "{..< a}" "{.. a}"]
 | |
| 581 | by (auto simp: subset_eq less_imp_le) | |
| 582 | ||
| 583 | lemma infinite_Ioi: "\<not> finite {a :: 'a :: {no_top, linorder} <..}"
 | |
| 584 | proof | |
| 585 |   assume "finite {a <..}"
 | |
| 586 |   then have *: "\<And>x. a < x \<Longrightarrow> x \<le> Max {a <..}"
 | |
| 587 | by auto | |
| 588 | ||
| 589 |   obtain y where "Max {a <..} < y"
 | |
| 590 | using gt_ex by auto | |
| 591 | ||
| 63540 | 592 | obtain x where x: "a < x" | 
| 56328 | 593 | using gt_ex by auto | 
| 63540 | 594 |   also from x have "x \<le> Max {a <..}"
 | 
| 56328 | 595 | by fact | 
| 60758 | 596 |   also note \<open>Max {a <..} < y\<close>
 | 
| 56328 | 597 |   finally have "y \<le> Max { a <..}"
 | 
| 598 | by fact | |
| 60758 | 599 |   with \<open>Max {a <..} < y\<close> show False by auto
 | 
| 56328 | 600 | qed | 
| 601 | ||
| 602 | lemma infinite_Ici: "\<not> finite {a :: 'a :: {no_top, linorder} ..}"
 | |
| 603 |   using infinite_Ioi[of a] finite_subset[of "{a <..}" "{a ..}"]
 | |
| 604 | by (auto simp: subset_eq less_imp_le) | |
| 605 | ||
| 60758 | 606 | subsubsection \<open>Intersection\<close> | 
| 32456 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 607 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 608 | context linorder | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 609 | begin | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 610 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 611 | lemma Int_atLeastAtMost[simp]: "{a..b} Int {c..d} = {max a c .. min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 612 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 613 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 614 | lemma Int_atLeastAtMostR1[simp]: "{..b} Int {c..d} = {c .. min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 615 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 616 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 617 | lemma Int_atLeastAtMostR2[simp]: "{a..} Int {c..d} = {max a c .. d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 618 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 619 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 620 | lemma Int_atLeastAtMostL1[simp]: "{a..b} Int {..d} = {a .. min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 621 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 622 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 623 | lemma Int_atLeastAtMostL2[simp]: "{a..b} Int {c..} = {max a c .. b}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 624 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 625 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 626 | lemma Int_atLeastLessThan[simp]: "{a..<b} Int {c..<d} = {max a c ..< min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 627 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 628 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 629 | lemma Int_greaterThanAtMost[simp]: "{a<..b} Int {c<..d} = {max a c <.. min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 630 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 631 | |
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 632 | lemma Int_greaterThanLessThan[simp]: "{a<..<b} Int {c<..<d} = {max a c <..< min b d}"
 | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 633 | by auto | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 634 | |
| 50417 | 635 | lemma Int_atMost[simp]: "{..a} \<inter> {..b} = {.. min a b}"
 | 
| 636 | by (auto simp: min_def) | |
| 637 | ||
| 57447 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 638 | lemma Ioc_disjoint: "{a<..b} \<inter> {c<..d} = {} \<longleftrightarrow> b \<le> a \<or> d \<le> c \<or> b \<le> c \<or> d \<le> a"
 | 
| 63092 | 639 | by auto | 
| 57447 
87429bdecad5
import more stuff from the CLT proof; base the lborel measure on interval_measure; remove lebesgue measure
 hoelzl parents: 
57418diff
changeset | 640 | |
| 32456 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 641 | end | 
| 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 642 | |
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 643 | context complete_lattice | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 644 | begin | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 645 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 646 | lemma | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 647 |   shows Sup_atLeast[simp]: "Sup {x ..} = top"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 648 |     and Sup_greaterThanAtLeast[simp]: "x < top \<Longrightarrow> Sup {x <..} = top"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 649 |     and Sup_atMost[simp]: "Sup {.. y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 650 |     and Sup_atLeastAtMost[simp]: "x \<le> y \<Longrightarrow> Sup { x .. y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 651 |     and Sup_greaterThanAtMost[simp]: "x < y \<Longrightarrow> Sup { x <.. y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 652 | by (auto intro!: Sup_eqI) | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 653 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 654 | lemma | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 655 |   shows Inf_atMost[simp]: "Inf {.. x} = bot"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 656 |     and Inf_atMostLessThan[simp]: "top < x \<Longrightarrow> Inf {..< x} = bot"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 657 |     and Inf_atLeast[simp]: "Inf {x ..} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 658 |     and Inf_atLeastAtMost[simp]: "x \<le> y \<Longrightarrow> Inf { x .. y} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 659 |     and Inf_atLeastLessThan[simp]: "x < y \<Longrightarrow> Inf { x ..< y} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 660 | by (auto intro!: Inf_eqI) | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 661 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 662 | end | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 663 | |
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 664 | lemma | 
| 53216 | 665 |   fixes x y :: "'a :: {complete_lattice, dense_linorder}"
 | 
| 51329 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 666 |   shows Sup_lessThan[simp]: "Sup {..< y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 667 |     and Sup_atLeastLessThan[simp]: "x < y \<Longrightarrow> Sup { x ..< y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 668 |     and Sup_greaterThanLessThan[simp]: "x < y \<Longrightarrow> Sup { x <..< y} = y"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 669 |     and Inf_greaterThan[simp]: "Inf {x <..} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 670 |     and Inf_greaterThanAtMost[simp]: "x < y \<Longrightarrow> Inf { x <.. y} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 671 |     and Inf_greaterThanLessThan[simp]: "x < y \<Longrightarrow> Inf { x <..< y} = x"
 | 
| 
4a3c453f99a1
split dense into inner_dense_order and no_top/no_bot
 hoelzl parents: 
51328diff
changeset | 672 | by (auto intro!: Inf_eqI Sup_eqI intro: dense_le dense_le_bounded dense_ge dense_ge_bounded) | 
| 32456 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 673 | |
| 60758 | 674 | subsection \<open>Intervals of natural numbers\<close> | 
| 14485 | 675 | |
| 69593 | 676 | subsubsection \<open>The Constant \<^term>\<open>lessThan\<close>\<close> | 
| 15047 | 677 | |
| 14485 | 678 | lemma lessThan_0 [simp]: "lessThan (0::nat) = {}"
 | 
| 679 | by (simp add: lessThan_def) | |
| 680 | ||
| 681 | lemma lessThan_Suc: "lessThan (Suc k) = insert k (lessThan k)" | |
| 682 | by (simp add: lessThan_def less_Suc_eq, blast) | |
| 683 | ||
| 60758 | 684 | text \<open>The following proof is convenient in induction proofs where | 
| 39072 | 685 | new elements get indices at the beginning. So it is used to transform | 
| 69593 | 686 | \<^term>\<open>{..<Suc n}\<close> to \<^term>\<open>0::nat\<close> and \<^term>\<open>{..< n}\<close>.\<close>
 | 
| 39072 | 687 | |
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69593diff
changeset | 688 | lemma zero_notin_Suc_image [simp]: "0 \<notin> Suc ` A" | 
| 59000 | 689 | by auto | 
| 690 | ||
| 39072 | 691 | lemma lessThan_Suc_eq_insert_0: "{..<Suc n} = insert 0 (Suc ` {..<n})"
 | 
| 59000 | 692 | by (auto simp: image_iff less_Suc_eq_0_disj) | 
| 39072 | 693 | |
| 14485 | 694 | lemma lessThan_Suc_atMost: "lessThan (Suc k) = atMost k" | 
| 695 | by (simp add: lessThan_def atMost_def less_Suc_eq_le) | |
| 696 | ||
| 68361 | 697 | lemma atMost_Suc_eq_insert_0: "{.. Suc n} = insert 0 (Suc ` {.. n})"
 | 
| 59000 | 698 | unfolding lessThan_Suc_atMost[symmetric] lessThan_Suc_eq_insert_0[of "Suc n"] .. | 
| 699 | ||
| 69276 | 700 | lemma UN_lessThan_UNIV: "(\<Union>m::nat. lessThan m) = UNIV" | 
| 14485 | 701 | by blast | 
| 702 | ||
| 69593 | 703 | subsubsection \<open>The Constant \<^term>\<open>greaterThan\<close>\<close> | 
| 15047 | 704 | |
| 65273 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 705 | lemma greaterThan_0: "greaterThan 0 = range Suc" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 706 | unfolding greaterThan_def | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 707 | by (blast dest: gr0_conv_Suc [THEN iffD1]) | 
| 14485 | 708 | |
| 709 | lemma greaterThan_Suc: "greaterThan (Suc k) = greaterThan k - {Suc k}"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 710 | unfolding greaterThan_def | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 711 | by (auto elim: linorder_neqE) | 
| 14485 | 712 | |
| 69276 | 713 | lemma INT_greaterThan_UNIV: "(\<Inter>m::nat. greaterThan m) = {}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 714 | by blast | 
| 14485 | 715 | |
| 69593 | 716 | subsubsection \<open>The Constant \<^term>\<open>atLeast\<close>\<close> | 
| 15047 | 717 | |
| 14485 | 718 | lemma atLeast_0 [simp]: "atLeast (0::nat) = UNIV" | 
| 719 | by (unfold atLeast_def UNIV_def, simp) | |
| 720 | ||
| 721 | lemma atLeast_Suc: "atLeast (Suc k) = atLeast k - {k}"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 722 | unfolding atLeast_def by (auto simp: order_le_less Suc_le_eq) | 
| 14485 | 723 | |
| 724 | lemma atLeast_Suc_greaterThan: "atLeast (Suc k) = greaterThan k" | |
| 725 | by (auto simp add: greaterThan_def atLeast_def less_Suc_eq_le) | |
| 726 | ||
| 69276 | 727 | lemma UN_atLeast_UNIV: "(\<Union>m::nat. atLeast m) = UNIV" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 728 | by blast | 
| 14485 | 729 | |
| 69593 | 730 | subsubsection \<open>The Constant \<^term>\<open>atMost\<close>\<close> | 
| 15047 | 731 | |
| 14485 | 732 | lemma atMost_0 [simp]: "atMost (0::nat) = {0}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 733 | by (simp add: atMost_def) | 
| 14485 | 734 | |
| 735 | lemma atMost_Suc: "atMost (Suc k) = insert (Suc k) (atMost k)" | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 736 | unfolding atMost_def by (auto simp add: less_Suc_eq order_le_less) | 
| 14485 | 737 | |
| 69276 | 738 | lemma UN_atMost_UNIV: "(\<Union>m::nat. atMost m) = UNIV" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 739 | by blast | 
| 14485 | 740 | |
| 69593 | 741 | subsubsection \<open>The Constant \<^term>\<open>atLeastLessThan\<close>\<close> | 
| 15047 | 742 | |
| 60758 | 743 | text\<open>The orientation of the following 2 rules is tricky. The lhs is | 
| 24449 | 744 | defined in terms of the rhs. Hence the chosen orientation makes sense | 
| 745 | in this theory --- the reverse orientation complicates proofs (eg | |
| 746 | nontermination). But outside, when the definition of the lhs is rarely | |
| 747 | used, the opposite orientation seems preferable because it reduces a | |
| 60758 | 748 | specific concept to a more general one.\<close> | 
| 28068 | 749 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 750 | lemma atLeast0LessThan [code_abbrev]: "{0::nat..<n} = {..<n}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 751 | by(simp add:lessThan_def atLeastLessThan_def) | 
| 24449 | 752 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 753 | lemma atLeast0AtMost [code_abbrev]: "{0..n::nat} = {..n}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 754 | by(simp add:atMost_def atLeastAtMost_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 755 | |
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 756 | lemma lessThan_atLeast0: "{..<n} = {0::nat..<n}"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 757 | by (simp add: atLeast0LessThan) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 758 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 759 | lemma atMost_atLeast0: "{..n} = {0::nat..n}"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 760 | by (simp add: atLeast0AtMost) | 
| 24449 | 761 | |
| 762 | lemma atLeastLessThan0: "{m..<0::nat} = {}"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 763 | by (simp add: atLeastLessThan_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 764 | |
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 765 | lemma atLeast0_lessThan_Suc: "{0..<Suc n} = insert n {0..<n}"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 766 | by (simp add: atLeast0LessThan lessThan_Suc) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 767 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 768 | lemma atLeast0_lessThan_Suc_eq_insert_0: "{0..<Suc n} = insert 0 (Suc ` {0..<n})"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 769 | by (simp add: atLeast0LessThan lessThan_Suc_eq_insert_0) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 770 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 771 | |
| 69593 | 772 | subsubsection \<open>The Constant \<^term>\<open>atLeastAtMost\<close>\<close> | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 773 | |
| 69198 | 774 | lemma Icc_eq_insert_lb_nat: "m \<le> n \<Longrightarrow> {m..n} = insert m {Suc m..n}"
 | 
| 775 | by auto | |
| 776 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 777 | lemma atLeast0_atMost_Suc: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 778 |   "{0..Suc n} = insert (Suc n) {0..n}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 779 | by (simp add: atLeast0AtMost atMost_Suc) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 780 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 781 | lemma atLeast0_atMost_Suc_eq_insert_0: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 782 |   "{0..Suc n} = insert 0 (Suc ` {0..n})"
 | 
| 68361 | 783 | by (simp add: atLeast0AtMost atMost_Suc_eq_insert_0) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 784 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 785 | |
| 69593 | 786 | subsubsection \<open>Intervals of nats with \<^term>\<open>Suc\<close>\<close> | 
| 15047 | 787 | |
| 60758 | 788 | text\<open>Not a simprule because the RHS is too messy.\<close> | 
| 15047 | 789 | lemma atLeastLessThanSuc: | 
| 790 |     "{m..<Suc n} = (if m \<le> n then insert n {m..<n} else {})"
 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 791 | by (auto simp add: atLeastLessThan_def) | 
| 15047 | 792 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 793 | lemma atLeastLessThan_singleton [simp]: "{m..<Suc m} = {m}"
 | 
| 15047 | 794 | by (auto simp add: atLeastLessThan_def) | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 795 | |
| 15045 | 796 | lemma atLeastLessThanSuc_atLeastAtMost: "{l..<Suc u} = {l..u}"
 | 
| 14485 | 797 | by (simp add: lessThan_Suc_atMost atLeastAtMost_def atLeastLessThan_def) | 
| 798 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 799 | lemma atLeastSucAtMost_greaterThanAtMost: "{Suc l..u} = {l<..u}"
 | 
| 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 800 | by (simp add: atLeast_Suc_greaterThan atLeastAtMost_def | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 801 | greaterThanAtMost_def) | 
| 14485 | 802 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 803 | lemma atLeastSucLessThan_greaterThanLessThan: "{Suc l..<u} = {l<..<u}"
 | 
| 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 804 | by (simp add: atLeast_Suc_greaterThan atLeastLessThan_def | 
| 14485 | 805 | greaterThanLessThan_def) | 
| 806 | ||
| 15554 | 807 | lemma atLeastAtMostSuc_conv: "m \<le> Suc n \<Longrightarrow> {m..Suc n} = insert (Suc n) {m..n}"
 | 
| 808 | by (auto simp add: atLeastAtMost_def) | |
| 809 | ||
| 45932 | 810 | lemma atLeastAtMost_insertL: "m \<le> n \<Longrightarrow> insert m {Suc m..n} = {m ..n}"
 | 
| 811 | by auto | |
| 812 | ||
| 69593 | 813 | text \<open>The analogous result is useful on \<^typ>\<open>int\<close>:\<close> | 
| 43157 | 814 | (* here, because we don't have an own int section *) | 
| 815 | lemma atLeastAtMostPlus1_int_conv: | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 816 |   "m \<le> 1+n \<Longrightarrow> {m..1+n} = insert (1+n) {m..n::int}"
 | 
| 43157 | 817 | by (auto intro: set_eqI) | 
| 818 | ||
| 33044 | 819 | lemma atLeastLessThan_add_Un: "i \<le> j \<Longrightarrow> {i..<j+k} = {i..<j} \<union> {j..<j+k::nat}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 820 | by (induct k) (simp_all add: atLeastLessThanSuc) | 
| 33044 | 821 | |
| 66936 | 822 | |
| 60758 | 823 | subsubsection \<open>Intervals and numerals\<close> | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 824 | |
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 825 | lemma lessThan_nat_numeral: \<comment> \<open>Evaluation for specific numerals\<close> | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 826 | "lessThan (numeral k :: nat) = insert (pred_numeral k) (lessThan (pred_numeral k))" | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 827 | by (simp add: numeral_eq_Suc lessThan_Suc) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 828 | |
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 829 | lemma atMost_nat_numeral: \<comment> \<open>Evaluation for specific numerals\<close> | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 830 | "atMost (numeral k :: nat) = insert (numeral k) (atMost (pred_numeral k))" | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 831 | by (simp add: numeral_eq_Suc atMost_Suc) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 832 | |
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 833 | lemma atLeastLessThan_nat_numeral: \<comment> \<open>Evaluation for specific numerals\<close> | 
| 62369 | 834 | "atLeastLessThan m (numeral k :: nat) = | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 835 | (if m \<le> (pred_numeral k) then insert (pred_numeral k) (atLeastLessThan m (pred_numeral k)) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 836 |                  else {})"
 | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 837 | by (simp add: numeral_eq_Suc atLeastLessThanSuc) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 838 | |
| 66936 | 839 | |
| 60758 | 840 | subsubsection \<open>Image\<close> | 
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 841 | |
| 66936 | 842 | context linordered_semidom | 
| 843 | begin | |
| 844 | ||
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 845 | lemma image_add_atLeast[simp]: "plus k ` {i..} = {k + i..}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 846 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 847 | have "n = k + (n - k)" if "i + k \<le> n" for n | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 848 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 849 | have "n = (n - (k + i)) + (k + i)" using that | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 850 | by (metis add_commute le_add_diff_inverse) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 851 | then show "n = k + (n - k)" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 852 | by (metis local.add_diff_cancel_left' add_assoc add_commute) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 853 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 854 | then show ?thesis | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 855 | by (fastforce simp: add_le_imp_le_diff add.commute) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 856 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 857 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 858 | lemma image_add_atLeastAtMost [simp]: | 
| 66936 | 859 |   "plus k ` {i..j} = {i + k..j + k}" (is "?A = ?B")
 | 
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 860 | proof | 
| 66936 | 861 | show "?A \<subseteq> ?B" | 
| 862 | by (auto simp add: ac_simps) | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 863 | next | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 864 | show "?B \<subseteq> ?A" | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 865 | proof | 
| 66936 | 866 | fix n | 
| 867 | assume "n \<in> ?B" | |
| 868 | then have "i \<le> n - k" | |
| 869 | by (simp add: add_le_imp_le_diff) | |
| 870 | have "n = n - k + k" | |
| 60615 
e5fa1d5d3952
Useful lemmas. The theorem concerning swapping the variables in a double integral.
 paulson <lp15@cam.ac.uk> parents: 
60586diff
changeset | 871 | proof - | 
| 66936 | 872 | from \<open>n \<in> ?B\<close> have "n = n - (i + k) + (i + k)" | 
| 873 | by simp | |
| 874 | also have "\<dots> = n - k - i + i + k" | |
| 875 | by (simp add: algebra_simps) | |
| 876 | also have "\<dots> = n - k + k" | |
| 877 | using \<open>i \<le> n - k\<close> by simp | |
| 878 | finally show ?thesis . | |
| 60615 
e5fa1d5d3952
Useful lemmas. The theorem concerning swapping the variables in a double integral.
 paulson <lp15@cam.ac.uk> parents: 
60586diff
changeset | 879 | qed | 
| 66936 | 880 |     moreover have "n - k \<in> {i..j}"
 | 
| 881 | using \<open>n \<in> ?B\<close> | |
| 882 | by (auto simp: add_le_imp_le_diff add_le_add_imp_diff_le) | |
| 883 | ultimately show "n \<in> ?A" | |
| 884 | by (simp add: ac_simps) | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 885 | qed | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 886 | qed | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 887 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 888 | lemma image_add_atLeastAtMost' [simp]: | 
| 66936 | 889 |   "(\<lambda>n. n + k) ` {i..j} = {i + k..j + k}"
 | 
| 890 | by (simp add: add.commute [of _ k]) | |
| 891 | ||
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 892 | lemma image_add_atLeastLessThan [simp]: | 
| 66936 | 893 |   "plus k ` {i..<j} = {i + k..<j + k}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 894 | by (simp add: image_set_diff atLeastLessThan_eq_atLeastAtMost_diff ac_simps) | 
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 895 | |
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 896 | lemma image_add_atLeastLessThan' [simp]: | 
| 66936 | 897 |   "(\<lambda>n. n + k) ` {i..<j} = {i + k..<j + k}"
 | 
| 898 | by (simp add: add.commute [of _ k]) | |
| 899 | ||
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 900 | lemma image_add_greaterThanAtMost[simp]: "(+) c ` {a<..b} = {c + a<..c + b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 901 | by (simp add: image_set_diff greaterThanAtMost_eq_atLeastAtMost_diff ac_simps) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 902 | |
| 66936 | 903 | end | 
| 904 | ||
| 35580 | 905 | context ordered_ab_group_add | 
| 906 | begin | |
| 907 | ||
| 908 | lemma | |
| 909 | fixes x :: 'a | |
| 910 |   shows image_uminus_greaterThan[simp]: "uminus ` {x<..} = {..<-x}"
 | |
| 911 |   and image_uminus_atLeast[simp]: "uminus ` {x..} = {..-x}"
 | |
| 912 | proof safe | |
| 913 | fix y assume "y < -x" | |
| 914 | hence *: "x < -y" using neg_less_iff_less[of "-y" x] by simp | |
| 915 |   have "- (-y) \<in> uminus ` {x<..}"
 | |
| 916 | by (rule imageI) (simp add: *) | |
| 917 |   thus "y \<in> uminus ` {x<..}" by simp
 | |
| 918 | next | |
| 919 | fix y assume "y \<le> -x" | |
| 920 |   have "- (-y) \<in> uminus ` {x..}"
 | |
| 60758 | 921 | by (rule imageI) (insert \<open>y \<le> -x\<close>[THEN le_imp_neg_le], simp) | 
| 35580 | 922 |   thus "y \<in> uminus ` {x..}" by simp
 | 
| 923 | qed simp_all | |
| 924 | ||
| 925 | lemma | |
| 926 | fixes x :: 'a | |
| 927 |   shows image_uminus_lessThan[simp]: "uminus ` {..<x} = {-x<..}"
 | |
| 928 |   and image_uminus_atMost[simp]: "uminus ` {..x} = {-x..}"
 | |
| 929 | proof - | |
| 930 |   have "uminus ` {..<x} = uminus ` uminus ` {-x<..}"
 | |
| 931 |     and "uminus ` {..x} = uminus ` uminus ` {-x..}" by simp_all
 | |
| 932 |   thus "uminus ` {..<x} = {-x<..}" and "uminus ` {..x} = {-x..}"
 | |
| 933 | by (simp_all add: image_image | |
| 934 | del: image_uminus_greaterThan image_uminus_atLeast) | |
| 935 | qed | |
| 936 | ||
| 937 | lemma | |
| 938 | fixes x :: 'a | |
| 939 |   shows image_uminus_atLeastAtMost[simp]: "uminus ` {x..y} = {-y..-x}"
 | |
| 940 |   and image_uminus_greaterThanAtMost[simp]: "uminus ` {x<..y} = {-y..<-x}"
 | |
| 941 |   and image_uminus_atLeastLessThan[simp]: "uminus ` {x..<y} = {-y<..-x}"
 | |
| 942 |   and image_uminus_greaterThanLessThan[simp]: "uminus ` {x<..<y} = {-y<..<-x}"
 | |
| 943 | by (simp_all add: atLeastAtMost_def greaterThanAtMost_def atLeastLessThan_def | |
| 944 | greaterThanLessThan_def image_Int[OF inj_uminus] Int_commute) | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 945 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 946 | lemma image_add_atMost[simp]: "(+) c ` {..a} = {..c + a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 947 | by (auto intro!: image_eqI[where x="x - c" for x] simp: algebra_simps) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 948 | |
| 35580 | 949 | end | 
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 950 | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 951 | lemma image_Suc_atLeastAtMost [simp]: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 952 |   "Suc ` {i..j} = {Suc i..Suc j}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 953 | using image_add_atLeastAtMost [of 1 i j] | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 954 | by (simp only: plus_1_eq_Suc) simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 955 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 956 | lemma image_Suc_atLeastLessThan [simp]: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 957 |   "Suc ` {i..<j} = {Suc i..<Suc j}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 958 | using image_add_atLeastLessThan [of 1 i j] | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 959 | by (simp only: plus_1_eq_Suc) simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 960 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 961 | corollary image_Suc_atMost: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 962 |   "Suc ` {..n} = {1..Suc n}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 963 | by (simp add: atMost_atLeast0 atLeastLessThanSuc_atLeastAtMost) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 964 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 965 | corollary image_Suc_lessThan: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 966 |   "Suc ` {..<n} = {1..n}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 967 | by (simp add: lessThan_atLeast0 atLeastLessThanSuc_atLeastAtMost) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 968 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 969 | lemma image_diff_atLeastAtMost [simp]: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 970 |   fixes d::"'a::linordered_idom" shows "((-) d ` {a..b}) = {d-b..d-a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 971 | apply auto | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 972 | apply (rule_tac x="d-x" in rev_image_eqI, auto) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 973 | done | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 974 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 975 | lemma image_diff_atLeastLessThan [simp]: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 976 | fixes a b c::"'a::linordered_idom" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 977 |   shows "(-) c ` {a..<b} = {c - b<..c - a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 978 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 979 |   have "(-) c ` {a..<b} = (+) c ` uminus ` {a ..<b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 980 | unfolding image_image by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 981 |   also have "\<dots> = {c - b<..c - a}" by simp
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 982 | finally show ?thesis by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 983 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 984 | |
| 67727 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 985 | lemma image_minus_const_greaterThanAtMost[simp]: | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 986 | fixes a b c::"'a::linordered_idom" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 987 |   shows "(-) c ` {a<..b} = {c - b..<c - a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 988 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 989 |   have "(-) c ` {a<..b} = (+) c ` uminus ` {a<..b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 990 | unfolding image_image by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 991 |   also have "\<dots> = {c - b..<c - a}" by simp
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 992 | finally show ?thesis by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 993 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 994 | |
| 67727 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 995 | lemma image_minus_const_atLeast[simp]: | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 996 | fixes a c::"'a::linordered_idom" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 997 |   shows "(-) c ` {a..} = {..c - a}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 998 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 999 |   have "(-) c ` {a..} = (+) c ` uminus ` {a ..}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1000 | unfolding image_image by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1001 |   also have "\<dots> = {..c - a}" by simp
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1002 | finally show ?thesis by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1003 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1004 | |
| 67727 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 1005 | lemma image_minus_const_AtMost[simp]: | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1006 | fixes b c::"'a::linordered_idom" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1007 |   shows "(-) c ` {..b} = {c - b..}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1008 | proof - | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1009 |   have "(-) c ` {..b} = (+) c ` uminus ` {..b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1010 | unfolding image_image by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1011 |   also have "\<dots> = {c - b..}" by simp
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1012 | finally show ?thesis by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1013 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1014 | |
| 67727 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 1015 | lemma image_minus_const_atLeastAtMost' [simp]: | 
| 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 1016 |   "(\<lambda>t. t-d)`{a..b} = {a-d..b-d}" for d::"'a::linordered_idom"
 | 
| 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 1017 | by (metis (no_types, lifting) diff_conv_add_uminus image_add_atLeastAtMost' image_cong) | 
| 
ce3e87a51488
moved Lipschitz continuity from AFP/Ordinary_Differential_Equations and AFP/Gromov_Hyperbolicity; moved lemmas from AFP/Gromov_Hyperbolicity/Library_Complements
 immler parents: 
67685diff
changeset | 1018 | |
| 69502 | 1019 | context linordered_field | 
| 1020 | begin | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1021 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1022 | lemma image_mult_atLeastAtMost [simp]: | 
| 69064 
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
 nipkow parents: 
68618diff
changeset | 1023 |   "((*) d ` {a..b}) = {d*a..d*b}" if "d>0"
 | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1024 | using that | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1025 | by (auto simp: field_simps mult_le_cancel_right intro: rev_image_eqI [where x="x/d" for x]) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1026 | |
| 69502 | 1027 | lemma image_divide_atLeastAtMost [simp]: | 
| 1028 |   "((\<lambda>c. c / d) ` {a..b}) = {a/d..b/d}" if "d>0"
 | |
| 1029 | proof - | |
| 1030 | from that have "inverse d > 0" | |
| 1031 | by simp | |
| 1032 | with image_mult_atLeastAtMost [of "inverse d" a b] | |
| 1033 |   have "(*) (inverse d) ` {a..b} = {inverse d * a..inverse d * b}"
 | |
| 1034 | by blast | |
| 1035 | moreover have "(*) (inverse d) = (\<lambda>c. c / d)" | |
| 1036 | by (simp add: fun_eq_iff field_simps) | |
| 1037 | ultimately show ?thesis | |
| 1038 | by simp | |
| 1039 | qed | |
| 1040 | ||
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1041 | lemma image_mult_atLeastAtMost_if: | 
| 69064 
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
 nipkow parents: 
68618diff
changeset | 1042 |   "(*) c ` {x .. y} =
 | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1043 |     (if c > 0 then {c * x .. c * y} else if x \<le> y then {c * y .. c * x} else {})"
 | 
| 69768 | 1044 | proof (cases "c = 0 \<or> x > y") | 
| 1045 | case True | |
| 1046 | then show ?thesis | |
| 1047 | by auto | |
| 1048 | next | |
| 1049 | case False | |
| 1050 | then have "x \<le> y" | |
| 1051 | by auto | |
| 1052 | from False consider "c < 0"| "c > 0" | |
| 1053 | by (auto simp add: neq_iff) | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1054 | then show ?thesis | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1055 | proof cases | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1056 | case 1 | 
| 69768 | 1057 |     have "(*) c ` {x..y} = {c * y..c * x}"
 | 
| 1058 | proof (rule set_eqI) | |
| 1059 | fix d | |
| 1060 | from 1 have "inj (\<lambda>z. z / c)" | |
| 1061 | by (auto intro: injI) | |
| 1062 |       then have "d \<in> (*) c ` {x..y} \<longleftrightarrow> d / c \<in> (\<lambda>z. z div c) ` (*) c ` {x..y}"
 | |
| 1063 | by (subst inj_image_mem_iff) simp_all | |
| 1064 |       also have "\<dots> \<longleftrightarrow> d / c \<in> {x..y}"
 | |
| 1065 | using 1 by (simp add: image_image) | |
| 1066 |       also have "\<dots> \<longleftrightarrow> d \<in> {c * y..c * x}"
 | |
| 1067 | by (auto simp add: field_simps 1) | |
| 1068 |       finally show "d \<in> (*) c ` {x..y} \<longleftrightarrow> d \<in> {c * y..c * x}" .
 | |
| 1069 | qed | |
| 1070 | with \<open>x \<le> y\<close> show ?thesis | |
| 1071 | by auto | |
| 1072 | qed (simp add: mult_left_mono_neg) | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1073 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1074 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1075 | lemma image_mult_atLeastAtMost_if': | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1076 |   "(\<lambda>x. x * c) ` {x..y} =
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1077 |     (if x \<le> y then if c > 0 then {x * c .. y * c} else {y * c .. x * c} else {})"
 | 
| 69768 | 1078 | using image_mult_atLeastAtMost_if [of c x y] by (auto simp add: ac_simps) | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1079 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1080 | lemma image_affinity_atLeastAtMost: | 
| 69768 | 1081 |   "((\<lambda>x. m * x + c) ` {a..b}) = (if {a..b} = {} then {}
 | 
| 1082 |             else if 0 \<le> m then {m * a + c .. m * b + c}
 | |
| 1083 |             else {m * b + c .. m * a + c})"
 | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1084 | proof - | 
| 69768 | 1085 | have *: "(\<lambda>x. m * x + c) = ((\<lambda>x. x + c) \<circ> (*) m)" | 
| 1086 | by (simp add: fun_eq_iff) | |
| 1087 | show ?thesis by (simp only: * image_comp [symmetric] image_mult_atLeastAtMost_if) | |
| 1088 | (auto simp add: mult_le_cancel_left) | |
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1089 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1090 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1091 | lemma image_affinity_atLeastAtMost_diff: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1092 |   "((\<lambda>x. m*x - c) ` {a..b}) = (if {a..b}={} then {}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1093 |             else if 0 \<le> m then {m*a - c .. m*b - c}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1094 |             else {m*b - c .. m*a - c})"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1095 | using image_affinity_atLeastAtMost [of m "-c" a b] | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1096 | by simp | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1097 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1098 | lemma image_affinity_atLeastAtMost_div: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1099 |   "((\<lambda>x. x/m + c) ` {a..b}) = (if {a..b}={} then {}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1100 |             else if 0 \<le> m then {a/m + c .. b/m + c}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1101 |             else {b/m + c .. a/m + c})"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1102 | using image_affinity_atLeastAtMost [of "inverse m" c a b] | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1103 | by (simp add: field_class.field_divide_inverse algebra_simps inverse_eq_divide) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1104 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1105 | lemma image_affinity_atLeastAtMost_div_diff: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1106 |   "((\<lambda>x. x/m - c) ` {a..b}) = (if {a..b}={} then {}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1107 |             else if 0 \<le> m then {a/m - c .. b/m - c}
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1108 |             else {b/m - c .. a/m - c})"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1109 | using image_affinity_atLeastAtMost_diff [of "inverse m" c a b] | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1110 | by (simp add: field_class.field_divide_inverse algebra_simps inverse_eq_divide) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1111 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1112 | end | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1113 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1114 | lemma atLeast1_lessThan_eq_remove0: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1115 |   "{Suc 0..<n} = {..<n} - {0}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1116 | by auto | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1117 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1118 | lemma atLeast1_atMost_eq_remove0: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1119 |   "{Suc 0..n} = {..n} - {0}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1120 | by auto | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1121 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1122 | lemma image_add_int_atLeastLessThan: | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1123 |     "(\<lambda>x. x + (l::int)) ` {0..<u-l} = {l..<u}"
 | 
| 67685 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1124 | apply (auto simp add: image_def) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1125 | apply (rule_tac x = "x - l" in bexI) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1126 | apply auto | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1127 | done | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1128 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1129 | lemma image_minus_const_atLeastLessThan_nat: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1130 | fixes c :: nat | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1131 |   shows "(\<lambda>i. i - c) ` {x ..< y} =
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1132 |       (if c < y then {x - c ..< y - c} else if x < y then {0} else {})"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1133 | (is "_ = ?right") | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1134 | proof safe | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1135 | fix a assume a: "a \<in> ?right" | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1136 |   show "a \<in> (\<lambda>i. i - c) ` {x ..< y}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1137 | proof cases | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1138 | assume "c < y" with a show ?thesis | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1139 | by (auto intro!: image_eqI[of _ _ "a + c"]) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1140 | next | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1141 | assume "\<not> c < y" with a show ?thesis | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1142 | by (auto intro!: image_eqI[of _ _ x] split: if_split_asm) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1143 | qed | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1144 | qed auto | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1145 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1146 | lemma image_int_atLeastLessThan: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1147 |   "int ` {a..<b} = {int a..<int b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1148 | by (auto intro!: image_eqI [where x = "nat x" for x]) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1149 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1150 | lemma image_int_atLeastAtMost: | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1151 |   "int ` {a..b} = {int a..int b}"
 | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1152 | by (auto intro!: image_eqI [where x = "nat x" for x]) | 
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1153 | |
| 
bdff8bf0a75b
moved theorems from AFP/Affine_Arithmetic and AFP/Ordinary_Differential_Equations
 immler parents: 
67613diff
changeset | 1154 | |
| 60758 | 1155 | subsubsection \<open>Finiteness\<close> | 
| 14485 | 1156 | |
| 15045 | 1157 | lemma finite_lessThan [iff]: fixes k :: nat shows "finite {..<k}"
 | 
| 14485 | 1158 | by (induct k) (simp_all add: lessThan_Suc) | 
| 1159 | ||
| 1160 | lemma finite_atMost [iff]: fixes k :: nat shows "finite {..k}"
 | |
| 1161 | by (induct k) (simp_all add: atMost_Suc) | |
| 1162 | ||
| 1163 | lemma finite_greaterThanLessThan [iff]: | |
| 15045 | 1164 |   fixes l :: nat shows "finite {l<..<u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1165 | by (simp add: greaterThanLessThan_def) | 
| 14485 | 1166 | |
| 1167 | lemma finite_atLeastLessThan [iff]: | |
| 15045 | 1168 |   fixes l :: nat shows "finite {l..<u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1169 | by (simp add: atLeastLessThan_def) | 
| 14485 | 1170 | |
| 1171 | lemma finite_greaterThanAtMost [iff]: | |
| 15045 | 1172 |   fixes l :: nat shows "finite {l<..u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1173 | by (simp add: greaterThanAtMost_def) | 
| 14485 | 1174 | |
| 1175 | lemma finite_atLeastAtMost [iff]: | |
| 1176 |   fixes l :: nat shows "finite {l..u}"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1177 | by (simp add: atLeastAtMost_def) | 
| 14485 | 1178 | |
| 60758 | 1179 | text \<open>A bounded set of natural numbers is finite.\<close> | 
| 67613 | 1180 | lemma bounded_nat_set_is_finite: "(\<forall>i\<in>N. i < (n::nat)) \<Longrightarrow> finite N" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1181 | by (rule finite_subset [OF _ finite_lessThan]) auto | 
| 28068 | 1182 | |
| 60758 | 1183 | text \<open>A set of natural numbers is finite iff it is bounded.\<close> | 
| 31044 | 1184 | lemma finite_nat_set_iff_bounded: | 
| 67091 | 1185 | "finite(N::nat set) = (\<exists>m. \<forall>n\<in>N. n<m)" (is "?F = ?B") | 
| 31044 | 1186 | proof | 
| 1187 | assume f:?F show ?B | |
| 60758 | 1188 | using Max_ge[OF \<open>?F\<close>, simplified less_Suc_eq_le[symmetric]] by blast | 
| 31044 | 1189 | next | 
| 60758 | 1190 | assume ?B show ?F using \<open>?B\<close> by(blast intro:bounded_nat_set_is_finite) | 
| 31044 | 1191 | qed | 
| 1192 | ||
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1193 | lemma finite_nat_set_iff_bounded_le: "finite(N::nat set) = (\<exists>m. \<forall>n\<in>N. n\<le>m)" | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1194 | unfolding finite_nat_set_iff_bounded | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1195 | by (blast dest:less_imp_le_nat le_imp_less_Suc) | 
| 31044 | 1196 | |
| 28068 | 1197 | lemma finite_less_ub: | 
| 1198 |      "!!f::nat=>nat. (!!n. n \<le> f n) ==> finite {n. f n \<le> u}"
 | |
| 1199 | by (rule_tac B="{..u}" in finite_subset, auto intro: order_trans)
 | |
| 14485 | 1200 | |
| 64773 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1201 | lemma bounded_Max_nat: | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1202 | fixes P :: "nat \<Rightarrow> bool" | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1203 | assumes x: "P x" and M: "\<And>x. P x \<Longrightarrow> x \<le> M" | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1204 | obtains m where "P m" "\<And>x. P x \<Longrightarrow> x \<le> m" | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1205 | proof - | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1206 |   have "finite {x. P x}"
 | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1207 | using M finite_nat_set_iff_bounded_le by auto | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1208 |   then have "Max {x. P x} \<in> {x. P x}"
 | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1209 | using Max_in x by auto | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1210 | then show ?thesis | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1211 |     by (simp add: \<open>finite {x. P x}\<close> that)
 | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1212 | qed | 
| 
223b2ebdda79
Many new theorems, and more tidying
 paulson <lp15@cam.ac.uk> parents: 
64272diff
changeset | 1213 | |
| 56328 | 1214 | |
| 60758 | 1215 | text\<open>Any subset of an interval of natural numbers the size of the | 
| 1216 | subset is exactly that interval.\<close> | |
| 24853 | 1217 | |
| 1218 | lemma subset_card_intvl_is_intvl: | |
| 55085 
0e8e4dc55866
moved 'fundef_cong' attribute (and other basic 'fun' stuff) up the dependency chain
 blanchet parents: 
54606diff
changeset | 1219 |   assumes "A \<subseteq> {k..<k + card A}"
 | 
| 
0e8e4dc55866
moved 'fundef_cong' attribute (and other basic 'fun' stuff) up the dependency chain
 blanchet parents: 
54606diff
changeset | 1220 |   shows "A = {k..<k + card A}"
 | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1221 | proof (cases "finite A") | 
| 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1222 | case True | 
| 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1223 | from this and assms show ?thesis | 
| 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1224 | proof (induct A rule: finite_linorder_max_induct) | 
| 24853 | 1225 | case empty thus ?case by auto | 
| 1226 | next | |
| 33434 | 1227 | case (insert b A) | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1228 | hence *: "b \<notin> A" by auto | 
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 1229 |     with insert have "A \<le> {k..<k + card A}" and "b = k + card A"
 | 
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1230 | by fastforce+ | 
| 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1231 | with insert * show ?case by auto | 
| 24853 | 1232 | qed | 
| 1233 | next | |
| 53374 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1234 | case False | 
| 
a14d2a854c02
tuned proofs -- clarified flow of facts wrt. calculation;
 wenzelm parents: 
53216diff
changeset | 1235 | with assms show ?thesis by simp | 
| 24853 | 1236 | qed | 
| 1237 | ||
| 1238 | ||
| 60758 | 1239 | subsubsection \<open>Proving Inclusions and Equalities between Unions\<close> | 
| 32596 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1240 | |
| 36755 | 1241 | lemma UN_le_eq_Un0: | 
| 1242 |   "(\<Union>i\<le>n::nat. M i) = (\<Union>i\<in>{1..n}. M i) \<union> M 0" (is "?A = ?B")
 | |
| 1243 | proof | |
| 67613 | 1244 | show "?A \<subseteq> ?B" | 
| 36755 | 1245 | proof | 
| 67613 | 1246 | fix x assume "x \<in> ?A" | 
| 1247 | then obtain i where i: "i\<le>n" "x \<in> M i" by auto | |
| 1248 | show "x \<in> ?B" | |
| 36755 | 1249 | proof(cases i) | 
| 1250 | case 0 with i show ?thesis by simp | |
| 1251 | next | |
| 1252 | case (Suc j) with i show ?thesis by auto | |
| 1253 | qed | |
| 1254 | qed | |
| 1255 | next | |
| 67613 | 1256 | show "?B \<subseteq> ?A" by fastforce | 
| 36755 | 1257 | qed | 
| 1258 | ||
| 1259 | lemma UN_le_add_shift: | |
| 1260 |   "(\<Union>i\<le>n::nat. M(i+k)) = (\<Union>i\<in>{k..n+k}. M i)" (is "?A = ?B")
 | |
| 1261 | proof | |
| 67613 | 1262 | show "?A \<subseteq> ?B" by fastforce | 
| 36755 | 1263 | next | 
| 67613 | 1264 | show "?B \<subseteq> ?A" | 
| 36755 | 1265 | proof | 
| 67613 | 1266 | fix x assume "x \<in> ?B" | 
| 1267 |     then obtain i where i: "i \<in> {k..n+k}" "x \<in> M(i)" by auto
 | |
| 67091 | 1268 | hence "i-k\<le>n \<and> x \<in> M((i-k)+k)" by auto | 
| 1269 | thus "x \<in> ?A" by blast | |
| 36755 | 1270 | qed | 
| 1271 | qed | |
| 1272 | ||
| 70723 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1273 | lemma UN_le_add_shift_strict: | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1274 |   "(\<Union>i<n::nat. M(i+k)) = (\<Union>i\<in>{k..<n+k}. M i)" (is "?A = ?B")
 | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1275 | proof | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1276 | show "?B \<subseteq> ?A" | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1277 | proof | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1278 | fix x assume "x \<in> ?B" | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1279 |     then obtain i where i: "i \<in> {k..<n+k}" "x \<in> M(i)" by auto
 | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1280 | then have "i - k < n \<and> x \<in> M((i-k) + k)" by auto | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1281 | then show "x \<in> ?A" using UN_le_add_shift by blast | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1282 | qed | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1283 | qed (fastforce) | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70365diff
changeset | 1284 | |
| 62369 | 1285 | lemma UN_UN_finite_eq: "(\<Union>n::nat. \<Union>i\<in>{0..<n}. A i) = (\<Union>n. A n)"
 | 
| 1286 | by (auto simp add: atLeast0LessThan) | |
| 32596 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1287 | |
| 62343 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1288 | lemma UN_finite_subset: | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1289 |   "(\<And>n::nat. (\<Union>i\<in>{0..<n}. A i) \<subseteq> C) \<Longrightarrow> (\<Union>n. A n) \<subseteq> C"
 | 
| 32596 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1290 | by (subst UN_UN_finite_eq [symmetric]) blast | 
| 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1291 | |
| 62369 | 1292 | lemma UN_finite2_subset: | 
| 62343 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1293 |   assumes "\<And>n::nat. (\<Union>i\<in>{0..<n}. A i) \<subseteq> (\<Union>i\<in>{0..<n + k}. B i)"
 | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1294 | shows "(\<Union>n. A n) \<subseteq> (\<Union>n. B n)" | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1295 | proof (rule UN_finite_subset, rule) | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1296 | fix n and a | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1297 |   from assms have "(\<Union>i\<in>{0..<n}. A i) \<subseteq> (\<Union>i\<in>{0..<n + k}. B i)" .
 | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1298 |   moreover assume "a \<in> (\<Union>i\<in>{0..<n}. A i)"
 | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1299 |   ultimately have "a \<in> (\<Union>i\<in>{0..<n + k}. B i)" by blast
 | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1300 | then show "a \<in> (\<Union>i. B i)" by (auto simp add: UN_UN_finite_eq) | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1301 | qed | 
| 32596 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1302 | |
| 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1303 | lemma UN_finite2_eq: | 
| 62343 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1304 |   "(\<And>n::nat. (\<Union>i\<in>{0..<n}. A i) = (\<Union>i\<in>{0..<n + k}. B i)) \<Longrightarrow>
 | 
| 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1305 | (\<Union>n. A n) = (\<Union>n. B n)" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1306 | apply (rule subset_antisym [OF UN_finite_subset UN_finite2_subset]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1307 | apply auto | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1308 | apply (force simp add: atLeastLessThan_add_Un [of 0])+ | 
| 62343 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62128diff
changeset | 1309 | done | 
| 32596 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1310 | |
| 
bd68c04dace1
New theorems for proving equalities and inclusions involving unions
 paulson parents: 
32456diff
changeset | 1311 | |
| 60758 | 1312 | subsubsection \<open>Cardinality\<close> | 
| 14485 | 1313 | |
| 15045 | 1314 | lemma card_lessThan [simp]: "card {..<u} = u"
 | 
| 15251 | 1315 | by (induct u, simp_all add: lessThan_Suc) | 
| 14485 | 1316 | |
| 1317 | lemma card_atMost [simp]: "card {..u} = Suc u"
 | |
| 1318 | by (simp add: lessThan_Suc_atMost [THEN sym]) | |
| 1319 | ||
| 15045 | 1320 | lemma card_atLeastLessThan [simp]: "card {l..<u} = u - l"
 | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1321 | proof - | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1322 |   have "{l..<u} = (\<lambda>x. x + l) ` {..<u-l}"
 | 
| 57113 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1323 | apply (auto simp add: image_def atLeastLessThan_def lessThan_def) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1324 | apply (rule_tac x = "x - l" in exI) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1325 | apply arith | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1326 | done | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1327 |   then have "card {l..<u} = card {..<u-l}"
 | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1328 | by (simp add: card_image inj_on_def) | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1329 | then show ?thesis | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1330 | by simp | 
| 
7e95523302e6
New theorems to enable the simplification of certain functions when applied to specific natural number constants (such as 4)
 paulson <lp15@cam.ac.uk> parents: 
56949diff
changeset | 1331 | qed | 
| 14485 | 1332 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1333 | lemma card_atLeastAtMost [simp]: "card {l..u} = Suc u - l"
 | 
| 14485 | 1334 | by (subst atLeastLessThanSuc_atLeastAtMost [THEN sym], simp) | 
| 1335 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1336 | lemma card_greaterThanAtMost [simp]: "card {l<..u} = u - l"
 | 
| 14485 | 1337 | by (subst atLeastSucAtMost_greaterThanAtMost [THEN sym], simp) | 
| 1338 | ||
| 15045 | 1339 | lemma card_greaterThanLessThan [simp]: "card {l<..<u} = u - Suc l"
 | 
| 14485 | 1340 | by (subst atLeastSucLessThan_greaterThanLessThan [THEN sym], simp) | 
| 1341 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1342 | lemma subset_eq_atLeast0_lessThan_finite: | 
| 63365 | 1343 | fixes n :: nat | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1344 |   assumes "N \<subseteq> {0..<n}"
 | 
| 63915 | 1345 | shows "finite N" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1346 | using assms finite_atLeastLessThan by (rule finite_subset) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1347 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1348 | lemma subset_eq_atLeast0_atMost_finite: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1349 | fixes n :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1350 |   assumes "N \<subseteq> {0..n}"
 | 
| 63915 | 1351 | shows "finite N" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1352 | using assms finite_atLeastAtMost by (rule finite_subset) | 
| 63365 | 1353 | |
| 26105 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1354 | lemma ex_bij_betw_nat_finite: | 
| 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1355 |   "finite M \<Longrightarrow> \<exists>h. bij_betw h {0..<card M} M"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1356 | apply(drule finite_imp_nat_seg_image_inj_on) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1357 | apply(auto simp:atLeast0LessThan[symmetric] lessThan_def[symmetric] card_image bij_betw_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1358 | done | 
| 26105 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1359 | |
| 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1360 | lemma ex_bij_betw_finite_nat: | 
| 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1361 |   "finite M \<Longrightarrow> \<exists>h. bij_betw h M {0..<card M}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1362 | by (blast dest: ex_bij_betw_nat_finite bij_betw_inv) | 
| 26105 
ae06618225ec
moved bij_betw from Library/FuncSet to Fun, redistributed some lemmas, and
 nipkow parents: 
26072diff
changeset | 1363 | |
| 31438 | 1364 | lemma finite_same_card_bij: | 
| 67091 | 1365 | "finite A \<Longrightarrow> finite B \<Longrightarrow> card A = card B \<Longrightarrow> \<exists>h. bij_betw h A B" | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1366 | apply(drule ex_bij_betw_finite_nat) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1367 | apply(drule ex_bij_betw_nat_finite) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1368 | apply(auto intro!:bij_betw_trans) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1369 | done | 
| 31438 | 1370 | |
| 1371 | lemma ex_bij_betw_nat_finite_1: | |
| 1372 |   "finite M \<Longrightarrow> \<exists>h. bij_betw h {1 .. card M} M"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1373 | by (rule finite_same_card_bij) auto | 
| 31438 | 1374 | |
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 1375 | lemma bij_betw_iff_card: | 
| 63114 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1376 | assumes "finite A" "finite B" | 
| 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1377 | shows "(\<exists>f. bij_betw f A B) \<longleftrightarrow> (card A = card B)" | 
| 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1378 | proof | 
| 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1379 | assume "card A = card B" | 
| 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1380 |   moreover obtain f where "bij_betw f A {0 ..< card A}"
 | 
| 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1381 | using assms ex_bij_betw_finite_nat by blast | 
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 1382 |   moreover obtain g where "bij_betw g {0 ..< card B} B"
 | 
| 63114 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1383 | using assms ex_bij_betw_nat_finite by blast | 
| 67091 | 1384 | ultimately have "bij_betw (g \<circ> f) A B" | 
| 63114 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1385 | by (auto simp: bij_betw_trans) | 
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 1386 | thus "(\<exists>f. bij_betw f A B)" by blast | 
| 63114 
27afe7af7379
Lots of new material for multivariate analysis
 paulson <lp15@cam.ac.uk> parents: 
63099diff
changeset | 1387 | qed (auto simp: bij_betw_same_card) | 
| 40703 
d1fc454d6735
Move some missing lemmas from Andrei Popescus 'Ordinals and Cardinals' AFP entry to the HOL-image.
 hoelzl parents: 
39302diff
changeset | 1388 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1389 | lemma subset_eq_atLeast0_lessThan_card: | 
| 63365 | 1390 | fixes n :: nat | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1391 |   assumes "N \<subseteq> {0..<n}"
 | 
| 63365 | 1392 | shows "card N \<le> n" | 
| 1393 | proof - | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1394 |   from assms finite_lessThan have "card N \<le> card {0..<n}"
 | 
| 63365 | 1395 | using card_mono by blast | 
| 1396 | then show ?thesis by simp | |
| 1397 | qed | |
| 1398 | ||
| 69235 | 1399 | text \<open>Relational version of @{thm [source] card_inj_on_le}:\<close>
 | 
| 1400 | lemma card_le_if_inj_on_rel: | |
| 1401 | assumes "finite B" | |
| 1402 | "\<And>a. a \<in> A \<Longrightarrow> \<exists>b. b\<in>B \<and> r a b" | |
| 1403 | "\<And>a1 a2 b. \<lbrakk> a1 \<in> A; a2 \<in> A; b \<in> B; r a1 b; r a2 b \<rbrakk> \<Longrightarrow> a1 = a2" | |
| 1404 | shows "card A \<le> card B" | |
| 1405 | proof - | |
| 1406 | let ?P = "\<lambda>a b. b \<in> B \<and> r a b" | |
| 1407 | let ?f = "\<lambda>a. SOME b. ?P a b" | |
| 1408 | have 1: "?f ` A \<subseteq> B" by (auto intro: someI2_ex[OF assms(2)]) | |
| 1409 | have "inj_on ?f A" | |
| 1410 | proof (auto simp: inj_on_def) | |
| 1411 | fix a1 a2 assume asms: "a1 \<in> A" "a2 \<in> A" "?f a1 = ?f a2" | |
| 1412 | have 0: "?f a1 \<in> B" using "1" \<open>a1 \<in> A\<close> by blast | |
| 1413 | have 1: "r a1 (?f a1)" using someI_ex[OF assms(2)[OF \<open>a1 \<in> A\<close>]] by blast | |
| 1414 | have 2: "r a2 (?f a1)" using someI_ex[OF assms(2)[OF \<open>a2 \<in> A\<close>]] asms(3) by auto | |
| 1415 | show "a1 = a2" using assms(3)[OF asms(1,2) 0 1 2] . | |
| 1416 | qed | |
| 1417 | with 1 show ?thesis using card_inj_on_le[of ?f A B] assms(1) by simp | |
| 1418 | qed | |
| 1419 | ||
| 63365 | 1420 | |
| 60758 | 1421 | subsection \<open>Intervals of integers\<close> | 
| 14485 | 1422 | |
| 15045 | 1423 | lemma atLeastLessThanPlusOne_atLeastAtMost_int: "{l..<u+1} = {l..(u::int)}"
 | 
| 14485 | 1424 | by (auto simp add: atLeastAtMost_def atLeastLessThan_def) | 
| 1425 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1426 | lemma atLeastPlusOneAtMost_greaterThanAtMost_int: "{l+1..u} = {l<..(u::int)}"
 | 
| 14485 | 1427 | by (auto simp add: atLeastAtMost_def greaterThanAtMost_def) | 
| 1428 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1429 | lemma atLeastPlusOneLessThan_greaterThanLessThan_int: | 
| 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1430 |     "{l+1..<u} = {l<..<u::int}"
 | 
| 14485 | 1431 | by (auto simp add: atLeastLessThan_def greaterThanLessThan_def) | 
| 1432 | ||
| 60758 | 1433 | subsubsection \<open>Finiteness\<close> | 
| 14485 | 1434 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1435 | lemma image_atLeastZeroLessThan_int: "0 \<le> u ==> | 
| 15045 | 1436 |     {(0::int)..<u} = int ` {..<nat u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1437 | unfolding image_def lessThan_def | 
| 14485 | 1438 | apply auto | 
| 1439 | apply (rule_tac x = "nat x" in exI) | |
| 35216 | 1440 | apply (auto simp add: zless_nat_eq_int_zless [THEN sym]) | 
| 14485 | 1441 | done | 
| 1442 | ||
| 15045 | 1443 | lemma finite_atLeastZeroLessThan_int: "finite {(0::int)..<u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1444 | proof (cases "0 \<le> u") | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1445 | case True | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1446 | then show ?thesis | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1447 | by (auto simp: image_atLeastZeroLessThan_int) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1448 | qed auto | 
| 14485 | 1449 | |
| 15045 | 1450 | lemma finite_atLeastLessThan_int [iff]: "finite {l..<u::int}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1451 | by (simp only: image_add_int_atLeastLessThan [symmetric, of l] finite_imageI finite_atLeastZeroLessThan_int) | 
| 14485 | 1452 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1453 | lemma finite_atLeastAtMost_int [iff]: "finite {l..(u::int)}"
 | 
| 14485 | 1454 | by (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym], simp) | 
| 1455 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1456 | lemma finite_greaterThanAtMost_int [iff]: "finite {l<..(u::int)}"
 | 
| 14485 | 1457 | by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp) | 
| 1458 | ||
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1459 | lemma finite_greaterThanLessThan_int [iff]: "finite {l<..<u::int}"
 | 
| 14485 | 1460 | by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp) | 
| 1461 | ||
| 24853 | 1462 | |
| 60758 | 1463 | subsubsection \<open>Cardinality\<close> | 
| 14485 | 1464 | |
| 15045 | 1465 | lemma card_atLeastZeroLessThan_int: "card {(0::int)..<u} = nat u"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1466 | proof (cases "0 \<le> u") | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1467 | case True | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1468 | then show ?thesis | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1469 | by (auto simp: image_atLeastZeroLessThan_int card_image inj_on_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1470 | qed auto | 
| 14485 | 1471 | |
| 15045 | 1472 | lemma card_atLeastLessThan_int [simp]: "card {l..<u} = nat (u - l)"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1473 | proof - | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1474 |   have "card {l..<u} = card {0..<u-l}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1475 | apply (subst image_add_int_atLeastLessThan [symmetric]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1476 | apply (rule card_image) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1477 | apply (simp add: inj_on_def) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1478 | done | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1479 | then show ?thesis | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1480 | by (simp add: card_atLeastZeroLessThan_int) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1481 | qed | 
| 14485 | 1482 | |
| 1483 | lemma card_atLeastAtMost_int [simp]: "card {l..u} = nat (u - l + 1)"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1484 | apply (subst atLeastLessThanPlusOne_atLeastAtMost_int [THEN sym]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1485 | apply (auto simp add: algebra_simps) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1486 | done | 
| 14485 | 1487 | |
| 15418 
e28853da5df5
removed two looping simplifications in SetInterval.thy; deleted the .ML file
 paulson parents: 
15402diff
changeset | 1488 | lemma card_greaterThanAtMost_int [simp]: "card {l<..u} = nat (u - l)"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1489 | by (subst atLeastPlusOneAtMost_greaterThanAtMost_int [THEN sym], simp) | 
| 14485 | 1490 | |
| 15045 | 1491 | lemma card_greaterThanLessThan_int [simp]: "card {l<..<u} = nat (u - (l + 1))"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1492 | by (subst atLeastPlusOneLessThan_greaterThanLessThan_int [THEN sym], simp) | 
| 14485 | 1493 | |
| 27656 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1494 | lemma finite_M_bounded_by_nat: "finite {k. P k \<and> k < (i::nat)}"
 | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1495 | proof - | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1496 |   have "{k. P k \<and> k < i} \<subseteq> {..<i}" by auto
 | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1497 | with finite_lessThan[of "i"] show ?thesis by (simp add: finite_subset) | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1498 | qed | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1499 | |
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1500 | lemma card_less: | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1501 | assumes zero_in_M: "0 \<in> M" | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1502 |   shows "card {k \<in> M. k < Suc i} \<noteq> 0"
 | 
| 27656 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1503 | proof - | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1504 |   from zero_in_M have "{k \<in> M. k < Suc i} \<noteq> {}" by auto
 | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1505 | with finite_M_bounded_by_nat show ?thesis by (auto simp add: card_eq_0_iff) | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1506 | qed | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1507 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1508 | lemma card_less_Suc2: | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1509 |   assumes "0 \<notin> M" shows "card {k. Suc k \<in> M \<and> k < i} = card {k \<in> M. k < Suc i}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1510 | proof - | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1511 | have *: "\<lbrakk>j \<in> M; j < Suc i\<rbrakk> \<Longrightarrow> j - Suc 0 < i \<and> Suc (j - Suc 0) \<in> M \<and> Suc 0 \<le> j" for j | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1512 | by (cases j) (use assms in auto) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1513 | show ?thesis | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1514 | proof (rule card_bij_eq) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1515 |     show "inj_on Suc {k. Suc k \<in> M \<and> k < i}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1516 | by force | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1517 |     show "inj_on (\<lambda>x. x - Suc 0) {k \<in> M. k < Suc i}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1518 | by (rule inj_on_diff_nat) (use * in blast) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1519 | qed (use * in auto) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1520 | qed | 
| 27656 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1521 | |
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1522 | lemma card_less_Suc: | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1523 | assumes "0 \<in> M" | 
| 27656 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1524 |     shows "Suc (card {k. Suc k \<in> M \<and> k < i}) = card {k \<in> M. k < Suc i}"
 | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1525 | proof - | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1526 |   have "Suc (card {k. Suc k \<in> M \<and> k < i}) = Suc (card {k. Suc k \<in> M - {0} \<and> k < i})"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1527 | by simp | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1528 |   also have "\<dots> = Suc (card {k \<in> M - {0}. k < Suc i})"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1529 | apply (subst card_less_Suc2) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1530 | using assms by auto | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1531 |   also have "\<dots> = Suc (card ({k \<in> M. k < Suc i} - {0}))"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1532 | by (force intro: arg_cong [where f=card]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1533 |   also have "\<dots> = card (insert 0 ({k \<in> M. k < Suc i} - {0}))"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1534 | by (simp add: card_insert) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1535 |   also have "... = card {k \<in> M. k < Suc i}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1536 | using assms | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1537 | by (force simp add: intro: arg_cong [where f=card]) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1538 | finally show ?thesis. | 
| 27656 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1539 | qed | 
| 
d4f6e64ee7cc
added verification framework for the HeapMonad and quicksort as example for this framework
 bulwahn parents: 
26105diff
changeset | 1540 | |
| 14485 | 1541 | |
| 64267 | 1542 | subsection \<open>Lemmas useful with the summation operator sum\<close> | 
| 13850 | 1543 | |
| 60758 | 1544 | text \<open>For examples, see Algebra/poly/UnivPoly2.thy\<close> | 
| 13735 | 1545 | |
| 60758 | 1546 | subsubsection \<open>Disjoint Unions\<close> | 
| 13735 | 1547 | |
| 60758 | 1548 | text \<open>Singletons and open intervals\<close> | 
| 13735 | 1549 | |
| 1550 | lemma ivl_disj_un_singleton: | |
| 15045 | 1551 |   "{l::'a::linorder} Un {l<..} = {l..}"
 | 
| 1552 |   "{..<u} Un {u::'a::linorder} = {..u}"
 | |
| 1553 |   "(l::'a::linorder) < u ==> {l} Un {l<..<u} = {l..<u}"
 | |
| 1554 |   "(l::'a::linorder) < u ==> {l<..<u} Un {u} = {l<..u}"
 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1555 |   "(l::'a::linorder) \<le> u ==> {l} Un {l<..u} = {l..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1556 |   "(l::'a::linorder) \<le> u ==> {l..<u} Un {u} = {l..u}"
 | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: 
13850diff
changeset | 1557 | by auto | 
| 13735 | 1558 | |
| 60758 | 1559 | text \<open>One- and two-sided intervals\<close> | 
| 13735 | 1560 | |
| 1561 | lemma ivl_disj_un_one: | |
| 15045 | 1562 |   "(l::'a::linorder) < u ==> {..l} Un {l<..<u} = {..<u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1563 |   "(l::'a::linorder) \<le> u ==> {..<l} Un {l..<u} = {..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1564 |   "(l::'a::linorder) \<le> u ==> {..l} Un {l<..u} = {..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1565 |   "(l::'a::linorder) \<le> u ==> {..<l} Un {l..u} = {..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1566 |   "(l::'a::linorder) \<le> u ==> {l<..u} Un {u<..} = {l<..}"
 | 
| 15045 | 1567 |   "(l::'a::linorder) < u ==> {l<..<u} Un {u..} = {l<..}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1568 |   "(l::'a::linorder) \<le> u ==> {l..u} Un {u<..} = {l..}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1569 |   "(l::'a::linorder) \<le> u ==> {l..<u} Un {u..} = {l..}"
 | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: 
13850diff
changeset | 1570 | by auto | 
| 13735 | 1571 | |
| 60758 | 1572 | text \<open>Two- and two-sided intervals\<close> | 
| 13735 | 1573 | |
| 1574 | lemma ivl_disj_un_two: | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1575 |   "[| (l::'a::linorder) < m; m \<le> u |] ==> {l<..<m} Un {m..<u} = {l<..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1576 |   "[| (l::'a::linorder) \<le> m; m < u |] ==> {l<..m} Un {m<..<u} = {l<..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1577 |   "[| (l::'a::linorder) \<le> m; m \<le> u |] ==> {l..<m} Un {m..<u} = {l..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1578 |   "[| (l::'a::linorder) \<le> m; m < u |] ==> {l..m} Un {m<..<u} = {l..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1579 |   "[| (l::'a::linorder) < m; m \<le> u |] ==> {l<..<m} Un {m..u} = {l<..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1580 |   "[| (l::'a::linorder) \<le> m; m \<le> u |] ==> {l<..m} Un {m<..u} = {l<..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1581 |   "[| (l::'a::linorder) \<le> m; m \<le> u |] ==> {l..<m} Un {m..u} = {l..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1582 |   "[| (l::'a::linorder) \<le> m; m \<le> u |] ==> {l..m} Un {m<..u} = {l..u}"
 | 
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: 
13850diff
changeset | 1583 | by auto | 
| 13735 | 1584 | |
| 60150 
bd773c47ad0b
New material about complex transcendental functions (especially Ln, Arg) and polynomials
 paulson <lp15@cam.ac.uk> parents: 
60017diff
changeset | 1585 | lemma ivl_disj_un_two_touch: | 
| 
bd773c47ad0b
New material about complex transcendental functions (especially Ln, Arg) and polynomials
 paulson <lp15@cam.ac.uk> parents: 
60017diff
changeset | 1586 |   "[| (l::'a::linorder) < m; m < u |] ==> {l<..m} Un {m..<u} = {l<..<u}"
 | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1587 |   "[| (l::'a::linorder) \<le> m; m < u |] ==> {l..m} Un {m..<u} = {l..<u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1588 |   "[| (l::'a::linorder) < m; m \<le> u |] ==> {l<..m} Un {m..u} = {l<..u}"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1589 |   "[| (l::'a::linorder) \<le> m; m \<le> u |] ==> {l..m} Un {m..u} = {l..u}"
 | 
| 60150 
bd773c47ad0b
New material about complex transcendental functions (especially Ln, Arg) and polynomials
 paulson <lp15@cam.ac.uk> parents: 
60017diff
changeset | 1590 | by auto | 
| 
bd773c47ad0b
New material about complex transcendental functions (especially Ln, Arg) and polynomials
 paulson <lp15@cam.ac.uk> parents: 
60017diff
changeset | 1591 | |
| 
bd773c47ad0b
New material about complex transcendental functions (especially Ln, Arg) and polynomials
 paulson <lp15@cam.ac.uk> parents: 
60017diff
changeset | 1592 | lemmas ivl_disj_un = ivl_disj_un_singleton ivl_disj_un_one ivl_disj_un_two ivl_disj_un_two_touch | 
| 13735 | 1593 | |
| 60758 | 1594 | subsubsection \<open>Disjoint Intersections\<close> | 
| 13735 | 1595 | |
| 60758 | 1596 | text \<open>One- and two-sided intervals\<close> | 
| 13735 | 1597 | |
| 1598 | lemma ivl_disj_int_one: | |
| 15045 | 1599 |   "{..l::'a::order} Int {l<..<u} = {}"
 | 
| 1600 |   "{..<l} Int {l..<u} = {}"
 | |
| 1601 |   "{..l} Int {l<..u} = {}"
 | |
| 1602 |   "{..<l} Int {l..u} = {}"
 | |
| 1603 |   "{l<..u} Int {u<..} = {}"
 | |
| 1604 |   "{l<..<u} Int {u..} = {}"
 | |
| 1605 |   "{l..u} Int {u<..} = {}"
 | |
| 1606 |   "{l..<u} Int {u..} = {}"
 | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: 
13850diff
changeset | 1607 | by auto | 
| 13735 | 1608 | |
| 60758 | 1609 | text \<open>Two- and two-sided intervals\<close> | 
| 13735 | 1610 | |
| 1611 | lemma ivl_disj_int_two: | |
| 15045 | 1612 |   "{l::'a::order<..<m} Int {m..<u} = {}"
 | 
| 1613 |   "{l<..m} Int {m<..<u} = {}"
 | |
| 1614 |   "{l..<m} Int {m..<u} = {}"
 | |
| 1615 |   "{l..m} Int {m<..<u} = {}"
 | |
| 1616 |   "{l<..<m} Int {m..u} = {}"
 | |
| 1617 |   "{l<..m} Int {m<..u} = {}"
 | |
| 1618 |   "{l..<m} Int {m..u} = {}"
 | |
| 1619 |   "{l..m} Int {m<..u} = {}"
 | |
| 14398 
c5c47703f763
Efficient, graph-based reasoner for linear and partial orders.
 ballarin parents: 
13850diff
changeset | 1620 | by auto | 
| 13735 | 1621 | |
| 32456 
341c83339aeb
tuned the simp rules for Int involving insert and intervals.
 nipkow parents: 
32436diff
changeset | 1622 | lemmas ivl_disj_int = ivl_disj_int_one ivl_disj_int_two | 
| 13735 | 1623 | |
| 60758 | 1624 | subsubsection \<open>Some Differences\<close> | 
| 15542 | 1625 | |
| 1626 | lemma ivl_diff[simp]: | |
| 1627 |  "i \<le> n \<Longrightarrow> {i..<m} - {i..<n} = {n..<(m::'a::linorder)}"
 | |
| 1628 | by(auto) | |
| 1629 | ||
| 56194 | 1630 | lemma (in linorder) lessThan_minus_lessThan [simp]: | 
| 1631 |   "{..< n} - {..< m} = {m ..< n}"
 | |
| 1632 | by auto | |
| 1633 | ||
| 60762 | 1634 | lemma (in linorder) atLeastAtMost_diff_ends: | 
| 1635 |   "{a..b} - {a, b} = {a<..<b}"
 | |
| 1636 | by auto | |
| 1637 | ||
| 15542 | 1638 | |
| 60758 | 1639 | subsubsection \<open>Some Subset Conditions\<close> | 
| 15542 | 1640 | |
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1641 | lemma ivl_subset [simp]: "({i..<j} \<subseteq> {m..<n}) = (j \<le> i \<or> m \<le> i \<and> j \<le> (n::'a::linorder))"
 | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1642 | using linorder_class.le_less_linear[of i n] | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1643 | apply (auto simp: linorder_not_le) | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1644 | apply (force intro: leI)+ | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1645 | done | 
| 15542 | 1646 | |
| 71258 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1647 | lemma get_smaller_card: | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1648 | assumes "finite A" "k \<le> card A" | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1649 | obtains B where "B \<subseteq> A" "card B = k" | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1650 | proof - | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1651 |   obtain h where h: "bij_betw h {0..<card A} A"
 | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1652 | using \<open>finite A\<close> ex_bij_betw_nat_finite by blast | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1653 | show thesis | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1654 | proof | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1655 |     show "h ` {0..<k} \<subseteq> A"
 | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1656 | by (metis \<open>k \<le> card A\<close> bij_betw_def h image_mono ivl_subset zero_le) | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1657 |     have "inj_on h {0..<k}"
 | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1658 | by (meson \<open>k \<le> card A\<close> bij_betw_def h inj_on_subset ivl_subset zero_le) | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1659 |     then show "card (h ` {0..<k}) = k"
 | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1660 | by (simp add: card_image) | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1661 | qed | 
| 
d67924987c34
a few new and tidier proofs (mostly about finite sets)
 paulson <lp15@cam.ac.uk> parents: 
71167diff
changeset | 1662 | qed | 
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14846diff
changeset | 1663 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1664 | subsection \<open>Generic big monoid operation over intervals\<close> | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1665 | |
| 66936 | 1666 | context semiring_char_0 | 
| 1667 | begin | |
| 1668 | ||
| 1669 | lemma inj_on_of_nat [simp]: | |
| 1670 | "inj_on of_nat N" | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1671 | by rule simp | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1672 | |
| 66936 | 1673 | lemma bij_betw_of_nat [simp]: | 
| 1674 | "bij_betw of_nat N A \<longleftrightarrow> of_nat ` N = A" | |
| 1675 | by (simp add: bij_betw_def) | |
| 1676 | ||
| 1677 | end | |
| 1678 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1679 | context comm_monoid_set | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1680 | begin | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1681 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1682 | lemma atLeastLessThan_reindex: | 
| 66936 | 1683 |   "F g {h m..<h n} = F (g \<circ> h) {m..<n}"
 | 
| 1684 |   if "bij_betw h {m..<n} {h m..<h n}" for m n ::nat
 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1685 | proof - | 
| 66936 | 1686 |   from that have "inj_on h {m..<n}" and "h ` {m..<n} = {h m..<h n}"
 | 
| 1687 | by (simp_all add: bij_betw_def) | |
| 1688 | then show ?thesis | |
| 1689 |     using reindex [of h "{m..<n}" g] by simp
 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1690 | qed | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1691 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1692 | lemma atLeastAtMost_reindex: | 
| 66936 | 1693 |   "F g {h m..h n} = F (g \<circ> h) {m..n}"
 | 
| 1694 |   if "bij_betw h {m..n} {h m..h n}" for m n ::nat
 | |
| 1695 | proof - | |
| 1696 |   from that have "inj_on h {m..n}" and "h ` {m..n} = {h m..h n}"
 | |
| 1697 | by (simp_all add: bij_betw_def) | |
| 1698 | then show ?thesis | |
| 1699 |     using reindex [of h "{m..n}" g] by simp
 | |
| 1700 | qed | |
| 1701 | ||
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1702 | lemma atLeastLessThan_shift_bounds: | 
| 66936 | 1703 |   "F g {m + k..<n + k} = F (g \<circ> plus k) {m..<n}"
 | 
| 1704 | for m n k :: nat | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1705 | using atLeastLessThan_reindex [of "plus k" m n g] | 
| 66936 | 1706 | by (simp add: ac_simps) | 
| 1707 | ||
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1708 | lemma atLeastAtMost_shift_bounds: | 
| 66936 | 1709 |   "F g {m + k..n + k} = F (g \<circ> plus k) {m..n}"
 | 
| 1710 | for m n k :: nat | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1711 | using atLeastAtMost_reindex [of "plus k" m n g] | 
| 66936 | 1712 | by (simp add: ac_simps) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1713 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1714 | lemma atLeast_Suc_lessThan_Suc_shift: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1715 |   "F g {Suc m..<Suc n} = F (g \<circ> Suc) {m..<n}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1716 | using atLeastLessThan_shift_bounds [of _ _ 1] | 
| 66936 | 1717 | by (simp add: plus_1_eq_Suc) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1718 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1719 | lemma atLeast_Suc_atMost_Suc_shift: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1720 |   "F g {Suc m..Suc n} = F (g \<circ> Suc) {m..n}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1721 | using atLeastAtMost_shift_bounds [of _ _ 1] | 
| 66936 | 1722 | by (simp add: plus_1_eq_Suc) | 
| 1723 | ||
| 1724 | lemma atLeast_int_lessThan_int_shift: | |
| 1725 |   "F g {int m..<int n} = F (g \<circ> int) {m..<n}"
 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1726 | by (rule atLeastLessThan_reindex) | 
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1727 | (simp add: image_int_atLeastLessThan) | 
| 66936 | 1728 | |
| 1729 | lemma atLeast_int_atMost_int_shift: | |
| 1730 |   "F g {int m..int n} = F (g \<circ> int) {m..n}"
 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1731 | by (rule atLeastAtMost_reindex) | 
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1732 | (simp add: image_int_atLeastAtMost) | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1733 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1734 | lemma atLeast0_lessThan_Suc: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1735 |   "F g {0..<Suc n} = F g {0..<n} \<^bold>* g n"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1736 | by (simp add: atLeast0_lessThan_Suc ac_simps) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1737 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1738 | lemma atLeast0_atMost_Suc: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1739 |   "F g {0..Suc n} = F g {0..n} \<^bold>* g (Suc n)"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1740 | by (simp add: atLeast0_atMost_Suc ac_simps) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1741 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1742 | lemma atLeast0_lessThan_Suc_shift: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1743 |   "F g {0..<Suc n} = g 0 \<^bold>* F (g \<circ> Suc) {0..<n}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1744 | by (simp add: atLeast0_lessThan_Suc_eq_insert_0 atLeast_Suc_lessThan_Suc_shift) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1745 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1746 | lemma atLeast0_atMost_Suc_shift: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1747 |   "F g {0..Suc n} = g 0 \<^bold>* F (g \<circ> Suc) {0..n}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1748 | by (simp add: atLeast0_atMost_Suc_eq_insert_0 atLeast_Suc_atMost_Suc_shift) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1749 | |
| 67987 | 1750 | lemma atLeast_Suc_lessThan: | 
| 1751 |   "F g {m..<n} = g m \<^bold>* F g {Suc m..<n}" if "m < n"
 | |
| 1752 | proof - | |
| 1753 |   from that have "{m..<n} = insert m {Suc m..<n}"
 | |
| 1754 | by auto | |
| 1755 | then show ?thesis by simp | |
| 1756 | qed | |
| 1757 | ||
| 1758 | lemma atLeast_Suc_atMost: | |
| 1759 |   "F g {m..n} = g m \<^bold>* F g {Suc m..n}" if "m \<le> n"
 | |
| 1760 | proof - | |
| 1761 |   from that have "{m..n} = insert m {Suc m..n}"
 | |
| 1762 | by auto | |
| 1763 | then show ?thesis by simp | |
| 1764 | qed | |
| 1765 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1766 | lemma ivl_cong: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1767 | "a = c \<Longrightarrow> b = d \<Longrightarrow> (\<And>x. c \<le> x \<Longrightarrow> x < d \<Longrightarrow> g x = h x) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1768 |     \<Longrightarrow> F g {a..<b} = F h {c..<d}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1769 | by (rule cong) simp_all | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1770 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1771 | lemma atLeastLessThan_shift_0: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1772 | fixes m n p :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1773 |   shows "F g {m..<n} = F (g \<circ> plus m) {0..<n - m}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1774 | using atLeastLessThan_shift_bounds [of g 0 m "n - m"] | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1775 | by (cases "m \<le> n") simp_all | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1776 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1777 | lemma atLeastAtMost_shift_0: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1778 | fixes m n p :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1779 | assumes "m \<le> n" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1780 |   shows "F g {m..n} = F (g \<circ> plus m) {0..n - m}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1781 | using assms atLeastAtMost_shift_bounds [of g 0 m "n - m"] by simp | 
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1782 | |
| 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1783 | lemma atLeastLessThan_concat: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1784 | fixes m n p :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1785 |   shows "m \<le> n \<Longrightarrow> n \<le> p \<Longrightarrow> F g {m..<n} \<^bold>* F g {n..<p} = F g {m..<p}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1786 | by (simp add: union_disjoint [symmetric] ivl_disj_un) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1787 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1788 | lemma atLeastLessThan_rev: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1789 |   "F g {n..<m} = F (\<lambda>i. g (m + n - Suc i)) {n..<m}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1790 | by (rule reindex_bij_witness [where i="\<lambda>i. m + n - Suc i" and j="\<lambda>i. m + n - Suc i"], auto) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1791 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1792 | lemma atLeastAtMost_rev: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1793 | fixes n m :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1794 |   shows "F g {n..m} = F (\<lambda>i. g (m + n - i)) {n..m}"
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1795 | by (rule reindex_bij_witness [where i="\<lambda>i. m + n - i" and j="\<lambda>i. m + n - i"]) auto | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1796 | |
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1797 | lemma atLeastLessThan_rev_at_least_Suc_atMost: | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1798 |   "F g {n..<m} = F (\<lambda>i. g (m + n - i)) {Suc n..m}"
 | 
| 67411 
3f4b0c84630f
restored naming of lemmas after corresponding constants
 haftmann parents: 
67399diff
changeset | 1799 | unfolding atLeastLessThan_rev [of g n m] | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1800 | by (cases m) (simp_all add: atLeast_Suc_atMost_Suc_shift atLeastLessThanSuc_atLeastAtMost) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1801 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1802 | end | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1803 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1804 | |
| 60758 | 1805 | subsection \<open>Summation indexed over intervals\<close> | 
| 15042 | 1806 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 1807 | syntax (ASCII) | 
| 64267 | 1808 |   "_from_to_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(SUM _ = _.._./ _)" [0,0,0,10] 10)
 | 
| 1809 |   "_from_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(SUM _ = _..<_./ _)" [0,0,0,10] 10)
 | |
| 1810 |   "_upt_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(SUM _<_./ _)" [0,0,10] 10)
 | |
| 1811 |   "_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(SUM _<=_./ _)" [0,0,10] 10)
 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 1812 | |
| 15056 | 1813 | syntax (latex_sum output) | 
| 64267 | 1814 | "_from_to_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 1815 |  ("(3\<^latex>\<open>$\\sum_{\<close>_ = _\<^latex>\<open>}^{\<close>_\<^latex>\<open>}$\<close> _)" [0,0,0,10] 10)
 | 
| 64267 | 1816 | "_from_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 1817 |  ("(3\<^latex>\<open>$\\sum_{\<close>_ = _\<^latex>\<open>}^{<\<close>_\<^latex>\<open>}$\<close> _)" [0,0,0,10] 10)
 | 
| 64267 | 1818 | "_upt_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 1819 |  ("(3\<^latex>\<open>$\\sum_{\<close>_ < _\<^latex>\<open>}$\<close> _)" [0,0,10] 10)
 | 
| 64267 | 1820 | "_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 1821 |  ("(3\<^latex>\<open>$\\sum_{\<close>_ \<le> _\<^latex>\<open>}$\<close> _)" [0,0,10] 10)
 | 
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14846diff
changeset | 1822 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 1823 | syntax | 
| 64267 | 1824 |   "_from_to_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sum>_ = _.._./ _)" [0,0,0,10] 10)
 | 
| 1825 |   "_from_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sum>_ = _..<_./ _)" [0,0,0,10] 10)
 | |
| 1826 |   "_upt_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sum>_<_./ _)" [0,0,10] 10)
 | |
| 1827 |   "_upto_sum" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Sum>_\<le>_./ _)" [0,0,10] 10)
 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 1828 | |
| 15048 | 1829 | translations | 
| 64267 | 1830 |   "\<Sum>x=a..b. t" == "CONST sum (\<lambda>x. t) {a..b}"
 | 
| 1831 |   "\<Sum>x=a..<b. t" == "CONST sum (\<lambda>x. t) {a..<b}"
 | |
| 1832 |   "\<Sum>i\<le>n. t" == "CONST sum (\<lambda>i. t) {..n}"
 | |
| 1833 |   "\<Sum>i<n. t" == "CONST sum (\<lambda>i. t) {..<n}"
 | |
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14846diff
changeset | 1834 | |
| 60758 | 1835 | text\<open>The above introduces some pretty alternative syntaxes for | 
| 15056 | 1836 | summation over intervals: | 
| 15052 | 1837 | \begin{center}
 | 
| 1838 | \begin{tabular}{lll}
 | |
| 15056 | 1839 | Old & New & \LaTeX\\ | 
| 69593 | 1840 | @{term[source]"\<Sum>x\<in>{a..b}. e"} & \<^term>\<open>\<Sum>x=a..b. e\<close> & @{term[mode=latex_sum]"\<Sum>x=a..b. e"}\\
 | 
| 1841 | @{term[source]"\<Sum>x\<in>{a..<b}. e"} & \<^term>\<open>\<Sum>x=a..<b. e\<close> & @{term[mode=latex_sum]"\<Sum>x=a..<b. e"}\\
 | |
| 1842 | @{term[source]"\<Sum>x\<in>{..b}. e"} & \<^term>\<open>\<Sum>x\<le>b. e\<close> & @{term[mode=latex_sum]"\<Sum>x\<le>b. e"}\\
 | |
| 1843 | @{term[source]"\<Sum>x\<in>{..<b}. e"} & \<^term>\<open>\<Sum>x<b. e\<close> & @{term[mode=latex_sum]"\<Sum>x<b. e"}
 | |
| 15052 | 1844 | \end{tabular}
 | 
| 1845 | \end{center}
 | |
| 15056 | 1846 | The left column shows the term before introduction of the new syntax, | 
| 1847 | the middle column shows the new (default) syntax, and the right column | |
| 1848 | shows a special syntax. The latter is only meaningful for latex output | |
| 1849 | and has to be activated explicitly by setting the print mode to | |
| 61799 | 1850 | \<open>latex_sum\<close> (e.g.\ via \<open>mode = latex_sum\<close> in | 
| 15056 | 1851 | antiquotations). It is not the default \LaTeX\ output because it only | 
| 1852 | works well with italic-style formulae, not tt-style. | |
| 15052 | 1853 | |
| 69593 | 1854 | Note that for uniformity on \<^typ>\<open>nat\<close> it is better to use | 
| 1855 | \<^term>\<open>\<Sum>x::nat=0..<n. e\<close> rather than \<open>\<Sum>x<n. e\<close>: \<open>sum\<close> may | |
| 1856 | not provide all lemmas available for \<^term>\<open>{m..<n}\<close> also in the
 | |
| 1857 | special form for \<^term>\<open>{..<n}\<close>.\<close>
 | |
| 15052 | 1858 | |
| 60758 | 1859 | text\<open>This congruence rule should be used for sums over intervals as | 
| 64267 | 1860 | the standard theorem @{text[source]sum.cong} does not work well
 | 
| 69593 | 1861 | with the simplifier who adds the unsimplified premise \<^term>\<open>x\<in>B\<close> to | 
| 60758 | 1862 | the context.\<close> | 
| 15542 | 1863 | |
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1864 | context comm_monoid_set | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1865 | begin | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1866 | |
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1867 | lemma zero_middle: | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1868 | assumes "1 \<le> p" "k \<le> p" | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1869 |   shows "F (\<lambda>j. if j < k then g j else if j = k then \<^bold>1 else h (j - Suc 0)) {..p}
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1870 |        = F (\<lambda>j. if j < k then g j else h j) {..p - Suc 0}"  (is "?lhs = ?rhs")
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1871 | proof - | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1872 |   have [simp]: "{..p - Suc 0} \<inter> {j. j < k} = {..<k}" "{..p - Suc 0} \<inter> - {j. j < k} = {k..p - Suc 0}"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1873 | using assms by auto | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1874 |   have "?lhs = F g {..<k} \<^bold>* F (\<lambda>j. if j = k then \<^bold>1 else h (j - Suc 0)) {k..p}"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1875 |     using union_disjoint [of "{..<k}" "{k..p}"] assms
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1876 | by (simp add: ivl_disj_int_one ivl_disj_un_one) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1877 |   also have "\<dots> = F g {..<k} \<^bold>* F (\<lambda>j.  h (j - Suc 0)) {Suc k..p}"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1878 | by (simp add: atLeast_Suc_atMost [of k p] assms) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1879 |   also have "\<dots> = F g {..<k} \<^bold>* F h {k .. p - Suc 0}"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1880 |     using reindex [of Suc "{k..p - Suc 0}"] assms by simp
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1881 | also have "\<dots> = ?rhs" | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1882 | by (simp add: If_cases) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1883 | finally show ?thesis . | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1884 | qed | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1885 | |
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1886 | lemma atMost_Suc [simp]: | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1887 |   "F g {..Suc n} = F g {..n} \<^bold>* g (Suc n)"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1888 | by (simp add: atMost_Suc ac_simps) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1889 | |
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1890 | lemma lessThan_Suc [simp]: | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1891 |   "F g {..<Suc n} = F g {..<n} \<^bold>* g n"
 | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1892 | by (simp add: lessThan_Suc ac_simps) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 1893 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1894 | lemma cl_ivl_Suc [simp]: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1895 |   "F g {m..Suc n} = (if Suc n < m then \<^bold>1 else F g {m..n} \<^bold>* g(Suc n))"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1896 | by (auto simp: ac_simps atLeastAtMostSuc_conv) | 
| 15561 | 1897 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1898 | lemma op_ivl_Suc [simp]: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1899 |   "F g {m..<Suc n} = (if n < m then \<^bold>1 else F g {m..<n} \<^bold>* g(n))"
 | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 1900 | by (auto simp: ac_simps atLeastLessThanSuc) | 
| 28068 | 1901 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1902 | lemma head: | 
| 28068 | 1903 | fixes n :: nat | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1904 | assumes mn: "m \<le> n" | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1905 |   shows "F g {m..n} = g m \<^bold>* F g {m<..n}" (is "?lhs = ?rhs")
 | 
| 28068 | 1906 | proof - | 
| 1907 | from mn | |
| 1908 |   have "{m..n} = {m} \<union> {m<..n}"
 | |
| 1909 | by (auto intro: ivl_disj_un_singleton) | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1910 |   hence "?lhs = F g ({m} \<union> {m<..n})"
 | 
| 28068 | 1911 | by (simp add: atLeast0LessThan) | 
| 1912 | also have "\<dots> = ?rhs" by simp | |
| 1913 | finally show ?thesis . | |
| 1914 | qed | |
| 1915 | ||
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1916 | lemma ub_add_nat: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1917 | assumes "(m::nat) \<le> n + 1" | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1918 |   shows "F g {m..n + p} = F g {m..n} \<^bold>* F g {n + 1..n + p}"
 | 
| 31501 | 1919 | proof- | 
| 60758 | 1920 |   have "{m .. n+p} = {m..n} \<union> {n+1..n+p}" using \<open>m \<le> n+1\<close> by auto
 | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1921 | thus ?thesis by (auto simp: ivl_disj_int union_disjoint atLeastSucAtMost_greaterThanAtMost) | 
| 31501 | 1922 | qed | 
| 28068 | 1923 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1924 | lemma nat_group: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1925 |   fixes k::nat shows "F (\<lambda>m. F g {m * k ..< m*k + k}) {..<n} = F g {..< n * k}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1926 | proof (cases k) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1927 | case (Suc l) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1928 | then have "k > 0" | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1929 | by auto | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1930 | then show ?thesis | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1931 | by (induct n) (simp_all add: atLeastLessThan_concat add.commute atLeast0LessThan[symmetric]) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1932 | qed auto | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1933 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1934 | lemma triangle_reindex: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1935 | fixes n :: nat | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1936 |   shows "F (\<lambda>(i,j). g i j) {(i,j). i+j < n} = F (\<lambda>k. F (\<lambda>i. g i (k - i)) {..k}) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1937 | apply (simp add: Sigma) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1938 | apply (rule reindex_bij_witness[where j="\<lambda>(i, j). (i+j, i)" and i="\<lambda>(k, i). (i, k - i)"]) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1939 | apply auto | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1940 | done | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1941 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1942 | lemma triangle_reindex_eq: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1943 | fixes n :: nat | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1944 |   shows "F (\<lambda>(i,j). g i j) {(i,j). i+j \<le> n} = F (\<lambda>k. F (\<lambda>i. g i (k - i)) {..k}) {..n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1945 | using triangle_reindex [of g "Suc n"] | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1946 | by (simp only: Nat.less_Suc_eq_le lessThan_Suc_atMost) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1947 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1948 | lemma nat_diff_reindex: "F (\<lambda>i. g (n - Suc i)) {..<n} = F g {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1949 | by (rule reindex_bij_witness[where i="\<lambda>i. n - Suc i" and j="\<lambda>i. n - Suc i"]) auto | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1950 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1951 | lemma shift_bounds_nat_ivl: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1952 |   "F g {m+k..<n+k} = F (\<lambda>i. g(i + k)){m..<n::nat}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1953 | by (induct "n", auto simp: atLeastLessThanSuc) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1954 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1955 | lemma shift_bounds_cl_nat_ivl: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1956 |   "F g {m+k..n+k} = F (\<lambda>i. g(i + k)){m..n::nat}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1957 | by (rule reindex_bij_witness[where i="\<lambda>i. i + k" and j="\<lambda>i. i - k"]) auto | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1958 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1959 | corollary shift_bounds_cl_Suc_ivl: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1960 |   "F g {Suc m..Suc n} = F (\<lambda>i. g(Suc i)){m..n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1961 | by (simp add: shift_bounds_cl_nat_ivl[where k="Suc 0", simplified]) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1962 | |
| 71167 
b4d409c65a76
Rearrangement of material in Complex_Analysis_Basics, which contained much that had nothing to do with complex analysis.
 paulson <lp15@cam.ac.uk> parents: 
71094diff
changeset | 1963 | corollary Suc_reindex_ivl: "m \<le> n \<Longrightarrow> F g {m..n} \<^bold>* g (Suc n) = g m \<^bold>* F (\<lambda>i. g (Suc i)) {m..n}"
 | 
| 
b4d409c65a76
Rearrangement of material in Complex_Analysis_Basics, which contained much that had nothing to do with complex analysis.
 paulson <lp15@cam.ac.uk> parents: 
71094diff
changeset | 1964 | by (simp add: assoc atLeast_Suc_atMost flip: shift_bounds_cl_Suc_ivl) | 
| 
b4d409c65a76
Rearrangement of material in Complex_Analysis_Basics, which contained much that had nothing to do with complex analysis.
 paulson <lp15@cam.ac.uk> parents: 
71094diff
changeset | 1965 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1966 | corollary shift_bounds_Suc_ivl: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1967 |   "F g {Suc m..<Suc n} = F (\<lambda>i. g(Suc i)){m..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1968 | by (simp add: shift_bounds_nat_ivl[where k="Suc 0", simplified]) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1969 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1970 | lemma atMost_Suc_shift: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1971 |   shows "F g {..Suc n} = g 0 \<^bold>* F (\<lambda>i. g (Suc i)) {..n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1972 | proof (induct n) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1973 | case 0 show ?case by simp | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1974 | next | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1975 | case (Suc n) note IH = this | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1976 |   have "F g {..Suc (Suc n)} = F g {..Suc n} \<^bold>* g (Suc (Suc n))"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1977 | by (rule atMost_Suc) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1978 |   also have "F g {..Suc n}  = g 0 \<^bold>* F (\<lambda>i. g (Suc i)) {..n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1979 | by (rule IH) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1980 |   also have "g 0 \<^bold>* F (\<lambda>i. g (Suc i)) {..n} \<^bold>* g (Suc (Suc n)) =
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1981 |              g 0 \<^bold>* (F (\<lambda>i. g (Suc i)) {..n} \<^bold>* g (Suc (Suc n)))"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1982 | by (rule assoc) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1983 |   also have "F (\<lambda>i. g (Suc i)) {..n} \<^bold>* g (Suc (Suc n)) = F (\<lambda>i. g (Suc i)) {..Suc n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1984 | by (rule atMost_Suc [symmetric]) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1985 | finally show ?case . | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1986 | qed | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1987 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1988 | lemma lessThan_Suc_shift: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1989 |   "F g {..<Suc n} = g 0 \<^bold>* F (\<lambda>i. g (Suc i)) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1990 | by (induction n) (simp_all add: ac_simps) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1991 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1992 | lemma atMost_shift: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1993 |   "F g {..n} = g 0 \<^bold>* F (\<lambda>i. g (Suc i)) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1994 | by (metis atLeast0AtMost atLeast0LessThan atLeastLessThanSuc_atLeastAtMost | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1995 | atLeastSucAtMost_greaterThanAtMost le0 head shift_bounds_Suc_ivl) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1996 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1997 | lemma last_plus: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1998 |   fixes n::nat  shows "m \<le> n \<Longrightarrow> F g {m..n} = g n \<^bold>* F g {m..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 1999 | by (cases n) (auto simp: atLeastLessThanSuc_atLeastAtMost commute) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2000 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2001 | lemma nested_swap: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2002 |      "F (\<lambda>i. F (\<lambda>j. a i j) {0..<i}) {0..n} = F (\<lambda>j. F (\<lambda>i. a i j) {Suc j..n}) {0..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2003 | by (induction n) (auto simp: distrib) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2004 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2005 | lemma nested_swap': | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2006 |      "F (\<lambda>i. F (\<lambda>j. a i j) {..<i}) {..n} = F (\<lambda>j. F (\<lambda>i. a i j) {Suc j..n}) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2007 | by (induction n) (auto simp: distrib) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2008 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2009 | lemma atLeast1_atMost_eq: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2010 |   "F g {Suc 0..n} = F (\<lambda>k. g (Suc k)) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2011 | proof - | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2012 |   have "F g {Suc 0..n} = F g (Suc ` {..<n})"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2013 | by (simp add: image_Suc_lessThan) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2014 |   also have "\<dots> = F (\<lambda>k. g (Suc k)) {..<n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2015 | by (simp add: reindex) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2016 | finally show ?thesis . | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2017 | qed | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2018 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2019 | lemma atLeastLessThan_Suc: "a \<le> b \<Longrightarrow> F g {a..<Suc b} = F g {a..<b} \<^bold>* g b"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2020 | by (simp add: atLeastLessThanSuc commute) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2021 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2022 | lemma nat_ivl_Suc': | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2023 | assumes "m \<le> Suc n" | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2024 |   shows   "F g {m..Suc n} = g (Suc n) \<^bold>* F g {m..n}"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2025 | proof - | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2026 |   from assms have "{m..Suc n} = insert (Suc n) {m..n}" by auto
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2027 |   also have "F g \<dots> = g (Suc n) \<^bold>* F g {m..n}" by simp
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2028 | finally show ?thesis . | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2029 | qed | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2030 | |
| 70365 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2031 | lemma in_pairs: "F g {2*m..Suc(2*n)} = F (\<lambda>i. g(2*i) \<^bold>* g(Suc(2*i))) {m..n}"
 | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2032 | proof (induction n) | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2033 | case 0 | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2034 | show ?case | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2035 | by (cases "m=0") auto | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2036 | next | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2037 | case (Suc n) | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2038 | then show ?case | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2039 | by (auto simp: assoc split: if_split_asm) | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2040 | qed | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2041 | |
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2042 | lemma in_pairs_0: "F g {..Suc(2*n)} = F (\<lambda>i. g(2*i) \<^bold>* g(Suc(2*i))) {..n}"
 | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2043 | using in_pairs [of _ 0 n] by (simp add: atLeast0AtMost) | 
| 
4df0628e8545
a few new lemmas and a bit of tidying
 paulson <lp15@cam.ac.uk> parents: 
70340diff
changeset | 2044 | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2045 | end | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2046 | |
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2047 | lemma sum_natinterval_diff: | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2048 |   fixes f:: "nat \<Rightarrow> ('a::ab_group_add)"
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2049 |   shows  "sum (\<lambda>k. f k - f(k + 1)) {(m::nat) .. n} =
 | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2050 | (if m \<le> n then f m - f(n + 1) else 0)" | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2051 | by (induct n, auto simp add: algebra_simps not_le le_Suc_eq) | 
| 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2052 | |
| 64267 | 2053 | lemma sum_diff_nat_ivl: | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 2054 | fixes f :: "nat \<Rightarrow> 'a::ab_group_add" | 
| 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 2055 |   shows "\<lbrakk> m \<le> n; n \<le> p \<rbrakk> \<Longrightarrow> sum f {m..<p} - sum f {m..<n} = sum f {n..<p}"
 | 
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
69768diff
changeset | 2056 | using sum.atLeastLessThan_concat [of m n p f,symmetric] | 
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 2057 | by (simp add: ac_simps) | 
| 15539 | 2058 | |
| 66936 | 2059 | lemma sum_diff_distrib: "\<forall>x. Q x \<le> P x \<Longrightarrow> (\<Sum>x<n. P x) - (\<Sum>x<n. Q x) = (\<Sum>x<n. P x - Q x :: nat)" | 
| 2060 | by (subst sum_subtractf_nat) auto | |
| 2061 | ||
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2062 | |
| 71094 | 2063 | context unique_euclidean_semiring_with_bit_shifts | 
| 67987 | 2064 | begin | 
| 2065 | ||
| 2066 | lemma take_bit_sum: | |
| 2067 | "take_bit n a = (\<Sum>k = 0..<n. push_bit k (of_bool (odd (drop_bit k a))))" | |
| 2068 | for n :: nat | |
| 2069 | proof (induction n arbitrary: a) | |
| 67816 | 2070 | case 0 | 
| 2071 | then show ?case | |
| 2072 | by simp | |
| 2073 | next | |
| 2074 | case (Suc n) | |
| 67987 | 2075 | have "(\<Sum>k = 0..<Suc n. push_bit k (of_bool (odd (drop_bit k a)))) = | 
| 2076 | of_bool (odd a) + (\<Sum>k = Suc 0..<Suc n. push_bit k (of_bool (odd (drop_bit k a))))" | |
| 2077 | by (simp add: sum.atLeast_Suc_lessThan ac_simps) | |
| 2078 | also have "(\<Sum>k = Suc 0..<Suc n. push_bit k (of_bool (odd (drop_bit k a)))) | |
| 2079 | = (\<Sum>k = 0..<n. push_bit k (of_bool (odd (drop_bit k (a div 2))))) * 2" | |
| 67907 
02a14c1cb917
prefer convention to place operation name before type name
 haftmann parents: 
67816diff
changeset | 2080 | by (simp only: sum.atLeast_Suc_lessThan_Suc_shift) (simp add: sum_distrib_right push_bit_double) | 
| 67816 | 2081 | finally show ?case | 
| 67987 | 2082 | using Suc [of "a div 2"] by (simp add: ac_simps) | 
| 2083 | qed | |
| 2084 | ||
| 2085 | end | |
| 2086 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2087 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2088 | subsubsection \<open>Shifting bounds\<close> | 
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16102diff
changeset | 2089 | |
| 66936 | 2090 | context comm_monoid_add | 
| 2091 | begin | |
| 2092 | ||
| 2093 | context | |
| 2094 | fixes f :: "nat \<Rightarrow> 'a" | |
| 2095 | assumes "f 0 = 0" | |
| 2096 | begin | |
| 64267 | 2097 | |
| 2098 | lemma sum_shift_lb_Suc0_0_upt: | |
| 66936 | 2099 |   "sum f {Suc 0..<k} = sum f {0..<k}"
 | 
| 2100 | proof (cases k) | |
| 2101 | case 0 | |
| 2102 | then show ?thesis | |
| 2103 | by simp | |
| 2104 | next | |
| 2105 | case (Suc k) | |
| 2106 |   moreover have "{0..<Suc k} = insert 0 {Suc 0..<Suc k}"
 | |
| 2107 | by auto | |
| 2108 | ultimately show ?thesis | |
| 2109 | using \<open>f 0 = 0\<close> by simp | |
| 2110 | qed | |
| 2111 | ||
| 68618 
3db8520941a4
de-applying (mostly Set_Interval)
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 2112 | lemma sum_shift_lb_Suc0_0: "sum f {Suc 0..k} = sum f {0..k}"
 | 
| 66936 | 2113 | proof (cases k) | 
| 2114 | case 0 | |
| 2115 | with \<open>f 0 = 0\<close> show ?thesis | |
| 2116 | by simp | |
| 2117 | next | |
| 2118 | case (Suc k) | |
| 2119 |   moreover have "{0..Suc k} = insert 0 {Suc 0..Suc k}"
 | |
| 2120 | by auto | |
| 2121 | ultimately show ?thesis | |
| 2122 | using \<open>f 0 = 0\<close> by simp | |
| 2123 | qed | |
| 2124 | ||
| 2125 | end | |
| 2126 | ||
| 2127 | end | |
| 19022 
0e6ec4fd204c
* moved ThreeDivides from Isar_examples to better suited HOL/ex
 kleing parents: 
17719diff
changeset | 2128 | |
| 64267 | 2129 | lemma sum_Suc_diff: | 
| 56238 
5d147e1e18d1
a few new lemmas and generalisations of old ones
 paulson <lp15@cam.ac.uk> parents: 
56215diff
changeset | 2130 | fixes f :: "nat \<Rightarrow> 'a::ab_group_add" | 
| 
5d147e1e18d1
a few new lemmas and generalisations of old ones
 paulson <lp15@cam.ac.uk> parents: 
56215diff
changeset | 2131 | assumes "m \<le> Suc n" | 
| 
5d147e1e18d1
a few new lemmas and generalisations of old ones
 paulson <lp15@cam.ac.uk> parents: 
56215diff
changeset | 2132 | shows "(\<Sum>i = m..n. f(Suc i) - f i) = f (Suc n) - f m" | 
| 
5d147e1e18d1
a few new lemmas and generalisations of old ones
 paulson <lp15@cam.ac.uk> parents: 
56215diff
changeset | 2133 | using assms by (induct n) (auto simp: le_Suc_eq) | 
| 55718 
34618f031ba9
A few lemmas about summations, etc.
 paulson <lp15@cam.ac.uk> parents: 
55242diff
changeset | 2134 | |
| 65273 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2135 | lemma sum_Suc_diff': | 
| 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2136 | fixes f :: "nat \<Rightarrow> 'a::ab_group_add" | 
| 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2137 | assumes "m \<le> n" | 
| 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2138 | shows "(\<Sum>i = m..<n. f (Suc i) - f i) = f n - f m" | 
| 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2139 | using assms by (induct n) (auto simp: le_Suc_eq) | 
| 
917ae0ba03a2
Removal of [simp] status for greaterThan_0. Moved two theorems into main HOL.
 paulson <lp15@cam.ac.uk> parents: 
64773diff
changeset | 2140 | |
| 52380 | 2141 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2142 | subsubsection \<open>Telescoping\<close> | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2143 | |
| 64267 | 2144 | lemma sum_telescope: | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2145 | fixes f::"nat \<Rightarrow> 'a::ab_group_add" | 
| 64267 | 2146 |   shows "sum (\<lambda>i. f i - f (Suc i)) {.. i} = f 0 - f (Suc i)"
 | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2147 | by (induct i) simp_all | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2148 | |
| 64267 | 2149 | lemma sum_telescope'': | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2150 | assumes "m \<le> n" | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2151 |   shows   "(\<Sum>k\<in>{Suc m..n}. f k - f (k - 1)) = f n - (f m :: 'a :: ab_group_add)"
 | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2152 | by (rule dec_induct[OF assms]) (simp_all add: algebra_simps) | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 2153 | |
| 64267 | 2154 | lemma sum_lessThan_telescope: | 
| 63721 | 2155 | "(\<Sum>n<m. f (Suc n) - f n :: 'a :: ab_group_add) = f m - f 0" | 
| 2156 | by (induction m) (simp_all add: algebra_simps) | |
| 2157 | ||
| 64267 | 2158 | lemma sum_lessThan_telescope': | 
| 63721 | 2159 | "(\<Sum>n<m. f n - f (Suc n) :: 'a :: ab_group_add) = f 0 - f m" | 
| 2160 | by (induction m) (simp_all add: algebra_simps) | |
| 2161 | ||
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2162 | |
| 66936 | 2163 | subsubsection \<open>The formula for geometric sums\<close> | 
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
16733diff
changeset | 2164 | |
| 66490 | 2165 | lemma sum_power2: "(\<Sum>i=0..<k. (2::nat)^i) = 2^k-1" | 
| 2166 | by (induction k) (auto simp: mult_2) | |
| 2167 | ||
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
16733diff
changeset | 2168 | lemma geometric_sum: | 
| 36307 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2169 | assumes "x \<noteq> 1" | 
| 56193 
c726ecfb22b6
cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
 hoelzl parents: 
55719diff
changeset | 2170 | shows "(\<Sum>i<n. x ^ i) = (x ^ n - 1) / (x - 1::'a::field)" | 
| 36307 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2171 | proof - | 
| 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2172 | from assms obtain y where "y = x - 1" and "y \<noteq> 0" by simp_all | 
| 56193 
c726ecfb22b6
cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
 hoelzl parents: 
55719diff
changeset | 2173 | moreover have "(\<Sum>i<n. (y + 1) ^ i) = ((y + 1) ^ n - 1) / y" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2174 | by (induct n) (simp_all add: field_simps \<open>y \<noteq> 0\<close>) | 
| 36307 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2175 | ultimately show ?thesis by simp | 
| 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2176 | qed | 
| 
1732232f9b27
sharpened constraint (c.f. 4e7f5b22dd7d); explicit is better than implicit
 haftmann parents: 
35828diff
changeset | 2177 | |
| 64267 | 2178 | lemma diff_power_eq_sum: | 
| 60162 | 2179 |   fixes y :: "'a::{comm_ring,monoid_mult}"
 | 
| 2180 | shows | |
| 2181 | "x ^ (Suc n) - y ^ (Suc n) = | |
| 2182 | (x - y) * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))" | |
| 2183 | proof (induct n) | |
| 2184 | case (Suc n) | |
| 2185 | have "x ^ Suc (Suc n) - y ^ Suc (Suc n) = x * (x * x^n) - y * (y * y ^ n)" | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2186 | by simp | 
| 60162 | 2187 | also have "... = y * (x ^ (Suc n) - y ^ (Suc n)) + (x - y) * (x * x^n)" | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2188 | by (simp add: algebra_simps) | 
| 60162 | 2189 | also have "... = y * ((x - y) * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x^n)" | 
| 2190 | by (simp only: Suc) | |
| 2191 | also have "... = (x - y) * (y * (\<Sum>p<Suc n. (x ^ p) * y ^ (n - p))) + (x - y) * (x * x^n)" | |
| 2192 | by (simp only: mult.left_commute) | |
| 2193 | also have "... = (x - y) * (\<Sum>p<Suc (Suc n). x ^ p * y ^ (Suc n - p))" | |
| 64267 | 2194 | by (simp add: field_simps Suc_diff_le sum_distrib_right sum_distrib_left) | 
| 60162 | 2195 | finally show ?case . | 
| 2196 | qed simp | |
| 2197 | ||
| 67443 
3abf6a722518
standardized towards new-style formal comments: isabelle update_comments;
 wenzelm parents: 
67411diff
changeset | 2198 | corollary power_diff_sumr2: \<comment> \<open>\<open>COMPLEX_POLYFUN\<close> in HOL Light\<close> | 
| 60162 | 2199 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | 
| 2200 | shows "x^n - y^n = (x - y) * (\<Sum>i<n. y^(n - Suc i) * x^i)" | |
| 64267 | 2201 | using diff_power_eq_sum[of x "n - 1" y] | 
| 60162 | 2202 | by (cases "n = 0") (simp_all add: field_simps) | 
| 2203 | ||
| 2204 | lemma power_diff_1_eq: | |
| 2205 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | |
| 2206 | shows "n \<noteq> 0 \<Longrightarrow> x^n - 1 = (x - 1) * (\<Sum>i<n. (x^i))" | |
| 64267 | 2207 | using diff_power_eq_sum [of x _ 1] | 
| 60162 | 2208 | by (cases n) auto | 
| 2209 | ||
| 2210 | lemma one_diff_power_eq': | |
| 2211 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | |
| 2212 | shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i<n. x^(n - Suc i))" | |
| 64267 | 2213 | using diff_power_eq_sum [of 1 _ x] | 
| 60162 | 2214 | by (cases n) auto | 
| 2215 | ||
| 2216 | lemma one_diff_power_eq: | |
| 2217 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | |
| 2218 | shows "n \<noteq> 0 \<Longrightarrow> 1 - x^n = (1 - x) * (\<Sum>i<n. x^i)" | |
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2219 | by (metis one_diff_power_eq' [of n x] sum.nat_diff_reindex) | 
| 60162 | 2220 | |
| 65578 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2221 | lemma sum_gp_basic: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2222 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2223 | shows "(1 - x) * (\<Sum>i\<le>n. x^i) = 1 - x^Suc n" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2224 | by (simp only: one_diff_power_eq [of "Suc n" x] lessThan_Suc_atMost) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2225 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2226 | lemma sum_power_shift: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2227 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2228 | assumes "m \<le> n" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2229 | shows "(\<Sum>i=m..n. x^i) = x^m * (\<Sum>i\<le>n-m. x^i)" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2230 | proof - | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2231 | have "(\<Sum>i=m..n. x^i) = x^m * (\<Sum>i=m..n. x^(i-m))" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2232 | by (simp add: sum_distrib_left power_add [symmetric]) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2233 | also have "(\<Sum>i=m..n. x^(i-m)) = (\<Sum>i\<le>n-m. x^i)" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2234 | using \<open>m \<le> n\<close> by (intro sum.reindex_bij_witness[where j="\<lambda>i. i - m" and i="\<lambda>i. i + m"]) auto | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2235 | finally show ?thesis . | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2236 | qed | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2237 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2238 | lemma sum_gp_multiplied: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2239 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2240 | assumes "m \<le> n" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2241 | shows "(1 - x) * (\<Sum>i=m..n. x^i) = x^m - x^Suc n" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2242 | proof - | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2243 | have "(1 - x) * (\<Sum>i=m..n. x^i) = x^m * (1 - x) * (\<Sum>i\<le>n-m. x^i)" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2244 | by (metis mult.assoc mult.commute assms sum_power_shift) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2245 | also have "... =x^m * (1 - x^Suc(n-m))" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2246 | by (metis mult.assoc sum_gp_basic) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2247 | also have "... = x^m - x^Suc n" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2248 | using assms | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2249 | by (simp add: algebra_simps) (metis le_add_diff_inverse power_add) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2250 | finally show ?thesis . | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2251 | qed | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2252 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2253 | lemma sum_gp: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2254 |   fixes x :: "'a::{comm_ring,division_ring}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2255 | shows "(\<Sum>i=m..n. x^i) = | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2256 | (if n < m then 0 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2257 | else if x = 1 then of_nat((n + 1) - m) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2258 | else (x^m - x^Suc n) / (1 - x))" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2259 | using sum_gp_multiplied [of m n x] apply auto | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2260 | by (metis eq_iff_diff_eq_0 mult.commute nonzero_divide_eq_eq) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2261 | |
| 66936 | 2262 | |
| 2263 | subsubsection\<open>Geometric progressions\<close> | |
| 65578 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2264 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2265 | lemma sum_gp0: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2266 |   fixes x :: "'a::{comm_ring,division_ring}"
 | 
| 70113 
c8deb8ba6d05
Fixing the main Homology theory; also moving a lot of sum/prod lemmas into their generic context
 paulson <lp15@cam.ac.uk> parents: 
70097diff
changeset | 2267 | shows "(\<Sum>i\<le>n. x^i) = (if x = 1 then of_nat(n + 1) else (1 - x^Suc n) / (1 - x))" | 
| 65578 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2268 | using sum_gp_basic[of x n] | 
| 70817 
dd675800469d
dedicated fact collections for algebraic simplification rules potentially splitting goals
 haftmann parents: 
70749diff
changeset | 2269 | by (simp add: mult.commute field_split_simps) | 
| 65578 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2270 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2271 | lemma sum_power_add: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2272 |   fixes x :: "'a::{comm_ring,monoid_mult}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2273 | shows "(\<Sum>i\<in>I. x^(m+i)) = x^m * (\<Sum>i\<in>I. x^i)" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2274 | by (simp add: sum_distrib_left power_add) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2275 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2276 | lemma sum_gp_offset: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2277 |   fixes x :: "'a::{comm_ring,division_ring}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2278 | shows "(\<Sum>i=m..m+n. x^i) = | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2279 | (if x = 1 then of_nat n + 1 else x^m * (1 - x^Suc n) / (1 - x))" | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2280 | using sum_gp [of x m "m+n"] | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2281 | by (auto simp: power_add algebra_simps) | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2282 | |
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2283 | lemma sum_gp_strict: | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2284 |   fixes x :: "'a::{comm_ring,division_ring}"
 | 
| 
e4997c181cce
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
 paulson <lp15@cam.ac.uk> parents: 
65273diff
changeset | 2285 | shows "(\<Sum>i<n. x^i) = (if x = 1 then of_nat n else (1 - x^n) / (1 - x))" | 
| 70817 
dd675800469d
dedicated fact collections for algebraic simplification rules potentially splitting goals
 haftmann parents: 
70749diff
changeset | 2286 | by (induct n) (auto simp: algebra_simps field_split_simps) | 
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
16733diff
changeset | 2287 | |
| 66936 | 2288 | |
| 2289 | subsubsection \<open>The formulae for arithmetic sums\<close> | |
| 2290 | ||
| 2291 | context comm_semiring_1 | |
| 2292 | begin | |
| 2293 | ||
| 2294 | lemma double_gauss_sum: | |
| 2295 | "2 * (\<Sum>i = 0..n. of_nat i) = of_nat n * (of_nat n + 1)" | |
| 2296 | by (induct n) (simp_all add: sum.atLeast0_atMost_Suc algebra_simps left_add_twice) | |
| 2297 | ||
| 2298 | lemma double_gauss_sum_from_Suc_0: | |
| 2299 | "2 * (\<Sum>i = Suc 0..n. of_nat i) = of_nat n * (of_nat n + 1)" | |
| 2300 | proof - | |
| 2301 |   have "sum of_nat {Suc 0..n} = sum of_nat (insert 0 {Suc 0..n})"
 | |
| 2302 | by simp | |
| 2303 |   also have "\<dots> = sum of_nat {0..n}"
 | |
| 2304 | by (cases n) (simp_all add: atLeast0_atMost_Suc_eq_insert_0) | |
| 2305 | finally show ?thesis | |
| 2306 | by (simp add: double_gauss_sum) | |
| 2307 | qed | |
| 2308 | ||
| 2309 | lemma double_arith_series: | |
| 2310 | "2 * (\<Sum>i = 0..n. a + of_nat i * d) = (of_nat n + 1) * (2 * a + of_nat n * d)" | |
| 2311 | proof - | |
| 2312 | have "(\<Sum>i = 0..n. a + of_nat i * d) = ((\<Sum>i = 0..n. a) + (\<Sum>i = 0..n. of_nat i * d))" | |
| 2313 | by (rule sum.distrib) | |
| 2314 | also have "\<dots> = (of_nat (Suc n) * a + d * (\<Sum>i = 0..n. of_nat i))" | |
| 2315 | by (simp add: sum_distrib_left algebra_simps) | |
| 2316 | finally show ?thesis | |
| 2317 | by (simp add: algebra_simps double_gauss_sum left_add_twice) | |
| 2318 | qed | |
| 2319 | ||
| 2320 | end | |
| 2321 | ||
| 70340 | 2322 | context unique_euclidean_semiring_with_nat | 
| 66936 | 2323 | begin | 
| 19469 
958d2f2dd8d4
moved arithmetic series to geometric series in SetInterval
 kleing parents: 
19376diff
changeset | 2324 | |
| 47222 
1b7c909a6fad
rephrase lemmas about arithmetic series using numeral '2'
 huffman parents: 
47108diff
changeset | 2325 | lemma gauss_sum: | 
| 66936 | 2326 | "(\<Sum>i = 0..n. of_nat i) = of_nat n * (of_nat n + 1) div 2" | 
| 2327 | using double_gauss_sum [of n, symmetric] by simp | |
| 2328 | ||
| 2329 | lemma gauss_sum_from_Suc_0: | |
| 2330 | "(\<Sum>i = Suc 0..n. of_nat i) = of_nat n * (of_nat n + 1) div 2" | |
| 2331 | using double_gauss_sum_from_Suc_0 [of n, symmetric] by simp | |
| 2332 | ||
| 2333 | lemma arith_series: | |
| 2334 | "(\<Sum>i = 0..n. a + of_nat i * d) = (of_nat n + 1) * (2 * a + of_nat n * d) div 2" | |
| 2335 | using double_arith_series [of a d n, symmetric] by simp | |
| 2336 | ||
| 2337 | end | |
| 2338 | ||
| 2339 | lemma gauss_sum_nat: | |
| 2340 |   "\<Sum>{0..n} = (n * Suc n) div 2"
 | |
| 2341 | using gauss_sum [of n, where ?'a = nat] by simp | |
| 19469 
958d2f2dd8d4
moved arithmetic series to geometric series in SetInterval
 kleing parents: 
19376diff
changeset | 2342 | |
| 
958d2f2dd8d4
moved arithmetic series to geometric series in SetInterval
 kleing parents: 
19376diff
changeset | 2343 | lemma arith_series_nat: | 
| 66936 | 2344 | "(\<Sum>i = 0..n. a + i * d) = Suc n * (2 * a + n * d) div 2" | 
| 2345 | using arith_series [of a d n] by simp | |
| 2346 | ||
| 2347 | lemma Sum_Icc_int: | |
| 2348 |   "\<Sum>{m..n} = (n * (n + 1) - m * (m - 1)) div 2"
 | |
| 2349 | if "m \<le> n" for m n :: int | |
| 2350 | using that proof (induct i \<equiv> "nat (n - m)" arbitrary: m n) | |
| 2351 | case 0 | |
| 2352 | then have "m = n" | |
| 2353 | by arith | |
| 2354 | then show ?case | |
| 2355 | by (simp add: algebra_simps mult_2 [symmetric]) | |
| 2356 | next | |
| 2357 | case (Suc i) | |
| 2358 | have 0: "i = nat((n-1) - m)" "m \<le> n-1" using Suc(2,3) by arith+ | |
| 2359 |   have "\<Sum> {m..n} = \<Sum> {m..1+(n-1)}" by simp
 | |
| 2360 |   also have "\<dots> = \<Sum> {m..n-1} + n" using \<open>m \<le> n\<close>
 | |
| 2361 | by(subst atLeastAtMostPlus1_int_conv) simp_all | |
| 2362 | also have "\<dots> = ((n-1)*(n-1+1) - m*(m-1)) div 2 + n" | |
| 2363 | by(simp add: Suc(1)[OF 0]) | |
| 2364 | also have "\<dots> = ((n-1)*(n-1+1) - m*(m-1) + 2*n) div 2" by simp | |
| 2365 | also have "\<dots> = (n*(n+1) - m*(m-1)) div 2" | |
| 2366 | by (simp add: algebra_simps mult_2_right) | |
| 2367 | finally show ?case . | |
| 2368 | qed | |
| 2369 | ||
| 2370 | lemma Sum_Icc_nat: | |
| 69182 | 2371 |   "\<Sum>{m..n} = (n * (n + 1) - m * (m - 1)) div 2" for m n :: nat
 | 
| 2372 | proof (cases "m \<le> n") | |
| 2373 | case True | |
| 2374 | then have *: "m * (m - 1) \<le> n * (n + 1)" | |
| 2375 | by (meson diff_le_self order_trans le_add1 mult_le_mono) | |
| 66936 | 2376 |   have "int (\<Sum>{m..n}) = (\<Sum>{int m..int n})"
 | 
| 2377 | by (simp add: sum.atLeast_int_atMost_int_shift) | |
| 2378 | also have "\<dots> = (int n * (int n + 1) - int m * (int m - 1)) div 2" | |
| 69182 | 2379 | using \<open>m \<le> n\<close> by (simp add: Sum_Icc_int) | 
| 66936 | 2380 | also have "\<dots> = int ((n * (n + 1) - m * (m - 1)) div 2)" | 
| 2381 | using le_square * by (simp add: algebra_simps of_nat_div of_nat_diff) | |
| 2382 | finally show ?thesis | |
| 2383 | by (simp only: of_nat_eq_iff) | |
| 69182 | 2384 | next | 
| 2385 | case False | |
| 2386 | then show ?thesis | |
| 2387 | by (auto dest: less_imp_Suc_add simp add: not_le algebra_simps) | |
| 19469 
958d2f2dd8d4
moved arithmetic series to geometric series in SetInterval
 kleing parents: 
19376diff
changeset | 2388 | qed | 
| 
958d2f2dd8d4
moved arithmetic series to geometric series in SetInterval
 kleing parents: 
19376diff
changeset | 2389 | |
| 66936 | 2390 | lemma Sum_Ico_nat: | 
| 69182 | 2391 |   "\<Sum>{m..<n} = (n * (n - 1) - m * (m - 1)) div 2" for m n :: nat
 | 
| 2392 | by (cases n) (simp_all add: atLeastLessThanSuc_atLeastAtMost Sum_Icc_nat) | |
| 19022 
0e6ec4fd204c
* moved ThreeDivides from Isar_examples to better suited HOL/ex
 kleing parents: 
17719diff
changeset | 2393 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 2394 | |
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2395 | subsubsection \<open>Division remainder\<close> | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2396 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2397 | lemma range_mod: | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2398 | fixes n :: nat | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2399 | assumes "n > 0" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2400 |   shows "range (\<lambda>m. m mod n) = {0..<n}" (is "?A = ?B")
 | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2401 | proof (rule set_eqI) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2402 | fix m | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2403 | show "m \<in> ?A \<longleftrightarrow> m \<in> ?B" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2404 | proof | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2405 | assume "m \<in> ?A" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2406 | with assms show "m \<in> ?B" | 
| 63915 | 2407 | by auto | 
| 63417 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2408 | next | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2409 | assume "m \<in> ?B" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2410 | moreover have "m mod n \<in> ?A" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2411 | by (rule rangeI) | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2412 | ultimately show "m \<in> ?A" | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2413 | by simp | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2414 | qed | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2415 | qed | 
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2416 | |
| 
c184ec919c70
more lemmas to emphasize {0::nat..(<)n} as canonical representation of intervals on nat
 haftmann parents: 
63365diff
changeset | 2417 | |
| 60758 | 2418 | subsection \<open>Products indexed over intervals\<close> | 
| 29960 
9d5c6f376768
 Syntactic support for products over set intervals
 paulson parents: 
29920diff
changeset | 2419 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 2420 | syntax (ASCII) | 
| 64272 | 2421 |   "_from_to_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(PROD _ = _.._./ _)" [0,0,0,10] 10)
 | 
| 2422 |   "_from_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(PROD _ = _..<_./ _)" [0,0,0,10] 10)
 | |
| 2423 |   "_upt_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(PROD _<_./ _)" [0,0,10] 10)
 | |
| 2424 |   "_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(PROD _<=_./ _)" [0,0,10] 10)
 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 2425 | |
| 29960 
9d5c6f376768
 Syntactic support for products over set intervals
 paulson parents: 
29920diff
changeset | 2426 | syntax (latex_prod output) | 
| 64272 | 2427 | "_from_to_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 2428 |  ("(3\<^latex>\<open>$\\prod_{\<close>_ = _\<^latex>\<open>}^{\<close>_\<^latex>\<open>}$\<close> _)" [0,0,0,10] 10)
 | 
| 64272 | 2429 | "_from_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 2430 |  ("(3\<^latex>\<open>$\\prod_{\<close>_ = _\<^latex>\<open>}^{<\<close>_\<^latex>\<open>}$\<close> _)" [0,0,0,10] 10)
 | 
| 64272 | 2431 | "_upt_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 2432 |  ("(3\<^latex>\<open>$\\prod_{\<close>_ < _\<^latex>\<open>}$\<close> _)" [0,0,10] 10)
 | 
| 64272 | 2433 | "_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 63935 
aa1fe1103ab8
raw control symbols are superseded by Latex.embed_raw;
 wenzelm parents: 
63918diff
changeset | 2434 |  ("(3\<^latex>\<open>$\\prod_{\<close>_ \<le> _\<^latex>\<open>}$\<close> _)" [0,0,10] 10)
 | 
| 29960 
9d5c6f376768
 Syntactic support for products over set intervals
 paulson parents: 
29920diff
changeset | 2435 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 2436 | syntax | 
| 64272 | 2437 |   "_from_to_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Prod>_ = _.._./ _)" [0,0,0,10] 10)
 | 
| 2438 |   "_from_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Prod>_ = _..<_./ _)" [0,0,0,10] 10)
 | |
| 2439 |   "_upt_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Prod>_<_./ _)" [0,0,10] 10)
 | |
| 2440 |   "_upto_prod" :: "idt \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> 'b"  ("(3\<Prod>_\<le>_./ _)" [0,0,10] 10)
 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61799diff
changeset | 2441 | |
| 29960 
9d5c6f376768
 Syntactic support for products over set intervals
 paulson parents: 
29920diff
changeset | 2442 | translations | 
| 64272 | 2443 |   "\<Prod>x=a..b. t" \<rightleftharpoons> "CONST prod (\<lambda>x. t) {a..b}"
 | 
| 2444 |   "\<Prod>x=a..<b. t" \<rightleftharpoons> "CONST prod (\<lambda>x. t) {a..<b}"
 | |
| 2445 |   "\<Prod>i\<le>n. t" \<rightleftharpoons> "CONST prod (\<lambda>i. t) {..n}"
 | |
| 2446 |   "\<Prod>i<n. t" \<rightleftharpoons> "CONST prod (\<lambda>i. t) {..<n}"
 | |
| 2447 | ||
| 2448 | lemma prod_int_plus_eq: "prod int {i..i+j} =  \<Prod>{int i..int (i+j)}"
 | |
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2449 | by (induct j) (auto simp add: atLeastAtMostSuc_conv atLeastAtMostPlus1_int_conv) | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2450 | |
| 64272 | 2451 | lemma prod_int_eq: "prod int {i..j} =  \<Prod>{int i..int j}"
 | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2452 | proof (cases "i \<le> j") | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2453 | case True | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2454 | then show ?thesis | 
| 64272 | 2455 | by (metis le_iff_add prod_int_plus_eq) | 
| 55242 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2456 | next | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2457 | case False | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2458 | then show ?thesis | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2459 | by auto | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2460 | qed | 
| 
413ec965f95d
Number_Theory: prime is no longer overloaded, but only for nat. Automatic coercion to int enabled.
 paulson <lp15@cam.ac.uk> parents: 
55143diff
changeset | 2461 | |
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2462 | subsection \<open>Efficient folding over intervals\<close> | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2463 | |
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2464 | function fold_atLeastAtMost_nat where | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2465 | [simp del]: "fold_atLeastAtMost_nat f a (b::nat) acc = | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2466 | (if a > b then acc else fold_atLeastAtMost_nat f (a+1) b (f a acc))" | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2467 | by pat_completeness auto | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2468 | termination by (relation "measure (\<lambda>(_,a,b,_). Suc b - a)") auto | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2469 | |
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2470 | lemma fold_atLeastAtMost_nat: | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2471 | assumes "comp_fun_commute f" | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2472 |   shows   "fold_atLeastAtMost_nat f a b acc = Finite_Set.fold f acc {a..b}"
 | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2473 | using assms | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2474 | proof (induction f a b acc rule: fold_atLeastAtMost_nat.induct, goal_cases) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2475 | case (1 f a b acc) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2476 | interpret comp_fun_commute f by fact | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2477 | show ?case | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2478 | proof (cases "a > b") | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2479 | case True | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2480 | thus ?thesis by (subst fold_atLeastAtMost_nat.simps) auto | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2481 | next | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2482 | case False | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2483 | with 1 show ?thesis | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2484 | by (subst fold_atLeastAtMost_nat.simps) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2485 | (auto simp: atLeastAtMost_insertL[symmetric] fold_fun_left_comm) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2486 | qed | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2487 | qed | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2488 | |
| 64267 | 2489 | lemma sum_atLeastAtMost_code: | 
| 2490 |   "sum f {a..b} = fold_atLeastAtMost_nat (\<lambda>a acc. f a + acc) a b 0"
 | |
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2491 | proof - | 
| 67399 | 2492 | have "comp_fun_commute (\<lambda>a. (+) (f a))" | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2493 | by unfold_locales (auto simp: o_def add_ac) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2494 | thus ?thesis | 
| 64267 | 2495 | by (simp add: sum.eq_fold fold_atLeastAtMost_nat o_def) | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2496 | qed | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2497 | |
| 64272 | 2498 | lemma prod_atLeastAtMost_code: | 
| 2499 |   "prod f {a..b} = fold_atLeastAtMost_nat (\<lambda>a acc. f a * acc) a b 1"
 | |
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2500 | proof - | 
| 69064 
5840724b1d71
Prefix form of infix with * on either side no longer needs special treatment
 nipkow parents: 
68618diff
changeset | 2501 | have "comp_fun_commute (\<lambda>a. (*) (f a))" | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2502 | by unfold_locales (auto simp: o_def mult_ac) | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2503 | thus ?thesis | 
| 64272 | 2504 | by (simp add: prod.eq_fold fold_atLeastAtMost_nat o_def) | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2505 | qed | 
| 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2506 | |
| 70746 
cf7b5020c207
Generalisation of many theorems to a more abstract type class (suggested by Mr Anonymous)
 paulson <lp15@cam.ac.uk> parents: 
70723diff
changeset | 2507 | (* TODO: Add support for folding over more kinds of intervals here *) | 
| 62128 
3201ddb00097
Integrated some material from Algebraic_Numbers AFP entry to Polynomials; generalised some polynomial stuff.
 eberlm parents: 
61955diff
changeset | 2508 | |
| 8924 | 2509 | end |