Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Integer scheduling inputs, feasible orders, ∑wjCj\sum w_jC_j∑wj​Cj​, and polynomial-time (randomized) approximation algorithms

Definition
SingleMachinePrec_VariableCost_Supplement_Scheduling

by mikedeng1 · Nov 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

approximation-algorithmsp2o-batch-supp500p2o-gran-per-chapterp2o-plan-paperp2o-v1polynomial-timescheduling

An instance of 1∣prec∣∑wjCj1|\mathrm{prec}|\sum w_jC_j1∣prec∣∑wj​Cj​ (p. 653) consists of nnn jobs 0,…,n−10,\dots,n-10,…,n−1, nonnegative integer processing times pjp_jpj​ and weights wjw_jwj​, and the precedence relation PPP, given by its n×nn\times nn×n Boolean matrix; the precedence constraints are required to form a partial order (reflexive, antisymmetric, transitive). The input code of an instance writes nnn in unary, every pjp_jpj​ and wjw_jwj​ in self-delimiting binary, and then the matrix row by row.

A schedule is a processing order σ\sigmaσ: a list containing every job exactly once. It is feasible when (i,j)∈P(i,j)\in P(i,j)∈P, i≠ji\neq ji=j, implies that iii comes before jjj in σ\sigmaσ. The completion time Cj(σ)C_j(\sigma)Cj​(σ) is the total processing time of jjj and of the jobs before it, and the cost of σ\sigmaσ is

cost⁡(σ)=∑jwj Cj(σ),\operatorname{cost}(\sigma)=\sum_{j} w_j\,C_j(\sigma),cost(σ)=j∑​wj​Cj​(σ),

the full objective, including its fixed part.

Given a class of inputs (an input may carry more data than the instance, such as a realizer) and a ratio α\alphaα, an α\alphaα-approximation algorithm maps the code of every input of the class to the code of a feasible order σ\sigmaσ with cost⁡(σ)≤α⋅cost⁡(τ)\operatorname{cost}(\sigma)\le\alpha\cdot\operatorname{cost}(\tau)cost(σ)≤α⋅cost(τ) for every feasible order τ\tauτ. It runs in polynomial time if it is computed by one multi-stack Turing machine within a polynomial in the length of the input code.

A randomized polynomial-time α\alphaα-approximation algorithm consists of two polynomial-time machines: the first computes from the input code a number N≥1N\ge1N≥1; a seed sss is drawn uniformly from {0,…,N−1}\{0,\dots,N-1\}{0,…,N−1}; the second maps the input code followed by the binary code of sss to the code of a feasible order σs\sigma_sσs​. Every outcome must be feasible and the expected cost must satisfy

1N∑s<Ncost⁡(σs)≤α⋅cost⁡(τ)for every feasible τ.\frac1N\sum_{s<N}\operatorname{cost}(\sigma_s)\le\alpha\cdot\operatorname{cost}(\tau)\quad\text{for every feasible }\tau .N1​s<N∑​cost(σs​)≤α⋅cost(τ)for every feasible τ.

These notions are the conclusions of the paper's algorithmic theorems (§§3–6).

