7
7
# Power Series---Integration---Conformal Mapping---Location of Zeros,
8
8
# Wiley-Interscience: New York, 1974
9
9
10
- import Base. eye, Base. inv, Base. length,
11
- Base.== , Base.+ , Base.- , Base.* , Base .(.* ), Base.^
10
+ import Base: zero, one, eye, inv, length, == , + , - , * , (.* ), ^
12
11
export FormalPowerSeries, fps, tovector, trim, isunit, isnonunit,
13
12
MatrixForm, reciprocal, derivative, isconstant, compose,
14
13
isalmostunit, FormalLaurentSeries
@@ -39,10 +38,8 @@ fps = FormalPowerSeries{Float64}
39
38
function tovector {T,Index<:Integer} (P:: FormalPowerSeries{T} , n :: Vector{Index} )
40
39
nn = length (n)
41
40
c = zeros (nn)
42
- for (k,v) in P. c
43
- for i= 1 : nn
44
- n[i]== k ? (c[i]= v) : nothing
45
- end
41
+ for (k,v) in P. c, i= 1 : nn
42
+ n[i]== k && (c[i]= v)
46
43
end
47
44
c
48
45
end
101
98
function - {T}(P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
102
99
c = Dict {BigInt, T} ()
103
100
for (k,v) in P. c
104
- haskey (c,k) ? (c[k] += v) : (c[k] = v)
101
+ c[k] = get (c,k, zero (T)) + v
105
102
end
106
103
for (k,v) in Q. c
107
- haskey (c,k) ? (c [k]-= v) : (c[k] = - v)
104
+ c [k] = get (c,k, zero (T)) - v
108
105
end
109
106
FormalPowerSeries {T} (c)
110
107
end
132
129
* {T}(P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) = CauchyProduct (P, Q)
133
130
function CauchyProduct {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
134
131
c = Dict {BigInt, T} ()
135
- for (k1, v1) in P. c
136
- for (k2, v2) in Q. c
137
- haskey (c, k1+ k2) ? (c[k1+ k2]+= v1* v2) : (c[k1+ k2]= v1* v2)
138
- end
132
+ for (k1, v1) in P. c, (k2, v2) in Q. c
133
+ c[k1+ k2]= get (c, k1+ k2, zero (T))+ v1* v2
139
134
end
140
135
FormalPowerSeries {T} (c)
141
136
end
@@ -170,7 +165,7 @@ isnonunit{T}(P::FormalPowerSeries{T}) = (!haskey(P.c, 0) || P.c[0]==0) && !isuni
170
165
# upper triangular Toeplitz matrix
171
166
# This constructs the dense matrix - Toeplitz matrices don't exist in Julia yet
172
167
function MatrixForm {T} (P:: FormalPowerSeries{T} , m :: Integer )
173
- m< 0 ? error (sprintf ( " Invalid matrix dimension %d requested" , m)) : true
168
+ m< 0 && error (" Invalid matrix dimension $m requested" )
174
169
M= zeros (T, m, m)
175
170
for (k,v) in P. c
176
171
if k < m
215
210
function derivative {T} (P:: FormalPowerSeries{T} )
216
211
c = Dict {BigInt, T} ()
217
212
for (k,v) in P. c
218
- if k != 0 && v != 0
213
+ if k != 0 && v != 0
219
214
c[k- 1 ] = k* v
220
215
end
221
216
end
@@ -260,14 +255,14 @@ end
260
255
261
256
# [H, p.45]
262
257
function isalmostunit {T} (P:: FormalPowerSeries{T} )
263
- (haskey (P. c, 0 ) && P. c[0 ]!= 0 ) ? (return false ) : true
258
+ (haskey (P. c, 0 ) && P. c[0 ]!= 0 ) ? (return false ) :
264
259
(haskey (P. c, 1 ) && P. c[1 ]!= 0 ) ? (return true ) : (return false )
265
260
end
266
261
267
262
268
263
# Reversion of a series (inverse with respect to composition)
269
264
# P^[-1]
270
- # [H. Sec.1.7, p.47, but more succintly stated on p.55]
265
+ # [H. Sec.1.7, p.47, but more succinctly stated on p.55]
271
266
# Constructs the upper left nxn subblock of the matrix representation
272
267
# and inverts it
273
268
function reversion {T} (P:: FormalPowerSeries{T} , n :: Integer )
@@ -280,7 +275,7 @@ function reversion{T}(P::FormalPowerSeries{T}, n :: Integer)
280
275
Q = P
281
276
ai = tovector (Q, n) # Extract coefficients P[1]...P[n]
282
277
A[i,:] = ai
283
- i< n ? Q *= P : nothing
278
+ i< n && ( Q *= P)
284
279
end
285
280
286
281
# TODO I just need the first row of the inverse
0 commit comments