@@ -119,6 +119,17 @@ ei(dim,i, coefficients) = tuple((coefficients*Matrix{Int}(I, dim, dim)[:,i])...)
119119differentiate (f:: Expansion , var, order) = differentiate (f, ei (dimension (f), var, order))
120120antidifferentiate (f:: Expansion , var, order) = antidifferentiate (f, ei (dimension (f), var, order))
121121
122+ function Base.:^ (f:: Expansion , i:: Int )
123+ @assert i >= 0
124+ if i == 1
125+ f
126+ elseif i == 2
127+ f * f
128+ else
129+ f^ (i- 1 ) * f
130+ end
131+ end
132+
122133# To be implemented: Laplacian (needs multiplying functions)
123134# # Δ(f::Expansion)
124135
@@ -127,7 +138,9 @@ adjoint(f::Expansion) = differentiate(f)
127138
128139∫ (f:: Expansion ) = antidifferentiate (f)
129140
130- roots (f:: Expansion ) = roots (dictionary (f), coefficients (f))
141+ roots (f:: Expansion ) = expansion_roots (dictionary (f), coefficients (f))
142+
143+ Base. @deprecate roots (dict:: Dictionary , coef:: AbstractVector ) expansion_roots (dict, coef)
131144
132145show (io:: IO , mime:: MIME"text/plain" , fun:: Expansion ) = composite_show (io, mime, fun)
133146Display. displaystencil (fun:: Expansion ) = [" Expansion(" , dictionary (fun), " , " , coefficients (fun), " )" ]
@@ -146,7 +159,10 @@ iscompatible(d1::Dictionary, d2::Dictionary) = false
146159
147160iscompatible (e1:: Expansion , e2:: Expansion ) = iscompatible (dictionary (e1),dictionary (e2))
148161
149- function compatible_dictionary (d1:: Dictionary , d2:: Dictionary )
162+ compatible_dictionary (d1:: Dictionary , d2:: Dictionary ) =
163+ default_compatible_dictionary (d1, d2)
164+
165+ function default_compatible_dictionary (d1:: Dictionary , d2:: Dictionary )
150166 if d1 == d2
151167 d1
152168 else
@@ -184,7 +200,6 @@ function to_compatible_expansions(e1::Expansion, e2::Expansion)
184200end
185201
186202function (+ )(f:: Expansion , g:: Expansion )
187- @assert iscompatible (f, g)
188203 dict, coef = expansion_sum (dictionary (f),dictionary (g),coefficients (f),coefficients (g))
189204 Expansion (dict, coef)
190205end
@@ -208,7 +223,7 @@ function expansion_sum2(dict1, dict2, coef1, coef2)
208223 if iscompatible (dict1, dict2)
209224 default_expansion_sum (dict1, dict2, coef1, coef2)
210225 else
211- error (" Multiplication of expansions in these dictionaries is not implemented." )
226+ error (" Summation of expansions in these dictionaries is not implemented." )
212227 end
213228end
214229
@@ -265,3 +280,23 @@ iterate(e::Expansion, state) = iterate(coefficients(e), state)
265280Base. collect (e:: Expansion ) = coefficients (e)
266281
267282Base. BroadcastStyle (e:: Expansion ) = Base. Broadcast. DefaultArrayStyle {dimension(e)} ()
283+
284+ # Interoperate with basis functions.
285+ # TODO : implement cleaner using promotion mechanism
286+
287+ Base.:* (φ1:: AbstractBasisFunction , φ2:: AbstractBasisFunction ) = expansion (φ1) * expansion (φ2)
288+ Base.:* (f:: Expansion , φ2:: AbstractBasisFunction ) = f * expansion (φ2)
289+ Base.:* (φ1:: AbstractBasisFunction , f:: Expansion ) = expansion (φ1) * f
290+
291+ Base.:* (A:: Number , φ:: AbstractBasisFunction ) = A * expansion (φ)
292+ Base.:* (φ:: AbstractBasisFunction , A:: Number ) = A * expansion (φ)
293+
294+ Base.:+ (φ1:: AbstractBasisFunction , φ2:: AbstractBasisFunction ) = expansion (φ1) + expansion (φ2)
295+ Base.:+ (f:: Expansion , φ2:: AbstractBasisFunction ) = f + expansion (φ2)
296+ Base.:+ (φ1:: AbstractBasisFunction , f:: Expansion ) = expansion (φ1) + f
297+
298+ Base.:- (φ1:: AbstractBasisFunction , φ2:: AbstractBasisFunction ) = expansion (φ1) - expansion (φ2)
299+ Base.:- (f:: Expansion , φ2:: AbstractBasisFunction ) = f - expansion (φ2)
300+ Base.:- (φ1:: AbstractBasisFunction , f:: Expansion ) = expansion (φ1) - f
301+
302+
0 commit comments