Lexicographic order on Nat-valued profiles #
Lexicographic comparison on lists / functions to ℕ (LexLE): a total
preorder on List Nat and a LinearOrder on the fixed-length
Lex (Fin n → Nat). (The subset-inclusion order on satisfied criteria
lives at Preorder.ofCriteria in Core/Order/OfCriteria.lean.)
Architecture #
LexLE, LexLT are decidable Prop relations defined by
structural recursion, delegating to standard combinators
(And.decidable, Or.decidable). LexMinProblem C n packages a finite
candidate set with a Fin n → Nat-valued score, exposing the
non-empty lex-min set via Finset.exists_min_image.
Algebraic structure — ordered additive monoid #
Lex (Fin n → Nat) carries:
AddCommMonoid— componentwise addition.LinearOrder— the lex order.IsOrderedAddMonoid— additive monotonicity: adding the same vector to both sides preserves the lex order.IsOrderedCancelAddMonoid— strict version of the above.
Together these say: Lex (Fin n → Nat) is a standard mathlib ordered
commutative monoid. Equivalently, the tropical (min-plus) semiring
view via Mathlib.Algebra.Tropical.Basic.
Variable-length vs fixed-length #
Variable-length (LexNatList): wraps List Nat with Preorder
instances. Weakest correct structure — LexLE on variable-length lists
is a preorder but not a partial order (trailing-zero ambiguity).
Fixed-length (Lex (Fin n → Nat), accessed as LexProfile Nat n):
full LinearOrder (lex). Fixing the length eliminates trailing-zero
ambiguity, upgrading LexLE to a linear order. LexMinProblem C n
always has a non-empty lex-min set via Finset.exists_min_image.
Connection to SatisfactionOrdering #
Core.Order.SatisfactionOrdering is the binary case
(0/≥ 1 interpreted as "satisfied" / "not") with subset-inclusion
comparison.
Lexicographic ≤ on List Nat (interpretable as cost vectors).
LexLE a b holds iff a is below b at the first position where they differ.
Trailing entries are implicitly 0.
Equations
- Core.Optimization.Evaluation.LexLE [] x✝ = True
- Core.Optimization.Evaluation.LexLE (a :: as) [] = (a = 0 ∧ Core.Optimization.Evaluation.LexLE as [])
- Core.Optimization.Evaluation.LexLE (a :: as) (b :: bs) = (a < b ∨ a = b ∧ Core.Optimization.Evaluation.LexLE as bs)
Instances For
Strict lexicographic <.
Equations
Instances For
Equations
- Core.Optimization.Evaluation.instDecidableLexLE [] x✝ = isTrue ⋯
- Core.Optimization.Evaluation.instDecidableLexLE (a :: as) [] = Core.Optimization.Evaluation.instDecidableLexLE._aux_1 a as (Core.Optimization.Evaluation.instDecidableLexLE as [])
- Core.Optimization.Evaluation.instDecidableLexLE (a :: as) (b :: bs) = Core.Optimization.Evaluation.instDecidableLexLE._aux_3 a as b bs (Core.Optimization.Evaluation.instDecidableLexLE as bs)
Lexicographic ≤ is reflexive.
Lexicographic ≤ is total for equal-length profiles.
LexLE [] b holds for any b: the empty list is vacuously
at-most-as-large-as any list.
Characterization of LexLE (x :: xs) []: all entries must be zero.
Pi.Lex over Fin (n+1) decomposes at index 0 (head-then-tail).
The decidable variable-length LexLE on List.ofFn agrees with the
fixed-length lexicographic order toLex on Fin n → Nat (= LexProfile Nat n) — the finite-tuple analogue of mathlib's MonomialOrder.lex (we keep
this bespoke computable order because mathlib's is noncomputable and
Finsupp-based). This is the bridge that lets a directional constraint be
spliced into a fixed-length profile as a position-block and still compare under
the canonical lex EVAL ([eisner-2000]/[lamont-2022b]).
Lexicographic ≤ is transitive. Together with lexLE_refl and
lexLE_total, this makes LexLE a total preorder on
equal-length profiles — the correct algebraic structure for
lex order.
Lexicographic < is irreflexive.
Lexicographic ≤ is antisymmetric on equal-length profiles: if two profiles of the same length are mutually ≤, they are equal.
This fails on List Nat in general (LexLE [] [0] and LexLE [0] []
both hold, but [] ≠ [0]) — the equal-length precondition eliminates
the trailing-zero ambiguity that makes LexLE merely a preorder.
A non-empty list has a minimum element under LexLE, provided all
profiles have equal length. This is the key ingredient for
optimal_nonempty: the lex-min set is non-empty.
List Nat wrapped to carry the LexLE-Preorder instance.
The bare List Nat doesn't carry a Preorder from LexLE (mathlib
leaves it ambiguous); this thin wrapper provides one. Only a
Preorder — not a PartialOrder — since trailing zeros are invisible
(LexLE [] [0] and LexLE [0] [] both hold). For a LinearOrder,
use fixed-length Lex (Fin n → Nat) (aka LexProfile Nat n).
- value : List ℕ
Instances For
Equations
- Core.Optimization.Evaluation.instDecidableEqLexNatList.decEq { value := a } { value := b } = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- Core.Optimization.Evaluation.instLELexNatList = { le := fun (a b : Core.Optimization.Evaluation.LexNatList) => Core.Optimization.Evaluation.LexLE a.value b.value }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- Core.Optimization.Evaluation.instDecidableLtLexNatList a b = instDecidableAnd
LexNatList.≤ is definitionally LexLE.
LexNatList.< is definitionally LexLT.
LexLE is total on equal-length values, expressed via LexNatList.
Pointwise addition on Lex (Fin n → Nat) reduces componentwise.
The zero Lex (Fin n → Nat) is pointwise zero.
Equations
- One or more equations did not get rendered due to their size.
Lex (Fin n → Nat) is an ordered additive commutative monoid:
componentwise addition preserves the lexicographic ordering. The
proof transfers the lex existential witness: if a < b at position
i with all earlier positions equal, then a + c < b + c at the
same position.
Left cancellation for lexicographic ≤.
Bridge: lexFinNatLE agrees with ≤ on Lex (Fin n → Nat).
Lexicographic ≤ as "no uncompensated inversion": toLex A ≤ toLex B holds
iff every coordinate where A strictly exceeds B is preceded (in index order)
by one where A is strictly below B. Stated for any linearly-ordered codomain;
used to ground OT's ERC satisfaction in the lex order.
Decidable ≤ on Lex (Fin n → Nat). The LinearOrder from Pi.Lex
is noncomputable, but this instance provides decidable comparison via
the recursive lexFinNatLE, making downstream by decide work.
Equations
- Core.Optimization.Evaluation.instDecidableLexFinNatProfileLE a b = decidable_of_iff (Core.Optimization.Evaluation.lexFinNatLE✝ n a b) ⋯
Decidable < on Lex (Fin n → Nat).
Equations
- Core.Optimization.Evaluation.instDecidableLexFinNatProfileLT a b = decidable_of_iff (¬b ≤ a) ⋯
Lexicographic order is decided at the first differing coordinate: A ≤ B iff at
the least index where they differ — when one exists — A is smaller. (Candidate for
mathlib's Pi.Lex API.)
Build a Lex (Fin n → Nat) from n atom-wise evaluation functions.
Given atoms as Fin n → C → Nat, produce the lex-comparable
fixed-length vector for c : C.
Equations
- Core.Optimization.Evaluation.lexFinNatOf atoms c = toLex fun (i : Fin n) => atoms i c
Instances For
WithTop (Lex (Fin n → Nat)) is a LinearOrderedAddCommMonoidWithTop:
it extends the ordered cancel monoid with an absorbing top element.
Prerequisite for the tropical semiring: mathlib's Tropical wrapper
then provides CommSemiring automatically.
Equations
- One or more equations did not get rendered due to their size.
The elements of s whose image under f is r-minimal — r-below every
image in s. The shared selection primitive behind LexMinProblem.lexMins
(over ≤ on Lex (Fin n → Nat)) and the variable-length LexLE-minimization
used by the prosodic/list-lex consumers.
Equations
- Core.Optimization.Evaluation.argMinSet s f r = {c ∈ s | ∀ d ∈ s, r (f c) (f d)}
Instances For
A minimizer's image bounds every image in s.
Minimizer-hood factors through the image, so it transports along image equality.
An element whose image is the bottom minimizes.
The minimizer set is the singleton {m} iff m strictly minimizes.
A finite candidate set C with a Fin n → Nat-valued score and a
nonemptiness witness. The lex-min set is nonempty
(exists_lexMin), computable (lexMins), and accessible via the
IsLexMin predicate.
- candidates : Finset C
- profile : C → Lex (Fin n → ℕ)
- nonempty : self.candidates.Nonempty
Instances For
A candidate is a lex-minimizer iff it's in the candidate set and its score is ≤ every other candidate's score.
Equations
- t.IsLexMin c = (c ∈ t.candidates ∧ ∀ c' ∈ t.candidates, t.profile c ≤ t.profile c')
Instances For
Every problem has a lex-minimizer. Delegates to
Finset.exists_min_image — the linear-ordered image of a nonempty
finset has a minimum.
The set of lex-minimizers, as an argMinSet over ≤. Computable via
instDecidableLexFinNatProfileLE; consumers can use by decide to verify
lex-mins on concrete problems.
Equations
- t.lexMins = Core.Optimization.Evaluation.argMinSet t.candidates t.profile fun (x1 x2 : Lex (Fin n → ℕ)) => x1 ≤ x2
Instances For
The lex-min set is always nonempty.
Lex-minimizers belong to the candidate set.
Check a Bool predicate for all elements of a Finset. Computable via
Finset.decidableBAll — avoids noncomputable Finset.toList.
Equations
- Core.Optimization.Evaluation.Finset.checkAll s p = decide (∀ c ∈ s, p c = true)
Instances For
Check a Bool predicate for some element of a Finset.
Equations
- Core.Optimization.Evaluation.Finset.checkAny s p = decide (∃ c ∈ s, p c = true)
Instances For
If a ≤ b lex-wise, then their first components satisfy
a 0 ≤ b 0.