Formalization Note Machines are the published QAlgorithms.Complexity.PolyTimeComputable (Mathlib's TM2ComputableInPolyTime on List Bool). Inserting idle time never helps, so idle-free orders suffice. toInstance gives the published real-valued SingleMachinePrec.VariableCost.Instance carried by an integer input. The comparison with every feasible order replaces OPT\mathrm{OPT}OPT and avoids a minimum over a possibly empty set.

Definition code
import Mathlib
import Definitions.Def_QAlgorithms_ClassicalStringComputability
import Definitions.Def_SingleMachinePrec_VariableCost_VertexCoverGraph

set_option autoImplicit false

namespace SingleMachinePrec.VariableCost.Supplement

open QAlgorithms.Complexity

/-! ### Binary codes -/

/-- Self-delimiting binary code of a natural number: each bit `b` of its binary expansion
(least significant first) is written as the pair `true, b`, and the word ends with `false`.
Its length is `2 · (number of binary digits) + 1`, so numbers are written in binary. -/
def encBin (m : ℕ) : Str :=
  (Nat.bits m).flatMap (fun b => [true, b]) ++ [false]

/-- Code of a list: its length in unary (`encNat`), followed by the codes of its entries. -/
def encList {α : Type} (f : α → Str) (l : List α) : Str :=
  encNat l.length ++ l.flatMap f

/-! ### Scheduling instances with integer data -/

/-- An instance of `1|prec|∑ w_j C_j` as an algorithm receives it (p. 653): `n` jobs
`0, …, n-1`, nonnegative integer processing times `p j` and weights `w j`, and the precedence
relation given by its `n × n` Boolean matrix (`prec i j = true` means `(i, j) ∈ P`). -/
structure SchedInput where
  n : ℕ
  p : Fin n → ℕ
  w : Fin n → ℕ
  prec : Fin n → Fin n → Bool

namespace SchedInput

/-- The precedence relation `P` of the instance, as a proposition. -/
def Prec (x : SchedInput) (i j : Fin x.n) : Prop := x.prec i j = true

/-- The precedence constraints form a partial order (reflexive, antisymmetric, transitive), as
required on p. 653. -/
def IsPoset (x : SchedInput) : Prop := IsPartialOrder (Fin x.n) x.Prec

/-- The input code: `n` in unary, then `p_0, …, p_{n-1}` and `w_0, …, w_{n-1}` in binary, then
the `n²` entries of the precedence matrix row by row. -/
def enc (x : SchedInput) : Str :=
  encNat x.n ++ (List.finRange x.n).flatMap (fun j => encBin (x.p j)) ++
    (List.finRange x.n).flatMap (fun j => encBin (x.w j)) ++
    (List.finRange x.n).flatMap (fun i => (List.finRange x.n).map (fun j => x.prec i j))

/-- A (non-preemptive, idle-free) schedule is a processing order `σ` of the jobs: a list
containing every job exactly once. It is feasible when `(i, j) ∈ P`, `i ≠ j` implies that `i`
comes before `j`. -/
def Feasible (x : SchedInput) (σ : List (Fin x.n)) : Prop :=
  σ.Nodup ∧ σ.length = x.n ∧ ∀ i j, x.Prec i j → i ≠ j → σ.idxOf i < σ.idxOf j

/-- Completion time `C_j` of job `j` in the order `σ`: the total processing time of `j` and of
the jobs before it. -/
def completion (x : SchedInput) (σ : List (Fin x.n)) (j : Fin x.n) : ℕ :=
  ((σ.take (σ.idxOf j + 1)).map x.p).sum

/-- The objective `∑_j w_j C_j` of the order `σ` (the full weighted completion time,
including its fixed part). -/
def cost (x : SchedInput) (σ : List (Fin x.n)) : ℕ :=
  ∑ j, x.w j * x.completion σ j

/-- The published real-valued instance (`SingleMachinePrec.VariableCost.Instance`) carried by
this integer input. -/
def toInstance (x : SchedInput) (h : x.IsPoset) : SingleMachinePrec.VariableCost.Instance (Fin x.n) where
  P := x.Prec
  isPartialOrder := h
  p := fun j => (x.p j : ℝ)
  w := fun j => (x.w j : ℝ)
  p_nonneg := fun _ => Nat.cast_nonneg _
  w_nonneg := fun _ => Nat.cast_nonneg _

end SchedInput

/-- The output code of a processing order: its length in unary, then the job indices in
binary. -/
def encSchedule {n : ℕ} (σ : List (Fin n)) : Str :=
  encList (fun j : Fin n => encBin j.val) σ

/-! ### Approximation algorithms -/

/-- `A` is an `α`-approximation algorithm on the inputs `a : I` satisfying `Cls`: on the code
`enc a` it outputs the code of a feasible order `σ` of the instance `inst a` whose cost is at
most `α a` times the cost of every feasible order (hence at most `α a · OPT`). -/
def IsApproxOn {I : Type} (enc : I → Str) (inst : I → SchedInput) (Cls : I → Prop)
    (α : I → ℝ) (A : Str → Str) : Prop :=
  ∀ a, Cls a → ∃ σ : List (Fin (inst a).n), A (enc a) = encSchedule σ ∧ (inst a).Feasible σ ∧
    ∀ τ : List (Fin (inst a).n), (inst a).Feasible τ →
      ((inst a).cost σ : ℝ) ≤ α a * ((inst a).cost τ : ℝ)

/-- A deterministic polynomial-time `α`-approximation algorithm: one multi-stack Turing machine,
running in time polynomial in the length of the input code, that is an `α`-approximation
algorithm on the inputs of class `Cls`. -/
def HasPolyTimeApprox {I : Type} (enc : I → Str) (inst : I → SchedInput) (Cls : I → Prop)
    (α : I → ℝ) : Prop :=
  ∃ A : Str → Str, PolyTimeComputable A ∧ IsApproxOn enc inst Cls α A

/-- A randomized polynomial-time `α`-approximation algorithm. Polynomial-time machine `R`
computes from the input code a range `N ≥ 1`; a seed `s` is drawn uniformly from
`{0, …, N-1}`; polynomial-time machine `A` maps the input code followed by `encBin s` to the
code of a feasible order `σ s`. Every outcome is feasible, and the expected cost
`(1/N) ∑_{s<N} cost (σ s)` is at most `α a` times the cost of every feasible order. -/
def HasPolyTimeRandApprox {I : Type} (enc : I → Str) (inst : I → SchedInput) (Cls : I → Prop)
    (α : I → ℝ) : Prop :=
  ∃ R A : Str → Str, PolyTimeComputable R ∧ PolyTimeComputable A ∧
    ∀ a, Cls a → ∃ N : ℕ, 0 < N ∧ R (enc a) = encBin N ∧
      ∃ σ : ℕ → List (Fin (inst a).n),
        (∀ s < N, A (enc a ++ encBin s) = encSchedule (σ s) ∧ (inst a).Feasible (σ s)) ∧
        ∀ τ : List (Fin (inst a).n), (inst a).Feasible τ →
          ∑ s ∈ Finset.range N, ((inst a).cost (σ s) : ℝ) ≤ α a * N * ((inst a).cost τ : ℝ)

end SingleMachinePrec.VariableCost.Supplement
Source
Ambühl, Mastrolilli, Mutsanas, Svensson, On the Approximability of Single-Machine Scheduling with Precedence Constraints, Math. Oper. Res. 36(4) (2011), p. 653, §1 (the problem 1|prec|∑w_jC_j); pp. 657–661, Theorems 3.2–6.5 (polynomial-time and randomized approximation algorithms)

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me