diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index f85f282c0bb..f5a0475135e 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -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 @@ -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. = 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`):: @@ -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: @@ -3711,7 +3722,9 @@ def is_principal(self, certificate=False): sage: B. = 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 @@ -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):