| author | wenzelm | 
| Tue, 28 Oct 2014 10:35:38 +0100 | |
| changeset 58798 | 49ed5eea15d4 | 
| parent 58709 | efdc6c533bd3 | 
| child 58881 | b9556a055632 | 
| permissions | -rw-r--r-- | 
| 41959 | 1 | (* Title: HOL/Library/Formal_Power_Series.thy | 
| 29687 | 2 | Author: Amine Chaieb, University of Cambridge | 
| 3 | *) | |
| 4 | ||
| 5 | header{* A formalization of formal power series *}
 | |
| 6 | ||
| 7 | theory Formal_Power_Series | |
| 55159 
608c157d743d
Replacing the theory Library/Binomial by Number_Theory/Binomial
 paulson <lp15@cam.ac.uk> parents: 
54681diff
changeset | 8 | imports "~~/src/HOL/Number_Theory/Binomial" | 
| 29687 | 9 | begin | 
| 10 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 11 | |
| 29906 | 12 | subsection {* The type of formal power series*}
 | 
| 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 | |
| 48757 | 29 | text{* Definition of the basic elements 0 and 1 and the basic operations of addition,
 | 
| 30 | negation and multiplication *} | |
| 29687 | 31 | |
| 36409 | 32 | instantiation fps :: (zero) zero | 
| 29687 | 33 | begin | 
| 34 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 35 | definition fps_zero_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 36 | "0 = Abs_fps (\<lambda>n. 0)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 37 | |
| 29687 | 38 | instance .. | 
| 39 | end | |
| 40 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 41 | lemma fps_zero_nth [simp]: "0 $ n = 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 42 | unfolding fps_zero_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 43 | |
| 36409 | 44 | instantiation fps :: ("{one, zero}") one
 | 
| 29687 | 45 | begin | 
| 46 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 47 | definition fps_one_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 48 | "1 = Abs_fps (\<lambda>n. if n = 0 then 1 else 0)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 49 | |
| 29687 | 50 | instance .. | 
| 51 | end | |
| 52 | ||
| 30488 | 53 | 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 | 54 | unfolding fps_one_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 55 | |
| 54681 | 56 | instantiation fps :: (plus) plus | 
| 29687 | 57 | begin | 
| 58 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 59 | definition fps_plus_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 60 | "op + = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n + g $ n))" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 61 | |
| 29687 | 62 | instance .. | 
| 63 | end | |
| 64 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 65 | 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 | 66 | unfolding fps_plus_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 :: (minus) minus | 
| 29687 | 69 | begin | 
| 70 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 71 | definition fps_minus_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 72 | "op - = (\<lambda>f g. Abs_fps (\<lambda>n. f $ n - g $ n))" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 73 | |
| 29687 | 74 | instance .. | 
| 75 | end | |
| 76 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 77 | 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 | 78 | unfolding fps_minus_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 79 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 80 | instantiation fps :: (uminus) uminus | 
| 29687 | 81 | begin | 
| 82 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 83 | definition fps_uminus_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 84 | "uminus = (\<lambda>f. Abs_fps (\<lambda>n. - (f $ n)))" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 85 | |
| 29687 | 86 | instance .. | 
| 87 | end | |
| 88 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 89 | 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 | 90 | unfolding fps_uminus_def by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 91 | |
| 54681 | 92 | instantiation fps :: ("{comm_monoid_add, times}") times
 | 
