A division-free determinant algorithm #
This file defines birdDetand Spec.birdDet, implementations of an
division-free algorithm for computing determinants. The algorithm runs in O(n^4)
for an n-by-n matrix.
This determinant algorithm comes from Richard S. Bird, A simple division-free algorithm for computing determinants.
Main definitions #
BirdDet.birdDet: The entrypoint for the determinant calculation.BirdDet.get: matrix entry lookup.BirdDet.sumFrom: The sumf lo + ... + f (n - 1).BirdDet.stepEntry: One scalar recurrence step.BirdDet.Spec.birdDet: An implementation of Bird's algorithm usingMatrix.
Main lemmas #
The lemmas in this file are unfolding equations.
Sum f lo + ... + f (n - 1). Returns zero when n <= lo.
Equations
- BirdDet.sumFrom n lo f = if lo < n then f lo + BirdDet.sumFrom n (lo + 1) f else 0
Instances For
One entry of one scalar Bird recurrence step.
Bird's paper defines a matrix recursion for an n × n matrix A:
F_0 = A
F_{t+1} = μ(F_t) * A
where μ(F_t) is obtained from F_t by replacing each diagonal entry
F_t k k with the negative sum of the diagonal entries below it, setting the
entries in the lower triangular part to 0, and leaving all other entries
unchanged:
μ(F_t) =
0 if i >= j
- ∑ k from i+1 to n-1, F_t k k if i = j
F_t i j if i < j
If we write out the entry-wise matrix multiplication F_{t+1} i j = (μ(F_t) * A) i j
we obtain:
F_{t+1} i j =
- (∑ k from i+1 to n-1, F_t k k) * (A i j)
+ ∑ k from i+1 to n-1, (F_t i k) * (A k j)
Equations
- BirdDet.stepEntry n A F i j = (-BirdDet.sumFrom n (i + 1) fun (k : ℕ) => F k k) * BirdDet.get n A i j + BirdDet.sumFrom n (i + 1) fun (k : ℕ) => F i k * BirdDet.get n A k j
Instances For
birdDet n A computes the determinant of the n × n matrix whose entries are
stored in A in row-major order.
Equations
- BirdDet.birdDet 0 A = 1
- BirdDet.birdDet k.succ A = (-1) ^ k * (BirdDet.stepEntry k.succ A)^[k] (BirdDet.get k.succ A) 0 0
Instances For
Unfold one scalar Bird recurrence step to the entry-wise formula.
A version of the Bird determinant algorithm that is stated in terms of Matrix.
Equations
- BirdDet.Spec.birdDet A_2 = 1
- BirdDet.Spec.birdDet A_2 = (-1) ^ k * (BirdDet.Spec.stepEntry A_2)^[k] A_2 0 0