Documentation

CslibFrontier.Algorithms.WordRAM.Auction.RowScan

Row scans for best and second-best reduced costs in Word-RAM auction #

Two independent read-only O(n) row scans over C[i₀, ·] + price[·]:

Both loop specs share the readout lemma AuctionMem.redCost_read from Auction.Workspace. The single-step functions and their realize certificates remain private.

Main definitions #

Main results #

Arguments for scanning one row rowBase[0..n) against bPrice[0..n).

  • n : ℕ

    Number of objects in the row.

  • rowBase : ℕ

    Base address bC + i₀ * n of person i₀'s cost row.

  • bPrice : ℕ

    Base address of object prices.

Instances For
    theorem Cslib.Algorithms.WordRAM.Auction.encScanRowArgs_fits {w : ℕ} {a : ScanRowArgs} (h_n : WordRAM.Fits w a.n) (h_rowBase : WordRAM.Fits w a.rowBase) (h_bPrice : WordRAM.Fits w a.bPrice) (j✝ : Fin 3) :
    @[reducible, inline]

    The tuple word encoding of the fields of encScanRowArgs.

    Running state of the argmin row scan (findBestProg).

    • idx : ℕ

      Next object index to inspect.

    • bestJ : ℕ

      Best object index seen so far.

    • bestVal : ℕ

      Least reduced cost seen so far.

    Instances For
      @[reducible, inline]

      The tuple word encoding of the fields of encBestState.

      theorem Cslib.Algorithms.WordRAM.Auction.encBestState_fits {w : ℕ} {a : BestState} (h_idx : WordRAM.Fits w a.idx) (h_bestJ : WordRAM.Fits w a.bestJ) (h_bestVal : WordRAM.Fits w a.bestVal) (j✝ : Fin 3) :

      Arguments for the second-best row scan (skipping bestJ).

      • n : ℕ

        Number of objects in the row.

      • rowBase : ℕ

        Base address bC + i₀ * n of person i₀'s cost row.

      • bPrice : ℕ

        Base address of object prices.

      • bestJ : ℕ

        Best object index to skip.

      Instances For
        @[reducible, inline]

        The tuple word encoding of the fields of encScanSecondArgs.

        theorem Cslib.Algorithms.WordRAM.Auction.encScanSecondArgs_fits {w : ℕ} {a : ScanSecondArgs} (h_n : WordRAM.Fits w a.n) (h_rowBase : WordRAM.Fits w a.rowBase) (h_bPrice : WordRAM.Fits w a.bPrice) (h_bestJ : WordRAM.Fits w a.bestJ) (j✝ : Fin 4) :

        Running state of the second-best reduced-cost scan (findSecondProg).

        • idx : ℕ

          Next object index to inspect.

        • hasSecond : ℕ

          0 if no object other than bestJ has been seen yet; 1 otherwise.

        • secondVal : ℕ

          Minimum reduced cost seen so far over j ≠ bestJ.

        Instances For
          theorem Cslib.Algorithms.WordRAM.Auction.encSecondState_fits {w : ℕ} {a : SecondState} (h_idx : WordRAM.Fits w a.idx) (h_hasSecond : WordRAM.Fits w a.hasSecond) (h_secondVal : WordRAM.Fits w a.secondVal) (j✝ : Fin 3) :
          @[reducible, inline]

          The tuple word encoding of the fields of encSecondState.

          Row scan 1: best object (findBestProg) #

          Scan a row of length d.n to find the object minimizing C[i₀, j] + price[j].

          theorem Cslib.Algorithms.WordRAM.Auction.findBest_spec {w W : ℕ} (ws : AuctionWS) {C : Fin ws.n × Fin ws.n → ℕ} {st : Lean.Assignment.AuctionState ws.n} (s₀ : DataStructure.Memory.State) (hws : ValidWS ws s₀) (ham : AuctionMem ws C st s₀) (hC_le : ∀ (i j : Fin ws.n), C (i, j) ≤ W) (hp_nn : ∀ (j : Fin ws.n), 0 ≤ st.price j) (hp_le : ∀ (j : Fin ws.n), st.price j ≤ ↑W + ↑ws.eps) (i₀ : Fin ws.n) (hfit1 : WordRAM.Fits w 1) (hfit_ws : WordRAM.Fits w (ws.outBase + ws.n + 1)) (hfit_rc : WordRAM.Fits w (2 * W + ws.eps)) :
          have rowBase := ws.bC + ↑i₀ * ws.n; have d := { n := ws.n, rowBase := rowBase, bPrice := ws.bPrice }; have prog := findBestProg d; have res := (DataStructure.Memory.spec 0).clientResult s₀ prog; FindBestSafe w d s₀ ∧ (DataStructure.Memory.spec w).ValidHistory s₀ ((DataStructure.Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 2 * ws.n ∧ (DataStructure.Memory.spec 0).clientState s₀ prog = s₀ ∧ ∃ (j₀ : Fin ws.n), Lean.Assignment.bestObject (fun (e : Fin ws.n × Fin ws.n) => ↑(C e)) st.price i₀ = some j₀ ∧ (∀ (k : Fin ws.n), Lean.Assignment.redCost (fun (e : Fin ws.n × Fin ws.n) => ↑(C e)) st.price i₀ j₀ ≤ Lean.Assignment.redCost (fun (e : Fin ws.n × Fin ws.n) => ↑(C e)) st.price i₀ k) ∧ res.bestJ = ↑j₀ ∧ ↑res.bestVal = Lean.Assignment.redCost (fun (e : Fin ws.n × Fin ws.n) => ↑(C e)) st.price i₀ j₀

          Specification of findBestProg: preserves memory, costs at most 2 * ws.n, and yields the exact bestObject index and value matching the pure Auction model.

          Row scan 2: second-best reduced cost (findSecondProg) #

          Scan a row of length d.n skipping d.bestJ to compute the second-least reduced cost.

          theorem Cslib.Algorithms.WordRAM.Auction.findSecond_spec {w W : ℕ} (ws : AuctionWS) {C : Fin ws.n × Fin ws.n → ℕ} {st : Lean.Assignment.AuctionState ws.n} (s₀ : DataStructure.Memory.State) (hws : ValidWS ws s₀) (ham : AuctionMem ws C st s₀) (hC_le : ∀ (i j : Fin ws.n), C (i, j) ≤ W) (hp_nn : ∀ (j : Fin ws.n), 0 ≤ st.price j) (hp_le : ∀ (j : Fin ws.n), st.price j ≤ ↑W + ↑ws.eps) (i₀ j₀ : Fin ws.n) (hfit1 : WordRAM.Fits w 1) (hfit_ws : WordRAM.Fits w (ws.outBase + ws.n + 1)) (hfit_rc : WordRAM.Fits w (2 * W + ws.eps)) :
          have rowBase := ws.bC + ↑i₀ * ws.n; have d := { n := ws.n, rowBase := rowBase, bPrice := ws.bPrice, bestJ := ↑j₀ }; have prog := findSecondProg d; have res := (DataStructure.Memory.spec 0).clientResult s₀ prog; FindSecondSafe w d s₀ ∧ (DataStructure.Memory.spec w).ValidHistory s₀ ((DataStructure.Memory.spec w).clientHistory s₀ prog) ∧ WordRAM.Realization.memoryCost prog s₀ ≤ 2 * ws.n ∧ (DataStructure.Memory.spec 0).clientState s₀ prog = s₀ ∧ match Lean.Assignment.secondBest (fun (e : Fin ws.n × Fin ws.n) => ↑(C e)) st.price i₀ j₀ with | none => res.hasSecond = 0 | some wVal => res.hasSecond = 1 ∧ ↑res.secondVal = wVal ∧ res.secondVal ≤ 2 * W + ws.eps

          Specification of findSecondProg: preserves memory, costs at most 2 * ws.n, and matches secondBest in the pure Auction model.