diff --git a/docs/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.md b/docs/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.md index eeb1cae86bb5..8a417d958040 100644 --- a/docs/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.md +++ b/docs/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.md @@ -1,6 +1,6 @@ # Schur polynomials -Given a partition $\lambda$ of $n$, the **Schur polynomial** is defined to be +Given a partition $\lambda$ with $n$ parts, the **Schur polynomial** is defined to be the polynomial $$s_\lambda := \sum x_1^{m_1}\dots x_n^{m_n}$$ diff --git a/src/Combinatorics/EnumerativeCombinatorics/partitions.jl b/src/Combinatorics/EnumerativeCombinatorics/partitions.jl index 204970cf6bfa..b9e853a9d150 100644 --- a/src/Combinatorics/EnumerativeCombinatorics/partitions.jl +++ b/src/Combinatorics/EnumerativeCombinatorics/partitions.jl @@ -227,10 +227,9 @@ function Base.iterate(P::Partitions{T}) where T return partition(T[1], check=false), (T[1], 1, 0) end - d = fill( T(1), n ) + d = fill(T(1), Int(n)) d[1] = n return partition(d[1:1], check=false), (d, 1, 1) - end @inline function Base.iterate(P::Partitions{T}, state::Tuple{Vector{T}, Int, Int}) where T @@ -381,7 +380,7 @@ function Base.iterate(P::PartitionsFixedNumParts{T}) where T only_distinct_parts = P.distinct_parts if n == 0 && k == 0 - return partition(T[], check=false), (T[], T[], 0, 0, 1, false) + return partition(T[], check=false), (T[], T[], T(0), T(0), 1, false) end # This iterator should be empty @@ -391,17 +390,17 @@ function Base.iterate(P::PartitionsFixedNumParts{T}) where T if n == k && lb == 1 only_distinct_parts && k > 1 && return nothing - return partition(T[1 for i in 1:n], check=false), (T[], T[], 0, 0, 1, false) + return partition(T[1 for i in 1:n], check=false), (T[], T[], T(0), T(0), 1, false) end if k == 1 && lb <= n <= ub - return partition(T[n], check=false), (T[], T[], 0, 0, 1, false) + return partition(T[n], check=false), (T[], T[], T(0), T(0), 1, false) end x = zeros(T,k) y = zeros(T,k) jj = only_distinct_parts*k*(k-1) - N = n - k*lb - div(jj,2) + N = T(n - k*lb - div(jj,2)) L2 = ub-lb 0 <= N <= k*L2 - jj || return nothing @@ -410,7 +409,7 @@ function Base.iterate(P::PartitionsFixedNumParts{T}) where T end i = 1 - L2 = L2 - only_distinct_parts*(k-1) + L2 = L2 - only_distinct_parts*T(k-1) while N > L2 N -= L2 @@ -421,7 +420,7 @@ function Base.iterate(P::PartitionsFixedNumParts{T}) where T return partition(x[1:k], check = false), (x, y, N, L2, i, true) end -@inline function Base.iterate(P::PartitionsFixedNumParts{T}, state::Tuple{Vector{T}, Vector{T}, T, IntegerUnion, Int, Bool}) where T +@inline function Base.iterate(P::PartitionsFixedNumParts{T}, state::Tuple{Vector{T}, Vector{T}, T, T, Int, Bool}) where T k = P.k x, y, N, L2, i, flag = state @@ -429,7 +428,7 @@ end if flag if i < k && N > 1 - N = 1 + N = T(1) x[i] = x[i] - 1 i += 1 x[i] = y[i] + 1 @@ -442,12 +441,11 @@ end flag = false end end - if !flag lcycle = false for j in i - 1:-1:1 - L2 = x[j] - y[j] - 1 - N = N + 1 + L2 = x[j] - y[j] - T(1) + N = N + T(1) if N <= (k-j)*L2 x[j] = y[j] + L2 lcycle = true @@ -457,7 +455,6 @@ end x[i] = y[i] i = j end - lcycle || return nothing while N > L2 N -= L2 @@ -769,7 +766,7 @@ end x[i] = m i -= 1 i == 0 && break # inner while loop - r = ii[i] + r = Int(ii[i]) N = N + x[i] - m m = y[i] end diff --git a/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl b/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl index 1f54c50e6477..48af8f85e786 100644 --- a/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl +++ b/src/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl @@ -120,7 +120,7 @@ function schur_polynomial_cbf(R::ZZMPolyRing, lambda::Partition{T}, n::Int = len end #calculate sub_dets[2:n] using Laplace extension - exp = zeros(Int, n) + exp = zeros(Int, ngens(R)) for i = 2:n for (columnview, ) in sub_dets[i] d = R() #the alternating sum of minors @@ -134,8 +134,11 @@ function schur_polynomial_cbf(R::ZZMPolyRing, lambda::Partition{T}, n::Int = len #multiply by the factorized term factor = MPolyBuildCtx(R) - exp = zeros(Int, n) - exp[columnview] .= exp_incr[i] + exp = zeros(Int, ngens(R)) + for j in 1:n + columnview[j] || continue + exp[j] = exp_incr[i] + end push_term!(factor, one(ZZ), exp) sub_dets[i][columnview] = mul!(d, d, finish(factor)) end diff --git a/src/Combinatorics/EnumerativeCombinatorics/tableaux.jl b/src/Combinatorics/EnumerativeCombinatorics/tableaux.jl index d82b81e2229f..86a7e8d0fe82 100644 --- a/src/Combinatorics/EnumerativeCombinatorics/tableaux.jl +++ b/src/Combinatorics/EnumerativeCombinatorics/tableaux.jl @@ -58,8 +58,7 @@ young_tableau(v::Vector{Vector{T}}; check::Bool = true) where T <: IntegerUnion data(tab::YoungTableau) = tab.t function Base.show(io::IO, tab::YoungTableau) - print(io, "Young tableau") - # TODO: is there meaningful information to add in one-line mode? + print(io, data(tab)) end function Base.show(io::IO, ::MIME"text/plain", tab::YoungTableau) @@ -591,7 +590,7 @@ function is_standard(tab::YoungTableau) numbs = falses(n) for i = 1:length(s) for j = 1:s[i] - if tab[i][j] > n + if tab[i][j] < 1 || tab[i][j] > n return false end numbs[tab[i][j]] = true diff --git a/src/Combinatorics/EnumerativeCombinatorics/types.jl b/src/Combinatorics/EnumerativeCombinatorics/types.jl index 848f96ba3d0c..ff9f4044c76e 100644 --- a/src/Combinatorics/EnumerativeCombinatorics/types.jl +++ b/src/Combinatorics/EnumerativeCombinatorics/types.jl @@ -78,10 +78,10 @@ struct CompositionsFixedNumParts{T<:IntegerUnion} if k > n # 1 does not have any weak compositions into 0 parts, so this will # produce an empty iterator - nk = 1 + nk = T(1) kk = 0 else - nk = n - k + nk = n - T(k) kk = k end return new{T}(n, k, weak_compositions(nk, kk)) @@ -165,7 +165,7 @@ struct PartitionsFixedNumParts{T<:IntegerUnion} if lb == 0 lb = 1 end - return new{T}(n, convert(T, k), T(lb), T(ub), only_distinct_parts) + return new{T}(n, Int(k), T(lb), T(ub), only_distinct_parts) end end diff --git a/test/Combinatorics/EnumerativeCombinatorics/compositions.jl b/test/Combinatorics/EnumerativeCombinatorics/compositions.jl index 7a847f012d20..e11e53145c1c 100644 --- a/test/Combinatorics/EnumerativeCombinatorics/compositions.jl +++ b/test/Combinatorics/EnumerativeCombinatorics/compositions.jl @@ -1,15 +1,15 @@ -@testset "compositions" begin +@testset "Compositions with integer type $T" for T in [Int, Int8, ZZRingElem] # Check some stupid cases - @test number_of_compositions(0, 0) == 1 - @test number_of_compositions(0, 1) == 0 - @test number_of_compositions(1, 0) == 0 - @test number_of_compositions(0) == 1 + @test number_of_compositions(T(0), T(0)) == 1 + @test number_of_compositions(T(0), T(1)) == 0 + @test number_of_compositions(T(1), T(0)) == 0 + @test number_of_compositions(T(0)) == 1 # First few number of compositions from https://oeis.org/A011782 nums = [1, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592] # Check if number_of_compositions is correct in these examples - @test [number_of_compositions(n) for n in 0:length(nums) - 1] == nums + @test [number_of_compositions(T(n)) for n in 0:length(nums) - 1] == nums # Complete check of compositions for small cases for n in 0:5 @@ -17,8 +17,9 @@ # of n into k parts for 0 <= k <= n allcomps = [] for k in 0:n - C = collect(compositions(n, k)) - @test length(C) == number_of_compositions(n, k) + C = @inferred collect(compositions(T(n), T(k))) + @test C isa Vector{Oscar.Composition{T}} + @test length(C) == number_of_compositions(T(n), T(k)) # Check if each composition consists of k parts and sums up to n for c in C @@ -37,19 +38,25 @@ @test allcomps == unique(allcomps) # Number of compositions needs to be correct - @test length(allcomps) == number_of_compositions(n) + @test length(allcomps) == number_of_compositions(T(n)) # Finally, check compositions(n) function - allcomps2 = collect(compositions(n)) + allcomps2 = @inferred collect(compositions(T(n))) + @test allcomps2 isa Vector{Oscar.Composition{T}} @test allcomps2 == unique(allcomps2) @test Set(allcomps) == Set(allcomps2) end + + # Test the case k > n + C = @inferred collect(compositions(T(2), T(3))) + @test C isa Vector{Oscar.Composition{T}} + @test isempty(C) end -@testset "Ascending compositions" begin +@testset "Ascending compositions with integer type $T" for T in [Int, Int8, ZZRingElem] for n in 0:20 - C = collect(ascending_compositions(n)) - @test length(C) == number_of_partitions(n) + C = @inferred collect(ascending_compositions(T(n))) + @test length(C) == number_of_partitions(T(n)) @test C == unique(C) for lambda in C @test sum(lambda) == n diff --git a/test/Combinatorics/EnumerativeCombinatorics/partitions.jl b/test/Combinatorics/EnumerativeCombinatorics/partitions.jl index bd3443a90cb6..bb17ba21013e 100644 --- a/test/Combinatorics/EnumerativeCombinatorics/partitions.jl +++ b/test/Combinatorics/EnumerativeCombinatorics/partitions.jl @@ -20,28 +20,31 @@ ############################################################################ # number_of_partitions(n) ############################################################################ - @testset "number_of_partitions(n)" begin + @testset "number_of_partitions(n) for integer type $T" for T in [Int, Int8, ZZRingElem] # From https://oeis.org/A000041 - @test [ number_of_partitions(i) for i in 0:49 ] == + @test [ number_of_partitions(T(i)) for i in 0:49 ] == ZZRingElem[ 1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490, 627, 792, 1002, 1255, 1575, 1958, 2436, 3010, 3718, 4565, 5604, 6842, 8349, 10143, 12310, 14883, 17977, 21637, 26015, 31185, 37338, 44583, 53174, 63261, 75175, 89134, 105558, 124754, 147273, 173525 ] # For some random large numbers, checked with Sage # Partitions(991).cardinality() - @test number_of_partitions(991) == ZZ(16839773100833956878604913215477) + if T !== Int8 + @test number_of_partitions(T(991)) == ZZ(16839773100833956878604913215477) + end - @test number_of_partitions(-1) == ZZ(0) + @test number_of_partitions(T(-1)) == ZZ(0) end ############################################################################ # partitions(n) ############################################################################ - @testset "partitions($n)" for n in 0:10 - P = collect(partitions(n)) + @testset "partitions($n) for integer type $T" for n in 0:10, T in [Int, Int8, ZZRingElem] + P = @inferred collect(partitions(T(n))) + @test P isa Vector{Oscar.Partition{T}} # Check that the number of partitions is correct # Note that number_of_partitions(n) is computed independently of partitions(n) - @test length(P) == number_of_partitions(n) + @test length(P) == number_of_partitions(T(n)) # Check that all partitions are distinct @test P == unique(P) @@ -55,59 +58,65 @@ ############################################################################ # number_of_partitions(n,k) ############################################################################ - @testset "number_of_partitions(n,k)" begin - @test number_of_partitions(0,0) == 1 - @test number_of_partitions(1,0) == 0 - @test number_of_partitions(1,1) == 1 - @test number_of_partitions(0,1) == 0 - @test number_of_partitions(2,3) == 0 + @testset "number_of_partitions(n,k) for integer type $T" for T in [Int, Int8, ZZRingElem] + @test number_of_partitions(T(0), T(0)) == 1 + @test number_of_partitions(T(1), T(0)) == 0 + @test number_of_partitions(T(1), T(1)) == 1 + @test number_of_partitions(T(0), T(1)) == 0 + @test number_of_partitions(T(2), T(3)) == 0 # From https://oeis.org/A008284 - @test [ number_of_partitions(n,k) for n in 1:14 for k in 1:n ] == + @test [ number_of_partitions(T(n), T(k)) for n in 1:14 for k in 1:n ] == ZZRingElem[ 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 3, 3, 2, 1, 1, 1, 3, 4, 3, 2, 1, 1, 1, 4, 5, 5, 3, 2, 1, 1, 1, 4, 7, 6, 5, 3, 2, 1, 1, 1, 5, 8, 9, 7, 5, 3, 2, 1, 1, 1, 5, 10, 11, 10, 7, 5, 3, 2, 1, 1, 1, 6, 12, 15, 13, 11, 7, 5, 3, 2, 1, 1, 1, 6, 14, 18, 18, 14, 11, 7, 5, 3, 2, 1, 1, 1, 7, 16, 23, 23, 20, 15, 11, 7, 5, 3, 2, 1, 1 ] # For some random large numbers, checked with Sage # Partitions(1991,length=170).cardinality() - @test number_of_partitions(1991,170) == ZZ(22381599503916828837298114953756766080813312) - @test number_of_partitions(1991,1000) == ZZ(16839773100833956878604913215477) - @test number_of_partitions(1991,670) == ZZ(3329965216307826492368402165868892548) - @test number_of_partitions(1991,1991) == ZZ(1) - @test number_of_partitions(1991,1) == ZZ(1) + if T !== Int8 + @test number_of_partitions(T(1991), T(170)) == ZZ(22381599503916828837298114953756766080813312) + @test number_of_partitions(T(1991), T(1000)) == ZZ(16839773100833956878604913215477) + @test number_of_partitions(T(1991), T(670)) == ZZ(3329965216307826492368402165868892548) + @test number_of_partitions(T(1991), T(1991)) == ZZ(1) + @test number_of_partitions(T(1991), T(1)) == ZZ(1) + end # From Knuth (2011), p. 25. - @test sum([number_of_partitions(30, i) for i in 0:10]) == 3590 + @test sum([number_of_partitions(T(30), T(i)) for i in 0:10]) == 3590 - @test number_of_partitions(-1, 0) == ZZ(0) - @test number_of_partitions(0, -1) == ZZ(0) + @test number_of_partitions(T(-1), T(0)) == ZZ(0) + @test number_of_partitions(T(0), T(-1)) == ZZ(0) end ############################################################################ # partitions(n,k) ############################################################################ - @testset "partitions($n,$k)" for n in 0:10, k in 0:n+1 - P = collect(partitions(n,k)) + @testset "partitions($n, $k) for integer type $T" for n in 0:10, k in 0:n+1, T in [Int, Int8, ZZRingElem] + P = @inferred collect(partitions(T(n), T(k))) + @test P isa Vector{Oscar.Partition{T}} # Create the same by filtering all partitions - Q = collect(partitions(n)) - filter!( Q->length(Q) == k, Q) + Q = @inferred collect(partitions(T(n))) + @test Q isa Vector{Oscar.Partition{T}} + filter!(Q -> length(Q) == k, Q) # Check that P and Q coincide (up to reordering) @test length(P) == length(Q) @test Set(P) == Set(Q) # Compare length with number_of_partitions(n,k) - @test length(P) == number_of_partitions(n,k) + @test length(P) == number_of_partitions(T(n), T(k)) end ############################################################################ # partitions(n,k,lb,ub) ############################################################################ - @testset "partitions($n,$k,lb,ub)" for n in 0:10, k in 0:n+1 - @testset "partitions($n,$k,$lb,$ub)" for lb in 0:n, ub in lb:n - P = collect(partitions(n,k,lb,ub)) + @testset "partitions($n, $k, lb, ub)" for n in 0:10, k in 0:n+1 + @testset "partitions($n, $k, $lb, $ub) for integer type $T" for lb in 0:n, ub in lb:n, T in [Int, Int8, ZZRingElem] + P = @inferred collect(partitions(T(n), T(k), T(lb), T(ub))) + @test P isa Vector{Oscar.Partition{T}} # Create the same by filtering all partitions - Q = collect(partitions(n,k)) + Q = @inferred collect(partitions(T(n), T(k))) + @test Q isa Vector{Oscar.Partition{T}} filter!( Q->all(>=(lb),Q), Q) filter!( Q->all(<=(ub),Q), Q) @@ -120,12 +129,14 @@ ############################################################################ # partitions(n,k,lb,ub; only_distinct_parts=true) ############################################################################ - @testset "partitions($n,$k,lb,ub; only_distinct_parts=true)" for n in 0:10, k in 0:n+1 - @testset "partitions($n,$k,$lb,$ub; only_distinct_parts=true)" for lb in 0:n, ub in lb:n - P = collect(partitions(n, k, lb, ub; only_distinct_parts=true)) + @testset "partitions($n, $k, lb, ub; only_distinct_parts=true)" for n in 0:10, k in 0:n+1 + @testset "partitions($n, $k, $lb, $ub; only_distinct_parts=true) for integer type $T" for lb in 0:n, ub in lb:n, T in [Int, Int16, ZZRingElem] + P = @inferred collect(partitions(T(n), T(k), T(lb), T(ub); only_distinct_parts=true)) + @test P isa Vector{Oscar.Partition{T}} # Create the same by filtering all partitions - Q = collect(partitions(n, k, lb, ub)) + Q = @inferred collect(partitions(T(n), T(k), T(lb), T(ub))) + @test Q isa Vector{Oscar.Partition{T}} filter!( Q->Q==unique(Q), Q ) # Check that P and Q coincide (up to reordering) @@ -137,34 +148,36 @@ ############################################################################ # partitions(n,k,v,mu) ############################################################################ - @testset "partitions(n,k,v,mu)" begin + @testset "partitions(n, k, v, mu) for integer type $T" for T in [Int, Int16, ZZRingElem] # Check argument errors - @test_throws ArgumentError partitions(5,2, [1,2], [1,2,3]) - @test_throws ArgumentError partitions(-1,2, [1,2,3], [1,2,3]) - @test_throws ArgumentError partitions(5,0,[1,2,3], [1,2]) - @test_throws ArgumentError partitions(6,3,[3,2,1],[1,2,3]) #req v strictly increasing - @test_throws ArgumentError partitions(6,3,[3,2,1],[0,2,3]) #mu > 0 - @test_throws ArgumentError partitions(6,3,[0,2,1],[1,2,3]) #v > 0 + @test_throws ArgumentError partitions(T(5), 2, T[1,2], [1,2,3]) + @test_throws ArgumentError partitions(T(-1), 2, T[1,2,3], [1,2,3]) + @test_throws ArgumentError partitions(T(5), 0, T[1,2,3], [1,2]) + @test_throws ArgumentError partitions(T(6), 3, T[3,2,1], [1,2,3]) #req v strictly increasing + @test_throws ArgumentError partitions(T(6), 3, T[3,2,1], [0,2,3]) #mu > 0 + @test_throws ArgumentError partitions(T(6), 3, T[0,2,1], [1,2,3]) #v > 0 # Issues from https://github.com/oscar-system/Oscar.jl/issues/2043 - @test length(collect(partitions(17, 3, [1, 4], [1,4]))) == 0 - @test collect(partitions(17, 5, [1, 4], [1, 4])) == [ partition(4, 4, 4, 4, 1) ] - @test length(collect(partitions(17, 6, [1, 2], [1, 7]))) == 0 - @test length(collect(partitions(20, 5, [1, 2, 3], [1, 3, 6]))) == 0 + @test length(collect(partitions(T(17), 3, T[1, 4], [1,4]))) == 0 + @test collect(partitions(T(17), 5, T[1, 4], [1, 4])) == [ partition(T[4, 4, 4, 4, 1]) ] + @test length(collect(partitions(T(17), 6, T[1, 2], [1, 7]))) == 0 + @test length(collect(partitions(T(20), 5, T[1, 2, 3], [1, 3, 6]))) == 0 # Issues UT found - @test length(collect(partitions(1, 1, [1], [1]))) == 1 - @test length(collect(partitions(100, 7, [1, 2, 5, 10, 20, 50], [2, 2, 2, 2, 2, 2]))) == 1 + @test length(collect(partitions(T(1), 1, T[1], [1]))) == 1 + @test length(collect(partitions(T(100), 7, T[1, 2, 5, 10, 20, 50], [2, 2, 2, 2, 2, 2]))) == 1 # Special cases @testset "Special cases n=$n, k=$k" for n in 0:20, k in 0:n+1 - P = collect(partitions(n, k, [i for i in 1:n], [n for i in 1:n])) - Q = collect(partitions(n, k)) + P = @inferred collect(partitions(T(n), k, T[i for i in 1:n], [n for i in 1:n])) + @test P isa Vector{Oscar.Partition{T}} + Q = collect(partitions(T(n), T(k))) @test length(P) == length(Q) @test Set(P) == Set(Q) - P = collect(partitions(n, k, [i for i in 1:n], [1 for i in 1:n])) - Q = collect(partitions(n, k, 1, n; only_distinct_parts=true)) + P = @inferred collect(partitions(T(n), k, T[i for i in 1:n], [1 for i in 1:n])) + @test P isa Vector{Oscar.Partition{T}} + Q = collect(partitions(T(n), T(k), T(1), T(n); only_distinct_parts=true)) @test length(P) == length(Q) @test Set(P) == Set(Q) end @@ -190,7 +203,6 @@ @test collect(partitions(1, Int[], Int[])) == Partition{Int}[] end - ############################################################################ # dominates(P) ############################################################################ diff --git a/test/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl b/test/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl index a8e12bd3ab35..4531532e6ff2 100644 --- a/test/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl +++ b/test/Combinatorics/EnumerativeCombinatorics/schur_polynomials.jl @@ -45,4 +45,9 @@ schur_polynomial(S, partition([2,1,1]), 3) == x[1]*x[2]*x[3]*(x[1]+x[2]+x[3]) schur_polynomial(S, partition([2,2]), 3) == x[1]^2*x[2]^2 + x[1]^2*x[3]^2 + x[2]^2*x[3]^2 + x[1]^2*x[2]*x[3] + x[1]*x[2]^2*x[3] + x[1]*x[2]*x[3]^2 + # From issue #3850 + R, _ = polynomial_ring(ZZ, ["x1", "x2", "x3"]) + f = Oscar.schur_polynomial_cbf(R, partition([49, 2])) + g = Oscar.schur_polynomial_combinat(R, partition([49, 2])) + @test f == g end diff --git a/test/Combinatorics/EnumerativeCombinatorics/tableaux.jl b/test/Combinatorics/EnumerativeCombinatorics/tableaux.jl index e994a4f1d9d1..f63cd47884f3 100644 --- a/test/Combinatorics/EnumerativeCombinatorics/tableaux.jl +++ b/test/Combinatorics/EnumerativeCombinatorics/tableaux.jl @@ -18,6 +18,7 @@ @test is_standard(young_tableau([[1,4],[2,4]])) == false @test is_standard(young_tableau([[1,2],[4]])) == false @test is_standard(young_tableau([[1,3,2],[4]])) == false + @test is_standard(young_tableau([[-1]])) == false # is_semistandard @test is_semistandard(young_tableau([[1,2,4,7,8],[3,5,6,9],[10]])) == true @@ -28,6 +29,7 @@ @test is_semistandard(young_tableau([[1,2,2],[3]])) == true @test is_semistandard(young_tableau([[1,2,3],[1,4]])) == false @test is_semistandard(young_tableau([[1,2,1],[2,4]])) == false + @test is_semistandard(young_tableau([[-1]])) == true # semistandard_tableaux(shape::Array{T,1}, max_val=sum(shape)::Integer) shapes = [[3,2,1],[3,3,1],[2,2,2]] diff --git a/test/Combinatorics/EnumerativeCombinatorics/weak_compositions.jl b/test/Combinatorics/EnumerativeCombinatorics/weak_compositions.jl index 57ceeb59d916..29aaedb03dd2 100644 --- a/test/Combinatorics/EnumerativeCombinatorics/weak_compositions.jl +++ b/test/Combinatorics/EnumerativeCombinatorics/weak_compositions.jl @@ -1,30 +1,29 @@ -@testset "weak compositions" begin - @test length(weak_compositions(3, 2)) == 4 - @test @inferred collect(weak_compositions(3, 2)) == map(weak_composition, [[3, 0], [2, 1], [1, 2], [0, 3]]) - @test @inferred collect(weak_compositions(Int8(3), 2)) == map(weak_composition, Vector{Int8}[[3, 0], [2, 1], [1, 2], [0, 3]]) - @test isempty(weak_compositions(1, 0)) - @test @inferred collect(weak_compositions(1, 0)) == Oscar.WeakComposition{Int}[] - @test length(weak_compositions(0, 0)) == 1 - @test @inferred collect(weak_compositions(0, 0)) == [weak_composition(Int[])] - @test length(weak_compositions(0, 3)) == 1 - @test @inferred collect(weak_compositions(0, 3)) == [weak_composition(Int[0, 0, 0])] +@testset "weak compositions for integer type $T" for T in [Int, Int8, ZZRingElem] + @test length(weak_compositions(T(3), T(2))) == 4 + @test @inferred collect(weak_compositions(T(3), T(2))) == map(weak_composition, [T[3, 0], T[2, 1], T[1, 2], T[0, 3]]) + @test isempty(weak_compositions(T(1), T(0))) + @test @inferred collect(weak_compositions(T(1), T(0))) == Oscar.WeakComposition{T}[] + @test length(weak_compositions(T(0), T(0))) == 1 + @test @inferred collect(weak_compositions(T(0), T(0))) == [weak_composition(T[])] + @test length(weak_compositions(T(0), T(3))) == 1 + @test @inferred collect(weak_compositions(T(0), T(3))) == [weak_composition(T[0, 0, 0])] - l = @inferred collect(weak_compositions(5, 3)) + l = @inferred collect(weak_compositions(T(5), T(3))) @test length(l) == 21 @test all(x -> sum(x) == 5, l) b = unique!(l) @test length(b) == length(l) - l = @inferred collect(weak_compositions(5, 0)) - @test l == Vector{Oscar.WeakComposition{Int}}() - l = @inferred collect(weak_compositions(0, 7)) - @test l == [weak_composition([0 for i in 1:7])] - l = @inferred collect(weak_compositions(1, 7)) + l = @inferred collect(weak_compositions(T(5), T(0))) + @test l == Vector{Oscar.WeakComposition{T}}() + l = @inferred collect(weak_compositions(T(0), T(7))) + @test l == [weak_composition(T[0 for i in 1:7])] + l = @inferred collect(weak_compositions(T(1), T(7))) @test length(l) == length(unique!(l)) == 7 - l = @inferred collect(weak_compositions(7, 1)) - @test l == [weak_composition([7])] + l = @inferred collect(weak_compositions(T(7), T(1))) + @test l == [weak_composition(T[7])] - @test number_of_weak_compositions(1, -2) == ZZ(0) - @test number_of_weak_compositions(-1, 0) == ZZ(0) + @test number_of_weak_compositions(T(1), T(-2)) == ZZ(0) + @test number_of_weak_compositions(T(-1), T(0)) == ZZ(0) end