AFTD Auto-Formalizing Theoretical Domains

List.foldl_max_mem

theoremverifiedformalizationimported Lean

foldl_max_mem: the running maximizer kept by the left fold lies in the candidate list acc :: l.

Statement

set_option autoImplicit true in
set_option relaxedAutoImplicit true in
variable {X Y : Type*} in
theorem List.foldl_max_mem [LE Y] [DecidableLE Y] (f : X → Y) :
    ∀ (l : List X) (acc : X),
      l.foldl (fun a z => if f a ≤ f z then z else a) acc ∈ acc :: l
Formalizes
EconCSLib, `List.foldl_max_mem`
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
Used by 1

Lean source view module on GitHub

set_option autoImplicit true inset_option relaxedAutoImplicit true invariable {X Y : Type*} in/-- `foldl_max_mem`: the running maximizer kept by the left fold lies in the candidate list `acc :: l`. -/theorem List.foldl_max_mem [LE Y] [DecidableLE Y] (f : X → Y) :    ∀ (l : List X) (acc : X),      l.foldl (fun a z => if f a ≤ f z then z else a) acc ∈ acc :: l := by  intro l  induction l with  | nil => intro acc; simp  | cons y ys ih =>      intro acc      rw [List.foldl_cons]      by_cases h : f acc ≤ f y      · rw [if_pos h]        exact List.mem_cons_of_mem acc (ih y)      · rw [if_neg h]        rcases List.mem_cons.mp (ih acc) with hr | hr        · rw [hr]; exact List.mem_cons_self        · exact List.mem_cons_of_mem acc (List.mem_cons_of_mem y hr)
See it in the graphDiscuss this resultChallenge it