# ApproxFun.jl multiplying fourier series and cosine/sine series issue

Hi @dlfivefifty
I am using ApproxFun.jl along with `Num` type from SYmbolics to work with `sin/cosine/Fourier` series as follows:

``````julia> myg =Fun(CosSpace(), rand(10));

myf = Fun(SinSpace(), rand(10));

using Symbolics

a=Symbolics.variables(:a, 0:9);   # create a Num vector

myh = Fun(Fourier(), a);

myg*myf;  # this works

myg*myh   # this doesnt work

myf*myh  # this also doesnt work

``````

Both cases that dont work throw following error, If someone can help me here ?

``````ERROR: TypeError: non-boolean (Num) used in boolean context
Stacktrace:
[1] standardchoplength(coeffs::Vector{Num}, tol::Num)
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/LinearAlgebra/standardchop.jl:46
[2] chop!
@ ~/.julia/packages/ApproxFunBase/OfsLT/src/Fun.jl:494 [inlined]
[3] chop!
@ ~/.julia/packages/ApproxFunBase/OfsLT/src/Fun.jl:503 [inlined]
[4] chop(f::Fun{CosSpace{PeriodicSegment{Float64}, Float64}, Num, SubArray{Num, 1, Vector{Num}, Tuple{StepRange{Int64, Int64}}, true}}, tol::Num)
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Fun.jl:521
[5] ConcreteMultiplication
@ ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:16 [inlined]
[6] ConcreteMultiplication
@ ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:26 [inlined]
[7] Multiplication(f::Fun{SS}, sp::CosSpace) where SS<:SinSpace
@ ApproxFunFourier ~/.julia/packages/ApproxFunFourier/a7eyk/src/FourierOperators.jl:218 [inlined]
[8] coefficienttimes(f::Fun{CosSpace{…}, Num, SubArray{…}}, g::Fun{CosSpace{…}, Float64, Vector{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:166
[9] default_mult_compatible(f::Fun{CosSpace{…}, Float64, Vector{…}}, g::Fun{CosSpace{…}, Num, SubArray{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:148
[10] default_mult(f::Fun{CosSpace{…}, Float64, Vector{…}}, g::Fun{CosSpace{…}, Num, SubArray{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:155
[11] *(f::Fun{CosSpace{…}, Float64, Vector{…}}, g::Fun{CosSpace{…}, Num, SubArray{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:164
[12] (::ApproxFunBase.var"#527#528"{Fun{CosSpace{PeriodicSegment{Float64}, Float64}, Float64, Vector{Float64}}})(gg::Function)
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Spaces/ProductSpaceOperators.jl:323
[13] _mapreduce(f::ApproxFunBase.var"#527#528"{Fun{CosSpace{…}, Float64, Vector{…}}}, op::typeof(+), ::IndexLinear, A::Vector{Fun{S, Num, SubArray{…}} where S})
@ Base ./reduce.jl:440
[14] _mapreduce_dim
@ ./reducedim.jl:365 [inlined]
@ Base ./reducedim.jl:357 [inlined]
[16] coefficienttimes
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Spaces/ProductSpaceOperators.jl:323 [inlined]
[17] default_mult_compatible(f::Fun{CosSpace{…}, Float64, Vector{…}}, g::Fun{ApproxFunBase.SumSpace{…}, Num, Vector{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:146
[18] default_mult(f::Fun{CosSpace{…}, Float64, Vector{…}}, g::Fun{ApproxFunBase.SumSpace{…}, Num, Vector{…}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:155
[19] *(f::Fun{CosSpace{PeriodicSegment{…}, Float64}, Float64, Vector{Float64}}, g::Fun{ApproxFunBase.SumSpace{Tuple{…}, PeriodicSegment{…}, Float64}, Num, Vector{Num}})
@ ApproxFunBase ~/.julia/packages/ApproxFunBase/OfsLT/src/Operators/banded/Multiplication.jl:164
[20] top-level scope
@ REPL[55]:1
Some type information was truncated. Use `show(err)` to see complete types.

``````

Create the constant length operator for `myg` first instead of trying to have it be adaptive.

1 Like

Thanks ! that was helpful. Any idea how do i multiply cosine series of many coeffs having different periods ? Requesting @dlfivefifty to take a look if possible

``````
julia> G = Fun(CosSpace(), rand(3))
Fun(CosSpace(【0.0,6.283185307179586❫), [0.587619, 0.499599, 0.616276])

julia> F = Fun(SinSpace(PeriodicSegment(0, pi)), rand(3));

julia> Multiplication(F, CosSpace())*G
ERROR: AssertionError: domain(f) == domain(sp)
Stacktrace:
[1] Multiplication(f::Fun{SinSpace{PeriodicSegment{Float64}, Float64}, Float64, Vector{Float64}}, sp::CosSpace{PeriodicSegment{Float64}, Float64})
@ ApproxFunFourier ~/.julia/packages/ApproxFunFourier/lFQDK/src/FourierOperators.jl:222
[2] top-level scope
@ REPL[11]:1
``````

I’m not sure what you expect it to do? Create a series with all possible combinations?

``````a= rand(3);  b= rand(3);  # typically arrays of of n elements