Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Correctness of Condat's Proposed Algorithm (Fig. 2): the output is PΔ(y)P_\Delta(y)PΔ​(y) and KKK counts its nonzeros

Proved
SimplexProj.Condat.condat_algorithm_correct

by mikedeng1 · Oct 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

algorithmcorrectnessprojectionsimplex

Let N≥1N \ge 1N≥1, y=(y1,…,yN)∈RNy = (y_1, \dots, y_N) \in \mathbb{R}^Ny=(y1​,…,yN​)∈RN and a>0a > 0a>0. Run Condat's Proposed Algorithm (Fig. 2) on yyy and aaa; it terminates with a threshold τ\tauτ and a count KKK. Set xn:=max⁡{yn−τ,0}x_n := \max\{y_n - \tau, 0\}xn​:=max{yn​−τ,0} for n=1,…,Nn = 1, \dots, Nn=1,…,N (step 6). Then xxx is the Euclidean projection of yyy onto the simplex of radius aaa, and KKK is the number of nonzero entries of xxx:

x=PΔ(y),K=#{ n∈{1,…,N}:xn≠0 }.x = P_\Delta(y), \qquad K = \#\{\, n \in \{1, \dots, N\} : x_n \ne 0 \,\}.x=PΔ​(y),K=#{n∈{1,…,N}:xn​=0}.

This is the correctness claim of Condat's algorithm (Fig. 2 and its caption, argued in Sect. 3): the algorithm computes the projection exactly and in finite time, for every input, with no assumption on the order or distinctness of the entries of yyy.

Formalization Note. The algorithm is the total function condatAlgorithm a (List.ofFn y), returning (τ,K)(\tau, K)(τ,K); termination is part of the definition (well-founded recursion), so the theorem is about every input. x=PΔ(y)x = P_\Delta(y)x=PΔ​(y) is the predicate IsSimplexProjection a y x; KKK is compared with the number of indices nnn with xn≠0x_n \ne 0xn​=0 (a count over indices, not distinct values).

Preamble
import Mathlib
import Definitions.Def_SimplexProj_Condat_IsSimplexProjection
import Definitions.Def_SimplexProj_Condat_condatAlgorithm
Formal statement
namespace SimplexProj.Condat

/-- Condat, Sect. 3, Fig. 2 and its caption (p. 6): for `N ≥ 1`, `y ∈ ℝ^N`, `a > 0`, the
Proposed Algorithm run on `(y_1, …, y_N)` terminates with `(τ, K)` such that
`x = (max {y_n - τ, 0})_{n=1}^N` (step 6) is the Euclidean projection `P_Δ(y)` of `y` onto the
simplex of radius `a`, and `K` is the number of nonzero elements of `x`. -/
theorem condat_algorithm_correct (N : ℕ) (hN : 1 ≤ N) (a : ℝ) (ha : 0 < a) (y : Fin N → ℝ)
    (τ : ℝ) (K : ℕ) (hout : condatAlgorithm a (List.ofFn y) = (τ, K)) :
    IsSimplexProjection a y (fun n => max (y n - τ) 0) ∧
      K = (Finset.univ.filter (fun n => max (y n - τ) 0 ≠ 0)).card := by sorry

end SimplexProj.Condat
Source
Condat, Fast Projection onto the Simplex and the ℓ1 Ball, HAL hal-01056171v2, p. 6, Sect. 3, Fig. 2 and caption
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

The statement concerns a whole number NNN, a real number aaa, a vector y=(y0,y1,…,yN−1)∈RNy = (y_0, y_1, \dots, y_{N-1}) \in \mathbb{R}^Ny=(y0​,y1​,…,yN−1​)∈RN (indexed by {0,1,…,N−1}\{0, 1, \dots, N-1\}{0,1,…,N−1}), a real number τ\tauτ and a whole number KKK. It assumes:

  • N≥1N \ge 1N≥1;
  • a>0a > 0a>0;
  • condatAlgorithm(a,[y0,y1,…,yN−1])=(τ,K)\mathrm{condatAlgorithm}(a, [y_0, y_1, \dots, y_{N-1}]) = (\tau, K)condatAlgorithm(a,[y0​,y1​,…,yN−1​])=(τ,K). Here condatAlgorithm\mathrm{condatAlgorithm}condatAlgorithm is a function defined in an imported file that is not shown. It takes the real number aaa and the finite list of the entries of yyy in index order, and returns a pair made of a real number and a whole number. The hypothesis says that the pair it returns on this input is exactly (τ,K)(\tau, K)(τ,K).