| 29687 | 93 | begin | 
| 94 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 95 | definition fps_times_def: | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 96 | "op * = (\<lambda>f g. Abs_fps (\<lambda>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 | 97 | |
| 29687 | 98 | instance .. | 
| 99 | end | |
| 100 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 101 | 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 | 102 | unfolding fps_times_def by simp | 
| 29687 | 103 | |
| 52891 | 104 | declare atLeastAtMost_iff [presburger] | 
| 105 | declare Bex_def [presburger] | |
| 106 | declare Ball_def [presburger] | |
| 29687 | 107 | |
| 29913 | 108 | lemma mult_delta_left: | 
| 109 | fixes x y :: "'a::mult_zero" | |
| 110 | shows "(if b then x else 0) * y = (if b then x * y else 0)" | |
| 111 | by simp | |
| 112 | ||
| 113 | lemma mult_delta_right: | |
| 114 | fixes x y :: "'a::mult_zero" | |
| 115 | shows "x * (if b then y else 0) = (if b then x * y else 0)" | |
| 116 | by simp | |
| 117 | ||
| 29687 | 118 | lemma cond_value_iff: "f (if b then x else y) = (if b then f x else f y)" | 
| 119 | by auto | |
| 52891 | 120 | |
| 29687 | 121 | lemma cond_application_beta: "(if b then f else g) x = (if b then f x else g x)" | 
| 122 | by auto | |
| 123 | ||
| 30488 | 124 | subsection{* Formal power series form a commutative ring with unity, if the range of sequences
 | 
| 29687 | 125 | they represent is a commutative ring with unity*} | 
| 126 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 127 | instance fps :: (semigroup_add) semigroup_add | 
| 29687 | 128 | proof | 
| 52891 | 129 | fix a b c :: "'a fps" | 
| 130 | show "a + b + c = a + (b + c)" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 131 | by (simp add: fps_ext add.assoc) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 132 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 133 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 134 | instance fps :: (ab_semigroup_add) ab_semigroup_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 135 | proof | 
| 52891 | 136 | fix a b :: "'a fps" | 
| 137 | show "a + b = b + a" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 138 | by (simp add: fps_ext add.commute) | 
| 29687 | 139 | qed | 
| 140 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 141 | lemma fps_mult_assoc_lemma: | 
| 53195 | 142 | fixes k :: nat | 
| 143 | 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 | 144 | 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 | 145 | (\<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 | 146 | by (induct k) (simp_all add: Suc_diff_le setsum.distrib add.assoc) | 
| 29687 | 147 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 148 | instance fps :: (semiring_0) semigroup_mult | 
| 29687 | 149 | proof | 
| 150 | fix a b c :: "'a fps" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 151 | show "(a * b) * c = a * (b * c)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 152 | proof (rule fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 153 | fix n :: nat | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 154 | 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 | 155 | (\<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 | 156 | by (rule fps_mult_assoc_lemma) | 
| 52891 | 157 | 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 | 158 | 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 | 159 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 160 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 161 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 162 | lemma fps_mult_commute_lemma: | 
| 52903 | 163 | fixes n :: nat | 
| 164 | 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 | 165 | 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 | 166 | 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 | 167 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 168 | instance fps :: (comm_semiring_0) ab_semigroup_mult | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 169 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 170 | fix a b :: "'a fps" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 171 | show "a * b = b * a" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 172 | proof (rule fps_ext) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 173 | fix n :: nat | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 174 | 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 | 175 | by (rule fps_mult_commute_lemma) | 
| 52891 | 176 | 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 | 177 | by (simp add: fps_mult_nth mult.commute) | 
| 29687 | 178 | qed | 
| 179 | qed | |
| 180 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 181 | instance fps :: (monoid_add) monoid_add | 
| 29687 | 182 | proof | 
| 52891 | 183 | fix a :: "'a fps" | 
| 184 | show "0 + a = a" by (simp add: fps_ext) | |
| 185 | show "a + 0 = a" by (simp add: fps_ext) | |
| 29687 | 186 | qed | 
| 187 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 188 | instance fps :: (comm_monoid_add) comm_monoid_add | 
| 29687 | 189 | proof | 
| 52891 | 190 | fix a :: "'a fps" | 
| 191 | show "0 + a = a" by (simp add: fps_ext) | |
| 29687 | 192 | qed | 
| 193 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 194 | instance fps :: (semiring_1) monoid_mult | 
| 29687 | 195 | proof | 
| 52891 | 196 | fix a :: "'a fps" | 
| 57418 | 197 | show "1 * a = a" by (simp add: fps_ext fps_mult_nth mult_delta_left setsum.delta) | 
| 198 | show "a * 1 = a" by (simp add: fps_ext fps_mult_nth mult_delta_right setsum.delta') | |
| 29687 | 199 | qed | 
| 200 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 201 | instance fps :: (cancel_semigroup_add) cancel_semigroup_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 202 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 203 | fix a b c :: "'a fps" | 
| 52891 | 204 |   { assume "a + b = a + c" then show "b = c" by (simp add: expand_fps_eq) }
 | 
| 205 |   { assume "b + a = c + a" then show "b = c" by (simp add: expand_fps_eq) }
 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 206 | qed | 
| 29687 | 207 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 208 | 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 | 209 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 210 | fix a b c :: "'a fps" | 
| 52891 | 211 | assume "a + b = a + c" | 
| 212 | then show "b = c" by (simp add: expand_fps_eq) | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 213 | qed | 
| 29687 | 214 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 215 | 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 | 216 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 217 | instance fps :: (group_add) group_add | 
| 29687 | 218 | proof | 
| 52891 | 219 | fix a b :: "'a fps" | 
| 220 | show "- a + a = 0" by (simp add: fps_ext) | |
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 221 | show "a + - b = a - b" by (simp add: fps_ext) | 
| 29687 | 222 | qed | 
| 223 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 224 | instance fps :: (ab_group_add) ab_group_add | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 225 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 226 | fix a b :: "'a fps" | 
| 52891 | 227 | show "- a + a = 0" by (simp add: fps_ext) | 
| 228 | 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 | 229 | qed | 
| 29687 | 230 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 231 | instance fps :: (zero_neq_one) zero_neq_one | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 232 | by default (simp add: expand_fps_eq) | 
| 29687 | 233 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 234 | instance fps :: (semiring_0) semiring | 
| 29687 | 235 | proof | 
| 236 | fix a b c :: "'a fps" | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 237 | show "(a + b) * c = a * c + b * c" | 
| 57418 | 238 | 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 | 239 | show "a * (b + c) = a * b + a * c" | 
| 57418 | 240 | by (simp add: expand_fps_eq fps_mult_nth distrib_left setsum.distrib) | 
| 29687 | 241 | qed | 
| 242 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 243 | instance fps :: (semiring_0) semiring_0 | 
| 29687 | 244 | proof | 
| 53195 | 245 | fix a :: "'a fps" | 
| 52891 | 246 | show "0 * a = 0" by (simp add: fps_ext fps_mult_nth) | 
| 247 | show "a * 0 = 0" by (simp add: fps_ext fps_mult_nth) | |
| 29687 | 248 | qed | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 249 | |
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 250 | instance fps :: (semiring_0_cancel) semiring_0_cancel .. | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 251 | |
| 29906 | 252 | subsection {* Selection of the nth power of the implicit variable in the infinite sum*}
 | 
| 29687 | 253 | |
| 254 | 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 | 255 | by (simp add: expand_fps_eq) | 
| 29687 | 256 | |
| 52902 | 257 | lemma fps_nonzero_nth_minimal: "f \<noteq> 0 \<longleftrightarrow> (\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m < n. f $ m = 0))" | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 258 | proof | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 259 | let ?n = "LEAST n. f $ n \<noteq> 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 260 | assume "f \<noteq> 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 261 | then have "\<exists>n. f $ n \<noteq> 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 262 | by (simp add: fps_nonzero_nth) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 263 | then have "f $ ?n \<noteq> 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 264 | by (rule LeastI_ex) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 265 | moreover have "\<forall>m<?n. f $ m = 0" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 266 | by (auto dest: not_less_Least) | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 267 | ultimately have "f $ ?n \<noteq> 0 \<and> (\<forall>m<?n. f $ m = 0)" .. | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 268 | then show "\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m<n. f $ m = 0)" .. | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 269 | next | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 270 | assume "\<exists>n. f $ n \<noteq> 0 \<and> (\<forall>m<n. f $ m = 0)" | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 271 | then show "f \<noteq> 0" by (auto simp add: expand_fps_eq) | 
| 29687 | 272 | qed | 
| 273 | ||
| 274 | 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 | 275 | by (rule expand_fps_eq) | 
| 29687 | 276 | |
| 52891 | 277 | 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 | 278 | proof (cases "finite S") | 
| 52891 | 279 | case True | 
| 280 | 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 | 281 | next | 
| 52891 | 282 | case False | 
| 283 | then show ?thesis by simp | |
| 29687 | 284 | qed | 
| 285 | ||
| 29906 | 286 | subsection{* Injection of the basic ring elements and multiplication by scalars *}
 | 
| 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 | |
| 29906 | 333 | subsection {* Formal power series form an integral domain*}
 | 
| 29687 | 334 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 335 | instance fps :: (ring) ring .. | 
| 29687 | 336 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 337 | instance fps :: (ring_1) ring_1 | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 338 | by (intro_classes, auto simp add: distrib_right) | 
| 29687 | 339 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 340 | instance fps :: (comm_ring_1) comm_ring_1 | 
| 54230 
b1d955791529
more simplification rules on unary and binary minus
 haftmann parents: 
53374diff
changeset | 341 | by (intro_classes, auto simp add: distrib_right) | 
| 29687 | 342 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 343 | instance fps :: (ring_no_zero_divisors) ring_no_zero_divisors | 
| 29687 | 344 | proof | 
| 345 | fix a b :: "'a fps" | |
| 346 | assume a0: "a \<noteq> 0" and b0: "b \<noteq> 0" | |
| 54681 | 347 | 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" | 
| 348 | unfolding fps_nonzero_nth_minimal | |
| 29687 | 349 | by blast+ | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 350 | have "(a * b) $ (i+j) = (\<Sum>k=0..i+j. a$k * b$(i+j-k))" | 
| 29687 | 351 | by (rule fps_mult_nth) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 352 |   also have "\<dots> = (a$i * b$(i+j-i)) + (\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k))"
 | 
| 57418 | 353 | by (rule setsum.remove) simp_all | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 354 |   also have "(\<Sum>k\<in>{0..i+j}-{i}. a$k * b$(i+j-k)) = 0"
 | 
| 57418 | 355 | proof (rule setsum.neutral [rule_format]) | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 356 |       fix k assume "k \<in> {0..i+j} - {i}"
 | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 357 | then have "k < i \<or> i+j-k < j" by auto | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 358 | then show "a$k * b$(i+j-k) = 0" using i j by auto | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 359 | qed | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 360 | also have "a$i * b$(i+j-i) + 0 = a$i * b$j" by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 361 | also have "a$i * b$j \<noteq> 0" using i j by simp | 
| 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 362 | finally have "(a*b) $ (i+j) \<noteq> 0" . | 
| 29687 | 363 | then show "a*b \<noteq> 0" unfolding fps_nonzero_nth by blast | 
| 364 | qed | |
| 365 | ||
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 366 | 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 | 367 | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 368 | instance fps :: (idom) idom .. | 
| 29687 | 369 | |
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 370 | lemma numeral_fps_const: "numeral k = fps_const (numeral k)" | 
| 48757 | 371 | 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 | 372 | fps_const_add [symmetric]) | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 373 | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 374 | lemma neg_numeral_fps_const: "- numeral k = fps_const (- numeral k)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 375 | by (simp only: numeral_fps_const fps_const_neg) | 
| 47108 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 376 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 377 | subsection{* The eXtractor series X*}
 | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 378 | |
| 54681 | 379 | lemma minus_one_power_iff: "(- (1::'a::comm_ring_1)) ^ n = (if even n then 1 else - 1)" | 
| 48757 | 380 | by (induct n) auto | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 381 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 382 | definition "X = Abs_fps (\<lambda>n. if n = 1 then 1 else 0)" | 
| 53195 | 383 | |
| 384 | lemma X_mult_nth [simp]: | |
| 54681 | 385 | "(X * (f :: 'a::semiring_1 fps)) $n = (if n = 0 then 0 else f $ (n - 1))" | 
| 53195 | 386 | proof (cases "n = 0") | 
| 387 | case False | |
| 388 | have "(X * f) $n = (\<Sum>i = 0..n. X $ i * f $ (n - i))" | |
| 389 | by (simp add: fps_mult_nth) | |
| 390 | also have "\<dots> = f $ (n - 1)" | |
| 57418 | 391 | using False by (simp add: X_def mult_delta_left setsum.delta) | 
| 53195 | 392 | finally show ?thesis using False by simp | 
| 393 | next | |
| 394 | case True | |
| 395 | then show ?thesis 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 | 396 | qed | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 397 | |
| 48757 | 398 | lemma X_mult_right_nth[simp]: | 
| 54681 | 399 | "((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 | 400 | by (metis X_mult_nth mult.commute) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 401 | |
| 54681 | 402 | lemma X_power_iff: "X^k = Abs_fps (\<lambda>n. if n = k then 1::'a::comm_ring_1 else 0)" | 
| 52902 | 403 | proof (induct k) | 
| 404 | case 0 | |
| 54452 | 405 | 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 | 406 | next | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 407 | case (Suc k) | 
| 52891 | 408 |   {
 | 
| 409 | fix m | |
| 54681 | 410 | have "(X^Suc k) $ m = (if m = 0 then 0::'a else (X^k) $ (m - 1))" | 
| 52891 | 411 | by (simp del: One_nat_def) | 
| 54681 | 412 | then have "(X^Suc k) $ m = (if m = Suc k then 1::'a else 0)" | 
| 52891 | 413 | using Suc.hyps by (auto cong del: if_weak_cong) | 
| 414 | } | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 415 | then show ?case by (simp add: fps_eq_iff) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 416 | qed | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 417 | |
| 48757 | 418 | lemma X_power_mult_nth: | 
| 54681 | 419 | "(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 | 420 | apply (induct k arbitrary: n) | 
| 52891 | 421 | apply simp | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 422 | unfolding power_Suc mult.assoc | 
| 48757 | 423 | apply (case_tac n) | 
| 424 | apply auto | |
| 425 | done | |
| 426 | ||
| 427 | lemma X_power_mult_right_nth: | |
| 54681 | 428 | "((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 | 429 | 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 | 430 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 431 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 432 | subsection{* Formal Power series form a metric space *}
 | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 433 | |
| 52902 | 434 | definition (in dist) "ball x r = {y. dist y x < r}"
 | 
| 48757 | 435 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 436 | instantiation fps :: (comm_ring_1) dist | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 437 | begin | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 438 | |
| 52891 | 439 | definition | 
| 54681 | 440 | dist_fps_def: "dist (a :: 'a fps) b = | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 441 | (if (\<exists>n. a$n \<noteq> b$n) then inverse (2 ^ (LEAST n. a$n \<noteq> b$n)) else 0)" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 442 | |
| 54681 | 443 | 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 | 444 | by (simp add: dist_fps_def) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 445 | |
| 54681 | 446 | lemma dist_fps_sym: "dist (a :: 'a fps) b = dist b a" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 447 | apply (auto simp add: dist_fps_def) | 
| 54681 | 448 | apply (rule cong[OF refl, where x="(\<lambda>n. a $ n \<noteq> b $ n)"]) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 449 | apply (rule ext) | 
| 48757 | 450 | apply auto | 
| 451 | done | |
| 452 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 453 | instance .. | 
| 48757 | 454 | |
| 30746 | 455 | end | 
| 456 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 457 | instantiation fps :: (comm_ring_1) metric_space | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 458 | begin | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 459 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 460 | definition open_fps_def: "open (S :: 'a fps set) = (\<forall>a \<in> S. \<exists>r. r >0 \<and> ball a r \<subseteq> S)" | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 461 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 462 | instance | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 463 | proof | 
| 52891 | 464 | fix S :: "'a fps set" | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 465 | show "open S = (\<forall>x\<in>S. \<exists>e>0. \<forall>y. dist y x < e \<longrightarrow> y \<in> S)" | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 466 | by (auto simp add: open_fps_def ball_def subset_eq) | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 467 | next | 
| 48757 | 468 |   {
 | 
| 469 | fix a b :: "'a fps" | |
| 470 |     {
 | |
| 52891 | 471 | assume "a = b" | 
| 472 | then have "\<not> (\<exists>n. a $ n \<noteq> b $ n)" by simp | |
| 48757 | 473 | then have "dist a b = 0" by (simp add: dist_fps_def) | 
| 474 | } | |
| 475 | moreover | |
| 476 |     {
 | |
| 477 | assume d: "dist a b = 0" | |
| 52891 | 478 | then have "\<forall>n. a$n = b$n" | 
| 48757 | 479 | by - (rule ccontr, simp add: dist_fps_def) | 
| 480 | then have "a = b" by (simp add: fps_eq_iff) | |
| 481 | } | |
| 482 | ultimately show "dist a b =0 \<longleftrightarrow> a = b" by blast | |
| 483 | } | |
| 484 | note th = this | |
| 485 | from th have th'[simp]: "\<And>a::'a fps. dist a a = 0" by simp | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 486 | fix a b c :: "'a fps" | 
| 48757 | 487 |   {
 | 
| 52891 | 488 | assume "a = b" | 
| 489 | then have "dist a b = 0" unfolding th . | |
| 490 | then have "dist a b \<le> dist a c + dist b c" | |
| 491 | using dist_fps_ge0 [of a c] dist_fps_ge0 [of b c] by simp | |
| 48757 | 492 | } | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 493 | moreover | 
| 48757 | 494 |   {
 | 
| 52891 | 495 | assume "c = a \<or> c = b" | 
| 48757 | 496 | then have "dist a b \<le> dist a c + dist b c" | 
| 52891 | 497 | by (cases "c = a") (simp_all add: th dist_fps_sym) | 
| 48757 | 498 | } | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 499 | moreover | 
| 52891 | 500 |   {
 | 
| 501 | assume ab: "a \<noteq> b" and ac: "a \<noteq> c" and bc: "b \<noteq> c" | |
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 502 | def n \<equiv> "\<lambda>a b::'a fps. LEAST n. a$n \<noteq> b$n" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 503 | then have n': "\<And>m a b. m < n a b \<Longrightarrow> a$m = b$m" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 504 | by (auto dest: not_less_Least) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 505 | |
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 506 | from ab ac bc | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 507 | have dab: "dist a b = inverse (2 ^ n a b)" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 508 | and dac: "dist a c = inverse (2 ^ n a c)" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 509 | and dbc: "dist b c = inverse (2 ^ n b c)" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 510 | by (simp_all add: dist_fps_def n_def fps_eq_iff) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 511 | from ab ac bc have nz: "dist a b \<noteq> 0" "dist a c \<noteq> 0" "dist b c \<noteq> 0" | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 512 | unfolding th by simp_all | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 513 | from nz have pos: "dist a b > 0" "dist a c > 0" "dist b c > 0" | 
| 52891 | 514 | using dist_fps_ge0[of a b] dist_fps_ge0[of a c] dist_fps_ge0[of b c] | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 515 | by auto | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 516 | have th1: "\<And>n. (2::real)^n >0" by auto | 
| 52891 | 517 |     {
 | 
| 518 | assume h: "dist a b > dist a c + dist b c" | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 519 | then have gt: "dist a b > dist a c" "dist a b > dist b c" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 520 | using pos by auto | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 521 | from gt have gtn: "n a b < n b c" "n a b < n a c" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 522 | unfolding dab dbc dac by (auto simp add: th1) | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 523 | from n'[OF gtn(2)] n'(1)[OF gtn(1)] | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 524 | have "a $ n a b = b $ n a b" by simp | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 525 | moreover have "a $ n a b \<noteq> b $ n a b" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 526 | unfolding n_def by (rule LeastI_ex) (insert ab, simp add: fps_eq_iff) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 527 | ultimately have False by contradiction | 
| 52891 | 528 | } | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 529 | then have "dist a b \<le> dist a c + dist b c" | 
| 52891 | 530 | by (auto simp add: not_le[symmetric]) | 
| 531 | } | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 532 | ultimately show "dist a b \<le> dist a c + dist b c" by blast | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 533 | qed | 
| 52891 | 534 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 535 | end | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 536 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 537 | text{* The infinite sums and justification of the notation in textbooks*}
 | 
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 538 | |
| 52891 | 539 | lemma reals_power_lt_ex: | 
| 54681 | 540 | fixes x y :: real | 
| 541 | assumes xp: "x > 0" | |
| 542 | and y1: "y > 1" | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 543 | shows "\<exists>k>0. (1/y)^k < x" | 
| 52891 | 544 | proof - | 
| 54681 | 545 | have yp: "y > 0" | 
| 546 | using y1 by simp | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 547 | from reals_Archimedean2[of "max 0 (- log y x) + 1"] | 
| 54681 | 548 | obtain k :: nat where k: "real k > max 0 (- log y x) + 1" | 
| 549 | by blast | |
| 550 | from k have kp: "k > 0" | |
| 551 | by simp | |
| 552 | from k have "real k > - log y x" | |
| 553 | by simp | |
| 554 | then have "ln y * real k > - ln x" | |
| 555 | unfolding log_def | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 556 | using ln_gt_zero_iff[OF yp] y1 | 
| 54681 | 557 | by (simp add: minus_divide_left field_simps del: minus_divide_left[symmetric]) | 
| 558 | then have "ln y * real k + ln x > 0" | |
| 559 | by simp | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 560 | 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 | 561 | by (simp add: ac_simps) | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 562 | then have "y ^ k * x > 1" | 
| 52891 | 563 | unfolding exp_zero exp_add exp_real_of_nat_mult exp_ln [OF xp] exp_ln [OF yp] | 
| 564 | by simp | |
| 565 | then have "x > (1 / y)^k" using yp | |
| 36350 | 566 | by (simp add: field_simps nonzero_power_divide) | 
| 54681 | 567 | then show ?thesis | 
| 568 | using kp by blast | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 569 | qed | 
| 52891 | 570 | |
| 54681 | 571 | lemma X_nth[simp]: "X$n = (if n = 1 then 1 else 0)" | 
| 572 | by (simp add: X_def) | |
| 573 | ||
| 574 | lemma X_power_nth[simp]: "(X^k) $n = (if n = k then 1 else 0::'a::comm_ring_1)" | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 575 | by (simp add: X_power_iff) | 
| 52891 | 576 | |
| 54452 | 577 | lemma fps_sum_rep_nth: "(setsum (\<lambda>i. fps_const(a$i)*X^i) {0..m})$n =
 | 
| 54681 | 578 | (if n \<le> m then a$n else 0::'a::comm_ring_1)" | 
| 52891 | 579 | apply (auto simp add: fps_setsum_nth cond_value_iff cong del: if_weak_cong) | 
| 57418 | 580 | apply (simp add: setsum.delta') | 
| 48757 | 581 | done | 
| 52891 | 582 | |
| 54452 | 583 | lemma fps_notation: "(\<lambda>n. setsum (\<lambda>i. fps_const(a$i) * X^i) {0..n}) ----> a"
 | 
| 52902 | 584 | (is "?s ----> a") | 
| 52891 | 585 | proof - | 
| 586 |   {
 | |
| 54681 | 587 | fix r :: real | 
| 52891 | 588 | assume rp: "r > 0" | 
| 589 | have th0: "(2::real) > 1" by simp | |
| 590 | from reals_power_lt_ex[OF rp th0] | |
| 591 | obtain n0 where n0: "(1/2)^n0 < r" "n0 > 0" by blast | |
| 592 |     {
 | |
| 54681 | 593 | fix n :: nat | 
| 52891 | 594 | assume nn0: "n \<ge> n0" | 
| 54452 | 595 | then have thnn0: "(1/2)^n \<le> (1/2 :: real)^n0" | 
| 52891 | 596 | by (auto intro: power_decreasing) | 
| 597 |       {
 | |
| 598 | assume "?s n = a" | |
| 599 | then have "dist (?s n) a < r" | |
| 600 | unfolding dist_eq_0_iff[of "?s n" a, symmetric] | |
| 601 | using rp by (simp del: dist_eq_0_iff) | |
| 602 | } | |
| 603 | moreover | |
| 604 |       {
 | |
| 605 | assume neq: "?s n \<noteq> a" | |
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 606 | def k \<equiv> "LEAST i. ?s n $ i \<noteq> a $ i" | 
| 52891 | 607 | from neq have dth: "dist (?s n) a = (1/2)^k" | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 608 | by (auto simp add: dist_fps_def inverse_eq_divide power_divide k_def fps_eq_iff) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 609 | |
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 610 | from neq have kn: "k > n" | 
| 54681 | 611 | by (auto simp: fps_sum_rep_nth not_le k_def fps_eq_iff | 
| 612 | split: split_if_asm intro: LeastI2_ex) | |
| 613 | then have "dist (?s n) a < (1/2)^n" | |
| 614 | unfolding dth by (auto intro: power_strict_decreasing) | |
| 615 | also have "\<dots> \<le> (1/2)^n0" | |
| 616 | using nn0 by (auto intro: power_decreasing) | |
| 617 | also have "\<dots> < r" | |
| 618 | using n0 by simp | |
| 52891 | 619 | finally have "dist (?s n) a < r" . | 
| 620 | } | |
| 54681 | 621 | ultimately have "dist (?s n) a < r" | 
| 622 | by blast | |
| 52891 | 623 | } | 
| 54681 | 624 | then have "\<exists>n0. \<forall> n \<ge> n0. dist (?s n) a < r" | 
| 625 | by blast | |
| 52891 | 626 | } | 
| 54681 | 627 | then show ?thesis | 
| 628 | unfolding LIMSEQ_def by blast | |
| 52891 | 629 | qed | 
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 630 | |
| 54681 | 631 | |
| 29906 | 632 | subsection{* Inverses of formal power series *}
 | 
| 29687 | 633 | |
| 57418 | 634 | declare setsum.cong[fundef_cong] | 
| 29687 | 635 | |
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 636 | instantiation fps :: ("{comm_monoid_add, inverse, times, uminus}") inverse
 | 
| 29687 | 637 | begin | 
| 638 | ||
| 52891 | 639 | fun natfun_inverse:: "'a fps \<Rightarrow> nat \<Rightarrow> 'a" | 
| 640 | where | |
| 29687 | 641 | "natfun_inverse f 0 = inverse (f$0)" | 
| 30488 | 642 | | "natfun_inverse f n = - inverse (f$0) * setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}"
 | 
| 29687 | 643 | |
| 52891 | 644 | definition | 
| 645 | fps_inverse_def: "inverse f = (if f $ 0 = 0 then 0 else Abs_fps (natfun_inverse f))" | |
| 646 | ||
| 647 | definition | |
| 648 | fps_divide_def: "divide = (\<lambda>(f::'a fps) g. f * inverse g)" | |
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 649 | |
| 29687 | 650 | instance .. | 
| 36311 
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
 haftmann parents: 
36309diff
changeset | 651 | |
| 29687 | 652 | end | 
| 653 | ||
| 52891 | 654 | lemma fps_inverse_zero [simp]: | 
| 54681 | 655 |   "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 | 656 | by (simp add: fps_ext fps_inverse_def) | 
| 29687 | 657 | |
| 52891 | 658 | 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 | 659 | apply (auto simp add: expand_fps_eq fps_inverse_def) | 
| 52891 | 660 | apply (case_tac n) | 
| 661 | apply auto | |
| 662 | done | |
| 663 | ||
| 664 | lemma inverse_mult_eq_1 [intro]: | |
| 665 | assumes f0: "f$0 \<noteq> (0::'a::field)" | |
| 29687 | 666 | shows "inverse f * f = 1" | 
| 52891 | 667 | proof - | 
| 54681 | 668 | 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 | 669 | by (simp add: mult.commute) | 
| 30488 | 670 | from f0 have ifn: "\<And>n. inverse f $ n = natfun_inverse f n" | 
| 29687 | 671 | by (simp add: fps_inverse_def) | 
| 672 | 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 | 673 | by (simp add: fps_mult_nth fps_inverse_def) | 
| 52891 | 674 |   {
 | 
| 675 | fix n :: nat | |
| 676 | assume np: "n > 0" | |
| 54681 | 677 |     from np have eq: "{0..n} = {0} \<union> {1 .. n}"
 | 
| 678 | by auto | |
| 679 |     have d: "{0} \<inter> {1 .. n} = {}"
 | |
| 680 | by auto | |
| 52891 | 681 | from f0 np have th0: "- (inverse f $ n) = | 
| 29687 | 682 |       (setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n}) / (f$0)"
 | 
| 52891 | 683 | by (cases n) (simp_all add: divide_inverse fps_inverse_def) | 
| 29687 | 684 | from th0[symmetric, unfolded nonzero_divide_eq_eq[OF f0]] | 
| 52891 | 685 |     have th1: "setsum (\<lambda>i. f$i * natfun_inverse f (n - i)) {1..n} = - (f$0) * (inverse f)$n"
 | 
| 36350 | 686 | by (simp add: field_simps) | 
| 30488 | 687 | have "(f * inverse f) $ n = (\<Sum>i = 0..n. f $i * natfun_inverse f (n - i))" | 
| 29687 | 688 | unfolding fps_mult_nth ifn .. | 
| 52891 | 689 | also have "\<dots> = f$0 * natfun_inverse f n + (\<Sum>i = 1..n. f$i * natfun_inverse f (n-i))" | 
| 46757 | 690 | by (simp add: eq) | 
| 54681 | 691 | also have "\<dots> = 0" | 
| 692 | unfolding th1 ifn by simp | |
| 693 | finally have "(inverse f * f)$n = 0" | |
| 694 | unfolding c . | |
| 52891 | 695 | } | 
| 54681 | 696 | with th0 show ?thesis | 
| 697 | by (simp add: fps_eq_iff) | |
| 29687 | 698 | qed | 
| 699 | ||
| 700 | 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 | 701 | by (simp add: fps_inverse_def nonzero_imp_inverse_nonzero) | 
| 29687 | 702 | |
| 703 | lemma fps_inverse_eq_0_iff[simp]: "inverse f = (0:: ('a::field) fps) \<longleftrightarrow> f $0 = 0"
 | |
| 52891 | 704 | proof - | 
| 705 |   {
 | |
| 54681 | 706 | assume "f $ 0 = 0" | 
| 707 | then have "inverse f = 0" | |
| 708 | by (simp add: fps_inverse_def) | |
| 52891 | 709 | } | 
| 29687 | 710 | moreover | 
| 52891 | 711 |   {
 | 
| 54681 | 712 | assume h: "inverse f = 0" | 
| 713 | assume c: "f $0 \<noteq> 0" | |
| 714 | from inverse_mult_eq_1[OF c] h have False | |
| 715 | by simp | |
| 52891 | 716 | } | 
| 29687 | 717 | ultimately show ?thesis by blast | 
| 718 | qed | |
| 719 | ||
| 48757 | 720 | lemma fps_inverse_idempotent[intro]: | 
| 721 | assumes f0: "f$0 \<noteq> (0::'a::field)" | |
| 29687 | 722 | shows "inverse (inverse f) = f" | 
| 52891 | 723 | proof - | 
| 29687 | 724 | from f0 have if0: "inverse f $ 0 \<noteq> 0" by simp | 
| 30488 | 725 | from inverse_mult_eq_1[OF f0] inverse_mult_eq_1[OF if0] | 
| 52891 | 726 | 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 | 727 | by (simp add: ac_simps) | 
| 54681 | 728 | then show ?thesis | 
| 729 | using f0 unfolding mult_cancel_left by simp | |
| 29687 | 730 | qed | 
| 731 | ||
| 48757 | 732 | lemma fps_inverse_unique: | 
| 52902 | 733 | assumes f0: "f$0 \<noteq> (0::'a::field)" | 
| 734 | and fg: "f*g = 1" | |
| 29687 | 735 | shows "inverse f = g" | 
| 52891 | 736 | proof - | 
| 29687 | 737 | from inverse_mult_eq_1[OF f0] fg | 
| 54681 | 738 | 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 | 739 | by (simp add: ac_simps) | 
| 54681 | 740 | then show ?thesis | 
| 741 | using f0 | |
| 742 | unfolding mult_cancel_right | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 743 | by (auto simp add: expand_fps_eq) | 
| 29687 | 744 | qed | 
| 745 | ||
| 30488 | 746 | lemma fps_inverse_gp: "inverse (Abs_fps(\<lambda>n. (1::'a::field))) | 
| 52902 | 747 | = Abs_fps (\<lambda>n. if n= 0 then 1 else if n=1 then - 1 else 0)" | 
| 29687 | 748 | apply (rule fps_inverse_unique) | 
| 749 | apply simp | |
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 750 | apply (simp add: fps_eq_iff fps_mult_nth) | 
| 54681 | 751 | apply clarsimp | 
| 752 | proof - | |
| 52891 | 753 | fix n :: nat | 
| 754 | assume n: "n > 0" | |
| 54681 | 755 | let ?f = "\<lambda>i. if n = i then (1::'a) else if n - i = 1 then - 1 else 0" | 
| 29687 | 756 | let ?g = "\<lambda>i. if i = n then 1 else if i=n - 1 then - 1 else 0" | 
| 757 | let ?h = "\<lambda>i. if i=n - 1 then - 1 else 0" | |
| 30488 | 758 |   have th1: "setsum ?f {0..n} = setsum ?g {0..n}"
 | 
| 57418 | 759 | by (rule setsum.cong) auto | 
| 30488 | 760 |   have th2: "setsum ?g {0..n - 1} = setsum ?h {0..n - 1}"
 | 
| 54681 | 761 | apply (insert n) | 
| 57418 | 762 | apply (rule setsum.cong) | 
| 54681 | 763 | apply auto | 
| 764 | done | |
| 765 |   have eq: "{0 .. n} = {0.. n - 1} \<union> {n}"
 | |
| 766 | by auto | |
| 767 |   from n have d: "{0.. n - 1} \<inter> {n} = {}"
 | |
| 768 | by auto | |
| 769 |   have f: "finite {0.. n - 1}" "finite {n}"
 | |
| 770 | by auto | |
| 29687 | 771 |   show "setsum ?f {0..n} = 0"
 | 
| 30488 | 772 | unfolding th1 | 
| 57418 | 773 | apply (simp add: setsum.union_disjoint[OF f d, unfolded eq[symmetric]] del: One_nat_def) | 
| 29687 | 774 | unfolding th2 | 
| 57418 | 775 | apply (simp add: setsum.delta) | 
| 52891 | 776 | done | 
| 29687 | 777 | qed | 
| 778 | ||
| 54681 | 779 | |
| 780 | subsection {* Formal Derivatives, and the MacLaurin theorem around 0 *}
 | |
| 29687 | 781 | |
| 782 | definition "fps_deriv f = Abs_fps (\<lambda>n. of_nat (n + 1) * f $ (n + 1))" | |
| 783 | ||
| 54681 | 784 | lemma fps_deriv_nth[simp]: "fps_deriv f $ n = of_nat (n +1) * f $ (n + 1)" | 
| 48757 | 785 | by (simp add: fps_deriv_def) | 
| 786 | ||
| 787 | lemma fps_deriv_linear[simp]: | |
| 788 | "fps_deriv (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = | |
| 789 | fps_const a * fps_deriv f + fps_const b * fps_deriv g" | |
| 36350 | 790 | unfolding fps_eq_iff fps_add_nth fps_const_mult_left fps_deriv_nth by (simp add: field_simps) | 
| 29687 | 791 | |
| 30488 | 792 | lemma fps_deriv_mult[simp]: | 
| 54681 | 793 | fixes f :: "'a::comm_ring_1 fps" | 
| 29687 | 794 | shows "fps_deriv (f * g) = f * fps_deriv g + fps_deriv f * g" | 
| 52891 | 795 | proof - | 
| 29687 | 796 | let ?D = "fps_deriv" | 
| 54681 | 797 |   {
 | 
| 798 | fix n :: nat | |
| 29687 | 799 |     let ?Zn = "{0 ..n}"
 | 
| 800 |     let ?Zn1 = "{0 .. n + 1}"
 | |
| 801 | let ?g = "\<lambda>i. of_nat (i+1) * g $ (i+1) * f $ (n - i) + | |
| 802 | of_nat (i+1)* f $ (i+1) * g $ (n - i)" | |
| 803 | let ?h = "\<lambda>i. of_nat i * g $ i * f $ ((n+1) - i) + | |
| 804 | of_nat i* f $ i * g $ ((n + 1) - i)" | |
| 52891 | 805 | have s0: "setsum (\<lambda>i. of_nat i * f $ i * g $ (n + 1 - i)) ?Zn1 = | 
| 806 | 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 | 807 | by (rule setsum.reindex_bij_witness[where i="op - (n + 1)" and j="op - (n + 1)"]) auto | 
| 52891 | 808 | have s1: "setsum (\<lambda>i. f $ i * g $ (n + 1 - i)) ?Zn1 = | 
| 809 | setsum (\<lambda>i. f $ (n + 1 - i) * g $ i) ?Zn1" | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 810 | by (rule setsum.reindex_bij_witness[where i="op - (n + 1)" and j="op - (n + 1)"]) auto | 
| 52891 | 811 | 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 | 812 | by (simp only: mult.commute) | 
| 29687 | 813 | also have "\<dots> = (\<Sum>i = 0..n. ?g i)" | 
| 57418 | 814 | by (simp add: fps_mult_nth setsum.distrib[symmetric]) | 
| 29687 | 815 |     also have "\<dots> = setsum ?h {0..n+1}"
 | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 816 | by (rule setsum.reindex_bij_witness_not_neutral | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 817 |             [where S'="{}" and T'="{0}" and j="Suc" and i="\<lambda>i. i - 1"]) auto
 | 
| 29687 | 818 | also have "\<dots> = (fps_deriv (f * g)) $ n" | 
| 57418 | 819 | apply (simp only: fps_deriv_nth fps_mult_nth setsum.distrib) | 
| 29687 | 820 | unfolding s0 s1 | 
| 57418 | 821 | unfolding setsum.distrib[symmetric] setsum_right_distrib | 
| 822 | apply (rule setsum.cong) | |
| 52891 | 823 | apply (auto simp add: of_nat_diff field_simps) | 
| 824 | done | |
| 825 | finally have "(f * ?D g + ?D f * g) $ n = ?D (f*g) $ n" . | |
| 826 | } | |
| 30488 | 827 | then show ?thesis unfolding fps_eq_iff by auto | 
| 29687 | 828 | qed | 
| 829 | ||
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 830 | 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 | 831 | 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 | 832 | |
| 54681 | 833 | lemma fps_deriv_neg[simp]: | 
| 834 | "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 | 835 | by (simp add: fps_eq_iff fps_deriv_def) | 
| 52891 | 836 | |
| 54681 | 837 | lemma fps_deriv_add[simp]: | 
| 838 | "fps_deriv ((f:: 'a::comm_ring_1 fps) + g) = fps_deriv f + fps_deriv g" | |
| 29687 | 839 | using fps_deriv_linear[of 1 f 1 g] by simp | 
| 840 | ||
| 54681 | 841 | lemma fps_deriv_sub[simp]: | 
| 842 | "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 | 843 | using fps_deriv_add [of f "- g"] by simp | 
| 29687 | 844 | |
| 845 | 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 | 846 | by (simp add: fps_ext fps_deriv_def fps_const_def) | 
| 29687 | 847 | |
| 48757 | 848 | lemma fps_deriv_mult_const_left[simp]: | 
| 54681 | 849 | "fps_deriv (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_deriv f" | 
| 29687 | 850 | by simp | 
| 851 | ||
| 852 | lemma fps_deriv_0[simp]: "fps_deriv 0 = 0" | |
| 853 | by (simp add: fps_deriv_def fps_eq_iff) | |
| 854 | ||
| 855 | lemma fps_deriv_1[simp]: "fps_deriv 1 = 0" | |
| 856 | by (simp add: fps_deriv_def fps_eq_iff ) | |
| 857 | ||
| 48757 | 858 | lemma fps_deriv_mult_const_right[simp]: | 
| 54681 | 859 | "fps_deriv (f * fps_const (c::'a::comm_ring_1)) = fps_deriv f * fps_const c" | 
| 29687 | 860 | by simp | 
| 861 | ||
| 48757 | 862 | lemma fps_deriv_setsum: | 
| 54681 | 863 | "fps_deriv (setsum f S) = setsum (\<lambda>i. fps_deriv (f i :: 'a::comm_ring_1 fps)) S" | 
| 53195 | 864 | proof (cases "finite S") | 
| 865 | case False | |
| 866 | then show ?thesis by simp | |
| 867 | next | |
| 868 | case True | |
| 869 | show ?thesis by (induct rule: finite_induct [OF True]) simp_all | |
| 29687 | 870 | qed | 
| 871 | ||
| 52902 | 872 | lemma fps_deriv_eq_0_iff [simp]: | 
| 54681 | 873 |   "fps_deriv f = 0 \<longleftrightarrow> f = fps_const (f$0 :: 'a::{idom,semiring_char_0})"
 | 
| 52902 | 874 | proof - | 
| 52891 | 875 |   {
 | 
| 876 | assume "f = fps_const (f$0)" | |
| 877 | then have "fps_deriv f = fps_deriv (fps_const (f$0))" by simp | |
| 878 | then have "fps_deriv f = 0" by simp | |
| 879 | } | |
| 29687 | 880 | moreover | 
| 52891 | 881 |   {
 | 
| 882 | assume z: "fps_deriv f = 0" | |
| 883 | then have "\<forall>n. (fps_deriv f)$n = 0" by simp | |
| 884 | then have "\<forall>n. f$(n+1) = 0" by (simp del: of_nat_Suc of_nat_add One_nat_def) | |
| 885 | then have "f = fps_const (f$0)" | |
| 29687 | 886 | apply (clarsimp simp add: fps_eq_iff fps_const_def) | 
| 887 | apply (erule_tac x="n - 1" in allE) | |
| 52891 | 888 | apply simp | 
| 889 | done | |
| 890 | } | |
| 29687 | 891 | ultimately show ?thesis by blast | 
| 892 | qed | |
| 893 | ||
| 30488 | 894 | lemma fps_deriv_eq_iff: | 
| 54681 | 895 |   fixes f :: "'a::{idom,semiring_char_0} fps"
 | 
| 29687 | 896 | shows "fps_deriv f = fps_deriv g \<longleftrightarrow> (f = fps_const(f$0 - g$0) + g)" | 
| 52891 | 897 | proof - | 
| 52903 | 898 | have "fps_deriv f = fps_deriv g \<longleftrightarrow> fps_deriv (f - g) = 0" | 
| 899 | by simp | |
| 54681 | 900 | also have "\<dots> \<longleftrightarrow> f - g = fps_const ((f - g) $ 0)" | 
| 52903 | 901 | unfolding fps_deriv_eq_0_iff .. | 
| 36350 | 902 | finally show ?thesis by (simp add: field_simps) | 
| 29687 | 903 | qed | 
| 904 | ||
| 48757 | 905 | lemma fps_deriv_eq_iff_ex: | 
| 54681 | 906 |   "(fps_deriv f = fps_deriv g) \<longleftrightarrow> (\<exists>c::'a::{idom,semiring_char_0}. f = fps_const c + g)"
 | 
| 53195 | 907 | by (auto simp: fps_deriv_eq_iff) | 
| 48757 | 908 | |
| 909 | ||
| 54681 | 910 | fun fps_nth_deriv :: "nat \<Rightarrow> 'a::semiring_1 fps \<Rightarrow> 'a fps" | 
| 48757 | 911 | where | 
| 29687 | 912 | "fps_nth_deriv 0 f = f" | 
| 913 | | "fps_nth_deriv (Suc n) f = fps_nth_deriv n (fps_deriv f)" | |
| 914 | ||
| 915 | lemma fps_nth_deriv_commute: "fps_nth_deriv (Suc n) f = fps_deriv (fps_nth_deriv n f)" | |
| 48757 | 916 | by (induct n arbitrary: f) auto | 
| 917 | ||
| 918 | lemma fps_nth_deriv_linear[simp]: | |
| 919 | "fps_nth_deriv n (fps_const (a::'a::comm_semiring_1) * f + fps_const b * g) = | |
| 920 | fps_const a * fps_nth_deriv n f + fps_const b * fps_nth_deriv n g" | |
| 921 | by (induct n arbitrary: f g) (auto simp add: fps_nth_deriv_commute) | |
| 922 | ||
| 923 | lemma fps_nth_deriv_neg[simp]: | |
| 54681 | 924 | "fps_nth_deriv n (- (f :: 'a::comm_ring_1 fps)) = - (fps_nth_deriv n f)" | 
| 48757 | 925 | by (induct n arbitrary: f) simp_all | 
| 926 | ||
| 927 | lemma fps_nth_deriv_add[simp]: | |
| 54681 | 928 | "fps_nth_deriv n ((f :: 'a::comm_ring_1 fps) + g) = fps_nth_deriv n f + fps_nth_deriv n g" | 
| 29687 | 929 | using fps_nth_deriv_linear[of n 1 f 1 g] by simp | 
| 930 | ||
| 48757 | 931 | lemma fps_nth_deriv_sub[simp]: | 
| 54681 | 932 | "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 | 933 | using fps_nth_deriv_add [of n f "- g"] by simp | 
| 29687 | 934 | |
| 935 | lemma fps_nth_deriv_0[simp]: "fps_nth_deriv n 0 = 0" | |
| 48757 | 936 | by (induct n) simp_all | 
| 29687 | 937 | |
| 938 | lemma fps_nth_deriv_1[simp]: "fps_nth_deriv n 1 = (if n = 0 then 1 else 0)" | |
| 48757 | 939 | by (induct n) simp_all | 
| 940 | ||
| 941 | lemma fps_nth_deriv_const[simp]: | |
| 942 | "fps_nth_deriv n (fps_const c) = (if n = 0 then fps_const c else 0)" | |
| 943 | by (cases n) simp_all | |
| 944 | ||
| 945 | lemma fps_nth_deriv_mult_const_left[simp]: | |
| 946 | "fps_nth_deriv n (fps_const (c::'a::comm_ring_1) * f) = fps_const c * fps_nth_deriv n f" | |
| 29687 | 947 | using fps_nth_deriv_linear[of n "c" f 0 0 ] by simp | 
| 948 | ||
| 48757 | 949 | lemma fps_nth_deriv_mult_const_right[simp]: | 
| 950 | "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 | 951 | using fps_nth_deriv_linear[of n "c" f 0 0] by (simp add: mult.commute) | 
| 29687 | 952 | |
| 48757 | 953 | lemma fps_nth_deriv_setsum: | 
| 54681 | 954 | "fps_nth_deriv n (setsum f S) = setsum (\<lambda>i. fps_nth_deriv n (f i :: 'a::comm_ring_1 fps)) S" | 
| 52903 | 955 | proof (cases "finite S") | 
| 956 | case True | |
| 957 | show ?thesis by (induct rule: finite_induct [OF True]) simp_all | |
| 958 | next | |
| 959 | case False | |
| 960 | then show ?thesis by simp | |
| 29687 | 961 | qed | 
| 962 | ||
| 48757 | 963 | lemma fps_deriv_maclauren_0: | 
| 54681 | 964 | "(fps_nth_deriv k (f :: 'a::comm_semiring_1 fps)) $ 0 = of_nat (fact k) * f $ k" | 
| 36350 | 965 | by (induct k arbitrary: f) (auto simp add: field_simps of_nat_mult) | 
| 29687 | 966 | |
| 54681 | 967 | |
| 968 | subsection {* Powers *}
 | |
| 29687 | 969 | |
| 970 | lemma fps_power_zeroth_eq_one: "a$0 =1 \<Longrightarrow> a^n $ 0 = (1::'a::semiring_1)" | |
| 48757 | 971 | by (induct n) (auto simp add: expand_fps_eq fps_mult_nth) | 
| 29687 | 972 | |
| 54681 | 973 | lemma fps_power_first_eq: "(a :: 'a::comm_ring_1 fps) $ 0 =1 \<Longrightarrow> a^n $ 1 = of_nat n * a$1" | 
| 52891 | 974 | proof (induct n) | 
| 975 | case 0 | |
| 976 | then show ?case by simp | |
| 29687 | 977 | next | 
| 978 | case (Suc n) | |
| 979 | note h = Suc.hyps[OF `a$0 = 1`] | |
| 30488 | 980 | show ?case unfolding power_Suc fps_mult_nth | 
| 52891 | 981 | using h `a$0 = 1` fps_power_zeroth_eq_one[OF `a$0=1`] | 
| 982 | by (simp add: field_simps) | |
| 29687 | 983 | qed | 
| 984 | ||
| 985 | lemma startsby_one_power:"a $ 0 = (1::'a::comm_ring_1) \<Longrightarrow> a^n $ 0 = 1" | |
| 48757 | 986 | by (induct n) (auto simp add: fps_mult_nth) | 
| 29687 | 987 | |
| 988 | lemma startsby_zero_power:"a $0 = (0::'a::comm_ring_1) \<Longrightarrow> n > 0 \<Longrightarrow> a^n $0 = 0" | |
| 48757 | 989 | by (induct n) (auto simp add: fps_mult_nth) | 
| 29687 | 990 | |
| 54681 | 991 | lemma startsby_power:"a $0 = (v::'a::comm_ring_1) \<Longrightarrow> a^n $0 = v^n" | 
| 52891 | 992 | by (induct n) (auto simp add: fps_mult_nth) | 
| 993 | ||
| 54681 | 994 | lemma startsby_zero_power_iff[simp]: "a^n $0 = (0::'a::idom) \<longleftrightarrow> n \<noteq> 0 \<and> a$0 = 0" | 
| 52891 | 995 | apply (rule iffI) | 
| 996 | apply (induct n) | |
| 997 | apply (auto simp add: fps_mult_nth) | |
| 998 | apply (rule startsby_zero_power, simp_all) | |
| 999 | done | |
| 29687 | 1000 | |
| 30488 | 1001 | lemma startsby_zero_power_prefix: | 
| 29687 | 1002 | assumes a0: "a $0 = (0::'a::idom)" | 
| 1003 | shows "\<forall>n < k. a ^ k $ n = 0" | |
| 30488 | 1004 | using a0 | 
| 54681 | 1005 | proof (induct k rule: nat_less_induct) | 
| 52891 | 1006 | fix k | 
| 54681 | 1007 | assume H: "\<forall>m<k. a $0 = 0 \<longrightarrow> (\<forall>n<m. a ^ m $ n = 0)" and a0: "a $ 0 = 0" | 
| 29687 | 1008 | let ?ths = "\<forall>m<k. a ^ k $ m = 0" | 
| 54681 | 1009 |   {
 | 
| 1010 | assume "k = 0" | |
| 1011 | then have ?ths by simp | |
| 1012 | } | |
| 29687 | 1013 | moreover | 
| 52891 | 1014 |   {
 | 
| 1015 | fix l | |
| 1016 | assume k: "k = Suc l" | |
| 1017 |     {
 | |
| 1018 | fix m | |
| 1019 | assume mk: "m < k" | |
| 1020 |       {
 | |
| 1021 | assume "m = 0" | |
| 1022 | then have "a^k $ m = 0" | |
| 1023 | using startsby_zero_power[of a k] k a0 by simp | |
| 1024 | } | |
| 29687 | 1025 | moreover | 
| 52891 | 1026 |       {
 | 
| 1027 | assume m0: "m \<noteq> 0" | |
| 54681 | 1028 | have "a ^k $ m = (a^l * a) $m" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1029 | by (simp add: k mult.commute) | 
| 54681 | 1030 | also have "\<dots> = (\<Sum>i = 0..m. a ^ l $ i * a $ (m - i))" | 
| 1031 | by (simp add: fps_mult_nth) | |
| 52891 | 1032 | also have "\<dots> = 0" | 
| 57418 | 1033 | apply (rule setsum.neutral) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1034 | apply auto | 
| 51489 | 1035 | apply (case_tac "x = m") | 
| 52891 | 1036 | using a0 apply simp | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1037 | apply (rule H[rule_format]) | 
| 52891 | 1038 | using a0 k mk apply auto | 
| 1039 | done | |
| 1040 | finally have "a^k $ m = 0" . | |
| 1041 | } | |
| 54681 | 1042 | ultimately have "a^k $ m = 0" | 
| 1043 | by blast | |
| 52891 | 1044 | } | 
| 1045 | then have ?ths by blast | |
| 1046 | } | |
| 54681 | 1047 | ultimately show ?ths | 
| 1048 | by (cases k) auto | |
| 29687 | 1049 | qed | 
| 1050 | ||
| 30488 | 1051 | lemma startsby_zero_setsum_depends: | 
| 54681 | 1052 | assumes a0: "a $0 = (0::'a::idom)" | 
| 1053 | and kn: "n \<ge> k" | |
| 29687 | 1054 |   shows "setsum (\<lambda>i. (a ^ i)$k) {0 .. n} = setsum (\<lambda>i. (a ^ i)$k) {0 .. k}"
 | 
| 57418 | 1055 | apply (rule setsum.mono_neutral_right) | 
| 54681 | 1056 | using kn | 
| 1057 | apply auto | |
| 29687 | 1058 | apply (rule startsby_zero_power_prefix[rule_format, OF a0]) | 
| 52891 | 1059 | apply arith | 
| 1060 | done | |
| 1061 | ||
| 1062 | lemma startsby_zero_power_nth_same: | |
| 54681 | 1063 | assumes a0: "a$0 = (0::'a::idom)" | 
| 29687 | 1064 | shows "a^n $ n = (a$1) ^ n" | 
| 52891 | 1065 | proof (induct n) | 
| 1066 | case 0 | |
| 52902 | 1067 | then show ?case by simp | 
| 29687 | 1068 | next | 
| 1069 | case (Suc n) | |
| 54681 | 1070 | have "a ^ Suc n $ (Suc n) = (a^n * a)$(Suc n)" | 
| 1071 | by (simp add: field_simps) | |
| 52891 | 1072 |   also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {0.. Suc n}"
 | 
| 1073 | by (simp add: fps_mult_nth) | |
| 29687 | 1074 |   also have "\<dots> = setsum (\<lambda>i. a^n$i * a $ (Suc n - i)) {n .. Suc n}"
 | 
| 57418 | 1075 | apply (rule setsum.mono_neutral_right) | 
| 29687 | 1076 | apply simp | 
| 1077 | apply clarsimp | |
| 1078 | apply clarsimp | |
| 1079 | apply (rule startsby_zero_power_prefix[rule_format, OF a0]) | |
| 1080 | apply arith | |
| 1081 | done | |
| 54681 | 1082 | also have "\<dots> = a^n $ n * a$1" | 
| 1083 | using a0 by simp | |
| 1084 | finally show ?case | |
| 1085 | using Suc.hyps by simp | |
| 29687 | 1086 | qed | 
| 1087 | ||
| 1088 | lemma fps_inverse_power: | |
| 54681 | 1089 | fixes a :: "'a::field fps" | 
| 29687 | 1090 | shows "inverse (a^n) = inverse a ^ n" | 
| 52891 | 1091 | proof - | 
| 1092 |   {
 | |
| 1093 | assume a0: "a$0 = 0" | |
| 54681 | 1094 | then have eq: "inverse a = 0" | 
| 1095 | by (simp add: fps_inverse_def) | |
| 1096 |     {
 | |
| 1097 | assume "n = 0" | |
| 1098 | then have ?thesis by simp | |
| 1099 | } | |
| 29687 | 1100 | moreover | 
| 52891 | 1101 |     {
 | 
| 1102 | assume n: "n > 0" | |
| 30488 | 1103 | from startsby_zero_power[OF a0 n] eq a0 n have ?thesis | 
| 52891 | 1104 | by (simp add: fps_inverse_def) | 
| 1105 | } | |
| 1106 | ultimately have ?thesis by blast | |
| 1107 | } | |
| 29687 | 1108 | moreover | 
| 52891 | 1109 |   {
 | 
| 1110 | assume a0: "a$0 \<noteq> 0" | |
| 29687 | 1111 | have ?thesis | 
| 1112 | apply (rule fps_inverse_unique) | |
| 1113 | apply (simp add: a0) | |
| 1114 | unfolding power_mult_distrib[symmetric] | |
| 1115 | apply (rule ssubst[where t = "a * inverse a" and s= 1]) | |
| 1116 | apply simp_all | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1117 | apply (subst mult.commute) | 
| 52891 | 1118 | apply (rule inverse_mult_eq_1[OF a0]) | 
| 1119 | done | |
| 1120 | } | |
| 29687 | 1121 | ultimately show ?thesis by blast | 
| 1122 | qed | |
| 1123 | ||
| 48757 | 1124 | lemma fps_deriv_power: | 
| 54681 | 1125 | "fps_deriv (a ^ n) = fps_const (of_nat n :: 'a::comm_ring_1) * fps_deriv a * a ^ (n - 1)" | 
| 48757 | 1126 | apply (induct n) | 
| 52891 | 1127 | apply (auto simp add: field_simps fps_const_add[symmetric] simp del: fps_const_add) | 
| 48757 | 1128 | apply (case_tac n) | 
| 52891 | 1129 | apply (auto simp add: field_simps) | 
| 48757 | 1130 | done | 
| 29687 | 1131 | |
| 30488 | 1132 | lemma fps_inverse_deriv: | 
| 54681 | 1133 | fixes a :: "'a::field fps" | 
| 29687 | 1134 | assumes a0: "a$0 \<noteq> 0" | 
| 53077 | 1135 | shows "fps_deriv (inverse a) = - fps_deriv a * (inverse a)\<^sup>2" | 
| 54681 | 1136 | proof - | 
| 29687 | 1137 | from inverse_mult_eq_1[OF a0] | 
| 1138 | have "fps_deriv (inverse a * a) = 0" by simp | |
| 54452 | 1139 | then have "inverse a * fps_deriv a + fps_deriv (inverse a) * a = 0" | 
| 1140 | by simp | |
| 1141 | then have "inverse a * (inverse a * fps_deriv a + fps_deriv (inverse a) * a) = 0" | |
| 1142 | by simp | |
| 29687 | 1143 | with inverse_mult_eq_1[OF a0] | 
| 53077 | 1144 | have "(inverse a)\<^sup>2 * fps_deriv a + fps_deriv (inverse a) = 0" | 
| 29687 | 1145 | unfolding power2_eq_square | 
| 36350 | 1146 | apply (simp add: field_simps) | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1147 | apply (simp add: mult.assoc[symmetric]) | 
| 52903 | 1148 | done | 
| 53077 | 1149 | then have "(inverse a)\<^sup>2 * fps_deriv a + fps_deriv (inverse a) - fps_deriv a * (inverse a)\<^sup>2 = | 
| 1150 | 0 - fps_deriv a * (inverse a)\<^sup>2" | |
| 29687 | 1151 | by simp | 
| 53077 | 1152 | then show "fps_deriv (inverse a) = - fps_deriv a * (inverse a)\<^sup>2" | 
| 52902 | 1153 | by (simp add: field_simps) | 
| 29687 | 1154 | qed | 
| 1155 | ||
| 30488 | 1156 | lemma fps_inverse_mult: | 
| 54681 | 1157 | fixes a :: "'a::field fps" | 
| 29687 | 1158 | shows "inverse (a * b) = inverse a * inverse b" | 
| 52903 | 1159 | proof - | 
| 52902 | 1160 |   {
 | 
| 54452 | 1161 | assume a0: "a$0 = 0" | 
| 1162 | then have ab0: "(a*b)$0 = 0" by (simp add: fps_mult_nth) | |
| 29687 | 1163 | from a0 ab0 have th: "inverse a = 0" "inverse (a*b) = 0" by simp_all | 
| 52902 | 1164 | have ?thesis unfolding th by simp | 
| 1165 | } | |
| 29687 | 1166 | moreover | 
| 52902 | 1167 |   {
 | 
| 54452 | 1168 | assume b0: "b$0 = 0" | 
| 1169 | then have ab0: "(a*b)$0 = 0" by (simp add: fps_mult_nth) | |
| 29687 | 1170 | from b0 ab0 have th: "inverse b = 0" "inverse (a*b) = 0" by simp_all | 
| 52902 | 1171 | have ?thesis unfolding th by simp | 
| 1172 | } | |
| 29687 | 1173 | moreover | 
| 52902 | 1174 |   {
 | 
| 1175 | assume a0: "a$0 \<noteq> 0" and b0: "b$0 \<noteq> 0" | |
| 29687 | 1176 | from a0 b0 have ab0:"(a*b) $ 0 \<noteq> 0" by (simp add: fps_mult_nth) | 
| 30488 | 1177 | from inverse_mult_eq_1[OF ab0] | 
| 29687 | 1178 | have "inverse (a*b) * (a*b) * inverse a * inverse b = 1 * inverse a * inverse b" by simp | 
| 1179 | then have "inverse (a*b) * (inverse a * a) * (inverse b * b) = inverse a * inverse b" | |
| 36350 | 1180 | by (simp add: field_simps) | 
| 52902 | 1181 | then have ?thesis using inverse_mult_eq_1[OF a0] inverse_mult_eq_1[OF b0] by simp | 
| 1182 | } | |
| 1183 | ultimately show ?thesis by blast | |
| 29687 | 1184 | qed | 
| 1185 | ||
| 30488 | 1186 | lemma fps_inverse_deriv': | 
| 54681 | 1187 | fixes a :: "'a::field fps" | 
| 29687 | 1188 | assumes a0: "a$0 \<noteq> 0" | 
| 53077 | 1189 | shows "fps_deriv (inverse a) = - fps_deriv a / a\<^sup>2" | 
| 29687 | 1190 | using fps_inverse_deriv[OF a0] | 
| 48757 | 1191 | unfolding power2_eq_square fps_divide_def fps_inverse_mult | 
| 1192 | by simp | |
| 29687 | 1193 | |
| 52902 | 1194 | lemma inverse_mult_eq_1': | 
| 1195 | assumes f0: "f$0 \<noteq> (0::'a::field)" | |
| 29687 | 1196 | shows "f * inverse f= 1" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1197 | by (metis mult.commute inverse_mult_eq_1 f0) | 
| 29687 | 1198 | |
| 52902 | 1199 | lemma fps_divide_deriv: | 
| 54681 | 1200 | fixes a :: "'a::field fps" | 
| 29687 | 1201 | assumes a0: "b$0 \<noteq> 0" | 
| 53077 | 1202 | shows "fps_deriv (a / b) = (fps_deriv a * b - a * fps_deriv b) / b\<^sup>2" | 
| 29687 | 1203 | using fps_inverse_deriv[OF a0] | 
| 48757 | 1204 | by (simp add: fps_divide_def field_simps | 
| 1205 | power2_eq_square fps_inverse_mult inverse_mult_eq_1'[OF a0]) | |
| 30488 | 1206 | |
| 29687 | 1207 | |
| 54681 | 1208 | 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 | 1209 | by (simp add: fps_inverse_gp fps_eq_iff X_def) | 
| 29687 | 1210 | |
| 1211 | 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 | 1212 | by (cases n) simp_all | 
| 29687 | 1213 | |
| 1214 | ||
| 1215 | lemma fps_inverse_X_plus1: | |
| 54681 | 1216 | "inverse (1 + X) = Abs_fps (\<lambda>n. (- (1::'a::field)) ^ n)" (is "_ = ?r") | 
| 1217 | proof - | |
| 29687 | 1218 | have eq: "(1 + X) * ?r = 1" | 
| 1219 | unfolding minus_one_power_iff | |
| 36350 | 1220 | by (auto simp add: field_simps fps_eq_iff) | 
| 54681 | 1221 | show ?thesis | 
| 1222 | by (auto simp add: eq intro: fps_inverse_unique) | |
| 29687 | 1223 | qed | 
| 1224 | ||
| 30488 | 1225 | |
| 29906 | 1226 | subsection{* Integration *}
 | 
| 31273 | 1227 | |
| 52903 | 1228 | definition fps_integral :: "'a::field_char_0 fps \<Rightarrow> 'a \<Rightarrow> 'a fps" | 
| 1229 | where "fps_integral a a0 = Abs_fps (\<lambda>n. if n = 0 then a0 else (a$(n - 1) / of_nat n))" | |
| 29687 | 1230 | |
| 31273 | 1231 | lemma fps_deriv_fps_integral: "fps_deriv (fps_integral a a0) = a" | 
| 1232 | unfolding fps_integral_def fps_deriv_def | |
| 1233 | by (simp add: fps_eq_iff del: of_nat_Suc) | |
| 29687 | 1234 | |
| 31273 | 1235 | lemma fps_integral_linear: | 
| 1236 | "fps_integral (fps_const a * f + fps_const b * g) (a*a0 + b*b0) = | |
| 1237 | fps_const a * fps_integral f a0 + fps_const b * fps_integral g b0" | |
| 1238 | (is "?l = ?r") | |
| 53195 | 1239 | proof - | 
| 54681 | 1240 | have "fps_deriv ?l = fps_deriv ?r" | 
| 1241 | by (simp add: fps_deriv_fps_integral) | |
| 1242 | moreover have "?l$0 = ?r$0" | |
| 1243 | by (simp add: fps_integral_def) | |
| 29687 | 1244 | ultimately show ?thesis | 
| 1245 | unfolding fps_deriv_eq_iff by auto | |
| 1246 | qed | |
| 30488 | 1247 | |
| 53195 | 1248 | |
| 29906 | 1249 | subsection {* Composition of FPSs *}
 | 
| 53195 | 1250 | |
| 54681 | 1251 | definition fps_compose :: "'a::semiring_1 fps \<Rightarrow> 'a fps \<Rightarrow> 'a fps" (infixl "oo" 55) | 
| 1252 |   where "a oo b = Abs_fps (\<lambda>n. setsum (\<lambda>i. a$i * (b^i$n)) {0..n})"
 | |
| 29687 | 1253 | |
| 48757 | 1254 | lemma fps_compose_nth: "(a oo b)$n = setsum (\<lambda>i. a$i * (b^i$n)) {0..n}"
 | 
| 1255 | by (simp add: fps_compose_def) | |
| 29687 | 1256 | |
| 54681 | 1257 | lemma fps_compose_X[simp]: "a oo X = (a :: 'a::comm_ring_1 fps)" | 
| 57418 | 1258 | by (simp add: fps_ext fps_compose_def mult_delta_right setsum.delta') | 
| 30488 | 1259 | |
| 1260 | lemma fps_const_compose[simp]: | |
| 54681 | 1261 | "fps_const (a::'a::comm_ring_1) oo b = fps_const a" | 
| 57418 | 1262 | by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum.delta) | 
| 29687 | 1263 | |
| 54681 | 1264 | 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 | 1265 | unfolding numeral_fps_const by simp | 
| 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
 huffman parents: 
46757diff
changeset | 1266 | |
| 54681 | 1267 | 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 | 1268 | unfolding neg_numeral_fps_const by simp | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 1269 | |
| 54681 | 1270 | lemma X_fps_compose_startby0[simp]: "a$0 = 0 \<Longrightarrow> X oo a = (a :: 'a::comm_ring_1 fps)" | 
| 57418 | 1271 | by (simp add: fps_eq_iff fps_compose_def mult_delta_left setsum.delta not_le) | 
| 29687 | 1272 | |
| 1273 | ||
| 29906 | 1274 | subsection {* Rules from Herbert Wilf's Generatingfunctionology*}
 | 
| 29687 | 1275 | |
| 29906 | 1276 | subsubsection {* Rule 1 *}
 | 
| 29687 | 1277 |   (* {a_{n+k}}_0^infty Corresponds to (f - setsum (\<lambda>i. a_i * x^i))/x^h, for h>0*)
 | 
| 1278 | ||
| 30488 | 1279 | lemma fps_power_mult_eq_shift: | 
| 52902 | 1280 | "X^Suc k * Abs_fps (\<lambda>n. a (n + Suc k)) = | 
| 54681 | 1281 |     Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a::comm_ring_1) * X^i) {0 .. k}"
 | 
| 52902 | 1282 | (is "?lhs = ?rhs") | 
| 1283 | proof - | |
| 54681 | 1284 |   { fix n :: nat
 | 
| 30488 | 1285 | have "?lhs $ n = (if n < Suc k then 0 else a n)" | 
| 29687 | 1286 | unfolding X_power_mult_nth by auto | 
| 1287 | also have "\<dots> = ?rhs $ n" | |
| 52902 | 1288 | proof (induct k) | 
| 1289 | case 0 | |
| 54452 | 1290 | then show ?case by (simp add: fps_setsum_nth) | 
| 29687 | 1291 | next | 
| 1292 | case (Suc k) | |
| 1293 | note th = Suc.hyps[symmetric] | |
| 52902 | 1294 |       have "(Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. Suc k})$n =
 | 
| 53196 | 1295 |         (Abs_fps a - setsum (\<lambda>i. fps_const (a i :: 'a) * X^i) {0 .. k} -
 | 
| 1296 | fps_const (a (Suc k)) * X^ Suc k) $ n" | |
| 52902 | 1297 | by (simp add: field_simps) | 
| 1298 | also have "\<dots> = (if n < Suc k then 0 else a n) - (fps_const (a (Suc k)) * X^ Suc k)$n" | |
| 1299 | using th unfolding fps_sub_nth by simp | |
| 29687 | 1300 | 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 | 1301 | unfolding X_power_mult_right_nth | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1302 | 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 | 1303 | apply (rule cong[of a a, OF refl]) | 
| 52902 | 1304 | apply arith | 
| 1305 | done | |
| 29687 | 1306 | finally show ?case by simp | 
| 1307 | qed | |
| 52902 | 1308 | finally have "?lhs $ n = ?rhs $ n" . | 
| 1309 | } | |
| 29687 | 1310 | then show ?thesis by (simp add: fps_eq_iff) | 
| 1311 | qed | |
| 1312 | ||
| 53195 | 1313 | |
| 1314 | subsubsection {* Rule 2*}
 | |
| 29687 | 1315 | |
| 1316 | (* We can not reach the form of Wilf, but still near to it using rewrite rules*) | |
| 30488 | 1317 |   (* If f reprents {a_n} and P is a polynomial, then
 | 
| 29687 | 1318 |         P(xD) f represents {P(n) a_n}*)
 | 
| 1319 | ||
| 54681 | 1320 | definition "XD = op * X \<circ> fps_deriv" | 
| 1321 | ||
| 1322 | lemma XD_add[simp]:"XD (a + b) = XD a + XD (b :: 'a::comm_ring_1 fps)" | |
| 36350 | 1323 | by (simp add: XD_def field_simps) | 
| 29687 | 1324 | |
| 1325 | lemma XD_mult_const[simp]:"XD (fps_const (c::'a::comm_ring_1) * a) = fps_const c * XD a" | |
| 36350 | 1326 | by (simp add: XD_def field_simps) | 
| 29687 | 1327 | |
| 52902 | 1328 | lemma XD_linear[simp]: "XD (fps_const c * a + fps_const d * b) = | 
| 54681 | 1329 | fps_const c * XD a + fps_const d * XD (b :: 'a::comm_ring_1 fps)" | 
| 29687 | 1330 | by simp | 
| 1331 | ||
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30837diff
changeset | 1332 | lemma XDN_linear: | 
| 52902 | 1333 | "(XD ^^ n) (fps_const c * a + fps_const d * b) = | 
| 54681 | 1334 | fps_const c * (XD ^^ n) a + fps_const d * (XD ^^ n) (b :: 'a::comm_ring_1 fps)" | 
| 48757 | 1335 | by (induct n) simp_all | 
| 29687 | 1336 | |
| 52902 | 1337 | lemma fps_mult_X_deriv_shift: "X* fps_deriv a = Abs_fps (\<lambda>n. of_nat n* a$n)" | 
| 1338 | by (simp add: fps_eq_iff) | |
| 29687 | 1339 | |
| 30994 | 1340 | |
| 30952 
7ab2716dd93b
power operation on functions with syntax o^; power operation on relations with syntax ^^
 haftmann parents: 
30837diff
changeset | 1341 | lemma fps_mult_XD_shift: | 
| 54681 | 1342 | "(XD ^^ k) (a :: 'a::comm_ring_1 fps) = Abs_fps (\<lambda>n. (of_nat n ^ k) * a$n)" | 
| 52902 | 1343 | by (induct k arbitrary: a) (simp_all add: XD_def fps_eq_iff field_simps del: One_nat_def) | 
| 29687 | 1344 | |
| 53195 | 1345 | |
| 54681 | 1346 | subsubsection {* Rule 3 is trivial and is given by @{text fps_times_def} *}
 | 
| 1347 | ||
| 1348 | subsubsection {* Rule 5 --- summation and "division" by (1 - X) *}
 | |
| 29687 | 1349 | |
| 1350 | lemma fps_divide_X_minus1_setsum_lemma: | |
| 54681 | 1351 |   "a = ((1::'a::comm_ring_1 fps) - X) * Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 53195 | 1352 | proof - | 
| 29687 | 1353 |   let ?sa = "Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 52902 | 1354 | have th0: "\<And>i. (1 - (X::'a fps)) $ i = (if i = 0 then 1 else if i = 1 then - 1 else 0)" | 
| 1355 | by simp | |
| 1356 |   {
 | |
| 54681 | 1357 | fix n :: nat | 
| 52902 | 1358 |     {
 | 
| 54681 | 1359 | assume "n = 0" | 
| 1360 | then have "a $ n = ((1 - X) * ?sa) $ n" | |
| 52902 | 1361 | by (simp add: fps_mult_nth) | 
| 1362 | } | |
| 29687 | 1363 | moreover | 
| 52902 | 1364 |     {
 | 
| 1365 | assume n0: "n \<noteq> 0" | |
| 54681 | 1366 |       then have u: "{0} \<union> ({1} \<union> {2..n}) = {0..n}" "{1} \<union> {2..n} = {1..n}"
 | 
| 1367 |         "{0..n - 1} \<union> {n} = {0..n}"
 | |
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 1368 | by (auto simp: set_eq_iff) | 
| 54681 | 1369 |       have d: "{0} \<inter> ({1} \<union> {2..n}) = {}" "{1} \<inter> {2..n} = {}" "{0..n - 1} \<inter> {n} = {}"
 | 
| 1370 | using n0 by simp_all | |
| 30488 | 1371 |       have f: "finite {0}" "finite {1}" "finite {2 .. n}"
 | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1372 |         "finite {0 .. n - 1}" "finite {n}" by simp_all
 | 
| 54681 | 1373 |       have "((1 - X) * ?sa) $ n = setsum (\<lambda>i. (1 - X)$ i * ?sa $ (n - i)) {0 .. n}"
 | 
| 52902 | 1374 | by (simp add: fps_mult_nth) | 
| 1375 | also have "\<dots> = a$n" | |
| 1376 | unfolding th0 | |
| 57418 | 1377 | unfolding setsum.union_disjoint[OF f(1) finite_UnI[OF f(2,3)] d(1), unfolded u(1)] | 
| 1378 | unfolding setsum.union_disjoint[OF f(2) f(3) d(2)] | |
| 52902 | 1379 | apply (simp) | 
| 57418 | 1380 | unfolding setsum.union_disjoint[OF f(4,5) d(3), unfolded u(3)] | 
| 52902 | 1381 | apply simp | 
| 1382 | done | |
| 54681 | 1383 | finally have "a$n = ((1 - X) * ?sa) $ n" | 
| 1384 | by simp | |
| 52902 | 1385 | } | 
| 54681 | 1386 | ultimately have "a$n = ((1 - X) * ?sa) $ n" | 
| 1387 | by blast | |
| 52902 | 1388 | } | 
| 54681 | 1389 | then show ?thesis | 
| 1390 | unfolding fps_eq_iff by blast | |
| 29687 | 1391 | qed | 
| 1392 | ||
| 1393 | lemma fps_divide_X_minus1_setsum: | |
| 54681 | 1394 |   "a /((1::'a::field fps) - X) = Abs_fps (\<lambda>n. setsum (\<lambda>i. a $ i) {0..n})"
 | 
| 52902 | 1395 | proof - | 
| 54681 | 1396 | let ?X = "1 - (X::'a fps)" | 
| 1397 | have th0: "?X $ 0 \<noteq> 0" | |
| 1398 | by simp | |
| 1399 |   have "a /?X = ?X *  Abs_fps (\<lambda>n::nat. setsum (op $ a) {0..n}) * inverse ?X"
 | |
| 29687 | 1400 | 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 | 1401 | by (simp add: fps_divide_def mult.assoc) | 
| 54681 | 1402 |   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 | 1403 | by (simp add: ac_simps) | 
| 54681 | 1404 | finally show ?thesis | 
| 1405 | by (simp add: inverse_mult_eq_1[OF th0]) | |
| 29687 | 1406 | qed | 
| 1407 | ||
| 53195 | 1408 | |
| 30488 | 1409 | subsubsection{* Rule 4 in its more general form: generalizes Rule 3 for an arbitrary
 | 
| 29687 | 1410 | finite product of FPS, also the relvant instance of powers of a FPS*} | 
| 1411 | ||
| 46131 | 1412 | definition "natpermute n k = {l :: nat list. length l = k \<and> listsum l = n}"
 | 
| 29687 | 1413 | |
| 1414 | lemma natlist_trivial_1: "natpermute n 1 = {[n]}"
 | |
| 1415 | apply (auto simp add: natpermute_def) | |
| 52902 | 1416 | apply (case_tac x) | 
| 1417 | apply auto | |
| 29687 | 1418 | done | 
| 1419 | ||
| 1420 | lemma append_natpermute_less_eq: | |
| 54452 | 1421 | assumes "xs @ ys \<in> natpermute n k" | 
| 54681 | 1422 | shows "listsum xs \<le> n" | 
| 1423 | and "listsum ys \<le> n" | |
| 52902 | 1424 | proof - | 
| 54452 | 1425 | from assms have "listsum (xs @ ys) = n" | 
| 1426 | by (simp add: natpermute_def) | |
| 1427 | then have "listsum xs + listsum ys = n" | |
| 1428 | by simp | |
| 1429 | then show "listsum xs \<le> n" and "listsum ys \<le> n" | |
| 1430 | by simp_all | |
| 29687 | 1431 | qed | 
| 1432 | ||
| 1433 | lemma natpermute_split: | |
| 54452 | 1434 | assumes "h \<le> k" | 
| 52902 | 1435 | shows "natpermute n k = | 
| 1436 |     (\<Union>m \<in>{0..n}. {l1 @ l2 |l1 l2. l1 \<in> natpermute m h \<and> l2 \<in> natpermute (n - m) (k - h)})"
 | |
| 1437 |   (is "?L = ?R" is "?L = (\<Union>m \<in>{0..n}. ?S m)")
 | |
| 1438 | proof - | |
| 1439 |   {
 | |
| 1440 | fix l | |
| 1441 | assume l: "l \<in> ?R" | |
| 1442 |     from l obtain m xs ys where h: "m \<in> {0..n}"
 | |
| 1443 | and xs: "xs \<in> natpermute m h" | |
| 1444 | and ys: "ys \<in> natpermute (n - m) (k - h)" | |
| 1445 | and leq: "l = xs@ys" by blast | |
| 1446 | from xs have xs': "listsum xs = m" | |
| 1447 | by (simp add: natpermute_def) | |
| 1448 | from ys have ys': "listsum ys = n - m" | |
| 1449 | by (simp add: natpermute_def) | |
| 30488 | 1450 | have "l \<in> ?L" using leq xs ys h | 
| 46131 | 1451 | apply (clarsimp simp add: natpermute_def) | 
| 29687 | 1452 | unfolding xs' ys' | 
| 54452 | 1453 | using assms xs ys | 
| 48757 | 1454 | unfolding natpermute_def | 
| 1455 | apply simp | |
| 1456 | done | |
| 1457 | } | |
| 29687 | 1458 | moreover | 
| 52902 | 1459 |   {
 | 
| 1460 | fix l | |
| 1461 | assume l: "l \<in> natpermute n k" | |
| 29687 | 1462 | let ?xs = "take h l" | 
| 1463 | let ?ys = "drop h l" | |
| 46131 | 1464 | let ?m = "listsum ?xs" | 
| 52902 | 1465 | from l have ls: "listsum (?xs @ ?ys) = n" | 
| 1466 | by (simp add: natpermute_def) | |
| 54452 | 1467 | have xs: "?xs \<in> natpermute ?m h" using l assms | 
| 52902 | 1468 | by (simp add: natpermute_def) | 
| 1469 | have l_take_drop: "listsum l = listsum (take h l @ drop h l)" | |
| 1470 | by simp | |
| 1471 | then have ys: "?ys \<in> natpermute (n - ?m) (k - h)" | |
| 54452 | 1472 | using l assms ls by (auto simp add: natpermute_def simp del: append_take_drop_id) | 
| 52902 | 1473 |     from ls have m: "?m \<in> {0..n}"
 | 
| 1474 | by (simp add: l_take_drop del: append_take_drop_id) | |
| 30488 | 1475 | from xs ys ls have "l \<in> ?R" | 
| 29687 | 1476 | apply auto | 
| 52902 | 1477 | apply (rule bexI [where x = "?m"]) | 
| 1478 | apply (rule exI [where x = "?xs"]) | |
| 1479 | apply (rule exI [where x = "?ys"]) | |
| 52891 | 1480 | using ls l | 
| 46131 | 1481 | apply (auto simp add: natpermute_def l_take_drop simp del: append_take_drop_id) | 
| 48757 | 1482 | apply simp | 
| 1483 | done | |
| 1484 | } | |
| 29687 | 1485 | ultimately show ?thesis by blast | 
| 1486 | qed | |
| 1487 | ||
| 1488 | lemma natpermute_0: "natpermute n 0 = (if n = 0 then {[]} else {})"
 | |
| 1489 | by (auto simp add: natpermute_def) | |
| 52902 | 1490 | |
| 29687 | 1491 | lemma natpermute_0'[simp]: "natpermute 0 k = (if k = 0 then {[]} else {replicate k 0})"
 | 
| 1492 | apply (auto simp add: set_replicate_conv_if natpermute_def) | |
| 1493 | apply (rule nth_equalityI) | |
| 48757 | 1494 | apply simp_all | 
| 1495 | done | |
| 29687 | 1496 | |
| 1497 | lemma natpermute_finite: "finite (natpermute n k)" | |
| 52902 | 1498 | proof (induct k arbitrary: n) | 
| 1499 | case 0 | |
| 1500 | then show ?case | |
| 29687 | 1501 | apply (subst natpermute_split[of 0 0, simplified]) | 
| 52902 | 1502 | apply (simp add: natpermute_0) | 
| 1503 | done | |
| 29687 | 1504 | next | 
| 1505 | case (Suc k) | |
| 52902 | 1506 | then show ?case unfolding natpermute_split [of k "Suc k", simplified] | 
| 29687 | 1507 | apply - | 
| 1508 | apply (rule finite_UN_I) | |
| 1509 | apply simp | |
| 1510 | unfolding One_nat_def[symmetric] natlist_trivial_1 | |
| 1511 | apply simp | |
| 1512 | done | |
| 1513 | qed | |
| 1514 | ||
| 1515 | lemma natpermute_contain_maximal: | |
| 1516 |   "{xs \<in> natpermute n (k+1). n \<in> set xs} = UNION {0 .. k} (\<lambda>i. {(replicate (k+1) 0) [i:=n]})"
 | |
| 1517 | (is "?A = ?B") | |
| 52903 | 1518 | proof - | 
| 52902 | 1519 |   {
 | 
| 1520 | fix xs | |
| 1521 | assume H: "xs \<in> natpermute n (k+1)" and n: "n \<in> set xs" | |
| 29687 | 1522 |     from n obtain i where i: "i \<in> {0.. k}" "xs!i = n" using H
 | 
| 30488 | 1523 | unfolding in_set_conv_nth by (auto simp add: less_Suc_eq_le natpermute_def) | 
| 52902 | 1524 |     have eqs: "({0..k} - {i}) \<union> {i} = {0..k}"
 | 
| 1525 | using i by auto | |
| 1526 |     have f: "finite({0..k} - {i})" "finite {i}"
 | |
| 1527 | by auto | |
| 1528 |     have d: "({0..k} - {i}) \<inter> {i} = {}"
 | |
| 1529 | using i by auto | |
| 1530 |     from H have "n = setsum (nth xs) {0..k}"
 | |
| 1531 | apply (simp add: natpermute_def) | |
| 1532 | apply (auto simp add: atLeastLessThanSuc_atLeastAtMost listsum_setsum_nth) | |
| 1533 | done | |
| 29687 | 1534 |     also have "\<dots> = n + setsum (nth xs) ({0..k} - {i})"
 | 
| 57418 | 1535 | unfolding setsum.union_disjoint[OF f d, unfolded eqs] using i by simp | 
| 52902 | 1536 |     finally have zxs: "\<forall> j\<in> {0..k} - {i}. xs!j = 0"
 | 
| 1537 | by auto | |
| 1538 | from H have xsl: "length xs = k+1" | |
| 1539 | by (simp add: natpermute_def) | |
| 29687 | 1540 | from i have i': "i < length (replicate (k+1) 0)" "i < k+1" | 
| 52902 | 1541 | unfolding length_replicate by presburger+ | 
| 29687 | 1542 | have "xs = replicate (k+1) 0 [i := n]" | 
| 1543 | apply (rule nth_equalityI) | |
| 1544 | unfolding xsl length_list_update length_replicate | |
| 1545 | apply simp | |
| 1546 | apply clarify | |
| 1547 | unfolding nth_list_update[OF i'(1)] | |
| 1548 | using i zxs | |
| 52902 | 1549 | apply (case_tac "ia = i") | 
| 1550 | apply (auto simp del: replicate.simps) | |
| 1551 | done | |
| 48757 | 1552 | then have "xs \<in> ?B" using i by blast | 
| 1553 | } | |
| 29687 | 1554 | moreover | 
| 52902 | 1555 |   {
 | 
| 1556 | fix i | |
| 1557 |     assume i: "i \<in> {0..k}"
 | |
| 29687 | 1558 | let ?xs = "replicate (k+1) 0 [i:=n]" | 
| 1559 | have nxs: "n \<in> set ?xs" | |
| 52902 | 1560 | apply (rule set_update_memI) | 
| 1561 | using i apply simp | |
| 1562 | done | |
| 1563 | have xsl: "length ?xs = k+1" | |
| 1564 | by (simp only: length_replicate length_list_update) | |
| 46131 | 1565 |     have "listsum ?xs = setsum (nth ?xs) {0..<k+1}"
 | 
| 1566 | unfolding listsum_setsum_nth xsl .. | |
| 29687 | 1567 |     also have "\<dots> = setsum (\<lambda>j. if j = i then n else 0) {0..< k+1}"
 | 
| 57418 | 1568 | by (rule setsum.cong) (simp_all del: replicate.simps) | 
| 1569 | also have "\<dots> = n" using i by (simp add: setsum.delta) | |
| 52902 | 1570 | finally have "?xs \<in> natpermute n (k+1)" | 
| 1571 | using xsl unfolding natpermute_def mem_Collect_eq by blast | |
| 1572 | then have "?xs \<in> ?A" | |
| 1573 | using nxs by blast | |
| 48757 | 1574 | } | 
| 29687 | 1575 | ultimately show ?thesis by auto | 
| 1576 | qed | |
| 1577 | ||
| 54452 | 1578 | text {* The general form *}
 | 
| 29687 | 1579 | lemma fps_setprod_nth: | 
| 52902 | 1580 | fixes m :: nat | 
| 54681 | 1581 | and a :: "nat \<Rightarrow> 'a::comm_ring_1 fps" | 
| 1582 |   shows "(setprod a {0 .. m}) $ n =
 | |
| 53196 | 1583 |     setsum (\<lambda>v. setprod (\<lambda>j. (a j) $ (v!j)) {0..m}) (natpermute n (m+1))"
 | 
| 29687 | 1584 | (is "?P m n") | 
| 52902 | 1585 | proof (induct m arbitrary: n rule: nat_less_induct) | 
| 29687 | 1586 | fix m n assume H: "\<forall>m' < m. \<forall>n. ?P m' n" | 
| 53196 | 1587 | show "?P m n" | 
| 1588 | proof (cases m) | |
| 1589 | case 0 | |
| 1590 | then show ?thesis | |
| 1591 | apply simp | |
| 1592 | unfolding natlist_trivial_1[where n = n, unfolded One_nat_def] | |
| 1593 | apply simp | |
| 1594 | done | |
| 1595 | next | |
| 1596 | case (Suc k) | |
| 1597 | then have km: "k < m" by arith | |
| 52902 | 1598 |     have u0: "{0 .. k} \<union> {m} = {0..m}"
 | 
| 54452 | 1599 | using Suc by (simp add: set_eq_iff) presburger | 
| 29687 | 1600 |     have f0: "finite {0 .. k}" "finite {m}" by auto
 | 
| 53196 | 1601 |     have d0: "{0 .. k} \<inter> {m} = {}" using Suc by auto
 | 
| 29687 | 1602 |     have "(setprod a {0 .. m}) $ n = (setprod a {0 .. k} * a m) $ n"
 | 
| 57418 | 1603 | unfolding setprod.union_disjoint[OF f0 d0, unfolded u0] by simp | 
| 29687 | 1604 |     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))"
 | 
| 1605 | unfolding fps_mult_nth H[rule_format, OF km] .. | |
| 1606 |     also have "\<dots> = (\<Sum>v\<in>natpermute n (m + 1). \<Prod>j\<in>{0..m}. a j $ v ! j)"
 | |
| 53196 | 1607 | apply (simp add: Suc) | 
| 48757 | 1608 | unfolding natpermute_split[of m "m + 1", simplified, of n, | 
| 53196 | 1609 | unfolded natlist_trivial_1[unfolded One_nat_def] Suc] | 
| 57418 | 1610 | apply (subst setsum.UNION_disjoint) | 
| 30488 | 1611 | apply simp | 
| 29687 | 1612 | apply simp | 
| 1613 | unfolding image_Collect[symmetric] | |
| 1614 | apply clarsimp | |
| 1615 | apply (rule finite_imageI) | |
| 1616 | 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 | 1617 | apply (clarsimp simp add: set_eq_iff) | 
| 29687 | 1618 | apply auto | 
| 57418 | 1619 | apply (rule setsum.cong) | 
| 1620 | apply (rule refl) | |
| 29687 | 1621 | unfolding setsum_left_distrib | 
| 1622 | apply (rule sym) | |
| 57418 | 1623 | apply (rule_tac l = "\<lambda>xs. xs @ [n - x]" in setsum.reindex_cong) | 
| 29687 | 1624 | apply (simp add: inj_on_def) | 
| 1625 | apply auto | |
| 57418 | 1626 | unfolding setprod.union_disjoint[OF f0 d0, unfolded u0, unfolded Suc] | 
| 29687 | 1627 | apply (clarsimp simp add: natpermute_def nth_append) | 
| 1628 | done | |
| 53196 | 1629 | finally show ?thesis . | 
| 1630 | qed | |
| 29687 | 1631 | qed | 
| 1632 | ||
| 1633 | text{* The special form for powers *}
 | |
| 1634 | lemma fps_power_nth_Suc: | |
| 52903 | 1635 | fixes m :: nat | 
| 54681 | 1636 | and a :: "'a::comm_ring_1 fps" | 
| 29687 | 1637 |   shows "(a ^ Suc m)$n = setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m}) (natpermute n (m+1))"
 | 
| 52902 | 1638 | proof - | 
| 54452 | 1639 |   have th0: "a^Suc m = setprod (\<lambda>i. a) {0..m}"
 | 
| 1640 | by (simp add: setprod_constant) | |
| 29687 | 1641 | show ?thesis unfolding th0 fps_setprod_nth .. | 
| 1642 | qed | |
| 52902 | 1643 | |
| 29687 | 1644 | lemma fps_power_nth: | 
| 54452 | 1645 | fixes m :: nat | 
| 54681 | 1646 | and a :: "'a::comm_ring_1 fps" | 
| 53196 | 1647 | shows "(a ^m)$n = | 
| 1648 |     (if m=0 then 1$n else setsum (\<lambda>v. setprod (\<lambda>j. a $ (v!j)) {0..m - 1}) (natpermute n m))"
 | |
| 52902 | 1649 | by (cases m) (simp_all add: fps_power_nth_Suc del: power_Suc) | 
| 29687 | 1650 | |
| 30488 | 1651 | lemma fps_nth_power_0: | 
| 54452 | 1652 | fixes m :: nat | 
| 54681 | 1653 | and a :: "'a::comm_ring_1 fps" | 
| 29687 | 1654 | shows "(a ^m)$0 = (a$0) ^ m" | 
| 53195 | 1655 | proof (cases m) | 
| 1656 | case 0 | |
| 1657 | then show ?thesis by simp | |
| 1658 | next | |
| 1659 | case (Suc n) | |
| 1660 |   then have c: "m = card {0..n}" by simp
 | |
| 1661 |   have "(a ^m)$0 = setprod (\<lambda>i. a$0) {0..n}"
 | |
| 1662 | by (simp add: Suc fps_power_nth del: replicate.simps power_Suc) | |
| 1663 | also have "\<dots> = (a$0) ^ m" | |
| 1664 | unfolding c by (rule setprod_constant) simp | |
| 1665 | finally show ?thesis . | |
| 29687 | 1666 | qed | 
| 1667 | ||
| 30488 | 1668 | lemma fps_compose_inj_right: | 
| 54681 | 1669 | assumes a0: "a$0 = (0::'a::idom)" | 
| 52902 | 1670 | and a1: "a$1 \<noteq> 0" | 
| 54681 | 1671 | shows "(b oo a = c oo a) \<longleftrightarrow> b = c" | 
| 1672 | (is "?lhs \<longleftrightarrow>?rhs") | |
| 53196 | 1673 | proof | 
| 1674 | assume ?rhs | |
| 1675 | then show "?lhs" by simp | |
| 1676 | next | |
| 1677 | assume h: ?lhs | |
| 1678 |   {
 | |
| 1679 | fix n | |
| 1680 | have "b$n = c$n" | |
| 1681 | proof (induct n rule: nat_less_induct) | |
| 1682 | fix n | |
| 1683 | assume H: "\<forall>m<n. b$m = c$m" | |
| 1684 |       {
 | |
| 1685 | assume n0: "n=0" | |
| 1686 | from h have "(b oo a)$n = (c oo a)$n" by simp | |
| 54452 | 1687 | then have "b$n = c$n" using n0 by (simp add: fps_compose_nth) | 
| 53196 | 1688 | } | 
| 1689 | moreover | |
| 1690 |       {
 | |
| 1691 | fix n1 assume n1: "n = Suc n1" | |
| 1692 |         have f: "finite {0 .. n1}" "finite {n}" by simp_all
 | |
| 1693 |         have eq: "{0 .. n1} \<union> {n} = {0 .. n}" using n1 by auto
 | |
| 1694 |         have d: "{0 .. n1} \<inter> {n} = {}" using n1 by auto
 | |
| 1695 | have seq: "(\<Sum>i = 0..n1. b $ i * a ^ i $ n) = (\<Sum>i = 0..n1. c $ i * a ^ i $ n)" | |
| 57418 | 1696 | apply (rule setsum.cong) | 
| 53196 | 1697 | using H n1 | 
| 1698 | apply auto | |
| 1699 | done | |
| 1700 | have th0: "(b oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + b$n * (a$1)^n" | |
| 57418 | 1701 | unfolding fps_compose_nth setsum.union_disjoint[OF f d, unfolded eq] seq | 
| 53196 | 1702 | using startsby_zero_power_nth_same[OF a0] | 
| 1703 | by simp | |
| 1704 | have th1: "(c oo a) $n = (\<Sum>i = 0..n1. c $ i * a ^ i $ n) + c$n * (a$1)^n" | |
| 57418 | 1705 | unfolding fps_compose_nth setsum.union_disjoint[OF f d, unfolded eq] | 
| 53196 | 1706 | using startsby_zero_power_nth_same[OF a0] | 
| 1707 | by simp | |
| 1708 | from h[unfolded fps_eq_iff, rule_format, of n] th0 th1 a1 | |
| 1709 | have "b$n = c$n" by auto | |
| 1710 | } | |
| 1711 | ultimately show "b$n = c$n" by (cases n) auto | |
| 1712 | qed} | |
| 1713 | then show ?rhs by (simp add: fps_eq_iff) | |
| 29687 | 1714 | qed | 
| 1715 | ||
| 1716 | ||
| 29906 | 1717 | subsection {* Radicals *}
 | 
| 29687 | 1718 | |
| 57418 | 1719 | declare setprod.cong [fundef_cong] | 
| 52903 | 1720 | |
| 54681 | 1721 | function radical :: "(nat \<Rightarrow> 'a \<Rightarrow> 'a) \<Rightarrow> nat \<Rightarrow> 'a::field fps \<Rightarrow> nat \<Rightarrow> 'a" | 
| 52902 | 1722 | where | 
| 29687 | 1723 | "radical r 0 a 0 = 1" | 
| 1724 | | "radical r 0 a (Suc n) = 0" | |
| 1725 | | "radical r (Suc k) a 0 = r (Suc k) (a$0)" | |
| 48757 | 1726 | | "radical r (Suc k) a (Suc n) = | 
| 1727 |     (a$ Suc n - setsum (\<lambda>xs. setprod (\<lambda>j. radical r (Suc k) a (xs ! j)) {0..k})
 | |
| 1728 |       {xs. xs \<in> natpermute (Suc n) (Suc k) \<and> Suc n \<notin> set xs}) /
 | |
| 1729 | (of_nat (Suc k) * (radical r (Suc k) a 0)^k)" | |
| 52902 | 1730 | by pat_completeness auto | 
| 29687 | 1731 | |
| 1732 | termination radical | |
| 1733 | proof | |
| 1734 | let ?R = "measure (\<lambda>(r, k, a, n). n)" | |
| 1735 |   {
 | |
| 52902 | 1736 | show "wf ?R" by auto | 
| 1737 | next | |
| 1738 | fix r k a n xs i | |
| 29687 | 1739 |     assume xs: "xs \<in> {xs \<in> natpermute (Suc n) (Suc k). Suc n \<notin> set xs}" and i: "i \<in> {0..k}"
 | 
| 52902 | 1740 |     {
 | 
| 1741 | assume c: "Suc n \<le> xs ! i" | |
| 1742 | from xs i have "xs !i \<noteq> Suc n" | |
| 1743 | by (auto simp add: in_set_conv_nth natpermute_def) | |
| 29687 | 1744 | with c have c': "Suc n < xs!i" by arith | 
| 52902 | 1745 |       have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}"
 | 
| 1746 | by simp_all | |
| 1747 |       have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}"
 | |
| 1748 | by auto | |
| 1749 |       have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})"
 | |
| 1750 | using i by auto | |
| 1751 | from xs have "Suc n = listsum xs" | |
| 1752 | by (simp add: natpermute_def) | |
| 46131 | 1753 |       also have "\<dots> = setsum (nth xs) {0..<Suc k}" using xs
 | 
| 1754 | by (simp add: natpermute_def listsum_setsum_nth) | |
| 29687 | 1755 |       also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
 | 
| 57418 | 1756 | unfolding eqs setsum.union_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)] | 
| 1757 | 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 | 1758 | by simp | 
| 52902 | 1759 | finally have False using c' by simp | 
| 1760 | } | |
| 1761 | then show "((r, Suc k, a, xs!i), r, Suc k, a, Suc n) \<in> ?R" | |
| 1762 | apply auto | |
| 1763 | apply (metis not_less) | |
| 1764 | done | |
| 1765 | next | |
| 1766 | fix r k a n | |
| 1767 | show "((r, Suc k, a, 0), r, Suc k, a, Suc n) \<in> ?R" by simp | |
| 1768 | } | |
| 29687 | 1769 | qed | 
| 1770 | ||
| 1771 | definition "fps_radical r n a = Abs_fps (radical r n a)" | |
| 1772 | ||
| 1773 | lemma fps_radical0[simp]: "fps_radical r 0 a = 1" | |
| 52902 | 1774 | apply (auto simp add: fps_eq_iff fps_radical_def) | 
| 1775 | apply (case_tac n) | |
| 1776 | apply auto | |
| 1777 | done | |
| 29687 | 1778 | |
| 1779 | lemma fps_radical_nth_0[simp]: "fps_radical r n a $ 0 = (if n=0 then 1 else r n (a$0))" | |
| 52902 | 1780 | by (cases n) (simp_all add: fps_radical_def) | 
| 29687 | 1781 | |
| 30488 | 1782 | lemma fps_radical_power_nth[simp]: | 
| 29687 | 1783 | assumes r: "(r k (a$0)) ^ k = a$0" | 
| 1784 | shows "fps_radical r k a ^ k $ 0 = (if k = 0 then 1 else a$0)" | |
| 53196 | 1785 | proof (cases k) | 
| 1786 | case 0 | |
| 1787 | then show ?thesis by simp | |
| 1788 | next | |
| 1789 | case (Suc h) | |
| 1790 |   have eq1: "fps_radical r k a ^ k $ 0 = (\<Prod>j\<in>{0..h}. fps_radical r k a $ (replicate k 0) ! j)"
 | |
| 1791 | unfolding fps_power_nth Suc by simp | |
| 1792 |   also have "\<dots> = (\<Prod>j\<in>{0..h}. r k (a$0))"
 | |
| 57418 | 1793 | apply (rule setprod.cong) | 
| 53196 | 1794 | apply simp | 
| 1795 | using Suc | |
| 54681 | 1796 | apply (subgoal_tac "replicate k 0 ! x = 0") | 
| 53196 | 1797 | apply (auto intro: nth_replicate simp del: replicate.simps) | 
| 1798 | done | |
| 1799 | also have "\<dots> = a$0" using r Suc by (simp add: setprod_constant) | |
| 1800 | finally show ?thesis using Suc by simp | |
| 30488 | 1801 | qed | 
| 29687 | 1802 | |
| 52902 | 1803 | lemma natpermute_max_card: | 
| 54452 | 1804 | assumes n0: "n \<noteq> 0" | 
| 52902 | 1805 |   shows "card {xs \<in> natpermute n (k+1). n \<in> set xs} = k + 1"
 | 
| 29687 | 1806 | unfolding natpermute_contain_maximal | 
| 52902 | 1807 | proof - | 
| 29687 | 1808 |   let ?A= "\<lambda>i. {replicate (k + 1) 0[i := n]}"
 | 
| 1809 |   let ?K = "{0 ..k}"
 | |
| 1810 | have fK: "finite ?K" by simp | |
| 1811 | have fAK: "\<forall>i\<in>?K. finite (?A i)" by auto | |
| 48757 | 1812 | have d: "\<forall>i\<in> ?K. \<forall>j\<in> ?K. i \<noteq> j \<longrightarrow> | 
| 1813 |     {replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
 | |
| 52902 | 1814 | proof clarify | 
| 1815 | fix i j | |
| 1816 | assume i: "i \<in> ?K" and j: "j\<in> ?K" and ij: "i\<noteq>j" | |
| 1817 |     {
 | |
| 1818 | assume eq: "replicate (k+1) 0 [i:=n] = replicate (k+1) 0 [j:= n]" | |
| 1819 | have "(replicate (k+1) 0 [i:=n] ! i) = n" | |
| 1820 | using i by (simp del: replicate.simps) | |
| 29687 | 1821 | moreover | 
| 52902 | 1822 | have "(replicate (k+1) 0 [j:=n] ! i) = 0" | 
| 1823 | using i ij by (simp del: replicate.simps) | |
| 1824 | ultimately have False | |
| 1825 | using eq n0 by (simp del: replicate.simps) | |
| 1826 | } | |
| 29687 | 1827 |     then show "{replicate (k + 1) 0[i := n]} \<inter> {replicate (k + 1) 0[j := n]} = {}"
 | 
| 1828 | by auto | |
| 1829 | qed | |
| 54452 | 1830 | from card_UN_disjoint[OF fK fAK d] | 
| 1831 |   show "card (\<Union>i\<in>{0..k}. {replicate (k + 1) 0[i := n]}) = k + 1"
 | |
| 52902 | 1832 | by simp | 
| 29687 | 1833 | qed | 
| 30488 | 1834 | |
| 1835 | lemma power_radical: | |
| 31273 | 1836 | fixes a:: "'a::field_char_0 fps" | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1837 | assumes a0: "a$0 \<noteq> 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1838 | shows "(r (Suc k) (a$0)) ^ Suc k = a$0 \<longleftrightarrow> (fps_radical r (Suc k) a) ^ (Suc k) = a" | 
| 54452 | 1839 | proof - | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1840 | let ?r = "fps_radical r (Suc k) a" | 
| 52903 | 1841 |   {
 | 
| 1842 | assume r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1843 | from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto | 
| 52903 | 1844 |     {
 | 
| 1845 | fix z | |
| 1846 | have "?r ^ Suc k $ z = a$z" | |
| 1847 | proof (induct z rule: nat_less_induct) | |
| 1848 | fix n | |
| 1849 | assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m" | |
| 1850 |         {
 | |
| 1851 | assume "n = 0" | |
| 54452 | 1852 | then have "?r ^ Suc k $ n = a $n" | 
| 52903 | 1853 | using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp | 
| 1854 | } | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1855 | moreover | 
| 52903 | 1856 |         {
 | 
| 1857 | fix n1 assume n1: "n = Suc n1" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1858 | 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 | 1859 | let ?Pnk = "natpermute n (k + 1)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1860 |           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 | 1861 |           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 | 1862 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1863 |           have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1864 | have f: "finite ?Pnkn" "finite ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1865 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1866 | by (metis natpermute_finite)+ | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1867 |           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 | 1868 | have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn" | 
| 57418 | 1869 | proof (rule setsum.cong) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1870 |             fix v assume v: "v \<in> {xs \<in> natpermute n (k + 1). n \<in> set xs}"
 | 
| 52903 | 1871 |             let ?ths = "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
 | 
| 1872 | fps_radical r (Suc k) a $ n * r (Suc k) (a $ 0) ^ k" | |
| 1873 |             from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
 | |
| 1874 | unfolding natpermute_contain_maximal by auto | |
| 1875 |             have "(\<Prod>j\<in>{0..k}. fps_radical r (Suc k) a $ v ! j) =
 | |
| 1876 |                 (\<Prod>j\<in>{0..k}. if j = i then fps_radical r (Suc k) a $ n else r (Suc k) (a$0))"
 | |
| 57418 | 1877 | apply (rule setprod.cong, simp) | 
| 53196 | 1878 | using i r0 | 
| 1879 | apply (simp del: replicate.simps) | |
| 52903 | 1880 | done | 
| 1881 | also have "\<dots> = (fps_radical r (Suc k) a $ n) * r (Suc k) (a$0) ^ k" | |
| 1882 | using i r0 by (simp add: setprod_gen_delta) | |
| 1883 | finally show ?ths . | |
| 57418 | 1884 | qed rule | 
| 52903 | 1885 | then have "setsum ?f ?Pnkn = of_nat (k+1) * ?r $ n * r (Suc k) (a $ 0) ^ k" | 
| 1886 | by (simp add: natpermute_max_card[OF nz, simplified]) | |
| 1887 | also have "\<dots> = a$n - setsum ?f ?Pnknn" | |
| 1888 | unfolding n1 using r00 a0 by (simp add: field_simps fps_radical_def del: of_nat_Suc) | |
| 1889 | finally have fn: "setsum ?f ?Pnkn = a$n - setsum ?f ?Pnknn" . | |
| 1890 | have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn" | |
| 57418 | 1891 | unfolding fps_power_nth_Suc setsum.union_disjoint[OF f d, unfolded eq] .. | 
| 52903 | 1892 | also have "\<dots> = a$n" unfolding fn by simp | 
| 1893 | finally have "?r ^ Suc k $ n = a $n" . | |
| 1894 | } | |
| 1895 | ultimately show "?r ^ Suc k $ n = a $n" by (cases n) auto | |
| 1896 | qed | |
| 1897 | } | |
| 1898 | then have ?thesis using r0 by (simp add: fps_eq_iff) | |
| 1899 | } | |
| 1900 | moreover | |
| 1901 |   {
 | |
| 1902 | assume h: "(fps_radical r (Suc k) a) ^ (Suc k) = a" | |
| 54452 | 1903 | then have "((fps_radical r (Suc k) a) ^ (Suc k))$0 = a$0" by simp | 
| 52903 | 1904 | then have "(r (Suc k) (a$0)) ^ Suc k = a$0" | 
| 1905 | unfolding fps_power_nth_Suc | |
| 1906 | by (simp add: setprod_constant del: replicate.simps) | |
| 1907 | } | |
| 1908 | ultimately show ?thesis by blast | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1909 | qed | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1910 | |
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1911 | (* | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1912 | lemma power_radical: | 
| 31273 | 1913 | fixes a:: "'a::field_char_0 fps" | 
| 29687 | 1914 | assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" and a0: "a$0 \<noteq> 0" | 
| 30488 | 1915 | shows "(fps_radical r (Suc k) a) ^ (Suc k) = a" | 
| 29687 | 1916 | proof- | 
| 1917 | let ?r = "fps_radical r (Suc k) a" | |
| 1918 | from a0 r0 have r00: "r (Suc k) (a$0) \<noteq> 0" by auto | |
| 1919 |   {fix z have "?r ^ Suc k $ z = a$z"
 | |
| 1920 | proof(induct z rule: nat_less_induct) | |
| 1921 | fix n assume H: "\<forall>m<n. ?r ^ Suc k $ m = a$m" | |
| 54452 | 1922 |       {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 | 1923 | using fps_radical_power_nth[of r "Suc k" a, OF r0] by simp} | 
| 29687 | 1924 | moreover | 
| 1925 |       {fix n1 assume n1: "n = Suc n1"
 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1926 |         have fK: "finite {0..k}" by simp
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1927 | 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 | 1928 | let ?Pnk = "natpermute n (k + 1)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1929 |         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 | 1930 |         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 | 1931 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1932 |         have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1933 | have f: "finite ?Pnkn" "finite ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1934 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1935 | by (metis natpermute_finite)+ | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1936 |         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 | 1937 | have "setsum ?f ?Pnkn = setsum (\<lambda>v. ?r $ n * r (Suc k) (a $ 0) ^ k) ?Pnkn" | 
| 57418 | 1938 | proof(rule setsum.cong2) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1939 |           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 | 1940 |           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 | 1941 |           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 | 1942 | unfolding natpermute_contain_maximal by auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1943 |           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 | 1944 | apply (rule setprod.cong, simp) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1945 | using i r0 by (simp del: replicate.simps) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1946 | 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 | 1947 | 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 | 1948 | finally show ?ths . | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1949 | qed | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1950 | 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 | 1951 | 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 | 1952 | also have "\<dots> = a$n - setsum ?f ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1953 | 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 | 1954 | 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 | 1955 | have "(?r ^ Suc k)$n = setsum ?f ?Pnkn + setsum ?f ?Pnknn" | 
| 57418 | 1956 | 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 | 1957 | 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 | 1958 | finally have "?r ^ Suc k $ n = a $n" .} | 
| 29687 | 1959 | ultimately show "?r ^ Suc k $ n = a $n" by (cases n, auto) | 
| 1960 | qed } | |
| 1961 | then show ?thesis by (simp add: fps_eq_iff) | |
| 1962 | qed | |
| 1963 | ||
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 1964 | *) | 
| 52903 | 1965 | lemma eq_divide_imp': | 
| 56480 
093ea91498e6
field_simps: better support for negation and division, and power
 hoelzl parents: 
56479diff
changeset | 1966 | fixes c :: "'a::field" shows "c \<noteq> 0 \<Longrightarrow> a * c = b \<Longrightarrow> a = b / c" | 
| 
093ea91498e6
field_simps: better support for negation and division, and power
 hoelzl parents: 
56479diff
changeset | 1967 | by (simp add: field_simps) | 
| 29687 | 1968 | |
| 30488 | 1969 | lemma radical_unique: | 
| 1970 | assumes r0: "(r (Suc k) (b$0)) ^ Suc k = b$0" | |
| 52903 | 1971 | and a0: "r (Suc k) (b$0 ::'a::field_char_0) = a$0" | 
| 1972 | and b0: "b$0 \<noteq> 0" | |
| 29687 | 1973 | shows "a^(Suc k) = b \<longleftrightarrow> a = fps_radical r (Suc k) b" | 
| 53196 | 1974 | proof - | 
| 29687 | 1975 | let ?r = "fps_radical r (Suc k) b" | 
| 1976 | have r00: "r (Suc k) (b$0) \<noteq> 0" using b0 r0 by auto | |
| 52903 | 1977 |   {
 | 
| 1978 | assume H: "a = ?r" | |
| 1979 | from H have "a^Suc k = b" | |
| 1980 | using power_radical[OF b0, of r k, unfolded r0] by simp | |
| 1981 | } | |
| 29687 | 1982 | moreover | 
| 52903 | 1983 |   {
 | 
| 1984 | assume H: "a^Suc k = b" | |
| 29687 | 1985 |     have ceq: "card {0..k} = Suc k" by simp
 | 
| 1986 | from a0 have a0r0: "a$0 = ?r$0" by simp | |
| 52903 | 1987 |     {
 | 
| 1988 | fix n | |
| 1989 | have "a $ n = ?r $ n" | |
| 1990 | proof (induct n rule: nat_less_induct) | |
| 1991 | fix n | |
| 1992 | assume h: "\<forall>m<n. a$m = ?r $m" | |
| 1993 |         {
 | |
| 1994 | assume "n = 0" | |
| 54452 | 1995 | then have "a$n = ?r $n" using a0 by simp | 
| 52903 | 1996 | } | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 1997 | moreover | 
| 52903 | 1998 |         {
 | 
| 1999 | fix n1 | |
| 2000 | assume n1: "n = Suc n1" | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2001 |           have fK: "finite {0..k}" by simp
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2002 | 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 | 2003 | let ?Pnk = "natpermute n (Suc k)" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2004 |         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 | 2005 |         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 | 2006 | have eq: "?Pnkn \<union> ?Pnknn = ?Pnk" by blast | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2007 |         have d: "?Pnkn \<inter> ?Pnknn = {}" by blast
 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2008 | have f: "finite ?Pnkn" "finite ?Pnknn" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2009 | using finite_Un[of ?Pnkn ?Pnknn, unfolded eq] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2010 | by (metis natpermute_finite)+ | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2011 |         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 | 2012 |         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 | 2013 | have "setsum ?g ?Pnkn = setsum (\<lambda>v. a $ n * (?r$0)^k) ?Pnkn" | 
| 57418 | 2014 | proof (rule setsum.cong) | 
| 52903 | 2015 | fix v | 
| 2016 |           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 | 2017 |           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 | 2018 |           from v obtain i where i: "i \<in> {0..k}" "v = replicate (k+1) 0 [i:= n]"
 | 
| 52903 | 2019 | unfolding Suc_eq_plus1 natpermute_contain_maximal | 
| 2020 | by (auto simp del: replicate.simps) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2021 |           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 | 2022 | apply (rule setprod.cong, simp) | 
| 54452 | 2023 | using i a0 | 
| 2024 | apply (simp del: replicate.simps) | |
| 52903 | 2025 | done | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2026 | also have "\<dots> = a $ n * (?r $ 0)^k" | 
| 46757 | 2027 | 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 | 2028 | finally show ?ths . | 
| 57418 | 2029 | qed rule | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2030 | 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 | 2031 | 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 | 2032 | have th1: "setsum ?g ?Pnknn = setsum ?f ?Pnknn" | 
| 57418 | 2033 | proof (rule setsum.cong, rule refl, rule setprod.cong, simp) | 
| 52903 | 2034 | fix xs i | 
| 2035 |           assume xs: "xs \<in> ?Pnknn" and i: "i \<in> {0..k}"
 | |
| 2036 |           {
 | |
| 2037 | assume c: "n \<le> xs ! i" | |
| 2038 | from xs i have "xs !i \<noteq> n" | |
| 2039 | 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 | 2040 | with c have c': "n < xs!i" by arith | 
| 52903 | 2041 |             have fths: "finite {0 ..< i}" "finite {i}" "finite {i+1..<Suc k}"
 | 
| 2042 | by simp_all | |
| 2043 |             have d: "{0 ..< i} \<inter> ({i} \<union> {i+1 ..< Suc k}) = {}" "{i} \<inter> {i+1..< Suc k} = {}"
 | |
| 2044 | by auto | |
| 2045 |             have eqs: "{0..<Suc k} = {0 ..< i} \<union> ({i} \<union> {i+1 ..< Suc k})"
 | |
| 2046 | using i by auto | |
| 2047 | from xs have "n = listsum xs" | |
| 2048 | by (simp add: natpermute_def) | |
| 2049 |             also have "\<dots> = setsum (nth xs) {0..<Suc k}"
 | |
| 2050 | 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 | 2051 |             also have "\<dots> = xs!i + setsum (nth xs) {0..<i} + setsum (nth xs) {i+1..<Suc k}"
 | 
| 57418 | 2052 | unfolding eqs setsum.union_disjoint[OF fths(1) finite_UnI[OF fths(2,3)] d(1)] | 
| 2053 | 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 | 2054 | by simp | 
| 52903 | 2055 | finally have False using c' by simp | 
| 2056 | } | |
| 52902 | 2057 | then have thn: "xs!i < n" by presburger | 
| 52903 | 2058 | 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 | 2059 | qed | 
| 54681 | 2060 | have th00: "\<And>x::'a. of_nat (Suc k) * (x * inverse (of_nat (Suc k))) = x" | 
| 36350 | 2061 | by (simp add: field_simps del: of_nat_Suc) | 
| 52903 | 2062 | from H have "b$n = a^Suc k $ n" | 
| 2063 | by (simp add: fps_eq_iff) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2064 | 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 | 2065 | unfolding fps_power_nth_Suc | 
| 57418 | 2066 | 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 | 2067 | unfolded eq, of ?g] by simp | 
| 52903 | 2068 | also have "\<dots> = of_nat (k+1) * a $ n * (?r $ 0)^k + setsum ?f ?Pnknn" | 
| 2069 | unfolding th0 th1 .. | |
| 2070 | finally have "of_nat (k+1) * a $ n * (?r $ 0)^k = b$n - setsum ?f ?Pnknn" | |
| 2071 | by simp | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2072 | 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 | 2073 | apply - | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2074 | apply (rule eq_divide_imp') | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2075 | using r00 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2076 | apply (simp del: of_nat_Suc) | 
| 57514 
bdc2c6b40bf2
prefer ac_simps collections over separate name bindings for add and mult
 haftmann parents: 
57512diff
changeset | 2077 | apply (simp add: ac_simps) | 
| 52903 | 2078 | done | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2079 | then have "a$n = ?r $n" | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2080 | apply (simp del: of_nat_Suc) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2081 | unfolding fps_radical_def n1 | 
| 52903 | 2082 | apply (simp add: field_simps n1 th00 del: of_nat_Suc) | 
| 2083 | done | |
| 2084 | } | |
| 2085 | ultimately show "a$n = ?r $ n" by (cases n) auto | |
| 2086 | qed | |
| 2087 | } | |
| 52902 | 2088 | then have "a = ?r" by (simp add: fps_eq_iff) | 
| 2089 | } | |
| 29687 | 2090 | ultimately show ?thesis by blast | 
| 2091 | qed | |
| 2092 | ||
| 2093 | ||
| 30488 | 2094 | lemma radical_power: | 
| 2095 | assumes r0: "r (Suc k) ((a$0) ^ Suc k) = a$0" | |
| 54681 | 2096 | and a0: "(a$0 :: 'a::field_char_0) \<noteq> 0" | 
| 29687 | 2097 | shows "(fps_radical r (Suc k) (a ^ Suc k)) = a" | 
| 52903 | 2098 | proof - | 
| 29687 | 2099 | let ?ak = "a^ Suc k" | 
| 52903 | 2100 | have ak0: "?ak $ 0 = (a$0) ^ Suc k" | 
| 2101 | by (simp add: fps_nth_power_0 del: power_Suc) | |
| 2102 | from r0 have th0: "r (Suc k) (a ^ Suc k $ 0) ^ Suc k = a ^ Suc k $ 0" | |
| 2103 | using ak0 by auto | |
| 2104 | from r0 ak0 have th1: "r (Suc k) (a ^ Suc k $ 0) = a $ 0" | |
| 2105 | by auto | |
| 2106 | from ak0 a0 have ak00: "?ak $ 0 \<noteq>0 " | |
| 2107 | by auto | |
| 2108 | from radical_unique[of r k ?ak a, OF th0 th1 ak00] show ?thesis | |
| 2109 | by metis | |
| 29687 | 2110 | qed | 
| 2111 | ||
| 30488 | 2112 | lemma fps_deriv_radical: | 
| 54681 | 2113 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2114 | assumes r0: "(r (Suc k) (a$0)) ^ Suc k = a$0" | 
| 2115 | and a0: "a$0 \<noteq> 0" | |
| 53196 | 2116 | shows "fps_deriv (fps_radical r (Suc k) a) = | 
| 2117 | fps_deriv a / (fps_const (of_nat (Suc k)) * (fps_radical r (Suc k) a) ^ k)" | |
| 52903 | 2118 | proof - | 
| 2119 | let ?r = "fps_radical r (Suc k) a" | |
| 29687 | 2120 | let ?w = "(fps_const (of_nat (Suc k)) * ?r ^ k)" | 
| 52903 | 2121 | from a0 r0 have r0': "r (Suc k) (a$0) \<noteq> 0" | 
| 2122 | by auto | |
| 2123 | from r0' have w0: "?w $ 0 \<noteq> 0" | |
| 2124 | by (simp del: of_nat_Suc) | |
| 29687 | 2125 | note th0 = inverse_mult_eq_1[OF w0] | 
| 2126 | let ?iw = "inverse ?w" | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2127 | from iffD1[OF power_radical[of a r], OF a0 r0] | 
| 52903 | 2128 | have "fps_deriv (?r ^ Suc k) = fps_deriv a" | 
| 2129 | by simp | |
| 54452 | 2130 | 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 | 2131 | by (simp add: fps_deriv_power ac_simps del: power_Suc) | 
| 54452 | 2132 | then have "?iw * fps_deriv ?r * ?w = ?iw * fps_deriv a" | 
| 52903 | 2133 | by simp | 
| 54452 | 2134 | then have "fps_deriv ?r * (?iw * ?w) = fps_deriv a / ?w" | 
| 29687 | 2135 | by (simp add: fps_divide_def) | 
| 30488 | 2136 | then show ?thesis unfolding th0 by simp | 
| 29687 | 2137 | qed | 
| 2138 | ||
| 30488 | 2139 | lemma radical_mult_distrib: | 
| 54681 | 2140 | fixes a :: "'a::field_char_0 fps" | 
| 48757 | 2141 | assumes k: "k > 0" | 
| 2142 | and ra0: "r k (a $ 0) ^ k = a $ 0" | |
| 2143 | and rb0: "r k (b $ 0) ^ k = b $ 0" | |
| 2144 | and a0: "a$0 \<noteq> 0" | |
| 2145 | and b0: "b$0 \<noteq> 0" | |
| 2146 | shows "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0) \<longleftrightarrow> | |
| 2147 | fps_radical r (k) (a*b) = fps_radical r (k) a * fps_radical r (k) (b)" | |
| 52903 | 2148 | proof - | 
| 2149 |   {
 | |
| 2150 | assume r0': "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)" | |
| 2151 | from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0" | |
| 2152 | by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib) | |
| 2153 |     {
 | |
| 2154 | assume "k = 0" | |
| 54452 | 2155 | then have ?thesis using r0' by simp | 
| 52903 | 2156 | } | 
| 2157 | moreover | |
| 2158 |     {
 | |
| 2159 | fix h assume k: "k = Suc h" | |
| 2160 | let ?ra = "fps_radical r (Suc h) a" | |
| 2161 | let ?rb = "fps_radical r (Suc h) b" | |
| 2162 | have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0" | |
| 2163 | using r0' k by (simp add: fps_mult_nth) | |
| 2164 | have ab0: "(a*b) $ 0 \<noteq> 0" | |
| 2165 | using a0 b0 by (simp add: fps_mult_nth) | |
| 2166 | 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] | |
| 2167 | iffD1[OF power_radical[of _ r], OF a0 ra0[unfolded k]] iffD1[OF power_radical[of _ r], OF b0 rb0[unfolded k]] k r0' | |
| 2168 | have ?thesis by (auto simp add: power_mult_distrib simp del: power_Suc) | |
| 2169 | } | |
| 2170 | ultimately have ?thesis by (cases k) auto | |
| 2171 | } | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2172 | moreover | 
| 52903 | 2173 |   {
 | 
| 2174 | assume h: "fps_radical r k (a*b) = fps_radical r k a * fps_radical r k b" | |
| 54452 | 2175 | then have "(fps_radical r k (a*b))$0 = (fps_radical r k a * fps_radical r k b)$0" | 
| 52903 | 2176 | by simp | 
| 2177 | then have "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)" | |
| 2178 | using k by (simp add: fps_mult_nth) | |
| 2179 | } | |
| 2180 | ultimately show ?thesis by blast | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2181 | qed | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2182 | |
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2183 | (* | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2184 | lemma radical_mult_distrib: | 
| 31273 | 2185 | fixes a:: "'a::field_char_0 fps" | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2186 | assumes | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2187 | ra0: "r k (a $ 0) ^ k = a $ 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2188 | and rb0: "r k (b $ 0) ^ k = b $ 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2189 | and r0': "r k ((a * b) $ 0) = r k (a $ 0) * r k (b $ 0)" | 
| 29687 | 2190 | and a0: "a$0 \<noteq> 0" | 
| 2191 | and b0: "b$0 \<noteq> 0" | |
| 2192 | shows "fps_radical r (k) (a*b) = fps_radical r (k) a * fps_radical r (k) (b)" | |
| 2193 | proof- | |
| 2194 | from r0' have r0: "(r (k) ((a*b)$0)) ^ k = (a*b)$0" | |
| 2195 | by (simp add: fps_mult_nth ra0 rb0 power_mult_distrib) | |
| 54452 | 2196 |   {assume "k=0" then have ?thesis by simp}
 | 
| 29687 | 2197 | moreover | 
| 2198 |   {fix h assume k: "k = Suc h"
 | |
| 2199 | let ?ra = "fps_radical r (Suc h) a" | |
| 2200 | let ?rb = "fps_radical r (Suc h) b" | |
| 30488 | 2201 | have th0: "r (Suc h) ((a * b) $ 0) = (fps_radical r (Suc h) a * fps_radical r (Suc h) b) $ 0" | 
| 29687 | 2202 | using r0' k by (simp add: fps_mult_nth) | 
| 2203 | have ab0: "(a*b) $ 0 \<noteq> 0" using a0 b0 by (simp add: fps_mult_nth) | |
| 30488 | 2204 | 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 | 2205 | 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 | 2206 | have ?thesis by (auto simp add: power_mult_distrib simp del: power_Suc)} | 
| 29687 | 2207 | ultimately show ?thesis by (cases k, auto) | 
| 2208 | qed | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2209 | *) | 
| 29687 | 2210 | |
| 54681 | 2211 | lemma fps_divide_1[simp]: "(a :: 'a::field fps) / 1 = a" | 
| 29687 | 2212 | by (simp add: fps_divide_def) | 
| 2213 | ||
| 2214 | lemma radical_divide: | |
| 31273 | 2215 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2216 | assumes kp: "k > 0" | 
| 2217 | and ra0: "(r k (a $ 0)) ^ k = a $ 0" | |
| 2218 | and rb0: "(r k (b $ 0)) ^ k = b $ 0" | |
| 2219 | and a0: "a$0 \<noteq> 0" | |
| 2220 | and b0: "b$0 \<noteq> 0" | |
| 2221 | shows "r k ((a $ 0) / (b$0)) = r k (a$0) / r k (b $ 0) \<longleftrightarrow> | |
| 2222 | fps_radical r k (a/b) = fps_radical r k a / fps_radical r k b" | |
| 2223 | (is "?lhs = ?rhs") | |
| 2224 | proof - | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2225 | let ?r = "fps_radical r k" | 
| 52903 | 2226 | from kp obtain h where k: "k = Suc h" by (cases k) auto | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2227 | 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 | 2228 | have rb0': "r k (b$0) \<noteq> 0" using b0 rb0 k by auto | 
| 30488 | 2229 | |
| 52902 | 2230 |   {
 | 
| 2231 | assume ?rhs | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2232 | then have "?r (a/b) $ 0 = (?r a / ?r b)$0" by simp | 
| 52891 | 2233 | then have ?lhs using k a0 b0 rb0' | 
| 52902 | 2234 | by (simp add: fps_divide_def fps_mult_nth fps_inverse_def divide_inverse) | 
| 2235 | } | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2236 | moreover | 
| 52902 | 2237 |   {
 | 
| 2238 | assume h: ?lhs | |
| 52891 | 2239 | 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 | 2240 | 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 | 2241 | have th0: "r k ((a/b)$0) ^ k = (a/b)$0" | 
| 52902 | 2242 | by (simp add: h nonzero_power_divide[OF rb0'] ra0 rb0) | 
| 52891 | 2243 | from a0 b0 ra0' rb0' kp h | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2244 | have th1: "r k ((a / b) $ 0) = (fps_radical r k a / fps_radical r k b) $ 0" | 
| 52902 | 2245 | by (simp add: fps_divide_def fps_mult_nth fps_inverse_def divide_inverse) | 
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2246 | from a0 b0 ra0' rb0' kp have ab0': "(a / b) $ 0 \<noteq> 0" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2247 | by (simp add: fps_divide_def fps_mult_nth fps_inverse_def nonzero_imp_inverse_nonzero) | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2248 | 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 | 2249 | note thb[simp] = iffD1[OF power_radical[where r=r and k=h], OF b0 rb0[unfolded k], unfolded k[symmetric]] | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2250 | have th2: "(?r a / ?r b)^k = a/b" | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2251 | by (simp add: fps_divide_def power_mult_distrib fps_inverse_power[symmetric]) | 
| 52902 | 2252 | 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] | 
| 2253 | have ?rhs . | |
| 2254 | } | |
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2255 | ultimately show ?thesis by blast | 
| 29687 | 2256 | qed | 
| 2257 | ||
| 31073 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2258 | lemma radical_inverse: | 
| 31273 | 2259 | fixes a :: "'a::field_char_0 fps" | 
| 52903 | 2260 | assumes k: "k > 0" | 
| 2261 | and ra0: "r k (a $ 0) ^ k = a $ 0" | |
| 2262 | and r1: "(r k 1)^k = 1" | |
| 2263 | and a0: "a$0 \<noteq> 0" | |
| 53196 | 2264 | shows "r k (inverse (a $ 0)) = r k 1 / (r k (a $ 0)) \<longleftrightarrow> | 
| 2265 | 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 | 2266 | 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 | 2267 | by (simp add: divide_inverse fps_divide_def) | 
| 
4b44c4d08aa6
Generalized distributivity theorems of radicals over multiplication, division and inverses
 chaieb parents: 
31021diff
changeset | 2268 | |
| 29906 | 2269 | subsection{* Derivative of composition *}
 | 
| 29687 | 2270 | |
| 30488 | 2271 | lemma fps_compose_deriv: | 
| 54681 | 2272 | fixes a :: "'a::idom fps" | 
| 29687 | 2273 | assumes b0: "b$0 = 0" | 
| 54681 | 2274 | shows "fps_deriv (a oo b) = ((fps_deriv a) oo b) * fps_deriv b" | 
| 52903 | 2275 | proof - | 
| 2276 |   {
 | |
| 2277 | fix n | |
| 29687 | 2278 |     have "(fps_deriv (a oo b))$n = setsum (\<lambda>i. a $ i * (fps_deriv (b^i))$n) {0.. Suc n}"
 | 
| 36350 | 2279 | by (simp add: fps_compose_def field_simps setsum_right_distrib del: of_nat_Suc) | 
| 29687 | 2280 |     also have "\<dots> = setsum (\<lambda>i. a$i * ((fps_const (of_nat i)) * (fps_deriv b * (b^(i - 1))))$n) {0.. Suc n}"
 | 
| 36350 | 2281 | by (simp add: field_simps fps_deriv_power del: fps_mult_left_const_nth of_nat_Suc) | 
| 52903 | 2282 |     also have "\<dots> = setsum (\<lambda>i. of_nat i * a$i * (((b^(i - 1)) * fps_deriv b))$n) {0.. Suc n}"
 | 
| 2283 | unfolding fps_mult_left_const_nth by (simp add: field_simps) | |
| 2284 |     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}"
 | |
| 2285 | unfolding fps_mult_nth .. | |
| 2286 |     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 | 2287 | apply (rule setsum.mono_neutral_right) | 
| 2288 | apply (auto simp add: mult_delta_left setsum.delta not_le) | |
| 52903 | 2289 | done | 
| 2290 |     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}"
 | |
