From e1e17f3b61c2a5f05c32126cd5067218ef2200e4 Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Wed, 27 Jul 2022 15:54:31 +0800 Subject: [PATCH] code style tweaks --- src/sage/quadratic_forms/binary_qf.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sage/quadratic_forms/binary_qf.py b/src/sage/quadratic_forms/binary_qf.py index 3814a9abac5..682c9f10c61 100755 --- a/src/sage/quadratic_forms/binary_qf.py +++ b/src/sage/quadratic_forms/binary_qf.py @@ -213,15 +213,11 @@ def __mul__(self, right): # ...or a 2x2 matrix... if (isinstance(right.parent(), MatrixSpace) and right.nrows() == right.ncols() == 2): - aa = right[0, 0] - bb = right[0, 1] - cc = right[1, 0] - dd = right[1, 1] + aa,bb,cc,dd = right.list() A = self.polynomial()(aa, cc) C = self.polynomial()(bb, dd) B = self.polynomial()(aa + bb, cc + dd) - A - C - qf = BinaryQF(A, B, C) - return qf + return BinaryQF(A, B, C) raise TypeError("right operand must be a binary quadratic form or 2x2 matrix") def __getitem__(self, n): @@ -846,17 +842,18 @@ def reduced_form(self, transformation=False, algorithm="default"): """ if self.is_reduced(): if transformation: - return self, Matrix(ZZ, 2, 2, [1, 0, 0, 1]) - else: - return self + return self, Matrix.identity(2) + return self if algorithm == "default": algorithm = 'sage' if self.is_reducible() else 'pari' + if algorithm == 'sage': if self.discriminant() <= 0: raise NotImplementedError('reduction of definite binary ' 'quadratic forms is not implemented in Sage') return self._reduce_indef(transformation) + elif algorithm == 'pari': # Negative definite forms are not supported by PARI. We can # work around this by reducing [-a,b,-c] instead of [a,b,c]. @@ -866,13 +863,16 @@ def reduced_form(self, transformation=False, algorithm="default"): if transformation: return (-r[0]*M, M*r[1]*M) return -r*M + + if self.is_reducible(): + raise NotImplementedError('reducible forms are not ' + 'supported using PARI') + if transformation: y,g = self.__pari__().qfbredsl2() return BinaryQF(y), Matrix(ZZ, g) - elif self.is_reducible(): - raise NotImplementedError('reducible forms are not ' - 'supported using PARI') return BinaryQF(self.__pari__().qfbred()) + else: raise ValueError('unknown implementation for binary quadratic form ' 'reduction: %s' % algorithm)