Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Dec 15, 2024
1 parent e0f733d commit edb0b1e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This package provides a standardized API for multivariate polynomial bases
based on the [MultivariatePolynomials](https://github.com/JuliaAlgebra/MultivariatePolynomials.jl) API.

It defines the following basis:
* `FixedPolynomialBasis`: A polynomial basis described by a list of polynomials.
* `FixedBasis`: A polynomial basis described by a list of polynomials.
* Monomial bases: `MonomialBasis` and `ScaledMonomialBasis`.
* Orthogonal bases:
- Hermite bases: `ProbabilistsHermiteBasis` and `PhysicistsHermiteBasis`.
Expand Down
10 changes: 5 additions & 5 deletions src/fixed.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
struct FixedPolynomialBasis{B,M,T,V} <: SA.ExplicitBasis{
struct FixedBasis{B,M,T,V} <: SA.ExplicitBasis{
SA.AlgebraElement{Algebra{FullBasis{B,M},B,M},T,V},
Int,
}
elements::Vector{SA.AlgebraElement{Algebra{FullBasis{B,M},B,M},T,V}}
end

Base.length(b::FixedPolynomialBasis) = length(b.elements)
Base.getindex(b::FixedPolynomialBasis, i::Integer) = b.elements[i]
Base.length(b::FixedBasis) = length(b.elements)
Base.getindex(b::FixedBasis, i::Integer) = b.elements[i]

function Base.show(io::IO, b::FixedPolynomialBasis)
print(io, "FixedPolynomialBasis(")
function Base.show(io::IO, b::FixedBasis)
print(io, "FixedBasis(")
_show_vector(io, MIME"text/plain"(), b.elements)
print(io, ")")
return
Expand Down
29 changes: 29 additions & 0 deletions test/fixed.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Test
import StarAlgebras as SA
using MultivariateBases
const MB = MultivariateBases
using DynamicPolynomials

@testset "FixedBasis" begin
@polyvar x y
x_term = MB.term_element(1, MB.Polynomial{MB.Monomial}(x))
y_term = MB.term_element(1, MB.Polynomial{MB.Monomial}(y))
p1 = x_term + im * y_term
p2 = x_term - im * y_term
fixed = MB.FixedBasis([p1, p2])
@test length(fixed) == 2
@test fixed[1] p1
@test fixed[2] p2
@test sprint(show, fixed) == "FixedBasis([$p1, $p2])"

semi = MB.SemisimpleBasis([
MB.FixedBasis([p1]),
MB.FixedBasis([p2]),
])
@test length(semi) == 1
@test sprint(show, semi) == "Semisimple basis with 2 simple sub-bases:\n FixedBasis([$p1])\n FixedBasis([$p2])"
mult = semi[1]
@test all(mult.polynomials .≈ [p1, p2])
smult = SA.star(mult)
@test all(smult.polynomials .≈ [p2, p1])
end
4 changes: 2 additions & 2 deletions test/monomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using DynamicPolynomials
@test MB.Polynomial{MB.Monomial}(x^3) != MB.Polynomial{MB.Monomial}(x^2)
end

#@testset "Linear" begin
@testset "Linear" begin
basis = SubBasis{MB.Monomial}([x, y])
@test basis == SubBasis{MB.Monomial}([y, x])
@test basis != SubBasis{MB.Monomial}([y, y^2, x])
Expand All @@ -33,7 +33,7 @@ end
@test sprint(show, MIME"text/plain"(), basis) ==
"SubBasis{Monomial}([y, x])"
@test sprint(print, basis) == "SubBasis{Monomial}([y, x])"
#end
end
@testset "Affine" begin
# It will be sorted and 1 will be moved at the end
basis = SubBasis{MB.Monomial}([1, x, y])
Expand Down

0 comments on commit edb0b1e

Please sign in to comment.