author  haftmann 
Sat, 28 Jun 2014 09:16:42 +0200  
changeset 57418  6ab1c7cb0b8d 
parent 57129  7edb7550663e 
child 57512  cc97b347b301 
permissions  rwrr 
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:
54681
diff
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:
31790
diff
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:
29906
diff
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:
29906
diff
changeset

18 
notation fps_nth (infixl "$" 75) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

19 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
39198
diff
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:
29906
diff
changeset

22 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

24 
by (simp add: expand_fps_eq) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

25 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

27 
by (simp add: Abs_fps_inverse) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

35 
definition fps_zero_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

36 
"0 = Abs_fps (\<lambda>n. 0)" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

37 

29687  38 
instance .. 
39 
end 

40 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

41 
lemma fps_zero_nth [simp]: "0 $ n = 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

42 
unfolding fps_zero_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

47 
definition fps_one_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

54 
unfolding fps_one_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

59 
definition fps_plus_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

61 

29687  62 
instance .. 
63 
end 

64 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

66 
unfolding fps_plus_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

67 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

71 
definition fps_minus_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

73 

29687  74 
instance .. 
75 
end 

76 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

78 
unfolding fps_minus_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

79 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

83 
definition fps_uminus_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

85 

29687  86 
instance .. 
87 
end 

88 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

90 
unfolding fps_uminus_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

95 
definition fps_times_def: 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

97 

29687  98 
instance .. 
99 
end 

100 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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)" 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

131 
by (simp add: fps_ext add_assoc) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

132 
qed 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

133 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

134 
instance fps :: (ab_semigroup_add) ab_semigroup_add 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

135 
proof 
52891  136 
fix a b :: "'a fps" 
137 
show "a + b = b + a" 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

145 
(\<Sum>j=0..k. \<Sum>i=0..k  j. f j i (n  j  i))" 
57418  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:
29906
diff
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:
29906
diff
changeset

151 
show "(a * b) * c = a * (b * c)" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

152 
proof (rule fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

153 
fix n :: nat 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

156 
by (rule fps_mult_assoc_lemma) 
52891  157 
then show "((a * b) * c) $ n = (a * (b * c)) $ n" 
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:
29906
diff
changeset

159 
qed 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

160 
qed 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

161 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
56480
diff
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:
29906
diff
changeset

167 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

168 
instance fps :: (comm_semiring_0) ab_semigroup_mult 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

169 
proof 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

170 
fix a b :: "'a fps" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

171 
show "a * b = b * a" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

172 
proof (rule fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

173 
fix n :: nat 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

175 
by (rule fps_mult_commute_lemma) 
52891  176 
then show "(a * b) $ n = (b * a) $ n" 
29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

201 
instance fps :: (cancel_semigroup_add) cancel_semigroup_add 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

202 
proof 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

206 
qed 
29687  207 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

209 
proof 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

213 
qed 
29687  214 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

216 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
53374
diff
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:
29906
diff
changeset

224 
instance fps :: (ab_group_add) ab_group_add 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

225 
proof 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

229 
qed 
29687  230 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

231 
instance fps :: (zero_neq_one) zero_neq_one 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

249 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

250 
instance fps :: (semiring_0_cancel) semiring_0_cancel .. 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

258 
proof 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

259 
let ?n = "LEAST n. f $ n \<noteq> 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

260 
assume "f \<noteq> 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

261 
then have "\<exists>n. f $ n \<noteq> 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

262 
by (simp add: fps_nonzero_nth) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

263 
then have "f $ ?n \<noteq> 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

264 
by (rule LeastI_ex) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

265 
moreover have "\<forall>m<?n. f $ m = 0" 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

266 
by (auto dest: not_less_Least) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

269 
next 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

289 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

291 
unfolding fps_const_def by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

292 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

294 
by (simp add: fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

295 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

297 
by (simp add: fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

298 

c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

300 
by (simp add: fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
31199
diff
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:
29906
diff
changeset

313 
by (simp add: fps_ext) 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
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:
29906
diff
changeset

335 
instance fps :: (ring) ring .. 
29687  336 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

337 
instance fps :: (ring_1) ring_1 
54230
b1d955791529
more simplification rules on unary and binary minus
haftmann
parents:
53374
diff
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:
29906
diff
changeset

340 
instance fps :: (comm_ring_1) comm_ring_1 
54230
b1d955791529
more simplification rules on unary and binary minus
haftmann
parents:
53374
diff
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:
29906
diff
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:
29906
diff
changeset

350 
have "(a * b) $ (i+j) = (\<Sum>k=0..i+j. a$k * b$(i+jk))" 
29687  351 
by (rule fps_mult_nth) 
29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

352 
also have "\<dots> = (a$i * b$(i+ji)) + (\<Sum>k\<in>{0..i+j}{i}. a$k * b$(i+jk))" 
57418  353 
by (rule setsum.remove) simp_all 
29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

354 
also have "(\<Sum>k\<in>{0..i+j}{i}. a$k * b$(i+jk)) = 0" 
57418  355 
proof (rule setsum.neutral [rule_format]) 
29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
changeset

357 
then have "k < i \<or> i+jk < j" by auto 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

358 
then show "a$k * b$(i+jk) = 0" using i j by auto 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

359 
qed 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

360 
also have "a$i * b$(i+ji) + 0 = a$i * b$j" by simp 
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
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:
29906
diff
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:
36309
diff
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:
36309
diff
changeset

367 

29911
c790a70a3d19
declare fps_nth as a typedef morphism; clean up instance proofs
huffman
parents:
29906
diff
changeset

368 
instance fps :: (idom) idom .. 
29687  369 

47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46757
diff
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:
46757
diff
changeset

372 
fps_const_add [symmetric]) 
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46757
diff
changeset

373 

54489
03ff4d1e6784
eliminiated neg_numeral in favour of  (numeral _)
haftmann
parents:
54452
diff
changeset

374 
lemma neg_numeral_fps_const: " numeral k = fps_const ( numeral k)" 
03ff4d1e6784
eliminiated neg_numeral in favour of  (numeral _)
haftmann
parents:
54452
diff
changeset

375 
by (simp only: numeral_fps_const fps_const_neg) 
47108
2a1953f0d20d
merged fork with new numeral representation (see NEWS)
huffman
parents:
46757
diff
changeset

376 

31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

377 
subsection{* The eXtractor series X*} 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

381 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

396 
qed 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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))" 
31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

400 
by (metis X_mult_nth mult_commute) 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

406 
next 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
changeset

416 
qed 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

420 
apply (induct k arbitrary: n) 
52891  421 
apply simp 
31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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))" 
31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

