Skip to content

Fix raising matrix group elements to negative powers#5594

Merged
fingolfin merged 1 commit intooscar-system:masterfrom
ThomasBreuer:TB_pow_mat
Nov 26, 2025
Merged

Fix raising matrix group elements to negative powers#5594
fingolfin merged 1 commit intooscar-system:masterfrom
ThomasBreuer:TB_pow_mat

Conversation

@ThomasBreuer
Copy link
Copy Markdown
Member

@ThomasBreuer ThomasBreuer commented Nov 26, 2025

If the underlying matrix is a ZZMatrix then negative exponents are not allowed.

(addresses a problem mentioned in #5550)

Note that the situation is a bit tricky:

julia> G = GL(2, ZZ);

julia> x = gen(G, 1);

julia> x^-1;  # this worked already before this pull request

julia> n = -1;

julia> x^n;
ERROR: DomainError with -1:
Exponent must be non-negative
Stacktrace:
 [1] ^(x::ZZMatrix, y::Int64)
   @ Nemo ~/.julia/packages/Nemo/kdloy/src/flint/fmpz_mat.jl:325
 [2] ^(x::MatrixGroupElem{ZZRingElem, ZZMatrix}, n::Int64)
   @ Oscar ~/.julia/packages/Oscar/S0B41/src/Groups/matrices/MatGrp.jl:437
 [3] top-level scope
   @ REPL[6]:1

The reason for that is some literal_pow magic from AbstractAlgebra.

julia> @which x^n
^(x::MatrixGroupElem, n::Int64)
     @ Oscar ~/.julia/packages/Oscar/S0B41/src/Groups/matrices/MatGrp.jl:437

julia> @which x^-1
literal_pow(::typeof(^), g::GroupElem, ::Val{-1})
     @ AbstractAlgebra ~/.julia/packages/AbstractAlgebra/L8iQ0/src/Groups.jl:228

We might do the same for ZZMatrix.

If the underlying matrix is a `ZZMatrix` then negative exponents
are not allowed.
@ThomasBreuer ThomasBreuer added release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes bug Something isn't working topic: groups bug: unexpected error labels Nov 26, 2025
@fingolfin
Copy link
Copy Markdown
Member

This literal_pow magic is something Julia does in general...

@fingolfin fingolfin changed the title fix powering of matrix group elements Fix raisin matrix group elements to negative powers Nov 26, 2025
@fingolfin fingolfin changed the title Fix raisin matrix group elements to negative powers Fix raising matrix group elements to negative powers Nov 26, 2025
@fingolfin fingolfin added release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes and removed release notes: not needed PRs introducing changes that are wholly irrelevant to the release notes labels Nov 26, 2025
@fingolfin fingolfin enabled auto-merge (squash) November 26, 2025 13:00
@fingolfin fingolfin merged commit ed28a4c into oscar-system:master Nov 26, 2025
44 of 47 checks passed
@ThomasBreuer ThomasBreuer deleted the TB_pow_mat branch November 26, 2025 14:09
@thofma
Copy link
Copy Markdown
Collaborator

thofma commented Nov 26, 2025

Would fixing powering for ZZMatrix also be an option?

@ThomasBreuer
Copy link
Copy Markdown
Member Author

Would fixing powering for ZZMatrix also be an option?

It is not clear for me that "fixing" is the right term, my understanding was that the DomainError is intentional.

If we want to change this then this is fine.

(The change belongs to Nemo.jl.
Also the literal_pow magic for exponent -1 could then be added there.)

@thofma
Copy link
Copy Markdown
Collaborator

thofma commented Nov 26, 2025

Hm, since we don't error here:

julia> ZZ(-1)^-2
1

I think we should also not error in the matrix case. I'll adjust it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug: unexpected error bug Something isn't working release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: groups

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants