Documentation

EconCSLib.Math.LinearAlgebra.FourierMotzkin

EconCSLib.Math.LinearAlgebra.FourierMotzkin #

Formalises the Theorem of the Alternative [MFoGT, Section 2.8, Exercise 7] over any linearly ordered field ([Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ]). We prove the Fin m ร— Fin n version directly; a general Fintype I form would transport via Fintype.equivFin.

For a finite system of weak linear inequalities A x โ‰ฅ b with A : Fin m โ†’ Fin n โ†’ ๐•œ, b : Fin m โ†’ ๐•œ, exactly one of:

is nonempty.

Blueprint #

The primal feasibility set and Farkas certificate set #

We parameterise the row index by an abstract Fintype I (rather than Fin m) because the Fourier-Motzkin reduction produces a row index of the form Iโฐ โŠ• (Iโบ ร— Iโป), which is naturally a Fintype but does not stay Fin m. A user typically instantiates I := Fin m at the application boundary.

def EconCSLib.LinearAlgebra.rowEval {๐•œ : Type u_1} [Field ๐•œ] {I : Type u_2} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (i : I) (x : Fin n โ†’ ๐•œ) :
๐•œ

Evaluate the LHS of row i of the matrix A : I โ†’ Fin n โ†’ ๐•œ at the point x : Fin n โ†’ ๐•œ.

