| author | wenzelm | 
| Sat, 14 May 2016 13:52:01 +0200 | |
| changeset 63093 | 3081f7719df7 | 
| parent 63040 | eb4ddd18d635 | 
| child 63317 | ca187a9f66da | 
| permissions | -rw-r--r-- | 
| 41959 | 1 | (* Title: HOL/Library/Formal_Power_Series.thy | 
| 29687 | 2 | Author: Amine Chaieb, University of Cambridge | 
| 3 | *) | |
| 4 | ||
| 60501 | 5 | section \<open>A formalization of formal power series\<close> | 
| 29687 | 6 | |
| 7 | theory Formal_Power_Series | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 8 | imports Complex_Main "~~/src/HOL/Number_Theory/Euclidean_Algorithm" | 
| 29687 | 9 | begin | 
| 10 | ||
| 60501 | 11 | |
| 60500 | 12 | subsection \<open>The type of formal power series\<close> | 
| 29687 | 13 | |
| 49834 | 14 | typedef 'a fps = "{f :: nat \<Rightarrow> 'a. True}"
 | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 15 | morphisms fps_nth Abs_fps | 
| 29687 | 16 | by simp | 
| 17 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 18 | notation fps_nth (infixl "$" 75) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 19 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 20 | lemma expand_fps_eq: "p = q \<longleftrightarrow> (\<forall>n. p $ n = q $ n)" | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 21 | by (simp add: fps_nth_inject [symmetric] fun_eq_iff) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 22 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 23 | lemma fps_ext: "(\<And>n. p $ n = q $ n) \<Longrightarrow> p = q" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 24 | by (simp add: expand_fps_eq) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 25 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 26 | lemma fps_nth_Abs_fps [simp]: "Abs_fps f $ n = f n" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 27 | by (simp add: Abs_fps_inverse) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 28 | |
| 60501 | 29 | text \<open>Definition of the basic elements 0 and 1 and the basic operations of addition, | 
| 30 | negation and multiplication.\<close> | |
| 29687 | 31 | |
| 36409 | 32 | instantiation fps :: (zero) zero | 
| 29687 | 33 | begin | 
| 60501 | 34 | definition fps_zero_def: "0 = Abs_fps (\<lambda>n. 0)" | 
| 35 | instance .. | |
| 29687 | 36 | end | 
| 37 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 38 | lemma fps_zero_nth [simp]: "0 $ n = 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 39 | unfolding fps_zero_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 40 | |
| 36409 | 41 | instantiation fps :: ("{one, zero}") one
 | 
| 29687 | 42 | begin | 
| 60501 | 43 | definition fps_one_def: "1 = Abs_fps (\<lambda>n. if n = 0 then 1 else 0)" | 
| 44 | instance .. | |
| 29687 | 45 | end | 
| 46 | ||
| 30488 | 47 | lemma fps_one_nth [simp]: "1 $ n = (if n = 0 then 1 else 0)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 48 | unfolding fps_one_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 49 | |
| 54681 | 50 | instantiation fps :: (plus) plus | 
| 29687 | 51 | begin | 
| 60501 | 52 | definition fps_plus_def: "op + = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n + g $ n))" | 
| 53 | instance .. | |
| 29687 | 54 | end | 
| 55 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 56 | lemma fps_add_nth [simp]: "(f + g) $ n = f $ n + g $ n" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 57 | unfolding fps_plus_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 58 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 59 | instantiation fps :: (minus) minus | 
| 29687 | 60 | begin | 
| 60501 | 61 | definition fps_minus_def: "op - = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n - g $ n))" | 
| 62 | instance .. | |
| 29687 | 63 | end | 
| 64 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 65 | lemma fps_sub_nth [simp]: "(f - g) $ n = f $ n - g $ n" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 66 | unfolding fps_minus_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 67 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 68 | instantiation fps :: (uminus) uminus | 
| 29687 | 69 | begin | 
| 60501 | 70 | definition fps_uminus_def: "uminus = (\<lambda>f. Abs_fps (\<lambda>n. - (f $ n)))" | 
| 71 | instance .. | |
| 29687 | 72 | end | 
| 73 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 74 | lemma fps_neg_nth [simp]: "(- f) $ n = - (f $ n)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 75 | unfolding fps_uminus_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 76 | |
| 54681 | 77 | instantiation fps :: ("{comm_monoid_add, times}") times
 | 
