AFTD Auto-Formalizing Theoretical Domains

List.foldl_max_ge

theoremverifiedformalizationimported Lean

foldl_max_ge: every element's f-image is ≤ that of the running maximizer kept by the left fold. The induction generalizes the accumulator.

Statement

set_option autoImplicit true in
set_option relaxedAutoImplicit true in
variable {X Y : Type*} in
theorem List.foldl_max_ge [TotalPreorder Y] [DecidableLE Y] (f : X → Y) :
    ∀ (l : List X) (acc : X), ∀ x ∈ acc :: l,
      f x ≤ f (l.foldl (fun a z => if f a ≤ f z then z else a) acc)
Formalizes
EconCSLib, `List.foldl_max_ge`
Lean proof
By xbei (from the file's git history), from github.com/gametheoryinlean/EconCSLib at 1a88f809b538 (Copyright (c) 2026 EconCSLib contributors. All rights reserved, Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.30.0.
Verified
08 Oct 2026
Axioms
propext
Built on 1
  • TotalPreorderA total preorder: a preorder where ≤ is total (complete). This is weaker than LinearOrder — it does NOT require antisymmetry or…
Used by 1
  • List.argMaxOn_geSoundness: every element's f-image is ≤ the chosen maximizer's.

Lean source view module on GitHub

set_option autoImplicit true inset_option relaxedAutoImplicit true invariable {X Y : Type*} in/-- `foldl_max_ge`: every element's `f`-image is `≤` that of the running maximizer kept by the left fold. The induction generalizes the accumulator. -/theorem List.foldl_max_ge [TotalPreorder Y] [DecidableLE Y] (f : X → Y) :    ∀ (l : List X) (acc : X), ∀ x ∈ acc :: l,      f x ≤ f (l.foldl (fun a z => if f a ≤ f z then z else a) acc) := by  intro l  induction l with  | nil =>      intro acc x hx      rw [List.mem_singleton] at hx      subst hx      exact le_refl _  | cons y ys ih =>      intro acc x hx      rw [List.foldl_cons]      by_cases h : f acc ≤ f y      · rw [if_pos h]        rcases List.mem_cons.mp hx with rfl | hx'        · exact le_trans h (ih y y List.mem_cons_self)        · exact ih y x hx'      · rw [if_neg h]        have hy : f y ≤ f acc := by          rcases TotalPreorder.le_total (f y) (f acc) with hle | hle          · exact hle          · exact absurd hle h        rcases List.mem_cons.mp hx with heq | hx'        · rw [heq]; exact ih acc acc List.mem_cons_self        · rcases List.mem_cons.mp hx' with rfl | hx''          · exact le_trans hy (ih acc acc List.mem_cons_self)          · exact ih acc x (List.mem_cons.mpr (Or.inr hx''))
See it in the graphDiscuss this resultChallenge it