77# Power Series---Integration---Conformal Mapping---Location of Zeros,
88# Wiley-Interscience: New York, 1974
99
10- import Base: zero, one, eye, inv, length, == , + , - , * , (.* ), ^
10+ import Base: zero, one, inv, length, == , + , - , * , ^
11+ import Base. Broadcast: broadcasted
1112export FormalPowerSeries, fps, tovector, trim, isunit, isnonunit,
1213 MatrixForm, reciprocal, derivative, isconstant, compose,
1314 isalmostunit, FormalLaurentSeries
@@ -36,11 +37,11 @@ FormalPowerSeries(v::Vector{T}) where T = FormalPowerSeries{T}(v)
3637# Convenient abbreviation for floats
3738fps = FormalPowerSeries{Float64}
3839
39- zero {T} (P:: FormalPowerSeries{T} ) = FormalPowerSeries (T[])
40- one {T} (P:: FormalPowerSeries{T} ) = FormalPowerSeries (T[1 ])
40+ zero (P:: FormalPowerSeries{T} ) where {T} = FormalPowerSeries (T[])
41+ one (P:: FormalPowerSeries{T} ) where {T} = FormalPowerSeries (T[1 ])
4142
4243# Return truncated vector with c[i] = P[n[i]]
43- function tovector {T,Index<:Integer} (P:: FormalPowerSeries{T} , n:: AbstractVector{Index} )
44+ function tovector (P:: FormalPowerSeries{T} , n:: AbstractVector{Index} ) where {T,Index <: Integer }
4445 nn = length (n)
4546 c = zeros (nn)
4647 for (k,v) in P. c, i in eachindex (n)
@@ -55,7 +56,7 @@ tovector(P::FormalPowerSeries, n::Integer)=tovector(P,1:n)
5556# Basic housekeeping and properties
5657
5758# Remove extraneous zeros
58- function trim {T} (P:: FormalPowerSeries{T} )
59+ function trim (P:: FormalPowerSeries{T} ) where {T}
5960 for (k,v) in P. c
6061 if v== 0
6162 delete! (P. c, k)
@@ -64,9 +65,9 @@ function trim{T}(P::FormalPowerSeries{T})
6465 return P
6566end
6667
67- length {T} (P:: FormalPowerSeries{T} )= max ([k for (k,v) in P. c])
68+ length (P:: FormalPowerSeries{T} ) where {T} = maximum ([k for (k,v) in P. c])
6869
69- function == {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
70+ function == (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
7071 for (k,v) in P. c
7172 if v== 0 # ignore explicit zeros
7273 continue
@@ -89,7 +90,7 @@ function =={T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
8990end
9091
9192# Basic arithmetic [H, p.10]
92- function + {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
93+ function + (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
9394 c = Dict {BigInt, T} ()
9495 for (k,v) in P. c
9596 haskey (c,k) ? (c[k]+= v) : (c[k]= v)
@@ -100,7 +101,7 @@ function +{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
100101 FormalPowerSeries {T} (c)
101102end
102103
103- function - {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
104+ function - (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
104105 c = Dict {BigInt, T} ()
105106 for (k,v) in P. c
106107 c[k] = get (c,k,zero (T)) + v
@@ -112,7 +113,7 @@ function -{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
112113end
113114
114115# negation
115- function - {T} (P:: FormalPowerSeries{T} )
116+ function - (P:: FormalPowerSeries{T} ) where {T}
116117 c = Dict {BigInt, T} ()
117118 for (k,v) in P. c
118119 c[k] = - v
@@ -121,18 +122,18 @@ function -{T}(P::FormalPowerSeries{T})
121122end
122123
123124# multiplication by scalar
124- function * {T} (P:: FormalPowerSeries{T} , n:: Number )
125+ function * (P:: FormalPowerSeries{T} , n:: Number ) where {T}
125126 c = Dict {BigInt, T} ()
126127 for (k,v) in P. c
127128 c[k] = n* v
128129 end
129130 FormalPowerSeries {T} (c)
130131end
131- * {T} (n:: Number , P:: FormalPowerSeries{T} ) = * (P, n)
132+ * (n:: Number , P:: FormalPowerSeries{T} ) where {T} = * (P, n)
132133
133134# Cauchy product [H, p.10]
134- * {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) = CauchyProduct (P, Q)
135- function CauchyProduct {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
135+ * (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T} = CauchyProduct (P, Q)
136+ function CauchyProduct (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
136137 c = Dict {BigInt, T} ()
137138 for (k1, v1) in P. c, (k2, v2) in Q. c
138139 c[k1+ k2]= get (c, k1+ k2, zero (T))+ v1* v2
@@ -141,36 +142,37 @@ function CauchyProduct{T}(P::FormalPowerSeries{T}, Q::FormalPowerSeries{T})
141142end
142143
143144# Hadamard product [H, p.10] - the elementwise product
144- broadcast (:: typeof (* ), P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where T =
145+ broadcasted (:: typeof (* ), P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where T =
145146 HadamardProduct (P, Q)
146- function HadamardProduct {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
147+ function HadamardProduct (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
147148 c = Dict {BigInt, T} ()
148149 for (k,v) in P. c
149- if v!= 0 && haskey (Q. c,k) && Q. c[k]= =0
150+ if v!= 0 && haskey (Q. c,k) && Q. c[k] ! =0
150151 c[k] = v * Q. c[k]
151152 end
152153 end
153154 FormalPowerSeries {T} (c)
154155end
155156
156157# The identity element over the complex numbers
157- function eye {T <: Number} (P:: FormalPowerSeries{T} )
158+ # replacement for previous function eye(P::FormalPowerSeries{T})
159+ function FormalPowerSeries {T} (s:: UniformScaling ) where {T}
158160 c = Dict {BigInt, T} ()
159161 c[0 ] = 1
160- FormalPowerSeries {T} (c)
162+ return FormalPowerSeries {T} (c)
161163end
162164
163- isunit {T <: Number} (P:: FormalPowerSeries{T} ) = P== eye (P )
165+ isunit (P:: FormalPowerSeries{T} ) where {T <: Number } = P== FormalPowerSeries {Float64} (I )
164166
165167# [H, p.12]
166- isnonunit {T} (P:: FormalPowerSeries{T} ) = (! haskey (P. c, 0 ) || P. c[0 ]== 0 ) && ! isunit (P)
168+ isnonunit (P:: FormalPowerSeries{T} ) where {T} = (! haskey (P. c, 0 ) || P. c[0 ]== 0 ) && ! isunit (P)
167169
168170# Constructs the top left m x m block of the (infinite) semicirculant matrix
169171# associated with the fps [H, Sec.1.3, p.14]
170172# [H] calls it the semicirculant, but in contemporary nomenclature this is an
171173# upper triangular Toeplitz matrix
172174# This constructs the dense matrix - Toeplitz matrices don't exist in Julia yet
173- function MatrixForm {T} (P:: FormalPowerSeries{T} , m :: Integer )
175+ function MatrixForm (P:: FormalPowerSeries{T} , m :: Integer ) where {T}
174176 m< 0 && error (" Invalid matrix dimension $m requested" )
175177 M= zeros (T, m, m)
176178 for (k,v) in P. c
@@ -254,13 +256,13 @@ end
254256
255257# Composition of fps [H, Sec.1.5, p.35]
256258# This is the quick and dirty version
257- function compose {T} (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} )
259+ function compose (P:: FormalPowerSeries{T} , Q:: FormalPowerSeries{T} ) where {T}
258260 sum ([v * Q^ k for (k, v) in P. c])
259261end
260262
261263
262264# [H, p.45]
263- function isalmostunit {T} (P:: FormalPowerSeries{T} )
265+ function isalmostunit (P:: FormalPowerSeries{T} ) where {T}
264266 (haskey (P. c, 0 ) && P. c[0 ]!= 0 ) ? (return false ) :
265267 (haskey (P. c, 1 ) && P. c[1 ]!= 0 ) ? (return true ) : (return false )
266268end
271273# [H. Sec.1.7, p.47, but more succinctly stated on p.55]
272274# Constructs the upper left nxn subblock of the matrix representation
273275# and inverts it
274- function reversion {T} (P:: FormalPowerSeries{T} , n :: Integer )
276+ function reversion (P:: FormalPowerSeries{T} , n :: Integer ) where {T}
275277 n> 0 ? error (" Need non-negative dimension" ) : nothing
276278
277279 Q = P
0 commit comments