@@ -25,7 +25,7 @@ type FormalPowerSeries{Coefficients}
25
25
for i= 1 : length (v)
26
26
if v[i] != 0
27
27
c[i- 1 ] = v[i] # Note this off by 1 - allows constant term c[0] to be set
28
- end
28
+ end
29
29
end
30
30
FormalPowerSeries {Coefficients} (c)
31
31
end
@@ -37,7 +37,7 @@ zero{T}(P::FormalPowerSeries{T}) = FormalPowerSeries(T[])
37
37
one {T} (P:: FormalPowerSeries{T} ) = FormalPowerSeries (T[1 ])
38
38
39
39
# Return truncated vector with c[i] = P[n[i]]
40
- function tovector {T,Index<:Integer} (P:: FormalPowerSeries{T} , n :: Vector {Index} )
40
+ function tovector {T,Index<:Integer} (P:: FormalPowerSeries{T} , n :: AbstractVector {Index} )
41
41
nn = length (n)
42
42
c = zeros (nn)
43
43
for (k,v) in P. c, i= 1 : nn
@@ -46,7 +46,7 @@ function tovector{T,Index<:Integer}(P::FormalPowerSeries{T}, n :: Vector{Index})
46
46
c
47
47
end
48
48
49
- tovector (P:: FormalPowerSeries , n:: Integer )= tovector (P,[ 1 : n] )
49
+ tovector (P:: FormalPowerSeries , n:: Integer )= tovector (P,1 : n)
50
50
51
51
52
52
# Basic housekeeping and properties
89
89
function + {T}(P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
90
90
c = Dict {BigInt, T} ()
91
91
for (k,v) in P. c
92
- haskey (c,k) ? (c[k]+= v) : (c[k]= v)
92
+ haskey (c,k) ? (c[k]+= v) : (c[k]= v)
93
93
end
94
94
for (k,v) in Q. c
95
- haskey (c,k) ? (c[k]+= v) : (c[k]= v)
95
+ haskey (c,k) ? (c[k]+= v) : (c[k]= v)
96
96
end
97
97
FormalPowerSeries {T} (c)
98
98
end
99
99
100
100
function - {T}(P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
101
101
c = Dict {BigInt, T} ()
102
102
for (k,v) in P. c
103
- c[k] = get (c,k,zero (T)) + v
103
+ c[k] = get (c,k,zero (T)) + v
104
104
end
105
105
for (k,v) in Q. c
106
- c[k] = get (c,k,zero (T)) - v
106
+ c[k] = get (c,k,zero (T)) - v
107
107
end
108
108
FormalPowerSeries {T} (c)
109
109
end
132
132
function CauchyProduct {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
133
133
c = Dict {BigInt, T} ()
134
134
for (k1, v1) in P. c, (k2, v2) in Q. c
135
- c[k1+ k2]= get (c, k1+ k2, zero (T))+ v1* v2
135
+ c[k1+ k2]= get (c, k1+ k2, zero (T))+ v1* v2
136
136
end
137
137
FormalPowerSeries {T} (c)
138
138
end
@@ -196,10 +196,10 @@ end
196
196
function reciprocal {T} (P:: FormalPowerSeries{T} , n :: Integer )
197
197
n< 0 ? error (sprintf (" Invalid inverse truncation length %d requested" , n)) : true
198
198
199
- a = tovector (P, [ 0 : n- 1 ] ) # Extract original coefficients in vector
199
+ a = tovector (P, 0 : n- 1 ) # Extract original coefficients in vector
200
200
a[1 ]== 0 ? (error (" Inverse does not exist" )) : true
201
201
inv_a1 = T<: Number ? 1.0 / a[1 ] : inv (a[1 ])
202
-
202
+
203
203
b = zeros (n) # Inverse
204
204
b[1 ] = inv_a1
205
205
for k= 2 : n
@@ -208,7 +208,7 @@ function reciprocal{T}(P::FormalPowerSeries{T}, n :: Integer)
208
208
FormalPowerSeries {T} (b)
209
209
end
210
210
211
- # Derivative of fps [H. Sec.1.4, p.18]
211
+ # Derivative of fps [H. Sec.1.4, p.18]
212
212
function derivative {T} (P:: FormalPowerSeries{T} )
213
213
c = Dict {BigInt, T} ()
214
214
for (k,v) in P. c
@@ -238,7 +238,7 @@ function ^{T}(P::FormalPowerSeries{T}, n :: Integer)
238
238
elseif n > 1
239
239
# The straightforward recursive way
240
240
return P^ (n- 1 ) * P
241
- # TODO implement the non-recursive formula
241
+ # TODO implement the non-recursive formula
242
242
elseif n== 1
243
243
return P
244
244
else
@@ -251,13 +251,13 @@ end
251
251
# Composition of fps [H, Sec.1.5, p.35]
252
252
# This is the quick and dirty version
253
253
function compose {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
254
- sum ([v * Q^ k for (k, v) in P. c])
254
+ sum ([v * Q^ k for (k, v) in P. c])
255
255
end
256
256
257
257
258
258
# [H, p.45]
259
259
function isalmostunit {T} (P:: FormalPowerSeries{T} )
260
- (haskey (P. c, 0 ) && P. c[0 ]!= 0 ) ? (return false ) :
260
+ (haskey (P. c, 0 ) && P. c[0 ]!= 0 ) ? (return false ) :
261
261
(haskey (P. c, 1 ) && P. c[1 ]!= 0 ) ? (return true ) : (return false )
262
262
end
263
263
269
269
# and inverts it
270
270
function reversion {T} (P:: FormalPowerSeries{T} , n :: Integer )
271
271
n> 0 ? error (" Need non-negative dimension" ) : nothing
272
-
272
+
273
273
Q = P
274
274
A = zeros (n, n)
275
275
# Construct the matrix representation (1.9-1), p.55
@@ -304,4 +304,3 @@ type FormalLaurentSeries{Coefficients}
304
304
c
305
305
end
306
306
end
307
-
0 commit comments