knapsack5_expected_offline_opt_eq
The expected offline optimum in the five-item knapsack instance equals 1011/50, i.e., knapsack5_expected_offline_opt = 1011 / 50.
Statement
theorem knapsack5_expected_offline_opt_eq :
knapsack5_expected_offline_opt = 1011 / 50- Formalizes
- arXiv:2611.33095 Section 3
- Verified
- 29 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 5
- knapsack5_expected_offline_optThe expected offline optimum knapsack5_expected_offline_opt : ℝ in the five-item knapsack instance, defined as the sum over ω : Bool ×…
- knapsack5_weightIn the five-item knapsack instance of arXiv:2611.33095 Section 3, the items have weights: item 0 (A) has weight 1, item 1 (B) has weight…
- knapsack5_principal_valThe function knapsack5_principal_val : Bool × Bool × Bool → Fin 5 → ℝ maps an uncurried state tuple (a, b, j) and an item i : Fin 5 to the…
- knapsack5_probThe rational probability mass function knapsack5_prob : Bool × Bool × Bool → ℚ assigns to each state (a, b, j) the product of (if a then 1…
- knapsack5_feasibleA subset of items in Fin 5 is feasible in the knapsack instance if the sum of its item weights does not exceed the knapsack capacity of 3.
Read back from the Lean
The declaration asserts that the expected offline optimal value of a 5-item stochastic knapsack problem, knapsack5_expected_offline_opt, is equal to 1011 / 50 (in ℝ).
Specifically:
- The probability space is the set of 8 outcomes $(a, b, j) \in \text{Bool} \times \text{Bool} \times \text{Bool}$, where $a, b, j$ are independent Bernoulli random variables with $\mathbb{P}(a = \text{true}) = 1/3$, $\mathbb{P}(b = \text{true}) = 1/3$, and $\mathbb{P}(j = \text{true}) = 1/100$.
- Five items $\{0, 1, 2, 3, 4\}$ have weights $1, 2, 2, 3, 3$, respectively.
- Their values under outcome $(a, b, j)$ are:
- Item 0: $9$ if $a$ is true, $0$ otherwise;
- Item 1: $9$ if $b$ is true, $0$ otherwise;
- Item 2: $3$;
- Item 3: $10$;
- Item 4: $900$ if $j$ is true, $0$ otherwise.
- A subset $S \subseteq \{0, 1, 2, 3, 4\}$ is feasible if the sum of weights of items in $S$ is at most $3$.
- For each outcome $\omega = (a, b, j)$, the offline optimum is the supremum of the total values attainable by feasible subsets.
- knapsack5_expected_offline_opt is the expectation (sum over all $\omega$ of the probability times the optimum for $\omega$).
- The theorem states this expectation equals $1011 / 50 = 20.22$.
Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.
The proof, explained
The theorem computes the expected offline optimum of a 5-item stochastic knapsack problem by finite exhaustion and exact rational arithmetic. Because the knapsack capacity is 3 and the items have small discrete weights, the offline optimization problem has only 8 random states and 32 possible subsets, allowing Lean's decision procedure (`decide`) to certify the exact integer maximum in each state. The supremum over feasible subsets in the definition of the offline optimum is then replaced by these state-dependent optimal values. Finally, the expectation over the three independent boolean variables is expanded into an explicit sum of 8 terms, which evaluates to 1011/50 by rational arithmetic.
For every state ω and every feasible item subset S, the sum of integer values of items in S is at most the claimed offline optimum. automation
The proposition is a universal quantification over the 8 possible states and the subsets of 5 items. Because feasibility (weight sum at most 3) and integer arithmetic are decidable, Lean's `decide` tactic checks all cases by exhaustive finite computation.
revert ω S hS decideFor every state ω, there exists a feasible item subset achieving the offline optimum value. automation
For each of the 8 states, there are only 32 subsets of items to consider. Lean's `decide` tactic tests each subset for feasibility and total value, finding a maximizing subset by exhaustive search.
revert ω decideFor every state ω and item index i, the real value of item i equals its integer value cast to ℝ. automation
Decomposing the state ω into its three boolean components and checking each of the 5 item indices yields 40 finite cases. Each case simplifies definitionally.
rcases ω with ⟨a, b, j⟩ fin_cases i <;> cases a <;> cases b <;> cases j <;> simp [knapsack5_principal_val, knapsack5_expected_offline_opt_eq_principal_val_nat]
For any state ω and subset S, the sum of real item values over S equals the sum of integer values cast to ℝ.
The natural-to-real cast commutes with finite sums by `Nat.cast_sum`, and the summands agree pointwise on all items by `knapsack5_expected_offline_opt_eq_principal_val_eq_nat`, so the sums are equal by `Finset.sum_congr`.
uses
Nat.cast_sum,Finset.sum_congr,knapsack5_expected_offline_opt_eq_principal_val_eq_natrw [Nat.cast_sum] exact Finset.sum_congr rfl (fun i _ => knapsack5_expected_offline_opt_eq_principal_val_eq_nat ω i)
The claimed optimal value, cast to ℝ, belongs to the set s of values achieved by feasible subsets.
By `knapsack5_expected_offline_opt_eq_nat_exists_opt`, there exists a feasible subset S attaining the integer optimum. Converting its real sum to the natural sum via `knapsack5_expected_offline_opt_eq_sum_val_eq_nat` shows that S achieves the target value.
uses
knapsack5_expected_offline_opt_eq_nat_exists_opt,knapsack5_expected_offline_opt_eq_sum_val_eq_natlet s := {r : ℝ | ∃ S : Finset (Fin 5), knapsack5_feasible S ∧ r = ∑ i ∈ S, knapsack5_principal_val ω i} have hmem : (knapsack5_expected_offline_opt_eq_opt_val_nat ω : ℝ) ∈ s := by obtain ⟨S, hS, hval⟩ := knapsack5_expected_offline_opt_eq_nat_exists_opt ω refine ⟨S, hS, ?_⟩ rw [knapsack5_expected_offline_opt_eq_sum_val_eq_nat, hval]
The claimed optimal value, cast to ℝ, is an upper bound on the set s of feasible values.
Any value r in s is the real sum of values of some feasible subset S. Rewriting r to the integer sum via `knapsack5_expected_offline_opt_eq_sum_val_eq_nat` and using `knapsack5_expected_offline_opt_eq_nat_le_opt` establishes the bound in ℕ, which transfers to ℝ via `Nat.cast_le.mpr`.
uses
knapsack5_expected_offline_opt_eq_sum_val_eq_nat,Nat.cast_le.mpr,knapsack5_expected_offline_opt_eq_nat_le_opthave hub : ∀ r ∈ s, r ≤ (knapsack5_expected_offline_opt_eq_opt_val_nat ω : ℝ) := by rintro r ⟨S, hS, rfl⟩ rw [knapsack5_expected_offline_opt_eq_sum_val_eq_nat] exact Nat.cast_le.mpr (knapsack5_expected_offline_opt_eq_nat_le_opt ω S hS)
The supremum of feasible knapsack values equals the integer optimum in ℝ.
Because s contains the candidate value, s is nonempty; because the candidate bounds s above, s is bounded above. By least upper bound properties (`csSup_le` and `le_csSup`), the supremum is both ≤ and ≥ the bound, so they are equal by antisymmetry (`le_antisymm`).
uses
csSup_le,le_csSup,le_antisymmhave hne : s.Nonempty := ⟨_, hmem⟩ have hbdd : BddAbove s := ⟨_, hub⟩ exact le_antisymm (csSup_le hne hub) (le_csSup hbdd hmem)
The sum of any real function g over the boolean type is g(true) + g(false).
The universe of booleans is the two-element set {true, false} by `Fintype.univ_bool`. Summing over this pair gives g(true) + g(false) via `Finset.sum_pair`, with distinctness of the elements checked by `decide`.
uses
Fintype.univ_bool,Finset.sum_pairhave : (Finset.univ : Finset Bool) = {true, false} := Fintype.univ_bool rw [this] exact Finset.sum_pair (by decide)
The sum of a function over Bool × Bool × Bool expands to the sum of its values at all 8 boolean triples.
The Cartesian product sum is rewritten as iterated sums using `Fintype.sum_prod_type`, each boolean sum is expanded using `knapsack5_expected_offline_opt_eq_sum_bool`, and polynomial addition associativity is resolved by `ring`.
uses
Fintype.sum_prod_type,knapsack5_expected_offline_opt_eq_sum_boolrw [Fintype.sum_prod_type] simp_rw [Fintype.sum_prod_type, knapsack5_expected_offline_opt_eq_sum_bool] ring
The expected offline optimum is expressed as an explicit sum of 8 terms, each the product of a state probability and the state's offline optimum.
Unfolding the definition of `knapsack5_expected_offline_opt` expresses it as an expectation of suprema. Each supremum is replaced by the corresponding integer optimum via `knapsack5_expected_offline_opt_eq_sSup_eq`, the sum over the product domain is expanded into 8 terms with `knapsack5_expected_offline_opt_eq_sum_bool3`, and the definitions of probabilities and optimal values are unfolded.
uses
knapsack5_expected_offline_opt_eq_sSup_eq,knapsack5_expected_offline_opt_eq_sum_bool3unfold knapsack5_expected_offline_opt simp_rw [knapsack5_expected_offline_opt_eq_sSup_eq] rw [knapsack5_expected_offline_opt_eq_sum_bool3] unfold knapsack5_prob knapsack5_expected_offline_opt_eq_opt_val_nat
The 8-term sum of rational products evaluates to 1011/50. automation
The tactic `norm_num` computes each probability-value product and simplifies the resulting sum of fractions to 1011/50.
norm_num
Nat.cast_sum- The natural-to-real cast of a finite sum of natural numbers equals the sum of the casted values.
Finset.sum_congr- Two finite sums are equal if their index sets are identical and their summands agree pointwise.
knapsack5_expected_offline_opt_eq_principal_val_eq_nat- For every state ω and item index i, the real knapsack value equals the integer knapsack value cast to ℝ.
knapsack5_expected_offline_opt_eq_nat_exists_opt- In every state ω, there exists a feasible subset of items whose total integer value achieves the offline optimum.
knapsack5_expected_offline_opt_eq_sum_val_eq_nat- For any state ω and subset S, the sum of real values of items in S equals the cast of their sum of integer values.
Nat.cast_le.mpr- An inequality between natural numbers implies the same inequality between their casts to ℝ.
knapsack5_expected_offline_opt_eq_nat_le_opt- For every state ω and feasible subset S, the integer value sum of S is at most the claimed offline optimum.
csSup_le- If a set is nonempty and upper-bounded by a, its supremum is at most a.
le_csSup- If a set is bounded above and contains an element a, then a is at most the supremum.
le_antisymm- If a ≤ b and b ≤ a in a partial order, then a = b.
Fintype.univ_bool- The universal finite set of booleans consists of {true, false}.
Finset.sum_pair- The sum of a function over a two-element set {a, b} with a ≠ b equals f(a) + f(b).
Fintype.sum_prod_type- A sum over a Cartesian product of finite types is equal to the iterated sum over the factors.
knapsack5_expected_offline_opt_eq_sum_bool- The sum of a real-valued function over the type Bool equals its value at true plus its value at false.
knapsack5_expected_offline_opt_eq_sSup_eq- In every state ω, the supremum of real values over feasible subsets equals the optimal integer value cast to ℝ.
knapsack5_expected_offline_opt_eq_sum_bool3- The sum of a real-valued function over Bool × Bool × Bool equals the sum of its values at all 8 boolean triples.
- Lemmas `knapsack5_expected_offline_opt_eq_nat_le_opt` and `knapsack5_expected_offline_opt_eq_nat_exists_opt` rely on `decide` to perform an exhaustive search over all 8 random states and 32 subsets of items to certify offline optimality.
- The final arithmetic calculation in `knapsack5_expected_offline_opt_eq` is discharged automatically by `norm_num`, which evaluates the 8-term rational sum.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
def knapsack5_expected_offline_opt_eq_principal_val_nat : Bool × Bool × Bool → Fin 5 → ℕ :=fun (a, b, j) i => match i with | 0 => if a then 9 else 0 | 1 => if b then 9 else 0 | 2 => 3 | 3 => 10 | _ => if j then 900 else 0instance knapsack5_expected_offline_opt_eq_feasible_dec : DecidablePred knapsack5_feasible := fun S => inferInstanceAs (Decidable (∑ i ∈ S, knapsack5_weight i ≤ 3))def knapsack5_expected_offline_opt_eq_opt_val_nat (ω : Bool × Bool × Bool) : ℕ := match ω with | (true, true, true) => 900 | (true, false, true) => 900 | (false, true, true) => 900 | (false, false, true) => 900 | (true, true, false) => 18 | (true, false, false) => 12 | (false, true, false) => 10 | (false, false, false) => 10lemma knapsack5_expected_offline_opt_eq_nat_le_opt (ω : Bool × Bool × Bool) (S : Finset (Fin 5)) (hS : knapsack5_feasible S) : ∑ i ∈ S, knapsack5_expected_offline_opt_eq_principal_val_nat ω i ≤ knapsack5_expected_offline_opt_eq_opt_val_nat ω := by revert ω S hS decidelemma knapsack5_expected_offline_opt_eq_nat_exists_opt (ω : Bool × Bool × Bool) : ∃ S : Finset (Fin 5), knapsack5_feasible S ∧ ∑ i ∈ S, knapsack5_expected_offline_opt_eq_principal_val_nat ω i = knapsack5_expected_offline_opt_eq_opt_val_nat ω := by revert ω decidelemma knapsack5_expected_offline_opt_eq_principal_val_eq_nat (ω : Bool × Bool × Bool) (i : Fin 5) : knapsack5_principal_val ω i = (knapsack5_expected_offline_opt_eq_principal_val_nat ω i : ℝ) := by rcases ω with ⟨a, b, j⟩ fin_cases i <;> cases a <;> cases b <;> cases j <;> simp [knapsack5_principal_val, knapsack5_expected_offline_opt_eq_principal_val_nat]lemma knapsack5_expected_offline_opt_eq_sum_val_eq_nat (ω : Bool × Bool × Bool) (S : Finset (Fin 5)) : ∑ i ∈ S, knapsack5_principal_val ω i = ((∑ i ∈ S, knapsack5_expected_offline_opt_eq_principal_val_nat ω i : ℕ) : ℝ) := by rw [Nat.cast_sum] exact Finset.sum_congr rfl (fun i _ => knapsack5_expected_offline_opt_eq_principal_val_eq_nat ω i)lemma knapsack5_expected_offline_opt_eq_sSup_eq (ω : Bool × Bool × Bool) : sSup {r : ℝ | ∃ S : Finset (Fin 5), knapsack5_feasible S ∧ r = ∑ i ∈ S, knapsack5_principal_val ω i} = (knapsack5_expected_offline_opt_eq_opt_val_nat ω : ℝ) := by let s := {r : ℝ | ∃ S : Finset (Fin 5), knapsack5_feasible S ∧ r = ∑ i ∈ S, knapsack5_principal_val ω i} have hmem : (knapsack5_expected_offline_opt_eq_opt_val_nat ω : ℝ) ∈ s := by obtain ⟨S, hS, hval⟩ := knapsack5_expected_offline_opt_eq_nat_exists_opt ω refine ⟨S, hS, ?_⟩ rw [knapsack5_expected_offline_opt_eq_sum_val_eq_nat, hval] have hub : ∀ r ∈ s, r ≤ (knapsack5_expected_offline_opt_eq_opt_val_nat ω : ℝ) := by rintro r ⟨S, hS, rfl⟩ rw [knapsack5_expected_offline_opt_eq_sum_val_eq_nat] exact Nat.cast_le.mpr (knapsack5_expected_offline_opt_eq_nat_le_opt ω S hS) have hne : s.Nonempty := ⟨_, hmem⟩ have hbdd : BddAbove s := ⟨_, hub⟩ exact le_antisymm (csSup_le hne hub) (le_csSup hbdd hmem)lemma knapsack5_expected_offline_opt_eq_sum_bool (g : Bool → ℝ) : ∑ x : Bool, g x = g true + g false := by have : (Finset.univ : Finset Bool) = {true, false} := Fintype.univ_bool rw [this] exact Finset.sum_pair (by decide)lemma knapsack5_expected_offline_opt_eq_sum_bool3 (f : Bool × Bool × Bool → ℝ) : ∑ ω : Bool × Bool × Bool, f ω = f (true, true, true) + f (true, true, false) + f (true, false, true) + f (true, false, false) + f (false, true, true) + f (false, true, false) + f (false, false, true) + f (false, false, false) := by rw [Fintype.sum_prod_type] simp_rw [Fintype.sum_prod_type, knapsack5_expected_offline_opt_eq_sum_bool] ring/-- Exact value of the expected offline optimum. -/theorem knapsack5_expected_offline_opt_eq : knapsack5_expected_offline_opt = 1011 / 50 := by unfold knapsack5_expected_offline_opt simp_rw [knapsack5_expected_offline_opt_eq_sSup_eq] rw [knapsack5_expected_offline_opt_eq_sum_bool3] unfold knapsack5_prob knapsack5_expected_offline_opt_eq_opt_val_nat norm_num