Equations
Instances For
    def EconCSLib.LinearAlgebra.IsFeasible {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (b : I โ†’ ๐•œ) :

    Primal feasibility of the system A x โ‰ฅ b.

    Equations
    Instances For
      def EconCSLib.LinearAlgebra.IsCertificate {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (b u : I โ†’ ๐•œ) :

      u : I โ†’ ๐•œ is a Farkas certificate of infeasibility of A x โ‰ฅ b.

      Equations
      Instances For
        def EconCSLib.LinearAlgebra.HasCertificate {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (b : I โ†’ ๐•œ) :

        Existence of a Farkas certificate.

        Equations
        Instances For

          Disjointness: IsFeasible and HasCertificate cannot both hold #

          theorem EconCSLib.LinearAlgebra.feas_cert_disjoint {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (b : I โ†’ ๐•œ) (hfeas : IsFeasible A b) (hcert : HasCertificate A b) :

          Sign partition of rows by the last-column coefficient #

          For an (n+1)-column matrix A : I โ†’ Fin (n+1) โ†’ ๐•œ over a Fintype row index I, partition I into the three sign-of-A i (Fin.last n) cases. We use abbrev so Lean's Subtype.fintype instances are transparent.

          The generic-I formulation (rather than Fin m) is needed for the induction in theorem_of_alternative_aux: after FM, the row index becomes ZeroRows โŠ• (PosRows ร— NegRows), which is itself a Fintype but not a Fin _.

          @[reducible, inline]
          abbrev EconCSLib.LinearAlgebra.ZeroRows {๐•œ : Type u_1} [Field ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) :
          Type u_2

          Rows where the last-column coefficient is zero.

          Equations
          Instances For
            @[reducible, inline]
            abbrev EconCSLib.LinearAlgebra.PosRows {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) :
            Type u_2

            Rows where the last-column coefficient is strictly positive.

            Equations
            Instances For
              @[reducible, inline]
              abbrev EconCSLib.LinearAlgebra.NegRows {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) :
              Type u_2

              Rows where the last-column coefficient is strictly negative.

              Equations
              Instances For
                @[reducible, inline]
                abbrev EconCSLib.LinearAlgebra.FMRowIndex {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) :
                Type u_2

                Reduced row index after Fourier-Motzkin elimination of the last column.

                Equations
                Instances For

                  Fourier-Motzkin reduced matrix and RHS #

                  Per blueprint docs/knowledge/nodes/core/linear_algebra.theorem_of_alternative.fourier_motzkin.md:

                  def EconCSLib.LinearAlgebra.fmA {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (idx : FMRowIndex A) (j : Fin n) :
                  ๐•œ

                  Reduced matrix coefficient.

                  Equations
                  Instances For
                    def EconCSLib.LinearAlgebra.fmB {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (idx : FMRowIndex A) :
                    ๐•œ

                    Reduced right-hand side.

                    Equations
                    Instances For
                      @[simp]
                      theorem EconCSLib.LinearAlgebra.fmA_inl {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (k : ZeroRows A) (j : Fin n) :
                      fmA A (Sum.inl k) j = A (โ†‘k) j.castSucc
                      @[simp]
                      theorem EconCSLib.LinearAlgebra.fmA_inr {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (p : PosRows A) (q : NegRows A) (j : Fin n) :
                      fmA A (Sum.inr (p, q)) j = -A (โ†‘q) (Fin.last n) * A (โ†‘p) j.castSucc + A (โ†‘p) (Fin.last n) * A (โ†‘q) j.castSucc
                      @[simp]
                      theorem EconCSLib.LinearAlgebra.fmB_inl {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (k : ZeroRows A) :
                      fmB A b (Sum.inl k) = b โ†‘k
                      @[simp]
                      theorem EconCSLib.LinearAlgebra.fmB_inr {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (p : PosRows A) (q : NegRows A) :
                      fmB A b (Sum.inr (p, q)) = -A (โ†‘q) (Fin.last n) * b โ†‘p + A (โ†‘p) (Fin.last n) * b โ†‘q
                      @[simp]
                      theorem EconCSLib.LinearAlgebra.rowEval_def {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_3} {n : โ„•} [Fintype I] (A : I โ†’ Fin n โ†’ ๐•œ) (i : I) (x : Fin n โ†’ ๐•œ) :
                      rowEval A i x = โˆ‘ j : Fin n, A i j * x j

                      Feasibility transfer (โ‡’ direction) #

                      If (x_0, ..., x_n) satisfies the original (n+1)-variable system, then (x_0, ..., x_{n-1}) satisfies the reduced n-variable system.

                      theorem EconCSLib.LinearAlgebra.fm_feasible_of_feasible {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (hfeas : IsFeasible A b) :
                      IsFeasible (fmA A) (fmB A b)

                      Reduced-pair lower-upper bound #

                      From the reduced inequality at (p, q) โˆˆ PosRows ร— NegRows, derive that the lower bound L_p(x') is at most the upper bound U_q(x'). This is the algebraic content of "max lower โ‰ค min upper" needed to construct x_last.

                      Feasibility transfer (โ‡ direction) #

                      If a solution x' of the reduced system exists, construct an x_last such that Fin.snoc x' x_last solves the original (n+1)-variable system.

                      theorem EconCSLib.LinearAlgebra.feasible_of_fm_feasible {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (hred : IsFeasible (fmA A) (fmB A b)) :

                      Certificate lift via the transposed FM matrix #

                      The FM reduction can be encoded as a matrix L : FMRowIndex A โ†’ Fin m โ†’ ๐•œ whose rows are the nonneg coefficients of the original rows feeding into each reduced row. The Farkas certificate of the reduced system lifts to the original via u := L^T u', i.e. u i = โˆ‘ idx, L idx i * u' idx.

                      def EconCSLib.LinearAlgebra.liftCoeff {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (idx : FMRowIndex A) (i : I) :
                      ๐•œ

                      The FM lift coefficient L idx i: the weight with which original row i enters the reduced row idx.

                      Equations
                      Instances For
                        theorem EconCSLib.LinearAlgebra.liftCoeff_inl {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (k : ZeroRows A) (i : I) :
                        liftCoeff A (Sum.inl k) i = if โ†‘k = i then 1 else 0
                        theorem EconCSLib.LinearAlgebra.liftCoeff_inr {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (p : PosRows A) (q : NegRows A) (i : I) :
                        liftCoeff A (Sum.inr (p, q)) i = (if โ†‘p = i then -A (โ†‘q) (Fin.last n) else 0) + if โ†‘q = i then A (โ†‘p) (Fin.last n) else 0
                        def EconCSLib.LinearAlgebra.liftCert {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (u' : FMRowIndex A โ†’ ๐•œ) (i : I) :
                        ๐•œ

                        The lifted certificate u i = โˆ‘ idx, L idx i * u'(idx).

                        Equations
                        Instances For
                          theorem EconCSLib.LinearAlgebra.liftCert_nonneg {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) {u' : FMRowIndex A โ†’ ๐•œ} (hu' : โˆ€ (idx : FMRowIndex A), 0 โ‰ค u' idx) (i : I) :

                          Pointwise nonneg lift.

                          theorem EconCSLib.LinearAlgebra.fm_cert_lift {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_2} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin (n + 1) โ†’ ๐•œ) (b : I โ†’ ๐•œ) (hred : HasCertificate (fmA A) (fmB A b)) :

                          Farkas certificate lift: if u' certifies the reduced system, liftCert A u' certifies the original.

                          Base case n = 0 #

                          For a 0-variable system, rowEval A i x = โˆ‘ j : Fin 0, โ€ฆ = 0 for every i, so feasibility collapses to โˆ€ i, b i โ‰ค 0. Negation yields a single i with 0 < b i, and the indicator at that i is the Farkas certificate.

                          Strong induction on the number of columns #

                          Combine: feasibility transfer (feasible_of_fm_feasible) is the contrapositive direction that brings ยฌ IsFeasible A b to ยฌ IsFeasible (fmA A) (fmB A b); the inductive hypothesis then yields the reduced certificate, and fm_cert_lift lifts it back to the original system.

                          Final packaged theorem #

                          theorem EconCSLib.LinearAlgebra.theorem_of_alternative {๐•œ : Type u_1} [Field ๐•œ] [LinearOrder ๐•œ] [IsStrictOrderedRing ๐•œ] {I : Type u_3} [Fintype I] [DecidableEq I] {n : โ„•} (A : I โ†’ Fin n โ†’ ๐•œ) (b : I โ†’ ๐•œ) :

                          Theorem of the Alternative [MFoGT, Section 2.8, Exercise 7]: for a finite system of weak linear inequalities A x โ‰ฅ b over a linearly ordered field, exactly one of the primal S = {x | Ax โ‰ฅ b} and the Farkas certificate set T = {u โ‰ฅ 0 | uแต€A = 0, โŸจu, bโŸฉ > 0} is nonempty.

                          Combines feas_cert_disjoint (disjointness) with the existence direction proved by Fourier-Motzkin elimination + induction on the number of variables (theorem_of_alternative_aux).