Skip to content
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

Improve @perm macro #4490

Merged
merged 9 commits into from
Jan 29, 2025
Merged

Improve @perm macro #4490

merged 9 commits into from
Jan 29, 2025

Conversation

lgoettgens
Copy link
Member

@lgoettgens lgoettgens commented Jan 21, 2025

Resolves #3010.

  • @perm n+1 [....] works now; the docstring always stated it would, but some macro hygiene thing messed up the use of local variables inside the degree expression.
  • @perm G [(1,2,3,4)] creates a list of perms with fixed parent G.
  • [@perm (1,2), @perm(3,4)] and similar constructions (where julia infers weird scopes of things) now raise an explicit error.
  • Complete feature parity for different versions. There are now 9 combinations based on the parent group (detect parent / given group / given degree of symmetric group) and the expression (single permutation, non-empty vector, non-empty tuple). The only ambiguity would be with the empty tuple, so we explicitly restrict vectors and tuple to be non-empty.

The release notes could include a compressed version of this list.

@lgoettgens

This comment was marked as outdated.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 84.21053% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.54%. Comparing base (29c57c9) to head (48a6ddf).
Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
src/Groups/perm.jl 84.21% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4490      +/-   ##
==========================================
- Coverage   84.60%   84.54%   -0.06%     
==========================================
  Files         672      672              
  Lines       88742    88907     +165     
==========================================
+ Hits        75083    75170      +87     
- Misses      13659    13737      +78     
Files with missing lines Coverage Δ
src/Groups/perm.jl 96.00% <84.21%> (-2.85%) ⬇️

... and 16 files with indirect coverage changes

@lgoettgens lgoettgens force-pushed the lg/at-perm branch 2 times, most recently from b80f625 to 81f7fa9 Compare January 22, 2025 22:24
@lgoettgens lgoettgens added the release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes label Jan 22, 2025
@lgoettgens
Copy link
Member Author

@fingolfin this now includes everything we discussed this afternoon

@lgoettgens lgoettgens marked this pull request as ready for review January 22, 2025 22:41

ps = @perm [(1,2,3)(4,5), (6,2,3,1), (), (2,)(1,4)]
@test ps isa Vector{PermGroupElem}
@test allequal(parent, ps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allequal requires Julia >= 1.8 and we still run some of these tests in Julia 1.6.

Perhaps we should provide an allequal implementation for older Julia versions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this what Compat.jl is for? We already have it in the environment as a dependency of GAP.jl anyway. For the time being, I just import this one function in older julia versions.

(I don't understand why the 1.10 job succeeded, as the allequal dispatch with predicate was only added right before the 1.11 feature freeze)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't understand why the 1.10 job succeeded, as the allequal dispatch with predicate was only added right before the 1.11 feature freeze)

1.6 does not have allequal at all and fails, 1.10 does have it and since we load Compat.jl it adds that version to the existing function:

julia> allequal(
allequal(f, xs::Tuple) @ Compat ~/.julia/packages/Compat/gd6AI/src/Compat.jl:790
allequal(f, xs) @ Compat ~/.julia/packages/Compat/gd6AI/src/Compat.jl:789
allequal(r::AbstractRange) @ Base set.jl:537
allequal(c::Union{AbstractDict, AbstractSet}) @ Base set.jl:535
allequal(itr) @ Base set.jl:533

(this is julia 1.10 with Oscar master)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding me of JuliaLang/Compat.jl#814. This indeed resolves my confusion.

Copy link
Member

@fingolfin fingolfin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Some minor comments. Overall looks good.

src/Groups/perm.jl Outdated Show resolved Hide resolved

In the remaining case, the parent group is inferred to be the symmetric group
with a degree of the highest integer referenced in `expr`. This may result in
evalutating the expressions in the cycle entries multiple times, so it is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
evalutating the expressions in the cycle entries multiple times, so it is
evaluating the expressions in the cycle entries multiple times, so it is

OK for now, but we could avoid that, couldn't we? By storing the result of the evaluation immediately as vectors (of vectors), and then later e.g. passing those to cperm

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only avoid it for the case of a single permutation, and indeed the previous code did. I removed that for the time being to reduce Tha number of case distinctions.
For the vector and tuple cases, we cannot let the cperm dispatch handle the detection. Consider e.g. @perm [(1, 2), (3,4)]. if we would delegate that to cperm([1, 2]) and cperm([3,4]), then the parents would differ (Sym(2) vs. Sym(4).

I have some ideas on how to avoid the double evaluation, but I need to think a bit more about it and test if it regressed performance for the case of just ints in all entries. Thus, I would like to move that to a follow-up PR

@fingolfin fingolfin merged commit 0ba63b2 into oscar-system:master Jan 29, 2025
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: to be added PRs introducing changes that should be (but have not yet been) mentioned in the release notes topic: groups
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug / missing feature in @perm macro
3 participants