From dcbc9c3e9e0cae1f4f0e6de5eb113aa1f5dd8681 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 12:18:11 +0200 Subject: [PATCH 01/26] Enter permutations in Julia. --- experimental/Experimental.jl | 2 + experimental/Permutations/Permutations.jl | 182 ++++++++++++++++++++++ 2 files changed, 184 insertions(+) create mode 100644 experimental/Permutations/Permutations.jl diff --git a/experimental/Experimental.jl b/experimental/Experimental.jl index 9d287069b43b..b34ba5ad4cc0 100644 --- a/experimental/Experimental.jl +++ b/experimental/Experimental.jl @@ -6,6 +6,8 @@ include("InvariantTheory.jl") include("GITFans.jl") include("GModule.jl") +include("Permutations/Permutations.jl") + include("Schemes/AffineSchemes.jl") include("Schemes/SpecOpen.jl") include("Schemes/Glueing.jl") diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl new file mode 100644 index 000000000000..93d394beeae2 --- /dev/null +++ b/experimental/Permutations/Permutations.jl @@ -0,0 +1,182 @@ +module Permutations + + using GAP + using Oscar + using MacroTools + +function HelloWorld() + print("Hello World!") + end + + macro perm(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_(xs__)) || return x + :($f, ($(xs...),)) + end +end + + + macro perm(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_(args__) where f_ isa Expr ) || return x + :($f, ($(xs...),)) + end +end + +############ + +macro perm2(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_(xs__)) || return x + :($f, ($(xs...),)) + end +end + +macro perm(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_symbol(xs__) where isexpr(f_,String)) || return perm2(x) + return x + end +end + +############### +# Without MacroTools +############### + +# Working in some way +macro permNew(ex) + + h = (ex).head + arg = (ex).args + + res = [] + + while h != :tuple + arg1 = arg[1] + arguments = deleteat!(arg,1) + insert!(res,1,arguments) + h = (arg1).head + arg = (arg1).args + end + + insert!(res,1,arg) + + return res + +end + + +macro permNew2(ex) + + h = (ex).head + arg = (ex).args + + if h == :tuple + return ex + else + @capture(ex, f_(xs__)) || print("hello world") + res = [:($xs__)] + + return res + + h = f_.head + + while h != :tuple + arg1 = arg[1] + arguments = deleteat!(arg,1) + insert!(res,1,arguments) + h = (arg1).head + arg = (arg1).args + end + + insert!(res,1,arg) + + return res + + end +end + + +macro permNew3(ex) + h = (ex).head + arg = (ex).args + res = [] + + while h != :tuple + arg1 = arg[1] + arguments = deleteat!(arg,1) + for i in 1:length(arguments) + if !isexpr(arguments[i],Int64) + arguments[i] = eval(arguments[i]) + end + end + insert!(res,1,Tuple(x for x in arguments)) + h = (arg1).head + arg = (arg1).args + end + + for i in 1:length(arg) + if !isexpr(arg[i],Int64) + arg[i] = eval(arg[i]) + end + end + insert!(res,1,Tuple(x for x in arg)) + + n = length(res) + if n == 1 + return res[1] + end + if n == 2 + return (res[1],res[2]) + end + + r = (res[1],res[2]) + for i in 3:n + r = (r, res[i]) + end + + return r +end + + +macro permGens(n, gens) + + return [permNew(g) for g in gens] + +end + + +############### + +macro perm2(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_(xs__)) || return x + :($f, ($(xs...),)) + end +end + +macro perm3(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_var(xs__)) || @capture(x, f_(xs__)) || return x + :($f, ($(xs...),)) + :($f($(xs...))) + end +end + +macro test(ex) + MacroTools.postwalk(ex) do x + @capture(x, f_(f_(f_))) || @capture(x, f_(xs__)) || return x + :($f, ($(xs...),)) + :($f($(xs...))) + end +end + +#function permutation_group(::Type{T}, n::Int) where T <: Oscar.GAPGroup +# if n < 1 +# throw(ArgumentError("n must be a positive integer")) +# end +# return T(GAP.Globals.SymmetricGroup(_gap_filter(T), n))c + +end #module Permutations + +using .Permutations From fbda880e6cecfe605e527c447b48361b12b26a6d Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 12:19:07 +0200 Subject: [PATCH 02/26] Remove old code. --- experimental/Permutations/Permutations.jl | 124 ---------------------- 1 file changed, 124 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 93d394beeae2..7845df0092f7 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -4,99 +4,6 @@ module Permutations using Oscar using MacroTools -function HelloWorld() - print("Hello World!") - end - - macro perm(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_(xs__)) || return x - :($f, ($(xs...),)) - end -end - - - macro perm(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_(args__) where f_ isa Expr ) || return x - :($f, ($(xs...),)) - end -end - -############ - -macro perm2(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_(xs__)) || return x - :($f, ($(xs...),)) - end -end - -macro perm(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_symbol(xs__) where isexpr(f_,String)) || return perm2(x) - return x - end -end - -############### -# Without MacroTools -############### - -# Working in some way -macro permNew(ex) - - h = (ex).head - arg = (ex).args - - res = [] - - while h != :tuple - arg1 = arg[1] - arguments = deleteat!(arg,1) - insert!(res,1,arguments) - h = (arg1).head - arg = (arg1).args - end - - insert!(res,1,arg) - - return res - -end - - -macro permNew2(ex) - - h = (ex).head - arg = (ex).args - - if h == :tuple - return ex - else - @capture(ex, f_(xs__)) || print("hello world") - res = [:($xs__)] - - return res - - h = f_.head - - while h != :tuple - arg1 = arg[1] - arguments = deleteat!(arg,1) - insert!(res,1,arguments) - h = (arg1).head - arg = (arg1).args - end - - insert!(res,1,arg) - - return res - - end -end - - macro permNew3(ex) h = (ex).head arg = (ex).args @@ -145,37 +52,6 @@ macro permGens(n, gens) end - -############### - -macro perm2(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_(xs__)) || return x - :($f, ($(xs...),)) - end -end - -macro perm3(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_var(xs__)) || @capture(x, f_(xs__)) || return x - :($f, ($(xs...),)) - :($f($(xs...))) - end -end - -macro test(ex) - MacroTools.postwalk(ex) do x - @capture(x, f_(f_(f_))) || @capture(x, f_(xs__)) || return x - :($f, ($(xs...),)) - :($f($(xs...))) - end -end - -#function permutation_group(::Type{T}, n::Int) where T <: Oscar.GAPGroup -# if n < 1 -# throw(ArgumentError("n must be a positive integer")) -# end -# return T(GAP.Globals.SymmetricGroup(_gap_filter(T), n))c end #module Permutations From a22a3ce0509d7d5fe2c6a0f32d6d662bf59af06c Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 13:06:51 +0200 Subject: [PATCH 03/26] Good work. --- experimental/Permutations/Permutations.jl | 32 +++-------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 7845df0092f7..de3a66a438c7 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -4,45 +4,21 @@ module Permutations using Oscar using MacroTools -macro permNew3(ex) +macro perm(ex) h = (ex).head arg = (ex).args res = [] while h != :tuple arg1 = arg[1] - arguments = deleteat!(arg,1) - for i in 1:length(arguments) - if !isexpr(arguments[i],Int64) - arguments[i] = eval(arguments[i]) - end - end - insert!(res,1,Tuple(x for x in arguments)) + insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) h = (arg1).head arg = (arg1).args end - for i in 1:length(arg) - if !isexpr(arg[i],Int64) - arg[i] = eval(arg[i]) - end - end - insert!(res,1,Tuple(x for x in arg)) - - n = length(res) - if n == 1 - return res[1] - end - if n == 2 - return (res[1],res[2]) - end - - r = (res[1],res[2]) - for i in 3:n - r = (r, res[i]) - end + insert!(res,1,Expr(:vect,arg...)) - return r + return :(Oscar.cperm($(res...))) end From c10c927d896b338794af2662e94a25e0de3dfe25 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 13:29:35 +0200 Subject: [PATCH 04/26] Working tests. --- experimental/Permutations/Permutations.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index de3a66a438c7..8ed7ed5fe8a9 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -2,7 +2,6 @@ module Permutations using GAP using Oscar - using MacroTools macro perm(ex) h = (ex).head @@ -18,7 +17,7 @@ macro perm(ex) insert!(res,1,Expr(:vect,arg...)) - return :(Oscar.cperm($(res...))) + return esc(:(Oscar.cperm($(res...)))) end From 87116bd8801cc2edb37a30dea2f209df78536a2e Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 13:30:29 +0200 Subject: [PATCH 05/26] Include tests. --- test/Modules/Julia-Mat-test.jl | 80 ++++++++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 81 insertions(+) create mode 100644 test/Modules/Julia-Mat-test.jl diff --git a/test/Modules/Julia-Mat-test.jl b/test/Modules/Julia-Mat-test.jl new file mode 100644 index 000000000000..a5929bbd7390 --- /dev/null +++ b/test/Modules/Julia-Mat-test.jl @@ -0,0 +1,80 @@ +@testset "Binomial Ideals" begin + + @testset "Binomial and unital test" begin + R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) + f = x+y + @test isbinomial(f) + J = ideal(R, [x^2-y^3, z^2]) + @test isbinomial(J) + Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) + I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) + @test Oscar.isbinomial(I) + @test Oscar.isunital(I) + + J = ideal([x*y - z*t^2 + t^3, z*t^2-t^3]) + @test Oscar.isbinomial(J) + J1 = ideal(Qxy, x^2+y^2+z^2) + @test !Oscar.isbinomial(J1) + end + + @testset "Cellular decomposition" begin + + R, x = PolynomialRing(QQ, "x"=>1:5) + I = ideal(R, [x[1]^3*x[3]-x[1]^3, x[1]^4, x[1]^2*x[2]*x[4]-x[1]^2*x[2], x[2]^2, x[4]^3-1]) + @test iscellular(I)[1] + I = ideal(R, [x[1]*x[4]^2-x[2]*x[5]^2, x[1]^3*x[3]^3-x[2]^4*x[4]^2, x[2]*x[4]^8-x[3]^3*x[5]^6]) + @test !iscellular(I)[1] + Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) + I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) + @test !Oscar.iscellular(I)[1] + lI = Oscar.cellular_decomposition(I) + lI2 = Oscar.cellular_decomposition_macaulay(I) + @test length(lI) == length(lI2) + for x in lI + @test iscellular(x)[1] + @test x in lI2 + end + R, x = PolynomialRing(QQ, "x"=>1:3) + I = ideal(R, [x[3]^2*(x[1]^2-x[2]^2), x[3]*(x[1]^4-x[2]^4), x[3]^3]) + ap = cellular_minimal_associated_primes(I) + @test length(ap) == 1 + RQab = base_ring(ap[1]) + @test ap[1] == ideal(RQab, [RQab[3]]) + + end + + @testset "Binomial primary decomposition" begin + Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) + I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) + lP = Oscar.binomial_primary_decomposition(I) + + J = lP[1][1] + for i = 2:length(lP) + J = intersect(J, lP[i][1]) + end + RQab = base_ring(J) + Qab = base_ring(RQab) + x, y, z, t = gens(RQab) + IQab = ideal([x*y, z*t^2-t^3, z^2-y^2]) + @test IQab == J + + + I = Oscar.birth_death_ideal(2, 1) + lP = Oscar.primary_decomposition(I) + lP1 = Oscar.binomial_primary_decomposition(I) + @test length(lP) == length(lP1) + RQab = base_ring(lP1[1][1]) + Qab = base_ring(RQab) + for x in lP + y = ideal(RQab, [map_coefficients(Qab, p, parent = RQab) for p in gens(x[1])]) + z = ideal(RQab, [map_coefficients(Qab, p, parent = RQab) for p in gens(x[2])]) + @test (y, z) in lP1 + end + + R, x = PolynomialRing(QQ, "x"=>1:3) + I = ideal(R, [x[3]^2*(x[1]^2-x[2]^2), x[3]*(x[1]^4-x[2]^4), x[3]^3]) + @test length(Oscar.binomial_primary_decomposition(I)) == 5 + + end + +end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 9c45aba45d61..7455e836b19d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -47,6 +47,7 @@ include("Experimental/galois-test.jl") include("Experimental/gmodule-test.jl") include("Experimental/ModStdQt-test.jl") include("Experimental/ModStdNF-test.jl") +include("Experimental/Permutations-test.jl") include("Modules/UngradedModules.jl") include("Modules/ModulesGraded.jl") From b495eb74e7f726924680ed2f43d6af27763494d1 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 13:32:03 +0200 Subject: [PATCH 06/26] Include correct tests. --- test/Experimental/Permutations-test.jl | 12 ++++ test/Modules/Julia-Mat-test.jl | 80 -------------------------- 2 files changed, 12 insertions(+), 80 deletions(-) create mode 100644 test/Experimental/Permutations-test.jl delete mode 100644 test/Modules/Julia-Mat-test.jl diff --git a/test/Experimental/Permutations-test.jl b/test/Experimental/Permutations-test.jl new file mode 100644 index 000000000000..3edd557e2af5 --- /dev/null +++ b/test/Experimental/Permutations-test.jl @@ -0,0 +1,12 @@ +@testset "Examples.Permutations" begin + p = Oscar.Permutations.@perm (1,2)(3,4)(5,6) + @test p == cperm([1,2],[3,4],[5,6]) + p = Oscar.Permutations.@perm (1,2)(3,4,5)(7,8,9) + @test p == cperm([1,2],[3,4,5],[7,8,9]) + + a=1;b=2;f=x->3*x + 2; + p = Oscar.Permutations.@perm (a,f(a),b)(a+1,b*2) + @test p == cperm([1,5,4,2]) +end + + diff --git a/test/Modules/Julia-Mat-test.jl b/test/Modules/Julia-Mat-test.jl deleted file mode 100644 index a5929bbd7390..000000000000 --- a/test/Modules/Julia-Mat-test.jl +++ /dev/null @@ -1,80 +0,0 @@ -@testset "Binomial Ideals" begin - - @testset "Binomial and unital test" begin - R, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"]) - f = x+y - @test isbinomial(f) - J = ideal(R, [x^2-y^3, z^2]) - @test isbinomial(J) - Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) - I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) - @test Oscar.isbinomial(I) - @test Oscar.isunital(I) - - J = ideal([x*y - z*t^2 + t^3, z*t^2-t^3]) - @test Oscar.isbinomial(J) - J1 = ideal(Qxy, x^2+y^2+z^2) - @test !Oscar.isbinomial(J1) - end - - @testset "Cellular decomposition" begin - - R, x = PolynomialRing(QQ, "x"=>1:5) - I = ideal(R, [x[1]^3*x[3]-x[1]^3, x[1]^4, x[1]^2*x[2]*x[4]-x[1]^2*x[2], x[2]^2, x[4]^3-1]) - @test iscellular(I)[1] - I = ideal(R, [x[1]*x[4]^2-x[2]*x[5]^2, x[1]^3*x[3]^3-x[2]^4*x[4]^2, x[2]*x[4]^8-x[3]^3*x[5]^6]) - @test !iscellular(I)[1] - Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) - I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) - @test !Oscar.iscellular(I)[1] - lI = Oscar.cellular_decomposition(I) - lI2 = Oscar.cellular_decomposition_macaulay(I) - @test length(lI) == length(lI2) - for x in lI - @test iscellular(x)[1] - @test x in lI2 - end - R, x = PolynomialRing(QQ, "x"=>1:3) - I = ideal(R, [x[3]^2*(x[1]^2-x[2]^2), x[3]*(x[1]^4-x[2]^4), x[3]^3]) - ap = cellular_minimal_associated_primes(I) - @test length(ap) == 1 - RQab = base_ring(ap[1]) - @test ap[1] == ideal(RQab, [RQab[3]]) - - end - - @testset "Binomial primary decomposition" begin - Qxy, (x, y, z, t) = PolynomialRing(FlintQQ, 4) - I = ideal(elem_type(Qxy)[x*y, z*t^2-t^3, z^2-y^2]) - lP = Oscar.binomial_primary_decomposition(I) - - J = lP[1][1] - for i = 2:length(lP) - J = intersect(J, lP[i][1]) - end - RQab = base_ring(J) - Qab = base_ring(RQab) - x, y, z, t = gens(RQab) - IQab = ideal([x*y, z*t^2-t^3, z^2-y^2]) - @test IQab == J - - - I = Oscar.birth_death_ideal(2, 1) - lP = Oscar.primary_decomposition(I) - lP1 = Oscar.binomial_primary_decomposition(I) - @test length(lP) == length(lP1) - RQab = base_ring(lP1[1][1]) - Qab = base_ring(RQab) - for x in lP - y = ideal(RQab, [map_coefficients(Qab, p, parent = RQab) for p in gens(x[1])]) - z = ideal(RQab, [map_coefficients(Qab, p, parent = RQab) for p in gens(x[2])]) - @test (y, z) in lP1 - end - - R, x = PolynomialRing(QQ, "x"=>1:3) - I = ideal(R, [x[3]^2*(x[1]^2-x[2]^2), x[3]*(x[1]^4-x[2]^4), x[3]^3]) - @test length(Oscar.binomial_primary_decomposition(I)) == 5 - - end - -end \ No newline at end of file From 1dec78c035d43bb03e39c167e224ba37c6345ab1 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 14:11:37 +0200 Subject: [PATCH 07/26] Solve merge conflict. --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7455e836b19d..460dec7bdd20 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -42,12 +42,12 @@ end include("Rings/binomial-ideals-test.jl") +include("Experimental/Permutations-test.jl") include("Experimental/PlaneCurve-test.jl") include("Experimental/galois-test.jl") include("Experimental/gmodule-test.jl") include("Experimental/ModStdQt-test.jl") include("Experimental/ModStdNF-test.jl") -include("Experimental/Permutations-test.jl") include("Modules/UngradedModules.jl") include("Modules/ModulesGraded.jl") From 02680e933486c7d1aa420dd701e589495c77e09a Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 15:13:15 +0200 Subject: [PATCH 08/26] Generate group with julia permutations. --- experimental/Permutations/Permutations.jl | 32 +++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 8ed7ed5fe8a9..64ba8e9b6873 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -21,10 +21,38 @@ macro perm(ex) end -macro permGens(n, gens) +macro perm(n,gens) + + s = symmetric_group(n) + ores = Vector{Expr}(undef,length(gens.args)) + i = 1 + for g in gens.args + h = g.head + arg = g.args + res = [] + + while h != :tuple + arg1 = arg[1] + insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) + h = (arg1).head + arg = (arg1).args + end + + insert!(res,1,Expr(:vect,arg...)) + + ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) + i = i + 1 + end + + return Expr(:vect,ores...) +end + + +function permgroup(n::Int64,gens::Vector{PermGroupElem}) - return [permNew(g) for g in gens] + print(GAP.Obj([GAP.Obj(x) for x in gens ])) + return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) end From b480ac3d44fe2a19ce187148dcf071ba597c6ab7 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 15:32:30 +0200 Subject: [PATCH 09/26] More tests. --- experimental/Permutations/Permutations.jl | 6 ++++-- test/Experimental/Permutations-test.jl | 26 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 64ba8e9b6873..5246d4e27b67 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -50,11 +50,13 @@ end function permgroup(n::Int64,gens::Vector{PermGroupElem}) - print(GAP.Obj([GAP.Obj(x) for x in gens ])) - return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) end +function size(G::PermGroup) + return GAP.Globals.Size(G.X) +end + end #module Permutations diff --git a/test/Experimental/Permutations-test.jl b/test/Experimental/Permutations-test.jl index 3edd557e2af5..e9e9d4b3340a 100644 --- a/test/Experimental/Permutations-test.jl +++ b/test/Experimental/Permutations-test.jl @@ -7,6 +7,32 @@ a=1;b=2;f=x->3*x + 2; p = Oscar.Permutations.@perm (a,f(a),b)(a+1,b*2) @test p == cperm([1,5,4,2]) + + gens = Oscar.Permutations.@perm 14 [ + (1,10) + (2,11) + (3,12) + (4,13) + (5,14) + (6,8) + (7,9) + (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) + (1,2)(10,11) + ] + p = Vector{PermGroupElem}(undef,9) + p[1] = cperm(symmetric_group(14),[1,10]) + p[2] = cperm(symmetric_group(14),[2,11]) + p[3] = cperm(symmetric_group(14),[3,12]) + p[4] = cperm(symmetric_group(14),[4,13]) + p[5] = cperm(symmetric_group(14),[5,14]) + p[6] = cperm(symmetric_group(14),[6,8]) + p[7] = cperm(symmetric_group(14),[7,9]) + p[8] = cperm(symmetric_group(14),[1,2,3,4,5,6,7],[8,9,10,11,12,13,14]) + p[9] = cperm(symmetric_group(14),[1,2],[10,11]) + @test gens == p + + G = Oscar.Permutations.permgroup(14,gens) + @test Oscar.Permutations.size(G) == 645120 end From c6204ce432c5f6d70442566c6918d043ab65783d Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 15:57:23 +0200 Subject: [PATCH 10/26] Add documentation. --- experimental/Permutations/Permutations.jl | 79 ++++++++++++++++++++++- 1 file changed, 76 insertions(+), 3 deletions(-) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 5246d4e27b67..27b987dd3557 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -1,8 +1,20 @@ +# This file implements a new way to input permutations in Julia. For example +# it is possible to create a permutation as follow +# pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) +# > (1,2,3)(4,5)(6,7,8) +# For this we use macros to modify the syntax tree of (1,2,3)(4,5)(6,7,8) such that +# Julia can deal with the expression. + module Permutations using GAP using Oscar +################################################################################ +# Macro to input a permutation as +# julia> pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) +# > (1,2,3)(4,5)(6,7,8) +# macro perm(ex) h = (ex).head arg = (ex).args @@ -20,7 +32,34 @@ macro perm(ex) return esc(:(Oscar.cperm($(res...)))) end - +################################################################################ +# Macro to input a list of permutation which are generated as elements of +# the symmetric_group(n) +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ] +# > 9-element Vector{PermGroupElem}: +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# +# julia> gens[1].parent +# > Sym( [ 1 .. 14 ] ) macro perm(n,gens) s = symmetric_group(n) @@ -47,17 +86,51 @@ macro perm(n,gens) return Expr(:vect,ores...) end - +################################################################################ +# Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ]; +# julia> G = Oscar.Permutations.permgroup(14,gens) +# > +# function permgroup(n::Int64,gens::Vector{PermGroupElem}) return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) end +################################################################################ +# Computes the size of a PermGroup +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ]; +# julia> G = Oscar.Permutations.permgroup(14,gens); +# julia> Oscar.Permutations.size(G) +# > 645120 +# function size(G::PermGroup) return GAP.Globals.Size(G.X) end - + end #module Permutations using .Permutations From 082d0dc4d52e5fde03cb26c4d268f274815a4340 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 5 May 2022 16:55:16 +0200 Subject: [PATCH 11/26] Add error tests. --- test/Experimental/Permutations-test.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Experimental/Permutations-test.jl b/test/Experimental/Permutations-test.jl index e9e9d4b3340a..e02abfddc451 100644 --- a/test/Experimental/Permutations-test.jl +++ b/test/Experimental/Permutations-test.jl @@ -8,6 +8,8 @@ p = Oscar.Permutations.@perm (a,f(a),b)(a+1,b*2) @test p == cperm([1,5,4,2]) + @test_throws ErrorException Oscar.Permutations.@perm (-1, 1) + gens = Oscar.Permutations.@perm 14 [ (1,10) (2,11) @@ -31,6 +33,8 @@ p[9] = cperm(symmetric_group(14),[1,2],[10,11]) @test gens == p + @test_throws ArgumentError Oscar.Permutations.@perm 10 [(1,11)] + G = Oscar.Permutations.permgroup(14,gens) @test Oscar.Permutations.size(G) == 645120 end From cc477610e03b5b130a1a2977919551c2406450a9 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Tue, 10 May 2022 16:25:12 +0200 Subject: [PATCH 12/26] Save changes. --- experimental/Permutations/Permutations.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl index 27b987dd3557..506ebae169d3 100644 --- a/experimental/Permutations/Permutations.jl +++ b/experimental/Permutations/Permutations.jl @@ -130,6 +130,7 @@ function size(G::PermGroup) return GAP.Globals.Size(G.X) end + export @perm end #module Permutations From fbe66e9c8a643f23a4035ccc110bba1f153a88d0 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 13:02:35 +0200 Subject: [PATCH 13/26] move files --- experimental/Experimental.jl | 2 - experimental/Permutations/Permutations.jl | 137 ---------------------- src/Groups/perm.jl | 131 +++++++++++++++++++++ test/Experimental/Permutations-test.jl | 42 ------- test/runtests.jl | 2 +- 5 files changed, 132 insertions(+), 182 deletions(-) delete mode 100644 experimental/Permutations/Permutations.jl delete mode 100644 test/Experimental/Permutations-test.jl diff --git a/experimental/Experimental.jl b/experimental/Experimental.jl index b34ba5ad4cc0..9d287069b43b 100644 --- a/experimental/Experimental.jl +++ b/experimental/Experimental.jl @@ -6,8 +6,6 @@ include("InvariantTheory.jl") include("GITFans.jl") include("GModule.jl") -include("Permutations/Permutations.jl") - include("Schemes/AffineSchemes.jl") include("Schemes/SpecOpen.jl") include("Schemes/Glueing.jl") diff --git a/experimental/Permutations/Permutations.jl b/experimental/Permutations/Permutations.jl deleted file mode 100644 index 506ebae169d3..000000000000 --- a/experimental/Permutations/Permutations.jl +++ /dev/null @@ -1,137 +0,0 @@ -# This file implements a new way to input permutations in Julia. For example -# it is possible to create a permutation as follow -# pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) -# > (1,2,3)(4,5)(6,7,8) -# For this we use macros to modify the syntax tree of (1,2,3)(4,5)(6,7,8) such that -# Julia can deal with the expression. - -module Permutations - - using GAP - using Oscar - -################################################################################ -# Macro to input a permutation as -# julia> pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) -# > (1,2,3)(4,5)(6,7,8) -# -macro perm(ex) - h = (ex).head - arg = (ex).args - res = [] - - while h != :tuple - arg1 = arg[1] - insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) - h = (arg1).head - arg = (arg1).args - end - - insert!(res,1,Expr(:vect,arg...)) - - return esc(:(Oscar.cperm($(res...)))) -end - -################################################################################ -# Macro to input a list of permutation which are generated as elements of -# the symmetric_group(n) -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ] -# > 9-element Vector{PermGroupElem}: -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# -# julia> gens[1].parent -# > Sym( [ 1 .. 14 ] ) -macro perm(n,gens) - - s = symmetric_group(n) - ores = Vector{Expr}(undef,length(gens.args)) - i = 1 - for g in gens.args - h = g.head - arg = g.args - res = [] - - while h != :tuple - arg1 = arg[1] - insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) - h = (arg1).head - arg = (arg1).args - end - - insert!(res,1,Expr(:vect,arg...)) - - ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) - i = i + 1 - end - - return Expr(:vect,ores...) -end - -################################################################################ -# Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ]; -# julia> G = Oscar.Permutations.permgroup(14,gens) -# > -# -function permgroup(n::Int64,gens::Vector{PermGroupElem}) - - return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) -end - -################################################################################ -# Computes the size of a PermGroup -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ]; -# julia> G = Oscar.Permutations.permgroup(14,gens); -# julia> Oscar.Permutations.size(G) -# > 645120 -# -function size(G::PermGroup) - return GAP.Globals.Size(G.X) -end - - export @perm - -end #module Permutations - -using .Permutations diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index d926711ab483..c020fef1c7cc 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -387,3 +387,134 @@ function cycle_structure(g::PermGroupElem) # TODO: use SortedDict from DataStructures.jl ? return Pair{Int,Int}[ i+1 => c[i] for i in 1:length(c) if GAP.Globals.ISB_LIST(c, i) ] end + + +# This file implements a new way to input permutations in Julia. For example +# it is possible to create a permutation as follow +# pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) +# > (1,2,3)(4,5)(6,7,8) +# For this we use macros to modify the syntax tree of (1,2,3)(4,5)(6,7,8) such that +# Julia can deal with the expression. + + +################################################################################ +# Macro to input a permutation as +# julia> pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) +# > (1,2,3)(4,5)(6,7,8) +# +macro perm(ex) + h = (ex).head + arg = (ex).args + res = [] + + while h != :tuple + arg1 = arg[1] + insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) + h = (arg1).head + arg = (arg1).args + end + + insert!(res,1,Expr(:vect,arg...)) + + return esc(:(Oscar.cperm($(res...)))) +end + +################################################################################ +# Macro to input a list of permutation which are generated as elements of +# the symmetric_group(n) +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ] +# > 9-element Vector{PermGroupElem}: +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# +# julia> gens[1].parent +# > Sym( [ 1 .. 14 ] ) +macro perm(n,gens) + + s = symmetric_group(n) + ores = Vector{Expr}(undef,length(gens.args)) + i = 1 + for g in gens.args + h = g.head + arg = g.args + res = [] + + while h != :tuple + arg1 = arg[1] + insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) + h = (arg1).head + arg = (arg1).args + end + + insert!(res,1,Expr(:vect,arg...)) + + ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) + i = i + 1 + end + + return Expr(:vect,ores...) +end + +################################################################################ +# Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ]; +# julia> G = Oscar.Permutations.permgroup(14,gens) +# > +# +function permgroup(n::Int64,gens::Vector{PermGroupElem}) + + return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) +end + +################################################################################ +# Computes the size of a PermGroup +# Example: +# julia> gens = Oscar.Permutations.@perm 14 [ +# (1,10) +# (2,11) +# (3,12) +# (4,13) +# (5,14) +# (6,8) +# (7,9) +# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) +# (1,2)(10,11) +# ]; +# julia> G = Oscar.Permutations.permgroup(14,gens); +# julia> Oscar.Permutations.size(G) +# > 645120 +# +function size(G::PermGroup) + return GAP.Globals.Size(G.X) +end + +export @perm,permgroup,size diff --git a/test/Experimental/Permutations-test.jl b/test/Experimental/Permutations-test.jl deleted file mode 100644 index e02abfddc451..000000000000 --- a/test/Experimental/Permutations-test.jl +++ /dev/null @@ -1,42 +0,0 @@ -@testset "Examples.Permutations" begin - p = Oscar.Permutations.@perm (1,2)(3,4)(5,6) - @test p == cperm([1,2],[3,4],[5,6]) - p = Oscar.Permutations.@perm (1,2)(3,4,5)(7,8,9) - @test p == cperm([1,2],[3,4,5],[7,8,9]) - - a=1;b=2;f=x->3*x + 2; - p = Oscar.Permutations.@perm (a,f(a),b)(a+1,b*2) - @test p == cperm([1,5,4,2]) - - @test_throws ErrorException Oscar.Permutations.@perm (-1, 1) - - gens = Oscar.Permutations.@perm 14 [ - (1,10) - (2,11) - (3,12) - (4,13) - (5,14) - (6,8) - (7,9) - (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) - (1,2)(10,11) - ] - p = Vector{PermGroupElem}(undef,9) - p[1] = cperm(symmetric_group(14),[1,10]) - p[2] = cperm(symmetric_group(14),[2,11]) - p[3] = cperm(symmetric_group(14),[3,12]) - p[4] = cperm(symmetric_group(14),[4,13]) - p[5] = cperm(symmetric_group(14),[5,14]) - p[6] = cperm(symmetric_group(14),[6,8]) - p[7] = cperm(symmetric_group(14),[7,9]) - p[8] = cperm(symmetric_group(14),[1,2,3,4,5,6,7],[8,9,10,11,12,13,14]) - p[9] = cperm(symmetric_group(14),[1,2],[10,11]) - @test gens == p - - @test_throws ArgumentError Oscar.Permutations.@perm 10 [(1,11)] - - G = Oscar.Permutations.permgroup(14,gens) - @test Oscar.Permutations.size(G) == 645120 -end - - diff --git a/test/runtests.jl b/test/runtests.jl index 460dec7bdd20..8dafc1c72c43 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,6 +31,7 @@ include("Groups/runtests.jl") include("Rings/NumberField.jl") include("Rings/FunctionField-test.jl") include("Rings/AbelianClosure.jl") +include("Groups/Permutations.jl") include("Rings/MPolyAnyMap/MPolyRing.jl") include("Rings/MPolyAnyMap/MPolyQuo.jl") @@ -42,7 +43,6 @@ end include("Rings/binomial-ideals-test.jl") -include("Experimental/Permutations-test.jl") include("Experimental/PlaneCurve-test.jl") include("Experimental/galois-test.jl") include("Experimental/gmodule-test.jl") From eae2be00723ec030ef4a41f849e49e7f106584d8 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 13:36:02 +0200 Subject: [PATCH 14/26] move tests --- test/Groups/Permutations.jl | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/Groups/Permutations.jl diff --git a/test/Groups/Permutations.jl b/test/Groups/Permutations.jl new file mode 100644 index 000000000000..dcecd42249cf --- /dev/null +++ b/test/Groups/Permutations.jl @@ -0,0 +1,44 @@ +@testset "Examples.Permutations" begin + p = @perm (1,2)(3,4)(5,6) + @test p == cperm([1,2],[3,4],[5,6]) + p = @perm (1,2)(3,4,5)(7,8,9) + @test p == cperm([1,2],[3,4,5],[7,8,9]) + + a=1;b=2;f=x->3*x + 2; + p = @perm (a,f(a),b)(a+1,b*2) + @test p == cperm([1,5,4,2]) + + @test_throws ErrorException @perm (-1, 1) + @test_throws LoadError @perm "bla" + @test_throws LoadError @perm 1 + 1 + + gens = @perm 14 [ + (1,10) + (2,11) + (3,12) + (4,13) + (5,14) + (6,8) + (7,9) + (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) + (1,2)(10,11) + ] + p = Vector{PermGroupElem}(undef,9) + p[1] = cperm(symmetric_group(14),[1,10]) + p[2] = cperm(symmetric_group(14),[2,11]) + p[3] = cperm(symmetric_group(14),[3,12]) + p[4] = cperm(symmetric_group(14),[4,13]) + p[5] = cperm(symmetric_group(14),[5,14]) + p[6] = cperm(symmetric_group(14),[6,8]) + p[7] = cperm(symmetric_group(14),[7,9]) + p[8] = cperm(symmetric_group(14),[1,2,3,4,5,6,7],[8,9,10,11,12,13,14]) + p[9] = cperm(symmetric_group(14),[1,2],[10,11]) + @test gens == p + + @test_throws ArgumentError @perm 10 [(1,11)] + + G = permgroup(14,gens) + @test size(G) == 645120 +end + + From 94b4009167c8cc6fe483f24ffa8ed07687bca27d Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 16:55:16 +0200 Subject: [PATCH 15/26] Improve code. --- src/Groups/perm.jl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index c020fef1c7cc..e890be04c631 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -407,14 +407,18 @@ macro perm(ex) arg = (ex).args res = [] - while h != :tuple + while h == :call arg1 = arg[1] - insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) + pushfirst!(res, Expr(:vect,arg[2:end]...)) h = (arg1).head arg = (arg1).args end - insert!(res,1,Expr(:vect,arg...)) + if h != :tuple + error("Input is not a permutation.") + end + + pushfirst!(res, Expr(:vect,arg...)) return esc(:(Oscar.cperm($(res...)))) end @@ -457,14 +461,18 @@ macro perm(n,gens) arg = g.args res = [] - while h != :tuple + while h == :call arg1 = arg[1] - insert!(res,1,Expr(:vect,arg[2:length(arg)]...)) + pushfirst!(res, Expr(:vect,arg[2:end]...)) h = (arg1).head arg = (arg1).args end - insert!(res,1,Expr(:vect,arg...)) + if h != :tuple + error("Input is not a permutation.") + end + + pushfirst!(res, Expr(:vect,arg...)) ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) i = i + 1 @@ -514,7 +522,7 @@ end # > 645120 # function size(G::PermGroup) - return GAP.Globals.Size(G.X) + return order(G) end export @perm,permgroup,size From 074290636d1ec970fa0252d44b2a3b2b381175c4 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 17:09:33 +0200 Subject: [PATCH 16/26] Use Markdown for documentation.@ --- src/Groups/perm.jl | 138 +++++++++++++++++++----------------- test/Groups/Permutations.jl | 2 +- 2 files changed, 72 insertions(+), 68 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index e890be04c631..fb56123a2f5b 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -389,7 +389,7 @@ function cycle_structure(g::PermGroupElem) end -# This file implements a new way to input permutations in Julia. For example +# The following code implements a new way to input permutations in Julia. For example # it is possible to create a permutation as follow # pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) # > (1,2,3)(4,5)(6,7,8) @@ -398,10 +398,20 @@ end ################################################################################ -# Macro to input a permutation as -# julia> pi = Oscar.Permutations.@perm (1,2,3)(4,5)(6,7,8) -# > (1,2,3)(4,5)(6,7,8) # +# perm +# +@doc Markdown.doc""" + @perm(ex) +Macro to input a permutation as +pi = @perm (1,2,3)(4,5)(6,7,8) to obtain +(1,2,3)(4,5)(6,7,8) +# Examples (jldoctest) +``` +julia> @perm (1,2,3)(4,5)(6,7,8) +(1,2,3)(4,5)(6,7,8) +``` +""" macro perm(ex) h = (ex).head arg = (ex).args @@ -423,34 +433,42 @@ macro perm(ex) return esc(:(Oscar.cperm($(res...)))) end + ################################################################################ -# Macro to input a list of permutation which are generated as elements of -# the symmetric_group(n) -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ] -# > 9-element Vector{PermGroupElem}: -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) # -# julia> gens[1].parent -# > Sym( [ 1 .. 14 ] ) +# perm(n,gens) +# +@doc Markdown.doc""" + @perm(n,gens) +Macro to input a list of permutation which are generated as elements of +the symmetric_group(n) +# Examples (jldoctest) +``` +julia> gens = Oscar.Permutations.@perm 14 [ + (1,10) + (2,11) + (3,12) + (4,13) + (5,14) + (6,8) + (7,9) + (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) + (1,2)(10,11) + ] +9-element Vector{PermGroupElem}: + (1,10) + (2,11) + (3,12) + (4,13) + (5,14) + (6,8) + (7,9) + (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) + (1,2)(10,11) +julia> gens[1].parent +Sym( [ 1 .. 14 ] ) +``` +""" macro perm(n,gens) s = symmetric_group(n) @@ -481,48 +499,34 @@ macro perm(n,gens) return Expr(:vect,ores...) end + ################################################################################ -# Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ]; -# julia> G = Oscar.Permutations.permgroup(14,gens) -# > # +# permgroup(n::Int64,gens::Vector{PermGroupElem}) +# +@doc Markdown.doc""" + permgroup(n::Int64,gens::Vector{PermGroupElem}) +Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) +# Examples (jldoctest) +``` +julia> gens = Oscar.Permutations.@perm 14 [ + (1,10) + (2,11) + (3,12) + (4,13) + (5,14) + (6,8) + (7,9) + (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) + (1,2)(10,11) + ]; +julia> G = Oscar.Permutations.permgroup(14,gens) + +``` +""" function permgroup(n::Int64,gens::Vector{PermGroupElem}) return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) end -################################################################################ -# Computes the size of a PermGroup -# Example: -# julia> gens = Oscar.Permutations.@perm 14 [ -# (1,10) -# (2,11) -# (3,12) -# (4,13) -# (5,14) -# (6,8) -# (7,9) -# (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) -# (1,2)(10,11) -# ]; -# julia> G = Oscar.Permutations.permgroup(14,gens); -# julia> Oscar.Permutations.size(G) -# > 645120 -# -function size(G::PermGroup) - return order(G) -end - export @perm,permgroup,size diff --git a/test/Groups/Permutations.jl b/test/Groups/Permutations.jl index dcecd42249cf..fd6e51eecd9e 100644 --- a/test/Groups/Permutations.jl +++ b/test/Groups/Permutations.jl @@ -38,7 +38,7 @@ @test_throws ArgumentError @perm 10 [(1,11)] G = permgroup(14,gens) - @test size(G) == 645120 + @test order(G) == 645120 end From 9c697169fdd5c705bfce5ec2c656c5c7791e5211 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 17:47:32 +0200 Subject: [PATCH 17/26] Improve while loop --- src/Groups/perm.jl | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index fb56123a2f5b..915732e1f018 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -413,22 +413,18 @@ julia> @perm (1,2,3)(4,5)(6,7,8) ``` """ macro perm(ex) - h = (ex).head - arg = (ex).args res = [] - - while h == :call - arg1 = arg[1] - pushfirst!(res, Expr(:vect,arg[2:end]...)) - h = (arg1).head - arg = (arg1).args + + while (ex).head == :call + pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) + ex = (ex).args[1] end - if h != :tuple + if (ex).head != :tuple error("Input is not a permutation.") end - pushfirst!(res, Expr(:vect,arg...)) + pushfirst!(res, Expr(:vect,(ex).args...)) return esc(:(Oscar.cperm($(res...)))) end @@ -474,23 +470,19 @@ macro perm(n,gens) s = symmetric_group(n) ores = Vector{Expr}(undef,length(gens.args)) i = 1 - for g in gens.args - h = g.head - arg = g.args + for ex in gens.args res = [] - - while h == :call - arg1 = arg[1] - pushfirst!(res, Expr(:vect,arg[2:end]...)) - h = (arg1).head - arg = (arg1).args + + while (ex).head == :call + pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) + ex = (ex).args[1] end - if h != :tuple - error("Input is not a permutation.") + if (ex).head != :tuple + error("Input is not a permutation.") end - pushfirst!(res, Expr(:vect,arg...)) + pushfirst!(res, Expr(:vect,(ex).args...)) ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) i = i + 1 From 774874c6de9b7c2e46c4b3c29c52371acfcceaa1 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Wed, 11 May 2022 19:57:19 +0200 Subject: [PATCH 18/26] Catch more errors. --- src/Groups/perm.jl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index 915732e1f018..c4d2507f1219 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -414,10 +414,24 @@ julia> @perm (1,2,3)(4,5)(6,7,8) """ macro perm(ex) res = [] + + if typeof(ex) != Expr + error("Input is not a permutation.") + end + + if (ex).head != :call && (ex).head != :tuple + error("Input is not a permutation.") + end while (ex).head == :call pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) ex = (ex).args[1] + if typeof(ex) != Expr + error("Input is not a permutation.") + end + if (ex).head != :call && (ex).head != :tuple + error("Input is not a permutation.") + end end if (ex).head != :tuple @@ -472,10 +486,25 @@ macro perm(n,gens) i = 1 for ex in gens.args res = [] + + if typeof(ex) != Expr + throw(ArgumentError("Input is not a permutation.")) + error("Input is not a permutation.") + end + + if (ex).head != :call && (ex).head != :tuple + error("Input is not a permutation.") + end while (ex).head == :call pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) ex = (ex).args[1] + if typeof(ex) != Expr + error("Input is not a permutation.") + end + if (ex).head != :call && (ex).head != :tuple + error("Input is not a permutation.") + end end if (ex).head != :tuple From 6cd658b95808d1b17897cedcfc1a7a3e169468f4 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 12 May 2022 10:27:07 +0200 Subject: [PATCH 19/26] More improvements. --- src/Groups/perm.jl | 57 +++++++++++++++++++------------------ test/Groups/Permutations.jl | 2 +- test/Groups/runtests.jl | 1 + test/runtests.jl | 1 - 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index c4d2507f1219..f3bfadfdbe91 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -402,12 +402,13 @@ end # perm # @doc Markdown.doc""" - @perm(ex) + @perm(ex) Macro to input a permutation as -pi = @perm (1,2,3)(4,5)(6,7,8) to obtain -(1,2,3)(4,5)(6,7,8) -# Examples (jldoctest) -``` +`pi = @perm (1,2,3)(4,5)(6,7,8)` to obtain +the permutation `(1,2,3)(4,5)(6,7,8)`, that is, the output of +`cperm([1,2,3],[4,5],[6,7,8])`. +# Examples +```jldoctest julia> @perm (1,2,3)(4,5)(6,7,8) (1,2,3)(4,5)(6,7,8) ``` @@ -419,26 +420,26 @@ macro perm(ex) error("Input is not a permutation.") end - if (ex).head != :call && (ex).head != :tuple + if ex.head != :call && ex.head != :tuple error("Input is not a permutation.") end - while (ex).head == :call - pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) - ex = (ex).args[1] + while ex.head == :call + pushfirst!(res, Expr(:vect, ex.args[2:end]...)) + ex = ex.args[1] if typeof(ex) != Expr error("Input is not a permutation.") end - if (ex).head != :call && (ex).head != :tuple + if ex.head != :call && ex.head != :tuple error("Input is not a permutation.") end end - if (ex).head != :tuple + if ex.head != :tuple error("Input is not a permutation.") end - pushfirst!(res, Expr(:vect,(ex).args...)) + pushfirst!(res, Expr(:vect,ex.args...)) return esc(:(Oscar.cperm($(res...)))) end @@ -449,11 +450,11 @@ end # perm(n,gens) # @doc Markdown.doc""" - @perm(n,gens) -Macro to input a list of permutation which are generated as elements of -the symmetric_group(n) -# Examples (jldoctest) -``` + @perm(n,gens) +Macro to input a list of permutations which are generated as elements of +the `symmetric_group(n)` with the function `cperm`. +# Examples +```jldoctest julia> gens = Oscar.Permutations.@perm 14 [ (1,10) (2,11) @@ -492,26 +493,26 @@ macro perm(n,gens) error("Input is not a permutation.") end - if (ex).head != :call && (ex).head != :tuple + if ex.head != :call && ex.head != :tuple error("Input is not a permutation.") end - while (ex).head == :call - pushfirst!(res, Expr(:vect, (ex).args[2:end]...)) + while ex.head == :call + pushfirst!(res, Expr(:vect, ex.args[2:end]...)) ex = (ex).args[1] if typeof(ex) != Expr error("Input is not a permutation.") end - if (ex).head != :call && (ex).head != :tuple + if ex.head != :call && ex.head != :tuple error("Input is not a permutation.") end end - if (ex).head != :tuple + if ex.head != :tuple error("Input is not a permutation.") end - pushfirst!(res, Expr(:vect,(ex).args...)) + pushfirst!(res, Expr(:vect,ex.args...)) ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) i = i + 1 @@ -526,10 +527,10 @@ end # permgroup(n::Int64,gens::Vector{PermGroupElem}) # @doc Markdown.doc""" - permgroup(n::Int64,gens::Vector{PermGroupElem}) -Generates a PermGroup with generators gens as a subgroup of symmetric_group(n) -# Examples (jldoctest) -``` + permgroup(n::Int64,gens::Vector{PermGroupElem}) +Generates a `PermGroup` with generators gens as a subgroup of `symmetric_group(n)`. +# Examples +```jldoctest julia> gens = Oscar.Permutations.@perm 14 [ (1,10) (2,11) @@ -550,4 +551,4 @@ function permgroup(n::Int64,gens::Vector{PermGroupElem}) return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) end -export @perm,permgroup,size +export @perm,permgroup diff --git a/test/Groups/Permutations.jl b/test/Groups/Permutations.jl index fd6e51eecd9e..217e1181c030 100644 --- a/test/Groups/Permutations.jl +++ b/test/Groups/Permutations.jl @@ -1,6 +1,6 @@ @testset "Examples.Permutations" begin p = @perm (1,2)(3,4)(5,6) - @test p == cperm([1,2],[3,4],[5,6]) + @test p == cperm([1,2],[3,4],[5,6]) p = @perm (1,2)(3,4,5)(7,8,9) @test p == cperm([1,2],[3,4,5],[7,8,9]) diff --git a/test/Groups/runtests.jl b/test/Groups/runtests.jl index 2ffb378a7e92..0bebf7e264ac 100644 --- a/test/Groups/runtests.jl +++ b/test/Groups/runtests.jl @@ -21,3 +21,4 @@ include("MatrixDisplay.jl") include("group_characters.jl") include("FiniteFormOrthogonalGroup.jl") include("GrpAb.jl") +include("Permutations.jl") diff --git a/test/runtests.jl b/test/runtests.jl index 8dafc1c72c43..9c45aba45d61 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -31,7 +31,6 @@ include("Groups/runtests.jl") include("Rings/NumberField.jl") include("Rings/FunctionField-test.jl") include("Rings/AbelianClosure.jl") -include("Groups/Permutations.jl") include("Rings/MPolyAnyMap/MPolyRing.jl") include("Rings/MPolyAnyMap/MPolyQuo.jl") From 2e5a6cd6e1470fe70540d92488efb9d61a39e204 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Thu, 12 May 2022 10:28:48 +0200 Subject: [PATCH 20/26] Remove brackets. --- src/Groups/perm.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index f3bfadfdbe91..b51a5459477f 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -499,7 +499,7 @@ macro perm(n,gens) while ex.head == :call pushfirst!(res, Expr(:vect, ex.args[2:end]...)) - ex = (ex).args[1] + ex = ex.args[1] if typeof(ex) != Expr error("Input is not a permutation.") end From 9cbdcd3d3e8119bda27bf4bb8db48047c28b2457 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Fri, 13 May 2022 16:24:37 +0200 Subject: [PATCH 21/26] Some improvements from GitHub. --- src/Groups/perm.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index b51a5459477f..100aebb55873 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -403,6 +403,7 @@ end # @doc Markdown.doc""" @perm(ex) + Macro to input a permutation as `pi = @perm (1,2,3)(4,5)(6,7,8)` to obtain the permutation `(1,2,3)(4,5)(6,7,8)`, that is, the output of @@ -451,11 +452,12 @@ end # @doc Markdown.doc""" @perm(n,gens) + Macro to input a list of permutations which are generated as elements of the `symmetric_group(n)` with the function `cperm`. # Examples ```jldoctest -julia> gens = Oscar.Permutations.@perm 14 [ +julia> gens = @perm 14 [ (1,10) (2,11) (3,12) @@ -476,13 +478,13 @@ julia> gens = Oscar.Permutations.@perm 14 [ (7,9) (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) (1,2)(10,11) -julia> gens[1].parent + +julia> parent(gens[1]) Sym( [ 1 .. 14 ] ) ``` """ macro perm(n,gens) - s = symmetric_group(n) ores = Vector{Expr}(undef,length(gens.args)) i = 1 for ex in gens.args @@ -528,11 +530,12 @@ end # @doc Markdown.doc""" permgroup(n::Int64,gens::Vector{PermGroupElem}) + Generates a `PermGroup` with generators gens as a subgroup of `symmetric_group(n)`. # Examples ```jldoctest julia> gens = Oscar.Permutations.@perm 14 [ - (1,10) + (1,10) (2,11) (3,12) (4,13) From bd16a6f6db14d6c3908c5018cf43151d34b32bbe Mon Sep 17 00:00:00 2001 From: Daniel Rademacher <33546089+danielrademacher@users.noreply.github.com> Date: Fri, 13 May 2022 16:27:51 +0200 Subject: [PATCH 22/26] Update src/Groups/perm.jl Co-authored-by: Max Horn --- src/Groups/perm.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index 100aebb55873..31bfa9dc6415 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -458,7 +458,7 @@ the `symmetric_group(n)` with the function `cperm`. # Examples ```jldoctest julia> gens = @perm 14 [ - (1,10) + (1,10) (2,11) (3,12) (4,13) From 61eb6f95221a42d6ef71a46bad44660da0e36e0a Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Fri, 13 May 2022 16:33:26 +0200 Subject: [PATCH 23/26] More improvements. --- src/Groups/perm.jl | 33 +-------------------------------- test/Groups/Permutations.jl | 6 +++--- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index 31bfa9dc6415..1768a9f92008 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -523,35 +523,4 @@ macro perm(n,gens) return Expr(:vect,ores...) end - -################################################################################ -# -# permgroup(n::Int64,gens::Vector{PermGroupElem}) -# -@doc Markdown.doc""" - permgroup(n::Int64,gens::Vector{PermGroupElem}) - -Generates a `PermGroup` with generators gens as a subgroup of `symmetric_group(n)`. -# Examples -```jldoctest -julia> gens = Oscar.Permutations.@perm 14 [ - (1,10) - (2,11) - (3,12) - (4,13) - (5,14) - (6,8) - (7,9) - (1,2,3,4,5,6,7)(8,9,10,11,12,13,14) - (1,2)(10,11) - ]; -julia> G = Oscar.Permutations.permgroup(14,gens) - -``` -""" -function permgroup(n::Int64,gens::Vector{PermGroupElem}) - - return PermGroup(GAP.Globals.Subgroup(GAP.Globals.SymmetricGroup(GAP.Obj(n)),GAP.Obj([GAP.Obj(x) for x in gens ]))) -end - -export @perm,permgroup +export @perm diff --git a/test/Groups/Permutations.jl b/test/Groups/Permutations.jl index 217e1181c030..f8914cbc4e00 100644 --- a/test/Groups/Permutations.jl +++ b/test/Groups/Permutations.jl @@ -9,8 +9,8 @@ @test p == cperm([1,5,4,2]) @test_throws ErrorException @perm (-1, 1) - @test_throws LoadError @perm "bla" - @test_throws LoadError @perm 1 + 1 + @test_throws LoadError @eval @perm "bla" + @test_throws LoadError @eval @perm 1 + 1 gens = @perm 14 [ (1,10) @@ -37,7 +37,7 @@ @test_throws ArgumentError @perm 10 [(1,11)] - G = permgroup(14,gens) + G = sub(symmetric_group(14),gens)[1] @test order(G) == 645120 end From fe5d38e72726ffaaf0a2571704a49660e567fad1 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Fri, 13 May 2022 17:35:01 +0200 Subject: [PATCH 24/26] More improvements. --- src/Groups/perm.jl | 82 ++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 54 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index 1768a9f92008..db406b59b2ff 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -397,6 +397,30 @@ end # Julia can deal with the expression. +################################################################################ +# +# _perm_helper +# + +function _perm_helper(ex::Expr) + res = [] + + while ex.head == :call + pushfirst!(res, Expr(:vect, ex.args[2:end]...)) + ex = ex.args[1] + ex isa Expr || error("Input is not a permutation expression") + end + + if ex.head != :tuple + error("Input is not a permutation.") + end + + pushfirst!(res, Expr(:vect,ex.args...)) + + return res +end + + ################################################################################ # # perm @@ -415,33 +439,8 @@ julia> @perm (1,2,3)(4,5)(6,7,8) ``` """ macro perm(ex) - res = [] - - if typeof(ex) != Expr - error("Input is not a permutation.") - end - - if ex.head != :call && ex.head != :tuple - error("Input is not a permutation.") - end - - while ex.head == :call - pushfirst!(res, Expr(:vect, ex.args[2:end]...)) - ex = ex.args[1] - if typeof(ex) != Expr - error("Input is not a permutation.") - end - if ex.head != :call && ex.head != :tuple - error("Input is not a permutation.") - end - end - - if ex.head != :tuple - error("Input is not a permutation.") - end - - pushfirst!(res, Expr(:vect,ex.args...)) - + ex isa Expr || error("Input is not a permutation expression") + res = _perm_helper(ex) return esc(:(Oscar.cperm($(res...)))) end @@ -488,33 +487,8 @@ macro perm(n,gens) ores = Vector{Expr}(undef,length(gens.args)) i = 1 for ex in gens.args - res = [] - - if typeof(ex) != Expr - throw(ArgumentError("Input is not a permutation.")) - error("Input is not a permutation.") - end - - if ex.head != :call && ex.head != :tuple - error("Input is not a permutation.") - end - - while ex.head == :call - pushfirst!(res, Expr(:vect, ex.args[2:end]...)) - ex = ex.args[1] - if typeof(ex) != Expr - error("Input is not a permutation.") - end - if ex.head != :call && ex.head != :tuple - error("Input is not a permutation.") - end - end - - if ex.head != :tuple - error("Input is not a permutation.") - end - - pushfirst!(res, Expr(:vect,ex.args...)) + ex isa Expr || error("Input is not a permutation expression") + res = _perm_helper(ex) ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) i = i + 1 From 9628dce8f9ed4e9500f534bb16b6b9f55edad386 Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Fri, 13 May 2022 17:45:11 +0200 Subject: [PATCH 25/26] More improvements. --- src/Groups/perm.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index db406b59b2ff..afffe173a469 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -405,13 +405,12 @@ end function _perm_helper(ex::Expr) res = [] - while ex.head == :call + while ex isa Expr && ex.head == :call pushfirst!(res, Expr(:vect, ex.args[2:end]...)) ex = ex.args[1] - ex isa Expr || error("Input is not a permutation expression") end - if ex.head != :tuple + if !(ex isa Expr) || ex.head != :tuple error("Input is not a permutation.") end From 946a9afddfdb87fec945927d52eee697830e0a9f Mon Sep 17 00:00:00 2001 From: Daniel Rademacher Date: Fri, 13 May 2022 18:09:01 +0200 Subject: [PATCH 26/26] Final improvements. --- src/Groups/perm.jl | 17 ++++++++++++----- test/Groups/Permutations.jl | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Groups/perm.jl b/src/Groups/perm.jl index afffe173a469..19a18207dd5e 100644 --- a/src/Groups/perm.jl +++ b/src/Groups/perm.jl @@ -403,6 +403,7 @@ end # function _perm_helper(ex::Expr) + res = [] while ex isa Expr && ex.head == :call @@ -438,6 +439,7 @@ julia> @perm (1,2,3)(4,5)(6,7,8) ``` """ macro perm(ex) + ex != :( () ) || return cperm() ex isa Expr || error("Input is not a permutation expression") res = _perm_helper(ex) return esc(:(Oscar.cperm($(res...)))) @@ -486,11 +488,16 @@ macro perm(n,gens) ores = Vector{Expr}(undef,length(gens.args)) i = 1 for ex in gens.args - ex isa Expr || error("Input is not a permutation expression") - res = _perm_helper(ex) - - ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) - i = i + 1 + if ex == :( () ) + ores[i] = esc(:(Oscar.cperm(symmetric_group($n)))) + i = i + 1 + else + ex isa Expr || error("Input is not a permutation expression") + res = _perm_helper(ex) + + ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) + i = i + 1 + end end return Expr(:vect,ores...) diff --git a/test/Groups/Permutations.jl b/test/Groups/Permutations.jl index f8914cbc4e00..7e77d04ade13 100644 --- a/test/Groups/Permutations.jl +++ b/test/Groups/Permutations.jl @@ -7,6 +7,8 @@ a=1;b=2;f=x->3*x + 2; p = @perm (a,f(a),b)(a+1,b*2) @test p == cperm([1,5,4,2]) + p = @perm () + @test p == cperm() @test_throws ErrorException @perm (-1, 1) @test_throws LoadError @eval @perm "bla"