Skip to content

Commit 7c13ae9

Browse files
author
Release Manager
committed
gh-38963: Disallow scaling of quaternion fractional ideals by zero This PR disallows the scaling of quaternion fractional ideals by the zero element of the surrounding quaternion algebra (throwing a `ValueError` in the process), as the result will by definition not be a fractional ideal. It also adds additional checks to avoid scaling by zero in other tests, which came up in the issue mentioned below, and it adds a missing warning for a long doctest. Fixes #38947. URL: #38963 Reported by: Sebastian A. Spindler Reviewer(s): Giacomo Pope
2 parents c007973 + ae698fb commit 7c13ae9

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/sage/algebras/quatalg/quaternion_algebra.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,7 @@ def scale(self, alpha, left=False):
26092609
26102610
INPUT:
26112611
2612-
- `\alpha` -- element of quaternion algebra
2612+
- `\alpha` -- nonzero element of quaternion algebra
26132613
26142614
- ``left`` -- boolean (default: ``False``); if ``True`` multiply
26152615
`\alpha` on the left, otherwise multiply `\alpha` on the right
@@ -2632,6 +2632,15 @@ def scale(self, alpha, left=False):
26322632
sage: I.gens()[0] * i
26332633
4*i
26342634
2635+
The scaling element must be nonzero::
2636+
2637+
sage: B.<i,j,k> = QuaternionAlgebra(419)
2638+
sage: O = B.quaternion_order([1/2 + 3/2*j, 1/6*i + 2/3*j + 1/2*k, 3*j, k])
2639+
sage: O * O.zero()
2640+
Traceback (most recent call last):
2641+
...
2642+
ValueError: the scaling factor must be nonzero
2643+
26352644
TESTS:
26362645
26372646
Scaling by `1` should not change anything (see :issue:`32245`)::
@@ -2657,6 +2666,8 @@ def scale(self, alpha, left=False):
26572666
"""
26582667
Q = self.quaternion_algebra()
26592668
alpha = Q(alpha)
2669+
if alpha.is_zero():
2670+
raise ValueError("the scaling factor must be nonzero")
26602671
if left:
26612672
gens = basis_for_quaternion_lattice([alpha * b for b in self.basis()])
26622673
else:
@@ -3657,7 +3668,9 @@ def is_right_equivalent(self, J, B=10, certificate=False):
36573668
sage: B = QuaternionAlgebra(101)
36583669
sage: i,j,k = B.gens()
36593670
sage: I = B.maximal_order().unit_ideal()
3660-
sage: beta = B.random_element() # random
3671+
sage: beta = B.random_element()
3672+
sage: while beta.is_zero():
3673+
....: beta = B.random_element()
36613674
sage: J = beta*I
36623675
sage: bool, alpha = I.is_right_equivalent(J, certificate=True)
36633676
sage: bool
@@ -3711,7 +3724,9 @@ def is_principal(self, certificate=False):
37113724
37123725
sage: B.<i,j,k> = QuaternionAlgebra(419)
37133726
sage: O = B.quaternion_order([1/2 + 3/2*j, 1/6*i + 2/3*j + 1/2*k, 3*j, k])
3714-
sage: beta = O.random_element() # random
3727+
sage: beta = O.random_element()
3728+
sage: while beta.is_zero():
3729+
....: beta = O.random_element()
37153730
sage: I = O*beta
37163731
sage: bool, alpha = I.is_principal(True)
37173732
sage: bool
@@ -3951,7 +3966,7 @@ def primitive_decomposition(self):
39513966
39523967
Check that randomly generated ideals decompose as expected::
39533968
3954-
sage: for d in ( m for m in range(400, 750) if is_squarefree(m) ):
3969+
sage: for d in ( m for m in range(400, 750) if is_squarefree(m) ): # long time (7s)
39553970
....: A = QuaternionAlgebra(d)
39563971
....: O = A.maximal_order()
39573972
....: for _ in range(10):

0 commit comments

Comments
 (0)