| 2291 | unfolding fps_deriv_nth | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2292 | by (rule setsum.reindex_cong [of Suc]) (auto simp add: mult.assoc) | 
| 52903 | 2293 | finally have th0: "(fps_deriv (a oo b))$n = | 
| 2294 |       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}" .
 | |
| 2295 | ||
| 2296 |     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 | 2297 | unfolding fps_mult_nth by (simp add: ac_simps) | 
| 52903 | 2298 |     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 | 2299 | unfolding fps_deriv_nth fps_compose_nth setsum_right_distrib mult.assoc | 
| 57418 | 2300 | apply (rule setsum.cong) | 
| 2301 | apply (rule refl) | |
| 2302 | apply (rule setsum.mono_neutral_left) | |
| 52903 | 2303 | apply (simp_all add: subset_eq) | 
| 2304 | apply clarify | |
| 2305 | apply (subgoal_tac "b^i$x = 0") | |
| 2306 | apply simp | |
| 2307 | apply (rule startsby_zero_power_prefix[OF b0, rule_format]) | |
| 2308 | apply simp | |
| 2309 | done | |
| 2310 |     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}"
 | |
| 2311 | unfolding setsum_right_distrib | |
| 57418 | 2312 | apply (subst setsum.commute) | 
| 2313 | apply (rule setsum.cong, rule refl)+ | |
| 52903 | 2314 | apply simp | 
| 2315 | done | |
| 2316 | finally have "(fps_deriv (a oo b))$n = (((fps_deriv a) oo b) * (fps_deriv b)) $n" | |
| 2317 | unfolding th0 by simp | |
| 2318 | } | |
| 2319 | then show ?thesis by (simp add: fps_eq_iff) | |
| 29687 | 2320 | qed | 
| 2321 | ||
| 2322 | lemma fps_mult_X_plus_1_nth: | |
| 2323 | "((1+X)*a) $n = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))" | |
| 52903 | 2324 | proof (cases n) | 
| 2325 | case 0 | |
| 54681 | 2326 | then show ?thesis | 
| 2327 | by (simp add: fps_mult_nth ) | |
| 52903 | 2328 | next | 
| 2329 | case (Suc m) | |
| 2330 |   have "((1+X)*a) $n = setsum (\<lambda>i. (1+X)$i * a$(n-i)) {0..n}"
 | |
| 2331 | by (simp add: fps_mult_nth) | |
| 2332 |   also have "\<dots> = setsum (\<lambda>i. (1+X)$i * a$(n-i)) {0.. 1}"
 | |
| 57418 | 2333 | unfolding Suc by (rule setsum.mono_neutral_right) auto | 
| 52903 | 2334 | also have "\<dots> = (if n = 0 then (a$n :: 'a::comm_ring_1) else a$n + a$(n - 1))" | 
| 2335 | by (simp add: Suc) | |
| 2336 | finally show ?thesis . | |
| 29687 | 2337 | qed | 
| 2338 | ||
| 54681 | 2339 | |
| 2340 | subsection {* Finite FPS (i.e. polynomials) and X *}
 | |
| 52903 | 2341 | |
| 29687 | 2342 | lemma fps_poly_sum_X: | 
| 30488 | 2343 | assumes z: "\<forall>i > n. a$i = (0::'a::comm_ring_1)" | 
| 29687 | 2344 |   shows "a = setsum (\<lambda>i. fps_const (a$i) * X^i) {0..n}" (is "a = ?r")
 | 
| 52903 | 2345 | proof - | 
| 2346 |   {
 | |
| 2347 | fix i | |
| 30488 | 2348 | have "a$i = ?r$i" | 
| 29687 | 2349 | unfolding fps_setsum_nth fps_mult_left_const_nth X_power_nth | 
| 57418 | 2350 | by (simp add: mult_delta_right setsum.delta' z) | 
| 29913 | 2351 | } | 
| 29687 | 2352 | then show ?thesis unfolding fps_eq_iff by blast | 
| 2353 | qed | |
| 2354 | ||
| 52903 | 2355 | |
| 29906 | 2356 | subsection{* Compositional inverses *}
 | 
| 29687 | 2357 | |
| 54681 | 2358 | fun compinv :: "'a fps \<Rightarrow> nat \<Rightarrow> 'a::field" | 
| 52903 | 2359 | where | 
| 29687 | 2360 | "compinv a 0 = X$0" | 
| 52903 | 2361 | | "compinv a (Suc n) = | 
| 2362 |     (X$ Suc n - setsum (\<lambda>i. (compinv a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
 | |
| 29687 | 2363 | |
| 2364 | definition "fps_inv a = Abs_fps (compinv a)" | |
| 2365 | ||
| 52903 | 2366 | lemma fps_inv: | 
| 2367 | assumes a0: "a$0 = 0" | |
| 2368 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 2369 | shows "fps_inv a oo a = X" | 
| 52903 | 2370 | proof - | 
| 29687 | 2371 | let ?i = "fps_inv a oo a" | 
| 52903 | 2372 |   {
 | 
| 2373 | fix n | |
| 30488 | 2374 | have "?i $n = X$n" | 
| 52903 | 2375 | proof (induct n rule: nat_less_induct) | 
| 2376 | fix n | |
| 2377 | assume h: "\<forall>m<n. ?i$m = X$m" | |
| 2378 | show "?i $ n = X$n" | |
| 2379 | proof (cases n) | |
| 2380 | case 0 | |
| 2381 | then show ?thesis using a0 | |
| 2382 | by (simp add: fps_compose_nth fps_inv_def) | |
| 2383 | next | |
| 2384 | case (Suc n1) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2385 |         have "?i $ n = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} + fps_inv a $ Suc n1 * (a $ 1)^ Suc n1"
 | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2386 | by (simp only: fps_compose_nth) (simp add: Suc startsby_zero_power_nth_same [OF a0] del: power_Suc) | 
| 52903 | 2387 |         also have "\<dots> = setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1} +
 | 
| 2388 |           (X$ Suc n1 - setsum (\<lambda>i. (fps_inv a $ i) * (a^i)$n) {0 .. n1})"
 | |
| 2389 | using a0 a1 Suc by (simp add: fps_inv_def) | |
| 2390 | also have "\<dots> = X$n" using Suc by simp | |
| 2391 | finally show ?thesis . | |
| 2392 | qed | |
| 2393 | qed | |
| 2394 | } | |
| 29687 | 2395 | then show ?thesis by (simp add: fps_eq_iff) | 
| 2396 | qed | |
| 2397 | ||
| 2398 | ||
| 54681 | 2399 | fun gcompinv :: "'a fps \<Rightarrow> 'a fps \<Rightarrow> nat \<Rightarrow> 'a::field" | 
| 52903 | 2400 | where | 
| 29687 | 2401 | "gcompinv b a 0 = b$0" | 
| 52903 | 2402 | | "gcompinv b a (Suc n) = | 
| 2403 |     (b$ Suc n - setsum (\<lambda>i. (gcompinv b a i) * (a^i)$Suc n) {0 .. n}) / (a$1) ^ Suc n"
 | |
| 29687 | 2404 | |
| 2405 | definition "fps_ginv b a = Abs_fps (gcompinv b a)" | |
| 2406 | ||
| 52903 | 2407 | lemma fps_ginv: | 
| 2408 | assumes a0: "a$0 = 0" | |
| 2409 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 2410 | shows "fps_ginv b a oo a = b" | 
| 52903 | 2411 | proof - | 
| 29687 | 2412 | let ?i = "fps_ginv b a oo a" | 
| 52903 | 2413 |   {
 | 
| 2414 | fix n | |
| 30488 | 2415 | have "?i $n = b$n" | 
| 52903 | 2416 | proof (induct n rule: nat_less_induct) | 
| 2417 | fix n | |
| 2418 | assume h: "\<forall>m<n. ?i$m = b$m" | |
| 2419 | show "?i $ n = b$n" | |
| 2420 | proof (cases n) | |
| 2421 | case 0 | |
| 2422 | then show ?thesis using a0 | |
| 2423 | by (simp add: fps_compose_nth fps_ginv_def) | |
| 2424 | next | |
| 2425 | case (Suc n1) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 2426 |         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"
 | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2427 | by (simp only: fps_compose_nth) (simp add: Suc startsby_zero_power_nth_same [OF a0] del: power_Suc) | 
| 52903 | 2428 |         also have "\<dots> = setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1} +
 | 
| 2429 |           (b$ Suc n1 - setsum (\<lambda>i. (fps_ginv b a $ i) * (a^i)$n) {0 .. n1})"
 | |
| 2430 | using a0 a1 Suc by (simp add: fps_ginv_def) | |
| 2431 | also have "\<dots> = b$n" using Suc by simp | |
| 2432 | finally show ?thesis . | |
| 2433 | qed | |
| 2434 | qed | |
| 2435 | } | |
| 29687 | 2436 | then show ?thesis by (simp add: fps_eq_iff) | 
| 2437 | qed | |
| 2438 | ||
| 2439 | 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 | 2440 | apply (auto simp add: fun_eq_iff fps_eq_iff fps_inv_def fps_ginv_def) | 
| 48757 | 2441 | apply (induct_tac n rule: nat_less_induct) | 
| 2442 | apply auto | |
| 29687 | 2443 | apply (case_tac na) | 
| 2444 | apply simp | |
| 2445 | apply simp | |
| 2446 | done | |
| 2447 | ||
| 2448 | lemma fps_compose_1[simp]: "1 oo a = 1" | |
| 57418 | 2449 | by (simp add: fps_eq_iff fps_compose_nth mult_delta_left setsum.delta) | 
| 29687 | 2450 | |
| 2451 | lemma fps_compose_0[simp]: "0 oo a = 0" | |
| 29913 | 2452 | by (simp add: fps_eq_iff fps_compose_nth) | 
| 29687 | 2453 | |
| 2454 | lemma fps_compose_0_right[simp]: "a oo 0 = fps_const (a$0)" | |
| 57418 | 2455 | by (auto simp add: fps_eq_iff fps_compose_nth power_0_left setsum.neutral) | 
| 29687 | 2456 | |
| 2457 | lemma fps_compose_add_distrib: "(a + b) oo c = (a oo c) + (b oo c)" | |
| 57418 | 2458 | by (simp add: fps_eq_iff fps_compose_nth field_simps setsum.distrib) | 
| 29687 | 2459 | |
| 2460 | lemma fps_compose_setsum_distrib: "(setsum f S) oo a = setsum (\<lambda>i. f i oo a) S" | |
| 52903 | 2461 | proof (cases "finite S") | 
| 2462 | case True | |
| 2463 | show ?thesis | |
| 2464 | proof (rule finite_induct[OF True]) | |
| 2465 |     show "setsum f {} oo a = (\<Sum>i\<in>{}. f i oo a)" by simp
 | |
| 2466 | next | |
| 2467 | fix x F | |
| 2468 | assume fF: "finite F" | |
| 2469 | and xF: "x \<notin> F" | |
| 2470 | and h: "setsum f F oo a = setsum (\<lambda>i. f i oo a) F" | |
| 2471 | show "setsum f (insert x F) oo a = setsum (\<lambda>i. f i oo a) (insert x F)" | |
| 2472 | using fF xF h by (simp add: fps_compose_add_distrib) | |
| 2473 | qed | |
| 2474 | next | |
| 2475 | case False | |
| 2476 | then show ?thesis by simp | |
| 29687 | 2477 | qed | 
| 2478 | ||
| 30488 | 2479 | lemma convolution_eq: | 
| 54452 | 2480 |   "setsum (\<lambda>i. a (i :: nat) * b (n - i)) {0 .. n} =
 | 
| 2481 |     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 | 2482 | by (rule setsum.reindex_bij_witness[where i=fst and j="\<lambda>i. (i, n - i)"]) auto | 
| 29687 | 2483 | |
| 2484 | lemma product_composition_lemma: | |
| 52903 | 2485 | assumes c0: "c$0 = (0::'a::idom)" | 
| 2486 | and d0: "d$0 = 0" | |
| 2487 | shows "((a oo c) * (b oo d))$n = | |
| 54452 | 2488 |     setsum (\<lambda>(k,m). a$k * b$m * (c^k * d^m) $ n) {(k,m). k + m \<le> n}"  (is "?l = ?r")
 | 
| 52903 | 2489 | proof - | 
| 54681 | 2490 |   let ?S = "{(k::nat, m::nat). k + m \<le> n}"
 | 
| 30488 | 2491 |   have s: "?S \<subseteq> {0..n} <*> {0..n}" by (auto simp add: subset_eq)
 | 
| 54681 | 2492 |   have f: "finite {(k::nat, m::nat). k + m \<le> n}"
 | 
| 29687 | 2493 | apply (rule finite_subset[OF s]) | 
| 52903 | 2494 | apply auto | 
| 2495 | done | |
| 54452 | 2496 |   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 | 2497 | apply (simp add: fps_mult_nth setsum_right_distrib) | 
| 57418 | 2498 | apply (subst setsum.commute) | 
| 2499 | apply (rule setsum.cong) | |
| 52903 | 2500 | apply (auto simp add: field_simps) | 
| 2501 | done | |
| 30488 | 2502 | also have "\<dots> = ?l" | 
| 29687 | 2503 | apply (simp add: fps_mult_nth fps_compose_nth setsum_product) | 
| 57418 | 2504 | apply (rule setsum.cong) | 
| 2505 | apply (rule refl) | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2506 | apply (simp add: setsum.cartesian_product mult.assoc) | 
| 57418 | 2507 | apply (rule setsum.mono_neutral_right[OF f]) | 
| 54452 | 2508 | apply (simp add: subset_eq) | 
| 2509 | apply presburger | |
| 29687 | 2510 | apply clarsimp | 
| 2511 | apply (rule ccontr) | |
| 2512 | apply (clarsimp simp add: not_le) | |
| 2513 | apply (case_tac "x < aa") | |
| 2514 | apply simp | |
| 2515 | apply (frule_tac startsby_zero_power_prefix[rule_format, OF c0]) | |
| 2516 | apply blast | |
| 2517 | apply simp | |
| 2518 | apply (frule_tac startsby_zero_power_prefix[rule_format, OF d0]) | |
| 2519 | apply blast | |
| 2520 | done | |
| 2521 | finally show ?thesis by simp | |
| 2522 | qed | |
| 2523 | ||
| 2524 | lemma product_composition_lemma': | |
| 52903 | 2525 | assumes c0: "c$0 = (0::'a::idom)" | 
| 2526 | and d0: "d$0 = 0" | |
| 2527 | shows "((a oo c) * (b oo d))$n = | |
| 54452 | 2528 |     setsum (\<lambda>k. setsum (\<lambda>m. a$k * b$m * (c^k * d^m) $ n) {0..n}) {0..n}"  (is "?l = ?r")
 | 
| 29687 | 2529 | unfolding product_composition_lemma[OF c0 d0] | 
| 57418 | 2530 | unfolding setsum.cartesian_product | 
| 2531 | apply (rule setsum.mono_neutral_left) | |
| 29687 | 2532 | apply simp | 
| 2533 | apply (clarsimp simp add: subset_eq) | |
| 2534 | apply clarsimp | |
| 2535 | apply (rule ccontr) | |
| 2536 | apply (subgoal_tac "(c^aa * d^ba) $ n = 0") | |
| 2537 | apply simp | |
| 2538 | unfolding fps_mult_nth | |
| 57418 | 2539 | apply (rule setsum.neutral) | 
| 29687 | 2540 | apply (clarsimp simp add: not_le) | 
| 51489 | 2541 | apply (case_tac "x < aa") | 
| 29687 | 2542 | apply (rule startsby_zero_power_prefix[OF c0, rule_format]) | 
| 2543 | apply simp | |
| 51489 | 2544 | apply (subgoal_tac "n - x < ba") | 
| 29687 | 2545 | apply (frule_tac k = "ba" in startsby_zero_power_prefix[OF d0, rule_format]) | 
| 2546 | apply simp | |
| 2547 | apply arith | |
| 2548 | done | |
| 30488 | 2549 | |
| 29687 | 2550 | |
| 30488 | 2551 | lemma setsum_pair_less_iff: | 
| 54452 | 2552 |   "setsum (\<lambda>((k::nat),m). a k * b m * c (k + m)) {(k,m). k + m \<le> n} =
 | 
| 2553 |     setsum (\<lambda>s. setsum (\<lambda>i. a i * b (s - i) * c s) {0..s}) {0..n}"
 | |
| 52903 | 2554 | (is "?l = ?r") | 
| 2555 | proof - | |
| 2556 |   let ?KM = "{(k,m). k + m \<le> n}"
 | |
| 54452 | 2557 |   let ?f = "\<lambda>s. UNION {(0::nat)..s} (\<lambda>i. {(i,s - i)})"
 | 
| 29687 | 2558 |   have th0: "?KM = UNION {0..n} ?f"
 | 
| 39302 
d7728f65b353
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
 nipkow parents: 
39198diff
changeset | 2559 | apply (simp add: set_eq_iff) | 
| 52902 | 2560 | apply presburger (* FIXME: slow! *) | 
| 29687 | 2561 | done | 
| 2562 | show "?l = ?r " | |
| 2563 | unfolding th0 | |
| 57418 | 2564 | apply (subst setsum.UNION_disjoint) | 
| 29687 | 2565 | apply auto | 
| 57418 | 2566 | apply (subst setsum.UNION_disjoint) | 
| 29687 | 2567 | apply auto | 
| 2568 | done | |
| 2569 | qed | |
| 2570 | ||
| 2571 | lemma fps_compose_mult_distrib_lemma: | |
| 2572 | assumes c0: "c$0 = (0::'a::idom)" | |
| 52903 | 2573 | shows "((a oo c) * (b oo c))$n = | 
| 54452 | 2574 |     setsum (\<lambda>s. setsum (\<lambda>i. a$i * b$(s - i) * (c^s) $ n) {0..s}) {0..n}"
 | 
| 52903 | 2575 | (is "?l = ?r") | 
| 29687 | 2576 | unfolding product_composition_lemma[OF c0 c0] power_add[symmetric] | 
| 54452 | 2577 | 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 | 2578 | |
| 2579 | ||
| 30488 | 2580 | lemma fps_compose_mult_distrib: | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2581 | assumes c0: "c $ 0 = (0::'a::idom)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2582 | shows "(a * b) oo c = (a oo c) * (b oo c)" | 
| 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2583 | apply (simp add: fps_eq_iff fps_compose_mult_distrib_lemma [OF c0]) | 
| 52903 | 2584 | apply (simp add: fps_compose_nth fps_mult_nth setsum_left_distrib) | 
| 2585 | done | |
| 2586 | ||
| 30488 | 2587 | lemma fps_compose_setprod_distrib: | 
| 29687 | 2588 | assumes c0: "c$0 = (0::'a::idom)" | 
| 54452 | 2589 | shows "setprod a S oo c = setprod (\<lambda>k. a k oo c) S" | 
| 29687 | 2590 | apply (cases "finite S") | 
| 2591 | apply simp_all | |
| 2592 | apply (induct S rule: finite_induct) | |
| 2593 | apply simp | |
| 2594 | apply (simp add: fps_compose_mult_distrib[OF c0]) | |
| 2595 | done | |
| 2596 | ||
| 53195 | 2597 | lemma fps_compose_power: | 
| 2598 | assumes c0: "c$0 = (0::'a::idom)" | |
| 2599 | shows "(a oo c)^n = a^n oo c" | |
| 2600 | (is "?l = ?r") | |
| 52903 | 2601 | proof (cases n) | 
| 2602 | case 0 | |
| 2603 | then show ?thesis by simp | |
| 2604 | next | |
| 2605 | case (Suc m) | |
| 54452 | 2606 |   have th0: "a^n = setprod (\<lambda>k. a) {0..m}" "(a oo c) ^ n = setprod (\<lambda>k. a oo c) {0..m}"
 | 
| 52903 | 2607 | by (simp_all add: setprod_constant Suc) | 
| 2608 | then show ?thesis | |
| 2609 | by (simp add: fps_compose_setprod_distrib[OF c0]) | |
| 29687 | 2610 | qed | 
| 2611 | ||
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2612 | lemma fps_compose_uminus: "- (a::'a::ring_1 fps) oo c = - (a oo c)" | 
| 36350 | 2613 | 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 | 2614 | |
| 52903 | 2615 | 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 | 2616 | 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 | 2617 | |
| 52903 | 2618 | lemma X_fps_compose: "X oo a = Abs_fps (\<lambda>n. if n = 0 then (0::'a::comm_ring_1) else a$n)" | 
| 57418 | 2619 | 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 | 2620 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2621 | lemma fps_inverse_compose: | 
| 52903 | 2622 | assumes b0: "(b$0 :: 'a::field) = 0" | 
| 2623 | 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 | 2624 | shows "inverse a oo b = inverse (a oo b)" | 
| 52903 | 2625 | proof - | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2626 | let ?ia = "inverse a" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2627 | let ?ab = "a oo b" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2628 | let ?iab = "inverse ?ab" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2629 | |
| 52903 | 2630 | from a0 have ia0: "?ia $ 0 \<noteq> 0" by simp | 
| 2631 | from a0 have ab0: "?ab $ 0 \<noteq> 0" by (simp add: fps_compose_def) | |
| 2632 | have "(?ia oo b) * (a oo b) = 1" | |
| 2633 | unfolding fps_compose_mult_distrib[OF b0, symmetric] | |
| 2634 | unfolding inverse_mult_eq_1[OF a0] | |
| 2635 | fps_compose_1 .. | |
| 54452 | 2636 | |
| 52903 | 2637 | then have "(?ia oo b) * (a oo b) * ?iab = 1 * ?iab" by simp | 
| 2638 | then have "(?ia oo b) * (?iab * (a oo b)) = ?iab" by simp | |
| 2639 | 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 | 2640 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2641 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2642 | lemma fps_divide_compose: | 
| 52903 | 2643 | assumes c0: "(c$0 :: 'a::field) = 0" | 
| 2644 | 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 | 2645 | shows "(a/b) oo c = (a oo c) / (b oo c)" | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2646 | unfolding fps_divide_def fps_compose_mult_distrib[OF c0] | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2647 | fps_inverse_compose[OF c0 b0] .. | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2648 | |
| 52903 | 2649 | lemma gp: | 
| 2650 | assumes a0: "a$0 = (0::'a::field)" | |
| 2651 | shows "(Abs_fps (\<lambda>n. 1)) oo a = 1/(1 - a)" | |
| 2652 | (is "?one oo a = _") | |
| 2653 | proof - | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2654 | have o0: "?one $ 0 \<noteq> 0" by simp | 
| 52891 | 2655 | 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 | 2656 | 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 | 2657 | have "inverse ?one = 1 - X" by (simp add: fps_eq_iff) | 
| 54452 | 2658 | then have "inverse (inverse ?one) = inverse (1 - X)" by simp | 
| 2659 | 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 | 2660 | by (simp add: fps_divide_def) | 
| 52903 | 2661 | show ?thesis | 
| 2662 | unfolding th | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2663 | 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 | 2664 | 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 | 2665 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2666 | |
| 52903 | 2667 | lemma fps_const_power [simp]: "fps_const (c::'a::ring_1) ^ n = fps_const (c^n)" | 
| 48757 | 2668 | by (induct n) auto | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2669 | |
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2670 | lemma fps_compose_radical: | 
| 31273 | 2671 | assumes b0: "b$0 = (0::'a::field_char_0)" | 
| 52903 | 2672 | and ra0: "r (Suc k) (a$0) ^ Suc k = a$0" | 
| 2673 | 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 | 2674 | shows "fps_radical r (Suc k) a oo b = fps_radical r (Suc k) (a oo b)" | 
| 52903 | 2675 | proof - | 
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2676 | 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 | 2677 | let ?ab = "a oo b" | 
| 52903 | 2678 | have ab0: "?ab $ 0 = a$0" | 
| 2679 | by (simp add: fps_compose_def) | |
| 2680 | from ab0 a0 ra0 have rab0: "?ab $ 0 \<noteq> 0" "r (Suc k) (?ab $ 0) ^ Suc k = ?ab $ 0" | |
| 2681 | by simp_all | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2682 | 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 | 2683 | 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 | 2684 | 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 | 2685 | unfolding fps_compose_power[OF b0] | 
| 52891 | 2686 | unfolding iffD1[OF power_radical[of a r k], OF a0 ra0] .. | 
| 52903 | 2687 | 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] | 
| 2688 | show ?thesis . | |
| 31199 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2689 | qed | 
| 
10d413b08fa7
FPS composition distributes over inverses, division and arbitrary nth roots. General geometric series theorem
 chaieb parents: 
31148diff
changeset | 2690 | |
| 52903 | 2691 | 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 | 2692 | by (simp add: fps_eq_iff fps_compose_nth setsum_right_distrib mult.assoc) | 
| 29687 | 2693 | |
| 2694 | lemma fps_const_mult_apply_right: | |
| 2695 | "(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 | 2696 | by (auto simp add: fps_const_mult_apply_left mult.commute) | 
| 29687 | 2697 | |
| 30488 | 2698 | lemma fps_compose_assoc: | 
| 52903 | 2699 | assumes c0: "c$0 = (0::'a::idom)" | 
| 2700 | and b0: "b$0 = 0" | |
| 29687 | 2701 | shows "a oo (b oo c) = a oo b oo c" (is "?l = ?r") | 
| 52903 | 2702 | proof - | 
| 2703 |   {
 | |
| 2704 | fix n | |
| 29687 | 2705 |     have "?l$n = (setsum (\<lambda>i. (fps_const (a$i) * b^i) oo c) {0..n})$n"
 | 
| 52903 | 2706 | 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 | 2707 | setsum_right_distrib mult.assoc fps_setsum_nth) | 
| 29687 | 2708 |     also have "\<dots> = ((setsum (\<lambda>i. fps_const (a$i) * b^i) {0..n}) oo c)$n"
 | 
| 2709 | by (simp add: fps_compose_setsum_distrib) | |
| 2710 | also have "\<dots> = ?r$n" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 2711 | apply (simp add: fps_compose_nth fps_setsum_nth setsum_left_distrib mult.assoc) | 
| 57418 | 2712 | apply (rule setsum.cong) | 
| 2713 | apply (rule refl) | |
| 2714 | apply (rule setsum.mono_neutral_right) | |
| 29687 | 2715 | apply (auto simp add: not_le) | 
| 52903 | 2716 | apply (erule startsby_zero_power_prefix[OF b0, rule_format]) | 
| 2717 | done | |
| 2718 | finally have "?l$n = ?r$n" . | |
| 2719 | } | |
| 29687 | 2720 | then show ?thesis by (simp add: fps_eq_iff) | 
| 2721 | qed | |
| 2722 | ||
| 2723 | ||
| 2724 | lemma fps_X_power_compose: | |
| 52903 | 2725 | assumes a0: "a$0=0" | 
| 54681 | 2726 | shows "X^k oo a = (a::'a::idom fps)^k" | 
| 2727 | (is "?l = ?r") | |
| 52903 | 2728 | proof (cases k) | 
| 2729 | case 0 | |
| 2730 | then show ?thesis by simp | |
| 2731 | next | |
| 53196 | 2732 | case (Suc h) | 
| 52903 | 2733 |   {
 | 
| 2734 | fix n | |
| 2735 |     {
 | |
| 2736 | assume kn: "k>n" | |
| 54452 | 2737 | then have "?l $ n = ?r $n" using a0 startsby_zero_power_prefix[OF a0] Suc | 
| 52903 | 2738 | by (simp add: fps_compose_nth del: power_Suc) | 
| 2739 | } | |
| 2740 | moreover | |
| 2741 |     {
 | |
| 2742 | assume kn: "k \<le> n" | |
| 54452 | 2743 | then have "?l$n = ?r$n" | 
| 57418 | 2744 | by (simp add: fps_compose_nth mult_delta_left setsum.delta) | 
| 52903 | 2745 | } | 
| 2746 | moreover have "k >n \<or> k\<le> n" by arith | |
| 2747 | ultimately have "?l$n = ?r$n" by blast | |
| 2748 | } | |
| 2749 | then show ?thesis unfolding fps_eq_iff by blast | |
| 29687 | 2750 | qed | 
| 2751 | ||
| 52903 | 2752 | lemma fps_inv_right: | 
| 2753 | assumes a0: "a$0 = 0" | |
| 2754 | and a1: "a$1 \<noteq> 0" | |
| 29687 | 2755 | shows "a oo fps_inv a = X" | 
| 52903 | 2756 | proof - | 
| 29687 | 2757 | let ?ia = "fps_inv a" | 
| 2758 | let ?iaa = "a oo fps_inv a" | |
| 2759 | have th0: "?ia $ 0 = 0" by (simp add: fps_inv_def) | |
| 30488 | 2760 | have th1: "?iaa $ 0 = 0" using a0 a1 | 
| 29687 | 2761 | by (simp add: fps_inv_def fps_compose_nth) | 
| 2762 | have th2: "X$0 = 0" by simp | |
| 2763 | from fps_inv[OF a0 a1] have "a oo (fps_inv a oo a) = a oo X" by simp | |
| 2764 | then have "(a oo fps_inv a) oo a = X oo a" | |
| 2765 | by (simp add: fps_compose_assoc[OF a0 th0] X_fps_compose_startby0[OF a0]) | |
| 2766 | with fps_compose_inj_right[OF a0 a1] | |
| 30488 | 2767 | show ?thesis by simp | 
| 29687 | 2768 | qed | 
| 2769 | ||
| 2770 | lemma fps_inv_deriv: | |
| 54681 | 2771 | assumes a0:"a$0 = (0::'a::field)" | 
| 52903 | 2772 | and a1: "a$1 \<noteq> 0" | 
| 29687 | 2773 | shows "fps_deriv (fps_inv a) = inverse (fps_deriv a oo fps_inv a)" | 
| 52903 | 2774 | proof - | 
| 29687 | 2775 | let ?ia = "fps_inv a" | 
| 2776 | let ?d = "fps_deriv a oo ?ia" | |
| 2777 | let ?dia = "fps_deriv ?ia" | |
| 2778 | have ia0: "?ia$0 = 0" by (simp add: fps_inv_def) | |
| 52902 | 2779 | have th0: "?d$0 \<noteq> 0" using a1 by (simp add: fps_compose_nth) | 
| 29687 | 2780 | from fps_inv_right[OF a0 a1] have "?d * ?dia = 1" | 
| 2781 | by (simp add: fps_compose_deriv[OF ia0, of a, symmetric] ) | |
| 54452 | 2782 | then have "inverse ?d * ?d * ?dia = inverse ?d * 1" by simp | 
| 52903 | 2783 | with inverse_mult_eq_1 [OF th0] | 
| 29687 | 2784 | show "?dia = inverse ?d" by simp | 
| 2785 | qed | |
| 2786 | ||
| 52891 | 2787 | lemma fps_inv_idempotent: | 
| 52903 | 2788 | assumes a0: "a$0 = 0" | 
| 2789 | and a1: "a$1 \<noteq> 0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2790 | shows "fps_inv (fps_inv a) = a" | 
| 52903 | 2791 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2792 | let ?r = "fps_inv" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2793 | have ra0: "?r a $ 0 = 0" by (simp add: fps_inv_def) | 
| 36350 | 2794 | from a1 have ra1: "?r a $ 1 \<noteq> 0" by (simp add: fps_inv_def field_simps) | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2795 | have X0: "X$0 = 0" by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2796 | from fps_inv[OF ra0 ra1] have "?r (?r a) oo ?r a = X" . | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2797 | then have "?r (?r a) oo ?r a oo a = X oo a" by simp | 
| 52891 | 2798 | then have "?r (?r a) oo (?r a oo a) = a" | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2799 | unfolding X_fps_compose_startby0[OF a0] | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2800 | unfolding fps_compose_assoc[OF a0 ra0, symmetric] . | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2801 | then show ?thesis unfolding fps_inv[OF a0 a1] by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2802 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2803 | |
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2804 | lemma fps_ginv_ginv: | 
| 52903 | 2805 | assumes a0: "a$0 = 0" | 
| 2806 | and a1: "a$1 \<noteq> 0" | |
| 2807 | and c0: "c$0 = 0" | |
| 2808 | and c1: "c$1 \<noteq> 0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2809 | shows "fps_ginv b (fps_ginv c a) = b oo a oo fps_inv c" | 
| 52903 | 2810 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2811 | let ?r = "fps_ginv" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2812 | from c0 have rca0: "?r c a $0 = 0" by (simp add: fps_ginv_def) | 
| 36350 | 2813 | from a1 c1 have rca1: "?r c a $ 1 \<noteq> 0" by (simp add: fps_ginv_def field_simps) | 
| 52891 | 2814 | from fps_ginv[OF rca0 rca1] | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2815 | have "?r b (?r c a) oo ?r c a = b" . | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2816 | then have "?r b (?r c a) oo ?r c a oo a = b oo a" by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2817 | 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 | 2818 | apply (subst fps_compose_assoc) | 
| 53195 | 2819 | using a0 c0 | 
| 2820 | apply (auto simp add: fps_ginv_def) | |
| 52903 | 2821 | done | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2822 | then have "?r b (?r c a) oo c = b oo a" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2823 | unfolding fps_ginv[OF a0 a1] . | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2824 | then have "?r b (?r c a) oo c oo fps_inv c= b oo a oo fps_inv c" by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2825 | 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 | 2826 | apply (subst fps_compose_assoc) | 
| 53195 | 2827 | using a0 c0 | 
| 2828 | apply (auto simp add: fps_inv_def) | |
| 52903 | 2829 | done | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2830 | then show ?thesis unfolding fps_inv_right[OF c0 c1] by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2831 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2832 | |
| 32410 | 2833 | lemma fps_ginv_deriv: | 
| 54681 | 2834 | assumes a0:"a$0 = (0::'a::field)" | 
| 52903 | 2835 | and a1: "a$1 \<noteq> 0" | 
| 32410 | 2836 | shows "fps_deriv (fps_ginv b a) = (fps_deriv b / fps_deriv a) oo fps_ginv X a" | 
| 52903 | 2837 | proof - | 
| 32410 | 2838 | let ?ia = "fps_ginv b a" | 
| 2839 | let ?iXa = "fps_ginv X a" | |
| 2840 | let ?d = "fps_deriv" | |
| 2841 | let ?dia = "?d ?ia" | |
| 2842 | have iXa0: "?iXa $ 0 = 0" by (simp add: fps_ginv_def) | |
| 2843 | have da0: "?d a $ 0 \<noteq> 0" using a1 by simp | |
| 2844 | from fps_ginv[OF a0 a1, of b] have "?d (?ia oo a) = fps_deriv b" by simp | |
| 2845 | then have "(?d ?ia oo a) * ?d a = ?d b" unfolding fps_compose_deriv[OF a0] . | |
| 2846 | then have "(?d ?ia oo a) * ?d a * inverse (?d a) = ?d b * inverse (?d a)" by simp | |
| 52891 | 2847 | then have "(?d ?ia oo a) * (inverse (?d a) * ?d a) = ?d b / ?d a" | 
| 32410 | 2848 | by (simp add: fps_divide_def) | 
| 2849 | then have "(?d ?ia oo a) oo ?iXa = (?d b / ?d a) oo ?iXa " | |
| 2850 | unfolding inverse_mult_eq_1[OF da0] by simp | |
| 2851 | then have "?d ?ia oo (a oo ?iXa) = (?d b / ?d a) oo ?iXa" | |
| 2852 | unfolding fps_compose_assoc[OF iXa0 a0] . | |
| 2853 | then show ?thesis unfolding fps_inv_ginv[symmetric] | |
| 2854 | unfolding fps_inv_right[OF a0 a1] by simp | |
| 2855 | qed | |
| 2856 | ||
| 29906 | 2857 | subsection{* Elementary series *}
 | 
| 29687 | 2858 | |
| 29906 | 2859 | subsubsection{* Exponential series *}
 | 
| 53195 | 2860 | |
| 30488 | 2861 | definition "E x = Abs_fps (\<lambda>n. x^n / of_nat (fact n))" | 
| 29687 | 2862 | |
| 31273 | 2863 | lemma E_deriv[simp]: "fps_deriv (E a) = fps_const (a::'a::field_char_0) * E a" (is "?l = ?r") | 
| 52903 | 2864 | proof - | 
| 53195 | 2865 |   {
 | 
| 2866 | fix n | |
| 29687 | 2867 | have "?l$n = ?r $ n" | 
| 53195 | 2868 | apply (auto simp add: E_def field_simps power_Suc[symmetric] | 
| 2869 | simp del: fact_Suc of_nat_Suc power_Suc) | |
| 52903 | 2870 | apply (simp add: of_nat_mult field_simps) | 
| 2871 | done | |
| 2872 | } | |
| 2873 | then show ?thesis by (simp add: fps_eq_iff) | |
| 29687 | 2874 | qed | 
| 2875 | ||
| 30488 | 2876 | lemma E_unique_ODE: | 
| 54681 | 2877 | "fps_deriv a = fps_const c * a \<longleftrightarrow> a = fps_const (a$0) * E (c::'a::field_char_0)" | 
| 29687 | 2878 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 52903 | 2879 | proof | 
| 2880 | assume d: ?lhs | |
| 30488 | 2881 | from d have th: "\<And>n. a $ Suc n = c * a$n / of_nat (Suc n)" | 
| 36350 | 2882 | by (simp add: fps_deriv_def fps_eq_iff field_simps del: of_nat_Suc) | 
| 52902 | 2883 |   {
 | 
| 2884 | fix n | |
| 2885 | have "a$n = a$0 * c ^ n/ (of_nat (fact n))" | |
| 29687 | 2886 | apply (induct n) | 
| 2887 | apply simp | |
| 30488 | 2888 | unfolding th | 
| 32042 | 2889 | using fact_gt_zero_nat | 
| 36350 | 2890 | apply (simp add: field_simps del: of_nat_Suc fact_Suc) | 
| 29687 | 2891 | apply (drule sym) | 
| 52902 | 2892 | apply (simp add: field_simps of_nat_mult) | 
| 2893 | done | |
| 2894 | } | |
| 29687 | 2895 | note th' = this | 
| 52903 | 2896 | show ?rhs by (auto simp add: fps_eq_iff fps_const_mult_left E_def intro: th') | 
| 2897 | next | |
| 2898 | assume h: ?rhs | |
| 2899 | show ?lhs | |
| 2900 | apply (subst h) | |
| 2901 | apply simp | |
| 2902 | apply (simp only: h[symmetric]) | |
| 2903 | apply simp | |
| 2904 | done | |
| 29687 | 2905 | qed | 
| 2906 | ||
| 31273 | 2907 | lemma E_add_mult: "E (a + b) = E (a::'a::field_char_0) * E b" (is "?l = ?r") | 
| 52903 | 2908 | proof - | 
| 29687 | 2909 | have "fps_deriv (?r) = fps_const (a+b) * ?r" | 
| 36350 | 2910 | by (simp add: fps_const_add[symmetric] field_simps del: fps_const_add) | 
| 29687 | 2911 | then have "?r = ?l" apply (simp only: E_unique_ODE) | 
| 2912 | by (simp add: fps_mult_nth E_def) | |
| 2913 | then show ?thesis .. | |
| 2914 | qed | |
| 2915 | ||
| 2916 | lemma E_nth[simp]: "E a $ n = a^n / of_nat (fact n)" | |
| 2917 | by (simp add: E_def) | |
| 2918 | ||
| 54681 | 2919 | lemma E0[simp]: "E (0::'a::field) = 1" | 
| 29687 | 2920 | by (simp add: fps_eq_iff power_0_left) | 
| 2921 | ||
| 31273 | 2922 | lemma E_neg: "E (- a) = inverse (E (a::'a::field_char_0))" | 
| 52903 | 2923 | proof - | 
| 29687 | 2924 | from E_add_mult[of a "- a"] have th0: "E a * E (- a) = 1" | 
| 2925 | by (simp ) | |
| 2926 | have th1: "E a $ 0 \<noteq> 0" by simp | |
| 2927 | from fps_inverse_unique[OF th1 th0] show ?thesis by simp | |
| 2928 | qed | |
| 2929 | ||
| 31273 | 2930 | lemma E_nth_deriv[simp]: "fps_nth_deriv n (E (a::'a::field_char_0)) = (fps_const a)^n * (E a)" | 
| 52902 | 2931 | by (induct n) auto | 
| 29687 | 2932 | |
| 54681 | 2933 | lemma X_compose_E[simp]: "X oo E (a::'a::field) = E a - 1" | 
| 29687 | 2934 | by (simp add: fps_eq_iff X_fps_compose) | 
| 2935 | ||
| 30488 | 2936 | lemma LE_compose: | 
| 2937 | assumes a: "a\<noteq>0" | |
| 29687 | 2938 | shows "fps_inv (E a - 1) oo (E a - 1) = X" | 
| 52903 | 2939 | and "(E a - 1) oo fps_inv (E a - 1) = X" | 
| 53195 | 2940 | proof - | 
| 29687 | 2941 | let ?b = "E a - 1" | 
| 2942 | have b0: "?b $ 0 = 0" by simp | |
| 2943 | have b1: "?b $ 1 \<noteq> 0" by (simp add: a) | |
| 2944 | from fps_inv[OF b0 b1] show "fps_inv (E a - 1) oo (E a - 1) = X" . | |
| 2945 | from fps_inv_right[OF b0 b1] show "(E a - 1) oo fps_inv (E a - 1) = X" . | |
| 2946 | qed | |
| 2947 | ||
| 30488 | 2948 | lemma fps_const_inverse: | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2949 | "a \<noteq> 0 \<Longrightarrow> inverse (fps_const (a::'a::field)) = fps_const (inverse a)" | 
| 52903 | 2950 | apply (auto simp add: fps_eq_iff fps_inverse_def) | 
| 2951 | apply (case_tac n) | |
| 2952 | apply auto | |
| 2953 | done | |
| 29687 | 2954 | |
| 30488 | 2955 | lemma inverse_one_plus_X: | 
| 54681 | 2956 | "inverse (1 + X) = Abs_fps (\<lambda>n. (- 1 ::'a::field)^n)" | 
| 29687 | 2957 | (is "inverse ?l = ?r") | 
| 52903 | 2958 | proof - | 
| 29687 | 2959 | have th: "?l * ?r = 1" | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 2960 | by (auto simp add: field_simps fps_eq_iff minus_one_power_iff) | 
| 29687 | 2961 | have th': "?l $ 0 \<noteq> 0" by (simp add: ) | 
| 2962 | from fps_inverse_unique[OF th' th] show ?thesis . | |
| 2963 | qed | |
| 2964 | ||
| 31273 | 2965 | lemma E_power_mult: "(E (c::'a::field_char_0))^n = E (of_nat n * c)" | 
| 52902 | 2966 | by (induct n) (auto simp add: field_simps E_add_mult) | 
| 29687 | 2967 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 2968 | lemma radical_E: | 
| 52891 | 2969 | assumes r: "r (Suc k) 1 = 1" | 
| 54681 | 2970 | shows "fps_radical r (Suc k) (E (c::'a::field_char_0)) = E (c / of_nat (Suc k))" | 
| 52903 | 2971 | proof - | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2972 | let ?ck = "(c / of_nat (Suc k))" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2973 | let ?r = "fps_radical r (Suc k)" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2974 | 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 | 2975 | by (simp_all del: of_nat_Suc) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2976 | 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 | 2977 | 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 | 2978 | "r (Suc k) (E c $ 0) = E ?ck $ 0" "E c $ 0 \<noteq> 0" using r by simp_all | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2979 | from th0 radical_unique[where r=r and k=k, OF th] | 
| 52891 | 2980 | show ?thesis by auto | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2981 | qed | 
| 29687 | 2982 | |
| 54681 | 2983 | 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 | 2984 | apply (auto simp add: fps_eq_iff E_def fps_compose_def power_mult_distrib) | 
| 57418 | 2985 | apply (simp add: cond_value_iff cond_application_beta setsum.delta' cong del: if_weak_cong) | 
| 52902 | 2986 | done | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 2987 | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 2988 | text{* The generalized binomial theorem as a  consequence of @{thm E_add_mult} *}
 | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 2989 | |
| 52891 | 2990 | lemma gbinomial_theorem: | 
| 54681 | 2991 |   "((a::'a::{field_char_0,field_inverse_zero})+b) ^ n =
 | 
| 52902 | 2992 | (\<Sum>k=0..n. of_nat (n choose k) * a^k * b^(n-k))" | 
| 2993 | proof - | |
| 52891 | 2994 | from E_add_mult[of a b] | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 2995 | have "(E (a + b)) $ n = (E a * E b)$n" by simp | 
| 52902 | 2996 | then have "(a + b) ^ n = | 
| 54681 | 2997 | (\<Sum>i::nat = 0::nat..n. a ^ i * b ^ (n - i) * (of_nat (fact n) / of_nat (fact i * fact (n - i))))" | 
| 36350 | 2998 | by (simp add: field_simps fps_mult_nth of_nat_mult[symmetric] setsum_right_distrib) | 
| 52891 | 2999 | then show ?thesis | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3000 | apply simp | 
| 57418 | 3001 | apply (rule setsum.cong) | 
| 3002 | apply simp_all | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3003 | apply (frule binomial_fact[where ?'a = 'a, symmetric]) | 
| 53196 | 3004 | apply (simp add: field_simps of_nat_mult) | 
| 3005 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3006 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3007 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3008 | text{* And the nat-form -- also available from Binomial.thy *}
 | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3009 | lemma binomial_theorem: "(a+b) ^ n = (\<Sum>k=0..n. (n choose k) * a^k * b^(n-k))" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3010 | using gbinomial_theorem[of "of_nat a" "of_nat b" n] | 
| 53196 | 3011 | unfolding of_nat_add[symmetric] of_nat_power[symmetric] of_nat_mult[symmetric] | 
| 3012 | of_nat_setsum[symmetric] | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3013 | by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3014 | |
| 53195 | 3015 | |
| 30488 | 3016 | subsubsection{* Logarithmic series *}
 | 
| 29687 | 3017 | |
| 52891 | 3018 | lemma Abs_fps_if_0: | 
| 54452 | 3019 | "Abs_fps(\<lambda>n. if n=0 then (v::'a::ring_1) else f n) = fps_const v + X * Abs_fps (\<lambda>n. f (Suc n))" | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3020 | by (auto simp add: fps_eq_iff) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3021 | |
| 52902 | 3022 | definition L :: "'a::field_char_0 \<Rightarrow> 'a fps" | 
| 3023 | where "L c = fps_const (1/c) * Abs_fps (\<lambda>n. if n = 0 then 0 else (- 1) ^ (n - 1) / of_nat n)" | |
| 29687 | 3024 | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3025 | lemma fps_deriv_L: "fps_deriv (L c) = fps_const (1/c) * inverse (1 + X)" | 
| 29687 | 3026 | unfolding inverse_one_plus_X | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3027 | by (simp add: L_def fps_eq_iff del: of_nat_Suc) | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3028 | |
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3029 | lemma L_nth: "L c $ n = (if n=0 then 0 else 1/c * ((- 1) ^ (n - 1) / of_nat n))" | 
| 36350 | 3030 | by (simp add: L_def field_simps) | 
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3031 | |
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3032 | lemma L_0[simp]: "L c $ 0 = 0" by (simp add: L_def) | 
| 52903 | 3033 | |
| 29687 | 3034 | lemma L_E_inv: | 
| 54452 | 3035 | fixes a :: "'a::field_char_0" | 
| 3036 | assumes a: "a \<noteq> 0" | |
| 3037 | shows "L a = fps_inv (E a - 1)" (is "?l = ?r") | |
| 52903 | 3038 | proof - | 
| 29687 | 3039 | let ?b = "E a - 1" | 
| 3040 | have b0: "?b $ 0 = 0" by simp | |
| 3041 | have b1: "?b $ 1 \<noteq> 0" by (simp add: a) | |
| 52903 | 3042 | have "fps_deriv (E a - 1) oo fps_inv (E a - 1) = | 
| 3043 | (fps_const a * (E a - 1) + fps_const a) oo fps_inv (E a - 1)" | |
| 36350 | 3044 | by (simp add: field_simps) | 
| 52903 | 3045 | also have "\<dots> = fps_const a * (X + 1)" | 
| 3046 | apply (simp add: fps_compose_add_distrib fps_const_mult_apply_left[symmetric] fps_inv_right[OF b0 b1]) | |
| 3047 | apply (simp add: field_simps) | |
| 3048 | done | |
| 29687 | 3049 | finally have eq: "fps_deriv (E a - 1) oo fps_inv (E a - 1) = fps_const a * (X + 1)" . | 
| 3050 | from fps_inv_deriv[OF b0 b1, unfolded eq] | |
| 3051 | have "fps_deriv (fps_inv ?b) = fps_const (inverse a) / (X + 1)" | |
| 52891 | 3052 | using a | 
| 29687 | 3053 | by (simp add: fps_const_inverse eq fps_divide_def fps_inverse_mult) | 
| 54452 | 3054 | 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 | 3055 | by (simp add: fps_deriv_L add.commute fps_divide_def divide_inverse) | 
| 29687 | 3056 | then show ?thesis unfolding fps_deriv_eq_iff | 
| 3057 | by (simp add: L_nth fps_inv_def) | |
| 3058 | qed | |
| 3059 | ||
| 52891 | 3060 | lemma L_mult_add: | 
| 52903 | 3061 | assumes c0: "c\<noteq>0" | 
| 3062 | and d0: "d\<noteq>0" | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3063 | shows "L c + L d = fps_const (c+d) * L (c*d)" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3064 | (is "?r = ?l") | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3065 | proof- | 
| 36350 | 3066 | 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 | 3067 | 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 | 3068 | 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 | 3069 | also have "\<dots> = fps_deriv ?l" | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3070 | apply (simp add: fps_deriv_L) | 
| 52903 | 3071 | apply (simp add: fps_eq_iff eq) | 
| 3072 | done | |
| 31369 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3073 | finally show ?thesis | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3074 | unfolding fps_deriv_eq_iff by simp | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3075 | qed | 
| 
8b460fd12100
Reverses idempotent; radical of E; generalized logarithm;
 chaieb parents: 
31199diff
changeset | 3076 | |
| 53196 | 3077 | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3078 | subsubsection{* Binomial series *}
 | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3079 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3080 | 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 | 3081 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3082 | 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 | 3083 | by (simp add: fps_binomial_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3084 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3085 | lemma fps_binomial_ODE_unique: | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3086 | fixes c :: "'a::field_char_0" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3087 | 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 | 3088 | (is "?lhs \<longleftrightarrow> ?rhs") | 
| 52903 | 3089 | proof - | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3090 | let ?da = "fps_deriv a" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3091 | let ?x1 = "(1 + X):: 'a fps" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3092 | let ?l = "?x1 * ?da" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3093 | let ?r = "fps_const c * a" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3094 | have x10: "?x1 $ 0 \<noteq> 0" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3095 | have "?l = ?r \<longleftrightarrow> inverse ?x1 * ?l = inverse ?x1 * ?r" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3096 | also have "\<dots> \<longleftrightarrow> ?da = (fps_const c * a) / ?x1" | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3097 | apply (simp only: fps_divide_def mult.assoc[symmetric] inverse_mult_eq_1[OF x10]) | 
| 52903 | 3098 | apply (simp add: field_simps) | 
| 3099 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3100 | finally have eq: "?l = ?r \<longleftrightarrow> ?lhs" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3101 | moreover | 
| 52891 | 3102 |   {assume h: "?l = ?r"
 | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3103 |     {fix n
 | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3104 | from h have lrn: "?l $ n = ?r$n" by simp | 
| 52891 | 3105 | |
| 3106 | from lrn | |
| 3107 | have "a$ Suc n = ((c - of_nat n) / of_nat (Suc n)) * a $n" | |
| 36350 | 3108 | apply (simp add: field_simps del: of_nat_Suc) | 
| 3109 | by (cases n, simp_all add: field_simps del: of_nat_Suc) | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3110 | } | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3111 | note th0 = this | 
| 53196 | 3112 |     {
 | 
| 3113 | fix n | |
| 3114 | have "a$n = (c gchoose n) * a$0" | |
| 3115 | proof (induct n) | |
| 3116 | case 0 | |
| 54452 | 3117 | then show ?case by simp | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3118 | next | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3119 | case (Suc m) | 
| 54452 | 3120 | then show ?case unfolding th0 | 
| 36350 | 3121 | apply (simp add: field_simps del: of_nat_Suc) | 
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3122 | unfolding mult.assoc[symmetric] gbinomial_mult_1 | 
| 53196 | 3123 | apply (simp add: field_simps) | 
| 3124 | done | |
| 3125 | qed | |
| 3126 | } | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3127 | note th1 = this | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3128 | have ?rhs | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3129 | apply (simp add: fps_eq_iff) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3130 | apply (subst th1) | 
| 53196 | 3131 | apply (simp add: field_simps) | 
| 3132 | done | |
| 3133 | } | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3134 | moreover | 
| 53196 | 3135 |   {
 | 
| 3136 | assume h: ?rhs | |
| 3137 | have th00: "\<And>x y. x * (a$0 * y) = a$0 * (x*y)" | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 3138 | by (simp add: mult.commute) | 
| 52891 | 3139 | have "?l = ?r" | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3140 | apply (subst h) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3141 | apply (subst (2) h) | 
| 36350 | 3142 | 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 | 3143 | unfolding mult.assoc[symmetric] th00 gbinomial_mult_1 | 
| 53196 | 3144 | apply (simp add: field_simps gbinomial_mult_1) | 
| 3145 | done | |
| 3146 | } | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3147 | ultimately show ?thesis by blast | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3148 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3149 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3150 | lemma fps_binomial_deriv: "fps_deriv (fps_binomial c) = fps_const c * fps_binomial c / (1 + X)" | 
| 53196 | 3151 | proof - | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3152 | let ?a = "fps_binomial c" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3153 | 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 | 3154 | 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 | 3155 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3156 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3157 | lemma fps_binomial_add_mult: "fps_binomial (c+d) = fps_binomial c * fps_binomial d" (is "?l = ?r") | 
| 53196 | 3158 | proof - | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3159 | let ?P = "?r - ?l" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3160 | let ?b = "fps_binomial" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3161 | let ?db = "\<lambda>x. fps_deriv (?b x)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3162 | have "fps_deriv ?P = ?db c * ?b d + ?b c * ?db d - ?db (c + d)" by simp | 
| 53196 | 3163 | also have "\<dots> = inverse (1 + X) * | 
| 3164 | (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 | 3165 | unfolding fps_binomial_deriv | 
| 36350 | 3166 | 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 | 3167 | also have "\<dots> = (fps_const (c + d)/ (1 + X)) * ?P" | 
| 36350 | 3168 | by (simp add: field_simps fps_divide_def 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 | 3169 | 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 | 3170 | by (simp add: fps_divide_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3171 | 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 | 3172 | unfolding fps_binomial_ODE_unique[symmetric] | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3173 | using th0 by simp | 
| 54452 | 3174 | 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 | 3175 | then show ?thesis by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3176 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3177 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3178 | lemma fps_minomial_minus_one: "fps_binomial (- 1) = inverse (1 + X)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3179 | (is "?l = inverse ?r") | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3180 | proof- | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3181 | have th: "?r$0 \<noteq> 0" by simp | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3182 | have th': "fps_deriv (inverse ?r) = fps_const (- 1) * inverse ?r / (1 + X)" | 
| 53196 | 3183 | 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 | 3184 | 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 | 3185 | have eq: "inverse ?r $ 0 = 1" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3186 | by (simp add: fps_inverse_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3187 | 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 | 3188 | show ?thesis by (simp add: fps_inverse_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3189 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3190 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3191 | text{* Vandermonde's Identity as a consequence *}
 | 
| 53196 | 3192 | lemma gbinomial_Vandermonde: | 
| 3193 |   "setsum (\<lambda>k. (a gchoose k) * (b gchoose (n - k))) {0..n} = (a + b) gchoose n"
 | |
| 3194 | proof - | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3195 | let ?ba = "fps_binomial a" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3196 | let ?bb = "fps_binomial b" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3197 | let ?bab = "fps_binomial (a + b)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3198 | 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 | 3199 | 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 | 3200 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3201 | |
| 53196 | 3202 | lemma binomial_Vandermonde: | 
| 3203 |   "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 | 3204 | using gbinomial_Vandermonde[of "(of_nat a)" "of_nat b" n] | 
| 53196 | 3205 | apply (simp only: binomial_gbinomial[symmetric] of_nat_mult[symmetric] | 
| 3206 | of_nat_setsum[symmetric] of_nat_add[symmetric]) | |
| 53195 | 3207 | apply simp | 
| 3208 | done | |
| 52891 | 3209 | |
| 53077 | 3210 | lemma binomial_Vandermonde_same: "setsum (\<lambda>k. (n choose k)\<^sup>2) {0..n} = (2*n) choose n"
 | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3211 | using binomial_Vandermonde[of n n n,symmetric] | 
| 53195 | 3212 | unfolding mult_2 | 
| 3213 | apply (simp add: power2_eq_square) | |
| 57418 | 3214 | apply (rule setsum.cong) | 
| 53195 | 3215 | apply (auto intro: binomial_symmetric) | 
| 3216 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3217 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3218 | lemma Vandermonde_pochhammer_lemma: | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3219 | fixes a :: "'a::field_char_0" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3220 |   assumes b: "\<forall> j\<in>{0 ..<n}. b \<noteq> of_nat j"
 | 
| 54452 | 3221 | shows "setsum (\<lambda>k. (pochhammer (- a) k * pochhammer (- (of_nat n)) k) / | 
| 53196 | 3222 |       (of_nat (fact k) * pochhammer (b - of_nat n + 1) k)) {0..n} =
 | 
| 54452 | 3223 | pochhammer (- (a + b)) n / pochhammer (- b) n" | 
| 53196 | 3224 | (is "?l = ?r") | 
| 3225 | proof - | |
| 54452 | 3226 | let ?m1 = "\<lambda>m. (- 1 :: 'a) ^ m" | 
| 3227 | let ?f = "\<lambda>m. of_nat (fact m)" | |
| 3228 | let ?p = "\<lambda>(x::'a). pochhammer (- x)" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3229 | from b have bn0: "?p b n \<noteq> 0" unfolding pochhammer_eq_0_iff by simp | 
| 53196 | 3230 |   {
 | 
| 3231 | fix k | |
| 3232 |     assume kn: "k \<in> {0..n}"
 | |
| 3233 |     {
 | |
| 3234 | assume c:"pochhammer (b - of_nat n + 1) n = 0" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3235 | 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 | 3236 | unfolding pochhammer_eq_0_iff by blast | 
| 52891 | 3237 | 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 | 3238 | by (simp add: algebra_simps) | 
| 52891 | 3239 | 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 | 3240 | using j kn by (simp add: of_nat_diff) | 
| 53196 | 3241 | with b have False using j by auto | 
| 3242 | } | |
| 52891 | 3243 | then have nz: "pochhammer (1 + b - of_nat n) n \<noteq> 0" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3244 | by (auto simp add: algebra_simps) | 
| 52891 | 3245 | |
| 3246 | from nz kn [simplified] have nz': "pochhammer (1 + b - of_nat n) k \<noteq> 0" | |
| 35175 | 3247 | by (rule pochhammer_neq_0_mono) | 
| 53196 | 3248 |     {
 | 
| 3249 | assume k0: "k = 0 \<or> n =0" | |
| 3250 | then have "b gchoose (n - k) = | |
| 3251 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f 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 | 3252 | using kn | 
| 53196 | 3253 | by (cases "k = 0") (simp_all add: gbinomial_pochhammer) | 
| 3254 | } | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3255 | moreover | 
| 53196 | 3256 |     {
 | 
| 3257 | assume n0: "n \<noteq> 0" and k0: "k \<noteq> 0" | |
| 3258 | then obtain m where m: "n = Suc m" by (cases n) auto | |
| 3259 | from k0 obtain h where h: "k = Suc h" by (cases k) auto | |
| 3260 |       {
 | |
| 3261 | assume kn: "k = n" | |
| 3262 | then have "b gchoose (n - k) = | |
| 3263 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f 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 | 3264 | using kn pochhammer_minus'[where k=k and n=n and b=b] | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3265 | apply (simp add: pochhammer_same) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3266 | using bn0 | 
| 53195 | 3267 | apply (simp add: field_simps power_add[symmetric]) | 
| 3268 | done | |
| 3269 | } | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3270 | moreover | 
| 53196 | 3271 |       {
 | 
| 3272 | assume nk: "k \<noteq> n" | |
| 54452 | 3273 |         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 | 3274 | by (simp_all add: setprod_constant m h) | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3275 | from kn nk have kn': "k < n" by simp | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3276 | have bnz0: "pochhammer (b - of_nat n + 1) k \<noteq> 0" | 
| 52891 | 3277 | using bn0 kn | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3278 | unfolding pochhammer_eq_0_iff | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3279 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3280 | apply (erule_tac x= "n - ka - 1" in allE) | 
| 53196 | 3281 | apply (auto simp add: algebra_simps of_nat_diff) | 
| 3282 | done | |
| 54452 | 3283 |         have eq1: "setprod (\<lambda>k. (1::'a) + of_nat m - of_nat k) {0 .. h} =
 | 
| 53196 | 3284 |           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 | 3285 | using kn' h m | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3286 | 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 | 3287 | (auto simp: of_nat_diff) | 
| 52891 | 3288 | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3289 | have th1: "(?m1 k * ?p (of_nat n) k) / ?f n = 1 / of_nat(fact (n - k))" | 
| 52891 | 3290 | unfolding m1nk | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3291 | unfolding m h pochhammer_Suc_setprod | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3292 | apply (simp add: field_simps del: fact_Suc) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3293 | unfolding fact_altdef_nat id_def | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3294 | unfolding of_nat_setprod | 
| 57418 | 3295 | unfolding setprod.distrib[symmetric] | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3296 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3297 | unfolding eq1 | 
| 57418 | 3298 | apply (subst setprod.union_disjoint[symmetric]) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3299 | apply (auto) | 
| 57418 | 3300 | apply (rule setprod.cong) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3301 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3302 | done | 
| 54452 | 3303 |         have th20: "?m1 n * ?p b n = setprod (\<lambda>i. b - of_nat i) {0..m}"
 | 
| 52891 | 3304 | unfolding m1nk | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3305 | unfolding m h pochhammer_Suc_setprod | 
| 57418 | 3306 | unfolding setprod.distrib[symmetric] | 
| 3307 | apply (rule setprod.cong) | |
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3308 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3309 | done | 
| 54452 | 3310 |         have th21:"pochhammer (b - of_nat n + 1) k = setprod (\<lambda>i. b - of_nat i) {n - k .. n - 1}"
 | 
| 52891 | 3311 | unfolding h m | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3312 | unfolding pochhammer_Suc_setprod | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3313 | using kn m h | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56480diff
changeset | 3314 | 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 | 3315 | (auto simp: of_nat_diff) | 
| 53196 | 3316 | |
| 3317 | have "?m1 n * ?p b n = | |
| 54452 | 3318 |           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 | 3319 | unfolding th20 th21 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3320 | unfolding h m | 
| 57418 | 3321 | apply (subst setprod.union_disjoint[symmetric]) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3322 | using kn' h m | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3323 | apply auto | 
| 57418 | 3324 | apply (rule setprod.cong) | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3325 | apply auto | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3326 | done | 
| 53196 | 3327 | then have th2: "(?m1 n * ?p b n)/pochhammer (b - of_nat n + 1) k = | 
| 54452 | 3328 |           setprod (\<lambda>i. b - of_nat i) {0.. n - k - 1}"
 | 
| 36350 | 3329 | using nz' by (simp add: field_simps) | 
| 53196 | 3330 | have "(?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k) = | 
| 3331 | ((?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 | 3332 | using bnz0 | 
| 36350 | 3333 | by (simp add: field_simps) | 
| 52891 | 3334 | also have "\<dots> = b gchoose (n - k)" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3335 | unfolding th1 th2 | 
| 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3336 | using kn' by (simp add: gbinomial_def) | 
| 53196 | 3337 | finally have "b gchoose (n - k) = | 
| 3338 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k)" | |
| 3339 | by simp | |
| 3340 | } | |
| 3341 | ultimately | |
| 3342 | have "b gchoose (n - k) = | |
| 3343 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k)" | |
| 53195 | 3344 | by (cases "k = n") auto | 
| 3345 | } | |
| 53196 | 3346 | ultimately have "b gchoose (n - k) = | 
| 3347 | (?m1 n * ?p b n * ?m1 k * ?p (of_nat n) k) / (?f n * pochhammer (b - of_nat n + 1) k)" | |
| 3348 | "pochhammer (1 + b - of_nat n) k \<noteq> 0 " | |
| 53195 | 3349 | apply (cases "n = 0") | 
| 52891 | 3350 | using nz' | 
| 53195 | 3351 | apply auto | 
| 3352 | apply (cases k) | |
| 3353 | apply auto | |
| 3354 | done | |
| 3355 | } | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3356 | note th00 = this | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3357 | have "?r = ((a + b) gchoose n) * (of_nat (fact n)/ (?m1 n * pochhammer (- b) n))" | 
| 52891 | 3358 | unfolding gbinomial_pochhammer | 
| 36350 | 3359 | using bn0 by (auto simp add: field_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3360 | also have "\<dots> = ?l" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3361 | unfolding gbinomial_Vandermonde[symmetric] | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3362 | apply (simp add: th00) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3363 | unfolding gbinomial_pochhammer | 
| 53196 | 3364 | using bn0 | 
| 3365 | apply (simp add: setsum_left_distrib setsum_right_distrib field_simps) | |
| 57418 | 3366 | apply (rule setsum.cong) | 
| 3367 | apply (rule refl) | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3368 | apply (drule th00(2)) | 
| 53196 | 3369 | apply (simp add: field_simps power_add[symmetric]) | 
| 3370 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3371 | finally show ?thesis by simp | 
| 52891 | 3372 | qed | 
| 3373 | ||
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3374 | lemma Vandermonde_pochhammer: | 
| 53195 | 3375 | fixes a :: "'a::field_char_0" | 
| 54452 | 3376 |   assumes c: "\<forall>i \<in> {0..< n}. c \<noteq> - of_nat i"
 | 
| 3377 | shows "setsum (\<lambda>k. (pochhammer a k * pochhammer (- (of_nat n)) k) / | |
| 53195 | 3378 |     (of_nat (fact k) * pochhammer c k)) {0..n} = pochhammer (c - a) n / pochhammer c n"
 | 
| 3379 | proof - | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3380 | let ?a = "- a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3381 | let ?b = "c + of_nat n - 1" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3382 |   have h: "\<forall> j \<in>{0..< n}. ?b \<noteq> of_nat j" using c
 | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3383 | apply (auto simp add: algebra_simps of_nat_diff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3384 | apply (erule_tac x= "n - j - 1" in ballE) | 
| 53195 | 3385 | apply (auto simp add: of_nat_diff algebra_simps) | 
| 3386 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3387 | have th0: "pochhammer (- (?a + ?b)) n = (- 1)^n * pochhammer (c - a) n" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3388 | unfolding pochhammer_minus[OF le_refl] | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3389 | by (simp add: algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3390 | have th1: "pochhammer (- ?b) n = (- 1)^n * pochhammer c n" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3391 | unfolding pochhammer_minus[OF le_refl] | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3392 | by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3393 | have nz: "pochhammer c n \<noteq> 0" using c | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3394 | by (simp add: pochhammer_eq_0_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3395 | from Vandermonde_pochhammer_lemma[where a = "?a" and b="?b" and n=n, OF h, unfolded th0 th1] | 
| 36350 | 3396 | show ?thesis using nz by (simp add: field_simps setsum_right_distrib) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3397 | qed | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3398 | |
| 53195 | 3399 | |
| 29906 | 3400 | subsubsection{* Formal trigonometric functions  *}
 | 
| 29687 | 3401 | |
| 31273 | 3402 | definition "fps_sin (c::'a::field_char_0) = | 
| 29687 | 3403 | Abs_fps (\<lambda>n. if even n then 0 else (- 1) ^((n - 1) div 2) * c^n /(of_nat (fact n)))" | 
| 3404 | ||
| 31273 | 3405 | definition "fps_cos (c::'a::field_char_0) = | 
| 3406 | Abs_fps (\<lambda>n. if even n then (- 1) ^ (n div 2) * c^n / (of_nat (fact n)) else 0)" | |
| 29687 | 3407 | |
| 30488 | 3408 | lemma fps_sin_deriv: | 
| 29687 | 3409 | "fps_deriv (fps_sin c) = fps_const c * fps_cos c" | 
| 3410 | (is "?lhs = ?rhs") | |
| 31273 | 3411 | proof (rule fps_ext) | 
| 53195 | 3412 | fix n :: nat | 
| 52902 | 3413 |   {
 | 
| 3414 | assume en: "even n" | |
| 3415 | have "?lhs$n = of_nat (n+1) * (fps_sin c $ (n+1))" by simp | |
| 3416 | also have "\<dots> = of_nat (n+1) * ((- 1)^(n div 2) * c^Suc n / of_nat (fact (Suc n)))" | |
| 3417 | using en by (simp add: fps_sin_def) | |
| 3418 | also have "\<dots> = (- 1)^(n div 2) * c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))" | |
| 3419 | unfolding fact_Suc of_nat_mult | |
| 3420 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 3421 | also have "\<dots> = (- 1)^(n div 2) *c^Suc n / of_nat (fact n)" | |
| 3422 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 3423 | finally have "?lhs $n = ?rhs$n" using en | |
| 3424 | by (simp add: fps_cos_def field_simps) | |
| 3425 | } | |
| 3426 | then show "?lhs $ n = ?rhs $ n" | |
| 53195 | 3427 | by (cases "even n") (simp_all add: fps_deriv_def fps_sin_def fps_cos_def) | 
| 29687 | 3428 | qed | 
| 3429 | ||
| 52902 | 3430 | lemma fps_cos_deriv: "fps_deriv (fps_cos c) = fps_const (- c)* (fps_sin c)" | 
| 29687 | 3431 | (is "?lhs = ?rhs") | 
| 31273 | 3432 | proof (rule fps_ext) | 
| 52902 | 3433 | have th0: "\<And>n. - ((- 1::'a) ^ n) = (- 1)^Suc n" by simp | 
| 31273 | 3434 | have th1: "\<And>n. odd n \<Longrightarrow> Suc ((n - 1) div 2) = Suc n div 2" | 
| 3435 | by (case_tac n, simp_all) | |
| 3436 | fix n::nat | |
| 52902 | 3437 |   {
 | 
| 3438 | assume en: "odd n" | |
| 3439 | from en have n0: "n \<noteq>0 " by presburger | |
| 3440 | have "?lhs$n = of_nat (n+1) * (fps_cos c $ (n+1))" by simp | |
| 3441 | also have "\<dots> = of_nat (n+1) * ((- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact (Suc n)))" | |
| 3442 | using en by (simp add: fps_cos_def) | |
| 3443 | also have "\<dots> = (- 1)^((n + 1) div 2)*c^Suc n * (of_nat (n+1) / (of_nat (Suc n) * of_nat (fact n)))" | |
| 3444 | unfolding fact_Suc of_nat_mult | |
| 3445 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 3446 | also have "\<dots> = (- 1)^((n + 1) div 2) * c^Suc n / of_nat (fact n)" | |
| 3447 | by (simp add: field_simps del: of_nat_add of_nat_Suc) | |
| 3448 | also have "\<dots> = (- ((- 1)^((n - 1) div 2))) * c^Suc n / of_nat (fact n)" | |
| 3449 | unfolding th0 unfolding th1[OF en] by simp | |
| 3450 | finally have "?lhs $n = ?rhs$n" using en | |
| 3451 | by (simp add: fps_sin_def field_simps) | |
| 3452 | } | |
| 3453 | then show "?lhs $ n = ?rhs $ n" | |
| 3454 | by (cases "even n") (simp_all add: fps_deriv_def fps_sin_def fps_cos_def) | |
| 29687 | 3455 | qed | 
| 3456 | ||
| 3457 | lemma fps_sin_cos_sum_of_squares: | |
| 53077 | 3458 | "(fps_cos c)\<^sup>2 + (fps_sin c)\<^sup>2 = 1" (is "?lhs = 1") | 
| 3459 | proof - | |
| 29687 | 3460 | have "fps_deriv ?lhs = 0" | 
| 52902 | 3461 | apply (simp add: fps_deriv_power fps_sin_deriv fps_cos_deriv) | 
| 3462 | apply (simp add: field_simps fps_const_neg[symmetric] del: fps_const_neg) | |
| 3463 | done | |
| 29687 | 3464 | then have "?lhs = fps_const (?lhs $ 0)" | 
| 3465 | unfolding fps_deriv_eq_0_iff . | |
| 3466 | also have "\<dots> = 1" | |
| 30960 | 3467 | by (auto simp add: fps_eq_iff numeral_2_eq_2 fps_mult_nth fps_cos_def fps_sin_def) | 
| 29687 | 3468 | finally show ?thesis . | 
| 3469 | qed | |
| 3470 | ||
| 31274 | 3471 | lemma divide_eq_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x / a = y \<longleftrightarrow> x = y * a" | 
| 53195 | 3472 | by auto | 
| 31274 | 3473 | |
| 3474 | lemma eq_divide_iff: "a \<noteq> (0::'a::field) \<Longrightarrow> x = y / a \<longleftrightarrow> x * a = y" | |
| 53195 | 3475 | by auto | 
| 31274 | 3476 | |
| 3477 | lemma fps_sin_nth_0 [simp]: "fps_sin c $ 0 = 0" | |
| 53195 | 3478 | unfolding fps_sin_def by simp | 
| 31274 | 3479 | |
| 3480 | lemma fps_sin_nth_1 [simp]: "fps_sin c $ 1 = c" | |
| 53195 | 3481 | unfolding fps_sin_def by simp | 
| 31274 | 3482 | |
| 3483 | lemma fps_sin_nth_add_2: | |
| 3484 | "fps_sin c $ (n + 2) = - (c * c * fps_sin c $ n / (of_nat(n+1) * of_nat(n+2)))" | |
| 53195 | 3485 | unfolding fps_sin_def | 
| 3486 | apply (cases n, simp) | |
| 3487 | apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc) | |
| 3488 | apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) | |
| 3489 | done | |
| 31274 | 3490 | |
| 3491 | lemma fps_cos_nth_0 [simp]: "fps_cos c $ 0 = 1" | |
| 53195 | 3492 | unfolding fps_cos_def by simp | 
| 31274 | 3493 | |
| 3494 | lemma fps_cos_nth_1 [simp]: "fps_cos c $ 1 = 0" | |
| 53195 | 3495 | unfolding fps_cos_def by simp | 
| 31274 | 3496 | |
| 3497 | lemma fps_cos_nth_add_2: | |
| 3498 | "fps_cos c $ (n + 2) = - (c * c * fps_cos c $ n / (of_nat(n+1) * of_nat(n+2)))" | |
| 52902 | 3499 | unfolding fps_cos_def | 
| 3500 | apply (simp add: divide_eq_iff eq_divide_iff del: of_nat_Suc fact_Suc) | |
| 3501 | apply (simp add: of_nat_mult del: of_nat_Suc mult_Suc) | |
| 3502 | done | |
| 3503 | ||
| 3504 | lemma nat_induct2: "P 0 \<Longrightarrow> P 1 \<Longrightarrow> (\<And>n. P n \<Longrightarrow> P (n + 2)) \<Longrightarrow> P (n::nat)" | |
| 3505 | unfolding One_nat_def numeral_2_eq_2 | |
| 3506 | apply (induct n rule: nat_less_induct) | |
| 53196 | 3507 | apply (case_tac n) | 
| 3508 | apply simp | |
| 3509 | apply (rename_tac m) | |
| 3510 | apply (case_tac m) | |
| 3511 | apply simp | |
| 3512 | apply (rename_tac k) | |
| 3513 | apply (case_tac k) | |
| 3514 | apply simp_all | |
| 52902 | 3515 | done | 
| 31274 | 3516 | |
| 3517 | lemma nat_add_1_add_1: "(n::nat) + 1 + 1 = n + 2" | |
| 52902 | 3518 | by simp | 
| 31274 | 3519 | |
| 3520 | lemma eq_fps_sin: | |
| 52902 | 3521 | assumes 0: "a $ 0 = 0" | 
| 3522 | and 1: "a $ 1 = c" | |
| 3523 | and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)" | |
| 31274 | 3524 | shows "a = fps_sin c" | 
| 52902 | 3525 | apply (rule fps_ext) | 
| 3526 | apply (induct_tac n rule: nat_induct2) | |
| 3527 | apply (simp add: 0) | |
| 3528 | apply (simp add: 1 del: One_nat_def) | |
| 3529 | apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) | |
| 3530 | apply (simp add: nat_add_1_add_1 fps_sin_nth_add_2 | |
| 3531 | del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') | |
| 3532 | apply (subst minus_divide_left) | |
| 3533 | apply (subst eq_divide_iff) | |
| 3534 | 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 | 3535 | apply (simp only: ac_simps) | 
| 52902 | 3536 | done | 
| 31274 | 3537 | |
| 3538 | lemma eq_fps_cos: | |
| 52902 | 3539 | assumes 0: "a $ 0 = 1" | 
| 3540 | and 1: "a $ 1 = 0" | |
| 3541 | and 2: "fps_deriv (fps_deriv a) = - (fps_const c * fps_const c * a)" | |
| 31274 | 3542 | shows "a = fps_cos c" | 
| 52902 | 3543 | apply (rule fps_ext) | 
| 3544 | apply (induct_tac n rule: nat_induct2) | |
| 3545 | apply (simp add: 0) | |
| 3546 | apply (simp add: 1 del: One_nat_def) | |
| 3547 | apply (rename_tac m, cut_tac f="\<lambda>a. a $ m" in arg_cong [OF 2]) | |
| 3548 | apply (simp add: nat_add_1_add_1 fps_cos_nth_add_2 | |
| 3549 | del: One_nat_def of_nat_Suc of_nat_add add_2_eq_Suc') | |
| 3550 | apply (subst minus_divide_left) | |
| 3551 | apply (subst eq_divide_iff) | |
| 3552 | 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 | 3553 | apply (simp only: ac_simps) | 
| 52902 | 3554 | done | 
| 31274 | 3555 | |
| 3556 | lemma mult_nth_0 [simp]: "(a * b) $ 0 = a $ 0 * b $ 0" | |
| 52902 | 3557 | by (simp add: fps_mult_nth) | 
| 31274 | 3558 | |
| 3559 | lemma mult_nth_1 [simp]: "(a * b) $ 1 = a $ 0 * b $ 1 + a $ 1 * b $ 0" | |
| 52902 | 3560 | by (simp add: fps_mult_nth) | 
| 3561 | ||
| 3562 | lemma fps_sin_add: "fps_sin (a + b) = fps_sin a * fps_cos b + fps_cos a * fps_sin b" | |
| 3563 | apply (rule eq_fps_sin [symmetric], simp, simp del: One_nat_def) | |
| 3564 | apply (simp del: fps_const_neg fps_const_add fps_const_mult | |
| 3565 | add: fps_const_add [symmetric] fps_const_neg [symmetric] | |
| 3566 | fps_sin_deriv fps_cos_deriv algebra_simps) | |
| 3567 | done | |
| 3568 | ||
| 3569 | lemma fps_cos_add: "fps_cos (a + b) = fps_cos a * fps_cos b - fps_sin a * fps_sin b" | |
| 3570 | apply (rule eq_fps_cos [symmetric], simp, simp del: One_nat_def) | |
| 3571 | apply (simp del: fps_const_neg fps_const_add fps_const_mult | |
| 3572 | add: fps_const_add [symmetric] fps_const_neg [symmetric] | |
| 3573 | fps_sin_deriv fps_cos_deriv algebra_simps) | |
| 3574 | done | |
| 31274 | 3575 | |
| 31968 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 3576 | 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 | 3577 | 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 | 3578 | |
| 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
 chaieb parents: 
31790diff
changeset | 3579 | 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 | 3580 | 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 | 3581 | |
| 29687 | 3582 | definition "fps_tan c = fps_sin c / fps_cos c" | 
| 3583 | ||
| 53077 | 3584 | lemma fps_tan_deriv: "fps_deriv (fps_tan c) = fps_const c / (fps_cos c)\<^sup>2" | 
| 52902 | 3585 | proof - | 
| 29687 | 3586 | have th0: "fps_cos c $ 0 \<noteq> 0" by (simp add: fps_cos_def) | 
| 30488 | 3587 | show ?thesis | 
| 29687 | 3588 | using fps_sin_cos_sum_of_squares[of c] | 
| 52902 | 3589 | apply (simp add: fps_tan_def fps_divide_deriv[OF th0] fps_sin_deriv fps_cos_deriv | 
| 3590 | fps_const_neg[symmetric] field_simps power2_eq_square del: fps_const_neg) | |
| 49962 
a8cc904a6820
Renamed {left,right}_distrib to distrib_{right,left}.
 webertj parents: 
49834diff
changeset | 3591 | unfolding distrib_left[symmetric] | 
| 52902 | 3592 | apply simp | 
| 3593 | done | |
| 29687 | 3594 | qed | 
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 3595 | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3596 | text {* Connection to E c over the complex numbers --- Euler and De Moivre*}
 | 
| 52902 | 3597 | 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 | 3598 | (is "?l = ?r") | 
| 52902 | 3599 | proof - | 
| 3600 |   { fix n :: nat
 | |
| 3601 |     {
 | |
| 3602 | assume en: "even n" | |
| 58709 
efdc6c533bd3
prefer generic elimination rules for even/odd over specialized unfold rules for nat
 haftmann parents: 
58681diff
changeset | 3603 | from en obtain m where m: "n = 2 * m" .. | 
| 52891 | 3604 | |
| 3605 | have "?l $n = ?r$n" | |
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3606 | by (simp add: m fps_sin_def fps_cos_def power_mult_distrib power_mult power_minus [of "c ^ 2"]) | 
| 52902 | 3607 | } | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3608 | moreover | 
| 52902 | 3609 |     {
 | 
| 58681 | 3610 | assume "odd n" | 
| 3611 | then obtain m where m: "n = 2 * m + 1" .. | |
| 52891 | 3612 | have "?l $n = ?r$n" | 
| 32960 
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
 wenzelm parents: 
32456diff
changeset | 3613 | by (simp add: m fps_sin_def fps_cos_def power_mult_distrib | 
| 54489 
03ff4d1e6784
eliminiated neg_numeral in favour of - (numeral _)
 haftmann parents: 
54452diff
changeset | 3614 | power_mult power_minus [of "c ^ 2"]) | 
| 52902 | 3615 | } | 
| 3616 | ultimately have "?l $n = ?r$n" by blast | |
| 3617 | } then show ?thesis by (simp add: fps_eq_iff) | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3618 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3619 | |
| 52902 | 3620 | 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 | 3621 | 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 | 3622 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3623 | lemma fps_const_minus: "fps_const (c::'a::group_add) - fps_const d = fps_const (c - d)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3624 | by (simp add: fps_eq_iff fps_const_def) | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3625 | |
| 54681 | 3626 | 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 | 3627 | by (fact numeral_fps_const) (* FIXME: duplicate *) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3628 | |
| 52902 | 3629 | lemma fps_cos_Eii: "fps_cos c = (E (ii * c) + E (- ii * c)) / fps_const 2" | 
| 3630 | proof - | |
| 52891 | 3631 | 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 | 3632 | by (simp add: numeral_fps_const) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3633 | show ?thesis | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3634 | unfolding Eii_sin_cos minus_mult_commute | 
| 52902 | 3635 | by (simp add: fps_sin_even fps_cos_odd numeral_fps_const fps_divide_def fps_const_inverse th) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3636 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3637 | |
| 52902 | 3638 | lemma fps_sin_Eii: "fps_sin c = (E (ii * c) - E (- ii * c)) / fps_const (2*ii)" | 
| 3639 | proof - | |
| 52891 | 3640 | 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 | 3641 | 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 | 3642 | show ?thesis | 
| 52902 | 3643 | unfolding Eii_sin_cos minus_mult_commute | 
| 3644 | by (simp add: fps_sin_even fps_cos_odd fps_divide_def fps_const_inverse th) | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3645 | qed | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3646 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3647 | lemma fps_tan_Eii: | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3648 | "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 | 3649 | unfolding fps_tan_def fps_sin_Eii fps_cos_Eii mult_minus_left E_neg | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3650 | apply (simp add: fps_divide_def fps_inverse_mult fps_const_mult[symmetric] fps_const_inverse del: fps_const_mult) | 
| 52902 | 3651 | apply simp | 
| 3652 | done | |
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3653 | |
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3654 | lemma fps_demoivre: "(fps_cos a + fps_const ii * fps_sin a)^n = fps_cos (of_nat n * a) + fps_const ii * fps_sin (of_nat n * a)" | 
| 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3655 | 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 | 3656 | by (simp add: ac_simps) | 
| 32157 
adea7a729c7a
Moved important theorems from FPS_Examples to FPS --- they are not
 chaieb parents: 
31968diff
changeset | 3657 | |
| 52902 | 3658 | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3659 | subsection {* Hypergeometric series *}
 | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3660 | |
| 54681 | 3661 | definition "F as bs (c::'a::{field_char_0,field_inverse_zero}) =
 | 
| 54452 | 3662 | Abs_fps (\<lambda>n. (foldl (\<lambda>r a. r* pochhammer a n) 1 as * c^n) / | 
| 3663 | (foldl (\<lambda>r b. r * pochhammer b n) 1 bs * of_nat (fact n)))" | |
| 52902 | 3664 | |
| 3665 | lemma F_nth[simp]: "F as bs c $ n = | |
| 3666 | (foldl (\<lambda>r a. r* pochhammer a n) 1 as * c^n) / | |
| 3667 | (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 | 3668 | by (simp add: F_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3669 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3670 | lemma foldl_mult_start: | 
| 54452 | 3671 | fixes v :: "'a::comm_ring_1" | 
| 3672 | shows "foldl (\<lambda>r x. r * f x) v as * x = foldl (\<lambda>r x. r * f x) (v * x) as " | |
| 48757 | 3673 | 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 | 3674 | |
| 53196 | 3675 | lemma foldr_mult_foldl: | 
| 54452 | 3676 | fixes v :: "'a::comm_ring_1" | 
| 3677 | shows "foldr (\<lambda>x r. r * f x) as v = foldl (\<lambda>r x. r * f x) v as" | |
| 48757 | 3678 | 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 | 3679 | |
| 53196 | 3680 | lemma F_nth_alt: | 
| 3681 | "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 | 3682 | 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 | 3683 | by (simp add: foldl_mult_start foldr_mult_foldl) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3684 | |
| 52891 | 3685 | lemma F_E[simp]: "F [] [] c = E c" | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3686 | by (simp add: fps_eq_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3687 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3688 | lemma F_1_0[simp]: "F [1] [] c = 1/(1 - fps_const c * X)" | 
| 52902 | 3689 | proof - | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3690 | 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 | 3691 | have th0: "(fps_const c * X) $ 0 = 0" by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3692 | show ?thesis unfolding gp[OF th0, symmetric] | 
| 53196 | 3693 | by (auto simp add: fps_eq_iff pochhammer_fact[symmetric] | 
| 57418 | 3694 | 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 | 3695 | qed | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3696 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3697 | lemma F_B[simp]: "F [-a] [] (- 1) = fps_binomial a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3698 | by (simp add: fps_eq_iff gbinomial_pochhammer algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3699 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3700 | lemma F_0[simp]: "F as bs c $0 = 1" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3701 | apply simp | 
| 54452 | 3702 | 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 | 3703 | apply auto | 
| 48757 | 3704 | apply (induct_tac as) | 
| 3705 | apply auto | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3706 | done | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3707 | |
| 53196 | 3708 | lemma foldl_prod_prod: | 
| 54452 | 3709 | "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 = | 
| 3710 | foldl (\<lambda>r x. r * f x * g x) (v * w) as" | |
| 48757 | 3711 | 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 | 3712 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3713 | |
| 53196 | 3714 | lemma F_rec: | 
| 54452 | 3715 | "F as bs c $ Suc n = ((foldl (\<lambda>r a. r* (a + of_nat n)) c as) / | 
| 3716 | (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 | 3717 | apply (simp del: of_nat_Suc of_nat_add fact_Suc) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3718 | 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 | 3719 | unfolding foldl_prod_prod[unfolded foldl_mult_start] pochhammer_Suc | 
| 52902 | 3720 | apply (simp add: algebra_simps of_nat_mult) | 
| 3721 | done | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3722 | |
| 54452 | 3723 | 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 | 3724 | by (simp add: XD_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3725 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3726 | lemma XD_0th[simp]: "XD a $ 0 = 0" by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3727 | lemma XD_Suc[simp]:" XD a $ Suc n = of_nat (Suc n) * a $ Suc n" by simp | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3728 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3729 | definition "XDp c a = XD a + fps_const c * a" | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3730 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3731 | 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 | 3732 | by (simp add: XDp_def algebra_simps) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3733 | |
| 54681 | 3734 | 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 | 3735 | 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 | 3736 | |
| 52902 | 3737 | 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 | 3738 | by (simp add: fun_eq_iff fps_eq_iff) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3739 | |
| 52902 | 3740 | 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 | 3741 | by (simp add: fps_eq_iff fps_integral_def) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3742 | |
| 52891 | 3743 | lemma F_minus_nat: | 
| 54681 | 3744 |   "F [- of_nat n] [- of_nat (n + m)] (c::'a::{field_char_0,field_inverse_zero}) $ k =
 | 
| 54452 | 3745 | (if k \<le> n then | 
| 52902 | 3746 | pochhammer (- of_nat n) k * c ^ k / (pochhammer (- of_nat (n + m)) k * of_nat (fact k)) | 
| 3747 | else 0)" | |
| 54681 | 3748 |   "F [- of_nat m] [- of_nat (m + n)] (c::'a::{field_char_0,field_inverse_zero}) $ k =
 | 
| 54452 | 3749 | (if k \<le> m then | 
| 52902 | 3750 | pochhammer (- of_nat m) k * c ^ k / (pochhammer (- of_nat (m + n)) k * of_nat (fact k)) | 
| 3751 | else 0)" | |
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3752 | by (auto simp add: pochhammer_eq_0_iff) | 
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3753 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3754 | 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 | 3755 | apply simp | 
| 57418 | 3756 | apply (subst setsum.insert[symmetric]) | 
| 52902 | 3757 | apply (auto simp add: not_less setsum_head_Suc) | 
| 3758 | done | |
| 3759 | ||
| 3760 | lemma pochhammer_rec_if: "pochhammer a n = (if n = 0 then 1 else a * pochhammer (a + 1) (n - 1))" | |
| 3761 | by (cases n) (simp_all add: pochhammer_rec) | |
| 3762 | ||
| 54681 | 3763 | lemma XDp_foldr_nth [simp]: "foldr (\<lambda>c r. XDp c \<circ> r) cs (\<lambda>c. XDp c a) c0 $ n = | 
| 54452 | 3764 | foldr (\<lambda>c r. (c + of_nat n) * r) cs (c0 + of_nat n) * a$n" | 
| 48757 | 3765 | by (induct cs arbitrary: c0) (auto simp add: algebra_simps) | 
| 32160 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3766 | |
| 
63686057cbe8
Vandermonde vs Pochhammer; Hypergeometric series - very basic facts
 chaieb parents: 
32157diff
changeset | 3767 | lemma genric_XDp_foldr_nth: | 
| 54452 | 3768 | assumes f: "\<forall>n c a. f c a $ n = (of_nat n + k c) * a$n" | 
| 54681 | 3769 | shows "foldr (\<lambda>c r. f c \<circ> r) cs (\<lambda>c. g c a) c0 $ n = | 
| 54452 | 3770 | foldr (\<lambda>c r. (k c + of_nat n) * r) cs (g c0 a $ n)" | 
| 48757 | 3771 | 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 | 3772 | |
| 51107 | 3773 | lemma dist_less_imp_nth_equal: | 
| 3774 | assumes "dist f g < inverse (2 ^ i)" | |
| 52902 | 3775 | and"j \<le> i" | 
| 51107 | 3776 | shows "f $ j = g $ j" | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3777 | proof (rule ccontr) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3778 | assume "f $ j \<noteq> g $ j" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3779 | then have "\<exists>n. f $ n \<noteq> g $ n" by auto | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3780 | with assms have "i < (LEAST n. f $ n \<noteq> g $ n)" | 
| 51107 | 3781 | by (simp add: split_if_asm dist_fps_def) | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3782 | also have "\<dots> \<le> j" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3783 | using `f $ j \<noteq> g $ j` by (auto intro: Least_le) | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3784 | finally show False using `j \<le> i` by simp | 
| 52902 | 3785 | qed | 
| 51107 | 3786 | |
| 3787 | lemma nth_equal_imp_dist_less: | |
| 3788 | assumes "\<And>j. j \<le> i \<Longrightarrow> f $ j = g $ j" | |
| 3789 | shows "dist f g < inverse (2 ^ i)" | |
| 52902 | 3790 | proof (cases "f = g") | 
| 3791 | case False | |
| 54452 | 3792 | then have "\<exists>n. f $ n \<noteq> g $ n" by (simp add: fps_eq_iff) | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3793 | with assms have "dist f g = inverse (2 ^ (LEAST n. f $ n \<noteq> g $ n))" | 
| 51107 | 3794 | by (simp add: split_if_asm dist_fps_def) | 
| 3795 | moreover | |
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3796 | from assms `\<exists>n. f $ n \<noteq> g $ n` have "i < (LEAST n. f $ n \<noteq> g $ n)" | 
| 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3797 | by (metis (mono_tags) LeastI not_less) | 
| 51107 | 3798 | ultimately show ?thesis by simp | 
| 54263 
c4159fe6fa46
move Lubs from HOL to HOL-Library (replaced by conditionally complete lattices)
 hoelzl parents: 
54230diff
changeset | 3799 | qed simp | 
| 52902 | 3800 | |
| 3801 | lemma dist_less_eq_nth_equal: "dist f g < inverse (2 ^ i) \<longleftrightarrow> (\<forall>j \<le> i. f $ j = g $ j)" | |
| 51107 | 3802 | using dist_less_imp_nth_equal nth_equal_imp_dist_less by blast | 
| 3803 | ||
| 3804 | instance fps :: (comm_ring_1) complete_space | |
| 3805 | proof | |
| 54681 | 3806 | fix X :: "nat \<Rightarrow> 'a fps" | 
| 51107 | 3807 | assume "Cauchy X" | 
| 3808 |   {
 | |
| 3809 | fix i | |
| 3810 | have "0 < inverse ((2::real)^i)" by simp | |
| 3811 | from metric_CauchyD[OF `Cauchy X` this] dist_less_imp_nth_equal | |
| 3812 | have "\<exists>M. \<forall>m \<ge> M. \<forall>j\<le>i. X M $ j = X m $ j" by blast | |
| 3813 | } | |
| 3814 | then obtain M where M: "\<forall>i. \<forall>m \<ge> M i. \<forall>j \<le> i. X (M i) $ j = X m $ j" by metis | |
| 54452 | 3815 | then have "\<forall>i. \<forall>m \<ge> M i. \<forall>j \<le> i. X (M i) $ j = X m $ j" by metis | 
| 51107 | 3816 | show "convergent X" | 
| 3817 | proof (rule convergentI) | |
| 3818 | show "X ----> Abs_fps (\<lambda>i. X (M i) $ i)" | |
| 3819 | unfolding tendsto_iff | |
| 3820 | proof safe | |
| 3821 | fix e::real assume "0 < e" | |
| 3822 | with LIMSEQ_inverse_realpow_zero[of 2, simplified, simplified filterlim_iff, | |
| 3823 | THEN spec, of "\<lambda>x. x < e"] | |
| 3824 | have "eventually (\<lambda>i. inverse (2 ^ i) < e) sequentially" | |
| 52902 | 3825 | apply safe | 
| 3826 | apply (auto simp: eventually_nhds) | |
| 3827 | done | |
| 51107 | 3828 | then obtain i where "inverse (2 ^ i) < e" by (auto simp: eventually_sequentially) | 
| 3829 | have "eventually (\<lambda>x. M i \<le> x) sequentially" by (auto simp: eventually_sequentially) | |
| 54452 | 3830 | then show "eventually (\<lambda>x. dist (X x) (Abs_fps (\<lambda>i. X (M i) $ i)) < e) sequentially" | 
| 51107 | 3831 | proof eventually_elim | 
| 52902 | 3832 | fix x | 
| 3833 | assume "M i \<le> x" | |
| 51107 | 3834 | moreover | 
| 3835 | have "\<And>j. j \<le> i \<Longrightarrow> X (M i) $ j = X (M j) $ j" | |
| 3836 | using M by (metis nat_le_linear) | |
| 3837 | ultimately have "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < inverse (2 ^ i)" | |
| 3838 | using M by (force simp: dist_less_eq_nth_equal) | |
| 3839 | also note `inverse (2 ^ i) < e` | |
| 3840 | finally show "dist (X x) (Abs_fps (\<lambda>j. X (M j) $ j)) < e" . | |
| 3841 | qed | |
| 3842 | qed | |
| 3843 | qed | |
| 3844 | qed | |
| 3845 | ||
| 29911 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
 huffman parents: 
29906diff
changeset | 3846 | end |