429 
by (metis X_power_mult_nth mult_commute) 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

430 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

431 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

432 
subsection{* Formal Power series form a metric space *} 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

436 
instantiation fps :: (comm_ring_1) dist 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

437 
begin 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

438 

52891  439 
definition 
54681  440 
dist_fps_def: "dist (a :: 'a fps) b = 
54263
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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:
31790
diff
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:
31790
diff
changeset

444 
by (simp add: dist_fps_def) 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
changeset

453 
instance .. 
48757  454 

30746  455 
end 
456 

31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

457 
instantiation fps :: (comm_ring_1) metric_space 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

458 
begin 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

459 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

461 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

462 
instance 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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 HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

502 
def n \<equiv> "\<lambda>a b::'a fps. LEAST n. a$n \<noteq> b$n" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

503 
then have n': "\<And>m a b. m < n a b \<Longrightarrow> a$m = b$m" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

504 
by (auto dest: not_less_Least) 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

505 

c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

506 
from ab ac bc 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

507 
have dab: "dist a b = inverse (2 ^ n a b)" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

508 
and dac: "dist a c = inverse (2 ^ n a c)" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

509 
and dbc: "dist b c = inverse (2 ^ n b c)" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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:
31790
diff
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:
31790
diff
changeset

512 
unfolding th by simp_all 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
changeset

515 
by auto 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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 tabwidth;
wenzelm
parents:
32456
diff
changeset

520 
using pos by auto 
54263
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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 tabwidth;
wenzelm
parents:
32456
diff
changeset

522 
unfolding dab dbc dac by (auto simp add: th1) 
54263
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

523 
from n'[OF gtn(2)] n'(1)[OF gtn(1)] 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

524 
have "a $ n a b = b $ n a b" by simp 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

525 
moreover have "a $ n a b \<noteq> b $ n a b" 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

526 
unfolding n_def by (rule LeastI_ex) (insert ab, simp add: fps_eq_iff) 
c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

527 
ultimately have False by contradiction 
52891  528 
} 
31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
changeset

533 
qed 
52891  534 

31968
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

535 
end 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

536 

0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
changeset

560 
then have "exp (real k * ln y + ln x) > exp 0" 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
changeset

561 
by (simp add: mult_ac) 
0314441a53a6
FPS form a metric space, which justifies the infinte sum notation
chaieb
parents:
31790
diff
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:
31790
diff
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:
31790
diff
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 HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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 HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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 HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
changeset

609 

c4159fe6fa46
move Lubs from HOL to HOLLibrary (replaced by conditionally complete lattices)
hoelzl
parents:
54230
diff
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:
31790
diff
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:
36309
diff
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:
36309
diff
changeset

649 

29687  650 
instance .. 
36311
ed3a87a7f977
epheremal replacement of field_simps by field_eq_simps; dropped old division_by_zero instance
haftmann
parents:
36309
diff
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:
29906
diff
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:
29906
diff
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" 
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:
29906
diff
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 (ni))" 
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:
29906
diff
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)" 
727 
by (simp add: mult_ac) 

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" 
739 
by (simp add: mult_ac) 

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:
29906
diff
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:
29906
diff
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:
56480
diff
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:
56480
diff
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" 
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:
56480
diff
changeset

816 
by (rule setsum.reindex_bij_witness_not_neutral 
7edb7550663e
introduce more powerful reindexing rules for big operators
hoelzl
parents:
56480
diff
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:
31790
diff
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:
31790
diff
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:
31790
diff
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:
29906
diff
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:
53374
diff
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:
29906
diff
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:
53374
diff
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" 

29687  951 
using fps_nth_deriv_linear[of n "c" f 0 0] by (simp add: mult_commute) 
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" 
1029 
by (simp add: k mult_commute) 

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 tabwidth;
wenzelm
parents:
32456
diff
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 tabwidth;
wenzelm
parents:
32456
diff
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 

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) 
52903  1147 
apply (simp add: mult_assoc[symmetric]) 
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" 
1197 
by (metis mult_commute inverse_mult_eq_1 f0) 

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:
29906
diff
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" 