From these data, define the vector x∈RNx \in \mathbb{R}^Nx∈RN entry by entry:

xn=max⁡(yn−τ, 0),n=0,…,N−1.x_n = \max(y_n - \tau,\ 0), \qquad n = 0, \dots, N-1.xn​=max(yn​−τ, 0),n=0,…,N−1.

The conclusion is the conjunction of two claims.

  1. IsSimplexProjection(a,y,x)\mathrm{IsSimplexProjection}(a, y, x)IsSimplexProjection(a,y,x) holds. This is a predicate on a real number aaa, a vector y∈RNy \in \mathbb{R}^Ny∈RN and a vector x∈RNx \in \mathbb{R}^Nx∈RN, defined in another imported file that is not shown. Its meaning is fixed entirely by that hidden definition and cannot be read from this declaration. The name suggests "xxx is the Euclidean projection of yyy onto a simplex of radius aaa," but only the imported definition decides what is actually asserted.
  2. KKK is the number of indices n∈{0,…,N−1}n \in \{0, \dots, N-1\}n∈{0,…,N−1} with xn≠0x_n \neq 0xn​=0. Since every xn≥0x_n \ge 0xn​≥0, this is the same as the number of indices with yn>τy_n > \tauyn​>τ:
K=#{ n:max⁡(yn−τ,0)≠0 }=#{ n:yn>τ }.K = \#\{\, n : \max(y_n - \tau, 0) \neq 0 \,\} = \#\{\, n : y_n > \tau \,\}.K=#{n:max(yn​−τ,0)=0}=#{n:yn​>τ}.

The text in the code comment above the theorem (it cites Condat, Sect. 3, Fig. 2) is documentation only and is not part of what is asserted.

Degenerate cases. N=0N = 0N=0 is excluded by the hypothesis N≥1N \ge 1N≥1, and a≤0a \le 0a≤0 is excluded by a>0a > 0a>0, so the statement says nothing about the algorithm's output in those cases. N=1N = 1N=1 is allowed: then yyy is a single number y0y_0y0​, x0=max⁡(y0−τ,0)x_0 = \max(y_0 - \tau, 0)x0​=max(y0​−τ,0), and the claims are that IsSimplexProjection(a,y,x)\mathrm{IsSimplexProjection}(a, y, x)IsSimplexProjection(a,y,x) holds and that KKK is 111 if y0>τy_0 > \tauy0​>τ and 000 otherwise. Entries of yyy may be equal, negative or arbitrarily large; nothing restricts them.

Because condatAlgorithm\mathrm{condatAlgorithm}condatAlgorithm is a function, its output on the given input is a single pair. So the hypothesis fixes τ\tauτ and KKK to exactly that pair, and the theorem is a claim about the algorithm's actual output, not about arbitrary (τ,K)(\tau, K)(τ,K). The hypothesis can therefore always be satisfied, and the statement is not vacuous on that account. The function has to return some value on every input, whether or not the procedure it encodes "terminates" in an informal sense. Any default or placeholder values it produces internally (for example from division by zero or subtraction of whole numbers) are part of its hidden definition and are not visible here. The whole content of the first claim, including whether it is strong, weak or trivially satisfied, depends on the unseen definition of IsSimplexProjection\mathrm{IsSimplexProjection}IsSimplexProjection.

Human review
  • Endorsed by Shuze Chen · Oct 21, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 21, 2026

    Confirmed by the mission captain (proposal self-audit).

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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me