-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Macro for entering permutations in cycle notation #1307
Macro for entering permutations in cycle notation #1307
Conversation
Would be good if there were some tests with invalid input, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!! Great work. Still some changes would be good
I also added a check for
But than an error occurs for cperm
Is this intended? |
src/Groups/perm.jl
Outdated
ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) | ||
i = i + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just let ores
start out as an empty vector and then do push!(ores, ...)
, then you don't need i
.
src/Groups/perm.jl
Outdated
|
||
pushfirst!(res, Expr(:vect,ex.args...)) | ||
|
||
ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This calls symmetric_group
again and again, which isn't great, as we create a new group object each time. This could be improved by using let
block; but I don't want to complicate things even further, so I suggest we first iron out everything else and get this merged, then we can worry about fine tuning.
Just for the record, here is what I'd do: I'd only collect the res
values here:
ores[i] = esc(:(Oscar.cperm(symmetric_group($n),$(res...)))) | |
ores[i] = esc(:( [$(res...)] )) |
Then, the final return
of this macro could look something like this:
return quote
let g = symmetric_group($n)
[ cperm(g, pi) for pi in [$(ores...)] ]
end
end
Note: normally we'd have to worry that g
and pi
could clash with symbols defined by the programmer in the surrounding code, and referenced in the permutation expression. This is where the esc
function comes into play: we applied it to the expressions we got from the user, but not to the outer expression above. This leads to the Julia macro hygiene functionality kicking in, which determines that g
and pi
(unlike symmetric_group
and cperm
) are not known variables, and replaces them by special generated names. You can check the effect of this via macroexpand
:
julia> g = 7 # introduce a variable g and use it in the macro expression:
7
julia> macroexpand(Main, :( Oscar.@perm 14 [
(g,9)
(1,2)(10,11)
]))
quote
let var"#332#g" = Oscar.symmetric_group(14)
[Oscar.cperm(var"#332#g", var"#333#pi"...) for var"#333#pi" = [[[g, 9]], [[1, 2], [10, 11]]]]
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Resolves oscar-system/GAP.jl#420
Resolves #1189