Monge matrices, total monotonicity, and the SMAWK algorithm #
An m × n matrix M : ℕ → ℕ → β is Monge (IsMonge) if
M i₁ j₁ + M i₂ j₂ ≤ M i₁ j₂ + M i₂ j₁ for all i₁ < i₂ < m and j₁ < j₂ < n, and totally
monotone (IsTotallyMonotone) if M i₁ j₂ < M i₁ j₁ → M i₂ j₂ < M i₂ j₁ for all i₁ < i₂ < m
and j₁ < j₂ < n. Every Monge matrix over an ordered cancellative additive commutative monoid is
totally monotone (IsMonge.isTotallyMonotone).
The SMAWK algorithm of Aggarwal, Klawe, Moran, Shor and Wilber finds the leftmost minimizing column
of every row of an m × n totally monotone matrix in O(m + n) entry comparisons
[AKM+87]:
reduceQprunes the candidate columnscolsto a sublist of length at mostrows.lengthwhile preserving the leftmost minimum of every row inrows.smawkQappliesreduceQ, recurses on the odd-indexed rowsoddRows, and interpolates the even-indexed rows between the adjacent odd-row minima.
The algorithm is written directly in CSLib's comparison-query model FreeM (LEQuery (ℕ × ℕ)),
where each matrix comparison (r, c₁) ≤ (r, c₂) is a query (LEQuery.ask) and pure index and list
bookkeeping is uncharged. Thus smawkQ_countQueries_le and rowMinimaQ_upperBound certify linear
comparison-query complexity (≤ 4 m + 2 n comparisons against every oracle), not a Word-RAM
running time. Evaluating smawkQ / rowMinimaQ against LEQuery.keyOracle (Function.uncurry M)
yields smawk / rowMinima, proved exact on every totally monotone matrix (smawk_spec,
isLeftmostRowMin_rowMinima).
Main definitions #
Cslib.Algorithms.Lean.Matrix.SMAWK.IsMonge: the Monge (submodular quadrangle) inequality on anm × nmatrix.Cslib.Algorithms.Lean.Matrix.SMAWK.IsTotallyMonotone: total monotonicity for row minima.Cslib.Algorithms.Lean.Matrix.SMAWK.IsLeftmostMinOn,Cslib.Algorithms.Lean.Matrix.SMAWK.IsLeftmostRowMin: leftmost minimizing column predicates.Cslib.Algorithms.Lean.Matrix.SMAWK.oddRows: odd-indexed rowsrows[1], rows[3], ….Cslib.Algorithms.Lean.Matrix.SMAWK.reduceQ,Cslib.Algorithms.Lean.Matrix.SMAWK.smawkQ,Cslib.Algorithms.Lean.Matrix.SMAWK.rowMinimaQ: SMAWK inFreeM (LEQuery (ℕ × ℕ)).Cslib.Algorithms.Lean.Matrix.SMAWK.reduce,Cslib.Algorithms.Lean.Matrix.SMAWK.smawk,Cslib.Algorithms.Lean.Matrix.SMAWK.rowMinima: pure evaluations against a matrixM.
Main results #
Cslib.Algorithms.Lean.Matrix.SMAWK.IsMonge.isTotallyMonotone: Monge implies totally monotone.Cslib.Algorithms.Lean.Matrix.SMAWK.IsTotallyMonotone.leftmostMinOn_mono: leftmost row minima are nondecreasing in the row index.Cslib.Algorithms.Lean.Matrix.SMAWK.reduce_spec:reducereturns a sublist of length at mostrows.lengthpreserving every row's leftmost minimum.Cslib.Algorithms.Lean.Matrix.SMAWK.smawk_spec,Cslib.Algorithms.Lean.Matrix.SMAWK.isLeftmostRowMin_rowMinima: exactness of SMAWK on every totally monotone matrix.Cslib.Algorithms.Lean.Matrix.SMAWK.reduceQ_countQueries_add_length_le,Cslib.Algorithms.Lean.Matrix.SMAWK.smawkQ_countQueries_le,Cslib.Algorithms.Lean.Matrix.SMAWK.rowMinimaQ_countQueries_le,Cslib.Algorithms.Lean.Matrix.SMAWK.rowMinimaQ_upperBound: at most4 m + 2 ncomparison queries against every oracle.
References #
Monge matrices, total monotonicity, and leftmost row minima #
Every Monge matrix over an ordered cancellative additive commutative monoid is totally monotone.
Contrapositive form of total monotonicity: if j₁ < j₂ and M i₂ j₁ ≤ M i₂ j₂, then
M i₁ j₁ ≤ M i₁ j₂ for every earlier row i₁ < i₂.
Every nonempty column list admits a leftmost minimizer for row r.
In a totally monotone matrix, leftmost row minima are monotone nondecreasing in the row index.
SMAWK in FreeM (LEQuery (ℕ × ℕ)) #
Interpolation phase of SMAWK: given the odd-row minima oddMins and remaining candidate
columns remCols, scan the bracketed intervals for the even-indexed rows and interleave them with
oddMins.
SMAWK algorithm in FreeM (LEQuery (ℕ × ℕ)): computes the leftmost minimizing column of every
row in rows among cols, using at most 4 * rows.length + 2 * cols.length entry comparisons
against every oracle.
Comparison-query program computing the leftmost minimizing column of every row of an m × n
matrix.
Leftmost row minima of an m × n matrix M, computed by SMAWK.
Comparison-query complexity bounds (for every oracle) #
For every oracle, reduceQ returns a sublist of cols of length at most rows.length,
and the sum of its query count and output length is at most 2 * cols.length.
Linear comparison-query bound for SMAWK: for every oracle, smawkQ rows cols makes at
most 4 * rows.length + 2 * cols.length comparison queries. This measures entry comparisons in
FreeM (LEQuery (ℕ × ℕ)) and makes no claim about Word-RAM running time.
For every oracle, rowMinimaQ m n makes at most 4 * m + 2 * n comparison queries.
Cslib.Query.UpperBound formulation of the O(m + n) comparison-query bound for SMAWK: on
matrices of size m + n ≤ k, rowMinimaQ m n makes at most 4 * k comparisons against every
oracle.
Exact correctness on totally monotone matrices #
Correctness of reduce: on a totally monotone m × n matrix, reduce M rows cols is a
sublist of cols of length at most rows.length that retains the leftmost minimizing column of
every row in rows.
Correctness of smawk: on a totally monotone m × n matrix, for strictly increasing
rows (all < m) and nonempty strictly increasing cols (all < n), smawk M rows cols
returns the exact leftmost minimizing column in cols for each row in rows.
On any totally monotone m × n matrix with 0 < n, rowMinima M m n has length m.
Exact optimality of SMAWK: on any totally monotone m × n matrix with 0 < n, the
i-th entry of rowMinima M m n is the leftmost minimizing column of row i.