Ticket #1141 (closed enhancement: fixed)
[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: | Work issues: | ||
| Report Upstream: | Reviewers: | ||
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
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
Change History
Changed 6 years ago by jbmohler
-
attachment
nf_poly_pointer.hg
added
comment:1 Changed 6 years ago by jbmohler
- Summary changed from Number Field elements arithmetic speed to [with patch] Number Field elements arithmetic speed
comment:4 Changed 5 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.

the patch!