# Ticket #1141(closed enhancement: fixed)

Opened 6 years ago

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

Reported by: Owned by: jbmohler somebody major sage-2.8.15 basic arithmetic

### 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
```

## Change History

the patch!

### 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:2 Changed 6 years ago by jbmohler

• Type changed from defect to enhancement

### comment:3 Changed 6 years ago by jbmohler

• Milestone changed from sage-2.9 to sage-2.8.13

### 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.

### comment:5 Changed 5 years ago by mabshoff

Merged in 2.8.15.alpha0

### comment:6 Changed 5 years ago by mabshoff

Merged in 2.8.15.alpha0

### comment:7 Changed 5 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.