Opened 7 years ago

Closed 6 years ago

#13256 closed enhancement (fixed)

abs floor ceil for quadratic number field

Reported by: vdelecroix Owned by: vdelecroix
Priority: major Milestone: sage-5.11
Component: number fields Keywords: absolute value, floor, ceiling, number field, quadratic
Cc: mhansen, berocal Merged in: sage-5.11.beta0
Authors: Vincent Delecroix Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #13213 Stopgaps:

Description (last modified by vdelecroix)

Implementation of absolute value (abs), floor (floor) and ceiling (ceil) function for elements in quadratic number field.

The implementation uses only manipulation of (mpz) integers.

The function abs depends on the function sign implemented in ticket #13213.

Attachments (2)

trac_13256-abs_floor_ceil_in_quadratic_fields.patch (5.7 KB) - added by vdelecroix 6 years ago.
trac_13256_details-review.patch (7.5 KB) - added by chapoton 6 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by vdelecroix

  • Description modified (diff)
  • Status changed from new to needs_review

comment:2 follow-up: Changed 6 years ago by kcrisman

Does the removal of

K.<a> = NumberField(x^2+1, embedding=CDF.gen()) 

as an example mean that one couldn't use this syntax at all any more? Would number fields from quadratics not automatically be quadratic fields (when mathematically appropriate, I'm excluding x^2-1 and the like) and inherit these methods, or would that simply not work now?

comment:3 in reply to: ↑ 2 Changed 6 years ago by vdelecroix

Replying to kcrisman:

Does the removal of

K.<a> = NumberField(x^2+1, embedding=CDF.gen()) 

as an example mean that one couldn't use this syntax at all any more?

This syntax is still available. The patch only aims to implement methods abs, floor and ceil for quadratic elements. As an example

sage: K.<sqrt2> = QuadraticField(2)
sage: sqrt2.floor()
1

It is yet possible (without the patch) to do

sage: K.<sqrt2> = QuadraticField(2)
sage: floor(sqrt2)
1

But there is a simpler and faster way to do it compared to what floor does (using the real interval field with finer and finer approximations). Note that if the method .floor is present, the the function floor will use it!

Would number fields from quadratics not automatically be quadratic fields (when mathematically appropriate, I'm excluding x^2-1 and the like) and inherit these methods, or would that simply not work now?

Yes, it is the way it is

sage: type(NumberField(x^2 + 1, 'a'))
<class 'sage.rings.number_field.number_field.NumberField_quadratic_with_category'>

comment:4 Changed 6 years ago by vdelecroix

  • Dependencies changed from #7160, #13213 to #13213
  • Description modified (diff)

comment:5 Changed 6 years ago by vdelecroix

The patch now takes care of the new doctest framework (ie replace "..." by "....:" for multiline tests).

comment:6 Changed 6 years ago by chapoton

I have made a short review patch, with correct links to trac and raise statements.

Changed 6 years ago by chapoton

comment:7 follow-up: Changed 6 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

ok, looks good to me. Positive review.

comment:8 in reply to: ↑ 7 Changed 6 years ago by vdelecroix

Replying to chapoton:

ok, looks good to me. Positive review.

Cool. Thanks Frédéric.

comment:9 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.10 to sage-5.11

comment:10 Changed 6 years ago by jdemeyer

  • Merged in set to sage-5.11.beta0
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.