Skip to content

Commit 6dcfb72

Browse files
[ fix #1476 ] improve performance of rational numbers (#1478)
1 parent 2ebfb28 commit 6dcfb72

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ Highlights
1414

1515
* Pseudo random generators for ℕ (available from `Data.Nat.Pseudorandom.LCG`)
1616

17+
* Large increase in the number of proofs about both normalised and unnormalised rational numbers.
18+
19+
* Drastically increased performance of normalised rational numbers.
20+
1721
Bug-fixes
1822
---------
1923

2024
* The sum operator `_⊎_` in `Data.Container.Indexed.Combinator` was not as universe
2125
polymorphic as it should have been. This has been fixed. The old, less universe
2226
polymorphic variant is still available under the new name `_⊎′_`.
27+
28+
* The performance of the `gcd` operator over naturals and hence all operations in
29+
`Data.Rational.Base` has been drastically increased by using the new `<-wellFounded-fast`
30+
operation in `Data.Nat.Induction`.
2331

2432
* The proof `isEquivalence` in `Function.Properties.(Equivalence/Inverse)` used to be
2533
defined in an anonymous module that took two unneccessary `Setoid` arguments:

src/Data/Digit.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Bit = Digit 2
5151

5252
toNatDigits : (base : ℕ) {base≤16 : True (1 ≤? base)} List ℕ
5353
toNatDigits base@(suc zero) n = replicate n 1
54-
toNatDigits base@(suc (suc b)) n = aux (<-wellFounded n) []
54+
toNatDigits base@(suc (suc b)) n = aux (<-wellFounded-fast n) []
5555
where
5656
aux : {n : ℕ} Acc _<_ n List ℕ List ℕ
5757
aux {zero} _ xs = (0 ∷ xs)

src/Data/Nat/GCD.agda

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open import Data.Nat.DivMod
1414
open import Data.Nat.GCD.Lemmas
1515
open import Data.Nat.Properties
1616
open import Data.Nat.Induction
17-
using (Acc; acc; <′-Rec; <′-recBuilder; <-wellFounded)
17+
using (Acc; acc; <′-Rec; <′-recBuilder; <-wellFounded-fast)
1818
open import Data.Product
1919
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
2020
open import Function
@@ -43,9 +43,9 @@ gcd′ m n@(suc n-1) (acc rec) n<m = gcd′ n (m % n) (rec _ n<m) (m%n<n m n-1)
4343

4444
gcd :
4545
gcd m n with <-cmp m n
46-
... | tri< m<n _ _ = gcd′ n m (<-wellFounded n) m<n
46+
... | tri< m<n _ _ = gcd′ n m (<-wellFounded-fast n) m<n
4747
... | tri≈ _ _ _ = m
48-
... | tri> _ _ n<m = gcd′ m n (<-wellFounded m) n<m
48+
... | tri> _ _ n<m = gcd′ m n (<-wellFounded-fast m) n<m
4949

5050
------------------------------------------------------------------------
5151
-- Core properties of gcd′

0 commit comments

Comments
 (0)