Ticket #1141 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

[with patch, with positive review] Number Field elements arithmetic speed

Reported by: jbmohler Owned by: somebody
Priority: major Milestone: sage-2.8.15
Component: basic arithmetic Keywords:
Cc: Author(s):
Report Upstream: Reviewer(s):
Merged in: Work issues:

Description

This patch just makes a few minor adjustments which gain a bit of speed with number field elements. It's barely worth talking about for absolute fields, but its quite nice for relative number fields.

The main work of the patch is to place a pointer to the defining polynomial into the number field element. This possibly introduces more maintenance, but the alternative is to move the number field parent class to cython.

original:

sage: L.<a> = CyclotomicField(3).extension(x^3 - 2)
sage: timeit a^6
100 loops, best of 3: 2.89 ms per loop
sage: K.<a> = NumberField(x^3-2*x^2+12)
sage: timeit a^4
10000 loops, best of 3: 44.3 µs per loop
sage: O.<a,b> = EquationOrder([x^2+1, x^2+2])
sage: timeit a*b
1000 loops, best of 3: 770 µs per loop

patched:

sage: L.<a> = CyclotomicField(3).extension(x^3 - 2)
sage: timeit a^6
10000 loops, best of 3: 92.7 µs per loop
sage: K.<a> = NumberField(x^3-2*x^2+12)
sage: timeit a^4
10000 loops, best of 3: 30.6 µs per loop
sage: O.<a,b> = EquationOrder([x^2+1, x^2+2])
sage: timeit a*b
100000 loops, best of 3: 19 µs per loop

Attachments

nf_poly_pointer.hg Download (2.1 KB) - added by jbmohler 2 years ago.
the patch!

Change History

Changed 2 years ago by jbmohler

the patch!

Changed 2 years ago by jbmohler

  • summary changed from Number Field elements arithmetic speed to [with patch] Number Field elements arithmetic speed

Changed 2 years ago by jbmohler

  • type changed from defect to enhancement

Changed 2 years ago by jbmohler

  • milestone changed from sage-2.9 to sage-2.8.13

Changed 2 years ago by cwitty

  • summary changed from [with patch] Number Field elements arithmetic speed to [with patch, with positive review] Number Field elements arithmetic speed

I applied the patch, verified the promised performance improvements, and checked that doctests in sage/rings/numberfield/* still pass.

I do think that moving the number field parent class to cython may be a better strategy long-term, if only to avoid the extra memory footprint of two more pointers per number field element (although that's probably a silly thing to worry about, given how big number field elements are anyway). But regardless, this patch should be applied for now.

I approve.

Changed 2 years ago by mabshoff

Merged in 2.8.15.alpha0

Changed 2 years ago by mabshoff

Merged in 2.8.15.alpha0

Changed 2 years ago by mabshoff

  • status changed from new to closed
  • resolution set to fixed

Merged in 2.8.15.alpha0 - 3rd time's the charm!

Note: See TracTickets for help on using tickets.