Documentation

Complexity.Computability.Circuit.Rational.Runtime.Determinant

A list program for the staged integer determinant #

Rational.DeterminantAlgorithm.determinant runs the stages of Bird's division-free determinant on dense tables whose dimension is part of the type. This file restates the same staged algorithm as an ordinary program on lists of rows, Rational.detRows, whose dimension is the number of rows, and certifies that it is computable in polynomial time on multi-tape Turing machines over framed lists of binary sign-magnitude integers (Rational.detRows_polytime). Missing entries read as 0 and extra entries are ignored.

It also bounds the size of every value the program computes. For a d × d input whose entries have absolute value below 2 ^ b, every entry of the k-th stage, and every partial sum and product computed while producing it, has absolute value below 2 ^ (b + k * (1 + d + b)). The bounds are also stated for the bit length Rational.intBits of a sign-magnitude binary encoding, and, following the original development, for the stages of the dense tables.

Main definitions #

Main results #

References #

Bounds on the dense table stages #

theorem Cslib.Circuits.Rational.DeterminantAlgorithm.step_bound {n : ℕ} (A F : Matrix (Fin n) (Fin n) ℤ) (B C : ℕ) (hA : ∀ (i j : Fin n), |A i j| ≤ ↑B) (hF : ∀ (i j : Fin n), |F i j| ≤ ↑C) (i j : Fin n) :
|BirdDet.Spec.stepEntry A F i j| ≤ ↑(2 * n * B * C)

One Bird stage multiplies entry bounds by at most twice the dimension.

theorem Cslib.Circuits.Rational.DeterminantAlgorithm.stages_bound {n : ℕ} (A : Table n) (B : ℕ) (hA : ∀ (i j : Fin n), |denote A i j| ≤ ↑B) (k : ℕ) (i j : Fin n) :
|denote (stages A k) i j| ≤ ↑(B * (2 * n * B) ^ k)

Every stored table entry has only linearly many multiplicative growth stages.

theorem Cslib.Circuits.Rational.DeterminantAlgorithm.stages_power_bound {n : ℕ} (A : Table n) (b : ℕ) (hA : ∀ (i j : Fin n), |denote A i j| ≤ 2 ^ b) (k : ℕ) (i j : Fin n) :
|denote (stages A k) i j| ≤ 2 ^ (b + k * (1 + n + b))

Binary exponent bound for all stored intermediate tables, including singular inputs.

The list program #

Entry (i, j) of a matrix stored as a list of rows; missing entries read as 0.

