diff --git a/src/trigonometric.jl b/src/trigonometric.jl index e8f026b..7b6ce57 100644 --- a/src/trigonometric.jl +++ b/src/trigonometric.jl @@ -6,12 +6,12 @@ Univariate trigonometric basis is a0 + a1 cos(ωt) + a2 sin(ωt) + a3 cos(2ωt) + a4 sin(2ωt) ``` """ -struct Trigonometric <: AbstractMonomialIndexed end +struct Trigonometric <: AbstractMultipleOrthogonal end _cos_id(d) = iszero(d) ? 0 : 2d - 1 _sin_id(d) = 2d _is_cos(d) = isodd(d) -_is_sin(d) = isodd(d) +_is_sin(d) = d > 0 && iseven(d) _id(d) = div(d + 1, 2) # https://en.wikipedia.org/wiki/Chebyshev_polynomials#Properties @@ -95,3 +95,6 @@ end function _promote_coef(::Type{T}, ::Type{Trigonometric}) where {T} return _promote_div(T) end + +# FIXME The cos part is, like Chebysev, maybe the sin part too ? We should do better here, this is just a stopgap +even_odd_separated(::Type{Trigonometric}) = false diff --git a/test/trigonometric.jl b/test/trigonometric.jl new file mode 100644 index 0000000..1c1fda7 --- /dev/null +++ b/test/trigonometric.jl @@ -0,0 +1,15 @@ +using Test +using MultivariateBases +using DynamicPolynomials + +@testset "StarAlgebras" begin + @polyvar x + a = MB.Polynomial{MB.Trigonometric}(x) + b = a * a + @test b.coeffs == MB.sparse_coefficients(1 // 2 + 1 // 2 * x^3) + c = b * b + @test c.coeffs == + MB.sparse_coefficients(3 // 8 + 1 // 2 * x^3 + 1 // 8 * x^7) + @test a * MB.Polynomial{MB.Trigonometric}(constant_monomial(typeof(x))) == + a * MB.Polynomial{MB.Trigonometric}(x^0) +end