Skip to content

Commit

Permalink
Disallow scaling fractional ideals by zero
Browse files Browse the repository at this point in the history
Plus added warning for a long doctest
  • Loading branch information
S17A05 committed Nov 13, 2024
1 parent 209ae4c commit c8927d9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/sage/algebras/quatalg/quaternion_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ def scale(self, alpha, left=False):
INPUT:
- `\alpha` -- element of quaternion algebra
- `\alpha` -- nonzero element of quaternion algebra
- ``left`` -- boolean (default: ``False``); if ``True`` multiply
`\alpha` on the left, otherwise multiply `\alpha` on the right
Expand All @@ -2632,6 +2632,15 @@ def scale(self, alpha, left=False):
sage: I.gens()[0] * i
4*i
The scaling element must be nonzero::
sage: B.<i,j,k> = QuaternionAlgebra(419)
sage: O = B.quaternion_order([1/2 + 3/2*j, 1/6*i + 2/3*j + 1/2*k, 3*j, k])
sage: O * O.zero()
Traceback (most recent call last):
...
ValueError: the scaling factor must be nonzero
TESTS:
Scaling by `1` should not change anything (see :issue:`32245`)::
Expand All @@ -2657,6 +2666,8 @@ def scale(self, alpha, left=False):
"""
Q = self.quaternion_algebra()
alpha = Q(alpha)
if alpha.is_zero():
raise ValueError("the scaling factor must be nonzero")
if left:
gens = basis_for_quaternion_lattice([alpha * b for b in self.basis()])
else:
Expand Down Expand Up @@ -3711,7 +3722,9 @@ def is_principal(self, certificate=False):
sage: B.<i,j,k> = QuaternionAlgebra(419)
sage: O = B.quaternion_order([1/2 + 3/2*j, 1/6*i + 2/3*j + 1/2*k, 3*j, k])
sage: beta = O.random_element() # random
sage: beta = O.random_element()
sage: while beta.is_zero():
....: beta = O.random_element()
sage: I = O*beta
sage: bool, alpha = I.is_principal(True)
sage: bool
Expand Down Expand Up @@ -3951,7 +3964,7 @@ def primitive_decomposition(self):
Check that randomly generated ideals decompose as expected::
sage: for d in ( m for m in range(400, 750) if is_squarefree(m) ):
sage: for d in ( m for m in range(400, 750) if is_squarefree(m) ): # long time (7s)
....: A = QuaternionAlgebra(d)
....: O = A.maximal_order()
....: for _ in range(10):
Expand Down

0 comments on commit c8927d9

Please sign in to comment.