Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ on:
branches: [master]
pull_request:
types: [opened, synchronize, reopened]
# needed to allow julia-actions/cache to delete old caches that it has created
permissions:
actions: write
contents: read
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Since MultivariatePolynomials doesn't have binary dependencies,
# only test on a subset of possible platforms.
include:
- version: '1'
os: ubuntu-latest
Expand All @@ -27,21 +29,12 @@ jobs:
os: ubuntu-latest
arch: x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v2
- name: dev
shell: julia --project=@. {0}
run: |
Expand All @@ -54,6 +47,7 @@ jobs:
with:
depwarn: error
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
34 changes: 34 additions & 0 deletions src/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function Base.show(io::IO, b::FixedBasis)
return
end

# TODO refactor with `SA.MappedBasis`
# https://github.com/JuliaAlgebra/StarAlgebras.jl/pull/76

"""
struct SemisimpleBasis{T,I,B<:SA.ExplicitBasis{T,I}} <: SA.ExplicitBasis{T,I}
bases::Vector{B}
Expand All @@ -35,6 +38,18 @@ end

Base.length(b::SemisimpleBasis) = length(first(b.bases))

function _iterate(b::SemisimpleBasis, elem_state)
if isnothing(elem_state)
return
end
elem, state = elem_state
return b[elem], state
end
Base.iterate(b::SemisimpleBasis) = _iterate(b, iterate(keys(first(b.bases))))
function Base.iterate(b::SemisimpleBasis, st)
return _iterate(b, iterate(keys(first(b.bases)), st))
end

"""
struct SemisimpleElement{P}
polynomials::Vector{P}
Expand All @@ -47,6 +62,25 @@ struct SemisimpleElement{P}
end
SA.star(p::SemisimpleElement) = SemisimpleElement(SA.star.(p.elements))

function Base.:(==)(a::SemisimpleElement, b::SemisimpleElement)
return length(a.elements) == length(b.elements) &&
all(zip(a.elements, b.elements)) do (a, b)
return a == b
end
end

function MA.operate!(
op::SA.UnsafeAddMul,
res,
A::SemisimpleElement,
B::SemisimpleElement,
α,
)
for (a, b) in zip(A.elements, B.elements)
MA.operate!(op, res, a, b, α)
end
end

function Base.getindex(b::SemisimpleBasis, i::Integer)
return SemisimpleElement(getindex.(b.bases, i))
end
Expand Down
34 changes: 28 additions & 6 deletions test/fixed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,41 @@ using DynamicPolynomials
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
q1 = x_term - im * y_term
p2 = im * x_term - 2y_term
q2 = -im * x_term - 2y_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
semi =
MB.SemisimpleBasis([MB.FixedBasis([p1, p2]), MB.FixedBasis([q1, q2])])
@test length(semi) == 2
@test sprint(show, semi) ==
"Semisimple basis with 2 simple sub-bases:\n FixedBasis([$p1])\n FixedBasis([$p2])"
"Semisimple basis with 2 simple sub-bases:\n FixedBasis([$p1, $p2])\n FixedBasis([$q1, $q2])"
mult = semi[1]
@test all(mult.elements .≈ [p1, p2])
@test all(mult.elements .≈ [p1, q1])
smult = SA.star(mult)
@test all(smult.elements .≈ [p2, p1])
@test all(smult.elements .≈ [q1, p1])

elem, state = iterate(semi)
@test elem == semi[1]
elem, state = iterate(semi, state)
@test elem == semi[2]
@test isnothing(iterate(semi, state))

res = zero(Complex{Int}, MB.algebra(MB.FullBasis{Monomial,typeof(x * y)}()))
MA.operate!(SA.UnsafeAddMul(*), res, semi[1], semi[2], true)
MA.operate!(SA.canonical, res)
@test res == p1 * p2 + q1 * q2
MA.operate!(SA.UnsafeAddMul(*), res, semi[1], semi[2], false)
@test res == p1 * p2 + q1 * q2
MA.operate!(SA.UnsafeAddMul(*), res, semi[2], semi[1], -1)
MA.operate!(SA.canonical, res)
@test iszero(res)
MA.operate!(SA.UnsafeAddMul(*), res, semi[2], semi[2], -1)
MA.operate!(SA.canonical, res)
@test res == -p2^2 - q2^2
end
Loading