# HG changeset patch
# User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
# Date 1369939497 -7200
# Node ID ab4a0ad7b817b20a5ec40af45489d5d89ea2b476
# Parent f8a5df7397e8d17d57640dbb6c4c379edfa402b9
trac 13256 review patch with links to trac
diff --git a/sage/rings/number_field/number_field_element_quadratic.pyx b/sage/rings/number_field/number_field_element_quadratic.pyx
a
|
b
|
AUTHORS: |
9 | 9 | - Robert Bradshaw (2007-09): Initial version |
10 | 10 | - David Harvey (2007-10): fix up a few bugs, polish around the edges |
11 | 11 | - David Loeffler (2009-05): add more documentation and tests |
12 | | - Vincent Delecroix (2012-07): comparisons for quadratic number fields (#13213), |
13 | | abs, floor and ceil functions (#13256) |
| 12 | - Vincent Delecroix (2012-07): comparisons for quadratic number fields |
| 13 | (:trac:`13213`), abs, floor and ceil functions (:trac:`13256`) |
14 | 14 | |
15 | | TODO: |
| 15 | .. TODO:: |
16 | 16 | |
17 | 17 | The ``_new()`` method should be overridden in this class to copy the ``D`` |
18 | 18 | and ``standard_embedding`` attributes |
… |
… |
def __make_NumberFieldElement_quadratic1 |
78 | 78 | sage: loads(dumps(a)) == a # indirect doctest |
79 | 79 | True |
80 | 80 | |
81 | | We test that #6462 is fixed:: |
| 81 | We test that :trac:`6462` is fixed:: |
82 | 82 | |
83 | 83 | sage: L = QuadraticField(-11,'a'); OL = L.maximal_order(); w = OL.0 |
84 | 84 | sage: loads(dumps(w)) == w # indirect doctest |
… |
… |
cdef class NumberFieldElement_quadratic( |
202 | 202 | self._ntl_coeff_as_mpz(&self.a, 0) |
203 | 203 | self._ntl_coeff_as_mpz(&self.b, 1) |
204 | 204 | if mpz_cmp_ui(self.a, 0) or mpz_cmp_ui(self.b, 0): |
205 | | gen = parent.gen() # should this be cached? |
| 205 | gen = parent.gen() # should this be cached? |
206 | 206 | self._ntl_denom_as_mpz(&self.denom) |
207 | 207 | if mpz_cmp_ui(self.b, 0): |
208 | 208 | mpz_mul(self.a, self.a, gen.denom) |
… |
… |
cdef class NumberFieldElement_quadratic( |
227 | 227 | pass |
228 | 228 | else: |
229 | 229 | raise ValueError("A parent of NumberFieldElement_quadratic with " |
230 | | "a canonical embedding should have an attribute " |
231 | | "_standard_embedding (used for comparisons of elements)") |
| 230 | "a canonical embedding should have an attribute " |
| 231 | "_standard_embedding (used for comparisons of elements)") |
232 | 232 | |
233 | 233 | cdef _new(self): |
234 | 234 | """ |
… |
… |
cdef class NumberFieldElement_quadratic( |
426 | 426 | if check: |
427 | 427 | if not isinstance(self.number_field(), number_field.NumberField_cyclotomic) \ |
428 | 428 | or not isinstance(new_parent, number_field.NumberField_cyclotomic): |
429 | | raise TypeError, "The field and the new parent field must both be cyclotomic fields." |
| 429 | raise TypeError("The field and the new parent field must both be cyclotomic fields.") |
430 | 430 | |
431 | 431 | if rel == 0: |
432 | 432 | small_order = self.number_field()._n() |
… |
… |
cdef class NumberFieldElement_quadratic( |
435 | 435 | try: |
436 | 436 | rel = ZZ(large_order / small_order) |
437 | 437 | except TypeError: |
438 | | raise TypeError, "The zeta_order of the new field must be a multiple of the zeta_order of the original." |
| 438 | raise TypeError("The zeta_order of the new field must be a multiple of the zeta_order of the original.") |
439 | 439 | |
440 | 440 | cdef NumberFieldElement_quadratic x2 |
441 | 441 | cdef int n = self._parent._n() |
… |
… |
cdef class NumberFieldElement_quadratic( |
731 | 731 | |
732 | 732 | The following is tested because of the implementation of |
733 | 733 | func:`Q_to_quadratic_field_element` which was the cause of some problems |
734 | | with #13213:: |
| 734 | with :trac:`13213`:: |
735 | 735 | |
736 | 736 | sage: K.<sqrt2> = QuadraticField(2,name='sqrt2') |
737 | 737 | sage: 1/2 + sqrt2 > 0 |
… |
… |
cdef class NumberFieldElement_quadratic( |
1179 | 1179 | sage: (3*a-2)/7 * b |
1180 | 1180 | 1 |
1181 | 1181 | |
1182 | | This fixes ticket #9357:: |
| 1182 | This fixes ticket :trac:`9357`:: |
1183 | 1183 | |
1184 | 1184 | sage: K.<a> = NumberField(x^2+1) |
1185 | 1185 | sage: d = K(0) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1279 | 1279 | """ |
1280 | 1280 | cdef Integer res |
1281 | 1281 | if mpz_cmp_ui(self.b, 0) != 0 or mpz_cmp_ui(self.denom, 1) != 0: |
1282 | | raise TypeError, "Unable to coerce %s to an integer"%self |
| 1282 | raise TypeError("Unable to coerce %s to an integer" % self) |
1283 | 1283 | else: |
1284 | 1284 | res = PY_NEW(Integer) |
1285 | 1285 | mpz_set(res.value, self.a) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1299 | 1299 | """ |
1300 | 1300 | cdef Rational res |
1301 | 1301 | if mpz_cmp_ui(self.b, 0)!=0: |
1302 | | raise TypeError, "Unable to coerce %s to a rational"%self |
| 1302 | raise TypeError("Unable to coerce %s to a rational" % self) |
1303 | 1303 | else: |
1304 | 1304 | res = <Rational>PY_NEW(Rational) |
1305 | 1305 | mpz_set(mpq_numref(res.value), self.a) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1333 | 1333 | """ |
1334 | 1334 | cdef Rational res |
1335 | 1335 | if mpz_sgn(self.D.value) > 0: |
1336 | | return self # totally real |
| 1336 | return self # totally real |
1337 | 1337 | else: |
1338 | 1338 | res = <Rational>PY_NEW(Rational) |
1339 | 1339 | mpz_set(mpq_numref(res.value), self.a) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1379 | 1379 | |
1380 | 1380 | """ |
1381 | 1381 | if mpz_sgn(self.D.value) > 0: |
1382 | | return PY_NEW(Rational) # = 0 |
| 1382 | return PY_NEW(Rational) # = 0 |
1383 | 1383 | embedding = self._parent.coerce_embedding() |
1384 | 1384 | cdef Integer negD = -self.D |
1385 | 1385 | cdef NumberFieldElement_quadratic q = <NumberFieldElement_quadratic>self._new() |
… |
… |
cdef class NumberFieldElement_quadratic( |
1390 | 1390 | if mpz_cmp_ui(negD.value, 1) == 0 or negD.is_square(): |
1391 | 1391 | # D = -1 is the most common case we'll see here |
1392 | 1392 | if embedding is None: |
1393 | | raise ValueError, "Embedding must be specified." |
| 1393 | raise ValueError("Embedding must be specified.") |
1394 | 1394 | res = <Rational>PY_NEW(Rational) |
1395 | 1395 | if mpz_cmp_ui(negD.value, 1) == 0: |
1396 | 1396 | mpz_set(mpq_numref(res.value), self.b) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1433 | 1433 | [1/5, 3] |
1434 | 1434 | """ |
1435 | 1435 | # In terms of the generator... |
1436 | | cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached? |
| 1436 | cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached? |
1437 | 1437 | cdef Rational const = <Rational>PY_NEW(Rational), lin = <Rational>PY_NEW(Rational) |
1438 | 1438 | ad, bd = self.parts() |
1439 | 1439 | if not self: |
… |
… |
cdef class NumberFieldElement_quadratic( |
1476 | 1476 | True |
1477 | 1477 | """ |
1478 | 1478 | # In terms of the generator... |
1479 | | cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached? |
| 1479 | cdef NumberFieldElement_quadratic gen = self.number_field().gen() # should this be cached? |
1480 | 1480 | cdef Integer denom |
1481 | 1481 | if gen.is_sqrt_disc(): |
1482 | 1482 | denom = PY_NEW(Integer) |
… |
… |
cdef class NumberFieldElement_quadratic( |
1596 | 1596 | if K is None or K == QQ: |
1597 | 1597 | # norm = (a^2 - d b^2) / self.denom^2 |
1598 | 1598 | mpz_pow_ui(mpq_numref(res.value), self.a, 2) |
1599 | | mpz_pow_ui(mpq_denref(res.value), self.b, 2) # use as temp |
| 1599 | mpz_pow_ui(mpq_denref(res.value), self.b, 2) # use as temp |
1600 | 1600 | mpz_mul(mpq_denref(res.value), mpq_denref(res.value), self.D.value) |
1601 | 1601 | mpz_sub(mpq_numref(res.value), mpq_numref(res.value), mpq_denref(res.value)) |
1602 | 1602 | mpz_pow_ui(mpq_denref(res.value), self.denom, 2) |