-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Fixed basis * Fixes * Fix format * Add doc * Clean up badges * Fix format * Fix
- Loading branch information
Showing
8 changed files
with
147 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,5 +82,6 @@ function MA.promote_operation( | |
end | ||
|
||
include("arithmetic.jl") | ||
include("fixed.jl") | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
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 | ||
Fixed basis with polynomials `elements`. | ||
""" | ||
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::FixedBasis) = length(b.elements) | ||
Base.getindex(b::FixedBasis, i::Integer) = b.elements[i] | ||
|
||
function Base.show(io::IO, b::FixedBasis) | ||
print(io, "FixedBasis(") | ||
_show_vector(io, MIME"text/plain"(), b.elements) | ||
print(io, ")") | ||
return | ||
end | ||
|
||
""" | ||
struct SemisimpleBasis{T,I,B<:SA.ExplicitBasis{T,I}} <: SA.ExplicitBasis{T,I} | ||
bases::Vector{B} | ||
end | ||
Semisimple basis for use with [SymbolicWedderburn](https://github.com/kalmarek/SymbolicWedderburn.jl/). | ||
Its elements are of [`SemisimpleElement`](@ref)s. | ||
""" | ||
struct SemisimpleBasis{T,I,B<:SA.ExplicitBasis{T,I}} <: SA.ExplicitBasis{T,I} | ||
bases::Vector{B} | ||
end | ||
|
||
Base.length(b::SemisimpleBasis) = length(first(b.bases)) | ||
|
||
""" | ||
struct SemisimpleElement{P} | ||
polynomials::Vector{P} | ||
end | ||
Elements of [`SemisimpleBasis`](@ref). | ||
""" | ||
struct SemisimpleElement{P} | ||
elements::Vector{P} | ||
end | ||
SA.star(p::SemisimpleElement) = SemisimpleElement(SA.star.(p.elements)) | ||
|
||
function Base.getindex(b::SemisimpleBasis, i::Integer) | ||
return SemisimpleElement(getindex.(b.bases, i)) | ||
end | ||
|
||
function Base.show(io::IO, b::SemisimpleBasis) | ||
if length(b.bases) == 1 | ||
print(io, "Simple basis:") | ||
else | ||
print(io, "Semisimple basis with $(length(b.bases)) simple sub-bases:") | ||
end | ||
for basis in b.bases | ||
println(io) | ||
print(io, " ") | ||
print(io, basis) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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.elements .≈ [p1, p2]) | ||
smult = SA.star(mult) | ||
@test all(smult.elements .≈ [p2, p1]) | ||
end |