diff --git a/experimental/LieAlgebras/src/LieAlgebras.jl b/experimental/LieAlgebras/src/LieAlgebras.jl index 9b264bf3ff43..d6cd094e36c6 100644 --- a/experimental/LieAlgebras/src/LieAlgebras.jl +++ b/experimental/LieAlgebras/src/LieAlgebras.jl @@ -84,6 +84,7 @@ import ..Oscar: tensor_product, weyl_vector, word, + zero!, zero_map, ⊕, ⊗ diff --git a/experimental/LieAlgebras/src/RootSystem.jl b/experimental/LieAlgebras/src/RootSystem.jl index 902e6773741a..88404e9b235d 100644 --- a/experimental/LieAlgebras/src/RootSystem.jl +++ b/experimental/LieAlgebras/src/RootSystem.jl @@ -524,6 +524,14 @@ function RootSpaceElem(w::WeightLatticeElem) return RootSpaceElem(root_system(w), w) end +function zero(::Type{RootSpaceElem}, R::RootSystem) + return RootSpaceElem(R, zero_matrix(QQ, 1, rank(R))) +end + +function zero(r::RootSpaceElem) + return zero(RootSpaceElem, root_system(r)) +end + function Base.:*(q::RationalUnion, r::RootSpaceElem) return RootSpaceElem(root_system(r), q * r.vec) end @@ -544,6 +552,29 @@ function Base.:-(r::RootSpaceElem) return RootSpaceElem(root_system(r), -r.vec) end +function zero!(r::RootSpaceElem) + r.vec = zero!(r.vec) + return r +end + +function add!(rr::RootSpaceElem, r1::RootSpaceElem, r2::RootSpaceElem) + @req root_system(rr) === root_system(r1) === root_system(r2) "parent root system mismatch" + rr.vec = add!(rr.vec, r1.vec, r2.vec) + return rr +end + +function neg!(rr::RootSpaceElem, r::RootSpaceElem) + @req root_system(rr) === root_system(r) "parent root system mismatch" + rr.vec = neg!(rr.vec, r.vec) + return rr +end + +function sub!(rr::RootSpaceElem, r1::RootSpaceElem, r2::RootSpaceElem) + @req root_system(rr) === root_system(r1) === root_system(r2) "parent root system mismatch" + rr.vec = sub!(rr.vec, r1.vec, r2.vec) + return rr +end + function Base.:(==)(r::RootSpaceElem, r2::RootSpaceElem) return r.root_system === r2.root_system && r.vec == r2.vec end @@ -682,6 +713,14 @@ function DualRootSpaceElem(root_system::RootSystem, vec::Vector{<:RationalUnion} return DualRootSpaceElem(root_system, matrix(QQ, 1, length(vec), vec)) end +function zero(::Type{DualRootSpaceElem}, R::RootSystem) + return DualRootSpaceElem(R, zero_matrix(QQ, 1, rank(R))) +end + +function zero(r::DualRootSpaceElem) + return zero(DualRootSpaceElem, root_system(r)) +end + function Base.:*(q::RationalUnion, r::DualRootSpaceElem) return DualRootSpaceElem(root_system(r), q * r.vec) end @@ -702,6 +741,29 @@ function Base.:-(r::DualRootSpaceElem) return DualRootSpaceElem(root_system(r), -r.vec) end +function zero!(r::DualRootSpaceElem) + r.vec = zero!(r.vec) + return r +end + +function add!(rr::DualRootSpaceElem, r1::DualRootSpaceElem, r2::DualRootSpaceElem) + @req root_system(rr) === root_system(r1) === root_system(r2) "parent root system mismatch" + rr.vec = add!(rr.vec, r1.vec, r2.vec) + return rr +end + +function neg!(rr::DualRootSpaceElem, r::DualRootSpaceElem) + @req root_system(rr) === root_system(r) "parent root system mismatch" + rr.vec = neg!(rr.vec, r.vec) + return rr +end + +function sub!(rr::DualRootSpaceElem, r1::DualRootSpaceElem, r2::DualRootSpaceElem) + @req root_system(rr) === root_system(r1) === root_system(r2) "parent root system mismatch" + rr.vec = sub!(rr.vec, r1.vec, r2.vec) + return rr +end + function Base.:(==)(r::DualRootSpaceElem, r2::DualRootSpaceElem) return r.root_system === r2.root_system && r.vec == r2.vec end @@ -839,18 +901,26 @@ function WeightLatticeElem(r::RootSpaceElem) return WeightLatticeElem(root_system(r), r) end +function zero(::Type{WeightLatticeElem}, R::RootSystem) + return WeightLatticeElem(R, zero_matrix(ZZ, rank(R), 1)) +end + +function zero(r::WeightLatticeElem) + return zero(WeightLatticeElem, root_system(r)) +end + function Base.:*(n::IntegerUnion, w::WeightLatticeElem) return WeightLatticeElem(root_system(w), n * w.vec) end function Base.:+(w::WeightLatticeElem, w2::WeightLatticeElem) - @req root_system(w) === root_system(w2) "parent weight lattics mismatch" + @req root_system(w) === root_system(w2) "parent root system mismatch" return WeightLatticeElem(root_system(w), w.vec + w2.vec) end function Base.:-(w::WeightLatticeElem, w2::WeightLatticeElem) - @req root_system(w) === root_system(w2) "parent weight lattics mismatch" + @req root_system(w) === root_system(w2) "parent root system mismatch" return WeightLatticeElem(root_system(w), w.vec - w2.vec) end @@ -859,25 +929,29 @@ function Base.:-(w::WeightLatticeElem) return WeightLatticeElem(root_system(w), -w.vec) end +function zero!(w::WeightLatticeElem) + w.vec = zero!(w.vec) + return w +end + function add!(wr::WeightLatticeElem, w1::WeightLatticeElem, w2::WeightLatticeElem) - add!(wr.vec, w1.vec, w2.vec) + @req root_system(wr) === root_system(w1) === root_system(w2) "parent root system mismatch" + wr.vec = add!(wr.vec, w1.vec, w2.vec) return wr end -add!(w1::WeightLatticeElem, w2::WeightLatticeElem) = add!(w1, w1, w2) - -function neg!(w::WeightLatticeElem) - neg!(w.vec) - return w +function neg!(wr::WeightLatticeElem, w::WeightLatticeElem) + @req root_system(wr) === root_system(w) "parent root system mismatch" + wr.vec = neg!(wr.vec, w.vec) + return wr end function sub!(wr::WeightLatticeElem, w1::WeightLatticeElem, w2::WeightLatticeElem) - sub!(wr.vec, w1.vec, w2.vec) + @req root_system(wr) === root_system(w1) === root_system(w2) "parent root system mismatch" + wr.vec = sub!(wr.vec, w1.vec, w2.vec) return wr end -sub!(w1::WeightLatticeElem, w2::WeightLatticeElem) = sub!(w1, w1, w2) - function Base.:(==)(w::WeightLatticeElem, w2::WeightLatticeElem) return w.root_system === w2.root_system && w.vec == w2.vec end @@ -983,7 +1057,7 @@ function conjugate_dominant_weight_with_elem!(w::WeightLatticeElem) end function dot(w1::WeightLatticeElem, w2::WeightLatticeElem) - @req root_system(w1) === root_system(w2) "parent weight lattices mismatch" + @req root_system(w1) === root_system(w2) "parent root system mismatch" R = root_system(w1) return dot( diff --git a/experimental/LieAlgebras/test/RootSystem-test.jl b/experimental/LieAlgebras/test/RootSystem-test.jl index 278000c23b73..b161be1a300e 100644 --- a/experimental/LieAlgebras/test/RootSystem-test.jl +++ b/experimental/LieAlgebras/test/RootSystem-test.jl @@ -132,6 +132,79 @@ ) end + @testset "Mutating arithmetics for $T" for T in ( + RootSpaceElem, DualRootSpaceElem, WeightLatticeElem + ) + rk = rank(R) + + x1 = T(R, rand(-10:10, rk)) + x2 = T(R, rand(-10:10, rk)) + x3 = T(R, rand(-10:10, rk)) + r1c = deepcopy(x1) + r2c = deepcopy(x2) + r3c = deepcopy(x3) + + for (f, f!) in ((zero, zero!),) + x1 = f!(x1) + @test x1 == f(r1c) + x1 = deepcopy(r1c) + end + + for (f, f!) in ((-, neg!),) + x1 = f!(x1, x2) + @test x1 == f(r2c) + @test x2 == r2c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + + x1 = f!(x1) + @test x1 == f(r1c) + x1 = deepcopy(r1c) + end + + for (f, f!) in ((+, add!), (-, sub!)) + x1 = f!(x1, x2, x3) + @test x1 == f(r2c, r3c) + @test x2 == r2c + @test x3 == r3c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + x3 = deepcopy(r3c) + + x1 = f!(x1, x1, x2) + @test x1 == f(r1c, r2c) + @test x2 == r2c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + + x1 = f!(x1, x2, x1) + @test x1 == f(r2c, r1c) + @test x2 == r2c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + + x1 = f!(x1, x2, x2) + @test x1 == f(r2c, r2c) + @test x2 == r2c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + + x1 = f!(x1, x1, x1) + @test x1 == f(r1c, r1c) + x1 = deepcopy(r1c) + + x1 = f!(x1, x2) + @test x1 == f(r1c, r2c) + @test x2 == r2c + x1 = deepcopy(r1c) + x2 = deepcopy(r2c) + + x1 = f!(x1, x1) + @test x1 == f(r1c, r1c) + x1 = deepcopy(r1c) + end + end + @testset "Serialization" begin mktempdir() do path test_save_load_roundtrip(path, R) do loaded