AFTD Auto-Formalizing Theoretical Domains

candidate_rank

def

Given a finite candidate type C with decidable equality, a linear order ord on C, and a candidate c in C, candidate_rank ord c is the 0-based index of c in Fin (Fintype.card C), defined as the number of candidates strictly greater than c under ord.

Statement

def candidate_rank {C : Type*} [Fintype C] [DecidableEq C]
    (ord : LinearOrder C) (c : C) : Fin (Fintype.card C)
Defined in
arXiv:2610.26535 Definition 2
Verified
24 Oct 2026
Axioms
none listed
Built on 2
  • TotalPreorderA total preorder: a preorder where ≤ is total (complete). This is weaker than LinearOrder — it does NOT require antisymmetry or…
  • LinearOrder.toTotalPreorderEvery LinearOrder is a TotalPreorder.
Used by 3

Read back from the Lean

Given a finite type C with decidable equality, a linear order ord on C, and an element c : C, candidate_rank is defined as the element of Fin (Fintype.card C) whose underlying value is the number of elements c' : C strictly greater than c with respect to ord (i.e., #{c' : C | c < c'}). (Consequently, the maximum element has rank 0 and the minimum element has rank Fintype.card C - 1.)

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

Lean source view module on GitHub

/-- The 0-based rank of candidate c in a linear order on candidates C, given by the number of candidates strictly preferred to c. -/
def candidate_rank {C : Type*} [Fintype C] [DecidableEq C]
    (ord : LinearOrder C) (c : C) : Fin (Fintype.card C) :=
  letI := ord
  have h_not : c ∉ Finset.filter (fun c' => c < c') Finset.univ := by simp
  have h_ssubset : Finset.filter (fun c' => c < c') Finset.univ ⊂ Finset.univ := by
    rw [Finset.ssubset_univ_iff]
    intro h_all
    have : c ∈ Finset.filter (fun c' => c < c') Finset.univ := by rw [h_all]; exact Finset.mem_univ c
    exact h_not this
  ⟨(Finset.filter (fun c' => c < c') Finset.univ).card, Finset.card_lt_card h_ssubset⟩
See it in the graphDiscuss this resultChallenge it