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