From d4875446c3a4ee815e598d1cdddbc06e3d646765 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Thu, 13 Jun 2024 12:48:31 +0200 Subject: [PATCH 01/30] Linear Combinations for Partitions (from december 23) --- .../SetPartitions/src/LinearCombinations.jl | 240 ++++++++++++++++++ .../SetPartitions/src/SetPartitions.jl | 23 +- experimental/SetPartitions/src/Util.jl | 34 +++ 3 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 experimental/SetPartitions/src/LinearCombinations.jl diff --git a/experimental/SetPartitions/src/LinearCombinations.jl b/experimental/SetPartitions/src/LinearCombinations.jl new file mode 100644 index 000000000000..0ba289f37772 --- /dev/null +++ b/experimental/SetPartitions/src/LinearCombinations.jl @@ -0,0 +1,240 @@ +""" +Sebvz todos: +- deepcopy +- dict zugriffe verbessern wenn möglich +- tests +- rename composition +""" + + +""" + LinearPartition{S <: AbstractPartition, T <: RingElement} + +Initialize LinearPartition object, while simplifying +the term. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> LinearPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) +LinearPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) +``` +""" +struct LinearPartition{S <: AbstractPartition, T <: RingElement} + coefficients :: Dict{S, T} + + function LinearPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + new(simplify_operation_zero(coeffs)) + end +end + +function LinearPartition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + LinearPartition{S, T}(coeffs) +end + + +# TODO hash + +function ==(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + p == q +end + +""" + LinearPartition(terms::Vector{Tuple{S, T}}) where + { S <: AbstractPartition, T <: RingElement } + +Return LinearPartition object generated from the Vector `terms` of 2-tuples, +where the first element in the tuple is a RingElement and the second +a SetPartition. Furthermore simplify the term before initializing +the LinearPartition object with the corresponding dict. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> LinearPartition([(SetPartition([1, 1], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) +LinearPartition(Dict(SetPartition([1, 1], [1, 1]) => 4 + 4*d)) +``` +""" +function LinearPartition(terms::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + LinearPartition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(terms))) +end + +#function LinearPartition{T}(p::S) where { S <: AbstractPartition, T <: RingElement } +# # LinearPartition([(p, one(T))]) +#end + +""" + add(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + +Return the addition between `p` and `q`. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> add(a, a) +LinearPartition(SetPartition([1, 2], [1, 1]) => 8, +SetPartition([1, 1], [1, 1]) => 8*d) +``` +""" +function add(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + + result = copy(p.coefficients) + + for i in pairs(q.coefficients) + result[i[1]] = get(result, i[1], 0) + i[2] + end + + LinearPartition(result) +end + +function +(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + add(p, q) +end + +""" + scale(a::RingElement, p::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + +Multiply each coefficient in `p` with `a` and return +the result. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> scale(0.5, LinearPartition(SetPartition([1, 2], [1, 1]) => 8, +SetPartition([1, 1], [1, 1]) => 8*d)) +LinearPartition(SetPartition([1, 2], [1, 1]) => 4, +SetPartition([1, 1], [1, 1]) => 4*d) +``` +""" +function scale(a::RingElement, p::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + result = Dict{S, T}() + + for (i, n) in pairs(p.coefficients) + result[i] = a * n + end + LinearPartition(result) +end + +function *(a::RingElement, p::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + scale(a, p) +end + +""" + composition(p::LinearPartition{P, R}, q::LinearPartition{P, R}, d::R) where + { P <: AbstractPartition, R <: RingElement } + +Multiply each coefficient from `p` with each coefficient from `q` +as well as perform a composition between each SetPartition part +in `p` and `q` and return the result. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> linear_composition(a, a) +LinearPartition(SetPartition([1, 2], [1, 1]) => 16*d + 16, +SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d) +``` +""" +function composition(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::RingElement) where + { S <: AbstractPartition, T <: RingElement } + result = Dict{S, T}() + + for i in pairs(p.coefficients) + for ii in pairs(q.coefficients) + (composition, loop) = composition_loops(i[1], ii[1]) + new_coefficient = i[2] * ii[2] * (d^loop) + result[composition] = get(result, composition, 0) + new_coefficient + end + end + LinearPartition(result) +end + +function composition(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::RingElement) where + { S <: AbstractPartition, T <: RingElement } + composition(p, q, d) +end + +""" + tensor_product(p::LinearPartition{P, R}, q::LinearPartition{P, R}) where + { P <: AbstractPartition, R <: RingElement } + +Perform a tensor product similar + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> linear_tensor_product(a, a) +LinearPartition(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, +SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 4*d + 4, +SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 8, +SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4)) +``` +""" +function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + + result = Dict{S, T}() + + for i in pairs(p.coefficients) + for ii in pairs(q.coefficients) + composition = tensor_product(i[1], ii[1]) + new_coefficient = i[2] * ii[2] + result[composition] = get(result, composition, 0) + new_coefficient + end + end + + LinearPartition(result) + +end + +function ⊗(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + tensor_product(p, q) +end + +# TODO think about involution + +""" + subtract(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + +Perform a subtraction between `p` and `q`and return the result. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> linear_tensor_product(a, a) +LinearPartition(SetPartition([1, 1], [1, 1]) => 0) +``` +""" +function subtract(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + add(p, scale(-1, q)) +end + +function -(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + subtract(p, q) +end diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 4763ded1a157..b98669d7b086 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -7,7 +7,9 @@ import Base: deepcopy, deepcopy_internal, hash, - size + size, + -, + + import Oscar: ⊗, @@ -19,11 +21,13 @@ import Oscar: parent, degree, tensor_product, - @req + @req, + RingElement export ColoredPartition export SetPartition export SpatialPartition +export LinearPartition export colored_partition export compose_count_loops @@ -51,6 +55,13 @@ export set_partition export spatial_partition export upper_colors export upper_points +export simplify_operation_zero +export simplify_operation +export add +export scale +export composition +export subtract + include("AbstractPartition.jl") @@ -60,6 +71,7 @@ include("ColoredPartition.jl") include("SpatialPartition.jl") include("PartitionProperties.jl") include("GenerateCategory.jl") +include("LinearCombinations.jl") end using .SetPartitions @@ -67,6 +79,7 @@ using .SetPartitions export ColoredPartition export SetPartition export SpatialPartition +export LinearPartition export colored_partition export compose_count_loops @@ -94,3 +107,9 @@ export set_partition export spatial_partition export upper_colors export upper_points +export simplify_operation_zero +export simplify_operation +export add +export scale +export composition +export subtract diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index e8a17e6b4f16..cc0ad674bc2d 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -123,3 +123,37 @@ function _add_partition_top_bottom(vector::Vector{Dict{Int, Set{T}}}, p::T) wher return vector end + +"""TODO sebvz comment""" +function simplify_operation(partition_sum::Vector) # TODO type + + partitions = Dict() + + for (i1, i2) in partition_sum + + if i2 == 0 # TODO RingElem + deleteat!(partition_sum, findall(x -> x == (i1, i2), partition_sum)) + continue + end + + if !(i1 in keys(partitions)) + partitions[i1] = i2 + else + deleteat!(partition_sum, findall(x -> x == (i1, i2), partition_sum)) + deleteat!(partition_sum, findall(x -> x == (i1, get(partitions, i1, -1)), partition_sum)) + push!(partition_sum, (i1, get(partitions, i1, -1) + i2)) + partitions[i1] = get(partitions, i1, -1) + i2 + end + end + partition_sum +end + +function simplify_operation_zero(p::Dict) + result = Dict() + for (i1, i2) in pairs(p) + if i2 != 0 # TODO RingElem + result[i1] = i2 + end + end + result +end From ebe1b41284b7e8e22f4ef9fdbfa47e906dabbb30 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Fri, 14 Jun 2024 14:11:40 +0200 Subject: [PATCH 02/30] Doctest partially fixed, tests added, renaming --- .../SetPartitions/src/LinearCombinations.jl | 147 ++++++++++-------- .../SetPartitions/src/SetPartitions.jl | 17 +- .../SetPartitions/test/LinearComb-test.jl | 24 +++ 3 files changed, 120 insertions(+), 68 deletions(-) create mode 100644 experimental/SetPartitions/test/LinearComb-test.jl diff --git a/experimental/SetPartitions/src/LinearCombinations.jl b/experimental/SetPartitions/src/LinearCombinations.jl index 0ba289f37772..b4fc6a836a5f 100644 --- a/experimental/SetPartitions/src/LinearCombinations.jl +++ b/experimental/SetPartitions/src/LinearCombinations.jl @@ -2,72 +2,93 @@ Sebvz todos: - deepcopy - dict zugriffe verbessern wenn möglich -- tests -- rename composition +- tests (done) +- rename composition (done) +- LinearSetPartition -> linear_partition +- doctest aufräumen (done) """ +""" +Fragen an Nicolas: +- name LinearSetPartition okay? (davor war er nur LinearPartition) +- Kommentar zeile 189, 139 +- Kommentar in LinearComb-test.jl Zeile 18 (da failt noch ein Test wegen nervigen Typen bruh), Zeile 20 +""" """ - LinearPartition{S <: AbstractPartition, T <: RingElement} + LinearSetPartition{S <: AbstractPartition, T <: RingElement} -Initialize LinearPartition object, while simplifying +Initialize LinearSetPartition object, while simplifying the term. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> LinearPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) -LinearPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) +julia> LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) ``` """ -struct LinearPartition{S <: AbstractPartition, T <: RingElement} +struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} - function LinearPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + function LinearSetPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} new(simplify_operation_zero(coeffs)) end end -function LinearPartition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - LinearPartition{S, T}(coeffs) +function LinearSetPartition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + LinearSetPartition{S, T}(coeffs) +end + +function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + LinearSetPartition{S, T}(coeffs) end # TODO hash -function ==(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - p == q + p.coefficients == q.coefficients end """ - LinearPartition(terms::Vector{Tuple{S, T}}) where - { S <: AbstractPartition, T <: RingElement } + LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } -Return LinearPartition object generated from the Vector `terms` of 2-tuples, +Return LinearSetPartition object generated from the Vector `term` of 2-tuples, where the first element in the tuple is a RingElement and the second a SetPartition. Furthermore simplify the term before initializing -the LinearPartition object with the corresponding dict. +the LinearSetPartition object with the corresponding dict. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> LinearPartition([(SetPartition([1, 1], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) -LinearPartition(Dict(SetPartition([1, 1], [1, 1]) => 4 + 4*d)) +julia> LinearSetPartition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` """ -function LinearPartition(terms::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - LinearPartition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(terms))) +function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + LinearSetPartition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) +end + +function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + LinearSetPartition(term) end -#function LinearPartition{T}(p::S) where { S <: AbstractPartition, T <: RingElement } -# # LinearPartition([(p, one(T))]) -#end +""" + get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + +Get the constructor field `coefficients`, the partition term, in form of a `Dict` from +`SetPartition` to coefficient. +""" +function get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + p.coefficients +end """ - add(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Return the addition between `p` and `q`. @@ -76,14 +97,14 @@ Return the addition between `p` and `q`. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), -(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +(set_partition([1, 1], [1, 1]), 4*d)]) julia> add(a, a) -LinearPartition(SetPartition([1, 2], [1, 1]) => 8, -SetPartition([1, 1], [1, 1]) => 8*d) +LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(8), +SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ -function add(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = copy(p.coefficients) @@ -92,16 +113,16 @@ function add(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where result[i[1]] = get(result, i[1], 0) + i[2] end - LinearPartition(result) + LinearSetPartition(result) end -function +(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } add(p, q) end """ - scale(a::RingElement, p::LinearPartition{S, T}) where + scale(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Multiply each coefficient in `p` with `a` and return @@ -111,29 +132,29 @@ the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> scale(0.5, LinearPartition(SetPartition([1, 2], [1, 1]) => 8, -SetPartition([1, 1], [1, 1]) => 8*d)) -LinearPartition(SetPartition([1, 2], [1, 1]) => 4, -SetPartition([1, 1], [1, 1]) => 4*d) +julia> scale(0.5, LinearSetPartition(set_partition([1, 2], [1, 1]) => S(8), +set_partition([1, 1], [1, 1]) => 8*d)) +LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), +SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ -function scale(a::RingElement, p::LinearPartition{S, T}) where +function scale(a::RingElement, p::LinearSetPartition{S, T}) where # Doctest geht leider nicht weil QQPolyRing kein float erlaubt { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() for (i, n) in pairs(p.coefficients) result[i] = a * n end - LinearPartition(result) + LinearSetPartition(result) end -function *(a::RingElement, p::LinearPartition{S, T}) where +function *(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } scale(a, p) end """ - composition(p::LinearPartition{P, R}, q::LinearPartition{P, R}, d::R) where + linear_composition(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}, d::R) where { P <: AbstractPartition, R <: RingElement } Multiply each coefficient from `p` with each coefficient from `q` @@ -144,14 +165,14 @@ in `p` and `q` and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) julia> linear_composition(a, a) -LinearPartition(SetPartition([1, 2], [1, 1]) => 16*d + 16, -SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d) +LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, +SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ -function composition(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::RingElement) where +function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::RingElement) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() @@ -162,16 +183,16 @@ function composition(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::Ring result[composition] = get(result, composition, 0) + new_coefficient end end - LinearPartition(result) + LinearSetPartition(result) end -function composition(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::RingElement) where +function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::RingElement) where { S <: AbstractPartition, T <: RingElement } - composition(p, q, d) + linear_composition(p, q, d) # Wofür hatten wir die funktion nochmal? end """ - tensor_product(p::LinearPartition{P, R}, q::LinearPartition{P, R}) where + linear_tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where { P <: AbstractPartition, R <: RingElement } Perform a tensor product similar @@ -180,16 +201,16 @@ Perform a tensor product similar ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), -(SetPartition([1, 1], [1, 1]), 4*d)]) +julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +(set_partition([1, 1], [1, 1]), 4*d)]) julia> linear_tensor_product(a, a) -LinearPartition(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, +LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 4*d + 4, -SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 8, -SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4)) +SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), +SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4))) ``` """ -function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function linear_tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() @@ -202,19 +223,19 @@ function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) wher end end - LinearPartition(result) + LinearSetPartition(result) end -function ⊗(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - tensor_product(p, q) + linear_tensor_product(p, q) end # TODO think about involution """ - subtract(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Perform a subtraction between `p` and `q`and return the result. @@ -223,18 +244,18 @@ Perform a subtraction between `p` and `q`and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearPartition([(SetPartition([1, 2], [1, 1]), 4), +julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) -julia> linear_tensor_product(a, a) -LinearPartition(SetPartition([1, 1], [1, 1]) => 0) +julia> subtract(a, a) +LinearSetPartition(Dict(SetPartition([1, 1], [1, 1]) => S(0))) ``` """ -function subtract(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } add(p, scale(-1, q)) end -function -(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where +function -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } subtract(p, q) end diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index b98669d7b086..36d78e4ca835 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -22,12 +22,13 @@ import Oscar: degree, tensor_product, @req, - RingElement + RingElement, + scale export ColoredPartition export SetPartition export SpatialPartition -export LinearPartition +export LinearSetPartition export colored_partition export compose_count_loops @@ -57,9 +58,12 @@ export upper_colors export upper_points export simplify_operation_zero export simplify_operation +export linear_partition +export get_term export add export scale -export composition +export linear_composition +export linear_tensor_product export subtract @@ -79,7 +83,7 @@ using .SetPartitions export ColoredPartition export SetPartition export SpatialPartition -export LinearPartition +export LinearSetPartition export colored_partition export compose_count_loops @@ -109,7 +113,10 @@ export upper_colors export upper_points export simplify_operation_zero export simplify_operation +export linear_partition +export get_term export add export scale -export composition +export linear_composition +export linear_tensor_product export subtract diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl new file mode 100644 index 000000000000..64ffe429f678 --- /dev/null +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -0,0 +1,24 @@ +@testset "LinearCombinations of SetPartitions" begin + @testset "LinearSetPartition Constructor" begin + S, d = polynomial_ring(QQ, "d") + @test get_term(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) + @test get_term(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) + @test get_term(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) + end + + @testset "LinearPartition Operations" begin + S, d = polynomial_ring(QQ, "d") + a = linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 5*d)]) + @test add(a, a) == a + a == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 10*d)) + @test add(a, linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)])) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) + + @test scale(S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d))) == S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) + + a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + @test linear_composition(a, a) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) # nerviger typ error den ich nicht checke weil es ja für die anderen geht + + @test linear_tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 4*d + 4, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4)) # der test failt aber da bräuchte ich nochmal die definition von diesem tensor product um das genau zu fixen + + @test subtract(a, a) == a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) + end +end From a307173cfe4053c669c53865f694e63dd87e797c Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 18 Jun 2024 10:28:09 +0200 Subject: [PATCH 03/30] deepcopy, fixed test, hash --- .../SetPartitions/src/LinearCombinations.jl | 91 +++++++++---------- .../SetPartitions/test/LinearComb-test.jl | 4 +- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/experimental/SetPartitions/src/LinearCombinations.jl b/experimental/SetPartitions/src/LinearCombinations.jl index b4fc6a836a5f..b443bdde7321 100644 --- a/experimental/SetPartitions/src/LinearCombinations.jl +++ b/experimental/SetPartitions/src/LinearCombinations.jl @@ -1,18 +1,7 @@ -""" -Sebvz todos: -- deepcopy -- dict zugriffe verbessern wenn möglich -- tests (done) -- rename composition (done) -- LinearSetPartition -> linear_partition -- doctest aufräumen (done) -""" - """ Fragen an Nicolas: - name LinearSetPartition okay? (davor war er nur LinearPartition) -- Kommentar zeile 189, 139 -- Kommentar in LinearComb-test.jl Zeile 18 (da failt noch ein Test wegen nervigen Typen bruh), Zeile 20 +- Kommentar zeile 195, 139 """ """ @@ -45,12 +34,32 @@ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T < LinearSetPartition{S, T}(coeffs) end +""" + get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } -# TODO hash +Get the constructor field `coefficients`, the partition term, in form of a `Dict` from +`SetPartition` to coefficient. +""" +function get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + p.coefficients +end + +function hash(p::LinearSetPartition, h::UInt) + return hash(p.coefficients) +end function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - p.coefficients == q.coefficients + get_term(p) == get_term(q) +end + +function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) + if haskey(stackdict, p) + return stackdict[p] + end + q = LinearSetPartition(deepcopy_internal(get_term(p), stackdict)) + stackdict[p] = q + return q end """ @@ -77,15 +86,7 @@ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartit LinearSetPartition(term) end -""" - get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } -Get the constructor field `coefficients`, the partition term, in form of a `Dict` from -`SetPartition` to coefficient. -""" -function get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - p.coefficients -end """ add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -97,7 +98,7 @@ Return the addition between `p` and `q`. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) julia> add(a, a) LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(8), @@ -107,13 +108,13 @@ SetPartition([1, 1], [1, 1]) => 8*d)) function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - result = copy(p.coefficients) + result = deepcopy(p) - for i in pairs(q.coefficients) - result[i[1]] = get(result, i[1], 0) + i[2] + for i in pairs(get_term(q)) + get_term(result)[i[1]] = get(get_term(result), i[1], 0) + i[2] end - LinearSetPartition(result) + LinearSetPartition(get_term(result)) end function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -132,7 +133,7 @@ the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> scale(0.5, LinearSetPartition(set_partition([1, 2], [1, 1]) => S(8), +julia> scale(0.5, linear_partition(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d)) LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) @@ -142,7 +143,7 @@ function scale(a::RingElement, p::LinearSetPartition{S, T}) where # Doctest geht { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for (i, n) in pairs(p.coefficients) + for (i, n) in pairs(get_term(p)) result[i] = a * n end LinearSetPartition(result) @@ -154,8 +155,8 @@ function *(a::RingElement, p::LinearSetPartition{S, T}) where end """ - linear_composition(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}, d::R) where - { P <: AbstractPartition, R <: RingElement } + linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where + { S <: AbstractPartition, T <: RingElement } Multiply each coefficient from `p` with each coefficient from `q` as well as perform a composition between each SetPartition part @@ -165,20 +166,20 @@ in `p` and `q` and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) -julia> linear_composition(a, a) +julia> linear_composition(a, a, d) LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ -function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::RingElement) where +function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for i in pairs(p.coefficients) - for ii in pairs(q.coefficients) - (composition, loop) = composition_loops(i[1], ii[1]) + for i in pairs(get_term(p)) + for ii in pairs(get_term(q)) + (composition, loop) = compose_count_loops(i[1], ii[1]) new_coefficient = i[2] * ii[2] * (d^loop) result[composition] = get(result, composition, 0) + new_coefficient end @@ -201,13 +202,13 @@ Perform a tensor product similar ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) julia> linear_tensor_product(a, a) -LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, -SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 4*d + 4, +LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, +SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), -SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4))) +SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d))) ``` """ function linear_tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -215,8 +216,8 @@ function linear_tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartitio result = Dict{S, T}() - for i in pairs(p.coefficients) - for ii in pairs(q.coefficients) + for i in pairs(get_term(p)) + for ii in pairs(get_term(q)) composition = tensor_product(i[1], ii[1]) new_coefficient = i[2] * ii[2] result[composition] = get(result, composition, 0) + new_coefficient @@ -232,8 +233,6 @@ function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where linear_tensor_product(p, q) end -# TODO think about involution - """ subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } @@ -244,7 +243,7 @@ Perform a subtraction between `p` and `q`and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> a = LinearSetPartition([(set_partition([1, 2], [1, 1]), S(4)), +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) julia> subtract(a, a) LinearSetPartition(Dict(SetPartition([1, 1], [1, 1]) => S(0))) diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index 64ffe429f678..2bfc68354ba2 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -15,9 +15,9 @@ @test scale(S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d))) == S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) - @test linear_composition(a, a) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) # nerviger typ error den ich nicht checke weil es ja für die anderen geht + @test linear_composition(a, a, d) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) - @test linear_tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 8*d, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 4*d + 4, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 4*d + 4)) # der test failt aber da bräuchte ich nochmal die definition von diesem tensor product um das genau zu fixen + @test linear_tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) @test subtract(a, a) == a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) end From e6d82e9fdc94f5fcdae7cdc1abda84b7421948e3 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 2 Jul 2024 16:07:14 +0200 Subject: [PATCH 04/30] minor comments --- experimental/SetPartitions/src/LinearCombinations.jl | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/experimental/SetPartitions/src/LinearCombinations.jl b/experimental/SetPartitions/src/LinearCombinations.jl index b443bdde7321..298a4cf0490b 100644 --- a/experimental/SetPartitions/src/LinearCombinations.jl +++ b/experimental/SetPartitions/src/LinearCombinations.jl @@ -1,7 +1,7 @@ """ Fragen an Nicolas: - name LinearSetPartition okay? (davor war er nur LinearPartition) -- Kommentar zeile 195, 139 +- Kommentar zeile 140 """ """ @@ -45,7 +45,7 @@ function get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T end function hash(p::LinearSetPartition, h::UInt) - return hash(p.coefficients) + return hash(p.coefficients, h) end function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -187,11 +187,6 @@ function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S LinearSetPartition(result) end -function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::RingElement) where - { S <: AbstractPartition, T <: RingElement } - linear_composition(p, q, d) # Wofür hatten wir die funktion nochmal? -end - """ linear_tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where { P <: AbstractPartition, R <: RingElement } From ac62a5a3f64bb404b8441b67ee1699f3621f7e8d Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Mon, 8 Jul 2024 10:56:18 +0200 Subject: [PATCH 05/30] comments, renaming, test, scale fix, using linear_partition ... --- ...rCombinations.jl => LinearSetPartition.jl} | 117 ++++++++++-------- .../SetPartitions/src/SetPartitions.jl | 10 +- .../SetPartitions/test/LinearComb-test.jl | 11 +- 3 files changed, 73 insertions(+), 65 deletions(-) rename experimental/SetPartitions/src/{LinearCombinations.jl => LinearSetPartition.jl} (67%) diff --git a/experimental/SetPartitions/src/LinearCombinations.jl b/experimental/SetPartitions/src/LinearSetPartition.jl similarity index 67% rename from experimental/SetPartitions/src/LinearCombinations.jl rename to experimental/SetPartitions/src/LinearSetPartition.jl index 298a4cf0490b..07aeb98bc485 100644 --- a/experimental/SetPartitions/src/LinearCombinations.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -1,22 +1,19 @@ """ Fragen an Nicolas: -- name LinearSetPartition okay? (davor war er nur LinearPartition) -- Kommentar zeile 140 -""" +- alles was mit NICOLAS im dokument markiert ist +- wir haben uns ja hier jetzt auf `get_coefficients` geeinigt, jedoch haben wir bei den Partitions zb + anstatt get upper points nur upper_points als getter. sollen wir dann hier doch nur coefficients? +- @req ? """ - LinearSetPartition{S <: AbstractPartition, T <: RingElement} -Initialize LinearSetPartition object, while simplifying -the term. +""" + LinearSetPartition -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) -LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) -``` +LinearSetPartition represents linear combinations of +of partitions of sets of upper and lower points +into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). +# NICOLAS paper LinearSetPartitions (find da aber vllt selber was muss ja nur bei Moritz gucken) """ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} @@ -26,44 +23,64 @@ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} end end -function LinearSetPartition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - LinearSetPartition{S, T}(coeffs) -end +""" + linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + +Initialize LinearSetPartition object, while simplifying the term. +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in x over QQ, d) +julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +""" function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} LinearSetPartition{S, T}(coeffs) end """ - get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + get_coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Get the constructor field `coefficients`, the partition term, in form of a `Dict` from `SetPartition` to coefficient. -""" -function get_term(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } +""" +function get_coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } p.coefficients end function hash(p::LinearSetPartition, h::UInt) - return hash(p.coefficients, h) + return hash(get_coefficients(p), h) end function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - get_term(p) == get_term(q) + get_coefficients(p) == get_coefficients(q) end function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) if haskey(stackdict, p) return stackdict[p] end - q = LinearSetPartition(deepcopy_internal(get_term(p), stackdict)) + q = linear_partition(deepcopy_internal(get_coefficients(p), stackdict)) stackdict[p] = q return q end """ - LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + LinearSetPartition + +LinearSetPartition represents linear combinations of +of partitions of sets of upper and lower points +into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). +# NICOLAS paper LinearSetPartitions (find da aber vllt selber was muss ja nur bei Moritz gucken) +""" +function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) +end + +""" + linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } Return LinearSetPartition object generated from the Vector `term` of 2-tuples, where the first element in the tuple is a RingElement and the second @@ -74,20 +91,14 @@ the LinearSetPartition object with the corresponding dict. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> LinearSetPartition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +julia> linear_partition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` """ -function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - LinearSetPartition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) -end - function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } LinearSetPartition(term) end - - """ add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } @@ -110,11 +121,11 @@ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where result = deepcopy(p) - for i in pairs(get_term(q)) - get_term(result)[i[1]] = get(get_term(result), i[1], 0) + i[2] + for i in pairs(get_coefficients(q)) + get_coefficients(result)[i[1]] = get(get_coefficients(result), i[1], 0) + i[2] end - LinearSetPartition(get_term(result)) + linear_partition(get_coefficients(result)) end function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -133,20 +144,20 @@ the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) -julia> scale(0.5, linear_partition(set_partition([1, 2], [1, 1]) => S(8), -set_partition([1, 1], [1, 1]) => 8*d)) +julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), +set_partition([1, 1], [1, 1]) => 8*d))) LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ -function scale(a::RingElement, p::LinearSetPartition{S, T}) where # Doctest geht leider nicht weil QQPolyRing kein float erlaubt +function scale(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for (i, n) in pairs(get_term(p)) + for (i, n) in pairs(get_coefficients(p)) result[i] = a * n end - LinearSetPartition(result) + linear_partition(result) end function *(a::RingElement, p::LinearSetPartition{S, T}) where @@ -154,8 +165,8 @@ function *(a::RingElement, p::LinearSetPartition{S, T}) where scale(a, p) end -""" - linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where +""" nur composition TODO + compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where { S <: AbstractPartition, T <: RingElement } Multiply each coefficient from `p` with each coefficient from `q` @@ -168,27 +179,27 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) -julia> linear_composition(a, a, d) +julia> compose(a, a, d) LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ -function linear_composition(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where +function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for i in pairs(get_term(p)) - for ii in pairs(get_term(q)) + for i in pairs(get_coefficients(p)) + for ii in pairs(get_coefficients(q)) (composition, loop) = compose_count_loops(i[1], ii[1]) new_coefficient = i[2] * ii[2] * (d^loop) result[composition] = get(result, composition, 0) + new_coefficient end end - LinearSetPartition(result) + linear_partition(result) end """ - linear_tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where + tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where { P <: AbstractPartition, R <: RingElement } Perform a tensor product similar @@ -199,40 +210,40 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in x over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -julia> linear_tensor_product(a, a) +julia> tensor_product(a, a) LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d))) ``` """ -function linear_tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where +function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for i in pairs(get_term(p)) - for ii in pairs(get_term(q)) + for i in pairs(get_coefficients(p)) + for ii in pairs(get_coefficients(q)) composition = tensor_product(i[1], ii[1]) new_coefficient = i[2] * ii[2] result[composition] = get(result, composition, 0) + new_coefficient end end - LinearSetPartition(result) + linear_partition(result) end function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - linear_tensor_product(p, q) + tensor_product(p, q) end """ subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } -Perform a subtraction between `p` and `q`and return the result. +Perform a subtraction between `p` and `q` and return the result. # Examples ```jldoctest diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 36d78e4ca835..1c7c56691d00 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -59,11 +59,9 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export get_term +export get_coefficients export add export scale -export linear_composition -export linear_tensor_product export subtract @@ -75,7 +73,7 @@ include("ColoredPartition.jl") include("SpatialPartition.jl") include("PartitionProperties.jl") include("GenerateCategory.jl") -include("LinearCombinations.jl") +include("LinearSetPartition.jl") end using .SetPartitions @@ -114,9 +112,7 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export get_term +export get_coefficients export add export scale -export linear_composition -export linear_tensor_product export subtract diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index 2bfc68354ba2..664f76626caf 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -1,9 +1,9 @@ @testset "LinearCombinations of SetPartitions" begin @testset "LinearSetPartition Constructor" begin S, d = polynomial_ring(QQ, "d") - @test get_term(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) - @test get_term(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) - @test get_term(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) + @test get_coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) + @test get_coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) + @test get_coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) end @testset "LinearPartition Operations" begin @@ -13,11 +13,12 @@ @test add(a, linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)])) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) @test scale(S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d))) == S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) + @test scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) == linear_partition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) - @test linear_composition(a, a, d) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) + @test compose(a, a, d) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) - @test linear_tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) + @test tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) @test subtract(a, a) == a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) end From 41270755817a07e9a7f04a22d3bd7ef32ca196e7 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Mon, 8 Jul 2024 11:02:15 +0200 Subject: [PATCH 06/30] return stmt --- .../SetPartitions/src/LinearSetPartition.jl | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 07aeb98bc485..53a53f677e38 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -19,7 +19,7 @@ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} function LinearSetPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - new(simplify_operation_zero(coeffs)) + return new(simplify_operation_zero(coeffs)) end end @@ -36,7 +36,7 @@ julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partitio LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) """ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - LinearSetPartition{S, T}(coeffs) + return LinearSetPartition{S, T}(coeffs) end """ @@ -46,7 +46,7 @@ Get the constructor field `coefficients`, the partition term, in form of a `Dict `SetPartition` to coefficient. """ function get_coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - p.coefficients + return p.coefficients end function hash(p::LinearSetPartition, h::UInt) @@ -55,7 +55,7 @@ end function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - get_coefficients(p) == get_coefficients(q) + return get_coefficients(p) == get_coefficients(q) end function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) @@ -76,7 +76,7 @@ into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). # NICOLAS paper LinearSetPartitions (find da aber vllt selber was muss ja nur bei Moritz gucken) """ function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) + return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) end """ @@ -96,7 +96,7 @@ LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` """ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - LinearSetPartition(term) + return LinearSetPartition(term) end """ @@ -125,12 +125,12 @@ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where get_coefficients(result)[i[1]] = get(get_coefficients(result), i[1], 0) + i[2] end - linear_partition(get_coefficients(result)) + return linear_partition(get_coefficients(result)) end function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - add(p, q) + return add(p, q) end """ @@ -157,12 +157,12 @@ function scale(a::RingElement, p::LinearSetPartition{S, T}) where for (i, n) in pairs(get_coefficients(p)) result[i] = a * n end - linear_partition(result) + return linear_partition(result) end function *(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - scale(a, p) + return scale(a, p) end """ nur composition TODO @@ -195,7 +195,7 @@ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) result[composition] = get(result, composition, 0) + new_coefficient end end - linear_partition(result) + return linear_partition(result) end """ @@ -230,13 +230,12 @@ function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T} end end - linear_partition(result) - + return linear_partition(result) end function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - tensor_product(p, q) + return tensor_product(p, q) end """ @@ -257,10 +256,10 @@ LinearSetPartition(Dict(SetPartition([1, 1], [1, 1]) => S(0))) """ function subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - add(p, scale(-1, q)) + return add(p, scale(-1, q)) end function -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - subtract(p, q) + return subtract(p, q) end From b21bb58efd964e713ced547ac2ad3866462ef7fd Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 14:43:11 +0200 Subject: [PATCH 07/30] cite and get_coefficients --- .../SetPartitions/src/LinearSetPartition.jl | 43 +++++++------------ .../SetPartitions/src/SetPartitions.jl | 4 +- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 53a53f677e38..0a9c631f44c4 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -1,19 +1,7 @@ -""" -Fragen an Nicolas: -- alles was mit NICOLAS im dokument markiert ist -- wir haben uns ja hier jetzt auf `get_coefficients` geeinigt, jedoch haben wir bei den Partitions zb - anstatt get upper points nur upper_points als getter. sollen wir dann hier doch nur coefficients? - -- @req ? -""" - """ LinearSetPartition -LinearSetPartition represents linear combinations of -of partitions of sets of upper and lower points -into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). -# NICOLAS paper LinearSetPartitions (find da aber vllt selber was muss ja nur bei Moritz gucken) +LinearSetPartition represents a linear combination of set-partitions. See Chapter 5 in [Gro20](@cite). """ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} @@ -40,29 +28,29 @@ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T < end """ - get_coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Get the constructor field `coefficients`, the partition term, in form of a `Dict` from `SetPartition` to coefficient. """ -function get_coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } +function coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } return p.coefficients end function hash(p::LinearSetPartition, h::UInt) - return hash(get_coefficients(p), h) + return hash(coefficients(p), h) end function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - return get_coefficients(p) == get_coefficients(q) + return coefficients(p) == coefficients(q) end function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) if haskey(stackdict, p) return stackdict[p] end - q = linear_partition(deepcopy_internal(get_coefficients(p), stackdict)) + q = linear_partition(deepcopy_internal(coefficients(p), stackdict)) stackdict[p] = q return q end @@ -72,8 +60,7 @@ end LinearSetPartition represents linear combinations of of partitions of sets of upper and lower points -into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). -# NICOLAS paper LinearSetPartitions (find da aber vllt selber was muss ja nur bei Moritz gucken) +into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). TODO """ function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) @@ -121,11 +108,11 @@ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where result = deepcopy(p) - for i in pairs(get_coefficients(q)) - get_coefficients(result)[i[1]] = get(get_coefficients(result), i[1], 0) + i[2] + for i in pairs(coefficients(q)) + coefficients(result)[i[1]] = get(coefficients(result), i[1], 0) + i[2] end - return linear_partition(get_coefficients(result)) + return linear_partition(coefficients(result)) end function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -154,7 +141,7 @@ function scale(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for (i, n) in pairs(get_coefficients(p)) + for (i, n) in pairs(coefficients(p)) result[i] = a * n end return linear_partition(result) @@ -188,8 +175,8 @@ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() - for i in pairs(get_coefficients(p)) - for ii in pairs(get_coefficients(q)) + for i in pairs(coefficients(p)) + for ii in pairs(coefficients(q)) (composition, loop) = compose_count_loops(i[1], ii[1]) new_coefficient = i[2] * ii[2] * (d^loop) result[composition] = get(result, composition, 0) + new_coefficient @@ -222,8 +209,8 @@ function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T} result = Dict{S, T}() - for i in pairs(get_coefficients(p)) - for ii in pairs(get_coefficients(q)) + for i in pairs(coefficients(p)) + for ii in pairs(coefficients(q)) composition = tensor_product(i[1], ii[1]) new_coefficient = i[2] * ii[2] result[composition] = get(result, composition, 0) + new_coefficient diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 1c7c56691d00..ffffd2f765bb 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -59,7 +59,7 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export get_coefficients +export coefficients export add export scale export subtract @@ -112,7 +112,7 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export get_coefficients +export coefficients export add export scale export subtract From ba5188a0c6abaea8f46576b4174469de30a70174 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 14:49:58 +0200 Subject: [PATCH 08/30] comments --- .../SetPartitions/src/LinearSetPartition.jl | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 0a9c631f44c4..407fa6f9b577 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -55,24 +55,13 @@ function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) return q end -""" - LinearSetPartition - -LinearSetPartition represents linear combinations of -of partitions of sets of upper and lower points -into disjoint subsets. See Section 4.1.1 in [Gro20](@cite). TODO -""" -function LinearSetPartition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) -end - """ linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } -Return LinearSetPartition object generated from the Vector `term` of 2-tuples, -where the first element in the tuple is a RingElement and the second -a SetPartition. Furthermore simplify the term before initializing -the LinearSetPartition object with the corresponding dict. +Return a `LinearSetPartition` generated from the Vector `term` of 2-tuples, +where the first element in the tuple is a `RingElement` and the second +a `SetPartition`. Furthermore simplify the term before initializing +the `LinearSetPartition` object with the corresponding dict. # Examples ```jldoctest @@ -83,7 +72,7 @@ LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` """ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - return LinearSetPartition(term) + return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) end """ @@ -152,7 +141,7 @@ function *(a::RingElement, p::LinearSetPartition{S, T}) where return scale(a, p) end -""" nur composition TODO +""" compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where { S <: AbstractPartition, T <: RingElement } @@ -189,7 +178,7 @@ end tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where { P <: AbstractPartition, R <: RingElement } -Perform a tensor product similar +Return the tensor product of `p` and `q`. # Examples ```jldoctest From 0636ae8040fc61c58867126138fe1b4a5c56efdd Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 14:50:59 +0200 Subject: [PATCH 09/30] readme --- experimental/SetPartitions/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/experimental/SetPartitions/README.md b/experimental/SetPartitions/README.md index a0c28c6b79cf..0069314df1f6 100644 --- a/experimental/SetPartitions/README.md +++ b/experimental/SetPartitions/README.md @@ -13,10 +13,7 @@ This includes: * basic set-partitions and operations on them (e.g. composition, tensor product, involution) * variations like colored partitions [TW18](@cite) and spatial partitions [CW16](@cite) * enumeration of partitions which can be constructed from a set of generators - -In the future, we plan to implement: * linear combinations of partitions -* examples of tensor categories in the framework of [TensorCategories.jl](https://github.com/FabianMaeurer/TensorCategories.jl) ## Contact From 3571eaa69cd60387fe10d42dc0ba972226a0d032 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 14:54:36 +0200 Subject: [PATCH 10/30] import coefficients --- experimental/SetPartitions/src/SetPartitions.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index ffffd2f765bb..832aaa256c9b 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -23,7 +23,8 @@ import Oscar: tensor_product, @req, RingElement, - scale + scale, + coefficients export ColoredPartition export SetPartition @@ -59,7 +60,6 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export coefficients export add export scale export subtract @@ -112,7 +112,6 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export coefficients export add export scale export subtract From 9842ff4da37d70e10b4af429d9becaa55f28d7be Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 14:56:02 +0200 Subject: [PATCH 11/30] test fix --- experimental/SetPartitions/test/LinearComb-test.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index 664f76626caf..c2db1f88748d 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -1,9 +1,9 @@ @testset "LinearCombinations of SetPartitions" begin @testset "LinearSetPartition Constructor" begin S, d = polynomial_ring(QQ, "d") - @test get_coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) - @test get_coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) - @test get_coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) + @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) + @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) + @test coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) end @testset "LinearPartition Operations" begin From a6d8169e774d9d832549332805891077695bd1c6 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 15:59:04 +0200 Subject: [PATCH 12/30] iszerro --- .../SetPartitions/src/SetPartitions.jl | 3 ++- experimental/SetPartitions/src/Util.jl | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 832aaa256c9b..adfb46a2ee36 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -24,7 +24,8 @@ import Oscar: @req, RingElement, scale, - coefficients + coefficients, + iszero export ColoredPartition export SetPartition diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index cc0ad674bc2d..f998374dad35 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -124,14 +124,18 @@ function _add_partition_top_bottom(vector::Vector{Dict{Int, Set{T}}}, p::T) wher return vector end -"""TODO sebvz comment""" -function simplify_operation(partition_sum::Vector) # TODO type +""" + simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } + +Simplify the vector representation of a `LinearSetPartition` in terms of associativity. +""" +function simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - partitions = Dict() + partitions = Dict{S, T}() for (i1, i2) in partition_sum - if i2 == 0 # TODO RingElem + if iszero(i2) deleteat!(partition_sum, findall(x -> x == (i1, i2), partition_sum)) continue end @@ -145,15 +149,20 @@ function simplify_operation(partition_sum::Vector) # TODO type partitions[i1] = get(partitions, i1, -1) + i2 end end - partition_sum + return partition_sum end -function simplify_operation_zero(p::Dict) - result = Dict() +""" + simplify_operation_zero(p::Dict{S, T}) where { S <: AbstractPartition, T <: RingElement } + +Simplify the dict representation of a `LinearSetPartition` in terms of zero coefficients. +""" +function simplify_operation_zero(p::Dict{S, T}) where { S <: AbstractPartition, T <: RingElement } + result = Dict{S, T}() for (i1, i2) in pairs(p) - if i2 != 0 # TODO RingElem + if !iszero(i2) result[i1] = i2 end end - result + return result end From d963179f6e7a19f71367c2873dd5bebd1db1cc37 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 16 Jul 2024 16:40:18 +0200 Subject: [PATCH 13/30] doctest fixes --- .../SetPartitions/src/LinearSetPartition.jl | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 407fa6f9b577..17797a30bf33 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -19,7 +19,7 @@ Initialize LinearSetPartition object, while simplifying the term. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) +(Univariate polynomial ring in d over QQ, d) julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) """ @@ -66,7 +66,7 @@ the `LinearSetPartition` object with the corresponding dict. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) +(Univariate polynomial ring in d over QQ, d) julia> linear_partition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` @@ -84,12 +84,10 @@ Return the addition between `p` and `q`. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), -(set_partition([1, 1], [1, 1]), 4*d)]) +(Univariate polynomial ring in d over QQ, d) +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) julia> add(a, a) -LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(8), -SetPartition([1, 1], [1, 1]) => 8*d)) +LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(8), SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -119,11 +117,9 @@ the result. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), -set_partition([1, 1], [1, 1]) => 8*d))) -LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), -SetPartition([1, 1], [1, 1]) => 4*d)) +(Univariate polynomial ring in d over QQ, d) +julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) +LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ function scale(a::RingElement, p::LinearSetPartition{S, T}) where @@ -152,12 +148,10 @@ in `p` and `q` and return the result. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), -(SetPartition([1, 1], [1, 1]), 4*d)]) +(Univariate polynomial ring in d over QQ, d) +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) julia> compose(a, a, d) -LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, -SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) +LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where @@ -183,9 +177,8 @@ Return the tensor product of `p` and `q`. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), -(set_partition([1, 1], [1, 1]), 4*d)]) +(Univariate polynomial ring in d over QQ, d) +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) julia> tensor_product(a, a) LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, @@ -223,9 +216,8 @@ Perform a subtraction between `p` and `q` and return the result. # Examples ```jldoctest julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in x over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), -(SetPartition([1, 1], [1, 1]), 4*d)]) +(Univariate polynomial ring in d over QQ, d) +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) julia> subtract(a, a) LinearSetPartition(Dict(SetPartition([1, 1], [1, 1]) => S(0))) ``` From e4fe5a5788f8cb60f241aedc141919a8a9b51fd7 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Wed, 17 Jul 2024 10:32:38 +0200 Subject: [PATCH 14/30] trying to fix doctest --- .../SetPartitions/src/LinearSetPartition.jl | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 17797a30bf33..b285d86042c8 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -20,20 +20,21 @@ Initialize LinearSetPartition object, while simplifying the term. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) + julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) -LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) """ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} return LinearSetPartition{S, T}(coeffs) end """ - coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } + coefficients(p::LinearSetPartition) Get the constructor field `coefficients`, the partition term, in form of a `Dict` from `SetPartition` to coefficient. """ -function coefficients(p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } +function coefficients(p::LinearSetPartition) return p.coefficients end @@ -67,8 +68,9 @@ the `LinearSetPartition` object with the corresponding dict. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) + julia> linear_partition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) +linear_partition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) ``` """ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } @@ -85,9 +87,11 @@ Return the addition between `p` and `q`. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) + julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + julia> add(a, a) -LinearSetPartition(Dict(set_partition([1, 2], [1, 1]) => S(8), SetPartition([1, 1], [1, 1]) => 8*d)) +linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d)) ``` """ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -118,8 +122,9 @@ the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) + julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) -LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) +linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) ``` """ function scale(a::RingElement, p::LinearSetPartition{S, T}) where @@ -132,8 +137,7 @@ function scale(a::RingElement, p::LinearSetPartition{S, T}) where return linear_partition(result) end -function *(a::RingElement, p::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } +function *(a::RingElement, p::LinearSetPartition) return scale(a, p) end @@ -149,9 +153,11 @@ in `p` and `q` and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) + +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + julia> compose(a, a, d) -LinearSetPartition(Dict(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) +linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where @@ -178,12 +184,14 @@ Return the tensor product of `p` and `q`. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) + julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + julia> tensor_product(a, a) -LinearSetPartition(Dict(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, -SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, -SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), -SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d))) +linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, +set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, +set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), +set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d))) ``` """ function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -217,9 +225,11 @@ Perform a subtraction between `p` and `q` and return the result. ```jldoctest julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (SetPartition([1, 1], [1, 1]), 4*d)]) + +julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + julia> subtract(a, a) -LinearSetPartition(Dict(SetPartition([1, 1], [1, 1]) => S(0))) +linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) ``` """ function subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where From b08bef8748380076b2b643747324a47e17883e62 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Wed, 17 Jul 2024 11:34:33 +0200 Subject: [PATCH 15/30] doctest fix 2.0 --- .../SetPartitions/src/LinearSetPartition.jl | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index b285d86042c8..b2d6e3ac4782 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -22,7 +22,8 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) -linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) """ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} return LinearSetPartition{S, T}(coeffs) @@ -70,7 +71,7 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> linear_partition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -linear_partition(Dict(set_partition([1, 1], [1, 1]) => 4 + 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1], [1, 1]) => 4*d + 4)) ``` """ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } @@ -89,9 +90,12 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) julia> add(a, a) -linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(8), SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -124,7 +128,8 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) -linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ function scale(a::RingElement, p::LinearSetPartition{S, T}) where @@ -155,9 +160,13 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(4), + SetPartition([1, 1], [1, 1]) => 4*d)) julia> compose(a, a, d) -linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where @@ -188,10 +197,11 @@ julia> S, d = polynomial_ring(QQ, "d") julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) julia> tensor_product(a, a) -linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, -set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, -set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), -set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d))) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, + SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, + SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), + SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) ``` """ function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -227,9 +237,11 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( + SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) julia> subtract(a, a) -linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}()) ``` """ function subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where From de2835cb8962a4493064d7d3888a883ea0fd02b1 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 23 Jul 2024 14:43:37 +0200 Subject: [PATCH 16/30] S(X) -> X for doctest --- .../SetPartitions/src/LinearSetPartition.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index b2d6e3ac4782..82d9538cad44 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -23,7 +23,7 @@ julia> S, d = polynomial_ring(QQ, "d") julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) """ function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} return LinearSetPartition{S, T}(coeffs) @@ -91,11 +91,11 @@ julia> S, d = polynomial_ring(QQ, "d") julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> add(a, a) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(8), SetPartition([1, 1], [1, 1]) => 8*d)) + SetPartition([1, 2], [1, 1]) => 8, SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -129,7 +129,7 @@ julia> S, d = polynomial_ring(QQ, "d") julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ function scale(a::RingElement, p::LinearSetPartition{S, T}) where @@ -161,7 +161,7 @@ julia> S, d = polynomial_ring(QQ, "d") julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(4), + SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> compose(a, a, d) @@ -200,7 +200,7 @@ julia> tensor_product(a, a) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, - SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), + SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) ``` """ @@ -238,7 +238,7 @@ julia> S, d = polynomial_ring(QQ, "d") julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> subtract(a, a) LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}()) From 9fb53137329504ef99843939c2b10121aa55be38 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Tue, 23 Jul 2024 14:52:40 +0200 Subject: [PATCH 17/30] removed add and substract --- .../SetPartitions/src/LinearSetPartition.jl | 26 ++++++------------- .../SetPartitions/src/SetPartitions.jl | 4 --- .../SetPartitions/test/LinearComb-test.jl | 6 ++--- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 82d9538cad44..db47d8cfd561 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -79,7 +79,7 @@ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartit end """ - add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where + +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Return the addition between `p` and `q`. @@ -93,12 +93,12 @@ julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partiti LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) -julia> add(a, a) +julia> a + a LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( SetPartition([1, 2], [1, 1]) => 8, SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ -function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where +function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = deepcopy(p) @@ -110,11 +110,6 @@ function add(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where return linear_partition(coefficients(result)) end -function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return add(p, q) -end - """ scale(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } @@ -226,7 +221,7 @@ function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where end """ - subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where + -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } Perform a subtraction between `p` and `q` and return the result. @@ -240,16 +235,11 @@ julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partiti LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) -julia> subtract(a, a) +julia> a - a LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}()) ``` """ -function subtract(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return add(p, scale(-1, q)) -end - function -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return subtract(p, q) -end + { S <: AbstractPartition, T <: RingElement } + return p + scale(-1, q) +end diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index adfb46a2ee36..5804fe6ebf6c 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -61,9 +61,7 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export add export scale -export subtract @@ -113,6 +111,4 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export add export scale -export subtract diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index c2db1f88748d..9e85af57432e 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -9,8 +9,8 @@ @testset "LinearPartition Operations" begin S, d = polynomial_ring(QQ, "d") a = linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 5*d)]) - @test add(a, a) == a + a == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 10*d)) - @test add(a, linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)])) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) + @test a + a == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 10*d)) + @test a + linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)]) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) @test scale(S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d))) == S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) @test scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) == linear_partition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) @@ -20,6 +20,6 @@ @test tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) - @test subtract(a, a) == a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) + @test a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) end end From 3028f5a1dc4087fa54b89581748b57db554508c8 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Wed, 24 Jul 2024 15:41:39 +0200 Subject: [PATCH 18/30] doctest without line breaks --- .../SetPartitions/src/LinearSetPartition.jl | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index db47d8cfd561..6ebd0b7909d1 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -90,12 +90,10 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> a + a -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 8, SetPartition([1, 1], [1, 1]) => 8*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 8, SetPartition([1, 1], [1, 1]) => 8*d)) ``` """ function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -123,8 +121,7 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) ``` """ function scale(a::RingElement, p::LinearSetPartition{S, T}) where @@ -155,13 +152,10 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 4, - SetPartition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> compose(a, a, d) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) ``` """ function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where @@ -190,13 +184,10 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> tensor_product(a, a) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, - SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, - SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, - SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) ``` """ function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where @@ -232,8 +223,7 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) +LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) julia> a - a LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}()) From 97a9b63fd7d6eeb3523fc2749bdb7468a59fe9e7 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Thu, 25 Jul 2024 12:29:03 +0200 Subject: [PATCH 19/30] feedback implementation part 1 --- .../SetPartitions/src/LinearSetPartition.jl | 71 +++---------------- .../SetPartitions/src/SetPartitions.jl | 3 - experimental/SetPartitions/src/Util.jl | 27 +++---- .../SetPartitions/test/LinearComb-test.jl | 6 +- 4 files changed, 29 insertions(+), 78 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 6ebd0b7909d1..7a127f8d0194 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -7,6 +7,9 @@ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} function LinearSetPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} + key_types = Set(typeof(k) for k in keys(coeffs)) + @req length(key_types) <= 1 "keys in the coefficients dictionary must be of the same subtype of AbstractPartition" + return new(simplify_operation_zero(coeffs)) end end @@ -78,53 +81,19 @@ function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartit return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) end -""" - +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - -Return the addition between `p` and `q`. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) - -julia> a + a -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 8, SetPartition([1, 1], [1, 1]) => 8*d)) -``` -""" function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - result = deepcopy(p) + result = deepcopy(coefficients(p)) for i in pairs(coefficients(q)) - coefficients(result)[i[1]] = get(coefficients(result), i[1], 0) + i[2] + result[i[1]] = get(result, i[1], 0) + i[2] end - return linear_partition(coefficients(result)) + return linear_partition(result) end -""" - scale(a::RingElement, p::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - -Multiply each coefficient in `p` with `a` and return -the result. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) -``` -""" -function scale(a::RingElement, p::LinearSetPartition{S, T}) where +function *(a::RingElement, p::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() @@ -132,10 +101,6 @@ function scale(a::RingElement, p::LinearSetPartition{S, T}) where result[i] = a * n end return linear_partition(result) -end - -function *(a::RingElement, p::LinearSetPartition) - return scale(a, p) end """ @@ -211,25 +176,11 @@ function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where return tensor_product(p, q) end -""" - -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - -Perform a subtraction between `p` and `q` and return the result. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) +function -(p::LinearSetPartition) + return (-1 * p) +end -julia> a - a -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}()) -``` -""" function -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where { S <: AbstractPartition, T <: RingElement } - return p + scale(-1, q) + return p + (-q) end diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 5804fe6ebf6c..8bf928109304 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -23,7 +23,6 @@ import Oscar: tensor_product, @req, RingElement, - scale, coefficients, iszero @@ -61,7 +60,6 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export scale @@ -111,4 +109,3 @@ export upper_points export simplify_operation_zero export simplify_operation export linear_partition -export scale diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index f998374dad35..c05cb9a03b51 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -127,29 +127,30 @@ end """ simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } -Simplify the vector representation of a `LinearSetPartition` in terms of associativity. +Simplify the vector representation of a `LinearSetPartition` in terms of distributivity. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in d over QQ, d) + +julia> simplify_operation([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d)]) +Dict{SetPartition, QQPolyRingElem} with 1 entry: + SetPartition([1, 1], [1, 1]) => 4*d + 10 +``` """ function simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } partitions = Dict{S, T}() for (i1, i2) in partition_sum - if iszero(i2) - deleteat!(partition_sum, findall(x -> x == (i1, i2), partition_sum)) continue end - - if !(i1 in keys(partitions)) - partitions[i1] = i2 - else - deleteat!(partition_sum, findall(x -> x == (i1, i2), partition_sum)) - deleteat!(partition_sum, findall(x -> x == (i1, get(partitions, i1, -1)), partition_sum)) - push!(partition_sum, (i1, get(partitions, i1, -1) + i2)) - partitions[i1] = get(partitions, i1, -1) + i2 - end + partitions[i1] = get(partitions, i1, 0) + i2 end - return partition_sum + + return [(s, t) for (s, t) in partitions] end """ diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index 9e85af57432e..fd1378960c95 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -4,6 +4,8 @@ @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) @test coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) + @test coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d), (set_partition([1, 1], [1, 2]), 4*d), (set_partition([1, 1], [1, 1]), S(0))])) == Dict(set_partition([1, 1], [1, 2]) => 4*d, set_partition([1, 1], [1, 1]) => 4*d + 10) + @test_throws ArgumentError linear_partition([(spatial_partition([2, 4], [4, 99], 2), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) end @testset "LinearPartition Operations" begin @@ -12,8 +14,8 @@ @test a + a == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 10*d)) @test a + linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)]) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) - @test scale(S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d))) == S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) - @test scale(S(1) / S(2), linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d))) == linear_partition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + @test S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) + @test (S(1) / S(2)) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) @test compose(a, a, d) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) From 9e08dcd212993df5ccadf860925cced29d9a8526 Mon Sep 17 00:00:00 2001 From: Nicolas <33184293+pinguly@users.noreply.github.com> Date: Thu, 25 Jul 2024 12:55:28 +0200 Subject: [PATCH 20/30] Update experimental/SetPartitions/src/LinearSetPartition.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- experimental/SetPartitions/src/LinearSetPartition.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl index 7a127f8d0194..3ba359d01806 100644 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ b/experimental/SetPartitions/src/LinearSetPartition.jl @@ -7,8 +7,7 @@ struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} coefficients :: Dict{S, T} function LinearSetPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - key_types = Set(typeof(k) for k in keys(coeffs)) - @req length(key_types) <= 1 "keys in the coefficients dictionary must be of the same subtype of AbstractPartition" + @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" return new(simplify_operation_zero(coeffs)) end From 80ad141efa4c9d1925a3145395f2d8f716fa9bef Mon Sep 17 00:00:00 2001 From: pinguly Date: Fri, 26 Jul 2024 10:36:46 +0200 Subject: [PATCH 21/30] rename to LinearPartition, implement base_ring, fix some docstrings --- .../SetPartitions/src/LinearPartition.jl | 201 ++++++++++++++++++ .../SetPartitions/src/LinearSetPartition.jl | 185 ---------------- .../SetPartitions/src/SetPartitions.jl | 33 +-- experimental/SetPartitions/src/Util.jl | 4 +- .../SetPartitions/test/LinearComb-test.jl | 30 +-- 5 files changed, 237 insertions(+), 216 deletions(-) create mode 100644 experimental/SetPartitions/src/LinearPartition.jl delete mode 100644 experimental/SetPartitions/src/LinearSetPartition.jl diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl new file mode 100644 index 000000000000..2682a2bf43be --- /dev/null +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -0,0 +1,201 @@ +""" + LinearPartition{S <: AbstractPartition, T <: RingElem} + +`LinearPartition` represents a linear combination of partitions of type `S` +with coefficients of type `T`. + +See for example Chapter 5 in [Gro20](@cite) for further information on linear +combinations of partitions. +""" +struct LinearPartition{S <: AbstractPartition, T <: RingElem} + base_ring :: Ring # parent_type(T) + coefficients :: Dict{S, T} + + function LinearPartition{S, T}(ring::Ring, coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElem} + @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" + @req (typeof(ring) == parent_type(T)) "Ring type is not the parent of the coefficient type" + for (_, c) in coeffs + @req (parent(c) == ring) "Coefficient does not belong to the base ring" + end + return new(ring, simplify_operation_zero(coeffs)) + end +end + +""" + linear_partition(ring::Ring, coeffs::Dict{S, <: Any}) where {S <: AbstractPartition} + +Construct a linear partition over `ring` with coefficients `coeffs`. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in d over QQ, d) + +julia> linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 4, set_partition([1, 1], [1, 1]) => 4*d)) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) +``` +""" +function linear_partition(ring::Ring, coeffs::Dict{S, <: Any}) where {S <: AbstractPartition} + ring_coeffs = Dict(p => ring(c) for (p, c) in coeffs) + return LinearPartition{S, elem_type(ring)}(ring, ring_coeffs) +end + +""" + linear_partition(ring::Ring, terms::Vector{Tuple{S, <: Any}}) where {S <: AbstractPartition} + +Return a `LinearPartition` generated from the Vector `term` of 2-tuples, +where the first element in the tuple is a `RingElement` and the second +a `SetPartition`. Furthermore simplify the term before initializing +the `LinearPartition` object with the corresponding dict. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in d over QQ, d) + +linear_partition(S, [(set_partition([1, 1], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1], [1, 1]) => 4*d + 4)) +``` +""" +function linear_partition(ring::Ring, terms::Vector{Tuple{S, <: Any}}) where {S <: AbstractPartition} + simpl_terms = simplify_operation([(p, ring(c)) for (p, c) in terms]) + return linear_partition(ring, Dict{S, elem_type(ring)}(simpl_terms)) +end + +""" + base_ring(p::LinearPartition{S, T}) where {S <: AbstractPartition, T <: RingElem} + +Return the underlying coefficient ring of `p`. +""" +function base_ring(p::LinearPartition{S, T}) where {S <: AbstractPartition, T <: RingElement} + return p.base_ring::parent_type(T) +end + +""" + coefficients(p::LinearPartition) + +Return the coefficients of `p` as dictionary from partitions to elements +of the underlying ring. +""" +function coefficients(p::LinearPartition) + return p.coefficients +end + +function hash(p::LinearPartition, h::UInt) + return hash(base_ring(p), hash(coefficients(p), h)) +end + +function ==(p::LinearPartition, q::LinearPartition) + return base_ring(p) == base_ring(q) && coefficients(p) == coefficients(q) +end + +function deepcopy_internal(p::LinearPartition, stackdict::IdDict) + if haskey(stackdict, p) + return stackdict[p] + end + q = linear_partition( + deepcopy_internal(base_ring(p), stackdict), + deepcopy_internal(coefficients(p), stackdict)) + stackdict[p] = q + return q +end + +function +(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + result = deepcopy(coefficients(p)) + for i in pairs(coefficients(q)) + result[i[1]] = get(result, i[1], 0) + i[2] + end + return linear_partition(base_ring(p), result) +end + +function *(a::RingElement, p::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElem } + a = base_ring(p)(a) + result = Dict{S, T}() + for (i, n) in pairs(coefficients(p)) + result[i] = a * n + end + return linear_partition(base_ring(p), result) +end + +""" + compose(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::T) where + { S <: AbstractPartition, T <: RingElement } + +Multiply each coefficient from `p` with each coefficient from `q` +as well as perform a composition between each SetPartition part +in `p` and `q` and return the result. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in d over QQ, d) + +julia> a = linear_partition(S, [(set_partition([1, 2], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) + +julia> compose(a, a, d) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) +``` +""" +function compose(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::T) where + { S <: AbstractPartition, T <: RingElement } + @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + result = Dict{S, T}() + for i in pairs(coefficients(p)) + for ii in pairs(coefficients(q)) + (composition, loop) = compose_count_loops(i[1], ii[1]) + new_coefficient = i[2] * ii[2] * (d^loop) + result[composition] = get(result, composition, 0) + new_coefficient + end + end + return linear_partition(base_ring(p), result) +end + +""" + tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + +Return the tensor product of `p` and `q`. + +# Examples +```jldoctest +julia> S, d = polynomial_ring(QQ, "d") +(Univariate polynomial ring in d over QQ, d) + +julia> a = linear_partition(S, [(set_partition([1, 2], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) + +julia> tensor_product(a, a) +LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) +``` +""" +function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + result = Dict{S, T}() + for i in pairs(coefficients(p)) + for ii in pairs(coefficients(q)) + composition = tensor_product(i[1], ii[1]) + new_coefficient = i[2] * ii[2] + result[composition] = get(result, composition, 0) + new_coefficient + end + end + return linear_partition(base_ring(p), result) +end + +function ⊗(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + return tensor_product(p, q) +end + +function -(p::LinearPartition) + return (-1 * p) +end + +function -(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where + { S <: AbstractPartition, T <: RingElement } + return p + (-q) +end diff --git a/experimental/SetPartitions/src/LinearSetPartition.jl b/experimental/SetPartitions/src/LinearSetPartition.jl deleted file mode 100644 index 3ba359d01806..000000000000 --- a/experimental/SetPartitions/src/LinearSetPartition.jl +++ /dev/null @@ -1,185 +0,0 @@ -""" - LinearSetPartition - -LinearSetPartition represents a linear combination of set-partitions. See Chapter 5 in [Gro20](@cite). -""" -struct LinearSetPartition{S <: AbstractPartition, T <: RingElement} - coefficients :: Dict{S, T} - - function LinearSetPartition{S, T}(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" - - return new(simplify_operation_zero(coeffs)) - end -end - -""" - linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - -Initialize LinearSetPartition object, while simplifying the term. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 4*d)) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}( - SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) -""" -function linear_partition(coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElement} - return LinearSetPartition{S, T}(coeffs) -end - -""" - coefficients(p::LinearSetPartition) - -Get the constructor field `coefficients`, the partition term, in form of a `Dict` from -`SetPartition` to coefficient. -""" -function coefficients(p::LinearSetPartition) - return p.coefficients -end - -function hash(p::LinearSetPartition, h::UInt) - return hash(coefficients(p), h) -end - -function ==(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return coefficients(p) == coefficients(q) -end - -function deepcopy_internal(p::LinearSetPartition, stackdict::IdDict) - if haskey(stackdict, p) - return stackdict[p] - end - q = linear_partition(deepcopy_internal(coefficients(p), stackdict)) - stackdict[p] = q - return q -end - -""" - linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - -Return a `LinearSetPartition` generated from the Vector `term` of 2-tuples, -where the first element in the tuple is a `RingElement` and the second -a `SetPartition`. Furthermore simplify the term before initializing -the `LinearSetPartition` object with the corresponding dict. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> linear_partition([(set_partition([1, 1], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1], [1, 1]) => 4*d + 4)) -``` -""" -function linear_partition(term::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } - return linear_partition(Dict{S, T}(x[1] => x[2] for x in simplify_operation(term))) -end - -function +(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - - result = deepcopy(coefficients(p)) - - for i in pairs(coefficients(q)) - result[i[1]] = get(result, i[1], 0) + i[2] - end - - return linear_partition(result) -end - -function *(a::RingElement, p::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - result = Dict{S, T}() - - for (i, n) in pairs(coefficients(p)) - result[i] = a * n - end - return linear_partition(result) -end - -""" - compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where - { S <: AbstractPartition, T <: RingElement } - -Multiply each coefficient from `p` with each coefficient from `q` -as well as perform a composition between each SetPartition part -in `p` and `q` and return the result. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) - -julia> compose(a, a, d) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 16*d + 16, SetPartition([1, 1], [1, 1]) => 16*d^2 + 16*d)) -``` -""" -function compose(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}, d::T) where - { S <: AbstractPartition, T <: RingElement } - result = Dict{S, T}() - - for i in pairs(coefficients(p)) - for ii in pairs(coefficients(q)) - (composition, loop) = compose_count_loops(i[1], ii[1]) - new_coefficient = i[2] * ii[2] * (d^loop) - result[composition] = get(result, composition, 0) + new_coefficient - end - end - return linear_partition(result) -end - -""" - tensor_product(p::LinearSetPartition{P, R}, q::LinearSetPartition{P, R}) where - { P <: AbstractPartition, R <: RingElement } - -Return the tensor product of `p` and `q`. - -# Examples -```jldoctest -julia> S, d = polynomial_ring(QQ, "d") -(Univariate polynomial ring in d over QQ, d) - -julia> a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) - -julia> tensor_product(a, a) -LinearSetPartition{SetPartition, QQPolyRingElem}(Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, SetPartition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, SetPartition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, SetPartition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) -``` -""" -function tensor_product(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - - result = Dict{S, T}() - - for i in pairs(coefficients(p)) - for ii in pairs(coefficients(q)) - composition = tensor_product(i[1], ii[1]) - new_coefficient = i[2] * ii[2] - result[composition] = get(result, composition, 0) + new_coefficient - end - end - - return linear_partition(result) -end - -function ⊗(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return tensor_product(p, q) -end - -function -(p::LinearSetPartition) - return (-1 * p) -end - -function -(p::LinearSetPartition{S, T}, q::LinearSetPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } - return p + (-q) -end diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 8bf928109304..7ee458014152 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -1,35 +1,40 @@ module SetPartitions import Base: + +, + -, + *, ==, - *, adjoint, deepcopy, deepcopy_internal, hash, - size, - -, - + + size import Oscar: + PermGroupElem, + Ring, + RingElem, + RingElement, ⊗, + @req, + base_ring, + coefficients, compose, cycles, + degree, + elem_type, involution, + iszero, join, - PermGroupElem, parent, - degree, - tensor_product, - @req, - RingElement, - coefficients, - iszero + parent_type, + tensor_product export ColoredPartition export SetPartition export SpatialPartition -export LinearSetPartition +export LinearPartition export colored_partition export compose_count_loops @@ -70,7 +75,7 @@ include("ColoredPartition.jl") include("SpatialPartition.jl") include("PartitionProperties.jl") include("GenerateCategory.jl") -include("LinearSetPartition.jl") +include("LinearPartition.jl") end using .SetPartitions @@ -78,7 +83,7 @@ using .SetPartitions export ColoredPartition export SetPartition export SpatialPartition -export LinearSetPartition +export LinearPartition export colored_partition export compose_count_loops diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index c05cb9a03b51..d6a6f9a03e55 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -127,7 +127,7 @@ end """ simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } -Simplify the vector representation of a `LinearSetPartition` in terms of distributivity. +Simplify the vector representation of a `LinearPartition` in terms of distributivity. # Examples ```jldoctest @@ -156,7 +156,7 @@ end """ simplify_operation_zero(p::Dict{S, T}) where { S <: AbstractPartition, T <: RingElement } -Simplify the dict representation of a `LinearSetPartition` in terms of zero coefficients. +Simplify the dict representation of a `LinearPartition` in terms of zero coefficients. """ function simplify_operation_zero(p::Dict{S, T}) where { S <: AbstractPartition, T <: RingElement } result = Dict{S, T}() diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearComb-test.jl index fd1378960c95..5c7e857ce350 100644 --- a/experimental/SetPartitions/test/LinearComb-test.jl +++ b/experimental/SetPartitions/test/LinearComb-test.jl @@ -1,27 +1,27 @@ @testset "LinearCombinations of SetPartitions" begin - @testset "LinearSetPartition Constructor" begin + @testset "LinearPartition Constructor" begin S, d = polynomial_ring(QQ, "d") - @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => S(4), set_partition([1, 1], [1, 1]) => 8*d) - @test coefficients(linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(0), set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) - @test coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) - @test coefficients(linear_partition([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d), (set_partition([1, 1], [1, 2]), 4*d), (set_partition([1, 1], [1, 1]), S(0))])) == Dict(set_partition([1, 1], [1, 2]) => 4*d, set_partition([1, 1], [1, 1]) => 4*d + 10) - @test_throws ArgumentError linear_partition([(spatial_partition([2, 4], [4, 99], 2), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) + @test coefficients(linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 4, set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 2], [1, 1]) => 4, set_partition([1, 1], [1, 1]) => 8*d) + @test coefficients(linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 0, set_partition([1, 1], [1, 1]) => 8*d))) == Dict(set_partition([1, 1], [1, 1]) => 8*d) + @test coefficients(linear_partition(S, [(set_partition([1, 1], [1, 1]), 5), (set_partition([1, 1], [1, 1]), 4*d)])) == Dict(set_partition([1, 1], [1, 1]) => 5 + 4*d) + @test coefficients(linear_partition(S, [(set_partition([1, 1], [1, 1]), 10), (set_partition([1, 1], [1, 1]), 4*d), (set_partition([1, 1], [1, 2]), 4*d), (set_partition([1, 1], [1, 1]), S(0))])) == Dict(set_partition([1, 1], [1, 2]) => 4*d, set_partition([1, 1], [1, 1]) => 4*d + 10) + @test_throws ArgumentError linear_partition(S, [(spatial_partition([2, 4], [4, 99], 2), 4), (set_partition([1, 1], [1, 1]), 4*d)]) end @testset "LinearPartition Operations" begin S, d = polynomial_ring(QQ, "d") - a = linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 5*d)]) - @test a + a == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 10*d)) - @test a + linear_partition([(set_partition([1, 1], [1, 1]), S(1)), (set_partition([1, 1], [1, 1]), 2*d)]) == linear_partition([(set_partition([1, 2], [1, 1]), S(5)), (set_partition([1, 1], [1, 1]), 7*d + 1)]) + a = linear_partition(S, [(set_partition([1, 2], [1, 1]), 5), (set_partition([1, 1], [1, 1]), 5*d)]) + @test a + a == linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 10, set_partition([1, 1], [1, 1]) => 10*d)) + @test a + linear_partition(S, [(set_partition([1, 1], [1, 1]), 1), (set_partition([1, 1], [1, 1]), 2*d)]) == linear_partition(S, [(set_partition([1, 2], [1, 1]), 5), (set_partition([1, 1], [1, 1]), 7*d + 1)]) - @test S(2) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(10), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(20), set_partition([1, 1], [1, 1]) => 16*d)) - @test (S(1) / S(2)) * linear_partition(Dict(set_partition([1, 2], [1, 1]) => S(8), set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(Dict(SetPartition([1, 2], [1, 1]) => S(4), SetPartition([1, 1], [1, 1]) => 4*d)) + @test 2 * linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 10, set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 20, set_partition([1, 1], [1, 1]) => 16*d)) + @test (1 // 2) * linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 8, set_partition([1, 1], [1, 1]) => 8*d)) == linear_partition(S, Dict(SetPartition([1, 2], [1, 1]) => 4, SetPartition([1, 1], [1, 1]) => 4*d)) - a = linear_partition([(set_partition([1, 2], [1, 1]), S(4)), (set_partition([1, 1], [1, 1]), 4*d)]) - @test compose(a, a, d) == linear_partition(Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) + a = linear_partition(S, [(set_partition([1, 2], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) + @test compose(a, a, d) == linear_partition(S, Dict(set_partition([1, 2], [1, 1]) => 16*d + 16, set_partition([1, 1], [1, 1]) => 16*d^2 + 16*d)) - @test tensor_product(a, a) == linear_partition(Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => S(16), set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) + @test tensor_product(a, a) == linear_partition(S, Dict(set_partition([1, 1, 2, 2], [1, 1, 2, 2]) => 16*d^2, set_partition([1, 2, 3, 3], [1, 1, 3, 3]) => 16*d, set_partition([1, 2, 3, 4], [1, 1, 3, 3]) => 16, set_partition([1, 1, 2, 3], [1, 1, 2, 2]) => 16*d)) - @test a - a == linear_partition(Dict(set_partition([1, 1], [1, 1]) => S(0))) + @test a - a == linear_partition(S, Dict(set_partition([1, 1], [1, 1]) => 0)) end end From 91fb265728c14ca7a93637267df5aa4d8940be23 Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Fri, 26 Jul 2024 11:20:58 +0200 Subject: [PATCH 22/30] minor doctest fix for simplify operation and linear_partition --- experimental/SetPartitions/src/LinearPartition.jl | 2 +- experimental/SetPartitions/src/Util.jl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index 2682a2bf43be..3e1e0de4c0a2 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -53,7 +53,7 @@ the `LinearPartition` object with the corresponding dict. julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) -linear_partition(S, [(set_partition([1, 1], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) +julia> linear_partition(S, [(set_partition([1, 1], [1, 1]), 4), (set_partition([1, 1], [1, 1]), 4*d)]) LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d over QQ, Dict{SetPartition, QQPolyRingElem}(SetPartition([1, 1], [1, 1]) => 4*d + 4)) ``` """ diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index d6a6f9a03e55..42cdfbf05a5e 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -135,8 +135,8 @@ julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) julia> simplify_operation([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d)]) -Dict{SetPartition, QQPolyRingElem} with 1 entry: - SetPartition([1, 1], [1, 1]) => 4*d + 10 +1-element Vector{Tuple{SetPartition, QQPolyRingElem}}: + (SetPartition([1, 1], [1, 1]), 4*d + 10) ``` """ function simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: AbstractPartition, T <: RingElement } From 78e8574a7f2423b44639b0f0daeacb54f5cb65cf Mon Sep 17 00:00:00 2001 From: Sebastian Volz <109701830+sebvz777@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:27:39 +0200 Subject: [PATCH 23/30] Update experimental/SetPartitions/src/LinearPartition.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- experimental/SetPartitions/src/LinearPartition.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index 3e1e0de4c0a2..06805cfa1389 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -13,7 +13,7 @@ struct LinearPartition{S <: AbstractPartition, T <: RingElem} function LinearPartition{S, T}(ring::Ring, coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElem} @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" - @req (typeof(ring) == parent_type(T)) "Ring type is not the parent of the coefficient type" + @req ring isa parent_type(T) "Ring type is not the parent of the coefficient type" for (_, c) in coeffs @req (parent(c) == ring) "Coefficient does not belong to the base ring" end From 25a827f569b768a3c5be7d3d7eb04788f4dccb19 Mon Sep 17 00:00:00 2001 From: Sebastian Volz <109701830+sebvz777@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:28:01 +0200 Subject: [PATCH 24/30] Update experimental/SetPartitions/src/LinearPartition.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- experimental/SetPartitions/src/LinearPartition.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index 06805cfa1389..a650c1927612 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -14,7 +14,7 @@ struct LinearPartition{S <: AbstractPartition, T <: RingElem} function LinearPartition{S, T}(ring::Ring, coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElem} @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" @req ring isa parent_type(T) "Ring type is not the parent of the coefficient type" - for (_, c) in coeffs + for c in values(coeff) @req (parent(c) == ring) "Coefficient does not belong to the base ring" end return new(ring, simplify_operation_zero(coeffs)) From b72f93220fb787684d36475bbb5add1989effc2b Mon Sep 17 00:00:00 2001 From: Sebastian Volz <109701830+sebvz777@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:28:49 +0200 Subject: [PATCH 25/30] Update experimental/SetPartitions/src/LinearPartition.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- experimental/SetPartitions/src/LinearPartition.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index a650c1927612..34cb3b50215a 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -94,7 +94,7 @@ function deepcopy_internal(p::LinearPartition, stackdict::IdDict) return stackdict[p] end q = linear_partition( - deepcopy_internal(base_ring(p), stackdict), + base_ring(p), deepcopy_internal(coefficients(p), stackdict)) stackdict[p] = q return q From 4069c34efdfebe3dc81e1492d48af2d1644b91cc Mon Sep 17 00:00:00 2001 From: Sebastian Volz <109701830+sebvz777@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:29:16 +0200 Subject: [PATCH 26/30] Update experimental/SetPartitions/src/Util.jl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lars Göttgens --- experimental/SetPartitions/src/Util.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index 42cdfbf05a5e..f17f04f3b529 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -150,7 +150,7 @@ function simplify_operation(partition_sum::Vector{Tuple{S, T}}) where { S <: Abs partitions[i1] = get(partitions, i1, 0) + i2 end - return [(s, t) for (s, t) in partitions] + return [(s, t) for (s, t) in partitions if !iszero(t)] end """ From 1721c841b15ced65db09722ccbbd47267af1569c Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Wed, 31 Jul 2024 11:10:23 +0200 Subject: [PATCH 27/30] fixing SetPartition reference in doctest and RingElem --- .../SetPartitions/src/LinearPartition.jl | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index 34cb3b50215a..3a153070b641 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -14,7 +14,7 @@ struct LinearPartition{S <: AbstractPartition, T <: RingElem} function LinearPartition{S, T}(ring::Ring, coeffs::Dict{S, T}) where {S <: AbstractPartition, T <: RingElem} @req isconcretetype(S) "Linear combinations are only defined for concrete subtypes of AbstractPartition" @req ring isa parent_type(T) "Ring type is not the parent of the coefficient type" - for c in values(coeff) + for c in values(coeffs) @req (parent(c) == ring) "Coefficient does not belong to the base ring" end return new(ring, simplify_operation_zero(coeffs)) @@ -67,10 +67,14 @@ end Return the underlying coefficient ring of `p`. """ -function base_ring(p::LinearPartition{S, T}) where {S <: AbstractPartition, T <: RingElement} +function base_ring(p::LinearPartition{S, T}) where {S <: AbstractPartition, T <: RingElem} return p.base_ring::parent_type(T) end +function base_ring_type(::Type{LinearPartition{S, T}}) where {S <: AbstractPartition, T <: RingElem} + return parent_type(T) +end + """ coefficients(p::LinearPartition) @@ -101,7 +105,7 @@ function deepcopy_internal(p::LinearPartition, stackdict::IdDict) end function +(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" result = deepcopy(coefficients(p)) for i in pairs(coefficients(q)) @@ -122,11 +126,13 @@ end """ compose(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::T) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } -Multiply each coefficient from `p` with each coefficient from `q` -as well as perform a composition between each SetPartition part -in `p` and `q` and return the result. +Return the composition between `p` and `q`. + +The composition is obtained by multiplying each coefficient +of `p` with each coefficient of `q` and composing the corresponding +partitions. # Examples ```jldoctest @@ -141,7 +147,7 @@ LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d ov ``` """ function compose(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::T) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" result = Dict{S, T}() for i in pairs(coefficients(p)) @@ -156,7 +162,7 @@ end """ tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } Return the tensor product of `p` and `q`. @@ -173,7 +179,7 @@ LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d ov ``` """ function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" result = Dict{S, T}() for i in pairs(coefficients(p)) @@ -187,7 +193,7 @@ function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) wher end function ⊗(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } return tensor_product(p, q) end @@ -196,6 +202,6 @@ function -(p::LinearPartition) end function -(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where - { S <: AbstractPartition, T <: RingElement } + { S <: AbstractPartition, T <: RingElem } return p + (-q) end From 6e8db15c52e276a224a9ae6eb300740c7707b99d Mon Sep 17 00:00:00 2001 From: pinguly Date: Wed, 31 Jul 2024 14:17:26 +0200 Subject: [PATCH 28/30] fix base_ring_type import --- experimental/SetPartitions/src/SetPartitions.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index 7ee458014152..fa6abfa7cc4c 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -19,6 +19,7 @@ import Oscar: ⊗, @req, base_ring, + base_ring_type, coefficients, compose, cycles, From d6de93ec59c574f493abd7de730b2fd40cd6d1ea Mon Sep 17 00:00:00 2001 From: sebvz777 Date: Mon, 26 Aug 2024 12:12:47 +0200 Subject: [PATCH 29/30] docstring improvements, renaming LinearComb-test to LinearPartition-test, redundant brackets removal etc --- .../SetPartitions/src/LinearPartition.jl | 17 ++++++++++------- experimental/SetPartitions/src/SetPartitions.jl | 8 ++------ ...nearComb-test.jl => LinearPartition-test.jl} | 0 3 files changed, 12 insertions(+), 13 deletions(-) rename experimental/SetPartitions/test/{LinearComb-test.jl => LinearPartition-test.jl} (100%) diff --git a/experimental/SetPartitions/src/LinearPartition.jl b/experimental/SetPartitions/src/LinearPartition.jl index 3a153070b641..7fb05774ff54 100644 --- a/experimental/SetPartitions/src/LinearPartition.jl +++ b/experimental/SetPartitions/src/LinearPartition.jl @@ -43,9 +43,10 @@ end """ linear_partition(ring::Ring, terms::Vector{Tuple{S, <: Any}}) where {S <: AbstractPartition} -Return a `LinearPartition` generated from the Vector `term` of 2-tuples, -where the first element in the tuple is a `RingElement` and the second -a `SetPartition`. Furthermore simplify the term before initializing +Return a `LinearPartition` generated from the vector `term` of 2-tuples, +where the first element in the tuple is an `AbstractPartition` and the second +a `RingElem`. The `ring` argument defines the base ring into which the second +elements of the tuples are converted. Furthermore simplify the term before initializing the `LinearPartition` object with the corresponding dict. # Examples @@ -106,7 +107,7 @@ end function +(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where { S <: AbstractPartition, T <: RingElem } - @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + @req base_ring(p) == base_ring(q) "Linear partitions are defined over different base rings" result = deepcopy(coefficients(p)) for i in pairs(coefficients(q)) result[i[1]] = get(result, i[1], 0) + i[2] @@ -132,7 +133,9 @@ Return the composition between `p` and `q`. The composition is obtained by multiplying each coefficient of `p` with each coefficient of `q` and composing the corresponding -partitions. +partitions. The `RingElem` parameter `d` multiplies each +coefficient based on the number of loops identified during the +composition. # Examples ```jldoctest @@ -148,7 +151,7 @@ LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d ov """ function compose(p::LinearPartition{S, T}, q::LinearPartition{S, T}, d::T) where { S <: AbstractPartition, T <: RingElem } - @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + @req base_ring(p) == base_ring(q) "Linear partitions are defined over different base rings" result = Dict{S, T}() for i in pairs(coefficients(p)) for ii in pairs(coefficients(q)) @@ -180,7 +183,7 @@ LinearPartition{SetPartition, QQPolyRingElem}(Univariate polynomial ring in d ov """ function tensor_product(p::LinearPartition{S, T}, q::LinearPartition{S, T}) where { S <: AbstractPartition, T <: RingElem } - @req (base_ring(p) == base_ring(q)) "Linear partitions are defined over different base rings" + @req base_ring(p) == base_ring(q) "Linear partitions are defined over different base rings" result = Dict{S, T}() for i in pairs(coefficients(p)) for ii in pairs(coefficients(q)) diff --git a/experimental/SetPartitions/src/SetPartitions.jl b/experimental/SetPartitions/src/SetPartitions.jl index fa6abfa7cc4c..b55f852adbf3 100644 --- a/experimental/SetPartitions/src/SetPartitions.jl +++ b/experimental/SetPartitions/src/SetPartitions.jl @@ -48,6 +48,7 @@ export is_non_crossing export is_pair export join export levels +export linear_partition export lower_colors export lower_points export number_of_blocks @@ -63,9 +64,6 @@ export set_partition export spatial_partition export upper_colors export upper_points -export simplify_operation_zero -export simplify_operation -export linear_partition @@ -97,6 +95,7 @@ export is_non_crossing export is_pair export join export levels +export linear_partition export lower_colors export lower_points export number_of_blocks @@ -112,6 +111,3 @@ export set_partition export spatial_partition export upper_colors export upper_points -export simplify_operation_zero -export simplify_operation -export linear_partition diff --git a/experimental/SetPartitions/test/LinearComb-test.jl b/experimental/SetPartitions/test/LinearPartition-test.jl similarity index 100% rename from experimental/SetPartitions/test/LinearComb-test.jl rename to experimental/SetPartitions/test/LinearPartition-test.jl From 5c3e20ad5eea18ed3c1a497c876487284274b9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Mon, 26 Aug 2024 13:40:54 +0200 Subject: [PATCH 30/30] Update experimental/SetPartitions/src/Util.jl --- experimental/SetPartitions/src/Util.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/SetPartitions/src/Util.jl b/experimental/SetPartitions/src/Util.jl index f17f04f3b529..869c37e5fba0 100644 --- a/experimental/SetPartitions/src/Util.jl +++ b/experimental/SetPartitions/src/Util.jl @@ -134,7 +134,7 @@ Simplify the vector representation of a `LinearPartition` in terms of distributi julia> S, d = polynomial_ring(QQ, "d") (Univariate polynomial ring in d over QQ, d) -julia> simplify_operation([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d)]) +julia> Oscar.SetPartitions.simplify_operation([(set_partition([1, 1], [1, 1]), S(10)), (set_partition([1, 1], [1, 1]), 4*d)]) 1-element Vector{Tuple{SetPartition, QQPolyRingElem}}: (SetPartition([1, 1], [1, 1]), 4*d + 10) ```