| 29687 | 78 | begin | 
| 60501 | 79 | definition fps_times_def: "op * = (\<lambda>f g. Abs_fps (\<lambda>n. \<Sum>i=0..n. f $ i * g $ (n - i)))" | 
| 80 | instance .. | |
| 29687 | 81 | end | 
| 82 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 83 | lemma fps_mult_nth: "(f * g) $ n = (\<Sum>i=0..n. f$i * g$(n - i))" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 84 | unfolding fps_times_def by simp | 
| 29687 | 85 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 86 | lemma fps_mult_nth_0 [simp]: "(f * g) $ 0 = f $ 0 * g $ 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 87 | unfolding fps_times_def by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 88 | |
| 52891 | 89 | declare atLeastAtMost_iff [presburger] | 
| 90 | declare Bex_def [presburger] | |
| 91 | declare Ball_def [presburger] | |
| 29687 | 92 | |
| 29913 | 93 | lemma mult_delta_left: | 
| 94 | fixes x y :: "'a::mult_zero" | |
| 95 | shows "(if b then x else 0) * y = (if b then x * y else 0)" | |
| 96 | by simp | |
| 97 | ||
| 98 | lemma mult_delta_right: | |
| 99 | fixes x y :: "'a::mult_zero" | |
| 100 | shows "x * (if b then y else 0) = (if b then x * y else 0)" | |
| 101 | by simp | |
| 102 | ||
| 29687 | 103 | lemma cond_value_iff: "f (if b then x else y) = (if b then f x else f y)" | 
| 104 | by auto | |
| 52891 | 105 | |
| 29687 | 106 | lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)" | 
| 107 | by auto | |
| 108 | ||
| 60501 | 109 | |
| 110 | subsection \<open>Formal power series form a commutative ring with unity, if the range of sequences | |
| 60500 | 111 | they represent is a commutative ring with unity\<close> | 
| 29687 | 112 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 113 | instance fps :: (semigroup_add) semigroup_add | 
| 29687 | 114 | proof | 
| 52891 | 115 | fix a b c :: "'a fps" | 
| 116 | show "a + b + c = a + (b + c)" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 117 | by (simp add: fps_ext add.assoc) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 118 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 119 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 120 | instance fps :: (ab_semigroup_add) ab_semigroup_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 121 | proof | 
| 52891 | 122 | fix a b :: "'a fps" | 
| 123 | show "a + b = b + a" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 124 | by (simp add: fps_ext add.commute) | 
| 29687 | 125 | qed | 
| 126 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 127 | lemma fps_mult_assoc_lemma: | 
| 53195 | 128 | fixes k :: nat | 
| 129 | and f :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> 'a::comm_monoid_add" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 130 | shows "(\<Sum>j=0..k. \<Sum>i=0..j. f i (j - i) (n - j)) = | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 131 | (\<Sum>j=0..k. \<Sum>i=0..k - j. f j i (n - j - i))" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 132 | by (induct k) (simp_all add: Suc_diff_le setsum.distrib add.assoc) | 
| 29687 | 133 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 134 | instance fps :: (semiring_0) semigroup_mult | 
| 29687 | 135 | proof | 
| 136 | fix a b c :: "'a fps" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 137 | show "(a * b) * c = a * (b * c)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 138 | proof (rule fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 139 | fix n :: nat | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 140 | have "(\<Sum>j=0..n. \<Sum>i=0..j. a$i * b$(j - i) * c$(n - j)) = | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 141 | (\<Sum>j=0..n. \<Sum>i=0..n - j. a$j * b$i * c$(n - j - i))" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 142 | by (rule fps_mult_assoc_lemma) | 
| 52891 | 143 | then show "((a * b) * c) $ n = (a * (b * c)) $ n" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 144 | by (simp add: fps_mult_nth setsum_right_distrib setsum_left_distrib mult.assoc) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 145 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 146 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 147 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 148 | lemma fps_mult_commute_lemma: | 
| 52903 | 149 | fixes n :: nat | 
| 150 | and f :: "nat \<Rightarrow> nat \<Rightarrow> 'a::comm_monoid_add" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 151 | shows "(\<Sum>i=0..n. f i (n - i)) = (\<Sum>i=0..n. f (n - i) i)" | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 152 | by (rule setsum.reindex_bij_witness[where i="op - n" and j="op - n"]) auto | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 153 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 154 | instance fps :: (comm_semiring_0) ab_semigroup_mult | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 155 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 156 | fix a b :: "'a fps" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 157 | show "a * b = b * a" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 158 | proof (rule fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 159 | fix n :: nat | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 160 | have "(\<Sum>i=0..n. a$i * b$(n - i)) = (\<Sum>i=0..n. a$(n - i) * b$i)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 161 | by (rule fps_mult_commute_lemma) | 
| 52891 | 162 | then show "(a * b) $ n = (b * a) $ n" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 163 | by (simp add: fps_mult_nth mult.commute) | 
| 29687 | 164 | qed | 
| 165 | qed | |
| 166 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 167 | instance fps :: (monoid_add) monoid_add | 
| 29687 | 168 | proof | 
| 52891 | 169 | fix a :: "'a fps" | 
| 170 | show "0 + a = a" by (simp add: fps_ext) | |
| 171 | show "a + 0 = a" by (simp add: fps_ext) | |
| 29687 | 172 | qed | 
| 173 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 174 | instance fps :: (comm_monoid_add) comm_monoid_add | 
| 29687 | 175 | proof | 
| 52891 | 176 | fix a :: "'a fps" | 
| 177 | show "0 + a = a" by (simp add: fps_ext) | |
| 29687 | 178 | qed | 
| 179 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 180 | instance fps :: (semiring_1) monoid_mult | 
| 29687 | 181 | proof | 
| 52891 | 182 | fix a :: "'a fps" | 
| 60501 | 183 | show "1 * a = a" | 
| 184 | by (simp add: fps_ext fps_mult_nth mult_delta_left setsum.delta) | |
| 185 | show "a * 1 = a" | |
| 186 | by (simp add: fps_ext fps_mult_nth mult_delta_right setsum.delta') | |
| 29687 | 187 | qed | 
| 188 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 189 | instance fps :: (cancel_semigroup_add) cancel_semigroup_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 190 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 191 | fix a b c :: "'a fps" | 
| 60501 | 192 | show "b = c" if "a + b = a + c" | 
| 193 | using that by (simp add: expand_fps_eq) | |
| 194 | show "b = c" if "b + a = c + a" | |
| 195 | using that by (simp add: expand_fps_eq) | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 196 | qed | 
| 29687 | 197 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 198 | instance fps :: (cancel_ab_semigroup_add) cancel_ab_semigroup_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 199 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 200 | fix a b c :: "'a fps" | 
| 60501 | 201 | show "a + b - a = b" | 
| 202 | by (simp add: expand_fps_eq) | |
| 203 | show "a - b - c = a - (b + c)" | |
| 204 | by (simp add: expand_fps_eq diff_diff_eq) | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 205 | qed | 
| 29687 | 206 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 207 | instance fps :: (cancel_comm_monoid_add) cancel_comm_monoid_add .. | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 208 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 209 | instance fps :: (group_add) group_add | 
| 29687 | 210 | proof | 
| 52891 | 211 | fix a b :: "'a fps" | 
| 212 | show "- a + a = 0" by (simp add: fps_ext) | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 213 | show "a + - b = a - b" by (simp add: fps_ext) | 
| 29687 | 214 | qed | 
| 215 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 216 | instance fps :: (ab_group_add) ab_group_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 217 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 218 | fix a b :: "'a fps" | 
| 52891 | 219 | show "- a + a = 0" by (simp add: fps_ext) | 
| 220 | show "a - b = a + - b" by (simp add: fps_ext) | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 221 | qed | 
| 29687 | 222 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 223 | instance fps :: (zero_neq_one) zero_neq_one | 
| 60679 | 224 | by standard (simp add: expand_fps_eq) | 
| 29687 | 225 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 226 | instance fps :: (semiring_0) semiring | 
| 29687 | 227 | proof | 
| 228 | fix a b c :: "'a fps" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 229 | show "(a + b) * c = a * c + b * c" | 
| 57418 | 230 | by (simp add: expand_fps_eq fps_mult_nth distrib_right setsum.distrib) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 231 | show "a * (b + c) = a * b + a * c" | 
| 57418 | 232 | by (simp add: expand_fps_eq fps_mult_nth distrib_left setsum.distrib) | 
| 29687 | 233 | qed | 
| 234 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 235 | instance fps :: (semiring_0) semiring_0 | 
| 29687 | 236 | proof | 
| 53195 | 237 | fix a :: "'a fps" | 
| 60501 | 238 | show "0 * a = 0" | 
| 239 | by (simp add: fps_ext fps_mult_nth) | |
| 240 | show "a * 0 = 0" | |
| 241 | by (simp add: fps_ext fps_mult_nth) | |
| 29687 | 242 | qed | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 243 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 244 | instance fps :: (semiring_0_cancel) semiring_0_cancel .. | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 245 | |
| 60867 | 246 | instance fps :: (semiring_1) semiring_1 .. | 
| 247 | ||
| 60501 | 248 | |
| 60500 | 249 | subsection \<open>Selection of the nth power of the implicit variable in the infinite sum\<close> | 
| 29687 | 250 | |
| 251 | lemma fps_nonzero_nth: "f \<noteq> 0 \<longleftrightarrow> (\<exists> n. f $n \<noteq> 0)" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 252 | by (simp add: expand_fps_eq) | 
| 29687 | 253 | |
| 52902 | 254 | lemma fps_nonzero_nth_minimal: "f \<noteq> 0 \<longleftrightarrow> (\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m < n. f $ m = 0))" | 
| 60501 | 255 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 256 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 257 | let ?n = "LEAST n. f $ n \<noteq> 0" | 
| 60501 | 258 | show ?rhs if ?lhs | 
| 259 | proof - | |
| 260 | from that have "\<exists>n. f $ n \<noteq> 0" | |
| 261 | by (simp add: fps_nonzero_nth) | |
| 262 | then have "f $ ?n \<noteq> 0" | |
| 263 | by (rule LeastI_ex) | |
| 264 | moreover have "\<forall>m<?n. f $ m = 0" | |
| 265 | by (auto dest: not_less_Least) | |
| 266 | ultimately have "f $ ?n \<noteq> 0 \<and> (\<forall>m<?n. f $ m = 0)" .. | |
| 267 | then show ?thesis .. | |
| 268 | qed | |
| 269 | show ?lhs if ?rhs | |
| 270 | using that by (auto simp add: expand_fps_eq) | |
| 29687 | 271 | qed | 
| 272 | ||
| 273 | lemma fps_eq_iff: "f = g \<longleftrightarrow> (\<forall>n. f $ n = g $n)" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 274 | by (rule expand_fps_eq) | 
| 29687 | 275 | |
| 52891 | 276 | lemma fps_setsum_nth: "setsum f S $ n = setsum (\<lambda>k. (f k) $ n) S" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 277 | proof (cases "finite S") | 
| 52891 | 278 | case True | 
| 279 | then show ?thesis by (induct set: finite) auto | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 280 | next | 
| 52891 | 281 | case False | 
| 282 | then show ?thesis by simp | |
| 29687 | 283 | qed | 
| 284 | ||
| 60501 | 285 | |
| 286 | subsection \<open>Injection of the basic ring elements and multiplication by scalars\<close> | |
| 29687 | 287 | |
| 52891 | 288 | definition "fps_const c = Abs_fps (\<lambda>n. if n = 0 then c else 0)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 289 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 290 | lemma fps_nth_fps_const [simp]: "fps_const c $ n = (if n = 0 then c else 0)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 291 | unfolding fps_const_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 292 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 293 | lemma fps_const_0_eq_0 [simp]: "fps_const 0 = 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 294 | by (simp add: fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 295 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 296 | lemma fps_const_1_eq_1 [simp]: "fps_const 1 = 1" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 297 | by (simp add: fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 298 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 299 | lemma fps_const_neg [simp]: "- (fps_const (c::'a::ring)) = fps_const (- c)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 300 | by (simp add: fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 301 | |
| 54681 | 302 | lemma fps_const_add [simp]: "fps_const (c::'a::monoid_add) + fps_const d = fps_const (c + d)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 303 | by (simp add: fps_ext) | 
| 52891 | 304 | |
| 54681 | 305 | lemma fps_const_sub [simp]: "fps_const (c::'a::group_add) - fps_const d = fps_const (c - d)" | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 306 | by (simp add: fps_ext) | 
| 52891 | 307 | |
| 54681 | 308 | lemma fps_const_mult[simp]: "fps_const (c::'a::ring) * fps_const d = fps_const (c * d)" | 
| 57418 | 309 | by (simp add: fps_eq_iff fps_mult_nth setsum.neutral) | 
| 29687 | 310 | |
| 54681 | 311 | lemma fps_const_add_left: "fps_const (c::'a::monoid_add) + f = | 
| 48757 | 312 | Abs_fps (\<lambda>n. if n = 0 then c + f$0 else f$n)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 313 | by (simp add: fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 314 | |
| 54681 | 315 | lemma fps_const_add_right: "f + fps_const (c::'a::monoid_add) = | 
| 48757 | 316 | Abs_fps (\<lambda>n. if n = 0 then f$0 + c else f$n)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 317 | by (simp add: fps_ext) | 
| 29687 | 318 | |
| 54681 | 319 | lemma fps_const_mult_left: "fps_const (c::'a::semiring_0) * f = Abs_fps (\<lambda>n. c * f$n)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 320 | unfolding fps_eq_iff fps_mult_nth | 
| 57418 | 321 | by (simp add: fps_const_def mult_delta_left setsum.delta) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 322 | |
| 54681 | 323 | lemma fps_const_mult_right: "f * fps_const (c::'a::semiring_0) = Abs_fps (\<lambda>n. f$n * c)" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 324 | unfolding fps_eq_iff fps_mult_nth | 
| 57418 | 325 | by (simp add: fps_const_def mult_delta_right setsum.delta') | 
| 29687 | 326 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 327 | lemma fps_mult_left_const_nth [simp]: "(fps_const (c::'a::semiring_1) * f)$n = c* f$n" | 
| 57418 | 328 | by (simp add: fps_mult_nth mult_delta_left setsum.delta) | 
| 29687 | 329 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 330 | lemma fps_mult_right_const_nth [simp]: "(f * fps_const (c::'a::semiring_1))$n = f$n * c" | 
| 57418 | 331 | by (simp add: fps_mult_nth mult_delta_right setsum.delta') | 
| 29687 | 332 | |
| 60501 | 333 | |
| 60500 | 334 | subsection \<open>Formal power series form an integral domain\<close> | 
| 29687 | 335 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 336 | instance fps :: (ring) ring .. | 
| 29687 | 337 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 338 | instance fps :: (ring_1) ring_1 | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 339 | by (intro_classes, auto simp add: distrib_right) | 
| 29687 | 340 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 341 | instance fps :: (comm_ring_1) comm_ring_1 | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 342 | by (intro_classes, auto simp add: distrib_right) | 
| 29687 | 343 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 344 | instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors | 
| 29687 | 345 | proof | 
| 346 | fix a b :: "'a fps" | |
| 60501 | 347 | assume "a \<noteq> 0" and "b \<noteq> 0" | 
| 348 | then obtain i j where i: "a $ i \<noteq> 0" "\<forall>k<i. a $ k = 0" and j: "b $ j \<noteq> 0" "\<forall>k<j. b $ k =0" | |
| 54681 | 349 | unfolding fps_nonzero_nth_minimal | 
| 29687 | 350 | by blast+ | 
| 60501 | 351 | have "(a * b) $ (i + j) = (\<Sum>k=0..i+j. a $ k * b $ (i + j - k))" | 
| 29687 | 352 | by (rule fps_mult_nth) | 
| 60501 | 353 |   also have "\<dots> = (a $ i * b $ (i + j - i)) + (\<Sum>k\<in>{0..i+j} - {i}. a $ k * b $ (i + j - k))"
 | 
| 57418 | 354 | by (rule setsum.remove) simp_all | 
| 60501 | 355 |   also have "(\<Sum>k\<in>{0..i+j}-{i}. a $ k * b $ (i + j - k)) = 0"
 | 
| 356 | proof (rule setsum.neutral [rule_format]) | |
| 357 |     fix k assume "k \<in> {0..i+j} - {i}"
 | |
| 358 | then have "k < i \<or> i+j-k < j" | |
| 359 | by auto | |
| 360 | then show "a $ k * b $ (i + j - k) = 0" | |
| 361 | using i j by auto | |
| 362 | qed | |
| 363 | also have "a $ i * b $ (i + j - i) + 0 = a $ i * b $ j" | |
| 364 | by simp | |
| 365 | also have "a $ i * b $ j \<noteq> 0" | |
| 366 | using i j by simp | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 367 | finally have "(a*b) $ (i+j) \<noteq> 0" . | 
| 60501 | 368 | then show "a * b \<noteq> 0" | 
| 369 | unfolding fps_nonzero_nth by blast | |
| 29687 | 370 | qed | 
| 371 | ||
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 372 | instance fps :: (ring_1_no_zero_divisors) ring_1_no_zero_divisors .. | 
| 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 373 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 374 | instance fps :: (idom) idom .. | 
| 29687 | 375 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 376 | lemma numeral_fps_const: "numeral k = fps_const (numeral k)" | 
| 48757 | 377 | by (induct k) (simp_all only: numeral.simps fps_const_1_eq_1 | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 378 | fps_const_add [symmetric]) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 379 | |
| 60867 | 380 | lemma neg_numeral_fps_const: | 
| 381 | "(- numeral k :: 'a :: ring_1 fps) = fps_const (- numeral k)" | |
| 382 | by (simp add: numeral_fps_const) | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 383 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 384 | lemma fps_numeral_nth: "numeral n $ i = (if i = 0 then numeral n else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 385 | by (simp add: numeral_fps_const) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 386 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 387 | lemma fps_numeral_nth_0 [simp]: "numeral n $ 0 = numeral n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 388 | by (simp add: numeral_fps_const) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 389 | |
| 60501 | 390 | |
| 391 | subsection \<open>The eXtractor series X\<close> | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 392 | |
| 54681 | 393 | lemma minus_one_power_iff: "(- (1::'a::comm_ring_1)) ^ n = (if even n then 1 else - 1)" | 
| 48757 | 394 | by (induct n) auto | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 395 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 396 | definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)" | 
| 53195 | 397 | |
| 398 | lemma X_mult_nth [simp]: | |
| 54681 | 399 | "(X * (f :: 'a::semiring_1 fps)) $n = (if n = 0 then 0 else f $ (n - 1))" | 
| 53195 | 400 | proof (cases "n = 0") | 
| 401 | case False | |
| 402 | have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" | |
| 403 | by (simp add: fps_mult_nth) | |
| 404 | also have "\<dots> = f $ (n - 1)" | |
| 57418 | 405 | using False by (simp add: X_def mult_delta_left setsum.delta) | 
| 60501 | 406 | finally show ?thesis | 
| 407 | using False by simp | |
| 53195 | 408 | next | 
| 409 | case True | |
| 60501 | 410 | then show ?thesis | 
| 411 | by (simp add: fps_mult_nth X_def) | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 412 | qed | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 413 | |
| 48757 | 414 | lemma X_mult_right_nth[simp]: | 
| 54681 | 415 | "((f :: 'a::comm_semiring_1 fps) * X) $n = (if n = 0 then 0 else f $ (n - 1))" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 416 | by (metis X_mult_nth mult.commute) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 417 | |
| 54681 | 418 | lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then 1::'a::comm_ring_1 else 0)" | 
| 52902 | 419 | proof (induct k) | 
| 420 | case 0 | |
| 54452 | 421 | then show ?case by (simp add: X_def fps_eq_iff) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 422 | next | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 423 | case (Suc k) | 
| 60501 | 424 | have "(X^Suc k) $ m = (if m = Suc k then 1::'a else 0)" for m | 
| 425 | proof - | |
| 426 | have "(X^Suc k) $ m = (if m = 0 then 0 else (X^k) $ (m - 1))" | |
| 52891 | 427 | by (simp del: One_nat_def) | 
| 60501 | 428 | then show ?thesis | 
| 52891 | 429 | using Suc.hyps by (auto cong del: if_weak_cong) | 
| 60501 | 430 | qed | 
| 431 | then show ?case | |
| 432 | by (simp add: fps_eq_iff) | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 433 | qed | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 434 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 435 | lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 436 | by (simp add: X_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 437 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 438 | lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else 0::'a::comm_ring_1)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 439 | by (simp add: X_power_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 440 | |
| 60501 | 441 | lemma X_power_mult_nth: "(X^k * (f :: 'a::comm_ring_1 fps)) $n = (if n < k then 0 else f $ (n - k))" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 442 | apply (induct k arbitrary: n) | 
| 52891 | 443 | apply simp | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 444 | unfolding power_Suc mult.assoc | 
| 48757 | 445 | apply (case_tac n) | 
| 446 | apply auto | |
| 447 | done | |
| 448 | ||
| 449 | lemma X_power_mult_right_nth: | |
| 54681 | 450 | "((f :: 'a::comm_ring_1 fps) * X^k) $n = (if n < k then 0 else f $ (n - k))" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 451 | by (metis X_power_mult_nth mult.commute) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 452 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 453 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 454 | lemma X_neq_fps_const [simp]: "(X :: 'a :: zero_neq_one fps) \<noteq> fps_const c" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 455 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 456 | assume "(X::'a fps) = fps_const (c::'a)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 457 | hence "X$1 = (fps_const (c::'a))$1" by (simp only:) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 458 | thus False by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 459 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 460 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 461 | lemma X_neq_zero [simp]: "(X :: 'a :: zero_neq_one fps) \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 462 | by (simp only: fps_const_0_eq_0[symmetric] X_neq_fps_const) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 463 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 464 | lemma X_neq_one [simp]: "(X :: 'a :: zero_neq_one fps) \<noteq> 1" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 465 | by (simp only: fps_const_1_eq_1[symmetric] X_neq_fps_const) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 466 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 467 | lemma X_neq_numeral [simp]: "(X :: 'a :: {semiring_1,zero_neq_one} fps) \<noteq> numeral c"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 468 | by (simp only: numeral_fps_const X_neq_fps_const) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 469 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 470 | lemma X_pow_eq_X_pow_iff [simp]: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 471 |   "(X :: ('a :: {comm_ring_1}) fps) ^ m = X ^ n \<longleftrightarrow> m = n"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 472 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 473 | assume "(X :: 'a fps) ^ m = X ^ n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 474 | hence "(X :: 'a fps) ^ m $ m = X ^ n $ m" by (simp only:) | 
| 62390 | 475 | thus "m = n" by (simp split: if_split_asm) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 476 | qed simp_all | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 477 | |
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 478 | |
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 479 | subsection \<open>Subdegrees\<close> | 
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 480 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 481 | definition subdegree :: "('a::zero) fps \<Rightarrow> nat" where
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 482 | "subdegree f = (if f = 0 then 0 else LEAST n. f$n \<noteq> 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 483 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 484 | lemma subdegreeI: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 485 | assumes "f $ d \<noteq> 0" and "\<And>i. i < d \<Longrightarrow> f $ i = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 486 | shows "subdegree f = d" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 487 | proof- | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 488 | from assms(1) have "f \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 489 | moreover from assms(1) have "(LEAST i. f $ i \<noteq> 0) = d" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 490 | proof (rule Least_equality) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 491 | fix e assume "f $ e \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 492 | with assms(2) have "\<not>(e < d)" by blast | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 493 | thus "e \<ge> d" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 494 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 495 | ultimately show ?thesis unfolding subdegree_def by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 496 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 497 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 498 | lemma nth_subdegree_nonzero [simp,intro]: "f \<noteq> 0 \<Longrightarrow> f $ subdegree f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 499 | proof- | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 500 | assume "f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 501 | hence "subdegree f = (LEAST n. f $ n \<noteq> 0)" by (simp add: subdegree_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 502 | also from \<open>f \<noteq> 0\<close> have "\<exists>n. f$n \<noteq> 0" using fps_nonzero_nth by blast | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 503 | from LeastI_ex[OF this] have "f $ (LEAST n. f $ n \<noteq> 0) \<noteq> 0" . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 504 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 505 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 506 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 507 | lemma nth_less_subdegree_zero [dest]: "n < subdegree f \<Longrightarrow> f $ n = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 508 | proof (cases "f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 509 | assume "f \<noteq> 0" and less: "n < subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 510 | note less | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 511 | also from \<open>f \<noteq> 0\<close> have "subdegree f = (LEAST n. f $ n \<noteq> 0)" by (simp add: subdegree_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 512 | finally show "f $ n = 0" using not_less_Least by blast | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 513 | qed simp_all | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 514 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 515 | lemma subdegree_geI: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 516 | assumes "f \<noteq> 0" "\<And>i. i < n \<Longrightarrow> f$i = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 517 | shows "subdegree f \<ge> n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 518 | proof (rule ccontr) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 519 | assume "\<not>(subdegree f \<ge> n)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 520 | with assms(2) have "f $ subdegree f = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 521 | moreover from assms(1) have "f $ subdegree f \<noteq> 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 522 | ultimately show False by contradiction | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 523 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 524 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 525 | lemma subdegree_greaterI: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 526 | assumes "f \<noteq> 0" "\<And>i. i \<le> n \<Longrightarrow> f$i = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 527 | shows "subdegree f > n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 528 | proof (rule ccontr) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 529 | assume "\<not>(subdegree f > n)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 530 | with assms(2) have "f $ subdegree f = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 531 | moreover from assms(1) have "f $ subdegree f \<noteq> 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 532 | ultimately show False by contradiction | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 533 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 534 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 535 | lemma subdegree_leI: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 536 | "f $ n \<noteq> 0 \<Longrightarrow> subdegree f \<le> n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 537 | by (rule leI) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 538 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 539 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 540 | lemma subdegree_0 [simp]: "subdegree 0 = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 541 | by (simp add: subdegree_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 542 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 543 | lemma subdegree_1 [simp]: "subdegree (1 :: ('a :: zero_neq_one) fps) = 0"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 544 | by (auto intro!: subdegreeI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 545 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 546 | lemma subdegree_X [simp]: "subdegree (X :: ('a :: zero_neq_one) fps) = 1"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 547 | by (auto intro!: subdegreeI simp: X_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 548 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 549 | lemma subdegree_fps_const [simp]: "subdegree (fps_const c) = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 550 | by (cases "c = 0") (auto intro!: subdegreeI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 551 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 552 | lemma subdegree_numeral [simp]: "subdegree (numeral n) = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 553 | by (simp add: numeral_fps_const) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 554 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 555 | lemma subdegree_eq_0_iff: "subdegree f = 0 \<longleftrightarrow> f = 0 \<or> f $ 0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 556 | proof (cases "f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 557 | assume "f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 558 | thus ?thesis | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 559 | using nth_subdegree_nonzero[OF \<open>f \<noteq> 0\<close>] by (fastforce intro!: subdegreeI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 560 | qed simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 561 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 562 | lemma subdegree_eq_0 [simp]: "f $ 0 \<noteq> 0 \<Longrightarrow> subdegree f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 563 | by (simp add: subdegree_eq_0_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 564 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 565 | lemma nth_subdegree_mult [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 566 |   fixes f g :: "('a :: {mult_zero,comm_monoid_add}) fps"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 567 | shows "(f * g) $ (subdegree f + subdegree g) = f $ subdegree f * g $ subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 568 | proof- | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 569 | let ?n = "subdegree f + subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 570 | have "(f * g) $ ?n = (\<Sum>i=0..?n. f$i * g$(?n-i))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 571 | by (simp add: fps_mult_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 572 | also have "... = (\<Sum>i=0..?n. if i = subdegree f then f$i * g$(?n-i) else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 573 | proof (intro setsum.cong) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 574 |     fix x assume x: "x \<in> {0..?n}"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 575 | hence "x = subdegree f \<or> x < subdegree f \<or> ?n - x < subdegree g" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 576 | thus "f $ x * g $ (?n - x) = (if x = subdegree f then f $ x * g $ (?n - x) else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 577 | by (elim disjE conjE) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 578 | qed auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 579 | also have "... = f $ subdegree f * g $ subdegree g" by (simp add: setsum.delta) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 580 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 581 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 582 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 583 | lemma subdegree_mult [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 584 | assumes "f \<noteq> 0" "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 585 |   shows "subdegree ((f :: ('a :: {ring_no_zero_divisors}) fps) * g) = subdegree f + subdegree g"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 586 | proof (rule subdegreeI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 587 | let ?n = "subdegree f + subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 588 | have "(f * g) $ ?n = (\<Sum>i=0..?n. f$i * g$(?n-i))" by (simp add: fps_mult_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 589 | also have "... = (\<Sum>i=0..?n. if i = subdegree f then f$i * g$(?n-i) else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 590 | proof (intro setsum.cong) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 591 |     fix x assume x: "x \<in> {0..?n}"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 592 | hence "x = subdegree f \<or> x < subdegree f \<or> ?n - x < subdegree g" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 593 | thus "f $ x * g $ (?n - x) = (if x = subdegree f then f $ x * g $ (?n - x) else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 594 | by (elim disjE conjE) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 595 | qed auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 596 | also have "... = f $ subdegree f * g $ subdegree g" by (simp add: setsum.delta) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 597 | also from assms have "... \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 598 | finally show "(f * g) $ (subdegree f + subdegree g) \<noteq> 0" . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 599 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 600 | fix m assume m: "m < subdegree f + subdegree g" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 601 | have "(f * g) $ m = (\<Sum>i=0..m. f$i * g$(m-i))" by (simp add: fps_mult_nth) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 602 | also have "... = (\<Sum>i=0..m. 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 603 | proof (rule setsum.cong) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 604 |     fix i assume "i \<in> {0..m}"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 605 | with m have "i < subdegree f \<or> m - i < subdegree g" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 606 | thus "f$i * g$(m-i) = 0" by (elim disjE) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 607 | qed auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 608 | finally show "(f * g) $ m = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 609 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 610 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 611 | lemma subdegree_power [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 612 |   "subdegree ((f :: ('a :: ring_1_no_zero_divisors) fps) ^ n) = n * subdegree f"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 613 | by (cases "f = 0"; induction n) simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 614 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 615 | lemma subdegree_uminus [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 616 |   "subdegree (-(f::('a::group_add) fps)) = subdegree f"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 617 | by (simp add: subdegree_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 618 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 619 | lemma subdegree_minus_commute [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 620 |   "subdegree (f-(g::('a::group_add) fps)) = subdegree (g - f)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 621 | proof - | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 622 | have "f - g = -(g - f)" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 623 | also have "subdegree ... = subdegree (g - f)" by (simp only: subdegree_uminus) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 624 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 625 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 626 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 627 | lemma subdegree_add_ge: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 628 |   assumes "f \<noteq> -(g :: ('a :: {group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 629 | shows "subdegree (f + g) \<ge> min (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 630 | proof (rule subdegree_geI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 631 | from assms show "f + g \<noteq> 0" by (subst (asm) eq_neg_iff_add_eq_0) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 632 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 633 | fix i assume "i < min (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 634 | hence "f $ i = 0" and "g $ i = 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 635 | thus "(f + g) $ i = 0" by force | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 636 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 637 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 638 | lemma subdegree_add_eq1: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 639 | assumes "f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 640 |   assumes "subdegree f < subdegree (g :: ('a :: {group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 641 | shows "subdegree (f + g) = subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 642 | proof (rule antisym[OF subdegree_leI]) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 643 | from assms show "subdegree (f + g) \<ge> subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 644 | by (intro order.trans[OF min.boundedI subdegree_add_ge]) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 645 | from assms have "f $ subdegree f \<noteq> 0" "g $ subdegree f = 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 646 | thus "(f + g) $ subdegree f \<noteq> 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 647 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 648 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 649 | lemma subdegree_add_eq2: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 650 | assumes "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 651 |   assumes "subdegree g < subdegree (f :: ('a :: {ab_group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 652 | shows "subdegree (f + g) = subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 653 | using subdegree_add_eq1[OF assms] by (simp add: add.commute) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 654 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 655 | lemma subdegree_diff_eq1: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 656 | assumes "f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 657 |   assumes "subdegree f < subdegree (g :: ('a :: {ab_group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 658 | shows "subdegree (f - g) = subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 659 | using subdegree_add_eq1[of f "-g"] assms by (simp add: add.commute) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 660 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 661 | lemma subdegree_diff_eq2: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 662 | assumes "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 663 |   assumes "subdegree g < subdegree (f :: ('a :: {ab_group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 664 | shows "subdegree (f - g) = subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 665 | using subdegree_add_eq2[of "-g" f] assms by (simp add: add.commute) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 666 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 667 | lemma subdegree_diff_ge [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 668 |   assumes "f \<noteq> (g :: ('a :: {group_add}) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 669 | shows "subdegree (f - g) \<ge> min (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 670 | using assms subdegree_add_ge[of f "-g"] by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 671 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 672 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 673 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 674 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 675 | subsection \<open>Shifting and slicing\<close> | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 676 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 677 | definition fps_shift :: "nat \<Rightarrow> 'a fps \<Rightarrow> 'a fps" where | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 678 | "fps_shift n f = Abs_fps (\<lambda>i. f $ (i + n))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 679 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 680 | lemma fps_shift_nth [simp]: "fps_shift n f $ i = f $ (i + n)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 681 | by (simp add: fps_shift_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 682 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 683 | lemma fps_shift_0 [simp]: "fps_shift 0 f = f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 684 | by (intro fps_ext) (simp add: fps_shift_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 685 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 686 | lemma fps_shift_zero [simp]: "fps_shift n 0 = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 687 | by (intro fps_ext) (simp add: fps_shift_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 688 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 689 | lemma fps_shift_one: "fps_shift n 1 = (if n = 0 then 1 else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 690 | by (intro fps_ext) (simp add: fps_shift_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 691 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 692 | lemma fps_shift_fps_const: "fps_shift n (fps_const c) = (if n = 0 then fps_const c else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 693 | by (intro fps_ext) (simp add: fps_shift_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 694 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 695 | lemma fps_shift_numeral: "fps_shift n (numeral c) = (if n = 0 then numeral c else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 696 | by (simp add: numeral_fps_const fps_shift_fps_const) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 697 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 698 | lemma fps_shift_X_power [simp]: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 699 | "n \<le> m \<Longrightarrow> fps_shift n (X ^ m) = (X ^ (m - n) ::'a::comm_ring_1 fps)" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 700 | by (intro fps_ext) (auto simp: fps_shift_def ) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 701 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 702 | lemma fps_shift_times_X_power: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 703 | "n \<le> subdegree f \<Longrightarrow> fps_shift n f * X ^ n = (f :: 'a :: comm_ring_1 fps)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 704 | by (intro fps_ext) (auto simp: X_power_mult_right_nth nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 705 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 706 | lemma fps_shift_times_X_power' [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 707 | "fps_shift n (f * X^n) = (f :: 'a :: comm_ring_1 fps)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 708 | by (intro fps_ext) (auto simp: X_power_mult_right_nth nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 709 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 710 | lemma fps_shift_times_X_power'': | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 711 | "m \<le> n \<Longrightarrow> fps_shift n (f * X^m) = fps_shift (n - m) (f :: 'a :: comm_ring_1 fps)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 712 | by (intro fps_ext) (auto simp: X_power_mult_right_nth nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 713 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 714 | lemma fps_shift_subdegree [simp]: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 715 | "n \<le> subdegree f \<Longrightarrow> subdegree (fps_shift n f) = subdegree (f :: 'a :: comm_ring_1 fps) - n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 716 | by (cases "f = 0") (force intro: nth_less_subdegree_zero subdegreeI)+ | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 717 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 718 | lemma subdegree_decompose: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 719 |   "f = fps_shift (subdegree f) f * X ^ subdegree (f :: ('a :: comm_ring_1) fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 720 | by (rule fps_ext) (auto simp: X_power_mult_right_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 721 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 722 | lemma subdegree_decompose': | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 723 |   "n \<le> subdegree (f :: ('a :: comm_ring_1) fps) \<Longrightarrow> f = fps_shift n f * X^n"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 724 | by (rule fps_ext) (auto simp: X_power_mult_right_nth intro!: nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 725 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 726 | lemma fps_shift_fps_shift: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 727 | "fps_shift (m + n) f = fps_shift m (fps_shift n f)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 728 | by (rule fps_ext) (simp add: add_ac) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 729 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 730 | lemma fps_shift_add: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 731 | "fps_shift n (f + g) = fps_shift n f + fps_shift n g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 732 | by (simp add: fps_eq_iff) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 733 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 734 | lemma fps_shift_mult: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 735 |   assumes "n \<le> subdegree (g :: 'b :: {comm_ring_1} fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 736 | shows "fps_shift n (h*g) = h * fps_shift n g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 737 | proof - | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 738 | from assms have "g = fps_shift n g * X^n" by (rule subdegree_decompose') | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 739 | also have "h * ... = (h * fps_shift n g) * X^n" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 740 | also have "fps_shift n ... = h * fps_shift n g" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 741 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 742 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 743 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 744 | lemma fps_shift_mult_right: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 745 |   assumes "n \<le> subdegree (g :: 'b :: {comm_ring_1} fps)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 746 | shows "fps_shift n (g*h) = h * fps_shift n g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 747 | by (subst mult.commute, subst fps_shift_mult) (simp_all add: assms) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 748 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 749 | lemma nth_subdegree_zero_iff [simp]: "f $ subdegree f = 0 \<longleftrightarrow> f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 750 | by (cases "f = 0") auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 751 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 752 | lemma fps_shift_subdegree_zero_iff [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 753 | "fps_shift (subdegree f) f = 0 \<longleftrightarrow> f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 754 | by (subst (1) nth_subdegree_zero_iff[symmetric], cases "f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 755 | (simp_all del: nth_subdegree_zero_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 756 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 757 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 758 | definition "fps_cutoff n f = Abs_fps (\<lambda>i. if i < n then f$i else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 759 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 760 | lemma fps_cutoff_nth [simp]: "fps_cutoff n f $ i = (if i < n then f$i else 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 761 | unfolding fps_cutoff_def by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 762 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 763 | lemma fps_cutoff_zero_iff: "fps_cutoff n f = 0 \<longleftrightarrow> (f = 0 \<or> n \<le> subdegree f)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 764 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 765 | assume A: "fps_cutoff n f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 766 | thus "f = 0 \<or> n \<le> subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 767 | proof (cases "f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 768 | assume "f \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 769 | with A have "n \<le> subdegree f" | 
| 62390 | 770 | by (intro subdegree_geI) (auto simp: fps_eq_iff split: if_split_asm) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 771 | thus ?thesis .. | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 772 | qed simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 773 | qed (auto simp: fps_eq_iff intro: nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 774 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 775 | lemma fps_cutoff_0 [simp]: "fps_cutoff 0 f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 776 | by (simp add: fps_eq_iff) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 777 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 778 | lemma fps_cutoff_zero [simp]: "fps_cutoff n 0 = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 779 | by (simp add: fps_eq_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 780 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 781 | lemma fps_cutoff_one: "fps_cutoff n 1 = (if n = 0 then 0 else 1)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 782 | by (simp add: fps_eq_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 783 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 784 | lemma fps_cutoff_fps_const: "fps_cutoff n (fps_const c) = (if n = 0 then 0 else fps_const c)" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 785 | by (simp add: fps_eq_iff) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 786 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 787 | lemma fps_cutoff_numeral: "fps_cutoff n (numeral c) = (if n = 0 then 0 else numeral c)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 788 | by (simp add: numeral_fps_const fps_cutoff_fps_const) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 789 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 790 | lemma fps_shift_cutoff: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 791 |   "fps_shift n (f :: ('a :: comm_ring_1) fps) * X^n + fps_cutoff n f = f"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 792 | by (simp add: fps_eq_iff X_power_mult_right_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 793 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 794 | |
| 60501 | 795 | subsection \<open>Formal Power series form a metric space\<close> | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 796 | |
| 52902 | 797 | definition (in dist) "ball x r = {y. dist y x < r}"
 | 
| 48757 | 798 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 799 | instantiation fps :: (comm_ring_1) dist | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 800 | begin | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 801 | |
| 52891 | 802 | definition | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 803 | dist_fps_def: "dist (a :: 'a fps) b = (if a = b then 0 else inverse (2 ^ subdegree (a - b)))" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 804 | |
| 54681 | 805 | lemma dist_fps_ge0: "dist (a :: 'a fps) b \<ge> 0" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 806 | by (simp add: dist_fps_def) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 807 | |
| 54681 | 808 | lemma dist_fps_sym: "dist (a :: 'a fps) b = dist b a" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 809 | by (simp add: dist_fps_def) | 
| 48757 | 810 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 811 | instance .. | 
| 48757 | 812 | |
| 30746 | 813 | end | 
| 814 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 815 | instantiation fps :: (comm_ring_1) metric_space | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 816 | begin | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 817 | |
| 62101 | 818 | definition uniformity_fps_def [code del]: | 
| 819 |   "(uniformity :: ('a fps \<times> 'a fps) filter) = (INF e:{0 <..}. principal {(x, y). dist x y < e})"
 | |
| 820 | ||
| 821 | definition open_fps_def' [code del]: | |
| 822 | "open (U :: 'a fps set) \<longleftrightarrow> (\<forall>x\<in>U. eventually (\<lambda>(x', y). x' = x \<longrightarrow> y \<in> U) uniformity)" | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 823 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 824 | instance | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 825 | proof | 
| 60501 | 826 | show th: "dist a b = 0 \<longleftrightarrow> a = b" for a b :: "'a fps" | 
| 62390 | 827 | by (simp add: dist_fps_def split: if_split_asm) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 828 | then have th'[simp]: "dist a a = 0" for a :: "'a fps" by simp | 
| 60501 | 829 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 830 | fix a b c :: "'a fps" | 
| 60501 | 831 | consider "a = b" | "c = a \<or> c = b" | "a \<noteq> b" "a \<noteq> c" "b \<noteq> c" by blast | 
| 832 | then show "dist a b \<le> dist a c + dist b c" | |
| 833 | proof cases | |
| 834 | case 1 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 835 | then show ?thesis by (simp add: dist_fps_def) | 
| 60501 | 836 | next | 
| 837 | case 2 | |
| 838 | then show ?thesis | |
| 52891 | 839 | by (cases "c = a") (simp_all add: th dist_fps_sym) | 
| 60501 | 840 | next | 
| 60567 | 841 | case neq: 3 | 
| 60558 | 842 | have False if "dist a b > dist a c + dist b c" | 
| 843 | proof - | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 844 | let ?n = "subdegree (a - b)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 845 | from neq have "dist a b > 0" "dist b c > 0" and "dist a c > 0" by (simp_all add: dist_fps_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 846 | with that have "dist a b > dist a c" and "dist a b > dist b c" by simp_all | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 847 | with neq have "?n < subdegree (a - c)" and "?n < subdegree (b - c)" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 848 | by (simp_all add: dist_fps_def field_simps) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 849 | hence "(a - c) $ ?n = 0" and "(b - c) $ ?n = 0" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 850 | by (simp_all only: nth_less_subdegree_zero) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 851 | hence "(a - b) $ ?n = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 852 | moreover from neq have "(a - b) $ ?n \<noteq> 0" by (intro nth_subdegree_nonzero) simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 853 | ultimately show False by contradiction | 
| 60558 | 854 | qed | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 855 | thus ?thesis by (auto simp add: not_le[symmetric]) | 
| 60501 | 856 | qed | 
| 62101 | 857 | qed (rule open_fps_def' uniformity_fps_def)+ | 
| 52891 | 858 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 859 | end | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 860 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 861 | declare uniformity_Abort[where 'a="'a :: comm_ring_1 fps", code] | 
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 862 | |
| 62101 | 863 | lemma open_fps_def: "open (S :: 'a::comm_ring_1 fps set) = (\<forall>a \<in> S. \<exists>r. r >0 \<and> ball a r \<subseteq> S)" | 
| 864 | unfolding open_dist ball_def subset_eq by simp | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 865 | |
| 60558 | 866 | text \<open>The infinite sums and justification of the notation in textbooks.\<close> | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 867 | |
| 52891 | 868 | lemma reals_power_lt_ex: | 
| 54681 | 869 | fixes x y :: real | 
| 870 | assumes xp: "x > 0" | |
| 871 | and y1: "y > 1" | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 872 | shows "\<exists>k>0. (1/y)^k < x" | 
| 52891 | 873 | proof - | 
| 54681 | 874 | have yp: "y > 0" | 
| 875 | using y1 by simp | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 876 | from reals_Archimedean2[of "max 0 (- log y x) + 1"] | 
| 54681 | 877 | obtain k :: nat where k: "real k > max 0 (- log y x) + 1" | 
| 878 | by blast | |
| 879 | from k have kp: "k > 0" | |
| 880 | by simp | |
| 881 | from k have "real k > - log y x" | |
| 882 | by simp | |
| 883 | then have "ln y * real k > - ln x" | |
| 884 | unfolding log_def | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 885 | using ln_gt_zero_iff[OF yp] y1 | 
| 54681 | 886 | by (simp add: minus_divide_left field_simps del: minus_divide_left[symmetric]) | 
| 887 | then have "ln y * real k + ln x > 0" | |
| 888 | by simp | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 889 | then have "exp (real k * ln y + ln x) > exp 0" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 890 | by (simp add: ac_simps) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 891 | then have "y ^ k * x > 1" | 
| 52891 | 892 | unfolding exp_zero exp_add exp_real_of_nat_mult exp_ln [OF xp] exp_ln [OF yp] | 
| 893 | by simp | |
| 894 | then have "x > (1 / y)^k" using yp | |
| 60867 | 895 | by (simp add: field_simps) | 
| 54681 | 896 | then show ?thesis | 
| 897 | using kp by blast | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 898 | qed | 
| 52891 | 899 | |
| 54452 | 900 | lemma fps_sum_rep_nth: "(setsum (\<lambda>i. fps_const(a$i)*X^i) {0..m})$n =
 | 
| 54681 | 901 | (if n \<le> m then a$n else 0::'a::comm_ring_1)" | 
| 52891 | 902 | apply (auto simp add: fps_setsum_nth cond_value_iff cong del: if_weak_cong) | 
| 57418 | 903 | apply (simp add: setsum.delta') | 
| 48757 | 904 | done | 
| 52891 | 905 | |
| 61969 | 906 | lemma fps_notation: "(\<lambda>n. setsum (\<lambda>i. fps_const(a$i) * X^i) {0..n}) \<longlonglongrightarrow> a"
 | 
| 907 | (is "?s \<longlonglongrightarrow> a") | |
| 52891 | 908 | proof - | 
| 60558 | 909 | have "\<exists>n0. \<forall>n \<ge> n0. dist (?s n) a < r" if "r > 0" for r | 
| 910 | proof - | |
| 60501 | 911 | obtain n0 where n0: "(1/2)^n0 < r" "n0 > 0" | 
| 912 | using reals_power_lt_ex[OF \<open>r > 0\<close>, of 2] by auto | |
| 60558 | 913 | show ?thesis | 
| 60501 | 914 | proof - | 
| 60558 | 915 | have "dist (?s n) a < r" if nn0: "n \<ge> n0" for n | 
| 916 | proof - | |
| 917 | from that have thnn0: "(1/2)^n \<le> (1/2 :: real)^n0" | |
| 60501 | 918 | by (simp add: divide_simps) | 
| 60558 | 919 | show ?thesis | 
| 60501 | 920 | proof (cases "?s n = a") | 
| 921 | case True | |
| 922 | then show ?thesis | |
| 923 | unfolding dist_eq_0_iff[of "?s n" a, symmetric] | |
| 924 | using \<open>r > 0\<close> by (simp del: dist_eq_0_iff) | |
| 925 | next | |
| 926 | case False | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 927 | from False have dth: "dist (?s n) a = (1/2)^subdegree (?s n - a)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 928 | by (simp add: dist_fps_def field_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 929 | from False have kn: "subdegree (?s n - a) > n" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 930 | by (intro subdegree_greaterI) (simp_all add: fps_sum_rep_nth) | 
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 931 | then have "dist (?s n) a < (1/2)^n" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 932 | by (simp add: field_simps dist_fps_def) | 
| 60501 | 933 | also have "\<dots> \<le> (1/2)^n0" | 
| 934 | using nn0 by (simp add: divide_simps) | |
| 935 | also have "\<dots> < r" | |
| 936 | using n0 by simp | |
| 937 | finally show ?thesis . | |
| 938 | qed | |
| 60558 | 939 | qed | 
| 60501 | 940 | then show ?thesis by blast | 
| 941 | qed | |
| 60558 | 942 | qed | 
| 54681 | 943 | then show ?thesis | 
| 60017 
b785d6d06430
Overloading of ln and powr, but "approximation" no longer works for powr. Code generation also fails due to type ambiguity in scala.
 paulson <lp15@cam.ac.uk> parents: 
59867diff
changeset | 944 | unfolding lim_sequentially by blast | 
| 52891 | 945 | qed | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 946 | |
| 54681 | 947 | |
| 60501 | 948 | subsection \<open>Inverses of formal power series\<close> | 
| 29687 | 949 | |
| 57418 | 950 | declare setsum.cong[fundef_cong] | 
| 29687 | 951 | |
| 60558 | 952 | instantiation fps :: ("{comm_monoid_add,inverse,times,uminus}") inverse
 | 
| 29687 | 953 | begin | 
| 954 | ||
| 52891 | 955 | fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" | 
| 956 | where | |
| 29687 | 957 | "natfun_inverse f 0 = inverse (f$0)" | 
| 30488 | 958 | | "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}"
 | 
| 29687 | 959 | |
| 60501 | 960 | definition fps_inverse_def: "inverse f = (if f $ 0 = 0 then 0 else Abs_fps (natfun_inverse f))" | 
| 961 | ||
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 962 | definition fps_divide_def: | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 963 | "f div g = (if g = 0 then 0 else | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 964 | let n = subdegree g; h = fps_shift n g | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 965 | in fps_shift n (f * inverse h))" | 
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 966 | |
| 29687 | 967 | instance .. | 
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 968 | |
| 29687 | 969 | end | 
| 970 | ||
| 52891 | 971 | lemma fps_inverse_zero [simp]: | 
| 54681 | 972 |   "inverse (0 :: 'a::{comm_monoid_add,inverse,times,uminus} fps) = 0"
 | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 973 | by (simp add: fps_ext fps_inverse_def) | 
| 29687 | 974 | |
| 52891 | 975 | lemma fps_inverse_one [simp]: "inverse (1 :: 'a::{division_ring,zero_neq_one} fps) = 1"
 | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 976 | apply (auto simp add: expand_fps_eq fps_inverse_def) | 
| 52891 | 977 | apply (case_tac n) | 
| 978 | apply auto | |
| 979 | done | |
| 980 | ||
| 981 | lemma inverse_mult_eq_1 [intro]: | |
| 982 | assumes f0: "f$0 \<noteq> (0::'a::field)" | |
| 29687 | 983 | shows "inverse f * f = 1" | 
| 52891 | 984 | proof - | 
| 54681 | 985 | have c: "inverse f * f = f * inverse f" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 986 | by (simp add: mult.commute) | 
| 30488 | 987 | from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n" | 
| 29687 | 988 | by (simp add: fps_inverse_def) | 
| 989 | from f0 have th0: "(inverse f * f) $ 0 = 1" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 990 | by (simp add: fps_mult_nth fps_inverse_def) | 
| 60501 | 991 | have "(inverse f * f)$n = 0" if np: "n > 0" for n | 
| 992 | proof - | |
| 54681 | 993 |     from np have eq: "{0..n} = {0} \<union> {1 .. n}"
 | 
| 994 | by auto | |
| 995 |     have d: "{0} \<inter> {1 .. n} = {}"
 | |
| 996 | by auto | |
| 52891 | 997 | from f0 np have th0: "- (inverse f $ n) = | 
| 29687 | 998 |       (setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}) / (f$0)"
 | 
| 52891 | 999 | by (cases n) (simp_all add: divide_inverse fps_inverse_def) | 
| 29687 | 1000 | from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]] | 
| 52891 | 1001 |     have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} = - (f$0) * (inverse f)$n"
 | 
| 36350 | 1002 | by (simp add: field_simps) | 
| 30488 | 1003 | have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))" | 
| 29687 | 1004 | unfolding fps_mult_nth ifn .. | 
| 52891 | 1005 | also have "\<dots> = f$0 * natfun_inverse f n + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))" | 
| 46757 | 1006 | by (simp add: eq) | 
| 54681 | 1007 | also have "\<dots> = 0" | 
| 1008 | unfolding th1 ifn by simp | |
| 60501 | 1009 | finally show ?thesis unfolding c . | 
| 1010 | qed | |
| 54681 | 1011 | with th0 show ?thesis | 
| 1012 | by (simp add: fps_eq_iff) | |
| 29687 | 1013 | qed | 
| 1014 | ||
| 60501 | 1015 | lemma fps_inverse_0_iff[simp]: "(inverse f) $ 0 = (0::'a::division_ring) \<longleftrightarrow> f $ 0 = 0" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 1016 | by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1017 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1018 | lemma fps_inverse_nth_0 [simp]: "inverse f $ 0 = inverse (f $ 0 :: 'a :: division_ring)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1019 | by (simp add: fps_inverse_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1020 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1021 | lemma fps_inverse_eq_0_iff[simp]: "inverse f = (0:: ('a::division_ring) fps) \<longleftrightarrow> f $ 0 = 0"
 | 
| 60501 | 1022 | proof | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1023 | assume A: "inverse f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1024 | have "0 = inverse f $ 0" by (subst A) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1025 | thus "f $ 0 = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1026 | qed (simp add: fps_inverse_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1027 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1028 | lemma fps_inverse_idempotent[intro, simp]: | 
| 48757 | 1029 | assumes f0: "f$0 \<noteq> (0::'a::field)" | 
| 29687 | 1030 | shows "inverse (inverse f) = f" | 
| 52891 | 1031 | proof - | 
| 29687 | 1032 | from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp | 
| 30488 | 1033 | from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0] | 
| 52891 | 1034 | have "inverse f * f = inverse f * inverse (inverse f)" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 1035 | by (simp add: ac_simps) | 
| 54681 | 1036 | then show ?thesis | 
| 1037 | using f0 unfolding mult_cancel_left by simp | |
| 29687 | 1038 | qed | 
| 1039 | ||
| 48757 | 1040 | lemma fps_inverse_unique: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1041 | assumes fg: "(f :: 'a :: field fps) * g = 1" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1042 | shows "inverse f = g" | 
| 52891 | 1043 | proof - | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1044 | have f0: "f $ 0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1045 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1046 | assume "f $ 0 = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1047 | hence "0 = (f * g) $ 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1048 | also from fg have "(f * g) $ 0 = 1" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1049 | finally show False by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1050 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1051 | from inverse_mult_eq_1[OF this] fg | 
| 54681 | 1052 | have th0: "inverse f * f = g * f" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 1053 | by (simp add: ac_simps) | 
| 54681 | 1054 | then show ?thesis | 
| 1055 | using f0 | |
| 1056 | unfolding mult_cancel_right | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 1057 | by (auto simp add: expand_fps_eq) | 
| 29687 | 1058 | qed | 
| 1059 | ||
| 60162 | 1060 | lemma setsum_zero_lemma: | 
| 1061 | fixes n::nat | |
| 1062 | assumes "0 < n" | |
| 1063 | shows "(\<Sum>i = 0..n. if n = i then 1 else if n - i = 1 then - 1 else 0) = (0::'a::field)" | |
| 54681 | 1064 | proof - | 
| 60162 | 1065 | let ?f = "\<lambda>i. if n = i then 1 else if n - i = 1 then - 1 else 0" | 
| 1066 | let ?g = "\<lambda>i. if i = n then 1 else if i = n - 1 then - 1 else 0" | |
| 29687 | 1067 | let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0" | 
| 30488 | 1068 |   have th1: "setsum ?f {0..n} = setsum ?g {0..n}"
 | 
| 57418 | 1069 | by (rule setsum.cong) auto | 
| 30488 | 1070 |   have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"
 | 
| 57418 | 1071 | apply (rule setsum.cong) | 
| 60162 | 1072 | using assms | 
| 54681 | 1073 | apply auto | 
| 1074 | done | |
| 1075 |   have eq: "{0 .. n} = {0.. n - 1} \<union> {n}"
 | |
| 1076 | by auto | |
| 60162 | 1077 |   from assms have d: "{0.. n - 1} \<inter> {n} = {}"
 | 
| 54681 | 1078 | by auto | 
| 1079 |   have f: "finite {0.. n - 1}" "finite {n}"
 | |
| 1080 | by auto | |
| 60162 | 1081 | show ?thesis | 
| 30488 | 1082 | unfolding th1 | 
| 57418 | 1083 | apply (simp add: setsum.union_disjoint[OF f d, unfolded eq[symmetric]] del: One_nat_def) | 
| 29687 | 1084 | unfolding th2 | 
| 57418 | 1085 | apply (simp add: setsum.delta) | 
| 52891 | 1086 | done | 
| 29687 | 1087 | qed | 
| 1088 | ||
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1089 | lemma fps_inverse_mult: "inverse (f * g :: 'a::field fps) = inverse f * inverse g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1090 | proof (cases "f$0 = 0 \<or> g$0 = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1091 | assume "\<not>(f$0 = 0 \<or> g$0 = 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1092 | hence [simp]: "f$0 \<noteq> 0" "g$0 \<noteq> 0" by simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1093 | show ?thesis | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1094 | proof (rule fps_inverse_unique) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1095 | have "f * g * (inverse f * inverse g) = (inverse f * f) * (inverse g * g)" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1096 | also have "... = 1" by (subst (1 2) inverse_mult_eq_1) simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1097 | finally show "f * g * (inverse f * inverse g) = 1" . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1098 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1099 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1100 | assume A: "f$0 = 0 \<or> g$0 = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1101 | hence "inverse (f * g) = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1102 | also from A have "... = inverse f * inverse g" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1103 | finally show "inverse (f * g) = inverse f * inverse g" . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1104 | qed | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1105 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1106 | |
| 60501 | 1107 | lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) = | 
| 1108 | Abs_fps (\<lambda>n. if n= 0 then 1 else if n=1 then - 1 else 0)" | |
| 60162 | 1109 | apply (rule fps_inverse_unique) | 
| 1110 | apply (simp_all add: fps_eq_iff fps_mult_nth setsum_zero_lemma) | |
| 1111 | done | |
| 1112 | ||
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1113 | lemma subdegree_inverse [simp]: "subdegree (inverse (f::'a::field fps)) = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1114 | proof (cases "f$0 = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1115 | assume nz: "f$0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1116 | hence "subdegree (inverse f) + subdegree f = subdegree (inverse f * f)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1117 | by (subst subdegree_mult) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1118 | also from nz have "subdegree f = 0" by (simp add: subdegree_eq_0_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1119 | also from nz have "inverse f * f = 1" by (rule inverse_mult_eq_1) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1120 | finally show "subdegree (inverse f) = 0" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1121 | qed (simp_all add: fps_inverse_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1122 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1123 | lemma fps_is_unit_iff [simp]: "(f :: 'a :: field fps) dvd 1 \<longleftrightarrow> f $ 0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1124 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1125 | assume "f dvd 1" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1126 | then obtain g where "1 = f * g" by (elim dvdE) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1127 | from this[symmetric] have "(f*g) $ 0 = 1" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1128 | thus "f $ 0 \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1129 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1130 | assume A: "f $ 0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1131 | thus "f dvd 1" by (simp add: inverse_mult_eq_1[OF A, symmetric]) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1132 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1133 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1134 | lemma subdegree_eq_0' [simp]: "(f :: 'a :: field fps) dvd 1 \<Longrightarrow> subdegree f = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1135 | by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1136 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1137 | lemma fps_unit_dvd [simp]: "(f $ 0 :: 'a :: field) \<noteq> 0 \<Longrightarrow> f dvd g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1138 | by (rule dvd_trans, subst fps_is_unit_iff) simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1139 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1140 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1141 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1142 | instantiation fps :: (field) ring_div | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1143 | begin | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1144 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1145 | definition fps_mod_def: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1146 | "f mod g = (if g = 0 then f else | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1147 | let n = subdegree g; h = fps_shift n g | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1148 | in fps_cutoff n (f * inverse h) * h)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1149 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1150 | lemma fps_mod_eq_zero: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1151 | assumes "g \<noteq> 0" and "subdegree f \<ge> subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1152 | shows "f mod g = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1153 | using assms by (cases "f = 0") (auto simp: fps_cutoff_zero_iff fps_mod_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1154 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1155 | lemma fps_times_divide_eq: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1156 | assumes "g \<noteq> 0" and "subdegree f \<ge> subdegree (g :: 'a fps)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1157 | shows "f div g * g = f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1158 | proof (cases "f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1159 | assume nz: "f \<noteq> 0" | 
| 63040 | 1160 | define n where "n = subdegree g" | 
| 1161 | define h where "h = fps_shift n g" | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1162 | from assms have [simp]: "h $ 0 \<noteq> 0" unfolding h_def by (simp add: n_def) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1163 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1164 | from assms nz have "f div g * g = fps_shift n (f * inverse h) * g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1165 | by (simp add: fps_divide_def Let_def h_def n_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1166 | also have "... = fps_shift n (f * inverse h) * X^n * h" unfolding h_def n_def | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1167 | by (subst subdegree_decompose[of g]) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1168 | also have "fps_shift n (f * inverse h) * X^n = f * inverse h" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1169 | by (rule fps_shift_times_X_power) (simp_all add: nz assms n_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1170 | also have "... * h = f * (inverse h * h)" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1171 | also have "inverse h * h = 1" by (rule inverse_mult_eq_1) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1172 | finally show ?thesis by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1173 | qed (simp_all add: fps_divide_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1174 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1175 | lemma | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1176 | assumes "g$0 \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1177 | shows fps_divide_unit: "f div g = f * inverse g" and fps_mod_unit [simp]: "f mod g = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1178 | proof - | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1179 | from assms have [simp]: "subdegree g = 0" by (simp add: subdegree_eq_0_iff) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1180 | from assms show "f div g = f * inverse g" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1181 | by (auto simp: fps_divide_def Let_def subdegree_eq_0_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1182 | from assms show "f mod g = 0" by (intro fps_mod_eq_zero) auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1183 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1184 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1185 | context | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1186 | begin | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1187 | private lemma fps_divide_cancel_aux1: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1188 | assumes "h$0 \<noteq> (0 :: 'a :: field)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1189 | shows "(h * f) div (h * g) = f div g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1190 | proof (cases "g = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1191 | assume "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1192 | from assms have "h \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1193 | note nz [simp] = \<open>g \<noteq> 0\<close> \<open>h \<noteq> 0\<close> | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1194 | from assms have [simp]: "subdegree h = 0" by (simp add: subdegree_eq_0_iff) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1195 | |
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1196 | have "(h * f) div (h * g) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1197 | fps_shift (subdegree g) (h * f * inverse (fps_shift (subdegree g) (h*g)))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1198 | by (simp add: fps_divide_def Let_def) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1199 | also have "h * f * inverse (fps_shift (subdegree g) (h*g)) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1200 | (inverse h * h) * f * inverse (fps_shift (subdegree g) g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1201 | by (subst fps_shift_mult) (simp_all add: algebra_simps fps_inverse_mult) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1202 | also from assms have "inverse h * h = 1" by (rule inverse_mult_eq_1) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1203 | finally show "(h * f) div (h * g) = f div g" by (simp_all add: fps_divide_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1204 | qed (simp_all add: fps_divide_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1205 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1206 | private lemma fps_divide_cancel_aux2: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1207 | "(f * X^m) div (g * X^m) = f div (g :: 'a :: field fps)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1208 | proof (cases "g = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1209 | assume [simp]: "g \<noteq> 0" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1210 | have "(f * X^m) div (g * X^m) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1211 | fps_shift (subdegree g + m) (f*inverse (fps_shift (subdegree g + m) (g*X^m))*X^m)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1212 | by (simp add: fps_divide_def Let_def algebra_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1213 | also have "... = f div g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1214 | by (simp add: fps_shift_times_X_power'' fps_divide_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1215 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1216 | qed (simp_all add: fps_divide_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1217 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1218 | instance proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1219 | fix f g :: "'a fps" | 
| 63040 | 1220 | define n where "n = subdegree g" | 
| 1221 | define h where "h = fps_shift n g" | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1222 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1223 | show "f div g * g + f mod g = f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1224 | proof (cases "g = 0 \<or> f = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1225 | assume "\<not>(g = 0 \<or> f = 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1226 | hence nz [simp]: "f \<noteq> 0" "g \<noteq> 0" by simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1227 | show ?thesis | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1228 | proof (rule disjE[OF le_less_linear]) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1229 | assume "subdegree f \<ge> subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1230 | with nz show ?thesis by (simp add: fps_mod_eq_zero fps_times_divide_eq) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1231 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1232 | assume "subdegree f < subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1233 | have g_decomp: "g = h * X^n" unfolding h_def n_def by (rule subdegree_decompose) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1234 | have "f div g * g + f mod g = | 
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1235 | fps_shift n (f * inverse h) * g + fps_cutoff n (f * inverse h) * h" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1236 | by (simp add: fps_mod_def fps_divide_def Let_def n_def h_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1237 | also have "... = h * (fps_shift n (f * inverse h) * X^n + fps_cutoff n (f * inverse h))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1238 | by (subst g_decomp) (simp add: algebra_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1239 | also have "... = f * (inverse h * h)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1240 | by (subst fps_shift_cutoff) simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1241 | also have "inverse h * h = 1" by (rule inverse_mult_eq_1) (simp add: h_def n_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1242 | finally show ?thesis by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1243 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1244 | qed (auto simp: fps_mod_def fps_divide_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1245 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1246 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1247 | fix f g h :: "'a fps" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1248 | assume "h \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1249 | show "(h * f) div (h * g) = f div g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1250 | proof - | 
| 63040 | 1251 | define m where "m = subdegree h" | 
| 1252 | define h' where "h' = fps_shift m h" | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1253 | have h_decomp: "h = h' * X ^ m" unfolding h'_def m_def by (rule subdegree_decompose) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1254 | from \<open>h \<noteq> 0\<close> have [simp]: "h'$0 \<noteq> 0" by (simp add: h'_def m_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1255 | have "(h * f) div (h * g) = (h' * f * X^m) div (h' * g * X^m)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1256 | by (simp add: h_decomp algebra_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1257 | also have "... = f div g" by (simp add: fps_divide_cancel_aux1 fps_divide_cancel_aux2) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1258 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1259 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1260 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1261 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1262 | fix f g h :: "'a fps" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1263 | assume [simp]: "h \<noteq> 0" | 
| 63040 | 1264 | define n h' where dfs: "n = subdegree h" "h' = fps_shift n h" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1265 | have "(f + g * h) div h = fps_shift n (f * inverse h') + fps_shift n (g * (h * inverse h'))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1266 | by (simp add: fps_divide_def Let_def dfs[symmetric] algebra_simps fps_shift_add) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1267 | also have "h * inverse h' = (inverse h' * h') * X^n" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1268 | by (subst subdegree_decompose) (simp_all add: dfs) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1269 | also have "... = X^n" by (subst inverse_mult_eq_1) (simp_all add: dfs) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1270 | also have "fps_shift n (g * X^n) = g" by simp | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1271 | also have "fps_shift n (f * inverse h') = f div h" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1272 | by (simp add: fps_divide_def Let_def dfs) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1273 | finally show "(f + g * h) div h = g + f div h" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1274 | qed (auto simp: fps_divide_def fps_mod_def Let_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1275 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1276 | end | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1277 | end | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1278 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1279 | lemma subdegree_mod: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1280 | assumes "f \<noteq> 0" "subdegree f < subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1281 | shows "subdegree (f mod g) = subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1282 | proof (cases "f div g * g = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1283 | assume "f div g * g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1284 | hence [simp]: "f div g \<noteq> 0" "g \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1285 | from mod_div_equality[of f g] have "f mod g = f - f div g * g" by (simp add: algebra_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1286 | also from assms have "subdegree ... = subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1287 | by (intro subdegree_diff_eq1) simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1288 | finally show ?thesis . | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1289 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1290 | assume zero: "f div g * g = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1291 | from mod_div_equality[of f g] have "f mod g = f - f div g * g" by (simp add: algebra_simps) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1292 | also note zero | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1293 | finally show ?thesis by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1294 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1295 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1296 | lemma fps_divide_nth_0 [simp]: "g $ 0 \<noteq> 0 \<Longrightarrow> (f div g) $ 0 = f $ 0 / (g $ 0 :: _ :: field)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1297 | by (simp add: fps_divide_unit divide_inverse) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1298 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1299 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1300 | lemma dvd_imp_subdegree_le: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1301 | "(f :: 'a :: idom fps) dvd g \<Longrightarrow> g \<noteq> 0 \<Longrightarrow> subdegree f \<le> subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1302 | by (auto elim: dvdE) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1303 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1304 | lemma fps_dvd_iff: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1305 | assumes "(f :: 'a :: field fps) \<noteq> 0" "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1306 | shows "f dvd g \<longleftrightarrow> subdegree f \<le> subdegree g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1307 | proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1308 | assume "subdegree f \<le> subdegree g" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1309 | with assms have "g mod f = 0" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1310 | by (simp add: fps_mod_def Let_def fps_cutoff_zero_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1311 | thus "f dvd g" by (simp add: dvd_eq_mod_eq_0) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1312 | qed (simp add: assms dvd_imp_subdegree_le) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1313 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1314 | lemma fps_const_inverse: "inverse (fps_const (a::'a::field)) = fps_const (inverse a)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1315 | by (cases "a \<noteq> 0", rule fps_inverse_unique) (auto simp: fps_eq_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1316 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1317 | lemma fps_const_divide: "fps_const (x :: _ :: field) / fps_const y = fps_const (x / y)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1318 | by (cases "y = 0") (simp_all add: fps_divide_unit fps_const_inverse divide_inverse) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1319 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1320 | lemma inverse_fps_numeral: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1321 |   "inverse (numeral n :: ('a :: field_char_0) fps) = fps_const (inverse (numeral n))"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1322 | by (intro fps_inverse_unique fps_ext) (simp_all add: fps_numeral_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1323 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1324 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1325 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1326 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1327 | instantiation fps :: (field) normalization_semidom | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1328 | begin | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1329 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1330 | definition fps_unit_factor_def [simp]: | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1331 | "unit_factor f = fps_shift (subdegree f) f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1332 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1333 | definition fps_normalize_def [simp]: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1334 | "normalize f = (if f = 0 then 0 else X ^ subdegree f)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1335 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1336 | instance proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1337 | fix f :: "'a fps" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1338 | show "unit_factor f * normalize f = f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1339 | by (simp add: fps_shift_times_X_power) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1340 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1341 | fix f g :: "'a fps" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1342 | show "unit_factor (f * g) = unit_factor f * unit_factor g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1343 | proof (cases "f = 0 \<or> g = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1344 | assume "\<not>(f = 0 \<or> g = 0)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1345 | thus "unit_factor (f * g) = unit_factor f * unit_factor g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1346 | unfolding fps_unit_factor_def | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1347 | by (auto simp: fps_shift_fps_shift fps_shift_mult fps_shift_mult_right) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1348 | qed auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1349 | qed auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1350 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1351 | end | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1352 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1353 | instance fps :: (field) algebraic_semidom .. | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1354 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1355 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1356 | subsection \<open>Formal power series form a Euclidean ring\<close> | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1357 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1358 | instantiation fps :: (field) euclidean_ring | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1359 | begin | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1360 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1361 | definition fps_euclidean_size_def: | 
| 62422 | 1362 | "euclidean_size f = (if f = 0 then 0 else 2 ^ subdegree f)" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1363 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1364 | instance proof | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1365 | fix f g :: "'a fps" assume [simp]: "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1366 | show "euclidean_size f \<le> euclidean_size (f * g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1367 | by (cases "f = 0") (auto simp: fps_euclidean_size_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1368 | show "euclidean_size (f mod g) < euclidean_size g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1369 | apply (cases "f = 0", simp add: fps_euclidean_size_def) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1370 | apply (rule disjE[OF le_less_linear[of "subdegree g" "subdegree f"]]) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1371 | apply (simp_all add: fps_mod_eq_zero fps_euclidean_size_def subdegree_mod) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1372 | done | 
| 62422 | 1373 | qed (simp_all add: fps_euclidean_size_def) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1374 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1375 | end | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1376 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1377 | instantiation fps :: (field) euclidean_ring_gcd | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1378 | begin | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1379 | definition fps_gcd_def: "(gcd :: 'a fps \<Rightarrow> _) = gcd_eucl" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1380 | definition fps_lcm_def: "(lcm :: 'a fps \<Rightarrow> _) = lcm_eucl" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1381 | definition fps_Gcd_def: "(Gcd :: 'a fps set \<Rightarrow> _) = Gcd_eucl" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1382 | definition fps_Lcm_def: "(Lcm :: 'a fps set \<Rightarrow> _) = Lcm_eucl" | 
| 62422 | 1383 | instance by standard (simp_all add: fps_gcd_def fps_lcm_def fps_Gcd_def fps_Lcm_def) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1384 | end | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1385 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1386 | lemma fps_gcd: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1387 | assumes [simp]: "f \<noteq> 0" "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1388 | shows "gcd f g = X ^ min (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1389 | proof - | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1390 | let ?m = "min (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1391 | show "gcd f g = X ^ ?m" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1392 | proof (rule sym, rule gcdI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1393 | fix d assume "d dvd f" "d dvd g" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1394 | thus "d dvd X ^ ?m" by (cases "d = 0") (auto simp: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1395 | qed (simp_all add: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1396 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1397 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1398 | lemma fps_gcd_altdef: "gcd (f :: 'a :: field fps) g = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1399 | (if f = 0 \<and> g = 0 then 0 else | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1400 | if f = 0 then X ^ subdegree g else | 
| 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1401 | if g = 0 then X ^ subdegree f else | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1402 | X ^ min (subdegree f) (subdegree g))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1403 | by (simp add: fps_gcd) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1404 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1405 | lemma fps_lcm: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1406 | assumes [simp]: "f \<noteq> 0" "g \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1407 | shows "lcm f g = X ^ max (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1408 | proof - | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1409 | let ?m = "max (subdegree f) (subdegree g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1410 | show "lcm f g = X ^ ?m" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1411 | proof (rule sym, rule lcmI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1412 | fix d assume "f dvd d" "g dvd d" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1413 | thus "X ^ ?m dvd d" by (cases "d = 0") (auto simp: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1414 | qed (simp_all add: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1415 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1416 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1417 | lemma fps_lcm_altdef: "lcm (f :: 'a :: field fps) g = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1418 | (if f = 0 \<or> g = 0 then 0 else X ^ max (subdegree f) (subdegree g))" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1419 | by (simp add: fps_lcm) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1420 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1421 | lemma fps_Gcd: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1422 |   assumes "A - {0} \<noteq> {}"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1423 |   shows   "Gcd A = X ^ (INF f:A-{0}. subdegree f)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1424 | proof (rule sym, rule GcdI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1425 | fix f assume "f \<in> A" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1426 |   thus "X ^ (INF f:A - {0}. subdegree f) dvd f"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1427 | by (cases "f = 0") (auto simp: fps_dvd_iff intro!: cINF_lower) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1428 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1429 | fix d assume d: "\<And>f. f \<in> A \<Longrightarrow> d dvd f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1430 |   from assms obtain f where "f \<in> A - {0}" by auto
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1431 | with d[of f] have [simp]: "d \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1432 |   from d assms have "subdegree d \<le> (INF f:A-{0}. subdegree f)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1433 | by (intro cINF_greatest) (auto simp: fps_dvd_iff[symmetric]) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1434 |   with d assms show "d dvd X ^ (INF f:A-{0}. subdegree f)" by (simp add: fps_dvd_iff)
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1435 | qed simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1436 | |
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1437 | lemma fps_Gcd_altdef: "Gcd (A :: 'a :: field fps set) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1438 |   (if A \<subseteq> {0} then 0 else X ^ (INF f:A-{0}. subdegree f))"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1439 | using fps_Gcd by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1440 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1441 | lemma fps_Lcm: | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1442 |   assumes "A \<noteq> {}" "0 \<notin> A" "bdd_above (subdegree`A)"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1443 | shows "Lcm A = X ^ (SUP f:A. subdegree f)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1444 | proof (rule sym, rule LcmI) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1445 | fix f assume "f \<in> A" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1446 | moreover from assms(3) have "bdd_above (subdegree ` A)" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1447 | ultimately show "f dvd X ^ (SUP f:A. subdegree f)" using assms(2) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1448 | by (cases "f = 0") (auto simp: fps_dvd_iff intro!: cSUP_upper) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1449 | next | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1450 | fix d assume d: "\<And>f. f \<in> A \<Longrightarrow> f dvd d" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1451 | from assms obtain f where f: "f \<in> A" "f \<noteq> 0" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1452 | show "X ^ (SUP f:A. subdegree f) dvd d" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1453 | proof (cases "d = 0") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1454 | assume "d \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1455 | moreover from d have "\<And>f. f \<in> A \<Longrightarrow> f \<noteq> 0 \<Longrightarrow> f dvd d" by blast | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1456 | ultimately have "subdegree d \<ge> (SUP f:A. subdegree f)" using assms | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1457 | by (intro cSUP_least) (auto simp: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1458 | with \<open>d \<noteq> 0\<close> show ?thesis by (simp add: fps_dvd_iff) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1459 | qed simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1460 | qed simp_all | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1461 | |
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1462 | lemma fps_Lcm_altdef: | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 1463 | "Lcm (A :: 'a :: field fps set) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1464 | (if 0 \<in> A \<or> \<not>bdd_above (subdegree`A) then 0 else | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1465 |       if A = {} then 1 else X ^ (SUP f:A. subdegree f))"
 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1466 | proof (cases "bdd_above (subdegree`A)") | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1467 | assume unbounded: "\<not>bdd_above (subdegree`A)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1468 | have "Lcm A = 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1469 | proof (rule ccontr) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1470 | assume "Lcm A \<noteq> 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1471 | from unbounded obtain f where f: "f \<in> A" "subdegree (Lcm A) < subdegree f" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1472 | unfolding bdd_above_def by (auto simp: not_le) | 
| 61799 | 1473 | moreover from this and \<open>Lcm A \<noteq> 0\<close> have "subdegree f \<le> subdegree (Lcm A)" | 
| 62422 | 1474 | by (intro dvd_imp_subdegree_le dvd_Lcm) simp_all | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1475 | ultimately show False by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1476 | qed | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1477 | with unbounded show ?thesis by simp | 
| 62422 | 1478 | qed (simp_all add: fps_Lcm Lcm_eq_0_I) | 
| 1479 | ||
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1480 | |
| 54681 | 1481 | |
| 60500 | 1482 | subsection \<open>Formal Derivatives, and the MacLaurin theorem around 0\<close> | 
| 29687 | 1483 | |
| 1484 | definition "fps_deriv f = Abs_fps (\<lambda>n. of_nat (n + 1) * f $ (n + 1))" | |
| 1485 | ||
| 54681 | 1486 | lemma fps_deriv_nth[simp]: "fps_deriv f $ n = of_nat (n +1) * f $ (n + 1)" | 
| 48757 | 1487 | by (simp add: fps_deriv_def) | 
| 1488 | ||
| 1489 | lemma fps_deriv_linear[simp]: | |
| 1490 | "fps_deriv (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = | |
| 1491 | fps_const a * fps_deriv f + fps_const b * fps_deriv g" | |
| 36350 | 1492 | unfolding fps_eq_iff fps_add_nth fps_const_mult_left fps_deriv_nth by (simp add: field_simps) | 
| 29687 | 1493 | |
| 30488 | 1494 | lemma fps_deriv_mult[simp]: | 
| 54681 | 1495 | fixes f :: "'a::comm_ring_1 fps" | 
| 29687 | 1496 | shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g" | 
| 52891 | 1497 | proof - | 
| 29687 | 1498 | let ?D = "fps_deriv" | 
| 60558 | 1499 | have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" for n | 
| 1500 | proof - | |
| 29687 | 1501 |     let ?Zn = "{0 ..n}"
 | 
| 1502 |     let ?Zn1 = "{0 .. n + 1}"
 | |
| 1503 | let ?g = "\<lambda>i. of_nat (i+1) * g $ (i+1) * f $ (n - i) + | |
| 1504 | of_nat (i+1)* f $ (i+1) * g $ (n - i)" | |
| 1505 | let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) + | |
| 1506 | of_nat i* f $ i * g $ ((n + 1) - i)" | |
| 52891 | 1507 | have s0: "setsum (\<lambda>i. of_nat i * f $ i * g $ (n + 1 - i)) ?Zn1 = | 
| 1508 | setsum (\<lambda>i. of_nat (n + 1 - i) * f $ (n + 1 - i) * g $ i) ?Zn1" | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 1509 | by (rule setsum.reindex_bij_witness[where i="op - (n + 1)" and j="op - (n + 1)"]) auto | 
| 52891 | 1510 | have s1: "setsum (\<lambda>i. f $ i * g $ (n + 1 - i)) ?Zn1 = | 
| 1511 | setsum (\<lambda>i. f $ (n + 1 - i) * g $ i) ?Zn1" | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 1512 | by (rule setsum.reindex_bij_witness[where i="op - (n + 1)" and j="op - (n + 1)"]) auto | 
| 52891 | 1513 | have "(f * ?D g + ?D f * g)$n = (?D g * f + ?D f * g)$n" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1514 | by (simp only: mult.commute) | 
| 29687 | 1515 | also have "\<dots> = (\<Sum>i = 0..n. ?g i)" | 
| 57418 | 1516 | by (simp add: fps_mult_nth setsum.distrib[symmetric]) | 
| 29687 | 1517 |     also have "\<dots> = setsum ?h {0..n+1}"
 | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 1518 | by (rule setsum.reindex_bij_witness_not_neutral | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 1519 |             [where S'="{}" and T'="{0}" and j="Suc" and i="\<lambda>i. i - 1"]) auto
 | 
| 29687 | 1520 | also have "\<dots> = (fps_deriv (f * g)) $ n" | 
| 57418 | 1521 | apply (simp only: fps_deriv_nth fps_mult_nth setsum.distrib) | 
| 29687 | 1522 | unfolding s0 s1 | 
| 57418 | 1523 | unfolding setsum.distrib[symmetric] setsum_right_distrib | 
| 1524 | apply (rule setsum.cong) | |
| 52891 | 1525 | apply (auto simp add: of_nat_diff field_simps) | 
| 1526 | done | |
| 60558 | 1527 | finally show ?thesis . | 
| 1528 | qed | |
| 1529 | then show ?thesis | |
| 1530 | unfolding fps_eq_iff by auto | |
| 29687 | 1531 | qed | 
| 1532 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 1533 | lemma fps_deriv_X[simp]: "fps_deriv X = 1" | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 1534 | by (simp add: fps_deriv_def X_def fps_eq_iff) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 1535 | |
| 54681 | 1536 | lemma fps_deriv_neg[simp]: | 
| 1537 | "fps_deriv (- (f:: 'a::comm_ring_1 fps)) = - (fps_deriv f)" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 1538 | by (simp add: fps_eq_iff fps_deriv_def) | 
| 52891 | 1539 | |
| 54681 | 1540 | lemma fps_deriv_add[simp]: | 
| 1541 | "fps_deriv ((f:: 'a::comm_ring_1 fps) + g) = fps_deriv f + fps_deriv g" | |
| 29687 | 1542 | using fps_deriv_linear[of 1 f 1 g] by simp | 
| 1543 | ||
| 54681 | 1544 | lemma fps_deriv_sub[simp]: | 
| 1545 | "fps_deriv ((f:: 'a::comm_ring_1 fps) - g) = fps_deriv f - fps_deriv g" | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 1546 | using fps_deriv_add [of f "- g"] by simp | 
| 29687 | 1547 | |
| 1548 | lemma fps_deriv_const[simp]: "fps_deriv (fps_const c) = 0" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 1549 | by (simp add: fps_ext fps_deriv_def fps_const_def) | 
| 29687 | 1550 | |
| 48757 | 1551 | lemma fps_deriv_mult_const_left[simp]: | 
| 54681 | 1552 | "fps_deriv (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_deriv f" | 
| 29687 | 1553 | by simp | 
| 1554 | ||
| 1555 | lemma fps_deriv_0[simp]: "fps_deriv 0 = 0" | |
| 1556 | by (simp add: fps_deriv_def fps_eq_iff) | |
| 1557 | ||
| 1558 | lemma fps_deriv_1[simp]: "fps_deriv 1 = 0" | |
| 1559 | by (simp add: fps_deriv_def fps_eq_iff ) | |
| 1560 | ||
| 48757 | 1561 | lemma fps_deriv_mult_const_right[simp]: | 
| 54681 | 1562 | "fps_deriv (f * fps_const (c::'a::comm_ring_1)) = fps_deriv f * fps_const c" | 
| 29687 | 1563 | by simp | 
| 1564 | ||
| 48757 | 1565 | lemma fps_deriv_setsum: | 
| 54681 | 1566 | "fps_deriv (setsum f S) = setsum (\<lambda>i. fps_deriv (f i :: 'a::comm_ring_1 fps)) S" | 
| 53195 | 1567 | proof (cases "finite S") | 
| 1568 | case False | |
| 1569 | then show ?thesis by simp | |
| 1570 | next | |
| 1571 | case True | |
| 1572 | show ?thesis by (induct rule: finite_induct [OF True]) simp_all | |
| 29687 | 1573 | qed | 
| 1574 | ||
| 52902 | 1575 | lemma fps_deriv_eq_0_iff [simp]: | 
| 54681 | 1576 |   "fps_deriv f = 0 \<longleftrightarrow> f = fps_const (f$0 :: 'a::{idom,semiring_char_0})"
 | 
| 60501 | 1577 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 1578 | proof | |
| 1579 | show ?lhs if ?rhs | |
| 1580 | proof - | |
| 1581 | from that have "fps_deriv f = fps_deriv (fps_const (f$0))" | |
| 1582 | by simp | |
| 1583 | then show ?thesis | |
| 1584 | by simp | |
| 1585 | qed | |
| 1586 | show ?rhs if ?lhs | |
| 1587 | proof - | |
| 1588 | from that have "\<forall>n. (fps_deriv f)$n = 0" | |
| 1589 | by simp | |
| 1590 | then have "\<forall>n. f$(n+1) = 0" | |
| 1591 | by (simp del: of_nat_Suc of_nat_add One_nat_def) | |
| 1592 | then show ?thesis | |
| 29687 | 1593 | apply (clarsimp simp add: fps_eq_iff fps_const_def) | 
| 1594 | apply (erule_tac x="n - 1" in allE) | |
| 52891 | 1595 | apply simp | 
| 1596 | done | |
| 60501 | 1597 | qed | 
| 29687 | 1598 | qed | 
| 1599 | ||
| 30488 | 1600 | lemma fps_deriv_eq_iff: | 
| 54681 | 1601 |   fixes f :: "'a::{idom,semiring_char_0} fps"
 | 
| 29687 | 1602 | shows "fps_deriv f = fps_deriv g \<longleftrightarrow> (f = fps_const(f$0 - g$0) + g)" | 
| 52891 | 1603 | proof - | 
| 52903 | 1604 | have "fps_deriv f = fps_deriv g \<longleftrightarrow> fps_deriv (f - g) = 0" | 
| 1605 | by simp | |
| 54681 | 1606 | also have "\<dots> \<longleftrightarrow> f - g = fps_const ((f - g) $ 0)" | 
| 52903 | 1607 | unfolding fps_deriv_eq_0_iff .. | 
| 60501 | 1608 | finally show ?thesis | 
| 1609 | by (simp add: field_simps) | |
| 29687 | 1610 | qed | 
| 1611 | ||
| 48757 | 1612 | lemma fps_deriv_eq_iff_ex: | 
| 54681 | 1613 |   "(fps_deriv f = fps_deriv g) \<longleftrightarrow> (\<exists>c::'a::{idom,semiring_char_0}. f = fps_const c + g)"
 | 
| 53195 | 1614 | by (auto simp: fps_deriv_eq_iff) | 
| 48757 | 1615 | |
| 1616 | ||
| 54681 | 1617 | fun fps_nth_deriv :: "nat \<Rightarrow> 'a::semiring_1 fps \<Rightarrow> 'a fps" | 
| 48757 | 1618 | where | 
| 29687 | 1619 | "fps_nth_deriv 0 f = f" | 
| 1620 | | "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)" | |
| 1621 | ||
| 1622 | lemma fps_nth_deriv_commute: "fps_nth_deriv (Suc n) f = fps_deriv (fps_nth_deriv n f)" | |
| 48757 | 1623 | by (induct n arbitrary: f) auto | 
| 1624 | ||
| 1625 | lemma fps_nth_deriv_linear[simp]: | |
| 1626 | "fps_nth_deriv n (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = | |
| 1627 | fps_const a * fps_nth_deriv n f + fps_const b * fps_nth_deriv n g" | |
| 1628 | by (induct n arbitrary: f g) (auto simp add: fps_nth_deriv_commute) | |
| 1629 | ||
| 1630 | lemma fps_nth_deriv_neg[simp]: | |
| 54681 | 1631 | "fps_nth_deriv n (- (f :: 'a::comm_ring_1 fps)) = - (fps_nth_deriv n f)" | 
| 48757 | 1632 | by (induct n arbitrary: f) simp_all | 
| 1633 | ||
| 1634 | lemma fps_nth_deriv_add[simp]: | |
| 54681 | 1635 | "fps_nth_deriv n ((f :: 'a::comm_ring_1 fps) + g) = fps_nth_deriv n f + fps_nth_deriv n g" | 
| 29687 | 1636 | using fps_nth_deriv_linear[of n 1 f 1 g] by simp | 
| 1637 | ||
| 48757 | 1638 | lemma fps_nth_deriv_sub[simp]: | 
| 54681 | 1639 | "fps_nth_deriv n ((f :: 'a::comm_ring_1 fps) - g) = fps_nth_deriv n f - fps_nth_deriv n g" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 1640 | using fps_nth_deriv_add [of n f "- g"] by simp | 
| 29687 | 1641 | |
| 1642 | lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0" | |
| 48757 | 1643 | by (induct n) simp_all | 
| 29687 | 1644 | |
| 1645 | lemma fps_nth_deriv_1[simp]: "fps_nth_deriv n 1 = (if n = 0 then 1 else 0)" | |
| 48757 | 1646 | by (induct n) simp_all | 
| 1647 | ||
| 1648 | lemma fps_nth_deriv_const[simp]: | |
| 1649 | "fps_nth_deriv n (fps_const c) = (if n = 0 then fps_const c else 0)" | |
| 1650 | by (cases n) simp_all | |
| 1651 | ||
| 1652 | lemma fps_nth_deriv_mult_const_left[simp]: | |
| 1653 | "fps_nth_deriv n (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_nth_deriv n f" | |
| 29687 | 1654 | using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp | 
| 1655 | ||
| 48757 | 1656 | lemma fps_nth_deriv_mult_const_right[simp]: | 
| 1657 | "fps_nth_deriv n (f * fps_const (c::'a::comm_ring_1)) = fps_nth_deriv n f * fps_const c" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1658 | using fps_nth_deriv_linear[of n "c" f 0 0] by (simp add: mult.commute) | 
| 29687 | 1659 | |
| 48757 | 1660 | lemma fps_nth_deriv_setsum: | 
| 54681 | 1661 | "fps_nth_deriv n (setsum f S) = setsum (\<lambda>i. fps_nth_deriv n (f i :: 'a::comm_ring_1 fps)) S" | 
| 52903 | 1662 | proof (cases "finite S") | 
| 1663 | case True | |
| 1664 | show ?thesis by (induct rule: finite_induct [OF True]) simp_all | |
| 1665 | next | |
| 1666 | case False | |
| 1667 | then show ?thesis by simp | |
| 29687 | 1668 | qed | 
| 1669 | ||
| 48757 | 1670 | lemma fps_deriv_maclauren_0: | 
| 54681 | 1671 | "(fps_nth_deriv k (f :: 'a::comm_semiring_1 fps)) $ 0 = of_nat (fact k) * f $ k" | 
| 36350 | 1672 | by (induct k arbitrary: f) (auto simp add: field_simps of_nat_mult) | 
| 29687 | 1673 | |
| 54681 | 1674 | |
| 60500 | 1675 | subsection \<open>Powers\<close> | 
| 29687 | 1676 | |
| 1677 | lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)" | |
| 48757 | 1678 | by (induct n) (auto simp add: expand_fps_eq fps_mult_nth) | 
| 29687 | 1679 | |
| 54681 | 1680 | lemma fps_power_first_eq: "(a :: 'a::comm_ring_1 fps) $ 0 =1 \<Longrightarrow> a^n $ 1 = of_nat n * a$1" | 
| 52891 | 1681 | proof (induct n) | 
| 1682 | case 0 | |
| 1683 | then show ?case by simp | |
| 29687 | 1684 | next | 
| 1685 | case (Suc n) | |
| 30488 | 1686 | show ?case unfolding power_Suc fps_mult_nth | 
| 60501 | 1687 | using Suc.hyps[OF \<open>a$0 = 1\<close>] \<open>a$0 = 1\<close> fps_power_zeroth_eq_one[OF \<open>a$0=1\<close>] | 
| 52891 | 1688 | by (simp add: field_simps) | 
| 29687 | 1689 | qed | 
| 1690 | ||
| 1691 | lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1" | |
| 48757 | 1692 | by (induct n) (auto simp add: fps_mult_nth) | 
| 29687 | 1693 | |
| 1694 | lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0" | |
| 48757 | 1695 | by (induct n) (auto simp add: fps_mult_nth) | 
| 29687 | 1696 | |
| 54681 | 1697 | lemma startsby_power:"a $0 = (v::'a::comm_ring_1) \<Longrightarrow> a^n $0 = v^n" | 
| 52891 | 1698 | by (induct n) (auto simp add: fps_mult_nth) | 
| 1699 | ||
| 54681 | 1700 | lemma startsby_zero_power_iff[simp]: "a^n $0 = (0::'a::idom) \<longleftrightarrow> n \<noteq> 0 \<and> a$0 = 0" | 
| 52891 | 1701 | apply (rule iffI) | 
| 1702 | apply (induct n) | |
| 1703 | apply (auto simp add: fps_mult_nth) | |
| 1704 | apply (rule startsby_zero_power, simp_all) | |
| 1705 | done | |
| 29687 | 1706 | |
| 30488 | 1707 | lemma startsby_zero_power_prefix: | 
| 60501 | 1708 | assumes a0: "a $ 0 = (0::'a::idom)" | 
| 29687 | 1709 | shows "\<forall>n < k. a ^ k $ n = 0" | 
| 30488 | 1710 | using a0 | 
| 54681 | 1711 | proof (induct k rule: nat_less_induct) | 
| 52891 | 1712 | fix k | 
| 54681 | 1713 | assume H: "\<forall>m<k. a $0 = 0 \<longrightarrow> (\<forall>n<m. a ^ m $ n = 0)" and a0: "a $ 0 = 0" | 
| 60501 | 1714 | show "\<forall>m<k. a ^ k $ m = 0" | 
| 1715 | proof (cases k) | |
| 1716 | case 0 | |
| 1717 | then show ?thesis by simp | |
| 1718 | next | |
| 1719 | case (Suc l) | |
| 1720 | have "a^k $ m = 0" if mk: "m < k" for m | |
| 1721 | proof (cases "m = 0") | |
| 1722 | case True | |
| 1723 | then show ?thesis | |
| 1724 | using startsby_zero_power[of a k] Suc a0 by simp | |
| 1725 | next | |
| 1726 | case False | |
| 1727 | have "a ^k $ m = (a^l * a) $m" | |
| 1728 | by (simp add: Suc mult.commute) | |
| 1729 | also have "\<dots> = (\<Sum>i = 0..m. a ^ l $ i * a $ (m - i))" | |
| 1730 | by (simp add: fps_mult_nth) | |
| 1731 | also have "\<dots> = 0" | |
| 1732 | apply (rule setsum.neutral) | |
| 1733 | apply auto | |
| 1734 | apply (case_tac "x = m") | |
| 1735 | using a0 apply simp | |
| 1736 | apply (rule H[rule_format]) | |
| 1737 | using a0 Suc mk apply auto | |
| 1738 | done | |
| 1739 | finally show ?thesis . | |
| 1740 | qed | |
| 1741 | then show ?thesis by blast | |
| 1742 | qed | |
| 29687 | 1743 | qed | 
| 1744 | ||
| 30488 | 1745 | lemma startsby_zero_setsum_depends: | 
| 54681 | 1746 | assumes a0: "a $0 = (0::'a::idom)" | 
| 1747 | and kn: "n \<ge> k" | |
| 29687 | 1748 |   shows "setsum (\<lambda>i. (a ^ i)$k) {0 .. n} = setsum (\<lambda>i. (a ^ i)$k) {0 .. k}"
 | 
| 57418 | 1749 | apply (rule setsum.mono_neutral_right) | 
| 54681 | 1750 | using kn | 
| 1751 | apply auto | |
| 29687 | 1752 | apply (rule startsby_zero_power_prefix[rule_format, OF a0]) | 
| 52891 | 1753 | apply arith | 
| 1754 | done | |
| 1755 | ||
| 1756 | lemma startsby_zero_power_nth_same: | |
| 54681 | 1757 | assumes a0: "a$0 = (0::'a::idom)" | 
| 29687 | 1758 | shows "a^n $ n = (a$1) ^ n" | 
| 52891 | 1759 | proof (induct n) | 
| 1760 | case 0 | |
| 52902 | 1761 | then show ?case by simp | 
| 29687 | 1762 | next | 
| 1763 | case (Suc n) | |
| 54681 | 1764 | have "a ^ Suc n $ (Suc n) = (a^n * a)$(Suc n)" | 
| 1765 | by (simp add: field_simps) | |
| 52891 | 1766 |   also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {0.. Suc n}"
 | 
| 1767 | by (simp add: fps_mult_nth) | |
| 29687 | 1768 |   also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {n .. Suc n}"
 | 
| 57418 | 1769 | apply (rule setsum.mono_neutral_right) | 
| 29687 | 1770 | apply simp | 
| 1771 | apply clarsimp | |
| 1772 | apply clarsimp | |
| 1773 | apply (rule startsby_zero_power_prefix[rule_format, OF a0]) | |
| 1774 | apply arith | |
| 1775 | done | |
| 54681 | 1776 | also have "\<dots> = a^n $ n * a$1" | 
| 1777 | using a0 by simp | |
| 1778 | finally show ?case | |
| 1779 | using Suc.hyps by simp | |
| 29687 | 1780 | qed | 
| 1781 | ||
| 1782 | lemma fps_inverse_power: | |
| 54681 | 1783 | fixes a :: "'a::field fps" | 
| 29687 | 1784 | shows "inverse (a^n) = inverse a ^ n" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1785 | by (induction n) (simp_all add: fps_inverse_mult) | 
| 29687 | 1786 | |
| 48757 | 1787 | lemma fps_deriv_power: | 
| 54681 | 1788 | "fps_deriv (a ^ n) = fps_const (of_nat n :: 'a::comm_ring_1) * fps_deriv a * a ^ (n - 1)" | 
| 48757 | 1789 | apply (induct n) | 
| 52891 | 1790 | apply (auto simp add: field_simps fps_const_add[symmetric] simp del: fps_const_add) | 
| 48757 | 1791 | apply (case_tac n) | 
| 52891 | 1792 | apply (auto simp add: field_simps) | 
| 48757 | 1793 | done | 
| 29687 | 1794 | |
| 30488 | 1795 | lemma fps_inverse_deriv: | 
| 54681 | 1796 | fixes a :: "'a::field fps" | 
| 29687 | 1797 | assumes a0: "a$0 \<noteq> 0" | 
| 53077 | 1798 | shows "fps_deriv (inverse a) = - fps_deriv a * (inverse a)\<^sup>2" | 
| 54681 | 1799 | proof - | 
| 29687 | 1800 | from inverse_mult_eq_1[OF a0] | 
| 1801 | have "fps_deriv (inverse a * a) = 0" by simp | |
| 54452 | 1802 | then have "inverse a * fps_deriv a + fps_deriv (inverse a) * a = 0" | 
| 1803 | by simp | |
| 1804 | then have "inverse a * (inverse a * fps_deriv a + fps_deriv (inverse a) * a) = 0" | |
| 1805 | by simp | |
| 29687 | 1806 | with inverse_mult_eq_1[OF a0] | 
| 53077 | 1807 | have "(inverse a)\<^sup>2 * fps_deriv a + fps_deriv (inverse a) = 0" | 
| 29687 | 1808 | unfolding power2_eq_square | 
| 36350 | 1809 | apply (simp add: field_simps) | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1810 | apply (simp add: mult.assoc[symmetric]) | 
| 52903 | 1811 | done | 
| 53077 | 1812 | then have "(inverse a)\<^sup>2 * fps_deriv a + fps_deriv (inverse a) - fps_deriv a * (inverse a)\<^sup>2 = | 
| 1813 | 0 - fps_deriv a * (inverse a)\<^sup>2" | |
| 29687 | 1814 | by simp | 
| 53077 | 1815 | then show "fps_deriv (inverse a) = - fps_deriv a * (inverse a)\<^sup>2" | 
| 52902 | 1816 | by (simp add: field_simps) | 
| 29687 | 1817 | qed | 
| 1818 | ||
| 30488 | 1819 | lemma fps_inverse_deriv': | 
| 54681 | 1820 | fixes a :: "'a::field fps" | 
| 60501 | 1821 | assumes a0: "a $ 0 \<noteq> 0" | 
| 53077 | 1822 | shows "fps_deriv (inverse a) = - fps_deriv a / a\<^sup>2" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1823 | using fps_inverse_deriv[OF a0] a0 | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1824 | by (simp add: fps_divide_unit power2_eq_square fps_inverse_mult) | 
| 29687 | 1825 | |
| 52902 | 1826 | lemma inverse_mult_eq_1': | 
| 1827 | assumes f0: "f$0 \<noteq> (0::'a::field)" | |
| 60567 | 1828 | shows "f * inverse f = 1" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1829 | by (metis mult.commute inverse_mult_eq_1 f0) | 
| 29687 | 1830 | |
| 61804 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1831 | (* FIXME: The last part of this proof should go through by simp once we have a proper | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1832 | theorem collection for simplifying division on rings *) | 
| 52902 | 1833 | lemma fps_divide_deriv: | 
| 61804 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1834 | assumes "b dvd (a :: 'a :: field fps)" | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1835 | shows "fps_deriv (a / b) = (fps_deriv a * b - a * fps_deriv b) / b^2" | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1836 | proof - | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1837 | have eq_divide_imp: "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b div c" for a b c :: "'a :: field fps" | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1838 | by (drule sym) (simp add: mult.assoc) | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1839 | from assms have "a = a / b * b" by simp | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1840 | also have "fps_deriv (a / b * b) = fps_deriv (a / b) * b + a / b * fps_deriv b" by simp | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1841 | finally have "fps_deriv (a / b) * b^2 = fps_deriv a * b - a * fps_deriv b" using assms | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1842 | by (simp add: power2_eq_square algebra_simps) | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1843 | thus ?thesis by (cases "b = 0") (auto simp: eq_divide_imp) | 
| 
67381557cee8
Generalised derivative rule for division on formal power series
 eberlm parents: 
61799diff
changeset | 1844 | qed | 
| 29687 | 1845 | |
| 54681 | 1846 | lemma fps_inverse_gp': "inverse (Abs_fps (\<lambda>n. 1::'a::field)) = 1 - X" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 1847 | by (simp add: fps_inverse_gp fps_eq_iff X_def) | 
| 29687 | 1848 | |
| 1849 | lemma fps_nth_deriv_X[simp]: "fps_nth_deriv n X = (if n = 0 then X else if n=1 then 1 else 0)" | |
| 52902 | 1850 | by (cases n) simp_all | 
| 29687 | 1851 | |
| 60501 | 1852 | lemma fps_inverse_X_plus1: "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::field)) ^ n)" | 
| 1853 | (is "_ = ?r") | |
| 54681 | 1854 | proof - | 
| 29687 | 1855 | have eq: "(1 + X) * ?r = 1" | 
| 1856 | unfolding minus_one_power_iff | |
| 36350 | 1857 | by (auto simp add: field_simps fps_eq_iff) | 
| 54681 | 1858 | show ?thesis | 
| 1859 | by (auto simp add: eq intro: fps_inverse_unique) | |
| 29687 | 1860 | qed | 
| 1861 | ||
| 30488 | 1862 | |
| 60501 | 1863 | subsection \<open>Integration\<close> | 
| 31273 | 1864 | |
| 52903 | 1865 | definition fps_integral :: "'a::field_char_0 fps \<Rightarrow> 'a \<Rightarrow> 'a fps" | 
| 1866 | where "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))" | |
| 29687 | 1867 | |
| 31273 | 1868 | lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a a0) = a" | 
| 1869 | unfolding fps_integral_def fps_deriv_def | |
| 1870 | by (simp add: fps_eq_iff del: of_nat_Suc) | |
| 29687 | 1871 | |
| 31273 | 1872 | lemma fps_integral_linear: | 
| 1873 | "fps_integral (fps_const a * f + fps_const b * g) (a*a0 + b*b0) = | |
| 1874 | fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0" | |
| 1875 | (is "?l = ?r") | |
| 53195 | 1876 | proof - | 
| 54681 | 1877 | have "fps_deriv ?l = fps_deriv ?r" | 
| 1878 | by (simp add: fps_deriv_fps_integral) | |
| 1879 | moreover have "?l$0 = ?r$0" | |
| 1880 | by (simp add: fps_integral_def) | |
| 29687 | 1881 | ultimately show ?thesis | 
| 1882 | unfolding fps_deriv_eq_iff by auto | |
| 1883 | qed | |
| 30488 | 1884 | |
| 53195 | 1885 | |
| 60500 | 1886 | subsection \<open>Composition of FPSs\<close> | 
| 53195 | 1887 | |
| 60501 | 1888 | definition fps_compose :: "'a::semiring_1 fps \<Rightarrow> 'a fps \<Rightarrow> 'a fps" (infixl "oo" 55) | 
| 54681 | 1889 |   where "a oo b = Abs_fps (\<lambda>n. setsum (\<lambda>i. a$i * (b^i$n)) {0..n})"
 | 
| 29687 | 1890 | |
| 48757 | 1891 | lemma fps_compose_nth: "(a oo b)$n = setsum (\<lambda>i. a$i * (b^i$n)) {0..n}"
 | 
| 1892 | by (simp add: fps_compose_def) | |
| 29687 | 1893 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1894 | lemma fps_compose_nth_0 [simp]: "(f oo g) $ 0 = f $ 0" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1895 | by (simp add: fps_compose_nth) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 1896 | |
| 54681 | 1897 | lemma fps_compose_X[simp]: "a oo X = (a :: 'a::comm_ring_1 fps)" | 
| 57418 | 1898 | by (simp add: fps_ext fps_compose_def mult_delta_right setsum.delta') | 
| 30488 | 1899 | |
| 60501 | 1900 | lemma fps_const_compose[simp]: "fps_const (a::'a::comm_ring_1) oo b = fps_const a" | 
| 57418 | 1901 | by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum.delta) | 
| 29687 | 1902 | |
| 54681 | 1903 | lemma numeral_compose[simp]: "(numeral k :: 'a::comm_ring_1 fps) oo b = numeral k" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 1904 | unfolding numeral_fps_const by simp | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 1905 | |
| 54681 | 1906 | lemma neg_numeral_compose[simp]: "(- numeral k :: 'a::comm_ring_1 fps) oo b = - numeral k" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 1907 | unfolding neg_numeral_fps_const by simp | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 1908 | |
| 54681 | 1909 | lemma X_fps_compose_startby0[simp]: "a$0 = 0 \<Longrightarrow> X oo a = (a :: 'a::comm_ring_1 fps)" | 
| 57418 | 1910 | by (simp add: fps_eq_iff fps_compose_def mult_delta_left setsum.delta not_le) | 
| 29687 | 1911 | |
| 1912 | ||
| 60500 | 1913 | subsection \<open>Rules from Herbert Wilf's Generatingfunctionology\<close> | 
| 1914 | ||
| 1915 | subsubsection \<open>Rule 1\<close> | |
| 29687 | 1916 |   (* {a_{n+k}}_0^infty Corresponds to (f - setsum (\<lambda>i. a_i * x^i))/x^h, for h>0*)
 | 
| 1917 | ||
| 30488 | 1918 | lemma fps_power_mult_eq_shift: | 
| 52902 | 1919 | "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = | 
| 54681 | 1920 |     Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a::comm_ring_1) * X^i) {0 .. k}"
 | 
| 52902 | 1921 | (is "?lhs = ?rhs") | 
| 1922 | proof - | |
| 60501 | 1923 | have "?lhs $ n = ?rhs $ n" for n :: nat | 
| 1924 | proof - | |
| 30488 | 1925 | have "?lhs $ n = (if n < Suc k then 0 else a n)" | 
| 29687 | 1926 | unfolding X_power_mult_nth by auto | 
| 1927 | also have "\<dots> = ?rhs $ n" | |
| 52902 | 1928 | proof (induct k) | 
| 1929 | case 0 | |
| 60501 | 1930 | then show ?case | 
| 1931 | by (simp add: fps_setsum_nth) | |
| 29687 | 1932 | next | 
| 1933 | case (Suc k) | |
| 52902 | 1934 |       have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. Suc k})$n =
 | 
| 53196 | 1935 |         (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. k} -
 | 
| 1936 | fps_const (a (Suc k)) * X^ Suc k) $ n" | |
| 52902 | 1937 | by (simp add: field_simps) | 
| 1938 | also have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n" | |
| 60501 | 1939 | using Suc.hyps[symmetric] unfolding fps_sub_nth by simp | 
| 29687 | 1940 | also have "\<dots> = (if n < Suc (Suc k) then 0 else a n)" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1941 | unfolding X_power_mult_right_nth | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1942 | apply (auto simp add: not_less fps_const_def) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1943 | apply (rule cong[of a a, OF refl]) | 
| 52902 | 1944 | apply arith | 
| 1945 | done | |
| 60501 | 1946 | finally show ?case | 
| 1947 | by simp | |
| 29687 | 1948 | qed | 
| 60501 | 1949 | finally show ?thesis . | 
| 1950 | qed | |
| 1951 | then show ?thesis | |
| 1952 | by (simp add: fps_eq_iff) | |
| 29687 | 1953 | qed | 
| 1954 | ||
| 53195 | 1955 | |
| 60500 | 1956 | subsubsection \<open>Rule 2\<close> | 
| 29687 | 1957 | |
| 1958 | (* We can not reach the form of Wilf, but still near to it using rewrite rules*) | |
| 30488 | 1959 |   (* If f reprents {a_n} and P is a polynomial, then
 | 
| 29687 | 1960 |         P(xD) f represents {P(n) a_n}*)
 | 
| 1961 | ||
| 54681 | 1962 | definition "XD = op * X \<circ> fps_deriv" | 
| 1963 | ||
| 1964 | lemma XD_add[simp]:"XD (a + b) = XD a + XD (b :: 'a::comm_ring_1 fps)" | |
| 36350 | 1965 | by (simp add: XD_def field_simps) | 
| 29687 | 1966 | |
| 1967 | lemma XD_mult_const[simp]:"XD (fps_const (c::'a::comm_ring_1) * a) = fps_const c * XD a" | |
| 36350 | 1968 | by (simp add: XD_def field_simps) | 
| 29687 | 1969 | |
| 52902 | 1970 | lemma XD_linear[simp]: "XD (fps_const c * a + fps_const d * b) = | 
| 54681 | 1971 | fps_const c * XD a + fps_const d * XD (b :: 'a::comm_ring_1 fps)" | 
| 29687 | 1972 | by simp | 
| 1973 | ||
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30837diff
changeset | 1974 | lemma XDN_linear: | 
| 52902 | 1975 | "(XD ^^ n) (fps_const c * a + fps_const d * b) = | 
| 54681 | 1976 | fps_const c * (XD ^^ n) a + fps_const d * (XD ^^ n) (b :: 'a::comm_ring_1 fps)" | 
| 48757 | 1977 | by (induct n) simp_all | 
| 29687 | 1978 | |
| 52902 | 1979 | lemma fps_mult_X_deriv_shift: "X* fps_deriv a = Abs_fps (\<lambda>n. of_nat n* a$n)" | 
| 1980 | by (simp add: fps_eq_iff) | |
| 29687 | 1981 | |
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30837diff
changeset | 1982 | lemma fps_mult_XD_shift: | 
| 54681 | 1983 | "(XD ^^ k) (a :: 'a::comm_ring_1 fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)" | 
| 52902 | 1984 | by (induct k arbitrary: a) (simp_all add: XD_def fps_eq_iff field_simps del: One_nat_def) | 
| 29687 | 1985 | |
| 53195 | 1986 | |
| 60501 | 1987 | subsubsection \<open>Rule 3\<close> | 
| 1988 | ||
| 61585 | 1989 | text \<open>Rule 3 is trivial and is given by \<open>fps_times_def\<close>.\<close> | 
| 60501 | 1990 | |
| 60500 | 1991 | |
| 1992 | subsubsection \<open>Rule 5 --- summation and "division" by (1 - X)\<close> | |
| 29687 | 1993 | |
| 1994 | lemma fps_divide_X_minus1_setsum_lemma: | |
| 54681 | 1995 |   "a = ((1::'a::comm_ring_1 fps) - X) * Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 53195 | 1996 | proof - | 
| 29687 | 1997 |   let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 52902 | 1998 | have th0: "\<And>i. (1 - (X::'a fps)) $ i = (if i = 0 then 1 else if i = 1 then - 1 else 0)" | 
| 1999 | by simp | |
| 60501 | 2000 | have "a$n = ((1 - X) * ?sa) $ n" for n | 
| 2001 | proof (cases "n = 0") | |
| 2002 | case True | |
| 2003 | then show ?thesis | |
| 2004 | by (simp add: fps_mult_nth) | |
| 2005 | next | |
| 2006 | case False | |
| 2007 |     then have u: "{0} \<union> ({1} \<union> {2..n}) = {0..n}" "{1} \<union> {2..n} = {1..n}"
 | |
| 2008 |       "{0..n - 1} \<union> {n} = {0..n}"
 | |
| 2009 | by (auto simp: set_eq_iff) | |
| 2010 |     have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}" "{0..n - 1} \<inter> {n} = {}"
 | |
| 2011 | using False by simp_all | |
| 2012 |     have f: "finite {0}" "finite {1}" "finite {2 .. n}"
 | |
| 2013 |       "finite {0 .. n - 1}" "finite {n}" by simp_all
 | |
| 2014 |     have "((1 - X) * ?sa) $ n = setsum (\<lambda>i. (1 - X)$ i * ?sa $ (n - i)) {0 .. n}"
 | |
| 2015 | by (simp add: fps_mult_nth) | |
| 2016 | also have "\<dots> = a$n" | |
| 2017 | unfolding th0 | |
| 2018 | unfolding setsum.union_disjoint[OF f(1) finite_UnI[OF f(2,3)] d(1), unfolded u(1)] | |
| 2019 | unfolding setsum.union_disjoint[OF f(2) f(3) d(2)] | |
| 2020 | apply (simp) | |
| 2021 | unfolding setsum.union_disjoint[OF f(4,5) d(3), unfolded u(3)] | |
| 2022 | apply simp | |
| 2023 | done | |
| 2024 | finally show ?thesis | |
| 2025 | by simp | |
| 2026 | qed | |
| 54681 | 2027 | then show ?thesis | 
| 2028 | unfolding fps_eq_iff by blast | |
| 29687 | 2029 | qed | 
| 2030 | ||
| 2031 | lemma fps_divide_X_minus1_setsum: | |
| 54681 | 2032 |   "a /((1::'a::field fps) - X) = Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 52902 | 2033 | proof - | 
| 54681 | 2034 | let ?X = "1 - (X::'a fps)" | 
| 2035 | have th0: "?X $ 0 \<noteq> 0" | |
| 2036 | by simp | |
| 2037 |   have "a /?X = ?X *  Abs_fps (\<lambda>n::nat. setsum (op $ a) {0..n}) * inverse ?X"
 | |
| 29687 | 2038 | using fps_divide_X_minus1_setsum_lemma[of a, symmetric] th0 | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2039 | by (simp add: fps_divide_def mult.assoc) | 
| 54681 | 2040 |   also have "\<dots> = (inverse ?X * ?X) * Abs_fps (\<lambda>n::nat. setsum (op $ a) {0..n}) "
 | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 2041 | by (simp add: ac_simps) | 
| 54681 | 2042 | finally show ?thesis | 
| 2043 | by (simp add: inverse_mult_eq_1[OF th0]) | |
| 29687 | 2044 | qed | 
| 2045 | ||
| 53195 | 2046 | |
| 60501 | 2047 | subsubsection \<open>Rule 4 in its more general form: generalizes Rule 3 for an arbitrary | 
| 60500 | 2048 | finite product of FPS, also the relvant instance of powers of a FPS\<close> | 
| 29687 | 2049 | |
| 46131 | 2050 | definition "natpermute n k = {l :: nat list. length l = k \<and> listsum l = n}"
 | 
| 29687 | 2051 | |
| 2052 | lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
 | |
| 2053 | apply (auto simp add: natpermute_def) | |
| 52902 | 2054 | apply (case_tac x) | 
| 2055 | apply auto | |
| 29687 | 2056 | done | 
| 2057 | ||
| 2058 | lemma append_natpermute_less_eq: | |
| 54452 | 2059 | assumes "xs @ ys \<in> natpermute n k" | 
| 54681 | 2060 | shows "listsum xs \<le> n" | 
| 2061 | and "listsum ys \<le> n" | |
| 52902 | 2062 | proof - | 
| 54452 | 2063 | from assms have "listsum (xs @ ys) = n" | 
| 2064 | by (simp add: natpermute_def) | |
| 2065 | then have "listsum xs + listsum ys = n" | |
| 2066 | by simp | |
| 2067 | then show "listsum xs \<le> n" and "listsum ys \<le> n" | |
| 2068 | by simp_all | |
| 29687 | 2069 | qed | 
| 2070 | ||
| 2071 | lemma natpermute_split: | |
| 54452 | 2072 | assumes "h \<le> k" | 
| 52902 | 2073 | shows "natpermute n k = | 
| 2074 |     (\<Union>m \<in>{0..n}. {l1 @ l2 |l1 l2. l1 \<in> natpermute m h \<and> l2 \<in> natpermute (n - m) (k - h)})"
 | |
| 60558 | 2075 |   (is "?L = ?R" is "_ = (\<Union>m \<in>{0..n}. ?S m)")
 | 
| 2076 | proof | |
| 2077 | show "?R \<subseteq> ?L" | |
| 2078 | proof | |
| 52902 | 2079 | fix l | 
| 2080 | assume l: "l \<in> ?R" | |
| 2081 |     from l obtain m xs ys where h: "m \<in> {0..n}"
 | |
| 2082 | and xs: "xs \<in> natpermute m h" | |
| 2083 | and ys: "ys \<in> natpermute (n - m) (k - h)" | |
| 2084 | and leq: "l = xs@ys" by blast | |
| 2085 | from xs have xs': "listsum xs = m" | |
| 2086 | by (simp add: natpermute_def) | |
| 2087 | from ys have ys': "listsum ys = n - m" | |
| 2088 | by (simp add: natpermute_def) | |
| 60558 | 2089 | show "l \<in> ?L" using leq xs ys h | 
| 46131 | 2090 | apply (clarsimp simp add: natpermute_def) | 
| 29687 | 2091 | unfolding xs' ys' | 
| 54452 | 2092 | using assms xs ys | 
| 48757 | 2093 | unfolding natpermute_def | 
| 2094 | apply simp | |
| 2095 | done | |
| 60558 | 2096 | qed | 
| 2097 | show "?L \<subseteq> ?R" | |
| 2098 | proof | |
| 52902 | 2099 | fix l | 
| 2100 | assume l: "l \<in> natpermute n k" | |
| 29687 | 2101 | let ?xs = "take h l" | 
| 2102 | let ?ys = "drop h l" | |
| 46131 | 2103 | let ?m = "listsum ?xs" | 
| 52902 | 2104 | from l have ls: "listsum (?xs @ ?ys) = n" | 
| 2105 | by (simp add: natpermute_def) | |
| 54452 | 2106 | have xs: "?xs \<in> natpermute ?m h" using l assms | 
| 52902 | 2107 | by (simp add: natpermute_def) | 
| 2108 | have l_take_drop: "listsum l = listsum (take h l @ drop h l)" | |
| 2109 | by simp | |
| 2110 | then have ys: "?ys \<in> natpermute (n - ?m) (k - h)" | |
| 54452 | 2111 | using l assms ls by (auto simp add: natpermute_def simp del: append_take_drop_id) | 
| 52902 | 2112 |     from ls have m: "?m \<in> {0..n}"
 | 
| 2113 | by (simp add: l_take_drop del: append_take_drop_id) | |
| 60558 | 2114 | from xs ys ls show "l \<in> ?R" | 
| 29687 | 2115 | apply auto | 
| 52902 | 2116 | apply (rule bexI [where x = "?m"]) | 
| 2117 | apply (rule exI [where x = "?xs"]) | |
| 2118 | apply (rule exI [where x = "?ys"]) | |
| 52891 | 2119 | using ls l | 
| 46131 | 2120 | apply (auto simp add: natpermute_def l_take_drop simp del: append_take_drop_id) | 
| 48757 | 2121 | apply simp | 
| 2122 | done | |
| 60558 | 2123 | qed | 
| 29687 | 2124 | qed | 
| 2125 | ||
| 2126 | lemma natpermute_0: "natpermute n 0 = (if n = 0 then {[]} else {})"
 | |
| 2127 | by (auto simp add: natpermute_def) | |
| 52902 | 2128 | |
| 29687 | 2129 | lemma natpermute_0'[simp]: "natpermute 0 k = (if k = 0 then {[]} else {replicate k 0})"
 | 
| 2130 | apply (auto simp add: set_replicate_conv_if natpermute_def) | |
| 2131 | apply (rule nth_equalityI) | |
| 48757 | 2132 | apply simp_all | 
| 2133 | done | |
| 29687 | 2134 | |
| 2135 | lemma natpermute_finite: "finite (natpermute n k)" | |
| 52902 | 2136 | proof (induct k arbitrary: n) | 
| 2137 | case 0 | |
| 2138 | then show ?case | |
| 29687 | 2139 | apply (subst natpermute_split[of 0 0, simplified]) | 
| 52902 | 2140 | apply (simp add: natpermute_0) | 
| 2141 | done | |
| 29687 | 2142 | next | 
| 2143 | case (Suc k) | |
| 52902 | 2144 | then show ?case unfolding natpermute_split [of k "Suc k", simplified] | 
| 29687 | 2145 | apply - | 
| 2146 | apply (rule finite_UN_I) | |
| 2147 | apply simp | |
| 2148 | unfolding One_nat_def[symmetric] natlist_trivial_1 | |
| 2149 | apply simp | |
| 2150 | done | |
| 2151 | qed | |
| 2152 | ||
| 2153 | lemma natpermute_contain_maximal: | |
| 60558 | 2154 |   "{xs \<in> natpermute n (k + 1). n \<in> set xs} = (\<Union>i\<in>{0 .. k}. {(replicate (k + 1) 0) [i:=n]})"
 | 
| 29687 | 2155 | (is "?A = ?B") | 
| 60558 | 2156 | proof | 
| 2157 | show "?A \<subseteq> ?B" | |
| 2158 | proof | |
| 52902 | 2159 | fix xs | 
| 60558 | 2160 | assume "xs \<in> ?A" | 
| 2161 | then have H: "xs \<in> natpermute n (k + 1)" and n: "n \<in> set xs" | |
| 2162 | by blast+ | |
| 2163 |     then obtain i where i: "i \<in> {0.. k}" "xs!i = n"
 | |
| 30488 | 2164 | unfolding in_set_conv_nth by (auto simp add: less_Suc_eq_le natpermute_def) | 
| 52902 | 2165 |     have eqs: "({0..k} - {i}) \<union> {i} = {0..k}"
 | 
| 2166 | using i by auto | |
| 2167 |     have f: "finite({0..k} - {i})" "finite {i}"
 | |
| 2168 | by auto | |
| 2169 |     have d: "({0..k} - {i}) \<inter> {i} = {}"
 | |
| 2170 | using i by auto | |
| 2171 |     from H have "n = setsum (nth xs) {0..k}"
 | |
| 2172 | apply (simp add: natpermute_def) | |
| 2173 | apply (auto simp add: atLeastLessThanSuc_atLeastAtMost listsum_setsum_nth) | |
| 2174 | done | |
| 29687 | 2175 |     also have "\<dots> = n + setsum (nth xs) ({0..k} - {i})"
 | 
| 57418 | 2176 | unfolding setsum.union_disjoint[OF f d, unfolded eqs] using i by simp | 
| 52902 | 2177 |     finally have zxs: "\<forall> j\<in> {0..k} - {i}. xs!j = 0"
 | 
| 2178 | by auto | |
| 2179 | from H have xsl: "length xs = k+1" | |
| 2180 | by (simp add: natpermute_def) | |
| 29687 | 2181 | from i have i': "i < length (replicate (k+1) 0)" "i < k+1" | 
| 52902 | 2182 | unfolding length_replicate by presburger+ | 
| 29687 | 2183 | have "xs = replicate (k+1) 0 [i := n]" | 
| 2184 | apply (rule nth_equalityI) | |
| 2185 | unfolding xsl length_list_update length_replicate | |
| 2186 | apply simp | |
| 2187 | apply clarify | |
| 2188 | unfolding nth_list_update[OF i'(1)] | |
| 2189 | using i zxs | |
| 52902 | 2190 | apply (case_tac "ia = i") | 
| 2191 | apply (auto simp del: replicate.simps) | |
| 2192 | done | |
| 60558 | 2193 | then show "xs \<in> ?B" using i by blast | 
| 2194 | qed | |
| 2195 | show "?B \<subseteq> ?A" | |
| 2196 | proof | |
| 2197 | fix xs | |
| 2198 | assume "xs \<in> ?B" | |
| 2199 |     then obtain i where i: "i \<in> {0..k}" and xs: "xs = replicate (k + 1) 0 [i:=n]"
 | |
| 2200 | by auto | |
| 2201 | have nxs: "n \<in> set xs" | |
| 2202 | unfolding xs | |
| 52902 | 2203 | apply (rule set_update_memI) | 
| 2204 | using i apply simp | |
| 2205 | done | |
| 60558 | 2206 | have xsl: "length xs = k + 1" | 
| 2207 | by (simp only: xs length_replicate length_list_update) | |
| 2208 |     have "listsum xs = setsum (nth xs) {0..<k+1}"
 | |
| 46131 | 2209 | unfolding listsum_setsum_nth xsl .. | 
| 29687 | 2210 |     also have "\<dots> = setsum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
 | 
| 60558 | 2211 | by (rule setsum.cong) (simp_all add: xs del: replicate.simps) | 
| 57418 | 2212 | also have "\<dots> = n" using i by (simp add: setsum.delta) | 
| 60558 | 2213 | finally have "xs \<in> natpermute n (k + 1)" | 
| 52902 | 2214 | using xsl unfolding natpermute_def mem_Collect_eq by blast | 
| 60558 | 2215 | then show "xs \<in> ?A" | 
| 2216 | using nxs by blast | |
| 2217 | qed | |
| 29687 | 2218 | qed | 
| 2219 | ||
| 60558 | 2220 | text \<open>The general form.\<close> | 
| 29687 | 2221 | lemma fps_setprod_nth: | 
| 52902 | 2222 | fixes m :: nat | 
| 54681 | 2223 | and a :: "nat \<Rightarrow> 'a::comm_ring_1 fps" | 
| 2224 |   shows "(setprod a {0 .. m}) $ n =
 | |
| 53196 | 2225 |     setsum (\<lambda>v. setprod (\<lambda>j. (a j) $ (v!j)) {0..m}) (natpermute n (m+1))"
 | 
| 29687 | 2226 | (is "?P m n") | 
| 52902 | 2227 | proof (induct m arbitrary: n rule: nat_less_induct) | 
| 29687 | 2228 | fix m n assume H: "\<forall>m' < m. \<forall>n. ?P m' n" | 
| 53196 | 2229 | show "?P m n" | 
| 2230 | proof (cases m) | |
| 2231 | case 0 | |
| 2232 | then show ?thesis | |
| 2233 | apply simp | |
| 2234 | unfolding natlist_trivial_1[where n = n, unfolded One_nat_def] | |
| 2235 | apply simp | |
| 2236 | done | |
| 2237 | next | |
| 2238 | case (Suc k) | |
| 2239 | then have km: "k < m" by arith | |
| 52902 | 2240 |     have u0: "{0 .. k} \<union> {m} = {0..m}"
 | 
| 54452 | 2241 | using Suc by (simp add: set_eq_iff) presburger | 
| 29687 | 2242 |     have f0: "finite {0 .. k}" "finite {m}" by auto
 | 
| 53196 | 2243 |     have d0: "{0 .. k} \<inter> {m} = {}" using Suc by auto
 | 
| 29687 | 2244 |     have "(setprod a {0 .. m}) $ n = (setprod a {0 .. k} * a m) $ n"
 | 
| 57418 | 2245 | unfolding setprod.union_disjoint[OF f0 d0, unfolded u0] by simp | 
| 29687 | 2246 |     also have "\<dots> = (\<Sum>i = 0..n. (\<Sum>v\<in>natpermute i (k + 1). \<Prod>j\<in>{0..k}. a j $ v ! j) * a m $ (n - i))"
 | 
| 2247 | unfolding fps_mult_nth H[rule_format, OF km] .. | |
| 2248 |     also have "\<dots> = (\<Sum>v\<in>natpermute n (m + 1). \<Prod>j\<in>{0..m}. a j $ v ! j)"
 | |
| 53196 | 2249 | apply (simp add: Suc) | 
| 48757 | 2250 | unfolding natpermute_split[of m "m + 1", simplified, of n, | 
| 53196 | 2251 | unfolded natlist_trivial_1[unfolded One_nat_def] Suc] | 
| 57418 | 2252 | apply (subst setsum.UNION_disjoint) | 
| 30488 | 2253 | apply simp | 
| 29687 | 2254 | apply simp | 
| 2255 | unfolding image_Collect[symmetric] | |
| 2256 | apply clarsimp | |
| 2257 | apply (rule finite_imageI) | |
| 2258 | apply (rule natpermute_finite) | |
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 2259 | apply (clarsimp simp add: set_eq_iff) | 
| 29687 | 2260 | apply auto | 
| 57418 | 2261 | apply (rule setsum.cong) | 
| 2262 | apply (rule refl) | |
| 29687 | 2263 | unfolding setsum_left_distrib | 
| 2264 | apply (rule sym) | |
| 57418 | 2265 | apply (rule_tac l = "\<lambda>xs. xs @ [n - x]" in setsum.reindex_cong) | 
| 29687 | 2266 | apply (simp add: inj_on_def) | 
| 2267 | apply auto | |
| 57418 | 2268 | unfolding setprod.union_disjoint[OF f0 d0, unfolded u0, unfolded Suc] | 
| 29687 | 2269 | apply (clarsimp simp add: natpermute_def nth_append) | 
| 2270 | done | |
| 53196 | 2271 | finally show ?thesis . | 
| 2272 | qed | |
| 29687 | 2273 | qed | 
| 2274 | ||
| 60558 | 2275 | text \<open>The special form for powers.\<close> | 
| 29687 | 2276 | lemma fps_power_nth_Suc: | 
| 52903 | 2277 | fixes m :: nat | 
| 54681 | 2278 | and a :: "'a::comm_ring_1 fps" | 
| 29687 | 2279 |   shows "(a ^ Suc m)$n = setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m}) (natpermute n (m+1))"
 | 
| 52902 | 2280 | proof - | 
| 54452 | 2281 |   have th0: "a^Suc m = setprod (\<lambda>i. a) {0..m}"
 | 
| 2282 | by (simp add: setprod_constant) | |
| 29687 | 2283 | show ?thesis unfolding th0 fps_setprod_nth .. | 
| 2284 | qed | |
| 52902 | 2285 | |
| 29687 | 2286 | lemma fps_power_nth: | 
| 54452 | 2287 | fixes m :: nat | 
| 54681 | 2288 | and a :: "'a::comm_ring_1 fps" | 
| 53196 | 2289 | shows "(a ^m)$n = | 
| 2290 |     (if m=0 then 1$n else setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m - 1}) (natpermute n m))"
 | |
| 52902 | 2291 | by (cases m) (simp_all add: fps_power_nth_Suc del: power_Suc) | 
| 29687 | 2292 | |
| 30488 | 2293 | lemma fps_nth_power_0: | 
| 54452 | 2294 | fixes m :: nat | 
| 54681 | 2295 | and a :: "'a::comm_ring_1 fps" | 
| 29687 | 2296 | shows "(a ^m)$0 = (a$0) ^ m" | 
| 53195 | 2297 | proof (cases m) | 
| 2298 | case 0 | |
| 2299 | then show ?thesis by simp | |
| 2300 | next | |
| 2301 | case (Suc n) | |
| 2302 |   then have c: "m = card {0..n}" by simp
 | |
| 2303 |   have "(a ^m)$0 = setprod (\<lambda>i. a$0) {0..n}"
 | |
| 2304 | by (simp add: Suc fps_power_nth del: replicate.simps power_Suc) | |
| 2305 | also have "\<dots> = (a$0) ^ m" | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62422diff
changeset | 2306 | unfolding c by (rule setprod_constant) | 
| 53195 | 2307 | finally show ?thesis . | 
| 29687 | 2308 | qed | 
| 2309 | ||
| 30488 | 2310 | lemma fps_compose_inj_right: | 
| 54681 | 2311 | assumes a0: "a$0 = (0::'a::idom)" | 
| 52902 | 2312 | and a1: "a$1 \<noteq> 0" | 
| 54681 | 2313 | shows "(b oo a = c oo a) \<longleftrightarrow> b = c" | 
| 2314 | (is "?lhs \<longleftrightarrow>?rhs") | |
| 53196 | 2315 | proof | 
| 60501 | 2316 | show ?lhs if ?rhs using that by simp | 
| 2317 | show ?rhs if ?lhs | |
| 2318 | proof - | |
| 2319 | have "b$n = c$n" for n | |
| 53196 | 2320 | proof (induct n rule: nat_less_induct) | 
| 2321 | fix n | |
| 2322 | assume H: "\<forall>m<n. b$m = c$m" | |
| 60501 | 2323 | show "b$n = c$n" | 
| 2324 | proof (cases n) | |
| 2325 | case 0 | |
| 2326 | from \<open>?lhs\<close> have "(b oo a)$n = (c oo a)$n" | |
| 2327 | by simp | |
| 2328 | then show ?thesis | |
| 2329 | using 0 by (simp add: fps_compose_nth) | |
| 2330 | next | |
| 2331 | case (Suc n1) | |
| 53196 | 2332 |         have f: "finite {0 .. n1}" "finite {n}" by simp_all
 | 
| 60501 | 2333 |         have eq: "{0 .. n1} \<union> {n} = {0 .. n}" using Suc by auto
 | 
| 2334 |         have d: "{0 .. n1} \<inter> {n} = {}" using Suc by auto
 | |
| 53196 | 2335 | have seq: "(\<Sum>i = 0..n1. b $ i * a ^ i $ n) = (\<Sum>i = 0..n1. c $ i * a ^ i $ n)" | 
| 57418 | 2336 | apply (rule setsum.cong) | 
| 60501 | 2337 | using H Suc | 
| 53196 | 2338 | apply auto | 
| 2339 | done | |
| 2340 | have th0: "(b oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + b$n * (a$1)^n" | |
| 57418 | 2341 | unfolding fps_compose_nth setsum.union_disjoint[OF f d, unfolded eq] seq | 
| 53196 | 2342 | using startsby_zero_power_nth_same[OF a0] | 
| 2343 | by simp | |
| 2344 | have th1: "(c oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + c$n * (a$1)^n" | |
| 57418 | 2345 | unfolding fps_compose_nth setsum.union_disjoint[OF f d, unfolded eq] | 
| 53196 | 2346 | using startsby_zero_power_nth_same[OF a0] | 
| 2347 | by simp | |
| 60501 | 2348 | from \<open>?lhs\<close>[unfolded fps_eq_iff, rule_format, of n] th0 th1 a1 | 
| 2349 | show ?thesis by auto | |
| 2350 | qed | |
| 2351 | qed | |
| 2352 | then show ?rhs by (simp add: fps_eq_iff) | |
| 2353 | qed | |
| 29687 | 2354 | qed | 
| 2355 | ||
| 2356 | ||
| 60500 | 2357 | subsection \<open>Radicals\<close> | 
| 29687 | 2358 | |
| 57418 | 2359 | declare setprod.cong [fundef_cong] | 
| 52903 | 2360 | |
| 54681 | 2361 | function radical :: "(nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a::field fps \<Rightarrow> nat \<Rightarrow> 'a" | 
| 52902 | 2362 | where | 
| 29687 | 2363 | "radical r 0 a 0 = 1" | 
| 2364 | | "radical r 0 a (Suc n) = 0" | |
| 2365 | | "radical r (Suc k) a 0 = r (Suc k) (a$0)" | |
| 48757 | 2366 | | "radical r (Suc k) a (Suc n) = | 
| 2367 |     (a$ Suc n - setsum (\<lambda>xs. setprod (\<lambda>j. radical r (Suc k) a (xs ! j)) {0..k})
 | |
| 2368 |       {xs. xs \<in> natpermute (Suc n) (Suc k) \<and> Suc n \<notin> set xs}) /
 | |
| 2369 | (of_nat (Suc k) * (radical r (Suc k) a 0)^k)" | |
| 52902 | 2370 | by pat_completeness auto | 
| 29687 | 2371 | |
| 2372 | termination radical | |
| 2373 | proof | |
| 2374 | let ?R = "measure (\<lambda>(r, k, a, n). n)" | |
| 2375 |   {
 | |
| 52902 | 2376 | show "wf ?R" by auto | 
| 2377 | next | |
| 2378 | fix r k a n xs i | |
| 29687 | 2379 |     assume xs: "xs \<in> {xs \<in> natpermute (Suc n) (Suc k). Suc n \<notin> set xs}" and i: "i \<in> {0..k}"
 | 
| 60558 | 2380 | have False if c: "Suc n \<le> xs ! i" | 
| 2381 | proof - | |
| 52902 | 2382 | from xs i have "xs !i \<noteq> Suc n" | 
| 2383 | by (auto simp add: in_set_conv_nth natpermute_def) | |
| 29687 | 2384 | with c have c': "Suc n < xs!i" by arith | 
| 52902 | 2385 |       have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}"
 | 
| 2386 | by simp_all | |
| 2387 |       have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}"
 | |
| 2388 | by auto | |
| 2389 |       have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})"
 | |
| 2390 | using i by auto | |
| 2391 | from xs have "Suc n = listsum xs" | |
| 2392 | by (simp add: natpermute_def) | |
| 46131 | 2393 |       also have "\<dots> = setsum (nth xs) {0..<Suc k}" using xs
 | 
| 2394 | by (simp add: natpermute_def listsum_setsum_nth) | |
| 29687 | 2395 |       also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
 | 
| 57418 | 2396 | unfolding eqs setsum.union_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)] | 
| 2397 | unfolding setsum.union_disjoint[OF fths(2) fths(3) d(2)] | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2398 | by simp | 
| 60558 | 2399 | finally show ?thesis using c' by simp | 
| 2400 | qed | |
| 52902 | 2401 | then show "((r, Suc k, a, xs!i), r, Suc k, a, Suc n) \<in> ?R" | 
| 2402 | apply auto | |
| 2403 | apply (metis not_less) | |
| 2404 | done | |
| 2405 | next | |
| 2406 | fix r k a n | |
| 2407 | show "((r, Suc k, a, 0), r, Suc k, a, Suc n) \<in> ?R" by simp | |
| 2408 | } | |
| 29687 | 2409 | qed | 
| 2410 | ||
| 2411 | definition "fps_radical r n a = Abs_fps (radical r n a)" | |
| 2412 | ||
| 2413 | lemma fps_radical0[simp]: "fps_radical r 0 a = 1" | |
| 52902 | 2414 | apply (auto simp add: fps_eq_iff fps_radical_def) | 
| 2415 | apply (case_tac n) | |
| 2416 | apply auto | |
| 2417 | done | |
| 29687 | 2418 | |
| 60501 | 2419 | lemma fps_radical_nth_0[simp]: "fps_radical r n a $ 0 = (if n = 0 then 1 else r n (a$0))" | 
| 52902 | 2420 | by (cases n) (simp_all add: fps_radical_def) | 
| 29687 | 2421 | |
| 30488 | 2422 | lemma fps_radical_power_nth[simp]: | 
| 29687 | 2423 | assumes r: "(r k (a$0)) ^ k = a$0" | 
| 2424 | shows "fps_radical r k a ^ k $ 0 = (if k = 0 then 1 else a$0)" | |
| 53196 | 2425 | proof (cases k) | 
| 2426 | case 0 | |
| 2427 | then show ?thesis by simp | |
| 2428 | next | |
| 2429 | case (Suc h) | |
| 2430 |   have eq1: "fps_radical r k a ^ k $ 0 = (\<Prod>j\<in>{0..h}. fps_radical r k a $ (replicate k 0) ! j)"
 | |
| 2431 | unfolding fps_power_nth Suc by simp | |
| 2432 |   also have "\<dots> = (\<Prod>j\<in>{0..h}. r k (a$0))"
 | |
| 57418 | 2433 | apply (rule setprod.cong) | 
| 53196 | 2434 | apply simp | 
| 2435 | using Suc | |
| 54681 | 2436 | apply (subgoal_tac "replicate k 0 ! x = 0") | 
| 53196 | 2437 | apply (auto intro: nth_replicate simp del: replicate.simps) | 
| 2438 | done | |
| 60501 | 2439 | also have "\<dots> = a$0" | 
| 2440 | using r Suc by (simp add: setprod_constant) | |
| 2441 | finally show ?thesis | |
| 2442 | using Suc by simp | |
| 30488 | 2443 | qed | 
| 29687 | 2444 | |
| 52902 | 2445 | lemma natpermute_max_card: | 
| 54452 | 2446 | assumes n0: "n \<noteq> 0" | 
| 60558 | 2447 |   shows "card {xs \<in> natpermute n (k + 1). n \<in> set xs} = k + 1"
 | 
| 29687 | 2448 | unfolding natpermute_contain_maximal | 
| 52902 | 2449 | proof - | 
| 60501 | 2450 |   let ?A = "\<lambda>i. {replicate (k + 1) 0[i := n]}"
 | 
| 29687 | 2451 |   let ?K = "{0 ..k}"
 | 
| 60501 | 2452 | have fK: "finite ?K" | 
| 2453 | by simp | |
| 2454 | have fAK: "\<forall>i\<in>?K. finite (?A i)" | |
| 2455 | by auto | |
| 48757 | 2456 | have d: "\<forall>i\<in> ?K. \<forall>j\<in> ?K. i \<noteq> j \<longrightarrow> | 
| 2457 |     {replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
 | |
| 52902 | 2458 | proof clarify | 
| 2459 | fix i j | |
| 60501 | 2460 | assume i: "i \<in> ?K" and j: "j \<in> ?K" and ij: "i \<noteq> j" | 
| 60558 | 2461 | have False if eq: "replicate (k+1) 0 [i:=n] = replicate (k+1) 0 [j:= n]" | 
| 2462 | proof - | |
| 52902 | 2463 | have "(replicate (k+1) 0 [i:=n] ! i) = n" | 
| 2464 | using i by (simp del: replicate.simps) | |
| 29687 | 2465 | moreover | 
| 52902 | 2466 | have "(replicate (k+1) 0 [j:=n] ! i) = 0" | 
| 2467 | using i ij by (simp del: replicate.simps) | |
| 60558 | 2468 | ultimately show ?thesis | 
| 52902 | 2469 | using eq n0 by (simp del: replicate.simps) | 
| 60558 | 2470 | qed | 
| 29687 | 2471 |     then show "{replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
 | 
| 2472 | by auto | |
| 2473 | qed | |
| 54452 | 2474 | from card_UN_disjoint[OF fK fAK d] | 
| 2475 |   show "card (\<Union>i\<in>{0..k}. {replicate (k + 1) 0[i := n]}) = k + 1"
 | |
| 52902 | 2476 | by simp | 
| 29687 | 2477 | qed | 
| 30488 | 2478 | |
| 2479 | lemma power_radical: | |
| 31273 | 2480 | fixes a:: "'a::field_char_0 fps" | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2481 | assumes a0: "a$0 \<noteq> 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2482 | shows "(r (Suc k) (a$0)) ^ Suc k = a$0 \<longleftrightarrow> (fps_radical r (Suc k) a) ^ (Suc k) = a" | 
| 60558 | 2483 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 2484 | proof | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2485 | let ?r = "fps_radical r (Suc k) a" | 
| 60558 | 2486 | show ?rhs if r0: ?lhs | 
| 2487 | proof - | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2488 | from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto | 
| 60501 | 2489 | have "?r ^ Suc k $ z = a$z" for z | 
| 2490 | proof (induct z rule: nat_less_induct) | |
| 2491 | fix n | |
| 2492 | assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m" | |
| 2493 | show "?r ^ Suc k $ n = a $n" | |
| 2494 | proof (cases n) | |
| 2495 | case 0 | |
| 2496 | then show ?thesis | |
| 2497 | using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp | |
| 2498 | next | |
| 2499 | case (Suc n1) | |
| 2500 | then have "n \<noteq> 0" by simp | |
| 2501 | let ?Pnk = "natpermute n (k + 1)" | |
| 2502 |         let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
 | |
| 2503 |         let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
 | |
| 2504 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | |
| 2505 |         have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | |
| 2506 | have f: "finite ?Pnkn" "finite ?Pnknn" | |
| 2507 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | |
| 2508 | by (metis natpermute_finite)+ | |
| 2509 |         let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
 | |
| 2510 | have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn" | |
| 2511 | proof (rule setsum.cong) | |
| 2512 |           fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
 | |
| 2513 |           let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
 | |
| 2514 | fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k" | |
| 2515 |           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
 | |
| 2516 | unfolding natpermute_contain_maximal by auto | |
| 2517 |           have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
 | |
| 2518 |               (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
 | |
| 2519 | apply (rule setprod.cong, simp) | |
| 2520 | using i r0 | |
| 2521 | apply (simp del: replicate.simps) | |
| 2522 | done | |
| 2523 | also have "\<dots> = (fps_radical r (Suc k) a $ n) * r (Suc k) (a$0) ^ k" | |
| 2524 | using i r0 by (simp add: setprod_gen_delta) | |
| 2525 | finally show ?ths . | |
| 2526 | qed rule | |
| 2527 | then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k" | |
| 2528 | by (simp add: natpermute_max_card[OF \<open>n \<noteq> 0\<close>, simplified]) | |
| 2529 | also have "\<dots> = a$n - setsum ?f ?Pnknn" | |
| 2530 | unfolding Suc using r00 a0 by (simp add: field_simps fps_radical_def del: of_nat_Suc) | |
| 2531 | finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" . | |
| 2532 | have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn" | |
| 2533 | unfolding fps_power_nth_Suc setsum.union_disjoint[OF f d, unfolded eq] .. | |
| 2534 | also have "\<dots> = a$n" unfolding fn by simp | |
| 2535 | finally show ?thesis . | |
| 52903 | 2536 | qed | 
| 60501 | 2537 | qed | 
| 60558 | 2538 | then show ?thesis using r0 by (simp add: fps_eq_iff) | 
| 2539 | qed | |
| 2540 | show ?lhs if ?rhs | |
| 2541 | proof - | |
| 2542 | from that have "((fps_radical r (Suc k) a) ^ (Suc k))$0 = a$0" | |
| 2543 | by simp | |
| 2544 | then show ?thesis | |
| 52903 | 2545 | unfolding fps_power_nth_Suc | 
| 2546 | by (simp add: setprod_constant del: replicate.simps) | |
| 60558 | 2547 | qed | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2548 | qed | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2549 | |
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2550 | (* | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2551 | lemma power_radical: | 
| 31273 | 2552 | fixes a:: "'a::field_char_0 fps" | 
| 29687 | 2553 | assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" and a0: "a$0 \<noteq> 0" | 
| 30488 | 2554 | shows "(fps_radical r (Suc k) a) ^ (Suc k) = a" | 
| 29687 | 2555 | proof- | 
| 2556 | let ?r = "fps_radical r (Suc k) a" | |
| 2557 | from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto | |
| 2558 |   {fix z have "?r ^ Suc k $ z = a$z"
 | |
| 2559 | proof(induct z rule: nat_less_induct) | |
| 2560 | fix n assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m" | |
| 54452 | 2561 |       {assume "n = 0" then have "?r ^ Suc k $ n = a $n"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2562 | using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp} | 
| 29687 | 2563 | moreover | 
| 2564 |       {fix n1 assume n1: "n = Suc n1"
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2565 |         have fK: "finite {0..k}" by simp
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2566 | have nz: "n \<noteq> 0" using n1 by arith | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2567 | let ?Pnk = "natpermute n (k + 1)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2568 |         let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2569 |         let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2570 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2571 |         have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2572 | have f: "finite ?Pnkn" "finite ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2573 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2574 | by (metis natpermute_finite)+ | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2575 |         let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2576 | have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn" | 
| 57418 | 2577 | proof(rule setsum.cong2) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2578 |           fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2579 |           let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) = fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2580 |           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2581 | unfolding natpermute_contain_maximal by auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2582 |           have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
 | 
| 57418 | 2583 | apply (rule setprod.cong, simp) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2584 | using i r0 by (simp del: replicate.simps) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2585 | also have "\<dots> = (fps_radical r (Suc k) a $ n) * r (Suc k) (a$0) ^ k" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2586 | unfolding setprod_gen_delta[OF fK] using i r0 by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2587 | finally show ?ths . | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2588 | qed | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2589 | then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2590 | by (simp add: natpermute_max_card[OF nz, simplified]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2591 | also have "\<dots> = a$n - setsum ?f ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2592 | unfolding n1 using r00 a0 by (simp add: field_simps fps_radical_def del: of_nat_Suc ) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2593 | finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" . | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2594 | have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn" | 
| 57418 | 2595 | unfolding fps_power_nth_Suc setsum.union_disjoint[OF f d, unfolded eq] .. | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2596 | also have "\<dots> = a$n" unfolding fn by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2597 | finally have "?r ^ Suc k $ n = a $n" .} | 
| 29687 | 2598 | ultimately show "?r ^ Suc k $ n = a $n" by (cases n, auto) | 
| 2599 | qed } | |
| 2600 | then show ?thesis by (simp add: fps_eq_iff) | |
| 2601 | qed | |
| 2602 | ||
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2603 | *) | 
| 52903 | 2604 | lemma eq_divide_imp': | 
| 60501 | 2605 | fixes c :: "'a::field" | 
| 2606 | shows "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c" | |
| 56480 
093ea91498e6
field_simps: better support for negation and division, and power
 hoelzl parents: 
56479diff
changeset | 2607 | by (simp add: field_simps) | 
| 29687 | 2608 | |
| 30488 | 2609 | lemma radical_unique: | 
| 2610 | assumes r0: "(r (Suc k) (b$0)) ^ Suc k = b$0" | |
| 52903 | 2611 | and a0: "r (Suc k) (b$0 ::'a::field_char_0) = a$0" | 
| 2612 | and b0: "b$0 \<noteq> 0" | |
| 29687 | 2613 | shows "a^(Suc k) = b \<longleftrightarrow> a = fps_radical r (Suc k) b" | 
| 60501 | 2614 | (is "?lhs \<longleftrightarrow> ?rhs" is "_ \<longleftrightarrow> a = ?r") | 
| 2615 | proof | |
| 2616 | show ?lhs if ?rhs | |
| 2617 | using that using power_radical[OF b0, of r k, unfolded r0] by simp | |
| 2618 | show ?rhs if ?lhs | |
| 2619 | proof - | |
| 2620 | have r00: "r (Suc k) (b$0) \<noteq> 0" using b0 r0 by auto | |
| 29687 | 2621 |     have ceq: "card {0..k} = Suc k" by simp
 | 
| 2622 | from a0 have a0r0: "a$0 = ?r$0" by simp | |
| 60501 | 2623 | have "a $ n = ?r $ n" for n | 
| 2624 | proof (induct n rule: nat_less_induct) | |
| 52903 | 2625 | fix n | 
| 60501 | 2626 | assume h: "\<forall>m<n. a$m = ?r $m" | 
| 2627 | show "a$n = ?r $ n" | |
| 2628 | proof (cases n) | |
| 2629 | case 0 | |
| 2630 | then show ?thesis using a0 by simp | |
| 2631 | next | |
| 2632 | case (Suc n1) | |
| 2633 |         have fK: "finite {0..k}" by simp
 | |
| 2634 | have nz: "n \<noteq> 0" using Suc by simp | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2635 | let ?Pnk = "natpermute n (Suc k)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2636 |         let ?Pnkn = "{xs \<in> ?Pnk. n \<in> set xs}"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2637 |         let ?Pnknn = "{xs \<in> ?Pnk. n \<notin> set xs}"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2638 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2639 |         have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2640 | have f: "finite ?Pnkn" "finite ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2641 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2642 | by (metis natpermute_finite)+ | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2643 |         let ?f = "\<lambda>v. \<Prod>j\<in>{0..k}. ?r $ v ! j"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2644 |         let ?g = "\<lambda>v. \<Prod>j\<in>{0..k}. a $ v ! j"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2645 | have "setsum ?g ?Pnkn = setsum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn" | 
| 57418 | 2646 | proof (rule setsum.cong) | 
| 52903 | 2647 | fix v | 
| 2648 |           assume v: "v \<in> {xs \<in> natpermute n (Suc k). n \<in> set xs}"
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2649 |           let ?ths = "(\<Prod>j\<in>{0..k}. a $ v ! j) = a $ n * (?r$0)^k"
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2650 |           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
 | 
| 52903 | 2651 | unfolding Suc_eq_plus1 natpermute_contain_maximal | 
| 2652 | by (auto simp del: replicate.simps) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2653 |           have "(\<Prod>j\<in>{0..k}. a $ v ! j) = (\<Prod>j\<in>{0..k}. if j = i then a $ n else r (Suc k) (b$0))"
 | 
| 57418 | 2654 | apply (rule setprod.cong, simp) | 
| 54452 | 2655 | using i a0 | 
| 2656 | apply (simp del: replicate.simps) | |
| 52903 | 2657 | done | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2658 | also have "\<dots> = a $ n * (?r $ 0)^k" | 
| 46757 | 2659 | using i by (simp add: setprod_gen_delta) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2660 | finally show ?ths . | 
| 57418 | 2661 | qed rule | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2662 | then have th0: "setsum ?g ?Pnkn = of_nat (k+1) * a $ n * (?r $ 0)^k" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2663 | by (simp add: natpermute_max_card[OF nz, simplified]) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2664 | have th1: "setsum ?g ?Pnknn = setsum ?f ?Pnknn" | 
| 57418 | 2665 | proof (rule setsum.cong, rule refl, rule setprod.cong, simp) | 
| 52903 | 2666 | fix xs i | 
| 2667 |           assume xs: "xs \<in> ?Pnknn" and i: "i \<in> {0..k}"
 | |
| 60501 | 2668 | have False if c: "n \<le> xs ! i" | 
| 2669 | proof - | |
| 2670 | from xs i have "xs ! i \<noteq> n" | |
| 52903 | 2671 | by (auto simp add: in_set_conv_nth natpermute_def) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2672 | with c have c': "n < xs!i" by arith | 
| 52903 | 2673 |             have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}"
 | 
| 2674 | by simp_all | |
| 2675 |             have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}"
 | |
| 2676 | by auto | |
| 2677 |             have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})"
 | |
| 2678 | using i by auto | |
| 2679 | from xs have "n = listsum xs" | |
| 2680 | by (simp add: natpermute_def) | |
| 2681 |             also have "\<dots> = setsum (nth xs) {0..<Suc k}"
 | |
| 2682 | using xs by (simp add: natpermute_def listsum_setsum_nth) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2683 |             also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
 | 
| 57418 | 2684 | unfolding eqs setsum.union_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)] | 
| 2685 | unfolding setsum.union_disjoint[OF fths(2) fths(3) d(2)] | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2686 | by simp | 
| 60501 | 2687 | finally show ?thesis using c' by simp | 
| 2688 | qed | |
| 52902 | 2689 | then have thn: "xs!i < n" by presburger | 
| 52903 | 2690 | from h[rule_format, OF thn] show "a$(xs !i) = ?r$(xs!i)" . | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2691 | qed | 
| 54681 | 2692 | have th00: "\<And>x::'a. of_nat (Suc k) * (x * inverse (of_nat (Suc k))) = x" | 
| 36350 | 2693 | by (simp add: field_simps del: of_nat_Suc) | 
| 60501 | 2694 | from \<open>?lhs\<close> have "b$n = a^Suc k $ n" | 
| 52903 | 2695 | by (simp add: fps_eq_iff) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2696 | also have "a ^ Suc k$n = setsum ?g ?Pnkn + setsum ?g ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2697 | unfolding fps_power_nth_Suc | 
| 57418 | 2698 | using setsum.union_disjoint[OF f d, unfolded Suc_eq_plus1[symmetric], | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2699 | unfolded eq, of ?g] by simp | 
| 52903 | 2700 | also have "\<dots> = of_nat (k+1) * a $ n * (?r $ 0)^k + setsum ?f ?Pnknn" | 
| 2701 | unfolding th0 th1 .. | |
| 2702 | finally have "of_nat (k+1) * a $ n * (?r $ 0)^k = b$n - setsum ?f ?Pnknn" | |
| 2703 | by simp | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2704 | then have "a$n = (b$n - setsum ?f ?Pnknn) / (of_nat (k+1) * (?r $ 0)^k)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2705 | apply - | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2706 | apply (rule eq_divide_imp') | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2707 | using r00 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2708 | apply (simp del: of_nat_Suc) | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 2709 | apply (simp add: ac_simps) | 
| 52903 | 2710 | done | 
| 60501 | 2711 | then show ?thesis | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2712 | apply (simp del: of_nat_Suc) | 
| 60501 | 2713 | unfolding fps_radical_def Suc | 
| 2714 | apply (simp add: field_simps Suc th00 del: of_nat_Suc) | |
| 52903 | 2715 | done | 
| 2716 | qed | |
| 60501 | 2717 | qed | 
| 2718 | then show ?rhs by (simp add: fps_eq_iff) | |
| 2719 | qed | |
| 29687 | 2720 | qed | 
| 2721 | ||
| 2722 | ||
| 30488 | 2723 | lemma radical_power: | 
| 2724 | assumes r0: "r (Suc k) ((a$0) ^ Suc k) = a$0" | |
| 54681 | 2725 | and a0: "(a$0 :: 'a::field_char_0) \<noteq> 0" | 
| 29687 | 2726 | shows "(fps_radical r (Suc k) (a ^ Suc k)) = a" | 
| 52903 | 2727 | proof - | 
| 29687 | 2728 | let ?ak = "a^ Suc k" | 
| 52903 | 2729 | have ak0: "?ak $ 0 = (a$0) ^ Suc k" | 
| 2730 | by (simp add: fps_nth_power_0 del: power_Suc) | |
| 2731 | from r0 have th0: "r (Suc k) (a ^ Suc k $ 0) ^ Suc k = a ^ Suc k $ 0" | |
| 2732 | using ak0 by auto | |
| 2733 | from r0 ak0 have th1: "r (Suc k) (a ^ Suc k $ 0) = a $ 0" | |
| 2734 | by auto | |
| 2735 | from ak0 a0 have ak00: "?ak $ 0 \<noteq>0 " | |
| 2736 | by auto | |
| 2737 | from radical_unique[of r k ?ak a, OF th0 th1 ak00] show ?thesis | |
| 2738 | by metis | |
| 29687 | 2739 | qed | 
| 2740 | ||
| 30488 | 2741 | lemma fps_deriv_radical: | 
| 54681 | 2742 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2743 | assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" | 
| 2744 | and a0: "a$0 \<noteq> 0" | |
| 53196 | 2745 | shows "fps_deriv (fps_radical r (Suc k) a) = | 
| 2746 | fps_deriv a / (fps_const (of_nat (Suc k)) * (fps_radical r (Suc k) a) ^ k)" | |
| 52903 | 2747 | proof - | 
| 2748 | let ?r = "fps_radical r (Suc k) a" | |
| 29687 | 2749 | let ?w = "(fps_const (of_nat (Suc k)) * ?r ^ k)" | 
| 52903 | 2750 | from a0 r0 have r0': "r (Suc k) (a$0) \<noteq> 0" | 
| 2751 | by auto | |
| 2752 | from r0' have w0: "?w $ 0 \<noteq> 0" | |
| 2753 | by (simp del: of_nat_Suc) | |
| 29687 | 2754 | note th0 = inverse_mult_eq_1[OF w0] | 
| 2755 | let ?iw = "inverse ?w" | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2756 | from iffD1[OF power_radical[of a r], OF a0 r0] | 
| 52903 | 2757 | have "fps_deriv (?r ^ Suc k) = fps_deriv a" | 
| 2758 | by simp | |
| 54452 | 2759 | then have "fps_deriv ?r * ?w = fps_deriv a" | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 2760 | by (simp add: fps_deriv_power ac_simps del: power_Suc) | 
| 54452 | 2761 | then have "?iw * fps_deriv ?r * ?w = ?iw * fps_deriv a" | 
| 52903 | 2762 | by simp | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2763 | with a0 r0 have "fps_deriv ?r * (?iw * ?w) = fps_deriv a / ?w" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2764 | by (subst fps_divide_unit) (auto simp del: of_nat_Suc) | 
| 30488 | 2765 | then show ?thesis unfolding th0 by simp | 
| 29687 | 2766 | qed | 
| 2767 | ||
| 30488 | 2768 | lemma radical_mult_distrib: | 
| 54681 | 2769 | fixes a :: "'a::field_char_0 fps" | 
| 48757 | 2770 | assumes k: "k > 0" | 
| 2771 | and ra0: "r k (a $ 0) ^ k = a $ 0" | |
| 2772 | and rb0: "r k (b $ 0) ^ k = b $ 0" | |
| 60558 | 2773 | and a0: "a $ 0 \<noteq> 0" | 
| 2774 | and b0: "b $ 0 \<noteq> 0" | |
| 48757 | 2775 | shows "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0) \<longleftrightarrow> | 
| 60558 | 2776 | fps_radical r k (a * b) = fps_radical r k a * fps_radical r k b" | 
| 2777 | (is "?lhs \<longleftrightarrow> ?rhs") | |
| 2778 | proof | |
| 2779 | show ?rhs if r0': ?lhs | |
| 2780 | proof - | |
| 2781 | from r0' have r0: "(r k ((a * b) $ 0)) ^ k = (a * b) $ 0" | |
| 52903 | 2782 | by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib) | 
| 60558 | 2783 | show ?thesis | 
| 60501 | 2784 | proof (cases k) | 
| 2785 | case 0 | |
| 2786 | then show ?thesis using r0' by simp | |
| 2787 | next | |
| 2788 | case (Suc h) | |
| 52903 | 2789 | let ?ra = "fps_radical r (Suc h) a" | 
| 2790 | let ?rb = "fps_radical r (Suc h) b" | |
| 2791 | have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0" | |
| 60501 | 2792 | using r0' Suc by (simp add: fps_mult_nth) | 
| 52903 | 2793 | have ab0: "(a*b) $ 0 \<noteq> 0" | 
| 2794 | using a0 b0 by (simp add: fps_mult_nth) | |
| 60501 | 2795 | from radical_unique[of r h "a*b" "fps_radical r (Suc h) a * fps_radical r (Suc h) b", OF r0[unfolded Suc] th0 ab0, symmetric] | 
| 2796 | iffD1[OF power_radical[of _ r], OF a0 ra0[unfolded Suc]] iffD1[OF power_radical[of _ r], OF b0 rb0[unfolded Suc]] Suc r0' | |
| 2797 | show ?thesis | |
| 2798 | by (auto simp add: power_mult_distrib simp del: power_Suc) | |
| 2799 | qed | |
| 60558 | 2800 | qed | 
| 2801 | show ?lhs if ?rhs | |
| 2802 | proof - | |
| 2803 | from that have "(fps_radical r k (a * b)) $ 0 = (fps_radical r k a * fps_radical r k b) $ 0" | |
| 52903 | 2804 | by simp | 
| 60558 | 2805 | then show ?thesis | 
| 52903 | 2806 | using k by (simp add: fps_mult_nth) | 
| 60558 | 2807 | qed | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2808 | qed | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2809 | |
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2810 | (* | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2811 | lemma radical_mult_distrib: | 
| 31273 | 2812 | fixes a:: "'a::field_char_0 fps" | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2813 | assumes | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2814 | ra0: "r k (a $ 0) ^ k = a $ 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2815 | and rb0: "r k (b $ 0) ^ k = b $ 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2816 | and r0': "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)" | 
| 29687 | 2817 | and a0: "a$0 \<noteq> 0" | 
| 2818 | and b0: "b$0 \<noteq> 0" | |
| 2819 | shows "fps_radical r (k) (a*b) = fps_radical r (k) a * fps_radical r (k) (b)" | |
| 2820 | proof- | |
| 2821 | from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0" | |
| 2822 | by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib) | |
| 54452 | 2823 |   {assume "k=0" then have ?thesis by simp}
 | 
| 29687 | 2824 | moreover | 
| 2825 |   {fix h assume k: "k = Suc h"
 | |
| 2826 | let ?ra = "fps_radical r (Suc h) a" | |
| 2827 | let ?rb = "fps_radical r (Suc h) b" | |
| 30488 | 2828 | have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0" | 
| 29687 | 2829 | using r0' k by (simp add: fps_mult_nth) | 
| 2830 | have ab0: "(a*b) $ 0 \<noteq> 0" using a0 b0 by (simp add: fps_mult_nth) | |
| 30488 | 2831 | from radical_unique[of r h "a*b" "fps_radical r (Suc h) a * fps_radical r (Suc h) b", OF r0[unfolded k] th0 ab0, symmetric] | 
| 29687 | 2832 | power_radical[of r, OF ra0[unfolded k] a0] power_radical[of r, OF rb0[unfolded k] b0] k | 
| 30273 
ecd6f0ca62ea
declare power_Suc [simp]; remove redundant type-specific versions of power_Suc
 huffman parents: 
29915diff
changeset | 2833 | have ?thesis by (auto simp add: power_mult_distrib simp del: power_Suc)} | 
| 29687 | 2834 | ultimately show ?thesis by (cases k, auto) | 
| 2835 | qed | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2836 | *) | 
| 29687 | 2837 | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2838 | lemma fps_divide_1 [simp]: "(a :: 'a::field fps) / 1 = a" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2839 | by (fact divide_1) | 
| 29687 | 2840 | |
| 2841 | lemma radical_divide: | |
| 31273 | 2842 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2843 | assumes kp: "k > 0" | 
| 2844 | and ra0: "(r k (a $ 0)) ^ k = a $ 0" | |
| 2845 | and rb0: "(r k (b $ 0)) ^ k = b $ 0" | |
| 2846 | and a0: "a$0 \<noteq> 0" | |
| 2847 | and b0: "b$0 \<noteq> 0" | |
| 2848 | shows "r k ((a $ 0) / (b$0)) = r k (a$0) / r k (b $ 0) \<longleftrightarrow> | |
| 2849 | fps_radical r k (a/b) = fps_radical r k a / fps_radical r k b" | |
| 2850 | (is "?lhs = ?rhs") | |
| 60501 | 2851 | proof | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2852 | let ?r = "fps_radical r k" | 
| 60558 | 2853 | from kp obtain h where k: "k = Suc h" | 
| 2854 | by (cases k) auto | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2855 | have ra0': "r k (a$0) \<noteq> 0" using a0 ra0 k by auto | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2856 | have rb0': "r k (b$0) \<noteq> 0" using b0 rb0 k by auto | 
| 30488 | 2857 | |
| 60501 | 2858 | show ?lhs if ?rhs | 
| 2859 | proof - | |
| 2860 | from that have "?r (a/b) $ 0 = (?r a / ?r b)$0" | |
| 2861 | by simp | |
| 2862 | then show ?thesis | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2863 | using k a0 b0 rb0' by (simp add: fps_divide_unit fps_mult_nth fps_inverse_def divide_inverse) | 
| 60501 | 2864 | qed | 
| 2865 | show ?rhs if ?lhs | |
| 2866 | proof - | |
| 52891 | 2867 | from a0 b0 have ab0[simp]: "(a/b)$0 = a$0 / b$0" | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2868 | by (simp add: fps_divide_def fps_mult_nth divide_inverse fps_inverse_def) | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2869 | have th0: "r k ((a/b)$0) ^ k = (a/b)$0" | 
| 60867 | 2870 | by (simp add: \<open>?lhs\<close> power_divide ra0 rb0) | 
| 60501 | 2871 | from a0 b0 ra0' rb0' kp \<open>?lhs\<close> | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2872 | have th1: "r k ((a / b) $ 0) = (fps_radical r k a / fps_radical r k b) $ 0" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2873 | by (simp add: fps_divide_unit fps_mult_nth fps_inverse_def divide_inverse) | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2874 | from a0 b0 ra0' rb0' kp have ab0': "(a / b) $ 0 \<noteq> 0" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2875 | by (simp add: fps_divide_unit fps_mult_nth fps_inverse_def nonzero_imp_inverse_nonzero) | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2876 | note tha[simp] = iffD1[OF power_radical[where r=r and k=h], OF a0 ra0[unfolded k], unfolded k[symmetric]] | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2877 | note thb[simp] = iffD1[OF power_radical[where r=r and k=h], OF b0 rb0[unfolded k], unfolded k[symmetric]] | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2878 | from b0 rb0' have th2: "(?r a / ?r b)^k = a/b" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 2879 | by (simp add: fps_divide_unit power_mult_distrib fps_inverse_power[symmetric]) | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 2880 | |
| 52902 | 2881 | from iffD1[OF radical_unique[where r=r and a="?r a / ?r b" and b="a/b" and k=h], symmetric, unfolded k[symmetric], OF th0 th1 ab0' th2] | 
| 60501 | 2882 | show ?thesis . | 
| 2883 | qed | |
| 29687 | 2884 | qed | 
| 2885 | ||
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2886 | lemma radical_inverse: | 
| 31273 | 2887 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2888 | assumes k: "k > 0" | 
| 2889 | and ra0: "r k (a $ 0) ^ k = a $ 0" | |
| 2890 | and r1: "(r k 1)^k = 1" | |
| 2891 | and a0: "a$0 \<noteq> 0" | |
| 53196 | 2892 | shows "r k (inverse (a $ 0)) = r k 1 / (r k (a $ 0)) \<longleftrightarrow> | 
| 2893 | fps_radical r k (inverse a) = fps_radical r k 1 / fps_radical r k a" | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2894 | using radical_divide[where k=k and r=r and a=1 and b=a, OF k ] ra0 r1 a0 | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2895 | by (simp add: divide_inverse fps_divide_def) | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2896 | |
| 60501 | 2897 | |
| 2898 | subsection \<open>Derivative of composition\<close> | |
| 29687 | 2899 | |
| 30488 | 2900 | lemma fps_compose_deriv: | 
| 54681 | 2901 | fixes a :: "'a::idom fps" | 
| 29687 | 2902 | assumes b0: "b$0 = 0" | 
| 54681 | 2903 | shows "fps_deriv (a oo b) = ((fps_deriv a) oo b) * fps_deriv b" | 
| 52903 | 2904 | proof - | 
| 60501 | 2905 | have "(fps_deriv (a oo b))$n = (((fps_deriv a) oo b) * (fps_deriv b)) $n" for n | 
| 2906 | proof - | |
| 29687 | 2907 |     have "(fps_deriv (a oo b))$n = setsum (\<lambda>i. a $ i * (fps_deriv (b^i))$n) {0.. Suc n}"
 | 
| 36350 | 2908 | by (simp add: fps_compose_def field_simps setsum_right_distrib del: of_nat_Suc) | 
| 29687 | 2909 |     also have "\<dots> = setsum (\<lambda>i. a$i * ((fps_const (of_nat i)) * (fps_deriv b * (b^(i - 1))))$n) {0.. Suc n}"
 | 
| 36350 | 2910 | by (simp add: field_simps fps_deriv_power del: fps_mult_left_const_nth of_nat_Suc) | 
| 52903 | 2911 |     also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (((b^(i - 1)) * fps_deriv b))$n) {0.. Suc n}"
 | 
| 2912 | unfolding fps_mult_left_const_nth by (simp add: field_simps) | |
| 2913 |     also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (setsum (\<lambda>j. (b^ (i - 1))$j * (fps_deriv b)$(n - j)) {0..n})) {0.. Suc n}"
 | |
| 2914 | unfolding fps_mult_nth .. | |
| 2915 |     also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (setsum (\<lambda>j. (b^ (i - 1))$j * (fps_deriv b)$(n - j)) {0..n})) {1.. Suc n}"
 | |
| 57418 | 2916 | apply (rule setsum.mono_neutral_right) | 
| 2917 | apply (auto simp add: mult_delta_left setsum.delta not_le) | |
| 52903 | 2918 | done | 
| 2919 |     also have "\<dots> = setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}"
 | |
| 2920 | unfolding fps_deriv_nth | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2921 | by (rule setsum.reindex_cong [of Suc]) (auto simp add: mult.assoc) | 
| 52903 | 2922 | finally have th0: "(fps_deriv (a oo b))$n = | 
| 2923 |       setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}" .
 | |
| 2924 | ||
| 2925 |     have "(((fps_deriv a) oo b) * (fps_deriv b))$n = setsum (\<lambda>i. (fps_deriv b)$ (n - i) * ((fps_deriv a) oo b)$i) {0..n}"
 | |
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 2926 | unfolding fps_mult_nth by (simp add: ac_simps) | 
| 52903 | 2927 |     also have "\<dots> = setsum (\<lambda>i. setsum (\<lambda>j. of_nat (n - i +1) * b$(n - i + 1) * of_nat (j + 1) * a$(j+1) * (b^j)$i) {0..n}) {0..n}"
 | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2928 | unfolding fps_deriv_nth fps_compose_nth setsum_right_distrib mult.assoc | 
| 57418 | 2929 | apply (rule setsum.cong) | 
| 2930 | apply (rule refl) | |
| 2931 | apply (rule setsum.mono_neutral_left) | |
| 52903 | 2932 | apply (simp_all add: subset_eq) | 
| 2933 | apply clarify | |
| 2934 | apply (subgoal_tac "b^i$x = 0") | |
| 2935 | apply simp | |
| 2936 | apply (rule startsby_zero_power_prefix[OF b0, rule_format]) | |
| 2937 | apply simp | |
| 2938 | done | |
| 2939 |     also have "\<dots> = setsum (\<lambda>i. of_nat (i + 1) * a$(i+1) * (setsum (\<lambda>j. (b^ i)$j * of_nat (n - j + 1) * b$(n - j + 1)) {0..n})) {0.. n}"
 | |
| 2940 | unfolding setsum_right_distrib | |
| 57418 | 2941 | apply (subst setsum.commute) | 
| 2942 | apply (rule setsum.cong, rule refl)+ | |
| 52903 | 2943 | apply simp | 
| 2944 | done | |
| 60501 | 2945 | finally show ?thesis | 
| 52903 | 2946 | unfolding th0 by simp | 
| 60501 | 2947 | qed | 
| 52903 | 2948 | then show ?thesis by (simp add: fps_eq_iff) | 
| 29687 | 2949 | qed | 
| 2950 | ||
| 2951 | lemma fps_mult_X_plus_1_nth: | |
| 2952 | "((1+X)*a) $n = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))" | |
| 52903 | 2953 | proof (cases n) | 
| 2954 | case 0 | |
| 54681 | 2955 | then show ?thesis | 
| 60501 | 2956 | by (simp add: fps_mult_nth) | 
| 52903 | 2957 | next | 
| 2958 | case (Suc m) | |
| 60501 | 2959 |   have "((1 + X)*a) $ n = setsum (\<lambda>i. (1 + X) $ i * a $ (n - i)) {0..n}"
 | 
| 52903 | 2960 | by (simp add: fps_mult_nth) | 
| 2961 |   also have "\<dots> = setsum (\<lambda>i. (1+X)$i * a$(n-i)) {0.. 1}"
 | |
| 57418 | 2962 | unfolding Suc by (rule setsum.mono_neutral_right) auto | 
| 52903 | 2963 | also have "\<dots> = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))" | 
| 2964 | by (simp add: Suc) | |
| 2965 | finally show ?thesis . | |
| 29687 | 2966 | qed | 
| 2967 | ||
| 54681 | 2968 | |
| 60500 | 2969 | subsection \<open>Finite FPS (i.e. polynomials) and X\<close> | 
| 52903 | 2970 | |
| 29687 | 2971 | lemma fps_poly_sum_X: | 
| 60501 | 2972 | assumes "\<forall>i > n. a$i = (0::'a::comm_ring_1)" | 
| 29687 | 2973 |   shows "a = setsum (\<lambda>i. fps_const (a$i) * X^i) {0..n}" (is "a = ?r")
 | 
| 52903 | 2974 | proof - | 
| 60501 | 2975 | have "a$i = ?r$i" for i | 
| 2976 | unfolding fps_setsum_nth fps_mult_left_const_nth X_power_nth | |
| 2977 | by (simp add: mult_delta_right setsum.delta' assms) | |
| 2978 | then show ?thesis | |
| 2979 | unfolding fps_eq_iff by blast | |
| 29687 | 2980 | qed | 
| 2981 | ||
| 52903 | 2982 | |
| 60501 | 2983 | subsection \<open>Compositional inverses\<close> | 
| 29687 | 2984 | |
| 54681 | 2985 | fun compinv :: "'a fps \<Rightarrow> nat \<Rightarrow> 'a::field" | 
| 52903 | 2986 | where | 
| 29687 | 2987 | "compinv a 0 = X$0" | 
| 52903 | 2988 | | "compinv a (Suc n) = | 
| 2989 |     (X$ Suc n - setsum (\<lambda>i. (compinv a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
 | |
| 29687 | 2990 | |
| 2991 | definition "fps_inv a = Abs_fps (compinv a)" | |
| 2992 | ||
| 52903 | 2993 | lemma fps_inv: | 
| 2994 | assumes a0: "a$0 = 0" | |
| 2995 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 2996 | shows "fps_inv a oo a = X" | 
| 52903 | 2997 | proof - | 
| 29687 | 2998 | let ?i = "fps_inv a oo a" | 
| 60501 | 2999 | have "?i $n = X$n" for n | 
| 3000 | proof (induct n rule: nat_less_induct) | |
| 52903 | 3001 | fix n | 
| 60501 | 3002 | assume h: "\<forall>m<n. ?i$m = X$m" | 
| 3003 | show "?i $ n = X$n" | |
| 3004 | proof (cases n) | |
| 3005 | case 0 | |
| 3006 | then show ?thesis using a0 | |
| 3007 | by (simp add: fps_compose_nth fps_inv_def) | |
| 3008 | next | |
| 3009 | case (Suc n1) | |
| 3010 |       have "?i $ n = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} + fps_inv a $ Suc n1 * (a $ 1)^ Suc n1"
 | |
| 3011 | by (simp only: fps_compose_nth) (simp add: Suc startsby_zero_power_nth_same [OF a0] del: power_Suc) | |
| 3012 |       also have "\<dots> = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} +
 | |
| 3013 |         (X$ Suc n1 - setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1})"
 | |
| 3014 | using a0 a1 Suc by (simp add: fps_inv_def) | |
| 3015 | also have "\<dots> = X$n" using Suc by simp | |
| 3016 | finally show ?thesis . | |
| 52903 | 3017 | qed | 
| 60501 | 3018 | qed | 
| 3019 | then show ?thesis | |
| 3020 | by (simp add: fps_eq_iff) | |
| 29687 | 3021 | qed | 
| 3022 | ||
| 3023 | ||
| 54681 | 3024 | fun gcompinv :: "'a fps \<Rightarrow> 'a fps \<Rightarrow> nat \<Rightarrow> 'a::field" | 
| 52903 | 3025 | where | 
| 29687 | 3026 | "gcompinv b a 0 = b$0" | 
| 52903 | 3027 | | "gcompinv b a (Suc n) = | 
| 3028 |     (b$ Suc n - setsum (\<lambda>i. (gcompinv b a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
 | |
| 29687 | 3029 | |
| 3030 | definition "fps_ginv b a = Abs_fps (gcompinv b a)" | |
| 3031 | ||
| 52903 | 3032 | lemma fps_ginv: | 
| 3033 | assumes a0: "a$0 = 0" | |
| 3034 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 3035 | shows "fps_ginv b a oo a = b" | 
| 52903 | 3036 | proof - | 
| 29687 | 3037 | let ?i = "fps_ginv b a oo a" | 
| 60501 | 3038 | have "?i $n = b$n" for n | 
| 3039 | proof (induct n rule: nat_less_induct) | |
| 52903 | 3040 | fix n | 
| 60501 | 3041 | assume h: "\<forall>m<n. ?i$m = b$m" | 
| 3042 | show "?i $ n = b$n" | |
| 3043 | proof (cases n) | |
| 3044 | case 0 | |
| 3045 | then show ?thesis using a0 | |
| 3046 | by (simp add: fps_compose_nth fps_ginv_def) | |
| 3047 | next | |
| 3048 | case (Suc n1) | |
| 3049 |       have "?i $ n = setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1} + fps_ginv b a $ Suc n1 * (a $ 1)^ Suc n1"
 | |
| 3050 | by (simp only: fps_compose_nth) (simp add: Suc startsby_zero_power_nth_same [OF a0] del: power_Suc) | |
| 3051 |       also have "\<dots> = setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1} +
 | |
| 3052 |         (b$ Suc n1 - setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1})"
 | |
| 3053 | using a0 a1 Suc by (simp add: fps_ginv_def) | |
| 3054 | also have "\<dots> = b$n" using Suc by simp | |
| 3055 | finally show ?thesis . | |
| 52903 | 3056 | qed | 
| 60501 | 3057 | qed | 
| 3058 | then show ?thesis | |
| 3059 | by (simp add: fps_eq_iff) | |
| 29687 | 3060 | qed | 
| 3061 | ||
| 3062 | lemma fps_inv_ginv: "fps_inv = fps_ginv X" | |
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 3063 | apply (auto simp add: fun_eq_iff fps_eq_iff fps_inv_def fps_ginv_def) | 
| 48757 | 3064 | apply (induct_tac n rule: nat_less_induct) | 
| 3065 | apply auto | |
| 29687 | 3066 | apply (case_tac na) | 
| 3067 | apply simp | |
| 3068 | apply simp | |
| 3069 | done | |
| 3070 | ||
| 3071 | lemma fps_compose_1[simp]: "1 oo a = 1" | |
| 57418 | 3072 | by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum.delta) | 
| 29687 | 3073 | |
| 3074 | lemma fps_compose_0[simp]: "0 oo a = 0" | |
| 29913 | 3075 | by (simp add: fps_eq_iff fps_compose_nth) | 
| 29687 | 3076 | |
| 60867 | 3077 | lemma fps_compose_0_right[simp]: "a oo 0 = fps_const (a $ 0)" | 
| 57418 | 3078 | by (auto simp add: fps_eq_iff fps_compose_nth power_0_left setsum.neutral) | 
| 29687 | 3079 | |
| 3080 | lemma fps_compose_add_distrib: "(a + b) oo c = (a oo c) + (b oo c)" | |
| 57418 | 3081 | by (simp add: fps_eq_iff fps_compose_nth field_simps setsum.distrib) | 
| 29687 | 3082 | |
| 3083 | lemma fps_compose_setsum_distrib: "(setsum f S) oo a = setsum (\<lambda>i. f i oo a) S" | |
| 52903 | 3084 | proof (cases "finite S") | 
| 3085 | case True | |
| 3086 | show ?thesis | |
| 3087 | proof (rule finite_induct[OF True]) | |
| 60501 | 3088 |     show "setsum f {} oo a = (\<Sum>i\<in>{}. f i oo a)"
 | 
| 3089 | by simp | |
| 52903 | 3090 | next | 
| 3091 | fix x F | |
| 3092 | assume fF: "finite F" | |
| 3093 | and xF: "x \<notin> F" | |
| 3094 | and h: "setsum f F oo a = setsum (\<lambda>i. f i oo a) F" | |
| 3095 | show "setsum f (insert x F) oo a = setsum (\<lambda>i. f i oo a) (insert x F)" | |
| 3096 | using fF xF h by (simp add: fps_compose_add_distrib) | |
| 3097 | qed | |
| 3098 | next | |
| 3099 | case False | |
| 3100 | then show ?thesis by simp | |
| 29687 | 3101 | qed | 
| 3102 | ||
| 30488 | 3103 | lemma convolution_eq: | 
| 54452 | 3104 |   "setsum (\<lambda>i. a (i :: nat) * b (n - i)) {0 .. n} =
 | 
| 3105 |     setsum (\<lambda>(i,j). a i * b j) {(i,j). i \<le> n \<and> j \<le> n \<and> i + j = n}"
 | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3106 | by (rule setsum.reindex_bij_witness[where i=fst and j="\<lambda>i. (i, n - i)"]) auto | 
| 29687 | 3107 | |
| 3108 | lemma product_composition_lemma: | |
| 52903 | 3109 | assumes c0: "c$0 = (0::'a::idom)" | 
| 3110 | and d0: "d$0 = 0" | |
| 3111 | shows "((a oo c) * (b oo d))$n = | |
| 54452 | 3112 |     setsum (\<lambda>(k,m). a$k * b$m * (c^k * d^m) $ n) {(k,m). k + m \<le> n}"  (is "?l = ?r")
 | 
| 52903 | 3113 | proof - | 
| 54681 | 3114 |   let ?S = "{(k::nat, m::nat). k + m \<le> n}"
 | 
| 61943 | 3115 |   have s: "?S \<subseteq> {0..n} \<times> {0..n}" by (auto simp add: subset_eq)
 | 
| 54681 | 3116 |   have f: "finite {(k::nat, m::nat). k + m \<le> n}"
 | 
| 29687 | 3117 | apply (rule finite_subset[OF s]) | 
| 52903 | 3118 | apply auto | 
| 3119 | done | |
| 54452 | 3120 |   have "?r =  setsum (\<lambda>i. setsum (\<lambda>(k,m). a$k * (c^k)$i * b$m * (d^m) $ (n - i)) {(k,m). k + m \<le> n}) {0..n}"
 | 
| 29687 | 3121 | apply (simp add: fps_mult_nth setsum_right_distrib) | 
| 57418 | 3122 | apply (subst setsum.commute) | 
| 3123 | apply (rule setsum.cong) | |
| 52903 | 3124 | apply (auto simp add: field_simps) | 
| 3125 | done | |
| 30488 | 3126 | also have "\<dots> = ?l" | 
| 29687 | 3127 | apply (simp add: fps_mult_nth fps_compose_nth setsum_product) | 
| 57418 | 3128 | apply (rule setsum.cong) | 
| 3129 | apply (rule refl) | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3130 | apply (simp add: setsum.cartesian_product mult.assoc) | 
| 57418 | 3131 | apply (rule setsum.mono_neutral_right[OF f]) | 
| 54452 | 3132 | apply (simp add: subset_eq) | 
| 3133 | apply presburger | |
| 29687 | 3134 | apply clarsimp | 
| 3135 | apply (rule ccontr) | |
| 3136 | apply (clarsimp simp add: not_le) | |
| 3137 | apply (case_tac "x < aa") | |
| 3138 | apply simp | |
| 3139 | apply (frule_tac startsby_zero_power_prefix[rule_format, OF c0]) | |
| 3140 | apply blast | |
| 3141 | apply simp | |
| 3142 | apply (frule_tac startsby_zero_power_prefix[rule_format, OF d0]) | |
| 3143 | apply blast | |
| 3144 | done | |
| 3145 | finally show ?thesis by simp | |
| 3146 | qed | |
| 3147 | ||
| 3148 | lemma product_composition_lemma': | |
| 52903 | 3149 | assumes c0: "c$0 = (0::'a::idom)" | 
| 3150 | and d0: "d$0 = 0" | |
| 3151 | shows "((a oo c) * (b oo d))$n = | |
| 54452 | 3152 |     setsum (\<lambda>k. setsum (\<lambda>m. a$k * b$m * (c^k * d^m) $ n) {0..n}) {0..n}"  (is "?l = ?r")
 | 
| 29687 | 3153 | unfolding product_composition_lemma[OF c0 d0] | 
| 57418 | 3154 | unfolding setsum.cartesian_product | 
| 3155 | apply (rule setsum.mono_neutral_left) | |
| 29687 | 3156 | apply simp | 
| 3157 | apply (clarsimp simp add: subset_eq) | |
| 3158 | apply clarsimp | |
| 3159 | apply (rule ccontr) | |
| 3160 | apply (subgoal_tac "(c^aa * d^ba) $ n = 0") | |
| 3161 | apply simp | |
| 3162 | unfolding fps_mult_nth | |
| 57418 | 3163 | apply (rule setsum.neutral) | 
| 29687 | 3164 | apply (clarsimp simp add: not_le) | 
| 51489 | 3165 | apply (case_tac "x < aa") | 
| 29687 | 3166 | apply (rule startsby_zero_power_prefix[OF c0, rule_format]) | 
| 3167 | apply simp | |
| 51489 | 3168 | apply (subgoal_tac "n - x < ba") | 
| 29687 | 3169 | apply (frule_tac k = "ba" in startsby_zero_power_prefix[OF d0, rule_format]) | 
| 3170 | apply simp | |
| 3171 | apply arith | |
| 3172 | done | |
| 30488 | 3173 | |
| 29687 | 3174 | |
| 30488 | 3175 | lemma setsum_pair_less_iff: | 
| 54452 | 3176 |   "setsum (\<lambda>((k::nat),m). a k * b m * c (k + m)) {(k,m). k + m \<le> n} =
 | 
| 3177 |     setsum (\<lambda>s. setsum (\<lambda>i. a i * b (s - i) * c s) {0..s}) {0..n}"
 | |
| 52903 | 3178 | (is "?l = ?r") | 
| 3179 | proof - | |
| 3180 |   let ?KM = "{(k,m). k + m \<le> n}"
 | |
| 54452 | 3181 |   let ?f = "\<lambda>s. UNION {(0::nat)..s} (\<lambda>i. {(i,s - i)})"
 | 
| 29687 | 3182 |   have th0: "?KM = UNION {0..n} ?f"
 | 
| 62343 
24106dc44def
prefer abbreviations for compound operators INFIMUM and SUPREMUM
 haftmann parents: 
62102diff
changeset | 3183 | by auto | 
| 29687 | 3184 | show "?l = ?r " | 
| 3185 | unfolding th0 | |
| 57418 | 3186 | apply (subst setsum.UNION_disjoint) | 
| 29687 | 3187 | apply auto | 
| 57418 | 3188 | apply (subst setsum.UNION_disjoint) | 
| 29687 | 3189 | apply auto | 
| 3190 | done | |
| 3191 | qed | |
| 3192 | ||
| 3193 | lemma fps_compose_mult_distrib_lemma: | |
| 3194 | assumes c0: "c$0 = (0::'a::idom)" | |
| 60501 | 3195 |   shows "((a oo c) * (b oo c))$n = setsum (\<lambda>s. setsum (\<lambda>i. a$i * b$(s - i) * (c^s) $ n) {0..s}) {0..n}"
 | 
| 29687 | 3196 | unfolding product_composition_lemma[OF c0 c0] power_add[symmetric] | 
| 54452 | 3197 | unfolding setsum_pair_less_iff[where a = "\<lambda>k. a$k" and b="\<lambda>m. b$m" and c="\<lambda>s. (c ^ s)$n" and n = n] .. | 
| 29687 | 3198 | |
| 30488 | 3199 | lemma fps_compose_mult_distrib: | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3200 | assumes c0: "c $ 0 = (0::'a::idom)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3201 | shows "(a * b) oo c = (a oo c) * (b oo c)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3202 | apply (simp add: fps_eq_iff fps_compose_mult_distrib_lemma [OF c0]) | 
| 52903 | 3203 | apply (simp add: fps_compose_nth fps_mult_nth setsum_left_distrib) | 
| 3204 | done | |
| 3205 | ||
| 30488 | 3206 | lemma fps_compose_setprod_distrib: | 
| 29687 | 3207 | assumes c0: "c$0 = (0::'a::idom)" | 
| 54452 | 3208 | shows "setprod a S oo c = setprod (\<lambda>k. a k oo c) S" | 
| 29687 | 3209 | apply (cases "finite S") | 
| 3210 | apply simp_all | |
| 3211 | apply (induct S rule: finite_induct) | |
| 3212 | apply simp | |
| 3213 | apply (simp add: fps_compose_mult_distrib[OF c0]) | |
| 3214 | done | |
| 3215 | ||
| 53195 | 3216 | lemma fps_compose_power: | 
| 3217 | assumes c0: "c$0 = (0::'a::idom)" | |
| 3218 | shows "(a oo c)^n = a^n oo c" | |
| 52903 | 3219 | proof (cases n) | 
| 3220 | case 0 | |
| 3221 | then show ?thesis by simp | |
| 3222 | next | |
| 3223 | case (Suc m) | |
| 54452 | 3224 |   have th0: "a^n = setprod (\<lambda>k. a) {0..m}" "(a oo c) ^ n = setprod (\<lambda>k. a oo c) {0..m}"
 | 
| 52903 | 3225 | by (simp_all add: setprod_constant Suc) | 
| 3226 | then show ?thesis | |
| 3227 | by (simp add: fps_compose_setprod_distrib[OF c0]) | |
| 29687 | 3228 | qed | 
| 3229 | ||
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3230 | lemma fps_compose_uminus: "- (a::'a::ring_1 fps) oo c = - (a oo c)" | 
| 36350 | 3231 | by (simp add: fps_eq_iff fps_compose_nth field_simps setsum_negf[symmetric]) | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3232 | |
| 52903 | 3233 | lemma fps_compose_sub_distrib: "(a - b) oo (c::'a::ring_1 fps) = (a oo c) - (b oo c)" | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 3234 | using fps_compose_add_distrib [of a "- b" c] by (simp add: fps_compose_uminus) | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3235 | |
| 52903 | 3236 | lemma X_fps_compose: "X oo a = Abs_fps (\<lambda>n. if n = 0 then (0::'a::comm_ring_1) else a$n)" | 
| 57418 | 3237 | by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum.delta) | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3238 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3239 | lemma fps_inverse_compose: | 
| 52903 | 3240 | assumes b0: "(b$0 :: 'a::field) = 0" | 
| 3241 | and a0: "a$0 \<noteq> 0" | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3242 | shows "inverse a oo b = inverse (a oo b)" | 
| 52903 | 3243 | proof - | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3244 | let ?ia = "inverse a" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3245 | let ?ab = "a oo b" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3246 | let ?iab = "inverse ?ab" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3247 | |
| 52903 | 3248 | from a0 have ia0: "?ia $ 0 \<noteq> 0" by simp | 
| 3249 | from a0 have ab0: "?ab $ 0 \<noteq> 0" by (simp add: fps_compose_def) | |
| 3250 | have "(?ia oo b) * (a oo b) = 1" | |
| 3251 | unfolding fps_compose_mult_distrib[OF b0, symmetric] | |
| 3252 | unfolding inverse_mult_eq_1[OF a0] | |
| 3253 | fps_compose_1 .. | |
| 54452 | 3254 | |
| 52903 | 3255 | then have "(?ia oo b) * (a oo b) * ?iab = 1 * ?iab" by simp | 
| 3256 | then have "(?ia oo b) * (?iab * (a oo b)) = ?iab" by simp | |
| 3257 | then show ?thesis unfolding inverse_mult_eq_1[OF ab0] by simp | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3258 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3259 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3260 | lemma fps_divide_compose: | 
| 52903 | 3261 | assumes c0: "(c$0 :: 'a::field) = 0" | 
| 3262 | and b0: "b$0 \<noteq> 0" | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3263 | shows "(a/b) oo c = (a oo c) / (b oo c)" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3264 | using b0 c0 by (simp add: fps_divide_unit fps_inverse_compose fps_compose_mult_distrib) | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3265 | |
| 52903 | 3266 | lemma gp: | 
| 3267 | assumes a0: "a$0 = (0::'a::field)" | |
| 3268 | shows "(Abs_fps (\<lambda>n. 1)) oo a = 1/(1 - a)" | |
| 3269 | (is "?one oo a = _") | |
| 3270 | proof - | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3271 | have o0: "?one $ 0 \<noteq> 0" by simp | 
| 52891 | 3272 | have th0: "(1 - X) $ 0 \<noteq> (0::'a)" by simp | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3273 | from fps_inverse_gp[where ?'a = 'a] | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3274 | have "inverse ?one = 1 - X" by (simp add: fps_eq_iff) | 
| 54452 | 3275 | then have "inverse (inverse ?one) = inverse (1 - X)" by simp | 
| 3276 | then have th: "?one = 1/(1 - X)" unfolding fps_inverse_idempotent[OF o0] | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3277 | by (simp add: fps_divide_def) | 
| 52903 | 3278 | show ?thesis | 
| 3279 | unfolding th | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3280 | unfolding fps_divide_compose[OF a0 th0] | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3281 | fps_compose_1 fps_compose_sub_distrib X_fps_compose_startby0[OF a0] .. | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3282 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3283 | |
| 52903 | 3284 | lemma fps_const_power [simp]: "fps_const (c::'a::ring_1) ^ n = fps_const (c^n)" | 
| 48757 | 3285 | by (induct n) auto | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3286 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3287 | lemma fps_compose_radical: | 
| 31273 | 3288 | assumes b0: "b$0 = (0::'a::field_char_0)" | 
| 52903 | 3289 | and ra0: "r (Suc k) (a$0) ^ Suc k = a$0" | 
| 3290 | and a0: "a$0 \<noteq> 0" | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3291 | shows "fps_radical r (Suc k) a oo b = fps_radical r (Suc k) (a oo b)" | 
| 52903 | 3292 | proof - | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3293 | let ?r = "fps_radical r (Suc k)" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3294 | let ?ab = "a oo b" | 
| 52903 | 3295 | have ab0: "?ab $ 0 = a$0" | 
| 3296 | by (simp add: fps_compose_def) | |
| 3297 | from ab0 a0 ra0 have rab0: "?ab $ 0 \<noteq> 0" "r (Suc k) (?ab $ 0) ^ Suc k = ?ab $ 0" | |
| 3298 | by simp_all | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3299 | have th00: "r (Suc k) ((a oo b) $ 0) = (fps_radical r (Suc k) a oo b) $ 0" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3300 | by (simp add: ab0 fps_compose_def) | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3301 | have th0: "(?r a oo b) ^ (Suc k) = a oo b" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3302 | unfolding fps_compose_power[OF b0] | 
| 52891 | 3303 | unfolding iffD1[OF power_radical[of a r k], OF a0 ra0] .. | 
| 52903 | 3304 | from iffD1[OF radical_unique[where r=r and k=k and b= ?ab and a = "?r a oo b", OF rab0(2) th00 rab0(1)], OF th0] | 
| 3305 | show ?thesis . | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3306 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 3307 | |
| 52903 | 3308 | lemma fps_const_mult_apply_left: "fps_const c * (a oo b) = (fps_const c * a) oo b" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3309 | by (simp add: fps_eq_iff fps_compose_nth setsum_right_distrib mult.assoc) | 
| 29687 | 3310 | |
| 3311 | lemma fps_const_mult_apply_right: | |
| 3312 | "(a oo b) * fps_const (c::'a::comm_semiring_1) = (fps_const c * a) oo b" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3313 | by (auto simp add: fps_const_mult_apply_left mult.commute) | 
| 29687 | 3314 | |
| 30488 | 3315 | lemma fps_compose_assoc: | 
| 52903 | 3316 | assumes c0: "c$0 = (0::'a::idom)" | 
| 3317 | and b0: "b$0 = 0" | |
| 29687 | 3318 | shows "a oo (b oo c) = a oo b oo c" (is "?l = ?r") | 
| 52903 | 3319 | proof - | 
| 60501 | 3320 | have "?l$n = ?r$n" for n | 
| 3321 | proof - | |
| 29687 | 3322 |     have "?l$n = (setsum (\<lambda>i. (fps_const (a$i) * b^i) oo c) {0..n})$n"
 | 
| 52903 | 3323 | by (simp add: fps_compose_nth fps_compose_power[OF c0] fps_const_mult_apply_left | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3324 | setsum_right_distrib mult.assoc fps_setsum_nth) | 
| 29687 | 3325 |     also have "\<dots> = ((setsum (\<lambda>i. fps_const (a$i) * b^i) {0..n}) oo c)$n"
 | 
| 3326 | by (simp add: fps_compose_setsum_distrib) | |
| 3327 | also have "\<dots> = ?r$n" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3328 | apply (simp add: fps_compose_nth fps_setsum_nth setsum_left_distrib mult.assoc) | 
| 57418 | 3329 | apply (rule setsum.cong) | 
| 3330 | apply (rule refl) | |
| 3331 | apply (rule setsum.mono_neutral_right) | |
| 29687 | 3332 | apply (auto simp add: not_le) | 
| 52903 | 3333 | apply (erule startsby_zero_power_prefix[OF b0, rule_format]) | 
| 3334 | done | |
| 60501 | 3335 | finally show ?thesis . | 
| 3336 | qed | |
| 3337 | then show ?thesis | |
| 3338 | by (simp add: fps_eq_iff) | |
| 29687 | 3339 | qed | 
| 3340 | ||
| 3341 | ||
| 3342 | lemma fps_X_power_compose: | |
| 52903 | 3343 | assumes a0: "a$0=0" | 
| 54681 | 3344 | shows "X^k oo a = (a::'a::idom fps)^k" | 
| 3345 | (is "?l = ?r") | |
| 52903 | 3346 | proof (cases k) | 
| 3347 | case 0 | |
| 3348 | then show ?thesis by simp | |
| 3349 | next | |
| 53196 | 3350 | case (Suc h) | 
| 60501 | 3351 | have "?l $ n = ?r $n" for n | 
| 3352 | proof - | |
| 3353 | consider "k > n" | "k \<le> n" by arith | |
| 3354 | then show ?thesis | |
| 3355 | proof cases | |
| 3356 | case 1 | |
| 3357 | then show ?thesis | |
| 3358 | using a0 startsby_zero_power_prefix[OF a0] Suc | |
| 52903 | 3359 | by (simp add: fps_compose_nth del: power_Suc) | 
| 60501 | 3360 | next | 
| 3361 | case 2 | |
| 3362 | then show ?thesis | |
| 57418 | 3363 | by (simp add: fps_compose_nth mult_delta_left setsum.delta) | 
| 60501 | 3364 | qed | 
| 3365 | qed | |
| 3366 | then show ?thesis | |
| 3367 | unfolding fps_eq_iff by blast | |
| 29687 | 3368 | qed | 
| 3369 | ||
| 52903 | 3370 | lemma fps_inv_right: | 
| 3371 | assumes a0: "a$0 = 0" | |
| 3372 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 3373 | shows "a oo fps_inv a = X" | 
| 52903 | 3374 | proof - | 
| 29687 | 3375 | let ?ia = "fps_inv a" | 
| 3376 | let ?iaa = "a oo fps_inv a" | |
| 60501 | 3377 | have th0: "?ia $ 0 = 0" | 
| 3378 | by (simp add: fps_inv_def) | |
| 3379 | have th1: "?iaa $ 0 = 0" | |
| 3380 | using a0 a1 by (simp add: fps_inv_def fps_compose_nth) | |
| 3381 | have th2: "X$0 = 0" | |
| 3382 | by simp | |
| 3383 | from fps_inv[OF a0 a1] have "a oo (fps_inv a oo a) = a oo X" | |
| 3384 | by simp | |
| 29687 | 3385 | then have "(a oo fps_inv a) oo a = X oo a" | 
| 3386 | by (simp add: fps_compose_assoc[OF a0 th0] X_fps_compose_startby0[OF a0]) | |
| 60501 | 3387 | with fps_compose_inj_right[OF a0 a1] show ?thesis | 
| 3388 | by simp | |
| 29687 | 3389 | qed | 
| 3390 | ||
| 3391 | lemma fps_inv_deriv: | |
| 60501 | 3392 | assumes a0: "a$0 = (0::'a::field)" | 
| 52903 | 3393 | and a1: "a$1 \<noteq> 0" | 
| 29687 | 3394 | shows "fps_deriv (fps_inv a) = inverse (fps_deriv a oo fps_inv a)" | 
| 52903 | 3395 | proof - | 
| 29687 | 3396 | let ?ia = "fps_inv a" | 
| 3397 | let ?d = "fps_deriv a oo ?ia" | |
| 3398 | let ?dia = "fps_deriv ?ia" | |
| 60501 | 3399 | have ia0: "?ia$0 = 0" | 
| 3400 | by (simp add: fps_inv_def) | |
| 3401 | have th0: "?d$0 \<noteq> 0" | |
| 3402 | using a1 by (simp add: fps_compose_nth) | |
| 29687 | 3403 | from fps_inv_right[OF a0 a1] have "?d * ?dia = 1" | 
| 3404 | by (simp add: fps_compose_deriv[OF ia0, of a, symmetric] ) | |
| 60501 | 3405 | then have "inverse ?d * ?d * ?dia = inverse ?d * 1" | 
| 3406 | by simp | |
| 3407 | with inverse_mult_eq_1 [OF th0] show "?dia = inverse ?d" | |
| 3408 | by simp | |
| 29687 | 3409 | qed | 
| 3410 | ||
| 52891 | 3411 | lemma fps_inv_idempotent: | 
| 52903 | 3412 | assumes a0: "a$0 = 0" | 
| 3413 | and a1: "a$1 \<noteq> 0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3414 | shows "fps_inv (fps_inv a) = a" | 
| 52903 | 3415 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3416 | let ?r = "fps_inv" | 
| 60501 | 3417 | have ra0: "?r a $ 0 = 0" | 
| 3418 | by (simp add: fps_inv_def) | |
| 3419 | from a1 have ra1: "?r a $ 1 \<noteq> 0" | |
| 3420 | by (simp add: fps_inv_def field_simps) | |
| 3421 | have X0: "X$0 = 0" | |
| 3422 | by simp | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3423 | from fps_inv[OF ra0 ra1] have "?r (?r a) oo ?r a = X" . | 
| 60501 | 3424 | then have "?r (?r a) oo ?r a oo a = X oo a" | 
| 3425 | by simp | |
| 52891 | 3426 | then have "?r (?r a) oo (?r a oo a) = a" | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3427 | unfolding X_fps_compose_startby0[OF a0] | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3428 | unfolding fps_compose_assoc[OF a0 ra0, symmetric] . | 
| 60501 | 3429 | then show ?thesis | 
| 3430 | unfolding fps_inv[OF a0 a1] by simp | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3431 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3432 | |
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3433 | lemma fps_ginv_ginv: | 
| 52903 | 3434 | assumes a0: "a$0 = 0" | 
| 3435 | and a1: "a$1 \<noteq> 0" | |
| 3436 | and c0: "c$0 = 0" | |
| 3437 | and c1: "c$1 \<noteq> 0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3438 | shows "fps_ginv b (fps_ginv c a) = b oo a oo fps_inv c" | 
| 52903 | 3439 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3440 | let ?r = "fps_ginv" | 
| 60501 | 3441 | from c0 have rca0: "?r c a $0 = 0" | 
| 3442 | by (simp add: fps_ginv_def) | |
| 3443 | from a1 c1 have rca1: "?r c a $ 1 \<noteq> 0" | |
| 3444 | by (simp add: fps_ginv_def field_simps) | |
| 52891 | 3445 | from fps_ginv[OF rca0 rca1] | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3446 | have "?r b (?r c a) oo ?r c a = b" . | 
| 60501 | 3447 | then have "?r b (?r c a) oo ?r c a oo a = b oo a" | 
| 3448 | by simp | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3449 | then have "?r b (?r c a) oo (?r c a oo a) = b oo a" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3450 | apply (subst fps_compose_assoc) | 
| 53195 | 3451 | using a0 c0 | 
| 3452 | apply (auto simp add: fps_ginv_def) | |
| 52903 | 3453 | done | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3454 | then have "?r b (?r c a) oo c = b oo a" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3455 | unfolding fps_ginv[OF a0 a1] . | 
| 60501 | 3456 | then have "?r b (?r c a) oo c oo fps_inv c= b oo a oo fps_inv c" | 
| 3457 | by simp | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3458 | then have "?r b (?r c a) oo (c oo fps_inv c) = b oo a oo fps_inv c" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3459 | apply (subst fps_compose_assoc) | 
| 53195 | 3460 | using a0 c0 | 
| 3461 | apply (auto simp add: fps_inv_def) | |
| 52903 | 3462 | done | 
| 60501 | 3463 | then show ?thesis | 
| 3464 | unfolding fps_inv_right[OF c0 c1] by simp | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3465 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3466 | |
| 32410 | 3467 | lemma fps_ginv_deriv: | 
| 54681 | 3468 | assumes a0:"a$0 = (0::'a::field)" | 
| 52903 | 3469 | and a1: "a$1 \<noteq> 0" | 
| 32410 | 3470 | shows "fps_deriv (fps_ginv b a) = (fps_deriv b / fps_deriv a) oo fps_ginv X a" | 
| 52903 | 3471 | proof - | 
| 32410 | 3472 | let ?ia = "fps_ginv b a" | 
| 3473 | let ?iXa = "fps_ginv X a" | |
| 3474 | let ?d = "fps_deriv" | |
| 3475 | let ?dia = "?d ?ia" | |
| 60501 | 3476 | have iXa0: "?iXa $ 0 = 0" | 
| 3477 | by (simp add: fps_ginv_def) | |
| 3478 | have da0: "?d a $ 0 \<noteq> 0" | |
| 3479 | using a1 by simp | |
| 3480 | from fps_ginv[OF a0 a1, of b] have "?d (?ia oo a) = fps_deriv b" | |
| 3481 | by simp | |
| 3482 | then have "(?d ?ia oo a) * ?d a = ?d b" | |
| 3483 | unfolding fps_compose_deriv[OF a0] . | |
| 3484 | then have "(?d ?ia oo a) * ?d a * inverse (?d a) = ?d b * inverse (?d a)" | |
| 3485 | by simp | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3486 | with a1 have "(?d ?ia oo a) * (inverse (?d a) * ?d a) = ?d b / ?d a" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3487 | by (simp add: fps_divide_unit) | 
| 60501 | 3488 | then have "(?d ?ia oo a) oo ?iXa = (?d b / ?d a) oo ?iXa" | 
| 32410 | 3489 | unfolding inverse_mult_eq_1[OF da0] by simp | 
| 3490 | then have "?d ?ia oo (a oo ?iXa) = (?d b / ?d a) oo ?iXa" | |
| 3491 | unfolding fps_compose_assoc[OF iXa0 a0] . | |
| 3492 | then show ?thesis unfolding fps_inv_ginv[symmetric] | |
| 3493 | unfolding fps_inv_right[OF a0 a1] by simp | |
| 3494 | qed | |
| 3495 | ||
| 60501 | 3496 | |
| 3497 | subsection \<open>Elementary series\<close> | |
| 3498 | ||
| 3499 | subsubsection \<open>Exponential series\<close> | |
| 53195 | 3500 | |
| 30488 | 3501 | definition "E x = Abs_fps (\<lambda>n. x^n / of_nat (fact n))" | 
| 29687 | 3502 | |
| 31273 | 3503 | lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::field_char_0) * E a" (is "?l = ?r") | 
| 52903 | 3504 | proof - | 
| 60501 | 3505 | have "?l$n = ?r $ n" for n | 
| 3506 | apply (auto simp add: E_def field_simps power_Suc[symmetric] | |
| 3507 | simp del: fact.simps of_nat_Suc power_Suc) | |
| 3508 | apply (simp add: of_nat_mult field_simps) | |
| 3509 | done | |
| 3510 | then show ?thesis | |
| 3511 | by (simp add: fps_eq_iff) | |
| 29687 | 3512 | qed | 
| 3513 | ||
| 30488 | 3514 | lemma E_unique_ODE: | 
| 54681 | 3515 | "fps_deriv a = fps_const c * a \<longleftrightarrow> a = fps_const (a$0) * E (c::'a::field_char_0)" | 
| 29687 | 3516 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 52903 | 3517 | proof | 
| 60501 | 3518 | show ?rhs if ?lhs | 
| 3519 | proof - | |
| 3520 | from that have th: "\<And>n. a $ Suc n = c * a$n / of_nat (Suc n)" | |
| 3521 | by (simp add: fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc) | |
| 3522 | have th': "a$n = a$0 * c ^ n/ (fact n)" for n | |
| 3523 | proof (induct n) | |
| 3524 | case 0 | |
| 3525 | then show ?case by simp | |
| 3526 | next | |
| 3527 | case Suc | |
| 3528 | then show ?case | |
| 3529 | unfolding th | |
| 3530 | using fact_gt_zero | |
| 3531 | apply (simp add: field_simps del: of_nat_Suc fact_Suc) | |
| 3532 | apply simp | |
| 3533 | done | |
| 3534 | qed | |
| 3535 | show ?thesis | |
| 3536 | by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro: th') | |
| 3537 | qed | |
| 3538 | show ?lhs if ?rhs | |
| 3539 | using that by (metis E_deriv fps_deriv_mult_const_left mult.left_commute) | |
| 29687 | 3540 | qed | 
| 3541 | ||
| 31273 | 3542 | lemma E_add_mult: "E (a + b) = E (a::'a::field_char_0) * E b" (is "?l = ?r") | 
| 52903 | 3543 | proof - | 
| 60501 | 3544 | have "fps_deriv ?r = fps_const (a + b) * ?r" | 
| 36350 | 3545 | by (simp add: fps_const_add[symmetric] field_simps del: fps_const_add) | 
| 60501 | 3546 | then have "?r = ?l" | 
| 3547 | by (simp only: E_unique_ODE) (simp add: fps_mult_nth E_def) | |
| 29687 | 3548 | then show ?thesis .. | 
| 3549 | qed | |
| 3550 | ||
| 3551 | lemma E_nth[simp]: "E a $ n = a^n / of_nat (fact n)" | |
| 3552 | by (simp add: E_def) | |
| 3553 | ||
| 54681 | 3554 | lemma E0[simp]: "E (0::'a::field) = 1" | 
| 29687 | 3555 | by (simp add: fps_eq_iff power_0_left) | 
| 3556 | ||
| 31273 | 3557 | lemma E_neg: "E (- a) = inverse (E (a::'a::field_char_0))" | 
| 52903 | 3558 | proof - | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3559 | from E_add_mult[of a "- a"] have th0: "E a * E (- a) = 1" by simp | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3560 | from fps_inverse_unique[OF th0] show ?thesis by simp | 
| 29687 | 3561 | qed | 
| 3562 | ||
| 31273 | 3563 | lemma E_nth_deriv[simp]: "fps_nth_deriv n (E (a::'a::field_char_0)) = (fps_const a)^n * (E a)" | 
| 52902 | 3564 | by (induct n) auto | 
| 29687 | 3565 | |
| 54681 | 3566 | lemma X_compose_E[simp]: "X oo E (a::'a::field) = E a - 1" | 
| 29687 | 3567 | by (simp add: fps_eq_iff X_fps_compose) | 
| 3568 | ||
| 30488 | 3569 | lemma LE_compose: | 
| 60501 | 3570 | assumes a: "a \<noteq> 0" | 
| 29687 | 3571 | shows "fps_inv (E a - 1) oo (E a - 1) = X" | 
| 52903 | 3572 | and "(E a - 1) oo fps_inv (E a - 1) = X" | 
| 53195 | 3573 | proof - | 
| 29687 | 3574 | let ?b = "E a - 1" | 
| 60501 | 3575 | have b0: "?b $ 0 = 0" | 
| 3576 | by simp | |
| 3577 | have b1: "?b $ 1 \<noteq> 0" | |
| 3578 | by (simp add: a) | |
| 29687 | 3579 | from fps_inv[OF b0 b1] show "fps_inv (E a - 1) oo (E a - 1) = X" . | 
| 3580 | from fps_inv_right[OF b0 b1] show "(E a - 1) oo fps_inv (E a - 1) = X" . | |
| 3581 | qed | |
| 3582 | ||
| 31273 | 3583 | lemma E_power_mult: "(E (c::'a::field_char_0))^n = E (of_nat n * c)" | 
| 52902 | 3584 | by (induct n) (auto simp add: field_simps E_add_mult) | 
| 29687 | 3585 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3586 | lemma radical_E: | 
| 52891 | 3587 | assumes r: "r (Suc k) 1 = 1" | 
| 54681 | 3588 | shows "fps_radical r (Suc k) (E (c::'a::field_char_0)) = E (c / of_nat (Suc k))" | 
| 52903 | 3589 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3590 | let ?ck = "(c / of_nat (Suc k))" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3591 | let ?r = "fps_radical r (Suc k)" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3592 | have eq0[simp]: "?ck * of_nat (Suc k) = c" "of_nat (Suc k) * ?ck = c" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3593 | by (simp_all del: of_nat_Suc) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3594 | have th0: "E ?ck ^ (Suc k) = E c" unfolding E_power_mult eq0 .. | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3595 | have th: "r (Suc k) (E c $0) ^ Suc k = E c $ 0" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3596 | "r (Suc k) (E c $ 0) = E ?ck $ 0" "E c $ 0 \<noteq> 0" using r by simp_all | 
| 60501 | 3597 | from th0 radical_unique[where r=r and k=k, OF th] show ?thesis | 
| 3598 | by auto | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3599 | qed | 
| 29687 | 3600 | |
| 54681 | 3601 | lemma Ec_E1_eq: "E (1::'a::field_char_0) oo (fps_const c * X) = E c" | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3602 | apply (auto simp add: fps_eq_iff E_def fps_compose_def power_mult_distrib) | 
| 57418 | 3603 | apply (simp add: cond_value_iff cond_application_beta setsum.delta' cong del: if_weak_cong) | 
| 52902 | 3604 | done | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3605 | |
| 53195 | 3606 | |
| 60501 | 3607 | subsubsection \<open>Logarithmic series\<close> | 
| 29687 | 3608 | |
| 52891 | 3609 | lemma Abs_fps_if_0: | 
| 60501 | 3610 | "Abs_fps (\<lambda>n. if n = 0 then (v::'a::ring_1) else f n) = | 
| 3611 | fps_const v + X * Abs_fps (\<lambda>n. f (Suc n))" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3612 | by (auto simp add: fps_eq_iff) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3613 | |
| 52902 | 3614 | definition L :: "'a::field_char_0 \<Rightarrow> 'a fps" | 
| 3615 | where "L c = fps_const (1/c) * Abs_fps (\<lambda>n. if n = 0 then 0 else (- 1) ^ (n - 1) / of_nat n)" | |
| 29687 | 3616 | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3617 | lemma fps_deriv_L: "fps_deriv (L c) = fps_const (1/c) * inverse (1 + X)" | 
| 60162 | 3618 | unfolding fps_inverse_X_plus1 | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3619 | by (simp add: L_def fps_eq_iff del: of_nat_Suc) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3620 | |
| 60501 | 3621 | lemma L_nth: "L c $ n = (if n = 0 then 0 else 1/c * ((- 1) ^ (n - 1) / of_nat n))" | 
| 36350 | 3622 | by (simp add: L_def field_simps) | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3623 | |
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3624 | lemma L_0[simp]: "L c $ 0 = 0" by (simp add: L_def) | 
| 52903 | 3625 | |
| 29687 | 3626 | lemma L_E_inv: | 
| 54452 | 3627 | fixes a :: "'a::field_char_0" | 
| 3628 | assumes a: "a \<noteq> 0" | |
| 3629 | shows "L a = fps_inv (E a - 1)" (is "?l = ?r") | |
| 52903 | 3630 | proof - | 
| 29687 | 3631 | let ?b = "E a - 1" | 
| 3632 | have b0: "?b $ 0 = 0" by simp | |
| 3633 | have b1: "?b $ 1 \<noteq> 0" by (simp add: a) | |
| 52903 | 3634 | have "fps_deriv (E a - 1) oo fps_inv (E a - 1) = | 
| 3635 | (fps_const a * (E a - 1) + fps_const a) oo fps_inv (E a - 1)" | |
| 36350 | 3636 | by (simp add: field_simps) | 
| 52903 | 3637 | also have "\<dots> = fps_const a * (X + 1)" | 
| 3638 | apply (simp add: fps_compose_add_distrib fps_const_mult_apply_left[symmetric] fps_inv_right[OF b0 b1]) | |
| 3639 | apply (simp add: field_simps) | |
| 3640 | done | |
| 29687 | 3641 | finally have eq: "fps_deriv (E a - 1) oo fps_inv (E a - 1) = fps_const a * (X + 1)" . | 
| 3642 | from fps_inv_deriv[OF b0 b1, unfolded eq] | |
| 3643 | have "fps_deriv (fps_inv ?b) = fps_const (inverse a) / (X + 1)" | |
| 52891 | 3644 | using a | 
| 29687 | 3645 | by (simp add: fps_const_inverse eq fps_divide_def fps_inverse_mult) | 
| 54452 | 3646 | then have "fps_deriv ?l = fps_deriv ?r" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3647 | by (simp add: fps_deriv_L add.commute fps_divide_def divide_inverse) | 
| 29687 | 3648 | then show ?thesis unfolding fps_deriv_eq_iff | 
| 3649 | by (simp add: L_nth fps_inv_def) | |
| 3650 | qed | |
| 3651 | ||
| 52891 | 3652 | lemma L_mult_add: | 
| 52903 | 3653 | assumes c0: "c\<noteq>0" | 
| 3654 | and d0: "d\<noteq>0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3655 | shows "L c + L d = fps_const (c+d) * L (c*d)" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3656 | (is "?r = ?l") | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3657 | proof- | 
| 36350 | 3658 | from c0 d0 have eq: "1/c + 1/d = (c+d)/(c*d)" by (simp add: field_simps) | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3659 | have "fps_deriv ?r = fps_const (1/c + 1/d) * inverse (1 + X)" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3660 | by (simp add: fps_deriv_L fps_const_add[symmetric] algebra_simps del: fps_const_add) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3661 | also have "\<dots> = fps_deriv ?l" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3662 | apply (simp add: fps_deriv_L) | 
| 52903 | 3663 | apply (simp add: fps_eq_iff eq) | 
| 3664 | done | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3665 | finally show ?thesis | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3666 | unfolding fps_deriv_eq_iff by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3667 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3668 | |
| 53196 | 3669 | |
| 60501 | 3670 | subsubsection \<open>Binomial series\<close> | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3671 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3672 | definition "fps_binomial a = Abs_fps (\<lambda>n. a gchoose n)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3673 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3674 | lemma fps_binomial_nth[simp]: "fps_binomial a $ n = a gchoose n" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3675 | by (simp add: fps_binomial_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3676 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3677 | lemma fps_binomial_ODE_unique: | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3678 | fixes c :: "'a::field_char_0" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3679 | shows "fps_deriv a = (fps_const c * a) / (1 + X) \<longleftrightarrow> a = fps_const (a$0) * fps_binomial c" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3680 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 60501 | 3681 | proof | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3682 | let ?da = "fps_deriv a" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3683 | let ?x1 = "(1 + X):: 'a fps" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3684 | let ?l = "?x1 * ?da" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3685 | let ?r = "fps_const c * a" | 
| 60501 | 3686 | |
| 3687 | have eq: "?l = ?r \<longleftrightarrow> ?lhs" | |
| 3688 | proof - | |
| 3689 | have x10: "?x1 $ 0 \<noteq> 0" by simp | |
| 3690 | have "?l = ?r \<longleftrightarrow> inverse ?x1 * ?l = inverse ?x1 * ?r" by simp | |
| 3691 | also have "\<dots> \<longleftrightarrow> ?da = (fps_const c * a) / ?x1" | |
| 3692 | apply (simp only: fps_divide_def mult.assoc[symmetric] inverse_mult_eq_1[OF x10]) | |
| 3693 | apply (simp add: field_simps) | |
| 3694 | done | |
| 3695 | finally show ?thesis . | |
| 3696 | qed | |
| 3697 | ||
| 3698 | show ?rhs if ?lhs | |
| 3699 | proof - | |
| 3700 | from eq that have h: "?l = ?r" .. | |
| 3701 | have th0: "a$ Suc n = ((c - of_nat n) / of_nat (Suc n)) * a $n" for n | |
| 3702 | proof - | |
| 3703 | from h have "?l $ n = ?r $ n" by simp | |
| 3704 | then show ?thesis | |
| 36350 | 3705 | apply (simp add: field_simps del: of_nat_Suc) | 
| 60501 | 3706 | apply (cases n) | 
| 3707 | apply (simp_all add: field_simps del: of_nat_Suc) | |
| 3708 | done | |
| 3709 | qed | |
| 3710 | have th1: "a $ n = (c gchoose n) * a $ 0" for n | |
| 3711 | proof (induct n) | |
| 3712 | case 0 | |
| 3713 | then show ?case by simp | |
| 3714 | next | |
| 3715 | case (Suc m) | |
| 3716 | then show ?case | |
| 3717 | unfolding th0 | |
| 3718 | apply (simp add: field_simps del: of_nat_Suc) | |
| 3719 | unfolding mult.assoc[symmetric] gbinomial_mult_1 | |
| 3720 | apply (simp add: field_simps) | |
| 3721 | done | |
| 3722 | qed | |
| 3723 | show ?thesis | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3724 | apply (simp add: fps_eq_iff) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3725 | apply (subst th1) | 
| 53196 | 3726 | apply (simp add: field_simps) | 
| 3727 | done | |
| 60501 | 3728 | qed | 
| 3729 | ||
| 3730 | show ?lhs if ?rhs | |
| 3731 | proof - | |
| 3732 | have th00: "x * (a $ 0 * y) = a $ 0 * (x * y)" for x y | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3733 | by (simp add: mult.commute) | 
| 52891 | 3734 | have "?l = ?r" | 
| 60501 | 3735 | apply (subst \<open>?rhs\<close>) | 
| 3736 | apply (subst (2) \<open>?rhs\<close>) | |
| 36350 | 3737 | apply (clarsimp simp add: fps_eq_iff field_simps) | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3738 | unfolding mult.assoc[symmetric] th00 gbinomial_mult_1 | 
| 53196 | 3739 | apply (simp add: field_simps gbinomial_mult_1) | 
| 3740 | done | |
| 60501 | 3741 | with eq show ?thesis .. | 
| 3742 | qed | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3743 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3744 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3745 | lemma fps_binomial_deriv: "fps_deriv (fps_binomial c) = fps_const c * fps_binomial c / (1 + X)" | 
| 53196 | 3746 | proof - | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3747 | let ?a = "fps_binomial c" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3748 | have th0: "?a = fps_const (?a$0) * ?a" by (simp) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3749 | from iffD2[OF fps_binomial_ODE_unique, OF th0] show ?thesis . | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3750 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3751 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3752 | lemma fps_binomial_add_mult: "fps_binomial (c+d) = fps_binomial c * fps_binomial d" (is "?l = ?r") | 
| 53196 | 3753 | proof - | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3754 | let ?P = "?r - ?l" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3755 | let ?b = "fps_binomial" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3756 | let ?db = "\<lambda>x. fps_deriv (?b x)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3757 | have "fps_deriv ?P = ?db c * ?b d + ?b c * ?db d - ?db (c + d)" by simp | 
| 53196 | 3758 | also have "\<dots> = inverse (1 + X) * | 
| 3759 | (fps_const c * ?b c * ?b d + fps_const d * ?b c * ?b d - fps_const (c+d) * ?b (c + d))" | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3760 | unfolding fps_binomial_deriv | 
| 36350 | 3761 | by (simp add: fps_divide_def field_simps) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3762 | also have "\<dots> = (fps_const (c + d)/ (1 + X)) * ?P" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 3763 | by (simp add: field_simps fps_divide_unit fps_const_add[symmetric] del: fps_const_add) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3764 | finally have th0: "fps_deriv ?P = fps_const (c+d) * ?P / (1 + X)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3765 | by (simp add: fps_divide_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3766 | have "?P = fps_const (?P$0) * ?b (c + d)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3767 | unfolding fps_binomial_ODE_unique[symmetric] | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3768 | using th0 by simp | 
| 54452 | 3769 | then have "?P = 0" by (simp add: fps_mult_nth) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3770 | then show ?thesis by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3771 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3772 | |
| 61552 
980dd46a03fb
Added binomial identities to CONTRIBUTORS; small lemmas on of_int/pochhammer
 eberlm parents: 
60867diff
changeset | 3773 | lemma fps_binomial_minus_one: "fps_binomial (- 1) = inverse (1 + X)" | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3774 | (is "?l = inverse ?r") | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3775 | proof- | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3776 | have th: "?r$0 \<noteq> 0" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3777 | have th': "fps_deriv (inverse ?r) = fps_const (- 1) * inverse ?r / (1 + X)" | 
| 53196 | 3778 | by (simp add: fps_inverse_deriv[OF th] fps_divide_def | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3779 | power2_eq_square mult.commute fps_const_neg[symmetric] del: fps_const_neg) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3780 | have eq: "inverse ?r $ 0 = 1" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3781 | by (simp add: fps_inverse_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3782 | from iffD1[OF fps_binomial_ODE_unique[of "inverse (1 + X)" "- 1"] th'] eq | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3783 | show ?thesis by (simp add: fps_inverse_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3784 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3785 | |
| 60558 | 3786 | text \<open>Vandermonde's Identity as a consequence.\<close> | 
| 53196 | 3787 | lemma gbinomial_Vandermonde: | 
| 3788 |   "setsum (\<lambda>k. (a gchoose k) * (b gchoose (n - k))) {0..n} = (a + b) gchoose n"
 | |
| 3789 | proof - | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3790 | let ?ba = "fps_binomial a" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3791 | let ?bb = "fps_binomial b" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3792 | let ?bab = "fps_binomial (a + b)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3793 | from fps_binomial_add_mult[of a b] have "?bab $ n = (?ba * ?bb)$n" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3794 | then show ?thesis by (simp add: fps_mult_nth) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3795 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3796 | |
| 53196 | 3797 | lemma binomial_Vandermonde: | 
| 3798 |   "setsum (\<lambda>k. (a choose k) * (b choose (n - k))) {0..n} = (a + b) choose n"
 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3799 | using gbinomial_Vandermonde[of "(of_nat a)" "of_nat b" n] | 
| 61649 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61610diff
changeset | 3800 | by (simp only: binomial_gbinomial[symmetric] of_nat_mult[symmetric] | 
| 
268d88ec9087
Tweaks for "real": Removal of [iff] status for some lemmas, adding [simp] for others. Plus fixes.
 paulson <lp15@cam.ac.uk> parents: 
61610diff
changeset | 3801 | of_nat_setsum[symmetric] of_nat_add[symmetric] of_nat_eq_iff) | 
| 52891 | 3802 | |
| 60501 | 3803 | lemma binomial_Vandermonde_same: "setsum (\<lambda>k. (n choose k)\<^sup>2) {0..n} = (2 * n) choose n"
 | 
| 3804 | using binomial_Vandermonde[of n n n, symmetric] | |
| 53195 | 3805 | unfolding mult_2 | 
| 3806 | apply (simp add: power2_eq_square) | |
| 57418 | 3807 | apply (rule setsum.cong) | 
| 53195 | 3808 | apply (auto intro: binomial_symmetric) | 
| 3809 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3810 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3811 | lemma Vandermonde_pochhammer_lemma: | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3812 | fixes a :: "'a::field_char_0" | 
| 60504 | 3813 |   assumes b: "\<forall>j\<in>{0 ..<n}. b \<noteq> of_nat j"
 | 
| 54452 | 3814 | shows "setsum (\<lambda>k. (pochhammer (- a) k * pochhammer (- (of_nat n)) k) / | 
| 53196 | 3815 |       (of_nat (fact k) * pochhammer (b - of_nat n + 1) k)) {0..n} =
 | 
| 54452 | 3816 | pochhammer (- (a + b)) n / pochhammer (- b) n" | 
| 53196 | 3817 | (is "?l = ?r") | 
| 3818 | proof - | |
| 54452 | 3819 | let ?m1 = "\<lambda>m. (- 1 :: 'a) ^ m" | 
| 3820 | let ?f = "\<lambda>m. of_nat (fact m)" | |
| 3821 | let ?p = "\<lambda>(x::'a). pochhammer (- x)" | |
| 60501 | 3822 | from b have bn0: "?p b n \<noteq> 0" | 
| 3823 | unfolding pochhammer_eq_0_iff by simp | |
| 60558 | 3824 | have th00: | 
| 3825 | "b gchoose (n - k) = | |
| 3826 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k)" | |
| 3827 | (is ?gchoose) | |
| 3828 | "pochhammer (1 + b - of_nat n) k \<noteq> 0" | |
| 3829 | (is ?pochhammer) | |
| 3830 |     if kn: "k \<in> {0..n}" for k
 | |
| 3831 | proof - | |
| 60501 | 3832 | have nz: "pochhammer (1 + b - of_nat n) n \<noteq> 0" | 
| 3833 | proof | |
| 3834 | assume "pochhammer (1 + b - of_nat n) n = 0" | |
| 3835 | then have c: "pochhammer (b - of_nat n + 1) n = 0" | |
| 3836 | by (simp add: algebra_simps) | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3837 | then obtain j where j: "j < n" "b - of_nat n + 1 = - of_nat j" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3838 | unfolding pochhammer_eq_0_iff by blast | 
| 52891 | 3839 | from j have "b = of_nat n - of_nat j - of_nat 1" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3840 | by (simp add: algebra_simps) | 
| 52891 | 3841 | then have "b = of_nat (n - j - 1)" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3842 | using j kn by (simp add: of_nat_diff) | 
| 60501 | 3843 | with b show False using j by auto | 
| 3844 | qed | |
| 52891 | 3845 | |
| 3846 | from nz kn [simplified] have nz': "pochhammer (1 + b - of_nat n) k \<noteq> 0" | |
| 35175 | 3847 | by (rule pochhammer_neq_0_mono) | 
| 60504 | 3848 | |
| 60567 | 3849 | consider "k = 0 \<or> n = 0" | "k \<noteq> 0" "n \<noteq> 0" | 
| 3850 | by blast | |
| 60504 | 3851 | then have "b gchoose (n - k) = | 
| 3852 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k)" | |
| 3853 | proof cases | |
| 3854 | case 1 | |
| 3855 | then show ?thesis | |
| 3856 | using kn by (cases "k = 0") (simp_all add: gbinomial_pochhammer) | |
| 3857 | next | |
| 60567 | 3858 | case neq: 2 | 
| 60501 | 3859 | then obtain m where m: "n = Suc m" | 
| 3860 | by (cases n) auto | |
| 60567 | 3861 | from neq(1) obtain h where h: "k = Suc h" | 
| 60501 | 3862 | by (cases k) auto | 
| 60504 | 3863 | show ?thesis | 
| 60501 | 3864 | proof (cases "k = n") | 
| 3865 | case True | |
| 3866 | then show ?thesis | |
| 59862 | 3867 | using pochhammer_minus'[where k=k and b=b] | 
| 3868 | apply (simp add: pochhammer_same) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3869 | using bn0 | 
| 53195 | 3870 | apply (simp add: field_simps power_add[symmetric]) | 
| 3871 | done | |
| 60501 | 3872 | next | 
| 3873 | case False | |
| 3874 | with kn have kn': "k < n" | |
| 3875 | by simp | |
| 54452 | 3876 |         have m1nk: "?m1 n = setprod (\<lambda>i. - 1) {0..m}" "?m1 k = setprod (\<lambda>i. - 1) {0..h}"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3877 | by (simp_all add: setprod_constant m h) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3878 | have bnz0: "pochhammer (b - of_nat n + 1) k \<noteq> 0" | 
| 52891 | 3879 | using bn0 kn | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3880 | unfolding pochhammer_eq_0_iff | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3881 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3882 | apply (erule_tac x= "n - ka - 1" in allE) | 
| 53196 | 3883 | apply (auto simp add: algebra_simps of_nat_diff) | 
| 3884 | done | |
| 54452 | 3885 |         have eq1: "setprod (\<lambda>k. (1::'a) + of_nat m - of_nat k) {0 .. h} =
 | 
| 53196 | 3886 |           setprod of_nat {Suc (m - h) .. Suc m}"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3887 | using kn' h m | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3888 | by (intro setprod.reindex_bij_witness[where i="\<lambda>k. Suc m - k" and j="\<lambda>k. Suc m - k"]) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3889 | (auto simp: of_nat_diff) | 
| 52891 | 3890 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3891 | have th1: "(?m1 k * ?p (of_nat n) k) / ?f n = 1 / of_nat(fact (n - k))" | 
| 52891 | 3892 | unfolding m1nk | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3893 | unfolding m h pochhammer_Suc_setprod | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3894 | apply (simp add: field_simps del: fact_Suc) | 
| 59730 
b7c394c7a619
The factorial function, "fact", now has type "nat => 'a"
 paulson <lp15@cam.ac.uk> parents: 
59667diff
changeset | 3895 | unfolding fact_altdef id_def | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3896 | unfolding of_nat_setprod | 
| 57418 | 3897 | unfolding setprod.distrib[symmetric] | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3898 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3899 | unfolding eq1 | 
| 57418 | 3900 | apply (subst setprod.union_disjoint[symmetric]) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3901 | apply (auto) | 
| 57418 | 3902 | apply (rule setprod.cong) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3903 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3904 | done | 
| 54452 | 3905 |         have th20: "?m1 n * ?p b n = setprod (\<lambda>i. b - of_nat i) {0..m}"
 | 
| 52891 | 3906 | unfolding m1nk | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3907 | unfolding m h pochhammer_Suc_setprod | 
| 57418 | 3908 | unfolding setprod.distrib[symmetric] | 
| 3909 | apply (rule setprod.cong) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3910 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3911 | done | 
| 54452 | 3912 |         have th21:"pochhammer (b - of_nat n + 1) k = setprod (\<lambda>i. b - of_nat i) {n - k .. n - 1}"
 | 
| 52891 | 3913 | unfolding h m | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3914 | unfolding pochhammer_Suc_setprod | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3915 | using kn m h | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3916 | by (intro setprod.reindex_bij_witness[where i="\<lambda>k. n - 1 - k" and j="\<lambda>i. m-i"]) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3917 | (auto simp: of_nat_diff) | 
| 53196 | 3918 | |
| 3919 | have "?m1 n * ?p b n = | |
| 54452 | 3920 |           pochhammer (b - of_nat n + 1) k * setprod (\<lambda>i. b - of_nat i) {0.. n - k - 1}"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3921 | unfolding th20 th21 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3922 | unfolding h m | 
| 57418 | 3923 | apply (subst setprod.union_disjoint[symmetric]) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3924 | using kn' h m | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3925 | apply auto | 
| 57418 | 3926 | apply (rule setprod.cong) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3927 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3928 | done | 
| 53196 | 3929 | then have th2: "(?m1 n * ?p b n)/pochhammer (b - of_nat n + 1) k = | 
| 54452 | 3930 |           setprod (\<lambda>i. b - of_nat i) {0.. n - k - 1}"
 | 
| 36350 | 3931 | using nz' by (simp add: field_simps) | 
| 53196 | 3932 | have "(?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k) = | 
| 3933 | ((?m1 k * ?p (of_nat n) k) / ?f n) * ((?m1 n * ?p b n)/pochhammer (b - of_nat n + 1) k)" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3934 | using bnz0 | 
| 36350 | 3935 | by (simp add: field_simps) | 
| 52891 | 3936 | also have "\<dots> = b gchoose (n - k)" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3937 | unfolding th1 th2 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3938 | using kn' by (simp add: gbinomial_def) | 
| 60501 | 3939 | finally show ?thesis by simp | 
| 3940 | qed | |
| 60504 | 3941 | qed | 
| 60558 | 3942 | then show ?gchoose and ?pochhammer | 
| 53195 | 3943 | apply (cases "n = 0") | 
| 52891 | 3944 | using nz' | 
| 53195 | 3945 | apply auto | 
| 3946 | done | |
| 60558 | 3947 | qed | 
| 60504 | 3948 | have "?r = ((a + b) gchoose n) * (of_nat (fact n) / (?m1 n * pochhammer (- b) n))" | 
| 52891 | 3949 | unfolding gbinomial_pochhammer | 
| 36350 | 3950 | using bn0 by (auto simp add: field_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3951 | also have "\<dots> = ?l" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3952 | unfolding gbinomial_Vandermonde[symmetric] | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3953 | apply (simp add: th00) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3954 | unfolding gbinomial_pochhammer | 
| 53196 | 3955 | using bn0 | 
| 3956 | apply (simp add: setsum_left_distrib setsum_right_distrib field_simps) | |
| 57418 | 3957 | apply (rule setsum.cong) | 
| 3958 | apply (rule refl) | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3959 | apply (drule th00(2)) | 
| 53196 | 3960 | apply (simp add: field_simps power_add[symmetric]) | 
| 3961 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3962 | finally show ?thesis by simp | 
| 52891 | 3963 | qed | 
| 3964 | ||
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3965 | lemma Vandermonde_pochhammer: | 
| 53195 | 3966 | fixes a :: "'a::field_char_0" | 
| 54452 | 3967 |   assumes c: "\<forall>i \<in> {0..< n}. c \<noteq> - of_nat i"
 | 
| 3968 | shows "setsum (\<lambda>k. (pochhammer a k * pochhammer (- (of_nat n)) k) / | |
| 53195 | 3969 |     (of_nat (fact k) * pochhammer c k)) {0..n} = pochhammer (c - a) n / pochhammer c n"
 | 
| 3970 | proof - | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3971 | let ?a = "- a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3972 | let ?b = "c + of_nat n - 1" | 
| 60558 | 3973 |   have h: "\<forall> j \<in>{0..< n}. ?b \<noteq> of_nat j"
 | 
| 3974 | using c | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3975 | apply (auto simp add: algebra_simps of_nat_diff) | 
| 60501 | 3976 | apply (erule_tac x = "n - j - 1" in ballE) | 
| 53195 | 3977 | apply (auto simp add: of_nat_diff algebra_simps) | 
| 3978 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3979 | have th0: "pochhammer (- (?a + ?b)) n = (- 1)^n * pochhammer (c - a) n" | 
| 59862 | 3980 | unfolding pochhammer_minus | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3981 | by (simp add: algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3982 | have th1: "pochhammer (- ?b) n = (- 1)^n * pochhammer c n" | 
| 59862 | 3983 | unfolding pochhammer_minus | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3984 | by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3985 | have nz: "pochhammer c n \<noteq> 0" using c | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3986 | by (simp add: pochhammer_eq_0_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3987 | from Vandermonde_pochhammer_lemma[where a = "?a" and b="?b" and n=n, OF h, unfolded th0 th1] | 
| 60501 | 3988 | show ?thesis | 
| 3989 | using nz by (simp add: field_simps setsum_right_distrib) | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3990 | qed | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3991 | |
| 53195 | 3992 | |
| 60501 | 3993 | subsubsection \<open>Formal trigonometric functions\<close> | 
| 29687 | 3994 | |
| 31273 | 3995 | definition "fps_sin (c::'a::field_char_0) = | 
| 29687 | 3996 | Abs_fps (\<lambda>n. if even n then 0 else (- 1) ^((n - 1) div 2) * c^n /(of_nat (fact n)))" | 
| 3997 | ||
| 31273 | 3998 | definition "fps_cos (c::'a::field_char_0) = | 
| 3999 | Abs_fps (\<lambda>n. if even n then (- 1) ^ (n div 2) * c^n / (of_nat (fact n)) else 0)" | |
| 29687 | 4000 | |
| 30488 | 4001 | lemma fps_sin_deriv: | 
| 29687 | 4002 | "fps_deriv (fps_sin c) = fps_const c * fps_cos c" | 
| 4003 | (is "?lhs = ?rhs") | |
| 31273 | 4004 | proof (rule fps_ext) | 
| 53195 | 4005 | fix n :: nat | 
| 60501 | 4006 | show "?lhs $ n = ?rhs $ n" | 
| 4007 | proof (cases "even n") | |
| 4008 | case True | |
| 52902 | 4009 | have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp | 
| 4010 | also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))" | |
| 60501 | 4011 | using True by (simp add: fps_sin_def) | 
| 52902 | 4012 | also have "\<dots> = (- 1)^(n div 2) * c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))" | 
| 4013 | unfolding fact_Suc of_nat_mult | |
| 4014 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 4015 | also have "\<dots> = (- 1)^(n div 2) *c^Suc n / of_nat (fact n)" | |
| 4016 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 60501 | 4017 | finally show ?thesis | 
| 4018 | using True by (simp add: fps_cos_def field_simps) | |
| 4019 | next | |
| 4020 | case False | |
| 4021 | then show ?thesis | |
| 4022 | by (simp_all add: fps_deriv_def fps_sin_def fps_cos_def) | |
| 4023 | qed | |
| 29687 | 4024 | qed | 
| 4025 | ||
| 52902 | 4026 | lemma fps_cos_deriv: "fps_deriv (fps_cos c) = fps_const (- c)* (fps_sin c)" | 
| 29687 | 4027 | (is "?lhs = ?rhs") | 
| 31273 | 4028 | proof (rule fps_ext) | 
| 60501 | 4029 | have th0: "- ((- 1::'a) ^ n) = (- 1)^Suc n" for n | 
| 4030 | by simp | |
| 4031 | show "?lhs $ n = ?rhs $ n" for n | |
| 4032 | proof (cases "even n") | |
| 4033 | case False | |
| 4034 | then have n0: "n \<noteq> 0" by presburger | |
| 4035 | from False have th1: "Suc ((n - 1) div 2) = Suc n div 2" | |
| 4036 | by (cases n) simp_all | |
| 52902 | 4037 | have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp | 
| 4038 | also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))" | |
| 60501 | 4039 | using False by (simp add: fps_cos_def) | 
| 52902 | 4040 | also have "\<dots> = (- 1)^((n + 1) div 2)*c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))" | 
| 4041 | unfolding fact_Suc of_nat_mult | |
| 4042 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 4043 | also have "\<dots> = (- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact n)" | |
| 4044 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 4045 | also have "\<dots> = (- ((- 1)^((n - 1) div 2))) * c^Suc n / of_nat (fact n)" | |
| 60501 | 4046 | unfolding th0 unfolding th1 by simp | 
| 4047 | finally show ?thesis | |
| 4048 | using False by (simp add: fps_sin_def field_simps) | |
| 4049 | next | |
| 4050 | case True | |
| 4051 | then show ?thesis | |
| 4052 | by (simp_all add: fps_deriv_def fps_sin_def fps_cos_def) | |
| 4053 | qed | |
| 29687 | 4054 | qed | 
| 4055 | ||
| 60501 | 4056 | lemma fps_sin_cos_sum_of_squares: "(fps_cos c)\<^sup>2 + (fps_sin c)\<^sup>2 = 1" | 
| 4057 | (is "?lhs = _") | |
| 53077 | 4058 | proof - | 
| 29687 | 4059 | have "fps_deriv ?lhs = 0" | 
| 52902 | 4060 | apply (simp add: fps_deriv_power fps_sin_deriv fps_cos_deriv) | 
| 4061 | apply (simp add: field_simps fps_const_neg[symmetric] del: fps_const_neg) | |
| 4062 | done | |
| 29687 | 4063 | then have "?lhs = fps_const (?lhs $ 0)" | 
| 4064 | unfolding fps_deriv_eq_0_iff . | |
| 4065 | also have "\<dots> = 1" | |
| 30960 | 4066 | by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def) | 
| 29687 | 4067 | finally show ?thesis . | 
| 4068 | qed | |
| 4069 | ||
| 31274 | 4070 | lemma fps_sin_nth_0 [simp]: "fps_sin c $ 0 = 0" | 
| 53195 | 4071 | unfolding fps_sin_def by simp | 
| 31274 | 4072 | |
| 4073 | lemma fps_sin_nth_1 [simp]: "fps_sin c $ 1 = c" | |
| 53195 | 4074 | unfolding fps_sin_def by simp | 
| 31274 | 4075 | |
| 4076 | lemma fps_sin_nth_add_2: | |
| 60501 | 4077 | "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat (n + 1) * of_nat (n + 2)))" | 
| 53195 | 4078 | unfolding fps_sin_def | 
| 60501 | 4079 | apply (cases n) | 
| 4080 | apply simp | |
| 60162 | 4081 | apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq del: of_nat_Suc fact_Suc) | 
| 53195 | 4082 | apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) | 
| 4083 | done | |
| 31274 | 4084 | |
| 4085 | lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1" | |
| 53195 | 4086 | unfolding fps_cos_def by simp | 
| 31274 | 4087 | |
| 4088 | lemma fps_cos_nth_1 [simp]: "fps_cos c $ 1 = 0" | |
| 53195 | 4089 | unfolding fps_cos_def by simp | 
| 31274 | 4090 | |
| 4091 | lemma fps_cos_nth_add_2: | |
| 60501 | 4092 | "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat (n + 1) * of_nat (n + 2)))" | 
| 52902 | 4093 | unfolding fps_cos_def | 
| 60162 | 4094 | apply (simp add: nonzero_divide_eq_eq nonzero_eq_divide_eq del: of_nat_Suc fact_Suc) | 
| 52902 | 4095 | apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) | 
| 4096 | done | |
| 4097 | ||
| 4098 | lemma nat_induct2: "P 0 \<Longrightarrow> P 1 \<Longrightarrow> (\<And>n. P n \<Longrightarrow> P (n + 2)) \<Longrightarrow> P (n::nat)" | |
| 4099 | unfolding One_nat_def numeral_2_eq_2 | |
| 4100 | apply (induct n rule: nat_less_induct) | |
| 53196 | 4101 | apply (case_tac n) | 
| 4102 | apply simp | |
| 4103 | apply (rename_tac m) | |
| 4104 | apply (case_tac m) | |
| 4105 | apply simp | |
| 4106 | apply (rename_tac k) | |
| 4107 | apply (case_tac k) | |
| 4108 | apply simp_all | |
| 52902 | 4109 | done | 
| 31274 | 4110 | |
| 4111 | lemma nat_add_1_add_1: "(n::nat) + 1 + 1 = n + 2" | |
| 52902 | 4112 | by simp | 
| 31274 | 4113 | |
| 4114 | lemma eq_fps_sin: | |
| 52902 | 4115 | assumes 0: "a $ 0 = 0" | 
| 4116 | and 1: "a $ 1 = c" | |
| 4117 | and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)" | |
| 31274 | 4118 | shows "a = fps_sin c" | 
| 52902 | 4119 | apply (rule fps_ext) | 
| 4120 | apply (induct_tac n rule: nat_induct2) | |
| 4121 | apply (simp add: 0) | |
| 4122 | apply (simp add: 1 del: One_nat_def) | |
| 4123 | apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) | |
| 4124 | apply (simp add: nat_add_1_add_1 fps_sin_nth_add_2 | |
| 4125 | del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') | |
| 4126 | apply (subst minus_divide_left) | |
| 60162 | 4127 | apply (subst nonzero_eq_divide_eq) | 
| 52902 | 4128 | apply (simp del: of_nat_add of_nat_Suc) | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 4129 | apply (simp only: ac_simps) | 
| 52902 | 4130 | done | 
| 31274 | 4131 | |
| 4132 | lemma eq_fps_cos: | |
| 52902 | 4133 | assumes 0: "a $ 0 = 1" | 
| 4134 | and 1: "a $ 1 = 0" | |
| 4135 | and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)" | |
| 31274 | 4136 | shows "a = fps_cos c" | 
| 52902 | 4137 | apply (rule fps_ext) | 
| 4138 | apply (induct_tac n rule: nat_induct2) | |
| 4139 | apply (simp add: 0) | |
| 4140 | apply (simp add: 1 del: One_nat_def) | |
| 4141 | apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) | |
| 4142 | apply (simp add: nat_add_1_add_1 fps_cos_nth_add_2 | |
| 4143 | del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') | |
| 4144 | apply (subst minus_divide_left) | |
| 60162 | 4145 | apply (subst nonzero_eq_divide_eq) | 
| 52902 | 4146 | apply (simp del: of_nat_add of_nat_Suc) | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 4147 | apply (simp only: ac_simps) | 
| 52902 | 4148 | done | 
| 31274 | 4149 | |
| 4150 | lemma mult_nth_0 [simp]: "(a * b) $ 0 = a $ 0 * b $ 0" | |
| 52902 | 4151 | by (simp add: fps_mult_nth) | 
| 31274 | 4152 | |
| 4153 | lemma mult_nth_1 [simp]: "(a * b) $ 1 = a $ 0 * b $ 1 + a $ 1 * b $ 0" | |
| 52902 | 4154 | by (simp add: fps_mult_nth) | 
| 4155 | ||
| 4156 | lemma fps_sin_add: "fps_sin (a + b) = fps_sin a * fps_cos b + fps_cos a * fps_sin b" | |
| 4157 | apply (rule eq_fps_sin [symmetric], simp, simp del: One_nat_def) | |
| 4158 | apply (simp del: fps_const_neg fps_const_add fps_const_mult | |
| 4159 | add: fps_const_add [symmetric] fps_const_neg [symmetric] | |
| 4160 | fps_sin_deriv fps_cos_deriv algebra_simps) | |
| 4161 | done | |
| 4162 | ||
| 4163 | lemma fps_cos_add: "fps_cos (a + b) = fps_cos a * fps_cos b - fps_sin a * fps_sin b" | |
| 4164 | apply (rule eq_fps_cos [symmetric], simp, simp del: One_nat_def) | |
| 4165 | apply (simp del: fps_const_neg fps_const_add fps_const_mult | |
| 4166 | add: fps_const_add [symmetric] fps_const_neg [symmetric] | |
| 4167 | fps_sin_deriv fps_cos_deriv algebra_simps) | |
| 4168 | done | |
| 31274 | 4169 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 4170 | lemma fps_sin_even: "fps_sin (- c) = - fps_sin c" | 
| 56479 
91958d4b30f7
revert c1bbd3e22226, a14831ac3023, and 36489d77c484: divide_minus_left/right are again simp rules
 hoelzl parents: 
56410diff
changeset | 4171 | by (auto simp add: fps_eq_iff fps_sin_def) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 4172 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 4173 | lemma fps_cos_odd: "fps_cos (- c) = fps_cos c" | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 4174 | by (auto simp add: fps_eq_iff fps_cos_def) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 4175 | |
| 29687 | 4176 | definition "fps_tan c = fps_sin c / fps_cos c" | 
| 4177 | ||
| 53077 | 4178 | lemma fps_tan_deriv: "fps_deriv (fps_tan c) = fps_const c / (fps_cos c)\<^sup>2" | 
| 52902 | 4179 | proof - | 
| 29687 | 4180 | have th0: "fps_cos c $ 0 \<noteq> 0" by (simp add: fps_cos_def) | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4181 | from this have "fps_cos c \<noteq> 0" by (intro notI) simp | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 4182 | hence "fps_deriv (fps_tan c) = | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4183 | fps_const c * (fps_cos c^2 + fps_sin c^2) / (fps_cos c^2)" | 
| 62102 
877463945ce9
fix code generation for uniformity: uniformity is a non-computable pure data.
 hoelzl parents: 
62101diff
changeset | 4184 | by (simp add: fps_tan_def fps_divide_deriv power2_eq_square algebra_simps | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4185 | fps_sin_deriv fps_cos_deriv fps_const_neg[symmetric] div_mult_swap | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4186 | del: fps_const_neg) | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4187 | also note fps_sin_cos_sum_of_squares | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4188 | finally show ?thesis by simp | 
| 29687 | 4189 | qed | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 4190 | |
| 60558 | 4191 | text \<open>Connection to E c over the complex numbers --- Euler and de Moivre.\<close> | 
| 60501 | 4192 | |
| 4193 | lemma Eii_sin_cos: "E (ii * c) = fps_cos c + fps_const ii * fps_sin c" | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4194 | (is "?l = ?r") | 
| 52902 | 4195 | proof - | 
| 60501 | 4196 | have "?l $ n = ?r $ n" for n | 
| 4197 | proof (cases "even n") | |
| 4198 | case True | |
| 4199 | then obtain m where m: "n = 2 * m" .. | |
| 4200 | show ?thesis | |
| 4201 | by (simp add: m fps_sin_def fps_cos_def power_mult_distrib power_mult power_minus [of "c ^ 2"]) | |
| 4202 | next | |
| 4203 | case False | |
| 4204 | then obtain m where m: "n = 2 * m + 1" .. | |
| 4205 | show ?thesis | |
| 4206 | by (simp add: m fps_sin_def fps_cos_def power_mult_distrib | |
| 4207 | power_mult power_minus [of "c ^ 2"]) | |
| 4208 | qed | |
| 4209 | then show ?thesis | |
| 4210 | by (simp add: fps_eq_iff) | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4211 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4212 | |
| 52902 | 4213 | lemma E_minus_ii_sin_cos: "E (- (ii * c)) = fps_cos c - fps_const ii * fps_sin c" | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4214 | unfolding minus_mult_right Eii_sin_cos by (simp add: fps_sin_even fps_cos_odd) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4215 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4216 | lemma fps_const_minus: "fps_const (c::'a::group_add) - fps_const d = fps_const (c - d)" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4217 | by (fact fps_const_sub) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4218 | |
| 54681 | 4219 | lemma fps_numeral_fps_const: "numeral i = fps_const (numeral i :: 'a::comm_ring_1)" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 4220 | by (fact numeral_fps_const) (* FIXME: duplicate *) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4221 | |
| 52902 | 4222 | lemma fps_cos_Eii: "fps_cos c = (E (ii * c) + E (- ii * c)) / fps_const 2" | 
| 4223 | proof - | |
| 52891 | 4224 | have th: "fps_cos c + fps_cos c = fps_cos c * fps_const 2" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 4225 | by (simp add: numeral_fps_const) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4226 | show ?thesis | 
| 60501 | 4227 | unfolding Eii_sin_cos minus_mult_commute | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4228 | by (simp add: fps_sin_even fps_cos_odd numeral_fps_const fps_divide_unit fps_const_inverse th) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4229 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4230 | |
| 52902 | 4231 | lemma fps_sin_Eii: "fps_sin c = (E (ii * c) - E (- ii * c)) / fps_const (2*ii)" | 
| 4232 | proof - | |
| 52891 | 4233 | have th: "fps_const \<i> * fps_sin c + fps_const \<i> * fps_sin c = fps_sin c * fps_const (2 * ii)" | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 4234 | by (simp add: fps_eq_iff numeral_fps_const) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4235 | show ?thesis | 
| 52902 | 4236 | unfolding Eii_sin_cos minus_mult_commute | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4237 | by (simp add: fps_sin_even fps_cos_odd fps_divide_unit fps_const_inverse th) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4238 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4239 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4240 | lemma fps_tan_Eii: | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4241 | "fps_tan c = (E (ii * c) - E (- ii * c)) / (fps_const ii * (E (ii * c) + E (- ii * c)))" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4242 | unfolding fps_tan_def fps_sin_Eii fps_cos_Eii mult_minus_left E_neg | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4243 | apply (simp add: fps_divide_unit fps_inverse_mult fps_const_mult[symmetric] fps_const_inverse del: fps_const_mult) | 
| 52902 | 4244 | apply simp | 
| 4245 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4246 | |
| 60501 | 4247 | lemma fps_demoivre: | 
| 4248 | "(fps_cos a + fps_const ii * fps_sin a)^n = | |
| 4249 | fps_cos (of_nat n * a) + fps_const ii * fps_sin (of_nat n * a)" | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4250 | unfolding Eii_sin_cos[symmetric] E_power_mult | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 4251 | by (simp add: ac_simps) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 4252 | |
| 52902 | 4253 | |
| 60500 | 4254 | subsection \<open>Hypergeometric series\<close> | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4255 | |
| 62422 | 4256 | (* TODO: Rename this *) | 
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59862diff
changeset | 4257 | definition "F as bs (c::'a::{field_char_0,field}) =
 | 
| 54452 | 4258 | Abs_fps (\<lambda>n. (foldl (\<lambda>r a. r* pochhammer a n) 1 as * c^n) / | 
| 4259 | (foldl (\<lambda>r b. r * pochhammer b n) 1 bs * of_nat (fact n)))" | |
| 52902 | 4260 | |
| 4261 | lemma F_nth[simp]: "F as bs c $ n = | |
| 4262 | (foldl (\<lambda>r a. r* pochhammer a n) 1 as * c^n) / | |
| 4263 | (foldl (\<lambda>r b. r * pochhammer b n) 1 bs * of_nat (fact n))" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4264 | by (simp add: F_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4265 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4266 | lemma foldl_mult_start: | 
| 54452 | 4267 | fixes v :: "'a::comm_ring_1" | 
| 4268 | shows "foldl (\<lambda>r x. r * f x) v as * x = foldl (\<lambda>r x. r * f x) (v * x) as " | |
| 48757 | 4269 | by (induct as arbitrary: x v) (auto simp add: algebra_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4270 | |
| 53196 | 4271 | lemma foldr_mult_foldl: | 
| 54452 | 4272 | fixes v :: "'a::comm_ring_1" | 
| 4273 | shows "foldr (\<lambda>x r. r * f x) as v = foldl (\<lambda>r x. r * f x) v as" | |
| 48757 | 4274 | by (induct as arbitrary: v) (auto simp add: foldl_mult_start) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4275 | |
| 53196 | 4276 | lemma F_nth_alt: | 
| 4277 | "F as bs c $ n = foldr (\<lambda>a r. r * pochhammer a n) as (c ^ n) / | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4278 | foldr (\<lambda>b r. r * pochhammer b n) bs (of_nat (fact n))" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4279 | by (simp add: foldl_mult_start foldr_mult_foldl) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4280 | |
| 52891 | 4281 | lemma F_E[simp]: "F [] [] c = E c" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4282 | by (simp add: fps_eq_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4283 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4284 | lemma F_1_0[simp]: "F [1] [] c = 1/(1 - fps_const c * X)" | 
| 52902 | 4285 | proof - | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4286 | let ?a = "(Abs_fps (\<lambda>n. 1)) oo (fps_const c * X)" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4287 | have th0: "(fps_const c * X) $ 0 = 0" by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4288 | show ?thesis unfolding gp[OF th0, symmetric] | 
| 53196 | 4289 | by (auto simp add: fps_eq_iff pochhammer_fact[symmetric] | 
| 57418 | 4290 | fps_compose_nth power_mult_distrib cond_value_iff setsum.delta' cong del: if_weak_cong) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4291 | qed | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4292 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4293 | lemma F_B[simp]: "F [-a] [] (- 1) = fps_binomial a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4294 | by (simp add: fps_eq_iff gbinomial_pochhammer algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4295 | |
| 60501 | 4296 | lemma F_0[simp]: "F as bs c $ 0 = 1" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4297 | apply simp | 
| 54452 | 4298 | apply (subgoal_tac "\<forall>as. foldl (\<lambda>(r::'a) (a::'a). r) 1 as = 1") | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4299 | apply auto | 
| 48757 | 4300 | apply (induct_tac as) | 
| 4301 | apply auto | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4302 | done | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4303 | |
| 53196 | 4304 | lemma foldl_prod_prod: | 
| 54452 | 4305 | "foldl (\<lambda>(r::'b::comm_ring_1) (x::'a::comm_ring_1). r * f x) v as * foldl (\<lambda>r x. r * g x) w as = | 
| 4306 | foldl (\<lambda>r x. r * f x * g x) (v * w) as" | |
| 48757 | 4307 | by (induct as arbitrary: v w) (auto simp add: algebra_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4308 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4309 | |
| 53196 | 4310 | lemma F_rec: | 
| 54452 | 4311 | "F as bs c $ Suc n = ((foldl (\<lambda>r a. r* (a + of_nat n)) c as) / | 
| 4312 | (foldl (\<lambda>r b. r * (b + of_nat n)) (of_nat (Suc n)) bs )) * F as bs c $ n" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4313 | apply (simp del: of_nat_Suc of_nat_add fact_Suc) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4314 | apply (simp add: foldl_mult_start del: fact_Suc of_nat_Suc) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4315 | unfolding foldl_prod_prod[unfolded foldl_mult_start] pochhammer_Suc | 
| 52902 | 4316 | apply (simp add: algebra_simps of_nat_mult) | 
| 4317 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4318 | |
| 54452 | 4319 | lemma XD_nth[simp]: "XD a $ n = (if n = 0 then 0 else of_nat n * a$n)" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4320 | by (simp add: XD_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4321 | |
| 60501 | 4322 | lemma XD_0th[simp]: "XD a $ 0 = 0" | 
| 4323 | by simp | |
| 4324 | lemma XD_Suc[simp]:" XD a $ Suc n = of_nat (Suc n) * a $ Suc n" | |
| 4325 | by simp | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4326 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4327 | definition "XDp c a = XD a + fps_const c * a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4328 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4329 | lemma XDp_nth[simp]: "XDp c a $ n = (c + of_nat n) * a$n" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4330 | by (simp add: XDp_def algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4331 | |
| 54681 | 4332 | lemma XDp_commute: "XDp b \<circ> XDp (c::'a::comm_ring_1) = XDp c \<circ> XDp b" | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 4333 | by (auto simp add: XDp_def fun_eq_iff fps_eq_iff algebra_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4334 | |
| 52902 | 4335 | lemma XDp0 [simp]: "XDp 0 = XD" | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 4336 | by (simp add: fun_eq_iff fps_eq_iff) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4337 | |
| 52902 | 4338 | lemma XDp_fps_integral [simp]: "XDp 0 (fps_integral a c) = X * a" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4339 | by (simp add: fps_eq_iff fps_integral_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4340 | |
| 52891 | 4341 | lemma F_minus_nat: | 
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59862diff
changeset | 4342 |   "F [- of_nat n] [- of_nat (n + m)] (c::'a::{field_char_0,field}) $ k =
 | 
| 54452 | 4343 | (if k \<le> n then | 
| 52902 | 4344 | pochhammer (- of_nat n) k * c ^ k / (pochhammer (- of_nat (n + m)) k * of_nat (fact k)) | 
| 4345 | else 0)" | |
| 59867 
58043346ca64
given up separate type classes demanding `inverse 0 = 0`
 haftmann parents: 
59862diff
changeset | 4346 |   "F [- of_nat m] [- of_nat (m + n)] (c::'a::{field_char_0,field}) $ k =
 | 
| 54452 | 4347 | (if k \<le> m then | 
| 52902 | 4348 | pochhammer (- of_nat m) k * c ^ k / (pochhammer (- of_nat (m + n)) k * of_nat (fact k)) | 
| 4349 | else 0)" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4350 | by (auto simp add: pochhammer_eq_0_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4351 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4352 | lemma setsum_eq_if: "setsum f {(n::nat) .. m} = (if m < n then 0 else f n + setsum f {n+1 .. m})"
 | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4353 | apply simp | 
| 57418 | 4354 | apply (subst setsum.insert[symmetric]) | 
| 52902 | 4355 | apply (auto simp add: not_less setsum_head_Suc) | 
| 4356 | done | |
| 4357 | ||
| 4358 | lemma pochhammer_rec_if: "pochhammer a n = (if n = 0 then 1 else a * pochhammer (a + 1) (n - 1))" | |
| 4359 | by (cases n) (simp_all add: pochhammer_rec) | |
| 4360 | ||
| 54681 | 4361 | lemma XDp_foldr_nth [simp]: "foldr (\<lambda>c r. XDp c \<circ> r) cs (\<lambda>c. XDp c a) c0 $ n = | 
| 54452 | 4362 | foldr (\<lambda>c r. (c + of_nat n) * r) cs (c0 + of_nat n) * a$n" | 
| 48757 | 4363 | by (induct cs arbitrary: c0) (auto simp add: algebra_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4364 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4365 | lemma genric_XDp_foldr_nth: | 
| 54452 | 4366 | assumes f: "\<forall>n c a. f c a $ n = (of_nat n + k c) * a$n" | 
| 54681 | 4367 | shows "foldr (\<lambda>c r. f c \<circ> r) cs (\<lambda>c. g c a) c0 $ n = | 
| 54452 | 4368 | foldr (\<lambda>c r. (k c + of_nat n) * r) cs (g c0 a $ n)" | 
| 48757 | 4369 | by (induct cs arbitrary: c0) (auto simp add: algebra_simps f) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 4370 | |
| 51107 | 4371 | lemma dist_less_imp_nth_equal: | 
| 4372 | assumes "dist f g < inverse (2 ^ i)" | |
| 52902 | 4373 | and"j \<le> i" | 
| 51107 | 4374 | shows "f $ j = g $ j" | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 4375 | proof (rule ccontr) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 4376 | assume "f $ j \<noteq> g $ j" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4377 | hence "f \<noteq> g" by auto | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4378 | with assms have "i < subdegree (f - g)" | 
| 62390 | 4379 | by (simp add: if_split_asm dist_fps_def) | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 4380 | also have "\<dots> \<le> j" | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4381 | using \<open>f $ j \<noteq> g $ j\<close> by (intro subdegree_leI) simp_all | 
| 60500 | 4382 | finally show False using \<open>j \<le> i\<close> by simp | 
| 52902 | 4383 | qed | 
| 51107 | 4384 | |
| 4385 | lemma nth_equal_imp_dist_less: | |
| 4386 | assumes "\<And>j. j \<le> i \<Longrightarrow> f $ j = g $ j" | |
| 4387 | shows "dist f g < inverse (2 ^ i)" | |
| 52902 | 4388 | proof (cases "f = g") | 
| 60501 | 4389 | case True | 
| 4390 | then show ?thesis by simp | |
| 4391 | next | |
| 52902 | 4392 | case False | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4393 | with assms have "dist f g = inverse (2 ^ subdegree (f - g))" | 
| 62390 | 4394 | by (simp add: if_split_asm dist_fps_def) | 
| 51107 | 4395 | moreover | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4396 | from assms and False have "i < subdegree (f - g)" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4397 | by (intro subdegree_greaterI) simp_all | 
| 51107 | 4398 | ultimately show ?thesis by simp | 
| 60501 | 4399 | qed | 
| 52902 | 4400 | |
| 4401 | lemma dist_less_eq_nth_equal: "dist f g < inverse (2 ^ i) \<longleftrightarrow> (\<forall>j \<le> i. f $ j = g $ j)" | |
| 51107 | 4402 | using dist_less_imp_nth_equal nth_equal_imp_dist_less by blast | 
| 4403 | ||
| 4404 | instance fps :: (comm_ring_1) complete_space | |
| 4405 | proof | |
| 54681 | 4406 | fix X :: "nat \<Rightarrow> 'a fps" | 
| 51107 | 4407 | assume "Cauchy X" | 
| 60501 | 4408 | obtain M where M: "\<forall>i. \<forall>m \<ge> M i. \<forall>j \<le> i. X (M i) $ j = X m $ j" | 
| 4409 | proof - | |
| 4410 | have "\<exists>M. \<forall>m \<ge> M. \<forall>j\<le>i. X M $ j = X m $ j" for i | |
| 4411 | proof - | |
| 4412 | have "0 < inverse ((2::real)^i)" by simp | |
| 4413 | from metric_CauchyD[OF \<open>Cauchy X\<close> this] dist_less_imp_nth_equal | |
| 4414 | show ?thesis by blast | |
| 4415 | qed | |
| 4416 | then show ?thesis using that by metis | |
| 4417 | qed | |
| 4418 | ||
| 51107 | 4419 | show "convergent X" | 
| 4420 | proof (rule convergentI) | |
| 61969 | 4421 | show "X \<longlonglongrightarrow> Abs_fps (\<lambda>i. X (M i) $ i)" | 
| 51107 | 4422 | unfolding tendsto_iff | 
| 4423 | proof safe | |
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4424 | fix e::real assume e: "0 < e" | 
| 61969 | 4425 | have "(\<lambda>n. inverse (2 ^ n) :: real) \<longlonglongrightarrow> 0" by (rule LIMSEQ_inverse_realpow_zero) simp_all | 
| 61608 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4426 | from this and e have "eventually (\<lambda>i. inverse (2 ^ i) < e) sequentially" | 
| 
a0487caabb4a
subdegree/shift/cutoff and Euclidean ring instance for formal power series
 eberlm parents: 
61585diff
changeset | 4427 | by (rule order_tendstoD) | 
| 60501 | 4428 | then obtain i where "inverse (2 ^ i) < e" | 
| 4429 | by (auto simp: eventually_sequentially) | |
| 4430 | have "eventually (\<lambda>x. M i \<le> x) sequentially" | |
| 4431 | by (auto simp: eventually_sequentially) | |
| 54452 | 4432 | then show "eventually (\<lambda>x. dist (X x) (Abs_fps (\<lambda>i. X (M i) $ i)) < e) sequentially" | 
| 51107 | 4433 | proof eventually_elim | 
| 52902 | 4434 | fix x | 
| 60501 | 4435 | assume x: "M i \<le> x" | 
| 4436 | have "X (M i) $ j = X (M j) $ j" if "j \<le> i" for j | |
| 4437 | using M that by (metis nat_le_linear) | |
| 4438 | with x have "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < inverse (2 ^ i)" | |
| 51107 | 4439 | using M by (force simp: dist_less_eq_nth_equal) | 
| 60500 | 4440 | also note \<open>inverse (2 ^ i) < e\<close> | 
| 51107 | 4441 | finally show "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < e" . | 
| 4442 | qed | |
| 4443 | qed | |
| 4444 | qed | |
| 4445 | qed | |
| 4446 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 4447 | end |