Instances For

    The d × d list of rows whose entry (i, j) is g i j.

    Instances For

      The list of rows of a square matrix.

      Instances For

        The square matrix denoted by a list of rows: its dimension is the number of rows, missing entries are 0 and extra entries are ignored.

        Instances For

          Pad or truncate every row to the number of rows.

          Instances For

            The diagonal entries F k k for i < k < d, summed in one Bird stage; d is the number of rows of A.

            Instances For

              The products F i k * A k j for i < k < d, summed in one Bird stage; d is the number of rows of A.

              Instances For

                Entry (i, j) of one Bird stage, BirdDet.Spec.stepEntry, on lists of rows.

                Instances For

                  One Bird stage on lists of rows.

                  Instances For

                    The k-th Bird stage, starting from the squared input.

                    Instances For

                      The staged division-free determinant of a list of rows, including dimension zero.

                      Instances For

                        The bit length of an integer in a sign-magnitude binary encoding: one sign bit followed by the binary digits of the absolute value.

                        Instances For

                          intBits z is the length of the binary sign-magnitude code of z.

                          Basic lemmas #

                          theorem Cslib.Circuits.Rational.rowEntry_tabulateRows (d : ℕ) (g : ℕ → ℕ → ℤ) (i j : ℕ) :
                          rowEntry (tabulateRows d g) i j = if i < d ∧ j < d then g i j else 0
                          @[simp]
                          theorem Cslib.Circuits.Rational.rowEntry_rowsOf {d : ℕ} (A : Matrix (Fin d) (Fin d) ℤ) (i j : Fin d) :
                          rowEntry (rowsOf A) ↑i ↑j = A i j

                          A tail of a range, summed as a list, is a tail sum over Fin.

                          theorem Cslib.Circuits.Rational.sum_map_drop_range_fin {d : ℕ} (i : Fin d) (f : ℕ → ℤ) :
                          (List.map f (List.drop (↑i + 1) (List.range d))).sum = ∑ k > i, f ↑k

                          Correctness #

                          The list stages agree with the Bird stages of the matrix denoted by the input.

                          On any list of rows, detRows is the determinant of the square matrix it denotes, of dimension the number of rows.

                          theorem Cslib.Circuits.Rational.detRows_eq_det_of_rowEntry {d : ℕ} {rows : List (List ℤ)} (A : Matrix (Fin d) (Fin d) ℤ) (hd : rows.length = d) (hA : ∀ (i j : Fin d), rowEntry rows ↑i ↑j = A i j) :
                          detRows rows = A.det

                          detRows computes the determinant of every list of rows that agrees with a square matrix of its length.

                          The list program computes the determinant.

                          The list program agrees with the staged determinant on dense tables.

                          Size bounds #

                          theorem Cslib.Circuits.Rational.natAbs_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) :
                          theorem Cslib.Circuits.Rational.natAbs_take_sum_le {l : List ℤ} {C : ℕ} (h : ∀ x ∈ l, x.natAbs ≤ C) (m : ℕ) :

                          Every prefix sum of a list is bounded by its length times a bound on its entries.

                          theorem Cslib.Circuits.Rational.natAbs_take_sum_le_of_length {l : List ℤ} {C m : ℕ} (hl : l.length ≤ m) (h : ∀ x ∈ l, x.natAbs ≤ C) (k : ℕ) :

                          Every prefix sum and the sum of a list of terms bounded by C are bounded by m * C, where m bounds the length.

                          theorem Cslib.Circuits.Rational.natAbs_rowEntry_lt {rows : List (List ℤ)} {b : ℕ} (h : ∀ row ∈ rows, ∀ z ∈ row, z.natAbs < 2 ^ b) (i j : ℕ) :
                          (rowEntry rows i j).natAbs < 2 ^ b

                          Entry bounds hold for every entry index once they hold for every stored entry.

                          theorem Cslib.Circuits.Rational.exists_rowEntry_eq {rows : List (List ℤ)} {row : List ℤ} {z : ℤ} (hrow : row ∈ rows) (hz : z ∈ row) :
                          ∃ (i : ℕ) (j : ℕ), rowEntry rows i j = z

                          Every stored entry of a list of rows is one of its indexed entries.

                          theorem Cslib.Circuits.Rational.natAbs_traceTerms_take_sum_lt {A F : List (List ℤ)} {b e : ℕ} (hF : ∀ (i j : ℕ), (rowEntry F i j).natAbs < 2 ^ e) (i m : ℕ) :
                          (List.take m (traceTerms A F i)).sum.natAbs < 2 ^ (e + (1 + A.length + b))

                          Every prefix sum of the diagonal terms of one stage obeys the next stage's bound.

                          theorem Cslib.Circuits.Rational.natAbs_productTerms_take_sum_lt {A F : List (List ℤ)} {b e : ℕ} (hA : ∀ (i j : ℕ), (rowEntry A i j).natAbs < 2 ^ b) (hF : ∀ (i j : ℕ), (rowEntry F i j).natAbs < 2 ^ e) (i j m : ℕ) :
                          (List.take m (productTerms A F i j)).sum.natAbs < 2 ^ (e + (1 + A.length + b))

                          Every prefix sum of the product terms of one stage obeys the next stage's bound.

                          theorem Cslib.Circuits.Rational.natAbs_traceTerms_sum_mul_lt {A F : List (List ℤ)} {b e : ℕ} (hA : ∀ (i j : ℕ), (rowEntry A i j).natAbs < 2 ^ b) (hF : ∀ (i j : ℕ), (rowEntry F i j).natAbs < 2 ^ e) (i j : ℕ) :
                          ((traceTerms A F i).sum * rowEntry A i j).natAbs < 2 ^ (e + (1 + A.length + b))

                          The trace product computed in one stage obeys the next stage's bound.

                          theorem Cslib.Circuits.Rational.natAbs_stepEntryRows_lt {A F : List (List ℤ)} {b e : ℕ} (hA : ∀ (i j : ℕ), (rowEntry A i j).natAbs < 2 ^ b) (hF : ∀ (i j : ℕ), (rowEntry F i j).natAbs < 2 ^ e) (i j : ℕ) :
                          (stepEntryRows A F i j).natAbs < 2 ^ (e + (1 + A.length + b))

                          One stage multiplies the entry bound by at most 2 ^ (1 + d + b).

                          theorem Cslib.Circuits.Rational.natAbs_rowEntry_stagesRows_lt {A : List (List ℤ)} {b : ℕ} (hA : ∀ (i j : ℕ), (rowEntry A i j).natAbs < 2 ^ b) (k i j : ℕ) :
                          (rowEntry (stagesRows A k) i j).natAbs < 2 ^ (b + k * (1 + A.length + b))

                          Every entry of the k-th stage of an input with entries below 2 ^ b in absolute value is below 2 ^ (b + k * (1 + d + b)), where d is the number of rows.

                          theorem Cslib.Circuits.Rational.natAbs_lt_of_mem_stagesRows {A : List (List ℤ)} {b : ℕ} (hA : ∀ (i j : ℕ), (rowEntry A i j).natAbs < 2 ^ b) (k : ℕ) {row : List ℤ} (hrow : row ∈ stagesRows A k) {z : ℤ} (hz : z ∈ row) :
                          z.natAbs < 2 ^ (b + k * (1 + A.length + b))

                          The stage bound for every stored entry of a stage.

                          Bounds in bit length #

                          theorem Cslib.Circuits.Rational.intBits_rowEntry_stagesRows_le {A : List (List ℤ)} {b : ℕ} (hA : ∀ (i j : ℕ), intBits (rowEntry A i j) ≤ b + 1) (k i j : ℕ) :
                          intBits (rowEntry (stagesRows A k) i j) ≤ b + k * (1 + A.length + b) + 1

                          The stage bound in bit length: inputs of at most b + 1 bits give k-th stage entries of at most b + k * (1 + d + b) + 1 bits.

                          theorem Cslib.Circuits.Rational.intBits_le_of_mem_stagesRows {A : List (List ℤ)} {b : ℕ} (hA : ∀ row ∈ A, ∀ z ∈ row, intBits z ≤ b + 1) (k : ℕ) {row : List ℤ} (hrow : row ∈ stagesRows A k) {z : ℤ} (hz : z ∈ row) :
                          intBits z ≤ b + k * (1 + A.length + b) + 1

                          The bit-length stage bound for every stored entry of a stage.

                          theorem Cslib.Circuits.Rational.intBits_step_le {A F : List (List ℤ)} {b e : ℕ} (hA : ∀ (i j : ℕ), intBits (rowEntry A i j) ≤ b + 1) (hF : ∀ (i j : ℕ), intBits (rowEntry F i j) ≤ e + 1) (i j m : ℕ) :
                          intBits (List.take m (traceTerms A F i)).sum ≤ e + (1 + A.length + b) + 1 ∧ intBits (List.take m (productTerms A F i j)).sum ≤ e + (1 + A.length + b) + 1 ∧ intBits ((traceTerms A F i).sum * rowEntry A i j) ≤ e + (1 + A.length + b) + 1 ∧ intBits (stepEntryRows A F i j) ≤ e + (1 + A.length + b) + 1

                          The bit-length bound on every value computed in one stage: prefix sums of both term lists, the trace product and the new entry.

                          Polynomial-time certificate #

                          theorem Cslib.Circuits.Rational.length_of_mem_tabulateRows {d : ℕ} {g : ℕ → ℕ → ℤ} {row : List ℤ} (hrow : row ∈ tabulateRows d g) :
                          row.length = d

                          Upper bound on the bit length of any entry in the first k Bird stages of a matrix of encoded length L.

                          Instances For

                            Upper bound on the encoded length of any row in the first k Bird stages of a matrix of encoded length L.

                            Instances For

                              Upper bound on the encoded length of any stage table in the first k Bird stages of a matrix of encoded length L.

                              Instances For

                                The staged division-free integer determinant detRows is computable in polynomial time on lists of rows of binary sign-magnitude integers.