//! [`ClosedSet`] — the typed witness for the closed-set-enum idiom.
//!
//! The substrate carries 36+ closed-set enums (`AtomKind`,
//! `QuoteForm`, `SexpShape`, `MacroDefHead`, `UnquoteForm`,
//! `KwargPathKind`, `ExpectedKwargShape`, `CompilerSpecIoStage` in
//! this crate; `ProcessPhase`, `ConditionKind`, `IntentKind`,
//! `LifetimeKind`, `TeardownPolicy`, `ProcessSignal`,
//! `ArtifactKind`, `ReportFormat`, `ChannelKind`, `ExportTrigger`,
//! `ReceiptKind`, `RequestorKind`, `SelectStrategyKind`,
//! `EncapsulationMode`, `EncapsulationTarget`, `DataClassification`,
//! `AllocationPhase`, `CalmClassification`, `OptimizationDirection`,
//! `HorizonKind`, `SubstrateType`, `ConvergencePointType`,
//! `MemberState`, `PoolPhase`,
//! `ReplacementPolicy`, `ReturnPolicy`, `AutoTerminateKind`,
//! `TerminateReasonKind`,
//! `VerificationPhase`, `WorkloadKind`, `MustReachPhase`,
//! `SighupStrategy`, `BreatheDimensionKind`, `MatrixTarget`,
//! `ReportPayloadShape`, … in `tatara-process`). Each one independently
//! re-derives the same four-piece shape:
//!
//! 1. `pub const ALL: [Self; N] = [...]` — the forced-arity array
//! literal that fails compilation if a new variant lands without
//! being added to the set.
//! 2. `fn label(self) -> &'static str` (or its domain-canonical
//! sibling — `prefix`, `marker`, `keyword`, `as_str`) — the typed
//! projection from variant to the canonical `&'static str` literal
//! the diagnostic / wire format uses.
//! 3. `impl FromStr` whose body is a linear sweep over `Self::ALL`
//! keyed on the projection — exactly the same 6-line for-loop /
//! `Err(Unknown<TypeName>(s.to_owned()))` shape every implementor
//! re-derives byte-for-byte.
//! 4. `pub struct Unknown<TypeName>(pub String)` with
//! `#[error("unknown <thing>: {0}")]` — the typed parse-rejection
//! carrier that hands the offending input back unchanged.
//!
//! Pieces 1, 2, 4 carry per-variant content (the variants themselves,
//! their canonical labels, the rejection-class wording) and stay
//! per-implementor. Piece 3 — the for-loop sweep — is mechanically
//! identical across every implementor and is the duplication this
//! trait lifts.
//!
//! ## Trait surface
//!
//! ```text
//! pub trait ClosedSet: Sized + Copy {
//! const ALL: &'static [Self];
//! type Unknown;
//! fn label(self) -> &'static str;
//! fn make_unknown(s: &str) -> Self::Unknown;
//!
//! // Default — the lifted for-loop body.
//! fn parse_label(s: &str) -> Result<Self, Self::Unknown> { ... }
//! }
//! ```
//!
//! A typical implementor wires in three lines beyond its existing
//! inherent surface, and its hand-rolled `FromStr` body collapses
//! from six lines to one:
//!
//! ```text
//! impl ClosedSet for AtomKind {
//! const ALL: &'static [Self] = &Self::ALL;
//! type Unknown = UnknownAtomKind;
//! fn label(self) -> &'static str { AtomKind::label(self) }
//! fn make_unknown(s: &str) -> Self::Unknown { UnknownAtomKind(s.to_owned()) }
//! }
//!
//! impl FromStr for AtomKind {
//! type Err = UnknownAtomKind;
//! fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
//! <Self as ClosedSet>::parse_label(s)
//! }
//! }
//! ```
//!
//! Implementors with a non-`label` inherent projection name
//! (`QuoteForm::prefix`, `UnquoteForm::marker`, `MacroDefHead::keyword`,
//! `tatara_process`'s `*::as_str`) delegate `ClosedSet::label` to
//! their domain-canonical method — the trait method gives every
//! implementor a STABLE name (`label`), with the inherent name kept as
//! the load-bearing domain-vocabulary projection (`prefix` for
//! homoiconic reader-form, `marker` for template-substitution
//! punctuation, `keyword` for macro-head reserved word, `as_str` for
//! `tatara-process`'s PascalCase wire format).
//!
//! ## Theory grounding
//!
//! THEORY.md §V.1 — knowable platform; the for-loop / `Unknown`-
//! emission pattern was a known idiom carried by convention across 36+
//! implementors. This trait makes the idiom a TYPED WITNESS — any new
//! closed-set enum that implements `ClosedSet` plugs into the trait's
//! default `parse_label` and a future generic consumer (a metrics
//! tagger, a Lisp keyword completer, an iac-forge canonical-form
//! renderer over closed-set kinds) can take a `T: ClosedSet`
//! parameter and walk the set without knowing which crate it lives in.
//!
//! THEORY.md §VI.1 — generation over composition; the trait IS the
//! generative shape. New closed-set enums add the trait impl + the
//! one-line FromStr delegation instead of re-deriving the for-loop
//! body, and the parse-rejection diagnostic surface narrows from "36+
//! independent sweeps that must each be kept symmetric" to "one
//! default body, 36+ impls of a four-method contract."
//!
//! # Provenance
//!
//! This crate is `pleme-io/tatara`'s `tatara-lisp/src/closed_set.rs` moved
//! verbatim, per `theory/TATARA-LISP-CONSOLIDATION.md` phase 2 step 1.
//! `tatara-lisp` neither carries nor re-exports `ClosedSet`, which keeps the
//! published `tatara-lisp` small enough for the phase-3 facade.
//!
//! **That property is a CONVENTION, not a structural guarantee — read this
//! before assuming otherwise.** Step 1 landed with the edge pointing
//! `tatara-closed-set → tatara-lisp` (for `domain::suggest`) and celebrated
//! the resulting cycle as the enforcement mechanism: the reverse edge "cannot
//! be written". That framing was load-bearing and is now false. Step 2 needs
//! `tatara-lisp` to carry the ~45 `LispError` variants whose payloads are
//! `ClosedSet` implementors, which requires exactly that reverse edge, so
//! phase 2 was structurally blocked by its own step 1.
//!
//! The edge was therefore INVERTED (patamar's cheapest verb, chosen on an
//! edge census of **one**): `suggest` moved here, `tatara-closed-set` dropped
//! its `tatara-lisp` dependency and became a true leaf, and `tatara-lisp`
//! now depends on this crate. The metric was never a `tatara-lisp` primitive
//! to begin with — step 1 pulled it forward from A *because closed-set needed
//! it*, and it had zero other callers in this workspace, so inverting put it
//! back with its only consumer rather than moving it away from callers.
//!
//! Consequence to respect: nothing now makes `tatara-lisp` re-exporting
//! `ClosedSet` a compile error. Keeping it out is a review-time rule.
//!
//! The trait body is byte-identical to its pre-split form apart from
//! `crate::domain::suggest` → `tatara_lisp::domain::suggest` and the
//! doc-links that pointed at sibling modules which stayed in `tatara-lisp`.
//! Nothing about the wire surface (`label` / `parse_label` / the
//! `"unknown {SET_LABEL}: {input}"` carrier rendering) was reshaped — the
//! implementors serialize Kubernetes CRD state through it.
// `#[derive(ClosedSet)]` proc-macro — same name as the trait, different
// namespace (proc-macros vs. types), so they coexist cleanly under one
// import. Mirrors A's `pub use tatara_lisp_derive::ClosedSet as
// DeriveClosedSet` re-export, so a consumer switching crates changes the
// import path and nothing else.
pub use tatara_closed_set_derive::ClosedSet as DeriveClosedSet;
// ── Near-match suggestion ──────────────────────────────────────────
//
// Homed here because this crate is its only consumer. Phase 2 step 1 pulled
// it forward from A's `tatara-lisp/src/domain.rs:983-1073` into `tatara-lisp`
// specifically so `suggest_closest` could compose it, which created the
// `tatara-closed-set → tatara-lisp` edge that then blocked step 2. It had no
// other caller in `tatara-lisp`, so the INVERT is a relocation to its only
// call site, not a move away from callers.
//
// `tatara-lisp` re-exports `suggest` from here, so `tatara_lisp::domain::suggest`
// still resolves for A-side parity and for step 3's `unknown_kwarg` hint.
/// Suggest the candidate closest to `needle` by Levenshtein distance,
/// when the closest candidate is within a bounded edit distance.
///
/// The bound scales with `needle`'s character length:
/// - len ≤ 3: bound 1 (single-character typo on a short identifier)
/// - len ≤ 7: bound 2 (insertion + transposition, two typos)
/// - len ≥ 8: bound 3 (longer identifiers absorb more drift)
///
/// Returns the closest candidate within the bound. Ties are broken
/// lexicographically so two operators on two machines see the same hint
/// for the same input — diagnostics are deterministic. An exact match in
/// `candidates` is excluded (the caller already has the keyword; the
/// suggestion exists for near-misses only). Empty `candidates` returns
/// `None`.
///
/// One named primitive lifts the substrate's understanding of "near-match
/// across a candidate set" out of any per-call-site implementation. The
/// unknown-kwarg diagnostic in `reject_unknown_kwargs` is the first
/// consumer; future consumers — `LispError::HeadMismatch`'s "did you
/// mean a registered domain?" hint, `tatara-check`'s registry-dispatch
/// suggestions, the LSP's completion-failure fallback — bind to one
/// helper rather than re-implementing edit distance.
///
/// Theory anchor: THEORY.md §V.1 — "Knowable platform … Render Anywhere."
/// Naming the likely intended candidate is the floor of a constructive
/// diagnostic. THEORY.md §VI.1 — generation over composition: every
/// near-match suggestion in the substrate routes through ONE primitive.
///
/// Frontier inspiration: rustc's `find_best_match_for_name`, Idris's
/// "did you mean …?" elaborator hint, Roslyn's `SymbolMatcher` — bounded
/// edit distance over a symbol table. Translation through pleme-io
/// primitives: a pure function over `&[&str]`, no new error variant, no
/// new IR layer, no new dep.
#[must_use]
pub fn suggest<'a>(needle: &str, candidates: &[&'a str]) -> Option<&'a str> {
let bound = suggestion_bound(needle);
let mut best: Option<(usize, &'a str)> = None;
for &candidate in candidates {
if candidate == needle {
continue;
}
let dist = levenshtein(needle, candidate);
if dist > bound {
continue;
}
match best {
None => best = Some((dist, candidate)),
Some((bd, bc)) if dist < bd || (dist == bd && candidate < bc) => {
best = Some((dist, candidate));
}
_ => {}
}
}
best.map(|(_, c)| c)
}
fn suggestion_bound(needle: &str) -> usize {
let n = needle.chars().count();
if n <= 3 {
1
} else if n <= 7 {
2
} else {
3
}
}
/// Classic two-row Levenshtein. Operates on `char`s so multibyte input
/// (e.g. a domain authored with non-ASCII identifiers) measures
/// character-distance, not byte-distance.
fn levenshtein(a: &str, b: &str) -> usize {
let a: Vec<char> = a.chars().collect();
let b: Vec<char> = b.chars().collect();
if a.is_empty() {
return b.len();
}
if b.is_empty() {
return a.len();
}
let mut prev: Vec<usize> = (0..=b.len()).collect();
let mut curr: Vec<usize> = vec![0; b.len() + 1];
for (i, ca) in a.iter().enumerate() {
curr[0] = i + 1;
for (j, cb) in b.iter().enumerate() {
let cost = usize::from(ca != cb);
curr[j + 1] = (prev[j + 1] + 1).min(curr[j] + 1).min(prev[j] + cost);
}
std::mem::swap(&mut prev, &mut curr);
}
prev[b.len()]
}
/// The closed-set-enum idiom as a typed witness.
///
/// Implementors carry an inherent `pub const ALL: [Self; N]` with a
/// forced-arity array literal so the compiler enforces variant /
/// cardinality coherence at the declaration; this trait re-exposes
/// the same data as a `&'static [Self]` slice so [`Self::parse_label`]
/// can iterate generically over `Self` without the inherent constant
/// being visible at the call site.
///
/// The default [`Self::parse_label`] is the substrate-wide for-loop
/// pattern lifted into ONE place. Every implementor's
/// [`std::str::FromStr::from_str`] body reduces to a single delegation
/// (`<Self as ClosedSet>::parse_label(s)`), and the per-implementor
/// `Unknown<TypeName>` carrier flows through [`Self::make_unknown`].
///
/// ## `#[derive(ClosedSet)]` proc-macro
///
/// The trait surface is hand-impl-friendly (four methods, no
/// associated types beyond `Unknown`); for implementors that follow
/// the substrate-wide naming convention the
/// [`#[derive(ClosedSet)]`](tatara_closed_set_derive::ClosedSet) proc-macro
/// (re-exported as [`crate::DeriveClosedSet`]) collapses the 4-line
/// `impl ClosedSet` + 4-line `impl FromStr` boilerplate onto ONE
/// derive line + a `#[closed_set(via = "<projection>")]` attribute
/// that names the inherent projection method:
///
/// ```ignore
/// #[derive(Clone, Copy, ..., tatara_closed_set::DeriveClosedSet)]
/// #[closed_set(via = "as_str")]
/// pub enum ChannelKind { HttpEvent, NatsSubject, Stdout }
///
/// impl ChannelKind {
/// pub const ALL: [Self; 3] = [Self::HttpEvent, Self::NatsSubject, Self::Stdout];
/// pub const fn as_str(self) -> &'static str { ... }
/// }
///
/// #[derive(Debug, thiserror::Error)]
/// #[error("unknown channel kind: {0}")]
/// pub struct UnknownChannelKind(pub String);
/// ```
///
/// The derive expects: `pub const ALL: [Self; N]`, an inherent
/// projection method whose name matches the `via` attribute
/// (defaults to `"label"`), and a struct named
/// `Unknown{EnumName}(pub String)` in the same module (overridable
/// via `#[closed_set(unknown = "...")]`). Bespoke `FromStr` shapes
/// (e.g. `tatara_lisp::error::CompilerSpecIoStage`'s compound
/// `"{operation}: {label}"` key) can suppress the generated
/// `FromStr` via `#[closed_set(no_from_str)]`.
///
/// Implementors that want the carrier ITSELF generated drop the
/// hand-rolled `pub struct UnknownX(pub String)` block and add
/// `#[closed_set(generate_unknown)]` — the derive then emits the
/// carrier with `Debug + Clone + PartialEq + Eq + thiserror::Error`
/// derives and the substrate-wide
/// `#[error("unknown <spaced-lowercase enum name>: {0}")]`
/// annotation (`ChannelKind` → "unknown channel kind: {0}",
/// `ReplacementPolicy` → "unknown replacement policy: {0}"). For
/// irregular labels (`MacroDefHead` → "macro definition head",
/// `MustReachPhase` → "must-reach phase") pin the operator-facing
/// wording with `#[closed_set(generate_unknown = "...")]`.
///
/// Implementors whose Display impl matches the substrate-wide
/// 5-line `f.write_str(self.<via>())` shape (28+ enums on the
/// PascalCase wire-format axis re-derive this byte-for-byte) drop
/// the hand-rolled `impl fmt::Display for X` block and add
/// `#[closed_set(display)]` — the derive then emits
/// `impl fmt::Display for X { f.write_str(Self::<via>(*self)) }`
/// alongside the trait impl, so the `<via> ⇄ Display ⇄ FromStr`
/// triad emits through ONE generative shape per enum. Implementors
/// with a bespoke Display body (e.g. structured-reason formatters
/// that compose more than the canonical wire label) keep their
/// hand-rolled block and leave the flag off.
pub trait ClosedSet: Sized + Copy + 'static {
/// The closed set — every variant the enum carries, in
/// declaration order. Implementors typically delegate to an
/// inherent `pub const ALL: [Self; N]` whose forced-arity array
/// literal pins the cardinality at the declaration site.
const ALL: &'static [Self];
/// The closed set's cardinality — the count of variants in
/// [`Self::ALL`], surfaced as a compile-time-known [`usize`] on
/// the trait so downstream generic code can bind to it in const
/// contexts ([`[T; N]`](array) dimensions,
/// [`Vec::with_capacity`](::std::vec::Vec::with_capacity) sizing,
/// bitset widths, per-variant lookup-table shapes) without
/// re-deriving `Self::ALL.len()` at every call site.
///
/// Default body is `Self::ALL.len()` — the count is a typed
/// CONSEQUENCE of the [`Self::ALL`] slice, not a second per-
/// implementor site the operator must keep in sync with the
/// variant listing. The `<[T]>::len` primitive is const-stable
/// (Rust 1.39+) so the projection evaluates at compile time on
/// every implementor whose inherent `pub const ALL: [Self; N]`
/// is itself a const array literal — the substrate-wide default
/// shape. Implementors override only when the cardinality surface
/// needs to diverge from [`Self::ALL`]'s natural length (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` overrides
/// exist — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl).
///
/// Sibling posture to [`Self::ALL`] on the (variant listing,
/// variant count) axis: [`Self::ALL`] is the [`&'static [Self]`](slice)
/// slice generic consumers iterate over, this const is the
/// [`usize`] count the same consumers reach for when they need a
/// compile-time-known dimension. The pair partitions the
/// (variant enumeration, cardinality) surface exhaustively — one
/// for iteration, one for const-generic bindings — with the
/// count derived from the listing at ONE substrate primitive
/// rather than at TWO independent per-implementor sites.
///
/// Future consumers — a compact-encoding wire format that
/// packs each variant into `ceil(log2(T::CARDINALITY))` bits, a
/// per-variant lookup table typed as `[Payload; T::CARDINALITY]`
/// whose length is verified at compile time against `T::ALL`, a
/// metrics tagger that pre-sizes a `Vec` for `T::CARDINALITY`
/// samples, a bitset over the closed-set indexed at
/// `T::CARDINALITY`-many positions — bind to ONE trait const
/// instead of hand-rolling the `Self::ALL.len()` composition at
/// each call site, and the closed-set projection's cardinality
/// surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the closed-set cardinality
/// becomes a TYPE-level projection on the trait rather than a
/// per-consumer inline `Self::ALL.len()` composition at every
/// downstream generic site. The (variant enumeration, cardinality)
/// pair partitions the closed-set surface exhaustively into TWO
/// typed projections, each with a distinct load-bearing consumer
/// surface — iteration for [`Self::ALL`], const-generic bindings
/// for this const.
/// THEORY.md §V.1 — knowable platform; the cardinality was an
/// unnamed inline projection (`T::ALL.len()`) recurring at 20+
/// test sites and every prospective const-generic consumer site
/// pre-lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of [`Self::ALL`] — generic consumers see ONE const,
/// not ONE inline-length-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the cardinality
/// emerges from the composition of ONE substrate primitive
/// ([`Self::ALL`]) with the standard-library const `<[T]>::len`
/// projection rather than as a per-implementor `const N: usize =
/// _` declaration. A future tightening of [`Self::ALL`] (a future
/// declaration-time cardinality assertion, a future
/// `#[closed_set(cardinality = N)]` derive attribute that pins
/// N at the source) propagates to every closed-set const-generic
/// consumer through ONE trait const.
///
/// Frontier inspiration: Idris's `Fin n` finite-cardinality type
/// exposes `n` at the type level so every downstream indexer /
/// enumerator binds to a compile-time count; Rust's
/// `std::mem::variant_count::<T>()` intrinsic (unstable, nightly-
/// only) exposes the same shape from the language side. MLIR's
/// `mlir::TypeAttrOfBase<TypeParam>::getMaxEnumValInternal` and
/// LLVM's `EnumAttrParams` similarly surface the enum's cardinality
/// as a first-class typed integer on the registry. Translation
/// through pleme-io primitives: a pure default associated const
/// initializer composing the trait's existing [`Self::ALL`] with
/// the const-stable `<[T]>::len` slice projection — no new dep,
/// no unstable intrinsic, no per-implementor override.
const CARDINALITY: usize = Self::ALL.len();
/// The substrate-wide spaced-lowercase NAME of the closed set —
/// the noun phrase the parse-rejection diagnostic threads into
/// `"unknown {SET_LABEL}: {input}"` and the typed companion the
/// trait exposes to generic consumers (metrics taggers, REPL /
/// LSP completion bars, exhaustive-listing renderers) that want
/// to name the set without re-deriving the projection at every
/// call site.
///
/// The substrate-wide convention pins this projection at TWO
/// sites pre-lift: (1) the auto-derived `pub struct
/// Unknown{EnumName}(pub String)` carrier's `#[error("unknown
/// <label>: {0}")]` annotation that
/// `#[closed_set(generate_unknown[ = "<label>"])]` emits, and
/// (2) per-implementor `_message_matches_substrate_convention`
/// test bodies that pin the rendered diagnostic byte-for-byte.
/// Lifting the label onto the trait means BOTH sites read from
/// ONE generative origin — the derive computes the label once,
/// emits it into the carrier's `#[error(...)]` annotation, AND
/// exposes it through this const so [`assert_closed_set_well_formed`]
/// can pin the rendered diagnostic shape generically through
/// the trait rather than through 33+ per-implementor literal
/// assertions.
///
/// Implementors auto-derive the projection from the PascalCase
/// enum name via the derive's `pascal_to_spaced_lowercase`
/// helper (`ChannelKind` → `"channel kind"`, `ReplacementPolicy`
/// → `"replacement policy"`); for irregular labels
/// (`MacroDefHead` → `"macro definition head"`, `MustReachPhase`
/// → `"must-reach phase"`) pin the operator-facing wording via
/// `#[closed_set(generate_unknown = "...")]` and the derive
/// threads the SAME label into both the carrier's `#[error(...)]`
/// annotation AND this const. An explicit
/// `#[closed_set(set_label = "...")]` override exists for the
/// degenerate case where an implementor wants to bind the
/// trait's set name independently of the carrier's diagnostic
/// label (no production implementor reaches for this today; the
/// axis exists for the same reason `via` does — a typed escape
/// hatch the derive surface exposes rather than forcing the
/// implementor to hand-roll the impl).
const SET_LABEL: &'static str;
/// The typed parse-rejection carrier this implementor emits when
/// [`Self::parse_label`] is handed a non-canonical input. The
/// substrate-wide convention is the
/// `pub struct UnknownX(pub String)` shape with a
/// `#[error("unknown <thing>: {0}")]` annotation, but the trait
/// does not require either — implementors are free to use a
/// richer carrier (a sum type, a structured diagnostic) as long
/// as it remains the `FromStr::Err` for the implementing type.
type Unknown;
/// Project the typed variant to its canonical `&'static str`
/// label — the projection [`Self::parse_label`] keys on.
///
/// Implementors with a domain-canonical inherent projection name
/// (`prefix` for `tatara_lisp::ast::QuoteForm`, `marker` for
/// `tatara_lisp::error::UnquoteForm`, `keyword` for
/// `tatara_lisp::error::MacroDefHead`, `as_str` across `tatara-process`'s
/// PascalCase wire-format enums) delegate this trait method to
/// their inherent method — the trait method gives generic
/// consumers a STABLE name (`label`) without renaming the
/// load-bearing domain vocabulary.
fn label(self) -> &'static str;
/// Wrap the offending input verbatim in the typed
/// parse-rejection carrier — the substrate-wide convention is
/// `Self::Unknown(s.to_owned())` for the `pub struct UnknownX(pub
/// String)` shape. The `&str` borrow (rather than `String`) lets
/// implementors that want to project the input through a
/// normalization step (a future structured diagnostic carrier
/// that records both the raw and the normalized form) do so
/// without forcing the trait surface to materialize an owned
/// `String` the implementor doesn't need.
fn make_unknown(s: &str) -> Self::Unknown;
/// Decode a canonical [`Self::label`] back into the typed variant
/// — `Ok(v)` when `s` matches some `v.label()` exactly, and
/// `Err(Self::make_unknown(s))` for every other string.
///
/// Linear sweep over [`Self::ALL`] keyed on [`Self::label`]. The
/// canonical literals live at ONE site (the implementor's
/// inherent projection) rather than at TWO (the projection PLUS
/// the per-variant `FromStr` arm pre-lift); adding a new variant
/// extends only `Self::ALL` + `Self::label`, NOT a third
/// per-variant literal site.
///
/// Default body composes [`Self::find_by_label`] with
/// [`Option::ok_or_else`] into [`Self::make_unknown`] — the sweep
/// itself lives at ONE substrate primitive
/// ([`Self::find_by_label`]), and the parse arm threads the
/// carrier materialization onto its `None` result. Implementors
/// override only when the parse surface shape diverges (e.g.
/// `tatara_lisp::error::CompilerSpecIoStage`'s compound
/// `"{operation}: {label}"` key, which keys on a projection PAIR
/// rather than a single label, and keeps its bespoke `FromStr`
/// body). An implementor that overrides [`Self::find_by_label`]
/// propagates the override through this default body to the
/// parse-decode arm automatically; the (allocating carrier
/// decode, non-allocating typed decode, non-allocating
/// predicate) triad of the closed-set surface funnels every
/// sweep through ONE typed primitive.
fn parse_label(s: &str) -> Result<Self, Self::Unknown> {
Self::find_by_label(s).ok_or_else(|| Self::make_unknown(s))
}
/// Zero-allocation typed decode — `Some(v)` when `s` matches some
/// variant's [`Self::label`] exactly, `None` for every other
/// string.
///
/// Peer of [`Self::parse_label`] on the (allocating carrier
/// decode, non-allocating typed decode) axis of the closed-set
/// surface: [`Self::parse_label`] materializes the typed
/// [`Self::Unknown`] carrier (owning a [`String`] copy of `s`)
/// on the reject path even when the caller drops it immediately
/// with `.ok()`; this method answers the SAME structural
/// question — "which canonical variant does `s` decode to, if
/// any?" — with a bare [`Option::None`] on rejection, never
/// entering [`Self::make_unknown`]. Consumers that need the
/// typed variant BUT can supply a natural default (a config
/// field with a fallback, an LSP hover under a candidate label,
/// a `filter_map` over a candidate stream that projects each
/// element onto its typed variant) route through this method
/// rather than paying the carrier allocation for the throwaway
/// diagnostic.
///
/// Sibling posture to [`Self::contains_label`] one axis over:
/// both walk [`Self::ALL`] keyed on [`Self::label`], but the
/// return-type axis partitions the consumer surface —
/// [`Self::contains_label`] returns a `bool` for the pure
/// predicate `if`-gates / `filter`-passes / lint checks route
/// through, this method returns the typed `Option<Self>` for
/// consumers that need the decoded variant. The two arms of the
/// axis compose: [`Self::contains_label`] is the default-body
/// projection of `Self::find_by_label(s).is_some()`, and
/// [`Self::parse_label`] is the default-body projection of
/// `Self::find_by_label(s).ok_or_else(|| Self::make_unknown(s))`
/// — every closed-set sweep threads through ONE primitive.
///
/// The (return-type × side-effect) cross-product of the
/// closed-set membership surface partitions exhaustively:
///
/// | Return | Allocating (materialize `Unknown`) | Non-Allocating |
/// |----------------------------|------------------------------------|-----------------------------|
/// | `Result<Self, Unknown>` | [`Self::parse_label`] | — |
/// | `Option<Self>` | — | [`Self::find_by_label`] |
/// | `bool` | — | [`Self::contains_label`] |
///
/// Default body is `Self::ALL.iter().copied().find(|v| v.label()
/// == s)` — a linear sweep composed from the same TWO substrate
/// primitives ([`Self::ALL`], [`Self::label`])
/// [`Self::parse_label`] and [`Self::contains_label`] would walk
/// over pre-lift, now lifted onto ONE trait body every consumer
/// routes through. Implementors override only when the typed-
/// decode surface needs to diverge from the natural
/// `ALL`-projection (no production implementor reaches for this
/// today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `labels_joined` /
/// `sorted_labels` / `sorted_labels_joined` / `suggest_closest` /
/// `parse_label_with_hint` / `contains_label` overrides exist —
/// a typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl).
///
/// Future consumers — a config-field decoder with a natural
/// fallback (`T::find_by_label(cfg).unwrap_or(T::default_kind())`)
/// that skips the throwaway Unknown allocation, a
/// `filter_map`-shaped stream projection over cluster-wide
/// `tatara.pleme.io/*` annotation keys, an LSP hover pass that
/// resolves the typed variant under the operator's cursor
/// WITHOUT allocating a carrier per non-matching hover, an
/// iac-forge tag decode-loop that partitions each incoming tag
/// stream into (typed_variant, bare_string) via
/// `find_by_label(tag).ok_or(tag)` — bind to ONE trait method
/// instead of hand-rolling either the `parse_label(s).ok()`
/// carrier-allocating shortcut (which pays the `String`
/// allocation on every reject) OR the inline
/// `Self::ALL.iter().copied().find(|v| v.label() == s)`
/// composition (which re-derives the sweep at every call site).
///
/// THEORY.md §III — the typescape; the zero-allocation typed
/// decode becomes a TYPE projection on the closed-set algebra
/// rather than an inline `iter().find(|v| v.label() == s)`
/// composition at every downstream consumer.
/// THEORY.md §V.1 — knowable platform; the zero-allocation typed
/// decode was an unnamed compound of [`Self::ALL`] +
/// [`Self::label`] + `Iterator::find` pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of the
/// two substrate primitives — generic consumers see ONE method,
/// not ONE typed-decode-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// zero-allocation typed decode emerges from the composition of
/// TWO substrate primitives ([`Self::ALL`], [`Self::label`])
/// rather than as a per-implementor inline `iter+find` pair. A
/// future tightening of either primitive (a future
/// `#[closed_set(via = "…")]`-driven projection rename, a future
/// canonicalization-aware label projection that folds case /
/// whitespace) propagates to every closed-set consumer through
/// ONE trait body — including [`Self::parse_label`],
/// [`Self::contains_label`], and [`Self::suggest_closest`],
/// which all default-body-delegate to this primitive.
///
/// Frontier inspiration: Rust's `enum_iterator::first_matching`
/// / Racket's `assf` (`(assf pred lst)` — first association whose
/// predicate holds) over a closed association list stand as the
/// same shape one vocabulary over on the finite-type-decode
/// side. MLIR's `Operation::dyn_cast<T>` on the typed op registry
/// is the same "look up the typed instance by discriminator,
/// return `Option`, don't materialize a diagnostic on miss"
/// axis over its closed-set-of-op-kinds. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::ALL`] + [`Self::label`] surfaces
/// with the standard-library `Iterator::find` primitive — no
/// new dep, no new IR layer, no new per-role primitive.
fn find_by_label(s: &str) -> Option<Self> {
Self::ALL
.iter()
.copied()
.find(|v| <Self as ClosedSet>::label(*v) == s)
}
/// Pure-membership predicate — `true` iff `s` matches some variant's
/// [`Self::label`] exactly, `false` for every other string.
///
/// Zero-allocation peer of [`Self::parse_label`]: `parse_label(s)`
/// materializes the typed [`Self::Unknown`] carrier (owning a
/// [`String`] copy of `s`) on the reject path even when the caller
/// drops it immediately with `.is_ok()`; this method answers the
/// SAME structural question — "is `s` a canonical label of this
/// closed set" — without ever entering [`Self::make_unknown`]. The
/// (allocating decode, non-allocating membership) axis of the
/// closed-set surface partitions cleanly: [`Self::parse_label`]
/// stays the load-bearing carrier-emitting path structured
/// diagnostics route through, [`Self::contains_label`] stays the
/// pure predicate `if`-gates / `filter`-passes / lint checks route
/// through.
///
/// Default body is `Self::ALL.iter().copied().any(|v| v.label() ==
/// s)` — a linear sweep composed from the same TWO substrate
/// primitives ([`Self::ALL`], [`Self::label`]) [`Self::parse_label`]
/// walks over, without the [`Self::make_unknown`] carrier
/// materialization the parse path threads on rejection.
/// Implementors override only when the membership surface needs to
/// diverge from the natural `ALL`-projection (no production
/// implementor reaches for this today; the axis exists for the same
/// reason `via` / `set_label` / `labels` / `labels_joined` /
/// `sorted_labels` / `sorted_labels_joined` / `suggest_closest` /
/// `parse_label_with_hint` overrides exist — a typed escape hatch
/// the trait surface exposes rather than forcing the implementor to
/// hand-roll the impl).
///
/// Future consumers — a lint that flags unknown kinds without
/// emitting a full structured diagnostic, an LSP hover pass that
/// highlights known canonical labels without decoding them, an
/// annotation-filter gate over cluster-wide `tatara.pleme.io/*`
/// signal keys, an iac-forge tag pre-check that partitions valid
/// canonical tags from unknown ones before committing to the typed
/// decode — bind to ONE trait method instead of hand-rolling the
/// `parse_label(s).is_ok()` shortcut (which pays the carrier
/// allocation on every reject) or the inline
/// `Self::ALL.iter().any(|v| v.label() == s)` composition (which
/// re-derives the sweep at every call site) at each callsite, and
/// the closed-set projection's pure-membership surface evolves at
/// ONE site rather than per-consumer.
///
/// THEORY.md §V.1 — knowable platform; the pure-membership
/// predicate was an unnamed compound of [`Self::ALL`] +
/// [`Self::label`] + `Iterator::any` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of the two
/// substrate primitives — generic consumers see ONE method, not
/// ONE membership-shape-per-crate. Sibling posture to
/// [`Self::parse_label`] on the (allocating decode, non-allocating
/// membership) axis: both walk `Self::ALL` keyed on
/// [`Self::label`], but the return-type axis partitions the
/// consumer surface — carrier-emitting decoders take
/// [`Self::parse_label`], predicate-gated filters take
/// [`Self::contains_label`].
/// THEORY.md §VI.1 — generation over composition; the
/// pure-membership predicate emerges from the composition of TWO
/// substrate primitives ([`Self::ALL`], [`Self::label`]) rather
/// than as a per-implementor inline `iter+any` pair. A future
/// tightening of either primitive (a future
/// `#[closed_set(via = "…")]`-driven projection rename, a future
/// canonicalization-aware label projection that folds case /
/// whitespace) propagates to every closed-set consumer through
/// ONE trait body.
///
/// Frontier inspiration: MLIR's `Type::isa<T>()` and
/// `Attribute::isa<T>()` typed predicates over the closed-set
/// registry — the "is this thing of this closed-set-member kind"
/// question emits at ONE typed method on the registry rather than
/// at every downstream operation's inline `dyn_cast` sweep.
/// Racket's `(member sym closed-list)` predicate over a closed
/// association list stands as the same shape one vocabulary over
/// on the homoiconic-Lisp side. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::ALL`] + [`Self::label`] surfaces with the
/// standard-library `Iterator::any` primitive — no new dep, no
/// new IR layer, no new per-role primitive.
fn contains_label(s: &str) -> bool {
Self::find_by_label(s).is_some()
}
/// Collect every variant's canonical [`Self::label`] into a
/// freshly-allocated `Vec<&'static str>` — `Self::ALL`'s elements
/// projected through [`Self::label`], in declaration order.
///
/// The substrate-wide
/// `T::ALL.iter().map(|v| v.label()).collect::<Vec<_>>()` shape
/// per-implementor test modules re-derived byte-for-byte
/// (the `*_canonical_names_pinned` / `*_all_is_unique_and_complete`
/// truth-table tests across `tatara-process` + `tatara-lisp`,
/// pre-lift) lifted into ONE generic projection. Generic consumers
/// (REPL exhaustive-listing diagnostics, LSP completion bars,
/// `tatara_lisp::domain::suggest`-keyed near-match suggesters)
/// take `T: ClosedSet` and call `T::labels()` rather than
/// hand-rolling the `ALL.iter().map().collect()` triple at each
/// call site.
///
/// Default body walks [`Self::ALL`] and applies [`Self::label`];
/// implementors override only when the labels surface diverges
/// from `Self::ALL`'s natural projection (no production implementor
/// reaches for this today — the override axis exists for the
/// degenerate case where an implementor's `labels()` surface
/// names a subset of `Self::ALL` distinct from what `label()`
/// projects).
///
/// THEORY.md §V.1 — knowable platform; the labels list was a
/// known idiom carried by convention across 10+ implementor
/// sites. Lifting it onto the trait makes the projection a TYPED
/// CONSEQUENCE of [`Self::ALL`] + [`Self::label`] — generic
/// consumers see ONE method, not ONE projection-shape-per-crate.
fn labels() -> ::std::vec::Vec<&'static str> {
Self::ALL
.iter()
.copied()
.map(<Self as ClosedSet>::label)
.collect()
}
/// Render the closed set's canonical labels joined by `sep` — the
/// substrate-wide candidate-list-as-string shape consumers thread
/// into structured-rejection diagnostics (`expected one of:
/// nix/flux/lisp/container/aplicacao/guest`, `allowed: :name,
/// :threshold`, `targets are kustomization|helm-release|deployment`).
///
/// Default body composes [`Self::labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the rendering is a typed CONSEQUENCE of `Self::ALL` +
/// `Self::label` + the chosen separator. Implementors override only
/// when the join surface needs to diverge from the natural
/// `labels().join(sep)` shape (no production implementor reaches for
/// this today — the axis exists for the same reason `via`,
/// `set_label`, `labels`, `suggest_closest`, `parse_label_with_hint`
/// overrides exist: a typed escape hatch the trait surface exposes
/// rather than forcing the implementor to hand-roll the impl).
///
/// The substrate-wide `let parts: Vec<&'static str> = T::ALL.iter()
/// .map(label).collect(); parts.join(sep)` shape recurred at FOUR
/// `tatara-process` test sites pre-lift
/// (`intent_error_empty_lists_every_kind_in_canonical_order`,
/// `artifact_error_empty_lists_every_kind_in_canonical_order`,
/// `channel_error_empty_lists_every_kind_in_canonical_order`,
/// `encapsulation_kind_error_empty_lists_every_target_in_canonical_order`)
/// each materializing the labels vec inline and asserting the join
/// against a hand-rolled `*_KIND_LIST` / `*_TARGET_LIST` constant —
/// past the ≥3 PRIME-DIRECTIVE trigger. Post-lift each test site
/// reduces to a single `T::labels_joined(sep)` call and the
/// candidate-list-as-string rendering binds at ONE trait method
/// every closed-set consumer can lean on without re-deriving the
/// `iter().map().collect().join()` triple.
///
/// Production sites that need a `&'static str` (a hand-rolled
/// `INTENT_KIND_LIST = "nix/flux/lisp/container/aplicacao/guest"`
/// constant stored in an error variant slot) keep their per-site
/// cached literal — this method runs at runtime and allocates a
/// `String`, so it does NOT replace the `const &'static str` shape
/// inline. Instead it stands as the canonical generative origin the
/// per-site cached literal is pinned against (via the existing
/// `*_error_empty_lists_every_kind_in_canonical_order` tests, now
/// routing through this method), so a regression that drifts the
/// production `&'static str` from the canonical join fails-loudly
/// at the test site without per-implementor inline materialization.
///
/// Future consumers — a metrics tagger that wants
/// `expected_one_of=intent_kinds:nix,flux,lisp,…` in a Prometheus
/// label, an LSP completion-bar renderer that wants
/// `nix | flux | lisp | …` separators, a `tatara-check` diagnostic
/// that wants `expected one of: nix, flux, lisp` for a
/// natural-language rendering — bind to ONE trait method instead of
/// hand-rolling the `iter+map+collect+join` triple at each call
/// site, and the closed-set projection's separator surface evolves
/// at ONE site rather than per-consumer.
///
/// THEORY.md §V.1 — knowable platform; the joined-candidate-list
/// shape was a known idiom carried by convention across 4+ test
/// sites + indirectly across 4+ production `&'static str`
/// constants. Lifting the join onto the trait makes the shape a
/// TYPED CONSEQUENCE of [`Self::labels`] + the chosen separator —
/// generic consumers see ONE method, not ONE join-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// joined-candidate-list rendering emerges from the composition of
/// THREE substrate primitives ([`Self::ALL`], [`Self::label`], the
/// caller-supplied separator) rather than as a per-implementor
/// inline `collect().join()` triple. A future tightening of the
/// candidate-list shape (a future Oxford-comma "..., or X" surface,
/// a future Unicode-aware separator) lands at ONE primitive and
/// propagates to every closed-set consumer.
///
/// Frontier inspiration: Idris's `show` on closed-set enumerations
/// — the candidate list emits as a single typed projection on the
/// finite-type universe rather than per-instance inline rendering.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::labels`] surface with the
/// `slice::join` standard-library primitive — no new dep, no new
/// IR layer.
fn labels_joined(sep: &str) -> ::std::string::String {
<Self as ClosedSet>::labels().join(sep)
}
/// Project [`Self::labels`] into ASCII-`sort_unstable` lexicographic
/// order — the substrate-wide canonical candidate-list ordering every
/// per-implementor `_all_is_unique_and_complete` test inlines a
/// hand-rolled `let mut sorted: Vec<&str> = T::ALL.iter().map(label)
/// .collect(); sorted.sort_unstable();` triple to materialize.
///
/// Default body composes [`Self::labels`] with
/// [`slice::sort_unstable`](https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable)
/// — the sorted-rendering is a typed CONSEQUENCE of `Self::ALL` +
/// `Self::label` + lexicographic order on `&str`. Implementors
/// override only when the sort surface needs to diverge from the
/// natural `labels().sort_unstable()` shape (no production
/// implementor reaches for this today — the axis exists for the same
/// reason `via`, `set_label`, `labels`, `labels_joined`,
/// `suggest_closest`, `parse_label_with_hint` overrides exist: a
/// typed escape hatch the trait surface exposes rather than forcing
/// the implementor to hand-roll the impl).
///
/// The substrate-wide `let mut sorted: Vec<&str> = T::ALL.iter()
/// .map(<via>).collect(); sorted.sort_unstable();` triple recurred
/// at SEVEN test sites pre-lift (`quote_form_all_is_unique_and_
/// complete`, `atom_kind_all_is_unique_and_complete`,
/// `kwarg_path_kind_all_is_unique_and_complete`,
/// `expected_kwarg_shape_all_is_unique_and_complete`,
/// `sexp_shape_all_is_unique_and_complete`,
/// `unquote_form_all_is_unique_and_complete`,
/// `macro_def_head_all_is_unique_and_complete`) each materializing
/// the labels vec inline and sorting it in place before asserting
/// against a hand-rolled sorted truth-table — past the ≥3
/// PRIME-DIRECTIVE trigger once the per-test inline triple is named.
/// Post-lift each test site reduces to `assert_eq!(T::sorted_labels(),
/// vec![<truth-table>])` and the canonical-ordered candidate-list
/// surface binds at ONE trait method every closed-set consumer can
/// lean on without re-deriving the `iter+map+collect+sort` quadruple.
///
/// Distinctness of the sorted result is already a substrate-wide
/// invariant pinned by [`assert_closed_set_well_formed`] (clause 3 —
/// labels are pairwise distinct), so the per-implementor `sorted ==
/// deduped` redundant double-check the inline triple carried can
/// retire alongside the materialization itself; the truth-table
/// comparison (the per-implementor unique payload — `vec!["'", ",",
/// ",@", "`"]` for `QuoteForm`, `vec!["bool", "float", "int",
/// "keyword", "string", "symbol"]` for `AtomKind`, …) stays at the
/// per-implementor test site as the load-bearing per-enum ground
/// truth this lift does NOT subsume.
///
/// Future consumers — an LSP completion bar that wants
/// `nix | flux | lisp | container | aplicacao | guest` in
/// alphabetical order, a `tatara-check` diagnostic that wants
/// `expected one of: aplicacao, container, flux, guest, lisp, nix`
/// for an alphabetized natural-language rendering, a typed
/// near-miss metric that wants the candidate set in a
/// deterministic-across-machines canonical order — bind to ONE
/// trait method instead of hand-rolling the
/// `iter+map+collect+sort` quadruple at each call site, and the
/// closed-set projection's canonical-ordering surface evolves at
/// ONE site rather than per-consumer.
///
/// THEORY.md §V.1 — knowable platform; the sorted-candidate-list
/// shape was a known idiom carried by convention across 7+ test
/// sites. Lifting the sort onto the trait makes the shape a TYPED
/// CONSEQUENCE of [`Self::labels`] + ASCII lexicographic ordering —
/// generic consumers see ONE method, not ONE sort-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// sorted-candidate-list rendering emerges from the composition of
/// THREE substrate primitives ([`Self::ALL`], [`Self::label`],
/// `slice::sort_unstable`) rather than as a per-implementor inline
/// `collect+sort` pair. A future tightening of the canonical-
/// ordering surface (a future Unicode-collation-aware sort, a
/// future declaration-order sibling) lands at ONE primitive and
/// propagates to every closed-set consumer.
///
/// Frontier inspiration: Idris's `show` over a finite-type universe
/// — the canonical-ordered listing emits as a single typed
/// projection rather than per-instance inline rendering. Translation
/// through pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::labels`] surface with the
/// `slice::sort_unstable` standard-library primitive — no new dep,
/// no new IR layer.
fn sorted_labels() -> ::std::vec::Vec<&'static str> {
let mut labels = <Self as ClosedSet>::labels();
labels.sort_unstable();
labels
}
/// Render the closed set's canonical labels in ASCII-`sort_unstable`
/// lexicographic order, joined by `sep` — the substrate-wide
/// canonical-ordered candidate-list-as-string shape consumers thread
/// into structured-rejection diagnostics that want alphabetized
/// rendering (`expected one of: aplicacao/container/flux/guest/lisp/nix`,
/// LSP completion bars sorted for humans, `tatara-check` "did you
/// mean X?" hints that walk a byte-wise-sorted candidate table).
///
/// Default body composes [`Self::sorted_labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the sorted-and-joined rendering is a typed CONSEQUENCE of
/// [`Self::ALL`] + [`Self::label`] + ASCII lexicographic ordering +
/// the chosen separator. Implementors override only when the sort
/// / join surface needs to diverge from the natural
/// `sorted_labels().join(sep)` shape (no production implementor
/// reaches for this today — the axis exists for the same reason
/// `via`, `set_label`, `labels`, `labels_joined`, `sorted_labels`,
/// `suggest_closest`, `parse_label_with_hint` overrides exist: a
/// typed escape hatch the trait surface exposes rather than forcing
/// the implementor to hand-roll the impl).
///
/// Sibling posture to the closed set of substrate-wide
/// candidate-list-as-string projections: [`Self::labels_joined`]
/// renders declaration-ordered labels (the `INTENT_KIND_LIST`-shaped
/// production constants that pin canonical serialization order),
/// [`Self::sorted_labels`] returns lexicographic-ordered labels as
/// a `Vec<&'static str>` (the truth-table shape per-implementor
/// `_all_is_unique_and_complete` tests key on), and THIS method
/// closes the third corner — the lexicographic-ordered
/// candidate-list-as-string. The three projections partition the
/// (declaration-vs-lexicographic ordering, Vec-vs-String surface)
/// cross-product exhaustively: declaration+Vec is [`Self::labels`],
/// declaration+String is [`Self::labels_joined`], lexicographic+Vec
/// is [`Self::sorted_labels`], lexicographic+String is this method.
/// A future consumer that wants a fifth surface (Oxford-comma joins,
/// Unicode-collation-aware sorting, a bulleted-list renderer) lands
/// at ONE additional trait method composed from these primitives,
/// not per-implementor.
///
/// Future consumers — an LSP completion bar rendering
/// `aplicacao | container | flux | guest | lisp | nix` in
/// alphabetized grammar-style form, a `tatara-check` diagnostic
/// rendering `expected one of: aplicacao, container, flux, guest,
/// lisp, nix` for a natural-language alphabetized surface, a
/// deterministic-across-machines metric label whose canonical
/// ordering must not depend on `Self::ALL`'s declaration order —
/// bind to ONE trait method instead of hand-rolling the
/// `sorted_labels().join(sep)` compound at each call site, and the
/// closed-set projection's alphabetized-rendering surface evolves
/// at ONE site rather than per-consumer.
///
/// THEORY.md §V.1 — knowable platform; the alphabetized
/// candidate-list-as-string shape sits as an unnamed compound of
/// [`Self::sorted_labels`] + [`slice::join`] pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of
/// [`Self::labels`] + ASCII lexicographic ordering + the chosen
/// separator — generic consumers see ONE method, not ONE
/// sort-then-join compound per crate.
/// THEORY.md §VI.1 — generation over composition; the
/// alphabetized-candidate-list rendering emerges from the
/// composition of FOUR substrate primitives ([`Self::ALL`],
/// [`Self::label`], `slice::sort_unstable`, `slice::join`) rather
/// than as a per-consumer inline `sort+join` pair. A future
/// tightening of either primitive (a Unicode-collation-aware sort,
/// an Oxford-comma-aware join, a locale-sensitive rendering)
/// propagates to every closed-set consumer through ONE trait body.
///
/// Frontier inspiration: Idris's `show` composed with `sort` over a
/// finite-type universe — the canonical-ordered rendering emits as
/// a single typed projection on the finite-type layer rather than
/// per-instance inline compound. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::sorted_labels`] surface with the `slice::join`
/// standard-library primitive — no new dep, no new IR layer.
fn sorted_labels_joined(sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_labels().join(sep)
}
/// Collect every typed variant into a freshly-allocated `Vec<Self>`
/// ordered by ASCII lexicographic [`Self::label`] — the typed-variant
/// sibling of [`Self::sorted_labels`] on the (typed variant,
/// canonical label) axis of the closed-set candidate-listing surface.
///
/// Peer of [`Self::sorted_labels`] one axis over on the (typed
/// variant, `&'static str` label) return-type axis: both walk
/// [`Self::ALL`] and project through [`Self::label`] to key the
/// ordering, but the return-type axis partitions the consumer
/// surface — LSP completion / `tatara-check` / metrics consumers
/// that render the label alone (`expected one of: alpha, beta, gamma`)
/// take [`Self::sorted_labels`], consumers that need the typed
/// variant next to the rendered label (an LSP completion API whose
/// selected item is a typed variant the caller reads back, a
/// `<variant.label()>: <count>` diagnostic that iterates
/// per-variant payloads in a machine-independent canonical order,
/// a metrics tagger that walks typed variants deterministically
/// across binaries) take this method. The two arms of the axis
/// compose element-wise: `Self::sorted_variants()[i].label()` equals
/// `Self::sorted_labels()[i]` for every `i in 0..Self::CARDINALITY`
/// — the load-bearing invariant the well-formedness sweep's clause
/// (17) pins.
///
/// The (return-type × ordering) 2×2 matrix on the closed-set
/// candidate-listing surface partitions post-lift:
///
/// | Ordering | `Vec<&'static str>` | `Vec<Self>` |
/// |----------------|-----------------------|--------------------------------|
/// | Declaration | [`Self::labels`] | `Self::ALL.iter().copied()` |
/// | Lexicographic | [`Self::sorted_labels`] | [`Self::sorted_variants`] |
///
/// The declaration + `Vec<Self>` corner stays at the direct
/// [`Self::ALL`] slice iterator — no primitive lifts, no default
/// body, no override axis, since `Self::ALL.iter().copied()` is the
/// natural zero-primitive projection. The lexicographic +
/// `Vec<Self>` corner — this method — is the missing lift: sorting
/// a `Vec<Self>` by label is a non-trivial composition of
/// [`Self::ALL`] + [`Self::label`] + `slice::sort_unstable_by_key`
/// that recurs at every prospective consumer site (an LSP
/// completion pass, a `tatara-check` per-variant diagnostic, a
/// deterministic-across-machines metric tagger) as the same
/// `T::ALL.to_vec().sort_unstable_by_key(|v| v.label())` triple.
///
/// Default body composes [`Self::ALL`] with `Vec::from` +
/// `slice::sort_unstable_by_key` keyed on [`Self::label`] — the
/// sorted-variant rendering is a typed CONSEQUENCE of `Self::ALL` +
/// `Self::label` + ASCII lexicographic ordering on the label
/// projection. Distinctness of the labels is already a substrate-
/// wide invariant pinned by [`assert_closed_set_well_formed`]
/// (clause 3 — labels are pairwise distinct), so unstable sorting
/// is deterministic on every implementor by construction —
/// `sort_unstable_by_key` never observes two equal keys to
/// reorder. Implementors override only when the ordering surface
/// needs to diverge from the natural label-keyed lexicographic
/// projection (no production implementor reaches for this today;
/// the axis exists for the same reason `via` / `set_label` /
/// `labels` / `sorted_labels` overrides exist — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl).
///
/// Future consumers — an LSP completion pass that returns typed
/// variants (not just labels) so the selected completion item
/// short-circuits back into `T` without a re-decode through
/// [`Self::find_by_label`], a `tatara-check` diagnostic that
/// renders per-variant projections (`<variant.label()>:
/// <variant.short_label()>` diagnostics on the double-label
/// surface `ProcessSignal` / `ConditionKind` carry) in a
/// machine-independent canonical order, a metrics tagger that
/// walks typed variants deterministically across binaries so
/// per-variant counter payloads emit in the same order on every
/// build, a per-variant lookup table `[Payload; T::CARDINALITY]`
/// exhaustively rendered as `(label, payload)` pairs in
/// alphabetical order — bind to ONE trait method instead of
/// hand-rolling the `let mut v: Vec<Self> = T::ALL.to_vec(); v
/// .sort_unstable_by_key(|x| x.label()); v` triple at each call
/// site, and the closed-set typed-variant canonical-ordering
/// surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (typed variant,
/// lexicographic ordering) projection becomes a TYPE projection on
/// the trait rather than a per-consumer hand-rolled
/// `T::ALL.to_vec().sort_unstable_by_key(|v| v.label())` triple at
/// every downstream stable-ordering site. The (return-type ×
/// ordering) 2×2 matrix partitions the closed-set
/// candidate-listing surface exhaustively into FOUR corners
/// (declaration + `Vec<&str>`, declaration + `Vec<Self>`,
/// lexicographic + `Vec<&str>`, lexicographic + `Vec<Self>`),
/// each with a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the sorted-typed-variants
/// shape was an unnamed compound of [`Self::ALL`] +
/// [`Self::label`] + `slice::sort_unstable_by_key` pre-lift.
/// Naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the two substrate primitives + the label-keyed lexicographic
/// ordering — generic consumers see ONE method, not ONE
/// sort-by-label shape per crate.
/// THEORY.md §VI.1 — generation over composition; the
/// sorted-typed-variants rendering emerges from the composition of
/// THREE substrate primitives ([`Self::ALL`], [`Self::label`],
/// `slice::sort_unstable_by_key`) rather than as a per-implementor
/// inline `to_vec+sort_unstable_by_key` triple. A future tightening
/// of any primitive (a Unicode-collation-aware sort, a
/// `#[closed_set(via = "…")]`-driven projection rename, a
/// canonicalization-aware label projection that folds case /
/// whitespace) propagates to every closed-set typed-variant
/// canonical-ordering consumer through ONE trait body — including
/// [`Self::sorted_labels`], which stays element-wise aligned
/// through the well-formedness contract.
///
/// Frontier inspiration: Idris's `sortBy` over a finite-type
/// universe keyed on a canonical `show` projection — the
/// canonical-ordered typed listing emits as a single projection on
/// the finite-type layer rather than per-instance inline compound.
/// MLIR's `OperationName::getSortedRegisteredOps` on the Op
/// registry returns typed op-names in a canonical order the
/// DiagnosticEngine renders per-kind diagnostics against; Racket's
/// `(sort (enum->list T) #:key T-label)` composes the enum's
/// canonical listing with a key-projected sort in the same
/// vocabulary one dispatch axis over. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::ALL`] surface with `Vec::from` and
/// `slice::sort_unstable_by_key` keyed on [`Self::label`] — no
/// new dep, no new IR layer, no supertrait bound.
fn sorted_variants() -> ::std::vec::Vec<Self> {
let mut variants: ::std::vec::Vec<Self> = Self::ALL.to_vec();
variants.sort_unstable_by_key(|v| <Self as ClosedSet>::label(*v));
variants
}
/// The lex-order full-set decl-index list — the `Vec<usize>` decl-slot
/// projection of [`Self::sorted_variants`] over the closed-set
/// full-set lex-axis aggregation surface. Every entry `i` in the
/// returned vector is the [`Self::index_of`] declaration-slot of
/// some variant in [`Self::sorted_variants`]; the returned vector's
/// entries are ORDERED by lex position but each entry carries the
/// DECLARATION slot the variant sits at in [`Self::ALL`], not the
/// lex slot. Equivalently: the returned vector is a PERMUTATION of
/// `0..T::CARDINALITY` — every declaration slot appears exactly
/// once (paired with clause 96 in [`assert_closed_set_well_formed`])
/// — and reading the permutation left-to-right walks the closed set
/// in ASCII-`sort_unstable` label order.
///
/// OPENS the (`Vec<usize>` decl-slot collection) return-shape row on
/// the (return-shape × ordering) 3×2 full-set aggregation matrix at
/// its (`Vec<usize>`, lex) corner. Sibling posture to
/// [`Self::sorted_variants`] one return-shape axis over on the
/// (`Vec<Self>`, `Vec<&'static str>`, `Vec<usize>`) return-shape
/// partition of the closed-set lex-axis full-set aggregation surface
/// — [`Self::sorted_variants`] materializes each full-set slot as
/// `Self`, [`Self::sorted_labels`] labels each slot under
/// [`Self::label`], this method projects each slot onto its
/// declaration-order `usize` position through [`Self::index_of`]. All
/// three walk the SAME (lex-ordered variant sequence) primitive and
/// MUST agree slot-for-slot on the underlying (variant → decl slot,
/// variant → canonical label, variant → variant) three-way
/// projection triangle over the full closed set.
///
/// The (return-shape × ordering × partition-flavor) 3×2×3 cube over
/// the closed-set aggregation surface post-lift:
///
/// | Return-shape | Full-set decl | Full-set lex | Endpoint decl | Endpoint lex | Interior decl | Interior lex |
/// |--------------------------|------------------------------|-----------------------------|-----------------------------|------------------------------------|-----------------------------|------------------------------------|
/// | `Vec<Self>` | (implicit `ALL`) | [`Self::sorted_variants`] | [`Self::endpoints`] pair | [`Self::sorted_endpoints`] pair | [`Self::interior`] | [`Self::sorted_interior`] |
/// | `Vec<&'static str>` | [`Self::labels`] | [`Self::sorted_labels`] | [`Self::endpoint_labels`] | [`Self::sorted_endpoint_labels`] | [`Self::interior_labels`] | [`Self::sorted_interior_labels`] |
/// | `Vec<usize>` | (implicit `0..CARDINALITY`) | this method | [`Self::endpoint_indices`] | [`Self::sorted_endpoint_indices`] | [`Self::interior_indices`] | [`Self::sorted_interior_indices`] |
///
/// The (`Vec<usize>`, full-set) row now closes at the lex column with
/// this method; the (`Vec<usize>`, full-set, decl) corner stays
/// implicit at `(0..T::CARDINALITY).collect()` because in declaration
/// order the decl-slot list is the identity range trivially derivable
/// from [`Self::CARDINALITY`] alone at every callsite whereas the
/// lex-order corner encodes the non-trivial lex-to-decl permutation
/// that consumers cannot re-derive without composing
/// [`Self::sorted_variants`] + [`Self::index_of`] verbatim.
///
/// Default body composes [`Self::sorted_variants`] with
/// `.into_iter()` + `.map(Self::index_of)` verbatim — the lex-order
/// full-set decl-slot collection is a typed CONSEQUENCE of the
/// lex-sort primitive composed with the per-slot decl-index
/// projection, not a fourth codepath through inline
/// `T::sorted_labels().into_iter().filter_map(|s| T::parse_label(s).ok()).map(T::index_of).collect()`
/// (which re-decodes each label through the parse surface AND
/// silently drops a variant whose label re-decode ever regresses)
/// or `T::ALL.iter().copied().collect::<Vec<_>>().sort_unstable_by_key(|&v| T::label(v))`
/// followed by a hand-rolled `map(index_of)` (which re-derives the
/// sort surface at every callsite). Implementors override only when
/// the lex-order full-set decl-slot collection needs to diverge from
/// the natural `sorted_variants().into_iter().map(index_of).collect()`
/// shape — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl. An implementor
/// that overrides [`Self::sorted_variants`] (or the [`Self::label`]
/// projection its `sort_unstable_by_key` funnels through) propagates
/// the override through this default body to the lex-order decl-slot
/// projection automatically.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_variants`] returns
/// `[T::first()]` whose `index_of()` is `0`, so this method returns
/// `vec![0]`. Two-variant degeneracy — [`Self::sorted_variants`]
/// returns the lex-sorted variant pair, so this method returns
/// `vec![lex_first.index_of(), lex_last.index_of()]` which permutes
/// `0..2` to `[0, 1]` when declaration order matches lex order and
/// to `[1, 0]` when declaration order reverses lex order.
///
/// DIVERGENCE FROM the implicit `(0..T::CARDINALITY).collect()`
/// full-set × decl surface: on any closed set whose declaration
/// order MATCHES lex order the returned vector collapses onto the
/// identity range `(0..T::CARDINALITY).collect()` (`StubKind`'s
/// canonical labels `("alpha", "beta", "gamma")` sort-in-place at
/// every position, so `T::sorted_indices() == vec![0, 1, 2]`). On
/// any closed set whose declaration order DIVERGES from lex order
/// the vector carries a NON-IDENTITY permutation of
/// `0..T::CARDINALITY` — the lex-to-decl slot map that turns "walk
/// the closed set in alphabetical order" into "iterate through this
/// decl-slot list", exposing the same permutation the
/// [`Self::sorted_endpoint_indices`] pair-endpoint corner extracts
/// at its (`usize`, lex) slot on the pair-arity axis one arity level
/// down.
///
/// Consumer surface — a `[Payload; T::CARDINALITY]` renderer that
/// emits per-slot payloads in alphabetical order without
/// materializing typed variants first (`for &i in
/// &T::sorted_indices() { render(payload_table[i]) }` instead of the
/// two-primitive `for v in T::sorted_variants() {
/// render(payload_table[T::index_of(v)]) }`), a deterministic-
/// across-machines Prometheus tag whose alphabetized rendering key
/// must route through the lex-to-decl permutation without exposing
/// the underlying declaration order, a `tatara-check` per-slot
/// per-label diagnostic that renders `<label>: <count>` in
/// alphabetized order while keying its counters on declaration
/// slots, an alphabetized full-set-observed bitset renderer that
/// sets bit `i` per observed decl-slot in the ORDER `i` sits at on
/// the lex axis — bind to ONE trait method instead of hand-rolling
/// `T::sorted_variants().into_iter().map(T::index_of).collect()`
/// (which re-derives the same two-primitive composition at every
/// callsite) OR the inline three-step
/// `T::sorted_labels().into_iter().filter_map(|s| T::parse_label(s).ok()).map(T::index_of).collect()`
/// (which re-decodes labels through the parse surface and silently
/// drops variants under any label-parse regression).
///
/// The lex-order full-set decl-slot collection contract —
/// `T::sorted_indices() == T::sorted_variants().into_iter().map(T::index_of).collect()`
/// on every implementor AND the returned vector is a PERMUTATION of
/// `0..T::CARDINALITY` (length matches, every slot in range, no
/// duplicates) — is guaranteed by the default composition through
/// [`Self::sorted_variants`] + [`Self::index_of`]; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (96) pins the composition against the natural
/// `sorted_variants().into_iter().map(index_of).collect()` shape AND
/// pins the returned vector as a permutation of
/// `0..T::CARDINALITY` on every implementor. The two-arm pin
/// partitions the failure modes at the (composition-equality) corner
/// AND the (permutation-membership) corner simultaneously so a
/// permissive override that folds the lex-order decl-slot collection
/// onto the identity range `(0..T::CARDINALITY).collect()` on a
/// closed set whose declaration order diverges from lex order fires
/// on the composition-equality arm loudly rather than silently.
///
/// THEORY.md §III — the typescape; the (full-set × lex → decl-slot
/// collection) `Vec<usize>` projection becomes a TYPE projection on
/// the trait rather than a per-consumer inline
/// `T::sorted_variants().into_iter().map(T::index_of).collect()`
/// two-primitive composition at every downstream lex-order-decl-slot
/// lookup site. The (return-shape × ordering × partition-flavor)
/// 3×2×3 aggregation cube's (`Vec<usize>`, lex, full-set) corner
/// closes here alongside the pre-existing (`Vec<usize>`, decl/lex,
/// endpoint) + (`Vec<usize>`, decl/lex, interior) corners; the
/// (return-shape × partition-flavor) column of the (`Vec<usize>`)
/// row now closes at the (full-set × lex), (endpoint × decl/lex),
/// (interior × decl/lex) corners with a single implicit
/// `(0..CARDINALITY).collect()` at the trivially-derivable
/// (full-set × decl) corner.
/// THEORY.md §V.1 — knowable platform; the (lex-order full-set
/// decl-slot collection) projection was an unnamed compound of
/// [`Self::sorted_variants`] + `.map(Self::index_of).collect()`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not ONE lex-order-decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of [`Self::sorted_variants`] +
/// [`Self::index_of`] rather than as a per-implementor
/// `const SORTED_INDICES: [usize; N]` declaration that silently
/// drifts from [`Self::ALL`] on any reordering or when a hand-rolled
/// [`Self::sorted_variants`] override carves a different lex-sort
/// permutation.
///
/// Frontier inspiration: Racket's `(enum-indices/sorted enum)` on a
/// closed enum projects the full-set alphabetized decl-slot list,
/// complementary to `(enum-indices enum)` that emits the raw
/// declaration-order slot list. MLIR's
/// `mlir::OperationName::sortedRegisteredOpIndices()` on the
/// registered-op enumeration returns the alphabetized decl-slot
/// permutation generic op-walkers thread through when their
/// canonical ordering must not depend on registration order.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::sorted_variants`] +
/// [`Self::index_of`] surfaces — no new dep, no new IR layer, no
/// supertrait bound, no per-implementor allocation beyond the
/// natural `Vec<usize>` collection the sibling
/// [`Self::sorted_interior_indices`] surface already routes one
/// partition-flavor axis over.
fn sorted_indices() -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// Project `needle` onto the closest variant whose
/// [`Self::label`] sits within the substrate-wide bounded edit
/// distance — the typed bridge between an unrecognized input and
/// the "did you mean …?" diagnostic surface.
///
/// Wires [`tatara_lisp::domain::suggest`] (the workspace-wide
/// Levenshtein primitive — bound 1 for ≤3 chars, 2 for ≤7 chars,
/// 3 for ≥8 chars, lexicographic tie-break) into the
/// [`ClosedSet`] surface so every closed-set parse rejection can
/// thread a typed hint without re-deriving the metric / the
/// candidate-list materialization at each consumer site. An
/// exact match returns [`None`] — that path lives at
/// [`Self::parse_label`]; this method exists for near-misses.
/// Inputs beyond the bound return [`None`] so the "did you mean
/// …?" surface stays conservative rather than guessing.
///
/// Default body walks [`Self::labels`], calls
/// [`tatara_lisp::domain::suggest`], and re-keys the suggested label
/// onto its [`Self::ALL`] variant. Implementors override only
/// when the suggestion metric needs to diverge from the
/// substrate-wide Levenshtein bound (no production implementor
/// reaches for this today; the axis exists for a future
/// implementor whose canonical labels embed punctuation /
/// case-sensitive Unicode where the default metric would
/// systematically miss).
///
/// THEORY.md §V.1 — knowable platform; the "did you mean …?"
/// suggestion shape ships at ONE primitive ([`tatara_lisp::domain::suggest`])
/// the substrate already routes kwarg + domain-keyword
/// diagnostics through. Lifting the closed-set bridge onto this
/// trait extends the SAME primitive's reach to every closed-set
/// enum without forcing each consumer to re-derive the
/// candidate-list shape.
///
/// THEORY.md §VI.1 — generation over composition; the
/// suggest-closest behavior emerges from the composition of
/// THREE substrate primitives ([`Self::ALL`], [`Self::label`],
/// [`tatara_lisp::domain::suggest`]) rather than as a per-implementor
/// edit-distance impl. Future improvements to the suggestion
/// metric (a future Damerau-Levenshtein lift, a future
/// case-insensitive override) edit ONE primitive and propagate to
/// every closed-set consumer.
///
/// Frontier inspiration: rustc's `find_best_match_for_name` on
/// `Symbol`s, Idris's elaborator-reflection hint pass over its
/// constructor namespace, Roslyn's `SymbolMatcher` over typed
/// member tables — bounded edit-distance over a closed symbol
/// table threaded into the parse-rejection diagnostic. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's [`Self::labels`] iterator with the substrate's
/// existing [`suggest`] metric.
fn suggest_closest(needle: &str) -> Option<Self> {
let candidates = Self::labels();
let target = suggest(needle, &candidates)?;
Self::find_by_label(target)
}
/// Decode `s` into the typed variant, threading a typed
/// [`Self::suggest_closest`] hint into the rejection envelope —
/// the structured-diagnostic surface that composes
/// [`Self::parse_label`] + [`Self::suggest_closest`] into ONE
/// call a downstream LSP / `tatara-check` consumer takes as
/// `T: ClosedSet`.
///
/// On exact match returns `Ok(v)` — the hint slot stays absent
/// because [`Self::suggest_closest`] is "near-miss only" by
/// contract (a successful parse short-circuits before
/// [`Self::suggest_closest`] runs, so the substrate-wide
/// "did you mean …?" surface never double-emits the same
/// variant once as a successful decode and once as a hint).
/// On miss returns `Err((unknown, hint))` where `unknown` is
/// the same typed carrier [`Self::parse_label`] would have
/// emitted (preserving the substrate-wide
/// `"unknown {SET_LABEL}: {input}"` rendering through
/// [`core::fmt::Display`]) and `hint` is the typed variant
/// [`Self::suggest_closest`] keys on — `Some(v)` when a
/// canonical label sits within the substrate-wide bounded edit
/// distance, `None` when no candidate qualifies (the
/// conservative-suggestion contract — silent over guessing).
///
/// The Err shape `(Self::Unknown, Option<Self>)` is deliberately
/// asymmetric: the typed carrier is the load-bearing payload
/// (the substrate-wide rejection surface every existing
/// implementor's parse boundary emits), while the hint is a
/// renderable-only adornment a downstream consumer threads next
/// to the rejection ("did you mean `Failed`?" next to the
/// `"unknown process phase: Failing"` shape) WITHOUT replacing
/// the typed rejection itself. Generic consumers that don't
/// care about the hint take `.0` (the typed carrier); consumers
/// that DO can render `did you mean <v.label()>?` from the
/// hint without re-deriving the metric / the candidate-list
/// materialization at each consumer site.
///
/// Default body composes [`Self::parse_label`] and
/// [`Self::suggest_closest`] verbatim — the structured shape is
/// a typed CONSEQUENCE of the two pre-existing primitives, not
/// a third codepath. Implementors override only when the
/// composition needs to diverge (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing
/// the implementor to hand-roll the impl).
///
/// THEORY.md §III — the typescape; the structured rejection
/// becomes a typed projection on the trait rather than a
/// per-consumer hand-rolled (`parse_label(s).map_err(|e| (e,
/// Self::suggest_closest(s)))`) call at every parse boundary.
/// THEORY.md §V.1 — knowable platform; the "did you mean …?"
/// surface emits at ONE primitive ([`tatara_lisp::domain::suggest`])
/// the substrate already routes diagnostics through, and the
/// composition that threads it next to the typed rejection
/// emits at ONE trait body that every closed-set enum inherits
/// through zero additional source.
/// THEORY.md §VI.1 — generation over composition; the
/// structured-diagnostic shape emerges from the composition of
/// FOUR substrate primitives ([`Self::ALL`], [`Self::label`],
/// [`Self::make_unknown`], [`tatara_lisp::domain::suggest`]) rather
/// than as a per-implementor structured-error impl. A future
/// LSP / `tatara-check` consumer takes `T: ClosedSet` and
/// renders a typed `"did you mean <variant>?"` next to a
/// rejection without binding to a per-implementor structured
/// carrier shape.
///
/// Frontier inspiration: rustc's `MultiSpan` typed-diagnostic
/// surface — the structured rejection carries both the typed
/// payload AND the typed adornment slot, with the adornment
/// rendered next to (not in place of) the typed rejection.
/// Translation through pleme-io primitives: a pure default
/// method composing the trait's existing
/// [`Self::parse_label`] + [`Self::suggest_closest`] surfaces
/// — no new primitive, no new dep, no new IR layer.
fn parse_label_with_hint(s: &str) -> Result<Self, (Self::Unknown, Option<Self>)> {
match Self::parse_label(s) {
Ok(v) => Ok(v),
Err(unknown) => Err((unknown, Self::suggest_closest(s))),
}
}
/// Zero-allocation typed decode of `s`, threading a typed
/// [`Self::suggest_closest`] hint into the rejection envelope —
/// the structured-diagnostic surface that composes
/// [`Self::find_by_label`] + [`Self::suggest_closest`] into ONE
/// call a downstream LSP / config-decoder / filter-map consumer
/// takes as `T: ClosedSet` WITHOUT paying the
/// [`Self::make_unknown`] carrier allocation
/// [`Self::parse_label_with_hint`] threads on rejection.
///
/// On exact match returns `Ok(v)` — the hint slot stays absent
/// because [`Self::suggest_closest`] is "near-miss only" by
/// contract (a successful lookup short-circuits before
/// [`Self::suggest_closest`] runs, so the substrate-wide
/// "did you mean …?" surface never double-emits the same
/// variant once as a successful decode and once as a hint).
/// On miss returns `Err(hint)` where `hint` is the typed variant
/// [`Self::suggest_closest`] keys on — `Some(v)` when a
/// canonical label sits within the substrate-wide bounded edit
/// distance, `None` when no candidate qualifies (the
/// conservative-suggestion contract — silent over guessing).
///
/// Peer of [`Self::parse_label_with_hint`] on the (allocating
/// carrier decode, non-allocating typed decode) axis of the
/// closed-set surface: [`Self::parse_label_with_hint`]
/// materializes the typed [`Self::Unknown`] carrier (owning a
/// [`String`] copy of `s`) on the reject path even when the
/// caller drops it immediately with `.map_err(|(_, hint)| hint)`;
/// this method answers the SAME structural question —
/// "which canonical variant does `s` decode to (or hint at), if
/// any?" — without ever entering [`Self::make_unknown`].
///
/// The (side-effect × hint) 2×2 matrix over the closed-set
/// decoded-arm return type partitions exhaustively post-lift:
///
/// | Side-effect on reject | No hint | With hint |
/// |-------------------------------|-----------------------------|------------------------------------|
/// | Allocating (materialize carrier) | [`Self::parse_label`] | [`Self::parse_label_with_hint`] |
/// | Non-allocating (typed decode) | [`Self::find_by_label`] | [`Self::find_by_label_with_hint`] |
///
/// Default body composes [`Self::find_by_label`] with
/// [`Self::suggest_closest`] verbatim — the structured shape is
/// a typed CONSEQUENCE of the two pre-existing primitives, not a
/// third codepath. Implementors override only when the
/// composition needs to diverge (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `suggest_closest` /
/// `parse_label_with_hint` overrides exist — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::find_by_label`] propagates the override
/// through this default body to the structured typed-decode arm
/// automatically; the (allocating carrier decode, non-allocating
/// typed decode) axis funnels every sweep through ONE typed
/// primitive on each of the (no-hint, with-hint) columns.
///
/// Future consumers — an LSP hover pass that resolves the typed
/// variant under the operator's cursor AND (on miss) renders a
/// `did you mean <v.label()>?` next to a bare rejection WITHOUT
/// paying carrier allocation per non-matching hover, a
/// config-field decoder with a natural fallback AND a typed
/// hint the operator sees when the field's value is a near-miss
/// (`T::find_by_label_with_hint(cfg).unwrap_or_else(|hint|
/// { emit_hint(hint); T::default_kind() })`), a `filter_map`-
/// shaped stream projection over cluster-wide `tatara.pleme.io/*`
/// annotation keys that partitions each element into
/// (typed_variant, typed_hint, bare_unrecognized_key) via
/// `find_by_label_with_hint` — bind to ONE trait method instead
/// of hand-rolling the
/// `find_by_label(s).ok_or_else(|| suggest_closest(s))`
/// composition at each callsite, and the closed-set
/// zero-allocation structured-decode surface evolves at ONE site
/// rather than per-consumer.
///
/// THEORY.md §III — the typescape; the structured typed-decode
/// becomes a TYPE projection on the trait rather than a
/// per-consumer hand-rolled
/// (`find_by_label(s).ok_or_else(|| suggest_closest(s))`) call
/// at every zero-allocation decode boundary. The (allocating
/// carrier decode, non-allocating typed decode) × (no-hint,
/// with-hint) 2×2 matrix partitions the structured-decode
/// surface exhaustively into FOUR typed projections, each with
/// a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the structured
/// typed-decode was an unnamed compound of
/// [`Self::find_by_label`] + [`Self::suggest_closest`] pre-lift.
/// Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not ONE structured-decode-shape-
/// per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// structured-diagnostic shape emerges from the composition of
/// TWO substrate primitives ([`Self::find_by_label`],
/// [`Self::suggest_closest`]) rather than as a per-implementor
/// structured-decode impl. A future tightening of either
/// primitive (a future perfect-hash lookup on
/// [`Self::find_by_label`], a future Damerau-Levenshtein lift
/// on [`Self::suggest_closest`], a future case-insensitive
/// projection axis) propagates to every closed-set structured
/// zero-allocation consumer through ONE trait body.
///
/// Frontier inspiration: rustc's `find_best_match_for_name`
/// composed with `Symbol::intern` — the typed-symbol lookup with
/// a bounded near-miss adornment slot, without materializing a
/// diagnostic on miss when the caller supplies a natural
/// fallback. MLIR's `Operation::dyn_cast<T>` composed with the
/// diagnostic engine's registered "did you mean" hook — the
/// typed op lookup returns `Option<T>` on miss, and the hint is
/// a separate typed projection over the op-kind registry.
/// Translation through pleme-io primitives: a pure default
/// method composing the trait's existing [`Self::find_by_label`]
/// with [`Self::suggest_closest`] — no new primitive, no new
/// dep, no new IR layer.
fn find_by_label_with_hint(s: &str) -> Result<Self, Option<Self>> {
match Self::find_by_label(s) {
Some(v) => Ok(v),
None => Err(Self::suggest_closest(s)),
}
}
/// Project `self` onto its zero-indexed position in [`Self::ALL`] —
/// the reverse projection of the [`Self::ALL`] slice's array-index
/// surface. Closes the (variant → position, position → variant)
/// bijection with `0..Self::CARDINALITY` that every per-variant
/// lookup-table / bitset / compact-encoding consumer binds to.
///
/// The forward direction — position → variant — is the plain
/// `Self::ALL[i]` array-indexing surface every consumer already
/// walks; the reverse direction — variant → position — is this
/// method. Together they form the bijection
/// `Self ↔ 0..Self::CARDINALITY` that composes with
/// [`Self::CARDINALITY`] into a typed const-generic surface
/// downstream consumers reach for whenever they need to key a
/// per-variant payload without hand-rolling the sweep.
///
/// Sibling posture to [`Self::find_by_label`] on the (label decode,
/// index decode) axis of the closed-set surface: [`Self::find_by_label`]
/// projects a `&str` onto its typed variant through the label
/// projection, this method projects a typed variant onto its
/// `usize` position through the [`Self::ALL`] slice. Both walk
/// [`Self::ALL`] as the single load-bearing per-variant listing,
/// keyed by a different projection — the (Self → &str, Self →
/// usize) return-type axis partitions the (typed variant →
/// canonical projection) surface exhaustively into TWO typed
/// projections, each with a distinct load-bearing consumer surface.
///
/// The (return-type) axis of the closed-set variant → projection
/// surface partitions post-lift:
///
/// | Projection direction | Projection surface |
/// |-----------------------------|---------------------------|
/// | Typed variant → `&'static str` label | [`Self::label`] |
/// | Typed variant → `usize` array index | [`Self::index_of`] |
///
/// Default body sweeps [`Self::ALL`] keyed on
/// [`core::mem::discriminant`] — the discriminant-keyed comparator
/// stays valid for every fieldless / typed enum implementor
/// (`std::mem::discriminant` on any real enum returns a well-defined
/// value per variant) WITHOUT forcing a `PartialEq` supertrait onto
/// the [`ClosedSet`] contract. The trait's supertrait bound stays
/// `Sized + Copy + 'static` — the minimum surface every implementor
/// carries — and the discriminant primitive re-uses the enum's
/// natural per-variant identity. Implementors override with a
/// per-variant `match` when the O(N) sweep shows up on a hot-path
/// profile (the substrate-wide typed-emission bind: no production
/// site today calls `index_of` on a per-message hot path, so the
/// default sweep costs nothing measurable, and the override axis
/// exists for the same reason `via` / `set_label` / `labels`
/// overrides exist — a typed escape hatch the trait surface exposes
/// rather than forcing the implementor to hand-roll the impl).
///
/// Panics if `Self::ALL` does not contain `self` — a structural
/// bug at the implementor's [`Self::ALL`] declaration, not a
/// runtime accident. The panic is guaranteed absent when the
/// [`Self::ALL`] listing covers every variant (the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (15)
/// pins on every implementor), so a passing well-formedness sweep
/// means every generic consumer can call `index_of` on any typed
/// variant without threading an `Option` through the return.
///
/// Future consumers — a per-variant lookup table `[Payload;
/// T::CARDINALITY]` whose index is `variant.index_of()`, a bitset
/// over the closed set that sets bit `variant.index_of()` per
/// observed variant, a compact wire encoding that emits
/// `variant.index_of() as u8` when the cardinality fits in a byte,
/// a per-variant metrics counter table sized `[u64; T::CARDINALITY]`
/// that increments `counters[variant.index_of()]` per sample — bind
/// to ONE trait method instead of hand-rolling either
/// `T::ALL.iter().position(|v| *v == variant).unwrap()` (which
/// requires the caller to import `PartialEq` at every call site AND
/// pay the sweep at every callsite) OR a per-implementor inline
/// `match self { ... }` (which re-derives the per-variant literal
/// index at every callsite).
///
/// THEORY.md §III — the typescape; the (typed variant → array
/// index) projection becomes a TYPE projection on the trait rather
/// than a per-consumer hand-rolled `T::ALL.iter().position(|v| *v
/// == self)` composition at every downstream indexing site. The
/// (variant → `&str`, variant → `usize`) return-type axis
/// partitions the (typed variant → canonical projection) surface
/// exhaustively into TWO typed projections, each with a distinct
/// load-bearing consumer surface — label decoding for
/// [`Self::label`], array indexing for this method.
/// THEORY.md §V.1 — knowable platform; the (variant → array
/// index) projection was an unnamed compound of [`Self::ALL`] +
/// `Iterator::position` + `PartialEq` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of [`Self::ALL`]
/// alone (the discriminant-keyed sweep re-uses the enum's natural
/// per-variant identity WITHOUT a `PartialEq` bound) — generic
/// consumers see ONE method, not ONE position-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// array index) projection emerges from the composition of ONE
/// substrate primitive ([`Self::ALL`]) with the standard-library
/// [`core::mem::discriminant`] projection and the standard-library
/// `Iterator::position` primitive rather than as a per-implementor
/// inline `match` block. A future tightening of [`Self::ALL`] (a
/// future `#[closed_set(cardinality = N)]` derive attribute that
/// pins N at the source, a future declaration-time position-
/// assertion) propagates to every closed-set const-generic consumer
/// through ONE trait method.
///
/// Frontier inspiration: Idris's `Fin n` finite-cardinality type
/// with `finToNat : Fin n -> Nat` — the finite-type universe
/// exposes a canonical (element → natural) projection every
/// downstream indexer binds to; MLIR's `TypeID` on the Op registry
/// gives each Op kind a stable index the DiagnosticEngine keys
/// per-kind counters on; Racket's `enum-index` on a closed enum
/// projects a symbol onto its declaration-order position; Rust's
/// `strum::EnumIter::position` composed with `PartialEq` — the
/// same shape one vocabulary over. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::ALL`] surface with `Iterator::position` keyed
/// on [`core::mem::discriminant`] — no new dep, no new IR layer,
/// no supertrait bound.
fn index_of(self) -> usize {
Self::ALL
.iter()
.position(|v| core::mem::discriminant(v) == core::mem::discriminant(&self))
.expect(
"ClosedSet::index_of: Self::ALL is missing self — implementor's ALL slice doesn't cover every variant",
)
}
/// Recover the typed variant at declaration-order position `i` in
/// [`Self::ALL`], or [`None`] if `i >= Self::CARDINALITY`.
///
/// The typed inverse of [`Self::index_of`] on the (typed variant ↔
/// `usize` array index) bijection: [`Self::index_of`] projects a
/// variant onto its `usize` position through the [`Self::ALL`]
/// slice; this method projects a `usize` position back onto its
/// typed variant. Together the two projections close the bijection
/// with `0..Self::CARDINALITY` at BOTH directions — every generic
/// consumer that stores a `variant.index_of()` for later decode
/// (a compact wire encoding that emits `variant.index_of() as u8`
/// and later recovers the variant, a slotted lookup table
/// `[Payload; T::CARDINALITY]` scanned back to `(variant, payload)`
/// pairs for exhaustive iteration, a bitset over the closed set
/// walked back to the set of observed variants, a metrics
/// aggregator that stores per-index counters and later renders
/// `<variant>: <count>` diagnostics) binds to ONE typed inverse
/// method rather than hand-rolling either `Self::ALL.get(i).copied()`
/// (which re-derives the same three-primitive composition at every
/// call site) OR a per-implementor inline `match i { 0 => Some(v0),
/// 1 => Some(v1), _ => None }` (which re-derives the per-variant
/// literal → variant table at every callsite AND drifts silently
/// when [`Self::ALL`] gains a new variant).
///
/// Sibling posture to [`Self::find_by_label`] on the (label decode,
/// index decode) axis of the closed-set inbound-projection surface:
/// [`Self::find_by_label`] projects a `&str` label back onto its
/// typed variant through the [`Self::ALL`] × [`Self::label`] sweep,
/// this method projects a `usize` position back onto its typed
/// variant through direct [`Self::ALL`] slice indexing. Both
/// return an [`Option<Self>`] because the input carrier is wider
/// than the closed set — every non-canonical `&str` decodes to
/// [`None`] on the label side, every out-of-range `usize` decodes
/// to [`None`] on the index side. Both share the SAME
/// zero-allocation shape and the SAME `Option`-typed rejection
/// arm; a generic consumer freely swaps between the two decode
/// surfaces based on its carrier without changing the program's
/// structured-decode semantics.
///
/// The (return-type × input-carrier) axis of the closed-set
/// inbound-projection surface partitions post-lift:
///
/// | Input carrier | Return type | Projection surface |
/// |------------------|----------------------|---------------------------|
/// | `&str` label | `Result<Self, U>` | [`Self::parse_label`] |
/// | `&str` label | `Option<Self>` | [`Self::find_by_label`] |
/// | `&str` label | `bool` | [`Self::contains_label`] |
/// | `usize` index | `Option<Self>` | [`Self::from_index`] |
///
/// Default body composes ONE substrate primitive ([`Self::ALL`])
/// with the standard-library `<[T]>::get` bounded-index projection —
/// no discriminant sweep, no `PartialEq` bound, no per-variant
/// `match`. Implementors override with a per-index `match` when
/// the O(1) slice lookup shows up on a hot-path profile (the
/// substrate-wide typed-emission bind: no production site today
/// calls `from_index` on a per-message hot path, so the default
/// slice lookup costs nothing measurable, and the override axis
/// exists for the same reason `via` / `set_label` / `labels` /
/// `index_of` overrides exist — a typed escape hatch the trait
/// surface exposes rather than forcing the implementor to
/// hand-roll the impl).
///
/// The bounded-index contract — the out-of-range arm returns
/// [`None`] for every `i >= Self::CARDINALITY` — is guaranteed by
/// the default `<[T]>::get` composition; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (16)
/// pins the both-directions equality on every implementor, so a
/// passing well-formedness sweep means every generic consumer can
/// call `from_index` on any `usize` payload and expect the same
/// `Option`-typed answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (array index → typed
/// variant) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline `Self::ALL.get(i).copied()`
/// composition at every downstream index-decode site. The
/// (variant → `usize`, `usize` → variant) direction axis of the
/// (variant ↔ array-index) bijection partitions exhaustively into
/// TWO typed projections, each with a distinct load-bearing
/// consumer surface — array indexing for [`Self::index_of`],
/// variant recovery for this method.
/// THEORY.md §V.1 — knowable platform; the (array index → typed
/// variant) projection was an unnamed compound of [`Self::ALL`] +
/// `<[T]>::get` + `Option::copied` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of
/// [`Self::ALL`] — generic consumers see ONE method, not ONE
/// slice-lookup-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (array
/// index → typed variant) projection emerges from the composition
/// of ONE substrate primitive ([`Self::ALL`]) with the
/// standard-library `<[T]>::get` bounded-index projection and the
/// standard-library `Option::copied` primitive rather than as a
/// per-implementor inline `match` block. A future tightening of
/// [`Self::ALL`] (a future `#[closed_set(cardinality = N)]` derive
/// attribute that pins N at the source, a future declaration-time
/// position-assertion) propagates to every closed-set const-generic
/// inverse-decode consumer through ONE trait method.
///
/// Frontier inspiration: Idris's `Fin n` finite-cardinality type
/// with `natToFin : Nat -> (n : Nat) -> Maybe (Fin n)` — the
/// finite-type universe exposes a canonical (natural → element)
/// bounded-decode projection every downstream compact-encoding
/// binds to, complementing `finToNat` in the opposite direction;
/// Racket's `enum->object` on a closed enum decodes an index back
/// to its variant; MLIR's `RegisteredOperationName::get(int)` on
/// the Op registry decodes a stable index back to its Op kind;
/// Rust's `strum::EnumIter::nth` composed with `Iterator::nth` —
/// the same shape one vocabulary over. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::ALL`] surface with `<[T]>::get` and
/// `Option::copied` — no new dep, no new IR layer, no supertrait
/// bound.
fn from_index(i: usize) -> Option<Self> {
Self::ALL.get(i).copied()
}
/// The declaration-order first variant of the closed set —
/// `Self::ALL[0]` projected onto the trait surface as a
/// panic-free typed anchor. Closes the (endpoint = 0) corner of
/// the closed-set endpoint-anchor axis.
///
/// Sibling posture to [`Self::last`] one axis over on the
/// (endpoint = 0, endpoint = `CARDINALITY - 1`) partition of the
/// closed-set endpoint surface: [`Self::first`] returns the
/// declaration-order head, [`Self::last`] returns the
/// declaration-order tail. Together the two anchors bracket
/// [`Self::ALL`] at its two structural endpoints without forcing
/// generic consumers to either (a) index into the slice directly
/// (`Self::ALL[0]` / `Self::ALL[Self::ALL.len() - 1]`) — which
/// makes the endpoint axis a per-consumer duplicated composition
/// of [`Self::ALL`] + `<[T]>::first` / `<[T]>::last` +
/// [`Option::copied`] + `Option::unwrap` — OR (b) route through
/// [`Self::from_index`] with a hand-rolled
/// `.unwrap_or_else(|| unreachable!())` at each callsite (which
/// re-derives the `0`-index / `CARDINALITY - 1`-index literal at
/// every downstream site AND pays an [`Option`]-typed dispatch
/// the closed-set non-empty contract structurally forbids). Both
/// endpoints are guaranteed to exist by the well-formedness
/// contract [`assert_closed_set_well_formed`]'s clause (1) — a
/// closed set with zero variants is a degenerate codomain the
/// substrate rejects at the well-formedness boundary — so the
/// endpoint anchors emit a bare typed variant with no [`Option`]
/// / [`Result`] indirection.
///
/// The (endpoint × direction) 1×2 matrix over the closed-set
/// endpoint-anchor surface partitions post-lift:
///
/// | Endpoint direction | Anchor surface |
/// |---------------------------|----------------------|
/// | Declaration-order head | [`Self::first`] |
/// | Declaration-order tail | [`Self::last`] |
///
/// Default body composes ONE substrate primitive ([`Self::ALL`])
/// with the standard-library slice-index-0 projection — the head
/// anchor is a typed CONSEQUENCE of [`Self::ALL`] + the non-empty
/// contract, not a per-implementor `const HEAD: Self = ...`
/// declaration. Implementors override only when the endpoint
/// surface needs to diverge from the natural `ALL[0]` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_labels` / `sorted_variants` / `from_index` overrides
/// exist — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl).
///
/// Future consumers — a config-field decoder that binds the
/// closed-set's canonical default without hand-rolling a per-
/// implementor `const DEFAULT: T = T::Alpha` declaration (a
/// `serde` deserializer wrapper that folds a missing field onto
/// [`Self::first`], a `Default` impl generator that emits
/// `impl Default for T { fn default() -> T { T::first() } }` at
/// derive time), a truth-table property test that anchors at
/// [`Self::first`] / [`Self::last`] as its declaration-order edges
/// (a quickcheck-shaped variant generator that iterates from the
/// head to the tail through `from_index` and pins the endpoints
/// through this pair), a wire-format decoder that emits an
/// out-of-band "reset to head" sentinel decoded through
/// [`Self::first`], a state-machine iterator that walks the
/// declaration-order chain from [`Self::first`] toward
/// [`Self::last`] via [`Self::from_index`] — bind to ONE trait
/// method instead of hand-rolling either the `Self::ALL[0]` slice
/// indexing (which re-derives the same one-primitive projection
/// at every callsite AND makes every downstream site depend on
/// `Self::ALL`'s slice-index API) OR the
/// `Self::from_index(0).unwrap()` composition (which pays an
/// [`Option`]-typed dispatch the closed-set non-empty contract
/// structurally forbids), and the closed-set endpoint-anchor
/// surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (declaration-order head
/// endpoint) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline `Self::ALL[0]` composition
/// at every downstream anchor site. The (head, tail) endpoint-
/// direction axis partitions the closed-set endpoint-anchor
/// surface exhaustively into TWO typed projections, each with a
/// distinct load-bearing consumer surface — the head for
/// canonical defaulters / iterator-start anchors, the tail for
/// iterator-terminator / bounded-loop guards.
/// THEORY.md §V.1 — knowable platform; the (declaration-order
/// head endpoint) projection was an unnamed compound of
/// [`Self::ALL`] + slice-index-0 pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of
/// [`Self::ALL`] alone — generic consumers see ONE method, not
/// ONE endpoint-shape-per-crate. The well-formedness clause (18)
/// pins [`Self::first`] against `T::ALL[0]` on every implementor
/// so a passing well-formedness sweep means every generic
/// consumer can call [`Self::first`] on any typed variant without
/// threading an [`Option`] through the return.
/// THEORY.md §VI.1 — generation over composition; the
/// (declaration-order head endpoint) projection emerges from the
/// composition of ONE substrate primitive ([`Self::ALL`]) with
/// the standard-library slice-index-0 projection rather than as
/// a per-implementor `const HEAD: Self = ...` declaration. A
/// future tightening of [`Self::ALL`] (a future
/// `#[closed_set(cardinality = N)]` derive attribute that pins N
/// at the source, a future declaration-time endpoint-assertion)
/// propagates to every closed-set endpoint-anchor consumer
/// through ONE trait method.
///
/// Frontier inspiration: Racket's `enum-first` / `enum-last` on
/// closed enumerations, Idris's `Fin n` finite-cardinality type's
/// `firstFin : Fin (S n)` / `lastFin : Fin (S n)` panic-free
/// endpoint constructors on the non-empty finite-type universe,
/// MLIR's `RegisteredOperationName::begin() / end()` on the Op
/// registry, Haskell's `bounded` type-class `minBound` /
/// `maxBound` axis over closed enumerations — bounded-type
/// endpoint anchors exposed as bare typed values rather than
/// [`Option`]-wrapped decodes. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::ALL`] surface with the standard-library
/// slice-index-0 projection — no new dep, no new IR layer, no
/// supertrait bound, no [`Option`]-typed dispatch.
fn first() -> Self {
Self::ALL[0]
}
/// The declaration-order last variant of the closed set —
/// `Self::ALL[Self::ALL.len() - 1]` projected onto the trait
/// surface as a panic-free typed anchor. Closes the
/// (endpoint = `CARDINALITY - 1`) corner of the closed-set
/// endpoint-anchor axis.
///
/// Sibling posture to [`Self::first`] one axis over on the
/// (endpoint = 0, endpoint = `CARDINALITY - 1`) partition of the
/// closed-set endpoint surface: [`Self::first`] returns the
/// declaration-order head, this method returns the
/// declaration-order tail. See [`Self::first`] for the shared
/// design rationale, sibling matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the (endpoint = `CARDINALITY - 1`)
/// arm of the same axis and inherits every property from the
/// (endpoint = 0) arm's documentation, differing only in the
/// concrete slice-index projection.
///
/// Default body composes ONE substrate primitive ([`Self::ALL`])
/// with the standard-library slice-index-`(N - 1)` projection —
/// the tail anchor is a typed CONSEQUENCE of [`Self::ALL`] + the
/// non-empty contract, not a per-implementor `const TAIL: Self =
/// ...` declaration. Both the `Self::ALL.len() - 1` subtraction
/// AND the subsequent indexing are guaranteed sound by the
/// well-formedness contract [`assert_closed_set_well_formed`]'s
/// clause (1) — `Self::ALL` is non-empty, so `Self::ALL.len()`
/// is `>= 1`, and the subtraction never underflows. The
/// well-formedness clause (18) pins [`Self::last`] against
/// `T::ALL[T::ALL.len() - 1]` on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// [`Self::last`] on any typed variant without threading an
/// [`Option`] through the return.
fn last() -> Self {
Self::ALL[Self::ALL.len() - 1]
}
/// The declaration-order head-endpoint label — `T::first().label()`
/// projected onto the trait surface as ONE call. Closes the
/// (`Self`, `&'static str`) return-type axis on the declaration-
/// axis (head, tail) endpoint-anchor partition at the head slot.
///
/// Sibling posture to [`Self::first`] one return-type axis over on
/// the (typed-variant `Self`, canonical-label `&'static str`)
/// partition of the closed-set declaration-axis head-endpoint
/// return-shape column — [`Self::first`] materializes the typed
/// head-endpoint variant, this method materializes its canonical
/// label WITHOUT threading the caller through the two-hop
/// `T::first().label()` composition. Sibling posture to
/// [`Self::endpoint_labels`] one aggregation-shape axis over on
/// the (single-slot `&'static str`, pair-tuple `(&'static str,
/// &'static str)`) partition of the closed-set declaration-axis
/// endpoint-label return-shape column — [`Self::endpoint_labels`]
/// aggregates BOTH endpoint-anchor labels into a tuple, this
/// method returns ONLY the head-endpoint label without forcing
/// the caller to destructure the pair and drop the tail slot.
///
/// The (return-type × endpoint-direction) 2×2 matrix over the
/// declaration-axis endpoint-anchor return-shape column partitions
/// post-lift:
///
/// | Return type \\ Endpoint | Head | Tail |
/// |--------------------------|--------------------------|-------------------------|
/// | `Self` (typed variant) | [`Self::first`] | [`Self::last`] |
/// | `&'static str` (label) | [`Self::first_label`] | [`Self::last_label`] |
///
/// Every generic consumer that wants the declaration-order head-
/// endpoint canonical label as ONE `&'static str` (a static
/// diagnostic banner that renders `"first: <head-label>"` without
/// materializing the typed anchor, a bounded-loop guard that
/// short-circuits on `s == T::first_label()` before decoding the
/// input string into a typed variant, a per-implementor coherence
/// probe that anchors an edge assertion at the head-endpoint
/// label slot, a completion UI that renders the declaration head
/// anchor by label without threading the caller through a
/// `T::first().label()` two-primitive composition) binds to ONE
/// typed method rather than hand-rolling either the
/// `T::first().label()` composition (which re-derives the same
/// two-primitive projection at every callsite) OR a per-
/// implementor `HEAD_LABEL: &'static str = "..."` const that
/// silently drifts from [`Self::label`] on rename.
///
/// Default body composes ONE substrate primitive
/// ([`Self::first`]) with the per-slot [`Self::label`] projection
/// — the head-endpoint label is a typed CONSEQUENCE of the
/// (typed head anchor) primitive composed with the (label
/// projection) primitive, not a per-implementor `const HEAD_LABEL:
/// &'static str = "..."` declaration. Implementors override only
/// when the head-endpoint label needs to diverge from the natural
/// `T::first().label()` shape (no production implementor reaches
/// for this today; the axis exists for the same reason `via` /
/// `set_label` / `labels` / `first` / `last` / `endpoint_labels`
/// overrides exist — a typed escape hatch rather than forcing
/// the implementor to hand-roll the impl). An implementor that
/// overrides [`Self::first`] OR overrides [`Self::label`]
/// propagates the override through this default body
/// automatically; the head-endpoint-label surface funnels through
/// the declaration head-anchor primitive on the anchor-materialization
/// column AND the per-slot label projection on the rendering
/// column.
///
/// The head-endpoint-label contract — `T::first_label() ==
/// T::first().label()` on every implementor — is guaranteed by
/// the default composition through [`Self::first`] and
/// [`Self::label`]; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (46) pins the
/// composition against the natural `T::first().label()` shape on
/// every implementor so a passing well-formedness sweep means
/// every generic consumer can call [`Self::first_label`] on any
/// typed carrier and expect the same `&'static str` answer at
/// every crate boundary.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] returns the sole
/// variant and this method returns its label, mirroring
/// [`Self::last_label`]'s singleton behavior one endpoint-
/// direction axis over. Both head and tail label projections
/// collapse onto the same label, preserving the label
/// projection SHAPE at the boundary-cardinality edge where the
/// two SLOTS collapse onto the same anchor.
///
/// THEORY.md §III — the typescape; the (declaration head anchor →
/// canonical label) singular projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `T::first().label()` two-primitive composition at every
/// downstream head-label rendering site.
/// THEORY.md §V.1 — knowable platform; the (declaration head
/// anchor → label) projection was an unnamed compound of
/// [`Self::first`] + [`Self::label`] pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of TWO
/// substrate primitives — generic consumers see ONE method, not
/// one head-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (declaration
/// head anchor → label) projection emerges from the composition
/// of TWO substrate primitives ([`Self::first`], [`Self::label`])
/// rather than as a per-implementor `const HEAD_LABEL: &'static
/// str = "..."` declaration. A future tightening of either
/// primitive (a future perfect-hash label lookup, a future
/// const-fn axis that makes the projection callable in const
/// contexts) propagates to every closed-set head-label consumer
/// through this method's body.
///
/// Frontier inspiration: Racket's `enum-first-label` on closed
/// enumerations (the singular head-anchor-label projection on the
/// declaration-order chain); Idris's `showFirst` on `Fin (S n)`
/// non-empty finite-cardinality head-anchor projections; Haskell's
/// `show minBound` on the `Bounded + Show` type-class pair (the
/// head-anchor-label rendering composed from two prelude
/// primitives on the bounded chain); MLIR's
/// `RegisteredOperationName::begin_name()` on the declaration-
/// order Op registry; Rust's `strum::EnumIter::next().map(|v|
/// v.get_str())` composed through the iterator API. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::first`] surface with the per-slot
/// [`Self::label`] projection — no new dep, no new IR layer, no
/// supertrait bound, no allocation.
fn first_label() -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::first())
}
/// The declaration-order tail-endpoint label — `T::last().label()`
/// projected onto the trait surface as ONE call. Closes the
/// (`Self`, `&'static str`) return-type axis on the declaration-
/// axis (head, tail) endpoint-anchor partition at the tail slot.
///
/// Sibling posture to [`Self::first_label`] one endpoint-direction
/// axis over on the (head, tail) partition of the declaration-
/// axis endpoint-label return-shape column: [`Self::first_label`]
/// returns the declaration-order head-anchor label, this method
/// returns the declaration-order tail-anchor label. See
/// [`Self::first_label`] for the shared design rationale, sibling
/// matrix, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the tail-
/// direction arm of the same axis and inherits every property
/// from the head arm's documentation, differing only in the
/// composition through [`Self::last`] instead of [`Self::first`].
///
/// Default body composes ONE substrate primitive ([`Self::last`])
/// with the per-slot [`Self::label`] projection. The tail-endpoint-
/// label contract — `T::last_label() == T::last().label()` on
/// every implementor — is guaranteed by the default composition;
/// the well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (47) pins the composition against the natural
/// `T::last().label()` shape on every implementor.
///
/// Clauses (18) + (34) + (36) + (46) + (47) together CLOSE the
/// (return-type × endpoint-direction × aggregation-shape) 2×2×2
/// = 8-corner projection cube on the declaration-axis endpoint-
/// anchor return-shape surface: [`Self::first`] / [`Self::last`]
/// on (`Self`, head/tail, singular) — clauses (18); [`Self::endpoints`]
/// on ((`Self`, `Self`), (head, tail), pair-tuple) — clause (34);
/// [`Self::endpoint_labels`] on ((`&'static str`, `&'static str`),
/// (head, tail), pair-tuple) — clause (36); and now
/// [`Self::first_label`] / [`Self::last_label`] on (`&'static str`,
/// head/tail, singular) — clauses (46) + (47). Every generic
/// consumer that binds any of the six projection methods sees the
/// SAME endpoint-anchor answer at every crate boundary regardless
/// of which return-type axis / endpoint-direction / aggregation-
/// shape corner it walks.
fn last_label() -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::last())
}
/// The declaration-order head-endpoint DECL-INDEX — `T::first().index_of()`
/// projected onto the trait surface as ONE call. Opens the
/// `usize`-typed return-type column on the declaration-axis (head,
/// tail) endpoint-anchor singular partition at the head slot,
/// mirroring [`Self::first_label`] one return-type axis over on
/// the (`&'static str`, `usize`) return-shape column of the
/// declaration-axis singular endpoint-anchor projection matrix.
///
/// Sibling posture to [`Self::first`] one return-type axis over on
/// the (typed-variant `Self`, decl-order slot `usize`) partition of
/// the closed-set declaration-axis head-endpoint return-shape column
/// — [`Self::first`] materializes the typed head-endpoint variant,
/// this method materializes its decl-slot WITHOUT threading the
/// caller through the two-hop `T::first().index_of()` composition.
/// Sibling posture to [`Self::first_label`] one return-type axis
/// over on the (`&'static str`, `usize`) partition of the closed-
/// set declaration-axis singular head-endpoint return-shape column
/// — [`Self::first_label`] projects the head-endpoint canonical
/// label, this method projects its decl-slot integer coordinate.
///
/// The (return-type × endpoint-direction) 3×2 matrix over the
/// declaration-axis singular endpoint-anchor return-shape column
/// partitions post-lift:
///
/// | Return type \\ Endpoint | Head | Tail |
/// |--------------------------|--------------------------|-------------------------|
/// | `Self` (typed variant) | [`Self::first`] | [`Self::last`] |
/// | `&'static str` (label) | [`Self::first_label`] | [`Self::last_label`] |
/// | `usize` (decl-slot) | [`Self::first_index`] | [`Self::last_index`] |
///
/// Every generic consumer that wants the declaration-order head-
/// endpoint decl-slot as ONE `usize` (a bounded-loop guard that
/// short-circuits when `i == T::first_index()` before decoding the
/// slot into a typed variant, a `<[U]>::get(T::first_index())`
/// parallel-vector lookup on a per-decl-slot side-table, a
/// completion cursor that positions the caret at the head decl-slot
/// coordinate WITHOUT threading the caller through a
/// `T::first().index_of()` two-primitive composition, a bounded-
/// range coherence probe that anchors an edge assertion at the
/// decl-head slot integer coordinate) binds to ONE typed method
/// rather than hand-rolling either the `T::first().index_of()`
/// composition (which re-derives the same two-primitive projection
/// at every callsite AND silently drifts when [`Self::first`] OR
/// [`Self::index_of`] is overridden) OR a per-implementor
/// `const HEAD_INDEX: usize = 0;` const that silently drifts from
/// [`Self::ALL`] on reordering.
///
/// Default body composes ONE substrate primitive
/// ([`Self::first`]) with the per-slot [`Self::index_of`] projection
/// — the head-endpoint decl-slot is a typed CONSEQUENCE of the
/// (typed head anchor) primitive composed with the (decl-index
/// projection) primitive, not a per-implementor
/// `const HEAD_INDEX: usize = 0;` declaration. Implementors override
/// only when the head-endpoint decl-slot needs to diverge from the
/// natural `T::first().index_of()` shape (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `first` / `last` /
/// `endpoint_labels` / `first_label` overrides exist — a typed
/// escape hatch rather than forcing the implementor to hand-roll
/// the impl). An implementor that overrides [`Self::first`] OR
/// overrides [`Self::index_of`] propagates the override through
/// this default body automatically; the head-endpoint-decl-slot
/// surface funnels through the declaration head-anchor primitive
/// on the anchor-materialization column AND the per-slot decl-
/// index projection on the coordinate-rendering column.
///
/// The head-endpoint-decl-slot contract — `T::first_index() ==
/// T::first().index_of() == 0` on every implementor — is guaranteed
/// by the default composition through [`Self::first`] and
/// [`Self::index_of`]; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (88) pins the
/// composition against the natural `T::first().index_of()` shape
/// AND against the literal `0` fixpoint on every implementor so
/// a passing well-formedness sweep means every generic consumer
/// can call [`Self::first_index`] on any typed carrier and expect
/// the same `usize` answer at every crate boundary.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] returns the sole variant
/// and this method returns its decl-slot `0`. The singleton edge is
/// the boundary-cardinality case where the head-endpoint decl-slot
/// AND the tail-endpoint decl-slot ([`Self::last_index`] on the
/// same singleton returns `T::CARDINALITY - 1 == 0`) AND the sole
/// interior-less variant's decl-slot all collapse onto the same `0`
/// anchor.
///
/// THEORY.md §III — the typescape; the (declaration head anchor →
/// decl-slot) singular projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline `T::first().index_of()`
/// two-primitive composition at every downstream head-slot lookup
/// site. Opens the `usize` return-type row on the (return-type ×
/// endpoint-direction) singular endpoint-anchor projection matrix.
/// THEORY.md §V.1 — knowable platform; the (declaration head anchor
/// → decl-slot) projection was an unnamed compound of
/// [`Self::first`] + [`Self::index_of`] pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of TWO substrate
/// primitives — generic consumers see ONE method, not one head-
/// decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (declaration
/// head anchor → decl-slot) projection emerges from the composition
/// of TWO substrate primitives ([`Self::first`], [`Self::index_of`])
/// rather than as a per-implementor `const HEAD_INDEX: usize = 0;`
/// declaration. A future tightening of either primitive (a future
/// perfect-hash forward projection, a future const-fn axis that
/// makes the projection callable in const contexts, a future
/// non-zero-based decl-slot extension for sparse closed sets)
/// propagates to every closed-set head-decl-slot consumer through
/// this method's body.
///
/// Frontier inspiration: Racket's `enum-first-index` on closed
/// enumerations under a canonical index projection (the singular
/// head-anchor decl-slot projection on the declaration-order chain);
/// Idris's `FZ : Fin (S n)` on the non-empty finite-cardinality
/// head-anchor slot (the typed zeroth element of a bounded chain);
/// Haskell's `fromEnum minBound` on the `Bounded + Enum` type-class
/// pair (the head-anchor decl-slot rendering composed from two
/// prelude primitives on the bounded chain); MLIR's
/// `RegisteredOperationName::begin_index()` on the declaration-
/// order Op registry; Rust's `strum::EnumIter::next().map(|v|
/// v as usize)` composed through the iterator API. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::first`] surface with the per-slot
/// [`Self::index_of`] projection — no new dep, no new IR layer,
/// no supertrait bound, no allocation.
fn first_index() -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::first())
}
/// The declaration-order tail-endpoint DECL-INDEX — `T::last().index_of()`
/// projected onto the trait surface as ONE call. Closes the
/// (`usize`, tail) corner of the (return-type × endpoint-direction)
/// 3×2 declaration-axis singular endpoint-anchor return-shape matrix
/// alongside [`Self::first`] (`Self`, head), [`Self::last`] (`Self`,
/// tail), [`Self::first_label`] (`&'static str`, head),
/// [`Self::last_label`] (`&'static str`, tail), and its head-direction
/// sibling [`Self::first_index`] (`usize`, head).
///
/// Sibling posture to [`Self::first_index`] one endpoint-direction
/// axis over on the (head, tail) partition of the declaration-axis
/// singular endpoint-anchor `usize`-return-shape column:
/// [`Self::first_index`] projects the head-endpoint decl-slot
/// (structurally `0`), this method projects the tail-endpoint decl-
/// slot (structurally `T::CARDINALITY - 1`). See [`Self::first_index`]
/// for the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the tail-direction arm of the same
/// axis and inherits every property from the head arm's
/// documentation, differing only in the composition through
/// [`Self::last`] instead of [`Self::first`] AND in the structural
/// fixpoint `T::CARDINALITY - 1` instead of `0`.
///
/// The (return-type × endpoint-direction) 3×2 declaration-axis
/// singular endpoint-anchor return-shape matrix partitions post-lift:
///
/// | Return type \\ Endpoint | Head | Tail |
/// |--------------------------|--------------------------|-------------------------|
/// | `Self` (typed variant) | [`Self::first`] | [`Self::last`] |
/// | `&'static str` (label) | [`Self::first_label`] | [`Self::last_label`] |
/// | `usize` (decl-slot) | [`Self::first_index`] | [`Self::last_index`] |
///
/// Every generic consumer that wants the declaration-order tail-
/// endpoint decl-slot as ONE `usize` (a bounded-loop guard that
/// short-circuits when `i == T::last_index()` before decoding the
/// slot into a typed variant, a `<[U]>::get(T::last_index())`
/// parallel-vector lookup on a per-decl-slot side-table at the tail
/// anchor, a completion cursor that positions the caret at the tail
/// decl-slot coordinate WITHOUT threading the caller through a
/// `T::last().index_of()` two-primitive composition, a bounded-range
/// coherence probe that anchors an edge assertion at the decl-tail
/// slot integer coordinate, an emptiness-guarded reverse-walk sink
/// that terminates at the tail decl-slot literal) binds to ONE typed
/// method rather than hand-rolling either the `T::last().index_of()`
/// composition (which re-derives the same two-primitive projection at
/// every callsite AND silently drifts when [`Self::last`] OR
/// [`Self::index_of`] is overridden) OR a per-implementor
/// `const TAIL_INDEX: usize = T::CARDINALITY - 1;` const that
/// silently drifts from [`Self::ALL`] on any addition or removal.
///
/// Default body composes ONE substrate primitive ([`Self::last`])
/// with the per-slot [`Self::index_of`] projection — the tail-
/// endpoint decl-slot is a typed CONSEQUENCE of the (typed tail
/// anchor) primitive composed with the (decl-index projection)
/// primitive, not a per-implementor
/// `const TAIL_INDEX: usize = T::CARDINALITY - 1;` declaration. An
/// implementor that overrides [`Self::last`] OR overrides
/// [`Self::index_of`] propagates the override through this default
/// body automatically; the tail-endpoint-decl-slot surface funnels
/// through the declaration tail-anchor primitive on the anchor-
/// materialization column AND the per-slot decl-index projection on
/// the coordinate-rendering column.
///
/// The tail-endpoint-decl-slot contract — `T::last_index() ==
/// T::last().index_of() == T::CARDINALITY - 1` on every implementor
/// — is guaranteed by the default composition through [`Self::last`]
/// and [`Self::index_of`]; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (89) pins the
/// composition against the natural `T::last().index_of()` shape AND
/// against the `T::CARDINALITY - 1` structural fixpoint on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call [`Self::last_index`] on any typed
/// carrier and expect the same `usize` answer at every crate
/// boundary.
///
/// Clauses (18) + (46) + (47) + (88) + (89) together CLOSE the
/// (return-type × endpoint-direction) 3×2 = 6-corner declaration-
/// axis singular endpoint-anchor return-shape matrix at ALL SIX
/// corners: (`Self`, head/tail) at clauses (18) — [`Self::first`] /
/// [`Self::last`]; (`&'static str`, head/tail) at clauses (46) +
/// (47) — [`Self::first_label`] / [`Self::last_label`]; and now
/// (`usize`, head/tail) at clauses (88) + (89) — [`Self::first_index`]
/// and this method. Every generic consumer that binds any of the
/// six singular endpoint-anchor projection methods sees the SAME
/// endpoint-anchor answer at every crate boundary regardless of
/// which return-type axis / endpoint-direction corner it walks.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::last`] returns the sole variant
/// and this method returns its decl-slot `0` (since
/// `T::CARDINALITY - 1 == 0`). The singleton edge is the boundary-
/// cardinality case where the head-endpoint decl-slot
/// ([`Self::first_index`]) AND the tail-endpoint decl-slot (this
/// method) AND the sole interior-less variant's decl-slot all
/// collapse onto the same `0` anchor, preserving the decl-slot
/// projection SHAPE at the boundary-cardinality edge where the two
/// SLOTS collapse onto the same anchor.
///
/// THEORY.md §III — the typescape; the (declaration tail anchor →
/// decl-slot) singular projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline `T::last().index_of()`
/// two-primitive composition at every downstream tail-slot lookup
/// site. Closes the `usize` return-type row on the (return-type ×
/// endpoint-direction) singular endpoint-anchor projection matrix at
/// the tail slot.
/// THEORY.md §V.1 — knowable platform; the (declaration tail anchor
/// → decl-slot) projection was an unnamed compound of
/// [`Self::last`] + [`Self::index_of`] pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of TWO substrate
/// primitives — generic consumers see ONE method, not one tail-
/// decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (declaration
/// tail anchor → decl-slot) projection emerges from the composition
/// of TWO substrate primitives ([`Self::last`], [`Self::index_of`])
/// rather than as a per-implementor
/// `const TAIL_INDEX: usize = T::CARDINALITY - 1;` declaration. A
/// future tightening of either primitive (a future perfect-hash
/// backward projection, a future const-fn axis that makes the
/// projection callable in const contexts, a future non-zero-based
/// decl-slot extension for sparse closed sets) propagates to every
/// closed-set tail-decl-slot consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-last-index` on closed
/// enumerations under a canonical index projection (the singular
/// tail-anchor decl-slot projection on the declaration-order chain);
/// Idris's `last : Fin (S n)` on the non-empty finite-cardinality
/// tail-anchor slot (the typed `n`-th element of a bounded chain);
/// Haskell's `fromEnum maxBound` on the `Bounded + Enum` type-class
/// pair (the tail-anchor decl-slot rendering composed from two
/// prelude primitives on the bounded chain); MLIR's
/// `RegisteredOperationName::end_index()` on the declaration-order
/// Op registry; Rust's `strum::EnumIter::last().map(|v| v as usize)`
/// composed through the iterator API. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::last`] surface with the per-slot [`Self::index_of`]
/// projection — no new dep, no new IR layer, no supertrait bound,
/// no allocation.
fn last_index() -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::last())
}
/// The declaration-order head-endpoint LABEL predicate — `true`
/// iff `s` equals [`Self::first_label`], `false` otherwise. Closes
/// the (arg-type × endpoint-direction) 2×2 declaration-axis
/// endpoint-membership matrix at the (`&str`, head) corner
/// alongside [`Self::is_first`] (Self, head), [`Self::is_last`]
/// (Self, tail), and its tail-direction sibling
/// [`Self::is_last_label`] (&str, tail).
///
/// The (arg-type × endpoint-direction) 2×2 endpoint-membership
/// matrix over the declaration-axis surface partitions post-lift:
///
/// | Arg-type \\ Endpoint | Head | Tail |
/// |-----------------------|-------------------------------|------------------------------|
/// | `Self` (variant) | [`Self::is_first`] | [`Self::is_last`] |
/// | `&str` (label) | [`Self::is_first_label`] | [`Self::is_last_label`] |
///
/// Sibling posture to [`Self::first_label`] one return-type axis
/// over on the (`&'static str`-returning label projection,
/// `bool`-returning label predicate) partition — [`Self::first_label`]
/// projects the declaration-order head-endpoint label,
/// this method answers "is this &str the declaration-order head-
/// endpoint label?" without threading the caller through a
/// per-callsite `s == T::first_label()` comparison. Sibling
/// posture to [`Self::is_first`] one arg-type axis over on the
/// (Self, &str) partition — [`Self::is_first`] answers "am I at
/// the head endpoint?" for a typed variant, this method answers
/// the same question for a raw label string WITHOUT decoding
/// through [`Self::parse_label`] or [`Self::find_by_label`]
/// (which would allocate the reject carrier on non-matching
/// inputs OR force the caller through the `Option<Self>`-typed
/// dispatch).
///
/// Every generic consumer that wants a zero-alloc O(1)
/// label-shaped head-boundary query (a streaming Lisp reader
/// that short-circuits on the head-anchor label before
/// materializing a typed variant, a CLI subcommand dispatcher
/// that folds the head-anchor label onto a special "default"
/// path, a serde deserializer wrapper that treats the head-
/// anchor label as a canonical default alignment, a
/// `tatara-check` diagnostic renderer that emits an anchored
/// `"expected first: <head-label>"` banner ONLY when the offending
/// input equals the head label — a distinguished error shape,
/// not the generic `"expected one of: A, B, C"` shape) binds to
/// ONE typed predicate rather than hand-rolling either the
/// `s == T::first_label()` inline comparison (which re-derives
/// the same one-primitive projection at every callsite AND
/// silently drifts when [`Self::first_label`] is overridden) OR
/// the two-primitive `T::find_by_label(s).map(<T as ClosedSet>::is_first)
/// .unwrap_or(false)` composition (which forces the caller through
/// the `Option<Self>`-typed dispatch AND folds the not-a-label
/// input onto `false` implicitly rather than by direct `&str`
/// equality).
///
/// Default body composes ONE substrate primitive
/// ([`Self::first_label`]) with the standard-library `&str`
/// equality operator — the label-shaped head-membership predicate
/// is a typed CONSEQUENCE of the (declaration-order head label)
/// projection, not a per-implementor `match s { "head-label" =>
/// true, _ => false }` block. Implementors override only when
/// the label-shaped head-membership surface needs to diverge
/// from the natural `s == T::first_label()` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `first` /
/// `first_label` overrides exist — a typed escape hatch rather
/// than forcing the implementor to hand-roll the impl). An
/// implementor that overrides [`Self::first_label`] propagates
/// the override through this default body automatically; the
/// (label → bool head-membership) projection funnels through ONE
/// typed primitive.
///
/// The label-shaped head-membership contract —
/// `T::is_first_label(T::first().label()) == true` AND
/// `T::is_first_label(v.label()) == false` for every non-first
/// canonical variant `v` on every implementor — is guaranteed by
/// the composition through [`Self::first_label`] AND the label-
/// pairwise-distinctness contract clause (3); the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (50)
/// pins the composition against the natural
/// `s == T::first_label()` shape on every implementor across every
/// canonical variant label AND the reserved probe input AND the
/// empty-string boundary so a passing well-formedness sweep means
/// every generic consumer can call [`Self::is_first_label`] on any
/// `&str` input at any crate boundary and expect the same `bool`
/// answer as the natural composition.
///
/// Not-a-label boundary — for any input `s` that is not a
/// canonical label of [`T::ALL`] (the reserved probe, the empty
/// string, an unknown token), this predicate returns `false`
/// (the equality against [`Self::first_label`] fails structurally
/// — the head label is by clause (4) non-empty and is by clause
/// (3) distinct from every other canonical label AND is by
/// the probe's construction distinct from any input that lands
/// in the substrate's `make_unknown` carrier). Callers that want
/// "is this a valid label AND the head label" compose this
/// predicate with [`Self::contains_label`] at the callsite;
/// callers that want "is this the head label OR reject as
/// unknown" compose this predicate with the natural `!` inversion.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first_label`] equals
/// [`Self::last_label`] (both project the sole canonical label)
/// so this predicate and [`Self::is_last_label`] collapse onto
/// the same `&str` equality check, mirroring [`Self::is_first`]
/// and [`Self::is_last`]'s singleton collapse at the (Self, bool)
/// arm one arg-type axis over.
///
/// THEORY.md §III — the typescape; the (label → head-membership
/// bool) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `s == T::first_label()` comparison
/// at every downstream label-shaped head-boundary query site.
/// THEORY.md §V.1 — knowable platform; the (label → head-
/// membership) projection was an unnamed compound of
/// [`Self::first_label`] + `&str` `==` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of ONE substrate
/// primitive — generic consumers see ONE method, not one label-
/// shaped-head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (label →
/// head-membership) projection emerges from the composition of
/// [`Self::first_label`] with the standard-library `&str` equality
/// operator rather than as a per-implementor `match s { ... }`
/// block. A future tightening of [`Self::first_label`] (a future
/// perfect-hash forward projection, a future const-fn axis that
/// makes the predicate callable in const contexts, a future
/// case-insensitive-label extension threaded through the head-
/// label default) propagates to every closed-set label-shaped
/// head-boundary consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-first-label?` on closed
/// enumerations under a canonical labeling (the label-shaped
/// head-membership predicate on the declaration-order chain);
/// Idris's `isFirstLabel : String -> Bool` on a `Show`ed `Fin (S n)`
/// composed via `showFin fZ == s` on the head-anchor slot;
/// Haskell's `(== show (minBound :: T))` on the `Bounded + Show`
/// type-class pair (the head-label equality check composed from
/// three prelude primitives on the bounded chain); MLIR's
/// `RegisteredOperationName::isBeginName(name)` on the
/// declaration-order Op registry; Rust's `strum::EnumIter::next()
/// .map(|v| v.get_str() == s).unwrap_or(false)` composed through
/// the iterator API. Translation through pleme-io primitives: a
/// pure default method composing the trait's existing
/// [`Self::first_label`] surface with the standard-library `&str`
/// equality operator — no new dep, no new IR layer, no supertrait
/// bound, no allocation, no [`Option`]-typed dispatch.
fn is_first_label(s: &str) -> bool {
s == <Self as ClosedSet>::first_label()
}
/// The declaration-order tail-endpoint LABEL predicate — `true`
/// iff `s` equals [`Self::last_label`], `false` otherwise.
/// Closes the (`&str`, tail) corner of the (arg-type ×
/// endpoint-direction) 2×2 declaration-axis endpoint-membership
/// matrix alongside [`Self::is_first`] (Self, head),
/// [`Self::is_last`] (Self, tail), and [`Self::is_first_label`]
/// (&str, head), completing the (arg-type × endpoint-direction)
/// 2×2 declaration-axis label-and-variant endpoint-membership
/// square.
///
/// Sibling posture to [`Self::is_first_label`] one endpoint-
/// direction axis over on the (head, tail) partition of the
/// declaration-axis label-shaped endpoint-membership surface:
/// [`Self::is_first_label`] answers "is this &str the
/// declaration-order head-endpoint label?", this method answers
/// "is this &str the declaration-order tail-endpoint label?".
/// See [`Self::is_first_label`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the tail-direction arm of the same axis and inherits every
/// property from the head arm's documentation, differing only in
/// the composition through [`Self::last_label`] instead of
/// [`Self::first_label`].
///
/// Default body composes ONE substrate primitive
/// ([`Self::last_label`]) with the standard-library `&str`
/// equality operator. The label-shaped tail-membership contract —
/// `T::is_last_label(T::last().label()) == true` AND
/// `T::is_last_label(v.label()) == false` for every non-last
/// canonical variant `v` on every implementor — is guaranteed by
/// the composition; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (51) pins the
/// composition against the natural `s == T::last_label()` shape
/// on every implementor across every canonical variant label AND
/// the reserved probe input AND the empty-string boundary.
///
/// Clauses (30) + (31) + (32) + (33) + (50) + (51) together open
/// the (arg-type × ordering × endpoint-direction) 2×2×2 = 8-corner
/// endpoint-membership hypercube at SIX of the eight corners on
/// the closed-set endpoint-membership surface: (Self,
/// declaration, head/tail) at clauses (30) — [`Self::is_first`] /
/// [`Self::is_last`]; (Self, lex, head/tail) at clauses (31) —
/// [`Self::is_sorted_first`] / [`Self::is_sorted_last`]; (&str,
/// declaration, head/tail) at clauses (50) + (51) — this method
/// and its head-direction sibling [`Self::is_first_label`]. The
/// remaining two corners on the (`&str`, lex, head/tail) column
/// (`is_sorted_first_label(s: &str) -> bool` and
/// `is_sorted_last_label(s: &str) -> bool`) are the natural next
/// lift on the lex-axis of the label-shaped endpoint-membership
/// hypercube.
fn is_last_label(s: &str) -> bool {
s == <Self as ClosedSet>::last_label()
}
/// The declaration-order head-endpoint membership predicate —
/// `true` when `self` is [`Self::first`], `false` otherwise.
/// Closes the (endpoint-anchor `Self`-returning, endpoint-membership
/// `bool`-returning) return-type axis over the (head, tail) partition
/// of the declaration-axis endpoint surface.
///
/// The (return-type × endpoint-direction) 2×2 matrix over the
/// declaration-axis endpoint-anchor surface partitions post-lift:
///
/// | Return type \\ Endpoint | Head | Tail |
/// |----------------------------|---------------------|--------------------|
/// | `Self` (anchor) | [`Self::first`] | [`Self::last`] |
/// | `bool` (membership) | [`Self::is_first`] | [`Self::is_last`] |
///
/// Sibling posture to [`Self::first`] one return-type axis over —
/// [`Self::first`] projects the head-endpoint variant, this method
/// answers "am I at the head endpoint?" without threading the caller
/// through a supertrait [`PartialEq`] bound the [`ClosedSet`] trait
/// deliberately does not require. Every generic consumer that
/// wants an O(1) head-boundary query (a bounded-loop guard that
/// short-circuits before `Self::prev` returns [`None`], a saga-step
/// engine that emits a "reset" event on the head-endpoint slot, a
/// truth-table property test that anchors an edge assertion at the
/// head-endpoint slot, a wraparound-cursor renderer that highlights
/// the head anchor before wrapping) binds to ONE typed predicate
/// rather than hand-rolling either the `self.index_of() == 0`
/// composition (which re-derives the same one-primitive projection
/// at every callsite) OR the `Self::PartialEq`-bounded
/// `self == Self::first()` comparison (which the trait's minimal
/// supertrait pair `Sized + Copy` structurally forbids).
///
/// Default body composes ONE substrate primitive
/// ([`Self::index_of`]) with an `usize` equality check against `0`
/// — the head-membership predicate is a typed CONSEQUENCE of the
/// (variant → declaration-order position) forward projection, not a
/// per-implementor `match self { Self::Head => true, _ => false }`
/// block. Implementors override only when the head-membership
/// surface needs to diverge from the natural
/// `index_of(self) == 0` shape (no production implementor reaches
/// for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `first` overrides exist — a
/// typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl). An implementor
/// that overrides [`Self::index_of`] propagates the override
/// through this default body automatically; the (variant → bool
/// head-membership) projection funnels through ONE typed primitive.
///
/// The head-membership contract — `T::first().is_first() == true`
/// on every implementor — is guaranteed by the composition through
/// [`Self::index_of`]'s `0`-slot projection clause (15) pins on
/// every declaration-order head; the well-formedness clause (30)
/// pins the composition against the natural
/// `index_of(self) == 0` shape AND the head-endpoint `true` fixpoint
/// on every implementor so a passing well-formedness sweep means
/// every generic consumer can call [`Self::is_first`] on any typed
/// variant and expect the same `bool` answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (variant → head-membership
/// bool) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `self.index_of() == 0` composition at
/// every downstream head-boundary query site.
/// THEORY.md §V.1 — knowable platform; the (variant → head-
/// membership) projection was an unnamed compound of
/// [`Self::index_of`] + `usize` `==` `0` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of ONE substrate
/// primitive — generic consumers see ONE method, not one
/// head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// head-membership) projection emerges from the composition of
/// [`Self::index_of`] with the standard-library `usize` equality
/// operator rather than as a per-implementor
/// `match self { ... }` block. A future tightening of
/// [`Self::index_of`] (a future perfect-hash forward projection, a
/// future const-fn axis that makes the predicate callable in const
/// contexts) propagates to every closed-set head-boundary consumer
/// through this method's body.
///
/// Frontier inspiration: Racket's `enum-first?` on closed
/// enumerations (the head-endpoint membership predicate on the
/// declaration-order chain); Idris's `Fin (S n)` finite-cardinality
/// type's `isFZ : Fin (S n) -> Bool` predicate on the head slot of
/// the non-empty finite-type universe; Haskell's `(== minBound)`
/// on the `Bounded + Enum` type-class pair; MLIR's
/// `RegisteredOperationName::isBegin()` on the declaration-order
/// Op registry; Rust's `strum::EnumIter::next().map(|v| v == self)`
/// composed through the iterator API. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::index_of`] surface with the standard-library `usize`
/// equality operator — no new dep, no new IR layer, no supertrait
/// [`PartialEq`] bound, no [`Option`]-typed dispatch.
fn is_first(self) -> bool {
<Self as ClosedSet>::index_of(self) == 0
}
/// The declaration-order tail-endpoint membership predicate —
/// `true` when `self` is [`Self::last`], `false` otherwise.
/// Closes the (bool, tail) corner of the (return-type ×
/// endpoint-direction) 2×2 declaration-axis endpoint matrix
/// alongside [`Self::is_first`].
///
/// Sibling posture to [`Self::is_first`] one axis over on the
/// (head, tail) partition of the declaration-axis endpoint-
/// membership surface: [`Self::is_first`] answers "am I at the
/// head endpoint?", this method answers "am I at the tail
/// endpoint?". See [`Self::is_first`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the tail-direction arm of the same axis and
/// inherits every property from the head arm's documentation,
/// differing only in the `+ 1 == Self::CARDINALITY` boundary
/// check.
///
/// Default body composes [`Self::index_of`] with an `usize`
/// equality check against [`Self::CARDINALITY`] under the natural
/// `+ 1` shift — the tail-membership predicate is a typed
/// CONSEQUENCE of the composition of the (variant → declaration-
/// order position) forward projection with the const-visible
/// variant count, not a per-implementor
/// `match self { Self::Tail => true, _ => false }` block. The
/// `+ 1 == Self::CARDINALITY` shape (rather than
/// `== Self::CARDINALITY - 1`) avoids the `usize` underflow
/// question on the well-formedness contract clause (1)'s
/// non-empty guarantee already forbids — clause (1) pins
/// `Self::CARDINALITY >= 1`, so `Self::CARDINALITY - 1` never
/// underflows in practice, but the `+ 1 ==` form composes without
/// ever performing the subtraction, keeping the projection callable
/// in a future const-fn context without the underflow discharge.
///
/// The tail-membership contract — `T::last().is_last() == true`
/// on every implementor — is guaranteed by the composition
/// through [`Self::index_of`]'s `Self::CARDINALITY - 1`-slot
/// projection clause (15) pins on every declaration-order tail;
/// the well-formedness clause (30) pins the composition against
/// the natural `index_of(self) + 1 == Self::CARDINALITY` shape AND
/// the tail-endpoint `true` fixpoint on every implementor so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::is_last`] on any typed variant and expect the same
/// `bool` answer at every crate boundary.
/// `T::last().is_last() == true` is the natural fixpoint the tail-
/// endpoint anchor and the tail-membership axis share, mirroring
/// the `T::first().is_first() == true` fixpoint on the head-
/// endpoint anchor / head-membership pair.
fn is_last(self) -> bool {
<Self as ClosedSet>::index_of(self) + 1 == <Self as ClosedSet>::CARDINALITY
}
/// The declaration-order head-endpoint INDEX predicate — `true`
/// iff the `usize` argument equals `0` (the declaration-order
/// head-endpoint's array slot in [`Self::ALL`]), `false`
/// otherwise. Closes the `(usize, head)` corner of the
/// (arg-type × endpoint-direction) 3×2 declaration-axis
/// endpoint-membership matrix alongside [`Self::is_first`]
/// (`Self`, head), [`Self::is_last`] (`Self`, tail),
/// [`Self::is_first_label`] (`&str`, head), and
/// [`Self::is_last_label`] (`&str`, tail).
///
/// The (arg-type × endpoint-direction) 3×2 endpoint-membership
/// matrix over the declaration-axis surface partitions post-lift:
///
/// | Arg-type \\ Endpoint | Head | Tail |
/// |-----------------------|-------------------------------|------------------------------|
/// | `Self` (variant) | [`Self::is_first`] | [`Self::is_last`] |
/// | `&str` (label) | [`Self::is_first_label`] | [`Self::is_last_label`] |
/// | `usize` (index) | [`Self::is_first_index`] | [`Self::is_last_index`] |
///
/// Sibling posture to [`Self::is_first`] one arg-type axis over
/// on the (`Self`, `&str`, `usize`) trio — [`Self::is_first`]
/// answers "am I at the declaration-order head endpoint?" for
/// a typed variant, [`Self::is_first_label`] answers the same
/// question for a raw label string, this method answers the
/// same question for a raw `usize` array-slot index WITHOUT
/// decoding through [`Self::from_index`] (which would allocate
/// the `Option<Self>`-typed dispatch on out-of-range inputs)
/// OR through [`Self::label_at`] combined with
/// [`Self::is_first_label`] (which would force the caller
/// through the `Option<&'static str>`-typed dispatch AND the
/// per-callsite `and_then` composition).
///
/// Every generic consumer that wants a zero-alloc O(1)
/// `usize`-shaped head-boundary query (a compact wire codec that
/// short-circuits on the head-anchor slot before materializing
/// a typed variant, a bitset state machine that folds the head-
/// anchor bit onto a canonical default, a Prometheus per-slot
/// bucket renderer that highlights the head-anchor bucket, a
/// `tatara-check` diagnostic renderer that emits an anchored
/// `"expected first slot: 0"` banner ONLY when the offending
/// index equals the head slot — a distinguished error shape,
/// not the generic `"expected one of: 0, 1, 2"` shape, a byte-
/// tagged compact-encoding that treats the head slot as the
/// canonical `0`-tag and folds every other slot onto a shifted
/// tail-arm) binds to ONE typed predicate rather than hand-rolling
/// either the `i == 0` inline comparison (which re-derives the
/// same magic-literal composition at every callsite AND silently
/// drifts when the definition of "declaration-order head slot"
/// gets tightened — a future closed-set that reserves slot `0`
/// for a sentinel and shifts every canonical slot up by one, a
/// future const-fn axis that makes the predicate callable in
/// const contexts) OR the `T::from_index(i).map(<T as
/// ClosedSet>::is_first).unwrap_or(false)` composition (which
/// pays an `Option<Self>`-typed dispatch AND folds the out-of-
/// range boundary onto `false` implicitly rather than by direct
/// `usize` equality).
///
/// Default body is a zero-alloc `usize` equality check against
/// the literal `0` — the index-shaped head-membership predicate
/// is the natural array-slot rendering of the closed-set
/// declaration-order head endpoint. Implementors override only
/// when the index-shaped head-membership surface needs to
/// diverge from the natural `i == 0` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `first` /
/// `first_label` / `is_first_label` overrides exist — a typed
/// escape hatch rather than forcing the implementor to hand-
/// roll the impl).
///
/// The index-shaped head-membership contract —
/// `T::is_first_index(0) == true` AND
/// `T::is_first_index(i) == false` for every
/// `i ∈ 1..T::CARDINALITY` on every implementor — is guaranteed
/// by the natural `usize` equality against `0`; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (74)
/// pins the composition against the natural `i == 0` shape on
/// every implementor across every canonical variant's array slot
/// AND the out-of-range boundary `T::CARDINALITY` probe so a
/// passing well-formedness sweep means every generic consumer
/// can call [`Self::is_first_index`] on any `usize` input at any
/// crate boundary and expect the same `bool` answer as the
/// natural composition.
///
/// Out-of-range boundary — for any input `i` outside
/// `0..T::CARDINALITY` (the canonical `T::CARDINALITY` probe, a
/// large slot like `usize::MAX`, any slot past the tail), this
/// predicate returns `false` (the equality against `0` fails
/// structurally — the head slot is by construction `0` and no
/// out-of-range slot equals `0` under the non-empty-`T::ALL`
/// contract). Callers that want "is this a valid slot AND the
/// head slot" compose this predicate with an `i <
/// T::CARDINALITY` range check at the callsite; callers that
/// want "is this the head slot OR reject as out-of-range"
/// compose this predicate with the natural `!` inversion.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, the sole variant's array slot `0` is
/// BOTH the declaration-order head-endpoint slot AND the
/// declaration-order tail-endpoint slot so this predicate and
/// [`Self::is_last_index`] collapse onto the same `usize`
/// equality check, mirroring [`Self::is_first`] /
/// [`Self::is_last`]'s singleton collapse at the (Self, bool)
/// arm AND [`Self::is_first_label`] / [`Self::is_last_label`]'s
/// singleton collapse at the (`&str`, bool) arm one arg-type
/// axis over.
///
/// THEORY.md §III — the typescape; the (usize → head-membership
/// bool) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `i == 0` comparison at every
/// downstream index-shaped head-boundary query site. Opens the
/// arg-type dimension of the declaration-axis endpoint-membership
/// matrix from the 2×2 (`Self`, `&str`) subset to the 3×2
/// (`Self`, `&str`, `usize`) trio.
/// THEORY.md §V.1 — knowable platform; the (usize →
/// head-membership) projection was an unnamed compound of the
/// `i == 0` comparison pre-lift; naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the closed-set
/// declaration-order head-slot literal — generic consumers see
/// ONE method, not one index-shaped-head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (usize →
/// head-membership) projection emerges from the closed-set
/// declaration-order head-slot literal `0` rather than as a
/// per-implementor `match i { 0 => true, _ => false }` block.
///
/// Frontier inspiration: Racket's `(enum-first-index? enum i)`
/// on a closed enumeration (the index-shaped head-membership
/// predicate composed through the array-position projection);
/// Idris's `isFZ : Fin (S n) -> Bool` composed through `finToNat`
/// on the head-anchor slot of the non-empty finite-type universe;
/// Haskell's `(== 0)` on the `Bounded + Enum` type-class pair's
/// `fromEnum minBound` projection; MLIR's
/// `RegisteredOperationName::isBeginIndex(idx)` on the
/// declaration-order Op registry; Rust's `strum::EnumIter::iter()
/// .position(|v| v == self).map(|i| i == 0).unwrap_or(false)`
/// composed through the iterator API. Translation through pleme-io
/// primitives: a pure default method composing the closed-set
/// declaration-order head-slot literal `0` with the standard-
/// library `usize` equality operator — no new dep, no new IR
/// layer, no supertrait bound, no allocation, no [`Option`]-typed
/// dispatch.
fn is_first_index(i: usize) -> bool {
i == 0
}
/// The declaration-order tail-endpoint INDEX predicate — `true`
/// iff the `usize` argument equals `T::CARDINALITY - 1` (the
/// declaration-order tail-endpoint's array slot in [`Self::ALL`]),
/// `false` otherwise. Closes the `(usize, tail)` corner of the
/// (arg-type × endpoint-direction) 3×2 declaration-axis
/// endpoint-membership matrix alongside [`Self::is_first`]
/// (`Self`, head), [`Self::is_last`] (`Self`, tail),
/// [`Self::is_first_label`] (`&str`, head),
/// [`Self::is_last_label`] (`&str`, tail), and its head-direction
/// sibling [`Self::is_first_index`] (`usize`, head), completing
/// the (arg-type × endpoint-direction) 3×2 declaration-axis
/// index-and-label-and-variant endpoint-membership rectangle.
///
/// Sibling posture to [`Self::is_first_index`] one endpoint-
/// direction axis over on the (head, tail) partition of the
/// declaration-axis index-shaped endpoint-membership surface:
/// [`Self::is_first_index`] answers "is this usize the
/// declaration-order head-endpoint slot?", this method answers
/// "is this usize the declaration-order tail-endpoint slot?".
/// See [`Self::is_first_index`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the tail-direction arm of the same axis and inherits every
/// property from the head arm's documentation, differing only in
/// the composition through the closed-set declaration-order
/// tail-slot literal `T::CARDINALITY - 1` (expressed as
/// `i + 1 == T::CARDINALITY` to avoid the `usize` underflow
/// question on the empty-`T::ALL` boundary the well-formedness
/// clause (1) forbids) instead of the head-slot literal `0`.
///
/// Default body is a zero-alloc `checked_add(1) == Some(CARDINALITY)`
/// composition — the index-shaped tail-membership predicate is
/// the natural array-slot rendering of the closed-set declaration-
/// order tail endpoint. The `checked_add` form (rather than the
/// raw `i + 1 == Self::CARDINALITY` composition) avoids the
/// `usize` overflow question on the `usize::MAX` boundary probe
/// — a raw `i + 1` computation would panic at runtime on
/// `usize::MAX` under `overflow-checks = true`, folding the
/// out-of-range boundary onto a panic while the natural typed
/// answer is `false`. The `Option<usize>`-typed dispatch through
/// `Some(CARDINALITY)` folds the overflow arm onto `None`
/// (structurally not equal to any `Some` variant), preserving
/// the tail-membership predicate's `false`-on-out-of-range
/// contract on every `usize` input including the arithmetic
/// boundary.
///
/// The index-shaped tail-membership contract —
/// `T::is_last_index(T::CARDINALITY - 1) == true` AND
/// `T::is_last_index(i) == false` for every
/// `i ∈ 0..T::CARDINALITY - 1` on every implementor — is
/// guaranteed by the natural `usize` equality against
/// `T::CARDINALITY`; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (75) pins the
/// composition against the natural `i + 1 == T::CARDINALITY`
/// shape on every implementor across every canonical variant's
/// array slot AND the out-of-range boundary `T::CARDINALITY`
/// probe.
///
/// Clauses (30), (31), (32), (33), (50), (51), (52), (53), (74),
/// and (75) together CLOSE the (arg-type × ordering ×
/// endpoint-direction) 3×2×2 = 12-corner endpoint-membership
/// hypercube on the declaration-axis surface at SIX of the twelve
/// corners: (`Self`, declaration, head/tail) at clauses (30) —
/// [`Self::is_first`] / [`Self::is_last`]; (`&str`, declaration,
/// head/tail) at clauses (50) and (51) — [`Self::is_first_label`]
/// and [`Self::is_last_label`]; and now (`usize`, declaration,
/// head/tail) at clauses (74) and (75) — this method and its
/// head-direction sibling. The remaining six corners on the
/// lex-axis column (`is_sorted_first_index`,
/// `is_sorted_last_index`, plus their `Self`-arg /
/// `&str`-arg siblings which already exist as
/// [`Self::is_sorted_first`], [`Self::is_sorted_last`],
/// [`Self::is_sorted_first_label`], and
/// [`Self::is_sorted_last_label`]) leave only the two
/// `(usize, lex, head/tail)` corners as the natural next lift.
fn is_last_index(i: usize) -> bool {
i.checked_add(1) == Some(<Self as ClosedSet>::CARDINALITY)
}
/// The lexicographic-order head-endpoint INDEX predicate — `true`
/// iff the `usize` argument equals `0` (the lex-order head-
/// endpoint's slot in [`Self::sorted_variants`], where the argument
/// is interpreted as a LEX position — the natural output shape of
/// [`Self::sorted_index_of`], [`Self::sorted_next_index`],
/// [`Self::sorted_prev_index`], [`Self::cycle_sorted_next_index`],
/// and [`Self::cycle_sorted_prev_index`]), `false` otherwise.
/// Closes the `(usize, lex, head)` corner of the (arg-type ×
/// ordering × endpoint-direction) 3×2×2 = 12-corner endpoint-
/// membership hypercube alongside [`Self::is_first`] (`Self`,
/// declaration, head), [`Self::is_last`] (`Self`, declaration,
/// tail), [`Self::is_sorted_first`] (`Self`, lex, head),
/// [`Self::is_sorted_last`] (`Self`, lex, tail),
/// [`Self::is_first_label`] (`&str`, declaration, head),
/// [`Self::is_last_label`] (`&str`, declaration, tail),
/// [`Self::is_sorted_first_label`] (`&str`, lex, head),
/// [`Self::is_sorted_last_label`] (`&str`, lex, tail),
/// [`Self::is_first_index`] (`usize`, declaration, head), and
/// [`Self::is_last_index`] (`usize`, declaration, tail).
///
/// The (arg-type × ordering × endpoint-direction) 3×2×2 endpoint-
/// membership hypercube over the closed-set boundary surface
/// partitions post-lift into eleven of twelve corners; only the
/// lex-tail sibling [`Self::is_sorted_last_index`] remains to close
/// the twelfth:
///
/// | Arg-type \\ Ordering \\ Endpoint | Declaration head | Declaration tail | Lex head | Lex tail |
/// |----------------------------------|-----------------------------|-----------------------------|----------------------------------|----------------------------------|
/// | `Self` (variant) | [`Self::is_first`] | [`Self::is_last`] | [`Self::is_sorted_first`] | [`Self::is_sorted_last`] |
/// | `&str` (label) | [`Self::is_first_label`] | [`Self::is_last_label`] | [`Self::is_sorted_first_label`] | [`Self::is_sorted_last_label`] |
/// | `usize` (index) | [`Self::is_first_index`] | [`Self::is_last_index`] | [`Self::is_sorted_first_index`] | [`Self::is_sorted_last_index`] |
///
/// Sibling posture to [`Self::is_first_index`] one ordering axis
/// over on the (declaration, lex) partition — [`Self::is_first_index`]
/// interprets `i` as a DECLARATION slot in [`Self::ALL`] and pins
/// it against the declaration-order head-slot literal `0`; this
/// method interprets `i` as a LEX position in [`Self::sorted_variants`]
/// and pins it against the lex-order head-slot literal `0`. The
/// `usize` bodies coincide (both endpoints land at slot `0` under
/// their respective orderings) but the SEMANTIC and load-bearing
/// consumer paths differ — a caller who computed a lex-position via
/// [`Self::sorted_index_of`] and wants to test lex-head membership
/// binds to THIS method (not [`Self::is_first_index`]) to make the
/// lex axis explicit at the call site and to inherit the (76)
/// well-formedness pin against `T::is_sorted_first_index(T::sorted_index_of(v))
/// == v.is_sorted_first()` rather than the (74) pin against
/// `T::is_first_index(T::index_of(v)) == v.is_first()`.
///
/// Every generic consumer that wants a zero-alloc O(1) `usize`-
/// shaped lex-head-boundary query (an alphabetized compact wire
/// codec that short-circuits on the lex-head-anchor slot before
/// materializing a typed variant, an LSP completion widget that
/// highlights the alphabetically-first candidate slot in a lex-
/// sorted picker, a lex-sorted Prometheus per-lex-slot bucket
/// renderer that anchors the lex-head-anchor bucket at a
/// distinguished color, a `tatara-check` diagnostic renderer that
/// emits an anchored `"expected first lex slot: 0"` banner ONLY
/// when the offending lex-position equals the lex-head slot, a
/// byte-tagged compact-encoding on the alphabetized carve that
/// treats the lex-head slot as the canonical `0`-tag) binds to ONE
/// typed predicate rather than hand-rolling either the `i == 0`
/// inline comparison on the lex axis (which re-derives the same
/// magic-literal composition at every callsite AND silently drifts
/// when the definition of "lex-head slot" gets tightened — a future
/// closed set that reserves lex-position `0` for a sentinel and
/// shifts every canonical lex-slot up by one, a future const-fn
/// axis that makes the predicate callable in const contexts, a
/// future `#[closed_set(compare_labels_with = ...)]` derive
/// attribute that swaps the ordering) OR the `T::from_sorted_index(i).
/// map(<T as ClosedSet>::is_sorted_first).unwrap_or(false)`
/// composition (which pays an `Option<Self>`-typed dispatch AND
/// folds the out-of-range boundary onto `false` implicitly rather
/// than by direct `usize` equality) OR the
/// `T::sorted_label_at(i).map(<T as ClosedSet>::is_sorted_first_label).
/// unwrap_or(false)` composition (which pays an
/// `Option<&'static str>`-typed dispatch AND routes through the
/// label-shaped lex-head predicate one arg-type axis over).
///
/// Default body is a zero-alloc `usize` equality check against the
/// literal `0` — the index-shaped lex-head-membership predicate is
/// the natural lex-position rendering of the closed-set lex-order
/// head endpoint. Implementors override only when the index-shaped
/// lex-head-membership surface needs to diverge from the natural
/// `i == 0` shape (no production implementor reaches for this
/// today; the axis exists for the same reason `via` / `set_label` /
/// `labels` / `sorted_first` / `sorted_first_label` /
/// `is_sorted_first_label` overrides exist — a typed escape hatch
/// rather than forcing the implementor to hand-roll the impl).
///
/// The index-shaped lex-head-membership contract —
/// `T::is_sorted_first_index(0) == true` AND
/// `T::is_sorted_first_index(i) == false` for every
/// `i ∈ 1..T::CARDINALITY` on every implementor — is guaranteed
/// by the natural `usize` equality against `0`; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (76)
/// pins the composition against the natural `i == 0` shape AND
/// against agreement with [`Self::is_sorted_first`] through the
/// (variant → lex slot) forward projection
/// [`Self::sorted_index_of`] on every implementor across every
/// canonical variant's lex slot AND the out-of-range boundary
/// `T::CARDINALITY` probe so a passing well-formedness sweep means
/// every generic consumer can call [`Self::is_sorted_first_index`]
/// on any `usize` input at any crate boundary and expect the same
/// `bool` answer as the natural composition.
///
/// Out-of-range boundary — for any input `i` outside
/// `0..T::CARDINALITY` (the canonical `T::CARDINALITY` probe, a
/// large slot like `usize::MAX`, any lex-position past the lex-
/// tail), this predicate returns `false` (the equality against `0`
/// fails structurally — the lex-head slot is by construction `0`
/// and no out-of-range lex-position equals `0` under the non-empty
/// `T::ALL` contract). Callers that want "is this a valid lex-slot
/// AND the lex-head slot" compose this predicate with an `i <
/// T::CARDINALITY` range check at the callsite; callers that want
/// "is this the lex-head slot OR reject as out-of-range" compose
/// this predicate with the natural `!` inversion.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, the sole variant's lex slot `0` is BOTH
/// the lex-order head-endpoint slot AND the lex-order tail-endpoint
/// slot so this predicate and [`Self::is_sorted_last_index`]
/// collapse onto the same `usize` equality check, mirroring
/// [`Self::is_sorted_first`] / [`Self::is_sorted_last`]'s singleton
/// collapse at the (`Self`, bool) arm AND
/// [`Self::is_sorted_first_label`] / [`Self::is_sorted_last_label`]'s
/// singleton collapse at the (`&str`, bool) arm one arg-type axis
/// over AND [`Self::is_first_index`] / [`Self::is_last_index`]'s
/// singleton collapse at the (declaration, `usize`) arm one
/// ordering axis over.
///
/// THEORY.md §III — the typescape; the (usize → lex-head-membership
/// bool) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `i == 0` comparison on a lex-position
/// input. Closes the ordering-axis of the index-shaped endpoint-
/// membership matrix from the 3×2×(declaration only) subset to the
/// full 3×2×2 = 12-corner endpoint-membership hypercube at eleven
/// of twelve corners (the sole remaining gap is
/// [`Self::is_sorted_last_index`] one endpoint-direction over).
/// THEORY.md §V.1 — knowable platform; the (usize → lex-head-
/// membership) projection was an unnamed compound of the `i == 0`
/// comparison on a lex-position input pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of the closed-set
/// lex-order head-slot literal — generic consumers see ONE method,
/// not one index-shaped-lex-head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (usize →
/// lex-head-membership) projection emerges from the closed-set
/// lex-order head-slot literal `0` rather than as a per-implementor
/// `match i { 0 => true, _ => false }` block on a lex-position
/// input.
///
/// Frontier inspiration: Racket's `(enum-sorted-first-index? enum
/// i)` on a closed enumeration under the lexicographic ordering
/// (the index-shaped lex-head-membership predicate on the
/// alphabetized chain composed through the array-position
/// projection); Idris's `isFZ : Fin (S n) -> Bool` composed through
/// `finToNat` on a `sortByLabel`-permuted labeling on the lex-head-
/// anchor slot of the non-empty finite-type universe; Haskell's
/// `(== 0)` composed with `sortOn show [minBound..maxBound]` on the
/// `Bounded + Show` type-class pair projected through `show` on the
/// alphabetized chain; MLIR's
/// `RegisteredOperationName::isLexBeginIndex(idx)` on the lex-
/// sorted Op registry; Rust's `strum::EnumIter::iter().collect::
/// <Vec<_>>().sort_by_key(|v| v.get_str()).iter().position(|v| v ==
/// self).map(|i| i == 0).unwrap_or(false)` composed through the
/// iterator API + a sort-by-label prelude. Translation through
/// pleme-io primitives: a pure default method composing the closed-
/// set lex-order head-slot literal `0` with the standard-library
/// `usize` equality operator — no new dep, no new IR layer, no
/// supertrait bound, no allocation, no [`Option`]-typed dispatch.
fn is_sorted_first_index(i: usize) -> bool {
i == 0
}
/// The lexicographic-order tail-endpoint INDEX predicate — `true`
/// iff the `usize` argument equals `T::CARDINALITY - 1` (the lex-
/// order tail-endpoint's slot in [`Self::sorted_variants`], where
/// the argument is interpreted as a LEX position — the natural
/// output shape of [`Self::sorted_index_of`],
/// [`Self::sorted_next_index`], [`Self::sorted_prev_index`],
/// [`Self::cycle_sorted_next_index`], and
/// [`Self::cycle_sorted_prev_index`]), `false` otherwise. Closes
/// the `(usize, lex, tail)` corner of the (arg-type × ordering ×
/// endpoint-direction) 3×2×2 = 12-corner endpoint-membership
/// hypercube — the TWELFTH and final corner alongside the eleven
/// enumerated in [`Self::is_sorted_first_index`]'s docstring.
///
/// Sibling posture to [`Self::is_sorted_first_index`] one endpoint-
/// direction axis over on the (head, tail) partition of the lex-
/// axis index-shaped endpoint-membership surface:
/// [`Self::is_sorted_first_index`] answers "is this usize the lex-
/// order head-endpoint lex-slot?", this method answers "is this
/// usize the lex-order tail-endpoint lex-slot?". See
/// [`Self::is_sorted_first_index`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the tail-direction arm of the same axis and inherits every
/// property from the head arm's documentation, differing only in
/// the composition through the closed-set lex-order tail-slot
/// literal `T::CARDINALITY - 1` (expressed as
/// `i.checked_add(1) == Some(T::CARDINALITY)` to avoid the `usize`
/// underflow question on the empty-`T::ALL` boundary the well-
/// formedness clause (1) forbids AND to avoid the `usize` overflow
/// question on the `usize::MAX` boundary probe) instead of the
/// head-slot literal `0`.
///
/// Default body is a zero-alloc `checked_add(1) == Some(CARDINALITY)`
/// composition — mirrors [`Self::is_last_index`]'s body one ordering
/// axis over on the (declaration, lex) partition. The `checked_add`
/// form (rather than the raw `i + 1 == Self::CARDINALITY`
/// composition) folds the arithmetic-overflow arm onto `None`
/// structurally, preserving the tail-membership predicate's
/// `false`-on-out-of-range contract on every `usize` input
/// including `usize::MAX`.
///
/// The index-shaped lex-tail-membership contract —
/// `T::is_sorted_last_index(T::CARDINALITY - 1) == true` AND
/// `T::is_sorted_last_index(i) == false` for every
/// `i ∈ 0..T::CARDINALITY - 1` on every implementor — is
/// guaranteed by the natural `usize` equality against
/// `T::CARDINALITY`; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (77) pins the
/// composition against the natural `i + 1 == T::CARDINALITY`
/// shape AND against agreement with [`Self::is_sorted_last`]
/// through the (variant → lex slot) forward projection
/// [`Self::sorted_index_of`] on every implementor across every
/// canonical variant's lex slot AND the out-of-range boundary
/// `T::CARDINALITY` probe.
///
/// Clauses (30), (31), (32), (33), (50), (51), (52), (53), (74),
/// (75), (76), and (77) together CLOSE the (arg-type × ordering ×
/// endpoint-direction) 3×2×2 = 12-corner endpoint-membership
/// hypercube on the closed-set boundary surface EXHAUSTIVELY:
/// (`Self`, declaration, head/tail) at clauses (30) —
/// [`Self::is_first`] / [`Self::is_last`]; (`Self`, lex, head/tail)
/// at clauses (31) — [`Self::is_sorted_first`] /
/// [`Self::is_sorted_last`]; (`&str`, declaration, head/tail) at
/// clauses (50) + (51) — [`Self::is_first_label`] /
/// [`Self::is_last_label`]; (`&str`, lex, head/tail) at clauses
/// (52) + (53) — [`Self::is_sorted_first_label`] /
/// [`Self::is_sorted_last_label`]; (`usize`, declaration,
/// head/tail) at clauses (74) + (75) — [`Self::is_first_index`] /
/// [`Self::is_last_index`]; and now (`usize`, lex, head/tail) at
/// clauses (76) + (77) — [`Self::is_sorted_first_index`] and this
/// method. Every generic consumer that binds any of the twelve
/// endpoint-membership methods sees the SAME endpoint-membership
/// answer at every crate boundary regardless of which arg-type
/// axis / ordering-axis / endpoint-direction axis it walks, and
/// the (arg-type × ordering × endpoint-direction) hypercube is now
/// FULLY closed — the next natural extension is the
/// (endpoint-partition axis) arm on the `usize` column
/// (`is_endpoint_index`, `is_interior_index`,
/// `is_sorted_endpoint_index`, `is_sorted_interior_index`) already
/// closed on the `Self` and `&str` columns at
/// [`Self::is_endpoint`] / [`Self::is_interior`] /
/// [`Self::is_sorted_endpoint`] / [`Self::is_sorted_interior`] /
/// [`Self::is_endpoint_label`] / [`Self::is_interior_label`] /
/// [`Self::is_sorted_endpoint_label`] /
/// [`Self::is_sorted_interior_label`].
fn is_sorted_last_index(i: usize) -> bool {
i.checked_add(1) == Some(<Self as ClosedSet>::CARDINALITY)
}
/// The lexicographically-least variant of the closed set — the
/// canonical minimum-by-[`Self::label`] under the standard-library
/// `str: Ord` ordering, projected onto the trait surface as a
/// panic-free typed anchor. Closes the (lexicographic-order, head)
/// corner of the (ordering-axis × endpoint-direction) 2×2
/// endpoint-anchor matrix — sibling posture to [`Self::first`]
/// (declaration-order, head), [`Self::last`] (declaration-order,
/// tail), and [`Self::sorted_last`] (lexicographic-order, tail).
///
/// The (ordering-axis × endpoint-direction) 2×2 matrix over the
/// closed-set endpoint-anchor surface partitions post-lift:
///
/// | Ordering axis \\ Endpoint | Head | Tail |
/// |---------------------------|-------------------------|------------------------|
/// | Declaration order | [`Self::first`] | [`Self::last`] |
/// | Lexicographic order | [`Self::sorted_first`] | [`Self::sorted_last`] |
///
/// Default body is a zero-alloc single-pass linear scan over
/// [`Self::ALL`] keyed on [`Self::label`] — the head anchor never
/// materializes the `Vec<Self>` [`Self::sorted_variants`] returns.
/// Implementors override only when the endpoint surface needs to
/// diverge from the natural label-keyed lex-min shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_labels` / `sorted_variants` / `first` overrides exist —
/// a typed escape hatch rather than forcing the implementor to
/// hand-roll the impl).
///
/// The non-empty contract [`assert_closed_set_well_formed`]'s
/// clause (1) guarantees `Self::ALL[0]` is sound; the label-pairwise-
/// distinctness contract clause (3) guarantees the lex-min is unique
/// (a strict `<` in the linear scan cannot reject a canonical
/// minimum in favor of a later equal-label variant, because no two
/// canonical labels can be equal). The well-formedness clause (19)
/// pins [`Self::sorted_first`] against
/// `T::sorted_variants()[0]` on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// [`Self::sorted_first`] on any typed variant without threading an
/// [`Option`] through the return.
///
/// Future consumers — a diagnostic renderer that anchors an
/// `"expected one of A..Z"` shape at the (lex-min, lex-max)
/// endpoints without materializing the full sorted-labels list, an
/// LSP completion default that highlights the alphabetically-first
/// choice as the pre-selected candidate, a serde deserializer
/// wrapper that folds a missing field onto the lex-least canonical
/// variant (rather than the declaration-order head [`Self::first`]
/// projects, when the closed set's canonical default is defined by
/// alphabetic order rather than declaration order), a property-test
/// generator that anchors at the (lex-min, lex-max) edges — bind to
/// ONE trait method instead of hand-rolling either the
/// `Self::sorted_variants()[0]` composition (which pays a Vec
/// allocation the linear scan doesn't need) OR the
/// `Self::labels().into_iter().min().and_then(Self::find_by_label)`
/// composition (which pays a Vec-of-labels allocation AND an
/// [`Option`]-typed dispatch the closed-set non-empty + distinct-
/// labels contract structurally forbids).
///
/// THEORY.md §III — the typescape; the (lexicographic-order head
/// endpoint) projection becomes a TYPE projection on the trait
/// rather than a per-consumer composition of [`Self::sorted_variants`]
/// combined with `<[Self]>::first` at every downstream anchor site.
/// The (declaration, lex) × (head, tail) endpoint-anchor 2×2 matrix
/// partitions the closed-set endpoint-anchor surface exhaustively
/// into FOUR typed projections, each with a distinct load-bearing
/// consumer surface.
///
/// THEORY.md §V.1 — knowable platform; the (lexicographic-order
/// head endpoint) projection was an unnamed compound of
/// [`Self::ALL`] combined with a label-keyed sort combined with a
/// slice-index-0 projection pre-lift; naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of [`Self::ALL`] combined
/// with [`Self::label`] alone — generic consumers see ONE method,
/// not ONE lex-endpoint-shape-per-crate. Clause (19) pins it
/// against [`Self::sorted_variants`]'s head endpoint so the
/// label-keyed linear scan and the sorted-listing surface stay
/// aligned at ONE anchor site.
///
/// THEORY.md §VI.1 — generation over composition; the (lex head
/// endpoint) projection emerges from the composition of TWO
/// substrate primitives ([`Self::ALL`] combined with
/// [`Self::label`]) via the standard-library `PartialOrd` on `str`
/// rather than as a per-implementor `const LEX_HEAD: Self = ...`
/// literal. A future tightening of the label comparator (a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the ordering, a future case-insensitive-label extension)
/// propagates to every closed-set lex-endpoint consumer through
/// this method's body.
///
/// Frontier inspiration: Haskell's `Data.List.minimumBy` on a
/// closed-set candidate list keyed by a projection function; Idris's
/// `Data.List.min` over the `Fin n` finite-cardinality universe
/// composed with a labeling projection; MLIR's
/// `RegisteredOperationName::begin()` on a lexicographically-sorted
/// Op registry; Racket's `(argmin T-label (enum->list T))` on a
/// closed-enum candidate list. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::ALL`] + [`Self::label`] surfaces with a strict-`<` linear
/// scan — no new dep, no new IR layer, no supertrait bound, no
/// [`Option`]-typed dispatch, no Vec allocation.
fn sorted_first() -> Self {
let mut best = Self::ALL[0];
let mut best_label = <Self as ClosedSet>::label(best);
for &v in &Self::ALL[1..] {
let lbl = <Self as ClosedSet>::label(v);
if lbl < best_label {
best = v;
best_label = lbl;
}
}
best
}
/// The lexicographically-greatest variant of the closed set — the
/// canonical maximum-by-[`Self::label`] under the standard-library
/// `str: Ord` ordering, projected onto the trait surface as a
/// panic-free typed anchor. Closes the (lexicographic-order, tail)
/// corner of the (ordering-axis × endpoint-direction) 2×2
/// endpoint-anchor matrix.
///
/// Sibling posture to [`Self::sorted_first`] one axis over on the
/// (head, tail) partition of the lexicographic-order endpoint-anchor
/// surface: [`Self::sorted_first`] returns the lex-min,
/// this method returns the lex-max. See [`Self::sorted_first`] for
/// the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the tail arm of the same axis and
/// inherits every property from the head arm's documentation,
/// differing only in the strict-`>` comparator direction.
///
/// Default body is a zero-alloc single-pass linear scan over
/// [`Self::ALL`] keyed on [`Self::label`] with the comparator
/// inverted — the tail anchor never materializes the `Vec<Self>`
/// [`Self::sorted_variants`] returns. The well-formedness clause
/// (19) pins [`Self::sorted_last`] against
/// `T::sorted_variants()[T::sorted_variants().len() - 1]` on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call [`Self::sorted_last`] on any typed
/// variant without threading an [`Option`] through the return.
fn sorted_last() -> Self {
let mut best = Self::ALL[0];
let mut best_label = <Self as ClosedSet>::label(best);
for &v in &Self::ALL[1..] {
let lbl = <Self as ClosedSet>::label(v);
if lbl > best_label {
best = v;
best_label = lbl;
}
}
best
}
/// The lex-order head-endpoint label — `T::sorted_first().label()`
/// projected onto the trait surface as ONE call. Closes the
/// (`Self`, `&'static str`) return-type axis on the lex-axis
/// (head, tail) endpoint-anchor partition at the head slot,
/// completing the (declaration × lex) × (head, tail) × (Self-anchor,
/// label) 2×2×2 = 8-corner endpoint-anchor return-shape cube
/// alongside [`Self::first`] / [`Self::last`] / [`Self::sorted_first`] /
/// [`Self::sorted_last`] (the Self-anchor corners), [`Self::first_label`] /
/// [`Self::last_label`] (the declaration-axis label corners), and
/// [`Self::sorted_last_label`] (the lex tail-label corner).
///
/// Sibling posture to [`Self::first_label`] one ordering axis over
/// on the (declaration, lex) partition of the closed-set head-
/// endpoint singular-label return-shape column — [`Self::first_label`]
/// returns the declaration-order head-anchor label,
/// this method returns the lex-order head-anchor label. Sibling
/// posture to [`Self::sorted_first`] one return-type axis over on
/// the (typed-variant `Self`, canonical-label `&'static str`)
/// partition of the closed-set lex-axis head-endpoint return-shape
/// column — [`Self::sorted_first`] materializes the typed lex-head
/// anchor, this method materializes its canonical label WITHOUT
/// threading the caller through the two-hop
/// `T::sorted_first().label()` composition. Sibling posture to
/// [`Self::sorted_endpoint_labels`] one aggregation-shape axis over
/// on the (single-slot `&'static str`, pair-tuple `(&'static str,
/// &'static str)`) partition of the closed-set lex-axis endpoint-
/// label return-shape column — [`Self::sorted_endpoint_labels`]
/// aggregates BOTH lex-endpoint-anchor labels into a tuple, this
/// method returns ONLY the lex-head-endpoint label without forcing
/// the caller to destructure the pair and drop the tail slot.
///
/// The (ordering × return-type × endpoint-direction) 2×2×2 matrix
/// over the singular endpoint-anchor return-shape surface
/// partitions post-lift:
///
/// | Ordering \\ (Return-type, Endpoint) | (Self, Head) | (Self, Tail) | (label, Head) | (label, Tail) |
/// |-------------------------------------|-----------------------|-----------------------|----------------------------|---------------------------|
/// | Declaration | [`Self::first`] | [`Self::last`] | [`Self::first_label`] | [`Self::last_label`] |
/// | Lex | [`Self::sorted_first`]| [`Self::sorted_last`] | [`Self::sorted_first_label`] | [`Self::sorted_last_label`] |
///
/// Every generic consumer that wants the lex-order head-endpoint
/// canonical label as ONE `&'static str` (an alphabetized-completion
/// banner that renders `"expected first: <lex-head-label>"` without
/// materializing the typed anchor, a bounded-alphabetized-loop guard
/// that short-circuits on `s == T::sorted_first_label()` before
/// decoding into a typed variant, a per-implementor coherence probe
/// that anchors an edge assertion at the lex-head-endpoint label
/// slot, an alphabetized-completion UI that renders the lex head
/// anchor by label without threading the caller through a
/// `T::sorted_first().label()` two-primitive composition, a
/// deterministic-across-machines Prometheus tag anchored at the
/// lex-min anchor label without materializing the
/// [`Self::sorted_labels`] list) binds to ONE typed method rather
/// than hand-rolling either the `T::sorted_first().label()`
/// composition (which re-derives the same two-primitive projection
/// at every callsite) OR a per-implementor `SORTED_HEAD_LABEL:
/// &'static str = "..."` const that silently drifts from
/// [`Self::label`] on rename OR from the label-keyed lex ordering
/// on any label rename that shifts the lex-min slot.
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_first`]) with the per-slot [`Self::label`]
/// projection — the lex-head-endpoint label is a typed CONSEQUENCE
/// of the (typed lex-head anchor) primitive composed with the
/// (label projection) primitive, not a per-implementor `const
/// SORTED_HEAD_LABEL: &'static str = "..."` declaration.
/// Implementors override only when the lex-head-endpoint label
/// needs to diverge from the natural `T::sorted_first().label()`
/// shape (no production implementor reaches for this today; the
/// axis exists for the same reason `via` / `set_label` / `labels` /
/// `first` / `last` / `sorted_first` / `sorted_last` /
/// `endpoint_labels` / `sorted_endpoint_labels` / `first_label` /
/// `last_label` overrides exist — a typed escape hatch rather than
/// forcing the implementor to hand-roll the impl). An implementor
/// that overrides [`Self::sorted_first`] OR overrides
/// [`Self::label`] propagates the override through this default
/// body automatically; the lex-head-endpoint-label surface funnels
/// through the lex-head-anchor primitive on the anchor-
/// materialization column AND the per-slot label projection on
/// the rendering column.
///
/// The lex-head-endpoint-label contract —
/// `T::sorted_first_label() == T::sorted_first().label()` on every
/// implementor — is guaranteed by the default composition through
/// [`Self::sorted_first`] and [`Self::label`]; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (48)
/// pins the composition against the natural
/// `T::sorted_first().label()` shape on every implementor so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::sorted_first_label`] on any typed carrier and
/// expect the same `&'static str` answer at every crate boundary.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] returns the sole
/// variant and this method returns its label, mirroring
/// [`Self::sorted_last_label`]'s singleton behavior one endpoint-
/// direction axis over. All four singular endpoint-label projections
/// ([`Self::first_label`], [`Self::last_label`],
/// [`Self::sorted_first_label`], [`Self::sorted_last_label`])
/// collapse onto the same label on a singleton, preserving the
/// label projection SHAPE at the boundary-cardinality edge where
/// all four SLOTS collapse onto the same anchor.
///
/// THEORY.md §III — the typescape; the (lex-head anchor → canonical
/// label) singular projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `T::sorted_first().label()` two-primitive composition at every
/// downstream lex-head-label rendering site.
/// THEORY.md §V.1 — knowable platform; the (lex-head anchor →
/// label) projection was an unnamed compound of
/// [`Self::sorted_first`] + [`Self::label`] pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of TWO
/// substrate primitives — generic consumers see ONE method, not
/// one lex-head-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (lex-head
/// anchor → label) projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_first`], [`Self::label`])
/// rather than as a per-implementor `const SORTED_HEAD_LABEL:
/// &'static str = "..."` declaration. A future tightening of
/// either primitive (a future perfect-hash label lookup, a future
/// const-fn axis that makes the projection callable in const
/// contexts, a future case-insensitive-label extension that shifts
/// which variant lands at the lex-min slot) propagates to every
/// closed-set lex-head-label consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-sorted-first-label` on
/// closed enumerations under lex-ordering (the singular lex-head-
/// anchor-label projection on the alphabetized chain); Idris's
/// `showSortedFirst` on `Fin (S n)` non-empty finite-cardinality
/// lex-head-anchor projections; Haskell's
/// `show (minimumBy (comparing show) [minBound..maxBound])` on
/// the `Bounded + Show` type-class pair (the lex-head-anchor-label
/// rendering composed from three prelude primitives on the bounded
/// chain); MLIR's `RegisteredOperationName::lex_begin_name()` on
/// the lex-sorted Op registry; Rust's `strum::EnumIter().min_by_key(|v|
/// v.get_str()).unwrap().get_str()` composed through the iterator
/// API. Translation through pleme-io primitives: a pure default
/// method composing the trait's existing [`Self::sorted_first`]
/// surface with the per-slot [`Self::label`] projection — no new
/// dep, no new IR layer, no supertrait bound, no allocation.
fn sorted_first_label() -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_first())
}
/// The lex-order tail-endpoint label — `T::sorted_last().label()`
/// projected onto the trait surface as ONE call. Closes the
/// (`Self`, `&'static str`) return-type axis on the lex-axis
/// (head, tail) endpoint-anchor partition at the tail slot,
/// completing the (declaration × lex) × (head, tail) × (Self-anchor,
/// label) 2×2×2 = 8-corner endpoint-anchor return-shape cube.
///
/// Sibling posture to [`Self::sorted_first_label`] one endpoint-
/// direction axis over on the (head, tail) partition of the lex-
/// axis singular endpoint-label return-shape column:
/// [`Self::sorted_first_label`] returns the lex-head-anchor label,
/// this method returns the lex-tail-anchor label. See
/// [`Self::sorted_first_label`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the tail-direction arm of the same axis and inherits every
/// property from the head arm's documentation, differing only in
/// the composition through [`Self::sorted_last`] instead of
/// [`Self::sorted_first`].
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_last`]) with the per-slot [`Self::label`]
/// projection. The lex-tail-endpoint-label contract —
/// `T::sorted_last_label() == T::sorted_last().label()` on every
/// implementor — is guaranteed by the default composition; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (49) pins the composition against the natural
/// `T::sorted_last().label()` shape on every implementor.
///
/// Clauses (18) + (19) + (34) + (35) + (36) + (37) + (46) + (47) +
/// (48) + (49) together CLOSE the (return-type × ordering ×
/// endpoint-direction × aggregation-shape) 2×2×2×2 = 16-corner
/// projection hypercube on the closed-set endpoint-anchor return-
/// shape surface: [`Self::first`] / [`Self::last`] /
/// [`Self::sorted_first`] / [`Self::sorted_last`] on (`Self`,
/// ordering × head/tail, singular) — clauses (18) + (19);
/// [`Self::endpoints`] / [`Self::sorted_endpoints`] on ((`Self`,
/// `Self`), ordering × (head, tail), pair-tuple) — clauses (34) +
/// (35); [`Self::endpoint_labels`] / [`Self::sorted_endpoint_labels`]
/// on ((`&'static str`, `&'static str`), ordering × (head, tail),
/// pair-tuple) — clauses (36) + (37); and now [`Self::first_label`] /
/// [`Self::last_label`] / [`Self::sorted_first_label`] /
/// [`Self::sorted_last_label`] on (`&'static str`, ordering ×
/// head/tail, singular) — clauses (46) + (47) + (48) + (49). Every
/// generic consumer that binds any of the twelve endpoint-anchor
/// projection methods sees the SAME endpoint-anchor answer at every
/// crate boundary regardless of which return-type axis / ordering-
/// axis / endpoint-direction / aggregation-shape corner it walks.
fn sorted_last_label() -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_last())
}
/// The lex-order head-endpoint DECL-INDEX — `T::sorted_first().index_of()`
/// projected onto the trait surface as ONE call. Opens the
/// `usize`-typed return-type row on the lex-axis (head, tail)
/// singular endpoint-anchor return-shape column at the head slot,
/// mirroring [`Self::sorted_first_label`] one return-type axis
/// over on the (`&'static str`, `usize`) return-shape column of
/// the lex-axis singular endpoint-anchor projection matrix AND
/// mirroring [`Self::first_index`] one ordering axis over on the
/// (declaration, lex) partition of the closed-set singular head-
/// endpoint decl-slot return-shape column.
///
/// Sibling posture to [`Self::sorted_first`] one return-type axis
/// over on the (typed-variant `Self`, decl-order slot `usize`)
/// partition of the closed-set lex-axis singular head-endpoint
/// return-shape column — [`Self::sorted_first`] materializes the
/// lex-min typed variant, this method materializes its decl-slot
/// integer coordinate WITHOUT threading the caller through the
/// two-hop `T::sorted_first().index_of()` composition. Sibling
/// posture to [`Self::first_index`] one ordering axis over on the
/// (declaration, lex) partition of the closed-set singular head-
/// endpoint decl-slot return-shape column — on an implementor
/// whose declaration order matches its lex order the two arms
/// return the same slot; on an implementor whose declaration
/// order diverges from its lex order they name DIFFERENT canonical
/// decl-slots (see `sorted_first_index_and_sorted_last_index_diverge_on_declaration_order_that_diverges_from_lex_order`).
///
/// The (return-type × ordering × endpoint-direction) 3×2×2 = 12-corner
/// singular endpoint-anchor return-shape hypercube partitions
/// post-lift:
///
/// | Return type \\ (Ordering, Endpoint) | (Decl, Head) | (Decl, Tail) | (Lex, Head) | (Lex, Tail) |
/// |-------------------------------------|---------------------------|--------------------------|-------------------------------|------------------------------|
/// | `Self` (typed variant) | [`Self::first`] | [`Self::last`] | [`Self::sorted_first`] | [`Self::sorted_last`] |
/// | `&'static str` (label) | [`Self::first_label`] | [`Self::last_label`] | [`Self::sorted_first_label`] | [`Self::sorted_last_label`] |
/// | `usize` (decl-slot) | [`Self::first_index`] | [`Self::last_index`] | [`Self::sorted_first_index`] | [`Self::sorted_last_index`] |
///
/// Every generic consumer that wants the lex-order head-endpoint
/// decl-slot as ONE `usize` (a lex-anchored parallel-vector lookup
/// on a per-decl-slot side-table `<[U]>::get(T::sorted_first_index())`
/// that folds the lex-min variant's shadow onto its decl-slot
/// integer coordinate WITHOUT allocating [`Self::sorted_variants`],
/// an alphabetized-completion cursor that positions the caret at
/// the lex-min decl-slot coordinate, a lex-boundary coherence probe
/// that anchors an edge assertion at the lex-head slot's decl-slot
/// integer coordinate WITHOUT walking [`Self::sorted_variants`]) binds
/// to ONE typed method rather than hand-rolling the
/// `T::sorted_first().index_of()` composition (which re-derives the
/// same two-primitive projection at every callsite AND silently
/// drifts when [`Self::sorted_first`] OR [`Self::index_of`] is
/// overridden) OR the `T::sorted_variants()[0].index_of()`
/// composition (which forces a `Vec<Self>` allocation the singular
/// arm avoids by construction).
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_first`]) with the per-slot [`Self::index_of`]
/// projection — the lex-head decl-slot is a typed CONSEQUENCE of
/// the (lex head anchor) primitive composed with the (decl-index
/// projection) primitive, not a per-implementor
/// `const SORTED_HEAD_INDEX: usize = ...;` declaration that
/// silently drifts from [`Self::ALL`] on any label edit.
/// Implementors override only when the lex-head decl-slot needs to
/// diverge from the natural `T::sorted_first().index_of()` shape
/// (no production implementor reaches for this today; the axis
/// exists for the same reason `via` / `set_label` / `labels` /
/// `first` / `last` / `sorted_first` / `sorted_last` /
/// `first_label` / `last_label` / `sorted_first_label` /
/// `sorted_last_label` / `first_index` / `last_index` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::sorted_first`] OR overrides [`Self::index_of`]
/// propagates the override through this default body automatically;
/// the lex-head-decl-slot surface funnels through the lex head-
/// anchor primitive on the anchor-materialization column AND the
/// per-slot decl-index projection on the coordinate-rendering
/// column.
///
/// The lex-head-decl-slot contract — `T::sorted_first_index() ==
/// T::sorted_first().index_of()` AND
/// `T::from_index(T::sorted_first_index()) == Some(T::sorted_first())`
/// on every implementor — is guaranteed by the default composition
/// through [`Self::sorted_first`] and [`Self::index_of`]; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (90) pins the composition against the natural
/// `T::sorted_first().index_of()` shape AND against the
/// `from_index`-round-trip fixpoint on every implementor so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::sorted_first_index`] on any typed carrier and
/// expect the same `usize` answer at every crate boundary.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] returns the sole
/// variant and this method returns its decl-slot `0`. All six
/// singular endpoint-anchor decl-slot projections
/// ([`Self::first_index`], [`Self::last_index`],
/// [`Self::sorted_first_index`], [`Self::sorted_last_index`], and
/// the two label-arm shadows [`Self::first_label`] +
/// [`Self::sorted_first_label`] under the singleton label
/// collapse) fold onto the same anchor at the boundary-cardinality
/// edge.
///
/// THEORY.md §III — the typescape; the (lex head anchor →
/// decl-slot) singular projection becomes a TYPE projection on
/// the trait rather than a per-consumer inline
/// `T::sorted_first().index_of()` two-primitive composition at
/// every downstream lex-head decl-slot lookup site.
/// THEORY.md §V.1 — knowable platform; the (lex head anchor →
/// decl-slot) projection was an unnamed compound of
/// [`Self::sorted_first`] + [`Self::index_of`] pre-lift; naming it
/// on the trait makes the projection a TYPED CONSEQUENCE of TWO
/// substrate primitives — generic consumers see ONE method, not
/// one lex-head-decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (lex head
/// anchor → decl-slot) projection emerges from the composition of
/// TWO substrate primitives rather than as a per-implementor
/// `const SORTED_HEAD_INDEX: usize = ...;` declaration.
///
/// Frontier inspiration: Racket's `enum-sorted-first-index` on
/// closed enumerations under lex-ordering; Idris's
/// `finToNat (sortedFirst : Fin (S n))` composed with a
/// `sortBy comparingLabel` prelude on the finite-cardinality
/// universe (folded onto the head slot of the lex-sorted chain);
/// Haskell's `fromEnum (minimumBy (comparing show) [minBound..])`
/// on the `Bounded + Enum + Show` type-class triple; MLIR's
/// `RegisteredOperationName::lex_begin_index()` on the lex-sorted
/// Op registry; Rust's
/// `strum::EnumIter().min_by_key(|v| v.get_str()).map(|v| v as usize)`
/// composed through the iterator API. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::sorted_first`] surface with the per-slot
/// [`Self::index_of`] projection — no new dep, no new IR layer,
/// no supertrait bound, no allocation.
fn sorted_first_index() -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::sorted_first())
}
/// The lex-order tail-endpoint DECL-INDEX —
/// `T::sorted_last().index_of()` projected onto the trait surface
/// as ONE call. Closes the (`usize`, lex, tail) corner of the
/// (return-type × ordering × endpoint-direction) 3×2×2 = 12-corner
/// singular endpoint-anchor return-shape hypercube alongside the
/// other eleven corners: [`Self::first`] / [`Self::last`] /
/// [`Self::sorted_first`] / [`Self::sorted_last`] on the Self-anchor
/// row, [`Self::first_label`] / [`Self::last_label`] /
/// [`Self::sorted_first_label`] / [`Self::sorted_last_label`] on
/// the label row, and [`Self::first_index`] / [`Self::last_index`] /
/// [`Self::sorted_first_index`] (this method's head sibling) on
/// the decl-slot row.
///
/// Sibling posture to [`Self::sorted_first_index`] one endpoint-
/// direction axis over on the (head, tail) partition of the lex-
/// axis singular endpoint-anchor `usize`-return-shape column:
/// [`Self::sorted_first_index`] projects the lex-head-endpoint's
/// decl-slot, this method projects the lex-tail-endpoint's
/// decl-slot. See [`Self::sorted_first_index`] for the shared
/// design rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the tail-direction arm of the same axis and inherits
/// every property from the head arm's documentation, differing only
/// in the composition through [`Self::sorted_last`] instead of
/// [`Self::sorted_first`]. Sibling posture to [`Self::last_index`]
/// one ordering axis over on the (declaration, lex) partition of
/// the closed-set singular tail-endpoint decl-slot return-shape
/// column — on an implementor whose declaration order matches its
/// lex order the two arms return the same slot; on an implementor
/// whose declaration order diverges from its lex order they name
/// DIFFERENT canonical decl-slots.
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_last`]) with the per-slot [`Self::index_of`]
/// projection. The lex-tail-decl-slot contract —
/// `T::sorted_last_index() == T::sorted_last().index_of()` AND
/// `T::from_index(T::sorted_last_index()) == Some(T::sorted_last())`
/// on every implementor — is guaranteed by the default composition;
/// the well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (91) pins the composition against the natural
/// `T::sorted_last().index_of()` shape AND against the
/// `from_index`-round-trip fixpoint on every implementor.
///
/// Clauses (88) + (89) + (90) + (91) together CLOSE the
/// (return-type × ordering × endpoint-direction) 3×2×2 = 12-corner
/// singular endpoint-anchor return-shape hypercube at ALL FOUR
/// `usize`-typed decl-slot corners: (declaration, head) at (88);
/// (declaration, tail) at (89); (lex, head) at (90); (lex, tail)
/// at (91). Every generic consumer that binds any of the twelve
/// singular endpoint-anchor projection methods sees the SAME
/// endpoint-anchor answer at every crate boundary regardless of
/// which return-type axis / ordering-axis / endpoint-direction
/// corner it walks.
fn sorted_last_index() -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::sorted_last())
}
/// The lexicographic-order head-endpoint membership predicate —
/// `true` when `self` is [`Self::sorted_first`], `false` otherwise.
/// Closes the (lex, head) corner of the (ordering-axis × endpoint-
/// direction) 2×2 endpoint-membership matrix alongside
/// [`Self::is_first`] (declaration, head), [`Self::is_last`]
/// (declaration, tail), and [`Self::is_sorted_last`] (lex, tail).
///
/// The (ordering-axis × endpoint-direction) 2×2 endpoint-membership
/// matrix over the closed-set `bool`-typed endpoint surface
/// partitions post-lift:
///
/// | Ordering axis \\ Endpoint | Head | Tail |
/// |---------------------------|--------------------------|-------------------------|
/// | Declaration order | [`Self::is_first`] | [`Self::is_last`] |
/// | Lexicographic order | [`Self::is_sorted_first`]| [`Self::is_sorted_last`]|
///
/// Combined with the (ordering × direction) 2×2 endpoint-ANCHOR
/// matrix ([`Self::first`], [`Self::last`], [`Self::sorted_first`],
/// [`Self::sorted_last`]), the two matrices together close the
/// (return-type × ordering × direction) 2×2×2 = 8-corner endpoint
/// cube — every generic consumer that wants a typed answer at an
/// endpoint slot binds to ONE of the eight methods rather than
/// hand-rolling either the `Self`-anchor comparison
/// (`self == T::sorted_first()`, needs a supertrait [`PartialEq`]
/// bound the trait's minimal `Sized + Copy` supertrait pair
/// structurally forbids) OR the two-primitive [`Self::sorted_index_of`]
/// composition (`self.sorted_index_of() == 0`, re-derives the
/// natural `usize`-equality composition at every callsite).
///
/// Default body composes [`Self::sorted_index_of`] with a `usize`
/// equality check against `0` — the head-membership predicate is
/// a typed CONSEQUENCE of the composition of the (variant → lex-
/// order position) forward projection with the const-visible `0`
/// slot, not a per-implementor
/// `match self { Self::LexHead => true, _ => false }` block. The
/// lex head-membership contract — `T::sorted_first().is_sorted_first()
/// == true` on every implementor — is guaranteed by the composition
/// through [`Self::sorted_index_of`]'s `0`-slot projection clause
/// (22) pins on every canonical variant; the well-formedness
/// clause (31) pins the composition against the natural
/// `sorted_index_of(self) == 0` shape AND the lex head-endpoint
/// `true` fixpoint on every implementor so a passing well-
/// formedness sweep means every generic consumer can call
/// [`Self::is_sorted_first`] on any typed variant and expect the
/// same `bool` answer at every crate boundary.
///
/// Future consumers — an alphabetized LSP completion cursor that
/// highlights the alphabetically-first choice differently (a
/// candidate about to be pre-selected on Enter, a keyboard-cursor
/// wrap-around handler that resets to the lex-min anchor); a
/// `tatara-check` diagnostic renderer that anchors the
/// `"expected one of: A..Z"` shape at the lex-min without
/// materializing the [`Self::sorted_labels`] list; a metrics
/// tagger that fires a distinguished counter on the lex-min slot;
/// a serde deserializer wrapper that folds a missing field onto
/// the lex-least canonical variant (the natural default-alignment
/// when the closed set's canonical ordering is alphabetic rather
/// than declaration-based) — bind to ONE typed predicate rather
/// than hand-rolling either the `self == T::sorted_first()`
/// comparison (which the trait's minimal supertrait pair
/// `Sized + Copy` structurally forbids without adding a
/// [`PartialEq`] bound) OR the two-primitive
/// `self.sorted_index_of() == 0` composition (which re-derives
/// the same lex-slot projection at every callsite).
///
/// THEORY.md §III — the typescape; the (variant → lex head-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `self.sorted_index_of() == 0` composition at every downstream
/// lex-head-boundary query site.
/// THEORY.md §V.1 — knowable platform; the (variant → lex head-
/// membership) projection was an unnamed compound of
/// [`Self::sorted_index_of`] + `usize` `==` `0` pre-lift; naming
/// it on the trait makes the projection a TYPED CONSEQUENCE of
/// ONE substrate primitive — generic consumers see ONE method,
/// not one lex-head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// lex head-membership) projection emerges from the composition
/// of [`Self::sorted_index_of`] with the standard-library `usize`
/// equality operator rather than as a per-implementor
/// `match self { ... }` block. A future tightening of
/// [`Self::sorted_index_of`] (a future perfect-hash lex-order
/// projection, a future const-fn lex-axis, a future case-
/// insensitive-label extension that shifts which variant lands
/// at the lex-min slot) propagates to every closed-set lex-head-
/// boundary consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-sorted-first?` on closed
/// enumerations under lex-ordering; Idris's `min : Fin (S n) ->
/// Fin (S n) -> Bool` composed with a `sortBy comparingLabel`
/// prelude on the finite-cardinality universe (folded onto the
/// head slot of the lex-sorted chain); Haskell's `(== minimumBy
/// comparing label [minBound..])` on the `Bounded + Enum` type-
/// class pair; MLIR's `RegisteredOperationName::isLexBegin()` on
/// the lex-sorted Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::sorted_index_of`] surface with the standard-
/// library `usize` equality operator — no new dep, no new IR
/// layer, no supertrait [`PartialEq`] bound, no [`Option`]-typed
/// dispatch.
fn is_sorted_first(self) -> bool {
<Self as ClosedSet>::sorted_index_of(self) == 0
}
/// The lexicographic-order tail-endpoint membership predicate —
/// `true` when `self` is [`Self::sorted_last`], `false` otherwise.
/// Closes the (lex, tail) corner of the (ordering-axis × endpoint-
/// direction) 2×2 endpoint-membership matrix, completing the
/// (return-type × ordering × direction) 2×2×2 = 8-corner endpoint
/// cube alongside [`Self::is_first`], [`Self::is_last`], and
/// [`Self::is_sorted_first`].
///
/// Sibling posture to [`Self::is_sorted_first`] one axis over on
/// the (head, tail) partition of the lex-axis endpoint-membership
/// surface: [`Self::is_sorted_first`] answers "am I at the lex
/// head endpoint?", this method answers "am I at the lex tail
/// endpoint?". See [`Self::is_sorted_first`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the tail-direction arm of the same axis and
/// inherits every property from the head arm's documentation,
/// differing only in the `+ 1 == Self::CARDINALITY` boundary
/// check.
///
/// Default body composes [`Self::sorted_index_of`] with an `usize`
/// equality check against [`Self::CARDINALITY`] under the natural
/// `+ 1` shift — the lex tail-membership predicate is a typed
/// CONSEQUENCE of the composition of the (variant → lex-order
/// position) forward projection with the const-visible variant
/// count, not a per-implementor
/// `match self { Self::LexTail => true, _ => false }` block. The
/// `+ 1 == Self::CARDINALITY` shape (rather than
/// `== Self::CARDINALITY - 1`) avoids the `usize` underflow
/// question the well-formedness contract clause (1)'s non-empty
/// guarantee already forbids — mirroring [`Self::is_last`]'s
/// declaration-axis shape one ordering axis over so the projection
/// stays callable in a future const-fn context without the
/// underflow discharge.
///
/// The lex tail-membership contract —
/// `T::sorted_last().is_sorted_last() == true` on every
/// implementor — is guaranteed by the composition through
/// [`Self::sorted_index_of`]'s `Self::CARDINALITY - 1`-slot
/// projection clause (22) pins on every lex-order tail; the
/// well-formedness clause (31) pins the composition against the
/// natural `sorted_index_of(self) + 1 == Self::CARDINALITY` shape
/// AND the lex tail-endpoint `true` fixpoint on every implementor
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::is_sorted_last`] on any typed variant and
/// expect the same `bool` answer at every crate boundary.
/// `T::sorted_last().is_sorted_last() == true` is the natural
/// fixpoint the lex tail-endpoint anchor and the lex tail-
/// membership axis share, mirroring
/// `T::last().is_last() == true` (declaration-axis, tail) and
/// `T::sorted_first().is_sorted_first() == true` (lex-axis, head).
fn is_sorted_last(self) -> bool {
<Self as ClosedSet>::sorted_index_of(self) + 1 == <Self as ClosedSet>::CARDINALITY
}
/// The lexicographic-order head-endpoint LABEL predicate — `true`
/// iff `s` equals [`Self::sorted_first_label`], `false` otherwise.
/// Closes the (`&str`, lex, head) corner of the (arg-type × ordering
/// × endpoint-direction) 2×2×2 = 8-corner endpoint-membership
/// hypercube alongside [`Self::is_first`] (Self, declaration, head),
/// [`Self::is_last`] (Self, declaration, tail),
/// [`Self::is_sorted_first`] (Self, lex, head),
/// [`Self::is_sorted_last`] (Self, lex, tail),
/// [`Self::is_first_label`] (&str, declaration, head), and
/// [`Self::is_last_label`] (&str, declaration, tail).
///
/// The (arg-type × ordering × endpoint-direction) 2×2×2 = 8-corner
/// endpoint-membership hypercube over the closed-set `bool`-typed
/// endpoint surface partitions post-lift:
///
/// | Arg-type \\ Ordering × Direction | Declaration head | Declaration tail | Lex head | Lex tail |
/// |----------------------------------|------------------------------|-----------------------------|-----------------------------------|----------------------------------|
/// | `Self` (variant) | [`Self::is_first`] | [`Self::is_last`] | [`Self::is_sorted_first`] | [`Self::is_sorted_last`] |
/// | `&str` (label) | [`Self::is_first_label`] | [`Self::is_last_label`] | [`Self::is_sorted_first_label`] | [`Self::is_sorted_last_label`] |
///
/// Sibling posture to [`Self::sorted_first_label`] one return-type
/// axis over on the (`&'static str`-returning label projection,
/// `bool`-returning label predicate) partition —
/// [`Self::sorted_first_label`] projects the lex-order head-endpoint
/// label, this method answers "is this &str the lex-order head-
/// endpoint label?" without threading the caller through a per-
/// callsite `s == T::sorted_first_label()` comparison. Sibling
/// posture to [`Self::is_first_label`] one ordering axis over on
/// the (declaration, lex) partition — [`Self::is_first_label`]
/// answers "is this &str the DECLARATION-order head-endpoint
/// label?", this method answers "is this &str the LEX-order head-
/// endpoint label?". Sibling posture to [`Self::is_sorted_first`]
/// one arg-type axis over on the (Self, &str) partition —
/// [`Self::is_sorted_first`] answers "am I at the lex head
/// endpoint?" for a typed variant, this method answers the same
/// question for a raw label string WITHOUT decoding through
/// [`Self::parse_label`] or [`Self::find_by_label`] (which would
/// allocate the reject carrier on non-matching inputs OR force the
/// caller through the `Option<Self>`-typed dispatch).
///
/// Every generic consumer that wants a zero-alloc O(1) label-shaped
/// lex-head-boundary query (an alphabetized-completion LSP cursor
/// that short-circuits on the alphabetically-first label before
/// materializing a typed variant, a CLI subcommand dispatcher that
/// folds the lex-min anchor label onto a special "default" path
/// (natural when the closed set's canonical ordering is alphabetic
/// rather than declaration-based), a serde deserializer wrapper
/// that treats the lex-min anchor label as the alphabetic default
/// alignment, a `tatara-check` diagnostic renderer that emits an
/// anchored `"expected first alphabetically: <lex-head-label>"`
/// banner ONLY when the offending input equals the lex-min label —
/// a distinguished error shape, not the generic
/// `"expected one of: A, B, C"` shape) binds to ONE typed predicate
/// rather than hand-rolling either the
/// `s == T::sorted_first_label()` inline comparison (which re-
/// derives the same one-primitive projection at every callsite AND
/// silently drifts when [`Self::sorted_first_label`] is overridden
/// after a label edit shifts the lex-min anchor) OR the two-
/// primitive `T::find_by_label(s).map(<T as ClosedSet>::is_sorted_first)
/// .unwrap_or(false)` composition (which forces the caller through
/// the `Option<Self>`-typed dispatch AND folds the not-a-label
/// input onto `false` implicitly rather than by direct `&str`
/// equality).
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_first_label`]) with the standard-library `&str`
/// equality operator — the label-shaped lex-head-membership
/// predicate is a typed CONSEQUENCE of the (lex-order head label)
/// projection, not a per-implementor `match s { "lex-head-label"
/// => true, _ => false }` block. Implementors override only when
/// the label-shaped lex-head-membership surface needs to diverge
/// from the natural `s == T::sorted_first_label()` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_first` / `sorted_first_label` overrides exist — a typed
/// escape hatch rather than forcing the implementor to hand-roll
/// the impl). An implementor that overrides
/// [`Self::sorted_first_label`] propagates the override through
/// this default body automatically; the (label → bool lex-head-
/// membership) projection funnels through ONE typed primitive.
///
/// The label-shaped lex-head-membership contract —
/// `T::is_sorted_first_label(T::sorted_first().label()) == true` AND
/// `T::is_sorted_first_label(v.label()) == false` for every non-lex-
/// first canonical variant `v` on every implementor — is guaranteed
/// by the composition through [`Self::sorted_first_label`] AND the
/// label-pairwise-distinctness contract clause (3); the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (52) pins the composition against the natural
/// `s == T::sorted_first_label()` shape on every implementor across
/// every canonical variant label AND the reserved probe input AND
/// the empty-string boundary so a passing well-formedness sweep
/// means every generic consumer can call
/// [`Self::is_sorted_first_label`] on any `&str` input at any crate
/// boundary and expect the same `bool` answer as the natural
/// composition.
///
/// Not-a-label boundary — for any input `s` that is not a canonical
/// label of [`T::ALL`] (the reserved probe, the empty string, an
/// unknown token), this predicate returns `false` (the equality
/// against [`Self::sorted_first_label`] fails structurally — the
/// lex-head label is by clause (4) non-empty and is by clause (3)
/// distinct from every other canonical label AND is by the probe's
/// construction distinct from any input that lands in the substrate's
/// `make_unknown` carrier). Callers that want "is this a valid label
/// AND the lex-head label" compose this predicate with
/// [`Self::contains_label`] at the callsite; callers that want
/// "is this the lex-head label OR reject as unknown" compose this
/// predicate with the natural `!` inversion.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first_label`] equals
/// [`Self::sorted_last_label`] (both project the sole canonical
/// label) so this predicate and [`Self::is_sorted_last_label`]
/// collapse onto the same `&str` equality check, mirroring
/// [`Self::is_sorted_first`] and [`Self::is_sorted_last`]'s
/// singleton collapse at the (Self, bool) arm one arg-type axis
/// over AND [`Self::is_first_label`] / [`Self::is_last_label`]'s
/// singleton collapse at the (&str, bool) arm one ordering axis
/// over. Preserves the (endpoint XOR interior) partition semantics
/// even at the boundary-cardinality edge where the two SLOTS
/// collapse onto the same anchor.
///
/// Clauses (30) + (31) + (50) + (51) + (52) together open the
/// (arg-type × ordering × endpoint-direction) 2×2×2 = 8-corner
/// endpoint-membership hypercube at SEVEN of the eight corners on
/// the closed-set endpoint-membership surface: (Self, declaration,
/// head/tail) at clauses (30) — [`Self::is_first`] /
/// [`Self::is_last`]; (Self, lex, head/tail) at clauses (31) —
/// [`Self::is_sorted_first`] / [`Self::is_sorted_last`]; (&str,
/// declaration, head/tail) at clauses (50) + (51) —
/// [`Self::is_first_label`] / [`Self::is_last_label`]; (&str, lex,
/// head) at clause (52) — this method. The remaining corner on
/// (&str, lex, tail) is [`Self::is_sorted_last_label`], the natural
/// tail-direction sibling this method's docs pair to.
///
/// THEORY.md §III — the typescape; the (label → lex-head-membership
/// bool) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `s == T::sorted_first_label()`
/// comparison at every downstream label-shaped lex-head-boundary
/// query site.
/// THEORY.md §V.1 — knowable platform; the (label → lex-head-
/// membership) projection was an unnamed compound of
/// [`Self::sorted_first_label`] + `&str` `==` pre-lift; naming it
/// on the trait makes the projection a TYPED CONSEQUENCE of ONE
/// substrate primitive — generic consumers see ONE method, not one
/// label-shaped-lex-head-boundary-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (label →
/// lex-head-membership) projection emerges from the composition of
/// [`Self::sorted_first_label`] with the standard-library `&str`
/// equality operator rather than as a per-implementor
/// `match s { ... }` block. A future tightening of
/// [`Self::sorted_first_label`] (a future perfect-hash forward
/// projection, a future const-fn axis that makes the predicate
/// callable in const contexts, a future case-insensitive-label
/// extension that shifts which variant lands at the lex-min slot)
/// propagates to every closed-set label-shaped lex-head-boundary
/// consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-sorted-first-label?` on
/// closed enumerations under a canonical labeling (the label-shaped
/// lex-head-membership predicate on the alphabetized chain);
/// Idris's `isSortedFirstLabel : String -> Bool` on a `Show`ed
/// lex-sorted `Fin (S n)` composed via
/// `showFin (sortedFirst xs) == s` on the lex-head-anchor slot;
/// Haskell's `(== minimumBy (comparing show) [minBound..maxBound])`
/// on the `Bounded + Show` type-class pair projected through `show`
/// on the alphabetized chain; MLIR's
/// `RegisteredOperationName::isLexBeginName(name)` on the lex-
/// sorted Op registry; Rust's `strum::EnumIter().min_by_key(|v|
/// v.get_str()).map(|v| v.get_str() == s).unwrap_or(false)`
/// composed through the iterator API. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::sorted_first_label`] surface with the standard-
/// library `&str` equality operator — no new dep, no new IR layer,
/// no supertrait bound, no allocation, no [`Option`]-typed
/// dispatch.
fn is_sorted_first_label(s: &str) -> bool {
s == <Self as ClosedSet>::sorted_first_label()
}
/// The lexicographic-order tail-endpoint LABEL predicate — `true`
/// iff `s` equals [`Self::sorted_last_label`], `false` otherwise.
/// Closes the (`&str`, lex, tail) corner of the (arg-type ×
/// ordering × endpoint-direction) 2×2×2 = 8-corner endpoint-
/// membership hypercube alongside [`Self::is_first`] (Self,
/// declaration, head), [`Self::is_last`] (Self, declaration, tail),
/// [`Self::is_sorted_first`] (Self, lex, head),
/// [`Self::is_sorted_last`] (Self, lex, tail),
/// [`Self::is_first_label`] (&str, declaration, head),
/// [`Self::is_last_label`] (&str, declaration, tail), and
/// [`Self::is_sorted_first_label`] (&str, lex, head), completing
/// the 8-corner hypercube on the closed-set endpoint-membership
/// surface.
///
/// Sibling posture to [`Self::is_sorted_first_label`] one endpoint-
/// direction axis over on the (head, tail) partition of the lex-
/// axis label-shaped endpoint-membership surface:
/// [`Self::is_sorted_first_label`] answers "is this &str the lex-
/// order head-endpoint label?", this method answers "is this &str
/// the lex-order tail-endpoint label?". See
/// [`Self::is_sorted_first_label`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the tail-direction arm of the same axis and inherits every
/// property from the head arm's documentation, differing only in
/// the composition through [`Self::sorted_last_label`] instead of
/// [`Self::sorted_first_label`].
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_last_label`]) with the standard-library `&str`
/// equality operator. The label-shaped lex-tail-membership contract
/// — `T::is_sorted_last_label(T::sorted_last().label()) == true`
/// AND `T::is_sorted_last_label(v.label()) == false` for every non-
/// lex-last canonical variant `v` on every implementor — is
/// guaranteed by the composition; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (53) pins the
/// composition against the natural `s == T::sorted_last_label()`
/// shape on every implementor across every canonical variant label
/// AND the reserved probe input AND the empty-string boundary.
///
/// Clauses (30) + (31) + (50) + (51) + (52) + (53) together CLOSE
/// the (arg-type × ordering × endpoint-direction) 2×2×2 = 8-corner
/// endpoint-membership hypercube on the closed-set endpoint-
/// membership surface: (Self, declaration, head/tail) at clauses
/// (30) — [`Self::is_first`] / [`Self::is_last`]; (Self, lex,
/// head/tail) at clauses (31) — [`Self::is_sorted_first`] /
/// [`Self::is_sorted_last`]; (&str, declaration, head/tail) at
/// clauses (50) + (51) — [`Self::is_first_label`] /
/// [`Self::is_last_label`]; (&str, lex, head/tail) at clauses (52)
/// and (53) — [`Self::is_sorted_first_label`] and this method.
/// Every generic consumer that binds any of the eight endpoint-
/// membership methods sees the SAME endpoint-membership answer at
/// every crate boundary regardless of which arg-type axis /
/// ordering-axis / endpoint-direction axis it walks.
fn is_sorted_last_label(s: &str) -> bool {
s == <Self as ClosedSet>::sorted_last_label()
}
/// The declaration-order endpoint-membership predicate — `true`
/// when `self` is either [`Self::first`] or [`Self::last`],
/// `false` on every strictly-interior slot. The endpoint-partition
/// arm of the (endpoint, interior) boolean-partition axis over the
/// declaration-axis endpoint surface — one predicate-flavor axis
/// over from the point-membership pair
/// ([`Self::is_first`], [`Self::is_last`]) and the natural
/// complement of [`Self::is_interior`].
///
/// Opens the (predicate-flavor × ordering) 2×2 matrix over the
/// declaration-axis boolean-boundary surface — the endpoint-cube
/// closure of clauses (30) + (31) named the point-membership arm
/// per direction; this method + [`Self::is_interior`] name the
/// **compound partition arm** the point-membership pair induces
/// under `∨` and its negation:
///
/// | Predicate flavor \\ Ordering | Declaration | Lex |
/// |---------------------------------|------------------------|-----------------------------|
/// | Point (head / tail) | [`Self::is_first`] / [`Self::is_last`] | [`Self::is_sorted_first`] / [`Self::is_sorted_last`] |
/// | Boundary (endpoint / interior) | [`Self::is_endpoint`] / [`Self::is_interior`] | [`Self::is_sorted_endpoint`] / [`Self::is_sorted_interior`] |
///
/// Every generic consumer that partitions the closed set into
/// (structural-boundary, strict-interior) slots without threading
/// the caller through a per-endpoint `is_first || is_last`
/// disjunction (a bounded-iteration guard that emits a
/// `first-or-last-slot` sentinel event on either terminus, a
/// wraparound-cursor renderer that renders a shared boundary badge
/// on both endpoints without duplicating the badge-emit fork,
/// a truth-table property test that anchors a shared
/// endpoint-parity assertion across both endpoint anchors, a
/// saga-step engine that opens a "structural-boundary" audit
/// event on either the head OR the tail, a per-tick UI carousel
/// that renders a persistent "at-boundary" glyph on both ends of
/// the chain, a phase-fold reducer whose interior arm short-
/// circuits ONLY when the current slot is strictly-interior) binds
/// to ONE typed compound predicate rather than hand-rolling either
/// the `self.is_first() || self.is_last()` disjunction (which
/// re-derives the same two-primitive composition at every callsite
/// AND makes every downstream site depend on the disjunction
/// shape) OR the `self.index_of() == 0 || self.index_of() + 1 ==
/// T::CARDINALITY` composition (which re-derives the same three-
/// primitive composition at every callsite AND makes every
/// downstream site depend on the `usize` boundary arithmetic) OR
/// a per-implementor inline `matches!(self, Self::Head | Self::
/// Tail)` block (which re-derives the per-variant endpoint table
/// at every callsite AND drifts silently when [`Self::ALL`] gains
/// a new variant that reorders the head/tail slots).
///
/// Default body composes [`Self::is_first`] with [`Self::is_last`]
/// under `||` — the boundary-membership predicate is a typed
/// CONSEQUENCE of the two pre-existing point-membership primitives
/// on the declaration axis, not a third codepath through
/// [`Self::index_of`] arithmetic. Implementors override only when
/// the boundary-membership surface needs to diverge from the
/// natural `is_first(self) || is_last(self)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `first` / `last` /
/// `is_first` / `is_last` overrides exist — a typed escape hatch
/// the trait surface exposes rather than forcing the implementor
/// to hand-roll the impl). An implementor that overrides either
/// [`Self::is_first`] OR [`Self::is_last`] propagates the override
/// through this default body automatically; the (variant → bool
/// boundary-membership) projection funnels through the SAME pair of
/// point-membership primitives the endpoint cube already routes.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] equals [`Self::last`],
/// so both point-membership predicates fire on the same variant
/// and this predicate returns `true` for the sole variant.
/// [`Self::is_interior`] correspondingly returns `false` — a
/// singleton has zero interior slots. Mirrors the singleton
/// collapse the point-membership axis observes at [`Self::first`]
/// / [`Self::last`] and preserves the (endpoint XOR interior)
/// partition semantics even at the boundary-cardinality edge.
///
/// The boundary-membership contract —
/// `T::first().is_endpoint() == true` AND
/// `T::last().is_endpoint() == true` on every implementor — is
/// guaranteed by the composition through
/// [`Self::is_first`] / [`Self::is_last`]'s endpoint-fixpoint
/// clauses (30); the well-formedness clause (32) pins the
/// composition against the natural
/// `is_first(self) || is_last(self)` shape AND the boundary-
/// endpoint `true` fixpoints on every implementor, so a passing
/// well-formedness sweep means every generic consumer can call
/// [`Self::is_endpoint`] on any typed variant and expect the same
/// `bool` answer at every crate boundary. The (endpoint,
/// interior) partition is EXHAUSTIVE — every variant in
/// [`Self::ALL`] answers `true` to EXACTLY ONE of the two
/// predicates, pinned by clause (32)'s complementarity assertion
/// `is_endpoint(v) != is_interior(v)` on every representative
/// input.
///
/// THEORY.md §III — the typescape; the (variant → boundary-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `self.is_first() || self.is_last()` composition at every
/// downstream structural-boundary query site. The (predicate-
/// flavor × ordering) 2×2 matrix over the declaration-axis
/// boolean-boundary surface opens a NEW axis alongside the
/// (return-type × direction) 2×2 endpoint-anchor / endpoint-
/// membership matrix clauses (18) + (30) already close on the
/// declaration axis.
/// THEORY.md §V.1 — knowable platform; the (variant → boundary-
/// membership) projection was an unnamed compound of
/// [`Self::is_first`] + [`Self::is_last`] + `||` pre-lift;
/// naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the two point-membership primitives — generic consumers see
/// ONE method, not one boundary-disjunction-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// boundary-membership) projection emerges from the composition of
/// TWO substrate primitives ([`Self::is_first`], [`Self::is_last`])
/// under the standard-library boolean `||` operator rather than as
/// a per-implementor `match self { ... }` block. A future
/// tightening of either primitive (a future const-fn axis that
/// makes the predicate callable in const contexts, a future
/// `#[closed_set(head = "…", tail = "…")]` derive attribute that
/// swaps the endpoint anchors) propagates to every closed-set
/// boundary-membership consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-boundary?` on closed
/// enumerations (the `∨`-composed endpoint membership predicate
/// over both anchors of the declaration-order chain); Idris's
/// `Fin (S n)` non-empty finite-cardinality types where the
/// (head, tail) endpoint partition folds through a shared
/// `isBoundary : Fin (S n) -> Bool` projection under boolean-or;
/// Haskell's `(\x -> x == minBound || x == maxBound)` on the
/// `Bounded + Enum` type-class pair; MLIR's
/// `RegisteredOperationName::isEndpoint()` on the declaration-
/// order Op registry; Idris's `Fin n` finite-cardinality type with
/// a boundary predicate composing the head + tail endpoint
/// checks; Racket's `(or (enum-first? e v) (enum-last? e v))`
/// composed at the callsite the substrate would rather bind at
/// the trait. Translation through pleme-io primitives: a pure
/// default method composing the trait's existing
/// [`Self::is_first`] and [`Self::is_last`] point-membership
/// primitives under the standard-library boolean `||` operator —
/// no new dep, no new IR layer, no supertrait bound, no `usize`
/// arithmetic discharge.
fn is_endpoint(self) -> bool {
<Self as ClosedSet>::is_first(self) || <Self as ClosedSet>::is_last(self)
}
/// The declaration-order interior-membership predicate — `true`
/// when `self` is neither [`Self::first`] nor [`Self::last`],
/// `false` on both endpoints. The natural complement of
/// [`Self::is_endpoint`] on the (endpoint, interior) boolean-
/// partition axis over the declaration-axis endpoint surface.
///
/// Sibling posture to [`Self::is_endpoint`] one arm over on the
/// (endpoint, interior) partition — [`Self::is_endpoint`] fires
/// on both structural anchors, this method fires on every
/// strictly-interior slot. See [`Self::is_endpoint`] for the
/// shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the complement-direction arm of
/// the same predicate-flavor axis and inherits every property
/// from the endpoint arm's documentation, differing only in the
/// leading `!` negation and the strictly-interior consumer
/// surface (a bounded-loop that walks ONLY interior slots and
/// short-circuits on either endpoint, a phase-fold reducer whose
/// interior arm processes NON-boundary payloads and reserves the
/// endpoint arm for boundary-only side effects, an
/// alphabetized-completion pass that hides the first + last
/// entries from a strictly-interior candidate list).
///
/// Default body composes [`Self::is_endpoint`] with the standard-
/// library `!` operator — the interior-membership predicate is a
/// typed CONSEQUENCE of the boundary-membership disjunction, not
/// a third codepath through `is_first ∧ is_last` inversion.
/// Implementors override only when the interior-membership
/// surface needs to diverge from the natural
/// `!is_endpoint(self)` shape (no production implementor reaches
/// for this today; the axis exists for the same reason
/// `is_endpoint` / `is_first` / `is_last` overrides exist — a
/// typed escape hatch rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::is_endpoint`] propagates the override through this
/// default body automatically; the (variant → bool interior-
/// membership) projection funnels through ONE typed primitive.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::is_endpoint`] fires on the sole
/// variant, so this method returns `false` for that variant. A
/// singleton closed set has ZERO interior slots by construction —
/// [`Self::ALL`] is `[Self::Only]` and the sole element is BOTH
/// endpoints simultaneously, leaving no room for a strictly-
/// interior slot. Mirrors the singleton collapse
/// [`Self::is_endpoint`] observes and preserves the (endpoint XOR
/// interior) partition semantics even at the boundary-cardinality
/// edge.
///
/// The (endpoint, interior) partition contract —
/// `is_endpoint(v) != is_interior(v)` on every variant `v` in
/// [`Self::ALL`] — is guaranteed by the default composition
/// through [`Self::is_endpoint`]'s `!` negation; the well-
/// formedness clause (32) pins the complementarity assertion on
/// every implementor so a passing well-formedness sweep means
/// every generic consumer can call [`Self::is_interior`] on any
/// typed variant and expect the exact complement of
/// [`Self::is_endpoint`] on the same variant. The endpoint-fix-
/// point corollary `T::first().is_interior() == false` AND
/// `T::last().is_interior() == false` is guaranteed by clause
/// (32)'s endpoint-anchor pin composed with the complementarity
/// assertion.
fn is_interior(self) -> bool {
!<Self as ClosedSet>::is_endpoint(self)
}
/// The lexicographic-order endpoint-membership predicate — `true`
/// when `self` is either [`Self::sorted_first`] or
/// [`Self::sorted_last`], `false` on every strictly-interior lex
/// slot. The endpoint-partition arm of the (endpoint, interior)
/// boolean-partition axis over the LEX-axis endpoint surface —
/// one predicate-flavor axis over from the lex point-membership
/// pair ([`Self::is_sorted_first`], [`Self::is_sorted_last`]) and
/// the natural complement of [`Self::is_sorted_interior`].
///
/// Closes the (predicate-flavor × ordering) 2×2 matrix over the
/// boolean-boundary surface — the declaration-axis arm
/// ([`Self::is_endpoint`] / [`Self::is_interior`]) is one ordering
/// axis over; this method + [`Self::is_sorted_interior`] name the
/// **compound partition arm** the lex point-membership pair induces
/// under `∨` and its negation:
///
/// | Predicate flavor \\ Ordering | Declaration | Lex |
/// |---------------------------------|------------------------|-----------------------------|
/// | Point (head / tail) | [`Self::is_first`] / [`Self::is_last`] | [`Self::is_sorted_first`] / [`Self::is_sorted_last`] |
/// | Boundary (endpoint / interior) | [`Self::is_endpoint`] / [`Self::is_interior`] | [`Self::is_sorted_endpoint`] / [`Self::is_sorted_interior`] |
///
/// Every generic consumer that partitions the closed set into
/// (lex-structural-boundary, lex-strict-interior) slots without
/// threading the caller through a per-endpoint
/// `is_sorted_first || is_sorted_last` disjunction (a bounded
/// alphabetized-iteration guard that emits a `lex-first-or-last-
/// slot` sentinel event on either lex terminus, an alphabetized-
/// carousel renderer that draws a shared boundary badge on both
/// lex endpoints without duplicating the badge-emit fork, a
/// truth-table property test that anchors a shared lex-endpoint-
/// parity assertion across both lex-endpoint anchors, a saga-step
/// engine that opens a "lex-structural-boundary" audit event on
/// either the lex head OR the lex tail, an alphabetized-completion
/// UI that renders a persistent "at-lex-boundary" glyph on both
/// ends of the alphabetized chain, a lex-phase-fold reducer whose
/// interior arm short-circuits ONLY when the current slot is
/// strictly-lex-interior) binds to ONE typed compound predicate
/// rather than hand-rolling either the
/// `self.is_sorted_first() || self.is_sorted_last()` disjunction
/// (which re-derives the same two-primitive composition at every
/// callsite AND makes every downstream site depend on the
/// disjunction shape) OR the
/// `self.sorted_index_of() == 0
/// || self.sorted_index_of() + 1 == T::CARDINALITY`
/// composition (which re-derives the same three-primitive
/// composition at every callsite AND makes every downstream site
/// depend on the `usize` boundary arithmetic on the lex axis) OR
/// a per-implementor inline
/// `matches!(self, Self::LexHead | Self::LexTail)` block (which
/// re-derives the per-variant lex-endpoint table at every callsite
/// AND drifts silently when [`Self::label`] gains a new variant
/// that reorders the lex-head / lex-tail slots).
///
/// Default body composes [`Self::is_sorted_first`] with
/// [`Self::is_sorted_last`] under `||` — the lex boundary-
/// membership predicate is a typed CONSEQUENCE of the two pre-
/// existing lex point-membership primitives, not a third codepath
/// through [`Self::sorted_index_of`] arithmetic. Implementors
/// override only when the lex boundary-membership surface needs to
/// diverge from the natural
/// `is_sorted_first(self) || is_sorted_last(self)` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `is_sorted_first` / `is_sorted_last` /
/// `is_endpoint` / `is_interior` overrides exist — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides either [`Self::is_sorted_first`] OR
/// [`Self::is_sorted_last`] propagates the override through this
/// default body automatically; the (variant → bool lex-boundary-
/// membership) projection funnels through the SAME pair of lex
/// point-membership primitives the endpoint cube already routes.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] equals
/// [`Self::sorted_last`], so both lex point-membership predicates
/// fire on the same variant and this predicate returns `true` for
/// the sole variant. [`Self::is_sorted_interior`] correspondingly
/// returns `false` — a singleton has zero lex-interior slots.
/// Mirrors the singleton collapse [`Self::is_endpoint`] observes
/// one ordering axis over and preserves the (lex-endpoint XOR
/// lex-interior) partition semantics even at the boundary-
/// cardinality edge.
///
/// The lex boundary-membership contract —
/// `T::sorted_first().is_sorted_endpoint() == true` AND
/// `T::sorted_last().is_sorted_endpoint() == true` on every
/// implementor — is guaranteed by the composition through
/// [`Self::is_sorted_first`] / [`Self::is_sorted_last`]'s lex-
/// endpoint-fixpoint clause (31); the well-formedness clause (33)
/// pins the composition against the natural
/// `is_sorted_first(self) || is_sorted_last(self)` shape AND the
/// lex-boundary-endpoint `true` fixpoints on every implementor, so
/// a passing well-formedness sweep means every generic consumer
/// can call [`Self::is_sorted_endpoint`] on any typed variant and
/// expect the same `bool` answer at every crate boundary. The
/// (lex-endpoint, lex-interior) partition is EXHAUSTIVE — every
/// variant in [`Self::ALL`] answers `true` to EXACTLY ONE of the
/// two predicates, pinned by clause (33)'s complementarity
/// assertion
/// `is_sorted_endpoint(v) != is_sorted_interior(v)` on every
/// representative input.
///
/// THEORY.md §III — the typescape; the (variant → lex-boundary-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `self.is_sorted_first() || self.is_sorted_last()` composition
/// at every downstream lex-structural-boundary query site. The
/// (predicate-flavor × ordering) 2×2 matrix over the boolean-
/// boundary surface CLOSES on the lex axis — the sibling
/// declaration-axis matrix opened with clause (32) is now paired
/// under a shared partition-flavor axis.
/// THEORY.md §V.1 — knowable platform; the (variant → lex-
/// boundary-membership) projection was an unnamed compound of
/// [`Self::is_sorted_first`] + [`Self::is_sorted_last`] + `||`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two lex point-membership primitives —
/// generic consumers see ONE method, not one lex-boundary-
/// disjunction-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// lex-boundary-membership) projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::is_sorted_first`], [`Self::is_sorted_last`]) under
/// the standard-library boolean `||` operator rather than as a
/// per-implementor `match self { ... }` block. A future tightening
/// of either primitive (a future const-fn lex axis, a future
/// case-insensitive-label extension that shifts which variant
/// lands at the lex-min slot, a future perfect-hash lex-order
/// projection) propagates to every closed-set lex-boundary-
/// membership consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-sorted-boundary?` on
/// closed enumerations under lex-ordering (the `∨`-composed lex-
/// endpoint-membership predicate over both anchors of the
/// alphabetized chain); Idris's `Fin (S n)` non-empty finite-
/// cardinality types where the (lex head, lex tail) endpoint
/// partition folds through a shared
/// `isSortedBoundary : Fin (S n) -> Bool` projection under
/// boolean-or; Haskell's `(\x -> x == minimumBy comparing label
/// [minBound..] || x == maximumBy comparing label [minBound..])`
/// on the `Bounded + Enum` type-class pair with a `sortBy label`
/// prelude; MLIR's `RegisteredOperationName::isLexEndpoint()` on
/// the lex-sorted Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::is_sorted_first`] and [`Self::is_sorted_last`]
/// lex point-membership primitives under the standard-library
/// boolean `||` operator — no new dep, no new IR layer, no
/// supertrait bound, no `usize` arithmetic discharge.
fn is_sorted_endpoint(self) -> bool {
<Self as ClosedSet>::is_sorted_first(self) || <Self as ClosedSet>::is_sorted_last(self)
}
/// The lexicographic-order interior-membership predicate — `true`
/// when `self` is neither [`Self::sorted_first`] nor
/// [`Self::sorted_last`], `false` on both lex endpoints. The
/// natural complement of [`Self::is_sorted_endpoint`] on the
/// (endpoint, interior) boolean-partition axis over the LEX-axis
/// endpoint surface.
///
/// Sibling posture to [`Self::is_sorted_endpoint`] one arm over
/// on the (endpoint, interior) partition — [`Self::is_sorted_endpoint`]
/// fires on both lex-structural anchors, this method fires on
/// every strictly-lex-interior slot. See [`Self::is_sorted_endpoint`]
/// for the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the complement-direction arm of
/// the same predicate-flavor axis and inherits every property from
/// the lex-endpoint arm's documentation, differing only in the
/// leading `!` negation and the strictly-lex-interior consumer
/// surface (a bounded lex-loop that walks ONLY interior alphabet
/// slots and short-circuits on either lex endpoint, a lex-phase-
/// fold reducer whose interior arm processes NON-boundary
/// alphabetized payloads and reserves the lex-endpoint arm for
/// lex-boundary-only side effects, an alphabetized-completion pass
/// that hides the alphabetically-first + alphabetically-last
/// entries from a strictly-interior candidate list).
///
/// Default body composes [`Self::is_sorted_endpoint`] with the
/// standard-library `!` operator — the lex interior-membership
/// predicate is a typed CONSEQUENCE of the lex boundary-membership
/// disjunction, not a third codepath through
/// `is_sorted_first ∧ is_sorted_last` inversion. Implementors
/// override only when the lex interior-membership surface needs
/// to diverge from the natural `!is_sorted_endpoint(self)` shape
/// (no production implementor reaches for this today; the axis
/// exists for the same reason `is_sorted_endpoint` /
/// `is_sorted_first` / `is_sorted_last` overrides exist — a typed
/// escape hatch rather than forcing the implementor to hand-roll
/// the impl). An implementor that overrides
/// [`Self::is_sorted_endpoint`] propagates the override through
/// this default body automatically; the (variant → bool lex-
/// interior-membership) projection funnels through ONE typed
/// primitive.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::is_sorted_endpoint`] fires on
/// the sole variant, so this method returns `false` for that
/// variant. A singleton closed set has ZERO lex-interior slots by
/// construction — [`Self::ALL`] is `[Self::Only]` and the sole
/// element is BOTH lex endpoints simultaneously, leaving no room
/// for a strictly-lex-interior slot. Mirrors the singleton
/// collapse [`Self::is_sorted_endpoint`] observes and preserves
/// the (lex-endpoint XOR lex-interior) partition semantics even
/// at the boundary-cardinality edge.
///
/// The (lex-endpoint, lex-interior) partition contract —
/// `is_sorted_endpoint(v) != is_sorted_interior(v)` on every
/// variant `v` in [`Self::ALL`] — is guaranteed by the default
/// composition through [`Self::is_sorted_endpoint`]'s `!`
/// negation; the well-formedness clause (33) pins the
/// complementarity assertion on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// [`Self::is_sorted_interior`] on any typed variant and expect
/// the exact complement of [`Self::is_sorted_endpoint`] on the
/// same variant. The lex-endpoint-anti-fix-point corollary
/// `T::sorted_first().is_sorted_interior() == false` AND
/// `T::sorted_last().is_sorted_interior() == false` is guaranteed
/// by clause (33)'s lex-endpoint-anchor pin composed with the
/// complementarity assertion.
fn is_sorted_interior(self) -> bool {
!<Self as ClosedSet>::is_sorted_endpoint(self)
}
/// The declaration-order label-shaped endpoint-membership predicate —
/// `true` iff `s` equals [`Self::first_label`] OR [`Self::last_label`],
/// `false` on every strictly-interior canonical label AND on every non-
/// canonical input. Closes the (`&str`, declaration, endpoint) corner
/// of the (arg-type × ordering × predicate-flavor) 2×2×2 = 8-corner
/// boolean-boundary hypercube alongside [`Self::is_endpoint`] (Self,
/// declaration, endpoint), [`Self::is_interior`] (Self, declaration,
/// interior), [`Self::is_sorted_endpoint`] (Self, lex, endpoint), and
/// [`Self::is_sorted_interior`] (Self, lex, interior), opening the
/// label-shaped column on the boolean-boundary surface one arg-type
/// axis over from the pre-existing `Self`-arg (endpoint, interior)
/// partition.
///
/// Sibling posture to [`Self::is_endpoint`] one arg-type axis over on
/// the (`Self`, `&str`) partition of the declaration-axis boolean-
/// boundary surface: [`Self::is_endpoint`] answers "is this variant
/// the declaration-order head OR tail?", this method answers "is this
/// &str the declaration-order head-endpoint OR tail-endpoint label?"
/// for a raw label string WITHOUT decoding through
/// [`Self::parse_label`] or [`Self::find_by_label`] (which would
/// allocate the reject carrier on non-matching inputs OR force the
/// caller through the `Option<Self>`-typed dispatch). See
/// [`Self::is_endpoint`] for the shared design rationale, sibling
/// matrix, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the label-
/// shaped-arg-type arm of the same predicate-flavor + ordering axis
/// and inherits every property from the `Self`-arg endpoint arm's
/// documentation, differing only in the composition through
/// [`Self::is_first_label`] + [`Self::is_last_label`] instead of
/// [`Self::is_first`] + [`Self::is_last`].
///
/// Default body composes [`Self::is_first_label`] with
/// [`Self::is_last_label`] under `||` — the label-shaped boundary-
/// membership predicate is a typed CONSEQUENCE of the two pre-
/// existing label-shaped point-membership primitives, not a third
/// codepath through [`Self::find_by_label`] with `Option::map`.
/// Implementors override only when the label-shaped boundary-
/// membership surface needs to diverge from the natural
/// `is_first_label(s) || is_last_label(s)` shape (no production
/// implementor reaches for this today; the axis exists for the same
/// reason `is_first_label` / `is_last_label` / `is_endpoint` /
/// `is_interior` overrides exist — a typed escape hatch the trait
/// surface exposes rather than forcing the implementor to hand-roll
/// the impl). An implementor that overrides either
/// [`Self::is_first_label`] OR [`Self::is_last_label`] propagates the
/// override through this default body automatically.
///
/// Non-canonical input contract — the reserved probe rejects
/// (`false`) and the empty-string boundary rejects (`false`) by
/// clause (4) composed with the (50) + (51) clauses that pin
/// [`Self::is_first_label`] / [`Self::is_last_label`]'s non-empty
/// canonical-label surface. Every generic consumer that binds this
/// predicate as its zero-alloc label-shaped structural-boundary
/// query surface (an annotation-key filter that fires on
/// `tatara.pleme.io/*` boundary keys without decoding through
/// `parse_label`'s carrier allocation, a diagnostic renderer that
/// emits a shared boundary badge on either endpoint label without
/// paying the two-primitive disjunction at each callsite, a lint
/// that flags label strings drifting away from the declared endpoint
/// pair) sees the SAME `bool` at every crate boundary.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first_label`] equals
/// [`Self::last_label`], so both label-shaped point-membership
/// predicates fire on the same canonical label and this predicate
/// returns `true` for the sole variant's label. [`Self::is_interior_label`]
/// correspondingly returns `false` — a singleton has zero interior
/// slots. Mirrors the singleton collapse [`Self::is_endpoint`]
/// observes at the `Self`-arg column one arg-type axis over.
///
/// THEORY.md §III — the typescape; the (&str → declaration-boundary-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `T::is_first_label(s) || T::is_last_label(s)` composition at every
/// downstream label-shaped structural-boundary query site.
/// THEORY.md §V.1 — knowable platform; the (&str → declaration-
/// boundary-membership bool) projection was an unnamed compound of
/// [`Self::is_first_label`] + [`Self::is_last_label`] + `||` pre-
/// lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two label-shaped point-membership primitives.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives under
/// the standard-library boolean `||` operator rather than as a
/// per-implementor `match s { ... }` block.
///
/// Frontier inspiration: Racket's `enum-boundary-label?` on closed
/// enumerations under label projection (the `∨`-composed label-
/// shaped endpoint-membership predicate over both declaration-order
/// anchors of the raw label string); Idris's `isBoundaryLabel :
/// String -> Bool` composed via `showFin (first xs) == s ||
/// showFin (last xs) == s`; MLIR's
/// `RegisteredOperationName::isDeclEndpointName(name)` on the
/// declaration-order Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::is_first_label`] and [`Self::is_last_label`] label-shaped
/// point-membership primitives under the standard-library boolean
/// `||` operator — no new dep, no new IR layer, no supertrait bound,
/// no allocation, no [`Option`]-typed dispatch.
fn is_endpoint_label(s: &str) -> bool {
<Self as ClosedSet>::is_first_label(s) || <Self as ClosedSet>::is_last_label(s)
}
/// The declaration-order label-shaped interior-membership predicate —
/// `true` iff `s` is a canonical label of a strictly-interior variant
/// (neither [`Self::first_label`] nor [`Self::last_label`]),
/// `false` on both endpoint labels AND on every non-canonical input.
/// Closes the (`&str`, declaration, interior) corner of the (arg-type
/// × ordering × predicate-flavor) 2×2×2 = 8-corner boolean-boundary
/// hypercube alongside [`Self::is_endpoint_label`] (&str,
/// declaration, endpoint).
///
/// Sibling posture to [`Self::is_interior`] one arg-type axis over
/// on the (`Self`, `&str`) partition of the declaration-axis
/// boolean-boundary surface: [`Self::is_interior`] answers "is this
/// variant strictly interior?", this method answers "is this &str
/// the label of a strictly-interior variant?" for a raw label string
/// WITHOUT decoding through [`Self::parse_label`] or
/// [`Self::find_by_label`].
///
/// Default body composes [`Self::contains_label`] with
/// [`!Self::is_endpoint_label`] under `&&` — a canonical label
/// answers `true` iff it is in the closed-set canonical labeling
/// AND is NOT an endpoint label; every non-canonical input answers
/// `false` because [`Self::contains_label`] rejects it. This shape
/// diverges from the `Self`-arg default `!is_endpoint(self)` (which
/// would answer `true` for a non-canonical input on the label
/// side) — the `&str` arg-type axis requires a domain-membership
/// gate because the input domain is unbounded, unlike the closed
/// `Self` domain. Composition rejects the reserved probe (falls out
/// of `contains_label`) and the empty-string boundary
/// (falls out of clause (4)'s empty-string reservation composed
/// with `contains_label`'s natural sweep).
///
/// Implementors override only when the label-shaped interior-
/// membership surface needs to diverge from the natural
/// `contains_label(s) && !is_endpoint_label(s)` shape (no production
/// implementor reaches for this today; the axis exists for the same
/// reason `is_endpoint_label` / `is_interior` / `contains_label`
/// overrides exist — a typed escape hatch). An implementor that
/// overrides [`Self::contains_label`] OR [`Self::is_endpoint_label`]
/// propagates the override through this default body automatically.
///
/// The (label-shaped endpoint, label-shaped interior) partition
/// contract on the CANONICAL sub-domain —
/// `is_endpoint_label(v.label()) != is_interior_label(v.label())`
/// for every variant `v` in [`Self::ALL`] — is guaranteed by the
/// default composition; the well-formedness clause (55) pins the
/// complementarity assertion on every canonical label. Outside the
/// canonical sub-domain BOTH predicates return `false` (the input
/// belongs to neither the endpoint sub-label nor the interior sub-
/// label — the label-shaped predicates project to `false` on the
/// non-canonical column, mirroring the `find_by_label(s).is_none()`
/// rejection semantics of [`Self::parse_label`]).
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `false` for the sole variant's label (the sole label is
/// BOTH endpoints so `is_endpoint_label` fires; the interior arm
/// correspondingly rejects).
///
/// THEORY.md §III — the typescape; the (&str → declaration-interior-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `T::contains_label(s) && !T::is_endpoint_label(s)` composition.
/// THEORY.md §V.1 — knowable platform; naming the projection on the
/// trait turns "the label is a strictly-interior canonical" from an
/// unnamed compound into a workspace-wide theorem.
///
/// Frontier inspiration: Racket's `enum-interior-label?` on closed
/// enumerations under label projection; Haskell's
/// `(\s -> s `elem` labels && s /= minLabel && s /= maxLabel)` on
/// the `Bounded + Show` type-class pair with a `sortBy id` prelude;
/// MLIR's `RegisteredOperationName::isDeclInteriorName(name)` on the
/// declaration-order Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::contains_label`] and [`Self::is_endpoint_label`] surfaces
/// under the standard-library boolean `&&` operator with unary `!` —
/// no new dep, no new IR layer, no supertrait bound, no allocation,
/// no [`Option`]-typed dispatch.
fn is_interior_label(s: &str) -> bool {
<Self as ClosedSet>::contains_label(s) && !<Self as ClosedSet>::is_endpoint_label(s)
}
/// The lexicographic-order label-shaped endpoint-membership
/// predicate — `true` iff `s` equals [`Self::sorted_first_label`]
/// OR [`Self::sorted_last_label`], `false` on every strictly-lex-
/// interior canonical label AND on every non-canonical input.
/// Closes the (`&str`, lex, endpoint) corner of the (arg-type ×
/// ordering × predicate-flavor) 2×2×2 = 8-corner boolean-boundary
/// hypercube alongside [`Self::is_endpoint_label`] (&str,
/// declaration, endpoint) and [`Self::is_sorted_endpoint`] (Self,
/// lex, endpoint).
///
/// Sibling posture to [`Self::is_sorted_endpoint`] one arg-type
/// axis over on the (`Self`, `&str`) partition of the lex-axis
/// boolean-boundary surface: [`Self::is_sorted_endpoint`] answers
/// "is this variant the lex head OR tail?", this method answers "is
/// this &str the lex head-endpoint OR tail-endpoint label?" for a
/// raw label string. See [`Self::is_sorted_endpoint`] for the
/// shared rationale, sibling matrix, override axis, and future-
/// consumer inventory.
///
/// Default body composes [`Self::is_sorted_first_label`] with
/// [`Self::is_sorted_last_label`] under `||` — the lex label-
/// shaped boundary-membership predicate is a typed CONSEQUENCE of
/// the two pre-existing lex label-shaped point-membership
/// primitives. Implementors override only when the lex label-
/// shaped boundary-membership surface needs to diverge from the
/// natural `is_sorted_first_label(s) || is_sorted_last_label(s)`
/// shape. An implementor that overrides either
/// [`Self::is_sorted_first_label`] OR [`Self::is_sorted_last_label`]
/// propagates the override through this default body automatically.
///
/// Non-canonical input contract — the reserved probe rejects and
/// the empty-string boundary rejects by clause (4) composed with
/// (52) + (53). Divergence from [`Self::is_endpoint_label`] on the
/// declaration axis is real: on any implementor whose declaration
/// order diverges from its lex order at the endpoints, this
/// predicate answers `true` on the lex-endpoint canonical labels
/// (which may be strictly-interior on the declaration axis), and
/// [`Self::is_endpoint_label`] answers `true` on the declaration-
/// endpoint canonical labels (which may be strictly-interior on
/// the lex axis).
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `true` for the sole variant's label (both lex point-
/// membership predicates fire on the same label).
///
/// THEORY.md §III — the typescape; the (&str → lex-boundary-
/// membership bool) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `T::is_sorted_first_label(s) || T::is_sorted_last_label(s)`
/// composition.
/// THEORY.md §V.1 — knowable platform; naming the projection on the
/// trait turns "the label is an alphabetized-boundary label" from
/// an unnamed compound into a workspace-wide theorem.
///
/// Frontier inspiration: Racket's `enum-sorted-boundary-label?` on
/// closed enumerations under lex-ordered label projection; Idris's
/// `isSortedBoundaryLabel : String -> Bool` composed via
/// `showFin (sortedFirst xs) == s ||
/// showFin (sortedLast xs) == s`; MLIR's
/// `RegisteredOperationName::isLexEndpointName(name)` on the lex-
/// sorted Op registry. Translation through pleme-io primitives: a
/// pure default method composing the trait's existing
/// [`Self::is_sorted_first_label`] and
/// [`Self::is_sorted_last_label`] surfaces under the standard-
/// library boolean `||` operator — no new dep, no new IR layer, no
/// supertrait bound, no allocation, no [`Option`]-typed dispatch.
fn is_sorted_endpoint_label(s: &str) -> bool {
<Self as ClosedSet>::is_sorted_first_label(s)
|| <Self as ClosedSet>::is_sorted_last_label(s)
}
/// The lexicographic-order label-shaped interior-membership
/// predicate — `true` iff `s` is a canonical label of a strictly-
/// lex-interior variant, `false` on both lex-endpoint labels AND on
/// every non-canonical input. Closes the (`&str`, lex, interior)
/// corner and the final corner of the (arg-type × ordering ×
/// predicate-flavor) 2×2×2 = 8-corner boolean-boundary hypercube
/// alongside [`Self::is_sorted_endpoint_label`] (&str, lex,
/// endpoint), [`Self::is_endpoint_label`] (&str, declaration,
/// endpoint), [`Self::is_interior_label`] (&str, declaration,
/// interior), [`Self::is_endpoint`] / [`Self::is_interior`] on the
/// declaration `Self`-arg column, and [`Self::is_sorted_endpoint`]
/// / [`Self::is_sorted_interior`] on the lex `Self`-arg column.
///
/// Sibling posture to [`Self::is_sorted_interior`] one arg-type
/// axis over on the (`Self`, `&str`) partition of the lex-axis
/// boolean-boundary surface: [`Self::is_sorted_interior`] answers
/// "is this variant strictly lex-interior?", this method answers
/// "is this &str the label of a strictly-lex-interior variant?"
/// for a raw label string WITHOUT decoding through
/// [`Self::parse_label`] or [`Self::find_by_label`].
///
/// Default body composes [`Self::contains_label`] with
/// [`!Self::is_sorted_endpoint_label`] under `&&` — mirrors the
/// declaration-axis [`Self::is_interior_label`] one ordering axis
/// over. The `&str` arg-type axis requires the same domain-
/// membership gate as [`Self::is_interior_label`] because the
/// input domain is unbounded; the composition rejects the reserved
/// probe and the empty-string boundary.
///
/// Implementors override only when the lex label-shaped interior-
/// membership surface needs to diverge from the natural
/// `contains_label(s) && !is_sorted_endpoint_label(s)` shape. An
/// implementor that overrides [`Self::contains_label`] OR
/// [`Self::is_sorted_endpoint_label`] propagates the override
/// through this default body automatically.
///
/// The (lex-endpoint-label, lex-interior-label) partition contract
/// on the CANONICAL sub-domain —
/// `is_sorted_endpoint_label(v.label()) !=
/// is_sorted_interior_label(v.label())` for every variant `v` in
/// [`Self::ALL`] — is guaranteed by the default composition; the
/// well-formedness clause (57) pins the complementarity assertion
/// on every canonical label. Outside the canonical sub-domain BOTH
/// predicates return `false`.
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `false` for the sole variant's label (the sole label is
/// BOTH lex endpoints so `is_sorted_endpoint_label` fires; the
/// interior arm correspondingly rejects).
///
/// Clauses (32) + (33) + (54) + (55) + (56) + (57) together CLOSE
/// the (arg-type × ordering × predicate-flavor) 2×2×2 = 8-corner
/// boolean-boundary hypercube — every generic consumer that walks
/// any of the eight (Self-or-&str, declaration-or-lex, endpoint-
/// or-interior) corners of the boundary-partition space binds to
/// ONE typed predicate rather than hand-rolling a composition.
///
/// THEORY.md §III — the typescape; the (&str → lex-interior-
/// membership bool) projection becomes a TYPE projection on the
/// trait. The 8-corner boolean-boundary hypercube CLOSES with
/// this method — every corner of the (arg-type × ordering ×
/// predicate-flavor) space is a typed default trait body composed
/// from substrate primitives.
/// THEORY.md §V.1 — knowable platform; naming the projection on
/// the trait turns "the label is a strictly-lex-interior canonical"
/// from an unnamed compound into a workspace-wide theorem.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives under
/// standard-library boolean operators, rather than as a per-
/// implementor `match s { ... }` block.
///
/// Frontier inspiration: Racket's `enum-sorted-interior-label?` on
/// closed enumerations under lex-ordered label projection;
/// Haskell's
/// `(\s -> s `elem` labels && s /= sortedMinLabel && s /= sortedMaxLabel)`
/// on the `Bounded + Show` type-class pair; MLIR's
/// `RegisteredOperationName::isLexInteriorName(name)` on the lex-
/// sorted Op registry. Translation through pleme-io primitives: a
/// pure default method composing the trait's existing
/// [`Self::contains_label`] and [`Self::is_sorted_endpoint_label`]
/// surfaces under the standard-library boolean `&&` operator with
/// unary `!` — no new dep, no new IR layer, no supertrait bound,
/// no allocation, no [`Option`]-typed dispatch.
fn is_sorted_interior_label(s: &str) -> bool {
<Self as ClosedSet>::contains_label(s) && !<Self as ClosedSet>::is_sorted_endpoint_label(s)
}
/// The declaration-order index-shaped endpoint-membership predicate —
/// `true` iff the `usize` argument equals `0` (the declaration-order
/// head-endpoint's slot in [`Self::ALL`]) OR
/// `T::CARDINALITY - 1` (the declaration-order tail-endpoint's
/// slot), `false` on every strictly-interior slot AND on every
/// out-of-range `usize`. Opens the `usize`-arg column of the
/// (arg-type × ordering × predicate-flavor × endpoint-direction)
/// hyperbook at the (declaration, endpoint) corner alongside the
/// pre-existing `Self`-arg column ([`Self::is_endpoint`],
/// [`Self::is_interior`], [`Self::is_sorted_endpoint`],
/// [`Self::is_sorted_interior`]) and `&str`-arg column
/// ([`Self::is_endpoint_label`], [`Self::is_interior_label`],
/// [`Self::is_sorted_endpoint_label`], [`Self::is_sorted_interior_label`]).
///
/// Sibling posture to [`Self::is_endpoint_label`] one arg-type axis
/// over on the (`Self`, `&str`, `usize`) partition of the
/// declaration-axis boolean-boundary surface:
/// [`Self::is_endpoint_label`] answers "is this &str the label of a
/// declaration-endpoint variant?", this method answers "is this
/// usize the array slot of a declaration-endpoint variant?" for a
/// raw index without materializing through [`Self::from_index`] or
/// [`Self::label_at`]. Every generic consumer that wants a
/// zero-alloc O(1) `usize`-shaped declaration-boundary query (a
/// compact wire codec that short-circuits on either declaration-
/// endpoint slot before materializing a typed variant, a bitset
/// state machine whose bounded head+tail arms fire ONLY on the
/// declaration-endpoint slots, a Prometheus per-slot bucket
/// renderer that draws a shared boundary badge on both endpoints
/// without duplicating the badge-emit fork, a byte-tagged compact-
/// encoding on the declaration-slot carve that anchors both
/// endpoints at distinguished bytes, a `tatara-check` diagnostic
/// renderer that emits an anchored `"declaration boundary slot"`
/// banner ONLY when the offending index equals either endpoint
/// slot) binds to ONE typed predicate rather than hand-rolling
/// either the `i == 0 || i + 1 == T::CARDINALITY` inline
/// composition on the declaration axis (which re-derives the same
/// two-literal composition at every callsite AND silently drifts
/// when the definition of "declaration boundary" gets tightened —
/// a future closed set that reserves declaration slot `0` for a
/// sentinel and shifts every canonical slot up by one, a future
/// const-fn axis that makes the predicate callable in const
/// contexts) OR the `T::from_index(i).map(<T as ClosedSet>::is_endpoint).unwrap_or(false)`
/// composition (which pays an `Option<Self>`-typed dispatch AND
/// folds the out-of-range boundary onto `false` implicitly rather
/// than by direct `usize` composition) OR the
/// `T::label_at(i).map(<T as ClosedSet>::is_endpoint_label).unwrap_or(false)`
/// composition (which pays an `Option<&'static str>`-typed
/// dispatch AND routes through the label-shaped declaration-
/// endpoint predicate one arg-type axis over).
///
/// Default body composes [`Self::is_first_index`] with
/// [`Self::is_last_index`] under `||` — the index-shaped
/// declaration-boundary-membership predicate is a typed CONSEQUENCE
/// of the two pre-existing index-shaped declaration point-membership
/// primitives, not a third codepath through inline literals. The
/// `usize::MAX` overflow answer inherits from
/// [`Self::is_last_index`]'s `checked_add(1) == Some(CARDINALITY)`
/// composition — both arms return `false` on `usize::MAX`, so the
/// disjunction correctly returns `false`. Implementors override
/// only when the index-shaped declaration-boundary-membership
/// surface needs to diverge from the natural
/// `is_first_index(i) || is_last_index(i)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `is_endpoint` / `is_endpoint_label` overrides exist
/// — a typed escape hatch rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides either
/// [`Self::is_first_index`] OR [`Self::is_last_index`] propagates
/// the override through this default body automatically.
///
/// The (declaration-endpoint, declaration-interior) partition
/// contract on the CANONICAL sub-domain
/// `0..T::CARDINALITY` — `is_endpoint_index(i) !=
/// is_interior_index(i)` for every `i ∈ 0..T::CARDINALITY` —
/// is guaranteed by the default composition; the well-formedness
/// clause (78) pins the complementarity assertion on every
/// canonical slot AND the shared out-of-range boundary rejection
/// (`T::is_endpoint_index(T::CARDINALITY) == false`). Outside the
/// canonical sub-domain BOTH predicates return `false` (the input
/// belongs to neither the endpoint sub-slot nor the interior sub-
/// slot — the index-shaped predicates project to `false` on the
/// out-of-range column, mirroring the `find_by_label(s).is_none()`
/// rejection semantics of the `&str`-arg column at
/// [`Self::is_endpoint_label`] and [`Self::is_interior_label`]).
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `true` for the sole variant's slot `0` (both index-
/// shaped point-membership predicates fire on the same slot);
/// [`Self::is_interior_index`] correspondingly returns `false`.
///
/// THEORY.md §III — the typescape; the (usize → declaration-
/// boundary-membership bool) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `i == 0 || i + 1 == T::CARDINALITY` composition on a
/// declaration-slot input at every downstream index-shaped
/// declaration-boundary query site.
/// THEORY.md §V.1 — knowable platform; naming the projection on
/// the trait turns "the index is a declaration-endpoint slot" from
/// an unnamed compound into a workspace-wide theorem.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::is_first_index`], [`Self::is_last_index`]) under the
/// standard-library boolean `||` operator, rather than as a per-
/// implementor `match i { 0 | (T::CARDINALITY - 1) => true, _ =>
/// false }` block.
///
/// Frontier inspiration: Racket's `enum-boundary-index?` on
/// closed enumerations under declaration-order index projection;
/// Idris's `isFZOrFS n (last n) : Fin (S n) -> Bool` composed
/// through `finToNat` on the declaration-order finite type;
/// Haskell's `\i -> i == 0 || i == length labels - 1` on the
/// `Bounded + Enum` type-class pair; MLIR's
/// `RegisteredOperationName::isDeclEndpointIndex(idx)` on the
/// declaration-order Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::is_first_index`] and [`Self::is_last_index`]
/// surfaces under the standard-library boolean `||` operator — no
/// new dep, no new IR layer, no supertrait bound, no allocation,
/// no [`Option`]-typed dispatch.
fn is_endpoint_index(i: usize) -> bool {
<Self as ClosedSet>::is_first_index(i) || <Self as ClosedSet>::is_last_index(i)
}
/// The declaration-order index-shaped interior-membership predicate —
/// `true` iff `i` names the array slot of a strictly-interior
/// variant (neither the declaration-order head slot `0` nor the
/// declaration-order tail slot `T::CARDINALITY - 1`), `false` on
/// both endpoint slots AND on every out-of-range `usize`. Closes
/// the (`usize`, declaration, interior) corner of the (arg-type ×
/// ordering × predicate-flavor) 3×2×2 = 12-corner boolean-boundary
/// hypercube alongside [`Self::is_endpoint_index`] (usize,
/// declaration, endpoint) and the pre-existing eight `Self`-and-
/// `&str` corners.
///
/// Sibling posture to [`Self::is_interior_label`] one arg-type axis
/// over on the (`Self`, `&str`, `usize`) partition of the
/// declaration-axis boolean-boundary surface: [`Self::is_interior_label`]
/// answers "is this &str the label of a strictly-interior variant?"
/// gated by [`Self::contains_label`]; this method answers "is this
/// usize the array slot of a strictly-interior variant?" gated by
/// the canonical-domain range check `i < T::CARDINALITY`.
///
/// Default body composes the canonical-domain gate
/// `i < T::CARDINALITY` with [`!Self::is_endpoint_index`] under
/// `&&` — a canonical slot answers `true` iff it is in the
/// canonical index domain `0..T::CARDINALITY` AND is NOT an
/// endpoint slot; every out-of-range input answers `false` because
/// the domain gate rejects it. This shape diverges from the
/// `Self`-arg default `!is_endpoint(self)` (which would answer
/// `true` for a non-canonical input on the label side) — the
/// `usize` arg-type axis requires a domain-membership gate because
/// the input domain is unbounded, unlike the closed `Self` domain.
/// The domain gate `i < T::CARDINALITY` is the natural `usize`-
/// arg parallel of [`Self::contains_label`]'s canonical-label
/// membership sweep on the `&str`-arg column: both gate the input
/// to the closed set's finite canonical sub-domain (the
/// `0..CARDINALITY` slot range on the `usize` axis, the canonical
/// label sub-set on the `&str` axis) before the boundary-partition
/// arm fires.
///
/// Composition rejects `T::CARDINALITY` (falls out of the domain
/// gate — the CARDINALITY-th slot is one past the canonical
/// range) AND rejects `usize::MAX` (also out of range). The
/// (declaration-endpoint, declaration-interior) partition
/// contract on the CANONICAL sub-domain
/// `0..T::CARDINALITY` — `is_endpoint_index(i) !=
/// is_interior_index(i)` for every `i ∈ 0..T::CARDINALITY` — is
/// guaranteed by the default composition; the well-formedness
/// clause (79) pins the complementarity assertion on every
/// canonical slot AND the shared out-of-range rejection
/// (`T::is_interior_index(T::CARDINALITY) == false`).
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `false` for the sole variant's slot `0` (the sole slot
/// is BOTH endpoints so [`Self::is_endpoint_index`] fires; the
/// interior arm correspondingly rejects). A singleton closed set
/// has ZERO strictly-interior slots by construction — mirrors the
/// singleton collapse [`Self::is_interior`] and
/// [`Self::is_interior_label`] observe on the two sibling arg-type
/// axes.
///
/// Implementors override only when the index-shaped declaration-
/// interior-membership surface needs to diverge from the natural
/// `i < T::CARDINALITY && !is_endpoint_index(i)` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `is_endpoint_index` /
/// `is_interior_label` overrides exist — a typed escape hatch). An
/// implementor that overrides [`Self::is_endpoint_index`]
/// propagates the override through this default body automatically.
///
/// THEORY.md §III — the typescape; the (usize → declaration-
/// interior-membership bool) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `i < T::CARDINALITY && !(i == 0 || i + 1 == T::CARDINALITY)`
/// composition.
/// THEORY.md §V.1 — knowable platform; naming the projection on
/// the trait turns "the index is a strictly-declaration-interior
/// slot" from an unnamed compound into a workspace-wide theorem.
///
/// Frontier inspiration: Racket's `enum-interior-index?` on closed
/// enumerations under declaration-order index projection;
/// Haskell's `\i -> i > 0 && i < length labels - 1` on the
/// `Bounded + Enum` type-class pair; MLIR's
/// `RegisteredOperationName::isDeclInteriorIndex(idx)` on the
/// declaration-order Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// [`Self::CARDINALITY`] and [`Self::is_endpoint_index`] surfaces
/// under the standard-library `<` comparison and boolean `&&` /
/// `!` operators — no new dep, no new IR layer, no supertrait
/// bound, no allocation, no [`Option`]-typed dispatch.
fn is_interior_index(i: usize) -> bool {
i < <Self as ClosedSet>::CARDINALITY && !<Self as ClosedSet>::is_endpoint_index(i)
}
/// The lexicographic-order index-shaped endpoint-membership
/// predicate — `true` iff the `usize` argument equals `0` (the
/// lex-order head-endpoint's slot in [`Self::sorted_variants`],
/// where the argument is interpreted as a LEX position — the
/// natural output shape of [`Self::sorted_index_of`],
/// [`Self::sorted_next_index`], [`Self::sorted_prev_index`],
/// [`Self::cycle_sorted_next_index`], and
/// [`Self::cycle_sorted_prev_index`]) OR `T::CARDINALITY - 1` (the
/// lex-order tail-endpoint's slot), `false` on every strictly-lex-
/// interior lex slot AND on every out-of-range `usize`. Closes the
/// (`usize`, lex, endpoint) corner of the (arg-type × ordering ×
/// predicate-flavor) 3×2×2 = 12-corner boolean-boundary hypercube
/// alongside [`Self::is_endpoint_index`] (usize, declaration,
/// endpoint).
///
/// Sibling posture to [`Self::is_endpoint_index`] one ordering
/// axis over on the (declaration, lex) partition —
/// [`Self::is_endpoint_index`] interprets `i` as a DECLARATION slot
/// in [`Self::ALL`] and answers "is this the declaration-endpoint
/// slot?"; this method interprets `i` as a LEX position in
/// [`Self::sorted_variants`] and answers "is this the lex-endpoint
/// slot?". The `usize` bodies coincide (both endpoints land at
/// slots `0` / `T::CARDINALITY - 1` under their respective
/// orderings) but the SEMANTIC and load-bearing consumer paths
/// differ — a caller who computed a lex-position via
/// [`Self::sorted_index_of`] and wants to test lex-boundary
/// membership binds to THIS method (not [`Self::is_endpoint_index`])
/// to make the lex axis explicit at the call site and to inherit
/// the (80) well-formedness pin against
/// `T::is_sorted_endpoint_index(T::sorted_index_of(v)) ==
/// v.is_sorted_endpoint()` rather than the (78) pin against
/// `T::is_endpoint_index(T::index_of(v)) == v.is_endpoint()`.
///
/// Default body composes [`Self::is_sorted_first_index`] with
/// [`Self::is_sorted_last_index`] under `||` — the lex index-
/// shaped boundary-membership predicate is a typed CONSEQUENCE of
/// the two pre-existing index-shaped lex point-membership
/// primitives. Implementors override only when the lex index-
/// shaped boundary-membership surface needs to diverge from the
/// natural `is_sorted_first_index(i) || is_sorted_last_index(i)`
/// shape. An implementor that overrides either
/// [`Self::is_sorted_first_index`] OR
/// [`Self::is_sorted_last_index`] propagates the override through
/// this default body automatically.
///
/// The (lex-endpoint, lex-interior) partition contract on the
/// CANONICAL sub-domain `0..T::CARDINALITY` —
/// `is_sorted_endpoint_index(i) != is_sorted_interior_index(i)`
/// for every `i ∈ 0..T::CARDINALITY` — is guaranteed by the
/// default composition; the well-formedness clause (80) pins the
/// complementarity assertion on every canonical slot AND the
/// shared out-of-range rejection
/// (`T::is_sorted_endpoint_index(T::CARDINALITY) == false`).
/// Outside the canonical sub-domain BOTH predicates return `false`.
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `true` for the sole variant's slot `0` (both lex-
/// endpoint point-membership predicates fire on the same slot);
/// [`Self::is_sorted_interior_index`] correspondingly returns
/// `false`.
///
/// THEORY.md §III — the typescape; the (usize → lex-boundary-
/// membership bool) projection on a LEX-position input becomes a
/// TYPE projection on the trait rather than a per-consumer inline
/// `i == 0 || i + 1 == T::CARDINALITY` composition on a lex-
/// position input.
/// THEORY.md §V.1 — knowable platform; naming the projection on
/// the trait turns "the lex slot is a lex-endpoint slot" from an
/// unnamed compound into a workspace-wide theorem.
///
/// Frontier inspiration: Racket's `enum-sorted-boundary-index?` on
/// closed enumerations under lex-ordered index projection; Idris's
/// `\i -> i == FZ || i == last n` on the lex-permuted finite type;
/// Haskell's `\i -> i == 0 || i == length sortedLabels - 1` on the
/// `Bounded + Show` type-class pair with a `sortBy` prelude;
/// MLIR's `RegisteredOperationName::isLexEndpointIndex(idx)` on
/// the lex-sorted Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::is_sorted_first_index`] and
/// [`Self::is_sorted_last_index`] surfaces under the standard-
/// library boolean `||` operator — no new dep, no new IR layer,
/// no supertrait bound, no allocation, no [`Option`]-typed
/// dispatch.
fn is_sorted_endpoint_index(i: usize) -> bool {
<Self as ClosedSet>::is_sorted_first_index(i)
|| <Self as ClosedSet>::is_sorted_last_index(i)
}
/// The lexicographic-order index-shaped interior-membership
/// predicate — `true` iff `i` names the lex slot of a strictly-
/// lex-interior variant, `false` on both lex-endpoint slots AND on
/// every out-of-range `usize`. Closes the (`usize`, lex, interior)
/// corner AND the FINAL corner of the (arg-type × ordering ×
/// predicate-flavor) 3×2×2 = 12-corner boolean-boundary hypercube
/// alongside [`Self::is_sorted_endpoint_index`] (usize, lex,
/// endpoint), [`Self::is_endpoint_index`] (usize, declaration,
/// endpoint), [`Self::is_interior_index`] (usize, declaration,
/// interior), and the pre-existing eight `Self`-and-`&str` corners.
///
/// Sibling posture to [`Self::is_sorted_interior_label`] one arg-
/// type axis over on the (`Self`, `&str`, `usize`) partition of
/// the lex-axis boolean-boundary surface:
/// [`Self::is_sorted_interior_label`] answers "is this &str the
/// label of a strictly-lex-interior variant?" gated by
/// [`Self::contains_label`]; this method answers "is this usize
/// the lex slot of a strictly-lex-interior variant?" gated by the
/// canonical-domain range check `i < T::CARDINALITY`.
///
/// Default body composes the canonical-domain gate
/// `i < T::CARDINALITY` with [`!Self::is_sorted_endpoint_index`]
/// under `&&` — mirrors the declaration-axis
/// [`Self::is_interior_index`] one ordering axis over. The `usize`
/// arg-type axis requires the same domain-membership gate as
/// [`Self::is_interior_index`] because the input domain is
/// unbounded; the composition rejects the out-of-range boundary
/// `T::CARDINALITY` AND `usize::MAX`.
///
/// Implementors override only when the lex index-shaped interior-
/// membership surface needs to diverge from the natural
/// `i < T::CARDINALITY && !is_sorted_endpoint_index(i)` shape. An
/// implementor that overrides [`Self::is_sorted_endpoint_index`]
/// propagates the override through this default body automatically.
///
/// The (lex-endpoint, lex-interior) partition contract on the
/// CANONICAL sub-domain `0..T::CARDINALITY` —
/// `is_sorted_endpoint_index(i) != is_sorted_interior_index(i)`
/// for every `i ∈ 0..T::CARDINALITY` — is guaranteed by the
/// default composition; the well-formedness clause (81) pins the
/// complementarity assertion on every canonical slot AND the
/// shared out-of-range rejection
/// (`T::is_sorted_interior_index(T::CARDINALITY) == false`).
/// Outside the canonical sub-domain BOTH predicates return `false`.
///
/// Singleton degeneracy — for `T::CARDINALITY == 1` this predicate
/// returns `false` for the sole variant's slot `0` (the sole slot
/// is BOTH lex endpoints so [`Self::is_sorted_endpoint_index`]
/// fires; the interior arm correspondingly rejects).
///
/// Clauses (32) + (33) + (54) + (55) + (56) + (57) + (78) + (79) +
/// (80) + (81) together CLOSE the (arg-type × ordering ×
/// predicate-flavor) 3×2×2 = 12-corner boolean-boundary hypercube
/// EXHAUSTIVELY — every generic consumer that walks any of the
/// twelve (Self-or-&str-or-usize, declaration-or-lex, endpoint-or-
/// interior) corners of the boundary-partition space binds to ONE
/// typed predicate rather than hand-rolling a composition.
///
/// THEORY.md §III — the typescape; the (usize → lex-interior-
/// membership bool) projection becomes a TYPE projection on the
/// trait. The 12-corner boolean-boundary hypercube CLOSES with
/// this method — every corner of the (arg-type × ordering ×
/// predicate-flavor) space is a typed default trait body composed
/// from substrate primitives.
/// THEORY.md §V.1 — knowable platform; naming the projection on
/// the trait turns "the lex slot is a strictly-lex-interior slot"
/// from an unnamed compound into a workspace-wide theorem.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives under
/// the standard-library `<` comparison and boolean `&&` / `!`
/// operators.
///
/// Frontier inspiration: Racket's `enum-sorted-interior-index?` on
/// closed enumerations under lex-ordered index projection;
/// Haskell's `\i -> i > 0 && i < length sortedLabels - 1` on the
/// `Bounded + Show` type-class pair with a `sortBy` prelude;
/// MLIR's `RegisteredOperationName::isLexInteriorIndex(idx)` on
/// the lex-sorted Op registry. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// [`Self::CARDINALITY`] and [`Self::is_sorted_endpoint_index`]
/// surfaces under the standard-library `<` comparison and boolean
/// `&&` / `!` operators — no new dep, no new IR layer, no
/// supertrait bound, no allocation, no [`Option`]-typed dispatch.
fn is_sorted_interior_index(i: usize) -> bool {
i < <Self as ClosedSet>::CARDINALITY && !<Self as ClosedSet>::is_sorted_endpoint_index(i)
}
/// The declaration-order endpoint anchor pair — the tuple
/// `(T::first(), T::last())` projected onto the trait surface as
/// ONE call. Closes the pair-aggregation corner of the closed-set
/// endpoint-anchor return-shape axis on the DECLARATION side —
/// the missing middle column between the two scalar endpoint
/// primitives ([`Self::first`], [`Self::last`]) and the collection
/// aggregation ([`Self::variants`]).
///
/// The (return-shape × declaration-anchor) 3-of-3 return-shape
/// column over the declaration-order anchor surface partitions
/// post-lift:
///
/// | Return shape | Anchor surface |
/// |-----------------------------|--------------------------|
/// | `Self` scalar (head) | [`Self::first`] |
/// | `Self` scalar (tail) | [`Self::last`] |
/// | `(Self, Self)` pair | [`Self::endpoints`] |
/// | `Vec<Self>` collection | [`Self::variants`] |
///
/// Sibling posture to [`Self::first`] + [`Self::last`] one return-
/// shape axis over on the (scalar, pair) partition of the closed-
/// set declaration-order anchor surface — [`Self::first`] and
/// [`Self::last`] project the two anchors as separate scalar
/// values, this method aggregates the two anchors into ONE tuple
/// call. Every generic consumer that wants BOTH declaration-order
/// endpoints (a bracketing renderer that emits `<head> ↔ <tail>`
/// in a diagnostic, a saga-step engine that transitions through
/// the head-anchor and tail-anchor states, a truth-table property
/// test that anchors edge assertions at BOTH endpoints, a wire-
/// format decoder that emits a per-run boundary payload naming
/// both anchors, a `tatara-check` per-implementor coherence probe
/// that renders both anchors in ONE diagnostic) binds to ONE
/// typed call rather than hand-rolling the
/// `(T::first(), T::last())` two-primitive re-derivation at every
/// callsite (which pays TWO trait dispatches AND makes every
/// downstream site depend on the tuple-construction shape).
///
/// Default body composes [`Self::first`] with [`Self::last`]
/// under the standard-library tuple constructor — the (head, tail)
/// pair aggregation is a typed CONSEQUENCE of the two pre-existing
/// endpoint-anchor primitives, not a third codepath through
/// [`Self::ALL`] with slice-index-0 / slice-index-(N - 1) projection.
/// Implementors override only when the pair
/// aggregation needs to diverge from the natural
/// `(first(), last())` shape (no production implementor reaches for
/// this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `first` / `last` overrides
/// exist — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl). An
/// implementor that overrides [`Self::first`] or [`Self::last`]
/// propagates the override through this default body to the pair
/// aggregation automatically; the (declaration-order head,
/// declaration-order tail) pair-aggregation surface funnels
/// through the two scalar endpoint-anchor primitives on each of
/// its tuple slots.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] and [`Self::last`] both
/// return the sole variant, so this method returns
/// `(Self::Only, Self::Only)` — the pair collapses to a diagonal
/// tuple over the sole variant. A singleton closed set has ONE
/// endpoint slot that IS both anchors simultaneously; the pair
/// aggregation preserves the tuple SHAPE even at the boundary-
/// cardinality edge where the two SLOTS collapse onto the same
/// value. Mirrors the singleton collapse [`Self::is_endpoint`]
/// observes on the (endpoint, interior) partition — both anchor
/// slots pin the same variant and every generic consumer that
/// destructures `let (head, tail) = T::endpoints();` reads the
/// SAME typed variant into `head` and `tail`.
///
/// The endpoint-anchor pair contract —
/// `T::endpoints() == (T::first(), T::last())` on every
/// implementor — is guaranteed by the default composition through
/// the two scalar endpoint-anchor primitives; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (34)
/// pins the composition against the natural
/// `(first(), last())` shape on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// [`Self::endpoints`] on any typed variant and expect the same
/// tuple answer at every crate boundary.
///
/// Future consumers — a boundary badge renderer that emits
/// `<head> ↔ <tail>` in ONE call instead of a two-primitive
/// composition at each rendering site, a range walker that
/// destructures `let (head, tail) = T::endpoints();` and iterates
/// through the declaration-order chain from `head.index_of()` to
/// `tail.index_of()`, a saga-step audit event that logs both
/// anchors atomically without threading the two primitives
/// through the event constructor, a `tatara-check` per-
/// implementor coherence probe that renders both anchors as a
/// pair diagnostic, a truth-table property test that anchors edge
/// assertions at BOTH endpoints through ONE destructure — bind to
/// ONE trait method instead of hand-rolling the
/// `(T::first(), T::last())` two-primitive composition at each
/// callsite, and the closed-set declaration-order endpoint pair-
/// aggregation surface evolves at ONE site rather than per-
/// consumer.
///
/// THEORY.md §III — the typescape; the (declaration-order head,
/// declaration-order tail) pair-aggregation becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `(T::first(), T::last())` composition at every downstream
/// pair-endpoint site. The closed-set endpoint-anchor return-shape
/// axis gains its pair-aggregation corner — the (`Self` scalar,
/// `(Self, Self)` pair, `Vec<Self>` collection) return-shape
/// column on the declaration-order endpoint-anchor row is now
/// fully closed.
/// THEORY.md §V.1 — knowable platform; the (declaration-order
/// endpoint pair) aggregation was an unnamed compound of
/// [`Self::first`] + [`Self::last`] pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of the two
/// substrate primitives — generic consumers see ONE method, not
/// ONE endpoint-pair-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// (declaration-order endpoint pair) aggregation emerges from the
/// composition of TWO substrate primitives ([`Self::first`],
/// [`Self::last`]) under the standard-library tuple constructor
/// rather than as a per-implementor
/// `const ENDPOINTS: (Self, Self) = (Self::Head, Self::Tail)`
/// declaration. A future tightening of either primitive (a future
/// const-fn endpoint-anchor axis that makes the pair callable in
/// const contexts, a future perfect-hash anchor projection)
/// propagates to every closed-set endpoint-pair consumer through
/// this method's body.
///
/// Frontier inspiration: Racket's `enum-endpoints` on closed
/// enumerations (the pair-aggregation of the declaration-order
/// head + tail anchors on the enumeration chain); Idris's
/// `Fin (S n)` non-empty finite-cardinality types where
/// `endpoints : Fin (S n) -> (Fin (S n), Fin (S n))` folds the
/// (head, tail) endpoint pair through a shared tuple projection;
/// Haskell's `(minBound, maxBound)` on the `Bounded` type-class
/// pair — the endpoint-anchor pair exposed as a bare typed tuple
/// rather than two separate scalar calls; MLIR's
/// `RegisteredOperationName::begin_end()` on the declaration-
/// order Op registry (the pair projection over the registered-op
/// enumeration). Translation through pleme-io primitives: a pure
/// default method composing the trait's existing [`Self::first`]
/// and [`Self::last`] scalar endpoint-anchor primitives under the
/// standard-library tuple constructor — no new dep, no new IR
/// layer, no supertrait bound, no [`Option`]-typed dispatch.
fn endpoints() -> (Self, Self) {
(<Self as ClosedSet>::first(), <Self as ClosedSet>::last())
}
/// The lexicographic-order endpoint anchor pair — the tuple
/// `(T::sorted_first(), T::sorted_last())` projected onto the
/// trait surface as ONE call. Closes the pair-aggregation corner
/// of the closed-set endpoint-anchor return-shape axis on the LEX
/// side.
///
/// Sibling posture to [`Self::endpoints`] one ordering axis over
/// on the (declaration, lex) partition of the closed-set
/// endpoint-anchor pair-aggregation surface — [`Self::endpoints`]
/// fires on the declaration-order (head, tail) pair, this method
/// fires on the lex-order (head, tail) pair. See
/// [`Self::endpoints`] for the shared design rationale, sibling
/// matrix, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// ordering-axis arm of the same return-shape axis and inherits
/// every property from the declaration-axis arm's documentation,
/// differing only in the composition through
/// [`Self::sorted_first`] / [`Self::sorted_last`] instead of
/// [`Self::first`] / [`Self::last`] and the alphabetized consumer
/// surface (an alphabetized boundary badge that emits
/// `<lex-head> ↔ <lex-tail>` in a diagnostic, a lex-ordered saga-
/// step engine that transitions through the lex-head-anchor and
/// lex-tail-anchor states, an alphabetized truth-table property
/// test that anchors edge assertions at BOTH lex endpoints
/// through ONE destructure, an alphabetized-completion UI that
/// renders the alphabetized boundary pair atomically).
///
/// Default body composes [`Self::sorted_first`] with
/// [`Self::sorted_last`] under the standard-library tuple
/// constructor — the (lex-head, lex-tail) pair aggregation is a
/// typed CONSEQUENCE of the two pre-existing lex-endpoint-anchor
/// primitives, not a third codepath through
/// [`Self::sorted_variants`] + `<[T]>::first` + `<[T]>::last` +
/// `Option::copied` + `Option::unwrap`. Implementors override
/// only when the lex-pair aggregation needs to diverge from the
/// natural `(sorted_first(), sorted_last())` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `sorted_labels` /
/// `sorted_first` / `sorted_last` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::sorted_first`] or [`Self::sorted_last`]
/// propagates the override through this default body to the lex-
/// pair aggregation automatically; the (lex-head, lex-tail) pair-
/// aggregation surface funnels through the two scalar lex-
/// endpoint-anchor primitives on each of its tuple slots.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] and
/// [`Self::sorted_last`] both return the sole variant, so this
/// method returns `(Self::Only, Self::Only)` — the lex-pair
/// collapses to a diagonal tuple over the sole variant. Mirrors
/// [`Self::endpoints`]'s singleton collapse one ordering axis
/// over and preserves the (lex-head, lex-tail) tuple SHAPE even
/// at the boundary-cardinality edge where the two SLOTS collapse
/// onto the same value.
///
/// The lex-endpoint-anchor pair contract —
/// `T::sorted_endpoints() == (T::sorted_first(), T::sorted_last())`
/// on every implementor — is guaranteed by the default
/// composition through the two scalar lex-endpoint-anchor
/// primitives; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (35) pins the
/// composition against the natural
/// `(sorted_first(), sorted_last())` shape on every implementor
/// so a passing well-formedness sweep means every generic
/// consumer can call [`Self::sorted_endpoints`] on any typed
/// variant and expect the same tuple answer at every crate
/// boundary.
///
/// The (ordering × pair-aggregation) 2×1 matrix over the closed-
/// set endpoint-anchor return-shape axis is now closed at BOTH
/// ordering corners — [`Self::endpoints`] on the declaration
/// axis, this method on the lex axis. Together the two methods
/// cover every ordering corner of the pair-return-shape column
/// of the closed-set endpoint-anchor matrix. A future range-
/// walker / boundary-badge / audit-event / per-implementor
/// coherence probe consumer that binds either method sees the
/// SAME `(Self, Self)` tuple shape at every crate boundary
/// regardless of whether it walks the declaration or lex axis.
fn sorted_endpoints() -> (Self, Self) {
(
<Self as ClosedSet>::sorted_first(),
<Self as ClosedSet>::sorted_last(),
)
}
/// The declaration-order endpoint-label pair — the tuple
/// `(T::first().label(), T::last().label())` projected onto the
/// trait surface as ONE call. Closes the `(&'static str, &'static str)`
/// pair-aggregation corner of the closed-set endpoint return-shape
/// axis on the declaration side.
///
/// The (return-shape × ordering) 2×2 pair-aggregation matrix over
/// the closed-set endpoint surface partitions post-lift:
///
/// | Return shape \\ Ordering | Declaration | Lex |
/// |--------------------------------|---------------------------------|----------------------------------------|
/// | `(Self, Self)` pair | [`Self::endpoints`] | [`Self::sorted_endpoints`] |
/// | `(&'static str, &'static str)` | [`Self::endpoint_labels`] | [`Self::sorted_endpoint_labels`] |
///
/// Sibling posture to [`Self::endpoints`] one return-shape axis
/// over on the (`(Self, Self)` typed-variant pair,
/// `(&'static str, &'static str)` label pair) partition of the
/// closed-set declaration-axis pair-aggregation surface —
/// [`Self::endpoints`] projects the typed-variant pair,
/// this method projects the same pair through to its canonical
/// [`Self::label`] renderings — one composition step further along
/// the same axis. Every generic consumer that wants BOTH
/// declaration-order endpoint LABELS (a boundary badge renderer
/// that emits `<head-label> ↔ <tail-label>` in a diagnostic
/// without materializing the typed variants, an alphabetized-
/// completion UI that pins the declaration-order boundary pair by
/// label, a wire-format decoder that emits a per-run boundary
/// payload naming both anchor labels, a `tatara-check` per-
/// implementor coherence probe that renders both anchor labels as
/// a pair diagnostic without a second `label()` call at each
/// tuple slot) binds to ONE typed call rather than hand-rolling
/// either the `let (h, t) = T::endpoints(); (h.label(), t.label())`
/// destructure (which re-derives the same two-primitive
/// composition at every callsite) OR the
/// `(T::first().label(), T::last().label())` four-primitive
/// composition at each callsite.
///
/// Default body destructures [`Self::endpoints`] and labels each
/// tuple slot under [`Self::label`] — the (head-label, tail-label)
/// pair aggregation is a typed CONSEQUENCE of the composition of
/// the pair-aggregation primitive with the per-slot label
/// projection, not a fifth codepath through [`Self::ALL`] with
/// slice-index-0 / slice-index-(N - 1) + per-slot label. An
/// implementor that overrides [`Self::endpoints`] (or the
/// [`Self::first`] / [`Self::last`] scalars [`Self::endpoints`]
/// funnels through) OR overrides [`Self::label`] propagates the
/// override through this default body to the label-pair
/// aggregation automatically; the (declaration-order head-label,
/// declaration-order tail-label) pair-aggregation surface funnels
/// through the pair-aggregation primitive on the tuple-shape
/// column AND the per-slot label projection on the rendering
/// column. Implementors override only when the label-pair
/// aggregation needs to diverge from the natural
/// `(first().label(), last().label())` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `endpoints`
/// overrides exist — a typed escape hatch the trait surface
/// exposes rather than forcing the implementor to hand-roll the
/// impl).
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] and [`Self::last`] both
/// return the sole variant and its label, so this method returns
/// `(Self::Only.label(), Self::Only.label())` — the label-pair
/// collapses to a diagonal tuple over the sole variant's label.
/// Mirrors [`Self::endpoints`]'s singleton collapse one return-
/// shape axis over and preserves the tuple SHAPE even at the
/// boundary-cardinality edge where the two SLOTS collapse onto
/// the same label.
///
/// The endpoint-label pair contract —
/// `T::endpoint_labels() == (T::first().label(), T::last().label())`
/// on every implementor — is guaranteed by the default composition
/// through the pair-aggregation primitive and the per-slot label
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (36) pins the
/// composition against the natural
/// `(first().label(), last().label())` shape on every implementor
/// so a passing well-formedness sweep means every generic
/// consumer can call [`Self::endpoint_labels`] on any typed
/// carrier and expect the same tuple answer at every crate
/// boundary.
///
/// THEORY.md §III — the typescape; the (declaration-order head-
/// label, declaration-order tail-label) pair-aggregation becomes
/// a TYPE projection on the trait rather than a per-consumer
/// inline `(T::first().label(), T::last().label())` composition
/// at every downstream label-pair-endpoint site. The closed-set
/// pair-aggregation return-shape matrix gains its
/// `&'static str` declaration-axis corner — the (`(Self, Self)`
/// typed-variant pair, `(&'static str, &'static str)` label pair)
/// return-shape axis on the declaration-order endpoint row is
/// now closed at BOTH corners.
/// THEORY.md §V.1 — knowable platform; the (declaration-order
/// head-label, declaration-order tail-label) pair aggregation
/// was an unnamed compound of [`Self::endpoints`] destructured
/// under [`Self::label`] pre-lift; naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the two substrate
/// primitives — generic consumers see ONE method, not one label-
/// pair-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// (declaration-order label-pair) aggregation emerges from the
/// composition of [`Self::endpoints`] with per-slot [`Self::label`]
/// projection rather than as a per-implementor
/// `const ENDPOINT_LABELS: (&str, &str) = ("head", "tail")`
/// declaration. A future tightening of either primitive (a
/// future const-fn endpoint-anchor axis, a future
/// canonicalization-aware [`Self::label`] projection that folds
/// case / whitespace) propagates to every closed-set label-pair
/// consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-endpoint-labels` on
/// closed enumerations (the label-pair-aggregation of the
/// declaration-order head + tail anchor renderings on the
/// enumeration chain); Idris's `Fin (S n)` non-empty finite-
/// cardinality types where `showEndpoints : Fin (S n) -> (String, String)`
/// folds the (head-label, tail-label) pair through a shared
/// tuple projection; Haskell's `(show minBound, show maxBound)`
/// on the `Bounded + Show` type-class pair — the endpoint-label
/// pair exposed as a bare typed tuple rather than four separate
/// scalar calls; MLIR's
/// `RegisteredOperationName::begin_end_names()` on the
/// declaration-order Op registry (the label-pair projection over
/// the registered-op enumeration). Translation through pleme-io
/// primitives: a pure default method destructuring the trait's
/// existing [`Self::endpoints`] pair-aggregation surface under
/// per-slot [`Self::label`] projection — no new dep, no new IR
/// layer, no supertrait bound, no allocation.
fn endpoint_labels() -> (&'static str, &'static str) {
let (head, tail) = <Self as ClosedSet>::endpoints();
(
<Self as ClosedSet>::label(head),
<Self as ClosedSet>::label(tail),
)
}
/// The lexicographic-order endpoint-label pair — the tuple
/// `(T::sorted_first().label(), T::sorted_last().label())`
/// projected onto the trait surface as ONE call. Closes the
/// `(&'static str, &'static str)` pair-aggregation corner of the
/// closed-set endpoint return-shape axis on the LEX side.
///
/// Sibling posture to [`Self::endpoint_labels`] one ordering axis
/// over on the (declaration, lex) partition of the closed-set
/// endpoint-label pair-aggregation surface —
/// [`Self::endpoint_labels`] fires on the declaration-order
/// (head-label, tail-label) pair, this method fires on the lex-
/// order (head-label, tail-label) pair. See
/// [`Self::endpoint_labels`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the lex-ordering-axis arm of the same return-shape axis
/// and inherits every property from the declaration-axis arm's
/// documentation, differing only in the composition through
/// [`Self::sorted_endpoints`] instead of [`Self::endpoints`] and
/// the alphabetized consumer surface (an alphabetized boundary
/// badge that emits `<lex-head-label> ↔ <lex-tail-label>` in a
/// diagnostic without a typed-variant materialization at each
/// slot, a lex-ordered saga-step audit event that emits both lex
/// anchor labels atomically, an alphabetized truth-table property
/// test that anchors edge assertions at BOTH lex endpoint labels
/// through ONE destructure, an alphabetized-completion UI that
/// renders the lex boundary pair by label).
///
/// Default body destructures [`Self::sorted_endpoints`] and labels
/// each tuple slot under [`Self::label`] — the (lex-head-label,
/// lex-tail-label) pair aggregation is a typed CONSEQUENCE of the
/// composition of the lex-pair-aggregation primitive with the
/// per-slot label projection, not a fifth codepath through
/// [`Self::sorted_variants`] + `<[T]>::first` + `<[T]>::last` +
/// per-slot label. Implementors override only when the lex-label-
/// pair aggregation needs to diverge from the natural
/// `(sorted_first().label(), sorted_last().label())` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_endpoints` overrides exist — a typed escape hatch the
/// trait surface exposes rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::sorted_endpoints`] (or the [`Self::sorted_first`] /
/// [`Self::sorted_last`] scalars [`Self::sorted_endpoints`]
/// funnels through) OR overrides [`Self::label`] propagates the
/// override through this default body to the lex-label-pair
/// aggregation automatically; the (lex-head-label, lex-tail-label)
/// pair-aggregation surface funnels through the lex-pair-
/// aggregation primitive on the tuple-shape column AND the per-
/// slot label projection on the rendering column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] and
/// [`Self::sorted_last`] both return the sole variant and its
/// label, so this method returns
/// `(Self::Only.label(), Self::Only.label())` — the lex-label-
/// pair collapses to a diagonal tuple over the sole variant's
/// label. Mirrors [`Self::endpoint_labels`]'s singleton collapse
/// one ordering axis over and preserves the (lex-head-label,
/// lex-tail-label) tuple SHAPE even at the boundary-cardinality
/// edge where the two SLOTS collapse onto the same label.
///
/// The lex-endpoint-label pair contract —
/// `T::sorted_endpoint_labels() == (T::sorted_first().label(), T::sorted_last().label())`
/// on every implementor — is guaranteed by the default
/// composition through the lex-pair-aggregation primitive and the
/// per-slot label projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (37) pins the
/// composition against the natural
/// `(sorted_first().label(), sorted_last().label())` shape on
/// every implementor so a passing well-formedness sweep means
/// every generic consumer can call [`Self::sorted_endpoint_labels`]
/// on any typed carrier and expect the same tuple answer at every
/// crate boundary.
///
/// The (ordering × pair-return-shape) 2×2 matrix over the closed-
/// set endpoint pair-aggregation surface is now closed at ALL
/// FOUR corners — [`Self::endpoints`] +
/// [`Self::sorted_endpoints`] on the `(Self, Self)` typed-variant
/// pair column, [`Self::endpoint_labels`] + this method on the
/// `(&'static str, &'static str)` label-pair column. Together the
/// four methods cover every (ordering, pair-return-shape) corner
/// of the closed-set endpoint pair-aggregation matrix. A future
/// range-walker / boundary-badge / audit-event / per-implementor
/// coherence probe consumer that binds any of the four sees the
/// SAME tuple shape at every crate boundary regardless of
/// whether it walks the declaration or lex axis and regardless
/// of whether it materializes the typed variant or the label.
fn sorted_endpoint_labels() -> (&'static str, &'static str) {
let (head, tail) = <Self as ClosedSet>::sorted_endpoints();
(
<Self as ClosedSet>::label(head),
<Self as ClosedSet>::label(tail),
)
}
/// The declaration-order endpoint DECL-INDEX pair — the tuple
/// `(T::first().index_of(), T::last().index_of())` projected onto
/// the trait surface as ONE call. Opens the `(usize, usize)` pair-
/// aggregation row on the closed-set endpoint-anchor pair
/// return-shape matrix at the (declaration) ordering corner,
/// mirroring [`Self::endpoint_labels`] one return-type axis over on
/// the (`(&'static str, &'static str)`, `(usize, usize)`) return-
/// shape column of the pair-endpoint aggregation matrix AND
/// mirroring [`Self::first_index`] + [`Self::last_index`] one
/// aggregation-shape axis over on the (singular scalar, pair-tuple)
/// partition of the closed-set declaration-axis endpoint-decl-slot
/// return-shape column.
///
/// The (return-type × ordering × aggregation-shape) 3×2×2 = 12-corner
/// endpoint-anchor return-shape hypercube partitions post-lift:
///
/// | Return type \\ (Ordering, Aggregation) | (Decl, Singular) | (Decl, Pair) | (Lex, Singular) | (Lex, Pair) |
/// |----------------------------------------|-----------------------------------------------|------------------------------------|--------------------------------------------------------------|---------------------------------------------|
/// | `Self` (typed variant) | [`Self::first`] / [`Self::last`] | [`Self::endpoints`] | [`Self::sorted_first`] / [`Self::sorted_last`] | [`Self::sorted_endpoints`] |
/// | `&'static str` (label) | [`Self::first_label`] / [`Self::last_label`] | [`Self::endpoint_labels`] | [`Self::sorted_first_label`] / [`Self::sorted_last_label`] | [`Self::sorted_endpoint_labels`] |
/// | `usize` (decl-slot) | [`Self::first_index`] / [`Self::last_index`] | this method | [`Self::sorted_first_index`] / [`Self::sorted_last_index`] | [`Self::sorted_endpoint_indices`] |
///
/// Every generic consumer that wants BOTH declaration-order endpoint
/// DECL-SLOTS as ONE `(usize, usize)` tuple (a bounded-loop range
/// walker that destructures
/// `let (head_idx, tail_idx) = T::endpoint_indices();` and walks
/// the declaration-order chain from `head_idx` to `tail_idx` on a
/// parallel-vector `<[U]>::iter().skip(head_idx).take(tail_idx - head_idx + 1)`
/// projection WITHOUT materializing the two typed anchor variants,
/// a `Range<usize>`-based traversal that binds BOTH endpoint decl-
/// slots atomically, a range-based coherence probe that anchors
/// BOTH endpoint slot assertions through ONE destructure, an audit
/// event that emits BOTH decl-slot integer coordinates atomically
/// without a per-slot `index_of()` call, a parallel-vector
/// boundary-badge that renders
/// `<vec[head_idx]> ↔ <vec[tail_idx]>` in ONE lookup pair) binds
/// to ONE typed method rather than hand-rolling the
/// `(T::first().index_of(), T::last().index_of())` four-primitive
/// composition OR the
/// `let (h, t) = T::endpoints(); (h.index_of(), t.index_of())`
/// two-step destructure-then-project at every callsite.
///
/// Default body destructures [`Self::endpoints`] and projects each
/// tuple slot under [`Self::index_of`] — the (head-decl-slot,
/// tail-decl-slot) pair aggregation is a typed CONSEQUENCE of the
/// composition of the pair-aggregation primitive with the per-slot
/// decl-index projection, not a fifth codepath through
/// [`Self::ALL`] with slice-index-0 / slice-index-(N - 1) integer
/// literals. Implementors override only when the decl-slot-pair
/// aggregation needs to diverge from the natural
/// `(first().index_of(), last().index_of())` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `endpoints` /
/// `endpoint_labels` overrides exist — a typed escape hatch the
/// trait surface exposes rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::endpoints`] (or the [`Self::first`] / [`Self::last`]
/// scalars it funnels through) OR overrides [`Self::index_of`]
/// propagates the override through this default body to the
/// decl-slot-pair aggregation automatically; the (declaration-order
/// head-decl-slot, declaration-order tail-decl-slot) pair-
/// aggregation surface funnels through the pair-aggregation
/// primitive on the tuple-shape column AND the per-slot decl-index
/// projection on the rendering column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] and [`Self::last`] both
/// return the sole variant whose `index_of()` is `0`, so this
/// method returns the diagonal tuple `(0, 0)` — the decl-slot pair
/// collapses to a diagonal tuple over the sole variant's decl-slot.
/// Mirrors [`Self::endpoints`]'s singleton collapse one return-shape
/// axis over and preserves the tuple SHAPE even at the boundary-
/// cardinality edge where the two SLOTS collapse onto the same
/// decl-slot integer coordinate. Two-variant degeneracy —
/// [`Self::first`] and [`Self::last`] name distinct variants at
/// decl-slots `0` and `1`, so this method returns `(0, 1)`.
///
/// The endpoint-decl-slot pair contract —
/// `T::endpoint_indices() == (T::first().index_of(), T::last().index_of())`
/// AND `T::endpoint_indices() == (0, T::CARDINALITY - 1)` on every
/// implementor — is guaranteed by the default composition through
/// the pair-aggregation primitive and the per-slot decl-index
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (92) pins the
/// composition against the natural
/// `(first().index_of(), last().index_of())` shape AND against the
/// `(0, CARDINALITY - 1)` structural fixpoint on every implementor
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::endpoint_indices`] on any typed carrier and
/// expect the same tuple answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (declaration-order head-
/// decl-slot, declaration-order tail-decl-slot) pair-aggregation
/// becomes a TYPE projection on the trait rather than a per-consumer
/// inline `(T::first().index_of(), T::last().index_of())`
/// composition at every downstream decl-slot-pair-endpoint site.
/// The closed-set pair-aggregation return-shape matrix gains its
/// `(usize, usize)` declaration-axis corner — the (return-type ×
/// ordering) 3×2 pair-endpoint aggregation matrix on the pair-tuple
/// return-shape column is now closed at the (`usize`, declaration)
/// corner.
/// THEORY.md §V.1 — knowable platform; the (declaration-order
/// head-decl-slot, declaration-order tail-decl-slot) pair
/// aggregation was an unnamed compound of [`Self::endpoints`]
/// destructured under [`Self::index_of`] pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of the two
/// substrate primitives — generic consumers see ONE method, not
/// one decl-slot-pair-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (declaration-
/// order decl-slot-pair) aggregation emerges from the composition
/// of [`Self::endpoints`] with per-slot [`Self::index_of`]
/// projection rather than as a per-implementor
/// `const ENDPOINT_INDICES: (usize, usize) = (0, N - 1)`
/// declaration that silently drifts from [`Self::ALL`] on any
/// reordering.
///
/// Frontier inspiration: Racket's `enum-endpoint-indices` on closed
/// enumerations (the decl-slot pair aggregation of the declaration-
/// order head + tail anchors on the enumeration chain); Idris's
/// `Fin (S n)` non-empty finite-cardinality types where
/// `endpointIndices : Fin (S n) -> (Nat, Nat)` folds the (head-idx,
/// tail-idx) pair through a shared tuple projection; Haskell's
/// `(fromEnum minBound, fromEnum maxBound)` on the `Bounded + Enum`
/// type-class pair — the endpoint decl-slot pair exposed as a bare
/// typed tuple rather than four separate scalar calls; MLIR's
/// `RegisteredOperationName::begin_end_indices()` on the
/// declaration-order Op registry (the decl-slot pair projection
/// over the registered-op enumeration). Translation through
/// pleme-io primitives: a pure default method destructuring the
/// trait's existing [`Self::endpoints`] pair-aggregation surface
/// under per-slot [`Self::index_of`] projection — no new dep, no
/// new IR layer, no supertrait bound, no allocation.
fn endpoint_indices() -> (usize, usize) {
let (head, tail) = <Self as ClosedSet>::endpoints();
(
<Self as ClosedSet>::index_of(head),
<Self as ClosedSet>::index_of(tail),
)
}
/// The lexicographic-order endpoint DECL-INDEX pair — the tuple
/// `(T::sorted_first().index_of(), T::sorted_last().index_of())`
/// projected onto the trait surface as ONE call. Closes the
/// (return-type × ordering) 3×2 = 6-corner pair-endpoint
/// aggregation matrix at the (`usize`, lex) corner alongside the
/// other five corners: [`Self::endpoints`] +
/// [`Self::sorted_endpoints`] on the `(Self, Self)` row,
/// [`Self::endpoint_labels`] + [`Self::sorted_endpoint_labels`] on
/// the `(&'static str, &'static str)` row, and
/// [`Self::endpoint_indices`] (this method's declaration-axis
/// sibling) on the `(usize, usize)` row.
///
/// Sibling posture to [`Self::endpoint_indices`] one ordering axis
/// over on the (declaration, lex) partition of the closed-set
/// `(usize, usize)`-typed pair-endpoint aggregation row —
/// [`Self::endpoint_indices`] projects the declaration-order
/// endpoint decl-slot pair, this method projects the lex-order
/// endpoint decl-slot pair. See [`Self::endpoint_indices`] for the
/// shared design rationale, sibling matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier inspiration
/// — this method is the lex-ordering-axis arm of the same axis and
/// inherits every property from the declaration-axis arm's
/// documentation, differing only in the composition through
/// [`Self::sorted_endpoints`] instead of [`Self::endpoints`] and
/// the alphabetized consumer surface (an alphabetized range-walker
/// that binds BOTH lex-endpoint decl-slots atomically, a lex-
/// ordered saga-step audit event that emits both lex anchor decl-
/// slot integer coordinates atomically, an alphabetized truth-table
/// property test that anchors edge assertions at BOTH lex endpoint
/// decl-slots through ONE destructure). On an implementor whose
/// declaration order matches its lex order the two arms return the
/// same tuple; on an implementor whose declaration order diverges
/// from its lex order they name DIFFERENT canonical decl-slot pairs
/// (see
/// `endpoint_indices_and_sorted_endpoint_indices_diverge_on_declaration_order_that_diverges_from_lex_order`).
///
/// Default body destructures [`Self::sorted_endpoints`] and projects
/// each tuple slot under [`Self::index_of`] — the (lex-head-decl-
/// slot, lex-tail-decl-slot) pair aggregation is a typed CONSEQUENCE
/// of the composition of the lex-pair-aggregation primitive with the
/// per-slot decl-index projection, not a fifth codepath through
/// [`Self::sorted_variants`] + `<[T]>::first` + `<[T]>::last` +
/// per-slot `index_of`. Implementors override only when the lex-
/// decl-slot-pair aggregation needs to diverge from the natural
/// `(sorted_first().index_of(), sorted_last().index_of())` shape.
/// An implementor that overrides [`Self::sorted_endpoints`] (or the
/// [`Self::sorted_first`] / [`Self::sorted_last`] scalars it funnels
/// through) OR overrides [`Self::index_of`] propagates the override
/// through this default body to the lex-decl-slot-pair aggregation
/// automatically.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_first`] and
/// [`Self::sorted_last`] both return the sole variant whose
/// `index_of()` is `0`, so this method returns the diagonal tuple
/// `(0, 0)`. All FOUR pair-endpoint aggregation projections
/// ([`Self::endpoints`], [`Self::sorted_endpoints`],
/// [`Self::endpoint_indices`], this method) collapse onto the same
/// anchor at the boundary-cardinality edge under their respective
/// per-slot return-type projections.
///
/// The lex-endpoint-decl-slot pair contract —
/// `T::sorted_endpoint_indices() == (T::sorted_first().index_of(), T::sorted_last().index_of())`
/// AND
/// `(T::from_index(T::sorted_endpoint_indices().0), T::from_index(T::sorted_endpoint_indices().1)) == (Some(T::sorted_first()), Some(T::sorted_last()))`
/// on every implementor — is guaranteed by the default composition
/// through the lex-pair-aggregation primitive and the per-slot
/// decl-index projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (93) pins the
/// composition against the natural
/// `(sorted_first().index_of(), sorted_last().index_of())` shape
/// AND against the `from_index`-round-trip fixpoint back onto the
/// lex-endpoint typed anchors on every implementor.
///
/// Clauses (34) + (35) + (36) + (37) + (92) + (93) together CLOSE
/// the (return-type × ordering) 3×2 = 6-corner pair-endpoint
/// aggregation matrix at ALL SIX corners: (`Self`, declaration) at
/// clause (34); (`Self`, lex) at clause (35); (`&'static str`,
/// declaration) at clause (36); (`&'static str`, lex) at clause (37);
/// (`usize`, declaration) at clause (92); (`usize`, lex) at clause
/// (93). Every generic consumer that binds any of the six pair-
/// endpoint aggregation projection methods sees the SAME tuple
/// shape at every crate boundary regardless of which return-type
/// axis / ordering-axis corner it walks.
fn sorted_endpoint_indices() -> (usize, usize) {
let (head, tail) = <Self as ClosedSet>::sorted_endpoints();
(
<Self as ClosedSet>::index_of(head),
<Self as ClosedSet>::index_of(tail),
)
}
/// Render the declaration-order endpoint-label pair as a `String`
/// joined by `sep` — the joined-`String` sibling of
/// [`Self::endpoint_labels`] one return-shape axis over on the
/// (tuple, `String`) partition of the closed-set declaration-axis
/// endpoint-label return-shape axis.
///
/// Default body destructures [`Self::endpoint_labels`] and joins
/// the two-element `[head, tail]` slice under
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the (head-label, tail-label) rendering-as-string is a typed
/// CONSEQUENCE of the declaration-axis endpoint-label-pair
/// primitive AND the caller-supplied separator, not a fifth
/// codepath through `format!("{head}{sep}{tail}")` or a per-
/// implementor inline `[T::first().label(), T::last().label()].join(sep)`
/// two-primitive compound. Implementors override only when the
/// endpoint-label-as-string surface needs to diverge from the
/// natural `[endpoint_labels().0, endpoint_labels().1].join(sep)`
/// shape (no production implementor reaches for this today; the
/// axis exists for the same reason `via`, `set_label`, `labels`,
/// `labels_joined`, `endpoints`, `endpoint_labels`,
/// `interior_labels_joined` overrides exist — a typed escape hatch
/// the trait surface exposes rather than forcing the implementor
/// to hand-roll the impl). An implementor that overrides
/// [`Self::endpoint_labels`] (or the [`Self::endpoints`] /
/// [`Self::first`] / [`Self::last`] scalars it funnels through,
/// or [`Self::label`]) propagates the override through this
/// default body to the (head-label, tail-label) joined rendering
/// automatically; the endpoint-label-as-string surface funnels
/// through the declaration-axis endpoint-label-pair primitive on
/// the pair-materialization column AND the `slice::join`
/// primitive on the separator-threading column.
///
/// Sibling posture to [`Self::labels_joined`] on the (full-set,
/// endpoint) partition-flavor axis of the closed-set declaration-
/// axis label-as-string rendering surface —
/// [`Self::labels_joined`] renders EVERY declaration-ordered
/// canonical label under the caller's separator, this method
/// renders ONLY the two declaration-boundary-anchor labels under
/// the same separator. Sibling posture to
/// [`Self::interior_labels_joined`] on the (endpoint, interior)
/// partition-flavor axis of the (declaration-axis × `String`)
/// column — [`Self::interior_labels_joined`] renders the
/// strictly-interior labels only, this method renders the
/// strictly-boundary labels only. Sibling posture to
/// [`Self::endpoint_labels`] one return-shape axis over on the
/// (`(&'static str, &'static str)` tuple, `String`) partition of
/// the declaration-axis endpoint-label return-shape column —
/// [`Self::endpoint_labels`] returns the raw two-slot tuple, this
/// method returns the caller-separator-joined `String`.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::first`] and [`Self::last`] both
/// return the sole variant, so [`Self::endpoint_labels`] returns
/// the diagonal tuple `(v.label(), v.label())` and this method
/// returns `[v.label(), v.label()].join(sep)` — for a singleton
/// stub with label `"only"` and separator `"/"`, the answer is
/// `"only/only"`. The tuple SHAPE is preserved even at the
/// boundary-cardinality edge where the two slots collapse onto
/// the same label. Two-variant degeneracy — [`Self::first`] and
/// [`Self::last`] name distinct variants, so this method renders
/// the caller-separator-joined string of the two variants' labels
/// (`[T::first().label(), T::last().label()].join(sep)`); for a
/// two-variant stub with labels `"head"`, `"tail"` and separator
/// `"/"`, the answer is `"head/tail"`.
///
/// Consumer surface — a substrate-wide `INTENT_KIND_LIST`-style
/// boundary-only production separator rendering
/// `<head>/<tail>`, a natural-language diagnostic rendering
/// `boundary: <head>, <tail>` in a caller-chosen comma-space
/// separator style, a grammar-style boundary-pair renderer
/// emitting `<head> | <tail>` under a pipe separator, a
/// deterministic-across-machines boundary-only Prometheus tag
/// whose separator convention must not leak the strictly-
/// interior slots — bind to ONE trait method instead of hand-
/// rolling the two-primitive
/// `let (h, t) = T::endpoint_labels(); [h, t].join(sep)`
/// composition OR the three-primitive
/// `[T::first().label(), T::last().label()].join(sep)` expansion
/// at every callsite.
///
/// The declaration-axis endpoint-label-as-string contract —
/// `T::endpoint_labels_joined(sep) == {let (h, t) = T::endpoint_labels(); [h, t].join(sep)}`
/// on every implementor for every `sep` — is guaranteed by the
/// default composition through [`Self::endpoint_labels`] and the
/// standard-library `slice::join` primitive; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (44)
/// pins the composition against the natural
/// `[endpoint_labels().0, endpoint_labels().1].join(sep)` shape
/// across THREE representative separators (`"/"`, `", "`, `"|"`)
/// matching clauses (8) + (42)'s sweep on every implementor so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::endpoint_labels_joined`] on any typed carrier and
/// expect the same `String` answer at every crate boundary.
///
/// The (partition-flavor × ordering × return-shape) 2×2×2 cube
/// over the closed-set label-aggregation surface CLOSES on the
/// endpoint arm at the (endpoint × declaration × `String`)
/// corner: [`Self::labels`] / [`Self::sorted_labels`] on the
/// (full-set × ordering × `Vec`) column,
/// [`Self::labels_joined`] / [`Self::sorted_labels_joined`] on
/// the (full-set × ordering × `String`) column,
/// [`Self::interior_labels`] / [`Self::sorted_interior_labels`]
/// on the (interior × ordering × `Vec`) column,
/// [`Self::interior_labels_joined`] /
/// [`Self::sorted_interior_labels_joined`] on the (interior ×
/// ordering × `String`) column, [`Self::endpoint_labels`] /
/// [`Self::sorted_endpoint_labels`] on the (endpoint × ordering ×
/// pair-tuple) column, and this method +
/// [`Self::sorted_endpoint_labels_joined`] on the (endpoint ×
/// ordering × `String`) column — every (partition-flavor,
/// ordering, return-shape) corner of the closed-set label-
/// aggregation cube now emits at ONE typed trait method.
///
/// THEORY.md §III — the typescape; the (declaration-axis
/// endpoint-label-pair rendering-as-string) projection becomes a
/// TYPE projection on the trait rather than a per-consumer inline
/// `let (h, t) = T::endpoint_labels(); [h, t].join(sep)`
/// composition at every downstream endpoint-label-as-string site.
/// THEORY.md §V.1 — knowable platform; the endpoint-label-as-
/// string projection was an unnamed compound of the endpoint-
/// label-pair primitive + `slice::join` pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of the
/// substrate's endpoint-label-pair primitive — generic consumers
/// see ONE method, not one endpoint-pair-then-join compound per
/// crate.
/// THEORY.md §VI.1 — generation over composition; the endpoint-
/// label-as-string rendering emerges from the composition of
/// FOUR substrate primitives ([`Self::first`], [`Self::last`],
/// [`Self::label`], `slice::join`) rather than as a per-
/// implementor inline `[T::first().label(), T::last().label()].join(sep)`
/// three-primitive compound.
///
/// Frontier inspiration: Racket's `enum-endpoint-labels` composed
/// with `string-join` on closed enumerations (the boundary-only
/// candidate-pair-as-string emits as a single typed projection
/// on the finite-type layer rather than per-instance inline
/// compound); Idris's `showEndpoints` composed with
/// `Data.List.intercalate` on `Fin (S n) -> (String, String)` non-
/// empty finite-cardinality endpoint-pair projections; Haskell's
/// `intercalate sep [show minBound, show maxBound]` on the
/// `Bounded + Show` type-class pair — the endpoint-label rendering
/// composed from three prelude primitives on the bounded chain;
/// MLIR's `RegisteredOperationName::begin_end_names_joined()` on
/// the declaration-order Op registry (the endpoint-label-as-string
/// projection over the registered-op enumeration). Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::endpoint_labels`] surface with the
/// `slice::join` standard-library primitive on a two-element
/// stack-allocated array — no new dep, no new IR layer, no
/// supertrait bound, no per-implementor allocation beyond the
/// natural `String` allocation
/// [`Self::labels_joined`]'s sibling surface already routes.
fn endpoint_labels_joined(sep: &str) -> ::std::string::String {
let (head, tail) = <Self as ClosedSet>::endpoint_labels();
[head, tail].join(sep)
}
/// Render the lex-order endpoint-label pair as a `String` joined
/// by `sep` — the alphabetized endpoint-label-as-string sibling
/// of [`Self::endpoint_labels_joined`] one ordering axis over on
/// the (declaration, lex) partition of the closed-set endpoint-
/// label-as-string surface.
///
/// Default body destructures [`Self::sorted_endpoint_labels`] and
/// joins the two-element `[lex-head, lex-tail]` slice under
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the alphabetized endpoint-label rendering is a typed
/// CONSEQUENCE of [`Self::sorted_first`] + [`Self::sorted_last`] +
/// [`Self::label`] + ASCII lexicographic ordering + the chosen
/// separator. Implementors override only when the alphabetized
/// join surface needs to diverge from the natural
/// `[sorted_endpoint_labels().0, sorted_endpoint_labels().1].join(sep)`
/// shape (no production implementor reaches for this today — the
/// axis exists for the same reason `via`, `set_label`, `labels`,
/// `labels_joined`, `sorted_labels`, `sorted_labels_joined`,
/// `endpoint_labels`, `sorted_endpoint_labels`,
/// `endpoint_labels_joined` overrides exist: a typed escape hatch
/// the trait surface exposes rather than forcing the implementor
/// to hand-roll the impl).
///
/// Sibling posture to [`Self::sorted_labels_joined`] on the
/// (full-set, endpoint) partition-flavor axis of the closed-set
/// alphabetized label-as-string rendering surface —
/// [`Self::sorted_labels_joined`] renders EVERY lex-ordered
/// canonical label under the caller's separator, this method
/// renders ONLY the two lex-boundary-anchor labels under the
/// same separator. Sibling posture to
/// [`Self::sorted_interior_labels_joined`] on the (endpoint,
/// interior) partition-flavor axis of the (lex-axis × `String`)
/// column — [`Self::sorted_interior_labels_joined`] renders the
/// strictly-lex-interior labels only, this method renders the
/// strictly-lex-boundary labels only. See
/// [`Self::endpoint_labels_joined`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-ordering-axis arm of the same
/// return-shape axis and inherits every property from the
/// declaration-axis arm's documentation, differing only in the
/// composition through [`Self::sorted_endpoint_labels`] instead
/// of [`Self::endpoint_labels`] and the alphabetized consumer
/// surface (an alphabetized boundary badge that emits
/// `<lex-head-label>/<lex-tail-label>` in a diagnostic, a lex-
/// ordered saga-step audit event that emits both lex anchor
/// labels joined by a caller-supplied separator, an alphabetized-
/// completion UI that renders the lex boundary pair by joined
/// label under a chart-caption-style separator).
///
/// Singleton + two-variant degeneracies — mirror
/// [`Self::endpoint_labels_joined`]'s degeneracy profile one
/// ordering axis over. Singleton: `[T::sorted_first().label(), T::sorted_last().label()].join(sep)`
/// collapses to `<only>/<only>` (the diagonal-tuple label repeats
/// under the caller-supplied separator); for a singleton stub
/// with label `"only"` and separator `"/"`, the answer is
/// `"only/only"`. Two-variant: renders the caller-separator-joined
/// string of the two lex-ordered variants' labels; for a two-
/// variant stub with lex-ordered labels `("head", "tail")` and
/// separator `"/"`, the answer is `"head/tail"`.
///
/// The lex-axis endpoint-label-as-string contract —
/// `T::sorted_endpoint_labels_joined(sep) == {let (h, t) = T::sorted_endpoint_labels(); [h, t].join(sep)}`
/// on every implementor for every `sep` — is guaranteed by the
/// default composition through [`Self::sorted_endpoint_labels`]
/// and the standard-library `slice::join` primitive; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (45) pins the composition against the natural
/// `[sorted_endpoint_labels().0, sorted_endpoint_labels().1].join(sep)`
/// shape across THREE representative separators (`"/"`, `", "`,
/// `"|"`) matching clauses (10) + (43)'s sweep on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call [`Self::sorted_endpoint_labels_joined`]
/// on any typed carrier and expect the same `String` answer at
/// every crate boundary.
///
/// The (partition-flavor × ordering × return-shape) 2×2×3 cube
/// over the closed-set label-aggregation surface CLOSES at the
/// (endpoint × lex × `String`) corner: [`Self::labels`] /
/// [`Self::sorted_labels`] on (full-set × ordering × `Vec`),
/// [`Self::labels_joined`] / [`Self::sorted_labels_joined`] on
/// (full-set × ordering × `String`), [`Self::interior_labels`] /
/// [`Self::sorted_interior_labels`] on (interior × ordering ×
/// `Vec`), [`Self::interior_labels_joined`] /
/// [`Self::sorted_interior_labels_joined`] on (interior ×
/// ordering × `String`), [`Self::endpoint_labels`] /
/// [`Self::sorted_endpoint_labels`] on (endpoint × ordering ×
/// pair-tuple), [`Self::endpoint_labels_joined`] + this method
/// on (endpoint × ordering × `String`). A future consumer that
/// binds any of the twelve sees the same `Vec<&'static str>` /
/// `(&'static str, &'static str)` / `String` shape at every
/// crate boundary regardless of which cube corner it walks.
fn sorted_endpoint_labels_joined(sep: &str) -> ::std::string::String {
let (head, tail) = <Self as ClosedSet>::sorted_endpoint_labels();
[head, tail].join(sep)
}
/// The declaration-order strict-interior variant list — the
/// `Vec<Self>` complement of [`Self::endpoints`] over the closed-
/// set boundary-partition axis. Every variant `v` in the returned
/// vector satisfies `<Self as ClosedSet>::is_interior(v) == true`
/// (`v` is neither [`Self::first`] nor [`Self::last`]); the
/// declaration order of [`Self::ALL`] is preserved verbatim.
///
/// Sibling posture to [`Self::endpoints`] one arm over on the
/// (boundary, interior) partition of the closed-set declaration-
/// axis — [`Self::endpoints`] aggregates the two structural
/// endpoint anchors into a `(Self, Self)` tuple, this method
/// aggregates every strictly-interior slot into a `Vec<Self>`
/// collection. Together the two projections cover every variant in
/// [`Self::ALL`] exactly once: `T::endpoints()` names the boundary
/// slots and `T::interior()` names the interior slots, and their
/// union is the whole closed set (for `T::CARDINALITY >= 2`; the
/// singleton case collapses to `T::endpoints() == (v, v)` +
/// `T::interior() == []` where `v` is the sole variant).
///
/// The (return-shape × partition-flavor) 2×1 matrix over the
/// closed-set declaration-axis boundary surface CLOSES on the
/// interior arm — [`Self::endpoints`] on the boundary arm returns a
/// `(Self, Self)` tuple over the two structural anchors, this
/// method on the interior arm returns a `Vec<Self>` collection over
/// every strictly-interior slot. A future range-walker /
/// interior-badge renderer / audit-event emitter / per-implementor
/// coherence probe consumer that wants every strictly-interior
/// slot (a bounded loop that skips both endpoints and iterates
/// ONLY interior payloads, a phase-fold reducer whose interior arm
/// composes NON-boundary side effects, an alphabetized-completion
/// UI that hides the first + last entries from a strictly-interior
/// candidate list, a `tatara-check` per-slot interior-diagnostic
/// that renders each strictly-interior slot's label without a
/// separate `is_interior`-filter at every callsite) binds to ONE
/// trait method rather than hand-rolling either the
/// `T::ALL.iter().copied().filter(<T as ClosedSet>::is_interior).collect()`
/// three-primitive composition at every callsite OR the
/// `T::ALL.iter().copied().filter(|v| !T::is_endpoint(*v)).collect()`
/// four-primitive composition (which re-derives the same per-
/// callsite boundary-partition filter shape AND makes every
/// downstream site depend on the specific `is_interior` /
/// `is_endpoint` composition surface).
///
/// Default body walks [`Self::ALL`] and filters each variant through
/// [`Self::is_interior`] — the strictly-interior collection is a
/// typed CONSEQUENCE of the boundary-partition predicate, not a
/// third codepath through `ALL.iter().skip(1).take(CARDINALITY - 2)`
/// slice arithmetic. Implementors override only when the interior
/// collection needs to diverge from the natural
/// `ALL.iter().copied().filter(is_interior).collect()` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_variants` / `endpoints` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::is_interior`] (or the [`Self::is_endpoint`] /
/// [`Self::is_first`] / [`Self::is_last`] scalars it funnels
/// through) propagates the override through this default body to
/// the interior-collection projection automatically; the (variant
/// → interior collection) projection funnels through ONE typed
/// predicate on the filter column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::is_interior`] returns `false` on
/// the sole variant (which is BOTH [`Self::first`] and
/// [`Self::last`]), so this method returns the empty vector `[]`.
/// The (boundary, interior) partition holds at the singleton edge:
/// the sole variant lands in the endpoint pair (`T::endpoints()`
/// returns the diagonal tuple `(v, v)`) and the interior collection
/// is empty. Two-variant degeneracy — for a closed set with
/// `T::CARDINALITY == 2`, [`Self::first`] and [`Self::last`] name
/// distinct variants and both answer `true` to
/// [`Self::is_endpoint`], so this method returns the empty vector
/// `[]`. The interior collection has strictly `CARDINALITY - 2`
/// elements for `CARDINALITY >= 2` and `0` elements at the
/// singleton edge (which coincides with `CARDINALITY.saturating_sub(2)`
/// at every cardinality).
///
/// The interior-collection contract —
/// `T::interior() == T::ALL.iter().copied().filter(T::is_interior).collect()`
/// on every implementor — is guaranteed by the default composition
/// through [`Self::is_interior`]'s boundary-partition predicate;
/// the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (38) pins the
/// composition against the natural
/// `ALL.iter().copied().filter(is_interior).collect()` shape on
/// every implementor so a passing well-formedness sweep means every
/// generic consumer can call [`Self::interior`] on any typed
/// carrier and expect the same `Vec<Self>` answer at every crate
/// boundary.
///
/// The (boundary, interior) partition invariant — every variant in
/// [`Self::ALL`] lands in EXACTLY ONE of the two projections (the
/// endpoint pair OR the interior collection) — is pinned by
/// clause (38)'s composition through [`Self::is_interior`] AND
/// clause (32)'s complementarity assertion between
/// [`Self::is_endpoint`] and [`Self::is_interior`]. A regression
/// that added a strictly-interior slot to the endpoint pair OR a
/// structural endpoint anchor to the interior collection would
/// fail EITHER clause on the implementor whose partition drifted.
///
/// THEORY.md §III — the typescape; the (declaration-axis strict-
/// interior collection) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `T::ALL.iter().copied().filter(T::is_interior).collect()`
/// composition at every downstream interior-walk site. The
/// (boundary, interior) partition matrix over the closed-set
/// declaration-axis pair-aggregation / interior-aggregation surface
/// closes on the interior arm — [`Self::endpoints`] on the
/// boundary arm, this method on the interior arm, together
/// covering every variant in [`Self::ALL`] exactly once.
/// THEORY.md §V.1 — knowable platform; the (declaration-axis
/// strict-interior collection) projection was an unnamed compound
/// of [`Self::ALL`] + [`Self::is_interior`] + `filter` + `collect`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's boundary-partition predicate —
/// generic consumers see ONE method, not one interior-filter-shape-
/// per-crate.
/// THEORY.md §VI.1 — generation over composition; the (declaration-
/// axis interior collection) projection emerges from the
/// composition of TWO substrate primitives ([`Self::ALL`],
/// [`Self::is_interior`]) under `Iterator::filter` +
/// `Iterator::collect` rather than as a per-implementor
/// `const INTERIOR: &'static [Self] = &[Self::Middle]` declaration.
/// A future tightening of either primitive (a future const-fn
/// `is_interior` axis, a future perfect-hash boundary-partition
/// projection, a future `Iterator::filter_map` fused walk) propagates
/// to every closed-set interior-collection consumer through this
/// method's body.
///
/// Frontier inspiration: Racket's `enum-interior` on closed
/// enumerations (the collection projection over every strictly-
/// interior slot after excluding the head + tail anchors); Idris's
/// `Fin (S (S n))` non-empty-with-strictly-interior finite-
/// cardinality types where `interior : Vect (S (S n)) a -> Vect n a`
/// drops the head + tail anchors from a non-empty-with-interior
/// vector; Haskell's `init . tail` on the `Bounded + Enum` type-
/// class pair — the boundary-stripped interior collection composed
/// from two prelude primitives on the ordered enumeration chain;
/// MLIR's `RegisteredOperationName::interior_ops()` on the
/// registered-op enumeration (the boundary-stripped operation
/// collection). Translation through pleme-io primitives: a pure
/// default method walking the trait's existing [`Self::ALL`] slice
/// under the [`Self::is_interior`] boundary-partition predicate —
/// no new dep, no new IR layer, no supertrait bound, no per-
/// implementor allocation beyond the natural `Vec<Self>` collection
/// the sibling [`Self::sorted_variants`] surface already routes.
fn interior() -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|v| <Self as ClosedSet>::is_interior(*v))
.collect()
}
/// The lexicographic-order strict-interior variant list — the
/// `Vec<Self>` complement of [`Self::sorted_endpoints`] over the
/// closed-set lex-boundary-partition axis. Every variant `v` in
/// the returned vector satisfies
/// `<Self as ClosedSet>::is_sorted_interior(v) == true` (`v` is
/// neither [`Self::sorted_first`] nor [`Self::sorted_last`]); the
/// lex order of [`Self::sorted_variants`] is preserved verbatim.
///
/// Sibling posture to [`Self::interior`] one ordering axis over on
/// the (declaration, lex) partition of the closed-set interior-
/// collection surface — [`Self::interior`] fires on the
/// declaration-order strictly-interior slice, this method fires on
/// the lex-order strictly-interior slice. See [`Self::interior`]
/// for the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-ordering-axis arm of the
/// same partition axis and inherits every property from the
/// declaration-axis arm's documentation, differing only in the
/// composition through [`Self::sorted_variants`] +
/// [`Self::is_sorted_interior`] instead of [`Self::ALL`] +
/// [`Self::is_interior`] and the alphabetized consumer surface (an
/// alphabetized interior loop that walks ONLY lex-interior slots
/// and short-circuits on either lex endpoint, an alphabetized-
/// phase-fold reducer whose interior arm processes NON-lex-boundary
/// payloads and reserves the lex-endpoint arm for lex-boundary-only
/// side effects, an alphabetized-completion pass that hides the
/// alphabetically-first + alphabetically-last entries from a
/// strictly-lex-interior candidate list).
///
/// Default body walks [`Self::sorted_variants`] and filters each
/// variant through [`Self::is_sorted_interior`] — the strictly-
/// lex-interior collection is a typed CONSEQUENCE of the lex-
/// boundary-partition predicate, not a fourth codepath through
/// `sorted_variants().into_iter().skip(1).take(CARDINALITY - 2)`
/// slice arithmetic. Implementors override only when the lex-
/// interior collection needs to diverge from the natural
/// `sorted_variants().into_iter().filter(is_sorted_interior).collect()`
/// shape (no production implementor reaches for this today; the
/// axis exists for the same reason `via` / `set_label` / `labels` /
/// `sorted_variants` / `sorted_endpoints` overrides exist — a
/// typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl). An implementor
/// that overrides [`Self::is_sorted_interior`] (or the
/// [`Self::is_sorted_endpoint`] / [`Self::is_sorted_first`] /
/// [`Self::is_sorted_last`] scalars it funnels through) propagates
/// the override through this default body to the lex-interior-
/// collection projection automatically; the (variant → lex-
/// interior collection) projection funnels through ONE typed
/// predicate on the filter column AND through
/// [`Self::sorted_variants`] on the ordering column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::is_sorted_interior`] returns
/// `false` on the sole variant (which is BOTH [`Self::sorted_first`]
/// and [`Self::sorted_last`]), so this method returns the empty
/// vector `[]`. Two-variant degeneracy — for a closed set with
/// `T::CARDINALITY == 2`, [`Self::sorted_first`] and
/// [`Self::sorted_last`] name distinct variants and both answer
/// `true` to [`Self::is_sorted_endpoint`], so this method returns
/// the empty vector `[]`. The lex-interior collection has strictly
/// `CARDINALITY - 2` elements for `CARDINALITY >= 2` and `0`
/// elements at the singleton edge, matching [`Self::interior`]'s
/// cardinality profile one ordering axis over.
///
/// The lex-interior-collection contract —
/// `T::sorted_interior() == T::sorted_variants().into_iter().filter(T::is_sorted_interior).collect()`
/// on every implementor — is guaranteed by the default composition
/// through [`Self::is_sorted_interior`]'s lex-boundary-partition
/// predicate; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (39) pins the
/// composition against the natural
/// `sorted_variants().into_iter().filter(is_sorted_interior).collect()`
/// shape on every implementor so a passing well-formedness sweep
/// means every generic consumer can call [`Self::sorted_interior`]
/// on any typed carrier and expect the same `Vec<Self>` answer at
/// every crate boundary.
///
/// The (ordering × partition-flavor) 2×2 matrix over the closed-
/// set boundary + interior aggregation surface is now closed at
/// ALL FOUR corners — [`Self::endpoints`] +
/// [`Self::sorted_endpoints`] on the boundary arm (declaration-
/// axis + lex-axis), [`Self::interior`] + this method on the
/// interior arm (declaration-axis + lex-axis). Together the four
/// methods cover every (ordering, partition-flavor) corner of the
/// closed-set variant-aggregation matrix. A future consumer that
/// binds any of the four sees the SAME `(Self, Self)` or
/// `Vec<Self>` shape at every crate boundary regardless of which
/// ordering axis it walks and regardless of whether it aggregates
/// the boundary or interior partition.
fn sorted_interior() -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|v| <Self as ClosedSet>::is_sorted_interior(*v))
.collect()
}
/// The declaration-order strict-interior label list — the
/// `Vec<&'static str>` label projection of [`Self::interior`] over
/// the closed-set declaration-axis boundary-partition surface.
/// Every label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some strictly-interior variant
/// (`<Self as ClosedSet>::is_interior(v) == true` for the sourcing
/// variant, so `s` is neither [`Self::first`]'s label nor
/// [`Self::last`]'s label); the declaration order of
/// [`Self::interior`] is preserved verbatim.
///
/// Sibling posture to [`Self::interior`] one return-shape axis
/// over on the (`Vec<Self>` typed-variant collection,
/// `Vec<&'static str>` label collection) partition of the closed-
/// set declaration-axis interior-aggregation surface — the
/// typed-variant arm materializes each strictly-interior slot as
/// `Self`, this method labels each slot under [`Self::label`]. The
/// two projections share the (boundary, interior) partition on
/// the boundary-partition column and share the declaration-order
/// ordering on the ordering column; they differ only on the
/// return-shape column, where the typed-variant arm returns the
/// carrier and the label arm returns the rendering. Both share
/// the exact `CARDINALITY.saturating_sub(2)` length invariant on
/// every implementor.
///
/// Sibling posture to [`Self::endpoint_labels`] one partition-
/// flavor axis over on the (boundary, interior) partition of the
/// closed-set declaration-axis label-aggregation surface —
/// [`Self::endpoint_labels`] aggregates the two structural
/// endpoint labels into a `(&'static str, &'static str)` tuple,
/// this method aggregates every strictly-interior label into a
/// `Vec<&'static str>` collection. Together the two label
/// projections cover every label in
/// [`Self::labels`](Self::sorted_labels)' declaration counterpart
/// exactly once: [`Self::endpoint_labels`] names the boundary
/// labels and this method names the interior labels, and their
/// union is the whole label sequence of [`Self::ALL`] (for
/// `T::CARDINALITY >= 2`; the singleton case collapses to
/// [`Self::endpoint_labels`] returning the diagonal tuple over
/// the sole label + this method returning `[]`).
///
/// The (partition-flavor × ordering × return-shape) 2×2×2 cube
/// over the closed-set boundary + interior aggregation surface
/// CLOSES on the (interior, declaration, label) corner —
/// [`Self::endpoints`] on the (boundary, declaration, variant)
/// corner, [`Self::endpoint_labels`] on the (boundary,
/// declaration, label) corner, [`Self::sorted_endpoints`] on the
/// (boundary, lex, variant) corner, [`Self::sorted_endpoint_labels`]
/// on the (boundary, lex, label) corner, [`Self::interior`] on
/// the (interior, declaration, variant) corner, this method on
/// the (interior, declaration, label) corner, [`Self::sorted_interior`]
/// on the (interior, lex, variant) corner, and
/// [`Self::sorted_interior_labels`] on the (interior, lex, label)
/// corner. Together the eight methods cover every corner of the
/// (partition-flavor × ordering × return-shape) cube on the
/// closed-set variant-aggregation surface. A future range-walker
/// / interior-label-badge renderer / audit-event emitter /
/// per-implementor coherence probe consumer that binds any of the
/// eight sees the SAME tuple or collection shape at every crate
/// boundary regardless of which cube corner it walks.
///
/// Future consumers — an alphabetized-completion pass that
/// renders every strictly-interior label WITHOUT a per-callsite
/// `T::interior().into_iter().map(T::label).collect()` two-primitive
/// composition (the substrate-wide `interior + label` sweep every
/// declaration-axis interior-label-badge renderer re-derives),
/// a `tatara-check` interior-label diagnostic that renders each
/// strictly-interior slot's label without materializing the
/// typed variant, an audit-event emitter that opens an
/// "interior-slot-label" side channel on every non-boundary
/// variant WITHOUT threading the caller through per-slot
/// `label()` calls, a metrics tagger that emits the interior
/// labels as a pre-declared histogram bucket-set — bind to ONE
/// trait method rather than hand-rolling the natural
/// `T::interior().into_iter().map(T::label).collect()` two-primitive
/// composition at every callsite. Any override of
/// [`Self::interior`] (or the [`Self::is_interior`] /
/// [`Self::is_endpoint`] / [`Self::is_first`] / [`Self::is_last`]
/// scalars it funnels through) OR of [`Self::label`] propagates
/// through this method's body to every interior-label-collection
/// consumer automatically; the (variant → interior-label
/// collection) projection funnels through ONE typed collection
/// primitive on the aggregation column AND the per-slot label
/// projection on the rendering column.
///
/// Default body maps [`Self::interior`] under [`Self::label`] —
/// the strictly-interior-label collection is a typed CONSEQUENCE
/// of the composition of the declaration-axis interior-collection
/// primitive with the per-slot label projection, not a third
/// codepath through `ALL.iter().copied().filter(is_interior).map(label).collect()`
/// four-primitive composition. Implementors override only when
/// the label-collection needs to diverge from the natural
/// `interior().into_iter().map(label).collect()` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_variants` / `interior` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl).
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::interior`] returns `[]`, so
/// this method returns `[]`. Two-variant degeneracy — for a
/// closed set with `T::CARDINALITY == 2`, [`Self::interior`]
/// returns `[]`, so this method returns `[]`. The interior-label
/// collection has strictly `CARDINALITY - 2` elements for
/// `CARDINALITY >= 2` and `0` elements at the singleton edge
/// (which coincides with `CARDINALITY.saturating_sub(2)` at every
/// cardinality).
///
/// The interior-label-collection contract —
/// `T::interior_labels() == T::interior().into_iter().map(T::label).collect()`
/// on every implementor — is guaranteed by the default
/// composition through [`Self::interior`]'s declaration-axis
/// interior-collection primitive AND the per-slot label
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (40) pins the
/// composition against the natural
/// `interior().into_iter().map(label).collect()` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call [`Self::interior_labels`] on any
/// typed carrier and expect the same `Vec<&'static str>` answer
/// at every crate boundary.
///
/// THEORY.md §III — the typescape; the (declaration-axis strict-
/// interior label collection) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `T::interior().into_iter().map(T::label).collect()` composition
/// at every downstream interior-label-walk site. The
/// (partition-flavor × ordering × return-shape) 2×2×2 cube over
/// the closed-set variant-aggregation surface closes on the
/// (interior, declaration, label) corner —
/// [`Self::endpoint_labels`] on the (boundary, declaration,
/// label) corner, this method on the (interior, declaration,
/// label) corner, together covering every declaration-axis label
/// in [`Self::ALL`] exactly once.
/// THEORY.md §V.1 — knowable platform; the (declaration-axis
/// strict-interior label collection) projection was an unnamed
/// compound of [`Self::interior`] + [`Self::label`] + `map` +
/// `collect` pre-lift; naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's declaration-
/// axis interior-collection primitive and the per-slot label
/// projection — generic consumers see ONE method, not one
/// interior-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// (declaration-axis interior-label collection) projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::interior`], [`Self::label`]) under `Iterator::map` +
/// `Iterator::collect` rather than as a per-implementor
/// `const INTERIOR_LABELS: &'static [&'static str] = &["middle"]`
/// declaration. A future tightening of either primitive (a future
/// const-fn `interior` axis, a future perfect-hash label
/// projection, a future `Iterator::filter_map` fused walk)
/// propagates to every closed-set interior-label-collection
/// consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-interior-labels` on
/// closed enumerations (the label projection over every strictly-
/// interior slot after excluding the head + tail anchors); Idris's
/// `Fin (S (S n)) -> Vect n String` non-empty-with-strictly-
/// interior label-vector projection via `showFin` composed with
/// the boundary-stripped `interior` primitive; Haskell's
/// `map show . init . tail` on the `Bounded + Enum + Show`
/// type-class trio — the boundary-stripped interior-label
/// collection composed from three prelude primitives on the
/// ordered enumeration chain; MLIR's
/// `RegisteredOperationName::interior_op_names()` on the
/// registered-op enumeration (the boundary-stripped operation-
/// name collection). Translation through pleme-io primitives: a
/// pure default method mapping the trait's existing
/// [`Self::interior`] collection under per-slot [`Self::label`]
/// projection — no new dep, no new IR layer, no supertrait bound,
/// no per-implementor allocation beyond the natural
/// `Vec<&'static str>` collection the sibling
/// [`Self::sorted_labels`] surface already routes.
fn interior_labels() -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::interior()
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The lexicographic-order strict-interior label list — the
/// `Vec<&'static str>` label projection of [`Self::sorted_interior`]
/// over the closed-set lex-axis boundary-partition surface. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some strictly-lex-interior variant
/// (`<Self as ClosedSet>::is_sorted_interior(v) == true` for the
/// sourcing variant, so `s` is neither [`Self::sorted_first`]'s
/// label nor [`Self::sorted_last`]'s label); the lex order of
/// [`Self::sorted_interior`] is preserved verbatim.
///
/// Sibling posture to [`Self::interior_labels`] one ordering axis
/// over on the (declaration, lex) partition of the closed-set
/// interior-label-collection surface — [`Self::interior_labels`]
/// fires on the declaration-order strictly-interior label slice,
/// this method fires on the lex-order strictly-interior label
/// slice. See [`Self::interior_labels`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-ordering-axis arm of the same
/// return-shape axis and inherits every property from the
/// declaration-axis arm's documentation, differing only in the
/// composition through [`Self::sorted_interior`] instead of
/// [`Self::interior`] and the alphabetized consumer surface (an
/// alphabetized interior-label loop that emits every strictly-
/// lex-interior label in lex order without a per-callsite
/// `sorted_interior + label + map + collect` composition, an
/// alphabetized-phase-fold reducer whose interior arm labels each
/// strictly-lex-interior slot for structured logging, an
/// alphabetized-completion pass that hides the alphabetically-
/// first + alphabetically-last labels from a strictly-lex-interior
/// candidate-label list).
///
/// Default body maps [`Self::sorted_interior`] under
/// [`Self::label`] — the strictly-lex-interior-label collection is
/// a typed CONSEQUENCE of the composition of the lex-axis interior-
/// collection primitive with the per-slot label projection, not a
/// fourth codepath through
/// `sorted_variants().into_iter().filter(is_sorted_interior).map(label).collect()`
/// four-primitive composition. Implementors override only when the
/// lex-interior-label collection needs to diverge from the natural
/// `sorted_interior().into_iter().map(label).collect()` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_variants` / `sorted_interior` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::sorted_interior`] (or the
/// [`Self::is_sorted_interior`] / [`Self::is_sorted_endpoint`] /
/// [`Self::is_sorted_first`] / [`Self::is_sorted_last`] scalars it
/// funnels through) OR overrides [`Self::label`] propagates the
/// override through this default body to the lex-interior-label-
/// collection projection automatically; the (variant → lex-
/// interior-label collection) projection funnels through ONE typed
/// collection primitive on the aggregation column AND the per-slot
/// label projection on the rendering column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_interior`] returns `[]`,
/// so this method returns `[]`. Two-variant degeneracy — for a
/// closed set with `T::CARDINALITY == 2`, [`Self::sorted_interior`]
/// returns `[]`, so this method returns `[]`. The lex-interior-
/// label collection has strictly `CARDINALITY - 2` elements for
/// `CARDINALITY >= 2` and `0` elements at the singleton edge,
/// matching [`Self::interior_labels`]'s cardinality profile one
/// ordering axis over.
///
/// The lex-interior-label-collection contract —
/// `T::sorted_interior_labels() == T::sorted_interior().into_iter().map(T::label).collect()`
/// on every implementor — is guaranteed by the default
/// composition through [`Self::sorted_interior`]'s lex-axis
/// interior-collection primitive AND the per-slot label
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (41) pins the
/// composition against the natural
/// `sorted_interior().into_iter().map(label).collect()` shape on
/// every implementor so a passing well-formedness sweep means
/// every generic consumer can call [`Self::sorted_interior_labels`]
/// on any typed carrier and expect the same
/// `Vec<&'static str>` answer at every crate boundary.
///
/// The (partition-flavor × ordering × return-shape) 2×2×2 cube
/// over the closed-set boundary + interior aggregation surface
/// is now closed at ALL EIGHT corners — [`Self::endpoints`] and
/// [`Self::sorted_endpoints`] on the (boundary, ordering,
/// variant) pair, [`Self::endpoint_labels`] and
/// [`Self::sorted_endpoint_labels`] on the (boundary, ordering,
/// label) pair, [`Self::interior`] and [`Self::sorted_interior`]
/// on the (interior, ordering, variant) pair,
/// [`Self::interior_labels`] and this method on the (interior,
/// ordering, label) pair. Together the eight methods cover every
/// corner of the (partition-flavor × ordering × return-shape)
/// 2×2×2 = 8-corner cube on the closed-set variant-aggregation
/// surface. A future consumer that binds any of the eight sees
/// the same tuple or collection shape at every crate boundary
/// regardless of which cube corner it walks (one of
/// `(Self, Self)`, `(&'static str, &'static str)`, `Vec<Self>`,
/// `Vec<&'static str>`).
fn sorted_interior_labels() -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::sorted_interior()
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// Render the declaration-order strict-interior label collection
/// as a `String` joined by `sep` — the substrate-wide alphabetized-
/// vs-declaration interior-label-as-string surface consumers thread
/// into structured diagnostics that want the boundary-stripped
/// candidate list in a caller-supplied separator style
/// (`interior: beta, gamma, delta`, `middle-only: beta/gamma`, an
/// interior-only `expected one of the middle kinds: … ` metrics
/// tag whose surface must NOT leak the two endpoint anchors).
///
/// Default body composes [`Self::interior_labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the interior-labels-as-string rendering is a typed
/// CONSEQUENCE of [`Self::ALL`] + [`Self::label`] +
/// [`Self::is_endpoint`] + the chosen separator. Implementors
/// override only when the join surface needs to diverge from the
/// natural `interior_labels().join(sep)` shape (no production
/// implementor reaches for this today — the axis exists for the
/// same reason `via`, `set_label`, `labels`, `labels_joined`,
/// `sorted_labels`, `sorted_labels_joined`, `interior_labels`,
/// `sorted_interior_labels`, `suggest_closest`,
/// `parse_label_with_hint` overrides exist: a typed escape hatch
/// the trait surface exposes rather than forcing the implementor
/// to hand-roll the impl).
///
/// Sibling posture to [`Self::labels_joined`] on the (full-set,
/// interior) partition-flavor axis of the closed-set label-as-
/// string rendering surface — [`Self::labels_joined`] renders
/// EVERY declaration-order canonical label under the caller's
/// separator, this method renders the SAME declaration-order
/// slice with the two boundary-anchor labels stripped. The
/// (partition-flavor × ordering × return-shape) 2×2×2 cube over
/// the closed-set label-aggregation surface has [`Self::labels`]
/// / [`Self::sorted_labels`] on the (full-set × ordering × Vec)
/// arm, [`Self::labels_joined`] / [`Self::sorted_labels_joined`]
/// on the (full-set × ordering × String) arm,
/// [`Self::interior_labels`] / [`Self::sorted_interior_labels`]
/// on the (interior × ordering × Vec) arm, and this method +
/// [`Self::sorted_interior_labels_joined`] on the (interior ×
/// ordering × String) arm — every corner of the 8-corner cube
/// binds to ONE trait method rather than a per-callsite
/// `iter+filter+map+collect+join` five-primitive composition.
///
/// Singleton + two-variant degeneracies —
/// [`Self::interior_labels`] returns the empty vector at both
/// edges, so `slice::join` on an empty slice yields the empty
/// string. Both boundary-cardinality edges collapse to `""`
/// regardless of the caller-supplied separator. The
/// interior-label-as-string projection's length collapses in
/// lockstep with [`Self::interior_labels`]'s length collapsing to
/// zero, matching the interior-label-Vec projection's
/// degeneracy profile one return-shape axis over.
///
/// The interior-labels-as-string contract —
/// `T::interior_labels_joined(sep) == T::interior_labels().join(sep)`
/// on every implementor for every `sep` — is guaranteed by the
/// default composition through [`Self::interior_labels`]'s
/// declaration-axis interior-collection primitive AND the
/// standard-library `slice::join` primitive; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (42)
/// pins the composition against the natural
/// `interior_labels().join(sep)` shape across THREE representative
/// separators (`"/"`, `", "`, `"|"`) on every implementor so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::interior_labels_joined`] on any typed carrier and
/// expect the same `String` answer at every crate boundary.
///
/// Future consumers — an interior-only completion bar renderer
/// that wants `beta | gamma | delta` grammar-style, a
/// `tatara-check` diagnostic that wants
/// `middle kinds: beta, gamma, delta` in a caller-chosen
/// separator style, an interior-only Prometheus tag whose
/// separator convention must not leak the boundary anchors, a
/// structured-logging formatter that renders every strictly-
/// interior label under a per-formatter separator — bind to ONE
/// trait method instead of hand-rolling the
/// `interior_labels().join(sep)` compound at each call site, and
/// the closed-set projection's interior-only rendering surface
/// evolves at ONE site rather than per-consumer.
///
/// THEORY.md §V.1 — knowable platform; the interior-labels-as-
/// string shape sat as an unnamed compound of
/// [`Self::interior_labels`] + [`slice::join`] pre-lift; naming
/// it on the trait makes the projection a TYPED CONSEQUENCE of
/// [`Self::interior_labels`] + the chosen separator — generic
/// consumers see ONE method, not ONE interior-then-join compound
/// per crate.
/// THEORY.md §VI.1 — generation over composition; the interior-
/// labels-as-string rendering emerges from the composition of
/// FIVE substrate primitives ([`Self::ALL`], [`Self::label`],
/// [`Self::is_endpoint`], `slice::join`, the caller-supplied
/// separator) rather than as a per-consumer inline
/// `iter+filter+map+collect+join` quintuple. A future tightening
/// of either primitive (a Unicode-collation-aware sort, an
/// Oxford-comma-aware join, a locale-sensitive rendering)
/// propagates to every closed-set consumer through ONE trait body.
///
/// Frontier inspiration: Racket's `enum-interior-labels`
/// composed with `string-join` on closed enumerations — the
/// boundary-stripped candidate-list-as-string emits as a single
/// typed projection on the finite-type layer rather than per-
/// instance inline compound. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::interior_labels`] surface with the
/// `slice::join` standard-library primitive — no new dep, no new
/// IR layer, no supertrait bound, no per-implementor allocation
/// beyond the natural `String` allocation
/// [`Self::labels_joined`]'s sibling surface already routes.
fn interior_labels_joined(sep: &str) -> ::std::string::String {
<Self as ClosedSet>::interior_labels().join(sep)
}
/// Render the lex-order strict-interior label collection as a
/// `String` joined by `sep` — the alphabetized interior-label-as-
/// string sibling of [`Self::interior_labels_joined`] one
/// ordering axis over on the (declaration, lex) partition of the
/// closed-set interior-label-as-string surface.
///
/// Default body composes [`Self::sorted_interior_labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// — the alphabetized interior-labels-as-string rendering is a
/// typed CONSEQUENCE of [`Self::ALL`] + [`Self::label`] +
/// [`Self::is_sorted_endpoint`] + ASCII lexicographic ordering +
/// the chosen separator. Implementors override only when the
/// alphabetized join surface needs to diverge from the natural
/// `sorted_interior_labels().join(sep)` shape (no production
/// implementor reaches for this today — the axis exists for the
/// same reason `via`, `set_label`, `labels`, `labels_joined`,
/// `sorted_labels`, `sorted_labels_joined`, `interior_labels`,
/// `sorted_interior_labels`, `interior_labels_joined`,
/// `suggest_closest`, `parse_label_with_hint` overrides exist: a
/// typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl).
///
/// Sibling posture to [`Self::sorted_labels_joined`] on the
/// (full-set, interior) partition-flavor axis of the closed-set
/// alphabetized label-as-string rendering surface —
/// [`Self::sorted_labels_joined`] renders EVERY lex-ordered
/// canonical label under the caller's separator, this method
/// renders the SAME lex-ordered slice with the two
/// lex-boundary-anchor labels stripped. See
/// [`Self::interior_labels_joined`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-ordering-axis arm of the same
/// return-shape axis and inherits every property from the
/// declaration-axis arm's documentation, differing only in the
/// composition through [`Self::sorted_interior_labels`] instead
/// of [`Self::interior_labels`] and the alphabetized consumer
/// surface (an alphabetized interior-only completion bar that
/// emits `beta | delta | epsilon`, a `tatara-check` diagnostic
/// rendering `middle kinds: beta, delta, epsilon` in
/// alphabetized natural-language surface, a deterministic-across-
/// machines interior-only Prometheus tag whose alphabetized
/// ordering must not depend on `Self::ALL`'s declaration order).
///
/// Singleton + two-variant degeneracies —
/// [`Self::sorted_interior_labels`] returns the empty vector at
/// both edges, so `slice::join` on an empty slice yields the
/// empty string. Both boundary-cardinality edges collapse to
/// `""` regardless of the caller-supplied separator, matching
/// [`Self::interior_labels_joined`]'s degeneracy profile one
/// ordering axis over.
///
/// The alphabetized interior-labels-as-string contract —
/// `T::sorted_interior_labels_joined(sep) == T::sorted_interior_labels().join(sep)`
/// on every implementor for every `sep` — is guaranteed by the
/// default composition through [`Self::sorted_interior_labels`]'s
/// lex-axis interior-collection primitive AND the standard-library
/// `slice::join` primitive; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (43) pins the
/// composition against the natural
/// `sorted_interior_labels().join(sep)` shape across THREE
/// representative separators (`"/"`, `", "`, `"|"`) on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call
/// [`Self::sorted_interior_labels_joined`] on any typed carrier
/// and expect the same `String` answer at every crate boundary.
///
/// The (partition-flavor × ordering × return-shape) 2×2×2 cube
/// over the closed-set label-aggregation surface is now closed
/// at ALL EIGHT corners — [`Self::labels`] on (full-set ×
/// declaration × Vec), [`Self::sorted_labels`] on (full-set ×
/// lex × Vec), [`Self::labels_joined`] on (full-set ×
/// declaration × String), [`Self::sorted_labels_joined`] on
/// (full-set × lex × String), [`Self::interior_labels`] on
/// (interior × declaration × Vec), [`Self::sorted_interior_labels`]
/// on (interior × lex × Vec), [`Self::interior_labels_joined`]
/// on (interior × declaration × String), and this method on
/// (interior × lex × String). A future consumer that binds any
/// of the eight sees the same `Vec<&'static str>` or `String`
/// shape at every crate boundary regardless of which cube corner
/// it walks.
fn sorted_interior_labels_joined(sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_interior_labels().join(sep)
}
/// The declaration-order strict-interior index list — the
/// `Vec<usize>` decl-slot projection of [`Self::interior`] over the
/// closed-set declaration-axis boundary-partition surface. Every
/// index `i` in the returned vector is the [`Self::index_of`]
/// declaration-slot of some strictly-interior variant `v` in
/// [`Self::interior`] (`<Self as ClosedSet>::is_interior(v) == true`,
/// equivalently `<Self as ClosedSet>::is_interior_index(i) == true`),
/// so `i` names neither `0` (the decl-head endpoint slot) nor
/// `Self::CARDINALITY - 1` (the decl-tail endpoint slot); the
/// declaration order of [`Self::interior`] is preserved verbatim.
///
/// Opens the (`Vec<usize>` decl-slot collection) return-shape row
/// on the (return-shape × ordering) 3×2 interior-aggregation matrix
/// past the pre-existing (`Vec<Self>` typed-variant collection) row
/// closed by [`Self::interior`] + [`Self::sorted_interior`] and the
/// (`Vec<&'static str>` label collection) row closed by
/// [`Self::interior_labels`] + [`Self::sorted_interior_labels`].
/// Sibling posture to [`Self::interior`] one return-shape axis over
/// on the (`Vec<Self>`, `Vec<&'static str>`, `Vec<usize>`)
/// return-shape partition of the closed-set declaration-axis
/// interior-aggregation surface — [`Self::interior`] materializes
/// each strictly-interior slot as `Self`, [`Self::interior_labels`]
/// labels each slot under [`Self::label`], this method projects
/// each slot onto its declaration-order `usize` position through
/// [`Self::index_of`]. All three walk the SAME
/// (declaration-endpoint-stripped variant sequence) primitive and
/// MUST agree slot-for-slot on the underlying (variant → decl slot,
/// variant → canonical label, variant → variant) three-way
/// projection triangle over the strictly-interior partition.
///
/// The (return-shape × ordering × partition-flavor) 3×2×2 cube
/// over the closed-set aggregation surface post-lift:
///
/// | Return-shape | Full-set decl | Full-set lex | Interior decl | Interior lex |
/// |--------------------------|--------------------|-------------------|---------------------|---------------------|
/// | `Vec<Self>` | (implicit `ALL`) | [`Self::sorted_variants`] | [`Self::interior`] | [`Self::sorted_interior`] |
/// | `Vec<&'static str>` | [`Self::labels`] | [`Self::sorted_labels`] | [`Self::interior_labels`] | [`Self::sorted_interior_labels`] |
/// | `Vec<usize>` | (implicit `0..CARDINALITY`) | (implicit `sorted_indices()` — pending) | [`Self::interior_indices`] | (pending) |
///
/// Default body composes [`Self::interior`] with `.into_iter()` +
/// `.map(Self::index_of)` verbatim — the strictly-interior
/// decl-slot collection is a typed CONSEQUENCE of the
/// boundary-partition predicate composed with the per-slot
/// decl-index projection, not a fourth codepath through inline
/// slice arithmetic `(1..T::CARDINALITY - 1).collect()` (which
/// re-derives the endpoint-position literals at every callsite AND
/// silently accepts a degenerate 0 / 1 / 2-variant set with a
/// `.saturating_sub` shape mismatch on the tail slot). Implementors
/// override only when the strictly-interior decl-slot collection
/// needs to diverge from the natural
/// `interior().into_iter().map(index_of).collect()` shape — a
/// typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl. An implementor
/// that overrides [`Self::is_interior`] (or the
/// [`Self::is_endpoint`] / [`Self::is_first`] / [`Self::is_last`]
/// scalars it funnels through) propagates the override through
/// [`Self::interior`] to this default body automatically; the
/// (variant → strictly-interior decl-slot collection) projection
/// funnels through ONE typed predicate on the filter column AND
/// through [`Self::index_of`] on the projection column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::interior`] returns the empty
/// vector, so this method returns `[]`. Two-variant degeneracy —
/// for `T::CARDINALITY == 2`, [`Self::interior`] returns `[]` (both
/// slots are endpoints), so this method returns `[]`. The
/// strictly-interior decl-slot collection has strictly
/// `CARDINALITY - 2` elements for `CARDINALITY >= 2` and `0`
/// elements at the singleton edge, matching [`Self::interior`]'s
/// cardinality profile one return-shape axis over.
///
/// Future consumers — a bounded interior loop that iterates over
/// `T::interior_indices()` to key per-slot data structures that
/// hold entries ONLY for strictly-interior slots (a
/// parallel-vector renderer that pins the endpoint slots to
/// distinct badges and walks ONLY the interior slots for the
/// standard cell rendering, a per-slot metrics counter table
/// `[u64; T::CARDINALITY]` that zeroes the endpoint slots and
/// increments ONLY the interior slots per sample, a bitset
/// interior-observed-slot renderer that sets bit `i` per observed
/// strictly-interior slot), a range-based coherence probe that
/// asserts every observed decl-slot sits in `T::interior_indices()`
/// before crediting the observation to the interior arm of a
/// boundary-flavored fold, a `tatara-check` per-slot per-label
/// diagnostic that renders `<label>: <count>` only for the
/// strictly-interior slots — bind to ONE trait method instead of
/// hand-rolling either
/// `T::interior().into_iter().map(T::index_of).collect()` (which
/// re-derives the same two-primitive composition at every
/// callsite) OR the inline
/// `(0..T::CARDINALITY).filter(|&i| T::is_interior_index(i)).collect()`
/// (which re-derives the underlying boundary-partition predicate
/// composition at every callsite AND drifts silently when a
/// future implementor overrides [`Self::interior`] to route
/// through a divergent boundary primitive).
///
/// The strictly-interior decl-slot collection contract —
/// `T::interior_indices() == T::interior().into_iter().map(T::index_of).collect()`
/// on every implementor — is guaranteed by the default composition
/// through [`Self::interior`] + [`Self::index_of`]; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (94) pins the composition against the natural
/// `interior().into_iter().map(index_of).collect()` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call `interior_indices` on any typed
/// carrier and expect the same `Vec<usize>` answer at every crate
/// boundary.
///
/// THEORY.md §III — the typescape; the (strictly-interior partition
/// → decl-slot collection) `Vec<usize>` projection becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `T::interior().into_iter().map(T::index_of).collect()` two-
/// primitive composition at every downstream interior-decl-slot
/// lookup site. The (return-shape × ordering) 3×2 interior-
/// aggregation matrix opens its (`Vec<usize>`, decl) corner
/// alongside the pre-existing (`Vec<Self>`, decl) corner
/// [`Self::interior`] and (`Vec<&'static str>`, decl) corner
/// [`Self::interior_labels`].
/// THEORY.md §V.1 — knowable platform; the (strictly-interior decl-
/// slot collection) projection was an unnamed compound of
/// [`Self::interior`] + `.map(Self::index_of).collect()` pre-lift;
/// naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the two substrate primitives — generic consumers see ONE
/// method, not ONE interior-decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of [`Self::interior`] +
/// [`Self::index_of`] rather than as a per-implementor
/// `const INTERIOR_INDICES: [usize; N - 2] = [1, 2, ..., N - 2];`
/// declaration that silently drifts from [`Self::ALL`] on any
/// reordering or when a hand-rolled [`Self::is_interior`] override
/// carves a different strictly-interior partition.
///
/// Frontier inspiration: Racket's `(enum-indices/interior enum)`
/// on a closed enum projects the interior partition directly onto
/// its declaration-order slot list, complementary to
/// `(enum-indices enum)` that emits the full-set slot list. MLIR's
/// `mlir::OperationName::interior_op_indices()` on the
/// registered-op enumeration (the boundary-stripped operation
/// collection's index projection). Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::interior`] + [`Self::index_of`] surfaces —
/// no new dep, no new IR layer, no supertrait bound, no per-
/// implementor allocation beyond the natural `Vec<usize>`
/// collection the sibling [`Self::interior_labels`] surface
/// already routes one return-shape axis over.
fn interior_indices() -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::interior()
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The lex-order strict-interior index list — the `Vec<usize>`
/// decl-slot projection of [`Self::sorted_interior`] over the
/// closed-set lex-axis boundary-partition surface. Every index `i`
/// in the returned vector is the [`Self::index_of`] declaration-slot
/// of some strictly-lex-interior variant `v` in
/// [`Self::sorted_interior`] (`<Self as ClosedSet>::is_sorted_interior(v)
/// == true`, equivalently `<Self as ClosedSet>::is_sorted_interior_index(<Self as ClosedSet>::sorted_index_of(v))
/// == true`), so `i` names neither the decl slot of
/// [`Self::sorted_first`] nor the decl slot of [`Self::sorted_last`];
/// the lex order of [`Self::sorted_interior`] is preserved verbatim
/// (the returned vector's entries are ORDERED by lex position but
/// each entry carries the DECLARATION slot the variant sits at in
/// [`Self::ALL`], not the lex slot — the same `usize` carrier
/// [`Self::interior_indices`] returns one ordering axis over).
///
/// CLOSES the (`Vec<usize>` decl-slot collection) return-shape row
/// on the (return-shape × ordering) 3×2 interior-aggregation matrix
/// at its (`Vec<usize>`, lex) corner peer to
/// [`Self::interior_indices`]'s (`Vec<usize>`, decl) corner one
/// ordering axis over. Sibling posture to
/// [`Self::sorted_interior_labels`] one return-shape axis over on
/// the (`Vec<Self>`, `Vec<&'static str>`, `Vec<usize>`) return-shape
/// partition of the closed-set lex-axis interior-aggregation surface
/// — [`Self::sorted_interior`] materializes each strictly-lex-
/// interior slot as `Self`, [`Self::sorted_interior_labels`] labels
/// each slot under [`Self::label`], this method projects each slot
/// onto its declaration-order `usize` position through
/// [`Self::index_of`]. All three walk the SAME (lex-endpoint-
/// stripped variant sequence) primitive and MUST agree slot-for-slot
/// on the underlying (variant → decl slot, variant → canonical
/// label, variant → variant) three-way projection triangle over the
/// strictly-lex-interior partition.
///
/// The (return-shape × ordering × partition-flavor) 3×2×2 cube over
/// the closed-set aggregation surface post-lift:
///
/// | Return-shape | Full-set decl | Full-set lex | Interior decl | Interior lex |
/// |--------------------------|--------------------|-------------------|---------------------|---------------------|
/// | `Vec<Self>` | (implicit `ALL`) | [`Self::sorted_variants`] | [`Self::interior`] | [`Self::sorted_interior`] |
/// | `Vec<&'static str>` | [`Self::labels`] | [`Self::sorted_labels`] | [`Self::interior_labels`] | [`Self::sorted_interior_labels`] |
/// | `Vec<usize>` | (implicit `0..CARDINALITY`) | (implicit `sorted_indices()` — pending) | [`Self::interior_indices`] | this method |
///
/// The (`Vec<usize>`, interior) row now closes at BOTH ordering
/// columns; the (`Vec<usize>`, full-set) row remains implicit at
/// both columns awaiting a future
/// [`Self::indices`] / [`Self::sorted_indices`] pair (a low-priority
/// lift — full-set `usize` collections are trivially derivable from
/// `T::CARDINALITY` alone at every callsite whereas the boundary-
/// partition-stripped interior variant needs the boundary predicate
/// composed in).
///
/// Default body composes [`Self::sorted_interior`] with
/// `.into_iter()` + `.map(Self::index_of)` verbatim — the strictly-
/// lex-interior decl-slot collection is a typed CONSEQUENCE of the
/// lex-boundary-partition predicate composed with the per-slot
/// decl-index projection, not a fourth codepath through inline
/// slice arithmetic
/// `T::sorted_variants().into_iter().enumerate().filter(|(li, _)| T::is_sorted_interior_index(li)).map(|(_, v)| T::index_of(v)).collect()`
/// (which re-derives the lex-endpoint-position literals at every
/// callsite AND drifts silently when a future implementor overrides
/// [`Self::is_sorted_interior_index`] to route through a divergent
/// lex-boundary primitive). Implementors override only when the
/// strictly-lex-interior decl-slot collection needs to diverge from
/// the natural `sorted_interior().into_iter().map(index_of).collect()`
/// shape — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl. An
/// implementor that overrides [`Self::is_sorted_interior`] (or the
/// [`Self::is_sorted_endpoint`] / [`Self::is_sorted_first`] /
/// [`Self::is_sorted_last`] scalars it funnels through) propagates
/// the override through [`Self::sorted_interior`] to this default
/// body automatically; the (variant → strictly-lex-interior decl-
/// slot collection) projection funnels through ONE typed predicate
/// on the filter column AND through [`Self::index_of`] on the
/// projection column.
///
/// Singleton degeneracy — for a closed set with
/// `T::CARDINALITY == 1`, [`Self::sorted_interior`] returns the
/// empty vector, so this method returns `[]`. Two-variant degeneracy
/// — for `T::CARDINALITY == 2`, [`Self::sorted_interior`] returns
/// `[]` (both slots are lex endpoints), so this method returns `[]`.
/// The strictly-lex-interior decl-slot collection has strictly
/// `CARDINALITY - 2` elements for `CARDINALITY >= 2` and `0`
/// elements at the singleton edge, matching
/// [`Self::sorted_interior`]'s cardinality profile one return-shape
/// axis over.
///
/// DIVERGENCE FROM [`Self::interior_indices`]: on any closed set
/// whose declaration order matches lex order the two methods return
/// the same slot list (`StubKind`'s canonical labels `("alpha",
/// "beta", "gamma")` sort-in-place at every position, so
/// `T::interior_indices() == T::sorted_interior_indices() == [1]`).
/// On any closed set whose declaration order DIVERGES from lex order
/// the two methods return different slot lists — the (`decl slots
/// filtered through the decl-order boundary`) collection under
/// [`Self::interior_indices`] is not the same as the (`decl slots
/// filtered through the lex-order boundary`) collection under this
/// method. Consumers that want the alphabetized interior slot list
/// (an alphabetized interior-only completion bar keyed on decl slots,
/// a `tatara-check` per-slot metrics counter that iterates the
/// canonical-label-sorted strictly-interior slots to key its counter
/// table, a deterministic-across-machines interior-only bitset
/// renderer whose alphabetized ordering must not depend on
/// [`Self::ALL`]'s declaration order) bind THIS method; consumers
/// that want the declaration-order interior slot list (a bounded
/// interior loop keyed on decl slots that must iterate variants in
/// their canonical declaration order) bind [`Self::interior_indices`].
///
/// Future consumers — a bounded lex-interior loop that iterates over
/// `T::sorted_interior_indices()` to key per-slot data structures
/// that hold entries ONLY for strictly-lex-interior slots (an
/// alphabetized interior-observed-slot renderer that sets bit `i`
/// per observed strictly-lex-interior slot in the ORDER `i` sits at
/// on the lex axis, a per-slot metrics counter table `[u64;
/// T::CARDINALITY]` that zeroes both lex endpoints and increments
/// the lex-interior slots per sample in lex-order arrival, a
/// deterministic-across-machines interior-only Prometheus tag whose
/// alphabetized rendering key routes through the strictly-lex-
/// interior decl-slot list), a range-based coherence probe that
/// asserts every observed decl-slot sits in
/// `T::sorted_interior_indices()` before crediting the observation
/// to the lex-interior arm of a boundary-flavored fold, a
/// `tatara-check` per-slot per-label diagnostic that renders
/// `<label>: <count>` for the strictly-lex-interior slots in
/// alphabetized order — bind to ONE trait method instead of
/// hand-rolling either
/// `T::sorted_interior().into_iter().map(T::index_of).collect()`
/// (which re-derives the same two-primitive composition at every
/// callsite) OR the inline enumeration-based composition that
/// re-derives the underlying lex-boundary-partition predicate at
/// every callsite AND drifts silently when a future implementor
/// overrides [`Self::sorted_interior`] to route through a divergent
/// lex-boundary primitive.
///
/// The strictly-lex-interior decl-slot collection contract —
/// `T::sorted_interior_indices() == T::sorted_interior().into_iter().map(T::index_of).collect()`
/// on every implementor — is guaranteed by the default composition
/// through [`Self::sorted_interior`] + [`Self::index_of`]; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (95) pins the composition against the natural
/// `sorted_interior().into_iter().map(index_of).collect()` shape on
/// every implementor so a passing well-formedness sweep means every
/// generic consumer can call `sorted_interior_indices` on any typed
/// carrier and expect the same `Vec<usize>` answer at every crate
/// boundary.
///
/// THEORY.md §III — the typescape; the (strictly-lex-interior
/// partition → decl-slot collection) `Vec<usize>` projection becomes
/// a TYPE projection on the trait rather than a per-consumer inline
/// `T::sorted_interior().into_iter().map(T::index_of).collect()`
/// two-primitive composition at every downstream lex-interior-decl-
/// slot lookup site. The (return-shape × ordering) 3×2 interior-
/// aggregation matrix CLOSES its sixth corner at the (`Vec<usize>`,
/// lex) slot alongside the five pre-existing corners.
/// THEORY.md §V.1 — knowable platform; the (strictly-lex-interior
/// decl-slot collection) projection was an unnamed compound of
/// [`Self::sorted_interior`] + `.map(Self::index_of).collect()`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not ONE lex-interior-decl-slot-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of [`Self::sorted_interior`] +
/// [`Self::index_of`] rather than as a per-implementor
/// `const SORTED_INTERIOR_INDICES: [usize; N - 2]` declaration
/// that silently drifts from [`Self::ALL`] on any reordering or
/// when a hand-rolled [`Self::is_sorted_interior`] override carves
/// a different strictly-lex-interior partition.
///
/// Frontier inspiration: Racket's `(enum-indices/lex-interior enum)`
/// on a closed enum projects the lex-interior partition directly
/// onto its declaration-order slot list, complementary to
/// `(enum-indices/interior enum)` that emits the declaration-
/// interior slot list. MLIR's
/// `mlir::OperationName::sorted_interior_op_indices()` on the
/// registered-op enumeration (the alphabetized boundary-stripped
/// operation collection's index projection). Translation through
/// pleme-io primitives: a pure default method composing the trait's
/// existing [`Self::sorted_interior`] + [`Self::index_of`] surfaces
/// — no new dep, no new IR layer, no supertrait bound, no per-
/// implementor allocation beyond the natural `Vec<usize>` collection
/// the sibling [`Self::interior_indices`] surface already routes one
/// ordering axis over.
fn sorted_interior_indices() -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_interior()
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// Recover the canonical [`Self::label`] at declaration-order
/// position `i` in [`Self::ALL`], or [`None`] if
/// `i >= Self::CARDINALITY`.
///
/// The direct `(usize → &'static str)` projection through the
/// closed set — the missing corner of the (input carrier ×
/// return-projection) 3-of-4 matrix formed by the three
/// pre-existing (variant, `&str` label, `usize` index) inbound-
/// projection surfaces on the trait:
///
/// | Input carrier | Output projection | Projection surface |
/// |------------------|------------------------|---------------------------|
/// | typed variant | `&'static str` label | [`Self::label`] |
/// | typed variant | `usize` index | [`Self::index_of`] |
/// | `usize` index | typed variant | [`Self::from_index`] |
/// | `usize` index | `&'static str` label | [`Self::label_at`] |
///
/// Together with [`Self::label`], [`Self::index_of`], and
/// [`Self::from_index`], this method closes the projection
/// triangle over the three closed-set carriers (typed variant,
/// `&'static str` canonical label, `usize` declaration-order
/// index) with a direct surface at every (input, output) pair.
/// Every projection through the closed set — variant → label,
/// variant → index, index → variant, and index → label — binds
/// to ONE trait method rather than routing through a two-step
/// composition at the call site.
///
/// Sibling posture to [`Self::from_index`] one axis over on the
/// (return-projection) axis of the `usize`-carrier partition:
/// [`Self::from_index`] projects a `usize` position onto its
/// typed variant through direct [`Self::ALL`] slice indexing,
/// this method projects the same `usize` position through to the
/// typed variant's canonical [`Self::label`] rendering — one
/// composition step further along the same axis. Both return an
/// [`Option`] because the input carrier is wider than the closed
/// set — every out-of-range `usize` decodes to [`None`] on both
/// projections, and both agree on the (in-range accept,
/// out-of-range reject) partition slot-for-slot by construction
/// (this method's default body is [`Self::from_index`] composed
/// with [`Self::label`], so any consumer that decodes through
/// this method sees the SAME `Option`-typed rejection arm every
/// other index-carrier decoder sees).
///
/// Default body composes [`Self::from_index`] with
/// [`Self::label`] verbatim — the `usize → &'static str` shape
/// is a typed CONSEQUENCE of the two pre-existing primitives, not
/// a third codepath. Implementors override only when the
/// composition needs to diverge from the natural
/// `from_index(i).map(label)` shape (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `sorted_labels` /
/// `sorted_variants` / `from_index` / `index_of` overrides exist —
/// a typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl). An implementor
/// that overrides [`Self::from_index`] propagates the override
/// through this default body to the direct-label projection
/// automatically; the (typed variant, `&'static str` label,
/// `usize` index) projection triangle funnels every `usize`-
/// carrier decode through ONE typed primitive on each of its
/// (variant, label) return-projection columns.
///
/// The bounded-index contract — the out-of-range arm returns
/// [`None`] for every `i >= Self::CARDINALITY` — is guaranteed by
/// the default composition through [`Self::from_index`]'s
/// `<[T]>::get` slice-bounded projection; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (20)
/// pins the both-directions equality against the natural
/// composition on every implementor, so a passing well-formedness
/// sweep means every generic consumer can call `label_at` on any
/// `usize` payload and expect the same `Option`-typed answer at
/// every crate boundary.
///
/// Future consumers — a compact wire-format decoder that emits
/// `variant.index_of() as u8` and later renders
/// `label_at(byte as usize)` for a diagnostic without materializing
/// the typed variant AT ALL (the natural `Option`-typed rejection
/// arm covers out-of-range serialized indices), a metrics tagger
/// that stores per-slot counter payloads under
/// `metrics[variant.index_of()]` and later renders per-slot
/// diagnostics `<label_at(slot)>: <count>` in declaration order
/// without a re-decode through [`Self::from_index`] +
/// [`Self::label`] at each rendering site, a `tatara-check`
/// per-slot diagnostic that walks `0..T::CARDINALITY` and renders
/// each slot's canonical label without carrying the typed
/// variant, a bitset-observed-variant renderer that walks the set
/// bits and renders each slot's label directly without a
/// [`Self::from_index`]-then-[`Self::label`] two-step at each set
/// bit — bind to ONE trait method instead of hand-rolling either
/// `T::from_index(i).map(|v| v.label())` (which re-derives the
/// same two-primitive composition at every callsite AND makes
/// every downstream site depend on [`Self::from_index`]'s
/// `Option`-typed dispatch shape) OR the inline
/// `T::ALL.get(i).copied().map(|v| v.label())` (which re-derives
/// the underlying three-primitive composition at every callsite)
/// at each callsite, and the closed-set `(usize → label)` direct
/// projection surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (`usize` array index →
/// `&'static str` label) projection becomes a TYPE projection on
/// the trait rather than a per-consumer inline
/// `Self::from_index(i).map(|v| v.label())` composition at every
/// downstream index-decode site. The (typed variant, `&'static str`
/// label, `usize` index) projection triangle over the closed-set
/// carriers gains its fourth direct edge — every (input, output)
/// pair over the three carriers binds to ONE typed projection
/// surface with no two-step composition at the call site.
/// THEORY.md §V.1 — knowable platform; the (`usize` → `&'static str`)
/// direct projection was an unnamed compound of [`Self::from_index`]
/// composed with [`Self::label`] pre-lift; naming it on the trait
/// makes the projection a TYPED CONSEQUENCE of the two substrate
/// primitives — generic consumers see ONE method, not ONE
/// index-to-label-shape-per-crate. The well-formedness clause (20) pins the composition
/// against the natural `from_index(i).map(label)` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call `label_at` on any `usize` payload and
/// expect the same `Option`-typed answer at every crate boundary.
/// THEORY.md §VI.1 — generation over composition; the direct
/// (`usize → label`) projection emerges from the composition of
/// TWO substrate primitives ([`Self::from_index`], [`Self::label`])
/// rather than as a per-implementor inline
/// `from_index(i).map(label)` compound. A future tightening of
/// either primitive (a future perfect-hash `from_index`, a future
/// canonicalization-aware `label` projection that folds case /
/// whitespace, a future const-fn `label` axis that makes the
/// projection compile-time visible) propagates to every closed-set
/// direct-label-projection consumer through ONE trait body.
///
/// Frontier inspiration: Idris's `Fin n` finite-cardinality type
/// with a canonical `showFin : Fin n -> String` projection — the
/// direct (position → rendered label) surface emits as a single
/// typed method on the finite-type universe rather than per-
/// instance inline `showFin (fromNat i)` composition. MLIR's
/// `mlir::OpBuilder::getOperationName(index)` on the Op registry
/// composes the (index → op) lookup with the (op → name)
/// projection into ONE direct `(index → name)` surface the
/// DiagnosticEngine renders per-slot diagnostics against. Racket's
/// `(enum-label enum i)` on a closed enum projects a declaration-
/// order position onto its rendered canonical label directly.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::from_index`] +
/// [`Self::label`] surfaces — no new dep, no new IR layer, no
/// supertrait bound, no allocation.
fn label_at(i: usize) -> Option<&'static str> {
<Self as ClosedSet>::from_index(i).map(<Self as ClosedSet>::label)
}
/// Recover the declaration-order `usize` position in [`Self::ALL`]
/// of the variant labelled `s`, or [`None`] if `s` matches no
/// variant's [`Self::label`].
///
/// The direct `(&str → usize)` projection through the closed set —
/// the missing corner of the (input carrier × return-projection)
/// 5-of-6 matrix that clause (20)'s `label_at` addition left open
/// on the projection triangle over the three closed-set carriers
/// (typed variant, `&'static str` canonical label, `usize`
/// declaration-order index):
///
/// | Input carrier | Output projection | Projection surface |
/// |------------------------|------------------------|------------------------------|
/// | typed variant | `&'static str` label | [`Self::label`] |
/// | typed variant | `usize` index | [`Self::index_of`] |
/// | `usize` index | typed variant | [`Self::from_index`] |
/// | `usize` index | `&'static str` label | [`Self::label_at`] |
/// | `&'static str` label | typed variant | [`Self::find_by_label`] |
/// | `&'static str` label | `usize` index | [`Self::index_of_label`] |
///
/// Together with [`Self::label`], [`Self::index_of`],
/// [`Self::from_index`], [`Self::label_at`], and
/// [`Self::find_by_label`], this method closes the projection
/// triangle over the three closed-set carriers with a direct
/// surface at EVERY (input, output) pair — the six directed edges
/// spanning the three carriers each bind to ONE trait method
/// rather than routing through a two-step composition at the call
/// site. Every projection through the closed set — variant →
/// label, variant → index, index → variant, index → label, label →
/// variant, label → index — emits at ONE typed primitive.
///
/// Sibling posture to [`Self::find_by_label`] one axis over on the
/// (return-projection) axis of the `&'static str`-carrier
/// partition: [`Self::find_by_label`] projects a `&str` label back
/// onto its typed variant through the [`Self::ALL`] ×
/// [`Self::label`] sweep, this method projects the same `&str`
/// label through to its declaration-order `usize` position — one
/// composition step further along the same axis. Both return an
/// [`Option`] because the input carrier is wider than the closed
/// set — every non-canonical `&str` decodes to [`None`] on both
/// projections, and both agree on the (in-range accept,
/// out-of-range reject) partition slot-for-slot by construction
/// (this method's default body is [`Self::find_by_label`] composed
/// with [`Self::index_of`], so any consumer that decodes through
/// this method sees the SAME `Option`-typed rejection arm every
/// other `&str`-carrier decoder sees).
///
/// Sibling posture to [`Self::label_at`] one axis over on the
/// (input-carrier) axis of the projection triangle: [`Self::label_at`]
/// closes the `usize`-carrier direct-label projection, this method
/// closes the `&str`-carrier direct-index projection — both are
/// the "one composition step further" corner past the immediate
/// carrier decode ([`Self::from_index`] / [`Self::find_by_label`]),
/// projecting through to the OTHER return-projection column that
/// the same carrier partition exposes. Together the two direct
/// projections close the (carrier × further-column) 2×2 matrix
/// past the two immediate decoders on both carrier partitions.
///
/// Default body composes [`Self::find_by_label`] with
/// [`Self::index_of`] verbatim — the `&str → usize` shape is a
/// typed CONSEQUENCE of the two pre-existing primitives, not a
/// third codepath. Implementors override only when the composition
/// needs to diverge from the natural `find_by_label(s).map(index_of)`
/// shape (no production implementor reaches for this today; the
/// axis exists for the same reason `via` / `set_label` / `labels` /
/// `sorted_labels` / `sorted_variants` / `from_index` / `index_of` /
/// `label_at` overrides exist — a typed escape hatch the trait
/// surface exposes rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::find_by_label`] (a future perfect-hash label-decoder, a
/// future canonicalization-aware label projection that folds case
/// or whitespace) propagates the override through this default
/// body to the direct-index projection automatically; the
/// projection triangle funnels every `&str`-carrier decode through
/// ONE typed primitive on each of its (variant, `usize` index)
/// return-projection columns.
///
/// The rejection contract — a non-canonical `&str` returns
/// [`None`], the empty-string boundary that clause (4) reserves as
/// structurally outside the closed set returns [`None`] — is
/// guaranteed by the default composition through
/// [`Self::find_by_label`]'s `Option`-typed sweep; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (21) pins the both-directions equality against the
/// natural composition on every implementor, so a passing
/// well-formedness sweep means every generic consumer can call
/// `index_of_label` on any `&str` payload and expect the same
/// `Option`-typed answer at every crate boundary.
///
/// Future consumers — a compact wire-format encoder that reads a
/// `&str` config value (a Kubernetes annotation, a YAML enum
/// field, a diagnostic input string) and emits its declaration-
/// order position directly as a `u8` without materializing the
/// typed variant at the encoder site, a metrics binner that reads
/// a diagnostic label from an incoming trace event and increments
/// `counters[T::index_of_label(label)?]` under the per-slot
/// aggregation shape without a two-step (`find_by_label` →
/// `index_of`) composition at each rendering site, a `tatara-check`
/// per-slot per-label diagnostic that partitions a batch of
/// incoming labels by declaration-order slot for reporting under
/// the natural `[per_slot; T::CARDINALITY]` aggregation shape, an
/// LSP-hover / config-decoder rendering that maps parsed labels
/// back to their canonical slot ordering for stable rendering —
/// bind to ONE trait method instead of hand-rolling either
/// `T::find_by_label(s).map(T::index_of)` (which re-derives the
/// same two-primitive composition at every callsite AND makes
/// every downstream site depend on [`Self::find_by_label`]'s
/// `Option`-typed dispatch shape) OR the inline
/// `T::ALL.iter().position(|v| v.label() == s)` (which re-derives
/// the underlying three-primitive composition at every callsite,
/// AND drops the [`Self::find_by_label`] override propagation that
/// keeps every carrier-decode consumer aligned on a single typed
/// dispatch) at each callsite, and the closed-set `(&str → index)`
/// direct projection surface evolves at ONE site rather than
/// per-consumer.
///
/// THEORY.md §III — the typescape; the (`&'static str` label →
/// `usize` array index) projection becomes a TYPE projection on
/// the trait rather than a per-consumer inline
/// `Self::find_by_label(s).map(Self::index_of)` composition at
/// every downstream label-to-slot site. The projection triangle
/// over the closed-set carriers gains its sixth (and final)
/// direct edge — every (input, output) pair across the (typed
/// variant, `&'static str` label, `usize` index) carriers binds
/// to ONE typed projection surface with no two-step composition
/// at the call site.
/// THEORY.md §V.1 — knowable platform; the (`&str` → `usize`)
/// direct projection was an unnamed compound of
/// [`Self::find_by_label`] composed with [`Self::index_of`]
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not ONE label-to-index-shape-per-crate.
/// The well-formedness clause (21) pins the composition against
/// the natural `find_by_label(s).map(index_of)` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call `index_of_label` on any `&str`
/// payload and expect the same `Option`-typed answer at every
/// crate boundary.
/// THEORY.md §VI.1 — generation over composition; the direct
/// (`&str → index`) projection emerges from the composition of
/// TWO substrate primitives ([`Self::find_by_label`],
/// [`Self::index_of`]) rather than as a per-implementor inline
/// `find_by_label(s).map(index_of)` compound. A future tightening
/// of either primitive (a future perfect-hash `find_by_label`, a
/// future canonicalization-aware label projection that folds
/// case / whitespace, a future const-fn `index_of` axis that
/// makes the projection compile-time visible) propagates to
/// every closed-set direct-index-projection consumer through ONE
/// trait body.
///
/// Frontier inspiration: Racket's `(enum-index enum sym)` on a
/// closed enum projects a symbol directly onto its
/// declaration-order position, without an intermediate typed-
/// variant materialization the caller must round-trip through.
/// MLIR's `mlir::TypeID::getIndex(StringRef name)` on the typed
/// registry composes the (name → op) lookup with the (op →
/// stable index) projection into ONE direct `(name → index)`
/// surface the DiagnosticEngine's per-op counters key off.
/// Clojure's `(.indexOf enum-values kw)` idiom over a keyword-
/// enum's canonical value set stands as the same shape one
/// vocabulary over on the JVM-Lisp side. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::find_by_label`] + [`Self::index_of`]
/// surfaces — no new dep, no new IR layer, no supertrait bound,
/// no allocation.
fn index_of_label(s: &str) -> Option<usize> {
<Self as ClosedSet>::find_by_label(s).map(<Self as ClosedSet>::index_of)
}
/// Allocating-carrier structured decode of `s` into a declaration-
/// order [`Self::ALL`] index — `Ok(idx)` when `s` matches some
/// `v.label()` exactly (where `idx == v.index_of()`), and
/// `Err(Self::make_unknown(s))` for every other string.
///
/// The allocating-carrier sibling of [`Self::index_of_label`] on
/// the (side-effect on reject) axis of the (`&str → usize`
/// declaration-order projection) surface — where
/// [`Self::index_of_label`] returns [`None`] on rejection without
/// entering [`Self::make_unknown`], this method materializes the
/// typed [`Self::Unknown`] carrier owning a [`String`] copy of `s`
/// so a downstream structured-diagnostic renderer can bind the
/// substrate-wide `unknown {SET_LABEL}: {input}` shape onto the
/// same reject path a `parse_label`-shaped decoder threads. The
/// (`&str → usize` decl) direct-projection surface completes at
/// BOTH ends of the (side-effect) axis, matching the shape
/// [`Self::parse_label`] / [`Self::find_by_label`] pin one
/// return-type column over on the (`&str → Self`) direct-decode
/// surface.
///
/// Sibling posture to [`Self::parse_label`] one return-type-axis
/// over on the (`&str → X` allocating carrier decode) surface:
/// [`Self::parse_label`] projects a `&str` label onto its typed
/// variant through the [`Self::ALL`] × [`Self::label`] sweep AND
/// threads the typed [`Self::Unknown`] carrier on rejection, this
/// method projects the same `&str` label through to its
/// declaration-order `usize` slot AND threads the SAME
/// [`Self::Unknown`] carrier on rejection — one composition step
/// further along the same allocating-carrier axis. Both return a
/// [`Result`] with the SAME [`Self::Unknown`] carrier shape on
/// rejection because the default composition threads
/// [`Self::parse_label`]'s `Err(unknown)` arm through
/// [`Result::map`] on the Ok column, so any consumer that decodes
/// through this method sees the SAME [`Self::Unknown`]-typed
/// rejection arm every `parse_label`-shaped `&str`-carrier
/// decoder sees.
///
/// The (return-type × side-effect × ordering) partition of the
/// closed-set direct-decode surface post-lift:
///
/// | Return \ Side-effect on reject | Allocating (materialize `Unknown`) | Non-allocating (`None` / `Option`) |
/// |------------------------------------|--------------------------------------------|---------------------------------------|
/// | `Self` | [`Self::parse_label`] | [`Self::find_by_label`] |
/// | `usize` (declaration-order) | [`Self::parse_index_of_label`] | [`Self::index_of_label`] |
/// | `usize` (lexicographic-order) | — | [`Self::sorted_index_of_label`] |
/// | `bool` | — | [`Self::contains_label`] |
///
/// Default body composes [`Self::parse_label`] with
/// [`Self::index_of`] on the Ok arm — the allocating-carrier
/// direct-index decode is a typed CONSEQUENCE of the two
/// pre-existing primitives, not a third codepath. Implementors
/// override only when the composition needs to diverge (no
/// production implementor reaches for this today; the axis exists
/// for the same reason [`Self::parse_label`] /
/// [`Self::find_by_label`] / [`Self::index_of_label`] /
/// [`Self::index_of`] overrides exist — a typed escape hatch the
/// trait surface exposes rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::parse_label`] (a future perfect-hash carrier decoder, a
/// future canonicalization-aware label projection that folds case
/// or whitespace on the parse-arm) propagates the override through
/// this default body to the direct-index decode automatically;
/// the (`&str → usize`) allocating-carrier decode funnels every
/// sweep through ONE typed primitive on each of its (accept,
/// reject) partition arms.
///
/// The (accept, reject) alignment with [`Self::parse_label`] — the
/// two methods MUST agree on membership at every `&str` payload
/// (both accept the same inputs, both reject the same inputs,
/// both surface the SAME [`Self::Unknown`] carrier shape on
/// rejection) — is guaranteed by the default composition and
/// pinned by the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (84) on every
/// implementor, so a passing well-formedness sweep means every
/// generic consumer can call `parse_index_of_label` on any `&str`
/// payload and expect the same `Result`-typed answer at every
/// crate boundary AND the SAME [`Self::Unknown`] carrier variant
/// on rejection as [`Self::parse_label`] surfaces.
///
/// Future consumers — a compact wire-format decoder that reads a
/// `&str` config value (a Kubernetes annotation, a YAML enum
/// field, a diagnostic input string) and emits its declaration-
/// order position directly as a `u8` AND (on miss) surfaces the
/// substrate-wide `unknown {SET_LABEL}: {input}` diagnostic
/// without a two-step `parse_label + index_of` composition at
/// the decoder site, a `?`-operator-chained kwarg decoder that
/// projects a `&str` field payload directly onto its declaration-
/// order slot for a per-slot lookup table AND propagates the
/// natural `?`-friendly [`Self::Unknown`] carrier on rejection,
/// a `serde::Deserialize`-shaped visitor that decodes a `&str`
/// enum wire-form onto its per-slot storage AND emits the
/// substrate-wide carrier through the visitor's `Error` type on
/// unknown-variant rejection, an LSP config-diagnostic renderer
/// that maps parsed labels back to their canonical declaration-
/// order slot for stable per-slot rendering AND surfaces the
/// same substrate-wide `unknown {SET_LABEL}: {input}` phrase on
/// miss — bind to ONE trait method instead of hand-rolling either
/// `T::parse_label(s).map(T::index_of)` (which re-derives the
/// same two-primitive composition at every callsite AND makes
/// every downstream site depend on [`Self::parse_label`]'s
/// `Result`-typed dispatch shape) OR the inline
/// `T::ALL.iter().position(|v| v.label() == s)
/// .ok_or_else(|| T::make_unknown(s))` (which re-derives the
/// underlying three-primitive composition at every callsite AND
/// drops the [`Self::parse_label`] override propagation that
/// keeps every allocating-carrier decode consumer aligned on a
/// single typed dispatch) at each callsite, and the closed-set
/// (`&str → usize` allocating-carrier decl-order decode) surface
/// evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the allocating-carrier
/// (`&str → usize` decl) decode becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `Self::parse_label(s).map(Self::index_of)` composition at
/// every downstream label-to-slot-with-carrier site. The
/// (return-type × side-effect × ordering) partition of the
/// closed-set direct-decode surface completes at the
/// (`usize`-decl, allocating-carrier) corner — the direct-index
/// projection column at BOTH ends of the (side-effect) axis now
/// binds to a typed primitive, matching the shape
/// [`Self::parse_label`] / [`Self::find_by_label`] pin one
/// return-type column over.
/// THEORY.md §V.1 — knowable platform; the allocating-carrier
/// (`&str → usize` decl) decode was an unnamed compound of
/// [`Self::parse_label`] + [`Self::index_of`] pre-lift. Naming
/// it on the trait makes the projection a TYPED CONSEQUENCE of
/// the two substrate primitives — generic consumers see ONE
/// method, not ONE parse-index-decode-shape-per-crate. Clause
/// (84) pins the composition against the natural
/// `parse_label(s).map(index_of)` shape on every implementor so
/// a passing well-formedness sweep means every generic consumer
/// can call `parse_index_of_label` on any `&str` payload and
/// expect the same `Result`-typed answer at every crate boundary.
/// THEORY.md §VI.1 — generation over composition; the
/// allocating-carrier direct-decl-decode emerges from the
/// composition of TWO substrate primitives ([`Self::parse_label`],
/// [`Self::index_of`]) rather than as a per-implementor inline
/// `parse_label(s).map(index_of)` compound. A future tightening
/// of either primitive (a future perfect-hash `parse_label`, a
/// future canonicalization-aware label projection that folds
/// case / whitespace on the parse-arm, a future const-fn
/// `index_of` axis that makes the projection callable in const
/// contexts) propagates to every closed-set allocating-carrier
/// direct-decl-decode consumer through ONE trait body.
///
/// Frontier inspiration: rustc's `Symbol::intern` composed with a
/// symbol-table index projection — the typed-symbol lookup with a
/// substrate-wide interned-string carrier on rejection composed
/// with the stable per-symbol slot projection, all through ONE
/// call the diagnostic engine binds to. MLIR's
/// `RegisteredOperationName::lookup(StringRef)` composed with
/// `getStableIndex()` on the typed op registry composes the
/// (name → registered op) allocating-carrier lookup with the (op
/// → stable index) projection into ONE direct
/// (`name → registered index`) surface the DiagnosticEngine's
/// per-op counters key off. Racket's `(hash-ref/failure enum sym
/// make-unknown)` composed with `(enum-index enum sym)` on a
/// closed enum stands as the same shape one vocabulary over on
/// the Lisp-VM side. Translation through pleme-io primitives: a
/// pure default method composing the trait's existing
/// [`Self::parse_label`] + [`Self::index_of`] surfaces — no new
/// dep, no new IR layer, no supertrait bound.
fn parse_index_of_label(s: &str) -> Result<usize, Self::Unknown> {
<Self as ClosedSet>::parse_label(s).map(<Self as ClosedSet>::index_of)
}
/// The (hint) sibling of [`Self::index_of_label`] — the zero-
/// allocation structured decode of `s` into a declaration-order
/// index, threading a typed [`Self::suggest_closest`] hint into the
/// rejection envelope. Peer of [`Self::find_by_label_with_hint`]
/// on the (`usize`-typed direct projection) axis of the closed-set
/// structured-decode surface: where [`Self::find_by_label_with_hint`]
/// returns the typed variant on match, this method projects that
/// variant through [`Self::index_of`] so the caller gets the
/// declaration-order slot directly.
///
/// On exact match returns `Ok(idx)` where `idx == v.index_of()` for
/// the canonical variant `v` bound to label `s`. On miss returns
/// `Err(hint)` where `hint` is the typed variant
/// [`Self::suggest_closest`] keys on — `Some(v)` when a canonical
/// label sits within the substrate-wide bounded edit distance,
/// `None` when no candidate qualifies (the conservative-suggestion
/// contract — silent over guessing).
///
/// The hint slot carries the TYPED VARIANT rather than its
/// declaration-order slot so a downstream diagnostic renderer can
/// freely project the hint through [`Self::label`] for a
/// `did you mean 'foo'?` message, through [`Self::index_of`] for
/// the near-miss's declaration slot, OR through
/// [`Self::sorted_index_of`] for the near-miss's lex slot — one
/// zero-allocation structured decode surfaces every consumer's
/// downstream projection without paying the
/// [`Self::make_unknown`] carrier allocation
/// [`Self::parse_label_with_hint`] threads on the same reject
/// path. Matches the (hint = typed variant) shape
/// [`Self::find_by_label_with_hint`] pins one axis over on the
/// (`Self`-typed direct decode) column.
///
/// Peer of [`Self::find_by_label_with_hint`] on the (return-type)
/// axis of the structured-decode surface — that method returns the
/// typed variant, this method returns its declaration-order slot.
/// Sibling of [`Self::index_of_label`] on the (hint) axis of the
/// (`&str → usize`) direct-index projection surface. Together with
/// the four sibling methods on the closed-set structured-decode
/// surface, this method closes the (return-type × hint) 2×2 corner
/// on the (`&str → usize` direct projection, with-hint) cell:
///
/// | Return type \ Hint | No hint | With hint |
/// |--------------------|---------------------------|------------------------------------|
/// | `Self` | [`Self::find_by_label`] | [`Self::find_by_label_with_hint`] |
/// | `usize` (decl) | [`Self::index_of_label`] | [`Self::index_of_label_with_hint`] |
///
/// Default body composes [`Self::find_by_label_with_hint`] with
/// [`Self::index_of`] on the Ok arm — the structured index decode
/// is a typed CONSEQUENCE of the two pre-existing primitives, not
/// a third codepath. Implementors override only when the
/// composition needs to diverge (no production implementor reaches
/// for this today; the axis exists for the same reason
/// [`Self::index_of_label`] / [`Self::find_by_label_with_hint`]
/// overrides exist — a typed escape hatch the trait surface
/// exposes rather than forcing the implementor to hand-roll the
/// impl). An implementor that overrides
/// [`Self::find_by_label_with_hint`] OR [`Self::index_of`]
/// propagates the override through this default body
/// automatically; the structured (`&str → usize`) decode with
/// hint funnels every sweep through ONE typed primitive per axis.
///
/// Future consumers — an LSP hover pass that resolves the typed
/// declaration-order slot under the operator's cursor AND (on
/// miss) renders a `did you mean <hint.label()>?` next to a bare
/// rejection WITHOUT paying carrier allocation per non-matching
/// hover; a compact wire-format decoder that reads a `&str` config
/// value and emits either the declaration-order byte directly OR
/// a typed near-miss the operator sees when the field's value is
/// a fuzzy hit
/// (`T::index_of_label_with_hint(cfg).unwrap_or_else(|hint|
/// { emit_hint(hint); T::default_kind().index_of() })`); a
/// `filter_map`-shaped stream projection over cluster-wide
/// `tatara.pleme.io/*` annotation keys that partitions each
/// element into (typed_slot, typed_hint, bare_unrecognized_key)
/// via `index_of_label_with_hint` — bind to ONE trait method
/// instead of hand-rolling the
/// `find_by_label_with_hint(s).map(index_of)` composition at each
/// callsite, and the closed-set zero-allocation structured
/// (`&str → usize`) decode surface evolves at ONE site rather
/// than per-consumer.
///
/// The (accept, reject) alignment with
/// [`Self::find_by_label_with_hint`] — the two methods MUST agree
/// on membership at every `&str` payload (both accept the same
/// inputs, both reject the same inputs, both surface the SAME
/// typed hint variant on rejection) — is guaranteed by the
/// default composition and pinned by the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (82) on every
/// implementor, so a passing well-formedness sweep means every
/// generic consumer can call `index_of_label_with_hint` on any
/// `&str` payload and expect the same `Result`-typed answer at
/// every crate boundary AND the SAME `Option<Self>` hint variant
/// on rejection as [`Self::find_by_label_with_hint`] surfaces.
///
/// THEORY.md §III — the typescape; the structured
/// (`&str → usize` with hint) decode becomes a TYPE projection on
/// the trait rather than a per-consumer inline
/// `find_by_label_with_hint(s).map(index_of)` composition at
/// every downstream label-to-slot-with-hint site. The (return-
/// type × hint) 2×2 matrix partitions the structured direct-
/// decode surface exhaustively into FOUR typed projections, each
/// with a distinct load-bearing consumer surface — `Self`-typed
/// carrier decode on either side of the (hint) axis, `usize`-
/// typed direct decode on either side.
/// THEORY.md §V.1 — knowable platform; the structured
/// (`&str → usize` with hint) decode was an unnamed compound of
/// [`Self::find_by_label_with_hint`] + [`Self::index_of`] pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not ONE structured-index-decode-
/// shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// structured-diagnostic shape emerges from the composition of
/// TWO substrate primitives ([`Self::find_by_label_with_hint`],
/// [`Self::index_of`]) rather than as a per-implementor
/// structured-index-decode impl. A future tightening of either
/// primitive (a future perfect-hash lookup on
/// [`Self::find_by_label_with_hint`], a future const-fn
/// [`Self::index_of`] axis that makes the projection callable in
/// const contexts) propagates to every closed-set structured
/// (`&str → usize` with hint) consumer through ONE trait body.
///
/// Frontier inspiration: rustc's `find_best_match_for_name`
/// composed with `Symbol::intern` composed with a caller-side
/// symbol-table index projection — the typed-symbol lookup with a
/// bounded near-miss adornment slot AND a downstream projection
/// onto a stable per-symbol slot without materializing a
/// diagnostic on miss when the caller supplies a natural
/// fallback. MLIR's `OperationName::dyn_cast<T>` composed with
/// `RegisteredOperationName::getStableIndex()` on miss delivers
/// the same (structured index decode with typed near-miss) shape
/// one vocabulary over on the typed op registry. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::find_by_label_with_hint`] with
/// [`Self::index_of`] — no new primitive, no new dep, no new IR
/// layer, no allocation.
fn index_of_label_with_hint(s: &str) -> Result<usize, Option<Self>> {
<Self as ClosedSet>::find_by_label_with_hint(s).map(<Self as ClosedSet>::index_of)
}
/// Allocating-carrier structured decode of `s` into a declaration-
/// order [`Self::ALL`] index THREADING a typed
/// [`Self::suggest_closest`] hint alongside the substrate-wide
/// [`Self::Unknown`] carrier on the reject arm — the (hint) sibling
/// of [`Self::parse_index_of_label`] one hint-axis over on the
/// (allocating carrier, `&str → usize` decl-order decode) surface
/// AND the (`usize`-typed direct projection) sibling of
/// [`Self::parse_label_with_hint`] one return-type-axis over on the
/// (allocating carrier, with-hint) surface. Where
/// [`Self::parse_index_of_label`] returns
/// `Result<usize, Self::Unknown>` (no hint threading), this method
/// widens the reject arm to `(Self::Unknown, Option<Self>)` so a
/// downstream `?`-operator-chained decoder gets BOTH the substrate-
/// wide `unknown {SET_LABEL}: {input}` carrier AND the typed
/// [`Self::suggest_closest`] near-miss slot through ONE call.
///
/// On exact match returns `Ok(idx)` where `idx == v.index_of()` for
/// the canonical variant `v` bound to label `s` (the hint slot
/// stays absent because [`Self::suggest_closest`] never fires on
/// the accept arm — a successful decode short-circuits before the
/// near-miss projection runs, so the substrate-wide "did you
/// mean …?" surface never double-emits the same variant once as a
/// successful decode and once as a hint). On miss returns
/// `Err((unknown, hint))` where `unknown` is the typed
/// [`Self::Unknown`] carrier owning a [`String`] copy of `s` and
/// rendering the substrate-wide `unknown {SET_LABEL}: {input}`
/// shape through [`Display`](core::fmt::Display) — the SAME
/// carrier shape [`Self::parse_label`] /
/// [`Self::parse_index_of_label`] / [`Self::parse_sorted_index_of_label`]
/// / [`Self::parse_label_with_hint`] emit on the reject path,
/// funnelled through ONE structural rejection variant every
/// `?`-operator-chained decoder / typed-`serde`-error surface /
/// substrate-wide diagnostic pipeline binds to — and `hint` is the
/// typed variant [`Self::suggest_closest`] keys on: `Some(v)` when
/// a canonical label sits within the substrate-wide bounded edit
/// distance, `None` when no candidate qualifies (the
/// conservative-suggestion contract — silent over guessing).
///
/// Peer of [`Self::parse_label_with_hint`] one return-type-axis
/// over on the (allocating carrier, with-hint) surface: both share
/// the SAME `(Self::Unknown, Option<Self>)` reject-arm tuple shape
/// AND the SAME two-primitive-composition body — differing only in
/// whether they surface the accept arm as the typed variant
/// directly ([`Self::parse_label_with_hint`]) OR project it
/// through [`Self::index_of`] onto the declaration-order slot
/// (this method). Peer of [`Self::parse_index_of_label`] one
/// hint-axis over on the (allocating carrier, `&str → usize`
/// decl-order) surface: where [`Self::parse_index_of_label`]
/// rejects with a bare [`Self::Unknown`], this method threads the
/// typed near-miss hint alongside the carrier. Peer of
/// [`Self::index_of_label_with_hint`] one side-effect-axis over on
/// the (`&str → usize` decl-order, with-hint) surface: where
/// [`Self::index_of_label_with_hint`] returns a bare
/// `Result<usize, Option<Self>>` (no carrier allocation on
/// rejection), this method materializes the typed carrier
/// alongside the hint.
///
/// The (side-effect × hint) 2×2 matrix on the (`&str → usize`
/// decl-order) row partitions post-lift:
///
/// | Side-effect on reject | No hint | With hint |
/// |--------------------------------------|----------------------------------|----------------------------------------------|
/// | Allocating (materialize carrier) | [`Self::parse_index_of_label`] | [`Self::parse_index_of_label_with_hint`] |
/// | Non-allocating (bare `Option`/hint) | [`Self::index_of_label`] | [`Self::index_of_label_with_hint`] |
///
/// Default body composes [`Self::parse_label_with_hint`] with
/// [`Self::index_of`] verbatim — the
/// `Result<usize-decl, (Self::Unknown, Option<Self>)>` shape is a
/// typed CONSEQUENCE of the two pre-existing primitives, not a
/// third codepath. [`Result::map`] on the Ok arm threads the
/// `Result<Self, (Self::Unknown, Option<Self>)>` shape
/// [`Self::parse_label_with_hint`] emits through
/// [`Self::index_of`], preserving the reject-arm tuple verbatim,
/// so the (`usize`-typed accept, tuple-typed reject) shape falls
/// out of the composition without a hand-rolled tuple constructor.
/// Implementors override only when the composition needs to
/// diverge (no production implementor reaches for this today; the
/// axis exists for the same reason [`Self::parse_label`] /
/// [`Self::parse_index_of_label`] / [`Self::parse_label_with_hint`]
/// / [`Self::index_of_label_with_hint`] overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::parse_label_with_hint`] OR [`Self::index_of`]
/// (a future perfect-hash carrier-decoder-with-hint, a future
/// canonicalization-aware label projection, a future const-fn
/// [`Self::index_of`] axis) propagates the override through this
/// default body to the allocating-carrier decl-decode with-hint
/// arm automatically; the (`&str → usize` decl-order with carrier
/// AND hint) decode funnels every sweep through ONE typed
/// primitive on each of the (accept, reject) partition arms.
///
/// The (accept, reject) alignment with
/// [`Self::parse_label_with_hint`] — the two methods MUST agree on
/// membership at every `&str` payload (both accept the same
/// inputs, both reject the same inputs, both surface the SAME
/// [`Self::Unknown`] carrier shape on rejection, both surface the
/// SAME `Option<Self>` hint variant on rejection) — is guaranteed
/// by the default composition and pinned by the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (86) on
/// every implementor, so a passing well-formedness sweep means
/// every generic consumer can call `parse_index_of_label_with_hint`
/// on any `&str` payload and expect the same `Result`-typed answer
/// at every crate boundary AND the SAME
/// `(Self::Unknown, Option<Self>)` tuple variant on rejection as
/// [`Self::parse_label_with_hint`] surfaces.
///
/// Future consumers — a `?`-operator-chained config decoder that
/// reads a `&str` field and emits its declaration-order slot
/// directly as a `u8` for a per-slot lookup table AND propagates
/// the natural `?`-friendly [`Self::Unknown`] carrier on rejection
/// AND (through a downstream `map_err(|(_, hint)| hint)` or
/// `inspect_err(|(_, hint)| render_hint(hint))` shim) surfaces the
/// typed near-miss WITHOUT re-running [`Self::suggest_closest`] at
/// the caller; a `serde::Deserialize`-shaped visitor over a `&str`
/// enum wire-form whose typed slot storage is keyed on declaration
/// order AND whose `Error` type carries both the substrate-wide
/// carrier AND the typed near-miss hint; an LSP config-diagnostic
/// renderer that maps parsed labels back to their canonical
/// declaration-order slot for stable per-slot rendering AND
/// surfaces both the same substrate-wide
/// `unknown {SET_LABEL}: {input}` phrase AND a `did you mean
/// <hint.label()>?` next to the bare rejection on the SAME
/// diagnostic frame — bind to ONE trait method instead of
/// hand-rolling either
/// `T::parse_label_with_hint(s).map(T::index_of)` (which re-derives
/// the same two-primitive composition at every callsite AND makes
/// every downstream site depend on
/// [`Self::parse_label_with_hint`]'s tuple-typed reject shape) OR
/// the inline
/// `T::parse_index_of_label(s).map_err(|u| (u, T::suggest_closest(s)))`
/// (which re-derives the underlying three-primitive composition at
/// every callsite AND drops the
/// [`Self::parse_label_with_hint`] override propagation that keeps
/// every allocating-carrier decl-decode with-hint consumer aligned
/// on a single typed dispatch) at each callsite, and the closed-
/// set (`&str → usize` allocating-carrier decl-order decode with
/// hint) surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the allocating-carrier
/// (`&str → usize` decl with hint) decode becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `Self::parse_label_with_hint(s).map(Self::index_of)`
/// composition at every downstream label-to-slot-with-carrier-AND-
/// hint site. The (return-type × side-effect × hint × ordering)
/// 4-axis surface's (`usize`-decl, allocating, with-hint) corner
/// binds at ONE typed method rather than at per-consumer inline
/// `parse_label_with_hint(s).map(index_of)` composition, mirroring
/// clause (7)'s pin one return-type-axis over on the
/// (`Self`-typed, allocating, with-hint) corner.
/// THEORY.md §V.1 — knowable platform; the allocating-carrier
/// (`&str → usize` decl with hint) decode was an unnamed compound
/// of [`Self::parse_label_with_hint`] + [`Self::index_of`] pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not ONE parse-index-decode-with-hint-shape-per-
/// crate. Clause (86) pins the composition against the natural
/// `parse_label_with_hint(s).map(index_of)` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call `parse_index_of_label_with_hint` on
/// any `&str` payload and expect the same `Result`-typed answer at
/// every crate boundary AND the SAME
/// `(Self::Unknown, Option<Self>)` tuple variant on rejection.
/// THEORY.md §VI.1 — generation over composition; the allocating-
/// carrier direct-decl-decode-with-hint emerges from the
/// composition of TWO substrate primitives
/// ([`Self::parse_label_with_hint`], [`Self::index_of`]) rather
/// than as a per-implementor inline
/// `parse_label_with_hint(s).map(index_of)` compound. A future
/// tightening of either primitive (a future perfect-hash
/// `parse_label_with_hint`, a future Damerau-Levenshtein lift on
/// [`Self::suggest_closest`] the composition threads through, a
/// future const-fn [`Self::index_of`] axis that makes the
/// projection callable in const contexts) propagates to every
/// closed-set allocating-carrier direct-decl-decode-with-hint
/// consumer through ONE trait body.
///
/// Frontier inspiration: rustc's `Symbol::intern` composed with
/// `find_best_match_for_name` composed with a symbol-table index
/// projection — the typed-symbol lookup with a substrate-wide
/// interned-string carrier on rejection composed with a bounded
/// near-miss adornment AND a stable per-symbol slot projection,
/// all through ONE call the diagnostic engine binds to. MLIR's
/// `RegisteredOperationName::lookup(StringRef)` composed with
/// `DiagnosticEngine::suggestBestMatch` composed with
/// `getStableIndex()` on the typed op registry gives the same
/// shape one vocabulary over on the C++ side — a bare `lookup`
/// misses, a `suggestBestMatch` sidechannel emits the near-miss,
/// and `getStableIndex()` projects the accept-arm registered op
/// onto its stable slot; this method fuses the three into ONE call
/// through the tuple reject-arm. Racket's `(hash-ref/failure enum
/// sym make-unknown)` composed with `(enum-suggest-closest enum
/// sym)` composed with `(enum-index enum sym)` on a closed enum
/// stands as the same shape one vocabulary over on the Lisp-VM
/// side. Translation through pleme-io primitives: a pure default
/// method composing the trait's existing
/// [`Self::parse_label_with_hint`] + [`Self::index_of`] surfaces —
/// no new dep, no new IR layer, no supertrait bound.
fn parse_index_of_label_with_hint(
s: &str,
) -> ::std::result::Result<usize, (Self::Unknown, ::std::option::Option<Self>)> {
<Self as ClosedSet>::parse_label_with_hint(s).map(<Self as ClosedSet>::index_of)
}
/// The declaration-order-index sibling of [`Self::index_of`] one
/// ordering-axis over — the direct (typed variant → `usize`
/// lexicographic-order index) projection through the closed set,
/// keyed on [`Self::label`] under the standard-library `str: Ord`
/// ordering. Returns the position `v` would occupy in
/// [`Self::sorted_variants`] — equivalently, the count of canonical
/// labels strictly less than [`Self::label`]`(self)` under `str::cmp`.
///
/// Closes the (typed variant → `usize` lexicographic index) forward
/// edge of the (variant, `&'static str` label, `usize` position)
/// projection triangle on the LEX ordering axis — the sibling
/// posture to [`Self::index_of`] one ordering-axis over on the
/// (declaration, lex) partition of the (variant → position)
/// forward-projection surface. Together with [`Self::index_of`], the
/// two methods bracket both ordering axes at the (variant → position)
/// forward edge — every generic consumer that anchors a per-slot
/// data structure on the closed set (a per-slot metrics counter, a
/// lex-sorted diagnostic renderer, a compact wire encoding whose
/// bytes sit in lex order rather than declaration order, a
/// bitset-observed-slot renderer that walks lex-sorted rendering
/// order) binds to the lex-ordering-axis surface at ONE trait
/// method rather than routing through a
/// `sorted_variants().iter().position(|v| v == self)` composition at
/// every callsite.
///
/// The (ordering-axis × forward-projection) partition post-lift:
///
/// | Ordering axis | Forward projection surface |
/// |----------------------|------------------------------|
/// | Declaration order | [`Self::index_of`] |
/// | Lexicographic order | [`Self::sorted_index_of`] |
///
/// Default body is a zero-alloc single-pass linear scan over
/// [`Self::ALL`] keyed on [`Self::label`] — a strict-`<` label
/// comparison against `self`'s canonical label counted through the
/// entire slice. The count equals the lex-order position by clause
/// (3)'s label-pairwise-distinctness contract: no two canonical
/// labels can be equal, so `str: Ord`'s total order on the labels
/// projects bijectively onto `0..T::CARDINALITY`, and the count of
/// strictly-lesser labels is the unique lex-order slot. Implementors
/// override only when the composition needs to diverge from the
/// natural label-keyed strict-`<` count shape — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl.
///
/// The lex-position contract — the returned `usize` sits in
/// `0..T::CARDINALITY` for every canonical variant — is guaranteed
/// by the default composition: the label-pairwise-distinctness
/// contract makes the strict-`<` count strictly less than
/// [`Self::CARDINALITY`] (the variant itself never counts, and
/// [`Self::CARDINALITY - 1`] other variants can at most all sit
/// below it under `str::cmp`); the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (22) pins the
/// both-directions equality against `T::sorted_variants()`'s
/// position of `self` on every implementor, so a passing
/// well-formedness sweep means every generic consumer can call
/// `sorted_index_of` on any typed variant and expect the same
/// `usize` answer at every crate boundary.
///
/// Future consumers — a lex-sorted per-slot metrics binner that
/// stores counter payloads at `metrics[variant.sorted_index_of()]`
/// so a natural per-slot walk in declaration order renders the
/// metrics in lex-sorted rendering order without a re-sort at the
/// rendering site, a compact wire-format encoder that emits
/// `variant.sorted_index_of() as u8` when the wire protocol pins
/// lex-order stability (a legal / regulatory contract that pins
/// the byte-order semantics on the CANONICAL alphabetic order
/// rather than the DECLARATION order — the two are structurally
/// distinct when the closed set's canonical ordering is defined by
/// alphabetic order rather than declaration order), a
/// bitset-observed-slot renderer that renders lex-sorted diagnostics
/// by walking the bit indices in lex order, a `tatara-check`
/// per-slot diagnostic that renders `<label>: <count>` in lex order
/// by keying counters on `sorted_index_of` — bind to ONE trait
/// method instead of hand-rolling either
/// `T::sorted_variants().iter().position(|v| v == self).unwrap()`
/// (which pays a `Vec<Self>` allocation the label-keyed count doesn't
/// need AND requires a `PartialEq` bound on the closed set) OR the
/// inline `T::ALL.iter().filter(|v| v.label() < self.label()).count()`
/// (which re-derives the same one-primitive composition at every
/// callsite AND makes every downstream site depend on the
/// [`Self::label`]-keyed strict-`<` shape) at each callsite, and
/// the closed-set (variant → lex position) direct projection
/// surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (typed variant → `usize`
/// lexicographic-order position) projection becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `Self::sorted_variants().iter().position(|v| v == self)`
/// composition at every downstream lex-index site. The (declaration,
/// lex) × (variant → position) 1×2 forward-projection partition
/// completes at BOTH ordering axes.
/// THEORY.md §V.1 — knowable platform; the (variant → lex position)
/// projection was an unnamed compound of [`Self::sorted_variants`] +
/// `Iterator::position` + `PartialEq` pre-lift; naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of [`Self::ALL`]
/// combined with [`Self::label`] alone — generic consumers see ONE
/// method, not ONE lex-position-shape-per-crate. Clause (22) pins
/// [`Self::sorted_index_of`] against `T::sorted_variants()`'s
/// position of `self` on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// `sorted_index_of` on any typed variant and expect the same
/// `usize` answer at every crate boundary.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// lex position) projection emerges from the composition of TWO
/// substrate primitives ([`Self::ALL`], [`Self::label`]) via the
/// standard-library `str: Ord` strict-`<` comparator rather than
/// as a per-implementor inline `sorted_variants().iter().position`
/// or a `const LEX_POS: [usize; N] = [...]` static table. A future
/// tightening of either primitive (a future canonicalization-aware
/// `label` projection, a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the ordering, a future case-insensitive-label extension)
/// propagates to every closed-set lex-position consumer through
/// ONE trait body.
///
/// Frontier inspiration: Racket's `(sort-index enum sym)` on a
/// closed enum projects a symbol directly onto its
/// lexicographic-order position without an intermediate sorted-list
/// materialization the caller must round-trip through. Idris's
/// `Data.List.findIndex` composed with a labeling projection on the
/// `Fin n` finite-cardinality universe delivers the same shape one
/// vocabulary over on the dependent-type side. MLIR's
/// `RegisteredOperationName::getStableIndex()` on the
/// lexicographically-sorted Op registry gives each Op kind a
/// canonical lex-order slot the DiagnosticEngine's per-slot
/// counters key off. Haskell's `Data.List.elemIndex` composed with
/// a `sortBy comparingLabel` prelude on a closed enumeration
/// projects the same (variant → lex position) shape via the same
/// two-primitive composition. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::ALL`] combined with [`Self::label`] surfaces
/// via a strict-`<` linear scan — no new dep, no new IR layer, no
/// supertrait bound, no `Vec` allocation, no `PartialEq` bound, no
/// `Option`-typed dispatch.
fn sorted_index_of(self) -> usize {
let my_label = <Self as ClosedSet>::label(self);
let mut count = 0usize;
for &v in Self::ALL {
if <Self as ClosedSet>::label(v) < my_label {
count += 1;
}
}
count
}
/// Recover the typed variant at lexicographic-order position `i` in
/// [`Self::sorted_variants`], or [`None`] if `i >= Self::CARDINALITY`.
///
/// The typed inverse of [`Self::sorted_index_of`] on the (typed
/// variant ↔ `usize` lexicographic-order position) bijection:
/// [`Self::sorted_index_of`] projects a variant onto its `usize`
/// lex-order position through the strict-`<` label sweep over
/// [`Self::ALL`]; this method projects a `usize` lex-order position
/// back onto its typed variant. Together the two projections close
/// the (variant ↔ lex-order position) bijection with
/// `0..T::CARDINALITY` at BOTH directions — every generic consumer
/// that stores a `variant.sorted_index_of()` for later lex-order
/// decode (a compact wire encoding whose bytes sit in lex order and
/// later recovers the variant, a lex-sorted slotted lookup table
/// scanned back to `(variant, payload)` pairs for exhaustive lex-
/// order iteration, a lex-order bitset walked back to the set of
/// observed variants in canonical alphabetic order, a Sekiban audit-
/// trail metric that stores per-lex-slot counters and later renders
/// `<variant>: <count>` diagnostics in lex order) binds to ONE
/// typed inverse method rather than hand-rolling either
/// `Self::sorted_variants().get(i).copied()` (which pays a
/// `Vec<Self>` allocation the direct-projection surface doesn't
/// need AND re-derives the same three-primitive composition at
/// every callsite) OR a per-implementor inline `match i { 0 =>
/// Some(v0), 1 => Some(v1), _ => None }` keyed on the lex slot
/// (which re-derives the per-variant lex-slot → variant table at
/// every callsite AND drifts silently when [`Self::ALL`] gains a
/// new variant that reorders the lex partition).
///
/// Sibling posture to [`Self::from_index`] one ordering-axis over on
/// the (declaration, lex) partition of the (`usize` position →
/// variant) inverse-projection surface: [`Self::from_index`]
/// projects a `usize` position back onto its typed variant through
/// direct [`Self::ALL`] slice indexing under declaration order, this
/// method projects a `usize` position back onto its typed variant
/// through [`Self::sorted_variants`] slice indexing under
/// lexicographic order. Both return an [`Option<Self>`] because the
/// input carrier is wider than the closed set — every out-of-range
/// `usize` decodes to [`None`] on both axes. Both share the SAME
/// zero-`PartialEq`-bound shape and the SAME `Option`-typed
/// rejection arm; a generic consumer freely swaps between the two
/// inverse-decode surfaces based on its ordering-axis carrier
/// without changing the program's structured-decode semantics.
///
/// The (ordering-axis × inverse-projection) partition post-lift:
///
/// | Ordering axis | Inverse projection surface |
/// |----------------------|----------------------------------|
/// | Declaration order | [`Self::from_index`] |
/// | Lexicographic order | [`Self::from_sorted_index`] |
///
/// Closes the second direct edge of the (variant, `&'static str`
/// label, `usize` position) projection triangle on the LEX ordering
/// axis — [`Self::sorted_index_of`] closed the first direct edge
/// (variant → lex position), this method closes the second direct
/// edge (lex position → variant). Downstream lifts
/// ([`Self::sorted_label_at`], [`Self::sorted_index_of_label`])
/// close the remaining lex-axis edges on the same natural
/// composition base.
///
/// Default body composes ONE substrate primitive
/// ([`Self::sorted_variants`]) with the standard-library
/// `<[T]>::get` bounded-index projection and [`Option::copied`] —
/// no discriminant sweep, no `PartialEq` bound, no per-variant
/// `match`. Sibling posture to [`Self::from_index`]'s
/// `Self::ALL.get(i).copied()` shape one ordering-axis over: both
/// bind the natural bounded-decode arm through the same
/// `<[T]>::get` composition on the corresponding sibling ALL-array
/// surface. Implementors override with a per-index `match` when
/// the O(1) slice lookup shows up on a hot-path profile (the
/// substrate-wide typed-emission bind: no production site today
/// calls `from_sorted_index` on a per-message hot path, so the
/// default slice lookup costs nothing measurable, and the override
/// axis exists for the same reason `via` / `set_label` / `labels` /
/// `index_of` / `from_index` overrides exist — a typed escape hatch
/// the trait surface exposes rather than forcing the implementor to
/// hand-roll the impl).
///
/// The bounded-index contract — the out-of-range arm returns
/// [`None`] for every `i >= Self::CARDINALITY` — is guaranteed by
/// the default `<[T]>::get` composition; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (23)
/// pins the both-directions equality on every implementor, so a
/// passing well-formedness sweep means every generic consumer can
/// call `from_sorted_index` on any `usize` payload and expect the
/// same `Option`-typed answer at every crate boundary.
///
/// Future consumers — a lex-order compact wire decoder that maps a
/// `u8` lex slot back to its variant (a legal / regulatory contract
/// that pins the byte-order semantics on the CANONICAL alphabetic
/// order rather than declaration order — the two are structurally
/// distinct when the closed set's canonical ordering is defined by
/// alphabetic order), a lex-order slotted lookup table
/// `[Payload; T::CARDINALITY]` scanned back to `(variant, payload)`
/// pairs by walking `for i in 0..T::CARDINALITY {
/// let v = T::from_sorted_index(i).unwrap(); ... }` for exhaustive
/// lex-order iteration, a lex-order bitset over the closed set
/// walked back to the set of observed variants in canonical
/// alphabetic order by mapping each observed bit back through this
/// method, a `tatara-check` per-slot diagnostic that renders
/// `<label>: <count>` in lex order and later recovers the typed
/// variant per slot for cross-checks — bind to ONE trait method
/// instead of composing three primitives
/// (`sorted_variants()` + `<[T]>::get` + `Option::copied`) with a
/// `Vec<Self>` allocation at every call site.
///
/// THEORY.md §III — the typescape; the (`usize` lex position →
/// typed variant) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `Self::sorted_variants().get(i).copied()` composition at every
/// downstream lex-order inverse-decode site. The (declaration, lex)
/// × (position → variant) 1×2 inverse-projection partition
/// completes at BOTH ordering axes.
/// THEORY.md §V.1 — knowable platform; the (lex position → typed
/// variant) projection was an unnamed compound of
/// [`Self::sorted_variants`] + `<[T]>::get` + `Option::copied`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of [`Self::sorted_variants`] — generic consumers
/// see ONE method, not ONE lex-inverse-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (lex
/// position → typed variant) projection emerges from the
/// composition of ONE substrate primitive
/// ([`Self::sorted_variants`]) with the standard-library
/// `<[T]>::get` bounded-index projection and the standard-library
/// `Option::copied` primitive rather than as a per-implementor
/// inline `match` block. A future tightening of
/// [`Self::sorted_variants`] (a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the ordering, a future canonicalization-aware `label`
/// projection that reorders the lex partition) propagates to every
/// closed-set lex-order inverse-decode consumer through ONE trait
/// method.
///
/// Frontier inspiration: Idris's `Fin n` finite-cardinality type
/// with `natToFin : Nat -> (n : Nat) -> Maybe (Fin n)` composed
/// with a lex-sorted labeling projection over the finite-type
/// universe — the finite-type surface exposes a canonical (natural
/// → element) bounded-decode projection that a downstream compact-
/// encoding binds to, in either declaration-order OR lex-order
/// through the composition. Racket's `(enum-index->object enum n
/// #:order 'lex)` on a closed enum decodes an index back to its
/// variant under the chosen ordering; MLIR's
/// `RegisteredOperationName::get(int)` on the lex-sorted Op registry
/// decodes a stable lex index back to its Op kind; Haskell's
/// `Data.List.genericIndex` composed with a `sortBy comparingLabel`
/// prelude on a closed enumeration projects the same (lex position
/// → variant) shape via the same two-primitive composition.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::sorted_variants`]
/// surface with `<[T]>::get` and `Option::copied` — no new dep, no
/// new IR layer, no supertrait bound.
fn from_sorted_index(i: usize) -> Option<Self> {
Self::sorted_variants().get(i).copied()
}
/// Recover the canonical [`Self::label`] at lexicographic-order
/// position `i` in [`Self::sorted_labels`], or [`None`] if
/// `i >= Self::CARDINALITY`.
///
/// The direct `(usize` lex-order position → `&'static str` canonical
/// label) projection through the closed set — the third direct edge
/// of the (typed variant, `&'static str` label, `usize` position)
/// projection triangle on the LEX ordering axis. Sibling posture to
/// [`Self::label_at`] one ordering-axis over on the (declaration,
/// lex) partition of the (`usize` position → `&'static str` label)
/// forward-projection surface: [`Self::label_at`] projects a
/// declaration-order `usize` position onto its canonical label
/// through [`Self::from_index`] + [`Self::label`], this method
/// projects the same `usize` position through
/// [`Self::from_sorted_index`] + [`Self::label`] under the
/// lexicographic ordering. Together the two direct projections
/// bracket both ordering axes at the (`usize` position →
/// `&'static str` label) forward edge — every generic consumer that
/// renders per-slot diagnostics against a `usize` slot binds to the
/// ordering-axis surface at ONE trait method rather than routing
/// through a `from_sorted_index(i).map(label)` composition or a
/// `sorted_labels().get(i).copied()` route at every callsite.
///
/// The (ordering-axis × direct-projection) partition post-lift:
///
/// | Ordering axis | (`usize` → label) projection surface |
/// |----------------------|--------------------------------------|
/// | Declaration order | [`Self::label_at`] |
/// | Lexicographic order | [`Self::sorted_label_at`] |
///
/// Closes the third direct edge of the lex-axis projection triangle
/// — [`Self::sorted_index_of`] closed the first direct edge (variant
/// → lex position), [`Self::from_sorted_index`] closed the second
/// (lex position → variant), this method closes the third (lex
/// position → `&'static str` label). [`Self::sorted_index_of_label`]
/// closes the fourth (and final) direct edge (`&str` label → lex
/// position) to complete the lex-axis triangle.
///
/// Default body composes [`Self::from_sorted_index`] with
/// [`Self::label`] verbatim — the `usize → &'static str` shape on
/// the lex axis is a typed CONSEQUENCE of the two pre-existing
/// primitives, not a third codepath. Implementors override only
/// when the composition needs to diverge from the natural
/// `from_sorted_index(i).map(label)` shape — a typed escape hatch
/// the trait surface exposes (same axis as `via` / `set_label` /
/// `labels` / `sorted_labels` / `sorted_variants` / `from_index` /
/// `index_of` / `label_at` / `from_sorted_index` overrides). An
/// implementor that overrides [`Self::from_sorted_index`] (a future
/// perfect-hash lex-slot decoder, a future canonicalization-aware
/// `label` projection that reorders the lex partition) propagates
/// the override through this default body to the direct-label
/// projection automatically; the lex-axis projection triangle
/// funnels every `usize`-carrier lex-decode through ONE typed
/// primitive on each of its (typed variant, `&'static str` label)
/// return-projection columns.
///
/// The bounded-index contract — the out-of-range arm returns
/// [`None`] for every `i >= Self::CARDINALITY` — is guaranteed by
/// the default composition through [`Self::from_sorted_index`]'s
/// `<[T]>::get` slice-bounded projection; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (24)
/// pins the both-directions equality against the natural
/// composition on every implementor, so a passing well-formedness
/// sweep means every generic consumer can call `sorted_label_at` on
/// any `usize` payload and expect the same `Option`-typed answer at
/// every crate boundary.
///
/// Future consumers — a lex-order compact wire-format decoder that
/// emits `variant.sorted_index_of() as u8` and later renders
/// `sorted_label_at(byte as usize)` for a diagnostic WITHOUT
/// materializing the typed variant at the rendering site (the
/// natural `Option`-typed rejection arm covers out-of-range
/// serialized lex indices), a lex-sorted metrics binner that stores
/// per-slot counter payloads under
/// `metrics[variant.sorted_index_of()]` and later renders per-slot
/// diagnostics `<sorted_label_at(slot)>: <count>` in lex order
/// without a re-decode through [`Self::from_sorted_index`] +
/// [`Self::label`] at each rendering site, a `tatara-check`
/// per-slot diagnostic that walks `0..T::CARDINALITY` and renders
/// each lex slot's canonical label without carrying the typed
/// variant, a bitset-observed-variant renderer that walks the set
/// bits under the lex-order rendering shape and renders each lex
/// slot's label directly without a
/// [`Self::from_sorted_index`]-then-[`Self::label`] two-step at
/// each set bit — bind to ONE trait method instead of hand-rolling
/// either `T::from_sorted_index(i).map(|v| v.label())` (which
/// re-derives the same two-primitive composition at every callsite
/// AND makes every downstream site depend on
/// [`Self::from_sorted_index`]'s `Option`-typed dispatch shape) OR
/// the inline `T::sorted_labels().get(i).copied()` (which pays a
/// `Vec<&'static str>` allocation the direct-projection surface
/// doesn't need AND re-derives the three-primitive composition at
/// every callsite) at each callsite, and the closed-set `(lex
/// position → label)` direct projection surface evolves at ONE site
/// rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (`usize` lex-order position
/// → `&'static str` canonical label) projection becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `Self::from_sorted_index(i).map(|v| v.label())` composition at
/// every downstream lex-slot-decode site. The (declaration, lex) ×
/// (`usize` position → `&'static str` label) 1×2 forward-projection
/// partition completes at BOTH ordering axes.
/// THEORY.md §V.1 — knowable platform; the (`usize` lex position
/// → `&'static str` label) projection was an unnamed compound of
/// [`Self::from_sorted_index`] composed with [`Self::label`]
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not ONE lex-slot-to-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the direct
/// (lex position → label) projection emerges from the composition
/// of TWO substrate primitives ([`Self::from_sorted_index`],
/// [`Self::label`]) rather than as a per-implementor inline
/// `from_sorted_index(i).map(label)` compound. A future tightening
/// of either primitive (a future perfect-hash `from_sorted_index`,
/// a future canonicalization-aware `label` projection that folds
/// case / whitespace, a future const-fn `label` axis that makes the
/// projection compile-time visible) propagates to every closed-set
/// direct-lex-label-projection consumer through ONE trait body.
///
/// Frontier inspiration: Racket's `(enum-label enum i #:order 'lex)`
/// on a closed enum projects a lex-order position onto its rendered
/// canonical label directly under the chosen ordering; MLIR's
/// `RegisteredOperationName::getStableName(int)` on the lex-sorted
/// Op registry projects a stable lex slot onto its canonical name
/// the DiagnosticEngine renders per-slot diagnostics against.
/// Haskell's `Data.List.genericIndex (sortBy comparingLabel labels)
/// i` composes the sort with the bounded-index projection into the
/// same `(lex position → label)` shape one vocabulary over.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::from_sorted_index`] +
/// [`Self::label`] surfaces — no new dep, no new IR layer, no
/// supertrait bound, no allocation.
fn sorted_label_at(i: usize) -> Option<&'static str> {
<Self as ClosedSet>::from_sorted_index(i).map(<Self as ClosedSet>::label)
}
/// Recover the lexicographic-order `usize` position of the variant
/// labelled `s`, or [`None`] if `s` matches no variant's
/// [`Self::label`].
///
/// The direct `(&str → usize` lex-order position) projection through
/// the closed set — the fourth (and final) direct edge of the (typed
/// variant, `&'static str` label, `usize` position) projection
/// triangle on the LEX ordering axis. Sibling posture to
/// [`Self::index_of_label`] one ordering-axis over on the
/// (declaration, lex) partition of the (`&str` → `usize` position)
/// forward-projection surface: [`Self::index_of_label`] projects a
/// `&str` label onto its declaration-order slot through
/// [`Self::find_by_label`] + [`Self::index_of`], this method projects
/// the same `&str` label onto its lexicographic-order slot through
/// [`Self::find_by_label`] + [`Self::sorted_index_of`]. Together the
/// two direct projections bracket both ordering axes at the (`&str`
/// → `usize` position) forward edge — every generic consumer that
/// slots a per-label incoming payload into a canonical
/// alphabetical-order slot (a lex-sorted per-label metrics binner
/// that keys `counters[T::sorted_index_of_label(label)?]` on a diagnostic
/// input string, a lex-order compact wire-format encoder that reads
/// a `&str` config value and emits its canonical alphabetic slot
/// directly as a `u8` without materializing the typed variant at the
/// encoder site, a `tatara-check` per-lex-slot per-label diagnostic
/// that partitions a batch of incoming labels by lex-order slot
/// under the natural `[per_slot; T::CARDINALITY]` aggregation shape,
/// an LSP-hover / config-decoder rendering that maps parsed labels
/// back to their canonical alphabetic slot ordering for stable
/// lex-order rendering) binds to the lex-ordering-axis surface at
/// ONE trait method rather than routing through a
/// `find_by_label(s).map(sorted_index_of)` composition or a
/// `sorted_labels().iter().position(|l| l == s)` scan at every
/// callsite.
///
/// The (ordering-axis × direct-projection) partition post-lift:
///
/// | Ordering axis | (`&str` → position) projection surface |
/// |----------------------|--------------------------------------------|
/// | Declaration order | [`Self::index_of_label`] |
/// | Lexicographic order | [`Self::sorted_index_of_label`] |
///
/// Closes the fourth (and final) direct edge of the lex-axis
/// projection triangle — [`Self::sorted_index_of`] closed the first
/// direct edge (variant → lex position), [`Self::from_sorted_index`]
/// closed the second (lex position → variant),
/// [`Self::sorted_label_at`] closed the third (lex position →
/// `&'static str` label), this method closes the fourth (`&str`
/// label → lex position). The (typed variant, `&'static str` label,
/// `usize` position) projection triangle now stays direct-projection
/// closed at EVERY (input, output) pair on BOTH the declaration and
/// lexicographic ordering axes — twelve directed edges total
/// (6 per ordering axis × 2 ordering axes) each bind to ONE typed
/// trait method with no two-step composition at the call site.
///
/// Default body composes [`Self::find_by_label`] with
/// [`Self::sorted_index_of`] verbatim — the `&str → usize` lex-slot
/// shape is a typed CONSEQUENCE of the two pre-existing primitives,
/// not a third codepath. Sibling posture to
/// [`Self::index_of_label`]'s `find_by_label(s).map(index_of)` shape
/// one ordering-axis over: both bind the natural `&str`-carrier
/// forward-slot decode through the same [`Self::find_by_label`]
/// primitive on the label-decode column and diverge only at the
/// terminal (variant → `usize`) projection they compose with — the
/// declaration-order axis threads [`Self::index_of`], the
/// lexicographic-order axis threads [`Self::sorted_index_of`].
/// Implementors override only when the composition needs to diverge
/// from the natural `find_by_label(s).map(sorted_index_of)` shape
/// — a typed escape hatch the trait surface exposes (same axis as
/// `via` / `set_label` / `labels` / `sorted_labels` /
/// `sorted_variants` / `from_index` / `index_of` / `label_at` /
/// `index_of_label` / `from_sorted_index` / `sorted_label_at` /
/// `sorted_index_of` overrides). An implementor that overrides
/// [`Self::find_by_label`] (a future perfect-hash label-decoder, a
/// future canonicalization-aware label projection that folds case
/// or whitespace) OR [`Self::sorted_index_of`] (a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the ordering, a future const-fn lex-position projection)
/// propagates the override through this default body to the
/// direct-lex-slot projection automatically; the lex-axis projection
/// triangle funnels every `&str`-carrier lex-decode through ONE
/// typed primitive on each of its (variant, `usize` lex position)
/// return-projection columns.
///
/// The rejection contract — a non-canonical `&str` returns [`None`],
/// the empty-string boundary that clause (4) reserves as structurally
/// outside the closed set returns [`None`] — is guaranteed by the
/// default composition through [`Self::find_by_label`]'s
/// `Option`-typed sweep; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (25) pins the
/// both-directions equality against the natural composition on
/// every implementor, so a passing well-formedness sweep means
/// every generic consumer can call `sorted_index_of_label` on any
/// `&str` payload and expect the same `Option`-typed answer at
/// every crate boundary.
///
/// Future consumers — a lex-sorted per-label metrics binner that
/// reads a diagnostic label from an incoming trace event and
/// increments `counters[T::sorted_index_of_label(label)?]` under
/// the lex-sorted per-slot aggregation shape without a two-step
/// (`find_by_label` → `sorted_index_of`) composition at each
/// rendering site, a lex-order compact wire-format encoder that
/// reads a `&str` config value (a Kubernetes annotation, a YAML
/// enum field, a diagnostic input string) and emits its canonical
/// alphabetic slot directly as a `u8` without materializing the
/// typed variant at the encoder site (a legal / regulatory contract
/// that pins the byte-order semantics on the CANONICAL alphabetic
/// order rather than declaration order — the two are structurally
/// distinct when the closed set's canonical ordering is defined by
/// alphabetic order), a `tatara-check` per-lex-slot per-label
/// diagnostic that partitions a batch of incoming labels by
/// lex-order slot for reporting under the natural
/// `[per_slot; T::CARDINALITY]` aggregation shape, an LSP-hover /
/// config-decoder rendering that maps parsed labels back to their
/// canonical alphabetic slot ordering for stable lex-order
/// rendering — bind to ONE trait method instead of hand-rolling
/// either `T::find_by_label(s).map(T::sorted_index_of)` (which
/// re-derives the same two-primitive composition at every callsite
/// AND makes every downstream site depend on
/// [`Self::find_by_label`]'s `Option`-typed dispatch shape) OR the
/// inline `T::sorted_labels().iter().position(|l| l == &s)` (which
/// pays a `Vec<&'static str>` allocation the label-keyed find
/// doesn't need AND re-derives the underlying three-primitive
/// composition at every callsite, AND drops the
/// [`Self::find_by_label`] override propagation that keeps every
/// carrier-decode consumer aligned on a single typed dispatch) at
/// each callsite, and the closed-set `(&str → lex position)` direct
/// projection surface evolves at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (`&'static str` label →
/// `usize` lex-order position) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `Self::find_by_label(s).map(Self::sorted_index_of)` composition
/// at every downstream label-to-lex-slot site. The projection
/// triangle over the closed-set carriers gains its final direct
/// edge on the lex ordering axis — every (input, output) pair
/// across the (typed variant, `&'static str` label, `usize`
/// position) carriers now binds to ONE typed projection surface at
/// BOTH ordering axes (declaration and lexicographic) with no
/// two-step composition at the call site.
/// THEORY.md §V.1 — knowable platform; the (`&str` → `usize` lex
/// position) direct projection was an unnamed compound of
/// [`Self::find_by_label`] composed with [`Self::sorted_index_of`]
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not ONE label-to-lex-slot-shape-per-crate. The
/// well-formedness clause (25) pins the composition against the
/// natural `find_by_label(s).map(sorted_index_of)` shape on every
/// implementor so a passing well-formedness sweep means every
/// generic consumer can call `sorted_index_of_label` on any `&str`
/// payload and expect the same `Option`-typed answer at every
/// crate boundary.
/// THEORY.md §VI.1 — generation over composition; the direct
/// (`&str → lex position`) projection emerges from the composition
/// of TWO substrate primitives ([`Self::find_by_label`],
/// [`Self::sorted_index_of`]) rather than as a per-implementor
/// inline `find_by_label(s).map(sorted_index_of)` compound. A future
/// tightening of either primitive (a future perfect-hash
/// `find_by_label`, a future canonicalization-aware label
/// projection that folds case / whitespace, a future const-fn
/// `sorted_index_of` axis that makes the projection compile-time
/// visible, a future `#[closed_set(compare_labels_with = ...)]`
/// derive attribute that swaps the ordering) propagates to every
/// closed-set direct-lex-slot-projection consumer through ONE trait
/// body.
///
/// Frontier inspiration: Racket's `(enum-sort-index enum sym)` on a
/// closed enum projects a symbol directly onto its lexicographic-
/// order position under the chosen ordering — the label-keyed lex-
/// slot forward decoder the counterpart to `(enum-index enum sym)`
/// on the declaration axis. MLIR's `RegisteredOperationName::
/// getStableIndexByName(StringRef name)` on the lex-sorted Op
/// registry composes the (name → op) lookup with the (op → stable
/// lex index) projection into ONE direct `(name → lex index)`
/// surface the DiagnosticEngine's per-lex-slot counters key off.
/// Haskell's `Data.List.elemIndex sym (sortBy comparingLabel
/// labels)` composes the sort with the label-keyed find into the
/// same `(&str → lex position)` shape one vocabulary over. Idris's
/// `Data.List.findIndex ((sym ==) . label)` composed with a lex-
/// sorted `sortBy` prelude on the `Fin n` finite-cardinality
/// universe delivers the same shape one vocabulary over on the
/// dependent-type side. Translation through pleme-io primitives:
/// a pure default method composing the trait's existing
/// [`Self::find_by_label`] + [`Self::sorted_index_of`] surfaces —
/// no new dep, no new IR layer, no supertrait bound, no allocation.
fn sorted_index_of_label(s: &str) -> Option<usize> {
<Self as ClosedSet>::find_by_label(s).map(<Self as ClosedSet>::sorted_index_of)
}
/// The (hint) sibling of [`Self::sorted_index_of_label`] — the zero-
/// allocation structured decode of `s` into a lexicographic-order
/// index, threading a typed [`Self::suggest_closest`] hint into the
/// rejection envelope. Peer of [`Self::index_of_label_with_hint`]
/// one ordering-axis over on the (`usize`-typed direct projection
/// with hint) surface: where [`Self::index_of_label_with_hint`]
/// projects the accept-arm variant through [`Self::index_of`]
/// (declaration order), this method projects it through
/// [`Self::sorted_index_of`] (lex order), so the caller gets the
/// canonical alphabetic-order slot directly.
///
/// On exact match returns `Ok(idx)` where `idx == v.sorted_index_of()`
/// for the canonical variant `v` bound to label `s`. On miss returns
/// `Err(hint)` where `hint` is the typed variant
/// [`Self::suggest_closest`] keys on — `Some(v)` when a canonical
/// label sits within the substrate-wide bounded edit distance,
/// `None` when no candidate qualifies (the conservative-suggestion
/// contract — silent over guessing).
///
/// The hint slot carries the TYPED VARIANT rather than its lex-order
/// slot so a downstream diagnostic renderer can freely project the
/// hint through [`Self::label`] for a `did you mean 'foo'?` message,
/// through [`Self::sorted_index_of`] for the near-miss's lex slot,
/// OR through [`Self::index_of`] for the near-miss's declaration
/// slot — one zero-allocation structured decode surfaces every
/// consumer's downstream projection without paying the
/// [`Self::make_unknown`] carrier allocation
/// [`Self::parse_label_with_hint`] threads on the same reject path.
/// The hint variant is IDENTICAL to the one
/// [`Self::index_of_label_with_hint`] surfaces on the same input —
/// the ordering axis is a downstream projection choice, not a hint-
/// carrier bifurcation. Matches the (hint = typed variant) shape
/// [`Self::find_by_label_with_hint`] pins one axis over on the
/// (`Self`-typed direct decode) column.
///
/// Peer of [`Self::sorted_index_of_label`] on the (hint) axis of the
/// (`&str → usize` lex-order direct-projection) surface. Peer of
/// [`Self::index_of_label_with_hint`] on the (ordering) axis of the
/// (`&str → usize` structured-decode-with-hint) surface. Closes the
/// FINAL corner of the (return-type × hint × ordering) 2×2×2 =
/// 8-corner cube on the closed-set structured-decode surface — the
/// (`usize`-typed, with-hint, lex-order) corner past the six
/// already-closed populated corners (the two `Self`-typed
/// ordering-axis corners collapse to one each on the carrier column
/// because the typed variant carries no ordering-axis distinction,
/// leaving 2 + 4 = 6 populated corners; this method opens the
/// eighth-and-final `usize`-typed corner):
///
/// | Return type \ Hint | No hint (decl) | With hint (decl) | No hint (lex) | With hint (lex) |
/// |--------------------|-----------------------------|-----------------------------------------|-----------------------------------|----------------------------------------------|
/// | `Self` | [`Self::find_by_label`] | [`Self::find_by_label_with_hint`] | (collapses onto `find_by_label`) | (collapses onto `find_by_label_with_hint`) |
/// | `usize` | [`Self::index_of_label`] | [`Self::index_of_label_with_hint`] | [`Self::sorted_index_of_label`] | [`Self::sorted_index_of_label_with_hint`] |
///
/// Default body composes [`Self::find_by_label_with_hint`] with
/// [`Self::sorted_index_of`] on the Ok arm — the structured lex-slot
/// decode is a typed CONSEQUENCE of the two pre-existing primitives,
/// not a third codepath. Sibling posture to
/// [`Self::index_of_label_with_hint`]'s
/// `find_by_label_with_hint(s).map(index_of)` shape one ordering-
/// axis over: both bind the natural `&str`-carrier with-hint decode
/// through the same [`Self::find_by_label_with_hint`] primitive on
/// the structured-decode column and diverge only at the terminal
/// (variant → `usize`) projection they compose with — the
/// declaration-order axis threads [`Self::index_of`], the lex-order
/// axis threads [`Self::sorted_index_of`]. Implementors override
/// only when the composition needs to diverge (no production
/// implementor reaches for this today; the axis exists for the same
/// reason [`Self::sorted_index_of_label`] /
/// [`Self::index_of_label_with_hint`] overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that overrides
/// [`Self::find_by_label_with_hint`] OR [`Self::sorted_index_of`]
/// propagates the override through this default body automatically;
/// the structured (`&str → usize` lex-order with hint) decode
/// funnels every sweep through ONE typed primitive per axis.
///
/// Future consumers — a lex-sorted LSP-hover pass that resolves the
/// typed lex-order slot under the operator's cursor AND (on miss)
/// renders a `did you mean <hint.label()>?` next to a bare rejection
/// WITHOUT paying carrier allocation per non-matching hover; a
/// lex-order compact wire-format decoder that reads a `&str` config
/// value and emits either the canonical alphabetic-order slot as a
/// `u8` directly OR a typed near-miss the operator sees when the
/// field's value is a fuzzy hit
/// (`T::sorted_index_of_label_with_hint(cfg).unwrap_or_else(|hint|
/// { emit_hint(hint); T::default_kind().sorted_index_of() })`) — a
/// legal / regulatory contract that pins the byte-order semantics
/// on the CANONICAL alphabetic order rather than the DECLARATION
/// order (the two are structurally distinct when the closed set's
/// canonical ordering is defined by alphabetic order); a
/// `filter_map`-shaped stream projection over cluster-wide
/// `tatara.pleme.io/*` annotation keys that partitions each element
/// into (typed_lex_slot, typed_hint, bare_unrecognized_key) via
/// `sorted_index_of_label_with_hint`; a `tatara-check` per-lex-slot
/// diagnostic that renders `<lex_idx>: <hint.label()>` per miss
/// under the natural `[per_slot; T::CARDINALITY]` aggregation shape
/// — bind to ONE trait method instead of hand-rolling the
/// `find_by_label_with_hint(s).map(sorted_index_of)` composition at
/// each callsite, and the closed-set zero-allocation structured
/// (`&str → usize` lex-order with hint) decode surface evolves at
/// ONE site rather than per-consumer.
///
/// The (accept, reject) alignment with
/// [`Self::find_by_label_with_hint`] — the two methods MUST agree
/// on membership at every `&str` payload (both accept the same
/// inputs, both reject the same inputs, both surface the SAME typed
/// hint variant on rejection) — is guaranteed by the default
/// composition and pinned by the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (83) on every
/// implementor, so a passing well-formedness sweep means every
/// generic consumer can call `sorted_index_of_label_with_hint` on
/// any `&str` payload and expect the same `Result`-typed answer at
/// every crate boundary AND the SAME `Option<Self>` hint variant
/// on rejection as [`Self::find_by_label_with_hint`] AND
/// [`Self::index_of_label_with_hint`] both surface.
///
/// THEORY.md §III — the typescape; the structured
/// (`&str → usize` lex-order with hint) decode becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `find_by_label_with_hint(s).map(sorted_index_of)` composition at
/// every downstream label-to-lex-slot-with-hint site. The (return-
/// type × hint × ordering) 2×2×2 cube on the closed-set structured-
/// decode surface now CLOSES at all populated corners — every
/// (input, output) pair on BOTH ordering axes with OR without hint
/// binds to ONE typed projection surface with no two-step
/// composition at any consumer site.
/// THEORY.md §V.1 — knowable platform; the structured
/// (`&str → usize` lex-order with hint) decode was an unnamed
/// compound of [`Self::find_by_label_with_hint`] +
/// [`Self::sorted_index_of`] pre-lift. Naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the two substrate
/// primitives — generic consumers see ONE method, not ONE
/// structured-lex-index-decode-shape-per-crate. Clause (83) pins
/// [`Self::sorted_index_of_label_with_hint`] against the natural
/// `find_by_label_with_hint(s).map(sorted_index_of)` composition on
/// every implementor so a passing well-formedness sweep means every
/// generic consumer can call `sorted_index_of_label_with_hint` on
/// any typed variant and expect the same `Result`-typed answer at
/// every crate boundary.
/// THEORY.md §VI.1 — generation over composition; the structured-
/// diagnostic shape emerges from the composition of TWO substrate
/// primitives ([`Self::find_by_label_with_hint`],
/// [`Self::sorted_index_of`]) rather than as a per-implementor
/// structured-lex-index-decode impl. A future tightening of either
/// primitive (a future perfect-hash lookup on
/// [`Self::find_by_label_with_hint`], a future const-fn
/// [`Self::sorted_index_of`] axis that makes the projection
/// callable in const contexts, a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the lex ordering) propagates to every closed-set
/// structured (`&str → usize` lex-order with hint) consumer through
/// ONE trait body.
///
/// Frontier inspiration: MLIR's `RegisteredOperationName::
/// getStableIndexByName(StringRef name)` composed with a bounded
/// near-miss adornment slot on the lex-sorted Op registry delivers
/// the same (structured lex-index decode with typed near-miss)
/// shape one vocabulary over on the typed op registry side. Racket's
/// `(enum-sort-index enum sym #:hint suggest-fn)` on a closed enum
/// composes the (name → sort-index) lookup with a bounded near-miss
/// suggestion into ONE structured lex-decode surface — the label-
/// keyed lex-slot decode with hint the counterpart to `(enum-index
/// enum sym #:hint suggest-fn)` on the declaration axis. Haskell's
/// `Data.List.elemIndex sym (sortBy comparingLabel labels)` composed
/// with an `editDistance`-bounded near-miss suggestion projects the
/// same `(&str → lex-position with hint)` shape one vocabulary over
/// on the pure-functional side. Translation through pleme-io
/// primitives: a pure default method composing the trait's existing
/// [`Self::find_by_label_with_hint`] with [`Self::sorted_index_of`]
/// — no new primitive, no new dep, no new IR layer, no allocation.
fn sorted_index_of_label_with_hint(s: &str) -> Result<usize, Option<Self>> {
<Self as ClosedSet>::find_by_label_with_hint(s).map(<Self as ClosedSet>::sorted_index_of)
}
/// Allocating-carrier structured decode of `s` into a
/// lexicographic-order index, threading the substrate-wide
/// `unknown {SET_LABEL}: {input}` [`Self::Unknown`] carrier
/// through the reject arm — the ordering-axis sibling of
/// [`Self::parse_index_of_label`] one ordering-axis over on the
/// (allocating-carrier `&str → usize` decode, no-hint) surface.
/// Where [`Self::parse_index_of_label`] projects the accept-arm
/// variant through [`Self::index_of`] (declaration order), this
/// method projects it through [`Self::sorted_index_of`] (lex
/// order), so the caller gets the canonical alphabetic-order slot
/// directly through ONE call the substrate's diagnostic engine
/// binds to.
///
/// On exact match returns `Ok(idx)` where `idx == v.sorted_index_of()`
/// for the canonical variant `v` bound to label `s`. On miss
/// returns `Err(unknown)` where `unknown` is the typed
/// [`Self::Unknown`] carrier owning a [`String`] copy of `s` and
/// rendering the substrate-wide `unknown {SET_LABEL}: {input}`
/// shape through [`Display`](core::fmt::Display) — the SAME
/// carrier shape [`Self::parse_label`] and
/// [`Self::parse_index_of_label`] emit on the reject path, funnelled
/// through ONE structural rejection variant every
/// `?`-operator-chained decoder / typed-`serde`-error surface /
/// substrate-wide diagnostic pipeline binds to.
///
/// Peer of [`Self::parse_index_of_label`] one ordering-axis over on
/// the (allocating carrier, `&str → usize` decode, no-hint) column
/// of the (return-type × side-effect × hint × ordering) 4-axis
/// surface: both share the SAME `Result<usize, Self::Unknown>`
/// return shape (allocating-carrier `?`-friendly), the SAME
/// non-hinted rejection arm, and the SAME two-primitive-
/// composition body — differing only in whether they project
/// through [`Self::index_of`] (declaration order) or
/// [`Self::sorted_index_of`] (lex order). Peer of
/// [`Self::sorted_index_of_label`] one side-effect axis over on
/// the (lex, no-hint, `&str → usize`) column: where
/// [`Self::sorted_index_of_label`] returns a bare
/// [`Option<usize>`] with no carrier allocation on rejection, this
/// method threads the substrate-wide typed carrier through the
/// reject arm, so a `?`-operator-chained decoder that wants both
/// the lex slot AND the substrate-wide diagnostic threading binds
/// to ONE method.
///
/// The (side-effect × ordering) 2×2 matrix on the (`&str → usize`
/// no-hint) row partitions post-lift:
///
/// | Side-effect on reject | Declaration order | Lexicographic order |
/// |-----------------------------------|--------------------------------|----------------------------------------|
/// | Allocating (materialize carrier) | [`Self::parse_index_of_label`] | [`Self::parse_sorted_index_of_label`] |
/// | Non-allocating (bare Option) | [`Self::index_of_label`] | [`Self::sorted_index_of_label`] |
///
/// Default body composes [`Self::parse_label`] with
/// [`Self::sorted_index_of`] verbatim — the
/// `Result<usize-lex, Self::Unknown>` shape is a typed CONSEQUENCE
/// of the two pre-existing primitives, not a third codepath.
/// Implementors override only when the composition needs to
/// diverge from the natural `parse_label(s).map(sorted_index_of)`
/// shape (no production implementor reaches for this today; the
/// axis exists for the same reason `via` / `set_label` / `labels` /
/// `parse_label` / `sorted_index_of` / `parse_index_of_label` /
/// `sorted_index_of_label` overrides exist — a typed escape hatch
/// the trait surface exposes rather than forcing the implementor
/// to hand-roll the impl). An implementor that overrides
/// [`Self::parse_label`] (a future perfect-hash label-decoder, a
/// future canonicalization-aware label projection that folds case
/// or whitespace) propagates the override through this default
/// body to the allocating-carrier lex-index arm automatically; the
/// (`Self`-return, `usize`-decl-return, `usize`-lex-return) column
/// of the allocating-carrier row funnels every structured
/// diagnostic-carrying decode through ONE typed primitive on each
/// of its return-projection columns.
///
/// The rejection contract — a non-canonical `&str` allocates
/// [`Self::Unknown`] via [`Self::make_unknown`] with the SAME
/// substrate-wide `unknown {SET_LABEL}: {input}` [`Display`](core::fmt::Display)
/// shape [`Self::parse_label`] emits, the empty-string boundary
/// that clause (4) reserves as structurally outside the closed
/// set rejects to the SAME carrier shape — is guaranteed by the
/// default composition through [`Self::parse_label`]'s allocating-
/// carrier reject arm; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (85) pins the
/// both-directions equality against the natural composition on
/// every implementor, so a passing well-formedness sweep means
/// every generic consumer can call `parse_sorted_index_of_label`
/// on any `&str` payload and expect the same
/// `Result<usize, Self::Unknown>` answer at every crate boundary.
///
/// Future consumers — a lex-order compact wire encoder that reads
/// a `&str` config value (a Kubernetes annotation with a lex-order
/// stability contract, a YAML enum field whose byte-order
/// semantics pin the CANONICAL alphabetic order rather than
/// DECLARATION order — the two are structurally distinct when the
/// closed set's canonical ordering is defined by alphabetic order),
/// emits its lex-order position AND propagates the substrate-wide
/// typed carrier on rejection via the `?` operator; a lex-order
/// metrics binner that reads a diagnostic label from an incoming
/// trace event and increments
/// `counters[T::parse_sorted_index_of_label(label)?]` under the
/// per-lex-slot aggregation shape AND threads the substrate-wide
/// typed error through its `Result` return path; a `tatara-check`
/// per-slot per-label diagnostic that partitions a batch of
/// incoming labels by lex-order slot AND surfaces the substrate-
/// wide typed rejection carrier on unrecognized inputs through
/// ONE method rather than through the two-primitive
/// `parse_label(s).map(sorted_index_of)` composition at each
/// callsite; a serde-`Deserialize` visitor over a `&str` enum
/// wire-form whose typed slot storage is keyed on lex order (a
/// wire-format that pins byte-order stability on alphabetic
/// order) — bind to ONE trait method instead of hand-rolling the
/// composition at each callsite, and the closed-set `(&str →
/// usize-lex with carrier)` structured projection surface evolves
/// at ONE site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (`&str → usize` lex-order
/// index with allocating carrier) structured decode becomes a
/// TYPE projection on the trait, completing the (side-effect ×
/// ordering) 2×2 partition on the (`&str → usize` no-hint) row at
/// the (allocating, lex) corner. The (return-type × side-effect ×
/// hint × ordering) 4-axis surface's (allocating, `usize`-lex,
/// no-hint) corner binds at ONE typed method rather than at
/// per-consumer inline `parse_label(s).map(sorted_index_of)`
/// composition.
/// THEORY.md §V.1 — knowable platform; the (`&str → usize-lex
/// with carrier`) projection was an unnamed compound of
/// [`Self::parse_label`] composed with [`Self::sorted_index_of`]
/// pre-lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not ONE lex-index-decode-shape-per-
/// crate.
/// THEORY.md §VI.1 — generation over composition; the direct
/// (`&str → usize-lex with carrier`) projection emerges from the
/// composition of TWO substrate primitives ([`Self::parse_label`],
/// [`Self::sorted_index_of`]) rather than as a per-implementor
/// inline compound. A future tightening of either primitive (a
/// future perfect-hash `parse_label`, a future canonicalization-
/// aware label projection that folds case / whitespace, a future
/// const-fn `sorted_index_of` axis) propagates to every closed-
/// set allocating-carrier lex-index consumer through ONE trait
/// body.
///
/// Frontier inspiration: rustc's `Symbol::intern` composed with a
/// lex-sorted symbol-table index projection — the typed-symbol
/// lookup with a substrate-wide interned-string carrier on
/// rejection composed with a stable lex-order slot projection, all
/// through ONE call the diagnostic engine binds to. MLIR's
/// `RegisteredOperationName::lookup(StringRef)` composed with
/// `getStableIndex()` on the lex-sorted Op registry — the same
/// shape one ordering-axis over on the C++ side. Racket's
/// `(hash-ref/failure enum sym make-unknown)` composed with
/// `(enum-sort-index enum sym)` on a closed enum stands as the
/// same shape one vocabulary over on the Lisp-VM side. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::parse_label`] +
/// [`Self::sorted_index_of`] surfaces — no new dep, no new IR
/// layer, no supertrait bound.
fn parse_sorted_index_of_label(s: &str) -> Result<usize, Self::Unknown> {
<Self as ClosedSet>::parse_label(s).map(<Self as ClosedSet>::sorted_index_of)
}
/// Allocating-carrier structured decode of `s` into a
/// lexicographic-order [`Self::ALL`] index THREADING a typed
/// [`Self::suggest_closest`] hint alongside the substrate-wide
/// [`Self::Unknown`] carrier on the reject arm — the (ordering)
/// sibling of [`Self::parse_index_of_label_with_hint`] one
/// ordering-axis over on the (allocating carrier, `&str → usize`
/// with-hint) surface AND the (side-effect) sibling of
/// [`Self::sorted_index_of_label_with_hint`] one side-effect axis
/// over on the (`&str → usize` lex-order with-hint) surface AND
/// the (hint) sibling of [`Self::parse_sorted_index_of_label`] one
/// hint-axis over on the (allocating carrier, `&str → usize`
/// lex-order) surface. Where [`Self::parse_index_of_label_with_hint`]
/// projects the accept-arm variant through [`Self::index_of`]
/// (declaration order), this method projects it through
/// [`Self::sorted_index_of`] (lex order), so the caller gets the
/// canonical alphabetic-order slot AND the substrate-wide
/// [`Self::Unknown`] carrier AND the typed
/// [`Self::suggest_closest`] near-miss slot through ONE call the
/// substrate's diagnostic engine binds to.
///
/// On exact match returns `Ok(idx)` where
/// `idx == v.sorted_index_of()` for the canonical variant `v`
/// bound to label `s` (the hint slot stays absent because
/// [`Self::suggest_closest`] never fires on the accept arm — a
/// successful decode short-circuits before the near-miss
/// projection runs, so the substrate-wide "did you mean …?"
/// surface never double-emits the same variant once as a
/// successful decode and once as a hint). On miss returns
/// `Err((unknown, hint))` where `unknown` is the typed
/// [`Self::Unknown`] carrier owning a [`String`] copy of `s` and
/// rendering the substrate-wide `unknown {SET_LABEL}: {input}`
/// shape through [`Display`](core::fmt::Display) — the SAME
/// carrier shape [`Self::parse_label`] /
/// [`Self::parse_index_of_label`] / [`Self::parse_sorted_index_of_label`]
/// / [`Self::parse_label_with_hint`] /
/// [`Self::parse_index_of_label_with_hint`] emit on the reject
/// path, funnelled through ONE structural rejection variant every
/// `?`-operator-chained decoder / typed-`serde`-error surface /
/// substrate-wide diagnostic pipeline binds to — and `hint` is
/// the typed variant [`Self::suggest_closest`] keys on: `Some(v)`
/// when a canonical label sits within the substrate-wide bounded
/// edit distance, `None` when no candidate qualifies (the
/// conservative-suggestion contract — silent over guessing).
///
/// Peer of [`Self::parse_index_of_label_with_hint`] one
/// ordering-axis over on the (allocating carrier, `&str → usize`
/// with-hint) surface: both share the SAME
/// `Result<usize, (Self::Unknown, Option<Self>)>` shape AND the
/// SAME two-primitive-composition body — differing only in
/// whether they project through [`Self::index_of`] (declaration
/// order) or [`Self::sorted_index_of`] (lex order). Peer of
/// [`Self::parse_sorted_index_of_label`] one hint-axis over on
/// the (allocating carrier, `&str → usize` lex-order) surface:
/// where [`Self::parse_sorted_index_of_label`] rejects with a bare
/// [`Self::Unknown`], this method threads the typed near-miss
/// hint alongside the carrier. Peer of
/// [`Self::sorted_index_of_label_with_hint`] one side-effect-axis
/// over on the (`&str → usize` lex-order with-hint) surface: where
/// [`Self::sorted_index_of_label_with_hint`] returns a bare
/// `Result<usize, Option<Self>>` (no carrier allocation on
/// rejection), this method materializes the typed carrier
/// alongside the hint.
///
/// The (side-effect × hint) 2×2 matrix on the (`&str → usize`
/// lex-order) row partitions post-lift:
///
/// | Side-effect on reject | No hint | With hint |
/// |--------------------------------------|----------------------------------------|----------------------------------------------------|
/// | Allocating (materialize carrier) | [`Self::parse_sorted_index_of_label`] | [`Self::parse_sorted_index_of_label_with_hint`] |
/// | Non-allocating (bare `Option`/hint) | [`Self::sorted_index_of_label`] | [`Self::sorted_index_of_label_with_hint`] |
///
/// Together with [`Self::parse_index_of_label_with_hint`] and
/// [`Self::sorted_index_of_label_with_hint`] this method CLOSES
/// the (return-type × side-effect × ordering × hint) 4-axis
/// surface's (`usize`, allocating, lex, with-hint) corner — the
/// last unopened cell on the two `usize`-typed return-type rows
/// across the (side-effect × ordering × hint) 2×2×2 cube. Every
/// generic consumer that wants any typed `usize` slot decode of
/// `&str` — declaration OR lex, with-hint OR no-hint, allocating
/// OR non-allocating carrier — binds to ONE typed method on the
/// trait, and the closed-set (`&str → usize`) structured-decode
/// surface evolves at ONE site per corner rather than at every
/// consumer.
///
/// Default body composes [`Self::parse_label_with_hint`] with
/// [`Self::sorted_index_of`] verbatim — the
/// `Result<usize-lex, (Self::Unknown, Option<Self>)>` shape is a
/// typed CONSEQUENCE of the two pre-existing primitives, not a
/// third codepath. [`Result::map`] on the Ok arm threads the
/// `Result<Self, (Self::Unknown, Option<Self>)>` shape
/// [`Self::parse_label_with_hint`] emits through
/// [`Self::sorted_index_of`], preserving the reject-arm tuple
/// verbatim, so the (`usize`-lex-typed accept, tuple-typed reject)
/// shape falls out of the composition without a hand-rolled tuple
/// constructor. Implementors override only when the composition
/// needs to diverge (no production implementor reaches for this
/// today; the axis exists for the same reason [`Self::parse_label`]
/// / [`Self::parse_index_of_label`] /
/// [`Self::parse_sorted_index_of_label`] /
/// [`Self::parse_label_with_hint`] /
/// [`Self::parse_index_of_label_with_hint`] /
/// [`Self::sorted_index_of_label_with_hint`] overrides exist — a
/// typed escape hatch the trait surface exposes rather than
/// forcing the implementor to hand-roll the impl). An implementor
/// that overrides [`Self::parse_label_with_hint`] OR
/// [`Self::sorted_index_of`] (a future perfect-hash carrier-
/// decoder-with-hint, a future canonicalization-aware label
/// projection, a future const-fn [`Self::sorted_index_of`] axis)
/// propagates the override through this default body to the
/// allocating-carrier lex-decode with-hint arm automatically; the
/// (`&str → usize` lex-order with carrier AND hint) decode
/// funnels every sweep through ONE typed primitive on each of the
/// (accept, reject) partition arms.
///
/// The (accept, reject) alignment with
/// [`Self::parse_label_with_hint`] — the two methods MUST agree
/// on membership at every `&str` payload (both accept the same
/// inputs, both reject the same inputs, both surface the SAME
/// [`Self::Unknown`] carrier shape on rejection, both surface the
/// SAME `Option<Self>` hint variant on rejection) — is guaranteed
/// by the default composition and pinned by the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (87) on
/// every implementor, so a passing well-formedness sweep means
/// every generic consumer can call
/// `parse_sorted_index_of_label_with_hint` on any `&str` payload
/// and expect the same `Result`-typed answer at every crate
/// boundary AND the SAME `(Self::Unknown, Option<Self>)` tuple
/// variant on rejection as [`Self::parse_label_with_hint`]
/// surfaces.
///
/// Future consumers — a lex-order `?`-operator-chained config
/// decoder that reads a `&str` field and emits its lex-order slot
/// directly as a `u8` for a per-lex-slot lookup table AND
/// propagates the natural `?`-friendly [`Self::Unknown`] carrier
/// on rejection AND (through a downstream
/// `map_err(|(_, hint)| hint)` or
/// `inspect_err(|(_, hint)| render_hint(hint))` shim) surfaces
/// the typed near-miss WITHOUT re-running
/// [`Self::suggest_closest`] at the caller; a
/// `serde::Deserialize`-shaped visitor over a `&str` enum
/// wire-form whose typed slot storage is keyed on lex order (a
/// wire-format that pins byte-order stability on alphabetic
/// order — a legal / regulatory contract that pins the byte-order
/// semantics on the CANONICAL alphabetic order rather than the
/// DECLARATION order — the two are structurally distinct when the
/// closed set's canonical ordering is defined by alphabetic
/// order) AND whose `Error` type carries both the substrate-wide
/// carrier AND the typed near-miss hint; an LSP config-diagnostic
/// renderer that maps parsed labels back to their canonical
/// lex-order slot for stable alphabetic per-slot rendering AND
/// surfaces both the same substrate-wide `unknown {SET_LABEL}:
/// {input}` phrase AND a `did you mean <hint.label()>?` next to
/// the bare rejection on the SAME diagnostic frame — bind to ONE
/// trait method instead of hand-rolling either
/// `T::parse_label_with_hint(s).map(T::sorted_index_of)` (which
/// re-derives the same two-primitive composition at every
/// callsite AND makes every downstream site depend on
/// [`Self::parse_label_with_hint`]'s tuple-typed reject shape) OR
/// the inline
/// `T::parse_sorted_index_of_label(s).map_err(|u| (u, T::suggest_closest(s)))`
/// (which re-derives the underlying three-primitive composition
/// at every callsite AND drops the
/// [`Self::parse_label_with_hint`] override propagation that
/// keeps every allocating-carrier lex-decode with-hint consumer
/// aligned on a single typed dispatch) at each callsite, and the
/// closed-set (`&str → usize` allocating-carrier lex-order decode
/// with hint) surface evolves at ONE site rather than per-
/// consumer.
///
/// THEORY.md §III — the typescape; the allocating-carrier
/// (`&str → usize` lex with hint) decode becomes a TYPE
/// projection on the trait rather than a per-consumer inline
/// `Self::parse_label_with_hint(s).map(Self::sorted_index_of)`
/// composition at every downstream label-to-lex-slot-with-carrier-
/// AND-hint site. The (return-type × side-effect × hint ×
/// ordering) 4-axis surface's (`usize`-lex, allocating, with-hint)
/// corner binds at ONE typed method rather than at per-consumer
/// inline `parse_label_with_hint(s).map(sorted_index_of)`
/// composition, mirroring clause (86)'s pin one ordering-axis
/// over on the (`usize`-decl, allocating, with-hint) corner AND
/// clause (83)'s pin one side-effect-axis over on the (`usize`-
/// lex, non-allocating, with-hint) corner. Together (7) + (83) +
/// (86) + (87) close the with-hint face across BOTH ordering
/// columns at BOTH side-effect columns on the `usize`-typed
/// return-type row of the 4-axis surface — the (`Self`-typed,
/// lex-ordering) corner collapses onto (7) because the carrier
/// decode's typed variant carries no ordering-axis distinction,
/// so the with-hint face of the 4-axis surface CLOSES at ALL its
/// populated corners.
/// THEORY.md §V.1 — knowable platform; the allocating-carrier
/// (`&str → usize` lex with hint) decode was an unnamed compound
/// of [`Self::parse_label_with_hint`] + [`Self::sorted_index_of`]
/// pre-lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not ONE parse-lex-index-decode-
/// with-hint-shape-per-crate. Clause (87) pins the composition
/// against the natural `parse_label_with_hint(s).map(
/// sorted_index_of)` shape on every implementor so a passing
/// well-formedness sweep means every generic consumer can call
/// `parse_sorted_index_of_label_with_hint` on any `&str` payload
/// and expect the same `Result`-typed answer at every crate
/// boundary AND the SAME `(Self::Unknown, Option<Self>)` tuple
/// variant on rejection.
/// THEORY.md §VI.1 — generation over composition; the
/// allocating-carrier direct-lex-decode-with-hint emerges from
/// the composition of TWO substrate primitives
/// ([`Self::parse_label_with_hint`], [`Self::sorted_index_of`])
/// rather than as a per-implementor inline
/// `parse_label_with_hint(s).map(sorted_index_of)` compound. A
/// future tightening of either primitive (a future perfect-hash
/// `parse_label_with_hint`, a future Damerau-Levenshtein lift on
/// [`Self::suggest_closest`] the composition threads through, a
/// future const-fn [`Self::sorted_index_of`] axis that makes the
/// projection callable in const contexts) propagates to every
/// closed-set allocating-carrier direct-lex-decode-with-hint
/// consumer through ONE trait body.
///
/// Frontier inspiration: rustc's `Symbol::intern` composed with
/// `find_best_match_for_name` composed with a lex-sorted symbol-
/// table index projection — the typed-symbol lookup with a
/// substrate-wide interned-string carrier on rejection composed
/// with a bounded near-miss adornment AND a stable per-symbol
/// lex-order slot projection, all through ONE call the diagnostic
/// engine binds to. MLIR's `RegisteredOperationName::lookup(
/// StringRef)` composed with `DiagnosticEngine::suggestBestMatch`
/// composed with `getStableIndexByName()` on the lex-sorted Op
/// registry gives the same shape one vocabulary over on the C++
/// side — a bare `lookup` misses, a `suggestBestMatch` sidechannel
/// emits the near-miss, and `getStableIndexByName()` projects the
/// accept-arm registered op onto its stable lex slot; this method
/// fuses the three into ONE call through the tuple reject-arm.
/// Racket's `(hash-ref/failure enum sym make-unknown)` composed
/// with `(enum-suggest-closest enum sym)` composed with
/// `(enum-sort-index enum sym)` on a closed enum stands as the
/// same shape one vocabulary over on the Lisp-VM side.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing
/// [`Self::parse_label_with_hint`] + [`Self::sorted_index_of`]
/// surfaces — no new dep, no new IR layer, no supertrait bound.
fn parse_sorted_index_of_label_with_hint(
s: &str,
) -> ::std::result::Result<usize, (Self::Unknown, ::std::option::Option<Self>)> {
<Self as ClosedSet>::parse_label_with_hint(s).map(<Self as ClosedSet>::sorted_index_of)
}
/// The declaration-order neighbor immediately AFTER `self` in
/// [`Self::ALL`] — `Some(Self::ALL[self.index_of() + 1])` when
/// `self` is not the tail, [`None`] otherwise.
///
/// The forward-direction arm of the (forward, backward) neighbor
/// axis over the closed set's declaration-order chain. Together
/// with [`Self::prev`] the pair closes the (endpoint = 0,
/// endpoint = `CARDINALITY - 1`) partition of the neighbor
/// surface — every generic consumer that walks the closed set as
/// a bounded chain (a state-machine iterator that steps
/// [`Self::first`] → [`Self::last`] one variant at a time, a
/// wraparound-cursor renderer that highlights the "next choice"
/// in an LSP completion list, a truth-table property test that
/// exercises adjacent-variant transitions, a signal-fold reducer
/// that walks the chain accumulating state) binds to ONE typed
/// neighbor method rather than hand-rolling either
/// `Self::from_index(self.index_of() + 1)` (which re-derives the
/// same two-primitive composition at every callsite AND makes
/// every downstream site depend on the `+ 1` arithmetic) OR a
/// per-implementor inline `match self { A => Some(B), B =>
/// Some(C), C => None }` (which re-derives the per-variant
/// neighbor table at every callsite AND drifts silently when
/// [`Self::ALL`] gains a new variant).
///
/// Sibling posture to [`Self::last`] on the (forward-neighbor,
/// tail-endpoint) axis of the closed-set traversal surface —
/// `T::last().next() == None` is the natural fixpoint the
/// forward-neighbor axis and the tail-endpoint anchor share.
/// Sibling posture to [`Self::prev`] one axis over on the
/// (forward, backward) direction partition of the neighbor
/// surface: this method returns the declaration-order successor,
/// [`Self::prev`] returns the declaration-order predecessor. The
/// (endpoint × direction) 2×2 matrix over the closed-set
/// traversal surface partitions post-lift:
///
/// | Direction \\ Boundary | Interior | Boundary |
/// |---------------------------|----------------------|------------------|
/// | Forward (declaration) | [`Self::next`] | [`Self::last`] |
/// | Backward (declaration) | [`Self::prev`] | [`Self::first`] |
///
/// Default body composes [`Self::index_of`] with
/// [`Self::from_index`] verbatim — the neighbor projection is a
/// typed CONSEQUENCE of the pre-existing (variant ↔ `usize`
/// array index) bijection, not a third codepath. Implementors
/// override only when the neighbor surface needs to diverge from
/// the natural `from_index(index_of(self) + 1)` shape (no
/// production implementor reaches for this today; the axis
/// exists for the same reason `via` / `set_label` / `labels` /
/// `from_index` / `first` / `last` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing
/// the implementor to hand-roll the impl). An implementor that
/// overrides [`Self::from_index`] propagates the override through
/// this default body automatically; the (variant → variant)
/// forward-neighbor projection funnels through ONE typed
/// primitive.
///
/// The bounded-neighbor contract — the tail arm returns [`None`]
/// for [`Self::last`] — is guaranteed by the default composition
/// through [`Self::from_index`]'s `<[T]>::get` slice-bounded
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (26) pins the
/// composition against the natural
/// `from_index(index_of(self) + 1)` shape AND the tail-endpoint
/// `None` guard on every implementor, so a passing well-
/// formedness sweep means every generic consumer can call
/// [`Self::next`] on any typed variant and expect the same
/// [`Option`]-typed answer at every crate boundary.
///
/// Future consumers — a state-machine iterator that walks
/// [`Self::first`] → [`Self::last`] one variant at a time via
/// `let mut cur = T::first(); while let Some(v) = cur.next() { ...
/// cur = v; }` without threading either `T::ALL`'s slice-index
/// API OR a per-variant `match` block through the iterator body,
/// a wraparound-cursor renderer that highlights the "next choice"
/// in an LSP completion list by composing `self.next().unwrap_or(
/// T::first())` — the wraparound is a typed CONSEQUENCE of the
/// bounded-neighbor axis, an implementor's saga-step engine that
/// advances phase-by-phase through the workload lifecycle by
/// binding each phase's forward transition to [`Self::next`], a
/// truth-table property test that exercises adjacent-variant
/// transitions without re-deriving the (variant → next-variant)
/// mapping at each callsite, a signal-fold reducer that walks
/// the chain accumulating state per-neighbor — bind to ONE trait
/// method instead of hand-rolling either the
/// `T::from_index(self.index_of() + 1)` composition (which
/// re-derives the same two-primitive composition at every
/// callsite AND makes every downstream site depend on the
/// arithmetic) OR the inline `T::ALL.get(self.index_of() +
/// 1).copied()` (which re-derives the underlying three-primitive
/// composition at every callsite) at each callsite, and the
/// closed-set forward-neighbor projection surface evolves at ONE
/// site rather than per-consumer.
///
/// THEORY.md §III — the typescape; the (variant → forward
/// neighbor) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline
/// `Self::from_index(self.index_of() + 1)` composition at every
/// downstream traversal site. The (forward, backward) direction
/// axis of the closed-set traversal surface partitions
/// exhaustively into TWO typed projections, each with a distinct
/// load-bearing consumer surface — forward walk for
/// [`Self::next`], backward walk for [`Self::prev`].
/// THEORY.md §V.1 — knowable platform; the (variant → forward
/// neighbor) projection was an unnamed compound of
/// [`Self::index_of`] + [`Self::from_index`] + `+ 1` arithmetic
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not one forward-neighbor-shape-per-
/// crate. The well-formedness clause (26) pins the composition
/// against the natural `from_index(index_of(self) + 1)` shape AND
/// the tail-endpoint `None` guard on every implementor so a
/// passing sweep means every generic consumer can call
/// [`Self::next`] on any typed variant and expect the same
/// [`Option`]-typed answer at every crate boundary.
/// THEORY.md §VI.1 — generation over composition; the (variant
/// → forward neighbor) projection emerges from the composition
/// of TWO substrate primitives ([`Self::index_of`],
/// [`Self::from_index`]) via `usize` `+ 1` arithmetic rather
/// than as a per-implementor `match self { A => Some(B), B =>
/// Some(C), C => None }` block. A future tightening of either
/// primitive (a future perfect-hash `from_index`, a future
/// const-fn `index_of` axis that makes the projection callable
/// in const contexts) propagates to every closed-set forward-
/// neighbor consumer through this method's body.
///
/// Frontier inspiration: Racket's `enum-next` on closed
/// enumerations (the direct-neighbor projection on the
/// declaration-order chain); Idris's `Fin n` finite-cardinality
/// type's `weakenN` / `strengthenN` neighbor operators on the
/// non-empty finite-type universe; Haskell's `succ` on the
/// `Bounded + Enum` type-class pair (which panics at the tail
/// endpoint rather than returning an `Option`, one design
/// decision away — this method takes the `Option`-typed panic-
/// free arm); MLIR's `RegisteredOperationName::next()` on the
/// declaration-order Op registry; Rust's `strum::EnumIter` /
/// `strum::IntoEnumIterator::iter().skip_while(|v| *v != self)
/// .nth(1)` composed through the iterator API. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::index_of`] +
/// [`Self::from_index`] surfaces via `usize` `+ 1` arithmetic —
/// no new dep, no new IR layer, no supertrait bound, no panic on
/// the tail-endpoint boundary.
fn next(self) -> Option<Self> {
<Self as ClosedSet>::from_index(<Self as ClosedSet>::index_of(self) + 1)
}
/// The declaration-order neighbor immediately BEFORE `self` in
/// [`Self::ALL`] — `Some(Self::ALL[self.index_of() - 1])` when
/// `self` is not the head, [`None`] otherwise.
///
/// Sibling posture to [`Self::next`] one axis over on the
/// (forward, backward) direction partition of the closed-set
/// neighbor surface: [`Self::next`] returns the declaration-order
/// successor, this method returns the declaration-order
/// predecessor. See [`Self::next`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the backward-direction arm of the same axis
/// and inherits every property from the forward arm's
/// documentation, differing only in the `- 1` arithmetic and the
/// head-endpoint underflow guard.
///
/// Default body composes [`Self::index_of`] with
/// [`Self::from_index`] under a `usize` `- 1` subtraction guarded
/// on `index_of(self) > 0` — the head-endpoint arm returns
/// [`None`] BEFORE the subtraction is attempted, so the `usize`
/// arithmetic never underflows. Implementors override only when
/// the neighbor surface needs to diverge from the natural
/// `from_index(index_of(self) - 1)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `from_index` /
/// `first` / `last` / `next` overrides exist — a typed escape
/// hatch rather than forcing the implementor to hand-roll the
/// impl). An implementor that overrides [`Self::from_index`]
/// propagates the override through this default body
/// automatically; the (variant → variant) backward-neighbor
/// projection funnels through ONE typed primitive.
///
/// The bounded-neighbor contract — the head arm returns [`None`]
/// for [`Self::first`] — is guaranteed by the explicit
/// `index_of(self) == 0` guard; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (26) pins the
/// composition against the natural
/// `from_index(index_of(self) - 1)` shape on interior variants
/// AND the head-endpoint `None` guard on every implementor, so a
/// passing well-formedness sweep means every generic consumer
/// can call [`Self::prev`] on any typed variant and expect the
/// same [`Option`]-typed answer at every crate boundary.
/// `T::first().prev() == None` is the natural fixpoint the
/// backward-neighbor axis and the head-endpoint anchor share,
/// mirroring the `T::last().next() == None` fixpoint on the
/// forward-neighbor / tail-endpoint pair.
fn prev(self) -> Option<Self> {
let i = <Self as ClosedSet>::index_of(self);
if i == 0 {
None
} else {
<Self as ClosedSet>::from_index(i - 1)
}
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately AFTER `self` in [`Self::ALL`] — the label
/// of [`Self::next`] projected through [`Self::label`], or [`None`]
/// when `self` is the declaration-order tail-endpoint.
///
/// The `&'static str`-return sibling of [`Self::next`] on the
/// declaration axis of the (return-type × direction) 2×2 matrix
/// over the (`Self`-return, `&'static str`-return) partition of
/// the declaration-order neighbor surface. Together with
/// [`Self::prev_label`], the pair closes the (return-type ×
/// direction) 2×2 declaration-axis label-shaped neighbor matrix
/// alongside the pre-existing [`Self::next`] / [`Self::prev`]
/// (`Self`-return) pair:
///
/// | Return-type \\ Direction | Forward | Backward |
/// |--------------------------|---------------------|---------------------|
/// | `Self` | [`Self::next`] | [`Self::prev`] |
/// | `&'static str` | [`Self::next_label`]| [`Self::prev_label`]|
///
/// Every generic consumer that wants the declaration-order
/// forward-neighbor CANONICAL LABEL rendering (a diagnostic
/// emitter that renders `"advanced to <next-label>"` after every
/// state-machine step without threading the typed variant through
/// [`Self::label`] at the callsite, a Kubernetes annotation
/// stamper that writes the successor-phase label onto a
/// per-transition CRD without materializing the typed successor,
/// a per-slot audit trail that logs the forward-neighbor label at
/// every advance without a two-step `v.next()?.label()`
/// composition at each rendering site, a `tatara-check` diagnostic
/// that displays the "expected next: <label>" hint on a saga-step
/// misalignment) binds to ONE trait method rather than hand-rolling
/// the `Self::next(self).map(<Self as ClosedSet>::label)`
/// composition at every callsite AND makes every downstream site
/// depend on the two-primitive composition.
///
/// Sibling posture to [`Self::first_label`] / [`Self::last_label`]
/// one structural landmark over on the (endpoint anchor,
/// neighbor) axis of the `&'static str`-return column: the
/// endpoint-anchor pair projects the head / tail labels
/// (guaranteed non-empty by clause (1)'s non-empty ALL), this
/// method projects the forward-neighbor label as an
/// [`Option`]-typed value because the tail-endpoint arm has no
/// forward neighbor to render.
///
/// Default body composes [`Self::next`] with [`Self::label`]
/// through `Option::map` — the label-shaped forward-neighbor
/// projection is a typed CONSEQUENCE of the pre-existing
/// [`Self::next`] surface funneled through [`Self::label`], not a
/// third codepath. Implementors override only when the
/// composition needs to diverge from the natural
/// `next().map(label)` shape (no production implementor reaches
/// for this today; the axis exists for the same reason `via` /
/// `set_label` / `labels` / `first_label` / `next` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::next`] propagates the override through this
/// default body automatically; the (variant → forward-neighbor
/// label) projection funnels through ONE typed primitive.
///
/// The bounded-neighbor-label contract — the tail-endpoint arm
/// returns [`None`] — is guaranteed by the default composition
/// through [`Self::next`]'s `Option::map` shape; the
/// well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (58) pins the composition against the natural
/// `next().map(label)` shape AND the tail-endpoint `None` guard
/// on every implementor, so a passing well-formedness sweep means
/// every generic consumer can call [`Self::next_label`] on any
/// typed variant and expect the same [`Option`]-typed answer at
/// every crate boundary. `T::last().next_label() == None` is the
/// natural fixpoint the forward-neighbor-label axis and the
/// tail-endpoint anchor share, mirroring the `T::last().next() ==
/// None` fixpoint one return-type axis over.
///
/// THEORY.md §III — the typescape; the (variant → forward-neighbor
/// label) projection becomes a TYPE projection on the trait rather
/// than a per-consumer inline `self.next().map(|v| v.label())`
/// composition at every downstream label-shaped forward-neighbor
/// rendering site. The (return-type × direction) 2×2 declaration-
/// axis neighbor matrix partitions exhaustively into FOUR typed
/// projections, each with a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the (variant → forward-
/// neighbor label) projection was an unnamed compound of
/// [`Self::next`] + [`Self::label`] + `Option::map` pre-lift;
/// naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the two substrate primitives — generic consumers see ONE
/// method, not one forward-neighbor-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// forward-neighbor label) projection emerges from the
/// composition of TWO substrate primitives ([`Self::next`],
/// [`Self::label`]) via `Option::map` rather than as a per-
/// implementor `match self { A => Some("b-label"), ... }` block.
///
/// Frontier inspiration: Racket's `(enum-next-label enum sym)` on
/// a closed enumeration (the direct label-projection sibling of
/// `enum-next`); Idris's `Fin n` with a `showFin` composed
/// through `weakenN` on the declaration-order chain; MLIR's
/// `RegisteredOperationName::next().getName()` folded to ONE
/// method on the Op registry's declaration-order chain; Rust's
/// `strum::EnumIter::iter().skip_while(|v| *v != self).nth(1)
/// .map(|v| v.get_str())` composed through the iterator API.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::next`] + [`Self::label`]
/// surfaces via `Option::map` — no new dep, no new IR layer, no
/// supertrait bound, no allocation.
fn next_label(self) -> Option<&'static str> {
<Self as ClosedSet>::next(self).map(<Self as ClosedSet>::label)
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately BEFORE `self` in [`Self::ALL`] — the
/// label of [`Self::prev`] projected through [`Self::label`], or
/// [`None`] when `self` is the declaration-order head-endpoint.
///
/// Sibling posture to [`Self::next_label`] one direction over on
/// the (forward, backward) direction partition of the declaration-
/// axis label-shaped neighbor surface: [`Self::next_label`]
/// returns the declaration-order successor label, this method
/// returns the declaration-order predecessor label. See
/// [`Self::next_label`] for the shared design rationale, the
/// (return-type × direction) 2×2 matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the backward-direction arm of the
/// same axis and inherits every property from the forward arm's
/// documentation, differing only in the composition through
/// [`Self::prev`] instead of [`Self::next`] and the head-endpoint
/// `None` guard rather than the tail-endpoint `None` guard.
///
/// Default body composes [`Self::prev`] with [`Self::label`]
/// through `Option::map`. The bounded-neighbor-label contract —
/// the head-endpoint arm returns [`None`] — is guaranteed by the
/// default composition through [`Self::prev`]'s head-endpoint
/// `None` guard; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (59) pins the
/// composition against the natural `prev().map(label)` shape AND
/// the head-endpoint `None` guard on every implementor.
/// `T::first().prev_label() == None` is the natural fixpoint the
/// backward-neighbor-label axis and the head-endpoint anchor
/// share, mirroring the `T::first().prev() == None` fixpoint one
/// return-type axis over.
///
/// Clauses (18) + (26) + (46) + (47) + (58) + (59) together CLOSE
/// the (return-type × direction × structural-landmark) 2×2×2 =
/// 8-corner declaration-axis label-and-variant endpoint-anchor +
/// neighbor hypercube: [`Self::first`] / [`Self::last`] on
/// (`Self`, endpoint) — clause (18); [`Self::next`] /
/// [`Self::prev`] on (`Self`, neighbor) — clause (26);
/// [`Self::first_label`] / [`Self::last_label`] on
/// (`&'static str`, endpoint) — clauses (46) + (47); and now
/// [`Self::next_label`] / [`Self::prev_label`] on
/// (`&'static str`, neighbor) — clauses (58) + (59). Every
/// generic consumer that binds any of the eight projection
/// methods sees the SAME structural answer at every crate
/// boundary regardless of which return-type / direction /
/// landmark axis corner it walks.
fn prev_label(self) -> Option<&'static str> {
<Self as ClosedSet>::prev(self).map(<Self as ClosedSet>::label)
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// AFTER `self` in [`Self::ALL`] — the position of [`Self::next`]
/// projected through [`Self::index_of`], or [`None`] when `self`
/// is the declaration-order tail-endpoint.
///
/// The `usize`-return arm of the (`Self`-return, `&'static str`-
/// return, `usize`-return) 3-way partition of the declaration-axis
/// bounded-neighbor surface. One return-type axis over from
/// [`Self::next`] (`Self`-return) and [`Self::next_label`]
/// (`&'static str`-return); together with [`Self::prev_index`] the
/// pair mirrors [`Self::next`] / [`Self::prev`] and
/// [`Self::next_label`] / [`Self::prev_label`] at the third return-
/// type corner of the (return-type × direction) 3×2 = 6-corner
/// declaration-axis bounded-neighbor return-shape matrix:
///
/// | Return-type \\ Direction | Forward | Backward |
/// |--------------------------|-----------------------|-----------------------|
/// | `Option<Self>` | [`Self::next`] | [`Self::prev`] |
/// | `Option<&'static str>` | [`Self::next_label`] | [`Self::prev_label`] |
/// | `Option<usize>` | [`Self::next_index`] | [`Self::prev_index`] |
///
/// Every generic consumer that renders the declaration-order
/// forward-neighbor as an ARRAY INDEX (a compact wire codec
/// emitting `next_slot=<index>` for the successor's `T::ALL`
/// position, a Prometheus histogram bucketed on the successor's
/// slot, a fixed-arity `[u64; T::CARDINALITY]` per-slot counter
/// incrementing at `next_index(self).unwrap_or(cardinality)`, a
/// bitset state machine that sets the successor's bit at the
/// next-index position, a byte-tagged compact-encoding emitting
/// `variant.next_index().unwrap_or(u8::MAX as usize) as u8` at
/// the tail boundary, a Sekiban audit binner keying the next
/// slot's array index into a per-transition audit trail) binds
/// to ONE typed method rather than re-deriving the
/// `v.next().map(T::index_of)` two-primitive composition at every
/// callsite.
///
/// Sibling posture to [`Self::last`] on the (forward-neighbor,
/// tail-endpoint) axis of the declaration-order traversal surface
/// — `T::last().next_index() == None` is the natural fixpoint the
/// forward-neighbor-index axis and the tail-endpoint anchor share,
/// mirroring the `T::last().next() == None` fixpoint one return-
/// type axis over AND the `T::last().next_label() == None`
/// fixpoint one return-type axis over.
///
/// Default body composes [`Self::next`] with [`Self::index_of`]
/// through `Option::map` — the forward-neighbor-index projection
/// is a typed CONSEQUENCE of the pre-existing (declaration-order
/// forward neighbor, canonical array position) pair, not a third
/// codepath. Implementors override only when the forward-
/// neighbor-index surface needs to diverge from the natural
/// `next().map(index_of)` shape (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `sorted_variants` /
/// `index_of` / `from_index` / `first` / `last` / `next` /
/// `next_label` overrides exist — a typed escape hatch the trait
/// surface exposes rather than forcing the implementor to
/// hand-roll the impl). An implementor that overrides
/// [`Self::next`] OR [`Self::index_of`] propagates the override
/// through this default body automatically; the (variant →
/// forward-neighbor index) projection funnels through ONE typed
/// primitive.
///
/// The bounded-neighbor-index contract — the tail-endpoint arm
/// returns [`None`] — is guaranteed by the default composition
/// through [`Self::next`]'s `Option::map` shape; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (66) pins the composition against the natural
/// `next().map(index_of)` shape AND the tail-endpoint `None`
/// guard on every implementor, so a passing well-formedness sweep
/// means every generic consumer can call [`Self::next_index`] on
/// any typed variant and expect the same [`Option`]-typed answer
/// at every crate boundary.
///
/// THEORY.md §III — the typescape; the (variant → forward-
/// neighbor index) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `self.next().map(|v| v.index_of())` composition at every
/// downstream index-shaped forward-neighbor rendering site. The
/// (return-type × direction) 3×2 declaration-axis bounded-
/// neighbor return-shape matrix partitions exhaustively into SIX
/// typed projections, each with a distinct load-bearing consumer
/// surface. Extending the (return-type ∈ {`Self`, label}) 2×2
/// declaration-axis bounded-neighbor matrix one return-type
/// dimension into {`Self`, label, index} 3×2 makes the array-
/// position projection a first-class typed sibling of the typed-
/// variant and canonical-label siblings on the same axis.
/// THEORY.md §V.1 — knowable platform; the (variant → forward-
/// neighbor index) projection was an unnamed compound of
/// [`Self::next`] + [`Self::index_of`] + `Option::map` pre-lift;
/// naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic
/// consumers see ONE method, not one forward-neighbor-index-
/// shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// forward-neighbor index) projection emerges from the
/// composition of TWO substrate primitives ([`Self::next`],
/// [`Self::index_of`]) via `Option::map` rather than as a per-
/// implementor `match self { A => Some(1), B => Some(2), C =>
/// None }` block. A future tightening of either primitive (a
/// future perfect-hash `from_index` that speeds up `next`, a
/// future `#[closed_set(fast_index_of)]` derive attribute that
/// swaps in an inlined jump table for the linear sweep, a future
/// per-variant `#[closed_set(pin_index = N)]` reserved-slot
/// attribute) propagates to every closed-set forward-neighbor-
/// index consumer through this method's body.
///
/// Frontier inspiration: Racket's `(enum-next-index enum sym)` on
/// a closed enumeration (the direct index-projection sibling of
/// `enum-next`); Idris's `Fin n` composed through `weakenN` on
/// the successor's finite-position projection; MLIR's
/// `RegisteredOperationName::next().getIndex()` folded to ONE
/// method on the Op registry's declaration-order chain; Rust's
/// `strum::EnumIter::iter().position(|v| Some(v) == self.next())`
/// composed through the iterator API. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::next`] + [`Self::index_of`] surfaces
/// via `Option::map` — no new dep, no new IR layer, no supertrait
/// bound, no allocation, no `strum` / `enum-iterator` crate
/// dependency.
fn next_index(self) -> Option<usize> {
<Self as ClosedSet>::next(self).map(<Self as ClosedSet>::index_of)
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// BEFORE `self` in [`Self::ALL`] — the position of [`Self::prev`]
/// projected through [`Self::index_of`], or [`None`] when `self`
/// is the declaration-order head-endpoint.
///
/// Sibling posture to [`Self::next_index`] one direction over on
/// the (forward, backward) direction partition of the
/// declaration-axis index-shaped bounded-neighbor surface:
/// [`Self::next_index`] returns the declaration-order successor
/// index, this method returns the declaration-order predecessor
/// index. See [`Self::next_index`] for the shared design
/// rationale, the (return-type × direction) 3×2 matrix, override
/// axis, future-consumer inventory, THEORY.md grounding, and
/// frontier inspiration — this method is the backward-direction
/// arm of the same axis and inherits every property from the
/// forward arm's documentation, differing only in the composition
/// through [`Self::prev`] instead of [`Self::next`] and the
/// head-endpoint `None` guard rather than the tail-endpoint
/// `None` guard.
///
/// Default body composes [`Self::prev`] with [`Self::index_of`]
/// through `Option::map`. The bounded-neighbor-index contract —
/// the head-endpoint arm returns [`None`] — is guaranteed by the
/// default composition through [`Self::prev`]'s head-endpoint
/// `None` guard; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (67) pins the
/// composition against the natural `prev().map(index_of)` shape
/// AND the head-endpoint `None` guard on every implementor.
/// `T::first().prev_index() == None` is the natural fixpoint the
/// backward-neighbor-index axis and the head-endpoint anchor
/// share, mirroring the `T::first().prev() == None` fixpoint one
/// return-type axis over AND the `T::first().prev_label() ==
/// None` fixpoint one return-type axis over.
///
/// Clauses (26) + (58) + (59) + (66) + (67) together CLOSE the
/// (return-type × direction) 3×2 = 6-corner declaration-axis
/// bounded-neighbor return-shape surface across the trio of
/// return types: `Option<Self>` at clause (26) — [`Self::next`] /
/// [`Self::prev`]; `Option<&'static str>` at clauses (58) + (59)
/// — [`Self::next_label`] / [`Self::prev_label`]; `Option<usize>`
/// at clauses (66) + (67) — [`Self::next_index`] /
/// [`Self::prev_index`]. Every generic consumer that binds any of
/// the six projection methods sees the SAME structural answer at
/// every crate boundary regardless of which return-type /
/// direction axis corner it walks, and the return-type axis is
/// now closed at the {`Self`, label, index} trio on the
/// declaration-axis bounded arm — the lex-axis mirrors
/// (`sorted_next_index` / `sorted_prev_index`) and the wrapping
/// mirrors (`cycle_next_index` / `cycle_prev_index` /
/// `cycle_sorted_next_index` / `cycle_sorted_prev_index`) become
/// the natural follow-up axes on the same 3×2×(bounded, wrapping)
/// × (declaration, lex) surface.
fn prev_index(self) -> Option<usize> {
<Self as ClosedSet>::prev(self).map(<Self as ClosedSet>::index_of)
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor immediately
/// AFTER `self` in [`Self::sorted_variants`] — the lex position of
/// [`Self::sorted_next`] projected through [`Self::sorted_index_of`],
/// or [`None`] when `self` is the lex-tail-endpoint.
///
/// The lex-order forward-direction arm of the (declaration, lex) ×
/// (forward, backward) × (`Self`-return, `&'static str`-return,
/// `usize`-return) 2×2×3 = 12-corner index-and-label-and-variant
/// neighbor hypercube — one ordering axis over from
/// [`Self::next_index`] (declaration-order forward index) and one
/// return-type axis over from [`Self::sorted_next`] (lex-order
/// forward variant) AND from [`Self::sorted_next_label`] (lex-order
/// forward label). Together with [`Self::sorted_prev_index`], the
/// pair mirrors [`Self::next_index`] / [`Self::prev_index`] one
/// ordering axis over, closing the (`usize`-return, neighbor) corner
/// of the hypercube on BOTH ordering axes:
///
/// | Direction \\ Ordering | Declaration order | Lexicographic order |
/// |------------------------------|---------------------------|-----------------------------|
/// | Forward index | [`Self::next_index`] | [`Self::sorted_next_index`] |
/// | Backward index | [`Self::prev_index`] | [`Self::sorted_prev_index`] |
///
/// Every generic consumer that renders the lex-order forward-
/// neighbor slot of a typed variant (an alphabetized compact wire
/// codec emitting `next_lex_slot=<index>` for cross-boundary handoff,
/// an alphabetized-completion LSP cursor that binds
/// `slot.sorted_next_index()` as its lex-forward step, a lex-order
/// Prometheus per-lex-slot bucket that keys per-transition metrics
/// off the lex-successor's position, a lex-sorted bitset state
/// machine setting the lex-successor's bit without threading
/// `sorted_index_of` through a match arm at the callsite, a
/// Sekiban lex-sorted per-transition audit binner keying on the
/// next lex slot, an alphabetized carousel-widget renderer that
/// stamps `next-lex-slot=<index>` onto a per-tab annotation) binds
/// to ONE typed method on the trait rather than re-deriving the
/// `v.sorted_next().map(|n| n.sorted_index_of())` two-primitive
/// composition at every callsite.
///
/// Default body composes [`Self::sorted_next`] with
/// [`Self::sorted_index_of`] through `Option::map` — the lex-order
/// forward-neighbor-index projection is a typed CONSEQUENCE of the
/// pre-existing (lex neighbor, canonical lex position) pair, not a
/// third codepath. Implementors override only when the lex-neighbor-
/// index surface needs to diverge from the natural
/// `sorted_next().map(sorted_index_of)` shape (no production
/// implementor reaches for this today; the axis exists for the same
/// reason `via` / `set_label` / `labels` / `sorted_index_of` /
/// `from_sorted_index` / `sorted_first` / `sorted_last` /
/// `sorted_next` / `sorted_next_label` / `next_index` overrides
/// exist — a typed escape hatch the trait surface exposes rather
/// than forcing the implementor to hand-roll the impl). An
/// implementor that overrides [`Self::sorted_next`] OR
/// [`Self::sorted_index_of`] propagates the override through this
/// default body automatically; the (variant → lex-forward-neighbor
/// lex-slot) projection funnels through ONE typed primitive.
///
/// The bounded-lex-neighbor-index contract — the lex-tail arm
/// returns [`None`] — is guaranteed by the default composition
/// through [`Self::sorted_next`]'s `Option::map` shape; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (68) pins the composition against the natural
/// `sorted_next().map(sorted_index_of)` shape AND the lex-tail-
/// endpoint `None` guard on every implementor, so a passing well-
/// formedness sweep means every generic consumer can call
/// [`Self::sorted_next_index`] on any typed variant and expect the
/// same [`Option`]-typed answer at every crate boundary.
/// `T::sorted_last().sorted_next_index() == None` is the natural
/// fixpoint the forward-lex-neighbor-index axis and the lex-tail-
/// endpoint anchor share, mirroring the
/// `T::sorted_last().sorted_next() == None` fixpoint one return-type
/// axis over AND the `T::sorted_last().sorted_next_label() == None`
/// fixpoint one return-type axis over AND the
/// `T::last().next_index() == None` fixpoint one ordering axis over.
///
/// THEORY.md §III — the typescape; the (variant → lex-forward-
/// neighbor lex-slot) projection becomes a TYPE projection on the
/// trait rather than a per-consumer inline
/// `self.sorted_next().map(|v| v.sorted_index_of())` composition at
/// every downstream lex-order index-shaped forward-traversal site.
/// The (return-type × direction × ordering) 3×2×2 = 12-corner
/// bounded-neighbor return-shape hypercube partitions exhaustively
/// into TWELVE typed projections; the (`usize`-return, lex,
/// forward) corner lands at this method. Extending the (return-type
/// ∈ {`Self`, label}) 2×2×2 lex-axis bounded-neighbor matrix one
/// return-type dimension into {`Self`, label, index} 3×2×2 makes
/// the lex-slot projection a first-class typed sibling of the
/// typed-variant and canonical-label siblings on the lex-forward
/// axis.
/// THEORY.md §V.1 — knowable platform; the (variant → lex-forward-
/// neighbor lex-slot) projection was an unnamed compound of
/// [`Self::sorted_next`] + [`Self::sorted_index_of`] + `Option::map`
/// pre-lift; naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the two substrate primitives — generic consumers
/// see ONE method, not one lex-forward-neighbor-lex-slot-shape-per-
/// crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// lex-forward-neighbor lex-slot) projection emerges from the
/// composition of TWO substrate primitives ([`Self::sorted_next`],
/// [`Self::sorted_index_of`]) via `Option::map` rather than as a
/// per-implementor `match self { A => Some(1), ... }` block keyed on
/// the lex partition. A future tightening of either primitive (a
/// future perfect-hash `from_sorted_index` that speeds up
/// `sorted_next`, a future `#[closed_set(compare_labels_with = ...)]`
/// derive attribute that swaps the ordering, a future
/// `#[closed_set(fast_sorted_index_of)]` derive attribute that
/// swaps in an inlined jump table for the strict-`<` linear sweep)
/// propagates to every closed-set lex-forward-neighbor-lex-slot
/// consumer through this method's body.
///
/// Frontier inspiration: Racket's `(enum-next-index enum sym #:order
/// 'lex)` on a closed enumeration under the lexicographic ordering
/// (the direct index-projection sibling of `enum-next` on the lex
/// axis); Idris's `Fin n` with a `sortByLabel`-permuted labeling
/// projection composed through `weakenN` on the lex partition;
/// MLIR's `RegisteredOperationName::nextByLexicalOrder().getStableIndex()`
/// folded to ONE method on the lex-sorted Op registry; Rust's
/// `strum::EnumIter::iter().collect::<Vec<_>>().sort_by_key(|v|
/// v.get_str()).iter().position(|v| Some(v) == self.sorted_next())`
/// composed through the iterator API + a sorted-by-label prelude.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::sorted_next`] +
/// [`Self::sorted_index_of`] surfaces via `Option::map` — no new
/// dep, no new IR layer, no supertrait bound, no allocation, no
/// `strum` / `enum-iterator` crate dependency.
fn sorted_next_index(self) -> Option<usize> {
<Self as ClosedSet>::sorted_next(self).map(<Self as ClosedSet>::sorted_index_of)
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor immediately
/// BEFORE `self` in [`Self::sorted_variants`] — the lex position of
/// [`Self::sorted_prev`] projected through
/// [`Self::sorted_index_of`], or [`None`] when `self` is the lex-
/// head-endpoint.
///
/// Sibling posture to [`Self::sorted_next_index`] one direction over
/// on the (forward, backward) direction partition of the lex-axis
/// index-shaped bounded-neighbor surface: [`Self::sorted_next_index`]
/// returns the lex-order successor's lex-slot, this method returns
/// the lex-order predecessor's lex-slot. See
/// [`Self::sorted_next_index`] for the shared design rationale, the
/// (declaration, lex) × (forward, backward) × (`Self`-return,
/// `&'static str`-return, `usize`-return) 2×2×3 = 12-corner
/// hypercube, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// backward-direction arm of the same lex-axis and inherits every
/// property from the forward arm's documentation, differing only in
/// the composition through [`Self::sorted_prev`] instead of
/// [`Self::sorted_next`] and the lex-head-endpoint `None` guard
/// rather than the lex-tail-endpoint `None` guard.
///
/// Default body composes [`Self::sorted_prev`] with
/// [`Self::sorted_index_of`] through `Option::map`. The bounded-lex-
/// neighbor-index contract — the lex-head-endpoint arm returns
/// [`None`] — is guaranteed by the default composition through
/// [`Self::sorted_prev`]'s lex-head-endpoint `None` guard; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (69) pins the composition against the natural
/// `sorted_prev().map(sorted_index_of)` shape AND the lex-head-
/// endpoint `None` guard on every implementor.
/// `T::sorted_first().sorted_prev_index() == None` is the natural
/// fixpoint the backward-lex-neighbor-index axis and the lex-head-
/// endpoint anchor share, mirroring the
/// `T::sorted_first().sorted_prev() == None` fixpoint one return-type
/// axis over AND the `T::sorted_first().sorted_prev_label() == None`
/// fixpoint one return-type axis over AND the
/// `T::first().prev_index() == None` fixpoint one ordering axis
/// over.
///
/// Clauses (26) + (27) + (58) + (59) + (60) + (61) + (66) + (67) +
/// (68) + (69) together CLOSE the (declaration × lex) × (forward,
/// backward) × (`Self`-return, `&'static str`-return, `usize`-return)
/// 2×2×3 = 12-corner bounded-neighbor return-shape hypercube on the
/// closed-set traversal surface. Every generic consumer that binds
/// any of the twelve projection methods sees the SAME structural
/// answer at every crate boundary regardless of which ordering /
/// direction / return-type axis corner it walks, and the return-type
/// axis is now closed at the {`Self`, label, index} trio on BOTH
/// ordering axes of the bounded arm — the wrapping mirrors
/// (`cycle_next_index` / `cycle_prev_index` /
/// `cycle_sorted_next_index` / `cycle_sorted_prev_index`) become the
/// natural follow-up axes on the same 3×2×(bounded, wrapping) ×
/// (declaration, lex) surface.
fn sorted_prev_index(self) -> Option<usize> {
<Self as ClosedSet>::sorted_prev(self).map(<Self as ClosedSet>::sorted_index_of)
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately AFTER `self` in [`Self::sorted_variants`] —
/// the label of [`Self::sorted_next`] projected through
/// [`Self::label`], or [`None`] when `self` is the lex-tail-endpoint.
///
/// The lex-order forward-direction arm of the (declaration, lex) ×
/// (forward, backward) × (`Self`-return, `&'static str`-return) 2×2×2
/// = 8-corner label-and-variant neighbor hypercube — one ordering
/// axis over from [`Self::next_label`] (declaration-order forward
/// label) and one return-type axis over from [`Self::sorted_next`]
/// (lex-order forward variant). Together with [`Self::sorted_prev_label`],
/// the pair mirrors [`Self::next_label`] / [`Self::prev_label`] one
/// ordering axis over, closing the (`&'static str`-return, neighbor)
/// corner of the hypercube on BOTH ordering axes:
///
/// | Direction \\ Ordering | Declaration order | Lexicographic order |
/// |------------------------------|---------------------------|---------------------------|
/// | Forward label | [`Self::next_label`] | [`Self::sorted_next_label`] |
/// | Backward label | [`Self::prev_label`] | [`Self::sorted_prev_label`] |
///
/// Every generic consumer that renders the lex-order forward-neighbor
/// LABEL of a typed variant (an alphabetized-completion LSP cursor
/// that emits "next: <label>" for the lex-sorted successor as its
/// completion-hint payload, a lex-sorted `tatara-check` diagnostic
/// renderer that stamps `expected-next-lex-label: <label>` into a
/// per-slot audit trail without threading the typed variant through
/// `.label()` at the callsite, a Kubernetes annotation stamper that
/// writes a lex-successor phase label onto a per-transition CRD, a
/// lex-order compact-encoded wire codec that emits the successor's
/// label for cross-boundary handoff) binds to ONE typed method on
/// the trait rather than re-deriving the
/// `v.sorted_next().map(|n| n.label())` two-primitive composition at
/// every callsite.
///
/// Default body composes [`Self::sorted_next`] with [`Self::label`]
/// through `Option::map` — the lex-order forward-neighbor-label
/// projection is a typed CONSEQUENCE of the pre-existing (lex
/// neighbor, canonical label) pair, not a third codepath.
/// Implementors override only when the lex-neighbor-label surface
/// needs to diverge from the natural `sorted_next().map(label)` shape
/// (no production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_index_of` / `from_sorted_index` / `sorted_first` /
/// `sorted_last` / `sorted_next` / `sorted_prev` overrides exist — a
/// typed escape hatch the trait surface exposes rather than forcing
/// the implementor to hand-roll the impl). An implementor that
/// overrides [`Self::sorted_next`] propagates the override through
/// this default body automatically; the (variant → lex-forward-neighbor
/// label) projection funnels through ONE typed primitive.
///
/// The bounded-lex-neighbor-label contract — the lex-tail arm returns
/// [`None`] — is guaranteed by the default composition through
/// [`Self::sorted_next`]'s `Option::map` shape; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (60) pins
/// the composition against the natural `sorted_next().map(label)`
/// shape AND the lex-tail-endpoint `None` guard on every implementor,
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::sorted_next_label`] on any typed variant and
/// expect the same [`Option`]-typed answer at every crate boundary.
/// `T::sorted_last().sorted_next_label() == None` is the natural
/// fixpoint the forward-lex-neighbor-label axis and the lex-tail-
/// endpoint anchor share, mirroring the
/// `T::sorted_last().sorted_next() == None` fixpoint one return-type
/// axis over AND the `T::last().next_label() == None` fixpoint one
/// ordering axis over.
///
/// THEORY.md §III — the typescape; the (variant → lex-forward-
/// neighbor label) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline
/// `self.sorted_next().map(|v| v.label())` composition at every
/// downstream lex-order label-shaped forward-traversal site. The
/// (declaration, lex) × (forward, backward) × (`Self`-return,
/// `&'static str`-return) 2×2×2 = 8-corner label-and-variant
/// neighbor hypercube partitions exhaustively into EIGHT typed
/// projections, each with a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the (variant → lex-forward-
/// neighbor label) projection was an unnamed compound of
/// [`Self::sorted_next`] + [`Self::label`] + `Option::map` pre-lift;
/// naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the two substrate primitives — generic consumers see ONE
/// method, not one lex-forward-neighbor-label-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// lex-forward-neighbor label) projection emerges from the
/// composition of TWO substrate primitives ([`Self::sorted_next`],
/// [`Self::label`]) via `Option::map` rather than as a per-
/// implementor `match self { A => Some("b-label"), ... }` block. A
/// future tightening of either primitive (a future perfect-hash
/// `from_sorted_index` that speeds up `sorted_next`, a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute that
/// swaps the ordering, a future `#[closed_set(label = "…")]`
/// per-variant attribute rework) propagates to every closed-set
/// lex-forward-neighbor-label consumer through this method's body.
///
/// Frontier inspiration: Racket's `(enum-next-label enum sym #:order
/// 'lex)` on a closed enumeration under the lexicographic ordering
/// (the direct label-projection sibling of `enum-next` on the lex
/// axis); Idris's `Fin n` with a `showFin` composed through a
/// lex-sorted labeling projection on the finite-type universe;
/// MLIR's `RegisteredOperationName::nextByLexicalOrder().getName()`
/// folded to ONE method on the lex-sorted Op registry; Rust's
/// `strum::EnumIter::iter().collect::<Vec<_>>().sort_by_key(|v|
/// v.get_str()).skip_while(|v| *v != self).nth(1)
/// .map(|v| v.get_str())` composed through the iterator API + a
/// sorted-by-label prelude. Translation through pleme-io primitives:
/// a pure default method composing the trait's existing
/// [`Self::sorted_next`] + [`Self::label`] surfaces via `Option::map`
/// — no new dep, no new IR layer, no supertrait bound, no allocation,
/// no `strum` / `enum-iterator` crate dependency.
fn sorted_next_label(self) -> Option<&'static str> {
<Self as ClosedSet>::sorted_next(self).map(<Self as ClosedSet>::label)
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately BEFORE `self` in [`Self::sorted_variants`] —
/// the label of [`Self::sorted_prev`] projected through
/// [`Self::label`], or [`None`] when `self` is the lex-head-endpoint.
///
/// Sibling posture to [`Self::sorted_next_label`] one direction over
/// on the (forward, backward) direction partition of the lex-axis
/// label-shaped neighbor surface: [`Self::sorted_next_label`] returns
/// the lex-order successor label, this method returns the lex-order
/// predecessor label. See [`Self::sorted_next_label`] for the shared
/// design rationale, the (declaration × lex) × (forward, backward)
/// × (`Self`-return, `&'static str`-return) 2×2×2 = 8-corner
/// hypercube, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// backward-direction arm of the same lex-axis and inherits every
/// property from the forward arm's documentation, differing only in
/// the composition through [`Self::sorted_prev`] instead of
/// [`Self::sorted_next`] and the lex-head-endpoint `None` guard
/// rather than the lex-tail-endpoint `None` guard.
///
/// Default body composes [`Self::sorted_prev`] with [`Self::label`]
/// through `Option::map`. The bounded-lex-neighbor-label contract —
/// the lex-head-endpoint arm returns [`None`] — is guaranteed by the
/// default composition through [`Self::sorted_prev`]'s lex-head-
/// endpoint `None` guard; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (61) pins the
/// composition against the natural `sorted_prev().map(label)` shape
/// AND the lex-head-endpoint `None` guard on every implementor.
/// `T::sorted_first().sorted_prev_label() == None` is the natural
/// fixpoint the backward-lex-neighbor-label axis and the lex-head-
/// endpoint anchor share, mirroring the
/// `T::sorted_first().sorted_prev() == None` fixpoint one return-type
/// axis over AND the `T::first().prev_label() == None` fixpoint one
/// ordering axis over.
///
/// Clauses (18) + (26) + (27) + (46) + (47) + (48) + (49) + (58) +
/// (59) + (60) + (61) together CLOSE the (declaration × lex) ×
/// (forward, backward) × (`Self`-return, `&'static str`-return)
/// × (endpoint-anchor, neighbor) 2×2×2×2 = 16-corner label-and-
/// variant traversal hypercube on the closed-set neighbor and
/// endpoint-anchor surface. Every generic consumer that binds any of
/// the sixteen projection methods sees the SAME structural answer at
/// every crate boundary regardless of which ordering / direction /
/// return-type / landmark axis corner it walks.
fn sorted_prev_label(self) -> Option<&'static str> {
<Self as ClosedSet>::sorted_prev(self).map(<Self as ClosedSet>::label)
}
/// The lexicographic-order neighbor immediately AFTER `self` in
/// [`Self::sorted_variants`] — `Some(Self::sorted_variants()[
/// self.sorted_index_of() + 1])` when `self` is not the lex-tail,
/// [`None`] otherwise.
///
/// The forward-direction arm of the (forward, backward) neighbor
/// axis over the closed set's LEX-order chain — one ordering-axis
/// over from [`Self::next`], which walks the DECLARATION-order chain.
/// Together with [`Self::sorted_prev`], the pair closes the
/// (lex-endpoint = 0, lex-endpoint = `CARDINALITY - 1`) partition of
/// the lex-order neighbor surface, and together with the pre-existing
/// [`Self::next`] / [`Self::prev`] pair on the declaration axis
/// completes the (declaration × lex) × (forward, backward) 2×2
/// closed-set neighbor matrix:
///
/// | Direction \\ Ordering axis | Declaration order | Lexicographic order |
/// |----------------------------|--------------------|----------------------|
/// | Forward | [`Self::next`] | [`Self::sorted_next`] |
/// | Backward | [`Self::prev`] | [`Self::sorted_prev`] |
///
/// Every generic consumer that walks the closed set as a bounded
/// chain under lexicographic order (an alphabetized-completion LSP
/// cursor that steps [`Self::sorted_first`] → [`Self::sorted_last`]
/// one lex slot at a time, a lex-sorted `tatara-check` per-slot
/// diagnostic renderer that binds `slot.sorted_next()` as its
/// forward-traversal surface, a lex-order compact-encoded wire
/// codec that walks slot-by-slot from the head, a Sekiban audit
/// binner that iterates observed-slot lex neighbors, an
/// alphabetized property-test sweep that exercises adjacent-
/// lex-slot transitions) binds to ONE typed lex-neighbor method
/// rather than hand-rolling either
/// `Self::from_sorted_index(self.sorted_index_of() + 1)` (which
/// re-derives the same two-primitive composition at every callsite
/// AND makes every downstream site depend on the `+ 1` arithmetic)
/// OR a per-implementor inline `match self { ... }` keyed on the
/// lex slot (which re-derives the per-variant lex-neighbor table
/// at every callsite AND drifts silently when [`Self::ALL`] gains
/// a new variant that reorders the lex partition).
///
/// Sibling posture to [`Self::sorted_last`] on the (forward-neighbor,
/// lex-tail-endpoint) axis of the lex-order traversal surface —
/// `T::sorted_last().sorted_next() == None` is the natural fixpoint
/// the forward-lex-neighbor axis and the lex-tail-endpoint anchor
/// share, mirroring the `T::last().next() == None` fixpoint on the
/// declaration axis.
///
/// Default body composes [`Self::sorted_index_of`] with
/// [`Self::from_sorted_index`] verbatim — the lex-neighbor
/// projection is a typed CONSEQUENCE of the pre-existing (variant
/// ↔ `usize` lex-order position) bijection, not a third codepath.
/// Implementors override only when the lex-neighbor surface needs
/// to diverge from the natural
/// `from_sorted_index(sorted_index_of(self) + 1)` shape (no
/// production implementor reaches for this today; the axis exists
/// for the same reason `via` / `set_label` / `labels` /
/// `sorted_index_of` / `from_sorted_index` / `sorted_first` /
/// `sorted_last` / `next` / `prev` overrides exist — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::from_sorted_index`] propagates the override
/// through this default body automatically; the (variant → variant)
/// forward-lex-neighbor projection funnels through ONE typed
/// primitive.
///
/// The bounded-neighbor contract — the lex-tail arm returns
/// [`None`] for [`Self::sorted_last`] — is guaranteed by the
/// default composition through [`Self::from_sorted_index`]'s
/// bounded projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (27) pins the
/// composition against the natural
/// `from_sorted_index(sorted_index_of(self) + 1)` shape AND the
/// lex-tail-endpoint `None` guard on every implementor, so a
/// passing well-formedness sweep means every generic consumer can
/// call [`Self::sorted_next`] on any typed variant and expect the
/// same [`Option`]-typed answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (variant → forward
/// lex-neighbor) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline
/// `Self::from_sorted_index(self.sorted_index_of() + 1)` composition
/// at every downstream lex-order traversal site. The (declaration,
/// lex) × (forward, backward) 2×2 neighbor matrix over the
/// closed-set traversal surface partitions exhaustively into FOUR
/// typed projections, each with a distinct load-bearing consumer
/// surface.
/// THEORY.md §V.1 — knowable platform; the (variant → forward
/// lex-neighbor) projection was an unnamed compound of
/// [`Self::sorted_index_of`] + [`Self::from_sorted_index`] + `+ 1`
/// arithmetic pre-lift; naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the two lex-axis substrate
/// primitives — generic consumers see ONE method, not one
/// lex-forward-neighbor-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the (variant →
/// forward lex-neighbor) projection emerges from the composition
/// of TWO substrate primitives ([`Self::sorted_index_of`],
/// [`Self::from_sorted_index`]) via `usize` `+ 1` arithmetic rather
/// than as a per-implementor `match self { ... }` block. A future
/// tightening of either primitive (a future perfect-hash
/// `from_sorted_index`, a future
/// `#[closed_set(compare_labels_with = ...)]` derive attribute
/// that swaps the ordering) propagates to every closed-set
/// forward-lex-neighbor consumer through this method's body.
///
/// Frontier inspiration: Racket's `(enum-next enum sym #:order
/// 'lex)` on a closed enumeration under the lexicographic ordering;
/// Idris's `Fin n` with a lex-sorted labeling projection composed
/// through `weakenN` / `strengthenN` on the lex partition; MLIR's
/// `RegisteredOperationName::nextByLexicalOrder()` on the
/// lex-sorted Op registry; Haskell's `succ` composed with a
/// `sortBy comparingLabel` prelude on a `Bounded + Enum` type-class
/// pair; Rust's `strum::EnumIter` composed through a sorted-by-label
/// prelude with `.skip_while(|v| *v != self).nth(1)`. Translation
/// through pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::sorted_index_of`] +
/// [`Self::from_sorted_index`] surfaces via `usize` `+ 1`
/// arithmetic — no new dep, no new IR layer, no supertrait bound,
/// no panic on the lex-tail-endpoint boundary, no `strum` /
/// `enum-iterator` crate dependency.
fn sorted_next(self) -> Option<Self> {
<Self as ClosedSet>::from_sorted_index(<Self as ClosedSet>::sorted_index_of(self) + 1)
}
/// The lexicographic-order neighbor immediately BEFORE `self` in
/// [`Self::sorted_variants`] — `Some(Self::sorted_variants()[
/// self.sorted_index_of() - 1])` when `self` is not the lex-head,
/// [`None`] otherwise.
///
/// Sibling posture to [`Self::sorted_next`] one axis over on the
/// (forward, backward) direction partition of the lex-order
/// neighbor surface: [`Self::sorted_next`] returns the lex-order
/// successor, this method returns the lex-order predecessor. See
/// [`Self::sorted_next`] for the shared design rationale, sibling
/// 2×2 matrix, override axis, future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// backward-direction arm of the same lex-axis and inherits every
/// property from the forward arm's documentation, differing only
/// in the `- 1` arithmetic and the lex-head-endpoint underflow
/// guard.
///
/// Default body composes [`Self::sorted_index_of`] with
/// [`Self::from_sorted_index`] under a `usize` `- 1` subtraction
/// guarded on `sorted_index_of(self) > 0` — the lex-head-endpoint
/// arm returns [`None`] BEFORE the subtraction is attempted, so
/// the `usize` arithmetic never underflows. Implementors override
/// only when the lex-neighbor surface needs to diverge from the
/// natural `from_sorted_index(sorted_index_of(self) - 1)` shape
/// (no production implementor reaches for this today; the axis
/// exists for the same reason `via` / `set_label` / `labels` /
/// `from_sorted_index` / `sorted_first` / `sorted_last` / `next` /
/// `prev` / `sorted_next` overrides exist — a typed escape hatch
/// rather than forcing the implementor to hand-roll the impl). An
/// implementor that overrides [`Self::from_sorted_index`]
/// propagates the override through this default body automatically;
/// the (variant → variant) backward-lex-neighbor projection funnels
/// through ONE typed primitive.
///
/// The bounded-neighbor contract — the lex-head arm returns
/// [`None`] for [`Self::sorted_first`] — is guaranteed by the
/// explicit `sorted_index_of(self) == 0` guard; the well-formedness
/// contract [`assert_closed_set_well_formed`]'s new clause (27)
/// pins the composition against the natural
/// `from_sorted_index(sorted_index_of(self) - 1)` shape on interior
/// lex slots AND the lex-head-endpoint `None` guard on every
/// implementor, so a passing well-formedness sweep means every
/// generic consumer can call [`Self::sorted_prev`] on any typed
/// variant and expect the same [`Option`]-typed answer at every
/// crate boundary. `T::sorted_first().sorted_prev() == None` is the
/// natural fixpoint the backward-lex-neighbor axis and the
/// lex-head-endpoint anchor share, mirroring the
/// `T::sorted_last().sorted_next() == None` fixpoint on the
/// forward-lex-neighbor / lex-tail-endpoint pair AND the
/// `T::first().prev() == None` fixpoint one ordering axis over.
fn sorted_prev(self) -> Option<Self> {
let i = <Self as ClosedSet>::sorted_index_of(self);
if i == 0 {
None
} else {
<Self as ClosedSet>::from_sorted_index(i - 1)
}
}
/// The declaration-order neighbor immediately AFTER `self` in
/// [`Self::ALL`], WRAPPING to [`Self::first`] at the tail —
/// `self.next().unwrap_or(Self::first())`. Returns [`Self`],
/// never [`Option<Self>`]: the wrapping arm folds the tail-
/// endpoint boundary onto the head-endpoint anchor rather than
/// leaving the [`None`] the bounded-neighbor axis returns.
///
/// The wrapping-return arm of the (Option-typed, wrapping)
/// partition over the closed-set forward-neighbor surface — one
/// return-type axis over from [`Self::next`], which returns the
/// bounded [`Option<Self>`] variant. Together with
/// [`Self::cycle_prev`], the pair closes the (forward, backward)
/// direction axis of the WRAPPING arm on the declaration ordering
/// axis, and together with the pre-existing [`Self::next`] /
/// [`Self::prev`] pair opens the (Option-typed, wrapping) × (forward,
/// backward) 2×2 matrix on the declaration-axis neighbor surface:
///
/// | Return type \\ Direction | Forward | Backward |
/// |-----------------------------|--------------------|--------------------|
/// | Option-typed (bounded) | [`Self::next`] | [`Self::prev`] |
/// | Wrapping (cyclic) | [`Self::cycle_next`] | [`Self::cycle_prev`] |
///
/// Every generic consumer that walks the closed set as an
/// INFINITE cyclic chain under declaration order (a wraparound-
/// cursor LSP completion renderer that steps through variants
/// unconditionally without threading an `Option`-branch through
/// the update path, a UI mode selector that "cycles to the next
/// mode on Tab", a round-robin scheduler that walks a fixed pool
/// of typed slots forever, a per-tick animation frame picker
/// that advances one variant per tick and wraps at the tail, a
/// declaration-order carousel widget) binds to ONE typed
/// wrapping-neighbor method rather than hand-rolling either
/// `self.next().unwrap_or(T::first())` (which re-derives the same
/// two-primitive composition at every callsite AND makes every
/// downstream site depend on the wrapping-fallback shape) OR
/// `T::from_index((self.index_of() + 1) % T::CARDINALITY)` (which
/// re-derives the modular-arithmetic composition at every callsite
/// AND makes every downstream site depend on the `%` operator on
/// `usize`) OR a per-implementor inline `match self { A => B, B
/// => C, C => A }` keyed on the declaration slot (which re-derives
/// the per-variant wraparound table at every callsite AND drifts
/// silently when [`Self::ALL`] gains a new variant that reorders
/// the wraparound edge).
///
/// Sibling posture to [`Self::last`] on the (forward-neighbor,
/// tail-endpoint) axis of the declaration-order traversal surface —
/// `T::last().cycle_next() == T::first()` is the natural fixpoint
/// the forward-wrapping-neighbor axis and the tail-endpoint anchor
/// share, folding the tail-endpoint boundary onto the head-endpoint
/// anchor at the shared structural landmark. Mirrors the
/// `T::last().next() == None` fixpoint on the bounded arm one
/// return-type axis over.
///
/// Default body composes [`Self::next`] with [`Self::first`]
/// through `Option::unwrap_or` — the wrapping-neighbor projection
/// is a typed CONSEQUENCE of the pre-existing (bounded neighbor,
/// head anchor) pair, not a third codepath. Implementors override
/// only when the wrapping-neighbor surface needs to diverge from
/// the natural `next().unwrap_or(first())` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `from_index` /
/// `first` / `last` / `next` / `prev` / `sorted_next` /
/// `sorted_prev` overrides exist — a typed escape hatch the trait
/// surface exposes rather than forcing the implementor to hand-
/// roll the impl). An implementor that overrides [`Self::next`]
/// or [`Self::first`] propagates the override through this default
/// body automatically; the (variant → wrapping-forward-neighbor)
/// projection funnels through TWO typed primitives.
///
/// The wrapping-neighbor contract — the tail arm returns
/// [`Self::first`] for [`Self::last`] — is guaranteed by the
/// default composition through [`Self::next`]'s `None` at the tail
/// AND [`Option::unwrap_or`]'s fallback semantics; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (28) pins the composition against the natural
/// `next().unwrap_or(first())` shape AND the tail-endpoint
/// `T::first()` fold on every implementor, so a passing well-
/// formedness sweep means every generic consumer can call
/// [`Self::cycle_next`] on any typed variant and expect the same
/// [`Self`]-typed answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (variant → wrapping-forward
/// neighbor) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline
/// `self.next().unwrap_or(T::first())` composition at every
/// downstream cyclic traversal site. The (Option-typed, wrapping)
/// × (forward, backward) 2×2 matrix on the declaration-axis
/// neighbor surface partitions exhaustively into FOUR typed
/// projections, each with a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the wrapping-neighbor
/// projections were unnamed compounds of [`Self::next`] +
/// [`Self::first`] + [`Option::unwrap_or`] pre-lift; naming them on
/// the trait makes the projections TYPED CONSEQUENCES of the two
/// bounded-arm primitives — generic consumers see ONE wrapping
/// method per direction, not one wrapping-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the wrapping-
/// neighbor projection emerges from the composition of TWO
/// substrate primitives ([`Self::next`], [`Self::first`]) via
/// [`Option::unwrap_or`] rather than as a per-implementor `match
/// self { A => B, B => C, C => A }` block or a modular-arithmetic
/// `T::from_index((self.index_of() + 1) % T::CARDINALITY)`
/// composition. A future tightening of either primitive (a future
/// perfect-hash `from_index` that speeds up `next`, a future
/// `const fn first`) propagates to every closed-set wrapping-
/// forward-neighbor consumer through this method's body.
///
/// Frontier inspiration: Racket's `(enum-cycle-next enum sym)`
/// on closed enumerations under a cyclic ordering (which folds
/// the tail onto the head rather than returning `#f`); Idris's
/// `Fin n` finite-cardinality type composed with modular
/// arithmetic through `finToNat` / `natToFin` on the cyclic
/// projection; Haskell's `succ` on the `Bounded + Enum` type-class
/// pair wrapped in `catch` to fold `Prelude.succ: bad argument` at
/// the tail-endpoint onto `minBound` (which reifies the wrapping
/// arm as an exception-catching shim rather than a total function
/// — this method takes the total-function arm); Emacs's
/// `enum-next-cyclic`; UI toolkit "cycle-through-modes" bindings
/// (Vim's `<Tab>` in command mode, Ctrl+Tab in editor mode).
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::next`] + [`Self::first`]
/// surfaces via [`Option::unwrap_or`] — no new dep, no new IR
/// layer, no supertrait bound, no `%` operator on `usize`, no
/// exception-catching, no `strum` / `enum-iterator` crate
/// dependency.
fn cycle_next(self) -> Self {
<Self as ClosedSet>::next(self).unwrap_or_else(<Self as ClosedSet>::first)
}
/// The declaration-order neighbor immediately BEFORE `self` in
/// [`Self::ALL`], WRAPPING to [`Self::last`] at the head —
/// `self.prev().unwrap_or(Self::last())`. Returns [`Self`], never
/// [`Option<Self>`]: the wrapping arm folds the head-endpoint
/// boundary onto the tail-endpoint anchor rather than leaving the
/// [`None`] the bounded-neighbor axis returns.
///
/// Sibling posture to [`Self::cycle_next`] one axis over on the
/// (forward, backward) direction partition of the closed-set
/// wrapping-neighbor surface: [`Self::cycle_next`] returns the
/// declaration-order successor with tail-wrap-to-head,
/// this method returns the declaration-order predecessor with
/// head-wrap-to-tail. See [`Self::cycle_next`] for the shared
/// design rationale, sibling 2×2 matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the backward-direction arm of
/// the same axis and inherits every property from the forward
/// arm's documentation, differing only in the [`Self::prev`] /
/// [`Self::last`] substrate primitives it composes.
///
/// Default body composes [`Self::prev`] with [`Self::last`]
/// through [`Option::unwrap_or`] — the wrapping-neighbor
/// projection is a typed CONSEQUENCE of the pre-existing (bounded
/// backward neighbor, tail anchor) pair, not a third codepath.
/// Implementors override only when the wrapping-neighbor surface
/// needs to diverge from the natural `prev().unwrap_or(last())`
/// shape. An implementor that overrides [`Self::prev`] or
/// [`Self::last`] propagates the override through this default
/// body automatically; the (variant → wrapping-backward-neighbor)
/// projection funnels through TWO typed primitives.
///
/// The wrapping-neighbor contract — the head arm returns
/// [`Self::last`] for [`Self::first`] — is guaranteed by the
/// default composition through [`Self::prev`]'s `None` at the
/// head AND [`Option::unwrap_or`]'s fallback semantics; the
/// well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (28) pins the
/// composition against the natural `prev().unwrap_or(last())`
/// shape AND the head-endpoint `T::last()` fold on every
/// implementor, so a passing well-formedness sweep means every
/// generic consumer can call [`Self::cycle_prev`] on any typed
/// variant and expect the same [`Self`]-typed answer at every
/// crate boundary. `T::first().cycle_prev() == T::last()` is the
/// natural fixpoint the backward-wrapping-neighbor axis and the
/// head-endpoint anchor share, mirroring the
/// `T::last().cycle_next() == T::first()` fixpoint on the
/// forward-wrapping-neighbor / tail-endpoint pair AND the
/// `T::first().prev() == None` fixpoint one return-type axis over.
fn cycle_prev(self) -> Self {
<Self as ClosedSet>::prev(self).unwrap_or_else(<Self as ClosedSet>::last)
}
/// The lexicographic-order neighbor immediately AFTER `self` in
/// [`Self::sorted_variants`], WRAPPING to [`Self::sorted_first`] at
/// the lex tail — `self.sorted_next().unwrap_or(Self::sorted_first())`.
/// Returns [`Self`], never [`Option<Self>`]: the wrapping arm folds
/// the lex-tail-endpoint boundary onto the lex-head-endpoint anchor
/// rather than leaving the [`None`] the bounded-lex-neighbor axis
/// returns.
///
/// The wrapping-return arm of the (Option-typed, wrapping)
/// partition over the closed-set forward-lex-neighbor surface — one
/// return-type axis over from [`Self::sorted_next`], which returns
/// the bounded [`Option<Self>`] variant. Together with
/// [`Self::cycle_sorted_prev`], the pair closes the (forward,
/// backward) direction axis of the WRAPPING arm on the lex ordering
/// axis, and together with the pre-existing [`Self::cycle_next`] /
/// [`Self::cycle_prev`] pair closes the (declaration, lex) ×
/// (forward, backward) 2×2 matrix on the WRAPPING partition of the
/// closed-set neighbor surface:
///
/// | Ordering \\ Direction | Forward wrap | Backward wrap |
/// |-----------------------|-----------------------------|-----------------------------|
/// | Declaration | [`Self::cycle_next`] | [`Self::cycle_prev`] |
/// | Lex | [`Self::cycle_sorted_next`] | [`Self::cycle_sorted_prev`] |
///
/// Every generic consumer that walks the closed set as an INFINITE
/// cyclic chain under LEX order (an alphabetized LSP completion
/// cursor that steps through variants unconditionally without
/// threading an `Option`-branch through the update path, an
/// alphabetized round-robin picker that cycles through variants in
/// canonical name order rather than declaration order, a
/// lex-sorted per-tick animation frame picker that advances one
/// alphabetized variant per tick and wraps at the lex tail, an
/// alphabetized carousel widget) binds to ONE typed
/// wrapping-lex-neighbor method rather than hand-rolling either
/// `self.sorted_next().unwrap_or(T::sorted_first())` (which re-derives
/// the same two-primitive composition at every callsite AND makes
/// every downstream site depend on the wrapping-fallback shape) OR
/// `T::from_sorted_index((self.sorted_index_of() + 1) % T::CARDINALITY)`
/// (which re-derives the modular-arithmetic composition at every
/// callsite AND makes every downstream site depend on the `%`
/// operator on `usize`) OR a per-implementor inline `match self { A
/// => B, B => C, C => A }` keyed on the lex slot (which re-derives
/// the per-variant lex-wraparound table at every callsite AND drifts
/// silently when [`Self::ALL`] gains a new variant whose canonical
/// label reorders the lex-wraparound edge).
///
/// Sibling posture to [`Self::sorted_last`] on the (forward-lex-
/// neighbor, lex-tail-endpoint) axis of the lex-order traversal
/// surface — `T::sorted_last().cycle_sorted_next() ==
/// T::sorted_first()` is the natural fixpoint the
/// forward-wrapping-lex-neighbor axis and the lex-tail-endpoint
/// anchor share, folding the lex-tail-endpoint boundary onto the
/// lex-head-endpoint anchor at the shared structural landmark.
/// Mirrors the `T::sorted_last().sorted_next() == None` fixpoint on
/// the bounded lex-arm one return-type axis over AND the
/// `T::last().cycle_next() == T::first()` fixpoint on the
/// declaration-wrapping arm one ordering axis over.
///
/// Default body composes [`Self::sorted_next`] with
/// [`Self::sorted_first`] through `Option::unwrap_or` — the
/// wrapping-lex-neighbor projection is a typed CONSEQUENCE of the
/// pre-existing (bounded lex-neighbor, lex-head anchor) pair, not a
/// third codepath. Implementors override only when the
/// wrapping-lex-neighbor surface needs to diverge from the natural
/// `sorted_next().unwrap_or(sorted_first())` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `via` / `set_label` / `labels` / `from_sorted_index` /
/// `sorted_first` / `sorted_last` / `sorted_next` / `sorted_prev` /
/// `cycle_next` / `cycle_prev` overrides exist — a typed escape
/// hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that overrides
/// [`Self::sorted_next`] or [`Self::sorted_first`] propagates the
/// override through this default body automatically; the
/// (variant → wrapping-forward-lex-neighbor) projection funnels
/// through TWO typed primitives.
///
/// The wrapping-lex-neighbor contract — the lex-tail arm returns
/// [`Self::sorted_first`] for [`Self::sorted_last`] — is guaranteed
/// by the default composition through [`Self::sorted_next`]'s `None`
/// at the lex tail AND [`Option::unwrap_or`]'s fallback semantics;
/// the well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (29) pins the composition against the natural
/// `sorted_next().unwrap_or(sorted_first())` shape AND the
/// lex-tail-endpoint `T::sorted_first()` fold on every implementor,
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::cycle_sorted_next`] on any typed variant and
/// expect the same [`Self`]-typed answer at every crate boundary.
///
/// THEORY.md §III — the typescape; the (variant → wrapping-forward
/// lex-neighbor) projection becomes a TYPE projection on the trait
/// rather than a per-consumer inline
/// `self.sorted_next().unwrap_or(T::sorted_first())` composition at
/// every downstream lex-cyclic-traversal site. The (declaration, lex)
/// × (forward, backward) 2×2 matrix on the WRAPPING partition of the
/// closed-set neighbor surface partitions exhaustively into FOUR
/// typed projections, each with a distinct load-bearing consumer
/// surface — closing the (Option-typed, wrapping) × (declaration,
/// lex) × (forward, backward) 2×2×2 = 8-corner neighbor cube at
/// EVERY corner.
/// THEORY.md §V.1 — knowable platform; the wrapping-lex-neighbor
/// projections were unnamed compounds of [`Self::sorted_next`] +
/// [`Self::sorted_first`] + [`Option::unwrap_or`] pre-lift; naming
/// them on the trait makes the projections TYPED CONSEQUENCES of the
/// two lex-bounded-arm primitives — generic consumers see ONE
/// wrapping method per direction per ordering axis, not one
/// wrapping-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the wrapping-
/// lex-neighbor projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_next`],
/// [`Self::sorted_first`]) via [`Option::unwrap_or`] rather than as
/// a per-implementor `match self { A => B, B => C, C => A }` block
/// keyed on the lex slot or a modular-arithmetic
/// `T::from_sorted_index((self.sorted_index_of() + 1) %
/// T::CARDINALITY)` composition. A future tightening of either
/// primitive (a future perfect-hash `from_sorted_index` that speeds
/// up `sorted_next`, a future `const fn sorted_first`) propagates to
/// every closed-set wrapping-forward-lex-neighbor consumer through
/// this method's body.
///
/// Frontier inspiration: Racket's `(sort-cycle-next enum sym)` on
/// closed enumerations under a lex-cyclic ordering; Common Lisp's
/// `SXHASH`-keyed lex-sorted enum walkers wrapped in a
/// `handler-case` that folds the tail-endpoint condition onto the
/// head-endpoint anchor (which reifies the wrapping arm as a
/// condition-handler shim rather than a total function — this
/// method takes the total-function arm); Idris's `Fin n`
/// finite-cardinality type composed with a lex-ordering permutation
/// through `finToNat` / `natToFin` on the cyclic projection; UI
/// toolkit "cycle-through-alphabetized-modes" bindings (Ctrl+n in
/// alphabetical mode selectors, alphabetized round-robin schedulers
/// in TUI palette pickers). Translation through pleme-io primitives:
/// a pure default method composing the trait's existing
/// [`Self::sorted_next`] + [`Self::sorted_first`] surfaces via
/// [`Option::unwrap_or`] — no new dep, no new IR layer, no
/// supertrait bound, no `%` operator on `usize`, no
/// condition-handling, no `strum` / `enum-iterator` crate dependency.
fn cycle_sorted_next(self) -> Self {
<Self as ClosedSet>::sorted_next(self).unwrap_or_else(<Self as ClosedSet>::sorted_first)
}
/// The lexicographic-order neighbor immediately BEFORE `self` in
/// [`Self::sorted_variants`], WRAPPING to [`Self::sorted_last`] at
/// the lex head — `self.sorted_prev().unwrap_or(Self::sorted_last())`.
/// Returns [`Self`], never [`Option<Self>`]: the wrapping arm folds
/// the lex-head-endpoint boundary onto the lex-tail-endpoint anchor
/// rather than leaving the [`None`] the bounded-lex-neighbor axis
/// returns.
///
/// Sibling posture to [`Self::cycle_sorted_next`] one axis over on
/// the (forward, backward) direction partition of the closed-set
/// wrapping-lex-neighbor surface: [`Self::cycle_sorted_next`]
/// returns the lex-order successor with lex-tail-wrap-to-lex-head,
/// this method returns the lex-order predecessor with
/// lex-head-wrap-to-lex-tail. See [`Self::cycle_sorted_next`] for
/// the shared design rationale, sibling 2×2 matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the backward-direction arm of the
/// same axis and inherits every property from the forward arm's
/// documentation, differing only in the [`Self::sorted_prev`] /
/// [`Self::sorted_last`] substrate primitives it composes.
///
/// Default body composes [`Self::sorted_prev`] with
/// [`Self::sorted_last`] through [`Option::unwrap_or`] — the
/// wrapping-lex-neighbor projection is a typed CONSEQUENCE of the
/// pre-existing (bounded backward lex-neighbor, lex-tail anchor)
/// pair, not a third codepath. Implementors override only when the
/// wrapping-lex-neighbor surface needs to diverge from the natural
/// `sorted_prev().unwrap_or(sorted_last())` shape. An implementor
/// that overrides [`Self::sorted_prev`] or [`Self::sorted_last`]
/// propagates the override through this default body automatically;
/// the (variant → wrapping-backward-lex-neighbor) projection funnels
/// through TWO typed primitives.
///
/// The wrapping-lex-neighbor contract — the lex-head arm returns
/// [`Self::sorted_last`] for [`Self::sorted_first`] — is guaranteed
/// by the default composition through [`Self::sorted_prev`]'s `None`
/// at the lex head AND [`Option::unwrap_or`]'s fallback semantics;
/// the well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (29) pins the composition against the natural
/// `sorted_prev().unwrap_or(sorted_last())` shape AND the
/// lex-head-endpoint `T::sorted_last()` fold on every implementor,
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::cycle_sorted_prev`] on any typed variant and
/// expect the same [`Self`]-typed answer at every crate boundary.
/// `T::sorted_first().cycle_sorted_prev() == T::sorted_last()` is
/// the natural fixpoint the backward-wrapping-lex-neighbor axis and
/// the lex-head-endpoint anchor share, mirroring the
/// `T::sorted_last().cycle_sorted_next() == T::sorted_first()`
/// fixpoint on the forward-wrapping-lex-neighbor / lex-tail-endpoint
/// pair, the `T::sorted_first().sorted_prev() == None` fixpoint one
/// return-type axis over, AND the `T::first().cycle_prev() ==
/// T::last()` fixpoint one ordering axis over. Clauses (28) + (29)
/// together close the (declaration, lex) × (forward, backward) 2×2
/// wrapping-neighbor matrix at ALL FOUR wraparound fixpoints,
/// completing the (Option-typed, wrapping) × (declaration, lex) ×
/// (forward, backward) 2×2×2 = 8-corner neighbor cube alongside
/// clauses (26) + (27) on the bounded partition.
fn cycle_sorted_prev(self) -> Self {
<Self as ClosedSet>::sorted_prev(self).unwrap_or_else(<Self as ClosedSet>::sorted_last)
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately AFTER `self` in [`Self::ALL`], WRAPPING
/// to [`Self::first_label`] at the tail — the label of
/// [`Self::cycle_next`] projected through [`Self::label`]. Returns
/// `&'static str`, never [`Option<&'static str>`]: the wrapping arm
/// folds the tail-endpoint boundary onto the head-endpoint anchor
/// label rather than leaving the [`None`] the bounded-neighbor-
/// label axis returns.
///
/// The wrapping-return arm of the (Option-typed, wrapping)
/// partition over the closed-set forward-declaration-neighbor label
/// surface — one return-type axis over from [`Self::next_label`],
/// which returns the bounded [`Option<&'static str>`] variant.
/// Together with [`Self::cycle_prev_label`], the pair closes the
/// (forward, backward) direction axis of the WRAPPING label arm on
/// the declaration ordering axis, and together with the pre-existing
/// [`Self::cycle_sorted_next_label`] / [`Self::cycle_sorted_prev_label`]
/// pair (added in the same lift) completes the (declaration × lex)
/// × (forward, backward) 2×2 wrapping-label-neighbor matrix:
///
/// | Ordering \\ Direction | Forward wrap | Backward wrap |
/// |-----------------------|----------------------------------|-----------------------------------|
/// | Declaration | [`Self::cycle_next_label`] | [`Self::cycle_prev_label`] |
/// | Lex | [`Self::cycle_sorted_next_label`] | [`Self::cycle_sorted_prev_label`] |
///
/// Every generic consumer that renders the wrapping-forward-neighbor
/// LABEL of a typed variant (a cyclic LSP completion cursor that
/// emits "next: <label>" unconditionally without threading an
/// `Option`-branch through the label-render path, a round-robin
/// picker that logs the next cyclic label as its rotation banner, a
/// carousel widget's next-tab label renderer, a per-tick animation
/// frame picker that stamps the next cyclic label into a per-frame
/// audit trail, a Kubernetes annotation stamper that writes the
/// wrapping-successor label onto a per-transition CRD without
/// threading the typed variant through `.label()` at the callsite)
/// binds to ONE typed method on the trait rather than re-deriving
/// the `v.cycle_next().label()` two-primitive composition at every
/// callsite OR the `v.next_label().unwrap_or(T::first_label())`
/// three-primitive composition at every callsite.
///
/// Default body composes [`Self::cycle_next`] with [`Self::label`]
/// verbatim — the wrapping-forward-neighbor-label projection is a
/// typed CONSEQUENCE of the pre-existing (wrapping forward-neighbor,
/// canonical label) pair, not a third codepath. Implementors override
/// only when the wrapping-forward-neighbor-label surface needs to
/// diverge from the natural `cycle_next().label()` shape. An
/// implementor that overrides [`Self::cycle_next`] or [`Self::label`]
/// propagates the override through this default body automatically;
/// the (variant → wrapping-forward-neighbor label) projection funnels
/// through TWO typed primitives.
///
/// The wrapping-neighbor-label contract — the tail arm returns
/// [`Self::first_label`] for [`Self::last`] — is guaranteed by the
/// default composition through [`Self::cycle_next`]'s tail-wrap-to-
/// head fold; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (62) pins the
/// composition against the natural `cycle_next().label()` shape AND
/// the tail-endpoint `T::first_label()` fold on every implementor,
/// so a passing well-formedness sweep means every generic consumer
/// can call [`Self::cycle_next_label`] on any typed variant and
/// expect the same `&'static str` answer at every crate boundary.
/// `T::last().cycle_next_label() == T::first_label()` is the natural
/// fixpoint the forward-wrapping-neighbor-label axis and the
/// tail-endpoint anchor share, mirroring
/// `T::last().cycle_next() == T::first()` one return-type axis over.
///
/// THEORY.md §III — the typescape; the (variant → wrapping-forward
/// declaration-neighbor label) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `self.cycle_next().label()` composition at every downstream
/// declaration-cyclic-label-traversal site. Clauses (28) + (29) +
/// (58) + (59) + (60) + (61) + (62) + (63) + (64) + (65) together
/// close the (declaration × lex) × (forward, backward) ×
/// (Option-typed-bounded, wrapping) × (`Self`-return,
/// `&'static str`-return) 2×2×2×2 = 16-corner label-and-variant
/// bounded-plus-wrapping traversal hypercube.
/// THEORY.md §V.1 — knowable platform; the wrapping-declaration-
/// neighbor-label projections were unnamed compounds of
/// [`Self::cycle_next`] + [`Self::label`] pre-lift; naming them on
/// the trait makes the projections TYPED CONSEQUENCES of the two
/// substrate primitives — generic consumers see ONE wrapping-label
/// method per direction per ordering axis, not one wrapping-label-
/// shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the wrapping-
/// declaration-neighbor-label projection emerges from composition
/// of substrate primitives rather than as a per-implementor
/// `match self { A => "b-label", B => "c-label", C => "a-label" }`
/// block keyed on the declaration slot.
///
/// Frontier inspiration: Racket's `(enum-cycle-next-label enum sym)`
/// — the label-projection sibling of `enum-cycle-next` on a closed
/// enumeration; Idris's `Fin n` with `showFin` composed through a
/// cyclic-successor projection on the finite-type universe; MLIR's
/// `RegisteredOperationName::cycleNext().getName()` folded to ONE
/// method on the declaration-order cyclic Op registry; Emacs's
/// `(symbol-name (enum-next-cyclic v))`. Translation through
/// pleme-io primitives: a pure default method composing the trait's
/// existing [`Self::cycle_next`] + [`Self::label`] surfaces
/// verbatim — no new dep, no new IR layer, no supertrait bound, no
/// `Option`-typed dispatch, no allocation.
fn cycle_next_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::cycle_next(self))
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately BEFORE `self` in [`Self::ALL`], WRAPPING
/// to [`Self::last_label`] at the head — the label of
/// [`Self::cycle_prev`] projected through [`Self::label`]. Returns
/// `&'static str`, never [`Option<&'static str>`].
///
/// Sibling posture to [`Self::cycle_next_label`] one direction over
/// on the (forward, backward) direction partition of the closed-set
/// wrapping-label-neighbor surface: [`Self::cycle_next_label`] returns
/// the declaration-order successor label with tail-wrap-to-head-label,
/// this method returns the declaration-order predecessor label with
/// head-wrap-to-tail-label. See [`Self::cycle_next_label`] for the
/// shared design rationale, sibling 2×2 matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the backward-direction arm of the
/// same axis and inherits every property from the forward arm's
/// documentation, differing only in the [`Self::cycle_prev`] /
/// [`Self::last_label`] substrate primitives it composes.
///
/// Default body composes [`Self::cycle_prev`] with [`Self::label`]
/// verbatim. The wrapping-neighbor-label contract — the head arm
/// returns [`Self::last_label`] for [`Self::first`] — is guaranteed
/// by the default composition through [`Self::cycle_prev`]'s head-
/// wrap-to-tail fold; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (63) pins the
/// composition against the natural `cycle_prev().label()` shape AND
/// the head-endpoint `T::last_label()` fold on every implementor.
/// `T::first().cycle_prev_label() == T::last_label()` is the natural
/// fixpoint the backward-wrapping-neighbor-label axis and the
/// head-endpoint anchor share, mirroring
/// `T::first().cycle_prev() == T::last()` one return-type axis over.
fn cycle_prev_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::cycle_prev(self))
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately AFTER `self` in [`Self::sorted_variants`],
/// WRAPPING to [`Self::sorted_first_label`] at the lex tail — the
/// label of [`Self::cycle_sorted_next`] projected through
/// [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`].
///
/// The lex-order forward-wrapping arm of the (declaration × lex) ×
/// (forward, backward) × (`Self`-return, `&'static str`-return)
/// × (Option-typed-bounded, wrapping) 2×2×2×2 = 16-corner label-
/// and-variant bounded-plus-wrapping traversal hypercube — one
/// ordering axis over from [`Self::cycle_next_label`] (declaration-
/// order wrapping-forward label), one return-type axis over from
/// [`Self::cycle_sorted_next`] (lex-order wrapping-forward variant),
/// and one bounded/wrapping axis over from [`Self::sorted_next_label`]
/// (lex-order bounded-forward label).
///
/// Every generic consumer that renders the wrapping-forward-lex-
/// neighbor LABEL of a typed variant (an alphabetized-cyclic LSP
/// completion cursor that emits "next: <lex-label>" for the wrapping
/// lex-sorted successor unconditionally, an alphabetized round-robin
/// picker that logs the next lex-cyclic label as its rotation banner,
/// an alphabetized carousel widget's next-tab label renderer, a
/// lex-cyclic per-tick animation frame picker) binds to ONE typed
/// method on the trait rather than re-deriving the
/// `v.cycle_sorted_next().label()` two-primitive composition at every
/// callsite OR the `v.sorted_next_label().unwrap_or(T::sorted_first_label())`
/// three-primitive composition at every callsite.
///
/// Default body composes [`Self::cycle_sorted_next`] with
/// [`Self::label`] verbatim. The wrapping-lex-neighbor-label contract
/// — the lex-tail arm returns [`Self::sorted_first_label`] for
/// [`Self::sorted_last`] — is guaranteed by the default composition
/// through [`Self::cycle_sorted_next`]'s lex-tail-wrap-to-lex-head
/// fold; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (64) pins the
/// composition against the natural `cycle_sorted_next().label()`
/// shape AND the lex-tail-endpoint `T::sorted_first_label()` fold on
/// every implementor.
/// `T::sorted_last().cycle_sorted_next_label() == T::sorted_first_label()`
/// is the natural fixpoint the forward-wrapping-lex-neighbor-label
/// axis and the lex-tail-endpoint anchor share, mirroring
/// `T::sorted_last().cycle_sorted_next() == T::sorted_first()` one
/// return-type axis over AND
/// `T::last().cycle_next_label() == T::first_label()` one ordering
/// axis over.
fn cycle_sorted_next_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::cycle_sorted_next(self))
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately BEFORE `self` in [`Self::sorted_variants`],
/// WRAPPING to [`Self::sorted_last_label`] at the lex head — the
/// label of [`Self::cycle_sorted_prev`] projected through
/// [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`].
///
/// Sibling posture to [`Self::cycle_sorted_next_label`] one direction
/// over on the (forward, backward) direction partition of the closed-
/// set wrapping-lex-label-neighbor surface. See
/// [`Self::cycle_sorted_next_label`] for the shared design rationale,
/// sibling 2×2 matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration.
///
/// Default body composes [`Self::cycle_sorted_prev`] with
/// [`Self::label`] verbatim. The wrapping-lex-neighbor-label contract
/// — the lex-head arm returns [`Self::sorted_last_label`] for
/// [`Self::sorted_first`] — is guaranteed by the default composition
/// through [`Self::cycle_sorted_prev`]'s lex-head-wrap-to-lex-tail
/// fold; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (65) pins the
/// composition against the natural `cycle_sorted_prev().label()`
/// shape AND the lex-head-endpoint `T::sorted_last_label()` fold on
/// every implementor. Clauses (28) + (29) + (58) + (59) + (60) +
/// (61) + (62) + (63) + (64) + (65) together CLOSE the (declaration
/// × lex) × (forward, backward) × (Option-typed-bounded, wrapping) ×
/// (`Self`-return, `&'static str`-return) 2×2×2×2 = 16-corner
/// label-and-variant bounded-plus-wrapping traversal hypercube on
/// the closed-set neighbor surface.
fn cycle_sorted_prev_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::cycle_sorted_prev(self))
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// AFTER `self` in [`Self::ALL`], WRAPPING to `0` at the tail — the
/// declaration-order position of [`Self::cycle_next`] projected
/// through [`Self::index_of`]. Returns `usize`, never
/// [`Option<usize>`]: the wrapping arm folds the tail-endpoint
/// boundary onto the head-index-anchor `0` rather than leaving the
/// [`None`] the bounded-neighbor-index axis returns.
///
/// The declaration-order forward-wrapping arm of the (declaration ×
/// lex) × (forward, backward) × (Option-typed-bounded, wrapping) ×
/// (`Self`-return, `&'static str`-return, `usize`-return) 2×2×2×3 =
/// 24-corner index-and-label-and-variant bounded-plus-wrapping
/// traversal hypercube — one bounded/wrapping axis over from
/// [`Self::next_index`] (declaration-order bounded-forward index),
/// one return-type axis over from [`Self::cycle_next`] (declaration-
/// order wrapping-forward variant) AND from [`Self::cycle_next_label`]
/// (declaration-order wrapping-forward label). Together with
/// [`Self::cycle_prev_index`], [`Self::cycle_sorted_next_index`], and
/// [`Self::cycle_sorted_prev_index`], the quartet closes the
/// (`usize`-return, wrapping) 2×2 corner of the hypercube on BOTH
/// ordering axes AND both direction axes:
///
/// | Direction \\ Ordering | Declaration order | Lexicographic order |
/// |-----------------------------------|----------------------------------|----------------------------------------|
/// | Forward wrapping index | [`Self::cycle_next_index`] | [`Self::cycle_sorted_next_index`] |
/// | Backward wrapping index | [`Self::cycle_prev_index`] | [`Self::cycle_sorted_prev_index`] |
///
/// Every generic consumer that renders the wrapping-forward-neighbor
/// SLOT of a typed variant (a compact wire codec emitting
/// `next_slot_cyclic=<index>` for cross-boundary handoff without
/// threading the tail-endpoint `None` branch, a cyclic round-robin
/// scheduler that binds `slot.cycle_next_index()` as its rotation
/// step without an unconditional wrap-guard, a byte-tagged compact
/// encoding that keys per-transition metrics off the cyclic
/// successor's declaration slot, a cyclic bitset state machine
/// setting the cyclic successor's bit without threading
/// `index_of` through a `unwrap_or(0)` at the callsite, a Sekiban
/// per-cyclic-transition audit binner keying on the next declaration
/// slot, a carousel-widget renderer that stamps
/// `next-slot-cyclic=<index>` onto a per-tab annotation) binds to
/// ONE typed method on the trait rather than re-deriving the
/// `v.cycle_next().index_of()` two-primitive composition OR the
/// `v.next_index().unwrap_or(0)` two-primitive composition at every
/// callsite.
///
/// Default body composes [`Self::cycle_next`] with [`Self::index_of`]
/// verbatim — the wrapping-forward-neighbor-index projection is a
/// typed CONSEQUENCE of the pre-existing (wrapping forward neighbor,
/// canonical declaration position) pair, not a third codepath.
/// Implementors override only when the wrapping-forward-neighbor-
/// index surface needs to diverge from the natural
/// `cycle_next().index_of()` shape (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `index_of` / `from_index` /
/// `first` / `last` / `next` / `next_label` / `next_index` /
/// `cycle_next` / `cycle_next_label` overrides exist — a typed
/// escape hatch the trait surface exposes rather than forcing the
/// implementor to hand-roll the impl). An implementor that overrides
/// [`Self::cycle_next`] OR [`Self::index_of`] propagates the
/// override through this default body automatically; the (variant →
/// wrapping-forward-neighbor declaration slot) projection funnels
/// through ONE typed primitive.
///
/// The wrapping-neighbor-index contract — the tail arm returns `0`
/// (the head-endpoint's declaration slot) — is guaranteed by the
/// default composition through [`Self::cycle_next`]'s tail-wrap-to-
/// head fold + [`Self::index_of`]'s natural `0`-at-head projection;
/// the well-formedness contract [`assert_closed_set_well_formed`]'s
/// new clause (70) pins the composition against the natural
/// `cycle_next().index_of()` shape AND the tail-endpoint `0` fold on
/// every implementor, so a passing well-formedness sweep means every
/// generic consumer can call [`Self::cycle_next_index`] on any typed
/// variant and expect the same [`usize`]-typed answer at every crate
/// boundary. `T::last().cycle_next_index() ==
/// T::first().index_of()` (i.e. `0`) is the natural fixpoint the
/// forward-wrapping-neighbor-index axis and the tail-endpoint anchor
/// share, mirroring `T::last().cycle_next() == T::first()` one
/// return-type axis over AND `T::last().cycle_next_label() ==
/// T::first_label()` one return-type axis over.
///
/// THEORY.md §III — the typescape; the (variant → wrapping-forward
/// declaration-neighbor slot) projection becomes a TYPE projection
/// on the trait rather than a per-consumer inline
/// `self.cycle_next().index_of()` composition at every downstream
/// declaration-cyclic-index-traversal site. The (return-type ×
/// direction × ordering × bounded/wrapping) 3×2×2×2 = 24-corner
/// traversal hypercube partitions exhaustively into TWENTY-FOUR
/// typed projections; the (`usize`-return, declaration, forward,
/// wrapping) corner lands at this method. Extending the (return-
/// type ∈ {`Self`, label}) 2×2×2×2 bounded-plus-wrapping label-and-
/// variant hypercube one return-type dimension into {`Self`, label,
/// index} 3×2×2×2 makes the declaration-cyclic-index projection a
/// first-class typed sibling of the typed-variant and canonical-
/// label siblings on the declaration-cyclic-forward corner.
/// THEORY.md §V.1 — knowable platform; the wrapping-forward-
/// neighbor-index projection was an unnamed compound of
/// [`Self::cycle_next`] + [`Self::index_of`] pre-lift; naming it on
/// the trait makes the projection a TYPED CONSEQUENCE of the two
/// substrate primitives — generic consumers see ONE wrapping-
/// forward-index method per ordering axis, not one wrapping-index-
/// shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the wrapping-
/// forward-neighbor-index projection emerges from composition of
/// substrate primitives rather than as a per-implementor
/// `match self { A => 1, B => 2, C => 0 }` block keyed on the
/// declaration slot.
///
/// Frontier inspiration: Racket's `(enum-cycle-next-index enum val)`
/// — the index-projection sibling of `enum-cycle-next` on a closed
/// enumeration composed through the declaration position projection;
/// Idris's `Fin n` composed through `finToNat` on the cyclic-
/// successor's finite-position projection; MLIR's
/// `RegisteredOperationName::cycleNext().getIndex()` folded to ONE
/// method on the declaration-order cyclic Op registry; Rust's
/// `strum::EnumIter::iter().position(|v| Some(v) == self.next()).unwrap_or(0)`
/// composed through the iterator API + a cyclic tail-arm fold.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::cycle_next`] +
/// [`Self::index_of`] surfaces verbatim — no new dep, no new IR
/// layer, no supertrait bound, no `Option`-typed dispatch, no
/// allocation, no `strum` / `enum-iterator` crate dependency.
fn cycle_next_index(self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::cycle_next(self))
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// BEFORE `self` in [`Self::ALL`], WRAPPING to `T::CARDINALITY - 1`
/// at the head — the declaration-order position of
/// [`Self::cycle_prev`] projected through [`Self::index_of`].
/// Returns `usize`, never [`Option<usize>`]: the wrapping arm folds
/// the head-endpoint boundary onto the tail-index-anchor rather
/// than leaving the [`None`] the bounded-neighbor-index axis
/// returns.
///
/// Sibling posture to [`Self::cycle_next_index`] one direction over
/// on the (forward, backward) direction partition of the
/// declaration-axis index-shaped wrapping-neighbor surface:
/// [`Self::cycle_next_index`] returns the declaration-order
/// successor slot with tail-wrap-to-head-slot `0`, this method
/// returns the declaration-order predecessor slot with head-wrap-
/// to-tail-slot `T::CARDINALITY - 1`. See
/// [`Self::cycle_next_index`] for the shared design rationale, the
/// 3×2×2×2 = 24-corner hypercube, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the backward-direction arm of the same axis and
/// inherits every property from the forward arm's documentation,
/// differing only in the composition through [`Self::cycle_prev`]
/// instead of [`Self::cycle_next`] and the head-endpoint
/// `T::CARDINALITY - 1` fold rather than the tail-endpoint `0`
/// fold.
///
/// Default body composes [`Self::cycle_prev`] with [`Self::index_of`]
/// verbatim. The wrapping-neighbor-index contract — the head arm
/// returns `T::CARDINALITY - 1` (the tail-endpoint's declaration
/// slot) — is guaranteed by the default composition through
/// [`Self::cycle_prev`]'s head-wrap-to-tail fold; the well-
/// formedness contract [`assert_closed_set_well_formed`]'s new
/// clause (71) pins the composition against the natural
/// `cycle_prev().index_of()` shape AND the head-endpoint
/// `T::CARDINALITY - 1` fold on every implementor.
/// `T::first().cycle_prev_index() == T::last().index_of()`
/// (i.e. `T::CARDINALITY - 1`) is the natural fixpoint the
/// backward-wrapping-neighbor-index axis and the head-endpoint
/// anchor share, mirroring `T::first().cycle_prev() == T::last()`
/// one return-type axis over AND `T::first().cycle_prev_label() ==
/// T::last_label()` one return-type axis over.
fn cycle_prev_index(self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::cycle_prev(self))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor immediately
/// AFTER `self` in [`Self::sorted_variants`], WRAPPING to `0` at
/// the lex tail — the lex position of [`Self::cycle_sorted_next`]
/// projected through [`Self::sorted_index_of`]. Returns `usize`,
/// never [`Option<usize>`]: the wrapping arm folds the lex-tail-
/// endpoint boundary onto the lex-head-index-anchor `0` rather than
/// leaving the [`None`] the bounded-lex-neighbor-index axis returns.
///
/// The lex-order forward-wrapping arm of the (declaration × lex) ×
/// (forward, backward) × (Option-typed-bounded, wrapping) ×
/// (`Self`-return, `&'static str`-return, `usize`-return) 2×2×2×3 =
/// 24-corner index-and-label-and-variant bounded-plus-wrapping
/// traversal hypercube — one ordering axis over from
/// [`Self::cycle_next_index`] (declaration-order wrapping-forward
/// index), one bounded/wrapping axis over from
/// [`Self::sorted_next_index`] (lex-order bounded-forward index),
/// and one return-type axis over from [`Self::cycle_sorted_next`]
/// (lex-order wrapping-forward variant) AND from
/// [`Self::cycle_sorted_next_label`] (lex-order wrapping-forward
/// label).
///
/// Every generic consumer that renders the wrapping-forward-lex-
/// neighbor SLOT of a typed variant (an alphabetized-cyclic LSP
/// completion cursor that emits "next-lex-slot: <index>" for the
/// wrapping lex-sorted successor unconditionally, an alphabetized
/// round-robin picker that logs the next lex-cyclic slot as its
/// rotation banner, an alphabetized carousel widget's next-tab lex-
/// slot renderer, a lex-cyclic per-tick animation frame picker) binds
/// to ONE typed method on the trait rather than re-deriving the
/// `v.cycle_sorted_next().sorted_index_of()` two-primitive
/// composition OR the `v.sorted_next_index().unwrap_or(0)` two-
/// primitive composition at every callsite.
///
/// Default body composes [`Self::cycle_sorted_next`] with
/// [`Self::sorted_index_of`] verbatim. The wrapping-lex-neighbor-
/// index contract — the lex-tail arm returns `0` (the lex-head-
/// endpoint's lex slot) — is guaranteed by the default composition
/// through [`Self::cycle_sorted_next`]'s lex-tail-wrap-to-lex-head
/// fold + [`Self::sorted_index_of`]'s natural `0`-at-lex-head
/// projection; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (72) pins the
/// composition against the natural
/// `cycle_sorted_next().sorted_index_of()` shape AND the lex-tail-
/// endpoint `0` fold on every implementor.
/// `T::sorted_last().cycle_sorted_next_index() ==
/// T::sorted_first().sorted_index_of()` (i.e. `0`) is the natural
/// fixpoint the forward-wrapping-lex-neighbor-index axis and the
/// lex-tail-endpoint anchor share, mirroring
/// `T::sorted_last().cycle_sorted_next() == T::sorted_first()`
/// one return-type axis over AND
/// `T::sorted_last().cycle_sorted_next_label() ==
/// T::sorted_first_label()` one return-type axis over AND
/// `T::last().cycle_next_index() == 0` one ordering axis over.
fn cycle_sorted_next_index(self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::cycle_sorted_next(self))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor immediately
/// BEFORE `self` in [`Self::sorted_variants`], WRAPPING to
/// `T::CARDINALITY - 1` at the lex head — the lex position of
/// [`Self::cycle_sorted_prev`] projected through
/// [`Self::sorted_index_of`]. Returns `usize`, never
/// [`Option<usize>`]: the wrapping arm folds the lex-head-endpoint
/// boundary onto the lex-tail-index-anchor rather than leaving the
/// [`None`] the bounded-lex-neighbor-index axis returns.
///
/// Sibling posture to [`Self::cycle_sorted_next_index`] one
/// direction over on the (forward, backward) direction partition of
/// the closed-set wrapping-lex-index-neighbor surface. See
/// [`Self::cycle_sorted_next_index`] for the shared design
/// rationale, sibling 2×2×2×3 = 24-corner hypercube, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration.
///
/// Default body composes [`Self::cycle_sorted_prev`] with
/// [`Self::sorted_index_of`] verbatim. The wrapping-lex-neighbor-
/// index contract — the lex-head arm returns `T::CARDINALITY - 1`
/// (the lex-tail-endpoint's lex slot) — is guaranteed by the
/// default composition through [`Self::cycle_sorted_prev`]'s lex-
/// head-wrap-to-lex-tail fold; the well-formedness contract
/// [`assert_closed_set_well_formed`]'s new clause (73) pins the
/// composition against the natural
/// `cycle_sorted_prev().sorted_index_of()` shape AND the lex-head-
/// endpoint `T::CARDINALITY - 1` fold on every implementor. Clauses
/// (26) + (27) + (28) + (29) + (58) + (59) + (60) + (61) + (62) +
/// (63) + (64) + (65) + (66) + (67) + (68) + (69) + (70) + (71) +
/// (72) + (73) together CLOSE the (declaration × lex) × (forward,
/// backward) × (Option-typed-bounded, wrapping) × (`Self`-return,
/// `&'static str`-return, `usize`-return) 2×2×2×3 = 24-corner
/// bounded-plus-wrapping return-shape hypercube on the closed-set
/// traversal surface.
fn cycle_sorted_prev_index(self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::cycle_sorted_prev(self))
}
/// The declaration-order strict-precedence pairwise predicate —
/// `true` iff `self` appears strictly before `other` in
/// [`Self::ALL`]'s declaration order, `false` on equality or when
/// `self` appears strictly after `other`. The binary peer of every
/// pre-existing UNARY declaration-axis endpoint predicate
/// ([`Self::is_first`], [`Self::is_last`], [`Self::is_endpoint`],
/// [`Self::is_interior`], [`Self::is_first_label`],
/// [`Self::is_last_label`], [`Self::is_endpoint_label`],
/// [`Self::is_interior_label`], [`Self::is_first_index`],
/// [`Self::is_last_index`], [`Self::is_endpoint_index`],
/// [`Self::is_interior_index`]) — those methods answer "where does
/// this ONE variant sit in the declaration axis," this method
/// answers "which of these TWO variants sits earlier in the
/// declaration axis." Opens the (self, other) pairwise-comparison
/// axis on the closed-set surface at the declaration-order
/// strict-less-than corner.
///
/// Sibling posture to [`Self::sorted_precedes`] (the lex-axis peer
/// on the same pairwise-comparison surface) and [`Self::succeeds`]
/// (the strict-greater-than direction-arm on the declaration
/// axis). Together the four methods CLOSE the (ordering × direction)
/// 2×2 = 4-corner pairwise-comparison matrix — declaration
/// × forward → [`Self::precedes`], declaration × backward →
/// [`Self::succeeds`], lex × forward → [`Self::sorted_precedes`],
/// lex × backward → [`Self::sorted_succeeds`].
///
/// Default body composes [`Self::index_of`] on both operands with
/// the standard-library `<` operator — the pairwise-comparison
/// predicate is a typed CONSEQUENCE of the (variant → declaration
/// position) projection, not a second codepath through a
/// per-variant `match` body. Implementors override only when the
/// pairwise-comparison surface needs to diverge from the natural
/// `index_of(self) < index_of(other)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `is_endpoint` / `is_first` / `is_last` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::index_of`] propagates the override through
/// this default body automatically; the (variant pair → bool
/// pairwise-precedence) projection funnels through ONE typed
/// primitive.
///
/// Strict-order contract: [`Self::precedes`] is
/// - IRREFLEXIVE: `!v.precedes(v)` for every `v` in [`Self::ALL`]
/// (a variant cannot strictly precede itself);
/// - ASYMMETRIC: `a.precedes(b) → !b.precedes(a)` for every pair
/// `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (strict precedence
/// is a directed edge);
/// - TRANSITIVE: `a.precedes(b) ∧ b.precedes(c) → a.precedes(c)`
/// for every triple `(a, b, c)` in
/// [`Self::ALL`] × [`Self::ALL`] × [`Self::ALL`] (declaration
/// order is a strict total order);
/// - TRICHOTOMOUS: exactly one of `a.precedes(b)`,
/// `a == b`, `b.precedes(a)` holds for every pair `(a, b)` in
/// [`Self::ALL`] × [`Self::ALL`] (declaration order is
/// TOTAL — every pair of distinct variants is comparable).
///
/// The four laws are guaranteed by the composition through
/// [`Self::index_of`] (which projects into `[0, CARDINALITY)` and
/// is injective by clause (17) on the well-formedness sweep) and
/// the standard-library `<` on `usize`'s strict total order — the
/// pairwise-comparison predicate emerges as a TYPED CONSEQUENCE
/// of the declaration-axis index bijection, not as a per-
/// implementor hand-rolled body. Pinned by
/// `precedes_is_irreflexive_across_every_variant`,
/// `precedes_is_asymmetric_across_every_pair`,
/// `precedes_is_transitive_across_every_triple`, and
/// `precedes_is_trichotomous_across_every_pair`.
///
/// Cross-axis composition law:
/// `a.precedes(b) == (a.index_of() < b.index_of())` for every
/// pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the
/// declaration-axis strict-precedence predicate binds byte-for-
/// byte to the `<` comparison on the (variant → declaration
/// position) projection). Pinned by
/// `precedes_agrees_with_index_of_strict_less_than_on_every_pair`.
///
/// Complement axis: `!a.precedes(b) && a != b → b.precedes(a)`
/// for every pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the
/// pairwise-precedence predicate's negation across the diagonal
/// IS the reverse-direction pairwise-precedence). Pinned by
/// `precedes_negation_off_diagonal_equals_reverse_precedence`.
///
/// Future consumers that compose against
/// [`Self::precedes`]: a `tatara-check` predicate
/// `(check-declaration-order-precedes …)` verifying a workspace-
/// wide phase-ordering constraint (e.g.
/// `Pending.precedes(Running)`), a Sekiban audit-trail metric
/// jointly labeled by the (before, after) pair of a phase
/// transition, an LSP diagnostic that sorts a set of variants in
/// declaration order via `Vec::sort_by(|a, b| if a.precedes(*b)
/// { Ordering::Less } else if b.precedes(*a) { Ordering::Greater
/// } else { Ordering::Equal })` — bind to ONE typed pairwise-
/// comparison predicate rather than re-deriving the
/// `index_of` composition inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the
/// pairwise-comparison predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `index_of(self) < index_of(other)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the pairwise-comparison surface was an unnamed inline
/// composition recurring at every prospective downstream
/// pairwise-ordering site pre-lift. Naming it on the trait makes
/// the predicate a TYPED CONSEQUENCE of the declaration-axis
/// index bijection — generic consumers see ONE typed predicate,
/// not ONE inline-composition-shape-per-crate. THEORY.md §VI.1 —
/// generation over composition; the pairwise-precedence
/// predicate emerges from the composition of TWO substrate
/// primitives ([`Self::index_of`] on both operands + the
/// standard-library `<` on `usize`) rather than as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Idris's `Fin n`-indexed comparison
/// primitives (`fin-lt`) surface pairwise-precedence as a
/// first-class predicate on the finite-cardinality type;
/// Haskell's `Data.Ord` type class exposes `compare :: a -> a
/// -> Ordering` as the trichotomous pairwise-comparison
/// primitive on any ordered type. Translation through pleme-io
/// primitives: the pairwise-precedence predicate on the closed-
/// set trait binds through [`Self::index_of`]'s declaration-axis
/// bijection into `usize`'s strict total order, so the trait
/// composition emerges from the substrate's typed index
/// projection rather than as a fresh substrate primitive.
fn precedes(self, other: Self) -> bool {
<Self as ClosedSet>::index_of(self) < <Self as ClosedSet>::index_of(other)
}
/// The declaration-order strict-succession pairwise predicate —
/// `true` iff `self` appears strictly AFTER `other` in
/// [`Self::ALL`]'s declaration order, `false` on equality or when
/// `self` appears strictly before `other`. The direction-complement
/// arm of [`Self::precedes`] on the (forward, backward) axis of
/// the declaration-order pairwise-comparison surface.
///
/// Sibling posture to [`Self::precedes`] one arm over on the
/// (forward, backward) direction axis — [`Self::precedes`] fires
/// when `self` sits strictly earlier, this method fires when
/// `self` sits strictly later. See [`Self::precedes`] for the
/// shared strict-order laws (irreflexivity, asymmetry,
/// transitivity, trichotomy), the cross-axis composition through
/// [`Self::index_of`], the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// reverse-direction arm of the same pairwise-comparison surface
/// and inherits every property from the forward arm's
/// documentation, differing only in the reversed operand order.
///
/// Default body composes [`Self::precedes`] with the operand
/// swap: `other.precedes(self)`. The succession predicate is a
/// typed CONSEQUENCE of the precedence predicate applied with
/// reversed operands, not a second codepath through
/// `index_of(self) > index_of(other)` inline. Implementors
/// override only when the succession surface needs to diverge
/// from the natural `other.precedes(self)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `is_endpoint` / `is_first` / `is_last` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::precedes`] propagates the override through
/// this default body automatically; the (variant pair → bool
/// pairwise-succession) projection funnels through ONE typed
/// primitive.
///
/// Direction-complement contract: `a.succeeds(b) == b.precedes(a)`
/// for every pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the
/// succession predicate binds byte-for-byte to the reverse-
/// operand precedence predicate). Pinned by
/// `succeeds_is_reverse_precedes_across_every_pair`.
fn succeeds(self, other: Self) -> bool {
<Self as ClosedSet>::precedes(other, self)
}
/// The lex-order strict-precedence pairwise predicate — `true`
/// iff `self` appears strictly before `other` in lexicographic
/// order over [`Self::label`]'s projection, `false` on equality
/// or when `self` appears strictly after `other`. The
/// lex-ordering peer of [`Self::precedes`] on the (declaration,
/// lex) ordering axis of the pairwise-comparison surface.
///
/// Sibling posture to [`Self::precedes`] one arm over on the
/// (declaration, lex) ordering axis — [`Self::precedes`] uses
/// [`Self::index_of`] (declaration position), this method uses
/// [`Self::sorted_index_of`] (lex position). See
/// [`Self::precedes`] for the shared strict-order laws
/// (irreflexivity, asymmetry, transitivity, trichotomy), the
/// cross-axis composition, the future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the lex-axis arm of the same pairwise-comparison surface
/// and inherits every property from the declaration arm's
/// documentation, differing only in the projection method the
/// composition routes through.
///
/// Default body composes [`Self::sorted_index_of`] on both
/// operands with the standard-library `<` operator. Implementors
/// override only when the lex-axis pairwise-comparison surface
/// needs to diverge from the natural `sorted_index_of(self) <
/// sorted_index_of(other)` shape.
///
/// Cross-axis composition law:
/// `a.sorted_precedes(b) == (a.sorted_index_of() <
/// b.sorted_index_of())` for every pair `(a, b)` in
/// [`Self::ALL`] × [`Self::ALL`] (the lex-axis strict-precedence
/// predicate binds byte-for-byte to the `<` comparison on the
/// (variant → lex position) projection). Pinned by
/// `sorted_precedes_agrees_with_sorted_index_of_strict_less_than_on_every_pair`.
///
/// Cross-ordering peer contract:
/// `a.sorted_precedes(b) ↔ (a.label() < b.label())` for every
/// pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the lex-axis
/// pairwise-comparison predicate binds byte-for-byte to the
/// `&str`'s natural lex comparison). Pinned by
/// `sorted_precedes_agrees_with_label_lex_less_than_on_every_pair`.
fn sorted_precedes(self, other: Self) -> bool {
<Self as ClosedSet>::sorted_index_of(self) < <Self as ClosedSet>::sorted_index_of(other)
}
/// The lex-order strict-succession pairwise predicate — `true`
/// iff `self` appears strictly AFTER `other` in lexicographic
/// order over [`Self::label`]'s projection, `false` on equality
/// or when `self` appears strictly before `other`. The
/// direction-complement of [`Self::sorted_precedes`] on the
/// (forward, backward) direction axis of the lex-ordering
/// pairwise-comparison surface.
///
/// Sibling posture to [`Self::sorted_precedes`] one arm over on
/// the (forward, backward) direction axis, AND to
/// [`Self::succeeds`] one arm over on the (declaration, lex)
/// ordering axis — the lex-order strict-succession predicate is
/// the intersection of both direction-complement axes over the
/// declaration-axis strict-precedence predicate. See
/// [`Self::precedes`] for the shared strict-order laws,
/// [`Self::succeeds`] for the direction-complement contract on
/// the declaration axis, and [`Self::sorted_precedes`] for the
/// lex-axis cross-composition — this method inherits every
/// property from those three and closes the four-corner
/// (ordering × direction) 2×2 pairwise-comparison matrix on the
/// closed-set surface EXHAUSTIVELY.
///
/// Default body composes [`Self::sorted_precedes`] with the
/// operand swap: `other.sorted_precedes(self)`. The lex-order
/// succession predicate is a typed CONSEQUENCE of the lex-order
/// precedence predicate applied with reversed operands.
///
/// Direction-complement contract: `a.sorted_succeeds(b) ==
/// b.sorted_precedes(a)` for every pair `(a, b)` in
/// [`Self::ALL`] × [`Self::ALL`] (the lex-order succession
/// predicate binds byte-for-byte to the reverse-operand lex-
/// order precedence predicate). Pinned by
/// `sorted_succeeds_is_reverse_sorted_precedes_across_every_pair`.
///
/// (74) + (75) + (76) + (77) together CLOSE the (declaration ×
/// lex) × (forward, backward) 2×2 = 4-corner pairwise-comparison
/// matrix on the closed-set surface — declaration × forward →
/// [`Self::precedes`], declaration × backward →
/// [`Self::succeeds`], lex × forward → [`Self::sorted_precedes`],
/// lex × backward → [`Self::sorted_succeeds`] — opening the
/// (self, other) binary pairwise-comparison axis at the strict-
/// less-than / strict-greater-than corners of the declaration
/// AND lex ordering axes exhaustively.
fn sorted_succeeds(self, other: Self) -> bool {
<Self as ClosedSet>::sorted_precedes(other, self)
}
/// The declaration-order non-strict-precedence pairwise predicate —
/// `true` iff `self` appears before OR is equal to `other` in
/// [`Self::ALL`]'s declaration order, `false` when `self` appears
/// strictly after `other`. The strictness-complement of
/// [`Self::precedes`] on the (strict, non-strict) axis of the
/// declaration-order pairwise-comparison surface.
///
/// Sibling posture to [`Self::precedes`] one arm over on the
/// (strict, non-strict) strictness axis, [`Self::succeeds_or_equal`]
/// one arm over on the (forward, backward) direction axis, and
/// [`Self::sorted_precedes_or_equal`] one arm over on the
/// (declaration, lex) ordering axis. Together with the pre-existing
/// [`Self::precedes`] / [`Self::succeeds`] / [`Self::sorted_precedes`]
/// / [`Self::sorted_succeeds`] quartet AND the three non-strict
/// siblings the four methods CLOSE the (ordering × direction ×
/// strictness) 2×2×2 = 8-corner pairwise-comparison hypercube on the
/// closed-set surface EXHAUSTIVELY — declaration × forward × strict
/// → [`Self::precedes`], declaration × backward × strict →
/// [`Self::succeeds`], lex × forward × strict →
/// [`Self::sorted_precedes`], lex × backward × strict →
/// [`Self::sorted_succeeds`], declaration × forward × non-strict →
/// [`Self::precedes_or_equal`], declaration × backward × non-strict
/// → [`Self::succeeds_or_equal`], lex × forward × non-strict →
/// [`Self::sorted_precedes_or_equal`], lex × backward × non-strict
/// → [`Self::sorted_succeeds_or_equal`].
///
/// Default body composes [`Self::index_of`] on both operands with
/// the standard-library `<=` operator — the non-strict
/// pairwise-comparison predicate is a typed CONSEQUENCE of the
/// (variant → declaration position) projection, not a second
/// codepath through a per-variant `match` body. Implementors
/// override only when the non-strict pairwise-comparison surface
/// needs to diverge from the natural
/// `index_of(self) <= index_of(other)` shape (no production
/// implementor reaches for this today; the axis exists for the
/// same reason `is_endpoint` / `is_first` / `is_last` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). An implementor that
/// overrides [`Self::index_of`] propagates the override through
/// this default body automatically; the (variant pair → bool
/// non-strict pairwise-precedence) projection funnels through ONE
/// typed primitive.
///
/// Non-strict-order contract: [`Self::precedes_or_equal`] is
/// - REFLEXIVE: `v.precedes_or_equal(v)` for every `v` in
/// [`Self::ALL`] (a variant non-strictly precedes itself — the
/// equality arm folds into the acceptance side of the predicate
/// AT the diagonal, in contrast to [`Self::precedes`]'s strict-
/// precedence surface which excludes the diagonal);
/// - ANTISYMMETRIC:
/// `a.precedes_or_equal(b) ∧ b.precedes_or_equal(a) → a == b`
/// for every pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`]
/// (two-sided non-strict precedence collapses to equality —
/// distinct variants sit with exactly ONE direction of
/// non-strict precedence, not both);
/// - TRANSITIVE:
/// `a.precedes_or_equal(b) ∧ b.precedes_or_equal(c) →
/// a.precedes_or_equal(c)` for every triple `(a, b, c)` in
/// [`Self::ALL`] × [`Self::ALL`] × [`Self::ALL`] (declaration
/// order is a non-strict total order);
/// - TOTAL:
/// `a.precedes_or_equal(b) ∨ b.precedes_or_equal(a)` for every
/// pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (declaration
/// order is a TOTAL non-strict order — at least one direction
/// holds on every pair, in contrast to [`Self::precedes`]'s
/// strict-precedence surface which fails both directions on the
/// diagonal).
///
/// The four laws are guaranteed by the composition through
/// [`Self::index_of`] (which projects into `[0, CARDINALITY)` and
/// is injective by clause (17) on the well-formedness sweep) and
/// the standard-library `<=` on `usize`'s non-strict total order —
/// the pairwise-comparison predicate emerges as a TYPED CONSEQUENCE
/// of the declaration-axis index bijection, not as a per-
/// implementor hand-rolled body. Pinned by
/// `precedes_or_equal_is_reflexive_across_every_variant`,
/// `precedes_or_equal_is_antisymmetric_across_every_pair`,
/// `precedes_or_equal_is_transitive_across_every_triple`, and
/// `precedes_or_equal_is_total_across_every_pair`.
///
/// Cross-axis composition law:
/// `a.precedes_or_equal(b) == (a.index_of() <= b.index_of())` for
/// every pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the
/// declaration-axis non-strict-precedence predicate binds byte-for-
/// byte to the `<=` comparison on the (variant → declaration
/// position) projection). Pinned by
/// `precedes_or_equal_agrees_with_index_of_less_than_or_equal_on_every_pair`.
///
/// Cross-strictness composition law:
/// `a.precedes_or_equal(b) == (a.precedes(b) || a == b)` for every
/// pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the non-strict
/// predicate is the disjunction of the strict predicate and
/// equality on the diagonal — the strictness axis carves the
/// pairwise-comparison surface into TWO typed projections that
/// agree off-diagonal AND partition the diagonal exclusively
/// between them). Pinned by
/// `precedes_or_equal_equals_precedes_or_equality_on_every_pair`.
///
/// Future consumers that compose against
/// [`Self::precedes_or_equal`]: a `tatara-check` predicate
/// `(check-declaration-order-non-strict-precedes …)` verifying a
/// workspace-wide monotonic phase-transition constraint (e.g.
/// `previous_phase.precedes_or_equal(next_phase)` on a re-entrant
/// SIGHUP path where an idempotent no-op transition to the same
/// phase is legal), a Sekiban audit-trail metric jointly labeled
/// by the (before, after) pair of a phase transition where the
/// same-phase self-loop is a canonical arm, an LSP diagnostic
/// that ranges over a half-open interval of variants via
/// `T::ALL.iter().filter(|v| lo.precedes_or_equal(**v) &&
/// v.precedes_or_equal(hi))` — bind to ONE typed non-strict
/// pairwise-comparison predicate rather than re-deriving the
/// `precedes(x, y) || x == y` composition inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the non-strict
/// pairwise-comparison predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `index_of(self) <= index_of(other)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the strictness axis was an unnamed inline composition
/// (`precedes(x, y) || x == y`) recurring at every prospective
/// downstream non-strict-pairwise-ordering site pre-lift. Naming
/// it on the trait makes the predicate a TYPED CONSEQUENCE of the
/// declaration-axis index bijection. THEORY.md §VI.1 — generation
/// over composition; the non-strict pairwise-precedence predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::index_of`] on both operands + the standard-library
/// `<=` on `usize`) rather than as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Idris's `Fin n`-indexed non-strict
/// comparison primitives (`fin-lte`) surface non-strict
/// pairwise-precedence as a first-class predicate on the finite-
/// cardinality type; Haskell's `Data.Ord` type class exposes `<=`
/// as the non-strict pairwise-comparison primitive alongside the
/// strict `<` on any ordered type. Translation through pleme-io
/// primitives: the non-strict pairwise-precedence predicate on
/// the closed-set trait binds through [`Self::index_of`]'s
/// declaration-axis bijection into `usize`'s non-strict total
/// order, so the trait composition emerges from the substrate's
/// typed index projection rather than as a fresh substrate
/// primitive.
fn precedes_or_equal(self, other: Self) -> bool {
<Self as ClosedSet>::index_of(self) <= <Self as ClosedSet>::index_of(other)
}
/// The declaration-order non-strict-succession pairwise predicate —
/// `true` iff `self` appears AFTER OR is equal to `other` in
/// [`Self::ALL`]'s declaration order, `false` when `self` appears
/// strictly before `other`. The direction-complement arm of
/// [`Self::precedes_or_equal`] on the (forward, backward) axis of
/// the declaration-order non-strict pairwise-comparison surface.
///
/// Sibling posture to [`Self::precedes_or_equal`] one arm over on
/// the (forward, backward) direction axis, AND to
/// [`Self::succeeds`] one arm over on the (strict, non-strict)
/// strictness axis — [`Self::precedes_or_equal`] fires when `self`
/// sits earlier OR equal, this method fires when `self` sits later
/// OR equal. See [`Self::precedes_or_equal`] for the shared
/// non-strict-order laws (reflexivity, antisymmetry, transitivity,
/// totality), the cross-axis composition through [`Self::index_of`],
/// the cross-strictness composition through [`Self::succeeds`] on
/// the strict axis, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// reverse-direction arm of the same non-strict pairwise-comparison
/// surface and inherits every property from the forward arm's
/// documentation, differing only in the reversed operand order.
///
/// Default body composes [`Self::precedes_or_equal`] with the
/// operand swap: `other.precedes_or_equal(self)`. The non-strict
/// succession predicate is a typed CONSEQUENCE of the non-strict
/// precedence predicate applied with reversed operands, not a
/// second codepath through `index_of(self) >= index_of(other)`
/// inline. An implementor that overrides [`Self::precedes_or_equal`]
/// propagates the override through this default body automatically;
/// the (variant pair → bool non-strict pairwise-succession)
/// projection funnels through ONE typed primitive.
///
/// Direction-complement contract:
/// `a.succeeds_or_equal(b) == b.precedes_or_equal(a)` for every
/// pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the non-strict
/// succession predicate binds byte-for-byte to the reverse-operand
/// non-strict precedence predicate). Pinned by
/// `succeeds_or_equal_is_reverse_precedes_or_equal_across_every_pair`.
fn succeeds_or_equal(self, other: Self) -> bool {
<Self as ClosedSet>::precedes_or_equal(other, self)
}
/// The lex-order non-strict-precedence pairwise predicate — `true`
/// iff `self` appears before OR is equal to `other` in lexicographic
/// order over [`Self::label`]'s projection, `false` when `self`
/// appears strictly after `other`. The lex-ordering peer of
/// [`Self::precedes_or_equal`] on the (declaration, lex) ordering
/// axis of the non-strict pairwise-comparison surface.
///
/// Sibling posture to [`Self::precedes_or_equal`] one arm over on
/// the (declaration, lex) ordering axis — [`Self::precedes_or_equal`]
/// uses [`Self::index_of`] (declaration position), this method uses
/// [`Self::sorted_index_of`] (lex position). See
/// [`Self::precedes_or_equal`] for the shared non-strict-order laws
/// (reflexivity, antisymmetry, transitivity, totality), the
/// cross-axis composition, the cross-strictness composition
/// through [`Self::sorted_precedes`] on the strict axis, the
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// non-strict pairwise-comparison surface and inherits every
/// property from the declaration arm's documentation, differing
/// only in the projection method the composition routes through.
///
/// Default body composes [`Self::sorted_index_of`] on both operands
/// with the standard-library `<=` operator. Implementors override
/// only when the lex-axis non-strict pairwise-comparison surface
/// needs to diverge from the natural
/// `sorted_index_of(self) <= sorted_index_of(other)` shape.
///
/// Cross-axis composition law:
/// `a.sorted_precedes_or_equal(b) == (a.sorted_index_of() <=
/// b.sorted_index_of())` for every pair `(a, b)` in
/// [`Self::ALL`] × [`Self::ALL`] (the lex-axis non-strict-precedence
/// predicate binds byte-for-byte to the `<=` comparison on the
/// (variant → lex position) projection). Pinned by
/// `sorted_precedes_or_equal_agrees_with_sorted_index_of_less_than_or_equal_on_every_pair`.
///
/// Cross-ordering peer contract:
/// `a.sorted_precedes_or_equal(b) ↔ (a.label() <= b.label())` for
/// every pair `(a, b)` in [`Self::ALL`] × [`Self::ALL`] (the
/// lex-axis non-strict pairwise-comparison predicate binds byte-
/// for-byte to the `&str`'s natural non-strict lex comparison).
/// Pinned by
/// `sorted_precedes_or_equal_agrees_with_label_lex_less_than_or_equal_on_every_pair`.
fn sorted_precedes_or_equal(self, other: Self) -> bool {
<Self as ClosedSet>::sorted_index_of(self) <= <Self as ClosedSet>::sorted_index_of(other)
}
/// The lex-order non-strict-succession pairwise predicate — `true`
/// iff `self` appears AFTER OR is equal to `other` in lexicographic
/// order over [`Self::label`]'s projection, `false` when `self`
/// appears strictly before `other`. The direction-complement of
/// [`Self::sorted_precedes_or_equal`] on the (forward, backward)
/// direction axis of the lex-ordering non-strict pairwise-
/// comparison surface.
///
/// Sibling posture to [`Self::sorted_precedes_or_equal`] one arm
/// over on the (forward, backward) direction axis, to
/// [`Self::succeeds_or_equal`] one arm over on the (declaration,
/// lex) ordering axis, AND to [`Self::sorted_succeeds`] one arm
/// over on the (strict, non-strict) strictness axis — the lex-order
/// non-strict-succession predicate is the intersection of all
/// three complement axes over the declaration-axis strict-precedence
/// predicate. See [`Self::precedes_or_equal`] for the shared non-
/// strict-order laws, [`Self::succeeds_or_equal`] for the
/// direction-complement contract on the declaration axis, and
/// [`Self::sorted_precedes_or_equal`] for the lex-axis cross-
/// composition — this method inherits every property from those
/// three and CLOSES the eight-corner (ordering × direction ×
/// strictness) 2×2×2 pairwise-comparison hypercube on the
/// closed-set surface EXHAUSTIVELY.
///
/// Default body composes [`Self::sorted_precedes_or_equal`] with
/// the operand swap: `other.sorted_precedes_or_equal(self)`. The
/// lex-order non-strict-succession predicate is a typed CONSEQUENCE
/// of the lex-order non-strict-precedence predicate applied with
/// reversed operands.
///
/// Direction-complement contract: `a.sorted_succeeds_or_equal(b) ==
/// b.sorted_precedes_or_equal(a)` for every pair `(a, b)` in
/// [`Self::ALL`] × [`Self::ALL`] (the lex-order non-strict
/// succession predicate binds byte-for-byte to the reverse-operand
/// lex-order non-strict precedence predicate). Pinned by
/// `sorted_succeeds_or_equal_is_reverse_sorted_precedes_or_equal_across_every_pair`.
///
/// (78) + (79) + (80) + (81) together CLOSE the (declaration ×
/// lex) × (forward, backward) × (strict, non-strict) 2×2×2 = 8-corner
/// pairwise-comparison hypercube on the closed-set surface — every
/// combination of ordering-axis × direction-axis × strictness-axis
/// binds through ONE typed pairwise-comparison predicate on the
/// trait, each routing through the substrate's typed index-axis
/// bijection into `usize`'s (strict / non-strict) total order at
/// ONE composition site.
fn sorted_succeeds_or_equal(self, other: Self) -> bool {
<Self as ClosedSet>::sorted_precedes_or_equal(other, self)
}
/// The declaration-order binary pairwise MIN projection — the
/// earlier of `self` and `other` in [`Self::ALL`]'s declaration
/// order. Returns `self` when `self.precedes_or_equal(other)` (so
/// ties fold to `self`, matching Rust's [`core::cmp::min`] tie-
/// break convention), returns `other` otherwise.
///
/// The Self-return value-selection sibling of the bool-return
/// pairwise-precedence predicate hypercube on the (return-shape)
/// axis of the binary-arity surface. Where
/// [`Self::precedes_or_equal`] answers "does `self` sit at or
/// before `other`?", this method returns the variant that DOES —
/// the min projection is the identity on the accepting half of
/// the non-strict pairwise-precedence relation. Together with
/// [`Self::max`] closes the (min, max) partition of the binary
/// pairwise-selection surface at the (return-shape) column on
/// the declaration axis; together with [`Self::sorted_min`] and
/// [`Self::sorted_max`] closes the (ordering × direction) 2×2 = 4-
/// corner pairwise-selection matrix on the closed-set surface at
/// the Self-return arm.
///
/// The Self-return arm of the (bool-return, Self-return) return-
/// shape partition of the binary pairwise-comparison surface: the
/// bool-return arm carries the (78)+(79)+(80)+(81) pairwise-
/// comparison hypercube via [`Self::precedes`],
/// [`Self::succeeds`], [`Self::precedes_or_equal`],
/// [`Self::succeeds_or_equal`], and their sorted peers; the Self-
/// return arm carries the min/max value-selection quartet this
/// method opens. Every generic consumer that needs "the earlier
/// of two variants" as a variant (rather than a bool answer to
/// "does the earlier one exist?") binds to ONE typed method
/// rather than re-deriving the
/// `if a.precedes_or_equal(b) { a } else { b }` composition
/// inline per callsite — a compact-encoding step that picks the
/// canonical member of an unordered pair for a stable index-slot
/// key, an LSP quickfix that projects a pair of enum tags to the
/// declaration-order earlier one for a "widen to lo" recommendation,
/// a `tatara-check` predicate `(min-phase a b)` folding two phase
/// observations to the earlier lifecycle stage, a Sekiban audit-
/// trail projector that reduces observed phase pairs to the
/// earliest stage for the "phase-min" derived metric.
///
/// Bracket contract: `min(a, b).precedes_or_equal(a)` AND
/// `min(a, b).precedes_or_equal(b)` on every pair `(a, b)` — the
/// min projection is a LOWER BOUND of the two operands under
/// non-strict declaration-order precedence. Pinned by
/// `min_precedes_or_equal_both_operands_on_every_pair`.
///
/// Membership contract: `min(a, b) == a` OR `min(a, b) == b` on
/// every pair — the min projection is one of the two operands
/// (never a third variant). Pinned by
/// `min_returns_one_of_its_two_operands_on_every_pair`.
///
/// Idempotence contract: `min(v, v) == v` on every variant — the
/// diagonal is the identity. Pinned by
/// `min_is_idempotent_on_the_diagonal_across_every_variant`.
///
/// Tie-break contract: `min(a, a) == a` AND when `a.index_of() ==
/// b.index_of()` (only possible when `a == b` in the closed set)
/// the projection returns `a` — the tie-break is left-biased,
/// mirroring [`core::cmp::min`]'s convention.
///
/// Cross-primitive composition contract: `clamp(v, lo, hi) ==
/// max(lo, min(v, hi))` on every well-formed triple `(v, lo, hi)`
/// with `lo.precedes_or_equal(hi)` — the ternary [`Self::clamp`]
/// projection is the canonical `max ∘ min` composition on the
/// closed-set surface. Pinned by
/// `min_composes_with_max_into_clamp_on_every_well_formed_triple`.
///
/// Default body composes [`Self::precedes_or_equal`] with the
/// tie-break-left variant selection — `if
/// self.precedes_or_equal(other) { self } else { other }`.
/// Implementors override only when the declaration-axis binary
/// min projection needs to diverge from the natural non-strict-
/// precedence-guarded selection (no production implementor
/// reaches for this today; the axis exists for the same reason
/// `via` / `set_label` / `labels` / `precedes` / `clamp`
/// overrides exist — a typed escape hatch rather than forcing
/// the implementor to hand-roll the impl).
///
/// Theory anchor: THEORY.md §III — the typescape; the binary
/// pairwise MIN projection becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `if a <= b { a } else { b }` shape at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the min
/// projection was an unnamed inline composition
/// (`if a.precedes_or_equal(b) { a } else { b }`) recurring at
/// every prospective downstream pairwise-selection site pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the non-strict pairwise-precedence predicate,
/// symmetric to how [`Self::clamp`] emerges as a typed
/// consequence of the strict pairwise-precedence predicate at
/// both range endpoints one arity level up on the (arity) axis.
/// THEORY.md §VI.1 — generation over composition; the binary MIN
/// projection emerges from the composition of ONE substrate
/// primitive ([`Self::precedes_or_equal`]) with the standard-
/// library `if`/`else` on `bool` rather than as a per-implementor
/// hand-rolled body. A future tightening of the underlying
/// non-strict-precedence primitive (a perfect-hash index lookup,
/// a const-fn axis making the predicate callable in const
/// contexts) propagates to every closed-set min consumer through
/// this method's body.
///
/// Frontier inspiration: Rust's [`core::cmp::min`] exposes the
/// same left-biased pairwise MIN projection on any `Ord` type
/// (`if a <= b { a } else { b }`) — the substrate mirrors the
/// tie-break-left convention on the closed-set surface without
/// requiring the `Ord` supertrait bound the trait's typed
/// pairwise-precedence primitives make redundant. Kotlin's
/// `minOf(a, b)` and Julia's `Base.min(a, b)` surface the same
/// projection on ordered types; Idris's `min : Ord a => a -> a
/// -> a` on the `Ord` type-class. MLIR's
/// `RegisteredOperationName::min(a, b)` on the Op registry
/// under the declaration-order chain. Translation through
/// pleme-io primitives: a pure default method composing the
/// trait's existing [`Self::precedes_or_equal`] surface with the
/// standard-library `if`/`else` on `bool` — no new dep, no new
/// IR layer, no supertrait bound (the pairwise-precedence
/// primitive replaces the `Ord` bound), no `Option`-typed
/// dispatch, no allocation.
fn min(self, other: Self) -> Self {
if <Self as ClosedSet>::precedes_or_equal(self, other) {
self
} else {
other
}
}
/// The declaration-order binary pairwise MAX projection — the
/// later of `self` and `other` in [`Self::ALL`]'s declaration
/// order. Returns `self` when `self.succeeds_or_equal(other)`
/// (ties fold to `self`, mirroring [`Self::min`]'s tie-break-
/// left convention across the (min, max) axis), returns
/// `other` otherwise. The direction-complement arm of
/// [`Self::min`] on the (min, max) axis of the declaration-order
/// binary pairwise-selection surface.
///
/// Sibling posture to [`Self::min`] one arm over on the (min,
/// max) partition — [`Self::min`] returns the declaration-order
/// earlier variant via [`Self::precedes_or_equal`], this method
/// returns the declaration-order later variant via
/// [`Self::succeeds_or_equal`]. See [`Self::min`] for the
/// shared design rationale, sibling matrix, bracket / membership
/// / idempotence / tie-break contracts, the cross-primitive
/// composition into [`Self::clamp`], the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the direction-complement arm of the same
/// binary pairwise-selection surface and inherits every property
/// from the min arm's documentation, differing only in the
/// projection method the tie-break-left selection routes
/// through.
///
/// Bracket contract: `max(a, b).succeeds_or_equal(a)` AND
/// `max(a, b).succeeds_or_equal(b)` on every pair — the max
/// projection is an UPPER BOUND of the two operands under
/// non-strict declaration-order succession.
///
/// Direction-complement contract:
/// `a.max(b).index_of() >= a.min(b).index_of()` on every pair —
/// the max projection sits at OR after the min projection under
/// the declaration-order index. When `a != b` the two are
/// distinct (max returns the later, min returns the earlier);
/// when `a == b` they collapse onto the shared diagonal. Pinned
/// by `min_and_max_bracket_every_pair_on_the_declaration_axis`.
///
/// Default body composes [`Self::succeeds_or_equal`] with the
/// tie-break-left variant selection — `if
/// self.succeeds_or_equal(other) { self } else { other }`.
/// Implementors override only when the declaration-axis binary
/// max projection needs to diverge from the natural non-strict-
/// succession-guarded selection.
fn max(self, other: Self) -> Self {
if <Self as ClosedSet>::succeeds_or_equal(self, other) {
self
} else {
other
}
}
/// The lex-order binary pairwise MIN projection — the lex-
/// earlier of `self` and `other` under [`Self::label`]'s
/// projection into ASCII lexicographic order. Returns `self`
/// when `self.sorted_precedes_or_equal(other)` (ties fold to
/// `self`), returns `other` otherwise. The lex-ordering peer of
/// [`Self::min`] on the (declaration, lex) ordering axis of the
/// binary pairwise-selection surface.
///
/// Sibling posture to [`Self::min`] one arm over on the
/// (declaration, lex) ordering axis — [`Self::min`] uses
/// [`Self::precedes_or_equal`] (declaration position), this
/// method uses [`Self::sorted_precedes_or_equal`] (lex position).
/// See [`Self::min`] for the shared bracket / membership /
/// idempotence / tie-break contracts, the cross-primitive
/// composition into [`Self::sorted_clamp`], the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis arm of the same binary pairwise-
/// selection surface and inherits every property from the
/// declaration arm's documentation, differing only in the
/// projection method the tie-break-left selection routes
/// through.
///
/// Cross-primitive composition contract: `sorted_clamp(v, lo,
/// hi) == sorted_max(lo, sorted_min(v, hi))` on every well-
/// formed lex-triple `(v, lo, hi)` with
/// `lo.sorted_precedes_or_equal(hi)` — the lex-axis peer of the
/// declaration-axis `clamp = max ∘ min` factoring one ordering
/// arm over.
///
/// Cross-ordering coincidence: `sorted_min(a, b) == min(a, b)`
/// on every pair `(a, b)` for which declaration and lex orders
/// agree on both `a` and `b` — the two orderings collapse when
/// the declaration order IS the lex order on the pair. Pinned by
/// `sorted_min_coincides_with_min_when_declaration_and_lex_orders_agree`.
///
/// Default body composes [`Self::sorted_precedes_or_equal`] with
/// the tie-break-left variant selection.
fn sorted_min(self, other: Self) -> Self {
if <Self as ClosedSet>::sorted_precedes_or_equal(self, other) {
self
} else {
other
}
}
/// The lex-order binary pairwise MAX projection — the lex-
/// later of `self` and `other` under [`Self::label`]'s
/// projection into ASCII lexicographic order. Returns `self`
/// when `self.sorted_succeeds_or_equal(other)` (ties fold to
/// `self`), returns `other` otherwise. Closes the (ordering ×
/// direction) 2×2 = 4-corner binary pairwise-selection matrix on
/// the closed-set surface at the (lex-order, max) corner —
/// sibling posture to [`Self::sorted_min`] one direction axis
/// over on the lex arm AND to [`Self::max`] one ordering axis
/// over on the max arm.
///
/// Together with [`Self::min`], [`Self::max`], and
/// [`Self::sorted_min`], CLOSES the (ordering × direction) 2×2 =
/// 4-corner binary pairwise-selection matrix at the Self-return
/// arm on the closed-set surface — every combination of
/// {declaration, lex} ordering × {min, max} direction binds
/// through ONE typed pairwise-selection projection on the
/// trait, each routing through the substrate's non-strict
/// pairwise-comparison primitive at ONE composition site. The
/// (return-shape) axis of this face carries the pairwise-
/// selection at the Self-return column; a future extension of
/// the same axis lifts the (label-return, index-return)
/// columns as `min_label` / `max_label` / `sorted_min_label` /
/// `sorted_max_label` (the label-return face) and
/// `min_index` / `max_index` / `sorted_min_index` /
/// `sorted_max_index` (the index-return face), mirroring the
/// (return-shape) closure pattern the clamp face closed one
/// arity level up.
///
/// See [`Self::min`] for the shared design rationale, bracket /
/// membership / idempotence / tie-break contracts, the cross-
/// primitive composition into [`Self::sorted_clamp`] via the
/// `sorted_clamp = sorted_max ∘ sorted_min` factoring, the
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-order arm of the max
/// direction column and inherits every property from the min
/// arm's documentation, differing only in the projection method
/// the tie-break-left selection routes through.
///
/// Default body composes [`Self::sorted_succeeds_or_equal`]
/// with the tie-break-left variant selection.
fn sorted_max(self, other: Self) -> Self {
if <Self as ClosedSet>::sorted_succeeds_or_equal(self, other) {
self
} else {
other
}
}
/// The canonical `&'static str` LABEL of the declaration-order
/// binary pairwise-MIN projection of `self` and `other` — the
/// label of [`Self::min`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`]: the
/// binary min projection is TOTAL on every operand pair, and
/// every variant carries a canonical label.
///
/// The label-return arm of the (`Self`-return, `&'static str`-return,
/// `usize`-return) return-shape partition of the closed-set
/// declaration-order binary pairwise-MIN surface — one return-shape
/// axis over from [`Self::min`] (`Self`-return declaration-axis
/// binary-min), one direction axis over from [`Self::max_label`]
/// (`&'static str`-return declaration-axis binary-max-label), and
/// one ordering axis over from [`Self::sorted_min_label`]
/// (`&'static str`-return lex-axis binary-min-label). Together
/// with the three sibling label-return pairwise-selection peers
/// this method opens the label-return column on the binary-arity
/// face at the (`&'static str`-return, ordering × direction)
/// 2×2 = 4-corner selection matrix past the pre-existing Self-return
/// 2×2 row (95)+(96) — mirroring the (return-shape × ordering)
/// column pattern the ternary-CLAMP-label lifts closed one arity
/// axis over at (93)+(94) on the ternary-arity face.
///
/// Every generic consumer that renders the pairwise-MIN
/// projection's LABEL of two typed variants (an LSP quick-info
/// hover that folds an observed-phase pair to the earlier
/// lifecycle stage and emits "earlier phase: <label>" without
/// threading the `Self`-return variant through a separate
/// `label` fold, a diagnostic renderer that projects an unordered
/// phase-observation pair to the declaration-order earlier
/// member and threads the projected label into the
/// `earlier: <label>` shape, a metrics tagger that folds two
/// competing enum tags to their declaration-order earlier peer
/// and emits the folded label as the tag) binds to ONE typed
/// method rather than re-deriving the `a.min(b).label()`
/// two-primitive composition at every callsite.
///
/// Default body composes [`Self::min`] with [`Self::label`]
/// verbatim. The min-projection LABEL contract — the
/// tie-break-left arm returns `self.label()` when
/// `self.precedes_or_equal(other)`, returns `other.label()`
/// otherwise — is guaranteed by the default composition through
/// [`Self::min`]'s non-strict-precedence-guarded selection.
/// `T::first().min_label(T::first()) == T::first().label()` is
/// the natural fixpoint the binary-min-label projection shares
/// with the declaration-head label, mirroring the
/// `T::first().clamp_label(T::first(), T::first()) ==
/// T::first().label()` fixpoint one arity level up on the
/// ternary-clamp-label face.
///
/// Frontier inspiration: Racket's `(symbol-name (enum-min a b))`
/// — the label-projection sibling of `enum-min` on a closed
/// enumeration under the non-strict-precedence-guarded selection
/// variant of the ordering; MLIR's
/// `RegisteredOperationName::min(a, b).getName()` folded to ONE
/// method on the closed Op registry's binary min projection;
/// Julia's `Base.min(a, b) |> string` applied to a closed
/// enumeration and threaded through the canonical name
/// projection; Idris's `Ord a => min a b |> toLabel` on the
/// binary-min projection's label return-shape column. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::min`] + [`Self::label`] surfaces
/// verbatim — no new dep, no new IR layer, no supertrait bound,
/// no `Option`-typed dispatch, no allocation, no `strum` /
/// `enum-iterator` crate dependency.
fn min_label(self, other: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::min(self, other))
}
/// The canonical `&'static str` LABEL of the declaration-order
/// binary pairwise-MAX projection of `self` and `other` — the
/// label of [`Self::max`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`].
///
/// The direction-complement peer of [`Self::min_label`] on the
/// (min, max) direction axis of the closed-set label-return
/// binary pairwise-selection surface. See [`Self::min_label`]
/// for the shared design rationale, sibling matrix, override
/// axis, future-consumer inventory, THEORY.md grounding, and
/// frontier inspiration — this method is the max-direction arm
/// of the same label-return binary-selection surface and
/// inherits every property from the min arm's documentation,
/// differing only in the substrate primitive the label-fallback
/// routes through ([`Self::max`] rather than [`Self::min`]) and
/// the non-strict-succession guard it composes at the
/// tie-break-left selection ([`Self::succeeds_or_equal`] rather
/// than [`Self::precedes_or_equal`]).
///
/// `T::first().max_label(T::first()) == T::first().label()` is
/// the natural fixpoint the binary-max-label projection shares
/// with the singleton-pair diagonal, mirroring the
/// `T::first().min_label(T::first()) == T::first().label()`
/// fixpoint on the min arm one direction column over.
fn max_label(self, other: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::max(self, other))
}
/// The canonical `&'static str` LABEL of the lex-order binary
/// pairwise-MIN projection of `self` and `other` — the label of
/// [`Self::sorted_min`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`].
///
/// The lex-ordering peer of [`Self::min_label`] on the
/// (declaration, lex) ordering axis of the closed-set label-return
/// binary pairwise-MIN surface. See [`Self::min_label`] for the
/// shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// label-return binary-min surface and inherits every property
/// from the declaration arm's documentation, differing only in
/// the substrate primitive the label-fallback routes through
/// ([`Self::sorted_min`] rather than [`Self::min`]) and the
/// lex-ordering non-strict-precedence guard it composes at the
/// tie-break-left selection ([`Self::sorted_precedes_or_equal`]
/// rather than [`Self::precedes_or_equal`]).
///
/// `T::sorted_first().sorted_min_label(T::sorted_first()) ==
/// T::sorted_first().label()` is the natural fixpoint the
/// lex-order binary-min-label projection shares with the lex-head
/// label, mirroring the `T::first().min_label(T::first()) ==
/// T::first().label()` fixpoint on the declaration arm one
/// ordering column over.
fn sorted_min_label(self, other: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_min(self, other))
}
/// The canonical `&'static str` LABEL of the lex-order binary
/// pairwise-MAX projection of `self` and `other` — the label of
/// [`Self::sorted_max`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`].
///
/// Closes the (return-shape × ordering × direction) 2×2×2 =
/// 8-corner label-return + Self-return binary pairwise-selection
/// hypercube on the binary-arity face at the (`&'static str`-return,
/// lex-order, max) corner — sibling posture to
/// [`Self::sorted_min_label`] one direction axis over on the lex
/// arm AND to [`Self::max_label`] one ordering axis over on the
/// max arm. Together with [`Self::min_label`], [`Self::max_label`],
/// and [`Self::sorted_min_label`] this method CLOSES the
/// (`&'static str`-return, ordering × direction) 2×2 = 4-corner
/// label-return face on the binary pairwise-selection surface
/// past the pre-existing Self-return 2×2 row that
/// [`Self::min`] / [`Self::max`] / [`Self::sorted_min`] /
/// [`Self::sorted_max`] closed at (95)+(96) — the (return-shape ×
/// ordering × direction) hypercube on the binary-arity face
/// carries every corner filled at the intersection of the
/// (`Self`, `&'static str`) return-shape pair and the
/// {declaration, lex} ordering × {min, max} direction 2×2
/// selection matrix, mirroring the (return-shape × ordering) 3×2 =
/// 6-corner CLAMP face closed one arity level up on the
/// ternary-arity face at (92)+(93)+(94).
///
/// See [`Self::min_label`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the lex-order arm of the max direction column on the
/// label-return surface and inherits every property from the
/// declaration arm's documentation, differing only in the
/// substrate primitive the label-fallback routes through
/// ([`Self::sorted_max`] rather than [`Self::max`]) and the
/// lex-ordering non-strict-succession guard it composes at the
/// tie-break-left selection ([`Self::sorted_succeeds_or_equal`]
/// rather than [`Self::succeeds_or_equal`]).
///
/// `T::sorted_first().sorted_max_label(T::sorted_first()) ==
/// T::sorted_first().label()` is the natural fixpoint the
/// lex-order binary-max-label projection shares with the
/// singleton-lex-pair diagonal, mirroring the
/// `T::first().max_label(T::first()) == T::first().label()`
/// fixpoint on the declaration arm one ordering column over.
fn sorted_max_label(self, other: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_max(self, other))
}
/// The `usize` DECLARATION-ORDER INDEX of the declaration-order
/// binary pairwise-MIN projection of `self` and `other` — the
/// declaration-order position of [`Self::min`] projected through
/// [`Self::index_of`]. Returns `usize`, never [`Option<usize>`]:
/// the binary min projection is TOTAL on every operand pair, and
/// every variant carries a declaration-order slot.
///
/// The index-return arm of the (`Self`-return, `&'static str`-return,
/// `usize`-return) return-shape partition of the closed-set
/// declaration-order binary pairwise-MIN surface — one return-shape
/// axis over from [`Self::min`] (`Self`-return declaration-axis
/// binary-min), one return-shape axis over from [`Self::min_label`]
/// (`&'static str`-return declaration-axis binary-min-label), and
/// one ordering axis over from [`Self::sorted_min_index`] (`usize`-
/// return lex-axis binary-min-index). Together with the three
/// sibling index-return pairwise-selection peers this method CLOSES
/// the (return-shape × ordering × direction) 3×2×2 = 12-corner
/// binary pairwise-selection hypercube on the binary-arity face
/// past the pre-existing Self-return 2×2 = 4-corner row that
/// (95)+(96) closed AND the label-return 2×2 = 4-corner row that
/// (97)+(98) closed — the {`Self`, label, index} return-shape trio
/// now carries every corner filled at the intersection with the
/// {declaration, lex} ordering × {min, max} direction 4-corner
/// selection matrix on the binary-arity face, mirroring the
/// (return-shape × ordering) 3×2 = 6-corner CLAMP face closed one
/// arity level up on the ternary-arity face at (92)+(93)+(94).
///
/// Every generic consumer that renders the pairwise-MIN
/// projection's SLOT of two typed variants (a compact wire codec
/// that folds an observed-phase pair to the declaration-order
/// earlier member and emits the folded slot for cross-boundary
/// handoff without threading `Option`-dispatch through the encoder,
/// a per-variant lookup-table indexer that folds an unordered
/// phase-observation pair to the declaration-order earlier peer
/// and reads the folded slot into a `[Payload; T::CARDINALITY]`
/// array, a bitset over the closed-set that folds pairwise-min
/// samples into a monitored window and reads the folded slot as
/// the bit index) binds to ONE typed method rather than re-deriving
/// the `a.min(b).index_of()` two-primitive composition at every
/// callsite.
///
/// Default body composes [`Self::min`] with [`Self::index_of`]
/// verbatim. The min-projection INDEX contract — the tie-break-
/// left arm returns `self.index_of()` when
/// `self.precedes_or_equal(other)`, returns `other.index_of()`
/// otherwise — is guaranteed by the default composition through
/// [`Self::min`]'s non-strict-precedence-guarded selection.
/// `T::first().min_index(T::first()) == 0` is the natural fixpoint
/// the binary-min-index projection shares with the declaration-
/// head slot, mirroring the `T::first().min_label(T::first()) ==
/// T::first().label()` fixpoint one return-shape axis over on
/// the label-return surface AND the `T::first().min(T::first())
/// == T::first()` fixpoint one return-shape axis over on the
/// variant-return surface.
///
/// Frontier inspiration: Racket's `(enum-index (enum-min a b))` —
/// the index-projection sibling of `enum-min` on a closed
/// enumeration under the non-strict-precedence-guarded selection
/// variant of the ordering; MLIR's
/// `RegisteredOperationName::min(a, b).getIndex()` folded to ONE
/// method on the closed Op registry's binary min projection;
/// Julia's `Base.min(a, b) |> Int` applied to a closed enumeration
/// and threaded through the canonical slot projection; Idris's
/// `Ord a => min a b |> toIndex` on the binary-min projection's
/// index return-shape column. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::min`] + [`Self::index_of`] surfaces verbatim —
/// no new dep, no new IR layer, no supertrait bound, no `Option`-
/// typed dispatch, no allocation, no `strum` / `enum-iterator`
/// crate dependency.
fn min_index(self, other: Self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::min(self, other))
}
/// The `usize` DECLARATION-ORDER INDEX of the declaration-order
/// binary pairwise-MAX projection of `self` and `other` — the
/// declaration-order position of [`Self::max`] projected through
/// [`Self::index_of`]. Returns `usize`, never [`Option<usize>`].
///
/// The direction-complement peer of [`Self::min_index`] on the
/// (min, max) direction axis of the closed-set index-return binary
/// pairwise-selection surface. See [`Self::min_index`] for the
/// shared design rationale, sibling matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the max-direction arm of the same
/// index-return binary-selection surface and inherits every
/// property from the min arm's documentation, differing only in
/// the substrate primitive the index-fallback routes through
/// ([`Self::max`] rather than [`Self::min`]) and the non-strict-
/// succession guard it composes at the tie-break-left selection
/// ([`Self::succeeds_or_equal`] rather than
/// [`Self::precedes_or_equal`]).
///
/// `T::first().max_index(T::first()) == 0` is the natural fixpoint
/// the binary-max-index projection shares with the singleton-pair
/// diagonal, mirroring the `T::first().min_index(T::first()) == 0`
/// fixpoint on the min arm one direction column over.
fn max_index(self, other: Self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::max(self, other))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the lex-order binary
/// pairwise-MIN projection of `self` and `other` — the lex position
/// of [`Self::sorted_min`] projected through
/// [`Self::sorted_index_of`]. Returns `usize`, never
/// [`Option<usize>`].
///
/// The lex-ordering peer of [`Self::min_index`] on the
/// (declaration, lex) ordering axis of the closed-set index-return
/// binary pairwise-MIN surface. See [`Self::min_index`] for the
/// shared design rationale, sibling matrix, override axis, future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// index-return binary-min surface and inherits every property
/// from the declaration arm's documentation, differing only in
/// the substrate primitive the index-fallback routes through
/// ([`Self::sorted_min`] rather than [`Self::min`]) and the
/// lex-ordering slot lookup it composes at the projection
/// ([`Self::sorted_index_of`] rather than [`Self::index_of`]).
///
/// `T::sorted_first().sorted_min_index(T::sorted_first()) == 0` is
/// the natural fixpoint the lex-order binary-min-index projection
/// shares with the lex-head slot, mirroring the
/// `T::first().min_index(T::first()) == 0` fixpoint on the
/// declaration arm one ordering column over AND the
/// `T::sorted_first().sorted_clamp_index(T::sorted_first(),
/// T::sorted_first()) == 0` fixpoint one arity level up on the
/// ternary-clamp-index face.
fn sorted_min_index(self, other: Self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::sorted_min(self, other))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the lex-order binary
/// pairwise-MAX projection of `self` and `other` — the lex position
/// of [`Self::sorted_max`] projected through
/// [`Self::sorted_index_of`]. Returns `usize`, never
/// [`Option<usize>`].
///
/// Closes the (return-shape × ordering × direction) 3×2×2 =
/// 12-corner binary pairwise-selection hypercube on the binary-
/// arity face at the (`usize`-return, lex-order, max) corner —
/// sibling posture to [`Self::sorted_min_index`] one direction
/// axis over on the lex arm AND to [`Self::max_index`] one
/// ordering axis over on the max arm. Together with
/// [`Self::min_index`], [`Self::max_index`], and
/// [`Self::sorted_min_index`] this method CLOSES the (`usize`-
/// return, ordering × direction) 2×2 = 4-corner index-return face
/// on the binary pairwise-selection surface past the pre-existing
/// Self-return 2×2 row that [`Self::min`] / [`Self::max`] /
/// [`Self::sorted_min`] / [`Self::sorted_max`] closed at
/// (95)+(96) AND the label-return 2×2 row that [`Self::min_label`]
/// / [`Self::max_label`] / [`Self::sorted_min_label`] /
/// [`Self::sorted_max_label`] closed at (97)+(98) — the
/// (return-shape × ordering × direction) 3×2×2 hypercube on the
/// binary-arity face carries every corner filled at the
/// intersection of the (`Self`, `&'static str`, `usize`) return-
/// shape trio and the {declaration, lex} ordering × {min, max}
/// direction 2×2 selection matrix, EXHAUSTIVELY closing the
/// binary-arity index-return face after the (return-shape ×
/// ordering) 3×2 = 6-corner CLAMP face was closed one arity level
/// up on the ternary-arity face at (92)+(93)+(94).
///
/// See [`Self::min_index`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the lex-order arm of the max direction column on the index-
/// return surface and inherits every property from the declaration
/// arm's documentation, differing only in the substrate primitive
/// the index-fallback routes through ([`Self::sorted_max`] rather
/// than [`Self::max`]) and the lex-ordering slot lookup it composes
/// at the projection ([`Self::sorted_index_of`] rather than
/// [`Self::index_of`]).
///
/// `T::sorted_first().sorted_max_index(T::sorted_first()) == 0` is
/// the natural fixpoint the lex-order binary-max-index projection
/// shares with the singleton-lex-pair diagonal, mirroring the
/// `T::first().max_index(T::first()) == 0` fixpoint on the
/// declaration arm one ordering column over AND the
/// `T::sorted_first().sorted_max_label(T::sorted_first()) ==
/// T::sorted_first().label()` fixpoint one return-shape axis over
/// on the label-return surface.
fn sorted_max_index(self, other: Self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::sorted_max(self, other))
}
/// The declaration-order N-ARY MIN projection — the earliest
/// variant of `items` under [`Self::ALL`]'s declaration order, or
/// [`None`] when `items` is empty. Folds [`Self::min`] over
/// `items` from left via [`Iterator::reduce`]: the singleton case
/// returns `Some(items[0])`, the k-length case returns
/// `Some(items.iter().copied().reduce(min).unwrap())`. The
/// arity-N opener on the closed-set surface past the exhaustively-
/// closed 12-corner binary pairwise-SELECTION hypercube (95)+(96)+
/// (97)+(98)+(99)+(100) — opens the arity axis one step further
/// from binary pairwise-selection to N-ary variadic reduction over
/// a slice.
///
/// Sibling posture to the binary pairwise-selection hypercube's
/// 12 corners one arity level down: the pairwise-selection
/// projections answer "which of TWO variants is earlier?"; this
/// method answers "which of N variants is earliest?" over a slice.
/// The declaration-axis composition binds through the substrate's
/// non-strict-precedence-guarded binary min primitive folded left
/// via [`Iterator::reduce`] — so the N-ary min emerges as a typed
/// CONSEQUENCE of the binary min primitive through the standard-
/// library `reduce` fold rather than a fresh substrate primitive
/// on the index axis. Not a new pairwise-comparison primitive —
/// the composition emerges from the just-closed 4-corner binary
/// Self-return selection matrix through the standard-library
/// `reduce` fold on `Iterator`.
///
/// Empty-slice contract: `T::min_of(&[]) == None` — the empty
/// slice has no earliest member, and the [`Option`]-typed return
/// carries the empty-fixpoint witness without allocating a
/// diagnostic carrier. Pinned by
/// `min_of_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::min_of(&[v]) == Some(v)` on every
/// variant `v` — a singleton slice reduces to its sole member
/// through the [`Iterator::reduce`] identity on 1-length inputs.
/// Pinned by
/// `min_of_returns_the_sole_member_on_every_singleton_slice_across_every_variant`.
///
/// Binary agreement contract: `T::min_of(&[a, b]) == Some(a.min(b))`
/// on every operand pair — the arity-2 reduction folds through the
/// substrate's binary min primitive, so the arity-N surface is
/// pointwise consistent with the arity-2 surface at the length-2
/// slice. Pinned by
/// `min_of_agrees_with_binary_min_on_every_length_two_slice_across_every_pair`.
///
/// Fold-left contract: `T::min_of(&[a, b, c]) ==
/// Some(a.min(b).min(c))` on every operand triple — the ternary
/// reduction folds through the substrate's binary min primitive
/// twice from the left. Pinned by
/// `min_of_agrees_with_left_fold_of_binary_min_on_every_triple`.
///
/// Full-set contract: `T::min_of(<T as ClosedSet>::ALL) ==
/// Some(T::first())` — the N-ary min over the entire closed set
/// folds to the declaration-head variant, the canonical fixpoint
/// the min projection shares with [`Self::first`] one arity axis
/// up. Pinned by
/// `min_of_over_the_full_set_projects_to_the_declaration_head_across_every_kind`.
///
/// Permutation-invariance contract: `T::min_of(items) ==
/// T::min_of(&permuted)` on every permutation of `items` — the
/// N-ary min is invariant under reordering of its input slice
/// because binary min is commutative on distinct pairs AND
/// idempotent on equal pairs, and both properties propagate
/// through the [`Iterator::reduce`] fold. Pinned by
/// `min_of_is_invariant_under_permutation_of_the_input_slice_across_every_triple`.
///
/// Future consumers that compose against [`Self::min_of`]: a
/// diagnostic renderer that folds an observed-phase MULTIset to
/// the declaration-order earliest lifecycle stage (as opposed to
/// the arity-2 renderer one arity down that folds a PAIR of
/// observations to their earlier peer); a `tatara-check`
/// predicate `(check-min-observed-phase items)` verifying a
/// workspace-wide lifecycle-observation constraint across an
/// arbitrary sample; a metrics tagger that folds a rolling window
/// of enum observations to the declaration-order earliest peer
/// and emits the folded tag as the window's min-membership label;
/// a WASI executor that folds a batch of admission-observed
/// phases from N concurrent controllers to the earliest lifecycle
/// stage and gates SIGHUP admission on the folded min. Every such
/// consumer binds to ONE typed method rather than re-deriving the
/// `items.iter().copied().reduce(T::min)` composition at every
/// callsite.
///
/// Default body composes [`Iterator::copied`] +
/// [`Iterator::reduce`] with [`Self::min`] verbatim: `items.iter()
/// .copied().reduce(<Self as ClosedSet>::min)`. Implementors
/// override only when the N-ary min projection needs to diverge
/// from the natural `reduce`-fold over the pre-existing binary
/// min primitive (no production implementor reaches for this
/// today; the axis exists for the same reason `via` / `set_label`
/// / `labels` / `precedes` / `clamp` / `min` overrides exist — a
/// typed escape hatch rather than forcing the implementor to
/// hand-roll the impl).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary min
/// projection becomes a TYPE-level primitive on the closed-set
/// trait rather than a per-consumer inline `items.iter().copied()
/// .reduce(T::min)` composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the N-ary min axis was an
/// unnamed inline composition (`.copied().reduce(min)`) that
/// would recur at every prospective downstream slice-reduction
/// site pre-lift. Naming it on the trait makes the projection a
/// TYPED CONSEQUENCE of the binary min primitive folded through
/// the standard-library `Iterator::reduce` at ONE composition
/// site. THEORY.md §VI.1 — generation over composition; the N-ary
/// min projection emerges from the composition of ONE substrate
/// primitive ([`Self::min`]) with the standard-library
/// [`Iterator::reduce`] rather than as a per-implementor hand-
/// rolled body. A future tightening of the underlying binary min
/// primitive (a perfect-hash index lookup, a const-fn axis making
/// the projection callable in const contexts) propagates to every
/// closed-set N-ary min consumer through this method's body.
///
/// Frontier inspiration: Rust's [`Iterator::min`] folds an
/// arbitrary iterator to its minimum under any [`Ord`] bound; the
/// substrate mirrors the same N-ary min projection on the closed-
/// set surface without requiring the [`Ord`] supertrait bound the
/// trait's typed pairwise-precedence primitives make redundant.
/// Common Lisp's `(apply #'min items)` and Racket's `(apply min
/// items)` surface the same variadic reduction on numeric types
/// via the language's apply idiom; Julia's `minimum(items)` on
/// any iterable of ordered types. MLIR's `llvm.intr.vector.reduce
/// .smin(vector<Nxi32>)` folds a vector to its signed-min through
/// a typed op on the closed operand-vector shape. Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::min`] surface with the standard-
/// library [`Iterator::copied`] + [`Iterator::reduce`] fold — no
/// new dep, no new IR layer, no supertrait bound (the pairwise-
/// precedence primitive replaces the `Ord` bound), no `apply`
/// idiom, no vector-shape carrier.
fn min_of(items: &[Self]) -> Option<Self> {
items.iter().copied().reduce(<Self as ClosedSet>::min)
}
/// The declaration-order N-ARY MAX projection — the latest
/// variant of `items` under [`Self::ALL`]'s declaration order, or
/// [`None`] when `items` is empty. Folds [`Self::max`] over
/// `items` from left via [`Iterator::reduce`].
///
/// The direction-complement peer of [`Self::min_of`] on the
/// (min, max) direction axis of the closed-set N-ary variadic
/// reduction surface. See [`Self::min_of`] for the shared design
/// rationale, empty-slice / singleton / binary-agreement / fold-
/// left / permutation-invariance contracts, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the max-direction arm of the same N-ary
/// variadic reduction surface and inherits every property from
/// the min arm's documentation, differing only in the substrate
/// primitive the `reduce` fold routes through ([`Self::max`]
/// rather than [`Self::min`]).
///
/// Full-set contract: `T::max_of(<T as ClosedSet>::ALL) ==
/// Some(T::last())` — the N-ary max over the entire closed set
/// folds to the declaration-tail variant, the canonical fixpoint
/// the max projection shares with [`Self::last`] one arity axis
/// up, mirroring the `T::min_of(<T as ClosedSet>::ALL) ==
/// Some(T::first())` fixpoint on the min arm one direction column
/// over.
///
/// Bracket contract: `T::min_of(items).index_of() <=
/// T::max_of(items).index_of()` on every non-empty slice — the
/// N-ary min sits at OR before the N-ary max under the
/// declaration-order index, mirroring the arity-2 bracket
/// contract one arity level down.
fn max_of(items: &[Self]) -> Option<Self> {
items.iter().copied().reduce(<Self as ClosedSet>::max)
}
/// The lex-order N-ARY MIN projection — the lex-earliest variant
/// of `items` under [`Self::label`]'s projection into ASCII
/// lexicographic order, or [`None`] when `items` is empty. Folds
/// [`Self::sorted_min`] over `items` from left via
/// [`Iterator::reduce`].
///
/// The lex-ordering peer of [`Self::min_of`] on the
/// (declaration, lex) ordering axis of the closed-set N-ary
/// variadic reduction surface. See [`Self::min_of`] for the
/// shared design rationale, empty-slice / singleton / binary-
/// agreement / fold-left / permutation-invariance contracts, the
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// N-ary variadic reduction surface and inherits every property
/// from the declaration arm's documentation, differing only in
/// the substrate primitive the `reduce` fold routes through
/// ([`Self::sorted_min`] rather than [`Self::min`]).
///
/// Full-set contract: `T::sorted_min_of(<T as ClosedSet>::ALL) ==
/// Some(T::sorted_first())` — the lex-order N-ary min over the
/// entire closed set folds to the lex-head variant.
///
/// Cross-ordering coincidence: `T::sorted_min_of(items) ==
/// T::min_of(items)` on every slice for which declaration and
/// lex orders agree pairwise — the two orderings collapse when
/// the declaration order IS the lex order on every operand in
/// the slice.
fn sorted_min_of(items: &[Self]) -> Option<Self> {
items
.iter()
.copied()
.reduce(<Self as ClosedSet>::sorted_min)
}
/// The lex-order N-ARY MAX projection — the lex-latest variant of
/// `items` under [`Self::label`]'s projection into ASCII
/// lexicographic order, or [`None`] when `items` is empty. Folds
/// [`Self::sorted_max`] over `items` from left via
/// [`Iterator::reduce`].
///
/// Closes the (ordering × direction) 2×2 = 4-corner N-ary
/// variadic-reduction Self-return matrix on the closed-set
/// surface at the (lex-order, max) corner — sibling posture to
/// [`Self::sorted_min_of`] one direction axis over on the lex arm
/// AND to [`Self::max_of`] one ordering axis over on the max arm.
/// Together with [`Self::min_of`], [`Self::max_of`], and
/// [`Self::sorted_min_of`] this method CLOSES the (ordering ×
/// direction) 2×2 = 4-corner Self-return N-ary variadic-reduction
/// matrix on the N-ary arity face past the exhaustively-closed
/// 12-corner (return-shape × ordering × direction) 3×2×2 binary
/// pairwise-SELECTION hypercube one arity level down — the arity
/// axis carries a Self-return N-ary opener at every combination
/// of {declaration, lex} ordering × {min, max} direction, with
/// the (label-return, index-return) return-shape columns as
/// future extensions mirroring the binary-arity face's
/// (return-shape × ordering × direction) 3×2×2 hypercube shape.
///
/// See [`Self::min_of`] for the shared design rationale, empty-
/// slice / singleton / binary-agreement / fold-left / permutation-
/// invariance contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// order arm of the max direction column on the N-ary variadic
/// reduction surface and inherits every property from the
/// declaration arm's documentation, differing only in the
/// substrate primitive the `reduce` fold routes through
/// ([`Self::sorted_max`] rather than [`Self::max`]).
///
/// Full-set contract: `T::sorted_max_of(<T as ClosedSet>::ALL) ==
/// Some(T::sorted_last())` — the lex-order N-ary max over the
/// entire closed set folds to the lex-tail variant.
fn sorted_max_of(items: &[Self]) -> Option<Self> {
items
.iter()
.copied()
.reduce(<Self as ClosedSet>::sorted_max)
}
/// The canonical `&'static str` LABEL of the declaration-order
/// N-ARY MIN projection of `items` — the label of [`Self::min_of`]
/// projected through [`Self::label`], or [`None`] when `items` is
/// empty. The label-return-shape peer of [`Self::min_of`] one
/// return-shape axis over on the N-ary variadic-reduction surface,
/// AND the N-ary-arity peer of [`Self::min_label`] one arity level
/// up. Opens the label-return column of the (return-shape × ordering
/// × direction) 3×2×2 = 12-corner N-ary variadic-reduction hypercube
/// past the exhaustively-closed 4-corner Self-return face
/// [`Self::min_of`] / [`Self::max_of`] / [`Self::sorted_min_of`] /
/// [`Self::sorted_max_of`] — the N-ary counterpart of the binary
/// pairwise-selection hypercube's own return-shape column
/// [`Self::min_label`] / [`Self::max_label`] /
/// [`Self::sorted_min_label`] / [`Self::sorted_max_label`] one
/// arity level down.
///
/// Empty-slice contract: `T::min_label_of(&[]) == None` — the empty
/// slice has no earliest member, so the label projection propagates
/// the empty-fixpoint witness through [`Option::map`] without
/// allocating a diagnostic carrier, mirroring the Self-return arm's
/// `T::min_of(&[]) == None` one return-shape column over. Pinned
/// by `min_label_of_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::min_label_of(&[v]) == Some(v.label())`
/// on every variant `v` — a singleton slice reduces to its sole
/// member's label through [`Iterator::reduce`]'s 1-length identity
/// composed with [`Self::label`]. Pinned by
/// `min_label_of_returns_the_sole_member_label_on_every_singleton_slice_across_every_variant`.
///
/// Self-return composition contract: `T::min_label_of(items) ==
/// T::min_of(items).map(T::label)` on every slice — the label-return
/// arm composes through the Self-return arm plus the trait's `label`
/// projection, not through a fresh substrate primitive on the
/// N-ary axis. Pinned by
/// `min_label_of_composes_min_of_with_label_across_every_triple`.
///
/// Full-set contract: `T::min_label_of(<T as ClosedSet>::ALL) ==
/// Some(T::first().label())` — the N-ary min-label over the entire
/// closed set folds to the declaration-head variant's label,
/// mirroring the Self-return arm's `T::min_of(ALL) ==
/// Some(T::first())` one return-shape column over.
///
/// Permutation-invariance contract: `T::min_label_of(items) ==
/// T::min_label_of(&permuted)` on every permutation of `items` —
/// the N-ary min-label is invariant under reordering of its input
/// slice because [`Self::min_of`] is, and the `label` map preserves
/// the invariance verbatim.
///
/// Future consumers that compose against [`Self::min_label_of`]: a
/// diagnostic renderer that folds an observed-phase MULTIset to the
/// declaration-order earliest lifecycle stage's CANONICAL LABEL
/// (rather than the typed variant one return-shape column over);
/// a `tatara-check` predicate that renders the earliest-observed
/// phase across an arbitrary sample as an `&'static str` for
/// human-readable audit-trail output; a metrics tagger that folds
/// a rolling window of enum observations to the declaration-order
/// earliest peer's LABEL and emits the folded string as the
/// window's min-membership tag — bypassing the intermediate
/// `Option<Self>` unwrap-and-project chain. Every such consumer
/// binds to ONE typed method rather than re-deriving the
/// `items.iter().copied().reduce(T::min).map(T::label)` composition
/// at every callsite.
///
/// Default body composes [`Self::min_of`] with [`Option::map`]
/// threading [`Self::label`] verbatim: `Self::min_of(items)
/// .map(Self::label)`. Implementors override only when the label-
/// return N-ary min projection needs to diverge from the natural
/// Self-return composition through the pre-existing label
/// projection (no production implementor reaches for this today).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary min-
/// label projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline `.reduce(T::min)
/// .map(T::label)` composition. THEORY.md §V.1 — knowable platform;
/// the N-ary label-return axis was an unnamed inline composition
/// pre-lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of TWO substrate primitives ([`Self::min_of`] +
/// [`Self::label`]) composed through [`Option::map`] at ONE
/// composition site. THEORY.md §VI.1 — generation over composition;
/// the N-ary min-label projection emerges from the composition of
/// TWO substrate primitives rather than a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: Racket's `(symbol->string (apply min
/// items))` composed with the language's apply idiom on a closed
/// symbolic union; Julia's `String(minimum(items))` on an ordered
/// enumeration; MLIR's `RegisteredOperationName::min_of(vector)
/// .getName()` folded to ONE method on the closed Op registry's
/// N-ary min projection. Translation through pleme-io primitives:
/// a pure default method composing the trait's existing
/// [`Self::min_of`] + [`Self::label`] surfaces through
/// [`Option::map`] verbatim — no new dep, no `apply` idiom, no
/// `String`-return allocating carrier.
fn min_label_of(items: &[Self]) -> Option<&'static str> {
<Self as ClosedSet>::min_of(items).map(<Self as ClosedSet>::label)
}
/// The canonical `&'static str` LABEL of the declaration-order
/// N-ARY MAX projection of `items` — the label of [`Self::max_of`]
/// projected through [`Self::label`], or [`None`] when `items` is
/// empty.
///
/// The direction-complement peer of [`Self::min_label_of`] on the
/// (min, max) direction axis of the closed-set label-return N-ary
/// variadic-reduction surface. See [`Self::min_label_of`] for the
/// shared design rationale, empty-slice / singleton / composition /
/// full-set / permutation-invariance contracts, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the max-direction arm of the same label-return N-ary
/// surface and inherits every property from the min arm's
/// documentation, differing only in the substrate primitive the
/// N-ary fold routes through ([`Self::max_of`] rather than
/// [`Self::min_of`]).
///
/// Full-set contract: `T::max_label_of(<T as ClosedSet>::ALL) ==
/// Some(T::last().label())` — the N-ary max-label over the entire
/// closed set folds to the declaration-tail variant's label,
/// mirroring the `T::min_label_of(ALL) == Some(T::first().label())`
/// fixpoint on the min arm one direction column over.
fn max_label_of(items: &[Self]) -> Option<&'static str> {
<Self as ClosedSet>::max_of(items).map(<Self as ClosedSet>::label)
}
/// The canonical `&'static str` LABEL of the lex-order N-ARY MIN
/// projection of `items` — the label of [`Self::sorted_min_of`]
/// projected through [`Self::label`], or [`None`] when `items` is
/// empty.
///
/// The lex-ordering peer of [`Self::min_label_of`] on the
/// (declaration, lex) ordering axis of the closed-set label-return
/// N-ary variadic-reduction surface. See [`Self::min_label_of`] for
/// the shared design rationale, contracts, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the lex-axis arm of the same label-return N-ary
/// surface and inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitive the
/// N-ary fold routes through ([`Self::sorted_min_of`] rather than
/// [`Self::min_of`]).
///
/// Full-set contract: `T::sorted_min_label_of(<T as ClosedSet>::ALL)
/// == Some(T::sorted_first().label())` — the lex-order N-ary min-
/// label over the entire closed set folds to the lex-head variant's
/// label.
///
/// Cross-ordering coincidence: `T::sorted_min_label_of(items) ==
/// T::min_label_of(items)` on every slice for which declaration and
/// lex orders agree pairwise — the two orderings collapse when the
/// declaration order IS the lex order on every operand.
fn sorted_min_label_of(items: &[Self]) -> Option<&'static str> {
<Self as ClosedSet>::sorted_min_of(items).map(<Self as ClosedSet>::label)
}
/// The canonical `&'static str` LABEL of the lex-order N-ARY MAX
/// projection of `items` — the label of [`Self::sorted_max_of`]
/// projected through [`Self::label`], or [`None`] when `items` is
/// empty.
///
/// Closes the label-return column of the (return-shape × ordering ×
/// direction) 3×2×2 = 12-corner N-ary variadic-reduction hypercube
/// at the (label-return, lex-order, max) corner — sibling posture
/// to [`Self::sorted_min_label_of`] one direction axis over on the
/// lex arm AND to [`Self::max_label_of`] one ordering axis over on
/// the max arm. Together with [`Self::min_label_of`],
/// [`Self::max_label_of`], and [`Self::sorted_min_label_of`] this
/// method CLOSES the (ordering × direction) 2×2 = 4-corner label-
/// return N-ary variadic-reduction matrix past the pre-existing
/// Self-return 4-corner face ([`Self::min_of`], [`Self::max_of`],
/// [`Self::sorted_min_of`], [`Self::sorted_max_of`]) — the N-ary
/// arity face now carries an ALL of {declaration, lex} ordering ×
/// {min, max} direction × {Self, label} return-shape corners, with
/// the (index-return) return-shape column as the future extension
/// mirroring the binary-arity face's own 3×2×2 hypercube shape.
///
/// See [`Self::min_label_of`] for the shared design rationale, the
/// empty-slice / singleton / composition / full-set / permutation-
/// invariance contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// order arm of the max direction column on the label-return N-ary
/// surface and inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitive the
/// N-ary fold routes through ([`Self::sorted_max_of`] rather than
/// [`Self::max_of`]).
///
/// Full-set contract: `T::sorted_max_label_of(<T as ClosedSet>::ALL)
/// == Some(T::sorted_last().label())` — the lex-order N-ary max-
/// label over the entire closed set folds to the lex-tail variant's
/// label.
fn sorted_max_label_of(items: &[Self]) -> Option<&'static str> {
<Self as ClosedSet>::sorted_max_of(items).map(<Self as ClosedSet>::label)
}
/// The `usize` DECLARATION-ORDER INDEX of the declaration-order
/// N-ARY MIN projection of `items` — the declaration-order position
/// of [`Self::min_of`] projected through [`Self::index_of`], or
/// [`None`] when `items` is empty. The index-return-shape peer of
/// [`Self::min_of`] one return-shape axis over on the N-ary
/// variadic-reduction surface, AND the N-ary-arity peer of
/// [`Self::min_index`] one arity level up. Opens the index-return
/// column of the (return-shape × ordering × direction) 3×2×2 =
/// 12-corner N-ary variadic-reduction hypercube past the pre-
/// existing Self-return 4-corner face [`Self::min_of`] /
/// [`Self::max_of`] / [`Self::sorted_min_of`] / [`Self::sorted_max_of`]
/// AND the label-return 4-corner face [`Self::min_label_of`] /
/// [`Self::max_label_of`] / [`Self::sorted_min_label_of`] /
/// [`Self::sorted_max_label_of`] — the N-ary counterpart of the
/// binary pairwise-selection hypercube's own index-return column
/// [`Self::min_index`] / [`Self::max_index`] /
/// [`Self::sorted_min_index`] / [`Self::sorted_max_index`] one arity
/// level down.
///
/// Empty-slice contract: `T::min_index_of(&[]) == None` — the empty
/// slice has no earliest member, so the index projection propagates
/// the empty-fixpoint witness through [`Option::map`] without
/// allocating a diagnostic carrier, mirroring the Self-return arm's
/// `T::min_of(&[]) == None` one return-shape column over AND the
/// label-return arm's `T::min_label_of(&[]) == None` one return-
/// shape column over. Pinned by
/// `min_index_of_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::min_index_of(&[v]) == Some(v.index_of())`
/// on every variant `v` — a singleton slice reduces to its sole
/// member's declaration-order position through [`Iterator::reduce`]'s
/// 1-length identity composed with [`Self::index_of`]. Pinned by
/// `min_index_of_returns_the_sole_member_index_on_every_singleton_slice_across_every_variant`.
///
/// Self-return composition contract: `T::min_index_of(items) ==
/// T::min_of(items).map(T::index_of)` on every slice — the index-
/// return arm composes through the Self-return arm plus the trait's
/// `index_of` projection, not through a fresh substrate primitive
/// on the N-ary axis. Pinned by
/// `min_index_of_composes_min_of_with_index_of_across_every_triple`.
///
/// Full-set contract: `T::min_index_of(<T as ClosedSet>::ALL) ==
/// Some(0)` — the N-ary min-index over the entire closed set folds
/// to the declaration-head slot's index, mirroring the Self-return
/// arm's `T::min_of(ALL) == Some(T::first())` one return-shape
/// column over AND the label-return arm's `T::min_label_of(ALL) ==
/// Some(T::first().label())` one return-shape column over.
///
/// Permutation-invariance contract: `T::min_index_of(items) ==
/// T::min_index_of(&permuted)` on every permutation of `items` —
/// the N-ary min-index is invariant under reordering of its input
/// slice because [`Self::min_of`] is, and the `index_of` map
/// preserves the invariance verbatim.
///
/// Binary-agreement contract: `T::min_index_of(&[a, b]) ==
/// Some(a.min_index(b))` on every operand pair — the arity-2 slice
/// on the N-ary index-return arm equals the arity-2 index-return
/// arm [`Self::min_index`] one arity level down, closing the
/// (arity × return-shape) 2×2 corner between the binary and N-ary
/// faces on the index-return column.
///
/// Future consumers that compose against [`Self::min_index_of`]: a
/// diagnostic renderer that folds an observed-phase MULTIset to the
/// declaration-order earliest lifecycle stage's CANONICAL SLOT
/// (rather than the typed variant one return-shape column over or
/// the label two return-shape columns over); a `tatara-check`
/// predicate that renders the earliest-observed phase across an
/// arbitrary sample as a `usize` for numeric audit-trail output
/// (index-tagged offsets are dense-packable in fixed-width metric
/// buffers where variant tags need padded discriminants and labels
/// need pointer-wide `&'static str` slots); a metrics tagger that
/// folds a rolling window of enum observations to the declaration-
/// order earliest peer's INDEX and emits the folded index as the
/// window's min-membership numeric tag — bypassing the intermediate
/// `Option<Self>` unwrap-and-project chain. Every such consumer
/// binds to ONE typed method rather than re-deriving the
/// `items.iter().copied().reduce(T::min).map(T::index_of)`
/// composition at every callsite.
///
/// Default body composes [`Self::min_of`] with [`Option::map`]
/// threading [`Self::index_of`] verbatim: `Self::min_of(items)
/// .map(Self::index_of)`. Implementors override only when the
/// index-return N-ary min projection needs to diverge from the
/// natural Self-return composition through the pre-existing index
/// projection (no production implementor reaches for this today).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary min-
/// index projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline `.reduce(T::min)
/// .map(T::index_of)` composition. THEORY.md §V.1 — knowable
/// platform; the N-ary index-return axis was an unnamed inline
/// composition pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of TWO substrate primitives
/// ([`Self::min_of`] + [`Self::index_of`]) composed through
/// [`Option::map`] at ONE composition site. THEORY.md §VI.1 —
/// generation over composition; the N-ary min-index projection
/// emerges from the composition of TWO substrate primitives rather
/// than a per-implementor hand-rolled body. A future tightening of
/// the underlying Self-return `min_of` (a perfect-hash reduction, a
/// const-fn body making the projection callable in const contexts,
/// a SIMD-vectorised fold on `[Self; N]` fixed-size input)
/// propagates to every closed-set N-ary index consumer through ONE
/// composition site.
///
/// Frontier inspiration: Racket's `(enum-index (apply enum-min
/// items))` composed with the language's apply idiom on a closed
/// symbolic union; Julia's `Int(minimum(items))` on an ordered
/// enumeration cast to its slot index; MLIR's
/// `RegisteredOperationName::min_of(vector).getIndex()` folded to
/// ONE method on the closed Op registry's N-ary min projection.
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::min_of`] +
/// [`Self::index_of`] surfaces through [`Option::map`] verbatim —
/// no new dep, no `apply` idiom, no `Int`-cast carrier.
fn min_index_of(items: &[Self]) -> Option<usize> {
<Self as ClosedSet>::min_of(items).map(<Self as ClosedSet>::index_of)
}
/// The `usize` DECLARATION-ORDER INDEX of the declaration-order
/// N-ARY MAX projection of `items` — the declaration-order position
/// of [`Self::max_of`] projected through [`Self::index_of`], or
/// [`None`] when `items` is empty.
///
/// The direction-complement peer of [`Self::min_index_of`] on the
/// (min, max) direction axis of the closed-set index-return N-ary
/// variadic-reduction surface. See [`Self::min_index_of`] for the
/// shared design rationale, empty-slice / singleton / composition /
/// full-set / permutation-invariance / binary-agreement contracts,
/// the future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the max-direction arm of the same
/// index-return N-ary surface and inherits every property from the
/// min arm's documentation, differing only in the substrate
/// primitive the N-ary fold routes through ([`Self::max_of`] rather
/// than [`Self::min_of`]).
///
/// Full-set contract: `T::max_index_of(<T as ClosedSet>::ALL) ==
/// Some(<T as ClosedSet>::ALL.len() - 1)` — the N-ary max-index
/// over the entire closed set folds to the declaration-tail slot's
/// index, mirroring the `T::min_index_of(ALL) == Some(0)` fixpoint
/// on the min arm one direction column over.
fn max_index_of(items: &[Self]) -> Option<usize> {
<Self as ClosedSet>::max_of(items).map(<Self as ClosedSet>::index_of)
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the lex-order N-ARY MIN
/// projection of `items` — the lex position of
/// [`Self::sorted_min_of`] projected through
/// [`Self::sorted_index_of`], or [`None`] when `items` is empty.
///
/// The lex-ordering peer of [`Self::min_index_of`] on the
/// (declaration, lex) ordering axis of the closed-set index-return
/// N-ary variadic-reduction surface. See [`Self::min_index_of`] for
/// the shared design rationale, contracts, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the lex-axis arm of the same index-return N-ary
/// surface and inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitive the
/// N-ary fold routes through ([`Self::sorted_min_of`] rather than
/// [`Self::min_of`]) and the lex-ordering slot lookup it composes
/// at the projection ([`Self::sorted_index_of`] rather than
/// [`Self::index_of`]).
///
/// Full-set contract: `T::sorted_min_index_of(<T as ClosedSet>::ALL)
/// == Some(0)` — the lex-order N-ary min-index over the entire
/// closed set folds to the lex-head slot's index.
///
/// Cross-ordering coincidence: `T::sorted_min_index_of(items) ==
/// T::min_index_of(items)` on every slice for which declaration
/// and lex orders agree pairwise — the two orderings collapse when
/// the declaration order IS the lex order on every operand.
fn sorted_min_index_of(items: &[Self]) -> Option<usize> {
<Self as ClosedSet>::sorted_min_of(items).map(<Self as ClosedSet>::sorted_index_of)
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the lex-order N-ARY MAX
/// projection of `items` — the lex position of
/// [`Self::sorted_max_of`] projected through
/// [`Self::sorted_index_of`], or [`None`] when `items` is empty.
///
/// Closes the (return-shape × ordering × direction) 3×2×2 =
/// 12-corner N-ary variadic-reduction hypercube on the N-ary arity
/// face at the (`usize`-return, lex-order, max) corner —
/// EXHAUSTIVELY closing the N-ary arity face after the Self-return
/// 4-corner (ordering × direction) 2×2 matrix ([`Self::min_of`] /
/// [`Self::max_of`] / [`Self::sorted_min_of`] /
/// [`Self::sorted_max_of`]) AND the label-return 4-corner
/// (ordering × direction) 2×2 matrix ([`Self::min_label_of`] /
/// [`Self::max_label_of`] / [`Self::sorted_min_label_of`] /
/// [`Self::sorted_max_label_of`]). Sibling posture to
/// [`Self::sorted_min_index_of`] one direction axis over on the lex
/// arm AND to [`Self::max_index_of`] one ordering axis over on the
/// max arm. Together with [`Self::min_index_of`],
/// [`Self::max_index_of`], and [`Self::sorted_min_index_of`] this
/// method CLOSES the (ordering × direction) 2×2 = 4-corner index-
/// return N-ary variadic-reduction matrix — the N-ary arity face
/// now MATCHES the binary-arity face's own 3×2×2 hypercube shape at
/// every corner of the (`Self`, `&'static str`, `usize`) return-
/// shape trio and the {declaration, lex} ordering × {min, max}
/// direction 2×2 selection matrix, the arity axis carrying the same
/// exhaustive 12-corner closure the binary axis carries one arity
/// level down.
///
/// See [`Self::min_index_of`] for the shared design rationale, the
/// empty-slice / singleton / composition / full-set / permutation-
/// invariance / binary-agreement contracts, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the lex-order arm of the max direction column on the
/// index-return N-ary surface and inherits every property from the
/// declaration arm's documentation, differing only in the substrate
/// primitive the N-ary fold routes through ([`Self::sorted_max_of`]
/// rather than [`Self::max_of`]) and the lex-ordering slot lookup
/// it composes at the projection ([`Self::sorted_index_of`] rather
/// than [`Self::index_of`]).
///
/// Full-set contract: `T::sorted_max_index_of(<T as ClosedSet>::ALL)
/// == Some(<T as ClosedSet>::ALL.len() - 1)` — the lex-order N-ary
/// max-index over the entire closed set folds to the lex-tail
/// slot's index. With the N-ary index-return face exhaustively
/// closed, the closed-set surface now carries a UNIFORM 12-corner
/// (return-shape × ordering × direction) 3×2×2 hypercube at BOTH
/// the binary-arity face AND the N-ary-arity face — every
/// projection under {Self, `&'static str`, `usize`} return-shape ×
/// {declaration, lex} ordering × {min, max} direction has a typed
/// method on the trait at BOTH arities, and no future N-ary
/// selection consumer at either arity needs to re-derive the
/// projection inline. The next extension on the arity axis carries
/// the same 12-corner shape one arity level up (ternary
/// closed-range selection over `[lo, hi]` under the {min, max}
/// direction axis + a {Self, label, index} return-shape trio),
/// mirroring the ternary CLAMP face's own 6-corner (return-shape ×
/// ordering) closure at (92)+(93)+(94).
fn sorted_max_index_of(items: &[Self]) -> Option<usize> {
<Self as ClosedSet>::sorted_max_of(items).map(<Self as ClosedSet>::sorted_index_of)
}
/// The declaration-order N-ARY NON-STRICT ASCENDING monotonicity
/// predicate — `true` iff every consecutive pair `(items[i],
/// items[i+1])` satisfies `items[i].precedes_or_equal(items[i+1])`
/// under [`Self::ALL`]'s declaration order, `false` on the first
/// consecutive pair that violates non-strict precedence. Folds
/// [`Self::precedes_or_equal`] over `items.windows(2)` via
/// [`Iterator::all`] — vacuously `true` on the empty slice AND on
/// every singleton slice (no adjacent pairs), threading the (0 &&
/// 1)-length identity of [`Iterator::all`] on `windows(2)` through
/// [`bool`]'s conjunctive fold.
///
/// The bool-return N-ARY MONOTONICITY opener on the closed-set
/// surface past the exhaustively-closed 8-corner (ordering ×
/// direction × strictness) 2×2×2 pairwise-comparison hypercube
/// (78)+(79)+(80)+(81) at the arity-2 face — opens the N-ary-arity
/// axis of the pairwise-comparison hypercube one arity level up
/// from the (`self`, `other`) binary-pair face to the
/// (`items: &[Self]`) N-ary-slice face. Sibling posture to the
/// N-ary variadic-reduction hypercube's own arity-N opening at
/// (101)+(102)+(103)+(104) one return-shape column over on the
/// Self-return face — where the reduction surface answers "which
/// variant of `items` is earliest / latest?", the monotonicity
/// surface answers "is `items` non-strict ascending / descending
/// throughout?".
///
/// The declaration-axis composition binds through the substrate's
/// non-strict pairwise-precedence primitive folded through
/// [`Iterator::all`] on the adjacent-pair window — so the N-ary
/// monotonicity predicate emerges as a typed CONSEQUENCE of the
/// arity-2 non-strict-precedence primitive through the standard-
/// library `all` fold on `slice::windows(2)`, not a fresh substrate
/// primitive on the index axis and not an inline hand-rolled
/// `zip(iter, iter.skip(1)).all(…)` composition at every consumer.
///
/// Empty-slice contract: `T::is_ascending(&[])` is `true` — the
/// vacuous fold on an empty adjacent-pair window returns `true`
/// through [`Iterator::all`]'s empty-fold identity, mirroring
/// [`slice::is_sorted`]'s empty-slice contract on the standard
/// library. Pinned by
/// `is_ascending_returns_true_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::is_ascending(&[v])` is `true` on every
/// variant `v` — a singleton slice has NO adjacent pairs, so the
/// `windows(2)` iterator yields zero windows and the `all` fold
/// returns `true` vacuously. Pinned by
/// `is_ascending_returns_true_on_every_singleton_slice_across_every_variant`.
///
/// Binary agreement contract: `T::is_ascending(&[a, b]) ==
/// a.precedes_or_equal(b)` on every operand pair — the arity-2
/// window folds through the substrate's binary non-strict-
/// precedence primitive, so the arity-N monotonicity surface is
/// pointwise consistent with the arity-2 pairwise-comparison
/// surface at the length-2 slice. Pinned by
/// `is_ascending_agrees_with_binary_precedes_or_equal_on_every_length_two_slice_across_every_pair`.
///
/// Full-set contract: `T::is_ascending(<T as ClosedSet>::ALL)` is
/// `true` — the entire closed set is by construction non-strictly
/// ascending under its own declaration order (every consecutive
/// pair `(ALL[i], ALL[i+1])` satisfies
/// `ALL[i].precedes_or_equal(ALL[i+1])` because `index_of(ALL[i])
/// == i < i + 1 == index_of(ALL[i+1])`), the canonical fixpoint
/// the ascending monotonicity predicate shares with the
/// declaration order itself. Pinned by
/// `is_ascending_over_the_full_set_holds`.
///
/// Direction-reversal contract: `T::is_ascending(items) ==
/// T::is_descending(reversed items)` on every slice — the
/// non-strict-ascending predicate on a slice binds byte-for-byte
/// to the non-strict-descending predicate on its reversal because
/// the (forward, backward) direction axis on the arity-2
/// pairwise-comparison face composes with the slice-reversal
/// permutation on the N-ary-arity face. Pinned by
/// `is_ascending_of_slice_agrees_with_is_descending_of_reversed_slice_across_every_triple`.
///
/// Future consumers that compose against [`Self::is_ascending`]:
/// a `tatara-check` predicate `(check-phases-monotone …)` verifying
/// a workspace-wide phase-transition constraint where a sequence
/// of phase names must be non-strictly ascending under the
/// substrate's `WorkloadPhase` declaration order (e.g.
/// `WorkloadPhase::is_ascending(&[Warming, Executing,
/// Contracting])` at plan time); an LSP diagnostic that verifies
/// a Lisp author-written sequence of severity levels is non-
/// strictly ascending under `Severity::ALL`'s declaration order;
/// a Sekiban audit-trail metric verifying that every observed
/// convergence-distance trajectory (a slice of
/// `ConvergenceDistance` samples) is non-strictly ascending
/// through convergence; the substrate's own `BoundaryPhase`
/// lifecycle projected via
/// `BoundaryPhase::is_ascending(&recorded_phases)` at attestation
/// time — bind to ONE typed N-ary monotonicity predicate rather
/// than re-deriving `pairs.all(|(a, b)| a.precedes_or_equal(b))`
/// inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// monotonicity predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `windows(2).all(…)` composition at every downstream generic
/// site. THEORY.md §V.1 — knowable platform; the N-ary-arity
/// monotonicity axis was an unnamed inline composition
/// (`items.windows(2).all(|w| w[0].precedes_or_equal(w[1]))`)
/// recurring at every prospective downstream monotonicity-check
/// site pre-lift. Naming it on the trait makes the predicate a
/// TYPED CONSEQUENCE of the non-strict pairwise-precedence
/// predicate applied across every adjacent operand window.
/// THEORY.md §VI.1 — generation over composition; the N-ary
/// monotonicity predicate emerges from the composition of TWO
/// substrate primitives ([`Self::precedes_or_equal`] at every
/// adjacent pair + the standard-library [`Iterator::all`] on
/// [`slice::windows`]) rather than as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Rust's own
/// [`slice::is_sorted`](https://doc.rust-lang.org/std/primitive.slice.html#method.is_sorted)
/// exposes the same non-strict-ascending predicate on any slice
/// whose element type carries [`PartialOrd`]; Common Lisp's
/// `(every #'<= items (rest items))` composes the same pairwise-
/// window fold via the language's `every` idiom; Julia's
/// `issorted(v; lt=<=)` on any iterable of ordered elements.
/// Racket's `(apply <= items)` folds the ordering primitive
/// variadically over the operand list. MLIR's `isSorted(vector)`
/// verification pass surfaces the same predicate on typed
/// vector operands. Translation through pleme-io primitives: the
/// N-ary monotonicity predicate on the closed-set trait binds
/// through [`Self::precedes_or_equal`]'s non-strict pairwise-
/// precedence composition folded over [`slice::windows(2)`] via
/// [`Iterator::all`] — no new dep, no supertrait bound (the
/// pairwise-precedence primitive replaces the [`PartialOrd`]
/// bound), no vector-shape carrier.
fn is_ascending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::precedes_or_equal(w[0], w[1]))
}
/// The declaration-order N-ARY NON-STRICT DESCENDING monotonicity
/// predicate — `true` iff every consecutive pair `(items[i],
/// items[i+1])` satisfies `items[i].succeeds_or_equal(items[i+1])`
/// under [`Self::ALL`]'s declaration order, `false` on the first
/// consecutive pair that violates non-strict succession. The
/// direction-complement arm of [`Self::is_ascending`] on the
/// (forward, backward) axis of the N-ary monotonicity surface.
///
/// See [`Self::is_ascending`] for the shared design rationale,
/// empty-slice / singleton / binary-agreement / full-set /
/// direction-reversal contracts, the future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the reverse-direction arm of the same N-ary monotonicity
/// surface and inherits every property from the forward arm's
/// documentation, differing only in the substrate primitive the
/// `windows(2).all(…)` fold routes through
/// ([`Self::succeeds_or_equal`] rather than
/// [`Self::precedes_or_equal`]).
///
/// Full-set contract: `T::is_descending(<T as ClosedSet>::ALL)` is
/// `true` iff `ALL.len() <= 1` — the entire closed set is
/// non-strictly descending only when the closed set has zero or
/// one variants (in which case the `windows(2)` fold is
/// vacuously `true`); on any closed set with two or more
/// variants, the very first adjacent pair `(ALL[0], ALL[1])`
/// satisfies `ALL[0].precedes(ALL[1])` (strict declaration
/// precedence), so `ALL[0].succeeds_or_equal(ALL[1])` is `false`
/// and the fold short-circuits. Pinned by
/// `is_descending_over_the_full_set_holds_iff_cardinality_is_zero_or_one`.
fn is_descending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::succeeds_or_equal(w[0], w[1]))
}
/// The lex-order N-ARY NON-STRICT ASCENDING monotonicity predicate
/// — `true` iff every consecutive pair `(items[i], items[i+1])`
/// satisfies `items[i].sorted_precedes_or_equal(items[i+1])` under
/// [`Self::label`]'s projection into ASCII lexicographic order,
/// `false` on the first consecutive pair that violates non-strict
/// lex-precedence. The lex-ordering peer of [`Self::is_ascending`]
/// on the (declaration, lex) ordering axis of the N-ary
/// monotonicity surface.
///
/// See [`Self::is_ascending`] for the shared design rationale,
/// empty-slice / singleton / binary-agreement / full-set /
/// direction-reversal contracts, the future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the lex-axis arm of the same N-ary monotonicity surface and
/// inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitive the
/// `windows(2).all(…)` fold routes through
/// ([`Self::sorted_precedes_or_equal`] rather than
/// [`Self::precedes_or_equal`]).
///
/// Cross-ordering coincidence: `T::is_sorted_ascending(items) ==
/// T::is_ascending(items)` on every slice for which declaration
/// and lex orders coincide pairwise — the two orderings collapse
/// on every adjacent pair, so the `windows(2).all(…)` folds bind
/// byte-for-byte. Pinned by
/// `is_sorted_ascending_and_is_sorted_descending_coincide_with_the_declaration_peers_when_orders_agree`.
fn is_sorted_ascending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::sorted_precedes_or_equal(w[0], w[1]))
}
/// The lex-order N-ARY NON-STRICT DESCENDING monotonicity predicate
/// — `true` iff every consecutive pair `(items[i], items[i+1])`
/// satisfies `items[i].sorted_succeeds_or_equal(items[i+1])` under
/// [`Self::label`]'s projection into ASCII lexicographic order,
/// `false` on the first consecutive pair that violates non-strict
/// lex-succession. Closes the (ordering × direction) 2×2 =
/// 4-corner N-ary non-strict monotonicity matrix on the closed-set
/// surface at the (lex-order, descending) corner past the three
/// prior corners at (declaration, ascending) / (declaration,
/// descending) / (lex, ascending).
///
/// Sibling posture to [`Self::is_sorted_ascending`] one direction
/// axis over on the lex arm AND to [`Self::is_descending`] one
/// ordering axis over on the descending arm — the lex-order
/// non-strict-descending predicate is the intersection of both
/// axis-complements over the declaration-axis non-strict-ascending
/// predicate. See [`Self::is_ascending`] for the shared design
/// rationale, empty-slice / singleton / binary-agreement /
/// full-set / direction-reversal contracts, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis reverse-direction arm of the same
/// N-ary monotonicity surface and inherits every property from
/// the three prior arms' documentation, differing only in the
/// substrate primitive the `windows(2).all(…)` fold routes
/// through ([`Self::sorted_succeeds_or_equal`] rather than
/// [`Self::precedes_or_equal`] / [`Self::succeeds_or_equal`] /
/// [`Self::sorted_precedes_or_equal`]).
///
/// (105) + (106) + (107) + (108) together CLOSE the (ordering ×
/// direction) 2×2 = 4-corner N-ary non-strict-monotonicity matrix
/// on the closed-set surface — every combination of
/// {declaration, lex} ordering × {ascending, descending}
/// direction binds through ONE typed N-ary bool-return predicate
/// on the trait, each routing through the substrate's typed
/// arity-2 non-strict pairwise-precedence primitive folded over
/// [`slice::windows(2)`] via [`Iterator::all`] at ONE composition
/// site. The strict-monotonicity (arity-N) 4-corner face and the
/// bool-return (arity-N) predicates over strict pairwise-
/// precedence remain as future extensions mirroring the arity-2
/// (ordering × direction × strictness) 2×2×2 = 8-corner hypercube
/// closure at (78)+(79)+(80)+(81).
fn is_sorted_descending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::sorted_succeeds_or_equal(w[0], w[1]))
}
/// The declaration-order N-ARY STRICT ASCENDING monotonicity
/// predicate — `true` iff every consecutive pair `(items[i],
/// items[i+1])` satisfies `items[i].precedes(items[i+1])` under
/// [`Self::ALL`]'s declaration order, `false` on the first
/// consecutive pair that violates strict precedence (including
/// any adjacent equal pair, by irreflexivity of the strict
/// pairwise-precedence primitive). The strictness-complement arm
/// of [`Self::is_ascending`] on the (strict, non-strict) axis of
/// the N-ary monotonicity surface.
///
/// See [`Self::is_ascending`] for the shared design rationale,
/// empty-slice / singleton / binary-agreement / full-set /
/// direction-reversal contracts, the future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method is
/// the strictness-complement arm of the same N-ary monotonicity
/// surface and inherits every property from the non-strict arm's
/// documentation, differing only in the substrate primitive the
/// `windows(2).all(…)` fold routes through ([`Self::precedes`]
/// rather than [`Self::precedes_or_equal`]).
///
/// Full-set contract: `T::is_strictly_ascending(<T as
/// ClosedSet>::ALL)` is `true` — the entire closed set is by
/// construction strictly ascending under its own declaration
/// order (every consecutive pair `(ALL[i], ALL[i+1])` satisfies
/// `ALL[i].precedes(ALL[i+1])` because `index_of(ALL[i]) == i <
/// i + 1 == index_of(ALL[i+1])`), the canonical fixpoint the
/// strict-ascending predicate shares with the declaration order
/// itself. Pinned by `is_strictly_ascending_over_the_full_set_holds`.
///
/// Constant-slice contract: `T::is_strictly_ascending(&[v, v])`
/// is `false` on every variant `v` — the irreflexivity axiom of
/// the strict pairwise-precedence primitive (`v.precedes(v) ==
/// false` for every `v`, since `index_of(v) < index_of(v)` is
/// `false`) forces the `windows(2)` fold to short-circuit on the
/// first adjacent equal pair, so any slice with at least two
/// consecutive equal elements is strictly non-monotonic on both
/// strictness-ascending and strictness-descending arms. Pinned by
/// `is_strictly_ascending_is_false_on_any_slice_with_adjacent_equal_elements`.
///
/// Strict-implies-non-strict contract:
/// `T::is_strictly_ascending(items) →
/// T::is_ascending(items)` on every slice — the strict pairwise-
/// precedence primitive `precedes` implies the non-strict
/// pairwise-precedence primitive `precedes_or_equal` at every
/// pair through `Self::index_of`'s composition with `usize`'s
/// `<` and `<=` (`i < j → i <= j`), so the conjunctive fold
/// through `Iterator::all` propagates the implication across
/// every adjacent-pair window. Pinned by
/// `is_strictly_ascending_implies_is_ascending_across_every_triple`.
fn is_strictly_ascending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::precedes(w[0], w[1]))
}
/// The declaration-order N-ARY STRICT DESCENDING monotonicity
/// predicate — `true` iff every consecutive pair `(items[i],
/// items[i+1])` satisfies `items[i].succeeds(items[i+1])` under
/// [`Self::ALL`]'s declaration order, `false` on the first
/// consecutive pair that violates strict succession (including
/// any adjacent equal pair). The direction-complement arm of
/// [`Self::is_strictly_ascending`] on the (forward, backward)
/// axis of the N-ary strict-monotonicity surface AND the
/// strictness-complement arm of [`Self::is_descending`] on the
/// (strict, non-strict) axis.
///
/// See [`Self::is_strictly_ascending`] for the shared design
/// rationale, empty-slice / singleton / binary-agreement / full-
/// set / direction-reversal / constant-slice / strict-implies-
/// non-strict contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the
/// reverse-direction arm of the same N-ary strict-monotonicity
/// surface and inherits every property from the forward arm's
/// documentation, differing only in the substrate primitive the
/// `windows(2).all(…)` fold routes through ([`Self::succeeds`]
/// rather than [`Self::precedes`]).
///
/// Full-set contract: `T::is_strictly_descending(<T as
/// ClosedSet>::ALL)` is `true` iff `ALL.len() <= 1` — the entire
/// closed set is strictly descending only when the closed set has
/// zero or one variants (in which case the `windows(2)` fold is
/// vacuously `true`); on any closed set with two or more
/// variants, the very first adjacent pair `(ALL[0], ALL[1])`
/// satisfies `ALL[0].precedes(ALL[1])`, so `ALL[0].succeeds(
/// ALL[1])` is `false` by asymmetry of the strict primitive and
/// the fold short-circuits. Pinned by
/// `is_strictly_descending_over_the_full_set_holds_iff_cardinality_is_zero_or_one`.
fn is_strictly_descending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::succeeds(w[0], w[1]))
}
/// The lex-order N-ARY STRICT ASCENDING monotonicity predicate —
/// `true` iff every consecutive pair `(items[i], items[i+1])`
/// satisfies `items[i].sorted_precedes(items[i+1])` under
/// [`Self::label`]'s projection into ASCII lexicographic order,
/// `false` on the first consecutive pair that violates strict
/// lex-precedence. The lex-ordering peer of
/// [`Self::is_strictly_ascending`] on the (declaration, lex)
/// ordering axis of the N-ary strict-monotonicity surface AND
/// the strictness-complement arm of [`Self::is_sorted_ascending`]
/// on the (strict, non-strict) axis.
///
/// See [`Self::is_strictly_ascending`] for the shared design
/// rationale, empty-slice / singleton / binary-agreement / full-
/// set / direction-reversal / constant-slice / strict-implies-
/// non-strict contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// axis arm of the same N-ary strict-monotonicity surface and
/// inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitive the
/// `windows(2).all(…)` fold routes through
/// ([`Self::sorted_precedes`] rather than [`Self::precedes`]).
///
/// Cross-ordering coincidence:
/// `T::is_sorted_strictly_ascending(items) ==
/// T::is_strictly_ascending(items)` on every slice for which
/// declaration and lex orders coincide pairwise — the two
/// orderings collapse on every adjacent pair, so the
/// `windows(2).all(…)` folds bind byte-for-byte. Pinned by
/// `is_sorted_strictly_ascending_and_is_sorted_strictly_descending_coincide_with_the_declaration_peers_when_orders_agree`.
fn is_sorted_strictly_ascending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::sorted_precedes(w[0], w[1]))
}
/// The lex-order N-ARY STRICT DESCENDING monotonicity predicate —
/// `true` iff every consecutive pair `(items[i], items[i+1])`
/// satisfies `items[i].sorted_succeeds(items[i+1])` under
/// [`Self::label`]'s projection into ASCII lexicographic order,
/// `false` on the first consecutive pair that violates strict
/// lex-succession. Closes the (ordering × direction × strictness)
/// 2×2×2 = 8-corner N-ary monotonicity hypercube on the closed-
/// set surface at the (lex-order, descending, strict) corner past
/// the seven prior corners at the four non-strict corners
/// (105)+(106)+(107)+(108) and the three prior strict corners
/// (declaration, ascending, strict), (declaration, descending,
/// strict), (lex, ascending, strict).
///
/// Sibling posture to [`Self::is_sorted_strictly_ascending`] one
/// direction axis over on the lex arm, [`Self::is_strictly_descending`]
/// one ordering axis over on the descending arm, AND
/// [`Self::is_sorted_descending`] one strictness axis over on the
/// lex-descending arm — the lex-order strict-descending predicate
/// is the intersection of all three axis-complements over the
/// declaration-axis non-strict-ascending predicate. See
/// [`Self::is_strictly_ascending`] for the shared design
/// rationale, empty-slice / singleton / binary-agreement / full-
/// set / direction-reversal / constant-slice / strict-implies-
/// non-strict contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// axis reverse-direction arm of the same N-ary strict-
/// monotonicity surface and inherits every property from the
/// three prior strict arms' documentation, differing only in the
/// substrate primitive the `windows(2).all(…)` fold routes
/// through ([`Self::sorted_succeeds`] rather than
/// [`Self::precedes`] / [`Self::succeeds`] /
/// [`Self::sorted_precedes`]).
///
/// (109) + (110) + (111) + (112) together CLOSE the (ordering ×
/// direction × strictness) 2×2×2 = 8-corner N-ary monotonicity
/// hypercube on the closed-set surface EXHAUSTIVELY past the four
/// non-strict corners (105)+(106)+(107)+(108) — every combination
/// of {declaration, lex} ordering × {ascending, descending}
/// direction × {strict, non-strict} strictness binds through ONE
/// typed N-ary bool-return predicate on the trait, each routing
/// through the substrate's typed arity-2 pairwise-precedence
/// primitive (strict or non-strict per the strictness axis)
/// folded over [`slice::windows(2)`] via [`Iterator::all`] at ONE
/// composition site. The arity-N monotonicity hypercube now
/// mirrors the exhaustively-closed 8-corner arity-2 (ordering ×
/// direction × strictness) pairwise-comparison hypercube
/// (74)+(75)+(76)+(77)+(78)+(79)+(80)+(81) at every dimension.
///
/// Anti-joint-strictness contract: on any slice with two or more
/// elements, `T::is_sorted_strictly_ascending(items) AND
/// T::is_sorted_strictly_descending(items)` is `false` — the
/// asymmetry axiom of the strict pairwise-precedence primitive
/// (`a.sorted_precedes(b) → NOT b.sorted_precedes(a)`) rules out
/// any adjacent pair from being simultaneously strictly ascending
/// AND strictly descending; on the empty slice OR a singleton the
/// joint conjunction is vacuously `true` on both arms. Pinned by
/// `is_strictly_ascending_and_is_strictly_descending_hold_jointly_iff_slice_has_zero_or_one_elements`.
fn is_sorted_strictly_descending(items: &[Self]) -> bool {
items
.windows(2)
.all(|w| <Self as ClosedSet>::sorted_succeeds(w[0], w[1]))
}
/// The declaration-order N-ARY NON-STRICT DIRECTION-COLLAPSED
/// monotonicity predicate — `true` iff `items` is EITHER non-
/// strictly ascending OR non-strictly descending under
/// [`Self::ALL`]'s declaration order, `false` when `items` fails
/// BOTH directions. The DIRECTION-COLLAPSED opener on the N-ary
/// monotonicity surface past the exhaustively-closed 8-corner
/// (arity-N × ordering × direction × strictness) 2×2×2 monotonicity
/// hypercube (105)+(106)+(107)+(108)+(109)+(110)+(111)+(112) — opens
/// the (direction-collapsed) axis one dimension over from the
/// direction-split predicates at the (declaration, non-strict)
/// corner.
///
/// Sibling posture to the direction-split arms
/// [`Self::is_ascending`] and [`Self::is_descending`] one direction-
/// collapse axis over: those two arms answer "is this slice non-
/// strictly ascending (respectively descending)?" over ONE direction;
/// this method answers "is this slice non-strictly monotone in
/// EITHER direction?" — the disjunction of both direction arms at
/// the same (ordering, strictness) corner. Composition through TWO
/// substrate primitives ([`Self::is_ascending`] +
/// [`Self::is_descending`] joined via the standard-library `||`
/// short-circuit on `bool`); not a fresh substrate primitive on the
/// index axis — the composition emerges from the just-closed
/// 8-corner N-ary monotonicity hypercube through disjunction of two
/// of its (declaration, non-strict) arms.
///
/// Empty-slice contract: `T::is_monotonic(&[])` is `true` — both
/// direction arms fold the empty slice to `true` (conjunctive
/// identity of `Iterator::all` on the zero-window `windows(2)`
/// fold), so the disjunction is `true` on the empty slice. Pinned by
/// `is_monotonic_returns_true_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::is_monotonic(&[v])` is `true` on every
/// variant `v` — both direction arms fold a length-1 slice to
/// `true` (no adjacent pairs → `all` returns `true` vacuously on
/// every arm), so the disjunction is `true` on every singleton.
/// Pinned by
/// `is_monotonic_returns_true_on_every_singleton_slice_across_every_variant`.
///
/// Direction-reversal invariance contract:
/// `T::is_monotonic(items) == T::is_monotonic(reversed items)` on
/// every slice — the (forward, backward) direction axis on the
/// direction-split face composes with the slice-reversal permutation
/// on the N-ary face, so reversing a monotone slice yields a
/// monotone slice on the opposite direction arm, and the
/// disjunction commutes with reversal. Direction-collapse projection
/// collapses the direction axis, so the reversal permutation
/// becomes a fixpoint on this arm. Pinned by
/// `is_monotonic_of_slice_agrees_with_is_monotonic_of_reversed_slice_across_every_triple`.
///
/// Constant-slice contract: `T::is_monotonic(&[v, v, …, v])` is
/// `true` on every constant slice of any length — both direction
/// arms are individually `true` on constant slices (through the
/// non-strict pairwise-precedence primitive's reflexivity), so the
/// disjunction is `true`. Pinned by
/// `is_monotonic_holds_on_every_constant_slice_across_every_variant`.
///
/// Full-set contract: `T::is_monotonic(<T as ClosedSet>::ALL)` is
/// `true` — the ascending arm is `true` over the full set by
/// construction, so the disjunction is `true`. Pinned by
/// `is_monotonic_over_the_full_set_holds`.
///
/// Future consumers that compose against [`Self::is_monotonic`]: a
/// `tatara-check` predicate `(check-phases-monotonic …)` verifying
/// a `WorkloadPhase` sequence is monotone in EITHER direction at
/// plan time (catching a spec whose phase sequence oscillates,
/// without pinning the direction the check ranges over); an LSP
/// diagnostic verifying a Lisp-author-written severity ladder is
/// monotonically ordered regardless of ascending vs descending
/// authoring convention; a Sekiban audit-trail metric verifying
/// that a convergence-distance trajectory is monotone across
/// convergence (either direction — the direction axis collapses
/// because a strictly-decreasing signal proves convergence and a
/// strictly-increasing signal proves divergence, and monotonicity
/// alone proves non-oscillation). Each binds to ONE typed direction-
/// collapsed N-ary monotonicity predicate on the trait rather than
/// re-deriving `T::is_ascending(items) || T::is_descending(items)`
/// inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the direction-
/// collapsed N-ary monotonicity predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::is_ascending(items) || T::is_descending(items)`
/// disjunction at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the direction-collapsed
/// axis was an unnamed inline composition
/// (`T::is_ascending(items) || T::is_descending(items)`) recurring
/// at every prospective downstream direction-agnostic monotonicity
/// site pre-lift. Naming it on the trait makes the predicate a
/// TYPED CONSEQUENCE of the direction-split arms disjoined through
/// the standard-library `||`.
/// THEORY.md §VI.1 — generation over composition; the direction-
/// collapsed predicate emerges from the composition of TWO
/// substrate primitives ([`Self::is_ascending`] +
/// [`Self::is_descending`] joined via the standard-library `||`
/// short-circuit) rather than as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Julia's `issorted(v)` predicate composed
/// with `issorted(reverse(v))` via `||` surfaces the same
/// direction-collapsed predicate on any iterable; NumPy's
/// `np.all(np.diff(a) >= 0) or np.all(np.diff(a) <= 0)` composes
/// the same disjunction on typed numeric arrays; Racket's
/// `(or (sorted? items <=) (sorted? items >=))` folds the same
/// disjunction variadically. Rust's `slice::is_sorted_by(|a, b|
/// order.compare(a, b))` on a "monotone" ordering that treats both
/// directions as sorted is the closest single-primitive peer.
/// MLIR's `isMonotonic` verification pass surfaces the same
/// predicate on typed vector operands. Translation through pleme-io
/// primitives: the direction-collapsed N-ary predicate on the
/// closed-set trait binds through the disjunction of the two
/// direction-split N-ary arms at the same (ordering, strictness)
/// corner — no new dep, no supertrait bound (the direction-split
/// arms replace the `Ord`+`PartialEq` bound the standard-library
/// signatures demand), no vector-shape carrier.
fn is_monotonic(items: &[Self]) -> bool {
<Self as ClosedSet>::is_ascending(items) || <Self as ClosedSet>::is_descending(items)
}
/// The declaration-order N-ARY STRICT DIRECTION-COLLAPSED
/// monotonicity predicate — `true` iff `items` is EITHER strictly
/// ascending OR strictly descending under [`Self::ALL`]'s
/// declaration order, `false` when `items` fails BOTH directions
/// (including any slice with two or more adjacent equal elements,
/// by irreflexivity of the strict pairwise-precedence primitive
/// on both direction arms). The strictness-complement arm of
/// [`Self::is_monotonic`] on the (strict, non-strict) axis of the
/// direction-collapsed N-ary monotonicity surface.
///
/// See [`Self::is_monotonic`] for the shared design rationale,
/// empty-slice / singleton / direction-reversal / full-set
/// contracts, the future-consumer inventory, THEORY.md grounding,
/// and frontier inspiration — this method is the strictness-
/// complement arm of the same direction-collapsed N-ary
/// monotonicity surface and inherits every property from the non-
/// strict arm's documentation, differing only in the substrate
/// primitives the disjunction routes through
/// ([`Self::is_strictly_ascending`] +
/// [`Self::is_strictly_descending`] rather than
/// [`Self::is_ascending`] + [`Self::is_descending`]).
///
/// Constant-slice contract: `T::is_strictly_monotonic(&[v, v])` is
/// `false` on every variant `v` — the irreflexivity axiom of the
/// strict pairwise-precedence primitive forces BOTH direction arms
/// to `false` on any slice with adjacent equal elements, so the
/// disjunction is `false`. Pinned by
/// `is_strictly_monotonic_is_false_on_any_slice_with_adjacent_equal_elements`.
///
/// Strict-implies-non-strict contract:
/// `T::is_strictly_monotonic(items) → T::is_monotonic(items)` on
/// every slice — each direction arm's strict variant implies its
/// non-strict variant (through the substrate's `usize` `<`/`<=`
/// implication), so the strict disjunction implies the non-strict
/// disjunction. Pinned by
/// `is_strictly_monotonic_implies_is_monotonic_across_every_triple`.
fn is_strictly_monotonic(items: &[Self]) -> bool {
<Self as ClosedSet>::is_strictly_ascending(items)
|| <Self as ClosedSet>::is_strictly_descending(items)
}
/// The lex-order N-ARY NON-STRICT DIRECTION-COLLAPSED monotonicity
/// predicate — `true` iff `items` is EITHER non-strictly lex-
/// ascending OR non-strictly lex-descending under [`Self::label`]'s
/// projection into ASCII lexicographic order, `false` when `items`
/// fails BOTH directions. The lex-ordering peer of
/// [`Self::is_monotonic`] on the (declaration, lex) ordering axis
/// of the direction-collapsed N-ary monotonicity surface.
///
/// See [`Self::is_monotonic`] for the shared design rationale,
/// empty-slice / singleton / direction-reversal / constant-slice /
/// full-set contracts, the future-consumer inventory, THEORY.md
/// grounding, and frontier inspiration — this method is the lex-
/// axis arm of the same direction-collapsed N-ary monotonicity
/// surface and inherits every property from the declaration arm's
/// documentation, differing only in the substrate primitives the
/// disjunction routes through ([`Self::is_sorted_ascending`] +
/// [`Self::is_sorted_descending`] rather than
/// [`Self::is_ascending`] + [`Self::is_descending`]).
///
/// Cross-ordering coincidence: `T::is_sorted_monotonic(items) ==
/// T::is_monotonic(items)` on every slice for which declaration
/// and lex orders coincide pairwise — both direction arms collapse
/// across the (declaration, lex) axis, so the disjunction
/// collapses too. Pinned by
/// `is_sorted_monotonic_and_is_sorted_strictly_monotonic_coincide_with_the_declaration_peers_when_orders_agree`.
fn is_sorted_monotonic(items: &[Self]) -> bool {
<Self as ClosedSet>::is_sorted_ascending(items)
|| <Self as ClosedSet>::is_sorted_descending(items)
}
/// The lex-order N-ARY STRICT DIRECTION-COLLAPSED monotonicity
/// predicate — `true` iff `items` is EITHER strictly lex-ascending
/// OR strictly lex-descending under [`Self::label`]'s projection
/// into ASCII lexicographic order, `false` when `items` fails BOTH
/// directions. Closes the (ordering × strictness) 2×2 = 4-corner
/// direction-collapsed N-ary monotonicity matrix on the closed-set
/// surface at the (lex-order, strict) corner past the three prior
/// corners at (declaration, non-strict) / (declaration, strict) /
/// (lex, non-strict).
///
/// Sibling posture to [`Self::is_sorted_monotonic`] one strictness
/// axis over on the lex arm, [`Self::is_strictly_monotonic`] one
/// ordering axis over on the strict arm, AND
/// [`Self::is_sorted_strictly_ascending`] one direction-collapse
/// axis over on the (lex, strict) arm — the lex-order strict
/// direction-collapsed predicate is the intersection of both axis-
/// complements over the declaration-axis non-strict direction-
/// collapsed predicate. See [`Self::is_monotonic`] for the shared
/// design rationale, empty-slice / singleton / direction-reversal /
/// constant-slice / full-set contracts, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis strictness-complement arm of the
/// same direction-collapsed N-ary monotonicity surface and
/// inherits every property from the three prior arms' documentation,
/// differing only in the substrate primitives the disjunction
/// routes through ([`Self::is_sorted_strictly_ascending`] +
/// [`Self::is_sorted_strictly_descending`] rather than the three
/// other pairs).
///
/// (113) + (114) + (115) + (116) together CLOSE the (ordering ×
/// strictness) 2×2 = 4-corner direction-collapsed N-ary
/// monotonicity matrix on the closed-set surface — every
/// combination of {declaration, lex} ordering × {strict, non-strict}
/// strictness binds through ONE typed direction-collapsed N-ary
/// bool-return predicate on the trait, each routing through the
/// substrate's typed direction-split N-ary arms disjoined via the
/// standard-library `||` at ONE composition site. The direction-
/// collapsed 4-corner matrix collapses the direction axis of the
/// exhaustively-closed 8-corner (arity-N × ordering × direction ×
/// strictness) monotonicity hypercube at (109)+(110)+(111)+(112),
/// partitioning the same (ordering × strictness) 4-corner face
/// through a direction-agnostic projection.
fn is_sorted_strictly_monotonic(items: &[Self]) -> bool {
<Self as ClosedSet>::is_sorted_strictly_ascending(items)
|| <Self as ClosedSet>::is_sorted_strictly_descending(items)
}
/// The N-ARY DIRECTION-JOINED "constant slice" predicate — `true` iff
/// `items` is BOTH non-strictly ascending AND non-strictly descending
/// under [`Self::ALL`]'s declaration order, `false` otherwise. Since
/// the substrate's declaration order is total, the joint condition
/// holds iff every adjacent pair is EQUAL, i.e. `items` is a
/// repetition of ONE variant (possibly zero-arity). The direction-
/// CONJUNCTION peer of [`Self::is_monotonic`]'s direction-DISJUNCTION
/// on the (∧, ∨) axis of the N-ary monotonicity face — while
/// [`Self::is_monotonic`] widens the direction-split arms through
/// `||` to accept EITHER ordering, this predicate NARROWS them
/// through `&&` to accept ONLY the constant intersection.
///
/// Ordering-axis invariance: `T::is_constant(items) ==
/// T::is_ascending(items) && T::is_descending(items) ==
/// T::is_sorted_ascending(items) && T::is_sorted_descending(items)`
/// — the constant-slice predicate is intrinsically ordering-
/// agnostic. Equality on the closed-set variants doesn't depend on
/// which order the substrate uses to compare them; a slice that is
/// simultaneously non-strictly ascending AND non-strictly descending
/// under ONE ordering is the same slice under EVERY ordering (all
/// elements equal). No separate `sorted_is_constant` peer is needed:
/// the (declaration, lex) axis COLLAPSES on this predicate by
/// construction, distinguishing it from every other N-ary
/// monotonicity predicate on the closed set (which needs both
/// declaration and lex arms because the two orderings differ pairwise
/// on non-constant slices). Pinned by
/// `is_constant_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::is_constant(&[])` is `true` on every
/// implementor — both direction arms are `true` on the empty slice
/// by vacuous quantification over adjacent pairs, so the conjunction
/// is `true`. Pinned by
/// `is_constant_returns_true_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::is_constant(&[v])` is `true` for every
/// variant `v` — both direction arms are `true` on every singleton
/// slice by vacuous quantification over adjacent pairs, so the
/// conjunction is `true`. Pinned by
/// `is_constant_returns_true_on_every_singleton_slice_across_every_variant`.
///
/// Repetition contract: `T::is_constant(&[v; N])` is `true` for every
/// variant `v` and every arity `N ≥ 0` — every adjacent pair is
/// `(v, v)`, so both direction arms accept the slice through their
/// non-strict-precedence composition (`v.precedes_or_equal(v)` and
/// `v.succeeds_or_equal(v)` both hold by reflexivity). Pinned by
/// `is_constant_returns_true_on_every_repetition_of_the_same_variant`.
///
/// Two-distinct-variant contract: `T::is_constant(items)` is `false`
/// on every slice containing two DISTINCT variants — declaration
/// order is total, so the two distinct variants sit at different
/// positions in [`Self::ALL`] and their strict-precedence relation
/// holds in exactly ONE direction, forcing the OTHER direction's
/// non-strict arm to reject the slice through the total-ordering
/// antisymmetry axiom. Pinned by
/// `is_constant_returns_false_on_any_slice_with_two_distinct_variants`.
///
/// Strict-implication contract: `T::is_constant(items) ⇒
/// !T::is_strictly_monotonic(items)` on every slice of arity ≥ 2 —
/// a constant slice with two or more elements contains adjacent equal
/// elements, which the strict-precedence primitive's irreflexivity
/// forces to reject through BOTH strict direction arms
/// ([`Self::is_strictly_ascending`] and
/// [`Self::is_strictly_descending`]), so the strictness-collapsed
/// disjunction ([`Self::is_strictly_monotonic`]) rejects too. The
/// arity ≥ 2 gate excludes the empty and singleton cases where both
/// predicates hold vacuously.
///
/// Non-strict-implication contract: `T::is_constant(items) ⇒
/// T::is_monotonic(items)` on every slice — a constant slice is a
/// witness of BOTH direction arms of the non-strict monotonicity
/// predicate, so the disjunction of the two arms accepts it too.
/// The converse fails past arity 2 (a strictly-monotonic non-constant
/// slice is monotonic without being constant), so `is_constant` is
/// strictly stronger than `is_monotonic` on the non-strict axis and
/// strictly weaker than `is_strictly_monotonic` on the strict axis
/// (past the trivially-both-hold empty and singleton cases).
///
/// Reversal-invariance: `T::is_constant(items) ==
/// T::is_constant(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its constant-ness because equality
/// is symmetric under position swap. The property is a typed
/// CONSEQUENCE of the direction-conjunction composition: reversing
/// swaps the ascending and descending arms, but the conjunction is
/// symmetric under that swap.
///
/// The direction-conjunction predicate sits at the OPPOSITE end of
/// the (∧, ∨) axis from the direction-disjunction predicate
/// [`Self::is_monotonic`]; together the two predicates NAME the two
/// endpoints of the direction-arm-combination axis, and every other
/// direction-combination (XOR, NAND, implication) is a downstream
/// derivation that binds through boolean composition of the two.
/// Widening the direction axis (`||`) accepts EITHER ordering;
/// narrowing the direction axis (`&&`) accepts ONLY the constant
/// intersection.
///
/// Future consumers that compose against [`Self::is_constant`]: a
/// `tatara-check` predicate `(check-phases-constant …)` verifying a
/// `WorkloadPhase` sequence is a repetition of ONE phase at plan
/// time (catching a spec whose "always in phase X" invariant is
/// silently violated, without pinning WHICH phase the check ranges
/// over); an LSP diagnostic verifying a Lisp-author-written closed-
/// set field is a repetition of the same variant across a batched
/// authoring surface; a Sekiban audit-trail metric verifying that a
/// convergence-classification trajectory is fixed at ONE
/// classification across a window (proof of the trajectory's
/// stability); a `tatara-lisp::macro_expand::Expander` cache pass
/// that skips a template rewrite when the operand slice is constant
/// (a valid optimization on any operator whose per-operand result
/// is idempotent). Each binds to ONE typed direction-joined N-ary
/// predicate on the trait rather than re-deriving `T::is_ascending(items)
/// && T::is_descending(items)` inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the direction-
/// joined N-ary "all elements equal" predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::is_ascending(items) && T::is_descending(items)`
/// conjunction at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the direction-joined axis
/// was an unnamed inline composition
/// (`T::is_ascending(items) && T::is_descending(items)`) recurring
/// at every prospective downstream "is-this-slice-a-constant"
/// site pre-lift AND at the pre-lift
/// `is_ascending_and_is_descending_hold_jointly_iff_slice_is_constant`
/// test's inline conjunction. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the direction-split arms
/// joined through the standard-library `&&`.
/// THEORY.md §VI.1 — generation over composition; the direction-
/// joined predicate emerges from the composition of TWO substrate
/// primitives ([`Self::is_ascending`] + [`Self::is_descending`]
/// joined via the standard-library `&&` short-circuit) rather
/// than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(andmap (λ (x) (equal? x head))
/// rest)` pattern for constant-slice detection; Julia's
/// `allequal(v)` (v1.8+) built-in that names the same predicate
/// through a dedicated primitive rather than an inline `all` over
/// a comparison; NumPy's `np.all(a == a[0])` composition on typed
/// arrays; Idris's `Vect n a` witness of a constant vector via the
/// `Replicate` constructor which encodes the same "all equal"
/// property structurally at the type level. Rust's iterator
/// `windows(2).all(|w| w[0] == w[1])` binds the same predicate on
/// any iterable slice. MLIR's `constant_vector` verification pass
/// surfaces the same predicate on typed vector operands.
/// Translation through pleme-io primitives: the direction-joined
/// N-ary predicate on the closed-set trait binds through the
/// conjunction of the two direction-split N-ary arms at the same
/// (ordering-agnostic, non-strict) corner — no new dep, no supertrait
/// bound (the direction-split arms replace the `PartialEq` bound the
/// standard-library signatures demand), no vector-shape carrier.
fn is_constant(items: &[Self]) -> bool {
<Self as ClosedSet>::is_ascending(items) && <Self as ClosedSet>::is_descending(items)
}
/// The N-ARY ORDERING-AGNOSTIC "pairwise distinct" predicate —
/// `true` iff every ordered pair of positions `(i, j)` with `i < j`
/// in `items` satisfies `items[i] != items[j]` (compared via
/// [`Self::index_of`]'s total-ordering discriminator), `false` on
/// the first pair of positions whose variants coincide. The
/// DISTINCTNESS-axis opener on the closed-set surface — dual to
/// [`Self::is_constant`] on the (constant, distinct) axis of the
/// N-ary element-equivalence face — while [`Self::is_constant`]
/// narrows to slices where every ordered pair AGREES, this
/// predicate widens to slices where every ordered pair DIFFERS.
///
/// Ordering-axis invariance: the predicate is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because the total-ordering discriminator
/// [`Self::index_of`] is a bijection into `[0, T::CARDINALITY)`,
/// so "variants coincide" is the same condition under EVERY
/// ordering. Sibling posture to
/// [`Self::is_constant`]'s ordering-axis invariance: both
/// endpoints of the (constant, distinct) equivalence-partition
/// axis are direction- AND ordering-agnostic; no separate
/// `sorted_is_pairwise_distinct` peer is needed. Pinned by
/// `is_pairwise_distinct_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::is_pairwise_distinct(&[])` is `true`
/// on every implementor — the outer sweep is vacuously `true` on
/// the empty slice by empty quantification over positions. Pinned
/// by `is_pairwise_distinct_returns_true_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::is_pairwise_distinct(&[v])` is `true`
/// for every variant `v` — the inner sweep is vacuously `true` on
/// every singleton slice because no strictly-greater position
/// exists to pair against. Pinned by
/// `is_pairwise_distinct_returns_true_on_every_singleton_slice_across_every_variant`.
///
/// Two-distinct-variant contract: `T::is_pairwise_distinct(&[a, b])`
/// is `true` for every ordered pair `(a, b)` with `a != b` — the
/// single pair `(0, 1)` sits at distinct variants, so the sweep
/// accepts. Pinned by
/// `is_pairwise_distinct_returns_true_on_every_two_distinct_variant_slice`.
///
/// Repetition-rejection contract: `T::is_pairwise_distinct(items)`
/// is `false` on every slice of arity ≥ 2 containing ANY two
/// positions with the same variant — the pair `(i, j)` at those
/// positions violates the outer-`all` short-circuit. Pinned by
/// `is_pairwise_distinct_returns_false_on_any_slice_with_a_repeated_variant`.
///
/// Full-set contract: `T::is_pairwise_distinct(<T as ClosedSet>::ALL)`
/// holds unconditionally on every implementor — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins labels as pairwise distinct, and [`Self::label`]
/// is a bijection between variants and labels, so the variants
/// themselves are pairwise distinct by construction. Complements
/// [`Self::is_constant`]'s full-set contract at the OPPOSITE corner
/// of the (constant, distinct) equivalence-partition axis — the
/// full set is distinct unconditionally while it is constant iff
/// cardinality ≤ 1. Pinned by
/// `is_pairwise_distinct_over_the_full_set_holds_unconditionally`.
///
/// Constant-vs-distinct partition: for every slice of arity ≥ 2,
/// `T::is_constant(items)` and `T::is_pairwise_distinct(items)`
/// are mutually exclusive — a constant slice past arity 1 has
/// two equal positions, and a pairwise-distinct slice has none.
/// They are NOT jointly exhaustive: a slice `[a, b, a]` on distinct
/// `a` and `b` is neither constant nor pairwise distinct. The
/// (constant, distinct) axis carves out the two extremes of the
/// N-ary element-equivalence surface without covering the
/// mixed-repetition interior. Pinned by
/// `is_pairwise_distinct_and_is_constant_are_mutually_exclusive_past_arity_one`.
///
/// Strict-monotonic-implication contract:
/// `T::is_strictly_monotonic(items) ⇒ T::is_pairwise_distinct(items)`
/// on every slice — the strict pairwise-precedence primitive's
/// irreflexivity axiom forces adjacent positions to sit at
/// distinct variants, and the strict monotonicity property
/// propagates that irreflexivity across every non-adjacent pair
/// via transitivity of the strict order (a strictly-monotonic
/// slice's variants sit at strictly-increasing or
/// strictly-decreasing positions in [`Self::ALL`], so no two
/// positions coincide). The converse fails past arity 2: the
/// permutation `[Alpha, Gamma, Beta]` is pairwise distinct but
/// neither strictly ascending nor strictly descending under
/// declaration order. Pinned by
/// `is_strictly_monotonic_implies_is_pairwise_distinct_across_every_triple`.
///
/// Reversal-invariance: `T::is_pairwise_distinct(items) ==
/// T::is_pairwise_distinct(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its pairwise-distinctness because
/// element equality is invariant under position permutation. Pinned
/// by `is_pairwise_distinct_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the predicate is a typed CONSEQUENCE of the
/// substrate's [`Self::index_of`] projection — the discriminator
/// between two variants is their position in [`Self::ALL`], which
/// closed-set well-formedness clause (3) pins as a bijection. The
/// composition uses standard-library `.iter().enumerate().all(…)`
/// with an inner `.iter().all(…)` over positions strictly greater
/// than the outer position, so the sweep is O(n(n-1)/2) on slice
/// arity `n` — allocation-free, no `PartialEq` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no bitset-shape carrier (a bitmap over
/// [`Self::CARDINALITY`] positions would improve to O(n) but
/// couple the surface to a compile-time cardinality bound; the
/// pairwise sweep is simpler and stays within the trait's minimal
/// supertrait surface).
///
/// Future consumers that compose against
/// [`Self::is_pairwise_distinct`]: a `tatara-check` predicate
/// `(check-phases-pairwise-distinct …)` verifying a `WorkloadPhase`
/// sequence has no repeated phase at plan time (catching a spec
/// that would silently re-enter the same phase and violate the
/// substrate's "each phase appears at most once" invariant); an
/// LSP diagnostic verifying a Lisp-author-written closed-set field
/// contains no repeated variant across a batched authoring surface
/// (`:severities [:info :warn :info]` flags the duplicate); a
/// Sekiban audit-trail metric verifying a convergence-classification
/// trajectory visits each classification AT MOST ONCE across a
/// window (proof of the trajectory's monotone progression through
/// the classification poset); a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that rejects a template whose generated identifier
/// set contains a repeated symbol (a hygiene violation the pass
/// otherwise catches only downstream through a name-collision
/// diagnostic). Each binds to ONE typed N-ary distinctness
/// predicate on the trait rather than re-deriving the pairwise
/// sweep inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// distinctness predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline nested
/// `for` loop at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the N-ary distinctness axis was an unnamed
/// inline composition recurring at every prospective downstream
/// "does-this-slice-repeat-a-variant" site pre-lift. Naming it
/// on the trait makes the predicate a TYPED CONSEQUENCE of the
/// substrate's total-ordering discriminator ([`Self::index_of`])
/// projected through the standard-library `.iter().enumerate().all(…)`
/// combinator.
/// THEORY.md §VI.1 — generation over composition; the pairwise-
/// distinctness predicate emerges from the composition of ONE
/// substrate primitive ([`Self::index_of`]) with the standard-
/// library `.iter().enumerate().all(…)` combinator rather than
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(check-duplicates lst)`
/// standard-library primitive that projects a slice through an
/// optional key extractor and reports the first duplicate; Julia's
/// `allunique(v)` (v1.8+) built-in that names the same predicate
/// through a dedicated primitive rather than an inline `Set(v)`
/// materialization; Python's `len(set(items)) == len(items)`
/// composition on hashable iterables; Idris's `NoDup : Vect n a
/// -> Type` witness of a duplicate-free vector via a
/// per-position position-differentiation proof carrier that
/// encodes the same "all distinct" property structurally at the
/// type level. Rust's `HashSet<_>::insert` returning `bool` (`true`
/// on fresh insert, `false` on duplicate) binds the same predicate
/// through an allocating set materialization. Haskell's
/// `Data.List.nub` composed with `length` comparison surfaces the
/// same shape on any `Eq`-instance. MLIR's `constant_index_set`
/// verification pass surfaces the same predicate on typed index
/// operands. Translation through pleme-io primitives: the N-ary
/// distinctness predicate on the closed-set trait binds through
/// the substrate's total-ordering discriminator [`Self::index_of`]
/// projected via the standard-library pairwise-`all` combinator
/// at the (ordering-agnostic, non-strict) corner of the
/// direction-arm-combination surface — no new dep, no supertrait
/// bound (the `index_of` projection replaces the `Eq`/`Hash`
/// bound the standard-library signatures demand), no set-shape
/// carrier, no allocation.
fn is_pairwise_distinct(items: &[Self]) -> bool {
items.iter().enumerate().all(|(i, a)| {
items[i + 1..]
.iter()
.all(|b| <Self as ClosedSet>::index_of(*a) != <Self as ClosedSet>::index_of(*b))
})
}
/// The N-ARY ORDERING-AGNOSTIC "distinct count" projection —
/// the `usize` cardinality of the SET of variant identities that
/// occur in `items`, computed as the count of positions whose
/// variant does not appear at any strictly-lesser position (a
/// "first-occurrence" sweep keyed on [`Self::index_of`]). The
/// USIZE-RETURN opener on the (return-shape) column of the
/// N-ary element-equivalence surface past the pre-existing
/// bool-return endpoints [`Self::is_constant`] (all elements
/// AGREE) and [`Self::is_pairwise_distinct`] (all elements
/// DIFFER) — while both bool-return endpoints answer a YES/NO
/// question about the extremes of the equivalence-partition
/// axis, this projection reports the EXACT distinctness
/// cardinality of the multiset the slice underlies, folding
/// both endpoints into two special values of ONE numerical
/// invariant. Not a fresh substrate primitive on the index axis
/// — the count emerges from the [`Self::index_of`] bijection
/// applied position-by-position with a strictly-lesser-position
/// dedup sweep, so the return value is a typed CONSEQUENCE of
/// the substrate's total-ordering discriminator.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES
/// on element equality because the total-ordering discriminator
/// [`Self::index_of`] is a bijection into `[0, T::CARDINALITY)`,
/// so "variants coincide" is the same condition under EVERY
/// ordering. Sibling posture to
/// [`Self::is_constant`] + [`Self::is_pairwise_distinct`]'s
/// ordering-axis invariance: every projection on the
/// equivalence-partition surface is direction- AND ordering-
/// agnostic; no separate `sorted_count_distinct` peer is needed.
/// Pinned by
/// `count_distinct_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_distinct(&[])` is `0` on
/// every implementor — the outer filter sweep is vacuously
/// empty on the empty slice, and `.count()` on an empty
/// iterator is `0`. Pinned by
/// `count_distinct_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::count_distinct(&[v])` is `1` for
/// every variant `v` — the sole position `(0, v)` has an empty
/// strictly-lesser-position prefix, so the `.any(…)` inner
/// sweep returns `false`, the `!` negation flips it to `true`,
/// and the outer `.count()` on the singleton passing-iterator
/// yields `1`. Pinned by
/// `count_distinct_returns_one_on_every_singleton_slice_across_every_variant`.
///
/// Constant-slice contract: `T::count_distinct(items)` is `1`
/// on every non-empty slice whose every position sits at the
/// SAME variant — position `0` passes the filter (empty prefix),
/// and every subsequent position rejects it (the outer position
/// sees itself in the strictly-lesser-position prefix). Pinned
/// by `count_distinct_equals_one_on_every_non_empty_constant_slice`.
///
/// Full-set contract: `T::count_distinct(<T as ClosedSet>::ALL)`
/// is `T::CARDINALITY` — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3)
/// pins labels (and hence variants) as pairwise distinct, so
/// EVERY position of `<T as ClosedSet>::ALL` passes the
/// first-occurrence filter, and the outer `.count()` yields the
/// arity `T::CARDINALITY`. Pinned by
/// `count_distinct_over_the_full_set_equals_cardinality`.
///
/// Upper bound: `T::count_distinct(items) <= items.len()` on
/// every slice — a filter never accepts more positions than it
/// visits. Tighter upper bound: `T::count_distinct(items) <=
/// T::CARDINALITY` on every slice — the closed set carries
/// exactly `T::CARDINALITY` variant identities, so the distinct
/// count cannot exceed the cardinality of the ambient set.
/// Pinned by
/// `count_distinct_is_bounded_above_by_min_of_slice_length_and_cardinality_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::is_pairwise_distinct(items)` iff
/// `T::count_distinct(items) == items.len()` — the pairwise-
/// distinctness predicate is the USIZE-return count reaching
/// its per-slice upper bound; and
/// * `T::is_constant(items)` iff `items.is_empty() ||
/// T::count_distinct(items) == 1` — the constant-slice
/// predicate is the USIZE-return count collapsing to `1` on
/// every non-empty slice (the empty slice is BOTH constant
/// and distinct-count-zero, so the disjunction is required
/// at the empty-slice endpoint).
///
/// Both identities pin the bool-return endpoints as typed
/// projections of the USIZE-return count. Pinned by
/// `count_distinct_equals_slice_length_iff_is_pairwise_distinct_holds`
/// and
/// `count_distinct_equals_one_iff_slice_is_non_empty_and_is_constant`.
///
/// Reversal-invariance: `T::count_distinct(items) ==
/// T::count_distinct(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its multiset of variant
/// identities, and the distinct count is a function of that
/// multiset alone. Pinned by
/// `count_distinct_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// the substrate's [`Self::index_of`] projection — the
/// discriminator between two variants is their position in
/// [`Self::ALL`], which closed-set well-formedness clause (3)
/// pins as a bijection. The composition uses standard-library
/// `.iter().enumerate().filter(…).count()` with the same
/// pairwise-position sweep [`Self::is_pairwise_distinct`]
/// binds against, so the sweep is O(n(n-1)/2) on slice arity
/// `n` — allocation-free, no `PartialEq` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait
/// pair stays untouched), no bitset-shape carrier (a bitmap
/// over [`Self::CARDINALITY`] positions would improve to
/// O(n) but couple the surface to a compile-time cardinality
/// bound; the pairwise sweep is simpler and stays within the
/// trait's minimal supertrait surface).
///
/// Future consumers that compose against
/// [`Self::count_distinct`]: a `tatara-check` predicate
/// `(check-phases-cover-cardinality …)` verifying a
/// `WorkloadPhase` sequence's distinct-count matches its
/// nominal size at plan time; an LSP diagnostic that renders
/// a batched authoring surface's per-field distinctness
/// cardinality as a completion hint (`":severities [:info :info
/// :warn] — 2 distinct of 3"`); a Sekiban audit-trail metric
/// labeled by the distinct-count of the trajectory across a
/// window (a "coverage" measure of the classification poset);
/// a `tatara-lisp::macro_expand::Expander` hygiene pass that
/// reports the exact number of distinct generated identifiers
/// (turning the pass-level pairwise-distinctness predicate
/// into a fine-grained diagnostic without a second sweep);
/// the substrate's own `WorkloadPhase` trajectory-cardinality
/// gauge projecting through `phase.count_distinct` to expose
/// the "how many phases did we actually visit" measure. Each
/// binds to ONE typed N-ary distinct-count projection on the
/// trait rather than re-deriving the first-occurrence sweep
/// inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// distinct-count projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// dedup sweep at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the N-ary distinct-count axis
/// was an unnamed inline composition recurring at every
/// prospective downstream "how many distinct variants does
/// this slice hit" site pre-lift. Naming it on the trait
/// makes the projection a TYPED CONSEQUENCE of the
/// substrate's total-ordering discriminator
/// ([`Self::index_of`]) projected through the standard-
/// library `.iter().enumerate().filter(…).count()` combinator.
/// THEORY.md §VI.1 — generation over composition; the
/// distinct-count projection emerges from the composition of
/// ONE substrate primitive ([`Self::index_of`]) with the
/// standard-library first-occurrence filter combinator rather
/// than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(length (remove-duplicates
/// lst))` composition on any list; Julia's `length(unique(v))`
/// composition on any iterable; NumPy's
/// `len(np.unique(a))` idiom on typed arrays; Python's
/// `len(set(items))` on hashable iterables; Idris's
/// `card : (v : Vect n a) -> Nat` that names the same
/// projection through a dedicated primitive on typed vectors.
/// Rust's `items.iter().collect::<HashSet<_>>().len()` binds
/// the same projection through an allocating set
/// materialization. MLIR's `constant_index_set` verification
/// pass surfaces the same projection on typed index operands
/// as a per-operand distinct-count check. Translation through
/// pleme-io primitives: the N-ary distinct-count projection
/// on the closed-set trait binds through the substrate's
/// total-ordering discriminator [`Self::index_of`] projected
/// via the standard-library first-occurrence-`filter`-then-
/// `count` combinator at the (ordering-agnostic, non-strict)
/// corner of the equivalence-partition surface — no new dep,
/// no supertrait bound (the `index_of` projection replaces the
/// `Eq`/`Hash` bound the standard-library signatures demand),
/// no set-shape carrier, no allocation.
fn count_distinct(items: &[Self]) -> usize {
items
.iter()
.enumerate()
.filter(|(i, a)| {
!items[..*i].iter().any(|b| {
<Self as ClosedSet>::index_of(**a) == <Self as ClosedSet>::index_of(*b)
})
})
.count()
}
/// The N-ARY ORDERING-AGNOSTIC "covers every variant" surjectivity
/// predicate — `true` iff every variant of [`Self::ALL`] occurs at
/// least once in `items`. The BOOL-RETURN opener on the (covering)
/// axis of the equivalence-partition surface, positioned as a typed
/// CONSEQUENCE of the just-lifted USIZE-return [`Self::count_distinct`]
/// projection reaching the substrate-carried upper bound
/// [`Self::CARDINALITY`]. The predicate answers YES/NO to "does this
/// slice HIT every variant?" — dual to [`Self::is_pairwise_distinct`]
/// (which answers YES/NO to "does this slice REPEAT any variant?")
/// on the same equivalence-partition surface, and orthogonal to
/// [`Self::is_constant`] (which answers YES/NO to "do all positions
/// SHARE one variant?"). Not a fresh substrate primitive on the
/// index axis — the predicate emerges from a single equality check
/// on the just-lifted usize-return count against the trait-level
/// [`Self::CARDINALITY`] constant.
///
/// Ordering-axis invariance: the predicate is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because the total-ordering discriminator
/// [`Self::index_of`] is a bijection into `[0, T::CARDINALITY)`, so
/// "did we hit every variant?" is the same question under EVERY
/// ordering. Sibling posture to [`Self::count_distinct`],
/// [`Self::is_constant`], and [`Self::is_pairwise_distinct`]'s
/// ordering-axis invariance: every projection on the equivalence-
/// partition surface is direction- AND ordering-agnostic; no
/// separate `sorted_is_covering` peer is needed. Pinned by
/// `is_covering_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::is_covering(&[])` is `true` iff
/// `T::CARDINALITY == 0` on every implementor — the empty slice
/// visits zero variants, and coverage requires visiting
/// `T::CARDINALITY`-many. On every non-degenerate closed-set enum
/// (the substrate's 36+ implementors all carry cardinality ≥ 1),
/// the empty slice rejects. Pinned by
/// `is_covering_returns_false_on_the_empty_slice_across_every_non_degenerate_kind`.
///
/// Singleton contract: `T::is_covering(&[v])` is `true` iff
/// `T::CARDINALITY == 1` on every implementor — a singleton visits
/// one variant, and coverage requires visiting `T::CARDINALITY`-many.
/// On every implementor with `T::CARDINALITY >= 2` (the substrate's
/// dominant case), every singleton rejects. Pinned by
/// `is_covering_returns_false_on_every_singleton_when_cardinality_is_at_least_two`.
///
/// Full-set contract: `T::is_covering(<T as ClosedSet>::ALL)` is
/// `true` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// labels (and hence variants) as pairwise distinct, so
/// `T::count_distinct(<T as ClosedSet>::ALL) == T::CARDINALITY`,
/// which is exactly the covering identity. Pinned by
/// `is_covering_over_the_full_set_holds_unconditionally`.
///
/// Concatenation-monotone contract: appending positions to a
/// covering slice preserves coverage (a superset of a variant-hit
/// slice hits every variant the sub-slice hits). Pinned by
/// `is_covering_over_the_doubled_full_set_holds_unconditionally`.
///
/// Composition identity: for every slice `items`,
/// `T::is_covering(items)` iff
/// `T::count_distinct(items) == T::CARDINALITY` — the surjectivity
/// predicate is the USIZE-return count reaching the substrate-
/// carried upper bound. Pinned by
/// `is_covering_composes_through_count_distinct_equals_cardinality_across_every_triple`.
///
/// Length lower bound: `T::is_covering(items)` implies
/// `items.len() >= T::CARDINALITY` on every slice — coverage
/// requires at least `T::CARDINALITY`-many positions because the
/// distinct count is bounded above by the slice length. The
/// contrapositive: `items.len() < T::CARDINALITY` implies
/// `!T::is_covering(items)`. Pinned by
/// `is_covering_implies_slice_length_is_at_least_cardinality_across_every_triple`.
///
/// Reversal-invariance: `T::is_covering(items)` equals
/// `T::is_covering(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its multiset of variant identities,
/// and coverage is a function of that multiset alone. Pinned by
/// `is_covering_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the predicate is a typed CONSEQUENCE of the
/// substrate's [`Self::count_distinct`] projection and the
/// [`Self::CARDINALITY`] constant. The composition uses one
/// equality check on the usize-return count, so the sweep inherits
/// [`Self::count_distinct`]'s O(n(n-1)/2) cost on slice arity `n`
/// — allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no bitset-shape carrier.
///
/// Future consumers that compose against [`Self::is_covering`]:
/// a `tatara-check` predicate `(check-phases-cover-all …)` verifying
/// that a `WorkloadPhase` sequence hits every phase at least once
/// at plan time — catching a spec that would silently omit a phase;
/// an LSP diagnostic on a Lisp-author-written closed-set field that
/// warns when the value multiset does not cover the ambient set
/// (`":severities [:warn :info]"` on a 3-variant severity enum
/// omits `:crit`); a Sekiban audit-trail metric labeled by
/// coverage of a classification poset (a "did we visit every
/// classification?" gauge across a window); a
/// `tatara-lisp::macro_expand::Expander` hygiene pass that
/// verifies a template's generated identifier set spans a required
/// closed vocabulary. Each binds to ONE typed N-ary surjectivity
/// predicate on the trait rather than re-deriving
/// `T::count_distinct(items) == T::CARDINALITY` inline per
/// callsite.
///
/// Compounding benefits the future
/// `ClosedSet::is_permutation_of_all` lift on the "does this slice
/// visit every variant exactly once?" corner of the equivalence-
/// partition surface: `is_permutation_of_all` is a typed
/// CONSEQUENCE of
/// `T::is_pairwise_distinct(items) && T::is_covering(items)`
/// (equivalently `items.len() == T::CARDINALITY && T::is_covering(items)`),
/// so once THIS lift lands the sibling predicate is a two-primitive
/// conjunction rather than a fresh inline sweep. The (covering,
/// distinct, permutation) triangle then closes at three typed
/// primitives on the same equivalence-partition surface.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// surjectivity predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::count_distinct(items) == T::CARDINALITY` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the covering axis was an unnamed inline composition
/// recurring at every prospective downstream "did we hit every
/// variant?" site pre-lift. Naming it makes the predicate a TYPED
/// CONSEQUENCE of the substrate's total-ordering discriminator
/// ([`Self::index_of`] via [`Self::count_distinct`]) compared
/// against the trait-level cardinality constant. THEORY.md §VI.1
/// — generation over composition; the covering predicate emerges
/// from the composition of ONE substrate primitive
/// ([`Self::count_distinct`]) with the trait-level constant
/// ([`Self::CARDINALITY`]) via a single `==` on `usize`, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `Forall_incl : forall (l m : list A),
/// (forall x, In x l -> In x m) -> incl l m` predicate that
/// captures the "every member of `l` occurs in `m`" surjectivity
/// relation between two lists; Idris's `Elem : (x : a) -> Vect n a
/// -> Type` combined with the "for-every-variant" universal
/// quantifier over a typed sum's constructor set surfaces the
/// same predicate structurally at the type level; Rust's own
/// `items.iter().collect::<HashSet<_>>().len() == T::CARDINALITY`
/// binds the predicate through an allocating set materialization.
/// Julia's `issetequal(unique(v), T)` on a typed vector; NumPy's
/// `np.array_equal(np.sort(np.unique(a)), T)` idiom. Translation
/// through pleme-io primitives: the N-ary surjectivity predicate
/// on the closed-set trait binds through the substrate's
/// [`Self::count_distinct`] projection reaching the trait-level
/// [`Self::CARDINALITY`] constant at the (ordering-agnostic)
/// corner of the equivalence-partition surface — no new dep, no
/// supertrait bound (the [`Self::count_distinct`] projection
/// replaces the `Eq`/`Hash` bound the standard-library signatures
/// demand), no set-shape carrier, no allocation.
fn is_covering(items: &[Self]) -> bool {
<Self as ClosedSet>::count_distinct(items) == <Self as ClosedSet>::CARDINALITY
}
/// The BOOL-return N-ARY predicate answering "does this slice visit
/// every variant EXACTLY ONCE?" — the (covering ∧ distinct)
/// CONJUNCTION corner of the equivalence-partition surface,
/// closing the (constant, distinct, covering, permutation) 4-
/// projection square past the three pre-existing typed primitives.
///
/// Composition: `T::is_permutation_of_all(items) ==
/// T::is_covering(items) && T::is_pairwise_distinct(items)` for
/// every slice, so the predicate is a TYPED CONSEQUENCE of two
/// prior N-ary primitives already lifted on the same surface. No
/// fresh substrate primitive — the (covering, distinct) conjunction
/// exactly names the "permutation of the full set" corner. The
/// prior [`Self::is_covering`] lift's compounding paragraph
/// explicitly named THIS predicate as the next natural lift on
/// the equivalence-partition surface once its two building-block
/// projections landed as typed primitives.
///
/// EQUIVALENT formulations pinned by tests:
/// * `T::is_covering(items) && T::is_pairwise_distinct(items)`
/// (the canonical form the body uses);
/// * `T::is_covering(items) && items.len() == T::CARDINALITY`
/// (via the pairwise-distinctness length-equals-count fixpoint —
/// a pairwise-distinct slice has `count_distinct == items.len()`,
/// and a covering slice has `count_distinct == T::CARDINALITY`);
/// * `T::is_pairwise_distinct(items) && items.len() ==
/// T::CARDINALITY` (the length-forced dual — a pairwise-distinct
/// slice of length `T::CARDINALITY` MUST hit every variant since
/// the distinct count and the ambient cardinality coincide);
/// * `T::count_distinct(items) == T::CARDINALITY && items.len() ==
/// T::CARDINALITY` (routing through the raw USIZE-return count).
///
/// Empty-slice contract: `T::is_permutation_of_all(&[])` iff
/// `T::CARDINALITY == 0` — the empty slice is a permutation of
/// the empty full set (both `is_covering` and
/// `is_pairwise_distinct` accept the empty slice on the
/// degenerate closed set with zero variants) and rejects on every
/// implementor of positive cardinality (the empty slice fails
/// the covering endpoint since `count_distinct == 0 <
/// T::CARDINALITY`). Pinned by
/// `is_permutation_of_all_returns_false_on_the_empty_slice_across_every_non_degenerate_kind`.
///
/// Singleton contract: `T::is_permutation_of_all(&[v])` iff
/// `T::CARDINALITY == 1` — a singleton is a permutation of a
/// cardinality-1 full set. Every cardinality-≥-2 implementor
/// (including StubKind at cardinality 3) rejects. Pinned by
/// `is_permutation_of_all_returns_false_on_every_singleton_when_cardinality_is_at_least_two`.
///
/// Full-set contract: `T::is_permutation_of_all(<T as ClosedSet>::ALL)`
/// is `true` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so `<T as ClosedSet>::ALL`
/// satisfies both `is_covering` (its distinct count reaches
/// `T::CARDINALITY`) and `is_pairwise_distinct` (no repetition).
/// Pinned by
/// `is_permutation_of_all_over_the_full_set_holds_unconditionally`.
///
/// Length-EQUAL-cardinality contract: `T::is_permutation_of_all(items)`
/// implies `items.len() == T::CARDINALITY` (bidirectional lower AND
/// upper bound) — coverage forces `items.len() >= T::CARDINALITY`
/// (the covering length lower bound), and pairwise-distinctness
/// forces `items.len() == T::count_distinct(items) <=
/// T::CARDINALITY`; together the two force EQUALITY. Contrapositive:
/// `items.len() != T::CARDINALITY` implies
/// `!T::is_permutation_of_all(items)`. Pinned by
/// `is_permutation_of_all_forces_slice_length_equals_cardinality_across_every_triple`.
/// This is the STRICTER upper bound the covering predicate's
/// LOWER bound (`items.len() >= T::CARDINALITY`) does not carry
/// alone — the doubled full set covers but is NOT a permutation of
/// all, closing the composition-monotonicity gap at the ADDING-
/// pairwise-distinctness step.
///
/// Doubled-full-set contract: `T::is_permutation_of_all` REJECTS
/// the doubled full set `[ALL[0], …, ALL[n-1], ALL[0], …,
/// ALL[n-1]]` whenever `T::CARDINALITY >= 1` — the doubled slice
/// covers (via [`Self::is_covering`]'s concatenation-monotonicity)
/// but repeats every variant so
/// [`Self::is_pairwise_distinct`] rejects. The contrast with
/// [`Self::is_covering`]'s
/// `is_covering_over_the_doubled_full_set_holds_unconditionally`
/// contract is the load-bearing difference the permutation
/// predicate carries past the covering predicate: coverage is
/// concatenation-MONOTONE while permutation-of-all is NOT (adding
/// a duplicate strictly breaks the conjunction). Pinned by
/// `is_permutation_of_all_rejects_the_doubled_full_set_across_every_non_degenerate_kind`.
///
/// Reversal-invariance: `T::is_permutation_of_all(items)` equals
/// `T::is_permutation_of_all(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its multiset of variant
/// identities, and both building-block projections are ordering-
/// agnostic fixpoints of that multiset. Sibling posture to
/// [`Self::is_covering`]'s
/// `is_covering_is_invariant_under_slice_reversal_across_every_triple`,
/// [`Self::is_pairwise_distinct`]'s
/// `is_pairwise_distinct_is_invariant_under_slice_reversal_across_every_triple`,
/// and [`Self::is_constant`]'s
/// `is_constant_is_invariant_under_slice_reversal_across_every_triple`
/// one column of the (return-shape) axis over: every projection
/// on the equivalence-partition surface is a fixpoint of slice
/// reversal. Pinned by
/// `is_permutation_of_all_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the predicate composes on two typed CONSEQUENCE
/// projections ([`Self::is_covering`] +
/// [`Self::is_pairwise_distinct`]), which in turn compose on ONE
/// substrate primitive ([`Self::count_distinct`]) and the trait-
/// level [`Self::CARDINALITY`] constant. The composition inherits
/// [`Self::count_distinct`]'s O(n(n-1)/2) cost on slice arity `n`
/// — allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no set-shape carrier, no allocation. The
/// short-circuit `&&` orders the covering-check first because
/// `count_distinct` is amortised across the sub-slice sweep the
/// pairwise-distinct predicate re-runs; a future micro-refactor
/// can substitute the equivalent `is_pairwise_distinct(items) &&
/// items.len() == T::CARDINALITY` form (pinned equivalent by the
/// length-forced dual test) without touching the surface.
///
/// Future consumers that compose against
/// [`Self::is_permutation_of_all`]: a `tatara-check` predicate
/// `(check-phases-permute-all …)` verifying that a
/// `WorkloadPhase` sequence hits every phase EXACTLY ONCE at
/// plan time — catching both an omitted phase (covering fails)
/// AND a duplicate (pairwise-distinct fails) at the ONE
/// predicate; an LSP diagnostic on a Lisp-author-written closed-
/// set field that emits at BOTH the "under-coverage" AND the
/// "duplicate" callsite through ONE typed sweep rather than
/// through two disjoint checks; a Sekiban audit-trail metric
/// labeled by whether a rollout window's per-phase transition
/// sequence forms a permutation of the full lifecycle (a
/// deterministic UP-DOWN cycle vs a degenerate churn); a
/// `tatara-lisp::macro_expand::Expander` hygiene pass that
/// verifies a template's generated identifier sequence forms a
/// permutation of a required closed vocabulary (each identifier
/// used exactly once, no omission and no re-use). Each binds to
/// ONE typed N-ary permutation predicate on the trait rather
/// than re-deriving the two-primitive conjunction inline per
/// callsite.
///
/// Compounding closure: the (constant, distinct, covering,
/// permutation) 4-projection square on the equivalence-partition
/// surface now closes at four typed primitives —
/// [`Self::is_constant`] (all elements equal),
/// [`Self::is_pairwise_distinct`] (no elements equal),
/// [`Self::is_covering`] (every variant hit at least once), and
/// THIS predicate (every variant hit exactly once) — plus one
/// usize-return sibling [`Self::count_distinct`] (how many
/// variants hit). The square's fifth CONJUNCTION corner
/// `(constant ∧ covering)` is degenerate (holds iff
/// `T::CARDINALITY == 1`); the sixth corner `(constant ∧
/// distinct)` is degenerate (holds iff `items.len() <= 1`);
/// permutation is the load-bearing NON-DEGENERATE conjunction.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// permutation predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::is_covering(items) && T::is_pairwise_distinct(items)`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the permutation-of-all axis was an
/// unnamed inline two-primitive conjunction pre-lift. Naming it
/// makes the predicate a TYPED CONSEQUENCE of two substrate
/// projections on the SAME equivalence-partition surface, so
/// the ONE bit of information "is this slice a permutation of
/// the ambient set?" binds against a NAMED predicate rather than
/// against an inline conjunction that could silently drift if
/// either building-block projection's semantics changes.
/// THEORY.md §VI.1 — generation over composition; the
/// permutation predicate emerges from the composition of TWO
/// substrate primitives ([`Self::is_covering`] +
/// [`Self::is_pairwise_distinct`]) via a single `&&` on `bool`,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `Permutation : list A -> list A ->
/// Prop` capturing the "same multiset" relation between two lists,
/// which restricted to a right-argument fixed to the canonical
/// full set exactly names THIS predicate structurally. Idris's
/// `Vect n a` combined with an isomorphism to a finite typed sum's
/// constructor set surfaces the same predicate through the
/// dependent-type lens (a `Vect n a` is a permutation of the full
/// set iff `n` matches the cardinality AND every constructor
/// appears). Rust's own
/// `let mut sorted: Vec<_> = items.to_vec(); sorted.sort(); sorted
/// == <T as ClosedSet>::ALL.to_vec()` idiom binds through an
/// allocating sort. Julia's `issetequal(v, T)` when
/// `length(v) == length(T)`. Haskell's `Data.List.sort a ==
/// [minBound .. maxBound]` on a `Bounded + Enum` type. NumPy's
/// `np.array_equal(np.sort(a), T)` idiom. Translation through
/// pleme-io primitives: the permutation predicate binds through
/// the substrate's [`Self::is_covering`] +
/// [`Self::is_pairwise_distinct`] conjunction — no new dep, no
/// `Ord`/`Eq`/`Hash` supertrait bound (the two building-block
/// projections already compose on the substrate's
/// [`Self::count_distinct`] primitive and the trait-level
/// [`Self::CARDINALITY`] constant), no sort-shape carrier, no
/// allocation.
fn is_permutation_of_all(items: &[Self]) -> bool {
<Self as ClosedSet>::is_covering(items) && <Self as ClosedSet>::is_pairwise_distinct(items)
}
/// The N-ARY ORDERING-AGNOSTIC "missing count" projection — the
/// `usize` cardinality of the SET of variants of [`Self::ALL`] that
/// do NOT occur in `items`, computed as the substrate-carried
/// [`Self::CARDINALITY`] constant minus the just-lifted usize-return
/// [`Self::count_distinct`] projection. The USIZE-RETURN opener on
/// the (absent) column of the (present, absent) partition-arm axis
/// of the equivalence-partition surface, positioned as the direct
/// dual of [`Self::count_distinct`] one column of the (partition-
/// arm) axis over — while [`Self::count_distinct`] reports "how
/// many variants does the slice HIT?", this projection reports
/// "how many variants does the slice MISS?", folding the ambient
/// set's partition into hit and miss cardinalities. Not a fresh
/// substrate primitive on the index axis — the count emerges from
/// one `usize`-subtraction of the just-lifted usize-return
/// [`Self::count_distinct`] projection from the trait-level
/// [`Self::CARDINALITY`] constant.
///
/// Partition identity: for every slice `items`,
/// `T::count_missing(items) + T::count_distinct(items) ==
/// T::CARDINALITY` — the (present, absent) partition arms cover
/// the ambient set exactly. Pinned by
/// `count_missing_plus_count_distinct_equals_cardinality_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because the total-ordering discriminator
/// [`Self::index_of`] is a bijection into `[0, T::CARDINALITY)`,
/// so "which variants are missing?" is the same question under
/// EVERY ordering. Sibling posture to [`Self::count_distinct`],
/// [`Self::is_constant`], [`Self::is_pairwise_distinct`],
/// [`Self::is_covering`], and [`Self::is_permutation_of_all`]'s
/// ordering-axis invariance: every projection on the
/// equivalence-partition surface is direction- AND ordering-
/// agnostic; no separate `sorted_count_missing` peer is needed.
/// Pinned by
/// `count_missing_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_missing(&[])` is
/// `T::CARDINALITY` on every implementor — the empty slice hits
/// zero variants, so it MISSES every variant of the ambient set.
/// Sibling posture to
/// `count_distinct_returns_zero_on_the_empty_slice_across_every_kind`
/// one column of the (partition-arm) axis over: the present-arm
/// projection reports its lower-bound fixpoint `0` at the empty-
/// slice endpoint, and the absent-arm projection reports its
/// upper-bound fixpoint `T::CARDINALITY` at the same endpoint.
/// Pinned by
/// `count_missing_returns_cardinality_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::count_missing(&[v])` is
/// `T::CARDINALITY - 1` for every variant `v` — a singleton hits
/// exactly one variant, so it misses `T::CARDINALITY - 1`-many.
/// Sibling posture to
/// `count_distinct_returns_one_on_every_singleton_slice_across_every_variant`
/// one column of the (partition-arm) axis over: the present-arm
/// projection collapses to `1` on every singleton, and the
/// absent-arm projection collapses to `T::CARDINALITY - 1` at
/// the same endpoint. Pinned by
/// `count_missing_returns_cardinality_minus_one_on_every_singleton_slice_across_every_variant`.
///
/// Full-set contract: `T::count_missing(<T as ClosedSet>::ALL)`
/// is `0` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// labels (and hence variants) as pairwise distinct, so
/// `T::count_distinct(<T as ClosedSet>::ALL) == T::CARDINALITY`,
/// which folds through the subtraction identity to `0` missing.
/// Complements
/// `count_distinct_over_the_full_set_equals_cardinality` at the
/// OPPOSITE arm of the (partition-arm) axis: the present-arm
/// count reaches its `T::CARDINALITY` upper bound, and the
/// absent-arm count collapses to its `0` lower bound. Pinned by
/// `count_missing_over_the_full_set_equals_zero`.
///
/// Concatenation-monotone contract: appending positions to a
/// slice can only KEEP or DECREASE the missing count (a superset
/// of a variant-hit slice misses AT MOST the variants the
/// sub-slice misses). Pinned by
/// `count_missing_over_the_doubled_full_set_equals_zero`.
///
/// Bool-projection identity (covering arm): for every slice
/// `items`, `T::count_missing(items) == 0` iff
/// `T::is_covering(items)` — the surjectivity predicate is the
/// absent-arm count collapsing to its lower-bound fixpoint (a
/// slice covers every variant iff none is missing). Sibling
/// posture to
/// `is_covering_composes_through_count_distinct_equals_cardinality_across_every_triple`
/// on the SAME equivalence-partition surface, viewed from the
/// absent-arm side. Pinned by
/// `count_missing_equals_zero_iff_is_covering_holds_across_every_triple`.
///
/// Upper-bound contract: `T::count_missing(items) <=
/// T::CARDINALITY` on every slice — the count is bounded above
/// by the ambient cardinality because the subtraction cannot
/// underflow (the well-formedness invariant guarantees
/// `T::count_distinct(items) <= T::CARDINALITY`, so the
/// difference is a non-negative `usize`). Pinned by
/// `count_missing_is_bounded_above_by_cardinality_across_every_triple`.
///
/// Reversal-invariance: `T::count_missing(items)` equals
/// `T::count_missing(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its multiset of variant
/// identities, and the missing count is a function of that
/// multiset alone. Pinned by
/// `count_missing_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_distinct`] projection and the
/// [`Self::CARDINALITY`] constant. The composition uses one
/// `usize`-subtraction, so the sweep inherits
/// [`Self::count_distinct`]'s O(n(n-1)/2) cost on slice arity
/// `n` — allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no bitset-shape carrier.
/// Underflow safety: the subtraction cannot wrap because
/// [`Self::count_distinct`]'s upper-bound contract (pinned by
/// `count_distinct_is_bounded_above_by_min_of_slice_length_and_cardinality_across_every_triple`)
/// pins `T::count_distinct(items) <= T::CARDINALITY` on every
/// slice.
///
/// Future consumers that compose against [`Self::count_missing`]:
/// a `tatara-check` predicate `(check-phases-missing-count …)`
/// verifying that a `WorkloadPhase` sequence misses AT MOST K
/// phases at plan time — catching a spec that would silently
/// omit more phases than an SLO permits; an LSP diagnostic on a
/// Lisp-author-written closed-set field that quantifies BY HOW
/// MANY variants the value multiset falls short of covering the
/// ambient set (`:severities [:warn]` on a 3-variant severity
/// enum reports 2 missing rather than the ONE bit "not covering"
/// that [`Self::is_covering`] surfaces); a Sekiban audit-trail
/// metric labeled by the ambient-set miss-count of a
/// classification poset (a "how many classifications were
/// missed?" gauge across a window); a
/// `tatara-lisp::macro_expand::Expander` hygiene pass that
/// quantifies a template's miss-count against a required closed
/// vocabulary. Each binds to ONE typed N-ary absent-count
/// projection on the trait rather than re-deriving
/// `T::CARDINALITY - T::count_distinct(items)` inline per
/// callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize)
/// 2×2 = 4-corner partition-arm × return-shape face on the
/// equivalence-partition surface now closes at four typed
/// primitives — [`Self::count_distinct`] (present-usize),
/// [`Self::is_covering`] (present-bool: "present-count reaches
/// cardinality"), THIS projection (absent-usize), and the
/// implicit `!T::is_covering(items)` (absent-bool: "any-missing"
/// as a boolean projection of the absent-count reaching `> 0`).
/// Once THIS lift lands the four corners bind to two typed
/// substrate primitives on the equivalence-partition surface,
/// and the (any-missing) predicate is a trivial future
/// composition on THIS count.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// absent-count projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::CARDINALITY - T::count_distinct(items)` subtraction at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (absent) column was an unnamed inline
/// composition recurring at every prospective downstream "how
/// many variants did we miss?" site pre-lift. Naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of the
/// substrate's total-ordering discriminator ([`Self::index_of`]
/// via [`Self::count_distinct`]) subtracted from the trait-level
/// [`Self::CARDINALITY`] constant. THEORY.md §VI.1 — generation
/// over composition; the missing-count projection emerges from
/// the composition of ONE substrate primitive
/// ([`Self::count_distinct`]) with the trait-level constant
/// ([`Self::CARDINALITY`]) via a single `-` on `usize`, not as
/// a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `length (list_diff T l)` idiom
/// composing list-set-difference with length to surface the
/// missing-count on a decidable-equality carrier; Idris's
/// `Data.Vect.Missing : Vect n a -> Vect m a -> Type` witness
/// combined with a fixed right-argument of the canonical full
/// set that surfaces the same projection at the type level;
/// Rust's own
/// `T::ALL.iter().filter(|v| !items.contains(v)).count()`
/// idiom binds through a per-position linear scan. Julia's
/// `length(setdiff(T, v))` on a typed vector; NumPy's
/// `len(np.setdiff1d(T, a))` idiom. Racket's
/// `(length (remove* v T))` composition on a list. Translation
/// through pleme-io primitives: the N-ary absent-count
/// projection on the closed-set trait binds through the
/// substrate's [`Self::count_distinct`] projection subtracted
/// from the trait-level [`Self::CARDINALITY`] constant — no
/// new dep, no supertrait bound (the [`Self::count_distinct`]
/// projection replaces the `Eq`/`Hash` bound the standard-
/// library set-difference signatures demand), no set-shape
/// carrier, no allocation.
fn count_missing(items: &[Self]) -> usize {
<Self as ClosedSet>::CARDINALITY - <Self as ClosedSet>::count_distinct(items)
}
/// The N-ARY ORDERING-AGNOSTIC "any variant missing?" predicate —
/// `true` iff AT LEAST ONE variant of [`Self::ALL`] does NOT occur
/// in `items`, computed as the just-lifted usize-return
/// [`Self::count_missing`] projection strictly exceeding zero. The
/// BOOL-RETURN closer on the (absent) arm of the (present, absent)
/// × (bool, usize) 2×2 = 4-corner partition-arm × return-shape
/// face on the equivalence-partition surface, positioned as the
/// direct DE MORGAN dual of [`Self::is_covering`] one column of
/// the (partition-arm) axis over — while [`Self::is_covering`]
/// reports "does the slice HIT every variant?", this projection
/// reports "does the slice MISS any variant?", folding the
/// ambient set's partition arms through the negation into the
/// bool-return absent-arm. Not a fresh substrate primitive on the
/// index axis — the predicate emerges from one comparison of the
/// just-lifted [`Self::count_missing`] projection against zero,
/// equivalently one `!` on the just-lifted [`Self::is_covering`]
/// predicate.
///
/// De Morgan identity: for every slice `items`,
/// `T::is_missing_any(items) == !T::is_covering(items)` — the
/// (any-missing, all-hit) partition arms are exact logical
/// negations of each other on the equivalence-partition surface.
/// Pinned by
/// `is_missing_any_de_morgan_dual_of_is_covering_across_every_triple`.
///
/// Count-projection identity: for every slice `items`,
/// `T::is_missing_any(items) == (T::count_missing(items) > 0)` —
/// the bool-return absent-arm predicate is the (nonzero-fixpoint)
/// projection of the usize-return absent-arm count. Sibling
/// posture to
/// `is_covering_composes_through_count_distinct_equals_cardinality_across_every_triple`
/// on the OPPOSITE partition arm: the present-arm bool predicate
/// is `count_distinct(items) == CARDINALITY`; the absent-arm
/// bool predicate is `count_missing(items) > 0`. Pinned by
/// `is_missing_any_holds_iff_count_missing_is_strictly_positive_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because
/// [`Self::count_missing`]'s ordering-axis invariance folds
/// through the `> 0` comparison bijectively. Sibling posture to
/// [`Self::count_distinct`], [`Self::count_missing`],
/// [`Self::is_constant`], [`Self::is_pairwise_distinct`],
/// [`Self::is_covering`], and [`Self::is_permutation_of_all`]'s
/// ordering-axis invariance: every projection on the
/// equivalence-partition surface is direction- AND ordering-
/// agnostic; no separate `sorted_is_missing_any` peer is needed.
/// Pinned by
/// `is_missing_any_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::is_missing_any(&[])` is `true` on
/// every implementor of non-zero cardinality — the empty slice
/// hits zero variants, so it misses every variant of the ambient
/// set (which is non-empty because the closed-set well-formedness
/// invariant guarantees `T::CARDINALITY >= 1`). Sibling posture
/// to
/// `is_covering_returns_false_on_the_empty_slice_across_every_non_degenerate_kind`
/// at the OPPOSITE partition arm: the present-arm predicate is
/// `false` at the empty slice; the absent-arm predicate is
/// `true`. Pinned by
/// `is_missing_any_returns_true_on_the_empty_slice_across_every_non_degenerate_kind`.
///
/// Singleton contract: `T::is_missing_any(&[v])` is `true` for
/// every variant `v` whenever `T::CARDINALITY >= 2` — a singleton
/// hits exactly one variant, so it misses `T::CARDINALITY - 1`-
/// many, which is at least one on every non-degenerate
/// implementor. Sibling posture to
/// `is_covering_returns_false_on_every_singleton_when_cardinality_is_at_least_two`
/// at the OPPOSITE partition arm. Pinned by
/// `is_missing_any_returns_true_on_every_singleton_when_cardinality_is_at_least_two`.
///
/// Full-set contract:
/// `T::is_missing_any(<T as ClosedSet>::ALL)` is `false`
/// UNCONDITIONALLY — the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins labels
/// (and hence variants) as pairwise distinct, so
/// `T::count_distinct(<T as ClosedSet>::ALL) == T::CARDINALITY`,
/// which folds through the [`Self::count_missing`] subtraction
/// identity to `0` missing, which folds through the `> 0`
/// comparison to `false`. Complements
/// `is_covering_over_the_full_set_holds_unconditionally` at the
/// OPPOSITE arm of the (partition-arm) axis: the present-arm
/// predicate reaches its `true` fixpoint at the full set; the
/// absent-arm predicate reaches its `false` fixpoint at the same
/// endpoint. Pinned by
/// `is_missing_any_over_the_full_set_is_false_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::is_missing_any(&<T as ClosedSet>::ALL.iter().chain(<T as
/// ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())` is
/// `false` UNCONDITIONALLY — appending positions to a
/// missing-none slice cannot introduce a missing variant.
/// Complements
/// `is_covering_over_the_doubled_full_set_holds_unconditionally`
/// at the OPPOSITE arm. Pinned by
/// `is_missing_any_over_the_doubled_full_set_is_false_across_every_kind`.
///
/// Reversal-invariance: `T::is_missing_any(items)` equals
/// `T::is_missing_any(items.iter().rev().copied().collect::<Vec<_>>())`
/// — reversing a slice preserves its multiset of variant
/// identities, and the any-missing predicate is a function of
/// that multiset alone. Pinned by
/// `is_missing_any_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_missing`] projection at the trait
/// level. The composition uses one `>` on `usize`, so the sweep
/// inherits [`Self::count_missing`]'s O(n(n-1)/2) cost on slice
/// arity `n` — allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against [`Self::is_missing_any`]:
/// a `tatara-check` predicate `(check-phases-cover-none-missing …)`
/// on a `WorkloadPhase` sequence that flags "some phase was
/// omitted" without paying for the miss-count when only the
/// existence of a gap matters; an LSP diagnostic on a Lisp-
/// author-written closed-set field that flags a value multiset
/// as INCOMPLETE without spelling out the count of the gap ("not
/// all severities covered" rather than "2 severities missing");
/// a Sekiban audit-trail metric flagging a classification poset
/// window as "any-classification-missed" without emitting the
/// count-side gauge; a
/// `tatara-lisp::macro_expand::Expander` hygiene pass that flags
/// a template's vocabulary as INCOMPLETE against a required
/// closed vocabulary. Each binds to ONE typed N-ary any-missing
/// predicate on the trait rather than re-deriving
/// `T::count_missing(items) > 0` or `!T::is_covering(items)`
/// inline per callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize)
/// 2×2 = 4-corner partition-arm × return-shape face on the
/// equivalence-partition surface now closes EXHAUSTIVELY at four
/// typed primitives — [`Self::count_distinct`] (present-usize),
/// [`Self::is_covering`] (present-bool: "present-count reaches
/// cardinality"), [`Self::count_missing`] (absent-usize), and
/// THIS projection (absent-bool: "absent-count is strictly
/// positive"). Post-lift the 4-corner square binds to four
/// typed substrate primitives with no unnamed inline residual on
/// any corner. The next lift on this surface — the Vec-return
/// column past the (bool, usize) columns just closed:
/// `missing_variants(items) -> Vec<Self>` (absent-Vec, the
/// concrete miss-set) with a sibling
/// `present_variants(items) -> Vec<Self>` (present-Vec, the
/// concrete hit-set) — opens a fresh return-shape axis past the
/// square that composes on [`Self::ALL`] filtered by hit/miss
/// membership.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// any-missing predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline `!T::is_
/// covering(items)` negation at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (absent-bool) corner
/// was an unnamed inline composition recurring at every
/// prospective downstream "did we miss any?" site pre-lift.
/// Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's absent-count projection
/// ([`Self::count_missing`]) compared strictly-positively to
/// `0`. THEORY.md §VI.1 — generation over composition; the
/// any-missing predicate emerges from the composition of ONE
/// substrate primitive ([`Self::count_missing`]) with a `> 0`
/// comparison on `usize`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Coq's `existsb (fun v => negb (In_dec
/// v l)) T` idiom composing an existential quantifier with a
/// membership predicate to surface the any-missing witness on a
/// decidable-equality carrier; Idris's `Data.Vect.Any :
/// (a -> Type) -> Vect n a -> Type` witness combined with a
/// slice-non-membership predicate that surfaces the same
/// projection at the type level; Rust's own
/// `T::ALL.iter().any(|v| !items.contains(v))` idiom binds
/// through a per-position linear scan on
/// `Self: Eq`. Julia's `!issubset(T, v)` on a typed vector;
/// Haskell's `not . null $ Data.List.\\ T v`. NumPy's
/// `bool(len(np.setdiff1d(T, a)))` idiom on a numeric array.
/// Translation through pleme-io primitives: the N-ary any-
/// missing predicate on the closed-set trait binds through the
/// substrate's [`Self::count_missing`] projection compared
/// strictly-positively to `0` — no new dep, no supertrait
/// bound (the [`Self::count_missing`] projection replaces the
/// `Eq`/`Hash` bound the standard-library any/setdiff signatures
/// demand), no set-shape carrier, no allocation.
fn is_missing_any(items: &[Self]) -> bool {
<Self as ClosedSet>::count_missing(items) > 0
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "occurrence count"
/// projection — the `usize` cardinality of the SET of positions of
/// `items` whose variant identity coincides with `target`, computed
/// as a per-position [`Self::index_of`] equality-filter through
/// `.count()`. The PER-TARGET USIZE-RETURN opener on the
/// (per-target × usize) MULTIPLICITY column of the equivalence-
/// partition surface, positioned as the direct PER-TARGET
/// DECOMPOSITION of the just-lifted N-ary set-level
/// [`Self::count_distinct`] projection — while
/// [`Self::count_distinct`] reports "how many DISTINCT variants
/// does the slice hit?" (a single set-level `usize`), this
/// projection reports "how many times does THIS variant appear?"
/// (a per-target `usize` that varies with `target`). Not a fresh
/// substrate primitive on the index axis — the count emerges from
/// one composition of the substrate's total-ordering discriminator
/// [`Self::index_of`] pinned as a bijection into
/// `[0, T::CARDINALITY)` by clause (16) with the standard-library
/// filter-through-count combinator.
///
/// Partition identity (multiplicity partition): for every slice
/// `items`,
/// `sum over v in T::ALL of T::count_occurrences_of(v, items) ==
/// items.len()` — the (per-target) occurrence-count multiset
/// partitions the slice's positions exactly, because every
/// position sits at EXACTLY ONE variant (the (variant → decl-slot)
/// injectivity clause (16) forces the per-position occurrence-arm
/// membership disjoint on `target`). Pinned by
/// `count_occurrences_of_summed_over_all_targets_equals_slice_length_across_every_triple`.
///
/// Multiplicity-versus-distinctness identity: for every slice
/// `items`,
/// `T::count_distinct(items) == T::ALL.iter().filter(|&&v| T::count_occurrences_of(v, items) > 0).count()`
/// — the set-level distinct count is exactly the count of TARGETS
/// whose per-target occurrence count is strictly positive. The
/// multiplicity projection SUBSUMES the distinct-count projection
/// on the (occurrence-count > 0) bool-projection column of the
/// per-target × return-shape face. Pinned by
/// `count_occurrences_of_positive_count_matches_count_distinct_across_every_triple`.
///
/// Present-arm identity (per-target membership): for every slice
/// `items` and every target `v`,
/// `T::count_occurrences_of(v, items) > 0` iff `v` appears at some
/// position of `items` — the multiplicity projection collapses
/// through the `> 0` comparison onto the per-target membership
/// predicate the ambient set's [`Self::present_variants`] Vec-
/// return witness carries. Pinned by
/// `count_occurrences_of_positive_count_matches_present_variants_membership_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because [`Self::index_of`] is a bijection into
/// `[0, T::CARDINALITY)`, so "how many positions match `target`?"
/// is the same question under EVERY ordering. Sibling posture to
/// [`Self::count_distinct`], [`Self::count_missing`],
/// [`Self::is_constant`], [`Self::is_pairwise_distinct`],
/// [`Self::is_covering`], [`Self::is_missing_any`], and
/// [`Self::is_permutation_of_all`]'s ordering-axis invariance:
/// every projection on the equivalence-partition surface is
/// direction- AND ordering-agnostic; no separate
/// `sorted_count_occurrences_of` peer is needed. Pinned by
/// `count_occurrences_of_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_occurrences_of(v, &[])` is `0`
/// for every target `v` — the empty slice hits zero positions, so
/// the filter accepts none. Sibling posture to
/// `count_distinct_returns_zero_on_the_empty_slice_across_every_kind`
/// on the collapsed set-level column: every counting projection
/// on the equivalence-partition surface reports `0` at the empty-
/// slice endpoint. Pinned by
/// `count_occurrences_of_returns_zero_on_the_empty_slice_across_every_target`.
///
/// Singleton hit contract: `T::count_occurrences_of(v, &[v])` is
/// `1` for every target `v` — a singleton slice that matches the
/// target hits it exactly once. Pinned by
/// `count_occurrences_of_returns_one_on_the_matching_singleton_across_every_target`.
///
/// Singleton miss contract: `T::count_occurrences_of(v, &[w])` is
/// `0` for every target `v` and slice-element `w != v` (compared
/// via [`Self::index_of`]) — a singleton slice at a different
/// variant misses the target. Pinned by
/// `count_occurrences_of_returns_zero_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::count_occurrences_of(v, <T as
/// ClosedSet>::ALL)` is `1` for every target `v` UNCONDITIONALLY —
/// the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins labels (and
/// hence variants) as pairwise distinct, so every variant appears
/// exactly once in [`Self::ALL`]. Pinned by
/// `count_occurrences_of_returns_one_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::count_occurrences_of(v, &<T as
/// ClosedSet>::ALL.iter().chain(<T as ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())`
/// is `2` for every target `v` UNCONDITIONALLY — the doubled full
/// set hits every variant exactly twice. Pinned by
/// `count_occurrences_of_returns_two_on_the_doubled_full_set_across_every_target`.
///
/// Repetition-monotone contract: for every slice `items` and every
/// target `v`, `T::count_occurrences_of(v, &[items, &[v][..]].concat())
/// == T::count_occurrences_of(v, items) + 1` — appending one
/// matching element increments the count by one; appending a non-
/// matching element preserves the count. Pinned by
/// `count_occurrences_of_increments_on_matching_append_across_every_target_and_variant`.
///
/// Upper-bound contract: `T::count_occurrences_of(v, items) <=
/// items.len()` on every slice and every target — the filter
/// never accepts more positions than it visits. Pinned by
/// `count_occurrences_of_is_bounded_above_by_slice_length_across_every_target_and_triple`.
///
/// Reversal-invariance: `T::count_occurrences_of(v, items)` equals
/// `T::count_occurrences_of(v, items.iter().rev().copied().collect::<Vec<_>>())`
/// for every target `v` — reversing a slice preserves its
/// multiset of variant identities, and the multiplicity of any
/// specific target is a function of that multiset alone. Pinned
/// by
/// `count_occurrences_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::index_of`] projection at the trait level.
/// The composition uses one `usize`-equality filter through
/// `.count()`, so the sweep costs O(n) on slice arity `n` —
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no bitset-shape carrier. STRICTLY BETTER
/// than [`Self::count_distinct`]'s O(n(n-1)/2) cost — the per-
/// target multiplicity projection linearizes what the set-level
/// distinct-count projection quadraticized against the first-
/// occurrence prefix sweep.
///
/// Future consumers that compose against
/// [`Self::count_occurrences_of`]: a `tatara-check` predicate
/// `(check-phase-invocation-count …)` that verifies a specific
/// `WorkloadPhase` appears EXACTLY N times in a rollout window at
/// plan time — catching a spec that would silently double-invoke
/// a phase; an LSP diagnostic on a Lisp-author-written closed-set
/// field that quantifies HOW MANY times a specific variant
/// appears in a value multiset (`":severities [:warn :warn :crit]"`
/// reports "warn: 2, crit: 1" per-variant rather than the ONE bit
/// "any repetition" that [`Self::is_pairwise_distinct`] surfaces);
/// a Sekiban audit-trail per-variant histogram bar (a "how often
/// did classification X get hit?" gauge across a window); a
/// `tatara-lisp::macro_expand::Expander` hygiene pass that
/// quantifies a template's per-identifier hit-count against a
/// required closed vocabulary; a per-slot rate limiter that reads
/// its throttle threshold as "at most K occurrences of THIS
/// variant per window". Each binds to ONE typed N-ary per-target
/// multiplicity projection on the trait rather than re-deriving
/// `items.iter().filter(|&&v| T::index_of(v) == T::index_of(target)).count()`
/// inline per callsite.
///
/// Compounding closure: the equivalence-partition surface now
/// opens the (per-target × usize) MULTIPLICITY column past the
/// (set-level × usize) + (set-level × bool) columns closed at
/// [`Self::count_distinct`] + [`Self::count_missing`] +
/// [`Self::is_covering`] + [`Self::is_missing_any`]. The next
/// natural lift on this surface — a Vec-return
/// `variant_counts(items) -> Vec<usize>` per-slot histogram whose
/// slot `i` reads `T::count_occurrences_of(T::from_index(i).unwrap(), items)`
/// — opens the (per-target-collection × Vec) column past the
/// (per-target × usize) column this lift opens. Downstream
/// consumers wanting the "mode" (variant with maximum
/// multiplicity), the "least-frequent" variant, or a full
/// histogram rendering compose on this projection through
/// [`Self::ALL`] iteration without an additional substrate
/// primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target multiplicity projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `items.iter().filter(|&&v| T::index_of(v) == T::index_of(target)).count()`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; the (per-target × usize) multiplicity
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "how many times did we hit THIS
/// variant?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's total-
/// ordering discriminator ([`Self::index_of`]) filtered through
/// the standard-library `.filter().count()` combinator.
/// THEORY.md §VI.1 — generation over composition; the per-target
/// multiplicity projection emerges from the composition of ONE
/// substrate primitive ([`Self::index_of`]) with an
/// `iter().filter().count()` combinator on slice arity `n`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `count_occ Nat.eq_dec l x` combinator
/// on `list nat` — the canonical per-target multiplicity projection
/// composing a decidable-equality predicate with a fold; Idris's
/// `Data.List.count : (a -> Bool) -> List a -> Nat` with the
/// equality predicate specialized to `\v => v == target`; Rust's
/// own `items.iter().filter(|&&v| v == target).count()` binds
/// through a `Self: PartialEq` supertrait bound; Julia's `count(==(v),
/// items)`; Python's `items.count(v)` on a `list`; NumPy's
/// `np.count_nonzero(items == v)` idiom; Haskell's
/// `length (filter (== v) items)`. Translation through pleme-io
/// primitives: the N-ary per-target multiplicity projection on
/// the closed-set trait binds through the substrate's
/// [`Self::index_of`] projection filtered on equality of the
/// target's decl-slot against the per-position decl-slot — no
/// new dep, no supertrait bound (the [`Self::index_of`]
/// projection replaces the `PartialEq` bound the standard-
/// library `count`-family signatures demand), no bitset-shape
/// carrier, no allocation.
fn count_occurrences_of(target: Self, items: &[Self]) -> usize {
let target_index = <Self as ClosedSet>::index_of(target);
items
.iter()
.filter(|&&v| <Self as ClosedSet>::index_of(v) == target_index)
.count()
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "occurs-in" membership
/// predicate — `true` iff AT LEAST ONE position of `items` carries
/// the same variant identity as `target`, computed as the just-
/// lifted usize-return [`Self::count_occurrences_of`] per-target
/// multiplicity projection strictly exceeding zero. The PER-TARGET
/// BOOL-RETURN opener on the (per-target × bool) MEMBERSHIP column
/// of the equivalence-partition surface, positioned as the direct
/// PER-TARGET DECOMPOSITION of the just-lifted N-ary set-level
/// [`Self::is_covering`] present-arm predicate one column of the
/// (per-target, set-level) arity axis over — while
/// [`Self::is_covering`] reports "does the slice HIT every
/// variant?" (a single set-level `bool`), this projection reports
/// "does the slice HIT THIS variant?" (a per-target `bool` that
/// varies with `target`). The (per-target, set-level) × (bool,
/// usize) 2×2 = 4-corner (arity × return-shape) face on the
/// equivalence-partition surface now closes the `bool` per-target
/// column at the (`bool`, per-target) corner peer to the (`usize`,
/// per-target) corner [`Self::count_occurrences_of`] opened.
///
/// Count-projection identity: for every slice `items` and every
/// target `v`,
/// `T::occurs_in(v, items) == (T::count_occurrences_of(v, items) > 0)`
/// — the per-target bool membership predicate is the (nonzero-
/// fixpoint) projection of the per-target usize multiplicity
/// count. Sibling posture to
/// `is_missing_any_holds_iff_count_missing_is_strictly_positive_across_every_triple`
/// on the COLLAPSED set-level arity axis: the set-level absent-arm
/// bool predicate is `count_missing(items) > 0`; the per-target
/// present-arm bool predicate is `count_occurrences_of(v, items) > 0`.
/// Pinned by
/// `occurs_in_holds_iff_count_occurrences_of_is_strictly_positive_across_every_target_and_triple`.
///
/// Present-arm identity (against Vec-return witness): for every
/// slice `items` and every target `v`,
/// `T::occurs_in(v, items) == T::present_variants(items).iter().any(|&w| T::index_of(w) == T::index_of(v))`
/// — the per-target bool predicate is the (per-target membership)
/// projection of the ambient set's Vec-return present-witness
/// projection. The bool-return per-target predicate SUBSUMES the
/// per-position membership sweep the Vec-return present-witness
/// projection carries. Pinned by
/// `occurs_in_matches_present_variants_membership_across_every_target_and_triple`.
///
/// Set-level composition identity: for every slice `items`,
/// `T::is_covering(items) == T::ALL.iter().all(|&v| T::occurs_in(v, items))`
/// — the set-level present-arm predicate is exactly the universal
/// quantifier over the ambient set applied to the per-target
/// present-arm predicate. This is the (per-target → set-level)
/// Kleene-star lift of the current projection back onto the
/// set-level column [`Self::is_covering`] opens. Pinned by
/// `is_covering_equals_forall_target_of_occurs_in_across_every_triple`.
///
/// Distinct-count identity: for every slice `items`,
/// `T::count_distinct(items) == T::ALL.iter().filter(|&&v| T::occurs_in(v, items)).count()`
/// — the set-level distinct count is exactly the count of TARGETS
/// whose per-target occurs-in predicate holds. Sibling posture to
/// `count_occurrences_of_positive_count_matches_count_distinct_across_every_triple`
/// on the (per-target × bool) column peer to the (per-target ×
/// usize > 0) column: both projections agree because both encode
/// the same (multiplicity > 0) fixpoint. Pinned by
/// `occurs_in_summed_over_all_targets_equals_count_distinct_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because
/// [`Self::count_occurrences_of`]'s ordering-axis invariance folds
/// through the `> 0` comparison bijectively. Sibling posture to
/// [`Self::count_distinct`], [`Self::count_missing`],
/// [`Self::count_occurrences_of`], [`Self::is_covering`],
/// [`Self::is_missing_any`], [`Self::is_uniform`], and every other
/// projection on the equivalence-partition surface: no separate
/// `sorted_occurs_in` peer is needed. Pinned by
/// `occurs_in_is_invariant_under_ordering_axis_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::occurs_in(v, &[])` is `false` for
/// every target `v` — the empty slice hits zero positions, so the
/// filter accepts none and the multiplicity is `0`, which folds
/// through the `> 0` comparison to `false`. Sibling posture to
/// `count_occurrences_of_returns_zero_on_the_empty_slice_across_every_target`
/// on the collapsed usize-return column: every membership
/// projection on the equivalence-partition surface reports `false`
/// at the empty-slice endpoint. Pinned by
/// `occurs_in_returns_false_on_the_empty_slice_across_every_target`.
///
/// Singleton hit contract: `T::occurs_in(v, &[v])` is `true` for
/// every target `v` — a singleton slice at the target hits it
/// exactly once, so the multiplicity is `1 > 0`. Pinned by
/// `occurs_in_returns_true_on_the_matching_singleton_across_every_target`.
///
/// Singleton miss contract: `T::occurs_in(v, &[w])` is `false` for
/// every target `v` and slice-element `w != v` (compared via
/// [`Self::index_of`]) — a singleton slice at a different variant
/// misses the target. Pinned by
/// `occurs_in_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::occurs_in(v, <T as ClosedSet>::ALL)` is
/// `true` for every target `v` UNCONDITIONALLY — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins labels (and hence variants) as pairwise
/// distinct, so every variant appears exactly once in
/// [`Self::ALL`], which folds through the `> 0` comparison to
/// `true`. Pinned by
/// `occurs_in_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract:
/// `T::occurs_in(v, &<T as ClosedSet>::ALL.iter().chain(<T as
/// ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())` is
/// `true` for every target `v` UNCONDITIONALLY — the doubled full
/// set hits every variant exactly twice, and `2 > 0` collapses to
/// `true`. Pinned by
/// `occurs_in_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Repetition-monotone contract: for every slice `items`, every
/// target `v`, and every appended variant `w`,
/// `T::occurs_in(v, &[items, &[w][..]].concat())` implies
/// `T::occurs_in(v, items) || T::index_of(w) == T::index_of(v)` —
/// appending an element to a slice can only introduce membership
/// (never remove it); once `occurs_in(v, items)` is `true`, no
/// append can flip it to `false`. Pinned by
/// `occurs_in_is_monotone_under_append_across_every_target_and_variant`.
///
/// Reversal-invariance: `T::occurs_in(v, items)` equals
/// `T::occurs_in(v, items.iter().rev().copied().collect::<Vec<_>>())`
/// for every target `v` — reversing a slice preserves its multiset
/// of variant identities, and the per-target membership predicate
/// is a function of that multiset alone. Pinned by
/// `occurs_in_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] projection at the
/// trait level. The composition uses one `>` on `usize`, so the
/// sweep inherits [`Self::count_occurrences_of`]'s O(n) cost on
/// slice arity `n` — allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against [`Self::occurs_in`]:
/// a `tatara-check` predicate `(check-phase-was-visited …)` that
/// verifies a specific `WorkloadPhase` appears AT LEAST ONCE in a
/// rollout window at plan time — catching a spec that would
/// silently omit a phase; an LSP diagnostic on a Lisp-author-
/// written closed-set field that flags a value multiset as NOT
/// INCLUDING a required variant ("severity :error is missing"
/// rather than the count-side "0 :error occurrences") without
/// paying for the multiplicity when only the membership matters;
/// a Sekiban audit-trail per-variant "has-hit" bit-vector (one
/// bit per variant) across a window rather than the per-variant
/// usize histogram; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the exact per-identifier "was it
/// referenced?" bool over a template's generated body against a
/// required closed vocabulary rather than a hit-count; a per-slot
/// alarm that fires when a specific variant appears at all
/// (rather than exceeds a threshold count). Each binds to ONE
/// typed N-ary per-target membership predicate on the trait rather
/// than re-deriving `T::count_occurrences_of(v, items) > 0` or
/// `items.iter().any(|&w| T::index_of(w) == T::index_of(v))`
/// inline per callsite.
///
/// Compounding closure: the (per-target, set-level) × (bool,
/// usize) 2×2 = 4-corner (arity × return-shape) face on the
/// equivalence-partition surface now closes EXHAUSTIVELY at four
/// typed primitives — [`Self::count_distinct`] (set-level, usize;
/// present-arm count), [`Self::is_covering`] (set-level, bool;
/// present-arm predicate: "present-count reaches cardinality"),
/// [`Self::count_occurrences_of`] (per-target, usize;
/// multiplicity), and THIS projection (per-target, bool;
/// membership: "multiplicity is strictly positive"). Post-lift
/// the 4-corner square binds to four typed substrate primitives
/// with no unnamed inline residual on any corner. The next lift
/// on this surface — a per-target `Option<usize>`-return
/// `first_occurrence_of(target, items) -> Option<usize>` (the
/// per-target head-position primitive) with a sibling
/// `last_occurrence_of` (per-target tail-position) — opens a
/// fresh `Option<usize>`-return column on the (per-target)
/// arity axis past the (bool, usize) columns this square closes.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target membership predicate becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::count_occurrences_of(v, items) > 0` or
/// `items.contains(&target)` composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (per-
/// target × bool) membership corner was an unnamed inline
/// composition recurring at every prospective downstream "did we
/// hit THIS variant?" site pre-lift. Naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the substrate's per-
/// target multiplicity projection ([`Self::count_occurrences_of`])
/// compared strictly-positively to `0`. THEORY.md §VI.1 —
/// generation over composition; the per-target membership
/// predicate emerges from the composition of ONE substrate
/// primitive ([`Self::count_occurrences_of`]) with a `> 0`
/// comparison on `usize`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Coq's `In v l` inductive predicate on
/// `list nat` — the canonical per-target list-membership
/// predicate composing decidable equality with a fold; Idris's
/// `Data.List.Elem : a -> List a -> Type` witness combined with
/// `isElem` decision on a decidable-equality carrier; Rust's own
/// `items.contains(&target)` binds through a `Self: PartialEq`
/// supertrait bound; Julia's `target in items`; Python's
/// `target in items` on a `list`; Haskell's `Data.List.elem
/// target items`; NumPy's `bool(np.isin(items, target).any())`
/// idiom. Translation through pleme-io primitives: the N-ary per-
/// target membership predicate on the closed-set trait binds
/// through the substrate's per-target multiplicity projection
/// [`Self::count_occurrences_of`] compared strictly-positively to
/// `0` — no new dep, no supertrait bound (the
/// [`Self::index_of`] projection [`Self::count_occurrences_of`]
/// threads through replaces the `PartialEq` bound the standard-
/// library `contains` / `elem` / `in` signatures demand), no
/// allocation.
fn occurs_in(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::count_occurrences_of(target, items) > 0
}
/// The N-ARY PER-TARGET "first occurrence position" projection —
/// `Some(i)` for the SMALLEST slice index `i` at which `items[i]`
/// carries the same variant identity as `target`, or `None` if
/// `target` does not appear. The PER-TARGET `Option<usize>`-RETURN
/// opener on the (per-target × `Option<usize>`) HEAD-POSITION column
/// of the equivalence-partition surface, positioned as the direct
/// POSITION-VALUE lift of the just-lifted bool-return
/// [`Self::occurs_in`] one return-shape axis over — while
/// [`Self::occurs_in`] reports "does the slice HIT this variant?"
/// (a per-target `bool`), this projection reports "at WHICH position
/// does the slice FIRST hit this variant?" (a per-target
/// `Option<usize>` whose `Some` arm carries the head-position and
/// whose `None` arm collapses onto [`Self::occurs_in`]'s `false`
/// arm).
///
/// Presence-composition identity: for every slice `items` and every
/// target `v`,
/// `T::first_occurrence_of(v, items).is_some() == T::occurs_in(v, items)`
/// — the `Option`'s discriminant is exactly the per-target bool
/// membership predicate, so `Some(_)` iff `occurs_in(_, _)` is
/// `true`. Pinned by
/// `first_occurrence_of_is_some_iff_occurs_in_across_every_target_and_triple`.
///
/// Count-composition identity: for every slice `items` and every
/// target `v`,
/// `T::first_occurrence_of(v, items).is_some() == (T::count_occurrences_of(v, items) > 0)`
/// — the head-position projection binds `Some` iff the multiplicity
/// is strictly positive.
///
/// Empty-slice contract: `T::first_occurrence_of(v, &[])` is `None`
/// for every target `v` — the empty slice hits zero positions, so
/// `Iterator::position` yields `None`. Pinned by
/// `first_occurrence_of_returns_none_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract:
/// `T::first_occurrence_of(v, &[v]) == Some(0)` for every target
/// `v` — the sole position hits the target. Pinned by
/// `first_occurrence_of_returns_some_zero_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract:
/// `T::first_occurrence_of(v, &[w]) == None` for every target `v`
/// and slice-element `w != v` (compared via [`Self::index_of`]).
/// Pinned by
/// `first_occurrence_of_returns_none_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract:
/// `T::first_occurrence_of(v, <T as ClosedSet>::ALL) == Some(T::index_of(v))`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// forces every variant to appear at exactly ONE position of the
/// full-set slice, and that position is precisely the variant's
/// decl-slot ([`Self::index_of`]). Pinned by clause (106) at the
/// full-set fixpoint AND by
/// `first_occurrence_of_returns_some_index_of_on_the_full_set_across_every_target`.
///
/// Upper-bound contract: for every slice `items` and every target
/// `v`,
/// `T::first_occurrence_of(v, items).map(|i| i < items.len()).unwrap_or(true)`
/// — a `Some(i)` position is a valid slice index in
/// `[0, items.len())`. Pinned by
/// `first_occurrence_of_returns_valid_slice_index_when_some_across_every_target_and_triple`.
///
/// Ordering (per-slot) contract: `T::first_occurrence_of(v, items)`
/// finds the SMALLEST valid slice index at which `items` carries a
/// variant with the same [`Self::index_of`] as `v`. At every valid
/// index `i < T::first_occurrence_of(v, items).unwrap_or(items.len())`,
/// `T::index_of(items[i]) != T::index_of(v)`. Pinned by
/// `first_occurrence_of_is_the_smallest_matching_position_across_every_target_and_triple`.
///
/// Ordering-vs-last contract:
/// `T::first_occurrence_of(v, items) <= T::last_occurrence_of(v, items)`
/// (compared under the `Option<usize>` product order: `None <=
/// None`; both `None` when target absent, both `Some` when target
/// present with `first <= last`). Pinned by
/// `first_occurrence_of_is_at_most_last_occurrence_of_across_every_target_and_triple`.
///
/// Slice-reversal contract: for every slice `items` and every
/// target `v` with `T::first_occurrence_of(v, items) == Some(i)`,
/// `T::first_occurrence_of(v, &reversed(items)) == Some(items.len() - 1 - T::last_occurrence_of(v, items).unwrap())`
/// — reversing the slice swaps first and last positions modulo
/// `items.len() - 1`. Pinned by
/// `slice_reversal_swaps_first_and_last_occurrence_of_across_every_target_and_triple`.
///
/// Signature note: the projection composes through
/// [`Iterator::position`] on the same [`Self::index_of`] discriminator
/// [`Self::count_occurrences_of`] threads through — allocation-free,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), O(n)
/// on slice arity `n` with EARLY EXIT at the first hit (strictly
/// tighter than [`Self::count_occurrences_of`]'s full-slice sweep
/// on the presence arm).
///
/// Future consumers that compose against
/// [`Self::first_occurrence_of`]: a `tatara-check` predicate
/// `(check-phase-first-position …)` that anchors the earliest slice
/// position at which a `WorkloadPhase` transitions in a rollout
/// window at plan time; an LSP diagnostic on a Lisp-author-written
/// closed-set field that flags a value multiset's HEAD-ANCHOR
/// mismatch ("severity :error first appears at position 4 rather
/// than 0") without paying for the multiplicity when only the
/// head-anchor matters; a Sekiban audit-trail per-variant "first
/// hit" timestamp anchor across a window rather than a per-variant
/// hit-count histogram; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the exact per-identifier "first bound
/// at position X" over a template's generated body against a
/// required closed vocabulary rather than a hit-count; a per-slot
/// alarm that fires at the FIRST occurrence of a specific variant
/// (rather than exceeds a threshold count). Each binds to ONE
/// typed N-ary per-target head-position primitive on the trait
/// rather than re-deriving `items.iter().position(|&w|
/// T::index_of(w) == T::index_of(target))` or the
/// `Self: PartialEq`-bound `items.iter().position(|&w| w == target)`
/// inline per callsite.
///
/// Compounding closure: the (per-target × return-shape) row on the
/// equivalence-partition surface now carries four typed corners —
/// [`Self::count_occurrences_of`] (usize; multiplicity),
/// [`Self::occurs_in`] (bool; membership), THIS projection
/// (`Option<usize>`; head-position), and its sibling
/// [`Self::last_occurrence_of`] (`Option<usize>`; tail-position)
/// one endpoint-direction axis over. The (per-target, set-level) ×
/// (bool, usize, Option<usize>) 2×3 = 6-corner (arity × return-
/// shape) block now closes the `Option<usize>`-return column at
/// the per-target arm. The next lift on this row past the
/// endpoint-anchor pair — a per-target `Vec<usize>`-return
/// `all_occurrences_of(target, items)` collecting EVERY slice
/// position of `target` — opens a fresh `Vec<usize>`-return column
/// on the (per-target) arity axis past the endpoint-anchor pair.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target head-position primitive becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `items.iter().position(…)` composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; naming the
/// (per-target × `Option<usize>` × head) corner on the trait makes
/// the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::index_of`] discriminator threaded through
/// [`Iterator::position`]. THEORY.md §VI.1 — generation over
/// composition; the head-position primitive emerges from one
/// composition ([`Iterator::position`] on [`Self::index_of`]-
/// equality) rather than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `List.find_index` derivable
/// combinator on `list nat` (the canonical per-target head-
/// position projection composing decidable equality with a fold);
/// Idris's `Data.List.findIndex : (a -> Bool) -> List a -> Maybe
/// Nat` with the equality predicate specialized to
/// `\v => v == target`; Rust's own
/// `items.iter().position(|&w| w == target)` binds through a
/// `Self: PartialEq` supertrait bound; Julia's `findfirst(==(v),
/// items)`; Python's `items.index(v)` on a `list` (with a
/// `ValueError` failure arm); Haskell's `Data.List.findIndex (==
/// v) items`. Translation through pleme-io primitives: the N-ary
/// per-target head-position projection on the closed-set trait
/// binds through [`Iterator::position`] keyed on the substrate's
/// [`Self::index_of`] projection — no new dep, no supertrait bound
/// (the [`Self::index_of`] projection replaces the `PartialEq`
/// bound the standard-library `position` / `findfirst` / `index`
/// signatures demand), no allocation.
fn first_occurrence_of(target: Self, items: &[Self]) -> Option<usize> {
let target_index = <Self as ClosedSet>::index_of(target);
items
.iter()
.position(|&v| <Self as ClosedSet>::index_of(v) == target_index)
}
/// The N-ARY PER-TARGET "last occurrence position" projection —
/// `Some(i)` for the LARGEST slice index `i` at which `items[i]`
/// carries the same variant identity as `target`, or `None` if
/// `target` does not appear. Sibling to
/// [`Self::first_occurrence_of`] one endpoint-direction axis over
/// on the (per-target × `Option<usize>` × endpoint-direction) 2-
/// corner face: [`Self::first_occurrence_of`] returns the smallest
/// matching slice index; this method returns the largest.
///
/// See [`Self::first_occurrence_of`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration — this
/// method is the tail-direction arm of the same axis and inherits
/// every property from the head arm's documentation, differing only
/// in the composition through [`Iterator::rposition`] rather than
/// [`Iterator::position`].
///
/// Presence-composition identity: for every slice `items` and every
/// target `v`,
/// `T::last_occurrence_of(v, items).is_some() == T::occurs_in(v, items)`
/// — the `Option`'s discriminant is exactly the per-target bool
/// membership predicate. Pinned by
/// `last_occurrence_of_is_some_iff_occurs_in_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::last_occurrence_of(v, &[])` is `None`
/// for every target `v`. Pinned by
/// `last_occurrence_of_returns_none_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract:
/// `T::last_occurrence_of(v, &[v]) == Some(0)`. Pinned by
/// `last_occurrence_of_returns_some_zero_on_the_matching_singleton_across_every_target`.
///
/// Full-set contract:
/// `T::last_occurrence_of(v, <T as ClosedSet>::ALL) == Some(T::index_of(v))`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// forces every variant to appear at exactly ONE position of the
/// full-set slice, so the first and last positions COINCIDE at the
/// variant's decl-slot. Pinned by clause (107) at the full-set
/// fixpoint AND by
/// `last_occurrence_of_returns_some_index_of_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract:
/// `T::last_occurrence_of(v, &doubled_full_set) == Some(T::CARDINALITY + T::index_of(v))`
/// — in the doubled slice each variant appears at TWO positions
/// (`index_of(v)` and `T::CARDINALITY + index_of(v)`), so the last-
/// position projection binds the second occurrence. Pinned by
/// `last_occurrence_of_returns_second_hit_on_the_doubled_full_set_across_every_target`.
///
/// Ordering (per-slot) contract: `T::last_occurrence_of(v, items)`
/// finds the LARGEST valid slice index at which `items` carries a
/// variant with the same [`Self::index_of`] as `v`. At every valid
/// index `i > T::last_occurrence_of(v, items).unwrap_or(0)`,
/// `T::index_of(items[i]) != T::index_of(v)`. Pinned by
/// `last_occurrence_of_is_the_largest_matching_position_across_every_target_and_triple`.
///
/// Signature note: the projection composes through
/// [`Iterator::rposition`] on the same [`Self::index_of`]
/// discriminator [`Self::count_occurrences_of`] threads through —
/// allocation-free, no supertrait bound past the trait's minimal
/// `Sized + Copy + 'static` pair, O(n) on slice arity `n` with
/// EARLY EXIT at the last hit walking from the tail.
fn last_occurrence_of(target: Self, items: &[Self]) -> Option<usize> {
let target_index = <Self as ClosedSet>::index_of(target);
items
.iter()
.rposition(|&v| <Self as ClosedSet>::index_of(v) == target_index)
}
/// The N-ARY PER-TARGET "all occurrence positions" projection —
/// the `Vec<usize>` of EVERY slice index at which `items[i]`
/// carries the same variant identity as `target`, in strictly
/// ascending slice-order. The PER-TARGET `Vec<usize>`-RETURN
/// opener on the (per-target × `Vec<usize>`) EVERY-POSITION column
/// of the equivalence-partition surface, positioned as the direct
/// VEC-LIFT of the just-lifted endpoint-anchor pair
/// [`Self::first_occurrence_of`] + [`Self::last_occurrence_of`]
/// one return-shape axis over — while those two projections report
/// the SMALLEST and LARGEST matching slice indices (a per-target
/// `Option<usize>` singleton at either endpoint of the matching
/// index set), THIS projection reports the ENTIRE matching index
/// set (a per-target `Vec<usize>` of every matching slice index).
/// The (per-target × return-shape) row on the equivalence-
/// partition surface now carries five typed corners:
/// [`Self::count_occurrences_of`] (usize; multiplicity),
/// [`Self::occurs_in`] (bool; membership),
/// [`Self::first_occurrence_of`] (`Option<usize>`; head-position),
/// [`Self::last_occurrence_of`] (`Option<usize>`; tail-position),
/// and THIS projection (`Vec<usize>`; every-position).
///
/// Length-composition identity: for every slice `items` and every
/// target `v`,
/// `T::all_occurrences_of(v, items).len() == T::count_occurrences_of(v, items)`
/// — the vector's length is exactly the per-target multiplicity,
/// because the filter accepts precisely those slice positions
/// whose variant identity matches the target. Pinned by
/// `all_occurrences_of_len_equals_count_occurrences_of_across_every_target_and_triple`.
///
/// Presence-composition identity: for every slice `items` and
/// every target `v`,
/// `!T::all_occurrences_of(v, items).is_empty() == T::occurs_in(v, items)`
/// — the vector's non-emptiness is exactly the per-target
/// membership predicate. Pinned by clause (108)'s doubled-full-
/// set arm.
///
/// Head-composition identity: for every slice `items` and every
/// target `v`,
/// `T::all_occurrences_of(v, items).first().copied() == T::first_occurrence_of(v, items)`
/// — the vector's head element is exactly the smallest matching
/// slice index, coinciding with the head-endpoint projection.
/// Pinned by
/// `all_occurrences_of_first_equals_first_occurrence_of_across_every_target_and_triple`.
///
/// Tail-composition identity: for every slice `items` and every
/// target `v`,
/// `T::all_occurrences_of(v, items).last().copied() == T::last_occurrence_of(v, items)`
/// — the vector's tail element is exactly the largest matching
/// slice index, coinciding with the tail-endpoint projection.
/// Pinned by
/// `all_occurrences_of_last_equals_last_occurrence_of_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::all_occurrences_of(v, &[])` is the
/// empty vector for every target `v` — the empty slice hits zero
/// positions, so the filter accepts nothing. Pinned by clause
/// (108)'s empty-slice fixpoint arm.
///
/// Full-set contract:
/// `T::all_occurrences_of(v, <T as ClosedSet>::ALL) == vec![T::index_of(v)]`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// forces every variant to appear at exactly ONE position of the
/// full-set slice, at slot `T::index_of(v)`. Pinned by clause
/// (108)'s full-set fixpoint arm.
///
/// Doubled-full-set contract:
/// `T::all_occurrences_of(v, &doubled_full_set) == vec![T::index_of(v), T::CARDINALITY + T::index_of(v)]`
/// UNCONDITIONALLY — in the doubled slice each variant appears at
/// EXACTLY TWO positions, and the ascending-order contract pins
/// the head hit at `T::index_of(v)` and the tail hit at
/// `T::CARDINALITY + T::index_of(v)`. Pinned by clause (108)'s
/// doubled-full-set arm.
///
/// Strictly-increasing contract: for every slice `items` and
/// every target `v`, adjacent elements of
/// `T::all_occurrences_of(v, items)` are STRICTLY INCREASING —
/// no matching slice index is repeated because
/// [`Iterator::enumerate`] threads a fresh index per position.
/// Pinned by
/// `all_occurrences_of_is_strictly_increasing_across_every_target_and_triple`.
///
/// Positional-correctness contract: for every slice `items`,
/// every target `v`, and every returned index `i` in
/// `T::all_occurrences_of(v, items)`, `i < items.len()` AND
/// `T::index_of(items[i]) == T::index_of(v)` — every returned
/// index is a valid slice index at which `items` carries the
/// target's variant identity. Pinned by
/// `all_occurrences_of_positions_all_match_across_every_target_and_triple`.
///
/// Partition identity: for every slice `items`,
/// `T::ALL.iter().map(|v| T::all_occurrences_of(v, items).len()).sum::<usize>() == items.len()`
/// — the per-target index sets partition the slice's positions
/// exactly, because every position sits at EXACTLY ONE variant
/// (the (variant → decl-slot) injectivity clause (16) forces the
/// per-position occurrence-arm membership disjoint on `target`).
/// Pinned by
/// `all_occurrences_of_summed_over_all_targets_equals_slice_length_across_every_triple`.
///
/// Signature note: the projection composes through
/// [`Iterator::enumerate`] + [`Iterator::filter`] + [`Iterator::map`]
/// on the same [`Self::index_of`] discriminator
/// [`Self::count_occurrences_of`] / [`Self::first_occurrence_of`]
/// / [`Self::last_occurrence_of`] thread through — one allocation
/// for the returned `Vec<usize>` bounded above by `items.len()`,
/// no supertrait bound past the trait's minimal `Sized + Copy +
/// 'static` pair, O(n) on slice arity `n` with NO early exit
/// (the every-position column REQUIRES a full-slice sweep, unlike
/// the endpoint-anchor pair's head- and tail-exit).
///
/// Compounding closure: the (per-target × return-shape) row on
/// the equivalence-partition surface now closes at the
/// `Vec<usize>`-return column past the `Option<usize>`-return
/// endpoint-anchor pair — every future downstream site that needs
/// "at which slice positions does this variant appear?" (a
/// tatara-check predicate reporting the full per-variant index
/// list rather than a head/tail anchor; a Sekiban audit-trail
/// per-variant position-vector across a rollout window; a
/// tatara-lisp macro-expander hygiene pass reporting every
/// per-identifier binding position rather than just the first; a
/// per-slot alarm firing on ANY occurrence of a specific variant
/// with the full position list attached) binds to ONE typed N-ary
/// per-target every-position primitive on the trait rather than
/// re-deriving
/// `items.iter().enumerate().filter(|&(_, &w)| T::index_of(w) == T::index_of(target)).map(|(i, _)| i).collect()`
/// or the `Self: PartialEq`-bound
/// `items.iter().enumerate().filter(|&(_, &w)| w == target).map(|(i, _)| i).collect()`
/// inline per callsite. The natural next lift past this every-
/// position corner is the per-target `bool` "is-mono-occurrence"
/// predicate `is_unique_occurrence_of(target, items) ==
/// T::count_occurrences_of(target, items) == 1` or the set-level
/// bool "every-variant-mono" predicate `is_multiset_slice(items)
/// == T::variant_counts(items).iter().all(|&c| c <= 1)`, each
/// opening a fresh (per-target × bool × multiplicity-shape) or
/// (set-level × bool × multiplicity-shape) corner past the
/// membership arm on the equivalence-partition surface.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target every-position primitive becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `items.iter().enumerate().filter(…).map(|(i, _)| i).collect()`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; naming the (per-target × `Vec<usize>`)
/// every-position corner on the trait makes the projection a
/// TYPED CONSEQUENCE of the substrate's [`Self::index_of`]
/// discriminator threaded through
/// [`Iterator::enumerate`] + [`Iterator::filter`] + [`Iterator::map`].
/// THEORY.md §VI.1 — generation over composition; the every-
/// position primitive emerges from one composition
/// (`enumerate().filter().map()` on [`Self::index_of`]-equality),
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `List.find_all_indices` (a decidable-
/// equality-derived every-position combinator on `list nat`);
/// Idris's `Data.List.findIndices : (a -> Bool) -> List a -> List
/// Nat` with the predicate specialized to `\v => v == target`;
/// Haskell's `Data.List.findIndices (== v) items :: [Int]`; Rust's
/// own `items.iter().enumerate().filter(|&(_, &w)| w == target).map(|(i, _)| i).collect::<Vec<_>>()`
/// idiom which binds through a `Self: PartialEq` supertrait bound;
/// Julia's `findall(==(v), items)`; Python's
/// `[i for i, w in enumerate(items) if w == v]` list comprehension;
/// NumPy's `np.flatnonzero(items == v)` or `np.where(items == v)[0]`
/// idiom. Translation through pleme-io primitives: the N-ary
/// per-target every-position projection on the closed-set trait
/// binds through `enumerate().filter().map()` keyed on the
/// substrate's [`Self::index_of`] projection — no new dep, no
/// supertrait bound (the [`Self::index_of`] projection replaces
/// the `PartialEq` bound the standard-library `findIndices` /
/// `findall` signatures demand), one allocation for the returned
/// `Vec<usize>` bounded above by `items.len()`.
fn all_occurrences_of(target: Self, items: &[Self]) -> ::std::vec::Vec<usize> {
let target_index = <Self as ClosedSet>::index_of(target);
items
.iter()
.copied()
.enumerate()
.filter(|&(_, v)| <Self as ClosedSet>::index_of(v) == target_index)
.map(|(i, _)| i)
.collect()
}
/// The N-ARY PER-TARGET "occurrence endpoint pair" projection —
/// `Some((first, last))` for the SMALLEST + LARGEST slice indices
/// at which `items` carries the same variant identity as `target`,
/// or `None` if `target` does not appear. The PER-TARGET
/// `Option<(usize, usize)>`-RETURN opener on the (per-target ×
/// `Option<(usize, usize)>`) ENDPOINT-PAIR column of the
/// equivalence-partition surface, positioned as the direct PAIR-
/// PACKAGED lift of the just-lifted
/// [`Self::first_occurrence_of`] + [`Self::last_occurrence_of`]
/// endpoint-anchor pair — while
/// the endpoint-anchor pair reports the head- and tail-position
/// across TWO separate `Option<usize>` returns, this projection
/// packages both endpoints into ONE atomic `Option<(usize, usize)>`
/// return via `Option::zip` on the two endpoint-anchor primitives.
/// Sibling posture to [`Self::variant_count_range`] one arity axis
/// over: the set-level projection returns `(usize, usize)` =
/// `(min_variant_count, max_variant_count)` of the histogram bars;
/// the per-target projection returns `Option<(usize, usize)>` =
/// the (head-position, tail-position) endpoint pair of a target's
/// slice occurrences. The (per-target × return-shape) row on the
/// equivalence-partition surface now closes the pair-return
/// column at the (`Option<(usize, usize)>`, per-target) corner
/// peer to the (`Vec<usize>`, per-target) corner
/// [`Self::all_occurrences_of`] just opened.
///
/// Presence-composition identity: for every slice `items` and every
/// target `v`,
/// `T::occurrence_endpoints_of(v, items).is_some() == T::occurs_in(v, items)`
/// — the `Option`'s discriminant is exactly the per-target bool
/// membership predicate, so `Some(_)` iff `occurs_in(_, _)` is
/// `true`. `Option::zip` returns `Some((_, _))` iff BOTH inputs
/// are `Some`, and the two endpoint-anchor primitives have
/// coincident presence-discriminants (both `Some` iff the target
/// appears at all), so the pair's `Some` arm coincides with the
/// bool membership predicate exactly. Pinned by
/// `occurrence_endpoints_of_is_some_iff_occurs_in_across_every_target_and_triple`.
///
/// Endpoint-pair composition identity: for every slice `items` and
/// every target `v`,
/// `T::occurrence_endpoints_of(v, items) == T::first_occurrence_of(v, items).zip(T::last_occurrence_of(v, items))`
/// — the pair-return is the direct `Option::zip` of the two
/// endpoint-anchor projections. Pinned by clause (109)'s
/// composition-equality arms + by
/// `occurrence_endpoints_of_equals_zip_of_first_and_last_occurrence_of_across_every_target_and_triple`.
///
/// Head-projection identity: for every slice `items` and every
/// target `v`,
/// `T::occurrence_endpoints_of(v, items).map(|(f, _)| f) == T::first_occurrence_of(v, items)`
/// — the first component of the pair equals the head-endpoint.
/// Pinned by
/// `occurrence_endpoints_of_head_equals_first_occurrence_of_across_every_target_and_triple`.
///
/// Tail-projection identity: for every slice `items` and every
/// target `v`,
/// `T::occurrence_endpoints_of(v, items).map(|(_, l)| l) == T::last_occurrence_of(v, items)`
/// — the second component of the pair equals the tail-endpoint.
/// Pinned by
/// `occurrence_endpoints_of_tail_equals_last_occurrence_of_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::occurrence_endpoints_of(v, &[])` is
/// `None` for every target `v` — the empty slice hits zero
/// positions, so both endpoint-anchor primitives yield `None`,
/// and `Option::zip` collapses to `None`. Pinned by clause (109)
/// and by
/// `occurrence_endpoints_of_returns_none_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract:
/// `T::occurrence_endpoints_of(v, &[v]) == Some((0, 0))` for
/// every target `v` — the sole position hits the target, so both
/// endpoint-anchor primitives yield `Some(0)`, and `Option::zip`
/// packages them as `Some((0, 0))`. Pinned by
/// `occurrence_endpoints_of_returns_some_zero_zero_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract:
/// `T::occurrence_endpoints_of(v, &[w]) == None` for every target
/// `v` and slice-element `w != v` (compared via
/// [`Self::index_of`]). Pinned by
/// `occurrence_endpoints_of_returns_none_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract:
/// `T::occurrence_endpoints_of(v, <T as ClosedSet>::ALL) ==
/// Some((T::index_of(v), T::index_of(v)))` UNCONDITIONALLY —
/// clause (3)'s pairwise-distinctness invariant forces every
/// variant to appear at exactly ONE position of the full-set
/// slice, so both endpoints coincide at that position. Pinned by
/// clause (109) at the full-set fixpoint AND by
/// `occurrence_endpoints_of_returns_index_of_pair_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract:
/// `T::occurrence_endpoints_of(v, &[T::ALL, T::ALL].concat()) ==
/// Some((T::index_of(v), T::CARDINALITY + T::index_of(v)))`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// exactly TWO positions, and the (head, tail) pair spans the two
/// copies. The doubled-full-set arm is the ONLY canonical fixpoint
/// arm that separates the (first, last) direction axis (on the
/// full set alone the two coincide), catching an override that
/// swaps the pair components or drops one of them. Pinned by
/// clause (109) and by
/// `occurrence_endpoints_of_returns_head_tail_pair_on_the_doubled_full_set_across_every_target`.
///
/// First ≤ Second contract: for every slice `items` and every
/// target `v`, `T::occurrence_endpoints_of(v, items)` on the
/// `Some((f, l))` arm satisfies `f <= l` — the head-position
/// (`Iterator::position`) always precedes the tail-position
/// (`Iterator::rposition`) on the same slice, and they coincide
/// exactly on singleton-hit slices. Pinned by clause (109) and by
/// `occurrence_endpoints_of_first_bounded_above_by_second_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis on `T::ALL`
/// COLLAPSES on element equality because the head- and tail-
/// endpoint primitives fold through `Iterator::position` /
/// `Iterator::rposition` on `index_of`-equality bijectively.
/// Sibling posture to every projection on the equivalence-
/// partition surface: no separate `sorted_occurrence_endpoints_of`
/// peer is needed.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::first_occurrence_of`] + [`Self::last_occurrence_of`]
/// via `Option::zip`. The sweep cost inherits the endpoint-anchor
/// pair: two O(n) scans with EARLY EXIT at the head- and tail-
/// hits respectively, no allocation, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::occurrence_endpoints_of`]: a `tatara-check` predicate
/// `(check-phase-visit-window …)` reporting the (first-visited,
/// last-visited) slice window for a specific `WorkloadPhase` in
/// ONE atomic pair rather than two separate head/tail queries; a
/// Sekiban audit-trail per-variant endpoint-pair record across a
/// rollout window; a `tatara-lisp::macro_expand::Expander` hygiene
/// pass reporting the (first-reference, last-reference) position
/// pair for an identifier's usage span; a per-slot alarm firing
/// on the (first-seen, last-seen) window of a specific variant.
/// Each binds to ONE typed N-ary per-target endpoint-pair
/// primitive on the trait rather than re-deriving
/// `T::first_occurrence_of(v, items).zip(T::last_occurrence_of(v, items))`
/// inline per callsite.
///
/// Compounding closure: the (per-target × return-shape) row on
/// the equivalence-partition surface now carries SIX typed
/// primitives — [`Self::count_occurrences_of`] (usize;
/// multiplicity), [`Self::occurs_in`] (bool; membership),
/// [`Self::first_occurrence_of`] (Option<usize>; head-position),
/// [`Self::last_occurrence_of`] (Option<usize>; tail-position),
/// [`Self::all_occurrences_of`] (Vec<usize>; every-position),
/// and THIS projection (Option<(usize, usize)>; endpoint-pair) —
/// closing the pair-return column on the per-target arity axis
/// past the five prior return-shape columns.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target endpoint-pair primitive becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::first_occurrence_of(v, items).zip(T::last_occurrence_of(v, items))`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; naming the (per-target ×
/// `Option<(usize, usize)>`) endpoint-pair column on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// two endpoint-anchor primitives packaged as one atomic
/// `Option::zip`. THEORY.md §VI.1 — generation over composition;
/// the endpoint-pair primitive emerges from one composition
/// (`Option::zip` on the two endpoint-anchor projections), not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `Option.bind (find_first eqb l) (fun f => Option.map (fun l => (f, l)) (find_last eqb l))`
/// pair-lift on `list nat`; Idris's `MonadZip` combinator
/// `Data.List.findIndex <*> Data.List.findLastIndex` lifting into
/// `Maybe (Nat, Nat)`; Julia's `let ps = findall(==(v), items);
/// isempty(ps) ? nothing : (first(ps), last(ps))` idiom; Rust's
/// own `items.iter().position(|&w| w == v).zip(items.iter().rposition(|&w| w == v))`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `try: return (items.index(v), len(items) - 1 - items[::-1].index(v))
/// except ValueError: return None` idiom; Haskell's `liftA2 (,)
/// (findIndex (== v) items) (fmap (\is -> last is) (nonEmptyIndices (== v) items))`.
/// Translation through pleme-io primitives: the N-ary per-target
/// endpoint-pair projection on the closed-set trait binds
/// through `Option::zip` on the substrate's two endpoint-anchor
/// projections — no new dep, no supertrait bound (the
/// [`Self::index_of`] projection the two endpoint-anchor
/// primitives thread through replaces the `PartialEq` bound the
/// standard-library `position`+`rposition`+`zip` signature chain
/// demands), no allocation, EARLY EXIT at both endpoints
/// inherited from the endpoint-anchor pair.
fn occurrence_endpoints_of(target: Self, items: &[Self]) -> Option<(usize, usize)> {
<Self as ClosedSet>::first_occurrence_of(target, items)
.zip(<Self as ClosedSet>::last_occurrence_of(target, items))
}
/// The N-ARY ORDERING-AGNOSTIC "per-target endpoint-span"
/// projection — the `Option<usize>` slot-difference reduction of
/// the [`Self::occurrence_endpoints_of`] endpoint-pair corner
/// (`Some(l - f)` on the `Some((f, l))` arm, `None` when the
/// target does not appear). The PER-TARGET `Option<usize>`-RETURN
/// SCALAR-DIFFERENCE REDUCTION opener on the (per-target ×
/// `Option<usize>` scalar-difference) column of the equivalence-
/// partition surface, positioned as the direct SCALAR-DIFFERENCE
/// projection of the just-lifted [`Self::occurrence_endpoints_of`]
/// pair-return corner. Sibling posture to
/// [`Self::variant_count_span`] one arity axis over: the set-level
/// projection returns `usize` = `max_variant_count -
/// min_variant_count` = the scalar-difference reduction of the
/// (min-bar, max-bar) direction pair via `Self::variant_count_range`;
/// the per-target projection returns `Option<usize>` = `l - f` =
/// the scalar-difference reduction of the (head, tail) endpoint
/// pair via `Self::occurrence_endpoints_of`. Both share the same
/// abstract shape "reduce a pair-return corner through slot-
/// subtraction to a scalar" but on different arities of the same
/// substrate — the set-level column reduces the (min-bar, max-bar)
/// direction pair; the per-target column reduces the (head, tail)
/// endpoint pair. The (per-target × return-shape) row on the
/// equivalence-partition surface now closes the `Option<usize>`
/// scalar-difference column at the (`Option<usize>`, per-target,
/// scalar-difference) corner peer to the (`Option<(usize, usize)>`,
/// per-target, pair) corner [`Self::occurrence_endpoints_of`]
/// just opened.
///
/// Presence-composition identity: for every slice `items` and every
/// target `v`,
/// `T::occurrence_span_of(v, items).is_some() == T::occurs_in(v, items)`
/// — the `Option`'s discriminant coincides with the per-target
/// bool membership predicate because `Option::map` preserves the
/// discriminant of its input, and `T::occurrence_endpoints_of`'s
/// `Some` arm already coincides with `T::occurs_in`. Pinned by
/// `occurrence_span_of_is_some_iff_occurs_in_across_every_target_and_triple`.
///
/// Endpoint-pair composition identity: for every slice `items` and
/// every target `v`,
/// `T::occurrence_span_of(v, items) == T::occurrence_endpoints_of(v, items).map(|(f, l)| l - f)`
/// — the scalar-difference return is the direct `Option::map` of
/// the pair-return through slot-subtraction. Pinned by clause (110)
/// and by
/// `occurrence_span_of_equals_map_of_occurrence_endpoints_of_slot_subtraction_across_every_target_and_triple`.
///
/// Endpoint-anchor composition identity: for every slice `items` and
/// every target `v`,
/// `T::occurrence_span_of(v, items) == T::first_occurrence_of(v, items).zip(T::last_occurrence_of(v, items)).map(|(f, l)| l - f)`
/// — the scalar-difference return equally composes through the two
/// endpoint-anchor primitives directly, bypassing the pair-return
/// corner. Pinned by
/// `occurrence_span_of_equals_zip_of_first_and_last_occurrence_of_slot_subtraction_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::occurrence_span_of(v, &[])` is `None`
/// for every target `v` — the empty slice hits zero positions, so
/// the pair-return corner yields `None`, and `Option::map` on
/// `None` collapses to `None`. Pinned by clause (110) and by
/// `occurrence_span_of_returns_none_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::occurrence_span_of(v, &[v]) ==
/// Some(0)` for every target `v` — the sole position hits the
/// target, the pair-return corner yields `Some((0, 0))`, and the
/// slot-subtraction reduction collapses to `Some(0 - 0) ==
/// Some(0)`. Pinned by
/// `occurrence_span_of_returns_some_zero_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract: `T::occurrence_span_of(v, &[w])
/// == None` for every target `v` and slice-element `w` with
/// `T::index_of(v) != T::index_of(w)`. Pinned by
/// `occurrence_span_of_returns_none_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::occurrence_span_of(v, <T as ClosedSet>::ALL)
/// == Some(0)` UNCONDITIONALLY — clause (3)'s pairwise-distinctness
/// invariant forces every variant to appear at exactly ONE position
/// of the full-set slice, so the pair-return corner yields
/// `Some((i, i))` where `i == T::index_of(v)`, and the slot-
/// subtraction reduction collapses to `Some(i - i) == Some(0)`.
/// Pinned by clause (110) at the full-set fixpoint AND by
/// `occurrence_span_of_returns_some_zero_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::occurrence_span_of(v, &[T::ALL,
/// T::ALL].concat()) == Some(T::CARDINALITY)` UNCONDITIONALLY —
/// the doubled full set hits every variant at exactly TWO positions
/// spanning the two copies (`i` and `T::CARDINALITY + i`), so the
/// pair-return corner yields `Some((i, T::CARDINALITY + i))`, and
/// the slot-subtraction reduction collapses to
/// `Some((T::CARDINALITY + i) - i) == Some(T::CARDINALITY)`. The
/// doubled-full-set arm is LOAD-BEARING — it is the ONLY canonical
/// fixpoint arm that separates the scalar-difference reduction
/// from a `_ => Some(0)` degenerate override (on empty, full, and
/// matching-singleton fixpoints both the correct and the drifted
/// override coincide on the `Some(0)` / `None` payload). Pinned by
/// clause (110) and by
/// `occurrence_span_of_returns_some_cardinality_on_the_doubled_full_set_across_every_target`.
///
/// Slice-length upper bound: for every slice `items` and every
/// target `v`, `T::occurrence_span_of(v, items).unwrap_or(0) <
/// items.len()` on non-empty slices (equivalently: `Some(s)` with
/// `s < items.len()`), because the (head, tail) endpoint pair lies
/// entirely in `0..items.len()`. Pinned by
/// `occurrence_span_of_is_bounded_above_by_slice_length_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis on `T::ALL`
/// COLLAPSES on element equality because it factors through the
/// endpoint-pair corner (itself ordering-agnostic) via
/// `Option::map`. Sibling posture to every projection on the
/// equivalence-partition surface: no separate
/// `sorted_occurrence_span_of` peer is needed.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::occurrence_endpoints_of`] via `Option::map` on slot-
/// subtraction. The sweep cost inherits the endpoint-pair corner:
/// two O(n) scans with EARLY EXIT at the head- and tail-hits
/// respectively, no allocation, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::occurrence_span_of`]: a `tatara-check` predicate
/// `(check-phase-visit-span …)` reporting the position-count
/// spread between first- and last-visited slots for a specific
/// `WorkloadPhase` in ONE atomic scalar rather than a pair-and-
/// then-subtract composition; a Sekiban audit-trail per-variant
/// scalar-span record across a rollout window; a
/// `tatara-lisp::macro_expand::Expander` hygiene pass reporting
/// the (first-reference to last-reference) usage-window width for
/// an identifier in ONE typed scalar rather than a pair-and-then-
/// subtract composition. Each binds to ONE typed N-ary per-target
/// scalar-difference primitive on the trait rather than re-
/// deriving `T::occurrence_endpoints_of(v, items).map(|(f, l)| l - f)`
/// inline per callsite.
///
/// Compounding closure: the (per-target × return-shape) row on
/// the equivalence-partition surface now carries SEVEN typed
/// primitives — [`Self::count_occurrences_of`] (usize;
/// multiplicity), [`Self::occurs_in`] (bool; membership),
/// [`Self::first_occurrence_of`] (Option<usize>; head-position),
/// [`Self::last_occurrence_of`] (Option<usize>; tail-position),
/// [`Self::all_occurrences_of`] (Vec<usize>; every-position),
/// [`Self::occurrence_endpoints_of`] (Option<(usize, usize)>;
/// endpoint-pair), and THIS projection (Option<usize>; endpoint-
/// span scalar-difference) — closing the `Option<usize>` scalar-
/// difference column on the per-target arity axis past the six
/// prior return-shape columns. Cross-arity peer to
/// [`Self::variant_count_span`] (set-level scalar-difference of the
/// (min-bar, max-bar) direction pair) — the (arity, scalar-
/// difference) 2×2 = 4-corner face now closes at both arity
/// columns.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target scalar-difference primitive becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::occurrence_endpoints_of(v, items).map(|(f, l)| l - f)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; naming the (per-target × `Option<usize>`)
/// scalar-difference column on the trait makes the projection a
/// TYPED CONSEQUENCE of the substrate's endpoint-pair primitive
/// packaged as one atomic `Option::map` on slot-subtraction.
/// THEORY.md §VI.1 — generation over composition; the scalar-
/// difference primitive emerges from one composition (`Option::map`
/// on the pair-return corner through slot-subtraction), not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `Option.map (fun '(f, l) => l - f)
/// (find_first_and_last eqb l)` scalar-difference lift on
/// `list nat`; Idris's `Data.List.findIndex <$> pairSubtract` idiom
/// on `Maybe (Nat, Nat)`; Julia's `let ps = findall(==(v), items);
/// isempty(ps) ? nothing : last(ps) - first(ps)` scalar reduction;
/// Rust's own `items.iter().position(|&w| w == v).zip(items.iter().rposition(|&w| w == v)).map(|(f, l)| l - f)`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `try: return items[::-1].index(v) + items.index(v) - len(items) + 1
/// except ValueError: return None` idiom composing head + tail via
/// arithmetic; Haskell's `(-) <$> findLastIndex (== v) items <*>
/// findIndex (== v) items` applicative-style. Translation through
/// pleme-io primitives: the N-ary per-target scalar-difference
/// projection on the closed-set trait binds through `Option::map`
/// on the substrate's endpoint-pair primitive's slot-subtraction —
/// no new dep, no supertrait bound (the [`Self::index_of`]
/// projection the endpoint-pair primitive already threads through
/// replaces the `PartialEq` bound the standard-library `position` +
/// `rposition` + `zip` + `map` signature chain demands), no
/// allocation, EARLY EXIT at both endpoints inherited from the
/// endpoint-pair corner underneath.
fn occurrence_span_of(target: Self, items: &[Self]) -> Option<usize> {
<Self as ClosedSet>::occurrence_endpoints_of(target, items).map(|(f, l)| l - f)
}
/// The N-ARY ORDERING-AGNOSTIC "per-target multiplicity-1"
/// predicate — the `bool` per-target UNIQUENESS test whose value
/// coincides with `T::count_occurrences_of(target, items) == 1`,
/// i.e. `true` iff the target appears EXACTLY ONCE in `items`.
/// The PER-TARGET `bool`-RETURN MULTIPLICITY-BAND CLOSER on the
/// (per-target × bool) column of the equivalence-partition surface,
/// positioned as the direct MULTIPLICITY-BAND projection of the
/// just-lifted usize-return [`Self::count_occurrences_of`] per-
/// target multiplicity primitive, one MULTIPLICITY-BAND axis over
/// from the (per-target × bool) MULTIPLICITY-POSITIVE corner
/// [`Self::occurs_in`]: while [`Self::occurs_in`] reports "does
/// the slice HIT this variant at least ONCE?" (multiplicity-band
/// `> 0`), this projection reports "does the slice HIT this
/// variant EXACTLY ONCE?" (multiplicity-band `== 1`). The (per-
/// target × bool × multiplicity-band) 2-corner face on the
/// equivalence-partition surface now closes at the (bool, per-
/// target, `== 1`) corner peer to the (bool, per-target, `> 0`)
/// corner [`Self::occurs_in`] opened.
///
/// Count-composition identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_occurrence_of(v, items) == (T::count_occurrences_of(v, items) == 1)`
/// — the bool predicate is EXACTLY the strict-equality test of
/// the per-target multiplicity primitive against `1`. Pinned by
/// clause (111) and by
/// `is_unique_occurrence_of_holds_iff_count_occurrences_of_equals_one_across_every_target_and_triple`.
///
/// Presence-and-non-repeat composition identity: for every slice
/// `items` and every target `v`,
/// `T::is_unique_occurrence_of(v, items) == (T::occurs_in(v, items) && T::count_occurrences_of(v, items) < 2)`
/// — the strict-equality-against-1 test factors through the
/// (multiplicity `> 0`) membership predicate conjoined with the
/// (multiplicity `< 2`) non-repeat predicate. Pinned by
/// `is_unique_occurrence_of_equals_occurs_in_and_count_less_than_two_across_every_target_and_triple`.
///
/// Every-position composition identity: for every slice `items`
/// and every target `v`,
/// `T::is_unique_occurrence_of(v, items) == (T::all_occurrences_of(v, items).len() == 1)`
/// — the strict-equality-against-1 test factors through the
/// every-position vec's length arm. Pinned by
/// `is_unique_occurrence_of_holds_iff_all_occurrences_of_len_equals_one_across_every_target_and_triple`.
///
/// Endpoint-coincidence composition identity: for every slice
/// `items` and every target `v`,
/// `T::is_unique_occurrence_of(v, items) == (T::occurrence_span_of(v, items) == Some(0) && T::occurs_in(v, items))`
/// — a unique occurrence pins the `(head, tail)` endpoint pair at
/// coincident slots (span `0`), and any hit on a non-empty slice
/// with zero span means exactly one occurrence; the `Some(0)`
/// arm on the empty slice collapses to `None` on the discriminant,
/// so the membership conjunct is load-bearing. Pinned by
/// `is_unique_occurrence_of_equals_span_zero_and_occurs_in_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_unique_occurrence_of(v, &[])` is
/// `false` for every target `v` — the empty slice hits zero
/// positions, so the per-target multiplicity is `0` and the
/// strict-equality test against `1` fails. Pinned by clause (111)
/// and by
/// `is_unique_occurrence_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::is_unique_occurrence_of(v,
/// &[v]) == true` for every target `v` — the sole position hits
/// the target with multiplicity `1`, so the strict-equality test
/// against `1` holds. Pinned by
/// `is_unique_occurrence_of_returns_true_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract: `T::is_unique_occurrence_of(v,
/// &[w]) == false` for every target `v` and slice-element `w`
/// with `T::index_of(v) != T::index_of(w)` — the per-target
/// multiplicity is `0` at the target, and the strict-equality
/// test against `1` fails. Pinned by
/// `is_unique_occurrence_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::is_unique_occurrence_of(v, <T as
/// ClosedSet>::ALL) == true` UNCONDITIONALLY — clause (3)'s
/// pairwise-distinctness invariant forces every variant to appear
/// at EXACTLY ONE position of the full-set slice, so the per-
/// target multiplicity is `1` and the strict-equality test holds
/// at every target. Pinned by clause (111) at the full-set
/// fixpoint AND by
/// `is_unique_occurrence_of_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::is_unique_occurrence_of(v,
/// &[T::ALL, T::ALL].concat()) == false` UNCONDITIONALLY — the
/// doubled full set hits every variant at EXACTLY TWO positions,
/// so the per-target multiplicity is `2` and the strict-equality
/// test against `1` fails at every target. The doubled-full-set
/// arm is LOAD-BEARING — it is the ONLY canonical fixpoint arm
/// that separates the strict-equality-against-1 test from the
/// weaker (multiplicity `> 0`) membership predicate: on empty,
/// matching-singleton, non-matching-singleton, and full-set
/// fixpoints the two coincide (both `false` on empty and non-
/// matching-singleton, both `true` on matching-singleton and
/// full-set); only the doubled-full-set arm distinguishes them
/// (`false` under the strict-equality test, `true` under the
/// weaker membership predicate). Pinned by clause (111) at the
/// doubled-full-set fixpoint AND by
/// `is_unique_occurrence_of_returns_false_on_the_doubled_full_set_across_every_target`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis on `T::ALL`
/// COLLAPSES on this predicate because it factors through
/// [`Self::count_occurrences_of`] (itself ordering-agnostic) via
/// a scalar-equality test. Sibling posture to every projection
/// on the equivalence-partition surface: no separate
/// `sorted_is_unique_occurrence_of` peer is needed.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_occurrences_of`] via strict-equality against `1`.
/// The sweep cost inherits the multiplicity primitive: O(n) on
/// slice arity `n`, allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_occurrence_of`]: a `tatara-check` predicate
/// `(check-phase-visited-exactly-once …)` reporting whether a
/// specific `WorkloadPhase` visits its rollout window EXACTLY ONCE
/// (a stricter contract than `check-phase-visited` at multiplicity
/// `> 0`) in ONE atomic bool rather than a count-and-then-compare
/// composition; a Sekiban audit-trail per-variant uniqueness bit
/// across a rollout window classifying variants into (absent,
/// unique, repeated) via the disjoint arms `!occurs_in`,
/// `is_unique_occurrence_of`, and `occurs_in && !is_unique_occurrence_of`;
/// a `tatara-lisp::macro_expand::Expander` hygiene pass that
/// flags an identifier introduced EXACTLY ONCE (a single-shot
/// binding, distinct from an unbound identifier OR a rebound
/// identifier) in ONE typed bool. Each binds to ONE typed N-ary
/// per-target multiplicity-1 predicate on the trait rather than
/// re-deriving `T::count_occurrences_of(v, items) == 1` inline
/// per callsite.
///
/// Compounding closure: the (per-target × bool × multiplicity-
/// band) 2-corner face on the equivalence-partition surface now
/// closes at the (bool, per-target, `== 1`) corner peer to the
/// (bool, per-target, `> 0`) corner [`Self::occurs_in`] one
/// MULTIPLICITY-BAND axis over. The natural next lift past this
/// unique-occurrence corner is the set-level `is_multiset_slice`
/// bool (`T::variant_counts(items).iter().all(|&c| c <= 1)` —
/// every variant appears at most ONCE across the entire slice,
/// equivalently `T::ALL.iter().all(|&v| !T::occurs_in(v, items) || T::is_unique_occurrence_of(v, items))`),
/// opening a fresh (set-level × bool × multiplicity-band) corner
/// past the (set-level × bool × modal-equality) uniformity corner
/// [`Self::is_uniform`] one multiplicity-band axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target multiplicity-1 primitive becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::count_occurrences_of(v, items) == 1` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// naming the (per-target × bool × `== 1`) corner on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::count_occurrences_of`] primitive packaged as one
/// atomic strict-equality test. THEORY.md §VI.1 — generation over
/// composition; the multiplicity-1 predicate emerges from one
/// composition (strict-equality against `1` on the multiplicity
/// primitive), not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `List.count_occ eqb l x = 1`
/// decidable-equality-derived uniqueness test on `list nat`;
/// Idris's `Data.List.count (== v) items == 1`; Julia's
/// `count(==(v), items) == 1`; Haskell's `length (filter (== v) items) == 1`;
/// Rust's own `items.iter().filter(|&&w| w == v).count() == 1`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `items.count(v) == 1`. Translation through pleme-io primitives:
/// the N-ary per-target multiplicity-1 predicate on the closed-
/// set trait binds through strict-equality against `1` on the
/// substrate's multiplicity primitive — no new dep, no supertrait
/// bound (the [`Self::index_of`] projection the multiplicity
/// primitive already threads through replaces the `PartialEq`
/// bound the standard-library `count` + `== 1` signature chain
/// demands), no allocation, O(n) on slice arity `n` inherited
/// verbatim from the multiplicity primitive.
fn is_unique_occurrence_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::count_occurrences_of(target, items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "per-target multiplicity-≥2"
/// predicate — the `bool` per-target REPETITION test whose value
/// coincides with `T::count_occurrences_of(target, items) >= 2`,
/// i.e. `true` iff the target appears AT LEAST TWICE in `items`.
/// The PER-TARGET `bool`-RETURN MULTIPLICITY-BAND CLOSER on the
/// (per-target × bool) column of the equivalence-partition surface,
/// positioned as the direct MULTIPLICITY-BAND projection of the
/// [`Self::count_occurrences_of`] per-target multiplicity primitive
/// one MULTIPLICITY-BAND axis over from BOTH the (per-target × bool)
/// MULTIPLICITY-POSITIVE corner [`Self::occurs_in`] (mult `> 0`)
/// AND the (per-target × bool) MULTIPLICITY-EQUALS-ONE corner
/// [`Self::is_unique_occurrence_of`] (mult `== 1`). The three
/// bands (`== 0`, `== 1`, `>= 2`) partition the per-target
/// multiplicity axis exhaustively into three disjoint arms,
/// exposed on the trait through the disjoint predicate triple
/// (`!occurs_in`, `is_unique_occurrence_of`,
/// `is_repeated_occurrence_of`) that closes the (per-target × bool
/// × multiplicity-band) 3-corner face on the equivalence-partition
/// surface — every position on the per-target multiplicity axis
/// binds to exactly ONE of the three typed predicates.
///
/// Count-composition identity: for every slice `items` and every
/// target `v`,
/// `T::is_repeated_occurrence_of(v, items) == (T::count_occurrences_of(v, items) >= 2)`
/// — the bool predicate is EXACTLY the lower-bound test of the
/// per-target multiplicity primitive against `2`. Pinned by
/// clause (112) and by
/// `is_repeated_occurrence_of_holds_iff_count_occurrences_of_ge_two_across_every_target_and_triple`.
///
/// Presence-and-repeat composition identity: for every slice
/// `items` and every target `v`,
/// `T::is_repeated_occurrence_of(v, items) == (T::occurs_in(v, items) && !T::is_unique_occurrence_of(v, items))`
/// — the (multiplicity `>= 2`) band factors through the
/// (multiplicity `> 0`) membership predicate conjoined with the
/// NEGATION of the (multiplicity `== 1`) uniqueness predicate.
/// Pinned by
/// `is_repeated_occurrence_of_equals_occurs_in_and_not_is_unique_across_every_target_and_triple`.
///
/// Every-position composition identity: for every slice `items`
/// and every target `v`,
/// `T::is_repeated_occurrence_of(v, items) == (T::all_occurrences_of(v, items).len() >= 2)`
/// — the lower-bound-against-2 test factors through the every-
/// position vec's length arm. Pinned by
/// `is_repeated_occurrence_of_holds_iff_all_occurrences_of_len_ge_two_across_every_target_and_triple`.
///
/// Endpoint-separation composition identity: for every slice
/// `items` and every target `v`,
/// `T::is_repeated_occurrence_of(v, items) == (T::occurrence_span_of(v, items).map(|s| s >= 1).unwrap_or(false))`
/// — a repeated occurrence pins the `(head, tail)` endpoint pair
/// at distinct slots (span `>= 1`), and any hit on a non-empty
/// slice with non-zero span means at least two occurrences; the
/// `None`-preserving `unwrap_or(false)` arm on the empty slice
/// collapses to `false` under the discriminant. Pinned by
/// `is_repeated_occurrence_of_equals_span_at_least_one_across_every_target_and_triple`.
///
/// Multiplicity-band partition (trichotomy): for every slice
/// `items` and every target `v`, EXACTLY ONE of the three typed
/// predicates holds — `!T::occurs_in(v, items)` (multiplicity `==
/// 0`), `T::is_unique_occurrence_of(v, items)` (multiplicity `==
/// 1`), or `T::is_repeated_occurrence_of(v, items)` (multiplicity
/// `>= 2`) — and the three arms are PAIRWISE DISJOINT. Pinned by
/// `is_repeated_occurrence_of_and_is_unique_occurrence_of_are_pairwise_disjoint_across_every_target_and_triple`
/// and
/// `multiplicity_band_predicates_partition_the_per_target_axis_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_repeated_occurrence_of(v, &[])` is
/// `false` for every target `v` — the empty slice hits zero
/// positions, so the per-target multiplicity is `0` and the
/// lower-bound test against `2` fails. Pinned by clause (112) and
/// by
/// `is_repeated_occurrence_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::is_repeated_occurrence_of(v,
/// &[v]) == false` for every target `v` — the sole position hits
/// the target with multiplicity `1`, so the lower-bound test
/// against `2` fails. Pinned by
/// `is_repeated_occurrence_of_returns_false_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract: `T::is_repeated_occurrence_of(v,
/// &[w]) == false` for every target `v` and slice-element `w`
/// with `T::index_of(v) != T::index_of(w)` — the per-target
/// multiplicity is `0` at the target, and the lower-bound test
/// against `2` fails. Pinned by
/// `is_repeated_occurrence_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::is_repeated_occurrence_of(v, <T as
/// ClosedSet>::ALL) == false` UNCONDITIONALLY — clause (3)'s
/// pairwise-distinctness invariant forces every variant to appear
/// at EXACTLY ONE position of the full-set slice, so the per-
/// target multiplicity is `1` and the lower-bound test against `2`
/// fails at every target. Pinned by clause (112) at the full-set
/// fixpoint AND by
/// `is_repeated_occurrence_of_returns_false_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::is_repeated_occurrence_of(v,
/// &[T::ALL, T::ALL].concat()) == true` UNCONDITIONALLY — the
/// doubled full set hits every variant at EXACTLY TWO positions,
/// so the per-target multiplicity is `2` and the lower-bound test
/// against `2` holds at every target. The doubled-full-set arm is
/// LOAD-BEARING — it is the ONLY canonical fixpoint arm that
/// separates the (multiplicity `>= 2`) band from the (multiplicity
/// `== 0`) absence band: on empty, matching-singleton, non-
/// matching-singleton, and full-set fixpoints both bands report
/// `false` (multiplicity is `0` or `1` at every corner); only the
/// doubled-full-set arm distinguishes them (`true` under the
/// repetition band, `false` under the absence band). Pinned by
/// clause (112) at the doubled-full-set fixpoint AND by
/// `is_repeated_occurrence_of_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis on `T::ALL`
/// COLLAPSES on this predicate because it factors through
/// [`Self::count_occurrences_of`] (itself ordering-agnostic) via
/// a scalar-lower-bound test. Sibling posture to every predicate
/// on the equivalence-partition surface: no separate
/// `sorted_is_repeated_occurrence_of` peer is needed.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_occurrences_of`] via lower-bound against `2`.
/// The sweep cost inherits the multiplicity primitive: O(n) on
/// slice arity `n`, allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_repeated_occurrence_of`]: a `tatara-check` predicate
/// `(check-phase-visited-more-than-once …)` reporting whether a
/// specific `WorkloadPhase` visits its rollout window AT LEAST
/// TWICE (a rollout-loop witness that distinguishes a
/// re-convergence retry from a single-shot success) in ONE
/// atomic bool rather than a count-and-then-compare composition;
/// a Sekiban audit-trail per-variant repetition bit across a
/// rollout window classifying variants into (absent, unique,
/// repeated) via the disjoint arms `!occurs_in`,
/// `is_unique_occurrence_of`, and `is_repeated_occurrence_of` —
/// this predicate CLOSES the third arm of the trichotomy;
/// a `tatara-lisp::macro_expand::Expander` hygiene pass that
/// flags a template identifier introduced MORE THAN ONCE
/// (a redefinition, distinct from an unbound identifier OR a
/// single-shot binding — a common bug shape in quasi-quote
/// templates that unquote-splice a variable set) in ONE typed
/// bool. Each binds to ONE typed N-ary per-target multiplicity-
/// ≥2 predicate on the trait rather than re-deriving
/// `T::count_occurrences_of(v, items) >= 2` inline per callsite.
///
/// Compounding closure: the (per-target × bool × multiplicity-
/// band) 3-corner face on the equivalence-partition surface now
/// CLOSES EXHAUSTIVELY at three disjoint bands — (mult `== 0`)
/// via `!T::occurs_in`, (mult `== 1`) via
/// [`Self::is_unique_occurrence_of`], and (mult `>= 2`) via this
/// predicate. Every point on the per-target multiplicity axis
/// now binds to exactly ONE typed predicate on the trait; the
/// trichotomy partition is a TYPED THEOREM the substrate proves
/// once and every downstream consumer routes through. The natural
/// next lift past this corner is the set-level `has_repeat` bool
/// (`T::ALL.iter().any(|&v| T::is_repeated_occurrence_of(v, items))`
/// — some variant appears MORE THAN ONCE across the entire slice,
/// equivalently `T::max_variant_count(items) >= 2`,
/// equivalently `!T::is_pairwise_distinct(items)`) opening a
/// (set-level × bool × multiplicity-band `>= 2`) corner peer to
/// the just-lifted (per-target × bool × mult `>= 2`) corner one
/// arity axis over on the (arity × mult-band) face. Note that the
/// existing [`Self::is_pairwise_distinct`] predicate ALREADY
/// closes the set-level (mult `<= 1`) band; a set-level `has_repeat`
/// lift would simply expose the NEGATION as a typed alias — a
/// distinct question but not a fresh compounding closure.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target multiplicity-≥2 primitive becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::count_occurrences_of(v, items) >= 2` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// naming the (per-target × bool × `>= 2`) corner on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::count_occurrences_of`] primitive packaged as one
/// atomic lower-bound test — AND completes the trichotomy
/// partition on the per-target multiplicity axis as a TYPED
/// THEOREM the substrate proves once. THEORY.md §VI.1 —
/// generation over composition; the multiplicity-≥2 predicate
/// emerges from one composition (lower-bound against `2` on the
/// multiplicity primitive), not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Coq's `2 <=? List.count_occ eqb l x`
/// decidable-equality-derived repetition test on `list nat`;
/// Idris's `Data.List.count (== v) items >= 2`; Julia's
/// `count(==(v), items) >= 2`; Haskell's `length (filter (== v) items) >= 2`;
/// Rust's own `items.iter().filter(|&&w| w == v).count() >= 2`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `items.count(v) >= 2`; SQL's `HAVING COUNT(*) >= 2` on a
/// `GROUP BY variant` aggregation — the canonical per-key
/// repetition witness on a relational carrier. Translation
/// through pleme-io primitives: the N-ary per-target multiplicity-
/// ≥2 predicate on the closed-set trait binds through lower-
/// bound against `2` on the substrate's multiplicity primitive —
/// no new dep, no supertrait bound (the [`Self::index_of`]
/// projection the multiplicity primitive already threads through
/// replaces the `PartialEq` bound the standard-library `count` +
/// `>= 2` signature chain demands), no allocation, O(n) on slice
/// arity `n` inherited verbatim from the multiplicity primitive.
fn is_repeated_occurrence_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::count_occurrences_of(target, items) >= 2
}
/// The N-ARY ORDERING-AGNOSTIC "target saturates every position"
/// predicate — `true` iff every position of `items` sits at the
/// target variant, computed as the strict-equality test of the
/// per-target multiplicity primitive [`Self::count_occurrences_of`]
/// against the slice arity `items.len()`. The PER-TARGET × bool ×
/// per-position-universal-quantifier corner OPENING the (per-target
/// × bool × per-position-quantifier) 2-corner face on the
/// equivalence-partition surface at the ∀-arm peer to the pre-
/// existing (per-target × bool × per-position-EXISTENTIAL-quantifier)
/// [`Self::occurs_in`] ∃-arm one QUANTIFIER-axis over — the ∃/∀
/// duality on the PER-POSITION quantifier axis at the SAME per-
/// target arity. Distinct from the (per-target × bool ×
/// multiplicity-band) trichotomy corners [`Self::occurs_in`] (mult
/// `> 0`) / [`Self::is_unique_occurrence_of`] (mult `== 1`) /
/// [`Self::is_repeated_occurrence_of`] (mult `>= 2`) which sit on
/// the multiplicity-band axis, while this predicate sits on the
/// slice-arity-relative saturation axis (multiplicity `==
/// items.len()`).
///
/// Count-composition identity: for every slice `items` and every
/// target `v`,
/// `T::is_saturated_by(v, items) == (T::count_occurrences_of(v, items) == items.len())`
/// — the bool predicate is EXACTLY the strict-equality test of the
/// per-target multiplicity primitive against the slice arity. The
/// canonical form the body uses. Pinned by clause (122) and by
/// `is_saturated_by_holds_iff_count_occurrences_of_equals_len_across_every_target_and_triple`.
///
/// Per-position universal identity: for every slice `items` and
/// every target `v`,
/// `T::is_saturated_by(v, items) == items.iter().all(|w| T::index_of(*w) == T::index_of(v))`
/// — the per-target saturation predicate is the EXACT universal
/// quantification over the slice's positions of the per-position
/// index-equality test via the substrate's [`Self::index_of`]
/// bijection (the closed-set well-formedness invariant clause (16)
/// pins that projection as injective). Pinned by
/// `is_saturated_by_equals_universal_of_index_of_equality_across_every_target_and_triple`.
///
/// Constant-arity-lift identity: for every slice `items` on any
/// implementor of cardinality `>= 1`,
/// `T::is_constant(items) == T::ALL.iter().any(|&v| T::is_saturated_by(v, items))`
/// — the set-level EXISTENTIAL LIFT of this per-target predicate
/// over [`Self::ALL`] equals the direction-conjunction constant
/// predicate [`Self::is_constant`]. This identity binds the SET-
/// LEVEL ARITY axis (`is_constant` = ∃v : ∀i, items[i] == v)
/// against the PER-TARGET ARITY axis (`is_saturated_by` = ∀i,
/// items[i] == v) one ARITY axis over on the (arity × per-position-
/// quantifier) face, pinning the compounding closure the set-level
/// [`Self::is_constant`] corner opened as the existential lift of
/// this per-target predicate. Pinned by
/// `is_constant_equals_existential_of_is_saturated_by_across_every_triple`.
///
/// Membership-and-covering-degenerate composition identity: for
/// every slice `items` and every target `v`,
/// `T::is_saturated_by(v, items) == (items.is_empty() || (T::occurs_in(v, items) && T::count_distinct(items) == 1))`
/// — the per-target saturation predicate factors through the
/// disjunction of (i) the empty-slice trivial-holds arm AND (ii)
/// the conjunction of (a) target-presence via [`Self::occurs_in`]
/// AND (b) singleton-distinct-count [`Self::count_distinct`] `== 1`
/// (the slice hits only ONE variant). Independent cross-check
/// distinct from the count-composition arm on the composition-arity
/// axis (empty-guard × two-way conjunction vs one direct scalar-
/// equality). Pinned by
/// `is_saturated_by_equals_empty_or_occurs_in_and_count_distinct_equals_one_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_saturated_by(v, &[])` is `true` for
/// every target `v` — the empty slice hits zero positions, the per-
/// target multiplicity is `0`, the slice arity is `0`, and the
/// strict-equality test `0 == 0` holds VACUOUSLY. Sibling posture
/// to [`Self::is_pairwise_distinct`]'s empty-slice vacuous-`true`
/// contract: both PER-POSITION UNIVERSAL-QUANTIFIER predicates
/// collapse to `true` on the empty slice by empty-quantification
/// over positions. Pinned by clause (122) and by
/// `is_saturated_by_returns_true_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::is_saturated_by(v, &[v]) ==
/// true` for every target `v` — the sole position hits the target,
/// the per-target multiplicity is `1`, the slice arity is `1`, and
/// the strict-equality test `1 == 1` holds. Pinned by
/// `is_saturated_by_returns_true_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract: `T::is_saturated_by(v, &[w]) ==
/// false` for every target `v` and slice-element `w` with
/// `T::index_of(v) != T::index_of(w)` — the per-target multiplicity
/// is `0` at the target, the slice arity is `1`, and the strict-
/// equality test `0 == 1` fails. The non-matching-singleton arm is
/// LOAD-BEARING as the drift catch for an override that folds onto
/// `true` unconditionally. Pinned by clause (122) and by
/// `is_saturated_by_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::is_saturated_by(v, <T as ClosedSet>::ALL)`
/// is `true` iff `T::CARDINALITY <= 1` at every target `v` — on
/// cardinality-0 implementors [`Self::ALL`] is empty and the
/// vacuous-`true` empty-slice arm applies (there are no targets to
/// test but the identity holds structurally); on cardinality-1
/// implementors [`Self::ALL`] is `[only]` and the sole variant
/// saturates it (`count == 1 == len`); on cardinality-`>= 2`
/// implementors [`Self::ALL`] holds every variant at exactly one
/// position (clause (3)'s pairwise-distinctness invariant), the
/// per-target multiplicity is `1` at every target, the slice arity
/// is `T::CARDINALITY >= 2`, and the strict-equality test `1 ==
/// T::CARDINALITY` fails. The full-set arm is LOAD-BEARING as the
/// boundary that separates saturation (per-target × ∀-position)
/// from covering ([`Self::is_covering`], which is `true` on the
/// full set at every cardinality). Pinned by clause (122) and by
/// `is_saturated_by_returns_false_on_the_full_set_across_every_target_at_cardinality_ge_two`.
///
/// Doubled-matching-singleton contract:
/// `T::is_saturated_by(v, &[v, v]) == true` for every target `v` —
/// both positions hit the target, the per-target multiplicity is
/// `2`, the slice arity is `2`, and the strict-equality test `2 ==
/// 2` holds. The doubled-matching-singleton arm is LOAD-BEARING as
/// the drift catch for an override that folds onto the (multi-
/// plicity `== 1`) uniqueness predicate [`Self::is_unique_occurrence_of`]
/// (which is `false` on this slice while THIS predicate is `true`).
/// Pinned by clause (122) and by
/// `is_saturated_by_returns_true_on_the_doubled_matching_singleton_across_every_target`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis on `T::ALL`
/// COLLAPSES on this predicate because it factors through
/// [`Self::count_occurrences_of`] (itself ordering-agnostic) via
/// a scalar strict-equality test against `items.len()`. No separate
/// `sorted_is_saturated_by` peer is needed. Sibling posture to
/// every predicate on the equivalence-partition surface. Pinned by
/// `is_saturated_by_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_occurrences_of`] via strict-equality against
/// `items.len()`. The sweep cost inherits the multiplicity
/// primitive: O(n) on slice arity `n`, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_saturated_by`]: a `tatara-check` predicate
/// `(check-window-saturated-by …)` that verifies a `WorkloadPhase`
/// window sits entirely at a SPECIFIC phase (e.g. entire attest
/// window is `Attested`, distinct from the set-level
/// [`Self::is_constant`] which only pins "SOME phase" rather than
/// WHICH phase); an LSP diagnostic on a Lisp-author-written closed-
/// set field that reports "field is entirely `<target>`" as a
/// per-variant witness distinct from the set-level constant
/// witness; a Sekiban audit-trail per-window classification anchor
/// binding "window is entirely `Converged`" as a typed proof-of-
/// stability distinct from "window is entirely some SINGLE
/// classification"; a `tatara-lisp::macro_expand::Expander` hygiene
/// pass that flags a template's identifier list as SATURATED BY a
/// specific gensym (e.g. every hygiene binding uses the same
/// generated identifier — a rare but signal-worthy invariant
/// distinct from the set-level "all-identifiers-equal" check). Each
/// binds to ONE typed N-ary per-target saturation predicate on the
/// trait rather than re-deriving
/// `T::count_occurrences_of(v, items) == items.len()` inline per
/// callsite.
///
/// Compounding closure: the (per-target × bool × per-position-
/// quantifier) 2-corner face on the equivalence-partition surface
/// now OPENS at the ∀-arm peer to [`Self::occurs_in`] — every point
/// on the per-target per-position-quantifier axis now binds to a
/// typed predicate on the trait ([`Self::occurs_in`] on the ∃-arm,
/// this predicate on the ∀-arm). The set-level ARITY-lift of the
/// ∀-arm through `T::ALL.iter().any(...)` recovers the pre-existing
/// direction-conjunction [`Self::is_constant`] predicate, closing
/// the (arity × per-position-quantifier) face at the (set-level, ∃-
/// over-targets-of-∀-over-positions) `is_constant` corner. The
/// natural next lift past this corner is the (per-target × Vec<usize>
/// × per-position-quantifier) sharpening — a per-target vec of
/// positions where the target does NOT sit (the vacuous-∀ witness
/// for the negation), OR the set-level `saturating_variant` primitive
/// (`Option<Self>` returning the sole saturating variant when
/// `is_constant` holds on a non-empty slice) opening the (return-
/// shape × arity) face on the saturation axis.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target ∀-position saturation predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::count_occurrences_of(v, items) == items.len()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; naming the (per-target × bool × ∀-position)
/// corner on the trait makes the projection a TYPED CONSEQUENCE of
/// the substrate's per-target multiplicity primitive packaged as
/// one atomic strict-equality test against the slice arity — AND
/// opens the ∀-arm peer to [`Self::occurs_in`] on the per-target
/// per-position-quantifier axis as a TYPED THEOREM the substrate
/// proves once. THEORY.md §VI.1 — generation over composition; the
/// saturation predicate emerges from one composition (strict-
/// equality against `items.len()` on the multiplicity primitive),
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `forallb (fun w => v =? w) items`
/// decidable-equality-derived per-position universal on `list nat`;
/// Idris's `all (\w => w == v) items` on a `Vect n a`; Racket's
/// `(andmap (λ (w) (equal? v w)) items)`; Julia's
/// `all(w -> w == v, items)`; Haskell's `all (== v) items`; Rust's
/// own `items.iter().all(|&w| w == v)` binds through a `Self:
/// PartialEq` supertrait bound; Python's `all(w == v for w in
/// items)`; SQL's `NOT EXISTS (SELECT 1 FROM t WHERE variant != v)`
/// — the canonical per-key saturation witness on a relational
/// carrier. Translation through pleme-io primitives: the N-ary per-
/// target ∀-position saturation predicate on the closed-set trait
/// binds through strict-equality against `items.len()` on the
/// substrate's per-target multiplicity primitive — no new dep, no
/// supertrait bound (the [`Self::index_of`] projection the
/// multiplicity primitive already threads through replaces the
/// `PartialEq` bound the standard-library `all(== v)` signature
/// chain demands), no allocation, O(n) on slice arity `n` inherited
/// verbatim from the multiplicity primitive.
fn is_saturated_by(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::count_occurrences_of(target, items) == items.len()
}
/// The N-ARY ORDERING-AGNOSTIC "per-slot variant histogram"
/// projection — the `Vec<usize>` DECLARATION-ORDER histogram over
/// [`Self::ALL`] whose slot `i` reports the multiplicity of
/// `T::ALL[i]` in `items`. The `Vec<usize>` per-slot histogram
/// opener on the (per-target × Vec) column of the equivalence-
/// partition surface, positioned as the concrete AGGREGATION
/// behind the just-lifted usize-return [`Self::count_occurrences_of`]
/// per-target multiplicity primitive (which reports the
/// multiplicity of ONE target) and the Vec-return
/// [`Self::present_variants`] present-witness projection (which
/// reports the STRICTLY-POSITIVE arm of the same histogram as a
/// typed variant witness). The (per-target, per-slot) × (usize,
/// Vec) 2×2 = 4-corner (arity × return-shape) face on the
/// equivalence-partition surface now closes the `Vec<usize>` per-
/// slot column at the (Vec<usize>, per-slot) corner peer to the
/// (`usize`, per-target) corner [`Self::count_occurrences_of`]
/// opened.
///
/// Declaration-order contract: slot `i` of the returned
/// `Vec<usize>` reports the multiplicity of `T::ALL[i]` in
/// `items` — the histogram walks [`Self::ALL`] in declaration
/// order and projects each slot's variant through the per-target
/// multiplicity primitive. Pinned by
/// `variant_counts_slot_i_equals_count_occurrences_of_variant_i_across_every_triple`.
///
/// Length contract: `T::variant_counts(items).len() == T::CARDINALITY`
/// on every slice on every implementor — the histogram has ONE
/// slot per variant of the closed set, so the returned vector's
/// length is anchored at the substrate's forced-arity constant.
/// Pinned by clause (98) at BOTH the full-set and empty-slice
/// fixpoints AND by the test-sweep.
///
/// Partition identity: for every slice `items`,
/// `T::variant_counts(items).iter().sum::<usize>() == items.len()`
/// — the histogram partitions the slice's positions exactly,
/// because every position sits at EXACTLY ONE variant (the
/// (variant → decl-slot) injectivity clause (16) forces the per-
/// position occurrence-arm membership disjoint on `target`). This
/// is the direct Vec-lift of
/// [`Self::count_occurrences_of`]'s per-target partition identity.
/// Pinned by
/// `variant_counts_summed_equals_slice_length_across_every_triple`.
///
/// Empty-slice contract: `T::variant_counts(&[])` is the all-
/// zeros vector of length [`Self::CARDINALITY`] on every
/// implementor — the empty slice hits zero positions, so every
/// per-slot filter accepts nothing. Pinned by clause (98)'s
/// empty-slice fixpoint arm and by
/// `variant_counts_returns_all_zeros_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::variant_counts(<T as ClosedSet>::ALL)` is the all-ones
/// vector of length [`Self::CARDINALITY`] UNCONDITIONALLY — the
/// closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants
/// as pairwise distinct, so every variant appears in `T::ALL` at
/// exactly one position and every histogram slot lands at `1`.
/// Pinned by clause (98)'s full-set fixpoint arm and by
/// `variant_counts_returns_all_ones_on_the_full_set_across_every_kind`.
///
/// Reversal-invariance: `T::variant_counts(items)` equals
/// `T::variant_counts(items.iter().rev().copied().collect::<Vec<_>>())`
/// for every slice — reversing a slice preserves its multiset of
/// variant identities, and every per-slot histogram bar is a
/// function of that multiset alone. Pinned by
/// `variant_counts_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level. The composition uses one `T::ALL` iteration
/// mapping each variant through [`Self::count_occurrences_of`],
/// so the sweep costs O(T::CARDINALITY * n) on slice arity `n` —
/// allocation-free per-slot, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::variant_counts`]: a `tatara-check` predicate
/// `(check-phases-histogram …)` that verifies a rollout window's
/// per-`WorkloadPhase` occurrence count matches a Lisp-authored
/// histogram spec exactly at plan time — catching a rollout that
/// silently over- or under-visits a specific phase; an LSP
/// diagnostic on a Lisp-author-written closed-set field that
/// renders the full per-variant histogram as an author-facing
/// spark-line (`":severities [:warn :warn :crit]" → "info: 0,
/// warn: 2, error: 0, crit: 1"`) rather than the per-target scalar
/// [`Self::count_occurrences_of`] projection or the collapsed
/// [`Self::count_distinct`] scalar; a Sekiban audit-trail per-
/// window classification histogram bar sequence carrying the
/// concrete per-variant occurrence counts as its per-window
/// witness; a `tatara-lisp::macro_expand::Expander` hygiene pass
/// that reports the exact per-identifier hit-count over a
/// template's generated body against a required closed
/// vocabulary; a per-slot rate limiter reading its throttle
/// budget as an entire per-variant histogram vector (rather than
/// a per-variant lookup per window). Each binds to ONE typed N-
/// ary per-slot histogram projection on the trait rather than
/// re-deriving
/// `T::ALL.iter().map(|v| T::count_occurrences_of(v, items)).collect()`
/// inline per callsite.
///
/// Compounding closure: the equivalence-partition surface now
/// closes the (per-target × Vec) column at the (Vec<usize>, per-
/// slot) corner peer to the (per-target × usize) corner
/// [`Self::count_occurrences_of`] opened. The next natural lift
/// on this surface — a `sorted_variant_counts(items) -> Vec<usize>`
/// LEX-order per-slot histogram whose slot `i` reads
/// `T::count_occurrences_of(T::sorted_variants()[i], items)` —
/// opens the (per-slot × lex) corner peer to the (per-slot ×
/// decl) corner this lift opens on the (per-slot × ordering)
/// 2-corner face of the histogram surface. Downstream consumers
/// wanting the "mode" (variant with maximum multiplicity, i.e.
/// argmax of the histogram) or the "least-frequent" variant
/// (argmin) compose on this projection through iterator sweep
/// without an additional substrate primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// slot histogram projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().map(|v| T::count_occurrences_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; the (per-slot × Vec) histogram corner
/// was an unnamed inline composition recurring at every
/// prospective downstream "what does the full per-variant
/// histogram look like?" site pre-lift. Naming it on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// per-target multiplicity primitive
/// [`Self::count_occurrences_of`] mapped over
/// [`Self::ALL`]. THEORY.md §VI.1 — generation over composition;
/// the per-slot histogram projection emerges from the composition
/// of ONE substrate primitive
/// ([`Self::count_occurrences_of`]) with an
/// `iter().map().collect()` combinator on `T::ALL`, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Clojure's `(frequencies coll)` returning
/// a `Map<Element, usize>` per-element histogram; Python's
/// `collections.Counter(items)` returning a `dict[element, int]`
/// per-element histogram; Julia's `StatsBase.counts(items,
/// levels)` on a fixed level-set returning a per-level
/// `Vector{Int}`; NumPy's `np.bincount(items, minlength=N)`
/// returning a per-index count array; R's `tabulate(items,
/// nbins)` returning a per-bin count vector; Coq's `count_occ_by`
/// combinator lifted to a per-element projection over a decidable-
/// equality carrier. Translation through pleme-io primitives: the
/// N-ary per-slot histogram projection on the closed-set trait
/// binds through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] mapped over [`Self::ALL`] — no
/// new dep, no supertrait bound (the [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` /
/// `frequencies` signatures demand), no map-shape carrier
/// allocation (the substrate's [`Self::ALL`] slot-order pins the
/// output to a dense `Vec<usize>` of length
/// [`Self::CARDINALITY`]), no allocation per input position (the
/// underlying primitive folds each position under `filter().count()`
/// without a hash-table probe).
fn variant_counts(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.map(|v| <Self as ClosedSet>::count_occurrences_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "per-slot variant histogram"
/// projection in LEX order — the `Vec<usize>` LEX-ORDER histogram
/// over [`Self::sorted_variants`] whose slot `i` reports the
/// multiplicity of `T::sorted_variants()[i]` in `items`. The
/// LEX-ORDER peer of [`Self::variant_counts`] on the (declaration,
/// lex) ordering axis of the (per-slot × Vec<usize>) column of the
/// equivalence-partition surface — closes the lex arm past the
/// declaration arm the sibling [`Self::variant_counts`] opened. The
/// (per-slot × Vec<usize>) × (declaration, lex) 1×2 = 2-corner
/// (return-shape × ordering) face on the histogram surface now
/// closes at BOTH ordering corners.
///
/// Lex-order contract: slot `i` of the returned `Vec<usize>` reports
/// the multiplicity of `T::sorted_variants()[i]` in `items` — the
/// histogram walks [`Self::sorted_variants`] in lex order and
/// projects each slot's variant through the per-target multiplicity
/// primitive. Pinned by
/// `sorted_variant_counts_slot_i_equals_count_occurrences_of_sorted_variant_i_across_every_triple`.
///
/// Length contract:
/// `T::sorted_variant_counts(items).len() == T::CARDINALITY` on
/// every slice on every implementor — the histogram has ONE slot
/// per variant of the closed set, so the returned vector's length is
/// anchored at the substrate's forced-arity constant. Matches
/// [`Self::variant_counts`]'s length contract byte-for-byte — the
/// (declaration, lex) axis reorders the slots but preserves the
/// per-slot arity. Pinned by clause (99) at BOTH the full-set and
/// empty-slice fixpoints AND by the test-sweep.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_variant_counts(items)` is a PERMUTATION of
/// `T::variant_counts(items)` — the two projections read the SAME
/// per-target multiplicity primitive over the SAME hit-set (from
/// [`Self::ALL`] / [`Self::sorted_variants`], each containing every
/// variant exactly once), so the multiset of per-slot counts in the
/// two returned Vecs coincides though the ordering differs. The
/// permutation is fixed by the (declaration → lex) index
/// bijection: `T::sorted_variant_counts(items)[i] ==
/// T::variant_counts(items)[T::sorted_variants()[i].index_of()]`.
/// Pinned by
/// `sorted_variant_counts_is_a_permutation_of_variant_counts_across_every_triple`
/// and
/// `sorted_variant_counts_slot_i_equals_variant_counts_at_sorted_variant_index_of_across_every_triple`.
///
/// Partition identity: for every slice `items`,
/// `T::sorted_variant_counts(items).iter().sum::<usize>() == items.len()`
/// — the histogram partitions the slice's positions exactly, because
/// every position sits at EXACTLY ONE variant (the (variant →
/// decl-slot) injectivity clause (16) forces the per-position
/// occurrence-arm membership disjoint on `target`, and the (variant
/// → lex-slot) sorted-index injectivity clause (17) forces the same
/// disjointness on the lex-order axis). This is the direct lex-lift
/// of [`Self::variant_counts`]'s partition identity — a permutation
/// preserves sums. Pinned by
/// `sorted_variant_counts_summed_equals_slice_length_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_variant_counts(&[])` is the
/// all-zeros vector of length [`Self::CARDINALITY`] on every
/// implementor — the empty slice hits zero positions, so every
/// per-slot filter accepts nothing. Sibling posture to
/// [`Self::variant_counts`]'s empty-slice endpoint one ordering axis
/// over: both projections agree on the empty-slice fixpoint because
/// the zero-vector has no positional content to distinguish decl
/// from lex order. Pinned by clause (99)'s empty-slice fixpoint arm
/// and by
/// `sorted_variant_counts_returns_all_zeros_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_variant_counts(<T as ClosedSet>::ALL)` is the all-ones
/// vector of length [`Self::CARDINALITY`] UNCONDITIONALLY — the
/// closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants
/// as pairwise distinct, so every variant appears in `T::ALL` at
/// exactly one position and every histogram slot lands at `1`. The
/// full-set endpoint also collapses the (decl, lex) ordering
/// distinction because an all-ones vector is a permutation-fixpoint.
/// Pinned by clause (99)'s full-set fixpoint arm and by
/// `sorted_variant_counts_returns_all_ones_on_the_full_set_across_every_kind`.
///
/// Reversal-invariance: `T::sorted_variant_counts(items)` equals
/// `T::sorted_variant_counts(items.iter().rev().copied().collect::<Vec<_>>())`
/// for every slice — reversing a slice preserves its multiset of
/// variant identities, and every per-slot histogram bar is a
/// function of that multiset alone. Pinned by
/// `sorted_variant_counts_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, composed with the substrate's
/// [`Self::sorted_variants`] canonical lex-order listing. The
/// composition uses one `T::sorted_variants()` iteration mapping
/// each variant through [`Self::count_occurrences_of`], so the
/// sweep costs O(N log N + T::CARDINALITY * n) on slice arity `n`
/// (the O(N log N) term is the outer `sort_unstable_by_key` inside
/// [`Self::sorted_variants`]; the O(T::CARDINALITY * n) term is
/// the per-slot per-target multiplicity sweep) — no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// map-shape carrier.
///
/// Future consumers that compose against
/// [`Self::sorted_variant_counts`]: a `tatara-check` predicate
/// `(check-phases-histogram-lex …)` that verifies a rollout window's
/// per-`WorkloadPhase` occurrence count matches a Lisp-authored
/// histogram spec in LEX ORDER (so operator-facing diagnostics
/// agree with the substrate-wide sorted-labels + sorted-variants
/// canonical-listing surface); an LSP diagnostic on a Lisp-author-
/// written closed-set field that renders the full per-variant
/// histogram as an author-facing spark-line in the same lex order
/// the "did you mean …?" suggestion surface uses (`":severities
/// [:warn :warn :crit]" → "crit: 1, info: 0, warn: 2"`) rather than
/// the declaration-order [`Self::variant_counts`] shape; a Sekiban
/// audit-trail per-window classification histogram bar sequence
/// carrying the concrete per-variant occurrence counts in lex order
/// for operator-facing render agreement across every downstream
/// surface; a metric-emitter that binds Prometheus-style label
/// vectors in the same lex order the operator-facing dashboard
/// column ordering uses. Each binds to ONE typed N-ary lex-order
/// per-slot histogram projection on the trait rather than re-
/// deriving
/// `T::sorted_variants().into_iter().map(|v| T::count_occurrences_of(v, items)).collect()`
/// inline per callsite.
///
/// Compounding closure: the equivalence-partition surface now
/// closes the (per-slot × Vec × ordering) 1×2 = 2-corner face at
/// the (Vec<usize>, per-slot, lex) corner peer to the (Vec<usize>,
/// per-slot, decl) corner [`Self::variant_counts`] opened. The
/// (per-target, per-slot) × (usize, Vec) × (decl, lex) 2×2×2 =
/// 8-corner (arity × return-shape × ordering) cube on the histogram
/// surface now closes at THREE typed primitives across the (arity,
/// return-shape) face — the pre-existing per-target × usize corner
/// [`Self::count_occurrences_of`] at the (arity, return-shape)
/// corner (ordering-collapsed because a per-target scalar has no
/// slot list to order), the per-slot × Vec × decl corner
/// [`Self::variant_counts`], and this lift's per-slot × Vec × lex
/// corner. The remaining (per-target × usize × ordering) corner
/// collapses trivially: the scalar count of one target is
/// ordering-agnostic on the OUTPUT axis. Downstream consumers
/// wanting the "lex-order mode" (variant with maximum multiplicity
/// selected in lex order on ties) or the "lex-order least-frequent"
/// variant (argmin in lex order on ties) compose on this projection
/// through iterator sweep without an additional substrate primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order per-slot histogram projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline
/// `T::sorted_variants().into_iter().map(|v| T::count_occurrences_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-slot × Vec × lex) histogram corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "what does the full per-variant histogram look like,
/// in lex order?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's per-target
/// multiplicity primitive [`Self::count_occurrences_of`] mapped
/// over [`Self::sorted_variants`]. THEORY.md §VI.1 — generation
/// over composition; the per-slot lex-order histogram projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::sorted_variants`] + [`Self::count_occurrences_of`])
/// with an `into_iter().map().collect()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `table(factor(items, levels =
/// sort(levels)))` — the canonical per-level histogram in lex-
/// sorted level order; Julia's `StatsBase.counts(items,
/// sort(levels))` on a lex-sorted level-set returning a per-level
/// `Vector{Int}`; Clojure's `(into (sorted-map) (frequencies
/// coll))` returning a `SortedMap<Element, usize>` per-element
/// histogram in key-sorted order; Python's `collections.Counter(items)
/// .most_common()` after sort keyed on the element; NumPy's
/// `np.bincount(items[np.argsort(labels)], minlength=N)` idiom on a
/// pre-sorted label projection; Coq's `count_occ_by` combinator
/// composed with a `sort`-then-map over a decidable-equality
/// carrier. Translation through pleme-io primitives: the N-ary lex-
/// order per-slot histogram projection on the closed-set trait
/// binds through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] mapped over
/// [`Self::sorted_variants`] — no new dep, no supertrait bound (the
/// [`Self::index_of`] projection [`Self::count_occurrences_of`]
/// threads through replaces the `Eq`/`Hash` bound the standard-
/// library `Counter` / `frequencies` signatures demand), no map-
/// shape carrier allocation (the substrate's [`Self::sorted_variants`]
/// slot-order pins the output to a dense `Vec<usize>` of length
/// [`Self::CARDINALITY`]), no allocation per input position (the
/// underlying primitive folds each position under `filter().count()`
/// without a hash-table probe).
fn sorted_variant_counts(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.map(|v| <Self as ClosedSet>::count_occurrences_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "modal multiplicity" projection —
/// the `usize` MAX-BAR of [`Self::variant_counts`], reporting the
/// largest per-variant occurrence count across [`Self::ALL`], or
/// `0` when `items` is empty. The SCALAR-STATISTIC opener on the
/// (set-level × usize × statistical-aggregate) column of the
/// equivalence-partition surface — the FIRST typed set-level scalar
/// aggregate to reduce the [`Self::variant_counts`] `Vec<usize>`
/// histogram to a single `usize` bar-height statistic past the
/// pre-existing (set-level × usize × cardinality) column of
/// [`Self::count_distinct`] + [`Self::count_missing`] (which count
/// slots of the histogram — the count of non-zero bars and the
/// count of zero bars — rather than the bars' magnitudes).
///
/// Compounding equation with [`Self::is_pairwise_distinct`]: for
/// every slice `items`, `T::max_variant_count(items) <= 1` iff
/// `T::is_pairwise_distinct(items)`. Post-lift the N-ary
/// distinctness predicate becomes a TYPED CONSEQUENCE of the
/// scalar modal-count aggregate at the (`<= 1`) threshold — no
/// per-consumer inline `T::variant_counts(items).iter().all(|&c|
/// c <= 1)` re-composition. Pinned by
/// `max_variant_count_at_most_one_iff_is_pairwise_distinct_across_every_triple`.
///
/// Empty-slice contract: `T::max_variant_count(&[]) == 0`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0` and the max-bar collapses
/// to `0`. Sibling posture to
/// `variant_counts_returns_all_zeros_on_the_empty_slice_across_every_kind`
/// one return-shape axis over: the Vec-return per-slot histogram
/// reports zeros at every slot; this scalar-return statistical
/// aggregate reports zero as the max-bar height. Pinned by
/// `max_variant_count_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::max_variant_count(<T as ClosedSet>::ALL)
/// == 1` UNCONDITIONALLY — the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants as
/// pairwise distinct, so every variant of [`Self::ALL`] appears at
/// exactly one position in the full-set slice and every per-variant
/// occurrence count is `1`, collapsing the max-bar to `1`. Pinned
/// by `max_variant_count_returns_one_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::max_variant_count(&doubled_full_set) == 2` UNCONDITIONALLY
/// — the doubled-full-set slice appends [`Self::ALL`] to itself, so
/// every variant appears at EXACTLY two positions and the max-bar
/// collapses to `2`. Pinned by
/// `max_variant_count_returns_two_on_the_doubled_full_set_across_every_kind`.
///
/// Singleton contract: `T::max_variant_count(&[v]) == 1` on every
/// variant `v` — the singleton slice hits exactly one variant at
/// exactly one position, so the max-bar is `1` (the target
/// variant's bar) with every other bar at `0`. Pinned by
/// `max_variant_count_returns_one_on_every_singleton_slice_across_every_variant`.
///
/// Composition-equality contract: for every slice `items`,
/// `T::max_variant_count(items) ==
/// T::variant_counts(items).into_iter().max().unwrap_or(0)` — the
/// scalar modal-count aggregate agrees with the max-reduction over
/// the decl-order histogram exactly. Sibling posture to
/// `variant_counts_slot_i_equals_count_occurrences_of_variant_i_across_every_triple`
/// one return-shape axis over: the per-slot histogram agrees with
/// the per-target multiplicity projection at every slot; this
/// scalar-return aggregate agrees with the max-reduction of that
/// same per-slot histogram. Pinned by
/// `max_variant_count_equals_max_of_variant_counts_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on BOTH input AND output axes — permuting
/// `items` preserves its multiset of variant identities, and the
/// max-bar is a function of that multiset alone; the scalar
/// return shape carries no ordering to permute on the output side.
/// The (decl, lex) ordering axis collapses on the scalar-return
/// column, and the composition-equality identity holds against
/// both [`Self::variant_counts`] AND [`Self::sorted_variant_counts`]
/// (the two histograms are permutations of each other, and the
/// max-reduction is permutation-invariant). Pinned by
/// `max_variant_count_equals_max_of_sorted_variant_counts_across_every_triple`
/// and
/// `max_variant_count_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Slice-length upper bound: for every slice `items`,
/// `T::max_variant_count(items) <= items.len()` — no per-variant
/// occurrence count can exceed the slice's total length (the sum
/// of all counts is `items.len()` per clause (98)'s partition
/// identity, and the max is bounded by the sum). Pinned by
/// `max_variant_count_is_bounded_above_by_slice_length_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, folded over [`Self::ALL`] via the standard-library
/// [`Iterator::max`] combinator. The composition uses
/// `<Self as ClosedSet>::ALL.iter().copied().map(|v|
/// <Self as ClosedSet>::count_occurrences_of(v, items)).max()
/// .unwrap_or(0)`, so the sweep costs O(T::CARDINALITY * n) on
/// slice arity `n` (mirroring [`Self::variant_counts`]) — no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// map-shape carrier, no allocation (the `Iterator::max` fold
/// yields a scalar). The `unwrap_or(0)` guard is a defensive
/// fallback: `T::CARDINALITY >= 1` by clause (1), so
/// [`Self::ALL`] is non-empty and the `max()` reduction always
/// yields `Some`, but the unwrap-with-fallback keeps the method
/// panic-free even if a future implementor violates clause (1)
/// (which is caught eagerly by [`assert_closed_set_well_formed`]).
///
/// Future consumers that compose against
/// [`Self::max_variant_count`]: a `tatara-check` predicate
/// `(check-phases-no-repeats …)` that verifies a rollout window
/// admits each `WorkloadPhase` at most once by binding
/// `max_variant_count <= 1` (a direct typed alias for the
/// pairwise-distinctness predicate); an LSP diagnostic on a Lisp-
/// author-written closed-set field that renders the modal-count
/// as an author-facing "most common value: X (appears N times)"
/// hint; a Sekiban audit-trail per-window statistical projection
/// carrying the peak per-variant occurrence count as its per-window
/// witness (not just the per-variant histogram vector); a metric-
/// emitter that binds Prometheus-style `max_bar` gauges alongside
/// the per-variant `bar_i` histogram. Each binds to ONE typed
/// N-ary scalar modal-count aggregate on the trait rather than
/// re-deriving `T::variant_counts(items).iter().copied().max()
/// .unwrap_or(0)` inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// usize × statistical-aggregate) column of the equivalence-
/// partition surface, past the pre-existing (set-level × usize ×
/// cardinality) column ([`Self::count_distinct`],
/// [`Self::count_missing`], [`Self::count_occurrences_of`]) and
/// the (per-slot × Vec<usize> × ordering) column
/// ([`Self::variant_counts`], [`Self::sorted_variant_counts`]).
/// The (min-bar, max-bar) direction axis on the statistical-
/// aggregate column becomes the natural next lift — the `min-bar`
/// direction collapses to `0` iff not covering, projecting as a
/// typed alias for [`Self::is_missing_any`] on every non-empty
/// slice; more expressive statistical aggregates (`argmax` /
/// `argmin` returning `Option<Self>` for the modal variant, the
/// count of variants achieving the modal multiplicity, the total
/// variance of the histogram vector) compose on this scalar
/// projection through iterator sweep without an additional
/// substrate primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// scalar modal-count aggregate becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::variant_counts(items).iter().copied().max().unwrap_or(0)`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; the (set-level × usize × statistical-
/// aggregate) modal-count corner was an unnamed inline
/// composition recurring at every prospective downstream "what is
/// the largest per-variant occurrence count?" site pre-lift.
/// Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's per-target multiplicity
/// primitive [`Self::count_occurrences_of`] folded over
/// [`Self::ALL`] under the standard-library `max` reduction.
/// THEORY.md §VI.1 — generation over composition; the scalar
/// modal-count aggregate emerges from the composition of ONE
/// substrate primitive ([`Self::count_occurrences_of`]) with an
/// `iter().copied().map().max()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `max(table(items))` — the canonical
/// max-bar of the per-level histogram on a factor carrier;
/// Julia's `maximum(values(StatsBase.countmap(items)))` on a
/// `Dict{Element, Int}` histogram; Python's `max(collections.Counter
/// (items).values(), default=0)` idiom; Haskell's `maximum . map
/// length . group . sort` on `Ord`-instance carriers; Clojure's
/// `(apply max 0 (vals (frequencies coll)))` composition on a
/// map histogram; NumPy's `np.bincount(items).max(initial=0)`
/// idiom on integer indices; Coq's `list_max ∘ map (count_occ_by
/// eq_dec items) all` composition on a decidable-equality
/// carrier. Translation through pleme-io primitives: the N-ary
/// scalar modal-count aggregate on the closed-set trait binds
/// through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] folded over [`Self::ALL`] under
/// the standard-library `max` reduction — no new dep, no
/// supertrait bound (the [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` /
/// `countmap` / `frequencies` signatures demand), no histogram-
/// carrier allocation (the `max` fold yields a scalar without
/// materializing the intermediate `Vec<usize>` histogram — the
/// per-target counts stream through the fold one at a time).
fn max_variant_count(items: &[Self]) -> usize {
<Self as ClosedSet>::ALL
.iter()
.copied()
.map(|v| <Self as ClosedSet>::count_occurrences_of(v, items))
.max()
.unwrap_or(0)
}
/// The N-ARY ORDERING-AGNOSTIC "least-common multiplicity"
/// projection — the `usize` MIN-BAR of [`Self::variant_counts`],
/// reporting the smallest per-variant occurrence count across
/// [`Self::ALL`], or `0` when `items` is empty. The SCALAR-STATISTIC
/// closer on the (min-bar, max-bar) direction axis of the
/// (set-level × usize × statistical-aggregate) column of the
/// equivalence-partition surface, positioned as the DIRECT
/// (min-bar) PEER to the just-lifted (max-bar) corner
/// [`Self::max_variant_count`]. The (min-bar, max-bar) direction
/// axis of the statistical-aggregate column now closes at both
/// corners: the max-bar reports the LARGEST per-variant occurrence
/// count (the modal multiplicity), and this min-bar reports the
/// SMALLEST per-variant occurrence count (the least-common
/// multiplicity).
///
/// Compounding equation with [`Self::is_missing_any`]: for every
/// slice `items`, `T::min_variant_count(items) == 0` iff
/// `T::is_missing_any(items)`. Post-lift the N-ary missing-any
/// predicate becomes a TYPED CONSEQUENCE of the scalar least-
/// common-multiplicity aggregate at the (`== 0`) threshold — no
/// per-consumer inline `T::variant_counts(items).iter().any(|&c|
/// c == 0)` re-composition. Sibling posture to
/// [`Self::max_variant_count`]'s (`<= 1` iff `is_pairwise_distinct`)
/// compounding equation one direction-axis over: the max-bar at
/// threshold `1` is the typed witness behind the N-ary pairwise-
/// distinctness predicate; the min-bar at threshold `0` is the
/// typed witness behind the N-ary missing-any predicate. Pinned by
/// `min_variant_count_equals_zero_iff_is_missing_any_across_every_triple`.
///
/// Dually: `T::min_variant_count(items) > 0` iff
/// `T::is_covering(items)` — the min-bar direction reports strict
/// positivity iff every variant is present, projecting through the
/// same per-variant occurrence-count composition
/// [`Self::is_covering`] threads through.
///
/// Empty-slice contract: `T::min_variant_count(&[]) == 0`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0` and the min-bar collapses to
/// `0`. Sibling posture to
/// `variant_counts_returns_all_zeros_on_the_empty_slice_across_every_kind`
/// one return-shape axis over: the Vec-return per-slot histogram
/// reports zeros at every slot; this scalar-return statistical
/// aggregate reports zero as the min-bar height. Pinned by
/// `min_variant_count_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract (non-degenerate): `T::min_variant_count(&[v])
/// == 0` on every variant `v` for every closed set of cardinality
/// `>= 2` — a singleton hits exactly one variant at one position,
/// leaving every OTHER variant at zero occurrences, so the min-bar
/// collapses to `0` (the un-hit variants' bar height). Diverges
/// from `T::max_variant_count(&[v]) == 1` on this same corner —
/// the (min, max) direction axis carries load-bearing divergence
/// on the singleton fixpoint: the max reads the target variant's
/// bar, the min reads any of the other variants' bars. Pinned by
/// `min_variant_count_returns_zero_on_every_singleton_slice_when_cardinality_is_at_least_two_across_every_variant`.
///
/// Full-set contract: `T::min_variant_count(<T as ClosedSet>::ALL)
/// == 1` UNCONDITIONALLY — the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants as
/// pairwise distinct, so every variant of [`Self::ALL`] appears at
/// exactly one position in the full-set slice and every per-variant
/// occurrence count is `1`, collapsing the min-bar to `1`. Pinned
/// by `min_variant_count_returns_one_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::min_variant_count(&doubled_full_set) == 2` UNCONDITIONALLY
/// — the doubled-full-set slice appends [`Self::ALL`] to itself, so
/// every variant appears at EXACTLY two positions and the min-bar
/// collapses to `2`. Pinned by
/// `min_variant_count_returns_two_on_the_doubled_full_set_across_every_kind`.
///
/// Composition-equality contract: for every slice `items`,
/// `T::min_variant_count(items) ==
/// T::variant_counts(items).into_iter().min().unwrap_or(0)` — the
/// scalar least-common-multiplicity aggregate agrees with the min-
/// reduction over the decl-order histogram exactly. Pinned by
/// `min_variant_count_equals_min_of_variant_counts_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on BOTH input AND output axes — permuting
/// `items` preserves its multiset of variant identities, and the
/// min-bar is a function of that multiset alone; the scalar
/// return shape carries no ordering to permute on the output side.
/// The (decl, lex) ordering axis collapses on the scalar-return
/// column, and the composition-equality identity holds against
/// both [`Self::variant_counts`] AND [`Self::sorted_variant_counts`]
/// (the two histograms are permutations of each other, and the
/// min-reduction is permutation-invariant). Pinned by
/// `min_variant_count_equals_min_of_sorted_variant_counts_across_every_triple`
/// and
/// `min_variant_count_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Max-bar upper bound: for every slice `items`,
/// `T::min_variant_count(items) <= T::max_variant_count(items)`
/// — the min-reduction over the per-slot histogram is bounded
/// above by the max-reduction over the same histogram. Pinned
/// by `min_variant_count_is_bounded_above_by_max_variant_count_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, folded over [`Self::ALL`] via the standard-library
/// [`Iterator::min`] combinator. The composition uses
/// `<Self as ClosedSet>::ALL.iter().copied().map(|v|
/// <Self as ClosedSet>::count_occurrences_of(v, items)).min()
/// .unwrap_or(0)`, mirroring [`Self::max_variant_count`] byte-for-
/// byte with `.min()` in place of `.max()`. Cost is
/// O(T::CARDINALITY * n) on slice arity `n` — no `PartialEq`/
/// `Eq`/`Hash` supertrait bound (the trait's minimal `Sized +
/// Copy + 'static` supertrait pair stays untouched), no map-
/// shape carrier, no allocation (the `Iterator::min` fold yields
/// a scalar). The `unwrap_or(0)` guard is a defensive fallback:
/// `T::CARDINALITY >= 1` by clause (1), so [`Self::ALL`] is non-
/// empty and the `min()` reduction always yields `Some`, but the
/// unwrap-with-fallback keeps the method panic-free even if a
/// future implementor violates clause (1) (which is caught eagerly
/// by [`assert_closed_set_well_formed`]).
///
/// Future consumers that compose against
/// [`Self::min_variant_count`]: a `tatara-check` predicate
/// `(check-phases-cover-every-variant …)` that verifies every
/// `WorkloadPhase` appears at least once in a rollout window by
/// binding `min_variant_count >= 1` (a direct typed alias for the
/// N-ary covering predicate); an LSP diagnostic on a Lisp-author-
/// written closed-set field that renders "least common value: X
/// (appears N times)" as an author-facing hint; a Sekiban audit-
/// trail per-window statistical projection carrying the smallest
/// per-variant occurrence count as its per-window witness
/// (surfacing the LEAST-visited variant on a rollout window); a
/// metric-emitter that binds Prometheus-style `min_bar` gauges
/// alongside the per-variant `bar_i` histogram + the just-lifted
/// `max_bar` gauge. Each binds to ONE typed N-ary scalar least-
/// common-multiplicity aggregate on the trait rather than re-
/// deriving `T::variant_counts(items).iter().copied().min()
/// .unwrap_or(0)` inline per callsite.
///
/// Compounding closure: this projection CLOSES the (min-bar, max-
/// bar) direction axis of the (set-level × usize × statistical-
/// aggregate) column of the equivalence-partition surface at the
/// (min-bar) corner peer to [`Self::max_variant_count`]. Both
/// direction corners of the statistical-aggregate column now bind
/// through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] folded over [`Self::ALL`] under
/// distinct-directional standard-library reductions (`max` vs
/// `min`). Downstream statistical aggregates naturally compose
/// from this pair — the (max, min) pair projects the histogram
/// range; the mean / total / variance shapes compose on the same
/// per-target multiplicity primitive under `sum` / `fold`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// scalar least-common-multiplicity aggregate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline
/// `T::variant_counts(items).iter().copied().min().unwrap_or(0)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × usize × statistical-
/// aggregate) min-bar corner was an unnamed inline composition
/// recurring at every prospective downstream "what is the smallest
/// per-variant occurrence count?" or "is every variant hit at
/// least once?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's per-target
/// multiplicity primitive [`Self::count_occurrences_of`] folded
/// over [`Self::ALL`] under the standard-library `min` reduction.
/// THEORY.md §VI.1 — generation over composition; the scalar
/// least-common-multiplicity aggregate emerges from the
/// composition of ONE substrate primitive
/// ([`Self::count_occurrences_of`]) with an
/// `iter().copied().map().min()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `min(table(items))` — the canonical
/// min-bar of the per-level histogram on a factor carrier;
/// Julia's `minimum(values(StatsBase.countmap(items)))` on a
/// `Dict{Element, Int}` histogram; Python's `min(collections.Counter
/// (items).values(), default=0)` idiom; Haskell's `minimum . map
/// length . group . sort` on `Ord`-instance carriers; Clojure's
/// `(apply min 0 (vals (frequencies coll)))` composition on a
/// map histogram; NumPy's `np.bincount(items, minlength=N).min()`
/// idiom on integer indices with a min-length pad so the un-hit
/// bars register as zeros (the same forcing this projection binds
/// through [`Self::ALL`] to enumerate every bar-slot); Coq's
/// `list_min ∘ map (count_occ_by eq_dec items) all` composition
/// on a decidable-equality carrier. Translation through pleme-io
/// primitives: the N-ary scalar least-common-multiplicity
/// aggregate on the closed-set trait binds through the substrate's
/// per-target multiplicity primitive [`Self::count_occurrences_of`]
/// folded over [`Self::ALL`] under the standard-library `min`
/// reduction — no new dep, no supertrait bound, no histogram-
/// carrier allocation (the `min` fold yields a scalar without
/// materializing the intermediate `Vec<usize>` histogram — the
/// per-target counts stream through the fold one at a time). The
/// [`Self::ALL`]-enumeration replaces the NumPy `minlength=N` pad:
/// every ambient variant contributes a bar to the fold, so an un-
/// hit variant registers a `0` and forces the min-bar to `0`
/// without a per-bar zero-padding step on the input side.
fn min_variant_count(items: &[Self]) -> usize {
<Self as ClosedSet>::ALL
.iter()
.copied()
.map(|v| <Self as ClosedSet>::count_occurrences_of(v, items))
.min()
.unwrap_or(0)
}
/// The N-ARY ORDERING-AGNOSTIC "variant-count range" projection —
/// the `(usize, usize)` PAIR of the histogram's (min-bar, max-bar)
/// endpoints projected onto the trait surface as ONE call. The
/// PAIR-RETURN endpoint-anchor opener on the (set-level ×
/// statistical-aggregate) column of the equivalence-partition
/// surface, positioned as the direct TUPLE-RETURN peer to the
/// two just-closed scalar-return direction corners
/// [`Self::min_variant_count`] + [`Self::max_variant_count`] one
/// return-shape axis over. The (set-level × statistical-aggregate)
/// × (`usize`-scalar, `(usize, usize)`-pair) 2-corner return-shape
/// face on the equivalence-partition surface now opens the pair-
/// return endpoint-anchor column past the (min-bar) + (max-bar)
/// scalar corners.
///
/// Direction-axis convention: the returned tuple's slot `0` is the
/// (min-bar), slot `1` is the (max-bar) — the `(min, max)`
/// convention mirrors the standard-library
/// [`Iterator::min`]/[`Iterator::max`] pair AND the pre-existing
/// [`Self::endpoint_indices`]'s `(head, tail)` convention one
/// axis-family over on the label-anchor surface. The two tuple
/// slots are the DIRECTION endpoints of the histogram range on the
/// per-variant occurrence-count axis: slot `0` reports the LEAST-
/// common multiplicity, slot `1` reports the MODAL multiplicity.
///
/// Composition-equality contract: for every slice `items`,
/// `T::variant_count_range(items) == (T::min_variant_count(items),
/// T::max_variant_count(items))` — the pair-return endpoint-anchor
/// projection binds through the two just-closed direction corners
/// on the (set-level × statistical-aggregate) column BYTE-FOR-BYTE.
/// Pinned by `variant_count_range_equals_min_max_pair_across_every_triple`.
///
/// Direction-axis order invariance: for every slice `items`,
/// `T::variant_count_range(items).0 <= T::variant_count_range(items).1`
/// UNCONDITIONALLY — the (min-bar) endpoint is bounded above by
/// the (max-bar) endpoint on every slice because `min(xs) <=
/// max(xs)` on every non-empty carrier `xs` (and `T::CARDINALITY
/// >= 1` by clause (1) guarantees non-emptiness of the histogram
/// carrier). Pinned by
/// `variant_count_range_first_bounded_above_by_second_across_every_triple`.
///
/// Empty-slice contract: `T::variant_count_range(&[]) == (0, 0)`
/// UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant occurrence count is `0` and BOTH direction
/// endpoints collapse to `0`. The tuple's slot-0 and slot-1
/// coincide at the empty-slice fixpoint because a constant-`0`
/// histogram has degenerate range. Pinned by
/// `variant_count_range_returns_zero_zero_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::variant_count_range(<T as ClosedSet>::ALL)
/// == (1, 1)` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant of [`Self::ALL`]
/// appears at exactly one position in the full-set slice and every
/// per-variant occurrence count is `1`, collapsing BOTH direction
/// endpoints to `1`. The tuple's slot-0 and slot-1 coincide at the
/// full-set fixpoint because a constant-`1` histogram has
/// degenerate range. Pinned by
/// `variant_count_range_returns_one_one_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract: `T::variant_count_range(&doubled)
/// == (2, 2)` UNCONDITIONALLY — the doubled-full-set slice appends
/// [`Self::ALL`] to itself, so every variant appears at EXACTLY two
/// positions and BOTH direction endpoints collapse to `2`. The
/// tuple's slot-0 and slot-1 coincide at the doubled-full-set
/// fixpoint because a constant-`2` histogram has degenerate range.
/// Pinned by
/// `variant_count_range_returns_two_two_on_the_doubled_full_set_across_every_kind`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on BOTH input AND output axes — permuting
/// `items` preserves its multiset of variant identities, and the
/// (min-bar, max-bar) pair is a function of that multiset alone;
/// the pair-return shape carries no ordering to permute on the
/// output side (the `(min, max)` convention pins slot roles by
/// direction, not by input order). Pinned by
/// `variant_count_range_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Compounding equations: the pair-return endpoint-anchor
/// projection collapses to the DEGENERATE (equal-slot) tuple iff
/// the histogram is UNIFORM — for every slice `items`,
/// `T::variant_count_range(items).0 == T::variant_count_range(items).1`
/// iff every per-variant occurrence count coincides. The three
/// canonical fixpoints (empty → `(0, 0)`, full → `(1, 1)`,
/// doubled → `(2, 2)`) exercise the degenerate-tuple case at three
/// distinct scalar values (`0`, `1`, `2`) so a future override
/// that folds onto a constant tuple bifurcates at the fixpoint
/// with the diverging value. The non-degenerate case is exercised
/// by every singleton `T::variant_count_range(&[v])` on a closed
/// set of cardinality `>= 2`, which returns `(0, 1)` (all other
/// variants miss, the target variant hits once) — the tuple's
/// slot-0 records the UN-HIT variants' bar, slot-1 records the
/// TARGET variant's bar. Sibling posture to
/// [`Self::endpoint_indices`] on the label-anchor surface one
/// axis-family over — [`Self::endpoint_indices`] packages the
/// (head-decl-slot, tail-decl-slot) pair on the (usize, usize)
/// pair-endpoint row of the declaration-axis label-anchor
/// aggregation matrix; this method packages the (min-bar, max-bar)
/// pair on the (usize, usize) pair-endpoint row of the set-level
/// statistical-aggregate matrix. Both close the pair-endpoint
/// row at their respective axis-family through a natural
/// composition of the two direction corners.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's two just-closed direction corners on the (set-level
/// × usize × statistical-aggregate) column — the composition uses
/// `(<Self as ClosedSet>::min_variant_count(items), <Self as
/// ClosedSet>::max_variant_count(items))` verbatim. Cost is
/// O(T::CARDINALITY * n) on slice arity `n` (folded through the
/// two direction corners, each of which walks `T::ALL` once and
/// sums per-target multiplicities over `items`) — no `PartialEq`/
/// `Eq`/`Hash` supertrait bound (the trait's minimal `Sized +
/// Copy + 'static` supertrait pair stays untouched), no map-shape
/// carrier, no allocation (the pair-return shape is a bare
/// `(usize, usize)` tuple).
///
/// Future consumers that compose against
/// [`Self::variant_count_range`]: a `tatara-check` predicate
/// `(check-phases-histogram-range …)` that emits the (least, most)
/// visited-variant multiplicity pair for a rollout window on a
/// `WorkloadPhase` sweep, so an operator sees "0 → 3" or "2 → 5"
/// at a glance rather than two separate scalar readouts; a
/// Prometheus-style metric emitter that binds the
/// `variant_count_range` gauge pair (min-bar + max-bar side-by-
/// side) rather than binding two separate scalar-gauge queries; a
/// Sekiban audit-trail per-window statistical projection that
/// surfaces the histogram range as one composite witness rather
/// than two scalar-witnesses; an LSP diagnostic that renders "0..3
/// visits" as an author-facing hint on a Lisp-author-written
/// closed-set field; a tatara-reconciler status printer that
/// projects a `Vec<Process>` collection's PhaseKind histogram
/// range onto the operator's dashboard as one pair. Each binds to
/// ONE typed pair-return endpoint-anchor projection on the trait
/// rather than re-deriving the `(min_variant_count(items),
/// max_variant_count(items))` pair inline per callsite.
///
/// Compounding closure: this projection OPENS the pair-return
/// column past the (min-bar) + (max-bar) scalar corners on the
/// (set-level × statistical-aggregate) row of the equivalence-
/// partition surface. The (set-level × statistical-aggregate) ×
/// (`usize`-scalar, `(usize, usize)`-pair) 2-corner return-shape
/// face now opens the pair-return endpoint-anchor column at the
/// direct tuple-endpoint peer to the two scalar direction corners.
/// Downstream range-based aggregates naturally compose from this
/// pair — the histogram spread (max - min saturated) and the
/// uniformity predicate (`min == max`) both bind through the same
/// pair-endpoint primitive under distinct scalar reductions,
/// mirroring the earlier `(head, tail)` label-anchor pair's
/// composition through `sorted_endpoints` /
/// `endpoint_indices` / `endpoint_labels`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// pair-return endpoint-anchor projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `(T::min_variant_count(items), T::max_variant_count
/// (items))` composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (pair-return endpoint-
/// anchor) corner was an unnamed inline composition recurring at
/// every prospective downstream "what is the histogram's range?"
/// site pre-lift. Naming it on the trait makes the projection a
/// TYPED CONSEQUENCE of the substrate's two direction corners
/// packaged as one pair-return tuple. THEORY.md §VI.1 — generation
/// over composition; the pair-return endpoint-anchor projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::min_variant_count`] + [`Self::max_variant_count`])
/// packaged as one atomic tuple, not as a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: NumPy's `(bincount(items).min(),
/// bincount(items).max())` idiom returned as one tuple; R's
/// `range(table(items))` on a factor carrier — returns the
/// two-endpoint vector of the histogram's per-level counts;
/// Julia's `extrema(values(StatsBase.countmap(items)))` on a
/// `Dict{Element, Int}` histogram; Python's `(min(c.values()),
/// max(c.values()))` idiom on a `collections.Counter`; Haskell's
/// `(minimum . map length . group . sort, maximum . map length .
/// group . sort)` pair on `Ord`-instance carriers; Clojure's
/// `(let [vs (vals (frequencies coll))] [(apply min 0 vs) (apply
/// max 0 vs)])` composition on a map histogram; Coq's `(list_min
/// ∘ counts, list_max ∘ counts)` pair on a decidable-equality
/// carrier. Translation through pleme-io primitives: the N-ary
/// pair-return endpoint-anchor projection on the closed-set trait
/// binds through the two direction corners of the set-level
/// statistical-aggregate column packaged as one atomic tuple —
/// no new dep, no supertrait bound, no histogram-carrier
/// allocation (the pair-return shape yields a bare
/// `(usize, usize)` tuple without materializing the intermediate
/// `Vec<usize>` histogram; the two direction corners each stream
/// through their own fold one at a time).
fn variant_count_range(items: &[Self]) -> (usize, usize) {
(
<Self as ClosedSet>::min_variant_count(items),
<Self as ClosedSet>::max_variant_count(items),
)
}
/// The N-ARY ORDERING-AGNOSTIC "uniform histogram" predicate —
/// `true` iff every per-variant occurrence count in `items`
/// coincides at ONE scalar bar-height, computed as the just-
/// lifted pair-return [`Self::variant_count_range`] projection's
/// two direction endpoints agreeing byte-for-byte. The BOOL-
/// RETURN UNIFORMITY closer on the (set-level × statistical-
/// aggregate) row of the equivalence-partition surface,
/// positioned as the direct SCALAR-REDUCTION of the just-opened
/// pair-return endpoint-anchor corner
/// [`Self::variant_count_range`] through the (slot-0 == slot-1)
/// tuple-projection equality. The (set-level × statistical-
/// aggregate) × (`usize`-scalar, `(usize, usize)`-pair,
/// `bool`-scalar) 3-corner return-shape face on the equivalence-
/// partition surface now closes the bool-return uniformity column
/// past the two scalar direction corners
/// [`Self::min_variant_count`] + [`Self::max_variant_count`] and
/// past the pair-return endpoint-anchor corner
/// [`Self::variant_count_range`], packaging the histogram's
/// (min-bar == max-bar) degeneracy-check as ONE bool.
///
/// Composition-equality contract: for every slice `items`,
/// `T::is_uniform(items)` iff `T::variant_count_range(items).0 ==
/// T::variant_count_range(items).1` — the bool-return uniformity
/// projection binds through the pair-return endpoint-anchor
/// projection's slot-equality BYTE-FOR-BYTE. Equivalently, iff
/// `T::min_variant_count(items) == T::max_variant_count(items)`
/// via the direction-corner pair. Pinned by
/// `is_uniform_agrees_with_variant_count_range_slot_equality_across_every_triple`
/// and `is_uniform_agrees_with_min_max_equality_across_every_triple`.
///
/// Empty-slice contract: `T::is_uniform(&[]) == true`
/// UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant occurrence count is `0`, and a constant-`0`
/// histogram is trivially uniform. The uniformity predicate
/// reaches its degenerate-tuple TRUE fixpoint at the empty-slice
/// endpoint through the pair-return projection collapsing to
/// `(0, 0)`. Pinned by
/// `is_uniform_returns_true_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::is_uniform(<T as ClosedSet>::ALL) ==
/// true` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position in the full-set
/// slice and every per-variant occurrence count is `1`,
/// collapsing the histogram to a constant-`1` bar and the
/// uniformity predicate to TRUE. Pinned by
/// `is_uniform_returns_true_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract: `T::is_uniform(&doubled) == true`
/// UNCONDITIONALLY — the doubled-full-set slice appends
/// [`Self::ALL`] to itself, so every variant appears at EXACTLY
/// two positions, the histogram collapses to a constant-`2` bar,
/// and the uniformity predicate collapses to TRUE. Pinned by
/// `is_uniform_returns_true_on_the_doubled_full_set_across_every_kind`.
///
/// Singleton NON-UNIFORMITY contract: for every variant `v` on a
/// closed set of cardinality `>= 2`, `T::is_uniform(&[v]) ==
/// false` — a singleton hits exactly one variant at one position,
/// so the histogram is `(0, …, 0, 1, 0, …, 0)` with a strictly-
/// positive (max == 1) bar at the hit variant and a strictly-
/// zero (min == 0) bar at every other variant. The uniformity
/// predicate collapses to FALSE because `min == 0 != 1 == max`.
/// The singleton is the SMALLEST-arity NON-uniform slice on a
/// cardinality-`>= 2` closed set — the three canonical constant-
/// histogram fixpoints (empty, full, doubled) all yield uniform
/// histograms, so the singleton on a `>= 2` closed set is the
/// primary non-degenerate drift catcher for a `_ => true`
/// override. Pinned by
/// `is_uniform_returns_false_on_every_singleton_slice_when_cardinality_is_at_least_two_across_every_variant`.
///
/// Ordering-axis invariance: the predicate is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the
/// (min-bar, max-bar) endpoints are functions of that multiset
/// alone; the bool-return shape carries no ordering to permute
/// on the output side. The (declaration, lex) ordering axis
/// collapses on this projection. Pinned by
/// `is_uniform_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Compounding equations: the bool-return uniformity predicate
/// collapses to TRUE at the three canonical constant-histogram
/// fixpoints (empty → `(0, 0)` → true; full → `(1, 1)` → true;
/// doubled → `(2, 2)` → true), all inherited from the pair-
/// return corner's degenerate-tuple contracts. The predicate
/// separates from the tighter [`Self::is_permutation_of_all`]
/// predicate at the (uniformity ∧ non-empty-max) corner: every
/// permutation-of-all IS uniform (the histogram is constant-`1`),
/// but not every uniform slice is a permutation (the constant-`0`
/// empty slice and the constant-`2` doubled full set are BOTH
/// uniform without being permutations). The predicate collapses
/// to `T::is_permutation_of_all(items)` under the additional
/// (max-bar == 1) side-constraint via
/// `T::is_uniform(items) && T::variant_count_range(items).1 == 1`
/// iff `T::is_permutation_of_all(items)`. Pinned by
/// `is_uniform_conjunction_with_max_equal_one_iff_is_permutation_of_all_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's just-lifted pair-return endpoint-anchor projection
/// [`Self::variant_count_range`] — the composition uses one
/// `usize`-equality on the tuple's two slots. Cost is
/// O(T::CARDINALITY * n) on slice arity `n` (folded through the
/// pair-return corner's two direction folds, each of which walks
/// `T::ALL` once and sums per-target multiplicities over `items`)
/// — no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no histogram-carrier allocation (the bool-return
/// shape is a bare `bool` scalar without materializing the
/// intermediate `Vec<usize>` histogram).
///
/// Future consumers that compose against [`Self::is_uniform`]: a
/// `tatara-check` predicate `(check-phases-are-balanced …)` that
/// asserts a rollout window visits every `WorkloadPhase` variant
/// the same number of times (catching a skewed rollout where one
/// phase runs more often than its siblings); a Prometheus-style
/// alert on a `Vec<Process>` collection whose PhaseKind
/// histogram becomes non-uniform (fires when one phase saturates
/// the fleet); a Sekiban audit-trail per-window uniformity
/// witness on a classification poset; an LSP diagnostic on a
/// Lisp-author-written closed-set field that reports "your
/// severities are unevenly represented" when the value multiset
/// falls short of uniform coverage; a chi-square test's null-
/// hypothesis short-circuit that skips the full statistic when
/// the histogram is exactly uniform. Each binds to ONE typed
/// bool-return uniformity projection on the trait rather than
/// re-deriving the pair-endpoint-equality inline per callsite.
///
/// Compounding closure: this projection CLOSES the bool-return
/// column past the pair-return endpoint-anchor corner on the
/// (set-level × statistical-aggregate) row of the equivalence-
/// partition surface. The (set-level × statistical-aggregate) ×
/// (`usize`-scalar, `(usize, usize)`-pair, `bool`-scalar) 3-
/// corner return-shape face now closes at the bool-return
/// uniformity corner as the direct scalar-reduction of the pair-
/// return endpoint-anchor projection. Downstream range-based
/// predicates naturally compose from this bool — the histogram
/// non-uniformity witness (`!T::is_uniform(items)`) and the
/// (uniform ∧ full-coverage) partition-check (`T::is_uniform &&
/// T::is_covering`) both bind through the same bool-return
/// primitive under standard boolean combinators.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// bool-return uniformity predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::variant_count_range(items).0 ==
/// T::variant_count_range(items).1` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (bool-return uniformity) corner was an unnamed inline
/// composition recurring at every prospective downstream "is
/// this histogram flat?" site pre-lift. Naming it on the trait
/// makes the predicate a TYPED CONSEQUENCE of the substrate's
/// pair-return endpoint-anchor projection packaged as one bool
/// scalar. THEORY.md §VI.1 — generation over composition; the
/// bool-return uniformity predicate emerges from the composition
/// of ONE substrate primitive ([`Self::variant_count_range`])
/// with the standard-library `usize`-equality combinator on the
/// tuple's two slots, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `np.all(bincount(items) ==
/// bincount(items)[0])` idiom on a categorical histogram; R's
/// `length(unique(table(items))) == 1` composition on a factor
/// carrier; Julia's `allequal(values(StatsBase.countmap(items)))`
/// on a `Dict{Element, Int}` histogram; Python's
/// `len(set(collections.Counter(items).values())) <= 1` idiom on
/// a Counter; Haskell's `all (== head hs) hs where hs = map
/// length . group . sort $ items` on `Ord`-instance carriers;
/// Clojure's `(apply = (vals (frequencies coll)))` composition
/// on a map histogram; Coq's `forall v w, count v items = count
/// w items` universal on a decidable-equality carrier;
/// statistics' chi-square null-hypothesis "expected == observed"
/// short-circuit. Translation through pleme-io primitives: the
/// N-ary bool-return uniformity predicate on the closed-set
/// trait binds through the just-lifted pair-return endpoint-
/// anchor projection's slot-equality — no new dep, no supertrait
/// bound, no histogram-carrier allocation (the bool-return
/// shape yields a bare `bool` without materializing the
/// intermediate `Vec<usize>` histogram; the pair-return corner
/// streams through its two direction folds one at a time).
fn is_uniform(items: &[Self]) -> bool {
let (min_bar, max_bar) = <Self as ClosedSet>::variant_count_range(items);
min_bar == max_bar
}
/// The N-ARY ORDERING-AGNOSTIC "variant count span" projection —
/// the `usize` NON-NEGATIVE scalar-difference of the just-lifted
/// pair-return [`Self::variant_count_range`] projection's two
/// direction endpoints, computed as `max_bar - min_bar` on the
/// (max-bar, min-bar) pair. The SCALAR-DIFFERENCE range-width
/// opener on the (set-level × statistical-aggregate) row of the
/// equivalence-partition surface, positioned as the second
/// SCALAR REDUCTION of the just-opened pair-return endpoint-
/// anchor corner [`Self::variant_count_range`] through the
/// (slot-1 - slot-0) tuple-projection SATURATED DIFFERENCE
/// (the pair-return corner pins slot-0 <= slot-1 by clause
/// (102)'s direction-axis-order arm, so the difference is
/// non-negative and no saturation ever fires). Peer posture to
/// [`Self::is_uniform`] one return-shape axis over: the bool-
/// return uniformity corner reduces the pair through
/// slot-EQUALITY (`min == max`), yielding a bare `bool`; this
/// usize-return span corner reduces the SAME pair through
/// slot-SUBTRACTION (`max - min`), yielding a bare `usize`
/// range-width. The (set-level × statistical-aggregate) ×
/// (`usize`-scalar-direction, `(usize, usize)`-pair,
/// `bool`-scalar, `usize`-scalar-difference) 4-corner return-
/// shape face on the equivalence-partition surface now opens
/// its FOURTH corner as the direct SCALAR-DIFFERENCE reduction
/// of the pair-return corner past the two direction corners,
/// the pair-return corner, and the bool-return uniformity
/// corner.
///
/// Composition-equality contract: for every slice `items`,
/// `T::variant_count_span(items) ==
/// T::variant_count_range(items).1 - T::variant_count_range(items).0`
/// — the scalar-difference range-width projection binds through
/// the pair-return endpoint-anchor projection's slot-subtraction
/// BYTE-FOR-BYTE. Equivalently, `T::variant_count_span(items)
/// == T::max_variant_count(items) - T::min_variant_count(items)`
/// via the direction-corner pair. Pinned by
/// `variant_count_span_agrees_with_variant_count_range_slot_subtraction_across_every_triple`
/// and `variant_count_span_agrees_with_max_minus_min_across_every_triple`.
///
/// Empty-slice contract: `T::variant_count_span(&[]) == 0`
/// UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant occurrence count is `0`, the pair-return
/// corner collapses to `(0, 0)`, and the difference collapses
/// to `0 - 0 == 0`. The span reaches its degenerate-tuple ZERO
/// fixpoint at the empty-slice endpoint. Pinned by
/// `variant_count_span_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::variant_count_span(<T as ClosedSet>::ALL)
/// == 0` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position, the pair-
/// return corner collapses to `(1, 1)`, and the difference
/// collapses to `1 - 1 == 0`. Pinned by
/// `variant_count_span_returns_zero_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract: `T::variant_count_span(&doubled)
/// == 0` UNCONDITIONALLY — the doubled-full-set slice appends
/// [`Self::ALL`] to itself, so every variant appears at EXACTLY
/// two positions, the pair-return corner collapses to `(2, 2)`,
/// and the difference collapses to `2 - 2 == 0`. Pinned by
/// `variant_count_span_returns_zero_on_the_doubled_full_set_across_every_kind`.
///
/// Singleton SPAN-EQUALS-ONE contract: for every variant `v` on
/// a closed set of cardinality `>= 2`, `T::variant_count_span(&[v])
/// == 1` — a singleton hits exactly one variant at one position,
/// leaving every OTHER variant at zero occurrences, so the pair-
/// return corner collapses to `(0, 1)` and the difference
/// collapses to `1 - 0 == 1`. The singleton is the SMALLEST-arity
/// non-uniform slice on a cardinality-`>= 2` closed set — the
/// three canonical constant-histogram fixpoints (empty, full,
/// doubled) all yield span `0`, so the singleton on a `>= 2`
/// closed set is the primary non-degenerate drift catcher for a
/// `_ => 0` override. Pinned by
/// `variant_count_span_returns_one_on_every_singleton_slice_when_cardinality_is_at_least_two_across_every_variant`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the
/// (min-bar, max-bar) endpoints are functions of that multiset
/// alone; the scalar-difference reduction carries no ordering to
/// permute on the output side. The (declaration, lex) ordering
/// axis collapses on this projection. Pinned by
/// `variant_count_span_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Compounding equations: the scalar-difference span collapses
/// to `0` at the three canonical constant-histogram fixpoints
/// (empty → `(0, 0)` → `0`; full → `(1, 1)` → `0`; doubled →
/// `(2, 2)` → `0`), all inherited from the pair-return corner's
/// degenerate-tuple contracts. The (span == 0) predicate agrees
/// byte-for-byte with [`Self::is_uniform`] via the (slot-
/// equality → zero-difference) tuple-projection reduction:
/// `T::variant_count_span(items) == 0 iff T::is_uniform(items)`
/// — the span binds through the SAME pair-return corner as the
/// bool-return uniformity projection but under a DIFFERENT
/// scalar reduction (SUBTRACTION vs. EQUALITY). Pinned by
/// `variant_count_span_equals_zero_iff_is_uniform_across_every_triple`.
/// The span is bounded above by the pair-return corner's max
/// slot: `T::variant_count_span(items) <=
/// T::variant_count_range(items).1` on every slice — the
/// difference `max - min` is bounded above by `max` itself
/// (since `min >= 0`). Pinned by
/// `variant_count_span_is_bounded_above_by_max_variant_count_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// just-lifted pair-return endpoint-anchor projection
/// [`Self::variant_count_range`] — the composition uses ONE
/// `usize`-subtraction on the tuple's two slots, with the
/// slot-0 <= slot-1 direction-axis-order pinned by clause (102)
/// guaranteeing the subtraction never underflows. Cost is
/// O(T::CARDINALITY * n) on slice arity `n` (folded through the
/// pair-return corner's two direction folds, each of which walks
/// `T::ALL` once and sums per-target multiplicities over `items`)
/// — no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no histogram-carrier allocation (the scalar-
/// difference shape yields a bare `usize` without materializing
/// the intermediate `Vec<usize>` histogram; the pair-return
/// corner streams through its two direction folds one at a time).
///
/// Future consumers that compose against [`Self::variant_count_span`]:
/// a `tatara-check` predicate `(check-phases-are-balanced-within
/// K …)` that asserts a rollout window's PhaseKind histogram
/// spread stays within a fixed tolerance `K` (catching a
/// rollout that skews too far even without hitting full
/// non-uniformity); a Prometheus-style spread-gauge on a
/// `Vec<Process>` collection whose PhaseKind histogram span
/// exceeds a threshold (fires when one phase runs far more
/// often than another without necessarily saturating the fleet);
/// a Sekiban audit-trail per-window spread witness on a
/// classification poset that surfaces the spread as one scalar
/// gauge rather than a pair-gauge; an LSP diagnostic on a
/// Lisp-author-written closed-set field that reports the
/// histogram spread as one scalar hint ("your severities range
/// by 3 visits") rather than as an endpoint pair. Each binds to
/// ONE typed scalar-return span projection on the trait rather
/// than re-deriving the `(max_variant_count(items) -
/// min_variant_count(items))` subtraction inline per callsite.
///
/// Compounding closure: this projection OPENS the scalar-
/// difference reduction column past the pair-return endpoint-
/// anchor corner and the bool-return uniformity corner on the
/// (set-level × statistical-aggregate) row of the equivalence-
/// partition surface. The (set-level × statistical-aggregate) ×
/// (`usize`-scalar-direction, `(usize, usize)`-pair,
/// `bool`-scalar, `usize`-scalar-difference) 4-corner return-
/// shape face now opens the fourth (scalar-difference range-
/// width) corner as the direct SCALAR-DIFFERENCE reduction of
/// the pair-return endpoint-anchor projection past the two
/// scalar direction corners and the pair-return corner. The
/// (uniformity, span) pair on the pair-return corner's TWO
/// scalar reductions gives downstream consumers a canonical
/// (bool, usize) surface for both the DEGENERACY witness and
/// the DEGREE-OF-DEGENERACY witness of the histogram.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// scalar-difference range-width projection becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline `T::variant_count_range(items).1 -
/// T::variant_count_range(items).0` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (scalar-difference range-width) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "how far apart are the histogram's endpoints?" site pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's pair-return endpoint-anchor
/// projection packaged as one scalar. THEORY.md §VI.1 —
/// generation over composition; the scalar-difference range-
/// width projection emerges from the composition of ONE
/// substrate primitive ([`Self::variant_count_range`]) with the
/// standard-library `usize`-subtraction combinator on the
/// tuple's two slots, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: NumPy's `bincount(items).ptp()` (peak-
/// to-peak) on a categorical histogram; R's `diff(range(table
/// (items)))` composition on a factor carrier; Julia's `let vs
/// = values(StatsBase.countmap(items)); maximum(vs) -
/// minimum(vs)` on a `Dict{Element, Int}` histogram; Python's
/// `max(c.values()) - min(c.values())` idiom on a
/// `collections.Counter`; Haskell's `let hs = map length .
/// group . sort $ items in maximum hs - minimum hs` on
/// `Ord`-instance carriers; Clojure's `(let [vs (vals
/// (frequencies coll))] (- (apply max vs) (apply min vs)))`
/// composition on a map histogram; MATLAB's `range(bincount)`
/// idiom. Translation through pleme-io primitives: the N-ary
/// scalar-difference range-width projection on the closed-set
/// trait binds through the just-lifted pair-return endpoint-
/// anchor projection's slot-subtraction — no new dep, no
/// supertrait bound, no histogram-carrier allocation (the
/// scalar-difference shape yields a bare `usize` without
/// materializing the intermediate `Vec<usize>` histogram; the
/// pair-return corner streams through its two direction folds
/// one at a time).
fn variant_count_span(items: &[Self]) -> usize {
let (min_bar, max_bar) = <Self as ClosedSet>::variant_count_range(items);
max_bar - min_bar
}
/// The N-ARY ORDERING-AGNOSTIC "modal variant" projection — the
/// `Option<Self>` DECLARATION-ORDER-FIRST ARGMAX over the
/// [`Self::variant_counts`] histogram, reporting the FIRST variant
/// of [`Self::ALL`] (walked in declaration order) whose per-target
/// count equals [`Self::max_variant_count`], or `None` when `items`
/// is empty. The ARGMAX-VARIANT opener on the (set-level ×
/// `Option<Self>` × statistical-aggregate) column of the
/// equivalence-partition surface, positioned as the FIRST typed
/// `Option<Self>`-return aggregate past the (set-level × `usize` ×
/// statistical-aggregate) direction column ([`Self::max_variant_count`],
/// [`Self::min_variant_count`]), the (set-level × `(usize, usize)` ×
/// pair-endpoint) column ([`Self::variant_count_range`]), the (set-
/// level × `bool` × uniformity) column ([`Self::is_uniform`]), and
/// the (set-level × `usize` × scalar-difference) column
/// ([`Self::variant_count_span`]). Where the scalar-return corners
/// project the histogram's MAGNITUDES (max-bar, min-bar, range,
/// span) or the FLATNESS witness (uniformity), this projection
/// promotes the ARGUMENT — the substrate variant achieving the
/// max-bar — from an inline `T::ALL.iter().find(|&&v|
/// T::count_occurrences_of(v, items) == T::max_variant_count(items))
/// .copied()` sweep at every prospective downstream "which variant
/// is the histogram's peak?" site to a typed `Option<Self>`-return
/// primitive on the trait. Not a fresh substrate primitive on the
/// index axis — the projection emerges from ONE
/// `T::ALL.iter().find(|&&v| ...)` sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::max_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `None` past the (max == 0,
/// every-count == 0) degenerate arm where an ungauded sweep would
/// silently return `Some(T::ALL[0])`.
///
/// Composition-equality contract: for every NON-EMPTY slice `items`,
/// `T::modal_variant(items).map(|v| T::count_occurrences_of(v, items))
/// == Some(T::max_variant_count(items))` — the argmax variant, when
/// present, achieves the modal multiplicity exactly. Sibling posture
/// to [`Self::variant_count_range`]'s slot-0 composition against
/// [`Self::min_variant_count`] one direction-axis over: both bind
/// the same substrate-wide (histogram × direction) surface through
/// different return shapes — the pair-return corner projects the
/// two magnitudes as a scalar tuple; this `Option<Self>`-return
/// corner projects the peak's ARGUMENT identity. Pinned by
/// `modal_variant_when_some_agrees_with_max_variant_count_across_every_triple`.
///
/// Empty-slice contract: `T::modal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, [`Self::max_variant_count`]
/// collapses to `0`, and an UNGUARDED `find(|v| count(v) == 0)`
/// sweep would silently return `Some(T::ALL[0])` past the (max ==
/// 0, every-count == 0) degenerate arm — the empty guard maps `&[]`
/// to `None` before the sweep. The `None`-at-empty fixpoint is
/// LOAD-BEARING as the drift catch for an override that omits the
/// guard: on the empty slice the guarded body returns `None`; the
/// unguarded sweep returns `Some(T::ALL[0])`, bifurcating the
/// contract loudly. Pinned by
/// `modal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Some-non-empty contract: `T::modal_variant(items).is_some()` iff
/// `!items.is_empty()` on every slice — the empty-slice arm is the
/// SOLE `None`-arm; on every non-empty slice the sweep hits at
/// least one variant whose count equals the modal multiplicity (the
/// pigeonhole argument via clause (98)'s partition identity forces
/// at least one variant's count to be strictly positive, and
/// [`Self::max_variant_count`] is exactly that variant's count on a
/// non-empty slice). Pinned by
/// `modal_variant_is_some_iff_slice_is_non_empty_across_every_triple`.
///
/// Full-set contract: `T::modal_variant(<T as ClosedSet>::ALL) ==
/// Some(T::first())` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position in the full-set
/// slice, every per-variant count is `1`, [`Self::max_variant_count`]
/// collapses to `1`, and the DECLARATION-ORDER-FIRST argmax sweep
/// hits `T::ALL[0] == T::first()` immediately. The full-set arm is
/// LOAD-BEARING as the drift catch for an override that walks
/// [`Self::sorted_variants`] instead of [`Self::ALL`] — a lex-order
/// argmax on the full set would return `Some(T::sorted_first())`,
/// bifurcating the declaration-order-first tie-breaking rule when
/// `T::first() != T::sorted_first()`. Pinned by
/// `modal_variant_returns_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::modal_variant(&doubled_full_set) == Some(T::first())`
/// UNCONDITIONALLY — the doubled-full-set slice appends
/// [`Self::ALL`] to itself, so every variant appears at EXACTLY
/// two positions, [`Self::max_variant_count`] collapses to `2`,
/// and the DECLARATION-ORDER-FIRST argmax sweep hits `T::ALL[0]
/// == T::first()` immediately. Pinned by
/// `modal_variant_returns_first_on_the_doubled_full_set_across_every_kind`.
///
/// Singleton contract: `T::modal_variant(&[v]) == Some(v)` on every
/// variant `v` — the singleton slice hits exactly one variant at
/// exactly one position, so [`Self::max_variant_count`] collapses
/// to `1` and the argmax sweep hits the target `v` (which is the
/// SOLE variant with a strictly-positive count on a singleton).
/// The other variants have count `0`, failing the `count(v) == max
/// == 1` predicate. Pinned by
/// `modal_variant_returns_some_target_on_every_singleton_slice_across_every_variant`.
///
/// Present-membership contract: for every NON-EMPTY slice `items`,
/// `T::modal_variant(items).map(|v| T::present_variants(items)
/// .contains(&v)) == Some(true)` — the modal variant, when present,
/// occurs at least once in `items` (the modal multiplicity is
/// strictly positive on any non-empty slice), so it sits in the
/// substrate's typed present-witness list. Pinned by
/// `modal_variant_when_some_sits_in_present_variants_across_every_triple`.
///
/// Declaration-order-first tie-break contract: for every slice
/// `items`, `T::modal_variant(items)` is the DECLARATION-ORDER
/// EARLIEST variant achieving the modal multiplicity — the
/// `T::ALL.iter().find(...)` sweep walks in declaration order and
/// commits on the first hit. Sibling posture to
/// [`Self::max_variant_count`]'s ordering-axis invariance on the
/// OUTPUT axis one return-shape over: the scalar max-bar collapses
/// (decl, lex) — magnitude is ordering-free; this `Option<Self>`-
/// return argument corner FIXES a canonical (declaration-order-
/// first) tie-breaking rule the scalar-return corner cannot express.
/// Pinned by
/// `modal_variant_is_declaration_order_first_argmax_across_every_triple`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::max_variant_count`] is a function of that
/// multiset alone, and the argmax sweep over [`Self::ALL`] (which
/// does NOT depend on `items`' ordering) is a function of that
/// multiset alone. Pinned by
/// `modal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, folded over [`Self::ALL`] via the standard-library
/// [`Iterator::find`] combinator against the just-lifted
/// [`Self::max_variant_count`] scalar. The composition uses one
/// `<Self as ClosedSet>::ALL.iter().copied().find(|&v|
/// <Self as ClosedSet>::count_occurrences_of(v, items) == max)`
/// sweep guarded by an empty-slice `is_empty()` short-circuit, so
/// the sweep costs O(T::CARDINALITY * n) on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one bounded `T::ALL.find`
/// sweep past the max scalar) — no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no histogram-carrier
/// allocation (the `find` sweep yields a bare `Option<Self>`
/// without materializing the intermediate `Vec<usize>` histogram;
/// the sweep streams through per-target counts one at a time and
/// commits at the first hit).
///
/// Future consumers that compose against [`Self::modal_variant`]:
/// a `tatara-check` predicate `(check-phases-mode …)` that reports
/// the modal `WorkloadPhase` in a rollout window (surfacing the
/// "which phase runs the most?" question as a typed variant rather
/// than a bar-height scalar); an LSP diagnostic on a Lisp-author-
/// written closed-set field that reports the modal variant as an
/// author-facing "most common: `<label>` (appears N times)" hint
/// binding both the argmax primitive AND its multiplicity through
/// [`Self::max_variant_count`]; a Sekiban audit-trail per-window
/// classification argmax witness carrying the peak variant as its
/// per-window witness (not just the bar-height scalar); a metric-
/// emitter that binds a Prometheus-style `mode_variant` label
/// alongside the scalar `max_bar` gauge; a per-slot scheduler
/// heuristic that promotes the modal `PhaseKind`'s successor slot
/// on partial ties. Each binds to ONE typed `Option<Self>`-return
/// argmax aggregate on the trait rather than re-deriving
/// `T::ALL.iter().copied().find(|&v| T::count_occurrences_of(v,
/// items) == T::max_variant_count(items))` inline (behind an
/// `is_empty()` short-circuit) per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × statistical-aggregate) column of the
/// equivalence-partition surface past the pre-existing (set-level ×
/// `usize` × statistical-aggregate) direction column
/// ([`Self::max_variant_count`], [`Self::min_variant_count`]), the
/// (set-level × `(usize, usize)` × statistical-aggregate) pair
/// column ([`Self::variant_count_range`]), the (set-level × `bool` ×
/// statistical-aggregate) uniformity column ([`Self::is_uniform`]),
/// and the (set-level × `usize` × scalar-difference) span column
/// ([`Self::variant_count_span`]). The (set-level × return-shape)
/// row on the statistical-aggregate column now carries FIVE typed
/// primitives across the (`usize`-direction, `(usize, usize)`-
/// pair, `bool`-uniformity, `usize`-scalar-difference,
/// `Option<Self>`-argument) face. The natural next lifts:
/// [`Self::least_frequent_variant`] returning `Option<Self>` for
/// the argmin one direction-axis over (the DECLARATION-ORDER-FIRST
/// variant achieving the min-bar); [`Self::sorted_modal_variant`]
/// returning `Option<Self>` for the LEX-ORDER-FIRST argmax one
/// ordering-axis over; the count of variants achieving the modal
/// multiplicity as a `usize` scalar past the argmax.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// `Option<Self>`-return argmax aggregate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::ALL.iter().copied().find(|&v|
/// T::count_occurrences_of(v, items) == T::max_variant_count(items))`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (`Option<Self>` × statistical-aggregate)
/// argmax corner was an unnamed inline composition recurring at
/// every prospective downstream "which variant is the histogram's
/// peak?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's per-target
/// multiplicity primitive [`Self::count_occurrences_of`] folded
/// over [`Self::ALL`] under the standard-library `find` reduction
/// against the substrate's just-lifted [`Self::max_variant_count`]
/// scalar. THEORY.md §VI.1 — generation over composition; the
/// argmax aggregate emerges from the composition of TWO substrate
/// primitives ([`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`]) with an `iter().copied().find()`
/// combinator, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `names(which.max(table(items)))` —
/// the canonical argmax over a factor histogram (returns the first
/// level in declaration order on ties); Julia's
/// `StatsBase.mode(items)` returning the first modal element in
/// iteration order; Python's `collections.Counter(items).most_common(1)`
/// returning the first-inserted modal element on ties; Clojure's
/// `(first (apply max-key val (frequencies coll)))` yielding the
/// first argmax key on ties; NumPy's `np.bincount(items).argmax()`
/// returning the first argmax index; SciPy's `scipy.stats.mode
/// (items, keepdims=False).mode` returning the first modal element
/// on ties; Haskell's `head . maximumBy (compare `on` length) .
/// group . sort` on `Ord`-instance carriers with a stable tie-
/// break; Coq's `list_argmax` combinator on a decidable-equality
/// carrier with a declaration-order tie-break. Translation through
/// pleme-io primitives: the N-ary `Option<Self>`-return argmax
/// aggregate on the closed-set trait binds through the substrate's
/// per-target multiplicity primitive [`Self::count_occurrences_of`]
/// folded over [`Self::ALL`] under the standard-library `find`
/// reduction against the just-lifted [`Self::max_variant_count`]
/// scalar — no new dep, no supertrait bound (the [`Self::index_of`]
/// projection [`Self::count_occurrences_of`] threads through
/// replaces the `Eq`/`Hash` bound the standard-library `Counter` /
/// `frequencies` / `countmap` argmax signatures demand), no
/// histogram-carrier allocation (the `find` sweep yields a bare
/// `Option<Self>` without materializing the intermediate
/// `Vec<usize>` histogram; the sweep streams through per-target
/// counts one at a time and commits at the first hit).
fn modal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.find(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == max)
}
/// The N-ARY ORDERING-AGNOSTIC "sorted modal variant" projection —
/// the `Option<Self>` LEX-ORDER-FIRST ARGMAX over the
/// [`Self::variant_counts`] histogram, reporting the FIRST variant
/// of [`Self::sorted_variants`] (walked in lex order) whose per-
/// target count equals [`Self::max_variant_count`], or `None` when
/// `items` is empty. The LEX-ORDER peer of [`Self::modal_variant`]
/// on the (declaration, lex) ordering axis of the (set-level ×
/// `Option<Self>` × statistical-aggregate) column — closes the lex
/// arm past the declaration arm the sibling [`Self::modal_variant`]
/// opened. Where [`Self::modal_variant`] walks [`Self::ALL`] in
/// DECLARATION order and commits at the first tied argmax, this
/// projection walks [`Self::sorted_variants`] in LEX order and
/// commits at the first tied argmax under the ASCII-`sort_unstable`
/// discriminator. The two projections AGREE byte-for-byte on every
/// slice whose argmax is UNIQUE (a single variant achieves the
/// modal multiplicity) AND on every slice whose argmax ties SIT
/// ENTIRELY within the (declaration-order-first == lex-order-first)
/// tie-break agreement window; they BIFURCATE at the smallest slice
/// whose argmax ties spread across a (`T::first() !=
/// T::sorted_first()`) declaration/lex divergence. Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from ONE `sorted_variants().into_iter().find(|&v| ...)` sweep
/// whose predicate binds [`Self::count_occurrences_of`] against the
/// just-lifted [`Self::max_variant_count`] scalar, guarded by an
/// empty-slice short-circuit that maps `&[]` to `None` past the
/// (max == 0, every-count == 0) degenerate arm where an unguarded
/// sweep would silently return `Some(T::sorted_first())`.
///
/// Composition-equality contract: for every NON-EMPTY slice `items`,
/// `T::sorted_modal_variant(items).map(|v|
/// T::count_occurrences_of(v, items)) ==
/// Some(T::max_variant_count(items))` — the argmax variant, when
/// present, achieves the modal multiplicity exactly. Sibling
/// posture to [`Self::modal_variant`]'s count-composition arm one
/// ordering-axis over: both bind the same substrate-wide (histogram
/// × argmax) surface through the same scalar identity but under
/// DIFFERENT tie-break rules (declaration-order-first vs lex-order-
/// first). Pinned by
/// `sorted_modal_variant_when_some_agrees_with_max_variant_count_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_modal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, [`Self::max_variant_count`]
/// collapses to `0`, and an UNGUARDED
/// `sorted_variants().into_iter().find(|v| count(v) == 0)` sweep
/// would silently return `Some(T::sorted_first())` past the (max ==
/// 0, every-count == 0) degenerate arm — the empty guard maps
/// `&[]` to `None` before the sweep. The `None`-at-empty fixpoint
/// is LOAD-BEARING as the drift catch for an override that omits
/// the guard: on the empty slice the guarded body returns `None`;
/// the unguarded sweep returns `Some(T::sorted_first())`,
/// bifurcating the contract loudly. Pinned by
/// `sorted_modal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Some-non-empty contract: `T::sorted_modal_variant(items).is_some()`
/// iff `!items.is_empty()` on every slice — the empty-slice arm is
/// the SOLE `None`-arm; on every non-empty slice the sweep hits at
/// least one variant whose count equals the modal multiplicity (the
/// pigeonhole argument via clause (98)'s partition identity forces
/// at least one variant's count to be strictly positive, and
/// [`Self::max_variant_count`] is exactly that variant's count on
/// a non-empty slice). Pinned by
/// `sorted_modal_variant_is_some_iff_slice_is_non_empty_across_every_triple`.
///
/// Full-set contract: `T::sorted_modal_variant(<T as ClosedSet>::ALL)
/// == Some(T::sorted_first())` UNCONDITIONALLY — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// of [`Self::ALL`] appears at exactly one position in the full-set
/// slice, every per-variant count is `1`, [`Self::max_variant_count`]
/// collapses to `1`, and the LEX-ORDER-FIRST argmax sweep hits
/// `T::sorted_variants()[0] == T::sorted_first()` immediately. The
/// full-set arm is LOAD-BEARING as the drift catch for an override
/// that walks [`Self::ALL`] instead of [`Self::sorted_variants`] —
/// a declaration-order argmax on the full set would return
/// `Some(T::first())`, bifurcating the lex-order-first tie-breaking
/// rule when `T::first() != T::sorted_first()`. Pinned by
/// `sorted_modal_variant_returns_sorted_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_modal_variant(&doubled_full_set) ==
/// Some(T::sorted_first())` UNCONDITIONALLY — the doubled-full-set
/// slice appends [`Self::ALL`] to itself, so every variant appears
/// at EXACTLY two positions, [`Self::max_variant_count`] collapses
/// to `2`, and the LEX-ORDER-FIRST argmax sweep hits
/// `T::sorted_variants()[0] == T::sorted_first()` immediately.
/// Pinned by
/// `sorted_modal_variant_returns_sorted_first_on_the_doubled_full_set_across_every_kind`.
///
/// Singleton contract: `T::sorted_modal_variant(&[v]) == Some(v)`
/// on every variant `v` — the singleton slice hits exactly one
/// variant at exactly one position, so [`Self::max_variant_count`]
/// collapses to `1` and the argmax sweep hits the target `v`
/// (which is the SOLE variant with a strictly-positive count on a
/// singleton, regardless of walk order). The other variants have
/// count `0`, failing the `count(v) == max == 1` predicate. Pinned
/// by
/// `sorted_modal_variant_returns_some_target_on_every_singleton_slice_across_every_variant`.
///
/// Present-membership contract: for every NON-EMPTY slice `items`,
/// `T::sorted_modal_variant(items).map(|v|
/// T::present_variants(items).contains(&v)) == Some(true)` — the
/// argmax variant, when present, occurs at least once in `items`,
/// so it sits in the substrate's typed present-witness list. An
/// INDEPENDENT cross-check distinct from the count-composition arm
/// on the aggregation axis (Vec-membership vs scalar-equality).
/// Pinned by
/// `sorted_modal_variant_when_some_sits_in_present_variants_across_every_triple`.
///
/// Lex-order-first tie-break contract: for every slice `items`,
/// `T::sorted_modal_variant(items)` is the LEX-ORDER EARLIEST
/// variant achieving the modal multiplicity — the
/// `sorted_variants().into_iter().find(...)` sweep walks in lex
/// order and commits on the first hit. Sibling posture to
/// [`Self::modal_variant`]'s DECLARATION-ORDER-FIRST tie-break one
/// ordering-axis over: this projection FIXES a canonical (lex-
/// order-first) tie-break rule alongside the sibling declaration-
/// order-first rule — every downstream consumer picks the tie-break
/// its output vocabulary demands. Pinned by
/// `sorted_modal_variant_is_lex_order_first_argmax_across_every_triple`.
///
/// Unique-argmax agreement contract: for every slice `items` whose
/// argmax is UNIQUE (a single variant achieves the modal
/// multiplicity), `T::sorted_modal_variant(items) ==
/// T::modal_variant(items)` — both tie-break rules commit at the
/// SAME variant when no tie exists. The two projections BIFURCATE
/// only on slices with ties whose declaration-order-first and lex-
/// order-first witnesses differ. The matching-singleton fixpoint
/// is a canonical unique-argmax witness; the full-set and doubled-
/// full-set fixpoints are canonical tie witnesses that bifurcate
/// declaration- vs lex-order on any closed set where
/// `T::first() != T::sorted_first()`. Pinned by
/// `sorted_modal_variant_agrees_with_modal_variant_on_matching_singleton_across_every_variant`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::max_variant_count`] is a function of that
/// multiset alone, and the argmax sweep over
/// [`Self::sorted_variants`] (which does NOT depend on `items`'
/// ordering) is a function of that multiset alone. Pinned by
/// `sorted_modal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, folded over [`Self::sorted_variants`] via the
/// standard-library [`Iterator::find`] combinator against the
/// just-lifted [`Self::max_variant_count`] scalar. The composition
/// uses one `is_empty()`-guarded `sorted_variants().into_iter()
/// .find(|&v| count == max)` sweep, so the sweep costs
/// O(N log N + T::CARDINALITY * n) on slice arity `n` (the
/// [`Self::sorted_variants`] canonical-lex-sort step + one
/// [`Self::max_variant_count`] fold + one bounded find sweep) —
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no histogram-carrier allocation (the `find` sweep
/// yields a bare `Option<Self>` without materializing the
/// intermediate `Vec<usize>` histogram; the sweep streams through
/// per-target counts one at a time and commits at the first hit).
///
/// Future consumers that compose against
/// [`Self::sorted_modal_variant`]: a `tatara-check` predicate
/// `(check-phases-mode-lex …)` that reports the modal
/// `WorkloadPhase` in a rollout window under a canonical LEX-order
/// tie-break for display-oriented tools (alphabetic mode-list),
/// distinct from the sibling declaration-order-first
/// [`Self::modal_variant`] argmax used for scheduler-oriented
/// consumers that route through declaration slots; an LSP
/// diagnostic on a Lisp-author-written closed-set field that
/// reports the modal variant under an author-facing "most common
/// (alphabetical tie-break): `<label>`" hint aligned with lex-
/// ordered enumeration surfaces; a Sekiban audit-trail per-window
/// classification argmax witness whose tie-break rule matches the
/// UI's lex-ordered navigation menu (so the audit trail and the
/// UI's default-selected argmax always agree on tied windows); a
/// metric-emitter that binds a Prometheus-style `mode_variant_lex`
/// label alongside the sibling `mode_variant_decl` label so tied-
/// argmax rollouts surface BOTH tie-break witnesses on the same
/// gauge (a common source of drift when a dashboard's tie-break
/// rule disagrees with a scheduler's). Each binds to ONE typed
/// `Option<Self>`-return lex-order argmax aggregate on the trait
/// rather than re-deriving `T::sorted_variants().into_iter()
/// .find(|&v| T::count_occurrences_of(v, items) ==
/// T::max_variant_count(items))` inline (behind an `is_empty()`
/// short-circuit) per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Option<Self>` × statistical-aggregate × ordering) 2-corner
/// face at the lex-arm past the declaration-arm the sibling
/// [`Self::modal_variant`] opened. The (set-level × return-shape ×
/// ordering) column on the statistical-aggregate row now closes
/// the argmax ordering face at both corners — declaration-order-
/// first via [`Self::modal_variant`], lex-order-first via THIS
/// projection. Sibling posture to the (set-level × Vec<Self> ×
/// ordering) column's `present_variants`/`sorted_present_variants`
/// closure, the `missing_variants`/`sorted_missing_variants`
/// closure, the `repeating_variants`/`sorted_repeating_variants`
/// closure, and the `unique_variants`/`sorted_unique_variants`
/// closure one return-shape axis over. The natural next lift past
/// this closure is [`Self::antimodal_variant`] returning
/// `Option<Self>` for the argmin (least-common-multiplicity
/// variant) one direction-axis over — opening the argmin corner
/// past the argmax corner on the (set-level × `Option<Self>` ×
/// statistical-aggregate × direction) face.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order-first `Option<Self>`-return argmax aggregate becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline `T::sorted_variants().into_iter().find(|&v|
/// T::count_occurrences_of(v, items) ==
/// T::max_variant_count(items))` composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the
/// (`Option<Self>` × statistical-aggregate × lex-order) argmax
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variant is the histogram's peak
/// under a canonical alphabetic tie-break?" site pre-lift. Naming
/// it on the trait makes the projection a TYPED CONSEQUENCE of
/// the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] folded over
/// [`Self::sorted_variants`] under the standard-library `find`
/// reduction against the substrate's just-lifted
/// [`Self::max_variant_count`] scalar. THEORY.md §VI.1 —
/// generation over composition; the lex-order argmax aggregate
/// emerges from the composition of THREE substrate primitives
/// ([`Self::sorted_variants`] + [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`]) with an `into_iter().find()`
/// combinator, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `names(which.max(table(items)[order
/// (names(table(items)))]))` — the canonical argmax over a factor
/// histogram lex-sorted by level name; Julia's
/// `sort!(collect(StatsBase.countmap(items)), by=first)` with
/// argmax-under-lex-tie-break by pre-sorting the (key, count)
/// pairs on the key; Python's `min([k for k, v in
/// collections.Counter(items).items() if v == max(collections
/// .Counter(items).values())])` — argmax with a min-key lex tie-
/// break; Racket's `(argmax cdr (sort (hash->list (frequencies
/// coll)) string<? #:key (compose symbol->string car)))` on a
/// lex-pre-sorted assoc list; Haskell's `head . sort . map fst .
/// filter (\(_, n) -> n == modal) . Map.toList . frequencies`.
/// Translation through pleme-io primitives: the N-ary lex-order-
/// first argmax aggregate on the closed-set trait binds through
/// [`Self::sorted_variants`] composed with the substrate's per-
/// target multiplicity primitive [`Self::count_occurrences_of`]
/// under the standard-library `find` reduction against
/// [`Self::max_variant_count`] — no new dep, no supertrait bound
/// (the substrate's [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through and
/// [`Self::sorted_variants`]'s ASCII-`sort_unstable_by_key`
/// replace the `Eq`/`Hash` + `Ord` bound the standard-library
/// counter+lex-sort signatures demand), no histogram-carrier
/// allocation (the `find` sweep yields a bare `Option<Self>`
/// without materializing the intermediate `Vec<usize>` histogram).
fn sorted_modal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == max)
}
/// The N-ARY ORDERING-AGNOSTIC "antimodal variant" projection —
/// the `Option<Self>` DECLARATION-ORDER-FIRST ARGMIN over the
/// [`Self::variant_counts`] histogram, reporting the FIRST variant
/// of [`Self::ALL`] (walked in declaration order) whose per-target
/// count equals [`Self::min_variant_count`], or `None` when `items`
/// is empty. The DIRECTION-AXIS peer of [`Self::modal_variant`] on
/// the (max-bar, min-bar) direction axis of the (set-level ×
/// `Option<Self>` × statistical-aggregate) column — opens the
/// argmin arm past the argmax arm the sibling [`Self::modal_variant`]
/// closed on the declaration-order corner. Where
/// [`Self::modal_variant`] finds the variant achieving
/// [`Self::max_variant_count`], this projection finds the variant
/// achieving [`Self::min_variant_count`]. On any slice with a
/// missing variant (equivalently, [`Self::is_missing_any`] holds,
/// equivalently, min == 0), the antimodal points at a MISSING
/// witness; on a covering slice (min ≥ 1), the antimodal points at
/// the least-common PRESENT variant. Not a fresh substrate
/// primitive on the index axis — the projection emerges from ONE
/// `T::ALL.iter().copied().find(|&v| ...)` sweep whose predicate
/// binds [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::min_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `None` past the (min == 0,
/// every-count == 0) degenerate arm where an unguarded sweep would
/// silently return `Some(T::first())`.
///
/// Composition-equality contract: for every NON-EMPTY slice `items`,
/// `T::antimodal_variant(items).map(|v|
/// T::count_occurrences_of(v, items)) ==
/// Some(T::min_variant_count(items))` — the argmin variant, when
/// present, achieves the least-common multiplicity exactly. Sibling
/// posture to [`Self::modal_variant`]'s count-composition arm one
/// direction-axis over: both bind the same substrate-wide
/// (histogram × argument) surface through the same per-target
/// multiplicity primitive but under DIFFERENT direction rules
/// (argmax against the modal multiplicity vs argmin against the
/// least-common multiplicity). Pinned by
/// `antimodal_variant_when_some_agrees_with_min_variant_count_across_every_triple`.
///
/// Empty-slice contract: `T::antimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, [`Self::min_variant_count`]
/// collapses to `0`, and an UNGUARDED `T::ALL.iter().copied().find(
/// |v| count(v) == 0)` sweep would silently return
/// `Some(T::first())` past the (min == 0, every-count == 0)
/// degenerate arm — the empty guard maps `&[]` to `None` before the
/// sweep. The `None`-at-empty fixpoint is LOAD-BEARING as the drift
/// catch for an override that omits the guard. Pinned by
/// `antimodal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Some-non-empty contract: `T::antimodal_variant(items).is_some()`
/// iff `!items.is_empty()` on every slice — the empty-slice arm is
/// the SOLE `None`-arm; on every non-empty slice the sweep hits at
/// least one variant whose count equals [`Self::min_variant_count`]
/// (the finite discrete histogram achieves its min at at least one
/// bin). Pinned by
/// `antimodal_variant_is_some_iff_slice_is_non_empty_across_every_triple`.
///
/// Full-set contract: `T::antimodal_variant(<T as ClosedSet>::ALL)
/// == Some(T::first())` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position in the full-set
/// slice, every per-variant count is `1`, [`Self::min_variant_count`]
/// collapses to `1`, and the DECLARATION-ORDER-FIRST argmin sweep
/// hits `T::ALL[0] == T::first()` immediately. On a flat histogram
/// (every count equal) the argmax and argmin agree on the tie-break
/// witness; the full-set fixpoint pins the direction-axis
/// degeneracy at both corners. Pinned by
/// `antimodal_variant_returns_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::antimodal_variant(&doubled_full_set) == Some(T::first())`
/// UNCONDITIONALLY — the doubled-full-set slice appends
/// [`Self::ALL`] to itself, so every variant appears at EXACTLY two
/// positions, [`Self::min_variant_count`] collapses to `2`, and the
/// DECLARATION-ORDER-FIRST argmin sweep hits `T::first()`
/// immediately. Pinned by
/// `antimodal_variant_returns_first_on_the_doubled_full_set_across_every_kind`.
///
/// Declaration-order-first tie-break contract: for every slice
/// `items`, `T::antimodal_variant(items)` is the DECLARATION-ORDER
/// EARLIEST variant achieving the least-common multiplicity — the
/// `T::ALL.iter().copied().find(...)` sweep walks in declaration
/// order and commits on the first hit. Sibling posture to
/// [`Self::modal_variant`]'s DECLARATION-ORDER-FIRST tie-break one
/// direction-axis over. Pinned by
/// `antimodal_variant_is_declaration_order_first_argmin_across_every_triple`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::min_variant_count`] is a function of that
/// multiset alone, and the argmin sweep over [`Self::ALL`] (which
/// does NOT depend on `items`' ordering) is a function of that
/// multiset alone. Pinned by
/// `antimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, folded over [`Self::ALL`] via the standard-library
/// [`Iterator::find`] combinator against the just-lifted
/// [`Self::min_variant_count`] scalar. The composition uses one
/// `is_empty()`-guarded `T::ALL.iter().copied().find(|&v| count ==
/// min)` sweep, so the sweep costs `O(T::CARDINALITY * n)` on
/// slice arity `n` (one [`Self::min_variant_count`] fold + one
/// bounded find sweep) — no `PartialEq`/`Eq`/`Hash` supertrait
/// bound, no histogram-carrier allocation.
///
/// Future consumers that compose against
/// [`Self::antimodal_variant`]: a `tatara-check` predicate
/// `(check-phases-antimode …)` that reports the LEAST-COMMON
/// `WorkloadPhase` in a rollout window (surfacing the "which phase
/// runs the least?" question as a typed variant rather than a
/// bar-height scalar); an LSP diagnostic on a Lisp-author-written
/// closed-set field that reports the antimodal variant as an
/// author-facing "least common: `<label>` (appears N times)" hint
/// binding both the argmin primitive AND its multiplicity through
/// [`Self::min_variant_count`]; a Sekiban audit-trail per-window
/// classification argmin witness carrying the trough variant as its
/// per-window witness (not just the bar-height scalar); a
/// scheduler-fairness heuristic that promotes the antimodal
/// `PhaseKind`'s successor slot to close the histogram's bottom bar
/// on rollouts. Each binds to ONE typed `Option<Self>`-return
/// argmin aggregate on the trait rather than re-deriving
/// `T::ALL.iter().copied().find(|&v| T::count_occurrences_of(v,
/// items) == T::min_variant_count(items))` inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction) argmin
/// corner past the argmax corner the sibling [`Self::modal_variant`]
/// closed on the declaration-order arm. The (set-level ×
/// `Option<Self>` × statistical-aggregate × direction × ordering)
/// 2×2 face now carries TWO of its FOUR corners at the declaration
/// arm — argmax via [`Self::modal_variant`] and argmin via THIS
/// projection. The natural next lift past this OPENING is
/// [`Self::sorted_antimodal_variant`] returning `Option<Self>` for
/// the LEX-ORDER-FIRST argmin one ordering-axis over, CLOSING the
/// (direction × ordering) 4-corner face at its fourth corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// declaration-order-first `Option<Self>`-return argmin aggregate
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline `T::ALL.iter().copied().find(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// composition. THEORY.md §V.1 — knowable platform; the argmin
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variant is the histogram's
/// trough?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the argmin aggregate emerges from the composition
/// of TWO substrate primitives ([`Self::count_occurrences_of`] +
/// [`Self::min_variant_count`]) with an `iter().copied().find()`
/// combinator.
///
/// Frontier inspiration: R's `names(which.min(table(items)))` —
/// the canonical argmin over a factor histogram; Julia's
/// `findmin(StatsBase.countmap(items))[2]` returning the argmin
/// key; Python's `min(collections.Counter(items).items(),
/// key=lambda p: p[1])[0]` yielding the first argmin key on ties;
/// NumPy's `np.bincount(items).argmin()` returning the first
/// argmin index; SciPy's `scipy.stats.mode(items, keepdims=False)`
/// paired with a `.antimode`-style counterpart in `statsmodels`;
/// Haskell's `head . minimumBy (compare `on` length) . group .
/// sort` on `Ord`-instance carriers with a stable tie-break;
/// Coq's `list_argmin` combinator on a decidable-equality carrier
/// with a declaration-order tie-break. Translation through pleme-io
/// primitives: the N-ary `Option<Self>`-return argmin aggregate on
/// the closed-set trait binds through the substrate's per-target
/// multiplicity primitive [`Self::count_occurrences_of`] folded
/// over [`Self::ALL`] under the standard-library `find` reduction
/// against the substrate's just-lifted [`Self::min_variant_count`]
/// scalar — no new dep, no supertrait bound, no histogram-carrier
/// allocation.
fn antimodal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.find(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == min)
}
/// The N-ARY ORDERING-AGNOSTIC "sorted antimodal variant" projection —
/// the `Option<Self>` LEX-ORDER-FIRST ARGMIN over the
/// [`Self::variant_counts`] histogram, reporting the FIRST variant
/// of [`Self::sorted_variants`] (walked in lex order) whose per-target
/// count equals [`Self::min_variant_count`], or `None` when `items`
/// is empty. The ORDERING-AXIS peer of [`Self::antimodal_variant`] on
/// the (declaration, lex) ordering axis of the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction) column — CLOSES
/// the (direction × ordering) 4-corner face at its final (argmin, lex)
/// corner past the argmax arm the sibling [`Self::sorted_modal_variant`]
/// closed one direction-axis over. Where [`Self::antimodal_variant`]
/// finds the DECLARATION-ORDER-FIRST variant achieving
/// [`Self::min_variant_count`], this projection finds the
/// LEX-ORDER-FIRST variant achieving [`Self::min_variant_count`]. On
/// any slice with a missing variant (equivalently,
/// [`Self::is_missing_any`] holds, equivalently, min == 0), the
/// sorted-antimodal points at the lex-order-first MISSING witness; on
/// a covering slice (min ≥ 1), the sorted-antimodal points at the
/// lex-order-first least-common PRESENT variant. Not a fresh substrate
/// primitive on the index axis — the projection emerges from ONE
/// `T::sorted_variants().into_iter().find(|&v| ...)` sweep whose
/// predicate binds [`Self::count_occurrences_of`] against
/// [`Self::min_variant_count`], guarded by an empty-slice
/// short-circuit that maps `&[]` to `None` past the (min == 0,
/// every-count == 0) degenerate arm where an unguarded sweep would
/// silently return `Some(T::sorted_first())`.
///
/// Composition-equality contract: for every NON-EMPTY slice `items`,
/// `T::sorted_antimodal_variant(items).map(|v|
/// T::count_occurrences_of(v, items)) ==
/// Some(T::min_variant_count(items))` — the lex-order-first argmin
/// variant, when present, achieves the least-common multiplicity
/// exactly. Sibling posture to [`Self::antimodal_variant`]'s
/// count-composition arm one ordering-axis over, AND to
/// [`Self::sorted_modal_variant`]'s count-composition arm one
/// direction-axis over: all three bind the same substrate-wide
/// (histogram × argument) surface through the same per-target
/// multiplicity primitive but under DIFFERENT tie-break rules
/// (declaration-order argmin, lex-order argmin, lex-order argmax).
/// Pinned by
/// `sorted_antimodal_variant_when_some_agrees_with_min_variant_count_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_antimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, [`Self::min_variant_count`]
/// collapses to `0`, and an UNGUARDED
/// `T::sorted_variants().into_iter().find(|v| count(v) == 0)` sweep
/// would silently return `Some(T::sorted_first())` past the (min ==
/// 0, every-count == 0) degenerate arm — the empty guard maps `&[]`
/// to `None` before the sweep. The `None`-at-empty fixpoint is
/// LOAD-BEARING as the drift catch for an override that omits the
/// guard. Pinned by
/// `sorted_antimodal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Some-non-empty contract: `T::sorted_antimodal_variant(items).is_some()`
/// iff `!items.is_empty()` on every slice — the empty-slice arm is
/// the SOLE `None`-arm; on every non-empty slice the sweep hits at
/// least one variant whose count equals [`Self::min_variant_count`]
/// (the finite discrete histogram achieves its min at at least one
/// bin). Pinned by
/// `sorted_antimodal_variant_is_some_iff_slice_is_non_empty_across_every_triple`.
///
/// Full-set contract:
/// `T::sorted_antimodal_variant(<T as ClosedSet>::ALL) ==
/// Some(T::sorted_first())` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position in the full-set
/// slice, every per-variant count is `1`, [`Self::min_variant_count`]
/// collapses to `1`, and the LEX-ORDER-FIRST argmin sweep hits
/// `T::sorted_variants()[0] == T::sorted_first()` immediately. On a
/// flat histogram (every count equal) the argmax and argmin agree on
/// the tie-break witness; the full-set fixpoint pins the direction-
/// axis degeneracy at the lex-order corner. Pinned by
/// `sorted_antimodal_variant_returns_sorted_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_antimodal_variant(&doubled_full_set) ==
/// Some(T::sorted_first())` UNCONDITIONALLY — the doubled-full-set
/// slice appends [`Self::ALL`] to itself, so every variant appears at
/// EXACTLY two positions, [`Self::min_variant_count`] collapses to
/// `2`, and the LEX-ORDER-FIRST argmin sweep hits `T::sorted_first()`
/// immediately. Pinned by
/// `sorted_antimodal_variant_returns_sorted_first_on_the_doubled_full_set_across_every_kind`.
///
/// Matching-singleton contract:
/// `T::sorted_antimodal_variant(&[v])` yields a variant `w` with
/// `T::count_occurrences_of(w, &[v]) == T::min_variant_count(&[v])`
/// for every `v` — the argmin, when present, achieves the least-
/// common multiplicity exactly. On cardinality ≥ 2 the sole target
/// hits `count == 1` while every non-target variant hits `count ==
/// 0`, so the argmin picks the LEX-ORDER-FIRST non-target variant.
/// The declaration-axis peer projection [`Self::antimodal_variant`]
/// picks the DECLARATION-ORDER-FIRST non-target variant on the same
/// slice; the two agree iff `T::ALL` and `T::sorted_variants` place
/// the same variant first among the non-target set (which they DO
/// when `T::first() == T::sorted_first()` AND `T::first() != v`, or
/// when the second-slot walks agree). Sibling posture to
/// `sorted_modal_variant_agrees_with_modal_variant_on_matching_singleton_across_every_variant`
/// one direction-axis over. Pinned by
/// `sorted_antimodal_variant_when_some_sits_in_min_multiplicity_bin_across_every_triple`.
///
/// Lex-order-first tie-break contract: for every slice `items`,
/// `T::sorted_antimodal_variant(items)` is the LEX-ORDER EARLIEST
/// variant achieving the least-common multiplicity — the
/// `T::sorted_variants().into_iter().find(...)` sweep walks in lex
/// order and commits on the first hit. Sibling posture to
/// [`Self::sorted_modal_variant`]'s LEX-ORDER-FIRST tie-break one
/// direction-axis over, AND to [`Self::antimodal_variant`]'s
/// DECLARATION-ORDER-FIRST tie-break one ordering-axis over. Pinned
/// by
/// `sorted_antimodal_variant_is_lex_order_first_argmin_across_every_triple`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::min_variant_count`] is a function of that multiset
/// alone, and the argmin sweep over [`Self::sorted_variants`] (which
/// does NOT depend on `items`' ordering) is a function of that
/// multiset alone. Pinned by
/// `sorted_antimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Singleton agreement with declaration-order peer at cardinality 1:
/// on the matching-singleton `[v]` at [`Self::ALL`] cardinality 1,
/// both directions agree at `Some(v)` (the sole variant hits count
/// 1 and there is no non-target to break on). On cardinality ≥ 2
/// the peers may diverge iff `T::ALL` and `T::sorted_variants`
/// disagree on the first non-target variant; on carriers where
/// `T::ALL == T::sorted_variants` element-wise the two projections
/// AGREE on every slice. Pinned by
/// `sorted_antimodal_variant_agrees_with_antimodal_variant_when_ordering_axes_align_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the trait
/// level, folded over [`Self::sorted_variants`] via the standard-
/// library [`Iterator::find`] combinator against
/// [`Self::min_variant_count`]. The composition uses one
/// `is_empty()`-guarded `T::sorted_variants().into_iter().find(|&v|
/// count == min)` sweep, so the sweep costs `O(T::CARDINALITY * n)`
/// on slice arity `n` (one [`Self::min_variant_count`] fold + one
/// bounded find sweep, plus one [`Self::sorted_variants`]
/// ASCII-`sort_unstable_by_key` allocation which
/// [`Self::sorted_modal_variant`] already pays across the same
/// direction axis) — no `PartialEq`/`Eq`/`Hash` supertrait bound, no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::sorted_antimodal_variant`]: a `tatara-check` predicate
/// `(check-phases-antimode-lex …)` that reports the LEX-ORDER-FIRST
/// least-common `WorkloadPhase` in a rollout window (surfacing the
/// "which phase runs the least, with the alphabetical tie-break
/// operators prefer for report tables?" question); an LSP diagnostic
/// on a Lisp-author-written closed-set field that reports the
/// sorted-antimodal variant as an author-facing "least common:
/// `<label>` (appears N times)" hint whose label is stable under
/// re-declaration of the closed set in a different order; a Sekiban
/// audit-trail per-window classification argmin witness whose label
/// binds to a lex-order tie-break invariant under substrate
/// reordering (a common source of diff churn in
/// non-declaration-stable audit UIs); a scheduler-fairness heuristic
/// that promotes the sorted-antimodal `PhaseKind`'s successor slot to
/// close the histogram's bottom bar on rollouts with a
/// lex-first-fair tie-break. Each binds to ONE typed `Option<Self>`-
/// return lex-order argmin aggregate on the trait rather than
/// re-deriving `T::sorted_variants().into_iter().find(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// inline per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction × ordering)
/// 2×2 face at its FOURTH corner — argmax/declaration
/// ([`Self::modal_variant`]), argmax/lex
/// ([`Self::sorted_modal_variant`]), argmin/declaration
/// ([`Self::antimodal_variant`]), and argmin/lex (THIS projection).
/// The (direction × ordering) face is now fully closed at both
/// directions across both orderings; the next lift past this closure
/// is naturally one axis over on the (return-shape × argument-count)
/// grid — a `(usize, usize)`-return pair-endpoint direction-anchor
/// like `variant_argmin_argmax_pair` yielding `(argmin, argmax)`
/// pairs (mirroring [`Self::variant_count_range`] on the scalar
/// column one return-shape axis over), or a `Vec<Self>`-return
/// direction-anchor like `argmin_variants` yielding all variants
/// achieving the min-bar (mirroring
/// [`Self::repeating_variants`] one multiplicity-band axis over).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// lex-order-first `Option<Self>`-return argmin aggregate becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline `T::sorted_variants().into_iter().find(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// composition. THEORY.md §V.1 — knowable platform; the lex-order
/// argmin corner was an unnamed inline composition recurring at
/// every prospective downstream "which variant is the histogram's
/// trough, with the lex tie-break?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the argmin aggregate emerges from
/// the composition of TWO substrate primitives
/// ([`Self::count_occurrences_of`] + [`Self::min_variant_count`])
/// with an `into_iter().find()` combinator over
/// [`Self::sorted_variants`].
///
/// Frontier inspiration: R's
/// `names(which.min(table(sort(unique(items)))))` — the lex-order
/// argmin over a factor histogram; Julia's `findmin(
/// StatsBase.countmap(items))[2]` under a sorted key-set tie-break;
/// Python's `min(sorted(collections.Counter(items).items(), key=
/// lambda p: p[0]), key=lambda p: p[1])[0]` yielding the
/// lex-order-first argmin key on ties; Haskell's `head . minimumBy
/// (compare `on` length) . groupBy (==) . sort` on `Ord`-instance
/// carriers with a lex tie-break; Coq's `list_argmin_lex` combinator
/// on a decidable-equality carrier with a lex-order tie-break.
/// Translation through pleme-io primitives: the N-ary `Option<Self>`-
/// return lex-order argmin aggregate on the closed-set trait binds
/// through [`Self::sorted_variants`] composed with the substrate's
/// per-target multiplicity primitive [`Self::count_occurrences_of`]
/// under the standard-library `find` reduction against
/// [`Self::min_variant_count`] — no new dep, no supertrait bound, no
/// histogram-carrier allocation.
fn sorted_antimodal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == min)
}
/// The N-ARY ORDERING-AGNOSTIC "modal variants" projection —
/// the `Vec<Self>` DECLARATION-ORDER witness-collection of EVERY
/// variant of [`Self::ALL`] whose per-target count equals
/// [`Self::max_variant_count`], preserving [`Self::ALL`]'s
/// declaration order and returning the empty vector when `items`
/// is empty. The Vec-RETURN opener on the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction × argmax)
/// corner peer to the (set-level × `Option<Self>` × statistical-
/// aggregate × direction × argmax) [`Self::modal_variant`] corner
/// one RETURN-SHAPE axis over — while [`Self::modal_variant`]
/// reports the FIRST tied argmax variant (a single-witness
/// commit), this projection reports EVERY tied argmax variant (a
/// COMPLETE witness-collection, no tie-break choice). The (set-
/// level × {`Option<Self>`, `Vec<Self>`} × statistical-aggregate ×
/// argmax × declaration-order) 2-corner (return-shape) row on the
/// equivalence-partition surface now closes the `Vec<Self>` per-
/// direction column past the `Option<Self>` first-witness column
/// [`Self::modal_variant`] closed.
///
/// Mult-band peer posture: the projection is the (statistical-
/// aggregate × direction) DIRECTION peer of the (multiplicity-
/// band) [`Self::repeating_variants`] Vec<Self>-return witness one
/// FILTER-KIND axis over — [`Self::repeating_variants`] filters
/// [`Self::ALL`] by `count(v) >= 2` (a fixed-threshold
/// multiplicity-band), this projection filters [`Self::ALL`] by
/// `count(v) == T::max_variant_count(items)` (a dynamic-threshold
/// statistical-aggregate direction-anchor). Both projections
/// share the `T::ALL.iter().copied().filter(...).collect()`
/// composition idiom on the (Vec<Self>, declaration-order, filter)
/// column.
///
/// First-witness identity: for every NON-EMPTY slice `items`,
/// `T::modal_variants(items).first().copied() == T::modal_variant(items)`
/// — the plural's HEAD equals the singular's commit because both
/// walk [`Self::ALL`] in declaration order and commit at the first
/// tied argmax. Pinned by
/// `modal_variants_head_agrees_with_modal_variant_across_every_triple`.
///
/// Count-composition identity: for every slice `items` and every
/// variant `v` in the returned Vec,
/// `T::count_occurrences_of(v, items) == T::max_variant_count(items)`
/// — every element of the returned Vec achieves the modal
/// multiplicity exactly. Pinned by
/// `modal_variants_elements_agree_with_max_variant_count_across_every_triple`.
///
/// Present-arm containment identity: for every NON-EMPTY slice
/// `items`, `T::modal_variants(items)` is a SUBSET (as multiset)
/// of `T::present_variants(items)` — every modal variant is
/// present (its count is at least `T::max_variant_count(items)
/// >= 1` on non-empty slices, so it appears in the slice).
/// Pinned by
/// `modal_variants_are_present_across_every_triple`.
///
/// Non-emptiness identity: `T::modal_variants(items).is_empty()`
/// iff `items.is_empty()` on every slice — the empty-slice arm
/// is the SOLE empty-Vec arm; on every non-empty slice the filter
/// hits at least one variant whose count equals
/// [`Self::max_variant_count`] (the finite discrete histogram
/// achieves its max at at least one bin). Pinned by
/// `modal_variants_is_non_empty_iff_slice_is_non_empty_across_every_triple`.
///
/// Empty-slice contract: `T::modal_variants(&[])` is the empty
/// `Vec<Self>` UNCONDITIONALLY — the empty slice hits zero
/// positions, so every per-variant occurrence count is `0`,
/// [`Self::max_variant_count`] collapses to `0`, and an UNGUARDED
/// `T::ALL.iter().copied().filter(|v| count(v) == 0).collect()`
/// sweep would silently return `T::ALL.to_vec()` past the (max ==
/// 0, every-count == 0) degenerate arm — the empty guard maps
/// `&[]` to `Vec::new()` before the sweep. The empty-Vec-at-empty
/// fixpoint is LOAD-BEARING as the drift catch for an override
/// that omits the guard. Pinned by clause (127) and by
/// `modal_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::modal_variants(<T as ClosedSet>::ALL)` equals
/// `<T as ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the closed-
/// set well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// appears at exactly one position in the full-set slice, every
/// per-variant count is `1`, [`Self::max_variant_count`] collapses
/// to `1`, and the filter hits EVERY variant — the flat-histogram
/// fixpoint pins the direction-axis degeneracy at every corner.
/// Pinned by clause (127) and by
/// `modal_variants_returns_all_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::modal_variants(&doubled_full_set)` equals
/// `<T as ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the doubled-
/// full-set slice appends [`Self::ALL`] to itself, so every
/// variant appears at EXACTLY two positions,
/// [`Self::max_variant_count`] collapses to `2`, and the filter
/// hits EVERY variant. Pinned by
/// `modal_variants_returns_all_on_the_doubled_full_set_across_every_kind`.
///
/// Matching-singleton contract: `T::modal_variants(&[v])` equals
/// `vec![v]` for every variant `v` UNCONDITIONALLY — a matching
/// singleton hits `count(v) == 1` at the target and `count(w) ==
/// 0` at every other variant, [`Self::max_variant_count`]
/// collapses to `1`, and the filter hits ONLY the target. Pinned
/// by
/// `modal_variants_returns_the_target_only_on_every_matching_singleton_across_every_variant`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::max_variant_count`] is a function of that
/// multiset alone, and the filter over [`Self::ALL`] (which does
/// NOT depend on `items`' ordering) is a function of that multiset
/// alone. Pinned by
/// `modal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, filtered over [`Self::ALL`] via the standard-
/// library [`Iterator::filter`] combinator against
/// [`Self::max_variant_count`]. The composition uses one
/// `is_empty()`-guarded
/// `T::ALL.iter().copied().filter(|&v| count == max).collect()`
/// sweep, so the sweep costs `O(T::CARDINALITY * n)` on slice
/// arity `n` (one [`Self::max_variant_count`] fold + one
/// [`Self::CARDINALITY`]-bounded filter sweep, plus one output-
/// `Vec` allocation of at most [`Self::CARDINALITY`] entries) —
/// no `PartialEq`/`Eq`/`Hash` supertrait bound, no bitset-shape
/// carrier.
///
/// Future consumers that compose against [`Self::modal_variants`]:
/// a `tatara-check` predicate `(check-phases-modes …)` that
/// reports EVERY `WorkloadPhase` tied at the modal multiplicity in
/// a rollout window (surfacing "which phases tie for the most
/// visits?" rather than the single first-witness argmax); an LSP
/// diagnostic on a Lisp-author-written closed-set field that
/// reports the full modal witness-collection as an author-facing
/// "most common: `<label1>`, `<label2>` (each appears N times)"
/// hint whose completeness matters for a tie'd histogram; a
/// Sekiban audit-trail per-window classification argmax
/// witness-collection that lists EVERY classification tied at the
/// modal band, distinguishing "unique mode = X" from "modes = X,
/// Y" without paying for the full histogram; a scheduler-fairness
/// heuristic that treats the entire modal witness-collection as a
/// "hot bucket" to depriorize evenly rather than committing on the
/// first tied argmax. Each binds to ONE typed `Vec<Self>`-return
/// direction-anchor aggregate on the trait rather than re-deriving
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == T::max_variant_count(items))
/// .collect()` inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction × declaration-
/// order × argmax) corner on the (return-shape × direction ×
/// ordering) grid, sitting peer to [`Self::modal_variant`]
/// (`Option<Self>`, argmax, declaration) one RETURN-SHAPE axis
/// over. The natural next lifts past this corner are: a
/// `sorted_modal_variants(items) -> Vec<Self>` LEX-ORDER peer
/// closing the (return-shape × ordering) face at the (Vec<Self>,
/// argmax, lex) corner; an `antimodal_variants(items) ->
/// Vec<Self>` DIRECTION peer opening the (Vec<Self>, argmin,
/// declaration) corner; and a `sorted_antimodal_variants(items) ->
/// Vec<Self>` LEX-ORDER × DIRECTION peer closing the 2×2×2 =
/// 8-corner (return-shape × direction × ordering) cube at its
/// final (Vec<Self>, argmin, lex) corner. Downstream consumers
/// wanting a `usize`-return "how many modes tie?" scalar compose
/// on this projection through `.len()` without an additional
/// substrate primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// `Vec<Self>`-return argmax witness-collection becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline
/// `T::ALL.iter().copied().filter(|&v| T::count_occurrences_of(v, items) == T::max_variant_count(items)).collect()`
/// composition. THEORY.md §V.1 — knowable platform; the (set-
/// level × `Vec<Self>` × argmax) witness-collection corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which variants ALL tie for the histogram's peak?"
/// site pre-lift. Naming it on the trait makes the projection a
/// TYPED CONSEQUENCE of the substrate's per-target multiplicity
/// primitive [`Self::count_occurrences_of`] filtered over
/// [`Self::ALL`] against [`Self::max_variant_count`]. THEORY.md
/// §VI.1 — generation over composition; the argmax witness-
/// collection emerges from the composition of TWO substrate
/// primitives ([`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`]) with an
/// `iter().copied().filter().collect()` combinator over
/// [`Self::ALL`].
///
/// Frontier inspiration: R's `names(table(items))[table(items) ==
/// max(table(items))]` — the direction-anchor filter yielding
/// every argmax key on a factor histogram; Julia's
/// `[k for (k, v) in StatsBase.countmap(items) if v ==
/// maximum(values(StatsBase.countmap(items)))]` on ties;
/// Python's `[k for k, v in collections.Counter(items).items()
/// if v == max(collections.Counter(items).values())]` yielding
/// the complete modal set on ties; Haskell's `map fst . filter
/// (\(_, n) -> n == maximum (map snd hist)) $ hist` on
/// `Ord`-instance carriers; Clojure's `(let [f (frequencies
/// coll) m (apply max (vals f))] (keep-indexed (fn [_ [k v]]
/// (when (= v m) k)) f))` idiom; Coq's `list_modes` combinator
/// on a decidable-equality carrier yielding the complete argmax
/// set. Translation through pleme-io primitives: the N-ary
/// `Vec<Self>`-return declaration-order argmax witness-collection
/// on the closed-set trait binds through [`Self::ALL`] filtered
/// via the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] against
/// [`Self::max_variant_count`] — no new dep, no supertrait bound
/// (the [`Self::index_of`] projection [`Self::count_occurrences_of`]
/// threads through replaces the `Eq`/`Hash` bound the standard-
/// library `Counter` / `frequencies` / `countmap` argmax
/// signatures demand), no histogram-carrier allocation (the
/// `filter` sweep yields a `Vec<Self>` without materializing the
/// intermediate `Vec<usize>` histogram; the sweep streams through
/// per-target counts one at a time and commits at each tied
/// argmax hit).
fn modal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == max)
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "sorted modal variants" projection
/// — the `Vec<Self>` LEX-ORDER witness-collection of EVERY variant
/// of [`Self::sorted_variants`] whose per-target count equals
/// [`Self::max_variant_count`], preserving
/// [`Self::sorted_variants`]'s canonical ASCII-lex order and
/// returning the empty vector when `items` is empty. The LEX-ORDER
/// peer of [`Self::modal_variants`] one ORDERING axis over,
/// CLOSING the (set-level × `Vec<Self>` × statistical-aggregate ×
/// argmax × ordering) 2-corner face at its lex-arm past the
/// declaration-arm the sibling [`Self::modal_variants`] opened.
/// One RETURN-SHAPE axis over from [`Self::sorted_modal_variant`]
/// (`Option<Self>` first-witness under the lex tie-break): while
/// [`Self::sorted_modal_variant`] reports the FIRST tied argmax
/// variant walked in lex order, this projection reports EVERY
/// tied argmax variant walked in lex order — a COMPLETE witness-
/// collection with a canonical alphabetic display order, no tie-
/// break choice. Not a fresh substrate primitive on the index
/// axis — the projection emerges from ONE
/// `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) == T::max_variant_count(items))
/// .collect()` sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::max_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `Vec::new()` past the (max ==
/// 0, every-count == 0) degenerate arm where an unguarded sweep
/// would silently return `T::sorted_variants()`.
///
/// Multiset-agreement identity: for every slice `items`,
/// `T::sorted_modal_variants(items)` is a LEX-ORDER PERMUTATION of
/// `T::modal_variants(items)` — the two projections agree as
/// multisets because both filter [`Self::ALL`] under the same
/// predicate (`count(v) == T::max_variant_count(items)`); they
/// differ ONLY in the walk order that generates the returned Vec
/// (declaration order vs lex order). Pinned by
/// `sorted_modal_variants_is_a_lex_permutation_of_modal_variants_across_every_triple`.
///
/// First-witness identity: for every NON-EMPTY slice `items`,
/// `T::sorted_modal_variants(items).first().copied() ==
/// T::sorted_modal_variant(items)` — the plural's HEAD equals the
/// singular's commit because both walk [`Self::sorted_variants`]
/// in lex order and commit at the first tied argmax. Pinned by
/// `sorted_modal_variants_head_agrees_with_sorted_modal_variant_across_every_triple`.
///
/// Count-composition identity: for every slice `items` and every
/// variant `v` in the returned Vec,
/// `T::count_occurrences_of(v, items) == T::max_variant_count(items)`
/// — every element of the returned Vec achieves the modal
/// multiplicity exactly. Pinned by
/// `sorted_modal_variants_elements_agree_with_max_variant_count_across_every_triple`.
///
/// Present-arm containment identity: for every NON-EMPTY slice
/// `items`, `T::sorted_modal_variants(items)` is a SUBSET (as
/// multiset) of `T::present_variants(items)` — every modal
/// variant is present (its count is at least
/// `T::max_variant_count(items) >= 1` on non-empty slices, so it
/// appears in the slice). Pinned by
/// `sorted_modal_variants_are_present_across_every_triple`.
///
/// Non-emptiness identity: `T::sorted_modal_variants(items).is_empty()`
/// iff `items.is_empty()` on every slice — the empty-slice arm
/// is the SOLE empty-Vec arm; on every non-empty slice the filter
/// hits at least one variant whose count equals
/// [`Self::max_variant_count`] (the finite discrete histogram
/// achieves its max at at least one bin). Pinned by
/// `sorted_modal_variants_is_non_empty_iff_slice_is_non_empty_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_modal_variants(&[])` is the
/// empty `Vec<Self>` UNCONDITIONALLY — the empty slice hits zero
/// positions, so every per-variant occurrence count is `0`,
/// [`Self::max_variant_count`] collapses to `0`, and an UNGUARDED
/// `T::sorted_variants().into_iter().filter(|v| count(v) == 0)
/// .collect()` sweep would silently return `T::sorted_variants()`
/// past the (max == 0, every-count == 0) degenerate arm — the
/// empty guard maps `&[]` to `Vec::new()` before the sweep. The
/// empty-Vec-at-empty fixpoint is LOAD-BEARING as the drift catch
/// for an override that omits the guard. Pinned by clause (128)
/// and by
/// `sorted_modal_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_modal_variants(<T as ClosedSet>::ALL)` equals
/// `T::sorted_variants()` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every
/// variant appears at exactly one position in the full-set slice,
/// every per-variant count is `1`, [`Self::max_variant_count`]
/// collapses to `1`, and the filter hits EVERY variant walked in
/// lex order — the flat-histogram fixpoint pins the direction-
/// axis degeneracy at every corner. The lex-order arm is LOAD-
/// BEARING as the drift catch for an override that walks
/// [`Self::ALL`] instead of [`Self::sorted_variants`] — a
/// declaration-order filter on the full set would return
/// `T::ALL.to_vec()`, bifurcating the lex-order walk when
/// `T::first() != T::sorted_first()`. Pinned by clause (128) and
/// by
/// `sorted_modal_variants_returns_sorted_variants_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_modal_variants(&doubled_full_set)` equals
/// `T::sorted_variants()` UNCONDITIONALLY — the doubled-full-set
/// slice appends [`Self::ALL`] to itself, so every variant
/// appears at EXACTLY two positions,
/// [`Self::max_variant_count`] collapses to `2`, and the filter
/// hits EVERY variant walked in lex order. Pinned by
/// `sorted_modal_variants_returns_sorted_variants_on_the_doubled_full_set_across_every_kind`.
///
/// Matching-singleton contract:
/// `T::sorted_modal_variants(&[v])` equals `vec![v]` for every
/// variant `v` UNCONDITIONALLY — a matching singleton hits
/// `count(v) == 1` at the target and `count(w) == 0` at every
/// other variant, [`Self::max_variant_count`] collapses to `1`,
/// and the filter hits ONLY the target regardless of walk order
/// (declaration vs lex). Pinned by
/// `sorted_modal_variants_returns_the_target_only_on_every_matching_singleton_across_every_variant`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::max_variant_count`] is a function of that
/// multiset alone, and the filter over [`Self::sorted_variants`]
/// (which does NOT depend on `items`' ordering) is a function of
/// that multiset alone. Pinned by
/// `sorted_modal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the
/// trait level, filtered over [`Self::sorted_variants`] via the
/// standard-library [`Iterator::filter`] combinator against
/// [`Self::max_variant_count`]. The composition uses one
/// `is_empty()`-guarded
/// `T::sorted_variants().into_iter().filter(|&v| count == max)
/// .collect()` sweep, so the sweep costs `O(N log N +
/// T::CARDINALITY * n)` on slice arity `n` (the
/// [`Self::sorted_variants`] canonical-lex-sort step + one
/// [`Self::max_variant_count`] fold + one
/// [`Self::CARDINALITY`]-bounded filter sweep, plus one output-
/// `Vec` allocation of at most [`Self::CARDINALITY`] entries) —
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no histogram-carrier allocation (the `filter`
/// sweep yields a `Vec<Self>` without materializing the
/// intermediate `Vec<usize>` histogram; the sweep streams
/// through per-target counts one at a time and commits at each
/// tied argmax hit).
///
/// Future consumers that compose against
/// [`Self::sorted_modal_variants`]: a `tatara-check` predicate
/// `(check-phases-modes-lex …)` that reports EVERY `WorkloadPhase`
/// tied at the modal multiplicity in a rollout window under a
/// canonical alphabetic display order (distinct from
/// [`Self::modal_variants`]'s declaration-order-canonical form
/// consumed by scheduler-oriented tools that route through
/// declaration slots); an LSP diagnostic that reports the full
/// modal witness-collection as an author-facing "most common
/// (alphabetical): `<label1>`, `<label2>` (each appears N times)"
/// hint aligned with lex-ordered enumeration surfaces; a Sekiban
/// audit-trail per-window classification argmax witness-collection
/// whose element order matches the UI's lex-ordered navigation
/// menu (so the audit trail and the UI's default enumeration
/// always agree on tied windows); a metric-emitter that binds a
/// Prometheus-style `mode_variants_lex` label alongside the
/// sibling `mode_variants_decl` label so tied-argmax rollouts
/// surface BOTH complete witness-collections on the same gauge.
/// Each binds to ONE typed `Vec<Self>`-return lex-order
/// witness-collection aggregate on the trait rather than re-
/// deriving `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) ==
/// T::max_variant_count(items)).collect()` inline (behind an
/// `is_empty()` short-circuit) per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × statistical-aggregate × argmax × ordering)
/// 2-corner face at the lex-arm past the declaration-arm
/// [`Self::modal_variants`] opened. Combined with the sibling
/// (`modal_variant`, `sorted_modal_variant`) closure one
/// RETURN-SHAPE axis over, the (set-level × {`Option<Self>`,
/// `Vec<Self>`} × statistical-aggregate × argmax × ordering)
/// 2×2 = 4-corner face on the direction-anchor argmax arm now
/// closes at every corner — the `Option<Self>` first-witness
/// row + `Vec<Self>` complete-witness row × declaration-order
/// column + lex-order column all pinned. The natural next lifts
/// past this closure are: an `antimodal_variants(items) ->
/// Vec<Self>` DIRECTION peer opening the (Vec<Self>, argmin,
/// declaration) corner on the direction-anchor argmin arm; a
/// `sorted_antimodal_variants(items) -> Vec<Self>` LEX-ORDER
/// × DIRECTION peer CLOSING the (return-shape × direction ×
/// ordering) 2×2×2 = 8-corner cube at its final (Vec<Self>,
/// argmin, lex) corner. Downstream consumers wanting a
/// `usize`-return "how many modes tie?" scalar compose on
/// this projection through `.len()` without an additional
/// substrate primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// `Vec<Self>`-return lex-order argmax witness-collection
/// becomes a TYPE-level primitive on the closed-set trait
/// rather than a per-consumer inline
/// `T::sorted_variants().into_iter().filter(|&v| T::count_occurrences_of(v, items) == T::max_variant_count(items)).collect()`
/// composition. THEORY.md §V.1 — knowable platform; the (set-
/// level × `Vec<Self>` × argmax × lex-order) witness-collection
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variants ALL tie for the
/// histogram's peak under a canonical alphabetic display
/// order?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's per-target
/// multiplicity primitive [`Self::count_occurrences_of`]
/// filtered over [`Self::sorted_variants`] against
/// [`Self::max_variant_count`]. THEORY.md §VI.1 — generation
/// over composition; the lex-order argmax witness-collection
/// emerges from the composition of THREE substrate primitives
/// ([`Self::sorted_variants`] +
/// [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`]) with an
/// `into_iter().filter().collect()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `sort(names(table(items))[table(items)
/// == max(table(items))])` — the lex-sorted direction-anchor
/// filter yielding every argmax key on a factor histogram;
/// Julia's `sort([k for (k, v) in StatsBase.countmap(items) if
/// v == maximum(values(StatsBase.countmap(items)))])` on ties;
/// Python's `sorted([k for k, v in
/// collections.Counter(items).items() if v ==
/// max(collections.Counter(items).values())])` yielding the
/// alphabetic-sorted complete modal set on ties; Haskell's
/// `sort . map fst . filter (\(_, n) -> n == maximum (map snd
/// hist)) $ hist` on `Ord`-instance carriers; Clojure's `(let
/// [f (frequencies coll) m (apply max (vals f))] (sort (keep-
/// indexed (fn [_ [k v]] (when (= v m) k)) f)))`; Racket's
/// `(sort (filter (λ (v) (= (count-occ v items)
/// (max-count items))) T) string<? #:key label)`. Translation
/// through pleme-io primitives: the N-ary `Vec<Self>`-return
/// lex-order argmax witness-collection on the closed-set trait
/// binds through [`Self::sorted_variants`] composed with the
/// substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] against
/// [`Self::max_variant_count`] — no new dep, no supertrait
/// bound (the [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through and
/// [`Self::sorted_variants`]'s ASCII-`sort_unstable_by_key`
/// replace the `Eq`/`Hash` + `Ord` bound the standard-library
/// counter+lex-sort signatures demand), no histogram-carrier
/// allocation.
fn sorted_modal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == max)
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "antimodal variants" projection —
/// the `Vec<Self>` DECLARATION-ORDER witness-collection of EVERY
/// variant of [`Self::ALL`] whose per-target count equals
/// [`Self::min_variant_count`], preserving [`Self::ALL`]'s canonical
/// declaration order and returning the empty vector when `items` is
/// empty. The DIRECTION-ANCHOR ARGMIN peer of [`Self::modal_variants`]
/// one DIRECTION axis over, OPENING the argmin arm of the (set-level
/// × `Vec<Self>` × statistical-aggregate × direction) column past
/// the argmax arm the sibling [`Self::modal_variants`] opened. One
/// RETURN-SHAPE axis over from [`Self::antimodal_variant`]
/// (`Option<Self>` first-witness under the declaration tie-break):
/// while [`Self::antimodal_variant`] reports the FIRST tied argmin
/// variant walked in declaration order, this projection reports
/// EVERY tied argmin variant walked in declaration order — a
/// COMPLETE witness-collection with the canonical authoring order,
/// no tie-break choice. Not a fresh substrate primitive on the
/// index axis — the projection emerges from ONE
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))
/// .collect()` sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::min_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `Vec::new()` past the (min == 0,
/// every-count == 0) degenerate arm where an unguarded sweep would
/// silently return `T::ALL.to_vec()`.
///
/// Multiset-agreement identity (direction-axis peer of modal): for
/// every slice `items`, `T::antimodal_variants(items)` and
/// `T::modal_variants(items)` are BOTH subsets of `T::ALL` filtered
/// under the same per-target multiplicity primitive
/// [`Self::count_occurrences_of`] — the former reports the tied
/// LEAST-COMMON variants (argmin), the latter reports the tied
/// MOST-COMMON variants (argmax). The two agree AS SETS iff the
/// histogram is flat (i.e. `T::max_variant_count(items) ==
/// T::min_variant_count(items)`), where BOTH projections yield the
/// same complete witness-collection (`T::ALL` on the full-set and
/// doubled-full-set fixpoints). Pinned by
/// `antimodal_variants_equals_modal_variants_on_flat_histogram_slices_across_every_kind`.
///
/// Missing-variants identity (min == 0 fixpoint): for every slice
/// `items` with [`Self::is_missing_any`] holding (equivalently,
/// [`Self::min_variant_count`]`(items) == 0`),
/// `T::antimodal_variants(items) == T::missing_variants(items)` —
/// on any slice with a missing variant, the argmin filter collapses
/// onto the MISSING witness-collection because every present variant
/// hits count `>= 1 > 0 == min`, and every missing variant hits
/// count `== 0 == min`. The argmin projection ABSORBS the missing-
/// witness projection at the min == 0 slice arm without an extra
/// substrate primitive. Pinned by
/// `antimodal_variants_equals_missing_variants_when_min_is_zero_across_every_triple`.
///
/// Head-composition identity: for every non-empty slice `items`,
/// `T::antimodal_variants(items).first().copied() ==
/// T::antimodal_variant(items)` — the plural's HEAD equals the
/// singular's declaration-order-first argmin commit because both
/// walk `T::ALL` in declaration order and commit at the first tied
/// argmin. Sibling posture to
/// `modal_variants_head_agrees_with_modal_variant_across_every_triple`
/// on the argmin arm. Pinned by
/// `antimodal_variants_head_agrees_with_antimodal_variant_across_every_triple`.
///
/// Presence-partition identity (argmin partitions ALL): for every
/// slice `items`, every element of `T::antimodal_variants(items)`
/// hits `count == T::min_variant_count(items)` — the projection is
/// the level-set of the per-target multiplicity primitive at the
/// min-count band. Pinned by
/// `antimodal_variants_elements_agree_with_min_variant_count_across_every_triple`.
///
/// Empty-slice contract: `T::antimodal_variants(&[])` is `Vec::new()`
/// on every implementor UNCONDITIONALLY — the empty slice hits zero
/// positions, every per-variant count collapses to `0`, and an
/// UNGUARDED `T::ALL.iter().copied().filter(|&v| count(v) == 0).collect()`
/// sweep would silently return `T::ALL.to_vec()` past the (min == 0,
/// every-count == 0) degenerate arm where every variant satisfies
/// `count == min == 0`. The `is_empty()` short-circuit maps `&[]`
/// to the empty vector explicitly, preventing the degenerate
/// argmin filter from firing on the empty slice. Sibling posture to
/// `modal_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`
/// on the argmin arm one DIRECTION axis over: the empty-slice arm
/// is the FIXPOINT of every set-level statistical-aggregate
/// projection because every histogram-driven predicate collapses
/// to `0 == 0`. Pinned by
/// `antimodal_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract: `T::antimodal_variants(&[v])` is
/// `vec![v]` at cardinality 1 (where the singleton hits the sole
/// variant which is trivially both argmax and argmin) and depends
/// on cardinality for larger sets — at `T::CARDINALITY >= 2`, a
/// matching singleton hits `count(v) == 1 == max` for the target
/// and `count(w) == 0 == min` for every other variant `w != v`,
/// so the argmin filter yields `T::ALL.iter().copied().filter(|&w|
/// index_of(w) != index_of(v)).collect()` (every non-target variant
/// in declaration order) rather than `vec![v]`. Sibling posture to
/// `antimodal_variant_returns_some_target_on_every_singleton_slice_at_cardinality_one_across_every_variant`
/// on the Vec arm: at cardinality `>= 2`, the singular argmin
/// commits at the FIRST non-target variant; this plural argmin
/// yields EVERY non-target variant. Pinned by
/// `antimodal_variants_returns_the_non_target_variants_on_matching_singleton_at_cardinality_gte_two_across_every_kind`.
///
/// Full-set contract: `T::antimodal_variants(<T as ClosedSet>::ALL)`
/// is `T::ALL.to_vec()` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins every variant of `T::ALL` at exactly one position on
/// the full-set slice, every per-target count is `1`,
/// `T::min_variant_count(T::ALL) == 1`, and the argmin filter hits
/// EVERY variant (the flat-histogram fixpoint pins the direction-
/// axis degeneracy — argmax and argmin coincide at every corner).
/// Sibling posture to
/// `modal_variants_returns_all_on_the_full_set_across_every_kind`
/// on the argmin arm — on the flat-histogram full-set fixpoint the
/// two direction-arms agree. Pinned by
/// `antimodal_variants_returns_all_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract: `T::antimodal_variants(&<T as
/// ClosedSet>::ALL.iter().chain(<T as ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())`
/// is `T::ALL.to_vec()` UNCONDITIONALLY — every variant of `T::ALL`
/// appears at exactly two positions of the doubled-full-set slice,
/// every per-variant count is `2`, `T::min_variant_count(doubled)
/// == 2`, and the argmin filter hits EVERY variant walked in
/// declaration order. The flat-histogram fixpoint pins the
/// direction-axis degeneracy at the doubled fixpoint too. Pinned by
/// `antimodal_variants_returns_all_on_the_doubled_full_set_across_every_kind`.
///
/// Ordering-axis invariance (of the ambient sort): the projection
/// is intrinsically ordering-agnostic in the SLICE ordering — the
/// argmin filter is a function of the multiset of per-target
/// counts, not of the slice ordering. Pinned by
/// `antimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] filtered over [`Self::ALL`]
/// against the just-lifted set-level scalar
/// [`Self::min_variant_count`] at the trait level. The composition
/// uses one `T::ALL` iteration mapping each variant through
/// [`Self::count_occurrences_of`] filtered by equality with
/// [`Self::min_variant_count`], so the sweep costs O(T::CARDINALITY
/// × n) on slice arity `n` — allocation-free per-slot on the
/// filter, one `Vec::with_capacity(T::CARDINALITY)`-shaped
/// allocation for the returned witness collection, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::antimodal_variants`]: a `tatara-check` predicate
/// `(check-phases-antimodes …)` that verifies a rollout window's
/// COMPLETE least-common witness-collection (rather than the
/// FIRST-witness commit) matches a Lisp-authored antimode spec
/// exactly at plan time — catching a spec that would silently omit
/// a tied argmin variant; an LSP "least common (all ties)" author
/// hint that renders every tied least-common variant as an
/// author-facing witness collection (`":severities [:info :warn]"
/// → "least common (tied): [:crit, :error]"`) rather than the
/// singular-commit surface; a Sekiban audit-trail argmin witness-
/// collection carrying every tied least-common variant per window
/// (rather than the first-commit surface); a `tatara-lisp::macro_expand::Expander`
/// hygiene pass reporting EVERY under-referenced identifier tied at
/// the min-count band against a required closed vocabulary; a per-
/// slot rate limiter reading its throttle floor as the complete
/// least-common variant collection (`"warn when ANY tied-least-
/// common variant appears fewer than K times"`) rather than a
/// single-witness threshold. Each binds to ONE typed N-ary
/// declaration-order argmin witness-collection on the trait rather
/// than re-deriving `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))
/// .collect()` inline per callsite.
///
/// Compounding closure: the substrate now knows the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction × ordering)
/// hypercube at THREE of its FOUR remaining corners — argmax
/// declaration ([`Self::modal_variants`]), argmax lex
/// ([`Self::sorted_modal_variants`]), and argmin declaration (this
/// lift). Combined with the sibling (`antimodal_variant`,
/// `sorted_antimodal_variant`) closure one RETURN-SHAPE axis over
/// on the (`Option<Self>`, argmin, {decl, lex}) 2-corner face, the
/// (set-level × {`Option<Self>`, `Vec<Self>`} × statistical-
/// aggregate × argmin × ordering) 2×2 = 4-corner face on the
/// direction-anchor argmin arm now closes at THREE of its FOUR
/// corners. The remaining corner — `sorted_antimodal_variants`
/// (Vec<Self>, argmin, lex) — closes the entire 2×2×2 = 8-corner
/// cube on the direction-anchor face at its final corner. Future
/// consumers wanting a min-count-band exhaustive witness in lex
/// order pin directly against that final lift's `sorted_variants()`
/// composition idiom without re-deriving the empty-guard + filter
/// shape.
///
/// Theory anchor: THEORY.md §III — the typescape; the (Vec<Self>,
/// argmin, declaration) witness-collection corner becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))
/// .collect()` composition. THEORY.md §V.1 — knowable platform;
/// naming the corner on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's `count_occurrences_of` primitive
/// filtered over `T::ALL` against `min_variant_count`. THEORY.md
/// §VI.1 — generation over composition; the declaration-order
/// argmin witness-collection emerges from the composition of TWO
/// substrate primitives ([`Self::count_occurrences_of`] +
/// [`Self::min_variant_count`]) with an `iter().filter().collect()`
/// combinator, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's
/// `names(table(items))[table(items) == min(table(items))]` — the
/// direction-anchor filter yielding every argmin key on a factor
/// histogram; Racket's `(filter (λ (v) (= (count-occ v items)
/// (min-count items))) T)` on a decidable-equality carrier;
/// Python's `[k for k, v in Counter(items).items() if v ==
/// min(Counter(items).values())]` yielding the complete least-common
/// set on ties; Haskell's `filter (\v -> countOcc v items ==
/// minVariantCount items) allVariants` on `Ord`-instance carriers.
/// Translation through pleme-io primitives: the N-ary declaration-
/// order argmin witness-collection on the closed-set trait binds
/// through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] filtered over [`Self::ALL`] against
/// the substrate's just-lifted [`Self::min_variant_count`] scalar
/// — no new dep, no supertrait bound (the [`Self::index_of`]
/// projection [`Self::count_occurrences_of`] threads through
/// replaces the `Eq`/`Hash` bound the standard-library
/// counter+argmin signatures demand), no histogram-carrier
/// allocation (the `filter` sweep yields a `Vec<Self>` without
/// materializing the intermediate `Vec<usize>` histogram; the sweep
/// streams through per-target counts one at a time and commits at
/// each tied argmin hit).
fn antimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == min)
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "sorted antimodal variants" projection
/// — the `Vec<Self>` LEX-ORDER witness-collection of EVERY variant of
/// [`Self::sorted_variants`] whose per-target count equals
/// [`Self::min_variant_count`], preserving [`Self::sorted_variants`]'s
/// canonical ASCII-lex order and returning the empty vector when
/// `items` is empty. The FINAL corner CLOSING the (return-shape ×
/// direction × ordering) 2×2×2 = 8-corner cube at its (Vec<Self>,
/// argmin, lex) corner. The LEX-ORDER peer of [`Self::antimodal_variants`]
/// one ORDERING axis over on the argmin arm — peer to
/// [`Self::sorted_modal_variants`] one DIRECTION axis over on the
/// lex-ordering arm. One RETURN-SHAPE axis over from
/// [`Self::sorted_antimodal_variant`] (`Option<Self>` first-witness
/// under the lex tie-break): while [`Self::sorted_antimodal_variant`]
/// reports the FIRST tied argmin variant walked in lex order, this
/// projection reports EVERY tied argmin variant walked in lex order —
/// a COMPLETE witness-collection with a canonical alphabetic display
/// order, no tie-break choice. Not a fresh substrate primitive on
/// the index axis — the projection emerges from ONE
/// `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) == T::min_variant_count(items))
/// .collect()` sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::min_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `Vec::new()` past the (min == 0,
/// every-count == 0) degenerate arm where an unguarded sweep would
/// silently return `T::sorted_variants()`.
///
/// Multiset-agreement identity: for every slice `items`,
/// `T::sorted_antimodal_variants(items)` is a LEX-ORDER PERMUTATION
/// of `T::antimodal_variants(items)` — the two projections agree as
/// multisets because both filter under the same predicate
/// (`count(v) == T::min_variant_count(items)`); they differ ONLY in
/// the walk order that generates the returned Vec (declaration order
/// vs lex order). Sibling posture to
/// `sorted_modal_variants_is_a_lex_permutation_of_modal_variants_across_every_triple`
/// one DIRECTION axis over. Pinned by
/// `sorted_antimodal_variants_is_a_lex_permutation_of_antimodal_variants_across_every_triple`.
///
/// First-witness identity: for every NON-EMPTY slice `items`,
/// `T::sorted_antimodal_variants(items).first().copied() ==
/// T::sorted_antimodal_variant(items)` — the plural's HEAD equals
/// the singular's commit because both walk [`Self::sorted_variants`]
/// in lex order and commit at the first tied argmin. Pinned by
/// `sorted_antimodal_variants_head_agrees_with_sorted_antimodal_variant_across_every_triple`.
///
/// Count-composition identity: for every slice `items` and every
/// variant `v` in the returned Vec,
/// `T::count_occurrences_of(v, items) == T::min_variant_count(items)`
/// — every element of the returned Vec achieves the least-common
/// multiplicity exactly. Pinned by
/// `sorted_antimodal_variants_elements_agree_with_min_variant_count_across_every_triple`.
///
/// Direction-axis degeneracy identity (flat-histogram slices): on
/// any flat-histogram slice (where `T::max_variant_count(items) ==
/// T::min_variant_count(items)`), `T::sorted_antimodal_variants(items)
/// == T::sorted_modal_variants(items)` — the argmin and argmax
/// lex-order witness-collections COINCIDE because the min-count band
/// and max-count band ARE the same band. Sibling posture to
/// `antimodal_variants_equals_modal_variants_on_flat_histogram_slices_across_every_kind`
/// one ORDERING axis over. Pinned on the full-set and doubled-full-
/// set fixpoints. Pinned by
/// `sorted_antimodal_variants_equals_sorted_modal_variants_on_flat_histogram_slices_across_every_kind`.
///
/// Missing-variants identity (min == 0 fixpoint): for every slice
/// `items` with [`Self::is_missing_any`] holding (equivalently,
/// [`Self::min_variant_count`]`(items) == 0`),
/// `T::sorted_antimodal_variants(items) ==
/// T::sorted_missing_variants(items)` — on any slice with a missing
/// variant, the argmin filter collapses onto the SORTED MISSING
/// witness-collection because every present variant hits count `>=
/// 1 > 0`, and every missing variant hits count `== 0 == min`, all
/// walked in lex order. The lex-order argmin projection ABSORBS the
/// lex-order missing-witness projection at the min == 0 slice arm
/// without an extra substrate primitive. Sibling posture to
/// `antimodal_variants_equals_missing_variants_when_min_is_zero_across_every_triple`
/// one ORDERING axis over. Pinned by
/// `sorted_antimodal_variants_equals_sorted_missing_variants_when_min_is_zero_across_every_triple`.
///
/// Non-emptiness identity:
/// `T::sorted_antimodal_variants(items).is_empty()` iff
/// `items.is_empty()` on every slice — the empty-slice arm is the
/// SOLE empty-Vec arm; on every non-empty slice the filter hits at
/// least one variant whose count equals [`Self::min_variant_count`]
/// (the finite discrete histogram achieves its min at at least one
/// bin). Pinned by
/// `sorted_antimodal_variants_is_non_empty_iff_slice_is_non_empty_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_antimodal_variants(&[])` is the
/// empty `Vec<Self>` UNCONDITIONALLY — the empty slice hits zero
/// positions, so every per-variant occurrence count is `0`,
/// [`Self::min_variant_count`] collapses to `0`, and an UNGUARDED
/// `T::sorted_variants().into_iter().filter(|v| count(v) == 0)
/// .collect()` sweep would silently return `T::sorted_variants()`
/// past the (min == 0, every-count == 0) degenerate arm — the empty
/// guard maps `&[]` to `Vec::new()` before the sweep. The empty-Vec-
/// at-empty fixpoint is LOAD-BEARING as the drift catch for an
/// override that omits the guard. Pinned by clause (130) and by
/// `sorted_antimodal_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_antimodal_variants(<T as ClosedSet>::ALL)` equals
/// `T::sorted_variants()` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant appears
/// at exactly one position in the full-set slice, every per-variant
/// count is `1`, [`Self::min_variant_count`] collapses to `1`, and
/// the filter hits EVERY variant walked in lex order — the flat-
/// histogram fixpoint pins the direction-axis degeneracy (argmin
/// and argmax coincide) at the lex-ordering arm. The lex-order arm
/// is LOAD-BEARING as the drift catch for an override that walks
/// [`Self::ALL`] instead of [`Self::sorted_variants`] — a
/// declaration-order filter on the full set would return
/// `T::ALL.to_vec()`, bifurcating the lex-order walk when
/// `T::first() != T::sorted_first()`. Pinned by clause (130) and by
/// `sorted_antimodal_variants_returns_sorted_variants_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_antimodal_variants(&doubled_full_set)` equals
/// `T::sorted_variants()` UNCONDITIONALLY — the doubled-full-set
/// slice appends [`Self::ALL`] to itself, so every variant appears
/// at EXACTLY two positions, [`Self::min_variant_count`] collapses
/// to `2`, and the filter hits EVERY variant walked in lex order.
/// The flat-histogram fixpoint pins the direction-axis degeneracy
/// at the doubled endpoint too. Pinned by
/// `sorted_antimodal_variants_returns_sorted_variants_on_the_doubled_full_set_across_every_kind`.
///
/// Matching-singleton contract:
/// `T::sorted_antimodal_variants(&[v])` is `vec![v]` at cardinality
/// 1 and depends on cardinality for larger sets — at
/// `T::CARDINALITY >= 2`, a matching singleton hits `count(v) == 1
/// == max` for the target and `count(w) == 0 == min` for every
/// other variant `w != v`, so the lex-order argmin filter yields
/// the LEX-ORDER-PRESERVING sub-slice of `T::sorted_variants()`
/// obtained by dropping the target (every non-target variant
/// walked in lex order). Sibling posture to
/// `antimodal_variants_returns_the_non_target_variants_on_matching_singleton_at_cardinality_gte_two_across_every_kind`
/// one ORDERING axis over: the declaration-order plural drops the
/// target from `T::ALL`; the lex-order plural drops the target from
/// `T::sorted_variants()`. Pinned by
/// `sorted_antimodal_variants_returns_the_non_target_variants_on_matching_singleton_at_cardinality_gte_two_across_every_kind`.
///
/// Ordering-axis invariance on the input axis: the projection is
/// intrinsically ordering-agnostic on the INPUT axis — permuting
/// `items` preserves its multiset of variant identities, so
/// [`Self::count_occurrences_of`] is a function of that multiset
/// alone, [`Self::min_variant_count`] is a function of that multiset
/// alone, and the filter over [`Self::sorted_variants`] (which does
/// NOT depend on `items`' ordering) is a function of that multiset
/// alone. Pinned by
/// `sorted_antimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::count_occurrences_of`] primitive at the trait
/// level, filtered over [`Self::sorted_variants`] via the standard-
/// library [`Iterator::filter`] combinator against
/// [`Self::min_variant_count`]. The composition uses one
/// `is_empty()`-guarded
/// `T::sorted_variants().into_iter().filter(|&v| count == min)
/// .collect()` sweep, so the sweep costs `O(N log N +
/// T::CARDINALITY * n)` on slice arity `n` (the
/// [`Self::sorted_variants`] canonical-lex-sort step + one
/// [`Self::min_variant_count`] fold + one
/// [`Self::CARDINALITY`]-bounded filter sweep, plus one output-`Vec`
/// allocation of at most [`Self::CARDINALITY`] entries) — no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// histogram-carrier allocation (the `filter` sweep yields a
/// `Vec<Self>` without materializing the intermediate `Vec<usize>`
/// histogram; the sweep streams through per-target counts one at a
/// time and commits at each tied argmin hit).
///
/// Future consumers that compose against
/// [`Self::sorted_antimodal_variants`]: a `tatara-check` predicate
/// `(check-phases-antimodes-lex …)` that reports EVERY `WorkloadPhase`
/// tied at the min-count band in a rollout window under a canonical
/// alphabetic display order (distinct from
/// [`Self::antimodal_variants`]'s declaration-order-canonical form
/// consumed by scheduler-oriented tools routing through declaration
/// slots); an LSP diagnostic that reports the full antimodal
/// witness-collection as an author-facing "least common
/// (alphabetical): `<label1>`, `<label2>` (each appears N times)"
/// hint aligned with lex-ordered enumeration surfaces; a Sekiban
/// audit-trail per-window classification argmin witness-collection
/// whose element order matches the UI's lex-ordered navigation menu
/// (so the audit trail and the UI's default enumeration always agree
/// on tied windows); a metric-emitter that binds a Prometheus-style
/// `antimode_variants_lex` label alongside the sibling
/// `antimode_variants_decl` label so tied-argmin rollouts surface
/// BOTH complete witness-collections on the same gauge. Each binds
/// to ONE typed `Vec<Self>`-return lex-order witness-collection
/// aggregate on the trait rather than re-deriving
/// `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) ==
/// T::min_variant_count(items)).collect()` inline (behind an
/// `is_empty()` short-circuit) per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction × ordering) 2×2×2
/// = 8-corner cube at its FINAL (Vec<Self>, argmin, lex) corner. All
/// four (return-shape × direction × ordering) Vec-return corners
/// (argmax declaration [`Self::modal_variants`], argmax lex
/// [`Self::sorted_modal_variants`], argmin declaration
/// [`Self::antimodal_variants`], argmin lex [`Self::sorted_antimodal_variants`])
/// now close at every corner, PARALLELING the four (return-shape ×
/// direction × ordering) Option-return corners (argmax declaration
/// [`Self::modal_variant`], argmax lex [`Self::sorted_modal_variant`],
/// argmin declaration [`Self::antimodal_variant`], argmin lex
/// [`Self::sorted_antimodal_variant`]) closed one RETURN-SHAPE axis
/// over. The (return-shape × direction × ordering) 2×2×2 = 8-corner
/// cube's `Vec<Self>` face + its `Option<Self>` face are BOTH FULLY
/// CLOSED as of this lift — the (return-shape × direction × ordering
/// × return-arity) 2×2×2×2 = 16-corner hypercube's statistical-
/// aggregate slab pins every corner. Future consumers wanting a
/// `usize`-return "how many antimodes tie?" scalar compose on this
/// projection through `.len()` without an additional substrate
/// primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// `Vec<Self>`-return lex-order argmin witness-collection becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline
/// `T::sorted_variants().into_iter().filter(|&v| T::count_occurrences_of(v, items) == T::min_variant_count(items)).collect()`
/// composition. THEORY.md §V.1 — knowable platform; the (set-level
/// × `Vec<Self>` × argmin × lex-order) witness-collection corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which variants ALL tie for the histogram's floor
/// under a canonical alphabetic display order?" site pre-lift.
/// Naming it on the trait makes the projection a TYPED CONSEQUENCE
/// of the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] filtered over
/// [`Self::sorted_variants`] against [`Self::min_variant_count`].
/// THEORY.md §VI.1 — generation over composition; the lex-order
/// argmin witness-collection emerges from the composition of THREE
/// substrate primitives ([`Self::sorted_variants`] +
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`])
/// with an `into_iter().filter().collect()` combinator, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `sort(names(table(items))[table(items)
/// == min(table(items))])` — the lex-sorted direction-anchor filter
/// yielding every argmin key on a factor histogram; Julia's
/// `sort([k for (k, v) in StatsBase.countmap(items) if v ==
/// minimum(values(StatsBase.countmap(items)))])` on ties; Python's
/// `sorted([k for k, v in collections.Counter(items).items() if v
/// == min(collections.Counter(items).values())])` yielding the
/// alphabetic-sorted complete antimodal set on ties; Haskell's
/// `sort . map fst . filter (\(_, n) -> n == minimum (map snd hist))
/// $ hist` on `Ord`-instance carriers; Racket's `(sort (filter (λ
/// (v) (= (count-occ v items) (min-count items))) T) string<?
/// #:key label)`. Translation through pleme-io primitives: the
/// N-ary `Vec<Self>`-return lex-order argmin witness-collection on
/// the closed-set trait binds through [`Self::sorted_variants`]
/// composed with the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] against
/// [`Self::min_variant_count`] — no new dep, no supertrait bound
/// (the [`Self::index_of`] projection [`Self::count_occurrences_of`]
/// threads through and [`Self::sorted_variants`]'s ASCII-
/// `sort_unstable_by_key` replace the `Eq`/`Hash` + `Ord` bound the
/// standard-library counter+lex-sort signatures demand), no
/// histogram-carrier allocation.
fn sorted_antimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == min)
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants tie for the mode?"
/// cardinality-count projection — the `usize` SET-LEVEL count of
/// variants of [`Self::ALL`] whose per-target multiplicity in `items`
/// equals [`Self::max_variant_count`], computed as the filter-count
/// reduction over [`Self::ALL`] of the (`count(v) == max`)
/// direction-anchor predicate. The USIZE-RETURN OPENER on the (set-
/// level × usize × statistical-aggregate × direction × argmax)
/// cardinality-count corner peer to the (set-level × `Vec<Self>` ×
/// statistical-aggregate × direction × argmax) [`Self::modal_variants`]
/// complete-witness corner one RETURN-SHAPE axis over on the modal-
/// aggregation matrix (`Vec<Self>` witness → `usize` cardinality via
/// the trivial `.len()` sharpening) AND peer to the (set-level ×
/// usize × multiplicity-band `== 1`) [`Self::count_unique_variants`]
/// and (set-level × usize × multiplicity-band `>= 2`)
/// [`Self::count_repeating_variants`] and (set-level × usize ×
/// multiplicity-band `== 0`) [`Self::count_missing`] cardinality-
/// count corners one AGGREGATION-KIND axis over on the (set-level ×
/// usize) row of the equivalence-partition surface (multiplicity-
/// band → direction-anchor aggregation-kind bifurcation). Not a fresh
/// substrate primitive on the index axis — the count emerges from
/// one `is_empty()`-guarded filter-count reduction over [`Self::ALL`]
/// of the (`count(v) == max`) predicate against the just-lifted
/// [`Self::max_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `0` past the (max == 0, every-
/// count == 0) degenerate arm where an unguarded sweep would silently
/// return [`Self::CARDINALITY`] (every variant satisfies the vacuous
/// `0 == 0` predicate) — equivalently, the length of the just-lifted
/// [`Self::modal_variants`] complete-witness Vec.
///
/// Length-composition identity: for every slice `items`,
/// `T::count_modal_variants(items) == T::modal_variants(items).len()`
/// — the set-level modal-set cardinality is EXACTLY the length of
/// the declaration-order-preserving argmax witness-collection. The
/// count is a return-shape SHARPENING of the Vec-return witness
/// (`Vec<Self>` → `usize`) — every downstream consumer that only
/// needs the cardinality (a Prometheus-style `mode_tie_count` gauge,
/// an LSP `N modes tie for the peak` hint, a scheduler-fairness
/// witness that dispatches on "is the mode unique?") pays no Vec
/// allocation. Pinned by clause (131) and by
/// `count_modal_variants_equals_modal_variants_len_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_modal_variants(items) == <T as ClosedSet>::ALL.iter().filter(|&&v| T::count_occurrences_of(v, items) == T::max_variant_count(items)).count()`
/// on non-empty slices, and `0` on the empty slice — the set-level
/// count is the EXACT filter-count reduction over [`Self::ALL`] of
/// the (`count(v) == max`) predicate against
/// [`Self::max_variant_count`], with the empty-slice guard mapping
/// `&[]` to `0` past the (max == 0, every-count == 0) degenerate arm
/// where the unguarded sweep would return [`Self::CARDINALITY`].
/// Pinned by
/// `count_modal_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::count_modal_variants(items) == T::variant_counts(items).iter().filter(|&&c| c == T::max_variant_count(items)).count()`
/// on non-empty slices, and `0` on the empty slice — the set-level
/// count is EXACTLY the count of per-slot histogram bars whose scalar
/// height equals the modal multiplicity. Independent cross-check
/// distinct from the filter-count arm on the return-shape (`Vec<usize>`
/// vs the direct per-target `count == max` predicate) axis. Pinned by
/// `count_modal_variants_equals_variant_counts_filter_equals_max_count_across_every_triple`.
///
/// Non-emptiness identity: for every slice `items`,
/// `T::count_modal_variants(items) > 0` iff `!items.is_empty()` on
/// every slice — the empty-slice arm is the SOLE zero-arm; on every
/// non-empty slice the finite discrete histogram achieves its max at
/// at least one bin, so at least one variant contributes. Pinned by
/// `count_modal_variants_is_strictly_positive_iff_slice_is_non_empty_across_every_triple`.
///
/// Bounded-above identity: for every slice `items`,
/// `T::count_modal_variants(items) <= T::CARDINALITY` AND
/// `T::count_modal_variants(items) <= T::count_distinct(items)` on
/// non-empty slices — the count is bounded above by the ambient
/// cardinality (there are only `T::CARDINALITY` variants to sample
/// from) AND by the count of PRESENT variants (a modal variant on a
/// non-empty slice achieves `max >= 1`, so it is a fortiori present
/// with mult `>= 1`). Pinned by
/// `count_modal_variants_is_bounded_above_by_cardinality_and_count_distinct_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::max_variant_count`] + [`Self::count_occurrences_of`] (both
/// ordering-agnostic) via a standard-library `filter().count()`
/// combinator over the closed set. No separate
/// `sorted_count_modal_variants` peer is needed. Pinned by
/// `count_modal_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_modal_variants(&[])` is `0`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::max_variant_count`] collapses to `0`, and an UNGUARDED
/// `T::ALL.iter().filter(|v| count(v) == 0).count()` sweep would
/// silently return [`Self::CARDINALITY`] past the (max == 0, every-
/// count == 0) degenerate arm where every variant satisfies the
/// vacuous `0 == 0` predicate — the empty guard maps `&[]` to `0`
/// before the sweep. The `0`-at-empty fixpoint is LOAD-BEARING as
/// the drift catch for an override that omits the guard. Pinned by
/// clause (131) and by
/// `count_modal_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::count_modal_variants(&[v])` is `1` for
/// every variant `v` — a singleton slice hits exactly one variant at
/// exactly one position, so exactly ONE per-target multiplicity is
/// `1` (the target `v`) and the others are `0`;
/// [`Self::max_variant_count`] collapses to `1` and only `v`
/// satisfies `count == max`. Pinned by
/// `count_modal_variants_returns_one_on_every_singleton_across_every_variant`.
///
/// Full-set contract: `T::count_modal_variants(<T as ClosedSet>::ALL)`
/// is [`Self::CARDINALITY`] UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant appears
/// at EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::max_variant_count`] collapses to `1`, and
/// the (`count == max`) filter hits EVERY variant — the flat-
/// histogram fixpoint pins the modal-set at full cardinality.
/// Pinned by clause (131) and by
/// `count_modal_variants_returns_cardinality_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_modal_variants(&doubled_full_set)` is
/// [`Self::CARDINALITY`] UNCONDITIONALLY — the doubled full set hits
/// every variant at EXACTLY TWO positions, every per-variant count
/// is `2`, [`Self::max_variant_count`] collapses to `2`, and the
/// (`count == max`) filter hits EVERY variant on the flat-histogram
/// fixpoint. Together with the full-set arm (which pins the same
/// [`Self::CARDINALITY`] fixpoint at max `== 1`), the doubled-full-
/// set arm demonstrates that the projection is INVARIANT under
/// uniform slice-multiplication on flat-histogram slices — pinning
/// the projection as a MODAL-TIE cardinality rather than the
/// modal-multiplicity scalar [`Self::max_variant_count`] which
/// TRANSITIONS from `1` to `2` between the two flat-histogram
/// fixpoints. Pinned by clause (131) and by
/// `count_modal_variants_returns_cardinality_on_the_doubled_full_set_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::max_variant_count`] + [`Self::count_occurrences_of`] via
/// the standard-library `filter().count()` combinator over
/// [`Self::ALL`]. The sweep cost is `O(T::CARDINALITY * n)` on slice
/// arity `n` — one [`Self::max_variant_count`] fold + one bounded
/// filter-count sweep — with NO short-circuit (the projection reports
/// a scalar cardinality distinct from the sibling
/// [`Self::modal_variant`] `Option<Self>` witness which DOES short-
/// circuit at the first tied argmax). The count materializes as a
/// scalar `usize` return value from a standard-library
/// `Iterator::count` combinator; no allocation, no set-shape carrier,
/// no supertrait bound (the [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`] primitives replace the `Eq`/`Hash`
/// bound the standard-library group-by-then-argmax signatures
/// demand). The default trait body threads the filter-count reduction
/// verbatim and satisfies every fixpoint arm + every composition-
/// equality arm for free; every implementor gets THIS projection.
///
/// Future consumers that compose against
/// [`Self::count_modal_variants`]: a `tatara-check` predicate
/// `(check-phases-mode-tie-count …)` that reports how many
/// `WorkloadPhase` variants tie at the modal multiplicity in a
/// rollout window (surfacing "is the mode unique or is there a tie?"
/// as a typed scalar rather than a full witness-collection); an LSP
/// diagnostic on a Lisp-author-written closed-set field that renders
/// the scalar mode-tie count as an author-facing "N modes tie for the
/// peak" hint rather than materializing the full Vec; a Sekiban
/// audit-trail per-window classification argmax metric that emits
/// the scalar tie-cardinality as a Prometheus gauge (paying no Vec
/// allocation per emission on the hot path); a scheduler-fairness
/// heuristic that branches on `count_modal_variants == 1` (unique
/// mode) vs `> 1` (tied) without materializing the full argmax set.
/// Each binds to ONE typed `usize`-return direction-anchor
/// cardinality-count aggregate on the trait rather than re-deriving
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) ==
/// T::max_variant_count(items)).count()` inline (behind an
/// `is_empty()` short-circuit) per callsite OR paying a Vec
/// allocation via `T::modal_variants(items).len()`.
///
/// Compounding closure: this projection OPENS the (set-level × usize
/// × statistical-aggregate × direction × argmax) cardinality-count
/// corner on the modal-aggregation matrix, sitting peer to the
/// (set-level × `Vec<Self>` × statistical-aggregate × direction ×
/// argmax) [`Self::modal_variants`] complete-witness corner one
/// RETURN-SHAPE axis over. The natural next lift past this corner is
/// `count_antimodal_variants(items) -> usize` DIRECTION peer one
/// direction axis over — opening the (set-level × usize ×
/// statistical-aggregate × direction × argmin) cardinality-count
/// corner past the argmax arm. Downstream consumers wanting the
/// (bool, usize) × direction 2×2 = 4-corner (bool-existence ×
/// usize-cardinality × direction) hyper-face composed of
/// (`has_unique_mode` = `count_modal_variants == 1`, THIS) for the
/// argmax arm and (`has_unique_antimode`, `count_antimodal_variants`)
/// for the argmin arm compose on this projection through a scalar
/// equality test against `1` without an additional substrate
/// primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level count of modal-tie variants becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|v| T::count_occurrences_of(*v, items) == T::max_variant_count(items)).count()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × usize × modal-tie) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "how many variants tie for the peak?" site pre-lift.
/// Naming it on the trait makes the count a TYPED CONSEQUENCE of the
/// substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] filtered through [`Self::ALL`]
/// against [`Self::max_variant_count`] and reduced via `.count()`.
/// THEORY.md §VI.1 — generation over composition; the count emerges
/// from the composition of TWO substrate primitives
/// ([`Self::count_occurrences_of`] + [`Self::max_variant_count`])
/// with an `iter().copied().filter(…).count()` combinator over
/// [`Self::ALL`], not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `sum(table(items) == max(table(items)))`
/// — the direction-anchor filter-count yielding the modal-tie
/// cardinality on a factor histogram; Julia's
/// `count(v -> v == maximum(values(StatsBase.countmap(items))), values(StatsBase.countmap(items)))`
/// on ties; Python's `sum(1 for v in collections.Counter(items).values() if v == max(collections.Counter(items).values()))`
/// yielding the complete modal-tie cardinality; Haskell's
/// `length . filter (== maximum hist) $ hist` on a histogram carrier;
/// Clojure's `(let [f (frequencies coll) m (apply max (vals f))] (count (filter #(= % m) (vals f))))`;
/// Coq's `length (filter (fun c => Nat.eqb c (maximum hist)) hist)`
/// on a decidable-equality-derived histogram; SQL's `SELECT COUNT(*)
/// FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant) WHERE
/// c = (SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM t GROUP BY
/// variant))` — the canonical set-level modal-tie cardinality.
/// Translation through pleme-io primitives: the N-ary set-level
/// modal-tie count on the closed-set trait binds through an
/// `iter().copied().filter(…).count()` combinator over [`Self::ALL`]
/// with the substrate's per-target multiplicity primitive against
/// the just-lifted [`Self::max_variant_count`] scalar — no new dep,
/// no supertrait bound (the [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`] pair replaces the `Eq`/`Hash` bound
/// the standard-library `Counter` / `frequencies` / `countmap`
/// argmax-tie-count signatures demand), no histogram-carrier
/// allocation (the sweep streams through per-target counts one at a
/// time and accumulates a scalar rather than materializing the
/// intermediate `Vec<usize>` histogram OR the [`Self::modal_variants`]
/// witness Vec).
fn count_modal_variants(items: &[Self]) -> usize {
if items.is_empty() {
return 0;
}
let max = <Self as ClosedSet>::max_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == max)
.count()
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants tie for the
/// antimode?" cardinality-count projection — the `usize` SET-LEVEL
/// count of variants of [`Self::ALL`] whose per-target multiplicity
/// in `items` equals [`Self::min_variant_count`], computed as the
/// filter-count reduction over [`Self::ALL`] of the
/// (`count(v) == min`) direction-anchor predicate. The USIZE-RETURN
/// CLOSER on the (set-level × usize × statistical-aggregate ×
/// direction × argmin) cardinality-count corner CLOSING the (set-
/// level × usize × statistical-aggregate × direction) 2-corner
/// cardinality-count face peer to the (set-level × usize ×
/// statistical-aggregate × direction × argmax)
/// [`Self::count_modal_variants`] cardinality-count corner one
/// DIRECTION axis over on the modal-aggregation matrix, AND peer to
/// the (set-level × `Vec<Self>` × statistical-aggregate × direction ×
/// argmin) [`Self::antimodal_variants`] complete-witness corner one
/// RETURN-SHAPE axis over on the same direction-anchor arm
/// (`Vec<Self>` witness → `usize` cardinality via the trivial
/// `.len()` sharpening). Not a fresh substrate primitive on the
/// index axis — the count emerges from one `is_empty()`-guarded
/// filter-count reduction over [`Self::ALL`] of the
/// (`count(v) == min`) predicate against the just-lifted
/// [`Self::min_variant_count`] scalar, guarded by an empty-slice
/// short-circuit that maps `&[]` to `0` past the (min == 0, every-
/// count == 0) degenerate arm where an unguarded sweep would
/// silently return [`Self::CARDINALITY`] (every variant satisfies
/// the vacuous `0 == 0` predicate) — equivalently, the length of the
/// just-lifted [`Self::antimodal_variants`] complete-witness Vec.
///
/// Length-composition identity: for every slice `items`,
/// `T::count_antimodal_variants(items) == T::antimodal_variants(items).len()`
/// — the set-level antimodal-set cardinality is EXACTLY the length
/// of the declaration-order-preserving argmin witness-collection.
/// The count is a return-shape SHARPENING of the Vec-return witness
/// (`Vec<Self>` → `usize`) — every downstream consumer that only
/// needs the cardinality (a Prometheus-style `antimode_tie_count`
/// gauge, an LSP `N variants tie for the trough` hint, a scheduler-
/// fairness witness that dispatches on "is the antimode unique?")
/// pays no Vec allocation. Sibling posture to
/// `count_modal_variants_equals_modal_variants_len_across_every_triple`
/// one DIRECTION axis over. Pinned by clause (132) and by
/// `count_antimodal_variants_equals_antimodal_variants_len_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_antimodal_variants(items) == <T as ClosedSet>::ALL.iter().filter(|&&v| T::count_occurrences_of(v, items) == T::min_variant_count(items)).count()`
/// on non-empty slices, and `0` on the empty slice — the set-level
/// count is the EXACT filter-count reduction over [`Self::ALL`] of
/// the (`count(v) == min`) predicate against
/// [`Self::min_variant_count`], with the empty-slice guard mapping
/// `&[]` to `0` past the (min == 0, every-count == 0) degenerate arm
/// where the unguarded sweep would return [`Self::CARDINALITY`].
/// Pinned by
/// `count_antimodal_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::count_antimodal_variants(items) == T::variant_counts(items).iter().filter(|&&c| c == T::min_variant_count(items)).count()`
/// on non-empty slices, and `0` on the empty slice — the set-level
/// count is EXACTLY the count of per-slot histogram bars whose
/// scalar height equals the antimodal multiplicity. Independent
/// cross-check distinct from the filter-count arm on the return-
/// shape (`Vec<usize>` vs the direct per-target `count == min`
/// predicate) axis. Pinned by
/// `count_antimodal_variants_equals_variant_counts_filter_equals_min_count_across_every_triple`.
///
/// Missing-count identity (min == 0 fixpoint): for every slice
/// `items` with [`Self::is_missing_any`] holding (equivalently,
/// [`Self::min_variant_count`]`(items) == 0`),
/// `T::count_antimodal_variants(items) == T::count_missing(items)`
/// — on any slice with a missing variant, the argmin filter
/// collapses onto the SET-LEVEL MISSING CARDINALITY because every
/// present variant hits count `>= 1 > 0` and every missing variant
/// hits count `== 0 == min`. The set-level argmin cardinality
/// ABSORBS the set-level missing-cardinality at the min == 0 slice
/// arm without an extra substrate primitive — a scalar-cardinality
/// analogue of the [`Self::antimodal_variants`] Vec-return
/// missing-witness absorption on the same fixpoint. Sibling posture
/// to `antimodal_variants_equals_missing_variants_when_min_is_zero_across_every_triple`
/// one RETURN-SHAPE axis over. Pinned by
/// `count_antimodal_variants_equals_count_missing_when_min_is_zero_across_every_triple`.
///
/// Direction-axis degeneracy identity (flat-histogram slices): on
/// any flat-histogram slice (where `T::max_variant_count(items) ==
/// T::min_variant_count(items)`), `T::count_antimodal_variants(items)
/// == T::count_modal_variants(items)` — the argmin and argmax
/// cardinality-counts COINCIDE because the min-count band and max-
/// count band ARE the same band. Sibling posture to
/// `antimodal_variants_equals_modal_variants_on_flat_histogram_slices_across_every_kind`
/// one RETURN-SHAPE axis over. Pinned on the full-set and doubled-
/// full-set fixpoints. Pinned by
/// `count_antimodal_variants_equals_count_modal_variants_on_flat_histogram_slices_across_every_kind`.
///
/// Non-emptiness identity: for every slice `items`,
/// `T::count_antimodal_variants(items) > 0` iff `!items.is_empty()`
/// on every slice — the empty-slice arm is the SOLE zero-arm; on
/// every non-empty slice the finite discrete histogram achieves its
/// min at at least one bin, so at least one variant contributes.
/// Sibling posture to
/// `count_modal_variants_is_strictly_positive_iff_slice_is_non_empty_across_every_triple`
/// one DIRECTION axis over. Pinned by
/// `count_antimodal_variants_is_strictly_positive_iff_slice_is_non_empty_across_every_triple`.
///
/// Bounded-above identity: for every slice `items`,
/// `T::count_antimodal_variants(items) <= T::CARDINALITY` — the
/// count is bounded above by the ambient cardinality (there are
/// only `T::CARDINALITY` variants to sample from). Unlike
/// [`Self::count_modal_variants`], the argmin cardinality is NOT
/// bounded above by [`Self::count_distinct`] — the argmin band can
/// contain MISSING variants (count `== 0`) which are NOT counted in
/// [`Self::count_distinct`], so on any slice with a missing variant
/// the antimodal cardinality can exceed the distinct cardinality
/// (the sole non-degenerate asymmetry between the argmax and argmin
/// cardinality-count corners on the direction axis). Pinned by
/// `count_antimodal_variants_is_bounded_above_by_cardinality_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::min_variant_count`] + [`Self::count_occurrences_of`] (both
/// ordering-agnostic) via a standard-library `filter().count()`
/// combinator over the closed set. No separate
/// `sorted_count_antimodal_variants` peer is needed. Pinned by
/// `count_antimodal_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_antimodal_variants(&[])` is `0`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::min_variant_count`] collapses to `0`, and an UNGUARDED
/// `T::ALL.iter().filter(|v| count(v) == 0).count()` sweep would
/// silently return [`Self::CARDINALITY`] past the (min == 0, every-
/// count == 0) degenerate arm where every variant satisfies the
/// vacuous `0 == 0` predicate — the empty guard maps `&[]` to `0`
/// before the sweep. The `0`-at-empty fixpoint is LOAD-BEARING as
/// the drift catch for an override that omits the guard. Pinned by
/// clause (132) and by
/// `count_antimodal_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract:
/// `T::count_antimodal_variants(&[v])` is `1` at cardinality `1`
/// (the singleton is the full set, min == max == 1, every variant
/// satisfies `count == min`), and `T::CARDINALITY - 1` at
/// cardinality `>= 2` (the target `v` has count `1`, every other
/// variant has count `0 == min`, and the filter hits every non-
/// target variant). The singleton arm is LOAD-BEARING as the DRIFT-
/// CATCH-BY-ASYMMETRY between the argmax and argmin corners on the
/// direction axis: at cardinality `>= 2`, `count_modal_variants` is
/// `1` on a singleton but THIS projection is `T::CARDINALITY - 1` —
/// an override that mirrors the argmax singleton fixpoint onto the
/// argmin corner bifurcates loudly at the (min-arm × singleton)
/// endpoint. Pinned by
/// `count_antimodal_variants_returns_cardinality_minus_one_on_matching_singleton_at_cardinality_gte_two_across_every_kind`.
///
/// Full-set contract:
/// `T::count_antimodal_variants(<T as ClosedSet>::ALL)` is
/// [`Self::CARDINALITY`] UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant appears
/// at EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::min_variant_count`] collapses to `1`, and
/// the (`count == min`) filter hits EVERY variant — the flat-
/// histogram fixpoint pins the antimodal-set at full cardinality.
/// Pinned by clause (132) and by
/// `count_antimodal_variants_returns_cardinality_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_antimodal_variants(&doubled_full_set)` is
/// [`Self::CARDINALITY`] UNCONDITIONALLY — the doubled full set
/// hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::min_variant_count`] collapses to `2`, and
/// the (`count == min`) filter hits EVERY variant on the flat-
/// histogram fixpoint. Together with the full-set arm (which pins
/// the same [`Self::CARDINALITY`] fixpoint at min `== 1`), the
/// doubled-full-set arm demonstrates that the projection is
/// INVARIANT under uniform slice-multiplication on flat-histogram
/// slices — pinning the projection as an ANTIMODAL-TIE cardinality
/// rather than the antimodal-multiplicity scalar
/// [`Self::min_variant_count`] which TRANSITIONS from `1` to `2`
/// between the two flat-histogram fixpoints. Pinned by clause (132)
/// and by
/// `count_antimodal_variants_returns_cardinality_on_the_doubled_full_set_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::min_variant_count`] + [`Self::count_occurrences_of`] via
/// the standard-library `filter().count()` combinator over
/// [`Self::ALL`]. The sweep cost is `O(T::CARDINALITY * n)` on slice
/// arity `n` — one [`Self::min_variant_count`] fold + one bounded
/// filter-count sweep — with NO short-circuit (the projection
/// reports a scalar cardinality distinct from the sibling
/// [`Self::antimodal_variant`] `Option<Self>` witness which DOES
/// short-circuit at the first tied argmin). The count materializes
/// as a scalar `usize` return value from a standard-library
/// `Iterator::count` combinator; no allocation, no set-shape carrier,
/// no supertrait bound (the [`Self::count_occurrences_of`] +
/// [`Self::min_variant_count`] primitives replace the `Eq`/`Hash`
/// bound the standard-library group-by-then-argmin signatures
/// demand). The default trait body threads the filter-count
/// reduction verbatim and satisfies every fixpoint arm + every
/// composition-equality arm for free; every implementor gets THIS
/// projection.
///
/// Future consumers that compose against
/// [`Self::count_antimodal_variants`]: a `tatara-check` predicate
/// `(check-phases-antimode-tie-count …)` that reports how many
/// `WorkloadPhase` variants tie at the antimodal multiplicity in a
/// rollout window (surfacing "is the least-visited phase unique or
/// is there a tie among the rarely-visited?" as a typed scalar
/// rather than a full witness-collection); an LSP diagnostic on a
/// Lisp-author-written closed-set field that renders the scalar
/// antimode-tie count as an author-facing "N variants tie for the
/// trough" hint rather than materializing the full Vec; a Sekiban
/// audit-trail per-window classification argmin metric that emits
/// the scalar tie-cardinality as a Prometheus gauge (paying no Vec
/// allocation per emission on the hot path); a scheduler-fairness
/// heuristic that branches on `count_antimodal_variants == 1`
/// (unique antimode → drop the unique-least-loaded worker safely)
/// vs `> 1` (tied → apply a secondary tie-break) without
/// materializing the full argmin set. Each binds to ONE typed
/// `usize`-return direction-anchor cardinality-count aggregate on
/// the trait rather than re-deriving `T::ALL.iter().copied()
/// .filter(|&v| T::count_occurrences_of(v, items) ==
/// T::min_variant_count(items)).count()` inline (behind an
/// `is_empty()` short-circuit) per callsite OR paying a Vec
/// allocation via `T::antimodal_variants(items).len()`.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// usize × statistical-aggregate × direction) 2-corner cardinality-
/// count face on the modal-aggregation matrix at its argmin corner
/// past the argmax [`Self::count_modal_variants`] corner one
/// DIRECTION axis over. Combined with the sibling closure one
/// RETURN-SHAPE axis over on the (set-level × `Vec<Self>` ×
/// statistical-aggregate × direction) 2-corner complete-witness face
/// via ([`Self::modal_variants`], [`Self::antimodal_variants`]), the
/// (set-level × {`usize`, `Vec<Self>`} × statistical-aggregate ×
/// direction) 2×2 = 4-corner (return-shape × direction) face on the
/// declaration-order arm now closes at every corner — a two-surface
/// (scalar cardinality × Vec witness) × two-direction (argmax ×
/// argmin) presentation of the modal-set on the substrate. The
/// natural next lift past this closure is the ORDERING peer arm on
/// the (set-level × usize × statistical-aggregate) column — but the
/// ordering-axis invariance identity above collapses that lift on
/// this projection (no separate `sorted_count_antimodal_variants`
/// peer is needed); the next OPENING lift is the SET-LEVEL BOOLEAN
/// unique-antimode predicate `has_unique_antimode(items) ==
/// (count_antimodal_variants(items) == 1)` — the bool-return
/// SHARPENING of THIS scalar cardinality against the `1` threshold
/// on the argmin arm, peer to the argmax `has_unique_mode` predicate
/// one DIRECTION axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level count of antimodal-tie variants becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::ALL.iter().filter(|v| T::count_occurrences_of(*v,
/// items) == T::min_variant_count(items)).count()` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (set-level × usize × antimodal-tie) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "how many variants tie for the trough?" site pre-lift.
/// Naming it on the trait makes the count a TYPED CONSEQUENCE of
/// the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] filtered through [`Self::ALL`]
/// against [`Self::min_variant_count`] and reduced via `.count()`.
/// THEORY.md §VI.1 — generation over composition; the count emerges
/// from the composition of TWO substrate primitives
/// ([`Self::count_occurrences_of`] + [`Self::min_variant_count`])
/// with an `iter().copied().filter(…).count()` combinator over
/// [`Self::ALL`], not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `sum(table(items) ==
/// min(table(items)))` — the direction-anchor filter-count yielding
/// the antimodal-tie cardinality on a factor histogram; Julia's
/// `count(v -> v == minimum(values(StatsBase.countmap(items))), values(StatsBase.countmap(items)))`
/// on ties; Python's
/// `sum(1 for v in collections.Counter(items).values() if v == min(collections.Counter(items).values()))`
/// yielding the complete antimodal-tie cardinality; Haskell's
/// `length . filter (== minimum hist) $ hist` on a histogram
/// carrier; Clojure's `(let [f (frequencies coll) m (apply min (vals f))] (count (filter #(= % m) (vals f))))`;
/// Coq's `length (filter (fun c => Nat.eqb c (minimum hist)) hist)`
/// on a decidable-equality-derived histogram; SQL's `SELECT COUNT(*)
/// FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant)
/// WHERE c = (SELECT MIN(c) FROM (SELECT COUNT(*) AS c FROM t GROUP
/// BY variant))` — the canonical set-level antimodal-tie
/// cardinality. Translation through pleme-io primitives: the N-ary
/// set-level antimodal-tie count on the closed-set trait binds
/// through an `iter().copied().filter(…).count()` combinator over
/// [`Self::ALL`] with the substrate's per-target multiplicity
/// primitive against the just-lifted [`Self::min_variant_count`]
/// scalar — no new dep, no supertrait bound (the
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`] pair
/// replaces the `Eq`/`Hash` bound the standard-library `Counter` /
/// `frequencies` / `countmap` argmin-tie-count signatures demand),
/// no histogram-carrier allocation (the sweep streams through per-
/// target counts one at a time and accumulates a scalar rather than
/// materializing the intermediate `Vec<usize>` histogram OR the
/// [`Self::antimodal_variants`] witness Vec). One critical
/// pleme-io-specific asymmetry against the argmax peer: the argmin
/// corner CAN admit missing variants (count `== 0 == min`), so on
/// any slice with a missing variant this cardinality can exceed
/// [`Self::count_distinct`] — the count is bounded above by
/// [`Self::CARDINALITY`] alone (not by the count of present
/// variants), unlike [`Self::count_modal_variants`] whose modal
/// variant always has count `>= 1` on non-empty slices and is a
/// fortiori present.
fn count_antimodal_variants(items: &[Self]) -> usize {
if items.is_empty() {
return 0;
}
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::count_occurrences_of(v, items) == min)
.count()
}
/// The N-ARY ORDERING-AGNOSTIC "target is a modal variant" per-target
/// predicate — `true` iff `target`'s per-target multiplicity in `items`
/// coincides with [`Self::max_variant_count`] AND `items` is non-empty,
/// computed as the conjunction of the non-emptiness guard with the
/// strict-equality test of [`Self::count_occurrences_of`] against
/// [`Self::max_variant_count`]. The BOOL-RETURN opener on the (per-
/// target × bool × statistical-aggregate × direction × argmax) corner,
/// positioned as the direct SET-LEVEL-EXISTENTIAL-LIFT INVERSE — the
/// per-target arity peer — of the (set-level × usize × statistical-
/// aggregate × direction × argmax) cardinality-count corner
/// [`Self::count_modal_variants`] one ARITY axis over (set-level ×
/// `usize` → per-target × `bool`), AND the STATISTICAL-AGGREGATE peer
/// of the pre-existing (per-target × bool × multiplicity-band `== 1`)
/// [`Self::is_unique_occurrence_of`] one PREDICATE-KIND axis over
/// (multiplicity-band → statistical-aggregate) on the same per-target
/// bool row of the equivalence-partition surface. Not a fresh
/// substrate primitive on the index axis — the predicate emerges from
/// one non-emptiness guard conjoined with one strict-equality test of
/// [`Self::count_occurrences_of`] against [`Self::max_variant_count`],
/// equivalently the [`Vec::contains`] membership of the target in the
/// just-lifted [`Self::modal_variants`] argmax witness-collection.
///
/// Count-composition identity: for every NON-EMPTY slice `items` and
/// every target `v`,
/// `T::is_modal_variant_of(v, items) == (T::count_occurrences_of(v, items) == T::max_variant_count(items))`
/// — the per-target bool predicate is EXACTLY the strict-equality
/// test of the per-target multiplicity primitive against the modal
/// multiplicity scalar. The canonical form the body uses. Pinned by
/// `is_modal_variant_of_holds_iff_count_equals_max_variant_count_on_non_empty_across_every_target_and_triple`.
///
/// Modal-witness membership identity: for every slice `items` and
/// every target `v`,
/// `T::is_modal_variant_of(v, items) == T::modal_variants(items).contains(&v)`
/// — the per-target bool predicate is EXACTLY the membership test of
/// the target in the declaration-order-preserving argmax witness-
/// collection. Independent cross-check distinct from the count-
/// composition arm on the surface axis (Vec-membership vs scalar
/// equality); pinned by
/// `is_modal_variant_of_agrees_with_modal_variants_membership_across_every_target_and_triple`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::modal_variant(items).is_some() == <T as ClosedSet>::ALL.iter().any(|&v| T::is_modal_variant_of(v, items))`
/// — the set-level `Option<Self>` argmax witness [`Self::modal_variant`]
/// is `Some` iff at least one target is modal, i.e. iff the
/// existential quantification over [`Self::ALL`] of THIS per-target
/// predicate holds. Equivalently `!items.is_empty()`, since the
/// modal variant is always present on any non-empty slice.
/// Pinned by
/// `is_modal_variant_of_existential_lift_agrees_with_modal_variant_across_every_triple`.
///
/// Cardinality-count identity: for every slice `items`,
/// `T::count_modal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_modal_variant_of(v, items)).count()`
/// — the set-level modal-tie count is the EXACT filter-count reduction
/// over [`Self::ALL`] of THIS per-target predicate. This identity binds
/// the per-target ARITY axis against the set-level ARITY axis one
/// arity axis over on the (arity × statistical-aggregate) face —
/// pinning THIS per-target predicate as the ATOMIC contribution to
/// the set-level cardinality-count aggregate. Pinned by
/// `is_modal_variant_of_count_equals_count_modal_variants_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_occurrences_of`] + [`Self::max_variant_count`] (both
/// ordering-agnostic) via a strict-equality test. No separate
/// `sorted_is_modal_variant_of` peer is needed. Pinned by
/// `is_modal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_modal_variant_of(v, &[])` is `false`
/// for every target `v` UNCONDITIONALLY — the empty slice hits zero
/// positions, [`Self::max_variant_count`] collapses to `0`, and an
/// UNGUARDED strict-equality test against `0` would silently return
/// `true` for every target past the (max == 0, every-count == 0)
/// degenerate arm — the empty-slice guard maps `&[]` to `false`
/// before the test. Sibling posture to
/// [`Self::count_modal_variants`]'s empty-slice guard one ARITY axis
/// over: the set-level cardinality-count collapses to `0` at the
/// empty slice; THIS per-target predicate collapses to `false` at
/// every target on the same endpoint (the disjunction over targets
/// coincides with the set-level `0` / `Some` fixpoint). The `false`-
/// at-empty fixpoint is LOAD-BEARING as the drift catch for an
/// override that omits the guard: the unguarded body returns `true`
/// unconditionally on the empty slice, bifurcating the contract
/// loudly at the (empty × any-target) endpoint. Pinned by
/// `is_modal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::is_modal_variant_of(v, &[v]) ==
/// true` for every variant `v` — the sole position hits the target,
/// [`Self::max_variant_count`] collapses to `1`, and only the target
/// satisfies `count == max` (every non-target has count `0`, failing
/// the predicate). Pinned by
/// `is_modal_variant_of_returns_true_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract: `T::is_modal_variant_of(v, &[w]) ==
/// false` for every target `v` and slice-element `w` with
/// `T::index_of(v) != T::index_of(w)` — the sole position hits the
/// slice-element `w`, not the target `v`; [`Self::max_variant_count`]
/// collapses to `1`, but the target's count is `0 != 1 == max`. Pinned
/// by
/// `is_modal_variant_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::is_modal_variant_of(v, <T as ClosedSet>::ALL)
/// == true` for every target `v` UNCONDITIONALLY — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// appears at EXACTLY ONE position of the full-set slice; every per-
/// variant count is `1`, [`Self::max_variant_count`] collapses to `1`,
/// and every target satisfies `count == max`. The flat-histogram
/// fixpoint pins THIS predicate as `true` at every target. Pinned by
/// `is_modal_variant_of_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::is_modal_variant_of(v, &doubled) ==
/// true` for every target `v` UNCONDITIONALLY — the doubled full set
/// hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::max_variant_count`] collapses to `2`, and
/// every target satisfies `count == max`. Together with the full-set
/// arm, the doubled-full-set arm pins THIS predicate as INVARIANT
/// under uniform slice-multiplication on flat-histogram slices.
/// Pinned by
/// `is_modal_variant_of_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_occurrences_of`] + [`Self::max_variant_count`] via
/// a non-emptiness-guarded strict-equality test on `usize`. The sweep
/// cost inherits the modal-count aggregate: `O(T::CARDINALITY * n)`
/// on slice arity `n` (one [`Self::max_variant_count`] fold + one
/// [`Self::count_occurrences_of`] fold at the target), allocation-
/// free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_modal_variant_of`]: a `tatara-check` predicate
/// `(check-target-phase-is-mode …)` that reports whether a specific
/// `WorkloadPhase` is the modal (most-visited) phase in a rollout
/// window in ONE typed bool rather than a count-and-compare
/// composition; an LSP diagnostic on a Lisp-authored closed-set field
/// that flags a specific expected variant as "not currently the peak"
/// without materializing the full argmax witness-collection; a Sekiban
/// audit-trail per-target modal bit across a rollout window
/// classifying each variant as (modal, antimodal, neither); a
/// scheduler-fairness heuristic that branches on "is worker X
/// currently the most-loaded?" as a per-worker bool without a
/// per-emission modal-witness allocation. Each binds to ONE typed
/// per-target bool predicate on the trait rather than re-deriving
/// `T::count_occurrences_of(v, items) == T::max_variant_count(items) && !items.is_empty()`
/// inline per callsite OR paying the Vec allocation
/// `T::modal_variants(items).contains(&v)` would demand.
///
/// Compounding closure: this projection OPENS the (per-target × bool
/// × statistical-aggregate × direction) column of the equivalence-
/// partition surface at its argmax arm past the pre-existing (per-
/// target × bool × multiplicity-band) trichotomy corners (`occurs_in`
/// mult `> 0`, [`Self::is_unique_occurrence_of`] mult `== 1`,
/// [`Self::is_repeated_occurrence_of`] mult `>= 2`) and the (per-
/// target × bool × per-position-universal-quantifier)
/// [`Self::is_saturated_by`] corner one PREDICATE-KIND axis over. The
/// (per-target × bool) row now carries FIVE distinct typed
/// predicates spanning (multiplicity-band × 3, per-position-∀ × 1,
/// statistical-aggregate × argmax × 1) — every downstream consumer
/// picks the atomic per-target bool query matching its output
/// vocabulary. The natural next lift past this OPENING is the
/// `is_antimodal_variant_of(target, items) -> bool` DIRECTION peer
/// one DIRECTION axis over, closing the (per-target × bool ×
/// statistical-aggregate × direction) 2-corner face at its argmin
/// arm past THIS argmax corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target modal-membership predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::count_occurrences_of(v, items) == T::max_variant_count(items) && !items.is_empty()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × argmax) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "is this target the histogram's peak?" site pre-lift.
/// Naming it on the trait makes the predicate a TYPED CONSEQUENCE of
/// the substrate's per-target multiplicity primitive against the
/// modal-count aggregate under a non-emptiness guard. THEORY.md
/// §VI.1 — generation over composition; the predicate emerges from
/// the composition of TWO substrate primitives
/// ([`Self::count_occurrences_of`] + [`Self::max_variant_count`])
/// with an `&&`-guarded strict-equality test on `usize`, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `table(items)[v] == max(table(items))`
/// per-level peak-membership test on a factor histogram; Julia's
/// `StatsBase.countmap(items)[v] == maximum(values(StatsBase.countmap(items)))`;
/// Python's `collections.Counter(items)[v] == max(collections.Counter(items).values())`;
/// Haskell's `length (filter (== v) items) == maximum (map length . group . sort $ items)`;
/// Clojure's `(let [f (frequencies coll)] (= (get f v 0) (apply max (vals f))))`;
/// Coq's `Nat.eqb (List.count_occ eqb l v) (fold_right max 0 (map (fun x => List.count_occ eqb l x) all))`
/// per-target argmax-membership test on a decidable-equality carrier;
/// SQL's `SELECT (COUNT(*) FILTER (WHERE variant = v)) = (SELECT MAX(c) FROM …)`
/// per-key peak-membership check on a `GROUP BY variant` aggregation.
/// Translation through pleme-io primitives: the N-ary per-target
/// modal-membership predicate on the closed-set trait binds through
/// the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::max_variant_count`] scalar under a non-emptiness guard —
/// no new dep, no supertrait bound (the [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` / `frequencies`
/// / `countmap` per-key peak-check signatures demand), no allocation,
/// O(T::CARDINALITY * n) on slice arity `n` inherited verbatim from
/// the modal-count aggregate.
fn is_modal_variant_of(target: Self, items: &[Self]) -> bool {
!items.is_empty()
&& <Self as ClosedSet>::count_occurrences_of(target, items)
== <Self as ClosedSet>::max_variant_count(items)
}
/// The N-ARY ORDERING-AGNOSTIC "target is an antimodal variant" per-
/// target predicate — `true` iff `target`'s per-target multiplicity in
/// `items` coincides with [`Self::min_variant_count`] AND `items` is
/// non-empty, computed as the conjunction of the non-emptiness guard
/// with the strict-equality test of [`Self::count_occurrences_of`]
/// against [`Self::min_variant_count`]. The BOOL-RETURN CLOSER on the
/// (per-target × bool × statistical-aggregate × direction × argmin)
/// corner CLOSING the (per-target × bool × statistical-aggregate ×
/// direction) 2-corner face at its argmin arm past the argmax corner
/// [`Self::is_modal_variant_of`] one DIRECTION axis over, AND the
/// direct SET-LEVEL-EXISTENTIAL-LIFT INVERSE — the per-target arity
/// peer — of the (set-level × usize × statistical-aggregate ×
/// direction × argmin) cardinality-count corner
/// [`Self::count_antimodal_variants`] one ARITY axis over (set-level ×
/// `usize` → per-target × `bool`). Not a fresh substrate primitive on
/// the index axis — the predicate emerges from one non-emptiness
/// guard conjoined with one strict-equality test of
/// [`Self::count_occurrences_of`] against [`Self::min_variant_count`],
/// equivalently the [`Vec::contains`] membership of the target in the
/// just-lifted [`Self::antimodal_variants`] argmin witness-collection.
///
/// Count-composition identity: for every NON-EMPTY slice `items` and
/// every target `v`,
/// `T::is_antimodal_variant_of(v, items) == (T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// — the per-target bool predicate is EXACTLY the strict-equality
/// test of the per-target multiplicity primitive against the antimodal
/// multiplicity scalar. The canonical form the body uses. Pinned by
/// `is_antimodal_variant_of_holds_iff_count_equals_min_variant_count_on_non_empty_across_every_target_and_triple`.
///
/// Antimodal-witness membership identity: for every slice `items` and
/// every target `v`,
/// `T::is_antimodal_variant_of(v, items) == T::antimodal_variants(items).contains(&v)`
/// — the per-target bool predicate is EXACTLY the membership test of
/// the target in the declaration-order-preserving argmin witness-
/// collection. Independent cross-check distinct from the count-
/// composition arm on the surface axis (Vec-membership vs scalar
/// equality); pinned by
/// `is_antimodal_variant_of_agrees_with_antimodal_variants_membership_across_every_target_and_triple`.
///
/// Cardinality-count identity: for every slice `items`,
/// `T::count_antimodal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_antimodal_variant_of(v, items)).count()`
/// — the set-level antimodal-tie count is the EXACT filter-count
/// reduction over [`Self::ALL`] of THIS per-target predicate. This
/// identity binds the per-target ARITY axis against the set-level
/// ARITY axis one arity axis over on the (arity × statistical-
/// aggregate) face — pinning THIS per-target predicate as the ATOMIC
/// contribution to the set-level cardinality-count aggregate. Pinned
/// by
/// `is_antimodal_variant_of_count_equals_count_antimodal_variants_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`] (both
/// ordering-agnostic) via a strict-equality test. No separate
/// `sorted_is_antimodal_variant_of` peer is needed. Pinned by
/// `is_antimodal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_antimodal_variant_of(v, &[])` is
/// `false` for every target `v` UNCONDITIONALLY — the empty slice
/// hits zero positions, [`Self::min_variant_count`] collapses to `0`,
/// and an UNGUARDED strict-equality test against `0` would silently
/// return `true` for every target past the (min == 0, every-count ==
/// 0) degenerate arm where every target satisfies the vacuous `0 ==
/// 0` predicate — the empty-slice guard maps `&[]` to `false` before
/// the test. Sibling posture to [`Self::count_antimodal_variants`]'s
/// empty-slice guard one ARITY axis over: the set-level cardinality-
/// count collapses to `0` at the empty slice; THIS per-target
/// predicate collapses to `false` at every target on the same
/// endpoint (the disjunction over targets coincides with the set-
/// level `0` fixpoint). The `false`-at-empty fixpoint is LOAD-BEARING
/// as the drift catch for an override that omits the guard: the
/// unguarded body returns `true` unconditionally on the empty slice
/// (every target hits `0 == 0`), bifurcating the contract loudly at
/// the (empty × any-target) endpoint. Pinned by
/// `is_antimodal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract (LOAD-BEARING ASYMMETRY vs argmax):
/// `T::is_antimodal_variant_of(v, &[v]) == false` for every variant
/// `v` at [`Self::CARDINALITY`] `>= 2` — the sole position hits the
/// target with count `1`, but every non-target variant is missing
/// (count `0`), so [`Self::min_variant_count`] collapses to `0` and
/// the target's count `1 != 0 == min` fails the predicate. This is
/// the DIRECT MIRROR of the matching-singleton fixpoint on the argmax
/// arm one DIRECTION axis over: on the argmax arm the target IS the
/// modal variant on `[v]` (count `1 == max == 1`); on the argmin arm
/// the target is NOT the antimodal variant on `[v]` (the non-target
/// variants are, at count `0 == min`). Sibling posture to
/// [`Self::count_antimodal_variants`]`([v]) == T::CARDINALITY - 1` one
/// ARITY axis over: the set-level cardinality-count reports the count
/// of NON-TARGET variants; THIS per-target predicate reports `false`
/// at the target and (per the non-matching-singleton arm) `true` at
/// every non-target — the disjunction over targets recovers the set-
/// level cardinality. Pinned by
/// `is_antimodal_variant_of_returns_false_on_the_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Non-matching-singleton contract (LOAD-BEARING ASYMMETRY vs
/// argmax): `T::is_antimodal_variant_of(v, &[w]) == true` for every
/// target `v` and slice-element `w` with `T::index_of(v) !=
/// T::index_of(w)` — the sole position hits `w`, not `v`; the
/// target's count is `0`, [`Self::min_variant_count`] collapses to
/// `0`, and the target satisfies `0 == 0 == min`. DIRECT MIRROR of
/// the non-matching-singleton fixpoint on the argmax arm one
/// DIRECTION axis over: on the argmax arm the non-matching target
/// is NOT the modal variant on `[w]` (count `0 != max == 1`); on the
/// argmin arm the non-matching target IS the antimodal variant on
/// `[w]` (count `0 == min == 0`). Pinned by
/// `is_antimodal_variant_of_returns_true_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract: `T::is_antimodal_variant_of(v, <T as ClosedSet>::ALL)
/// == true` for every target `v` UNCONDITIONALLY — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// appears at EXACTLY ONE position of the full-set slice; every per-
/// variant count is `1`, [`Self::min_variant_count`] collapses to `1`,
/// and every target satisfies `count == min`. The flat-histogram
/// fixpoint pins THIS predicate as `true` at every target — the
/// direction axis on flat-histogram slices COLLAPSES (`min == max`),
/// so the argmin and argmax arms coincide on both flat-histogram
/// fixpoints. Pinned by
/// `is_antimodal_variant_of_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract: `T::is_antimodal_variant_of(v, &doubled)
/// == true` for every target `v` UNCONDITIONALLY — the doubled full
/// set hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::min_variant_count`] collapses to `2`, and
/// every target satisfies `count == min`. Together with the full-set
/// arm, the doubled-full-set arm pins THIS predicate as INVARIANT
/// under uniform slice-multiplication on flat-histogram slices.
/// Pinned by
/// `is_antimodal_variant_of_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`] via a
/// non-emptiness-guarded strict-equality test on `usize`. The sweep
/// cost inherits the antimodal-count aggregate: `O(T::CARDINALITY *
/// n)` on slice arity `n` (one [`Self::min_variant_count`] fold + one
/// [`Self::count_occurrences_of`] fold at the target), allocation-
/// free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_antimodal_variant_of`]: a `tatara-check` predicate
/// `(check-target-phase-is-antimode …)` that reports whether a
/// specific `WorkloadPhase` is the antimodal (least-visited) phase in
/// a rollout window in ONE typed bool rather than a count-and-compare
/// composition; an LSP diagnostic on a Lisp-authored closed-set field
/// that flags a specific expected variant as "currently the trough"
/// without materializing the full argmin witness-collection; a
/// Sekiban audit-trail per-target antimodal bit across a rollout
/// window (composed with the just-lifted argmax bit to classify each
/// variant as (modal, antimodal, neither, both-on-flat-histogram) in
/// ONE typed 2-bool projection); a scheduler-fairness heuristic that
/// branches on "is worker X currently the least-loaded?" as a per-
/// worker bool without a per-emission antimodal-witness allocation.
/// Each binds to ONE typed per-target bool predicate on the trait
/// rather than re-deriving
/// `T::count_occurrences_of(v, items) == T::min_variant_count(items) && !items.is_empty()`
/// inline per callsite OR paying the Vec allocation
/// `T::antimodal_variants(items).contains(&v)` would demand.
///
/// Compounding closure: this projection CLOSES the (per-target × bool
/// × statistical-aggregate × direction) 2-corner face at its argmin
/// arm past the just-opened [`Self::is_modal_variant_of`] argmax
/// corner one DIRECTION axis over, completing the (per-target × bool
/// × statistical-aggregate × direction) column at both corners. The
/// (per-target × bool) row now carries SIX distinct typed predicates
/// spanning (multiplicity-band × 3, per-position-∀ × 1, statistical-
/// aggregate × direction × 2) — every downstream consumer picks the
/// atomic per-target bool query matching its output vocabulary. The
/// natural next OPENING lift past this closure is the SET-LEVEL
/// BOOLEAN unique-antimode predicate `has_unique_antimode(items) ==
/// (count_antimodal_variants(items) == 1)` — the bool-return
/// SHARPENING of the just-lifted set-level argmin cardinality-count
/// against the `1` threshold on the argmin arm, peer to the argmax
/// `has_unique_mode` predicate one DIRECTION axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target antimodal-membership predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline
/// `T::count_occurrences_of(v, items) == T::min_variant_count(items) && !items.is_empty()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × argmin) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "is this target the histogram's trough?" site pre-lift.
/// Naming it on the trait makes the predicate a TYPED CONSEQUENCE of
/// the substrate's per-target multiplicity primitive against the
/// antimodal-count aggregate under a non-emptiness guard. THEORY.md
/// §VI.1 — generation over composition; the predicate emerges from
/// the composition of TWO substrate primitives
/// ([`Self::count_occurrences_of`] + [`Self::min_variant_count`])
/// with an `&&`-guarded strict-equality test on `usize`, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `table(items)[v] == min(table(items))`
/// per-level trough-membership test on a factor histogram; Julia's
/// `StatsBase.countmap(items)[v] == minimum(values(StatsBase.countmap(items)))`;
/// Python's `collections.Counter(items)[v] == min(collections.Counter(items).values())`;
/// Haskell's `length (filter (== v) items) == minimum (map length . group . sort $ items)`;
/// Clojure's `(let [f (frequencies coll)] (= (get f v 0) (apply min (vals f))))`;
/// Coq's `Nat.eqb (List.count_occ eqb l v) (fold_right min 0 (map (fun x => List.count_occ eqb l x) all))`
/// per-target argmin-membership test on a decidable-equality carrier;
/// SQL's `SELECT (COUNT(*) FILTER (WHERE variant = v)) = (SELECT MIN(c) FROM …)`
/// per-key trough-membership check on a `GROUP BY variant`
/// aggregation. Translation through pleme-io primitives: the N-ary
/// per-target antimodal-membership predicate on the closed-set trait
/// binds through the substrate's per-target multiplicity primitive
/// [`Self::count_occurrences_of`] against the just-lifted
/// [`Self::min_variant_count`] scalar under a non-emptiness guard —
/// no new dep, no supertrait bound (the [`Self::index_of`] projection
/// [`Self::count_occurrences_of`] threads through replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` / `frequencies` /
/// `countmap` per-key trough-check signatures demand), no allocation,
/// `O(T::CARDINALITY * n)` on slice arity `n` inherited verbatim from
/// the antimodal-count aggregate. One critical pleme-io-specific
/// asymmetry against the argmax peer: the argmin corner reports
/// `true` at every non-target on the (matching-singleton × non-
/// target) product where the argmax peer reports `false` — the
/// disjunction-over-targets nevertheless recovers non-emptiness on
/// both direction arms via
/// `<T as ClosedSet>::ALL.iter().any(|&v| T::is_antimodal_variant_of(v, items)) == !items.is_empty()`.
fn is_antimodal_variant_of(target: Self, items: &[Self]) -> bool {
!items.is_empty()
&& <Self as ClosedSet>::count_occurrences_of(target, items)
== <Self as ClosedSet>::min_variant_count(items)
}
/// The N-ARY ORDERING-AGNOSTIC "does the mode fall on a UNIQUE
/// variant?" set-level predicate — `true` iff EXACTLY ONE variant of
/// [`Self::ALL`] ties for [`Self::max_variant_count`] in `items`,
/// computed as the strict-equality test of the just-lifted
/// [`Self::count_modal_variants`] cardinality-count aggregate against
/// the scalar threshold `1`. The BOOL-RETURN SHARPENING on the (set-
/// level × bool × statistical-aggregate × direction × argmax × unique-
/// tie) corner OPENING the (set-level × bool × statistical-aggregate
/// × direction × argmax × cardinality-count-threshold) column peer to
/// [`Self::count_modal_variants`] one RETURN-SHAPE axis over (set-
/// level × `usize` cardinality → set-level × `bool` uniqueness test
/// against `1`) AND peer to [`Self::modal_variant`] one RETURN-SHAPE
/// axis over (set-level × `Option<Self>` first-witness → set-level ×
/// `bool` uniqueness of the witness's tie-class). Not a fresh
/// substrate primitive on the index axis — the predicate emerges from
/// one strict-equality test of the just-lifted
/// [`Self::count_modal_variants`] scalar against `1`, equivalently
/// the [`Vec::len`] equality of the declaration-order argmax witness-
/// collection [`Self::modal_variants`] against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_mode(items) == (T::count_modal_variants(items) == 1)`
/// — the set-level bool predicate is EXACTLY the strict-equality test
/// of the just-lifted set-level cardinality-count aggregate against
/// the scalar threshold `1`. The canonical form the body uses. Pinned
/// by `has_unique_mode_equals_count_modal_variants_eq_one_across_every_triple`.
///
/// Modal-witness length identity: for every slice `items`,
/// `T::has_unique_mode(items) == (T::modal_variants(items).len() == 1)`
/// — the set-level bool predicate is EXACTLY the length-equality
/// test of the declaration-order argmax witness-collection against
/// `1`. Independent cross-check distinct from the count-composition
/// arm on the surface axis (Vec-length vs scalar equality). Pinned
/// by `has_unique_mode_agrees_with_modal_variants_len_eq_one_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_modal_variants`] (ordering-agnostic) via a scalar
/// equality test against a fixed constant. No separate
/// `sorted_has_unique_mode` peer is needed. Pinned by
/// `has_unique_mode_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_mode(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_modal_variants`] collapses to `0` at the empty-slice
/// endpoint via its non-emptiness guard, and `0 != 1`. The `false`-
/// at-empty fixpoint pins uniqueness as a NON-EMPTINESS-REQUIRING
/// property: an empty histogram has no mode to be unique. Pinned by
/// `has_unique_mode_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract: `T::has_unique_mode(&[v])` is `true`
/// for every variant `v` — the sole position hits `v` at count `1`,
/// every non-target variant has count `0`, [`Self::max_variant_count`]
/// collapses to `1`, and only `v` satisfies `count == max` so
/// [`Self::count_modal_variants`] reports `1`. Every singleton
/// slice has a UNIQUE mode (its sole element). Pinned by
/// `has_unique_mode_returns_true_on_every_singleton_across_every_variant`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::has_unique_mode(<T as ClosedSet>::ALL)` is `false` — the
/// closed-set well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// appears at EXACTLY ONE position of the full-set slice; every per-
/// variant count is `1`, so every variant ties for the mode, and
/// [`Self::count_modal_variants`] reports [`Self::CARDINALITY`] `>= 2`.
/// The flat-histogram fixpoint pins UNIQUENESS as `false` on any non-
/// trivial closed set — a completely flat histogram has NO unique
/// mode. Pinned by
/// `has_unique_mode_returns_false_on_the_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::has_unique_mode(&doubled)` is `false` — the doubled full set
/// hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::max_variant_count`] collapses to `2`, and
/// every variant satisfies `count == max`, so
/// [`Self::count_modal_variants`] reports [`Self::CARDINALITY`] `>= 2`.
/// The predicate is INVARIANT under uniform slice-multiplication on
/// flat-histogram slices. Pinned by
/// `has_unique_mode_returns_false_on_the_doubled_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_modal_variants`] via one scalar equality test on
/// `usize`. The sweep cost inherits the modal-count aggregate:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one filter-count over
/// [`Self::ALL`]), allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound.
///
/// Future consumers that compose against
/// [`Self::has_unique_mode`]: a `tatara-check` predicate
/// `(check-mode-is-unique …)` that reports "the winning variant is
/// unambiguous" in ONE typed bool rather than a Vec-length or
/// count-and-compare composition; a scheduler-fairness diagnostic
/// that flags "the observed rollout has a UNIQUE dominant phase"
/// without materializing the modal witness-collection; a Sekiban
/// audit-trail bit `mode_uniqueness_bit(items)` binding to the same
/// scalar; an LSP hint that surfaces "the majority variant is
/// unambiguous" on a Lisp-authored histogram field without allocating
/// the witness-Vec.
///
/// Compounding closure: this projection OPENS the (set-level × bool
/// × statistical-aggregate × direction × argmax × unique-tie) corner
/// on the modal-aggregation matrix, sharpening the just-lifted
/// [`Self::count_modal_variants`] cardinality-count scalar past the
/// `1` threshold. The natural next lift past this corner is
/// `has_unique_antimode(items) -> bool` DIRECTION peer one direction
/// axis over — opening the (set-level × bool × statistical-aggregate
/// × direction × argmin × unique-tie) corner as `count_antimodal_variants
/// == 1`. The (set-level × bool × statistical-aggregate × direction ×
/// argmax × unique-tie) row now carries ONE corner; adding the
/// argmin peer will close the (direction × unique-tie) 2-corner face
/// on this row.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level modal-uniqueness bool predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::count_modal_variants(items) == 1` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × bool × modal-uniqueness) corner was an unnamed
/// inline composition recurring at every prospective downstream "is
/// the winner unambiguous?" site pre-lift. Naming it on the trait
/// makes the predicate a TYPED CONSEQUENCE of the substrate's just-
/// lifted modal-tie count aggregate. THEORY.md §VI.1 — generation
/// over composition; the predicate emerges from the composition of
/// ONE substrate primitive ([`Self::count_modal_variants`]) with a
/// scalar equality against `1`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `sum(table(items) == max(table(items))) == 1`
/// — modal-uniqueness on a factor histogram; Julia's
/// `count(v -> v == maximum(values(StatsBase.countmap(items))), values(StatsBase.countmap(items))) == 1`;
/// Python's `sum(1 for v in collections.Counter(items).values() if v == max(collections.Counter(items).values())) == 1`;
/// Haskell's `(== 1) . length . filter (== maximum hist) $ hist`;
/// Clojure's `(= 1 (count (filter #(= % (apply max (vals f))) (vals f))))`
/// on `f = (frequencies coll)`; Coq's `Nat.eqb (length (filter …)) 1`;
/// SQL's `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c
/// FROM t GROUP BY variant) WHERE c = (SELECT MAX(c) FROM …)` — the
/// canonical set-level modal-uniqueness test. Translation through
/// pleme-io primitives: the N-ary set-level modal-uniqueness
/// predicate on the closed-set trait binds through the just-lifted
/// [`Self::count_modal_variants`] scalar against the constant `1` —
/// no new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` on slice arity `n` inherited verbatim
/// from the modal-count aggregate. `T::ALL`'s pairwise-distinctness
/// invariant makes the full-set fixpoint `false` at cardinality
/// `>= 2` a TYPED CONSEQUENCE the Coq / SQL peers state as a
/// separate lemma.
fn has_unique_mode(items: &[Self]) -> bool {
<Self as ClosedSet>::count_modal_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "does the antimode fall on a UNIQUE
/// variant?" set-level predicate — `true` iff EXACTLY ONE variant of
/// [`Self::ALL`] ties for [`Self::min_variant_count`] in `items`,
/// computed as the strict-equality test of the just-lifted
/// [`Self::count_antimodal_variants`] cardinality-count aggregate
/// against the scalar threshold `1`. The BOOL-RETURN SHARPENING on
/// the (set-level × bool × statistical-aggregate × direction × argmin
/// × unique-tie) corner CLOSING the (set-level × bool × statistical-
/// aggregate × direction × unique-tie) 2-corner face at its argmin
/// arm past the just-opened [`Self::has_unique_mode`] argmax corner
/// one DIRECTION axis over on the modal-aggregation matrix, AND peer
/// to [`Self::count_antimodal_variants`] one RETURN-SHAPE axis over
/// (set-level × `usize` cardinality → set-level × `bool` uniqueness
/// test against `1`) AND peer to [`Self::antimodal_variant`] one
/// RETURN-SHAPE axis over (set-level × `Option<Self>` first-witness
/// → set-level × `bool` uniqueness of the witness's tie-class). Not
/// a fresh substrate primitive on the index axis — the predicate
/// emerges from one strict-equality test of the just-lifted
/// [`Self::count_antimodal_variants`] scalar against `1`,
/// equivalently the [`Vec::len`] equality of the declaration-order
/// argmin witness-collection [`Self::antimodal_variants`] against
/// `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_antimode(items) == (T::count_antimodal_variants(items) == 1)`
/// — the set-level bool predicate is EXACTLY the strict-equality test
/// of the just-lifted set-level cardinality-count aggregate against
/// the scalar threshold `1`. The canonical form the body uses. Pinned
/// by `has_unique_antimode_equals_count_antimodal_variants_eq_one_across_every_triple`.
///
/// Antimodal-witness length identity: for every slice `items`,
/// `T::has_unique_antimode(items) == (T::antimodal_variants(items).len() == 1)`
/// — the set-level bool predicate is EXACTLY the length-equality
/// test of the declaration-order argmin witness-collection against
/// `1`. Independent cross-check distinct from the count-composition
/// arm on the surface axis (Vec-length vs scalar equality). Pinned
/// by `has_unique_antimode_agrees_with_antimodal_variants_len_eq_one_across_every_triple`.
///
/// Flat-histogram coincidence identity: for every slice `items` whose
/// per-variant histogram is flat (i.e. every variant of [`Self::ALL`]
/// shares one common multiplicity — the empty, full-set, and doubled-
/// full-set fixpoints; on any implementor of cardinality `1` every
/// slice satisfies this),
/// `T::has_unique_antimode(items) == T::has_unique_mode(items)` — the
/// direction axis on flat-histogram slices COLLAPSES (`min == max`),
/// so the argmin and argmax cardinality-count aggregates coincide,
/// and their strict-equality tests against `1` coincide. LOAD-BEARING
/// asymmetry against the (per-target × bool × direction) 2-corner
/// face where the direction-axis peer [`Self::is_antimodal_variant_of`]
/// CARRIES asymmetry against [`Self::is_modal_variant_of`] on the
/// matching-singleton at cardinality `>= 2` — on THIS set-level bool
/// row the direction axis reduces to a single scalar-equality test,
/// so the matching-singleton at cardinality `>= 3` yields `false` on
/// both direction arms (via `count_modal_variants([v]) == 1` versus
/// `count_antimodal_variants([v]) == CARDINALITY - 1 >= 2`) while the
/// direction axis coincides on the flat-histogram fixpoints.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_antimodal_variants`] (ordering-agnostic) via a
/// scalar equality test against a fixed constant. No separate
/// `sorted_has_unique_antimode` peer is needed. Pinned by
/// `has_unique_antimode_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_antimode(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_antimodal_variants`] collapses to `0` at the empty-
/// slice endpoint via its non-emptiness guard, and `0 != 1`. The
/// `false`-at-empty fixpoint pins uniqueness as a NON-EMPTINESS-
/// REQUIRING property: an empty histogram has no antimode to be
/// unique. Sibling posture to
/// `has_unique_mode_returns_false_on_the_empty_slice_across_every_kind`
/// one DIRECTION axis over: both direction-anchor uniqueness
/// predicates collapse to `false` at the empty-slice endpoint via
/// their respective cardinality-count aggregates' `0`-at-empty
/// fixpoint. Pinned by
/// `has_unique_antimode_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::has_unique_antimode(&[v])` is `false` for every variant `v` —
/// the sole position hits `v` at count `1`, every non-target variant
/// has count `0`, [`Self::min_variant_count`] collapses to `0`, and
/// EVERY non-target variant satisfies `count == min`, so
/// [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`]
/// `- 1 >= 2 != 1`. LOAD-BEARING ASYMMETRY against
/// [`Self::has_unique_mode`] which returns `true` on the same
/// singleton (only the sole target hits `count == max == 1` so
/// `count_modal_variants([v]) == 1`) — the (singleton × direction)
/// endpoint separates the argmax and argmin uniqueness corners
/// distinctly on set-level bool. Pinned by
/// `has_unique_antimode_returns_false_on_the_matching_singleton_at_cardinality_ge_three_across_every_variant`.
///
/// Single-missing contract at [`Self::CARDINALITY`] `>= 2`: for the
/// slice `T::ALL[..T::CARDINALITY - 1]` (omit the last variant),
/// `T::has_unique_antimode(&single_missing)` is `true` — every
/// present variant `v` has count `1`, the omitted last variant has
/// count `0`, [`Self::min_variant_count`] collapses to `0`, and ONLY
/// the omitted variant satisfies `count == min`, so
/// [`Self::count_antimodal_variants`] reports `1`. The single-missing
/// arm is LOAD-BEARING as the `true`-arm catch: every OTHER canonical
/// fixpoint at cardinality `>= 2` (empty, matching-singleton at
/// cardinality `>= 3`, full-set, doubled-full-set) reports `false`,
/// so an override that folds onto `false` unconditionally would pass
/// every other fixpoint arm silently but bifurcate at THIS single-
/// missing arm loudly. Pinned by
/// `has_unique_antimode_returns_true_on_the_single_missing_slice_at_cardinality_ge_two_across_every_kind`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::has_unique_antimode(<T as ClosedSet>::ALL)` is `false` — the
/// closed-set well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every variant
/// appears at EXACTLY ONE position of the full-set slice; every per-
/// variant count is `1`, every variant ties for the antimode, and
/// [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`]
/// `>= 2`. The flat-histogram fixpoint pins UNIQUENESS as `false` on
/// any non-trivial closed set — a completely flat histogram has NO
/// unique antimode. Sibling posture to
/// `has_unique_mode_returns_false_on_the_full_set_at_cardinality_ge_two_across_every_kind`
/// one DIRECTION axis over: on flat-histogram slices `min == max`
/// collapses the direction axis and both uniqueness corners coincide
/// at `false`. Pinned by
/// `has_unique_antimode_returns_false_on_the_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::has_unique_antimode(&doubled)` is `false` — the doubled full
/// set hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::min_variant_count`] collapses to `2`, every
/// variant ties for the antimode, and
/// [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`]
/// `>= 2`. The predicate is INVARIANT under uniform slice-
/// multiplication on flat-histogram slices. Pinned by
/// `has_unique_antimode_returns_false_on_the_doubled_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_antimodal_variants`] via one scalar equality test on
/// `usize`. The sweep cost inherits the antimodal-count aggregate:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::min_variant_count`] fold + one filter-count over
/// [`Self::ALL`]), allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound.
///
/// Future consumers that compose against
/// [`Self::has_unique_antimode`]: a `tatara-check` predicate
/// `(check-antimode-is-unique …)` that reports "the trough variant is
/// unambiguous" in ONE typed bool rather than a Vec-length or count-
/// and-compare composition; a scheduler-fairness diagnostic that
/// flags "the observed rollout has a UNIQUE least-visited phase"
/// without materializing the antimodal witness-collection; a Sekiban
/// audit-trail bit `antimode_uniqueness_bit(items)` binding to the
/// same scalar, composable with the just-lifted mode-uniqueness bit
/// into a typed 2-bit `(mode, antimode) uniqueness` classifier per
/// window; an LSP hint that surfaces "the trough variant is
/// unambiguous" on a Lisp-authored histogram field without allocating
/// the witness-Vec; a coverage-planning heuristic that branches on
/// "does the least-covered arm stand alone?" as a per-window bool
/// without paying the antimodal-witness Vec allocation.
///
/// Compounding closure: this projection CLOSES the (set-level × bool
/// × statistical-aggregate × direction × unique-tie) 2-corner face at
/// its argmin arm past the just-opened [`Self::has_unique_mode`]
/// argmax corner one DIRECTION axis over on the modal-aggregation
/// matrix, completing the (direction × unique-tie) column at both
/// corners. The natural next lift past this closure is the (set-level
/// × bool × statistical-aggregate × trichotomy) composition
/// `has_flat_histogram(items) == (count_modal_variants(items) ==
/// count_antimodal_variants(items))` — the bool-return direction-
/// coincidence predicate one PREDICATE-KIND axis over, opening the
/// "does the histogram treat every variant equally?" corner sitting
/// between the (per-target uniqueness) [`Self::is_uniform`] corner
/// and the (direction-symmetry) modal/antimodal-coincidence corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level antimodal-uniqueness bool predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::count_antimodal_variants(items) == 1` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (set-level × bool × antimodal-uniqueness) corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "is the trough unambiguous?" site pre-lift. Naming it
/// on the trait makes the predicate a TYPED CONSEQUENCE of the
/// substrate's just-lifted antimodal-tie count aggregate. THEORY.md
/// §VI.1 — generation over composition; the predicate emerges from
/// the composition of ONE substrate primitive
/// ([`Self::count_antimodal_variants`]) with a scalar equality
/// against `1`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `sum(table(items) == min(table(items))) == 1`
/// — antimodal-uniqueness on a factor histogram; Julia's
/// `count(v -> v == minimum(values(StatsBase.countmap(items))), values(StatsBase.countmap(items))) == 1`;
/// Python's `sum(1 for v in collections.Counter(items).values() if v == min(collections.Counter(items).values())) == 1`;
/// Haskell's `(== 1) . length . filter (== minimum hist) $ hist`;
/// Clojure's `(= 1 (count (filter #(= % (apply min (vals f))) (vals f))))`
/// on `f = (frequencies coll)`; Coq's `Nat.eqb (length (filter …)) 1`
/// on a decidable-equality-derived histogram; SQL's `SELECT COUNT(*)
/// = 1 FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant)
/// WHERE c = (SELECT MIN(c) FROM …)` — the canonical set-level
/// antimodal-uniqueness test. Translation through pleme-io
/// primitives: the N-ary set-level antimodal-uniqueness predicate on
/// the closed-set trait binds through the just-lifted
/// [`Self::count_antimodal_variants`] scalar against the constant `1`
/// — no new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` on slice arity `n` inherited verbatim
/// from the antimodal-count aggregate. `T::ALL`'s pairwise-
/// distinctness invariant makes the full-set fixpoint `false` at
/// cardinality `>= 2` a TYPED CONSEQUENCE the Coq / SQL peers state
/// as a separate lemma. One critical pleme-io-specific asymmetry
/// against the argmax peer: the argmin uniqueness reports `false` at
/// the matching-singleton at cardinality `>= 3` where the argmax peer
/// reports `true` (`count_antimodal_variants([v]) == CARDINALITY - 1`
/// versus `count_modal_variants([v]) == 1`), so the direction axis
/// SEPARATES at the singleton on set-level bool while COINCIDING on
/// the flat-histogram fixpoints.
fn has_unique_antimode(items: &[Self]) -> bool {
<Self as ClosedSet>::count_antimodal_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "target is THE UNIQUE modal variant" per-
/// target predicate — `true` iff `target` is a modal variant of `items`
/// (its per-target multiplicity coincides with [`Self::max_variant_count`])
/// AND `items` has a unique mode ([`Self::count_modal_variants`] `== 1`),
/// computed as the conjunction of the just-lifted per-target argmax
/// membership predicate [`Self::is_modal_variant_of`] with the just-
/// lifted set-level modal-uniqueness predicate [`Self::has_unique_mode`].
/// The BOOL-RETURN ARITY-LIFT opener on the (per-target × bool ×
/// statistical-aggregate × direction × argmax × unique-tie) corner
/// OPENING the (arity × unique-tie) 2-corner face at its (per-target ×
/// argmax) arm peer to [`Self::has_unique_mode`] (set-level × bool ×
/// argmax × unique-tie) one ARITY axis over AND peer to
/// [`Self::is_modal_variant_of`] (per-target × bool × argmax) one
/// UNIQUE-TIE-SHARPENING axis over. Not a fresh substrate primitive on
/// the index axis — the predicate emerges from the conjunction of the
/// per-target argmax membership predicate with the set-level modal-
/// uniqueness scalar, equivalently the strict-equality test of the
/// just-lifted first-witness [`Self::modal_variant`] projection against
/// `Some(target)`.
///
/// Argmax-conjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_modal_variant_of(v, items) == (T::is_modal_variant_of(v, items) && T::has_unique_mode(items))`
/// — the per-target uniqueness predicate is EXACTLY the conjunction of
/// the per-target argmax membership predicate with the set-level
/// modal-uniqueness scalar. The canonical form the body uses. Pinned
/// by `is_unique_modal_variant_of_equals_modal_membership_and_unique_mode_across_every_target_and_triple`.
///
/// First-witness identity: for every slice `items` and every target `v`,
/// `T::is_unique_modal_variant_of(v, items) == (T::modal_variant(items) == Some(v))`
/// — when `items` has a unique mode, the just-lifted declaration-order-
/// first argmax witness [`Self::modal_variant`] returns EXACTLY the
/// unique modal variant, so equating it byte-for-byte with `Some(v)`
/// coincides with THIS per-target uniqueness predicate at every target.
/// When `items` has no unique mode (empty slice or `count_modal_variants
/// >= 2`), [`Self::modal_variant`] either returns `None` (empty) or
/// returns the declaration-order-first tie-member (multiple ties); the
/// strict-equality test against `Some(v)` returns `false` at every
/// target in both branches, coinciding with THIS per-target predicate's
/// `false`-at-non-unique fixpoint. Independent cross-check distinct
/// from the argmax-conjunction arm on the surface axis (Option-equality
/// vs bool-conjunction). Pinned by
/// `is_unique_modal_variant_of_agrees_with_modal_variant_option_equality_across_every_target_and_triple`.
///
/// Modal-witness singleton identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_modal_variant_of(v, items) == (T::modal_variants(items) == vec![v])`
/// — when `items` has a unique mode, the declaration-order argmax
/// witness-collection [`Self::modal_variants`] collapses to a length-`1`
/// Vec containing EXACTLY that unique variant, so slot-`0`-equality
/// against `v` coincides with THIS per-target uniqueness predicate.
/// When `items` has no unique mode, [`Self::modal_variants`] either
/// returns an empty Vec (empty slice) or a length-`>= 2` Vec (multiple
/// ties); the length-`1` equality against `vec![v]` returns `false` at
/// every target in both branches. Independent cross-check on the
/// witness-Vec surface axis distinct from the scalar-conjunction and
/// Option-equality arms. Pinned by
/// `is_unique_modal_variant_of_agrees_with_modal_variants_singleton_across_every_target_and_triple`.
///
/// At-most-one-target identity: for every slice `items`,
/// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_unique_modal_variant_of(v, items)).count() == usize::from(T::has_unique_mode(items))`
/// — the set-level filter-count reduction over [`Self::ALL`] of THIS
/// per-target predicate reports EXACTLY `0` when `items` has no unique
/// mode (either the empty slice or a multi-way tie) and EXACTLY `1`
/// when `items` has a unique mode (only that one variant satisfies the
/// conjunction). Sibling posture to
/// `is_modal_variant_of_count_equals_count_modal_variants_across_every_triple`
/// one UNIQUE-TIE-SHARPENING axis over: the unsharpened per-target
/// argmax membership predicate contributes to `count_modal_variants` at
/// every tie-member; THIS sharpened per-target predicate contributes to
/// `has_unique_mode as usize` at the sole unique-mode witness. Pinned
/// by `is_unique_modal_variant_of_count_equals_has_unique_mode_as_usize_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_modal_variant_of`] + [`Self::has_unique_mode`] (both
/// ordering-agnostic — the former via [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`], the latter via [`Self::count_modal_variants`])
/// via a boolean conjunction. No separate `sorted_is_unique_modal_variant_of`
/// peer is needed. Pinned by
/// `is_unique_modal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_unique_modal_variant_of(v, &[])` is
/// `false` for every target `v` UNCONDITIONALLY — the empty slice hits
/// zero positions, [`Self::is_modal_variant_of`] collapses to `false`
/// at every target via its empty-slice guard (independent of the
/// [`Self::has_unique_mode`] conjunct's own `false`-at-empty fixpoint),
/// so the conjunction lands on `false` at every target through either
/// arm. Sibling posture to
/// `is_modal_variant_of_returns_false_on_the_empty_slice_across_every_target`
/// one UNIQUE-TIE-SHARPENING axis over: the unsharpened per-target
/// argmax predicate reports `false` at every target on the empty
/// slice; THIS sharpened per-target predicate inherits the fixpoint
/// verbatim. Pinned by
/// `is_unique_modal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract: `T::is_unique_modal_variant_of(v, &[v])
/// == true` for every variant `v` — the sole position hits the target
/// with count `1`, [`Self::is_modal_variant_of`] reports `true` at
/// `count == max == 1`, [`Self::has_unique_mode`] reports `true` at
/// `count_modal_variants == 1`, and the conjunction lands on `true`.
/// Sibling posture to
/// `has_unique_mode_returns_true_on_every_singleton_across_every_variant`
/// one ARITY axis over: the set-level uniqueness bit reports `true` on
/// the matching singleton; THIS per-target predicate reports `true` at
/// EXACTLY the sole matching target (the unique mode) and `false` at
/// every other target (via the [`Self::is_modal_variant_of`] arm of the
/// conjunction — non-matching targets have count `0 != max == 1`).
/// Pinned by
/// `is_unique_modal_variant_of_returns_true_on_the_matching_singleton_across_every_variant`.
///
/// Non-matching-singleton contract: `T::is_unique_modal_variant_of(v, &[w])
/// == false` for every target `v` and slice-element `w` with
/// `T::index_of(v) != T::index_of(w)` — the sole position hits `w`,
/// not `v`; the target's count is `0`, [`Self::max_variant_count`]
/// collapses to `1`, [`Self::is_modal_variant_of`] reports `false` at
/// `count == 0 != max == 1`, and the conjunction lands on `false`
/// through the [`Self::is_modal_variant_of`] arm regardless of the
/// [`Self::has_unique_mode`] arm's own `true` fixpoint on the singleton.
/// Sibling posture to
/// `is_modal_variant_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`
/// one UNIQUE-TIE-SHARPENING axis over: both predicates report `false`
/// at the non-matching target on the singleton. Pinned by
/// `is_unique_modal_variant_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_modal_variant_of(v, <T as ClosedSet>::ALL) == false`
/// for every target `v` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause (3)
/// pins variants as pairwise distinct, so every variant appears at
/// EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::is_modal_variant_of`] reports `true` at every
/// target (via the flat-histogram fixpoint), but [`Self::has_unique_mode`]
/// reports `false` because `count_modal_variants(T::ALL) ==
/// T::CARDINALITY >= 2 != 1`, and the conjunction lands on `false` at
/// every target through the [`Self::has_unique_mode`] arm. LOAD-BEARING
/// ASYMMETRY against [`Self::is_modal_variant_of`] which reports `true`
/// on the same slice at every target — the unique-tie sharpening
/// SEPARATES the per-target argmax membership predicate from THIS per-
/// target uniqueness predicate on the flat-histogram fixpoint at
/// cardinality `>= 2`. Pinned by
/// `is_unique_modal_variant_of_returns_false_on_the_full_set_at_cardinality_ge_two_across_every_target`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_modal_variant_of(v, &doubled) == false` for every
/// target `v` UNCONDITIONALLY — the doubled full set hits every
/// variant at EXACTLY TWO positions, every per-variant count is `2`,
/// [`Self::is_modal_variant_of`] reports `true` at every target, but
/// [`Self::has_unique_mode`] reports `false` because `count_modal_variants
/// == T::CARDINALITY >= 2 != 1`, and the conjunction lands on `false`
/// at every target. Together with the full-set arm, the doubled-full-
/// set arm pins THIS predicate as INVARIANT under uniform slice-
/// multiplication on flat-histogram slices AT `false` at cardinality
/// `>= 2`. Pinned by
/// `is_unique_modal_variant_of_returns_false_on_the_doubled_full_set_at_cardinality_ge_two_across_every_target`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_modal_variant_of`] + [`Self::has_unique_mode`] via a
/// boolean conjunction on `bool`. The sweep cost inherits both
/// primitives: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one [`Self::count_occurrences_of`]
/// fold at the target + one filter-count over [`Self::ALL`] via
/// [`Self::count_modal_variants`]; the short-circuiting `&&` avoids the
/// second aggregate when the first arm falsifies), allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_modal_variant_of`]: a `tatara-check` predicate
/// `(check-target-is-the-unique-mode …)` that reports "the winning
/// variant is unambiguous AND matches the expected witness" in ONE
/// typed bool rather than a two-step Vec-length + membership
/// composition; an LSP diagnostic on a Lisp-authored closed-set field
/// that flags a specific expected variant as "currently the unique
/// majority" without materializing the modal witness-collection; a
/// Sekiban audit-trail per-target unique-mode bit binding the same
/// scalar, composable with the just-lifted per-target antimode bit
/// into a typed 2-bit `(unique-mode-of-target, unique-antimode-of-
/// target)` classifier per window; a scheduler-fairness heuristic
/// that branches on "is worker X the unique busiest?" as a per-worker
/// bool without paying the modal-witness Vec allocation; a majority-
/// election predicate that reports "target won the plurality
/// unambiguously" without a two-round tally. Each binds to ONE typed
/// per-target bool predicate on the trait rather than re-deriving
/// `T::is_modal_variant_of(v, items) && T::has_unique_mode(items)`
/// inline per callsite OR paying the Vec allocation
/// `T::modal_variants(items) == vec![v]` would demand.
///
/// Compounding closure: this projection OPENS the (per-target × bool ×
/// statistical-aggregate × direction × argmax × unique-tie) corner on
/// the modal-aggregation matrix as the direct SHARPENING of the per-
/// target argmax membership predicate by the set-level modal-
/// uniqueness bit. The (arity × unique-tie × direction) 2×2×2 = 8-
/// corner cube now opens its FIFTH corner at (per-target, unique-tie,
/// argmax) past the four (arity × direction) corners
/// ([`Self::is_modal_variant_of`], [`Self::is_antimodal_variant_of`],
/// [`Self::has_unique_mode`], [`Self::has_unique_antimode`]). The
/// natural next lift past this opening is
/// `is_unique_antimodal_variant_of(target, items) -> bool` DIRECTION
/// peer one direction axis over — closing the (per-target × bool ×
/// statistical-aggregate × direction × unique-tie) 2-corner face at
/// its argmin arm as `is_antimodal_variant_of(v, items) &&
/// has_unique_antimode(items)`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target unique-mode predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::is_modal_variant_of(v, items) && T::has_unique_mode(items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × argmax × unique-tie)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "is this target the unique winner?" site
/// pre-lift. Naming it on the trait makes the predicate a TYPED
/// CONSEQUENCE of the just-lifted per-target argmax membership and
/// set-level modal-uniqueness bit under a boolean conjunction.
/// THEORY.md §VI.1 — generation over composition; the predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::is_modal_variant_of`] + [`Self::has_unique_mode`]) with
/// the `&&` combinator on `bool`, not as a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: R's `table(items)[v] == max(table(items)) &&
/// sum(table(items) == max(table(items))) == 1` per-level plurality-
/// winner test on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = maximum(values(c)); c[v] == m &&
/// count(==(m), values(c)) == 1 end` on a `Dict{Element, Int}`
/// histogram; Python's `let c = collections.Counter(items), m =
/// max(c.values()); c[v] == m and list(c.values()).count(m) == 1` on
/// a Counter; Haskell's `let hs = map length . group . sort $ items,
/// m = maximum hs in count v items == m && length (filter (== m) hs)
/// == 1` on `Ord`-instance carriers; Clojure's `(let [f (frequencies
/// coll), m (apply max (vals f))] (and (= (get f v 0) m) (= 1 (count
/// (filter #(= % m) (vals f))))))`; Coq's `andb (Nat.eqb (count v
/// items) max) (Nat.eqb (length (filter (fun c => Nat.eqb c max)
/// hist)) 1)` per-target plurality-winner test on a decidable-
/// equality carrier; SQL's `SELECT v = winner FROM (SELECT variant AS
/// winner, COUNT(*) AS c FROM t GROUP BY variant HAVING COUNT(*) =
/// (SELECT MAX(c) FROM …) AND (SELECT COUNT(DISTINCT tied) FROM …
/// WHERE c = MAX) = 1)` — the canonical single-winner majority-
/// election test. Translation through pleme-io primitives: the N-ary
/// per-target unique-mode predicate on the closed-set trait binds
/// through the just-lifted [`Self::is_modal_variant_of`] argmax
/// membership predicate conjoined with the [`Self::has_unique_mode`]
/// set-level uniqueness bit — no new dep, no supertrait bound (the
/// [`Self::index_of`] projection [`Self::count_occurrences_of`]
/// threads through replaces the `Eq`/`Hash` bound the standard-
/// library `Counter` / `frequencies` / `countmap` per-key single-
/// winner check signatures demand), no allocation, `O(T::CARDINALITY *
/// n)` on slice arity `n` inherited from the underlying aggregates
/// with short-circuiting on the argmax arm. One pleme-io-specific
/// asymmetry: the sharpened predicate SEPARATES the flat-histogram
/// fixpoints (full-set, doubled-full-set at cardinality `>= 2`) from
/// the unsharpened [`Self::is_modal_variant_of`] predicate — at the
/// flat-histogram fixpoints the argmax arm holds at every target but
/// the uniqueness arm falsifies universally, so the conjunction
/// lands on `false` at every target rather than the unsharpened
/// predicate's `true`.
fn is_unique_modal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_modal_variant_of(target, items)
&& <Self as ClosedSet>::has_unique_mode(items)
}
/// The N-ARY ORDERING-AGNOSTIC "target is THE UNIQUE antimodal
/// variant" per-target predicate — `true` iff `target` is an
/// antimodal variant of `items` (its per-target multiplicity coincides
/// with [`Self::min_variant_count`]) AND `items` has a unique
/// antimode ([`Self::count_antimodal_variants`] `== 1`), computed as
/// the conjunction of the just-lifted per-target argmin membership
/// predicate [`Self::is_antimodal_variant_of`] with the just-lifted
/// set-level antimodal-uniqueness predicate
/// [`Self::has_unique_antimode`]. The BOOL-RETURN DIRECTION-CLOSING
/// corner CLOSING the (per-target × bool × statistical-aggregate ×
/// direction × unique-tie) 2-corner face at its argmin arm peer to
/// [`Self::is_unique_modal_variant_of`] one DIRECTION axis over AND
/// peer to [`Self::has_unique_antimode`] (set-level × bool × argmin
/// × unique-tie) one ARITY axis over AND peer to
/// [`Self::is_antimodal_variant_of`] (per-target × bool × argmin)
/// one UNIQUE-TIE-SHARPENING axis over. Not a fresh substrate
/// primitive on the index axis — the predicate emerges from the
/// conjunction of the per-target argmin membership predicate with
/// the set-level antimodal-uniqueness scalar, equivalently the
/// strict-equality test of the just-lifted first-witness
/// [`Self::antimodal_variant`] projection against `Some(target)`.
///
/// Argmin-conjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_antimodal_variant_of(v, items) == (T::is_antimodal_variant_of(v, items) && T::has_unique_antimode(items))`
/// — the per-target antimodal-uniqueness predicate is EXACTLY the
/// conjunction of the per-target argmin membership predicate with
/// the set-level antimodal-uniqueness scalar. The canonical form
/// the body uses. Pinned by
/// `is_unique_antimodal_variant_of_equals_antimodal_membership_and_unique_antimode_across_every_target_and_triple`.
///
/// First-witness identity: for every slice `items` and every target
/// `v`,
/// `T::is_unique_antimodal_variant_of(v, items) == (T::antimodal_variant(items) == Some(v))`
/// — when `items` has a unique antimode, the just-lifted declaration-
/// order-first argmin witness [`Self::antimodal_variant`] returns
/// EXACTLY the unique antimodal variant, so equating it byte-for-byte
/// with `Some(v)` coincides with THIS per-target uniqueness predicate
/// at every target. When `items` has no unique antimode (empty slice
/// or `count_antimodal_variants >= 2`), [`Self::antimodal_variant`]
/// either returns `None` (empty) or returns the declaration-order-
/// first tie-member (multiple ties); the strict-equality test against
/// `Some(v)` returns `false` at every target in both branches,
/// coinciding with THIS per-target predicate's `false`-at-non-unique
/// fixpoint. Independent cross-check distinct from the argmin-
/// conjunction arm on the surface axis (Option-equality vs bool-
/// conjunction). Pinned by
/// `is_unique_antimodal_variant_of_agrees_with_antimodal_variant_option_equality_across_every_target_and_triple`.
///
/// Antimodal-witness singleton identity: for every slice `items` and
/// every target `v`,
/// `T::is_unique_antimodal_variant_of(v, items) == (T::antimodal_variants(items) == vec![v])`
/// — when `items` has a unique antimode, the declaration-order argmin
/// witness-collection [`Self::antimodal_variants`] collapses to a
/// length-`1` Vec containing EXACTLY that unique variant, so slot-`0`-
/// equality against `v` coincides with THIS per-target uniqueness
/// predicate. When `items` has no unique antimode, [`Self::antimodal_variants`]
/// either returns an empty Vec (empty slice) or a length-`>= 2` Vec
/// (multiple ties); the length-`1` equality against `vec![v]` returns
/// `false` at every target in both branches. Independent cross-check
/// on the witness-Vec surface axis distinct from the scalar-
/// conjunction and Option-equality arms. Pinned by
/// `is_unique_antimodal_variant_of_agrees_with_antimodal_variants_singleton_across_every_target_and_triple`.
///
/// At-most-one-target identity: for every slice `items`,
/// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_unique_antimodal_variant_of(v, items)).count() == usize::from(T::has_unique_antimode(items))`
/// — the set-level filter-count reduction over [`Self::ALL`] of THIS
/// per-target predicate reports EXACTLY `0` when `items` has no
/// unique antimode (either the empty slice or a multi-way tie) and
/// EXACTLY `1` when `items` has a unique antimode (only that one
/// variant satisfies the conjunction). Sibling posture to
/// `is_antimodal_variant_of_count_equals_count_antimodal_variants_across_every_triple`
/// one UNIQUE-TIE-SHARPENING axis over: the unsharpened per-target
/// argmin membership predicate contributes to `count_antimodal_variants`
/// at every tie-member; THIS sharpened per-target predicate
/// contributes to `has_unique_antimode as usize` at the sole unique-
/// antimode witness. Pinned by
/// `is_unique_antimodal_variant_of_count_equals_has_unique_antimode_as_usize_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_antimodal_variant_of`] + [`Self::has_unique_antimode`]
/// (both ordering-agnostic — the former via [`Self::count_occurrences_of`] +
/// [`Self::min_variant_count`], the latter via [`Self::count_antimodal_variants`])
/// via a boolean conjunction. No separate `sorted_is_unique_antimodal_variant_of`
/// peer is needed. Pinned by
/// `is_unique_antimodal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_unique_antimodal_variant_of(v, &[])`
/// is `false` for every target `v` UNCONDITIONALLY — the empty slice
/// hits zero positions, [`Self::is_antimodal_variant_of`] collapses
/// to `false` at every target via its empty-slice guard (independent
/// of the [`Self::has_unique_antimode`] conjunct's own `false`-at-
/// empty fixpoint), so the conjunction lands on `false` at every
/// target through either arm. Sibling posture to
/// `is_antimodal_variant_of_returns_false_on_the_empty_slice_across_every_target`
/// one UNIQUE-TIE-SHARPENING axis over: the unsharpened per-target
/// argmin predicate reports `false` at every target on the empty
/// slice; THIS sharpened per-target predicate inherits the fixpoint
/// verbatim. Pinned by
/// `is_unique_antimodal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_antimodal_variant_of(v, &[v]) == false` for every
/// variant `v` — the sole position hits `v` with count `1`, every
/// non-target variant has count `0`, [`Self::min_variant_count`]
/// collapses to `0`, [`Self::is_antimodal_variant_of`] reports
/// `false` at target `v` because `count(v) == 1 != min == 0`, and
/// the conjunction lands on `false` through the membership arm
/// regardless of the [`Self::has_unique_antimode`] arm's value.
/// LOAD-BEARING ASYMMETRY against [`Self::is_unique_modal_variant_of`]
/// which reports `true` on the same slice at target `v` — the
/// direction sharpening SEPARATES the argmax and argmin unique-tie
/// corners on the matching-singleton fixpoint at cardinality `>= 2`.
/// Pinned by
/// `is_unique_antimodal_variant_of_returns_false_on_the_matching_singleton_at_cardinality_ge_two_across_every_variant`.
///
/// Non-matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::is_unique_antimodal_variant_of(v, &[w]) == false` for every
/// target `v` and slice-element `w` with
/// `T::index_of(v) != T::index_of(w)` — the sole position hits `w`,
/// not `v`; the target's count is `0`, [`Self::min_variant_count`]
/// collapses to `0`, [`Self::is_antimodal_variant_of`] reports `true`
/// at every non-slice target on the argmin band, but
/// [`Self::has_unique_antimode`] reports `false` on the singleton at
/// cardinality `>= 3` because `count_antimodal_variants([w]) ==
/// T::CARDINALITY - 1 >= 2 != 1` (every non-slice variant lies on
/// the argmin band), and the conjunction lands on `false` at every
/// non-slice target through the uniqueness arm. LOAD-BEARING
/// ASYMMETRY against [`Self::is_antimodal_variant_of`] which reports
/// `true` on the same slice at every non-slice target — the unique-
/// tie sharpening SEPARATES the per-target argmin membership
/// predicate from THIS per-target uniqueness predicate on the non-
/// matching-singleton fixpoint at cardinality `>= 3`. Pinned by
/// `is_unique_antimodal_variant_of_returns_false_on_the_non_matching_singleton_at_cardinality_ge_three_across_every_target_pair`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_antimodal_variant_of(v, <T as ClosedSet>::ALL) == false`
/// for every target `v` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant appears
/// at EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::is_antimodal_variant_of`] reports `true` at
/// every target (via the flat-histogram fixpoint), but
/// [`Self::has_unique_antimode`] reports `false` because
/// `count_antimodal_variants(T::ALL) == T::CARDINALITY >= 2 != 1`,
/// and the conjunction lands on `false` at every target through the
/// [`Self::has_unique_antimode`] arm. LOAD-BEARING ASYMMETRY against
/// [`Self::is_antimodal_variant_of`] which reports `true` on the same
/// slice at every target — the unique-tie sharpening SEPARATES the
/// per-target argmin membership predicate from THIS per-target
/// uniqueness predicate on the flat-histogram fixpoint at
/// cardinality `>= 2`. Pinned by
/// `is_unique_antimodal_variant_of_returns_false_on_the_full_set_at_cardinality_ge_two_across_every_target`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_antimodal_variant_of(v, &doubled) == false` for every
/// target `v` UNCONDITIONALLY — the doubled full set hits every
/// variant at EXACTLY TWO positions, every per-variant count is `2`,
/// [`Self::is_antimodal_variant_of`] reports `true` at every target,
/// but [`Self::has_unique_antimode`] reports `false` because
/// `count_antimodal_variants == T::CARDINALITY >= 2 != 1`, and the
/// conjunction lands on `false` at every target. Together with the
/// full-set arm, the doubled-full-set arm pins THIS predicate as
/// INVARIANT under uniform slice-multiplication on flat-histogram
/// slices AT `false` at cardinality `>= 2`. Pinned by
/// `is_unique_antimodal_variant_of_returns_false_on_the_doubled_full_set_at_cardinality_ge_two_across_every_target`.
///
/// Single-missing contract at [`Self::CARDINALITY`] `>= 2`: for the
/// omit-last fixture `T::ALL[..T::CARDINALITY - 1]`, every present
/// variant hits count `1`, the omitted last variant hits count `0
/// == min`, [`Self::is_antimodal_variant_of`] reports `true` at
/// EXACTLY the omitted last variant on the argmin band and `false`
/// at every present variant, [`Self::has_unique_antimode`] reports
/// `true` because `count_antimodal_variants == 1`, so the
/// conjunction lands on `true` at EXACTLY the omitted last variant
/// and `false` at every present variant. The single-missing arm is
/// the LOAD-BEARING `true`-arm CATCH on the argmin unique-tie
/// corner — every OTHER canonical fixpoint at cardinality `>= 2`
/// (empty, matching-singleton, non-matching-singleton at cardinality
/// `>= 3`, full-set, doubled-full-set) pins the projection at
/// `false`, so an override that folds onto `false` unconditionally
/// bifurcates HERE loudly. Pinned by
/// `is_unique_antimodal_variant_of_returns_true_at_missing_target_on_the_single_missing_slice_at_cardinality_ge_two`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_antimodal_variant_of`] + [`Self::has_unique_antimode`]
/// via a boolean conjunction on `bool`. The sweep cost inherits both
/// primitives: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::min_variant_count`] fold + one
/// [`Self::count_occurrences_of`] fold at the target + one filter-
/// count over [`Self::ALL`] via [`Self::count_antimodal_variants`];
/// the short-circuiting `&&` avoids the second aggregate when the
/// first arm falsifies), allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_antimodal_variant_of`]: a `tatara-check`
/// predicate `(check-target-is-the-unique-antimode …)` that reports
/// "the least-common variant is unambiguous AND matches the expected
/// witness" in ONE typed bool rather than a two-step Vec-length +
/// membership composition; an LSP diagnostic on a Lisp-authored
/// closed-set field that flags a specific expected variant as
/// "currently the unique minority" without materializing the
/// antimodal witness-collection; a Sekiban audit-trail per-target
/// unique-antimode bit binding the same scalar, composable with the
/// just-lifted per-target unique-mode bit into a typed 2-bit
/// `(unique-mode-of-target, unique-antimode-of-target)` classifier
/// per window; a scheduler-fairness heuristic that branches on "is
/// worker X the unique idlest?" as a per-worker bool without paying
/// the antimodal-witness Vec allocation; a starvation-diagnosis
/// predicate that reports "target is uniquely under-served" without
/// a two-round tally. Each binds to ONE typed per-target bool
/// predicate on the trait rather than re-deriving
/// `T::is_antimodal_variant_of(v, items) && T::has_unique_antimode(items)`
/// inline per callsite OR paying the Vec allocation
/// `T::antimodal_variants(items) == vec![v]` would demand.
///
/// Compounding closure: this projection CLOSES the (per-target ×
/// bool × statistical-aggregate × direction × unique-tie) 2-corner
/// face at its argmin arm past the just-opened
/// [`Self::is_unique_modal_variant_of`] corner. The (arity ×
/// unique-tie × direction) 2×2×2 = 8-corner cube now closes its
/// SIXTH corner at (per-target, unique-tie, argmin) past the four
/// (arity × direction) corners ([`Self::is_modal_variant_of`],
/// [`Self::is_antimodal_variant_of`], [`Self::has_unique_mode`],
/// [`Self::has_unique_antimode`]) AND the just-opened (per-target ×
/// argmax × unique-tie) corner. The natural next lifts past this
/// closure are `is_unique_modal_variant_or_antimodal_variant_of` —
/// the direction-agnostic union predicate collapsing the two
/// unique-tie corners under `||` — and the set-level
/// `is_uniquely_modal_and_antimodal` peer collapsing the same
/// direction axis under `&&` at the set-level arity peer.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target unique-antimode predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::is_antimodal_variant_of(v, items) && T::has_unique_antimode(items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × argmin × unique-tie)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "is this target the unique loser?" site
/// pre-lift. Naming it on the trait makes the predicate a TYPED
/// CONSEQUENCE of the just-lifted per-target argmin membership and
/// set-level antimodal-uniqueness bit under a boolean conjunction.
/// THEORY.md §VI.1 — generation over composition; the predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::is_antimodal_variant_of`] + [`Self::has_unique_antimode`])
/// with the `&&` combinator on `bool`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `table(items)[v] == min(table(items)) &&
/// sum(table(items) == min(table(items))) == 1` per-level unique-
/// loser test on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = minimum(values(c)); c[v] == m &&
/// count(==(m), values(c)) == 1 end` on a `Dict{Element, Int}`
/// histogram; Python's `let c = collections.Counter(items), m =
/// min(c.values()); c[v] == m and list(c.values()).count(m) == 1`
/// on a Counter; Haskell's `let hs = map length . group . sort $
/// items, m = minimum hs in count v items == m && length (filter (==
/// m) hs) == 1` on `Ord`-instance carriers; Clojure's `(let [f
/// (frequencies coll), m (apply min (vals f))] (and (= (get f v 0)
/// m) (= 1 (count (filter #(= % m) (vals f))))))`; Coq's per-target
/// unique-minimum andb; SQL's single-loser majority-election test on
/// a GROUP BY variant HAVING COUNT(*) = MIN AND COUNT DISTINCT tied
/// = 1. Translation through pleme-io primitives: the N-ary per-
/// target unique-antimode predicate on the closed-set trait binds
/// through the just-lifted [`Self::is_antimodal_variant_of`] argmin
/// membership predicate conjoined with the [`Self::has_unique_antimode`]
/// set-level uniqueness bit — no new dep, no supertrait bound, no
/// allocation, `O(T::CARDINALITY * n)` inherited from the underlying
/// aggregates with short-circuiting on the argmin arm. One pleme-
/// io-specific asymmetry: the antimodal direction has a NON-TRIVIAL
/// `true`-fixpoint OUTSIDE the matching-singleton corner — the
/// single-missing (omit-last) fixture at cardinality `>= 2` pins the
/// projection at `true` at the omitted last variant, mirroring the
/// argmax matching-singleton fixpoint's role as the LOAD-BEARING
/// `true`-arm catch for the argmin uniqueness corner (where the
/// matching singleton itself collapses to `false` because the target
/// hits count `1` while the min sits at `0`).
fn is_unique_antimodal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_antimodal_variant_of(target, items)
&& <Self as ClosedSet>::has_unique_antimode(items)
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique modal variant" projection
/// — `Some(v)` iff `items` has a unique mode ([`Self::has_unique_mode`]
/// holds) AND `v` is the sole variant achieving [`Self::max_variant_count`],
/// else `None`. Computed as the just-lifted set-level modal-uniqueness
/// bit [`Self::has_unique_mode`] guarding the just-lifted declaration-
/// order first-witness [`Self::modal_variant`] projection: when the
/// guard holds the argmax witness is unambiguous and lifted verbatim;
/// when the guard falsifies the projection collapses to `None`. The
/// `Option<Self>`-RETURN SHARPENING on the (set-level × `Option<Self>`
/// × statistical-aggregate × direction × argmax × unique-tie) corner
/// OPENING the (set-level × `Option<Self>` × statistical-aggregate ×
/// unique-tie) column past the four (set-level × `Option<Self>` ×
/// statistical-aggregate × direction × ordering) declaration/lex/
/// argmax/argmin unsharpened corners ([`Self::modal_variant`],
/// [`Self::sorted_modal_variant`], [`Self::antimodal_variant`],
/// [`Self::sorted_antimodal_variant`]) one UNIQUE-TIE-SHARPENING axis
/// over on the modal-aggregation matrix, AND peer to
/// [`Self::has_unique_mode`] one RETURN-SHAPE axis over (set-level ×
/// `bool` uniqueness bit → set-level × `Option<Self>` witness-when-
/// unique) AND peer to [`Self::modal_variant`] one UNIQUE-TIE-
/// SHARPENING axis over (declaration-order first-witness → declaration-
/// order first-witness gated by uniqueness). Not a fresh substrate
/// primitive on the index axis — the projection emerges from a
/// boolean conjunction of the just-lifted set-level uniqueness bit
/// with the just-lifted declaration-order first-witness projection
/// under an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_modal_variant(items) == if T::has_unique_mode(items) { T::modal_variant(items) } else { None }`
/// — the projection is EXACTLY the guarded lift of the declaration-
/// order argmax first-witness under the set-level modal-uniqueness
/// bit. The canonical form the body uses. Pinned by
/// `unique_modal_variant_equals_has_unique_mode_gated_modal_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_modal_variant(items).is_some() == T::has_unique_mode(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level modal-uniqueness bit. Independent cross-check distinct
/// from the guarded-first-witness identity on the surface axis
/// (`Option::is_some` vs conditional-Option construction). Pinned by
/// `unique_modal_variant_is_some_iff_has_unique_mode_across_every_triple`.
///
/// Modal-witness singleton identity: for every slice `items`,
/// `T::unique_modal_variant(items) == (if T::modal_variants(items).len() == 1 { Some(T::modal_variants(items)[0]) } else { None })`
/// — when `items` has a unique mode, the declaration-order argmax
/// witness-collection [`Self::modal_variants`] collapses to a length-
/// `1` Vec containing EXACTLY that unique variant, so its slot-`0`
/// wrapped in `Some` coincides with THIS projection. When `items` has
/// no unique mode, [`Self::modal_variants`] either returns an empty
/// Vec (empty slice) or a length-`>= 2` Vec (multiple ties); the
/// length-`1` guard falsifies and the projection collapses to `None`
/// through both branches. Independent cross-check on the witness-Vec
/// surface axis distinct from the scalar-conjunction and Option-
/// return arms. Pinned by
/// `unique_modal_variant_agrees_with_modal_variants_singleton_across_every_triple`.
///
/// Per-target composition identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_modal_variant_of(v, items) == (T::unique_modal_variant(items) == Some(v))`
/// — the per-target unique-mode membership predicate is EXACTLY the
/// strict-equality test of THIS set-level `Option<Self>` projection
/// against `Some(v)`. Sibling posture to the argmin peer
/// `is_unique_antimodal_variant_of` / `antimodal_variant`'s first-
/// witness identity one DIRECTION axis over. Pinned by
/// `unique_modal_variant_option_equality_agrees_with_is_unique_modal_variant_of_across_every_target_and_triple`.
///
/// Slice-reversal invariance on the input axis: the projection
/// factors through [`Self::has_unique_mode`] (ordering-agnostic —
/// the underlying [`Self::count_modal_variants`] is invariant under
/// slice-reversal) and [`Self::modal_variant`] (ordering-agnostic —
/// the underlying [`Self::count_occurrences_of`] +
/// [`Self::max_variant_count`] are both invariant under slice-
/// reversal) via a boolean-guarded `Option`-collapse. Pinned by
/// `unique_modal_variant_is_invariant_under_slice_reversal_across_every_triple`.
/// This orders-input-invariance does NOT collapse the SEARCH-ORDER
/// axis over [`Self::ALL`] vs [`Self::sorted_variants`]: the LEX-
/// ORDER peer [`Self::sorted_unique_modal_variant`] one ORDERING
/// axis over pins the ordering-choice-irrelevance identity
/// separately as a substrate-proven theorem (WHEN the uniqueness
/// bit holds the SOLE argmax witness is unambiguous so both search
/// orders find it).
///
/// Empty-slice contract: `T::unique_modal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_mode`] collapses to `false` via its
/// `count_modal_variants(&[]) == 0 != 1` fixpoint, and the guard-arm
/// short-circuit maps the empty slice to `None` before
/// [`Self::modal_variant`]'s own `None`-at-empty branch is consulted.
/// The `None`-at-empty fixpoint is LOAD-BEARING as the drift catch
/// for an override that omits the guard: on the empty slice the
/// guarded body returns `None`; an unguarded `modal_variant(items)`
/// forward returns `None` too (both agree at the empty-slice
/// endpoint), but on the flat-histogram full-set fixpoint the
/// guarded body returns `None` while the unguarded forward returns
/// `Some(T::first())`, bifurcating the (uniqueness-guarded, first-
/// witness) contract loudly at the full-set arm. Pinned by
/// `unique_modal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract: `T::unique_modal_variant(&[v]) == Some(v)`
/// for every variant `v` — the sole position hits `v` with count `1`,
/// every non-target variant has count `0`,
/// [`Self::max_variant_count`] collapses to `1`,
/// [`Self::count_modal_variants`] reports `1` (only `v` ties for the
/// max), [`Self::has_unique_mode`] returns `true`, and
/// [`Self::modal_variant`] returns `Some(v)`. The matching-singleton
/// arm is the LOAD-BEARING `Some`-arm catch at every cardinality: on
/// the empty and both flat-histogram fixpoints the projection lands
/// on `None`, so an override that folds onto `None` unconditionally
/// silently passes every OTHER fixpoint arm but bifurcates HERE at
/// `None != Some(v)`. Pinned by
/// `unique_modal_variant_returns_some_target_on_the_matching_singleton_across_every_variant`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::unique_modal_variant(<T as ClosedSet>::ALL) == None`
/// UNCONDITIONALLY — the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants as
/// pairwise distinct, so every variant of [`Self::ALL`] appears at
/// EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::count_modal_variants`] reports
/// [`Self::CARDINALITY`] `>= 2`, [`Self::has_unique_mode`] returns
/// `false`, and the guard falsifies. LOAD-BEARING ASYMMETRY against
/// [`Self::modal_variant`] which returns `Some(T::first())` on the
/// same slice — the unique-tie sharpening SEPARATES the unsharpened
/// argmax first-witness (returns the declaration-order-first tie-
/// member) from THIS uniqueness-gated projection (collapses to
/// `None` on multi-way ties) on the flat-histogram fixpoint at
/// cardinality `>= 2`. Pinned by
/// `unique_modal_variant_returns_none_on_the_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::unique_modal_variant(&doubled) == None` — the doubled full
/// set hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::count_modal_variants`] reports
/// [`Self::CARDINALITY`] `>= 2`, [`Self::has_unique_mode`] returns
/// `false`, and the guard falsifies. Together with the full-set arm,
/// the doubled-full-set arm pins THIS projection as INVARIANT under
/// uniform slice-multiplication on flat-histogram slices AT `None` at
/// cardinality `>= 2`. Pinned by
/// `unique_modal_variant_returns_none_on_the_doubled_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_mode`] + [`Self::modal_variant`] via a boolean-
/// guarded `Option`-collapse on `Option<Self>`. The sweep cost
/// inherits both underlying projections: `O(T::CARDINALITY * n)` on
/// slice arity `n` (one [`Self::max_variant_count`] fold, one
/// [`Self::count_modal_variants`] filter-count sweep, and one
/// [`Self::modal_variant`] find sweep when the guard holds; the
/// short-circuiting `if` avoids the second sweep when the guard
/// falsifies), allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait
/// pair stays untouched).
///
/// Future consumers that compose against [`Self::unique_modal_variant`]:
/// a `tatara-check` predicate `(check-mode-if-unique …)` that reports
/// "the peak variant, if unambiguous" as a typed `Option`-return
/// rather than a two-step (has-unique-mode? then modal-variant)
/// composition; a Sekiban audit-trail per-window witness-if-unique
/// binding to the same scalar, composable with the just-lifted set-
/// level uniqueness bit into a typed `(unique-mode-bit, unique-mode-
/// witness)` classifier per window; a scheduler-fairness diagnostic
/// that reports "the busiest worker, only if uniquely busiest"
/// without paying the modal-witness Vec allocation; an LSP hint that
/// surfaces the histogram peak on a Lisp-authored field only when
/// the peak is unambiguous, staying silent on tied peaks; a metric
/// emitter that binds a Prometheus-style `unique_mode_variant` label
/// with the empty-string absent semantic on tied windows, distinct
/// from the sibling `mode_variant_decl` label which always reports
/// the declaration-order-first tie-member. Each binds to ONE typed
/// `Option<Self>`-return uniqueness-gated argmax aggregate on the
/// trait rather than re-deriving `if T::has_unique_mode(items) {
/// T::modal_variant(items) } else { None }` inline per callsite OR
/// paying the Vec allocation `T::modal_variants(items).into_iter().next()
/// .filter(|_| T::modal_variants(items).len() == 1)` would demand.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction × argmax ×
/// unique-tie) corner as the FIRST corner of the (`Option<Self>` ×
/// unique-tie) 2×2 face the natural next lifts will fill — the
/// argmin peer `unique_antimodal_variant(items) == if
/// has_unique_antimode(items) { antimodal_variant(items) } else {
/// None }` closes the direction axis one DIRECTION axis over; the
/// lex-order peers `sorted_unique_modal_variant` /
/// `sorted_unique_antimodal_variant` close the ordering axis one
/// ORDERING axis over. Each remaining corner emerges as a boolean-
/// guarded lift of the existing (`Option<Self>` × statistical-
/// aggregate × direction × ordering) unsharpened peer under the
/// existing (bool × direction) uniqueness bit, so the (`Option<Self>`
/// × unique-tie × direction × ordering) 2×2×2 = 8-corner cube fills
/// with no fresh substrate primitives on the index axis.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-mode `Option<Self>` witness projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline `if T::has_unique_mode(items) { T::modal_variant(items)
/// } else { None }` composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (set-level × `Option<Self>`
/// × unique-mode) witness-if-unique corner was an unnamed inline
/// composition recurring at every prospective downstream "which
/// variant is the histogram's peak, if it's unambiguous?" site pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the just-lifted set-level uniqueness bit and the
/// declaration-order argmax first-witness under a boolean-guarded
/// `Option`-collapse. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_mode`] + [`Self::modal_variant`])
/// with the `if _ { _ } else { None }` combinator on `Option<Self>`,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- which(t ==
/// max(t)); if (length(m) == 1) names(t)[m] else NA }` — the
/// canonical guarded-argmax on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = maximum(values(c)), ties =
/// filter(kv -> kv[2] == m, collect(c)); length(ties) == 1 ?
/// Some(ties[1][1]) : Nothing end` on a `Dict{Element, Int}` histogram;
/// Python's `let c = collections.Counter(items); tied = [k for k, v in
/// c.items() if v == max(c.values(), default=0)]; tied[0] if
/// len(tied) == 1 else None`; Haskell's `let hs = map (\g -> (head
/// g, length g)) . group . sort $ items; m = maximum (map snd hs); ts
/// = filter ((== m) . snd) hs in case ts of [(v, _)] -> Just v; _ ->
/// Nothing` on `Ord`-instance carriers; Clojure's `(let [f (frequencies
/// coll), m (apply max (vals f)), ts (filter #(= (val %) m) f)] (when
/// (= 1 (count ts)) (key (first ts))))`; Coq's `option`-return guarded-
/// argmax; SQL's `SELECT variant FROM (SELECT variant, COUNT(*) AS c
/// FROM t GROUP BY variant HAVING c = (SELECT MAX(c) …)) WHERE (SELECT
/// COUNT(*) FROM …) = 1` — the canonical set-level uniqueness-guarded
/// argmax witness. Translation through pleme-io primitives: the N-ary
/// set-level uniqueness-gated argmax witness projection on the
/// closed-set trait binds through the just-lifted
/// [`Self::has_unique_mode`] guard conjoined with the just-lifted
/// [`Self::modal_variant`] first-witness under an `Option`-collapse
/// — no new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_modal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_mode(items) {
<Self as ClosedSet>::modal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique modal variant, lex-first"
/// projection — `Some(v)` iff `items` has a unique mode
/// ([`Self::has_unique_mode`] holds) AND `v` is the sole variant of
/// [`Self::sorted_variants`] achieving [`Self::max_variant_count`],
/// else `None`. Computed as the just-lifted set-level modal-
/// uniqueness bit [`Self::has_unique_mode`] guarding a LEX-ORDER
/// first-witness sweep of [`Self::sorted_variants`] keyed on
/// `count == max` — equivalently, the just-lifted
/// [`Self::sorted_modal_variant`] projection under the same guard.
/// The LEX-ORDER `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner
/// OPENING the (set-level × `Option<Self>` × sorted × statistical-
/// aggregate × direction × argmax × unique-tie) row on the MODAL-
/// AGGREGATION surface — the lex-ordering peer of the just-lifted
/// declaration-order [`Self::unique_modal_variant`] one ORDERING
/// axis over, peer to [`Self::sorted_modal_variants`] one UNIQUE-
/// TIE-SHARPENING axis over (existential `>= 1` Vec of modal
/// witnesses → uniqueness `== 1` `Option<Self>` collapse), AND peer
/// to [`Self::sorted_unique_missing_variant`] +
/// [`Self::sorted_unique_repeating_variant`] +
/// [`Self::sorted_unique_unique_variant`] one SURFACE axis over on
/// the equivalence-partition matrix. Not a fresh substrate
/// primitive on the index axis — the projection emerges from a
/// boolean conjunction of the set-level modal-uniqueness bit with a
/// lex-order first-witness [`Iterator::find`] sweep of
/// [`Self::sorted_variants`] under an `Option`-collapse when the
/// guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_modal_variant(items) ==
/// T::unique_modal_variant(items)` — when the sole argmax witness is
/// UNIQUE ([`Self::has_unique_mode`] holds) declaration-order and
/// lex-order both walk the same `count == max` predicate over the
/// same `T::CARDINALITY`-sized variant carrier and land on THE SAME
/// SOLE argmax variant; when the guard falsifies both projections
/// collapse to `None` through the same guard arm. The LEX peer is
/// thus IDENTICALLY equal to its declaration-order sibling on every
/// input — the search-order axis becomes provably irrelevant WHEN
/// the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_modal_variant_equals_unique_modal_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_modal_variant(items) ==
/// if T::has_unique_mode(items) { T::sorted_modal_variant(items) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_modal_variant(items).is_some() ==
/// T::has_unique_mode(items)` — the `Option<Self>` return's
/// `is_some` bit COINCIDES with the set-level modal-uniqueness bit.
/// Independent cross-check on the surface axis (`Option::is_some`
/// vs conditional-Option construction) distinct from the option-
/// equality arm against [`Self::unique_modal_variant`].
///
/// Sorted-modal witness singleton identity: for every slice `items`,
/// `T::sorted_unique_modal_variant(items) == (if T::sorted_modal_variants(items).len() == 1 { Some(T::sorted_modal_variants(items)[0]) } else { None })`
/// — when `items` has a unique mode, the lex-order argmax witness-
/// collection [`Self::sorted_modal_variants`] collapses to a length-
/// `1` Vec containing EXACTLY that unique variant, so its slot-`0`
/// wrapped in `Some` coincides with THIS projection. Independent
/// cross-check on the witness-Vec surface axis distinct from the
/// scalar arms.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_mode`] (ordering-agnostic on the input axis
/// — the underlying [`Self::count_modal_variants`] is invariant
/// under slice-reversal) and [`Self::sorted_modal_variant`]
/// (ordering-agnostic on the input axis — the underlying
/// [`Self::count_occurrences_of`] + [`Self::max_variant_count`] are
/// both invariant under slice-reversal) under a boolean-guarded
/// `Option`-collapse.
///
/// Empty-slice contract: `T::sorted_unique_modal_variant(&[]) ==
/// None` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_modal_variants`] reports `0` at the empty-slice
/// short-circuit, [`Self::has_unique_mode`] returns `false`, and
/// the guard collapses the projection to `None` before
/// [`Self::sorted_modal_variant`]'s own `None`-at-empty branch is
/// consulted.
///
/// Matching-singleton contract: `T::sorted_unique_modal_variant(&[v])
/// == Some(v)` for every variant `v` — the sole position hits `v`
/// at count `1`, every non-target sits at count `0`,
/// [`Self::max_variant_count`] collapses to `1`,
/// [`Self::count_modal_variants`] reports `1` (only `v` ties for
/// the max), [`Self::has_unique_mode`] returns `true`, and the lex-
/// order sweep of [`Self::sorted_variants`] hits `v` at its sole
/// count-`1` entry — the SAME variant the declaration-order sweep
/// at [`Self::unique_modal_variant`] lands on.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::sorted_unique_modal_variant(T::ALL) == None` UNCONDITIONALLY
/// — clause (3)'s pairwise-distinctness invariant pins every
/// variant at exactly one position, every per-target multiplicity
/// is `1`, [`Self::count_modal_variants`] reports
/// [`Self::CARDINALITY`] `>= 2`, [`Self::has_unique_mode`] returns
/// `false`, and the guard collapses to `None`. LOAD-BEARING
/// ASYMMETRY against [`Self::sorted_modal_variant`] which returns
/// `Some(T::sorted_first())` on the same slice — the unique-tie
/// sharpening SEPARATES the unsharpened lex-order argmax first-
/// witness (returns the lex-order-first tie-member) from THIS
/// uniqueness-gated projection (collapses to `None` on multi-way
/// ties) on the flat-histogram fixpoint at cardinality `>= 2`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::sorted_unique_modal_variant(T::ALL ++ T::ALL) == None`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// exactly two positions, every count is `2`,
/// [`Self::count_modal_variants`] reports [`Self::CARDINALITY`],
/// [`Self::has_unique_mode`] returns `false`, and the guard
/// collapses to `None`.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`
/// (LOAD-BEARING POSITIVE ARM):
/// `T::sorted_unique_modal_variant([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == Some(T::ALL[0])`. On the non-flat triple `T::ALL[0]` sits at
/// count `2` (the SOLE argmax witness), `T::ALL[1]` at count `1`,
/// `T::ALL[2..]` at count `0`; [`Self::count_modal_variants`]
/// reports `1`, [`Self::has_unique_mode`] returns `true`, the guard
/// fires, and the lex-order sweep of [`Self::sorted_variants`] hits
/// the SAME sole argmax variant `T::ALL[0]` that the declaration-
/// order sweep at [`Self::unique_modal_variant`] lands on. BY
/// UNIQUENESS of the argmax witness the sole witness is the ONLY
/// variant either sweep can find. LOAD-BEARING DISJOINT-WITNESS
/// mirror of the sibling equivalence-partition (mult `== 1`) arm
/// [`Self::sorted_unique_unique_variant`] at the SAME bimodal-
/// triple fixture: the equivalence-partition unique-band arm lands
/// on `Some(T::ALL[1])`; THIS modal-aggregation argmax arm lands on
/// `Some(T::ALL[0])` — the two POSITIVE `Some(_)` arms of the LEX-
/// ORDER uniqueness column on the two orthogonal surfaces (modal-
/// aggregation × direction, equivalence-partition × mult-band)
/// report DIFFERENT witnesses on the same slice, pinning the two
/// surfaces as ORTHOGONAL uniqueness axes with disjoint witness
/// projections riding DIFFERENT variants of the CANONICAL bimodal
/// triple.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_mode`] + [`Self::sorted_modal_variant`] via a
/// boolean-guarded `Option`-collapse on `Option<Self>`. Cost
/// inherits both underlying projections: `O(T::CARDINALITY * n)` on
/// slice arity `n` (one [`Self::max_variant_count`] fold, one
/// [`Self::count_modal_variants`] filter-count sweep, and one lex-
/// order [`Iterator::find`] sweep when the guard holds; the short-
/// circuiting `if` avoids the second sweep when the guard
/// falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, allocation-free at the return,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_modal_variant`]: a `tatara-check` predicate
/// `(check-mode-if-unique-lex-first …)` that reports "the peak
/// variant, in lex order, if unambiguous" for a caller that prefers
/// lex-order presentation regardless of declaration-order (which
/// may be arbitrary or convenience-ordered); an LSP hint that
/// surfaces the histogram peak on a Lisp-authored field only when
/// the peak is unambiguous, sorted so the highlight stays
/// deterministic under enum refactoring that permutes declaration
/// order; a Sekiban audit-trail per-window witness-if-unique
/// binding that pins the lex-order peak-witness for stability
/// against upstream declaration-order churn. Each binds to ONE
/// typed lex-order `Option<Self>`-return uniqueness-gated argmax
/// aggregate on the trait — AND, by the ordering-choice-irrelevance
/// identity, TYPED PROOF that the search-order choice is
/// operationally free WHEN the underlying uniqueness bit holds.
///
/// Compounding closure: this projection OPENS the LEX-ORDER arm of
/// the (set-level × `Option<Self>` × sorted × statistical-aggregate
/// × direction × argmax × unique-tie) row on the MODAL-AGGREGATION
/// surface at its (argmax) direction anchor — the lex peer of the
/// just-lifted declaration-order [`Self::unique_modal_variant`] one
/// ORDERING axis over, mirroring the closure of the LEX-ORDER
/// equivalence-partition trichotomy
/// ([`Self::sorted_unique_missing_variant`] +
/// [`Self::sorted_unique_repeating_variant`] +
/// [`Self::sorted_unique_unique_variant`]) on the peer surface. The
/// natural next lift past this corner is the argmin peer
/// `sorted_unique_antimodal_variant` closing the direction axis one
/// DIRECTION axis over, then the direction-composition LEX peers
/// (`sorted_unique_extremal_variant`, `sorted_unique_middle_band_variant`,
/// `sorted_unique_bimodal_variant`) one COMBINATOR axis over,
/// filling the (`Option<Self>` × unique-tie × direction × ordering)
/// 2×2×2 = 8-corner cube and its (`Option<Self>` × unique-tie ×
/// direction-composition × ordering) 3×2 direction-composition-lex
/// grid with no fresh substrate primitives on the index axis.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × statistical-aggregate ×
/// direction × argmax × unique-tie) corner becomes a TYPED WITNESS
/// on the ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_mode(items) { T::sorted_modal_variant(items) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-irrelevance)
/// the substrate proves once rather than every downstream site re-
/// proving via `sorted_unique_modal_variant(items) == unique_modal_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Option<Self>` × direction × argmax × unique-tie)
/// corner was an unnamed inline composition — OR silently absent
/// because the caller shrugged and used the declaration-order
/// sibling without proof of coincidence — recurring at every
/// prospective downstream "which variant is the histogram's peak,
/// in lex order, if unambiguous?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the projection emerges from the
/// composition of the two substrate primitives
/// [`Self::has_unique_mode`] + [`Self::sorted_modal_variant`] with
/// the `if _ { _ } else { None }` combinator on `Option<Self>`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); s <- sort(names(t)[t == max(t)]); if (length(s) == 1) s[1] else NA }`
/// — the guarded lex-order argmax on a factor histogram; Julia's
/// `let c = StatsBase.countmap(items), m = maximum(values(c)), ties = filter(kv -> kv[2] == m, sort(collect(c), by = kv -> kv[1])); length(ties) == 1 ? Some(ties[1][1]) : Nothing end`;
/// Python's `sorted(k for k, v in collections.Counter(items).items() if v == max(collections.Counter(items).values(), default=0))[:1]`
/// filtered by outer count-guard; Haskell's `filter (\v -> Map.findWithDefault 0 v hs == m) (sort allLevels)`
/// guarded to singleton; Clojure's `(let [f (frequencies coll), m (apply max (vals f)), ts (filter #(= (val %) m) (sort ALL-LEVELS))] (when (= 1 (count ts)) (first ts)))`;
/// SQL's `SELECT variant FROM t GROUP BY variant HAVING COUNT(*) = (SELECT MAX(c) …) ORDER BY variant LIMIT 1`
/// filtered by an outer count-guard. Translation through pleme-io
/// primitives: the projection binds through the set-level modal-
/// uniqueness bit [`Self::has_unique_mode`] conjoined with the
/// just-lifted lex-order argmax first-witness
/// [`Self::sorted_modal_variant`] under an `Option`-collapse — no
/// new dep, no supertrait bound (`Sized + Copy + 'static` stays
/// untouched), no allocation at the return, cost inherited from
/// the underlying aggregates with short-circuiting on the guard.
fn sorted_unique_modal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_mode(items) {
<Self as ClosedSet>::sorted_modal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique antimodal variant" projection
/// — `Some(v)` iff `items` has a unique antimode
/// ([`Self::has_unique_antimode`] holds) AND `v` is the sole variant
/// achieving [`Self::min_variant_count`], else `None`. Computed as the
/// just-lifted set-level antimodal-uniqueness bit
/// [`Self::has_unique_antimode`] guarding the declaration-order first-
/// witness [`Self::antimodal_variant`] projection: when the guard holds
/// the argmin witness is unambiguous and lifted verbatim; when the guard
/// falsifies the projection collapses to `None`. The `Option<Self>`-
/// RETURN SHARPENING on the (set-level × `Option<Self>` × statistical-
/// aggregate × direction × argmin × unique-tie) corner CLOSING the
/// (set-level × `Option<Self>` × statistical-aggregate × direction ×
/// unique-tie) 2-corner face at its argmin arm past the just-opened
/// [`Self::unique_modal_variant`] argmax corner one DIRECTION axis over
/// on the modal-aggregation matrix, AND peer to
/// [`Self::has_unique_antimode`] one RETURN-SHAPE axis over (set-level ×
/// `bool` uniqueness bit → set-level × `Option<Self>` witness-when-
/// unique) AND peer to [`Self::antimodal_variant`] one UNIQUE-TIE-
/// SHARPENING axis over (declaration-order first-witness → declaration-
/// order first-witness gated by uniqueness). Not a fresh substrate
/// primitive on the index axis — the projection emerges from a boolean
/// conjunction of the just-lifted set-level antimodal-uniqueness bit
/// with the just-lifted declaration-order first-argmin witness
/// projection under an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_antimodal_variant(items) == if T::has_unique_antimode(items) { T::antimodal_variant(items) } else { None }`
/// — the projection is EXACTLY the guarded lift of the declaration-
/// order argmin first-witness under the set-level antimodal-uniqueness
/// bit. The canonical form the body uses. Pinned by
/// `unique_antimodal_variant_equals_has_unique_antimode_gated_antimodal_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_antimodal_variant(items).is_some() == T::has_unique_antimode(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level antimodal-uniqueness bit. Independent cross-check distinct
/// from the guarded-first-witness identity on the surface axis
/// (`Option::is_some` vs conditional-Option construction). Pinned by
/// `unique_antimodal_variant_is_some_iff_has_unique_antimode_across_every_triple`.
///
/// Antimodal-witness singleton identity: for every slice `items`,
/// `T::unique_antimodal_variant(items) == (if T::antimodal_variants(items).len() == 1 { Some(T::antimodal_variants(items)[0]) } else { None })`
/// — when `items` has a unique antimode, the declaration-order argmin
/// witness-collection [`Self::antimodal_variants`] collapses to a
/// length-`1` Vec containing EXACTLY that unique variant, so its slot-
/// `0` wrapped in `Some` coincides with THIS projection. When `items`
/// has no unique antimode, [`Self::antimodal_variants`] either returns
/// an empty Vec (empty slice) or a length-`>= 2` Vec (multiple ties);
/// the length-`1` guard falsifies and the projection collapses to
/// `None` through both branches. Independent cross-check on the
/// witness-Vec surface axis distinct from the scalar-conjunction and
/// Option-return arms. Pinned by
/// `unique_antimodal_variant_agrees_with_antimodal_variants_singleton_across_every_triple`.
///
/// Per-target composition identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_antimodal_variant_of(v, items) == (T::unique_antimodal_variant(items) == Some(v))`
/// — the per-target unique-antimode membership predicate is EXACTLY the
/// strict-equality test of THIS set-level `Option<Self>` projection
/// against `Some(v)`. Sibling posture to the argmax peer
/// [`Self::is_unique_modal_variant_of`] / [`Self::unique_modal_variant`]'s
/// first-witness identity one DIRECTION axis over. Pinned by
/// `unique_antimodal_variant_option_equality_agrees_with_is_unique_antimodal_variant_of_across_every_target_and_triple`.
///
/// Flat-histogram coincidence identity: for every slice `items` whose
/// per-variant histogram is flat (i.e. every variant of [`Self::ALL`]
/// shares one common multiplicity — the empty, full-set, and doubled-
/// full-set fixpoints; on any implementor of cardinality `1` every
/// slice satisfies this),
/// `T::unique_antimodal_variant(items) == T::unique_modal_variant(items)`
/// — the direction axis on flat-histogram slices COLLAPSES (`min ==
/// max`), so the argmin and argmax first-witnesses coincide AND the
/// uniqueness guards coincide at their common (`count_modal_variants
/// == count_antimodal_variants == T::CARDINALITY`) value, and the
/// guarded `Option<Self>` projections coincide byte-for-byte. Sibling
/// posture to `has_unique_antimode_coincides_with_has_unique_mode_on_flat_histogram_slices`
/// one RETURN-SHAPE axis over: the set-level bool row's flat-histogram
/// coincidence lifts verbatim to the `Option<Self>`-witness row through
/// the shared guarded-lift combinator. Pinned by
/// `unique_antimodal_variant_coincides_with_unique_modal_variant_on_flat_histogram_slices`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_antimode`] (ordering-agnostic — the underlying
/// [`Self::count_antimodal_variants`] is invariant under slice-reversal)
/// and [`Self::antimodal_variant`] (ordering-agnostic — the underlying
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`] are both
/// invariant under slice-reversal) via a boolean-guarded `Option`-
/// collapse. Pinned by
/// `unique_antimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
/// The lex-order peer [`Self::sorted_unique_antimodal_variant`]
/// substrate-proves this ordering-agnosticism as a TYPED THEOREM
/// (ordering-choice-irrelevance) rather than a per-consumer inline
/// re-derivation — the two projections are IDENTICALLY equal on every
/// input because declaration-order and lex-order sweeps land on THE
/// SAME sole argmin variant WHEN the underlying antimodal-uniqueness
/// bit holds and BOTH collapse to `None` through the same guard arm
/// when the bit falsifies.
///
/// Empty-slice contract: `T::unique_antimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_antimode`] collapses to `false` via its
/// `count_antimodal_variants(&[]) == 0 != 1` fixpoint, and the guard-
/// arm short-circuit maps the empty slice to `None` before
/// [`Self::antimodal_variant`]'s own `None`-at-empty branch is consulted.
/// The `None`-at-empty fixpoint is LOAD-BEARING as the drift catch for
/// an override that omits the guard: on the empty slice the guarded
/// body returns `None`; an unguarded `antimodal_variant(items)` forward
/// returns `None` too (both agree at the empty-slice endpoint), but on
/// the flat-histogram full-set fixpoint at cardinality `>= 2` the
/// guarded body returns `None` while the unguarded forward returns
/// `Some(T::first())`, bifurcating the (uniqueness-guarded, first-
/// witness) contract loudly at the full-set arm. Pinned by
/// `unique_antimodal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::unique_antimodal_variant(&[v]) == None` for every variant `v` —
/// the sole position hits `v` at count `1`, every non-target variant
/// has count `0`, [`Self::min_variant_count`] collapses to `0`, EVERY
/// non-target variant satisfies `count == min`, so
/// [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`]
/// `- 1 >= 2 != 1`, [`Self::has_unique_antimode`] returns `false`, and
/// the guard collapses the projection to `None`. LOAD-BEARING
/// ASYMMETRY against [`Self::unique_modal_variant`] which returns
/// `Some(v)` on the same slice — the direction axis SEPARATES the
/// argmax and argmin uniqueness-witness corners distinctly on set-
/// level `Option<Self>` at the matching-singleton fixpoint on any
/// implementor of cardinality `>= 3`. Pinned by
/// `unique_antimodal_variant_returns_none_on_the_matching_singleton_at_cardinality_ge_three_across_every_variant`.
///
/// Single-missing contract at [`Self::CARDINALITY`] `>= 2`: for the
/// slice `T::ALL[..T::CARDINALITY - 1]` (omit the last variant),
/// `T::unique_antimodal_variant(&single_missing) == Some(T::ALL[T::CARDINALITY - 1])`
/// — every present variant `v` has count `1`, the omitted last
/// variant has count `0`, [`Self::min_variant_count`] collapses to
/// `0`, ONLY the omitted variant satisfies `count == min`, so
/// [`Self::count_antimodal_variants`] reports `1`,
/// [`Self::has_unique_antimode`] returns `true`, and
/// [`Self::antimodal_variant`] returns `Some(T::ALL[T::CARDINALITY -
/// 1])`. The single-missing arm is the LOAD-BEARING `Some`-arm catch
/// on the argmin unique-tie corner — every OTHER canonical fixpoint at
/// cardinality `>= 2` (empty, matching-singleton at cardinality
/// `>= 3`, full-set, doubled-full-set) reports `None`, so an override
/// that folds onto `None` unconditionally passes every other arm
/// silently but bifurcates HERE loudly. Sibling posture to
/// `is_unique_antimodal_variant_of_returns_true_at_missing_target_on_the_single_missing_slice_at_cardinality_ge_two`
/// one ARITY axis over: the per-target argmin unique-tie predicate
/// reaches its `true` fixpoint at EXACTLY the omitted last variant on
/// the same slice; THIS set-level `Option<Self>` witness reaches its
/// `Some(_)` fixpoint at the same slice reporting the same omitted
/// variant as the witness. Pinned by
/// `unique_antimodal_variant_returns_some_omitted_last_on_the_single_missing_slice_at_cardinality_ge_two_across_every_kind`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::unique_antimodal_variant(<T as ClosedSet>::ALL) == None`
/// UNCONDITIONALLY — the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants as
/// pairwise distinct, so every variant of [`Self::ALL`] appears at
/// EXACTLY ONE position of the full-set slice, every per-variant count
/// is `1`, [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`]
/// `>= 2`, [`Self::has_unique_antimode`] returns `false`, and the
/// guard collapses the projection to `None`. LOAD-BEARING ASYMMETRY
/// against [`Self::antimodal_variant`] which returns `Some(T::first())`
/// on the same slice — the unique-tie sharpening SEPARATES the
/// unsharpened argmin first-witness (returns the declaration-order-
/// first tie-member) from THIS uniqueness-gated projection (collapses
/// to `None` on multi-way ties) on the flat-histogram fixpoint at
/// cardinality `>= 2`. Pinned by
/// `unique_antimodal_variant_returns_none_on_the_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::unique_antimodal_variant(&doubled) == None` — the doubled full
/// set hits every variant at EXACTLY TWO positions, every per-variant
/// count is `2`, [`Self::count_antimodal_variants`] reports
/// [`Self::CARDINALITY`] `>= 2`, [`Self::has_unique_antimode`] returns
/// `false`, and the guard collapses the projection to `None`. Together
/// with the full-set arm pins THIS projection as INVARIANT under
/// uniform slice-multiplication on flat-histogram slices AT `None` at
/// cardinality `>= 2`. Pinned by
/// `unique_antimodal_variant_returns_none_on_the_doubled_full_set_at_cardinality_ge_two_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_antimode`] + [`Self::antimodal_variant`] via a
/// boolean-guarded `Option`-collapse on `Option<Self>`. The sweep cost
/// inherits both underlying projections: `O(T::CARDINALITY * n)` on
/// slice arity `n` (one [`Self::min_variant_count`] fold, one
/// [`Self::count_antimodal_variants`] filter-count sweep, and one
/// [`Self::antimodal_variant`] find sweep when the guard holds; the
/// short-circuiting `if` avoids the second sweep when the guard
/// falsifies), allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_antimodal_variant`]: a `tatara-check` predicate
/// `(check-antimode-if-unique …)` that reports "the trough variant, if
/// unambiguous" as a typed `Option`-return rather than a two-step
/// (has-unique-antimode? then antimodal-variant) composition; a
/// Sekiban audit-trail per-window witness-if-unique binding to the
/// same scalar, composable with the just-lifted set-level antimodal-
/// uniqueness bit into a typed `(unique-antimode-bit, unique-antimode-
/// witness)` classifier per window; a scheduler-fairness diagnostic
/// that reports "the idlest worker, only if uniquely idlest" without
/// paying the antimodal-witness Vec allocation; an LSP hint that
/// surfaces the histogram trough on a Lisp-authored field only when
/// the trough is unambiguous, staying silent on tied troughs; a
/// starvation-witness metric emitter that binds a Prometheus-style
/// `unique_antimode_variant` label with the empty-string absent
/// semantic on tied windows, distinct from the sibling
/// `antimode_variant_decl` label which always reports the declaration-
/// order-first tie-member. Each binds to ONE typed `Option<Self>`-
/// return uniqueness-gated argmin aggregate on the trait rather than
/// re-deriving `if T::has_unique_antimode(items) {
/// T::antimodal_variant(items) } else { None }` inline per callsite
/// OR paying the Vec allocation `T::antimodal_variants(items).into_iter().next()
/// .filter(|_| T::antimodal_variants(items).len() == 1)` would demand.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction × unique-tie)
/// 2-corner face at its argmin arm past the just-opened
/// [`Self::unique_modal_variant`] argmax corner one DIRECTION axis
/// over, completing the (direction × unique-tie) column at both
/// corners on the `Option<Self>`-return row. The just-lifted lex-
/// order peer [`Self::sorted_unique_antimodal_variant`] closes the
/// (declaration, lex) row at the argmin arm as the mirror
/// [`Self::sorted_unique_modal_variant`] closed at the argmax arm,
/// EXHAUSTIVELY CLOSING the (`Option<Self>` × direction × ordering ×
/// unique-tie) 2×2×2 = 8-corner cube at its FINAL corner past the
/// (argmax, declaration), (argmax, lex), (argmin, declaration) prior
/// three uniqueness-gated arms; the natural next lifts past this
/// closure walk one COMBINATOR axis over on the modal-aggregation
/// matrix into the direction-composition (extremal / middle-band /
/// bimodal × ordering × unique-tie) arms via the same boolean-guarded
/// lift under an `Option`-collapse.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-antimode `Option<Self>` witness projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline `if T::has_unique_antimode(items) {
/// T::antimodal_variant(items) } else { None }` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × `Option<Self>` × unique-antimode) witness-if-unique
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variant is the histogram's trough,
/// if it's unambiguous?" site pre-lift. Naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the just-lifted set-level
/// antimodal-uniqueness bit and the declaration-order argmin first-
/// witness under a boolean-guarded `Option`-collapse. THEORY.md
/// §VI.1 — generation over composition; the projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::has_unique_antimode`] + [`Self::antimodal_variant`]) with
/// the `if _ { _ } else { None }` combinator on `Option<Self>`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- which(t ==
/// min(t)); if (length(m) == 1) names(t)[m] else NA }` — the
/// canonical guarded-argmin on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = minimum(values(c)), ties =
/// filter(kv -> kv[2] == m, collect(c)); length(ties) == 1 ?
/// Some(ties[1][1]) : Nothing end` on a `Dict{Element, Int}`
/// histogram; Python's `let c = collections.Counter(items); tied =
/// [k for k, v in c.items() if v == min(c.values(), default=0)];
/// tied[0] if len(tied) == 1 else None`; Haskell's `case filter
/// ((== m) . snd) hs of [(v, _)] -> Just v; _ -> Nothing` on the
/// per-target min-count fold; Clojure's `(let [f (frequencies coll),
/// m (apply min (vals f)), ts (filter #(= (val %) m) f)] (when (= 1
/// (count ts)) (key (first ts))))`; Coq's `option`-return guarded-
/// argmin; SQL's `SELECT variant FROM (SELECT variant, COUNT(*) AS c
/// FROM t GROUP BY variant HAVING c = (SELECT MIN(c) …)) WHERE (SELECT
/// COUNT(*) FROM …) = 1` — the canonical set-level uniqueness-guarded
/// argmin witness. Translation through pleme-io primitives: the N-ary
/// set-level uniqueness-gated argmin witness projection on the closed-
/// set trait binds through the just-lifted [`Self::has_unique_antimode`]
/// guard conjoined with the just-lifted [`Self::antimodal_variant`]
/// first-witness under an `Option`-collapse — no new dep, no
/// supertrait bound, no allocation, `O(T::CARDINALITY * n)` inherited
/// from the underlying aggregates with short-circuiting on the guard.
/// One pleme-io-specific asymmetry against the argmax peer: the
/// argmin uniqueness reports `Some(_)` at the single-missing (omit-
/// last) fixture at cardinality `>= 2` — a fixpoint the argmax peer
/// misses entirely because `count_modal_variants(single_missing) ==
/// T::CARDINALITY - 1 >= 1` at the (present, count 1) band with no
/// unique argmax at cardinality `>= 3` — so the direction axis
/// SEPARATES on this LOAD-BEARING `Some`-arm catch while COINCIDING
/// on the flat-histogram fixpoints where the direction axis
/// collapses.
fn unique_antimodal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_antimode(items) {
<Self as ClosedSet>::antimodal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique antimodal variant, lex-
/// first" projection — `Some(v)` iff `items` has a unique antimode
/// ([`Self::has_unique_antimode`] holds) AND `v` is the sole variant
/// of [`Self::sorted_variants`] achieving [`Self::min_variant_count`],
/// else `None`. Computed as the just-lifted set-level antimodal-
/// uniqueness bit [`Self::has_unique_antimode`] guarding a LEX-ORDER
/// first-witness sweep of [`Self::sorted_variants`] keyed on
/// `count == min` — equivalently, the just-lifted
/// [`Self::sorted_antimodal_variant`] projection under the same
/// guard. The LEX-ORDER `Option<Self>`-RETURN UNIQUE-TIE SHARPENING
/// corner EXHAUSTIVELY CLOSING the (set-level × `Option<Self>` ×
/// statistical-aggregate × direction × ordering × unique-tie) 2×2×2
/// = 8-corner cube at its FINAL corner past the (argmax, declaration)
/// [`Self::unique_modal_variant`] opener, the (argmax, lex)
/// [`Self::sorted_unique_modal_variant`] just-lifted argmax-lex
/// closure, and the (argmin, declaration) [`Self::unique_antimodal_variant`]
/// argmin-declaration closure — the argmin-lex arm one ORDERING axis
/// over from [`Self::unique_antimodal_variant`] AND one DIRECTION axis
/// over from [`Self::sorted_unique_modal_variant`]. Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from a boolean conjunction of the set-level antimodal-uniqueness
/// bit with a lex-order first-witness [`Iterator::find`] sweep of
/// [`Self::sorted_variants`] under an `Option`-collapse when the
/// guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_antimodal_variant(items) ==
/// T::unique_antimodal_variant(items)` — when the sole argmin witness
/// is UNIQUE ([`Self::has_unique_antimode`] holds) declaration-order
/// and lex-order both walk the same `count == min` predicate over the
/// same `T::CARDINALITY`-sized variant carrier and land on THE SAME
/// SOLE argmin variant; when the guard falsifies both projections
/// collapse to `None` through the same guard arm. The LEX peer is
/// thus IDENTICALLY equal to its declaration-order sibling on every
/// input — the search-order axis becomes provably irrelevant WHEN
/// the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_antimodal_variant_equals_unique_antimodal_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence. Sibling posture
/// to the argmax peer's ordering-choice-irrelevance identity one
/// DIRECTION axis over: the argmax and argmin arms report DIFFERENT
/// witnesses on the same slice at directional-asymmetry fixtures
/// (e.g. the single-missing arm at cardinality `>= 2`) but BOTH
/// witness ordering-agnosticism on their respective direction anchor.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_antimodal_variant(items) ==
/// if T::has_unique_antimode(items) { T::sorted_antimodal_variant(items) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_antimodal_variant(items).is_some() ==
/// T::has_unique_antimode(items)` — the `Option<Self>` return's
/// `is_some` bit COINCIDES with the set-level antimodal-uniqueness
/// bit. Independent cross-check on the surface axis distinct from the
/// option-equality arm against [`Self::unique_antimodal_variant`].
///
/// Sorted-antimodal witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_antimodal_variant(items) == (if T::sorted_antimodal_variants(items).len() == 1 { Some(T::sorted_antimodal_variants(items)[0]) } else { None })`
/// — when `items` has a unique antimode, the lex-order argmin witness-
/// collection [`Self::sorted_antimodal_variants`] collapses to a
/// length-`1` Vec containing EXACTLY that unique variant, so its
/// slot-`0` wrapped in `Some` coincides with THIS projection.
/// Independent cross-check on the witness-Vec surface axis distinct
/// from the scalar arms.
///
/// Flat-histogram coincidence identity: for every NON-EMPTY slice
/// `items` whose per-variant histogram is flat (i.e. every variant of
/// [`Self::ALL`] shares one common multiplicity — the empty, full-
/// set, and doubled-full-set fixpoints),
/// `T::sorted_unique_antimodal_variant(items) == T::sorted_unique_modal_variant(items)`
/// — the direction axis on flat-histogram slices COLLAPSES
/// (`min == max`), so the argmin and argmax lex-first-witnesses
/// coincide AND the uniqueness guards coincide at their common
/// (`count_modal_variants == count_antimodal_variants == T::CARDINALITY`)
/// value, and the guarded `Option<Self>` projections coincide byte-
/// for-byte. Sibling posture to
/// `unique_antimodal_variant_coincides_with_unique_modal_variant_on_flat_histogram_slices`
/// one ORDERING axis over: the declaration-order (direction × unique-
/// tie) coincidence lifts verbatim to the lex-order row through the
/// shared guarded-lift combinator.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_antimode`] (ordering-agnostic on the input axis
/// — the underlying [`Self::count_antimodal_variants`] is invariant
/// under slice-reversal) and [`Self::sorted_antimodal_variant`]
/// (ordering-agnostic on the input axis — the underlying
/// [`Self::count_occurrences_of`] + [`Self::min_variant_count`] are
/// both invariant under slice-reversal) under a boolean-guarded
/// `Option`-collapse.
///
/// Empty-slice contract: `T::sorted_unique_antimodal_variant(&[]) ==
/// None` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_antimodal_variants`] reports `0` at the empty-slice
/// short-circuit, [`Self::has_unique_antimode`] returns `false`, and
/// the guard collapses the projection to `None` before
/// [`Self::sorted_antimodal_variant`]'s own `None`-at-empty branch
/// is consulted.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::sorted_unique_antimodal_variant(&[v]) == None` for every
/// variant `v` — the sole position hits `v` at count `1`, every
/// non-target variant has count `0`, [`Self::min_variant_count`]
/// collapses to `0`, EVERY non-target variant satisfies `count ==
/// min`, so [`Self::count_antimodal_variants`] reports
/// [`Self::CARDINALITY`] `- 1 >= 2 != 1`,
/// [`Self::has_unique_antimode`] returns `false`, and the guard
/// collapses the projection to `None`. LOAD-BEARING ASYMMETRY
/// against [`Self::sorted_unique_modal_variant`] which returns
/// `Some(v)` on the same slice — the direction axis SEPARATES the
/// argmax and argmin uniqueness-witness corners distinctly on the
/// lex-order `Option<Self>`-return row at the matching-singleton
/// fixpoint on any implementor of cardinality `>= 3`.
///
/// Single-missing contract at [`Self::CARDINALITY`] `>= 2`
/// (LOAD-BEARING POSITIVE ARM): for the slice
/// `T::ALL[..T::CARDINALITY - 1]` (omit the last variant),
/// `T::sorted_unique_antimodal_variant(&single_missing) == Some(T::ALL[T::CARDINALITY - 1])`
/// — every present variant has count `1`, the omitted last variant
/// has count `0`, [`Self::min_variant_count`] collapses to `0`, ONLY
/// the omitted variant satisfies `count == min`, so
/// [`Self::count_antimodal_variants`] reports `1`,
/// [`Self::has_unique_antimode`] returns `true`, the guard fires,
/// and the lex-order sweep of [`Self::sorted_variants`] hits the
/// SAME sole argmin variant `T::ALL[T::CARDINALITY - 1]` that the
/// declaration-order sweep at [`Self::unique_antimodal_variant`]
/// lands on. BY UNIQUENESS of the argmin witness the sole witness is
/// the ONLY variant either sweep can find. The single-missing arm is
/// the LOAD-BEARING `Some`-arm catch on the argmin-lex unique-tie
/// corner — every OTHER canonical fixpoint at cardinality `>= 2`
/// (empty, matching-singleton at cardinality `>= 3`, full-set,
/// doubled-full-set) reports `None`, so an override that folds onto
/// `None` unconditionally passes every other arm silently but
/// bifurcates HERE loudly. LOAD-BEARING DISJOINT-WITNESS mirror of
/// the sibling equivalence-partition (mult `== 0`) arm
/// [`Self::sorted_unique_missing_variant`] at the SAME single-missing
/// fixture: both LEX-ORDER `Some(_)` arms report THE SAME omitted-
/// last variant on this fixture because the argmin-band and the
/// (mult `== 0`) miss-band COINCIDE at exactly the omitted variant
/// on this canonical positive fixpoint — the two orthogonal surfaces
/// (modal-aggregation × direction × argmin, equivalence-partition ×
/// mult-band `== 0`) UNIFY at the single-missing witness because
/// argmin-count-`0` and missing-multiplicity-`0` are the same band on
/// slices where `min_variant_count == 0`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::sorted_unique_antimodal_variant(T::ALL) == None`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at count `1`, every per-variant multiplicity
/// is `1`, [`Self::count_antimodal_variants`] reports
/// [`Self::CARDINALITY`] `>= 2`, [`Self::has_unique_antimode`]
/// returns `false`, and the guard collapses to `None`. LOAD-BEARING
/// ASYMMETRY against [`Self::sorted_antimodal_variant`] which
/// returns `Some(T::sorted_first())` on the same slice — the unique-
/// tie sharpening SEPARATES the unsharpened lex-order argmin first-
/// witness (returns the lex-order-first tie-member) from THIS
/// uniqueness-gated projection (collapses to `None` on multi-way
/// ties) on the flat-histogram fixpoint at cardinality `>= 2`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::sorted_unique_antimodal_variant(T::ALL ++ T::ALL) == None`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// exactly two positions, every count is `2`,
/// [`Self::count_antimodal_variants`] reports [`Self::CARDINALITY`],
/// [`Self::has_unique_antimode`] returns `false`, and the guard
/// collapses to `None`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_antimode`] + [`Self::sorted_antimodal_variant`]
/// via a boolean-guarded `Option`-collapse on `Option<Self>`. Cost
/// inherits both underlying projections: `O(T::CARDINALITY * n)` on
/// slice arity `n` (one [`Self::min_variant_count`] fold, one
/// [`Self::count_antimodal_variants`] filter-count sweep, and one
/// lex-order [`Iterator::find`] sweep when the guard holds; the
/// short-circuiting `if` avoids the second sweep when the guard
/// falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, allocation-free at the return,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_antimodal_variant`]: a `tatara-check`
/// predicate `(check-antimode-if-unique-lex-first …)` that reports
/// "the trough variant, in lex order, if unambiguous" for a caller
/// that prefers lex-order presentation regardless of declaration-
/// order (which may be arbitrary or convenience-ordered); a Sekiban
/// audit-trail per-window witness-if-unique binding that pins the
/// lex-order trough-witness for stability against upstream
/// declaration-order churn; a scheduler-fairness diagnostic reporting
/// "the idlest worker, lex-first, only if uniquely idlest" for
/// deterministic presentation on enum refactoring that permutes
/// declaration order; a starvation-witness metric emitter that binds
/// a Prometheus-style `unique_antimode_variant_lex` label with the
/// empty-string absent semantic on tied windows. Each binds to ONE
/// typed lex-order `Option<Self>`-return uniqueness-gated argmin
/// aggregate on the trait — AND, by the ordering-choice-irrelevance
/// identity, TYPED PROOF that the search-order choice is
/// operationally free WHEN the underlying antimodal-uniqueness bit
/// holds.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × `Option<Self>` × statistical-aggregate × direction ×
/// ordering × unique-tie) 2×2×2 = 8-corner cube at its FINAL corner
/// past the (argmax, declaration) [`Self::unique_modal_variant`]
/// opener, the (argmax, lex) [`Self::sorted_unique_modal_variant`]
/// argmax-lex closure, and the (argmin, declaration)
/// [`Self::unique_antimodal_variant`] argmin-declaration closure. The
/// natural next lifts past this closure walk one COMBINATOR axis over
/// on the modal-aggregation matrix into the direction-composition
/// (extremal / middle-band / bimodal) LEX-order uniqueness-gated arms
/// (`sorted_unique_extremal_variant`, `sorted_unique_middle_band_variant`,
/// `sorted_unique_bimodal_variant`), each emerging as a boolean-
/// guarded lift of the existing (`Option<Self>` × direction-
/// composition × ordering) unsharpened peer under the existing (bool
/// × direction-composition) uniqueness bit with no fresh substrate
/// primitives on the index axis.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × statistical-aggregate ×
/// direction × argmin × unique-tie) corner becomes a TYPED WITNESS
/// on the ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_antimode(items) { T::sorted_antimodal_variant(items) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once rather than every downstream site re-proving
/// via `sorted_unique_antimodal_variant(items) == unique_antimodal_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Option<Self>` × direction × argmin × unique-tie)
/// corner was an unnamed inline composition — OR silently absent
/// because the caller shrugged and used the declaration-order sibling
/// without proof of coincidence — recurring at every prospective
/// downstream "which variant is the histogram's trough, in lex order,
/// if unambiguous?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of the
/// two substrate primitives [`Self::has_unique_antimode`] +
/// [`Self::sorted_antimodal_variant`] with the `if _ { _ } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `{ t <- table(items); s <- sort(names(t)[t == min(t)]); if (length(s) == 1) s[1] else NA }`
/// — the guarded lex-order argmin on a factor histogram; Julia's
/// `let c = StatsBase.countmap(items), m = minimum(values(c)), ties = filter(kv -> kv[2] == m, sort(collect(c), by = kv -> kv[1])); length(ties) == 1 ? Some(ties[1][1]) : Nothing end`;
/// Python's `sorted(k for k, v in collections.Counter(items).items() if v == min(collections.Counter(items).values(), default=0))[:1]`
/// filtered by outer count-guard; Haskell's `filter (\v -> Map.findWithDefault 0 v hs == m) (sort allLevels)`
/// guarded to singleton; Clojure's `(let [f (frequencies coll), m (apply min (vals f)), ts (filter #(= (val %) m) (sort ALL-LEVELS))] (when (= 1 (count ts)) (first ts)))`;
/// SQL's `SELECT variant FROM t GROUP BY variant HAVING COUNT(*) = (SELECT MIN(c) …) ORDER BY variant LIMIT 1`
/// filtered by an outer count-guard. Translation through pleme-io
/// primitives: the projection binds through the set-level antimodal-
/// uniqueness bit [`Self::has_unique_antimode`] conjoined with the
/// lex-order argmin first-witness [`Self::sorted_antimodal_variant`]
/// under an `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation at the
/// return, cost inherited from the underlying aggregates with short-
/// circuiting on the guard.
fn sorted_unique_antimodal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_antimode(items) {
<Self as ClosedSet>::sorted_antimodal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique extremal variant, lex-
/// first" projection — `Some(v)` iff `items` has a UNIQUE extremal
/// witness ([`Self::has_unique_extremal_variant`] holds) AND `v` is
/// the sole variant of [`Self::sorted_variants`] achieving EITHER
/// [`Self::max_variant_count`] OR [`Self::min_variant_count`], else
/// `None`. Computed as the just-lifted set-level extremal-union
/// uniqueness bit [`Self::has_unique_extremal_variant`] guarding a
/// LEX-ORDER first-witness sweep of [`Self::sorted_variants`] keyed
/// on `count == max || count == min` — equivalently, the just-
/// lifted [`Self::sorted_extremal_variant`] projection under the
/// same guard. The LEX-ORDER `Option<Self>`-RETURN UNIQUE-TIE
/// SHARPENING corner OPENING the (set-level × `Option<Self>` ×
/// statistical-aggregate × direction-composition × ordering ×
/// unique-tie) column past the (declaration, union) opener
/// [`Self::unique_extremal_variant`] one ORDERING axis over on the
/// modal-aggregation matrix — the union-lex arm one COMBINATOR
/// axis over from [`Self::sorted_unique_modal_variant`] /
/// [`Self::sorted_unique_antimodal_variant`] which just closed the
/// direction-anchored 8-corner cube at the (argmax, lex) and
/// (argmin, lex) corners. Not a fresh substrate primitive on the
/// index axis — the projection emerges from a boolean conjunction
/// of the set-level extremal-union uniqueness bit with a lex-order
/// first-witness [`Iterator::find`] sweep of [`Self::sorted_variants`]
/// under an `Option`-collapse when the guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_extremal_variant(items) ==
/// T::unique_extremal_variant(items)` — when the sole extremal
/// witness is UNIQUE ([`Self::has_unique_extremal_variant`] holds)
/// declaration-order and lex-order both walk the same `count ==
/// max || count == min` predicate over the same `T::CARDINALITY`-
/// sized variant carrier and land on THE SAME SOLE extremal
/// variant; when the guard falsifies both projections collapse to
/// `None` through the same guard arm. The LEX peer is thus
/// IDENTICALLY equal to its declaration-order sibling on every
/// input — the search-order axis becomes provably irrelevant WHEN
/// the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_extremal_variant_equals_unique_extremal_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence. Sibling
/// posture to the direction-anchored peers' ordering-choice-
/// irrelevance identities one COMBINATOR axis over: the argmax
/// and argmin arms report DIRECTION-SPECIFIC witnesses on the same
/// slice at directional-asymmetry fixtures (single-missing arm at
/// cardinality `>= 2`, matching-singleton arm) while THIS union
/// arm collapses to `None` on every multi-variant fixture at
/// cardinality `>= 2` via the degenerate-opener property.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_extremal_variant(items) ==
/// if T::has_unique_extremal_variant(items) { T::sorted_extremal_variant(items) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_extremal_variant(items).is_some() ==
/// T::has_unique_extremal_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level extremal-
/// union uniqueness bit. Independent cross-check on the surface
/// axis distinct from the option-equality arm against
/// [`Self::unique_extremal_variant`].
///
/// Sorted-extremal witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_extremal_variant(items) == (if T::sorted_extremal_variants(items).len() == 1 { Some(T::sorted_extremal_variants(items)[0]) } else { None })`
/// — when `items` has a unique extremal witness, the lex-order
/// union witness-collection [`Self::sorted_extremal_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection. Independent cross-check on the witness-Vec surface
/// axis distinct from the scalar arms.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_extremal_variant`] (ordering-agnostic on the
/// input axis — the underlying [`Self::count_extremal_variants`]
/// is invariant under slice-reversal) and
/// [`Self::sorted_extremal_variant`] (ordering-agnostic on the
/// input axis — the underlying max/min-fold pair +
/// [`Self::count_occurrences_of`] find sweep are all invariant
/// under slice-reversal) under a boolean-guarded `Option`-collapse.
///
/// Empty-slice contract: `T::sorted_unique_extremal_variant(&[]) ==
/// None` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_extremal_variants`] reports `0` at the empty-
/// slice short-circuit, [`Self::has_unique_extremal_variant`]
/// returns `false`, and the guard collapses the projection to
/// `None` before [`Self::sorted_extremal_variant`]'s own `None`-
/// at-empty branch is consulted.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::sorted_unique_extremal_variant(items) == None` on EVERY
/// non-empty slice on EVERY implementor with `T::CARDINALITY >=
/// 2` — the inclusion-exclusion identity `count_extremal_variants
/// == count_modal + count_antimodal - count_bimodal` pins the
/// union cardinality at `T::CARDINALITY` on every flat-histogram
/// fixpoint (max == min collapses all three counts) and at `>= 2`
/// on every non-flat fixpoint (max != min splits argmax and argmin
/// into two disjoint non-empty bands with empty intersection, so
/// the union carries at least one modal AND one antimodal
/// variant — count `>= 2`). [`Self::has_unique_extremal_variant`]
/// therefore returns `false` everywhere past the empty slice at
/// cardinality `>= 2`, and the guard collapses the projection to
/// `None`. THIS corner INHERITS the DEGENERATE-OPENER property of
/// its declaration-order sibling [`Self::unique_extremal_variant`]
/// verbatim — the SOLE `Some(_)` arm sits at `T::CARDINALITY == 1`
/// where a matching singleton (= full-set) collapses the union to
/// a single variant, out of reach of the multi-variant test-
/// module fixtures. LOAD-BEARING ASYMMETRY against
/// [`Self::sorted_unique_modal_variant`] which returns `Some(v)`
/// on every matching-singleton at any cardinality — the
/// direction-composition axis SEPARATES the argmax uniqueness-
/// witness corner from THIS union uniqueness-witness corner on
/// the matching-singleton fixpoint at cardinality `>= 2` (the
/// argmax witness collapses to `{v}`, unambiguous; the union
/// witness carries both `{v}` and `T::ALL \ {v}`, ambiguous).
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_extremal_variant(&[v]) == None` for every
/// variant `v` — the target hits count `1 == max`, every non-
/// target sits at count `0 == min`, the argmax band `{v}` (size
/// `1`) and the argmin band `T::ALL \ {v}` (size `T::CARDINALITY -
/// 1 >= 1`) are disjoint, so [`Self::count_extremal_variants`]
/// reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_extremal_variant`] returns `false`, and the
/// guard collapses to `None`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::sorted_unique_extremal_variant(<T as ClosedSet>::ALL) ==
/// None` + `T::sorted_unique_extremal_variant(&doubled) == None`
/// — on either flat-histogram fixpoint every variant sits at BOTH
/// extremes simultaneously via the (max == min) collapse; the
/// union covers all of [`Self::ALL`],
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY >=
/// 2`, and the guard collapses to `None`. LOAD-BEARING ASYMMETRY
/// against [`Self::sorted_extremal_variant`] which returns
/// `Some(T::sorted_first())` on the same slice — the unique-tie
/// sharpening SEPARATES the unsharpened lex-order union first-
/// witness from THIS uniqueness-gated projection at the flat-
/// histogram fixpoint.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax
/// is `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]`
/// (count `0`), the union carries the two disjoint bands and
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY - 1
/// >= 2`, so the guard collapses the projection to `None`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_extremal_variant`] +
/// [`Self::sorted_extremal_variant`] via a boolean-guarded
/// `Option`-collapse on `Option<Self>`. Cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity
/// `n` (one max/min-fold pair, one
/// [`Self::count_extremal_variants`] filter-count sweep, and one
/// lex-order [`Iterator::find`] sweep when the guard holds; the
/// short-circuiting `if` avoids the second sweep when the guard
/// falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, allocation-free at the return,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_extremal_variant`]: a `tatara-check`
/// predicate `(check-extremal-if-unique-lex-first …)` that reports
/// "the sole extremal variant, in lex order, if unambiguous" for
/// a caller that prefers lex-order presentation regardless of
/// declaration-order (which may be arbitrary or convenience-
/// ordered); a Sekiban audit-trail per-window witness-if-unique
/// binding that pins the lex-order extremum for stability against
/// upstream declaration-order churn; an LSP hint that surfaces
/// the histogram extremum on a Lisp-authored field only when the
/// extremum is unambiguous, in lex order, staying silent on tied
/// unions; a Prometheus-style `unique_extremal_variant_lex` label
/// with the empty-string absent semantic on tied windows. Each
/// binds to ONE typed lex-order `Option<Self>`-return uniqueness-
/// gated union aggregate on the trait — AND, by the ordering-
/// choice-irrelevance identity, TYPED PROOF that the search-order
/// choice is operationally free WHEN the underlying extremal-
/// uniqueness bit holds.
///
/// Compounding closure: this projection OPENS the LEX-ORDER
/// (`Option<Self>` × direction-composition × ordering × unique-
/// tie) row on the direction-composition surface past the just-
/// closed direction-anchored (argmax, lex) + (argmin, lex) arms
/// [`Self::sorted_unique_modal_variant`] +
/// [`Self::sorted_unique_antimodal_variant`] one COMBINATOR axis
/// over, peer to [`Self::unique_extremal_variant`] one ORDERING
/// axis over. The remaining two tiles on the direction-composition
/// LEX row are the complement arm
/// `sorted_unique_middle_band_variant(items) -> Option<Self>`
/// (returning `Some(v)` iff `has_unique_middle_band_variant(items)`
/// holds AND `v` is the lex-first sole strict-interior variant)
/// and the intersection arm `sorted_unique_bimodal_variant(items)
/// -> Option<Self>` (returning `Some(v)` iff
/// `has_unique_bimodal_variant(items)` holds AND `v` is the lex-
/// first sole `max == min` witness). Each remaining corner
/// emerges as a boolean-guarded lift of the existing
/// (`Option<Self>` × direction-composition × lex) unsharpened peer
/// under the existing (`bool` × direction-composition × unique-
/// tie) uniqueness bit with no fresh substrate primitives on the
/// index axis.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × statistical-aggregate ×
/// direction-composition × union × unique-tie) corner becomes a
/// TYPED WITNESS on the ClosedSet trait rather than a per-consumer
/// inline `if T::has_unique_extremal_variant(items) { T::sorted_extremal_variant(items) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-
/// irrelevance) the substrate proves once rather than every
/// downstream site re-proving via
/// `sorted_unique_extremal_variant(items) == unique_extremal_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform;
/// the (lex-order × `Option<Self>` × direction-composition × union
/// × unique-tie) corner was an unnamed inline composition — OR
/// silently absent because the caller shrugged and used the
/// declaration-order sibling without proof of coincidence —
/// recurring at every prospective downstream "which variant is
/// the histogram's extremum, in lex order, if unambiguous?" site
/// pre-lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of the two substrate
/// primitives [`Self::has_unique_extremal_variant`] +
/// [`Self::sorted_extremal_variant`] with the
/// `if _ { _ } else { None }` combinator on `Option<Self>`, not as
/// a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t);
/// n <- min(t); s <- sort(names(t)[t == m | t == n]); if
/// (length(s) == 1) s[1] else NA }` — the guarded lex-order union
/// on a factor histogram; Julia's `let c = StatsBase.countmap(items),
/// m = maximum(values(c)), n = minimum(values(c)), ties =
/// filter(kv -> kv[2] == m || kv[2] == n, sort(collect(c), by =
/// kv -> kv[1])); length(ties) == 1 ? Some(ties[1][1]) : Nothing
/// end`; Python's `sorted(k for k, v in
/// collections.Counter(items).items() if v ==
/// max(collections.Counter(items).values(), default=0) or v ==
/// min(collections.Counter(items).values(), default=0))[:1]`
/// filtered by outer count-guard; Haskell's `filter (\v ->
/// let c = Map.findWithDefault 0 v hs in c == m || c == n) (sort
/// allLevels)` guarded to singleton; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min (vals
/// f)), ts (filter #(or (= (val %) m) (= (val %) n)) (sort ALL-
/// LEVELS))] (when (= 1 (count ts)) (first ts)))`; SQL's `SELECT
/// variant FROM t GROUP BY variant HAVING COUNT(*) = (SELECT
/// MAX(c) …) OR COUNT(*) = (SELECT MIN(c) …) ORDER BY variant
/// LIMIT 1` filtered by an outer count-guard. Translation through
/// pleme-io primitives: the projection binds through the set-
/// level extremal-union uniqueness bit
/// [`Self::has_unique_extremal_variant`] conjoined with the lex-
/// order union first-witness [`Self::sorted_extremal_variant`]
/// under an `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation at
/// the return, cost inherited from the underlying aggregates with
/// short-circuiting on the guard.
fn sorted_unique_extremal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_extremal_variant(items) {
<Self as ClosedSet>::sorted_extremal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique middle-band variant, lex-
/// first" projection — `Some(v)` iff `items` has a UNIQUE strict-
/// interior witness ([`Self::has_unique_middle_band_variant`] holds)
/// AND `v` is the sole variant of [`Self::sorted_variants`] with
/// occurrence-count STRICTLY BETWEEN [`Self::max_variant_count`] AND
/// [`Self::min_variant_count`], else `None`. Computed as the just-
/// lifted set-level middle-band uniqueness bit
/// [`Self::has_unique_middle_band_variant`] guarding the LEX-ORDER
/// strict-interior first-witness [`Self::sorted_middle_band_variant`]
/// projection: when the guard holds the complement witness is
/// unambiguous and lifted verbatim; when the guard falsifies the
/// projection collapses to `None`. The LEX-ORDER `Option<Self>`-
/// RETURN UNIQUE-TIE SHARPENING corner CLOSING the complement arm
/// of the (set-level × sorted × `Option<Self>` × direction-
/// composition × combinator × unique-tie) row past the just-opened
/// UNION arm [`Self::sorted_unique_extremal_variant`] one COMBINATOR
/// axis over on the modal-aggregation matrix AND peer to
/// [`Self::unique_middle_band_variant`] one ORDERING axis over
/// (declaration-order → lex-order strict-interior first-witness-
/// when-unique) AND peer to [`Self::sorted_middle_band_variant`]
/// one UNIQUE-TIE-SHARPENING axis over (unsharpened lex-order
/// strict-interior first-witness → uniqueness-gated lex-order
/// strict-interior first-witness). Not a fresh substrate primitive
/// on the index axis — the projection emerges from a boolean
/// conjunction of the just-lifted set-level middle-band uniqueness
/// bit with the just-lifted lex-order strict-interior first-witness
/// projection under an `Option`-collapse when the guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variant(items) ==
/// T::unique_middle_band_variant(items)` — when the sole strict-
/// interior witness is UNIQUE ([`Self::has_unique_middle_band_variant`]
/// holds) declaration-order and lex-order both walk the same
/// `count > min && count < max` predicate over the same
/// `T::CARDINALITY`-sized variant carrier and land on THE SAME SOLE
/// strict-interior variant; when the guard falsifies both
/// projections collapse to `None` through the same guard arm. The
/// LEX peer is thus IDENTICALLY equal to its declaration-order
/// sibling on every input — the search-order axis becomes provably
/// irrelevant WHEN the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_middle_band_variant_equals_unique_middle_band_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence. Sibling
/// posture to the just-opened union peer
/// [`Self::sorted_unique_extremal_variant`] one COMBINATOR axis
/// over which pins the SAME ordering-choice-irrelevance identity
/// against [`Self::unique_extremal_variant`]: both witness-if-
/// unique corners on the direction-composition row prove the
/// search-order axis irrelevant, so the substrate's four search-
/// order projections on the (union, complement) × (declaration,
/// lex) 2×2 face of the unique-tie-sharpened direction-composition
/// row of the closed-set trait now pairwise-collapse to two
/// projections modulo the two uniqueness bits.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variant(items) ==
/// if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variant(items) }
/// else { None }` — the canonical form the body uses. Pinned by
/// `sorted_unique_middle_band_variant_equals_has_unique_middle_band_variant_gated_sorted_middle_band_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variant(items).is_some() ==
/// T::has_unique_middle_band_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level middle-band
/// uniqueness bit. Independent cross-check on the surface axis
/// distinct from the option-equality arm against
/// [`Self::unique_middle_band_variant`]. Pinned by
/// `sorted_unique_middle_band_variant_is_some_iff_has_unique_middle_band_variant_across_every_triple`.
///
/// Sorted-middle-band witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_middle_band_variant(items) == (if T::sorted_middle_band_variants(items).len() == 1 { Some(T::sorted_middle_band_variants(items)[0]) } else { None })`
/// — when `items` has a unique middle-band witness, the lex-order
/// complement witness-collection [`Self::sorted_middle_band_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection. Independent cross-check on the witness-Vec surface
/// axis distinct from the scalar arms. Pinned by
/// `sorted_unique_middle_band_variant_agrees_with_sorted_middle_band_variants_singleton_across_every_triple`.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_middle_band_variant`] (ordering-agnostic on
/// the input axis — the underlying [`Self::count_middle_band_variants`]
/// is invariant under slice-reversal) and
/// [`Self::sorted_middle_band_variant`] (ordering-agnostic on the
/// input axis — the underlying max/min-fold pair +
/// [`Self::count_occurrences_of`] find sweep are all invariant
/// under slice-reversal) under a boolean-guarded `Option`-collapse.
/// Pinned by
/// `sorted_unique_middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_middle_band_variant(&[])
/// == None` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_middle_band_variants`] reports `0` at the empty-
/// slice short-circuit, [`Self::has_unique_middle_band_variant`]
/// returns `false` (0 != 1), and the guard collapses the projection
/// to `None` before [`Self::sorted_middle_band_variant`]'s own
/// `None`-at-empty branch is consulted.
///
/// Flat-histogram contract at cardinality `>= 2`:
/// `T::sorted_unique_middle_band_variant(<T as ClosedSet>::ALL) ==
/// None` + `T::sorted_unique_middle_band_variant(&doubled) == None`
/// — on either flat-histogram fixpoint every variant sits at BOTH
/// extremes simultaneously via the (max == min) collapse, NO
/// variant sits strictly between,
/// [`Self::count_middle_band_variants`] reports `0`,
/// [`Self::has_unique_middle_band_variant`] returns `false`, and
/// the guard collapses the projection to `None`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_middle_band_variant(&[v]) == None` for every
/// variant `v` — the target hits count `1 == max`, every non-
/// target sits at count `0 == min`; EVERY variant of [`Self::ALL`]
/// sits AT one of the two extremes, NO variant sits strictly
/// between, [`Self::count_middle_band_variants`] reports `0`, and
/// the guard collapses to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::sorted_unique_middle_band_variant([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == Some(T::ALL[1])` — the LOAD-BEARING SOLE
/// `Some(_)`-arm on the canonical fixture window. On the non-flat
/// triple `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at
/// count `1` STRICTLY between max `2` and min `0` (the SOLE strict-
/// interior inhabitant), `T::ALL[2..]` at count `0 == min`;
/// [`Self::count_middle_band_variants`] reports `1`,
/// [`Self::has_unique_middle_band_variant`] returns `true`, the
/// guard fires, and [`Self::sorted_middle_band_variant`]'s lex-
/// order sweep hits `T::ALL[1]` on the sole middle-band member.
/// LOAD-BEARING SYMMETRY against [`Self::unique_middle_band_variant`]
/// which returns `Some(T::ALL[1])` on the same fixture (the SOLE
/// strict-interior variant is uniquely identified regardless of
/// ordering — the length-1 witness collection has ordering-
/// invariant content). Pinned by
/// `sorted_unique_middle_band_variant_returns_some_alpha_1_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::sorted_middle_band_variant`] via a boolean-guarded
/// `Option`-collapse on `Option<Self>`. Cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity
/// `n` (one max/min-fold pair, one
/// [`Self::count_middle_band_variants`] filter-count sweep, and
/// one lex-order [`Iterator::find`] sweep when the guard holds;
/// the short-circuiting `if` avoids the second sweep when the
/// guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for
/// the [`Self::sorted_variants`] cache, allocation-free at the
/// return, no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_middle_band_variant`]: a `tatara-check`
/// predicate `(check-middle-band-if-unique-lex-first …)` that
/// reports "the sole strict-interior variant, in lex order, if
/// unambiguous" for a caller that prefers lex-order presentation
/// regardless of declaration-order; a Sekiban audit-trail per-
/// window witness-if-unique binding that pins the lex-order
/// middle-band witness for stability against upstream declaration-
/// order churn; an LSP hint that surfaces the SOLE middle-priority
/// enum-arm — the canonical "everyone else is either exhaustive
/// or missed" reviewer heuristic — on a Lisp-authored variant-
/// list only when the interior is unambiguous, in lex order,
/// staying silent on tied interiors; a Prometheus-style
/// `unique_middle_band_variant_lex` label with the empty-string
/// absent semantic on tied windows. Each binds to ONE typed lex-
/// order `Option<Self>`-return uniqueness-gated complement
/// aggregate on the trait — AND, by the ordering-choice-
/// irrelevance identity, TYPED PROOF that the search-order choice
/// is operationally free WHEN the underlying middle-band-
/// uniqueness bit holds.
///
/// Compounding closure: this projection CLOSES the complement arm
/// of the LEX-ORDER (set-level × `Option<Self>` × direction-
/// composition × combinator × unique-tie) row on the direction-
/// composition surface past the just-opened UNION arm
/// [`Self::sorted_unique_extremal_variant`] one COMBINATOR axis
/// over, peer to [`Self::unique_middle_band_variant`] one
/// ORDERING axis over. The remaining tile on the LEX row is the
/// intersection arm `sorted_unique_bimodal_variant(items) ->
/// Option<Self>` (returning `Some(v)` iff
/// `has_unique_bimodal_variant(items)` holds AND `v` is the lex-
/// first sole `max == min` witness), emerging as a boolean-
/// guarded lift of [`Self::sorted_bimodal_variant`] under
/// [`Self::has_unique_bimodal_variant`]. Together with the just-
/// opened union arm the LEX row will EXHAUSTIVELY CLOSE the
/// (set-level × `Option<Self>` × direction-composition ×
/// combinator × ordering × unique-tie) 3×2 face at its final
/// intersection-arm tile once the sibling `sorted_unique_bimodal_variant`
/// lands.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × statistical-aggregate ×
/// direction-composition × complement × unique-tie) corner
/// becomes a TYPED WITNESS on the ClosedSet trait rather than a
/// per-consumer inline
/// `if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variant(items) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-
/// irrelevance) the substrate proves once rather than every
/// downstream site re-proving via
/// `sorted_unique_middle_band_variant(items) == unique_middle_band_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform;
/// the (lex-order × `Option<Self>` × direction-composition ×
/// complement × unique-tie) corner was an unnamed inline
/// composition — OR silently absent because the caller shrugged
/// and used the declaration-order sibling without proof of
/// coincidence — recurring at every prospective downstream "which
/// variant is the histogram's strict interior, in lex order, if
/// unambiguous?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of
/// the two substrate primitives
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::sorted_middle_band_variant`] with the
/// `if _ { _ } else { None }` combinator on `Option<Self>`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t);
/// n <- min(t); s <- sort(names(t)[t > n & t < m]); if
/// (length(s) == 1) s[1] else NA }` — the guarded lex-order
/// strict-interior on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = maximum(values(c)), n =
/// minimum(values(c)), ties = filter(kv -> n < kv[2] < m,
/// sort(collect(c), by = kv -> kv[1])); length(ties) == 1 ?
/// Some(ties[1][1]) : Nothing end`; Python's `sorted(k for k, v
/// in collections.Counter(items).items() if
/// min(collections.Counter(items).values(), default=0) < v <
/// max(collections.Counter(items).values(), default=0))[:1]`
/// filtered by outer count-guard; Haskell's `filter (\v -> let c
/// = Map.findWithDefault 0 v hs in c > n && c < m) (sort
/// allLevels)` guarded to singleton; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min
/// (vals f)), ts (filter #(< n (val %) m) (sort ALL-LEVELS))]
/// (when (= 1 (count ts)) (first ts)))`; SQL's `SELECT variant
/// FROM t GROUP BY variant HAVING COUNT(*) > (SELECT MIN(c) …)
/// AND COUNT(*) < (SELECT MAX(c) …) ORDER BY variant LIMIT 1`
/// filtered by an outer count-guard. Translation through pleme-io
/// primitives: the projection binds through the set-level middle-
/// band uniqueness bit [`Self::has_unique_middle_band_variant`]
/// conjoined with the lex-order complement first-witness
/// [`Self::sorted_middle_band_variant`] under an `Option`-
/// collapse — no new dep, no supertrait bound (`Sized + Copy +
/// 'static` stays untouched), no allocation at the return, cost
/// inherited from the underlying aggregates with short-circuiting
/// on the guard.
fn sorted_unique_middle_band_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_middle_band_variant(items) {
<Self as ClosedSet>::sorted_middle_band_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique bimodal variant, lex-
/// first" projection — `Some(v)` iff `items` has a UNIQUE
/// intersection-band witness ([`Self::has_unique_bimodal_variant`]
/// holds) AND `v` is the sole variant of [`Self::sorted_variants`]
/// whose occurrence-count sits at BOTH [`Self::max_variant_count`]
/// AND [`Self::min_variant_count`] simultaneously, else `None`.
/// Computed as the just-lifted set-level bimodal uniqueness bit
/// [`Self::has_unique_bimodal_variant`] guarding the LEX-ORDER
/// uniformity-collapse first-witness [`Self::sorted_bimodal_variant`]
/// projection: when the guard holds the intersection witness is
/// unambiguous and lifted verbatim; when the guard falsifies the
/// projection collapses to `None`. The LEX-ORDER `Option<Self>`-
/// RETURN UNIQUE-TIE SHARPENING corner CLOSING the intersection
/// arm of the (set-level × sorted × `Option<Self>` × direction-
/// composition × combinator × unique-tie) row past the just-opened
/// UNION arm [`Self::sorted_unique_extremal_variant`] AND the just-
/// closed COMPLEMENT arm [`Self::sorted_unique_middle_band_variant`]
/// one COMBINATOR axis over on the modal-aggregation matrix AND
/// EXHAUSTIVELY CLOSING the (set-level × sorted × `Option<Self>` ×
/// direction-composition × combinator × ordering × unique-tie)
/// 3×2 face at its FINAL SIXTH TILE — the (intersection, lex)
/// corner past the (union, declaration), (union, lex),
/// (complement, declaration), (complement, lex), (intersection,
/// declaration) five closers. Peer to
/// [`Self::unique_bimodal_variant`] one ORDERING axis over
/// (declaration-order → lex-order intersection first-witness-when-
/// unique) AND peer to [`Self::sorted_bimodal_variant`] one
/// UNIQUE-TIE-SHARPENING axis over (unsharpened lex-order
/// intersection first-witness → uniqueness-gated lex-order
/// intersection first-witness). Not a fresh substrate primitive on
/// the index axis — the projection emerges from a boolean
/// conjunction of the just-lifted set-level bimodal uniqueness bit
/// with the just-lifted lex-order intersection first-witness
/// projection under an `Option`-collapse when the guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variant(items) ==
/// T::unique_bimodal_variant(items)` — when the sole bimodal
/// witness is UNIQUE ([`Self::has_unique_bimodal_variant`] holds)
/// declaration-order and lex-order both walk the same `count ==
/// max && count == min` predicate over the same
/// `T::CARDINALITY`-sized variant carrier and land on THE SAME
/// SOLE bimodal variant; when the guard falsifies both projections
/// collapse to `None` through the same guard arm. The LEX peer is
/// thus IDENTICALLY equal to its declaration-order sibling on
/// every input — the search-order axis becomes provably irrelevant
/// WHEN the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_bimodal_variant_equals_unique_bimodal_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence. Sibling
/// posture to the just-lifted union + complement peers
/// [`Self::sorted_unique_extremal_variant`] +
/// [`Self::sorted_unique_middle_band_variant`] one COMBINATOR axis
/// over which pin the SAME ordering-choice-irrelevance identity
/// against [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`]: all three witness-if-
/// unique corners on the direction-composition row prove the
/// search-order axis irrelevant, so the substrate's SIX search-
/// order projections on the (union, complement, intersection) ×
/// (declaration, lex) 3×2 face of the unique-tie-sharpened
/// direction-composition row of the closed-set trait now pairwise-
/// collapse to three projections modulo the three uniqueness bits.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variant(items) ==
/// if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variant(items) }
/// else { None }` — the canonical form the body uses. Pinned by
/// `sorted_unique_bimodal_variant_equals_has_unique_bimodal_variant_gated_sorted_bimodal_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variant(items).is_some() ==
/// T::has_unique_bimodal_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level bimodal
/// uniqueness bit. Independent cross-check on the surface axis
/// distinct from the option-equality arm against
/// [`Self::unique_bimodal_variant`]. Pinned by
/// `sorted_unique_bimodal_variant_is_some_iff_has_unique_bimodal_variant_across_every_triple`.
///
/// Sorted-bimodal witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_bimodal_variant(items) == (if T::sorted_bimodal_variants(items).len() == 1 { Some(T::sorted_bimodal_variants(items)[0]) } else { None })`
/// — when `items` has a unique bimodal witness, the lex-order
/// intersection witness-collection [`Self::sorted_bimodal_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection. Independent cross-check on the witness-Vec surface
/// axis distinct from the scalar arms. Pinned by
/// `sorted_unique_bimodal_variant_agrees_with_sorted_bimodal_variants_singleton_across_every_triple`.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_bimodal_variant`] (ordering-agnostic on the
/// input axis — the underlying [`Self::count_bimodal_variants`] is
/// invariant under slice-reversal) and
/// [`Self::sorted_bimodal_variant`] (ordering-agnostic on the
/// input axis — the underlying [`Self::is_uniform`] +
/// [`Self::sorted_variants`] head projection are both invariant
/// under slice-reversal) under a boolean-guarded `Option`-collapse.
/// Pinned by
/// `sorted_unique_bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_bimodal_variant(&[])
/// == None` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_bimodal_variants`] reports `0` at the empty-slice
/// short-circuit, [`Self::has_unique_bimodal_variant`] returns
/// `false` (0 != 1), and the guard collapses the projection to
/// `None` before [`Self::sorted_bimodal_variant`]'s own `None`-at-
/// empty branch is consulted.
///
/// Flat-histogram contract at cardinality `>= 2`:
/// `T::sorted_unique_bimodal_variant(<T as ClosedSet>::ALL) ==
/// None` + `T::sorted_unique_bimodal_variant(&doubled) == None`
/// — on either flat-histogram fixpoint every variant sits at BOTH
/// extremes simultaneously via the (max == min) collapse, EVERY
/// variant of [`Self::ALL`] hits the intersection band,
/// [`Self::count_bimodal_variants`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the
/// guard collapses to `None`. LOAD-BEARING ASYMMETRY against
/// [`Self::sorted_bimodal_variant`] which returns
/// `Some(T::sorted_first())` on the same slice — the unique-tie
/// sharpening SEPARATES the unsharpened lex-order intersection
/// first-witness from THIS uniqueness-gated projection at the
/// flat-histogram fixpoint. At `T::CARDINALITY == 1` the full-set
/// slice collapses to a single variant at max == min == 1,
/// [`Self::count_bimodal_variants`] reports `1`,
/// [`Self::has_unique_bimodal_variant`] returns `true`, and the
/// guarded lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm
/// of the degenerate closer, out of reach of the cardinality-3
/// stub.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_bimodal_variant(&[v]) == None` for every
/// variant `v` — the target hits count `1 == max`, every non-
/// target sits at count `0 == min`; max != min pins a strict
/// direction split, NO variant hits both extremes simultaneously,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the
/// guard collapses to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::sorted_unique_bimodal_variant([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == None` — the canonical non-flat triple pins
/// `T::ALL[0]` at count `2 == max`, `T::ALL[1]` at count `1`,
/// `T::ALL[2..]` at count `0 == min`; max != min pins a strict
/// direction split, NO variant hits both extremes,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the
/// guard collapses to `None`. LOAD-BEARING DISCRIMINATOR from
/// [`Self::sorted_unique_middle_band_variant`] which reports
/// `Some(T::ALL[1])` on the same fixture — the direction-
/// composition axis SEPARATES this INTERSECTION degenerate arm
/// from the COMPLEMENT positive arm on the shared canonical
/// fixture window at cardinality >= 3.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_bimodal_variant`] +
/// [`Self::sorted_bimodal_variant`] via a boolean-guarded
/// `Option`-collapse on `Option<Self>`. Cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity
/// `n` (one [`Self::is_uniform`] max/min-fold pair, one
/// [`Self::count_bimodal_variants`] arithmetic reduction, and one
/// lex-order head projection via [`Self::sorted_variants`] when
/// the guard holds; the short-circuiting `if` avoids the head
/// projection when the guard falsifies) + `O(T::CARDINALITY log
/// T::CARDINALITY)` for the [`Self::sorted_variants`] cache,
/// allocation-free at the return, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_bimodal_variant`]: a `tatara-check`
/// predicate `(check-bimodal-if-unique-lex-first …)` that reports
/// "the sole variant that sits at BOTH histogram extremes
/// simultaneously, in lex order, if unambiguous" for a caller
/// that prefers lex-order presentation regardless of declaration-
/// order; a Sekiban audit-trail per-window witness-if-unique
/// binding that pins the lex-order intersection witness for
/// stability against upstream declaration-order churn; an LSP
/// hint that surfaces the SOLE flat-diagonal enum-arm on a Lisp-
/// authored variant-list only when the intersection is
/// unambiguous, in lex order, staying silent on tied intersections;
/// a Prometheus-style `unique_bimodal_variant_lex` label with the
/// empty-string absent semantic on tied windows. Each binds to
/// ONE typed lex-order `Option<Self>`-return uniqueness-gated
/// intersection aggregate on the trait — AND, by the ordering-
/// choice-irrelevance identity, TYPED PROOF that the search-
/// order choice is operationally free WHEN the underlying bimodal-
/// uniqueness bit holds.
///
/// Compounding closure: this projection CLOSES the intersection
/// arm of the LEX-ORDER (set-level × `Option<Self>` × direction-
/// composition × combinator × unique-tie) row on the direction-
/// composition surface past the just-opened UNION arm
/// [`Self::sorted_unique_extremal_variant`] AND the just-closed
/// COMPLEMENT arm [`Self::sorted_unique_middle_band_variant`] one
/// COMBINATOR axis over, peer to [`Self::unique_bimodal_variant`]
/// one ORDERING axis over. Together with the union + complement
/// arms this EXHAUSTIVELY CLOSES the (set-level × `Option<Self>` ×
/// direction-composition × combinator × ordering × unique-tie)
/// 3×2 face at its FINAL SIXTH TILE — every direction-composition
/// arm's declaration-order and lex-order first-witness-when-
/// unique projection is now a TYPED WITNESS on the ClosedSet
/// trait, pairwise-collapsed under the three ordering-choice-
/// irrelevance identities. The remaining orthogonal direction
/// for this row is the equivalence-partition surface's LEX-ORDER
/// (mult `>= 2` / `== 0` / `== 1`) trichotomy, already closed by
/// [`Self::sorted_unique_repeating_variant`],
/// [`Self::sorted_unique_missing_variant`],
/// [`Self::sorted_unique_unique_variant`].
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × statistical-aggregate ×
/// direction-composition × intersection × unique-tie) corner
/// becomes a TYPED WITNESS on the ClosedSet trait rather than a
/// per-consumer inline
/// `if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variant(items) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-
/// irrelevance) the substrate proves once rather than every
/// downstream site re-proving via
/// `sorted_unique_bimodal_variant(items) == unique_bimodal_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform;
/// the (lex-order × `Option<Self>` × direction-composition ×
/// intersection × unique-tie) corner was an unnamed inline
/// composition — OR silently absent because the caller shrugged
/// and used the declaration-order sibling without proof of
/// coincidence — recurring at every prospective downstream "which
/// variant sits at both histogram extremes, in lex order, if
/// unambiguous?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of
/// the two substrate primitives [`Self::has_unique_bimodal_variant`]
/// + [`Self::sorted_bimodal_variant`] with the `if _ { _ } else
/// { None }` combinator on `Option<Self>`, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t);
/// n <- min(t); s <- sort(names(t)[t == m & t == n]); if
/// (length(s) == 1) s[1] else NA }` — the guarded lex-order
/// intersection on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = maximum(values(c)), n =
/// minimum(values(c)), ties = filter(kv -> kv[2] == m && kv[2]
/// == n, sort(collect(c), by = kv -> kv[1])); length(ties) == 1
/// ? Some(ties[1][1]) : Nothing end`; Python's `sorted(k for k,
/// v in collections.Counter(items).items() if v ==
/// max(collections.Counter(items).values(), default=0) and v ==
/// min(collections.Counter(items).values(), default=0))[:1]`
/// filtered by outer count-guard; Haskell's `filter (\v -> let c
/// = Map.findWithDefault 0 v hs in c == m && c == n) (sort
/// allLevels)` guarded to singleton; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min
/// (vals f)), ts (filter #(and (= (val %) m) (= (val %) n))
/// (sort ALL-LEVELS))] (when (= 1 (count ts)) (first ts)))`;
/// SQL's `SELECT variant FROM t GROUP BY variant HAVING COUNT(*)
/// = (SELECT MAX(c) …) AND COUNT(*) = (SELECT MIN(c) …) ORDER BY
/// variant LIMIT 1` filtered by an outer count-guard. Translation
/// through pleme-io primitives: the projection binds through the
/// set-level bimodal uniqueness bit
/// [`Self::has_unique_bimodal_variant`] conjoined with the lex-
/// order intersection first-witness [`Self::sorted_bimodal_variant`]
/// under an `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation at
/// the return, cost inherited from the underlying aggregates with
/// short-circuiting on the guard.
fn sorted_unique_bimodal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_bimodal_variant(items) {
<Self as ClosedSet>::sorted_bimodal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "target is AT EITHER histogram
/// extreme" per-target predicate — `true` iff `target` sits on the
/// modal (argmax) band OR the antimodal (argmin) band of the per-
/// variant occurrence histogram over `items`, computed as the
/// DIRECTION-AGNOSTIC UNION of the just-lifted per-target argmax
/// membership predicate [`Self::is_modal_variant_of`] with the
/// just-lifted per-target argmin membership predicate
/// [`Self::is_antimodal_variant_of`] under `||`. The BOOL-RETURN
/// DIRECTION-AGNOSTIC UNION OPENER on the (per-target × bool ×
/// statistical-aggregate × direction-agnostic × union) corner
/// OPENING the (per-target × bool × statistical-aggregate ×
/// direction-composition) column past the four (per-target × bool ×
/// statistical-aggregate × direction × unsharpened/unique-tie)
/// direction-anchored corners ([`Self::is_modal_variant_of`],
/// [`Self::is_antimodal_variant_of`], [`Self::is_unique_modal_variant_of`],
/// [`Self::is_unique_antimodal_variant_of`]) one DIRECTION-
/// COMPOSITION axis over on the modal-aggregation matrix. Not a
/// fresh substrate primitive on the index axis — the predicate
/// emerges from ONE boolean disjunction of the two direction-
/// anchored per-target argmax/argmin membership predicates,
/// equivalently the non-emptiness-guarded disjunction test of the
/// just-lifted [`Self::count_occurrences_of`] scalar against
/// EITHER [`Self::max_variant_count`] OR [`Self::min_variant_count`].
///
/// Direction-union identity: for every slice `items` and every
/// target `v`,
/// `T::is_extremal_variant_of(v, items) == (T::is_modal_variant_of(v, items) || T::is_antimodal_variant_of(v, items))`
/// — the per-target direction-agnostic union predicate is EXACTLY
/// the boolean disjunction of the argmax membership predicate with
/// the argmin membership predicate. The canonical form the body
/// uses. Pinned by
/// `is_extremal_variant_of_equals_is_modal_or_antimodal_variant_of_across_every_target_and_triple`.
///
/// Count-band identity: for every NON-EMPTY slice `items` and every
/// target `v`,
/// `T::is_extremal_variant_of(v, items) == (T::count_occurrences_of(v, items) == T::max_variant_count(items) || T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// — the per-target bool predicate is EXACTLY the strict-equality
/// disjunction of the per-target multiplicity primitive against the
/// modal-count aggregate OR the antimodal-count aggregate. Sibling
/// posture to the count-composition identities of the two direction-
/// anchored siblings one DIRECTION-COMPOSITION axis over: each
/// direction sibling tests strict-equality against ONE aggregate
/// endpoint; THIS union predicate tests strict-equality against
/// EITHER endpoint under `||`. Pinned by
/// `is_extremal_variant_of_holds_iff_count_equals_max_or_min_on_non_empty_across_every_target_and_triple`.
///
/// Existential-over-directions identity: for every slice `items` and
/// every target `v`,
/// `T::is_extremal_variant_of(v, items) == !items.is_empty() && (T::antimodal_variants(items).contains(&v) || T::modal_variants(items).contains(&v))`
/// — the per-target union predicate is EXACTLY the non-emptiness-
/// guarded disjunction of the target's membership in either
/// direction's witness-collection. Independent cross-check distinct
/// from the count-band arm on the surface axis (Vec-membership vs
/// scalar-equality disjunction); pinned by
/// `is_extremal_variant_of_agrees_with_modal_or_antimodal_variants_membership_across_every_target_and_triple`.
///
/// Uniformity-collapse identity: for every NON-EMPTY slice `items`
/// on which [`Self::is_uniform`] holds (i.e. every present variant
/// shares one common per-variant count),
/// `T::is_extremal_variant_of(v, items) == true` UNCONDITIONALLY at
/// every target `v` — the direction axis on flat-histogram slices
/// COLLAPSES (`max == min`), so `count(v) == max iff count(v) ==
/// min`, both direction arms coincide bit-for-bit, and the `||`
/// disjunction lifts through the flat-histogram fixpoint verbatim.
/// Sibling posture to the flat-histogram fixpoints of
/// [`Self::is_modal_variant_of`] and [`Self::is_antimodal_variant_of`]
/// one DIRECTION-COMPOSITION axis over: each direction sibling
/// reports `true` at every target on the flat histogram; THIS union
/// predicate inherits the `true` fixpoint verbatim. Pinned by
/// `is_extremal_variant_of_returns_true_at_every_target_on_every_uniform_non_empty_slice_across_every_triple`.
///
/// De Morgan identity: for every slice `items` and every target `v`,
/// `!T::is_extremal_variant_of(v, items) == (!T::is_modal_variant_of(v, items) && !T::is_antimodal_variant_of(v, items))`
/// — the negation of the direction-agnostic union predicate is
/// EXACTLY the conjunction of the negations of the two direction-
/// anchored predicates. Equivalently: `target` is a MIDDLE-BAND
/// variant of `items` iff its per-variant count sits STRICTLY
/// BETWEEN [`Self::min_variant_count`] and [`Self::max_variant_count`],
/// i.e. `min < count(target) < max`, which requires
/// [`Self::variant_count_span`] `>= 2` (the two direction endpoints
/// bracket a strictly-interior band). Pinned by
/// `not_is_extremal_variant_of_agrees_with_de_morgan_conjunction_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`]
/// (both ordering-agnostic — each factors through
/// [`Self::count_occurrences_of`] + one direction-anchored
/// aggregate, all invariant under slice-reversal) via a boolean
/// disjunction. No separate `sorted_is_extremal_variant_of` peer is
/// needed. Pinned by
/// `is_extremal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_extremal_variant_of(v, &[])` is
/// `false` for every target `v` UNCONDITIONALLY — the empty slice
/// hits zero positions, both direction-anchored predicates collapse
/// to `false` at every target via their shared non-emptiness guards
/// on [`Self::is_modal_variant_of`] and
/// [`Self::is_antimodal_variant_of`], and the disjunction lands on
/// `false` at every target through both arms. Sibling posture to
/// the empty-slice fixpoints of the two direction siblings one
/// DIRECTION-COMPOSITION axis over: both directions inherit their
/// `false`-at-empty guard; THIS union predicate inherits both
/// guards under `||`. Pinned by
/// `is_extremal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_extremal_variant_of(v, &[v]) == true` for every variant
/// `v` — the sole position hits the target with count `1 == max`,
/// [`Self::is_modal_variant_of`] reports `true` at the target on
/// the argmax band, and the disjunction lands on `true` through the
/// argmax arm regardless of the argmin arm's `false` value (at
/// `count(v) == 1 != min == 0`). LOAD-BEARING `true` fixpoint on
/// the target itself. Pinned by
/// `is_extremal_variant_of_returns_true_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_extremal_variant_of(v, &[w]) == true` for every target
/// `v` and slice-element `w` with `T::index_of(v) != T::index_of(w)`
/// — the sole position hits `w`, not `v`; the target's count is `0
/// == min`, [`Self::is_antimodal_variant_of`] reports `true` at the
/// non-matching target on the argmin band, and the disjunction lands
/// on `true` through the argmin arm regardless of the argmax arm's
/// `false` value (at `count(v) == 0 != max == 1`). Together with
/// the matching-singleton arm, pins THIS predicate at `true` at
/// EVERY target on EVERY singleton at cardinality `>= 2` — the
/// singleton's histogram has only two bands (max `1`, min `0`) with
/// no middle inhabitant, so every target satisfies one direction
/// arm. Pinned by
/// `is_extremal_variant_of_returns_true_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_extremal_variant_of(v, <T as ClosedSet>::ALL) == true` for
/// every target `v` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant appears at
/// EXACTLY ONE position of the full-set slice, every per-variant
/// count is `1`, [`Self::max_variant_count`] and
/// [`Self::min_variant_count`] both collapse to `1`, both direction-
/// anchored predicates report `true` at every target on the flat-
/// histogram fixpoint, and the disjunction inherits the `true`
/// fixpoint verbatim. Direct instance of the uniformity-collapse
/// identity above. Pinned by
/// `is_extremal_variant_of_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_extremal_variant_of(v, &doubled) == true` for every target
/// `v` UNCONDITIONALLY — the doubled full set hits every variant at
/// EXACTLY TWO positions, [`Self::max_variant_count`] and
/// [`Self::min_variant_count`] both collapse to `2`, both direction-
/// anchored predicates report `true` at every target, and the
/// disjunction inherits the `true` fixpoint. Together with the
/// full-set arm, the doubled-full-set arm pins THIS predicate as
/// INVARIANT under uniform slice-multiplication on flat-histogram
/// slices AT `true` at cardinality `>= 2`. Pinned by
/// `is_extremal_variant_of_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Middle-band (min < count < max) fixture at [`Self::CARDINALITY`]
/// `>= 3`: the slice `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits
/// `T::ALL[0]` at count `2 == max`, `T::ALL[1]` at count `1`
/// (MIDDLE), and `T::ALL[2]` at count `0 == min`.
/// [`Self::is_modal_variant_of`] reports `true` at `T::ALL[0]`
/// and `false` at every other target; [`Self::is_antimodal_variant_of`]
/// reports `true` at `T::ALL[2]` and `false` at every other target;
/// the disjunction lands on `true` at `T::ALL[0]` (argmax), `false`
/// at `T::ALL[1]` (MIDDLE — the LOAD-BEARING `false` at a non-empty
/// fixpoint), and `true` at `T::ALL[2]` (argmin). LOAD-BEARING
/// ASYMMETRY against the uniformity-collapse identity — every other
/// canonical fixpoint pins THIS predicate at `true` on non-empty
/// slices at cardinality `>= 2`, so an override that folds onto
/// `true` unconditionally silently passes every OTHER non-empty
/// fixpoint arm but bifurcates HERE loudly at
/// `T::ALL[1]` in the middle band. Pinned by
/// `is_extremal_variant_of_returns_false_at_middle_band_target_on_the_bimodal_triple_at_cardinality_ge_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`]
/// via a boolean disjunction on `bool`. The sweep cost inherits
/// both primitives: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one [`Self::count_occurrences_of`]
/// fold at the target on the argmax arm; on `false`-at-argmax the
/// argmin arm adds one [`Self::min_variant_count`] fold + one
/// [`Self::count_occurrences_of`] re-fold; the short-circuiting
/// `||` avoids the second aggregate when the argmax arm holds),
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched).
///
/// Future consumers that compose against
/// [`Self::is_extremal_variant_of`]: a `tatara-check` predicate
/// `(check-target-is-at-histogram-extreme …)` that reports "the
/// target variant sits at EITHER end of the rollout histogram" in
/// ONE typed bool rather than a two-step `(is-modal? or is-anti?)`
/// composition; a Sekiban audit-trail per-target extremity bit
/// binding the direction-agnostic union scalar per window,
/// composable with the just-lifted argmax/argmin bits into a typed
/// 3-bool `(is-modal, is-antimodal, is-extremal)` classifier per
/// window whose triple `(true, true, true)` witnesses flat-histogram
/// membership at the target and `(false, false, false)` witnesses
/// non-emptiness plus middle-band membership; a scheduler-fairness
/// heuristic that reports "is worker X at either extreme of the
/// load spectrum?" as a per-worker bool without paying the two
/// direction-witness Vec allocations; an LSP diagnostic on a Lisp-
/// authored closed-set field that flags a specific expected variant
/// as "currently non-central" without materializing either
/// direction's witness-collection; a Prometheus-style
/// `at_histogram_extreme` gauge that fires on every non-central
/// variant of a rollout window. Each binds to ONE typed per-target
/// bool predicate on the trait rather than re-deriving
/// `T::is_modal_variant_of(v, items) || T::is_antimodal_variant_of(v, items)`
/// inline per callsite OR paying the two Vec allocations
/// `T::modal_variants(items).contains(&v) || T::antimodal_variants(items).contains(&v)`
/// would demand.
///
/// Compounding closure: this projection OPENS the (per-target ×
/// bool × statistical-aggregate × direction-composition) column at
/// its FIRST corner past the four direction-anchored per-target
/// bool predicates one DIRECTION-COMPOSITION axis over. The
/// (direction-composition × combinator) grid on the per-target
/// bool row now opens its DISJUNCTION arm — the natural next lifts
/// past this opening are:
/// * `is_bimodal_variant_of(v, items) == is_modal_variant_of(v,
/// items) && is_antimodal_variant_of(v, items)` — the CONJUNCTION
/// arm, closing the (per-target × bool × direction-composition)
/// 2-corner face at its `&&` arm past THIS `||` opener; equivalent
/// to "target sits on the flat-histogram diagonal" via the
/// uniformity-collapse identity.
/// * `count_extremal_variants(items) -> usize` — the set-level
/// arity-lift of THIS per-target predicate via
/// `T::ALL.iter().filter(|&v| is_extremal_variant_of(v, items)).count()`,
/// opening the (set-level × usize × direction-agnostic × union)
/// corner one ARITY axis over.
/// * `is_middle_band_variant_of(v, items) == !is_extremal_variant_of(v, items) && !items.is_empty()`
/// — the direct COMPLEMENT of THIS predicate on non-empty slices,
/// opening the middle-band membership corner as a typed
/// consequence of the De Morgan identity above.
///
/// Each remaining corner emerges as a boolean combinator applied to
/// the two just-lifted direction-anchored per-target predicates
/// [`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`],
/// so the (per-target × bool × direction-composition) column fills
/// with no fresh substrate primitives on the index axis.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target direction-agnostic extremity predicate becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline `T::is_modal_variant_of(v, items) || T::is_antimodal_variant_of(v, items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × direction-agnostic
/// × union) corner was an unnamed inline composition recurring at
/// every prospective downstream "is this target at ANY histogram
/// extreme?" site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the two just-lifted direction-
/// anchored membership predicates under a boolean disjunction.
/// THEORY.md §VI.1 — generation over composition; the predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`])
/// with the `||` combinator on `bool`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `let t <- table(items); t[v] ==
/// max(t) || t[v] == min(t)` per-level extremity test on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items), m =
/// maximum(values(c)), n = minimum(values(c)); c[v] == m || c[v]
/// == n end` on a `Dict{Element, Int}` histogram; Python's `let c
/// = collections.Counter(items); c[v] in (max(c.values()),
/// min(c.values()))` on a Counter; Haskell's `let hs = map length
/// . group . sort $ items, m = maximum hs, n = minimum hs in count
/// v items == m || count v items == n`; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min (vals
/// f))] (or (= (get f v 0) m) (= (get f v 0) n)))`; Coq's per-
/// target `orb (Nat.eqb (List.count_occ eqb l v) (max_count l))
/// (Nat.eqb (List.count_occ eqb l v) (min_count l))` on a
/// decidable-equality carrier; SQL's `SELECT variant FROM t GROUP
/// BY variant HAVING COUNT(*) IN (SELECT MAX(c) FROM …, SELECT
/// MIN(c) FROM …)`. Translation through pleme-io primitives: the
/// N-ary per-target direction-agnostic extremity predicate on the
/// closed-set trait binds through the two just-lifted direction-
/// anchored membership predicates under a boolean disjunction — no
/// new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the argmax arm. One pleme-io-specific asymmetry
/// against the direction siblings: the union corner has a NON-
/// TRIVIAL `false`-fixpoint OUTSIDE the empty slice — the middle-
/// band fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality
/// `>= 3` pins the projection at `false` at target `T::ALL[1]`
/// (which sits at count `1`, strictly between `max == 2` and `min
/// == 0`), a fixpoint neither direction sibling isolates on its own
/// (each direction sibling reports `false` at TWO of the three
/// targets on the same slice; only the union's middle-band `false`
/// isolates the LOAD-BEARING drift catch against `_ => true`).
fn is_extremal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_modal_variant_of(target, items)
|| <Self as ClosedSet>::is_antimodal_variant_of(target, items)
}
/// The N-ARY ORDERING-AGNOSTIC "target at BOTH histogram extremes?"
/// predicate — `true` iff `target`'s per-slot count in `items` equals
/// BOTH [`Self::max_variant_count`] AND [`Self::min_variant_count`]
/// simultaneously, computed as the boolean CONJUNCTION of
/// [`Self::is_modal_variant_of`] and [`Self::is_antimodal_variant_of`].
/// The BOOL-RETURN closer on the (per-target × bool × statistical-
/// aggregate × direction-composition × combinator) 2-corner face at
/// its `&&` CONJUNCTION arm past the just-opened `||` DISJUNCTION arm
/// [`Self::is_extremal_variant_of`] one COMBINATOR axis over, AND the
/// per-target × flat-histogram-diagonal witness on the (per-target ×
/// bool × statistical-aggregate × direction-composition) column. Not
/// a fresh substrate primitive on the index axis — the predicate
/// emerges from ONE boolean AND on the two just-lifted direction-
/// anchored membership predicates, equivalently the count-band
/// coincidence identity `count(target, items) ==
/// max_variant_count(items) == min_variant_count(items)` on non-empty
/// slices (where the max/min bands COINCIDE on the flat-histogram
/// diagonal at target).
///
/// Direction-conjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_bimodal_variant_of(v, items) == (T::is_modal_variant_of(v, items) && T::is_antimodal_variant_of(v, items))`
/// — the canonical body. Pinned by clause (142) and by
/// `is_bimodal_variant_of_equals_is_modal_and_antimodal_variant_of_across_every_target_and_triple`.
///
/// Count-band coincidence identity: for every NON-EMPTY slice `items`
/// and every target `v`, `T::is_bimodal_variant_of(v, items) ==
/// (T::count_occurrences_of(v, items) == T::max_variant_count(items)
/// && T::count_occurrences_of(v, items) == T::min_variant_count(items))`
/// — the projection agrees with the count-band coincidence test on
/// non-empty slices. Independent cross-check distinct from the
/// direction-conjunction arm on the composition axis. Pinned by
/// `is_bimodal_variant_of_holds_iff_count_equals_max_and_min_on_non_empty_across_every_target_and_triple`.
///
/// Uniformity-collapse identity: for every NON-EMPTY slice `items`
/// and every target `v`, `T::is_bimodal_variant_of(v, items) ==
/// T::is_uniform(items)` — the projection reports `true` at every
/// target on any non-empty slice where the max-count and min-count
/// bands coincide (equivalently, [`Self::is_uniform`] holds), and
/// `false` at every target otherwise. The predicate is independent
/// of `target` on non-empty slices — a witness for the flat-
/// histogram diagonal that a per-target membership predicate reduces
/// to a set-level scalar via [`Self::is_uniform`]. Sibling posture
/// to [`Self::is_extremal_variant_of`]'s uniformity-collapse arm one
/// COMBINATOR axis over: the DISJUNCTION arm reports `true` at every
/// target on flat-histogram slices AND at EVERY direction-endpoint
/// target on non-flat slices; the CONJUNCTION arm reports `true` at
/// every target ONLY on flat-histogram slices, collapsing every non-
/// flat slice to `false` at every target. Pinned by
/// `is_bimodal_variant_of_holds_at_every_target_iff_slice_is_uniform_across_every_triple`.
///
/// De Morgan identity: for every slice `items` and every target `v`,
/// `!T::is_bimodal_variant_of(v, items) == (!T::is_modal_variant_of(v, items) || !T::is_antimodal_variant_of(v, items))`
/// — the boolean NEGATION of the conjunction agrees with the
/// disjunction of negations, the canonical De Morgan surface. Pinned
/// by `not_is_bimodal_variant_of_agrees_with_de_morgan_disjunction_across_every_target_and_triple`.
///
/// Union-implication identity: for every slice `items` and every
/// target `v`, `T::is_bimodal_variant_of(v, items) ==>
/// T::is_extremal_variant_of(v, items)` — the CONJUNCTION corner is
/// a REFINEMENT of the DISJUNCTION corner (every target at both
/// extremes is trivially at some extreme). The reverse implication
/// fails on any non-flat slice at a direction-endpoint target (which
/// sits at ONE extreme but not the other). Pinned by
/// `is_bimodal_variant_of_implies_is_extremal_variant_of_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — it factors through two ordering-agnostic
/// direction-anchored membership predicates joined under boolean
/// conjunction. No separate `sorted_is_bimodal_variant_of` peer is
/// needed. Pinned by
/// `is_bimodal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_bimodal_variant_of(v, &[])` is
/// `false` UNCONDITIONALLY at every target — both direction siblings
/// collapse to `false` on the empty slice via their shared non-
/// emptiness guards, and the conjunction lands on `false` at every
/// target through both arms. Sibling posture to
/// [`Self::is_extremal_variant_of`]'s empty-slice fixpoint one
/// COMBINATOR axis over. Pinned by clause (142) and by
/// `is_bimodal_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::is_bimodal_variant_of(v, &[v]) == false` for every variant
/// `v` — the sole position hits the target at count `1 == max`, but
/// [`Self::CARDINALITY`]`>= 2` implies at least one non-target
/// variant sits at count `0 == min`, so
/// [`Self::is_antimodal_variant_of`] reports `false` at the target
/// (count `1 != 0 == min`), and the conjunction lands on `false`
/// through the argmin arm. LOAD-BEARING `false`-arm catch on the
/// conjunction corner separating it from the disjunction sibling
/// (which reports `true` on the same fixture through the argmax
/// arm). Pinned by
/// `is_bimodal_variant_of_returns_false_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract at cardinality `>= 2`:
/// `T::is_bimodal_variant_of(v, &[w]) == false` for every target
/// `v` and slice-element `w` with `v != w` — the sole position hits
/// `w`, so the target's count is `0 == min`, but `w`'s count is
/// `1 == max`, so [`Self::is_modal_variant_of`] reports `false` at
/// the target (count `0 != 1 == max`), and the conjunction lands on
/// `false` through the argmax arm. LOAD-BEARING `false`-arm catch on
/// the conjunction corner separating it from the disjunction sibling
/// (which reports `true` on the same fixture through the argmin
/// arm). Pinned by
/// `is_bimodal_variant_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract:
/// `T::is_bimodal_variant_of(v, <T as ClosedSet>::ALL) == true` for
/// every target `v` UNCONDITIONALLY at cardinality `>= 1` — clause
/// (3)'s pairwise-distinctness invariant pins every variant at
/// exactly one position of the full-set slice,
/// [`Self::max_variant_count`] and [`Self::min_variant_count`] both
/// collapse to `1`, both direction siblings report `true` at every
/// target on the flat-histogram fixpoint, and the conjunction
/// inherits `true` verbatim. LOAD-BEARING `true`-arm catch on the
/// conjunction corner. Pinned by
/// `is_bimodal_variant_of_returns_true_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract:
/// `T::is_bimodal_variant_of(v, &doubled) == true` for every target
/// `v` — the doubled full set hits every variant at exactly two
/// positions, [`Self::max_variant_count`] and
/// [`Self::min_variant_count`] both collapse to `2`, both direction
/// siblings report `true` at every target on the second flat-
/// histogram fixpoint, and the conjunction inherits `true` verbatim.
/// Pinned by
/// `is_bimodal_variant_of_returns_true_on_the_doubled_full_set_across_every_target`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2] ->
/// 0 == min)`. `T::is_bimodal_variant_of(v, &bimodal_triple)` returns
/// `false` at EVERY target `v` — the argmax-endpoint target sits at
/// `2 != 0`, the middle-band target sits at `1 != 2` and `1 != 0`,
/// the argmin-endpoint target sits at `0 != 2`. LOAD-BEARING all-
/// `false`-arm catch on the bimodal-triple fixture that separates
/// this corner from [`Self::is_extremal_variant_of`] (which reports
/// `true` at both direction endpoints) one COMBINATOR axis over.
/// Pinned by
/// `is_bimodal_variant_of_returns_false_at_every_target_on_the_bimodal_triple_at_cardinality_ge_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the two
/// direction-anchored per-target membership predicates
/// [`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`]
/// joined under boolean conjunction. The composition uses one `&&`
/// on `bool`, so the sweep inherits the O(T::CARDINALITY * n) cost
/// of the direction siblings on slice arity `n` with short-
/// circuiting on the argmax arm — allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::is_bimodal_variant_of`]: a `tatara-check` predicate
/// `(check-target-at-flat-diagonal …)` that reports whether a target
/// `WorkloadPhase` sits at the flat-histogram diagonal across a
/// rollout window (a witness that the target has the same
/// multiplicity as EVERY other phase — the phase-histogram is flat
/// AND the target participates) without paying for the min/max fold
/// separately at every callsite; an LSP diagnostic on a Lisp-author-
/// written variant-list that flags "target sits on the histogram
/// diagonal" as a witness the author's frequency-balanced
/// enumeration holds at THIS target; a Sekiban audit-trail per-
/// target diagonal-participation gauge alongside the sibling union-
/// membership gauge (a downstream consumer would read
/// `bimodal_at_target` as "the flat-histogram invariant holds at
/// this target" AND `extremal_at_target` as "the target sits at some
/// extreme"); a `tatara-lisp::macro_expand::Expander` hygiene pass
/// that flags a template's identifier multiset as "this identifier
/// participates in the flat-histogram diagonal" (a common
/// balancing-check shape) in ONE typed bool rather than an inline
/// `T::is_modal_variant_of(v, items) && T::is_antimodal_variant_of(v, items)`
/// conjunction. Each binds to ONE typed N-ary per-target flat-
/// diagonal predicate on the trait rather than re-deriving the
/// conjunction inline per callsite.
///
/// Compounding closure: the (per-target × bool × statistical-
/// aggregate × direction-composition × combinator) 2-corner face on
/// the modal-aggregation matrix now CLOSES at its CONJUNCTION arm
/// past the just-opened `||` DISJUNCTION arm [`Self::is_extremal_variant_of`]
/// one COMBINATOR axis over. The (per-target × bool × direction-
/// composition) column now carries THREE typed predicates aligned
/// against the two direction-anchored membership predicates:
/// (a) [`Self::is_extremal_variant_of`] — DISJUNCTION (`||`, some
/// extreme); (b) [`Self::is_bimodal_variant_of`] — CONJUNCTION
/// (`&&`, both extremes); with (c) an implicit "neither extreme"
/// (NOR arm) obtainable as `!T::is_extremal_variant_of(v, items)`
/// without a fresh substrate primitive (the trivial complement).
/// The natural next lifts past this closure are:
/// * `count_extremal_variants(items) -> usize` — the set-level
/// arity-lift of [`Self::is_extremal_variant_of`] via
/// `T::ALL.iter().filter(|&v| is_extremal_variant_of(v, items)).count()`,
/// opening the (set-level × usize × direction-agnostic × union)
/// corner one ARITY axis over.
/// * `count_bimodal_variants(items) -> usize` — the set-level
/// arity-lift of THIS per-target predicate via
/// `T::ALL.iter().filter(|&v| is_bimodal_variant_of(v, items)).count()`,
/// opening the (set-level × usize × direction-agnostic ×
/// intersection) corner one ARITY axis over. On non-empty slices
/// this collapses to `T::CARDINALITY` when [`Self::is_uniform`]
/// holds and to `0` otherwise via the uniformity-collapse
/// identity — a candidate for further sharpening past the naive
/// filter-count into a scalar branch on [`Self::is_uniform`].
/// * `is_middle_band_variant_of(v, items) == !is_extremal_variant_of(v, items) && !items.is_empty()`
/// — the direct COMPLEMENT of [`Self::is_extremal_variant_of`] on
/// non-empty slices, opening the middle-band membership corner as
/// a typed consequence of the De Morgan identity.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target flat-diagonal membership predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::is_modal_variant_of(v, items) && T::is_antimodal_variant_of(v, items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × direction-agnostic ×
/// intersection) corner was an unnamed inline composition recurring
/// at every prospective downstream "is this target at BOTH histogram
/// extremes?" site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the two direction-anchored
/// membership predicates under a boolean conjunction. THEORY.md
/// §VI.1 — generation over composition; the predicate emerges from
/// the composition of TWO substrate primitives
/// ([`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`])
/// with the `&&` combinator on `bool`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `let t <- table(items); t[v] ==
/// max(t) && t[v] == min(t)` per-level flat-diagonal test on a
/// factor histogram; Julia's `let c = StatsBase.countmap(items),
/// m = maximum(values(c)), n = minimum(values(c)); c[v] == m &&
/// c[v] == n end` on a `Dict{Element, Int}` histogram; Python's
/// `let c = collections.Counter(items); c[v] == max(c.values()) ==
/// min(c.values())` on a Counter (chained equality is the canonical
/// idiom); Haskell's `let hs = map length . group . sort $ items,
/// m = maximum hs, n = minimum hs in count v items == m && count v
/// items == n`; Clojure's `(let [f (frequencies coll), m (apply
/// max (vals f)), n (apply min (vals f))] (and (= (get f v 0) m)
/// (= (get f v 0) n)))`; Coq's per-target `andb (Nat.eqb
/// (List.count_occ eqb l v) (max_count l)) (Nat.eqb
/// (List.count_occ eqb l v) (min_count l))` on a decidable-equality
/// carrier; SQL's `SELECT variant FROM t GROUP BY variant HAVING
/// COUNT(*) = (SELECT MAX(c) FROM …) AND COUNT(*) = (SELECT MIN(c)
/// FROM …)`. Translation through pleme-io primitives: the N-ary
/// per-target direction-agnostic flat-diagonal predicate on the
/// closed-set trait binds through the two just-lifted direction-
/// anchored membership predicates under a boolean conjunction — no
/// new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the argmax arm.
fn is_bimodal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_modal_variant_of(target, items)
&& <Self as ClosedSet>::is_antimodal_variant_of(target, items)
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants sit at BOTH histogram
/// extremes?" cardinality-count projection — the `usize` SET-LEVEL
/// count of variants of [`Self::ALL`] for which
/// [`Self::is_bimodal_variant_of`] holds against `items`, SHARPENED past
/// the naive filter-count reduction over the per-target predicate via
/// the uniformity-collapse identity: on non-empty slices EVERY variant
/// satisfies the flat-diagonal predicate iff [`Self::is_uniform`] holds
/// (max == min), so the count collapses to [`Self::CARDINALITY`] on
/// flat-histogram non-empty slices and to `0` on every non-flat non-
/// empty slice AND on the empty slice. The USIZE-RETURN CLOSER on the
/// (set-level × usize × statistical-aggregate × direction-composition ×
/// combinator) 2-corner face at its `&&` CONJUNCTION arm one COMBINATOR
/// axis over from a prospective disjunction sibling
/// `count_extremal_variants`, AND the direct SET-LEVEL ARITY LIFT of
/// the just-lifted (per-target × bool × statistical-aggregate ×
/// direction-composition × intersection) [`Self::is_bimodal_variant_of`]
/// corner one ARITY axis over on the modal-aggregation matrix, AND peer
/// to [`Self::count_modal_variants`] one DIRECTION-COMPOSITION axis over
/// on the (set-level × usize × statistical-aggregate) cardinality-count
/// row (`count_modal_variants` — argmax filter-count; THIS —
/// intersection scalar branch). Not a fresh substrate primitive on the
/// index axis — the count emerges from one `is_empty()`-guarded scalar
/// branch on the just-lifted [`Self::is_uniform`] projection, returning
/// [`Self::CARDINALITY`] on flat-histogram non-empty slices and `0`
/// otherwise. The sharpening replaces the naive `T::ALL.iter().filter(
/// |&v| T::is_bimodal_variant_of(v, items)).count()` sweep
/// (`O(T::CARDINALITY² * n)` — the per-target predicate itself costs
/// `O(T::CARDINALITY * n)`) with a single [`Self::is_uniform`] sweep
/// (`O(T::CARDINALITY * n)`), inheriting the max/min-fold cost of the
/// underlying aggregate exactly once.
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::count_bimodal_variants(items) == if items.is_empty() { 0 } else if T::is_uniform(items) { T::CARDINALITY } else { 0 }`
/// — the canonical body. The per-target flat-diagonal predicate reports
/// `true` at EVERY target on a non-empty flat-histogram slice AND at NO
/// target on any non-flat slice, so the arity-lift's cardinality is
/// either the full closed-set count or zero. Pinned by clause (143) and
/// by `count_bimodal_variants_agrees_with_uniformity_collapse_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_bimodal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v, items)).count()`
/// — the sharpened scalar-branch body agrees with the naive filter-
/// count reduction over [`Self::ALL`] of the per-target predicate.
/// Independent cross-check distinct from the uniformity-collapse arm on
/// the compilation-shape (scalar branch vs iterator sweep) axis. Pinned
/// by `count_bimodal_variants_equals_filter_count_of_is_bimodal_variant_of_across_every_triple`.
///
/// Length-composition identity (through the intersection Vec sibling):
/// on the arity-lift face the scalar cardinality collapses to `0` or
/// [`Self::CARDINALITY`] verbatim; downstream consumers that only need
/// the cardinality (an LSP diagnostic hint that renders "N variants sit
/// on the flat diagonal", a Sekiban `bimodal_tie_count` gauge, a
/// `tatara-check` predicate that dispatches on "does EVERY variant sit
/// on the diagonal?") pay a single scalar comparison rather than
/// materializing the intersection witness. Sibling posture to
/// [`Self::count_modal_variants`]'s length-composition arm one
/// COMBINATOR axis over.
///
/// Union-refinement identity: for every slice `items`,
/// `T::count_bimodal_variants(items) <= T::CARDINALITY` AND on non-empty
/// slices `T::count_bimodal_variants(items) == T::CARDINALITY` iff
/// `T::count_bimodal_variants(items) == T::count_modal_variants(items)`
/// (equivalently, [`Self::is_uniform`] holds). The intersection
/// cardinality is bounded above by BOTH direction siblings'
/// cardinality-counts ([`Self::count_modal_variants`],
/// [`Self::count_antimodal_variants`]) — a witness that the corner
/// SHARPENS both direction arms simultaneously into the flat-diagonal
/// slot. Pinned by `count_bimodal_variants_is_bounded_above_by_count_modal_variants_across_every_triple`.
///
/// Two-value dichotomy identity: for every slice `items`,
/// `T::count_bimodal_variants(items) ∈ {0, T::CARDINALITY}` — the
/// arity-lift's image is the two-point set: zero on every non-flat
/// slice AND on the empty slice, [`Self::CARDINALITY`] on every non-
/// empty flat-histogram slice. No intermediate values are reachable,
/// distinguishing this projection from the direction-anchored
/// [`Self::count_modal_variants`] / [`Self::count_antimodal_variants`]
/// pair which span the full `[0, T::CARDINALITY]` range. Pinned by
/// `count_bimodal_variants_lands_in_the_two_value_dichotomy_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_uniform`] (ordering-agnostic) via a scalar branch. No
/// separate `sorted_count_bimodal_variants` peer is needed. Pinned by
/// `count_bimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::count_bimodal_variants(&[])` is `0`
/// UNCONDITIONALLY — the empty slice is the SOLE zero-arm that also
/// satisfies [`Self::is_uniform`]`(&[]) == true` under the vacuous
/// (min == max == 0) collapse, so the empty guard is LOAD-BEARING to
/// keep the count at zero at the empty endpoint (an unguarded
/// `if is_uniform(items) { T::CARDINALITY } else { 0 }` body would
/// silently return [`Self::CARDINALITY`] on `&[]` past the vacuous
/// flat-histogram arm). Pinned by clause (143) and by
/// `count_bimodal_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::count_bimodal_variants(&[v])` is `0` for every variant `v` — the
/// sole position hits `v` at count `1 == max`, but every non-target
/// variant sits at count `0 == min`, so the histogram is NON-FLAT
/// (max `1` != min `0`), [`Self::is_uniform`] reports `false`, and the
/// scalar branch lands on `0`. LOAD-BEARING `0`-arm catch on the
/// intersection cardinality-count corner separating it from the argmax
/// sibling [`Self::count_modal_variants`] which reports `1` on the
/// same fixture. Pinned by
/// `count_bimodal_variants_returns_zero_on_every_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Full-set contract:
/// `T::count_bimodal_variants(<T as ClosedSet>::ALL)` is
/// [`Self::CARDINALITY`] UNCONDITIONALLY — clause (3)'s pairwise-
/// distinctness invariant pins every variant at exactly one position,
/// [`Self::max_variant_count`] and [`Self::min_variant_count`] both
/// collapse to `1`, [`Self::is_uniform`] reports `true` on the flat-
/// histogram fixpoint, and the scalar branch lands on
/// [`Self::CARDINALITY`]. LOAD-BEARING `T::CARDINALITY`-arm catch on
/// the intersection cardinality-count corner. Pinned by clause (143)
/// and by
/// `count_bimodal_variants_returns_cardinality_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_bimodal_variants(&doubled)` is [`Self::CARDINALITY`]
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// exactly two positions, [`Self::max_variant_count`] and
/// [`Self::min_variant_count`] both collapse to `2`,
/// [`Self::is_uniform`] reports `true` on the second flat-histogram
/// fixpoint, and the scalar branch lands on [`Self::CARDINALITY`].
/// Together with the full-set arm the pair demonstrates that the
/// projection is INVARIANT under uniform slice-multiplication on flat-
/// histogram slices — pinning the projection as a FLAT-DIAGONAL
/// cardinality rather than the underlying multiplicity scalar
/// [`Self::max_variant_count`] which TRANSITIONS from `1` to `2`
/// between the two flat-histogram fixpoints. Pinned by clause (143)
/// and by
/// `count_bimodal_variants_returns_cardinality_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::count_bimodal_variants(&bimodal_triple)` is `0` — the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits `T::ALL[0]` at
/// count `2 == max`, `T::ALL[1]` at count `1` (MIDDLE), `T::ALL[2]` at
/// count `0 == min`; the histogram is NON-FLAT (max `2` != min `0`),
/// [`Self::is_uniform`] reports `false`, and the scalar branch lands
/// on `0`. LOAD-BEARING `0`-arm catch on the non-flat fixture that
/// separates the intersection cardinality from a prospective
/// `count_extremal_variants` sibling (which would report `2` on the
/// same fixture — the argmax and argmin endpoints). Pinned by
/// `count_bimodal_variants_returns_zero_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_uniform`] via one `is_empty()` guard + one scalar
/// conditional. The sharpened body inherits [`Self::is_uniform`]'s
/// `O(T::CARDINALITY * n)` cost on slice arity `n` (one max/min fold
/// through the per-variant multiplicity primitive with early exit on
/// the first non-flat bar), strictly beating the naive
/// `T::ALL.iter().filter(|&v| T::is_bimodal_variant_of(v, items)).count()`
/// sweep which pays `O(T::CARDINALITY² * n)` — one per-target
/// [`Self::is_bimodal_variant_of`] call per variant, each of which
/// re-derives the max and min folds internally. Allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// histogram-shape carrier.
///
/// Future consumers that compose against
/// [`Self::count_bimodal_variants`]: a `tatara-check` predicate
/// `(check-phases-flat-diagonal-count …)` that reports how many
/// `WorkloadPhase` variants sit on the flat-histogram diagonal in a
/// rollout window — always either `0` (non-flat) or `T::CARDINALITY`
/// (flat), a two-value dispatch surface that a downstream consumer can
/// treat as "every phase visited the same number of times" without
/// re-computing the max/min pair; an LSP diagnostic on a Lisp-author-
/// written variant-list that renders "N variants sit on the flat
/// diagonal (uniform histogram)" as a typed scalar rather than
/// materializing the intersection Vec; a Sekiban audit-trail
/// `bimodal_tie_count` gauge that emits the scalar cardinality
/// alongside the direction-anchored `modal_tie_count` /
/// `antimodal_tie_count` gauges (paying no per-target sweep on the
/// hot path); a scheduler-fairness heuristic that branches on
/// `count_bimodal_variants == T::CARDINALITY` (fully balanced —
/// deploy the uniform-quota strategy) vs `== 0` (imbalanced — deploy
/// the modal-priority strategy) without materializing the full
/// intersection set. Each binds to ONE typed `usize`-return set-level
/// intersection-cardinality aggregate on the trait rather than paying
/// the `O(T::CARDINALITY² * n)` naive filter-count sweep OR
/// re-deriving the `if is_uniform { T::CARDINALITY } else { 0 }`
/// scalar branch inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level × usize ×
/// statistical-aggregate × direction-composition × combinator) 2-corner
/// cardinality-count face on the modal-aggregation matrix at its `&&`
/// CONJUNCTION arm, peer to the just-opened (per-target × bool ×
/// intersection) [`Self::is_bimodal_variant_of`] one ARITY axis over
/// AND peer to [`Self::count_modal_variants`] one DIRECTION-
/// COMPOSITION axis over. The natural next lift on the same face is
/// the DISJUNCTION arm `count_extremal_variants(items) -> usize` (the
/// set-level arity-lift of [`Self::is_extremal_variant_of`]) — that
/// corner CANNOT sharpen to a scalar branch on any existing set-level
/// primitive because its image spans the full `[0, T::CARDINALITY]`
/// range (unlike THIS corner's two-value dichotomy), so it stays as a
/// naive `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v,
/// items)).count()` filter-count sweep OR SHARPENS to
/// `T::count_modal_variants(items) + T::count_antimodal_variants(items) - T::count_bimodal_variants(items)`
/// via the inclusion-exclusion identity — a candidate compounding
/// consumer of THIS projection past the direction-anchored
/// cardinality-count pair one ARITY axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-level
/// count of flat-diagonal variants becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|&v| T::is_bimodal_variant_of(v, items)).count()`
/// composition (which itself factors through two direction-anchored
/// per-target predicates on every variant, paying `O(T::CARDINALITY² * n)`)
/// at every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (set-level × usize × intersection) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "how many variants sit on the flat diagonal?" site pre-
/// lift. Naming it on the trait AND SHARPENING it past the naive
/// filter-count via the uniformity-collapse identity makes the count a
/// TYPED CONSEQUENCE of ONE substrate primitive [`Self::is_uniform`]
/// rather than a composition of `T::CARDINALITY` per-target predicate
/// calls. THEORY.md §VI.1 — generation over composition; the sharpened
/// body emerges from the composition of ONE substrate primitive
/// ([`Self::is_uniform`]) with an `is_empty()` guard + a scalar
/// conditional on [`Self::CARDINALITY`], not as a per-implementor
/// hand-rolled body OR as a naive filter-count sweep over
/// [`Self::ALL`] of the per-target predicate.
///
/// Frontier inspiration: R's `let t <- table(items); if (length(t) == 0) 0L else if (max(t) == min(t)) length(t) else 0L` on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items); isempty(c) ? 0 : (maximum(values(c)) == minimum(values(c)) ? length(c) : 0) end`
/// on a `Dict{Element, Int}` histogram; Python's `let c = collections.Counter(items); 0 if not c else (len(c) if max(c.values()) == min(c.values()) else 0)`
/// (chained comparison on a Counter); Haskell's `let hs = map length . group . sort $ items in if null hs then 0 else if maximum hs == minimum hs then length hs else 0`;
/// Clojure's `(let [f (frequencies coll)] (if (empty? f) 0 (if (= (apply max (vals f)) (apply min (vals f))) (count f) 0)))`; Coq's
/// `if List.eqb 0 (List.length l) then 0 else if Nat.eqb (max_count l) (min_count l) then length (variants) else 0` on a decidable-
/// equality-derived histogram; SQL's `SELECT CASE WHEN (SELECT COUNT(DISTINCT variant) FROM t) = 0 THEN 0 WHEN (SELECT MAX(c) FROM …) = (SELECT MIN(c) FROM …) THEN (SELECT COUNT(DISTINCT variant) FROM …) ELSE 0 END`.
/// Translation through pleme-io primitives: the N-ary set-level flat-
/// diagonal count on the closed-set trait binds through ONE
/// `is_empty()` guard + ONE branch on the just-lifted
/// [`Self::is_uniform`] projection returning either [`Self::CARDINALITY`]
/// or `0` — no new dep, no supertrait bound (the [`Self::is_uniform`]
/// primitive replaces the `Eq`/`Hash` bound the standard-library
/// `Counter` / `frequencies` / `countmap` chained-max-min-comparison
/// signatures demand), no histogram-carrier allocation (the sweep
/// streams through per-target counts one at a time and accumulates a
/// max/min pair rather than materializing the intermediate `Vec<usize>`
/// histogram OR the intersection witness Vec), one algorithmic factor
/// of `T::CARDINALITY` shaved off the naive filter-count sweep via the
/// uniformity-collapse sharpening.
fn count_bimodal_variants(items: &[Self]) -> usize {
if items.is_empty() || !<Self as ClosedSet>::is_uniform(items) {
0
} else {
<Self as ClosedSet>::CARDINALITY
}
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants sit at EITHER histogram
/// extreme?" cardinality-count projection — the `usize` SET-LEVEL count of
/// variants of [`Self::ALL`] for which [`Self::is_extremal_variant_of`]
/// holds against `items`, SHARPENED past the naive filter-count reduction
/// via the inclusion-exclusion identity
/// `|A ∪ B| = |A| + |B| − |A ∩ B|`
/// against the just-lifted direction-anchored cardinality-count pair
/// [`Self::count_modal_variants`] + [`Self::count_antimodal_variants`] and
/// the intersection sibling [`Self::count_bimodal_variants`]. The
/// USIZE-RETURN CLOSER on the (set-level × usize × statistical-aggregate ×
/// direction-composition × combinator) 2-corner cardinality-count face at
/// its `||` DISJUNCTION arm past the just-closed `&&` CONJUNCTION arm
/// [`Self::count_bimodal_variants`] one COMBINATOR axis over on the
/// modal-aggregation matrix, AND the direct SET-LEVEL ARITY LIFT of the
/// just-lifted (per-target × bool × statistical-aggregate ×
/// direction-composition × union) [`Self::is_extremal_variant_of`] corner
/// one ARITY axis over, AND peer to [`Self::count_modal_variants`] +
/// [`Self::count_antimodal_variants`] one COMBINATOR axis over on the
/// (set-level × usize × statistical-aggregate × direction-composition)
/// cardinality-count row. Not a fresh substrate primitive on the index
/// axis — the count emerges from ONE `is_empty()` guard + ONE
/// inclusion-exclusion arithmetic on the three just-lifted set-level
/// cardinality-count aggregates, replacing the naive
/// `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v, items)).count()`
/// sweep (`O(T::CARDINALITY² * n)` — the per-target predicate itself
/// costs `O(T::CARDINALITY * n)`) with three max/min-fold sweeps
/// (`O(T::CARDINALITY * n)` each) that ALREADY run inside the direction
/// siblings, so on any callsite that also consumes
/// [`Self::count_modal_variants`] or [`Self::count_antimodal_variants`]
/// the arithmetic collapses to two arithmetic ops and one comparison
/// against a cached fold pair, inheriting the max/min-fold cost of the
/// underlying aggregates exactly once.
///
/// Inclusion-exclusion identity: for every slice `items`,
/// `T::count_extremal_variants(items) == T::count_modal_variants(items) + T::count_antimodal_variants(items) - T::count_bimodal_variants(items)`
/// — the canonical body. Under the union-refinement identity
/// [`Self::count_bimodal_variants`] `<= min(count_modal_variants,
/// count_antimodal_variants)`, so the subtraction NEVER underflows and the
/// arithmetic is total on `usize`. Pinned by clause (144) and by
/// `count_extremal_variants_agrees_with_inclusion_exclusion_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_extremal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v, items)).count()`
/// — the sharpened inclusion-exclusion body agrees with the naive
/// filter-count reduction over [`Self::ALL`] of the per-target predicate.
/// Independent cross-check distinct from the inclusion-exclusion arm on
/// the compilation-shape (arithmetic on aggregates vs iterator sweep)
/// axis. Pinned by
/// `count_extremal_variants_equals_filter_count_of_is_extremal_variant_of_across_every_triple`.
///
/// Uniformity-collapse identity: for every NON-EMPTY slice `items` on
/// which [`Self::is_uniform`] holds,
/// `T::count_extremal_variants(items) == T::CARDINALITY`
/// — the direction axis on flat-histogram slices COLLAPSES (`max == min`),
/// so every present variant satisfies BOTH direction arms and the union
/// predicate reports `true` at every target of [`Self::ALL`]. Sibling
/// posture to [`Self::count_bimodal_variants`]'s uniformity-collapse arm
/// one COMBINATOR axis over: on flat-histogram non-empty slices BOTH
/// combinator arms coincide at [`Self::CARDINALITY`] because
/// intersection = union on the flat-histogram diagonal; the two arms
/// bifurcate on every non-flat slice (the disjunction stays `>= 1` while
/// the intersection collapses to `0`).
///
/// Strict-positivity identity: for every slice `items`,
/// `T::count_extremal_variants(items) > 0 iff !items.is_empty()`
/// — on the empty slice both direction siblings collapse to `0` and the
/// arithmetic lands on `0`; on every non-empty slice
/// [`Self::max_variant_count`] `>= 1` is achieved by at least one variant,
/// so [`Self::count_modal_variants`] `>= 1` and the arithmetic inherits
/// `>= 1` verbatim past the (always non-negative) subtraction. Sibling
/// posture to [`Self::count_modal_variants`]'s strict-positivity arm one
/// COMBINATOR axis over. Pinned by
/// `count_extremal_variants_is_strictly_positive_iff_slice_is_non_empty_across_every_triple`.
///
/// Cardinality-upper-bound identity: for every slice `items`,
/// `T::count_extremal_variants(items) <= T::CARDINALITY` UNCONDITIONALLY
/// AND `T::count_extremal_variants(items) == T::CARDINALITY` iff
/// `items.is_empty() || T::is_uniform(items)` fails on the empty guard AND
/// [`Self::is_uniform`] holds — the union of two subsets of [`Self::ALL`]
/// is bounded above by the full carrier and hits its ceiling exactly when
/// every variant satisfies one of the two direction arms (equivalently the
/// two direction siblings jointly cover [`Self::ALL`], which on non-empty
/// slices happens EXACTLY at flat-histogram fixpoints). Pinned by
/// `count_extremal_variants_is_bounded_above_by_cardinality_across_every_triple`.
///
/// Bimodal-count refinement identity: for every slice `items`,
/// `T::count_bimodal_variants(items) <= T::count_extremal_variants(items)`
/// — the intersection cardinality is bounded above by the union
/// cardinality (set-theoretic monotonicity). On flat-histogram non-empty
/// slices both cardinalities coincide at [`Self::CARDINALITY`]; on every
/// non-flat non-empty slice the intersection collapses to `0` while the
/// union stays `>= 1` (any argmax target). Pinned by
/// `count_extremal_variants_is_bounded_below_by_count_bimodal_variants_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through three
/// ordering-agnostic cardinality-count aggregates via inclusion-exclusion
/// arithmetic. No separate `sorted_count_extremal_variants` peer is
/// needed. Pinned by
/// `count_extremal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::count_extremal_variants(&[])` is `0`
/// UNCONDITIONALLY — every direction sibling and the intersection sibling
/// collapse to `0` on the empty slice via their shared non-emptiness
/// guards, and `0 + 0 - 0 == 0`. Pinned by clause (144) and by
/// `count_extremal_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::count_extremal_variants(&[v])` is [`Self::CARDINALITY`] for every
/// variant `v` — the sole position hits `v` at count `1 == max` while
/// every non-target variant sits at count `0 == min`, so
/// [`Self::count_modal_variants`] reports `1`,
/// [`Self::count_antimodal_variants`] reports `T::CARDINALITY - 1`,
/// [`Self::count_bimodal_variants`] reports `0`, and the arithmetic lands
/// on `1 + (T::CARDINALITY - 1) - 0 == T::CARDINALITY`. LOAD-BEARING
/// [`Self::CARDINALITY`]-arm catch on the union cardinality-count corner
/// separating it from [`Self::count_bimodal_variants`] which reports `0`
/// on the same fixture. Pinned by
/// `count_extremal_variants_returns_cardinality_on_every_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Full-set contract:
/// `T::count_extremal_variants(<T as ClosedSet>::ALL)` is
/// [`Self::CARDINALITY`] UNCONDITIONALLY — clause (3)'s pairwise-
/// distinctness invariant pins every variant at exactly one position,
/// [`Self::max_variant_count`] and [`Self::min_variant_count`] both
/// collapse to `1`, [`Self::count_modal_variants`] and
/// [`Self::count_antimodal_variants`] both report [`Self::CARDINALITY`],
/// [`Self::count_bimodal_variants`] reports [`Self::CARDINALITY`], and the
/// arithmetic lands on
/// `T::CARDINALITY + T::CARDINALITY - T::CARDINALITY == T::CARDINALITY`.
/// Direct instance of the uniformity-collapse identity above. Pinned by
/// clause (144) and by
/// `count_extremal_variants_returns_cardinality_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_extremal_variants(&doubled)` is [`Self::CARDINALITY`]
/// UNCONDITIONALLY — the doubled full set hits every variant at exactly
/// two positions; the same arithmetic pattern as the full-set arm on the
/// second flat-histogram fixpoint. Pinned by clause (144) and by
/// `count_extremal_variants_returns_cardinality_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::count_extremal_variants(&bimodal_triple)` is `T::CARDINALITY - 1`
/// — on `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is non-flat
/// (max `2`, min `0`), [`Self::count_modal_variants`] reports `1` (just
/// `T::ALL[0]`), [`Self::count_antimodal_variants`] reports
/// `T::CARDINALITY - 2` (every variant from `T::ALL[2]` onward at
/// count `0 == min`), [`Self::count_bimodal_variants`] reports `0`, and
/// the arithmetic lands on
/// `1 + (T::CARDINALITY - 2) - 0 == T::CARDINALITY - 1`. The `MIDDLE`
/// target `T::ALL[1]` is the sole non-extremal target on this fixture —
/// LOAD-BEARING witness that the union cardinality is strictly less than
/// [`Self::CARDINALITY`] on every non-flat slice with a middle-band
/// inhabitant. Pinned by
/// `count_extremal_variants_returns_cardinality_minus_one_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of three
/// set-level cardinality-count aggregates —
/// [`Self::count_modal_variants`], [`Self::count_antimodal_variants`],
/// and [`Self::count_bimodal_variants`] — composed via inclusion-
/// exclusion arithmetic. The body inherits their `O(T::CARDINALITY * n)` cost on
/// slice arity `n` — three max/min-fold sweeps through the per-variant
/// multiplicity primitive plus two arithmetic ops. Strictly beats the
/// naive
/// `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v, items)).count()`
/// sweep which pays `O(T::CARDINALITY² * n)` — one per-target
/// [`Self::is_extremal_variant_of`] call per variant, each of which
/// re-derives the max and min folds internally. Allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// histogram-shape carrier.
///
/// Future consumers that compose against
/// [`Self::count_extremal_variants`]: a `tatara-check` predicate
/// `(check-phases-at-histogram-extreme-count …)` that reports how many
/// `WorkloadPhase` variants sit at some extreme of a rollout window —
/// `T::CARDINALITY` on flat histograms, strictly less otherwise,
/// composable with the just-lifted [`Self::count_bimodal_variants`] gauge
/// as a two-scalar `(union_count, intersection_count)` pair per window; an
/// LSP diagnostic on a Lisp-author-written variant-list that renders "N
/// of M variants sit at the histogram extremes (the remaining M - N sit
/// in the middle band)" as a typed scalar; a Sekiban audit-trail
/// `extremal_tie_count` gauge alongside the direction-anchored
/// `modal_tie_count` / `antimodal_tie_count` gauges (paying no per-target
/// sweep on the hot path when the direction gauges are already computed);
/// a scheduler-fairness heuristic that branches on
/// `count_extremal_variants == T::CARDINALITY` (fully polarized —
/// no middle band, no smoothing needed) vs `< T::CARDINALITY` (there is a
/// middle band to grow into or shrink from) without materializing the
/// intersection witness. Each binds to ONE typed `usize`-return set-level
/// union-cardinality aggregate on the trait rather than paying the
/// `O(T::CARDINALITY² * n)` naive filter-count sweep OR re-deriving the
/// inclusion-exclusion arithmetic inline per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level × usize ×
/// statistical-aggregate × direction-composition × combinator) 2-corner
/// cardinality-count face at its `||` DISJUNCTION arm past the just-
/// opened `&&` CONJUNCTION arm [`Self::count_bimodal_variants`] one
/// COMBINATOR axis over. The (set-level × usize × direction-composition)
/// column now carries FOUR aligned cardinality-count aggregates against
/// the two direction-anchored gauges: (a) [`Self::count_modal_variants`]
/// — argmax band; (b) [`Self::count_antimodal_variants`] — argmin band;
/// (c) [`Self::count_bimodal_variants`] — intersection (`&&`, flat
/// diagonal); (d) THIS — union (`||`, either extreme); the "middle band"
/// cardinality obtains as
/// `T::CARDINALITY - T::count_extremal_variants(items)` on non-empty
/// slices via the De Morgan complement without a fresh substrate
/// primitive. The natural next lifts past this closure are:
/// * `is_middle_band_variant_of(v, items) == !is_extremal_variant_of(v, items) && !items.is_empty()`
/// — the per-target COMPLEMENT of [`Self::is_extremal_variant_of`] on
/// non-empty slices, opening the middle-band membership corner as a
/// typed consequence of the De Morgan identity.
/// * `count_middle_band_variants(items) -> usize` — the set-level
/// COMPLEMENT of THIS projection via
/// `if items.is_empty() { 0 } else { T::CARDINALITY - T::count_extremal_variants(items) }`,
/// opening the (set-level × usize × middle-band) corner one
/// COMBINATOR axis over on the (extreme / middle) partition of
/// [`Self::ALL`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-level
/// count of extremal variants becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v, items)).count()`
/// composition (which itself factors through two direction-anchored
/// predicates per variant, paying `O(T::CARDINALITY² * n)`) at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × usize × union) corner was an unnamed inline composition
/// recurring at every prospective downstream "how many variants sit at
/// some extreme?" site pre-lift. Naming it on the trait AND SHARPENING
/// it via inclusion-exclusion makes the count a TYPED CONSEQUENCE of
/// THREE substrate primitives ([`Self::count_modal_variants`],
/// [`Self::count_antimodal_variants`], [`Self::count_bimodal_variants`])
/// under `+` / `-` on `usize` rather than a composition of
/// `T::CARDINALITY` per-target predicate calls. THEORY.md §VI.1 —
/// generation over composition; the sharpened body emerges from the
/// composition of THREE substrate primitives under inclusion-exclusion
/// arithmetic, not as a per-implementor hand-rolled body OR as a naive
/// filter-count sweep over [`Self::ALL`] of the per-target predicate.
///
/// Frontier inspiration: R's
/// `let t <- table(items); sum(t == max(t) | t == min(t))` on a factor
/// histogram; Julia's
/// `let c = StatsBase.countmap(items); count(v -> (c[v] == maximum(values(c))) || (c[v] == minimum(values(c))), keys(c)) end`
/// on a `Dict{Element, Int}` histogram; Python's
/// `let c = collections.Counter(items); sum(1 for v in c if c[v] in (max(c.values()), min(c.values())))`
/// on a Counter; Haskell's
/// `let hs = map length . group . sort $ items in length . filter (\h -> h == maximum hs || h == minimum hs) $ hs`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f))] (count (filter (fn [v] (or (= (get f v 0) m) (= (get f v 0) n))) (vals f))))`;
/// Coq's per-target
/// `List.length (List.filter (fun v => orb (Nat.eqb (List.count_occ eqb l v) (max_count l)) (Nat.eqb (List.count_occ eqb l v) (min_count l))) variants)`
/// on a decidable-equality carrier; SQL's
/// `SELECT COUNT(DISTINCT variant) FROM t WHERE variant_count IN (SELECT MAX(c) FROM …, SELECT MIN(c) FROM …)`.
/// Translation through pleme-io primitives: the N-ary set-level union
/// cardinality on the closed-set trait binds through ONE arithmetic
/// composition on the just-lifted set-level cardinality-count aggregates
/// via the inclusion-exclusion identity — no new dep, no supertrait bound
/// (the ([`Self::count_modal_variants`], [`Self::count_antimodal_variants`],
/// [`Self::count_bimodal_variants`]) triple replaces the `Eq`/`Hash`
/// bound the standard-library `Counter` / `frequencies` / `countmap`
/// filter-over-values signatures demand), no histogram-carrier
/// allocation, one algorithmic factor of `T::CARDINALITY` shaved off the
/// naive filter-count sweep via the inclusion-exclusion sharpening.
fn count_extremal_variants(items: &[Self]) -> usize {
if items.is_empty() {
return 0;
}
let modal = <Self as ClosedSet>::count_modal_variants(items);
let antimodal = <Self as ClosedSet>::count_antimodal_variants(items);
let bimodal = <Self as ClosedSet>::count_bimodal_variants(items);
modal + antimodal - bimodal
}
/// The N-ARY ORDERING-AGNOSTIC "target sits STRICTLY between the two
/// histogram extremes?" predicate — `true` iff the slice is non-empty
/// AND `target`'s per-slot count in `items` sits STRICTLY between
/// [`Self::min_variant_count`] and [`Self::max_variant_count`]
/// (equivalently, `target` is NEITHER at the argmax band NOR at the
/// argmin band), computed as the boolean CONJUNCTION of a non-empty
/// guard AND the negation of [`Self::is_extremal_variant_of`]. The
/// BOOL-RETURN OPENER on the (per-target × bool × statistical-
/// aggregate × direction-composition × complement) middle-band corner
/// past the just-closed (per-target × bool × statistical-aggregate ×
/// direction-composition × combinator) 2-corner union/intersection
/// face — the direct De Morgan COMPLEMENT of [`Self::is_extremal_variant_of`]
/// on non-empty slices, closing the (extreme / middle) partition of
/// [`Self::ALL`] on every non-empty slice at every target. Not a
/// fresh substrate primitive on the index axis — the predicate emerges
/// from ONE non-empty guard AND one boolean negation of the just-
/// lifted (per-target × bool × direction-composition × union)
/// [`Self::is_extremal_variant_of`] corner, equivalently the count-
/// band strict-between test `min < count < max` on non-empty slices.
///
/// De Morgan complement identity: for every slice `items` and every
/// target `v`,
/// `T::is_middle_band_variant_of(v, items) == (!items.is_empty() && !T::is_extremal_variant_of(v, items))`
/// — the canonical body. Pinned by clause (145) and by
/// `is_middle_band_variant_of_equals_not_is_extremal_variant_of_and_non_empty_across_every_target_and_triple`.
///
/// Direction-conjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_middle_band_variant_of(v, items) == (!items.is_empty() && !T::is_modal_variant_of(v, items) && !T::is_antimodal_variant_of(v, items))`
/// — the De Morgan expansion of the complement identity through
/// `!(A || B) == !A && !B` applied to
/// [`Self::is_extremal_variant_of`]'s direction-union body. The
/// middle band emerges as the CONJUNCTION of the negations of both
/// direction-anchored membership predicates one COMBINATOR axis over
/// from the (per-target × bool × direction-composition × intersection)
/// [`Self::is_bimodal_variant_of`] corner (`is_modal_variant_of &&
/// is_antimodal_variant_of` — both extremes) — THIS corner is
/// `!is_modal_variant_of && !is_antimodal_variant_of` (neither
/// extreme). Pinned by
/// `is_middle_band_variant_of_equals_not_is_modal_and_not_is_antimodal_variant_of_and_non_empty_across_every_target_and_triple`.
///
/// Count-band strict-between identity: for every NON-EMPTY slice
/// `items` and every target `v`, `T::is_middle_band_variant_of(v, items) ==
/// (T::min_variant_count(items) < T::count_occurrences_of(v, items)
/// && T::count_occurrences_of(v, items) < T::max_variant_count(items))`
/// — the projection agrees with the count-band strict-between test on
/// non-empty slices. Independent cross-check distinct from the
/// direction-conjunction arm on the composition axis. Pinned by
/// `is_middle_band_variant_of_holds_iff_count_strictly_between_min_and_max_on_non_empty_across_every_target_and_triple`.
///
/// Uniformity-collapse identity: for every NON-EMPTY slice `items`
/// on which [`Self::is_uniform`] holds (max == min) and every target
/// `v`, `T::is_middle_band_variant_of(v, items) == false` — the flat-
/// histogram surface has NO strict middle-band inhabitant (max ==
/// min collapses the strict-between interval to empty), and every
/// target reduces to the extremal partition at both endpoints
/// simultaneously. Sibling posture to
/// [`Self::is_extremal_variant_of`]'s uniformity-collapse arm one
/// COMPLEMENT axis over: the UNION corner reports `true` at every
/// target on flat-histogram non-empty slices; THIS COMPLEMENT corner
/// reports `false` at every target on the same slices. Pinned by
/// `is_middle_band_variant_of_returns_false_at_every_target_on_every_uniform_non_empty_slice_across_every_triple`.
///
/// Extreme-middle partition identity: for every NON-EMPTY slice
/// `items` and every target `v`,
/// `T::is_extremal_variant_of(v, items) ^ T::is_middle_band_variant_of(v, items) == true`
/// (equivalently, `T::is_extremal_variant_of(v, items) !=
/// T::is_middle_band_variant_of(v, items)`) — the two corners
/// partition [`Self::ALL`] into disjoint arms on every non-empty
/// slice at every target: exactly one of the two holds, never both,
/// never neither. Together with the empty-slice fixpoint (both
/// corners report `false`), this pins the (extreme / middle) axis as
/// a clean partition of the per-target predicate surface with a
/// dedicated empty-slice sink arm. Pinned by
/// `is_middle_band_variant_of_partitions_the_variant_surface_with_is_extremal_variant_of_across_every_target_and_triple`.
///
/// Cardinality-lower-bound identity: for every implementor with
/// [`Self::CARDINALITY`]`< 3` and every slice `items` and every
/// target `v`, `T::is_middle_band_variant_of(v, items) == false`
/// UNCONDITIONALLY — a histogram of at most two distinct positions
/// has no space for a strictly-between count (either max == min on
/// uniform slices or the two positions ARE the two extremes). The
/// (per-target × bool × strict-middle) corner reaches its `false`
/// fixpoint universally at cardinality `<= 2`. LOAD-BEARING
/// invariance: the corner OPENS at cardinality `>= 3` only, where
/// the bimodal-triple fixture carries the sole non-trivial `true`-
/// arm witness. (No dedicated test — subsumed by the empty-slice /
/// singleton / full-set / doubled-full-set fixpoint arms all
/// reporting `false` at every target at every cardinality.)
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — it factors through an ordering-agnostic
/// non-empty guard AND the ordering-agnostic
/// [`Self::is_extremal_variant_of`] predicate joined under boolean
/// conjunction. No separate `sorted_is_middle_band_variant_of` peer
/// is needed. Pinned by
/// `is_middle_band_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_middle_band_variant_of(v, &[])` is
/// `false` UNCONDITIONALLY at every target — the non-empty guard
/// short-circuits past the vacuous `!T::is_extremal_variant_of(v,
/// &[])` (which itself reports `true` because
/// [`Self::is_extremal_variant_of`] reports `false` on the empty
/// slice) to land on `false`. Sibling posture to
/// [`Self::is_extremal_variant_of`]'s empty-slice fixpoint one
/// COMPLEMENT axis over: BOTH corners reach their `false` fixpoint
/// at the empty-slice endpoint — a witness that the empty slice sits
/// OUTSIDE the (extreme / middle) partition entirely, not on some
/// hidden middle-band boundary. LOAD-BEARING `false`-arm catch: an
/// override that drops the non-empty guard would silently commit to
/// `!T::is_extremal_variant_of(v, &[]) == true` at every target on
/// the empty slice, silently making the partition identity fold
/// through the extremes at cardinality `>= 1`. Pinned by clause (145)
/// and by
/// `is_middle_band_variant_of_returns_false_on_the_empty_slice_across_every_target`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::is_middle_band_variant_of(v, &[v]) == false` for every variant
/// `v` — the sole position hits the target at count `1 == max`,
/// [`Self::is_extremal_variant_of`] reports `true` at the target on
/// the argmax band, the complement lands on `false` at the target,
/// and the conjunction with the non-empty guard inherits `false`.
/// LOAD-BEARING `false`-arm catch on the matching-singleton fixture
/// where the target sits AT an extreme (max), not strictly between.
/// Pinned by
/// `is_middle_band_variant_of_returns_false_on_the_matching_singleton_across_every_target`.
///
/// Non-matching-singleton contract at cardinality `>= 2`:
/// `T::is_middle_band_variant_of(v, &[w]) == false` for every target
/// `v` and slice-element `w` with `v != w` — the sole position hits
/// `w`, so the target's count is `0 == min`,
/// [`Self::is_extremal_variant_of`] reports `true` at the target on
/// the argmin band, the complement lands on `false` at the target,
/// and the conjunction with the non-empty guard inherits `false`.
/// LOAD-BEARING `false`-arm catch on the non-matching-singleton
/// fixture where the target sits AT an extreme (min), not strictly
/// between. Pinned by
/// `is_middle_band_variant_of_returns_false_on_the_non_matching_singleton_across_every_target_pair`.
///
/// Full-set contract:
/// `T::is_middle_band_variant_of(v, <T as ClosedSet>::ALL) == false`
/// for every target `v` UNCONDITIONALLY at cardinality `>= 1` —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// at exactly one position of the full-set slice,
/// [`Self::max_variant_count`] and [`Self::min_variant_count`] both
/// collapse to `1`, [`Self::is_extremal_variant_of`] reports `true`
/// at every target on the flat-histogram fixpoint, and the
/// complement collapses to `false` at every target. LOAD-BEARING
/// `false`-arm catch on the flat-histogram diagonal — a witness that
/// the strict-middle band is EMPTY on uniform slices. Pinned by
/// `is_middle_band_variant_of_returns_false_on_the_full_set_across_every_target`.
///
/// Doubled-full-set contract:
/// `T::is_middle_band_variant_of(v, &doubled) == false` for every
/// target `v` — the doubled full set hits every variant at exactly
/// two positions, both extremes collapse to `2`,
/// [`Self::is_extremal_variant_of`] reports `true` at every target,
/// and the complement collapses to `false`. Sibling posture to the
/// full-set arm on the second flat-histogram fixpoint. Pinned by
/// `is_middle_band_variant_of_returns_false_on_the_doubled_full_set_across_every_target`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2] ->
/// 0 == min)`. `T::is_middle_band_variant_of(v, &bimodal_triple)`
/// returns `true` at the SOLE middle-band target `T::ALL[1]` and
/// `false` at BOTH direction-endpoint targets — argmax `T::ALL[0]`
/// (at count `2 == max`, [`Self::is_extremal_variant_of`] reports
/// `true`) AND argmin `T::ALL[2]` (at count `0 == min`, sits on the
/// argmin band, extremal). LOAD-BEARING `true`-arm catch on the
/// bimodal-triple fixture — the SOLE fixpoint witness the middle-
/// band corner carries a `true` arm. This is the DUAL of
/// [`Self::is_extremal_variant_of`]'s `false`-arm middle-band catch
/// on the same fixture one COMPLEMENT axis over: extremal reports
/// `false` ONLY at `T::ALL[1]`; THIS reports `true` ONLY at
/// `T::ALL[1]`. Pinned by
/// `is_middle_band_variant_of_returns_true_at_middle_band_target_on_the_bimodal_triple_at_cardinality_ge_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the just-
/// lifted per-target direction-composition [`Self::is_extremal_variant_of`]
/// predicate composed under a non-empty guard AND one boolean
/// negation. The composition uses one `!items.is_empty()` bool AND
/// one `!` on `bool` AND one `&&` on `bool`, so the sweep inherits
/// the O(T::CARDINALITY * n) cost of the underlying direction siblings
/// on slice arity `n` — allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::is_middle_band_variant_of`]: a `tatara-check` predicate
/// `(check-target-at-histogram-middle …)` that reports whether a
/// target `WorkloadPhase` sits STRICTLY between the two histogram
/// extremes across a rollout window (a witness that the target is
/// neither over-rolled nor under-rolled — sitting in the middle band
/// where operator attention is disproportionately valuable) without
/// paying for the min/max fold separately at every callsite; an LSP
/// diagnostic on a Lisp-author-written variant-list that flags
/// "target sits strictly between max and min positions" as a witness
/// the author's frequency-balance heuristic holds at THIS target
/// (distinct from the flat-diagonal witness the [`Self::is_bimodal_variant_of`]
/// sibling offers one COMBINATOR axis over); a Sekiban audit-trail
/// per-target middle-band-participation gauge alongside the
/// direction-union `extremal_at_target` gauge (a downstream consumer
/// would read `middle_band_at_target` as "the target participates in
/// the strict-between interval" AND `extremal_at_target` as "the
/// target sits at some extreme" — the pair partitions the per-target
/// predicate surface on non-empty slices); a `tatara-lisp::
/// macro_expand::Expander` hygiene pass that flags a template's
/// identifier multiset as "this identifier participates in the
/// strict-middle band" (a common shape for identifiers whose
/// occurrence count is neither the most-frequent nor the least-
/// frequent — a soft attention marker for template review) in ONE
/// typed bool rather than an inline
/// `!T::is_modal_variant_of(v, items) && !T::is_antimodal_variant_of(v, items) && !items.is_empty()`
/// conjunction. Each binds to ONE typed N-ary per-target strict-
/// middle predicate on the trait rather than re-deriving the De
/// Morgan complement inline per callsite.
///
/// Compounding closure: this projection OPENS the (per-target × bool
/// × statistical-aggregate × direction-composition × complement)
/// middle-band corner past the just-closed (per-target × bool ×
/// statistical-aggregate × direction-composition × combinator)
/// 2-corner union/intersection face. The (per-target × bool ×
/// direction-composition) column now carries FOUR aligned membership
/// predicates: (a) [`Self::is_modal_variant_of`] — argmax band; (b)
/// [`Self::is_antimodal_variant_of`] — argmin band; (c)
/// [`Self::is_extremal_variant_of`] — union (`||`, some extreme); (d)
/// [`Self::is_bimodal_variant_of`] — intersection (`&&`, both
/// extremes); (e) THIS — complement (`!` on non-empty, neither
/// extreme). Together with the empty-slice fixpoint (which sits
/// outside the (extreme / middle) partition entirely — both (c) and
/// (e) report `false`), this closes the per-target direction-
/// composition surface at every possible (max, min, count) band
/// coincidence pattern. The natural next lift past this closure is:
/// * `count_middle_band_variants(items) -> usize` — the set-level
/// ARITY LIFT of THIS per-target predicate via
/// `if items.is_empty() { 0 } else { T::CARDINALITY - T::count_extremal_variants(items) }`,
/// opening the (set-level × usize × middle-band) corner one ARITY
/// axis over. Direct COMPLEMENT of
/// [`Self::count_extremal_variants`] via
/// `T::CARDINALITY - T::count_extremal_variants(items)` on non-
/// empty slices — closes the (extreme / middle) partition on the
/// set-level usize row.
/// * `has_middle_band_variant(items) -> bool` — the set-level
/// existential lift via `T::CARDINALITY > T::count_extremal_variants(items)`
/// equivalently `T::CARDINALITY >= 3 && !items.is_empty() && !T::is_uniform(items)`,
/// opening the (set-level × bool × middle-band × existential)
/// corner one ARITY axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target strict-middle membership predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline
/// `!items.is_empty() && !T::is_extremal_variant_of(v, items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × direction-agnostic ×
/// complement) corner was an unnamed inline composition recurring at
/// every prospective downstream "is this target strictly between the
/// two extremes?" site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the just-lifted (per-target ×
/// bool × direction-agnostic × union)
/// [`Self::is_extremal_variant_of`] corner under a non-empty guard
/// AND one boolean negation. THEORY.md §VI.1 — generation over
/// composition; the predicate emerges from the composition of one
/// substrate primitive ([`Self::is_extremal_variant_of`]) with one
/// bool guard and one bool combinator, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `let t <- table(items); t[v] > min(t)
/// && t[v] < max(t)` per-level strict-between test on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items), m =
/// maximum(values(c)), n = minimum(values(c)); n < c[v] < m end` on
/// a `Dict{Element, Int}` histogram (chained comparison is the
/// canonical idiom); Python's `let c = collections.Counter(items);
/// min(c.values()) < c[v] < max(c.values())` on a Counter (chained
/// comparison syntax matches the mathematical notation); Haskell's
/// `let hs = map length . group . sort $ items, m = maximum hs, n =
/// minimum hs in count v items > n && count v items < m`; Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply
/// min (vals f)), c (get f v 0)] (and (> c n) (< c m)))`; Coq's per-
/// target `andb (Nat.ltb (min_count l) (List.count_occ eqb l v))
/// (Nat.ltb (List.count_occ eqb l v) (max_count l))` on a decidable-
/// equality carrier; SQL's `SELECT variant FROM t GROUP BY variant
/// HAVING COUNT(*) > (SELECT MIN(c) FROM …) AND COUNT(*) < (SELECT
/// MAX(c) FROM …)`. Translation through pleme-io primitives: the
/// N-ary per-target direction-agnostic strict-middle predicate on
/// the closed-set trait binds through the just-lifted (per-target ×
/// bool × direction-agnostic × union) [`Self::is_extremal_variant_of`]
/// corner under a non-empty guard AND one boolean negation — no new
/// dep, no supertrait bound, no allocation, O(T::CARDINALITY * n)
/// inherited from the underlying direction siblings with short-
/// circuiting on the empty-slice guard AND on the argmax arm of the
/// nested extremal test.
fn is_middle_band_variant_of(target: Self, items: &[Self]) -> bool {
!items.is_empty() && !<Self as ClosedSet>::is_extremal_variant_of(target, items)
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants sit STRICTLY between
/// the two histogram extremes?" cardinality-count projection — the
/// `usize` SET-LEVEL count of variants of [`Self::ALL`] for which
/// [`Self::is_middle_band_variant_of`] holds against `items`, SHARPENED
/// past the naive filter-count reduction via the De Morgan complement
/// identity `|middle| = T::CARDINALITY - |extremal|` on non-empty
/// slices against the just-lifted (set-level × usize × direction-
/// composition × union) [`Self::count_extremal_variants`] cardinality-
/// count aggregate. The USIZE-RETURN CLOSER on the (set-level × usize
/// × statistical-aggregate × direction-composition × complement)
/// middle-band corner ARITY-LIFTING [`Self::is_middle_band_variant_of`]
/// one ARITY axis over on the modal-aggregation matrix, AND the direct
/// SET-LEVEL COMPLEMENT of the just-lifted (set-level × usize ×
/// statistical-aggregate × direction-composition × union)
/// [`Self::count_extremal_variants`] corner one COMPLEMENT axis over,
/// closing the (extreme / middle) partition on the set-level usize
/// row. Not a fresh substrate primitive on the index axis — the count
/// emerges from ONE `is_empty()` guard + ONE subtraction on the just-
/// lifted set-level union cardinality-count aggregate, replacing the
/// naive
/// `T::ALL.iter().filter(|&v| T::is_middle_band_variant_of(v, items)).count()`
/// sweep (`O(T::CARDINALITY² * n)` — the per-target predicate itself
/// costs `O(T::CARDINALITY * n)` via the nested extremal test) with
/// one subtraction against a cached [`Self::count_extremal_variants`]
/// aggregate that ALREADY runs inside the union sibling, so on any
/// callsite that also consumes [`Self::count_extremal_variants`] the
/// arithmetic collapses to one arithmetic op against the cached fold,
/// inheriting the max/min-fold cost of the underlying aggregate
/// exactly once.
///
/// De Morgan complement identity: for every slice `items`,
/// `T::count_middle_band_variants(items) == if items.is_empty() { 0 } else { T::CARDINALITY - T::count_extremal_variants(items) }`
/// — the canonical body. Under the cardinality-upper-bound identity
/// [`Self::count_extremal_variants`] `<= T::CARDINALITY`, so the
/// subtraction NEVER underflows and the arithmetic is total on
/// `usize`. Pinned by clause (146) and by
/// `count_middle_band_variants_agrees_with_de_morgan_complement_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_middle_band_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, items)).count()`
/// — the sharpened De Morgan complement body agrees with the naive
/// filter-count reduction over [`Self::ALL`] of the per-target
/// predicate. Independent cross-check distinct from the De Morgan
/// complement arm on the compilation-shape (arithmetic on aggregate
/// vs iterator sweep) axis. Pinned by
/// `count_middle_band_variants_equals_filter_count_of_is_middle_band_variant_of_across_every_triple`.
///
/// Partition-sum identity: for every NON-EMPTY slice `items`,
/// `T::count_middle_band_variants(items) + T::count_extremal_variants(items) == T::CARDINALITY`
/// — the (extreme / middle) partition of [`Self::ALL`] on non-empty
/// slices sums to the full carrier cardinality. The two arms together
/// cover [`Self::ALL`] exactly once. Pinned by
/// `count_middle_band_variants_plus_count_extremal_variants_equals_cardinality_on_non_empty_across_every_triple`.
///
/// Uniformity-collapse identity: for every NON-EMPTY slice `items` on
/// which [`Self::is_uniform`] holds,
/// `T::count_middle_band_variants(items) == 0`
/// — the flat-histogram surface has NO strict middle-band inhabitant
/// (max == min collapses the strict-between interval to empty), and
/// every present variant satisfies BOTH direction arms, so
/// [`Self::count_extremal_variants`] reports [`Self::CARDINALITY`]
/// and the subtraction lands on `0`. Sibling posture to
/// [`Self::count_extremal_variants`]'s uniformity-collapse arm one
/// COMPLEMENT axis over: the UNION count reaches its ceiling
/// [`Self::CARDINALITY`] on flat-histogram non-empty slices; THIS
/// COMPLEMENT count reaches its floor `0` on the same slices. Pinned
/// by
/// `count_middle_band_variants_returns_zero_on_every_uniform_non_empty_slice_across_every_triple`.
///
/// Empty-or-uniform-collapse identity: for every slice `items`,
/// `T::count_middle_band_variants(items) == 0 iff items.is_empty() || T::is_uniform(items)`
/// — the middle-band cardinality is `0` EXACTLY when the slice sits
/// on the empty-slice endpoint OR the flat-histogram diagonal. On
/// every non-empty non-flat slice the middle-band cardinality is
/// STRICTLY POSITIVE only when there exists a target strictly between
/// the two extremes; at cardinality `<= 2` no such target exists
/// (there is no room between max and min), so the middle-band count
/// stays at `0` on cardinality-2 non-flat slices too. Pinned by
/// `count_middle_band_variants_is_zero_iff_slice_is_empty_or_uniform_across_every_triple`.
///
/// Cardinality-upper-bound identity: for every slice `items`,
/// `T::count_middle_band_variants(items) <= T::CARDINALITY`
/// UNCONDITIONALLY — the count is bounded above by the full carrier
/// (the middle band is a subset of [`Self::ALL`]). On non-empty slices
/// the tighter bound `<= T::CARDINALITY - 2` holds on every non-
/// uniform slice (both extremes are non-empty and disjoint, so
/// [`Self::count_extremal_variants`] `>= 2` there); on uniform non-
/// empty slices the count collapses to `0`; on the empty slice the
/// count is `0`. Pinned by
/// `count_middle_band_variants_is_bounded_above_by_cardinality_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through an
/// ordering-agnostic empty-slice guard AND the ordering-agnostic
/// [`Self::count_extremal_variants`] aggregate under subtraction. No
/// separate `sorted_count_middle_band_variants` peer is needed.
/// Pinned by
/// `count_middle_band_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::count_middle_band_variants(&[])` is `0`
/// UNCONDITIONALLY — the empty-slice guard short-circuits past the
/// vacuous `T::CARDINALITY - T::count_extremal_variants(&[])` (which
/// would otherwise fold onto `T::CARDINALITY` because
/// [`Self::count_extremal_variants`] reports `0` on the empty slice)
/// to land on `0`. Sibling posture to
/// [`Self::is_middle_band_variant_of`]'s empty-slice fixpoint one
/// ARITY axis over: BOTH corners reach their `0`/`false` fixpoint at
/// the empty-slice endpoint — a witness that the empty slice sits
/// OUTSIDE the (extreme / middle) partition entirely, not on some
/// hidden middle-band boundary. LOAD-BEARING `0`-arm catch: an
/// override that drops the empty-slice guard would silently commit to
/// `T::CARDINALITY - 0 == T::CARDINALITY` on the empty slice,
/// silently making the partition identity fold through the ceiling
/// at cardinality `>= 1`. Pinned by clause (146) and by
/// `count_middle_band_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::count_middle_band_variants(&[v])` is `0` for every variant
/// `v` — the sole position hits `v` at count `1 == max` while every
/// non-target variant sits at count `0 == min`,
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY` (every
/// variant sits at some extreme), and the arithmetic lands on
/// `T::CARDINALITY - T::CARDINALITY == 0`. LOAD-BEARING `0`-arm
/// catch: no middle band on singleton slices. Pinned by
/// `count_middle_band_variants_returns_zero_on_every_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Full-set contract:
/// `T::count_middle_band_variants(<T as ClosedSet>::ALL)` is `0`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position of the full-set slice,
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY` on the
/// flat-histogram fixpoint, and the arithmetic lands on `0`. Direct
/// instance of the uniformity-collapse identity above. Pinned by
/// clause (146) and by
/// `count_middle_band_variants_returns_zero_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_middle_band_variants(&doubled)` is `0` UNCONDITIONALLY
/// — the doubled full set hits every variant at exactly two positions
/// (max == min == 2), [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY` on the second flat-histogram fixpoint, and the
/// arithmetic lands on `0`. Sibling posture to the full-set arm on
/// the second flat-histogram fixpoint. Pinned by clause (146) and by
/// `count_middle_band_variants_returns_zero_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::count_middle_band_variants(&bimodal_triple)` is `1` — on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is non-flat
/// (max `2`, `T::ALL[1]` at `1` (MIDDLE), min `0`),
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY - 1`
/// (every variant is extremal except the sole middle-band target
/// `T::ALL[1]`), and the arithmetic lands on
/// `T::CARDINALITY - (T::CARDINALITY - 1) == 1`. The `MIDDLE` target
/// `T::ALL[1]` is the SOLE middle-band inhabitant on this fixture —
/// LOAD-BEARING `1`-arm catch: the SOLE canonical fixpoint witness
/// the middle-band cardinality corner carries a strictly-positive
/// arm. DUAL of [`Self::count_extremal_variants`]'s
/// `T::CARDINALITY - 1`-arm catch on the same fixture one COMPLEMENT
/// axis over. Pinned by
/// `count_middle_band_variants_returns_one_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the just-
/// lifted set-level union cardinality-count aggregate
/// [`Self::count_extremal_variants`] composed under an empty-slice
/// guard AND one subtraction. The body inherits its
/// `O(T::CARDINALITY * n)` cost on slice arity `n` — one call into
/// the underlying max/min-fold aggregates plus one arithmetic op.
/// Strictly beats the naive
/// `T::ALL.iter().filter(|&v| T::is_middle_band_variant_of(v, items)).count()`
/// sweep which pays `O(T::CARDINALITY² * n)` — one per-target
/// [`Self::is_middle_band_variant_of`] call per variant, each of
/// which re-derives the extremal test internally. Allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::count_middle_band_variants`]: a `tatara-check` predicate
/// `(check-phases-at-histogram-middle-count …)` that reports how many
/// `WorkloadPhase` variants sit STRICTLY between the two histogram
/// extremes across a rollout window (a witness that N variants are
/// neither over-rolled nor under-rolled — the operator-attention
/// band) composable with the just-lifted
/// [`Self::count_extremal_variants`] gauge as a two-scalar
/// `(extremal_count, middle_count)` pair per window summing to
/// [`Self::CARDINALITY`] on non-empty slices; an LSP diagnostic on
/// a Lisp-author-written variant-list that renders "N of M variants
/// sit STRICTLY between the histogram extremes" as a typed scalar; a
/// Sekiban audit-trail `middle_band_count` gauge alongside the union
/// `extremal_count` gauge (paying no per-target sweep on the hot path
/// when the union gauge is already computed); a scheduler-fairness
/// heuristic that branches on `count_middle_band_variants == 0`
/// (fully polarized — every variant sits at some extreme) vs `> 0`
/// (there is a middle band to grow into or shrink from) without
/// materializing the middle-band witness. Each binds to ONE typed
/// `usize`-return set-level middle-band cardinality aggregate on the
/// trait rather than paying the `O(T::CARDINALITY² * n)` naive
/// filter-count sweep OR re-deriving the De Morgan complement
/// arithmetic inline per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level × usize
/// × statistical-aggregate × direction-composition × complement)
/// middle-band corner past the just-opened (per-target × bool ×
/// statistical-aggregate × direction-composition × complement)
/// [`Self::is_middle_band_variant_of`] corner one ARITY axis over.
/// The (set-level × usize × direction-composition) column now carries
/// FIVE aligned cardinality-count aggregates against the two
/// direction-anchored gauges: (a) [`Self::count_modal_variants`] —
/// argmax band; (b) [`Self::count_antimodal_variants`] — argmin band;
/// (c) [`Self::count_bimodal_variants`] — intersection (`&&`, flat
/// diagonal); (d) [`Self::count_extremal_variants`] — union (`||`,
/// some extreme); (e) THIS — complement (`!` on non-empty, neither
/// extreme). Together with the partition-sum identity
/// (d) + (e) == [`Self::CARDINALITY`] on non-empty slices, the row
/// closes the (extreme / middle) partition of [`Self::ALL`] on the
/// set-level usize surface. The natural next lift past this closure
/// is:
/// * `middle_band_variants(items) -> Vec<Self>` — the (`Vec<Self>`
/// set-level statistical-aggregate declaration-order complete-
/// witness) return-shape peer of THIS `usize`-return count, one
/// RETURN-SHAPE axis over. The middle-band inhabitants as a
/// materialized witness vector rather than just a cardinality.
/// * `has_middle_band_variant(items) -> bool` — the (`bool` set-
/// level existential lift) return-shape peer via
/// `T::count_middle_band_variants(items) >= 1`, one RETURN-SHAPE
/// axis over. Cheaper than the count on hot paths that only need
/// an existence witness.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level count of middle-band variants becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|&v| T::is_middle_band_variant_of(v, items)).count()`
/// composition (which itself factors through the extremal predicate
/// per variant, paying `O(T::CARDINALITY² * n)`) at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (set-level ×
/// usize × middle-band) corner was an unnamed inline composition
/// recurring at every prospective downstream "how many variants sit
/// in the middle band?" site pre-lift. Naming it on the trait AND
/// SHARPENING it via the De Morgan complement makes the count a
/// TYPED CONSEQUENCE of ONE substrate primitive
/// ([`Self::count_extremal_variants`]) under `-` on `usize` rather
/// than a composition of `T::CARDINALITY` per-target predicate calls.
/// THEORY.md §VI.1 — generation over composition; the sharpened body
/// emerges from the composition of ONE substrate primitive under
/// subtraction, not as a per-implementor hand-rolled body OR as a
/// naive filter-count sweep over [`Self::ALL`] of the per-target
/// predicate.
///
/// Frontier inspiration: R's
/// `let t <- table(items); if (length(t) == 0) 0L else sum(t > min(t) & t < max(t))`
/// on a factor histogram; Julia's
/// `let c = StatsBase.countmap(items); isempty(c) ? 0 : count(v -> minimum(values(c)) < c[v] < maximum(values(c)), keys(c)) end`
/// on a `Dict{Element, Int}` histogram (chained comparison is the
/// canonical idiom); Python's
/// `let c = collections.Counter(items); 0 if not c else sum(1 for v in c if min(c.values()) < c[v] < max(c.values()))`
/// on a Counter; Haskell's
/// `let hs = map length . group . sort $ items in if null hs then 0 else length . filter (\h -> h > minimum hs && h < maximum hs) $ hs`;
/// Clojure's
/// `(let [f (frequencies coll)] (if (empty? f) 0 (let [m (apply max (vals f)), n (apply min (vals f))] (count (filter (fn [v] (and (> (get f v 0) n) (< (get f v 0) m))) (vals f))))))`;
/// Coq's per-target
/// `List.length (List.filter (fun v => andb (Nat.ltb (min_count l) (List.count_occ eqb l v)) (Nat.ltb (List.count_occ eqb l v) (max_count l))) variants)`
/// on a decidable-equality carrier; SQL's
/// `SELECT COUNT(DISTINCT variant) FROM t WHERE variant_count > (SELECT MIN(c) FROM …) AND variant_count < (SELECT MAX(c) FROM …)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// middle-band cardinality on the closed-set trait binds through ONE
/// arithmetic subtraction on the just-lifted set-level union
/// cardinality-count aggregate via the De Morgan complement identity
/// — no new dep, no supertrait bound (the just-lifted
/// [`Self::count_extremal_variants`] aggregate replaces the `Eq`/
/// `Hash` bound the standard-library `Counter` / `frequencies` /
/// `countmap` filter-over-values signatures demand), no histogram-
/// carrier allocation, one algorithmic factor of `T::CARDINALITY`
/// shaved off the naive filter-count sweep via the De Morgan
/// complement sharpening.
fn count_middle_band_variants(items: &[Self]) -> usize {
if items.is_empty() {
0
} else {
<Self as ClosedSet>::CARDINALITY - <Self as ClosedSet>::count_extremal_variants(items)
}
}
/// The N-ARY ORDERING-AGNOSTIC "does ANY variant sit STRICTLY between the
/// two histogram extremes?" set-level existential predicate — `true` iff
/// AT LEAST ONE variant of [`Self::ALL`] carries an occurrence-count
/// strictly greater than [`Self::min_variant_count`] AND strictly less
/// than [`Self::max_variant_count`], computed as the strict-lower-bound
/// test of the just-lifted [`Self::count_middle_band_variants`]
/// cardinality-count aggregate against the scalar threshold `1`. The
/// BOOL-RETURN OPENER on the (set-level × bool × statistical-aggregate ×
/// direction-composition × complement × existential) middle-band
/// existence corner peer to [`Self::count_middle_band_variants`] one
/// RETURN-SHAPE axis over (set-level × `usize` cardinality → set-level ×
/// `bool` existential lift against `>= 1`) AND the direct SET-LEVEL
/// EXISTENTIAL LIFT of the (per-target × bool × statistical-aggregate ×
/// direction-composition × complement)
/// [`Self::is_middle_band_variant_of`] corner one ARITY axis over on the
/// modal-aggregation matrix. Not a fresh substrate primitive on the
/// index axis — the predicate emerges from one strict-lower-bound test
/// of the just-lifted [`Self::count_middle_band_variants`] scalar
/// against `1`, equivalently the disjunction over [`Self::ALL`] of the
/// per-target [`Self::is_middle_band_variant_of`] predicate. Cheaper
/// than the count on hot paths that only need an existence witness —
/// the count aggregate's `T::CARDINALITY - count_extremal` arithmetic
/// runs unchanged, but the downstream consumer binds a typed bool bit
/// against the composed threshold rather than a scalar-and-compare
/// composition.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_middle_band_variant(items) == (T::count_middle_band_variants(items) >= 1)`
/// — the set-level bool predicate is EXACTLY the strict-lower-bound
/// test of the just-lifted set-level cardinality-count aggregate against
/// the scalar threshold `1`. The canonical form the body uses. Pinned
/// by clause (147) and by
/// `has_middle_band_variant_equals_count_middle_band_variants_ge_one_across_every_triple`.
///
/// De Morgan complement identity: for every slice `items`,
/// `T::has_middle_band_variant(items) == (!items.is_empty() && T::count_extremal_variants(items) < T::CARDINALITY)`
/// — the set-level bool predicate factors through the just-lifted
/// (set-level × usize × direction-composition × union)
/// [`Self::count_extremal_variants`] cardinality-count aggregate via
/// the De Morgan complement of the (extreme / middle) partition of
/// [`Self::ALL`]: the middle band is non-empty exactly when the extreme
/// band fails to cover [`Self::ALL`] on a non-empty slice. Independent
/// cross-check distinct from the count-composition arm on the
/// compilation-shape (subtraction-then-compare vs upper-bound test)
/// axis. Pinned by
/// `has_middle_band_variant_agrees_with_de_morgan_complement_across_every_triple`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::has_middle_band_variant(items) == <T as ClosedSet>::ALL.iter().copied().any(|v| T::is_middle_band_variant_of(v, items))`
/// — the set-level bool predicate is the EXACT existential
/// quantification over [`Self::ALL`] of the per-target middle-band
/// predicate. This identity binds the set-level ARITY axis against the
/// per-target ARITY axis one arity axis over on the (arity × direction-
/// composition × complement) face, pinning the compounding closure the
/// prior per-target lift opened. Pinned by
/// `has_middle_band_variant_equals_existential_of_is_middle_band_variant_of_across_every_triple`.
///
/// Empty-or-extremal-ceiling biconditional: for every slice `items`,
/// `T::has_middle_band_variant(items) == false iff items.is_empty() || T::count_extremal_variants(items) == T::CARDINALITY`
/// — the middle-band existence bit is `false` EXACTLY when the slice
/// sits on the empty-slice endpoint OR every variant sits at some
/// extreme (equivalently, the extremal count hits its ceiling). This
/// covers the flat-histogram diagonal (where max == min collapses
/// every present variant onto both direction bands simultaneously
/// so every variant is trivially extremal), the every-target-
/// extremal fixture (e.g. `[T::ALL[0]; k]` where the sole present
/// variant sits at max and every absent variant sits at min == 0),
/// singleton slices at cardinality `>= 2`, and the empty-slice
/// endpoint. At cardinality `<= 2` no target sits strictly between
/// max and min (there is no room), so the bit stays at `false` on
/// every cardinality-`<= 2` non-empty slice; at cardinality `>= 3`
/// the bit is `true` iff there exists a target with count strictly
/// between the two extremes. Sibling posture to
/// [`Self::count_middle_band_variants`]'s empty-or-uniform-collapse
/// arm one RETURN-SHAPE axis over — that arm uses the (empty ||
/// uniform) shape as a sufficient-but-not-necessary sub-condition
/// on the same biconditional; the necessary-and-sufficient form
/// factors through the extremal-count ceiling directly. Pinned by
/// `has_middle_band_variant_is_false_iff_slice_is_empty_or_extremal_ceiling_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_middle_band_variants`] (ordering-agnostic) via a scalar
/// lower-bound test against a fixed constant. No separate
/// `sorted_has_middle_band_variant` peer is needed. Pinned by
/// `has_middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_middle_band_variant(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_middle_band_variants`] collapses to `0` at the empty-
/// slice guard, and `0 < 1`. The `false`-at-empty fixpoint pins middle-
/// band existence as a NON-EMPTINESS-REQUIRING property: an empty
/// histogram has no target to sit anywhere. Sibling posture to
/// [`Self::is_middle_band_variant_of`]'s empty-slice fixpoint one ARITY
/// axis over. Pinned by clause (147) and by
/// `has_middle_band_variant_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_middle_band_variant(&[v])` is `false` for every variant `v`
/// — the sole position hits `v` at count `1 == max` while every non-
/// target variant sits at count `0 == min`, every variant sits at some
/// extreme, [`Self::count_middle_band_variants`] reports `0`, and
/// `0 < 1`. LOAD-BEARING `false`-arm catch: no middle band on singleton
/// slices. Pinned by
/// `has_middle_band_variant_returns_false_on_every_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Full-set contract:
/// `T::has_middle_band_variant(<T as ClosedSet>::ALL)` is `false`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant pins
/// every variant at exactly one position of the full-set slice,
/// [`Self::count_middle_band_variants`] reports `0` on the flat-
/// histogram fixpoint, and `0 < 1`. Direct instance of the uniformity-
/// collapse identity above. Pinned by clause (147) and by
/// `has_middle_band_variant_returns_false_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::has_middle_band_variant(&doubled)` is `false` UNCONDITIONALLY —
/// the doubled full set hits every variant at exactly two positions
/// (max == min == 2), [`Self::count_middle_band_variants`] reports `0`
/// on the second flat-histogram fixpoint, and `0 < 1`. Sibling posture
/// to the full-set arm on the second flat-histogram fixpoint. Pinned
/// by clause (147) and by
/// `has_middle_band_variant_returns_false_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::has_middle_band_variant(&bimodal_triple)` is `true` — on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is non-flat
/// (max `2`, `T::ALL[1]` at `1` (MIDDLE), min `0`),
/// [`Self::count_middle_band_variants`] reports `1`, and `1 >= 1`.
/// LOAD-BEARING `true`-arm catch: the SOLE canonical fixpoint witness
/// the middle-band existence corner carries a `true` arm. DUAL of
/// [`Self::count_middle_band_variants`]'s `1`-arm catch on the same
/// fixture one RETURN-SHAPE axis over. Pinned by clause (147) and by
/// `has_middle_band_variant_returns_true_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the just-
/// lifted set-level middle-band cardinality aggregate
/// [`Self::count_middle_band_variants`] composed under one scalar
/// strict-lower-bound test on `usize`. The body inherits its
/// `O(T::CARDINALITY * n)` cost on slice arity `n` — one call into the
/// underlying De Morgan complement aggregate plus one comparison.
/// Allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::has_middle_band_variant`]: a `tatara-check` predicate
/// `(check-histogram-has-middle-band …)` that reports "the rollout has
/// at least one variant NEITHER over-rolled NOR under-rolled — an
/// operator-attention target exists" in ONE typed bool rather than a
/// scalar-and-compare composition; a scheduler-fairness gate that
/// branches on `has_middle_band_variant` (there is a middle band to
/// grow into or shrink from) vs `!has_middle_band_variant` (fully
/// polarized — every variant sits at some extreme) without materializing
/// the middle-band cardinality; a Sekiban audit-trail bit
/// `middle_band_exists_bit(items)` binding to the same scalar; an LSP
/// hint that surfaces "at least one variant sits strictly between the
/// histogram extremes" on a Lisp-authored variant-list without paying
/// the count aggregate on the diagnostic hot path.
///
/// Compounding closure: this projection OPENS the (set-level × bool ×
/// statistical-aggregate × direction-composition × complement ×
/// existential) middle-band existence corner peer to
/// [`Self::count_middle_band_variants`] one RETURN-SHAPE axis over
/// (set-level × usize cardinality → set-level × bool existential
/// against `>= 1`). The (set-level × bool × direction-composition) row
/// now carries the existential lift of the (extreme / middle) partition
/// on the set-level bool surface. The natural next lift past this
/// corner is:
/// * `middle_band_variants(items) -> Vec<Self>` — the (`Vec<Self>` set-
/// level statistical-aggregate declaration-order complete-witness)
/// return-shape peer of THIS `bool`-return existence bit, one RETURN-
/// SHAPE axis over. The middle-band inhabitants as a materialized
/// witness vector rather than just an existence bit. Under the
/// filter-collect composition
/// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`.
/// * `sorted_middle_band_variants(items) -> Vec<Self>` — the LEX-ORDER
/// peer of the declaration-order `middle_band_variants` corner, one
/// ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-level
/// middle-band existence predicate becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::count_middle_band_variants(items) >= 1` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × bool × middle-band × existential) corner was an
/// unnamed inline composition recurring at every prospective downstream
/// "does any variant sit strictly between the histogram extremes?" site
/// pre-lift. Naming it on the trait makes the predicate a TYPED
/// CONSEQUENCE of the substrate's just-lifted middle-band cardinality
/// aggregate under a scalar strict-lower-bound test on `usize`.
/// THEORY.md §VI.1 — generation over composition; the predicate emerges
/// from the composition of ONE substrate primitive
/// ([`Self::count_middle_band_variants`]) with a scalar strict-lower-
/// bound against `1`, not as a per-implementor hand-rolled body OR as
/// a naive filter-any sweep over [`Self::ALL`] of the per-target
/// predicate.
///
/// Frontier inspiration: R's `any(t > min(t) & t < max(t))` on a
/// factor histogram; Julia's
/// `any(v -> minimum(values(c)) < c[v] < maximum(values(c)), keys(c))`
/// on `c = StatsBase.countmap(items)`; Python's
/// `any(min(c.values()) < v < max(c.values()) for v in c.values())`
/// on `c = collections.Counter(items)` (chained comparison is the
/// canonical idiom); Haskell's
/// `any (\h -> h > minimum hs && h < maximum hs) hs`
/// on `hs = map length . group . sort $ items`; Clojure's
/// `(let [f (frequencies coll), n (apply min (vals f)), m (apply max (vals f))]
/// (some (fn [v] (and (> v n) (< v m))) (vals f)))`;
/// Coq's `existsb (fun v => andb (Nat.ltb (min_count l) (List.count_occ eqb l v))
/// (Nat.ltb (List.count_occ eqb l v) (max_count l))) variants`
/// on a decidable-equality carrier; SQL's
/// `SELECT EXISTS (SELECT 1 FROM (SELECT variant, COUNT(*) AS c FROM t
/// GROUP BY variant) x WHERE x.c > (SELECT MIN(c) FROM …) AND x.c < (SELECT MAX(c) FROM …))`.
/// Translation through pleme-io primitives: the N-ary set-level middle-
/// band existential predicate on the closed-set trait binds through
/// ONE scalar strict-lower-bound test on the just-lifted set-level
/// middle-band cardinality aggregate — no new dep, no supertrait bound
/// (the just-lifted [`Self::count_middle_band_variants`] aggregate
/// replaces the `Eq`/`Hash` bound the standard-library `Counter` /
/// `frequencies` / `countmap` any-over-values signatures demand), no
/// histogram-carrier allocation, `O(T::CARDINALITY * n)` on slice
/// arity `n` inherited verbatim from the count aggregate.
fn has_middle_band_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_middle_band_variants(items) >= 1
}
/// The N-ARY ORDERING-AGNOSTIC "does ANY variant sit on the FLAT
/// HISTOGRAM DIAGONAL?" set-level existential predicate — `true` iff
/// AT LEAST ONE variant of [`Self::ALL`] carries an occurrence-count
/// EQUAL to BOTH [`Self::min_variant_count`] AND
/// [`Self::max_variant_count`] (equivalently, the slice is non-empty
/// AND every variant sits at BOTH extremes simultaneously —
/// [`Self::is_uniform`] holds on the non-empty guard), computed as
/// the strict-lower-bound test of the just-lifted
/// [`Self::count_bimodal_variants`] cardinality-count aggregate
/// against the scalar threshold `1`. The BOOL-RETURN CLOSER on the
/// (set-level × bool × statistical-aggregate × direction-composition
/// × intersection × existential) bimodal existence corner peer to
/// [`Self::count_bimodal_variants`] one RETURN-SHAPE axis over
/// (set-level × `usize` cardinality → set-level × `bool` existential
/// lift against `>= 1`) AND the direct SET-LEVEL EXISTENTIAL LIFT of
/// the (per-target × bool × statistical-aggregate × direction-
/// composition × intersection) [`Self::is_bimodal_variant_of`] corner
/// one ARITY axis over on the modal-aggregation matrix AND peer to
/// the just-opened [`Self::has_middle_band_variant`] one DIRECTION-
/// COMPOSITION axis over (intersection `&&` arm vs the complement
/// `!extremal` arm — jointly with [`Self::has_extremal_variant`]'s
/// prospective union `||` arm the three form the set-level
/// existential trichotomy on the modal-aggregation matrix). Not a
/// fresh substrate primitive on the index axis — the predicate
/// emerges from one strict-lower-bound test of the just-lifted
/// [`Self::count_bimodal_variants`] scalar against `1`, equivalently
/// the non-empty guard AND [`Self::is_uniform`] via the uniformity-
/// collapse identity, equivalently the disjunction over
/// [`Self::ALL`] of the per-target
/// [`Self::is_bimodal_variant_of`] predicate.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_bimodal_variant(items) == (T::count_bimodal_variants(items) >= 1)`
/// — the set-level bool predicate is EXACTLY the strict-lower-bound
/// test of the just-lifted set-level cardinality-count aggregate
/// against the scalar threshold `1`. The canonical form the body
/// uses. Pinned by clause (148) and by
/// `has_bimodal_variant_equals_count_bimodal_variants_ge_one_across_every_triple`.
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::has_bimodal_variant(items) == (!items.is_empty() && T::is_uniform(items))`
/// — the set-level bool predicate collapses to the CONJUNCTION of a
/// non-empty guard AND the just-lifted (set-level × bool ×
/// statistical-aggregate) [`Self::is_uniform`] projection via the
/// two-value dichotomy of [`Self::count_bimodal_variants`] (image
/// `{0, T::CARDINALITY}` — the count reaches `T::CARDINALITY >= 1`
/// exactly on non-empty flat-histogram slices, `0` otherwise). This
/// identity binds the intersection-arm existence bit against the
/// pre-existing bool-return uniformity primitive one FACTORING axis
/// over — the (set-level × bool × direction-composition ×
/// intersection × existential) corner factors CLEANLY through the
/// (set-level × bool × statistical-aggregate) [`Self::is_uniform`]
/// corner past a non-empty guard, so any downstream consumer that
/// wants "is the histogram flat on a non-empty slice?" binds to ONE
/// typed bool bit without materializing the intersection count.
/// Independent cross-check distinct from the count-composition arm
/// on the compilation-shape (count-and-compare vs uniformity-and-
/// nonempty conjunction) axis. Pinned by
/// `has_bimodal_variant_agrees_with_uniformity_collapse_across_every_triple`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::has_bimodal_variant(items) == <T as ClosedSet>::ALL.iter().copied().any(|v| T::is_bimodal_variant_of(v, items))`
/// — the set-level bool predicate is the EXACT existential
/// quantification over [`Self::ALL`] of the per-target bimodal
/// predicate. This identity binds the set-level ARITY axis against
/// the per-target ARITY axis one arity axis over on the (arity ×
/// direction-composition × intersection) face, pinning the
/// compounding closure the prior per-target lift opened. Pinned by
/// `has_bimodal_variant_equals_existential_of_is_bimodal_variant_of_across_every_triple`.
///
/// Middle-band De Morgan identity: for every NON-EMPTY slice
/// `items`, `T::has_bimodal_variant(items) == !T::has_middle_band_variant(items) && T::is_uniform(items)`
/// EQUIVALENTLY `T::has_bimodal_variant(items) => !T::has_middle_band_variant(items)`
/// — on non-empty slices the bimodal-existence bit implies the
/// absence of a middle-band inhabitant (flat-histogram slices have
/// NO strict-between count), while the reverse implication requires
/// the additional non-flat-vs-flat discrimination that the
/// [`Self::is_uniform`] projection carries. The two set-level
/// existential bits sit on opposite sides of the (intersection /
/// complement) axis of the direction-composition face. Pinned by
/// `has_bimodal_variant_and_has_middle_band_variant_are_mutually_exclusive_on_non_empty_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_bimodal_variants`] (ordering-agnostic) via a scalar
/// lower-bound test against a fixed constant. No separate
/// `sorted_has_bimodal_variant` peer is needed. Pinned by
/// `has_bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_bimodal_variant(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_bimodal_variants`] collapses to `0` at the empty-
/// slice guard past the vacuous flat-histogram arm (an unguarded
/// scalar branch would silently return `T::CARDINALITY >= 1` on the
/// empty slice because `min == max == 0` reads as trivially flat),
/// and `0 < 1`. The `false`-at-empty fixpoint pins bimodal existence
/// as a NON-EMPTINESS-REQUIRING property: an empty histogram has no
/// target to sit anywhere. Sibling posture to
/// [`Self::has_middle_band_variant`]'s empty-slice fixpoint one
/// DIRECTION-COMPOSITION axis over. Pinned by clause (148) and by
/// `has_bimodal_variant_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_bimodal_variant(&[v])` is `false` for every variant `v`
/// — the sole position hits `v` at count `1 == max` while every non-
/// target variant sits at count `0 == min`, the histogram is non-
/// flat (max `1` != min `0`), [`Self::is_uniform`] reports `false`,
/// [`Self::count_bimodal_variants`] reports `0`, and `0 < 1`. LOAD-
/// BEARING `false`-arm catch on the intersection existence corner
/// separating it from the (prospective) union-arm sibling
/// `has_extremal_variant` which reports `true` on the same fixture
/// (some variant IS at some extreme — indeed every variant is
/// extremal on the singleton fixture). Pinned by
/// `has_bimodal_variant_returns_false_on_every_matching_singleton_at_cardinality_gte_two_across_every_variant`.
///
/// Full-set contract:
/// `T::has_bimodal_variant(<T as ClosedSet>::ALL)` is `true`
/// UNCONDITIONALLY on every implementor of non-zero cardinality —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// at exactly one position of the full-set slice, [`Self::is_uniform`]
/// reports `true` on the flat-histogram fixpoint (max == min == 1),
/// [`Self::count_bimodal_variants`] reports `T::CARDINALITY >= 1`,
/// and `T::CARDINALITY >= 1`. LOAD-BEARING `true`-arm catch:
/// canonical fixpoint witness that the intersection existence
/// corner carries a `true` arm — every variant of [`Self::ALL`]
/// sits on the flat diagonal of the full-set histogram. Pinned by
/// clause (148) and by
/// `has_bimodal_variant_returns_true_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::has_bimodal_variant(&doubled)` is `true` on every implementor
/// of non-zero cardinality — the doubled full set hits every variant
/// at exactly two positions, [`Self::is_uniform`] reports `true` on
/// the second flat-histogram fixpoint (max == min == 2),
/// [`Self::count_bimodal_variants`] reports `T::CARDINALITY >= 1`,
/// and `T::CARDINALITY >= 1`. Sibling posture to the full-set arm on
/// the second flat-histogram fixpoint; together the two flat-
/// histogram fixpoints demonstrate the projection is INVARIANT under
/// uniform slice-multiplication. Pinned by clause (148) and by
/// `has_bimodal_variant_returns_true_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::has_bimodal_variant(&bimodal_triple)` is `false` — on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is non-flat
/// (max `2`, min `0`), [`Self::is_uniform`] reports `false`,
/// [`Self::count_bimodal_variants`] reports `0`, and `0 < 1`. LOAD-
/// BEARING `false`-arm catch on the non-flat middle-band fixture
/// distinguishing this intersection existence corner from the
/// (prospective) union existence corner `has_extremal_variant` which
/// reports `true` on the same fixture (T::ALL[0] IS at max). DUAL of
/// [`Self::has_middle_band_variant`]'s `true`-arm catch on the same
/// fixture one DIRECTION-COMPOSITION axis over. Pinned by clause
/// (148) and by
/// `has_bimodal_variant_returns_false_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the just-
/// lifted set-level intersection cardinality aggregate
/// [`Self::count_bimodal_variants`] composed under one scalar
/// strict-lower-bound test on `usize`. The body inherits its
/// `O(T::CARDINALITY * n)` cost on slice arity `n` — one call into
/// the underlying uniformity-collapse aggregate plus one comparison.
/// Allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::has_bimodal_variant`]: a `tatara-check` predicate
/// `(check-histogram-is-flat …)` that reports "every phase of the
/// rollout window sits at the same count — the rollout is fully
/// balanced" in ONE typed bool rather than a count-and-compare
/// composition OR a bare [`Self::is_uniform`] call that fails to
/// distinguish the (empty) endpoint from a genuinely flat non-empty
/// slice; a scheduler-fairness gate that branches on
/// `has_bimodal_variant` (the rollout hit the flat diagonal — no
/// further smoothing needed) vs `!has_bimodal_variant` (some variant
/// sits off the diagonal — smoothing is still needed) without
/// materializing the intersection cardinality; a Sekiban audit-trail
/// bit `flat_diagonal_bit(items)` binding to the same scalar; an LSP
/// hint that surfaces "every variant sits at the same count on this
/// slice" on a Lisp-authored variant-list without paying the count
/// aggregate on the diagnostic hot path.
///
/// Compounding closure: this projection CLOSES the (set-level × bool
/// × statistical-aggregate × direction-composition × intersection ×
/// existential) bimodal existence corner peer to
/// [`Self::count_bimodal_variants`] one RETURN-SHAPE axis over
/// (set-level × usize cardinality → set-level × bool existential
/// against `>= 1`) AND peer to [`Self::has_middle_band_variant`] one
/// DIRECTION-COMPOSITION axis over. The (set-level × bool ×
/// direction-composition × existential) row now carries the (`&&`,
/// `!extremal`) pair of aligned existential bits — flat-diagonal
/// existence (THIS) and middle-band existence — with a shared
/// count-composition body. The natural next lift on the same face is
/// the DISJUNCTION arm `has_extremal_variant(items) -> bool` (the
/// set-level existential lift of [`Self::is_extremal_variant_of`])
/// — that corner collapses to `!items.is_empty()` on any implementor
/// because every non-empty slice has an argmax target (guaranteeing
/// an extremal-witness), so the corner sharpens to the trivial non-
/// emptiness bit rather than paying the union cardinality aggregate.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level bimodal existence predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::count_bimodal_variants(items) >= 1` composition OR
/// `!items.is_empty() && T::is_uniform(items)` conjunction at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × bool × intersection × existential) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "is the histogram flat on a non-empty slice?" site
/// pre-lift. Naming it on the trait makes the predicate a TYPED
/// CONSEQUENCE of the substrate's just-lifted intersection
/// cardinality aggregate under a scalar strict-lower-bound test on
/// `usize`. THEORY.md §VI.1 — generation over composition; the
/// predicate emerges from the composition of ONE substrate primitive
/// ([`Self::count_bimodal_variants`]) with a scalar strict-lower-
/// bound against `1`, not as a per-implementor hand-rolled body OR
/// as a naive filter-any sweep over [`Self::ALL`] of the per-target
/// predicate.
///
/// Frontier inspiration: R's `!is.null(t) && max(t) == min(t) && length(t) > 0`
/// on `t <- table(items)`; Julia's `!isempty(c) && allequal(values(c))`
/// on `c = StatsBase.countmap(items)`; Python's
/// `bool(c) and (max(c.values()) == min(c.values()))` on
/// `c = collections.Counter(items)`; Haskell's
/// `not (null hs) && all (== head hs) hs where hs = map length . group . sort $ items`;
/// Clojure's `(let [f (frequencies coll)] (and (seq f) (apply = (vals f))))`;
/// Coq's `andb (negb (Nat.eqb 0 (List.length l))) (existsb (fun v => Nat.eqb (max_count l) (List.count_occ eqb l v) && Nat.eqb (min_count l) (List.count_occ eqb l v)) variants)`
/// on a decidable-equality carrier; SQL's
/// `SELECT EXISTS (SELECT 1 FROM t GROUP BY variant HAVING COUNT(*) IN (SELECT MAX(c), MIN(c) FROM …) AND MAX(c) = MIN(c))`.
/// Translation through pleme-io primitives: the N-ary set-level
/// bimodal existential predicate on the closed-set trait binds
/// through ONE scalar strict-lower-bound test on the just-lifted
/// set-level intersection cardinality aggregate — no new dep, no
/// supertrait bound (the just-lifted [`Self::count_bimodal_variants`]
/// aggregate replaces the `Eq`/`Hash` bound the standard-library
/// `Counter` / `frequencies` / `countmap` any-over-values signatures
/// demand), no histogram-carrier allocation, `O(T::CARDINALITY * n)`
/// on slice arity `n` inherited verbatim from the count aggregate.
fn has_bimodal_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_bimodal_variants(items) >= 1
}
/// The N-ARY ORDERING-AGNOSTIC "does ANY variant sit at EITHER
/// histogram extreme?" set-level existential predicate — `true` iff
/// AT LEAST ONE variant of [`Self::ALL`] carries an occurrence-count
/// EQUAL to EITHER [`Self::min_variant_count`] OR
/// [`Self::max_variant_count`], SHARPENED via the union-arm non-
/// emptiness collapse: on ANY non-empty slice the argmax band is
/// non-empty (SOME variant achieves the max count `>= 1`, and that
/// variant is trivially at the argmax extreme via
/// [`Self::is_modal_variant_of`], so
/// [`Self::is_extremal_variant_of`] holds on it via the disjunction
/// arm), and the empty slice has no target to sit anywhere. The
/// BOOL-RETURN CLOSER on the (set-level × bool × statistical-
/// aggregate × direction-composition × union × existential) extremal
/// existence corner peer to [`Self::count_extremal_variants`] one
/// RETURN-SHAPE axis over (set-level × `usize` cardinality → set-
/// level × `bool` existential lift against `>= 1`) AND the direct
/// SET-LEVEL EXISTENTIAL LIFT of the (per-target × bool ×
/// statistical-aggregate × direction-composition × union)
/// [`Self::is_extremal_variant_of`] corner one ARITY axis over on
/// the modal-aggregation matrix AND peer to
/// [`Self::has_middle_band_variant`] +
/// [`Self::has_bimodal_variant`] one DIRECTION-COMPOSITION axis
/// over — the three form the set-level existential trichotomy on
/// the modal-aggregation matrix (union / intersection / complement
/// of the two direction-anchored membership predicates). Not a
/// fresh substrate primitive on the index axis — the predicate
/// collapses to the pre-existing standard-library
/// `!<[Self]>::is_empty()` slice-empty bit past a NON-EMPTINESS
/// COLLAPSE proof; the count-composition body
/// `T::count_extremal_variants(items) >= 1` and the existential-
/// lift body `T::ALL.iter().any(|v| T::is_extremal_variant_of(v, items))`
/// are the equivalent-but-slower canonical forms the identities
/// pin against.
///
/// Non-emptiness collapse identity: for every slice `items`,
/// `T::has_extremal_variant(items) == !items.is_empty()` — the
/// canonical form the body uses. The set-level union-arm existence
/// bit SHARPENS to the bare non-emptiness bit because the argmax
/// band is INHABITED on every non-empty slice (the histogram
/// admits a max count `>= 1` at some variant, and that variant is
/// extremal via the union arm), while the empty slice reports
/// `false` at every variant of [`Self::ALL`] under both direction-
/// anchored membership predicates. Cost: `O(1)` on the slice
/// pointer-header check — one algorithmic factor of
/// `T::CARDINALITY * n` shaved off the count-composition sweep,
/// one factor of `T::CARDINALITY * n` shaved off the naive
/// existential-lift sweep. Pinned by clause (149) and by
/// `has_extremal_variant_equals_slice_non_emptiness_across_every_triple`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_extremal_variant(items) == (T::count_extremal_variants(items) >= 1)`
/// — the (union × existential) bit is EXACTLY the strict-lower-
/// bound test of the just-lifted set-level union cardinality
/// aggregate against the scalar threshold `1`. The equivalent-but-
/// slower canonical form pre-SHARPENING. Independent cross-check
/// distinct from the non-emptiness collapse arm on the
/// compilation-shape (count-and-compare vs slice-header-test)
/// axis. Pinned by
/// `has_extremal_variant_equals_count_extremal_variants_ge_one_across_every_triple`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::has_extremal_variant(items) == <T as ClosedSet>::ALL.iter().copied().any(|v| T::is_extremal_variant_of(v, items))`
/// — the set-level bool predicate is the EXACT existential
/// quantification over [`Self::ALL`] of the per-target extremal
/// predicate. This identity binds the set-level ARITY axis
/// against the per-target ARITY axis one arity axis over on the
/// (arity × direction-composition × union) face, pinning the
/// compounding closure the prior per-target lift opened. Pinned
/// by `has_extremal_variant_equals_existential_of_is_extremal_variant_of_across_every_triple`.
///
/// Trichotomy composition-equality on non-empty slices: for every
/// NON-EMPTY slice `items`,
/// `T::has_extremal_variant(items) == (T::has_bimodal_variant(items) || T::has_middle_band_variant(items) || (!T::has_bimodal_variant(items) && !T::has_middle_band_variant(items)))`
/// EQUIVALENTLY `T::has_extremal_variant(items) == true`
/// on every non-empty slice — the union-arm existence bit
/// SATURATES the non-empty domain, so the (intersection ×
/// existential) and (complement × existential) bits partition its
/// `true` arm on non-empty slices without ever making the union-
/// arm `false`. The three bits form the set-level existential
/// trichotomy on the modal-aggregation matrix: `has_extremal_variant`
/// (union, always `true` on non-empty) subsumes both
/// `has_bimodal_variant` (intersection, `true` iff flat-diagonal)
/// and `has_middle_band_variant` (complement, `true` iff strict-
/// interior inhabitant), which are mutually exclusive on non-
/// empty slices via the (intersection / complement) De Morgan
/// split. Pinned by
/// `has_extremal_variant_subsumes_has_bimodal_variant_or_has_middle_band_variant_on_non_empty_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through the
/// standard-library `<[Self]>::is_empty` slice-header bit which is
/// trivially reversal-invariant (reversing a slice preserves its
/// length). No separate `sorted_has_extremal_variant` peer is
/// needed. Pinned by
/// `has_extremal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_extremal_variant(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions, both
/// direction-anchored membership predicates
/// [`Self::is_modal_variant_of`] + [`Self::is_antimodal_variant_of`]
/// report `false` at every target on their shared non-emptiness
/// guards, so [`Self::is_extremal_variant_of`] reports `false` at
/// every target under the disjunction arm, and the existential
/// sweep over [`Self::ALL`] reports `false`; equivalently
/// [`Self::count_extremal_variants`] returns `0` at the empty-
/// slice guard, and `0 < 1`. The `false`-at-empty fixpoint pins
/// extremal existence as a NON-EMPTINESS-REQUIRING property: an
/// empty histogram has no target to sit anywhere. LOAD-BEARING
/// `false`-arm catch — the SOLE canonical fixture witness the
/// union existence corner has a `false` arm; every non-empty
/// slice witnesses the `true` arm past the non-emptiness
/// collapse. Sibling posture to [`Self::has_bimodal_variant`]'s +
/// [`Self::has_middle_band_variant`]'s empty-slice fixpoints one
/// DIRECTION-COMPOSITION axis over (all three set-level bits
/// share the empty-slice `false` fixpoint under the non-emptiness
/// guard). Pinned by clause (149) and by
/// `has_extremal_variant_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_extremal_variant(&[v])` is `true` for every variant `v`
/// — the sole position hits `v` at count `1 == max` while every
/// non-target variant sits at count `0 == min`; the target `v` is
/// extremal at the argmax band under [`Self::is_modal_variant_of`],
/// so [`Self::is_extremal_variant_of`] holds on `v` under the
/// disjunction arm (indeed every variant is extremal on the
/// singleton fixture — the two extremes coincide over the two-
/// value dichotomy on the sparse histogram), and the existential
/// sweep over [`Self::ALL`] hits `v` (equivalently, [`Self::count_extremal_variants`]
/// reports `T::CARDINALITY >= 1`, and `T::CARDINALITY >= 1`).
/// LOAD-BEARING `true`-arm catch DISCRIMINATING this union
/// existence corner from [`Self::has_bimodal_variant`] which
/// reports `false` on the same fixture at cardinality `>= 2` (the
/// non-flat sparse histogram has no flat-diagonal inhabitant even
/// though every variant is extremal). Pinned by
/// `has_extremal_variant_returns_true_on_every_matching_singleton_across_every_variant`.
///
/// Full-set contract:
/// `T::has_extremal_variant(<T as ClosedSet>::ALL)` is `true`
/// UNCONDITIONALLY on every implementor of non-zero cardinality —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// at exactly one position of the full-set slice, [`Self::is_uniform`]
/// reports `true` on the flat-histogram fixpoint (max == min == 1),
/// every variant sits at BOTH extremes simultaneously and is
/// therefore extremal, [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY >= 1`, and `T::CARDINALITY >= 1`. Sibling
/// posture to [`Self::has_bimodal_variant`]'s + [`Self::has_middle_band_variant`]'s
/// full-set fixpoints one DIRECTION-COMPOSITION axis over (the
/// (union, intersection, complement) triple at (`true`, `true`,
/// `false`) on the flat-histogram fixpoint witnesses the (union ⊇
/// intersection) subsumption + the (union ⊇ complement)
/// subsumption simultaneously). Pinned by clause (149) and by
/// `has_extremal_variant_returns_true_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::has_extremal_variant(&doubled)` is `true` on every
/// implementor of non-zero cardinality — the doubled full set hits
/// every variant at exactly two positions, the flat-histogram
/// fixpoint at count `2` makes every variant extremal via the
/// (max == min == 2) collapse, and [`Self::count_extremal_variants`]
/// reports `T::CARDINALITY >= 1`. Sibling posture to the full-set
/// arm on the second flat-histogram fixpoint; together the two
/// flat-histogram fixpoints demonstrate the projection is
/// INVARIANT under uniform slice-multiplication. Pinned by clause
/// (149) and by
/// `has_extremal_variant_returns_true_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::has_extremal_variant(&bimodal_triple)` is `true` — on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is non-flat
/// (max `2`, min `0`), T::ALL[0] sits at the argmax band and
/// T::ALL[2..] sits at the argmin band, so at LEAST two variants
/// (indeed [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY - 1`) are extremal, and the existential sweep
/// hits either. LOAD-BEARING `true`-arm catch on the non-flat
/// middle-band fixture DISCRIMINATING this union existence corner
/// from [`Self::has_bimodal_variant`] which reports `false` on the
/// same fixture (the non-flat histogram has no flat-diagonal
/// inhabitant). Pinned by clause (149) and by
/// `has_extremal_variant_returns_true_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// standard-library `<[Self]>::is_empty` slice-header bit under
/// one boolean negation, SHARPENED past the count-composition body
/// `T::count_extremal_variants(items) >= 1` via the non-emptiness
/// collapse identity that binds the union-arm existence bit
/// against the bare non-emptiness bit. The body inherits its
/// `O(1)` cost on slice arity `n` — one pointer-header check plus
/// one boolean negation. Allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// histogram-carrier allocation, no call into the underlying count
/// aggregate or per-target predicate sweep. One algorithmic factor
/// of `T::CARDINALITY * n` shaved off the count-composition sweep,
/// one factor of `T::CARDINALITY * n` shaved off the naive
/// existential-lift sweep.
///
/// Future consumers that compose against
/// [`Self::has_extremal_variant`]: a `tatara-check` predicate
/// `(check-window-has-extreme …)` that reports "the rollout window
/// carries at least one phase at an extreme count" in ONE typed
/// bool without paying the count aggregate — since every non-
/// empty window carries an argmax phase, the predicate reduces to
/// the non-emptiness guard the consumer already knows to check;
/// a scheduler-fairness gate that early-exits on
/// `!has_extremal_variant` (the workload buffer is empty — no
/// smoothing to consider) vs `has_extremal_variant` (there is at
/// least one target sitting at an extreme — the smoothing pass
/// proceeds with a trivial non-emptiness guarantee); a Sekiban
/// audit-trail bit `saw_extreme_bit(items)` binding to the same
/// scalar as `saw_any_bit(items)` on non-empty windows, revealing
/// the two bits are IDENTICAL past the non-emptiness collapse; an
/// LSP hint that surfaces "this Lisp-authored variant-list has at
/// least one variant at an extreme" on a Lisp-authored variant-
/// list — SHARPENED to the bare non-emptiness guard on the
/// diagnostic hot path so the hint fires without paying any
/// histogram traversal.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// bool × statistical-aggregate × direction-composition × union ×
/// existential) extremal existence corner peer to
/// [`Self::count_extremal_variants`] one RETURN-SHAPE axis over
/// (set-level × usize cardinality → set-level × bool existential
/// against `>= 1`) AND peer to
/// [`Self::has_bimodal_variant`] +
/// [`Self::has_middle_band_variant`] one DIRECTION-COMPOSITION
/// axis over — the three bits now form the (set-level × bool ×
/// direction-composition × existential) TRICHOTOMY (union /
/// intersection / complement) on the modal-aggregation matrix
/// with sharpened bodies at every corner (`!items.is_empty()`,
/// `count_bimodal_variants >= 1`, `count_middle_band_variants >= 1`).
/// The natural next lifts past this closure are the ORDERING-
/// AGNOSTIC arity peers — `first_extremal_variant(items) -> Option<Self>`
/// (the argmax first-witness on non-empty slices), and
/// `extremal_variants(items) -> Vec<Self>` (the full argmax-argmin
/// enumeration on the (arity × ordering) grid) — each emerges by
/// composing the just-closed direction-composition trichotomy
/// under a witness-extraction combinator.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level extremal existence predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `!items.is_empty()` guard that duplicates the argmax-
/// inhabited-on-non-empty proof at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (set-level × bool ×
/// union × existential) corner was an unnamed inline SHARPENING
/// recurring at every prospective downstream "is some variant at
/// some extreme?" site pre-lift — naming it on the trait makes
/// the SHARPENING a TYPED CONSEQUENCE of the substrate's non-
/// emptiness collapse identity rather than a hand-rolled `O(1)`
/// short-circuit past the `O(T::CARDINALITY * n)` count
/// aggregate. THEORY.md §VI.1 — generation over composition; the
/// predicate emerges from the negation of the standard-library
/// slice-empty bit past a proof-carrying SHARPENING (the argmax
/// non-emptiness on non-empty slices), not as a per-implementor
/// hand-rolled body OR as a naive filter-any sweep over
/// [`Self::ALL`] of the per-target predicate.
///
/// Frontier inspiration: R's `length(items) > 0` on any
/// countmap; Julia's `!isempty(items)` past `!isempty(c) &&
/// (max(values(c)) == count(v) || min(values(c)) == count(v)) for
/// some v`; Python's `bool(items)` past
/// `bool(c) and any(c.get(v, 0) in (max(c.values()), min(c.values())) for v in variants)`;
/// Haskell's `not (null items)` past
/// `let hs = map length . group . sort $ items in any (\h -> h == maximum hs || h == minimum hs) hs`;
/// Clojure's `(seq items)` past
/// `(let [f (frequencies items), m (apply max (vals f)), n (apply min (vals f))] (some #(or (= (get f % 0) m) (= (get f % 0) n)) (keys f)))`;
/// SQL's `EXISTS (SELECT 1 FROM t)` past
/// `EXISTS (SELECT 1 FROM t GROUP BY variant HAVING COUNT(*) IN (SELECT MAX(c), MIN(c) FROM …))`.
/// Translation through pleme-io primitives: the N-ary set-level
/// extremal existential predicate on the closed-set trait binds
/// through ONE standard-library `<[Self]>::is_empty` slice-header
/// check under one boolean negation past a proof-carrying
/// SHARPENING — no new dep, no supertrait bound (the standard-
/// library `<[Self]>::is_empty` replaces the `Eq`/`Hash` bound the
/// standard-library `Counter` / `frequencies` / `countmap` any-
/// over-values signatures demand), no histogram-carrier
/// allocation, `O(1)` on slice arity `n` (one algorithmic factor
/// of `T::CARDINALITY * n` shaved off the count-composition sweep,
/// one factor of `T::CARDINALITY * n` shaved off the naive
/// existential-lift sweep).
fn has_extremal_variant(items: &[Self]) -> bool {
!items.is_empty()
}
/// The N-ARY ORDERING-AGNOSTIC "extremal variants" projection — the
/// `Vec<Self>` DECLARATION-ORDER witness-collection of EVERY variant
/// of [`Self::ALL`] for which [`Self::is_extremal_variant_of`] holds
/// against `items` (equivalently, whose per-slot count equals EITHER
/// [`Self::max_variant_count`] OR [`Self::min_variant_count`]),
/// preserving [`Self::ALL`]'s canonical declaration order and
/// returning the empty vector when `items` is empty. The DIRECTION-
/// COMPOSITION UNION opener on the (set-level × `Vec<Self>` ×
/// statistical-aggregate × direction-composition × union) corner
/// past the direction-anchored [`Self::modal_variants`] +
/// [`Self::antimodal_variants`] pair one DIRECTION-COMPOSITION axis
/// over. Direct SET-LEVEL ARITY LIFT of the (per-target × bool ×
/// direction-composition × union) [`Self::is_extremal_variant_of`]
/// corner one ARITY axis over, AND peer to
/// [`Self::count_extremal_variants`] one RETURN-SHAPE axis over
/// (`usize` cardinality → `Vec<Self>` witness-collection). Not a
/// fresh substrate primitive on the index axis — the projection
/// emerges from ONE `is_empty()` guard AND ONE max/min-fold pair AND
/// ONE `T::CARDINALITY`-bounded filter sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the pair, guarded so `&[]`
/// maps to `Vec::new()` past the (max == min == 0, every-count == 0)
/// degenerate arm where an unguarded sweep would silently return
/// `T::ALL.to_vec()`.
///
/// Union-composition identity: for every slice `items`,
/// `T::extremal_variants(items)` equals the DECLARATION-ORDER union
/// of [`Self::modal_variants`]`(items)` and
/// [`Self::antimodal_variants`]`(items)` as a subset of
/// [`Self::ALL`] — every element of either direction-anchored
/// witness-collection appears in the extremal collection, and every
/// element of the extremal collection appears in at least one of the
/// two direction-anchored collections. The two sides agree as
/// declaration-order-walked subsets of [`Self::ALL`]. Pinned by
/// `extremal_variants_agrees_with_union_of_modal_and_antimodal_variants_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::extremal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// — the sharpened max/min-fold body agrees with the naive filter
/// over [`Self::ALL`] of the per-target predicate. Independent
/// cross-check on the composition-shape (max/min-fold-pair vs
/// per-target predicate sweep) axis. Pinned by
/// `extremal_variants_agrees_with_filter_of_is_extremal_variant_of_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::extremal_variants(items).len() == T::count_extremal_variants(items)`
/// — the plural's LEN equals the just-lifted set-level union
/// cardinality because both projections filter [`Self::ALL`] under
/// the same direction-composition predicate. Pinned by
/// `extremal_variants_len_agrees_with_count_extremal_variants_across_every_triple`.
///
/// Non-emptiness identity: `T::extremal_variants(items).is_empty()`
/// iff `items.is_empty()` — on the empty slice the guard maps to
/// `Vec::new()`; on every non-empty slice
/// [`Self::max_variant_count`] `>= 1` is achieved by at least one
/// variant, so the filter hits that variant at the argmax band.
/// Pinned by
/// `extremal_variants_is_non_empty_iff_slice_is_non_empty_across_every_triple`.
///
/// Uniformity-collapse identity: on every NON-EMPTY slice `items` on
/// which [`Self::is_uniform`] holds (max == min),
/// `T::extremal_variants(items) == T::ALL.to_vec()` — the direction
/// axis on flat-histogram slices COLLAPSES so every variant is at
/// BOTH extremes simultaneously and the filter hits every variant.
///
/// Ordering-axis invariance: the projection factors through the
/// ordering-agnostic [`Self::max_variant_count`] +
/// [`Self::min_variant_count`] fold pair and walks [`Self::ALL`] in
/// declaration order; permuting `items` preserves its variant
/// multiset, so the filter is a function of that multiset alone.
/// Pinned by
/// `extremal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::extremal_variants(&[])` is the empty
/// `Vec<Self>` UNCONDITIONALLY — the empty guard is LOAD-BEARING
/// past the (max == min == 0, every-count == 0) degenerate arm
/// where an unguarded sweep would silently return `T::ALL.to_vec()`.
///
/// Full-set contract:
/// `T::extremal_variants(<T as ClosedSet>::ALL) == T::ALL.to_vec()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, max == min == 1, and
/// the filter hits EVERY variant walked in declaration order.
///
/// Doubled-full-set contract:
/// `T::extremal_variants(&doubled)` equals `T::ALL.to_vec()` — the
/// second flat-histogram fixpoint at count `2`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::extremal_variants(&[v]) == T::ALL.to_vec()` for every variant
/// `v` — the sole position hits `v` at count `1 == max` and every
/// non-target variant sits at count `0 == min`, so every variant is
/// extremal via one of the two arms. LOAD-BEARING contract
/// separating this UNION projection from [`Self::modal_variants`]
/// which reports `[v]` on the same fixture (only the argmax
/// variant).
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the middle-band target `T::ALL[1]` is EXCLUDED and
/// every other variant is included, so
/// `T::extremal_variants(&bimodal_triple)` equals every variant of
/// [`Self::ALL`] EXCEPT `T::ALL[1]` walked in declaration order,
/// with length `T::CARDINALITY - 1`. LOAD-BEARING catch on the non-
/// flat middle-band fixture — the SOLE canonical fixture witness
/// this projection returns a PROPER subset of [`Self::ALL`], not
/// the full carrier.
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::max_variant_count`] fold + ONE [`Self::min_variant_count`]
/// fold + ONE [`Self::CARDINALITY`]-bounded filter sweep against
/// [`Self::count_occurrences_of`]. The sweep costs
/// `O(T::CARDINALITY * n)` on slice arity `n` — strictly beats the
/// naive `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v,
/// items)).collect()` sweep which pays `O(T::CARDINALITY² * n)` (the
/// per-target predicate re-derives the max and min folds internally
/// once per variant). Allocation of one output `Vec` of at most
/// [`Self::CARDINALITY`] entries; no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no histogram-carrier
/// allocation (the sweep streams through per-target counts one at a
/// time and commits at each hit).
///
/// Future consumers that compose against [`Self::extremal_variants`]:
/// a `tatara-check` predicate `(check-phases-extremal …)` that
/// enumerates EVERY `WorkloadPhase` sitting at some histogram
/// extreme in a rollout window; an LSP diagnostic that surfaces the
/// complete union witness-collection as an author-facing "at some
/// extreme: `<label1>`, `<label2>`" hint (distinct from the argmax-
/// only [`Self::modal_variants`] hint one COMBINATOR axis over); a
/// Sekiban audit-trail per-window extremal witness-collection gauge
/// alongside the direction-anchored [`Self::modal_variants`] +
/// [`Self::antimodal_variants`] pair. Each binds to ONE typed
/// `Vec<Self>`-return direction-composition union witness-
/// collection on the trait rather than re-deriving the max/min-
/// fold-guarded filter inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction-composition ×
/// union) corner past the direction-anchored pair
/// [`Self::modal_variants`] and [`Self::antimodal_variants`],
/// aligned with the just-closed (set-level × usize × direction-
/// composition) row via [`Self::count_extremal_variants`] one
/// RETURN-SHAPE axis over. The natural next lifts past this
/// closure are:
///
/// * `sorted_extremal_variants(items) -> Vec<Self>` — the LEX-
/// ORDER peer one ORDERING axis over, closing the (set-level ×
/// `Vec<Self>` × direction-composition × union × ordering) 2-
/// corner face at its lex arm.
/// * `middle_band_variants(items) -> Vec<Self>` — the De Morgan
/// COMPLEMENT one COMBINATOR axis over, via
/// `T::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// equivalently the declaration-order set-difference
/// `T::ALL.to_vec()` minus `T::extremal_variants(items)` on non-
/// empty slices.
/// * `bimodal_variants(items) -> Vec<Self>` — the INTERSECTION
/// peer one COMBINATOR axis over, opening the flat-diagonal Vec-
/// return witness collection.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level union witness-collection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × union) corner
/// was an unnamed inline SHARPENING recurring at every prospective
/// downstream "which variants sit at some extreme?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the sharpened
/// body emerges from the composition of THREE substrate primitives
/// ([`Self::max_variant_count`], [`Self::min_variant_count`],
/// [`Self::count_occurrences_of`]) filtered over [`Self::ALL`] with
/// an `into_iter().filter().collect()` combinator.
///
/// Frontier inspiration: R's `names(table(items))[table(items) ==
/// max(table(items)) | table(items) == min(table(items))]` on a
/// factor histogram; Julia's
/// `[k for (k, v) in StatsBase.countmap(items) if v == maximum(values(c)) || v == minimum(values(c))]`;
/// Python's `[k for k, v in collections.Counter(items).items() if
/// v in (max(c.values()), min(c.values()))]`; Haskell's
/// `map fst . filter (\(_, n) -> n == maximum ns || n == minimum ns) $ hist`;
/// Clojure's `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f))] (filter #(let [c (get f % 0)] (or (= c m) (= c n))) (keys f)))`.
/// Translation through pleme-io primitives: the N-ary `Vec<Self>`-
/// return declaration-order direction-composition union witness-
/// collection on the closed-set trait binds through
/// [`Self::max_variant_count`] + [`Self::min_variant_count`] +
/// [`Self::count_occurrences_of`] under one filter over
/// [`Self::ALL`] — no new dep, no supertrait bound (the max/min
/// pair replaces the `Eq`/`Hash` bound the standard-library
/// `Counter` / `frequencies` / `countmap` signatures demand), no
/// histogram-carrier allocation, one algorithmic factor of
/// `T::CARDINALITY` shaved off the naive filter sweep via the
/// max/min-fold sharpening.
fn extremal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c == max || c == min
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "middle-band variants" projection — the
/// `Vec<Self>` DECLARATION-ORDER witness-collection of EVERY variant of
/// [`Self::ALL`] for which [`Self::is_middle_band_variant_of`] holds
/// against `items` (equivalently, whose per-slot count sits STRICTLY
/// between [`Self::min_variant_count`] and [`Self::max_variant_count`]),
/// preserving [`Self::ALL`]'s canonical declaration order and returning
/// the empty vector when `items` is empty. The DIRECTION-COMPOSITION
/// COMPLEMENT closer on the (set-level × `Vec<Self>` × statistical-
/// aggregate × direction-composition × complement) corner CLOSING the
/// (set-level × `Vec<Self>` × direction-composition) row past the
/// direction-anchored [`Self::modal_variants`] + [`Self::antimodal_variants`]
/// pair AND the just-opened UNION arm [`Self::extremal_variants`] one
/// DIRECTION-COMPOSITION axis over. Direct SET-LEVEL ARITY LIFT of the
/// (per-target × bool × direction-composition × complement)
/// [`Self::is_middle_band_variant_of`] corner one ARITY axis over, AND
/// peer to [`Self::count_middle_band_variants`] one RETURN-SHAPE axis
/// over (`usize` cardinality → `Vec<Self>` witness-collection). Not a
/// fresh substrate primitive on the index axis — the projection emerges
/// from ONE `is_empty()` guard AND ONE max/min-fold pair AND ONE
/// `T::CARDINALITY`-bounded filter sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the pair via the STRICT
/// interior test `c != max && c != min`, guarded so `&[]` maps to
/// `Vec::new()` past the (max == min == 0, every-count == 0) degenerate
/// arm where an unguarded sweep would silently return `Vec::new()` for
/// the WRONG reason (every variant is extremal on the empty slice, not
/// middle-band).
///
/// Complement-composition identity: for every slice `items`,
/// `T::middle_band_variants(items)` equals the DECLARATION-ORDER
/// set-difference of [`Self::ALL`] and [`Self::extremal_variants`]`(items)`
/// on every NON-EMPTY slice — every element of the middle-band
/// witness-collection is a variant of [`Self::ALL`] NOT present in
/// the extremal collection, and every variant of [`Self::ALL`] NOT
/// present in the extremal collection appears in the middle-band
/// collection. The (extreme / middle) partition of [`Self::ALL`]
/// on non-empty slices lifts to the `Vec<Self>` return-shape row via
/// this identity. On the empty slice both projections collapse to
/// `Vec::new()` via the shared load-bearing empty-slice guard. Pinned
/// by `middle_band_variants_agrees_with_set_difference_of_all_and_extremal_variants_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::middle_band_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// — the sharpened max/min-fold body agrees with the naive filter over
/// [`Self::ALL`] of the per-target predicate. Independent cross-check
/// on the composition-shape (max/min-fold-pair vs per-target predicate
/// sweep) axis. Pinned by
/// `middle_band_variants_agrees_with_filter_of_is_middle_band_variant_of_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::middle_band_variants(items).len() == T::count_middle_band_variants(items)`
/// — the plural's LEN equals the just-lifted set-level middle-band
/// cardinality-count aggregate because both projections filter
/// [`Self::ALL`] under the same direction-composition predicate. Pinned
/// by `middle_band_variants_len_agrees_with_count_middle_band_variants_across_every_triple`.
///
/// Disjointness identity: for every slice `items`,
/// `T::middle_band_variants(items)` and `T::extremal_variants(items)`
/// share NO common variant — the (extreme / middle) partition of
/// [`Self::ALL`] on non-empty slices is DISJOINT by construction (a
/// variant's count either sits at max/min or strictly between, never
/// both). Pinned by
/// `middle_band_variants_and_extremal_variants_are_disjoint_across_every_triple`.
///
/// Interleaving identity: for every NON-EMPTY slice `items`, walking
/// [`Self::ALL`] and threading each variant into either the middle-
/// band or extremal collection recovers [`Self::ALL`] element-for-
/// element in declaration order (every variant lands in EXACTLY ONE of
/// the two projections on non-empty). On the empty slice both projections
/// collapse to `Vec::new()` via the shared empty-slice guard. Pinned by
/// `middle_band_variants_interleaved_with_extremal_variants_recovers_all_across_every_triple`.
///
/// Uniformity-collapse identity: on every NON-EMPTY slice `items` on
/// which [`Self::is_uniform`] holds (max == min),
/// `T::middle_band_variants(items) == Vec::new()` — the direction axis
/// on flat-histogram slices COLLAPSES so every variant is at BOTH
/// extremes simultaneously (equivalently, no variant is strictly
/// between), and the strict interior filter matches nothing. The
/// canonical NON-EMPTY empty-collection arm one COMBINATOR axis over
/// from [`Self::extremal_variants`]'s uniformity-collapse arm (which
/// reports `T::ALL.to_vec()` on the same fixture). Pinned by the full-
/// set + doubled-full-set + matching-singleton fixpoints.
///
/// Ordering-axis invariance: the projection factors through the
/// ordering-agnostic [`Self::max_variant_count`] +
/// [`Self::min_variant_count`] fold pair and walks [`Self::ALL`] in
/// declaration order; permuting `items` preserves its variant multiset,
/// so the filter is a function of that multiset alone. Pinned by
/// `middle_band_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::middle_band_variants(&[])` is the empty
/// `Vec<Self>` UNCONDITIONALLY — the empty guard is LOAD-BEARING past
/// the (max == min == 0, every-count == 0) degenerate arm where an
/// unguarded sweep would silently return `Vec::new()` too but for the
/// WRONG structural reason (every variant sits AT the collapsed
/// max/min band, not strictly between). The guard makes the empty-slice
/// answer a TYPED CONSEQUENCE of the non-emptiness precondition
/// [`Self::is_middle_band_variant_of`] carries at every target rather
/// than an accidental collision with the strict-interior filter arm.
///
/// Full-set contract:
/// `T::middle_band_variants(<T as ClosedSet>::ALL) == Vec::new()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant pins
/// every variant at exactly one position, max == min == 1, the
/// (max == min == 1) collapse pins every variant simultaneously at
/// both extremes, the strict interior filter matches nothing.
///
/// Doubled-full-set contract:
/// `T::middle_band_variants(&doubled) == Vec::new()` — the second flat-
/// histogram fixpoint at count `2`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::middle_band_variants(&[v]) == Vec::new()` for every variant `v`
/// — the sole position hits `v` at count `1 == max` and every non-
/// target variant sits at count `0 == min`, so every variant is
/// extremal via one of the two arms and none sits strictly between.
/// LOAD-BEARING contract separating this COMPLEMENT projection from
/// [`Self::extremal_variants`] which reports `T::ALL.to_vec()` on the
/// same fixture.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal triple
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the middle-band target `T::ALL[1]` is INCLUDED as the
/// SOLE inhabitant, so `T::middle_band_variants(&bimodal_triple) ==
/// vec![T::ALL[1]]`, with length `1`. LOAD-BEARING SOLE canonical
/// fixture where this projection returns a NON-EMPTY vector — every
/// other canonical fixpoint pins it to `Vec::new()`. DUAL of
/// [`Self::extremal_variants`]'s bimodal-triple arm one COMBINATOR
/// axis over (which returns `T::CARDINALITY - 1` variants EXCEPT
/// `T::ALL[1]`).
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::max_variant_count`] fold + ONE [`Self::min_variant_count`]
/// fold + ONE [`Self::CARDINALITY`]-bounded filter sweep against
/// [`Self::count_occurrences_of`] with the STRICT interior predicate
/// `c != max && c != min`. The sweep costs `O(T::CARDINALITY * n)` on
/// slice arity `n` — strictly beats the naive
/// `T::ALL.iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// sweep which pays `O(T::CARDINALITY² * n)` (the per-target predicate
/// re-derives the max and min folds internally once per variant, then
/// negates one union arm — each per-target call independently redoes
/// the fold pair). Allocation of one output `Vec` of at most
/// [`Self::CARDINALITY`] entries; no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no histogram-carrier allocation.
///
/// Future consumers that compose against [`Self::middle_band_variants`]:
/// a `tatara-check` predicate `(check-phases-middle-band …)` that
/// enumerates EVERY `WorkloadPhase` sitting STRICTLY between the
/// histogram extremes in a rollout window — the operator-attention
/// target variants NEITHER over-rolled NOR under-rolled; an LSP
/// diagnostic that surfaces the complete middle-band witness-collection
/// as an author-facing "in the middle: `<label1>`, `<label2>`" hint
/// distinct from the extremal-only [`Self::extremal_variants`] hint one
/// COMBINATOR axis over; a Sekiban audit-trail per-window middle-band
/// witness-collection gauge alongside the direction-anchored
/// [`Self::modal_variants`] + [`Self::antimodal_variants`] + union
/// [`Self::extremal_variants`] triple. Each binds to ONE typed
/// `Vec<Self>`-return direction-composition complement witness-
/// collection on the trait rather than re-deriving the max/min-fold-
/// guarded strict-interior filter inline per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction-composition ×
/// complement) corner past the just-opened
/// [`Self::extremal_variants`] union arm one DIRECTION-COMPOSITION
/// axis over, aligned with the just-lifted (set-level × usize ×
/// direction-composition × complement) row via
/// [`Self::count_middle_band_variants`] one RETURN-SHAPE axis over. The
/// (set-level × `Vec<Self>` × direction-composition) row now carries
/// three inhabitants — the direction-anchored pair
/// ([`Self::modal_variants`], [`Self::antimodal_variants`]) at the
/// argmax/argmin corners, the UNION arm [`Self::extremal_variants`]
/// at the disjunction corner, and THIS COMPLEMENT arm at the middle-
/// band corner. The natural next lifts past this closure are:
///
/// * `sorted_middle_band_variants(items) -> Vec<Self>` — the LEX-ORDER
/// peer one ORDERING axis over, closing the (set-level × `Vec<Self>`
/// × direction-composition × complement × ordering) 2-corner face at
/// its lex arm.
/// * `bimodal_variants(items) -> Vec<Self>` — the INTERSECTION peer
/// one COMBINATOR axis over, opening the flat-diagonal Vec-return
/// witness-collection past the (set-level × usize × intersection)
/// [`Self::count_bimodal_variants`] aggregate one RETURN-SHAPE axis
/// over.
/// * `sorted_extremal_variants(items) -> Vec<Self>` — the LEX-ORDER
/// peer of the just-opened union arm one ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-level
/// complement witness-collection becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × complement) corner
/// was an unnamed inline SHARPENING recurring at every prospective
/// downstream "which variants sit STRICTLY between the histogram
/// extremes?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the sharpened body emerges from the composition of
/// THREE substrate primitives ([`Self::max_variant_count`],
/// [`Self::min_variant_count`], [`Self::count_occurrences_of`]) filtered
/// over [`Self::ALL`] with an `into_iter().filter().collect()`
/// combinator under the STRICT interior conjunction `c != max &&
/// c != min` — one algorithmic factor of `T::CARDINALITY` shaved off
/// the naive per-target filter sweep via the max/min-fold sharpening.
///
/// Frontier inspiration: R's `names(table(items))[table(items) !=
/// max(table(items)) & table(items) != min(table(items))]` on a factor
/// histogram; Julia's
/// `[k for (k, v) in StatsBase.countmap(items) if minimum(values(c)) < v < maximum(values(c))]`
/// (Julia's chained-comparison idiom); Python's
/// `[k for k, v in collections.Counter(items).items() if min(c.values()) < v < max(c.values())]`
/// (Python's chained-comparison idiom); Haskell's
/// `map fst . filter (\(_, n) -> n > minimum ns && n < maximum ns) $ hist`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f))] (filter #(let [c (get f % 0)] (and (> c n) (< c m))) (keys f)))`;
/// SQL's
/// `SELECT variant FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant) x WHERE x.c > (SELECT MIN(c) FROM …) AND x.c < (SELECT MAX(c) FROM …)`.
/// Translation through pleme-io primitives: the N-ary `Vec<Self>`-return
/// declaration-order direction-composition complement witness-collection
/// on the closed-set trait binds through [`Self::max_variant_count`] +
/// [`Self::min_variant_count`] + [`Self::count_occurrences_of`] under
/// one filter over [`Self::ALL`] with a strict-interior conjunction —
/// no new dep, no supertrait bound (the max/min pair replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` / `frequencies` /
/// `countmap` signatures demand), no histogram-carrier allocation, one
/// algorithmic factor of `T::CARDINALITY` shaved off the naive filter
/// sweep via the max/min-fold sharpening.
fn middle_band_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c != max && c != min
})
.collect()
}
/// The N-ARY LEX-ORDER "middle-band variants" projection — the
/// `Vec<Self>` LEX-ORDER witness-collection of EVERY variant of
/// [`Self::sorted_variants`] for which
/// [`Self::is_middle_band_variant_of`] holds against `items`
/// (equivalently, whose per-slot count sits STRICTLY between
/// [`Self::min_variant_count`] and [`Self::max_variant_count`]),
/// preserving [`Self::sorted_variants`]'s canonical ASCII-lex order
/// and returning the empty vector when `items` is empty. The
/// LEX-ORDER peer of [`Self::middle_band_variants`] one ORDERING
/// axis over, CLOSING the (set-level × `Vec<Self>` × statistical-
/// aggregate × direction-composition × complement × ordering)
/// 2-corner face at its lex-arm past the declaration-arm the
/// sibling [`Self::middle_band_variants`] opened. Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from ONE `is_empty()` guard + ONE max/min-fold pair + ONE
/// `T::CARDINALITY`-bounded filter sweep over
/// [`Self::sorted_variants`] whose predicate binds
/// [`Self::count_occurrences_of`] against the pair via the STRICT
/// interior test `c != max && c != min`.
///
/// Multiset-agreement identity: for every slice `items`,
/// `T::sorted_middle_band_variants(items)` is a LEX-ORDER PERMUTATION
/// of `T::middle_band_variants(items)` — the two projections agree
/// as multisets (both filter under the strict interior conjunction
/// `c != max && c != min`) and differ ONLY in walk order
/// (declaration vs lex). Pinned by
/// `sorted_middle_band_variants_is_a_lex_permutation_of_middle_band_variants_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::sorted_middle_band_variants(items).len() == T::count_middle_band_variants(items)`
/// — the plural's LEN equals the just-lifted set-level middle-band
/// cardinality-count aggregate because both projections filter
/// under the same direction-composition predicate; ordering does
/// NOT affect cardinality. Pinned by
/// `sorted_middle_band_variants_len_agrees_with_count_middle_band_variants_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::sorted_middle_band_variants(items) == T::sorted_variants().into_iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// — the sharpened max/min-fold body agrees with the naive filter
/// over [`Self::sorted_variants`] of the per-target predicate.
/// Independent cross-check on the composition-shape (max/min-fold-
/// pair vs per-target predicate sweep) axis. Pinned by
/// `sorted_middle_band_variants_agrees_with_filter_of_is_middle_band_variant_of_across_every_triple`.
///
/// Complement-composition identity: for every NON-EMPTY slice
/// `items`, `T::sorted_middle_band_variants(items)` equals the
/// LEX-ORDER set-difference of [`Self::sorted_variants`] and
/// [`Self::extremal_variants`]`(items)` (walking
/// [`Self::sorted_variants`] and filtering out any variant that
/// appears in [`Self::extremal_variants`]) — the (extreme /
/// middle) partition of the closed-set lifts to the lex-order
/// `Vec<Self>` return-shape row via this identity. On the empty
/// slice both projections collapse to `Vec::new()` via the shared
/// load-bearing empty-slice guard. Pinned by
/// `sorted_middle_band_variants_agrees_with_lex_set_difference_of_sorted_variants_and_extremal_variants_across_every_triple`.
///
/// Disjointness identity: for every slice `items`,
/// `T::sorted_middle_band_variants(items)` and
/// [`Self::extremal_variants`]`(items)` share NO common variant —
/// the (extreme / middle) partition of the closed set on non-empty
/// slices is DISJOINT by construction (a variant's count either
/// sits at max/min or strictly between, never both). Pinned by
/// `sorted_middle_band_variants_and_extremal_variants_are_disjoint_across_every_triple`.
///
/// Ordering-axis invariance on the INPUT axis: the projection
/// factors through the ordering-agnostic
/// [`Self::max_variant_count`] + [`Self::min_variant_count`] fold
/// pair AND walks [`Self::sorted_variants`] (which does NOT depend
/// on `items`' ordering); permuting `items` preserves its variant
/// multiset, so the projection is a function of that multiset
/// alone. Pinned by
/// `sorted_middle_band_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_middle_band_variants(&[])` is
/// the empty `Vec<Self>` UNCONDITIONALLY — the empty guard is
/// LOAD-BEARING past the (max == min == 0, every-count == 0)
/// degenerate arm where an unguarded sweep would silently return
/// `Vec::new()` too but for the WRONG structural reason (every
/// variant sits AT the collapsed max/min band, not strictly
/// between). The guard makes the empty-slice answer a TYPED
/// CONSEQUENCE of the non-emptiness precondition
/// [`Self::is_middle_band_variant_of`] carries at every target
/// rather than an accidental collision with the strict-interior
/// filter arm.
///
/// Full-set contract:
/// `T::sorted_middle_band_variants(<T as ClosedSet>::ALL) == Vec::new()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, max == min == 1,
/// the (max == min == 1) collapse pins every variant simultaneously
/// at both extremes, the strict interior filter matches nothing.
///
/// Doubled-full-set contract:
/// `T::sorted_middle_band_variants(&doubled) == Vec::new()` — the
/// second flat-histogram fixpoint at count `2`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_middle_band_variants(&[v]) == Vec::new()` for every
/// variant `v` — the sole position hits `v` at count `1 == max`
/// and every non-target variant sits at count `0 == min`, so every
/// variant is extremal via one of the two arms and none sits
/// strictly between. LOAD-BEARING contract separating this
/// COMPLEMENT projection from [`Self::extremal_variants`] which
/// reports `T::ALL.to_vec()` on the same fixture.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the middle-band target `T::ALL[1]` is INCLUDED as
/// the SOLE inhabitant regardless of walk order, so
/// `T::sorted_middle_band_variants(&bimodal_triple) == vec![T::ALL[1]]`.
/// LOAD-BEARING SOLE canonical fixture where this projection
/// returns a NON-EMPTY vector — every other canonical fixpoint
/// pins it to `Vec::new()`.
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::max_variant_count`] fold + ONE [`Self::min_variant_count`]
/// fold + ONE [`Self::CARDINALITY`]-bounded filter sweep over
/// [`Self::sorted_variants`] against [`Self::count_occurrences_of`]
/// with the STRICT interior predicate `c != max && c != min`. The
/// sweep costs `O(N log N + T::CARDINALITY * n)` on slice arity `n`
/// (the [`Self::sorted_variants`] canonical-lex-sort step + one
/// [`Self::max_variant_count`] fold + one [`Self::min_variant_count`]
/// fold + one [`Self::CARDINALITY`]-bounded filter sweep, plus one
/// output-`Vec` allocation of at most [`Self::CARDINALITY`]
/// entries) — strictly beats the naive
/// `T::sorted_variants().into_iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// sweep which pays `O(N log N + T::CARDINALITY² * n)` (the per-
/// target predicate re-derives the max and min folds internally
/// once per variant). No `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no histogram-carrier allocation.
///
/// Future consumers that compose against
/// [`Self::sorted_middle_band_variants`]: a `tatara-check` predicate
/// `(check-phases-middle-band-lex …)` that enumerates EVERY
/// `WorkloadPhase` sitting STRICTLY between the histogram extremes
/// in a rollout window under a canonical alphabetic display order
/// (distinct from [`Self::middle_band_variants`]'s declaration-
/// order-canonical form consumed by scheduler-oriented tools that
/// route through declaration slots); an LSP diagnostic that
/// surfaces the complete middle-band witness-collection as an
/// author-facing "in the middle (alphabetical): `<label1>`,
/// `<label2>`" hint aligned with lex-ordered enumeration surfaces;
/// a Sekiban audit-trail per-window middle-band witness-collection
/// gauge whose element order matches the UI's lex-ordered
/// navigation menu. Each binds to ONE typed `Vec<Self>`-return
/// lex-order direction-composition complement witness-collection on
/// the trait rather than re-deriving
/// `T::sorted_variants().into_iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// inline (behind an `is_empty()` short-circuit) per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × direction-composition × complement × ordering)
/// 2-corner face at its lex-arm past the declaration-arm
/// [`Self::middle_band_variants`] opened. Combined with the sibling
/// ([`Self::modal_variants`], [`Self::sorted_modal_variants`]) and
/// ([`Self::antimodal_variants`], [`Self::sorted_antimodal_variants`])
/// (declaration, lex) pairs, the (set-level × `Vec<Self>` ×
/// direction-composition × ordering) row now carries FIVE
/// inhabitants — the direction-anchored pair, its lex peers, and
/// this complement lex peer. The natural next lifts past this
/// closure are: `sorted_extremal_variants(items) -> Vec<Self>`
/// (the LEX-ORDER peer of [`Self::extremal_variants`] one ORDERING
/// axis over, closing the union arm's lex corner) and
/// `bimodal_variants(items) -> Vec<Self>` (the INTERSECTION peer
/// one COMBINATOR axis over, opening the flat-diagonal Vec-return
/// witness-collection past the just-lifted
/// [`Self::count_bimodal_variants`] aggregate one RETURN-SHAPE
/// axis over).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order direction-composition complement witness-collection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::sorted_variants().into_iter().filter(|&v| T::is_middle_band_variant_of(v, items)).collect()`
/// composition. THEORY.md §V.1 — knowable platform; the (set-level
/// × `Vec<Self>` × complement × lex) corner was an unnamed inline
/// SHARPENING recurring at every prospective downstream "which
/// variants sit STRICTLY between the histogram extremes, walked in
/// a canonical alphabetic display order?" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the sharpened body emerges
/// from the composition of FOUR substrate primitives
/// ([`Self::sorted_variants`], [`Self::max_variant_count`],
/// [`Self::min_variant_count`], [`Self::count_occurrences_of`])
/// filtered over [`Self::sorted_variants`] with an
/// `into_iter().filter().collect()` combinator under the STRICT
/// interior conjunction.
///
/// Frontier inspiration: R's `sort(names(table(items))[table(items)
/// != max(table(items)) & table(items) != min(table(items))])`
/// yielding the alphabetic-sorted complete middle-band set on a
/// factor histogram; Julia's `sort([k for (k, v) in
/// StatsBase.countmap(items) if minimum(values(c)) < v <
/// maximum(values(c))])`; Python's `sorted([k for k, v in
/// collections.Counter(items).items() if min(c.values()) < v <
/// max(c.values())])`; Haskell's `sort . map fst . filter (\(_, n)
/// -> n > minimum ns && n < maximum ns) $ hist`; Racket's `(sort
/// (filter (λ (v) (< n (count-occ v items) m)) T) string<? #:key
/// label)`. Translation through pleme-io primitives: the N-ary
/// `Vec<Self>`-return lex-order direction-composition complement
/// witness-collection on the closed-set trait binds through
/// [`Self::sorted_variants`] + [`Self::max_variant_count`] +
/// [`Self::min_variant_count`] + [`Self::count_occurrences_of`]
/// under one filter with a strict-interior conjunction — no new
/// dep, no supertrait bound (the max/min pair replaces the
/// `Eq`/`Hash` + `Ord` bound the standard-library counter+lex-sort
/// signatures demand), no histogram-carrier allocation, one
/// algorithmic factor of `T::CARDINALITY` shaved off the naive
/// per-target filter sweep via the max/min-fold sharpening.
fn sorted_middle_band_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c != max && c != min
})
.collect()
}
/// The N-ARY LEX-ORDER "extremal variants" projection — the
/// `Vec<Self>` LEX-ORDER witness-collection of EVERY variant of
/// [`Self::sorted_variants`] for which
/// [`Self::is_extremal_variant_of`] holds against `items`
/// (equivalently, whose per-slot count sits AT either
/// [`Self::max_variant_count`] or [`Self::min_variant_count`]),
/// preserving [`Self::sorted_variants`]'s canonical ASCII-lex order
/// and returning the empty vector when `items` is empty. The
/// LEX-ORDER peer of [`Self::extremal_variants`] one ORDERING axis
/// over, CLOSING the (set-level × `Vec<Self>` × statistical-
/// aggregate × direction-composition × union × ordering) 2-corner
/// face at its lex-arm past the declaration-arm the sibling
/// [`Self::extremal_variants`] opened. Not a fresh substrate
/// primitive on the index axis — the projection emerges from ONE
/// `is_empty()` guard + ONE max/min-fold pair + ONE
/// `T::CARDINALITY`-bounded filter sweep over
/// [`Self::sorted_variants`] whose predicate binds
/// [`Self::count_occurrences_of`] against the pair via the UNION
/// test `c == max || c == min`.
///
/// Multiset-agreement identity: for every slice `items`,
/// `T::sorted_extremal_variants(items)` is a LEX-ORDER PERMUTATION
/// of `T::extremal_variants(items)` — the two projections agree
/// as multisets (both filter under the same union disjunction
/// `c == max || c == min`) and differ ONLY in walk order
/// (declaration vs lex). Pinned by
/// `sorted_extremal_variants_is_a_lex_permutation_of_extremal_variants_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::sorted_extremal_variants(items).len() == T::count_extremal_variants(items)`
/// — the plural's LEN equals the just-lifted set-level extremal
/// cardinality-count aggregate because both projections filter
/// under the same direction-composition predicate; ordering does
/// NOT affect cardinality. Pinned by
/// `sorted_extremal_variants_len_agrees_with_count_extremal_variants_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::sorted_extremal_variants(items) == T::sorted_variants().into_iter().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// — the sharpened max/min-fold body agrees with the naive filter
/// over [`Self::sorted_variants`] of the per-target predicate.
/// Independent cross-check on the composition-shape (max/min-fold-
/// pair vs per-target predicate sweep) axis. Pinned by
/// `sorted_extremal_variants_agrees_with_filter_of_is_extremal_variant_of_across_every_triple`.
///
/// Complement-partition identity: for every NON-EMPTY slice
/// `items`, `T::sorted_extremal_variants(items)` equals the
/// LEX-ORDER set-difference of [`Self::sorted_variants`] and
/// [`Self::sorted_middle_band_variants`]`(items)` (walking
/// [`Self::sorted_variants`] and filtering out any variant that
/// appears in [`Self::sorted_middle_band_variants`]) — the (extreme
/// / middle) partition of the closed-set lifts to the lex-order
/// `Vec<Self>` return-shape row via this identity. On the empty
/// slice both projections collapse to `Vec::new()` via the shared
/// load-bearing empty-slice guard AND
/// `T::sorted_variants().into_iter().filter(|v|
/// !T::sorted_middle_band_variants(&[]).contains(v))` returns
/// `T::sorted_variants()` — the identity holds ONLY on non-empty
/// slices. Pinned by
/// `sorted_extremal_variants_agrees_with_lex_set_difference_of_sorted_variants_and_sorted_middle_band_variants_across_every_triple`.
///
/// Disjointness identity: for every slice `items`,
/// `T::sorted_extremal_variants(items)` and
/// [`Self::sorted_middle_band_variants`]`(items)` share NO common
/// variant — the (extreme / middle) partition of the closed set on
/// non-empty slices is DISJOINT by construction (a variant's count
/// either sits at max/min or strictly between, never both). Pinned
/// by
/// `sorted_extremal_variants_and_sorted_middle_band_variants_are_disjoint_across_every_triple`.
///
/// Ordering-axis invariance on the INPUT axis: the projection
/// factors through the ordering-agnostic
/// [`Self::max_variant_count`] + [`Self::min_variant_count`] fold
/// pair AND walks [`Self::sorted_variants`] (which does NOT depend
/// on `items`' ordering); permuting `items` preserves its variant
/// multiset, so the projection is a function of that multiset
/// alone. Pinned by
/// `sorted_extremal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_extremal_variants(&[])` is
/// the empty `Vec<Self>` UNCONDITIONALLY — the empty guard is
/// LOAD-BEARING past the (max == min == 0, every-count == 0)
/// degenerate arm where an unguarded sweep would collapse `c == max
/// || c == min` onto `true` at EVERY variant and return
/// `T::sorted_variants()` (the WRONG structural answer — every
/// variant is vacuously extremal when the histogram is uniformly
/// zero). The guard makes the empty-slice answer a TYPED
/// CONSEQUENCE of the non-emptiness precondition
/// [`Self::is_extremal_variant_of`] carries at every target rather
/// than an accidental collision with the union filter arm. Sibling
/// posture to [`Self::extremal_variants`]'s empty-slice guard one
/// ORDERING axis over — both guards discriminate this UNION
/// projection from a naive
/// `T::sorted_variants().into_iter().filter(...).collect()` sweep
/// which would silently bifurcate the empty-slice answer.
///
/// Full-set contract:
/// `T::sorted_extremal_variants(<T as ClosedSet>::ALL) == T::sorted_variants()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, max == min == 1,
/// the (max == min == 1) collapse pins every variant simultaneously
/// at both extremes, the union filter matches EVERY variant, and
/// the projection returns [`Self::sorted_variants`] intact.
///
/// Doubled-full-set contract:
/// `T::sorted_extremal_variants(&doubled) == T::sorted_variants()`
/// — the second flat-histogram fixpoint at count `2`: every
/// variant sits at both extremes via max == min == 2 and the union
/// filter matches everything.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_extremal_variants(&[v]) == T::sorted_variants()` for
/// every variant `v` — the sole position hits `v` at count `1 ==
/// max` and every non-target variant sits at count `0 == min`, so
/// every variant of [`Self::sorted_variants`] is extremal via one
/// of the two arms. LOAD-BEARING FULL-COVERAGE contract
/// distinguishing this UNION projection from
/// [`Self::sorted_middle_band_variants`] (which returns
/// `Vec::new()` on the same fixture).
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the middle-band target `T::ALL[1]` is EXCLUDED and
/// every other variant is INCLUDED via one of the two arms
/// (T::ALL[0] via max, T::ALL[2..] via min), walked in lex order,
/// so
/// `T::sorted_extremal_variants(&bimodal_triple)`'s LEN equals
/// `T::CARDINALITY - 1` — the SOLE canonical fixture where this
/// projection populates a PROPER subset of
/// [`Self::sorted_variants`] with cardinality strictly between
/// `1` and `T::CARDINALITY`.
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::max_variant_count`] fold + ONE [`Self::min_variant_count`]
/// fold + ONE [`Self::CARDINALITY`]-bounded filter sweep over
/// [`Self::sorted_variants`] against [`Self::count_occurrences_of`]
/// with the UNION predicate `c == max || c == min`. The
/// sweep costs `O(N log N + T::CARDINALITY * n)` on slice arity `n`
/// (the [`Self::sorted_variants`] canonical-lex-sort step + one
/// [`Self::max_variant_count`] fold + one [`Self::min_variant_count`]
/// fold + one [`Self::CARDINALITY`]-bounded filter sweep, plus one
/// output-`Vec` allocation of at most [`Self::CARDINALITY`]
/// entries) — strictly beats the naive
/// `T::sorted_variants().into_iter().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// sweep which pays `O(N log N + T::CARDINALITY² * n)` (the per-
/// target predicate re-derives the max and min folds internally
/// once per variant). No `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched), no histogram-carrier allocation.
///
/// Future consumers that compose against
/// [`Self::sorted_extremal_variants`]: a `tatara-check` predicate
/// `(check-phases-extremal-lex …)` that enumerates EVERY
/// `WorkloadPhase` sitting AT some histogram extreme in a rollout
/// window under a canonical alphabetic display order (distinct
/// from [`Self::extremal_variants`]'s declaration-order-canonical
/// form consumed by scheduler-oriented tools that route through
/// declaration slots); an LSP diagnostic that surfaces the
/// complete extremal witness-collection as an author-facing "at
/// some extreme (alphabetical): `<label1>`, `<label2>`" hint
/// aligned with lex-ordered enumeration surfaces; a Sekiban audit-
/// trail per-window extremal witness-collection gauge whose
/// element order matches the UI's lex-ordered navigation menu.
/// Each binds to ONE typed `Vec<Self>`-return lex-order
/// direction-composition union witness-collection on the trait
/// rather than re-deriving
/// `T::sorted_variants().into_iter().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// inline (behind an `is_empty()` short-circuit) per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × direction-composition × union × ordering) 2-corner
/// face at its lex-arm past the declaration-arm
/// [`Self::extremal_variants`] opened. Combined with the sibling
/// ([`Self::modal_variants`], [`Self::sorted_modal_variants`]),
/// ([`Self::antimodal_variants`], [`Self::sorted_antimodal_variants`]),
/// and ([`Self::middle_band_variants`],
/// [`Self::sorted_middle_band_variants`]) (declaration, lex) pairs,
/// the (set-level × `Vec<Self>` × direction-composition × ordering)
/// row now closes at the (argmax, argmin, union, complement)
/// direction-composition inhabitants — the intersection arm
/// (bimodal_variants, sorted_bimodal_variants) remains the sole
/// pair of Vec-return direction-composition corners still open. The
/// natural next lifts past this closure are: `bimodal_variants(items)
/// -> Vec<Self>` (the INTERSECTION opener one COMBINATOR axis over,
/// past the just-lifted [`Self::count_bimodal_variants`] aggregate
/// one RETURN-SHAPE axis over) and `sorted_bimodal_variants(items)
/// -> Vec<Self>` (the intersection arm's lex-order closer).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order direction-composition union witness-collection becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline
/// `T::sorted_variants().into_iter().filter(|&v| T::is_extremal_variant_of(v, items)).collect()`
/// composition. THEORY.md §V.1 — knowable platform; the (set-level
/// × `Vec<Self>` × union × lex) corner was an unnamed inline
/// SHARPENING recurring at every prospective downstream "which
/// variants sit AT the histogram extremes, walked in a canonical
/// alphabetic display order?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the sharpened body emerges from
/// the composition of THREE substrate primitives
/// ([`Self::max_variant_count`], [`Self::min_variant_count`],
/// [`Self::count_occurrences_of`]) filtered over
/// [`Self::sorted_variants`] with an
/// `into_iter().filter().collect()` combinator under the UNION
/// disjunction.
///
/// Frontier inspiration: R's `sort(names(table(items))[table(items)
/// == max(table(items)) | table(items) == min(table(items))])`
/// yielding the alphabetic-sorted complete extremal set on a
/// factor histogram; Julia's `sort([k for (k, v) in
/// StatsBase.countmap(items) if v == maximum(values(c)) || v ==
/// minimum(values(c))])`; Python's `sorted([k for k, v in
/// collections.Counter(items).items() if v in (max(c.values()),
/// min(c.values()))])`; Haskell's `sort . map fst . filter
/// (\(_, n) -> n == maximum ns || n == minimum ns) $ hist`;
/// Racket's `(sort (filter (λ (v) (or (= (count-occ v items) m)
/// (= (count-occ v items) n))) T) string<? #:key label)`.
/// Translation through pleme-io primitives: the N-ary `Vec<Self>`-
/// return lex-order direction-composition union witness-collection
/// on the closed-set trait binds through
/// [`Self::max_variant_count`] + [`Self::min_variant_count`] +
/// [`Self::count_occurrences_of`] under one filter with a UNION
/// disjunction — no new dep, no supertrait bound (the max/min pair
/// replaces the `Eq`/`Hash` + `Ord` bound the standard-library
/// counter+lex-sort signatures demand), no histogram-carrier
/// allocation, one algorithmic factor of `T::CARDINALITY` shaved
/// off the naive per-target filter sweep via the max/min-fold
/// sharpening.
fn sorted_extremal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() {
return ::std::vec::Vec::new();
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c == max || c == min
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "bimodal variants" projection — the
/// `Vec<Self>` DECLARATION-ORDER witness-collection of EVERY variant
/// of [`Self::ALL`] for which [`Self::is_bimodal_variant_of`] holds
/// against `items` (equivalently, whose per-slot count sits at BOTH
/// [`Self::max_variant_count`] AND [`Self::min_variant_count`]
/// simultaneously), preserving [`Self::ALL`]'s canonical declaration
/// order and returning the empty vector when `items` is empty. The
/// DIRECTION-COMPOSITION INTERSECTION opener on the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction-composition ×
/// intersection) corner OPENING the (set-level × `Vec<Self>` ×
/// direction-composition × combinator) 2-corner flat-diagonal face
/// at its `&&` CONJUNCTION arm past the just-lifted UNION arm
/// [`Self::extremal_variants`] one COMBINATOR axis over on the
/// modal-aggregation matrix. Direct SET-LEVEL ARITY LIFT of the
/// (per-target × bool × direction-composition × intersection)
/// [`Self::is_bimodal_variant_of`] corner one ARITY axis over, AND
/// peer to [`Self::count_bimodal_variants`] one RETURN-SHAPE axis
/// over (`usize` cardinality → `Vec<Self>` witness-collection) via
/// the SAME uniformity-collapse SHARPENING (which cuts one
/// algorithmic factor of `T::CARDINALITY` off the naive filter
/// sweep — a two-value dichotomy over `T::ALL.to_vec()` /
/// `Vec::new()` gated by [`Self::is_uniform`] rather than a per-
/// target predicate re-derivation of the max and min folds).
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::bimodal_variants(items) == T::ALL.to_vec()` iff `items` is
/// NON-EMPTY AND [`Self::is_uniform`] holds (max == min), else
/// `Vec::new()`. On non-empty uniform slices every variant sits at
/// BOTH extremes simultaneously via the flat-histogram collapse and
/// the intersection filter matches every variant; on every other
/// slice (non-uniform non-empty AND empty) the intersection filter
/// matches NO variant — either because max != min pins a strict
/// direction split (no variant hits both extremes) or because the
/// empty guard short-circuits past the vacuous (max == min == 0)
/// flat-histogram collapse. Pinned by
/// `bimodal_variants_returns_all_iff_slice_is_non_empty_and_uniform_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::bimodal_variants(items) == <T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// — the sharpened uniformity-collapse body agrees with the naive
/// filter over [`Self::ALL`] of the per-target predicate.
/// Independent cross-check on the composition-shape (uniformity-
/// collapse vs per-target predicate sweep) axis. Pinned by
/// `bimodal_variants_agrees_with_filter_of_is_bimodal_variant_of_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::bimodal_variants(items).len() == T::count_bimodal_variants(items)`
/// — the plural's LEN equals the just-lifted set-level intersection
/// cardinality-count aggregate because both projections filter
/// [`Self::ALL`] under the same direction-composition intersection
/// predicate. Pinned by
/// `bimodal_variants_len_agrees_with_count_bimodal_variants_across_every_triple`.
///
/// Inclusion identity: for every slice `items`,
/// `T::bimodal_variants(items) ⊆ T::extremal_variants(items)` as
/// multisets — every variant sitting at BOTH extremes trivially
/// sits at AT LEAST ONE extreme, so the intersection subset
/// injects into the union superset. Pinned by
/// `bimodal_variants_is_subset_of_extremal_variants_across_every_triple`.
///
/// Disjointness identity: for every slice `items`,
/// `T::bimodal_variants(items)` and [`Self::middle_band_variants`]`(items)`
/// share NO common variant — every bimodal target sits AT the
/// max/min collapsed extremes and every middle-band target sits
/// STRICTLY between them, so the two arms are mutually exclusive
/// by construction. Pinned by
/// `bimodal_variants_and_middle_band_variants_are_disjoint_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through the
/// ordering-agnostic [`Self::is_uniform`] predicate + a walk over
/// [`Self::ALL`] in declaration order; permuting `items` preserves
/// its variant multiset, so the projection is a function of that
/// multiset alone. Pinned by
/// `bimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::bimodal_variants(&[])` is the empty
/// `Vec<Self>` UNCONDITIONALLY — the empty guard is LOAD-BEARING
/// past the vacuous (max == min == 0) flat-histogram collapse of
/// [`Self::is_uniform`] where an unguarded branch would silently
/// return `T::ALL.to_vec()` (every variant satisfies `count == max
/// == min == 0` vacuously — the WRONG structural answer). The
/// guard makes the empty-slice answer a TYPED CONSEQUENCE of the
/// non-emptiness precondition [`Self::is_bimodal_variant_of`]
/// carries at every target rather than an accidental collision
/// with the intersection filter arm on the degenerate empty
/// histogram.
///
/// Full-set contract:
/// `T::bimodal_variants(<T as ClosedSet>::ALL) == T::ALL.to_vec()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, max == min == 1,
/// [`Self::is_uniform`] holds on the flat-histogram fixpoint, and
/// the intersection collapse pins every variant simultaneously at
/// both extremes.
///
/// Doubled-full-set contract:
/// `T::bimodal_variants(&doubled) == T::ALL.to_vec()` — the second
/// flat-histogram fixpoint at count `2`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::bimodal_variants(&[v]) == Vec::new()` for every variant `v`
/// — the sole position hits `v` at count `1 == max` but every
/// non-target variant sits at count `0 == min`, so the histogram
/// is non-flat (max `1` != min `0`), [`Self::is_uniform`] reports
/// `false`, and the dichotomy lands on `Vec::new()`. LOAD-BEARING
/// empty-collection arm DISCRIMINATING this INTERSECTION projection
/// from [`Self::extremal_variants`] (which reports `T::ALL.to_vec()`
/// on the same fixture via the (max ∨ min) union covering every
/// variant through one of the two arms).
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the histogram is non-flat (max `2` != min `0`),
/// [`Self::is_uniform`] reports `false`, and the dichotomy lands on
/// `Vec::new()`. LOAD-BEARING `Vec::new()`-arm catch that separates
/// the intersection witness-collection from a prospective
/// [`Self::extremal_variants`] sibling (which would report
/// `T::CARDINALITY - 1` variants on the same fixture — the argmax
/// and argmin endpoints minus the middle-band inhabitant).
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::is_uniform`] test + ONE `T::ALL.to_vec()` clone (only on
/// the uniform non-empty arm) — no [`Self::CARDINALITY`]-bounded
/// filter sweep, no [`Self::count_occurrences_of`] re-derivation
/// per variant. Cost is `O(T::CARDINALITY * n)` on slice arity `n`
/// (inherited from [`Self::is_uniform`]'s max/min-fold pair, one
/// [`Self::CARDINALITY`]-length copy on the uniform arm) — strictly
/// beats the naive
/// `T::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// sweep which pays `O(T::CARDINALITY² * n)` (the per-target
/// predicate re-derives the max and min folds internally once per
/// variant, then intersects — each per-target call independently
/// redoes the fold pair). Allocation of one output `Vec` of either
/// `0` or [`Self::CARDINALITY`] entries; no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no histogram-carrier
/// allocation.
///
/// Future consumers that compose against [`Self::bimodal_variants`]:
/// a `tatara-check` predicate `(check-phases-flat …)` that
/// enumerates the COMPLETE variant witness-collection of a rollout
/// window sitting on the flat-histogram diagonal — the operator-
/// attention target set when the rollout is uniformly-distributed
/// (the DUAL of [`Self::middle_band_variants`]'s "strictly-between"
/// target set); an LSP diagnostic that surfaces the complete flat-
/// diagonal witness-collection as an author-facing "uniformly
/// distributed across: `<label1>`, `<label2>`" hint distinct from
/// the direction-anchored [`Self::modal_variants`] AND
/// [`Self::antimodal_variants`] pair; a Sekiban audit-trail per-
/// window flat-diagonal witness-collection gauge alongside the
/// direction-anchored [`Self::modal_variants`] AND
/// [`Self::antimodal_variants`] AND union [`Self::extremal_variants`]
/// AND complement [`Self::middle_band_variants`] quadruple. Each
/// binds to ONE typed `Vec<Self>`-return direction-composition
/// intersection witness-collection on the trait rather than re-
/// deriving the uniformity-gated `T::ALL.to_vec()` / `Vec::new()`
/// dichotomy inline per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Vec<Self>` × statistical-aggregate × direction-composition ×
/// intersection) corner past the just-lifted
/// [`Self::extremal_variants`] union arm one COMBINATOR axis over,
/// aligned with the just-lifted (set-level × usize × direction-
/// composition × intersection) row via
/// [`Self::count_bimodal_variants`] one RETURN-SHAPE axis over. The
/// (set-level × `Vec<Self>` × direction-composition) row now
/// carries four inhabitants — the direction-anchored pair
/// ([`Self::modal_variants`], [`Self::antimodal_variants`]) at the
/// argmax/argmin corners, the UNION arm
/// [`Self::extremal_variants`] at the disjunction corner, the
/// COMPLEMENT arm [`Self::middle_band_variants`] at the strict-
/// interior corner, and THIS INTERSECTION arm at the flat-diagonal
/// corner. The natural next lifts past this closure are:
///
/// * `sorted_bimodal_variants(items) -> Vec<Self>` — the LEX-ORDER
/// peer one ORDERING axis over, closing the (set-level ×
/// `Vec<Self>` × direction-composition × intersection × ordering)
/// 2-corner face at its lex arm.
/// * `bimodal_variant(items) -> Option<Self>` — the FIRST-WITNESS
/// peer one RETURN-SHAPE axis over, closing the (set-level ×
/// `Option<Self>` × intersection) first-witness corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level intersection witness-collection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::ALL.iter().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × intersection)
/// corner was an unnamed inline SHARPENING recurring at every
/// prospective downstream "which variants sit at BOTH histogram
/// extremes simultaneously?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the sharpened body emerges from
/// the composition of TWO substrate primitives
/// ([`Self::is_uniform`], `T::ALL.to_vec()`) under a dichotomy
/// gate — one algorithmic factor of `T::CARDINALITY` shaved off
/// the naive per-target filter sweep via the uniformity-collapse
/// SHARPENING.
///
/// Frontier inspiration: R's `if (all(table(items) == table(items)[1]))
/// names(table(items)) else character(0)` on a factor histogram;
/// Julia's
/// `let c = StatsBase.countmap(items); if length(unique(values(c))) == 1 collect(keys(c)) else eltype(items)[] end`;
/// Python's
/// `list(c.keys()) if len(set(c.values())) == 1 else []` on a
/// `collections.Counter`; Haskell's
/// `if length (nub ns) == 1 then map fst hist else []`; Clojure's
/// `(let [f (frequencies coll), vs (vals f)] (if (apply = vs) (keys f) ()))`;
/// SQL's
/// `SELECT variant FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant) x WHERE (SELECT COUNT(DISTINCT c) FROM …) = 1`.
/// Translation through pleme-io primitives: the N-ary `Vec<Self>`-
/// return declaration-order direction-composition intersection
/// witness-collection on the closed-set trait binds through
/// [`Self::is_uniform`] gating a `T::ALL.to_vec()` /
/// `Vec::new()` dichotomy — no new dep, no supertrait bound (the
/// uniformity gate replaces the `Eq`/`Hash` bound the standard-
/// library `Counter` / `frequencies` / `countmap` signatures
/// demand), no histogram-carrier allocation, one algorithmic factor
/// of `T::CARDINALITY` shaved off the naive filter sweep via the
/// uniformity-collapse SHARPENING.
fn bimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() || !<Self as ClosedSet>::is_uniform(items) {
::std::vec::Vec::new()
} else {
<Self as ClosedSet>::ALL.to_vec()
}
}
/// The N-ARY LEX-ORDER "bimodal variants" projection — the
/// `Vec<Self>` LEX-ORDER witness-collection of EVERY variant of
/// [`Self::sorted_variants`] for which [`Self::is_bimodal_variant_of`]
/// holds against `items` (equivalently, whose per-slot count sits at
/// BOTH [`Self::max_variant_count`] AND [`Self::min_variant_count`]
/// simultaneously), preserving [`Self::sorted_variants`]'s canonical
/// ASCII-lex order and returning the empty vector when `items` is
/// empty. The LEX-ORDER peer of [`Self::bimodal_variants`] one
/// ORDERING axis over, CLOSING the (set-level × `Vec<Self>` ×
/// statistical-aggregate × direction-composition × intersection ×
/// ordering) 2-corner face at its lex-arm past the declaration-arm
/// the sibling [`Self::bimodal_variants`] opened. Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from the SAME uniformity-collapse SHARPENING as
/// [`Self::bimodal_variants`] (`if items.is_empty() ||
/// !T::is_uniform(items) { Vec::new() } else { T::sorted_variants() }`)
/// with `T::sorted_variants()` in place of `T::ALL.to_vec()` on the
/// uniform arm — the lex axis surfaces ONLY in the returned walk
/// order.
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items) == T::sorted_variants()` iff
/// `items` is NON-EMPTY AND [`Self::is_uniform`] holds (max == min),
/// else `Vec::new()`. On non-empty uniform slices every variant
/// sits at BOTH extremes simultaneously via the flat-histogram
/// collapse and the intersection filter matches every variant; on
/// every other slice (non-uniform non-empty AND empty) the
/// intersection filter matches NO variant — either because
/// max != min pins a strict direction split (no variant hits both
/// extremes) or because the empty guard short-circuits past the
/// vacuous (max == min == 0) flat-histogram collapse. Pinned by
/// `sorted_bimodal_variants_returns_sorted_variants_iff_slice_is_non_empty_and_uniform_across_every_triple`.
///
/// Multiset-agreement identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items)` is a LEX-ORDER PERMUTATION
/// of `T::bimodal_variants(items)` — the two projections agree as
/// multisets (both filter under the same intersection dichotomy
/// gated on [`Self::is_uniform`]) and differ ONLY in walk order
/// (declaration vs lex). Pinned by
/// `sorted_bimodal_variants_is_a_lex_permutation_of_bimodal_variants_across_every_triple`.
///
/// Length-composition identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items).len() == T::count_bimodal_variants(items)`
/// — the plural's LEN equals the set-level intersection
/// cardinality-count aggregate because both projections filter
/// under the same direction-composition intersection predicate;
/// ordering does NOT affect cardinality. Pinned by
/// `sorted_bimodal_variants_len_agrees_with_count_bimodal_variants_across_every_triple`.
///
/// Filter-count identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items) == T::sorted_variants().into_iter().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// — the sharpened uniformity-collapse body agrees with the naive
/// filter over [`Self::sorted_variants`] of the per-target
/// predicate. Independent cross-check on the composition-shape
/// (uniformity-collapse vs per-target predicate sweep) axis.
/// Pinned by
/// `sorted_bimodal_variants_agrees_with_filter_of_is_bimodal_variant_of_across_every_triple`.
///
/// Inclusion identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items) ⊆ T::sorted_extremal_variants(items)`
/// as multisets — every variant sitting at BOTH extremes trivially
/// sits at AT LEAST ONE extreme, so the lex-order intersection
/// subset injects into the lex-order union superset. Pinned by
/// `sorted_bimodal_variants_is_subset_of_sorted_extremal_variants_across_every_triple`.
///
/// Disjointness identity: for every slice `items`,
/// `T::sorted_bimodal_variants(items)` and
/// [`Self::sorted_middle_band_variants`]`(items)` share NO common
/// variant — every bimodal target sits AT the max/min collapsed
/// extremes and every middle-band target sits STRICTLY between
/// them, so the two arms are mutually exclusive by construction.
/// Pinned by
/// `sorted_bimodal_variants_and_sorted_middle_band_variants_are_disjoint_across_every_triple`.
///
/// Ordering-axis invariance on the INPUT axis: the projection
/// factors through the ordering-agnostic [`Self::is_uniform`]
/// predicate + a walk over [`Self::sorted_variants`] (which does
/// NOT depend on `items`' ordering); permuting `items` preserves
/// its variant multiset, so the projection is a function of that
/// multiset alone. Pinned by
/// `sorted_bimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_bimodal_variants(&[])` is the
/// empty `Vec<Self>` UNCONDITIONALLY — the empty guard is
/// LOAD-BEARING past the vacuous (max == min == 0) flat-histogram
/// collapse of [`Self::is_uniform`] where an unguarded branch
/// would silently return `T::sorted_variants()` (every variant
/// satisfies `count == max == min == 0` vacuously — the WRONG
/// structural answer). The guard makes the empty-slice answer a
/// TYPED CONSEQUENCE of the non-emptiness precondition
/// [`Self::is_bimodal_variant_of`] carries at every target rather
/// than an accidental collision with the intersection filter arm
/// on the degenerate empty histogram. Sibling posture to
/// [`Self::bimodal_variants`]'s empty-slice guard one ORDERING
/// axis over — both guards discriminate this INTERSECTION
/// projection from a naive
/// `T::sorted_variants().into_iter().filter(...).collect()` sweep
/// which would silently bifurcate the empty-slice answer.
///
/// Full-set contract:
/// `T::sorted_bimodal_variants(<T as ClosedSet>::ALL) == T::sorted_variants()`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, max == min == 1,
/// [`Self::is_uniform`] holds on the flat-histogram fixpoint, and
/// the intersection collapse pins every variant simultaneously at
/// both extremes — walked in lex order via
/// [`Self::sorted_variants`].
///
/// Doubled-full-set contract:
/// `T::sorted_bimodal_variants(&doubled) == T::sorted_variants()`
/// — the second flat-histogram fixpoint at count `2`: every
/// variant sits at both extremes via max == min == 2, walked in
/// lex order.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_bimodal_variants(&[v]) == Vec::new()` for every
/// variant `v` — the sole position hits `v` at count `1 == max`
/// but every non-target variant sits at count `0 == min`, so the
/// histogram is non-flat (max `1` != min `0`), [`Self::is_uniform`]
/// reports `false`, and the dichotomy lands on `Vec::new()`.
/// LOAD-BEARING empty-collection arm DISCRIMINATING this
/// LEX-ORDER INTERSECTION projection from
/// [`Self::sorted_extremal_variants`] (which reports
/// `T::sorted_variants()` on the same fixture via the (max ∨ min)
/// union covering every variant through one of the two arms).
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] ->
/// 0 == min)`; the histogram is non-flat (max `2` != min `0`),
/// [`Self::is_uniform`] reports `false`, and the dichotomy lands
/// on `Vec::new()`. LOAD-BEARING `Vec::new()`-arm catch that
/// separates the LEX-ORDER intersection witness-collection from a
/// prospective [`Self::sorted_extremal_variants`] sibling (which
/// would report `T::CARDINALITY - 1` variants on the same fixture
/// walked in lex order — the argmax and argmin endpoints minus
/// the middle-band inhabitant).
///
/// Signature note: the body composes ONE `is_empty()` guard + ONE
/// [`Self::is_uniform`] test + ONE [`Self::sorted_variants`] call
/// (only on the uniform non-empty arm) — no [`Self::CARDINALITY`]-
/// bounded filter sweep, no [`Self::count_occurrences_of`] re-
/// derivation per variant. Cost is `O(T::CARDINALITY * n +
/// T::CARDINALITY log T::CARDINALITY)` on slice arity `n` (the
/// [`Self::is_uniform`] max/min-fold pair on `n` + the
/// [`Self::sorted_variants`] canonical-lex-sort step on the uniform
/// arm only) — strictly beats the naive
/// `T::sorted_variants().into_iter().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// sweep which pays `O(T::CARDINALITY² * n + T::CARDINALITY log
/// T::CARDINALITY)` (the per-target predicate re-derives the max
/// and min folds internally once per variant, then intersects —
/// each per-target call independently redoes the fold pair, on top
/// of the lex sort). Allocation of one output `Vec` of either `0`
/// or [`Self::CARDINALITY`] entries; no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no histogram-carrier
/// allocation.
///
/// Future consumers that compose against
/// [`Self::sorted_bimodal_variants`]: a `tatara-check` predicate
/// `(check-phases-flat-lex …)` that enumerates the COMPLETE
/// variant witness-collection of a rollout window sitting on the
/// flat-histogram diagonal under a canonical alphabetic display
/// order (distinct from [`Self::bimodal_variants`]'s declaration-
/// order-canonical form consumed by scheduler-oriented tools that
/// route through declaration slots); an LSP diagnostic that
/// surfaces the complete flat-diagonal witness-collection as an
/// author-facing "uniformly distributed across (alphabetical):
/// `<label1>`, `<label2>`" hint aligned with lex-ordered
/// enumeration surfaces; a Sekiban audit-trail per-window flat-
/// diagonal witness-collection gauge whose element order matches
/// the UI's lex-ordered navigation menu — completing the (modal,
/// antimodal, union, complement, intersection) × (declaration,
/// lex) 5×2 witness-collection surface at ITS FINAL corner. Each
/// binds to ONE typed `Vec<Self>`-return lex-order direction-
/// composition intersection witness-collection on the trait rather
/// than re-deriving the uniformity-gated `T::sorted_variants()` /
/// `Vec::new()` dichotomy inline per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Vec<Self>` × direction-composition × intersection × ordering)
/// 2-corner face at its lex-arm past the declaration-arm
/// [`Self::bimodal_variants`] opened. Combined with the sibling
/// ([`Self::modal_variants`], [`Self::sorted_modal_variants`]),
/// ([`Self::antimodal_variants`], [`Self::sorted_antimodal_variants`]),
/// ([`Self::extremal_variants`], [`Self::sorted_extremal_variants`]),
/// and ([`Self::middle_band_variants`],
/// [`Self::sorted_middle_band_variants`]) (declaration, lex) pairs,
/// the (set-level × `Vec<Self>` × direction-composition × ordering)
/// 5×2 grid on the modal-aggregation matrix now closes at EVERY
/// direction-composition inhabitant across BOTH ordering arms — the
/// argmax pair, argmin pair, union pair, complement pair, AND
/// intersection pair are all pinned at both walk orders. The next
/// natural lifts past this closure are:
///
/// * `bimodal_variant(items) -> Option<Self>` — the FIRST-WITNESS
/// peer one RETURN-SHAPE axis over, opening the (set-level ×
/// `Option<Self>` × intersection) first-witness declaration-order
/// corner past this projection's plural analogue.
/// * `sorted_bimodal_variant(items) -> Option<Self>` — the
/// LEX-ORDER first-witness peer one ORDERING axis over from
/// `bimodal_variant`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order direction-composition intersection witness-collection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::sorted_variants().into_iter().filter(|&v| T::is_bimodal_variant_of(v, items)).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × intersection ×
/// lex) corner was an unnamed inline SHARPENING recurring at every
/// prospective downstream "which variants sit at BOTH histogram
/// extremes simultaneously, walked in a canonical alphabetic
/// display order?" site pre-lift. THEORY.md §VI.1 — generation
/// over composition; the sharpened body emerges from the
/// composition of TWO substrate primitives ([`Self::is_uniform`],
/// [`Self::sorted_variants`]) under a dichotomy gate — one
/// algorithmic factor of `T::CARDINALITY` shaved off the naive
/// per-target filter sweep via the uniformity-collapse SHARPENING.
///
/// Frontier inspiration: R's `if (all(table(items) == table(items)[1]))
/// sort(names(table(items))) else character(0)` on a factor
/// histogram; Julia's
/// `let c = StatsBase.countmap(items); if length(unique(values(c))) == 1 sort(collect(keys(c))) else eltype(items)[] end`;
/// Python's
/// `sorted(list(c.keys())) if len(set(c.values())) == 1 else []`
/// on a `collections.Counter`; Haskell's
/// `if length (nub ns) == 1 then sort (map fst hist) else []`;
/// Clojure's
/// `(let [f (frequencies coll), vs (vals f)] (if (apply = vs) (sort (keys f)) ()))`;
/// Racket's `(if (apply = (hash-values h)) (sort (hash-keys h) string<?) '())`.
/// Translation through pleme-io primitives: the N-ary `Vec<Self>`-
/// return lex-order direction-composition intersection witness-
/// collection on the closed-set trait binds through
/// [`Self::is_uniform`] gating a [`Self::sorted_variants`] call /
/// `Vec::new()` dichotomy — no new dep, no supertrait bound (the
/// uniformity gate replaces the `Eq`/`Hash` + `Ord` bound the
/// standard-library `Counter`+lex-sort signatures demand), no
/// histogram-carrier allocation, one algorithmic factor of
/// `T::CARDINALITY` shaved off the naive filter sweep via the
/// uniformity-collapse SHARPENING.
fn sorted_bimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if items.is_empty() || !<Self as ClosedSet>::is_uniform(items) {
::std::vec::Vec::new()
} else {
<Self as ClosedSet>::sorted_variants()
}
}
/// The N-ARY DECLARATION-ORDER "extremal variant" projection — the
/// `Option<Self>` DECLARATION-ORDER-FIRST-WITNESS over the direction-
/// composition UNION of [`Self::max_variant_count`] and
/// [`Self::min_variant_count`], reporting the FIRST variant of
/// [`Self::ALL`] (walked in declaration order) whose per-target count
/// hits AT LEAST ONE of the two histogram extremes, or `None` when
/// `items` is empty. The OPTION-RETURN opener on the direction-
/// composition axis peer to [`Self::modal_variant`] (argmax first-
/// witness, declaration) and [`Self::antimodal_variant`] (argmin
/// first-witness, declaration) one DIRECTION-COMPOSITION axis over
/// via the disjunctive extremal predicate — the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction-composition ×
/// union) row OPENS its declaration-order first-witness corner past
/// the direction-anchored (argmax, argmin) pair one DIRECTION-
/// COMPOSITION axis over on the modal-aggregation matrix. Direct
/// FIRST-WITNESS PROJECTION of the (set-level × `Vec<Self>` ×
/// statistical-aggregate × direction-composition × union)
/// [`Self::extremal_variants`] corner one RETURN-SHAPE axis over
/// (`Vec<Self>` witness-collection → `Option<Self>` first-witness),
/// AND peer to [`Self::has_extremal_variant`] one RETURN-SHAPE axis
/// over (`bool` existence → `Option<Self>` first-witness), AND direct
/// SET-LEVEL ARITY LIFT of the (per-target × bool × direction-
/// composition × union) [`Self::is_extremal_variant_of`] corner one
/// ARITY axis over via the FIRST-witness projection over the per-
/// target predicate. Not a fresh substrate primitive on the index
/// axis — the projection emerges from ONE `is_empty()` guard AND ONE
/// max/min-fold pair AND ONE `T::CARDINALITY`-bounded declaration-
/// order `find` sweep whose predicate binds
/// [`Self::count_occurrences_of`] against the pair via the union
/// test `c == max || c == min`, guarded so `&[]` maps to `None` past
/// the (max == min == 0, every-count == 0) degenerate arm where an
/// unguarded sweep would silently return `Some(T::first())` (every
/// variant satisfies `count == 0 == max == min` vacuously — the
/// WRONG structural answer past the non-emptiness precondition
/// [`Self::is_extremal_variant_of`] carries).
///
/// Composition-membership contract: for every NON-EMPTY slice
/// `items`, `T::extremal_variant(items).map(|v|
/// T::is_extremal_variant_of(v, items)) == Some(true)` — the
/// declaration-order first extremal witness, when present, satisfies
/// the per-target extremal predicate exactly. Sibling posture to
/// [`Self::modal_variant`]'s count-composition arm one DIRECTION-
/// COMPOSITION axis over (which binds against [`Self::max_variant_count`]
/// via the argmax predicate) and [`Self::antimodal_variant`]'s count-
/// composition arm one DIRECTION-COMPOSITION axis over (which binds
/// against [`Self::min_variant_count`] via the argmin predicate):
/// this projection binds against BOTH extremes disjunctively, so its
/// composition-membership arm is the direct
/// [`Self::is_extremal_variant_of`] predicate on the returned
/// witness rather than a scalar-equality arm on one extreme.
///
/// First-witness-of-plural identity: for every slice `items`,
/// `T::extremal_variant(items) == T::extremal_variants(items).first().copied()`
/// — the singular OPTION-return direction-composition union first-
/// witness AGREES with the FIRST element of the plural VEC-return
/// direction-composition union witness-collection walked in the same
/// declaration-order canonical order. On non-empty slices the plural
/// is non-empty (the argmax band covers at least one variant), so
/// `.first()` yields `Some(v)` for the SAME first-witness `v` the
/// singular reports; on the empty slice both collapse to `None`/
/// `Vec::new()`. The FIRST-WITNESS identity that binds the (set-
/// level × direction-composition × union) return-shape axis pair.
/// Pinned by
/// `extremal_variant_equals_first_of_extremal_variants_across_every_triple`.
///
/// Is-some-composition identity: for every slice `items`,
/// `T::extremal_variant(items).is_some() == T::has_extremal_variant(items)`
/// — the OPTION-return first-witness is `Some` iff the BOOL-return
/// existential predicate holds. The RETURN-SHAPE identity that binds
/// the (set-level × direction-composition × union) return-shape axis
/// pair against the bool existence corner. Pinned by
/// `extremal_variant_is_some_iff_has_extremal_variant_across_every_triple`.
///
/// Direction-composition disjunction identity: for every slice
/// `items`, `T::extremal_variant(items)` is one of `Some(v)` where
/// `v` sits at the argmax band OR at the argmin band — equivalently,
/// where [`Self::is_modal_variant_of`]`(v, items)` OR
/// [`Self::is_antimodal_variant_of`]`(v, items)` holds. The
/// DECLARATION-ORDER walk means it agrees with
/// [`Self::modal_variant`] whenever `T::first()` sits at the argmax
/// band (universally true on the flat-histogram fixpoints where max
/// == min so every variant hits both bands); on strictly non-flat
/// slices where `T::first()` sits STRICTLY between the extremes
/// (middle-band inhabitant of the (max, min) pair), the walk
/// continues past `T::first()` until it hits the FIRST variant of
/// [`Self::ALL`] at either extreme. Pinned by
/// `extremal_variant_when_some_lands_on_argmax_or_argmin_band_across_every_triple`.
///
/// Some-non-empty contract: `T::extremal_variant(items).is_some()`
/// iff `!items.is_empty()` on every slice — the empty-slice arm is
/// the SOLE `None`-arm; on every non-empty slice the sweep hits at
/// least one variant at the argmax band (the finite discrete
/// histogram achieves its max at at least one bin, and that bin's
/// count equals max, satisfying the union predicate). Pinned by
/// `extremal_variant_is_some_iff_slice_is_non_empty_across_every_triple`.
///
/// Empty-slice contract: `T::extremal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty guard is LOAD-BEARING past the
/// vacuous (max == min == 0, every-count == 0) degenerate arm where
/// an unguarded `find` sweep would silently return
/// `Some(T::first())` (every variant satisfies `c == 0 == max ==
/// min` vacuously — the WRONG structural answer). The `None`-at-
/// empty fixpoint is LOAD-BEARING as the drift catch for an override
/// that omits the guard: on the empty slice the guarded body returns
/// `None`; the unguarded sweep returns `Some(T::first())`,
/// bifurcating the contract loudly. Sibling posture to
/// [`Self::modal_variant`] + [`Self::antimodal_variant`]'s empty-
/// slice `None`-fixpoint one DIRECTION-COMPOSITION axis over. Pinned
/// by clause (156) and by
/// `extremal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract:
/// `T::extremal_variant(&[v]) == Some(T::first())` at cardinality
/// `>= 1` for every variant `v` — the sole position hits `v` at
/// count `1 == max`, every non-target variant sits at count `0 ==
/// min`, so EVERY variant of [`Self::ALL`] satisfies `c == max || c
/// == min` and the declaration-order `find` sweep hits
/// `T::first()` immediately. Sibling posture to
/// [`Self::extremal_variants`]'s matching-singleton `T::ALL.to_vec()`
/// fixpoint one RETURN-SHAPE axis over: the plural reports EVERY
/// variant is extremal on this fixture; the singular reports the
/// FIRST such variant in declaration order.
///
/// Full-set contract: `T::extremal_variant(<T as ClosedSet>::ALL)
/// == Some(T::first())` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at exactly one position in the full-set
/// slice, every per-variant count is `1 == max == min` (the flat-
/// histogram fixpoint pins the direction axis degeneracy at every
/// corner), and the DECLARATION-ORDER `find` sweep hits
/// `T::ALL[0] == T::first()` immediately. Pinned by clause (156) and
/// by
/// `extremal_variant_returns_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::extremal_variant(&doubled_full_set) == Some(T::first())`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// EXACTLY two positions, every per-variant count is `2 == max ==
/// min`, the flat-histogram fixpoint pins the direction axis
/// degeneracy at every corner via the (max == min == 2) collapse,
/// and the DECLARATION-ORDER `find` sweep hits `T::first()`
/// immediately. Pinned by clause (156) and by
/// `extremal_variant_returns_first_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract:
/// `T::extremal_variant(&[T::ALL[0], T::ALL[0], T::ALL[1]]) ==
/// Some(T::ALL[0])` at cardinality `>= 3` — the fixture hits
/// T::ALL[0] at count `2 == max`, T::ALL[1] at count `1` (MIDDLE-
/// band), T::ALL[2] at count `0 == min`; the declaration-order sweep
/// hits T::ALL[0] at the argmax band first (it satisfies `count == 2
/// == max`). LOAD-BEARING SOLE canonical fixture that DISCRIMINATES
/// this UNION projection from [`Self::modal_variant`] (which agrees
/// on this fixture — both project the argmax winner) AND from
/// [`Self::antimodal_variant`] (which yields `Some(T::ALL[2])` on
/// the same fixture, projecting the argmin instead of the union).
/// Pinned by clause (156) and by
/// `extremal_variant_agrees_with_modal_variant_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Ordering-axis invariance on the INPUT axis: the projection factors
/// through the ordering-agnostic max/min-fold pair + a declaration-
/// order walk over [`Self::ALL`] (which does NOT depend on `items`'
/// ordering); permuting `items` preserves its variant multiset, so
/// the projection is a function of that multiset alone. Sibling
/// posture to [`Self::extremal_variants`]'s reversal-invariance
/// contract one RETURN-SHAPE axis over. Pinned by
/// `extremal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::max_variant_count`] +
/// [`Self::min_variant_count`] pair + [`Self::count_occurrences_of`]
/// projections at the trait level. The composition uses one
/// `is_empty()` guard AND one max/min-fold pair AND one
/// `T::CARDINALITY`-bounded declaration-order `find` sweep, so the
/// sweep is O(T::CARDINALITY * n) on slice arity `n` (both folds
/// stream through the per-variant multiplicity primitive without
/// materializing an intermediate `Vec<usize>` histogram; the `find`
/// short-circuits on the first hit — `T::first()` on every flat-
/// histogram fixture, at worst `T::CARDINALITY - 1` steps in on a
/// worst-case walk that has to skip every middle-band inhabitant).
/// Allocation-free (`Option<Self>` return has no heap footprint), no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::extremal_variant`]: a `tatara-check` predicate `(check-
/// phases-report-extremal-witness …)` on a `WorkloadPhase` sequence
/// that names ONE canonical outlier phase (either the most-visited
/// or the least-visited, whichever appears first in declaration
/// order) without paying for the full [`Self::extremal_variants`]
/// witness-collection when only ONE representative is needed for an
/// error message; an LSP diagnostic on a Lisp-author-written
/// variant-list that flags "the first outlier variant of your list"
/// (arg-highlight target) in ONE typed `Option<Self>` rather than
/// an inline
/// `T::ALL.iter().copied().find(|&v| T::is_extremal_variant_of(v,
/// items))` sweep; a Sekiban audit-trail metric that gauges the
/// declaration-order-first outlier classification when only the
/// canonical first witness is displayed in a compact one-line
/// summary. Each binds to ONE typed OPTION-return direction-
/// composition union first-witness on the trait rather than re-
/// deriving the max/min-fold pair + declaration-order `find`
/// composition inline per callsite.
///
/// Compounding closure: the (set-level × `Option<Self>` × direction-
/// composition × union) row OPENS its declaration-order first-
/// witness corner past the direction-anchored (argmax
/// [`Self::modal_variant`], argmin [`Self::antimodal_variant`]) pair
/// one DIRECTION-COMPOSITION axis over on the modal-aggregation
/// matrix. Combined with the pre-existing (set-level × `Vec<Self>` ×
/// direction-composition) 5-column row + the (set-level × `bool` ×
/// direction-composition × existential) 3-column row + the (set-
/// level × `usize` × direction-composition × cardinality) 3-column
/// row + the (per-target × `bool` × direction-composition) 3-column
/// row on the modal-aggregation matrix, the DIRECTION-COMPOSITION
/// axis's UNION arm now carries a typed FIRST-WITNESS projection at
/// the singular return-shape complementing the plural collection,
/// the existence bit, the cardinality count, and the per-target
/// predicate. The natural next lifts past this OPENER are:
///
/// * `sorted_extremal_variant(items) -> Option<Self>` — the LEX-
/// ORDER first-witness peer one ORDERING axis over from
/// [`Self::extremal_variant`], closing the (set-level ×
/// `Option<Self>` × direction-composition × union × ordering)
/// 2-corner face at its lex arm.
/// * `middle_band_variant(items) -> Option<Self>` — the COMPLEMENT
/// first-witness peer one DIRECTION-COMPOSITION axis over.
/// * `bimodal_variant(items) -> Option<Self>` — the INTERSECTION
/// first-witness peer one DIRECTION-COMPOSITION axis over, gated
/// by the same uniformity-collapse dichotomy as
/// [`Self::bimodal_variants`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// declaration-order direction-composition union first-witness
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::ALL.iter().copied().find(|&v| { let c =
/// T::count_occurrences_of(v, items); c == T::max_variant_count(items)
/// || c == T::min_variant_count(items) })` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform; the
/// (set-level × `Option<Self>` × direction-composition × union)
/// corner was an unnamed inline PROJECTION recurring at every
/// prospective downstream "which is the FIRST outlier variant?" site
/// pre-lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of THREE substrate
/// primitives ([`Self::max_variant_count`],
/// [`Self::min_variant_count`], [`Self::count_occurrences_of`])
/// under a disjunctive predicate over a bounded declaration-order
/// `find` — no per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `find (fun v => Nat.eqb (count_occ
/// eqb l v) (max_count l) || Nat.eqb (count_occ eqb l v)
/// (min_count l)) T` idiom composing a first-witness projection
/// with a disjunctive extremal predicate on a decidable-equality
/// carrier; Racket's `(findf (λ (v) (let ((c (count (λ (w) (equal?
/// v w)) items))) (or (= c (apply max histogram)) (= c (apply min
/// histogram))))) all)`; Haskell's `find (\v -> let c = length
/// (filter (== v) items) in c == maximum hist || c == minimum
/// hist) all`; Julia's `findfirst(v -> let c = count(==(v), items);
/// c == maximum(hist) || c == minimum(hist), T)`; Python's `next((v
/// for v in T if items.count(v) in (max_c, min_c)), None)`. Rust's
/// own `T::ALL.iter().copied().find(|v| { … })` idiom binds through
/// a `Self: PartialEq` supertrait bound. SQL's `SELECT variant FROM
/// hist WHERE count IN (SELECT MAX(count) FROM hist UNION SELECT
/// MIN(count) FROM hist) LIMIT 1`. Translation through pleme-io
/// primitives: the declaration-order OPTION-return direction-
/// composition union first-witness on the closed-set trait binds
/// through one `is_empty()` guard + one max/min-fold pair + one
/// declaration-order `find` — no new dep, no supertrait bound (the
/// [`Self::count_occurrences_of`] projection replaces the `Eq`/
/// `Hash` bound the standard-library `Counter`/`countmap`/
/// `frequencies` signatures demand), no histogram-carrier
/// allocation, no intermediate `Vec<usize>` — one algorithmic
/// factor short-circuits at the first extremal witness rather than
/// walking every variant.
fn extremal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL.iter().copied().find(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c == max || c == min
})
}
/// The N-ARY ORDERING-AGNOSTIC "sorted extremal variant" projection
/// — the `Option<Self>` LEX-ORDER-FIRST-WITNESS over the
/// [`Self::variant_counts`] histogram under the DIRECTION-
/// COMPOSITION UNION predicate, reporting the FIRST variant of
/// [`Self::sorted_variants`] (walked in LEX order under the
/// ASCII-`sort_unstable_by_key(label)` discriminator) whose per-
/// target count equals EITHER [`Self::max_variant_count`] OR
/// [`Self::min_variant_count`], or `None` when `items` is empty.
/// The LEX-ORDER peer of [`Self::extremal_variant`] on the
/// (declaration, lex) ordering axis of the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction-composition ×
/// union) column — CLOSES the lex arm past the declaration arm the
/// sibling [`Self::extremal_variant`] opened, completing the
/// (set-level × `Option<Self>` × direction-composition × union ×
/// ordering) 2-corner face at both corners. Where
/// [`Self::extremal_variant`] walks [`Self::ALL`] in DECLARATION
/// order and commits at the first variant satisfying the union
/// predicate `c == max || c == min`, this projection walks
/// [`Self::sorted_variants`] in LEX order and commits at the first
/// variant satisfying the SAME union predicate under the ASCII-
/// `sort_unstable_by_key(label)` discriminator. The two projections
/// AGREE byte-for-byte on every implementor whose declaration order
/// coincides with the ASCII-lex order of its labels (a common case
/// for enums whose variants happen to be declared in
/// alphabetically-sorted order) AND on every slice whose union band
/// covers all of [`Self::ALL`] (the flat-histogram fixpoints
/// `T::ALL`, `T::ALL ++ T::ALL`, `&[]` degenerately-empty guard,
/// and every matching-singleton at cardinality `>= 2` where every
/// variant satisfies `c == max || c == min`); they BIFURCATE at the
/// smallest slice whose union band excludes the ambient
/// `T::sorted_first()` in some non-flat middle-band configuration
/// AND whose declaration order diverges from lex order across that
/// band. Not a fresh substrate primitive on the index axis — the
/// projection emerges from the same `is_empty()` guard + max/min-
/// fold pair + `find` sweep, differing only in the substrate
/// primitive the sweep routes through
/// ([`Self::sorted_variants`] rather than [`Self::ALL`]).
///
/// Composition-equality contract: for every slice `items`,
/// `T::sorted_extremal_variant(items) ==
/// T::sorted_extremal_variants(items).first().copied()` — the
/// singular OPTION-return direction-composition union lex-order-
/// first-witness AGREES with the FIRST element of the plural
/// VEC-return direction-composition union lex-order witness-
/// collection [`Self::sorted_extremal_variants`] returns. Pinned
/// by
/// `sorted_extremal_variant_equals_first_of_sorted_extremal_variants_across_every_triple`.
///
/// Is-some-composition contract: for every slice `items`,
/// `T::sorted_extremal_variant(items).is_some() ==
/// T::has_extremal_variant(items)` — the OPTION-return LEX-first-
/// witness is Some iff the BOOL-return existential predicate holds.
/// Sibling posture to
/// `extremal_variant_is_some_iff_has_extremal_variant_across_every_triple`
/// one ORDERING axis over: BOTH the declaration-order and lex-
/// order first-witness projections agree with the ORDERING-
/// AGNOSTIC existential predicate on the same (Some, None)
/// partition. Pinned by
/// `sorted_extremal_variant_is_some_iff_has_extremal_variant_across_every_triple`.
///
/// Sibling-composition contract: for every slice `items`,
/// `T::sorted_extremal_variant(items).is_some() ==
/// T::extremal_variant(items).is_some()` — the (Some, None)
/// partition of the lex-order first-witness AGREES with the (Some,
/// None) partition of the declaration-order first-witness on
/// every slice. The two projections may disagree on the VALUE they
/// report inside the Some arm on any slice whose union band spans
/// a (T::first() != T::sorted_first())-divergent split, but they
/// AGREE on WHEN the Some arm fires. Pinned by
/// `sorted_extremal_variant_is_some_iff_extremal_variant_is_some_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_extremal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, [`Self::max_variant_count`]
/// and [`Self::min_variant_count`] BOTH collapse to `0`, and every
/// variant hits `count == 0 == max == min` — an UNGUARDED
/// `sorted_variants().into_iter().find(|&v| c == max || c == min)`
/// sweep would silently return `Some(T::sorted_first())` past this
/// degenerate arm; the empty guard maps `&[]` to `None` before the
/// sweep. Pinned by clause (157) and by
/// `sorted_extremal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_extremal_variant(&[target]) ==
/// Some(T::sorted_first())` for every target at cardinality
/// `>= 2` — the sole position hits `target` at count `1 == max`
/// while every non-target variant sits at count `0 == min`, so
/// EVERY variant of [`Self::ALL`] satisfies `c == max || c == min`
/// under the union predicate, and the lex-order `find` sweep hits
/// [`Self::sorted_first`] immediately regardless of which target
/// sits in the singleton. Pinned by clause (157) and by
/// `sorted_extremal_variant_returns_sorted_first_on_every_matching_singleton_across_every_variant`.
///
/// Full-set contract: `T::sorted_extremal_variant(<T as
/// ClosedSet>::ALL) == Some(T::sorted_first())` UNCONDITIONALLY —
/// pairwise-distinctness (clause (3)) pins every variant of
/// [`Self::ALL`] at exactly one position on the full-set slice,
/// every per-variant count is `1`, [`Self::max_variant_count`]
/// == [`Self::min_variant_count`] == `1`, every variant is
/// extremal via the (max == min == 1) flat-histogram collapse, and
/// the lex-order sweep hits [`Self::sorted_first`] immediately.
/// This is the LOAD-BEARING full-set fixpoint DISCRIMINATING this
/// LEX-order projection from the DECLARATION-order sibling
/// [`Self::extremal_variant`] (which lands on [`Self::first`]) on
/// any implementor whose declaration order diverges from lex order.
/// Pinned by clause (157) and by
/// `sorted_extremal_variant_returns_sorted_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_extremal_variant(<T as ClosedSet>::ALL ++ <T as
/// ClosedSet>::ALL) == Some(T::sorted_first())` UNCONDITIONALLY —
/// max == min == 2, every variant is extremal via the second
/// flat-histogram fixpoint, and the lex-order sweep hits
/// [`Self::sorted_first`] immediately. Pinned by clause (157) and
/// by
/// `sorted_extremal_variant_returns_sorted_first_on_the_doubled_full_set_across_every_kind`.
///
/// Direction-composition disjunction identity: for every slice
/// `items`, whenever `T::sorted_extremal_variant(items) ==
/// Some(v)`, `T::is_extremal_variant_of(v, items)` holds — the
/// reported witness sits at EITHER the argmax band OR the argmin
/// band (equivalently, [`Self::is_modal_variant_of`] holds OR
/// [`Self::is_antimodal_variant_of`] holds). Pinned by
/// `sorted_extremal_variant_when_some_lands_on_argmax_or_argmin_band_across_every_triple`.
///
/// Reversal-invariance: the projection factors through the
/// ordering-agnostic max/min-fold pair + a walk over
/// [`Self::sorted_variants`] in LEX order — the (declaration, lex)
/// axis on the SLICE side COLLAPSES on element equality because
/// max/min are functions of the multiset alone. Pinned by
/// `sorted_extremal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection composes ONE `is_empty()` guard
/// with the max/min-fold pair and one `find` sweep over the trait-
/// provided [`Self::sorted_variants`] surface — no
/// `PartialEq`/`Eq`/`Hash`/`Ord` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); short-circuits at the first witness rather than
/// walking every variant.
///
/// Future consumers that compose against
/// [`Self::sorted_extremal_variant`]: a `tatara-check` predicate
/// `(check-first-outlier-lex …)` that verifies the ONE canonical
/// outlier variant name (either most-common or least-common,
/// whichever appears first in ALPHABETICAL order) rather than
/// declaration order — the LSP-facing ordering-stable variant of
/// the [`Self::extremal_variant`] consumer inventory; an LSP
/// diagnostic that highlights the FIRST outlier in a Lisp-author-
/// written closed-set field under LEX order (so the diagnostic
/// location is stable across `#[derive(TataraDomain)]` reorderings
/// of the variant declaration); a Sekiban audit-trail gauge that
/// names the lex-first outlier for humans reading through
/// alphabetized dashboards. Each binds to ONE typed
/// `Option<Self>`-return call rather than re-deriving the
/// `sorted_variants().into_iter().find(|v| c == max || c == min)`
/// composition per callsite.
///
/// Compounding closure: the (set-level × `Option<Self>` ×
/// direction-composition × union × ordering) 2-corner face now
/// closes EXHAUSTIVELY at BOTH corners — the declaration arm at
/// [`Self::extremal_variant`], the lex arm at THIS projection.
/// The next lift on the same direction-composition axis is the
/// COMPLEMENT-arm sibling `middle_band_variant(items) ->
/// Option<Self>` (the declaration-order first-witness of the
/// COMPLEMENT band `c != max && c != min`) OPENING the (set-level
/// × `Option<Self>` × direction-composition × complement × ordering)
/// 2-corner face at its declaration arm past the union-arm this
/// pair closes, followed by its own `sorted_middle_band_variant`
/// lex sibling that closes the complement lex arm.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary LEX-
/// ORDER direction-composition union first-witness becomes a
/// TYPE-level primitive on the closed-set trait. THEORY.md §V.1 —
/// knowable platform; naming the (set-level × `Option<Self>` ×
/// direction-composition × union × lex) corner on the trait makes
/// the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::sorted_variants`] projection composed with the trait's
/// max/min-fold pair under the disjunctive union predicate.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the same three substrate primitives as the
/// declaration-order sibling under a substitution of the walk
/// surface — no per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `find (fun v => Nat.eqb (count_occ
/// eqb l v) (max_count l) || Nat.eqb (count_occ eqb l v)
/// (min_count l)) (sort String_as_OT.le T)` idiom composing a
/// first-witness projection with a disjunctive extremal predicate
/// over a lex-sorted carrier; Racket's `(findf (λ (v) …)
/// (sort all string<? #:key symbol->string))`; Haskell's
/// `find (\v -> ...) (sortBy (comparing label) all)`; Python's
/// `next((v for v in sorted(T, key=str) if items.count(v) in (max_c,
/// min_c)), None)`. Translation through pleme-io primitives: the
/// LEX-ORDER OPTION-return direction-composition union first-
/// witness on the closed-set trait binds through
/// [`Self::sorted_variants`] (an ASCII-`sort_unstable_by_key`
/// projection replacing the standard-library `Ord`/`String`
/// carrier bound) + the max/min-fold pair + one lex-order `find`
/// — no new dep, no supertrait bound (`Sized + Copy + 'static`
/// stays untouched), no allocation beyond the
/// [`Self::sorted_variants`] Vec-return itself, short-circuits at
/// the first witness.
fn sorted_extremal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c == max || c == min
})
}
/// The N-ARY ORDERING-AGNOSTIC "middle-band variant" projection —
/// the `Option<Self>` DECLARATION-ORDER-FIRST-WITNESS over the
/// [`Self::variant_counts`] histogram under the DIRECTION-
/// COMPOSITION COMPLEMENT predicate, reporting the FIRST variant
/// of [`Self::ALL`] (walked in DECLARATION order) whose per-target
/// count sits STRICTLY between [`Self::min_variant_count`] and
/// [`Self::max_variant_count`] (equivalently, whose count neither
/// tops the argmax band NOR bottoms the argmin band), or `None`
/// when `items` is empty OR every variant sits at one of the two
/// extremes. The COMPLEMENT-arm OPENER on the (set-level ×
/// `Option<Self>` × direction-composition × ordering) row past the
/// (set-level × `Option<Self>` × direction-composition × union ×
/// ordering) 2-corner face the ([`Self::extremal_variant`],
/// [`Self::sorted_extremal_variant`]) pair just closed one
/// COMBINATOR axis over via De Morgan complement — where the union
/// arm walks with `c == max || c == min`, THIS complement arm
/// walks with `c != max && c != min`. Peer to
/// [`Self::middle_band_variants`] one RETURN-SHAPE axis over
/// (`Vec<Self>` → `Option<Self>` first-witness), peer to
/// [`Self::has_middle_band_variant`] one RETURN-SHAPE axis over
/// (`bool` → `Option<Self>`), peer to [`Self::count_middle_band_variants`]
/// one RETURN-SHAPE axis over (`usize` → `Option<Self>`), and
/// peer to [`Self::extremal_variant`] one COMBINATOR axis over
/// (union → complement) via the STRICT interior conjunction
/// SHARPENING the union disjunction's OR into the complement
/// conjunction's AND-NOT.
///
/// Composition-equality contract: for every slice `items`,
/// `T::middle_band_variant(items) ==
/// T::middle_band_variants(items).first().copied()` — the
/// singular OPTION-return direction-composition complement
/// declaration-order first-witness AGREES with the FIRST element
/// of the plural VEC-return direction-composition complement
/// declaration-order witness-collection [`Self::middle_band_variants`]
/// returns. Pinned by
/// `middle_band_variant_equals_first_of_middle_band_variants_across_every_triple`.
///
/// Is-some-composition contract: for every slice `items`,
/// `T::middle_band_variant(items).is_some() ==
/// T::has_middle_band_variant(items)` — the OPTION-return first-
/// witness is Some iff the BOOL-return existential predicate
/// holds. Pinned by
/// `middle_band_variant_is_some_iff_has_middle_band_variant_across_every_triple`.
///
/// Empty-slice contract: `T::middle_band_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions, every
/// per-variant count is `0`, [`Self::max_variant_count`] and
/// [`Self::min_variant_count`] both collapse to `0`, and every
/// variant hits `count == 0 == max == min` under the union
/// predicate — equivalently NO variant satisfies the STRICT
/// interior conjunction `c != max && c != min` because every
/// count equals BOTH extremes; the empty guard maps `&[]` to
/// `None` before the sweep to align the empty-slice semantics
/// with the union sibling's guard. Pinned by
/// `middle_band_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::middle_band_variant(<T as
/// ClosedSet>::ALL) == None` UNCONDITIONALLY — clause (3)'s
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] at exactly one position on the full-set slice,
/// every per-variant count is `1`, [`Self::max_variant_count`]
/// == [`Self::min_variant_count`] == `1`, EVERY variant sits at
/// BOTH extremes simultaneously via the (max == min == 1) flat-
/// histogram collapse, so NO variant satisfies the strict interior
/// conjunction. This is the LOAD-BEARING flat-histogram None-arm
/// DISCRIMINATING this COMPLEMENT projection from
/// [`Self::extremal_variant`] (which lands on
/// `Some(T::first())` on the same fixture). Pinned by
/// `middle_band_variant_returns_none_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::middle_band_variant(<T as ClosedSet>::ALL ++ <T as
/// ClosedSet>::ALL) == None` UNCONDITIONALLY — max == min == 2,
/// every variant sits at BOTH extremes via the second flat-
/// histogram fixpoint, no variant sits strictly between. Pinned
/// by `middle_band_variant_returns_none_on_the_doubled_full_set_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::middle_band_variant(&[v]) == None` for every variant `v`
/// — the sole position hits `v` at count `1 == max` while every
/// non-target variant sits at count `0 == min`, so every variant
/// sits AT one of the two extremes and NO variant sits strictly
/// between. LOAD-BEARING contract separating this COMPLEMENT
/// projection from [`Self::extremal_variant`] (which reports
/// `Some(T::first())` on the same fixture). Pinned by
/// `middle_band_variant_returns_none_on_every_matching_singleton_across_every_variant`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the bimodal
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is
/// `(T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..]
/// -> 0 == min)`; the middle-band target `T::ALL[1]` is the SOLE
/// inhabitant of the strict interior, so the declaration-order
/// sweep hits it immediately regardless of walk order and
/// `T::middle_band_variant(&bimodal_triple) == Some(T::ALL[1])`.
/// LOAD-BEARING SOLE canonical fixture where this projection
/// returns a NON-`None` value — every other canonical fixpoint
/// pins it to `None`. Pinned by
/// `middle_band_variant_returns_all_1_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Direction-composition complement identity: for every slice
/// `items`, whenever `T::middle_band_variant(items) == Some(v)`,
/// [`Self::is_middle_band_variant_of`]`(v, items)` holds — the
/// reported witness sits STRICTLY between the argmax and argmin
/// bands (equivalently, neither [`Self::is_modal_variant_of`]
/// nor [`Self::is_antimodal_variant_of`] holds). Pinned by
/// `middle_band_variant_when_some_lands_on_strict_interior_band_across_every_triple`.
///
/// Union-disjointness identity: for every slice `items`,
/// whenever `T::middle_band_variant(items) == Some(v)`,
/// [`Self::is_extremal_variant_of`]`(v, items)` is `false` — the
/// (extreme / middle) partition of the closed set on non-empty
/// slices is DISJOINT by construction. Pinned by
/// `middle_band_variant_when_some_is_not_extremal_across_every_triple`.
///
/// Reversal-invariance: the projection factors through the
/// ordering-agnostic max/min-fold pair + a walk over
/// [`Self::ALL`] in declaration order — the (declaration, lex)
/// axis on the SLICE side COLLAPSES on element equality because
/// max/min are functions of the multiset alone. Pinned by
/// `middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection composes ONE `is_empty()`
/// guard with the max/min-fold pair and one declaration-order
/// `find` sweep over [`Self::ALL`] — no
/// `PartialEq`/`Eq`/`Hash`/`Ord` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); short-circuits at the first middle-band witness
/// rather than walking every variant.
///
/// Future consumers that compose against
/// [`Self::middle_band_variant`]: a `tatara-check` predicate
/// `(check-first-middle-band-target …)` that surfaces the ONE
/// canonical middle-band variant name for a rollout histogram
/// window whose distribution is non-flat — the human-facing
/// "which phase is neither the most nor the least frequent, in
/// declaration order?" answer per window; an LSP diagnostic
/// that highlights the FIRST middle-band variant in a Lisp-
/// author-written closed-set field (so authors see which variant
/// sits STRICTLY between the histogram extremes without walking
/// the plural collection); a Sekiban audit-trail gauge that names
/// the first middle-band inhabitant for dashboards summarizing
/// non-flat distributions in ONE cell. Each binds to ONE typed
/// `Option<Self>`-return call rather than re-deriving the
/// `T::ALL.iter().copied().find(|v| c != max && c != min)`
/// composition per callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × direction-composition × complement ×
/// ordering) 2-corner face at its declaration arm past the union-
/// arm the ([`Self::extremal_variant`],
/// [`Self::sorted_extremal_variant`]) pair closed. The natural
/// next lift on the same combinator axis is
/// `sorted_middle_band_variant(items) -> Option<Self>` — the
/// LEX-order peer that CLOSES the complement 2-corner face at
/// its lex arm; after that, `bimodal_variant(items) ->
/// Option<Self>` opens the INTERSECTION arm past the COMPLEMENT
/// arm this projection opens one COMBINATOR axis over via
/// `c == max && c == min` (the flat-diagonal predicate).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// declaration-order direction-composition complement first-
/// witness becomes a TYPE-level primitive on the closed-set
/// trait. THEORY.md §V.1 — knowable platform; naming the (set-
/// level × `Option<Self>` × direction-composition × complement ×
/// declaration) corner on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's [`Self::ALL`] projection
/// composed with the max/min-fold pair under the strict interior
/// conjunction. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the same three substrate
/// primitives as the union sibling under a substitution of the
/// predicate combinator (`|| → && !`, De Morgan complement).
///
/// Frontier inspiration: Coq's `find (fun v => negb (Nat.eqb
/// (count_occ eqb l v) (max_count l)) && negb (Nat.eqb
/// (count_occ eqb l v) (min_count l))) T` idiom composing a
/// first-witness projection with a strict-interior extremal
/// predicate; Racket's `(findf (λ (v) (and (not (= c max)) (not
/// (= c min)))) T)`; Haskell's `find (\v -> c v /= max && c v /=
/// min) T`; Python's `next((v for v in T if min_c < items.count(v)
/// < max_c), None)`. Translation through pleme-io primitives:
/// the DECLARATION-ORDER OPTION-return direction-composition
/// complement first-witness on the closed-set trait binds
/// through one `is_empty()` guard + one max/min-fold pair + one
/// declaration-order `find` under the strict-interior conjunction
/// — no new dep, no supertrait bound
/// (the [`Self::count_occurrences_of`] projection replaces the
/// `Eq`/`Hash` bound the standard-library `Counter` signatures
/// demand), no histogram-carrier allocation, short-circuits at
/// the first middle-band witness.
fn middle_band_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::ALL.iter().copied().find(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c != max && c != min
})
}
/// The N-ARY ORDERING-AGNOSTIC "sorted middle-band variant"
/// projection — the `Option<Self>` LEX-ORDER-FIRST-WITNESS over
/// the [`Self::variant_counts`] histogram under the DIRECTION-
/// COMPOSITION COMPLEMENT predicate, reporting the FIRST variant
/// of [`Self::sorted_variants`] (walked in LEX order under the
/// ASCII-`sort_unstable_by_key(label)` discriminator) whose per-
/// target count sits STRICTLY between [`Self::min_variant_count`]
/// and [`Self::max_variant_count`] (equivalently, whose count
/// neither tops the argmax band NOR bottoms the argmin band), or
/// `None` when `items` is empty OR every variant sits at one of
/// the two extremes. The LEX-ORDER peer of
/// [`Self::middle_band_variant`] on the (declaration, lex) ordering
/// axis of the (set-level × `Option<Self>` × statistical-aggregate
/// × direction-composition × complement) column — CLOSES the lex
/// arm past the declaration arm the sibling
/// [`Self::middle_band_variant`] opened, completing the (set-level
/// × `Option<Self>` × direction-composition × complement ×
/// ordering) 2-corner face at both corners. Where
/// [`Self::middle_band_variant`] walks [`Self::ALL`] in DECLARATION
/// order and commits at the first variant satisfying the STRICT
/// interior conjunction `c != max && c != min`, this projection
/// walks [`Self::sorted_variants`] in LEX order and commits at the
/// first variant satisfying the SAME strict interior conjunction
/// under the ASCII-`sort_unstable_by_key(label)` discriminator. The
/// two projections AGREE byte-for-byte on every implementor whose
/// declaration order coincides with the ASCII-lex order of its
/// labels (a common case for enums whose variants happen to be
/// declared in alphabetically-sorted order) AND on every slice
/// whose middle band is EMPTY (`None` on both sides via the shared
/// flat-histogram + matching-singleton `None` fixpoints); they
/// BIFURCATE at the smallest slice whose middle band is non-empty
/// AND whose declaration order diverges from lex order across that
/// band. Not a fresh substrate primitive on the index axis — the
/// projection emerges from the same `is_empty()` guard + max/min-
/// fold pair + `find` sweep as the declaration-order sibling,
/// differing only in the substrate primitive the sweep routes
/// through ([`Self::sorted_variants`] rather than [`Self::ALL`])
/// AND in NOTHING else on the predicate axis.
///
/// Composition-equality contract: for every slice `items`,
/// `T::sorted_middle_band_variant(items) ==
/// T::sorted_middle_band_variants(items).first().copied()` — the
/// singular OPTION-return direction-composition complement lex-
/// order first-witness AGREES with the FIRST element of the plural
/// VEC-return direction-composition complement lex-order witness-
/// collection [`Self::sorted_middle_band_variants`] returns. Pinned
/// by
/// `sorted_middle_band_variant_equals_first_of_sorted_middle_band_variants_across_every_triple`.
///
/// Is-some-composition contract: for every slice `items`,
/// `T::sorted_middle_band_variant(items).is_some() ==
/// T::has_middle_band_variant(items)` — the OPTION-return LEX-
/// first-witness is Some iff the BOOL-return existential predicate
/// holds. Sibling posture to
/// `middle_band_variant_is_some_iff_has_middle_band_variant_across_every_triple`
/// one ORDERING axis over: BOTH the declaration-order and lex-
/// order first-witness projections agree with the ORDERING-
/// AGNOSTIC existential predicate on the same (Some, None)
/// partition. Pinned by
/// `sorted_middle_band_variant_is_some_iff_has_middle_band_variant_across_every_triple`.
///
/// Sibling-composition contract: for every slice `items`,
/// `T::sorted_middle_band_variant(items).is_some() ==
/// T::middle_band_variant(items).is_some()` — the (Some, None)
/// partition of the lex-order first-witness AGREES with the
/// (Some, None) partition of the declaration-order first-witness
/// on every slice. The two projections may disagree on the VALUE
/// they report inside the Some arm on any slice whose middle band
/// spans a (T::first() != T::sorted_first())-divergent split, but
/// they AGREE on WHEN the Some arm fires. Pinned by
/// `sorted_middle_band_variant_is_some_iff_middle_band_variant_is_some_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_middle_band_variant(&[]) ==
/// None` UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant occurrence count is `0`,
/// [`Self::max_variant_count`] and [`Self::min_variant_count`]
/// BOTH collapse to `0`, and NO variant satisfies the STRICT
/// interior conjunction `0 != 0 && 0 != 0` (which is `false` at
/// every variant). Sibling posture to
/// [`Self::middle_band_variant`]'s empty-slice `None`-fixpoint one
/// ORDERING axis over: the empty guard is COSMETIC alignment with
/// the union sibling [`Self::sorted_extremal_variant`]'s guard, not
/// load-bearing on the empty-slice fixpoint (the unguarded LEX
/// sweep body ALSO lands on `None` here — the strict-interior
/// conjunction fails at every variant on the vacuous
/// (max == min == 0, every-count == 0) degenerate arm). Pinned by
/// clause (159) and by
/// `sorted_middle_band_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_middle_band_variant(&[target]) == None` for every
/// variant `target` — the sole position hits `target` at count
/// `1 == max`, every non-target variant sits at count `0 == min`,
/// so EVERY variant of [`Self::ALL`] sits AT one of the two
/// extremes and NO variant sits strictly between; the LEX-order
/// sweep exhausts [`Self::sorted_variants`] without a hit and
/// returns `None`. Sibling posture to
/// [`Self::middle_band_variant`]'s matching-singleton `None`-arm
/// one ORDERING axis over: the union-band-covers-everything
/// fixpoint on a matching singleton pins BOTH the declaration-
/// order and lex-order complement projections at `None`
/// independently of walk order. Pinned by clause (159) and by
/// `sorted_middle_band_variant_returns_none_on_every_matching_singleton_across_every_variant`.
///
/// Full-set contract: `T::sorted_middle_band_variant(<T as
/// ClosedSet>::ALL) == None` UNCONDITIONALLY — clause (3)'s
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] at exactly one position, every per-variant count
/// is `1 == max == min` (the flat-histogram fixpoint pins the
/// direction axis degeneracy at every corner), EVERY variant sits
/// at BOTH extremes simultaneously via the (max == min == 1)
/// collapse, and NO variant satisfies the STRICT interior
/// conjunction. The LOAD-BEARING flat-histogram `None`-arm
/// DISCRIMINATING this COMPLEMENT projection from
/// [`Self::sorted_extremal_variant`] (which lands on
/// Some(T::sorted_first()) on the same fixture). Pinned by clause
/// (159) and by
/// `sorted_middle_band_variant_returns_none_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_middle_band_variant(&doubled_full_set) == None`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// EXACTLY two positions, every per-variant count is `2 == max ==
/// min`, the flat-histogram fixpoint pins the direction axis
/// degeneracy at every corner via the (max == min == 2) collapse,
/// and NO variant sits strictly between. Pinned by clause (159)
/// and by
/// `sorted_middle_band_variant_returns_none_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract:
/// `T::sorted_middle_band_variant(&[T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == Some(T::sorted_variants()[1])` at cardinality
/// `>= 3` on any implementor where declaration and lex orders
/// coincide on the first three positions (as on the StubKind
/// carrier) — the fixture hits T::ALL[0] at count `2 == max`,
/// T::ALL[1] at count `1` (MIDDLE-band), T::ALL[2] at count
/// `0 == min`; the LEX-order sweep visits [`Self::sorted_variants`]
/// in ASCII order and commits at T::ALL[1] because T::ALL[0] fails
/// the strict interior at `c == max` and T::ALL[1] is the FIRST
/// LEX-order variant satisfying `c != max && c != min`. LOAD-
/// BEARING SOLE canonical fixture where this projection returns a
/// NON-`None` value — every other canonical fixpoint (empty,
/// full-set, doubled-full-set, matching-singleton) pins it to
/// `None`. Pinned by
/// `sorted_middle_band_variant_returns_sorted_all_1_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Direction-composition complement identity: for every slice
/// `items`, whenever `T::sorted_middle_band_variant(items) ==
/// Some(v)`, [`Self::is_middle_band_variant_of`]`(v, items)`
/// holds — the reported witness sits STRICTLY between the argmax
/// and argmin bands (equivalently, neither
/// [`Self::is_modal_variant_of`] nor [`Self::is_antimodal_variant_of`]
/// holds). Pinned by
/// `sorted_middle_band_variant_when_some_lands_on_strict_interior_band_across_every_triple`.
///
/// Union-disjointness identity: for every slice `items`, whenever
/// `T::sorted_middle_band_variant(items) == Some(v)`,
/// [`Self::is_extremal_variant_of`]`(v, items)` is `false` — the
/// (extreme / middle) partition of the closed set on non-empty
/// slices is DISJOINT by construction, so the LEX-order first
/// witness of the complement band NEVER sits at the extremes.
/// Pinned by
/// `sorted_middle_band_variant_when_some_is_not_extremal_across_every_triple`.
///
/// Reversal-invariance: the projection factors through the
/// ordering-agnostic max/min-fold pair + a walk over
/// [`Self::sorted_variants`] in lex order — the (declaration, lex)
/// axis on the SLICE side COLLAPSES on element equality because
/// max/min are functions of the multiset alone AND
/// [`Self::sorted_variants`] itself depends only on the closed set
/// (not on `items`). Pinned by
/// `sorted_middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection composes ONE `is_empty()` guard
/// with the max/min-fold pair and one lex-order `find` sweep over
/// [`Self::sorted_variants`] — no `PartialEq`/`Eq`/`Hash`/`Ord`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched); short-circuits at the first
/// middle-band witness rather than walking every variant.
///
/// Future consumers that compose against
/// [`Self::sorted_middle_band_variant`]: a `tatara-check` predicate
/// `(check-first-sorted-middle-band-target …)` that surfaces the
/// ONE canonical alphabetical middle-band variant name for a
/// rollout histogram window whose distribution is non-flat — the
/// human-facing "which phase is neither the most nor the least
/// frequent, in alphabetical order?" answer per window; an LSP
/// diagnostic that highlights the FIRST alphabetical middle-band
/// variant in a Lisp-author-written closed-set field (so authors
/// see which variant sits STRICTLY between the histogram extremes
/// under the canonical alphabetical presentation the LSP surfaces
/// enum members in); a Sekiban audit-trail gauge that names the
/// first alphabetical middle-band inhabitant for dashboards
/// summarizing non-flat distributions under the canonical
/// alphabetical sort every operator scans by default. Each binds
/// to ONE typed `Option<Self>`-return call rather than re-deriving
/// the `T::sorted_variants().into_iter().find(|v| c != max && c !=
/// min)` composition per callsite.
///
/// Compounding closure: the (set-level × `Option<Self>` ×
/// direction-composition × complement × ordering) 2-corner face
/// now closes EXHAUSTIVELY at BOTH corners — the declaration arm
/// at [`Self::middle_band_variant`], the lex arm at THIS
/// projection. Together with the (set-level × `Option<Self>` ×
/// direction-composition × union × ordering) 2-corner face
/// ([`Self::extremal_variant`] + [`Self::sorted_extremal_variant`]),
/// the (set-level × `Option<Self>` × direction-composition ×
/// combinator × ordering) 3×2 grid now closes at FOUR of its SIX
/// tiles at the two ordering columns of both the union arm and
/// the complement arm — the intersection arm remains open (natural
/// next lifts `bimodal_variant(items) -> Option<Self>` +
/// `sorted_bimodal_variant(items) -> Option<Self>` via the flat-
/// diagonal predicate `c == max && c == min`).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary LEX-
/// ORDER direction-composition complement first-witness becomes a
/// TYPE-level primitive on the closed-set trait. THEORY.md §V.1 —
/// knowable platform; naming the (set-level × `Option<Self>` ×
/// direction-composition × complement × lex) corner on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::sorted_variants`] projection composed with the max/
/// min-fold pair under the strict-interior conjunction. THEORY.md
/// §VI.1 — generation over composition; the projection emerges
/// from the same three substrate primitives as the declaration-
/// order complement sibling under a substitution of the walk
/// surface — no per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `find (fun v => negb (Nat.eqb
/// (count_occ eqb l v) (max_count l)) && negb (Nat.eqb (count_occ
/// eqb l v) (min_count l))) (sort String_as_OT.le T)` idiom
/// composing a first-witness projection with a strict-interior
/// extremal predicate over a lex-sorted carrier; Racket's `(findf
/// (λ (v) (and (not (= c max)) (not (= c min)))) (sort all
/// string<? #:key symbol->string))`; Haskell's `find (\v -> c v /=
/// max && c v /= min) (sortBy (comparing label) all)`; Python's
/// `next((v for v in sorted(T, key=str) if min_c < items.count(v)
/// < max_c), None)`. Translation through pleme-io primitives: the
/// LEX-ORDER OPTION-return direction-composition complement first-
/// witness on the closed-set trait binds through
/// [`Self::sorted_variants`] (an ASCII-`sort_unstable_by_key`
/// projection replacing the standard-library `Ord`/`String`
/// carrier bound) + the max/min-fold pair + one lex-order `find`
/// under the strict-interior conjunction — no new dep, no
/// supertrait bound (`Sized + Copy + 'static` stays untouched),
/// no allocation beyond the [`Self::sorted_variants`] Vec-return
/// itself, no histogram-carrier allocation, short-circuits at the
/// first middle-band witness.
fn sorted_middle_band_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() {
return None;
}
let max = <Self as ClosedSet>::max_variant_count(items);
let min = <Self as ClosedSet>::min_variant_count(items);
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| {
let c = <Self as ClosedSet>::count_occurrences_of(v, items);
c != max && c != min
})
}
/// The N-ARY ORDERING-AGNOSTIC "bimodal variant" projection — the
/// `Option<Self>` DECLARATION-ORDER-FIRST-WITNESS over the
/// [`Self::variant_counts`] histogram under the DIRECTION-
/// COMPOSITION INTERSECTION predicate, reporting the FIRST variant
/// of [`Self::ALL`] (walked in declaration order) whose per-target
/// count equals BOTH [`Self::max_variant_count`] AND
/// [`Self::min_variant_count`] simultaneously (equivalently, whose
/// count sits at the flat-diagonal collapse where `max == min`), or
/// `None` when `items` is empty OR the histogram is non-flat
/// (`max != min` pins a strict direction split, so NO variant hits
/// both extremes). The DECLARATION-ORDER opener on the (set-level
/// × `Option<Self>` × direction-composition × intersection ×
/// ordering) 2-corner face, OPENING the intersection arm of the
/// (set-level × `Option<Self>` × direction-composition × ordering)
/// row past the union arm the ([`Self::extremal_variant`],
/// [`Self::sorted_extremal_variant`]) pair closed one COMBINATOR
/// axis over AND past the complement arm the
/// ([`Self::middle_band_variant`], [`Self::sorted_middle_band_variant`])
/// pair closed one COMBINATOR axis over via the flat-diagonal
/// predicate `c == max && c == min` (equivalently `max == min`,
/// the uniformity-collapse identity). Not a fresh substrate
/// primitive on the index axis — the projection emerges from the
/// SAME uniformity-collapse SHARPENING as
/// [`Self::bimodal_variants`] (`if items.is_empty() ||
/// !T::is_uniform(items) { None } else { T::ALL.first().copied() }`)
/// with `.first().copied()` in place of `.to_vec()` on the uniform
/// arm — the `Option<Self>` first-witness projection surfaces
/// ONLY in the truncation from the full witness collection to its
/// declaration-order head.
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::bimodal_variant(items) == Some(T::first())` iff `items` is
/// NON-EMPTY AND [`Self::is_uniform`] holds (max == min), else
/// `None`. On non-empty uniform slices every variant sits at BOTH
/// extremes simultaneously via the flat-histogram collapse and
/// the intersection filter matches every variant — the
/// declaration-order first-witness lands on [`Self::first`]; on
/// every other slice (non-uniform non-empty AND empty) the
/// intersection filter matches NO variant — either because
/// max != min pins a strict direction split (no variant hits both
/// extremes) or because the empty guard short-circuits past the
/// vacuous (max == min == 0) flat-histogram collapse. Pinned by
/// `bimodal_variant_returns_some_first_iff_slice_is_non_empty_and_uniform_across_every_triple`.
///
/// Composition-equality contract: for every slice `items`,
/// `T::bimodal_variant(items) ==
/// T::bimodal_variants(items).first().copied()` — the singular
/// OPTION-return direction-composition intersection first-witness
/// AGREES with the FIRST element of the plural VEC-return
/// direction-composition intersection witness-collection
/// [`Self::bimodal_variants`] returns. Pinned by
/// `bimodal_variant_equals_first_of_bimodal_variants_across_every_triple`.
///
/// Is-some-composition contract: for every slice `items`,
/// `T::bimodal_variant(items).is_some() ==
/// T::has_bimodal_variant(items)` — the OPTION-return intersection
/// first-witness is Some iff the BOOL-return existential predicate
/// holds. Sibling posture to
/// `middle_band_variant_is_some_iff_has_middle_band_variant_across_every_triple`
/// one COMBINATOR axis over: BOTH the declaration-order complement
/// and declaration-order intersection first-witness projections
/// agree with the ORDERING-AGNOSTIC existential predicate on the
/// same (Some, None) partition. Pinned by
/// `bimodal_variant_is_some_iff_has_bimodal_variant_across_every_triple`.
///
/// Empty-slice contract: `T::bimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty guard is LOAD-BEARING past the
/// vacuous (max == min == 0) flat-histogram collapse of
/// [`Self::is_uniform`] where an unguarded branch would silently
/// return `Some(T::first())` (every variant satisfies `count ==
/// max == min == 0` vacuously — the WRONG structural answer).
/// The guard makes the empty-slice answer a TYPED CONSEQUENCE of
/// the non-emptiness precondition [`Self::is_bimodal_variant_of`]
/// carries at every target rather than an accidental collision
/// with the intersection filter arm on the degenerate empty
/// histogram. Sibling posture to [`Self::bimodal_variants`]'s
/// empty-slice guard one RETURN-SHAPE axis over. Pinned by clause
/// (160) and by
/// `bimodal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::bimodal_variant(&[target]) == None` for every variant
/// `target` — the sole position hits `target` at count `1 == max`
/// while every non-target variant sits at count `0 == min`, so
/// the histogram is non-flat (max `1` != min `0`),
/// [`Self::is_uniform`] reports `false`, and the dichotomy lands
/// on `None`. LOAD-BEARING None-arm DISCRIMINATING this
/// INTERSECTION projection from [`Self::extremal_variant`] (which
/// reports `Some(T::first())` on the same fixture via the (max ∨
/// min) union covering every variant through one of the two
/// arms). Pinned by clause (160) and by
/// `bimodal_variant_returns_none_on_every_matching_singleton_across_every_variant`.
///
/// Full-set contract: `T::bimodal_variant(<T as ClosedSet>::ALL) ==
/// Some(T::first())` UNCONDITIONALLY — clause (3)'s pairwise-
/// distinctness invariant pins every variant of [`Self::ALL`] at
/// exactly one position on the full-set slice, every per-variant
/// count is `1`, [`Self::max_variant_count`] ==
/// [`Self::min_variant_count`] == `1`, [`Self::is_uniform`]
/// reports `true`, every variant sits at BOTH extremes
/// simultaneously via the (max == min == 1) collapse, and the
/// declaration-order first-witness lands on [`Self::first`]
/// immediately. LOAD-BEARING flat-histogram Some-arm
/// DISCRIMINATING this INTERSECTION projection from
/// [`Self::middle_band_variant`] (which lands on `None` on the
/// same fixture — the flat-histogram collapse pins the middle
/// band as empty while pinning the intersection band as full).
/// Pinned by clause (160) and by
/// `bimodal_variant_returns_some_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::bimodal_variant(&doubled_full_set) == Some(T::first())`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// EXACTLY two positions, every per-variant count is `2 == max ==
/// min`, [`Self::is_uniform`] reports `true`, every variant sits
/// at BOTH extremes via the second flat-histogram fixpoint, and
/// the declaration-order first-witness lands on [`Self::first`]
/// immediately. Pinned by clause (160) and by
/// `bimodal_variant_returns_some_first_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract:
/// `T::bimodal_variant(&[T::ALL[0], T::ALL[0], T::ALL[1]]) == None`
/// at cardinality `>= 3` — the bimodal triple hits T::ALL[0] at
/// count `2 == max`, T::ALL[1] at count `1` (MIDDLE-band),
/// T::ALL[2] at count `0 == min`; the histogram is non-flat
/// (max `2` != min `0`), [`Self::is_uniform`] reports `false`,
/// and the dichotomy lands on `None`. LOAD-BEARING None-arm on
/// the SAME canonical fixture where [`Self::middle_band_variant`]
/// reports `Some(T::ALL[1])` and [`Self::extremal_variant`]
/// reports `Some(T::ALL[0])` — the three projections split the
/// modal-aggregation matrix into its three direction-composition
/// arms on the ONE canonical non-flat triple. Pinned by
/// `bimodal_variant_returns_none_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Direction-composition intersection identity: for every slice
/// `items`, whenever `T::bimodal_variant(items) == Some(v)`,
/// [`Self::is_bimodal_variant_of`]`(v, items)` holds — the
/// reported witness sits at BOTH the argmax and argmin bands
/// simultaneously (equivalently, both
/// [`Self::is_modal_variant_of`] AND
/// [`Self::is_antimodal_variant_of`] hold on it). Pinned by
/// `bimodal_variant_when_some_lands_on_flat_diagonal_across_every_triple`.
///
/// Union-inclusion identity: for every slice `items`, whenever
/// `T::bimodal_variant(items) == Some(v)`,
/// [`Self::is_extremal_variant_of`]`(v, items)` holds — every
/// variant sitting at BOTH extremes trivially sits at AT LEAST
/// ONE extreme, so the intersection first-witness injects into
/// the union band by construction. Pinned by
/// `bimodal_variant_when_some_is_extremal_across_every_triple`.
///
/// Middle-band-disjointness identity: for every slice `items`,
/// whenever `T::bimodal_variant(items) == Some(v)`,
/// [`Self::is_middle_band_variant_of`]`(v, items)` is `false` —
/// the (intersection / middle) partition of the closed set on
/// non-empty slices is DISJOINT by construction, so the
/// declaration-order intersection first-witness NEVER sits in
/// the strict interior. Pinned by
/// `bimodal_variant_when_some_is_not_middle_band_across_every_triple`.
///
/// Reversal-invariance: the projection factors through the
/// ordering-agnostic [`Self::is_uniform`] predicate + a
/// declaration-order pick of [`Self::first`] (which does NOT
/// depend on `items`); permuting `items` preserves its variant
/// multiset, so the projection is a function of that multiset
/// alone. Pinned by
/// `bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection composes ONE `is_empty()` guard
/// with one [`Self::is_uniform`] call and one
/// `T::ALL.first().copied()` pick — no
/// `PartialEq`/`Eq`/`Hash`/`Ord` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); short-circuits at the uniformity dichotomy without
/// materializing the histogram twice or walking [`Self::ALL`].
///
/// Future consumers that compose against
/// [`Self::bimodal_variant`]: a `tatara-check` predicate
/// `(check-first-bimodal-target …)` that surfaces the ONE
/// canonical name for a rollout histogram window whose
/// distribution is FLAT (every phase equally represented) — the
/// human-facing "is this window bimodal, and if so which is the
/// declaration-order first variant?" answer per window; an LSP
/// diagnostic that highlights the declaration-order first
/// bimodal witness in a Lisp-author-written closed-set field
/// under the canonical presentation order of
/// `#[derive(TataraDomain)]` variants; a Sekiban audit-trail
/// gauge that names the declaration-order first bimodal
/// inhabitant for dashboards summarizing flat distributions.
/// Each binds to ONE typed `Option<Self>`-return call rather than
/// re-deriving the `T::ALL.iter().copied().find(|&v| c == max &&
/// c == min)` composition per callsite.
///
/// Compounding closure: the (set-level × `Option<Self>` ×
/// direction-composition × intersection × ordering) 2-corner face
/// now OPENS at its DECLARATION arm at THIS projection. Together
/// with the (set-level × `Option<Self>` × direction-composition ×
/// union × ordering) 2-corner face ([`Self::extremal_variant`] +
/// [`Self::sorted_extremal_variant`]) and the (set-level ×
/// `Option<Self>` × direction-composition × complement × ordering)
/// 2-corner face ([`Self::middle_band_variant`] +
/// [`Self::sorted_middle_band_variant`]), the (set-level ×
/// `Option<Self>` × direction-composition × combinator × ordering)
/// 3×2 grid now closes at FIVE of its SIX tiles — the intersection
/// LEX arm (`sorted_bimodal_variant`) remains as the natural next
/// lift closing the intersection ordering face.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// direction-composition intersection first-witness becomes a
/// TYPE-level primitive on the closed-set trait. THEORY.md §V.1 —
/// knowable platform; naming the (set-level × `Option<Self>` ×
/// direction-composition × intersection × declaration) corner on
/// the trait makes the projection a TYPED CONSEQUENCE of the
/// substrate's [`Self::is_uniform`] predicate composed with
/// [`Self::first`]. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the same TWO substrate primitives
/// as the plural sibling under a truncation of the returned
/// collection to its declaration-order head — no per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Coq's `if uniform_dec l then Some (head
/// T) else None` composing a decidable uniformity predicate with
/// a declaration-order first-witness; Racket's `(if (uniform?
/// items) (car T) #f)`; Haskell's `if isUniform items then Just
/// (head all) else Nothing`; Python's `next(iter(T), None) if
/// items and max_c == min_c else None`. Translation through
/// pleme-io primitives: the DECLARATION-ORDER OPTION-return
/// direction-composition intersection first-witness on the
/// closed-set trait binds through [`Self::is_uniform`] +
/// [`Self::first`] (an `ALL.first().copied()` projection with no
/// standard-library `Iterator` idiom to lean on) — no new dep, no
/// supertrait bound (`Sized + Copy + 'static` stays untouched),
/// no allocation beyond the pick itself, short-circuits at the
/// uniformity dichotomy.
fn bimodal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() || !<Self as ClosedSet>::is_uniform(items) {
None
} else {
<Self as ClosedSet>::ALL.first().copied()
}
}
/// The N-ARY LEX-ORDER "bimodal variant" projection — the
/// `Option<Self>` LEX-ORDER-FIRST-WITNESS over the
/// [`Self::variant_counts`] histogram under the DIRECTION-
/// COMPOSITION INTERSECTION predicate, reporting the FIRST variant
/// of [`Self::sorted_variants`] (walked in ASCII-lex order over
/// [`Self::label`]) whose per-target count equals BOTH
/// [`Self::max_variant_count`] AND [`Self::min_variant_count`]
/// simultaneously (equivalently, whose count sits at the flat-
/// diagonal collapse where `max == min`), or `None` when `items`
/// is empty OR the histogram is non-flat (`max != min` pins a
/// strict direction split, so NO variant hits both extremes). The
/// LEX-ORDER peer of [`Self::bimodal_variant`] one ORDERING axis
/// over, CLOSING the (set-level × `Option<Self>` × statistical-
/// aggregate × direction-composition × intersection × ordering)
/// 2-corner face at its lex-arm past the declaration-arm the
/// sibling [`Self::bimodal_variant`] opened AND CLOSING the (set-
/// level × `Option<Self>` × direction-composition × combinator ×
/// ordering) 3×2 grid at its FINAL sixth tile past the (union
/// declaration, union lex, complement declaration, complement lex,
/// intersection declaration) 5-tile prefix the sibling projections
/// ([`Self::extremal_variant`], [`Self::sorted_extremal_variant`],
/// [`Self::middle_band_variant`], [`Self::sorted_middle_band_variant`],
/// [`Self::bimodal_variant`]) covered. Not a fresh substrate
/// primitive on the index axis — the projection emerges from the
/// SAME uniformity-collapse SHARPENING as [`Self::bimodal_variant`]
/// (`if items.is_empty() || !T::is_uniform(items) { None } else {
/// T::sorted_variants().first().copied() }`) with
/// `T::sorted_variants().first().copied()` in place of
/// `T::ALL.first().copied()` on the uniform arm — the lex axis
/// surfaces ONLY in the returned first-witness pick.
///
/// Uniformity-collapse identity: for every slice `items`,
/// `T::sorted_bimodal_variant(items) == Some(T::sorted_first())`
/// iff `items` is NON-EMPTY AND [`Self::is_uniform`] holds (max ==
/// min), else `None`. On non-empty uniform slices every variant
/// sits at BOTH extremes simultaneously via the flat-histogram
/// collapse and the intersection filter matches every variant —
/// the lex-order first-witness lands on [`Self::sorted_first`]; on
/// every other slice (non-uniform non-empty AND empty) the
/// intersection filter matches NO variant — either because
/// max != min pins a strict direction split (no variant hits both
/// extremes) or because the empty guard short-circuits past the
/// vacuous (max == min == 0) flat-histogram collapse. Pinned by
/// `sorted_bimodal_variant_returns_some_sorted_first_iff_slice_is_non_empty_and_uniform_across_every_triple`.
///
/// Composition-equality contract: for every slice `items`,
/// `T::sorted_bimodal_variant(items) ==
/// T::sorted_bimodal_variants(items).first().copied()` — the
/// singular OPTION-return LEX-order direction-composition
/// intersection first-witness AGREES with the FIRST element of the
/// plural VEC-return LEX-order direction-composition intersection
/// witness-collection [`Self::sorted_bimodal_variants`] returns.
/// Pinned by
/// `sorted_bimodal_variant_equals_first_of_sorted_bimodal_variants_across_every_triple`.
///
/// Is-some-composition contract: for every slice `items`,
/// `T::sorted_bimodal_variant(items).is_some() ==
/// T::has_bimodal_variant(items)` — the OPTION-return LEX-order
/// intersection first-witness is Some iff the BOOL-return
/// existential predicate (which is ordering-agnostic) holds.
/// Sibling posture to
/// `sorted_middle_band_variant_is_some_iff_has_middle_band_variant_across_every_triple`
/// one COMBINATOR axis over: BOTH the lex-order complement and
/// lex-order intersection first-witness projections agree with the
/// ORDERING-AGNOSTIC existential predicate on the same (Some,
/// None) partition. Pinned by
/// `sorted_bimodal_variant_is_some_iff_has_bimodal_variant_across_every_triple`.
///
/// Sibling-composition identity: for every slice `items`,
/// `T::sorted_bimodal_variant(items).is_some() ==
/// T::bimodal_variant(items).is_some()` — the (Some, None)
/// partition of the LEX-order intersection first-witness AGREES
/// with the (Some, None) partition of the declaration-order
/// intersection first-witness on every slice. The two projections
/// may disagree on the VALUE they report inside the Some arm on
/// any slice whose uniform histogram lets a (T::first() !=
/// T::sorted_first())-divergent split, but they AGREE on WHEN the
/// Some arm fires (both gate through the SAME uniformity dichotomy
/// via [`Self::is_uniform`]). Pinned by
/// `sorted_bimodal_variant_is_some_iff_bimodal_variant_is_some_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_bimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty guard is LOAD-BEARING past the
/// vacuous (max == min == 0) flat-histogram collapse of
/// [`Self::is_uniform`] where an unguarded branch would silently
/// return `Some(T::sorted_first())` (every variant satisfies
/// `count == max == min == 0` vacuously — the WRONG structural
/// answer). The guard makes the empty-slice answer a TYPED
/// CONSEQUENCE of the non-emptiness precondition
/// [`Self::is_bimodal_variant_of`] carries at every target rather
/// than an accidental collision with the intersection filter arm
/// on the degenerate empty histogram. Sibling posture to
/// [`Self::bimodal_variant`]'s empty-slice guard one ORDERING axis
/// over. Pinned by clause (161) and by
/// `sorted_bimodal_variant_returns_none_on_the_empty_slice_across_every_kind`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_bimodal_variant(&[target]) == None` for every
/// variant `target` — the sole position hits `target` at count
/// `1 == max` while every non-target variant sits at count `0 ==
/// min`, so the histogram is non-flat (max `1` != min `0`),
/// [`Self::is_uniform`] reports `false`, and the dichotomy lands
/// on `None`. LOAD-BEARING None-arm DISCRIMINATING this LEX-order
/// INTERSECTION projection from [`Self::sorted_extremal_variant`]
/// (which reports `Some(T::sorted_first())` on the same fixture
/// via the (max ∨ min) union covering every variant through one
/// of the two arms). Pinned by clause (161) and by
/// `sorted_bimodal_variant_returns_none_on_every_matching_singleton_across_every_variant`.
///
/// Full-set contract: `T::sorted_bimodal_variant(<T as
/// ClosedSet>::ALL) == Some(T::sorted_first())` UNCONDITIONALLY —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// of [`Self::ALL`] at exactly one position on the full-set slice,
/// every per-variant count is `1`, [`Self::max_variant_count`] ==
/// [`Self::min_variant_count`] == `1`, [`Self::is_uniform`]
/// reports `true`, every variant sits at BOTH extremes
/// simultaneously via the (max == min == 1) collapse, and the
/// lex-order first-witness lands on [`Self::sorted_first`]
/// immediately. LOAD-BEARING flat-histogram Some-arm
/// DISCRIMINATING this LEX-order INTERSECTION projection from
/// [`Self::sorted_middle_band_variant`] (which lands on `None` on
/// the same fixture — the flat-histogram collapse pins the middle
/// band as empty while pinning the intersection band as full).
/// Pinned by clause (161) and by
/// `sorted_bimodal_variant_returns_some_sorted_first_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_bimodal_variant(&doubled_full_set) ==
/// Some(T::sorted_first())` UNCONDITIONALLY — the doubled full set
/// hits every variant at EXACTLY two positions, every per-variant
/// count is `2 == max == min`, [`Self::is_uniform`] reports
/// `true`, every variant sits at BOTH extremes via the second
/// flat-histogram fixpoint, and the lex-order first-witness lands
/// on [`Self::sorted_first`] immediately. Pinned by clause (161)
/// and by
/// `sorted_bimodal_variant_returns_some_sorted_first_on_the_doubled_full_set_across_every_kind`.
///
/// Bimodal-triple contract:
/// `T::sorted_bimodal_variant(&[T::ALL[0], T::ALL[0], T::ALL[1]])
/// == None` at cardinality `>= 3` — the bimodal triple hits
/// T::ALL[0] at count `2 == max`, T::ALL[1] at count `1` (MIDDLE-
/// band), T::ALL[2] at count `0 == min`; the histogram is non-flat
/// (max `2` != min `0`), [`Self::is_uniform`] reports `false`, and
/// the dichotomy lands on `None`. LOAD-BEARING None-arm on the
/// SAME canonical fixture where [`Self::sorted_middle_band_variant`]
/// reports `Some(T::sorted_variants()[1])` and
/// [`Self::sorted_extremal_variant`] reports
/// `Some(T::sorted_first())` — the three lex-order projections
/// split the modal-aggregation matrix into its three direction-
/// composition arms on the ONE canonical non-flat triple, mirroring
/// the declaration-order trichotomy one ORDERING axis over. Pinned
/// by
/// `sorted_bimodal_variant_returns_none_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Direction-composition intersection identity: for every slice
/// `items`, whenever `T::sorted_bimodal_variant(items) == Some(v)`,
/// [`Self::is_bimodal_variant_of`]`(v, items)` holds — the
/// reported witness sits at BOTH the argmax and argmin bands
/// simultaneously (equivalently, both
/// [`Self::is_modal_variant_of`] AND
/// [`Self::is_antimodal_variant_of`] hold on it). Pinned by
/// `sorted_bimodal_variant_when_some_lands_on_flat_diagonal_across_every_triple`.
///
/// Union-inclusion identity: for every slice `items`, whenever
/// `T::sorted_bimodal_variant(items) == Some(v)`,
/// [`Self::is_extremal_variant_of`]`(v, items)` holds — every
/// variant sitting at BOTH extremes trivially sits at AT LEAST ONE
/// extreme, so the lex-order intersection first-witness injects
/// into the union band by construction. Pinned by
/// `sorted_bimodal_variant_when_some_is_extremal_across_every_triple`.
///
/// Middle-band-disjointness identity: for every slice `items`,
/// whenever `T::sorted_bimodal_variant(items) == Some(v)`,
/// [`Self::is_middle_band_variant_of`]`(v, items)` is `false` —
/// the (intersection / middle) partition of the closed set on
/// non-empty slices is DISJOINT by construction, so the lex-order
/// intersection first-witness NEVER sits in the strict interior.
/// Pinned by
/// `sorted_bimodal_variant_when_some_is_not_middle_band_across_every_triple`.
///
/// Reversal-invariance: the projection factors through the
/// ordering-agnostic [`Self::is_uniform`] predicate + a lex-order
/// pick of [`Self::sorted_first`] (which does NOT depend on
/// `items`); permuting `items` preserves its variant multiset, so
/// the projection is a function of that multiset alone. Pinned by
/// `sorted_bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection composes ONE `is_empty()` guard
/// with one [`Self::is_uniform`] call and one
/// `T::sorted_variants().first().copied()` pick (the lex-sort
/// runs only on the uniform non-empty arm) — no
/// `PartialEq`/`Eq`/`Hash`/`Ord` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); short-circuits at the uniformity dichotomy without
/// materializing the histogram twice or walking [`Self::ALL`]
/// beyond the internal sort step. Cost is `O(T::CARDINALITY * n +
/// T::CARDINALITY log T::CARDINALITY)` on slice arity `n` — the
/// [`Self::is_uniform`] max/min-fold pair on `n` + the
/// [`Self::sorted_variants`] canonical-lex-sort step on the
/// uniform arm only — strictly beats the naive
/// `T::sorted_variants().into_iter().find(|&v| c == max && c ==
/// min)` sweep which pays the sort cost unconditionally.
///
/// Future consumers that compose against
/// [`Self::sorted_bimodal_variant`]: a `tatara-check` predicate
/// `(check-first-bimodal-target-lex …)` that surfaces the ONE
/// canonical LEX-order name for a rollout histogram window whose
/// distribution is FLAT (every phase equally represented) — the
/// human-facing "is this window bimodal, and if so which is the
/// ASCII-alphabetic FIRST variant?" answer per window, aligned with
/// dashboard consumers that route through lex-ordered enumeration
/// surfaces (distinct from [`Self::bimodal_variant`]'s declaration-
/// order-canonical form consumed by scheduler-oriented tools that
/// route through declaration slots); an LSP diagnostic that
/// highlights the ASCII-lex FIRST bimodal witness in a Lisp-author-
/// written closed-set field under the canonical alphabetic display
/// order aligned with the language server's outline view; a Sekiban
/// audit-trail gauge that names the LEX-order first bimodal
/// inhabitant for dashboards summarizing flat distributions in
/// alphabetic order. Each binds to ONE typed `Option<Self>`-return
/// call rather than re-deriving the `T::sorted_variants().first().
/// copied()` gated by `!items.is_empty() && T::is_uniform(items)`
/// composition per callsite.
///
/// Compounding closure: this projection CLOSES the (set-level ×
/// `Option<Self>` × direction-composition × intersection ×
/// ordering) 2-corner face at its lex-arm past the declaration-arm
/// [`Self::bimodal_variant`] opened AND CLOSES the (set-level ×
/// `Option<Self>` × direction-composition × combinator × ordering)
/// 3×2 grid at its FINAL sixth tile — the (union declaration, union
/// lex, complement declaration, complement lex, intersection
/// declaration, intersection lex) 6-tile matrix is now
/// EXHAUSTIVELY closed. Combined with the sibling
/// ([`Self::modal_variant`], [`Self::sorted_modal_variant`],
/// [`Self::antimodal_variant`], [`Self::sorted_antimodal_variant`])
/// direction-anchor pairs, the (set-level × `Option<Self>` ×
/// statistical-aggregate × direction-composition × ordering) 5×2
/// first-witness grid on the modal-aggregation matrix now closes at
/// EVERY direction-composition inhabitant across BOTH ordering
/// arms — the argmax pair, argmin pair, union pair, complement
/// pair, AND intersection pair are all pinned at BOTH walk orders
/// at the singular first-witness return-shape, exactly mirroring
/// the plural `Vec<Self>` grid closed one RETURN-SHAPE axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order direction-composition intersection first-witness becomes a
/// TYPE-level primitive on the closed-set trait. THEORY.md §V.1 —
/// knowable platform; naming the (set-level × `Option<Self>` ×
/// direction-composition × intersection × lex) corner on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// [`Self::is_uniform`] predicate composed with
/// [`Self::sorted_first`]. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the same TWO substrate
/// primitives as the plural sibling under a truncation of the
/// returned collection to its lex-order head — no per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Coq's `if uniform_dec l then Some (head
/// (sort label_le T)) else None` composing a decidable uniformity
/// predicate with an ASCII-lex first-witness projection; Racket's
/// `(if (uniform? items) (car (sort T string<? #:key label)) #f)`;
/// Haskell's `if isUniform items then Just (head (sortOn label
/// all)) else Nothing`; Python's `next(iter(sorted(T, key=label)),
/// None) if items and max_c == min_c else None`. Translation
/// through pleme-io primitives: the LEX-ORDER OPTION-return
/// direction-composition intersection first-witness on the closed-
/// set trait binds through [`Self::is_uniform`] +
/// [`Self::sorted_first`] (a `sorted_variants().first().copied()`
/// projection with no standard-library `Iterator` idiom to lean on)
/// — no new dep, no supertrait bound (`Sized + Copy + 'static`
/// stays untouched), no allocation beyond the pick + the internal
/// sort itself, short-circuits at the uniformity dichotomy.
fn sorted_bimodal_variant(items: &[Self]) -> Option<Self> {
if items.is_empty() || !<Self as ClosedSet>::is_uniform(items) {
None
} else {
<Self as ClosedSet>::sorted_variants().first().copied()
}
}
/// The N-ARY ORDERING-AGNOSTIC "does the STRICT-INTERIOR band fall on
/// a UNIQUE variant?" set-level predicate — `true` iff EXACTLY ONE
/// variant of [`Self::ALL`] carries an occurrence-count STRICTLY
/// between [`Self::min_variant_count`] and
/// [`Self::max_variant_count`], computed as the strict-equality test
/// of the just-lifted [`Self::count_middle_band_variants`]
/// cardinality-count aggregate against the scalar threshold `1`. The
/// BOOL-RETURN UNIQUE-TIE SHARPENING OPENER on the (set-level × bool
/// × statistical-aggregate × direction-composition × complement ×
/// unique-tie) corner OPENING the (set-level × bool × direction-
/// composition × unique-tie) column past the direction-anchored
/// (`has_unique_mode`, `has_unique_antimode`) argmax/argmin pair one
/// DIRECTION-COMPOSITION axis over on the modal-aggregation matrix
/// AND peer to [`Self::count_middle_band_variants`] one RETURN-SHAPE
/// axis over (set-level × `usize` cardinality → set-level × `bool`
/// uniqueness test against `1`) AND peer to
/// [`Self::has_middle_band_variant`] one UNIQUE-TIE-SHARPENING axis
/// over (existential `>= 1` → uniqueness `== 1`). Not a fresh
/// substrate primitive on the index axis — the predicate emerges
/// from one strict-equality test of the just-lifted
/// [`Self::count_middle_band_variants`] scalar against `1`,
/// equivalently the [`Vec::len`] equality of the declaration-order
/// middle-band witness-collection [`Self::middle_band_variants`]
/// against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_middle_band_variant(items) ==
/// (T::count_middle_band_variants(items) == 1)` — the set-level
/// bool predicate is EXACTLY the strict-equality test of the just-
/// lifted set-level cardinality-count aggregate against the scalar
/// threshold `1`. The canonical form the body uses. Pinned by
/// `has_unique_middle_band_variant_equals_count_middle_band_variants_eq_one_across_every_triple`.
///
/// Middle-band witness length identity: for every slice `items`,
/// `T::has_unique_middle_band_variant(items) ==
/// (T::middle_band_variants(items).len() == 1)` — the set-level
/// bool predicate is EXACTLY the length-equality test of the
/// declaration-order complement witness-collection against `1`.
/// Independent cross-check distinct from the count-composition arm
/// on the surface axis (Vec-length vs scalar equality). Pinned by
/// `has_unique_middle_band_variant_agrees_with_middle_band_variants_len_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_middle_band_variant(items) ==>
/// T::has_middle_band_variant(items)` — a UNIQUE middle-band witness
/// trivially entails the EXISTENCE of a middle-band witness (the
/// unique-tie sharpening `count == 1` implies the existential
/// `count >= 1`). The converse fails at the bimodal-triple fixture
/// at cardinality `>= 4` where the histogram carries multiple non-
/// extreme variants tied at count `0` in the middle band (no such
/// tie exists at cardinality `3` where the sole middle-band witness
/// is T::ALL[1]). Pinned by
/// `has_unique_middle_band_variant_implies_has_middle_band_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_middle_band_variants`] (ordering-agnostic) via a
/// scalar equality test against a fixed constant. No separate
/// `sorted_has_unique_middle_band_variant` peer is needed. Pinned by
/// `has_unique_middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_middle_band_variant(&[])`
/// is `false` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_middle_band_variants`] collapses to `0` at its
/// empty-slice guard, and `0 != 1`. The `false`-at-empty fixpoint
/// pins middle-band uniqueness as a NON-EMPTINESS-REQUIRING
/// property.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_unique_middle_band_variant(&[v])` is `false` for every
/// variant `v` — the sole position hits `v` at count `1 == max`
/// while every non-target variant sits at count `0 == min`; the
/// two-value dichotomy has NO strictly-interior band,
/// [`Self::count_middle_band_variants`] reports `0`, and `0 != 1`.
///
/// Full-set + doubled-full-set contract: on the flat-histogram
/// fixpoint every variant sits at BOTH extremes simultaneously via
/// the (max == min) collapse; no variant falls in the strict
/// interior, so [`Self::count_middle_band_variants`] reports `0`
/// and `0 != 1`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax
/// is `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]` (count
/// `0`), and the sole middle-band witness is T::ALL[1] at count
/// `1` (strictly between `0` and `2`);
/// [`Self::count_middle_band_variants`] reports `1` and `1 == 1`.
/// LOAD-BEARING `true`-arm catch DISCRIMINATING this uniqueness
/// corner from the direction-composition unique-tie peers on the
/// column — the SOLE canonical fixpoint witness the (direction-
/// composition × unique-tie × complement) corner has a `true` arm
/// at cardinality `3`, which the direction-anchored peers
/// [`Self::has_unique_mode`] / [`Self::has_unique_antimode`] miss
/// on the same fixture (the argmax hits a unique T::ALL[0] but
/// SHARES with THIS complement corner via the direction-composition
/// axis; the argmin ties `T::ALL[2..]` at count `0` and reports
/// `false` at cardinality `>= 4`).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_middle_band_variants`] via one scalar equality
/// test on `usize`. The sweep cost inherits the middle-band count
/// aggregate: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] + [`Self::min_variant_count`] fold
/// pair + one `T::CARDINALITY - count_extremal` arithmetic),
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched).
///
/// Future consumers that compose against
/// [`Self::has_unique_middle_band_variant`]: a `tatara-check`
/// predicate `(check-middle-band-is-unique …)` that reports "the
/// sole strict-interior variant is unambiguous" in ONE typed bool
/// rather than a Vec-length or count-and-compare composition; a
/// Sekiban audit-trail bit `middle_band_uniqueness_bit(items)`
/// binding to the same scalar, composable with the future
/// `unique_middle_band_variant -> Option<Self>` witness-if-unique
/// projection into a typed `(unique-middle-band-bit, unique-middle-
/// band-witness)` classifier per window; an LSP hint that surfaces
/// "this Lisp-authored histogram has a UNIQUE middle-band variant"
/// on a Lisp-authored variant-list without allocating the middle-
/// band witness-Vec.
///
/// Compounding closure: this projection OPENS the (set-level × bool
/// × statistical-aggregate × direction-composition × complement ×
/// unique-tie) corner on the modal-aggregation matrix, sharpening
/// the just-lifted [`Self::count_middle_band_variants`] cardinality-
/// count scalar past the `1` threshold peer to
/// [`Self::has_unique_mode`] + [`Self::has_unique_antimode`] one
/// DIRECTION-COMPOSITION axis over on the (direction-composition ×
/// unique-tie) row. The natural next lifts past this corner are the
/// two peer direction-composition arms — `has_unique_extremal_variant(items) ==
/// (count_extremal_variants == 1)` (union arm, degenerate opener —
/// `false` at every cardinality `>= 2` past the empty slice via the
/// inclusion-exclusion `count_modal + count_antimodal - count_bimodal >= 2`
/// on non-flat and `== CARDINALITY` on flat) and
/// `has_unique_bimodal_variant(items) == (count_bimodal_variants == 1)`
/// (intersection arm, degenerate opener — `false` at every
/// cardinality `>= 2` past the empty slice via the flat-histogram
/// dichotomy pinning count_bimodal at `0` or `CARDINALITY`). Both
/// peers are TYPED CONSEQUENCES of the existing sibling cardinality-
/// count aggregates under the same `== 1` sharpening, closing the
/// (direction-composition × unique-tie × bool) 3-corner row on the
/// modal-aggregation matrix.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level middle-band uniqueness bool predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::count_middle_band_variants(items) == 1` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (set-level × bool × middle-band-uniqueness) corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "is the sole strict-interior witness unambiguous?"
/// site pre-lift. Naming it on the trait makes the predicate a
/// TYPED CONSEQUENCE of the substrate's just-lifted middle-band
/// count aggregate. THEORY.md §VI.1 — generation over composition;
/// the predicate emerges from the composition of ONE substrate
/// primitive ([`Self::count_middle_band_variants`]) with a scalar
/// equality against `1`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); m <- max(t); n <- min(t); sum(t > n & t < m) == 1 }`
/// — the middle-band uniqueness test on a factor histogram; Julia's
/// `count(v -> minimum(values(c)) < v < maximum(values(c)), values(c)) == 1`
/// on `c = StatsBase.countmap(items)`; Python's
/// `let c = collections.Counter(items); mx = max(c.values(), default=0); mn = min(c.values(), default=0); sum(1 for v in c.values() if mn < v < mx) == 1`;
/// Haskell's
/// `let hs = map length . group . sort $ items; m = maximum hs; n = minimum hs in length (filter (\c -> n < c && c < m) hs) == 1`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f))] (= 1 (count (filter #(and (> % n) (< % m)) (vals f)))))`;
/// SQL's
/// `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant) WHERE c > (SELECT MIN(c) …) AND c < (SELECT MAX(c) …)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// middle-band-uniqueness predicate on the closed-set trait binds
/// through the just-lifted [`Self::count_middle_band_variants`]
/// scalar against the constant `1` — no new dep, no supertrait
/// bound, no allocation, `O(T::CARDINALITY * n)` on slice arity `n`
/// inherited verbatim from the middle-band-count aggregate.
fn has_unique_middle_band_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_middle_band_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "does the EXTREMAL union band fall on
/// a UNIQUE variant?" set-level predicate — `true` iff EXACTLY ONE
/// variant of [`Self::ALL`] carries an occurrence-count MATCHING
/// EITHER [`Self::max_variant_count`] OR [`Self::min_variant_count`],
/// computed as the strict-equality test of the just-lifted
/// [`Self::count_extremal_variants`] cardinality-count aggregate
/// against the scalar threshold `1`. The BOOL-RETURN UNIQUE-TIE
/// SHARPENING corner CLOSING the (set-level × bool × direction-
/// composition × unique-tie) row past the just-opened
/// [`Self::has_unique_middle_band_variant`] complement arm one
/// COMBINATOR axis over on the modal-aggregation matrix AND peer to
/// [`Self::count_extremal_variants`] one RETURN-SHAPE axis over
/// (set-level × `usize` cardinality → set-level × `bool` uniqueness
/// test against `1`) AND peer to [`Self::has_extremal_variant`] one
/// UNIQUE-TIE-SHARPENING axis over (existential `>= 1` → uniqueness
/// `== 1`). Not a fresh substrate primitive on the index axis — the
/// predicate emerges from one strict-equality test of the just-lifted
/// [`Self::count_extremal_variants`] scalar against `1`, equivalently
/// the [`Vec::len`] equality of the declaration-order union witness-
/// collection [`Self::extremal_variants`] against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_extremal_variant(items) ==
/// (T::count_extremal_variants(items) == 1)` — the set-level bool
/// predicate is EXACTLY the strict-equality test of the just-lifted
/// set-level cardinality-count aggregate against the scalar threshold
/// `1`. The canonical form the body uses. Pinned by
/// `has_unique_extremal_variant_equals_count_extremal_variants_eq_one_across_every_triple`.
///
/// Extremal witness length identity: for every slice `items`,
/// `T::has_unique_extremal_variant(items) ==
/// (T::extremal_variants(items).len() == 1)` — the set-level bool
/// predicate is EXACTLY the length-equality test of the declaration-
/// order union witness-collection against `1`. Independent cross-
/// check distinct from the count-composition arm on the surface axis
/// (Vec-length vs scalar equality). Pinned by
/// `has_unique_extremal_variant_agrees_with_extremal_variants_len_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_extremal_variant(items) ==>
/// T::has_extremal_variant(items)` — a UNIQUE extremal witness
/// trivially entails the EXISTENCE of an extremal witness (the
/// unique-tie sharpening `count == 1` implies the existential
/// `count >= 1`). Pinned by
/// `has_unique_extremal_variant_implies_has_extremal_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_extremal_variants`] (ordering-agnostic) via a scalar
/// equality test against a fixed constant. No separate
/// `sorted_has_unique_extremal_variant` peer is needed. Pinned by
/// `has_unique_extremal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_extremal_variant(&[])` is
/// `false` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_extremal_variants`] collapses to `0` at its empty-
/// slice guard, and `0 != 1`.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::has_unique_extremal_variant(items)` is `false` on EVERY non-
/// empty slice on EVERY implementor with `T::CARDINALITY >= 2` — the
/// inclusion-exclusion identity `count_extremal_variants ==
/// count_modal + count_antimodal - count_bimodal` pins the union
/// cardinality at `T::CARDINALITY` on every flat-histogram fixpoint
/// (max == min collapses all three counts to `T::CARDINALITY`) and at
/// `>= 2` on every non-flat fixpoint (max != min splits the argmax
/// and argmin into two disjoint non-empty bands with empty
/// intersection, so the union carries at least one modal AND one
/// antimodal variant — count `>= 2`). The scalar equality against
/// `1` therefore fails everywhere past the empty slice at cardinality
/// `>= 2`. THIS corner is the DEGENERATE OPENER on the (set-level ×
/// bool × direction-composition × union × unique-tie) axis — the
/// SOLE positive arm sits at `T::CARDINALITY == 1` where a matching
/// singleton (= full-set) collapses the union to a single variant,
/// out of reach of the multi-variant test-module fixtures.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_unique_extremal_variant(&[v])` is `false` for every
/// variant `v` — the target hits count `1 == max`, every non-target
/// sits at count `0 == min`, the argmax band is `{v}` (size 1) and
/// the argmin band is `T::ALL \ {v}` (size `T::CARDINALITY - 1 >=
/// 1`), disjoint, so [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY >= 2`, and `T::CARDINALITY != 1`.
///
/// Full-set + doubled-full-set contract: on either flat-histogram
/// fixpoint every variant sits at BOTH extremes simultaneously via
/// the (max == min) collapse; the union covers all of [`Self::ALL`],
/// so [`Self::count_extremal_variants`] reports `T::CARDINALITY` and
/// `T::CARDINALITY != 1` on every implementor with cardinality `>=
/// 2`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is
/// `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]` (count
/// `0`), the union carries the two disjoint bands and
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY - 1 >=
/// 2`, and the equality against `1` fails. LOAD-BEARING `false`-arm
/// catch DISCRIMINATING this uniqueness corner from
/// [`Self::has_unique_middle_band_variant`]'s SOLE positive arm on
/// the same fixture — the union-arm degenerate opener and the
/// complement-arm strict-interior positive arm split the direction-
/// composition axis on the canonical bimodal fixture.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_extremal_variants`] via one scalar equality test on
/// `usize`. The sweep cost inherits the extremal count aggregate:
/// `O(T::CARDINALITY * n)` on slice arity `n`, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::has_unique_extremal_variant`]: a `tatara-check` predicate
/// `(check-extremal-is-unique …)` that reports "exactly one variant
/// sits at an extreme" as a one-typed-call answer (in practice, at
/// cardinality `>= 2`, a compile-time-known `false` predicate on
/// every non-empty slice — a substrate-level THEOREM the checker
/// can rely on rather than re-verify per slice); a Sekiban audit-
/// trail bit `extremal_uniqueness_bit(items)` that composes with a
/// future `unique_extremal_variant -> Option<Self>` witness-if-
/// unique projection into a typed classifier; an LSP hint on a
/// Lisp-authored variant-list that surfaces the degenerate
/// theorem's positive arm ONLY at CARDINALITY 1 sets.
///
/// Compounding closure: this projection CLOSES the (set-level × bool
/// × statistical-aggregate × direction-composition × union × unique-
/// tie) corner on the modal-aggregation matrix, sharpening the
/// just-lifted [`Self::count_extremal_variants`] cardinality-count
/// scalar past the `1` threshold peer to
/// [`Self::has_unique_middle_band_variant`] one COMBINATOR axis over
/// on the (direction-composition × unique-tie) row. The remaining
/// tile on the row is the intersection arm
/// `has_unique_bimodal_variant(items) == (count_bimodal_variants ==
/// 1)` — a peer degenerate opener with the same `false`-at-cardinality-
/// `>= 2` collapse via the two-value dichotomy `{0, T::CARDINALITY}`
/// on the intersection count.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level extremal-union uniqueness bool predicate becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-consumer
/// inline `T::count_extremal_variants(items) == 1` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; naming the (set-level × bool × union × unique-tie)
/// corner on the trait makes the degenerate opener's compile-time
/// theorem `T::CARDINALITY >= 2 => !T::has_unique_extremal_variant`
/// on non-empty slices a TYPED CONSEQUENCE of the substrate's just-
/// lifted extremal count aggregate rather than an unnamed inline
/// composition. THEORY.md §VI.1 — generation over composition; the
/// predicate emerges from the composition of ONE substrate primitive
/// ([`Self::count_extremal_variants`]) with a scalar equality
/// against `1`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t); n <-
/// min(t); sum(t == m | t == n) == 1 }` — the extremal-union
/// uniqueness test on a factor histogram; Julia's
/// `count(v -> v == maximum(values(c)) || v == minimum(values(c)), values(c)) == 1`
/// on `c = StatsBase.countmap(items)`; Python's
/// `let c = collections.Counter(items); mx = max(c.values(), default=0); mn = min(c.values(), default=0); sum(1 for v in c.values() if v == mx or v == mn) == 1`;
/// Haskell's
/// `let hs = map length . group . sort $ items; m = maximum hs; n = minimum hs in length (filter (\c -> c == m || c == n) hs) == 1`;
/// SQL's
/// `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant) WHERE c = (SELECT MAX(c) …) OR c = (SELECT MIN(c) …)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// extremal-union uniqueness predicate on the closed-set trait binds
/// through the just-lifted [`Self::count_extremal_variants`] scalar
/// against the constant `1` — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` on slice arity `n` inherited verbatim from
/// the extremal-count aggregate.
fn has_unique_extremal_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_extremal_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "does the BIMODAL intersection band
/// fall on a UNIQUE variant?" set-level predicate — `true` iff
/// EXACTLY ONE variant of [`Self::ALL`] carries an occurrence-count
/// MATCHING BOTH [`Self::max_variant_count`] AND
/// [`Self::min_variant_count`], computed as the strict-equality test
/// of the just-lifted [`Self::count_bimodal_variants`] cardinality-
/// count aggregate against the scalar threshold `1`. The BOOL-RETURN
/// UNIQUE-TIE SHARPENING corner CLOSING the (set-level × bool ×
/// direction-composition × unique-tie) row past the just-lifted
/// [`Self::has_unique_extremal_variant`] union arm one COMBINATOR
/// axis over on the modal-aggregation matrix AND EXHAUSTIVELY
/// CLOSING the (set-level × bool × direction-composition ×
/// combinator × unique-tie) row at its FINAL THIRD tile (past the
/// UNION arm [`Self::has_unique_extremal_variant`] closed and the
/// COMPLEMENT arm [`Self::has_unique_middle_band_variant`] closed).
/// Peer to [`Self::count_bimodal_variants`] one RETURN-SHAPE axis
/// over (set-level × `usize` cardinality → set-level × `bool`
/// uniqueness test against `1`) AND peer to
/// [`Self::has_bimodal_variant`] one UNIQUE-TIE-SHARPENING axis
/// over (existential `>= 1` → uniqueness `== 1`). Not a fresh
/// substrate primitive on the index axis — the predicate emerges
/// from one strict-equality test of the just-lifted
/// [`Self::count_bimodal_variants`] scalar against `1`,
/// equivalently the [`Vec::len`] equality of the declaration-order
/// intersection witness-collection [`Self::bimodal_variants`]
/// against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_bimodal_variant(items) ==
/// (T::count_bimodal_variants(items) == 1)` — the set-level bool
/// predicate is EXACTLY the strict-equality test of the just-lifted
/// set-level cardinality-count aggregate against the scalar threshold
/// `1`. The canonical form the body uses. Pinned by
/// `has_unique_bimodal_variant_equals_count_bimodal_variants_eq_one_across_every_triple`.
///
/// Bimodal witness length identity: for every slice `items`,
/// `T::has_unique_bimodal_variant(items) ==
/// (T::bimodal_variants(items).len() == 1)` — the set-level bool
/// predicate is EXACTLY the length-equality test of the declaration-
/// order intersection witness-collection against `1`. Independent
/// cross-check distinct from the count-composition arm on the
/// surface axis (Vec-length vs scalar equality). Pinned by
/// `has_unique_bimodal_variant_agrees_with_bimodal_variants_len_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_bimodal_variant(items) ==>
/// T::has_bimodal_variant(items)` — a UNIQUE bimodal witness
/// trivially entails the EXISTENCE of a bimodal witness (the
/// unique-tie sharpening `count == 1` implies the existential
/// `count >= 1`). Pinned by
/// `has_unique_bimodal_variant_implies_has_bimodal_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_bimodal_variants`] (ordering-agnostic) via a scalar
/// equality test against a fixed constant. No separate
/// `sorted_has_unique_bimodal_variant` peer is needed. Pinned by
/// `has_unique_bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_bimodal_variant(&[])` is
/// `false` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_bimodal_variants`] collapses to `0` at its empty-
/// slice guard, and `0 != 1`.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::has_unique_bimodal_variant(items)` is `false` on EVERY non-
/// empty slice on EVERY implementor with `T::CARDINALITY >= 2` — the
/// uniformity-collapse identity pins [`Self::count_bimodal_variants`]
/// at the TWO-VALUE DICHOTOMY `{0, T::CARDINALITY}` on every slice
/// (flat histogram → every variant sits at BOTH extremes
/// simultaneously via the `max == min` collapse → count reports
/// `T::CARDINALITY`; non-flat histogram → the argmax and argmin
/// bands are disjoint at at least one variant, so no variant sits
/// in the intersection → count reports `0`). Neither value equals
/// `1` at `T::CARDINALITY >= 2`, so the equality against `1` fails
/// everywhere past the empty slice. THIS corner is the DEGENERATE
/// OPENER on the (set-level × bool × direction-composition ×
/// intersection × unique-tie) axis — the SOLE positive arm sits at
/// `T::CARDINALITY == 1` where a matching singleton (= full-set)
/// collapses the intersection to a single variant, out of reach of
/// the multi-variant test-module fixtures.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::has_unique_bimodal_variant(&[v])` is `false` for every
/// variant `v` — the target hits count `1 == max`, every non-target
/// sits at count `0 == min`, `max != min`, so no variant sits in
/// the intersection (the non-flat argmax {target} at count 1
/// disjoint from the argmin `T::ALL \ {target}` at count 0), and
/// [`Self::count_bimodal_variants`] reports `0`.
///
/// Full-set + doubled-full-set contract: on either flat-histogram
/// fixpoint every variant sits at BOTH extremes simultaneously via
/// the (max == min) collapse; the intersection covers ALL of
/// [`Self::ALL`], so [`Self::count_bimodal_variants`] reports
/// `T::CARDINALITY` and `T::CARDINALITY != 1` on every implementor
/// with cardinality `>= 2`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax
/// is `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]`
/// (count `0`), `max != min`, so no variant sits in the
/// intersection and [`Self::count_bimodal_variants`] reports `0`.
/// LOAD-BEARING `false`-arm catch DISCRIMINATING this uniqueness
/// corner from [`Self::has_unique_middle_band_variant`]'s SOLE
/// positive arm on the same fixture — the intersection-arm
/// degenerate opener and the complement-arm strict-interior
/// positive arm split the direction-composition axis on the
/// canonical bimodal fixture. Peer discriminator to
/// [`Self::has_unique_extremal_variant`]'s bimodal-triple
/// `false`-arm one COMBINATOR axis over: the extremal-union
/// aggregate reports `T::CARDINALITY - 1 >= 2` (the argmax band
/// UNION the argmin band); this intersection aggregate reports `0`
/// (the argmax band DISJOINT-INTERSECTED with the argmin band).
/// Both arms of the row fold onto `false` past the empty slice at
/// cardinality `>= 2`, but through complementary aggregate
/// numerators.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_bimodal_variants`] via one scalar equality test on
/// `usize`. The sweep cost inherits the bimodal count aggregate:
/// `O(T::CARDINALITY * n)` on slice arity `n`, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::has_unique_bimodal_variant`]: a `tatara-check` predicate
/// `(check-bimodal-is-unique …)` that reports "exactly one variant
/// sits at BOTH extremes simultaneously" as a one-typed-call answer
/// (in practice, at cardinality `>= 2`, a compile-time-known
/// `false` predicate on every non-empty slice — a substrate-level
/// THEOREM the checker can rely on rather than re-verify per slice
/// via the two-value dichotomy `{0, T::CARDINALITY}` on the
/// bimodal count aggregate); a Sekiban audit-trail bit
/// `bimodal_uniqueness_bit(items)` that composes with a future
/// `unique_bimodal_variant -> Option<Self>` witness-if-unique
/// projection into a typed classifier per window; an LSP hint on a
/// Lisp-authored variant-list that surfaces the degenerate
/// theorem's positive arm ONLY at CARDINALITY 1 sets.
///
/// Compounding closure: this projection CLOSES the (set-level × bool
/// × statistical-aggregate × direction-composition × intersection ×
/// unique-tie) corner on the modal-aggregation matrix, sharpening
/// the just-lifted [`Self::count_bimodal_variants`] cardinality-
/// count scalar past the `1` threshold peer to
/// [`Self::has_unique_extremal_variant`] one COMBINATOR axis over
/// on the (direction-composition × unique-tie) row AND
/// EXHAUSTIVELY CLOSING the (direction-composition × combinator ×
/// unique-tie) 3-corner row at its FINAL THIRD tile past the UNION
/// arm and the COMPLEMENT arm. Together with clauses opened by
/// [`Self::has_unique_mode`] + [`Self::has_unique_antimode`] one
/// DIRECTION-COMPOSITION axis over, the (set-level × bool ×
/// direction × unique-tie) 4-column landscape now closes at ALL
/// FOUR inhabitants (argmax, argmin, union, complement,
/// intersection). The natural next lift past this row-completion is
/// the `Option<Self>`-return WITNESS-IF-UNIQUE projection column
/// `unique_bimodal_variant(items) -> Option<Self>` returning
/// `Some(v)` when the intersection witness is unambiguous and
/// `None` otherwise, peer to a hypothetical
/// `unique_extremal_variant` / `unique_middle_band_variant` triple
/// on the (direction-composition × option-witness) row one
/// RETURN-SHAPE axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level bimodal-intersection uniqueness bool predicate becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline `T::count_bimodal_variants(items) == 1`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; naming the (set-level × bool × intersection
/// × unique-tie) corner on the trait makes the degenerate opener's
/// compile-time theorem `T::CARDINALITY >= 2 =>
/// !T::has_unique_bimodal_variant` on non-empty slices a TYPED
/// CONSEQUENCE of the substrate's just-lifted bimodal count
/// aggregate's two-value dichotomy `{0, T::CARDINALITY}` rather
/// than an unnamed inline composition. THEORY.md §VI.1 —
/// generation over composition; the predicate emerges from the
/// composition of ONE substrate primitive
/// ([`Self::count_bimodal_variants`]) with a scalar equality
/// against `1`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t); n
/// <- min(t); sum(t == m & t == n) == 1 }` — the bimodal-
/// intersection uniqueness test on a factor histogram (which
/// collapses to `sum(t == m) == 1` when `m == n`, i.e. flat
/// histogram, and to `0` otherwise); Julia's
/// `count(v -> v == maximum(values(c)) && v == minimum(values(c)), values(c)) == 1`
/// on `c = StatsBase.countmap(items)`; Python's
/// `let c = collections.Counter(items); mx = max(c.values(), default=0); mn = min(c.values(), default=0); sum(1 for v in c.values() if v == mx and v == mn) == 1`;
/// Haskell's
/// `let hs = map length . group . sort $ items; m = maximum hs; n = minimum hs in length (filter (\c -> c == m && c == n) hs) == 1`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f))] (= 1 (count (filter #(and (= % m) (= % n)) (vals f)))))`;
/// SQL's `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c
/// FROM t GROUP BY variant) WHERE c = (SELECT MAX(c) …) AND c =
/// (SELECT MIN(c) …)`. Translation through pleme-io primitives: the
/// N-ary set-level bimodal-intersection-uniqueness predicate on the
/// closed-set trait binds through the just-lifted
/// [`Self::count_bimodal_variants`] scalar against the constant `1`
/// — no new dep, no supertrait bound (`Sized + Copy + 'static`
/// stays untouched), no allocation, `O(T::CARDINALITY * n)` on
/// slice arity `n` inherited verbatim from the bimodal-count
/// aggregate.
fn has_unique_bimodal_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_bimodal_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique extremal variant"
/// projection — `Some(v)` iff `items` has a UNIQUE extremal witness
/// ([`Self::has_unique_extremal_variant`] holds) AND `v` is the sole
/// variant achieving EITHER [`Self::max_variant_count`] OR
/// [`Self::min_variant_count`], else `None`. Computed as the just-
/// lifted set-level extremal-union uniqueness bit
/// [`Self::has_unique_extremal_variant`] guarding the declaration-
/// order union first-witness [`Self::extremal_variant`] projection:
/// when the guard holds the union witness is unambiguous and lifted
/// verbatim; when the guard falsifies the projection collapses to
/// `None`. The `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner
/// OPENING the (set-level × `Option<Self>` × statistical-aggregate ×
/// direction-composition × unique-tie) column past the four unsharpened
/// (declaration/lex × union/complement/intersection) direction-
/// composition first-witness peers ([`Self::extremal_variant`],
/// [`Self::sorted_extremal_variant`], [`Self::middle_band_variant`],
/// [`Self::sorted_middle_band_variant`], [`Self::bimodal_variant`],
/// [`Self::sorted_bimodal_variant`]) one UNIQUE-TIE-SHARPENING axis
/// over on the modal-aggregation matrix, AND peer to
/// [`Self::unique_modal_variant`] one DIRECTION-COMPOSITION axis over
/// (argmax first-witness-if-unique → union first-witness-if-unique)
/// AND peer to [`Self::has_unique_extremal_variant`] one RETURN-SHAPE
/// axis over (set-level × `bool` union uniqueness bit → set-level ×
/// `Option<Self>` union witness-when-unique). Not a fresh substrate
/// primitive on the index axis — the projection emerges from a boolean
/// conjunction of the just-lifted set-level extremal-union uniqueness
/// bit with the just-lifted declaration-order union first-witness
/// projection under an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_extremal_variant(items) == if T::has_unique_extremal_variant(items) { T::extremal_variant(items) } else { None }`
/// — the projection is EXACTLY the guarded lift of the declaration-
/// order union first-witness under the set-level extremal-union
/// uniqueness bit. The canonical form the body uses. Pinned by
/// `unique_extremal_variant_equals_has_unique_extremal_variant_gated_extremal_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_extremal_variant(items).is_some() == T::has_unique_extremal_variant(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level extremal-union uniqueness bit. Independent cross-check
/// distinct from the guarded-first-witness identity on the surface
/// axis (`Option::is_some` vs conditional-Option construction). Pinned
/// by `unique_extremal_variant_is_some_iff_has_unique_extremal_variant_across_every_triple`.
///
/// Extremal witness singleton identity: for every slice `items`,
/// `T::unique_extremal_variant(items) == (if T::extremal_variants(items).len() == 1 { Some(T::extremal_variants(items)[0]) } else { None })`
/// — when `items` has a unique extremal witness, the declaration-order
/// union witness-collection [`Self::extremal_variants`] collapses to a
/// length-`1` Vec containing EXACTLY that unique variant, so its slot-
/// `0` wrapped in `Some` coincides with THIS projection. When `items`
/// has no unique extremal witness, [`Self::extremal_variants`] either
/// returns an empty Vec (empty slice) or a length-`>= 2` Vec (multiple
/// ties in the union); the length-`1` guard falsifies and the
/// projection collapses to `None` through both branches. Independent
/// cross-check on the witness-Vec surface axis distinct from the
/// scalar-conjunction and Option-return arms. Pinned by
/// `unique_extremal_variant_agrees_with_extremal_variants_singleton_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_extremal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_extremal_variants`] is invariant under
/// slice-reversal) and [`Self::extremal_variant`] (ordering-agnostic
/// — the underlying max/min-fold pair + [`Self::count_occurrences_of`]
/// find sweep are all invariant under slice-reversal) via a boolean-
/// guarded `Option`-collapse. No separate `sorted_unique_extremal_variant`
/// peer is needed. Pinned by
/// `unique_extremal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_extremal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_extremal_variant`] collapses to `false` via its
/// `count_extremal_variants(&[]) == 0 != 1` fixpoint, and the guard-
/// arm short-circuit maps the empty slice to `None` before
/// [`Self::extremal_variant`]'s own `None`-at-empty branch is
/// consulted. Sibling posture to [`Self::unique_modal_variant`]'s
/// empty-slice `None` fixpoint one DIRECTION-COMPOSITION axis over.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::unique_extremal_variant(items) == None` on EVERY non-empty
/// slice on EVERY implementor with `T::CARDINALITY >= 2` — the
/// inclusion-exclusion identity `count_extremal_variants ==
/// count_modal + count_antimodal - count_bimodal` pins the union
/// cardinality at `T::CARDINALITY` on every flat-histogram fixpoint
/// (max == min collapses all three counts to `T::CARDINALITY`) and at
/// `>= 2` on every non-flat fixpoint (max != min splits the argmax
/// and argmin into two disjoint non-empty bands with empty
/// intersection, so the union carries at least one modal AND one
/// antimodal variant — count `>= 2`). [`Self::has_unique_extremal_variant`]
/// therefore returns `false` everywhere past the empty slice at
/// cardinality `>= 2`, and the guard collapses the projection to
/// `None`. THIS corner is the DEGENERATE OPENER on the (`Option<Self>`
/// × direction-composition × union × unique-tie) axis — the SOLE
/// `Some(_)` arm sits at `T::CARDINALITY == 1` where a matching
/// singleton (= full-set) collapses the union to a single variant,
/// out of reach of the multi-variant test-module fixtures. LOAD-
/// BEARING ASYMMETRY against [`Self::unique_modal_variant`] which
/// returns `Some(v)` on every matching-singleton at any cardinality —
/// the direction-composition axis SEPARATES the argmax uniqueness-
/// witness corner from THIS union uniqueness-witness corner on the
/// matching-singleton fixpoint at cardinality `>= 2` (the argmax
/// witness collapses to `{v}`, unambiguous; the union witness
/// carries both `{v}` and `T::ALL \ {v}`, ambiguous).
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::unique_extremal_variant(&[v]) == None` for every variant `v` —
/// the target hits count `1 == max`, every non-target sits at count
/// `0 == min`, the argmax band is `{v}` (size 1) and the argmin band
/// is `T::ALL \ {v}` (size `T::CARDINALITY - 1 >= 1`), disjoint, so
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_extremal_variant`] returns `false`, and the
/// guard collapses the projection to `None`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_extremal_variant(<T as ClosedSet>::ALL) == None` +
/// `T::unique_extremal_variant(&doubled) == None` — on either flat-
/// histogram fixpoint every variant sits at BOTH extremes
/// simultaneously via the (max == min) collapse; the union covers all
/// of [`Self::ALL`], [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY >= 2`, and the guard collapses to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is
/// `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]` (count
/// `0`), the union carries the two disjoint bands and
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY - 1 >=
/// 2`, so the guard collapses the projection to `None`.
///
/// Per-target composition identity (future): the eventual
/// `is_unique_extremal_variant_of(v, items)` per-target uniqueness
/// predicate will pin `T::is_unique_extremal_variant_of(v, items) ==
/// (T::unique_extremal_variant(items) == Some(v))` — sibling posture
/// to [`Self::unique_modal_variant`]'s per-target composition through
/// [`Self::is_unique_modal_variant_of`] one DIRECTION-COMPOSITION
/// axis over.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_extremal_variant`] + [`Self::extremal_variant`]
/// via a boolean-guarded `Option`-collapse on `Option<Self>`. The
/// sweep cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one max/min-fold pair,
/// one [`Self::count_extremal_variants`] filter-count sweep, and one
/// [`Self::extremal_variant`] find sweep when the guard holds; the
/// short-circuiting `if` avoids the second sweep when the guard
/// falsifies), allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait
/// pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_extremal_variant`]: a `tatara-check` predicate
/// `(check-extremal-if-unique …)` that reports "the sole extremal
/// variant, if unambiguous" as a typed `Option`-return rather than a
/// two-step (has-unique-extremal-variant? then extremal-variant)
/// composition; a Sekiban audit-trail per-window witness-if-unique
/// binding to the same scalar, composable with the just-lifted set-
/// level extremal-union uniqueness bit into a typed
/// (unique-extremal-bit, unique-extremal-witness) classifier; an LSP
/// hint that surfaces the histogram extremum on a Lisp-authored
/// field only when the extremum is unambiguous, staying silent on
/// tied unions. Each binds to ONE typed `Option<Self>`-return
/// uniqueness-gated union aggregate on the trait rather than re-
/// deriving `if T::has_unique_extremal_variant(items) { T::extremal_variant(items) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::extremal_variants(items).into_iter().next().filter(|_| T::extremal_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × statistical-aggregate × direction-composition ×
/// unique-tie) column past the just-closed (set-level × `bool` ×
/// direction-composition × combinator × unique-tie) 3-corner row on
/// the modal-aggregation matrix, peer to [`Self::unique_modal_variant`]
/// one DIRECTION-COMPOSITION axis over. The remaining two tiles on
/// the row are the complement arm
/// `unique_middle_band_variant(items) -> Option<Self>` (returning
/// `Some(v)` iff `has_unique_middle_band_variant(items)` holds AND
/// `v` is the sole strict-interior variant) and the intersection arm
/// `unique_bimodal_variant(items) -> Option<Self>` (returning
/// `Some(v)` iff `has_unique_bimodal_variant(items)` holds AND `v`
/// is the sole `max == min` witness). Each remaining corner emerges
/// as a boolean-guarded lift of the existing (`Option<Self>` ×
/// direction-composition × unsharpened) peer under the existing
/// (`bool` × direction-composition × unique-tie) uniqueness bit, so
/// the (`Option<Self>` × direction-composition × unique-tie) 3-corner
/// row fills with no fresh substrate primitives on the index axis.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-extremal `Option<Self>` witness projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline `if T::has_unique_extremal_variant(items) { T::extremal_variant(items) } else { None }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Option<Self>` × direction-
/// composition × union × unique-tie) witness-if-unique corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which variant is the histogram's extremum, if it's
/// unambiguous?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the just-lifted set-level
/// extremal-union uniqueness bit and the declaration-order union
/// first-witness under a boolean-guarded `Option`-collapse. THEORY.md
/// §VI.1 — generation over composition; the projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::has_unique_extremal_variant`] +
/// [`Self::extremal_variant`]) with the `if _ { _ } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t); n <-
/// min(t); tied <- names(t)[t == m | t == n]; if (length(tied) == 1)
/// tied[1] else NA }` — the canonical guarded-union on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items), m =
/// maximum(values(c)), n = minimum(values(c)), ties = filter(kv ->
/// kv[2] == m || kv[2] == n, collect(c)); length(ties) == 1 ?
/// Some(ties[1][1]) : Nothing end` on a `Dict{Element, Int}`
/// histogram; Python's `let c = collections.Counter(items); mx =
/// max(c.values(), default=0); mn = min(c.values(), default=0);
/// tied = [k for k, v in c.items() if v == mx or v == mn]; tied[0]
/// if len(tied) == 1 else None`; Haskell's `let hs = map (\g ->
/// (head g, length g)) . group . sort $ items; m = maximum (map snd
/// hs); n = minimum (map snd hs); ts = filter (\(_, c) -> c == m ||
/// c == n) hs in case ts of [(v, _)] -> Just v; _ -> Nothing`;
/// Clojure's `(let [f (frequencies coll), m (apply max (vals f)), n
/// (apply min (vals f)), ts (filter #(or (= (val %) m) (= (val %) n))
/// f)] (when (= 1 (count ts)) (key (first ts))))`; SQL's `SELECT
/// variant FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY
/// variant HAVING c = (SELECT MAX(c) …) OR c = (SELECT MIN(c) …))
/// WHERE (SELECT COUNT(*) FROM …) = 1`. Translation through pleme-io
/// primitives: the N-ary set-level uniqueness-gated union witness
/// projection on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_extremal_variant`] guard conjoined with the
/// just-lifted [`Self::extremal_variant`] first-witness under an
/// `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_extremal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_extremal_variant(items) {
<Self as ClosedSet>::extremal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique middle-band variant"
/// projection — `Some(v)` iff `items` has a UNIQUE strict-interior
/// witness ([`Self::has_unique_middle_band_variant`] holds) AND `v` is
/// the sole variant with occurrence-count STRICTLY BETWEEN
/// [`Self::max_variant_count`] AND [`Self::min_variant_count`], else
/// `None`. Computed as the just-lifted set-level middle-band uniqueness
/// bit [`Self::has_unique_middle_band_variant`] guarding the
/// declaration-order strict-interior first-witness
/// [`Self::middle_band_variant`] projection: when the guard holds the
/// complement witness is unambiguous and lifted verbatim; when the
/// guard falsifies the projection collapses to `None`. The
/// `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner CLOSING the
/// complement arm of the (set-level × `Option<Self>` × direction-
/// composition × unique-tie) row past the just-opened UNION arm
/// [`Self::unique_extremal_variant`] one COMBINATOR axis over on the
/// modal-aggregation matrix AND peer to
/// [`Self::has_unique_middle_band_variant`] one RETURN-SHAPE axis over
/// (set-level × `bool` complement uniqueness bit → set-level ×
/// `Option<Self>` complement witness-when-unique) AND peer to
/// [`Self::middle_band_variant`] one UNIQUE-TIE-SHARPENING axis over
/// (unsharpened declaration-order strict-interior first-witness →
/// uniqueness-gated declaration-order strict-interior first-witness).
/// Not a fresh substrate primitive on the index axis — the projection
/// emerges from a boolean conjunction of the just-lifted set-level
/// middle-band uniqueness bit with the just-lifted declaration-order
/// strict-interior first-witness projection under an `Option`-collapse
/// when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_middle_band_variant(items) == if T::has_unique_middle_band_variant(items) { T::middle_band_variant(items) } else { None }`
/// — the canonical form the body uses. Pinned by
/// `unique_middle_band_variant_equals_has_unique_middle_band_variant_gated_middle_band_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_middle_band_variant(items).is_some() == T::has_unique_middle_band_variant(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level middle-band uniqueness bit. Independent cross-check on
/// the surface axis (`Option::is_some` vs conditional-Option
/// construction). Pinned by
/// `unique_middle_band_variant_is_some_iff_has_unique_middle_band_variant_across_every_triple`.
///
/// Middle-band witness singleton identity: for every slice `items`,
/// `T::unique_middle_band_variant(items) == (if T::middle_band_variants(items).len() == 1 { Some(T::middle_band_variants(items)[0]) } else { None })`
/// — when `items` has a unique middle-band witness, the declaration-
/// order complement witness-collection [`Self::middle_band_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection. Independent cross-check on the witness-Vec surface
/// axis distinct from the scalar-conjunction and Option-return arms.
/// Pinned by
/// `unique_middle_band_variant_agrees_with_middle_band_variants_singleton_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_middle_band_variant`] (ordering-agnostic — the
/// underlying [`Self::count_middle_band_variants`] is invariant under
/// slice-reversal) and [`Self::middle_band_variant`] (ordering-
/// agnostic — the underlying max/min-fold pair +
/// [`Self::count_occurrences_of`] find sweep are all invariant under
/// slice-reversal) via a boolean-guarded `Option`-collapse. No
/// separate `sorted_unique_middle_band_variant` peer is needed until
/// the sibling LEX corner is opened. Pinned by
/// `unique_middle_band_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_middle_band_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_middle_band_variant`] collapses to `false` via
/// its `count_middle_band_variants(&[]) == 0 != 1` fixpoint, and the
/// guard-arm short-circuit maps the empty slice to `None` before
/// [`Self::middle_band_variant`]'s own `None`-at-empty branch is
/// consulted.
///
/// Flat-histogram contract at cardinality `>= 2`:
/// `T::unique_middle_band_variant(<T as ClosedSet>::ALL) == None` +
/// `T::unique_middle_band_variant(&doubled) == None` — on either
/// flat-histogram fixpoint every variant sits at BOTH extremes
/// simultaneously via the (max == min) collapse, NO variant sits
/// strictly between, [`Self::count_middle_band_variants`] reports
/// `0`, [`Self::has_unique_middle_band_variant`] returns `false`, and
/// the guard collapses the projection to `None`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::unique_middle_band_variant(&[v]) == None` for every variant
/// `v` — the target hits count `1 == max`, every non-target sits at
/// count `0 == min`; EVERY variant of [`Self::ALL`] sits AT one of
/// the two extremes, NO variant sits strictly between,
/// [`Self::count_middle_band_variants`] reports `0`, and the guard
/// collapses to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::unique_middle_band_variant([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == Some(T::ALL[1])` — the LOAD-BEARING SOLE `Some(_)`-arm on the
/// canonical fixture window. On the non-flat triple `T::ALL[0]` sits
/// at count `2 == max`, `T::ALL[1]` at count `1` STRICTLY between max
/// `2` and min `0` (the SOLE strict-interior inhabitant), `T::ALL[2..]`
/// at count `0 == min`; [`Self::count_middle_band_variants`] reports
/// `1`, [`Self::has_unique_middle_band_variant`] returns `true`, the
/// guard fires, and [`Self::middle_band_variant`]'s declaration-order
/// sweep hits `T::ALL[1]` immediately. LOAD-BEARING ASYMMETRY against
/// [`Self::unique_extremal_variant`] which returns `None` on the same
/// fixture (the union band carries the two disjoint extremes) — the
/// DIRECTION-COMPOSITION axis SEPARATES the union DEGENERATE opener
/// from THIS complement POSITIVE opener on the canonical bimodal
/// triple. Pinned by
/// `unique_middle_band_variant_returns_all_1_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::middle_band_variant`] via a boolean-guarded
/// `Option`-collapse on `Option<Self>`. The sweep cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity `n`,
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); the short-circuiting `if` avoids the second sweep when
/// the guard falsifies.
///
/// Future consumers that compose against
/// [`Self::unique_middle_band_variant`]: a `tatara-check` predicate
/// `(check-middle-band-if-unique …)` that reports "the sole strict-
/// interior variant, if unambiguous" as a typed `Option`-return
/// rather than a two-step (has-unique-middle-band-variant? then
/// middle-band-variant) composition; an LSP diagnostic on a Lisp-
/// authored variant-list that surfaces the SOLE middle-priority
/// enum-arm — the canonical "everyone else is either exhaustive or
/// missed" reviewer heuristic — only when the interior is
/// unambiguous, staying silent on tied interiors; a Sekiban audit-
/// trail per-window witness-if-unique binding to the same scalar,
/// composable with the just-lifted set-level middle-band uniqueness
/// bit into a typed (unique-middle-band-bit, unique-middle-band-
/// witness) classifier. Each binds to ONE typed `Option<Self>`-return
/// uniqueness-gated complement aggregate on the trait rather than
/// re-deriving
/// `if T::has_unique_middle_band_variant(items) { T::middle_band_variant(items) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::middle_band_variants(items).into_iter().next().filter(|_| T::middle_band_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection CLOSES the complement arm of
/// the (set-level × `Option<Self>` × statistical-aggregate ×
/// direction-composition × unique-tie) row past the just-opened UNION
/// arm [`Self::unique_extremal_variant`] one COMBINATOR axis over on
/// the modal-aggregation matrix, peer to
/// [`Self::has_unique_middle_band_variant`] one RETURN-SHAPE axis
/// over. The remaining tile on the row is the intersection arm
/// `unique_bimodal_variant(items) -> Option<Self>` (returning
/// `Some(v)` iff `has_unique_bimodal_variant(items)` holds AND `v` is
/// the sole `max == min` witness), emerging as a boolean-guarded lift
/// of [`Self::bimodal_variant`] under
/// [`Self::has_unique_bimodal_variant`]. Together with clauses (162),
/// (163), (164) (the (set-level × bool × direction-composition × union
/// / complement / intersection × unique-tie) counterparts) one RETURN-
/// SHAPE axis over, the (`Option<Self>` × direction-composition ×
/// complement × unique-tie) corner now closes the RETURN-SHAPE axis
/// at the boolean-guarded-Option-collapse layer above the pre-existing
/// bool-return uniqueness bit.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-middle-band `Option<Self>` witness projection becomes
/// a TYPE-level primitive on the closed-set trait rather than a per-
/// consumer inline
/// `if T::has_unique_middle_band_variant(items) { T::middle_band_variant(items) } else { None }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Option<Self>` × direction-
/// composition × complement × unique-tie) witness-if-unique corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "which variant is the histogram's strict interior, if
/// it's unambiguous?" site pre-lift. Naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the just-lifted set-level
/// middle-band uniqueness bit and the declaration-order strict-
/// interior first-witness under a boolean-guarded `Option`-collapse.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::has_unique_middle_band_variant`] +
/// [`Self::middle_band_variant`]) with the `if _ { _ } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t); n <-
/// min(t); mid <- names(t)[t > n & t < m]; if (length(mid) == 1)
/// mid[1] else NA }` — the canonical guarded strict-interior on a
/// factor histogram; Julia's `let c = StatsBase.countmap(items), m =
/// maximum(values(c)), n = minimum(values(c)), mid = filter(kv ->
/// n < kv[2] < m, collect(c)); length(mid) == 1 ? Some(mid[1][1]) :
/// Nothing end`; Python's `let c = collections.Counter(items); mx =
/// max(c.values(), default=0); mn = min(c.values(), default=0); mid
/// = [k for k, v in c.items() if mn < v < mx]; mid[0] if len(mid) ==
/// 1 else None`; Haskell's `let hs = map (\g -> (head g, length g))
/// . group . sort $ items; m = maximum (map snd hs); n = minimum
/// (map snd hs); ts = filter (\(_, c) -> c > n && c < m) hs in case
/// ts of [(v, _)] -> Just v; _ -> Nothing`; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min
/// (vals f)), ts (filter #(< n (val %) m) f)] (when (= 1 (count ts))
/// (key (first ts))))`; SQL's `SELECT variant FROM (SELECT variant,
/// COUNT(*) AS c FROM t GROUP BY variant HAVING c > (SELECT MIN(c)
/// …) AND c < (SELECT MAX(c) …)) WHERE (SELECT COUNT(*) FROM …) =
/// 1`. Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated complement witness projection on the closed-set
/// trait binds through the just-lifted
/// [`Self::has_unique_middle_band_variant`] guard conjoined with the
/// just-lifted [`Self::middle_band_variant`] first-witness under an
/// `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_middle_band_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_middle_band_variant(items) {
<Self as ClosedSet>::middle_band_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique bimodal variant" projection
/// — `Some(v)` iff `items` has a UNIQUE flat-diagonal witness
/// ([`Self::has_unique_bimodal_variant`] holds) AND `v` is the sole
/// variant with occurrence-count sitting SIMULTANEOUSLY at BOTH
/// [`Self::max_variant_count`] AND [`Self::min_variant_count`] (the
/// uniformity-collapse `max == min` fixpoint), else `None`. Computed
/// as the just-lifted set-level bimodal uniqueness bit
/// [`Self::has_unique_bimodal_variant`] guarding the declaration-order
/// intersection first-witness [`Self::bimodal_variant`] projection:
/// when the guard holds the intersection witness is unambiguous and
/// lifted verbatim; when the guard falsifies the projection collapses
/// to `None`. The `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner
/// CLOSING the intersection arm of the (set-level × `Option<Self>` ×
/// direction-composition × unique-tie) row past the just-opened UNION
/// arm [`Self::unique_extremal_variant`] AND the just-closed COMPLEMENT
/// arm [`Self::unique_middle_band_variant`] one COMBINATOR axis over
/// on the modal-aggregation matrix AND EXHAUSTIVELY CLOSING the
/// (`Option<Self>` × direction-composition × combinator × unique-tie)
/// 3-corner row at its FINAL THIRD tile past the union + complement
/// arms AND peer to [`Self::has_unique_bimodal_variant`] one
/// RETURN-SHAPE axis over (set-level × `bool` intersection uniqueness
/// bit → set-level × `Option<Self>` intersection witness-when-unique)
/// AND peer to [`Self::bimodal_variant`] one UNIQUE-TIE-SHARPENING
/// axis over (unsharpened declaration-order intersection first-witness
/// → uniqueness-gated declaration-order intersection first-witness).
/// Not a fresh substrate primitive on the index axis — the projection
/// emerges from a boolean conjunction of the just-lifted set-level
/// bimodal uniqueness bit with the declaration-order intersection
/// first-witness projection under an `Option`-collapse when the guard
/// falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_bimodal_variant(items) == if T::has_unique_bimodal_variant(items) { T::bimodal_variant(items) } else { None }`
/// — the canonical form the body uses. Pinned by
/// `unique_bimodal_variant_equals_has_unique_bimodal_variant_gated_bimodal_variant_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_bimodal_variant(items).is_some() == T::has_unique_bimodal_variant(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level bimodal uniqueness bit. Independent cross-check distinct
/// from the guarded-first-witness identity on the surface axis
/// (`Option::is_some` vs conditional-Option construction). Pinned by
/// `unique_bimodal_variant_is_some_iff_has_unique_bimodal_variant_across_every_triple`.
///
/// Bimodal witness singleton identity: for every slice `items`,
/// `T::unique_bimodal_variant(items) == (if T::bimodal_variants(items).len() == 1 { Some(T::bimodal_variants(items)[0]) } else { None })`
/// — when `items` has a unique bimodal witness, the declaration-order
/// intersection witness-collection [`Self::bimodal_variants`] collapses
/// to a length-`1` Vec containing EXACTLY that unique variant, so its
/// slot-`0` wrapped in `Some` coincides with THIS projection.
/// Independent cross-check on the witness-Vec surface axis. Pinned by
/// `unique_bimodal_variant_agrees_with_bimodal_variants_singleton_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_bimodal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_bimodal_variants`] is invariant under
/// slice-reversal) and [`Self::bimodal_variant`] (ordering-agnostic
/// — the underlying [`Self::is_uniform`] fold + `T::ALL.first()` pick
/// are all invariant under slice-reversal) via a boolean-guarded
/// `Option`-collapse. No separate `sorted_unique_bimodal_variant`
/// peer is needed until the sibling LEX corner is opened. Pinned by
/// `unique_bimodal_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_bimodal_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_bimodal_variant`] collapses to `false` via its
/// `count_bimodal_variants(&[]) == 0 != 1` fixpoint, and the guard-arm
/// short-circuit maps the empty slice to `None` before
/// [`Self::bimodal_variant`]'s own `None`-at-empty branch is
/// consulted.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::unique_bimodal_variant(items) == None` on EVERY slice on EVERY
/// implementor with `T::CARDINALITY >= 2` — the uniformity-collapse
/// identity `count_bimodal_variants ∈ {0, T::CARDINALITY}` pins the
/// intersection cardinality at either `0` (non-flat via disjoint
/// argmax/argmin bands) or `T::CARDINALITY` (flat via max == min
/// pinning every variant at both extremes), and neither `0` nor
/// `T::CARDINALITY >= 2` equals `1`. [`Self::has_unique_bimodal_variant`]
/// therefore returns `false` everywhere at cardinality `>= 2`, and
/// the guard collapses the projection to `None`. THIS corner is the
/// DEGENERATE OPENER on the (`Option<Self>` × direction-composition ×
/// intersection × unique-tie) axis — the SOLE `Some(_)` arm sits at
/// `T::CARDINALITY == 1` where a non-empty slice collapses the
/// intersection to a single variant, out of reach of the multi-variant
/// test-module fixtures. LOAD-BEARING ASYMMETRY against
/// [`Self::unique_middle_band_variant`] which returns
/// `Some(T::ALL[1])` on the canonical bimodal triple — the
/// direction-composition axis SEPARATES this INTERSECTION degenerate
/// arm from the COMPLEMENT positive arm on the same fixture at
/// cardinality `>= 3`.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::unique_bimodal_variant(&[v]) == None` for every variant `v` —
/// the target hits count `1 == max`, every non-target sits at count
/// `0 == min`, `max != min` pins a strict direction split, NO variant
/// hits both extremes simultaneously, [`Self::count_bimodal_variants`]
/// reports `0`, and the guard collapses to `None`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_bimodal_variant(<T as ClosedSet>::ALL) == None` +
/// `T::unique_bimodal_variant(&doubled) == None` — on either
/// flat-histogram fixpoint every variant sits at BOTH extremes
/// simultaneously via the (max == min) collapse, the intersection
/// covers all of [`Self::ALL`], [`Self::count_bimodal_variants`]
/// reports `T::CARDINALITY >= 2`, and the guard collapses the
/// projection to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::unique_bimodal_variant([T::ALL[0], T::ALL[0], T::ALL[1]]) ==
/// None` — on the canonical non-flat triple `T::ALL[0]` sits at count
/// `2 == max`, `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0 ==
/// min`; `max != min` pins a strict direction split, NO variant hits
/// both extremes, [`Self::count_bimodal_variants`] reports `0`, and
/// the guard collapses the projection to `None`. LOAD-BEARING
/// DISCRIMINATOR from [`Self::unique_middle_band_variant`] which
/// returns `Some(T::ALL[1])` on the same fixture — the complement
/// arm's strict-interior singleton is EXACTLY the strict interior;
/// THIS intersection arm reports the impossible flat-diagonal
/// singleton and collapses to `None`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_bimodal_variant`] + [`Self::bimodal_variant`]
/// via a boolean-guarded `Option`-collapse on `Option<Self>`. The
/// sweep cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one uniformity-fold via
/// [`Self::is_uniform`], one [`Self::count_bimodal_variants`] scalar
/// check when the guard holds; the short-circuiting `if` avoids the
/// second sweep when the guard falsifies), allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_bimodal_variant`]: a `tatara-check` predicate
/// `(check-bimodal-if-unique …)` that reports "the sole flat-diagonal
/// variant, if unambiguous" as a typed `Option`-return rather than a
/// two-step (has-unique-bimodal-variant? then bimodal-variant)
/// composition; an LSP diagnostic on a Lisp-authored variant-list that
/// surfaces the SOLE degenerate flat-histogram variant — the shape of
/// the "all one thing" quick-fix — only when the histogram is
/// unambiguously flat AND cardinality-1 collapses; a Sekiban
/// audit-trail per-window witness-if-unique binding to the same
/// scalar, composable with the just-lifted set-level bimodal
/// uniqueness bit into a typed (unique-bimodal-bit,
/// unique-bimodal-witness) classifier. Each binds to ONE typed
/// `Option<Self>`-return uniqueness-gated intersection aggregate on
/// the trait rather than re-deriving
/// `if T::has_unique_bimodal_variant(items) { T::bimodal_variant(items) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::bimodal_variants(items).into_iter().next().filter(|_| T::bimodal_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection CLOSES the intersection arm
/// of the (set-level × `Option<Self>` × statistical-aggregate ×
/// direction-composition × unique-tie) row past the just-opened UNION
/// arm [`Self::unique_extremal_variant`] AND the just-closed COMPLEMENT
/// arm [`Self::unique_middle_band_variant`] one COMBINATOR axis over
/// on the modal-aggregation matrix AND EXHAUSTIVELY CLOSES the
/// (`Option<Self>` × direction-composition × combinator × unique-tie)
/// 3-corner row at its FINAL THIRD tile. Together with clauses (162),
/// (163), (164) (the (set-level × bool × direction-composition ×
/// complement / union / intersection × unique-tie) counterparts) one
/// RETURN-SHAPE axis over AND clauses (165), (166) (the sibling
/// Option-return union + complement uniqueness-gated projections) one
/// COMBINATOR axis over, the (direction-composition × combinator ×
/// unique-tie) 2×3 = 6-corner (bool × Option) × (union × complement ×
/// intersection) landscape now closes at ALL SIX inhabitants. The
/// natural next lift past this corner is the LEX-order sibling
/// `sorted_unique_bimodal_variant` (guarded lift of
/// [`Self::sorted_bimodal_variant`] under
/// [`Self::has_unique_bimodal_variant`]) or the direction-anchored
/// LEX-order siblings (`sorted_unique_modal_variant`,
/// `sorted_unique_antimodal_variant`, …) one ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-level
/// unique-bimodal `Option<Self>` witness projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline
/// `if T::has_unique_bimodal_variant(items) { T::bimodal_variant(items) } else { None }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Option<Self>` × direction-
/// composition × intersection × unique-tie) witness-if-unique corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "which variant is the histogram's flat-diagonal
/// witness, if it's unambiguous?" site pre-lift. Naming it on the
/// trait makes the projection a TYPED CONSEQUENCE of the just-lifted
/// set-level bimodal uniqueness bit and the declaration-order
/// intersection first-witness under a boolean-guarded `Option`-
/// collapse. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of TWO substrate primitives
/// ([`Self::has_unique_bimodal_variant`] + [`Self::bimodal_variant`])
/// with the `if _ { _ } else { None }` combinator on `Option<Self>`,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); m <- max(t); n <-
/// min(t); flat <- names(t)[t == m & t == n]; if (length(flat) == 1)
/// flat[1] else NA }` — the canonical guarded flat-diagonal on a
/// factor histogram; Julia's `let c = StatsBase.countmap(items), m =
/// maximum(values(c)), n = minimum(values(c)), flat = filter(kv ->
/// kv[2] == m && kv[2] == n, collect(c)); length(flat) == 1 ?
/// Some(flat[1][1]) : Nothing end`; Python's `let c =
/// collections.Counter(items); mx = max(c.values(), default=0); mn =
/// min(c.values(), default=0); flat = [k for k, v in c.items() if v
/// == mx and v == mn]; flat[0] if len(flat) == 1 else None`;
/// Haskell's `let hs = map (\g -> (head g, length g)) . group . sort
/// $ items; m = maximum (map snd hs); n = minimum (map snd hs); ts =
/// filter (\(_, c) -> c == m && c == n) hs in case ts of [(v, _)] ->
/// Just v; _ -> Nothing`; Clojure's `(let [f (frequencies coll), m
/// (apply max (vals f)), n (apply min (vals f)), ts (filter #(and (=
/// (val %) m) (= (val %) n)) f)] (when (= 1 (count ts)) (key (first
/// ts))))`; SQL's `SELECT variant FROM (SELECT variant, COUNT(*) AS c
/// FROM t GROUP BY variant HAVING c = (SELECT MAX(c) …) AND c =
/// (SELECT MIN(c) …)) WHERE (SELECT COUNT(*) FROM …) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated intersection witness projection on the closed-set
/// trait binds through the just-lifted
/// [`Self::has_unique_bimodal_variant`] guard conjoined with the
/// just-lifted [`Self::bimodal_variant`] first-witness under an
/// `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_bimodal_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_bimodal_variant(items) {
<Self as ClosedSet>::bimodal_variant(items)
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique extremal witness as a
/// singleton-or-empty Vec" projection — returns `vec![v]` iff `items`
/// has a UNIQUE extremal witness ([`Self::has_unique_extremal_variant`]
/// holds) AND `v` is the sole variant achieving EITHER
/// [`Self::max_variant_count`] OR [`Self::min_variant_count`], else
/// `vec![]`. Computed as the just-lifted set-level extremal-union
/// uniqueness bit [`Self::has_unique_extremal_variant`] guarding the
/// declaration-order union witness-collection
/// [`Self::extremal_variants`]: when the guard holds the collection is
/// already a length-`1` Vec by the guard's own definition
/// (`count_extremal_variants == 1`) and is lifted verbatim; when the
/// guard falsifies the projection collapses to the EMPTY Vec through
/// a zero-allocation `::std::vec::Vec::new()` short-circuit. The
/// `Vec<Self>`-RETURN UNIQUE-TIE SHARPENING corner OPENING the
/// (set-level × `Vec<Self>` × statistical-aggregate × direction-
/// composition × unique-tie) column past the six unsharpened
/// (declaration/lex × union/complement/intersection) direction-
/// composition witness-collection peers
/// ([`Self::extremal_variants`], [`Self::sorted_extremal_variants`],
/// [`Self::middle_band_variants`],
/// [`Self::sorted_middle_band_variants`], [`Self::bimodal_variants`],
/// [`Self::sorted_bimodal_variants`]) one UNIQUE-TIE-SHARPENING axis
/// over on the modal-aggregation matrix AND peer to
/// [`Self::unique_extremal_variant`] (set-level × `Option<Self>` ×
/// union × unique-tie) one RETURN-SHAPE axis over (Option-return
/// witness-when-unique → Vec-return singleton-or-empty-when-unique)
/// AND peer to [`Self::has_unique_extremal_variant`] (set-level ×
/// `bool` × union × unique-tie) one RETURN-SHAPE axis over (bool
/// uniqueness bit → Vec-return singleton-or-empty carrier of the same
/// bit). Not a fresh substrate primitive on the index axis — the
/// projection emerges from the boolean-guarded selection of the just-
/// lifted declaration-order union witness-collection under the set-
/// level extremal-union uniqueness bit, collapsing to the empty Vec
/// through the guard-arm when the bit falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_extremal_variants(items) == if T::has_unique_extremal_variant(items) { T::extremal_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_extremal_variants_equals_has_unique_extremal_variant_gated_extremal_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_extremal_variants(items).len() == usize::from(T::has_unique_extremal_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level extremal-
/// union uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since when
/// `count_extremal_variants == 1` the underlying
/// [`Self::extremal_variants`] filter over [`Self::ALL`] admits
/// EXACTLY ONE variant). Independent cross-check on the surface axis
/// distinct from the guarded-witness-collection arm (length reduction
/// vs conditional Vec-select). Pinned by
/// `unique_extremal_variants_len_equals_has_unique_extremal_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_extremal_variants(items).first().copied() == T::unique_extremal_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both encode
/// the same "sole witness if unique, else nothing" semantics through
/// different return shapes. Pinned by
/// `unique_extremal_variants_first_equals_unique_extremal_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_extremal_variants(items).is_empty() == !T::has_unique_extremal_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_extremal_variants_is_empty_iff_not_has_unique_extremal_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_extremal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_extremal_variants`] is invariant under
/// slice-reversal) and [`Self::extremal_variants`] (ordering-agnostic
/// on the input axis — the underlying max/min-fold pair +
/// [`Self::is_extremal_variant_of`] filter over [`Self::ALL`] are all
/// invariant under slice-reversal) via a boolean-guarded Vec-select.
/// Pinned by
/// `unique_extremal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_extremal_variants(&[]) == vec![]`
/// UNCONDITIONALLY — [`Self::has_unique_extremal_variant`] collapses
/// to `false` via its `count_extremal_variants(&[]) == 0 != 1`
/// fixpoint, and the guard-arm short-circuit maps the empty slice to
/// the empty Vec before [`Self::extremal_variants`]'s own empty-Vec-
/// at-empty branch is consulted.
///
/// Degenerate-opener contract at cardinality `>= 2`:
/// `T::unique_extremal_variants(items) == vec![]` on EVERY non-empty
/// canonical fixture on EVERY implementor with `T::CARDINALITY >= 2`
/// — the inclusion-exclusion identity pins the union cardinality at
/// either `0` or `>= 2` past the empty slice at cardinality `>= 2`,
/// so [`Self::has_unique_extremal_variant`] returns `false` and the
/// guard collapses the projection to the EMPTY Vec. THIS corner is
/// the DEGENERATE OPENER on the (`Vec<Self>` × direction-composition
/// × union × unique-tie) axis — the SOLE non-empty arm sits at
/// `T::CARDINALITY == 1` where a matching singleton (= full-set)
/// collapses the union to a single variant, out of reach of the
/// multi-variant test-module fixtures. LOAD-BEARING ASYMMETRY against
/// [`Self::extremal_variants`] which returns a non-empty Vec on
/// every non-empty slice.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_extremal_variant`] +
/// [`Self::extremal_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_extremal_variants`] reduction for the guard, one
/// [`Self::extremal_variants`] filter sweep when the guard holds; the
/// short-circuiting `if` avoids the filter sweep AND the Vec
/// allocation when the guard falsifies), no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_extremal_variants`]: a `tatara-check` predicate
/// `(check-extremals-if-unique …)` that reports the singleton-or-
/// empty extremal witness collection as a typed `Vec<Self>`-return
/// rather than a two-step (has-unique-extremal-variant? then
/// extremal-variants) composition; a Sekiban audit-trail per-window
/// singleton-or-empty binding that composes uniformly with the
/// six-Vec (union/complement/intersection × declaration/lex) rows
/// through a shared Vec return shape; downstream aggregate code that
/// iterates over "the sole witness if any" without needing to
/// dispatch on Option/Vec at the callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-extremal `Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set trait
/// rather than a per-consumer inline
/// `if T::has_unique_extremal_variant(items) { T::extremal_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × direction-
/// composition × union × unique-tie) witness-if-unique corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "the sole extremal, as a Vec, if it's unambiguous"
/// site pre-lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_extremal_variant`] +
/// [`Self::extremal_variants`]) with the `if _ { _ } else { vec![] }`
/// combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); m <- max(t); n <- min(t); tied <- names(t)[t == m | t == n]; if (length(tied) == 1) tied else character(0) }`
/// — the canonical guarded-union singleton-or-empty carrier on a
/// factor histogram; Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f)), ts (filter #(or (= (val %) m) (= (val %) n)) f)] (if (= 1 (count ts)) [(key (first ts))] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) IN (SELECT MAX(c), MIN(c) FROM …)) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated union singleton-or-empty projection on the
/// closed-set trait binds through the just-lifted
/// [`Self::has_unique_extremal_variant`] guard conjoined with the
/// just-lifted [`Self::extremal_variants`] witness-collection under
/// a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_extremal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_extremal_variant(items) {
<Self as ClosedSet>::extremal_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique strict-interior witness as
/// a singleton-or-empty Vec" projection — returns `vec![v]` iff `items`
/// has a UNIQUE strict-interior witness ([`Self::has_unique_middle_band_variant`]
/// holds) AND `v` is the sole variant whose per-target multiplicity
/// sits STRICTLY between [`Self::max_variant_count`] and
/// [`Self::min_variant_count`], else `vec![]`. Computed as the just-
/// lifted set-level middle-band uniqueness bit
/// [`Self::has_unique_middle_band_variant`] guarding the declaration-
/// order complement witness-collection [`Self::middle_band_variants`]:
/// when the guard holds the collection is already a length-`1` Vec by
/// the guard's own definition (`count_middle_band_variants == 1`) and
/// is lifted verbatim; when the guard falsifies the projection
/// collapses to the EMPTY Vec through a zero-allocation
/// `::std::vec::Vec::new()` short-circuit. The `Vec<Self>`-RETURN
/// UNIQUE-TIE SHARPENING corner CLOSING the complement arm of the
/// (set-level × `Vec<Self>` × statistical-aggregate × direction-
/// composition × combinator × unique-tie) row past the just-opened
/// UNION arm [`Self::unique_extremal_variants`] one COMBINATOR axis
/// over on the modal-aggregation matrix, peer to
/// [`Self::unique_middle_band_variant`] (set-level × `Option<Self>` ×
/// complement × unique-tie) one RETURN-SHAPE axis over (Option-return
/// witness-when-unique → Vec-return singleton-or-empty-when-unique)
/// AND peer to [`Self::has_unique_middle_band_variant`] (set-level ×
/// `bool` × complement × unique-tie) one RETURN-SHAPE axis over (bool
/// uniqueness bit → Vec-return singleton-or-empty carrier of the same
/// bit). Not a fresh substrate primitive on the index axis — the
/// projection emerges from the boolean-guarded selection of the just-
/// lifted declaration-order complement witness-collection under the
/// set-level middle-band uniqueness bit, collapsing to the empty Vec
/// through the guard-arm when the bit falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_middle_band_variants(items) == if T::has_unique_middle_band_variant(items) { T::middle_band_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_middle_band_variants_equals_has_unique_middle_band_variant_gated_middle_band_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_middle_band_variants(items).len() == usize::from(T::has_unique_middle_band_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level middle-
/// band uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since when
/// `count_middle_band_variants == 1` the underlying
/// [`Self::middle_band_variants`] filter over [`Self::ALL`] admits
/// EXACTLY ONE variant). Independent cross-check on the surface axis
/// distinct from the guarded-witness-collection arm (length reduction
/// vs conditional Vec-select). Pinned by
/// `unique_middle_band_variants_len_equals_has_unique_middle_band_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_middle_band_variants(items).first().copied() == T::unique_middle_band_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both encode
/// the same "sole strict-interior witness if unique, else nothing"
/// semantics through different return shapes. Pinned by
/// `unique_middle_band_variants_first_equals_unique_middle_band_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_middle_band_variants(items).is_empty() == !T::has_unique_middle_band_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_middle_band_variants_is_empty_iff_not_has_unique_middle_band_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_middle_band_variant`] (ordering-agnostic — the
/// underlying [`Self::count_middle_band_variants`] is invariant under
/// slice-reversal) and [`Self::middle_band_variants`] (ordering-
/// agnostic on the input axis — the underlying max/min-fold pair +
/// [`Self::is_middle_band_variant_of`] filter over [`Self::ALL`] are
/// all invariant under slice-reversal) via a boolean-guarded Vec-
/// select. Pinned by
/// `unique_middle_band_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_middle_band_variants(&[]) == vec![]`
/// UNCONDITIONALLY — [`Self::has_unique_middle_band_variant`]
/// collapses to `false` via its `count_middle_band_variants(&[]) == 0
/// != 1` fixpoint, and the guard-arm short-circuit maps the empty
/// slice to the empty Vec before [`Self::middle_band_variants`]'s own
/// empty-Vec-at-empty branch is consulted.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::unique_middle_band_variants(&[v]) == vec![]` for every variant
/// `v` — the target hits count `1 == max`, every non-target sits at
/// count `0 == min`, EVERY variant sits AT one of the two extremes,
/// NO variant sits strictly between,
/// [`Self::count_middle_band_variants`] reports `0`,
/// [`Self::has_unique_middle_band_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_middle_band_variants(<T as ClosedSet>::ALL) == vec![]` +
/// `T::unique_middle_band_variants(&doubled) == vec![]` — on either
/// flat-histogram fixpoint max == min collapses the strict interior
/// to the empty set, [`Self::count_middle_band_variants`] reports
/// `0`, [`Self::has_unique_middle_band_variant`] returns `false`, and
/// the guard collapses the projection to `vec![]`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::unique_middle_band_variants([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == vec![T::ALL[1]]` — the LOAD-BEARING SOLE NON-EMPTY arm on the
/// canonical fixture window. `T::ALL[0]` sits at count `2 == max`,
/// `T::ALL[1]` at count `1` STRICTLY between max `2` and min `0` (the
/// SOLE strict-interior inhabitant), `T::ALL[2]` at count `0 == min`;
/// [`Self::count_middle_band_variants`] reports `1`,
/// [`Self::has_unique_middle_band_variant`] returns `true`, guard
/// fires, [`Self::middle_band_variants`]'s declaration-order sweep
/// hits `T::ALL[1]` as the sole surviving strict-interior witness,
/// and the guarded lift reports `vec![T::ALL[1]]`. LOAD-BEARING
/// DISCRIMINATOR from [`Self::unique_extremal_variants`] which
/// returns `vec![]` on the SAME fixture — the direction-composition
/// axis SEPARATES this COMPLEMENT positive arm from the UNION
/// degenerate arm on the shared canonical fixture window at
/// cardinality `>= 3`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::middle_band_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_middle_band_variants`] reduction for the guard, one
/// [`Self::middle_band_variants`] filter sweep when the guard holds;
/// the short-circuiting `if` avoids the filter sweep AND the Vec
/// allocation when the guard falsifies), no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_middle_band_variants`]: a `tatara-check` predicate
/// `(check-middle-band-if-unique …)` that reports the singleton-or-
/// empty strict-interior witness collection as a typed
/// `Vec<Self>`-return rather than a two-step (has-unique-middle-band-
/// variant? then middle-band-variants) composition; a Sekiban audit-
/// trail per-window singleton-or-empty binding that composes
/// uniformly with the six-Vec (union/complement/intersection ×
/// declaration/lex) rows through a shared Vec return shape;
/// downstream aggregate code that iterates over "the sole strict-
/// interior witness if any" without needing to dispatch on
/// Option/Vec at the callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-middle-band `Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set trait
/// rather than a per-consumer inline
/// `if T::has_unique_middle_band_variant(items) { T::middle_band_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V — the
/// (set-level × `Vec<Self>` × direction-composition × complement ×
/// unique-tie) witness-if-unique corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// strict-interior variant, as a Vec, if it's unambiguous" site pre-
/// lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_middle_band_variant`] +
/// [`Self::middle_band_variants`]) with the `if _ { _ } else { vec![] }`
/// combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); m <- max(t); n <- min(t); mid <- names(t)[t > n & t < m]; if (length(mid) == 1) mid else character(0) }`
/// — the canonical guarded strict-interior singleton-or-empty
/// carrier on a factor histogram; Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f)), ts (filter #(and (> (val %) n) (< (val %) m)) f)] (if (= 1 (count ts)) [(key (first ts))] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) > (SELECT MIN(c) FROM …) AND COUNT(*) < (SELECT MAX(c) FROM …)) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated complement singleton-or-empty projection on the
/// closed-set trait binds through the just-lifted
/// [`Self::has_unique_middle_band_variant`] guard conjoined with the
/// just-lifted [`Self::middle_band_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
///
/// Compounding closure: this projection CLOSES the complement arm of
/// the (set-level × `Vec<Self>` × direction-composition × combinator
/// × unique-tie) row past the just-opened UNION arm
/// [`Self::unique_extremal_variants`] one COMBINATOR axis over. The
/// natural next lift past this corner is the INTERSECTION arm
/// `unique_bimodal_variants` (guarded lift of
/// [`Self::bimodal_variants`] under
/// [`Self::has_unique_bimodal_variant`]) which EXHAUSTIVELY CLOSES
/// the (`Vec<Self>` × direction-composition × combinator × unique-
/// tie) 3-corner row at its FINAL THIRD tile.
fn unique_middle_band_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_middle_band_variant(items) {
<Self as ClosedSet>::middle_band_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique intersection-band witness as
/// a singleton-or-empty Vec" projection — returns
/// [`Self::bimodal_variants`] iff `items` has a UNIQUE intersection-band
/// witness ([`Self::has_unique_bimodal_variant`] holds — equivalently
/// the histogram is flat AND `T::CARDINALITY == 1`), else `vec![]`.
/// Computed as the just-lifted set-level intersection-band uniqueness
/// bit [`Self::has_unique_bimodal_variant`] guarding the declaration-
/// order intersection witness-collection [`Self::bimodal_variants`]:
/// when the guard holds the collection is already a length-`1` Vec by
/// the guard's own definition (`count_bimodal_variants == 1`) and is
/// lifted verbatim; when the guard falsifies the projection collapses
/// to the EMPTY Vec through a zero-allocation
/// `::std::vec::Vec::new()` short-circuit. The `Vec<Self>`-RETURN
/// UNIQUE-TIE SHARPENING corner CLOSING the intersection arm of the
/// (set-level × `Vec<Self>` × statistical-aggregate × direction-
/// composition × combinator × unique-tie) row past the just-opened
/// UNION arm [`Self::unique_extremal_variants`] AND the just-closed
/// COMPLEMENT arm [`Self::unique_middle_band_variants`] one COMBINATOR
/// axis over on the modal-aggregation matrix AND EXHAUSTIVELY CLOSING
/// the (`Vec<Self>` × direction-composition × combinator × unique-tie)
/// 3-corner row at its FINAL THIRD tile, peer to
/// [`Self::unique_bimodal_variant`] (set-level × `Option<Self>` ×
/// intersection × unique-tie) one RETURN-SHAPE axis over (Option-
/// return witness-when-unique → Vec-return singleton-or-empty-when-
/// unique) AND peer to [`Self::has_unique_bimodal_variant`]
/// (set-level × `bool` × intersection × unique-tie) one RETURN-SHAPE
/// axis over (bool uniqueness bit → Vec-return singleton-or-empty
/// carrier of the same bit). Not a fresh substrate primitive on the
/// index axis — the projection emerges from the boolean-guarded
/// selection of the just-lifted declaration-order intersection
/// witness-collection under the set-level intersection-band uniqueness
/// bit, collapsing to the empty Vec through the guard-arm when the
/// bit falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_bimodal_variants(items) == if T::has_unique_bimodal_variant(items) { T::bimodal_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_bimodal_variants_equals_has_unique_bimodal_variant_gated_bimodal_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_bimodal_variants(items).len() == usize::from(T::has_unique_bimodal_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level intersection-
/// band uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since
/// `has_unique_bimodal_variant` holds only when
/// `count_bimodal_variants == 1`, and the guarded lift of
/// [`Self::bimodal_variants`] admits EXACTLY ONE variant on that
/// arm). Independent cross-check on the surface axis distinct from
/// the guarded-witness-collection arm (length reduction vs
/// conditional Vec-select). Pinned by
/// `unique_bimodal_variants_len_equals_has_unique_bimodal_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_bimodal_variants(items).first().copied() == T::unique_bimodal_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both encode
/// the same "sole intersection-band witness if unique, else nothing"
/// semantics through different return shapes. Pinned by
/// `unique_bimodal_variants_first_equals_unique_bimodal_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_bimodal_variants(items).is_empty() == !T::has_unique_bimodal_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_bimodal_variants_is_empty_iff_not_has_unique_bimodal_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_bimodal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_bimodal_variants`] is invariant under
/// slice-reversal via the uniformity-collapse dichotomy) and
/// [`Self::bimodal_variants`] (ordering-agnostic on the input axis —
/// the underlying [`Self::is_uniform`] gate + `T::ALL.to_vec()` /
/// `Vec::new()` dichotomy are all invariant under slice-reversal) via
/// a boolean-guarded Vec-select. Pinned by
/// `unique_bimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_bimodal_variants(&[]) == vec![]`
/// UNCONDITIONALLY — [`Self::has_unique_bimodal_variant`] collapses
/// to `false` via its `count_bimodal_variants(&[]) == 0 != 1`
/// fixpoint (the empty-slice guard on [`Self::bimodal_variants`]
/// short-circuits BEFORE the uniformity gate is consulted so the
/// vacuous flat-histogram `is_uniform(&[]) == true` doesn't leak
/// into the count), and the guard-arm maps the empty slice to the
/// empty Vec directly.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::unique_bimodal_variants(&[v]) == vec![]` for every variant
/// `v` — the target hits count `1 == max`, every non-target sits at
/// count `0 == min`, the histogram is non-flat (max `1` != min `0`),
/// [`Self::is_uniform`] returns `false`,
/// [`Self::bimodal_variants`] collapses to `Vec::new()`,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Full-set contract: `T::unique_bimodal_variants(<T as ClosedSet>::ALL) ==
/// (if T::CARDINALITY == 1 { T::ALL.to_vec() } else { vec![] })` —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// at exactly one position, [`Self::max_variant_count`] ==
/// [`Self::min_variant_count`] == 1 on the flat-histogram fixpoint,
/// [`Self::is_uniform`] returns `true`,
/// [`Self::bimodal_variants`] admits EVERY variant via the
/// (max == min == 1) collapse, and
/// [`Self::count_bimodal_variants`] reports `T::CARDINALITY`.
/// [`Self::has_unique_bimodal_variant`] then holds iff
/// `T::CARDINALITY == 1`, and the guarded lift returns
/// `T::ALL.to_vec()` (a length-`1` Vec) on that arm and `vec![]` on
/// every `T::CARDINALITY >= 2` arm. LOAD-BEARING singleton-carrier
/// positive fixpoint at `T::CARDINALITY == 1` — the ONLY positive
/// arm on this corner across any test-module carrier.
///
/// Doubled-full-set contract:
/// `T::unique_bimodal_variants(&doubled) ==
/// (if T::CARDINALITY == 1 { T::ALL.to_vec() } else { vec![] })` —
/// the second flat-histogram fixpoint (max == min == 2) folds through
/// the same uniformity-collapse dichotomy as the full-set arm; the
/// projection returns `T::ALL.to_vec()` at `T::CARDINALITY == 1`
/// (`bimodal_variants` = [T::ALL[0]] via the flat-histogram fixpoint)
/// and `vec![]` at `T::CARDINALITY >= 2`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::unique_bimodal_variants([T::ALL[0], T::ALL[0], T::ALL[1]]) == vec![]`
/// — the histogram is (T::ALL[0] -> 2 == max, T::ALL[1] -> 1 ==
/// MIDDLE, T::ALL[2..] -> 0 == min); non-flat (max `2` != min `0`),
/// [`Self::is_uniform`] returns `false`,
/// [`Self::bimodal_variants`] reports `Vec::new()`,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`. LOAD-BEARING
/// DISCRIMINATOR from [`Self::unique_middle_band_variants`] which
/// reports `vec![T::ALL[1]]` on the SAME fixture — the direction-
/// composition axis SEPARATES this INTERSECTION degenerate arm
/// from the COMPLEMENT positive arm on the shared canonical
/// fixture window at cardinality `>= 3`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_bimodal_variant`] +
/// [`Self::bimodal_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_bimodal_variants`] reduction for the guard via
/// the uniformity-collapse dichotomy, one
/// [`Self::bimodal_variants`] dichotomy sweep when the guard holds;
/// the short-circuiting `if` avoids the sweep AND the Vec allocation
/// when the guard falsifies), no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait
/// pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_bimodal_variants`]: a `tatara-check` predicate
/// `(check-bimodal-if-unique …)` that reports the singleton-or-
/// empty flat-diagonal witness collection as a typed
/// `Vec<Self>`-return rather than a two-step (has-unique-bimodal-
/// variant? then bimodal-variants) composition; a Sekiban audit-
/// trail per-window singleton-or-empty binding that composes
/// uniformly with the six-Vec (union/complement/intersection ×
/// declaration/lex) rows through a shared Vec return shape;
/// downstream aggregate code that iterates over "the sole flat-
/// diagonal witness if any" without needing to dispatch on
/// Option/Vec at the callsite; a scheduler-fairness heuristic that
/// branches on "is the workload distribution perfectly flat over a
/// single dispatch class in this window?" through one typed Vec-
/// return primitive.
///
/// Compounding closure: this projection CLOSES the intersection arm
/// of the (set-level × `Vec<Self>` × direction-composition ×
/// combinator × unique-tie) row past the just-opened UNION arm
/// [`Self::unique_extremal_variants`] AND the just-closed COMPLEMENT
/// arm [`Self::unique_middle_band_variants`] one COMBINATOR axis
/// over AND EXHAUSTIVELY CLOSES the (`Vec<Self>` × direction-
/// composition × combinator × unique-tie) 3-corner row at its FINAL
/// THIRD tile. The (set-level × Vec × direction-composition ×
/// combinator × unique-tie) row is now EXHAUSTIVELY closed; the
/// natural next lift past this row is the LEX-order peer trio
/// (`sorted_unique_extremal_variants`,
/// `sorted_unique_middle_band_variants`,
/// `sorted_unique_bimodal_variants`) opening the (`Vec<Self>` ×
/// sorted × unique-tie) column one ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-bimodal `Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set
/// trait rather than a per-consumer inline
/// `if T::has_unique_bimodal_variant(items) { T::bimodal_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V — the
/// (set-level × `Vec<Self>` × direction-composition × intersection ×
/// unique-tie) witness-if-unique corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// flat-diagonal variant, as a Vec, if it's unambiguous" site pre-
/// lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_bimodal_variant`] +
/// [`Self::bimodal_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); if (length(unique(t)) == 1 && length(t) == 1) names(t) else character(0) }`
/// — the canonical guarded flat-diagonal singleton-or-empty
/// carrier on a factor histogram; Julia's
/// `let c = StatsBase.countmap(items); if length(c) == 1 && length(unique(values(c))) == 1 collect(keys(c)) else eltype(items)[] end`;
/// Python's
/// `list(c.keys()) if len(c) == 1 and len(set(c.values())) == 1 else []`
/// on a `collections.Counter`; Clojure's
/// `(let [f (frequencies coll)] (if (and (= 1 (count f)) (apply = (vals f))) (keys f) ()))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING (SELECT COUNT(DISTINCT c) FROM …) = 1 AND (SELECT COUNT(*) FROM …) = 1)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated intersection singleton-or-empty projection on
/// the closed-set trait binds through the just-lifted
/// [`Self::has_unique_bimodal_variant`] guard conjoined with the
/// just-lifted [`Self::bimodal_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_bimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_bimodal_variant(items) {
<Self as ClosedSet>::bimodal_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "unique extremal witnesses in LEX order,
/// as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_extremal_variants`] iff `items` has a UNIQUE extremum
/// ([`Self::has_unique_extremal_variant`] holds), else `vec![]`.
/// Computed as the just-lifted set-level extremal uniqueness bit
/// [`Self::has_unique_extremal_variant`] guarding the LEX-ORDER union
/// witness-collection [`Self::sorted_extremal_variants`]: when the guard
/// holds the collection is already a length-`1` Vec by the guard's own
/// definition (`count_extremal_variants == 1`) and is lifted verbatim;
/// when the guard falsifies the projection collapses to the EMPTY Vec
/// through a zero-allocation `::std::vec::Vec::new()` short-circuit.
/// The LEX-ORDER `Vec<Self>`-RETURN UNIQUE-TIE SHARPENING corner
/// OPENING the LEX-ORDER (`Vec<Self>` × direction-composition ×
/// combinator × unique-tie) row past the just-closed declaration-order
/// trio ([`Self::unique_extremal_variants`],
/// [`Self::unique_middle_band_variants`],
/// [`Self::unique_bimodal_variants`]) one ORDERING axis over on the
/// modal-aggregation matrix, peer to [`Self::unique_extremal_variants`]
/// one ORDERING axis over (declaration-order → lex-order union
/// witness-collection-when-unique) AND peer to
/// [`Self::sorted_extremal_variants`] one UNIQUE-TIE-SHARPENING axis
/// over (unsharpened lex-order union witness-collection →
/// uniqueness-gated lex-order union witness-collection) AND peer to
/// [`Self::sorted_unique_extremal_variant`] one RETURN-SHAPE axis over
/// (Option-return lex-first-witness-when-unique → Vec-return
/// singleton-or-empty-when-unique). Not a fresh substrate primitive on
/// the index axis — the projection emerges from the boolean-guarded
/// selection of the just-lifted lex-order union witness-collection
/// under the set-level extremal uniqueness bit, collapsing to the
/// empty Vec through the guard-arm when the bit falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_extremal_variants(items) ==
/// T::unique_extremal_variants(items)` — when the sole extremum is
/// UNIQUE ([`Self::has_unique_extremal_variant`] holds) the underlying
/// [`Self::sorted_extremal_variants`] and
/// [`Self::extremal_variants`] each collapse to a length-`1` Vec
/// containing THE SAME sole extremal variant (uniqueness pins the sole
/// witness before any ordering choice is consulted); when the guard
/// falsifies both projections collapse to `vec![]` through the same
/// guard arm. The LEX peer is thus IDENTICALLY equal to its
/// declaration-order sibling on every input — the search-order axis
/// becomes provably irrelevant WHEN the underlying uniqueness bit
/// holds. Pinned by
/// `sorted_unique_extremal_variants_equals_unique_extremal_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-consumer
/// inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_extremal_variants(items) ==
/// if T::has_unique_extremal_variant(items) { T::sorted_extremal_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_extremal_variants_equals_has_unique_extremal_variant_gated_sorted_extremal_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_extremal_variants(items).len() ==
/// usize::from(T::has_unique_extremal_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level extremal uniqueness bit
/// projected onto `usize`: exactly `0` when the bit falsifies, exactly
/// `1` when it holds. Pinned by
/// `sorted_unique_extremal_variants_len_equals_has_unique_extremal_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_extremal_variants(items).first().copied() ==
/// T::sorted_unique_extremal_variant(items)` — the `Vec`-return's
/// first-element projection COINCIDES with the `Option`-return LEX
/// peer one RETURN-SHAPE axis over, since both encode the same "sole
/// extremal witness if unique, else nothing" semantics through
/// different return shapes. Pinned by
/// `sorted_unique_extremal_variants_first_equals_sorted_unique_extremal_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_extremal_variants(items).is_empty() ==
/// !T::has_unique_extremal_variant(items)` — the return-Vec's
/// emptiness coincides with the NEGATION of the set-level uniqueness
/// bit. Independent cross-check on the surface axis distinct from the
/// length-coincidence arm (Vec::is_empty vs integer equality). Pinned
/// by
/// `sorted_unique_extremal_variants_is_empty_iff_not_has_unique_extremal_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_extremal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_extremal_variants`] is invariant under
/// slice-reversal) and [`Self::sorted_extremal_variants`]
/// (ordering-agnostic on the input axis — the underlying max/min-fold
/// pair + [`Self::count_occurrences_of`] filter sweep over
/// [`Self::sorted_variants`] are all invariant under slice-reversal)
/// via a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_extremal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_extremal_variants(&[]) ==
/// vec![]` UNCONDITIONALLY — [`Self::has_unique_extremal_variant`]
/// collapses to `false` via `count_extremal_variants(&[]) == 0 != 1`,
/// and the guard-arm short-circuit maps the empty slice to the empty
/// Vec before [`Self::sorted_extremal_variants`]'s own empty-Vec-at-
/// empty branch is consulted.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_extremal_variants(&[v]) == vec![]` for every
/// variant `v` — argmax `{v}` and argmin `T::ALL \ {v}` are DISJOINT
/// at cardinality `>= 2`, [`Self::count_extremal_variants`] reports
/// `T::CARDINALITY >= 2`, [`Self::has_unique_extremal_variant`]
/// returns `false`, and the guard collapses the projection to
/// `vec![]`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::sorted_unique_extremal_variants(<T as ClosedSet>::ALL) ==
/// vec![]` + `T::sorted_unique_extremal_variants(&doubled) == vec![]`
/// — on either flat-histogram fixpoint every variant sits at BOTH
/// extremes via the (max == min) collapse,
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_extremal_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::sorted_unique_extremal_variants([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == vec![]` — argmax `{T::ALL[0]}` at count `2` and
/// argmin `T::ALL[2..]` at count `0` are disjoint,
/// [`Self::count_extremal_variants`] reports `T::CARDINALITY - 1 >=
/// 2`, [`Self::has_unique_extremal_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_extremal_variant`] +
/// [`Self::sorted_extremal_variants`] via a boolean-guarded Vec-
/// select on `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_extremal_variants`] reduction for the guard, one
/// [`Self::sorted_extremal_variants`] filter sweep over
/// [`Self::sorted_variants`] when the guard holds; the short-
/// circuiting `if` avoids the sweep AND the Vec allocation when the
/// guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_extremal_variants`]: a `tatara-check`
/// predicate `(check-extremal-if-unique-lex …)` that reports the
/// singleton-or-empty lex-order union witness collection as a typed
/// `Vec<Self>`-return rather than a two-step composition; a Sekiban
/// audit-trail per-window singleton-or-empty binding stable against
/// upstream declaration-order churn.
///
/// Compounding closure: this projection OPENS the LEX-ORDER
/// (`Vec<Self>` × direction-composition × combinator × unique-tie)
/// row past the just-closed declaration-order trio one ORDERING axis
/// over. The natural next lifts past this corner are the complement
/// arm `sorted_unique_middle_band_variants` (guarded lift of
/// [`Self::sorted_middle_band_variants`] under
/// [`Self::has_unique_middle_band_variant`]) and the intersection
/// arm `sorted_unique_bimodal_variants` (guarded lift of
/// [`Self::sorted_bimodal_variants`] under
/// [`Self::has_unique_bimodal_variant`]) which together EXHAUSTIVELY
/// CLOSE the (`Vec<Self>` × direction-composition × combinator ×
/// ordering × unique-tie) 3×2 face at its final two lex tiles.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Vec<Self>` × sorted × statistical-aggregate ×
/// direction-composition × union × unique-tie) corner becomes a
/// TYPED WITNESS on the ClosedSet trait rather than a per-consumer
/// inline
/// `if T::has_unique_extremal_variant(items) { T::sorted_extremal_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Vec<Self>` × direction-composition × union ×
/// unique-tie) corner was an unnamed inline composition — or
/// silently absent because callers reached for the declaration-order
/// sibling without proof of coincidence — recurring at every
/// prospective downstream "the sole extremal, as a Vec, in lex order,
/// if it's unambiguous" site pre-lift. THEORY.md §VI.1 — generation
/// over composition; the projection emerges from the composition of
/// TWO substrate primitives ([`Self::has_unique_extremal_variant`] +
/// [`Self::sorted_extremal_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); m <- max(t); n <- min(t); s <- sort(names(t)[t == m | t == n]); if (length(s) == 1) s else character(0) }`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f)), ts (sort (filter #(or (= (val %) m) (= (val %) n)) f))] (if (= 1 (count ts)) [(key (first ts))] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) IN (SELECT MAX(c), MIN(c) FROM …) ORDER BY variant) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order union singleton-or-empty projection on
/// the closed-set trait binds through the just-lifted
/// [`Self::has_unique_extremal_variant`] guard conjoined with the
/// just-lifted [`Self::sorted_extremal_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn sorted_unique_extremal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_extremal_variant(items) {
<Self as ClosedSet>::sorted_extremal_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "unique middle-band witnesses in LEX order,
/// as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_middle_band_variants`] iff `items` has a UNIQUE strict-
/// interior variant ([`Self::has_unique_middle_band_variant`] holds), else
/// `vec![]`. Computed as the just-lifted set-level middle-band uniqueness
/// bit [`Self::has_unique_middle_band_variant`] guarding the LEX-ORDER
/// complement witness-collection [`Self::sorted_middle_band_variants`]:
/// when the guard holds the collection is already a length-`1` Vec by the
/// guard's own definition (`count_middle_band_variants == 1`) and is
/// lifted verbatim; when the guard falsifies the projection collapses to
/// the EMPTY Vec through a zero-allocation `::std::vec::Vec::new()`
/// short-circuit. The LEX-ORDER `Vec<Self>`-RETURN COMPLEMENT UNIQUE-TIE
/// SHARPENING corner CLOSING the complement arm of the LEX-ORDER
/// (`Vec<Self>` × direction-composition × combinator × unique-tie) row
/// past the just-opened union arm [`Self::sorted_unique_extremal_variants`]
/// one COMBINATOR axis over on the modal-aggregation matrix, peer to
/// [`Self::unique_middle_band_variants`] one ORDERING axis over
/// (declaration-order → lex-order complement witness-collection-when-
/// unique) AND peer to [`Self::sorted_middle_band_variants`] one UNIQUE-
/// TIE-SHARPENING axis over (unsharpened lex-order complement witness-
/// collection → uniqueness-gated lex-order complement witness-collection)
/// AND peer to [`Self::sorted_unique_middle_band_variant`] one RETURN-
/// SHAPE axis over (Option-return lex-first-witness-when-unique → Vec-
/// return singleton-or-empty-when-unique). Not a fresh substrate primitive
/// on the index axis — the projection emerges from the boolean-guarded
/// selection of the just-lifted lex-order complement witness-collection
/// under the set-level middle-band uniqueness bit, collapsing to the
/// empty Vec through the guard-arm when the bit falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variants(items) ==
/// T::unique_middle_band_variants(items)` — when the sole strict-interior
/// variant is UNIQUE ([`Self::has_unique_middle_band_variant`] holds) the
/// underlying [`Self::sorted_middle_band_variants`] and
/// [`Self::middle_band_variants`] each collapse to a length-`1` Vec
/// containing THE SAME sole strict-interior variant (uniqueness pins the
/// sole witness before any ordering choice is consulted); when the guard
/// falsifies both projections collapse to `vec![]` through the same guard
/// arm. The LEX peer is thus IDENTICALLY equal to its declaration-order
/// sibling on every input — the search-order axis becomes provably
/// irrelevant WHEN the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_middle_band_variants_equals_unique_middle_band_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-consumer
/// inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variants(items) ==
/// if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_middle_band_variants_equals_has_unique_middle_band_variant_gated_sorted_middle_band_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variants(items).len() ==
/// usize::from(T::has_unique_middle_band_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level middle-band uniqueness bit
/// projected onto `usize`: exactly `0` when the bit falsifies, exactly
/// `1` when it holds. Pinned by
/// `sorted_unique_middle_band_variants_len_equals_has_unique_middle_band_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variants(items).first().copied() ==
/// T::sorted_unique_middle_band_variant(items)` — the `Vec`-return's
/// first-element projection COINCIDES with the `Option`-return LEX peer
/// one RETURN-SHAPE axis over, since both encode the same "sole strict-
/// interior witness if unique, else nothing" semantics through different
/// return shapes. Pinned by
/// `sorted_unique_middle_band_variants_first_equals_sorted_unique_middle_band_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_middle_band_variants(items).is_empty() ==
/// !T::has_unique_middle_band_variant(items)` — the return-Vec's
/// emptiness coincides with the NEGATION of the set-level uniqueness bit.
/// Independent cross-check on the surface axis distinct from the length-
/// coincidence arm (Vec::is_empty vs integer equality). Pinned by
/// `sorted_unique_middle_band_variants_is_empty_iff_not_has_unique_middle_band_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_middle_band_variant`] (ordering-agnostic — the
/// underlying [`Self::count_middle_band_variants`] is invariant under
/// slice-reversal) and [`Self::sorted_middle_band_variants`] (ordering-
/// agnostic on the input axis — the underlying max/min-fold pair +
/// [`Self::count_occurrences_of`] filter sweep over
/// [`Self::sorted_variants`] are all invariant under slice-reversal) via
/// a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_middle_band_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_middle_band_variants(&[]) ==
/// vec![]` UNCONDITIONALLY — [`Self::has_unique_middle_band_variant`]
/// collapses to `false` via `count_middle_band_variants(&[]) == 0 != 1`,
/// and the guard-arm short-circuit maps the empty slice to the empty Vec
/// before [`Self::sorted_middle_band_variants`]'s own empty-Vec-at-empty
/// branch is consulted.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_middle_band_variants(&[v]) == vec![]` for every
/// variant `v` — the target hits count `1 == max`, every non-target sits
/// at count `0 == min`, EVERY variant sits AT one of the two extremes,
/// NO variant sits strictly between, [`Self::count_middle_band_variants`]
/// reports `0`, [`Self::has_unique_middle_band_variant`] returns `false`,
/// and the guard collapses the projection to `vec![]`.
///
/// Full-set + doubled-full-set contract at cardinality `>= 2`:
/// `T::sorted_unique_middle_band_variants(<T as ClosedSet>::ALL) ==
/// vec![]` + `T::sorted_unique_middle_band_variants(&doubled) == vec![]`
/// — on either flat-histogram fixpoint max == min collapses the union
/// band to every variant simultaneously, NO variant sits strictly
/// between, [`Self::count_middle_band_variants`] reports `0`,
/// [`Self::has_unique_middle_band_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`. LOAD-BEARING structural
/// symmetry to the union corner clause (191) whose flat-histogram arms
/// ALSO collapse to `vec![]` via the mirror-image `T::CARDINALITY >= 2`
/// uniqueness-failure path (union band = every variant vs middle band =
/// no variant — the same `has_unique_*` falsification with opposite
/// direction-composition polarity).
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::sorted_unique_middle_band_variants([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == vec![T::ALL[1]]` — the LOAD-BEARING SOLE non-empty
/// arm on the canonical fixture window. `T::ALL[0]` sits at count `2 ==
/// max`, `T::ALL[1]` at count `1` STRICTLY between max `2` and min `0`
/// (the SOLE strict-interior inhabitant), `T::ALL[2..]` at count `0 ==
/// min`; [`Self::count_middle_band_variants`] reports `1`,
/// [`Self::has_unique_middle_band_variant`] returns `true`, the guard
/// fires, and [`Self::sorted_middle_band_variants`]'s lex-order sweep
/// hits `T::ALL[1]` as its sole tie-member. LOAD-BEARING DISCRIMINATOR
/// from clause (191)'s union counterpart which reports `vec![]` on the
/// SAME fixture (union carries the two disjoint extremes but has NO
/// unique extremum since `count_extremal_variants == T::CARDINALITY - 1
/// >= 2`) — the direction-composition axis SEPARATES this COMPLEMENT
/// positive arm from the UNION degenerate arm on the shared canonical
/// fixture window at cardinality `>= 3`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::sorted_middle_band_variants`] via a boolean-guarded Vec-
/// select on `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_middle_band_variants`] reduction for the guard via the
/// De Morgan complement of [`Self::count_extremal_variants`], one
/// [`Self::sorted_middle_band_variants`] filter sweep over
/// [`Self::sorted_variants`] when the guard holds; the short-circuiting
/// `if` avoids the sweep AND the Vec allocation when the guard
/// falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_middle_band_variants`]: a `tatara-check`
/// predicate `(check-middle-band-if-unique-lex …)` that reports the
/// singleton-or-empty lex-order complement witness collection as a
/// typed `Vec<Self>`-return rather than a two-step composition; a
/// Sekiban audit-trail per-window singleton-or-empty binding stable
/// against upstream declaration-order churn.
///
/// Compounding closure: this projection CLOSES the complement arm of
/// the LEX-ORDER (`Vec<Self>` × direction-composition × combinator ×
/// unique-tie) row past the just-opened UNION arm
/// [`Self::sorted_unique_extremal_variants`] one COMBINATOR axis over.
/// The natural next lift past this corner is the intersection arm
/// `sorted_unique_bimodal_variants` (guarded lift of
/// [`Self::sorted_bimodal_variants`] under
/// [`Self::has_unique_bimodal_variant`]) which EXHAUSTIVELY CLOSES the
/// (`Vec<Self>` × direction-composition × combinator × ordering ×
/// unique-tie) 3×2 face at its FINAL sixth tile.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Vec<Self>` × sorted × statistical-aggregate ×
/// direction-composition × complement × unique-tie) corner becomes a
/// TYPED WITNESS on the ClosedSet trait rather than a per-consumer
/// inline
/// `if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Vec<Self>` × direction-composition × complement ×
/// unique-tie) corner was an unnamed inline composition — or silently
/// absent because callers reached for the declaration-order sibling
/// without proof of coincidence — recurring at every prospective
/// downstream "the sole strict-interior variant, as a Vec, in lex
/// order, if it's unambiguous" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::has_unique_middle_band_variant`] +
/// [`Self::sorted_middle_band_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); m <- max(t); n <- min(t); s <- sort(names(t)[t != m & t != n]); if (length(s) == 1) s else character(0) }`;
/// Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply min (vals f)), ts (sort (keys (filter #(and (not= (val %) m) (not= (val %) n)) f)))] (if (= 1 (count ts)) [(first ts)] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) NOT IN (SELECT MAX(c) FROM …) AND COUNT(*) NOT IN (SELECT MIN(c) FROM …) ORDER BY variant) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order complement singleton-or-empty projection
/// on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_middle_band_variant`] guard conjoined with the
/// just-lifted [`Self::sorted_middle_band_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn sorted_unique_middle_band_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_middle_band_variant(items) {
<Self as ClosedSet>::sorted_middle_band_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique intersection-band witness in
/// LEX order, as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_bimodal_variants`] iff `items` has a UNIQUE intersection-
/// band witness ([`Self::has_unique_bimodal_variant`] holds — equivalently
/// the histogram is flat AND `T::CARDINALITY == 1`), else `vec![]`.
/// Computed as the just-lifted set-level intersection-band uniqueness bit
/// [`Self::has_unique_bimodal_variant`] guarding the LEX-ORDER intersection
/// witness-collection [`Self::sorted_bimodal_variants`]: when the guard
/// holds the collection is already a length-`1` Vec by the guard's own
/// definition (`count_bimodal_variants == 1`) and is lifted verbatim; when
/// the guard falsifies the projection collapses to the EMPTY Vec through a
/// zero-allocation `::std::vec::Vec::new()` short-circuit. The LEX-ORDER
/// `Vec<Self>`-RETURN INTERSECTION UNIQUE-TIE SHARPENING corner CLOSING
/// the intersection arm of the LEX-ORDER (`Vec<Self>` × direction-
/// composition × combinator × unique-tie) row past the just-opened UNION
/// arm [`Self::sorted_unique_extremal_variants`] AND the just-closed
/// COMPLEMENT arm [`Self::sorted_unique_middle_band_variants`] one
/// COMBINATOR axis over on the modal-aggregation matrix AND EXHAUSTIVELY
/// CLOSING the (set-level × `Vec<Self>` × direction-composition ×
/// combinator × ordering × unique-tie) 3×2 face at its FINAL SIXTH TILE,
/// peer to [`Self::unique_bimodal_variants`] one ORDERING axis over
/// (declaration-order → lex-order intersection witness-collection-when-
/// unique) AND peer to [`Self::sorted_bimodal_variants`] one UNIQUE-TIE-
/// SHARPENING axis over (unsharpened lex-order intersection witness-
/// collection → uniqueness-gated lex-order intersection witness-
/// collection) AND peer to [`Self::sorted_unique_bimodal_variant`] one
/// RETURN-SHAPE axis over (Option-return lex-first-witness-when-unique →
/// Vec-return singleton-or-empty-when-unique). Not a fresh substrate
/// primitive on the index axis — the projection emerges from the boolean-
/// guarded selection of the just-lifted lex-order intersection witness-
/// collection under the set-level intersection-band uniqueness bit,
/// collapsing to the empty Vec through the guard-arm when the bit
/// falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variants(items) ==
/// T::unique_bimodal_variants(items)` — when the sole intersection-band
/// witness is UNIQUE ([`Self::has_unique_bimodal_variant`] holds) the
/// underlying [`Self::sorted_bimodal_variants`] and
/// [`Self::bimodal_variants`] each collapse to a length-`1` Vec containing
/// THE SAME sole intersection-band witness (uniqueness forces
/// `T::CARDINALITY == 1`, and at cardinality `1` the sorted-variants
/// projection agrees byte-for-byte with the declaration-order projection
/// on a one-element carrier); when the guard falsifies both projections
/// collapse to `vec![]` through the same guard arm. The LEX peer is thus
/// IDENTICALLY equal to its declaration-order sibling on every input —
/// the search-order axis becomes provably irrelevant WHEN the underlying
/// uniqueness bit holds. Pinned by
/// `sorted_unique_bimodal_variants_equals_unique_bimodal_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-consumer
/// inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variants(items) ==
/// if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_bimodal_variants_equals_has_unique_bimodal_variant_gated_sorted_bimodal_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variants(items).len() ==
/// usize::from(T::has_unique_bimodal_variant(items))` — the return-Vec's
/// length COINCIDES with the set-level intersection-band uniqueness bit
/// projected onto `usize`: exactly `0` when the bit falsifies, exactly
/// `1` when it holds. Pinned by
/// `sorted_unique_bimodal_variants_len_equals_has_unique_bimodal_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variants(items).first().copied() ==
/// T::sorted_unique_bimodal_variant(items)` — the `Vec`-return's first-
/// element projection COINCIDES with the `Option`-return LEX peer one
/// RETURN-SHAPE axis over, since both encode the same "sole intersection-
/// band witness if unique, else nothing" semantics through different
/// return shapes. Pinned by
/// `sorted_unique_bimodal_variants_first_equals_sorted_unique_bimodal_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_bimodal_variants(items).is_empty() ==
/// !T::has_unique_bimodal_variant(items)` — the return-Vec's emptiness
/// coincides with the NEGATION of the set-level uniqueness bit.
/// Independent cross-check on the surface axis distinct from the length-
/// coincidence arm (Vec::is_empty vs integer equality). Pinned by
/// `sorted_unique_bimodal_variants_is_empty_iff_not_has_unique_bimodal_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_bimodal_variant`] (ordering-agnostic — the
/// underlying [`Self::count_bimodal_variants`] is invariant under slice-
/// reversal via the uniformity-collapse dichotomy) and
/// [`Self::sorted_bimodal_variants`] (ordering-agnostic on the input axis
/// — the underlying [`Self::is_uniform`] gate + [`Self::sorted_variants`]
/// / `Vec::new()` dichotomy are all invariant under slice-reversal) via
/// a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_bimodal_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_bimodal_variants(&[]) ==
/// vec![]` UNCONDITIONALLY — [`Self::has_unique_bimodal_variant`]
/// collapses to `false` via its `count_bimodal_variants(&[]) == 0 != 1`
/// fixpoint (the empty-slice guard on [`Self::sorted_bimodal_variants`]
/// short-circuits BEFORE the uniformity gate is consulted so the vacuous
/// `is_uniform(&[]) == true` doesn't leak into the count), and the guard-
/// arm maps the empty slice to the empty Vec directly.
///
/// Matching-singleton contract at cardinality `>= 2`:
/// `T::sorted_unique_bimodal_variants(&[v]) == vec![]` for every variant
/// `v` — the target hits count `1 == max`, every non-target sits at
/// count `0 == min`, the histogram is non-flat (max `1` != min `0`),
/// [`Self::is_uniform`] returns `false`,
/// [`Self::sorted_bimodal_variants`] collapses to `Vec::new()`,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the guard
/// collapses the projection to `vec![]`.
///
/// Full-set contract: `T::sorted_unique_bimodal_variants(<T as ClosedSet>::ALL) ==
/// (if T::CARDINALITY == 1 { T::sorted_variants() } else { vec![] })` —
/// clause (3)'s pairwise-distinctness invariant pins every variant at
/// exactly one position, the flat histogram (max == min == 1) fires
/// [`Self::is_uniform`], [`Self::sorted_bimodal_variants`] admits EVERY
/// variant in lex order via the uniformity-collapse dichotomy, and
/// [`Self::count_bimodal_variants`] reports `T::CARDINALITY`.
/// [`Self::has_unique_bimodal_variant`] then holds iff
/// `T::CARDINALITY == 1`, and the guarded lift returns
/// [`Self::sorted_variants`] (a length-`1` Vec) on that arm and `vec![]`
/// on every `T::CARDINALITY >= 2` arm. LOAD-BEARING singleton-carrier
/// positive fixpoint at `T::CARDINALITY == 1` — the ONLY positive arm on
/// this corner across any test-module carrier.
///
/// Doubled-full-set contract:
/// `T::sorted_unique_bimodal_variants(&doubled) ==
/// (if T::CARDINALITY == 1 { T::sorted_variants() } else { vec![] })` —
/// the second flat-histogram fixpoint (max == min == 2) folds through the
/// same uniformity-collapse dichotomy as the full-set arm; the projection
/// returns [`Self::sorted_variants`] at `T::CARDINALITY == 1` and
/// `vec![]` at `T::CARDINALITY >= 2`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::sorted_unique_bimodal_variants([T::ALL[0], T::ALL[0], T::ALL[1]]) == vec![]`
/// — the histogram is (T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE,
/// T::ALL[2..] -> 0 == min); non-flat (max `2` != min `0`),
/// [`Self::is_uniform`] returns `false`,
/// [`Self::sorted_bimodal_variants`] reports `Vec::new()`,
/// [`Self::count_bimodal_variants`] reports `0`,
/// [`Self::has_unique_bimodal_variant`] returns `false`, and the guard
/// collapses the projection to `vec![]`. LOAD-BEARING DISCRIMINATOR from
/// [`Self::sorted_unique_middle_band_variants`] which reports
/// `vec![T::ALL[1]]` on the SAME fixture — the direction-composition axis
/// SEPARATES this INTERSECTION degenerate arm from the COMPLEMENT
/// positive arm on the shared canonical fixture window at cardinality
/// `>= 3`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_bimodal_variant`] +
/// [`Self::sorted_bimodal_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_bimodal_variants`] reduction for the guard via the
/// uniformity-collapse dichotomy, one [`Self::sorted_bimodal_variants`]
/// dichotomy over [`Self::sorted_variants`] when the guard holds; the
/// short-circuiting `if` avoids the sweep AND the Vec allocation when the
/// guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static` supertrait pair
/// stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_bimodal_variants`]: a `tatara-check` predicate
/// `(check-bimodal-if-unique-lex …)` that reports the singleton-or-empty
/// lex-order intersection witness collection as a typed `Vec<Self>`-
/// return rather than a two-step composition; a Sekiban audit-trail per-
/// window singleton-or-empty binding stable against upstream declaration-
/// order churn.
///
/// Compounding closure: this projection CLOSES the intersection arm of
/// the LEX-ORDER (`Vec<Self>` × direction-composition × combinator ×
/// unique-tie) row past the just-opened UNION arm
/// [`Self::sorted_unique_extremal_variants`] AND the just-closed
/// COMPLEMENT arm [`Self::sorted_unique_middle_band_variants`] one
/// COMBINATOR axis over AND EXHAUSTIVELY CLOSES the (set-level ×
/// `Vec<Self>` × direction-composition × combinator × ordering × unique-
/// tie) 3×2 face at its FINAL SIXTH TILE. The natural next lift past this
/// corner opens the (per-target × `bool` × direction-composition × unique-
/// tie × ordering) column via the LEX-ORDER peer of the just-lifted per-
/// target extremal / middle-band / bimodal unique-tie predicates.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the (set-
/// level × `Vec<Self>` × sorted × statistical-aggregate × direction-
/// composition × intersection × unique-tie) corner becomes a TYPED
/// WITNESS on the ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once. THEORY.md §V.1 — knowable platform; the (lex-
/// order × `Vec<Self>` × direction-composition × intersection × unique-
/// tie) corner was an unnamed inline composition — or silently absent
/// because callers reached for the declaration-order sibling without
/// proof of coincidence — recurring at every prospective downstream "the
/// sole flat-diagonal variant, as a Vec, in lex order, if it's
/// unambiguous" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of TWO
/// substrate primitives ([`Self::has_unique_bimodal_variant`] +
/// [`Self::sorted_bimodal_variants`]) with the `if _ { _ } else { vec![] }`
/// combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); if (length(unique(t)) == 1 && length(t) == 1) sort(names(t)) else character(0) }`;
/// Clojure's
/// `(let [f (frequencies coll)] (if (and (= 1 (count f)) (apply = (vals f))) (sort (keys f)) ()))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING (SELECT COUNT(DISTINCT c) FROM …) = 1 AND (SELECT COUNT(*) FROM …) = 1 ORDER BY variant)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order intersection singleton-or-empty projection
/// on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_bimodal_variant`] guard conjoined with the just-
/// lifted [`Self::sorted_bimodal_variants`] witness-collection under a
/// Vec-select — no new dep, no supertrait bound, `O(T::CARDINALITY * n)`
/// inherited from the underlying aggregates with short-circuiting on the
/// guard.
fn sorted_unique_bimodal_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_bimodal_variant(items) {
<Self as ClosedSet>::sorted_bimodal_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "target is THE UNIQUE extremal variant"
/// per-target predicate — `true` iff `target` is an extremal variant of
/// `items` (its per-target multiplicity sits on the union of the argmax
/// and argmin bands via [`Self::is_extremal_variant_of`]) AND `items`
/// has a unique extremum ([`Self::count_extremal_variants`] `== 1`),
/// computed as the conjunction of the per-target union membership
/// predicate [`Self::is_extremal_variant_of`] with the set-level
/// extremal-uniqueness predicate [`Self::has_unique_extremal_variant`].
/// The BOOL-RETURN PER-TARGET UNION UNIQUE-TIE SHARPENING corner
/// OPENING the (per-target × bool × statistical-aggregate × direction-
/// composition × union × unique-tie) column past the direction-anchored
/// (`is_unique_modal_variant_of`, `is_unique_antimodal_variant_of`) pair
/// one DIRECTION-COMPOSITION axis over on the modal-aggregation matrix
/// AND peer to [`Self::has_unique_extremal_variant`] (set-level × bool
/// × union × unique-tie) one ARITY axis over AND peer to
/// [`Self::is_extremal_variant_of`] (per-target × bool × union) one
/// UNIQUE-TIE-SHARPENING axis over AND peer to
/// [`Self::unique_extremal_variant`] (set-level × `Option<Self>` ×
/// union × unique-tie) one ARITY axis over. Not a fresh substrate
/// primitive on the index axis — the predicate emerges from the
/// conjunction of the just-lifted per-target union membership predicate
/// with the just-lifted set-level extremal-uniqueness scalar,
/// equivalently the strict-equality test of the just-lifted first-
/// witness [`Self::unique_extremal_variant`] projection against
/// `Some(target)`.
///
/// Union-conjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_extremal_variant_of(v, items) == (T::is_extremal_variant_of(v, items) && T::has_unique_extremal_variant(items))`
/// — the per-target extremal-uniqueness predicate is EXACTLY the
/// conjunction of the per-target union membership predicate with the
/// set-level extremal-uniqueness scalar. The canonical form the body
/// uses. Pinned by
/// `is_unique_extremal_variant_of_equals_extremal_membership_and_unique_extremal_variant_across_every_target_and_triple`.
///
/// First-witness identity: for every slice `items` and every target
/// `v`,
/// `T::is_unique_extremal_variant_of(v, items) == (T::unique_extremal_variant(items) == Some(v))`
/// — when `items` has a unique extremum, the just-lifted set-level
/// witness [`Self::unique_extremal_variant`] returns EXACTLY the
/// unique extremal variant, so equating it byte-for-byte with
/// `Some(v)` coincides with THIS per-target predicate at every target.
/// When `items` has no unique extremum, [`Self::unique_extremal_variant`]
/// collapses to `None`; the strict-equality test against `Some(v)`
/// returns `false` at every target, coinciding with THIS predicate's
/// `false`-at-non-unique fixpoint. Independent cross-check distinct
/// from the union-conjunction arm on the surface axis (Option-equality
/// vs bool-conjunction). Pinned by
/// `is_unique_extremal_variant_of_agrees_with_unique_extremal_variant_option_equality_across_every_target_and_triple`.
///
/// At-most-one-target identity: for every slice `items`,
/// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_unique_extremal_variant_of(v, items)).count() == usize::from(T::has_unique_extremal_variant(items))`
/// — the set-level filter-count reduction over [`Self::ALL`] of THIS
/// per-target predicate reports EXACTLY `0` when `items` has no unique
/// extremum and EXACTLY `1` when `items` has a unique extremum (only
/// that one variant satisfies the conjunction). Sibling posture to
/// `is_extremal_variant_of_count_equals_count_extremal_variants_across_every_triple`
/// one UNIQUE-TIE-SHARPENING axis over. Pinned by
/// `is_unique_extremal_variant_of_count_equals_has_unique_extremal_variant_as_usize_across_every_triple`.
///
/// Direction-disjunction identity: for every slice `items` and every
/// target `v`,
/// `T::is_unique_extremal_variant_of(v, items) == ((T::is_unique_modal_variant_of(v, items) || T::is_unique_antimodal_variant_of(v, items)) && T::has_unique_extremal_variant(items))`
/// — the per-target union unique-tie predicate factors through the
/// per-target direction-anchored unique-tie pair under `||`, but ONLY
/// when the SET-LEVEL union uniqueness bit holds (the direction-anchored
/// unique-tie pair pins per-target argmax/argmin uniqueness ANCHORED to
/// EACH BAND, not the UNION band). Pinned by
/// `is_unique_extremal_variant_of_agrees_with_direction_disjunction_gated_by_unique_extremal_variant_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_extremal_variant_of`] plus [`Self::has_unique_extremal_variant`]
/// (both ordering-agnostic — the former via [`Self::count_occurrences_of`],
/// [`Self::max_variant_count`], and [`Self::min_variant_count`] on a
/// disjunction, the latter via [`Self::count_extremal_variants`]) via a
/// boolean conjunction. No separate `sorted_is_unique_extremal_variant_of`
/// peer is needed. Pinned by
/// `is_unique_extremal_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract: `T::is_unique_extremal_variant_of(v, &[])`
/// is `false` for every target `v` UNCONDITIONALLY — the empty slice
/// hits zero positions, [`Self::is_extremal_variant_of`] collapses to
/// `false` at every target via its empty-slice guard (independent of
/// the [`Self::has_unique_extremal_variant`] conjunct's own `false`-at-
/// empty fixpoint), so the conjunction lands on `false` at every
/// target through either arm.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_extremal_variant_of(v, &[v]) == false` for every
/// variant `v` — the sole position hits `v` with count `1 == max`,
/// every non-target sits at count `0 == min`,
/// [`Self::is_extremal_variant_of`] reports `true` at every target (all
/// variants land on the union band), but [`Self::has_unique_extremal_variant`]
/// reports `false` because `count_extremal_variants([v])` equals
/// `T::CARDINALITY >= 2` which is not `1`, and the conjunction lands
/// on `false` at every target through the uniqueness arm.
///
/// Non-matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::is_unique_extremal_variant_of(v, &[w]) == false` for every
/// target `v` and slice-element `w` with `T::index_of(v) !=
/// T::index_of(w)` — the sole position hits `w`; the target's count
/// is `0 == min`, [`Self::is_extremal_variant_of`] reports `true` at
/// the target (on the argmin band), but [`Self::has_unique_extremal_variant`]
/// reports `false` because `count_extremal_variants([w])` equals
/// `T::CARDINALITY >= 3` which is not `1`, and the conjunction lands
/// on `false` at every target through the uniqueness arm.
///
/// Full-set + doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_extremal_variant_of(v, T::ALL) == false` +
/// `T::is_unique_extremal_variant_of(v, &doubled) == false` for every
/// target `v` UNCONDITIONALLY — on either flat-histogram fixpoint every
/// variant lands simultaneously on both extremes via the max == min
/// collapse, `count_extremal_variants` reports `T::CARDINALITY >= 2`,
/// and the conjunction lands on `false` at every target through the
/// uniqueness arm.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::is_unique_extremal_variant_of(v, &[T::ALL[0], T::ALL[0], T::ALL[1]])
/// == false` for every target `v` — on the canonical non-flat triple
/// `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at count `1`
/// (strictly interior), `T::ALL[2..]` at count `0 == min`;
/// [`Self::is_extremal_variant_of`] reports `true` at `T::ALL[0]` and
/// at every `T::ALL[i]` for `i >= 2` (union band), but
/// [`Self::has_unique_extremal_variant`] reports `false` because
/// `count_extremal_variants` reports `T::CARDINALITY - 1 >= 2` (one
/// argmax + `T::CARDINALITY - 2` argmin witnesses). LOAD-BEARING
/// DEGENERATE-OPENER PROPERTY: on a cardinality-`>= 2` implementor the
/// SOLE `true` arm of THIS predicate sits at `T::CARDINALITY == 1`
/// where a non-empty slice trivially collapses the union band to a
/// single variant; every canonical fixpoint on a multi-variant stub
/// pins the projection at `false`, mirroring the degenerate-opener
/// property of [`Self::has_unique_extremal_variant`] +
/// [`Self::unique_extremal_variant`] one ARITY axis over.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_extremal_variant_of`] + [`Self::has_unique_extremal_variant`]
/// via a boolean conjunction on `bool`. The sweep cost inherits both
/// primitives: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one [`Self::min_variant_count`]
/// fold + one [`Self::count_occurrences_of`] fold at the target + one
/// filter-count over [`Self::ALL`] via [`Self::count_extremal_variants`];
/// the short-circuiting `&&` avoids the second aggregate when the first
/// arm falsifies), allocation-free, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_extremal_variant_of`]: a `tatara-check` predicate
/// `(check-target-is-the-unique-extremum …)` that reports "the sole
/// extremal variant (max OR min side) is unambiguous AND matches the
/// expected witness" in ONE typed bool rather than a two-step Vec-
/// length + membership composition; an LSP diagnostic on a Lisp-
/// authored closed-set field that flags a specific expected variant
/// as "currently the unique extremum" without materializing the
/// extremal witness-collection; a Sekiban audit-trail per-target
/// unique-extremum bit binding the same scalar, composable with the
/// per-target unique-mode + unique-antimode bits into a typed 3-bit
/// `(unique-mode-of-target, unique-antimode-of-target, unique-
/// extremum-of-target)` classifier per window (with the direction-
/// composition axis pinned by the trichotomy `is_unique_extremal ⇒
/// is_unique_modal || is_unique_antimodal` at the SET-level uniqueness-
/// gated site); a scheduler-fairness heuristic that branches on "is
/// worker X the unique boundary worker (busiest OR idlest)?" as a per-
/// worker bool without paying the extremal-witness Vec allocation;
/// a starvation / bottleneck-diagnosis predicate that reports "target
/// is uniquely at the boundary" without a two-round tally. Each binds
/// to ONE typed per-target bool predicate on the trait rather than
/// re-deriving `T::is_extremal_variant_of(v, items) &&
/// T::has_unique_extremal_variant(items)` inline per callsite OR
/// paying the Vec allocation `T::extremal_variants(items) == vec![v]`
/// would demand.
///
/// Compounding closure: this projection OPENS the (per-target × bool ×
/// statistical-aggregate × direction-composition × union × unique-tie)
/// corner on the modal-aggregation matrix as the ARITY LIFT of the
/// just-lifted set-level union uniqueness bit
/// [`Self::has_unique_extremal_variant`] conjoined with the per-target
/// union membership predicate [`Self::is_extremal_variant_of`]. Together
/// with the just-lifted direction-anchored (`is_unique_modal_variant_of`,
/// `is_unique_antimodal_variant_of`) pair one DIRECTION-COMPOSITION
/// axis over, the (per-target × bool × direction/direction-composition ×
/// unique-tie) row now opens its THIRD tile past the two direction-
/// anchored corners. The natural next lifts past this opening are
/// `is_unique_middle_band_variant_of(target, items) -> bool` complement
/// peer (returning `true` iff `target` is the sole strict-interior
/// witness) and `is_unique_bimodal_variant_of(target, items) -> bool`
/// intersection peer (returning `true` iff `target` is the sole flat-
/// diagonal witness) — both emerge from analogous conjunctions of the
/// per-target complement / intersection membership predicates with the
/// just-lifted set-level complement / intersection uniqueness bits.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-target
/// unique-extremum predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::is_extremal_variant_of(v, items) && T::has_unique_extremal_variant(items)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × direction-composition ×
/// union × unique-tie) corner was an unnamed inline composition
/// recurring at every prospective downstream "is this target the
/// unique boundary variant?" site pre-lift. Naming it on the trait
/// makes the predicate a TYPED CONSEQUENCE of the just-lifted per-
/// target union membership predicate and set-level extremal-uniqueness
/// bit under a boolean conjunction. THEORY.md §VI.1 — generation over
/// composition; the predicate emerges from the composition of TWO
/// substrate primitives ([`Self::is_extremal_variant_of`] +
/// [`Self::has_unique_extremal_variant`]) with the `&&` combinator on
/// `bool`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `let t = table(items); v %in%
/// names(t)[t == max(t) | t == min(t)] && sum(t == max(t) | t ==
/// min(t)) == 1` per-level unique-boundary test on a factor histogram;
/// Julia's `let c = StatsBase.countmap(items), m = maximum(values(c)),
/// n = minimum(values(c)); (c[v] == m || c[v] == n) && count(kv ->
/// kv[2] == m || kv[2] == n, collect(c)) == 1 end` on a
/// `Dict{Element, Int}` histogram; Python's `let c =
/// collections.Counter(items), mx = max(c.values(), default=0), mn =
/// min(c.values(), default=0); (c[v] == mx or c[v] == mn) and sum(1
/// for x in c.values() if x == mx or x == mn) == 1` on a Counter;
/// Haskell's `let hs = map (\g -> (head g, length g)) . group . sort $
/// items; m = maximum (map snd hs); n = minimum (map snd hs); ts =
/// filter (\(_, c) -> c == m || c == n) hs in count v items == m ||
/// count v items == n && length ts == 1` on `Ord`-instance carriers;
/// Clojure's `(let [f (frequencies coll), m (apply max (vals f)), n
/// (apply min (vals f)), ts (filter #(or (= (val %) m) (= (val %) n))
/// f)] (and (or (= (get f v 0) m) (= (get f v 0) n)) (= 1 (count
/// ts))))`; SQL's per-target unique-boundary test on a GROUP BY
/// variant HAVING COUNT(*) IN (MAX, MIN) AND (COUNT DISTINCT bucket)
/// equals `1`. Translation through pleme-io primitives: the N-ary
/// per-target unique-extremum predicate on the closed-set trait binds
/// through the just-lifted [`Self::is_extremal_variant_of`] union
/// membership predicate conjoined with the just-lifted
/// [`Self::has_unique_extremal_variant`] set-level uniqueness bit — no
/// new dep, no supertrait bound, no allocation, `O(T::CARDINALITY * n)`
/// inherited from the underlying aggregates with short-circuiting on
/// the union-membership arm. One pleme-io-specific asymmetry: the
/// union direction-composition axis makes the predicate DEGENERATE at
/// [`Self::CARDINALITY`] `>= 2` (every canonical fixpoint pins the
/// projection at `false` because the union band pulls at least two
/// witnesses on every non-flat AND every flat slice at cardinality
/// `>= 2`); the SOLE `true` arm sits at [`Self::CARDINALITY`] `== 1`,
/// out of reach of a multi-variant stub, mirroring the degenerate-
/// opener property that [`Self::has_unique_extremal_variant`] and
/// [`Self::unique_extremal_variant`] carry one ARITY axis over.
fn is_unique_extremal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_extremal_variant_of(target, items)
&& <Self as ClosedSet>::has_unique_extremal_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "is `target` the SOLE
/// strictly-interior variant?" predicate — `true` iff `target`
/// sits STRICTLY BETWEEN the max and min counts of `items` AND
/// exactly ONE variant of [`Self::ALL`] sits on that strict-
/// interior band, computed as the just-lifted per-target
/// complement membership [`Self::is_middle_band_variant_of`]
/// projection conjoined with the just-lifted set-level
/// complement uniqueness bit
/// [`Self::has_unique_middle_band_variant`] via `&&`. The
/// (per-target × bool × direction-composition × complement ×
/// unique-tie) corner CLOSING the complement arm of the (per-
/// target × bool × direction-composition × combinator × unique-
/// tie) 3-corner row past the just-opened union arm
/// [`Self::is_unique_extremal_variant_of`] one COMBINATOR axis
/// over.
///
/// Union-corner asymmetry — LOAD-BEARING POSITIVE ARM: unlike the
/// sibling [`Self::is_unique_extremal_variant_of`] whose
/// canonical multi-variant fixpoints ALL pin the projection at
/// `false` (the union band always pulls at least two witnesses on
/// every flat AND non-flat slice at cardinality `>= 2`, so its
/// sole positive arm sits at `T::CARDINALITY == 1` out of reach
/// of a multi-variant stub), THIS complement projection carries a
/// LOAD-BEARING `true` arm on the canonical bimodal-triple
/// fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality
/// `>= 3`: `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at
/// count `1` (STRICTLY INTERIOR — the SOLE middle-band witness),
/// `T::ALL[2..]` at count `0 == min`;
/// [`Self::is_middle_band_variant_of`] reports `true` only at
/// `T::ALL[1]`, [`Self::has_unique_middle_band_variant`] reports
/// `true` because `count_middle_band_variants == 1`, and the
/// conjunction lands on `true` at `T::ALL[1]` and `false` at
/// every other target. The fixture therefore witnesses BOTH the
/// positive-arm existence AND the strict-target-uniqueness
/// contract simultaneously.
///
/// Empty-slice contract: `T::is_unique_middle_band_variant_of(v, &[])`
/// is `false` for every target `v` — [`Self::is_middle_band_variant_of`]
/// reports `false` at every target on the empty slice via its
/// max == min == 0 collapse arm, and `false && _` short-circuits
/// to `false`. Sibling posture to the empty-slice arm of
/// [`Self::is_unique_extremal_variant_of`] one COMBINATOR axis
/// over.
///
/// Singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_middle_band_variant_of(v, &[w])` is `false` for
/// every target `v` and slice-element `w` — a singleton has
/// max `1` at `w` and min `0` at every other variant; no variant
/// sits STRICTLY between `0` and `1`, so
/// [`Self::is_middle_band_variant_of`] reports `false` at every
/// target and the conjunction collapses to `false`. Both the
/// matching-singleton (`w == v`) and non-matching-singleton
/// (`w != v`) arms pin the projection at `false`.
///
/// Flat-histogram contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_middle_band_variant_of(v, T::ALL) == false` +
/// `T::is_unique_middle_band_variant_of(v, &doubled) == false`
/// for every target `v` UNCONDITIONALLY — on either flat-
/// histogram fixpoint max == min collapses the strict-interior
/// band to the empty set, [`Self::is_middle_band_variant_of`]
/// reports `false` at every target, and the conjunction lands on
/// `false`.
///
/// At-most-one-target contract: for every slice `items`,
/// `T::ALL.iter().filter(|&&v| T::is_unique_middle_band_variant_of(v, items)).count()`
/// equals `usize::from(T::has_unique_middle_band_variant(items))`
/// on every slice — the per-target predicate's set-level filter-
/// count equals the set-level complement uniqueness bit cast to
/// `usize`; at most ONE target satisfies the per-target
/// predicate, and it does exactly when
/// [`Self::has_unique_middle_band_variant`] holds.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_middle_band_variant_of`] +
/// [`Self::has_unique_middle_band_variant`] via a boolean
/// conjunction on `bool`. The sweep cost inherits both primitives:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::max_variant_count`] fold + one
/// [`Self::min_variant_count`] fold + one
/// [`Self::count_occurrences_of`] fold at the target + one
/// filter-count over [`Self::ALL`] via
/// [`Self::count_middle_band_variants`]; the short-circuiting
/// `&&` avoids the second aggregate when the first arm
/// falsifies), allocation-free, no supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_middle_band_variant_of`]: a `tatara-check`
/// predicate `(check-target-is-the-unique-strict-interior …)` that
/// reports "the sole strictly-interior variant is unambiguous AND
/// matches the expected witness" in ONE typed bool rather than a
/// two-step Vec-length + membership composition; an LSP
/// diagnostic that flags a Lisp-authored closed-set field as
/// "currently the unique strict-interior variant" without
/// materializing the middle-band witness-collection; a Sekiban
/// audit-trail per-target unique-interior bit binding the same
/// scalar, composable with the per-target unique-extremum bit
/// into a typed 2-bit strict-interior-vs-boundary classifier per
/// window; a scheduler-fairness heuristic that branches on "is
/// worker X the sole strictly-mid-load worker (neither the
/// busiest nor the idlest)?"; a starvation / bottleneck-diagnosis
/// predicate that reports "target is uniquely off both boundaries"
/// without a two-round tally. Each binds to ONE typed per-target
/// bool predicate on the trait rather than re-deriving
/// `T::is_middle_band_variant_of(v, items) &&
/// T::has_unique_middle_band_variant(items)` inline per callsite
/// OR paying the Vec allocation
/// `T::middle_band_variants(items) == vec![v]` would demand.
///
/// Compounding closure: this projection CLOSES the complement arm
/// of the (per-target × bool × direction-composition × combinator
/// × unique-tie) 3-corner row past the just-opened union arm
/// [`Self::is_unique_extremal_variant_of`] one COMBINATOR axis
/// over. The natural next lift on this row —
/// `is_unique_bimodal_variant_of(target, items) -> bool`
/// intersection peer (returning `true` iff `target` is the SOLE
/// flat-diagonal witness — necessarily false on multi-variant
/// fixtures since the flat-diagonal band pulls the entire set
/// simultaneously when it pulls at all) — CLOSES the final tile
/// of the (per-target × bool × direction-composition × combinator
/// × unique-tie) 3-corner row via a
/// `is_bimodal_variant_of(target, items) &&
/// has_unique_bimodal_variant(items)` conjunction, mirroring THIS
/// projection's shape one COMBINATOR axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target unique-strict-interior predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::is_middle_band_variant_of(v, items) &&
/// T::has_unique_middle_band_variant(items)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (per-target × bool × direction-composition × complement ×
/// unique-tie) corner was an unnamed inline composition
/// recurring at every prospective downstream "is this target the
/// unique strict-interior variant?" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the predicate emerges
/// from the composition of TWO substrate primitives
/// ([`Self::is_middle_band_variant_of`] +
/// [`Self::has_unique_middle_band_variant`]) with the `&&`
/// combinator on `bool`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `let t = table(items); v %in%
/// setdiff(names(t)[t > min(t) & t < max(t)], character(0)) &&
/// sum(t > min(t) & t < max(t)) == 1` per-level unique-strict-
/// interior test on a factor histogram; Julia's `let c =
/// StatsBase.countmap(items), m = maximum(values(c)), n =
/// minimum(values(c)); (n < c[v] < m) && count(kv -> n < kv[2] <
/// m, collect(c)) == 1 end` on a `Dict{Element, Int}` histogram;
/// Python's `let c = collections.Counter(items), mx =
/// max(c.values(), default=0), mn = min(c.values(), default=0);
/// (mn < c[v] < mx) and sum(1 for x in c.values() if mn < x < mx)
/// == 1` on a Counter; Haskell's `let hs = map (\g -> (head g,
/// length g)) . group . sort $ items; m = maximum (map snd hs);
/// n = minimum (map snd hs); ts = filter (\(_, c) -> c > n && c
/// < m) hs in n < count v items && count v items < m && length ts
/// == 1` on `Ord`-instance carriers; Clojure's `(let [f
/// (frequencies coll), m (apply max (vals f)), n (apply min (vals
/// f)), ts (filter #(< n (val %) m) f)] (and (< n (get f v 0) m)
/// (= 1 (count ts))))`. Translation through pleme-io primitives:
/// the projection binds through the just-lifted
/// [`Self::is_middle_band_variant_of`] complement membership
/// predicate conjoined with the just-lifted
/// [`Self::has_unique_middle_band_variant`] set-level uniqueness
/// bit — no new dep, no supertrait bound, no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying
/// aggregates with short-circuiting on the complement-membership
/// arm. One pleme-io-specific asymmetry: the complement direction-
/// composition axis carries a NON-DEGENERATE positive arm on the
/// canonical bimodal-triple fixture at cardinality `>= 3` (unlike
/// the union sibling [`Self::is_unique_extremal_variant_of`]
/// which stays degenerate on every multi-variant fixture),
/// mirroring the load-bearing positive arm
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::unique_middle_band_variant`] carry one ARITY axis
/// over.
fn is_unique_middle_band_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_middle_band_variant_of(target, items)
&& <Self as ClosedSet>::has_unique_middle_band_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "is `target` the SOLE
/// flat-diagonal variant?" predicate — `true` iff `target` sits on
/// BOTH the argmax AND the argmin bands of `items`
/// simultaneously AND exactly ONE variant of [`Self::ALL`] sits on
/// that intersection band, computed as the just-lifted per-target
/// intersection membership [`Self::is_bimodal_variant_of`]
/// projection conjoined with the just-lifted set-level
/// intersection uniqueness bit
/// [`Self::has_unique_bimodal_variant`] via `&&`. The (per-target ×
/// bool × direction-composition × intersection × unique-tie)
/// corner CLOSING the intersection arm of the (per-target × bool ×
/// direction-composition × combinator × unique-tie) 3-corner row
/// past the just-opened union arm
/// [`Self::is_unique_extremal_variant_of`] AND the just-closed
/// complement arm [`Self::is_unique_middle_band_variant_of`] one
/// COMBINATOR axis over AND EXHAUSTIVELY CLOSING the (per-target ×
/// bool × direction-composition × combinator × unique-tie)
/// 3-corner row at its FINAL THIRD tile.
///
/// Degenerate-at-multi-variant contract — DEEPER THAN THE UNION
/// SIBLING: unlike [`Self::is_unique_extremal_variant_of`] whose
/// canonical multi-variant fixpoints ALL pin the projection at
/// `false` (the union band always pulls at least two witnesses on
/// every flat AND non-flat slice at cardinality `>= 2`), THIS
/// intersection projection is DOUBLY DEGENERATE at cardinality
/// `>= 2`: the intersection band is EMPTY on every non-flat slice
/// (max != min so no variant sits on both bands simultaneously,
/// [`Self::is_bimodal_variant_of`] falsifies universally, the
/// membership arm short-circuits the conjunction to `false`) AND
/// the intersection band pulls the ENTIRE closed set on every
/// non-empty flat-histogram slice (max == min so every variant
/// sits on both bands, [`Self::count_bimodal_variants`] collapses
/// to [`Self::CARDINALITY`] `>= 2`, so
/// [`Self::has_unique_bimodal_variant`] falsifies at
/// `count_bimodal_variants != 1`, the uniqueness arm short-
/// circuits the conjunction to `false`). Both arms collapse to
/// `false` universally at cardinality `>= 2` — the SOLE positive
/// arm sits at [`Self::CARDINALITY`] `== 1` on a non-empty slice
/// (the sole variant is both the sole modal AND the sole
/// antimodal AND the sole flat-diagonal witness, out of reach of
/// a multi-variant fixture).
///
/// Empty-slice contract: `T::is_unique_bimodal_variant_of(v, &[])`
/// is `false` for every target `v` — [`Self::is_bimodal_variant_of`]
/// reports `false` at every target on the empty slice via the
/// underlying [`Self::is_modal_variant_of`]'s empty-slice guard,
/// and `false && _` short-circuits to `false`. Sibling posture to
/// the empty-slice arms of [`Self::is_unique_extremal_variant_of`]
/// AND [`Self::is_unique_middle_band_variant_of`] one COMBINATOR
/// axis over.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_bimodal_variant_of(v, &[v])` is `false` for every
/// target `v` — a singleton has max `1` at `v` and min `0` at
/// every other variant; `v` sits on the argmax band but NOT on
/// the argmin band (its count `1 != 0 == min`), so
/// [`Self::is_bimodal_variant_of`] reports `false` at `v` and the
/// conjunction collapses to `false`. Every non-target arm
/// (`count 0 == min` but count `0 != 1 == max`) also fails the
/// intersection membership arm.
///
/// Non-matching-singleton contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::is_unique_bimodal_variant_of(v, &[w])` with
/// `T::index_of(v) != T::index_of(w)` is `false` for every target
/// pair — the singleton pins `w` at count `1 == max` and every
/// non-`w` variant (including `v`) at count `0 == min`; the
/// intersection band is empty (max != min), so
/// [`Self::is_bimodal_variant_of`] reports `false` at every target
/// and the conjunction lands on `false`.
///
/// Flat-histogram contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_bimodal_variant_of(v, T::ALL) == false` +
/// `T::is_unique_bimodal_variant_of(v, &doubled) == false` for
/// every target `v` UNCONDITIONALLY — on either flat-histogram
/// fixpoint max == min so [`Self::is_bimodal_variant_of`] reports
/// `true` at EVERY target (the entire closed set sits on the
/// intersection band), but
/// [`Self::count_bimodal_variants`] collapses to
/// [`Self::CARDINALITY`] `>= 2` and
/// [`Self::has_unique_bimodal_variant`] falsifies at
/// `T::CARDINALITY >= 2 != 1`, so the conjunction lands on `false`
/// at every target via the uniqueness arm. LOAD-BEARING ASYMMETRY
/// against [`Self::is_bimodal_variant_of`] which reports `true` on
/// the same slice at every target.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::is_unique_bimodal_variant_of(v, &[T::ALL[0], T::ALL[0], T::ALL[1]])`
/// is `false` for every target `v` — `T::ALL[0]` sits at count
/// `2 == max`, `T::ALL[1]` at count `1` (strictly interior),
/// `T::ALL[2..]` at count `0 == min`; the intersection band is
/// empty (max != min so no variant sits on both bands),
/// [`Self::is_bimodal_variant_of`] reports `false` at every target
/// and the conjunction lands on `false` via the membership arm.
/// DISTINGUISHES the intersection corner from the complement
/// sibling [`Self::is_unique_middle_band_variant_of`] which
/// reports `true` at `T::ALL[1]` on the same fixture.
///
/// At-most-one-target contract: for every slice `items`,
/// `T::ALL.iter().filter(|&&v| T::is_unique_bimodal_variant_of(v, items)).count()`
/// equals `usize::from(T::has_unique_bimodal_variant(items))` on
/// every slice — the per-target predicate's set-level filter-
/// count equals the set-level intersection uniqueness bit cast to
/// `usize`; at most ONE target satisfies the per-target
/// predicate, and it does exactly when
/// [`Self::has_unique_bimodal_variant`] holds (out of reach of
/// multi-variant fixtures, but the identity holds trivially on
/// them since both sides collapse to `0`).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_bimodal_variant_of`] +
/// [`Self::has_unique_bimodal_variant`] via a boolean conjunction
/// on `bool`. The sweep cost inherits both primitives:
/// `O(T::CARDINALITY * n)` on slice arity `n` (the underlying
/// [`Self::is_bimodal_variant_of`] costs `O(T::CARDINALITY * n)`
/// through its conjunction of [`Self::is_modal_variant_of`] and
/// [`Self::is_antimodal_variant_of`]; the sharpened
/// [`Self::has_unique_bimodal_variant`] costs
/// `O(T::CARDINALITY * n)` through the uniformity-collapse
/// identity on [`Self::count_bimodal_variants`]; short-circuiting
/// `&&` avoids the second aggregate when the first arm falsifies),
/// allocation-free, no supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::is_unique_bimodal_variant_of`]: a `tatara-check`
/// predicate `(check-target-is-the-unique-flat-diagonal …)` that
/// reports "the sole flat-diagonal variant is unambiguous AND
/// matches the expected witness" in ONE typed bool rather than a
/// two-step Vec-length + membership composition; an LSP
/// diagnostic that flags a Lisp-authored closed-set field as
/// "currently the unique flat-diagonal variant" without
/// materializing the intersection witness-collection; a Sekiban
/// audit-trail per-target unique-flat-diagonal bit binding the
/// same scalar, composable with the per-target unique-extremum +
/// unique-strict-interior bits into a typed 3-bit
/// direction-composition classifier per window; a scheduler-
/// fairness heuristic that branches on "is worker X the sole
/// perfectly-balanced worker (simultaneously the busiest AND the
/// idlest — degenerate collapse to the single-worker fleet)?".
/// Each binds to ONE typed per-target bool predicate on the trait
/// rather than re-deriving
/// `T::is_bimodal_variant_of(v, items) &&
/// T::has_unique_bimodal_variant(items)` inline per callsite OR
/// paying the Vec allocation
/// `T::bimodal_variants(items) == vec![v]` would demand.
///
/// Compounding closure: this projection CLOSES the intersection
/// arm of the (per-target × bool × direction-composition ×
/// combinator × unique-tie) 3-corner row past the just-opened
/// union arm [`Self::is_unique_extremal_variant_of`] AND the
/// just-closed complement arm
/// [`Self::is_unique_middle_band_variant_of`] one COMBINATOR axis
/// over AND EXHAUSTIVELY CLOSES the (per-target × bool ×
/// direction-composition × combinator × unique-tie) 3-corner row
/// at its FINAL THIRD tile, mirroring the exhaustive closure the
/// (set-level × bool × direction-composition × combinator ×
/// unique-tie) [`Self::has_unique_bimodal_variant`] row + the
/// (set-level × `Option<Self>` × direction-composition ×
/// combinator × unique-tie) [`Self::unique_bimodal_variant`] row
/// carry one ARITY / RETURN-SHAPE axis over. The natural next
/// lift past this row: sharpen a downstream `tatara-check`
/// primitive against a caixa-authored expected flat-diagonal
/// witness via the composed
/// `T::unique_bimodal_variant(items) == Some(expected)` identity,
/// binding through ONE typed Option-equality rather than THREE
/// separate identities re-derived at every callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary per-
/// target unique-flat-diagonal predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::is_bimodal_variant_of(v, items) &&
/// T::has_unique_bimodal_variant(items)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (per-target × bool × direction-composition × intersection
/// × unique-tie) corner was an unnamed inline composition
/// recurring at every prospective downstream "is this target the
/// unique flat-diagonal variant?" site pre-lift. THEORY.md §VI.1
/// — generation over composition; the predicate emerges from the
/// composition of TWO substrate primitives
/// ([`Self::is_bimodal_variant_of`] +
/// [`Self::has_unique_bimodal_variant`]) with the `&&` combinator
/// on `bool`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `let t = table(items); m = max(t);
/// n = min(t); flat = names(t)[t == m & t == n]; v %in% flat &&
/// length(flat) == 1` per-level unique-flat-diagonal test on a
/// factor histogram; Julia's `let c = StatsBase.countmap(items),
/// m = maximum(values(c)), n = minimum(values(c)), flat =
/// filter(kv -> kv[2] == m && kv[2] == n, collect(c)); haskey(c,
/// v) && c[v] == m && c[v] == n && length(flat) == 1 end` on a
/// `Dict{Element, Int}` histogram; Python's `let c =
/// collections.Counter(items), mx = max(c.values(), default=0),
/// mn = min(c.values(), default=0), flat = [k for k, x in
/// c.items() if x == mx and x == mn]; c[v] == mx and c[v] == mn
/// and len(flat) == 1` on a Counter; Haskell's `let hs = map (\g
/// -> (head g, length g)) . group . sort $ items; m = maximum
/// (map snd hs); n = minimum (map snd hs); ts = filter (\(_, c)
/// -> c == m && c == n) hs; cv = count v items in cv == m && cv
/// == n && length ts == 1` on `Ord`-instance carriers; Clojure's
/// `(let [f (frequencies coll), m (apply max (vals f)), n (apply
/// min (vals f)), ts (filter #(and (= (val %) m) (= (val %) n))
/// f), cv (get f v 0)] (and (= cv m) (= cv n) (= 1 (count ts))))`.
/// Translation through pleme-io primitives: the projection binds
/// through the just-lifted [`Self::is_bimodal_variant_of`]
/// intersection membership predicate conjoined with the just-
/// lifted [`Self::has_unique_bimodal_variant`] set-level
/// uniqueness bit — no new dep, no supertrait bound, no
/// allocation, `O(T::CARDINALITY * n)` inherited from the
/// underlying aggregates with short-circuiting on the intersection-
/// membership arm. One pleme-io-specific asymmetry: the
/// intersection direction-composition axis is DOUBLY DEGENERATE
/// at [`Self::CARDINALITY`] `>= 2` (both non-flat + flat multi-
/// variant fixtures collapse to `false` — non-flat via the
/// membership arm short-circuit, flat via the uniqueness arm
/// short-circuit) — mirroring the two-value dichotomy identity
/// on the sibling [`Self::count_bimodal_variants`] one RETURN-
/// SHAPE axis over.
fn is_unique_bimodal_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_bimodal_variant_of(target, items)
&& <Self as ClosedSet>::has_unique_bimodal_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC "any variant repeating?" predicate —
/// `true` iff AT LEAST ONE variant of [`Self::ALL`] appears TWO OR
/// MORE times in `items`, computed as the just-lifted usize-return
/// [`Self::max_variant_count`] projection MEETING-OR-EXCEEDING the
/// scalar threshold `2`. The BOOL-RETURN opener on the (set-level ×
/// bool × multiplicity-band `>= 2`) corner peer to the (set-level ×
/// bool × multiplicity-band `== 0`) [`Self::is_missing_any`] corner
/// one MULTIPLICITY-BAND axis over, AND the direct SET-LEVEL
/// EXISTENTIAL LIFT of the (per-target × bool × multiplicity-band
/// `>= 2`) [`Self::is_repeated_occurrence_of`] corner one ARITY axis
/// over on the (arity × mult-band) face of the equivalence-partition
/// surface. Not a fresh substrate primitive on the index axis — the
/// predicate emerges from one comparison of the just-lifted
/// [`Self::max_variant_count`] modal-count aggregate against `2`,
/// equivalently the disjunction over [`Self::ALL`] of the per-target
/// [`Self::is_repeated_occurrence_of`] predicate.
///
/// Max-composition identity: for every slice `items`,
/// `T::is_repeating_any(items) == (T::max_variant_count(items) >= 2)`
/// — the bool-return existential-repeat predicate is EXACTLY the
/// lower-bound test of the modal-count aggregate against `2`. Pinned
/// by clause (113) and by
/// `is_repeating_any_holds_iff_max_variant_count_ge_two_across_every_triple`.
///
/// De Morgan identity: for every slice `items`,
/// `T::is_repeating_any(items) == !T::is_pairwise_distinct(items)` —
/// the (some-variant-repeats) predicate is the exact logical
/// NEGATION of the (no-variant-repeats) predicate on the equivalence-
/// partition surface. Together with [`Self::is_missing_any`]'s
/// De Morgan pairing against [`Self::is_covering`], the (set-level ×
/// bool × multiplicity-band) face now carries TWO independent
/// De Morgan pairs — (`is_missing_any`, `is_covering`) on the
/// (mult `== 0`, mult `>= 1`) split, and (`is_repeating_any`,
/// `is_pairwise_distinct`) on the (mult `>= 2`, mult `<= 1`) split.
/// Pinned by
/// `is_repeating_any_de_morgan_dual_of_is_pairwise_distinct_across_every_triple`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::is_repeating_any(items) == <T as ClosedSet>::ALL.iter().any(|&v| T::is_repeated_occurrence_of(v, items))`
/// — the set-level bool predicate is the EXACT existential
/// quantification over [`Self::ALL`] of the per-target multiplicity-
/// ≥2 predicate. This identity binds the set-level ARITY axis
/// against the per-target ARITY axis one arity axis over on the
/// (arity × mult-band) face, pinning the compounding closure the
/// prior per-target lift opened. Pinned by
/// `is_repeating_any_equals_existential_of_is_repeated_occurrence_of_across_every_triple`.
///
/// Distinct-count composition identity: for every slice `items`,
/// `T::is_repeating_any(items) == (T::count_distinct(items) < items.len())`
/// — a slice is repetition-free iff its distinct-count reaches its
/// slice-length upper bound, so its NEGATION (the strictly-lesser
/// case) is EXACTLY the existential-repeat predicate. Pinned by
/// `is_repeating_any_holds_iff_count_distinct_is_strictly_less_than_slice_length_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// element equality because [`Self::max_variant_count`]'s ordering-
/// axis invariance folds through the `>= 2` comparison bijectively.
/// Sibling posture to [`Self::is_missing_any`],
/// [`Self::is_pairwise_distinct`], [`Self::is_covering`],
/// [`Self::is_permutation_of_all`], [`Self::is_constant`], and
/// [`Self::is_uniform`]'s ordering-axis invariance: every projection
/// on the equivalence-partition surface is direction- AND ordering-
/// agnostic; no separate `sorted_is_repeating_any` peer is needed.
/// Pinned by
/// `is_repeating_any_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::is_repeating_any(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant occurrence count is `0`, the modal-count aggregate
/// collapses to `0`, and the lower-bound test against `2` fails.
/// Sibling posture to
/// `is_missing_any_returns_true_on_the_empty_slice_across_every_non_degenerate_kind`
/// one MULTIPLICITY-BAND axis over: the (mult `== 0`) band predicate
/// reaches its `true` fixpoint at the empty slice on any non-
/// degenerate implementor; the (mult `>= 2`) band predicate reaches
/// its `false` fixpoint at the same endpoint UNIVERSALLY (independent
/// of cardinality, since even a cardinality-0 empty slice has no
/// variant repeating). Pinned by clause (113) and by
/// `is_repeating_any_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::is_repeating_any(&[v])` is `false` for
/// every variant `v` — a singleton hits exactly one variant at one
/// position, so the modal-count aggregate collapses to `1` and the
/// lower-bound test against `2` fails. The singleton is the
/// LOAD-BEARING catcher separating the (mult `>= 2`) band from a
/// `_ => true` unconditional override — the empty slice and the
/// full set both yield `false` under the correct projection AND
/// under the drifted override, so the singleton (with correct value
/// `false`) is the smallest-arity slice that fires the drift catch
/// distinctly from the fixpoint arms. Pinned by
/// `is_repeating_any_returns_false_on_every_singleton_across_every_variant`.
///
/// Full-set contract: `T::is_repeating_any(<T as ClosedSet>::ALL)`
/// is `false` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant of [`Self::ALL`]
/// appears at exactly ONE position in the full-set slice, the
/// modal-count aggregate collapses to `1`, and the lower-bound test
/// against `2` fails. Sibling posture to
/// `is_missing_any_over_the_full_set_is_false_across_every_kind`
/// one MULTIPLICITY-BAND axis over: both existential predicates
/// reach their `false` fixpoint at the full-set endpoint because the
/// full set is the CANONICAL PERMUTATION (mult `== 1` at every
/// target) — no variant is missing AND no variant is repeating.
/// Pinned by clause (113) at the full-set fixpoint AND by
/// `is_repeating_any_over_the_full_set_is_false_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::is_repeating_any(&doubled)` is `true` on every implementor of
/// non-zero cardinality — the doubled full set hits every variant at
/// EXACTLY TWO positions, the modal-count aggregate collapses to
/// `2`, and the lower-bound test against `2` holds. The doubled-
/// full-set arm is LOAD-BEARING — it is the ONLY canonical fixpoint
/// arm that separates the (mult `>= 2`) band from the (mult `<= 1`)
/// [`Self::is_pairwise_distinct`] band: on empty, singleton, and
/// full-set fixpoints both bands report their `true`-for-distinct
/// / `false`-for-repeating value; only the doubled-full-set arm
/// distinguishes them (`true` under this predicate, `false` under
/// `is_pairwise_distinct`). Pinned by clause (113) at the doubled-
/// full-set fixpoint AND by
/// `is_repeating_any_returns_true_on_the_doubled_full_set_across_every_non_degenerate_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::max_variant_count`] projection at the trait
/// level. The composition uses one `>=` on `usize`, so the sweep
/// inherits [`Self::max_variant_count`]'s O(T::CARDINALITY * n) cost
/// on slice arity `n` — allocation-free (the max fold streams
/// through the per-variant multiplicity primitive without
/// materializing the intermediate `Vec<usize>` histogram), no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against [`Self::is_repeating_any`]:
/// a `tatara-check` predicate `(check-phases-report-any-repeat …)`
/// on a `WorkloadPhase` sequence that flags "some phase visited
/// more than once" (a rollout-loop witness distinct from a single-
/// shot success) without paying for the modal-count when only the
/// existence of a repeat matters; an LSP diagnostic on a Lisp-
/// author-written variant-list that flags "some variant listed more
/// than once" WITHOUT counting how many (the shape of a
/// duplicate-detection quick-fix that just wants to know a repeat
/// exists); a Sekiban audit-trail metric flagging a classification
/// poset window as "any-classification-repeated" WITHOUT emitting
/// the count-side gauge; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that flags a template's identifier multiset as
/// CARRYING SOME REDEFINITION (a common bug shape in quasi-quote
/// templates that unquote-splice a variable set) in ONE typed bool
/// rather than an inline `T::ALL.iter().any(|&v|
/// T::is_repeated_occurrence_of(v, items))` disjunction. Each binds
/// to ONE typed N-ary any-repeat predicate on the trait rather than
/// re-deriving `T::max_variant_count(items) >= 2` OR
/// `!T::is_pairwise_distinct(items)` OR the existential over targets
/// inline per callsite.
///
/// Compounding closure: the (set-level × bool × multiplicity-band)
/// face on the equivalence-partition surface now OPENS its (mult
/// `>= 2`) corner past the pre-existing (mult `== 0`)
/// [`Self::is_missing_any`] corner and (mult `<= 1`)
/// [`Self::is_pairwise_distinct`] corner. Combined with the per-
/// target trichotomy the prior lift closed (`!occurs_in`,
/// `is_unique_occurrence_of`, `is_repeated_occurrence_of`), the
/// (arity × mult-band) face now carries THREE typed set-level
/// existential predicates (`is_missing_any`, `is_repeating_any`) +
/// (`is_pairwise_distinct`, `is_covering`) that project the per-
/// target multiplicity axis's three bands onto set-level bools via
/// standard-library `any` / `all` combinators. The natural next
/// lift past this corner is the (set-level × bool × multiplicity-
/// band `== 1`) `has_singleton_variant` corner (`T::ALL.iter().any(|&v|
/// T::is_unique_occurrence_of(v, items))` — the existential lift
/// of the middle band, distinct from any existing predicate)
/// closing the set-level existential-bool face at its remaining
/// mult-band corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary any-
/// repeat predicate becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline
/// `T::max_variant_count(items) >= 2` composition OR
/// `!T::is_pairwise_distinct(items)` negation at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (set-
/// level × bool × mult `>= 2`) corner was an unnamed inline
/// composition recurring at every prospective downstream "did some
/// variant repeat?" site pre-lift. Naming it on the trait makes
/// the predicate a TYPED CONSEQUENCE of the substrate's modal-count
/// aggregate compared meet-or-exceed against `2`. THEORY.md §VI.1
/// — generation over composition; the any-repeat predicate emerges
/// from the composition of ONE substrate primitive
/// ([`Self::max_variant_count`]) with a `>= 2` comparison on
/// `usize`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `existsb (fun v => 2 <=? count_occ
/// eqb l v) T` idiom composing an existential quantifier with a
/// per-key repetition witness on a decidable-equality carrier;
/// Idris's `any (\v => count (== v) items >= 2) all` on a
/// `Vect n a`; Racket's `(ormap (λ (v) (>= (count (λ (w) (equal? v w))
/// items) 2)) T)` on a list; Julia's `any(v ->
/// count(==(v), items) >= 2, T)` on a typed vector; Haskell's `any
/// (\v -> length (filter (== v) items) >= 2) all`; Rust's own
/// `T::ALL.iter().any(|v| items.iter().filter(|w| v == w).count() >= 2)`
/// idiom binds through a `Self: PartialEq` supertrait bound;
/// Python's `any(items.count(v) >= 2 for v in T)`; SQL's `EXISTS
/// (SELECT 1 FROM GROUP BY variant HAVING COUNT(*) >= 2)` on a
/// relational carrier — the canonical set-level any-repeat witness.
/// Translation through pleme-io primitives: the N-ary any-repeat
/// predicate on the closed-set trait binds through the substrate's
/// [`Self::max_variant_count`] projection compared meet-or-exceed
/// against `2` — no new dep, no supertrait bound (the
/// [`Self::max_variant_count`] projection replaces the
/// `Eq`/`Hash` bound the standard-library any/group-by signatures
/// demand), no set-shape carrier, no allocation.
fn is_repeating_any(items: &[Self]) -> bool {
<Self as ClosedSet>::max_variant_count(items) >= 2
}
/// The N-ARY ORDERING-AGNOSTIC "any variant unique?" predicate —
/// `true` iff AT LEAST ONE variant of [`Self::ALL`] appears EXACTLY
/// ONCE in `items`, computed as the disjunction over [`Self::ALL`]
/// of the per-target [`Self::is_unique_occurrence_of`] predicate.
/// The BOOL-RETURN closer on the (set-level × bool × multiplicity-
/// band) 3-corner existential-lift face at its final `== 1`
/// corner peer to the (set-level × bool × multiplicity-band `== 0`)
/// [`Self::is_missing_any`] corner and the (set-level × bool ×
/// multiplicity-band `>= 2`) [`Self::is_repeating_any`] corner
/// one MULTIPLICITY-BAND axis over, AND the direct SET-LEVEL
/// EXISTENTIAL LIFT of the (per-target × bool × multiplicity-band
/// `== 1`) [`Self::is_unique_occurrence_of`] corner one ARITY
/// axis over on the (arity × mult-band) face of the equivalence-
/// partition surface. Not a fresh substrate primitive on the
/// index axis — the predicate emerges from one existential
/// disjunction over [`Self::ALL`] of the per-target multiplicity-
/// `== 1` predicate, equivalently the histogram vector's
/// containment of the scalar `1`.
///
/// Existential-lift identity: for every slice `items`,
/// `T::is_unique_any(items) == <T as ClosedSet>::ALL.iter().any(|&v| T::is_unique_occurrence_of(v, items))`
/// — the set-level bool predicate is the EXACT existential
/// quantification over [`Self::ALL`] of the per-target multiplicity-
/// ==1 predicate. This identity binds the set-level ARITY axis
/// against the per-target ARITY axis one arity axis over on the
/// (arity × mult-band) face, pinning the compounding closure the
/// prior per-target lift opened as the middle band of the
/// trichotomy. Pinned by clause (114) and by
/// `is_unique_any_equals_existential_of_is_unique_occurrence_of_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::is_unique_any(items) == <T as ClosedSet>::variant_counts(items).contains(&1)`
/// — the set-level bool predicate is EXACTLY the containment test
/// of the scalar `1` in the per-slot histogram vector. Independent
/// cross-check distinct from the existential-lift arm on the
/// return-shape (`Vec<usize>` vs the per-target `bool` predicate)
/// axis. Pinned by
/// `is_unique_any_holds_iff_variant_counts_contains_one_across_every_triple`.
///
/// Trichotomy-closure identity: the (set-level × bool ×
/// multiplicity-band) 3-corner existential-lift face on the
/// equivalence-partition surface now CLOSES EXHAUSTIVELY at three
/// disjoint bands — (mult `== 0`) via [`Self::is_missing_any`],
/// (mult `== 1`) via THIS PREDICATE, and (mult `>= 2`) via
/// [`Self::is_repeating_any`]. Every position on the set-level
/// existential-multiplicity axis now binds to exactly ONE typed
/// predicate on the trait; the trichotomy partition is a TYPED
/// THEOREM the substrate proves once and every downstream
/// consumer routes through — peer posture one arity axis over to
/// the (per-target × bool × multiplicity-band) trichotomy the
/// prior three lifts closed via (`!occurs_in`,
/// `is_unique_occurrence_of`, `is_repeated_occurrence_of`).
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// this predicate because it factors through
/// [`Self::is_unique_occurrence_of`] (itself ordering-agnostic)
/// via a standard-library `any` combinator over the closed set.
/// No separate `sorted_is_unique_any` peer is needed. Pinned by
/// `is_unique_any_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::is_unique_any(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant multiplicity is `0` and the per-target
/// `== 1` test fails at every target. The empty-slice arm is
/// LOAD-BEARING as the drift catch for an override that folds
/// onto `true` unconditionally (empty slice is the smallest
/// slice where the correct answer is `false`). Pinned by clause
/// (114) and by
/// `is_unique_any_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::is_unique_any(<T as ClosedSet>::ALL)`
/// is `true` on every implementor of non-zero cardinality — the
/// closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants
/// as pairwise distinct, so every variant of [`Self::ALL`] appears
/// at EXACTLY ONE position in the full-set slice; every per-target
/// multiplicity is `1` and the existential disjunction fires at
/// the first variant. The full-set arm is LOAD-BEARING as the
/// drift catch for an override that folds onto `false`
/// unconditionally — at cardinality `>= 1` the correct answer is
/// `true` (any variant is a witness), so a `_ => false` override
/// bifurcates loudly. Pinned by clause (114) at the full-set
/// fixpoint AND by
/// `is_unique_any_over_the_full_set_is_true_across_every_non_degenerate_kind`.
///
/// Doubled-full-set contract: `T::is_unique_any(&doubled)` is
/// `false` on every implementor of non-zero cardinality — the
/// doubled full set hits every variant at EXACTLY TWO positions,
/// so every per-target multiplicity is `2` and the per-target
/// `== 1` test fails at every target. Together with the full-set
/// arm (which pins the `true` fixpoint at cardinality `>= 1`),
/// the doubled-full-set arm demonstrates that the predicate
/// TRANSITIONS from `true` (at the canonical permutation) to
/// `false` (at the canonical repetition) purely through the
/// per-target multiplicity band change — pinning the projection
/// as a strict `== 1` predicate rather than the weaker `>= 1`
/// membership predicate [`Self::is_covering`]. Pinned by clause
/// (114) at the doubled-full-set fixpoint AND by
/// `is_unique_any_returns_false_on_the_doubled_full_set_across_every_non_degenerate_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_unique_occurrence_of`] via the standard-library
/// `any` combinator over [`Self::ALL`]. The sweep cost is
/// O(T::CARDINALITY * n) on slice arity `n` — one per-target
/// multiplicity primitive per variant, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
/// Short-circuiting: the `any` combinator halts at the first
/// witness variant, so the average-case cost drops proportionally
/// with the density of unique-multiplicity variants.
///
/// Future consumers that compose against [`Self::is_unique_any`]:
/// a `tatara-check` predicate `(check-phases-report-any-unique …)`
/// on a `WorkloadPhase` sequence that flags "some phase visited
/// exactly once" (a canary-witness distinct from a re-convergence
/// loop OR a never-visited phase) without paying for the modal-
/// count histogram when only the existence of a singleton matters;
/// an LSP diagnostic on a Lisp-author-written variant-list that
/// flags "some variant occurs exactly once" as a completion hint
/// distinct from full-coverage OR repeated-usage; a Sekiban audit-
/// trail metric flagging a classification poset window as
/// "any-classification-singleton" WITHOUT emitting the per-slot
/// histogram; a `tatara-lisp::macro_expand::Expander` hygiene
/// pass that flags a template's identifier multiset as CARRYING
/// SOME LINEAR BINDING (a variable used exactly once — the shape
/// of a linearity-lint diagnostic distinct from unbound OR
/// re-bound identifiers) in ONE typed bool. Each binds to ONE
/// typed N-ary any-unique predicate on the trait rather than
/// re-deriving the `T::ALL.iter().any(|v| T::count_occurrences_of(v, items) == 1)`
/// disjunction OR the `T::variant_counts(items).contains(&1)`
/// histogram-arm inline per callsite.
///
/// Compounding closure: the (set-level × bool × multiplicity-band)
/// 3-corner existential-lift face on the equivalence-partition
/// surface now CLOSES EXHAUSTIVELY at three disjoint corners
/// covering the trichotomy (`== 0`, `== 1`, `>= 2`). The natural
/// next lift past this closure is the SET-LEVEL UNIVERSAL LIFT
/// face — `is_uniformly_repeating` (∀v : count(v) >= 2, the
/// universal peer to this predicate's existential; equivalently
/// `min_variant_count(items) >= 2` on a covering slice) — opening
/// the (set-level × bool × mult-band × quantifier) 4th-axis
/// hypercube at its universal-`>= 2` corner peer to the existing
/// (set-level × universal × mult `>= 1`) [`Self::is_covering`]
/// corner and (set-level × universal × mult `<= 1`)
/// [`Self::is_pairwise_distinct`] corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary any-
/// unique predicate becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline existential over
/// the per-target multiplicity-`== 1` predicate at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (set-level × bool × mult `== 1`) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "did some variant occur exactly once?" site pre-lift. Naming
/// it on the trait makes the predicate a TYPED CONSEQUENCE of
/// the substrate's per-target uniqueness primitive lifted
/// set-level via the standard-library `any` combinator — AND
/// closes the (set-level × bool × multiplicity-band) existential-
/// lift trichotomy as a TYPED THEOREM the substrate proves
/// once. THEORY.md §VI.1 — generation over composition; the any-
/// unique predicate emerges from the composition of ONE substrate
/// primitive ([`Self::is_unique_occurrence_of`]) with an
/// `iter().copied().any(…)` combinator over [`Self::ALL`], not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `existsb (fun v => Nat.eqb 1
/// (count_occ eqb l v)) all` decidable-equality-derived any-
/// unique test on `list nat`; Idris's `any (\v => count (== v)
/// items == 1) all` on a `Vect n a`; Racket's `(ormap (λ (v)
/// (= (count (λ (w) (equal? v w)) items) 1)) all)`; Julia's
/// `any(v -> count(==(v), items) == 1, all)`; Haskell's `any
/// (\v -> length (filter (== v) items) == 1) all`; Rust's own
/// `T::ALL.iter().any(|v| items.iter().filter(|w| v == w).count() == 1)`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `any(items.count(v) == 1 for v in all)`; SQL's `EXISTS
/// (SELECT 1 FROM GROUP BY variant HAVING COUNT(*) = 1)` — the
/// canonical set-level any-singleton witness. Translation through
/// pleme-io primitives: the N-ary any-unique predicate on the
/// closed-set trait binds through an `iter().copied().any(…)`
/// combinator over [`Self::ALL`] with the substrate's per-target
/// uniqueness primitive inside — no new dep, no supertrait bound
/// (the [`Self::is_unique_occurrence_of`] primitive replaces the
/// `Eq`/`Hash` bound the standard-library any/group-by
/// signatures demand), no set-shape carrier, no allocation.
fn is_unique_any(items: &[Self]) -> bool {
<Self as ClosedSet>::ALL
.iter()
.copied()
.any(|v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
}
/// The N-ARY ORDERING-AGNOSTIC "count of unique-multiplicity
/// variants" projection — the `usize` count of variants of
/// [`Self::ALL`] whose per-target multiplicity in `items` equals
/// EXACTLY `1`, computed as the `.count()` reduction of
/// [`Self::ALL`] filtered through the per-target
/// [`Self::is_unique_occurrence_of`] predicate. The SET-LEVEL
/// USIZE-RETURN closer on the (set-level × usize × multiplicity-
/// band) 3-corner face at the middle band peer to the (set-level
/// × usize × multiplicity-band `== 0`) [`Self::count_missing`]
/// corner one MULTIPLICITY-BAND axis over, AND the direct
/// USIZE-RETURN SHARPENING of the (set-level × bool ×
/// multiplicity-band `== 1`) [`Self::is_unique_any`] corner one
/// return-shape axis over — while [`Self::is_unique_any`] reports
/// "IS THERE at least one variant occurring exactly once?" (a
/// set-level `bool`), this projection reports "HOW MANY variants
/// occur exactly once?" (a set-level `usize` that is a strict
/// refinement of the bool). Not a fresh substrate primitive on
/// the index axis — the count emerges from one composition of
/// [`Self::ALL`] filtered through the per-target
/// [`Self::is_unique_occurrence_of`] uniqueness primitive.
///
/// Membership-projection identity: for every slice `items`,
/// `T::is_unique_any(items) == (T::count_unique_variants(items) > 0)`
/// — the set-level bool any-unique predicate is the (nonzero-
/// fixpoint) projection of THIS usize count. The bool-return
/// existential-lift decomposes through the strict cardinality
/// count exactly. Pinned by
/// `is_unique_any_holds_iff_count_unique_variants_is_strictly_positive_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::count_unique_variants(items) == T::variant_counts(items).iter().filter(|&&c| c == 1).count()`
/// — the set-level count of unique-multiplicity variants is
/// EXACTLY the count of per-slot histogram bars equal to `1`.
/// Independent cross-check distinct from the filter-composition
/// arm on the return-shape (`Vec<usize>` vs the per-target
/// [`Self::is_unique_occurrence_of`] `bool` predicate) axis.
/// Pinned by
/// `count_unique_variants_equals_variant_counts_filter_equals_one_count_across_every_triple`.
///
/// Trichotomy-cardinality-partition identity: for every slice
/// `items`,
/// `T::count_missing(items) + T::count_unique_variants(items) + T::count_repeating_variants(items) == T::CARDINALITY`
/// — the three set-level cardinality counts on the multiplicity-
/// band trichotomy PARTITION the ambient set's cardinality
/// exactly, because every variant belongs to EXACTLY ONE of the
/// three disjoint bands (mult `== 0`, mult `== 1`, mult `>= 2`).
/// This identity binds the count-side trichotomy against the
/// [`Self::CARDINALITY`] constant as a load-bearing partition
/// invariant. (Not yet checkable — `count_repeating_variants` is
/// the next lift on the (mult `>= 2`) corner one MULTIPLICITY-
/// BAND axis over; when it lands the identity binds all three
/// counts to the substrate's forced-arity constant on every
/// slice.) The two-arm (mult `== 0` + mult `>= 1`) analogue
/// `T::count_missing(items) + T::count_distinct(items) == T::CARDINALITY`
/// is already checkable and lifts through
/// `count_unique_variants + count_repeating_variants == count_distinct`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// this count because it factors through
/// [`Self::is_unique_occurrence_of`] (itself ordering-agnostic)
/// via a standard-library `filter().count()` combinator over the
/// closed set. No separate `sorted_count_unique_variants` peer
/// is needed. Pinned by
/// `count_unique_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_unique_variants(&[])` is `0`
/// UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant multiplicity is `0` and the per-target
/// `== 1` test fails at every target. Sibling posture to
/// `is_unique_any_returns_false_on_the_empty_slice_across_every_kind`
/// one return-shape axis over: the set-level bool any-unique
/// predicate collapses to `false` at the empty slice; this
/// projection collapses to `0` at the same endpoint. Pinned by
/// `count_unique_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::count_unique_variants(<T as ClosedSet>::ALL)` is
/// `T::CARDINALITY` UNCONDITIONALLY — the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s clause
/// (3) pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] appears at EXACTLY ONE position of the full-set
/// slice; every per-target multiplicity is `1` and every variant
/// contributes to the count. Complements
/// `is_unique_any_over_the_full_set_is_true_across_every_non_degenerate_kind`
/// one return-shape axis over: the set-level bool any-unique
/// predicate reaches `true` at the full set; this count reaches
/// its `T::CARDINALITY` maximum at the same endpoint. Pinned by
/// `count_unique_variants_over_the_full_set_equals_cardinality_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_unique_variants(&<T as ClosedSet>::ALL.iter().chain(<T as
/// ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())` is `0`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// EXACTLY TWO positions, so every per-target multiplicity is `2`
/// and the per-target `== 1` test fails at every target.
/// Together with the full-set arm, the doubled-full-set arm
/// demonstrates that the projection TRANSITIONS from
/// `T::CARDINALITY` (at the canonical permutation) to `0` (at the
/// canonical repetition) purely through the per-target
/// multiplicity band change — pinning the projection as a STRICT
/// `== 1` count rather than the weaker `>= 1` presence count
/// [`Self::count_distinct`]. Pinned by
/// `count_unique_variants_returns_zero_on_the_doubled_full_set_across_every_kind`.
///
/// Bounded-above contract: for every slice `items`,
/// `T::count_unique_variants(items) <= T::CARDINALITY` AND
/// `T::count_unique_variants(items) <= T::count_distinct(items)`
/// — the count is bounded above by the ambient cardinality (there
/// are only `T::CARDINALITY` variants to sample from) AND by the
/// count of PRESENT variants (a variant with mult `== 1` is a
/// fortiori present with mult `>= 1`). The pair of upper bounds
/// partition the projection's range at the (set-level × usize)
/// slot on the equivalence-partition surface. Pinned by
/// `count_unique_variants_is_bounded_above_by_cardinality_and_count_distinct_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_unique_occurrence_of`] via the standard-library
/// `filter().count()` combinator over [`Self::ALL`]. The sweep
/// cost is O(T::CARDINALITY * n) on slice arity `n` — one per-
/// target multiplicity primitive per variant, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched). The
/// `filter().count()` composition does NOT short-circuit (unlike
/// [`Self::is_unique_any`]'s `.any(…)`), because the cardinality
/// count is a distinct output from the existential predicate.
///
/// Future consumers that compose against
/// [`Self::count_unique_variants`]: a `tatara-check` predicate
/// `(check-phases-report-unique-count …)` on a `WorkloadPhase`
/// sequence that verifies EXACTLY `k` phases are visited once
/// (rather than just "some phase is visited once" via the sibling
/// [`Self::is_unique_any`]) at plan time — a stricter linearity
/// constraint distinct from full coverage OR pure absence; an
/// LSP diagnostic on a Lisp-author-written variant-list that
/// renders the count of linearly-bound identifiers ("3 of 5
/// severities are used exactly once") rather than a mere bool
/// witness; a Sekiban audit-trail metric emitting the count of
/// canary-witness classifications across a window rather than the
/// bool witness alone; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the cardinality of linearly-bound
/// template identifiers as a scalar rather than a per-identifier
/// bool sweep. Each binds to ONE typed N-ary count-unique
/// primitive on the trait rather than re-deriving
/// `T::ALL.iter().filter(|&&v| T::count_occurrences_of(v, items) == 1).count()`
/// OR
/// `T::variant_counts(items).iter().filter(|&&c| c == 1).count()`
/// inline per callsite.
///
/// Compounding closure: the (set-level × usize × multiplicity-
/// band) 3-corner CARDINALITY-COUNT face on the equivalence-
/// partition surface now closes at TWO of three bands — (mult
/// `== 0`) via [`Self::count_missing`], and (mult `== 1`) via
/// THIS projection. The natural next lift on this surface —
/// `count_repeating_variants(items) -> usize` closing the (mult
/// `>= 2`) band peer to this one MULTIPLICITY-BAND axis over —
/// opens the strict-repeat count corner and CLOSES the set-
/// level × usize trichotomy exhaustively at three typed
/// cardinality-count primitives. Downstream consumers wanting
/// the (bool, usize) × mult-band 3×2 = 6-corner (bool-existence
/// × usize-cardinality × mult-band) hyper-face composed of
/// (`is_missing_any`, `count_missing`), (`is_unique_any`, THIS),
/// (`is_repeating_any`, `count_repeating_variants`) — three
/// paired (existential, cardinality) primitives on the same
/// multiplicity band — bind through these six primitives on
/// the substrate.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// set-level count of unique-multiplicity variants becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline
/// `T::ALL.iter().filter(|v| T::count_occurrences_of(*v, items) == 1).count()`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (set-level × usize × mult `== 1`)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "how many variants occur exactly
/// once?" site pre-lift. Naming it on the trait makes the
/// count a TYPED CONSEQUENCE of the substrate's per-target
/// uniqueness primitive [`Self::is_unique_occurrence_of`]
/// filtered through [`Self::ALL`] and reduced via `.count()`.
/// THEORY.md §VI.1 — generation over composition; the count
/// emerges from the composition of ONE substrate primitive
/// ([`Self::is_unique_occurrence_of`]) with an
/// `iter().copied().filter(…).count()` combinator over
/// [`Self::ALL`], not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `length (filter (fun v => Nat.eqb 1
/// (count_occ eqb l v)) all)` decidable-equality-derived count-
/// singleton primitive on `list nat`; Idris's `length (filter (\v
/// => count (== v) items == 1) all)` on a `Vect n a`; Racket's
/// `(length (filter (λ (v) (= (count (λ (w) (equal? v w)) items) 1)) all))`;
/// Julia's `count(v -> count(==(v), items) == 1, all)`; Haskell's
/// `length (filter (\v -> length (filter (== v) items) == 1) all)`;
/// Rust's own
/// `T::ALL.iter().filter(|v| items.iter().filter(|w| v == *w).count() == 1).count()`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `sum(1 for v in all if items.count(v) == 1)`; SQL's `SELECT
/// COUNT(*) FROM (SELECT variant FROM t GROUP BY variant HAVING
/// COUNT(*) = 1)` — the canonical set-level singleton-cardinality
/// count. Translation through pleme-io primitives: the N-ary
/// set-level unique-variant count on the closed-set trait binds
/// through an `iter().copied().filter(…).count()` combinator
/// over [`Self::ALL`] with the substrate's per-target uniqueness
/// primitive inside — no new dep, no supertrait bound (the
/// [`Self::is_unique_occurrence_of`] primitive replaces the
/// `Eq`/`Hash` bound the standard-library group-by signatures
/// demand), no set-shape carrier, no allocation.
fn count_unique_variants(items: &[Self]) -> usize {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
.count()
}
/// The N-ARY ORDERING-AGNOSTIC "how many variants occur two or
/// more times?" cardinality-count projection — the `usize`
/// SET-LEVEL count of variants of [`Self::ALL`] whose per-target
/// multiplicity in `items` is STRICTLY AT LEAST `2`, computed as
/// the filter-count reduction over [`Self::ALL`] of the per-target
/// [`Self::is_repeated_occurrence_of`] predicate. The USIZE-RETURN
/// closer on the (set-level × usize × multiplicity-band) 3-corner
/// cardinality-count face at its final `>= 2` strict-repeat
/// corner peer to the (set-level × usize × multiplicity-band
/// `== 0`) [`Self::count_missing`] corner and the (set-level ×
/// usize × multiplicity-band `== 1`) [`Self::count_unique_variants`]
/// corner one MULTIPLICITY-BAND axis over, AND the direct SET-
/// LEVEL EXISTENTIAL-COUNT SHARPENING of the (set-level × bool ×
/// multiplicity-band `>= 2`) [`Self::is_repeating_any`] predicate
/// one return-shape axis over (bool-return → usize-return via
/// cardinality sharpening) on the (arity × mult-band × return-
/// shape) face of the equivalence-partition surface. Not a fresh
/// substrate primitive on the index axis — the count emerges from
/// one filter-count reduction over [`Self::ALL`] of the per-target
/// multiplicity-`>= 2` predicate, equivalently the count of per-
/// slot histogram bars strictly at least `2`.
///
/// Filter-count identity: for every slice `items`,
/// `T::count_repeating_variants(items) == <T as ClosedSet>::ALL.iter().filter(|&&v| T::is_repeated_occurrence_of(v, items)).count()`
/// — the set-level count is the EXACT filter-count reduction over
/// [`Self::ALL`] of the per-target multiplicity-≥2 predicate. This
/// identity binds the set-level ARITY axis against the per-target
/// ARITY axis one arity axis over on the (arity × mult-band) face,
/// pinning the compounding closure the prior per-target lift opened
/// as the strict-repeat band of the trichotomy. Pinned by clause
/// (116) and by
/// `count_repeating_variants_equals_variant_counts_filter_ge_two_count_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::count_repeating_variants(items) == <T as ClosedSet>::variant_counts(items).iter().filter(|&&c| c >= 2).count()`
/// — the set-level count is EXACTLY the count of per-slot
/// histogram bars whose scalar height is at least `2`. Independent
/// cross-check distinct from the filter-count arm on the return-
/// shape (`Vec<usize>` vs the per-target `bool` predicate) axis.
/// Pinned by
/// `count_repeating_variants_equals_variant_counts_filter_ge_two_count_across_every_triple`.
///
/// Trichotomy-partition identity (LOAD-BEARING): for every slice
/// `items`,
/// `T::count_missing(items) + T::count_unique_variants(items) + T::count_repeating_variants(items) == T::CARDINALITY`
/// — the three set-level cardinality-count corners of the
/// (multiplicity-band) trichotomy on `T::ALL` PARTITION the
/// `T::CARDINALITY`-many variants of the ambient closed set EXACTLY
/// (every variant lands in EXACTLY ONE of the three bands (mult
/// `== 0`, mult `== 1`, mult `>= 2`) at every slice). The equality
/// is the arithmetic witness of the trichotomy partition — an
/// override that inflates or deflates any of the three corners
/// bifurcates the identity loudly. Pinned by clause (116) at all
/// three canonical fixpoints AND by
/// `count_missing_plus_count_unique_variants_plus_count_repeating_variants_partitions_cardinality_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_repeated_occurrence_of`] (itself ordering-agnostic)
/// via a standard-library `filter().count()` combinator over the
/// closed set. No separate `sorted_count_repeating_variants` peer
/// is needed. Pinned by
/// `count_repeating_variants_is_invariant_under_ordering_axis_across_every_triple`.
///
/// Empty-slice contract: `T::count_repeating_variants(&[])` is
/// `0` UNCONDITIONALLY — the empty slice hits zero positions, so
/// every per-variant multiplicity is `0` and the per-target
/// `>= 2` test fails at every target. Pinned by clause (116) and
/// by
/// `count_repeating_variants_returns_zero_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::count_repeating_variants(T::ALL)` is
/// `0` on every implementor — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3) pins
/// variants as pairwise distinct, so every variant of [`Self::ALL`]
/// appears at EXACTLY ONE position of the full-set slice; every
/// per-target multiplicity is `1` and the per-target `>= 2` test
/// fails at every target. Pinned by clause (116) at the full-set
/// fixpoint AND by
/// `count_repeating_variants_over_the_full_set_returns_zero_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::count_repeating_variants(T::ALL ++ T::ALL)` is
/// `T::CARDINALITY` on every implementor — the doubled full set
/// hits every variant at EXACTLY TWO positions, so every per-
/// target multiplicity is `2` and every variant contributes to
/// the count. Together with the full-set arm (which pins the `0`
/// fixpoint at the canonical permutation), the doubled-full-set
/// arm demonstrates that the projection TRANSITIONS from `0` (at
/// the canonical permutation) to `T::CARDINALITY` (at the
/// canonical repetition) purely through the per-target
/// multiplicity band change — pinning the projection as a STRICT
/// `>= 2` count rather than the weaker `>= 1` presence count
/// [`Self::count_distinct`] which reports `T::CARDINALITY` on
/// BOTH the full set and the doubled full set. Pinned by clause
/// (116) at the doubled-full-set fixpoint AND by
/// `count_repeating_variants_over_the_doubled_full_set_equals_cardinality_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_repeated_occurrence_of`] via the standard-library
/// `filter().count()` combinator over [`Self::ALL`]. The sweep
/// cost is O(T::CARDINALITY * n) on slice arity `n` — one per-
/// target multiplicity scan per variant of the ambient closed
/// set — with NO short-circuit (the projection reports a scalar
/// cardinality distinct from the sibling [`Self::is_repeating_any`]
/// bool witness which DOES short-circuit at the first witness).
/// The count materializes as a scalar `usize` return value from a
/// standard-library `Iterator::count` combinator; no allocation,
/// no set-shape carrier, no supertrait bound (the
/// [`Self::is_repeated_occurrence_of`] primitive replaces the
/// `Eq`/`Hash` bound the standard-library group-by signatures
/// demand). The default trait body threads the filter-count
/// reduction verbatim and satisfies every fixpoint arm + every
/// composition-equality arm for free; every implementor gets
/// THIS projection.
///
/// The strict-repeat count CLOSES the (set-level × usize ×
/// multiplicity-band) 3-corner cardinality-count trichotomy
/// exhaustively at three typed cardinality-count primitives —
/// (mult `== 0`) via [`Self::count_missing`], (mult `== 1`) via
/// [`Self::count_unique_variants`], and (mult `>= 2`) via THIS
/// PROJECTION. Every position on the set-level cardinality-count
/// multiplicity axis now binds to exactly ONE typed count on the
/// trait; the trichotomy partition is a TYPED THEOREM the
/// substrate proves once and every downstream consumer routes
/// through — peer posture one return-shape axis over to the
/// (set-level × bool × multiplicity-band) trichotomy the prior
/// three lifts closed via (`is_missing_any`, `is_unique_any`,
/// `is_repeating_any`). Downstream consumers wanting the
/// (bool, usize) × mult-band 3×2 = 6-corner (bool-existence ×
/// usize-cardinality × mult-band) hyper-face composed of
/// (`is_missing_any`, `count_missing`), (`is_unique_any`,
/// `count_unique_variants`), (`is_repeating_any`, THIS) — three
/// paired (existential, cardinality) primitives on the same
/// multiplicity band — bind through these six primitives on the
/// substrate.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// set-level count of strict-repeat-multiplicity variants
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::ALL.iter().filter(|v| T::count_occurrences_of(*v, items) >= 2).count()`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (set-level × usize × mult
/// `>= 2`) corner was an unnamed inline composition recurring at
/// every prospective downstream "how many variants occur two or
/// more times?" site pre-lift. Naming it on the trait makes the
/// count a TYPED CONSEQUENCE of the substrate's per-target
/// strict-repeat primitive [`Self::is_repeated_occurrence_of`]
/// filtered through [`Self::ALL`] and reduced via `.count()`;
/// AND makes the LOAD-BEARING trichotomy-partition identity
/// `count_missing + count_unique_variants + count_repeating_variants == T::CARDINALITY`
/// a substrate-level THEOREM the well-formedness contract pins
/// once rather than a per-consumer inline sanity check.
/// THEORY.md §VI.1 — generation over composition; the count
/// emerges from the composition of ONE substrate primitive
/// ([`Self::is_repeated_occurrence_of`]) with an
/// `iter().copied().filter(…).count()` combinator over
/// [`Self::ALL`], not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `length (filter (fun v => 2 <=?
/// count_occ eqb l v) all)` decidable-equality-derived count-
/// repeat primitive on `list nat`; Idris's `length (filter (\v
/// => count (== v) items >= 2) all)` on a `Vect n a`; Racket's
/// `(length (filter (λ (v) (>= (count (λ (w) (equal? v w)) items) 2)) all))`;
/// Julia's `count(v -> count(==(v), items) >= 2, all)`; Haskell's
/// `length (filter (\v -> length (filter (== v) items) >= 2) all)`;
/// Rust's own
/// `T::ALL.iter().filter(|v| items.iter().filter(|w| v == *w).count() >= 2).count()`
/// binds through a `Self: PartialEq` supertrait bound; Python's
/// `sum(1 for v in all if items.count(v) >= 2)`; SQL's `SELECT
/// COUNT(*) FROM (SELECT variant FROM t GROUP BY variant HAVING
/// COUNT(*) >= 2)` — the canonical set-level strict-repeat-
/// cardinality count. Translation through pleme-io primitives:
/// the N-ary set-level strict-repeat count on the closed-set
/// trait binds through an `iter().copied().filter(…).count()`
/// combinator over [`Self::ALL`] with the substrate's per-target
/// strict-repeat primitive inside — no new dep, no supertrait
/// bound (the [`Self::is_repeated_occurrence_of`] primitive
/// replaces the `Eq`/`Hash` bound the standard-library group-by
/// signatures demand), no set-shape carrier, no allocation.
fn count_repeating_variants(items: &[Self]) -> usize {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::is_repeated_occurrence_of(v, items))
.count()
}
/// The N-ARY ORDERING-AGNOSTIC "does the STRICT-REPEAT band fall on
/// a UNIQUE variant?" set-level predicate — `true` iff EXACTLY ONE
/// variant of [`Self::ALL`] carries an occurrence-count STRICTLY AT
/// LEAST `2` in `items`, computed as the strict-equality test of the
/// just-lifted [`Self::count_repeating_variants`] cardinality-count
/// aggregate against the scalar threshold `1`. The BOOL-RETURN
/// UNIQUE-TIE SHARPENING corner OPENING the (set-level × bool ×
/// equivalence-partition × multiplicity-band × unique-tie) row on the
/// EQUIVALENCE-PARTITION surface at its (mult `>= 2`) band, peer to
/// [`Self::count_repeating_variants`] one RETURN-SHAPE axis over
/// (set-level × `usize` cardinality → set-level × `bool` uniqueness
/// test against `1`), peer to [`Self::is_repeating_any`] one UNIQUE-
/// TIE-SHARPENING axis over (existential `>= 1` → uniqueness `== 1`)
/// AND peer to [`Self::has_unique_extremal_variant`] +
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::has_unique_bimodal_variant`] one SURFACE axis over — those
/// three land the same unique-tie sharpening on the modal-
/// AGGREGATION surface (direction-composition × combinator); THIS
/// projection lands it on the equivalence-PARTITION surface
/// (multiplicity-band). Not a fresh substrate primitive on the index
/// axis — the predicate emerges from one strict-equality test of the
/// just-lifted [`Self::count_repeating_variants`] scalar against `1`,
/// equivalently the [`Vec::len`] equality of the declaration-order
/// strict-repeat witness-collection [`Self::repeating_variants`]
/// against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_repeating_variant(items) ==
/// (T::count_repeating_variants(items) == 1)` — the set-level bool
/// predicate is EXACTLY the strict-equality test of the just-lifted
/// set-level cardinality-count aggregate against the scalar threshold
/// `1`. The canonical form the body uses. Pinned by
/// `has_unique_repeating_variant_equals_count_repeating_variants_eq_one_across_every_triple`.
///
/// Strict-repeat witness length identity: for every slice `items`,
/// `T::has_unique_repeating_variant(items) ==
/// (T::repeating_variants(items).len() == 1)` — the set-level bool
/// predicate is EXACTLY the length-equality test of the declaration-
/// order strict-repeat witness-collection against `1`. Independent
/// cross-check distinct from the count-composition arm on the
/// surface axis (Vec-length vs scalar equality). Pinned by
/// `has_unique_repeating_variant_agrees_with_repeating_variants_len_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_repeating_variant(items) ==>
/// T::is_repeating_any(items)` — a UNIQUE strict-repeat witness
/// trivially entails the EXISTENCE of a strict-repeat witness (the
/// unique-tie sharpening `count == 1` implies the existential
/// `count >= 1`). Pinned by
/// `has_unique_repeating_variant_implies_is_repeating_any_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_repeating_variants`] (ordering-agnostic) via a
/// scalar equality test against a fixed constant. No separate
/// `sorted_has_unique_repeating_variant` peer is needed. Pinned by
/// `has_unique_repeating_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_repeating_variant(&[])` is
/// `false` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_repeating_variants`] collapses to `0` at its empty-
/// slice guard, and `0 != 1`. The `false`-at-empty fixpoint pins
/// strict-repeat uniqueness as a NON-EMPTINESS-REQUIRING property.
///
/// Matching-singleton contract: `T::has_unique_repeating_variant(&[v])`
/// is `false` for every variant `v` — the sole position hits `v` at
/// count `1` (not repeating), every non-target variant sits at count
/// `0` (also not repeating), [`Self::count_repeating_variants`]
/// reports `0`, and `0 != 1`.
///
/// Full-set contract: `T::has_unique_repeating_variant(T::ALL)` is
/// `false` on every implementor — clause (3)'s pairwise-distinctness
/// invariant pins every variant at exactly one position of the full-
/// set slice; every per-target multiplicity is `1` and the per-target
/// `>= 2` test fails at every target; [`Self::count_repeating_variants`]
/// reports `0` and `0 != 1`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::has_unique_repeating_variant(T::ALL ++ T::ALL)` is `false` on
/// every implementor with `T::CARDINALITY >= 2` — the doubled full
/// set hits every variant at EXACTLY TWO positions, every per-target
/// multiplicity is `2 >= 2`, and every variant contributes to the
/// count; [`Self::count_repeating_variants`] reports `T::CARDINALITY`,
/// and `T::CARDINALITY >= 2 != 1`. The SOLE positive arm on the
/// doubled-full-set fixpoint sits at `T::CARDINALITY == 1` where a
/// doubled singleton `[T::ALL[0], T::ALL[0]]` collapses the strict-
/// repeat count to `1` and the equality holds.
///
/// Bimodal-triple contract at cardinality `>= 3`: on the canonical
/// non-flat triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]`
/// sits at count `2 >= 2` (the SOLE strict-repeat witness),
/// `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
/// [`Self::count_repeating_variants`] reports `1` and `1 == 1`.
/// LOAD-BEARING `true`-arm catch DISCRIMINATING this equivalence-
/// partition uniqueness corner from the sibling
/// [`Self::has_unique_extremal_variant`] and
/// [`Self::has_unique_bimodal_variant`] DEGENERATE openers on the
/// modal-aggregation surface at the same fixture (where the union +
/// intersection direction-composition arms both fold to `false` via
/// the `count >= 2` inclusion-exclusion collapse). The equivalence-
/// partition (mult `>= 2`) unique-tie corner and the modal-
/// aggregation direction-composition unique-tie corners split on
/// the canonical bimodal fixture — the substrate SURFACE axis
/// discriminates the two uniqueness bands. Sibling posture to
/// [`Self::has_unique_middle_band_variant`] (which reports `true` at
/// T::ALL[1] on the same fixture via the direction-composition
/// complement arm): both the equivalence-partition (mult `>= 2`)
/// corner AND the modal-aggregation direction-composition complement
/// corner report `true` on the bimodal triple; their (mult `>= 2`)
/// witness is T::ALL[0] and their strictly-interior witness is
/// T::ALL[1] — DISJOINT variants pinning the two surfaces as
/// independent uniqueness signals on the same slice.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_repeating_variants`] via one scalar equality test on
/// `usize`. The sweep cost inherits the strict-repeat count aggregate:
/// `O(T::CARDINALITY * n)` on slice arity `n`, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::has_unique_repeating_variant`]: a `tatara-check` predicate
/// `(check-strict-repeat-is-unique …)` that reports "the sole
/// strictly-repeating variant is unambiguous" in ONE typed bool
/// rather than a Vec-length or count-and-compare composition; a
/// Sekiban audit-trail bit `strict_repeat_uniqueness_bit(items)`
/// binding to the same scalar, composable with a future
/// `unique_repeating_variant -> Option<Self>` witness-if-unique
/// projection into a typed `(unique-strict-repeat-bit, unique-strict-
/// repeat-witness)` classifier per window; an LSP hint on a Lisp-
/// authored histogram that surfaces "this slice has EXACTLY ONE
/// repeating variant" without allocating the strict-repeat witness-
/// Vec; a scheduler-fairness heuristic that branches on "is worker X
/// the sole double-scheduled worker in this window?". Each binds to
/// ONE typed set-level `bool` predicate on the trait rather than
/// re-deriving `T::count_repeating_variants(items) == 1` inline per
/// callsite OR paying the Vec allocation
/// `T::repeating_variants(items).len() == 1` would demand.
///
/// Compounding closure: this projection OPENS the (set-level × bool
/// × equivalence-partition × multiplicity-band × unique-tie) row on
/// the equivalence-partition surface at its (mult `>= 2`) band, peer
/// to the just-lifted [`Self::has_unique_extremal_variant`] +
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::has_unique_bimodal_variant`] triple one SURFACE axis over
/// on the modal-aggregation matrix — the four together lay down the
/// unique-tie sharpening on BOTH surfaces of the closed-set trait's
/// bool-return set-level uniqueness face. The natural next lifts
/// past this corner are the two peer multiplicity-band arms —
/// `has_unique_missing_variant(items) == (count_missing == 1)` (mult
/// `== 0` opener) and `has_unique_unique_variant(items) ==
/// (count_unique_variants == 1)` (mult `== 1` opener) — closing the
/// (set-level × bool × equivalence-partition × mult-band × unique-
/// tie) 3-corner row on the trichotomy; downstream a peer
/// `unique_repeating_variant() -> Option<Self>` witness-if-unique
/// projection one RETURN-SHAPE axis over lifts the same predicate to
/// the Option-return column; a peer per-target arity lift
/// `is_unique_repeating_variant_of(target, items)` one ARITY axis
/// over closes the per-target column via
/// `is_repeated_occurrence_of(target, items) && has_unique_repeating_variant(items)`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level strict-repeat uniqueness bool predicate becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline `T::count_repeating_variants(items) == 1`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × bool × equivalence-partition
/// × mult `>= 2` × unique-tie) corner was an unnamed inline
/// composition recurring at every prospective downstream "is there
/// EXACTLY ONE repeating variant?" site pre-lift. Naming it on the
/// trait makes the predicate a TYPED CONSEQUENCE of the substrate's
/// just-lifted strict-repeat count aggregate. THEORY.md §VI.1 —
/// generation over composition; the predicate emerges from the
/// composition of ONE substrate primitive
/// ([`Self::count_repeating_variants`]) with a scalar equality
/// against `1`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); sum(t >= 2) == 1 }`
/// — the strict-repeat uniqueness test on a factor histogram;
/// Julia's `count(v -> v >= 2, values(StatsBase.countmap(items))) == 1`;
/// Python's `sum(1 for c in collections.Counter(items).values() if c >= 2) == 1`;
/// Haskell's `length (filter (>= 2) . map length . group . sort $ items) == 1`;
/// Clojure's `(= 1 (count (filter #(>= (val %) 2) (frequencies coll))))`;
/// SQL's `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant HAVING c >= 2)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// strict-repeat uniqueness predicate on the closed-set trait binds
/// through the just-lifted [`Self::count_repeating_variants`] scalar
/// against the constant `1` — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` on slice arity `n` inherited verbatim
/// from the strict-repeat count aggregate.
fn has_unique_repeating_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_repeating_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique strict-repeat variant"
/// projection — `Some(v)` iff `items` has a UNIQUE strict-repeat
/// witness ([`Self::has_unique_repeating_variant`] holds) AND `v` is
/// the sole variant whose per-target multiplicity in `items` sits
/// STRICTLY AT LEAST `2` (equivalently, the sole variant on
/// [`Self::ALL`] satisfying [`Self::is_repeated_occurrence_of`] at
/// this slice), else `None`. Computed as the just-lifted set-level
/// strict-repeat uniqueness bit [`Self::has_unique_repeating_variant`]
/// guarding a declaration-order first-witness sweep of [`Self::ALL`]
/// through the substrate's per-target strict-repeat primitive
/// [`Self::is_repeated_occurrence_of`]: when the guard holds the
/// sweep hits EXACTLY ONE variant and the sole witness lifts through
/// verbatim; when the guard falsifies the projection collapses to
/// `None`. The `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner
/// OPENING the (set-level × `Option<Self>` × equivalence-partition ×
/// multiplicity-band `>= 2` × unique-tie) column past the just-
/// lifted [`Self::has_unique_repeating_variant`] one RETURN-SHAPE
/// axis over (set-level × `bool` strict-repeat uniqueness bit →
/// set-level × `Option<Self>` strict-repeat witness-when-unique) AND
/// peer to [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] one SURFACE axis over — those
/// three land the same `Option<Self>` uniqueness-guarded witness on
/// the MODAL-AGGREGATION surface (direction-composition × combinator);
/// THIS projection lands it on the EQUIVALENCE-PARTITION surface
/// (multiplicity-band). Not a fresh substrate primitive on the index
/// axis — the projection emerges from the just-lifted set-level
/// strict-repeat uniqueness bit guarding a first-witness sweep of
/// [`Self::ALL`] through the substrate's per-target strict-repeat
/// primitive under an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_repeating_variant(items) == if T::has_unique_repeating_variant(items) { T::ALL.iter().copied().find(|&v| T::is_repeated_occurrence_of(v, items)) } else { None }`
/// — the canonical form the body uses. Pinned by
/// `unique_repeating_variant_equals_has_unique_repeating_variant_gated_find_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_repeating_variant(items).is_some() == T::has_unique_repeating_variant(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level strict-repeat uniqueness bit. Independent cross-check
/// on the surface axis (`Option::is_some` vs conditional-Option
/// construction). Pinned by
/// `unique_repeating_variant_is_some_iff_has_unique_repeating_variant_across_every_triple`.
///
/// Strict-repeat witness singleton identity: for every slice `items`,
/// `T::unique_repeating_variant(items) == (if T::repeating_variants(items).len() == 1 { Some(T::repeating_variants(items)[0]) } else { None })`
/// — when `items` has a unique strict-repeat witness, the
/// declaration-order strict-repeat witness-collection
/// [`Self::repeating_variants`] collapses to a length-`1` Vec
/// containing EXACTLY that unique variant, so its slot-`0` wrapped
/// in `Some` coincides with THIS projection. Independent cross-check
/// on the witness-Vec surface axis distinct from the guarded-find
/// arm. Pinned by
/// `unique_repeating_variant_agrees_with_repeating_variants_singleton_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_repeating_variant`] (ordering-agnostic — the
/// underlying [`Self::count_repeating_variants`] is invariant under
/// slice-reversal) and the per-target
/// [`Self::is_repeated_occurrence_of`] primitive (ordering-agnostic —
/// factored through [`Self::count_occurrences_of`]) via a boolean-
/// guarded first-witness sweep of [`Self::ALL`] (declaration-order,
/// independent of `items`' ordering). No separate
/// `sorted_unique_repeating_variant` peer is needed until the
/// sibling LEX corner is opened. Pinned by
/// `unique_repeating_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_repeating_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_repeating_variant`] collapses to `false` via
/// its `count_repeating_variants(&[]) == 0 != 1` fixpoint, and the
/// guard-arm short-circuit maps the empty slice to `None` before the
/// per-target strict-repeat sweep is consulted.
///
/// Full-set contract:
/// `T::unique_repeating_variant(<T as ClosedSet>::ALL) == None` —
/// clause (3)'s pairwise-distinctness invariant pins every variant
/// at exactly one position of the full-set slice, every per-target
/// multiplicity is `1`, [`Self::count_repeating_variants`] reports
/// `0`, [`Self::has_unique_repeating_variant`] returns `false`, and
/// the guard collapses the projection to `None`.
///
/// Matching-singleton contract: `T::unique_repeating_variant(&[v])
/// == None` for every variant `v` — the sole position hits `v` at
/// count `1` (not strictly repeating), every non-target sits at
/// count `0` (also not strictly repeating);
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses to `None`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_repeating_variant(&doubled) == None` — the doubled
/// full set hits every variant at EXACTLY TWO positions, every per-
/// target multiplicity is `2 >= 2`, EVERY variant is a strict-
/// repeat witness, [`Self::count_repeating_variants`] reports
/// `T::CARDINALITY >= 2`, [`Self::has_unique_repeating_variant`]
/// returns `false` (multiple witnesses, no unique one), and the
/// guard collapses to `None`. At cardinality `== 1` the doubled
/// slice `[T::ALL[0], T::ALL[0]]` collapses the strict-repeat count
/// to `1`, [`Self::has_unique_repeating_variant`] returns `true`,
/// and the guarded find lands on `T::ALL[0]`.
///
/// Bimodal-triple contract at cardinality `>= 3`:
/// `T::unique_repeating_variant([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == Some(T::ALL[0])` — the LOAD-BEARING SOLE `Some(_)`-arm on the
/// canonical fixture window. On the non-flat triple `T::ALL[0]`
/// sits at count `2 >= 2` (the SOLE strict-repeat witness),
/// `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
/// [`Self::count_repeating_variants`] reports `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, the
/// guard fires, and the declaration-order sweep of [`Self::ALL`]
/// through [`Self::is_repeated_occurrence_of`] hits `T::ALL[0]`
/// immediately. LOAD-BEARING ASYMMETRY against
/// [`Self::unique_extremal_variant`] and
/// [`Self::unique_bimodal_variant`] which BOTH return `None` on the
/// same fixture (the union band pulls two disjoint extremes; the
/// intersection band collapses to empty on the non-flat triple),
/// AND against [`Self::unique_middle_band_variant`] which returns
/// `Some(T::ALL[1])` at the SOLE strict-interior witness — the
/// equivalence-partition (mult `>= 2`) uniqueness column and the
/// modal-aggregation direction-composition complement uniqueness
/// column report `Some(_)` at DIFFERENT witnesses (`T::ALL[0]`
/// vs `T::ALL[1]`) on the same slice, pinning the two surfaces as
/// orthogonal uniqueness axes with disjoint witness projections.
/// Pinned by
/// `unique_repeating_variant_returns_some_all_0_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::is_repeated_occurrence_of`] via a boolean-guarded first-
/// witness sweep on `Option<Self>`. The sweep cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity
/// `n`, allocation-free (`::find` on the `Copy` variant stream and
/// the substrate's [`Self::is_repeated_occurrence_of`] primitive
/// avoid the Vec-alloc `T::repeating_variants(items).into_iter().next()`
/// would demand), no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); the short-circuiting `if` avoids the second sweep
/// when the guard falsifies, and the `find` short-circuits on the
/// first hit when the guard holds.
///
/// Future consumers that compose against
/// [`Self::unique_repeating_variant`]: a `tatara-check` predicate
/// `(check-strict-repeat-if-unique …)` that reports "the sole
/// strictly-repeating variant, if unambiguous" as a typed
/// `Option`-return rather than a two-step (has-unique-repeating-
/// variant? then filter-find) composition; an LSP diagnostic on a
/// Lisp-authored `:severities [:info :warn :info]` closed-set field
/// that surfaces the SOLE strictly-repeated enum-arm ("used more
/// than once: [info]") only when the duplication is unambiguous,
/// staying silent on tied duplications; a Sekiban audit-trail per-
/// window witness-if-unique binding to the same scalar, composable
/// with the just-lifted set-level strict-repeat uniqueness bit
/// into a typed (unique-strict-repeat-bit, unique-strict-repeat-
/// witness) classifier per window; a scheduler-fairness heuristic
/// that reports "worker X is the sole double-scheduled worker in
/// this window" without paying the strict-repeat witness-Vec
/// allocation. Each binds to ONE typed `Option<Self>`-return
/// uniqueness-gated strict-repeat aggregate on the trait rather
/// than re-deriving
/// `if T::has_unique_repeating_variant(items) { T::ALL.iter().copied().find(|&v| T::is_repeated_occurrence_of(v, items)) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::repeating_variants(items).into_iter().next().filter(|_| T::repeating_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × equivalence-partition × multiplicity-band ×
/// unique-tie) column on the EQUIVALENCE-PARTITION surface at its
/// (mult `>= 2`) band, peer to the just-lifted
/// [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] triple one SURFACE axis over on
/// the MODAL-AGGREGATION surface. The two surfaces now carry the
/// SAME `Option<Self>`-return uniqueness-guarded witness pattern on
/// BOTH sides of the closed-set trait's set-level uniqueness face —
/// the (bool, `Option<Self>`) × (equivalence-partition, modal-
/// aggregation) 2×2 = 4-corner surface face now closes at seven
/// typed primitives ([`Self::has_unique_repeating_variant`] +
/// [`Self::has_unique_extremal_variant`] +
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::has_unique_bimodal_variant`] on the bool arm; THIS +
/// [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] on the Option arm). The natural
/// next lift past this opening is the per-target arity lift
/// `is_unique_repeating_variant_of(target, items) -> bool` threading
/// `is_repeated_occurrence_of(target, items) &&
/// has_unique_repeating_variant(items)` (peer to
/// [`Self::is_unique_extremal_variant_of`] +
/// [`Self::is_unique_middle_band_variant_of`] +
/// [`Self::is_unique_bimodal_variant_of`] one SURFACE axis over
/// on the modal-aggregation surface).
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × equivalence-partition × mult `>= 2`
/// × unique-tie) corner becomes a TYPED WITNESS on the ClosedSet
/// trait rather than a per-consumer inline
/// `if T::has_unique_repeating_variant(items) { T::ALL.iter().copied().find(|&v| T::is_repeated_occurrence_of(v, items)) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; the N-ary set-
/// level unique-strict-repeat `Option<Self>` witness projection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (set-
/// level × `Option<Self>` × equivalence-partition × mult `>= 2` ×
/// unique-tie) witness-if-unique corner was an unnamed inline
/// composition recurring at every prospective downstream "which
/// variant is the sole strict-repeat witness, if it's unambiguous?"
/// site pre-lift. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_repeating_variant`] +
/// [`Self::is_repeated_occurrence_of`]) with an `if _ { _.find(…) }
/// else { None }` combinator on `Option<Self>`, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); r <- names(t)[t
/// \>= 2]; if (length(r) == 1) r[1] else NA }` — the canonical
/// guarded strict-repeat first-witness on a factor histogram;
/// Julia's `let c = StatsBase.countmap(items), r = filter(kv ->
/// kv[2] >= 2, collect(c)); length(r) == 1 ? Some(r[1][1]) : Nothing
/// end`; Python's `let c = collections.Counter(items); r = [k for
/// k, v in c.items() if v >= 2]; r[0] if len(r) == 1 else None`;
/// Haskell's `let hs = map (\g -> (head g, length g)) . group .
/// sort $ items; rs = filter (\(_, c) -> c >= 2) hs in case rs of
/// [(v, _)] -> Just v; _ -> Nothing`; Clojure's `(let [rs (filter
/// #(>= (val %) 2) (frequencies coll))] (when (= 1 (count rs))
/// (key (first rs))))`; SQL's `SELECT variant FROM (SELECT variant,
/// COUNT(*) AS c FROM t GROUP BY variant HAVING c >= 2) WHERE
/// (SELECT COUNT(*) FROM …) = 1`. Translation through pleme-io
/// primitives: the N-ary set-level uniqueness-gated strict-repeat
/// witness projection on the closed-set trait binds through the
/// just-lifted [`Self::has_unique_repeating_variant`] guard
/// composed with a declaration-order find sweep of [`Self::ALL`]
/// through the substrate's [`Self::is_repeated_occurrence_of`]
/// primitive under an `Option`-collapse — no new dep, no
/// supertrait bound (`Sized + Copy + 'static` stays untouched), no
/// allocation, `O(T::CARDINALITY * n)` inherited from the
/// underlying aggregates with short-circuiting on both the guard
/// and the find.
fn unique_repeating_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_repeating_variant(items) {
<Self as ClosedSet>::ALL
.iter()
.copied()
.find(|&v| <Self as ClosedSet>::is_repeated_occurrence_of(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "is `target` the SOLE
/// strictly-repeating variant?" predicate — `true` iff `target`
/// occurs TWO OR MORE times in `items` AND exactly ONE variant of
/// [`Self::ALL`] sits on that strict-repeat band, computed as the
/// substrate's per-target strict-repeat membership
/// [`Self::is_repeated_occurrence_of`] projection conjoined with
/// the just-lifted set-level strict-repeat uniqueness bit
/// [`Self::has_unique_repeating_variant`] via `&&`. The (per-
/// target × bool × equivalence-partition × multiplicity-band
/// `>= 2` × unique-tie sharpening) corner OPENING the equivalence-
/// partition arm of the (per-target × bool × unique-tie) column
/// peer to [`Self::is_unique_extremal_variant_of`] +
/// [`Self::is_unique_middle_band_variant_of`] +
/// [`Self::is_unique_bimodal_variant_of`] one SURFACE axis over —
/// those three land the same `bool` uniqueness-guarded predicate
/// on the MODAL-AGGREGATION surface (direction-composition ×
/// combinator); THIS projection lands it on the EQUIVALENCE-
/// PARTITION surface (multiplicity-band). AND peer to
/// [`Self::has_unique_repeating_variant`] one ARITY axis over,
/// AND peer to [`Self::unique_repeating_variant`] one RETURN-
/// SHAPE axis over. Not a fresh substrate primitive on the index
/// axis — the predicate emerges from the boolean conjunction of
/// the substrate's per-target strict-repeat primitive with the
/// just-lifted set-level strict-repeat uniqueness bit.
///
/// Composition-conjunction identity: for every slice `items` and
/// every target `v`,
/// `T::is_unique_repeating_variant_of(v, items) == T::is_repeated_occurrence_of(v, items) && T::has_unique_repeating_variant(items)`
/// — the canonical form the body uses. Pinned by
/// `is_unique_repeating_variant_of_equals_repeated_occurrence_and_unique_repeating_variant_across_every_target_and_triple`.
///
/// At-most-one-target identity: for every slice `items`,
/// `T::ALL.iter().filter(|&&v| T::is_unique_repeating_variant_of(v, items)).count() == usize::from(T::has_unique_repeating_variant(items))`
/// — the per-target predicate's set-level filter-count equals the
/// set-level strict-repeat uniqueness bit cast to `usize`; at most
/// ONE target satisfies the per-target predicate, and it does
/// exactly when [`Self::has_unique_repeating_variant`] holds.
/// Pinned by
/// `is_unique_repeating_variant_of_count_equals_has_unique_repeating_variant_as_usize_across_every_triple`.
///
/// Unique-repeating-variant option-equality identity: for every
/// slice `items` and every target `v`,
/// `T::is_unique_repeating_variant_of(v, items) == (T::unique_repeating_variant(items) == Some(v))`
/// — the per-target `bool` predicate coincides with the equality
/// test between the set-level `Option<Self>` witness projection
/// and `Some(v)`. Independent cross-check on the return-shape axis
/// distinct from the composition-conjunction body. Pinned by
/// `is_unique_repeating_variant_of_agrees_with_unique_repeating_variant_option_equality_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_repeated_occurrence_of`] (ordering-agnostic —
/// factored through [`Self::count_occurrences_of`]) and
/// [`Self::has_unique_repeating_variant`] (ordering-agnostic — the
/// underlying [`Self::count_repeating_variants`] is invariant
/// under slice-reversal) via a boolean conjunction. No separate
/// `sorted_is_unique_repeating_variant_of` peer is needed until
/// the sibling LEX corner is opened. Pinned by
/// `is_unique_repeating_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract:
/// `T::is_unique_repeating_variant_of(v, &[])` is `false` for
/// every target `v` — [`Self::is_repeated_occurrence_of`] reports
/// `false` at every target on the empty slice (count `0 < 2`),
/// and `false && _` short-circuits to `false`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_repeating_variant_of(v, &[v])` is `false` for
/// every target `v` — a singleton has `v` at count `1` (not
/// strictly repeating), [`Self::is_repeated_occurrence_of`]
/// reports `false` at `v`, and the conjunction lands on `false`
/// through the membership arm. Both matching (`w == v`) and
/// non-matching (`w != v`) singleton arms pin the projection at
/// `false`.
///
/// Full-set contract: `T::is_unique_repeating_variant_of(v, T::ALL)`
/// is `false` for every target `v` — clause (3)'s pairwise-
/// distinctness invariant pins every variant at count exactly `1`
/// (not strictly repeating); [`Self::is_repeated_occurrence_of`]
/// falsifies at every target, and the conjunction lands on
/// `false`.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_repeating_variant_of(v, T::ALL ++ T::ALL)` is
/// `false` for every target `v` — the doubled full set hits every
/// variant at exactly two positions, [`Self::is_repeated_occurrence_of`]
/// reports `true` at every target, but
/// [`Self::has_unique_repeating_variant`] returns `false` at
/// `count_repeating_variants == T::CARDINALITY >= 2 != 1`, so
/// the conjunction lands on `false` at every target via the
/// uniqueness arm.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`
/// (LOAD-BEARING POSITIVE ARM): on the canonical fixture
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2 >= 2` (the SOLE strict-repeat witness), `T::ALL[1]` at
/// count `1`, `T::ALL[2..]` at count `0`;
/// [`Self::is_repeated_occurrence_of`] reports `true` only at
/// `T::ALL[0]`, [`Self::has_unique_repeating_variant`] reports
/// `true` via `count_repeating_variants == 1`, and the
/// conjunction lands on `true` at `T::ALL[0]` and `false` at
/// every other target. LOAD-BEARING ASYMMETRY against
/// [`Self::is_unique_middle_band_variant_of`] which reports
/// `true` at `T::ALL[1]` on the SAME fixture — the equivalence-
/// partition (mult `>= 2`) unique-target column and the modal-
/// aggregation direction-composition complement unique-target
/// column report `true` at DIFFERENT targets on the same slice,
/// mirroring the sibling asymmetry between
/// [`Self::unique_repeating_variant`] +
/// [`Self::unique_middle_band_variant`] one RETURN-SHAPE axis
/// over. LOAD-BEARING ASYMMETRY against
/// [`Self::is_unique_extremal_variant_of`] +
/// [`Self::is_unique_bimodal_variant_of`] which BOTH stay
/// universally `false` on the same fixture (the union band pulls
/// two disjoint extremes so its uniqueness bit falsifies; the
/// intersection band collapses to empty on the non-flat triple).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_repeated_occurrence_of`] +
/// [`Self::has_unique_repeating_variant`] via a boolean
/// conjunction on `bool`. The sweep cost inherits both primitives:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_occurrences_of`] fold at the target + one
/// [`Self::count_repeating_variants`] filter-count over
/// [`Self::ALL`]; the short-circuiting `&&` avoids the second
/// aggregate when the first arm falsifies), allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::is_unique_repeating_variant_of`]: a `tatara-check`
/// predicate `(check-target-is-the-sole-strict-repeat …)` that
/// reports "the sole strictly-repeating variant is unambiguous
/// AND matches the expected witness" in ONE typed bool rather
/// than a two-step `has_unique_repeating_variant?` +
/// witness-equality composition; an LSP diagnostic on a Lisp-
/// authored `:severities [:info :warn :info]` closed-set field
/// that flags the SOLE strictly-duplicated enum-arm ("used more
/// than once: [info]") without materializing the strict-repeat
/// witness-collection AND while staying silent on tied
/// duplications; a Sekiban audit-trail per-target unique-repeat
/// bit binding the same scalar, composable with the per-target
/// unique-extremum bit into a typed 2-bit strict-repeat-vs-
/// boundary classifier per window; a scheduler-fairness heuristic
/// that branches on "is worker X the SOLE double-scheduled
/// worker in this window?"; an LSP duplicate-detection quick-fix
/// that offers to rename only when the duplication is unambiguous
/// AND the target is the sole offender. Each binds to ONE typed
/// per-target bool predicate on the trait rather than re-deriving
/// `T::is_repeated_occurrence_of(v, items) && T::has_unique_repeating_variant(items)`
/// inline per callsite OR paying the option-equality composition
/// `T::unique_repeating_variant(items) == Some(v)` would demand
/// (materially equivalent, but the boolean-conjunction form is
/// the canonical trait body and avoids re-invoking the first-
/// witness sweep behind [`Self::unique_repeating_variant`]).
///
/// Compounding closure: this projection OPENS the (per-target ×
/// bool × equivalence-partition × mult `>= 2` × unique-tie) corner
/// on the EQUIVALENCE-PARTITION surface, peer to the just-lifted
/// [`Self::is_unique_extremal_variant_of`] +
/// [`Self::is_unique_middle_band_variant_of`] +
/// [`Self::is_unique_bimodal_variant_of`] triple one SURFACE axis
/// over on the MODAL-AGGREGATION surface. The two surfaces now
/// carry the SAME `bool`-return uniqueness-guarded per-target
/// predicate on BOTH sides of the closed-set trait's per-target
/// uniqueness face — the (`bool` set-level, `Option<Self>` set-
/// level, `bool` per-target) × (equivalence-partition, modal-
/// aggregation) 3×2 = 6-corner surface face now closes at ten
/// typed primitives ([`Self::has_unique_repeating_variant`] +
/// [`Self::has_unique_extremal_variant`] +
/// [`Self::has_unique_middle_band_variant`] +
/// [`Self::has_unique_bimodal_variant`] on the bool set-level arm;
/// [`Self::unique_repeating_variant`] +
/// [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] on the Option set-level arm;
/// THIS + [`Self::is_unique_extremal_variant_of`] +
/// [`Self::is_unique_middle_band_variant_of`] +
/// [`Self::is_unique_bimodal_variant_of`] on the bool per-target
/// arm — total ELEVEN primitives across the face; ordered
/// listing off by one due to the modal-aggregation surface's
/// three direction-composition variants against the equivalence-
/// partition surface's ONE multiplicity-band column). The
/// (equivalence-partition × unique-tie) uniqueness column now
/// closes at three corners at the (bool set-level, `Option<Self>`
/// set-level, bool per-target) return-shape × arity trio,
/// exhausting the closed uniqueness surface at (mult `>= 2`).
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (per-target × bool × equivalence-partition × mult `>= 2` ×
/// unique-tie) corner becomes a TYPED WITNESS on the ClosedSet
/// trait rather than a per-consumer inline
/// `T::is_repeated_occurrence_of(v, items) && T::has_unique_repeating_variant(items)`
/// re-derivation. THEORY.md §III — the typescape; the N-ary per-
/// target unique-strict-repeat predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (per-target × bool ×
/// equivalence-partition × mult `>= 2` × unique-tie) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "is this target the sole strict-repeat witness?"
/// site pre-lift. THEORY.md §VI.1 — generation over composition;
/// the predicate emerges from the composition of TWO substrate
/// primitives ([`Self::is_repeated_occurrence_of`] +
/// [`Self::has_unique_repeating_variant`]) with the `&&`
/// combinator on `bool`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `let t = table(items); (t[v] >= 2)
/// && (sum(t >= 2) == 1)` per-level unique-strict-repeat test on
/// a factor histogram; Julia's `let c =
/// StatsBase.countmap(items); (get(c, v, 0) >= 2) &&
/// (count(kv -> kv[2] >= 2, collect(c)) == 1) end` on a
/// `Dict{Element, Int}` histogram; Python's `let c =
/// collections.Counter(items); c[v] >= 2 and
/// sum(1 for x in c.values() if x >= 2) == 1` on a Counter;
/// Haskell's `let hs = map (\g -> (head g, length g)) . group .
/// sort $ items; rs = filter (\(_, c) -> c >= 2) hs in count v
/// items >= 2 && length rs == 1` on `Ord`-instance carriers;
/// Clojure's `(let [f (frequencies coll)] (and (>= (get f v 0) 2)
/// (= 1 (count (filter #(>= (val %) 2) f)))))`; SQL's
/// `EXISTS (SELECT 1 FROM t WHERE variant = ? GROUP BY variant
/// HAVING COUNT(*) >= 2) AND (SELECT COUNT(*) FROM (SELECT
/// variant FROM t GROUP BY variant HAVING COUNT(*) >= 2)) = 1`.
/// Translation through pleme-io primitives: the projection binds
/// through the substrate's [`Self::is_repeated_occurrence_of`]
/// per-target strict-repeat membership predicate conjoined with
/// the just-lifted [`Self::has_unique_repeating_variant`] set-
/// level uniqueness bit — no new dep, no supertrait bound, no
/// allocation, `O(T::CARDINALITY * n)` inherited from the
/// underlying aggregates with short-circuiting on the strict-
/// repeat membership arm. One pleme-io-specific asymmetry: the
/// equivalence-partition surface's LOAD-BEARING positive arm at
/// `T::ALL[0]` on the canonical bimodal-triple fixture is
/// DISJOINT from the modal-aggregation complement surface's
/// LOAD-BEARING positive arm at `T::ALL[1]` — the two surfaces
/// pin uniqueness at DIFFERENT witnesses on the same slice,
/// witnessing their orthogonality as separate uniqueness
/// projections rather than redundant covers of one underlying
/// property.
fn is_unique_repeating_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_repeated_occurrence_of(target, items)
&& <Self as ClosedSet>::has_unique_repeating_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC "does the (mult `== 0`) MISS-band
/// fall on a UNIQUE variant?" set-level predicate — `true` iff
/// EXACTLY ONE variant of [`Self::ALL`] is ABSENT from `items`
/// (i.e., `items` hits every variant except one), computed as
/// the strict-equality test of [`Self::count_missing`] against
/// the scalar threshold `1`. The BOOL-RETURN UNIQUE-TIE
/// SHARPENING corner CLOSING the miss-band arm of the (set-
/// level × bool × equivalence-partition × multiplicity-band ×
/// unique-tie) row on the EQUIVALENCE-PARTITION surface at its
/// (mult `== 0`) band, peer to [`Self::has_unique_repeating_variant`]
/// (mult `>= 2`) one MULTIPLICITY-BAND axis over — the two
/// together bracket the unique-tie sharpening at BOTH extremal
/// bands of the mult-band trichotomy; peer to
/// [`Self::count_missing`] one RETURN-SHAPE axis over (set-
/// level × `usize` miss-cardinality → set-level × `bool` miss-
/// uniqueness test against `1`); peer to [`Self::is_missing_any`]
/// one UNIQUE-TIE-SHARPENING axis over (existential `>= 1` →
/// uniqueness `== 1`). Not a fresh substrate primitive on the
/// index axis — the predicate emerges from one strict-equality
/// test of the substrate's [`Self::count_missing`] scalar
/// against `1`, equivalently the [`Vec::len`] equality of the
/// declaration-order miss witness-collection
/// [`Self::missing_variants`] against `1`.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_missing_variant(items) ==
/// (T::count_missing(items) == 1)` — the set-level bool
/// predicate is EXACTLY the strict-equality test of the
/// substrate's set-level miss-count aggregate against the
/// scalar threshold `1`. The canonical form the body uses.
/// Pinned by
/// `has_unique_missing_variant_equals_count_missing_eq_one_across_every_triple`.
///
/// Miss-witness length identity: for every slice `items`,
/// `T::has_unique_missing_variant(items) ==
/// (T::missing_variants(items).len() == 1)` — the set-level
/// bool predicate is EXACTLY the length-equality test of the
/// declaration-order miss-witness-collection against `1`.
/// Independent cross-check distinct from the count-composition
/// arm on the surface axis (Vec-length vs scalar equality).
/// Pinned by
/// `has_unique_missing_variant_agrees_with_missing_variants_len_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_missing_variant(items) ==>
/// T::is_missing_any(items)` — a UNIQUE missing witness
/// trivially entails the EXISTENCE of a missing witness (the
/// unique-tie sharpening `count == 1` implies the existential
/// `count `\>=` 1`). Pinned by
/// `has_unique_missing_variant_implies_is_missing_any_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_missing`] (ordering-agnostic — factored through
/// [`Self::count_distinct`]) via a scalar equality test against
/// a fixed constant. No separate
/// `sorted_has_unique_missing_variant` peer is needed. Pinned
/// by
/// `has_unique_missing_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_missing_variant(&[])`
/// is `true` iff [`Self::CARDINALITY`] `== 1` on the
/// implementor — the empty slice hits zero variants,
/// [`Self::count_missing`] collapses to [`Self::CARDINALITY`]
/// via `CARDINALITY - count_distinct(&[]) == CARDINALITY - 0`,
/// and the equality against `1` holds EXACTLY when the ambient
/// set has EXACTLY ONE variant (which is then trivially the
/// sole absentee). Sibling posture to the sibling
/// (mult `>= 2`) miss's empty-slice contract at the OPPOSITE
/// multiplicity-band arm: the strict-repeat arm falsifies
/// UNCONDITIONALLY at empty
/// (`count_repeating_variants(&[]) == 0 != 1`); the miss arm
/// falsifies at empty on every implementor with
/// `T::CARDINALITY >= 2` and TRIVIALIZES on the SOLE
/// cardinality-1 arm.
///
/// Full-set contract:
/// `T::has_unique_missing_variant(T::ALL)` is `false`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness
/// invariant pins every variant at exactly one position of the
/// full-set slice, [`Self::count_missing`] reports `0`, and
/// `0 != 1`. The `false`-at-full-set fixpoint pins miss-
/// uniqueness as a COVERING-INCOMPATIBLE property — the full-
/// set slice IS its own miss-arm zero fixpoint.
///
/// Doubled-full-set contract:
/// `T::has_unique_missing_variant(T::ALL ++ T::ALL)` is
/// `false` UNCONDITIONALLY — appending positions to a covering
/// slice cannot introduce a missing variant,
/// [`Self::count_missing`] reports `0`, and `0 != 1`.
///
/// All-but-first contract at [`Self::CARDINALITY`] `>= 2`
/// (LOAD-BEARING `true`-arm catch): on the canonical fixture
/// `T::ALL[1..].to_vec()` (i.e., the full set with the first
/// variant omitted), `T::ALL[0]` is the SOLE variant absent
/// from `items`; every other variant of [`Self::ALL`] hits at
/// least one position, [`Self::count_missing`] reports `1` and
/// the equality against `1` HOLDS. LOAD-BEARING positive
/// fixture pinning the projection as a NON-TRIVIAL predicate
/// that fires when EXACTLY ONE variant is missing — mirror of
/// the bimodal-triple fixture at
/// [`Self::has_unique_repeating_variant`] one MULTIPLICITY-
/// BAND axis over (the strict-repeat arm's positive fixture at
/// `T::ALL[0]` witnesses the (mult `>= 2`) unique-tie at
/// count 2; THIS arm's positive fixture at `T::ALL[0]`
/// witnesses the (mult `== 0`) unique-tie at count 0). Both
/// witnesses coincide at `T::ALL[0]` by fixture construction,
/// yet the two arms are TYPED as ORTHOGONAL uniqueness
/// signals on disjoint mult-bands.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_missing`] via one scalar equality test on
/// `usize`. The sweep cost inherits the miss-count aggregate:
/// `O(n(n-1)/2)` on slice arity `n` from the pairwise-
/// distinctness scan behind [`Self::count_distinct`],
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait
/// bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::has_unique_missing_variant`]: a `tatara-check`
/// predicate `(check-covering-except-one …)` that reports
/// "the slice covers everything except EXACTLY ONE variant"
/// in ONE typed bool rather than a Vec-length or count-and-
/// compare composition; an LSP diagnostic on a Lisp-authored
/// closed-set field that surfaces "one variant is missing" as
/// a targeted single-arm cue (e.g., a severity-set covering
/// `[info, warn]` with the sole missing arm being `[error]`)
/// without materializing the miss-witness Vec; a
/// `WorkloadPhase` rollout monitor that flags "EXACTLY ONE
/// phase never fired this window" as its atomic single-gap
/// indicator; a Sekiban audit bit `single_miss_bit(items)`
/// composable with a future
/// `unique_missing_variant -> Option<Self>` witness-if-unique
/// projection into a typed (single-miss-bit, single-miss-
/// witness) classifier per window; a `tatara-lisp` hygiene
/// pass that flags a template's vocabulary as ONE-VARIANT-
/// INCOMPLETE against a required closed vocabulary without
/// spelling out the miss-count. Each binds to ONE typed set-
/// level `bool` predicate on the trait rather than re-deriving
/// `T::count_missing(items) == 1` inline per callsite OR
/// paying the Vec allocation
/// `T::missing_variants(items).len() == 1` would demand.
///
/// Compounding closure: this projection CLOSES the miss-band
/// arm of the (set-level × bool × equivalence-partition ×
/// mult-band × unique-tie) row past the just-lifted
/// [`Self::has_unique_repeating_variant`] strict-repeat arm
/// one MULTIPLICITY-BAND axis over — the two together bracket
/// the unique-tie sharpening on BOTH EXTREMAL bands of the
/// mult-band trichotomy (mult `== 0` at THIS,
/// mult `>= 2` at [`Self::has_unique_repeating_variant`]).
/// The natural next lift on this surface is the MIDDLE band —
/// `has_unique_unique_variant(items) ==
/// (count_unique_variants == 1)` (mult `== 1` opener) —
/// closing the (set-level × bool × equivalence-partition ×
/// mult-band × unique-tie) 3-corner row on the trichotomy at
/// its EXHAUSTIVE FINAL tile; downstream a peer
/// `unique_missing_variant() -> Option<Self>` witness-if-
/// unique projection one RETURN-SHAPE axis over lifts the
/// same predicate to the Option-return column via
/// `if has_unique_missing_variant { missing_variants.first().copied() } else { None }`;
/// a peer per-target arity lift
/// `is_unique_missing_variant_of(target, items)` one ARITY
/// axis over closes the per-target column via
/// `!items.iter().any(|w| index_of(*w) == index_of(target)) && has_unique_missing_variant(items)`.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern;
/// the (set-level × bool × equivalence-partition × mult
/// `== 0` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `T::count_missing(items) == 1` re-derivation. THEORY.md
/// §III — the typescape; the N-ary set-level miss-uniqueness
/// bool predicate becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (set-level × bool ×
/// equivalence-partition × mult `== 0` × unique-tie) corner
/// was an unnamed inline composition recurring at every
/// prospective downstream "is EXACTLY ONE variant missing?"
/// site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the predicate emerges from the composition of
/// ONE substrate primitive ([`Self::count_missing`]) with a
/// scalar equality against `1`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); sum(!(all
/// %in% names(t))) == 1 }` set-difference-cardinality-eq-one
/// test on a factor histogram; Julia's `count(v -> !(v in
/// items), all) == 1`; Python's `sum(1 for v in ALL if v not
/// in items) == 1`; Haskell's `length (all \\ nub items) == 1`;
/// Clojure's `(= 1 (count (remove (set coll) all)))`; SQL's
/// `SELECT COUNT(*) = 1 FROM (SELECT variant FROM all EXCEPT
/// SELECT variant FROM t)`. Translation through pleme-io
/// primitives: the N-ary set-level miss-uniqueness predicate
/// on the closed-set trait binds through the substrate's
/// [`Self::count_missing`] scalar (itself defined as
/// `T::CARDINALITY - T::count_distinct(items)`) against the
/// constant `1` — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(n(n-1)/2)` on slice arity `n` inherited verbatim from
/// the miss-count aggregate.
fn has_unique_missing_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_missing(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "does the (mult `== 1`) UNIQUE-band
/// fall on a UNIQUE variant?" set-level predicate — `true` iff
/// EXACTLY ONE variant of [`Self::ALL`] occurs at multiplicity
/// EXACTLY `1` in `items` (i.e., `items` has EXACTLY ONE
/// singleton-multiplicity witness on its per-variant histogram),
/// computed as the strict-equality test of
/// [`Self::count_unique_variants`] against the scalar threshold
/// `1`. The BOOL-RETURN UNIQUE-TIE SHARPENING corner
/// EXHAUSTIVELY CLOSING the middle-band arm of the (set-level ×
/// bool × equivalence-partition × multiplicity-band × unique-
/// tie) row on the EQUIVALENCE-PARTITION surface at its
/// (mult `== 1`) band — the row's FINAL THIRD tile past the
/// just-lifted (mult `== 0`) [`Self::has_unique_missing_variant`]
/// miss-band arm and the (mult `>= 2`)
/// [`Self::has_unique_repeating_variant`] strict-repeat arm one
/// MULTIPLICITY-BAND axis over. The three together bracket the
/// unique-tie sharpening across ALL THREE bands of the mult-
/// band trichotomy (`== 0`, `== 1`, `>= 2`), exhaustively
/// closing the (set-level × bool × equivalence-partition ×
/// mult-band × unique-tie) 3-corner row on the equivalence-
/// partition surface — the mirror closure of the (set-level ×
/// usize × equivalence-partition × mult-band) 3-corner
/// cardinality-count row ([`Self::count_missing`],
/// [`Self::count_unique_variants`],
/// [`Self::count_repeating_variants`]) one RETURN-SHAPE axis
/// over on the equivalence-partition surface, AND the mirror
/// closure of the (set-level × bool × equivalence-partition ×
/// mult-band × existential) 3-corner existential-lift row
/// ([`Self::is_missing_any`], [`Self::is_unique_any`],
/// [`Self::is_repeating_any`]) one UNIQUE-TIE-SHARPENING axis
/// over. Peer to [`Self::count_unique_variants`] one RETURN-
/// SHAPE axis over (set-level × `usize` unique-cardinality →
/// set-level × `bool` unique-uniqueness test against `1`); peer
/// to [`Self::is_unique_any`] one UNIQUE-TIE-SHARPENING axis
/// over (existential `>= 1` → uniqueness `== 1`). Not a fresh
/// substrate primitive on the index axis — the predicate emerges
/// from one strict-equality test of the substrate's
/// [`Self::count_unique_variants`] scalar against `1`,
/// equivalently the count of per-variant histogram bars strictly
/// equal to `1` collapsed to a `== 1` bit.
///
/// Count-composition identity: for every slice `items`,
/// `T::has_unique_unique_variant(items) ==
/// (T::count_unique_variants(items) == 1)` — the set-level bool
/// predicate is EXACTLY the strict-equality test of the
/// substrate's set-level unique-variant count aggregate against
/// the scalar threshold `1`. The canonical form the body uses.
/// Pinned by
/// `has_unique_unique_variant_equals_count_unique_variants_eq_one_across_every_triple`.
///
/// Existence-implication identity: for every slice `items`,
/// `T::has_unique_unique_variant(items) ==>
/// T::is_unique_any(items)` — a UNIQUE unique-multiplicity
/// witness trivially entails the EXISTENCE of a unique-
/// multiplicity witness (the unique-tie sharpening `count == 1`
/// implies the existential `count `\>=` 1`). Pinned by
/// `has_unique_unique_variant_implies_is_unique_any_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::count_unique_variants`] (ordering-agnostic — factored
/// through the per-target [`Self::is_unique_occurrence_of`]
/// filter-count over [`Self::ALL`]) via a scalar equality test
/// against a fixed constant. No separate
/// `sorted_has_unique_unique_variant` peer is needed. Pinned by
/// `has_unique_unique_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::has_unique_unique_variant(&[])` is
/// `false` UNCONDITIONALLY — the empty slice hits zero variants,
/// every per-variant multiplicity is `0`, [`Self::count_unique_variants`]
/// reports `0`, and `0 != 1`. Sibling posture to the
/// (mult `>= 2`) strict-repeat arm's empty-slice contract at
/// [`Self::has_unique_repeating_variant`]: both TWO
/// PER-VARIANT-POSITIVE bands (mult `== 1` at THIS, mult `>= 2`
/// at the strict-repeat arm) falsify UNCONDITIONALLY on the
/// empty slice; only the (mult `== 0`) miss-band arm at
/// [`Self::has_unique_missing_variant`] holds an empty-slice
/// LOAD-BEARING `true`-arm at the SOLE cardinality-1
/// implementor (where the empty slice's miss-count collapses to
/// [`Self::CARDINALITY`] `== 1`).
///
/// Full-set contract: `T::has_unique_unique_variant(T::ALL)` is
/// `true` iff [`Self::CARDINALITY`] `== 1` on the implementor —
/// clause (3)'s pairwise-distinctness invariant pins every
/// variant of the full-set slice at exactly one position,
/// every per-target multiplicity is `1`,
/// [`Self::count_unique_variants`] reports
/// [`Self::CARDINALITY`], and the equality against `1` holds
/// EXACTLY when the ambient set has EXACTLY ONE variant. Sibling
/// posture to the (mult `== 0`) miss-band arm at
/// [`Self::has_unique_missing_variant`]: THIS arm trivializes on
/// the SOLE cardinality-1 implementor via a FULL-SET fixpoint
/// (`count_unique_variants(T::ALL) == 1`); the miss-band arm
/// trivializes on the SAME cardinality-1 implementor via an
/// EMPTY-SLICE fixpoint (`count_missing(&[]) == 1`) — the two
/// trivialization arms MEET at cardinality `== 1` on
/// COMPLEMENTARY fixtures, pinning the cardinality-1 collapse
/// as a STRUCTURAL degeneracy of the mult-band trichotomy
/// rather than an arm-specific accident.
///
/// Doubled-full-set contract:
/// `T::has_unique_unique_variant(T::ALL ++ T::ALL)` is `false`
/// UNCONDITIONALLY — appending a full-set copy to the full-set
/// slice hits every variant at multiplicity `2`, every per-
/// target multiplicity-`== 1` test fails,
/// [`Self::count_unique_variants`] reports `0`, and `0 != 1`.
/// The `false`-at-doubled-full-set fixpoint pins unique-
/// uniqueness as a UNIFORM-REPEAT-INCOMPATIBLE property — the
/// doubled full set IS its own unique-band zero fixpoint.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`
/// (LOAD-BEARING `true`-arm catch): on the canonical non-flat
/// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits
/// at multiplicity `2` (the (mult `>= 2`) witness), `T::ALL[1]`
/// at multiplicity `1` (the SOLE (mult `== 1`) witness),
/// `T::ALL[2..]` at multiplicity `0`;
/// [`Self::count_unique_variants`] reports `1` and the equality
/// against `1` HOLDS. LOAD-BEARING positive fixture pinning the
/// projection as a NON-TRIVIAL predicate that fires when
/// EXACTLY ONE variant sits on the singleton-multiplicity band
/// — mirror-with-DISJOINT-witness of the bimodal-triple fixture
/// at [`Self::has_unique_repeating_variant`] one MULTIPLICITY-
/// BAND axis over. The two arms fire on the SAME fixture at
/// DISJOINT witnesses (`T::ALL[0]` for the strict-repeat arm,
/// `T::ALL[1]` for THIS unique-band arm), witnessing the two
/// unique-tie sharpenings as TYPED ORTHOGONAL uniqueness
/// signals riding DIFFERENT variants of the same slice — the
/// bimodal triple is the CANONICAL WITNESS of the mult-band
/// trichotomy's positive-band split.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::count_unique_variants`] via one scalar equality test
/// on `usize`. The sweep cost inherits the unique-variant count
/// aggregate: `O(T::CARDINALITY * n)` on slice arity `n` from
/// the filter-count reduction over [`Self::ALL`] with the per-
/// target [`Self::is_unique_occurrence_of`] predicate inside,
/// allocation-free, no `PartialEq`/`Eq`/`Hash` supertrait bound
/// (the trait's minimal `Sized + Copy + 'static` supertrait
/// pair stays untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::has_unique_unique_variant`]: a `tatara-check`
/// predicate `(check-singleton-hit-is-unique …)` that reports
/// "the slice has EXACTLY ONE variant occurring exactly once"
/// in ONE typed bool rather than a Vec-length or count-and-
/// compare composition; a Sekiban audit-trail bit
/// `unique_band_uniqueness_bit(items)` binding to the same
/// scalar, composable with a future
/// `unique_unique_variant -> Option<Self>` witness-if-unique
/// projection into a typed (unique-band-uniqueness-bit,
/// unique-band-uniqueness-witness) classifier per window; an
/// LSP diagnostic on a Lisp-authored histogram that surfaces
/// "this slice has EXACTLY ONE singleton-multiplicity variant"
/// (e.g., a `WorkloadPhase` window where EXACTLY ONE phase
/// fired EXACTLY ONCE, singling out an outlier singleton) as a
/// targeted single-arm cue without materializing the witness-
/// Vec; a scheduler-fairness heuristic that branches on "is
/// there a UNIQUE worker that ran EXACTLY ONE task this window?"
/// as the singleton-outlier detector. Each binds to ONE typed
/// set-level `bool` predicate on the trait rather than re-
/// deriving `T::count_unique_variants(items) == 1` inline per
/// callsite.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × bool × equivalence-partition × multiplicity-
/// band × unique-tie) 3-corner row on the equivalence-partition
/// surface at its MIDDLE (mult `== 1`) band, past the (mult
/// `== 0`) [`Self::has_unique_missing_variant`] miss-band arm
/// and the (mult `>= 2`) [`Self::has_unique_repeating_variant`]
/// strict-repeat arm one MULTIPLICITY-BAND axis over — the row
/// is now the CANONICAL bool-return unique-tie sharpening on
/// the equivalence-partition surface, closed at its FINAL third
/// tile. Downstream lifts: a peer per-target arity lift
/// `is_unique_unique_variant_of(target, items)` one ARITY axis
/// over closes the per-target column via
/// `is_unique_occurrence_of(target, items) && has_unique_unique_variant(items)`;
/// a peer `unique_unique_variant() -> Option<Self>` witness-if-
/// unique projection one RETURN-SHAPE axis over lifts the same
/// predicate to the Option-return column via
/// `if has_unique_unique_variant { ALL.iter().copied().find(is_unique_occurrence_of) } else { None }`.
/// The natural NEXT surface past the equivalence-partition row's
/// exhaustive closure is the (set-level × Option-return ×
/// equivalence-partition × mult-band × unique-tie) row's
/// middle-band arm — the same three-band trichotomy lifted to
/// witness-return shape — which reaches its own exhaustive
/// closure at the SAME (mult `== 1`) middle tile.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern;
/// the (set-level × bool × equivalence-partition × mult
/// `== 1` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `T::count_unique_variants(items) == 1` re-derivation.
/// THEORY.md §III — the typescape; the N-ary set-level unique-
/// band uniqueness bool predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (set-level × bool ×
/// equivalence-partition × mult `== 1` × unique-tie) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "is there EXACTLY ONE singleton-multiplicity
/// variant?" site pre-lift. Naming it on the trait EXHAUSTIVELY
/// CLOSES the equivalence-partition unique-tie row as a TYPED
/// THEOREM the substrate proves once, mirroring the existential-
/// lift trichotomy's exhaustive closure one UNIQUE-TIE-SHARPENING
/// axis over. THEORY.md §VI.1 — generation over composition;
/// the predicate emerges from the composition of ONE substrate
/// primitive ([`Self::count_unique_variants`]) with a scalar
/// equality against `1`, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `{ t <- table(items); sum(t == 1)
/// == 1 }` singleton-uniqueness test on a factor histogram;
/// Julia's `count(v -> v == 1, values(StatsBase.countmap(items))) == 1`;
/// Python's `sum(1 for c in collections.Counter(items).values() if c == 1) == 1`;
/// Haskell's `length (filter (== 1) . map length . group . sort $ items) == 1`;
/// Clojure's `(= 1 (count (filter #(= (val %) 1) (frequencies coll))))`;
/// SQL's `SELECT COUNT(*) = 1 FROM (SELECT variant, COUNT(*) AS c FROM t GROUP BY variant HAVING c = 1)`.
/// Translation through pleme-io primitives: the N-ary set-level
/// unique-band uniqueness predicate on the closed-set trait
/// binds through the just-lifted [`Self::count_unique_variants`]
/// scalar against the constant `1` — no new dep, no supertrait
/// bound (`Sized + Copy + 'static` stays untouched), no
/// allocation, `O(T::CARDINALITY * n)` on slice arity `n`
/// inherited verbatim from the unique-variant count aggregate.
fn has_unique_unique_variant(items: &[Self]) -> bool {
<Self as ClosedSet>::count_unique_variants(items) == 1
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique unique-band variant"
/// projection — `Some(v)` iff `items` has a UNIQUE singleton-
/// multiplicity witness ([`Self::has_unique_unique_variant`] holds)
/// AND `v` is the sole variant whose per-target multiplicity in
/// `items` sits EXACTLY at `1` (equivalently, the sole variant on
/// [`Self::ALL`] satisfying [`Self::is_unique_occurrence_of`] at
/// this slice), else `None`. Computed as the just-lifted set-level
/// unique-band uniqueness bit [`Self::has_unique_unique_variant`]
/// guarding a declaration-order first-witness sweep of [`Self::ALL`]
/// through the substrate's per-target singleton-multiplicity
/// primitive [`Self::is_unique_occurrence_of`]: when the guard holds
/// the sweep hits EXACTLY ONE variant and the sole witness lifts
/// through verbatim; when the guard falsifies the projection
/// collapses to `None`. The `Option<Self>`-RETURN UNIQUE-TIE
/// SHARPENING corner EXHAUSTIVELY CLOSING the middle-band arm of
/// the (set-level × `Option<Self>` × equivalence-partition ×
/// multiplicity-band × unique-tie) row on the EQUIVALENCE-PARTITION
/// surface at its (mult `== 1`) band — the row's FINAL THIRD tile
/// past the just-lifted (mult `>= 2`)
/// [`Self::unique_repeating_variant`] strict-repeat arm one
/// MULTIPLICITY-BAND axis over. Peer to
/// [`Self::has_unique_unique_variant`] one RETURN-SHAPE axis over
/// (set-level × `bool` unique-band uniqueness bit → set-level ×
/// `Option<Self>` unique-band witness-when-unique); peer to
/// [`Self::unique_repeating_variant`] one MULTIPLICITY-BAND axis
/// over (mult `>= 2` `Option<Self>` strict-repeat witness → mult
/// `== 1` `Option<Self>` unique-band witness). Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from the just-lifted set-level unique-band uniqueness bit
/// guarding a first-witness sweep of [`Self::ALL`] through the
/// substrate's per-target singleton-multiplicity primitive under
/// an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_unique_variant(items) == if T::has_unique_unique_variant(items) { T::ALL.iter().copied().find(|&v| T::is_unique_occurrence_of(v, items)) } else { None }`
/// — the canonical form the body uses. Pinned by
/// `unique_unique_variant_equals_has_unique_unique_variant_gated_find_across_every_triple`.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_unique_variant(items).is_some() == T::has_unique_unique_variant(items)`
/// — the `Option<Self>` return's `is_some` bit COINCIDES with the
/// set-level unique-band uniqueness bit. Independent cross-check
/// on the surface axis (`Option::is_some` vs conditional-Option
/// construction). Pinned by
/// `unique_unique_variant_is_some_iff_has_unique_unique_variant_across_every_triple`.
///
/// Unique-witness singleton identity: for every slice `items`,
/// `T::unique_unique_variant(items) == (if T::unique_variants(items).len() == 1 { Some(T::unique_variants(items)[0]) } else { None })`
/// — when `items` has a unique singleton-multiplicity witness, the
/// declaration-order strict-uniqueness witness-collection
/// [`Self::unique_variants`] collapses to a length-`1` Vec
/// containing EXACTLY that unique variant, so its slot-`0` wrapped
/// in `Some` coincides with THIS projection. Independent cross-
/// check on the witness-Vec surface axis distinct from the
/// guarded-find arm. Pinned by
/// `unique_unique_variant_agrees_with_unique_variants_singleton_across_every_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_unique_variant`] (ordering-agnostic — the
/// underlying [`Self::count_unique_variants`] is invariant under
/// slice-reversal) and the per-target
/// [`Self::is_unique_occurrence_of`] primitive (ordering-agnostic —
/// factored through [`Self::count_occurrences_of`]) via a boolean-
/// guarded first-witness sweep of [`Self::ALL`] (declaration-
/// order, independent of `items`' ordering). No separate
/// `sorted_unique_unique_variant` peer is needed until the sibling
/// LEX corner is opened. Pinned by
/// `unique_unique_variant_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_unique_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::has_unique_unique_variant`] collapses to `false` via
/// its `count_unique_variants(&[]) == 0 != 1` fixpoint, and the
/// guard-arm short-circuit maps the empty slice to `None` before
/// the per-target singleton-multiplicity sweep is consulted.
///
/// Full-set contract:
/// `T::unique_unique_variant(<T as ClosedSet>::ALL)` is
/// `Some(T::ALL[0])` iff [`Self::CARDINALITY`] `== 1` on the
/// implementor, else `None` — clause (3)'s pairwise-distinctness
/// invariant pins every variant at exactly one position of the
/// full-set slice, every per-target multiplicity is `1`,
/// [`Self::count_unique_variants`] reports [`Self::CARDINALITY`],
/// [`Self::has_unique_unique_variant`] holds EXACTLY when
/// [`Self::CARDINALITY`] `== 1`. At `T::CARDINALITY == 1` the
/// guarded find lands on `T::ALL[0]` (the sole singleton-
/// multiplicity witness); at `T::CARDINALITY >= 2` every variant
/// is a singleton-multiplicity witness, uniqueness fails, and the
/// guard collapses to `None`.
///
/// Doubled-full-set contract: `T::unique_unique_variant(T::ALL ++
/// T::ALL) == None` UNCONDITIONALLY — appending a full-set copy
/// to the full-set slice hits every variant at multiplicity `2`,
/// every per-target multiplicity-`== 1` test fails,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false`, and the
/// guard collapses to `None`.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`:
/// `T::unique_unique_variant([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == Some(T::ALL[1])` — the LOAD-BEARING SOLE `Some(_)`-arm on
/// the canonical fixture window. On the non-flat triple
/// `T::ALL[0]` sits at count `2 >= 2`, `T::ALL[1]` at count `1`
/// (the SOLE (mult `== 1`) witness), `T::ALL[2..]` at count `0`;
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, the guard
/// fires, and the declaration-order sweep of [`Self::ALL`] through
/// [`Self::is_unique_occurrence_of`] hits `T::ALL[1]` at slot 1
/// (the sweep bypasses `T::ALL[0]` where the singleton-band test
/// falsifies at count `2 != 1`). LOAD-BEARING DISJOINT-WITNESS
/// mirror of [`Self::unique_repeating_variant`] on the SAME
/// slice: the strict-repeat arm lands on `Some(T::ALL[0])`; THIS
/// unique-band arm lands on `Some(T::ALL[1])` — the two POSITIVE
/// `Some(_)` arms of the equivalence-partition (mult `>= 2`, mult
/// `== 1`) uniqueness columns report DIFFERENT witnesses on the
/// same slice, pinning the two multiplicity-bands as ORTHOGONAL
/// uniqueness axes with disjoint witness projections riding
/// DIFFERENT variants of the CANONICAL bimodal triple. Pinned by
/// `unique_unique_variant_returns_some_all_1_on_the_bimodal_triple_at_cardinality_gte_three`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_unique_variant`] +
/// [`Self::is_unique_occurrence_of`] via a boolean-guarded first-
/// witness sweep on `Option<Self>`. The sweep cost inherits both
/// underlying projections: `O(T::CARDINALITY * n)` on slice arity
/// `n`, allocation-free (`::find` on the `Copy` variant stream and
/// the substrate's [`Self::is_unique_occurrence_of`] primitive
/// avoid the Vec-alloc `T::unique_variants(items).into_iter().next()`
/// would demand), no `PartialEq`/`Eq`/`Hash` supertrait bound (the
/// trait's minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched); the short-circuiting `if` avoids the second sweep
/// when the guard falsifies, and the `find` short-circuits on the
/// first hit when the guard holds.
///
/// Future consumers that compose against
/// [`Self::unique_unique_variant`]: a `tatara-check` predicate
/// `(check-singleton-hit-if-unique …)` that reports "the sole
/// singleton-multiplicity variant, if unambiguous" as a typed
/// `Option`-return rather than a two-step (has-unique-unique-
/// variant? then filter-find) composition; an LSP diagnostic on a
/// Lisp-authored `:phases [:pending :running :pending]` closed-
/// set field that surfaces the SOLE singleton-multiplicity enum-
/// arm ("occurred exactly once: [running]") only when the
/// singleton-multiplicity witness is unambiguous, staying silent
/// on tied singletons; a Sekiban audit-trail per-window witness-
/// if-unique binding to the same scalar, composable with the
/// just-lifted set-level unique-band uniqueness bit into a typed
/// (unique-band-uniqueness-bit, unique-band-uniqueness-witness)
/// classifier per window; a scheduler-fairness heuristic that
/// reports "worker X is the sole single-scheduled worker in this
/// window" without paying the singleton-multiplicity witness-Vec
/// allocation. Each binds to ONE typed `Option<Self>`-return
/// uniqueness-gated singleton-multiplicity aggregate on the trait
/// rather than re-deriving
/// `if T::has_unique_unique_variant(items) { T::ALL.iter().copied().find(|&v| T::is_unique_occurrence_of(v, items)) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::unique_variants(items).into_iter().next().filter(|_| T::unique_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × `Option<Self>` × equivalence-partition ×
/// multiplicity-band × unique-tie) 3-corner row on the
/// EQUIVALENCE-PARTITION surface at its MIDDLE (mult `== 1`) band,
/// past the (mult `>= 2`) [`Self::unique_repeating_variant`]
/// strict-repeat arm one MULTIPLICITY-BAND axis over — the row is
/// now the CANONICAL `Option<Self>`-return unique-tie sharpening
/// on the equivalence-partition surface, closed at its FINAL
/// third tile (the (mult `== 0`) miss-band `Option<Self>` peer
/// `unique_missing_variant() -> Option<Self>` is a sibling
/// projection on the OPPOSITE-EXTREMAL band and awaits its own
/// lift). Mirrors the bool-return trichotomy row's exhaustive
/// closure ([`Self::has_unique_missing_variant`] +
/// [`Self::has_unique_unique_variant`] +
/// [`Self::has_unique_repeating_variant`]) one RETURN-SHAPE axis
/// over. Downstream lifts: a peer per-target arity lift
/// `is_unique_unique_variant_of(target, items) -> bool` threading
/// `is_unique_occurrence_of(target, items) &&
/// has_unique_unique_variant(items)` (peer to
/// [`Self::is_unique_repeating_variant_of`] one MULTIPLICITY-BAND
/// axis over on the same surface).
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × equivalence-partition × mult
/// `== 1` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_unique_variant(items) { T::ALL.iter().copied().find(|&v| T::is_unique_occurrence_of(v, items)) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; the N-ary set-
/// level unique-band `Option<Self>` witness-if-unique projection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (set-
/// level × `Option<Self>` × equivalence-partition × mult `== 1` ×
/// unique-tie) witness-if-unique corner was an unnamed inline
/// composition recurring at every prospective downstream "which
/// variant is the sole singleton-multiplicity witness, if it's
/// unambiguous?" site pre-lift. Naming it EXHAUSTIVELY CLOSES the
/// equivalence-partition `Option<Self>` unique-tie row's middle
/// tile as a TYPED THEOREM the substrate proves once. THEORY.md
/// §VI.1 — generation over composition; the projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::has_unique_unique_variant`] +
/// [`Self::is_unique_occurrence_of`]) with an `if _ { _.find(…) }
/// else { None }` combinator on `Option<Self>`, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); s <- names(t)[t
/// == 1]; if (length(s) == 1) s[1] else NA }` — the canonical
/// guarded singleton-multiplicity first-witness on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items), s =
/// filter(kv -> kv[2] == 1, collect(c)); length(s) == 1 ?
/// Some(s[1][1]) : Nothing end`; Python's `let c =
/// collections.Counter(items); s = [k for k, v in c.items() if v
/// == 1]; s[0] if len(s) == 1 else None`; Haskell's `let hs =
/// map (\g -> (head g, length g)) . group . sort $ items; ss =
/// filter (\(_, c) -> c == 1) hs in case ss of [(v, _)] -> Just
/// v; _ -> Nothing`; Clojure's `(let [ss (filter #(= (val %) 1)
/// (frequencies coll))] (when (= 1 (count ss)) (key (first ss))))`;
/// SQL's `SELECT variant FROM (SELECT variant, COUNT(*) AS c FROM
/// t GROUP BY variant HAVING c = 1) WHERE (SELECT COUNT(*) FROM
/// …) = 1`. Translation through pleme-io primitives: the N-ary
/// set-level uniqueness-gated singleton-multiplicity witness
/// projection on the closed-set trait binds through the just-
/// lifted [`Self::has_unique_unique_variant`] guard composed with
/// a declaration-order find sweep of [`Self::ALL`] through the
/// substrate's [`Self::is_unique_occurrence_of`] primitive under
/// an `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying
/// aggregates with short-circuiting on both the guard and the
/// find.
fn unique_unique_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_unique_variant(items) {
<Self as ClosedSet>::ALL
.iter()
.copied()
.find(|&v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique missing variant"
/// projection — `Some(v)` iff `items` has a UNIQUE miss-band witness
/// ([`Self::has_unique_missing_variant`] holds) AND `v` is the sole
/// variant of [`Self::ALL`] whose per-target multiplicity sits at
/// `== 0`, else `None`. Computed as the just-lifted set-level
/// miss-band uniqueness bit [`Self::has_unique_missing_variant`]
/// guarding a declaration-order first-witness sweep of [`Self::ALL`]
/// keyed on `!<Self as ClosedSet>::occurs_in`: when the guard holds
/// the sweep hits the SOLE missing variant unambiguously; when the
/// guard falsifies the projection collapses to `None`. The
/// `Option<Self>`-RETURN UNIQUE-TIE SHARPENING corner EXHAUSTIVELY
/// CLOSING the miss-band arm of the (set-level × `Option<Self>` ×
/// equivalence-partition × multiplicity-band × unique-tie) row on
/// the EQUIVALENCE-PARTITION surface at its (mult `== 0`) band —
/// the FINAL THIRD tile past the just-lifted (mult `>= 2`) peer
/// [`Self::unique_repeating_variant`] and the (mult `== 1`) peer
/// [`Self::unique_unique_variant`] one MULTIPLICITY-BAND axis over.
/// Together the three EXHAUSTIVELY CLOSE the (set-level ×
/// `Option<Self>` × equivalence-partition × mult-band × unique-tie)
/// trichotomy row on the equivalence-partition surface — peer to
/// [`Self::has_unique_missing_variant`] one RETURN-SHAPE axis over
/// (set-level × `bool` miss-band uniqueness bit → set-level ×
/// `Option<Self>` miss-band witness-when-unique) AND peer to
/// [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] one SURFACE axis over on the
/// modal-aggregation matrix. Not a fresh substrate primitive on the
/// index axis — the projection emerges from a boolean conjunction
/// of the just-lifted set-level miss-band uniqueness bit with a
/// declaration-order first-witness [`Iterator::find`] sweep under
/// an `Option`-collapse when the guard falsifies.
///
/// Guarded-first-witness identity: for every slice `items`,
/// `T::unique_missing_variant(items) ==
/// if T::has_unique_missing_variant(items)
/// { T::ALL.iter().copied().find(|&v| !T::occurs_in(v, items)) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::unique_missing_variant(items).is_some() ==
/// T::has_unique_missing_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level miss-band
/// uniqueness bit. Independent cross-check on the surface axis
/// (`Option::is_some` vs conditional-Option construction).
///
/// Missing witness singleton identity: for every slice `items`,
/// `T::unique_missing_variant(items) == (if T::missing_variants(items).len() == 1 { Some(T::missing_variants(items)[0]) } else { None })`
/// — when `items` has a unique missing witness the declaration-
/// order missing witness-collection [`Self::missing_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::has_unique_missing_variant`] (ordering-agnostic — the
/// underlying [`Self::count_missing`] is invariant under slice-
/// reversal) and a declaration-order sweep of the ambient
/// [`Self::ALL`] keyed on the negation of [`Self::occurs_in`] (also
/// ordering-agnostic on the input axis via
/// [`Self::count_occurrences_of`]) under a boolean-guarded
/// `Option`-collapse. No separate `sorted_unique_missing_variant`
/// peer is needed until the sibling LEX corner is opened.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::unique_missing_variant(&[]) == None` — the empty slice hits
/// zero positions, EVERY variant sits at multiplicity `0`,
/// [`Self::count_missing`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `None`. The SOLE positive
/// arm on the empty-slice fixpoint sits at `T::CARDINALITY == 1`
/// where the singleton closed set's SOLE variant is trivially
/// missing from the empty slice, [`Self::count_missing`] reports
/// `1`, and the sweep hits `T::ALL[0]`.
///
/// Matching-singleton contract at cardinality `>= 3`:
/// `T::unique_missing_variant(&[v]) == None` for every variant
/// `v` — the target hits count `1`, every non-target sits at
/// count `0`, `T::CARDINALITY - 1 >= 2` non-target variants are
/// simultaneously missing, [`Self::count_missing`] reports
/// `T::CARDINALITY - 1 >= 2`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `None`.
///
/// Full-set contract: `T::unique_missing_variant(T::ALL) == None`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// pins every variant at exactly one position, no variant is
/// missing, [`Self::count_missing`] reports `0`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `None`.
///
/// Doubled-full-set contract: `T::unique_missing_variant(T::ALL ++
/// T::ALL) == None` UNCONDITIONALLY — the doubled full set hits
/// every variant at exactly two positions, no variant is missing,
/// [`Self::count_missing`] reports `0`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `None`.
///
/// Single-missing contract at cardinality `>= 2`: on
/// `T::ALL[..T::CARDINALITY - 1]` (the full set minus its declaration-
/// order last variant) `T::ALL[T::CARDINALITY - 1]` is the SOLE
/// missing witness at multiplicity `0`, every other variant sits at
/// multiplicity `1`, [`Self::count_missing`] reports `1`,
/// [`Self::has_unique_missing_variant`] returns `true`, the guard
/// fires, and the declaration-order sweep of [`Self::ALL`] bypasses
/// every present variant and hits `T::ALL[T::CARDINALITY - 1]` at
/// its miss entry — the LOAD-BEARING SOLE `Some(_)`-arm on the
/// canonical fixture window at cardinality `>= 2`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_missing_variant`] + [`Self::occurs_in`] via
/// a boolean-guarded declaration-order `Iterator::find` sweep on
/// the negation of [`Self::occurs_in`]. Cost:
/// `O(T::CARDINALITY * n)` on slice arity `n`, allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched); the
/// short-circuiting `if` avoids the sweep when the guard falsifies.
///
/// Future consumers that compose against
/// [`Self::unique_missing_variant`]: a `tatara-check` predicate
/// `(check-single-hole-if-unique …)` that reports "the sole
/// missing variant, if unambiguous" as a typed `Option`-return
/// rather than a two-step (has-unique-missing? then
/// dig-out-witness) composition; an LSP diagnostic on a Lisp-
/// authored variant-list that surfaces the SOLE omitted enum-arm
/// — the canonical "you forgot one" reviewer heuristic — only when
/// the omission is unambiguous, staying silent on multiple-omission
/// windows; a Sekiban audit-trail per-window witness-if-unique
/// binding to the same scalar, composable with the just-lifted
/// set-level miss-band uniqueness bit into a typed (unique-miss-
/// bit, unique-miss-witness) classifier; a scheduler-fairness
/// heuristic that binds the sole never-scheduled worker as the
/// singular boost target only when the answer is unambiguous.
/// Each binds to ONE typed `Option<Self>`-return uniqueness-gated
/// miss-band aggregate on the trait rather than re-deriving
/// `if T::has_unique_missing_variant(items) { T::ALL.iter().copied().find(|&v| !T::occurs_in(v, items)) } else { None }`
/// inline per callsite OR paying the Vec allocation
/// `T::missing_variants(items).into_iter().next().filter(|_| T::missing_variants(items).len() == 1)`
/// would demand.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// miss-band arm of the (set-level × `Option<Self>` × equivalence-
/// partition × multiplicity-band × unique-tie) trichotomy row on
/// the equivalence-partition surface at its FINAL third tile past
/// the just-lifted [`Self::unique_repeating_variant`] (mult `>= 2`)
/// strict-repeat arm AND [`Self::unique_unique_variant`] (mult
/// `== 1`) unique-band arm one MULTIPLICITY-BAND axis over — the
/// three together EXHAUSTIVELY CLOSE the (set-level × `Option<Self>`
/// × equivalence-partition × mult-band × unique-tie) trichotomy on
/// the equivalence-partition surface. Peer to
/// [`Self::has_unique_missing_variant`] one RETURN-SHAPE axis over
/// (bool → `Option<Self>`) AND peer to
/// [`Self::unique_extremal_variant`] +
/// [`Self::unique_middle_band_variant`] +
/// [`Self::unique_bimodal_variant`] one SURFACE axis over on the
/// modal-aggregation matrix. The natural next lifts past this
/// corner are the two peer per-target arity lifts —
/// `is_unique_missing_variant_of(target, items)` (mult `== 0`
/// per-target opener) and `is_unique_unique_variant_of(target,
/// items)` (mult `== 1` per-target opener) — closing the (per-
/// target × bool × equivalence-partition × mult-band × unique-tie)
/// 3-corner row on the trichotomy alongside the already-opened
/// (mult `>= 2`) [`Self::is_unique_repeating_variant_of`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-missing `Option<Self>` witness projection becomes
/// a TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline
/// `if T::has_unique_missing_variant(items) { T::missing_variants(items).first().copied() } else { None }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Option<Self>` × equivalence-
/// partition × mult `== 0` × unique-tie) witness-if-unique corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "which variant is the histogram's sole omission, if
/// unambiguous?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the just-lifted set-level
/// miss-band uniqueness bit and the per-target occurrence
/// membership primitive under a boolean-guarded declaration-order
/// first-witness collapse. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of TWO
/// substrate primitives ([`Self::has_unique_missing_variant`] +
/// [`Self::occurs_in`]) with the `if _ { ALL.find(!occurs_in) }
/// else { None }` combinator on `Option<Self>`, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(factor(items,
/// levels = LEVELS)); m <- names(t)[t == 0]; if (length(m) == 1)
/// m[1] else NA }` — the guarded singleton-omission first-witness
/// on a factor histogram over a closed level set; Julia's `let c =
/// StatsBase.countmap(items), miss = filter(v -> get(c, v, 0) == 0,
/// LEVELS); length(miss) == 1 ? Some(miss[1]) : Nothing end`;
/// Python's `{ c = collections.Counter(items); miss = [v for v in
/// LEVELS if c[v] == 0]; miss[0] if len(miss) == 1 else None }`;
/// Haskell's `let hs = Set.fromList items; ms = filter (\v ->
/// not (Set.member v hs)) allLevels in case ms of [v] -> Just v; _
/// -> Nothing`; Clojure's `(let [present (set coll), miss (remove
/// present LEVELS)] (when (= 1 (count miss)) (first miss)))`; SQL's
/// `SELECT variant FROM levels WHERE variant NOT IN (SELECT
/// DISTINCT variant FROM t) AND (SELECT COUNT(*) FROM levels WHERE
/// variant NOT IN (SELECT DISTINCT variant FROM t)) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated miss-band witness projection on the closed-set
/// trait binds through the just-lifted
/// [`Self::has_unique_missing_variant`] guard conjoined with a
/// declaration-order [`Iterator::find`] sweep of [`Self::ALL`]
/// keyed on the negation of [`Self::occurs_in`] under an
/// `Option`-collapse — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying miss-count
/// aggregate with short-circuiting on the guard.
fn unique_missing_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_missing_variant(items) {
<Self as ClosedSet>::ALL
.iter()
.copied()
.find(|&v| !<Self as ClosedSet>::occurs_in(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique missing variant, lex-
/// first" projection — `Some(v)` iff `items` has a UNIQUE miss-band
/// witness ([`Self::has_unique_missing_variant`] holds) AND `v` is
/// the sole variant of [`Self::sorted_variants`] whose per-target
/// multiplicity sits at `== 0`, else `None`. Computed as the just-
/// lifted set-level miss-band uniqueness bit
/// [`Self::has_unique_missing_variant`] guarding a LEX-ORDER first-
/// witness sweep of [`Self::sorted_variants`] keyed on
/// `!<Self as ClosedSet>::occurs_in`. The LEX-ORDER `Option<Self>`-
/// RETURN UNIQUE-TIE SHARPENING corner OPENING the (set-level ×
/// `Option<Self>` × ordering × equivalence-partition ×
/// multiplicity-band × unique-tie) row on the EQUIVALENCE-PARTITION
/// surface at its (mult `== 0`) miss-band arm — the lex-ordering
/// peer of the just-lifted declaration-order
/// [`Self::unique_missing_variant`] one ORDERING axis over, peer to
/// [`Self::sorted_missing_variants`] one UNIQUE-TIE-SHARPENING axis
/// over (existential `>= 1` Vec of misses → uniqueness `== 1`
/// `Option<Self>` collapse), AND peer to
/// [`Self::sorted_extremal_variant`] +
/// [`Self::sorted_middle_band_variant`] +
/// [`Self::sorted_bimodal_variant`] one SURFACE axis over on the
/// modal-aggregation matrix. Not a fresh substrate primitive on the
/// index axis — the projection emerges from a boolean conjunction
/// of the just-lifted set-level miss-band uniqueness bit with a
/// lex-order first-witness [`Iterator::find`] sweep of
/// [`Self::sorted_variants`] under an `Option`-collapse when the
/// guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_missing_variant(items) ==
/// T::unique_missing_variant(items)` — when the sole missing
/// witness is UNIQUE ([`Self::has_unique_missing_variant`] holds)
/// declaration-order and lex-order both walk `T::CARDINALITY - 1`
/// present variants and land on THE SAME SOLE missing variant; when
/// the guard falsifies both projections collapse to `None` through
/// the same guard arm. The LEX peer is thus IDENTICALLY equal to
/// its declaration-order sibling on every input — the ordering
/// axis becomes provably irrelevant WHEN the underlying uniqueness
/// bit holds. Pinned by
/// `sorted_unique_missing_variant_equals_unique_missing_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_missing_variant(items) ==
/// if T::has_unique_missing_variant(items)
/// { T::sorted_variants().into_iter().find(|&v| !T::occurs_in(v, items)) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_missing_variant(items).is_some() ==
/// T::has_unique_missing_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level miss-band
/// uniqueness bit. Independent cross-check on the surface axis
/// (`Option::is_some` vs conditional-Option construction).
///
/// Sorted-missing witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_missing_variant(items) == (if T::sorted_missing_variants(items).len() == 1 { Some(T::sorted_missing_variants(items)[0]) } else { None })`
/// — when `items` has a unique missing witness the lex-order
/// missing witness-collection [`Self::sorted_missing_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_missing_variant`] (ordering-agnostic on the
/// input axis — the underlying [`Self::count_missing`] is invariant
/// under slice-reversal) and a lex-order sweep of
/// [`Self::sorted_variants`] keyed on the negation of
/// [`Self::occurs_in`] (also ordering-agnostic on the input axis
/// via [`Self::count_occurrences_of`]) under a boolean-guarded
/// `Option`-collapse.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::sorted_unique_missing_variant(&[]) == None` — the empty
/// slice hits zero positions, every variant sits at multiplicity
/// `0`, [`Self::count_missing`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `None`.
///
/// Full-set + doubled-full-set contract:
/// `T::sorted_unique_missing_variant(T::ALL) == None` and
/// `T::sorted_unique_missing_variant(T::ALL ++ T::ALL) == None`
/// UNCONDITIONALLY — clause (3)'s pairwise-distinctness invariant
/// forces every variant present at count `>= 1` on both fixtures,
/// no variant is missing, and the guard collapses to `None`.
///
/// Single-missing contract at cardinality `>= 2`: on
/// `T::ALL[..T::CARDINALITY - 1]` (the full set minus its
/// declaration-order last variant) `T::ALL[T::CARDINALITY - 1]` is
/// the SOLE missing witness at multiplicity `0`,
/// [`Self::has_unique_missing_variant`] returns `true`, the guard
/// fires, and the lex-order sweep of [`Self::sorted_variants`]
/// bypasses every present variant and hits
/// `T::ALL[T::CARDINALITY - 1]` at its sole missing entry — the
/// SAME variant the declaration-order sweep at
/// [`Self::unique_missing_variant`] lands on. The LOAD-BEARING
/// SOLE `Some(_)`-arm on the canonical single-missing fixture
/// witnesses the ordering-choice-irrelevance identity structurally.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_missing_variant`] + [`Self::occurs_in`] +
/// [`Self::sorted_variants`] via a boolean-guarded lex-order
/// [`Iterator::find`] sweep on the negation of [`Self::occurs_in`].
/// Cost: `O(T::CARDINALITY * n)` on slice arity `n` for the
/// [`Self::count_occurrences_of`] sweeps + `O(T::CARDINALITY log
/// T::CARDINALITY)` for the [`Self::sorted_variants`] cache, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched); the
/// short-circuiting `if` avoids the sweep when the guard falsifies.
///
/// Future consumers that compose against
/// [`Self::sorted_unique_missing_variant`]: a `tatara-check`
/// predicate `(check-single-hole-if-unique-lex-first …)` that
/// reports "the sole missing variant, in lex order, if unambiguous"
/// for a caller that prefers lex-order presentation regardless of
/// declaration-order (which may be arbitrary or convenience-
/// ordered); an LSP diagnostic on a Lisp-authored variant-list that
/// surfaces the SOLE lex-first omitted enum-arm — the canonical
/// "you forgot one" reviewer heuristic — sorted so the highlight
/// stays deterministic under enum refactoring that permutes
/// declaration order; a Sekiban audit-trail per-window witness-if-
/// unique binding that pins the lex-order first-witness for
/// stability against upstream declaration-order churn. Each binds
/// to ONE typed lex-order `Option<Self>`-return uniqueness-gated
/// miss-band aggregate on the trait — AND, by the ordering-choice-
/// irrelevance identity, TYPED PROOF that the ordering choice is
/// operationally free WHEN the underlying uniqueness bit holds
/// (the substrate proves the equivalence once so every downstream
/// consumer can pick whichever surface reads best without
/// re-verifying the coincidence per callsite).
///
/// Compounding closure: this projection OPENS the miss-band arm of
/// the (set-level × `Option<Self>` × ordering × equivalence-
/// partition × multiplicity-band × unique-tie) row on the
/// equivalence-partition surface at its (mult `== 0`) band under
/// the LEX-ORDER ordering peer — the lex peer of the just-lifted
/// declaration-order [`Self::unique_missing_variant`] one ORDERING
/// axis over. The natural next lifts past this corner are the two
/// peer lex mult-band arms —
/// `sorted_unique_unique_variant(items)` (mult `== 1` lex opener)
/// and `sorted_unique_repeating_variant(items)` (mult `>= 2` lex
/// opener) — closing the (set-level × `Option<Self>` × sorted ×
/// equivalence-partition × mult-band × unique-tie) trichotomy row
/// past THIS mult `== 0` opener alongside the already-closed
/// declaration-order (set-level × `Option<Self>` × equivalence-
/// partition × mult-band × unique-tie) trichotomy row.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × equivalence-partition ×
/// mult `== 0` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_missing_variant(items) { T::sorted_variants().into_iter().find(|&v| !T::occurs_in(v, items)) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; the N-ary lex-
/// order set-level unique-missing `Option<Self>` witness projection
/// becomes a TYPE-level primitive on the closed-set trait alongside
/// its declaration-order sibling; the ordering-choice-irrelevance
/// identity between the two is itself a TYPED THEOREM the substrate
/// proves once at [`assert_closed_set_well_formed`] rather than at
/// every downstream callsite. THEORY.md §V.1 — knowable platform;
/// the (lex-order × `Option<Self>` × mult `== 0` × unique-tie)
/// corner was an unnamed inline composition — OR silently absent
/// because the caller shrugged and used the declaration-order
/// sibling without proof of coincidence — recurring at every
/// prospective downstream "which variant is the histogram's sole
/// omission, in lex order, if unambiguous?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of the three substrate primitives
/// [`Self::has_unique_missing_variant`], [`Self::sorted_variants`],
/// and [`Self::occurs_in`] with the
/// `if _ { sorted_variants.find(!occurs_in) } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: R's `{ t <- table(factor(items, levels =
/// LEVELS)); m <- sort(names(t)[t == 0]); if (length(m) == 1) m[1]
/// else NA }` — the guarded singleton-omission lex-first witness on
/// a sorted factor histogram; Julia's `let c =
/// StatsBase.countmap(items), miss = filter(v -> get(c, v, 0) == 0,
/// sort(LEVELS)); length(miss) == 1 ? Some(miss[1]) : Nothing end`;
/// Python's `sorted(v for v in LEVELS if collections.Counter(items)[v] == 0)[:1]`
/// filtered by length; Haskell's `let hs = Set.fromList items; ms =
/// filter (\v -> not (Set.member v hs)) (sort allLevels) in case
/// ms of [v] -> Just v; _ -> Nothing`; SQL's `SELECT variant FROM
/// levels WHERE variant NOT IN (SELECT DISTINCT variant FROM t)
/// ORDER BY variant LIMIT 1` filtered by an outer count-guard.
/// Translation through pleme-io primitives: the projection binds
/// through the just-lifted [`Self::has_unique_missing_variant`]
/// guard conjoined with a lex-order [`Iterator::find`] sweep of
/// [`Self::sorted_variants`] keyed on the negation of
/// [`Self::occurs_in`] under an `Option`-collapse — no new dep, no
/// supertrait bound (`Sized + Copy + 'static` stays untouched),
/// cost inherited from the underlying aggregates with short-
/// circuiting on the guard.
fn sorted_unique_missing_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_missing_variant(items) {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| !<Self as ClosedSet>::occurs_in(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique strictly-repeating variant,
/// lex-first" projection — `Some(v)` iff `items` has a UNIQUE strict-
/// repeat witness ([`Self::has_unique_repeating_variant`] holds) AND
/// `v` is the sole variant of [`Self::sorted_variants`] whose per-
/// target multiplicity sits at `>= 2`, else `None`. Computed as the
/// just-lifted set-level strict-repeat uniqueness bit
/// [`Self::has_unique_repeating_variant`] guarding a LEX-ORDER first-
/// witness sweep of [`Self::sorted_variants`] keyed on
/// [`Self::is_repeated_occurrence_of`]. The LEX-ORDER `Option<Self>`-
/// RETURN UNIQUE-TIE SHARPENING corner OPENING the (set-level ×
/// `Option<Self>` × sorted × equivalence-partition × multiplicity-band
/// × unique-tie) row on the EQUIVALENCE-PARTITION surface at its
/// (mult `>= 2`) strict-repeat arm — the lex-ordering peer of the
/// just-closed declaration-order [`Self::unique_repeating_variant`]
/// one ORDERING axis over, peer to
/// [`Self::sorted_repeating_variants`] one UNIQUE-TIE-SHARPENING axis
/// over (existential `>= 1` Vec of strict-repeaters → uniqueness
/// `== 1` `Option<Self>` collapse), AND peer to
/// [`Self::sorted_unique_missing_variant`] one MULTIPLICITY-BAND axis
/// over on the equivalence-partition surface (the two together
/// bracket the LEX-ORDER `Option<Self>` unique-tie sharpening at BOTH
/// EXTREMAL bands of the mult-band trichotomy — the mult `== 1`
/// middle arm `sorted_unique_unique_variant` remains the last tile).
/// Not a fresh substrate primitive on the index axis — the projection
/// emerges from a boolean conjunction of the set-level strict-repeat
/// uniqueness bit with a lex-order first-witness [`Iterator::find`]
/// sweep of [`Self::sorted_variants`] under an `Option`-collapse when
/// the guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_repeating_variant(items) ==
/// T::unique_repeating_variant(items)` — when the sole strict-repeat
/// witness is UNIQUE ([`Self::has_unique_repeating_variant`] holds)
/// declaration-order and lex-order both walk the same predicate over
/// the same `T::CARDINALITY`-sized variant carrier and land on THE
/// SAME SOLE strict-repeat variant; when the guard falsifies both
/// projections collapse to `None` through the same guard arm. The
/// LEX peer is thus IDENTICALLY equal to its declaration-order
/// sibling on every input — the ordering axis becomes provably
/// irrelevant WHEN the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_repeating_variant_equals_unique_repeating_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_repeating_variant(items) ==
/// if T::has_unique_repeating_variant(items)
/// { T::sorted_variants().into_iter().find(|&v| T::is_repeated_occurrence_of(v, items)) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_repeating_variant(items).is_some() ==
/// T::has_unique_repeating_variant(items)` — the `Option<Self>`
/// return's `is_some` bit COINCIDES with the set-level strict-repeat
/// uniqueness bit. Independent cross-check on the surface axis
/// (`Option::is_some` vs conditional-Option construction).
///
/// Sorted-repeating witness singleton identity: for every slice
/// `items`,
/// `T::sorted_unique_repeating_variant(items) == (if T::sorted_repeating_variants(items).len() == 1 { Some(T::sorted_repeating_variants(items)[0]) } else { None })`
/// — when `items` has a unique strict-repeat witness the lex-order
/// strict-repeat witness-collection [`Self::sorted_repeating_variants`]
/// collapses to a length-`1` Vec containing EXACTLY that unique
/// variant, so its slot-`0` wrapped in `Some` coincides with THIS
/// projection.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_repeating_variant`] (ordering-agnostic on the
/// input axis — the underlying [`Self::count_repeating_variants`] is
/// invariant under slice-reversal) and a lex-order sweep of
/// [`Self::sorted_variants`] keyed on
/// [`Self::is_repeated_occurrence_of`] (also ordering-agnostic on
/// the input axis via [`Self::count_occurrences_of`]) under a
/// boolean-guarded `Option`-collapse.
///
/// Empty-slice contract: `T::sorted_unique_repeating_variant(&[]) ==
/// None` UNCONDITIONALLY — the empty slice hits zero positions,
/// every variant sits at multiplicity `0`,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses the projection to `None` before the
/// [`Self::sorted_variants`] sweep is consulted.
///
/// Matching-singleton contract:
/// `T::sorted_unique_repeating_variant(&[v]) == None` for every
/// variant `v` — the sole position hits `v` at count `1` (not
/// strictly repeating), every non-target sits at count `0` (also not
/// strictly repeating); [`Self::count_repeating_variants`] reports
/// `0`, [`Self::has_unique_repeating_variant`] returns `false`, and
/// the guard collapses to `None`.
///
/// Full-set contract:
/// `T::sorted_unique_repeating_variant(T::ALL) == None` — clause
/// (3)'s pairwise-distinctness invariant pins every variant at
/// exactly one position, every per-target multiplicity is `1`,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses to `None`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::sorted_unique_repeating_variant(&doubled) == None` — the
/// doubled full set hits every variant at EXACTLY TWO positions,
/// every per-target multiplicity is `2 >= 2`, EVERY variant is a
/// strict-repeat witness, [`Self::count_repeating_variants`] reports
/// `T::CARDINALITY >= 2`, [`Self::has_unique_repeating_variant`]
/// returns `false` (multiple witnesses, no unique one), and the
/// guard collapses to `None`.
///
/// Bimodal-triple contract at cardinality `>= 3` (LOAD-BEARING
/// POSITIVE ARM):
/// `T::sorted_unique_repeating_variant([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == Some(T::ALL[0])`. On the non-flat triple
/// `T::ALL[0]` sits at count `2 >= 2` (the SOLE strict-repeat
/// witness), `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
/// [`Self::has_unique_repeating_variant`] returns `true`, the guard
/// fires, and the lex-order sweep of [`Self::sorted_variants`] hits
/// the SAME sole strict-repeat variant `T::ALL[0]` that the
/// declaration-order sweep at [`Self::unique_repeating_variant`]
/// lands on. The LOAD-BEARING SOLE `Some(_)`-arm on the canonical
/// bimodal-triple fixture witnesses the ordering-choice-irrelevance
/// identity structurally — BY UNIQUENESS of the strict-repeat witness
/// the sole strict-repeater is the ONLY variant either sweep can
/// find.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::is_repeated_occurrence_of`] + [`Self::sorted_variants`]
/// via a boolean-guarded lex-order [`Iterator::find`] sweep. Cost:
/// `O(T::CARDINALITY * n)` on slice arity `n` for the
/// [`Self::count_occurrences_of`] sweeps + `O(T::CARDINALITY log
/// T::CARDINALITY)` for the [`Self::sorted_variants`] cache, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched); the
/// short-circuiting `if` avoids the sweep when the guard falsifies
/// and `find` short-circuits on the first hit when it holds.
///
/// Future consumers that compose against
/// [`Self::sorted_unique_repeating_variant`]: a `tatara-check`
/// predicate `(check-strict-repeat-if-unique-lex-first …)` that
/// reports "the sole strictly-repeating variant, in lex order, if
/// unambiguous" for a caller that prefers lex-order presentation
/// regardless of declaration-order (which may be arbitrary or
/// convenience-ordered); an LSP diagnostic on a Lisp-authored
/// `:severities [:info :warn :info]` closed-set field that surfaces
/// the SOLE strictly-repeated enum-arm ("used more than once:
/// [info]") sorted so the highlight stays deterministic under enum
/// refactoring that permutes declaration order; a Sekiban audit-
/// trail per-window witness-if-unique binding that pins the lex-
/// order first-witness for stability against upstream declaration-
/// order churn. Each binds to ONE typed lex-order `Option<Self>`-
/// return uniqueness-gated strict-repeat aggregate on the trait —
/// AND, by the ordering-choice-irrelevance identity, TYPED PROOF
/// that the ordering choice is operationally free WHEN the
/// underlying uniqueness bit holds (the substrate proves the
/// equivalence once so every downstream consumer can pick whichever
/// surface reads best without re-verifying the coincidence per
/// callsite).
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Option<Self>` × sorted × equivalence-partition × multiplicity-
/// band × unique-tie) row on the equivalence-partition surface at
/// its (mult `>= 2`) strict-repeat arm under the LEX-ORDER ordering
/// peer — the lex peer of the just-closed declaration-order
/// [`Self::unique_repeating_variant`] one ORDERING axis over, peer
/// to the just-lifted [`Self::sorted_unique_missing_variant`]
/// (mult `== 0` lex opener) one MULTIPLICITY-BAND axis over. The
/// two together bracket the lex-order `Option<Self>` unique-tie
/// sharpening at BOTH EXTREMAL mult-bands; the natural next lift
/// past this corner is the remaining middle-band lex peer
/// `sorted_unique_unique_variant(items)` (mult `== 1` lex opener)
/// which EXHAUSTIVELY CLOSES the (set-level × `Option<Self>` ×
/// sorted × equivalence-partition × mult-band × unique-tie)
/// trichotomy row at its FINAL third tile.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × equivalence-partition ×
/// mult `>= 2` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_repeating_variant(items) { T::sorted_variants().into_iter().find(|&v| T::is_repeated_occurrence_of(v, items)) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-
/// irrelevance) the substrate proves once rather than every
/// downstream site re-proving via
/// `sorted_unique_repeating_variant(items) == unique_repeating_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform;
/// the (lex-order × `Option<Self>` × mult `>= 2` × unique-tie)
/// corner was an unnamed inline composition — OR silently absent
/// because the caller shrugged and used the declaration-order
/// sibling without proof of coincidence — recurring at every
/// prospective downstream "which variant is the sole strict-repeat
/// witness, in lex order, if unambiguous?" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the projection emerges from
/// the composition of the three substrate primitives
/// [`Self::has_unique_repeating_variant`], [`Self::sorted_variants`],
/// and [`Self::is_repeated_occurrence_of`] with the
/// `if _ { sorted_variants.find(is_repeated_occurrence_of) } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: R's `{ t <- table(factor(items, levels =
/// LEVELS)); r <- sort(names(t)[t >= 2]); if (length(r) == 1) r[1]
/// else NA }` — the guarded singleton-repeat lex-first witness on a
/// sorted factor histogram; Julia's `let c =
/// StatsBase.countmap(items), r = filter(v -> get(c, v, 0) >= 2,
/// sort(LEVELS)); length(r) == 1 ? Some(r[1]) : Nothing end`;
/// Python's `sorted(v for v in LEVELS if collections.Counter(items)[v] >= 2)[:1]`
/// filtered by length; Haskell's `let c = Map.fromListWith (+) [(v, 1)
/// | v <- items]; rs = filter (\v -> Map.findWithDefault 0 v c >= 2)
/// (sort allLevels) in case rs of [v] -> Just v; _ -> Nothing`;
/// Clojure's `(let [rs (filter #(>= (get (frequencies coll) % 0) 2)
/// (sort ALL-LEVELS))] (when (= 1 (count rs)) (first rs)))`; SQL's
/// `SELECT variant FROM levels WHERE variant IN (SELECT variant FROM
/// t GROUP BY variant HAVING COUNT(*) >= 2) ORDER BY variant LIMIT 1`
/// filtered by an outer count-guard. Translation through
/// pleme-io primitives: the projection binds through the just-
/// lifted [`Self::has_unique_repeating_variant`] guard conjoined
/// with a lex-order [`Iterator::find`] sweep of
/// [`Self::sorted_variants`] keyed on
/// [`Self::is_repeated_occurrence_of`] under an `Option`-collapse —
/// no new dep, no supertrait bound (`Sized + Copy + 'static` stays
/// untouched), cost inherited from the underlying aggregates with
/// short-circuiting on the guard.
fn sorted_unique_repeating_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_repeating_variant(items) {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| <Self as ClosedSet>::is_repeated_occurrence_of(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC "THE unique unique-band variant,
/// lex-first" projection — `Some(v)` iff `items` has a UNIQUE
/// singleton-multiplicity witness ([`Self::has_unique_unique_variant`]
/// holds) AND `v` is the sole variant of [`Self::sorted_variants`]
/// whose per-target multiplicity sits EXACTLY at `1`, else `None`.
/// Computed as the just-lifted set-level unique-band uniqueness bit
/// [`Self::has_unique_unique_variant`] guarding a LEX-ORDER first-
/// witness sweep of [`Self::sorted_variants`] keyed on the substrate's
/// per-target singleton-multiplicity primitive
/// [`Self::is_unique_occurrence_of`]. The LEX-ORDER `Option<Self>`-
/// RETURN UNIQUE-TIE SHARPENING corner EXHAUSTIVELY CLOSING the
/// middle-band arm of the (set-level × `Option<Self>` × sorted ×
/// equivalence-partition × multiplicity-band × unique-tie) row on the
/// EQUIVALENCE-PARTITION surface at its (mult `== 1`) band — the FINAL
/// THIRD tile past the just-lifted (mult `>= 2`)
/// [`Self::sorted_unique_repeating_variant`] strict-repeat arm AND the
/// just-lifted (mult `== 0`) [`Self::sorted_unique_missing_variant`]
/// miss-band arm one MULTIPLICITY-BAND axis over. Together the three
/// EXHAUSTIVELY CLOSE the (set-level × `Option<Self>` × sorted ×
/// equivalence-partition × mult-band × unique-tie) trichotomy row on
/// the LEX-ORDER equivalence-partition surface. Peer to
/// [`Self::unique_unique_variant`] one ORDERING axis over (the
/// declaration-order sibling this LEX peer is provably identical to),
/// AND peer to [`Self::has_unique_unique_variant`] one RETURN-SHAPE
/// axis over. Not a fresh substrate primitive on the index axis — the
/// projection emerges from a boolean-guarded lex-order first-witness
/// [`Iterator::find`] sweep of [`Self::sorted_variants`] under an
/// `Option`-collapse when the guard falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_unique_variant(items) ==
/// T::unique_unique_variant(items)` — when the sole singleton-
/// multiplicity witness is UNIQUE ([`Self::has_unique_unique_variant`]
/// holds) declaration-order and lex-order both walk the same predicate
/// over the same `T::CARDINALITY`-sized variant carrier and land on
/// THE SAME SOLE (mult `== 1`) variant; when the guard falsifies both
/// projections collapse to `None` through the same guard arm. The LEX
/// peer is thus IDENTICALLY equal to its declaration-order sibling on
/// every input — the ordering axis becomes provably irrelevant WHEN
/// the underlying uniqueness bit holds. Pinned by
/// `sorted_unique_unique_variant_equals_unique_unique_variant_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-first-witness identity: for every slice `items`,
/// `T::sorted_unique_unique_variant(items) ==
/// if T::has_unique_unique_variant(items)
/// { T::sorted_variants().into_iter().find(|&v| T::is_unique_occurrence_of(v, items)) }
/// else { None }` — the canonical form the body uses.
///
/// Is-some coincidence identity: for every slice `items`,
/// `T::sorted_unique_unique_variant(items).is_some() ==
/// T::has_unique_unique_variant(items)` — the `Option<Self>` return's
/// `is_some` bit COINCIDES with the set-level unique-band uniqueness
/// bit. Independent cross-check on the surface axis (`Option::is_some`
/// vs conditional-Option construction).
///
/// Sorted-unique witness singleton identity: for every slice `items`,
/// `T::sorted_unique_unique_variant(items) == (if T::sorted_unique_variants(items).len() == 1 { Some(T::sorted_unique_variants(items)[0]) } else { None })`
/// — when `items` has a unique singleton-multiplicity witness the lex-
/// order singleton-multiplicity witness-collection
/// [`Self::sorted_unique_variants`] collapses to a length-`1` Vec
/// containing EXACTLY that unique variant, so its slot-`0` wrapped in
/// `Some` coincides with THIS projection.
///
/// Slice-reversal invariance: the projection factors through
/// [`Self::has_unique_unique_variant`] (ordering-agnostic on the input
/// axis — the underlying [`Self::count_unique_variants`] is invariant
/// under slice-reversal) and a lex-order sweep of
/// [`Self::sorted_variants`] keyed on
/// [`Self::is_unique_occurrence_of`] (also ordering-agnostic on the
/// input axis via [`Self::count_occurrences_of`]) under a boolean-
/// guarded `Option`-collapse.
///
/// Empty-slice contract: `T::sorted_unique_unique_variant(&[]) == None`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false`, and the guard
/// collapses the projection to `None` before the
/// [`Self::sorted_variants`] sweep is consulted.
///
/// Matching-singleton contract: `T::sorted_unique_unique_variant(&[v])
/// == Some(v)` for every variant `v` — the sole position hits `v` at
/// count `1` (the SOLE singleton-multiplicity witness), every non-
/// target sits at count `0` (not singleton-multiplicity);
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, the guard
/// fires, and the lex-order sweep of [`Self::sorted_variants`] finds
/// `v` at its sole singleton entry — the SAME variant the declaration-
/// order sweep at [`Self::unique_unique_variant`] lands on.
///
/// Full-set contract: `T::sorted_unique_unique_variant(T::ALL)` is
/// `Some(T::sorted_variants()[0])` iff [`Self::CARDINALITY`] `== 1`
/// on the implementor, else `None` — clause (3)'s pairwise-distinctness
/// invariant pins every variant at exactly one position of the full-
/// set slice, every per-target multiplicity is `1`,
/// [`Self::count_unique_variants`] reports [`Self::CARDINALITY`],
/// [`Self::has_unique_unique_variant`] holds EXACTLY when
/// [`Self::CARDINALITY`] `== 1`. At `T::CARDINALITY == 1` the guarded
/// lex sweep lands on the sole variant; at `T::CARDINALITY >= 2` every
/// variant is a singleton-multiplicity witness, uniqueness fails, and
/// the guard collapses to `None`.
///
/// Doubled-full-set contract:
/// `T::sorted_unique_unique_variant(T::ALL ++ T::ALL) == None`
/// UNCONDITIONALLY — appending a full-set copy to the full-set slice
/// hits every variant at multiplicity `2`, every per-target
/// multiplicity-`== 1` test fails,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false`, and the guard
/// collapses to `None`.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`
/// (LOAD-BEARING POSITIVE ARM):
/// `T::sorted_unique_unique_variant([T::ALL[0], T::ALL[0], T::ALL[1]])
/// == Some(T::ALL[1])`. On the non-flat triple `T::ALL[0]` sits at
/// count `2 >= 2`, `T::ALL[1]` at count `1` (the SOLE (mult `== 1`)
/// witness), `T::ALL[2..]` at count `0`;
/// [`Self::has_unique_unique_variant`] returns `true`, the guard
/// fires, and the lex-order sweep of [`Self::sorted_variants`] hits
/// the SAME sole singleton-multiplicity variant `T::ALL[1]` that the
/// declaration-order sweep at [`Self::unique_unique_variant`] lands
/// on. The LOAD-BEARING SOLE `Some(_)`-arm on the canonical bimodal-
/// triple fixture witnesses the ordering-choice-irrelevance identity
/// structurally — BY UNIQUENESS of the singleton-multiplicity witness
/// the sole witness is the ONLY variant either sweep can find.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_unique_variant`] +
/// [`Self::is_unique_occurrence_of`] + [`Self::sorted_variants`] via
/// a boolean-guarded lex-order [`Iterator::find`] sweep. Cost:
/// `O(T::CARDINALITY * n)` on slice arity `n` for the
/// [`Self::count_occurrences_of`] sweeps + `O(T::CARDINALITY log
/// T::CARDINALITY)` for the [`Self::sorted_variants`] cache, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched); the
/// short-circuiting `if` avoids the sweep when the guard falsifies
/// and `find` short-circuits on the first hit when it holds.
///
/// Future consumers that compose against
/// [`Self::sorted_unique_unique_variant`]: a `tatara-check` predicate
/// `(check-singleton-hit-if-unique-lex-first …)` that reports "the
/// sole singleton-multiplicity variant, in lex order, if unambiguous"
/// for a caller that prefers lex-order presentation regardless of
/// declaration-order (which may be arbitrary or convenience-ordered);
/// an LSP diagnostic on a Lisp-authored `:phases [:pending :running
/// :pending]` closed-set field that surfaces the SOLE singleton-
/// multiplicity enum-arm ("occurred exactly once: [running]") sorted
/// so the highlight stays deterministic under enum refactoring that
/// permutes declaration order; a Sekiban audit-trail per-window
/// witness-if-unique binding that pins the lex-order singleton-
/// multiplicity witness for stability against upstream declaration-
/// order churn. Each binds to ONE typed lex-order `Option<Self>`-
/// return uniqueness-gated singleton-multiplicity aggregate on the
/// trait — AND, by the ordering-choice-irrelevance identity, TYPED
/// PROOF that the ordering choice is operationally free WHEN the
/// underlying uniqueness bit holds (the substrate proves the
/// equivalence once so every downstream consumer can pick whichever
/// surface reads best without re-verifying the coincidence per
/// callsite).
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × `Option<Self>` × sorted × equivalence-partition ×
/// multiplicity-band × unique-tie) trichotomy row on the LEX-ORDER
/// equivalence-partition surface at its MIDDLE (mult `== 1`) band,
/// past the just-lifted (mult `>= 2`)
/// [`Self::sorted_unique_repeating_variant`] strict-repeat arm AND
/// the just-lifted (mult `== 0`)
/// [`Self::sorted_unique_missing_variant`] miss-band arm one
/// MULTIPLICITY-BAND axis over — the row is now the CANONICAL
/// `Option<Self>`-return unique-tie sharpening on the LEX-ORDER
/// equivalence-partition surface, closed at its FINAL third tile.
/// Mirrors the declaration-order trichotomy row's exhaustive closure
/// ([`Self::unique_missing_variant`] + [`Self::unique_unique_variant`]
/// + [`Self::unique_repeating_variant`]) one ORDERING axis over.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Option<Self>` × sorted × equivalence-partition ×
/// mult `== 1` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_unique_variant(items) { T::sorted_variants().into_iter().find(|&v| T::is_unique_occurrence_of(v, items)) } else { None }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once rather than every downstream site re-proving
/// via `sorted_unique_unique_variant(items) == unique_unique_variant(items)`
/// assertions per callsite. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Option<Self>` × mult `== 1` × unique-tie) corner was
/// an unnamed inline composition — OR silently absent because the
/// caller shrugged and used the declaration-order sibling without
/// proof of coincidence — recurring at every prospective downstream
/// "which variant is the sole singleton-multiplicity witness, in lex
/// order, if unambiguous?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the projection emerges from the
/// composition of the three substrate primitives
/// [`Self::has_unique_unique_variant`], [`Self::sorted_variants`],
/// and [`Self::is_unique_occurrence_of`] with the
/// `if _ { sorted_variants.find(is_unique_occurrence_of) } else { None }`
/// combinator on `Option<Self>`, not as a per-implementor hand-
/// rolled body.
///
/// Frontier inspiration: R's `t <- table(items); s <- sort(names(t)[t == 1]); if (length(s) == 1) s[1] else NA`
/// — the guarded singleton-multiplicity lex-first witness on a sorted
/// factor histogram; Julia's `let c = StatsBase.countmap(items), s = filter(kv -> kv[2] == 1, sort(collect(c), by = kv -> kv[1])); length(s) == 1 ? Some(s[1][1]) : Nothing end`;
/// Python's `sorted(k for k, v in collections.Counter(items).items() if v == 1)[:1]`
/// filtered by length; Haskell's `let hs = Map.fromListWith (+) [(v, 1) | v <- items]; ss = filter (\v -> Map.findWithDefault 0 v hs == 1) (sort allLevels) in case ss of [v] -> Just v; _ -> Nothing`;
/// Clojure's `(let [ss (filter #(= 1 (get (frequencies coll) % 0)) (sort ALL-LEVELS))] (when (= 1 (count ss)) (first ss)))`;
/// SQL's `SELECT variant FROM t GROUP BY variant HAVING COUNT(*) = 1 ORDER BY variant LIMIT 1`
/// filtered by an outer count-guard. Translation through pleme-io
/// primitives: the projection binds through the set-level unique-band
/// uniqueness bit [`Self::has_unique_unique_variant`] conjoined with
/// a lex-order [`Iterator::find`] sweep of [`Self::sorted_variants`]
/// keyed on the substrate's per-target [`Self::is_unique_occurrence_of`]
/// primitive under an `Option`-collapse — no new dep, no supertrait
/// bound (`Sized + Copy + 'static` stays untouched), cost inherited
/// from the underlying aggregates with short-circuiting on the guard.
fn sorted_unique_unique_variant(items: &[Self]) -> Option<Self> {
if <Self as ClosedSet>::has_unique_unique_variant(items) {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.find(|&v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
} else {
None
}
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "is `target` the SOLE
/// absent variant?" predicate — `true` iff `target` does NOT
/// occur in `items` AND exactly ONE variant of [`Self::ALL`] is
/// missing from `items`, computed as the negation of the
/// substrate's per-target membership predicate
/// [`Self::occurs_in`] conjoined with the just-lifted set-level
/// miss-band uniqueness bit [`Self::has_unique_missing_variant`]
/// via `&&`. The (per-target × bool × equivalence-partition ×
/// multiplicity-band `== 0` × unique-tie sharpening) corner
/// OPENING the miss-band arm of the (per-target × bool ×
/// equivalence-partition × mult-band × unique-tie) column past
/// the just-opened (mult `>= 2`)
/// [`Self::is_unique_repeating_variant_of`] strict-repeat arm one
/// MULTIPLICITY-BAND axis over on the EQUIVALENCE-PARTITION
/// surface — the two together bracket the per-target unique-tie
/// sharpening at BOTH EXTREMAL bands of the mult-band trichotomy.
/// Peer to [`Self::has_unique_missing_variant`] one ARITY axis
/// over (set-level `bool` miss-band uniqueness bit → per-target
/// `bool` miss-band membership-if-unique test); peer to
/// [`Self::unique_missing_variant`] one RETURN-SHAPE axis over
/// (set-level `Option<Self>` miss-band witness-when-unique →
/// per-target `bool` miss-band membership-when-unique). Not a
/// fresh substrate primitive on the index axis — the predicate
/// emerges from the boolean conjunction of the negation of the
/// substrate's per-target membership primitive with the just-
/// lifted set-level miss-band uniqueness bit.
///
/// Composition-conjunction identity: for every slice `items` and
/// every target `v`,
/// `T::is_unique_missing_variant_of(v, items) == !T::occurs_in(v, items) && T::has_unique_missing_variant(items)`
/// — the canonical form the body uses. Pinned by
/// `is_unique_missing_variant_of_equals_not_occurs_in_and_has_unique_missing_variant_across_every_target_and_triple`.
///
/// At-most-one-target identity: for every slice `items`,
/// `T::ALL.iter().filter(|&&v| T::is_unique_missing_variant_of(v, items)).count() == usize::from(T::has_unique_missing_variant(items))`
/// — the per-target predicate's set-level filter-count equals the
/// set-level miss-band uniqueness bit cast to `usize`; at most
/// ONE target satisfies the per-target predicate, and it does
/// exactly when [`Self::has_unique_missing_variant`] holds.
/// Pinned by
/// `is_unique_missing_variant_of_count_equals_has_unique_missing_variant_as_usize_across_every_triple`.
///
/// Unique-missing-variant option-equality identity: for every
/// slice `items` and every target `v`,
/// `T::is_unique_missing_variant_of(v, items) == (T::unique_missing_variant(items) == Some(v))`
/// — the per-target `bool` predicate coincides with the equality
/// test between the set-level `Option<Self>` witness projection
/// and `Some(v)`. Independent cross-check on the return-shape
/// axis distinct from the composition-conjunction body. Pinned
/// by
/// `is_unique_missing_variant_of_agrees_with_unique_missing_variant_option_equality_across_every_target_and_triple`.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::occurs_in`] (ordering-agnostic — factored through
/// [`Self::count_occurrences_of`]) and
/// [`Self::has_unique_missing_variant`] (ordering-agnostic — the
/// underlying [`Self::count_missing`] is invariant under slice-
/// reversal) via a boolean conjunction. No separate
/// `sorted_is_unique_missing_variant_of` peer is needed until the
/// sibling LEX corner is opened. Pinned by
/// `is_unique_missing_variant_of_is_invariant_under_slice_reversal_across_every_target_and_triple`.
///
/// Empty-slice contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_missing_variant_of(v, &[])` is `false` for every
/// target `v` — [`Self::has_unique_missing_variant`] falsifies on
/// the empty slice at cardinality `>= 2` via
/// `count_missing(&[]) == T::CARDINALITY >= 2 != 1`, and the
/// conjunction collapses through the uniqueness arm regardless
/// of the negated-membership arm. The SOLE positive arm on the
/// empty-slice fixpoint sits at `T::CARDINALITY == 1` where
/// `!occurs_in(T::ALL[0], &[])` is `true`,
/// `has_unique_missing_variant(&[])` is `true`, and the
/// conjunction lands on `true` at the sole variant.
///
/// Matching-singleton contract:
/// `T::is_unique_missing_variant_of(v, &[v])` is `false` for
/// every target `v` — the target occurs at count `1`,
/// `!occurs_in(v, &[v])` is `false`, and the conjunction lands on
/// `false` at the negated-membership arm regardless of the
/// uniqueness arm.
///
/// Full-set contract:
/// `T::is_unique_missing_variant_of(v, T::ALL)` is `false` for
/// every target `v` — clause (3)'s pairwise-distinctness
/// invariant forces every variant to occur at exactly one
/// position, `!occurs_in(v, T::ALL)` is `false` at every target,
/// and the conjunction lands on `false` through the negated-
/// membership arm.
///
/// Doubled-full-set contract:
/// `T::is_unique_missing_variant_of(v, T::ALL ++ T::ALL)` is
/// `false` for every target `v` — the doubled full set hits every
/// variant at exactly two positions, `!occurs_in(v, doubled)` is
/// `false` at every target, and the conjunction lands on `false`
/// through the negated-membership arm.
///
/// Single-missing contract at [`Self::CARDINALITY`] `>= 2`
/// (LOAD-BEARING POSITIVE ARM): on `T::ALL[..T::CARDINALITY - 1]`
/// the last-declaration-slot variant
/// `T::ALL[T::CARDINALITY - 1]` is the SOLE absent variant, every
/// other variant hits at least one position,
/// [`Self::count_missing`] reports `1`,
/// [`Self::has_unique_missing_variant`] returns `true`,
/// `!occurs_in(T::ALL[T::CARDINALITY - 1], slice)` is `true` at
/// the SOLE missing target and `false` at every present target,
/// and the conjunction lands on `true` at
/// `T::ALL[T::CARDINALITY - 1]` and `false` at every other target.
/// LOAD-BEARING ASYMMETRY against
/// [`Self::is_unique_repeating_variant_of`] which stays
/// UNIVERSALLY `false` on the same fixture (every present variant
/// sits at count `1` — none at count `>= 2` — so
/// [`Self::has_unique_repeating_variant`] falsifies at
/// `count_repeating_variants == 0 != 1` and the conjunction
/// collapses through the uniqueness arm at every target),
/// witnessing the two per-target mult-band predicates as
/// ORTHOGONAL uniqueness signals: this arm's positive fixture is
/// the strict-repeat arm's SILENT fixture, and vice-versa on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` where the strict-repeat
/// arm fires at `T::ALL[0]` while THIS miss-arm stays `false` at
/// every target (no variant is missing when
/// `T::CARDINALITY == 2`; when `T::CARDINALITY >= 3`,
/// `T::CARDINALITY - 2` variants are simultaneously missing so
/// the miss-band uniqueness bit falsifies).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::occurs_in`] + [`Self::has_unique_missing_variant`] via
/// a boolean conjunction on `bool` with the membership arm
/// negated. The sweep cost inherits both primitives: `O(n)` on
/// slice arity `n` for the [`Self::count_occurrences_of`] fold at
/// the target + `O(n(n-1)/2)` for the pairwise-distinctness scan
/// behind [`Self::count_missing`]; the short-circuiting `&&`
/// avoids the second aggregate when the first arm falsifies
/// (i.e., when `target` occurs in `items`), allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::is_unique_missing_variant_of`]: a `tatara-check`
/// predicate `(check-target-is-the-sole-hole …)` that reports
/// "the sole absent variant is unambiguous AND matches the
/// expected witness" in ONE typed bool rather than a two-step
/// `has_unique_missing_variant?` + witness-equality composition;
/// an LSP diagnostic on a Lisp-authored closed-set field that
/// flags a targeted "you forgot exactly this variant" hint only
/// when the omission is unambiguous AND matches the expected
/// witness (e.g., a severity policy that covers
/// `[:info :warn]` and REQUIRES `[:error]` — the quick-fix lights
/// up only when `error` is the SOLE unambiguously-missing arm);
/// a Sekiban audit-trail per-target unique-miss bit binding the
/// same scalar, composable with the per-target unique-strict-
/// repeat bit into a typed 2-bit hole-vs-strict-repeat classifier
/// per window; a `WorkloadPhase` rollout monitor that binds
/// "phase X is the SOLE never-fired phase in this window" as its
/// singular-gap witness only when the answer is unambiguous.
/// Each binds to ONE typed per-target bool predicate on the trait
/// rather than re-deriving
/// `!T::occurs_in(v, items) && T::has_unique_missing_variant(items)`
/// inline per callsite OR paying the option-equality composition
/// `T::unique_missing_variant(items) == Some(v)` would demand
/// (materially equivalent, but the boolean-conjunction form is
/// the canonical trait body and avoids re-invoking the first-
/// witness `T::ALL` sweep behind
/// [`Self::unique_missing_variant`]).
///
/// Compounding closure: this projection OPENS the (per-target ×
/// bool × equivalence-partition × mult `== 0` × unique-tie)
/// corner on the EQUIVALENCE-PARTITION surface at its miss-band
/// arm past the just-opened
/// [`Self::is_unique_repeating_variant_of`] (mult `>= 2`) strict-
/// repeat arm one MULTIPLICITY-BAND axis over — the two together
/// bracket the per-target unique-tie sharpening at BOTH EXTREMAL
/// bands of the mult-band trichotomy. Peer to
/// [`Self::has_unique_missing_variant`] one ARITY axis over AND
/// peer to [`Self::unique_missing_variant`] one RETURN-SHAPE axis
/// over — the (bool set-level, `Option<Self>` set-level, bool
/// per-target) 3-corner mini-face on the miss-band arm of the
/// equivalence-partition surface now closes at THIS third corner,
/// mirroring the same 3-corner closure at the strict-repeat arm
/// ([`Self::has_unique_repeating_variant`],
/// [`Self::unique_repeating_variant`],
/// [`Self::is_unique_repeating_variant_of`]) one MULTIPLICITY-
/// BAND axis over. The natural next lift on this surface is the
/// MIDDLE band's per-target arm —
/// `is_unique_unique_variant_of(target, items) == is_unique_occurrence_of(target, items) && has_unique_unique_variant(items)`
/// (mult `== 1` per-target closer) — EXHAUSTIVELY CLOSING the
/// (per-target × bool × equivalence-partition × mult-band ×
/// unique-tie) 3-corner row on the trichotomy at its FINAL
/// middle-band tile.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (per-target × bool × equivalence-partition × mult `== 0` ×
/// unique-tie) corner becomes a TYPED WITNESS on the ClosedSet
/// trait rather than a per-consumer inline
/// `!T::occurs_in(v, items) && T::has_unique_missing_variant(items)`
/// re-derivation. THEORY.md §III — the typescape; the N-ary per-
/// target unique-miss predicate becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × equivalence-
/// partition × mult `== 0` × unique-tie) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "is this target the sole absent witness?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::occurs_in`] negated + [`Self::has_unique_missing_variant`])
/// with the `&&` combinator on `bool`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `let t = table(items); (t[v] == 0)
/// && (sum(t == 0) == 1)` per-level unique-miss test on a factor
/// histogram; Julia's `let c = StatsBase.countmap(items);
/// (get(c, v, 0) == 0) && (count(w -> get(c, w, 0) == 0,
/// LEVELS) == 1) end` on a `Dict{Element, Int}` histogram;
/// Python's `let c = collections.Counter(items); c[v] == 0 and
/// sum(1 for w in ALL if c[w] == 0) == 1` on a Counter;
/// Haskell's `let hs = Set.fromList items in not (Set.member v
/// hs) && length (filter (\w -> not (Set.member w hs)) all)
/// == 1`; Clojure's `(let [present (set coll)] (and (not
/// (present v)) (= 1 (count (remove present LEVELS)))))`; SQL's
/// `NOT EXISTS (SELECT 1 FROM t WHERE variant = ?) AND
/// (SELECT COUNT(*) FROM levels WHERE variant NOT IN (SELECT
/// DISTINCT variant FROM t)) = 1`. Translation through pleme-io
/// primitives: the projection binds through the substrate's
/// [`Self::occurs_in`] per-target membership predicate NEGATED
/// and conjoined with the just-lifted
/// [`Self::has_unique_missing_variant`] set-level miss-band
/// uniqueness bit — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying miss-
/// count aggregate with short-circuiting on the negated-
/// membership arm.
fn is_unique_missing_variant_of(target: Self, items: &[Self]) -> bool {
!<Self as ClosedSet>::occurs_in(target, items)
&& <Self as ClosedSet>::has_unique_missing_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC PER-TARGET "is `target` the SOLE
/// singleton-multiplicity variant?" predicate — `true` iff `target`
/// occurs EXACTLY ONCE in `items` AND exactly ONE variant of
/// [`Self::ALL`] sits on that singleton-multiplicity band, computed
/// as the substrate's per-target singleton-multiplicity
/// [`Self::is_unique_occurrence_of`] projection conjoined with the
/// just-lifted set-level unique-band uniqueness bit
/// [`Self::has_unique_unique_variant`] via `&&`. The (per-target ×
/// bool × equivalence-partition × multiplicity-band `== 1` ×
/// unique-tie sharpening) corner EXHAUSTIVELY CLOSING the middle-
/// band arm of the (per-target × bool × equivalence-partition ×
/// mult-band × unique-tie) 3-corner row on the EQUIVALENCE-
/// PARTITION surface at its FINAL third tile past the (mult `>= 2`)
/// [`Self::is_unique_repeating_variant_of`] strict-repeat arm AND
/// the (mult `== 0`) [`Self::is_unique_missing_variant_of`] miss-
/// band arm one MULTIPLICITY-BAND axis over — the three together
/// EXHAUSTIVELY CLOSE the per-target unique-tie sharpening across
/// the mult-band trichotomy, mirroring the same exhaustive closure
/// at the set-level `bool` (
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::has_unique_missing_variant`] +
/// [`Self::has_unique_unique_variant`]) row and set-level
/// `Option<Self>` ([`Self::unique_repeating_variant`] +
/// [`Self::unique_missing_variant`] +
/// [`Self::unique_unique_variant`]) row. Peer to
/// [`Self::has_unique_unique_variant`] one ARITY axis over AND peer
/// to [`Self::unique_unique_variant`] one RETURN-SHAPE axis over —
/// the (`bool` set-level, `Option<Self>` set-level, `bool` per-
/// target) 3-corner mini-face on the middle-band arm of the
/// equivalence-partition surface now closes at THIS third corner,
/// mirroring the same 3-corner closure at the strict-repeat arm
/// ([`Self::has_unique_repeating_variant`],
/// [`Self::unique_repeating_variant`],
/// [`Self::is_unique_repeating_variant_of`]) AND at the miss-band
/// arm ([`Self::has_unique_missing_variant`],
/// [`Self::unique_missing_variant`],
/// [`Self::is_unique_missing_variant_of`]) one MULTIPLICITY-BAND
/// axis over. Not a fresh substrate primitive on the index axis —
/// the predicate emerges from the boolean conjunction of the
/// substrate's per-target singleton-multiplicity primitive with the
/// just-lifted set-level unique-band uniqueness bit.
///
/// Composition-conjunction identity: for every slice `items` and
/// every target `v`,
/// `T::is_unique_unique_variant_of(v, items) == T::is_unique_occurrence_of(v, items) && T::has_unique_unique_variant(items)`
/// — the canonical form the body uses.
///
/// At-most-one-target identity: for every slice `items`,
/// `T::ALL.iter().filter(|&&v| T::is_unique_unique_variant_of(v, items)).count() == usize::from(T::has_unique_unique_variant(items))`
/// — the per-target predicate's set-level filter-count equals the
/// set-level unique-band uniqueness bit cast to `usize`; at most ONE
/// target satisfies the per-target predicate, and it does exactly
/// when [`Self::has_unique_unique_variant`] holds.
///
/// Unique-unique-variant option-equality identity: for every slice
/// `items` and every target `v`,
/// `T::is_unique_unique_variant_of(v, items) == (T::unique_unique_variant(items) == Some(v))`
/// — the per-target `bool` predicate coincides with the equality
/// test between the set-level `Option<Self>` witness projection and
/// `Some(v)`. Independent cross-check on the return-shape axis
/// distinct from the composition-conjunction body.
///
/// Ordering-axis invariance: the projection factors through
/// [`Self::is_unique_occurrence_of`] (ordering-agnostic — factored
/// through [`Self::count_occurrences_of`]) and
/// [`Self::has_unique_unique_variant`] (ordering-agnostic — the
/// underlying [`Self::count_unique_variants`] is invariant under
/// slice-reversal) via a boolean conjunction. No separate
/// `sorted_is_unique_unique_variant_of` peer is needed until the
/// sibling LEX corner is opened.
///
/// Empty-slice contract:
/// `T::is_unique_unique_variant_of(v, &[])` is `false` for every
/// target `v` — [`Self::is_unique_occurrence_of`] reports `false`
/// at every target on the empty slice (count `0 != 1`), and
/// `false && _` short-circuits to `false`.
///
/// Matching-singleton contract at [`Self::CARDINALITY`] `>= 2`
/// (LOAD-BEARING `true`-arm catch on a compact fixture):
/// `T::is_unique_unique_variant_of(v, &[v])` is `true` for every
/// target `v` — the singleton hits `v` at count `1` (the SOLE
/// singleton-multiplicity witness), every other variant at count
/// `0`; [`Self::is_unique_occurrence_of`] reports `true` at `v`,
/// [`Self::count_unique_variants(&[v])`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, and the
/// conjunction lands on `true`. Non-matching arm at the same
/// singleton: `T::is_unique_unique_variant_of(w, &[v])` is `false`
/// for every non-matching `w != v` at cardinality `>= 2` — `w`
/// sits at count `0`, [`Self::is_unique_occurrence_of`] falsifies
/// at `w`, and the conjunction lands on `false` through the
/// membership arm. The compact matching-singleton POSITIVE fixture
/// LOAD-BEARING DISCRIMINATES from
/// [`Self::is_unique_repeating_variant_of`] +
/// [`Self::is_unique_missing_variant_of`] which BOTH stay
/// UNIVERSALLY `false` on the same matching-singleton fixture (the
/// strict-repeat arm falsifies at count `1 < 2`; the miss-band arm
/// falsifies via the negated-membership arm at the matching target
/// AND via the uniqueness arm on non-matching targets at cardinality
/// `>= 3` where `T::CARDINALITY - 1 >= 2` variants are simultaneously
/// missing).
///
/// Full-set contract at [`Self::CARDINALITY`] `>= 2`:
/// `T::is_unique_unique_variant_of(v, T::ALL)` is `false` for every
/// target `v` — clause (3)'s pairwise-distinctness invariant pins
/// every variant at count exactly `1` (every variant is a
/// singleton-multiplicity witness, so
/// [`Self::count_unique_variants`] on `T::ALL` reports
/// [`Self::CARDINALITY`] `>= 2`),
/// [`Self::has_unique_unique_variant`] returns `false` via the
/// uniqueness arm, and the conjunction lands on `false` at every
/// target.
///
/// Doubled-full-set contract at [`Self::CARDINALITY`] `>= 1`:
/// `T::is_unique_unique_variant_of(v, T::ALL ++ T::ALL)` is `false`
/// for every target `v` — the doubled full set hits every variant
/// at exactly two positions, no variant sits at the singleton-
/// multiplicity band, [`Self::is_unique_occurrence_of`] falsifies
/// at every target, and the conjunction lands on `false` through
/// the membership arm.
///
/// Bimodal-triple contract at [`Self::CARDINALITY`] `>= 3`
/// (LOAD-BEARING POSITIVE ARM): on the canonical fixture
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2 >= 2`, `T::ALL[1]` at count `1` (the SOLE singleton-
/// multiplicity witness), `T::ALL[2..]` at count `0`;
/// [`Self::is_unique_occurrence_of`] reports `true` only at
/// `T::ALL[1]`, [`Self::has_unique_unique_variant`] reports `true`
/// via `count_unique_variants == 1`, and the conjunction lands on
/// `true` at `T::ALL[1]` and `false` at every other target. LOAD-
/// BEARING DISJOINT-WITNESS mirror of
/// [`Self::is_unique_repeating_variant_of`] on the SAME slice: the
/// strict-repeat arm's positive corner sits at `T::ALL[0]`; THIS
/// unique-band arm's positive corner sits at `T::ALL[1]` — the two
/// per-target POSITIVE `true` corners of the equivalence-partition
/// (mult `>= 2`, mult `== 1`) uniqueness columns report `true` at
/// DIFFERENT targets on the same slice, mirroring the sibling
/// asymmetry between [`Self::unique_repeating_variant`] +
/// [`Self::unique_unique_variant`] one RETURN-SHAPE axis over AND
/// between [`Self::is_unique_middle_band_variant_of`] on the modal-
/// aggregation surface one SURFACE axis over (which pins its
/// bimodal-triple positive arm at `T::ALL[1]` for the direction-
/// composition complement, coinciding with THIS witness by fixture
/// arithmetic yet TYPED as ORTHOGONAL uniqueness signals on
/// disjoint surfaces). LOAD-BEARING ASYMMETRY against
/// [`Self::is_unique_missing_variant_of`] which stays UNIVERSALLY
/// `false` on the same bimodal-triple fixture at cardinality `>= 3`
/// (multiple variants are simultaneously missing so the miss-band
/// uniqueness bit falsifies).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::is_unique_occurrence_of`] +
/// [`Self::has_unique_unique_variant`] via a boolean conjunction on
/// `bool`. The sweep cost inherits both primitives:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_occurrences_of`] fold at the target + one
/// [`Self::count_unique_variants`] filter-count over
/// [`Self::ALL`]; the short-circuiting `&&` avoids the second
/// aggregate when the first arm falsifies), allocation-free, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::is_unique_unique_variant_of`]: a `tatara-check` predicate
/// `(check-target-is-the-sole-singleton …)` that reports "the sole
/// singleton-multiplicity variant is unambiguous AND matches the
/// expected witness" in ONE typed bool rather than a two-step
/// `has_unique_unique_variant?` + witness-equality composition; an
/// LSP diagnostic on a Lisp-authored histogram that flags the SOLE
/// singleton-occurrence enum-arm (`"used exactly once: [warn]"`) as a
/// targeted single-arm cue only when the singleton is unambiguous;
/// a Sekiban audit-trail per-target unique-singleton bit binding
/// the same scalar, composable with the per-target unique-repeat
/// bit into a typed 2-bit singleton-vs-repeat classifier per
/// window; a scheduler-fairness heuristic that branches on "is
/// worker X the SOLE worker that ran EXACTLY ONE task this
/// window?" as the singleton-outlier per-worker detector; an LSP
/// once-only-detection quick-fix that offers to promote a spec's
/// sole once-used identifier to a reusable binding only when the
/// singleton usage is unambiguous AND the target is the sole
/// once-used identifier. Each binds to ONE typed per-target bool
/// predicate on the trait rather than re-deriving
/// `T::is_unique_occurrence_of(v, items) && T::has_unique_unique_variant(items)`
/// inline per callsite OR paying the option-equality composition
/// `T::unique_unique_variant(items) == Some(v)` would demand
/// (materially equivalent, but the boolean-conjunction form is
/// the canonical trait body and avoids re-invoking the first-
/// witness `T::ALL` sweep behind
/// [`Self::unique_unique_variant`]).
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// middle-band arm of the (per-target × bool × equivalence-
/// partition × mult-band × unique-tie) 3-corner row on the
/// equivalence-partition surface at its FINAL third tile past the
/// (mult `>= 2`) [`Self::is_unique_repeating_variant_of`] strict-
/// repeat arm AND the (mult `== 0`)
/// [`Self::is_unique_missing_variant_of`] miss-band arm one
/// MULTIPLICITY-BAND axis over — the row is now the CANONICAL
/// per-target unique-tie sharpening on the equivalence-partition
/// surface, closed at every tile of the mult-band trichotomy. The
/// (`bool` set-level, `Option<Self>` set-level, `bool` per-target)
/// × (mult `>= 2`, mult `== 1`, mult `== 0`) 3×3 = 9-corner
/// equivalence-partition unique-tie face NOW EXHAUSTIVELY CLOSES
/// at nine typed primitives:
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::has_unique_unique_variant`] +
/// [`Self::has_unique_missing_variant`] on the bool set-level row;
/// [`Self::unique_repeating_variant`] +
/// [`Self::unique_unique_variant`] +
/// [`Self::unique_missing_variant`] on the Option set-level row;
/// [`Self::is_unique_repeating_variant_of`] + THIS +
/// [`Self::is_unique_missing_variant_of`] on the bool per-target
/// row. The natural NEXT surface past this exhaustive closure is
/// the (set-level × `Vec<Self>` × equivalence-partition × mult-band
/// × unique-tie) row's per-band witness-if-unique projections OR
/// the lex-ordering peer face lifting the same trichotomy through
/// a `sorted_` prefix.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (per-target × bool × equivalence-partition × mult `== 1` ×
/// unique-tie) corner becomes a TYPED WITNESS on the ClosedSet
/// trait rather than a per-consumer inline
/// `T::is_unique_occurrence_of(v, items) && T::has_unique_unique_variant(items)`
/// re-derivation. THEORY.md §III — the typescape; the N-ary per-
/// target unique-singleton predicate becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (per-target × bool × equivalence-
/// partition × mult `== 1` × unique-tie) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "is this target the sole singleton-multiplicity witness?" site
/// pre-lift. Naming it on the trait EXHAUSTIVELY CLOSES the per-
/// target equivalence-partition unique-tie row as a TYPED THEOREM
/// the substrate proves once, mirroring the set-level bool and
/// set-level Option rows' exhaustive closures one ARITY axis over.
/// THEORY.md §VI.1 — generation over composition; the predicate
/// emerges from the composition of TWO substrate primitives
/// ([`Self::is_unique_occurrence_of`] +
/// [`Self::has_unique_unique_variant`]) with the `&&` combinator on
/// `bool`, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: R's `let t = table(items); (t[v] == 1)
/// && (sum(t == 1) == 1)` per-level unique-singleton test on a
/// factor histogram; Julia's `let c = StatsBase.countmap(items);
/// (get(c, v, 0) == 1) && (count(kv -> kv[2] == 1, collect(c))
/// == 1) end` on a `Dict{Element, Int}` histogram; Python's
/// `let c = collections.Counter(items); c[v] == 1 and
/// sum(1 for x in c.values() if x == 1) == 1` on a Counter;
/// Haskell's `let hs = map (\g -> (head g, length g)) . group .
/// sort $ items; ss = filter (\(_, c) -> c == 1) hs in count v
/// items == 1 && length ss == 1` on `Ord`-instance carriers;
/// Clojure's `(let [f (frequencies coll)] (and (= 1 (get f v 0))
/// (= 1 (count (filter #(= (val %) 1) f)))))`; SQL's
/// `EXISTS (SELECT 1 FROM t WHERE variant = ? GROUP BY variant
/// HAVING COUNT(*) = 1) AND (SELECT COUNT(*) FROM (SELECT
/// variant FROM t GROUP BY variant HAVING COUNT(*) = 1)) = 1`.
/// Translation through pleme-io primitives: the projection binds
/// through the substrate's [`Self::is_unique_occurrence_of`]
/// per-target singleton-multiplicity membership predicate conjoined
/// with the just-lifted [`Self::has_unique_unique_variant`] set-
/// level uniqueness bit — no new dep, no supertrait bound
/// (`Sized + Copy + 'static` stays untouched), no allocation,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the singleton-multiplicity membership
/// arm. One pleme-io-specific disjoint-witness split: on the
/// canonical bimodal-triple fixture the equivalence-partition
/// surface's (mult `>= 2`, mult `== 1`) uniqueness columns pin
/// their per-target POSITIVE `true` corners at DIFFERENT slots
/// (`T::ALL[0]` and `T::ALL[1]` respectively), witnessing the two
/// bands as ORTHOGONAL uniqueness projections rather than
/// redundant covers of one underlying property.
fn is_unique_unique_variant_of(target: Self, items: &[Self]) -> bool {
<Self as ClosedSet>::is_unique_occurrence_of(target, items)
&& <Self as ClosedSet>::has_unique_unique_variant(items)
}
/// The N-ARY ORDERING-AGNOSTIC "present variants" projection —
/// the `Vec<Self>` DECLARATION-ORDER hit-set of [`Self::ALL`],
/// keeping every variant that OCCURS at least once in `items`
/// and dropping every variant that does NOT. The VEC-RETURN
/// PRESENT-ARM opener on the equivalence-partition surface,
/// positioned as the concrete WITNESS behind the just-lifted
/// bool-return [`Self::is_covering`] predicate (which reports
/// whether the hit-set reaches full cardinality) and the
/// usize-return [`Self::count_distinct`] projection (which
/// reports the hit-set's cardinality alone). Sibling posture to
/// [`Self::missing_variants`] one column of the (partition-arm)
/// axis over: this projection materializes the PRESENT arm as
/// a `Vec<Self>` witness; [`Self::missing_variants`]
/// materializes the ABSENT arm as a `Vec<Self>` witness. The
/// (present, absent) × (bool, usize, Vec) 2×3 = 6-corner
/// partition-arm × return-shape face on the equivalence-
/// partition surface now opens the Vec-return column at BOTH
/// partition arms.
///
/// Declaration-order contract: the returned `Vec<Self>` walks
/// [`Self::ALL`] in declaration order and keeps every variant
/// whose [`Self::index_of`] matches SOME position of `items` —
/// so the output is ALWAYS a SUBSEQUENCE of [`Self::ALL`] with
/// each variant appearing AT MOST ONCE. The projection is
/// intrinsically DEDUPED against the ambient closed set's
/// well-formedness clause (3) pairwise-distinctness invariant.
/// Pinned by
/// `present_variants_preserves_declaration_order_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::present_variants(items).len() == T::count_distinct(items)`
/// — the Vec-return present-arm projection's length matches the
/// usize-return present-arm count exactly. Pinned by
/// `present_variants_length_equals_count_distinct_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-
/// set membership predicate is a function of that multiset
/// alone. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned
/// by `present_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::present_variants(&[])` is the
/// empty `Vec` on every implementor — the empty slice hits
/// zero variants, so no variant of [`Self::ALL`] passes the
/// membership filter. Sibling posture to
/// `is_covering_returns_false_on_the_empty_slice_across_every_non_degenerate_kind`
/// at the OPPOSITE return-shape column: the bool-return
/// projection reports `false` (present-arm predicate fails);
/// this Vec-return projection reports `[]` (present-arm
/// witness is empty). Pinned by
/// `present_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::present_variants(&[v])` is `vec![v]`
/// for every variant `v` — a singleton hits exactly one
/// variant, so the filter keeps exactly that variant.
///
/// Full-set contract:
/// `T::present_variants(<T as ClosedSet>::ALL) == <T as
/// ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the closed-set
/// well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pins variants as pairwise distinct, so every
/// variant of [`Self::ALL`] hits itself in the input, and the
/// filter keeps every variant in the same declaration order.
/// Pinned by
/// `present_variants_over_the_full_set_equals_all_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::present_variants(&<T as ClosedSet>::ALL.iter().chain(<T as
/// ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>()) == <T
/// as ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the doubled
/// full set hits every variant (twice), and the projection's
/// intrinsic dedup against [`Self::ALL`] folds the doubled
/// multiset into the singleton hit-set. Pinned by
/// `present_variants_over_the_doubled_full_set_equals_all_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// the substrate's [`Self::index_of`] projection — the
/// discriminator between two variants is their position in
/// [`Self::ALL`], which closed-set well-formedness clause (3)
/// pins as a bijection. The composition uses
/// `<Self as ClosedSet>::ALL.iter().copied().filter(…).collect()`
/// with an inner `items.iter().any(…)` membership sweep, so
/// the total sweep is O(T::CARDINALITY * n) on slice arity
/// `n` — allocating exactly the hit-set on the output side,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::present_variants`]: a `tatara-check` predicate
/// `(check-phases-report-hits …)` that emits the concrete
/// list of `WorkloadPhase` variants a rollout window visited
/// (not just their count); an LSP diagnostic on a Lisp-author-
/// written closed-set field that renders the hit-set as an
/// author-facing completion hint (`":severities [:info :warn]
/// — hit: [info, warn]"`); a Sekiban audit-trail projection
/// that carries the concrete hit-set of a classification poset
/// window as its per-window witness (not just the coverage
/// count); a `tatara-lisp::macro_expand::Expander` hygiene
/// pass that reports the exact set of generated identifiers a
/// template hit (turning the pass-level coverage predicate
/// into a fine-grained diagnostic without a second sweep).
/// Each binds to ONE typed N-ary present-witness projection on
/// the trait rather than re-deriving the ALL-filter-by-
/// membership sweep inline per callsite.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// present-witness projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().copied().filter(|v| items.contains(v)).collect()`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (present-Vec) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which variants did we actually hit?" site pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's total-ordering discriminator
/// ([`Self::index_of`]) projected via the standard-library
/// filter-then-collect combinator. THEORY.md §VI.1 —
/// generation over composition; the present-witness projection
/// emerges from the composition of ONE substrate primitive
/// ([`Self::index_of`]) with an `iter().copied().filter(…).collect()`
/// combinator, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `filter (fun v => existsb (Nat.eqb
/// (index v)) items) all` idiom composing a filter with an
/// existential membership predicate on a decidable-equality
/// carrier; Idris's `filter (\v => any (\w => index v == index w)
/// items) all` on a `Vect n a`; Rust's own
/// `T::ALL.iter().copied().filter(|v| items.contains(v)).collect()`
/// idiom binds through a per-position linear scan on `Self:
/// PartialEq`; Julia's `intersect(all, unique(items))` allocating
/// two sides; Haskell's `Data.List.intersect all items`
/// composition; NumPy's `np.intersect1d(all, items)` idiom.
/// Translation through pleme-io primitives: the N-ary present-
/// witness projection on the closed-set trait binds through the
/// substrate's [`Self::index_of`] projection via the standard-
/// library filter combinator — no new dep, no supertrait bound
/// (the [`Self::index_of`] projection replaces the `Eq`/`Hash`
/// bound the standard-library signatures demand), no set-shape
/// carrier.
fn present_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|v| {
items
.iter()
.any(|w| <Self as ClosedSet>::index_of(*v) == <Self as ClosedSet>::index_of(*w))
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "missing variants" projection —
/// the `Vec<Self>` DECLARATION-ORDER miss-set of [`Self::ALL`],
/// keeping every variant that does NOT occur in `items` and
/// dropping every variant that DOES. The VEC-RETURN ABSENT-ARM
/// closer on the (present, absent) partition-arm axis over the
/// Vec-return column of the equivalence-partition surface,
/// positioned as the direct DE MORGAN dual of
/// [`Self::present_variants`] and as the concrete WITNESS
/// behind the just-lifted bool-return [`Self::is_missing_any`]
/// predicate (which reports whether the miss-set is non-empty)
/// and the usize-return [`Self::count_missing`] projection
/// (which reports the miss-set's cardinality alone).
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::present_variants`] and
/// [`Self::missing_variants`] (each walking [`Self::ALL`] in
/// declaration order) forms a PARTITION of [`Self::ALL`] — the
/// two Vecs are DISJOINT and their union preserves both the
/// declaration-order sub-sequence property AND [`Self::ALL`]'s
/// full membership. Pinned by
/// `present_variants_and_missing_variants_are_disjoint_across_every_triple`
/// and
/// `present_variants_interleaved_with_missing_variants_recovers_all_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::missing_variants(items).len() == T::count_missing(items)`
/// — the Vec-return absent-arm projection's length matches the
/// usize-return absent-arm count exactly. Pinned by
/// `missing_variants_length_equals_count_missing_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::missing_variants(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set is empty iff the
/// present-arm predicate holds;
/// * `!T::missing_variants(items).is_empty()` iff
/// `T::is_missing_any(items)` — the miss-set is non-empty
/// iff the absent-arm predicate holds.
///
/// Both identities pin the bool-return endpoints as typed
/// projections of the Vec-return miss-set. Pinned by
/// `missing_variants_is_empty_iff_is_covering_holds_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the miss-
/// set membership predicate is a function of that multiset
/// alone. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned
/// by `missing_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract:
/// `T::missing_variants(&[]) == <T as ClosedSet>::ALL.to_vec()`
/// UNCONDITIONALLY — the empty slice hits zero variants, so
/// EVERY variant of [`Self::ALL`] passes the "not present"
/// filter. Sibling posture to
/// `is_missing_any_returns_true_on_the_empty_slice_across_every_non_degenerate_kind`
/// at the OPPOSITE return-shape column: the bool-return
/// projection reports `true` (absent-arm predicate holds);
/// this Vec-return projection reports the full ambient set
/// (absent-arm witness is maximal). Pinned by
/// `missing_variants_over_the_empty_slice_equals_all_across_every_kind`.
///
/// Full-set contract:
/// `T::missing_variants(<T as ClosedSet>::ALL)` is the empty
/// `Vec` UNCONDITIONALLY — the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clause (3)
/// pins variants as pairwise distinct, so every variant of
/// [`Self::ALL`] hits itself in the input, and no variant
/// passes the "not present" filter. Pinned by
/// `missing_variants_over_the_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Doubled-full-set contract: `T::missing_variants` returns the
/// empty `Vec` on the doubled full set UNCONDITIONALLY —
/// appending positions to a covering slice cannot ADD a
/// missing variant. Pinned by
/// `missing_variants_over_the_doubled_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// the substrate's [`Self::index_of`] projection — the same
/// discriminator [`Self::present_variants`] binds against,
/// negated at the membership predicate. The composition uses
/// `<Self as ClosedSet>::ALL.iter().copied().filter(…).collect()`
/// with an inner `!items.iter().any(…)` NON-membership sweep,
/// so the total sweep is O(T::CARDINALITY * n) on slice arity
/// `n` — allocating exactly the miss-set on the output side,
/// no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays
/// untouched), no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::missing_variants`]: a `tatara-check` predicate
/// `(check-phases-report-gaps …)` that emits the concrete
/// list of `WorkloadPhase` variants a rollout window OMITTED
/// (not just whether it missed any); an LSP diagnostic on a
/// Lisp-author-written closed-set field that renders the miss-
/// set as an author-facing completion hint (`":severities
/// [:info :warn] — missing: [error]"`); a Sekiban audit-trail
/// projection that carries the concrete gap-set of a
/// classification poset window as its per-window witness (not
/// just the count of gaps); a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the exact set of vocabulary
/// identifiers a template FAILED to bind. Each binds to ONE
/// typed N-ary miss-witness projection on the trait rather
/// than re-deriving the ALL-filter-by-NON-membership sweep
/// inline per callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize,
/// Vec) 2×3 = 6-corner partition-arm × return-shape face on
/// the equivalence-partition surface now closes EXHAUSTIVELY
/// at six typed primitives — [`Self::is_covering`] +
/// [`Self::count_distinct`] + [`Self::present_variants`] on
/// the present arm, [`Self::is_missing_any`] +
/// [`Self::count_missing`] + THIS projection on the absent
/// arm. Post-lift the 6-corner face binds to six typed
/// substrate primitives with no unnamed inline residual on
/// any corner. The next natural lift on this surface — the
/// (declaration, lex) ordering axis: `sorted_present_variants` +
/// `sorted_missing_variants` peers walking [`Self::sorted_variants`]
/// instead of [`Self::ALL`], opening the lex-order arm of the
/// Vec-return column past the declaration-order arm THIS pair
/// just closed.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// miss-witness projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::ALL.iter().copied().filter(|v| !items.contains(v)).collect()`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (absent-Vec) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which variants did we MISS?" site pre-lift.
/// Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's total-ordering discriminator
/// ([`Self::index_of`]) projected via the standard-library
/// filter combinator with a NEGATED membership predicate.
/// THEORY.md §VI.1 — generation over composition; the miss-
/// witness projection emerges from the composition of ONE
/// substrate primitive ([`Self::index_of`]) with an
/// `iter().copied().filter(!…).collect()` combinator, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `filter (fun v => negb (existsb
/// (Nat.eqb (index v)) items)) all` idiom composing a filter
/// with a NEGATED existential membership predicate; Idris's
/// `filter (\v => not (any (\w => index v == index w) items))
/// all` on a `Vect n a`; Rust's own
/// `T::ALL.iter().copied().filter(|v| !items.contains(v)).collect()`
/// idiom; Julia's `setdiff(all, unique(items))`; Haskell's
/// `Data.List.\\ all items` composition; NumPy's
/// `np.setdiff1d(all, items)` idiom. Translation through pleme-
/// io primitives: the N-ary miss-witness projection on the
/// closed-set trait binds through the substrate's
/// [`Self::index_of`] projection via the standard-library
/// filter combinator with a NEGATED membership predicate — no
/// new dep, no supertrait bound, no set-shape carrier.
fn missing_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|v| {
!items
.iter()
.any(|w| <Self as ClosedSet>::index_of(*v) == <Self as ClosedSet>::index_of(*w))
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "repeating variants" projection
/// — the `Vec<Self>` DECLARATION-ORDER strict-repeat set of
/// [`Self::ALL`], keeping every variant whose per-target
/// multiplicity in `items` is `>= 2` and dropping every variant
/// whose multiplicity is `<= 1`. The VEC-RETURN STRICT-REPEAT
/// corner OPENING the (`Vec<Self>`, set-level, multiplicity-
/// band `>= 2`) column past the (`bool`, set-level,
/// multiplicity-band `>= 2`) [`Self::is_repeating_any`]
/// existential corner AND the (`usize`, set-level, multiplicity-
/// band `>= 2`) [`Self::count_repeating_variants`] cardinality
/// corner on the equivalence-partition surface, positioned as
/// the concrete WITNESS behind those two peer projections
/// (which report whether the strict-repeat set is non-empty and
/// its cardinality alone, respectively).
///
/// Cardinality identity: for every slice `items`,
/// `T::repeating_variants(items).len() ==
/// T::count_repeating_variants(items)` — the Vec-return strict-
/// repeat projection's length matches the usize-return strict-
/// repeat count exactly. Pinned by
/// `repeating_variants_length_equals_count_repeating_variants_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::repeating_variants(items).is_empty()` iff
/// `!T::is_repeating_any(items)` — the strict-repeat set is
/// empty iff the strict-repeat existential fails;
/// * `!T::repeating_variants(items).is_empty()` iff
/// `T::is_repeating_any(items)` — the strict-repeat set is
/// non-empty iff the strict-repeat existential holds.
///
/// Both identities pin the bool-return existential endpoint as
/// a typed projection of the Vec-return strict-repeat set.
/// Pinned by
/// `repeating_variants_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Sub-set relation: `T::repeating_variants(items)` is a SUBSET
/// of `T::present_variants(items)` — every strict-repeat
/// variant occurs at least once, so the (multiplicity `>= 2`)
/// band is contained in the (multiplicity `>= 1`) presence
/// band. Symmetrically, `T::repeating_variants(items)` is
/// DISJOINT from `T::missing_variants(items)` (the multiplicity
/// `== 0` band cannot overlap the multiplicity `>= 2` band).
/// Pinned by
/// `repeating_variants_is_a_subset_of_present_variants_across_every_triple`
/// and
/// `repeating_variants_is_disjoint_from_missing_variants_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the
/// strict-repeat predicate is a function of that multiset
/// alone. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned
/// by `repeating_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Declaration-order subsequence contract: the returned
/// `Vec<Self>` is ALWAYS a subsequence of [`Self::ALL`] — every
/// variant appears at most once (dedup by the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pairwise-distinctness), in [`Self::ALL`]'s
/// declaration order. Pinned by
/// `repeating_variants_preserves_declaration_order_across_every_triple`.
///
/// Empty-slice contract: `T::repeating_variants(&[])` is the
/// empty `Vec` UNCONDITIONALLY — the empty slice hits zero
/// positions, so every per-variant multiplicity is `0` and the
/// per-target `>= 2` test fails at every target. Sibling
/// posture to
/// `is_repeating_any_returns_false_on_the_empty_slice_across_every_kind`
/// at the OPPOSITE return-shape column: the bool-return
/// projection reports `false` (strict-repeat existential
/// fails); this Vec-return projection reports `[]` (strict-
/// repeat witness is empty). Pinned by
/// `repeating_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::repeating_variants(<T as ClosedSet>::ALL)` is the empty
/// `Vec` UNCONDITIONALLY — the closed-set well-formedness
/// invariant's clause (3) pairwise-distinctness pins every
/// variant of [`Self::ALL`] as occurring at EXACTLY ONE
/// position of the full-set slice, so every per-target
/// multiplicity is `1` and the per-target `>= 2` test fails at
/// every target. Pinned by
/// `repeating_variants_over_the_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::repeating_variants(&<T as ClosedSet>::ALL.iter().chain(<T
/// as ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>()) ==
/// <T as ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the
/// doubled full set hits every variant at EXACTLY TWO
/// positions, so every per-target multiplicity is `2` and the
/// per-target `>= 2` test succeeds at every target; the
/// projection dedups against [`Self::ALL`] and returns each
/// variant exactly once in declaration order. The doubled-full-
/// set arm is LOAD-BEARING — it is the ONLY canonical fixpoint
/// arm that separates the (multiplicity `>= 2`) band from the
/// (multiplicity `== 0`) absence band (empty, full-set both
/// coincide on `[]`). Pinned by
/// `repeating_variants_over_the_doubled_full_set_equals_all_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// the substrate's per-target [`Self::is_repeated_occurrence_of`]
/// primitive filtered through [`Self::ALL`]. The composition
/// uses `<Self as ClosedSet>::ALL.iter().copied().filter(…)
/// .collect()` with the substrate's strict-repeat per-target
/// predicate as the filter — allocation-free on the
/// `Sized + Copy + 'static` supertrait pair (no
/// `PartialEq`/`Eq`/`Hash` bound; the substrate's
/// [`Self::index_of`] projection replaces the standard-library
/// group-by signatures' `Eq`/`Hash` demand), `O(T::CARDINALITY
/// × n)` worst-case on slice arity `n` for the per-target
/// occurrence sweep, no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::repeating_variants`]: a `tatara-check` predicate
/// `(check-phases-report-repeated-variants …)` that emits the
/// concrete list of `WorkloadPhase` variants a rollout window
/// saw MORE THAN ONCE (a duplication witness rather than the
/// sibling `is_repeating_any` existential or the sibling
/// `count_repeating_variants` cardinality); an LSP diagnostic
/// on a Lisp-author-written `:severities [:info :warn :info]`
/// closed-set field that renders the strict-repeat set as an
/// author-facing "used more than once: [info]" completion
/// hint; a Sekiban audit-trail projection that carries the
/// concrete duplication set of a classification poset window
/// as its per-window witness (not just the existential or the
/// count); a `tatara-lisp::macro_expand::Expander` hygiene
/// pass that reports the exact set of non-linearly-bound
/// identifiers a template hit (turning the pass-level `bool`
/// or `usize` diagnostic into a fine-grained witness without a
/// second sweep). Each binds to ONE typed N-ary strict-repeat-
/// witness projection on the trait rather than re-deriving
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) >= 2).collect()` inline
/// per callsite.
///
/// Compounding closure: the (bool, usize, `Vec<Self>`) ×
/// (mult `== 0`, mult `>= 1`, mult `== 1`, mult `>= 2`) 3×4 =
/// 12-corner (return-shape × multiplicity-band) grid on the
/// equivalence-partition surface now closes at TEN typed
/// primitives — [`Self::is_missing_any`] +
/// [`Self::count_missing`] + [`Self::missing_variants`] at the
/// (mult `== 0`) band, [`Self::is_covering`] +
/// [`Self::count_distinct`] + [`Self::present_variants`] at the
/// (mult `>= 1`) band, [`Self::is_unique_any`] +
/// [`Self::count_unique_variants`] at the (mult `== 1`) band
/// (the Vec-return witness on this band is the natural next
/// lift one MULTIPLICITY-BAND axis under from this projection),
/// [`Self::is_repeating_any`] +
/// [`Self::count_repeating_variants`] + THIS at the (mult `>= 2`)
/// band. The (mult `>= 2`) column is now EXHAUSTIVELY closed
/// at three peer projections on the substrate rather than
/// unnamed inline compositions at every downstream generic
/// site.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// strict-repeat witness projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-
/// consumer inline
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) >= 2).collect()`
/// composition at every downstream generic site. THEORY.md
/// §V.1 — knowable platform; the (Vec-return, mult `>= 2`)
/// corner was an unnamed inline composition recurring at
/// every prospective downstream "which variants occurred TWO
/// OR MORE TIMES?" site pre-lift. Naming it on the trait
/// makes the projection a TYPED CONSEQUENCE of the substrate's
/// per-target strict-repeat primitive
/// ([`Self::is_repeated_occurrence_of`]) filtered through
/// [`Self::ALL`] via the standard-library filter combinator.
/// THEORY.md §VI.1 — generation over composition; the strict-
/// repeat witness projection emerges from the composition of
/// ONE substrate primitive with an
/// `iter().copied().filter(…).collect()` combinator, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `filter (fun v => 2 <=? count_occ
/// eqb l v) all` decidable-equality-derived strict-repeat
/// witness on a `list nat`; SQL's `SELECT variant FROM t GROUP
/// BY variant HAVING COUNT(*) >= 2` group-by-with-having
/// idiom; NumPy's
/// `all[np.array([np.sum(items == v) >= 2 for v in all])]`
/// vectorized strict-repeat mask; Racket's `(filter (lambda
/// (v) (>= (count (curry equal? v) items) 2)) all)` on a
/// `listof T` bundle. Translation through pleme-io primitives:
/// the N-ary strict-repeat witness projection on the closed-
/// set trait binds through the substrate's per-target strict-
/// repeat primitive [`Self::is_repeated_occurrence_of`] filtered
/// through [`Self::ALL`] instead of an `Eq`/`Hash` supertrait
/// bound on a `GROUP BY`-shaped carrier — staying allocation-
/// free on the `Sized + Copy + 'static` supertrait pair.
fn repeating_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::is_repeated_occurrence_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "present variants" projection —
/// the `Vec<Self>` LEX-ORDER hit-set of [`Self::sorted_variants`],
/// keeping every variant that DOES occur in `items` and dropping
/// every variant that doesn't. The LEX-ORDER peer of
/// [`Self::present_variants`] on the (declaration, lex) ordering
/// axis of the Vec-return column of the equivalence-partition
/// surface — opens the lex arm past the declaration arm the prior
/// pair closed.
///
/// Composition law: for every slice `items`,
/// `T::sorted_present_variants(items) ==
/// T::sorted_variants().into_iter().filter(|v| items.iter().any(|w|
/// T::index_of(*v) == T::index_of(*w))).collect()` — the projection
/// binds through the substrate's [`Self::sorted_variants`]
/// canonical-listing surface composed with the standard-library
/// filter combinator keyed on [`Self::index_of`] equality. The
/// hit-set MEMBERSHIP predicate matches [`Self::present_variants`]
/// byte-for-byte on every variant; only the ITERATION ORDER
/// differs (lex vs declaration).
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_present_variants(items)` is a PERMUTATION of
/// `T::present_variants(items)` — the two projections filter the
/// SAME hit-set from [`Self::ALL`] / [`Self::sorted_variants`]
/// (both of which contain every variant exactly once by the
/// closed-set well-formedness invariant [`assert_closed_set_well_formed`]'s
/// clauses 3 + 17), so the multiset of variant identities in the
/// two returned Vecs coincides though the ordering differs. Pinned
/// by `sorted_present_variants_is_a_permutation_of_present_variants_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_present_variants(items).len() ==
/// T::count_distinct(items)` — the lex-order Vec-return present-
/// arm projection's length matches the usize-return present-arm
/// count exactly, and matches the declaration-order Vec-return
/// present-arm length. Pinned by
/// `sorted_present_variants_length_equals_count_distinct_across_every_triple`.
///
/// Lex-order subsequence contract: the returned `Vec<Self>` is
/// ALWAYS a subsequence of [`Self::sorted_variants`] — every
/// variant appears at most once (dedup by well-formedness), in
/// [`Self::sorted_variants`]'s lex order. Pinned by
/// `sorted_present_variants_preserves_lex_order_across_every_triple`
/// which verifies the label sequence is strictly ascending in
/// ASCII order via `windows(2).all(|w| w[0] < w[1])`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_present_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_present_variants(&[])` is the
/// empty `Vec` UNCONDITIONALLY — the empty slice hits zero
/// variants, so no variant of [`Self::sorted_variants`] passes the
/// membership filter. Sibling posture to the OPPOSITE
/// declaration-order arm at
/// `present_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`;
/// both projections agree on the empty-slice endpoint because the
/// zero-Vec has no ordering to distinguish. Pinned by
/// `sorted_present_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_present_variants(<T as ClosedSet>::ALL) ==
/// T::sorted_variants()` UNCONDITIONALLY — the well-formedness
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself in the input, so the filter
/// keeps every variant of [`Self::sorted_variants`] in the same
/// lex order. The full-set endpoint reveals the ordering
/// asymmetry: the declaration arm returns [`Self::ALL`]-order;
/// the lex arm returns [`Self::sorted_variants`]-order. Pinned by
/// `sorted_present_variants_over_the_full_set_equals_sorted_variants_across_every_kind`.
///
/// Doubled-full-set contract: `T::sorted_present_variants` on the
/// doubled full set collapses the doubled multiset into the
/// singleton hit-set [`Self::sorted_variants`] UNCONDITIONALLY —
/// the projection walks [`Self::sorted_variants`] and each variant
/// is kept at most once. Pinned by
/// `sorted_present_variants_over_the_doubled_full_set_equals_sorted_variants_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::sorted_variants`] canonical-listing surface
/// composed with the substrate's [`Self::index_of`] projection at
/// the membership predicate. The composition uses
/// `<Self as ClosedSet>::sorted_variants().into_iter().filter(…)
/// .collect()` — the outer `sorted_variants()` allocation is O(N
/// log N) on the closed-set cardinality (from `sort_unstable_by_key`
/// inside [`Self::sorted_variants`]), plus O(N * n) on the slice
/// arity `n` for the filter's inner NON-membership sweep. No
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::sorted_present_variants`]: a `tatara-check` predicate
/// `(check-phases-report-present-in-lex-order …)` that emits the
/// concrete list of `WorkloadPhase` variants that OCCURRED in a
/// rollout window in LEX ORDER (not declaration order, so operator-
/// facing diagnostics and metric-label sweeps agree with the
/// closed-set surface's canonical-listing surface); an LSP
/// completion hint that renders the hit-set in the same lex order
/// the substrate-wide "did you mean …?" suggestion surface uses; a
/// Sekiban audit-trail projection that carries the concrete
/// present-set of a classification poset window in lex order for
/// operator-facing render agreement across every downstream surface.
/// Each binds to ONE typed N-ary lex-order hit-witness projection
/// on the trait rather than re-deriving the sorted-then-filter
/// composition inline per callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize, Vec)
/// × (declaration, lex) 2×3×2 = 12-corner (partition-arm × return-
/// shape × ordering) prism on the equivalence-partition surface
/// now closes at TEN typed primitives — the pre-existing six-corner
/// declaration-order slice
/// ([`Self::is_covering`] + [`Self::count_distinct`] +
/// [`Self::present_variants`] on the present arm,
/// [`Self::is_missing_any`] + [`Self::count_missing`] +
/// [`Self::missing_variants`] on the absent arm) PLUS this pair
/// PLUS the just-lifted [`Self::sorted_missing_variants`] peer on
/// the lex arm. The remaining pair of the 12-corner prism —
/// `sorted_is_covering` + `sorted_is_missing_any` bool-return AND
/// `sorted_count_distinct` + `sorted_count_missing` usize-return —
/// COLLAPSES to the same bytes as the declaration-arm bool +
/// usize projections (the bool "does it cover?" and usize "how
/// many hit/miss?" projections are ordering-agnostic on the OUTPUT
/// axis, unlike the Vec return which carries ordering). Naming
/// them as separate primitives would duplicate the declaration-
/// arm's bytes; the (declaration, lex) axis of the prism is
/// materially distinct ONLY on the Vec-return column, so this
/// pair (+ [`Self::sorted_missing_variants`]) exhausts the
/// (declaration, lex) axis's naming budget on the equivalence-
/// partition surface.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order present-witness projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::sorted_variants().into_iter().filter(|v| items.contains(v))
/// .collect()` composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (present-Vec, lex-order)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variants did we hit, in lex
/// order?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's canonical-
/// listing surface composed with the substrate's total-ordering
/// discriminator via the standard-library filter combinator.
/// THEORY.md §VI.1 — generation over composition; the lex-order
/// present-witness projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_variants`] + [`Self::index_of`])
/// via an `into_iter().filter(…).collect()` combinator, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(sort (filter (lambda (v) (member
/// v items)) (enum->list T)) #:key T-label)` — the canonical-list-
/// then-filter idiom on any decidable-equality carrier, keyed on a
/// label projection; Haskell's `sortOn label . filter (\`elem\`
/// items)` on a `[T]` bundle-then-filter shape; NumPy's
/// `np.intersect1d(all, items)` idiom (which returns lex-sorted by
/// default, matching this projection's output ordering byte-for-
/// byte on ASCII-labeled closed sets). Translation through pleme-
/// io primitives: the N-ary lex-order present-witness projection
/// on the closed-set trait binds through [`Self::sorted_variants`]
/// (the canonical lex-order enumeration) composed with the
/// substrate's [`Self::index_of`] projection (the total-ordering
/// discriminator) via the standard-library filter combinator — no
/// new dep, no supertrait bound, no set-shape carrier.
fn sorted_present_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|v| {
items
.iter()
.any(|w| <Self as ClosedSet>::index_of(*v) == <Self as ClosedSet>::index_of(*w))
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "missing variants" projection —
/// the `Vec<Self>` LEX-ORDER miss-set of [`Self::sorted_variants`],
/// keeping every variant that does NOT occur in `items` and
/// dropping every variant that DOES. The LEX-ORDER peer of
/// [`Self::missing_variants`] on the (declaration, lex) ordering
/// axis of the Vec-return column of the equivalence-partition
/// surface — closes the lex arm past the declaration arm the
/// sibling [`Self::sorted_present_variants`] opened.
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::sorted_present_variants`] and
/// [`Self::sorted_missing_variants`] (each walking
/// [`Self::sorted_variants`] in lex order) forms a PARTITION of
/// [`Self::sorted_variants`] — the two Vecs are DISJOINT and their
/// union preserves both the lex-order sub-sequence property AND
/// [`Self::sorted_variants`]'s full membership. Pinned by
/// `sorted_present_variants_and_sorted_missing_variants_are_disjoint_across_every_triple`
/// and
/// `sorted_present_variants_interleaved_with_sorted_missing_variants_recovers_sorted_variants_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_missing_variants(items)` is a PERMUTATION of
/// `T::missing_variants(items)` — the two projections filter the
/// SAME miss-set from [`Self::ALL`] / [`Self::sorted_variants`]
/// (both containing every variant exactly once), so the multiset
/// of variant identities in the two returned Vecs coincides though
/// the ordering differs. Pinned by
/// `sorted_missing_variants_is_a_permutation_of_missing_variants_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_missing_variants(items).len() ==
/// T::count_missing(items)` — the lex-order Vec-return absent-arm
/// projection's length matches the usize-return absent-arm count
/// exactly, and matches the declaration-order Vec-return absent-
/// arm length. Pinned by
/// `sorted_missing_variants_length_equals_count_missing_across_every_triple`.
///
/// Bool-projection identity: for every slice `items`,
/// `T::sorted_missing_variants(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set is empty iff the
/// present-arm predicate holds. Pinned by
/// `sorted_missing_variants_is_empty_iff_is_covering_holds_across_every_triple`.
/// The bool-projection is INVARIANT under the (declaration, lex)
/// axis — same bool bytes on both arms — because
/// `Self::is_covering` is a function of the miss-set's cardinality
/// alone.
///
/// Lex-order subsequence contract: the returned `Vec<Self>` is
/// ALWAYS a subsequence of [`Self::sorted_variants`] with each
/// variant appearing at most once, in [`Self::sorted_variants`]'s
/// lex order. Pinned by
/// `sorted_missing_variants_preserves_lex_order_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the miss-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order. Pinned by
/// `sorted_missing_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract:
/// `T::sorted_missing_variants(&[]) == T::sorted_variants()`
/// UNCONDITIONALLY — the empty slice hits zero variants, so EVERY
/// variant of [`Self::sorted_variants`] passes the "not present"
/// filter. Pinned by
/// `sorted_missing_variants_over_the_empty_slice_equals_sorted_variants_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_missing_variants(<T as ClosedSet>::ALL)` is the empty
/// `Vec` UNCONDITIONALLY — every variant of [`Self::ALL`] hits
/// itself in the input, so no variant passes the "not present"
/// filter. Pinned by
/// `sorted_missing_variants_over_the_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Signature note: the projection composes the substrate's
/// [`Self::sorted_variants`] canonical-listing surface with the
/// substrate's [`Self::index_of`] projection via the standard-
/// library filter combinator with a NEGATED membership predicate.
/// The composition uses
/// `<Self as ClosedSet>::sorted_variants().into_iter().filter(…)
/// .collect()` with an inner `!items.iter().any(…)` non-membership
/// sweep, so the total sweep is O(N log N) for the sort step plus
/// O(N * n) on slice arity `n` for the filter — no supertrait
/// bound, no bitset carrier.
///
/// Compounding closure: this projection AND
/// [`Self::sorted_present_variants`] close the lex-arm of the (Vec-
/// return × ordering) 2×2 face on the equivalence-partition
/// surface — the pair completes the 6-of-12-corner prism the sibling
/// declaration-arm pair (present_variants + missing_variants) opened
/// on the equivalence-partition surface's (partition-arm × return-
/// shape × ordering) 2×3×2 axes, with the bool + usize columns
/// COLLAPSING across the (declaration, lex) axis (ordering-
/// agnostic scalar returns) while the Vec column BIFURCATES
/// (ordering-carrying vector returns).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order miss-witness projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::sorted_variants().into_iter().filter(|v| !items.contains
/// (v)).collect()` composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (absent-Vec, lex-order)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which variants did we MISS, in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the lex-order miss-witness projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::sorted_variants`] + [`Self::index_of`]) via an
/// `into_iter().filter(!…).collect()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(sort (filter (lambda (v) (not
/// (member v items))) (enum->list T)) #:key T-label)` — the
/// canonical-list-then-negated-filter idiom on any decidable-
/// equality carrier; Haskell's `sortOn label . filter (not . (\`elem\`
/// items))` on a `[T]` bundle-then-negated-filter shape; NumPy's
/// `np.setdiff1d(all, items)` idiom (which returns lex-sorted by
/// default, matching this projection's output ordering byte-for-
/// byte on ASCII-labeled closed sets). Translation through pleme-
/// io primitives: the N-ary lex-order miss-witness projection on
/// the closed-set trait binds through [`Self::sorted_variants`]
/// composed with the substrate's [`Self::index_of`] projection via
/// the standard-library filter combinator with a NEGATED
/// membership predicate — no new dep, no supertrait bound, no
/// set-shape carrier.
fn sorted_missing_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|v| {
!items
.iter()
.any(|w| <Self as ClosedSet>::index_of(*v) == <Self as ClosedSet>::index_of(*w))
})
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "repeating variants" projection
/// — the `Vec<Self>` LEX-ORDER strict-repeat set of
/// [`Self::sorted_variants`], keeping every variant whose per-
/// target multiplicity in `items` is `>= 2` and dropping every
/// variant whose multiplicity is `<= 1`. The LEX-ORDER peer of
/// [`Self::repeating_variants`] on the (declaration, lex)
/// ordering axis of the `Vec<Self>`-return strict-repeat-band
/// column of the equivalence-partition surface — CLOSES the lex
/// arm past the declaration arm the sibling
/// [`Self::repeating_variants`] opened, and CLOSES the (partition-
/// arm × ordering) 3×2 = 6-corner `Vec<Self>`-return face at its
/// SIXTH (strict-repeat, lex) corner peer to
/// [`Self::sorted_present_variants`] (present × lex) and
/// [`Self::sorted_missing_variants`] (absent × lex) one PARTITION-
/// ARM axis over on the same lex column.
///
/// Composition law: for every slice `items`,
/// `T::sorted_repeating_variants(items) ==
/// T::sorted_variants().into_iter().filter(|&v|
/// T::is_repeated_occurrence_of(v, items)).collect()` — the
/// projection binds through the substrate's [`Self::sorted_variants`]
/// canonical lex-order listing surface composed with the
/// substrate's per-target strict-repeat primitive
/// [`Self::is_repeated_occurrence_of`] via the standard-library
/// filter combinator. The strict-repeat MEMBERSHIP predicate
/// matches [`Self::repeating_variants`] byte-for-byte on every
/// variant; only the ITERATION ORDER differs (lex vs declaration).
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_repeating_variants(items)` is a PERMUTATION of
/// `T::repeating_variants(items)` — the two projections filter
/// the SAME strict-repeat set from [`Self::ALL`] /
/// [`Self::sorted_variants`] (both of which contain every variant
/// exactly once by the closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clauses 3 + 17), so the
/// multiset of variant identities in the two returned Vecs
/// coincides though the ordering differs. Pinned by
/// `sorted_repeating_variants_is_a_permutation_of_repeating_variants_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_repeating_variants(items).len() ==
/// T::count_repeating_variants(items)` — the lex-order Vec-return
/// strict-repeat projection's length matches the usize-return
/// strict-repeat count exactly, and matches the declaration-order
/// Vec-return strict-repeat length. Pinned by
/// `sorted_repeating_variants_length_equals_count_repeating_variants_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::sorted_repeating_variants(items).is_empty()` iff
/// `!T::is_repeating_any(items)` — the strict-repeat set is
/// empty iff the strict-repeat existential fails;
/// * `!T::sorted_repeating_variants(items).is_empty()` iff
/// `T::is_repeating_any(items)` — the strict-repeat set is
/// non-empty iff the strict-repeat existential holds.
///
/// Both bool-projections are INVARIANT under the (declaration,
/// lex) axis — the bool return carries no ordering, so the
/// identity holds identically on the declaration arm (pinned by
/// `repeating_variants_is_empty_iff_not_is_repeating_any_across_every_triple`)
/// AND on the lex arm (this pin). Pinned by
/// `sorted_repeating_variants_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Sub-set relation: `T::sorted_repeating_variants(items)` is a
/// SUBSET of `T::sorted_present_variants(items)` — every strict-
/// repeat variant occurs at least once, so the (multiplicity `>=
/// 2`) band is contained in the (multiplicity `>= 1`) presence
/// band. Symmetrically, `T::sorted_repeating_variants(items)` is
/// DISJOINT from `T::sorted_missing_variants(items)` (the
/// multiplicity `== 0` band cannot overlap the multiplicity `>=
/// 2` band). Pinned by
/// `sorted_repeating_variants_is_a_subset_of_sorted_present_variants_across_every_triple`
/// and
/// `sorted_repeating_variants_is_disjoint_from_sorted_missing_variants_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_repeating_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Lex-order subsequence contract: the returned `Vec<Self>` is
/// ALWAYS a subsequence of [`Self::sorted_variants`] — every
/// variant appears at most once (dedup by the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pairwise-distinctness), in [`Self::sorted_variants`]'s
/// lex order. Pinned by
/// `sorted_repeating_variants_preserves_lex_order_across_every_triple`
/// which verifies the label sequence is strictly ascending in
/// ASCII order via `windows(2).all(|w| w[0] < w[1])`.
///
/// Empty-slice contract: `T::sorted_repeating_variants(&[])` is
/// the empty `Vec` UNCONDITIONALLY — the empty slice hits zero
/// positions, so every per-variant multiplicity is `0` and the
/// per-target `>= 2` test fails at every target. Sibling posture
/// to the OPPOSITE declaration-order arm at
/// `repeating_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`;
/// both arms agree on the empty-slice endpoint because the
/// zero-Vec has no ordering to distinguish. Pinned by
/// `sorted_repeating_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract:
/// `T::sorted_repeating_variants(<T as ClosedSet>::ALL)` is the
/// empty `Vec` UNCONDITIONALLY — the closed-set well-formedness
/// invariant's clause (3) pairwise-distinctness pins every
/// variant of [`Self::ALL`] as occurring at EXACTLY ONE position
/// of the full-set slice, so every per-target multiplicity is
/// `1` and the per-target `>= 2` test fails at every target.
/// Pinned by
/// `sorted_repeating_variants_over_the_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_repeating_variants(&<T as ClosedSet>::ALL.iter().chain(
/// <T as ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>()) ==
/// T::sorted_variants()` UNCONDITIONALLY — the doubled full set
/// hits every variant at EXACTLY TWO positions, so every per-
/// target multiplicity is `2` and the per-target `>= 2` test
/// succeeds at every target; the projection dedups against
/// [`Self::sorted_variants`] and returns each variant exactly
/// once in lex order. The doubled-full-set arm is LOAD-BEARING
/// — it is the ONLY canonical fixpoint arm that separates the
/// (multiplicity `>= 2`) band from the (multiplicity `== 0`)
/// absence band (empty, full-set both coincide on `[]`). The
/// full-set endpoint reveals the ordering asymmetry: the
/// declaration arm returns [`Self::ALL`]-order; the lex arm
/// returns [`Self::sorted_variants`]-order. Pinned by
/// `sorted_repeating_variants_over_the_doubled_full_set_equals_sorted_variants_across_every_kind`.
///
/// Signature note: the projection composes the substrate's
/// [`Self::sorted_variants`] canonical-listing surface with the
/// substrate's per-target [`Self::is_repeated_occurrence_of`]
/// primitive via the standard-library filter combinator. The
/// composition uses `<Self as ClosedSet>::sorted_variants()
/// .into_iter().filter(…).collect()` — the outer
/// `sorted_variants()` allocation is O(N log N) on the closed-
/// set cardinality (from `sort_unstable_by_key` inside
/// [`Self::sorted_variants`]), plus O(N * n) on the slice arity
/// `n` for the filter's per-target occurrence sweep. No
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched), no
/// bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::sorted_repeating_variants`]: a `tatara-check`
/// predicate `(check-phases-report-repeated-variants-in-lex-order …)`
/// that emits the concrete list of `WorkloadPhase` variants a
/// rollout window saw MORE THAN ONCE in LEX ORDER (not
/// declaration order, so operator-facing duplication diagnostics
/// and metric-label sweeps agree with the closed-set surface's
/// canonical-listing surface); an LSP diagnostic on a Lisp-
/// author-written `:severities [:info :warn :info]` closed-set
/// field that renders the strict-repeat set as an author-facing
/// "used more than once: [info]" completion hint sorted lex; a
/// Sekiban audit-trail projection that carries the concrete
/// duplication set of a classification poset window in lex order
/// for operator-facing render agreement across every downstream
/// surface; a `tatara-lisp::macro_expand::Expander` hygiene pass
/// that reports the exact set of non-linearly-bound identifiers
/// a template hit in lex order (matching the substrate-wide
/// "did you mean …?" surface's canonical listing). Each binds
/// to ONE typed N-ary lex-order strict-repeat-witness projection
/// on the trait rather than re-deriving the sorted-then-filter
/// composition inline per callsite.
///
/// Compounding closure: the (present, absent, strict-repeat) ×
/// (declaration, lex) 3×2 = 6-corner `Vec<Self>`-return (partition-
/// arm × ordering) face on the equivalence-partition surface now
/// closes at SIX typed primitives — [`Self::present_variants`] +
/// [`Self::sorted_present_variants`] on the present arm,
/// [`Self::missing_variants`] + [`Self::sorted_missing_variants`]
/// on the absent arm, [`Self::repeating_variants`] + THIS on the
/// strict-repeat arm. The (partition-arm × ordering) face is now
/// EXHAUSTIVELY closed on the `Vec<Self>`-return column; the
/// (bool, usize) return-shape columns COLLAPSE across the
/// (declaration, lex) axis (ordering-agnostic scalar returns:
/// [`Self::is_covering`] / [`Self::count_distinct`] on the present
/// arm, [`Self::is_missing_any`] / [`Self::count_missing`] on the
/// absent arm, [`Self::is_repeating_any`] /
/// [`Self::count_repeating_variants`] on the strict-repeat arm),
/// so the (partition-arm × ordering) axis of the prism is
/// materially distinct ONLY on the Vec-return column, which this
/// pair (+ the pre-existing four peer projections) exhausts.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order strict-repeat-witness projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) >= 2).collect()` composition
/// at every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (strict-repeat-Vec, lex-order) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which variants did we hit MORE THAN ONCE, in lex
/// order?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's canonical-
/// listing surface composed with the substrate's per-target
/// strict-repeat primitive via the standard-library filter
/// combinator. THEORY.md §VI.1 — generation over composition;
/// the lex-order strict-repeat-witness projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::sorted_variants`] + [`Self::is_repeated_occurrence_of`])
/// via an `into_iter().filter(…).collect()` combinator, not as a
/// per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(sort (filter (lambda (v) (>=
/// (count (curry equal? v) items) 2)) (enum->list T)) #:key
/// T-label)` — the canonical-list-then-strict-repeat-filter
/// idiom on any decidable-equality carrier, keyed on a label
/// projection; Haskell's `sortOn label . filter (\v -> length
/// (filter (== v) items) >= 2)` on a `[T]` bundle-then-filter
/// shape; NumPy's `np.sort(all[np.array([np.sum(items == v) >=
/// 2 for v in all])])` vectorized strict-repeat mask composed
/// with a lex-order sort; SQL's `SELECT variant FROM t GROUP BY
/// variant HAVING COUNT(*) >= 2 ORDER BY variant` group-by-with-
/// having-then-order-by idiom. Translation through pleme-io
/// primitives: the N-ary lex-order strict-repeat-witness
/// projection on the closed-set trait binds through the substrate's
/// [`Self::sorted_variants`] canonical lex-order enumeration
/// composed with the substrate's per-target strict-repeat
/// primitive [`Self::is_repeated_occurrence_of`] via the standard-
/// library filter combinator — no new dep, no `Eq`/`Hash`
/// supertrait bound, no set-shape carrier.
fn sorted_repeating_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| <Self as ClosedSet>::is_repeated_occurrence_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "unique variants" projection — the
/// `Vec<Self>` DECLARATION-ORDER strict-uniqueness set of
/// [`Self::ALL`], keeping every variant whose per-target
/// multiplicity in `items` is EXACTLY `1` and dropping every
/// variant whose multiplicity is `0` or `>= 2`. The VEC-RETURN
/// STRICT-UNIQUENESS corner OPENING the (`Vec<Self>`, set-level,
/// multiplicity-band `== 1`) column past the (`bool`, set-level,
/// multiplicity-band `== 1`) [`Self::is_unique_any`] existential
/// corner AND the (`usize`, set-level, multiplicity-band `== 1`)
/// [`Self::count_unique_variants`] cardinality corner on the
/// equivalence-partition surface, positioned as the concrete
/// WITNESS behind those two peer projections (which report
/// whether the strict-uniqueness set is non-empty and its
/// cardinality alone, respectively).
///
/// Cardinality identity: for every slice `items`,
/// `T::unique_variants(items).len() ==
/// T::count_unique_variants(items)` — the Vec-return strict-
/// uniqueness projection's length matches the usize-return
/// strict-uniqueness count exactly. Sibling posture to
/// `repeating_variants_length_equals_count_repeating_variants_across_every_triple`
/// on the peer (mult `>= 2`) band. Pinned by
/// `unique_variants_length_equals_count_unique_variants_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::unique_variants(items).is_empty()` iff
/// `!T::is_unique_any(items)` — the strict-uniqueness set is
/// empty iff the strict-uniqueness existential fails;
/// * `!T::unique_variants(items).is_empty()` iff
/// `T::is_unique_any(items)` — the strict-uniqueness set is
/// non-empty iff the strict-uniqueness existential holds.
///
/// Both identities pin the bool-return existential endpoint as a
/// typed projection of the Vec-return strict-uniqueness set.
/// Pinned by
/// `unique_variants_is_empty_iff_not_is_unique_any_across_every_triple`.
///
/// Sub-set relation: `T::unique_variants(items)` is a SUBSET of
/// `T::present_variants(items)` — every strict-uniqueness variant
/// occurs at least once, so the (multiplicity `== 1`) band is
/// contained in the (multiplicity `>= 1`) presence band.
/// Symmetrically, `T::unique_variants(items)` is DISJOINT from
/// `T::missing_variants(items)` (the multiplicity `== 0` band
/// cannot overlap the multiplicity `== 1` band) AND DISJOINT
/// from `T::repeating_variants(items)` (the multiplicity `>= 2`
/// band cannot overlap the multiplicity `== 1` band). Pinned by
/// `unique_variants_is_a_subset_of_present_variants_across_every_triple`,
/// `unique_variants_is_disjoint_from_missing_variants_across_every_triple`,
/// and
/// `unique_variants_is_disjoint_from_repeating_variants_across_every_triple`.
///
/// Trichotomy partition identity: for every slice `items`, the
/// three Vec-return witnesses on the multiplicity-band trichotomy
/// PARTITION [`Self::ALL`] exactly, so
/// `T::missing_variants(items).len() +
/// T::unique_variants(items).len() +
/// T::repeating_variants(items).len() == T::CARDINALITY`. This
/// is the Vec-return lift of
/// `count_missing + count_unique_variants + count_repeating_variants
/// == T::CARDINALITY` on the peer usize-return column. Pinned by
/// `unique_variants_plus_missing_variants_plus_repeating_variants_partitions_all_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// uniqueness predicate is a function of that multiset alone.
/// The OUTPUT ordering is fixed by [`Self::ALL`]'s declaration
/// order regardless of the input ordering. Pinned by
/// `unique_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Declaration-order subsequence contract: the returned
/// `Vec<Self>` is ALWAYS a subsequence of [`Self::ALL`] — every
/// variant appears at most once (dedup by the closed-set well-
/// formedness invariant [`assert_closed_set_well_formed`]'s
/// clause (3) pairwise-distinctness), in [`Self::ALL`]'s
/// declaration order. Pinned by
/// `unique_variants_preserves_declaration_order_across_every_triple`.
///
/// Empty-slice contract: `T::unique_variants(&[])` is the empty
/// `Vec` UNCONDITIONALLY — the empty slice hits zero positions,
/// so every per-variant multiplicity is `0` and the per-target
/// `== 1` test fails at every target. Sibling posture to
/// `is_unique_any_returns_false_on_the_empty_slice_across_every_kind`
/// at the OPPOSITE return-shape column: the bool-return
/// projection reports `false` (strict-uniqueness existential
/// fails); this Vec-return projection reports `[]` (strict-
/// uniqueness witness is empty). Pinned by
/// `unique_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::unique_variants(<T as ClosedSet>::ALL)
/// == <T as ClosedSet>::ALL.to_vec()` UNCONDITIONALLY — the
/// closed-set well-formedness invariant's clause (3) pairwise-
/// distinctness pins every variant of [`Self::ALL`] as occurring
/// at EXACTLY ONE position of the full-set slice, so every per-
/// target multiplicity is `1` and the per-target `== 1` test
/// succeeds at every target. The full-set arm is LOAD-BEARING —
/// it is the ONLY canonical fixpoint arm that separates the
/// (multiplicity `== 1`) band from the (multiplicity `== 0`)
/// absence band (empty-slice arm) AND from the (multiplicity
/// `>= 2`) repetition band (doubled-full-set arm). Pinned by
/// `unique_variants_over_the_full_set_equals_all_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::unique_variants(&<T as ClosedSet>::ALL.iter().chain(<T
/// as ClosedSet>::ALL.iter()).copied().collect::<Vec<_>>())`
/// is the empty `Vec` UNCONDITIONALLY — the doubled full set
/// hits every variant at EXACTLY TWO positions, so every per-
/// target multiplicity is `2` and the per-target `== 1` test
/// fails at every target. The doubled-full-set arm is LOAD-
/// BEARING as the boundary separating the (mult `== 1`) band
/// from the (mult `>= 2`) band. Pinned by
/// `unique_variants_over_the_doubled_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's per-target [`Self::is_unique_occurrence_of`]
/// primitive filtered through [`Self::ALL`]. The composition
/// uses `<Self as ClosedSet>::ALL.iter().copied().filter(…)
/// .collect()` with the substrate's strict-uniqueness per-target
/// predicate as the filter — allocation-free on the `Sized +
/// Copy + 'static` supertrait pair (no `PartialEq`/`Eq`/`Hash`
/// bound; the substrate's [`Self::index_of`] projection replaces
/// the standard-library group-by signatures' `Eq`/`Hash` demand),
/// `O(T::CARDINALITY × n)` worst-case on slice arity `n` for the
/// per-target occurrence sweep, no bitset-shape carrier.
///
/// Future consumers that compose against
/// [`Self::unique_variants`]: a `tatara-check` predicate
/// `(check-phases-report-unique-variants …)` that emits the
/// concrete list of `WorkloadPhase` variants a rollout window
/// saw EXACTLY ONCE (a strict-uniqueness witness rather than the
/// sibling `is_unique_any` existential or the sibling
/// `count_unique_variants` cardinality); an LSP diagnostic on a
/// Lisp-author-written `:severities [:info :warn :info]` closed-
/// set field that renders the strict-uniqueness set as an
/// author-facing "used exactly once: [warn]" completion hint;
/// a Sekiban audit-trail projection that carries the concrete
/// unique-witness set of a classification poset window as its
/// per-window witness (not just the existential or the count);
/// a `tatara-lisp::macro_expand::Expander` hygiene pass that
/// reports the exact set of linearly-bound identifiers a
/// template hit (turning the pass-level `bool` or `usize`
/// diagnostic into a fine-grained witness without a second
/// sweep). Each binds to ONE typed N-ary strict-uniqueness-
/// witness projection on the trait rather than re-deriving
/// `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == 1).collect()` inline
/// per callsite.
///
/// Compounding closure: the (`Vec<Self>`, set-level) ×
/// (mult `== 0`, mult `>= 1`, mult `== 1`, mult `>= 2`) 1×4 =
/// 4-corner (return-shape × multiplicity-band) grid on the
/// equivalence-partition surface's Vec-return column now closes
/// EXHAUSTIVELY at four typed peer projections —
/// [`Self::missing_variants`] (mult `== 0`),
/// [`Self::present_variants`] (mult `>= 1`), THIS (mult `== 1`),
/// [`Self::repeating_variants`] (mult `>= 2`). The (Vec-return ×
/// multiplicity-band) row is now EXHAUSTIVELY closed at four peer
/// projections on the substrate rather than unnamed inline
/// compositions at every downstream generic site. The next
/// natural lift on this surface — the (declaration, lex) ordering
/// axis: `sorted_unique_variants` walking [`Self::sorted_variants`]
/// instead of [`Self::ALL`], opening the lex-order arm of the
/// (mult `== 1`) column past the declaration-order arm THIS
/// projection opens.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// strict-uniqueness witness projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::ALL.iter().copied().filter(|&v|
/// T::count_occurrences_of(v, items) == 1).collect()`
/// composition at every downstream generic site. THEORY.md §V.1
/// — knowable platform; the (Vec-return, mult `== 1`) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which variants occurred EXACTLY ONCE?" site pre-
/// lift. Naming it on the trait makes the projection a TYPED
/// CONSEQUENCE of the substrate's per-target strict-uniqueness
/// primitive ([`Self::is_unique_occurrence_of`]) filtered through
/// [`Self::ALL`] via the standard-library filter combinator.
/// THEORY.md §VI.1 — generation over composition; the strict-
/// uniqueness witness projection emerges from the composition of
/// ONE substrate primitive with an `iter().copied().filter(…)
/// .collect()` combinator, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Coq's `filter (fun v => count_occ eqb l v
/// =? 1) all` decidable-equality-derived strict-uniqueness
/// witness on a `list nat`; SQL's `SELECT variant FROM t GROUP BY
/// variant HAVING COUNT(*) = 1` group-by-with-having idiom
/// (linear duplicates elimination); NumPy's
/// `all[np.array([np.sum(items == v) == 1 for v in all])]`
/// vectorized strict-uniqueness mask; Racket's `(filter (lambda
/// (v) (= (count (curry equal? v) items) 1)) all)` on a `listof
/// T` bundle. Translation through pleme-io primitives: the N-ary
/// strict-uniqueness witness projection on the closed-set trait
/// binds through the substrate's per-target strict-uniqueness
/// primitive [`Self::is_unique_occurrence_of`] filtered through
/// [`Self::ALL`] instead of an `Eq`/`Hash` supertrait bound on
/// a `GROUP BY`-shaped carrier — staying allocation-free on the
/// `Sized + Copy + 'static` supertrait pair.
fn unique_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::ALL
.iter()
.copied()
.filter(|&v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "unique variants" projection —
/// the `Vec<Self>` LEX-ORDER strict-uniqueness set of
/// [`Self::sorted_variants`], keeping every variant whose per-
/// target multiplicity in `items` is EXACTLY `1` and dropping
/// every variant whose multiplicity is `0` or `>= 2`. The LEX-
/// ORDER peer of [`Self::unique_variants`] on the (declaration,
/// lex) ordering axis of the Vec-return column of the
/// equivalence-partition surface — closes the lex arm past the
/// declaration arm the prior projection opens.
///
/// Composition law: for every slice `items`,
/// `T::sorted_unique_variants(items) ==
/// T::sorted_variants().into_iter().filter(|&v|
/// T::is_unique_occurrence_of(v, items)).collect()` — the
/// projection binds through the substrate's
/// [`Self::sorted_variants`] canonical-listing surface composed
/// with the standard-library filter combinator keyed on
/// [`Self::is_unique_occurrence_of`]. The uniqueness MEMBERSHIP
/// predicate matches [`Self::unique_variants`] byte-for-byte on
/// every variant; only the ITERATION ORDER differs (lex vs
/// declaration).
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_unique_variants(items)` is a PERMUTATION of
/// `T::unique_variants(items)` — the two projections filter the
/// SAME strict-uniqueness set from [`Self::ALL`] /
/// [`Self::sorted_variants`] (both of which contain every
/// variant exactly once by the closed-set well-formedness
/// invariant [`assert_closed_set_well_formed`]'s clauses 3 + 17),
/// so the multiset of variant identities in the two returned
/// Vecs coincides though the ordering differs. Pinned by
/// `sorted_unique_variants_is_a_permutation_of_unique_variants_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_unique_variants(items).len() ==
/// T::count_unique_variants(items)` — the lex-order Vec-return
/// strict-uniqueness projection's length matches the usize-
/// return strict-uniqueness count exactly. Pinned by
/// `sorted_unique_variants_length_equals_count_unique_variants_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::sorted_unique_variants(items).is_empty()` iff
/// `!T::is_unique_any(items)`;
/// * `!T::sorted_unique_variants(items).is_empty()` iff
/// `T::is_unique_any(items)`.
///
/// Pinned by
/// `sorted_unique_variants_is_empty_iff_not_is_unique_any_across_every_triple`.
///
/// Lex-order subsequence contract: the returned `Vec<Self>` is
/// ALWAYS a subsequence of [`Self::sorted_variants`] — every
/// variant appears at most once, in lex order of
/// [`Self::label`]. Pinned by
/// `sorted_unique_variants_preserves_lex_order_across_every_triple`.
///
/// Ordering-axis normalization: on implementors whose
/// declaration order diverges from lex order, the lex-arm and
/// decl-arm projections carry the SAME multiset but DIFFERENT
/// declaration-order-preserving indexing. Pinned by
/// `sorted_unique_variants_normalizes_arbitrary_declaration_order`.
///
/// Empty-slice contract: `T::sorted_unique_variants(&[])` is the
/// empty `Vec` UNCONDITIONALLY — every multiplicity is `0`, so
/// no variant survives the per-target `== 1` filter. Pinned by
/// `sorted_unique_variants_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::sorted_unique_variants(<T as
/// ClosedSet>::ALL) == T::sorted_variants()` UNCONDITIONALLY —
/// clause (3)'s pairwise-distinctness invariant pins every
/// variant as occurring at EXACTLY ONE position of the full-set
/// slice, so every per-target multiplicity is `1` and the
/// projection returns each variant of `T::sorted_variants()`
/// exactly once in lex order. Pinned by
/// `sorted_unique_variants_over_the_full_set_equals_sorted_variants_across_every_kind`.
///
/// Doubled-full-set contract:
/// `T::sorted_unique_variants(&<T as ClosedSet>::ALL.iter()
/// .chain(<T as ClosedSet>::ALL.iter()).copied()
/// .collect::<Vec<_>>())` is the empty `Vec` UNCONDITIONALLY —
/// every per-target multiplicity is `2` and the per-target `==
/// 1` test fails at every target. Pinned by
/// `sorted_unique_variants_over_the_doubled_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of TWO
/// substrate primitives ([`Self::sorted_variants`] +
/// [`Self::is_unique_occurrence_of`]) via an
/// `into_iter().filter(…).collect()` combinator, not as a per-
/// implementor hand-rolled body — allocation-owned (the
/// `sorted_variants` allocation is inherited verbatim, no
/// second allocation past the filter), no
/// `PartialEq`/`Eq`/`Hash` bound, `O(T::CARDINALITY × n)` worst-
/// case on slice arity `n`.
///
/// Compounding closure: the (`Vec<Self>`, declaration, lex) 3×2
/// = 6-corner `Vec<Self>`-return (partition-arm × ordering)
/// face on the equivalence-partition surface at the (mult `>= 1`,
/// mult `== 0`, mult `>= 2`) partition-arm triple was closed by
/// [`Self::sorted_repeating_variants`]; adding this projection
/// and the peer [`Self::unique_variants`] promotes the face to
/// a 4×2 = 8-corner face by adding the (mult `== 1`) column at
/// BOTH ordering arms, EXHAUSTIVELY closing every corner on the
/// Vec-return column of the (partition-arm × ordering) face at
/// eight typed peer projections — [`Self::present_variants`] +
/// [`Self::sorted_present_variants`] (mult `>= 1`),
/// [`Self::missing_variants`] + [`Self::sorted_missing_variants`]
/// (mult `== 0`), [`Self::repeating_variants`] +
/// [`Self::sorted_repeating_variants`] (mult `>= 2`),
/// [`Self::unique_variants`] + THIS (mult `== 1`).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order strict-uniqueness-witness projection becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline `T::sorted_variants().into_iter().filter(|&v|
/// T::count_occurrences_of(v, items) == 1).collect()` composition
/// at every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (strict-uniqueness-Vec, lex-order) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which variants occurred EXACTLY ONCE, in lex
/// order?" site pre-lift. Naming it on the trait makes the
/// projection a TYPED CONSEQUENCE of the substrate's canonical-
/// listing surface composed with the substrate's per-target
/// strict-uniqueness primitive via the standard-library filter
/// combinator. THEORY.md §VI.1 — generation over composition;
/// the lex-order strict-uniqueness-witness projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::sorted_variants`] +
/// [`Self::is_unique_occurrence_of`]) via an
/// `into_iter().filter(…).collect()` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(sort (filter (lambda (v) (=
/// (count (curry equal? v) items) 1)) (enum->list T)) #:key
/// T-label)` — the canonical-list-then-strict-uniqueness-filter
/// idiom on any decidable-equality carrier, keyed on a label
/// projection; Haskell's `sortOn label . filter (\v -> length
/// (filter (== v) items) == 1)` on a `[T]` bundle-then-filter
/// shape; NumPy's `np.sort(all[np.array([np.sum(items == v) == 1
/// for v in all])])` vectorized strict-uniqueness mask composed
/// with a lex-order sort; SQL's `SELECT variant FROM t GROUP BY
/// variant HAVING COUNT(*) = 1 ORDER BY variant` group-by-with-
/// having-then-order-by idiom. Translation through pleme-io
/// primitives: the N-ary lex-order strict-uniqueness-witness
/// projection on the closed-set trait binds through the
/// substrate's [`Self::sorted_variants`] canonical lex-order
/// enumeration composed with the substrate's per-target strict-
/// uniqueness primitive [`Self::is_unique_occurrence_of`] via
/// the standard-library filter combinator — no new dep, no
/// `Eq`/`Hash` supertrait bound, no set-shape carrier.
fn sorted_unique_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
<Self as ClosedSet>::sorted_variants()
.into_iter()
.filter(|&v| <Self as ClosedSet>::is_unique_occurrence_of(v, items))
.collect()
}
/// The N-ARY ORDERING-AGNOSTIC "the unique miss-band witness as a
/// singleton-or-empty Vec" projection — returns
/// [`Self::missing_variants`] iff `items` has a UNIQUE miss-band
/// witness ([`Self::has_unique_missing_variant`] holds) AND is the
/// sole variant whose per-target multiplicity sits at `== 0`, else
/// `vec![]`. Computed as the just-lifted set-level miss-band
/// uniqueness bit [`Self::has_unique_missing_variant`] guarding the
/// declaration-order miss-set witness-collection
/// [`Self::missing_variants`]: when the guard holds the collection
/// is already a length-`1` Vec by the guard's own definition
/// (`count_missing == 1`) and is lifted verbatim; when the guard
/// falsifies the projection collapses to the EMPTY Vec through a
/// zero-allocation `::std::vec::Vec::new()` short-circuit. The
/// `Vec<Self>`-RETURN UNIQUE-TIE SHARPENING corner OPENING the
/// (set-level × `Vec<Self>` × equivalence-partition ×
/// multiplicity-band × unique-tie) column past the eight unsharpened
/// (declaration/lex × miss/repeat/unique/present) equivalence-
/// partition witness-collection peers ([`Self::missing_variants`],
/// [`Self::sorted_missing_variants`], [`Self::repeating_variants`],
/// [`Self::sorted_repeating_variants`], [`Self::unique_variants`],
/// [`Self::sorted_unique_variants`], [`Self::present_variants`],
/// [`Self::sorted_present_variants`]) one UNIQUE-TIE-SHARPENING
/// axis over on the equivalence-partition surface AND peer to
/// [`Self::unique_extremal_variants`] (set-level × `Vec<Self>` ×
/// modal-aggregation × direction-composition × union × unique-tie)
/// one SURFACE axis over on the modal-aggregation matrix AND peer
/// to [`Self::unique_missing_variant`] (set-level × `Option<Self>`
/// × equivalence-partition × mult-band `== 0` × unique-tie) one
/// RETURN-SHAPE axis over (Option-return witness-when-unique →
/// Vec-return singleton-or-empty-when-unique) AND peer to
/// [`Self::has_unique_missing_variant`] (set-level × `bool` ×
/// equivalence-partition × mult-band `== 0` × unique-tie) one
/// RETURN-SHAPE axis over (bool uniqueness bit → Vec-return
/// singleton-or-empty carrier of the same bit). Not a fresh
/// substrate primitive on the index axis — the projection emerges
/// from the boolean-guarded selection of the declaration-order
/// miss-set witness-collection under the set-level miss-band
/// uniqueness bit, collapsing to the empty Vec through the guard-
/// arm when the bit falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_missing_variants(items) == if T::has_unique_missing_variant(items) { T::missing_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_missing_variants_equals_has_unique_missing_variant_gated_missing_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_missing_variants(items).len() == usize::from(T::has_unique_missing_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level miss-
/// band uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since when
/// `count_missing == 1` the underlying [`Self::missing_variants`]
/// filter over [`Self::ALL`] admits EXACTLY ONE variant).
/// Independent cross-check on the surface axis distinct from the
/// guarded-witness-collection arm (length reduction vs conditional
/// Vec-select). Pinned by
/// `unique_missing_variants_len_equals_has_unique_missing_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_missing_variants(items).first().copied() == T::unique_missing_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both
/// encode the same "sole absent witness if unique, else nothing"
/// semantics through different return shapes. Pinned by
/// `unique_missing_variants_first_equals_unique_missing_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_missing_variants(items).is_empty() == !T::has_unique_missing_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_missing_variants_is_empty_iff_not_has_unique_missing_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_missing_variant`] (ordering-agnostic — the
/// underlying [`Self::count_missing`] is invariant under slice-
/// reversal via [`Self::count_occurrences_of`]) and
/// [`Self::missing_variants`] (ordering-agnostic on the input axis
/// — the underlying [`Self::occurs_in`] complement filter over
/// [`Self::ALL`] is invariant under slice-reversal) via a boolean-
/// guarded Vec-select. Pinned by
/// `unique_missing_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::unique_missing_variants(&[]) == vec![]` — the empty slice
/// hits zero positions, so every variant sits at count `0`,
/// [`Self::count_missing`] reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`. Sibling posture at
/// `T::CARDINALITY == 1`: [`Self::count_missing`] reports `1`, the
/// guard holds, and the projection returns
/// `T::missing_variants(&[]) == T::ALL.to_vec()` — the SOLE non-
/// empty degenerate arm at cardinality-1.
///
/// Matching-singleton contract: at `T::CARDINALITY >= 3` on every
/// variant `v`, `T::unique_missing_variants(&[v]) == vec![]` — the
/// target hits count `1`, every non-target sits at count `0`, so
/// [`Self::count_missing`] reports `T::CARDINALITY - 1 >= 2`,
/// [`Self::has_unique_missing_variant`] returns `false`, and the
/// guard collapses to `vec![]`. At `T::CARDINALITY == 2` the
/// matching singleton leaves EXACTLY ONE non-target absent,
/// [`Self::count_missing`] reports `1`, the guard holds, and the
/// projection returns `vec![the-non-target]`.
///
/// Full-set + doubled-full-set contract:
/// `T::unique_missing_variants(T::ALL) == vec![]` +
/// `T::unique_missing_variants(&doubled) == vec![]`
/// UNCONDITIONALLY — the pairwise-distinctness invariant pins every
/// variant at exactly one position on the full set (doubled to two
/// on the doubled fixture), no variant is absent,
/// [`Self::count_missing`] reports `0`,
/// [`Self::has_unique_missing_variant`] returns `false` via
/// `0 != 1`, and the guard collapses to `vec![]`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2 == max`, `T::ALL[1]` at count `1` (strict interior),
/// `T::ALL[2..]` at count `0 == min`;
/// [`Self::count_missing`] reports `T::CARDINALITY - 2`. At
/// `T::CARDINALITY == 3` that is `1`, the guard holds, and the
/// projection returns `vec![T::ALL[2]]` — the LOAD-BEARING sole
/// non-empty arm on the multi-variant test-module fixture at the
/// canonical bimodal cardinality. At `T::CARDINALITY >= 4` the
/// miss-band cardinality `>= 2` falsifies the guard, and the
/// projection collapses to `vec![]`. LOAD-BEARING DISCRIMINATOR
/// from [`Self::unique_extremal_variants`] which returns `vec![]`
/// on the SAME fixture — the SURFACE axis SEPARATES the
/// EQUIVALENCE-PARTITION miss-band positive arm at cardinality `3`
/// from the MODAL-AGGREGATION union degenerate arm on the shared
/// canonical fixture window.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_missing_variant`] +
/// [`Self::missing_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_missing`] reduction for the guard, one
/// [`Self::missing_variants`] filter sweep when the guard holds;
/// the short-circuiting `if` avoids the filter sweep AND the Vec
/// allocation when the guard falsifies), no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_missing_variants`]: a `tatara-check` predicate
/// `(check-missing-if-unique …)` that reports the singleton-or-
/// empty absent witness collection as a typed `Vec<Self>`-return
/// rather than a two-step (has-unique-missing-variant? then
/// missing-variants) composition; a Sekiban audit-trail per-window
/// singleton-or-empty binding that composes uniformly with the
/// modal-aggregation Vec-return unique-tie corners
/// ([`Self::unique_extremal_variants`],
/// [`Self::unique_middle_band_variants`],
/// [`Self::unique_bimodal_variants`]) through a shared Vec return
/// shape; downstream aggregate code that iterates over "the sole
/// absent variant if any" without needing to dispatch on
/// Option/Vec at the callsite.
///
/// Compounding closure: this projection OPENS the (set-level ×
/// `Vec<Self>` × equivalence-partition × mult-band × unique-tie)
/// column at its (mult `== 0`) miss-band arm — the NEW UNIQUE-TIE-
/// SHARPENING axis on the equivalence-partition Vec surface, peer
/// to the just-closed modal-aggregation (set-level × `Vec<Self>` ×
/// direction-composition × combinator × ordering × unique-tie) 3×2
/// face one SURFACE axis over. The natural next lifts past this
/// corner are the (mult `>= 2`) STRICT-REPEAT arm
/// `unique_repeating_variants` (guarded lift of
/// [`Self::repeating_variants`] under
/// [`Self::has_unique_repeating_variant`]) and the (mult `== 1`)
/// STRICT-UNIQUENESS arm `unique_unique_variants` (guarded lift of
/// [`Self::unique_variants`] under
/// [`Self::has_unique_unique_variant`]) that CLOSE the equivalence-
/// partition Vec-return unique-tie trichotomy row, followed by
/// their LEX-order peers (`sorted_unique_missing_variants`, etc.)
/// one ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-missing `Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set
/// trait rather than a per-consumer inline
/// `if T::has_unique_missing_variant(items) { T::missing_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × equivalence-
/// partition × mult-band `== 0` × unique-tie) witness-if-unique
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "the sole absent variant, as a Vec, if
/// it's unambiguous" site pre-lift. THEORY.md §VI.1 — generation
/// over composition; the projection emerges from the composition
/// of TWO substrate primitives ([`Self::has_unique_missing_variant`]
/// + [`Self::missing_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); miss <- setdiff(all, names(t)); if (length(miss) == 1) miss else character(0) }`
/// — the canonical guarded-absent singleton-or-empty carrier on a
/// factor histogram; Clojure's
/// `(let [seen (set coll), miss (remove seen all)] (if (= 1 (count miss)) [(first miss)] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT v FROM all_variants WHERE v NOT IN (SELECT DISTINCT variant FROM t)) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated miss-band singleton-or-empty projection on the
/// closed-set trait binds through the just-lifted
/// [`Self::has_unique_missing_variant`] guard conjoined with the
/// declaration-order [`Self::missing_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_missing_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_missing_variant(items) {
<Self as ClosedSet>::missing_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique strict-repeat witness as a
/// singleton-or-empty Vec" projection — returns
/// [`Self::repeating_variants`] iff `items` has a UNIQUE strict-repeat
/// witness ([`Self::has_unique_repeating_variant`] holds) AND is the
/// sole variant whose per-target multiplicity sits at `>= 2`, else
/// `vec![]`. Computed as the just-lifted set-level strict-repeat
/// uniqueness bit [`Self::has_unique_repeating_variant`] guarding the
/// declaration-order strict-repeat witness-collection
/// [`Self::repeating_variants`]: when the guard holds the collection
/// is already a length-`1` Vec by the guard's own definition
/// (`count_repeating_variants == 1`) and is lifted verbatim; when the
/// guard falsifies the projection collapses to the EMPTY Vec through
/// a zero-allocation `::std::vec::Vec::new()` short-circuit. The
/// `Vec<Self>`-RETURN UNIQUE-TIE SHARPENING corner CLOSING the strict-
/// repeat arm of the (set-level × `Vec<Self>` × equivalence-partition
/// × mult-band × unique-tie) row past the just-opened (mult `== 0`)
/// miss-band arm [`Self::unique_missing_variants`] one MULTIPLICITY-
/// BAND axis over on the equivalence-partition surface AND peer to
/// [`Self::unique_repeating_variant`] (set-level × `Option<Self>` ×
/// equivalence-partition × mult-band `>= 2` × unique-tie) one RETURN-
/// SHAPE axis over (Option-return witness-when-unique → Vec-return
/// singleton-or-empty-when-unique) AND peer to
/// [`Self::has_unique_repeating_variant`] (set-level × `bool` ×
/// equivalence-partition × mult-band `>= 2` × unique-tie) one RETURN-
/// SHAPE axis over (bool uniqueness bit → Vec-return singleton-or-
/// empty carrier of the same bit). Not a fresh substrate primitive
/// on the index axis — the projection emerges from the boolean-
/// guarded selection of the declaration-order strict-repeat witness-
/// collection under the set-level strict-repeat uniqueness bit,
/// collapsing to the empty Vec through the guard-arm when the bit
/// falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_repeating_variants(items) == if T::has_unique_repeating_variant(items) { T::repeating_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_repeating_variants_equals_has_unique_repeating_variant_gated_repeating_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_repeating_variants(items).len() == usize::from(T::has_unique_repeating_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level strict-
/// repeat uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since when
/// `count_repeating_variants == 1` the underlying
/// [`Self::repeating_variants`] filter over [`Self::ALL`] admits
/// EXACTLY ONE variant). Independent cross-check on the surface axis
/// distinct from the guarded-witness-collection arm (length reduction
/// vs conditional Vec-select). Pinned by
/// `unique_repeating_variants_len_equals_has_unique_repeating_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_repeating_variants(items).first().copied() == T::unique_repeating_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both encode
/// the same "sole strict-repeat witness if unique, else nothing"
/// semantics through different return shapes. Pinned by
/// `unique_repeating_variants_first_equals_unique_repeating_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_repeating_variants(items).is_empty() == !T::has_unique_repeating_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_repeating_variants_is_empty_iff_not_has_unique_repeating_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_repeating_variant`] (ordering-agnostic — the
/// underlying [`Self::count_repeating_variants`] is invariant under
/// slice-reversal via [`Self::count_occurrences_of`]) and
/// [`Self::repeating_variants`] (ordering-agnostic on the input axis
/// — the underlying [`Self::is_repeated_occurrence_of`] filter over
/// [`Self::ALL`] is invariant under slice-reversal) via a boolean-
/// guarded Vec-select. Pinned by
/// `unique_repeating_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_repeating_variants(&[]) == vec![]`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false` via
/// `0 != 1`, and the guard collapses the projection to `vec![]`
/// through the empty-Vec arm before the underlying witness-collection
/// filter is consulted.
///
/// Matching-singleton contract: on every variant `v`,
/// `T::unique_repeating_variants(&[v]) == vec![]` — the target hits
/// count `1` (not strictly repeating), every non-target sits at count
/// `0` (also not strictly repeating);
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses to `vec![]`.
///
/// Full-set contract:
/// `T::unique_repeating_variants(<T as ClosedSet>::ALL) == vec![]`
/// UNCONDITIONALLY — the pairwise-distinctness invariant pins every
/// variant at exactly one position of the full-set slice,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false` via
/// `0 != 1`, and the guard collapses to `vec![]`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_repeating_variants(&doubled) == vec![]` — the doubled
/// full set hits every variant at exactly two positions, EVERY
/// per-target multiplicity is `2 >= 2`,
/// [`Self::count_repeating_variants`] reports
/// `T::CARDINALITY >= 2`, [`Self::has_unique_repeating_variant`]
/// returns `false` (multiple witnesses, no unique one), and the guard
/// collapses to `vec![]`. Sibling positive arm at
/// `T::CARDINALITY == 1`: the doubled slice
/// `[T::ALL[0], T::ALL[0]]` collapses the strict-repeat count to `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, and the
/// projection returns `vec![T::ALL[0]]` — the SOLE non-empty
/// degenerate arm at cardinality-1.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count `2`
/// (the SOLE strict-repeat witness), `T::ALL[1]` at count `1`,
/// `T::ALL[2..]` at count `0`;
/// [`Self::count_repeating_variants`] reports `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, the guard
/// holds, and the projection returns `vec![T::ALL[0]]` — the LOAD-
/// BEARING sole non-empty arm on the multi-variant test-module
/// fixture at the canonical bimodal cardinality. LOAD-BEARING
/// DISCRIMINATOR from [`Self::unique_missing_variants`] which returns
/// `vec![T::ALL[2]]` on the SAME fixture at cardinality `== 3` — the
/// MULTIPLICITY-BAND axis SEPARATES the (mult `>= 2`) strict-repeat
/// positive arm (WITNESS `T::ALL[0]`) from the (mult `== 0`)
/// miss-band positive arm (WITNESS `T::ALL[2]`) on the shared
/// canonical fixture window: the two POSITIVE arms report DIFFERENT
/// witnesses, pinning the strict-repeat and miss bands as orthogonal
/// uniqueness axes on the equivalence-partition surface with disjoint
/// witness projections. LOAD-BEARING DISCRIMINATOR from
/// [`Self::unique_extremal_variants`] which returns `vec![]` on the
/// SAME fixture — the SURFACE axis SEPARATES this EQUIVALENCE-
/// PARTITION strict-repeat positive arm from the MODAL-AGGREGATION
/// union degenerate arm.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::repeating_variants`] via a boolean-guarded Vec-select on
/// `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_repeating_variants`] reduction for the guard, one
/// [`Self::repeating_variants`] filter sweep when the guard holds;
/// the short-circuiting `if` avoids the filter sweep AND the Vec
/// allocation when the guard falsifies), no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_repeating_variants`]: a `tatara-check` predicate
/// `(check-repeating-if-unique …)` that reports the singleton-or-
/// empty strict-repeat witness collection as a typed
/// `Vec<Self>`-return rather than a two-step (has-unique-repeating-
/// variant? then repeating-variants) composition; a Sekiban audit-
/// trail per-window singleton-or-empty binding that composes
/// uniformly with the modal-aggregation Vec-return unique-tie corners
/// ([`Self::unique_extremal_variants`],
/// [`Self::unique_middle_band_variants`],
/// [`Self::unique_bimodal_variants`]) AND the miss-band peer
/// ([`Self::unique_missing_variants`]) through a shared Vec return
/// shape; downstream aggregate code that iterates over "the sole
/// strict-repeat witness if any" without needing to dispatch on
/// Option/Vec at the callsite.
///
/// Compounding closure: this projection CLOSES the (mult `>= 2`)
/// strict-repeat arm of the (set-level × `Vec<Self>` × equivalence-
/// partition × mult-band × unique-tie) row past the just-opened
/// (mult `== 0`) miss-band arm [`Self::unique_missing_variants`] one
/// MULTIPLICITY-BAND axis over on the equivalence-partition surface.
/// The natural next lift past this corner is the (mult `== 1`)
/// STRICT-UNIQUENESS arm `unique_unique_variants` (guarded lift of
/// [`Self::unique_variants`] under
/// [`Self::has_unique_unique_variant`]) that EXHAUSTIVELY CLOSES the
/// row at its FINAL third tile, followed by their LEX-order peers
/// (`sorted_unique_repeating_variants`, etc.) one ORDERING axis over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-strict-repeat `Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set trait
/// rather than a per-consumer inline
/// `if T::has_unique_repeating_variant(items) { T::repeating_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × equivalence-
/// partition × mult-band `>= 2` × unique-tie) witness-if-unique
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "the sole strict-repeat witness, as a
/// Vec, if it's unambiguous" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::has_unique_repeating_variant`] +
/// [`Self::repeating_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); reps <- names(t)[t >= 2]; if (length(reps) == 1) reps else character(0) }`
/// — the canonical guarded-strict-repeat singleton-or-empty carrier
/// on a factor histogram; Clojure's
/// `(let [reps (filter #(>= (val %) 2) (frequencies coll))] (if (= 1 (count reps)) [(key (first reps))] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) >= 2) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated strict-repeat singleton-or-empty projection on
/// the closed-set trait binds through the just-lifted
/// [`Self::has_unique_repeating_variant`] guard conjoined with the
/// declaration-order [`Self::repeating_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_repeating_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_repeating_variant(items) {
<Self as ClosedSet>::repeating_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique unique-band witness as a
/// singleton-or-empty Vec" projection — returns
/// [`Self::unique_variants`] iff `items` has a UNIQUE (mult `== 1`)
/// witness ([`Self::has_unique_unique_variant`] holds) AND is the
/// sole variant whose per-target multiplicity sits EXACTLY at `1`,
/// else `vec![]`. Computed as the just-lifted set-level unique-band
/// uniqueness bit [`Self::has_unique_unique_variant`] guarding the
/// declaration-order strict-uniqueness witness-collection
/// [`Self::unique_variants`]: when the guard holds the collection
/// is already a length-`1` Vec by the guard's own definition
/// (`count_unique_variants == 1`) and is lifted verbatim; when the
/// guard falsifies the projection collapses to the EMPTY Vec through
/// a zero-allocation `::std::vec::Vec::new()` short-circuit. The
/// `Vec<Self>`-RETURN UNIQUE-TIE SHARPENING corner EXHAUSTIVELY
/// CLOSING the middle (mult `== 1`) arm of the (set-level ×
/// `Vec<Self>` × equivalence-partition × mult-band × unique-tie)
/// 3-corner row on the EQUIVALENCE-PARTITION surface AT ITS FINAL
/// THIRD TILE past the (mult `== 0`) miss-band arm
/// [`Self::unique_missing_variants`] AND the (mult `>= 2`) strict-
/// repeat arm [`Self::unique_repeating_variants`] one MULTIPLICITY-
/// BAND axis over. Peer to [`Self::unique_unique_variant`] (set-
/// level × `Option<Self>` × equivalence-partition × mult `== 1` ×
/// unique-tie) one RETURN-SHAPE axis over (Option-return witness-
/// when-unique → Vec-return singleton-or-empty-when-unique) AND
/// peer to [`Self::has_unique_unique_variant`] (set-level × `bool`
/// × equivalence-partition × mult `== 1` × unique-tie) one RETURN-
/// SHAPE axis over (bool uniqueness bit → Vec-return singleton-or-
/// empty carrier of the same bit). Not a fresh substrate primitive
/// on the index axis — the projection emerges from the boolean-
/// guarded selection of the declaration-order strict-uniqueness
/// witness-collection under the set-level unique-band uniqueness
/// bit, collapsing to the empty Vec through the guard-arm when the
/// bit falsifies.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_unique_variants(items) == if T::has_unique_unique_variant(items) { T::unique_variants(items) } else { vec![] }`
/// — the canonical form the body uses. Pinned by
/// `unique_unique_variants_equals_has_unique_unique_variant_gated_unique_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_unique_variants(items).len() == usize::from(T::has_unique_unique_variant(items))`
/// — the return-Vec's length COINCIDES with the set-level unique-
/// band uniqueness bit projected onto `usize`: exactly `0` when the
/// bit falsifies, exactly `1` when it holds (since when
/// `count_unique_variants == 1` the underlying
/// [`Self::unique_variants`] filter over [`Self::ALL`] admits
/// EXACTLY ONE variant). Independent cross-check on the surface axis
/// distinct from the guarded-witness-collection arm (length
/// reduction vs conditional Vec-select). Pinned by
/// `unique_unique_variants_len_equals_has_unique_unique_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::unique_unique_variants(items).first().copied() == T::unique_unique_variant(items)`
/// — the `Vec`-return's first-element projection COINCIDES with the
/// `Option`-return peer one RETURN-SHAPE axis over, since both
/// encode the same "sole unique-band witness if unique, else
/// nothing" semantics through different return shapes. Pinned by
/// `unique_unique_variants_first_equals_unique_unique_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_unique_variants(items).is_empty() == !T::has_unique_unique_variant(items)`
/// — the return-Vec's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check on the surface
/// axis distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `unique_unique_variants_is_empty_iff_not_has_unique_unique_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_unique_variant`] (ordering-agnostic — the
/// underlying [`Self::count_unique_variants`] is invariant under
/// slice-reversal via [`Self::count_occurrences_of`]) and
/// [`Self::unique_variants`] (ordering-agnostic on the input axis —
/// the underlying [`Self::is_unique_occurrence_of`] filter over
/// [`Self::ALL`] is invariant under slice-reversal) via a boolean-
/// guarded Vec-select. Pinned by
/// `unique_unique_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_unique_variants(&[]) == vec![]`
/// UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false` via
/// `0 != 1`, and the guard collapses the projection to `vec![]`
/// through the empty-Vec arm before the underlying witness-
/// collection filter is consulted.
///
/// Matching-singleton contract: on every variant `v`,
/// `T::unique_unique_variants(&[v]) == vec![v]` — the target hits
/// count `1` (the SOLE unique-band witness), every non-target sits
/// at count `0` (miss-band, not unique-band);
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] holds, and the guarded lift
/// returns the singleton `vec![v]`. LOAD-BEARING NON-EMPTY DEGENERATE
/// ARM at the singleton fixture — distinct from
/// [`Self::unique_missing_variants`] (collapses to `vec![]` at
/// CARDINALITY `<= 2` on the same singleton, positive at
/// CARDINALITY `== 2` returning the sole absent variant) AND
/// [`Self::unique_repeating_variants`] (collapses to `vec![]`
/// unconditionally on every singleton).
///
/// Full-set contract: `T::unique_unique_variants(<T as ClosedSet>::ALL)`
/// is `T::ALL.to_vec()` iff [`Self::CARDINALITY`] `== 1`, else
/// `vec![]` — the pairwise-distinctness invariant pins every
/// variant at exactly one position of the full-set slice, every
/// per-target multiplicity is `1`, [`Self::count_unique_variants`]
/// reports [`Self::CARDINALITY`], [`Self::has_unique_unique_variant`]
/// holds EXACTLY when [`Self::CARDINALITY`] `== 1`. At
/// `T::CARDINALITY == 1` the guarded lift returns `vec![T::ALL[0]]`
/// (the sole unique-band witness); at `T::CARDINALITY >= 2` every
/// variant is a unique-band witness, uniqueness fails, and the
/// guard collapses to `vec![]`.
///
/// Doubled-full-set contract: `T::unique_unique_variants(&doubled)
/// == vec![]` UNCONDITIONALLY — appending a full-set copy hits
/// every variant at multiplicity `2`, every per-target `== 1` test
/// fails, [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false`, and the
/// guard collapses to `vec![]`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2` (strict-repeat), `T::ALL[1]` at count `1` (the SOLE unique-
/// band witness), `T::ALL[2..]` at count `0`;
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, the guard
/// holds, and the projection returns `vec![T::ALL[1]]` — the LOAD-
/// BEARING SOLE non-empty positive arm on the multi-variant test-
/// module fixture at the canonical bimodal cardinality. LOAD-BEARING
/// DISJOINT-WITNESS mirror of [`Self::unique_missing_variants`]
/// (returns `vec![T::ALL[2]]`) AND [`Self::unique_repeating_variants`]
/// (returns `vec![T::ALL[0]]`) on the SAME fixture at cardinality
/// `== 3` — the MULTIPLICITY-BAND axis SEPARATES the (mult `== 1`)
/// unique-band positive arm (WITNESS `T::ALL[1]`) from the (mult
/// `== 0`) miss-band positive arm (WITNESS `T::ALL[2]`) AND from
/// the (mult `>= 2`) strict-repeat positive arm (WITNESS
/// `T::ALL[0]`) on the shared canonical fixture window: the THREE
/// POSITIVE arms report THREE DIFFERENT witnesses, EXHAUSTIVELY
/// pinning the trichotomy of multiplicity bands as orthogonal
/// uniqueness axes with disjoint witness projections riding
/// DIFFERENT variants of the CANONICAL bimodal triple. LOAD-BEARING
/// DISCRIMINATOR from [`Self::unique_extremal_variants`] which
/// returns `vec![]` on the SAME fixture — the SURFACE axis
/// SEPARATES this EQUIVALENCE-PARTITION unique-band positive arm
/// from the MODAL-AGGREGATION union degenerate arm.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_unique_variant`] + [`Self::unique_variants`]
/// via a boolean-guarded Vec-select on `Vec<Self>`. Cost inherits
/// both underlying projections: `O(T::CARDINALITY * n)` on slice
/// arity `n` (one [`Self::count_unique_variants`] reduction for
/// the guard, one [`Self::unique_variants`] filter sweep when the
/// guard holds; the short-circuiting `if` avoids the filter sweep
/// AND the Vec allocation when the guard falsifies), no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::unique_unique_variants`]: a `tatara-check` predicate
/// `(check-unique-if-unique …)` that reports the singleton-or-
/// empty unique-band witness collection as a typed `Vec<Self>`-
/// return rather than a two-step (has-unique-unique-variant? then
/// unique-variants) composition; a Sekiban audit-trail per-window
/// singleton-or-empty binding that composes uniformly with the
/// miss-band peer [`Self::unique_missing_variants`] + the strict-
/// repeat peer [`Self::unique_repeating_variants`] through a shared
/// Vec return shape, closing the equivalence-partition Vec-return
/// unique-tie trichotomy at three typed peer projections;
/// downstream aggregate code that iterates over "the sole unique-
/// band witness if any" without needing to dispatch on Option/Vec
/// at the callsite.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × `Vec<Self>` × equivalence-partition × mult-band ×
/// unique-tie) 3-corner row on the EQUIVALENCE-PARTITION surface
/// AT ITS FINAL THIRD TILE past the (mult `== 0`) miss-band arm
/// [`Self::unique_missing_variants`] AND the (mult `>= 2`) strict-
/// repeat arm [`Self::unique_repeating_variants`] one MULTIPLICITY-
/// BAND axis over — the row is now the CANONICAL `Vec<Self>`-
/// return unique-tie sharpening on the equivalence-partition
/// surface, closed at its FINAL third tile. Mirrors the bool-
/// return trichotomy row's exhaustive closure
/// ([`Self::has_unique_missing_variant`] +
/// [`Self::has_unique_unique_variant`] +
/// [`Self::has_unique_repeating_variant`]) AND the `Option<Self>`-
/// return trichotomy row's exhaustive closure
/// ([`Self::unique_missing_variant`] +
/// [`Self::unique_unique_variant`] +
/// [`Self::unique_repeating_variant`]) one RETURN-SHAPE axis over
/// — the three return-shape columns (`bool`, `Option<Self>`,
/// `Vec<Self>`) each now EXHAUSTIVELY CLOSE the (mult `== 0`, mult
/// `== 1`, mult `>= 2`) trichotomy on the equivalence-partition
/// surface at nine typed peer projections. The natural next lifts
/// past this exhaustive closure are the LEX-order peers
/// (`sorted_unique_missing_variants`,
/// `sorted_unique_unique_variants`,
/// `sorted_unique_repeating_variants`) one ORDERING axis over,
/// each of which is provably equal to its declaration-order peer
/// under the `unique_variants == sorted_unique_variants` (as
/// multiset) identity.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary set-
/// level unique-unique-`Vec<Self>` singleton-or-empty witness
/// projection becomes a TYPE-level primitive on the closed-set
/// trait rather than a per-consumer inline
/// `if T::has_unique_unique_variant(items) { T::unique_variants(items) } else { vec![] }`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × `Vec<Self>` × equivalence-
/// partition × mult `== 1` × unique-tie) witness-if-unique corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "the sole unique-band witness, as a Vec, if it's
/// unambiguous" site pre-lift. Naming it EXHAUSTIVELY CLOSES the
/// equivalence-partition Vec-return unique-tie row's final tile as
/// a TYPED THEOREM the substrate proves once. THEORY.md §VI.1 —
/// generation over composition; the projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::has_unique_unique_variant`] +
/// [`Self::unique_variants`]) with the `if _ { _ } else { vec![] }`
/// combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); s <- names(t)[t == 1]; if (length(s) == 1) s else character(0) }`
/// — the canonical guarded-unique-band singleton-or-empty carrier
/// on a factor histogram; Clojure's
/// `(let [ss (filter #(= (val %) 1) (frequencies coll))] (if (= 1 (count ss)) [(key (first ss))] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) = 1) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated unique-band singleton-or-empty projection on
/// the closed-set trait binds through the just-lifted
/// [`Self::has_unique_unique_variant`] guard conjoined with the
/// declaration-order [`Self::unique_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn unique_unique_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_unique_variant(items) {
<Self as ClosedSet>::unique_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique miss-band witness in LEX
/// order, as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_missing_variants`] iff `items` has a UNIQUE absent
/// variant ([`Self::has_unique_missing_variant`] holds), else
/// `vec![]`. Computed as the just-lifted set-level miss-band
/// uniqueness bit [`Self::has_unique_missing_variant`] guarding the
/// LEX-ORDER miss-band witness-collection
/// [`Self::sorted_missing_variants`]: when the guard holds the
/// collection is already a length-`1` Vec by the guard's own
/// definition (`count_missing_variants == 1`) and is lifted
/// verbatim; when the guard falsifies the projection collapses to
/// the EMPTY Vec through a zero-allocation
/// `::std::vec::Vec::new()` short-circuit. The LEX-ORDER
/// `Vec<Self>`-RETURN MISS-BAND UNIQUE-TIE SHARPENING corner
/// OPENING the LEX-ORDER (`Vec<Self>` × equivalence-partition ×
/// mult-band × unique-tie) row past the just-closed declaration-
/// order trio ([`Self::unique_missing_variants`],
/// [`Self::unique_repeating_variants`],
/// [`Self::unique_unique_variants`]) one ORDERING axis over on the
/// EQUIVALENCE-PARTITION surface, peer to
/// [`Self::unique_missing_variants`] one ORDERING axis over
/// (declaration-order → lex-order miss-band witness-collection-
/// when-unique) AND peer to [`Self::sorted_missing_variants`] one
/// UNIQUE-TIE-SHARPENING axis over (unsharpened lex-order miss-band
/// witness-collection → uniqueness-gated lex-order miss-band
/// witness-collection) AND peer to
/// [`Self::sorted_unique_missing_variant`] one RETURN-SHAPE axis
/// over (Option-return lex-first-witness-when-unique → Vec-return
/// singleton-or-empty-when-unique) AND peer to
/// [`Self::sorted_unique_extremal_variants`] one SURFACE axis over
/// on the (Vec × sorted × unique-tie) face (EQUIVALENCE-PARTITION
/// miss-band → MODAL-AGGREGATION union band). Not a fresh substrate
/// primitive on the index axis — the projection emerges from the
/// boolean-guarded selection of the just-lifted lex-order miss-band
/// witness-collection under the set-level miss-band uniqueness bit,
/// collapsing to the empty Vec through the guard-arm when the bit
/// falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_missing_variants(items) ==
/// T::unique_missing_variants(items)` — when the sole absent variant
/// is UNIQUE ([`Self::has_unique_missing_variant`] holds) the
/// underlying [`Self::sorted_missing_variants`] and
/// [`Self::missing_variants`] each collapse to a length-`1` Vec
/// containing THE SAME sole absent variant (uniqueness pins the sole
/// witness before any ordering choice is consulted); when the guard
/// falsifies both projections collapse to `vec![]` through the same
/// guard arm. The LEX peer is thus IDENTICALLY equal to its
/// declaration-order sibling on every input — the search-order axis
/// becomes provably irrelevant WHEN the underlying uniqueness bit
/// holds. Pinned by
/// `sorted_unique_missing_variants_equals_unique_missing_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_missing_variants(items) ==
/// if T::has_unique_missing_variant(items) { T::sorted_missing_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_missing_variants_equals_has_unique_missing_variant_gated_sorted_missing_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_missing_variants(items).len() ==
/// usize::from(T::has_unique_missing_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level miss-band uniqueness
/// bit projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds. Pinned by
/// `sorted_unique_missing_variants_len_equals_has_unique_missing_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_missing_variants(items).first().copied() ==
/// T::sorted_unique_missing_variant(items)` — the `Vec`-return's
/// first-element projection COINCIDES with the `Option`-return LEX
/// peer one RETURN-SHAPE axis over, since both encode the same
/// "sole absent witness if unique, else nothing" semantics through
/// different return shapes. Pinned by
/// `sorted_unique_missing_variants_first_equals_sorted_unique_missing_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_missing_variants(items).is_empty() ==
/// !T::has_unique_missing_variant(items)` — the return-Vec's
/// emptiness coincides with the NEGATION of the set-level miss-band
/// uniqueness bit. Independent cross-check on the surface axis
/// distinct from the length-coincidence arm (Vec::is_empty vs
/// integer equality). Pinned by
/// `sorted_unique_missing_variants_is_empty_iff_not_has_unique_missing_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_missing_variant`] (ordering-agnostic — the
/// underlying [`Self::count_missing_variants`] is invariant under
/// slice-reversal via [`Self::occurs_in`]) and
/// [`Self::sorted_missing_variants`] (ordering-agnostic on the input
/// axis — the underlying membership sweep over
/// [`Self::sorted_variants`] is invariant under slice-reversal) via
/// a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_missing_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::sorted_unique_missing_variants(&[]) == vec![]` —
/// [`Self::count_missing_variants`] reports `T::CARDINALITY >= 2` on
/// the empty slice (every variant is missing),
/// [`Self::has_unique_missing_variant`] returns `false` via
/// `T::CARDINALITY != 1`, and the guard-arm short-circuit maps the
/// empty slice to the empty Vec.
///
/// Full-set + doubled-full-set contract:
/// `T::sorted_unique_missing_variants(<T as ClosedSet>::ALL) ==
/// vec![]` + `T::sorted_unique_missing_variants(&doubled) == vec![]`
/// — on either flat-histogram fixpoint every variant appears at
/// least once, [`Self::count_missing_variants`] reports `0`,
/// [`Self::has_unique_missing_variant`] returns `false` via
/// `0 != 1`, and the guard collapses the projection to `vec![]`.
///
/// Bimodal-triple contract at cardinality `== 3`:
/// `T::sorted_unique_missing_variants([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == vec![T::ALL[2]]` — the LOAD-BEARING SOLE non-
/// empty arm at the canonical cardinality-3 window. `T::ALL[0]` at
/// count `2`, `T::ALL[1]` at count `1`, `T::ALL[2]` at count `0`
/// (the SOLE absent variant); [`Self::count_missing_variants`]
/// reports `1`, [`Self::has_unique_missing_variant`] returns `true`,
/// the guard fires, and [`Self::sorted_missing_variants`]'s lex-
/// order sweep hits `T::ALL[2]` as its sole miss. LOAD-BEARING
/// DISCRIMINATOR from the sibling declaration-order corner
/// [`Self::unique_missing_variants`] which reports the SAME
/// witness `vec![T::ALL[2]]` on the SAME fixture (the ordering-
/// choice-irrelevance identity in action — miss-band uniqueness
/// pins the witness before either sweep-order kicks in).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_missing_variant`] +
/// [`Self::sorted_missing_variants`] via a boolean-guarded Vec-
/// select on `Vec<Self>`. Cost inherits both underlying
/// projections: `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_missing_variants`] reduction for the guard via
/// [`Self::occurs_in`], one [`Self::sorted_missing_variants`] filter
/// sweep over [`Self::sorted_variants`] when the guard holds; the
/// short-circuiting `if` avoids the sweep AND the Vec allocation
/// when the guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)`
/// for the [`Self::sorted_variants`] cache, no
/// `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's minimal
/// `Sized + Copy + 'static` supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_missing_variants`]: a `tatara-check`
/// predicate `(check-missing-if-unique-lex …)` that reports the
/// singleton-or-empty lex-order miss-band witness collection as a
/// typed `Vec<Self>`-return rather than a two-step composition; a
/// Sekiban audit-trail per-window singleton-or-empty binding stable
/// against upstream declaration-order churn.
///
/// Compounding closure: this projection OPENS the LEX-ORDER
/// (`Vec<Self>` × equivalence-partition × mult-band × unique-tie)
/// row past the just-closed declaration-order trio one ORDERING
/// axis over on the EQUIVALENCE-PARTITION surface. The natural next
/// lifts past this corner are the (mult `>= 2`) strict-repeat arm
/// `sorted_unique_repeating_variants` (guarded lift of
/// [`Self::sorted_repeating_variants`] under
/// [`Self::has_unique_repeating_variant`]) and the (mult `== 1`)
/// unique-band arm `sorted_unique_unique_variants` (guarded lift of
/// [`Self::sorted_unique_variants`] under
/// [`Self::has_unique_unique_variant`]) which together EXHAUSTIVELY
/// CLOSE the (`Vec<Self>` × equivalence-partition × mult-band ×
/// ordering × unique-tie) 3×2 face at its final two lex tiles.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Vec<Self>` × sorted × equivalence-partition × mult
/// `== 0` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_missing_variant(items) { T::sorted_missing_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-
/// level primitive plus a typed THEOREM (ordering-choice-
/// irrelevance) the substrate proves once. THEORY.md §V.1 —
/// knowable platform; the (lex-order × `Vec<Self>` × mult `== 0` ×
/// unique-tie) corner was an unnamed inline composition — or
/// silently absent because callers reached for the declaration-
/// order sibling without proof of coincidence — recurring at every
/// prospective downstream "the sole absent variant, as a Vec, in
/// lex order, if it's unambiguous" site pre-lift. THEORY.md §VI.1
/// — generation over composition; the projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::has_unique_missing_variant`] +
/// [`Self::sorted_missing_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); miss <- sort(setdiff(all, names(t))); if (length(miss) == 1) miss else character(0) }`
/// — the canonical guarded-absent lex-order singleton-or-empty
/// carrier on a factor histogram; Clojure's
/// `(let [seen (set coll), miss (sort (remove seen all))] (if (= 1 (count miss)) [(first miss)] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT v FROM all_variants WHERE v NOT IN (SELECT DISTINCT variant FROM t) ORDER BY v) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order miss-band singleton-or-empty
/// projection on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_missing_variant`] guard conjoined with the
/// just-lifted [`Self::sorted_missing_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn sorted_unique_missing_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_missing_variant(items) {
<Self as ClosedSet>::sorted_missing_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique strict-repeat witness in LEX
/// order, as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_repeating_variants`] iff `items` has a UNIQUE
/// strict-repeat variant ([`Self::has_unique_repeating_variant`]
/// holds), else `vec![]`. Computed as the just-lifted set-level
/// strict-repeat uniqueness bit [`Self::has_unique_repeating_variant`]
/// guarding the LEX-ORDER strict-repeat witness-collection
/// [`Self::sorted_repeating_variants`]: when the guard holds the
/// collection is already a length-`1` Vec by the guard's own
/// definition (`count_repeating_variants == 1`) and is lifted verbatim;
/// when the guard falsifies the projection collapses to the EMPTY Vec
/// through a zero-allocation `::std::vec::Vec::new()` short-circuit.
/// The LEX-ORDER `Vec<Self>`-RETURN STRICT-REPEAT UNIQUE-TIE SHARPENING
/// corner CLOSING the strict-repeat arm of the LEX-ORDER (`Vec<Self>`
/// × equivalence-partition × mult-band × unique-tie) row past the
/// just-opened (mult `== 0`) miss-band arm
/// [`Self::sorted_unique_missing_variants`] one MULTIPLICITY-BAND axis
/// over on the EQUIVALENCE-PARTITION surface, peer to
/// [`Self::unique_repeating_variants`] one ORDERING axis over
/// (declaration-order → lex-order strict-repeat witness-collection-
/// when-unique) AND peer to [`Self::sorted_repeating_variants`] one
/// UNIQUE-TIE-SHARPENING axis over (unsharpened lex-order strict-
/// repeat witness-collection → uniqueness-gated lex-order strict-
/// repeat witness-collection) AND peer to
/// [`Self::sorted_unique_repeating_variant`] one RETURN-SHAPE axis
/// over (Option-return lex-first-witness-when-unique → Vec-return
/// singleton-or-empty-when-unique) AND peer to
/// [`Self::sorted_unique_extremal_variants`] one SURFACE axis over on
/// the (Vec × sorted × unique-tie) face (EQUIVALENCE-PARTITION strict-
/// repeat band → MODAL-AGGREGATION union band). Not a fresh substrate
/// primitive on the index axis — the projection emerges from the
/// boolean-guarded selection of the just-lifted lex-order strict-
/// repeat witness-collection under the set-level strict-repeat
/// uniqueness bit, collapsing to the empty Vec through the guard-arm
/// when the bit falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_repeating_variants(items) ==
/// T::unique_repeating_variants(items)` — when the sole strict-repeat
/// variant is UNIQUE ([`Self::has_unique_repeating_variant`] holds)
/// the underlying [`Self::sorted_repeating_variants`] and
/// [`Self::repeating_variants`] each collapse to a length-`1` Vec
/// containing THE SAME sole strict-repeat variant (uniqueness pins the
/// sole witness before any ordering choice is consulted); when the
/// guard falsifies both projections collapse to `vec![]` through the
/// same guard arm. The LEX peer is thus IDENTICALLY equal to its
/// declaration-order sibling on every input — the search-order axis
/// becomes provably irrelevant WHEN the underlying uniqueness bit
/// holds. Pinned by
/// `sorted_unique_repeating_variants_equals_unique_repeating_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_repeating_variants(items) ==
/// if T::has_unique_repeating_variant(items) { T::sorted_repeating_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_repeating_variants_equals_has_unique_repeating_variant_gated_sorted_repeating_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_repeating_variants(items).len() ==
/// usize::from(T::has_unique_repeating_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level strict-repeat uniqueness
/// bit projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds. Pinned by
/// `sorted_unique_repeating_variants_len_equals_has_unique_repeating_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_repeating_variants(items).first().copied() ==
/// T::sorted_unique_repeating_variant(items)` — the `Vec`-return's
/// first-element projection COINCIDES with the `Option`-return LEX
/// peer one RETURN-SHAPE axis over, since both encode the same "sole
/// strict-repeat witness if unique, else nothing" semantics through
/// different return shapes. Pinned by
/// `sorted_unique_repeating_variants_first_equals_sorted_unique_repeating_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_repeating_variants(items).is_empty() ==
/// !T::has_unique_repeating_variant(items)` — the return-Vec's
/// emptiness coincides with the NEGATION of the set-level strict-
/// repeat uniqueness bit. Independent cross-check on the surface axis
/// distinct from the length-coincidence arm (Vec::is_empty vs integer
/// equality). Pinned by
/// `sorted_unique_repeating_variants_is_empty_iff_not_has_unique_repeating_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_repeating_variant`] (ordering-agnostic — the
/// underlying [`Self::count_repeating_variants`] is invariant under
/// slice-reversal via [`Self::is_repeated_occurrence_of`]) and
/// [`Self::sorted_repeating_variants`] (ordering-agnostic on the
/// input axis — the underlying [`Self::is_repeated_occurrence_of`]
/// filter over [`Self::sorted_variants`] is invariant under slice-
/// reversal) via a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_repeating_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_repeating_variants(&[]) ==
/// vec![]` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false` via `0 !=
/// 1`, and the guard collapses the projection to `vec![]` through the
/// guard arm before the underlying witness-collection filter is
/// consulted.
///
/// Matching-singleton contract: on every variant `v`,
/// `T::sorted_unique_repeating_variants(&[v]) == vec![]` — the target
/// hits count `1` (unique-band, not strict-repeat), every non-target
/// sits at count `0` (miss-band, not strict-repeat);
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Full-set contract: `T::sorted_unique_repeating_variants(<T as
/// ClosedSet>::ALL) == vec![]` UNCONDITIONALLY — clause (3)'s
/// pairwise-distinctness invariant pins every variant at exactly one
/// position, every per-target multiplicity is `1`,
/// [`Self::count_repeating_variants`] reports `0`,
/// [`Self::has_unique_repeating_variant`] returns `false`, and the
/// guard collapses the projection to `vec![]`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::sorted_unique_repeating_variants(&doubled) == vec![]` — the
/// doubled full-set appends [`Self::ALL`] to itself, every variant
/// hits count `2` (all repeating), [`Self::count_repeating_variants`]
/// reports `T::CARDINALITY >= 2`,
/// [`Self::has_unique_repeating_variant`] returns `false` via
/// `T::CARDINALITY != 1`, and the guard collapses the projection to
/// `vec![]`. At cardinality `== 1` the doubled slice `[T::ALL[0],
/// T::ALL[0]]` collapses the strict-repeat count to `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, guard fires,
/// and the guarded lex-lift returns `vec![T::ALL[0]]` (the SOLE
/// positive arm on the degenerate cardinality-1 corner of the
/// doubled-full-set fixture).
///
/// Bimodal-triple contract at cardinality `== 3`:
/// `T::sorted_unique_repeating_variants([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == vec![T::ALL[0]]` — the LOAD-BEARING SOLE non-empty
/// arm at the canonical cardinality-3 window. `T::ALL[0]` at count `2`
/// (the SOLE strict-repeat witness), `T::ALL[1]` at count `1`
/// (unique-band, not strict-repeat), `T::ALL[2]` at count `0` (miss-
/// band, not strict-repeat); [`Self::count_repeating_variants`]
/// reports `1`, [`Self::has_unique_repeating_variant`] returns `true`,
/// the guard fires, and [`Self::sorted_repeating_variants`]'s lex-
/// order sweep hits `T::ALL[0]` as its sole strict-repeat variant.
/// LOAD-BEARING DISCRIMINATOR from the sibling declaration-order
/// corner [`Self::unique_repeating_variants`] which reports the SAME
/// witness `vec![T::ALL[0]]` on the SAME fixture (the ordering-choice-
/// irrelevance identity in action — strict-repeat uniqueness pins the
/// witness before either sweep-order kicks in) AND from the just-
/// opened miss-band lex-peer [`Self::sorted_unique_missing_variants`]
/// which reports `vec![T::ALL[2]]` on the SAME fixture (the
/// MULTIPLICITY-BAND axis SEPARATES the strict-repeat positive arm
/// from the miss-band positive arm on the shared canonical fixture
/// window: the two POSITIVE arms report DIFFERENT witnesses on the
/// same slice, pinning the (mult `>= 2`) and (mult `== 0`) bands as
/// orthogonal uniqueness axes with disjoint witness projections
/// riding DIFFERENT variants of the CANONICAL bimodal triple).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_repeating_variant`] +
/// [`Self::sorted_repeating_variants`] via a boolean-guarded Vec-
/// select on `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_repeating_variants`] reduction for the guard via
/// [`Self::is_repeated_occurrence_of`], one
/// [`Self::sorted_repeating_variants`] filter sweep over
/// [`Self::sorted_variants`] when the guard holds; the short-
/// circuiting `if` avoids the sweep AND the Vec allocation when the
/// guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_repeating_variants`]: a `tatara-check`
/// predicate `(check-repeating-if-unique-lex …)` that reports the
/// singleton-or-empty lex-order strict-repeat witness collection as a
/// typed `Vec<Self>`-return rather than a two-step composition; a
/// Sekiban audit-trail per-window singleton-or-empty binding stable
/// against upstream declaration-order churn.
///
/// Compounding closure: this projection CLOSES the strict-repeat arm
/// of the LEX-ORDER (`Vec<Self>` × equivalence-partition × mult-band ×
/// unique-tie) row past the just-opened (mult `== 0`) miss-band arm
/// [`Self::sorted_unique_missing_variants`] one MULTIPLICITY-BAND axis
/// over on the EQUIVALENCE-PARTITION surface. The natural next lift
/// past this corner is the (mult `== 1`) unique-band arm
/// `sorted_unique_unique_variants` (guarded lift of
/// [`Self::sorted_unique_variants`] under
/// [`Self::has_unique_unique_variant`]) which EXHAUSTIVELY CLOSES the
/// LEX-ORDER trichotomy row at its FINAL third tile AND EXHAUSTIVELY
/// CLOSES the (`Vec<Self>` × equivalence-partition × mult-band ×
/// ordering × unique-tie) 3×2 face at its SIXTH tile.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Vec<Self>` × sorted × equivalence-partition × mult
/// `>= 2` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_repeating_variant(items) { T::sorted_repeating_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Vec<Self>` × mult `>= 2` × unique-tie) corner was an
/// unnamed inline composition — or silently absent because callers
/// reached for the declaration-order sibling without proof of
/// coincidence — recurring at every prospective downstream "the sole
/// strict-repeat variant, as a Vec, in lex order, if it's
/// unambiguous" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of TWO
/// substrate primitives ([`Self::has_unique_repeating_variant`] +
/// [`Self::sorted_repeating_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); rep <- sort(names(t)[t >= 2]); if (length(rep) == 1) rep else character(0) }`
/// — the canonical guarded-strict-repeat lex-order singleton-or-empty
/// carrier on a factor histogram; Clojure's
/// `(let [rep (sort (keys (filter #(>= (val %) 2) (frequencies coll))))] (if (= 1 (count rep)) [(first rep)] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) >= 2 ORDER BY variant) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order strict-repeat singleton-or-empty
/// projection on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_repeating_variant`] guard conjoined with the
/// just-lifted [`Self::sorted_repeating_variants`] witness-collection
/// under a Vec-select — no new dep, no supertrait bound,
/// `O(T::CARDINALITY * n)` inherited from the underlying aggregates
/// with short-circuiting on the guard.
fn sorted_unique_repeating_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_repeating_variant(items) {
<Self as ClosedSet>::sorted_repeating_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "the unique unique-band witness in LEX
/// order, as a singleton-or-empty Vec" projection — returns
/// [`Self::sorted_unique_variants`] iff `items` has a UNIQUE unique-
/// band variant ([`Self::has_unique_unique_variant`] holds), else
/// `vec![]`. Computed as the just-lifted set-level unique-band
/// uniqueness bit [`Self::has_unique_unique_variant`] guarding the
/// LEX-ORDER strict-uniqueness witness-collection
/// [`Self::sorted_unique_variants`]: when the guard holds the
/// collection is already a length-`1` Vec by the guard's own
/// definition (`count_unique_variants == 1`) and is lifted verbatim;
/// when the guard falsifies the projection collapses to the EMPTY Vec
/// through a zero-allocation `::std::vec::Vec::new()` short-circuit.
/// The LEX-ORDER `Vec<Self>`-RETURN UNIQUE-BAND UNIQUE-TIE SHARPENING
/// corner EXHAUSTIVELY CLOSING the middle (mult `== 1`) arm of the
/// LEX-ORDER (`Vec<Self>` × equivalence-partition × mult-band ×
/// unique-tie) row AT ITS FINAL THIRD TILE past the (mult `== 0`)
/// miss-band arm [`Self::sorted_unique_missing_variants`] AND the
/// (mult `>= 2`) strict-repeat arm
/// [`Self::sorted_unique_repeating_variants`] one MULTIPLICITY-BAND
/// axis over on the EQUIVALENCE-PARTITION surface — the row is now
/// the CANONICAL LEX-ORDER `Vec<Self>`-return unique-tie sharpening
/// on the equivalence-partition surface, closed at its FINAL third
/// tile AND EXHAUSTIVELY CLOSING the (`Vec<Self>` × equivalence-
/// partition × mult-band × ordering × unique-tie) 3×2 face at its
/// SIXTH tile. Peer to [`Self::unique_unique_variants`] one ORDERING
/// axis over (declaration-order → lex-order unique-band witness-
/// collection-when-unique) AND peer to
/// [`Self::sorted_unique_variants`] one UNIQUE-TIE-SHARPENING axis
/// over (unsharpened lex-order strict-uniqueness witness-collection →
/// uniqueness-gated lex-order unique-band witness-collection) AND
/// peer to [`Self::sorted_unique_unique_variant`] one RETURN-SHAPE
/// axis over (Option-return lex-first-witness-when-unique → Vec-
/// return singleton-or-empty-when-unique). Not a fresh substrate
/// primitive on the index axis — the projection emerges from the
/// boolean-guarded selection of the LEX-ORDER strict-uniqueness
/// witness-collection under the set-level unique-band uniqueness bit,
/// collapsing to the empty Vec through the guard-arm when the bit
/// falsifies.
///
/// Ordering-choice-irrelevance identity: for every slice `items`,
/// `T::sorted_unique_unique_variants(items) ==
/// T::unique_unique_variants(items)` — when the sole unique-band
/// variant is UNIQUE ([`Self::has_unique_unique_variant`] holds) the
/// underlying [`Self::sorted_unique_variants`] and
/// [`Self::unique_variants`] each collapse to a length-`1` Vec
/// containing THE SAME sole unique-band variant (uniqueness pins the
/// sole witness before any ordering choice is consulted); when the
/// guard falsifies both projections collapse to `vec![]` through the
/// same guard arm. The LEX peer is thus IDENTICALLY equal to its
/// declaration-order sibling on every input — the search-order axis
/// becomes provably irrelevant WHEN the underlying uniqueness bit
/// holds. Pinned by
/// `sorted_unique_unique_variants_equals_unique_unique_variants_across_every_triple`
/// as a TYPED THEOREM the substrate proves once, replacing per-
/// consumer inline re-derivations of the equivalence.
///
/// Guarded-lex-witness-collection identity: for every slice `items`,
/// `T::sorted_unique_unique_variants(items) ==
/// if T::has_unique_unique_variant(items) { T::sorted_unique_variants(items) }
/// else { vec![] }` — the canonical form the body uses. Pinned by
/// `sorted_unique_unique_variants_equals_has_unique_unique_variant_gated_sorted_unique_variants_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::sorted_unique_unique_variants(items).len() ==
/// usize::from(T::has_unique_unique_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level unique-band uniqueness
/// bit projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds. Pinned by
/// `sorted_unique_unique_variants_len_equals_has_unique_unique_variant_as_usize_across_every_triple`.
///
/// Option-equality identity: for every slice `items`,
/// `T::sorted_unique_unique_variants(items).first().copied() ==
/// T::sorted_unique_unique_variant(items)` — the `Vec`-return's
/// first-element projection COINCIDES with the `Option`-return LEX
/// peer one RETURN-SHAPE axis over, since both encode the same "sole
/// unique-band witness if unique, else nothing" semantics through
/// different return shapes. Pinned by
/// `sorted_unique_unique_variants_first_equals_sorted_unique_unique_variant_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::sorted_unique_unique_variants(items).is_empty() ==
/// !T::has_unique_unique_variant(items)` — the return-Vec's
/// emptiness coincides with the NEGATION of the set-level unique-
/// band uniqueness bit. Independent cross-check on the surface axis
/// distinct from the length-coincidence arm (Vec::is_empty vs integer
/// equality). Pinned by
/// `sorted_unique_unique_variants_is_empty_iff_not_has_unique_unique_variant_across_every_triple`.
///
/// Reversal-invariance identity: the projection factors through
/// [`Self::has_unique_unique_variant`] (ordering-agnostic — the
/// underlying [`Self::count_unique_variants`] is invariant under
/// slice-reversal via [`Self::count_occurrences_of`]) and
/// [`Self::sorted_unique_variants`] (ordering-agnostic on the input
/// axis — the underlying [`Self::is_unique_occurrence_of`] filter
/// over [`Self::sorted_variants`] is invariant under slice-reversal)
/// via a boolean-guarded Vec-select. Pinned by
/// `sorted_unique_unique_variants_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_unique_unique_variants(&[]) ==
/// vec![]` UNCONDITIONALLY — the empty slice hits zero positions,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false` via `0 != 1`,
/// and the guard collapses the projection to `vec![]` through the
/// guard arm before the underlying witness-collection filter is
/// consulted.
///
/// Matching-singleton contract: on every variant `v`,
/// `T::sorted_unique_unique_variants(&[v]) == vec![v]` — the target
/// hits count `1` (the SOLE unique-band witness), every non-target
/// sits at count `0` (miss-band, not unique-band);
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] holds, and the guarded lex-
/// lift returns the singleton `vec![v]`. LOAD-BEARING NON-EMPTY
/// DEGENERATE ARM at the singleton fixture — distinct from
/// [`Self::sorted_unique_missing_variants`] (collapses to `vec![]` at
/// CARDINALITY `<= 2` on the same singleton) AND
/// [`Self::sorted_unique_repeating_variants`] (collapses to `vec![]`
/// unconditionally on every singleton).
///
/// Full-set contract: `T::sorted_unique_unique_variants(<T as
/// ClosedSet>::ALL)` is `T::sorted_variants()` iff
/// [`Self::CARDINALITY`] `== 1`, else `vec![]` — the pairwise-
/// distinctness invariant pins every variant at exactly one position,
/// every per-target multiplicity is `1`,
/// [`Self::count_unique_variants`] reports [`Self::CARDINALITY`],
/// [`Self::has_unique_unique_variant`] holds EXACTLY when
/// [`Self::CARDINALITY`] `== 1`. At `T::CARDINALITY == 1` the guarded
/// lex-lift returns `vec![T::ALL[0]]` (the sole unique-band witness);
/// at `T::CARDINALITY >= 2` every variant is a unique-band witness,
/// uniqueness fails, and the guard collapses to `vec![]`.
///
/// Doubled-full-set contract: `T::sorted_unique_unique_variants(&doubled)
/// == vec![]` UNCONDITIONALLY — appending a full-set copy hits every
/// variant at multiplicity `2`, every per-target `== 1` test fails,
/// [`Self::count_unique_variants`] reports `0`,
/// [`Self::has_unique_unique_variant`] returns `false`, and the guard
/// collapses to `vec![]`.
///
/// Bimodal-triple contract at cardinality `== 3`:
/// `T::sorted_unique_unique_variants([T::ALL[0], T::ALL[0],
/// T::ALL[1]]) == vec![T::ALL[1]]` — the LOAD-BEARING SOLE non-empty
/// arm at the canonical cardinality-3 window. `T::ALL[0]` at count
/// `2` (strict-repeat), `T::ALL[1]` at count `1` (the SOLE unique-
/// band witness), `T::ALL[2]` at count `0` (miss-band);
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] holds, guard fires, and
/// [`Self::sorted_unique_variants`]'s lex-order sweep hits `T::ALL[1]`
/// as its sole unique-band variant. LOAD-BEARING DISCRIMINATOR from
/// the sibling declaration-order corner
/// [`Self::unique_unique_variants`] which reports the SAME witness
/// `vec![T::ALL[1]]` on the SAME fixture (the ordering-choice-
/// irrelevance identity in action — unique-band uniqueness pins the
/// witness before either sweep-order kicks in) AND from the just-
/// opened miss-band lex-peer [`Self::sorted_unique_missing_variants`]
/// which reports `vec![T::ALL[2]]` AND the just-closed strict-repeat
/// lex-peer [`Self::sorted_unique_repeating_variants`] which reports
/// `vec![T::ALL[0]]` on the SAME fixture (the MULTIPLICITY-BAND axis
/// EXHAUSTIVELY SEPARATES the three lex positive arms at DIFFERENT
/// witnesses of the same canonical bimodal triple, pinning the
/// trichotomy of multiplicity bands as orthogonal uniqueness axes
/// with disjoint witness projections riding THREE DIFFERENT variants
/// of the CANONICAL bimodal triple).
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::has_unique_unique_variant`] +
/// [`Self::sorted_unique_variants`] via a boolean-guarded Vec-select
/// on `Vec<Self>`. Cost inherits both underlying projections:
/// `O(T::CARDINALITY * n)` on slice arity `n` (one
/// [`Self::count_unique_variants`] reduction for the guard via
/// [`Self::count_occurrences_of`], one
/// [`Self::sorted_unique_variants`] filter sweep over
/// [`Self::sorted_variants`] when the guard holds; the short-
/// circuiting `if` avoids the sweep AND the Vec allocation when the
/// guard falsifies) + `O(T::CARDINALITY log T::CARDINALITY)` for the
/// [`Self::sorted_variants`] cache, no `PartialEq`/`Eq`/`Hash`
/// supertrait bound (the trait's minimal `Sized + Copy + 'static`
/// supertrait pair stays untouched).
///
/// Future consumers that compose against
/// [`Self::sorted_unique_unique_variants`]: a `tatara-check`
/// predicate `(check-unique-if-unique-lex …)` that reports the
/// singleton-or-empty lex-order unique-band witness collection as a
/// typed `Vec<Self>`-return rather than a two-step composition; a
/// Sekiban audit-trail per-window singleton-or-empty binding stable
/// against upstream declaration-order churn.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// middle (mult `== 1`) arm of the LEX-ORDER (`Vec<Self>` ×
/// equivalence-partition × mult-band × unique-tie) row AT ITS FINAL
/// THIRD TILE past the (mult `== 0`) miss-band arm
/// [`Self::sorted_unique_missing_variants`] AND the (mult `>= 2`)
/// strict-repeat arm [`Self::sorted_unique_repeating_variants`] one
/// MULTIPLICITY-BAND axis over on the EQUIVALENCE-PARTITION surface.
/// The (`Vec<Self>` × equivalence-partition × mult-band × ordering ×
/// unique-tie) 3×2 face is now EXHAUSTIVELY CLOSED at its SIXTH
/// tile — three lex-order corners
/// ([`Self::sorted_unique_missing_variants`],
/// [`Self::sorted_unique_unique_variants`],
/// [`Self::sorted_unique_repeating_variants`]) mirror three
/// declaration-order corners ([`Self::unique_missing_variants`],
/// [`Self::unique_unique_variants`],
/// [`Self::unique_repeating_variants`]) each pinning the ordering-
/// choice-irrelevance identity as a TYPED THEOREM. The natural next
/// lifts past this exhaustive face closure are the per-target
/// `is_sorted_unique_*_variant_of` LEX peers one ARITY axis over,
/// each of which projects the same guarded-lex predicate onto a
/// specific target variant.
///
/// Theory anchor: THEORY.md §II.1 — the Rust + Lisp pattern; the
/// (set-level × `Vec<Self>` × sorted × equivalence-partition × mult
/// `== 1` × unique-tie) corner becomes a TYPED WITNESS on the
/// ClosedSet trait rather than a per-consumer inline
/// `if T::has_unique_unique_variant(items) { T::sorted_unique_variants(items) } else { vec![] }`
/// re-derivation. THEORY.md §III — the typescape; a fresh TYPE-level
/// primitive plus a typed THEOREM (ordering-choice-irrelevance) the
/// substrate proves once. THEORY.md §V.1 — knowable platform; the
/// (lex-order × `Vec<Self>` × mult `== 1` × unique-tie) corner was
/// an unnamed inline composition — or silently absent because
/// callers reached for the declaration-order sibling without proof of
/// coincidence — recurring at every prospective downstream "the sole
/// unique-band variant, as a Vec, in lex order, if it's unambiguous"
/// site pre-lift. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the composition of TWO substrate
/// primitives ([`Self::has_unique_unique_variant`] +
/// [`Self::sorted_unique_variants`]) with the
/// `if _ { _ } else { vec![] }` combinator on `Vec<Self>`.
///
/// Frontier inspiration: R's
/// `{ t <- table(items); s <- sort(names(t)[t == 1]); if (length(s) == 1) s else character(0) }`
/// — the canonical guarded-unique-band lex-order singleton-or-empty
/// carrier on a factor histogram; Clojure's
/// `(let [ss (sort (keys (filter #(= (val %) 1) (frequencies coll))))] (if (= 1 (count ss)) [(first ss)] []))`;
/// SQL's
/// `SELECT ARRAY(SELECT variant FROM t GROUP BY variant HAVING COUNT(*) = 1 ORDER BY variant) WHERE cardinality(…) = 1`.
/// Translation through pleme-io primitives: the N-ary set-level
/// uniqueness-gated lex-order unique-band singleton-or-empty
/// projection on the closed-set trait binds through the just-lifted
/// [`Self::has_unique_unique_variant`] guard conjoined with the
/// [`Self::sorted_unique_variants`] witness-collection under a Vec-
/// select — no new dep, no supertrait bound, `O(T::CARDINALITY * n)`
/// inherited from the underlying aggregates with short-circuiting on
/// the guard.
fn sorted_unique_unique_variants(items: &[Self]) -> ::std::vec::Vec<Self> {
if <Self as ClosedSet>::has_unique_unique_variant(items) {
<Self as ClosedSet>::sorted_unique_variants(items)
} else {
::std::vec::Vec::new()
}
}
/// The N-ARY ORDERING-AGNOSTIC "every variant repeats?" predicate —
/// `true` iff EVERY variant of [`Self::ALL`] appears AT LEAST TWICE
/// in `items`, computed as the just-lifted set-level scalar
/// [`Self::min_variant_count`] projection's lower-bound test against
/// `2`. The BOOL-RETURN closer on the (set-level × bool × universal-
/// lift × multiplicity-band) 4th-axis hypercube at the universal-
/// lift `>= 2` corner peer to the pre-existing (set-level × bool ×
/// universal-lift × multiplicity-band `>= 1`) [`Self::is_covering`]
/// corner one MULTIPLICITY-BAND axis over AND peer to the pre-
/// existing (set-level × bool × universal-lift × multiplicity-band
/// `<= 1`) [`Self::is_pairwise_distinct`] corner one MULTIPLICITY-
/// BAND axis over on the SAME universal-lift arm of the quantifier
/// axis, AND the direct SET-LEVEL UNIVERSAL PEER of the (set-level
/// × bool × existential-lift × multiplicity-band `>= 2`)
/// [`Self::is_repeating_any`] corner one QUANTIFIER axis over on
/// the SAME multiplicity band. Not a fresh substrate primitive on
/// the index axis — the predicate emerges from ONE lower-bound
/// scalar comparison against the substrate's just-lifted set-level
/// least-common-multiplicity aggregate.
///
/// Min-composition identity: for every slice `items`,
/// `T::is_uniformly_repeating(items) == (T::min_variant_count(items) >= 2)`
/// — the set-level universal-lift repeat predicate is EXACTLY the
/// lower-bound test of the least-common-multiplicity aggregate
/// against `2`. The canonical form the body uses. Pinned by
/// `is_uniformly_repeating_agrees_with_min_variant_count_ge_two_across_every_triple`.
///
/// Universal-lift identity: for every slice `items`,
/// `T::is_uniformly_repeating(items) == <T as ClosedSet>::ALL.iter().all(|&v| T::count_occurrences_of(v, items) >= 2)`
/// — the set-level bool predicate is the EXACT universal
/// quantification over [`Self::ALL`] of the per-target multiplicity-
/// `>= 2` predicate. This identity binds the set-level ARITY axis
/// against the per-target ARITY axis one arity axis over on the
/// (arity × mult-band × quantifier) face, pinning the compounding
/// closure the prior per-target lifts opened as the universal peer
/// to the existential `is_repeating_any` corner. Pinned by
/// `is_uniformly_repeating_equals_universal_of_is_repeated_occurrence_of_across_every_triple`.
///
/// Histogram-arm identity: for every slice `items`,
/// `T::is_uniformly_repeating(items) == <T as ClosedSet>::variant_counts(items).iter().all(|&c| c >= 2)`
/// — the set-level bool predicate is EXACTLY the universal test
/// against `>= 2` over the per-slot histogram vector. Independent
/// cross-check distinct from the min-composition + universal-lift
/// arms on the return-shape (`Vec<usize>` vs the per-target
/// `usize` multiplicity vs the set-level `usize` min-bar) axis.
/// Pinned by
/// `is_uniformly_repeating_agrees_with_variant_counts_all_ge_two_across_every_triple`.
///
/// De Morgan decomposition identity: for every slice `items`,
/// `T::is_uniformly_repeating(items) == (T::is_covering(items) && !T::is_unique_any(items))`
/// — the universal-lift `>= 2` predicate factors EXACTLY through
/// the conjunction of (i) universal-lift `>= 1` ([`Self::is_covering`]:
/// every variant hit at least once) AND (ii) negated existential
/// `== 1` ([`Self::is_unique_any`]: no variant hit exactly once).
/// Covering rules out (mult `== 0`) at every variant; negating
/// any-unique rules out (mult `== 1`) at every variant; together
/// they force every variant into the strict (mult `>= 2`) band.
/// This identity threads THIS predicate through the trichotomy
/// (mult `== 0`, mult `== 1`, mult `>= 2`) as the UNIVERSAL COMPLEMENT
/// of the two lower bands' existential lifts — the same trichotomy
/// [`Self::is_missing_any`], [`Self::is_unique_any`],
/// [`Self::is_repeating_any`] partition on the existential arm.
/// Pinned by
/// `is_uniformly_repeating_equals_covering_and_not_unique_any_across_every_triple`.
///
/// Empty-slice contract: `T::is_uniformly_repeating(&[])` is `false`
/// UNCONDITIONALLY — the empty slice hits zero positions, so every
/// per-variant multiplicity is `0`, and [`Self::min_variant_count`]
/// on the empty slice is `0`, so `0 >= 2` is `false`. The empty-
/// slice arm is LOAD-BEARING as the drift catch for an override
/// that folds onto `true` unconditionally. Pinned by clause (121)
/// and by
/// `is_uniformly_repeating_returns_false_on_the_empty_slice_across_every_kind`.
///
/// Full-set contract: `T::is_uniformly_repeating(<T as ClosedSet>::ALL)`
/// is `false` on every implementor of non-zero cardinality — the
/// closed-set well-formedness invariant
/// [`assert_closed_set_well_formed`]'s clause (3) pins variants as
/// pairwise distinct, so every variant of [`Self::ALL`] appears at
/// EXACTLY ONE position in the full-set slice; every per-variant
/// multiplicity is `1`, [`Self::min_variant_count`] on the full set
/// is `1`, and `1 >= 2` is `false`. The full-set arm is LOAD-BEARING
/// as the drift catch for an override that folds onto `true`
/// unconditionally, AND is the boundary that separates this strict
/// (mult `>= 2`) universal-lift predicate from the weaker (mult
/// `>= 1`) universal-lift predicate [`Self::is_covering`], which is
/// `true` on the full set. Pinned by clause (121) and by
/// `is_uniformly_repeating_returns_false_on_the_full_set_across_every_kind`.
///
/// Doubled-full-set contract: `T::is_uniformly_repeating(&doubled)`
/// is `true` on every implementor of non-zero cardinality — the
/// doubled full set appends [`Self::ALL`] to itself, so every variant
/// appears at EXACTLY TWO positions, [`Self::min_variant_count`] on
/// the doubled full set is `2`, and `2 >= 2` is `true`. Together
/// with the full-set arm (which pins the `false` fixpoint at
/// cardinality `>= 1`), the doubled-full-set arm demonstrates that
/// the predicate TRANSITIONS from `false` (at the canonical
/// permutation) to `true` (at the canonical repetition) purely
/// through the per-variant multiplicity band change — pinning the
/// projection as a strict `>= 2` predicate AND is the LOAD-BEARING
/// drift catch for an override that folds onto `false`
/// unconditionally. Pinned by clause (121) at the doubled-full-set
/// fixpoint AND by
/// `is_uniformly_repeating_returns_true_on_the_doubled_full_set_across_every_non_degenerate_kind`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic — the (declaration, lex) axis COLLAPSES on
/// this predicate because it factors through
/// [`Self::min_variant_count`] (itself ordering-agnostic via
/// [`Self::count_occurrences_of`]) via a scalar-comparison. No
/// separate `sorted_is_uniformly_repeating` peer is needed. Pinned
/// by
/// `is_uniformly_repeating_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Signature note: the projection is a typed CONSEQUENCE of
/// [`Self::min_variant_count`] via a scalar `>= 2` comparison. The
/// cost is O(T::CARDINALITY * n) on slice arity `n` (inherited from
/// the min-bar aggregate's per-target multiplicity sum), allocation-
/// free, no `PartialEq`/`Eq`/`Hash` supertrait bound (the trait's
/// minimal `Sized + Copy + 'static` supertrait pair stays untouched),
/// no histogram-carrier allocation (the bool-return shape is a bare
/// `bool` scalar without materializing the intermediate `Vec<usize>`
/// histogram).
///
/// Future consumers that compose against
/// [`Self::is_uniformly_repeating`]: a `tatara-check` predicate
/// `(check-phases-every-visited-twice …)` on a `WorkloadPhase`
/// sequence that flags "every phase visited at least twice" (a
/// resilience-cycle witness distinct from a single-pass rollout OR
/// a partially-repeated churn) without paying for the full histogram
/// when only the min-bar's `>= 2` band matters; an LSP diagnostic
/// on a Lisp-author-written variant-list that flags "every variant
/// appears at least twice" as a redundancy-completeness hint
/// distinct from full-coverage OR any-repetition; a Sekiban audit-
/// trail metric flagging a classification poset window as
/// "every-classification-doubly-witnessed" WITHOUT emitting the
/// per-slot histogram; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that flags a template's identifier multiset as
/// UNIFORMLY-BOUND (every binding used at least twice — the shape
/// of a "no-linear-use" lint distinct from unbound OR singly-used
/// identifiers) in ONE typed bool. Each binds to ONE typed N-ary
/// universal-repeat predicate on the trait rather than re-deriving
/// the `T::ALL.iter().all(|v| T::count_occurrences_of(v, items) >= 2)`
/// conjunction OR the `T::variant_counts(items).iter().all(|&c| c >= 2)`
/// histogram-arm inline per callsite.
///
/// Compounding closure: the (set-level × bool × quantifier ×
/// multiplicity-band) 4th-axis hypercube on the equivalence-
/// partition surface now CLOSES at three universal-lift corners
/// across the (mult `<= 1`, mult `>= 1`, mult `>= 2`) partition of
/// the multiplicity-band axis — [`Self::is_pairwise_distinct`]
/// (universal-lift `<= 1`), [`Self::is_covering`] (universal-lift
/// `>= 1`), and THIS PREDICATE (universal-lift `>= 2`). The three
/// existential-lift corners across the same partition
/// ([`Self::is_missing_any`] at `== 0`, [`Self::is_unique_any`] at
/// `== 1`, [`Self::is_repeating_any`] at `>= 2`) now bind against
/// their universal peers through the standard `∀/∃` duality: the
/// universal at each band is the negation of the existential at the
/// complementary band (universal `<= 1` = not existential `>= 2`;
/// universal `>= 1` = not existential `== 0`; universal `>= 2` =
/// not existential `<= 1` = not (existential `== 0` or existential
/// `== 1`)). The natural next lift past this closure is the
/// (set-level × usize × universal × mult `>= 2`) sharpening —
/// `count_uniformly_repeating_bar` (the min-bar itself, which is
/// `>= 2` iff this predicate holds; equivalently
/// `T::min_variant_count(items)` above the `>= 2` threshold), or
/// the (set-level × bool × universal × mult `== 0`) corner
/// `is_uniformly_missing` (∀v : count(v) == 0, equivalently
/// `items.is_empty()` on a non-degenerate carrier).
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// universal-repeat predicate becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline universal
/// over the per-target multiplicity-`>= 2` predicate at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (set-level × bool × universal × mult `>= 2`) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "does every variant occur at least twice?" site pre-
/// lift. Naming it on the trait makes the predicate a TYPED
/// CONSEQUENCE of the substrate's set-level least-common-
/// multiplicity aggregate lifted through a `>= 2` scalar comparison
/// — AND closes the (set-level × bool × universal × multiplicity-
/// band) hypercube corner as a TYPED THEOREM the substrate proves
/// once. THEORY.md §VI.1 — generation over composition; the
/// uniform-repeat predicate emerges from the composition of ONE
/// substrate primitive ([`Self::min_variant_count`]) with a `usize`-
/// scalar comparison, not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Coq's `forallb (fun v => 2 <=? count_occ
/// eqb l v) all` decidable-equality-derived universal-repeat test
/// on `list nat`; Idris's `all (\v => count (== v) items >= 2)
/// all` on a `Vect n a`; Racket's `(andmap (λ (v) (>= (count (λ
/// (w) (equal? v w)) items) 2)) all)`; Julia's `all(v -> count(==(v),
/// items) >= 2, all)`; Haskell's `all (\v -> length (filter (== v)
/// items) >= 2) all`; Rust's own `T::ALL.iter().all(|v|
/// items.iter().filter(|w| v == w).count() >= 2)` binds through a
/// `Self: PartialEq` supertrait bound; Python's
/// `all(items.count(v) >= 2 for v in all)`; SQL's
/// `NOT EXISTS (SELECT 1 FROM t GROUP BY variant HAVING COUNT(*) < 2)`
/// — the canonical set-level
/// universal-repeat witness. Translation through pleme-io primitives:
/// the N-ary universal-repeat predicate on the closed-set trait
/// binds through the set-level least-common-multiplicity aggregate
/// [`Self::min_variant_count`] under a `usize`-scalar `>= 2`
/// comparison — no new dep, no supertrait bound (the substrate
/// primitive replaces the `Eq`/`Hash` bound the standard-library
/// universal/group-by signatures demand), no set-shape carrier, no
/// allocation.
fn is_uniformly_repeating(items: &[Self]) -> bool {
<Self as ClosedSet>::min_variant_count(items) >= 2
}
/// The N-ARY DECLARATION-ORDER "present labels" projection — the
/// `Vec<&'static str>` label rendering of [`Self::present_variants`]
/// under [`Self::label`]. Every label `s` in the returned vector is
/// the canonical [`Self::label`] rendering of some variant present
/// in `items`; the declaration order of [`Self::present_variants`]
/// is preserved verbatim.
///
/// Sibling posture to [`Self::present_variants`] one return-shape
/// axis over on the (`Vec<Self>` typed-variant witness,
/// `Vec<&'static str>` label witness) partition of the equivalence-
/// partition surface — the typed-variant arm materializes each hit
/// slot as `Self`, this method labels each slot under
/// [`Self::label`]. The two projections share the (present) partition
/// arm AND the declaration-order ordering; they differ only on the
/// return-shape column, where the typed-variant arm returns the
/// carrier and the label arm returns the rendering.
///
/// Sibling posture to [`Self::interior_labels`] one partition-flavor
/// axis over on the (interior, present) partition of the closed-set
/// declaration-axis label-aggregation surface — [`Self::interior_labels`]
/// aggregates every strictly-interior label into a `Vec<&'static str>`
/// collection over the STATIC boundary-partition of [`Self::ALL`];
/// this method aggregates every present label into a
/// `Vec<&'static str>` collection over the DYNAMIC equivalence-
/// partition of an N-ary input slice.
///
/// Cardinality identity: for every slice `items`,
/// `T::present_labels(items).len() == T::count_distinct(items)` —
/// the label-Vec-return present-arm projection's length matches the
/// usize-return present-arm count exactly, and matches
/// [`Self::present_variants`]'s length one return-shape column over.
/// Pinned by
/// `present_labels_length_equals_count_distinct_across_every_triple`.
///
/// Bool-projection identities: for every slice `items`,
/// * `T::present_labels(items).len() == T::CARDINALITY` iff
/// `T::is_covering(items)` — the hit-set label list covers every
/// variant iff the covering predicate holds;
/// * `T::present_labels(items).is_empty()` iff `items.is_empty()` —
/// the hit-set label list is empty iff the input slice is empty.
///
/// Composition law: for every slice `items`,
/// `T::present_labels(items) ==
/// T::present_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::present_variants`] Vec-return primitive composed with the
/// per-slot [`Self::label`] projection. Pinned by
/// `present_labels_equals_present_variants_mapped_under_label_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items` preserves
/// its multiset of variant identities, and the hit-set membership
/// predicate is a function of that multiset alone. The OUTPUT
/// ordering is fixed by [`Self::ALL`]'s declaration order regardless
/// of the input ordering. Pinned by
/// `present_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::present_labels(&[])` is the empty
/// `Vec` UNCONDITIONALLY. Full-set contract:
/// `T::present_labels(<T as ClosedSet>::ALL) == T::labels()` — the
/// full-set hit-set labels equal the substrate's declaration-order
/// label listing exactly. Both pinned across every kind.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// touched-labels …)` that renders the concrete list of
/// `WorkloadPhase` labels a rollout window HIT (not just their typed
/// witnesses); an LSP completion pin that renders the present labels
/// as an author-facing "already-selected" hint; a Sekiban audit-
/// trail projection that carries the concrete hit-label set of a
/// classification poset window as its per-window witness; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that lists the
/// vocabulary identifiers a template DID bind. Each binds to ONE
/// typed N-ary hit-witness label projection on the trait rather
/// than re-deriving the `present_variants + label + map + collect`
/// four-primitive composition inline per callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize, Vec-
/// variant, Vec-label) 2×4 = 8-corner partition-arm × return-shape
/// face on the equivalence-partition surface now opens the label-
/// return column at the (present, label) corner alongside the
/// pre-existing [`Self::is_covering`], [`Self::count_distinct`],
/// [`Self::present_variants`] on the present arm; the sibling
/// [`Self::missing_labels`] peer closes the (absent, label) corner.
/// The next natural lift on this surface — the (declaration, lex)
/// ordering axis: `sorted_present_labels` and `sorted_missing_labels`
/// peers walking [`Self::sorted_present_variants`] and
/// [`Self::sorted_missing_variants`] instead of the declaration-axis
/// Vec-return peers.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary hit-
/// label projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline
/// `T::present_variants(items).into_iter().map(T::label).collect()`
/// four-primitive composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (present-Vec-label)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which labels did we HIT?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the hit-label
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::present_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Coq's `map label (filter (fun v => existsb
/// (Nat.eqb (index v)) items) all)` composing the hit-set filter
/// with a `map` under `label`; Racket's `(map T-label (filter
/// (lambda (v) (member v items)) (enum->list T)))`; NumPy's
/// `[label[i] for i in np.intersect1d(all_indices, item_indices)]`.
/// Translation through pleme-io primitives: a pure default method
/// mapping the trait's existing [`Self::present_variants`] Vec-return
/// primitive under the per-slot [`Self::label`] projection — no new
/// dep, no supertrait bound, no set-shape carrier.
fn present_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::present_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "present labels joined" projection —
/// the `String` rendering of [`Self::present_labels`] joined by
/// `sep`. Composes the substrate's declaration-axis hit-label
/// Vec-return primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of [`Self::present_labels`]
/// automatically satisfies this projection at every downstream
/// site.
///
/// Sibling posture to [`Self::interior_labels_joined`] one
/// partition-flavor axis over on the (interior, present) partition
/// of the closed-set declaration-axis label-as-string surface —
/// [`Self::interior_labels_joined`] renders the STATIC strictly-
/// interior partition of [`Self::ALL`] under the caller's
/// separator, this method renders the DYNAMIC present partition of
/// an N-ary input slice under the same separator. Sibling posture
/// to [`Self::present_labels`] one return-shape axis over on the
/// (`Vec<&'static str>`, `String`) partition of the equivalence-
/// partition label-aggregation surface — the Vec-return arm
/// materializes each hit slot as a `&'static str`, this method
/// joins them into a single `String` under the caller's separator.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::present_labels_joined(items, sep) ==
/// T::present_labels(items).join(sep)` — the join-string projection
/// binds through the substrate's [`Self::present_labels`] Vec-return
/// primitive composed with `slice::join`. Pinned by
/// `present_labels_joined_equals_present_labels_dot_join_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items` preserves
/// its multiset of variant identities, and the hit-set membership
/// predicate is a function of that multiset alone. The OUTPUT
/// ordering is fixed by [`Self::ALL`]'s declaration order regardless
/// of the input ordering. Pinned by
/// `present_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::present_labels_joined(&[], sep)` is
/// the empty `String` UNCONDITIONALLY for every `sep` — the empty
/// slice hits zero variants, and `slice::join` on an empty slice
/// yields the empty string. Full-set contract:
/// `T::present_labels_joined(<T as ClosedSet>::ALL, sep) ==
/// T::labels_joined(sep)` — the full-set hit-labels join equals the
/// substrate's declaration-order labels join exactly under any
/// separator.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window HIT as author-
/// facing text (`"touched phases: bootstrap, warmup, ready"`); an
/// LSP completion pin that renders the present labels of an author-
/// written closed-set field as a comma-joined "already-selected"
/// hint; a Sekiban audit-trail projection whose per-window hit-label
/// witness renders as a deterministic pipe-joined string across
/// machines; a `tatara-lisp::macro_expand::Expander` diagnostic that
/// emits the bound vocabulary identifiers as a slash-joined natural-
/// language surface. Each binds to ONE typed N-ary hit-label-as-
/// string projection on the trait rather than re-deriving
/// `T::present_labels(items).join(sep)` inline per callsite.
///
/// Compounding closure: the (partition-flavor × return-shape) 2×2
/// matrix over the closed-set declaration-axis label-aggregation
/// surface opens the (present × `String`) corner alongside the
/// pre-existing [`Self::present_labels`] on (present × `Vec`) and
/// [`Self::interior_labels_joined`] on (interior × `String`).
/// The natural next lifts on this face — [`Self::missing_labels_joined`]
/// on (absent × `String` × declaration), and their two lex-axis
/// peers `sorted_present_labels_joined` and `sorted_missing_labels_joined`
/// — each bind through their respective sibling Vec-return primitive
/// under the same `slice::join` combinator.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary hit-
/// label-as-string projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::present_labels(items).join(sep)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (present, label, `String`) corner was an unnamed inline
/// composition recurring at every prospective downstream "which
/// labels did we HIT, rendered joined?" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the projection emerges
/// from the composition of ONE substrate primitive
/// ([`Self::present_labels`]) with the standard-library
/// `slice::join` combinator, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label
/// (filter (lambda (v) (member v items)) (enum->list T))) sep)`;
/// Haskell's `intercalate sep (map label (filter (`elem` items)
/// all))` on the `Bounded + Enum + Show` type-class trio; Julia's
/// `join(label.(intersect(all, unique(items))), sep)`. Translation
/// through pleme-io primitives: a pure default method composing
/// [`Self::present_labels`] with `slice::join` — no new dep, no
/// supertrait bound, no set-shape carrier, no allocation beyond
/// the natural `String` allocation [`Self::labels_joined`]'s
/// sibling surface already routes.
fn present_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::present_labels(items).join(sep)
}
/// The N-ARY DECLARATION-ORDER "missing labels" projection — the
/// `Vec<&'static str>` label rendering of [`Self::missing_variants`]
/// under [`Self::label`]. Every label `s` in the returned vector is
/// the canonical [`Self::label`] rendering of some variant ABSENT
/// from `items`; the declaration order of [`Self::missing_variants`]
/// is preserved verbatim. The DE MORGAN dual of
/// [`Self::present_labels`] one partition-arm axis over on the label-
/// return column of the equivalence-partition surface.
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::present_labels`] and
/// [`Self::missing_labels`] (each walking [`Self::ALL`] in
/// declaration order under [`Self::label`]) forms a PARTITION of
/// [`Self::labels`] — the two Vecs are DISJOINT and their union
/// preserves both the declaration-order subsequence property AND
/// [`Self::labels`]'s full membership. Pinned by
/// `present_labels_and_missing_labels_are_disjoint_across_every_triple`
/// and
/// `present_labels_interleaved_with_missing_labels_recovers_labels_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::missing_labels(items).len() == T::count_missing(items)` — the
/// label-Vec-return absent-arm projection's length matches the
/// usize-return absent-arm count exactly, and matches
/// [`Self::missing_variants`]'s length one return-shape column over.
/// Pinned by
/// `missing_labels_length_equals_count_missing_across_every_triple`.
///
/// Bool-projection identity: for every slice `items`,
/// `T::missing_labels(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set label list is empty iff
/// the present-arm predicate holds. Pinned by
/// `missing_labels_is_empty_iff_is_covering_holds_across_every_triple`.
///
/// Composition law: for every slice `items`,
/// `T::missing_labels(items) ==
/// T::missing_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::missing_variants`] Vec-return primitive composed with the
/// per-slot [`Self::label`] projection.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items` preserves
/// its multiset of variant identities. The OUTPUT ordering is fixed
/// by [`Self::ALL`]'s declaration order.
///
/// Empty-slice contract: `T::missing_labels(&[]) == T::labels()`
/// UNCONDITIONALLY — the empty slice hits zero variants, so every
/// variant of [`Self::ALL`] passes the "not present" filter and
/// contributes its label. Full-set contract:
/// `T::missing_labels(<T as ClosedSet>::ALL)` is the empty `Vec`
/// UNCONDITIONALLY — the well-formedness pairwise-distinctness
/// invariant pins every variant of [`Self::ALL`] as hitting itself.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// omitted-labels …)` that renders the concrete list of
/// `WorkloadPhase` labels a rollout window MISSED as author-facing
/// text; an LSP diagnostic on a Lisp-author-written closed-set
/// field that renders the miss-set as an author-facing completion
/// hint (`":severities [:info :warn] — missing: error"`); a
/// Sekiban audit-trail projection that carries the concrete gap-
/// label set of a classification poset window as its per-window
/// witness; a `tatara-lisp::macro_expand::Expander` hygiene pass
/// that reports the exact set of vocabulary identifiers a template
/// FAILED to bind by name. Each binds to ONE typed N-ary miss-
/// witness label projection on the trait rather than re-deriving
/// the `missing_variants + label + map + collect` four-primitive
/// composition inline per callsite.
///
/// Compounding closure: the (present, absent) × (bool, usize, Vec-
/// variant, Vec-label) 2×4 = 8-corner partition-arm × return-shape
/// face on the equivalence-partition surface now closes the
/// declaration-order label-return column — [`Self::present_labels`]
/// on the (present, label) corner + THIS projection on the (absent,
/// label) corner, exhaustively closing the four declaration-order
/// corners past the four (bool, usize, Vec-variant) declaration-
/// order corners this pair sits alongside.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary miss-
/// label projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline
/// `T::missing_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (absent-Vec-label) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "which labels did we MISS?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the miss-label projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::missing_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Coq's `map label (filter (fun v => negb
/// (existsb (Nat.eqb (index v)) items)) all)` composing the miss-
/// set filter with a `map` under `label`; Racket's `(map T-label
/// (filter (lambda (v) (not (member v items))) (enum->list T)))`;
/// Julia's `[label[v] for v in setdiff(all, unique(items))]`;
/// Haskell's `map label (all \\ items)` composition on the
/// `Bounded + Enum + Show` type-class trio. Translation through
/// pleme-io primitives: a pure default method mapping the trait's
/// existing [`Self::missing_variants`] Vec-return primitive under
/// the per-slot [`Self::label`] projection — no new dep, no
/// supertrait bound, no set-shape carrier.
fn missing_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::missing_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "missing labels joined" projection —
/// the `String` rendering of [`Self::missing_labels`] joined by
/// `sep`. Composes the substrate's declaration-axis miss-label
/// Vec-return primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of [`Self::missing_labels`]
/// automatically satisfies this projection at every downstream
/// site. The DE MORGAN dual of [`Self::present_labels_joined`]
/// one partition-arm axis over on the `String`-return column of
/// the equivalence-partition surface, and the DECLARATION-ORDER
/// arm of the (present, absent) × (declaration, lex) 2×2 = 4-corner
/// join-string face this projection closes past its
/// [`Self::present_labels_joined`] sibling.
///
/// Sibling posture to [`Self::missing_labels`] one return-shape
/// axis over on the (`Vec<&'static str>`, `String`) partition of
/// the equivalence-partition label-aggregation surface — the Vec-
/// return arm materializes each miss slot as a `&'static str`, this
/// method joins them into a single `String` under the caller's
/// separator. Sibling posture to [`Self::interior_labels_joined`]
/// one partition-flavor axis over on the (static-interior, dynamic-
/// miss) partition of the closed-set declaration-axis label-as-
/// string surface — [`Self::interior_labels_joined`] renders the
/// STATIC strictly-interior partition of [`Self::ALL`] under the
/// caller's separator, this method renders the DYNAMIC miss
/// partition of an N-ary input slice under the same separator.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::missing_labels_joined(items, sep) ==
/// T::missing_labels(items).join(sep)` — the join-string projection
/// binds through the substrate's [`Self::missing_labels`] Vec-return
/// primitive composed with `slice::join`. Pinned by
/// `missing_labels_joined_equals_missing_labels_dot_join_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items` preserves
/// its multiset of variant identities, and the miss-set membership
/// predicate is a function of that multiset alone. The OUTPUT
/// ordering is fixed by [`Self::ALL`]'s declaration order regardless
/// of the input ordering. Pinned by
/// `missing_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::missing_labels_joined(&[], sep) ==
/// T::labels_joined(sep)` UNCONDITIONALLY for every `sep` — the
/// empty slice hits zero variants, so every label of [`Self::ALL`]
/// passes the "not present" filter and contributes its label to
/// the joined output in declaration order. Full-set contract:
/// `T::missing_labels_joined(<T as ClosedSet>::ALL, sep) == ""`
/// UNCONDITIONALLY — the well-formedness pairwise-distinctness
/// invariant pins every variant as hitting itself, the miss-set
/// is empty, and `slice::join` on an empty slice yields the empty
/// string.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window MISSED as
/// author-facing text (`"omitted phases: contracting, terminal"`);
/// an LSP completion pin that renders the missing labels of an
/// author-written closed-set field as a comma-joined "still
/// available" hint; a Sekiban audit-trail projection whose per-
/// window miss-label witness renders as a deterministic pipe-joined
/// string across machines; a `tatara-lisp::macro_expand::Expander`
/// diagnostic that emits the UNBOUND vocabulary identifiers as a
/// slash-joined natural-language surface. Each binds to ONE typed
/// N-ary miss-label-as-string projection on the trait rather than
/// re-deriving `T::missing_labels(items).join(sep)` inline per
/// callsite.
///
/// Compounding closure: the (partition-arm × return-shape) 2×2
/// declaration-order face on the equivalence-partition surface now
/// exhaustively CLOSES the declaration-order join-string column at
/// the (absent, `String`) corner alongside [`Self::present_labels_joined`]
/// on (present, `String`), [`Self::present_labels`] on
/// (present, `Vec`), and [`Self::missing_labels`] on (absent, `Vec`).
/// The natural next lifts on this face — `sorted_present_labels_joined`
/// on (present × `String` × lex), and `sorted_missing_labels_joined`
/// on (absent × `String` × lex) — each bind through their respective
/// lex-order Vec-return primitive under the same `slice::join`
/// combinator.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary miss-
/// label-as-string projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::missing_labels(items).join(sep)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (absent, label, `String`) corner was an unnamed inline
/// composition recurring at every prospective downstream "which
/// labels did we MISS, rendered joined?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of ONE substrate primitive
/// ([`Self::missing_labels`]) with the standard-library
/// `slice::join` combinator, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label
/// (filter (lambda (v) (not (member v items))) (enum->list T)))
/// sep)`; Haskell's `intercalate sep (map label (all \\ items))`
/// on the `Bounded + Enum + Show` type-class trio; Julia's
/// `join(label.(setdiff(all, unique(items))), sep)`. Translation
/// through pleme-io primitives: a pure default method composing
/// [`Self::missing_labels`] with `slice::join` — no new dep, no
/// supertrait bound, no set-shape carrier, no allocation beyond
/// the natural `String` allocation [`Self::labels_joined`]'s
/// sibling surface already routes.
fn missing_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::missing_labels(items).join(sep)
}
/// The N-ARY DECLARATION-ORDER "repeating labels" projection — the
/// `Vec<&'static str>` label rendering of [`Self::repeating_variants`]
/// under [`Self::label`]. Every label `s` in the returned vector is
/// the canonical [`Self::label`] rendering of some variant appearing
/// STRICTLY MORE THAN ONCE (multiplicity `>= 2`) in `items`; the
/// declaration order of [`Self::repeating_variants`] is preserved
/// verbatim. The (multiplicity `>= 2`) STRICT-REPEAT band peer of
/// [`Self::present_labels`] (multiplicity `>= 1`) and
/// [`Self::missing_labels`] (multiplicity `== 0`) one MULTIPLICITY-
/// BAND axis over on the equivalence-partition surface — OPENS the
/// (repeating, `Vec<&'static str>` label, declaration-order) corner
/// past the pre-existing (present, `Vec<&'static str>` label,
/// declaration-order) and (absent, `Vec<&'static str>` label,
/// declaration-order) doublet on the label-return column.
///
/// Composition law: for every slice `items`,
/// `T::repeating_labels(items) ==
/// T::repeating_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::repeating_variants`] Vec-return primitive composed with
/// the per-slot [`Self::label`] projection. Pinned by
/// `repeating_labels_equals_repeating_variants_mapped_under_label_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::repeating_labels(items).len() ==
/// T::count_repeating_variants(items)` — the label-Vec-return
/// strict-repeat projection's length matches the usize-return
/// strict-repeat count exactly, and matches
/// [`Self::repeating_variants`]'s length one return-shape column
/// over. Pinned by
/// `repeating_labels_length_equals_count_repeating_variants_across_every_triple`.
///
/// Bool-projection identity: for every slice `items`,
/// `T::repeating_labels(items).is_empty() ==
/// !T::is_repeating_any(items)` — the strict-repeat label list is
/// empty iff no target hits multiplicity `>= 2`. Cross-checks the
/// label-Vec-return strict-repeat witness against the pre-existing
/// bool-return strict-repeat existential. Pinned by
/// `repeating_labels_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::ALL`]'s declaration order
/// regardless of the input ordering. Pinned by
/// `repeating_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::repeating_labels(&[])` is the empty
/// `Vec` UNCONDITIONALLY — the empty slice hits zero positions and
/// no target reaches multiplicity `>= 2`, so no label contributes.
/// Pinned by
/// `repeating_labels_returns_the_empty_vec_on_the_empty_slice_across_every_kind`.
///
/// Singleton contract: `T::repeating_labels(&[v])` is the empty
/// `Vec` for every variant `v` — a singleton hits multiplicity `1`
/// at exactly one target and the strict-repeat `>= 2` test fails
/// at every target, so no label contributes. The singleton
/// endpoint is the boundary that separates the strict-repeat band
/// from the presence band: `T::present_labels(&[v])` reports the
/// singleton `vec![T::label(v)]` at the SAME slice, so the two
/// projections diverge on the (mult `>= 1`, mult `>= 2`) boundary
/// at every singleton fixture. Pinned by
/// `repeating_labels_returns_the_empty_vec_on_every_singleton_across_every_variant`.
///
/// Full-set contract: `T::repeating_labels(<T as ClosedSet>::ALL)`
/// is the empty `Vec` UNCONDITIONALLY — the well-formedness
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting multiplicity `1` in the full-set slice,
/// so the strict-repeat `>= 2` test fails at every target and no
/// label contributes. The full-set endpoint mirrors the empty-slice
/// endpoint on this band — both collapse to `[]` — because the
/// (multiplicity `== 0`) and (multiplicity `== 1`) bands both fall
/// below the strict-repeat `>= 2` threshold. Pinned by
/// `repeating_labels_over_the_full_set_returns_the_empty_vec_across_every_kind`.
///
/// Doubled-full-set contract: `T::repeating_labels` on the doubled
/// full set equals [`Self::labels`] UNCONDITIONALLY — the doubled
/// full set hits every variant at multiplicity `2` (satisfying the
/// strict-repeat `>= 2` test at every target), so every label of
/// [`Self::ALL`] contributes in declaration order. The doubled-
/// full-set arm is LOAD-BEARING — it is the ONLY canonical fixpoint
/// arm that separates the (multiplicity `>= 2`) strict-repeat band
/// from the (multiplicity `== 0`) miss band (empty and full-set
/// both coincide on `[]` on the strict-repeat band; the
/// multiplicity `== 2` doubled-full-set fixture is what forces
/// non-emptiness). Pinned by
/// `repeating_labels_over_the_doubled_full_set_equals_labels_across_every_kind`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::repeating_variants`] Vec-return strict-repeat
/// witness composed with the per-slot [`Self::label`] projection
/// under `Iterator::map` + `Iterator::collect`. The composition uses
/// `<Self as ClosedSet>::repeating_variants(items).into_iter().map
/// (<Self as ClosedSet>::label).collect()` — O(T::CARDINALITY * n)
/// inherited from the underlying strict-repeat witness plus
/// O(T::CARDINALITY) for the map. No `PartialEq`/`Eq`/`Hash`
/// supertrait bound, no bitset-shape carrier.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window RE-ENTERED
/// (multiplicity `>= 2`) as author-facing text (`"re-entered
/// phases: warmup, ready"`); an LSP diagnostic on a Lisp-author-
/// written closed-set field that renders the strict-repeat set as
/// an author-facing "duplicate values" warning (`":severities
/// [:info :warn :info] — duplicates: info"`); a Sekiban audit-
/// trail projection that carries the concrete strict-repeat label
/// set of a classification poset window as its per-window witness;
/// a `tatara-lisp::macro_expand::Expander` hygiene pass that reports
/// the exact set of vocabulary identifiers a template bound MORE
/// THAN ONCE. Each binds to ONE typed N-ary strict-repeat label
/// projection on the trait rather than re-deriving the
/// `repeating_variants + into_iter + map(label) + collect` four-
/// primitive composition inline per callsite.
///
/// Compounding closure: the (partition-band × return-shape × ordering)
/// 3×4×2 matrix over the closed-set label-aggregation surface now
/// OPENS the (repeating × `Vec<&'static str>` × declaration-order)
/// corner past the pre-existing (present × `Vec<&'static str>` ×
/// declaration-order) [`Self::present_labels`] and (absent ×
/// `Vec<&'static str>` × declaration-order) [`Self::missing_labels`]
/// doublet. The natural next lifts on this face — a
/// `repeating_labels_joined` on (repeating × `String` ×
/// declaration-order) via a `slice::join` composition, a
/// `sorted_repeating_labels` on (repeating × `Vec<&'static str>` ×
/// lex-order) via a `sorted_repeating_variants + map(label) +
/// collect` composition, and a `sorted_repeating_labels_joined` on
/// (repeating × `String` × lex-order) via a `slice::join`
/// composition on the lex-arm Vec — each bind through their
/// respective sibling variant-collector primitive under the per-
/// slot [`Self::label`] projection or the `slice::join` combinator.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// strict-repeat label projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::repeating_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (repeating-Vec-label) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which labels did we REPEAT?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the strict-
/// repeat label projection emerges from the composition of TWO
/// substrate primitives ([`Self::repeating_variants`] +
/// [`Self::label`]) via `Iterator::map` + `Iterator::collect`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(map T-label (filter (lambda (v)
/// (>= (count v items) 2)) (enum->list T)))` composing the strict-
/// repeat filter with a `map` under `label`; Haskell's `map label
/// (filter (\v -> length (filter (==v) items) >= 2) all)` on the
/// `Bounded + Enum + Show + Eq` type-class quartet; R's
/// `names(table(items))[table(items) >= 2]` on a factor histogram
/// where `table` computes the multiplicity vector; SQL's
/// `SELECT label(variant) FROM t GROUP BY variant HAVING COUNT(*)
/// \>= 2`. Translation through pleme-io primitives: a pure default
/// method mapping the trait's existing [`Self::repeating_variants`]
/// Vec-return primitive under the per-slot [`Self::label`]
/// projection — no new dep, no supertrait bound, no set-shape
/// carrier, no additional allocation beyond the natural
/// `Vec<&'static str>` [`Self::labels`]'s sibling surface already
/// routes.
fn repeating_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::repeating_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "repeating labels joined" projection —
/// the `String` rendering of [`Self::repeating_labels`] joined by
/// `sep`. Composes the substrate's declaration-axis strict-repeat
/// label-Vec primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of [`Self::repeating_labels`]
/// automatically satisfies this projection at every downstream site.
/// The (multiplicity `>= 2`) STRICT-REPEAT band peer of
/// [`Self::present_labels_joined`] (multiplicity `>= 1`) and
/// [`Self::missing_labels_joined`] (multiplicity `== 0`) one
/// MULTIPLICITY-BAND axis over on the declaration-order `String`-
/// return column of the equivalence-partition surface —
/// EXHAUSTIVELY CLOSES the (partition-band × `String` ×
/// declaration-order) 3-tile row at its FINAL third tile past
/// the pre-existing (present, `String`, declaration) and
/// (absent, `String`, declaration) doublet.
///
/// Sibling posture to [`Self::repeating_labels`] one return-shape
/// axis over on the (`Vec<&'static str>`, `String`) partition of the
/// declaration-order arm of the strict-repeat band — the Vec-return
/// arm materializes each strict-repeat slot as a `&'static str`,
/// this method joins them into a single `String` under the caller's
/// separator. Sibling posture to [`Self::missing_labels_joined`] one
/// MULTIPLICITY-BAND axis over on the equivalence-partition surface
/// — [`Self::missing_labels_joined`] renders the (multiplicity
/// `== 0`) miss band, this method renders the (multiplicity `>= 2`)
/// strict-repeat band, both under the SAME `slice::join` combinator
/// on the SAME declaration-order arm.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::repeating_labels_joined(items, sep) ==
/// T::repeating_labels(items).join(sep)` — the join-string projection
/// binds through the substrate's [`Self::repeating_labels`] Vec-return
/// primitive composed with `slice::join`. Pinned by
/// `repeating_labels_joined_equals_repeating_labels_dot_join_across_every_triple`.
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`, `T::repeating_labels_joined(items, sep).is_empty()
/// == !T::is_repeating_any(items)` — the strict-repeat join-string
/// is empty iff no target hits multiplicity `>= 2`. Cross-checks the
/// join-string-column projection against the bool-column projection
/// one return-shape column over, and against the sibling
/// [`Self::repeating_labels`] `is_empty` identity one return-shape
/// column over on the Vec-return arm. Pinned by
/// `repeating_labels_joined_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items` preserves
/// its multiset of variant identities, and the strict-repeat
/// predicate is a function of that multiset alone. The OUTPUT
/// ordering is fixed by [`Self::ALL`]'s declaration order regardless
/// of the input ordering, so the joined `String` matches byte-for-
/// byte under reversal. Pinned by
/// `repeating_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::repeating_labels_joined(&[], sep) == ""`
/// UNCONDITIONALLY for every `sep` — the empty slice hits zero
/// positions, every per-target multiplicity is `0`, the strict-
/// repeat `>= 2` test fails at every target, and `slice::join` on
/// the empty slice yields the empty `String`. Pinned by
/// `repeating_labels_joined_over_the_empty_slice_returns_the_empty_string_across_every_separator`.
///
/// Singleton contract: `T::repeating_labels_joined(&[v], sep) == ""`
/// UNCONDITIONALLY for every variant `v` and every `sep` — a
/// singleton hits multiplicity `1` at exactly one target and the
/// strict-repeat `>= 2` test fails at every target, so no label
/// contributes and the joined `String` is empty. Pinned by
/// `repeating_labels_joined_over_every_singleton_returns_the_empty_string_across_every_separator`.
///
/// Full-set contract: `T::repeating_labels_joined(<T as
/// ClosedSet>::ALL, sep) == ""` UNCONDITIONALLY — the well-formedness
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself, every per-target multiplicity is
/// `1`, the strict-repeat `>= 2` test fails at every target, and
/// the empty label-Vec joins to the empty `String`. The full-set
/// endpoint mirrors the empty-slice endpoint on this band — both
/// collapse to `""` — because the (multiplicity `== 0`) and
/// (multiplicity `== 1`) bands both fall below the strict-repeat
/// `>= 2` threshold. Pinned by
/// `repeating_labels_joined_over_the_full_set_returns_the_empty_string_across_every_separator`.
///
/// Doubled-full-set contract: `T::repeating_labels_joined` on the
/// doubled full set equals [`Self::labels_joined`] UNCONDITIONALLY —
/// the doubled full set hits every variant at multiplicity `2`
/// (satisfying the strict-repeat `>= 2` test at every target), so
/// every label of [`Self::ALL`] contributes in declaration order and
/// `slice::join` renders them under the caller's separator matching
/// [`Self::labels_joined`] byte-for-byte. The doubled-full-set arm
/// is LOAD-BEARING — it is the ONLY canonical fixpoint arm that
/// separates the (multiplicity `>= 2`) strict-repeat band from the
/// (multiplicity `== 0`) miss band (empty and full-set both coincide
/// on `""` on the strict-repeat band; the multiplicity `== 2`
/// doubled-full-set fixture is what forces non-emptiness). Pinned by
/// `repeating_labels_joined_over_the_doubled_full_set_equals_labels_joined_across_every_separator`.
///
/// Signature note: the projection is a typed CONSEQUENCE of the
/// substrate's [`Self::repeating_labels`] Vec-return strict-repeat
/// witness composed with the standard-library `slice::join`
/// combinator. The composition uses
/// `<Self as ClosedSet>::repeating_labels(items).join(sep)` — O(N)
/// on the miss-label Vec's length inherited from the underlying
/// strict-repeat witness plus O(N * sep.len()) for the join. No
/// `PartialEq`/`Eq`/`Hash` supertrait bound, no bitset-shape carrier.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window RE-ENTERED
/// (multiplicity `>= 2`) as a comma-joined author-facing string
/// (`"re-entered phases: warmup, ready"`); an LSP diagnostic on a
/// Lisp-author-written closed-set field that renders the strict-
/// repeat label set as a pipe-joined "duplicate values" warning
/// (`":severities [:info :warn :info] — duplicates: info"`); a
/// Sekiban audit-trail projection that carries the concrete strict-
/// repeat label set of a classification poset window as its per-
/// window witness rendered under a deterministic separator across
/// machines; a `tatara-lisp::macro_expand::Expander` hygiene pass
/// that reports the exact set of vocabulary identifiers a template
/// bound MORE THAN ONCE as a slash-joined natural-language surface.
/// Each binds to ONE typed N-ary strict-repeat label-as-string
/// projection on the trait rather than re-deriving
/// `T::repeating_labels(items).join(sep)` inline per callsite.
///
/// Compounding closure: the (partition-band × return-shape ×
/// ordering) 3×4×2 matrix over the closed-set label-aggregation
/// surface now EXHAUSTIVELY CLOSES the (declaration-order × 3-band
/// × `String`-return) row at its FINAL third tile past the pre-
/// existing (present × `String` × declaration-order)
/// [`Self::present_labels_joined`] and (absent × `String` ×
/// declaration-order) [`Self::missing_labels_joined`] doublet. The
/// natural next lifts on this face — a `sorted_repeating_labels` on
/// (repeating × `Vec<&'static str>` × lex-order) via a
/// `sorted_repeating_variants + map(label) + collect` composition,
/// and a `sorted_repeating_labels_joined` on (repeating × `String` ×
/// lex-order) via a `slice::join` composition on the lex-arm Vec —
/// each bind through their respective sibling variant-collector
/// primitive under the per-slot [`Self::label`] projection or the
/// `slice::join` combinator.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// strict-repeat label-as-string projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::repeating_labels(items).join(sep)` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (repeating × `String` × declaration-order) corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "which labels did we REPEAT, rendered joined?" site
/// pre-lift. THEORY.md §VI.1 — generation over composition; the
/// strict-repeat label-as-string projection emerges from the
/// composition of ONE substrate primitive
/// ([`Self::repeating_labels`]) with the standard-library
/// `slice::join` combinator, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label
/// (filter (lambda (v) (>= (count v items) 2)) (enum->list T))) sep)`
/// composing the strict-repeat filter with a `string-join` combinator
/// under the per-slot label projection; Haskell's `intercalate sep
/// (map label (filter (\v -> length (filter (==v) items) >= 2) all))`
/// on the `Bounded + Enum + Show + Eq` type-class quartet; R's
/// `paste(names(table(items))[table(items) >= 2], collapse=sep)`
/// on a factor histogram; SQL's `STRING_AGG(label(variant), sep)
/// FROM t GROUP BY variant HAVING COUNT(*) >= 2` on a group-by
/// aggregate. Translation through pleme-io primitives: a pure default
/// method composing [`Self::repeating_labels`] with `slice::join` —
/// no new dep, no supertrait bound, no set-shape carrier, no
/// additional allocation beyond the natural `String` allocation
/// [`Self::labels_joined`]'s sibling surface already routes.
fn repeating_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::repeating_labels(items).join(sep)
}
/// The N-ARY LEX-ORDER "present labels" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::sorted_present_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant present in `items`;
/// the lex order of [`Self::sorted_present_variants`] is preserved
/// verbatim. The LEX-ORDER peer of [`Self::present_labels`] on the
/// (declaration, lex) ordering axis of the label-return column of
/// the equivalence-partition surface — opens the lex arm past the
/// declaration arm the sibling [`Self::present_labels`] closed.
///
/// Sibling posture to [`Self::sorted_present_variants`] one return-
/// shape axis over on the (`Vec<Self>` typed-variant witness,
/// `Vec<&'static str>` label witness) partition of the lex-order
/// arm of the equivalence-partition surface — the typed-variant
/// arm materializes each hit slot as `Self`, this method labels
/// each slot under [`Self::label`]. The two projections share the
/// (present) partition arm AND the lex-order ordering; they differ
/// only on the return-shape column, where the typed-variant arm
/// returns the carrier and the label arm returns the rendering.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_present_labels(items)` is a PERMUTATION of
/// `T::present_labels(items)` — the two projections label the SAME
/// hit-set under [`Self::label`] (both containing every variant
/// exactly once), so the multiset of labels in the two returned
/// Vecs coincides though the ordering differs. Pinned by
/// `sorted_present_labels_is_a_permutation_of_present_labels_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_present_labels(items).len() ==
/// T::count_distinct(items)` — the lex-order label-Vec-return
/// present-arm projection's length matches the usize-return
/// present-arm count exactly, and matches the declaration-order
/// label-Vec-return present-arm length one ordering axis over.
/// Pinned by
/// `sorted_present_labels_length_equals_count_distinct_across_every_triple`.
///
/// Composition law: for every slice `items`,
/// `T::sorted_present_labels(items) ==
/// T::sorted_present_variants(items).into_iter().map(T::label).collect()`
/// — the lex-order label-Vec projection binds through the
/// substrate's [`Self::sorted_present_variants`] Vec-return
/// primitive composed with the per-slot [`Self::label`] projection.
/// Pinned by
/// `sorted_present_labels_equals_sorted_present_variants_mapped_under_label_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities. The OUTPUT
/// ordering is fixed by [`Self::sorted_variants`]'s lex order
/// regardless of the input ordering. Pinned by
/// `sorted_present_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_present_labels(&[])` is the
/// empty `Vec` UNCONDITIONALLY. Full-set contract:
/// `T::sorted_present_labels(<T as ClosedSet>::ALL) ==
/// T::sorted_labels()` — the full-set hit-set lex-order labels
/// equal the substrate's lex-order label listing exactly. Both
/// pinned across every kind.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// touched-labels-sorted …)` that renders the concrete list of
/// `WorkloadPhase` labels a rollout window HIT in lex order (author-
/// stable regardless of `ALL`-array layout drift); an LSP
/// completion pin that renders the present labels in lex order as
/// an author-facing "already-selected" hint; a Sekiban audit-trail
/// projection that carries the concrete hit-label set of a
/// classification poset window in canonical lex order as its per-
/// window witness. Each binds to ONE typed N-ary lex-order hit-
/// witness label projection on the trait rather than re-deriving
/// the `sorted_present_variants + label + map + collect` four-
/// primitive composition inline per callsite.
///
/// Compounding closure: the (partition-arm × return-shape ×
/// ordering) 2×4×2 = 16-corner face on the equivalence-partition
/// surface now opens the lex arm of the label-return column at the
/// (present, label, lex) corner alongside the pre-existing
/// (present, label, declaration) corner at
/// [`Self::present_labels`], the (present, Vec-variant, declaration)
/// corner at [`Self::present_variants`], the (present, Vec-variant,
/// lex) corner at [`Self::sorted_present_variants`]; the sibling
/// [`Self::sorted_missing_labels`] peer closes the (absent, label,
/// lex) corner, exhaustively closing the (label-return × ordering)
/// 2×2 = 4-corner face on the label-return column of the
/// equivalence-partition surface.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order hit-label projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::sorted_present_variants(items).into_iter().map(T::label).collect()`
/// four-primitive composition at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the (present-Vec-label, lex-
/// order) corner was an unnamed inline composition recurring at
/// every prospective downstream "which labels did we HIT, in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the lex-order hit-label projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::sorted_present_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: Racket's `(map T-label (sort (filter
/// (lambda (v) (member v items)) (enum->list T)) #:key T-label))`
/// composing the hit-set filter, a lex sort, and a `map` under
/// `label`; Haskell's `map label . sortOn label . filter (\`elem\`
/// items)`; Julia's `[label(v) for v in sort(intersect(all, items),
/// by=label)]`. Translation through pleme-io primitives: a pure
/// default method mapping the trait's existing
/// [`Self::sorted_present_variants`] Vec-return primitive under the
/// per-slot [`Self::label`] projection — no new dep, no supertrait
/// bound, no set-shape carrier.
fn sorted_present_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::sorted_present_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY LEX-ORDER "present labels joined" projection — the
/// `String` rendering of [`Self::sorted_present_labels`] joined by
/// `sep`. Composes the substrate's lex-axis hit-label Vec-return
/// primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::sorted_present_labels`] automatically satisfies this
/// projection at every downstream site. The LEX-ORDER peer of
/// [`Self::present_labels_joined`] one ordering axis over on the
/// (declaration, lex) axis of the join-string column of the
/// equivalence-partition surface — opens the lex arm past the
/// declaration arm the sibling [`Self::present_labels_joined`]
/// closed.
///
/// Sibling posture to [`Self::sorted_present_labels`] one return-
/// shape axis over on the (`Vec<&'static str>`, `String`) partition
/// of the lex-order arm of the equivalence-partition label-
/// aggregation surface — the Vec-return arm materializes each hit
/// slot as a `&'static str`, this method joins them into a single
/// `String` under the caller's separator. Sibling posture to
/// [`Self::sorted_labels_joined`] one partition-flavor axis over on
/// the (full-set, present-partition) surface — [`Self::sorted_labels_joined`]
/// renders EVERY label of [`Self::sorted_variants`] under the
/// caller's separator, this method renders only the DYNAMIC hit
/// partition of an N-ary input slice under the same separator in
/// the same lex order.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::sorted_present_labels_joined(items, sep) ==
/// T::sorted_present_labels(items).join(sep)` — the join-string
/// projection binds through the substrate's
/// [`Self::sorted_present_labels`] Vec-return primitive composed
/// with `slice::join`. Pinned by
/// `sorted_present_labels_joined_equals_sorted_present_labels_dot_join_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items` and
/// every separator `sep`, `T::sorted_present_labels_joined(items,
/// sep)` and `T::present_labels_joined(items, sep)` render the
/// SAME hit-label multiset through `slice::join` — the two
/// projections join the SAME set of labels under the SAME
/// separator, but the OUTPUT byte layout differs whenever
/// declaration order and lex order diverge on the hit-set. On
/// implementors where declaration order aligns with lex order, the
/// two projections coincide byte-for-byte; on implementors that
/// diverge, the two projections diverge on layout while agreeing
/// on membership. Pinned by
/// `sorted_present_labels_joined_and_present_labels_joined_share_hit_multiset_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_present_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_present_labels_joined(&[], sep)
/// == ""` UNCONDITIONALLY for every `sep` — the empty slice hits
/// zero variants, so [`Self::sorted_present_labels`] yields the
/// empty `Vec`, and `slice::join` on an empty slice yields the
/// empty string. Full-set contract:
/// `T::sorted_present_labels_joined(<T as ClosedSet>::ALL, sep) ==
/// T::sorted_labels_joined(sep)` UNCONDITIONALLY for every `sep` —
/// the pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself, so every label survives the
/// filter and the returned join equals the substrate's lex-order
/// join under the same separator byte-for-byte.
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`, `T::sorted_present_labels_joined(items,
/// sep).is_empty()` iff `T::is_empty_hit_set(items)` — the lex-
/// order hit-set join-string is empty iff the underlying hit-set
/// is empty (i.e. iff `items` is either the empty slice OR the
/// zero-multiplicity carrier). Sibling posture to
/// `present_labels_joined.is_empty()` one ordering axis over — the
/// bool-projection is INVARIANT under the (declaration, lex) axis
/// because empty-set-ness is a function of the hit-set's
/// cardinality alone.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window HIT in
/// canonical lex order as author-facing text (`"observed phases:
/// contracting, executing, terminal"` — author-stable regardless
/// of `ALL`-array declaration layout drift); an LSP completion pin
/// that renders the hit labels of an author-written closed-set
/// field in canonical lex order as a comma-joined "already-
/// selected" hint; a Sekiban audit-trail projection that carries
/// the hit-label witness of a classification poset window as a
/// deterministic pipe-joined string across machines regardless of
/// declaration-layout drift; a `tatara-lisp::macro_expand::Expander`
/// diagnostic that emits the concrete BOUND vocabulary identifiers
/// as a canonical slash-joined natural-language surface. Each
/// binds to ONE typed N-ary lex-order hit-label-as-string
/// projection on the trait rather than re-deriving
/// `T::sorted_present_labels(items).join(sep)` inline per callsite.
///
/// Compounding closure: the (partition-arm × return-shape ×
/// ordering) 2×4×2 = 16-corner face on the equivalence-partition
/// surface now OPENS the lex-order arm of the join-string column
/// at the (present, `String`, lex) corner alongside the
/// pre-existing (present, `String`, declaration) corner at
/// [`Self::present_labels_joined`], the (absent, `String`,
/// declaration) corner at [`Self::missing_labels_joined`], and the
/// four Vec-return corners at [`Self::present_labels`] /
/// [`Self::missing_labels`] / [`Self::sorted_present_labels`] /
/// [`Self::sorted_missing_labels`]. The sole natural next lift on
/// this face — `sorted_missing_labels_joined` on (absent, `String`,
/// lex) — CLOSES the (partition-arm × ordering) 2×2 = 4-corner
/// face on the join-string column at its last remaining corner.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order hit-label-as-string projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_present_labels(items).join(sep)` composition
/// at every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (present, label, `String`, lex) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which labels did we HIT, rendered joined in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of
/// ONE substrate primitive ([`Self::sorted_present_labels`]) with
/// the standard-library `slice::join` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label (sort
/// (filter (lambda (v) (member v items)) (enum->list T)) #:key
/// T-label)) sep)`; Haskell's `intercalate sep . map label .
/// sortOn label . filter (\`elem\` items)` on the `Bounded + Enum
/// + Show` type-class trio; Julia's
/// `join(label.(sort(intersect(all, items), by=label)), sep)`.
/// Translation through pleme-io
/// primitives: a pure default method composing
/// [`Self::sorted_present_labels`] with `slice::join` — no new
/// dep, no supertrait bound, no set-shape carrier, no allocation
/// beyond the natural `String` allocation
/// [`Self::sorted_labels_joined`]'s sibling surface already routes.
fn sorted_present_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_present_labels(items).join(sep)
}
/// The N-ARY LEX-ORDER "missing labels" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::sorted_missing_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant ABSENT from `items`;
/// the lex order of [`Self::sorted_missing_variants`] is preserved
/// verbatim. The DE MORGAN dual of [`Self::sorted_present_labels`]
/// one partition-arm axis over on the lex-order arm of the label-
/// return column of the equivalence-partition surface, and the
/// LEX-ORDER peer of [`Self::missing_labels`] on the (declaration,
/// lex) ordering axis.
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::sorted_present_labels`] and
/// [`Self::sorted_missing_labels`] (each walking
/// [`Self::sorted_variants`] in lex order under [`Self::label`])
/// forms a PARTITION of [`Self::sorted_labels`] — the two Vecs are
/// DISJOINT and their union preserves both the lex-order sub-
/// sequence property AND [`Self::sorted_labels`]'s full membership.
/// Pinned by
/// `sorted_present_labels_and_sorted_missing_labels_are_disjoint_across_every_triple`
/// and
/// `sorted_present_labels_interleaved_with_sorted_missing_labels_recovers_sorted_labels_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_missing_labels(items)` is a PERMUTATION of
/// `T::missing_labels(items)` — the two projections label the SAME
/// miss-set under [`Self::label`]. Pinned by
/// `sorted_missing_labels_is_a_permutation_of_missing_labels_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_missing_labels(items).len() ==
/// T::count_missing(items)` — the lex-order label-Vec-return
/// absent-arm projection's length matches the usize-return absent-
/// arm count exactly.
///
/// Bool-projection identity: for every slice `items`,
/// `T::sorted_missing_labels(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set lex-order label list is
/// empty iff the present-arm predicate holds. Pinned by
/// `sorted_missing_labels_is_empty_iff_is_covering_holds_across_every_triple`.
/// The bool-projection is INVARIANT under the (declaration, lex)
/// axis — same bool bytes on both arms — because `Self::is_covering`
/// is a function of the miss-set's cardinality alone.
///
/// Composition law: for every slice `items`,
/// `T::sorted_missing_labels(items) ==
/// T::sorted_missing_variants(items).into_iter().map(T::label).collect()`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities. The OUTPUT
/// ordering is fixed by [`Self::sorted_variants`]'s lex order.
///
/// Empty-slice contract:
/// `T::sorted_missing_labels(&[]) == T::sorted_labels()`
/// UNCONDITIONALLY — the empty slice hits zero variants, so every
/// variant passes the "not present" filter and contributes its
/// label in lex order. Full-set contract:
/// `T::sorted_missing_labels(<T as ClosedSet>::ALL)` is the empty
/// `Vec` UNCONDITIONALLY.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// omitted-labels-sorted …)` that renders the concrete list of
/// `WorkloadPhase` labels a rollout window MISSED in canonical lex
/// order (author-stable regardless of `ALL`-array layout drift);
/// an LSP diagnostic on a Lisp-author-written closed-set field
/// that renders the miss-set in lex order as an author-facing
/// completion hint; a Sekiban audit-trail projection that carries
/// the concrete gap-label set of a classification poset window in
/// canonical lex order as its per-window witness; a `tatara-lisp::
/// macro_expand::Expander` hygiene pass that reports the exact set
/// of vocabulary identifiers a template FAILED to bind by name in
/// canonical lex order. Each binds to ONE typed N-ary lex-order
/// miss-witness label projection on the trait rather than re-
/// deriving the `sorted_missing_variants + label + map + collect`
/// four-primitive composition inline per callsite.
///
/// Compounding closure: the (partition-arm × return-shape ×
/// ordering) 2×4×2 = 16-corner face on the equivalence-partition
/// surface EXHAUSTIVELY CLOSES the (label-return × ordering) 4-
/// corner face on the label-return column — [`Self::present_labels`]
/// on (present, decl); [`Self::missing_labels`] on (absent, decl);
/// [`Self::sorted_present_labels`] on (present, lex); THIS
/// projection on (absent, lex). Past the exhaustively-closed 4-
/// corner Vec-variant × ordering face on the same 16-corner face.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order miss-label projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::sorted_missing_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (absent-Vec-label, lex-order) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which labels did we MISS, in lex order?" site pre-
/// lift. THEORY.md §VI.1 — generation over composition; the lex-
/// order miss-label projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_missing_variants`] +
/// [`Self::label`]) via `Iterator::map` + `Iterator::collect`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(map T-label (sort (filter
/// (lambda (v) (not (member v items))) (enum->list T)) #:key
/// T-label))`; NumPy's `np.setdiff1d(all, items)` (lex-sorted by
/// default on ASCII-labeled closed sets, matching this projection's
/// output ordering); Haskell's `map label . sortOn label . (all \\)`
/// on the `Bounded + Enum + Show` type-class trio. Translation
/// through pleme-io primitives: a pure default method mapping the
/// trait's existing [`Self::sorted_missing_variants`] Vec-return
/// primitive under the per-slot [`Self::label`] projection — no
/// new dep, no supertrait bound, no set-shape carrier.
fn sorted_missing_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::sorted_missing_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY LEX-ORDER "missing labels joined" projection — the
/// `String` rendering of [`Self::sorted_missing_labels`] joined by
/// `sep`. Composes the substrate's lex-axis miss-label Vec-return
/// primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::sorted_missing_labels`] automatically satisfies this
/// projection at every downstream site. The FOURTH corner CLOSING
/// the (partition-arm × ordering) 2×2 = 4-corner join-string face
/// on the label-join column of the equivalence-partition surface
/// past the pre-existing corners at [`Self::present_labels_joined`]
/// (present × decl), [`Self::missing_labels_joined`] (absent × decl),
/// and [`Self::sorted_present_labels_joined`] (present × lex). The
/// LEX-ORDER peer of [`Self::missing_labels_joined`] one ordering
/// axis over, and the DE MORGAN dual of
/// [`Self::sorted_present_labels_joined`] one partition-arm axis
/// over.
///
/// Sibling posture to [`Self::sorted_missing_labels`] one return-
/// shape axis over on the (`Vec<&'static str>`, `String`) partition
/// of the lex-order arm of the equivalence-partition label-
/// aggregation surface — the Vec-return arm materializes each miss
/// slot as a `&'static str`, this method joins them into a single
/// `String` under the caller's separator. Sibling posture to
/// [`Self::sorted_labels_joined`] one partition-flavor axis over on
/// the (full-set, missing-partition) surface —
/// [`Self::sorted_labels_joined`] renders EVERY label of
/// [`Self::sorted_variants`] under the caller's separator, this
/// method renders only the DYNAMIC miss partition of an N-ary input
/// slice under the same separator in the same lex order.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::sorted_missing_labels_joined(items, sep) ==
/// T::sorted_missing_labels(items).join(sep)` — the join-string
/// projection binds through the substrate's
/// [`Self::sorted_missing_labels`] Vec-return primitive composed
/// with `slice::join`. Pinned by
/// `sorted_missing_labels_joined_equals_sorted_missing_labels_dot_join_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items` and
/// every separator `sep`, `T::sorted_missing_labels_joined(items,
/// sep)` and `T::missing_labels_joined(items, sep)` render the SAME
/// miss-label multiset through `slice::join` — the two projections
/// join the SAME set of labels under the SAME separator, but the
/// OUTPUT byte layout differs whenever declaration order and lex
/// order diverge on the miss-set. On implementors where declaration
/// order aligns with lex order, the two projections coincide byte-
/// for-byte; on implementors that diverge, the two projections
/// diverge on layout while agreeing on membership.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the miss-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_missing_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_missing_labels_joined(&[], sep)
/// == T::sorted_labels_joined(sep)` UNCONDITIONALLY for every `sep`
/// — the empty slice hits zero variants, so EVERY label of
/// [`Self::ALL`] passes the "not present" filter,
/// [`Self::sorted_missing_labels`] yields the full lex-order label
/// listing, and `slice::join` under the caller's separator matches
/// [`Self::sorted_labels_joined`]'s byte layout exactly. Full-set
/// contract: `T::sorted_missing_labels_joined(<T as ClosedSet>::ALL,
/// sep) == ""` UNCONDITIONALLY for every `sep` — the well-formedness
/// pairwise-distinctness invariant pins every variant as hitting
/// itself, so the miss-set is empty and `slice::join` on an empty
/// slice yields the empty `String`. The two contracts are De Morgan
/// duals of [`Self::sorted_present_labels_joined`]'s empty-slice /
/// full-set contracts one partition-arm axis over — the miss-arm
/// empty-slice expands to full-labels-in-lex-order, the miss-arm
/// full-set collapses to the empty string, mirror-reversed from
/// the present-arm's empty-slice/full-set behaviors.
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`, `T::sorted_missing_labels_joined(items,
/// sep).is_empty()` iff `T::is_covering(items)` — the lex-order
/// miss-set join-string is empty iff the covering predicate holds
/// (i.e. iff the miss-label Vec is empty). Sibling posture to
/// `missing_labels_joined.is_empty()` one ordering axis over — the
/// bool-projection is INVARIANT under the (declaration, lex) axis
/// because miss-set-emptiness is a function of the miss-set's
/// cardinality alone. Pinned by
/// `sorted_missing_labels_joined_is_empty_iff_is_covering_holds_across_every_triple`.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window MISSED in
/// canonical lex order as author-facing text (`"omitted phases:
/// contracting, terminal, warming"` — author-stable regardless of
/// `ALL`-array declaration layout drift); an LSP completion pin
/// that renders the missing labels of an author-written closed-set
/// field in canonical lex order as a comma-joined "still available"
/// hint; a Sekiban audit-trail projection whose per-window miss-
/// label witness renders as a deterministic pipe-joined string
/// across machines regardless of declaration-layout drift; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that emits the
/// UNBOUND vocabulary identifiers as a canonical slash-joined
/// natural-language surface. Each binds to ONE typed N-ary lex-
/// order miss-label-as-string projection on the trait rather than
/// re-deriving `T::sorted_missing_labels(items).join(sep)` inline
/// per callsite.
///
/// Compounding closure: the (partition-arm × ordering) 2×2 = 4-
/// corner face on the join-string column of the equivalence-
/// partition surface is now EXHAUSTIVELY CLOSED — the four corners
/// [`Self::present_labels_joined`] on (present × decl),
/// [`Self::missing_labels_joined`] on (absent × decl),
/// [`Self::sorted_present_labels_joined`] on (present × lex), and
/// THIS projection on (absent × lex) all bind through the same
/// `Vec-return + slice::join` composition shape, and each of the
/// four Vec-return underliers ([`Self::present_labels`] /
/// [`Self::missing_labels`] / [`Self::sorted_present_labels`] /
/// [`Self::sorted_missing_labels`]) already exists on the label-
/// column arm one return-shape axis over. Past the exhaustively-
/// closed (Vec-label × ordering × partition-arm) 2×2×2 = 8-corner
/// face on the label-column arm.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order miss-label-as-string projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_missing_labels(items).join(sep)` composition
/// at every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (absent, label, `String`, lex) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which labels did we MISS, rendered joined in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of ONE
/// substrate primitive ([`Self::sorted_missing_labels`]) with the
/// standard-library `slice::join` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label (sort
/// (filter (lambda (v) (not (member v items))) (enum->list T))
/// #:key T-label)) sep)`; Haskell's `intercalate sep . map label .
/// sortOn label . (all \\)` on the `Bounded + Enum + Show` type-
/// class trio; Julia's `join(label.(sort(setdiff(all, unique(items)),
/// by=label)), sep)`. Translation through pleme-io primitives: a
/// pure default method composing [`Self::sorted_missing_labels`]
/// with `slice::join` — no new dep, no supertrait bound, no set-
/// shape carrier, no allocation beyond the natural `String`
/// allocation [`Self::sorted_labels_joined`]'s sibling surface
/// already routes.
fn sorted_missing_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_missing_labels(items).join(sep)
}
/// The N-ARY LEX-ORDER "repeating labels" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::sorted_repeating_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant whose per-target
/// multiplicity in `items` is `>= 2`; the lex order of
/// [`Self::sorted_repeating_variants`] is preserved verbatim. The
/// LEX-ORDER peer of [`Self::repeating_labels`] one ORDERING axis
/// over on the equivalence-partition surface — opens the lex arm
/// of the (strict-repeat × `Vec<&'static str>`) column past the
/// declaration arm the sibling [`Self::repeating_labels`] closed,
/// mirroring [`Self::sorted_present_labels`] opening its lex arm
/// past [`Self::present_labels`] and [`Self::sorted_missing_labels`]
/// opening its lex arm past [`Self::missing_labels`].
///
/// Sibling posture to [`Self::sorted_repeating_variants`] one
/// return-shape axis over on the (`Vec<Self>` typed-variant witness,
/// `Vec<&'static str>` label witness) partition of the lex-order arm
/// of the strict-repeat band — the typed-variant arm materializes
/// each strict-repeat slot as `Self`, this method labels each slot
/// under [`Self::label`]. Sibling posture to [`Self::sorted_missing_labels`]
/// and [`Self::sorted_present_labels`] one MULTIPLICITY-BAND axis
/// over on the lex-order label-Vec-return column — the three share
/// the lex-order ordering AND the label-Vec-return shape; they
/// differ only on the multiplicity-band column, where miss reports
/// `== 0`, present reports `>= 1`, and this projection reports
/// `>= 2`.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_repeating_labels(items)` is a PERMUTATION of
/// `T::repeating_labels(items)` — the two projections label the
/// SAME strict-repeat set under [`Self::label`], so the multiset
/// of labels in the two returned Vecs coincides though the
/// ordering differs. On implementors where declaration order
/// aligns with lex order, the two projections coincide element-
/// for-element; on implementors that diverge, they diverge on
/// layout while agreeing on membership. Pinned by
/// `sorted_repeating_labels_is_a_permutation_of_repeating_labels_across_every_triple`.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_repeating_labels(items).len() ==
/// T::count_repeating_variants(items)` — the lex-order label-Vec-
/// return strict-repeat projection's length matches the usize-
/// return strict-repeat count exactly, and matches the declaration-
/// order label-Vec-return strict-repeat length one ordering axis
/// over at [`Self::repeating_labels`]. Pinned by
/// `sorted_repeating_labels_length_equals_count_repeating_variants_across_every_triple`.
///
/// Composition law: for every slice `items`,
/// `T::sorted_repeating_labels(items) ==
/// T::sorted_repeating_variants(items).into_iter().map(T::label).collect()`
/// — the lex-order label-Vec projection binds through the
/// substrate's [`Self::sorted_repeating_variants`] Vec-return
/// primitive composed with the per-slot [`Self::label`] projection.
/// Pinned by
/// `sorted_repeating_labels_equals_sorted_repeating_variants_mapped_under_label_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_repeating_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Bool-projection identity: for every slice `items`,
/// `T::sorted_repeating_labels(items).is_empty() ==
/// !T::is_repeating_any(items)` — the lex-order strict-repeat
/// label list is empty iff the strict-repeat existential fails.
/// The bool-projection is INVARIANT under the (declaration, lex)
/// axis because strict-repeat-emptiness is a function of the
/// strict-repeat set's cardinality alone. Pinned by
/// `sorted_repeating_labels_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_repeating_labels(&[])` is the
/// empty `Vec` UNCONDITIONALLY — the empty slice hits zero
/// positions and no target reaches multiplicity `>= 2`. Singleton
/// contract: `T::sorted_repeating_labels(&[v])` is the empty `Vec`
/// for every variant `v` — a singleton hits multiplicity `1` at
/// exactly one target and the strict-repeat `>= 2` test fails at
/// every target. Full-set contract: `T::sorted_repeating_labels(<T
/// as ClosedSet>::ALL)` is the empty `Vec` UNCONDITIONALLY — the
/// well-formedness pairwise-distinctness invariant pins every
/// variant of [`Self::ALL`] as hitting itself, every per-target
/// multiplicity is `1`, and the strict-repeat `>= 2` test fails.
/// Doubled-full-set contract: `T::sorted_repeating_labels` on the
/// doubled full set equals [`Self::sorted_labels`] UNCONDITIONALLY
/// — the doubled full set hits every variant at multiplicity `2`,
/// so every label of [`Self::ALL`] contributes in lex order. The
/// doubled-full-set arm is LOAD-BEARING — the ONLY canonical
/// fixpoint arm that separates the strict-repeat band from the
/// miss band on the lex-label-Vec column (empty and full-set both
/// coincide on `[]`; the multiplicity `== 2` doubled-full-set is
/// what forces non-emptiness). All four pinned across every kind.
///
/// Future consumers — a `tatara-check` diagnostic that renders
/// the concrete `WorkloadPhase` labels a rollout window RE-ENTERED
/// (multiplicity `>= 2`) in canonical lex order as author-stable
/// text (`"re-entered phases: contracting, ready, warmup"` —
/// stable regardless of `ALL`-array layout drift); an LSP
/// diagnostic on a Lisp-author-written closed-set field that
/// renders the strict-repeat label set in canonical lex order as
/// an author-facing "duplicate values" warning; a Sekiban audit-
/// trail projection that carries the concrete strict-repeat label
/// set of a classification poset window in canonical lex order as
/// its per-window witness across machines regardless of
/// declaration-layout drift; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the exact set of vocabulary
/// identifiers a template bound MORE THAN ONCE in canonical lex
/// order as a natural-language surface. Each binds to ONE typed
/// N-ary lex-order strict-repeat label projection on the trait
/// rather than re-deriving the `sorted_repeating_variants +
/// map(label) + collect` four-primitive composition inline per
/// callsite.
///
/// Compounding closure: the (partition-band × return-shape ×
/// ordering) 3×4×2 matrix over the closed-set label-aggregation
/// surface now OPENS the (repeating × `Vec<&'static str>` × lex-
/// order) corner past the pre-existing (present × `Vec<&'static
/// str>` × lex-order) [`Self::sorted_present_labels`] and (absent
/// × `Vec<&'static str>` × lex-order) [`Self::sorted_missing_labels`]
/// doublet — mirroring the exhaustively-closed declaration-order
/// trio (present × decl) [`Self::present_labels`], (absent × decl)
/// [`Self::missing_labels`], (repeating × decl)
/// [`Self::repeating_labels`]. The natural next lift on this face
/// — a `sorted_repeating_labels_joined` on (repeating × `String` ×
/// lex-order) via a `slice::join` composition on this Vec-arm,
/// EXHAUSTIVELY CLOSING the (partition-band × ordering) 3×2 face
/// on the label-join column at its final sixth tile past the pre-
/// existing quintet of [`Self::present_labels_joined`],
/// [`Self::missing_labels_joined`], [`Self::repeating_labels_joined`],
/// [`Self::sorted_present_labels_joined`], and
/// [`Self::sorted_missing_labels_joined`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order strict-repeat label projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_repeating_variants(items).into_iter().map
/// (T::label).collect()` composition at every downstream generic
/// site. THEORY.md §V.1 — knowable platform; the (repeating,
/// label, lex) corner was an unnamed inline composition recurring
/// at every prospective downstream "which labels did we REPEAT,
/// in canonical lex order?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the lex-order strict-repeat label
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::sorted_repeating_variants`] +
/// [`Self::label`]) via `Iterator::map` + `Iterator::collect`,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(map T-label (sort (filter
/// (lambda (v) (>= (count v items) 2)) (enum->list T)) #:key
/// T-label))` composing the strict-repeat filter with a lex sort
/// and a `map` under `label`; Haskell's `map label . sortOn label
/// . filter (\v -> length (filter (==v) items) >= 2) all` on the
/// `Bounded + Enum + Show + Eq` type-class quartet; Julia's
/// `[label(v) for v in sort(filter(v -> count(==(v), items) >= 2,
/// all), by=label)]`; SQL's `SELECT label(variant) FROM t GROUP
/// BY variant HAVING COUNT(*) >= 2 ORDER BY label(variant)`.
/// Translation through pleme-io primitives: a pure default method
/// mapping the trait's existing [`Self::sorted_repeating_variants`]
/// Vec-return primitive under the per-slot [`Self::label`]
/// projection — no new dep, no supertrait bound, no set-shape
/// carrier, no additional allocation beyond the natural
/// `Vec<&'static str>` [`Self::sorted_labels`]'s sibling surface
/// already routes.
fn sorted_repeating_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::sorted_repeating_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY LEX-ORDER "repeating labels joined" projection — the
/// `String` rendering of [`Self::sorted_repeating_labels`] joined by
/// `sep`. Composes the substrate's lex-axis strict-repeat-label
/// Vec-return primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::sorted_repeating_labels`] automatically satisfies this
/// projection at every downstream site. The SIXTH corner
/// EXHAUSTIVELY CLOSING the (partition-band × ordering) 3×2 =
/// 6-corner join-string face on the label-join column of the
/// equivalence-partition surface past the pre-existing quintet at
/// [`Self::present_labels_joined`] (present × decl),
/// [`Self::missing_labels_joined`] (absent × decl),
/// [`Self::repeating_labels_joined`] (repeating × decl),
/// [`Self::sorted_present_labels_joined`] (present × lex), and
/// [`Self::sorted_missing_labels_joined`] (absent × lex). The
/// LEX-ORDER peer of [`Self::repeating_labels_joined`] one ORDERING
/// axis over, and the mult-band `>= 2` peer of
/// [`Self::sorted_missing_labels_joined`] +
/// [`Self::sorted_present_labels_joined`] one PARTITION-BAND axis
/// over on the lex arm.
///
/// Sibling posture to [`Self::sorted_repeating_labels`] one return-
/// shape axis over on the (`Vec<&'static str>`, `String`) partition
/// of the lex-order arm of the equivalence-partition strict-repeat
/// label-aggregation surface — the Vec-return arm materializes each
/// strict-repeat slot as a `&'static str`, this method joins them
/// into a single `String` under the caller's separator. Sibling
/// posture to [`Self::sorted_labels_joined`] one partition-flavor
/// axis over on the (full-set, strict-repeat-partition) surface —
/// [`Self::sorted_labels_joined`] renders EVERY label of
/// [`Self::sorted_variants`] under the caller's separator, this
/// method renders only the DYNAMIC strict-repeat partition of an
/// N-ary input slice under the same separator in the same lex order.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::sorted_repeating_labels_joined(items, sep) ==
/// T::sorted_repeating_labels(items).join(sep)` — the join-string
/// projection binds through the substrate's
/// [`Self::sorted_repeating_labels`] Vec-return primitive composed
/// with `slice::join`. Pinned by
/// `sorted_repeating_labels_joined_equals_sorted_repeating_labels_dot_join_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items` and
/// every separator `sep`, `T::sorted_repeating_labels_joined(items,
/// sep)` and `T::repeating_labels_joined(items, sep)` render the
/// SAME strict-repeat-label multiset through `slice::join` — the
/// two projections join the SAME set of labels under the SAME
/// separator, but the OUTPUT byte layout differs whenever
/// declaration order and lex order diverge on the strict-repeat
/// set. On implementors where declaration order aligns with lex
/// order, the two projections coincide byte-for-byte; on
/// implementors that diverge, the two projections diverge on
/// layout while agreeing on membership.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering. Pinned by
/// `sorted_repeating_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_repeating_labels_joined(&[],
/// sep) == ""` UNCONDITIONALLY for every `sep` — the empty slice
/// hits zero positions, every per-target multiplicity is `0`, the
/// strict-repeat `>= 2` test fails at every target, and
/// `slice::join` on the empty slice yields the empty `String`.
/// Singleton contract: `T::sorted_repeating_labels_joined(&[v],
/// sep) == ""` UNCONDITIONALLY for every variant `v` and every
/// `sep` — a singleton hits multiplicity `1` at exactly one target
/// and the strict-repeat `>= 2` test fails at every target, so no
/// label contributes and the joined `String` is empty. Full-set
/// contract: `T::sorted_repeating_labels_joined(<T as
/// ClosedSet>::ALL, sep) == ""` UNCONDITIONALLY — the well-
/// formedness pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself, every per-target multiplicity
/// is `1`, and the empty label-Vec joins to the empty `String`. The
/// empty-slice, singleton, and full-set arms all collapse to `""`
/// because the (multiplicity `== 0`) and (multiplicity `== 1`)
/// bands both fall below the strict-repeat `>= 2` threshold.
///
/// Doubled-full-set contract:
/// `T::sorted_repeating_labels_joined(<T as ClosedSet>::ALL ++ <T
/// as ClosedSet>::ALL, sep) == T::sorted_labels_joined(sep)`
/// UNCONDITIONALLY for every `sep` — the doubled full set hits
/// every variant at multiplicity `2` (satisfying the strict-repeat
/// `>= 2` test at every target), so every label of [`Self::ALL`]
/// contributes in lex order and `slice::join` renders them under
/// the caller's separator matching [`Self::sorted_labels_joined`]
/// byte-for-byte. The doubled-full-set arm is LOAD-BEARING — it is
/// the ONLY canonical fixpoint arm that separates the strict-repeat
/// band from the miss band on the lex-label-join column (empty,
/// singleton, and full-set all coincide on `""`; the multiplicity
/// `== 2` doubled-full-set fixture is what forces non-emptiness).
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`,
/// `T::sorted_repeating_labels_joined(items, sep).is_empty() ==
/// !T::is_repeating_any(items)` — the lex-order strict-repeat
/// join-string is empty iff the strict-repeat existential fails.
/// The bool-projection is INVARIANT under the (declaration, lex)
/// axis because strict-repeat-emptiness is a function of the
/// strict-repeat set's cardinality alone. Pinned by
/// `sorted_repeating_labels_joined_is_empty_iff_not_is_repeating_any_across_every_triple`.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` labels a rollout window RE-ENTERED
/// (multiplicity `>= 2`) in canonical lex order as author-stable
/// text (`"re-entered phases: contracting, ready, warmup"` —
/// stable regardless of `ALL`-array layout drift); an LSP
/// diagnostic on a Lisp-author-written closed-set field that
/// renders the strict-repeat label set in canonical lex order as
/// an author-facing pipe-joined "duplicate values" warning; a
/// Sekiban audit-trail projection whose per-window strict-repeat-
/// label witness renders as a deterministic slash-joined string
/// across machines regardless of declaration-layout drift; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that emits
/// duplicate-template-binding vocabulary identifiers as a
/// canonical comma-joined natural-language surface. Each binds to
/// ONE typed N-ary lex-order strict-repeat-label-as-string
/// projection on the trait rather than re-deriving
/// `T::sorted_repeating_labels(items).join(sep)` inline per
/// callsite OR paying the two-primitive
/// `sorted_repeating_variants + map(label) + collect + join`
/// composition every downstream site would otherwise require.
///
/// Compounding closure: the (partition-band × ordering) 3×2 = 6-
/// corner face on the join-string column of the equivalence-
/// partition surface is now EXHAUSTIVELY CLOSED — the six corners
/// [`Self::present_labels_joined`] on (present × decl),
/// [`Self::missing_labels_joined`] on (absent × decl),
/// [`Self::repeating_labels_joined`] on (repeating × decl),
/// [`Self::sorted_present_labels_joined`] on (present × lex),
/// [`Self::sorted_missing_labels_joined`] on (absent × lex), and
/// THIS projection on (repeating × lex) all bind through the same
/// `Vec-return + slice::join` composition shape, and each of the
/// six Vec-return underliers ([`Self::present_labels`] /
/// [`Self::missing_labels`] / [`Self::repeating_labels`] /
/// [`Self::sorted_present_labels`] / [`Self::sorted_missing_labels`]
/// / [`Self::sorted_repeating_labels`]) already exists on the
/// label-column arm one return-shape axis over. Past the
/// exhaustively-closed (Vec-label × ordering × partition-band)
/// 3×2 = 6-corner face on the label-column arm.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order strict-repeat-label-as-string projection becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline `T::sorted_repeating_labels(items).join(sep)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (repeating, label, `String`, lex) corner
/// was an unnamed inline composition recurring at every prospective
/// downstream "which labels did we REPEAT, rendered joined in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of ONE
/// substrate primitive ([`Self::sorted_repeating_labels`]) with the
/// standard-library `slice::join` combinator, not as a per-
/// implementor hand-rolled body.
///
/// Frontier inspiration: Racket's `(string-join (map T-label
/// (sort (filter (lambda (v) (>= (count v items) 2)) (enum->list
/// T)) #:key T-label)) sep)` composing the strict-repeat filter
/// with a lex sort, a per-slot `label` map and a `string-join`
/// combinator; Haskell's `intercalate sep . map label . sortOn
/// label . filter (\v -> length (filter (==v) items) >= 2) $ all`
/// on the `Bounded + Enum + Show + Eq` type-class quartet; Julia's
/// `join(sort([label(v) for v in all if count(==(v), items) >= 2]),
/// sep)`; SQL's `STRING_AGG(label(variant), sep ORDER BY
/// label(variant)) FROM t GROUP BY variant HAVING COUNT(*) >= 2`.
/// Translation through pleme-io primitives: a pure default method
/// composing [`Self::sorted_repeating_labels`] with `slice::join`
/// — no new dep, no supertrait bound, no set-shape carrier, no
/// allocation beyond the natural `String` allocation
/// [`Self::sorted_labels_joined`]'s sibling surface already routes.
fn sorted_repeating_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_repeating_labels(items).join(sep)
}
/// The N-ARY DECLARATION-ORDER "present indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::present_variants`] under [`Self::index_of`]. Every
/// `usize` `i` in the returned vector is the [`Self::ALL`]-position
/// of some variant present in `items`; the declaration order of
/// [`Self::present_variants`] is preserved verbatim, so the
/// returned indices form a STRICTLY ASCENDING subsequence of
/// `0..Self::CARDINALITY`. The VEC-INDEX-RETURN present-arm opener
/// on the (Vec<Self>, Vec<&'static str>, Vec<usize>) return-shape
/// column trio of the equivalence-partition surface, positioned
/// past the exhaustively-closed 4-corner (Vec-variant, Vec-label)
/// × (declaration, lex) label-and-variant face the prior lifts
/// [`Self::present_variants`], [`Self::missing_variants`],
/// [`Self::sorted_present_variants`], [`Self::sorted_missing_variants`],
/// [`Self::present_labels`], [`Self::missing_labels`],
/// [`Self::sorted_present_labels`], [`Self::sorted_missing_labels`]
/// closed.
///
/// Composition law: for every slice `items`,
/// `T::present_indices(items) ==
/// T::present_variants(items).into_iter().map(T::index_of).collect()`
/// — the index-Vec projection binds through the substrate's
/// [`Self::present_variants`] Vec-return primitive composed with
/// the per-slot [`Self::index_of`] projection.
///
/// Cardinality identity: for every slice `items`,
/// `T::present_indices(items).len() == T::count_distinct(items)` —
/// the index-Vec-return present-arm projection's length matches the
/// usize-return present-arm count exactly, and matches
/// [`Self::present_variants`] and [`Self::present_labels`] one
/// return-shape column over.
///
/// Declaration-order subsequence contract: the returned
/// `Vec<usize>` is ALWAYS a STRICTLY ASCENDING subsequence of
/// `0..Self::CARDINALITY` — every index appears at most once
/// (dedup by well-formedness), in the natural `usize` ordering
/// that coincides with [`Self::ALL`]'s declaration order under
/// [`Self::index_of`]. This subsequence property IS the composition-
/// law + [`Self::present_variants`]'s declaration-order-subsequence
/// contract propagated through [`Self::index_of`]'s bijection with
/// `0..Self::CARDINALITY`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::ALL`]'s declaration order.
///
/// Empty-slice contract: `T::present_indices(&[])` is the empty
/// `Vec` UNCONDITIONALLY. Full-set contract:
/// `T::present_indices(<T as ClosedSet>::ALL)` is
/// `(0..T::CARDINALITY).collect::<Vec<usize>>()` — the pairwise-
/// distinctness invariant pins every variant of [`Self::ALL`] as
/// hitting itself, so every index survives the filter in strictly
/// ascending order.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// touched-indices …)` that renders a compact bitset-like index
/// witness of a rollout window's hit-set for wire-encoding under
/// `u8`; an LSP diagnostic that walks the hit-indices against a
/// `[Payload; T::CARDINALITY]` slotted lookup table to render
/// per-slot annotations at each present variant's position; a
/// Sekiban audit-trail projection that carries the concrete hit-
/// index set of a classification poset window as a numerically
/// dense witness (rather than the typed variant or label
/// witnesses) for compact wire serialization; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that reports
/// the exact positions (not the typed variants) a template DID
/// bind. Each binds to ONE typed N-ary hit-witness index
/// projection on the trait rather than re-deriving the
/// `present_variants + index_of + map + collect` four-primitive
/// composition inline per callsite.
///
/// Compounding closure: the (present, absent) × (Vec<Self>,
/// Vec<&'static str>, Vec<usize>) × (declaration, lex) 2×3×2 = 12-
/// corner face on the equivalence-partition surface now opens the
/// index-return column at the (present, decl) corner alongside
/// the exhaustively-closed 8-corner Vec-variant × Vec-label ×
/// (declaration, lex) face; the sibling [`Self::missing_indices`]
/// peer closes the (absent, decl) corner, opening the index-return
/// column at both declaration-order arms. The next natural lift
/// on this surface — the (declaration, lex) ordering axis:
/// `sorted_present_indices` + `sorted_missing_indices` peers
/// walking [`Self::sorted_present_variants`] and
/// [`Self::sorted_missing_variants`] under [`Self::index_of`],
/// exhaustively closing the (index-return × ordering) 2×2 = 4-
/// corner face on the index-return column.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary hit-
/// index projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline
/// `T::present_variants(items).into_iter().map(T::index_of).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (present-Vec-index) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which INDICES did we HIT?" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the hit-index
/// projection emerges from the composition of TWO substrate
/// primitives ([`Self::present_variants`] + [`Self::index_of`])
/// via `Iterator::map` + `Iterator::collect`.
///
/// Frontier inspiration: NumPy's `np.where(np.isin(all, items))[0]`
/// — the boolean-mask-into-index-array idiom composing a hit-set
/// filter with a positional projection; Coq's `map index_of
/// (filter (fun v => existsb (Nat.eqb (index v)) items) all)`;
/// Julia's `findall(v -> v in items, all)` (returns 1-indexed
/// positions on a `Vector`); Racket's `(map T-index (filter
/// (lambda (v) (member v items)) (enum->list T)))`. Translation
/// through pleme-io primitives: a pure default method mapping the
/// trait's existing [`Self::present_variants`] Vec-return primitive
/// under the per-slot [`Self::index_of`] projection — no new dep,
/// no supertrait bound, no set-shape carrier.
fn present_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::present_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY DECLARATION-ORDER "missing indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::missing_variants`] under [`Self::index_of`]. Every
/// `usize` `i` in the returned vector is the [`Self::ALL`]-position
/// of some variant ABSENT from `items`; the declaration order of
/// [`Self::missing_variants`] is preserved verbatim, so the
/// returned indices form a STRICTLY ASCENDING subsequence of
/// `0..Self::CARDINALITY`. The DE MORGAN dual of
/// [`Self::present_indices`] one partition-arm axis over on the
/// index-return column of the equivalence-partition surface.
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::present_indices`] and
/// [`Self::missing_indices`] (each walking [`Self::ALL`] in
/// declaration order under [`Self::index_of`]) forms a PARTITION
/// of `0..Self::CARDINALITY` — the two Vecs are DISJOINT and their
/// multiset-union recovers every index of `0..Self::CARDINALITY`
/// exactly once.
///
/// Composition law: for every slice `items`,
/// `T::missing_indices(items) ==
/// T::missing_variants(items).into_iter().map(T::index_of).collect()`
/// — the index-Vec projection binds through the substrate's
/// [`Self::missing_variants`] Vec-return primitive composed with
/// the per-slot [`Self::index_of`] projection.
///
/// Cardinality identity: for every slice `items`,
/// `T::missing_indices(items).len() == T::count_missing(items)` —
/// the index-Vec-return absent-arm projection's length matches the
/// usize-return absent-arm count exactly, and matches
/// [`Self::missing_variants`] and [`Self::missing_labels`] one
/// return-shape column over.
///
/// Bool-projection identity: for every slice `items`,
/// `T::missing_indices(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set index list is empty iff
/// the present-arm predicate holds.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities. The OUTPUT
/// ordering is fixed by [`Self::ALL`]'s declaration order.
///
/// Empty-slice contract: `T::missing_indices(&[])` is
/// `(0..T::CARDINALITY).collect::<Vec<usize>>()` UNCONDITIONALLY
/// — the empty slice hits zero variants, so every index of
/// `0..T::CARDINALITY` passes the "not present" filter. Full-set
/// contract: `T::missing_indices(<T as ClosedSet>::ALL)` is the
/// empty `Vec` UNCONDITIONALLY — the pairwise-distinctness
/// invariant pins every variant as hitting itself.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// omitted-indices …)` that renders a compact bitset-like index
/// witness of a rollout window's MISS-set for wire-encoding under
/// `u8`; an LSP diagnostic that walks the miss-indices against a
/// `[Payload; T::CARDINALITY]` slotted lookup table to render per-
/// slot annotations at each absent variant's position; a Sekiban
/// audit-trail projection that carries the concrete gap-index set
/// of a classification poset window as a numerically dense witness
/// for compact wire serialization. Each binds to ONE typed N-ary
/// miss-witness index projection on the trait rather than re-
/// deriving the `missing_variants + index_of + map + collect`
/// four-primitive composition inline per callsite.
///
/// Compounding closure: the (present, absent) × (Vec<Self>,
/// Vec<&'static str>, Vec<usize>) × (declaration, lex) 2×3×2 = 12-
/// corner face on the equivalence-partition surface now closes the
/// declaration-order index-return column — [`Self::present_indices`]
/// on the (present, decl) corner + THIS projection on the (absent,
/// decl) corner. Past the exhaustively-closed 8-corner Vec-variant
/// × Vec-label × (declaration, lex) face. The next natural lift on
/// this surface — the (declaration, lex) ordering axis:
/// `sorted_present_indices` + `sorted_missing_indices` peers
/// walking [`Self::sorted_present_variants`] and
/// [`Self::sorted_missing_variants`] under [`Self::index_of`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary miss-
/// index projection becomes a TYPE-level primitive on the closed-
/// set trait rather than a per-consumer inline
/// `T::missing_variants(items).into_iter().map(T::index_of).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (absent-Vec-index) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "which INDICES did we MISS?" site pre-lift. THEORY.md §VI.1 —
/// generation over composition; the miss-index projection emerges
/// from the composition of TWO substrate primitives
/// ([`Self::missing_variants`] + [`Self::index_of`]) via
/// `Iterator::map` + `Iterator::collect`.
///
/// Frontier inspiration: NumPy's `np.where(~np.isin(all,
/// items))[0]` composing the miss-set boolean-mask with a
/// positional projection; Julia's `findall(v -> !(v in items),
/// all)`; Racket's `(map T-index (filter (lambda (v) (not (member
/// v items))) (enum->list T)))`; Coq's `map index_of (filter (fun
/// v => negb (existsb (Nat.eqb (index v)) items)) all)`.
/// Translation through pleme-io primitives: a pure default method
/// mapping the trait's existing [`Self::missing_variants`] Vec-
/// return primitive under the per-slot [`Self::index_of`]
/// projection — no new dep, no supertrait bound, no set-shape
/// carrier.
fn missing_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::missing_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY LEX-ORDER "present indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::sorted_present_variants`] under [`Self::index_of`]. Every
/// `usize` `i` in the returned vector is the [`Self::ALL`]-position
/// of some variant present in `items`; the lex order of
/// [`Self::sorted_present_variants`] is preserved verbatim, so the
/// returned indices form a subsequence of
/// [`Self::sorted_variants`]-under-[`Self::index_of`] (whose
/// declaration-axis peer [`Self::present_indices`] is a subsequence
/// of `0..Self::CARDINALITY` in strictly ascending order). The
/// LEX-ORDER peer of [`Self::present_indices`] on the (declaration,
/// lex) ordering axis of the index-return column of the
/// equivalence-partition surface.
///
/// Composition law: for every slice `items`,
/// `T::sorted_present_indices(items) ==
/// T::sorted_present_variants(items).into_iter().map(T::index_of).collect()`
/// — the lex-order index-Vec projection binds through the
/// substrate's [`Self::sorted_present_variants`] Vec-return primitive
/// composed with the per-slot [`Self::index_of`] projection.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_present_indices(items)` is a PERMUTATION of
/// `T::present_indices(items)` — the two projections index the SAME
/// hit-set under [`Self::index_of`], so the multiset of indices in
/// the two returned Vecs coincides though the ordering differs.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_present_indices(items).len() ==
/// T::count_distinct(items)` — the lex-order index-Vec-return
/// present-arm projection's length matches the usize-return present-
/// arm count exactly, and matches [`Self::sorted_present_variants`]
/// and [`Self::sorted_present_labels`] one return-shape column over.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities. The OUTPUT
/// ordering is fixed by [`Self::sorted_variants`]'s lex order under
/// [`Self::index_of`] — for an implementor whose declaration order
/// aligns with lex order (like `StubKind`) the returned indices
/// coincide with the strictly-ascending
/// [`Self::present_indices`] output byte-for-byte; for an
/// implementor whose declaration order differs from lex order the
/// returned indices carry the LEX permutation of `0..CARDINALITY`
/// filtered against the hit-set.
///
/// Empty-slice contract: `T::sorted_present_indices(&[])` is the
/// empty `Vec` UNCONDITIONALLY. Full-set contract:
/// `T::sorted_present_indices(<T as ClosedSet>::ALL) ==
/// T::sorted_variants().into_iter().map(T::index_of).collect()` — the
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself, so every index survives the
/// filter and the returned Vec matches the lex-order `Self::ALL`-
/// index listing.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// touched-indices-sorted …)` that renders the concrete list of
/// `WorkloadPhase` [`Self::ALL`]-indices a rollout window HIT in
/// canonical lex order (author-stable regardless of `ALL`-array
/// layout drift); an LSP diagnostic that walks the hit-indices in
/// lex order against a `[Payload; T::CARDINALITY]` slotted lookup
/// table to render per-slot annotations at each present variant's
/// position in canonical lex order; a Sekiban audit-trail projection
/// that carries the concrete hit-index set of a classification poset
/// window in canonical lex order as a numerically dense witness for
/// compact wire serialization stable across `ALL`-array layout
/// drift. Each binds to ONE typed N-ary lex-order hit-witness index
/// projection on the trait rather than re-deriving the
/// `sorted_present_variants + index_of + map + collect` four-
/// primitive composition inline per callsite.
///
/// Compounding closure: the (partition-arm × return-shape ×
/// ordering) 2×3×2 = 12-corner face on the equivalence-partition
/// surface now closes the lex-order arm of the index-return column
/// at the (present, lex) corner alongside the exhaustively-closed
/// 8-corner Vec-variant × Vec-label × (declaration, lex) face and
/// the (declaration, index-return) 2-corner face; the sibling
/// [`Self::sorted_missing_indices`] peer closes the (absent, lex)
/// corner, EXHAUSTIVELY CLOSING the (index-return × ordering) 2×2 =
/// 4-corner face on the index-return column and the 12-corner
/// equivalence-partition (partition-arm × return-shape × ordering)
/// 2×3×2 axes.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order hit-index projection becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::sorted_present_variants(items).into_iter().map(T::index_of).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (present-Vec-index, lex-order) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which INDICES did we HIT, in lex order?" site pre-
/// lift. THEORY.md §VI.1 — generation over composition; the lex-
/// order hit-index projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_present_variants`] +
/// [`Self::index_of`]) via `Iterator::map` + `Iterator::collect`, not
/// as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `np.where(np.isin(sorted_all,
/// items))[0]` composing a lex-sorted enumeration with a hit-set
/// boolean-mask and a positional projection; Racket's `(map T-index
/// (sort (filter (lambda (v) (member v items)) (enum->list T))
/// #:key T-label))`; Julia's `[index_of(v) for v in sort(intersect
/// (all, items), by=label)]`; Haskell's `map index . sortOn label
/// . filter (\`elem\` items)`. Translation through pleme-io
/// primitives: a pure default method mapping the trait's existing
/// [`Self::sorted_present_variants`] Vec-return primitive under the
/// per-slot [`Self::index_of`] projection — no new dep, no
/// supertrait bound, no set-shape carrier.
fn sorted_present_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_present_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY LEX-ORDER "missing indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::sorted_missing_variants`] under [`Self::index_of`]. Every
/// `usize` `i` in the returned vector is the [`Self::ALL`]-position
/// of some variant ABSENT from `items`; the lex order of
/// [`Self::sorted_missing_variants`] is preserved verbatim. The DE
/// MORGAN dual of [`Self::sorted_present_indices`] one partition-arm
/// axis over on the lex-order arm of the index-return column of the
/// equivalence-partition surface, and the LEX-ORDER peer of
/// [`Self::missing_indices`] on the (declaration, lex) ordering
/// axis — EXHAUSTIVELY CLOSES the (index-return × ordering) 2×2 =
/// 4-corner face on the index-return column past the three prior
/// corners.
///
/// De Morgan complement identity: for every slice `items`, the
/// concatenation of [`Self::sorted_present_indices`] and
/// [`Self::sorted_missing_indices`] (each walking
/// [`Self::sorted_variants`] in lex order under [`Self::index_of`])
/// forms a PARTITION of `T::sorted_variants().into_iter().map
/// (T::index_of).collect()` — the two Vecs are DISJOINT and their
/// multiset-union recovers every index of `0..Self::CARDINALITY`
/// exactly once through the LEX permutation.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_missing_indices(items)` is a PERMUTATION of
/// `T::missing_indices(items)` — the two projections index the SAME
/// miss-set under [`Self::index_of`].
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_missing_indices(items).len() ==
/// T::count_missing(items)` — the lex-order index-Vec-return absent-
/// arm projection's length matches the usize-return absent-arm
/// count exactly.
///
/// Bool-projection identity: for every slice `items`,
/// `T::sorted_missing_indices(items).is_empty()` iff
/// `T::is_covering(items)` — the miss-set lex-order index list is
/// empty iff the covering predicate holds. The bool-projection is
/// INVARIANT under the (declaration, lex) axis — same bool bytes
/// on both arms — because `Self::is_covering` is a function of the
/// miss-set's cardinality alone.
///
/// Composition law: for every slice `items`,
/// `T::sorted_missing_indices(items) ==
/// T::sorted_missing_variants(items).into_iter().map(T::index_of).collect()`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities. The OUTPUT
/// ordering is fixed by [`Self::sorted_variants`]'s lex order
/// under [`Self::index_of`].
///
/// Empty-slice contract:
/// `T::sorted_missing_indices(&[]) ==
/// T::sorted_variants().into_iter().map(T::index_of).collect()`
/// UNCONDITIONALLY — the empty slice hits zero variants, so every
/// variant passes the "not present" filter and contributes its
/// index in lex order. Full-set contract:
/// `T::sorted_missing_indices(<T as ClosedSet>::ALL)` is the empty
/// `Vec` UNCONDITIONALLY.
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// omitted-indices-sorted …)` that renders the concrete list of
/// `WorkloadPhase` [`Self::ALL`]-indices a rollout window MISSED in
/// canonical lex order (author-stable regardless of `ALL`-array
/// layout drift); an LSP diagnostic that walks the miss-indices in
/// lex order against a `[Payload; T::CARDINALITY]` slotted lookup
/// table to render per-slot annotations at each absent variant's
/// position in canonical lex order; a Sekiban audit-trail projection
/// that carries the concrete gap-index set of a classification poset
/// window in canonical lex order as a numerically dense witness for
/// compact wire serialization stable across `ALL`-array layout
/// drift. Each binds to ONE typed N-ary lex-order miss-witness
/// index projection on the trait rather than re-deriving the
/// `sorted_missing_variants + index_of + map + collect` four-
/// primitive composition inline per callsite.
///
/// Compounding closure: the (partition-arm × return-shape ×
/// ordering) 2×3×2 = 12-corner face on the equivalence-partition
/// surface EXHAUSTIVELY CLOSES at this method — the (index-return ×
/// ordering) 2×2 = 4-corner face on the index-return column now
/// carries all four corners ([`Self::present_indices`] on the
/// (present, decl) corner, [`Self::missing_indices`] on the (absent,
/// decl) corner, [`Self::sorted_present_indices`] on the (present,
/// lex) corner, THIS projection on the (absent, lex) corner), and
/// the full 12-corner (partition-arm × return-shape × ordering)
/// prism (Vec-variant + Vec-label + Vec-index) × (declaration, lex)
/// × (present, absent) is now closed. Any further compounding on
/// the equivalence-partition surface must open a NEW axis — e.g.
/// `Vec<(usize, Self)>` (index-plus-variant), `Vec<(usize,
/// &'static str)>` (index-plus-label), or an arity-widening face
/// like partition-arm ternary (equal-to-any, absent-from-any,
/// mixed) — past the exhaustively-closed 12-corner return-shape
/// prism.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order miss-index projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::sorted_missing_variants(items).into_iter().map(T::index_of).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (absent-Vec-index, lex-order) corner was
/// an unnamed inline composition recurring at every prospective
/// downstream "which INDICES did we MISS, in lex order?" site pre-
/// lift. THEORY.md §VI.1 — generation over composition; the lex-
/// order miss-index projection emerges from the composition of TWO
/// substrate primitives ([`Self::sorted_missing_variants`] +
/// [`Self::index_of`]) via `Iterator::map` + `Iterator::collect`,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `np.where(~np.isin(sorted_all,
/// items))[0]` composing a lex-sorted enumeration with a miss-set
/// boolean-mask and a positional projection; Racket's `(map T-index
/// (sort (filter (lambda (v) (not (member v items))) (enum->list T))
/// #:key T-label))`; Julia's `[index_of(v) for v in sort(setdiff
/// (all, items), by=label)]`; Coq's `map index_of (filter (fun v =>
/// negb (existsb (Nat.eqb (index v)) items)) (sort all by label))`.
/// Translation through pleme-io primitives: a pure default method
/// mapping the trait's existing [`Self::sorted_missing_variants`]
/// Vec-return primitive under the per-slot [`Self::index_of`]
/// projection — no new dep, no supertrait bound, no set-shape
/// carrier.
fn sorted_missing_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_missing_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY DECLARATION-ORDER "repeating indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::repeating_variants`] under [`Self::index_of`]. Every
/// `usize` `i` in the returned vector is the [`Self::ALL`]-position
/// of some variant appearing STRICTLY MORE THAN ONCE (multiplicity
/// `>= 2`) in `items`; the declaration order of
/// [`Self::repeating_variants`] is preserved verbatim, so the
/// returned indices form a STRICTLY ASCENDING subsequence of
/// `0..Self::CARDINALITY`. The (multiplicity `>= 2`) STRICT-REPEAT
/// band peer of [`Self::present_indices`] (multiplicity `>= 1`) and
/// [`Self::missing_indices`] (multiplicity `== 0`) one MULTIPLICITY-
/// BAND axis over on the index-return column of the equivalence-
/// partition surface — OPENS the (repeating, `Vec<usize>` index,
/// declaration-order) corner past the exhaustively-closed
/// (index-return × ordering) 2×2 = 4-corner face on the (present,
/// absent) doublet that [`Self::present_indices`],
/// [`Self::missing_indices`], [`Self::sorted_present_indices`],
/// [`Self::sorted_missing_indices`] closed. Peer to
/// [`Self::repeating_labels`] one RETURN-SHAPE column over on the
/// same multiplicity band — same partition-arm, same declaration
/// order, different Vec-return projection (`Vec<usize>` vs
/// `Vec<&'static str>`).
///
/// Composition law: for every slice `items`,
/// `T::repeating_indices(items) ==
/// T::repeating_variants(items).into_iter().map(T::index_of).collect()`
/// — the index-Vec projection binds through the substrate's
/// [`Self::repeating_variants`] Vec-return primitive composed with
/// the per-slot [`Self::index_of`] projection.
///
/// Cardinality identity: for every slice `items`,
/// `T::repeating_indices(items).len() ==
/// T::count_repeating_variants(items)` — the index-Vec-return
/// strict-repeat projection's length matches the usize-return
/// strict-repeat count exactly, and matches
/// [`Self::repeating_variants`] and [`Self::repeating_labels`] one
/// return-shape column over.
///
/// Bool-projection identity: for every slice `items`,
/// `T::repeating_indices(items).is_empty() ==
/// !T::is_repeating_any(items)` — the strict-repeat index list is
/// empty iff no target hits multiplicity `>= 2`. Cross-checks the
/// index-Vec-return strict-repeat witness against the pre-existing
/// bool-return strict-repeat existential.
///
/// Declaration-order subsequence contract: the returned
/// `Vec<usize>` is ALWAYS a STRICTLY ASCENDING subsequence of
/// `0..Self::CARDINALITY` — every index appears at most once
/// (dedup by well-formedness), in the natural `usize` ordering
/// that coincides with [`Self::ALL`]'s declaration order under
/// [`Self::index_of`]. This subsequence property IS the composition-
/// law + [`Self::repeating_variants`]'s declaration-order-subsequence
/// contract propagated through [`Self::index_of`]'s bijection with
/// `0..Self::CARDINALITY`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::ALL`]'s declaration order.
///
/// Empty-slice contract: `T::repeating_indices(&[])` is the empty
/// `Vec` UNCONDITIONALLY — the empty slice hits zero positions and
/// no target reaches multiplicity `>= 2`, so no index contributes.
///
/// Singleton contract: `T::repeating_indices(&[v])` is the empty
/// `Vec` for every variant `v` — a singleton hits multiplicity `1`
/// at exactly one target and the strict-repeat `>= 2` test fails
/// at every target, so no index contributes.
///
/// Full-set contract: `T::repeating_indices(<T as ClosedSet>::ALL)`
/// is the empty `Vec` UNCONDITIONALLY — the well-formedness
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting multiplicity `1` in the full-set slice,
/// so the strict-repeat `>= 2` test fails at every target.
///
/// Doubled-full-set contract: `T::repeating_indices` on the doubled
/// full set equals `(0..T::CARDINALITY).collect::<Vec<usize>>()`
/// UNCONDITIONALLY — the doubled full set hits every variant at
/// multiplicity `2` (satisfying the strict-repeat `>= 2` test at
/// every target), so every index of `0..T::CARDINALITY` contributes
/// in declaration order. The doubled-full-set arm is LOAD-BEARING
/// — it is the ONLY canonical fixpoint arm that separates the
/// (multiplicity `>= 2`) strict-repeat band from the miss/present
/// bands (empty and full-set both coincide on `[]` on the strict-
/// repeat band; the multiplicity `== 2` doubled-full-set fixture is
/// what forces non-emptiness).
///
/// Future consumers — a `tatara-check` predicate `(check-phases-
/// re-entered-indices …)` that renders a compact bitset-like index
/// witness of a rollout window's STRICT-REPEAT set for wire-encoding
/// under `u8`; an LSP diagnostic that walks the strict-repeat
/// indices against a `[Payload; T::CARDINALITY]` slotted lookup
/// table to render per-slot annotations at each repeated variant's
/// position; a Sekiban audit-trail projection that carries the
/// concrete strict-repeat-index set of a classification poset
/// window as a numerically dense witness (rather than the typed
/// variant or label witnesses) for compact wire serialization; a
/// `tatara-lisp::macro_expand::Expander` hygiene pass reporting
/// the exact positions (not the typed variants) a template bound
/// MORE THAN ONCE. Each binds to ONE typed N-ary strict-repeat
/// index projection on the trait rather than re-deriving the
/// `repeating_variants + index_of + map + collect` four-primitive
/// composition inline per callsite.
///
/// Compounding closure: the (partition-band × return-shape ×
/// ordering) 3×3×2 = 18-corner face on the equivalence-partition
/// surface now OPENS the (strict-repeat, `Vec<usize>` index,
/// declaration-order) corner past the exhaustively-closed 4-corner
/// (present, absent) × (declaration, lex) index-return face. The
/// natural next lift on this surface — the (lex-order) ordering
/// axis: [`sorted_repeating_indices`] via a
/// `sorted_repeating_variants + map(index_of) + collect`
/// composition, closing the strict-repeat arm's ordering-axis pair
/// at its lex tile and moving the (partition-band × ordering)
/// index-return face from 5/6 to 6/6 exhaustive closure.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary strict-
/// repeat index projection becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `T::repeating_variants(items).into_iter().map(T::index_of).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (strict-repeat, `Vec<usize>` index,
/// declaration-order) corner was an unnamed inline composition
/// recurring at every prospective downstream "which INDICES did we
/// REPEAT?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the strict-repeat index projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::repeating_variants`] + [`Self::index_of`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: NumPy's `np.where(np.array([np.sum(items
/// == v) >= 2 for v in all]))[0]` composing the strict-repeat
/// boolean-mask with a positional projection; Julia's `findall(v
/// -> count(==(v), items) >= 2, all)`; Racket's `(map T-index
/// (filter (lambda (v) (>= (count (curry equal? v) items) 2))
/// (enum->list T)))`; SQL's `SELECT index_of(variant) FROM t
/// GROUP BY variant HAVING COUNT(*) >= 2 ORDER BY index_of(variant)`.
/// Translation through pleme-io primitives: a pure default method
/// mapping the trait's existing [`Self::repeating_variants`] Vec-
/// return primitive under the per-slot [`Self::index_of`]
/// projection — no new dep, no supertrait bound, no set-shape
/// carrier.
fn repeating_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::repeating_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY LEX-ORDER "repeating indices" projection — the
/// `Vec<usize>` [`Self::ALL`]-index rendering of
/// [`Self::sorted_repeating_variants`] under [`Self::index_of`].
/// Every `usize` `i` in the returned vector is the [`Self::ALL`]-
/// position of some variant appearing STRICTLY MORE THAN ONCE
/// (multiplicity `>= 2`) in `items`; the lex order of
/// [`Self::sorted_repeating_variants`] is preserved verbatim, so the
/// returned indices form a canonical LEX-order subsequence of
/// [`Self::sorted_variants`] under [`Self::index_of`] — which is
/// NOT in general a monotone subsequence of `0..Self::CARDINALITY`
/// on implementors whose declaration order diverges from
/// [`Self::sorted_labels`]. The LEX-ORDER peer of
/// [`Self::repeating_indices`] one ORDERING axis over on the
/// equivalence-partition surface — EXHAUSTIVELY CLOSES the
/// (partition-band × ordering) 3×2 = 6-corner face on the
/// index-return column at its FINAL sixth tile past the pre-
/// existing quintet of [`Self::present_indices`],
/// [`Self::missing_indices`], [`Self::repeating_indices`],
/// [`Self::sorted_present_indices`], and [`Self::sorted_missing_indices`],
/// mirroring the exhaustively-closed (partition-band × ordering) 3×2
/// face on the sibling label-Vec-return column that
/// [`Self::sorted_repeating_labels`] closed one return-shape axis
/// over.
///
/// Sibling posture to [`Self::sorted_repeating_labels`] one RETURN-
/// SHAPE column over on the same lex-order strict-repeat arm — the
/// two projections walk the SAME lex-ordered strict-repeat witness
/// set through different per-slot projections ([`Self::index_of`]
/// vs [`Self::label`]) and coincide on cardinality, emptiness, and
/// slice-reversal invariance at every slice. Sibling posture to
/// [`Self::sorted_repeating_variants`] one RETURN-SHAPE axis over
/// on the (`Vec<Self>` typed-variant witness, `Vec<usize>` index
/// witness) partition of the lex-order arm — the typed-variant arm
/// materializes each strict-repeat slot as `Self`, this method
/// indexes each slot under [`Self::index_of`].
///
/// Composition law: for every slice `items`,
/// `T::sorted_repeating_indices(items) ==
/// T::sorted_repeating_variants(items).into_iter().map(T::index_of).collect()`
/// — the lex-order index-Vec projection binds through the
/// substrate's [`Self::sorted_repeating_variants`] Vec-return
/// primitive composed with the per-slot [`Self::index_of`]
/// projection. This IS the default trait body.
///
/// Cross-arm permutation identity: for every slice `items`,
/// `T::sorted_repeating_indices(items)` is a PERMUTATION of
/// `T::repeating_indices(items)` — the two projections index the
/// SAME strict-repeat set under [`Self::index_of`], so the multiset
/// of indices in the two returned Vecs coincides though the
/// ordering differs. On implementors where declaration order
/// aligns with lex order, the two projections coincide element-
/// for-element; on implementors that diverge, they diverge on
/// layout while agreeing on membership.
///
/// Cardinality identity: for every slice `items`,
/// `T::sorted_repeating_indices(items).len() ==
/// T::count_repeating_variants(items)` — the lex-order index-Vec-
/// return strict-repeat projection's length matches the usize-
/// return strict-repeat count exactly, and matches the declaration-
/// order index-Vec-return strict-repeat length one ordering axis
/// over at [`Self::repeating_indices`] AND the lex-order label-Vec-
/// return length one return-shape column over at
/// [`Self::sorted_repeating_labels`].
///
/// Bool-projection identity: for every slice `items`,
/// `T::sorted_repeating_indices(items).is_empty() ==
/// !T::is_repeating_any(items)` — the lex-order strict-repeat
/// index list is empty iff no target hits multiplicity `>= 2`. The
/// bool-projection is INVARIANT under the (declaration, lex)
/// ordering axis AND under the (variant, label, index) return-shape
/// axis because strict-repeat-emptiness is a function of the
/// strict-repeat set's cardinality alone.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering.
///
/// Empty-slice contract: `T::sorted_repeating_indices(&[])` is the
/// empty `Vec` UNCONDITIONALLY — the empty slice hits zero
/// positions and no target reaches multiplicity `>= 2`, so no
/// index contributes.
///
/// Singleton contract: `T::sorted_repeating_indices(&[v])` is the
/// empty `Vec` for every variant `v` — a singleton hits
/// multiplicity `1` at exactly one target and the strict-repeat
/// `>= 2` test fails at every target, so no index contributes.
///
/// Full-set contract: `T::sorted_repeating_indices(<T as
/// ClosedSet>::ALL)` is the empty `Vec` UNCONDITIONALLY — the
/// well-formedness pairwise-distinctness invariant pins every
/// variant of [`Self::ALL`] as hitting multiplicity `1` in the
/// full-set slice, so the strict-repeat `>= 2` test fails at every
/// target.
///
/// Doubled-full-set contract: `T::sorted_repeating_indices` on the
/// doubled full set equals `T::sorted_variants().into_iter().
/// map(T::index_of).collect()` UNCONDITIONALLY — the doubled full
/// set hits every variant at multiplicity `2` (satisfying the
/// strict-repeat `>= 2` test at every target), so every index of
/// `T::sorted_variants` contributes in lex order. On implementors
/// where declaration order aligns with lex order, this equals
/// `(0..T::CARDINALITY).collect()`; on implementors that diverge,
/// the output is a lex-ordered permutation of the same index set.
/// The doubled-full-set arm is LOAD-BEARING — it is the ONLY
/// canonical fixpoint arm that separates the (multiplicity `>= 2`)
/// strict-repeat band from the miss/present bands (empty and full-
/// set both coincide on `[]` on the strict-repeat band; the
/// multiplicity `== 2` doubled-full-set fixture is what forces non-
/// emptiness).
///
/// Future consumers — a `tatara-check` predicate `(check-phases-re-
/// entered-indices-sorted …)` that renders a compact
/// canonically-ordered index witness of a rollout window's STRICT-
/// REPEAT set for wire-encoding under `u8` STABLE across
/// `ALL`-array declaration-layout drift (declaration-order writes
/// diverge on layout changes; lex order pins the wire encoding to
/// the author-stable label sort); an LSP diagnostic that walks the
/// lex-ordered strict-repeat indices against a `[Payload;
/// T::CARDINALITY]` slotted lookup table to render per-slot
/// annotations in author-friendly canonical order at each repeated
/// variant's position; a Sekiban audit-trail projection that carries
/// the concrete strict-repeat-index set of a classification poset
/// window in canonical lex order as a numerically dense witness
/// (rather than the label or variant witnesses) for compact wire
/// serialization; a `tatara-lisp::macro_expand::Expander` hygiene
/// pass reporting the exact positions of a template's repeated
/// bindings in canonical lex order for author-stable diagnostic
/// output. Each binds to ONE typed N-ary lex-order strict-repeat
/// index projection on the trait rather than re-deriving the
/// `sorted_repeating_variants + index_of + map + collect` four-
/// primitive composition inline per callsite.
///
/// Compounding closure: the (partition-band × ordering) 3×2 = 6-
/// corner index-return face on the equivalence-partition surface
/// now EXHAUSTIVELY CLOSES at its FINAL sixth tile past the pre-
/// existing quintet — the strict-repeat arm's ordering-axis pair
/// (declaration, lex) is closed at both endpoints via
/// [`Self::repeating_indices`] and this method, and the surface's
/// (partition-band × ordering) index-return face fully matches the
/// exhaustively-closed (partition-band × ordering) label-Vec-return
/// face one return-shape column over.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order strict-repeat index projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_repeating_variants(items).into_iter().map
/// (T::index_of).collect()` composition at every downstream
/// generic site. THEORY.md §V.1 — knowable platform; the (strict-
/// repeat, `Vec<usize>` index, lex-order) corner was an unnamed
/// inline composition recurring at every prospective downstream
/// "which INDICES did we REPEAT, in canonical lex order?" site
/// pre-lift. THEORY.md §VI.1 — generation over composition; the
/// lex-order strict-repeat index projection emerges from the
/// composition of TWO substrate primitives
/// ([`Self::sorted_repeating_variants`] + [`Self::index_of`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: NumPy's `np.argsort(labels)[np.where
/// (np.array([np.sum(items == v) >= 2 for v in
/// sorted(all, key=label)]))[0]]` composing the strict-repeat
/// boolean-mask over the lex-sorted enumeration with a positional
/// projection; Julia's `[index_of(v) for v in sort(filter(v ->
/// count(==(v), items) >= 2, all), by=label)]`; Racket's `(map
/// T-index (sort (filter (lambda (v) (>= (count (curry equal? v)
/// items) 2)) (enum->list T)) #:key T-label))`; SQL's `SELECT
/// index_of(variant) FROM t GROUP BY variant HAVING COUNT(*) >= 2
/// ORDER BY label(variant)`. Translation through pleme-io
/// primitives: a pure default method mapping the trait's existing
/// [`Self::sorted_repeating_variants`] Vec-return primitive under
/// the per-slot [`Self::index_of`] projection — no new dep, no
/// supertrait bound, no set-shape carrier, no additional
/// allocation beyond the natural `Vec<usize>` the sibling
/// [`Self::sorted_present_indices`] / [`Self::sorted_missing_indices`]
/// surface already routes.
fn sorted_repeating_indices(items: &[Self]) -> ::std::vec::Vec<usize> {
<Self as ClosedSet>::sorted_repeating_variants(items)
.into_iter()
.map(<Self as ClosedSet>::index_of)
.collect()
}
/// The N-ARY DECLARATION-ORDER "present indices joined" projection
/// — the `String` rendering of [`Self::present_indices`] under
/// `usize::to_string` joined by `sep`. Composes the substrate's
/// declaration-axis hit-index Vec-return primitive with the
/// per-slot `usize`-to-`String` projection and the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of [`Self::present_indices`]
/// automatically satisfies this projection at every downstream
/// site. OPENS the (indices, joined) column of the (partition-band
/// × ordering × return-shape) 3×2×2 = 12-tile equivalence-partition
/// index-aggregation surface past the exhaustively-closed 6-corner
/// (partition-band × ordering) Vec-return face at [`Self::present_indices`]
/// / [`Self::missing_indices`] / [`Self::repeating_indices`] /
/// [`Self::sorted_present_indices`] / [`Self::sorted_missing_indices`]
/// / [`Self::sorted_repeating_indices`] one RETURN-SHAPE axis over.
///
/// Sibling posture to [`Self::present_labels_joined`] one field-
/// flavor axis over on the (label, index) partition of the
/// declaration-order hit-arm join-string surface —
/// [`Self::present_labels_joined`] renders each hit slot as a
/// `&'static str` label through [`Self::label`], this method
/// renders each hit slot as a decimal-`usize` index-under-
/// [`Self::index_of`] rendered through `usize::to_string`. Sibling
/// posture to [`Self::present_indices`] one return-shape axis over
/// on the (`Vec<usize>`, `String`) partition of the declaration-
/// order hit-arm index-aggregation surface — the Vec-return arm
/// materializes each hit slot as a `usize`, this method joins them
/// into a single `String` under the caller's separator.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::present_indices_joined(items, sep) ==
/// T::present_indices(items).iter().map(usize::to_string).collect::<Vec<String>>().join(sep)`
/// — the join-string projection binds through the substrate's
/// [`Self::present_indices`] Vec-return primitive composed with
/// `usize::to_string` and `slice::join`. Pinned by
/// `present_indices_joined_equals_present_indices_dot_map_to_string_dot_join_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::ALL`]'s declaration order
/// regardless of the input ordering, so the joined `String` matches
/// byte-for-byte under reversal. Pinned by
/// `present_indices_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::present_indices_joined(&[], sep)` is
/// the empty `String` UNCONDITIONALLY for every `sep` — the empty
/// slice hits zero variants, so [`Self::present_indices`] yields
/// the empty `Vec`, and `slice::join` on an empty slice yields the
/// empty string. Full-set contract:
/// `T::present_indices_joined(<T as ClosedSet>::ALL, sep) ==
/// (0..T::CARDINALITY).map(|i| i.to_string()).collect::<Vec<_>>().join(sep)`
/// UNCONDITIONALLY for every `sep` — the pairwise-distinctness
/// invariant pins every variant of [`Self::ALL`] as hitting itself
/// at its own [`Self::index_of`], so every index of
/// `0..T::CARDINALITY` survives the filter in declaration order.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` indices a rollout window HIT as a
/// compact deterministic wire-string (`"0,2,4"` — numerically
/// dense, `usize`-round-trippable through `str::parse`) for
/// per-cluster witness serialization; an LSP diagnostic that
/// renders the hit-indices of an author-written closed-set field
/// as a comma-joined slot-number hint against a
/// `[Payload; T::CARDINALITY]` slotted table; a Sekiban audit-
/// trail projection whose per-window hit-index witness renders as
/// a deterministic pipe-joined string across machines regardless
/// of declaration-layout drift; a `tatara-lisp::macro_expand::Expander`
/// diagnostic that emits the concrete BOUND vocabulary slot-
/// indices as a canonical slash-joined natural-language surface.
/// Each binds to ONE typed N-ary hit-index-as-string projection on
/// the trait rather than re-deriving
/// `T::present_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// inline per callsite.
///
/// Compounding closure: the (partition-band × ordering × return-
/// shape) 3×2×2 = 12-corner equivalence-partition index-
/// aggregation surface now OPENS the (present, declaration, join-
/// string) corner past the exhaustively-closed 6-corner (partition-
/// band × ordering) Vec-return face. The natural next lifts on
/// this face — `missing_indices_joined` on (missing, declaration,
/// join-string), `repeating_indices_joined` on (repeating,
/// declaration, join-string), and their three lex-axis peers
/// `sorted_present_indices_joined` / `sorted_missing_indices_joined`
/// / `sorted_repeating_indices_joined` — each bind through their
/// respective sibling Vec-return primitive under the same
/// `usize::to_string` + `slice::join` composition, closing the
/// (partition-band × ordering) 3×2 face on the join-string column
/// tile by tile.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary hit-
/// index-as-string projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::present_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (present, index, `String`, declaration)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which INDICES did we HIT, rendered
/// joined?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of
/// ONE substrate primitive ([`Self::present_indices`]) with the
/// standard-library `usize::to_string` + `slice::join` combinators,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `",".join(map(str,
/// np.where(np.isin(all, items))[0]))` composing the hit-index
/// positional projection with a stringify + join; Julia's
/// `join(string.(findall(v -> v in items, all)), sep)`; Racket's
/// `(string-join (map number->string (filter (lambda (i) (member
/// (list-ref all i) items)) (range (length all)))) sep)`.
/// Translation through pleme-io primitives: a pure default method
/// composing [`Self::present_indices`] with `usize::to_string` and
/// `slice::join` — no new dep, no supertrait bound, no set-shape
/// carrier, no allocation beyond the natural intermediate
/// `Vec<String>` the `slice::join` combinator's per-slot
/// stringification already routes.
fn present_indices_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::present_indices(items)
.into_iter()
.map(|i| i.to_string())
.collect::<::std::vec::Vec<::std::string::String>>()
.join(sep)
}
/// The N-ARY DECLARATION-ORDER "missing indices" join-string
/// projection — the [`Self::missing_indices`] Vec-return miss-
/// witness index list stringified per slot under `usize::to_string`
/// and threaded into a single `String` under the caller's separator.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::missing_indices_joined(items, sep) ==
/// T::missing_indices(items).iter().map(usize::to_string).collect::<Vec<String>>().join(sep)`
/// — the join-string projection binds through the substrate's
/// [`Self::missing_indices`] Vec-return primitive composed with
/// `usize::to_string` and `slice::join`. Pinned by
/// `missing_indices_joined_equals_missing_indices_dot_map_to_string_dot_join_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the miss-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::ALL`]'s declaration order
/// regardless of the input ordering, so the joined `String` matches
/// byte-for-byte under reversal. Pinned by
/// `missing_indices_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::missing_indices_joined(&[], sep)` is
/// `(0..T::CARDINALITY).map(|i| i.to_string()).collect::<Vec<_>>().join(sep)`
/// UNCONDITIONALLY for every `sep` — the empty slice hits zero
/// variants, so [`Self::missing_indices`] yields
/// `(0..T::CARDINALITY).collect::<Vec<usize>>()`, and the join over
/// the resulting decimal-`usize` slots equals the substrate's
/// `0..CARDINALITY` decimal-slot join exactly under any separator.
/// Full-set contract: `T::missing_indices_joined(<T as ClosedSet>::ALL, sep)`
/// is the empty `String` UNCONDITIONALLY for every `sep` — the
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself at its own [`Self::index_of`],
/// so [`Self::missing_indices`] yields the empty `Vec`, and
/// `slice::join` on an empty slice yields the empty string. Both
/// endpoints are DE MORGAN duals of the corresponding
/// [`Self::present_indices_joined`] endpoints one partition-arm
/// axis over.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` indices a rollout window MISSED as a
/// compact deterministic wire-string (`"1,3,5"` — numerically
/// dense, `usize`-round-trippable through `str::parse`) for
/// per-cluster gap-witness serialization; an LSP diagnostic that
/// renders the miss-indices of an author-written closed-set field
/// as a comma-joined slot-number hint against a
/// `[Payload; T::CARDINALITY]` slotted table pointing out which
/// slots are UNCOVERED; a Sekiban audit-trail projection whose
/// per-window gap-index witness renders as a deterministic pipe-
/// joined string across machines regardless of declaration-layout
/// drift; a `tatara-lisp::macro_expand::Expander` diagnostic that
/// emits the concrete UNBOUND vocabulary slot-indices as a
/// canonical slash-joined natural-language surface. Each binds to
/// ONE typed N-ary miss-index-as-string projection on the trait
/// rather than re-deriving the four-primitive
/// `T::missing_indices(items).iter().map(usize::to_string).collect().join(sep)`
/// composition inline per callsite.
///
/// Compounding closure: the (partition-band × ordering × return-
/// shape) 3×2×2 = 12-corner equivalence-partition index-
/// aggregation surface now CLOSES the declaration-order arm of the
/// (present, missing) × declaration face on the join-string column
/// past the just-lifted [`Self::present_indices_joined`] present-
/// arm opener one PARTITION-BAND axis over — [`Self::present_indices_joined`]
/// on (present, declaration, join-string) + THIS projection on
/// (missing, declaration, join-string). The natural next lifts on
/// this face — `repeating_indices_joined` on (repeating,
/// declaration, join-string) closing the declaration-arm trio, and
/// their three lex-axis peers `sorted_present_indices_joined` /
/// `sorted_missing_indices_joined` / `sorted_repeating_indices_joined`
/// — each bind through their respective sibling Vec-return
/// primitive under the same `usize::to_string` + `slice::join`
/// composition, closing the (partition-band × ordering) 3×2 face
/// on the join-string column tile by tile.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary miss-
/// index-as-string projection becomes a TYPE-level primitive on
/// the closed-set trait rather than a per-consumer inline
/// `T::missing_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (missing, index, `String`, declaration)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which INDICES did we MISS, rendered
/// joined?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from ONE substrate
/// primitive ([`Self::missing_indices`]) composed with the
/// standard-library `usize::to_string` + `slice::join` combinators,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `",".join(map(str,
/// np.where(~np.isin(all, items))[0]))` composing the miss-index
/// positional projection with a stringify + join; Julia's
/// `join(string.(findall(v -> !(v in items), all)), sep)`;
/// Racket's `(string-join (map number->string (filter (lambda (i)
/// (not (member (list-ref all i) items))) (range (length all))))
/// sep)`. Translation through pleme-io primitives: a pure default
/// method composing [`Self::missing_indices`] with
/// `usize::to_string` and `slice::join` — no new dep, no
/// supertrait bound, no set-shape carrier, no allocation beyond
/// the natural intermediate `Vec<String>` the `slice::join`
/// combinator's per-slot stringification already routes.
fn missing_indices_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::missing_indices(items)
.into_iter()
.map(|i| i.to_string())
.collect::<::std::vec::Vec<::std::string::String>>()
.join(sep)
}
/// The N-ARY DECLARATION-ORDER "repeating indices" join-string
/// projection — the [`Self::repeating_indices`] Vec-return
/// strict-repeat-witness index list stringified per slot under
/// `usize::to_string` and threaded into a single `String` under the
/// caller's separator.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::repeating_indices_joined(items, sep) ==
/// T::repeating_indices(items).iter().map(usize::to_string).collect::<Vec<String>>().join(sep)`
/// — the join-string projection binds through the substrate's
/// [`Self::repeating_indices`] Vec-return primitive composed with
/// `usize::to_string` and `slice::join`. Pinned by
/// `repeating_indices_joined_equals_repeating_indices_dot_map_to_string_dot_join_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the strict-
/// repeat `>= 2` membership predicate is a function of that
/// multiset alone. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering, so the
/// joined `String` matches byte-for-byte under reversal. Pinned by
/// `repeating_indices_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::repeating_indices_joined(&[], sep)`
/// is the empty `String` UNCONDITIONALLY for every `sep` — the
/// empty slice hits zero positions and no target reaches
/// multiplicity `>= 2`, so [`Self::repeating_indices`] yields the
/// empty `Vec`, and `slice::join` on an empty slice yields the
/// empty string. Full-set contract:
/// `T::repeating_indices_joined(<T as ClosedSet>::ALL, sep)` is
/// the empty `String` UNCONDITIONALLY for every `sep` — the
/// pairwise-distinctness invariant pins every variant of
/// [`Self::ALL`] as hitting itself at multiplicity `1`, so the
/// strict-repeat `>= 2` test fails at every target and
/// [`Self::repeating_indices`] yields the empty `Vec`. Singleton
/// contract: `T::repeating_indices_joined(&[v], sep)` is the empty
/// `String` for every variant `v` and every `sep` — a singleton
/// hits multiplicity `1` at exactly one target and the strict-
/// repeat `>= 2` test fails at every target. The three
/// "no-strict-repeat" endpoints (empty, singleton, full-set) all
/// coincide on the empty string, mirroring the empty-Vec fixpoint
/// of the sibling [`Self::repeating_indices`] Vec-return primitive
/// one return-shape axis over.
///
/// Doubled-full-set contract: `T::repeating_indices_joined` on the
/// doubled full set equals
/// `(0..T::CARDINALITY).map(|i| i.to_string()).collect::<Vec<_>>().join(sep)`
/// UNCONDITIONALLY for every `sep` — the doubled full set hits
/// every variant at multiplicity `2`, satisfying the strict-repeat
/// `>= 2` test at every target, so [`Self::repeating_indices`]
/// yields `(0..T::CARDINALITY).collect::<Vec<usize>>()` and the
/// join over the resulting decimal-`usize` slots equals the
/// substrate's `0..CARDINALITY` decimal-slot join exactly under
/// any separator. This doubled-full-set arm is LOAD-BEARING — it
/// is the ONLY canonical fixpuint arm that separates the strict-
/// repeat band from the miss/present bands on the join-string
/// column (empty and full-set both coincide on the empty string on
/// the strict-repeat band; the multiplicity `== 2` doubled-full-
/// set fixture is what forces non-emptiness on the join-string
/// projection).
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` indices a rollout window RE-ENTERED as
/// a compact deterministic wire-string (`"1,3"` — numerically
/// dense, `usize`-round-trippable through `str::parse`) for
/// per-cluster re-entry-witness serialization; an LSP diagnostic
/// that renders the strict-repeat indices of an author-written
/// closed-set field as a comma-joined slot-number hint against a
/// `[Payload; T::CARDINALITY]` slotted lookup table pointing out
/// which slots are RE-VISITED; a Sekiban audit-trail projection
/// whose per-window strict-repeat-index witness renders as a
/// deterministic pipe-joined string across machines regardless of
/// declaration-layout drift; a `tatara-lisp::macro_expand::Expander`
/// hygiene pass that reports the concrete positions of a
/// template's REPEATED bindings as a canonical slash-joined
/// natural-language surface. Each binds to ONE typed N-ary
/// repeat-index-as-string projection on the trait rather than
/// re-deriving the four-primitive
/// `T::repeating_indices(items).iter().map(usize::to_string).collect().join(sep)`
/// composition inline per callsite.
///
/// Compounding closure: the (partition-band × ordering × return-
/// shape) 3×2×2 = 12-corner equivalence-partition index-
/// aggregation surface now EXHAUSTIVELY CLOSES the declaration-
/// order arm of the (partition-band × declaration × join-string)
/// 3-corner row past the [`Self::present_indices_joined`] present-
/// arm opener AND [`Self::missing_indices_joined`] missing-arm
/// closer at its FINAL third tile — [`Self::present_indices_joined`]
/// on (present, declaration, join-string) +
/// [`Self::missing_indices_joined`] on (missing, declaration,
/// join-string) + THIS projection on (repeating, declaration,
/// join-string). The natural next lifts on this face —
/// `sorted_present_indices_joined` / `sorted_missing_indices_joined`
/// / `sorted_repeating_indices_joined` — each bind through their
/// respective sibling Vec-return primitive under the same
/// `usize::to_string` + `slice::join` composition, closing the
/// (partition-band × ordering) 3×2 face on the join-string column
/// at the lex-order row.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// repeat-index-as-string projection becomes a TYPE-level primitive
/// on the closed-set trait rather than a per-consumer inline
/// `T::repeating_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (repeating, index, `String`, declaration)
/// corner was an unnamed inline composition recurring at every
/// prospective downstream "which INDICES did we REPEAT, rendered
/// joined?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from ONE substrate
/// primitive ([`Self::repeating_indices`]) composed with the
/// standard-library `usize::to_string` + `slice::join` combinators,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `",".join(map(str,
/// np.where(np.array([np.sum(items == v) >= 2 for v in all]))[0]))`
/// composing the strict-repeat boolean-mask positional projection
/// with a stringify + join; Julia's `join(string.(findall(v ->
/// count(==(v), items) >= 2, all)), sep)`; Racket's `(string-join
/// (map number->string (filter (lambda (i) (>= (count (curry
/// equal? (list-ref all i)) items) 2)) (range (length all)))) sep)`.
/// Translation through pleme-io primitives: a pure default method
/// composing [`Self::repeating_indices`] with `usize::to_string`
/// and `slice::join` — no new dep, no supertrait bound, no set-
/// shape carrier, no allocation beyond the natural intermediate
/// `Vec<String>` the `slice::join` combinator's per-slot
/// stringification already routes.
fn repeating_indices_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::repeating_indices(items)
.into_iter()
.map(|i| i.to_string())
.collect::<::std::vec::Vec<::std::string::String>>()
.join(sep)
}
/// The N-ARY LEX-ORDER "present indices joined" projection — the
/// `String` rendering of [`Self::sorted_present_indices`] under
/// `usize::to_string` joined by `sep`. Composes the substrate's
/// lex-axis hit-index Vec-return primitive with the per-slot
/// `usize`-to-`String` projection and the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::sorted_present_indices`] automatically satisfies this
/// projection at every downstream site. OPENS the LEX-ORDER row of
/// the (partition-band × ordering × join-string) 3×2 = 6-corner
/// face on the index-join column of the equivalence-partition
/// index-aggregation surface past the just-closed declaration-order
/// row at [`Self::present_indices_joined`], [`Self::missing_indices_joined`],
/// and [`Self::repeating_indices_joined`] one ORDERING axis over.
///
/// Sibling posture to [`Self::sorted_present_labels_joined`] one
/// field-flavor axis over on the (label, index) partition of the
/// lex-order hit-arm join-string surface —
/// [`Self::sorted_present_labels_joined`] renders each hit slot in
/// lex order as a `&'static str` label through [`Self::label`],
/// this method renders each hit slot in lex order as a decimal-
/// `usize` index-under-[`Self::index_of`] rendered through
/// `usize::to_string`. Sibling posture to
/// [`Self::sorted_present_indices`] one return-shape axis over on
/// the (`Vec<usize>`, `String`) partition of the lex-order hit-arm
/// index-aggregation surface — the Vec-return arm materializes
/// each hit slot as a `usize`, this method joins them into a single
/// `String` under the caller's separator. Sibling posture to
/// [`Self::present_indices_joined`] one ORDERING axis over on the
/// (declaration, lex) axis of the index-join column — same
/// partition-band, same return-shape, different ordering.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::sorted_present_indices_joined(items, sep) ==
/// T::sorted_present_indices(items).iter().map(usize::to_string).collect::<Vec<String>>().join(sep)`
/// — the join-string projection binds through the substrate's
/// [`Self::sorted_present_indices`] Vec-return primitive composed
/// with `usize::to_string` and `slice::join`. Pinned by
/// `sorted_present_indices_joined_equals_sorted_present_indices_dot_map_to_string_dot_join_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items` and
/// every separator `sep`, `T::sorted_present_indices_joined(items,
/// sep)` and `T::present_indices_joined(items, sep)` render the
/// SAME hit-index multiset through `usize::to_string + slice::join`
/// — the two projections join the SAME set of indices under the
/// SAME separator, but the OUTPUT byte layout differs whenever
/// declaration order and lex order diverge on the hit-set. On
/// implementors where declaration order aligns with lex order, the
/// two projections coincide byte-for-byte; on implementors that
/// diverge, the two projections diverge on layout while agreeing
/// on membership.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the hit-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering, so the joined `String`
/// matches byte-for-byte under reversal. Pinned by
/// `sorted_present_indices_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_present_indices_joined(&[], sep)`
/// is the empty `String` UNCONDITIONALLY for every `sep` — the
/// empty slice hits zero variants, so [`Self::sorted_present_indices`]
/// yields the empty `Vec`, and `slice::join` on an empty slice
/// yields the empty string. Full-set contract:
/// `T::sorted_present_indices_joined(<T as ClosedSet>::ALL, sep) ==
/// T::sorted_variants().into_iter().map(T::index_of).map(|i| i.to_string()).collect::<Vec<_>>().join(sep)`
/// UNCONDITIONALLY for every `sep` — the pairwise-distinctness
/// invariant pins every variant of [`Self::ALL`] as hitting itself
/// at its own [`Self::index_of`], so every index of
/// `T::sorted_variants` under `T::index_of` survives the filter in
/// lex order and contributes its decimal-`usize` rendering to the
/// join.
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`, `T::sorted_present_indices_joined(items,
/// sep).is_empty() == items.is_empty()` — the lex-order hit-index
/// join-string is empty iff no variant is hit (iff `items` is
/// empty). The bool-projection is INVARIANT under the (declaration,
/// lex) axis because hit-set-emptiness is a function of the
/// hit-set's cardinality alone. Pinned indirectly through the
/// composition law + [`Self::sorted_present_indices`]'s
/// bool-projection identity one return-shape axis over.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` indices a rollout window HIT in
/// canonical LEX order as a compact deterministic wire-string
/// (`"0,2,4"` — numerically dense, `usize`-round-trippable through
/// `str::parse`, AUTHOR-STABLE regardless of `ALL`-array
/// declaration-layout drift because the index positions walk
/// [`Self::sorted_variants`] rather than [`Self::ALL`]) for
/// per-cluster witness serialization; an LSP diagnostic that
/// renders the hit-indices of an author-written closed-set field in
/// canonical lex order as a comma-joined slot-number hint against a
/// `[Payload; T::CARDINALITY]` slotted table; a Sekiban audit-trail
/// projection whose per-window hit-index witness renders as a
/// deterministic pipe-joined string across machines in canonical
/// lex order regardless of declaration-layout drift; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that emits the
/// concrete BOUND vocabulary slot-indices in canonical lex order as
/// a slash-joined natural-language surface. Each binds to ONE
/// typed N-ary lex-order hit-index-as-string projection on the
/// trait rather than re-deriving the four-primitive
/// `T::sorted_present_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// composition inline per callsite.
///
/// Compounding closure: the (partition-band × ordering × return-
/// shape) 3×2×2 = 12-corner equivalence-partition index-
/// aggregation surface now OPENS the (present, lex-order, join-
/// string) corner past the just-exhaustively-closed declaration-
/// order arm of the (partition-band × declaration × join-string)
/// 3-corner row — [`Self::present_indices_joined`] on (present,
/// declaration, join-string), [`Self::missing_indices_joined`] on
/// (missing, declaration, join-string),
/// [`Self::repeating_indices_joined`] on (repeating, declaration,
/// join-string), and THIS projection OPENING the (present,
/// lex-order, join-string) tile of the (partition-band × lex-order
/// × join-string) row. The natural next lifts on this face —
/// `sorted_missing_indices_joined` on (missing, lex-order,
/// join-string) closing the miss-arm one PARTITION-BAND axis over,
/// and `sorted_repeating_indices_joined` on (repeating, lex-order,
/// join-string) EXHAUSTIVELY closing the lex-order row at its
/// final third tile — each bind through their respective sibling
/// lex-order Vec-return primitive under the same `usize::to_string`
/// / `slice::join` composition, closing the (partition-band ×
/// ordering) 3×2 face on the join-string column tile by tile.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order hit-index-as-string projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_present_indices(items).iter().map
/// (usize::to_string).collect::<Vec<_>>().join(sep)` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (present, index, `String`, lex) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which INDICES did we HIT, rendered joined in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of ONE
/// substrate primitive ([`Self::sorted_present_indices`]) with the
/// standard-library `usize::to_string` + `slice::join` combinators,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `",".join(map(str, np.argsort
/// (labels)[np.isin(np.argsort(labels).map(all.__getitem__),
/// items)]))` composing the lex-sorted enumeration's positional
/// projection with a hit-set boolean mask and a stringify + join;
/// Julia's `join(string.(sort(findall(v -> v in items, all),
/// by=i -> label(all[i]))), sep)`; Racket's `(string-join (map
/// number->string (sort (filter (lambda (i) (member (list-ref all
/// i) items)) (range (length all))) #:key (lambda (i) (label
/// (list-ref all i))))) sep)`. Translation through pleme-io
/// primitives: a pure default method composing
/// [`Self::sorted_present_indices`] with `usize::to_string` and
/// `slice::join` — no new dep, no supertrait bound, no set-shape
/// carrier, no allocation beyond the natural intermediate
/// `Vec<String>` the `slice::join` combinator's per-slot
/// stringification already routes.
fn sorted_present_indices_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_present_indices(items)
.into_iter()
.map(|i| i.to_string())
.collect::<::std::vec::Vec<::std::string::String>>()
.join(sep)
}
/// The N-ARY LEX-ORDER "missing indices joined" projection — the
/// `String` rendering of [`Self::sorted_missing_indices`] under
/// `usize::to_string` joined by `sep`. Composes the substrate's
/// lex-axis miss-index Vec-return primitive with the per-slot
/// `usize`-to-`String` projection and the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::sorted_missing_indices`] automatically satisfies this
/// projection at every downstream site. CLOSES the miss-arm one
/// PARTITION-BAND axis over on the LEX-ORDER row of the (partition-
/// band × ordering × join-string) 3×2 = 6-corner face on the index-
/// join column of the equivalence-partition index-aggregation
/// surface past the just-opened [`Self::sorted_present_indices_joined`]
/// present-arm one PARTITION-BAND axis over.
///
/// Sibling posture to [`Self::sorted_present_indices_joined`] one
/// PARTITION-BAND axis over on the (present, missing) axis of the
/// lex-order miss-arm join-string surface — same ordering, same
/// return-shape, DE MORGAN dual partition-band. Sibling posture to
/// [`Self::sorted_missing_indices`] one return-shape axis over on
/// the (`Vec<usize>`, `String`) partition of the lex-order miss-arm
/// index-aggregation surface — the Vec-return arm materializes each
/// miss slot as a `usize`, this method joins them into a single
/// `String` under the caller's separator. Sibling posture to
/// [`Self::missing_indices_joined`] one ORDERING axis over on the
/// (declaration, lex) axis of the miss-index-join column — same
/// partition-band, same return-shape, different ordering. Sibling
/// posture to [`Self::sorted_missing_labels_joined`] one field-
/// flavor axis over on the (label, index) partition of the lex-
/// order miss-arm join-string surface — [`Self::sorted_missing_labels_joined`]
/// renders each miss slot in lex order as a `&'static str` label
/// through [`Self::label`], this method renders each miss slot in
/// lex order as a decimal-`usize` index-under-[`Self::index_of`]
/// rendered through `usize::to_string`.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::sorted_missing_indices_joined(items, sep) ==
/// T::sorted_missing_indices(items).iter().map(usize::to_string).collect::<Vec<String>>().join(sep)`
/// — the join-string projection binds through the substrate's
/// [`Self::sorted_missing_indices`] Vec-return primitive composed
/// with `usize::to_string` and `slice::join`. Pinned by
/// `sorted_missing_indices_joined_equals_sorted_missing_indices_dot_map_to_string_dot_join_across_every_triple`.
///
/// Cross-arm permutation identity: for every slice `items` and
/// every separator `sep`, `T::sorted_missing_indices_joined(items,
/// sep)` and `T::missing_indices_joined(items, sep)` render the
/// SAME miss-index multiset through `usize::to_string + slice::join`
/// — the two projections join the SAME set of indices under the
/// SAME separator, but the OUTPUT byte layout differs whenever
/// declaration order and lex order diverge on the miss-set. On
/// implementors where declaration order aligns with lex order, the
/// two projections coincide byte-for-byte; on implementors that
/// diverge, the two projections diverge on layout while agreeing
/// on membership.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — permuting `items`
/// preserves its multiset of variant identities, and the miss-set
/// membership predicate is a function of that multiset alone. The
/// OUTPUT ordering is fixed by [`Self::sorted_variants`]'s lex
/// order regardless of the input ordering, so the joined `String`
/// matches byte-for-byte under reversal. Pinned by
/// `sorted_missing_indices_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::sorted_missing_indices_joined(&[], sep)
/// == T::sorted_variants().into_iter().map(T::index_of).map(|i|
/// i.to_string()).collect::<Vec<_>>().join(sep)` UNCONDITIONALLY
/// for every `sep` — the empty slice hits zero variants, so every
/// variant passes the "not present" filter and
/// [`Self::sorted_missing_indices`] yields
/// `T::sorted_variants().into_iter().map(T::index_of).collect()`;
/// the join over the resulting decimal-`usize` slots equals the
/// substrate's lex-order full-set index-join exactly under any
/// separator. Full-set contract: `T::sorted_missing_indices_joined(<T
/// as ClosedSet>::ALL, sep)` is the empty `String` UNCONDITIONALLY
/// for every `sep` — the pairwise-distinctness invariant pins every
/// variant of [`Self::ALL`] as hitting itself at its own
/// [`Self::index_of`], so the miss-set is empty on the full slice,
/// [`Self::sorted_missing_indices`] yields the empty `Vec`, and
/// `slice::join` on an empty slice yields the empty string. Both
/// endpoints are DE MORGAN duals of the corresponding
/// [`Self::sorted_present_indices_joined`] endpoints one partition-
/// arm axis over.
///
/// Bool-projection identity: for every slice `items` and every
/// separator `sep`, `T::sorted_missing_indices_joined(items,
/// sep).is_empty() == T::is_covering(items)` — the lex-order miss-
/// index join-string is empty iff the covering predicate holds (iff
/// every variant is hit). The bool-projection is INVARIANT under
/// the (declaration, lex) axis because covering-of-the-miss-set is
/// a function of the miss-set's cardinality alone. Pinned indirectly
/// through the composition law + [`Self::sorted_missing_indices`]'s
/// bool-projection identity one return-shape axis over.
///
/// Future consumers — a `tatara-check` diagnostic that renders the
/// concrete `WorkloadPhase` indices a rollout window MISSED in
/// canonical LEX order as a compact deterministic wire-string
/// (`"1,3,5"` — numerically dense, `usize`-round-trippable through
/// `str::parse`, AUTHOR-STABLE regardless of `ALL`-array
/// declaration-layout drift because the index positions walk
/// [`Self::sorted_variants`] rather than [`Self::ALL`]) for
/// per-cluster gap-witness serialization; an LSP diagnostic that
/// renders the miss-indices of an author-written closed-set field
/// in canonical lex order as a comma-joined slot-number hint
/// against a `[Payload; T::CARDINALITY]` slotted lookup table
/// pointing out which slots are UNCOVERED in canonical lex order;
/// a Sekiban audit-trail projection whose per-window gap-index
/// witness renders as a deterministic pipe-joined string across
/// machines in canonical lex order regardless of declaration-layout
/// drift; a `tatara-lisp::macro_expand::Expander` diagnostic that
/// emits the concrete UNBOUND vocabulary slot-indices in canonical
/// lex order as a slash-joined natural-language surface. Each binds
/// to ONE typed N-ary lex-order miss-index-as-string projection on
/// the trait rather than re-deriving the four-primitive
/// `T::sorted_missing_indices(items).iter().map(usize::to_string).collect::<Vec<_>>().join(sep)`
/// composition inline per callsite.
///
/// Compounding closure: the (partition-band × ordering × return-
/// shape) 3×2×2 = 12-corner equivalence-partition index-
/// aggregation surface now CLOSES the miss-arm one PARTITION-BAND
/// axis over on the LEX-ORDER row of the (partition-band × lex-
/// order × join-string) 3-corner row past the just-opened present-
/// arm [`Self::sorted_present_indices_joined`] one PARTITION-BAND
/// axis over — [`Self::sorted_present_indices_joined`] on (present,
/// lex-order, join-string) + THIS projection on (missing, lex-
/// order, join-string). The natural next lift on this face —
/// `sorted_repeating_indices_joined` on (repeating, lex-order,
/// join-string) EXHAUSTIVELY closing the lex-order row at its
/// FINAL third tile AND EXHAUSTIVELY closing the (partition-band ×
/// ordering × join-string) 3×2 = 6-corner face at its FINAL sixth
/// tile — binds through its sibling lex-order Vec-return primitive
/// [`Self::sorted_repeating_indices`] under the same
/// `usize::to_string` + `slice::join` composition.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary lex-
/// order miss-index-as-string projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline `T::sorted_missing_indices(items).iter().map
/// (usize::to_string).collect::<Vec<_>>().join(sep)` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (missing, index, `String`, lex) corner was an
/// unnamed inline composition recurring at every prospective
/// downstream "which INDICES did we MISS, rendered joined in lex
/// order?" site pre-lift. THEORY.md §VI.1 — generation over
/// composition; the projection emerges from the composition of ONE
/// substrate primitive ([`Self::sorted_missing_indices`]) with the
/// standard-library `usize::to_string` + `slice::join` combinators,
/// not as a per-implementor hand-rolled body.
///
/// Frontier inspiration: NumPy's `",".join(map(str, np.argsort
/// (labels)[~np.isin(np.argsort(labels).map(all.__getitem__),
/// items)]))` composing the lex-sorted enumeration's positional
/// projection with a miss-set boolean mask and a stringify + join;
/// Julia's `join(string.(sort(findall(v -> !(v in items), all),
/// by=i -> label(all[i]))), sep)`; Racket's `(string-join (map
/// number->string (sort (filter (lambda (i) (not (member (list-ref
/// all i) items))) (range (length all))) #:key (lambda (i) (label
/// (list-ref all i))))) sep)`. Translation through pleme-io
/// primitives: a pure default method composing
/// [`Self::sorted_missing_indices`] with `usize::to_string` and
/// `slice::join` — no new dep, no supertrait bound, no set-shape
/// carrier, no allocation beyond the natural intermediate
/// `Vec<String>` the `slice::join` combinator's per-slot
/// stringification already routes.
fn sorted_missing_indices_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::sorted_missing_indices(items)
.into_iter()
.map(|i| i.to_string())
.collect::<::std::vec::Vec<::std::string::String>>()
.join(sep)
}
/// The N-ARY DECLARATION-ORDER "the unique miss-band witness as a
/// singleton-or-empty label Vec" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::unique_missing_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant ABSENT from `items` AND
/// the SOLE absent variant (the miss-band uniqueness guard
/// [`Self::has_unique_missing_variant`] holds). When the guard
/// falsifies the projection collapses to the EMPTY Vec through a
/// zero-allocation short-circuit inherited from
/// [`Self::unique_missing_variants`].
///
/// The `Vec<&'static str>`-RETURN UNIQUE-TIE SHARPENING corner
/// OPENING the LABEL-return column of the (set-level ×
/// `Vec<&'static str>` × equivalence-partition × mult-band ×
/// unique-tie) row past the just-closed variant-return trio
/// ([`Self::unique_missing_variants`],
/// [`Self::unique_repeating_variants`],
/// [`Self::unique_unique_variants`]) one RETURN-SHAPE axis over on
/// the equivalence-partition surface. Peer to [`Self::missing_labels`]
/// one UNIQUE-TIE-SHARPENING axis over on the label-Vec return column
/// (unsharpened miss-set label collection → uniqueness-gated singleton-
/// or-empty label collection). Peer to
/// [`Self::unique_missing_variants`] one RETURN-SHAPE axis over on
/// the miss-band unique-tie corner (variant-Vec witness → label-Vec
/// witness of the same singleton-or-empty binding).
///
/// Composition law: for every slice `items`,
/// `T::unique_missing_labels(items) ==
/// T::unique_missing_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::unique_missing_variants`] Vec-return primitive composed
/// with the per-slot [`Self::label`] projection. Pinned by
/// `unique_missing_labels_equals_unique_missing_variants_mapped_under_label_across_every_triple`.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_missing_labels(items) ==
/// if T::has_unique_missing_variant(items) { T::missing_labels(items) } else { vec![] }`
/// — the uniqueness-gated label Vec coincides with the boolean-
/// guarded miss-set label Vec through the composition of
/// [`Self::unique_missing_variants`]'s guard-arm with [`Self::label`].
/// Pinned by
/// `unique_missing_labels_equals_has_unique_missing_variant_gated_missing_labels_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_missing_labels(items).len() ==
/// usize::from(T::has_unique_missing_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level miss-band uniqueness bit
/// projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds (since the label-Vec inherits the
/// singleton-or-empty length discipline from
/// [`Self::unique_missing_variants`] one RETURN-SHAPE axis over
/// under the injective per-slot [`Self::label`] projection). Pinned
/// by
/// `unique_missing_labels_len_equals_has_unique_missing_variant_as_usize_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_missing_labels(items).is_empty() ==
/// !T::has_unique_missing_variant(items)` — the label-Vec's
/// emptiness coincides with the NEGATION of the set-level uniqueness
/// bit. Independent cross-check on the surface axis distinct from
/// the length-coincidence arm (`Vec::is_empty` vs integer equality).
/// Pinned by
/// `unique_missing_labels_is_empty_iff_not_has_unique_missing_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_missing_variants`] factors through the ordering-
/// agnostic [`Self::has_unique_missing_variant`] +
/// [`Self::missing_variants`] pair, and [`Self::label`] is a pure
/// projection. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned by
/// `unique_missing_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::unique_missing_labels(&[]) == vec![]` — the empty slice puts
/// every variant in the miss band, [`Self::count_missing`] reports
/// `T::CARDINALITY >= 2`, the uniqueness guard falsifies via
/// `count != 1`, and the projection collapses to the empty Vec.
/// At cardinality `== 1` the empty slice pins `count_missing == 1`,
/// the guard holds, and the projection returns
/// `vec![T::ALL[0].label()]`.
///
/// Full-set contract: `T::unique_missing_labels(<T as ClosedSet>::ALL) ==
/// vec![]` UNCONDITIONALLY — the pairwise-distinctness invariant
/// pins every variant at exactly one position of the full-set
/// slice, [`Self::count_missing`] reports `0`, the guard falsifies
/// via `0 != 1`, and the projection collapses to the empty Vec.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[2]` sits at count
/// `0` (the SOLE absent variant), [`Self::count_missing`] reports
/// `1`, [`Self::has_unique_missing_variant`] returns `true`, the
/// guard holds, and the projection returns
/// `vec![T::ALL[2].label()]` — the LOAD-BEARING sole non-empty arm
/// on the multi-variant test-module fixture at the canonical
/// bimodal cardinality.
///
/// Future consumers — a `tatara-check` predicate `(check-missing-if-
/// unique …)` that reports the singleton-or-empty miss-band label
/// witness as a typed author-facing string list rather than a two-
/// step (has-unique-missing-variant? then missing-labels)
/// composition; an LSP diagnostic on a Lisp-author-written closed-
/// set field that renders "the sole omitted label" (only when
/// uniquely omitted) as author-facing completion text (`":severities
/// [:info :warn] — sole omission: error"`); a Sekiban audit-trail
/// projection whose per-window "sole missing label" witness renders
/// as a deterministic label list across machines; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that emits THE
/// LONE unbound vocabulary identifier's label when uniqueness holds
/// through a single typed label-Vec rather than a two-step
/// composition. Each binds to ONE typed N-ary uniqueness-gated
/// miss-witness label projection on the trait rather than re-
/// deriving the four-primitive
/// `unique_missing_variants + label + map + collect` composition
/// inline per callsite.
///
/// Compounding closure: this projection OPENS the label-return
/// column of the (set-level × `Vec<&'static str>` × equivalence-
/// partition × mult-band × unique-tie) row past the just-closed
/// variant-return trio ([`Self::unique_missing_variants`],
/// [`Self::unique_repeating_variants`],
/// [`Self::unique_unique_variants`]) one RETURN-SHAPE axis over
/// on the equivalence-partition surface. The natural next lifts on
/// this face — `unique_missing_labels_joined` on the join-string
/// return axis; `unique_repeating_labels` / `unique_unique_labels`
/// on the peer multiplicity-band arms; the lex-order peers under
/// `sorted_unique_*_labels` — each bind through the same
/// composition of the uniqueness-gated variant Vec under
/// [`Self::label`].
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated miss-label projection becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline
/// `T::unique_missing_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × label × equivalence-partition
/// × mult `== 0` × unique-tie) corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// missing label, if unique, else nothing" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the projection emerges from
/// the composition of TWO substrate primitives
/// ([`Self::unique_missing_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); miss <-
/// setdiff(all, names(t)); if (length(miss) == 1) miss else
/// character(0) }` on a factor histogram; Clojure's
/// `(let [miss (remove (set items) all)] (if (= 1 (count miss))
/// [(label (first miss))] []))`; Julia's `let miss =
/// setdiff(all, items); length(miss) == 1 ? [label(only(miss))] :
/// String[] end`; Haskell's `case all \\ items of [v] -> [label v]
/// ; _ -> []` on the `Bounded + Enum + Show` type-class trio.
/// Translation through pleme-io primitives: a pure default method
/// mapping the just-lifted [`Self::unique_missing_variants`] Vec-
/// return primitive under the per-slot [`Self::label`] projection —
/// no new dep, no supertrait bound, no set-shape carrier.
fn unique_missing_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::unique_missing_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "the unique strict-repeat witness as a
/// singleton-or-empty label Vec" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::unique_repeating_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant that appears TWO-OR-MORE
/// times in `items` AND is the SOLE strict-repeat variant (the
/// strict-repeat uniqueness guard
/// [`Self::has_unique_repeating_variant`] holds). When the guard
/// falsifies the projection collapses to the EMPTY Vec through a
/// zero-allocation short-circuit inherited from
/// [`Self::unique_repeating_variants`].
///
/// The `Vec<&'static str>`-RETURN UNIQUE-TIE SHARPENING corner
/// CLOSING the strict-repeat arm of the (set-level ×
/// `Vec<&'static str>` × equivalence-partition × mult-band ×
/// unique-tie) row past the just-opened (mult `== 0`) miss-band arm
/// [`Self::unique_missing_labels`] one MULTIPLICITY-BAND axis over on
/// the equivalence-partition surface. Peer to
/// [`Self::repeating_labels`] one UNIQUE-TIE-SHARPENING axis over on
/// the label-Vec return column (unsharpened strict-repeat label
/// collection → uniqueness-gated singleton-or-empty label collection).
/// Peer to [`Self::unique_repeating_variants`] one RETURN-SHAPE axis
/// over on the strict-repeat unique-tie corner (variant-Vec witness
/// → label-Vec witness of the same singleton-or-empty binding).
///
/// Composition law: for every slice `items`,
/// `T::unique_repeating_labels(items) ==
/// T::unique_repeating_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::unique_repeating_variants`] Vec-return primitive composed
/// with the per-slot [`Self::label`] projection. Pinned by
/// `unique_repeating_labels_equals_unique_repeating_variants_mapped_under_label_across_every_triple`.
///
/// Guarded-witness-collection identity: for every slice `items`,
/// `T::unique_repeating_labels(items) ==
/// if T::has_unique_repeating_variant(items) { T::repeating_labels(items) } else { vec![] }`
/// — the uniqueness-gated label Vec coincides with the boolean-
/// guarded strict-repeat label Vec through the composition of
/// [`Self::unique_repeating_variants`]'s guard-arm with
/// [`Self::label`]. Pinned by
/// `unique_repeating_labels_equals_has_unique_repeating_variant_gated_repeating_labels_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_repeating_labels(items).len() ==
/// usize::from(T::has_unique_repeating_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level strict-repeat uniqueness
/// bit projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds (since the label-Vec inherits the
/// singleton-or-empty length discipline from
/// [`Self::unique_repeating_variants`] one RETURN-SHAPE axis over
/// under the injective per-slot [`Self::label`] projection). Pinned
/// by
/// `unique_repeating_labels_len_equals_has_unique_repeating_variant_as_usize_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_repeating_labels(items).is_empty() ==
/// !T::has_unique_repeating_variant(items)` — the label-Vec's
/// emptiness coincides with the NEGATION of the set-level uniqueness
/// bit. Independent cross-check on the surface axis distinct from
/// the length-coincidence arm (`Vec::is_empty` vs integer equality).
/// Pinned by
/// `unique_repeating_labels_is_empty_iff_not_has_unique_repeating_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_repeating_variants`] factors through the ordering-
/// agnostic [`Self::has_unique_repeating_variant`] +
/// [`Self::repeating_variants`] pair, and [`Self::label`] is a pure
/// projection. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned by
/// `unique_repeating_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_repeating_labels(&[]) == vec![]`
/// UNCONDITIONALLY — the empty slice hits zero positions, every per-
/// target multiplicity is `0`, [`Self::count_repeating_variants`]
/// reports `0`, the uniqueness guard falsifies via `0 != 1`, and the
/// projection collapses to the empty Vec.
///
/// Full-set contract: `T::unique_repeating_labels(<T as ClosedSet>::ALL) ==
/// vec![]` UNCONDITIONALLY — the pairwise-distinctness invariant
/// pins every variant at exactly one position of the full-set slice,
/// every per-target multiplicity is `1`, the strict-repeat `>= 2`
/// test fails at every target, [`Self::count_repeating_variants`]
/// reports `0`, the guard falsifies via `0 != 1`, and the projection
/// collapses to the empty Vec.
///
/// Doubled-full-set contract: `T::unique_repeating_labels` on the
/// doubled full set returns `vec![T::ALL[0].label()]` iff
/// [`Self::CARDINALITY`] `== 1`, else `vec![]` — every variant hits
/// multiplicity `2` (satisfying the strict-repeat `>= 2` test at
/// every target), so [`Self::count_repeating_variants`] reports
/// [`Self::CARDINALITY`]; the uniqueness guard `count == 1` holds
/// EXACTLY when [`Self::CARDINALITY`] `== 1`. At `T::CARDINALITY == 1`
/// the guarded lift returns `vec![T::ALL[0].label()]` (the sole
/// strict-repeat witness); at `T::CARDINALITY >= 2` every variant is
/// a strict-repeat witness, uniqueness fails, and the guard
/// collapses to `vec![]`.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2` (the SOLE strict-repeat witness), `T::ALL[1]` at count `1`
/// (unique-band, not strict-repeat), `T::ALL[2..]` at count `0`
/// (miss-band); [`Self::count_repeating_variants`] reports `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, the guard
/// holds, and the projection returns `vec![T::ALL[0].label()]` —
/// the LOAD-BEARING sole non-empty arm on the multi-variant test-
/// module fixture at the canonical bimodal cardinality. LOAD-BEARING
/// DISJOINT-WITNESS mirror of [`Self::unique_missing_labels`]
/// (returns `vec![T::ALL[2].label()]`) AND
/// [`Self::unique_repeating_variants`] (returns `vec![T::ALL[0]]`) on
/// the SAME fixture at cardinality `== 3` — the MULTIPLICITY-BAND
/// axis SEPARATES the (mult `>= 2`) strict-repeat positive arm
/// (WITNESS `T::ALL[0].label()`) from the (mult `== 0`) miss-band
/// positive arm (WITNESS `T::ALL[2].label()`) on the shared canonical
/// fixture window: the two label positive arms report TWO DIFFERENT
/// witnesses one MULTIPLICITY-BAND axis apart, pinning the miss-band
/// / strict-repeat band separation on the LABEL-return column under
/// the injective per-slot [`Self::label`] projection.
///
/// Future consumers — a `tatara-check` predicate `(check-repeating-
/// if-unique …)` that reports the singleton-or-empty strict-repeat
/// label witness as a typed author-facing string list rather than a
/// two-step (has-unique-repeating-variant? then repeating-labels)
/// composition; an LSP diagnostic on a Lisp-author-written closed-
/// set field that renders "the sole duplicated label" (only when
/// uniquely duplicated) as author-facing completion text
/// (`":severities [:info :warn :info] — sole duplicate: info"`); a
/// Sekiban audit-trail projection whose per-window "sole duplicate
/// label" witness renders as a deterministic label list across
/// machines; a `tatara-lisp::macro_expand::Expander` diagnostic that
/// emits THE LONE re-bound vocabulary identifier's label when
/// uniqueness holds through a single typed label-Vec rather than a
/// two-step composition. Each binds to ONE typed N-ary uniqueness-
/// gated strict-repeat-witness label projection on the trait rather
/// than re-deriving the four-primitive
/// `unique_repeating_variants + label + map + collect` composition
/// inline per callsite.
///
/// Compounding closure: this projection CLOSES the strict-repeat arm
/// of the (set-level × `Vec<&'static str>` × equivalence-partition ×
/// mult-band × unique-tie) row past the just-opened (mult `== 0`)
/// miss-band arm [`Self::unique_missing_labels`] one MULTIPLICITY-
/// BAND axis over on the equivalence-partition surface. The (mult-
/// band × return-shape) 3×2 face on the unique-tie subsurface now
/// sits 5/6 closed at (miss, variant), (strict-repeat, variant),
/// (unique-band, variant), (miss, label), (strict-repeat, label) —
/// with the (unique-band, label) `unique_unique_labels` corner as
/// the natural next lift EXHAUSTIVELY CLOSING the row at 6/6.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated strict-repeat-label projection becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-consumer
/// inline
/// `T::unique_repeating_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × label × equivalence-partition
/// × mult `>= 2` × unique-tie) corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// duplicated label, if unique, else nothing" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::unique_repeating_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); reps <-
/// names(t)[t >= 2]; if (length(reps) == 1) reps else character(0) }`
/// on a factor histogram; Clojure's `(let [reps (filter #(>= (val %)
/// 2) (frequencies coll))] (if (= 1 (count reps)) [(name (key (first
/// reps)))] []))`; Julia's `let reps = [v for v in all if
/// count(==(v), items) >= 2]; length(reps) == 1 ? [label(only(reps))]
/// : String[] end`; Haskell's `case [v | v <- all, length (filter
/// (==v) items) >= 2] of [v] -> [label v] ; _ -> []` on the
/// `Bounded + Enum + Show + Eq` type-class quartet. Translation
/// through pleme-io primitives: a pure default method mapping the
/// just-lifted [`Self::unique_repeating_variants`] Vec-return
/// primitive under the per-slot [`Self::label`] projection — no new
/// dep, no supertrait bound, no set-shape carrier.
fn unique_repeating_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::unique_repeating_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "the unique unique-band witness as a
/// singleton-or-empty label Vec" projection — the
/// `Vec<&'static str>` label rendering of
/// [`Self::unique_unique_variants`] under [`Self::label`]. Every
/// label `s` in the returned vector is the canonical
/// [`Self::label`] rendering of some variant that appears EXACTLY
/// ONCE in `items` AND is the SOLE unique-band variant (the
/// unique-band uniqueness guard [`Self::has_unique_unique_variant`]
/// holds). When the guard falsifies the projection collapses to
/// the EMPTY Vec through a zero-allocation short-circuit inherited
/// from [`Self::unique_unique_variants`].
///
/// The `Vec<&'static str>`-RETURN UNIQUE-BAND UNIQUE-TIE SHARPENING
/// corner EXHAUSTIVELY CLOSING the (set-level × `Vec<&'static str>` ×
/// equivalence-partition × mult-band × unique-tie) 3-corner row at
/// its FINAL THIRD tile past the just-opened (mult `== 0`) miss-band
/// arm [`Self::unique_missing_labels`] AND the just-closed
/// (mult `>= 2`) strict-repeat arm [`Self::unique_repeating_labels`]
/// one MULTIPLICITY-BAND axis over on the equivalence-partition
/// surface. The (mult-band × return-shape) 3×2 face on the
/// unique-tie subsurface now sits 6/6 CLOSED at (miss, variant),
/// (strict-repeat, variant), (unique-band, variant), (miss, label),
/// (strict-repeat, label), and THIS (unique-band, label) corner —
/// EXHAUSTIVE closure of the equivalence-partition unique-tie
/// subsurface across BOTH the multiplicity-band trichotomy AND the
/// (Vec-of-variant, Vec-of-label) return-shape dichotomy.
///
/// Peer to [`Self::unique_unique_variants`] one RETURN-SHAPE axis
/// over on the unique-band unique-tie corner (variant-Vec witness →
/// label-Vec witness of the same singleton-or-empty binding).
///
/// Composition law: for every slice `items`,
/// `T::unique_unique_labels(items) ==
/// T::unique_unique_variants(items).into_iter().map(T::label).collect()`
/// — the label-Vec projection binds through the substrate's
/// [`Self::unique_unique_variants`] Vec-return primitive composed
/// with the per-slot [`Self::label`] projection. Pinned by
/// `unique_unique_labels_equals_unique_unique_variants_mapped_under_label_across_every_triple`.
///
/// Length coincidence identity: for every slice `items`,
/// `T::unique_unique_labels(items).len() ==
/// usize::from(T::has_unique_unique_variant(items))` — the return-
/// Vec's length COINCIDES with the set-level unique-band uniqueness
/// bit projected onto `usize`: exactly `0` when the bit falsifies,
/// exactly `1` when it holds (since the label-Vec inherits the
/// singleton-or-empty length discipline from
/// [`Self::unique_unique_variants`] one RETURN-SHAPE axis over
/// under the injective per-slot [`Self::label`] projection). Pinned
/// by
/// `unique_unique_labels_len_equals_has_unique_unique_variant_as_usize_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items`,
/// `T::unique_unique_labels(items).is_empty() ==
/// !T::has_unique_unique_variant(items)` — the label-Vec's
/// emptiness coincides with the NEGATION of the set-level uniqueness
/// bit. Independent cross-check on the surface axis distinct from
/// the length-coincidence arm (`Vec::is_empty` vs integer equality).
/// Pinned by
/// `unique_unique_labels_is_empty_iff_not_has_unique_unique_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_unique_variants`] factors through the
/// ordering-agnostic [`Self::has_unique_unique_variant`] +
/// [`Self::unique_variants`] pair, and [`Self::label`] is a pure
/// projection. The OUTPUT ordering is fixed by [`Self::ALL`]'s
/// declaration order regardless of the input ordering. Pinned by
/// `unique_unique_labels_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_unique_labels(&[]) == vec![]`
/// UNCONDITIONALLY — the empty slice hits zero positions, every
/// per-target multiplicity is `0`, [`Self::count_unique_variants`]
/// reports `0`, the uniqueness guard falsifies via `0 != 1`, and
/// the projection collapses to the empty Vec.
///
/// Full-set contract: `T::unique_unique_labels(<T as ClosedSet>::ALL)`
/// returns `vec![T::ALL[0].label()]` iff [`Self::CARDINALITY`] `== 1`,
/// else `vec![]` — pairwise-distinctness pins every variant at
/// exactly one position of the full-set slice, so every per-target
/// multiplicity is `1` and [`Self::count_unique_variants`] reports
/// [`Self::CARDINALITY`]. The uniqueness guard `count == 1` holds
/// EXACTLY when [`Self::CARDINALITY`] `== 1`. At `T::CARDINALITY == 1`
/// the guarded lift returns `vec![T::ALL[0].label()]` (the sole
/// unique-band witness); at `T::CARDINALITY >= 2` every variant is
/// a unique-band witness, uniqueness fails at `T::CARDINALITY != 1`,
/// and the guard collapses to `vec![]`.
///
/// Doubled-full-set contract:
/// `T::unique_unique_labels(&doubled) == vec![]` UNCONDITIONALLY —
/// every variant sits at count `2` (strict-repeat, NOT unique-band),
/// so [`Self::count_unique_variants`] reports `0`, the uniqueness
/// guard falsifies via `0 != 1`, and the projection collapses to
/// the empty Vec at every cardinality. DISTINCT from the
/// [`Self::unique_repeating_labels`] sibling one MULTIPLICITY-BAND
/// axis over, which returns `vec![T::ALL[0].label()]` at
/// `T::CARDINALITY == 1` (the sole strict-repeat witness).
///
/// Matching-singleton positive-arm contract: for every variant `v`
/// in [`Self::ALL`], `T::unique_unique_labels(&[v]) ==
/// vec![v.label()]` UNCONDITIONALLY — the target hits count `1`
/// (the SOLE unique-band witness), every non-target sits at count
/// `0`, [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] holds, and the composition
/// returns the singleton label Vec of the sole unique-band variant.
/// LOAD-BEARING NON-EMPTY DEGENERATE arm inherited from
/// [`Self::unique_unique_variants`]'s matching-singleton discipline
/// — DISTINCT from [`Self::unique_repeating_labels`] which
/// collapses to `vec![]` on every matching singleton AND from
/// [`Self::unique_missing_labels`] whose singleton behavior is
/// CARDINALITY-dependent.
///
/// Bimodal-triple contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `T::ALL[0]` sits at count
/// `2` (strict-repeat, NOT unique-band), `T::ALL[1]` at count `1`
/// (the SOLE unique-band witness), `T::ALL[2..]` at count `0`
/// (miss-band); [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, the guard
/// holds, and the projection returns `vec![T::ALL[1].label()]` —
/// the LOAD-BEARING sole non-empty arm on the multi-variant
/// test-module fixture at the canonical bimodal cardinality.
/// LOAD-BEARING TRICHOTOMY DISCRIMINATOR from
/// [`Self::unique_missing_labels`] (returns `vec![T::ALL[2].label()]`)
/// AND [`Self::unique_repeating_labels`] (returns
/// `vec![T::ALL[0].label()]`) on the SAME fixture at cardinality
/// `== 3` — the MULTIPLICITY-BAND axis EXHAUSTIVELY PARTITIONS the
/// three positive label arms at THREE DIFFERENT witnesses
/// (`T::ALL[0].label()`, `T::ALL[1].label()`, `T::ALL[2].label()`)
/// on the shared canonical fixture window under the injective
/// per-slot [`Self::label`] projection. The three label positive
/// arms report THREE DIFFERENT witnesses one MULTIPLICITY-BAND axis
/// apart, pinning the miss-band / strict-repeat / unique-band
/// separation on the LABEL-return column.
///
/// Future consumers — a `tatara-check` predicate `(check-unique-
/// if-unique …)` that reports the singleton-or-empty unique-band
/// label witness as a typed author-facing string list rather than a
/// two-step (has-unique-unique-variant? then unique-variants →
/// map label) composition; an LSP diagnostic on a Lisp-author-
/// written closed-set field that renders "the sole once-occurring
/// label" (only when uniquely once-occurring) as author-facing
/// completion text (`":severities [:info :warn :info] — sole
/// once-occurring: warn"`); a Sekiban audit-trail projection whose
/// per-window "sole once-occurring label" witness renders as a
/// deterministic label list across machines; a
/// `tatara-lisp::macro_expand::Expander` diagnostic that emits THE
/// LONE singly-bound vocabulary identifier's label when uniqueness
/// holds through a single typed label-Vec rather than a two-step
/// composition. Each binds to ONE typed N-ary uniqueness-gated
/// unique-band-witness label projection on the trait rather than
/// re-deriving the four-primitive `unique_unique_variants + label +
/// map + collect` composition inline per callsite.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (set-level × `Vec<&'static str>` × equivalence-partition ×
/// mult-band × unique-tie) 3-corner row at its FINAL THIRD tile
/// past the miss + strict-repeat arms one MULTIPLICITY-BAND axis
/// over on the equivalence-partition surface AND CLOSES the
/// (mult-band × return-shape) 3×2 face on the unique-tie subsurface
/// at 6/6. The natural next lifts past this closure are the lex-
/// order peers `sorted_unique_missing_labels` /
/// `sorted_unique_repeating_labels` / `sorted_unique_unique_labels`
/// (one ORDERING axis over) and the joined-string peers
/// `unique_missing_labels_joined` / `unique_repeating_labels_joined`
/// / `unique_unique_labels_joined` (one RETURN-SHAPE axis further,
/// from Vec-label to joined String) — each binds through the same
/// composition of the uniqueness-gated variant Vec under
/// [`Self::label`] plus the ordering / join primitive.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated unique-band-label projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline
/// `T::unique_unique_variants(items).into_iter().map(T::label).collect()`
/// composition at every downstream generic site. THEORY.md §V.1 —
/// knowable platform; the (set-level × label × equivalence-partition
/// × mult `== 1` × unique-tie) corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// once-occurring label, if unique, else nothing" site pre-lift.
/// THEORY.md §VI.1 — generation over composition; the projection
/// emerges from the composition of TWO substrate primitives
/// ([`Self::unique_unique_variants`] + [`Self::label`]) via
/// `Iterator::map` + `Iterator::collect`, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); ones <-
/// names(t)[t == 1]; if (length(ones) == 1) ones else character(0) }`
/// on a factor histogram; Clojure's `(let [ones (filter (fn [[_ n]]
/// (= n 1)) (frequencies coll))] (if (= 1 (count ones)) [(name (key
/// (first ones)))] []))`; Julia's `let ones = [v for v in all if
/// count(==(v), items) == 1]; length(ones) == 1 ? [label(only(ones))]
/// : String[] end`; Haskell's `case [v | v <- all, length (filter
/// (==v) items) == 1] of [v] -> [label v] ; _ -> []` on the
/// `Bounded + Enum + Show + Eq` type-class quartet. Translation
/// through pleme-io primitives: a pure default method mapping the
/// pre-existing [`Self::unique_unique_variants`] Vec-return primitive
/// under the per-slot [`Self::label`] projection — no new dep, no
/// supertrait bound, no set-shape carrier.
fn unique_unique_labels(items: &[Self]) -> ::std::vec::Vec<&'static str> {
<Self as ClosedSet>::unique_unique_variants(items)
.into_iter()
.map(<Self as ClosedSet>::label)
.collect()
}
/// The N-ARY DECLARATION-ORDER "the unique miss-band witness as a
/// singleton-or-empty joined-label String" projection — the `String`
/// rendering of [`Self::unique_missing_labels`] joined by `sep`.
/// Composes the substrate's just-lifted uniqueness-gated miss-band
/// label-Vec primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::unique_missing_labels`] automatically satisfies this
/// projection at every downstream site. When the miss-band uniqueness
/// guard [`Self::has_unique_missing_variant`] holds, the projection
/// returns the sole absent variant's label as a bare `String` (no
/// separator surfaces because the joined slice is a singleton); when
/// the guard falsifies, the projection collapses to the EMPTY
/// `String` through a zero-allocation short-circuit inherited from
/// [`Self::unique_missing_labels`].
///
/// The `String`-RETURN UNIQUE-TIE SHARPENING corner OPENING the
/// JOIN-STRING column of the (set-level × `String` ×
/// equivalence-partition × mult-band × unique-tie) row past the
/// just-closed label-Vec trio ([`Self::unique_missing_labels`],
/// [`Self::unique_repeating_labels`], [`Self::unique_unique_labels`])
/// one RETURN-SHAPE axis over on the equivalence-partition surface.
/// Peer to [`Self::missing_labels_joined`] one UNIQUE-TIE-SHARPENING
/// axis over on the join-string return column (unsharpened miss-set
/// label-join → uniqueness-gated singleton-or-empty label-join).
/// Peer to [`Self::unique_missing_labels`] one RETURN-SHAPE axis over
/// on the miss-band unique-tie corner (label-Vec witness → joined-
/// String witness of the same singleton-or-empty binding).
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::unique_missing_labels_joined(items, sep) ==
/// T::unique_missing_labels(items).join(sep)` — the joined-String
/// projection binds through the substrate's
/// [`Self::unique_missing_labels`] Vec-return primitive composed with
/// `slice::join`. Pinned by
/// `unique_missing_labels_joined_equals_unique_missing_labels_dot_join_across_every_triple`.
///
/// Guarded-witness-collection identity: for every slice `items` and
/// every separator `sep`, `T::unique_missing_labels_joined(items,
/// sep) == if T::has_unique_missing_variant(items) {
/// T::missing_labels_joined(items, sep) } else { String::new() }` —
/// the uniqueness-gated join-String coincides with the boolean-
/// guarded miss-set label-join through the composition of
/// [`Self::unique_missing_labels`]'s guard-arm with `slice::join`.
/// Pinned by
/// `unique_missing_labels_joined_equals_has_unique_missing_variant_gated_missing_labels_joined_across_every_triple`.
///
/// Bare-label singleton identity: for every slice `items` on which
/// [`Self::has_unique_missing_variant`] holds AND for every separator
/// `sep`, `T::unique_missing_labels_joined(items, sep) ==
/// T::unique_missing_labels(items)[0]` (as `String`) — because the
/// underlying label-Vec is a SINGLETON on the positive arm, the
/// separator NEVER surfaces in the output; `slice::join` on a
/// singleton `[label]` returns `label.to_string()` regardless of
/// `sep`. Pinned by
/// `unique_missing_labels_joined_is_separator_agnostic_on_the_positive_arm_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items` and every
/// separator `sep`, `T::unique_missing_labels_joined(items,
/// sep).is_empty() == !T::has_unique_missing_variant(items)` — the
/// join-String's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check binding the
/// String-return uniqueness projection against the bool-column
/// projection one return-shape column over, and against the sibling
/// [`Self::unique_missing_labels`] `is_empty` identity one return-
/// shape column over on the Vec-return arm. Pinned by
/// `unique_missing_labels_joined_is_empty_iff_not_has_unique_missing_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_missing_labels`] factors through the
/// ordering-agnostic [`Self::has_unique_missing_variant`] +
/// [`Self::missing_variants`] pair under [`Self::label`], and
/// `slice::join` is a pure combinator. The OUTPUT byte layout is
/// fixed by [`Self::ALL`]'s declaration order regardless of the
/// input ordering, so the joined `String` matches byte-for-byte
/// under reversal. Pinned by
/// `unique_missing_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract at cardinality `>= 2`:
/// `T::unique_missing_labels_joined(&[], sep) == String::new()` for
/// every `sep` — the empty slice puts every variant in the miss
/// band, [`Self::count_missing`] reports `T::CARDINALITY >= 2`, the
/// uniqueness guard falsifies via `count != 1`, the label-Vec
/// collapses to `vec![]`, and `slice::join` on an empty slice yields
/// the empty `String`. At cardinality `== 1` the empty slice pins
/// `count_missing == 1`, the guard holds, and the projection returns
/// `T::ALL[0].label().to_string()` for every `sep`.
///
/// Full-set contract: `T::unique_missing_labels_joined(<T as
/// ClosedSet>::ALL, sep) == String::new()` UNCONDITIONALLY for every
/// `sep` — the pairwise-distinctness invariant pins every variant at
/// exactly one position of the full-set slice,
/// [`Self::count_missing`] reports `0`, the guard falsifies via
/// `0 != 1`, the label-Vec collapses to `vec![]`, and `slice::join`
/// on the empty slice yields the empty `String`.
///
/// Doubled-full-set contract:
/// `T::unique_missing_labels_joined(&doubled, sep) == String::new()`
/// UNCONDITIONALLY for every `sep` — every variant sits at count
/// `2` (strict-repeat, NOT miss-band), so [`Self::count_missing`]
/// reports `0`, the uniqueness guard falsifies via `0 != 1`, and the
/// projection collapses to the empty `String` at every cardinality.
///
/// Bimodal-triple positive-arm contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` for every `sep`, `T::ALL[2]`
/// sits at count `0` (the SOLE absent variant),
/// [`Self::count_missing`] reports `1`,
/// [`Self::has_unique_missing_variant`] returns `true`, the label-
/// Vec collapses to `vec![T::ALL[2].label()]`, and `slice::join` on
/// the singleton returns `T::ALL[2].label().to_string()` — the
/// SEPARATOR-AGNOSTIC positive arm on the multi-variant test-module
/// fixture at the canonical bimodal cardinality (the separator
/// NEVER surfaces because the joined slice is a singleton).
///
/// Empty-separator degeneracy: on the positive arm, the joined
/// `String` equals the sole absent label EXACTLY under the empty
/// separator (the joined slice is a singleton, `slice::join` on a
/// singleton is identity-into-`String`); on the negative arm, the
/// joined `String` is empty. Independent cross-check that the
/// combinator threads the empty separator through without inserting
/// a spurious rendering. Pinned by
/// `unique_missing_labels_joined_threads_empty_separator_into_a_concatenated_run`.
///
/// Multi-char separator verbatim: on the positive arm, the multi-
/// character separator NEVER surfaces because the label-Vec is a
/// singleton; on the negative arm, the output is the empty `String`.
/// Independent cross-check that the combinator does not treat only
/// single-character separators verbatim, pinning the same identity
/// under a multi-byte separator surface. Pinned by
/// `unique_missing_labels_joined_threads_multi_char_separator_verbatim`.
///
/// Future consumers — a `tatara-check` predicate `(check-missing-if-
/// unique-joined …)` that reports the singleton-or-empty miss-band
/// join-String witness as a typed author-facing scalar rather than a
/// three-step (has-unique-missing-variant? then missing-labels then
/// join) composition; an LSP diagnostic on a Lisp-author-written
/// closed-set field that renders "the sole omitted label" (only when
/// uniquely omitted) as an author-facing scalar completion string
/// (`":severities [:info :warn] — sole omission: error"` where the
/// suffix is `.to_string()` of the sole miss label); a Sekiban
/// audit-trail projection whose per-window "sole missing label"
/// witness renders as a deterministic scalar across machines
/// (rather than a Vec that a downstream consumer must join
/// separately); a `tatara-lisp::macro_expand::Expander` diagnostic
/// that emits THE LONE unbound vocabulary identifier's label when
/// uniqueness holds through a single typed String rather than a
/// three-step composition. Each binds to ONE typed N-ary
/// uniqueness-gated miss-witness join-String projection on the
/// trait rather than re-deriving the three-primitive
/// `unique_missing_labels + join` composition inline per callsite.
///
/// Compounding closure: this projection OPENS the JOIN-STRING
/// return column of the (set-level × `String` × equivalence-
/// partition × mult-band × unique-tie) row past the just-closed
/// label-Vec trio ([`Self::unique_missing_labels`],
/// [`Self::unique_repeating_labels`], [`Self::unique_unique_labels`])
/// one RETURN-SHAPE axis over on the equivalence-partition surface.
/// The (mult-band × return-shape) 3×3 face on the unique-tie
/// subsurface now sits 7/9 closed at (miss, variant),
/// (strict-repeat, variant), (unique-band, variant), (miss, label),
/// (strict-repeat, label), (unique-band, label), and THIS
/// (miss, join-String) corner — with the (strict-repeat, join-String)
/// `unique_repeating_labels_joined` corner and the (unique-band,
/// join-String) `unique_unique_labels_joined` corner as the natural
/// next lifts closing the row past this opener.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated miss-band join-String projection becomes a
/// TYPE-level primitive on the closed-set trait rather than a
/// per-consumer inline
/// `T::unique_missing_labels(items).join(sep)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (set-level × `String` × equivalence-partition × mult `== 0`
/// × unique-tie) corner was an unnamed inline composition recurring
/// at every prospective downstream "the sole missing label as a
/// bare string, if unique, else empty" site pre-lift. THEORY.md
/// §VI.1 — generation over composition; the projection emerges
/// from the composition of ONE substrate primitive
/// ([`Self::unique_missing_labels`]) with the standard-library
/// `slice::join` combinator, not as a per-implementor hand-rolled
/// body.
///
/// Frontier inspiration: R's `{ t <- table(items); miss <-
/// setdiff(all, names(t)); if (length(miss) == 1) miss[[1]] else ""
/// }` on a factor histogram (returns a bare character scalar rather
/// than a length-0 vector on the negative arm); Clojure's
/// `(let [miss (remove (set items) all)] (if (= 1 (count miss))
/// (name (first miss)) ""))`; Julia's `let miss = setdiff(all,
/// items); length(miss) == 1 ? label(only(miss)) : "" end`;
/// Haskell's `case all \\ items of [v] -> label v ; _ -> ""` on the
/// `Bounded + Enum + Show` type-class trio. Translation through
/// pleme-io primitives: a pure default method composing the
/// just-lifted [`Self::unique_missing_labels`] Vec-return primitive
/// under `slice::join` — no new dep, no supertrait bound, no
/// set-shape carrier, no allocation beyond the natural intermediate
/// `Vec<&'static str>` the `slice::join` combinator's per-slot
/// stringification already routes.
fn unique_missing_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::unique_missing_labels(items).join(sep)
}
/// The N-ARY DECLARATION-ORDER "the unique strict-repeat witness as
/// a singleton-or-empty joined-label String" projection — the
/// `String` rendering of [`Self::unique_repeating_labels`] joined by
/// `sep`. Composes the substrate's just-lifted uniqueness-gated
/// strict-repeat label-Vec primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::unique_repeating_labels`] automatically satisfies this
/// projection at every downstream site. When the strict-repeat
/// uniqueness guard [`Self::has_unique_repeating_variant`] holds,
/// the projection returns the sole repeated variant's label as a
/// bare `String` (no separator surfaces because the joined slice is
/// a singleton); when the guard falsifies, the projection collapses
/// to the EMPTY `String` through a zero-allocation short-circuit
/// inherited from [`Self::unique_repeating_labels`].
///
/// The `String`-RETURN UNIQUE-TIE SHARPENING corner CLOSING the
/// strict-repeat arm of the (set-level × `String` ×
/// equivalence-partition × mult-band × unique-tie) row past the
/// just-opened (mult `== 0`) miss-band arm
/// [`Self::unique_missing_labels_joined`] one MULTIPLICITY-BAND axis
/// over on the equivalence-partition surface. Peer to
/// [`Self::repeating_labels_joined`] one UNIQUE-TIE-SHARPENING axis
/// over on the join-string return column (unsharpened strict-repeat
/// label-join → uniqueness-gated singleton-or-empty label-join).
/// Peer to [`Self::unique_repeating_labels`] one RETURN-SHAPE axis
/// over on the strict-repeat unique-tie corner (label-Vec witness →
/// joined-String witness of the same singleton-or-empty binding).
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::unique_repeating_labels_joined(items, sep) ==
/// T::unique_repeating_labels(items).join(sep)` — the joined-String
/// projection binds through the substrate's
/// [`Self::unique_repeating_labels`] Vec-return primitive composed
/// with `slice::join`. Pinned by
/// `unique_repeating_labels_joined_equals_unique_repeating_labels_dot_join_across_every_triple`.
///
/// Guarded-witness-collection identity: for every slice `items` and
/// every separator `sep`, `T::unique_repeating_labels_joined(items,
/// sep) == if T::has_unique_repeating_variant(items) {
/// T::repeating_labels_joined(items, sep) } else { String::new() }`
/// — the uniqueness-gated join-String coincides with the boolean-
/// guarded strict-repeat label-join through the composition of
/// [`Self::unique_repeating_labels`]'s guard-arm with `slice::join`.
/// Pinned by
/// `unique_repeating_labels_joined_equals_has_unique_repeating_variant_gated_repeating_labels_joined_across_every_triple`.
///
/// Bare-label singleton identity: for every slice `items` on which
/// [`Self::has_unique_repeating_variant`] holds AND for every
/// separator `sep`, `T::unique_repeating_labels_joined(items, sep)
/// == T::unique_repeating_labels(items)[0]` (as `String`) — because
/// the underlying label-Vec is a SINGLETON on the positive arm, the
/// separator NEVER surfaces in the output; `slice::join` on a
/// singleton `[label]` returns `label.to_string()` regardless of
/// `sep`. Pinned by
/// `unique_repeating_labels_joined_is_separator_agnostic_on_the_positive_arm_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items` and every
/// separator `sep`, `T::unique_repeating_labels_joined(items,
/// sep).is_empty() == !T::has_unique_repeating_variant(items)` —
/// the join-String's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check binding the
/// String-return uniqueness projection against the bool-column
/// projection one return-shape column over, and against the sibling
/// [`Self::unique_repeating_labels`] `is_empty` identity one
/// return-shape column over on the Vec-return arm. Pinned by
/// `unique_repeating_labels_joined_is_empty_iff_not_has_unique_repeating_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_repeating_labels`] factors through the
/// ordering-agnostic [`Self::has_unique_repeating_variant`] +
/// [`Self::repeating_variants`] pair under [`Self::label`], and
/// `slice::join` is a pure combinator. The OUTPUT byte layout is
/// fixed by [`Self::ALL`]'s declaration order regardless of the
/// input ordering, so the joined `String` matches byte-for-byte
/// under reversal. Pinned by
/// `unique_repeating_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_repeating_labels_joined(&[],
/// sep) == String::new()` UNCONDITIONALLY for every `sep` — the
/// empty slice hits zero positions, [`Self::count_repeating_variants`]
/// reports `0`, the uniqueness guard falsifies via `0 != 1`, the
/// label-Vec collapses to `vec![]`, and `slice::join` on `[]`
/// yields the empty `String` at every cardinality.
///
/// Full-set contract: `T::unique_repeating_labels_joined(<T as
/// ClosedSet>::ALL, sep) == String::new()` UNCONDITIONALLY for
/// every `sep` — pairwise-distinctness pins every variant at
/// exactly one position of the full-set slice,
/// [`Self::count_repeating_variants`] reports `0`, the guard
/// falsifies via `0 != 1`, the label-Vec collapses to `vec![]`, and
/// `slice::join` on the empty slice yields the empty `String`.
///
/// Doubled-full-set contract at cardinality `>= 2`:
/// `T::unique_repeating_labels_joined(&doubled, sep) ==
/// String::new()` for every `sep` — every variant hit twice pins
/// [`Self::count_repeating_variants`] `== T::CARDINALITY`, the
/// uniqueness guard falsifies at `T::CARDINALITY >= 2` via
/// `CARDINALITY != 1`, and the projection collapses to the empty
/// `String`. At cardinality `== 1` the doubled slice pins
/// `count_repeating_variants == 1`, the guard holds, and the
/// projection returns `T::ALL[0].label().to_string()` for every
/// `sep`.
///
/// Bimodal-triple positive-arm contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` for every `sep`, `T::ALL[0]`
/// sits at count `2` (the SOLE strict-repeat variant),
/// [`Self::count_repeating_variants`] reports `1`,
/// [`Self::has_unique_repeating_variant`] returns `true`, the
/// label-Vec collapses to `vec![T::ALL[0].label()]`, and
/// `slice::join` on the singleton returns
/// `T::ALL[0].label().to_string()` — the SEPARATOR-AGNOSTIC positive
/// arm on the multi-variant test-module fixture at the canonical
/// bimodal cardinality (the separator NEVER surfaces because the
/// joined slice is a singleton). LOAD-BEARING DISJOINT-WITNESS
/// mirror of [`Self::unique_missing_labels_joined`]'s bimodal-triple
/// arm (which reports `T::ALL[2].label()`) one MULTIPLICITY-BAND
/// axis over on the JOIN-STRING return column — the two positive
/// join-String arms report TWO DIFFERENT witnesses
/// (`T::ALL[0].label()` vs `T::ALL[2].label()`) on the SAME fixture,
/// pinning the strict-repeat / miss-band band separation under the
/// injective per-slot [`Self::label`] projection composed with
/// `slice::join`.
///
/// Empty-separator degeneracy: on the positive arm, the joined
/// `String` equals the sole strict-repeat label EXACTLY under the
/// empty separator (the joined slice is a singleton, `slice::join`
/// on a singleton is identity-into-`String`); on the negative arm,
/// the joined `String` is empty. Independent cross-check that the
/// combinator threads the empty separator through without inserting
/// a spurious rendering. Pinned by
/// `unique_repeating_labels_joined_threads_empty_separator_into_a_concatenated_run`.
///
/// Multi-char separator verbatim: on the positive arm, the multi-
/// character separator NEVER surfaces because the label-Vec is a
/// singleton; on the negative arm, the output is the empty `String`.
/// Independent cross-check that the combinator does not treat only
/// single-character separators verbatim, pinning the same identity
/// under a multi-byte separator surface. Pinned by
/// `unique_repeating_labels_joined_threads_multi_char_separator_verbatim`.
///
/// Future consumers — a `tatara-check` predicate `(check-repeating-
/// if-unique-joined …)` that reports the singleton-or-empty
/// strict-repeat band join-String witness as a typed author-facing
/// scalar rather than a three-step (has-unique-repeating-variant?
/// then repeating-labels then join) composition; an LSP diagnostic
/// on a Lisp-author-written closed-set field that renders "the sole
/// duplicated label" (only when uniquely duplicated) as an author-
/// facing scalar completion string
/// (`":severities [:info :info :warn] — sole duplicate: info"`
/// where the suffix is `.to_string()` of the sole strict-repeat
/// label); a Sekiban audit-trail projection whose per-window "sole
/// duplicated label" witness renders as a deterministic scalar
/// across machines (rather than a Vec that a downstream consumer
/// must join separately); a `tatara-lisp::macro_expand::Expander`
/// diagnostic that emits THE LONE doubly-bound vocabulary
/// identifier's label when uniqueness holds through a single typed
/// String rather than a three-step composition. Each binds to ONE
/// typed N-ary uniqueness-gated strict-repeat-witness join-String
/// projection on the trait rather than re-deriving the three-
/// primitive `unique_repeating_labels + join` composition inline per
/// callsite.
///
/// Compounding closure: this projection CLOSES the strict-repeat
/// arm of the JOIN-STRING return column of the (set-level ×
/// `String` × equivalence-partition × mult-band × unique-tie) row
/// past the just-opened miss-band arm
/// [`Self::unique_missing_labels_joined`] one MULTIPLICITY-BAND axis
/// over on the equivalence-partition surface. The (mult-band ×
/// return-shape) 3×3 face on the unique-tie subsurface now sits
/// 8/9 closed at (miss, variant), (strict-repeat, variant),
/// (unique-band, variant), (miss, label), (strict-repeat, label),
/// (unique-band, label), (miss, join-String), and THIS
/// (strict-repeat, join-String) corner — with the (unique-band,
/// join-String) `unique_unique_labels_joined` corner as the natural
/// next lift EXHAUSTIVELY CLOSING the row past this closure at its
/// FINAL 9/9 tile.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated strict-repeat-band join-String projection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::unique_repeating_labels(items).join(sep)` composition at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the (set-level × `String` × equivalence-partition ×
/// mult `>= 2` × unique-tie) corner was an unnamed inline
/// composition recurring at every prospective downstream "the sole
/// duplicated label as a bare string, if unique, else empty" site
/// pre-lift. THEORY.md §VI.1 — generation over composition; the
/// projection emerges from the composition of ONE substrate
/// primitive ([`Self::unique_repeating_labels`]) with the standard-
/// library `slice::join` combinator, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); reps <-
/// names(t)[t >= 2]; if (length(reps) == 1) reps else "" }` on a
/// factor histogram (returns a bare character scalar rather than a
/// length-0 vector on the negative arm); Clojure's `(let [reps
/// (filter #(>= (val %) 2) (frequencies coll))] (if (= 1 (count
/// reps)) (name (key (first reps))) ""))`; Julia's `let reps =
/// [v for v in all if count(==(v), items) >= 2]; length(reps) == 1
/// ? label(only(reps)) : "" end`; Haskell's `case [v | v <- all,
/// length (filter (==v) items) >= 2] of [v] -> label v ; _ -> ""`
/// on the `Bounded + Enum + Show + Eq` type-class quartet.
/// Translation through pleme-io primitives: a pure default method
/// composing the just-lifted [`Self::unique_repeating_labels`]
/// Vec-return primitive under `slice::join` — no new dep, no
/// supertrait bound, no set-shape carrier, no allocation beyond the
/// natural intermediate `Vec<&'static str>` the `slice::join`
/// combinator's per-slot stringification already routes.
fn unique_repeating_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::unique_repeating_labels(items).join(sep)
}
/// The N-ARY DECLARATION-ORDER "the unique unique-band witness as a
/// singleton-or-empty joined-label String" projection — the
/// `String` rendering of [`Self::unique_unique_labels`] joined by
/// `sep`. Composes the substrate's just-lifted uniqueness-gated
/// unique-band label-Vec primitive with the standard-library
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// combinator so a passing implementor of
/// [`Self::unique_unique_labels`] automatically satisfies this
/// projection at every downstream site. When the unique-band
/// uniqueness guard [`Self::has_unique_unique_variant`] holds, the
/// projection returns the sole once-occurring variant's label as a
/// bare `String` (no separator surfaces because the joined slice
/// is a singleton); when the guard falsifies, the projection
/// collapses to the EMPTY `String` through a zero-allocation
/// short-circuit inherited from [`Self::unique_unique_labels`].
///
/// The `String`-RETURN UNIQUE-BAND UNIQUE-TIE SHARPENING corner
/// EXHAUSTIVELY CLOSING the (set-level × `String` ×
/// equivalence-partition × mult-band × unique-tie) 3-corner
/// JOIN-STRING row at its FINAL THIRD tile past the just-closed
/// (mult `>= 2`) strict-repeat arm
/// [`Self::unique_repeating_labels_joined`] AND the (mult `== 0`)
/// miss-band arm [`Self::unique_missing_labels_joined`] one
/// MULTIPLICITY-BAND axis over on the equivalence-partition
/// surface AND CLOSING the (mult-band × return-shape) 3×3 face on
/// the unique-tie subsurface at 9/9 — EXHAUSTIVE closure of the
/// equivalence-partition unique-tie subsurface across BOTH the
/// multiplicity-band trichotomy AND the (Vec-of-variant,
/// Vec-of-label, label-join-String) return-shape trichotomy.
///
/// Peer to [`Self::unique_unique_labels`] one RETURN-SHAPE axis
/// over on the unique-band unique-tie corner (label-Vec witness →
/// joined-String witness of the same singleton-or-empty binding).
/// Peer to [`Self::unique_repeating_labels_joined`] and
/// [`Self::unique_missing_labels_joined`] one MULTIPLICITY-BAND
/// axis over on the JOIN-STRING return column.
///
/// Composition law: for every slice `items` and every separator
/// `sep`, `T::unique_unique_labels_joined(items, sep) ==
/// T::unique_unique_labels(items).join(sep)` — the joined-String
/// projection binds through the substrate's
/// [`Self::unique_unique_labels`] Vec-return primitive composed
/// with `slice::join`. Pinned by
/// `unique_unique_labels_joined_equals_unique_unique_labels_dot_join_across_every_triple`.
///
/// Guarded-witness-collection identity: for every slice `items`
/// and every separator `sep`, `T::unique_unique_labels_joined(items,
/// sep) == if T::has_unique_unique_variant(items) {
/// T::unique_variants(items)[0].label().to_string() } else {
/// String::new() }` — the uniqueness-gated join-String coincides
/// with the boolean-guarded sole unique-band variant label rendered
/// as `String` through the composition of
/// [`Self::unique_unique_labels`]'s guard-arm with `slice::join`.
/// Pinned by
/// `unique_unique_labels_joined_equals_has_unique_unique_variant_gated_sole_label_across_every_triple`.
///
/// Bare-label singleton identity: for every slice `items` on which
/// [`Self::has_unique_unique_variant`] holds AND for every
/// separator `sep`, `T::unique_unique_labels_joined(items, sep)
/// == T::unique_unique_labels(items)[0]` (as `String`) — because
/// the underlying label-Vec is a SINGLETON on the positive arm,
/// the separator NEVER surfaces in the output; `slice::join` on a
/// singleton `[label]` returns `label.to_string()` regardless of
/// `sep`. Pinned by
/// `unique_unique_labels_joined_is_separator_agnostic_on_the_positive_arm_across_every_triple`.
///
/// Is-empty coincidence identity: for every slice `items` and
/// every separator `sep`, `T::unique_unique_labels_joined(items,
/// sep).is_empty() == !T::has_unique_unique_variant(items)` — the
/// join-String's emptiness coincides with the NEGATION of the
/// set-level uniqueness bit. Independent cross-check binding the
/// String-return uniqueness projection against the bool-column
/// projection one return-shape column over, and against the
/// sibling [`Self::unique_unique_labels`] `is_empty` identity one
/// return-shape column over on the Vec-return arm. Pinned by
/// `unique_unique_labels_joined_is_empty_iff_not_has_unique_unique_variant_across_every_triple`.
///
/// Ordering-axis invariance: the projection is intrinsically
/// ordering-agnostic on the INPUT axis — the underlying
/// [`Self::unique_unique_labels`] factors through the
/// ordering-agnostic [`Self::has_unique_unique_variant`] +
/// [`Self::unique_variants`] pair under [`Self::label`], and
/// `slice::join` is a pure combinator. The OUTPUT byte layout is
/// fixed by [`Self::ALL`]'s declaration order regardless of the
/// input ordering, so the joined `String` matches byte-for-byte
/// under reversal. Pinned by
/// `unique_unique_labels_joined_is_invariant_under_slice_reversal_across_every_triple`.
///
/// Empty-slice contract: `T::unique_unique_labels_joined(&[], sep)
/// == String::new()` UNCONDITIONALLY for every `sep` — the empty
/// slice hits zero positions, every per-target multiplicity is
/// `0`, [`Self::count_unique_variants`] reports `0`, the
/// uniqueness guard falsifies via `0 != 1`, the label-Vec
/// collapses to `vec![]`, and `slice::join` on `[]` yields the
/// empty `String` at every cardinality.
///
/// Full-set contract: `T::unique_unique_labels_joined(<T as
/// ClosedSet>::ALL, sep)` returns `T::ALL[0].label().to_string()`
/// iff [`Self::CARDINALITY`] `== 1` (regardless of `sep`) else
/// `String::new()` — pairwise-distinctness pins every variant at
/// exactly one position of the full-set slice, so every per-target
/// multiplicity is `1` and [`Self::count_unique_variants`] reports
/// [`Self::CARDINALITY`]. The guard `count == 1` holds EXACTLY
/// when [`Self::CARDINALITY`] `== 1`; at that cardinality the
/// singleton label-Vec renders the sole variant's label as a bare
/// `String` regardless of `sep`. At [`Self::CARDINALITY`] `>= 2`
/// the guard falsifies via `CARDINALITY != 1` and the projection
/// collapses to the empty `String`.
///
/// Doubled-full-set contract:
/// `T::unique_unique_labels_joined(&doubled, sep) == String::new()`
/// UNCONDITIONALLY for every `sep` — every variant sits at count
/// `2` (strict-repeat, NOT unique-band), so
/// [`Self::count_unique_variants`] reports `0`, the uniqueness
/// guard falsifies via `0 != 1`, and the projection collapses to
/// the empty `String` at every cardinality. DISTINCT from the
/// [`Self::unique_repeating_labels_joined`] sibling one
/// MULTIPLICITY-BAND axis over, which returns
/// `T::ALL[0].label().to_string()` at `T::CARDINALITY == 1` (the
/// sole strict-repeat witness).
///
/// Matching-singleton positive-arm contract: for every variant `v`
/// in [`Self::ALL`] AND for every `sep`,
/// `T::unique_unique_labels_joined(&[v], sep) ==
/// v.label().to_string()` UNCONDITIONALLY — the target hits count
/// `1` (the SOLE unique-band witness), every non-target sits at
/// count `0`, [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] holds, the label-Vec
/// collapses to `vec![v.label()]`, and `slice::join` on the
/// singleton returns `v.label().to_string()` — the SEPARATOR-
/// AGNOSTIC positive arm at every cardinality. LOAD-BEARING
/// NON-EMPTY DEGENERATE arm inherited from
/// [`Self::unique_unique_labels`]'s matching-singleton discipline
/// — DISTINCT from [`Self::unique_repeating_labels_joined`] which
/// collapses to the empty `String` on every matching singleton
/// AND from [`Self::unique_missing_labels_joined`] whose singleton
/// behavior is CARDINALITY-dependent.
///
/// Bimodal-triple positive-arm contract at cardinality `>= 3`: on
/// `[T::ALL[0], T::ALL[0], T::ALL[1]]` for every `sep`, `T::ALL[1]`
/// sits at count `1` (the SOLE unique-band variant),
/// [`Self::count_unique_variants`] reports `1`,
/// [`Self::has_unique_unique_variant`] returns `true`, the
/// label-Vec collapses to `vec![T::ALL[1].label()]`, and
/// `slice::join` on the singleton returns
/// `T::ALL[1].label().to_string()` — the SEPARATOR-AGNOSTIC
/// positive arm on the multi-variant test-module fixture at the
/// canonical bimodal cardinality (the separator NEVER surfaces
/// because the joined slice is a singleton). LOAD-BEARING
/// TRICHOTOMY DISCRIMINATOR from
/// [`Self::unique_missing_labels_joined`] (reports
/// `T::ALL[2].label()`) AND
/// [`Self::unique_repeating_labels_joined`] (reports
/// `T::ALL[0].label()`) on the SAME fixture at cardinality `== 3`
/// — the MULTIPLICITY-BAND axis EXHAUSTIVELY PARTITIONS the three
/// positive join-String arms at THREE DIFFERENT witnesses one
/// MULTIPLICITY-BAND axis apart, pinning the miss-band /
/// strict-repeat / unique-band separation on the JOIN-STRING
/// return column under the injective per-slot [`Self::label`]
/// projection composed with `slice::join`.
///
/// Empty-separator degeneracy: on the positive arm, the joined
/// `String` equals the sole unique-band label EXACTLY under the
/// empty separator (the joined slice is a singleton, `slice::join`
/// on a singleton is identity-into-`String`); on the negative arm,
/// the joined `String` is empty. Independent cross-check that the
/// combinator threads the empty separator through without
/// inserting a spurious rendering. Pinned by
/// `unique_unique_labels_joined_threads_empty_separator_into_a_concatenated_run`.
///
/// Multi-char separator verbatim: on the positive arm, the multi-
/// character separator NEVER surfaces because the label-Vec is a
/// singleton; on the negative arm, the output is the empty
/// `String`. Independent cross-check that the combinator does not
/// treat only single-character separators verbatim, pinning the
/// same identity under a multi-byte separator surface. Pinned by
/// `unique_unique_labels_joined_threads_multi_char_separator_verbatim`.
///
/// Future consumers — a `tatara-check` predicate `(check-unique-
/// if-unique-joined …)` that reports the singleton-or-empty
/// unique-band join-String witness as a typed author-facing scalar
/// rather than a three-step (has-unique-unique-variant? then
/// unique-labels then join) composition; an LSP diagnostic on a
/// Lisp-author-written closed-set field that renders "the sole
/// once-occurring label" (only when uniquely once-occurring) as an
/// author-facing scalar completion string
/// (`":severities [:info :warn :info] — sole once-occurring: warn"`
/// where the suffix is `.to_string()` of the sole unique-band
/// label); a Sekiban audit-trail projection whose per-window "sole
/// once-occurring label" witness renders as a deterministic scalar
/// across machines (rather than a Vec that a downstream consumer
/// must join separately); a `tatara-lisp::macro_expand::Expander`
/// diagnostic that emits THE LONE singly-bound vocabulary
/// identifier's label when uniqueness holds through a single typed
/// String rather than a three-step composition. Each binds to ONE
/// typed N-ary uniqueness-gated unique-band-witness join-String
/// projection on the trait rather than re-deriving the three-
/// primitive `unique_unique_labels + join` composition inline per
/// callsite.
///
/// Compounding closure: this projection EXHAUSTIVELY CLOSES the
/// (mult `== 1`) unique-band arm of the JOIN-STRING return column
/// of the (set-level × `String` × equivalence-partition ×
/// mult-band × unique-tie) row past the just-closed
/// [`Self::unique_repeating_labels_joined`] AND
/// [`Self::unique_missing_labels_joined`] one MULTIPLICITY-BAND
/// axis over on the equivalence-partition surface AT ITS FINAL
/// THIRD tile — the JOIN-STRING return column now sits 3/3 closed.
/// The (mult-band × return-shape) 3×3 face on the unique-tie
/// subsurface EXHAUSTIVELY CLOSES at 9/9 at (miss, variant),
/// (strict-repeat, variant), (unique-band, variant), (miss,
/// label), (strict-repeat, label), (unique-band, label), (miss,
/// join-String), (strict-repeat, join-String), and THIS
/// (unique-band, join-String) FINAL corner — EXHAUSTIVE closure
/// across BOTH the multiplicity-band trichotomy AND the
/// (variant-Vec, label-Vec, label-join-String) return-shape
/// trichotomy. The natural next lifts past this closure are the
/// lex-order peers `sorted_unique_missing_labels_joined` /
/// `sorted_unique_repeating_labels_joined` /
/// `sorted_unique_unique_labels_joined` one ORDERING axis over,
/// each binding through the same composition of the
/// uniqueness-gated variant Vec under [`Self::label`] plus the
/// LEX-order primitive plus `slice::join`.
///
/// Theory anchor: THEORY.md §III — the typescape; the N-ary
/// uniqueness-gated unique-band-band join-String projection
/// becomes a TYPE-level primitive on the closed-set trait rather
/// than a per-consumer inline
/// `T::unique_unique_labels(items).join(sep)` composition at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the (set-level × `String` × equivalence-partition × mult
/// `== 1` × unique-tie) corner was an unnamed inline composition
/// recurring at every prospective downstream "the sole
/// once-occurring label as a bare string, if unique, else empty"
/// site pre-lift. THEORY.md §VI.1 — generation over composition;
/// the projection emerges from the composition of ONE substrate
/// primitive ([`Self::unique_unique_labels`]) with the standard-
/// library `slice::join` combinator, not as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: R's `{ t <- table(items); ones <-
/// names(t)[t == 1]; if (length(ones) == 1) ones else "" }` on a
/// factor histogram (returns a bare character scalar rather than a
/// length-0 vector on the negative arm); Clojure's `(let [ones
/// (filter #(= (val %) 1) (frequencies coll))] (if (= 1 (count
/// ones)) (name (key (first ones))) ""))`; Julia's `let ones =
/// [v for v in all if count(==(v), items) == 1]; length(ones) == 1
/// ? label(only(ones)) : "" end`; Haskell's `case [v | v <- all,
/// length (filter (==v) items) == 1] of [v] -> label v ; _ -> ""`
/// on the `Bounded + Enum + Show + Eq` type-class quartet.
/// Translation through pleme-io primitives: a pure default method
/// composing the just-lifted [`Self::unique_unique_labels`]
/// Vec-return primitive under `slice::join` — no new dep, no
/// supertrait bound, no set-shape carrier, no allocation beyond
/// the natural intermediate `Vec<&'static str>` the `slice::join`
/// combinator's per-slot stringification already routes.
fn unique_unique_labels_joined(items: &[Self], sep: &str) -> ::std::string::String {
<Self as ClosedSet>::unique_unique_labels(items).join(sep)
}
/// The declaration-order INCLUSIVE-both closed-range containment
/// predicate — `true` iff `self` sits in the closed range
/// `[lo, hi]` of [`Self::ALL`]'s declaration order, `false` when
/// `self` sits strictly before `lo` OR strictly after `hi`. The
/// TERNARY-arity opener on the closed-set surface, past the
/// exhaustively-closed 8-corner (ordering × direction × strictness)
/// 2×2×2 pairwise-comparison hypercube (78)+(79)+(80)+(81) — opens
/// the arity axis one step further from binary pairwise-comparison
/// to ternary closed-range containment.
///
/// Sibling posture to the pairwise-comparison hypercube's eight
/// corners one arity level down: the pairwise-comparison predicates
/// answer "does `self` sit at, before, or after `other`?" over ONE
/// bound; this method answers "does `self` sit between `lo` and
/// `hi` inclusive?" over TWO bounds. The declaration-axis
/// composition binds through the non-strict-precedence predicate
/// on both bound-to-self edges of the range —
/// `lo.precedes_or_equal(self) ∧ self.precedes_or_equal(hi)` — so
/// the ternary containment predicate is a typed CONSEQUENCE of the
/// non-strict pairwise-precedence predicate applied at the two
/// range endpoints. Not a fresh substrate primitive on the index
/// axis — the composition emerges from the just-closed 8-corner
/// pairwise-comparison hypercube through conjunction of two of its
/// (non-strict, forward) arms.
///
/// Endpoint-inclusivity contract: BOTH `lo` and `hi` sit INSIDE
/// the closed range — `lo.is_between(lo, hi)` and
/// `hi.is_between(lo, hi)` are BOTH `true` when
/// `lo.precedes_or_equal(hi)`. Reflexivity on the diagonal:
/// `v.is_between(v, v)` is `true` for every `v` (the singleton
/// range `[v, v]` contains exactly `v`). Empty-range degeneracy:
/// `v.is_between(hi, lo)` is `false` when `hi` strictly succeeds
/// `lo` — the reversed range is empty because no variant can
/// simultaneously non-strictly succeed `hi` AND non-strictly
/// precede `lo` when `hi` sits later than `lo`. The empty-range
/// arm is a typed CONSEQUENCE of the non-strict-precedence
/// predicate's totality (declaration order is total, so `hi
/// precedes lo` iff `lo precedes hi` is false modulo equality) —
/// pinned by `is_between_is_false_on_reversed_range_endpoints`.
///
/// Range-partition contract: for every ordered pair `(lo, hi)`
/// with `lo.precedes_or_equal(hi)`, the set of variants `v` for
/// which `v.is_between(lo, hi)` is `true` equals the contiguous
/// declaration-order range `[Self::index_of(lo),
/// Self::index_of(hi)]` — the ternary containment predicate
/// partitions [`Self::ALL`] into the inside-range set and the
/// outside-range set at every ordered range. Pinned by
/// `is_between_partitions_all_across_every_bound_pair`.
///
/// Future consumers that compose against [`Self::is_between`]: an
/// LSP diagnostic that ranges over a closed interval of variants
/// via `T::ALL.iter().filter(|v| v.is_between(lo, hi))` — bind to
/// ONE typed ternary closed-range containment predicate rather
/// than re-deriving `lo.precedes_or_equal(v) &&
/// v.precedes_or_equal(hi)` inline per callsite; a `tatara-check`
/// predicate `(check-phase-in-window …)` verifying a workspace-
/// wide phase-transition constraint where a phase must sit
/// between a lower and upper watermark (e.g. `Executing.is_between
/// (Warming, Contracting)` on the substrate's `WorkloadPhase`
/// lifecycle); a Sekiban audit-trail metric jointly labeled by
/// membership in a phase-transition window; the substrate's own
/// `WorkloadPhase` lifecycle projected via `phase.is_between
/// (Warming(_), Contracting(_))` to gate SIGHUP admission on the
/// executing-window.
///
/// Theory anchor: THEORY.md §III — the typescape; the ternary
/// closed-range containment predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline conjunction of two non-strict-precedence calls at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the ternary-arity axis was an unnamed inline composition
/// (`lo.precedes_or_equal(v) && v.precedes_or_equal(hi)`)
/// recurring at every prospective downstream closed-range-
/// membership site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the non-strict pairwise-
/// precedence predicate applied at both range endpoints.
/// THEORY.md §VI.1 — generation over composition; the ternary
/// closed-range containment predicate emerges from the
/// composition of TWO substrate primitives ([`Self::precedes_or_equal`]
/// at both bound-to-self edges + the standard-library `&&` on
/// `bool`) rather than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Ruby's `Comparable#between?(lo, hi)`
/// surfaces the ternary closed-range containment predicate as a
/// first-class inclusive-both membership check on any ordered
/// type; Rust's own `std::ops::RangeInclusive::contains(&v)`
/// exposes the same predicate on the inclusive-range value
/// carrier. Translation through pleme-io primitives: the ternary
/// closed-range containment predicate on the closed-set trait
/// binds through [`Self::precedes_or_equal`]'s non-strict
/// pairwise-precedence composition applied at both range
/// endpoints, so the ternary containment emerges from the
/// substrate's typed non-strict pairwise-comparison surface
/// rather than as a fresh substrate primitive on the index axis
/// or from a foreign `RangeInclusive` value carrier that would
/// leak an implementation detail through the trait's API. The
/// closed-set trait carries the containment predicate as a
/// typed projection on the variant, not on a heap-allocated
/// range carrier.
fn is_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::precedes_or_equal(lo, self)
&& <Self as ClosedSet>::precedes_or_equal(self, hi)
}
/// The lex-order INCLUSIVE-both closed-range containment
/// predicate — `true` iff `self` sits in the closed range
/// `[lo, hi]` of the lex-order [`Self::sorted_labels`], `false`
/// when `self` sits strictly before `lo` OR strictly after `hi`
/// in lex order. The lex-ordering peer of [`Self::is_between`] on
/// the (declaration, lex) ordering axis of the ternary closed-
/// range containment surface.
///
/// Sibling posture to [`Self::is_between`] one arm over on the
/// (declaration, lex) ordering axis — [`Self::is_between`] uses
/// [`Self::precedes_or_equal`] (declaration order), this method
/// uses [`Self::sorted_precedes_or_equal`] (lex order). See
/// [`Self::is_between`] for the shared closed-range-containment
/// laws (reflexivity, endpoint-inclusivity, empty-range
/// degeneracy), the range-partition contract, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis arm of the same ternary closed-
/// range containment surface and inherits every property from
/// the declaration arm's documentation, differing only in the
/// projection method the composition routes through.
///
/// Default body composes [`Self::sorted_precedes_or_equal`] at
/// both range endpoints:
/// `lo.sorted_precedes_or_equal(self) &&
/// self.sorted_precedes_or_equal(hi)`. Implementors override only
/// when the lex-axis ternary closed-range containment surface
/// needs to diverge from the natural composition of the
/// pre-existing non-strict pairwise-precedence predicate applied
/// at both range endpoints.
///
/// (82) + (83) together OPEN the (ordering) 2×1 arity-3 opener on
/// the ternary-containment surface — the two arms cover the
/// declaration and lex axes at inclusive-both ternary arity, past
/// the exhaustively-closed 8-corner pairwise-comparison hypercube
/// on the trait one arity level down. Future extensions along
/// (inclusive-exclusive) endpoint-inclusivity axes can further
/// carve the ternary-containment surface into the 4-corner
/// (ordering × endpoint-inclusivity-flavor) matrix (`[lo, hi]` /
/// `(lo, hi)` / `[lo, hi)` / `(lo, hi]`) — the (82)+(83) pair sits
/// at the (inclusive-both) corner of each axis and stays the
/// canonical entry point on the ternary-containment surface.
fn is_sorted_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::sorted_precedes_or_equal(lo, self)
&& <Self as ClosedSet>::sorted_precedes_or_equal(self, hi)
}
/// The declaration-order EXCLUSIVE-both closed-range containment
/// predicate — `true` iff `self` sits STRICTLY inside the open
/// range `(lo, hi)` of the declaration-order [`Self::ALL`],
/// `false` when `self` coincides with EITHER endpoint OR sits
/// outside. The strict-precedence peer of [`Self::is_between`] on
/// the (endpoint-inclusivity) axis of the ternary closed-range
/// containment surface — opens the (exclusive-both) corner of the
/// 4-corner (ordering × endpoint-inclusivity-flavor) matrix past
/// the (inclusive-both) corner (82)+(83) [`Self::is_between`] /
/// [`Self::is_sorted_between`] closed.
///
/// Sibling posture to [`Self::is_between`] one arm over on the
/// (inclusive-exclusive) endpoint-inclusivity axis of the ternary
/// closed-range containment surface: [`Self::is_between`] composes
/// through [`Self::precedes_or_equal`] (non-strict) at both range
/// endpoints; this method composes through [`Self::precedes`]
/// (strict) at both range endpoints. The strict-precedence
/// predicate at the two endpoints EXCLUDES both `lo` and `hi` from
/// the containment set — the "strict interior" of the closed
/// range, distinct from [`Self::is_between`]'s inclusive-both
/// closed range. Mirrors the strict-vs-non-strict axis one arity
/// level down: [`Self::precedes`] / [`Self::precedes_or_equal`]
/// stand in the same relationship on binary arity as this method
/// stands to [`Self::is_between`] on ternary arity.
///
/// Endpoint-exclusivity contract: NEITHER `lo` NOR `hi` sit inside
/// the strict interior — `lo.is_strictly_between(lo, hi) == false`
/// AND `hi.is_strictly_between(lo, hi) == false` for every ordered
/// pair `(lo, hi)`, including the trivially-empty case
/// `lo == hi`. Irreflexivity on the diagonal:
/// `v.is_strictly_between(v, v) == false` for every `v` (the
/// exclusive-both singleton range `(v, v)` is empty because
/// [`Self::precedes`] is irreflexive at both bound-to-self edges).
/// The endpoint-exclusivity arm is a typed CONSEQUENCE of the
/// strict-precedence predicate's irreflexivity — pinned by
/// `is_strictly_between_excludes_both_range_endpoints_for_every_ordered_pair`
/// and
/// `is_strictly_between_is_irreflexive_across_every_variant`.
/// Empty-range degeneracy on reversed endpoints:
/// `v.is_strictly_between(hi, lo) == false` when `hi` strictly
/// succeeds `lo` — inherited verbatim from [`Self::is_between`]'s
/// empty-range arm, because a reversed strict range is empty for
/// the same total-order reason a reversed non-strict range is.
///
/// Range-partition contract: for every ordered pair `(lo, hi)`
/// with `lo.precedes_or_equal(hi)`, the set of variants `v` for
/// which `v.is_strictly_between(lo, hi) == true` equals the
/// contiguous declaration-order OPEN range
/// `[Self::index_of(lo)+1, Self::index_of(hi))` — the strict-
/// interior variant set, distinct from [`Self::is_between`]'s
/// inclusive-both closed range which spans
/// `[Self::index_of(lo), Self::index_of(hi)]`. Pinned by
/// `is_strictly_between_partitions_all_across_every_bound_pair`.
/// The strict interior on the full range `(first, last)` equals
/// the declaration-order interior partition — the same variant
/// set [`Self::interior`] renders — pinned by
/// `is_strictly_between_full_range_admits_only_the_interior`.
///
/// Future consumers that compose against
/// [`Self::is_strictly_between`]: an LSP diagnostic that ranges
/// over the STRICT interior of a closed interval of variants via
/// `T::ALL.iter().filter(|v| v.is_strictly_between(lo, hi))` —
/// bind to ONE typed ternary strict-open-range containment
/// predicate rather than re-deriving `lo.precedes(v) &&
/// v.precedes(hi)` inline per callsite; a `tatara-check`
/// predicate `(check-phase-strictly-in-window …)` verifying a
/// workspace-wide phase-transition constraint where a phase must
/// sit STRICTLY between a lower and upper watermark (e.g.
/// `Executing.is_strictly_between(Warming, Contracting)` on the
/// substrate's `WorkloadPhase` lifecycle, excluding the watermark
/// phases themselves from the "actively executing" window); a
/// Sekiban audit-trail metric labeled by strict-interior
/// membership in a phase-transition window; the substrate's own
/// `WorkloadPhase` lifecycle projected via
/// `phase.is_strictly_between(Pending, Terminal)` to gate the
/// "actively converging" set — the strict interior of the
/// lifecycle, excluding the head and tail markers themselves.
///
/// Theory anchor: THEORY.md §III — the typescape; the ternary
/// strict-open-range containment predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline conjunction of two strict-precedence calls at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the strict-interior ternary-arity axis was an unnamed inline
/// composition (`lo.precedes(v) && v.precedes(hi)`) that would
/// recur at every prospective downstream strict-open-range-
/// membership site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of the strict pairwise-
/// precedence predicate applied at both range endpoints.
/// THEORY.md §VI.1 — generation over composition; the ternary
/// strict-open-range containment predicate emerges from the
/// composition of TWO substrate primitives ([`Self::precedes`] at
/// both bound-to-self edges + the standard-library `&&` on
/// `bool`) rather than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: mathematics' standard open-interval
/// notation `(lo, hi)` denotes the strict interior of a real
/// interval — the same predicate at the ternary-arity level of
/// the closed-set surface. Racket's `<` composes with itself on a
/// pair `(<? lo v)`/`(<? v hi)` for the same open-interval
/// membership check; Common Lisp's `(< lo v hi)` chained-comparison
/// idiom exposes the strict-open-range membership as a first-class
/// n-ary predicate on numeric types. Translation through pleme-io
/// primitives: the ternary strict-open-range containment predicate
/// on the closed-set trait binds through [`Self::precedes`]'s
/// strict pairwise-precedence composition applied at both range
/// endpoints, so the strict interior emerges from the substrate's
/// typed strict pairwise-comparison surface rather than as a
/// fresh substrate primitive on the index axis. The closed-set
/// trait carries the strict-interior predicate as a typed
/// projection on the variant, not on a chained-comparison
/// n-ary macro or a foreign `Range` value carrier.
fn is_strictly_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::precedes(lo, self) && <Self as ClosedSet>::precedes(self, hi)
}
/// The lex-order EXCLUSIVE-both closed-range containment predicate
/// — `true` iff `self` sits STRICTLY inside the open range
/// `(lo, hi)` of the lex-order [`Self::sorted_labels`], `false`
/// when `self` coincides with EITHER endpoint OR sits outside in
/// lex order. The lex-ordering peer of [`Self::is_strictly_between`]
/// on the (declaration, lex) ordering axis of the ternary strict-
/// open-range containment surface.
///
/// Sibling posture to [`Self::is_strictly_between`] one arm over
/// on the (declaration, lex) ordering axis —
/// [`Self::is_strictly_between`] uses [`Self::precedes`]
/// (declaration order, strict), this method uses
/// [`Self::sorted_precedes`] (lex order, strict). See
/// [`Self::is_strictly_between`] for the shared strict-open-range-
/// containment laws (irreflexivity, endpoint-exclusivity, empty-
/// range degeneracy), the range-partition contract, the future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// ternary strict-open-range containment surface and inherits
/// every property from the declaration arm's documentation,
/// differing only in the projection method the composition
/// routes through.
///
/// Default body composes [`Self::sorted_precedes`] at both range
/// endpoints: `lo.sorted_precedes(self) &&
/// self.sorted_precedes(hi)`. Implementors override only when the
/// lex-axis ternary strict-open-range containment surface needs to
/// diverge from the natural composition of the pre-existing strict
/// pairwise-precedence predicate applied at both range endpoints.
///
/// (84) + (85) together OPEN the (exclusive-both) corner of the
/// (ordering × endpoint-inclusivity-flavor) 4-corner matrix past
/// the (inclusive-both) corner (82)+(83) closed. Together with
/// (82)+(83), four of the eight sub-corners
/// (ordering × endpoint-inclusivity-flavor) 2×2 = 4-corner matrix
/// are now closed: (declaration, inclusive-both) at (82) —
/// [`Self::is_between`], (lex, inclusive-both) at (83) —
/// [`Self::is_sorted_between`], (declaration, exclusive-both) at
/// (84) — [`Self::is_strictly_between`], and now (lex, exclusive-
/// both) at (85) — this method. Future extensions along the
/// half-open endpoint-inclusivity axes (`[lo, hi)` /
/// `(lo, hi]`) close the remaining four corners of the ternary-
/// containment surface — the (82)+(83)+(84)+(85) quartet sits at
/// the two closed-form corners (both-closed and both-open) and
/// stays the canonical entry point for a future
/// (half-open) axis.
fn is_sorted_strictly_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::sorted_precedes(lo, self)
&& <Self as ClosedSet>::sorted_precedes(self, hi)
}
/// The declaration-order RIGHT-HALF-OPEN closed-range containment
/// predicate — `true` iff `self` sits in the half-open range
/// `[lo, hi)` of the declaration-order [`Self::ALL`], `false` when
/// `self` coincides with the upper endpoint `hi`, sits strictly
/// before `lo`, OR sits strictly after `hi`. The "canonical
/// half-open" arm on the (endpoint-inclusivity-flavor) axis of the
/// ternary closed-range containment surface — mirroring
/// `std::ops::Range::contains`, Python `range()`, and the standard
/// mathematical `[lo, hi)` interval notation where the RIGHT
/// endpoint is the OPEN one.
///
/// Sibling posture to [`Self::is_between`] (both-inclusive, `[lo,
/// hi]`) and [`Self::is_strictly_between`] (both-exclusive, `(lo,
/// hi)`) one arm over on the (endpoint-inclusivity-flavor) axis of
/// the ternary closed-range containment surface: [`Self::is_between`]
/// composes [`Self::precedes_or_equal`] at BOTH bound-to-self edges;
/// [`Self::is_strictly_between`] composes [`Self::precedes`] at
/// BOTH edges; this method composes [`Self::precedes_or_equal`] at
/// the LOWER edge and [`Self::precedes`] at the UPPER edge — the
/// asymmetric mix that defines the right-half-open interval. The
/// declaration-axis composition binds through
/// `lo.precedes_or_equal(self) ∧ self.precedes(hi)`, so the
/// right-half-open containment predicate is a typed CONSEQUENCE of
/// the two pre-existing pairwise-precedence predicates (non-strict
/// at the lower edge, strict at the upper edge) applied at the two
/// range endpoints. Not a fresh substrate primitive on the index
/// axis — the composition emerges from the just-closed 8-corner
/// pairwise-comparison hypercube through conjunction of one
/// non-strict-forward arm and one strict-forward arm.
///
/// Endpoint-inclusivity contract: the LOWER endpoint `lo` sits
/// INSIDE the half-open range — `lo.is_right_half_open_between(lo,
/// hi)` is `true` when `lo.precedes(hi)` (the range is non-empty);
/// the UPPER endpoint `hi` sits OUTSIDE — `hi.is_right_half_open_between(lo,
/// hi)` is ALWAYS `false` (irreflexivity of [`Self::precedes`] at
/// the upper edge). Reflexivity on the diagonal:
/// `v.is_right_half_open_between(v, v)` is `false` for every `v`
/// because the singleton half-open range `[v, v)` is EMPTY (no
/// variant simultaneously non-strictly-succeeds `v` AND strictly-
/// precedes `v`). Empty-range degeneracy: `v.is_right_half_open_between(hi,
/// lo)` is `false` when `hi` strictly succeeds `lo` — the reversed
/// half-open range is empty because no variant can simultaneously
/// non-strictly succeed `hi` AND strictly precede `lo` when `hi`
/// sits later than `lo`. The empty-range arm is a typed
/// CONSEQUENCE of the pairwise-precedence predicates' totality.
///
/// Range-partition contract: for every ordered pair `(lo, hi)`
/// with `lo.precedes_or_equal(hi)`, the set of variants `v` for
/// which `v.is_right_half_open_between(lo, hi)` is `true` equals
/// the RIGHT-HALF-OPEN declaration-order slice
/// `Self::ALL[index_of(lo)..index_of(hi)]` — the half-open interval,
/// distinct from the inclusive-both peer's closed interval
/// `Self::ALL[index_of(lo)..=index_of(hi)]` and from the
/// exclusive-both peer's open interval
/// `Self::ALL[index_of(lo)+1..index_of(hi)]`. Pinned by
/// `is_right_half_open_between_partitions_all_across_every_bound_pair`.
///
/// Future consumers that compose against
/// [`Self::is_right_half_open_between`]: an LSP diagnostic that
/// ranges over the RIGHT-HALF-OPEN interior of a closed-set
/// interval via `T::ALL.iter().filter(|v|
/// v.is_right_half_open_between(lo, hi))` — bind to ONE typed
/// ternary right-half-open-range containment predicate rather than
/// re-deriving `lo.precedes_or_equal(v) && v.precedes(hi)` inline
/// per callsite; a `tatara-check` predicate `(check-phase-in-window-
/// exclusive-upper …)` verifying a workspace-wide phase-transition
/// constraint where a phase must sit at or after a lower watermark
/// AND strictly before an upper watermark (e.g. `Executing
/// .is_right_half_open_between(Warming, Contracting)` on the
/// substrate's `WorkloadPhase` lifecycle — the "actively serving
/// OR just warming, not yet draining" window); a Sekiban audit-
/// trail metric labeled by right-half-open membership in a phase-
/// transition window; the substrate's own iteration idiom
/// `for v in T::ALL { if v.is_right_half_open_between(lo, hi) {
/// … } }` mirroring `for v in lo..hi` on integer ranges but on
/// the typed closed-set surface directly — the canonical
/// half-open iteration pattern lifted to the typed algebra without
/// leaking a foreign `std::ops::Range` value carrier.
///
/// (86) + (87) together OPEN the (right-half-open) corner of the
/// (ordering × endpoint-inclusivity-flavor) 2×4 = 8-corner
/// hypercube past the four already-closed corners at
/// (inclusive-both) (82)+(83) and (exclusive-both) (84)+(85). The
/// (86)+(87) pair is the ASYMMETRIC-COMPOSITION corner where the
/// two pairwise-precedence predicates ([`Self::precedes_or_equal`]
/// and [`Self::precedes`]) BOTH participate at the range's two
/// endpoints — a typed peer of the mathematically canonical
/// half-open interval `[lo, hi)`. Adding
/// [`Self::is_left_half_open_between`] / [`Self::is_sorted_left_half_open_between`]
/// at (88)+(89) closes the FINAL corner of the (endpoint-
/// inclusivity-flavor) axis EXHAUSTIVELY on the ternary-
/// containment surface — the four flavors span the full closure
/// `{inclusive-both, exclusive-both, right-half-open, left-half-
/// open}` and there is no further sub-corner to open past the
/// eight-way exhaustive closure.
///
/// Theory anchor: THEORY.md §III — the typescape; the ternary
/// right-half-open-range containment predicate becomes a TYPE-level
/// primitive on the closed-set trait rather than a per-consumer
/// inline mixed conjunction of one non-strict-precedence call and
/// one strict-precedence call at every downstream generic site.
/// THEORY.md §V.1 — knowable platform; the right-half-open
/// endpoint-inclusivity axis was an unnamed asymmetric inline
/// composition (`lo.precedes_or_equal(v) && v.precedes(hi)`)
/// recurring at every prospective downstream half-open-range-
/// membership site pre-lift. Naming it on the trait makes the
/// predicate a TYPED CONSEQUENCE of BOTH pairwise-precedence
/// predicates applied at the two range endpoints, ONE per edge.
/// THEORY.md §VI.1 — generation over composition; the ternary
/// right-half-open containment predicate emerges from the
/// composition of THREE substrate primitives
/// ([`Self::precedes_or_equal`] at the lower edge +
/// [`Self::precedes`] at the upper edge + the standard-library `&&`
/// on `bool`) rather than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Rust's `std::ops::Range::contains(&v)` on
/// the value carrier `lo..hi` exposes the right-half-open
/// containment predicate as a first-class method on the
/// standard-library range type; Python's `lo <= v < hi` chained-
/// comparison idiom composes non-strict-below AND strict-above
/// into ONE bounded-range membership check syntactically; Kotlin's
/// `v in lo..<hi` right-exclusive-range operator exposes the same
/// half-open interval on ordered types. Translation through pleme-io
/// primitives: the ternary right-half-open containment predicate
/// on the closed-set trait binds through [`Self::precedes_or_equal`]
/// at the lower edge and [`Self::precedes`] at the upper edge —
/// the asymmetric mixed composition that defines `[lo, hi)`
/// mathematically. The closed-set trait carries the containment
/// predicate as a typed projection on the variant, not on a
/// foreign `Range` value carrier or a chained-comparison n-ary
/// macro; the mixed composition emerges from the substrate's typed
/// pairwise-comparison surface rather than as a fresh substrate
/// primitive on the index axis.
fn is_right_half_open_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::precedes_or_equal(lo, self) && <Self as ClosedSet>::precedes(self, hi)
}
/// The lex-order RIGHT-HALF-OPEN closed-range containment
/// predicate — `true` iff `self` sits in the half-open range
/// `[lo, hi)` of the lex-order [`Self::sorted_labels`], `false`
/// when `self` coincides with the upper endpoint `hi`, sits
/// strictly before `lo` OR strictly after `hi` in lex order. The
/// lex-ordering peer of [`Self::is_right_half_open_between`] on
/// the (declaration, lex) ordering axis of the ternary right-
/// half-open-range containment surface.
///
/// Sibling posture to [`Self::is_right_half_open_between`] one arm
/// over on the (declaration, lex) ordering axis —
/// [`Self::is_right_half_open_between`] uses
/// [`Self::precedes_or_equal`] at the lower edge and
/// [`Self::precedes`] at the upper edge (declaration order), this
/// method uses [`Self::sorted_precedes_or_equal`] at the lower
/// edge and [`Self::sorted_precedes`] at the upper edge (lex
/// order). See [`Self::is_right_half_open_between`] for the shared
/// right-half-open-range-containment laws (lower-endpoint-
/// inclusivity, upper-endpoint-exclusivity, empty-range
/// degeneracy), the range-partition contract, the future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis arm of the same ternary right-
/// half-open-range containment surface and inherits every property
/// from the declaration arm's documentation, differing only in the
/// projection methods the mixed composition routes through.
///
/// Default body composes [`Self::sorted_precedes_or_equal`] at the
/// lower edge with [`Self::sorted_precedes`] at the upper edge:
/// `lo.sorted_precedes_or_equal(self) &&
/// self.sorted_precedes(hi)`. Implementors override only when the
/// lex-axis ternary right-half-open-range containment surface
/// needs to diverge from the natural asymmetric mixed composition
/// of the pre-existing pairwise-precedence predicates applied at
/// the two range endpoints.
///
/// (86) + (87) together OPEN the (right-half-open) corner of the
/// (ordering × endpoint-inclusivity-flavor) 2×4 = 8-corner
/// hypercube past the four already-closed corners at
/// (inclusive-both) (82)+(83) and (exclusive-both) (84)+(85). See
/// [`Self::is_right_half_open_between`] for the shared (endpoint-
/// inclusivity-flavor) hypercube-closure narrative.
fn is_sorted_right_half_open_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::sorted_precedes_or_equal(lo, self)
&& <Self as ClosedSet>::sorted_precedes(self, hi)
}
/// The declaration-order LEFT-HALF-OPEN closed-range containment
/// predicate — `true` iff `self` sits in the half-open range
/// `(lo, hi]` of the declaration-order [`Self::ALL`], `false` when
/// `self` coincides with the lower endpoint `lo`, sits strictly
/// before `lo`, OR sits strictly after `hi`. The MIRROR
/// asymmetric-mix on the (endpoint-inclusivity-flavor) axis of the
/// ternary closed-range containment surface — mirroring the
/// mathematical `(lo, hi]` interval notation where the LEFT
/// endpoint is the OPEN one, and Kotlin's absent-but-natural
/// `v in lo<..hi` left-exclusive-range shape (Kotlin exposes
/// `..<` for right-half-open but not the mirror; the substrate
/// closes both flavors symmetrically).
///
/// Sibling posture to [`Self::is_between`] (both-inclusive,
/// `[lo, hi]`), [`Self::is_strictly_between`] (both-exclusive,
/// `(lo, hi)`), and [`Self::is_right_half_open_between`]
/// (right-half-open, `[lo, hi)`) one arm over on the (endpoint-
/// inclusivity-flavor) axis of the ternary closed-range
/// containment surface: [`Self::is_between`] composes
/// [`Self::precedes_or_equal`] at BOTH edges;
/// [`Self::is_strictly_between`] composes [`Self::precedes`] at
/// BOTH edges; [`Self::is_right_half_open_between`] composes
/// [`Self::precedes_or_equal`] at the LOWER edge and
/// [`Self::precedes`] at the UPPER edge; this method composes
/// [`Self::precedes`] at the LOWER edge and
/// [`Self::precedes_or_equal`] at the UPPER edge — the MIRROR
/// asymmetric mix that defines the left-half-open interval. The
/// declaration-axis composition binds through
/// `lo.precedes(self) ∧ self.precedes_or_equal(hi)`, so the
/// left-half-open containment predicate is a typed CONSEQUENCE
/// of the two pre-existing pairwise-precedence predicates
/// (strict at the lower edge, non-strict at the upper edge)
/// applied at the two range endpoints. Not a fresh substrate
/// primitive on the index axis — the composition emerges from
/// the just-closed 8-corner pairwise-comparison hypercube
/// through conjunction of one strict-forward arm and one non-
/// strict-forward arm — the MIRROR of
/// [`Self::is_right_half_open_between`]'s composition on the
/// (which-edge-is-strict) axis.
///
/// Endpoint-inclusivity contract: the LOWER endpoint `lo` sits
/// OUTSIDE the half-open range — `lo.is_left_half_open_between(lo,
/// hi)` is ALWAYS `false` (irreflexivity of [`Self::precedes`] at
/// the lower edge); the UPPER endpoint `hi` sits INSIDE —
/// `hi.is_left_half_open_between(lo, hi)` is `true` when
/// `lo.precedes(hi)` (the range is non-empty). Reflexivity on
/// the diagonal: `v.is_left_half_open_between(v, v)` is `false`
/// for every `v` because the singleton half-open range `(v, v]`
/// is EMPTY (no variant simultaneously strictly-succeeds `v` AND
/// non-strictly-precedes `v`). Empty-range degeneracy:
/// `v.is_left_half_open_between(hi, lo)` is `false` when `hi`
/// strictly succeeds `lo` — the reversed half-open range is
/// empty because no variant can simultaneously strictly succeed
/// `hi` AND non-strictly precede `lo` when `hi` sits later than
/// `lo`. The empty-range arm is a typed CONSEQUENCE of the
/// pairwise-precedence predicates' totality.
///
/// Range-partition contract: for every ordered pair `(lo, hi)`
/// with `lo.precedes_or_equal(hi)`, the set of variants `v` for
/// which `v.is_left_half_open_between(lo, hi)` is `true` equals
/// the LEFT-HALF-OPEN declaration-order slice
/// `Self::ALL[index_of(lo)+1..=index_of(hi)]` — the mirror
/// half-open interval, distinct from the inclusive-both peer's
/// closed interval `Self::ALL[index_of(lo)..=index_of(hi)]`,
/// from the exclusive-both peer's open interval
/// `Self::ALL[index_of(lo)+1..index_of(hi)]`, AND from the
/// right-half-open peer's slice
/// `Self::ALL[index_of(lo)..index_of(hi)]`. Pinned by
/// `is_left_half_open_between_partitions_all_across_every_bound_pair`.
///
/// Future consumers that compose against
/// [`Self::is_left_half_open_between`]: an LSP diagnostic that
/// ranges over the LEFT-HALF-OPEN interior of a closed-set
/// interval via `T::ALL.iter().filter(|v|
/// v.is_left_half_open_between(lo, hi))` — bind to ONE typed
/// ternary left-half-open-range containment predicate rather
/// than re-deriving `lo.precedes(v) && v.precedes_or_equal(hi)`
/// inline per callsite; a `tatara-check` predicate `(check-phase-
/// in-window-exclusive-lower …)` verifying a workspace-wide
/// phase-transition constraint where a phase must sit strictly
/// after a lower watermark AND at or before an upper watermark
/// (e.g. `Executing.is_left_half_open_between(Warming,
/// Contracting)` on the substrate's `WorkloadPhase` lifecycle —
/// the "past-warming, up-to-and-including draining" window); a
/// Sekiban audit-trail metric labeled by left-half-open
/// membership in a phase-transition window; the substrate's own
/// mirror iteration idiom `for v in T::ALL { if
/// v.is_left_half_open_between(lo, hi) { … } }` — the canonical
/// left-half-open iteration pattern lifted to the typed algebra
/// without leaking a foreign `std::ops::Range` value carrier
/// (which is right-half-open only on the stdlib surface).
///
/// (88) + (89) together CLOSE the (left-half-open) corner of the
/// (ordering × endpoint-inclusivity-flavor) 2×4 = 8-corner
/// hypercube EXHAUSTIVELY past the six already-closed corners at
/// (inclusive-both) (82)+(83), (exclusive-both) (84)+(85), and
/// (right-half-open) (86)+(87). Together the FOUR endpoint-
/// inclusivity flavors `{inclusive-both, exclusive-both,
/// right-half-open, left-half-open}` span the full closure on
/// the endpoint-inclusivity axis — there is no further sub-corner
/// to open past the EIGHT-way exhaustive closure. This lift is
/// the terminal move on the (endpoint-inclusivity-flavor) axis
/// of the ternary closed-range containment surface.
///
/// Theory anchor: THEORY.md §III — the typescape; the ternary
/// left-half-open-range containment predicate becomes a TYPE-
/// level primitive on the closed-set trait rather than a per-
/// consumer inline mirror mixed conjunction of one strict-
/// precedence call and one non-strict-precedence call at every
/// downstream generic site. THEORY.md §V.1 — knowable platform;
/// the left-half-open endpoint-inclusivity axis was an unnamed
/// asymmetric inline composition (`lo.precedes(v) &&
/// v.precedes_or_equal(hi)`) recurring at every prospective
/// downstream half-open-range-membership site pre-lift. Naming
/// it on the trait makes the predicate a TYPED CONSEQUENCE of
/// BOTH pairwise-precedence predicates applied at the two range
/// endpoints, ONE per edge, MIRRORED relative to
/// [`Self::is_right_half_open_between`]. THEORY.md §VI.1 —
/// generation over composition; the ternary left-half-open
/// containment predicate emerges from the composition of THREE
/// substrate primitives ([`Self::precedes`] at the lower edge +
/// [`Self::precedes_or_equal`] at the upper edge + the standard-
/// library `&&` on `bool`) rather than as a per-implementor
/// hand-rolled body.
///
/// Frontier inspiration: SQL's `BETWEEN … AND …` operator
/// implicitly closes both endpoints (`[lo, hi]`) and needs
/// `> lo AND <= hi` written out longhand to express `(lo, hi]`;
/// Racket's `<= x hi` composed with `< lo x` predicates through
/// `(and …)` at the `math/statistics` bin-membership boundary;
/// R's `findInterval(x, breaks, rightmost.closed = TRUE)` where
/// the RIGHTMOST bin is closed on both ends but the interior
/// bins are LEFT-HALF-OPEN `(lo, hi]` by default — the reverse
/// of Python/Rust's right-half-open convention. Translation
/// through pleme-io primitives: the ternary left-half-open
/// containment predicate on the closed-set trait binds through
/// [`Self::precedes`] at the lower edge and
/// [`Self::precedes_or_equal`] at the upper edge — the mirror
/// asymmetric mixed composition that defines `(lo, hi]`
/// mathematically, natively expressed on the typed closed-set
/// surface directly rather than through a foreign SQL/Racket/R
/// binning convention.
fn is_left_half_open_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::precedes(lo, self) && <Self as ClosedSet>::precedes_or_equal(self, hi)
}
/// The lex-order LEFT-HALF-OPEN closed-range containment
/// predicate — `true` iff `self` sits in the half-open range
/// `(lo, hi]` of the lex-order [`Self::sorted_labels`], `false`
/// when `self` coincides with the lower endpoint `lo`, sits
/// strictly before `lo` OR strictly after `hi` in lex order. The
/// lex-ordering peer of [`Self::is_left_half_open_between`] on
/// the (declaration, lex) ordering axis of the ternary left-
/// half-open-range containment surface.
///
/// Sibling posture to [`Self::is_left_half_open_between`] one
/// arm over on the (declaration, lex) ordering axis —
/// [`Self::is_left_half_open_between`] uses [`Self::precedes`]
/// at the lower edge and [`Self::precedes_or_equal`] at the
/// upper edge (declaration order), this method uses
/// [`Self::sorted_precedes`] at the lower edge and
/// [`Self::sorted_precedes_or_equal`] at the upper edge (lex
/// order). See [`Self::is_left_half_open_between`] for the
/// shared left-half-open-range-containment laws (lower-
/// endpoint-exclusivity, upper-endpoint-inclusivity, empty-
/// range degeneracy), the range-partition contract, the future-
/// consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// ternary left-half-open-range containment surface and inherits
/// every property from the declaration arm's documentation,
/// differing only in the projection methods the mirror mixed
/// composition routes through.
///
/// Default body composes [`Self::sorted_precedes`] at the lower
/// edge with [`Self::sorted_precedes_or_equal`] at the upper
/// edge: `lo.sorted_precedes(self) &&
/// self.sorted_precedes_or_equal(hi)`. Implementors override
/// only when the lex-axis ternary left-half-open-range
/// containment surface needs to diverge from the natural mirror
/// asymmetric mixed composition of the pre-existing pairwise-
/// precedence predicates applied at the two range endpoints.
///
/// (88) + (89) together CLOSE the (left-half-open) corner of the
/// (ordering × endpoint-inclusivity-flavor) 2×4 = 8-corner
/// hypercube EXHAUSTIVELY past the six already-closed corners at
/// (inclusive-both) (82)+(83), (exclusive-both) (84)+(85), and
/// (right-half-open) (86)+(87). See
/// [`Self::is_left_half_open_between`] for the shared (endpoint-
/// inclusivity-flavor) hypercube-closure narrative.
fn is_sorted_left_half_open_between(self, lo: Self, hi: Self) -> bool {
<Self as ClosedSet>::sorted_precedes(lo, self)
&& <Self as ClosedSet>::sorted_precedes_or_equal(self, hi)
}
/// The declaration-order ternary CLAMP projection — the
/// value-projection sibling of [`Self::is_between`] on the
/// (return-shape) axis of the ternary closed-range surface.
/// Given a well-formed range `[lo, hi]` with
/// `lo.precedes_or_equal(hi)`, projects `self` INTO the range by
/// (a) returning `lo` when `self` strictly precedes `lo`, (b)
/// returning `hi` when `hi` strictly precedes `self`, and (c)
/// returning `self` unchanged otherwise. The typed
/// value-projection dual of the eight-corner
/// (ordering × endpoint-inclusivity-flavor) bool-return ternary
/// containment hypercube (`is_between` (82)+(83),
/// `is_strictly_between` (84)+(85), `is_right_half_open_between`
/// (86)+(87), `is_left_half_open_between` (88)+(89)) — where the
/// eight bool-return corners answer "does `self` sit in the
/// range?", this projection answers "what variant IN the range
/// does `self` project to?".
///
/// Sibling posture to [`Self::is_between`] one arm over on the
/// (return-shape) axis: [`Self::is_between`] returns `bool`
/// (containment predicate), this method returns `Self` (containment
/// projection). The two together partition the (return-shape) axis
/// on ternary arity into TWO typed projections — one for
/// membership answers, one for saturation answers — with the
/// projection derived from the same substrate primitives
/// ([`Self::precedes`] at both bound-to-self edges) at ONE call
/// site rather than per-consumer.
///
/// Fixed-point + saturation contract: for every well-formed range
/// `[lo, hi]` with `lo.precedes_or_equal(hi)` and every variant
/// `v`:
///
/// - IN-RANGE FIXED POINT: `v.is_between(lo, hi) →
/// v.clamp(lo, hi) == v`. Every variant that sits INSIDE the
/// closed range is a fixed point of the projection — the
/// projection is the IDENTITY on the (inclusive-both)
/// containment set. Pinned by
/// `clamp_fixes_variants_that_sit_in_range_across_every_well_formed_triple`.
/// - BELOW-RANGE SATURATION: `v.precedes(lo) →
/// v.clamp(lo, hi) == lo`. Variants strictly below the range
/// saturate to the LOWER endpoint. Pinned by
/// `clamp_projects_below_range_variants_to_the_lower_endpoint`.
/// - ABOVE-RANGE SATURATION: `hi.precedes(v) →
/// v.clamp(lo, hi) == hi`. Variants strictly above the range
/// saturate to the UPPER endpoint. Pinned by
/// `clamp_projects_above_range_variants_to_the_upper_endpoint`.
/// - IDEMPOTENCE: `v.clamp(lo, hi).clamp(lo, hi) ==
/// v.clamp(lo, hi)` for every `v` — the projection is
/// IDEMPOTENT on every well-formed range because one hop lands
/// inside `[lo, hi]` and the second hop is the identity on the
/// containment set. Pinned by
/// `clamp_is_idempotent_on_every_well_formed_triple`.
/// - ENDPOINT FIXED POINTS: `lo.clamp(lo, hi) == lo` AND
/// `hi.clamp(lo, hi) == hi` for every well-formed pair — the
/// two range endpoints are ALWAYS fixed points. Pinned by
/// `clamp_fixes_range_endpoints_across_every_well_formed_triple`.
/// - PATH-UNIFORMITY: `v.clamp(lo, hi)` agrees with the
/// min-of-max composition `max(lo, min(v, hi))` routed through
/// the pairwise-precedence primitives — the projection is a
/// typed CONSEQUENCE of [`Self::precedes`] applied at the two
/// bound-to-self edges, not a fresh substrate primitive on the
/// index axis. Pinned by
/// `clamp_agrees_with_min_max_composition_on_every_well_formed_triple`.
///
/// Well-formedness precondition: implementors + consumers assume
/// `lo.precedes_or_equal(hi)` at every call site — the
/// reversed-range case (`hi.precedes(lo)`) is DEGENERATE (the
/// closed range `[lo, hi]` is empty when reversed) and the
/// projection's output on the reversed range is UNSPECIFIED past
/// "one of `{lo, hi, self}`". The tests pin the well-formed-range
/// contract only; downstream consumers should compose
/// [`Self::precedes_or_equal`] as a well-formedness guard when
/// the range endpoints originate from untrusted input.
///
/// Range-partition contract on the well-formed range: for every
/// ordered pair `(lo, hi)` with `lo.precedes_or_equal(hi)`, the
/// mapping `v → v.clamp(lo, hi)` projects
/// `Self::ALL[..index_of(lo)]` to the constant `lo`, projects
/// `Self::ALL[index_of(lo)..=index_of(hi)]` to the identity, and
/// projects `Self::ALL[index_of(hi)+1..]` to the constant `hi` —
/// the substrate-typed saturation semantics native to closed-set
/// projections on a finite total order. The IMAGE of the
/// projection under any well-formed range is exactly the closed
/// containment set of the range — the projection maps every
/// input variant to some variant that sits IN the range.
///
/// Future consumers that compose against [`Self::clamp`]: a
/// `tatara-check` predicate `(clamp-phase-into-window …)` that
/// projects a phase transition into a bounded lifecycle window
/// (e.g. `phase.clamp(Warming, Contracting)` on the substrate's
/// `WorkloadPhase` lifecycle — the "project stray phase into the
/// executing window" saturation); an LSP quickfix that saturates
/// an out-of-range user-supplied variant into the closed
/// containment set of a `#[clamp(lo, hi)]`-annotated field via
/// `T::ALL.iter().map(|v| v.clamp(lo, hi))` — bind to ONE typed
/// ternary clamp projection rather than re-deriving the
/// `min(max(v, lo), hi)` composition inline per callsite; a
/// Sekiban audit-trail projector that clamps an observed
/// lifecycle phase into the operator's authorized window before
/// emitting the audit event; the substrate's own saturation
/// idiom `for v in T::ALL { emit(v.clamp(lo, hi)) }` — the
/// canonical clamp iteration pattern lifted to the typed algebra
/// without leaking a foreign `Ord::clamp` panicking value carrier.
///
/// Default body composes [`Self::precedes`] at both bound-to-self
/// edges: `if self.precedes(lo) { lo } else if hi.precedes(self)
/// { hi } else { self }`. Implementors override only when the
/// declaration-axis ternary clamp projection needs to diverge from
/// the natural strict-precedence-guarded saturation.
///
/// (90) + (91) together OPEN the (return-shape) column on the
/// ternary-arity face of the closed-set surface past the
/// exhaustively-closed 8-corner (ordering ×
/// endpoint-inclusivity-flavor) bool-return hypercube — the two
/// arms cover the declaration and lex axes at
/// (Self-return, inclusive-both-endpoint) ternary arity. Future
/// extensions along the (endpoint-inclusivity-flavor) axis on the
/// Self-return corner can further carve the projection surface
/// into per-flavor clamps (a strictly-below/above form that
/// saturates to `lo.succeeds`/`hi.precedes` instead of `lo`/`hi`,
/// though `lo`/`hi` remain the natural inclusive saturation points
/// on a finite closed set).
///
/// Theory anchor: THEORY.md §III — the typescape; the ternary
/// clamp projection becomes a TYPE-level primitive on the
/// closed-set trait rather than a per-consumer inline
/// `if v < lo { lo } else if v > hi { hi } else { v }` shape at
/// every downstream generic site. THEORY.md §V.1 — knowable
/// platform; the clamp projection was an unnamed inline
/// composition recurring at every prospective downstream
/// closed-range-saturation site pre-lift. Naming it on the trait
/// makes the projection a TYPED CONSEQUENCE of the strict
/// pairwise-precedence predicate applied at both range endpoints,
/// symmetric to how [`Self::is_between`] emerges as a typed
/// consequence of the non-strict pairwise-precedence predicate
/// applied at both range endpoints one column over on the
/// (return-shape) axis.
/// THEORY.md §VI.1 — generation over composition; the ternary
/// clamp projection emerges from the composition of THREE
/// substrate primitives ([`Self::precedes`] at both bound-to-self
/// edges + the standard-library `if`/`else` on `bool`) rather
/// than as a per-implementor hand-rolled body.
///
/// Frontier inspiration: Rust's [`Ord::clamp`](core::cmp::Ord::clamp)
/// exposes the same saturation projection on any totally-ordered
/// type but PANICS via `assert!(min <= max)` on reversed
/// endpoints — a runtime-error escape hatch the substrate rejects
/// (a substrate primitive that panics on structurally-degenerate
/// input silently forces every consumer into pre-guard
/// boilerplate). Kotlin's `Comparable.coerceIn(lo, hi)` surfaces
/// the same projection with well-formedness-precondition-checked
/// behavior; Julia's `Base.clamp(x, lo, hi)` returns
/// `min(max(x, lo), hi)` unconditionally (defined on reversed
/// endpoints but degenerate). Translation through pleme-io
/// primitives: the substrate's ternary clamp projection binds
/// through [`Self::precedes`] at both bound-to-self edges — a
/// TOTAL projection on well-formed ranges, UNSPECIFIED but
/// non-panicking on reversed ranges (the substrate rejects the
/// std-clamp panic-on-precondition-violation shape). The typed
/// well-formedness precondition is documented, not asserted; the
/// closed-set trait carries the projection as a typed value
/// projection on the variant, not on a foreign `Range` value
/// carrier or a chained-comparison n-ary macro.
fn clamp(self, lo: Self, hi: Self) -> Self {
if <Self as ClosedSet>::precedes(self, lo) {
lo
} else if <Self as ClosedSet>::precedes(hi, self) {
hi
} else {
self
}
}
/// The lex-order ternary CLAMP projection — the value-projection
/// sibling of [`Self::is_sorted_between`] on the (return-shape)
/// axis of the ternary closed-range surface. Given a well-formed
/// lex-range `[lo, hi]` with `lo.sorted_precedes_or_equal(hi)`,
/// projects `self` INTO the lex-range by returning `lo` when
/// `self` strictly lex-precedes `lo`, returning `hi` when `hi`
/// strictly lex-precedes `self`, and returning `self` unchanged
/// otherwise. The lex-ordering peer of [`Self::clamp`] on the
/// (declaration, lex) ordering axis of the ternary Self-return
/// closed-range surface.
///
/// Sibling posture to [`Self::clamp`] one arm over on the
/// (declaration, lex) ordering axis — [`Self::clamp`] uses
/// [`Self::precedes`] at both bound-to-self edges (declaration
/// order), this method uses [`Self::sorted_precedes`] at both
/// bound-to-self edges (lex order). See [`Self::clamp`] for the
/// shared clamp-projection laws (in-range fixed-point,
/// below/above-range saturation, idempotence, endpoint fixed-
/// points, path-uniformity), the range-partition contract, the
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// ternary Self-return closed-range surface and inherits every
/// property from the declaration arm's documentation, differing
/// only in the projection method the strict-precedence-guarded
/// saturation routes through.
///
/// Default body composes [`Self::sorted_precedes`] at both bound-
/// to-self edges: `if self.sorted_precedes(lo) { lo } else if
/// hi.sorted_precedes(self) { hi } else { self }`. Implementors
/// override only when the lex-axis ternary clamp projection needs
/// to diverge from the natural lex-order strict-precedence-
/// guarded saturation.
///
/// (90) + (91) together OPEN the (return-shape) column on the
/// ternary-arity face of the closed-set surface past the
/// exhaustively-closed 8-corner (ordering ×
/// endpoint-inclusivity-flavor) bool-return hypercube. See
/// [`Self::clamp`] for the shared (return-shape) axis narrative.
fn sorted_clamp(self, lo: Self, hi: Self) -> Self {
if <Self as ClosedSet>::sorted_precedes(self, lo) {
lo
} else if <Self as ClosedSet>::sorted_precedes(hi, self) {
hi
} else {
self
}
}
/// The canonical `&'static str` LABEL of the declaration-order
/// ternary-CLAMP projection of `self` into the closed range
/// `[lo, hi]` — the label of [`Self::clamp`] projected through
/// [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`]: the ternary clamp projection is
/// TOTAL on well-formed ranges (every well-formed triple lands
/// on a variant in the closed range, and every variant carries
/// a canonical label).
///
/// The label-return arm of the (`Self`-return, `&'static str`-return,
/// `usize`-return) return-shape partition of the closed-set
/// declaration-order ternary-CLAMP surface — one return-shape
/// axis over from [`Self::clamp`] (`Self`-return declaration-axis
/// ternary-clamp) and one ordering axis over from
/// [`Self::sorted_clamp_label`] (`&'static str`-return lex-axis
/// ternary-clamp-label). Together with the three sibling clamp-
/// projection peers ([`Self::sorted_clamp_label`],
/// [`Self::clamp_index`], [`Self::sorted_clamp_index`]) OPENS the
/// (return-shape × ordering) 3×2 = 6-corner clamp face on the
/// ternary-arity surface past the pre-existing Self-return
/// 1×2 = 2-corner (declaration, lex) row that (90)+(91) opened,
/// mirroring the (return-shape × ordering) column pattern the
/// SATURATING neighbor lifts closed one boundary-behavior axis
/// over on the neighbor surface.
///
/// Every generic consumer that renders the ternary-clamp
/// projection's LABEL of a typed variant (an LSP quick-info
/// hover that clamps a phase into a validity window and emits
/// "phase clamped to: <label>", a diagnostic renderer that
/// projects an out-of-range enum tag into a policy-defined
/// clamp window and threads the projected label into the
/// `expected: <label>` shape, a metrics tagger that clamps an
/// observed variant into a reporting window and emits the
/// clamped label as the tag) binds to ONE typed method rather
/// than re-deriving the `v.clamp(lo, hi).label()` two-primitive
/// composition at every callsite.
///
/// Default body composes [`Self::clamp`] with [`Self::label`]
/// verbatim. The clamp-projection LABEL contract — the in-range
/// arm returns `self.label()` for every containment-set variant,
/// the below-range arm returns `lo.label()`, and the above-range
/// arm returns `hi.label()` — is guaranteed by the default
/// composition through [`Self::clamp`]'s strict-precedence-
/// guarded saturation. `T::first().clamp_label(T::first(),
/// T::first()) == T::first().label()` is the natural fixpoint
/// the ternary-clamp-label projection shares with the singleton-
/// range endpoint, mirroring the `T::first().clamp(T::first(),
/// T::first()) == T::first()` fixpoint one return-shape axis
/// over on the variant-return surface.
///
/// Frontier inspiration: Racket's
/// `(symbol-name (enum-clamp v lo hi))` — the label-projection
/// sibling of `enum-clamp` on a closed enumeration under the
/// strict-precedence-guarded saturation variant of the ordering;
/// MLIR's `RegisteredOperationName::clamp(lo, hi).getName()`
/// folded to ONE method on the closed Op registry's ternary
/// clamp projection; Julia's `Base.clamp(x, lo, hi) |> string`
/// applied to a closed enumeration and threaded through the
/// canonical name projection; Idris's `Fin n` composed through
/// `min lo (max hi x) |> toLabel` on the ternary-clamp
/// projection's finite-position projection under the label
/// return-shape column. Translation through pleme-io primitives:
/// a pure default method composing the trait's existing
/// [`Self::clamp`] + [`Self::label`] surfaces verbatim — no new
/// dep, no new IR layer, no supertrait bound, no `Option`-typed
/// dispatch, no allocation, no `strum` / `enum-iterator` crate
/// dependency.
fn clamp_label(self, lo: Self, hi: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::clamp(self, lo, hi))
}
/// The canonical `&'static str` LABEL of the lex-order ternary-
/// CLAMP projection of `self` into the closed lex-range
/// `[lo, hi]` — the label of [`Self::sorted_clamp`] projected
/// through [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`].
///
/// The lex-ordering peer of [`Self::clamp_label`] on the
/// (declaration, lex) ordering axis of the closed-set label-
/// return ternary-CLAMP surface. See [`Self::clamp_label`] for
/// the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// label-return ternary-clamp surface and inherits every
/// property from the declaration arm's documentation, differing
/// only in the substrate primitive the label-fallback routes
/// through ([`Self::sorted_clamp`] rather than [`Self::clamp`])
/// and the lex-ordering precedence guards it composes at both
/// bound-to-self edges ([`Self::sorted_precedes`] rather than
/// [`Self::precedes`]).
///
/// `T::sorted_first().sorted_clamp_label(T::sorted_first(),
/// T::sorted_first()) == T::sorted_first().label()` is the
/// natural fixpoint the lex-order ternary-clamp-label projection
/// shares with the singleton-lex-range endpoint, mirroring the
/// `T::first().clamp_label(T::first(), T::first()) ==
/// T::first().label()` fixpoint on the declaration arm one
/// ordering column over.
fn sorted_clamp_label(self, lo: Self, hi: Self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_clamp(self, lo, hi))
}
/// The `usize` DECLARATION-ORDER INDEX of the declaration-order
/// ternary-CLAMP projection of `self` into the closed range
/// `[lo, hi]` — the declaration-order position of
/// [`Self::clamp`] projected through [`Self::index_of`].
/// Returns `usize`, never [`Option<usize>`]: the ternary clamp
/// projection is TOTAL on well-formed ranges, and every
/// variant carries a declaration-order slot.
///
/// The index-return arm of the (`Self`-return, `&'static str`-return,
/// `usize`-return) return-shape partition of the closed-set
/// declaration-order ternary-CLAMP surface — one return-shape
/// axis over from [`Self::clamp`] (`Self`-return declaration-axis
/// ternary-clamp), one return-shape axis over from
/// [`Self::clamp_label`] (`&'static str`-return declaration-axis
/// ternary-clamp-label), and one ordering axis over from
/// [`Self::sorted_clamp_index`] (`usize`-return lex-axis
/// ternary-clamp-index). Together with the three sibling clamp-
/// projection peers this method CLOSES the (return-shape ×
/// ordering) 3×2 = 6-corner clamp face on the ternary-arity
/// surface past the pre-existing Self-return 1×2 = 2-corner
/// (declaration, lex) row — the {`Self`, label, index} return-
/// shape trio now carries every corner filled at the intersection
/// with the {declaration, lex} ordering pair on the ternary-
/// clamp column of the ternary-arity face.
///
/// Every generic consumer that renders the ternary-clamp
/// projection's SLOT of a typed variant (a compact wire codec
/// that clamps an observed enum tag into a policy-defined
/// reporting window and emits the clamped slot for cross-
/// boundary handoff without threading `Option`-dispatch through
/// the encoder, a per-variant lookup-table indexer that clamps
/// an out-of-range probe into the declared range and reads the
/// clamped slot into a `[Payload; T::CARDINALITY]` array, a
/// bitset over the closed-set that clamps observed samples into
/// a monitored window and reads the clamped slot as the bit
/// index) binds to ONE typed method rather than re-deriving the
/// `v.clamp(lo, hi).index_of()` two-primitive composition at
/// every callsite.
///
/// Default body composes [`Self::clamp`] with [`Self::index_of`]
/// verbatim. The clamp-projection INDEX contract — the in-range
/// arm returns `self.index_of()` for every containment-set
/// variant, the below-range arm returns `lo.index_of()`, and the
/// above-range arm returns `hi.index_of()` — is guaranteed by
/// the default composition through [`Self::clamp`]'s strict-
/// precedence-guarded saturation. `T::first().clamp_index(
/// T::first(), T::first()) == 0` is the natural fixpoint the
/// ternary-clamp-index projection shares with the declaration-
/// head slot, mirroring the `T::first().clamp(T::first(),
/// T::first()) == T::first()` fixpoint one return-shape axis
/// over on the variant-return surface AND the
/// `T::first().clamp_label(T::first(), T::first()) ==
/// T::first().label()` fixpoint one return-shape axis over on
/// the label-return surface.
///
/// Frontier inspiration: Racket's
/// `(enum-index (enum-clamp v lo hi))` — the index-projection
/// sibling of `enum-clamp` on a closed enumeration under the
/// strict-precedence-guarded saturation variant of the ordering;
/// MLIR's `RegisteredOperationName::clamp(lo, hi).getIndex()`
/// folded to ONE method on the closed Op registry's ternary
/// clamp projection; Idris's `Fin n` composed through the
/// ternary-clamp projection's finite-position projection under
/// the index return-shape column; LLVM's `EnumAttr::getValue()`
/// composed through the clamp-into-attribute-range projection
/// on a closed attribute enum. Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::clamp`] + [`Self::index_of`] surfaces
/// verbatim — no new dep, no new IR layer, no supertrait
/// bound, no `Option`-typed dispatch, no allocation, no
/// `strum` / `enum-iterator` crate dependency.
fn clamp_index(self, lo: Self, hi: Self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::clamp(self, lo, hi))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the lex-order
/// ternary-CLAMP projection of `self` into the closed lex-range
/// `[lo, hi]` — the lex position of [`Self::sorted_clamp`]
/// projected through [`Self::sorted_index_of`]. Returns `usize`,
/// never [`Option<usize>`].
///
/// The lex-ordering peer of [`Self::clamp_index`] on the
/// (declaration, lex) ordering axis of the closed-set index-
/// return ternary-CLAMP surface. See [`Self::clamp_index`] for
/// the shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the lex-axis arm of the same
/// index-return ternary-clamp surface and inherits every property
/// from the declaration arm's documentation, differing only in
/// the substrate primitive the index-fallback routes through
/// ([`Self::sorted_clamp`] rather than [`Self::clamp`]) and the
/// lex-ordering slot lookup it composes at the projection
/// ([`Self::sorted_index_of`] rather than [`Self::index_of`]).
///
/// Together with [`Self::clamp_label`], [`Self::sorted_clamp_label`],
/// and [`Self::clamp_index`] this method CLOSES the (return-shape
/// × ordering) 3×2 = 6-corner clamp face on the ternary-arity
/// surface past the pre-existing Self-return 1×2 = 2-corner
/// (declaration, lex) row that (90)+(91) opened — the ternary-
/// arity face on the closed-set surface now carries every corner
/// filled at the intersection of the {`Self`, label, index}
/// return-shape trio and the {declaration, lex} ordering pair on
/// the ternary-clamp column, mirroring the (return-shape ×
/// ordering × direction) 3×2×2 = 12-corner SATURATING neighbor
/// hypercube one boundary-behavior axis over on the neighbor
/// surface.
///
/// `T::sorted_first().sorted_clamp_index(T::sorted_first(),
/// T::sorted_first()) == 0` is the natural fixpoint the lex-
/// order ternary-clamp-index projection shares with the lex-
/// head slot, mirroring the `T::first().clamp_index(T::first(),
/// T::first()) == 0` fixpoint on the declaration arm one
/// ordering column over.
fn sorted_clamp_index(self, lo: Self, hi: Self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::sorted_clamp(self, lo, hi))
}
/// The declaration-order neighbor immediately AFTER `self` in
/// [`Self::ALL`], SATURATING at `self` at the tail — the third arm
/// of the (boundary-behavior) axis on the closed-set forward-
/// declaration-neighbor surface past the pre-existing
/// (Option-typed-bounded, [`Self`]-typed-wrapping) partition:
/// [`Self::next`] returns [`None`] at the tail, [`Self::cycle_next`]
/// FOLDS the tail-endpoint boundary onto [`Self::first`], and THIS
/// method PINS `self` at the tail-endpoint boundary — the
/// "stay-at-boundary" arm of the three-way boundary-behavior
/// partition. Returns [`Self`], never [`Option<Self>`]: the
/// saturating arm folds the tail-endpoint boundary onto `self`
/// itself rather than wrapping to the head ([`Self::cycle_next`])
/// or leaving the [`None`] the bounded arm ([`Self::next`]) returns.
///
/// The saturating-return arm of the (boundary-behavior) axis
/// closes a THIRD projection on the closed-set forward-neighbor
/// surface — one row beyond the (Option-typed-bounded,
/// [`Self`]-typed-wrapping) 2-row partition on the return-shape ×
/// boundary-behavior sub-face. Together with
/// [`Self::saturating_prev`], the pair closes the (forward,
/// backward) direction axis of the SATURATING arm on the
/// declaration ordering axis, and together with
/// [`Self::sorted_saturating_next`] / [`Self::sorted_saturating_prev`]
/// completes the (declaration × lex) × (forward, backward) 2×2
/// matrix on the SATURATING partition:
///
/// | Ordering \\ Direction | Forward saturate | Backward saturate |
/// |-----------------------|---------------------------------|----------------------------------|
/// | Declaration | [`Self::saturating_next`] | [`Self::saturating_prev`] |
/// | Lex | [`Self::sorted_saturating_next`] | [`Self::sorted_saturating_prev`] |
///
/// Every generic consumer that walks the closed set as a
/// STOP-AT-BOUNDARY chain under declaration order (an LSP
/// completion cursor that steps forward through variants
/// unconditionally without threading an `Option`-branch through
/// the update path AND without wrapping the tail-endpoint onto
/// the head at the boundary — a common UI shape where the
/// carousel arrow disables at the tail rather than cycling; a
/// keybinding-driven per-tick advance that stops at the last
/// variant rather than looping; a paginated selector that
/// disables the "next" affordance at the tail without rolling
/// over) binds to ONE typed saturating-forward-neighbor method
/// rather than hand-rolling either `self.next().unwrap_or(self)`
/// (which re-derives the same two-primitive composition at
/// every callsite AND makes every downstream site depend on
/// the saturating-fallback shape) OR a per-implementor inline
/// `match self { A => B, B => C, C => C }` block keyed on the
/// declaration slot (which re-derives the per-variant
/// saturating table at every callsite AND drifts silently when
/// [`Self::ALL`] gains a new variant whose slot reorders the
/// tail-saturating edge).
///
/// Sibling posture to [`Self::last`] on the (forward-neighbor,
/// tail-endpoint) axis of the declaration-order traversal
/// surface — `T::last().saturating_next() == T::last()` is the
/// natural fixpoint the forward-saturating-neighbor axis and the
/// tail-endpoint anchor share, PINNING the tail-endpoint variant
/// as the saturating-forward fixed point at the boundary.
/// Mirrors the `T::last().next() == None` fixpoint on the
/// bounded arm one boundary-behavior column over AND the
/// `T::last().cycle_next() == T::first()` fixpoint on the
/// wrapping arm one boundary-behavior column over — the three
/// arms differ ONLY at the tail-endpoint variant, agreeing on
/// EVERY interior variant.
///
/// Default body composes [`Self::next`] with the identity
/// fallback through [`Option::unwrap_or`] — the saturating-
/// neighbor projection is a typed CONSEQUENCE of the pre-
/// existing bounded-neighbor primitive folded through the
/// stay-at-`self` fallback, not a third codepath. Implementors
/// override only when the saturating-neighbor surface needs to
/// diverge from the natural `next().unwrap_or(self)` shape. An
/// implementor that overrides [`Self::next`] propagates the
/// override through this default body automatically; the
/// (variant → saturating-forward-neighbor) projection funnels
/// through ONE typed primitive.
///
/// The saturating-neighbor contract — the tail arm returns
/// `self` for [`Self::last`] — is guaranteed by the default
/// composition through [`Self::next`]'s `None` at the tail AND
/// [`Option::unwrap_or`]'s fallback semantics. Every generic
/// consumer can call [`Self::saturating_next`] on any typed
/// variant and expect the same [`Self`]-typed answer at every
/// crate boundary.
///
/// THEORY.md §III — the typescape; the (variant →
/// saturating-forward declaration-neighbor) projection becomes
/// a TYPE projection on the trait rather than a per-consumer
/// inline `self.next().unwrap_or(self)` composition at every
/// downstream saturating-traversal site. The (boundary-behavior)
/// axis on the closed-set forward-neighbor surface partitions
/// EXHAUSTIVELY into THREE typed projections — Option-typed
/// bounded ([`Self::next`]), [`Self`]-typed wrapping
/// ([`Self::cycle_next`]), [`Self`]-typed saturating (this
/// method) — each with a distinct load-bearing consumer surface.
/// THEORY.md §V.1 — knowable platform; the saturating-neighbor
/// projection was an unnamed compound of [`Self::next`] +
/// [`Option::unwrap_or`] pre-lift; naming it on the trait makes
/// the projection a TYPED CONSEQUENCE of the bounded-neighbor
/// primitive folded through the stay-at-`self` fallback —
/// generic consumers see ONE saturating-forward method, not one
/// saturating-shape-per-crate.
/// THEORY.md §VI.1 — generation over composition; the
/// saturating-forward-neighbor projection emerges from
/// composition of ONE substrate primitive ([`Self::next`])
/// through [`Option::unwrap_or`] rather than as a per-implementor
/// `match self { A => B, B => C, C => C }` block keyed on the
/// declaration slot with an identity fallthrough at the tail.
///
/// Frontier inspiration: Rust's `usize::saturating_add(1)` on
/// the totally-ordered `usize` universe (the arithmetic
/// saturating primitive that pins the operand at `usize::MAX`
/// on overflow, mirrored HERE as the variant saturating primitive
/// that pins the operand at [`Self::last`] on tail); Kotlin's
/// `Iterator.nextOrNull()` composed with `?: this` (the manual
/// stay-at-self fallback); Racket's `enum-next-clamped` on
/// closed enumerations under the clamp-at-boundary variant of
/// the cyclic ordering; UI toolkit carousel bindings that
/// disable the "next" affordance at the boundary (React
/// Aria's `useCarousel` clamped variant, Radix's `Carousel.Next`
/// with `disabled` at the tail). Translation through pleme-io
/// primitives: a pure default method composing the trait's
/// existing [`Self::next`] surface via [`Option::unwrap_or`] —
/// no new dep, no new IR layer, no supertrait bound, no
/// arithmetic on `usize`, no wrapping to the head, no `None` on
/// the tail-endpoint boundary.
fn saturating_next(self) -> Self {
<Self as ClosedSet>::next(self).unwrap_or(self)
}
/// The declaration-order neighbor immediately BEFORE `self` in
/// [`Self::ALL`], SATURATING at `self` at the head —
/// `self.prev().unwrap_or(self)`. Returns [`Self`], never
/// [`Option<Self>`]: the saturating arm folds the head-endpoint
/// boundary onto `self` itself rather than wrapping to the tail
/// ([`Self::cycle_prev`]) or leaving the [`None`] the bounded
/// arm ([`Self::prev`]) returns.
///
/// Sibling posture to [`Self::saturating_next`] one arm over on
/// the (forward, backward) direction partition of the closed-set
/// saturating-neighbor surface: [`Self::saturating_next`] returns
/// the declaration-order successor pinned at the tail-endpoint,
/// this method returns the declaration-order predecessor pinned
/// at the head-endpoint. See [`Self::saturating_next`] for the
/// shared design rationale, sibling matrix, override axis,
/// future-consumer inventory, THEORY.md grounding, and frontier
/// inspiration — this method is the backward-direction arm of
/// the same axis and inherits every property from the forward
/// arm's documentation, differing only in the [`Self::prev`]
/// substrate primitive it composes and the head-endpoint anchor
/// it pins at the boundary.
///
/// Default body composes [`Self::prev`] with the identity
/// fallback through [`Option::unwrap_or`] — the saturating-
/// neighbor projection is a typed CONSEQUENCE of the pre-
/// existing bounded-neighbor primitive folded through the
/// stay-at-`self` fallback, not a third codepath. Implementors
/// override only when the saturating-neighbor surface needs to
/// diverge from the natural `prev().unwrap_or(self)` shape.
///
/// The saturating-neighbor contract — the head arm returns
/// `self` for [`Self::first`] — is guaranteed by the default
/// composition through [`Self::prev`]'s `None` at the head AND
/// [`Option::unwrap_or`]'s fallback semantics.
/// `T::first().saturating_prev() == T::first()` is the natural
/// fixpoint the backward-saturating-neighbor axis and the
/// head-endpoint anchor share, mirroring the
/// `T::last().saturating_next() == T::last()` fixpoint on the
/// forward-saturating arm one direction column over AND the
/// `T::first().prev() == None` fixpoint on the bounded arm one
/// boundary-behavior column over AND the
/// `T::first().cycle_prev() == T::last()` fixpoint on the
/// wrapping arm one boundary-behavior column over.
fn saturating_prev(self) -> Self {
<Self as ClosedSet>::prev(self).unwrap_or(self)
}
/// The lex-order neighbor immediately AFTER `self` in
/// [`Self::sorted_variants`], SATURATING at `self` at the lex
/// tail — `self.sorted_next().unwrap_or(self)`. Returns
/// [`Self`], never [`Option<Self>`]: the saturating arm folds
/// the lex-tail-endpoint boundary onto `self` itself rather
/// than wrapping to the lex head ([`Self::cycle_sorted_next`])
/// or leaving the [`None`] the bounded lex arm
/// ([`Self::sorted_next`]) returns.
///
/// The lex-ordering peer of [`Self::saturating_next`] on the
/// (declaration, lex) ordering axis of the closed-set
/// saturating-forward-neighbor surface. See
/// [`Self::saturating_next`] for the shared design rationale,
/// sibling matrix, override axis, future-consumer inventory,
/// THEORY.md grounding, and frontier inspiration — this method
/// is the lex-axis arm of the same saturating-forward-neighbor
/// surface and inherits every property from the declaration
/// arm's documentation, differing only in the substrate
/// primitive the saturating-fallback routes through
/// ([`Self::sorted_next`] rather than [`Self::next`]) and the
/// lex-tail-endpoint anchor it pins at the boundary
/// ([`Self::sorted_last`] rather than [`Self::last`]).
///
/// `T::sorted_last().sorted_saturating_next() == T::sorted_last()`
/// is the natural fixpoint the forward-saturating-lex-neighbor
/// axis and the lex-tail-endpoint anchor share, mirroring the
/// `T::last().saturating_next() == T::last()` fixpoint on the
/// declaration arm one ordering column over.
fn sorted_saturating_next(self) -> Self {
<Self as ClosedSet>::sorted_next(self).unwrap_or(self)
}
/// The lex-order neighbor immediately BEFORE `self` in
/// [`Self::sorted_variants`], SATURATING at `self` at the lex
/// head — `self.sorted_prev().unwrap_or(self)`. Returns
/// [`Self`], never [`Option<Self>`]: the saturating arm folds
/// the lex-head-endpoint boundary onto `self` itself rather
/// than wrapping to the lex tail ([`Self::cycle_sorted_prev`])
/// or leaving the [`None`] the bounded lex arm
/// ([`Self::sorted_prev`]) returns.
///
/// The lex-ordering peer of [`Self::saturating_prev`] on the
/// (declaration, lex) ordering axis of the closed-set
/// saturating-backward-neighbor surface. See
/// [`Self::saturating_next`] for the shared design rationale
/// on the (boundary-behavior) axis and the three-arm partition
/// (bounded / wrapping / saturating), and [`Self::saturating_prev`]
/// for the backward-direction sibling posture. Together with
/// [`Self::saturating_next`], [`Self::saturating_prev`], and
/// [`Self::sorted_saturating_next`] this method CLOSES the
/// (declaration × lex) × (forward, backward) 2×2 = 4-corner
/// matrix on the SATURATING arm of the (boundary-behavior)
/// axis of the closed-set variant-return neighbor surface —
/// the (boundary-behavior) axis now carries THREE arms
/// (Option-typed bounded, [`Self`]-typed wrapping, [`Self`]-typed
/// saturating) across the full (ordering × direction) 4-corner
/// matrix, for a 3×2×2 = 12-corner (boundary-behavior × ordering
/// × direction) hypercube on the variant-return neighbor
/// surface.
///
/// `T::sorted_first().sorted_saturating_prev() == T::sorted_first()`
/// is the natural fixpoint the backward-saturating-lex-neighbor
/// axis and the lex-head-endpoint anchor share, completing the
/// four saturating-neighbor fixpoints at every arm of the 2×2
/// (ordering × direction) matrix.
fn sorted_saturating_prev(self) -> Self {
<Self as ClosedSet>::sorted_prev(self).unwrap_or(self)
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately AFTER `self` in [`Self::ALL`], SATURATING
/// at [`Self::label`] at the tail — the label of
/// [`Self::saturating_next`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`]: the
/// saturating arm folds the tail-endpoint boundary onto `self`'s
/// OWN label rather than wrapping to [`Self::first_label`] (the
/// wrapping arm's [`Self::cycle_next_label`] fold) or leaving the
/// [`None`] the bounded arm ([`Self::next_label`]) returns.
///
/// The label-return arm of the (Self-return, `&'static str`-return)
/// return-shape partition of the closed-set
/// SATURATING-forward-neighbor surface — one return-shape axis
/// over from [`Self::saturating_next`] (`Self`-return declaration-
/// axis saturating-forward), one boundary-behavior axis over from
/// [`Self::next_label`] (`Option<&'static str>`-return bounded-
/// forward-label), and one boundary-behavior axis over from
/// [`Self::cycle_next_label`] (`&'static str`-return wrapping-
/// forward-label). Together with the three lex + backward peers
/// below, this OPENS the label-return column on the SATURATING
/// arm of the (boundary-behavior) axis on the label-shaped
/// neighbor surface past the pre-existing (bounded, wrapping)
/// 2-row partition — the (return-shape × boundary-behavior)
/// column pattern the [`Self::saturating_next`] lift opened on
/// the variant-return surface now closes one return-shape column
/// over onto the label-return surface as well.
///
/// Every generic consumer that renders the saturating-forward-
/// neighbor LABEL of a typed variant (an LSP completion cursor
/// that emits "next: <label>" for the next variant but STAYS at
/// the current label at the tail-endpoint rather than cycling to
/// the head-label, a paginated selector's "next" affordance's
/// label renderer that disables at the boundary by re-emitting
/// the current label, a carousel widget's next-arrow label
/// renderer that reads the same label when the arrow is
/// disabled) binds to ONE typed method rather than re-deriving
/// the `v.saturating_next().label()` two-primitive composition
/// OR the `v.next_label().unwrap_or(v.label())` three-primitive
/// composition at every callsite.
///
/// Default body composes [`Self::saturating_next`] with
/// [`Self::label`] verbatim. The saturating-neighbor-label
/// contract — the tail arm returns `self.label()` for
/// [`Self::last`] — is guaranteed by the default composition
/// through [`Self::saturating_next`]'s tail-stay-at-`self` fold.
/// `T::last().saturating_next_label() == T::last().label()` is
/// the natural fixpoint the forward-saturating-neighbor-label
/// axis and the tail-endpoint anchor share, mirroring the
/// `T::last().saturating_next() == T::last()` fixpoint one
/// return-type axis over on the variant-return surface AND the
/// `T::last().cycle_next_label() == T::first_label()` fixpoint
/// one boundary-behavior axis over on the wrapping arm.
///
/// Frontier inspiration: Racket's
/// `(symbol-name (enum-next-clamped v))` — the label-projection
/// sibling of `enum-next-clamped` on a closed enumeration under
/// the clamp-at-boundary variant of the ordering; MLIR's
/// `RegisteredOperationName::saturatingNext().getName()` folded to
/// ONE method on the closed Op registry's saturating-successor
/// projection; UI toolkit carousel bindings that read the "next"
/// affordance's label from the disabled-at-boundary state without
/// wrapping to the opposite endpoint's label (React Aria's
/// `useCarousel` clamped-mode label rendering, Radix's
/// `Carousel.Next` disabled-tail label rendering). Translation
/// through pleme-io primitives: a pure default method composing
/// the trait's existing [`Self::saturating_next`] +
/// [`Self::label`] surfaces verbatim — no new dep, no new IR
/// layer, no supertrait bound, no `Option`-typed dispatch, no
/// allocation.
fn saturating_next_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::saturating_next(self))
}
/// The canonical `&'static str` LABEL of the declaration-order
/// neighbor immediately BEFORE `self` in [`Self::ALL`], SATURATING
/// at [`Self::label`] at the head — the label of
/// [`Self::saturating_prev`] projected through [`Self::label`].
/// Returns `&'static str`, never [`Option<&'static str>`].
///
/// Sibling posture to [`Self::saturating_next_label`] one
/// direction over on the (forward, backward) direction partition
/// of the closed-set saturating-label-neighbor surface. See
/// [`Self::saturating_next_label`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the backward-direction arm of the same axis and
/// inherits every property from the forward arm's documentation,
/// differing only in the [`Self::saturating_prev`] substrate
/// primitive it composes and the head-endpoint stay-at-`self`
/// anchor it pins at the boundary.
///
/// Default body composes [`Self::saturating_prev`] with
/// [`Self::label`] verbatim. The saturating-neighbor-label
/// contract — the head arm returns `self.label()` for
/// [`Self::first`] — is guaranteed by the default composition
/// through [`Self::saturating_prev`]'s head-stay-at-`self` fold.
/// `T::first().saturating_prev_label() == T::first().label()` is
/// the natural fixpoint the backward-saturating-neighbor-label
/// axis and the head-endpoint anchor share, mirroring
/// `T::first().saturating_prev() == T::first()` one return-type
/// axis over on the variant-return surface AND
/// `T::first().cycle_prev_label() == T::last_label()` one
/// boundary-behavior axis over on the wrapping arm.
fn saturating_prev_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::saturating_prev(self))
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately AFTER `self` in [`Self::sorted_variants`],
/// SATURATING at [`Self::label`] at the lex tail — the label of
/// [`Self::sorted_saturating_next`] projected through
/// [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`].
///
/// The lex-ordering peer of [`Self::saturating_next_label`] on the
/// (declaration, lex) ordering axis of the closed-set
/// saturating-label-forward-neighbor surface. See
/// [`Self::saturating_next_label`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis arm of the same
/// saturating-forward-label-neighbor surface and inherits every
/// property from the declaration arm's documentation, differing
/// only in the substrate primitive the saturating-label-fallback
/// routes through ([`Self::sorted_saturating_next`] rather than
/// [`Self::saturating_next`]) and the lex-tail-endpoint anchor it
/// pins at the boundary.
///
/// `T::sorted_last().sorted_saturating_next_label() ==
/// T::sorted_last().label()` is the natural fixpoint the forward-
/// saturating-lex-label-neighbor axis and the lex-tail-endpoint
/// anchor share, mirroring the
/// `T::last().saturating_next_label() == T::last().label()`
/// fixpoint on the declaration arm one ordering column over.
fn sorted_saturating_next_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_saturating_next(self))
}
/// The canonical `&'static str` LABEL of the lexicographic-order
/// neighbor immediately BEFORE `self` in [`Self::sorted_variants`],
/// SATURATING at [`Self::label`] at the lex head — the label of
/// [`Self::sorted_saturating_prev`] projected through
/// [`Self::label`]. Returns `&'static str`, never
/// [`Option<&'static str>`].
///
/// Sibling posture to [`Self::sorted_saturating_next_label`] one
/// direction over on the (forward, backward) direction partition
/// of the closed-set saturating-lex-label-neighbor surface.
/// Together with [`Self::saturating_next_label`],
/// [`Self::saturating_prev_label`], and
/// [`Self::sorted_saturating_next_label`] this method CLOSES the
/// (declaration × lex) × (forward, backward) 2×2 = 4-corner matrix
/// on the SATURATING arm of the (boundary-behavior) axis of the
/// closed-set label-return neighbor surface — the (return-shape ×
/// boundary-behavior) 2×3 = 6-column plane on the (ordering ×
/// direction) 4-corner grid now carries an additional 4 corners
/// on the label-return side, mirroring the 4 corners the
/// [`Self::saturating_next`] lift opened on the variant-return
/// side, for a jointly-closed (return-shape × boundary-behavior ×
/// ordering × direction) 2×3×2×2 = 24-corner
/// label-and-variant-return neighbor sub-hypercube on the closed-
/// set surface — the wrapping-and-bounded 2×2×2×2 = 16-corner
/// hypercube on the same return-shape × ordering × direction axes
/// (which commit d10ab00 CLOSED) now extends to include the
/// saturating column that this quartet opens.
///
/// `T::sorted_first().sorted_saturating_prev_label() ==
/// T::sorted_first().label()` is the natural fixpoint the
/// backward-saturating-lex-label-neighbor axis and the lex-head-
/// endpoint anchor share, completing the four saturating-label-
/// neighbor fixpoints at every arm of the 2×2 (ordering ×
/// direction) matrix on the label-return SATURATING column.
fn sorted_saturating_prev_label(self) -> &'static str {
<Self as ClosedSet>::label(<Self as ClosedSet>::sorted_saturating_prev(self))
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// AFTER `self` in [`Self::ALL`], SATURATING at
/// [`Self::index_of`]`(self)` at the tail — the declaration-order
/// position of [`Self::saturating_next`] projected through
/// [`Self::index_of`]. Returns `usize`, never [`Option<usize>`]:
/// the saturating arm folds the tail-endpoint boundary onto
/// `self`'s OWN slot rather than wrapping to `0` (the wrapping
/// arm's [`Self::cycle_next_index`] fold) or leaving the [`None`]
/// the bounded arm ([`Self::next_index`]) returns.
///
/// The index-return arm of the (`Self`-return, `&'static str`-return,
/// `usize`-return) return-shape partition of the closed-set
/// SATURATING-forward-neighbor surface — one return-shape axis
/// over from [`Self::saturating_next`] (`Self`-return declaration-
/// axis saturating-forward), one return-shape axis over from
/// [`Self::saturating_next_label`] (`&'static str`-return
/// declaration-axis saturating-forward-label), one boundary-behavior
/// axis over from [`Self::next_index`] (`Option<usize>`-return
/// bounded-forward-index), and one boundary-behavior axis over
/// from [`Self::cycle_next_index`] (`usize`-return wrapping-forward-
/// index). Together with the three lex + backward peers below,
/// this CLOSES the index-return column on the SATURATING arm of
/// the (boundary-behavior) axis on the index-shaped neighbor
/// surface — the (return-shape × boundary-behavior × ordering ×
/// direction) 3×3×2×2 = 36-corner
/// index-and-label-and-variant-return neighbor hypercube on the
/// closed-set surface now carries every corner filled at the
/// intersection of the {`Self`, label, index} return-shape trio and
/// the {bounded, wrapping, saturating} boundary-behavior trio.
///
/// Every generic consumer that renders the saturating-forward-
/// neighbor SLOT of a typed variant (an LSP completion cursor
/// that emits `next-slot: <index>` for the next variant but STAYS
/// at the current slot at the tail-endpoint rather than cycling
/// to slot `0`, a compact wire codec that emits the saturating
/// successor's slot for cross-boundary handoff without threading
/// `Option`-dispatch through the encoder, a bounded-selector's
/// "next" affordance's slot renderer that disables at the
/// boundary by re-emitting the current slot, a carousel widget's
/// next-arrow slot renderer that reads the same slot when the
/// arrow is disabled) binds to ONE typed method rather than
/// re-deriving the `v.saturating_next().index_of()`
/// two-primitive composition OR the
/// `v.next_index().unwrap_or(v.index_of())` three-primitive
/// composition at every callsite.
///
/// Default body composes [`Self::saturating_next`] with
/// [`Self::index_of`] verbatim. The saturating-neighbor-index
/// contract — the tail arm returns `self.index_of()` for
/// [`Self::last`] — is guaranteed by the default composition
/// through [`Self::saturating_next`]'s tail-stay-at-`self` fold.
/// `T::last().saturating_next_index() == T::last().index_of()`
/// (i.e. `T::CARDINALITY - 1`) is the natural fixpoint the
/// forward-saturating-neighbor-index axis and the tail-endpoint
/// anchor share, mirroring the
/// `T::last().saturating_next() == T::last()` fixpoint one
/// return-type axis over on the variant-return surface AND the
/// `T::last().saturating_next_label() == T::last().label()`
/// fixpoint one return-type axis over on the label-return surface
/// AND the `T::last().cycle_next_index() == 0` fixpoint one
/// boundary-behavior axis over on the wrapping arm.
///
/// Frontier inspiration: Racket's
/// `(enum-index (enum-next-clamped v))` — the index-projection
/// sibling of `enum-next-clamped` on a closed enumeration under
/// the clamp-at-boundary variant of the ordering; MLIR's
/// `RegisteredOperationName::saturatingNext().getIndex()` folded
/// to ONE method on the closed Op registry's saturating-successor
/// index projection; Idris's `Fin n` composed through `weakenN`
/// on the saturating-successor's finite-position projection under
/// the tail-stay-at-`n-1` variant of the ordering; UI toolkit
/// carousel bindings that read the disabled-tail next-slot from
/// the current slot without wrapping to slot 0 (React Aria's
/// `useCarousel` clamped-mode current-index rendering, Radix's
/// `Carousel.Next` disabled-tail current-index rendering).
/// Translation through pleme-io primitives: a pure default method
/// composing the trait's existing [`Self::saturating_next`] +
/// [`Self::index_of`] surfaces verbatim — no new dep, no new IR
/// layer, no supertrait bound, no `Option`-typed dispatch, no
/// allocation, no `strum` / `enum-iterator` crate dependency.
fn saturating_next_index(self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::saturating_next(self))
}
/// The `usize` DECLARATION-ORDER INDEX of the neighbor immediately
/// BEFORE `self` in [`Self::ALL`], SATURATING at
/// [`Self::index_of`]`(self)` at the head — the declaration-order
/// position of [`Self::saturating_prev`] projected through
/// [`Self::index_of`]. Returns `usize`, never [`Option<usize>`].
///
/// Sibling posture to [`Self::saturating_next_index`] one
/// direction over on the (forward, backward) direction partition
/// of the closed-set saturating-index-neighbor surface. See
/// [`Self::saturating_next_index`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the backward-direction arm of the same axis
/// and inherits every property from the forward arm's
/// documentation, differing only in the [`Self::saturating_prev`]
/// substrate primitive it composes and the head-endpoint
/// stay-at-`self.index_of()` anchor it pins at the boundary.
///
/// Default body composes [`Self::saturating_prev`] with
/// [`Self::index_of`] verbatim. The saturating-neighbor-index
/// contract — the head arm returns `self.index_of()` for
/// [`Self::first`] — is guaranteed by the default composition
/// through [`Self::saturating_prev`]'s head-stay-at-`self` fold.
/// `T::first().saturating_prev_index() == T::first().index_of()`
/// (i.e. `0`) is the natural fixpoint the backward-saturating-
/// neighbor-index axis and the head-endpoint anchor share,
/// mirroring `T::first().saturating_prev() == T::first()` one
/// return-type axis over on the variant-return surface AND
/// `T::first().saturating_prev_label() == T::first().label()`
/// one return-type axis over on the label-return surface AND
/// `T::first().cycle_prev_index() == T::CARDINALITY - 1` one
/// boundary-behavior axis over on the wrapping arm.
fn saturating_prev_index(self) -> usize {
<Self as ClosedSet>::index_of(<Self as ClosedSet>::saturating_prev(self))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor
/// immediately AFTER `self` in [`Self::sorted_variants`],
/// SATURATING at [`Self::sorted_index_of`]`(self)` at the lex
/// tail — the lex position of [`Self::sorted_saturating_next`]
/// projected through [`Self::sorted_index_of`]. Returns `usize`,
/// never [`Option<usize>`].
///
/// The lex-ordering peer of [`Self::saturating_next_index`] on
/// the (declaration, lex) ordering axis of the closed-set
/// saturating-index-forward-neighbor surface. See
/// [`Self::saturating_next_index`] for the shared design
/// rationale, sibling matrix, override axis, future-consumer
/// inventory, THEORY.md grounding, and frontier inspiration —
/// this method is the lex-axis arm of the same
/// saturating-forward-index-neighbor surface and inherits every
/// property from the declaration arm's documentation, differing
/// only in the substrate primitive the saturating-index-fallback
/// routes through ([`Self::sorted_saturating_next`] rather than
/// [`Self::saturating_next`]) and the lex-tail-endpoint anchor it
/// pins at the boundary
/// ([`Self::sorted_index_of`]`(`[`Self::sorted_last`]`)` rather
/// than [`Self::index_of`]`(`[`Self::last`]`)`).
///
/// `T::sorted_last().sorted_saturating_next_index() ==
/// T::sorted_last().sorted_index_of()` (i.e. `T::CARDINALITY - 1`)
/// is the natural fixpoint the forward-saturating-lex-index-
/// neighbor axis and the lex-tail-endpoint anchor share,
/// mirroring the
/// `T::last().saturating_next_index() == T::last().index_of()`
/// fixpoint on the declaration arm one ordering column over.
fn sorted_saturating_next_index(self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::sorted_saturating_next(self))
}
/// The `usize` LEXICOGRAPHIC-ORDER INDEX of the neighbor
/// immediately BEFORE `self` in [`Self::sorted_variants`],
/// SATURATING at [`Self::sorted_index_of`]`(self)` at the lex
/// head — the lex position of [`Self::sorted_saturating_prev`]
/// projected through [`Self::sorted_index_of`]. Returns `usize`,
/// never [`Option<usize>`].
///
/// Sibling posture to [`Self::sorted_saturating_next_index`] one
/// direction over on the (forward, backward) direction partition
/// of the closed-set saturating-lex-index-neighbor surface.
/// Together with [`Self::saturating_next_index`],
/// [`Self::saturating_prev_index`], and
/// [`Self::sorted_saturating_next_index`] this method CLOSES the
/// (declaration × lex) × (forward, backward) 2×2 = 4-corner
/// matrix on the SATURATING arm of the (boundary-behavior) axis
/// of the closed-set index-return neighbor surface — the
/// (return-shape × boundary-behavior × ordering × direction)
/// 3×3×2×2 = 36-corner
/// index-and-label-and-variant-return neighbor hypercube on the
/// closed-set surface now carries every corner filled at the
/// intersection of the {`Self`, label, index} return-shape trio
/// and the {bounded, wrapping, saturating} boundary-behavior trio
/// — the wrapping-and-bounded 2×3×2×2 = 24-corner hypercube on
/// the same return-shape × ordering × direction axes (which
/// commit 6e6c5b9 CLOSED) now extends to include the saturating
/// column that this quartet opens.
///
/// `T::sorted_first().sorted_saturating_prev_index() ==
/// T::sorted_first().sorted_index_of()` (i.e. `0`) is the natural
/// fixpoint the backward-saturating-lex-index-neighbor axis and
/// the lex-head-endpoint anchor share, completing the four
/// saturating-index-neighbor fixpoints at every arm of the 2×2
/// (ordering × direction) matrix on the index-return SATURATING
/// column.
fn sorted_saturating_prev_index(self) -> usize {
<Self as ClosedSet>::sorted_index_of(<Self as ClosedSet>::sorted_saturating_prev(self))
}
}
/// Generic well-formedness contract for a [`ClosedSet`] implementor —
/// the substrate-wide testkit helper that lifts the three structural
/// invariants every per-implementor test module re-derived byte-for-byte
/// pre-lift onto ONE call site:
///
/// 1. `T::ALL` is non-empty — a closed-set with zero variants is a
/// degenerate codomain [`ClosedSet::parse_label`] can never succeed
/// on; an empty `ALL` is a structural bug at the type-system
/// boundary, not a runtime accident.
/// 2. Every variant in `T::ALL` round-trips through
/// [`ClosedSet::label`] → [`ClosedSet::parse_label`] back to itself —
/// the workspace-wide `*_roundtrip_via_as_str` invariant lifted from
/// the per-implementor test surface (`ProcessPhase`,
/// `VerificationPhase`, `MustReachPhase`, `IntentKind`, `LifetimeKind`,
/// …) onto the trait.
/// 3. The labels of `T::ALL` are pairwise distinct — distinctness feeds
/// [`ClosedSet::parse_label`]'s linear sweep: a duplicate would
/// silently fold two variants into one at the round-trip boundary
/// (the sweep returns the FIRST matching variant). The workspace-wide
/// `*_all_is_unique_and_complete` invariant lifted from the
/// per-implementor `HashSet`-sweep test onto the trait.
/// 4. The empty string `""` is OUTSIDE the closed set —
/// `parse_label("")` returns [`Err`]. This is implied by (2) + (3)
/// when no implementor's `label()` projects to `""`, but checking it
/// directly catches a regression where an implementor accidentally
/// introduced an empty label as a variant projection.
/// 5. [`ClosedSet::SET_LABEL`] is non-empty AND the typed parse-rejection
/// carrier's [`core::fmt::Display`] rendering threads it into the
/// substrate-wide `"unknown {SET_LABEL}: {input}"` shape verbatim —
/// the per-implementor `_message_matches_substrate_convention` test
/// that 13+ implementors pin byte-for-byte (`UnknownEncapsulationTarget`
/// → `"unknown encapsulation target: foo"`, `UnknownArtifactKind` →
/// `"unknown artifact kind: foo"`, …) lifted onto the trait so the
/// diagnostic-shape contract emits from ONE generative origin (the
/// derive's `emit_unknown_struct` helper) AND verifies through ONE
/// typed contract (this assertion). A regression that drifts the
/// rendering between two implementors (a future derive emitter that
/// changes the prefix, a hand-rolled carrier whose `#[error(...)]`
/// annotation omits the noun phrase) fails this assertion on the
/// affected implementor without needing 33+ per-implementor literal
/// tests to catch the drift independently.
/// 6. [`ClosedSet::labels`] equals the natural
/// `Self::ALL.iter().copied().map(label).collect()` projection — the
/// labels-list surface generic consumers (REPL exhaustive listers,
/// LSP completion bars, [`ClosedSet::suggest_closest`]'s
/// candidate-list) walk over. The default trait body satisfies the
/// clause for free; the assertion catches a future implementor
/// whose `labels()` override diverges from `ALL`'s natural
/// projection (a degenerate axis the trait surface exposes for the
/// same reason `via` / `set_label` exist — a typed escape hatch
/// rather than forcing the implementor to hand-roll the impl). A
/// drifted override fails this clause loudly rather than silently
/// bifurcating the candidate-list surface every
/// `suggest_closest` consumer routes through.
/// 7. [`ClosedSet::parse_label_with_hint`] composes [`ClosedSet::parse_label`]
/// and [`ClosedSet::suggest_closest`] verbatim — every variant in
/// `T::ALL` decodes to `Ok(v)` through the structured surface
/// (the hint slot is structurally absent on the Ok arm), and the
/// sweep's reserved probe input rejects with the SAME typed
/// carrier [`ClosedSet::parse_label`] would have emitted (same
/// [`core::fmt::Display`] rendering — the substrate-wide
/// `"unknown {SET_LABEL}: {input}"` shape) AND with a `None`
/// hint slot (the probe sits beyond [`ClosedSet::suggest_closest`]'s
/// bounded edit distance by construction — its 38-char body shares
/// no characters with any plausible canonical label). The default
/// trait body satisfies the clause for free; the assertion catches
/// a future implementor whose `parse_label_with_hint` override
/// drifts from the natural composition (a degenerate axis the
/// trait surface exposes for the same reason `via` / `set_label` /
/// `labels` overrides exist — a typed escape hatch rather than
/// forcing the implementor to hand-roll the impl). A drifted
/// override that emits the wrong carrier OR fabricates a hint for
/// the unrecognizable probe fails this clause loudly rather than
/// silently bifurcating the structured-diagnostic surface every
/// `parse_label_with_hint` consumer routes through.
/// 8. [`ClosedSet::labels_joined`] composes [`ClosedSet::labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// verbatim — the joined-candidate-list rendering every
/// diagnostic / metrics consumer routes through emits at ONE
/// trait body. The sweep walks three representative separators
/// (`"/"`, `", "`, `"|"`) so a drift in any one of the three
/// rendering surfaces (slash for the substrate's `INTENT_KIND_LIST`-
/// shaped production constants, comma-space for diagnostic
/// `expected one of: ...` shapes, pipe for grammar-style lists)
/// fails the testkit on every implementor. The default trait body
/// satisfies the clause for free; the assertion catches a future
/// implementor whose override returns a different join shape (a
/// different separator threading, a subset of labels) loudly
/// rather than silently bifurcating the candidate-list-as-string
/// rendering every consumer routes through.
/// 9. [`ClosedSet::sorted_labels`] composes [`ClosedSet::labels`] with
/// [`slice::sort_unstable`](https://doc.rust-lang.org/std/primitive.slice.html#method.sort_unstable)
/// verbatim — the canonical-ordered candidate-list rendering every
/// `_all_is_unique_and_complete` per-implementor test (the 7+
/// `let mut sorted: Vec<&str> = T::ALL.iter().map(<via>).collect();
/// sorted.sort_unstable();` inline triples across `QuoteForm`,
/// `AtomKind`, `KwargPathKind`, `ExpectedKwargShape`, `SexpShape`,
/// `UnquoteForm`, `MacroDefHead`, …) routes through emits at ONE
/// trait body. The default trait body satisfies the clause for free;
/// the assertion catches a future implementor whose override returns
/// a different sort shape (a subset of labels, a different ordering,
/// declaration order instead of lexicographic) loudly rather than
/// silently bifurcating the canonical-ordered candidate-list surface
/// every LSP / `tatara-check` / metrics consumer routes through.
/// 10. [`ClosedSet::sorted_labels_joined`] composes
/// [`ClosedSet::sorted_labels`] with
/// [`slice::join`](https://doc.rust-lang.org/std/primitive.slice.html#method.join)
/// verbatim — the alphabetized joined-candidate-list rendering
/// every diagnostic / metrics consumer that wants a
/// lexicographic-ordered `expected one of: ...` shape routes
/// through emits at ONE trait body. The sweep walks the same three
/// representative separators clause (8) uses (`"/"`, `", "`, `"|"`)
/// so a drift in any one of the three rendering surfaces (slash
/// for ordering-independent production constants, comma-space for
/// natural-language alphabetized `expected one of: ...` shapes,
/// pipe for grammar-style alphabetized alternative lists) fails
/// the testkit on every implementor. The default trait body
/// satisfies the clause for free; the assertion catches a future
/// implementor whose override returns a different sort-then-join
/// shape (a different separator threading, a subset of labels,
/// declaration order instead of lexicographic) loudly rather than
/// silently bifurcating the alphabetized-candidate-list-as-string
/// rendering every LSP / `tatara-check` / metrics consumer routes
/// through.
/// 11. [`ClosedSet::contains_label`] composes [`ClosedSet::ALL`] +
/// [`ClosedSet::label`] with [`Iterator::any`] verbatim — the
/// pure-membership predicate every zero-allocation lint / filter /
/// gate consumer routes through emits at ONE trait body without
/// ever materializing the [`ClosedSet::Unknown`] carrier
/// [`ClosedSet::parse_label`] threads on rejection. The sweep
/// walks every variant's canonical label (expected `true`), the
/// reserved 38-char probe (expected `false` — the same probe
/// clauses (5) + (7) reserve as lexically distinct from every
/// plausible canonical label), and the empty-string boundary
/// (expected `false` matching clause (4)) so a drift in any of
/// the three natural predicate arms (a permissive override that
/// accepts non-canonical strings, a strict override that rejects
/// a canonical label, a subset-projection override that names
/// fewer labels than `Self::ALL.iter().map(label)` covers) fails
/// the testkit on every implementor. The default trait body
/// satisfies the clause for free; the assertion catches a future
/// implementor whose override drifts the composition loudly
/// rather than silently bifurcating the pure-membership surface
/// every lint / filter / gate consumer routes through.
/// 12. [`ClosedSet::find_by_label`] composes [`ClosedSet::ALL`] +
/// [`ClosedSet::label`] with [`Iterator::find`] verbatim — the
/// zero-allocation typed decode every consumer that needs the
/// variant (but can supply a natural fallback) routes through
/// emits at ONE trait body without ever materializing the
/// [`ClosedSet::Unknown`] carrier [`ClosedSet::parse_label`]
/// threads on rejection. The sweep walks every variant's
/// canonical label (expected `Some(v)` — the acceptance arm
/// round-trips through the typed decode), the reserved 38-char
/// probe (expected `None` — the same probe clauses (5) + (7) +
/// (11) reserve as lexically distinct from every plausible
/// canonical label), and the empty-string boundary (expected
/// `None` matching clauses (4) + (11)) so a drift in any of the
/// three natural typed-decode arms (a permissive override that
/// accepts non-canonical strings, a strict override that
/// rejects a canonical label, a subset-projection override that
/// names fewer labels than `Self::ALL.iter().map(label)` covers)
/// fails the testkit on every implementor. The default trait
/// body satisfies the clause for free; the assertion catches a
/// future implementor whose override drifts the composition
/// loudly rather than silently bifurcating the zero-allocation
/// typed-decode surface every consumer routes through. Sibling
/// posture to clause (11) on the (bool, Option<Self>)
/// return-type axis — both walk the SAME (`Self::ALL`,
/// `Self::label`) primitive pair and MUST agree on the
/// underlying (accept, reject) partition; the pin verifies the
/// alignment across both arms of the axis.
/// 13. [`ClosedSet::find_by_label_with_hint`] composes
/// [`ClosedSet::find_by_label`] and [`ClosedSet::suggest_closest`]
/// verbatim — the zero-allocation structured-decode surface
/// every consumer that needs the typed variant AND (on miss) the
/// typed hint, without paying the [`ClosedSet::Unknown`] carrier
/// allocation [`ClosedSet::parse_label_with_hint`] threads on
/// rejection, routes through emits at ONE trait body. Every
/// variant in `T::ALL` decodes to `Ok(v)` through the structured
/// surface (the hint slot is structurally absent on the Ok arm),
/// and the sweep's reserved probe input rejects with `Err(None)`
/// — the probe sits beyond [`ClosedSet::suggest_closest`]'s
/// bounded edit distance by construction (its 38-char body
/// shares no characters with any plausible canonical label), so
/// the conservative-suggestion contract demands the absent hint
/// slot. The default trait body satisfies the clause for free;
/// the assertion catches a future implementor whose
/// `find_by_label_with_hint` override drifts from the natural
/// composition (a degenerate axis the trait surface exposes for
/// the same reason `via` / `set_label` / `labels` overrides
/// exist — a typed escape hatch rather than forcing the
/// implementor to hand-roll the impl). A drifted override that
/// accepts the probe as `Ok`, fabricates a hint for the
/// unrecognizable probe, OR emits the wrong typed decode on a
/// canonical variant fails this clause loudly rather than
/// silently bifurcating the zero-allocation structured-decode
/// surface every LSP / config-decoder / filter-map consumer
/// routes through. Sibling posture to clause (7) on the
/// (allocating carrier decode, non-allocating typed decode)
/// axis — both compose the SAME [`ClosedSet::suggest_closest`]
/// hint primitive next to the underlying typed-decode primitive
/// on their respective (allocating, non-allocating) columns of
/// the (side-effect × hint) 2×2 matrix; the pin verifies the
/// alignment across both arms of the axis.
/// 14. [`ClosedSet::CARDINALITY`] equals [`ClosedSet::ALL`]`.len()` — the
/// const-visible variant count matches the runtime slice length.
/// The default trait const initializer `Self::ALL.len()`
/// satisfies the clause for free; the assertion catches a future
/// implementor whose override drifts the count (a hand-rolled
/// const that reports a different cardinality than `Self::ALL`
/// actually carries) loudly rather than silently bifurcating the
/// const-generic surface every downstream `[Payload;
/// T::CARDINALITY]` array / bitset-width consumer routes through.
/// Sibling posture to clause (1) — clause (1) pins `T::ALL` non-
/// empty, this clause pins the const-visible count against the
/// slice length so a generic const-generic consumer that binds
/// `[Payload; T::CARDINALITY]` and iterates `T::ALL` in lockstep
/// stays sound at both the type-level dimension AND the runtime
/// iteration boundary.
/// 15. For every `i in 0..T::ALL.len()`,
/// `T::ALL[i].index_of()` equals `i` — the (typed variant →
/// `usize` array index) bijection with `0..T::CARDINALITY` holds
/// on every declaration-order position. The default trait body's
/// discriminant-keyed `Iterator::position` sweep satisfies the
/// clause for free; the assertion catches a future implementor
/// whose override drifts from the natural `ALL`-position
/// projection (a hand-rolled `match` that swaps two arms, a
/// constant that reports the same index for every variant, an
/// over-eager caching layer that returns a stale index after a
/// variant-listing edit) loudly rather than silently bifurcating
/// the (variant → array index) bijection every downstream
/// per-variant lookup-table `[Payload; T::CARDINALITY]` /
/// bitset / compact-encoding consumer routes through. Sibling
/// posture to clause (14) — clause (14) pins the const-visible
/// cardinality against `T::ALL`'s slice length, this clause pins
/// the per-variant position against `T::ALL`'s indexed access so
/// the closed set's (typed variant ↔ array-index position)
/// bijection stays sound at the compile-time dimension (clause
/// 14) AND the runtime per-variant projection (this clause).
/// 16. For every `i in 0..T::CARDINALITY`, `T::from_index(i)` equals
/// `Some(T::ALL[i])`, AND `T::from_index(T::CARDINALITY)` equals
/// [`None`] — the (`usize` array index → typed variant) inverse
/// projection agrees with direct [`ClosedSet::ALL`] slice indexing
/// on the in-range domain AND rejects the first out-of-range
/// index. Clauses (15) + (16) together pin the (typed variant ↔
/// `usize` array index) bijection at BOTH directions: clause (15)
/// covers the forward `variant.index_of() == i` projection, this
/// clause covers the inverse `T::from_index(i) == Some(v)`
/// projection AND the out-of-range guard. The default trait body's
/// `Self::ALL.get(i).copied()` composition satisfies the clause
/// for free; the assertion catches a future implementor whose
/// override drifts the bounded-decode arm (a permissive override
/// that returns `Some` for an out-of-range index, folding an
/// out-of-range serialized index onto an in-range variant; a
/// strict override that returns `None` for a valid in-range index,
/// silently dropping variants at the compact-decode boundary; a
/// swapped override that recovers the wrong variant for a valid
/// index, silently bifurcating the (variant ↔ index) round-trip)
/// loudly rather than silently bifurcating the inverse-decode
/// surface every downstream compact-encoding / bitset-observed-
/// variant / lookup-table-iteration consumer routes through.
/// Sibling posture to clause (12) on the (label decode, index
/// decode) axis of the closed-set inbound-projection surface —
/// both close the inbound-projection surface with an
/// [`Option`]-typed rejection arm, [`ClosedSet::find_by_label`]
/// for the `&str` carrier, [`ClosedSet::from_index`] for the
/// `usize` carrier; the pin verifies the alignment across both
/// carriers on the (in-range accept, out-of-range reject)
/// partition.
/// 17. [`ClosedSet::sorted_variants`] composes [`ClosedSet::ALL`] with
/// `Vec::from` + `slice::sort_unstable_by_key` keyed on
/// [`ClosedSet::label`] verbatim, AND stays element-wise aligned
/// with [`ClosedSet::sorted_labels`] on the (typed variant,
/// canonical label) axis of the closed-set candidate-listing
/// surface. For every `i in 0..T::CARDINALITY`,
/// `T::sorted_variants()[i].label()` equals
/// `T::sorted_labels()[i]`, AND the sorted-variant slice length
/// equals [`ClosedSet::CARDINALITY`]. The default trait body
/// satisfies the clause for free; the assertion catches a future
/// implementor whose override drifts the composition (a subset of
/// variants, a different ordering, a swapped variant, an
/// off-by-one length) loudly rather than silently bifurcating the
/// sorted-typed-variant candidate-list surface every LSP /
/// `tatara-check` / metrics consumer routes through. Sibling
/// posture to clauses (9) + (16) — clause (9) pins the
/// lexicographic `Vec<&'static str>` corner of the (return-type ×
/// ordering) 2×2 matrix, this clause pins the lexicographic
/// `Vec<Self>` corner AND the element-wise alignment across the
/// two lexicographic corners so a downstream consumer that walks
/// `zip(sorted_variants(), sorted_labels())` per-slot sees the
/// same (typed variant, canonical label) pair on both projections.
/// Clause (16) covered the `usize` inverse-projection alignment
/// with `T::ALL` slice indexing; this clause covers the label-
/// keyed inverse-ordering alignment with `T::sorted_labels`, so
/// the closed set's two structural projections (index-keyed and
/// label-keyed) both stay sound at the runtime element-wise
/// boundary.
/// 18. [`ClosedSet::first`] equals `T::ALL[0]` AND [`ClosedSet::last`]
/// equals `T::ALL[T::ALL.len() - 1]` — the declaration-order
/// endpoint anchors project the head and tail of the [`ClosedSet::ALL`]
/// slice onto the trait surface as bare typed variants (no
/// [`Option`] / [`Result`] indirection, because clause (1) pins
/// [`ClosedSet::ALL`] non-empty so both endpoints are guaranteed
/// to exist). The default trait bodies satisfy the clause for
/// free; the assertion catches a future implementor whose
/// override drifts from the natural slice-endpoint projections
/// (a permissive override that returns some interior variant, a
/// swapped override that returns [`ClosedSet::last`]'s tail for
/// [`ClosedSet::first`], a stale override that returns the wrong
/// endpoint after a variant-listing edit) loudly rather than
/// silently bifurcating the endpoint-anchor surface every
/// downstream defaulter / iterator-start / iterator-terminator
/// consumer routes through. Sibling posture to clauses (15) +
/// (16) — clauses (15) + (16) pin the (typed variant ↔ array
/// index) bijection with `0..T::CARDINALITY` on every interior
/// slot, this clause pins the (head, tail) endpoint anchors
/// against `T::ALL[0]` / `T::ALL[T::ALL.len() - 1]` so the
/// closed set's structural endpoints stay sound at the two
/// canonical anchor sites.
/// 20. For every `i in 0..T::CARDINALITY`, `T::label_at(i)` equals
/// `Some(T::ALL[i].label())`, AND `T::label_at(T::CARDINALITY)`
/// equals [`None`] — the direct (`usize` array index →
/// `&'static str` canonical label) projection agrees with the
/// natural [`ClosedSet::from_index`] + [`ClosedSet::label`]
/// composition on the in-range domain AND rejects the first
/// out-of-range index. Clauses (16) + (20) together pin the
/// `usize`-carrier decode axis of the (typed variant, `&'static
/// str` label, `usize` index) projection triangle at BOTH
/// return-projection columns: clause (16) covers the (index →
/// typed variant) return-projection, this clause covers the
/// (index → `&'static str` label) return-projection. The
/// default trait body's [`ClosedSet::from_index`] +
/// [`ClosedSet::label`] composition satisfies the clause for
/// free; the assertion catches a future implementor whose
/// override drifts the direct-label projection arm (a permissive
/// override that returns `Some(_)` for an out-of-range index,
/// folding an out-of-range serialized index onto an in-range
/// label — silently bifurcating the direct-label projection from
/// [`ClosedSet::from_index`]'s bounded-decode arm; a strict
/// override that returns [`None`] for a valid in-range index,
/// silently dropping labels at the compact-decode boundary; a
/// swapped override that recovers the wrong label for a valid
/// index, silently bifurcating the (variant, `&'static str`
/// label, `usize` index) projection triangle) loudly rather than
/// silently bifurcating the direct-label projection surface every
/// downstream compact-encoding / metrics-per-slot / bitset-
/// observed-slot / `tatara-check` per-slot diagnostic consumer
/// routes through. Sibling posture to clause (16) on the
/// (typed variant, `&'static str` label) return-projection axis
/// of the `usize`-carrier partition — clause (16) closes the
/// (index → typed variant) direct projection, this clause closes
/// the (index → `&'static str` label) direct projection, so the
/// `usize`-carrier partition of the projection triangle stays
/// sound at both return-projection columns AND on both the
/// in-range accept AND the out-of-range reject partitions.
/// 23. For every `i in 0..T::CARDINALITY`, `T::from_sorted_index(i)`
/// equals `Some(T::sorted_variants()[i])`, AND
/// `T::from_sorted_index(T::CARDINALITY)` equals [`None`] — the
/// (`usize` lex-order position → typed variant) inverse projection
/// agrees with direct [`ClosedSet::sorted_variants`] slice indexing
/// on the in-range domain AND rejects the first out-of-range
/// index. Clauses (22) + (23) together pin the (typed variant ↔
/// `usize` lex-order position) bijection at BOTH directions:
/// clause (22) covers the forward `variant.sorted_index_of() == i`
/// projection, this clause covers the inverse
/// `T::from_sorted_index(i) == Some(v)` projection AND the
/// out-of-range guard. The default trait body's
/// `Self::sorted_variants().get(i).copied()` composition satisfies
/// the clause for free; the assertion catches a future implementor
/// whose override drifts the bounded-decode arm (a permissive
/// override that returns `Some(_)` for an out-of-range index, a
/// strict override that returns [`None`] for a valid in-range lex
/// slot, a swapped override that recovers the wrong variant for a
/// valid lex slot) loudly rather than silently bifurcating the
/// lex-order inverse-decode surface every downstream lex-order
/// compact-encoding / lex-order-bitset-observed-variant / lex-
/// order-lookup-table-iteration consumer routes through. Sibling
/// posture to clauses (16) + (22) — clause (16) closes the
/// (declaration-order index → typed variant) inverse projection on
/// the (declaration, lex) partition of the (position → variant)
/// inverse-projection surface; this clause closes the (lex-order
/// index → typed variant) inverse projection so the (declaration,
/// lex) × (position → variant) 1×2 inverse-projection partition
/// completes at BOTH ordering axes.
/// 24. For every `i in 0..T::CARDINALITY`, `T::sorted_label_at(i)`
/// equals `Some(T::sorted_labels()[i])`, AND
/// `T::sorted_label_at(T::CARDINALITY)` equals [`None`] — the
/// direct (`usize` lex-order position → `&'static str` canonical
/// label) projection agrees with the natural
/// [`ClosedSet::from_sorted_index`] + [`ClosedSet::label`]
/// composition on the in-range domain (equivalently, with direct
/// [`ClosedSet::sorted_labels`] slice indexing under lex ordering)
/// AND rejects the first out-of-range lex slot. Clauses (20) + (24)
/// together pin the (`usize` position → `&'static str` label)
/// forward projection at BOTH ordering axes: clause (20) covers the
/// declaration-ordering direct-label projection, this clause covers
/// the lex-ordering direct-label projection. The default trait
/// body's [`ClosedSet::from_sorted_index`] + [`ClosedSet::label`]
/// composition satisfies the clause for free; the assertion catches
/// a future implementor whose override drifts the direct-label
/// projection arm (a permissive override that returns `Some(_)` for
/// an out-of-range lex slot, folding an out-of-range serialized
/// lex index onto an in-range label at the lex-order compact-decode
/// boundary; a strict override that returns [`None`] for a valid
/// in-range lex slot, silently dropping labels at the lex-order
/// rendering boundary; a swapped override that recovers the wrong
/// label for a valid lex slot, silently bifurcating the lex-axis
/// projection triangle) loudly rather than silently bifurcating
/// the direct-label projection surface every downstream lex-order
/// compact-encoding / lex-sorted-metrics-binner / bitset-observed-
/// slot-lex-renderer / `tatara-check` per-lex-slot diagnostic
/// consumer routes through. Sibling posture to clauses (20) + (23)
/// — clause (20) closes the (declaration-order index → `&'static
/// str` label) direct projection, clause (23) closes the (lex-order
/// index → typed variant) inverse projection, this clause closes
/// the (lex-order index → `&'static str` label) direct projection
/// so the lex-axis projection triangle stays sound at BOTH
/// return-projection columns AND on both the in-range accept AND
/// the out-of-range reject partitions.
/// 25. For every variant `v` in `T::ALL`, `T::sorted_index_of_label(
/// v.label())` equals `Some(v.sorted_index_of())`, AND
/// `T::sorted_index_of_label(<reserved probe>)` equals [`None`], AND
/// `T::sorted_index_of_label("")` equals [`None`] — the direct
/// (`&'static str` label → `usize` lex-order position) projection
/// agrees with the natural [`ClosedSet::find_by_label`] +
/// [`ClosedSet::sorted_index_of`] composition on the in-range
/// canonical domain AND rejects both the reserved out-of-set probe
/// AND the empty-string boundary that clause (4) reserves as
/// structurally outside every closed set. Clauses (21) + (25)
/// together pin the (`&str` label → `usize` position) forward
/// projection at BOTH ordering axes: clause (21) covers the
/// declaration-ordering direct-index projection, this clause covers
/// the lex-ordering direct-index projection — so the (`&str` label
/// → `usize` position) forward-projection partition stays sound at
/// BOTH ordering axes. The default trait body's
/// [`ClosedSet::find_by_label`] + [`ClosedSet::sorted_index_of`]
/// composition satisfies the clause for free; the assertion catches
/// a future implementor whose override drifts the direct-lex-slot
/// projection arm (a permissive override that returns `Some(_)` for
/// a non-canonical `&str` — folding an off-set string onto an
/// in-range lex slot at the direct-projection column while
/// `find_by_label` still rejects it, silently bifurcating the
/// `&str`-carrier decode axis on the lex-order projection column;
/// a strict override that returns [`None`] for a canonical variant's
/// label, silently dropping lex slots at the label-decode boundary;
/// a swapped override that recovers the wrong lex slot for a valid
/// canonical label, silently bifurcating the (typed variant,
/// `&'static str` label, `usize` position) lex-axis projection
/// triangle at its fourth direct edge) loudly rather than silently
/// bifurcating the direct-lex-slot projection surface every
/// downstream lex-sorted-metrics-binner / lex-order-compact-encoder
/// / `tatara-check` per-lex-slot per-label diagnostic / LSP-hover
/// consumer routes through. Sibling posture to clauses (12) + (22)
/// — clause (12) closes the (`&str` → typed variant) `Option`-typed
/// direct projection, clause (22) closes the (typed variant →
/// `usize` lex position) forward projection, this clause closes
/// the (`&str` → `usize` lex position) direct projection composed
/// from BOTH primitives AND pins the alignment with the natural
/// two-step composition on every implementor. Together clauses
/// (12) + (22) + (25) close the `&str`-carrier partition of the
/// lex-axis projection triangle at both the immediate (variant)
/// decode column AND the further (lex position) decode column,
/// mirroring the way clauses (12) + (15) + (21) close the same
/// `&str`-carrier partition on the declaration axis. With clauses
/// (20) + (21) + (22) + (23) + (24) + (25) all in place, the
/// (typed variant, `&'static str` label, `usize` position)
/// projection triangle stays direct-projection closed at EVERY
/// (input, output) pair on BOTH ordering axes.
/// 26. For every variant `v` in `T::ALL`, `v.next()` equals
/// `T::from_index(v.index_of() + 1)`, AND `v.prev()` equals
/// `T::from_index(v.index_of() - 1)` when `v.index_of() > 0`,
/// AND `T::first().prev()` equals [`None`], AND `T::last().next()`
/// equals [`None`] — the declaration-order (variant → forward
/// neighbor, variant → backward neighbor) direction pair agrees
/// with the natural [`ClosedSet::index_of`] +
/// [`ClosedSet::from_index`] composition on every interior slot
/// AND rejects both endpoint boundaries. The default trait
/// bodies (`from_index(index_of(self) + 1)` for the forward arm,
/// `from_index(index_of(self) - 1)` guarded on
/// `index_of(self) > 0` for the backward arm) satisfy both arms
/// for free; the assertion catches a future implementor whose
/// override drifts either neighbor arm (a permissive forward
/// override that returns `Some(_)` at the tail — folding a
/// tail-boundary walk onto a wraparound to the head at the
/// forward-projection column while the composed `+ 1` arithmetic
/// would return [`None`] through `from_index`'s `<[T]>::get`;
/// a permissive backward override that returns `Some(_)` at the
/// head — folding a head-boundary walk onto a wraparound to the
/// tail through the `usize` underflow the guard prevents; a
/// swapped override that returns the predecessor for
/// [`Self::next`] AND the successor for [`Self::prev`], silently
/// inverting the traversal direction every downstream state-
/// machine iterator / phase-fold reducer / LSP wraparound-cursor
/// consumer walks over; a stale override that returns the wrong
/// neighbor after a variant-listing edit) loudly rather than
/// silently bifurcating the neighbor-projection surface every
/// downstream state-machine iterator / saga-step engine /
/// truth-table property test / phase-fold reducer consumer
/// routes through. Sibling posture to clauses (15) + (16) + (18)
/// — clauses (15) + (16) pin the (typed variant ↔ `usize` array
/// index) bijection at BOTH directions, clause (18) pins the
/// (head, tail) endpoint anchors against `T::ALL[0]` /
/// `T::ALL[T::ALL.len() - 1]`, this clause pins the (forward,
/// backward) neighbor projections against the composition of
/// both bijection arms AND pins the endpoint-boundary [`None`]
/// guards on both direction arms — so the closed-set traversal
/// surface stays sound at BOTH direction arms AND on the shared
/// endpoint-anchor fixpoints (`T::last().next() == None`,
/// `T::first().prev() == None`) that thread the neighbor axis
/// back through the endpoint-anchor axis.
///
/// Per-implementor domain-specific tests STAY in the implementor's
/// test module — the `gates_phase` truth tables, the
/// `can_transition_to` state-machine contracts, the serde wire-format
/// coherence sweeps, the signal-shaped `short_str` dual-projection
/// matches — those project per-variant content the trait's structural
/// contract can't see. This helper lifts ONLY the structural four (+1)
/// every implementor copies.
///
/// Marked `#[track_caller]` so a failure points at the per-implementor
/// test's call site rather than at this helper, giving the operator a
/// stable signal about which closed-set implementor regressed.
///
/// Usage from any per-implementor test module in any crate that
/// depends on `tatara-lisp` (this crate, `tatara-process`,
/// `tatara-domains`, future closed-set implementors):
///
/// ```text
/// #[test]
/// fn process_phase_is_well_formed_closed_set() {
/// tatara_lisp::closed_set::assert_closed_set_well_formed::<ProcessPhase>();
/// }
/// ```
///
/// THEORY.md §V.1 — knowable platform; the three structural test
/// invariants were known patterns carried by convention across 36+
/// per-implementor test modules. This helper makes them a TYPED
/// CONSEQUENCE of the [`ClosedSet`] contract — any future implementor
/// that calls this helper inherits the contract without re-deriving
/// the three assertions.
#[track_caller]
pub fn assert_closed_set_well_formed<T>()
where
T: ClosedSet + PartialEq + core::fmt::Debug,
T::Unknown: core::fmt::Display,
{
let type_name = core::any::type_name::<T>();
assert!(
!T::ALL.is_empty(),
"{type_name}: T::ALL is empty — a closed-set with zero variants is degenerate",
);
for &v in T::ALL {
let label = v.label();
match T::parse_label(label) {
Ok(decoded) => assert_eq!(
decoded, v,
"{type_name}: round-trip {label:?} → variant decoded to a different variant",
),
Err(_) => {
panic!("{type_name}: round-trip {label:?} → variant rejected by parse_label",)
}
}
}
let mut labels: Vec<&'static str> = T::ALL
.iter()
.copied()
.map(<T as ClosedSet>::label)
.collect();
let total = labels.len();
labels.sort_unstable();
labels.dedup();
assert_eq!(
labels.len(),
total,
"{type_name}: duplicate labels in T::ALL — the parse_label sweep would fold two variants into one",
);
assert!(
T::parse_label("").is_err(),
"{type_name}: empty string is a valid label — a closed-set whose codomain includes \"\" is degenerate",
);
// (5) — SET_LABEL non-empty + carrier renders the substrate-wide
// `"unknown {SET_LABEL}: {input}"` shape verbatim. The probe
// input `"__assert_closed_set_well_formed_probe__"` is chosen
// to be lexically distinct from every conceivable canonical
// variant label across the substrate (PascalCase wire form,
// kebab-case keyword form, punctuation marker form) so the
// sweep `T::parse_label` walks rejects unambiguously and lands
// in the `make_unknown` carrier — the rendering this assertion
// pins is the carrier's `Display`, not a `parse_label` Ok-arm.
assert!(
!T::SET_LABEL.is_empty(),
"{type_name}: T::SET_LABEL is empty — the substrate-wide diagnostic shape needs a noun phrase to render `unknown <set>: <input>`",
);
let probe = "__assert_closed_set_well_formed_probe__";
let rendered = T::make_unknown(probe).to_string();
let expected = {
let mut out = String::with_capacity("unknown : ".len() + T::SET_LABEL.len() + probe.len());
out.push_str("unknown ");
out.push_str(T::SET_LABEL);
out.push_str(": ");
out.push_str(probe);
out
};
assert_eq!(
rendered, expected,
"{type_name}: parse-rejection carrier's Display drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the derive's `#[error(...)]` annotation and the trait's SET_LABEL const must thread the SAME noun phrase",
);
// (6) — `T::labels()` matches `T::ALL.iter().copied().map(label).collect()`.
// The default trait body satisfies the clause for free; the
// assertion catches a future implementor whose override drifts
// from the natural `ALL`-projection surface every
// `suggest_closest` consumer walks over. Length AND
// index-by-index match — neither alone catches "different labels,
// same length" drift nor "right labels, wrong order" drift.
let labels = T::labels();
let natural: Vec<&'static str> = T::ALL
.iter()
.copied()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
labels, natural,
"{type_name}: T::labels() drifted from T::ALL.iter().copied().map(label).collect() — the labels-list surface every `suggest_closest` consumer walks over no longer matches the natural ALL-projection",
);
// (7) — `T::parse_label_with_hint` composes `parse_label` +
// `suggest_closest` verbatim. Every variant decodes to `Ok(v)`
// through the structured surface; the probe rejects with the
// SAME carrier shape `parse_label` emits AND with a `None` hint
// slot (the 38-char probe sits beyond `suggest_closest`'s
// bounded edit distance by construction — no plausible canonical
// label shares enough characters with the reserved probe to fall
// inside the bound-3 window). The default trait body satisfies
// the clause for free; the assertion catches an override that
// drifts the composition.
for &v in T::ALL {
let label = v.label();
match T::parse_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v,
"{type_name}: parse_label_with_hint round-trip {label:?} → variant decoded to a different variant",
),
Err(_) => panic!(
"{type_name}: parse_label_with_hint round-trip {label:?} → variant rejected by parse_label_with_hint",
),
}
}
match T::parse_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: parse_label_with_hint accepted the reserved probe input — the structured surface MUST reject every input outside the closed set",
),
Err((carrier, hint)) => {
assert_eq!(
carrier.to_string(),
expected,
"{type_name}: parse_label_with_hint's Err carrier drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the override emits a different carrier than `parse_label` would",
);
assert!(
hint.is_none(),
"{type_name}: parse_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
);
}
}
// (8) — `T::labels_joined(sep)` composes `T::labels()` with
// `slice::join` verbatim. The default trait body satisfies the
// clause for free; the assertion catches a future implementor
// whose override drifts from the natural
// `labels().join(sep)` shape (a degenerate axis the trait
// surface exposes for the same reason `via` / `set_label` /
// `labels` / `suggest_closest` / `parse_label_with_hint`
// overrides exist — a typed escape hatch rather than forcing
// the implementor to hand-roll the impl). Sweep three
// representative separators (the slash, comma-space, and pipe
// shapes the substrate's existing production sites lean on)
// so a drift in any one of the three rendering surfaces
// (slash for `INTENT_KIND_LIST`-shaped lists, comma-space for
// diagnostic `expected one of: ...` shapes, pipe for ergonomic
// grammar-style lists) fails the testkit on every implementor.
for sep in ["/", ", ", "|"] {
let lifted = T::labels_joined(sep);
let natural = T::labels().join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::labels_joined({sep:?}) drifted from T::labels().join({sep:?}) — the joined-candidate-list rendering every diagnostic / metrics consumer routes through no longer matches the natural labels-projection",
);
}
// (9) — `T::sorted_labels()` composes `T::labels()` with
// `slice::sort_unstable` verbatim. The default trait body satisfies
// the clause for free; the assertion catches a future implementor
// whose override drifts from the natural `labels().sort_unstable()`
// shape (a different ordering, a subset of labels, declaration order
// instead of lexicographic) loudly rather than silently bifurcating
// the canonical-ordered candidate-list surface every LSP /
// `tatara-check` / metrics consumer routes through.
let lifted_sorted = T::sorted_labels();
let natural_sorted = {
let mut v = T::labels();
v.sort_unstable();
v
};
assert_eq!(
lifted_sorted, natural_sorted,
"{type_name}: T::sorted_labels() drifted from `let mut v = T::labels(); v.sort_unstable(); v` — the canonical-ordered candidate-list surface every LSP / `tatara-check` / metrics consumer routes through no longer matches the natural labels-then-sort projection",
);
// (10) — `T::sorted_labels_joined(sep)` composes
// `T::sorted_labels()` with `slice::join` verbatim. The default
// trait body satisfies the clause for free; the assertion catches
// a future implementor whose override returns a different shape
// (a subset of labels, a different ordering, declaration order
// instead of lexicographic, a wrong separator threading) loudly
// rather than silently bifurcating the alphabetized-
// candidate-list-as-string surface every LSP / `tatara-check` /
// metrics consumer routes through. Sweep the same three
// representative separators clause (8) uses (`"/"`, `", "`, `"|"`)
// so an isolated drift on any of the three natural rendering
// surfaces (slash for ordering-independent production constants,
// comma-space for natural-language alphabetized `expected one of:
// ...` shapes, pipe for grammar-style alphabetized alternative
// lists) fails the testkit on every implementor.
for sep in ["/", ", ", "|"] {
let lifted = T::sorted_labels_joined(sep);
let natural = T::sorted_labels().join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::sorted_labels_joined({sep:?}) drifted from T::sorted_labels().join({sep:?}) — the alphabetized joined-candidate-list rendering every diagnostic / metrics consumer routes through no longer matches the natural sorted-labels-then-join projection",
);
}
// (11) — `T::contains_label(s)` MUST agree with
// `T::parse_label(s).is_ok()` on every representative input:
// every canonical label matches (`true`), the reserved probe
// rejects (`false`), and the empty-string boundary rejects
// (`false`) matching clause (4). The default trait body
// satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a
// permissive override that returns `true` for inputs outside
// the closed set, a strict override that returns `false` for a
// canonical label, a subset-projection override that names
// fewer labels than `Self::ALL.iter().map(label)` covers) loudly
// rather than silently bifurcating the pure-membership surface
// every lint / filter / gate consumer routes through.
for &v in T::ALL {
let label = v.label();
assert!(
T::contains_label(label),
"{type_name}: T::contains_label({label:?}) returned false for a canonical variant label — the pure-membership predicate drifted from the natural `ALL`-projection",
);
}
assert!(
!T::contains_label(probe),
"{type_name}: T::contains_label(<reserved probe>) returned true for an input outside the closed set — the pure-membership predicate accepted a non-canonical string",
);
assert!(
!T::contains_label(""),
"{type_name}: T::contains_label(\"\") returned true — the pure-membership predicate accepted the empty-string boundary that clause (4) reserves as structurally outside every closed set",
);
// (12) — `T::find_by_label(s)` MUST agree with
// `T::parse_label(s).ok()` on every representative input: every
// canonical label decodes to `Some(v)` (the acceptance arm
// round-trips through the typed decode), the reserved probe
// rejects to `None` (the same probe clauses (5) + (7) + (11)
// reserve as lexically distinct from every plausible canonical
// label), and the empty-string boundary rejects to `None`
// matching clauses (4) + (11). The default trait body satisfies
// the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a
// permissive override that returns `Some(_)` for inputs outside
// the closed set, a strict override that returns `None` for a
// canonical label, a subset-projection override that names fewer
// labels than `Self::ALL.iter().map(label)` covers) loudly
// rather than silently bifurcating the zero-allocation
// typed-decode surface every LSP / config-decoder / filter-map
// consumer routes through. Sibling posture to clause (11) on the
// (bool, Option<Self>) return-type axis — both walk the SAME
// (Self::ALL, Self::label) primitive pair and MUST agree on the
// underlying (accept, reject) partition; the pin verifies the
// alignment across both arms of the axis.
for &v in T::ALL {
let label = v.label();
match T::find_by_label(label) {
Some(decoded) => assert_eq!(
decoded, v,
"{type_name}: T::find_by_label({label:?}) decoded to a different variant — the zero-allocation typed decode drifted from the natural `ALL`-projection",
),
None => panic!(
"{type_name}: T::find_by_label({label:?}) returned None for a canonical variant label — the zero-allocation typed decode drifted from the natural `ALL`-projection",
),
}
}
assert!(
T::find_by_label(probe).is_none(),
"{type_name}: T::find_by_label(<reserved probe>) returned Some(_) for an input outside the closed set — the zero-allocation typed decode accepted a non-canonical string",
);
assert!(
T::find_by_label("").is_none(),
"{type_name}: T::find_by_label(\"\") returned Some(_) — the zero-allocation typed decode accepted the empty-string boundary that clause (4) reserves as structurally outside every closed set",
);
// (13) — `T::find_by_label_with_hint` composes `find_by_label` +
// `suggest_closest` verbatim. Every variant decodes to `Ok(v)`
// through the structured surface; the probe rejects with
// `Err(None)` — the same 38-char probe clause (7) reserves as
// beyond `suggest_closest`'s bounded edit distance by
// construction. The default trait body satisfies the clause for
// free; the assertion catches an override that drifts the
// composition (accepts the probe as Ok, fabricates a hint for
// the unrecognizable probe, OR emits the wrong typed decode on
// a canonical variant). Sibling posture to clause (7) on the
// (allocating carrier decode, non-allocating typed decode) axis
// of the closed-set surface — both compose the SAME
// `suggest_closest` hint primitive next to the underlying
// typed-decode primitive on their respective columns of the
// (side-effect × hint) 2×2 matrix.
for &v in T::ALL {
let label = v.label();
match T::find_by_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v,
"{type_name}: find_by_label_with_hint round-trip {label:?} → variant decoded to a different variant",
),
Err(_) => panic!(
"{type_name}: find_by_label_with_hint round-trip {label:?} → variant rejected by find_by_label_with_hint",
),
}
}
match T::find_by_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: find_by_label_with_hint accepted the reserved probe input — the structured zero-allocation surface MUST reject every input outside the closed set",
),
Err(hint) => {
assert!(
hint.is_none(),
"{type_name}: find_by_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
);
}
}
// (14) — `T::CARDINALITY` MUST equal `T::ALL.len()`. The default
// trait const initializer `Self::ALL.len()` satisfies the clause
// for free; the assertion catches a future implementor whose
// override drifts from the natural `ALL`-length projection (a
// degenerate axis the trait surface exposes for the same reason
// `via` / `set_label` / `labels` overrides exist — a typed escape
// hatch rather than forcing the implementor to hand-roll the
// impl). A drifted override that reports a different count than
// `Self::ALL` actually carries silently bifurcates every
// downstream const-generic consumer's `[T; T::CARDINALITY]`
// array from `Self::ALL`'s runtime iteration; pinning the
// equality here catches the drift on every implementor before
// any consumer sizes a const array against the drifted count.
// Sibling posture to clause (1) — clause (1) pins `T::ALL` non-
// empty, this clause pins the const-visible count against the
// slice length so a generic const-generic consumer that takes
// `T::CARDINALITY - 1` as a top-rank index stays sound.
assert_eq!(
T::CARDINALITY,
T::ALL.len(),
"{type_name}: T::CARDINALITY drifted from T::ALL.len() — the const-visible cardinality no longer matches the runtime variant count. A generic const-generic consumer that binds `[Payload; T::CARDINALITY]` against `T::ALL`-length iteration would silently size the wrong dimension",
);
// (15) — For every `i in 0..T::ALL.len()`, `T::ALL[i].index_of()`
// MUST equal `i`. The default trait body's discriminant-keyed
// `Iterator::position` sweep satisfies the clause for free; the
// assertion catches a future implementor whose override drifts
// from the natural `ALL`-position projection (a hand-rolled
// `match` that swaps two arms, a constant that reports the same
// index for every variant, an over-eager caching layer that
// returns a stale index after a variant-listing edit). A drifted
// override silently bifurcates the (variant → array index)
// bijection with `0..T::CARDINALITY` — a downstream per-variant
// lookup-table `[Payload; T::CARDINALITY]` consumer keyed by
// `variant.index_of()` would land on the wrong slot; pinning the
// equality here catches the drift on every implementor before any
// consumer keys a per-variant payload against the drifted
// position. Sibling posture to clause (14) — clause (14) pins the
// const-visible cardinality against `T::ALL`'s slice length, this
// clause pins the per-variant position against `T::ALL`'s indexed
// access so the closed set's (typed variant ↔ array-index
// position) bijection stays sound at the compile-time dimension
// (clause 14) AND the runtime per-variant projection (this
// clause).
for (i, &v) in T::ALL.iter().enumerate() {
assert_eq!(
v.index_of(),
i,
"{type_name}: T::ALL[{i}].index_of() drifted from its declaration-order position — the (variant → array index) bijection with 0..T::CARDINALITY broke on this variant, so a per-variant lookup-table `[Payload; T::CARDINALITY]` consumer keyed by `variant.index_of()` would land on the wrong slot",
);
}
// (16) — For every `i in 0..T::CARDINALITY`, `T::from_index(i)`
// MUST equal `Some(T::ALL[i])`, AND `T::from_index(T::CARDINALITY)`
// MUST return `None`. The default trait body's
// `Self::ALL.get(i).copied()` composition satisfies the clause for
// free; the assertion catches a future implementor whose override
// drifts the bounded-decode arm (a permissive override that
// returns `Some` for an out-of-range index, folding an out-of-
// range serialized index onto an in-range variant; a strict
// override that returns `None` for a valid in-range index,
// silently dropping variants at the compact-decode boundary; a
// swapped override that recovers the wrong variant for a valid
// index, silently bifurcating the (variant ↔ index) round-trip).
// Sibling posture to clause (15) — clause (15) pins the forward
// `variant.index_of() == i` projection on every declaration-order
// position, this clause pins the inverse `T::from_index(i) ==
// Some(v)` projection AND the out-of-range `T::from_index(N) ==
// None` guard so the (typed variant ↔ `usize` array index)
// bijection stays sound at BOTH directions on every implementor.
for (i, &v) in T::ALL.iter().enumerate() {
let recovered = T::from_index(i);
assert_eq!(
recovered,
Some(v),
"{type_name}: T::from_index({i}) drifted from Some(T::ALL[{i}]) — the (array index → typed variant) inverse projection broke on this slot, so a downstream compact-encoding consumer that stores `variant.index_of() as u8` and later recovers the variant through `T::from_index(byte as usize)` would land on the wrong variant",
);
}
assert!(
T::from_index(T::CARDINALITY).is_none(),
"{type_name}: T::from_index(T::CARDINALITY) returned Some — the out-of-range guard drifted, so a per-variant lookup-table `[Payload; T::CARDINALITY]` consumer that decodes an out-of-range serialized index would silently fold onto an in-range variant rather than surfacing the corruption at the decode boundary",
);
// (17) — `T::sorted_variants()` MUST compose `T::ALL` +
// `Vec::from` + `slice::sort_unstable_by_key` keyed on `label`
// verbatim, AND stay element-wise aligned with
// `T::sorted_labels()` on the (typed variant, canonical label)
// axis. Sweep both the length equality (against `T::CARDINALITY`)
// AND the per-slot alignment (`sorted_variants()[i].label() ==
// sorted_labels()[i]` for every `i in 0..T::CARDINALITY`). The
// default trait body's `to_vec().sort_unstable_by_key(|v| v.label())`
// composition satisfies the clause for free; the assertion catches
// a future implementor whose override drifts the composition (a
// subset of variants, a swapped variant, a different ordering, an
// off-by-one length) loudly rather than silently bifurcating the
// sorted-typed-variant candidate-list surface every LSP /
// `tatara-check` / metrics consumer routes through. Sibling
// posture to clause (9) — clause (9) pins the lexicographic
// `Vec<&'static str>` corner of the (return-type × ordering) 2×2
// matrix, this clause pins the lexicographic `Vec<Self>` corner
// AND the element-wise alignment across the two lexicographic
// corners so a downstream consumer that walks `zip(sorted_variants(),
// sorted_labels())` per-slot sees the same (typed variant,
// canonical label) pair on both projections.
let sorted_variants = T::sorted_variants();
assert_eq!(
sorted_variants.len(),
T::CARDINALITY,
"{type_name}: T::sorted_variants().len() drifted from T::CARDINALITY — the sorted-typed-variant candidate-list surface lost or gained a variant, so a downstream consumer that walks `zip(sorted_variants(), sorted_labels())` per-slot would run off the end or short-cut before covering every variant",
);
let sorted_variant_labels: Vec<&'static str> = sorted_variants
.iter()
.copied()
.map(<T as ClosedSet>::label)
.collect();
let sorted_labels_reference = T::sorted_labels();
assert_eq!(
sorted_variant_labels, sorted_labels_reference,
"{type_name}: T::sorted_variants() projected element-wise through label() drifted from T::sorted_labels() — the (typed variant, canonical label) alignment on the lexicographic-ordering axis broke, so a downstream consumer that walks `zip(sorted_variants(), sorted_labels())` would see two different renderings on the same slot",
);
// (18) — `T::first()` equals `T::ALL[0]` AND `T::last()` equals
// `T::ALL[T::ALL.len() - 1]`. The default trait bodies satisfy
// the clause for free; the assertion catches a future implementor
// whose override drifts from the natural slice-endpoint
// projections (a permissive override that returns some interior
// variant, a swapped override that returns the tail for
// `first()`, a stale override that returns the wrong endpoint
// after a variant-listing edit) loudly rather than silently
// bifurcating the endpoint-anchor surface every downstream
// defaulter / iterator-start / iterator-terminator consumer
// routes through. Sibling posture to clauses (15) + (16) —
// clauses (15) + (16) pin the (typed variant ↔ array index)
// bijection with `0..T::CARDINALITY` on every interior slot,
// this clause pins the (head, tail) endpoint anchors against
// `T::ALL[0]` / `T::ALL[T::ALL.len() - 1]` so the closed set's
// structural endpoints stay sound at the two canonical anchor
// sites. The non-empty contract clause (1) guarantees both
// endpoints exist; the subtraction `T::ALL.len() - 1` never
// underflows.
assert_eq!(
T::first(),
T::ALL[0],
"{type_name}: T::first() drifted from T::ALL[0] — the declaration-order head endpoint anchor no longer matches the natural slice-index-0 projection, so a downstream defaulter / iterator-start consumer that binds `T::first()` as its canonical anchor would land on the wrong variant",
);
assert_eq!(
T::last(),
T::ALL[T::ALL.len() - 1],
"{type_name}: T::last() drifted from T::ALL[T::ALL.len() - 1] — the declaration-order tail endpoint anchor no longer matches the natural slice-index-(N - 1) projection, so a downstream iterator-terminator / bounded-loop consumer that binds `T::last()` as its canonical anchor would land on the wrong variant",
);
// (19) — `T::sorted_first()` equals `T::sorted_variants()[0]` AND
// `T::sorted_last()` equals
// `T::sorted_variants()[T::sorted_variants().len() - 1]`. The
// default trait bodies satisfy the clause for free (both compose
// `T::ALL` + `T::label` via a zero-alloc linear scan whose result
// agrees with the sorted-listing endpoints by strict-`<` /
// strict-`>` uniqueness under the label-pairwise-distinctness
// contract clause (3)); the assertion catches a future implementor
// whose override drifts from the natural lex-endpoint projections
// (a permissive override that returns some interior variant, a
// swapped override that returns the lex-max for `sorted_first()`, a
// stale override that returns the wrong endpoint after a label
// edit) loudly rather than silently bifurcating the lex-endpoint
// anchor surface every downstream defaulter / diagnostic-boundary
// / property-test consumer routes through. Sibling posture to
// clauses (17) + (18) — clause (17) pins the sorted-typed-variant
// listing element-wise against the sorted-labels projection under
// the lex ordering, clause (18) pins the declaration-order (head,
// tail) endpoint anchors against `T::ALL[0]` / `T::ALL[T::ALL.len()
// - 1]`, this clause pins the lex-order (head, tail) endpoint
// anchors against `T::sorted_variants()[0]` /
// `T::sorted_variants()[T::sorted_variants().len() - 1]` so the
// (declaration × lexicographic) × (head, tail) endpoint-anchor 2×2
// matrix stays fully-pinned. The non-empty contract clause (1) +
// clause (17)'s length equality guarantee `sorted_variants` is
// non-empty; the subtraction `sorted_variants.len() - 1` never
// underflows. Reuses the `sorted_variants` Vec clause (17) already
// materialized so this clause pays no additional allocation.
assert_eq!(
T::sorted_first(),
sorted_variants[0],
"{type_name}: T::sorted_first() drifted from T::sorted_variants()[0] — the lexicographic-order head endpoint anchor no longer matches the natural label-keyed lex-min projection, so a downstream diagnostic-boundary / lex-defaulter consumer that binds `T::sorted_first()` as its canonical anchor would land on the wrong variant",
);
assert_eq!(
T::sorted_last(),
sorted_variants[sorted_variants.len() - 1],
"{type_name}: T::sorted_last() drifted from T::sorted_variants()[T::sorted_variants().len() - 1] — the lexicographic-order tail endpoint anchor no longer matches the natural label-keyed lex-max projection, so a downstream diagnostic-boundary / bounded-loop-lex consumer that binds `T::sorted_last()` as its canonical anchor would land on the wrong variant",
);
// (20) — For every `i in 0..T::CARDINALITY`, `T::label_at(i)`
// MUST equal `Some(T::ALL[i].label())`, AND
// `T::label_at(T::CARDINALITY)` MUST equal `None`. The default
// trait body composes `T::from_index(i).map(T::label)` verbatim
// and satisfies both arms for free; the assertion catches a
// future implementor whose override drifts the direct-label
// projection arm (a permissive override that returns `Some(_)`
// for an out-of-range index — folding an out-of-range serialized
// index onto an in-range label at the direct-projection column
// while `from_index` still rejects it, silently bifurcating the
// `usize`-carrier decode axis; a strict override that returns
// `None` for a valid in-range index, silently dropping labels at
// the compact-decode boundary; a swapped override that recovers
// the wrong label for a valid index, silently bifurcating the
// (variant, `&'static str` label, `usize` index) projection
// triangle at its fourth direct edge) loudly rather than silently
// bifurcating the direct-label projection surface every downstream
// compact-encoding / metrics-per-slot / bitset-observed-slot /
// `tatara-check` per-slot diagnostic consumer routes through.
// Sibling posture to clause (16) on the (typed variant, `&'static
// str` label) return-projection axis of the `usize`-carrier
// partition — clause (16) closes the (index → typed variant)
// direct projection AND the out-of-range guard, this clause
// closes the (index → `&'static str` label) direct projection AND
// the SAME out-of-range guard on the second return-projection
// column so the `usize`-carrier partition of the projection
// triangle stays sound at both return-projection columns AND on
// both the in-range accept AND the out-of-range reject partitions.
for (i, &v) in T::ALL.iter().enumerate() {
assert_eq!(
T::label_at(i),
Some(v.label()),
"{type_name}: T::label_at({i}) drifted from Some(T::ALL[{i}].label()) — the direct (usize → &'static str label) projection no longer agrees with the natural from_index+label composition on the in-range accept arm, so a downstream compact-encoding / metrics-per-slot / bitset-observed-slot / tatara-check per-slot diagnostic consumer that binds `T::label_at(i)` as its direct-projection surface would render the wrong canonical label at index {i}",
);
}
assert_eq!(
T::label_at(T::CARDINALITY),
None,
"{type_name}: T::label_at(T::CARDINALITY) drifted from None — the direct (usize → &'static str label) projection accepted the first out-of-range index (T::CARDINALITY), so an out-of-range serialized index would fold onto an in-range canonical label on the direct-projection column while `from_index` still rejects it, silently bifurcating the usize-carrier decode axis of the projection triangle",
);
// (21) — For every variant `v` in `T::ALL`, `T::index_of_label(
// v.label())` MUST equal `Some(v.index_of())`, AND
// `T::index_of_label(<reserved probe>)` MUST equal `None`, AND
// `T::index_of_label("")` MUST equal `None`. The default trait body
// composes `T::find_by_label(s).map(T::index_of)` verbatim and
// satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the direct-index projection arm
// (a permissive override that returns `Some(_)` for a non-canonical
// `&str` — folding an off-set string onto an in-range slot at the
// direct-projection column while `find_by_label` still rejects it,
// silently bifurcating the `&str`-carrier decode axis; a strict
// override that returns `None` for a canonical variant's label,
// silently dropping slots at the label-decode boundary; a swapped
// override that recovers the wrong slot for a valid canonical
// label, silently bifurcating the (variant, `&'static str` label,
// `usize` index) projection triangle at its sixth direct edge)
// loudly rather than silently bifurcating the direct-index
// projection surface every downstream compact-encoder / metrics-
// binner / `tatara-check` per-slot per-label diagnostic / LSP-hover
// consumer routes through. Sibling posture to clauses (12) + (15)
// — clause (12) closes the (`&str` → typed variant) `Option`-typed
// direct projection, clause (15) closes the (typed variant →
// `usize`) forward projection, this clause closes the (`&str` →
// `usize`) direct projection composed from BOTH primitives AND
// pins the alignment with the natural two-step composition on
// every implementor. Together clauses (12) + (15) + (21) close
// the `&str`-carrier partition of the projection triangle at both
// the immediate (variant) decode column AND the further (index)
// decode column, mirroring the way clauses (16) + (20) close the
// `usize`-carrier partition at both its immediate (variant) decode
// column AND its further (label) decode column.
for &v in T::ALL {
let label = v.label();
assert_eq!(
T::index_of_label(label),
Some(v.index_of()),
"{type_name}: T::index_of_label({label:?}) drifted from Some(v.index_of()) — the direct (&str label → usize index) projection no longer agrees with the natural find_by_label+index_of composition on the canonical accept arm, so a downstream compact-encoder / metrics-binner / tatara-check per-slot per-label diagnostic / LSP-hover consumer that binds `T::index_of_label(s)` as its direct-projection surface would render the wrong slot for the canonical label {label:?}",
);
}
assert!(
T::index_of_label(probe).is_none(),
"{type_name}: T::index_of_label(<reserved probe>) returned Some(_) for an input outside the closed set — the direct (&str label → usize index) projection accepted a non-canonical string, silently folding an off-set string onto an in-range slot at the direct-projection column while `find_by_label` still rejects it, bifurcating the &str-carrier decode axis of the projection triangle",
);
assert!(
T::index_of_label("").is_none(),
"{type_name}: T::index_of_label(\"\") returned Some(_) — the direct (&str label → usize index) projection accepted the empty-string boundary that clause (4) reserves as structurally outside every closed set, folding the reserved boundary onto an in-range slot at the direct-projection column",
);
// (22) — For every variant `v` in `T::ALL`,
// `T::sorted_index_of(v)` MUST equal the position of `v` in
// `T::sorted_variants()`. The default trait body is a zero-alloc
// label-keyed strict-`<` linear scan over `T::ALL`; under clause
// (3)'s label-pairwise-distinctness contract, the count of labels
// strictly less than `v.label()` equals the unique lex-order slot
// `sorted_variants` places `v` in. The assertion catches a future
// implementor whose override drifts the direct (variant → lex
// position) projection — a permissive override that returns a
// slot outside `0..T::CARDINALITY`, a swapped override that
// returns the declaration-order slot instead of the lex-order
// slot, a stale override that returns the wrong lex-order slot
// after a label edit — loudly rather than silently bifurcating
// the lex-position projection surface every downstream
// lex-sorted-metrics-binner / lex-order-stable-wire-encoder /
// bitset-observed-slot-lex-renderer consumer routes through.
// Sibling posture to clauses (15) + (17) — clause (15) closes the
// (variant → declaration-order position) forward projection AND
// pins it against `T::ALL`'s position of `self`, clause (17)
// closes the sorted-typed-variant listing element-wise against
// the sorted-labels projection under the lex ordering, this
// clause closes the (variant → lex-order position) forward
// projection AND pins it against `T::sorted_variants()`'s
// position of `self` so the (declaration, lex) × (variant →
// position) forward-projection partition stays sound at BOTH
// ordering axes AND on every canonical variant slot. Reuses the
// `sorted_variants` Vec clauses (17) + (19) already materialized
// so this clause pays no additional allocation on top of the
// existing sweep's traversal surface.
for &v in T::ALL {
let expected_slot = sorted_variants
.iter()
.position(|w| core::mem::discriminant(w) == core::mem::discriminant(&v))
.expect(
"assert_closed_set_well_formed: T::sorted_variants() missing a canonical variant — clause (17)'s length equality should already have caught this",
);
assert_eq!(
T::sorted_index_of(v),
expected_slot,
"{type_name}: T::sorted_index_of({v:?}) drifted from T::sorted_variants()'s position of the variant — the direct (variant → lex-order position) projection no longer agrees with the natural sorted_variants.position projection, so a downstream lex-sorted-metrics-binner / lex-order-stable-wire-encoder / bitset-observed-slot-lex-renderer consumer that binds `v.sorted_index_of()` as its direct-projection surface would render the wrong lex slot for {v:?}",
);
}
// (23) — For every `i in 0..T::CARDINALITY`,
// `T::from_sorted_index(i)` MUST equal `Some(T::sorted_variants()
// [i])`, AND `T::from_sorted_index(T::CARDINALITY)` MUST equal
// `None`. The (`usize` lex-order position → typed variant) inverse
// projection agrees with direct `T::sorted_variants` slice indexing
// on the in-range domain AND rejects the first out-of-range index.
// Clauses (22) + (23) together pin the (typed variant ↔ `usize`
// lex-order position) bijection at BOTH directions: clause (22)
// covers the forward `variant.sorted_index_of() == i` projection,
// this clause covers the inverse `T::from_sorted_index(i) ==
// Some(v)` projection AND the out-of-range guard. The default
// trait body's `Self::sorted_variants().get(i).copied()`
// composition satisfies the clause for free; the assertion catches
// a future implementor whose override drifts the bounded-decode
// arm (a permissive override that returns `Some(_)` for an out-of-
// range index, folding an out-of-range serialized lex slot onto an
// in-range variant at the lex-order compact-decode boundary; a
// strict override that returns `None` for a valid in-range lex
// slot, silently dropping variants at the lex-order compact-decode
// boundary; a swapped override that recovers the wrong variant for
// a valid lex slot, silently bifurcating the (variant ↔ lex-order
// position) round-trip — a `variant.sorted_index_of()` round-
// tripped through `T::from_sorted_index(_)` would land at a
// different variant, breaking every lex-order compact-encoder /
// lex-order bitset consumer that expects the round-trip to close)
// loudly rather than silently bifurcating the lex-order inverse-
// decode surface every downstream lex-order compact-encoding /
// lex-order-bitset-observed-variant / lex-order-lookup-table-
// iteration consumer routes through. Sibling posture to clauses
// (16) + (22) — clause (16) closes the (declaration-order index →
// typed variant) inverse projection AND pins it against `T::ALL`
// slice indexing, clause (22) closes the (variant → lex-order
// position) forward projection AND pins it against
// `T::sorted_variants()`'s position of `self`, this clause closes
// the (lex-order index → typed variant) inverse projection AND
// pins it against `T::sorted_variants()` slice indexing so the
// (declaration, lex) × (position → variant) 1×2 inverse-projection
// partition stays sound at BOTH ordering axes AND on every
// canonical lex slot AND on the first out-of-range boundary.
// Reuses the `sorted_variants` Vec clauses (17) + (19) + (22)
// already materialized so this clause pays no additional
// allocation on top of the existing sweep's traversal surface.
for (i, &sorted_variant) in sorted_variants.iter().enumerate() {
let decoded = T::from_sorted_index(i);
assert_eq!(
decoded,
Some(sorted_variant),
"{type_name}: T::from_sorted_index({i}) drifted from Some(T::sorted_variants()[{i}]) — the direct (lex-order index → typed variant) inverse projection no longer agrees with direct T::sorted_variants slice indexing on the in-range domain, so a downstream lex-order compact-decoder / lex-order-bitset-observed-variant / lex-order-lookup-table consumer that binds `T::from_sorted_index(i)` as its inverse-decode surface would recover the wrong variant for lex slot {i}",
);
}
assert_eq!(
T::from_sorted_index(T::CARDINALITY),
None,
"{type_name}: T::from_sorted_index(T::CARDINALITY) returned Some(_) — the (lex-order index → typed variant) inverse projection accepted the first out-of-range lex slot, folding an out-of-range serialized lex index onto an in-range variant at the lex-order compact-decode boundary. Clauses (14) + (23) together pin `T::CARDINALITY` as the first structurally-out-of-range lex slot — a permissive override that fails this pin bifurcates the lex-order compact-encoding surface every downstream consumer routes through.",
);
// (24) — For every `i in 0..T::CARDINALITY`,
// `T::sorted_label_at(i)` MUST equal `Some(T::sorted_labels()[i])`,
// AND `T::sorted_label_at(T::CARDINALITY)` MUST equal `None`. The
// direct (`usize` lex-order position → `&'static str` canonical
// label) projection agrees with the natural `from_sorted_index` +
// `label` composition on the in-range domain (equivalently, with
// direct `T::sorted_labels` slice indexing under lex ordering) AND
// rejects the first out-of-range lex slot. Clauses (20) + (24)
// together pin the (`usize` position → `&'static str` label) forward
// projection at BOTH ordering axes: clause (20) covers the
// declaration-ordering direct-label projection, this clause covers
// the lex-ordering direct-label projection. The default trait body's
// `from_sorted_index(i).map(label)` composition satisfies the clause
// for free; the assertion catches a future implementor whose
// override drifts the direct-label projection arm (a permissive
// override that returns `Some(_)` for an out-of-range lex slot,
// folding an out-of-range serialized lex index onto an in-range
// label at the lex-order compact-decode boundary; a strict override
// that returns `None` for a valid in-range lex slot, silently
// dropping labels at the lex-order rendering boundary; a swapped
// override that recovers the wrong label for a valid lex slot,
// silently bifurcating the lex-axis projection triangle) loudly
// rather than silently bifurcating the direct-label projection
// surface every downstream lex-order compact-encoding / lex-sorted-
// metrics-binner / bitset-observed-slot-lex-renderer / `tatara-check`
// per-lex-slot diagnostic consumer routes through. Sibling posture
// to clauses (20) + (23) — clause (20) closes the (declaration-order
// index → `&'static str` label) direct projection, clause (23)
// closes the (lex-order index → typed variant) inverse projection,
// this clause closes the (lex-order index → `&'static str` label)
// direct projection so the lex-axis projection triangle stays sound
// at BOTH return-projection columns AND on both the in-range accept
// AND the out-of-range reject partitions. Reuses the
// `sorted_labels_reference` Vec clause (17) already materialized so
// this clause pays no additional allocation on top of the existing
// sweep's traversal surface.
for (i, &expected_label) in sorted_labels_reference.iter().enumerate() {
let decoded = T::sorted_label_at(i);
assert_eq!(
decoded,
Some(expected_label),
"{type_name}: T::sorted_label_at({i}) drifted from Some(T::sorted_labels()[{i}]) — the direct (lex-order index → `&'static str` label) projection no longer agrees with direct T::sorted_labels slice indexing on the in-range domain, so a downstream lex-order compact-decoder / lex-sorted-metrics-binner / bitset-observed-slot-lex-renderer consumer that binds `T::sorted_label_at(i)` as its direct-label projection surface would render the wrong label for lex slot {i}",
);
}
assert_eq!(
T::sorted_label_at(T::CARDINALITY),
None,
"{type_name}: T::sorted_label_at(T::CARDINALITY) returned Some(_) — the (lex-order index → `&'static str` label) direct projection accepted the first out-of-range lex slot, folding an out-of-range serialized lex index onto an in-range label at the lex-order compact-decode boundary. Clauses (14) + (24) together pin `T::CARDINALITY` as the first structurally-out-of-range lex slot — a permissive override that fails this pin bifurcates the lex-order rendering surface every downstream consumer routes through.",
);
// (25) — For every variant `v` in `T::ALL`,
// `T::sorted_index_of_label(v.label())` MUST equal
// `Some(v.sorted_index_of())`, AND
// `T::sorted_index_of_label(<reserved probe>)` MUST equal `None`,
// AND `T::sorted_index_of_label("")` MUST equal `None`. The default
// trait body composes `T::find_by_label(s).map(T::sorted_index_of)`
// verbatim and satisfies both arms for free; the assertion catches
// a future implementor whose override drifts the direct-lex-slot
// projection arm (a permissive override that returns `Some(_)` for
// a non-canonical `&str` — folding an off-set string onto an
// in-range lex slot at the direct-projection column while
// `find_by_label` still rejects it, silently bifurcating the
// `&str`-carrier decode axis on the lex-order projection column;
// a strict override that returns `None` for a canonical variant's
// label, silently dropping lex slots at the label-decode boundary;
// a swapped override that recovers the wrong lex slot for a valid
// canonical label, silently bifurcating the (typed variant,
// `&'static str` label, `usize` position) lex-axis projection
// triangle at its fourth direct edge) loudly rather than silently
// bifurcating the direct-lex-slot projection surface every
// downstream lex-sorted-metrics-binner / lex-order-compact-encoder
// / `tatara-check` per-lex-slot per-label diagnostic / LSP-hover
// consumer routes through. Sibling posture to clauses (21) + (22)
// — clause (21) closes the (`&str` → declaration-order index) direct
// projection AND pins the composition against
// `find_by_label+index_of`, clause (22) closes the (variant →
// lex-order position) forward projection AND pins it against
// `T::sorted_variants()`'s position of `self`, this clause closes
// the (`&str` → lex-order index) direct projection AND pins the
// composition against `find_by_label+sorted_index_of` so the
// (declaration, lex) × (`&str` → position) 1×2 direct-projection
// partition stays sound at BOTH ordering axes AND on every canonical
// variant label AND on both the reserved out-of-set probe boundary
// AND the empty-string boundary. With clauses (20) + (21) + (22) +
// (23) + (24) + (25) all in place, the (typed variant, `&'static
// str` label, `usize` position) projection triangle stays direct-
// projection closed at EVERY (input, output) pair on BOTH ordering
// axes.
for &v in T::ALL {
let label = v.label();
assert_eq!(
T::sorted_index_of_label(label),
Some(v.sorted_index_of()),
"{type_name}: T::sorted_index_of_label({label:?}) drifted from Some(v.sorted_index_of()) — the direct (&str label → usize lex-order index) projection no longer agrees with the natural find_by_label+sorted_index_of composition on the canonical accept arm, so a downstream lex-sorted-metrics-binner / lex-order-compact-encoder / tatara-check per-lex-slot per-label diagnostic / LSP-hover consumer that binds `T::sorted_index_of_label(s)` as its direct-projection surface would render the wrong lex slot for the canonical label {label:?}",
);
}
assert!(
T::sorted_index_of_label(probe).is_none(),
"{type_name}: T::sorted_index_of_label(<reserved probe>) returned Some(_) for an input outside the closed set — the direct (&str label → usize lex-order index) projection accepted a non-canonical string, silently folding an off-set string onto an in-range lex slot at the direct-projection column while `find_by_label` still rejects it, bifurcating the &str-carrier decode axis of the lex-order projection triangle",
);
assert!(
T::sorted_index_of_label("").is_none(),
"{type_name}: T::sorted_index_of_label(\"\") returned Some(_) — the direct (&str label → usize lex-order index) projection accepted the empty-string boundary that clause (4) reserves as structurally outside every closed set, folding the reserved boundary onto an in-range lex slot at the direct-projection column",
);
// (26) — For every variant `v` in `T::ALL`, `v.next()` MUST equal
// `T::from_index(v.index_of() + 1)`, AND `v.prev()` MUST equal
// `T::from_index(v.index_of() - 1)` when `v.index_of() > 0`, AND
// `T::first().prev()` MUST equal `None`, AND `T::last().next()`
// MUST equal `None`. The default trait bodies compose
// `from_index(index_of(self) + 1)` (forward arm) and
// `from_index(index_of(self) - 1)` guarded on `index_of(self) > 0`
// (backward arm) verbatim and satisfy both arms for free; the
// assertion catches a future implementor whose override drifts
// either neighbor projection (a permissive forward override that
// returns `Some(_)` at the tail — folding a tail-boundary walk
// onto a wraparound to the head at the forward-projection column
// while the composed `+ 1` arithmetic would return `None`; a
// permissive backward override that returns `Some(_)` at the head
// — folding a head-boundary walk onto a wraparound to the tail
// through the `usize` underflow the guard prevents; a swapped
// override that returns the predecessor for `next` AND the
// successor for `prev`, silently inverting the traversal
// direction; a stale override that returns the wrong neighbor
// after a variant-listing edit) loudly rather than silently
// bifurcating the neighbor-projection surface every downstream
// state-machine iterator / saga-step engine / truth-table
// property test / phase-fold reducer consumer routes through.
// Sibling posture to clauses (15) + (16) + (18) — clauses (15) +
// (16) pin the (typed variant ↔ `usize` array index) bijection at
// BOTH directions, clause (18) pins the (head, tail) endpoint
// anchors against `T::ALL[0]` / `T::ALL[T::ALL.len() - 1]`, this
// clause pins the (forward, backward) neighbor projections against
// the composition of both bijection arms AND pins the endpoint-
// boundary `None` guards on both direction arms — so the closed-
// set traversal surface stays sound at BOTH direction arms AND on
// the shared endpoint-anchor fixpoints (`T::last().next() ==
// None`, `T::first().prev() == None`).
for &v in T::ALL {
let i = v.index_of();
let expected_next = T::from_index(i + 1);
assert_eq!(
v.next(),
expected_next,
"{type_name}: {v:?}.next() drifted from T::from_index({v:?}.index_of() + 1) — the direct (variant → forward neighbor) projection no longer agrees with the natural index_of+from_index composition, so a downstream state-machine iterator / saga-step engine / phase-fold reducer / LSP wraparound-cursor consumer that binds `v.next()` as its forward-traversal surface would land on the wrong neighbor for {v:?}",
);
if i > 0 {
let expected_prev = T::from_index(i - 1);
assert_eq!(
v.prev(),
expected_prev,
"{type_name}: {v:?}.prev() drifted from T::from_index({v:?}.index_of() - 1) — the direct (variant → backward neighbor) projection no longer agrees with the natural index_of+from_index composition on an interior slot, so a downstream state-machine iterator / saga-step engine / phase-fold reducer / LSP wraparound-cursor consumer that binds `v.prev()` as its backward-traversal surface would land on the wrong neighbor for {v:?}",
);
}
}
assert_eq!(
T::first().prev(),
None,
"{type_name}: T::first().prev() returned Some(_) — the (variant → backward neighbor) projection accepted the head-endpoint boundary, silently folding a head-boundary walk onto a wraparound to the tail while the natural `usize` underflow guard should return `None`. Clauses (18) + (26) together pin `T::first().prev() == None` as the structural fixpoint the head-endpoint anchor and the backward-neighbor axis share",
);
assert_eq!(
T::last().next(),
None,
"{type_name}: T::last().next() returned Some(_) — the (variant → forward neighbor) projection accepted the tail-endpoint boundary, silently folding a tail-boundary walk onto a wraparound to the head while the natural `<[T]>::get` bounded-index projection should return `None`. Clauses (18) + (26) together pin `T::last().next() == None` as the structural fixpoint the tail-endpoint anchor and the forward-neighbor axis share",
);
// (27) — For every variant `v` in `T::ALL`, `v.sorted_next()` MUST
// equal `T::from_sorted_index(v.sorted_index_of() + 1)`, AND
// `v.sorted_prev()` MUST equal
// `T::from_sorted_index(v.sorted_index_of() - 1)` when
// `v.sorted_index_of() > 0`, AND `T::sorted_first().sorted_prev()`
// MUST equal `None`, AND `T::sorted_last().sorted_next()` MUST
// equal `None`. The default trait bodies compose
// `from_sorted_index(sorted_index_of(self) + 1)` (forward arm) and
// `from_sorted_index(sorted_index_of(self) - 1)` guarded on
// `sorted_index_of(self) > 0` (backward arm) verbatim and satisfy
// both arms for free; the assertion catches a future implementor
// whose override drifts either lex-neighbor projection (a
// permissive forward override that returns `Some(_)` at the
// lex-tail — folding a lex-tail-boundary walk onto a wraparound
// to the lex-head at the forward-lex-projection column while the
// composed `+ 1` arithmetic would return `None`; a permissive
// backward override that returns `Some(_)` at the lex-head —
// folding a lex-head-boundary walk onto a wraparound to the
// lex-tail through the `usize` underflow the guard prevents; a
// swapped override that returns the lex-predecessor for
// `sorted_next` AND the lex-successor for `sorted_prev`, silently
// inverting the lex-traversal direction; a stale override that
// returns the wrong lex-neighbor after a variant-listing edit
// reorders the lex partition) loudly rather than silently
// bifurcating the lex-neighbor-projection surface every
// downstream alphabetized-completion LSP cursor / lex-sorted
// `tatara-check` per-slot diagnostic renderer / lex-order
// compact-encoded wire codec / Sekiban audit binner /
// alphabetized property-test sweep consumer routes through.
// Sibling posture to clauses (22) + (23) + (26) — clauses (22) +
// (23) pin the (typed variant ↔ `usize` lex-order position)
// bijection at BOTH directions, clause (26) pins the (forward,
// backward) declaration-order neighbor projections against the
// composition of both declaration-axis bijection arms AND pins
// the endpoint-boundary `None` guards on both direction arms,
// this clause pins the (forward, backward) LEX-order neighbor
// projections against the composition of both lex-axis bijection
// arms AND pins the lex-endpoint-boundary `None` guards on both
// direction arms — so the closed-set neighbor surface stays sound
// at BOTH direction arms AND on BOTH ordering axes AND on the
// shared lex-endpoint-anchor fixpoints
// (`T::sorted_last().sorted_next() == None`,
// `T::sorted_first().sorted_prev() == None`). Clauses (26) + (27)
// together close the (declaration × lex) × (forward, backward)
// 2×2 closed-set neighbor matrix at ALL FOUR direct
// projection surfaces AND at ALL FOUR endpoint-boundary
// fixpoints.
for &v in T::ALL {
let i = v.sorted_index_of();
let expected_sorted_next = T::from_sorted_index(i + 1);
assert_eq!(
v.sorted_next(),
expected_sorted_next,
"{type_name}: {v:?}.sorted_next() drifted from T::from_sorted_index({v:?}.sorted_index_of() + 1) — the direct (variant → forward lex-neighbor) projection no longer agrees with the natural sorted_index_of+from_sorted_index composition, so a downstream alphabetized-completion LSP cursor / lex-sorted tatara-check per-slot diagnostic renderer / lex-order compact-encoded wire codec / Sekiban audit binner consumer that binds `v.sorted_next()` as its forward-lex-traversal surface would land on the wrong lex-neighbor for {v:?}",
);
if i > 0 {
let expected_sorted_prev = T::from_sorted_index(i - 1);
assert_eq!(
v.sorted_prev(),
expected_sorted_prev,
"{type_name}: {v:?}.sorted_prev() drifted from T::from_sorted_index({v:?}.sorted_index_of() - 1) — the direct (variant → backward lex-neighbor) projection no longer agrees with the natural sorted_index_of+from_sorted_index composition on an interior lex slot, so a downstream alphabetized-completion LSP cursor / lex-sorted tatara-check per-slot diagnostic renderer / lex-order compact-encoded wire codec / Sekiban audit binner consumer that binds `v.sorted_prev()` as its backward-lex-traversal surface would land on the wrong lex-neighbor for {v:?}",
);
}
}
assert_eq!(
T::sorted_first().sorted_prev(),
None,
"{type_name}: T::sorted_first().sorted_prev() returned Some(_) — the (variant → backward lex-neighbor) projection accepted the lex-head-endpoint boundary, silently folding a lex-head-boundary walk onto a wraparound to the lex-tail while the natural `usize` underflow guard should return `None`. Clauses (26) + (27) together pin `T::sorted_first().sorted_prev() == None` as the structural fixpoint the lex-head-endpoint anchor and the backward-lex-neighbor axis share, mirroring `T::first().prev() == None` one ordering axis over",
);
assert_eq!(
T::sorted_last().sorted_next(),
None,
"{type_name}: T::sorted_last().sorted_next() returned Some(_) — the (variant → forward lex-neighbor) projection accepted the lex-tail-endpoint boundary, silently folding a lex-tail-boundary walk onto a wraparound to the lex-head while the natural bounded-index projection should return `None`. Clauses (26) + (27) together pin `T::sorted_last().sorted_next() == None` as the structural fixpoint the lex-tail-endpoint anchor and the forward-lex-neighbor axis share, mirroring `T::last().next() == None` one ordering axis over",
);
// (28) — For every variant `v` in `T::ALL`, `v.cycle_next()` MUST
// equal `v.next().unwrap_or(T::first())`, AND `v.cycle_prev()`
// MUST equal `v.prev().unwrap_or(T::last())`, AND
// `T::last().cycle_next()` MUST equal `T::first()`, AND
// `T::first().cycle_prev()` MUST equal `T::last()`. The default
// trait bodies compose `next().unwrap_or(first())` (forward-
// wrapping arm) and `prev().unwrap_or(last())` (backward-
// wrapping arm) verbatim and satisfy both arms for free; the
// assertion catches a future implementor whose override drifts
// either wrapping-neighbor projection (a permissive forward-
// wrapping override that returns some interior variant at the
// tail rather than the head anchor — folding a cyclic walk onto
// an unbounded interior loop while the composed `next()
// .unwrap_or(first())` shape would fold the tail onto
// `T::first()`; a permissive backward-wrapping override that
// returns some interior variant at the head rather than the tail
// anchor — folding a cyclic backward walk onto an unbounded
// interior loop through the mismatched fallback; a swapped
// override that returns the wrapping-predecessor for `cycle_next`
// AND the wrapping-successor for `cycle_prev`, silently inverting
// the cyclic traversal direction; a stale override that returns
// the wrong wrapping-neighbor after a variant-listing edit
// reorders `T::ALL`) loudly rather than silently bifurcating the
// wrapping-neighbor-projection surface every downstream
// wraparound-cursor LSP completion renderer / UI mode selector /
// round-robin scheduler / declaration-order carousel widget /
// per-tick animation frame picker consumer routes through.
// Sibling posture to clauses (18) + (26) — clause (18) pins the
// (head, tail) endpoint anchors against `T::ALL[0]` /
// `T::ALL[T::ALL.len() - 1]`, clause (26) pins the (forward,
// backward) bounded-neighbor projections against the composition
// of both bijection arms AND pins the endpoint-boundary `None`
// guards on both direction arms, this clause pins the (forward,
// backward) WRAPPING-neighbor projections against the composition
// of the bounded-neighbor arm with the SIBLING-direction endpoint
// anchor AND pins the endpoint-boundary wraparound folds on both
// direction arms — so the closed-set declaration-axis neighbor
// surface stays sound on BOTH return-type arms (Option-typed /
// wrapping) AND on BOTH direction arms AND on the shared
// endpoint-anchor wraparound fixpoints (`T::last().cycle_next()
// == T::first()`, `T::first().cycle_prev() == T::last()`).
// Clauses (26) + (28) together close the (Option-typed, wrapping)
// × (forward, backward) 2×2 declaration-axis neighbor matrix at
// ALL FOUR direct projection surfaces AND at ALL FOUR endpoint-
// boundary fixpoints.
for &v in T::ALL {
let expected_cycle_next = v.next().unwrap_or_else(T::first);
assert_eq!(
v.cycle_next(),
expected_cycle_next,
"{type_name}: {v:?}.cycle_next() drifted from {v:?}.next().unwrap_or(T::first()) — the direct (variant → wrapping-forward neighbor) projection no longer agrees with the natural next+first composition, so a downstream wraparound-cursor LSP completion renderer / UI mode selector / round-robin scheduler / declaration-order carousel widget consumer that binds `v.cycle_next()` as its forward-wrapping-traversal surface would land on the wrong wrapping-neighbor for {v:?}",
);
let expected_cycle_prev = v.prev().unwrap_or_else(T::last);
assert_eq!(
v.cycle_prev(),
expected_cycle_prev,
"{type_name}: {v:?}.cycle_prev() drifted from {v:?}.prev().unwrap_or(T::last()) — the direct (variant → wrapping-backward neighbor) projection no longer agrees with the natural prev+last composition, so a downstream wraparound-cursor LSP completion renderer / UI mode selector / round-robin scheduler / declaration-order carousel widget consumer that binds `v.cycle_prev()` as its backward-wrapping-traversal surface would land on the wrong wrapping-neighbor for {v:?}",
);
}
assert_eq!(
T::last().cycle_next(),
T::first(),
"{type_name}: T::last().cycle_next() returned a variant other than T::first() — the (variant → wrapping-forward neighbor) projection failed to fold the tail-endpoint boundary onto the head-endpoint anchor while the natural next+first composition should return T::first(). Clauses (18) + (28) together pin `T::last().cycle_next() == T::first()` as the structural wraparound fixpoint the tail-endpoint anchor and the forward-wrapping-neighbor axis share, mirroring `T::last().next() == None` one return-type axis over",
);
assert_eq!(
T::first().cycle_prev(),
T::last(),
"{type_name}: T::first().cycle_prev() returned a variant other than T::last() — the (variant → wrapping-backward neighbor) projection failed to fold the head-endpoint boundary onto the tail-endpoint anchor while the natural prev+last composition should return T::last(). Clauses (18) + (28) together pin `T::first().cycle_prev() == T::last()` as the structural wraparound fixpoint the head-endpoint anchor and the backward-wrapping-neighbor axis share, mirroring `T::first().prev() == None` one return-type axis over",
);
// (29) — For every variant `v` in `T::ALL`, `v.cycle_sorted_next()`
// MUST equal `v.sorted_next().unwrap_or(T::sorted_first())`, AND
// `v.cycle_sorted_prev()` MUST equal
// `v.sorted_prev().unwrap_or(T::sorted_last())`, AND
// `T::sorted_last().cycle_sorted_next()` MUST equal
// `T::sorted_first()`, AND `T::sorted_first().cycle_sorted_prev()`
// MUST equal `T::sorted_last()`. The default trait bodies compose
// `sorted_next().unwrap_or(sorted_first())` (forward-wrapping-lex
// arm) and `sorted_prev().unwrap_or(sorted_last())` (backward-
// wrapping-lex arm) verbatim and satisfy both arms for free; the
// assertion catches a future implementor whose override drifts
// either wrapping-lex-neighbor projection (a permissive forward-
// wrapping-lex override that returns some interior variant at the
// lex tail rather than the lex-head anchor — folding a lex-cyclic
// walk onto an unbounded interior loop while the composed
// `sorted_next().unwrap_or(sorted_first())` shape would fold the
// lex tail onto `T::sorted_first()`; a permissive backward-
// wrapping-lex override that returns some interior variant at the
// lex head rather than the lex-tail anchor — folding a lex-cyclic
// backward walk onto an unbounded interior loop through the
// mismatched fallback; a swapped override that returns the
// wrapping-lex-predecessor for `cycle_sorted_next` AND the
// wrapping-lex-successor for `cycle_sorted_prev`, silently
// inverting the cyclic lex-traversal direction; a stale override
// that returns the wrong wrapping-lex-neighbor after a variant-
// listing edit reorders the lex partition) loudly rather than
// silently bifurcating the wrapping-lex-neighbor-projection surface
// every downstream alphabetized wraparound-cursor LSP completion
// renderer / alphabetized UI mode selector / alphabetized round-
// robin scheduler / lex-order carousel widget / alphabetized
// per-tick animation frame picker consumer routes through. Sibling
// posture to clauses (18) + (26) + (27) + (28) — clause (18) pins
// the (head, tail) endpoint anchors against `T::ALL[0]` /
// `T::ALL[T::ALL.len() - 1]`, clauses (26) + (27) pin the (forward,
// backward) bounded-neighbor projections on BOTH ordering axes AND
// pin the endpoint-boundary `None` guards on all four direction
// arms, clause (28) pins the (forward, backward) WRAPPING-neighbor
// projections on the DECLARATION axis against the composition of
// the bounded-neighbor arm with the sibling-direction endpoint
// anchor AND pins the endpoint-boundary wraparound folds on both
// declaration-axis direction arms, this clause pins the (forward,
// backward) WRAPPING-neighbor projections on the LEX axis against
// the composition of the lex-bounded-neighbor arm with the
// sibling-direction lex-endpoint anchor AND pins the lex-endpoint-
// boundary wraparound folds on both lex-axis direction arms — so
// the closed-set neighbor surface stays sound on BOTH return-type
// arms (Option-typed / wrapping) AND on BOTH direction arms AND on
// BOTH ordering axes AND on the shared lex-endpoint-anchor
// wraparound fixpoints (`T::sorted_last().cycle_sorted_next() ==
// T::sorted_first()`, `T::sorted_first().cycle_sorted_prev() ==
// T::sorted_last()`). Clauses (26) + (27) + (28) + (29) together
// close the (Option-typed, wrapping) × (declaration, lex) ×
// (forward, backward) 2×2×2 = 8-corner closed-set neighbor cube at
// ALL EIGHT direct projection surfaces AND at ALL EIGHT endpoint-
// boundary fixpoints.
for &v in T::ALL {
let expected_cycle_sorted_next = v.sorted_next().unwrap_or_else(T::sorted_first);
assert_eq!(
v.cycle_sorted_next(),
expected_cycle_sorted_next,
"{type_name}: {v:?}.cycle_sorted_next() drifted from {v:?}.sorted_next().unwrap_or(T::sorted_first()) — the direct (variant → wrapping-forward lex-neighbor) projection no longer agrees with the natural sorted_next+sorted_first composition, so a downstream alphabetized wraparound-cursor LSP completion renderer / alphabetized UI mode selector / alphabetized round-robin scheduler / lex-order carousel widget consumer that binds `v.cycle_sorted_next()` as its forward-wrapping-lex-traversal surface would land on the wrong wrapping-lex-neighbor for {v:?}",
);
let expected_cycle_sorted_prev = v.sorted_prev().unwrap_or_else(T::sorted_last);
assert_eq!(
v.cycle_sorted_prev(),
expected_cycle_sorted_prev,
"{type_name}: {v:?}.cycle_sorted_prev() drifted from {v:?}.sorted_prev().unwrap_or(T::sorted_last()) — the direct (variant → wrapping-backward lex-neighbor) projection no longer agrees with the natural sorted_prev+sorted_last composition, so a downstream alphabetized wraparound-cursor LSP completion renderer / alphabetized UI mode selector / alphabetized round-robin scheduler / lex-order carousel widget consumer that binds `v.cycle_sorted_prev()` as its backward-wrapping-lex-traversal surface would land on the wrong wrapping-lex-neighbor for {v:?}",
);
}
assert_eq!(
T::sorted_last().cycle_sorted_next(),
T::sorted_first(),
"{type_name}: T::sorted_last().cycle_sorted_next() returned a variant other than T::sorted_first() — the (variant → wrapping-forward lex-neighbor) projection failed to fold the lex-tail-endpoint boundary onto the lex-head-endpoint anchor while the natural sorted_next+sorted_first composition should return T::sorted_first(). Clauses (18) + (29) together pin `T::sorted_last().cycle_sorted_next() == T::sorted_first()` as the structural lex-wraparound fixpoint the lex-tail-endpoint anchor and the forward-wrapping-lex-neighbor axis share, mirroring `T::sorted_last().sorted_next() == None` one return-type axis over AND `T::last().cycle_next() == T::first()` one ordering axis over",
);
assert_eq!(
T::sorted_first().cycle_sorted_prev(),
T::sorted_last(),
"{type_name}: T::sorted_first().cycle_sorted_prev() returned a variant other than T::sorted_last() — the (variant → wrapping-backward lex-neighbor) projection failed to fold the lex-head-endpoint boundary onto the lex-tail-endpoint anchor while the natural sorted_prev+sorted_last composition should return T::sorted_last(). Clauses (18) + (29) together pin `T::sorted_first().cycle_sorted_prev() == T::sorted_last()` as the structural lex-wraparound fixpoint the lex-head-endpoint anchor and the backward-wrapping-lex-neighbor axis share, mirroring `T::sorted_first().sorted_prev() == None` one return-type axis over AND `T::first().cycle_prev() == T::last()` one ordering axis over",
);
// (30) — For every variant `v` in `T::ALL`, `v.is_first()` MUST
// equal `v.index_of() == 0`, AND `v.is_last()` MUST equal
// `v.index_of() + 1 == T::CARDINALITY`, AND
// `T::first().is_first()` MUST be `true`, AND
// `T::last().is_last()` MUST be `true`. The default trait bodies
// compose `index_of(self) == 0` (head-arm) and
// `index_of(self) + 1 == Self::CARDINALITY` (tail-arm) verbatim
// and satisfy both arms for free; the assertion catches a future
// implementor whose override drifts either endpoint-membership
// projection (a permissive head override that returns `true` on
// an interior slot — folding a bounded-loop guard onto the wrong
// partition of `T::ALL` and silently short-circuiting an iterator
// before it reaches the head-endpoint; a permissive tail override
// that returns `true` on an interior slot — folding a
// termination-detection consumer onto the wrong partition of
// `T::ALL` and silently short-circuiting the iterator before it
// reaches the tail-endpoint; a swapped override that returns
// `is_last`'s answer for `is_first` AND vice-versa, silently
// inverting the (head, tail) membership partition; a stale
// override that returns the wrong endpoint membership after a
// variant-listing edit shifts the slot alignment) loudly rather
// than silently bifurcating the endpoint-membership projection
// surface every downstream bounded-loop guard / saga-step
// engine / truth-table property test / wraparound-cursor
// renderer / termination-detection consumer routes through.
// Sibling posture to clauses (15) + (18) — clause (15) pins the
// (variant → declaration-order position) forward projection
// against `T::ALL`'s position of `self`, clause (18) pins the
// (head, tail) endpoint anchors against `T::ALL[0]` /
// `T::ALL[T::ALL.len() - 1]`, this clause pins the (bool head-
// membership, bool tail-membership) projections against the
// composition of the forward-position projection with the const-
// visible variant count AND pins the endpoint-anchor `true`
// fixpoints on both direction arms — so the closed-set
// declaration-axis endpoint surface stays sound on BOTH return-
// type arms (`Self`-typed anchor / `bool`-typed membership) AND
// on BOTH direction arms AND on the shared endpoint-anchor
// membership fixpoints (`T::first().is_first() == true`,
// `T::last().is_last() == true`). Clauses (18) + (30) together
// close the (return-type × direction) 2×2 declaration-axis
// endpoint matrix at ALL FOUR direct projection surfaces AND at
// BOTH endpoint-anchor membership fixpoints.
for &v in T::ALL {
let i = v.index_of();
assert_eq!(
v.is_first(),
i == 0,
"{type_name}: {v:?}.is_first() drifted from {v:?}.index_of() == 0 — the direct (variant → head-membership bool) projection no longer agrees with the natural `index_of == 0` composition, so a downstream bounded-loop guard / saga-step engine / truth-table property test / wraparound-cursor renderer consumer that binds `v.is_first()` as its head-boundary query surface would answer the wrong `bool` for {v:?}",
);
assert_eq!(
v.is_last(),
i + 1 == T::CARDINALITY,
"{type_name}: {v:?}.is_last() drifted from {v:?}.index_of() + 1 == T::CARDINALITY — the direct (variant → tail-membership bool) projection no longer agrees with the natural `index_of + 1 == CARDINALITY` composition, so a downstream termination-detection / bounded-loop-terminator / saga-step engine / wraparound-cursor renderer consumer that binds `v.is_last()` as its tail-boundary query surface would answer the wrong `bool` for {v:?}",
);
}
assert!(
T::first().is_first(),
"{type_name}: T::first().is_first() returned false — the (variant → head-membership bool) projection failed to fire on the declaration-order head endpoint anchor while the natural `index_of == 0` composition should return true. Clauses (18) + (30) together pin `T::first().is_first() == true` as the structural fixpoint the head-endpoint anchor and the head-membership predicate axis share",
);
assert!(
T::last().is_last(),
"{type_name}: T::last().is_last() returned false — the (variant → tail-membership bool) projection failed to fire on the declaration-order tail endpoint anchor while the natural `index_of + 1 == CARDINALITY` composition should return true. Clauses (18) + (30) together pin `T::last().is_last() == true` as the structural fixpoint the tail-endpoint anchor and the tail-membership predicate axis share, mirroring `T::first().is_first() == true` one direction axis over",
);
// (31) — For every variant `v` in `T::ALL`, `v.is_sorted_first()`
// MUST equal `v.sorted_index_of() == 0`, AND `v.is_sorted_last()`
// MUST equal `v.sorted_index_of() + 1 == T::CARDINALITY`, AND
// `T::sorted_first().is_sorted_first()` MUST be `true`, AND
// `T::sorted_last().is_sorted_last()` MUST be `true`. The default
// trait bodies compose `sorted_index_of(self) == 0` (lex head-arm)
// and `sorted_index_of(self) + 1 == Self::CARDINALITY` (lex tail-
// arm) verbatim and satisfy both arms for free; the assertion
// catches a future implementor whose override drifts either lex-
// endpoint-membership projection (a permissive lex head override
// that returns `true` on an interior lex slot — folding a
// bounded-lex-loop guard onto the wrong partition of the
// alphabetized listing and silently short-circuiting an
// alphabetized iterator before it reaches the lex-head endpoint;
// a permissive lex tail override that returns `true` on an
// interior lex slot — folding a lex-termination-detection
// consumer onto the wrong partition; a swapped override that
// returns `is_sorted_last`'s answer for `is_sorted_first` AND
// vice-versa, silently inverting the (lex-head, lex-tail)
// membership partition; a stale override that returns the wrong
// endpoint membership after a label edit shifts the lex slot
// alignment) loudly rather than silently bifurcating the lex-
// endpoint-membership projection surface every downstream
// alphabetized-LSP-cursor / lex-anchored-diagnostic-renderer /
// lex-slot-metrics-tagger / alphabetized-default-deserializer
// consumer routes through. Sibling posture to clause (30) one
// ordering-axis over on the (declaration, lex) partition of the
// (return-type × ordering × direction) 2×2×2 endpoint cube —
// clause (30) pins the (bool head-membership, bool tail-
// membership) projections on the DECLARATION axis, this clause
// pins the (bool lex-head-membership, bool lex-tail-membership)
// projections on the LEX axis. Clauses (18) + (19) + (30) + (31)
// together close the (return-type × ordering × direction) 2×2×2
// = 8-corner endpoint cube at ALL EIGHT direct projection
// surfaces AND at ALL FOUR endpoint-anchor membership fixpoints
// (`T::first().is_first()`, `T::last().is_last()`,
// `T::sorted_first().is_sorted_first()`,
// `T::sorted_last().is_sorted_last()` — one per corner of the
// (ordering × direction) 2×2 anchor matrix).
for &v in T::ALL {
let i = v.sorted_index_of();
assert_eq!(
v.is_sorted_first(),
i == 0,
"{type_name}: {v:?}.is_sorted_first() drifted from {v:?}.sorted_index_of() == 0 — the direct (variant → lex-head-membership bool) projection no longer agrees with the natural `sorted_index_of == 0` composition, so a downstream alphabetized-LSP-cursor / lex-anchored-diagnostic-renderer / lex-slot-metrics-tagger / alphabetized-default-deserializer consumer that binds `v.is_sorted_first()` as its lex-head-boundary query surface would answer the wrong `bool` for {v:?}",
);
assert_eq!(
v.is_sorted_last(),
i + 1 == T::CARDINALITY,
"{type_name}: {v:?}.is_sorted_last() drifted from {v:?}.sorted_index_of() + 1 == T::CARDINALITY — the direct (variant → lex-tail-membership bool) projection no longer agrees with the natural `sorted_index_of + 1 == CARDINALITY` composition, so a downstream alphabetized-termination-detector / lex-bounded-loop-terminator / lex-anchored-diagnostic-renderer consumer that binds `v.is_sorted_last()` as its lex-tail-boundary query surface would answer the wrong `bool` for {v:?}",
);
}
assert!(
T::sorted_first().is_sorted_first(),
"{type_name}: T::sorted_first().is_sorted_first() returned false — the (variant → lex-head-membership bool) projection failed to fire on the lex-order head endpoint anchor while the natural `sorted_index_of == 0` composition should return true. Clauses (19) + (31) together pin `T::sorted_first().is_sorted_first() == true` as the structural fixpoint the lex-head-endpoint anchor and the lex-head-membership predicate axis share, mirroring `T::first().is_first() == true` one ordering axis over",
);
assert!(
T::sorted_last().is_sorted_last(),
"{type_name}: T::sorted_last().is_sorted_last() returned false — the (variant → lex-tail-membership bool) projection failed to fire on the lex-order tail endpoint anchor while the natural `sorted_index_of + 1 == CARDINALITY` composition should return true. Clauses (19) + (31) together pin `T::sorted_last().is_sorted_last() == true` as the structural fixpoint the lex-tail-endpoint anchor and the lex-tail-membership predicate axis share, mirroring `T::last().is_last() == true` one ordering axis over and completing the 8-corner endpoint cube",
);
// (32) — For every variant `v` in `T::ALL`, `v.is_endpoint()` MUST
// equal `v.is_first() || v.is_last()`, AND `v.is_interior()` MUST
// equal `!(v.is_first() || v.is_last())`, AND
// `is_endpoint(v) != is_interior(v)` (exhaustive complementarity),
// AND `T::first().is_endpoint()` MUST be `true`, AND
// `T::last().is_endpoint()` MUST be `true`, AND
// `T::first().is_interior()` MUST be `false`, AND
// `T::last().is_interior()` MUST be `false`. The default trait
// bodies compose `is_first(self) || is_last(self)` (boundary arm)
// and `!is_endpoint(self)` (interior arm) verbatim and satisfy
// both arms for free; the assertion catches a future implementor
// whose override drifts either boundary-membership projection (a
// permissive endpoint override that returns `true` on an interior
// slot — folding a boundary-glyph-emit / audit-event / bounded-
// iteration-guard consumer onto the wrong partition of `T::ALL`
// and silently short-circuiting the strict-interior arm; a
// permissive interior override that returns `true` on an endpoint
// slot — folding a strictly-interior renderer onto the wrong
// partition; a swapped override that returns `is_interior`'s
// answer for `is_endpoint` AND vice-versa, silently inverting the
// (endpoint, interior) partition — passing the exhaustive
// complementarity assertion but drifting from the point-
// membership composition on every variant; a stale override that
// fails the complementarity assertion — returns the SAME `bool`
// for both predicates on some variant, breaking the (endpoint XOR
// interior) partition contract every downstream boundary-vs-
// interior consumer relies on) loudly rather than silently
// bifurcating the boundary-membership projection surface every
// downstream shared-endpoint-badge renderer / boundary-audit-
// event emitter / strictly-interior phase-fold reducer / carousel-
// boundary-glyph consumer routes through. Sibling posture to
// clauses (18) + (30) — clause (18) pins the (head, tail)
// endpoint anchors against `T::ALL[0]` / `T::ALL[T::ALL.len() -
// 1]`, clause (30) pins the (bool head-membership, bool tail-
// membership) projections against the composition of the forward-
// position projection with the const-visible variant count, this
// clause pins the (bool boundary-membership, bool interior-
// membership) partition against the composition of the point-
// membership pair under `||` AND its negation AND pins the
// exhaustive complementarity `is_endpoint XOR is_interior` on
// every variant. Clauses (18) + (30) + (32) together open the
// (predicate-flavor × direction) 2×2 declaration-axis endpoint
// matrix at ALL FOUR direct projection surfaces (`Self`-typed
// anchor / `bool`-typed point membership / `bool`-typed boundary
// membership / `bool`-typed interior membership) AND at BOTH
// endpoint-anchor boundary-fixpoints (`T::first().is_endpoint()`,
// `T::last().is_endpoint()`) AND at BOTH endpoint-anchor
// interior-fixpoints (`T::first().is_interior() == false`,
// `T::last().is_interior() == false`).
for &v in T::ALL {
let expected_endpoint = v.is_first() || v.is_last();
assert_eq!(
v.is_endpoint(),
expected_endpoint,
"{type_name}: {v:?}.is_endpoint() drifted from {v:?}.is_first() || {v:?}.is_last() — the direct (variant → boundary-membership bool) projection no longer agrees with the natural `is_first || is_last` composition, so a downstream shared-endpoint-badge renderer / boundary-audit-event emitter / bounded-iteration guard consumer that binds `v.is_endpoint()` as its structural-boundary query surface would answer the wrong `bool` for {v:?}",
);
assert_eq!(
v.is_interior(),
!expected_endpoint,
"{type_name}: {v:?}.is_interior() drifted from !({v:?}.is_first() || {v:?}.is_last()) — the direct (variant → interior-membership bool) projection no longer agrees with the natural `!is_endpoint` composition, so a downstream strictly-interior phase-fold reducer / strictly-interior alphabetized-completion pass / boundary-hidden renderer consumer that binds `v.is_interior()` as its strict-interior query surface would answer the wrong `bool` for {v:?}",
);
assert_ne!(
v.is_endpoint(),
v.is_interior(),
"{type_name}: {v:?}.is_endpoint() and {v:?}.is_interior() returned the SAME bool — the (endpoint, interior) partition MUST be exhaustive: every variant answers `true` to EXACTLY ONE of the two predicates. A drift here means BOTH predicates fired (a permissive-permissive override pair) OR BOTH predicates rejected (a strict-strict override pair) on {v:?}, breaking the boundary-partition every downstream boundary-vs-interior consumer relies on",
);
}
assert!(
T::first().is_endpoint(),
"{type_name}: T::first().is_endpoint() returned false — the (variant → boundary-membership bool) projection failed to fire on the declaration-order head endpoint anchor while the natural `is_first || is_last` composition should return true. Clauses (18) + (30) + (32) together pin `T::first().is_endpoint() == true` as the structural fixpoint the head-endpoint anchor and the boundary-membership predicate axis share",
);
assert!(
T::last().is_endpoint(),
"{type_name}: T::last().is_endpoint() returned false — the (variant → boundary-membership bool) projection failed to fire on the declaration-order tail endpoint anchor while the natural `is_first || is_last` composition should return true. Clauses (18) + (30) + (32) together pin `T::last().is_endpoint() == true` as the structural fixpoint the tail-endpoint anchor and the boundary-membership predicate axis share, mirroring `T::first().is_endpoint() == true` one direction axis over",
);
assert!(
!T::first().is_interior(),
"{type_name}: T::first().is_interior() returned true — the (variant → interior-membership bool) projection fired on the declaration-order head endpoint anchor while the natural `!is_endpoint` composition should return false. Clauses (18) + (30) + (32) together pin `T::first().is_interior() == false` as the structural anti-fixpoint the head-endpoint anchor and the interior-membership predicate axis share, mirroring `T::first().is_endpoint() == true` one predicate-flavor axis over",
);
assert!(
!T::last().is_interior(),
"{type_name}: T::last().is_interior() returned true — the (variant → interior-membership bool) projection fired on the declaration-order tail endpoint anchor while the natural `!is_endpoint` composition should return false. Clauses (18) + (30) + (32) together pin `T::last().is_interior() == false` as the structural anti-fixpoint the tail-endpoint anchor and the interior-membership predicate axis share, mirroring `T::last().is_endpoint() == true` one predicate-flavor axis over",
);
// (33) — For every variant `v` in `T::ALL`, `v.is_sorted_endpoint()`
// MUST equal `v.is_sorted_first() || v.is_sorted_last()`, AND
// `v.is_sorted_interior()` MUST equal
// `!(v.is_sorted_first() || v.is_sorted_last())`, AND
// `is_sorted_endpoint(v) != is_sorted_interior(v)` (exhaustive
// complementarity), AND `T::sorted_first().is_sorted_endpoint()`
// MUST be `true`, AND `T::sorted_last().is_sorted_endpoint()` MUST
// be `true`, AND `T::sorted_first().is_sorted_interior()` MUST be
// `false`, AND `T::sorted_last().is_sorted_interior()` MUST be
// `false`. The default trait bodies compose
// `is_sorted_first(self) || is_sorted_last(self)` (lex-boundary
// arm) and `!is_sorted_endpoint(self)` (lex-interior arm) verbatim
// and satisfy both arms for free; the assertion catches a future
// implementor whose override drifts either lex-boundary-membership
// projection (a permissive lex-endpoint override that returns
// `true` on a strict-lex-interior slot — folding an alphabetized-
// boundary-glyph-emit / lex-audit-event / bounded-alphabetized-
// iteration-guard consumer onto the wrong partition of `T::ALL`
// and silently short-circuiting the strict-lex-interior arm; a
// permissive lex-interior override that returns `true` on a lex-
// endpoint slot — folding a strictly-lex-interior alphabetized
// renderer onto the wrong partition; a swapped override that
// returns `is_sorted_interior`'s answer for `is_sorted_endpoint`
// AND vice-versa, silently inverting the (lex-endpoint, lex-
// interior) partition — passing the exhaustive complementarity
// assertion but drifting from the lex point-membership composition
// on every variant; a stale override that fails the
// complementarity assertion — returns the SAME `bool` for both
// predicates on some variant, breaking the (lex-endpoint XOR lex-
// interior) partition contract every downstream lex-boundary-vs-
// interior consumer relies on) loudly rather than silently
// bifurcating the lex-boundary-membership projection surface every
// downstream shared-lex-endpoint-badge renderer / lex-boundary-
// audit-event emitter / strictly-lex-interior phase-fold reducer /
// alphabetized-carousel-boundary-glyph consumer routes through.
// Sibling posture to clauses (19) + (31) + (32) — clause (19) pins
// the (lex head, lex tail) endpoint anchors against
// `T::sorted_variants()[0]` / `T::sorted_variants()[T::CARDINALITY
// - 1]`, clause (31) pins the (bool lex-head-membership, bool lex-
// tail-membership) projections against the composition of the lex-
// position projection with the const-visible variant count, clause
// (32) pins the (bool boundary-membership, bool interior-
// membership) partition on the DECLARATION axis, this clause pins
// the (bool lex-boundary-membership, bool lex-interior-membership)
// partition on the LEX axis against the composition of the lex
// point-membership pair under `||` AND its negation AND pins the
// exhaustive complementarity `is_sorted_endpoint XOR
// is_sorted_interior` on every variant. Clauses (19) + (31) + (33)
// together open the (predicate-flavor × direction) 2×2 lex-axis
// endpoint matrix at ALL FOUR direct projection surfaces (`Self`-
// typed lex anchor / `bool`-typed lex point membership / `bool`-
// typed lex boundary membership / `bool`-typed lex interior
// membership) AND at BOTH lex-endpoint-anchor lex-boundary-
// fixpoints (`T::sorted_first().is_sorted_endpoint()`,
// `T::sorted_last().is_sorted_endpoint()`) AND at BOTH lex-
// endpoint-anchor lex-interior-anti-fixpoints
// (`T::sorted_first().is_sorted_interior() == false`,
// `T::sorted_last().is_sorted_interior() == false`). Clauses (32)
// + (33) together CLOSE the (predicate-flavor × ordering) 2×2
// matrix over the boolean-boundary surface — the declaration-axis
// arm ((32)) and the lex-axis arm ((33)) now cover every ordering
// × predicate-flavor corner of the boolean-boundary space.
for &v in T::ALL {
let expected_sorted_endpoint = v.is_sorted_first() || v.is_sorted_last();
assert_eq!(
v.is_sorted_endpoint(),
expected_sorted_endpoint,
"{type_name}: {v:?}.is_sorted_endpoint() drifted from {v:?}.is_sorted_first() || {v:?}.is_sorted_last() — the direct (variant → lex-boundary-membership bool) projection no longer agrees with the natural `is_sorted_first || is_sorted_last` composition, so a downstream shared-lex-endpoint-badge renderer / lex-boundary-audit-event emitter / bounded-alphabetized-iteration-guard consumer that binds `v.is_sorted_endpoint()` as its lex-structural-boundary query surface would answer the wrong `bool` for {v:?}",
);
assert_eq!(
v.is_sorted_interior(),
!expected_sorted_endpoint,
"{type_name}: {v:?}.is_sorted_interior() drifted from !({v:?}.is_sorted_first() || {v:?}.is_sorted_last()) — the direct (variant → lex-interior-membership bool) projection no longer agrees with the natural `!is_sorted_endpoint` composition, so a downstream strictly-lex-interior phase-fold reducer / strictly-lex-interior alphabetized-completion pass / lex-boundary-hidden renderer consumer that binds `v.is_sorted_interior()` as its strict-lex-interior query surface would answer the wrong `bool` for {v:?}",
);
assert_ne!(
v.is_sorted_endpoint(),
v.is_sorted_interior(),
"{type_name}: {v:?}.is_sorted_endpoint() and {v:?}.is_sorted_interior() returned the SAME bool — the (lex-endpoint, lex-interior) partition MUST be exhaustive: every variant answers `true` to EXACTLY ONE of the two predicates. A drift here means BOTH predicates fired (a permissive-permissive override pair) OR BOTH predicates rejected (a strict-strict override pair) on {v:?}, breaking the lex-boundary-partition every downstream lex-boundary-vs-lex-interior consumer relies on",
);
}
assert!(
T::sorted_first().is_sorted_endpoint(),
"{type_name}: T::sorted_first().is_sorted_endpoint() returned false — the (variant → lex-boundary-membership bool) projection failed to fire on the lex-order head endpoint anchor while the natural `is_sorted_first || is_sorted_last` composition should return true. Clauses (19) + (31) + (33) together pin `T::sorted_first().is_sorted_endpoint() == true` as the structural fixpoint the lex-head-endpoint anchor and the lex-boundary-membership predicate axis share, mirroring `T::first().is_endpoint() == true` one ordering axis over",
);
assert!(
T::sorted_last().is_sorted_endpoint(),
"{type_name}: T::sorted_last().is_sorted_endpoint() returned false — the (variant → lex-boundary-membership bool) projection failed to fire on the lex-order tail endpoint anchor while the natural `is_sorted_first || is_sorted_last` composition should return true. Clauses (19) + (31) + (33) together pin `T::sorted_last().is_sorted_endpoint() == true` as the structural fixpoint the lex-tail-endpoint anchor and the lex-boundary-membership predicate axis share, mirroring `T::last().is_endpoint() == true` one ordering axis over and closing the (predicate-flavor × ordering) 2×2 matrix over the boolean-boundary surface",
);
assert!(
!T::sorted_first().is_sorted_interior(),
"{type_name}: T::sorted_first().is_sorted_interior() returned true — the (variant → lex-interior-membership bool) projection fired on the lex-order head endpoint anchor while the natural `!is_sorted_endpoint` composition should return false. Clauses (19) + (31) + (33) together pin `T::sorted_first().is_sorted_interior() == false` as the structural anti-fixpoint the lex-head-endpoint anchor and the lex-interior-membership predicate axis share, mirroring `T::sorted_first().is_sorted_endpoint() == true` one predicate-flavor axis over",
);
assert!(
!T::sorted_last().is_sorted_interior(),
"{type_name}: T::sorted_last().is_sorted_interior() returned true — the (variant → lex-interior-membership bool) projection fired on the lex-order tail endpoint anchor while the natural `!is_sorted_endpoint` composition should return false. Clauses (19) + (31) + (33) together pin `T::sorted_last().is_sorted_interior() == false` as the structural anti-fixpoint the lex-tail-endpoint anchor and the lex-interior-membership predicate axis share, mirroring `T::sorted_last().is_sorted_endpoint() == true` one predicate-flavor axis over",
);
// (34) — `T::endpoints()` MUST equal `(T::first(), T::last())` —
// the pair-aggregation on the declaration-axis endpoint-anchor
// return-shape column projects the two scalar endpoint anchors
// into a single tuple call. The default trait body composes
// `(T::first(), T::last())` verbatim and satisfies the clause for
// free; the assertion catches a future implementor whose override
// drifts the tuple (a swapped override that returns
// `(T::last(), T::first())` — silently inverting the (head, tail)
// tuple-slot semantics every downstream pair-endpoint consumer
// relies on; a stale override that returns a `(T::Head, T::Head)`
// diagonal tuple — silently folding both tuple slots onto the
// head-endpoint anchor and dropping the tail-endpoint from every
// range-walker / boundary-badge / audit-event / per-implementor
// coherence probe consumer; a permissive override that fabricates
// a `(T::Head, T::Interior)` non-endpoint tuple — silently routing
// a strictly-interior slot into the tail-endpoint tuple slot;
// a subset-projection override that returns a `(T::Head, T::Head)`
// singleton-collapse tuple on a `T::CARDINALITY >= 2` closed set
// — silently collapsing the pair-aggregation onto a diagonal at a
// cardinality edge where the two slots should diverge) loudly
// rather than silently bifurcating the pair-aggregation surface
// every downstream boundary-badge renderer / range-walker
// destructure / saga-step audit-event emitter / per-implementor
// coherence probe consumer routes through. Sibling posture to
// clauses (18) + (30) + (32) — clause (18) pins the individual
// (head, tail) scalar endpoint-anchor projections against
// `T::ALL[0]` / `T::ALL[T::CARDINALITY - 1]`, clause (30) pins the
// per-anchor bool membership projections, clause (32) pins the
// boundary-partition boolean projections, this clause pins the
// pair-aggregation tuple projection against the composition of
// the two scalar endpoint-anchor primitives. Clauses (18) + (34)
// together open the (return-shape × declaration-anchor) 3-of-3
// return-shape column (Self scalar head / Self scalar tail /
// (Self, Self) pair) at ALL THREE direct projection surfaces on
// the declaration axis.
assert_eq!(
T::endpoints(),
(T::first(), T::last()),
"{type_name}: T::endpoints() drifted from (T::first(), T::last()) — the direct (declaration-order endpoint pair) tuple projection no longer agrees with the natural `(T::first(), T::last())` two-primitive composition, so a downstream boundary-badge renderer / range-walker destructure / saga-step audit-event emitter / per-implementor coherence probe consumer that binds `T::endpoints()` as its pair-aggregation query surface would answer the wrong tuple",
);
// (35) — `T::sorted_endpoints()` MUST equal
// `(T::sorted_first(), T::sorted_last())` — the pair-aggregation
// on the lex-axis endpoint-anchor return-shape column projects
// the two scalar lex-endpoint anchors into a single tuple call.
// The default trait body composes
// `(T::sorted_first(), T::sorted_last())` verbatim and satisfies
// the clause for free; the assertion catches a future implementor
// whose override drifts the tuple (a swapped override that
// returns `(T::sorted_last(), T::sorted_first())` — silently
// inverting the (lex-head, lex-tail) tuple-slot semantics; a
// stale override that returns a `(T::LexHead, T::LexHead)`
// diagonal tuple on a non-singleton closed set — silently folding
// both lex-tuple slots onto the lex-head-endpoint anchor; a
// permissive override that fabricates a `(T::LexHead, T::Interior)`
// non-lex-endpoint tuple — silently routing a strictly-lex-
// interior slot into the lex-tail-endpoint tuple slot; a
// declaration-axis fold override that returns `(T::first(),
// T::last())` instead of the lex-endpoint tuple — silently
// bifurcating the two ordering axes' pair-aggregations onto the
// SAME tuple, breaking the (declaration, lex) ordering partition
// every downstream lex-boundary-badge renderer / alphabetized-
// range-walker destructure / alphabetized-saga-step audit-event
// emitter / lex-order per-implementor coherence probe consumer
// relies on) loudly rather than silently bifurcating the lex-
// pair-aggregation surface every downstream alphabetized-boundary
// consumer routes through. Sibling posture to clauses (19) + (31)
// + (33) — clause (19) pins the individual (lex-head, lex-tail)
// scalar lex-endpoint-anchor projections against
// `T::sorted_variants()[0]` / `T::sorted_variants()[T::CARDINALITY
// - 1]`, clause (31) pins the per-anchor lex bool membership
// projections, clause (33) pins the lex-boundary-partition
// boolean projections, this clause pins the lex-pair-aggregation
// tuple projection against the composition of the two scalar
// lex-endpoint-anchor primitives. Clauses (34) + (35) together
// CLOSE the (ordering × pair-aggregation) 2×1 matrix over the
// closed-set endpoint-anchor return-shape axis — the declaration-
// axis arm ((34)) and the lex-axis arm ((35)) now cover every
// ordering corner of the pair-return-shape column of the closed-
// set endpoint-anchor matrix, so every generic consumer that
// binds either pair-aggregation surface sees the SAME `(Self,
// Self)` tuple shape at every crate boundary regardless of which
// ordering axis it walks.
assert_eq!(
T::sorted_endpoints(),
(T::sorted_first(), T::sorted_last()),
"{type_name}: T::sorted_endpoints() drifted from (T::sorted_first(), T::sorted_last()) — the direct (lex-order endpoint pair) tuple projection no longer agrees with the natural `(T::sorted_first(), T::sorted_last())` two-primitive composition, so a downstream lex-boundary-badge renderer / alphabetized-range-walker destructure / alphabetized-saga-step audit-event emitter / lex-order per-implementor coherence probe consumer that binds `T::sorted_endpoints()` as its lex-pair-aggregation query surface would answer the wrong tuple",
);
// (36) — `T::endpoint_labels()` MUST equal
// `(T::first().label(), T::last().label())` — the label-pair
// aggregation on the declaration-axis endpoint return-shape column
// projects the two scalar endpoint anchors through per-slot
// `label` projection into a single tuple call. The default trait
// body destructures `T::endpoints()` and labels each tuple slot
// verbatim, satisfying the clause for free; the assertion catches
// a future implementor whose override drifts the label tuple (a
// swapped override that returns
// `(T::last().label(), T::first().label())` — silently inverting
// the (head-label, tail-label) tuple-slot semantics every
// downstream label-boundary-badge renderer / label-range-walker
// destructure / label-saga-step audit-event emitter / per-
// implementor label-coherence probe consumer relies on; a stale
// override that returns a `("head", "head")` diagonal tuple —
// silently folding both label-tuple slots onto the head-anchor
// label; a permissive override that fabricates a `("head", "middle")`
// non-endpoint tuple — silently routing a strictly-interior
// variant's label into the tail-endpoint tuple slot; a fabricated
// override that returns a `("hi", "bye")` payload — silently
// detaching the label pair from the (T::first(), T::last())
// composition) loudly rather than silently bifurcating the
// declaration-axis label-pair-aggregation surface every downstream
// label-boundary-badge / label-range-walker / label-audit-event
// consumer routes through. Sibling posture to clauses (18) + (34) —
// clause (18) pins the (head, tail) scalar endpoint-anchor
// projections, clause (34) pins the (typed variant, typed variant)
// pair-aggregation projection, this clause pins the (label,
// label) pair-aggregation projection against the composition of
// the two scalar endpoint-anchor primitives with the per-slot
// `label` projection. Clauses (34) + (36) together open the
// (return-shape × pair-aggregation) 2×1 label matrix on the
// declaration-order endpoint row at BOTH return-shape corners
// ((Self, Self) tuple / (&'static str, &'static str) tuple).
assert_eq!(
T::endpoint_labels(),
(T::first().label(), T::last().label()),
"{type_name}: T::endpoint_labels() drifted from (T::first().label(), T::last().label()) — the direct (declaration-order endpoint label pair) tuple projection no longer agrees with the natural `(T::first().label(), T::last().label())` composition, so a downstream label-boundary-badge renderer / label-range-walker destructure / label-saga-step audit-event emitter / per-implementor label-coherence probe consumer that binds `T::endpoint_labels()` as its label-pair-aggregation query surface would answer the wrong tuple",
);
// (37) — `T::sorted_endpoint_labels()` MUST equal
// `(T::sorted_first().label(), T::sorted_last().label())` — the
// label-pair aggregation on the lex-axis endpoint return-shape
// column projects the two scalar lex-endpoint anchors through per-
// slot `label` projection into a single tuple call. The default
// trait body destructures `T::sorted_endpoints()` and labels each
// tuple slot verbatim, satisfying the clause for free; the
// assertion catches a future implementor whose override drifts
// the lex-label tuple (a swapped override that returns
// `(T::sorted_last().label(), T::sorted_first().label())` —
// silently inverting the (lex-head-label, lex-tail-label) tuple-
// slot semantics; a stale override that returns a
// `("lex-head", "lex-head")` diagonal tuple on a non-singleton
// closed set — silently folding both lex-label-tuple slots onto
// the lex-head-anchor label; a permissive override that
// fabricates a `("lex-head", "middle")` non-lex-endpoint tuple —
// silently routing a strictly-lex-interior variant's label into
// the lex-tail-endpoint tuple slot; a declaration-axis fold
// override that returns `(T::first().label(), T::last().label())`
// instead of the lex-endpoint label tuple — silently bifurcating
// the two ordering axes' label-pair-aggregations onto the SAME
// tuple, breaking the (declaration, lex) ordering partition every
// downstream lex-label-boundary-badge renderer / alphabetized-
// label-range-walker destructure / alphabetized-label-saga-step
// audit-event emitter consumer relies on) loudly rather than
// silently bifurcating the lex-label-pair-aggregation surface
// every downstream alphabetized-label-boundary consumer routes
// through. Sibling posture to clauses (19) + (35) + (36) — clause
// (19) pins the individual (lex-head, lex-tail) scalar lex-
// endpoint-anchor projections, clause (35) pins the (typed
// variant, typed variant) lex-pair-aggregation projection, clause
// (36) pins the (label, label) declaration-pair-aggregation
// projection, this clause pins the (label, label) lex-pair-
// aggregation projection against the composition of the two
// scalar lex-endpoint-anchor primitives with the per-slot `label`
// projection. Clauses (34) + (35) + (36) + (37) together CLOSE
// the (ordering × pair-return-shape) 2×2 matrix over the closed-
// set endpoint pair-aggregation surface — the declaration-axis
// typed-variant pair ((34)), the lex-axis typed-variant pair
// ((35)), the declaration-axis label pair ((36)), and the lex-
// axis label pair ((37)) now cover every (ordering, pair-return-
// shape) corner of the closed-set endpoint pair-aggregation
// matrix, so every generic consumer that binds any of the four
// pair-aggregation surfaces sees the SAME tuple shape at every
// crate boundary regardless of which ordering axis it walks and
// regardless of whether it materializes the typed variant or the
// label.
assert_eq!(
T::sorted_endpoint_labels(),
(T::sorted_first().label(), T::sorted_last().label()),
"{type_name}: T::sorted_endpoint_labels() drifted from (T::sorted_first().label(), T::sorted_last().label()) — the direct (lex-order endpoint label pair) tuple projection no longer agrees with the natural `(T::sorted_first().label(), T::sorted_last().label())` composition, so a downstream lex-label-boundary-badge renderer / alphabetized-label-range-walker destructure / alphabetized-label-saga-step audit-event emitter / lex-order per-implementor label-coherence probe consumer that binds `T::sorted_endpoint_labels()` as its lex-label-pair-aggregation query surface would answer the wrong tuple",
);
// (38) — `T::interior()` MUST equal
// `T::ALL.iter().copied().filter(T::is_interior).collect()` — the
// declaration-axis strictly-interior collection projects every
// slot for which the boundary-partition predicate
// `T::is_interior` fires, preserving [`T::ALL`]'s declaration
// order verbatim. The default trait body walks `T::ALL` under the
// `is_interior` filter and collects into `Vec<Self>` verbatim,
// satisfying the clause for free; the assertion catches a future
// implementor whose override drifts the interior collection (a
// permissive override that seeds an endpoint anchor into the
// interior slot — silently violating the (boundary, interior)
// partition every downstream interior-range-walker / interior-
// badge / interior-audit-event consumer relies on; a strict
// override that drops a strictly-interior variant from the
// collection — silently truncating the interior partition; a
// subset-projection override that reorders the interior slots
// out of declaration order — silently bifurcating the ordering
// contract every downstream declaration-axis interior consumer
// routes through; a fabricated override that returns a `Vec<Self>`
// built from `T::sorted_variants()` instead of `T::ALL` —
// silently folding the declaration-axis interior projection onto
// the lex-axis interior projection at the ordering-divergent
// implementor edge) loudly rather than silently bifurcating the
// declaration-axis interior-collection surface. Sibling posture
// to clauses (32) + (34) — clause (32) pins the (boundary,
// interior) boolean-partition predicate against the natural
// `!is_endpoint` composition, clause (34) pins the pair-
// aggregation on the boundary arm, this clause pins the vector-
// aggregation on the interior arm against the composition of the
// declaration-order slice and the boundary-partition predicate.
// Clauses (34) + (38) together CLOSE the (partition-flavor ×
// return-shape) 2×1 matrix over the closed-set declaration-axis
// variant-aggregation surface — the boundary arm at
// `(Self, Self)` pair-aggregation ((34)) + the interior arm at
// `Vec<Self>` collection-aggregation ((38)) now cover every
// partition slot in [`T::ALL`] exactly once. Length corollary —
// `T::interior().len() == T::CARDINALITY.saturating_sub(2)` on
// every implementor (0 for the singleton and 2-variant edges;
// `CARDINALITY - 2` otherwise) — is guaranteed by this clause's
// composition through the boundary-partition predicate.
let interior = T::interior();
let natural_interior: Vec<T> = T::ALL
.iter()
.copied()
.filter(|v| T::is_interior(*v))
.collect();
assert_eq!(
interior, natural_interior,
"{type_name}: T::interior() drifted from T::ALL.iter().copied().filter(T::is_interior).collect() — the direct (declaration-order strict-interior collection) `Vec<Self>` projection no longer agrees with the natural composition of `T::ALL` under the boundary-partition predicate, so a downstream interior-range-walker / interior-badge renderer / interior-audit-event emitter / per-implementor interior-coherence probe consumer that binds `T::interior()` as its declaration-axis interior-aggregation query surface would walk the wrong set of slots",
);
for v in &interior {
assert!(
T::is_interior(*v),
"{type_name}: T::interior() carries {v:?} but T::is_interior({v:?}) returned false — the interior-collection surface leaked a boundary variant into the strictly-interior collection, silently violating the (boundary, interior) partition every downstream interior-only consumer relies on",
);
assert!(
!T::is_endpoint(*v),
"{type_name}: T::interior() carries {v:?} but T::is_endpoint({v:?}) returned true — the interior-collection surface leaked a structural endpoint anchor into the strictly-interior collection, silently violating the (boundary, interior) partition every downstream interior-only consumer relies on",
);
}
assert_eq!(
interior.len(),
T::CARDINALITY.saturating_sub(2),
"{type_name}: T::interior().len() ({}) drifted from T::CARDINALITY.saturating_sub(2) ({}) — the interior collection MUST contain exactly `CARDINALITY - 2` slots for a closed set with `CARDINALITY >= 2` and 0 slots at the singleton edge",
interior.len(),
T::CARDINALITY.saturating_sub(2),
);
// (39) — `T::sorted_interior()` MUST equal
// `T::sorted_variants().into_iter().filter(T::is_sorted_interior).collect()`
// — the lex-axis strictly-interior collection projects every slot
// for which the lex-boundary-partition predicate
// `T::is_sorted_interior` fires, preserving
// [`T::sorted_variants`]'s lex order verbatim. The default trait
// body walks `T::sorted_variants()` under the `is_sorted_interior`
// filter and collects into `Vec<Self>` verbatim, satisfying the
// clause for free; the assertion catches a future implementor
// whose override drifts the lex-interior collection (a permissive
// override that seeds a lex-endpoint anchor into the lex-interior
// slot — silently violating the (lex-boundary, lex-interior)
// partition every downstream alphabetized-interior consumer relies
// on; a strict override that drops a strictly-lex-interior variant
// from the collection — silently truncating the lex-interior
// partition; a subset-projection override that reorders the lex-
// interior slots out of lex order — silently bifurcating the
// alphabetized-ordering contract every downstream lex-axis
// interior consumer routes through; a declaration-axis fold
// override that returns `T::interior()` instead of the lex-
// filtered collection — silently bifurcating the two ordering
// axes' interior-aggregations onto the SAME `Vec<Self>` at the
// ordering-divergent implementor edge) loudly rather than
// silently bifurcating the lex-axis interior-collection surface.
// Sibling posture to clauses (33) + (35) + (38) — clause (33)
// pins the (lex-boundary, lex-interior) boolean-partition
// predicate against the natural `!is_sorted_endpoint`
// composition, clause (35) pins the lex-pair-aggregation on the
// lex-boundary arm, clause (38) pins the declaration-axis
// interior-collection, this clause pins the lex-axis interior-
// collection against the composition of the lex-order variant
// sequence and the lex-boundary-partition predicate. Clauses
// (34) + (35) + (38) + (39) together CLOSE the (ordering ×
// partition-flavor) 2×2 matrix over the closed-set boundary +
// interior aggregation surface — the declaration-axis boundary
// pair ((34)), the lex-axis boundary pair ((35)), the declaration-
// axis interior collection ((38)), and the lex-axis interior
// collection ((39)) now cover every (ordering, partition-flavor)
// corner of the closed-set variant-aggregation matrix. Length
// corollary — `T::sorted_interior().len() == T::CARDINALITY.saturating_sub(2)`
// on every implementor — matches [`T::interior`]'s cardinality
// profile one ordering axis over.
let sorted_interior = T::sorted_interior();
let natural_sorted_interior: Vec<T> = T::sorted_variants()
.into_iter()
.filter(|v| T::is_sorted_interior(*v))
.collect();
assert_eq!(
sorted_interior, natural_sorted_interior,
"{type_name}: T::sorted_interior() drifted from T::sorted_variants().into_iter().filter(T::is_sorted_interior).collect() — the direct (lex-order strict-interior collection) `Vec<Self>` projection no longer agrees with the natural composition of `T::sorted_variants` under the lex-boundary-partition predicate, so a downstream alphabetized-interior-range-walker / lex-interior-badge renderer / alphabetized-interior-audit-event emitter / per-implementor lex-interior-coherence probe consumer that binds `T::sorted_interior()` as its lex-axis interior-aggregation query surface would walk the wrong set of slots",
);
for v in &sorted_interior {
assert!(
T::is_sorted_interior(*v),
"{type_name}: T::sorted_interior() carries {v:?} but T::is_sorted_interior({v:?}) returned false — the lex-interior-collection surface leaked a lex-boundary variant into the strictly-lex-interior collection, silently violating the (lex-boundary, lex-interior) partition every downstream lex-interior-only consumer relies on",
);
assert!(
!T::is_sorted_endpoint(*v),
"{type_name}: T::sorted_interior() carries {v:?} but T::is_sorted_endpoint({v:?}) returned true — the lex-interior-collection surface leaked a lex-endpoint anchor into the strictly-lex-interior collection, silently violating the (lex-boundary, lex-interior) partition every downstream lex-interior-only consumer relies on",
);
}
assert_eq!(
sorted_interior.len(),
T::CARDINALITY.saturating_sub(2),
"{type_name}: T::sorted_interior().len() ({}) drifted from T::CARDINALITY.saturating_sub(2) ({}) — the lex-interior collection MUST contain exactly `CARDINALITY - 2` slots for a closed set with `CARDINALITY >= 2` and 0 slots at the singleton edge",
sorted_interior.len(),
T::CARDINALITY.saturating_sub(2),
);
// (40) — `T::interior_labels()` MUST equal
// `T::interior().into_iter().map(T::label).collect()` — the
// declaration-axis strictly-interior LABEL collection projects
// every label of every strictly-interior slot in `T::interior()`,
// preserving the underlying declaration order verbatim. The
// default trait body maps `T::interior()` under `T::label` and
// collects into `Vec<&'static str>` verbatim, satisfying the
// clause for free; the assertion catches a future implementor
// whose override drifts the interior-label collection (a
// permissive override that seeds an endpoint anchor's label into
// the interior-label slot — silently violating the (boundary,
// interior) label partition every downstream declaration-axis
// interior-label consumer relies on; a strict override that
// drops a strictly-interior slot's label from the collection —
// silently truncating the interior-label partition; a subset-
// projection override that reorders the interior-label slots out
// of declaration order — silently bifurcating the ordering
// contract every downstream declaration-axis interior-label
// consumer routes through; a fabricated override that returns a
// `Vec<&'static str>` built from `T::sorted_interior_labels()`
// instead of `T::interior_labels()` — silently folding the
// declaration-axis interior-label projection onto the lex-axis
// interior-label projection at the ordering-divergent implementor
// edge) loudly rather than silently bifurcating the declaration-
// axis interior-label-collection surface. Sibling posture to
// clauses (36) + (38) — clause (36) pins the (declaration-axis)
// label-pair aggregation on the boundary arm, clause (38) pins
// the (declaration-axis) variant collection on the interior arm,
// this clause pins the (declaration-axis) label collection on the
// interior arm against the composition of the declaration-axis
// interior-collection primitive and the per-slot label
// projection. Clauses (36) + (37) + (40) + (41) together CLOSE
// the (partition-flavor × ordering) 2×2 matrix over the closed-
// set LABEL aggregation surface — the boundary arm at
// `(&'static str, &'static str)` pair-aggregation ((36) + (37))
// + the interior arm at `Vec<&'static str>` collection-
// aggregation ((40) + (41)) now cover every (partition-flavor,
// ordering) corner of the closed-set label-aggregation matrix.
// Length corollary —
// `T::interior_labels().len() == T::CARDINALITY.saturating_sub(2)`
// on every implementor (0 for the singleton and 2-variant edges;
// `CARDINALITY - 2` otherwise) — is guaranteed by this clause's
// composition through the declaration-axis interior-collection
// primitive.
let interior_labels = T::interior_labels();
let natural_interior_labels: Vec<&'static str> =
T::interior().into_iter().map(T::label).collect();
assert_eq!(
interior_labels, natural_interior_labels,
"{type_name}: T::interior_labels() drifted from T::interior().into_iter().map(T::label).collect() — the direct (declaration-order strict-interior label collection) `Vec<&'static str>` projection no longer agrees with the natural composition of `T::interior` under the per-slot `T::label` projection, so a downstream interior-label-badge renderer / interior-label-audit-event emitter / per-implementor interior-label-coherence probe consumer that binds `T::interior_labels()` as its declaration-axis interior-label-aggregation query surface would render the wrong set of labels",
);
for label in &interior_labels {
assert!(
T::interior().into_iter().any(|v| T::label(v) == *label),
"{type_name}: T::interior_labels() carries {label:?} but no strictly-interior variant projects onto that label — the interior-label collection surface leaked a boundary anchor's label (or fabricated a non-canonical label) into the strictly-interior label collection, silently violating the (boundary, interior) label partition every downstream interior-label-only consumer relies on",
);
}
assert_eq!(
interior_labels.len(),
T::CARDINALITY.saturating_sub(2),
"{type_name}: T::interior_labels().len() ({}) drifted from T::CARDINALITY.saturating_sub(2) ({}) — the interior-label collection MUST contain exactly `CARDINALITY - 2` labels for a closed set with `CARDINALITY >= 2` and 0 labels at the singleton edge",
interior_labels.len(),
T::CARDINALITY.saturating_sub(2),
);
// (41) — `T::sorted_interior_labels()` MUST equal
// `T::sorted_interior().into_iter().map(T::label).collect()` —
// the lex-axis strictly-interior LABEL collection projects every
// label of every strictly-lex-interior slot in
// `T::sorted_interior()`, preserving the underlying lex order
// verbatim. The default trait body maps `T::sorted_interior()`
// under `T::label` and collects into `Vec<&'static str>` verbatim,
// satisfying the clause for free; the assertion catches a future
// implementor whose override drifts the lex-interior-label
// collection (a permissive override that seeds a lex-endpoint
// anchor's label into the lex-interior-label slot — silently
// violating the (lex-boundary, lex-interior) label partition
// every downstream alphabetized-interior-label consumer relies
// on; a strict override that drops a strictly-lex-interior slot's
// label from the collection — silently truncating the lex-
// interior-label partition; a subset-projection override that
// reorders the lex-interior-label slots out of lex order —
// silently bifurcating the alphabetized-ordering contract every
// downstream lex-axis interior-label consumer routes through; a
// declaration-axis fold override that returns
// `T::interior_labels()` instead of the lex-filtered label
// collection — silently bifurcating the two ordering axes'
// interior-label-aggregations onto the SAME `Vec<&'static str>`
// at the ordering-divergent implementor edge) loudly rather than
// silently bifurcating the lex-axis interior-label-collection
// surface. Sibling posture to clauses (37) + (39) + (40) —
// clause (37) pins the (lex-axis) label-pair aggregation on the
// lex-boundary arm, clause (39) pins the (lex-axis) variant
// collection on the lex-interior arm, clause (40) pins the
// (declaration-axis) label collection on the interior arm, this
// clause pins the (lex-axis) label collection on the lex-
// interior arm against the composition of the lex-axis interior-
// collection primitive and the per-slot label projection.
// Clauses (34) + (35) + (36) + (37) + (38) + (39) + (40) + (41)
// together CLOSE the (partition-flavor × ordering × return-shape)
// 2×2×2 cube over the closed-set boundary + interior
// aggregation surface — the declaration-axis boundary pair ((34)
// + (36)), the lex-axis boundary pair ((35) + (37)), the
// declaration-axis interior collection ((38) + (40)), and the
// lex-axis interior collection ((39) + (41)) now cover every
// (partition-flavor, ordering, return-shape) corner of the
// closed-set variant-aggregation cube at both the typed-variant
// return-shape column and the label return-shape column. Length
// corollary —
// `T::sorted_interior_labels().len() == T::CARDINALITY.saturating_sub(2)`
// on every implementor — matches [`T::interior_labels`]'s
// cardinality profile one ordering axis over.
let sorted_interior_labels = T::sorted_interior_labels();
let natural_sorted_interior_labels: Vec<&'static str> =
T::sorted_interior().into_iter().map(T::label).collect();
assert_eq!(
sorted_interior_labels, natural_sorted_interior_labels,
"{type_name}: T::sorted_interior_labels() drifted from T::sorted_interior().into_iter().map(T::label).collect() — the direct (lex-order strict-interior label collection) `Vec<&'static str>` projection no longer agrees with the natural composition of `T::sorted_interior` under the per-slot `T::label` projection, so a downstream alphabetized-interior-label-badge renderer / alphabetized-interior-label-audit-event emitter / per-implementor lex-interior-label-coherence probe consumer that binds `T::sorted_interior_labels()` as its lex-axis interior-label-aggregation query surface would render the wrong set of labels",
);
for label in &sorted_interior_labels {
assert!(
T::sorted_interior().into_iter().any(|v| T::label(v) == *label),
"{type_name}: T::sorted_interior_labels() carries {label:?} but no strictly-lex-interior variant projects onto that label — the lex-interior-label collection surface leaked a lex-boundary anchor's label (or fabricated a non-canonical label) into the strictly-lex-interior label collection, silently violating the (lex-boundary, lex-interior) label partition every downstream lex-interior-label-only consumer relies on",
);
}
assert_eq!(
sorted_interior_labels.len(),
T::CARDINALITY.saturating_sub(2),
"{type_name}: T::sorted_interior_labels().len() ({}) drifted from T::CARDINALITY.saturating_sub(2) ({}) — the lex-interior-label collection MUST contain exactly `CARDINALITY - 2` labels for a closed set with `CARDINALITY >= 2` and 0 labels at the singleton edge",
sorted_interior_labels.len(),
T::CARDINALITY.saturating_sub(2),
);
// (42) — `T::interior_labels_joined(sep)` MUST compose
// `T::interior_labels()` with `slice::join` verbatim across every
// representative separator. The default trait body satisfies the
// clause for free; the assertion catches a future implementor
// whose override drifts the composition (a permissive override
// that leaks a boundary anchor's label into the joined output —
// silently violating the (boundary, interior) label partition
// every downstream declaration-axis interior-label-as-string
// consumer relies on; a strict override that drops a strictly-
// interior slot's label from the joined output — silently
// truncating the interior-label-as-string partition; a fabricated
// override that ignores the caller-supplied separator or threads
// a different separator; a fold override that returns
// `T::sorted_interior_labels_joined(sep)` instead of the
// declaration-axis rendering — silently bifurcating the two
// ordering axes' interior-label-as-string surfaces onto the SAME
// `String` at the ordering-divergent implementor edge) loudly
// rather than silently bifurcating the declaration-axis interior-
// label-as-string surface. Sweep three representative separators
// (slash for interior-only production constants, comma-space for
// natural-language `middle kinds: ...` shapes, pipe for grammar-
// style alternative lists) so an isolated drift on any of the
// three natural rendering surfaces fails the testkit on every
// implementor. Sibling posture to clauses (8) + (40) — clause
// (8) pins the (full-set × declaration × String) label-as-string
// shape, clause (40) pins the (interior × declaration × Vec)
// label collection, this clause pins the (interior × declaration
// × String) label-as-string shape against the composition of the
// declaration-axis interior-label-collection primitive and the
// caller-supplied separator through `slice::join`.
for sep in ["/", ", ", "|"] {
let lifted = T::interior_labels_joined(sep);
let natural = T::interior_labels().join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::interior_labels_joined({sep:?}) drifted from T::interior_labels().join({sep:?}) — the declaration-axis interior-labels-as-string rendering every diagnostic / metrics consumer routes through no longer matches the natural interior-labels-then-join composition",
);
}
// (43) — `T::sorted_interior_labels_joined(sep)` MUST compose
// `T::sorted_interior_labels()` with `slice::join` verbatim
// across every representative separator. The default trait body
// satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a permissive
// override that leaks a lex-boundary anchor's label into the
// joined output; a strict override that drops a strictly-lex-
// interior slot's label; a fabricated override that ignores the
// caller-supplied separator; a declaration-axis fold override
// that returns `T::interior_labels_joined(sep)` instead of the
// lex-filtered rendering — silently bifurcating the two ordering
// axes' interior-label-as-string surfaces onto the SAME `String`
// at the ordering-divergent implementor edge) loudly rather than
// silently bifurcating the lex-axis interior-label-as-string
// surface. Sweep the same three representative separators clause
// (42) uses (`"/"`, `", "`, `"|"`) so an isolated drift on any of
// the three natural alphabetized rendering surfaces (slash for
// ordering-independent interior-only production constants,
// comma-space for natural-language alphabetized `middle kinds:
// ...` shapes, pipe for grammar-style alphabetized alternative
// lists) fails the testkit on every implementor. Sibling posture
// to clauses (10) + (41) — clause (10) pins the (full-set × lex ×
// String) alphabetized label-as-string shape, clause (41) pins
// the (interior × lex × Vec) lex-interior label collection, this
// clause pins the (interior × lex × String) alphabetized label-
// as-string shape against the composition of the lex-axis
// interior-label-collection primitive and the caller-supplied
// separator through `slice::join`. Clauses (8) + (10) + (40) +
// (41) + (42) + (43) together CLOSE the (partition-flavor ×
// ordering × return-shape) 2×2×2 cube over the closed-set
// label-aggregation surface at BOTH the `Vec<&'static str>`
// return-shape column ((40) + (41)) AND the `String` return-shape
// column ((42) + (43)) on the interior arm, mirroring clauses
// (8) + (10) on the full-set arm.
for sep in ["/", ", ", "|"] {
let lifted = T::sorted_interior_labels_joined(sep);
let natural = T::sorted_interior_labels().join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::sorted_interior_labels_joined({sep:?}) drifted from T::sorted_interior_labels().join({sep:?}) — the lex-axis alphabetized interior-labels-as-string rendering every diagnostic / metrics consumer routes through no longer matches the natural sorted-interior-labels-then-join composition",
);
}
// (44) — `T::endpoint_labels_joined(sep)` MUST compose
// `T::endpoint_labels()` with `slice::join` verbatim across every
// representative separator. The default trait body destructures
// the declaration-axis endpoint-label pair and joins the two-
// element slice under the caller-supplied separator, satisfying
// the clause for free; the assertion catches a future implementor
// whose override drifts the composition (a permissive override
// that leaks a strictly-interior label into the joined output —
// silently violating the (boundary, interior) label partition
// every downstream declaration-axis endpoint-label-as-string
// consumer relies on; a swapped override that inverts the
// (head-label, tail-label) tuple-slot ordering in the joined
// rendering — silently bifurcating the declaration-axis
// endpoint-anchor semantics every downstream boundary-badge /
// boundary-diagnostic / boundary-audit-event consumer routes
// through; a fabricated override that ignores the caller-supplied
// separator or threads a different separator; a fold override
// that returns `T::sorted_endpoint_labels_joined(sep)` instead of
// the declaration-axis rendering — silently bifurcating the two
// ordering axes' endpoint-label-as-string surfaces onto the SAME
// `String` at the ordering-divergent implementor edge) loudly
// rather than silently bifurcating the declaration-axis endpoint-
// label-as-string surface. Sweep three representative separators
// (slash for boundary-only production constants, comma-space for
// natural-language `boundary: ...` shapes, pipe for grammar-style
// alternative lists) matching clauses (8) + (42)'s sweep so an
// isolated drift on any of the three natural rendering surfaces
// fails the testkit on every implementor. Sibling posture to
// clauses (8) + (36) + (42) — clause (8) pins the (full-set ×
// declaration × String) label-as-string shape, clause (36) pins
// the (endpoint × declaration × pair-tuple) label-pair shape,
// clause (42) pins the (interior × declaration × String) label-
// as-string shape, this clause pins the (endpoint × declaration ×
// String) label-as-string shape against the composition of the
// declaration-axis endpoint-label-pair primitive and the caller-
// supplied separator through `slice::join`.
for sep in ["/", ", ", "|"] {
let lifted = T::endpoint_labels_joined(sep);
let (head, tail) = T::endpoint_labels();
let natural = [head, tail].join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::endpoint_labels_joined({sep:?}) drifted from [T::endpoint_labels().0, T::endpoint_labels().1].join({sep:?}) — the declaration-axis endpoint-labels-as-string rendering every boundary-badge / boundary-diagnostic / boundary-audit-event consumer routes through no longer matches the natural endpoint-labels-then-join composition",
);
}
// (45) — `T::sorted_endpoint_labels_joined(sep)` MUST compose
// `T::sorted_endpoint_labels()` with `slice::join` verbatim
// across every representative separator. The default trait body
// satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a permissive
// override that leaks a strictly-lex-interior label into the
// joined output; a swapped override that inverts the (lex-head-
// label, lex-tail-label) tuple-slot ordering; a fabricated
// override that ignores the caller-supplied separator; a
// declaration-axis fold override that returns
// `T::endpoint_labels_joined(sep)` instead of the lex-axis
// rendering — silently bifurcating the two ordering axes'
// endpoint-label-as-string surfaces onto the SAME `String` at the
// ordering-divergent implementor edge) loudly rather than
// silently bifurcating the lex-axis endpoint-label-as-string
// surface. Sweep the same three representative separators clause
// (44) uses (`"/"`, `", "`, `"|"`) so an isolated drift on any of
// the three natural alphabetized rendering surfaces (slash for
// ordering-independent boundary-only production constants,
// comma-space for natural-language alphabetized `boundary: ...`
// shapes, pipe for grammar-style alphabetized alternative lists)
// fails the testkit on every implementor. Sibling posture to
// clauses (10) + (37) + (43) + (44) — clause (10) pins the
// (full-set × lex × String) alphabetized label-as-string shape,
// clause (37) pins the (endpoint × lex × pair-tuple) lex-label-
// pair shape, clause (43) pins the (interior × lex × String)
// alphabetized label-as-string shape, clause (44) pins the
// (endpoint × declaration × String) declaration-endpoint-label-
// as-string shape, this clause pins the (endpoint × lex ×
// String) alphabetized-endpoint-label-as-string shape against
// the composition of the lex-axis endpoint-label-pair primitive
// and the caller-supplied separator through `slice::join`.
// Clauses (8) + (10) + (36) + (37) + (40) + (41) + (42) + (43) +
// (44) + (45) together CLOSE the (partition-flavor × ordering ×
// return-shape) cube over the closed-set LABEL-aggregation
// surface at EVERY (full-set/interior/endpoint × declaration/lex
// × Vec/String/pair-tuple) corner — the (endpoint × ordering ×
// String) corner (this clause + clause (44)) mirrors the
// (interior × ordering × String) corner (clauses (42) + (43))
// one partition-flavor axis over on the (interior, endpoint)
// partition of the boundary axis, closing the joined-`String`
// return-shape column on the endpoint arm.
for sep in ["/", ", ", "|"] {
let lifted = T::sorted_endpoint_labels_joined(sep);
let (head, tail) = T::sorted_endpoint_labels();
let natural = [head, tail].join(sep);
assert_eq!(
lifted, natural,
"{type_name}: T::sorted_endpoint_labels_joined({sep:?}) drifted from [T::sorted_endpoint_labels().0, T::sorted_endpoint_labels().1].join({sep:?}) — the lex-axis alphabetized endpoint-labels-as-string rendering every alphabetized-boundary-badge / alphabetized-boundary-diagnostic / alphabetized-boundary-audit-event consumer routes through no longer matches the natural sorted-endpoint-labels-then-join composition",
);
}
// (46) — `T::first_label()` MUST equal `T::first().label()` — the
// singular head-endpoint label projection on the declaration-axis
// endpoint-label return-shape column composes the (declaration
// head anchor) primitive with the (per-slot label) projection. The
// default trait body composes `T::label(T::first())` verbatim and
// satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the head-label projection (a
// stale override that hard-codes a literal `&'static str` detached
// from [`Self::label`] — silently forking the head-anchor
// rendering from the label-projection primitive every downstream
// head-label consumer routes through; a permissive override that
// returns a strictly-interior variant's label — silently routing
// an interior slot into the head-endpoint-label projection; a fold
// override that returns `T::last().label()` — silently swapping
// the head-endpoint label onto the tail-endpoint label; an
// override that returns [`Self::endpoint_labels`]'s slot-1
// instead of slot-0 — silently bifurcating the singular head-
// label projection with the pair-tuple's tail-label slot; a
// fabricated override that returns the empty string — silently
// detaching the head-label rendering from every canonical label
// in [`T::ALL`]) loudly rather than silently bifurcating the
// singular head-endpoint-label projection surface every downstream
// head-label consumer routes through. Sibling posture to clauses
// (18) + (34) + (36) — clause (18) pins the individual (head,
// tail) scalar endpoint-anchor projections against `T::ALL[0]` /
// `T::ALL[T::CARDINALITY - 1]`, clause (34) pins the (typed
// variant, typed variant) pair-aggregation projection, clause (36)
// pins the (label, label) pair-aggregation projection, this
// clause pins the singular `&'static str` head-label projection
// against the composition of the scalar head-endpoint-anchor
// primitive with the per-slot label projection. Clauses (18) +
// (36) + (46) together open the (return-type × aggregation-shape)
// 2×2 matrix over the declaration-axis head-endpoint anchor's
// return-shape column at THREE of the four corners (typed-variant
// singular / (typed-variant, typed-variant) pair-tuple / label
// singular); the fourth corner is the (label, label) pair-tuple
// arm covered by clause (36) on the head-slot column.
assert_eq!(
T::first_label(),
T::first().label(),
"{type_name}: T::first_label() drifted from T::first().label() — the singular declaration-order head-endpoint label projection no longer agrees with the natural `T::first().label()` two-primitive composition, so a downstream head-label banner / head-label completion / head-label coherence probe consumer that binds `T::first_label()` as its singular head-anchor label query surface would render the wrong `&'static str`",
);
// (47) — `T::last_label()` MUST equal `T::last().label()` — the
// singular tail-endpoint label projection on the declaration-axis
// endpoint-label return-shape column composes the (declaration
// tail anchor) primitive with the (per-slot label) projection. The
// default trait body composes `T::label(T::last())` verbatim and
// satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the tail-label projection (a
// stale override that hard-codes a literal `&'static str` detached
// from [`Self::label`]; a permissive override that returns a
// strictly-interior variant's label — silently routing an interior
// slot into the tail-endpoint-label projection; a fold override
// that returns `T::first().label()` — silently swapping the tail-
// endpoint label onto the head-endpoint label; an override that
// returns [`Self::endpoint_labels`]'s slot-0 instead of slot-1 —
// silently bifurcating the singular tail-label projection with the
// pair-tuple's head-label slot; a fabricated override that returns
// the empty string) loudly rather than silently bifurcating the
// singular tail-endpoint-label projection surface every downstream
// tail-label consumer routes through. Sibling posture to clause
// (46) one endpoint-direction axis over on the (head, tail)
// partition of the declaration-axis singular endpoint-label
// return-shape column. Clauses (18) + (34) + (36) + (46) + (47)
// together CLOSE the (return-type × endpoint-direction ×
// aggregation-shape) 2×2×2 = 8-corner projection cube on the
// declaration-axis endpoint-anchor return-shape surface: (`Self`,
// head/tail, singular) at clauses (18); ((`Self`, `Self`), (head,
// tail), pair) at clause (34); ((`&'static str`, `&'static str`),
// (head, tail), pair) at clause (36); and (`&'static str`,
// head/tail, singular) at clauses (46) + (47). Every generic
// consumer that binds any of the six declaration-axis projection
// methods sees the SAME endpoint-anchor answer at every crate
// boundary regardless of which return-type axis / endpoint-
// direction / aggregation-shape corner it walks.
assert_eq!(
T::last_label(),
T::last().label(),
"{type_name}: T::last_label() drifted from T::last().label() — the singular declaration-order tail-endpoint label projection no longer agrees with the natural `T::last().label()` two-primitive composition, so a downstream tail-label banner / tail-label completion / tail-label coherence probe consumer that binds `T::last_label()` as its singular tail-anchor label query surface would render the wrong `&'static str`",
);
// (48) — `T::sorted_first_label()` MUST equal
// `T::sorted_first().label()` — the singular lex-head-endpoint
// label projection on the lex-axis endpoint-label return-shape
// column composes the (lex head anchor) primitive with the
// (per-slot label) projection. The default trait body composes
// `T::label(T::sorted_first())` verbatim and satisfies the clause
// for free; the assertion catches a future implementor whose
// override drifts the lex-head-label projection (a stale override
// that hard-codes a literal `&'static str` detached from
// [`Self::label`] — silently forking the lex-head-anchor rendering
// from the label-projection primitive every downstream lex-head-
// label consumer routes through; a permissive override that
// returns a strictly-lex-interior variant's label — silently
// routing an interior slot into the lex-head-endpoint-label
// projection; a fold override that returns
// `T::sorted_last().label()` — silently swapping the lex-head-
// endpoint label onto the lex-tail-endpoint label; a stale
// override that folds `T::sorted_first_label()` onto
// `T::first_label()` — silently bifurcating the (declaration, lex)
// ordering axis at the singular head-endpoint-label return-shape
// slot on any implementor whose declaration order diverges from
// its lex order; an override that returns
// [`Self::sorted_endpoint_labels`]'s slot-1 instead of slot-0 —
// silently bifurcating the singular lex-head-label projection
// with the pair-tuple's lex-tail-label slot; a fabricated override
// that returns the empty string — silently detaching the lex-
// head-label rendering from every canonical label in [`T::ALL`])
// loudly rather than silently bifurcating the singular lex-head-
// endpoint-label projection surface every downstream lex-head-
// label consumer routes through. Sibling posture to clauses
// (18) + (34) + (36) + (37) + (46) — clause (18) pins the
// individual (declaration head, declaration tail) scalar endpoint-
// anchor projections against `T::ALL[0]` /
// `T::ALL[T::CARDINALITY - 1]`, clause (34) pins the (typed
// variant, typed variant) pair-aggregation projection on the
// declaration axis, clause (36) pins the (label, label) pair-
// aggregation projection on the declaration axis, clause (37)
// pins the (label, label) pair-aggregation projection on the lex
// axis, clause (46) pins the singular `&'static str` head-label
// projection against the composition of the declaration head-
// endpoint-anchor primitive with the per-slot label projection,
// this clause pins the singular `&'static str` lex-head-label
// projection against the composition of the lex head-endpoint-
// anchor primitive with the per-slot label projection. Clauses
// (36) + (37) + (46) + (48) together open the (ordering ×
// aggregation-shape) 2×2 matrix over the head-endpoint anchor's
// label return-shape column at ALL FOUR corners.
assert_eq!(
T::sorted_first_label(),
T::sorted_first().label(),
"{type_name}: T::sorted_first_label() drifted from T::sorted_first().label() — the singular lex-order head-endpoint label projection no longer agrees with the natural `T::sorted_first().label()` two-primitive composition, so a downstream lex-head-label banner / alphabetized-completion cursor / lex-head-label coherence probe consumer that binds `T::sorted_first_label()` as its singular lex-head-anchor label query surface would render the wrong `&'static str`",
);
// (49) — `T::sorted_last_label()` MUST equal
// `T::sorted_last().label()` — the singular lex-tail-endpoint
// label projection on the lex-axis endpoint-label return-shape
// column composes the (lex tail anchor) primitive with the
// (per-slot label) projection. The default trait body composes
// `T::label(T::sorted_last())` verbatim and satisfies the clause
// for free; the assertion catches a future implementor whose
// override drifts the lex-tail-label projection (a stale override
// that hard-codes a literal `&'static str` detached from
// [`Self::label`]; a permissive override that returns a strictly-
// lex-interior variant's label — silently routing an interior
// slot into the lex-tail-endpoint-label projection; a fold
// override that returns `T::sorted_first().label()` — silently
// swapping the lex-tail-endpoint label onto the lex-head-endpoint
// label; a stale override that folds `T::sorted_last_label()`
// onto `T::last_label()` — silently bifurcating the (declaration,
// lex) ordering axis at the singular tail-endpoint-label return-
// shape slot on any implementor whose declaration order diverges
// from its lex order; an override that returns
// [`Self::sorted_endpoint_labels`]'s slot-0 instead of slot-1 —
// silently bifurcating the singular lex-tail-label projection with
// the pair-tuple's lex-head-label slot; a fabricated override
// that returns the empty string) loudly rather than silently
// bifurcating the singular lex-tail-endpoint-label projection
// surface every downstream lex-tail-label consumer routes through.
// Sibling posture to clause (48) one endpoint-direction axis over
// on the (head, tail) partition of the lex-axis singular
// endpoint-label return-shape column. Clauses (18) + (19) + (34) +
// (35) + (36) + (37) + (46) + (47) + (48) + (49) together CLOSE
// the (return-type × ordering × endpoint-direction × aggregation-
// shape) 2×2×2×2 = 16-corner projection hypercube on the closed-
// set endpoint-anchor return-shape surface: (`Self`, ordering ×
// head/tail, singular) at clauses (18) + (19); ((`Self`, `Self`),
// ordering × (head, tail), pair) at clauses (34) + (35); ((label,
// label), ordering × (head, tail), pair) at clauses (36) + (37);
// and (`&'static str`, ordering × head/tail, singular) at
// clauses (46) + (47) + (48) + (49). Every generic consumer that
// binds any of the twelve declaration-axis-or-lex-axis projection
// methods sees the SAME endpoint-anchor answer at every crate
// boundary regardless of which return-type axis / ordering-axis /
// endpoint-direction / aggregation-shape corner it walks.
assert_eq!(
T::sorted_last_label(),
T::sorted_last().label(),
"{type_name}: T::sorted_last_label() drifted from T::sorted_last().label() — the singular lex-order tail-endpoint label projection no longer agrees with the natural `T::sorted_last().label()` two-primitive composition, so a downstream lex-tail-label banner / alphabetized-completion cursor / lex-tail-label coherence probe consumer that binds `T::sorted_last_label()` as its singular lex-tail-anchor label query surface would render the wrong `&'static str`",
);
// (50) — `T::is_first_label(s)` MUST equal `s == T::first_label()`
// on every representative input: every canonical variant label
// matches iff the variant is the declaration-order head anchor,
// the reserved probe rejects (`false`), and the empty-string
// boundary rejects (`false`). The default trait body composes
// `s == <T as ClosedSet>::first_label()` verbatim and satisfies
// the clause for free; the assertion catches a future implementor
// whose override drifts the composition (a permissive override
// that returns `true` for a non-head label — silently routing a
// strictly-interior variant's label into the label-shaped head-
// membership predicate; a strict override that returns `false`
// for the canonical head label — silently detaching the label-
// shaped head-membership predicate from the natural
// `s == T::first_label()` composition every downstream label-
// shaped head-boundary consumer routes through; a fold override
// that answers "is this the tail label?" instead — silently
// swapping the head-direction predicate onto the tail-direction
// predicate at the (head, tail) endpoint-direction axis; an
// override that always returns `true` for non-empty inputs —
// silently collapsing the label-shaped head-membership onto a
// trivial non-empty predicate; a fabricated override that
// returns `true` on the empty-string boundary — silently
// detaching the label-shaped head-membership from the non-empty
// canonical-label surface clause (4) pins) loudly rather than
// silently bifurcating the label-shaped head-membership surface
// every downstream label-shaped head-boundary consumer routes
// through. Sibling posture to clauses (30) + (46) — clause (30)
// pins the `Self`-arg head-membership predicate against the
// natural `self.index_of() == 0` composition, clause (46) pins
// the singular head-endpoint label projection against
// `T::first().label()`, this clause pins the `&str`-arg head-
// membership predicate against the natural `s == T::first_label()`
// composition. Clauses (30) + (50) together open the (arg-type,
// head) column of the (arg-type × endpoint-direction) 2×2 = 4-
// corner declaration-axis endpoint-membership matrix at the head
// arm on BOTH arg-type axes.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_first_label(label);
let natural = label == T::first_label();
assert_eq!(
lifted, natural,
"{type_name}: T::is_first_label({label:?}) drifted from `{label:?} == T::first_label()` — the label-shaped head-endpoint membership predicate no longer agrees with the natural `s == T::first_label()` one-primitive composition on the canonical label of variant {v:?}, so a downstream streaming Lisp reader / CLI subcommand dispatcher / anchored-diagnostic renderer that binds `T::is_first_label(s)` as its zero-alloc label-shaped head-anchor query surface would answer the wrong `bool`",
);
}
assert!(
!T::is_first_label(probe),
"{type_name}: T::is_first_label({probe:?}) returned true on the reserved probe input — the label-shaped head-endpoint membership predicate MUST reject every input outside the closed set's canonical labeling; the probe is by construction distinct from every canonical label AND from every substrate-produced label, so a `true` answer here silently permits inputs beyond the closed set into the label-shaped head-boundary surface",
);
assert!(
!T::is_first_label(""),
"{type_name}: T::is_first_label(\"\") returned true on the empty-string boundary — the label-shaped head-endpoint membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling, so a `true` answer here silently permits the empty-string boundary into the label-shaped head-boundary surface",
);
// (51) — `T::is_last_label(s)` MUST equal `s == T::last_label()`
// on every representative input: every canonical variant label
// matches iff the variant is the declaration-order tail anchor,
// the reserved probe rejects (`false`), and the empty-string
// boundary rejects (`false`). The default trait body composes
// `s == <T as ClosedSet>::last_label()` verbatim and satisfies
// the clause for free; the assertion catches a future implementor
// whose override drifts the composition (a permissive override
// that returns `true` for a non-tail label; a strict override
// that returns `false` for the canonical tail label; a fold
// override that answers "is this the head label?" instead —
// silently swapping the tail-direction predicate onto the head-
// direction predicate at the (head, tail) endpoint-direction axis;
// an override that always returns `true` for non-empty inputs; a
// fabricated override that returns `true` on the empty-string
// boundary) loudly rather than silently bifurcating the label-
// shaped tail-membership surface every downstream label-shaped
// tail-boundary consumer routes through. Sibling posture to
// clause (50) one endpoint-direction axis over on the (head, tail)
// partition of the declaration-axis label-shaped endpoint-
// membership sweep. Clauses (30) + (50) + (51) together CLOSE the
// (arg-type × endpoint-direction) 2×2 = 4-corner declaration-axis
// endpoint-membership matrix on the closed-set head/tail-
// membership surface: (Self, head/tail) at clause (30) —
// [`Self::is_first`] / [`Self::is_last`]; (&str, head/tail) at
// clauses (50) + (51) — [`Self::is_first_label`] /
// [`Self::is_last_label`]. Every generic consumer that binds any
// of the four declaration-axis endpoint-membership methods sees
// the SAME endpoint-membership answer at every crate boundary
// regardless of which arg-type axis / endpoint-direction axis it
// walks.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_last_label(label);
let natural = label == T::last_label();
assert_eq!(
lifted, natural,
"{type_name}: T::is_last_label({label:?}) drifted from `{label:?} == T::last_label()` — the label-shaped tail-endpoint membership predicate no longer agrees with the natural `s == T::last_label()` one-primitive composition on the canonical label of variant {v:?}, so a downstream streaming Lisp reader / CLI subcommand dispatcher / anchored-diagnostic renderer that binds `T::is_last_label(s)` as its zero-alloc label-shaped tail-anchor query surface would answer the wrong `bool`",
);
}
assert!(
!T::is_last_label(probe),
"{type_name}: T::is_last_label({probe:?}) returned true on the reserved probe input — the label-shaped tail-endpoint membership predicate MUST reject every input outside the closed set's canonical labeling",
);
assert!(
!T::is_last_label(""),
"{type_name}: T::is_last_label(\"\") returned true on the empty-string boundary — the label-shaped tail-endpoint membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling",
);
// (52) — `T::is_sorted_first_label(s)` MUST equal
// `s == T::sorted_first_label()` on every representative input:
// every canonical variant label matches iff the variant is the lex-
// order head anchor, the reserved probe rejects (`false`), and the
// empty-string boundary rejects (`false`). The default trait body
// composes `s == <T as ClosedSet>::sorted_first_label()` verbatim
// and satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a permissive
// override that returns `true` for a non-lex-head label — silently
// routing an interior lex slot's label into the label-shaped lex-
// head-membership predicate; a strict override that returns `false`
// for the canonical lex-head label — silently detaching the label-
// shaped lex-head-membership predicate from the natural
// `s == T::sorted_first_label()` composition every downstream
// label-shaped lex-head-boundary consumer routes through; a fold
// override that answers "is this the declaration-head label?"
// instead — silently swapping the lex-axis onto the declaration-
// axis at the (declaration, lex) ordering axis; a fold override
// that answers "is this the lex-tail label?" instead — silently
// swapping the head-direction onto the tail-direction at the (head,
// tail) endpoint-direction axis; an override that always returns
// `true` for non-empty inputs — silently collapsing the label-
// shaped lex-head-membership onto a trivial non-empty predicate; a
// fabricated override that returns `true` on the empty-string
// boundary — silently detaching the label-shaped lex-head-
// membership from the non-empty canonical-label surface clause (4)
// pins) loudly rather than silently bifurcating the label-shaped
// lex-head-membership surface every downstream label-shaped lex-
// head-boundary consumer routes through. Sibling posture to clauses
// (31) + (48) + (50) — clause (31) pins the Self-arg lex-head-
// membership predicate against the natural
// `sorted_index_of(self) == 0` composition, clause (48) pins the
// singular lex-head-endpoint label projection against
// `T::sorted_first().label()`, clause (50) pins the &str-arg
// declaration-head-membership predicate against
// `s == T::first_label()`, this clause pins the &str-arg lex-head-
// membership predicate against the natural
// `s == T::sorted_first_label()` composition. Clauses (30) + (31) +
// (50) + (52) together open the (arg-type × ordering × head-
// direction) 2×2 = 4-corner endpoint-membership matrix at the head
// arm on BOTH arg-type axes AND BOTH ordering axes.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_sorted_first_label(label);
let natural = label == T::sorted_first_label();
assert_eq!(
lifted, natural,
"{type_name}: T::is_sorted_first_label({label:?}) drifted from `{label:?} == T::sorted_first_label()` — the label-shaped lex-head-endpoint membership predicate no longer agrees with the natural `s == T::sorted_first_label()` one-primitive composition on the canonical label of variant {v:?}, so a downstream alphabetized-completion LSP cursor / alphabetic-default-deserializer / lex-anchored-diagnostic renderer that binds `T::is_sorted_first_label(s)` as its zero-alloc label-shaped lex-head-anchor query surface would answer the wrong `bool`",
);
}
assert!(
!T::is_sorted_first_label(probe),
"{type_name}: T::is_sorted_first_label({probe:?}) returned true on the reserved probe input — the label-shaped lex-head-endpoint membership predicate MUST reject every input outside the closed set's canonical labeling; the probe is by construction distinct from every canonical label AND from every substrate-produced label, so a `true` answer here silently permits inputs beyond the closed set into the label-shaped lex-head-boundary surface",
);
assert!(
!T::is_sorted_first_label(""),
"{type_name}: T::is_sorted_first_label(\"\") returned true on the empty-string boundary — the label-shaped lex-head-endpoint membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling, so a `true` answer here silently permits the empty-string boundary into the label-shaped lex-head-boundary surface",
);
// (53) — `T::is_sorted_last_label(s)` MUST equal
// `s == T::sorted_last_label()` on every representative input:
// every canonical variant label matches iff the variant is the lex-
// order tail anchor, the reserved probe rejects (`false`), and the
// empty-string boundary rejects (`false`). The default trait body
// composes `s == <T as ClosedSet>::sorted_last_label()` verbatim
// and satisfies the clause for free; the assertion catches a future
// implementor whose override drifts the composition (a permissive
// override that returns `true` for a non-lex-tail label; a strict
// override that returns `false` for the canonical lex-tail label; a
// fold override that answers "is this the declaration-tail label?"
// instead — silently swapping the lex-axis onto the declaration-
// axis at the (declaration, lex) ordering axis; a fold override
// that answers "is this the lex-head label?" instead — silently
// swapping the tail-direction onto the head-direction at the (head,
// tail) endpoint-direction axis; an override that always returns
// `true` for non-empty inputs; a fabricated override that returns
// `true` on the empty-string boundary) loudly rather than silently
// bifurcating the label-shaped lex-tail-membership surface every
// downstream label-shaped lex-tail-boundary consumer routes
// through. Sibling posture to clause (52) one endpoint-direction
// axis over on the (head, tail) partition of the lex-axis label-
// shaped endpoint-membership sweep. Clauses (30) + (31) + (50) +
// (51) + (52) + (53) together CLOSE the (arg-type × ordering ×
// endpoint-direction) 2×2×2 = 8-corner endpoint-membership
// hypercube on the closed-set endpoint-membership surface: (Self,
// declaration, head/tail) at clause (30) — [`Self::is_first`] /
// [`Self::is_last`]; (Self, lex, head/tail) at clause (31) —
// [`Self::is_sorted_first`] / [`Self::is_sorted_last`]; (&str,
// declaration, head/tail) at clauses (50) + (51) —
// [`Self::is_first_label`] / [`Self::is_last_label`]; (&str, lex,
// head/tail) at clauses (52) + (53) —
// [`Self::is_sorted_first_label`] / [`Self::is_sorted_last_label`].
// Every generic consumer that binds any of the eight endpoint-
// membership methods sees the SAME endpoint-membership answer at
// every crate boundary regardless of which arg-type axis / ordering-
// axis / endpoint-direction axis it walks.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_sorted_last_label(label);
let natural = label == T::sorted_last_label();
assert_eq!(
lifted, natural,
"{type_name}: T::is_sorted_last_label({label:?}) drifted from `{label:?} == T::sorted_last_label()` — the label-shaped lex-tail-endpoint membership predicate no longer agrees with the natural `s == T::sorted_last_label()` one-primitive composition on the canonical label of variant {v:?}, so a downstream alphabetized-completion LSP cursor / alphabetic-default-deserializer / lex-anchored-diagnostic renderer that binds `T::is_sorted_last_label(s)` as its zero-alloc label-shaped lex-tail-anchor query surface would answer the wrong `bool`",
);
}
assert!(
!T::is_sorted_last_label(probe),
"{type_name}: T::is_sorted_last_label({probe:?}) returned true on the reserved probe input — the label-shaped lex-tail-endpoint membership predicate MUST reject every input outside the closed set's canonical labeling",
);
assert!(
!T::is_sorted_last_label(""),
"{type_name}: T::is_sorted_last_label(\"\") returned true on the empty-string boundary — the label-shaped lex-tail-endpoint membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling",
);
// (54) — `T::is_endpoint_label(s)` MUST equal
// `T::is_first_label(s) || T::is_last_label(s)` on every
// representative input: every canonical variant label answers
// `true` iff the variant is a declaration-order endpoint anchor,
// the reserved probe rejects (`false`), and the empty-string
// boundary rejects (`false`). Additionally the label-shaped
// endpoint pin agrees with the `Self`-arg endpoint pin through
// the natural label projection —
// `T::is_endpoint_label(v.label()) == v.is_endpoint()` for every
// canonical variant `v`, tying the label-shaped column
// (arg-type = &str) to the pre-existing `Self`-arg column
// (arg-type = Self) at every canonical slot. The default trait
// body composes
// `<T as ClosedSet>::is_first_label(s) || <T as ClosedSet>::is_last_label(s)`
// verbatim and satisfies the clause for free; the assertion
// catches a future implementor whose override drifts the
// composition (a permissive override that returns `true` for a
// strictly-interior canonical label — silently routing an
// interior slot's label into the label-shaped structural-
// boundary predicate; a strict override that returns `false`
// for the canonical head-endpoint OR tail-endpoint label — silently
// detaching the label-shaped boundary-membership from the natural
// point-membership disjunction; a fold override that answers "is
// this the lex-endpoint label?" instead — silently swapping the
// declaration-axis onto the lex-axis at the (declaration, lex)
// ordering axis; an override that always returns `true` on any
// non-empty input — silently collapsing the boundary predicate
// onto a trivial non-empty predicate; a fabricated override
// that returns `true` on the empty-string boundary or the
// reserved probe) loudly rather than silently bifurcating the
// label-shaped boundary-membership surface every downstream
// label-shaped structural-boundary consumer routes through.
// Sibling posture to clause (32) — clause (32) pins the `Self`-arg
// declaration-axis boundary-membership predicate against the
// natural `is_first(self) || is_last(self)` composition, this
// clause pins the `&str`-arg declaration-axis boundary-
// membership predicate against the natural
// `is_first_label(s) || is_last_label(s)` composition. Clauses
// (32) + (54) together open the (arg-type × predicate-flavor)
// 2×2 = 4-corner boundary-membership matrix at BOTH arg-type
// axes on the endpoint arm of the declaration-axis boolean-
// boundary surface.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_endpoint_label(label);
let natural = T::is_first_label(label) || T::is_last_label(label);
assert_eq!(
lifted, natural,
"{type_name}: T::is_endpoint_label({label:?}) drifted from `T::is_first_label({label:?}) || T::is_last_label({label:?})` — the label-shaped declaration-boundary-membership predicate no longer agrees with the natural `is_first_label(s) || is_last_label(s)` two-primitive composition on the canonical label of variant {v:?}, so a downstream shared-endpoint-badge renderer / annotation-key filter / lint that flags label strings drifting away from the declared endpoint pair — consumers that bind `T::is_endpoint_label(s)` as their zero-alloc label-shaped structural-boundary query surface — would answer the wrong `bool`",
);
assert_eq!(
lifted,
v.is_endpoint(),
"{type_name}: T::is_endpoint_label({label:?}) diverged from {v:?}.is_endpoint() through the natural label projection — the (Self, &str) arg-type axis bifurcated at the declaration boundary-membership predicate on the canonical label of variant {v:?}",
);
}
assert!(
!T::is_endpoint_label(probe),
"{type_name}: T::is_endpoint_label({probe:?}) returned true on the reserved probe input — the label-shaped declaration-boundary-membership predicate MUST reject every input outside the closed set's canonical labeling; the probe is by construction distinct from every canonical label AND from every substrate-produced label, so a `true` answer here silently permits inputs beyond the closed set into the label-shaped structural-boundary surface",
);
assert!(
!T::is_endpoint_label(""),
"{type_name}: T::is_endpoint_label(\"\") returned true on the empty-string boundary — the label-shaped declaration-boundary-membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling",
);
// (55) — `T::is_interior_label(s)` MUST equal
// `T::contains_label(s) && !T::is_endpoint_label(s)` on every
// representative input: every canonical variant label answers
// `true` iff the variant is a strictly-interior declaration
// slot, the reserved probe rejects (`false` — non-canonical),
// and the empty-string boundary rejects (`false` — non-
// canonical). Additionally the label-shaped interior pin agrees
// with the `Self`-arg interior pin through the natural label
// projection — `T::is_interior_label(v.label()) == v.is_interior()`
// for every canonical variant `v`, tying the label-shaped
// interior column to the pre-existing `Self`-arg interior
// column at every canonical slot. Additionally the (label-
// shaped endpoint, label-shaped interior) partition contract on
// the canonical sub-domain —
// `is_endpoint_label(v.label()) != is_interior_label(v.label())`
// for every variant `v` — is pinned as an exhaustive
// complementarity assertion, mirroring clause (32)'s
// complementarity pin one arg-type axis over. The default trait
// body composes
// `<T as ClosedSet>::contains_label(s) && !<T as ClosedSet>::is_endpoint_label(s)`
// verbatim and satisfies the clause for free; the assertion
// catches a future implementor whose override drifts the
// composition (a permissive override that returns `true` for an
// endpoint label — folding the endpoint slot into the interior
// slot; a permissive override that returns `true` for a non-
// canonical input — dropping the domain-membership gate; a
// strict override that returns `false` for a strictly-interior
// canonical label — silently detaching the interior arm from
// the canonical partition; a swap override that inverts the
// (endpoint, interior) partition on the label-shaped column)
// loudly rather than silently bifurcating the label-shaped
// interior-membership surface. Sibling posture to clause (32)
// one arg-type axis over. Clauses (32) + (54) + (55) together
// CLOSE the (arg-type × predicate-flavor) 2×2 = 4-corner
// boundary-membership matrix on the declaration-axis boolean-
// boundary surface at ALL FOUR corners: (Self, endpoint) at
// clause (32), (Self, interior) at clause (32), (&str,
// endpoint) at clause (54), (&str, interior) at clause (55).
for &v in T::ALL {
let label = v.label();
let lifted = T::is_interior_label(label);
let natural = T::contains_label(label) && !T::is_endpoint_label(label);
assert_eq!(
lifted, natural,
"{type_name}: T::is_interior_label({label:?}) drifted from `T::contains_label({label:?}) && !T::is_endpoint_label({label:?})` — the label-shaped declaration-interior-membership predicate no longer agrees with the natural domain-gated interior composition on the canonical label of variant {v:?}, so a downstream strictly-interior renderer / interior-slot audit event / boundary-hidden completion pass consumer that binds `T::is_interior_label(s)` as its zero-alloc label-shaped interior query surface would answer the wrong `bool`",
);
assert_eq!(
lifted,
v.is_interior(),
"{type_name}: T::is_interior_label({label:?}) diverged from {v:?}.is_interior() through the natural label projection — the (Self, &str) arg-type axis bifurcated at the declaration interior-membership predicate on the canonical label of variant {v:?}",
);
assert_ne!(
T::is_endpoint_label(label),
T::is_interior_label(label),
"{type_name}: T::is_endpoint_label({label:?}) and T::is_interior_label({label:?}) returned the SAME bool on the canonical label of variant {v:?} — the label-shaped (endpoint, interior) partition MUST be exhaustive on canonical labels: every canonical label answers `true` to EXACTLY ONE of the two predicates. A drift here means BOTH predicates fired OR BOTH predicates rejected on {v:?}'s canonical label, breaking the label-shaped boundary-partition on the declaration axis",
);
}
assert!(
!T::is_interior_label(probe),
"{type_name}: T::is_interior_label({probe:?}) returned true on the reserved probe input — the label-shaped declaration-interior-membership predicate MUST reject every input outside the closed set's canonical labeling; the domain-membership gate through `contains_label` is load-bearing on the `&str` arg-type column",
);
assert!(
!T::is_interior_label(""),
"{type_name}: T::is_interior_label(\"\") returned true on the empty-string boundary — the label-shaped declaration-interior-membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling and the domain-membership gate through `contains_label` rejects it accordingly",
);
// (56) — `T::is_sorted_endpoint_label(s)` MUST equal
// `T::is_sorted_first_label(s) || T::is_sorted_last_label(s)`
// on every representative input: every canonical variant label
// answers `true` iff the variant is a lex-order endpoint anchor,
// the reserved probe rejects, and the empty-string boundary
// rejects. Additionally the label-shaped lex-endpoint pin
// agrees with the `Self`-arg lex-endpoint pin through the
// natural label projection —
// `T::is_sorted_endpoint_label(v.label()) == v.is_sorted_endpoint()`
// for every canonical variant `v`. The default trait body
// composes
// `<T as ClosedSet>::is_sorted_first_label(s) || <T as ClosedSet>::is_sorted_last_label(s)`
// verbatim and satisfies the clause for free. Sibling posture
// to clause (33) one arg-type axis over, and to clause (54)
// one ordering axis over. Clauses (33) + (54) + (56) open the
// (arg-type × ordering) 2×2 matrix on the endpoint arm of the
// boolean-boundary surface at ALL FOUR arg-type × ordering
// corners.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_sorted_endpoint_label(label);
let natural = T::is_sorted_first_label(label) || T::is_sorted_last_label(label);
assert_eq!(
lifted, natural,
"{type_name}: T::is_sorted_endpoint_label({label:?}) drifted from `T::is_sorted_first_label({label:?}) || T::is_sorted_last_label({label:?})` — the label-shaped lex-boundary-membership predicate no longer agrees with the natural `is_sorted_first_label(s) || is_sorted_last_label(s)` two-primitive composition on the canonical label of variant {v:?}, so a downstream alphabetized-boundary-badge renderer / lex-boundary annotation-key filter consumer that binds `T::is_sorted_endpoint_label(s)` as its zero-alloc label-shaped lex-structural-boundary query surface would answer the wrong `bool`",
);
assert_eq!(
lifted,
v.is_sorted_endpoint(),
"{type_name}: T::is_sorted_endpoint_label({label:?}) diverged from {v:?}.is_sorted_endpoint() through the natural label projection — the (Self, &str) arg-type axis bifurcated at the lex boundary-membership predicate on the canonical label of variant {v:?}",
);
}
assert!(
!T::is_sorted_endpoint_label(probe),
"{type_name}: T::is_sorted_endpoint_label({probe:?}) returned true on the reserved probe input — the label-shaped lex-boundary-membership predicate MUST reject every input outside the closed set's canonical labeling",
);
assert!(
!T::is_sorted_endpoint_label(""),
"{type_name}: T::is_sorted_endpoint_label(\"\") returned true on the empty-string boundary — the label-shaped lex-boundary-membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling",
);
// (57) — `T::is_sorted_interior_label(s)` MUST equal
// `T::contains_label(s) && !T::is_sorted_endpoint_label(s)` on
// every representative input: every canonical variant label
// answers `true` iff the variant is a strictly-lex-interior
// slot, the reserved probe rejects, and the empty-string
// boundary rejects. Additionally the label-shaped lex-interior
// pin agrees with the `Self`-arg lex-interior pin through the
// natural label projection —
// `T::is_sorted_interior_label(v.label()) == v.is_sorted_interior()`
// for every canonical variant `v`. Additionally the (label-
// shaped lex-endpoint, label-shaped lex-interior) partition
// contract on the canonical sub-domain —
// `is_sorted_endpoint_label(v.label()) != is_sorted_interior_label(v.label())`
// for every variant `v` — is pinned as an exhaustive
// complementarity assertion. The default trait body composes
// `<T as ClosedSet>::contains_label(s) && !<T as ClosedSet>::is_sorted_endpoint_label(s)`
// verbatim and satisfies the clause for free. Clauses (32) +
// (33) + (54) + (55) + (56) + (57) together CLOSE the (arg-type
// × ordering × predicate-flavor) 2×2×2 = 8-corner boolean-
// boundary hypercube on the closed-set boolean-boundary surface:
// (Self, declaration, endpoint/interior) at clause (32) —
// [`Self::is_endpoint`] / [`Self::is_interior`]; (Self, lex,
// endpoint/interior) at clause (33) — [`Self::is_sorted_endpoint`]
// / [`Self::is_sorted_interior`]; (&str, declaration,
// endpoint/interior) at clauses (54) + (55) —
// [`Self::is_endpoint_label`] / [`Self::is_interior_label`];
// (&str, lex, endpoint/interior) at clauses (56) + (57) —
// [`Self::is_sorted_endpoint_label`] /
// [`Self::is_sorted_interior_label`]. Every generic consumer
// that binds any of the eight boolean-boundary methods sees
// the SAME structural-boundary answer at every crate boundary
// regardless of which arg-type axis / ordering-axis /
// predicate-flavor axis it walks.
for &v in T::ALL {
let label = v.label();
let lifted = T::is_sorted_interior_label(label);
let natural = T::contains_label(label) && !T::is_sorted_endpoint_label(label);
assert_eq!(
lifted, natural,
"{type_name}: T::is_sorted_interior_label({label:?}) drifted from `T::contains_label({label:?}) && !T::is_sorted_endpoint_label({label:?})` — the label-shaped lex-interior-membership predicate no longer agrees with the natural domain-gated lex-interior composition on the canonical label of variant {v:?}",
);
assert_eq!(
lifted,
v.is_sorted_interior(),
"{type_name}: T::is_sorted_interior_label({label:?}) diverged from {v:?}.is_sorted_interior() through the natural label projection — the (Self, &str) arg-type axis bifurcated at the lex interior-membership predicate on the canonical label of variant {v:?}",
);
assert_ne!(
T::is_sorted_endpoint_label(label),
T::is_sorted_interior_label(label),
"{type_name}: T::is_sorted_endpoint_label({label:?}) and T::is_sorted_interior_label({label:?}) returned the SAME bool on the canonical label of variant {v:?} — the label-shaped (lex-endpoint, lex-interior) partition MUST be exhaustive on canonical labels: every canonical label answers `true` to EXACTLY ONE of the two predicates. A drift here means BOTH predicates fired OR BOTH predicates rejected on {v:?}'s canonical label, breaking the label-shaped boundary-partition on the lex axis",
);
}
assert!(
!T::is_sorted_interior_label(probe),
"{type_name}: T::is_sorted_interior_label({probe:?}) returned true on the reserved probe input — the label-shaped lex-interior-membership predicate MUST reject every input outside the closed set's canonical labeling",
);
assert!(
!T::is_sorted_interior_label(""),
"{type_name}: T::is_sorted_interior_label(\"\") returned true on the empty-string boundary — the label-shaped lex-interior-membership predicate MUST reject the empty string; clause (4) pins the empty string as structurally reserved outside every canonical labeling and the domain-membership gate through `contains_label` rejects it accordingly",
);
// (58) — For every variant `v` in `T::ALL`, `v.next_label()` MUST
// equal `v.next().map(T::label)`, AND `T::last().next_label()`
// MUST equal `None`. The default trait body composes
// `next(self).map(label)` verbatim and satisfies both arms for
// free; the assertion catches a future implementor whose override
// drifts the forward-neighbor-label projection (a permissive
// override that returns `Some(<some interior-neighbor label>)` at
// the tail — folding the tail-boundary walk onto a wraparound to
// the head's label while the composed projection would return
// `None`; a swapped override that returns the predecessor's label
// for `next_label`, silently inverting the direction of the label-
// rendered forward walk; a stale override that returns the wrong
// neighbor label after a variant-listing edit reorders `T::ALL`)
// loudly rather than silently bifurcating the forward-neighbor-
// label projection surface every downstream diagnostic renderer /
// Kubernetes annotation stamper / per-slot audit trail / saga-step
// hint consumer routes through. Sibling posture to clauses (26) +
// (46) + (47) — clause (26) pins the `Self`-return forward-
// neighbor projection at both direction arms + endpoint fixpoints,
// clauses (46) + (47) pin the `&'static str`-return endpoint-
// anchor projections at both direction arms of the (head, tail)
// partition, this clause pins the `&'static str`-return forward-
// neighbor projection against the composition of both AND pins the
// tail-endpoint `None` guard — so the closed-set label-shaped
// forward-neighbor surface stays sound at the declaration axis AND
// on the shared tail-endpoint fixpoint (`T::last().next_label() ==
// None`).
for &v in T::ALL {
let expected_next_label = v.next().map(<T as ClosedSet>::label);
assert_eq!(
v.next_label(),
expected_next_label,
"{type_name}: {v:?}.next_label() drifted from {v:?}.next().map(T::label) — the direct (variant → forward-neighbor label) projection no longer agrees with the natural next+label composition, so a downstream diagnostic renderer / Kubernetes annotation stamper / per-slot audit trail / saga-step hint consumer that binds `v.next_label()` as its forward-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::last().next_label(),
None,
"{type_name}: T::last().next_label() returned Some(_) — the (variant → forward-neighbor label) projection accepted the tail-endpoint boundary, silently folding a tail-boundary label render onto a wraparound to the head's label while the natural `next().map(label)` composition should return `None`. Clauses (26) + (58) together pin `T::last().next_label() == None` as the structural fixpoint the tail-endpoint anchor and the forward-neighbor-label axis share, mirroring `T::last().next() == None` one return-type axis over",
);
// (59) — For every variant `v` in `T::ALL`, `v.prev_label()` MUST
// equal `v.prev().map(T::label)`, AND `T::first().prev_label()`
// MUST equal `None`. The default trait body composes
// `prev(self).map(label)` verbatim and satisfies both arms for
// free; the assertion catches a future implementor whose override
// drifts the backward-neighbor-label projection (a permissive
// override that returns `Some(<some interior-neighbor label>)` at
// the head — folding the head-boundary walk onto a wraparound to
// the tail's label while the composed projection would return
// `None`; a swapped override that returns the successor's label
// for `prev_label`, silently inverting the direction of the label-
// rendered backward walk; a stale override that returns the wrong
// neighbor label after a variant-listing edit reorders `T::ALL`)
// loudly rather than silently bifurcating the backward-neighbor-
// label projection surface every downstream diagnostic renderer /
// Kubernetes annotation stamper / per-slot audit trail / saga-step
// hint consumer routes through. Clauses (18) + (26) + (46) + (47)
// + (58) + (59) together CLOSE the (return-type × direction ×
// structural-landmark) 2×2×2 = 8-corner declaration-axis label-
// and-variant endpoint-anchor + neighbor hypercube: (`Self`,
// endpoint) at clause (18) — [`Self::first`] / [`Self::last`];
// (`Self`, neighbor) at clause (26) — [`Self::next`] /
// [`Self::prev`]; (`&'static str`, endpoint) at clauses (46) +
// (47) — [`Self::first_label`] / [`Self::last_label`]; and
// (`&'static str`, neighbor) at clauses (58) + (59) —
// [`Self::next_label`] / [`Self::prev_label`]. Every generic
// consumer that binds any of the eight projection methods sees
// the SAME structural answer at every crate boundary regardless
// of which return-type / direction / landmark axis corner it
// walks.
for &v in T::ALL {
let expected_prev_label = v.prev().map(<T as ClosedSet>::label);
assert_eq!(
v.prev_label(),
expected_prev_label,
"{type_name}: {v:?}.prev_label() drifted from {v:?}.prev().map(T::label) — the direct (variant → backward-neighbor label) projection no longer agrees with the natural prev+label composition, so a downstream diagnostic renderer / Kubernetes annotation stamper / per-slot audit trail / saga-step hint consumer that binds `v.prev_label()` as its backward-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::first().prev_label(),
None,
"{type_name}: T::first().prev_label() returned Some(_) — the (variant → backward-neighbor label) projection accepted the head-endpoint boundary, silently folding a head-boundary label render onto a wraparound to the tail's label while the natural `prev().map(label)` composition should return `None`. Clauses (26) + (59) together pin `T::first().prev_label() == None` as the structural fixpoint the head-endpoint anchor and the backward-neighbor-label axis share, mirroring `T::first().prev() == None` one return-type axis over",
);
// (60) — For every variant `v` in `T::ALL`, `v.sorted_next_label()`
// MUST equal `v.sorted_next().map(T::label)`, AND
// `T::sorted_last().sorted_next_label()` MUST equal `None`. The
// default trait body composes `sorted_next(self).map(label)` verbatim
// and satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the forward-lex-neighbor-label
// projection (a permissive override that returns `Some(<some interior
// lex-neighbor label>)` at the lex-tail — folding the lex-tail-
// boundary walk onto a wraparound to the lex-head's label while the
// composed projection would return `None`; a swapped override that
// returns the lex-predecessor's label for `sorted_next_label`,
// silently inverting the direction of the lex-label-rendered forward
// walk; a stale override that returns the wrong lex-neighbor label
// after a variant-listing edit reorders the lex partition) loudly
// rather than silently bifurcating the forward-lex-neighbor-label
// projection surface every downstream alphabetized-completion LSP
// cursor / lex-sorted `tatara-check` per-slot diagnostic renderer /
// Kubernetes annotation stamper / lex-order compact-encoded wire
// codec consumer routes through. Sibling posture to clauses (27) +
// (48) + (49) + (58) — clause (27) pins the `Self`-return lex-
// neighbor projection at both direction arms + lex-endpoint fixpoints,
// clauses (48) + (49) pin the `&'static str`-return lex-endpoint-
// anchor projections at both direction arms of the (lex-head,
// lex-tail) partition, clause (58) pins the `&'static str`-return
// forward-neighbor projection against the composition of both on the
// declaration axis, this clause pins the `&'static str`-return
// forward-neighbor projection against the composition of both on the
// LEX axis AND pins the lex-tail-endpoint `None` guard — so the
// closed-set label-shaped forward-neighbor surface stays sound at
// BOTH ordering axes AND on the shared lex-tail-endpoint fixpoint
// (`T::sorted_last().sorted_next_label() == None`).
for &v in T::ALL {
let expected_sorted_next_label = v.sorted_next().map(<T as ClosedSet>::label);
assert_eq!(
v.sorted_next_label(),
expected_sorted_next_label,
"{type_name}: {v:?}.sorted_next_label() drifted from {v:?}.sorted_next().map(T::label) — the direct (variant → forward lex-neighbor label) projection no longer agrees with the natural sorted_next+label composition, so a downstream alphabetized-completion LSP cursor / lex-sorted tatara-check per-slot diagnostic renderer / Kubernetes annotation stamper / lex-order compact-encoded wire codec consumer that binds `v.sorted_next_label()` as its forward-lex-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::sorted_last().sorted_next_label(),
None,
"{type_name}: T::sorted_last().sorted_next_label() returned Some(_) — the (variant → forward lex-neighbor label) projection accepted the lex-tail-endpoint boundary, silently folding a lex-tail-boundary label render onto a wraparound to the lex-head's label while the natural `sorted_next().map(label)` composition should return `None`. Clauses (27) + (60) together pin `T::sorted_last().sorted_next_label() == None` as the structural fixpoint the lex-tail-endpoint anchor and the forward-lex-neighbor-label axis share, mirroring `T::sorted_last().sorted_next() == None` one return-type axis over AND `T::last().next_label() == None` one ordering axis over",
);
// (61) — For every variant `v` in `T::ALL`, `v.sorted_prev_label()`
// MUST equal `v.sorted_prev().map(T::label)`, AND
// `T::sorted_first().sorted_prev_label()` MUST equal `None`. The
// default trait body composes `sorted_prev(self).map(label)` verbatim
// and satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the backward-lex-neighbor-label
// projection (a permissive override that returns `Some(<some interior
// lex-neighbor label>)` at the lex-head — folding the lex-head-
// boundary walk onto a wraparound to the lex-tail's label while the
// composed projection would return `None`; a swapped override that
// returns the lex-successor's label for `sorted_prev_label`, silently
// inverting the direction of the lex-label-rendered backward walk; a
// stale override that returns the wrong lex-neighbor label after a
// variant-listing edit reorders the lex partition) loudly rather than
// silently bifurcating the backward-lex-neighbor-label projection
// surface every downstream alphabetized-completion LSP cursor /
// lex-sorted `tatara-check` per-slot diagnostic renderer / Kubernetes
// annotation stamper / lex-order compact-encoded wire codec consumer
// routes through. Clauses (18) + (26) + (27) + (46) + (47) + (48) +
// (49) + (58) + (59) + (60) + (61) together CLOSE the (declaration ×
// lex) × (forward, backward) × (`Self`-return, `&'static str`-return)
// × (endpoint-anchor, neighbor) 2×2×2×2 = 16-corner label-and-variant
// traversal hypercube on the closed-set neighbor + endpoint-anchor
// surface. Every generic consumer that binds any of the sixteen
// projection methods sees the SAME structural answer at every crate
// boundary regardless of which ordering / direction / return-type /
// landmark axis corner it walks.
for &v in T::ALL {
let expected_sorted_prev_label = v.sorted_prev().map(<T as ClosedSet>::label);
assert_eq!(
v.sorted_prev_label(),
expected_sorted_prev_label,
"{type_name}: {v:?}.sorted_prev_label() drifted from {v:?}.sorted_prev().map(T::label) — the direct (variant → backward lex-neighbor label) projection no longer agrees with the natural sorted_prev+label composition, so a downstream alphabetized-completion LSP cursor / lex-sorted tatara-check per-slot diagnostic renderer / Kubernetes annotation stamper / lex-order compact-encoded wire codec consumer that binds `v.sorted_prev_label()` as its backward-lex-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::sorted_first().sorted_prev_label(),
None,
"{type_name}: T::sorted_first().sorted_prev_label() returned Some(_) — the (variant → backward lex-neighbor label) projection accepted the lex-head-endpoint boundary, silently folding a lex-head-boundary label render onto a wraparound to the lex-tail's label while the natural `sorted_prev().map(label)` composition should return `None`. Clauses (27) + (61) together pin `T::sorted_first().sorted_prev_label() == None` as the structural fixpoint the lex-head-endpoint anchor and the backward-lex-neighbor-label axis share, mirroring `T::sorted_first().sorted_prev() == None` one return-type axis over AND `T::first().prev_label() == None` one ordering axis over",
);
// (62) — For every variant `v` in `T::ALL`, `v.cycle_next_label()`
// MUST equal `v.cycle_next().label()`, AND
// `T::last().cycle_next_label()` MUST equal `T::first_label()`. The
// default trait body composes `label(cycle_next(self))` verbatim and
// satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the wrapping-forward-neighbor-
// label projection (a divergent override that folds the tail label
// onto some interior label rather than the head label, silently
// bifurcating the cyclic label-rendered forward walk; a swapped
// override that returns the predecessor's label; a stale override
// that returns the wrong wrapping-neighbor label after a variant-
// listing edit reorders `T::ALL`) loudly rather than silently
// bifurcating the wrapping-forward-neighbor-label projection surface
// every downstream cyclic LSP completion cursor / round-robin picker
// rotation banner / carousel-widget next-tab renderer / per-tick
// animation-frame audit trail / Kubernetes wrapping-annotation
// stamper consumer routes through. Sibling posture to clauses (28) +
// (58) — clause (28) pins the `Self`-return wrapping-forward-neighbor
// projection at the tail-wraparound fixpoint, clause (58) pins the
// `&'static str`-return bounded-forward-neighbor projection at the
// tail-endpoint `None` fixpoint, this clause pins the `&'static str`-
// return wrapping-forward-neighbor projection against the composition
// of the wrapping variant primitive with the canonical label AND at
// the shared tail-wraparound label fixpoint
// (`T::last().cycle_next_label() == T::first_label()`).
for &v in T::ALL {
let expected_cycle_next_label = <T as ClosedSet>::label(v.cycle_next());
assert_eq!(
v.cycle_next_label(),
expected_cycle_next_label,
"{type_name}: {v:?}.cycle_next_label() drifted from {v:?}.cycle_next().label() — the direct (variant → wrapping-forward-neighbor label) projection no longer agrees with the natural cycle_next+label composition, so a downstream cyclic LSP completion cursor / round-robin picker rotation banner / carousel-widget next-tab renderer / per-tick animation-frame audit trail / Kubernetes wrapping-annotation stamper consumer that binds `v.cycle_next_label()` as its wrapping-forward-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::last().cycle_next_label(),
T::first_label(),
"{type_name}: T::last().cycle_next_label() drifted from T::first_label() — the (variant → wrapping-forward-neighbor label) projection at the tail-endpoint boundary did not fold onto the head-endpoint anchor label while the natural `cycle_next().label()` composition folds `T::last()` onto `T::first()` at the wraparound edge and then projects `T::first().label()`. Clauses (28) + (62) together pin `T::last().cycle_next_label() == T::first_label()` as the structural fixpoint the tail-endpoint anchor and the wrapping-forward-neighbor-label axis share, mirroring `T::last().cycle_next() == T::first()` one return-type axis over",
);
// (63) — For every variant `v` in `T::ALL`, `v.cycle_prev_label()`
// MUST equal `v.cycle_prev().label()`, AND
// `T::first().cycle_prev_label()` MUST equal `T::last_label()`. The
// default trait body composes `label(cycle_prev(self))` verbatim and
// satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the wrapping-backward-neighbor-
// label projection loudly rather than silently bifurcating the
// wrapping-backward-neighbor-label projection surface every
// downstream cyclic-backward LSP completion cursor / round-robin
// picker rotation banner / carousel-widget prev-tab renderer /
// per-tick animation-frame audit trail consumer routes through.
// Sibling posture to clauses (28) + (59) on the (forward, backward)
// partition of the declaration-axis wrapping-label-neighbor surface.
for &v in T::ALL {
let expected_cycle_prev_label = <T as ClosedSet>::label(v.cycle_prev());
assert_eq!(
v.cycle_prev_label(),
expected_cycle_prev_label,
"{type_name}: {v:?}.cycle_prev_label() drifted from {v:?}.cycle_prev().label() — the direct (variant → wrapping-backward-neighbor label) projection no longer agrees with the natural cycle_prev+label composition, so a downstream cyclic-backward LSP completion cursor / round-robin picker rotation banner / carousel-widget prev-tab renderer / per-tick animation-frame audit trail consumer that binds `v.cycle_prev_label()` as its wrapping-backward-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::first().cycle_prev_label(),
T::last_label(),
"{type_name}: T::first().cycle_prev_label() drifted from T::last_label() — the (variant → wrapping-backward-neighbor label) projection at the head-endpoint boundary did not fold onto the tail-endpoint anchor label while the natural `cycle_prev().label()` composition folds `T::first()` onto `T::last()` at the wraparound edge and then projects `T::last().label()`. Clauses (28) + (63) together pin `T::first().cycle_prev_label() == T::last_label()` as the structural fixpoint the head-endpoint anchor and the wrapping-backward-neighbor-label axis share, mirroring `T::first().cycle_prev() == T::last()` one return-type axis over",
);
// (64) — For every variant `v` in `T::ALL`, `v.cycle_sorted_next_label()`
// MUST equal `v.cycle_sorted_next().label()`, AND
// `T::sorted_last().cycle_sorted_next_label()` MUST equal
// `T::sorted_first_label()`. The default trait body composes
// `label(cycle_sorted_next(self))` verbatim and satisfies both arms
// for free; the assertion catches a future implementor whose override
// drifts the wrapping-forward-lex-neighbor-label projection loudly
// rather than silently bifurcating the projection surface every
// downstream alphabetized-cyclic LSP completion cursor /
// alphabetized round-robin picker / alphabetized carousel-widget
// next-tab renderer / lex-cyclic per-tick animation-frame audit
// trail consumer routes through. Sibling posture to clauses (29) +
// (60) + (62) — clause (29) pins the `Self`-return wrapping-
// forward-lex-neighbor projection at the lex-tail-wraparound
// fixpoint, clause (60) pins the `&'static str`-return bounded-
// forward-lex-neighbor projection at the lex-tail-endpoint `None`
// fixpoint, clause (62) pins the `&'static str`-return wrapping-
// forward-declaration-neighbor projection at the tail-wraparound
// label fixpoint on the declaration axis, this clause pins the same
// `&'static str`-return wrapping-forward-neighbor projection on the
// LEX axis AND at the shared lex-tail-wraparound label fixpoint
// (`T::sorted_last().cycle_sorted_next_label() == T::sorted_first_label()`).
for &v in T::ALL {
let expected_cycle_sorted_next_label = <T as ClosedSet>::label(v.cycle_sorted_next());
assert_eq!(
v.cycle_sorted_next_label(),
expected_cycle_sorted_next_label,
"{type_name}: {v:?}.cycle_sorted_next_label() drifted from {v:?}.cycle_sorted_next().label() — the direct (variant → wrapping-forward lex-neighbor label) projection no longer agrees with the natural cycle_sorted_next+label composition, so a downstream alphabetized-cyclic LSP completion cursor / alphabetized round-robin picker / alphabetized carousel-widget next-tab renderer / lex-cyclic per-tick animation-frame audit trail consumer that binds `v.cycle_sorted_next_label()` as its wrapping-forward-lex-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::sorted_last().cycle_sorted_next_label(),
T::sorted_first_label(),
"{type_name}: T::sorted_last().cycle_sorted_next_label() drifted from T::sorted_first_label() — the (variant → wrapping-forward lex-neighbor label) projection at the lex-tail-endpoint boundary did not fold onto the lex-head-endpoint anchor label while the natural `cycle_sorted_next().label()` composition folds `T::sorted_last()` onto `T::sorted_first()` at the lex-wraparound edge and then projects `T::sorted_first().label()`. Clauses (29) + (64) together pin `T::sorted_last().cycle_sorted_next_label() == T::sorted_first_label()` as the structural fixpoint the lex-tail-endpoint anchor and the wrapping-forward-lex-neighbor-label axis share, mirroring `T::sorted_last().cycle_sorted_next() == T::sorted_first()` one return-type axis over AND `T::last().cycle_next_label() == T::first_label()` one ordering axis over",
);
// (65) — For every variant `v` in `T::ALL`, `v.cycle_sorted_prev_label()`
// MUST equal `v.cycle_sorted_prev().label()`, AND
// `T::sorted_first().cycle_sorted_prev_label()` MUST equal
// `T::sorted_last_label()`. The default trait body composes
// `label(cycle_sorted_prev(self))` verbatim and satisfies both arms
// for free; the assertion catches a future implementor whose override
// drifts the wrapping-backward-lex-neighbor-label projection loudly.
// Clauses (28) + (29) + (58) + (59) + (60) + (61) + (62) + (63) +
// (64) + (65) together CLOSE the (declaration × lex) × (forward,
// backward) × (Option-typed-bounded, wrapping) × (`Self`-return,
// `&'static str`-return) 2×2×2×2 = 16-corner label-and-variant
// bounded-plus-wrapping traversal hypercube on the closed-set
// neighbor surface. Every generic consumer that binds any of the
// sixteen projection methods sees the SAME structural answer at
// every crate boundary regardless of which ordering / direction /
// bounded-or-wrapping / return-type axis corner it walks.
for &v in T::ALL {
let expected_cycle_sorted_prev_label = <T as ClosedSet>::label(v.cycle_sorted_prev());
assert_eq!(
v.cycle_sorted_prev_label(),
expected_cycle_sorted_prev_label,
"{type_name}: {v:?}.cycle_sorted_prev_label() drifted from {v:?}.cycle_sorted_prev().label() — the direct (variant → wrapping-backward lex-neighbor label) projection no longer agrees with the natural cycle_sorted_prev+label composition, so a downstream alphabetized-cyclic-backward LSP completion cursor / alphabetized round-robin picker / alphabetized carousel-widget prev-tab renderer / lex-cyclic per-tick animation-frame audit trail consumer that binds `v.cycle_sorted_prev_label()` as its wrapping-backward-lex-neighbor label-rendering surface would emit the wrong label for {v:?}",
);
}
assert_eq!(
T::sorted_first().cycle_sorted_prev_label(),
T::sorted_last_label(),
"{type_name}: T::sorted_first().cycle_sorted_prev_label() drifted from T::sorted_last_label() — the (variant → wrapping-backward lex-neighbor label) projection at the lex-head-endpoint boundary did not fold onto the lex-tail-endpoint anchor label while the natural `cycle_sorted_prev().label()` composition folds `T::sorted_first()` onto `T::sorted_last()` at the lex-wraparound edge and then projects `T::sorted_last().label()`. Clauses (29) + (65) together pin `T::sorted_first().cycle_sorted_prev_label() == T::sorted_last_label()` as the structural fixpoint the lex-head-endpoint anchor and the wrapping-backward-lex-neighbor-label axis share, mirroring `T::sorted_first().cycle_sorted_prev() == T::sorted_last()` one return-type axis over AND `T::first().cycle_prev_label() == T::last_label()` one ordering axis over",
);
// (66) — For every variant `v` in `T::ALL`, `v.next_index()` MUST
// equal `v.next().map(T::index_of)`, AND `T::last().next_index()`
// MUST equal `None`. The default trait body composes
// `next(self).map(index_of)` verbatim and satisfies both arms for
// free; the assertion catches a future implementor whose override
// drifts the forward-neighbor-index projection (a permissive
// override that returns `Some(0)` at the tail — folding the tail-
// boundary walk onto a wraparound to the head-index while the
// composed projection would return `None`; a swapped override that
// returns the predecessor's index for `next_index`, silently
// inverting the direction of the index-rendered forward walk; a
// stale override that returns the wrong neighbor index after a
// variant-listing edit reorders `T::ALL`) loudly rather than
// silently bifurcating the forward-neighbor-index projection
// surface every downstream compact wire codec / Prometheus per-
// slot bucket / bitset state machine / byte-tagged compact
// encoding / Sekiban per-transition audit binner consumer routes
// through. Sibling posture to clauses (26) + (58) — clause (26)
// pins the `Self`-return forward-neighbor projection at both
// direction arms + endpoint fixpoints, clause (58) pins the
// `&'static str`-return forward-neighbor projection against the
// composition of `next` + `label`, this clause pins the
// `usize`-return forward-neighbor projection against the
// composition of `next` + `index_of` AND pins the tail-endpoint
// `None` guard — so the closed-set index-shaped forward-neighbor
// surface stays sound at the declaration axis AND on the shared
// tail-endpoint fixpoint (`T::last().next_index() == None`).
for &v in T::ALL {
let expected_next_index = v.next().map(<T as ClosedSet>::index_of);
assert_eq!(
v.next_index(),
expected_next_index,
"{type_name}: {v:?}.next_index() drifted from {v:?}.next().map(T::index_of) — the direct (variant → forward-neighbor index) projection no longer agrees with the natural next+index_of composition, so a downstream compact wire codec / Prometheus per-slot bucket / bitset state machine / byte-tagged compact encoding / Sekiban per-transition audit binner consumer that binds `v.next_index()` as its forward-neighbor index-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::last().next_index(),
None,
"{type_name}: T::last().next_index() returned Some(_) — the (variant → forward-neighbor index) projection accepted the tail-endpoint boundary, silently folding a tail-boundary index render onto a wraparound to the head-index while the natural `next().map(index_of)` composition should return `None`. Clauses (26) + (66) together pin `T::last().next_index() == None` as the structural fixpoint the tail-endpoint anchor and the forward-neighbor-index axis share, mirroring `T::last().next() == None` one return-type axis over AND `T::last().next_label() == None` one return-type axis over",
);
// (67) — For every variant `v` in `T::ALL`, `v.prev_index()` MUST
// equal `v.prev().map(T::index_of)`, AND `T::first().prev_index()`
// MUST equal `None`. The default trait body composes
// `prev(self).map(index_of)` verbatim and satisfies both arms for
// free; the assertion catches a future implementor whose override
// drifts the backward-neighbor-index projection (a permissive
// override that returns `Some(T::CARDINALITY - 1)` at the head —
// folding the head-boundary walk onto a wraparound to the tail-
// index while the composed projection would return `None`; a
// swapped override that returns the successor's index for
// `prev_index`, silently inverting the direction of the index-
// rendered backward walk; a stale override that returns the
// wrong neighbor index after a variant-listing edit reorders
// `T::ALL`) loudly rather than silently bifurcating the backward-
// neighbor-index projection surface every downstream compact
// wire codec / Prometheus per-slot bucket / bitset state machine
// / byte-tagged compact encoding consumer routes through. Clauses
// (26) + (58) + (59) + (66) + (67) together CLOSE the (return-
// type × direction) 3×2 = 6-corner declaration-axis bounded-
// neighbor return-shape surface across the trio of return types:
// `Option<Self>` at clause (26) — [`Self::next`] / [`Self::prev`];
// `Option<&'static str>` at clauses (58) + (59) —
// [`Self::next_label`] / [`Self::prev_label`]; `Option<usize>` at
// clauses (66) + (67) — [`Self::next_index`] /
// [`Self::prev_index`]. Every generic consumer that binds any of
// the six projection methods sees the SAME structural answer at
// every crate boundary regardless of which return-type / direction
// axis corner it walks, and the return-type axis is now closed at
// the {`Self`, label, index} trio on the declaration-axis bounded
// arm.
for &v in T::ALL {
let expected_prev_index = v.prev().map(<T as ClosedSet>::index_of);
assert_eq!(
v.prev_index(),
expected_prev_index,
"{type_name}: {v:?}.prev_index() drifted from {v:?}.prev().map(T::index_of) — the direct (variant → backward-neighbor index) projection no longer agrees with the natural prev+index_of composition, so a downstream compact wire codec / Prometheus per-slot bucket / bitset state machine / byte-tagged compact encoding consumer that binds `v.prev_index()` as its backward-neighbor index-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::first().prev_index(),
None,
"{type_name}: T::first().prev_index() returned Some(_) — the (variant → backward-neighbor index) projection accepted the head-endpoint boundary, silently folding a head-boundary index render onto a wraparound to the tail-index while the natural `prev().map(index_of)` composition should return `None`. Clauses (26) + (67) together pin `T::first().prev_index() == None` as the structural fixpoint the head-endpoint anchor and the backward-neighbor-index axis share, mirroring `T::first().prev() == None` one return-type axis over AND `T::first().prev_label() == None` one return-type axis over",
);
// (68) — For every variant `v` in `T::ALL`,
// `v.sorted_next_index()` MUST equal
// `v.sorted_next().map(T::sorted_index_of)`, AND
// `T::sorted_last().sorted_next_index()` MUST equal `None`. The
// default trait body composes
// `sorted_next(self).map(sorted_index_of)` verbatim and satisfies
// both arms for free; the assertion catches a future implementor
// whose override drifts the forward-lex-neighbor-index projection
// (a permissive override that returns `Some(0)` at the lex-tail —
// folding the lex-tail-boundary walk onto a wraparound to the
// lex-head-slot while the composed projection would return `None`;
// a swapped override that returns the lex-predecessor's lex-slot
// for `sorted_next_index`, silently inverting the direction of
// the lex-index-rendered forward walk; a stale override that
// returns the wrong lex-neighbor lex-slot after a variant-listing
// edit reorders the lex partition) loudly rather than silently
// bifurcating the forward-lex-neighbor-index projection surface
// every downstream alphabetized compact wire codec / lex-sorted
// Prometheus per-lex-slot bucket / lex-sorted bitset state machine
// / Sekiban lex-sorted per-transition audit binner consumer routes
// through. Sibling posture to clauses (27) + (60) + (66) — clause
// (27) pins the `Self`-return lex-neighbor projection at both
// direction arms + lex-endpoint fixpoints, clause (60) pins the
// `&'static str`-return forward-lex-neighbor projection against
// the composition of `sorted_next` + `label`, clause (66) pins
// the `usize`-return forward-neighbor projection against the
// composition of `next` + `index_of` on the declaration axis,
// this clause pins the `usize`-return forward-neighbor projection
// against the composition of `sorted_next` + `sorted_index_of` on
// the LEX axis AND pins the lex-tail-endpoint `None` guard — so
// the closed-set index-shaped forward-neighbor surface stays sound
// at BOTH ordering axes AND on the shared lex-tail-endpoint
// fixpoint (`T::sorted_last().sorted_next_index() == None`).
for &v in T::ALL {
let expected_sorted_next_index = v.sorted_next().map(<T as ClosedSet>::sorted_index_of);
assert_eq!(
v.sorted_next_index(),
expected_sorted_next_index,
"{type_name}: {v:?}.sorted_next_index() drifted from {v:?}.sorted_next().map(T::sorted_index_of) — the direct (variant → forward lex-neighbor lex-slot) projection no longer agrees with the natural sorted_next+sorted_index_of composition, so a downstream alphabetized compact wire codec / lex-sorted Prometheus per-lex-slot bucket / lex-sorted bitset state machine / Sekiban lex-sorted per-transition audit binner consumer that binds `v.sorted_next_index()` as its forward-lex-neighbor lex-slot-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::sorted_last().sorted_next_index(),
None,
"{type_name}: T::sorted_last().sorted_next_index() returned Some(_) — the (variant → forward lex-neighbor lex-slot) projection accepted the lex-tail-endpoint boundary, silently folding a lex-tail-boundary lex-slot render onto a wraparound to the lex-head-slot while the natural `sorted_next().map(sorted_index_of)` composition should return `None`. Clauses (27) + (68) together pin `T::sorted_last().sorted_next_index() == None` as the structural fixpoint the lex-tail-endpoint anchor and the forward-lex-neighbor-index axis share, mirroring `T::sorted_last().sorted_next() == None` one return-type axis over AND `T::sorted_last().sorted_next_label() == None` one return-type axis over AND `T::last().next_index() == None` one ordering axis over",
);
// (69) — For every variant `v` in `T::ALL`,
// `v.sorted_prev_index()` MUST equal
// `v.sorted_prev().map(T::sorted_index_of)`, AND
// `T::sorted_first().sorted_prev_index()` MUST equal `None`. The
// default trait body composes
// `sorted_prev(self).map(sorted_index_of)` verbatim and satisfies
// both arms for free; the assertion catches a future implementor
// whose override drifts the backward-lex-neighbor-index projection
// (a permissive override that returns `Some(T::CARDINALITY - 1)`
// at the lex-head — folding the lex-head-boundary walk onto a
// wraparound to the lex-tail-slot while the composed projection
// would return `None`; a swapped override that returns the lex-
// successor's lex-slot for `sorted_prev_index`, silently inverting
// the direction of the lex-index-rendered backward walk; a stale
// override that returns the wrong lex-neighbor lex-slot after a
// variant-listing edit reorders the lex partition) loudly rather
// than silently bifurcating the backward-lex-neighbor-index
// projection surface every downstream alphabetized compact wire
// codec / lex-sorted Prometheus per-lex-slot bucket / lex-sorted
// bitset state machine consumer routes through. Clauses (26) +
// (27) + (58) + (59) + (60) + (61) + (66) + (67) + (68) + (69)
// together CLOSE the (declaration × lex) × (forward, backward) ×
// (`Self`-return, `&'static str`-return, `usize`-return) 2×2×3 =
// 12-corner bounded-neighbor return-shape hypercube on the closed-
// set traversal surface. Every generic consumer that binds any of
// the twelve projection methods sees the SAME structural answer at
// every crate boundary regardless of which ordering / direction /
// return-type axis corner it walks, and the return-type axis is
// now closed at the {`Self`, label, index} trio on BOTH ordering
// axes of the bounded arm.
for &v in T::ALL {
let expected_sorted_prev_index = v.sorted_prev().map(<T as ClosedSet>::sorted_index_of);
assert_eq!(
v.sorted_prev_index(),
expected_sorted_prev_index,
"{type_name}: {v:?}.sorted_prev_index() drifted from {v:?}.sorted_prev().map(T::sorted_index_of) — the direct (variant → backward lex-neighbor lex-slot) projection no longer agrees with the natural sorted_prev+sorted_index_of composition, so a downstream alphabetized compact wire codec / lex-sorted Prometheus per-lex-slot bucket / lex-sorted bitset state machine consumer that binds `v.sorted_prev_index()` as its backward-lex-neighbor lex-slot-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::sorted_first().sorted_prev_index(),
None,
"{type_name}: T::sorted_first().sorted_prev_index() returned Some(_) — the (variant → backward lex-neighbor lex-slot) projection accepted the lex-head-endpoint boundary, silently folding a lex-head-boundary lex-slot render onto a wraparound to the lex-tail-slot while the natural `sorted_prev().map(sorted_index_of)` composition should return `None`. Clauses (27) + (69) together pin `T::sorted_first().sorted_prev_index() == None` as the structural fixpoint the lex-head-endpoint anchor and the backward-lex-neighbor-index axis share, mirroring `T::sorted_first().sorted_prev() == None` one return-type axis over AND `T::sorted_first().sorted_prev_label() == None` one return-type axis over AND `T::first().prev_index() == None` one ordering axis over",
);
// (70) — For every variant `v` in `T::ALL`,
// `v.cycle_next_index()` MUST equal `T::index_of(v.cycle_next())`,
// AND `T::last().cycle_next_index()` MUST equal `0` (the head-
// endpoint's declaration slot). The default trait body composes
// `cycle_next(self)` with `index_of` verbatim and satisfies both
// arms for free; the assertion catches a future implementor whose
// override drifts the wrapping-forward-neighbor-index projection
// (a permissive override that returns `T::CARDINALITY` at the tail
// — folding the tail-boundary walk onto a one-past-the-end slot
// while the composed projection would return `0`; a swapped
// override that returns the wrapping predecessor's slot for
// `cycle_next_index`, silently inverting the direction of the
// index-rendered cyclic forward walk; a stale override that
// returns the wrong wrapping-neighbor slot after a variant-listing
// edit reorders `T::ALL`) loudly rather than silently bifurcating
// the wrapping-forward-neighbor-index projection surface every
// downstream cyclic round-robin scheduler / carousel-widget
// renderer / Sekiban per-cyclic-transition audit binner consumer
// routes through. Sibling posture to clauses (28) + (62) + (66) —
// clause (28) pins the `Self`-return wrapping-forward-neighbor
// projection at the tail-wrap-to-head fixpoint, clause (62) pins
// the `&'static str`-return wrapping-forward-neighbor projection
// against the composition of `cycle_next` + `label`, clause (66)
// pins the `usize`-return bounded-forward-neighbor projection
// against the composition of `next` + `index_of` on the same
// declaration axis, this clause pins the `usize`-return wrapping-
// forward-neighbor projection against the composition of
// `cycle_next` + `index_of` AND pins the tail-endpoint `0` fold —
// so the closed-set index-shaped forward-neighbor surface stays
// sound at BOTH bounded/wrapping arms AND on the shared tail-
// endpoint fixpoint (`T::last().cycle_next_index() == 0`).
for &v in T::ALL {
let expected_cycle_next_index = <T as ClosedSet>::index_of(v.cycle_next());
assert_eq!(
v.cycle_next_index(),
expected_cycle_next_index,
"{type_name}: {v:?}.cycle_next_index() drifted from T::index_of({v:?}.cycle_next()) — the direct (variant → wrapping forward-neighbor declaration slot) projection no longer agrees with the natural cycle_next+index_of composition, so a downstream cyclic round-robin scheduler / carousel-widget renderer / Sekiban per-cyclic-transition audit binner consumer that binds `v.cycle_next_index()` as its wrapping-forward-neighbor index-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::last().cycle_next_index(),
0,
"{type_name}: T::last().cycle_next_index() != 0 — the (variant → wrapping forward-neighbor declaration slot) projection accepted the tail-endpoint boundary but did not fold onto the head-endpoint's declaration slot 0, so the wrapping arm silently bifurcated from the natural `cycle_next().index_of()` composition. Clauses (28) + (70) together pin `T::last().cycle_next_index() == 0` as the structural fixpoint the tail-endpoint anchor and the forward-wrapping-neighbor-index axis share, mirroring `T::last().cycle_next() == T::first()` one return-type axis over AND `T::last().cycle_next_label() == T::first_label()` one return-type axis over",
);
// (71) — For every variant `v` in `T::ALL`,
// `v.cycle_prev_index()` MUST equal `T::index_of(v.cycle_prev())`,
// AND `T::first().cycle_prev_index()` MUST equal `T::CARDINALITY -
// 1` (the tail-endpoint's declaration slot). The default trait
// body composes `cycle_prev(self)` with `index_of` verbatim and
// satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the wrapping-backward-neighbor-
// index projection (a permissive override that returns
// `T::CARDINALITY` at the head — folding the head-boundary walk
// onto a one-past-the-end slot while the composed projection would
// return `T::CARDINALITY - 1`; a swapped override that returns the
// wrapping successor's slot for `cycle_prev_index`, silently
// inverting the direction of the index-rendered cyclic backward
// walk; a stale override that returns the wrong wrapping-neighbor
// slot after a variant-listing edit reorders `T::ALL`) loudly
// rather than silently bifurcating the wrapping-backward-neighbor-
// index projection surface. Sibling posture to clauses (29) + (63)
// + (67) + (70) on the same 3×2×2 = 12-corner declaration-axis
// wrapping-neighbor-index return-shape face.
for &v in T::ALL {
let expected_cycle_prev_index = <T as ClosedSet>::index_of(v.cycle_prev());
assert_eq!(
v.cycle_prev_index(),
expected_cycle_prev_index,
"{type_name}: {v:?}.cycle_prev_index() drifted from T::index_of({v:?}.cycle_prev()) — the direct (variant → wrapping backward-neighbor declaration slot) projection no longer agrees with the natural cycle_prev+index_of composition, so a downstream cyclic round-robin scheduler / carousel-widget renderer / Sekiban per-cyclic-transition audit binner consumer that binds `v.cycle_prev_index()` as its wrapping-backward-neighbor index-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::first().cycle_prev_index(),
T::ALL.len() - 1,
"{type_name}: T::first().cycle_prev_index() != T::CARDINALITY - 1 — the (variant → wrapping backward-neighbor declaration slot) projection accepted the head-endpoint boundary but did not fold onto the tail-endpoint's declaration slot T::CARDINALITY - 1, so the wrapping arm silently bifurcated from the natural `cycle_prev().index_of()` composition. Clauses (29) + (71) together pin `T::first().cycle_prev_index() == T::CARDINALITY - 1` as the structural fixpoint the head-endpoint anchor and the backward-wrapping-neighbor-index axis share, mirroring `T::first().cycle_prev() == T::last()` one return-type axis over AND `T::first().cycle_prev_label() == T::last_label()` one return-type axis over",
);
// (72) — For every variant `v` in `T::ALL`,
// `v.cycle_sorted_next_index()` MUST equal
// `T::sorted_index_of(v.cycle_sorted_next())`, AND
// `T::sorted_last().cycle_sorted_next_index()` MUST equal `0` (the
// lex-head-endpoint's lex slot). The default trait body composes
// `cycle_sorted_next(self)` with `sorted_index_of` verbatim and
// satisfies both arms for free; the assertion catches a future
// implementor whose override drifts the wrapping-forward-lex-
// neighbor-index projection (a permissive override that returns
// `T::CARDINALITY` at the lex-tail — folding the lex-tail-boundary
// walk onto a one-past-the-end slot while the composed projection
// would return `0`; a swapped override that returns the lex-
// wrapping predecessor's slot for `cycle_sorted_next_index`,
// silently inverting the direction of the lex-index-rendered
// cyclic forward walk; a stale override that returns the wrong
// lex-wrapping-neighbor slot after a variant-listing edit reorders
// the lex partition) loudly rather than silently bifurcating the
// wrapping-forward-lex-neighbor-index projection surface every
// downstream alphabetized-cyclic LSP completion cursor /
// alphabetized round-robin picker / alphabetized carousel widget /
// lex-cyclic per-tick animation frame picker consumer routes
// through. Sibling posture to clauses (28) + (64) + (68) + (70) on
// the (declaration, lex) × (bounded, wrapping) × (`Self`-return,
// `&'static str`-return, `usize`-return) 2×2×3 = 12-corner
// wrapping-forward-neighbor face.
for &v in T::ALL {
let expected_cycle_sorted_next_index =
<T as ClosedSet>::sorted_index_of(v.cycle_sorted_next());
assert_eq!(
v.cycle_sorted_next_index(),
expected_cycle_sorted_next_index,
"{type_name}: {v:?}.cycle_sorted_next_index() drifted from T::sorted_index_of({v:?}.cycle_sorted_next()) — the direct (variant → wrapping forward-lex-neighbor lex-slot) projection no longer agrees with the natural cycle_sorted_next+sorted_index_of composition, so a downstream alphabetized-cyclic LSP completion cursor / alphabetized round-robin picker / alphabetized carousel widget / lex-cyclic per-tick animation frame picker consumer that binds `v.cycle_sorted_next_index()` as its wrapping-forward-lex-neighbor lex-slot-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::sorted_last().cycle_sorted_next_index(),
0,
"{type_name}: T::sorted_last().cycle_sorted_next_index() != 0 — the (variant → wrapping forward-lex-neighbor lex-slot) projection accepted the lex-tail-endpoint boundary but did not fold onto the lex-head-endpoint's lex slot 0, so the wrapping arm silently bifurcated from the natural `cycle_sorted_next().sorted_index_of()` composition. Clauses (64) + (72) together pin `T::sorted_last().cycle_sorted_next_index() == 0` as the structural fixpoint the lex-tail-endpoint anchor and the forward-wrapping-lex-neighbor-index axis share, mirroring `T::sorted_last().cycle_sorted_next() == T::sorted_first()` one return-type axis over AND `T::sorted_last().cycle_sorted_next_label() == T::sorted_first_label()` one return-type axis over AND `T::last().cycle_next_index() == 0` one ordering axis over",
);
// (73) — For every variant `v` in `T::ALL`,
// `v.cycle_sorted_prev_index()` MUST equal
// `T::sorted_index_of(v.cycle_sorted_prev())`, AND
// `T::sorted_first().cycle_sorted_prev_index()` MUST equal
// `T::CARDINALITY - 1` (the lex-tail-endpoint's lex slot). The
// default trait body composes `cycle_sorted_prev(self)` with
// `sorted_index_of` verbatim and satisfies both arms for free; the
// assertion catches a future implementor whose override drifts the
// wrapping-backward-lex-neighbor-index projection (a permissive
// override that returns `T::CARDINALITY` at the lex-head — folding
// the lex-head-boundary walk onto a one-past-the-end slot while
// the composed projection would return `T::CARDINALITY - 1`; a
// swapped override that returns the lex-wrapping successor's slot
// for `cycle_sorted_prev_index`, silently inverting the direction
// of the lex-index-rendered cyclic backward walk; a stale override
// that returns the wrong lex-wrapping-neighbor slot after a
// variant-listing edit reorders the lex partition) loudly rather
// than silently bifurcating the wrapping-backward-lex-neighbor-
// index projection surface. Clauses (26) + (27) + (28) + (29) +
// (58) + (59) + (60) + (61) + (62) + (63) + (64) + (65) + (66) +
// (67) + (68) + (69) + (70) + (71) + (72) + (73) together CLOSE
// the (declaration × lex) × (forward, backward) × (Option-typed-
// bounded, wrapping) × (`Self`-return, `&'static str`-return,
// `usize`-return) 2×2×2×3 = 24-corner bounded-plus-wrapping return-
// shape hypercube on the closed-set traversal surface. Every
// generic consumer that binds any of the twenty-four projection
// methods sees the SAME structural answer at every crate boundary
// regardless of which ordering / direction / bounded-wrapping /
// return-type axis corner it walks, and the return-type axis is
// now closed at the {`Self`, label, index} trio on BOTH ordering
// axes AND on BOTH bounded/wrapping arms.
for &v in T::ALL {
let expected_cycle_sorted_prev_index =
<T as ClosedSet>::sorted_index_of(v.cycle_sorted_prev());
assert_eq!(
v.cycle_sorted_prev_index(),
expected_cycle_sorted_prev_index,
"{type_name}: {v:?}.cycle_sorted_prev_index() drifted from T::sorted_index_of({v:?}.cycle_sorted_prev()) — the direct (variant → wrapping backward-lex-neighbor lex-slot) projection no longer agrees with the natural cycle_sorted_prev+sorted_index_of composition, so a downstream alphabetized-cyclic LSP completion cursor / alphabetized round-robin picker / alphabetized carousel widget consumer that binds `v.cycle_sorted_prev_index()` as its wrapping-backward-lex-neighbor lex-slot-rendering surface would emit the wrong slot for {v:?}",
);
}
assert_eq!(
T::sorted_first().cycle_sorted_prev_index(),
T::ALL.len() - 1,
"{type_name}: T::sorted_first().cycle_sorted_prev_index() != T::CARDINALITY - 1 — the (variant → wrapping backward-lex-neighbor lex-slot) projection accepted the lex-head-endpoint boundary but did not fold onto the lex-tail-endpoint's lex slot T::CARDINALITY - 1, so the wrapping arm silently bifurcated from the natural `cycle_sorted_prev().sorted_index_of()` composition. Clauses (65) + (73) together pin `T::sorted_first().cycle_sorted_prev_index() == T::CARDINALITY - 1` as the structural fixpoint the lex-head-endpoint anchor and the backward-wrapping-lex-neighbor-index axis share, mirroring `T::sorted_first().cycle_sorted_prev() == T::sorted_last()` one return-type axis over AND `T::sorted_first().cycle_sorted_prev_label() == T::sorted_last_label()` one return-type axis over AND `T::first().cycle_prev_index() == T::CARDINALITY - 1` one ordering axis over",
);
// (74) — For every variant `v` in `T::ALL`,
// `T::is_first_index(T::index_of(v))` MUST equal `v.is_first()`,
// AND `T::is_first_index(0) == true`, AND
// `T::is_first_index(T::CARDINALITY) == false` (the out-of-range
// boundary probe). The default trait body is the natural `i == 0`
// literal and satisfies all three arms for free; the assertion
// catches a future implementor whose override drifts the index-
// shaped head-membership predicate (a swapped override that
// returns `true` on the declaration-tail slot `T::CARDINALITY - 1`
// instead of the declaration-head slot `0` — silently folding
// the index-shaped head-membership predicate onto the tail-
// direction predicate at the (head, tail) endpoint-direction
// axis; an offset override that returns `true` on a strictly-
// interior slot; a permissive override that accepts the out-of-
// range `T::CARDINALITY` probe or `usize::MAX` — folding the
// out-of-range boundary onto the head slot every downstream
// index-shaped head-boundary consumer routes through) loudly
// rather than silently bifurcating the declaration-axis index-
// shaped head-membership surface every downstream compact wire
// codec / bitset state machine / Prometheus per-slot bucket
// renderer / byte-tagged compact-encoding consumer routes
// through. Sibling posture to clauses (30) + (50) — clause (30)
// pins the `Self`-arg declaration-axis head-membership predicate
// against `index_of(self) == 0`, clause (50) pins the `&str`-arg
// declaration-axis head-membership predicate against
// `s == T::first_label()`, this clause pins the `usize`-arg
// declaration-axis head-membership predicate against `i == 0` on
// the same declaration-axis head-endpoint slot AND on the
// shared out-of-range boundary probe — so the closed-set index-
// shaped head-membership surface stays sound at every arg-type
// corner (`Self`, `&str`, `usize`) AND on the shared head-
// endpoint fixpoint (`T::is_first_index(0) == true`) AND on the
// shared out-of-range rejection (`T::is_first_index(T::CARDINALITY)
// == false`).
for &v in T::ALL {
let expected_is_first_index = v.is_first();
assert_eq!(
T::is_first_index(<T as ClosedSet>::index_of(v)),
expected_is_first_index,
"{type_name}: T::is_first_index(T::index_of({v:?})) drifted from {v:?}.is_first() — the direct (usize → declaration head-membership bool) projection no longer agrees with the natural `Self`-arg is_first predicate through the (variant → declaration slot) forward projection, so a downstream compact wire codec / bitset state machine / Prometheus per-slot bucket renderer / byte-tagged compact-encoding consumer that binds `T::is_first_index(idx)` as its index-shaped declaration-head-boundary rendering surface would emit the wrong bool for {v:?}'s slot",
);
}
assert!(
T::is_first_index(0),
"{type_name}: T::is_first_index(0) != true — the (usize → declaration head-membership bool) projection rejected the canonical declaration-order head-endpoint slot 0, silently forking the index-shaped head-membership predicate from the natural `i == 0` composition. Clauses (30) + (50) + (74) together pin `T::is_first_index(0) == true` as the structural fixpoint the declaration-head-endpoint slot and the index-shaped head-membership axis share, mirroring `T::first().is_first() == true` one arg-type axis over AND `T::is_first_label(T::first_label()) == true` one arg-type axis over",
);
assert!(
!T::is_first_index(T::ALL.len()),
"{type_name}: T::is_first_index(T::CARDINALITY) != false — the (usize → declaration head-membership bool) projection accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end slot onto the declaration-head-endpoint `true` answer while the natural `i == 0` composition should return `false`. The out-of-range boundary — canonical or otherwise — must reject via the closed-set head-slot literal 0's structural rejection of every non-zero `usize`",
);
// (75) — For every variant `v` in `T::ALL`,
// `T::is_last_index(T::index_of(v))` MUST equal `v.is_last()`,
// AND `T::is_last_index(T::CARDINALITY - 1) == true`, AND
// `T::is_last_index(T::CARDINALITY) == false` (the out-of-range
// boundary probe). The default trait body is the natural
// `i + 1 == T::CARDINALITY` literal and satisfies all three arms
// for free; the assertion catches a future implementor whose
// override drifts the index-shaped tail-membership predicate (a
// swapped override that returns `true` on the declaration-head
// slot `0` instead of the declaration-tail slot `T::CARDINALITY -
// 1` — silently folding the index-shaped tail-membership
// predicate onto the head-direction predicate at the (head, tail)
// endpoint-direction axis; an off-by-one override that returns
// `true` on `T::CARDINALITY` instead of `T::CARDINALITY - 1` —
// silently walking one slot past the tail-endpoint boundary; a
// stale override that returns the wrong slot after a variant-
// listing edit changes the cardinality). Clauses (30) + (31) +
// (32) + (33) + (50) + (51) + (52) + (53) + (74) + (75) together
// CLOSE the (arg-type × ordering × endpoint-direction) 3×2×2 =
// 12-corner endpoint-membership hypercube on the declaration-axis
// face at SIX of the twelve corners: (`Self`, declaration,
// head/tail) at clauses (30), (`&str`, declaration, head/tail) at
// clauses (50) + (51), and now (`usize`, declaration, head/tail)
// at clauses (74) + (75). The remaining SIX corners on the lex-
// axis column (`is_sorted_first_index`, `is_sorted_last_index`,
// plus the six `Self`-arg / `&str`-arg / `usize`-arg lex-endpoint
// predicates) leave the lex-axis face as the natural next lift.
for &v in T::ALL {
let expected_is_last_index = v.is_last();
assert_eq!(
T::is_last_index(<T as ClosedSet>::index_of(v)),
expected_is_last_index,
"{type_name}: T::is_last_index(T::index_of({v:?})) drifted from {v:?}.is_last() — the direct (usize → declaration tail-membership bool) projection no longer agrees with the natural `Self`-arg is_last predicate through the (variant → declaration slot) forward projection, so a downstream compact wire codec / bitset state machine / Prometheus per-slot bucket renderer / byte-tagged compact-encoding consumer that binds `T::is_last_index(idx)` as its index-shaped declaration-tail-boundary rendering surface would emit the wrong bool for {v:?}'s slot",
);
}
assert!(
T::is_last_index(T::ALL.len() - 1),
"{type_name}: T::is_last_index(T::CARDINALITY - 1) != true — the (usize → declaration tail-membership bool) projection rejected the canonical declaration-order tail-endpoint slot T::CARDINALITY - 1, silently forking the index-shaped tail-membership predicate from the natural `i + 1 == T::CARDINALITY` composition. Clauses (30) + (51) + (75) together pin `T::is_last_index(T::CARDINALITY - 1) == true` as the structural fixpoint the declaration-tail-endpoint slot and the index-shaped tail-membership axis share, mirroring `T::last().is_last() == true` one arg-type axis over AND `T::is_last_label(T::last_label()) == true` one arg-type axis over",
);
assert!(
!T::is_last_index(T::ALL.len()),
"{type_name}: T::is_last_index(T::CARDINALITY) != false — the (usize → declaration tail-membership bool) projection accepted the out-of-range boundary probe T::CARDINALITY (one past the tail), silently folding a one-past-the-end slot onto the declaration-tail-endpoint `true` answer while the natural `i + 1 == T::CARDINALITY` composition should return `false` (T::CARDINALITY + 1 > T::CARDINALITY). The out-of-range boundary — canonical or otherwise — must reject via the closed-set tail-slot literal T::CARDINALITY - 1's structural rejection of every out-of-range `usize`",
);
// (76) — For every variant `v` in `T::ALL`,
// `T::is_sorted_first_index(T::sorted_index_of(v))` MUST equal
// `v.is_sorted_first()`, AND `T::is_sorted_first_index(0) == true`,
// AND `T::is_sorted_first_index(T::CARDINALITY) == false` (the out-
// of-range boundary probe). The default trait body is the natural
// `i == 0` literal on a LEX-position input and satisfies all three
// arms for free; the assertion catches a future implementor whose
// override drifts the index-shaped lex-head-membership predicate
// (a swapped override that returns `true` on the lex-tail slot
// `T::CARDINALITY - 1` instead of the lex-head slot `0` — silently
// folding the index-shaped lex-head-membership predicate onto the
// tail-direction predicate at the (head, tail) endpoint-direction
// axis; an offset override that returns `true` on a strictly-
// interior lex slot; a permissive override that accepts the out-
// of-range `T::CARDINALITY` probe or `usize::MAX` — folding the
// out-of-range boundary onto the lex-head slot every downstream
// index-shaped lex-head-boundary consumer routes through; a lex-
// vs-declaration confusion that keys the index-shaped lex-head-
// membership predicate off `index_of` instead of `sorted_index_of`
// — silently bifurcating the lex-axis face onto the declaration-
// axis face every downstream alphabetized compact wire codec /
// lex-sorted Prometheus per-lex-slot bucket renderer consumer
// routes through) loudly rather than silently bifurcating the lex-
// axis index-shaped head-membership surface. Sibling posture to
// clauses (31) + (52) + (74) — clause (31) pins the `Self`-arg
// lex-axis head-membership predicate against `sorted_index_of(self)
// == 0`, clause (52) pins the `&str`-arg lex-axis head-membership
// predicate against `s == T::sorted_first_label()`, clause (74)
// pins the `usize`-arg declaration-axis head-membership predicate
// against `i == 0` on the declaration axis, this clause pins the
// `usize`-arg lex-axis head-membership predicate against `i == 0`
// on the LEX-position input axis AND on the shared out-of-range
// boundary probe — so the closed-set index-shaped head-membership
// surface stays sound at every (arg-type, ordering) corner AND on
// the shared lex-head-endpoint fixpoint
// (`T::is_sorted_first_index(0) == true`) AND on the shared out-of-
// range rejection (`T::is_sorted_first_index(T::CARDINALITY) ==
// false`).
for &v in T::ALL {
let expected_is_sorted_first_index = v.is_sorted_first();
assert_eq!(
T::is_sorted_first_index(<T as ClosedSet>::sorted_index_of(v)),
expected_is_sorted_first_index,
"{type_name}: T::is_sorted_first_index(T::sorted_index_of({v:?})) drifted from {v:?}.is_sorted_first() — the direct (usize → lex head-membership bool) projection on a lex-position input no longer agrees with the natural `Self`-arg is_sorted_first predicate through the (variant → lex slot) forward projection, so a downstream alphabetized compact wire codec / lex-sorted Prometheus per-lex-slot bucket renderer / lex-sorted LSP completion highlighter consumer that binds `T::is_sorted_first_index(lex_idx)` as its index-shaped lex-head-boundary rendering surface would emit the wrong bool for {v:?}'s lex slot",
);
}
assert!(
T::is_sorted_first_index(0),
"{type_name}: T::is_sorted_first_index(0) != true — the (usize → lex head-membership bool) projection on a lex-position input rejected the canonical lex-order head-endpoint slot 0, silently forking the index-shaped lex-head-membership predicate from the natural `i == 0` composition. Clauses (31) + (52) + (76) together pin `T::is_sorted_first_index(0) == true` as the structural fixpoint the lex-head-endpoint slot and the index-shaped lex-head-membership axis share, mirroring `T::sorted_first().is_sorted_first() == true` one arg-type axis over AND `T::is_sorted_first_label(T::sorted_first_label()) == true` one arg-type axis over AND `T::is_first_index(0) == true` one ordering axis over",
);
assert!(
!T::is_sorted_first_index(T::ALL.len()),
"{type_name}: T::is_sorted_first_index(T::CARDINALITY) != false — the (usize → lex head-membership bool) projection on a lex-position input accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end lex slot onto the lex-head-endpoint `true` answer while the natural `i == 0` composition should return `false`. The out-of-range boundary — canonical or otherwise — must reject via the closed-set lex-head-slot literal 0's structural rejection of every non-zero `usize`",
);
// (77) — For every variant `v` in `T::ALL`,
// `T::is_sorted_last_index(T::sorted_index_of(v))` MUST equal
// `v.is_sorted_last()`, AND `T::is_sorted_last_index(T::CARDINALITY
// - 1) == true`, AND `T::is_sorted_last_index(T::CARDINALITY) ==
// false` (the out-of-range boundary probe). The default trait body
// is the natural `i + 1 == T::CARDINALITY` literal (via
// `checked_add` to avoid `usize::MAX` overflow) on a LEX-position
// input and satisfies all three arms for free; the assertion
// catches a future implementor whose override drifts the index-
// shaped lex-tail-membership predicate (a swapped override that
// returns `true` on the lex-head slot `0` instead of the lex-tail
// slot `T::CARDINALITY - 1` — silently folding the index-shaped
// lex-tail-membership predicate onto the head-direction predicate
// at the (head, tail) endpoint-direction axis; an off-by-one
// override that returns `true` on `T::CARDINALITY` instead of
// `T::CARDINALITY - 1` — silently walking one lex slot past the
// lex-tail-endpoint boundary; a stale override that returns the
// wrong lex slot after a variant-listing edit changes the
// cardinality; a lex-vs-declaration confusion that keys the index-
// shaped lex-tail-membership predicate off `index_of` instead of
// `sorted_index_of`). Clauses (30) + (31) + (32) + (33) + (50) +
// (51) + (52) + (53) + (74) + (75) + (76) + (77) together CLOSE
// the (arg-type × ordering × endpoint-direction) 3×2×2 = 12-corner
// endpoint-membership hypercube on the closed-set boundary surface
// EXHAUSTIVELY at all twelve corners: (`Self`, declaration,
// head/tail) at clauses (30) — [`is_first`] / [`is_last`]; (`Self`,
// lex, head/tail) at clauses (31) — [`is_sorted_first`] /
// [`is_sorted_last`]; (`&str`, declaration, head/tail) at clauses
// (50) + (51) — [`is_first_label`] / [`is_last_label`]; (`&str`,
// lex, head/tail) at clauses (52) + (53) — [`is_sorted_first_label`]
// / [`is_sorted_last_label`]; (`usize`, declaration, head/tail) at
// clauses (74) + (75) — [`is_first_index`] / [`is_last_index`];
// and now (`usize`, lex, head/tail) at clauses (76) + (77) —
// [`is_sorted_first_index`] / [`is_sorted_last_index`]. Every
// generic consumer that binds any of the twelve endpoint-
// membership methods sees the SAME endpoint-membership answer at
// every crate boundary regardless of which arg-type / ordering /
// endpoint-direction axis it walks. The natural next lift is the
// (endpoint-partition axis) arm on the `usize` column
// (`is_endpoint_index`, `is_interior_index`,
// `is_sorted_endpoint_index`, `is_sorted_interior_index`) — the
// `Self` and `&str` columns of that surface already exist at
// clauses (32) + (33) + (54) + (55) + (56) + (57).
for &v in T::ALL {
let expected_is_sorted_last_index = v.is_sorted_last();
assert_eq!(
T::is_sorted_last_index(<T as ClosedSet>::sorted_index_of(v)),
expected_is_sorted_last_index,
"{type_name}: T::is_sorted_last_index(T::sorted_index_of({v:?})) drifted from {v:?}.is_sorted_last() — the direct (usize → lex tail-membership bool) projection on a lex-position input no longer agrees with the natural `Self`-arg is_sorted_last predicate through the (variant → lex slot) forward projection, so a downstream alphabetized compact wire codec / lex-sorted Prometheus per-lex-slot bucket renderer / lex-sorted LSP completion highlighter consumer that binds `T::is_sorted_last_index(lex_idx)` as its index-shaped lex-tail-boundary rendering surface would emit the wrong bool for {v:?}'s lex slot",
);
}
assert!(
T::is_sorted_last_index(T::ALL.len() - 1),
"{type_name}: T::is_sorted_last_index(T::CARDINALITY - 1) != true — the (usize → lex tail-membership bool) projection on a lex-position input rejected the canonical lex-order tail-endpoint slot T::CARDINALITY - 1, silently forking the index-shaped lex-tail-membership predicate from the natural `i + 1 == T::CARDINALITY` composition. Clauses (31) + (53) + (77) together pin `T::is_sorted_last_index(T::CARDINALITY - 1) == true` as the structural fixpoint the lex-tail-endpoint slot and the index-shaped lex-tail-membership axis share, mirroring `T::sorted_last().is_sorted_last() == true` one arg-type axis over AND `T::is_sorted_last_label(T::sorted_last_label()) == true` one arg-type axis over AND `T::is_last_index(T::CARDINALITY - 1) == true` one ordering axis over",
);
assert!(
!T::is_sorted_last_index(T::ALL.len()),
"{type_name}: T::is_sorted_last_index(T::CARDINALITY) != false — the (usize → lex tail-membership bool) projection on a lex-position input accepted the out-of-range boundary probe T::CARDINALITY (one past the lex-tail), silently folding a one-past-the-end lex slot onto the lex-tail-endpoint `true` answer while the natural `i + 1 == T::CARDINALITY` composition should return `false`. The out-of-range boundary — canonical or otherwise — must reject via the closed-set lex-tail-slot literal T::CARDINALITY - 1's structural rejection of every out-of-range `usize`",
);
// (78) — For every variant `v` in `T::ALL`,
// `T::is_endpoint_index(T::index_of(v))` MUST equal `v.is_endpoint()`,
// AND `T::is_endpoint_index(T::CARDINALITY) == false` (the out-of-
// range boundary probe). The default trait body is the disjunction
// `is_first_index(i) || is_last_index(i)` composing the two pre-
// existing declaration-axis index-shaped point-membership
// primitives; the assertion catches a future implementor whose
// override drifts the index-shaped declaration-boundary-membership
// predicate (a swapped override that returns `true` on strictly-
// interior slots and `false` on the endpoint slots; an offset
// override that folds the disjunction onto only ONE endpoint arm;
// a permissive override that accepts the out-of-range
// `T::CARDINALITY` probe or `usize::MAX` — folding the out-of-range
// boundary onto the `true` answer every downstream index-shaped
// declaration-boundary consumer routes through). Sibling posture
// to clauses (32) + (54) — clause (32) pins the `Self`-arg
// declaration-axis boundary-membership predicate against
// `is_first(self) || is_last(self)`, clause (54) pins the
// `&str`-arg declaration-axis boundary-membership predicate
// against `is_first_label(s) || is_last_label(s)`, this clause
// pins the `usize`-arg declaration-axis boundary-membership
// predicate against `is_first_index(i) || is_last_index(i)` on
// the DECLARATION-slot input axis. Opens the `usize`-arg column
// of the (arg-type × ordering × predicate-flavor) 3×2×2 = 12-
// corner boolean-boundary hypercube at the (declaration, endpoint)
// corner — the `Self` and `&str` columns of this surface already
// exist at clauses (32) + (33) + (54) + (55) + (56) + (57).
for &v in T::ALL {
let expected_is_endpoint_index = v.is_endpoint();
assert_eq!(
T::is_endpoint_index(<T as ClosedSet>::index_of(v)),
expected_is_endpoint_index,
"{type_name}: T::is_endpoint_index(T::index_of({v:?})) drifted from {v:?}.is_endpoint() — the direct (usize → declaration boundary-membership bool) projection no longer agrees with the natural `Self`-arg is_endpoint predicate through the (variant → declaration slot) forward projection, so a downstream compact wire codec / bitset state machine / Prometheus per-slot bucket renderer / byte-tagged compact-encoding consumer that binds `T::is_endpoint_index(idx)` as its index-shaped declaration-boundary rendering surface would emit the wrong bool for {v:?}'s slot",
);
}
assert!(
!T::is_endpoint_index(T::ALL.len()),
"{type_name}: T::is_endpoint_index(T::CARDINALITY) != false — the (usize → declaration boundary-membership bool) projection accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end slot onto the declaration-boundary `true` answer while the natural `is_first_index(i) || is_last_index(i)` composition should return `false`. The out-of-range boundary — canonical or otherwise — must reject via the closed-set head-slot literal `0`'s and tail-slot literal `T::CARDINALITY - 1`'s structural rejection of every out-of-range `usize`",
);
// (79) — For every variant `v` in `T::ALL`,
// `T::is_interior_index(T::index_of(v))` MUST equal
// `v.is_interior()`, AND `T::is_interior_index(T::CARDINALITY) ==
// false` (the out-of-range boundary probe), AND per-slot
// complementarity `T::is_endpoint_index(i) !=
// T::is_interior_index(i)` for every `i ∈ 0..T::CARDINALITY`. The
// default trait body is the natural
// `i < T::CARDINALITY && !is_endpoint_index(i)` composition; the
// assertion catches a future implementor whose override drifts the
// index-shaped declaration-interior-membership predicate (a
// swapped override that returns `true` on the endpoint slots; a
// permissive override that returns `true` on `T::CARDINALITY` or
// `usize::MAX` — silently folding the out-of-range boundary onto
// the interior `true` answer; a missing domain gate override that
// returns `!is_endpoint_index(i)` unconditionally — silently
// folding every out-of-range `usize` onto the interior `true`
// answer). Sibling posture to clauses (32) + (55) — clause (32)
// pins the `Self`-arg declaration-interior predicate against
// `!is_endpoint(self)` (no domain gate needed on the closed
// `Self`-arg), clause (55) pins the `&str`-arg declaration-
// interior predicate against `contains_label(s) &&
// !is_endpoint_label(s)` (with the `contains_label` domain gate),
// this clause pins the `usize`-arg declaration-interior predicate
// against `i < T::CARDINALITY && !is_endpoint_index(i)` (with the
// canonical-index-range domain gate — the natural `usize`-arg
// parallel of `contains_label`'s canonical-label domain gate).
for &v in T::ALL {
let expected_is_interior_index = v.is_interior();
assert_eq!(
T::is_interior_index(<T as ClosedSet>::index_of(v)),
expected_is_interior_index,
"{type_name}: T::is_interior_index(T::index_of({v:?})) drifted from {v:?}.is_interior() — the direct (usize → declaration interior-membership bool) projection no longer agrees with the natural `Self`-arg is_interior predicate through the (variant → declaration slot) forward projection, so a downstream bounded interior-loop / phase-fold reducer / interior-completion pass consumer that binds `T::is_interior_index(idx)` would drift for {v:?}'s slot",
);
}
assert!(
!T::is_interior_index(T::ALL.len()),
"{type_name}: T::is_interior_index(T::CARDINALITY) != false — the (usize → declaration interior-membership bool) projection accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end slot onto the declaration-interior `true` answer while the natural `i < T::CARDINALITY && !is_endpoint_index(i)` composition should return `false`. The canonical-index-range domain gate must reject every out-of-range `usize`, mirroring `contains_label(s)`'s canonical-label domain gate on the `&str`-arg axis one arg-type axis over",
);
for i in 0..T::ALL.len() {
assert_ne!(
T::is_endpoint_index(i),
T::is_interior_index(i),
"{type_name}: T::is_endpoint_index({i}) == T::is_interior_index({i}) — the (declaration-endpoint, declaration-interior) partition collapsed on slot {i}, breaking the boolean-partition contract every generic consumer expects. On every canonical slot in 0..T::CARDINALITY the two predicates MUST answer complementary bools, mirroring the `Self`-arg complementarity clause (32) one arg-type axis over AND the `&str`-arg complementarity clause (55) one arg-type axis over",
);
}
// (80) — For every variant `v` in `T::ALL`,
// `T::is_sorted_endpoint_index(T::sorted_index_of(v))` MUST equal
// `v.is_sorted_endpoint()`, AND
// `T::is_sorted_endpoint_index(T::CARDINALITY) == false` (the out-
// of-range boundary probe). The default trait body is the
// disjunction `is_sorted_first_index(i) ||
// is_sorted_last_index(i)` composing the two pre-existing lex-axis
// index-shaped point-membership primitives; the assertion catches
// a future implementor whose override drifts the lex-axis index-
// shaped boundary-membership predicate (a lex-vs-declaration
// confusion that keys the lex-axis predicate off `index_of`
// instead of `sorted_index_of` — silently bifurcating the lex
// axis onto the declaration face). Sibling posture to clauses
// (33) + (56) + (78) — clause (33) pins the `Self`-arg lex-axis
// boundary predicate, clause (56) pins the `&str`-arg lex-axis
// boundary predicate, clause (78) pins the `usize`-arg
// declaration-axis boundary predicate, this clause pins the
// `usize`-arg LEX-axis boundary predicate.
for &v in T::ALL {
let expected_is_sorted_endpoint_index = v.is_sorted_endpoint();
assert_eq!(
T::is_sorted_endpoint_index(<T as ClosedSet>::sorted_index_of(v)),
expected_is_sorted_endpoint_index,
"{type_name}: T::is_sorted_endpoint_index(T::sorted_index_of({v:?})) drifted from {v:?}.is_sorted_endpoint() — the direct (usize → lex boundary-membership bool) projection on a lex-position input no longer agrees with the natural `Self`-arg is_sorted_endpoint predicate through the (variant → lex slot) forward projection, so a downstream alphabetized-boundary compact wire codec / lex-sorted Prometheus per-lex-slot bucket renderer consumer that binds `T::is_sorted_endpoint_index(lex_idx)` would emit the wrong bool for {v:?}'s lex slot",
);
}
assert!(
!T::is_sorted_endpoint_index(T::ALL.len()),
"{type_name}: T::is_sorted_endpoint_index(T::CARDINALITY) != false — the (usize → lex boundary-membership bool) projection on a lex-position input accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end lex slot onto the lex-boundary `true` answer while the natural `is_sorted_first_index(i) || is_sorted_last_index(i)` composition should return `false`",
);
// (81) — For every variant `v` in `T::ALL`,
// `T::is_sorted_interior_index(T::sorted_index_of(v))` MUST equal
// `v.is_sorted_interior()`, AND
// `T::is_sorted_interior_index(T::CARDINALITY) == false` (the out-
// of-range boundary probe), AND per-slot complementarity
// `T::is_sorted_endpoint_index(i) != T::is_sorted_interior_index(i)`
// for every `i ∈ 0..T::CARDINALITY`. Closes the (`usize`, lex,
// interior) corner and the FINAL corner of the (arg-type ×
// ordering × predicate-flavor) 3×2×2 = 12-corner boolean-boundary
// hypercube alongside clauses (32) + (33) + (54) + (55) + (56) +
// (57) + (78) + (79) + (80). Every generic consumer that binds
// any of the twelve endpoint-partition methods sees the SAME
// partition answer at every crate boundary regardless of which
// arg-type / ordering / predicate-flavor axis it walks. The
// natural next lift is the (endpoint-partition-agreement) axis
// across the twelve corners — pairwise agreement between the
// three arg-type columns on the same (ordering, predicate-flavor)
// corner — or the (endpoint-partition axis) fold onto the
// wrapping-neighbor + neighbor projections (a
// `sorted_next_index_or_wrap_endpoint` composite that renders the
// wrapping neighbor iff the current lex slot is strictly-lex-
// interior).
for &v in T::ALL {
let expected_is_sorted_interior_index = v.is_sorted_interior();
assert_eq!(
T::is_sorted_interior_index(<T as ClosedSet>::sorted_index_of(v)),
expected_is_sorted_interior_index,
"{type_name}: T::is_sorted_interior_index(T::sorted_index_of({v:?})) drifted from {v:?}.is_sorted_interior() — the direct (usize → lex interior-membership bool) projection on a lex-position input no longer agrees with the natural `Self`-arg is_sorted_interior predicate through the (variant → lex slot) forward projection, so a downstream bounded lex-interior loop / lex-phase-fold reducer / alphabetized-completion interior-hiding consumer that binds `T::is_sorted_interior_index(lex_idx)` would drift for {v:?}'s lex slot",
);
}
assert!(
!T::is_sorted_interior_index(T::ALL.len()),
"{type_name}: T::is_sorted_interior_index(T::CARDINALITY) != false — the (usize → lex interior-membership bool) projection on a lex-position input accepted the out-of-range boundary probe T::CARDINALITY, silently folding a one-past-the-end lex slot onto the lex-interior `true` answer while the natural `i < T::CARDINALITY && !is_sorted_endpoint_index(i)` composition should return `false`",
);
for i in 0..T::ALL.len() {
assert_ne!(
T::is_sorted_endpoint_index(i),
T::is_sorted_interior_index(i),
"{type_name}: T::is_sorted_endpoint_index({i}) == T::is_sorted_interior_index({i}) — the (lex-endpoint, lex-interior) partition collapsed on lex slot {i}, breaking the boolean-partition contract every generic consumer expects. On every canonical slot in 0..T::CARDINALITY the two predicates MUST answer complementary bools, mirroring the `Self`-arg complementarity clause (33) one arg-type axis over AND the `&str`-arg complementarity clause (57) one arg-type axis over",
);
}
// (82) — `T::index_of_label_with_hint` composes
// `find_by_label_with_hint` + `index_of` verbatim on the Ok arm
// AND preserves the `Option<Self>` hint slot on the Err arm.
// Every variant decodes to `Ok(v.index_of())` through the
// structured surface; the reserved probe rejects with `Err(None)`
// — the same 38-char probe clause (7) reserves as beyond
// `suggest_closest`'s bounded edit distance by construction; the
// empty-string boundary clause (4) reserves as structurally
// outside the closed set rejects with `Err(_)` (the hint slot's
// shape on the empty-string arm is `suggest_closest`'s call —
// typically `None` but not fixed by contract, so the assertion
// matches on the reject side alone). The default trait body
// satisfies the clause for free; the assertion catches an
// override that drifts the composition (accepts the probe as Ok
// through a permissive index return, fabricates a hint slot the
// sibling `find_by_label_with_hint` doesn't surface, OR emits the
// wrong declaration-order slot on a canonical variant). Sibling
// posture to clause (13) on the (return-type × hint) 2×2 axis of
// the closed-set structured-decode surface — clause (13) pins
// the `Self`-typed decode arm's alignment with
// `find_by_label + suggest_closest`, this clause pins the
// `usize`-typed decode arm's alignment with
// `find_by_label_with_hint + index_of`. Together the two
// clauses close both columns of the (return-type × hint) 2×2
// corner on the (with-hint) row.
for &v in T::ALL {
let label = v.label();
match T::index_of_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v.index_of(),
"{type_name}: index_of_label_with_hint round-trip {label:?} → variant decoded to slot {decoded} but v.index_of() == {} — the structured (`&str → usize` with hint) decode drifted from the natural `find_by_label_with_hint(s).map(index_of)` composition on the accept arm",
v.index_of(),
),
Err(_) => panic!(
"{type_name}: index_of_label_with_hint round-trip {label:?} → canonical variant rejected by the structured (`&str → usize` with hint) decode",
),
}
}
match T::index_of_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: index_of_label_with_hint accepted the reserved probe input — the structured zero-allocation `usize`-typed decode MUST reject every input outside the closed set",
),
Err(hint) => assert!(
hint.is_none(),
"{type_name}: index_of_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
),
}
// Cross-column alignment with clause (13)'s sibling primitive —
// on EVERY probe (canonical labels + reserved probe + empty
// string) the two structured-decode surfaces MUST agree on
// membership AND on the typed hint variant. `Ok`-arm's typed
// hint is structurally absent (`suggest_closest` never fires on
// the accept path), so alignment on the accept path degenerates
// to `index_of_label_with_hint(s) == Ok(v.index_of())` when
// `find_by_label_with_hint(s) == Ok(v)`. `Err`-arm's typed hint
// is [`Self::suggest_closest`]'s answer on the same input, so
// alignment holds iff both siblings surface the SAME
// `Option<Self>` hint variant on the reject arm.
for &v in T::ALL {
let label = v.label();
let hint_decode = T::index_of_label_with_hint(label);
let carrier_decode = T::find_by_label_with_hint(label);
match (hint_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.index_of(),
"{type_name}: index_of_label_with_hint({label:?}) accepted at slot {idx} but find_by_label_with_hint({label:?}) accepted at variant {w:?} whose index_of() == {} — the two structured-decode surfaces bifurcated on the accept arm's typed slot",
w.index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both structured-decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: index_of_label_with_hint({label:?}) and find_by_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the structured-decode surface bifurcated across the (return-type) axis",
),
}
}
match (
T::index_of_label_with_hint(probe),
T::find_by_label_with_hint(probe),
) {
(Err(hint_a), Err(hint_b)) => assert_eq!(
hint_a, hint_b,
"{type_name}: index_of_label_with_hint(reserved probe) and find_by_label_with_hint(reserved probe) disagreed on the typed hint slot — the structured-decode surface bifurcated on the (hint) axis's Option<Self> variant across the two return-type columns",
),
_ => panic!(
"{type_name}: index_of_label_with_hint / find_by_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (83) — `T::sorted_index_of_label_with_hint` composes
// `find_by_label_with_hint` + `sorted_index_of` verbatim on the Ok
// arm AND preserves the `Option<Self>` hint slot on the Err arm.
// Every variant decodes to `Ok(v.sorted_index_of())` through the
// structured surface; the reserved probe rejects with `Err(None)`
// — the same 38-char probe reserved as beyond `suggest_closest`'s
// bounded edit distance by construction. The default trait body
// satisfies the clause for free; the assertion catches an override
// that drifts the composition (accepts the probe as Ok through a
// permissive lex-index return, fabricates a hint slot the sibling
// `find_by_label_with_hint` doesn't surface, OR emits the wrong
// lex-order slot on a canonical variant). Sibling posture to clause
// (82) one ordering-axis over on the (return-type × hint × ordering)
// 2×2×2 axis of the closed-set structured-decode surface — clause
// (82) pins the `usize`-typed DECLARATION-order decode arm's
// alignment with `find_by_label_with_hint + index_of`, this clause
// pins the `usize`-typed LEX-order decode arm's alignment with
// `find_by_label_with_hint + sorted_index_of`. Together (13) + (82)
// + (83) close the with-hint row of the (return-type × ordering)
// 2×2 corner on the structured-decode surface — the `Self`-typed
// carrier decode at (13), the `usize`-typed declaration-order
// decode at (82), the `usize`-typed lex-order decode at (83). The
// (`Self`-typed, lex-ordering) corner collapses onto (13) because
// the carrier decode's typed variant carries no ordering-axis
// distinction, so the with-hint face of the cube CLOSES at THREE
// populated corners.
for &v in T::ALL {
let label = v.label();
match T::sorted_index_of_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v.sorted_index_of(),
"{type_name}: sorted_index_of_label_with_hint round-trip {label:?} → variant decoded to lex slot {decoded} but v.sorted_index_of() == {} — the structured (`&str → usize` lex-order with hint) decode drifted from the natural `find_by_label_with_hint(s).map(sorted_index_of)` composition on the accept arm",
v.sorted_index_of(),
),
Err(_) => panic!(
"{type_name}: sorted_index_of_label_with_hint round-trip {label:?} → canonical variant rejected by the structured (`&str → usize` lex-order with hint) decode",
),
}
}
match T::sorted_index_of_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: sorted_index_of_label_with_hint accepted the reserved probe input — the structured zero-allocation `usize`-typed lex-order decode MUST reject every input outside the closed set",
),
Err(hint) => assert!(
hint.is_none(),
"{type_name}: sorted_index_of_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
),
}
// Cross-column alignment with clause (13)'s sibling primitive on
// the (return-type) axis AND cross-ordering alignment with clause
// (82) one ordering-axis over — on EVERY probe (canonical labels +
// reserved probe) the three structured-decode surfaces MUST agree
// on membership AND on the typed hint variant. Alignment against
// `find_by_label_with_hint` on the accept arm degenerates to
// `sorted_index_of_label_with_hint(s) == Ok(v.sorted_index_of())`
// when `find_by_label_with_hint(s) == Ok(v)`. Alignment against
// `index_of_label_with_hint` on the reject arm demands the SAME
// `Option<Self>` hint variant — the hint carrier is
// ordering-axis-independent (both `usize`-typed structured decodes
// route through the same `suggest_closest` on miss), so the two
// decode surfaces MUST surface the same typed hint.
for &v in T::ALL {
let label = v.label();
let lex_decode = T::sorted_index_of_label_with_hint(label);
let carrier_decode = T::find_by_label_with_hint(label);
match (lex_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.sorted_index_of(),
"{type_name}: sorted_index_of_label_with_hint({label:?}) accepted at lex slot {idx} but find_by_label_with_hint({label:?}) accepted at variant {w:?} whose sorted_index_of() == {} — the two structured-decode surfaces bifurcated on the accept arm's typed lex slot",
w.sorted_index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: sorted_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both structured-decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: sorted_index_of_label_with_hint({label:?}) and find_by_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the structured-decode surface bifurcated across the (return-type × ordering) axis",
),
}
}
match (
T::sorted_index_of_label_with_hint(probe),
T::find_by_label_with_hint(probe),
) {
(Err(hint_a), Err(hint_b)) => assert_eq!(
hint_a, hint_b,
"{type_name}: sorted_index_of_label_with_hint(reserved probe) and find_by_label_with_hint(reserved probe) disagreed on the typed hint slot — the structured-decode surface bifurcated on the (hint) axis's Option<Self> variant across the (return-type × ordering) axes",
),
_ => panic!(
"{type_name}: sorted_index_of_label_with_hint / find_by_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
match (
T::sorted_index_of_label_with_hint(probe),
T::index_of_label_with_hint(probe),
) {
(Err(hint_a), Err(hint_b)) => assert_eq!(
hint_a, hint_b,
"{type_name}: sorted_index_of_label_with_hint(reserved probe) and index_of_label_with_hint(reserved probe) disagreed on the typed hint slot — the two `usize`-typed structured-decode surfaces bifurcated on the (hint) axis's Option<Self> variant across the (ordering) axis",
),
_ => panic!(
"{type_name}: sorted_index_of_label_with_hint / index_of_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (84) — `T::parse_index_of_label` composes `parse_label` +
// `index_of` verbatim on the Ok arm AND preserves the
// `Self::Unknown` carrier shape on the Err arm. Every variant
// decodes to `Ok(v.index_of())` through the structured surface;
// the reserved probe rejects with the SAME substrate-wide
// `unknown {SET_LABEL}: {input}` carrier `parse_label` emits —
// both allocating-carrier decoders route through
// `make_unknown(probe)` on the reject arm, so the Display of
// the rejected carrier MUST render identically across the two
// return-type columns. The default trait body satisfies the
// clause for free; the assertion catches an override that
// drifts the composition (accepts the probe as Ok through a
// permissive index return, fabricates a different Unknown
// carrier shape than `parse_label` surfaces, OR emits the
// wrong declaration-order slot on a canonical variant). Sibling
// posture to clauses (7) + (21) + (82) on the (return-type ×
// side-effect × ordering × hint) 4-axis surface — clause (7)
// pins the `Self`-typed allocating-carrier decode with-hint
// arm's alignment, clause (21) pins the `usize`-typed decl-
// order non-allocating decode arm's alignment, clause (82) pins
// the `usize`-typed decl-order non-allocating decode with-hint
// arm's alignment, this clause pins the `usize`-typed decl-
// order allocating-carrier decode arm's alignment with
// `parse_label + index_of`. Together (2) + (7) + (21) + (82) +
// (84) close the allocating-carrier column on the (return-type
// × side-effect) 2×2 face at every populated (return-type)
// row of the (`Self`, `usize`-decl) partition — the (no-hint)
// corner on each row (parse_label at Self, parse_index_of_label
// at usize-decl) and the (with-hint) corner on the Self row
// (parse_label_with_hint at (7)). The (`usize`-decl with-hint,
// allocating-carrier) corner remains an unopened sibling that
// a future lift over `parse_label_with_hint + index_of` closes
// one axis further along the (hint) column — the sibling posture
// this clause's (usize-decl, no-hint) corner opens.
for &v in T::ALL {
let label = v.label();
match T::parse_index_of_label(label) {
Ok(decoded) => assert_eq!(
decoded, v.index_of(),
"{type_name}: parse_index_of_label round-trip {label:?} → variant decoded to declaration-order slot {decoded} but v.index_of() == {} — the allocating-carrier (`&str → usize` decl-order) decode drifted from the natural `parse_label(s).map(index_of)` composition on the accept arm",
v.index_of(),
),
Err(_) => panic!(
"{type_name}: parse_index_of_label round-trip {label:?} → canonical variant rejected by the allocating-carrier (`&str → usize` decl-order) decode",
),
}
}
match T::parse_index_of_label(probe) {
Ok(_) => panic!(
"{type_name}: parse_index_of_label accepted the reserved probe input — the allocating-carrier `usize`-typed decl-order decode MUST reject every input outside the closed set",
),
Err(carrier) => assert_eq!(
carrier.to_string(),
expected,
"{type_name}: parse_index_of_label's Err carrier drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the override emits a different carrier than `parse_label` would",
),
}
assert!(
T::parse_index_of_label("").is_err(),
"{type_name}: parse_index_of_label accepted the empty string — the empty-string boundary is structurally reserved outside the closed set at every allocating-carrier decode column",
);
// Cross-column alignment with clause (2)'s sibling primitive on the
// (return-type) axis — on EVERY probe (canonical labels + reserved
// probe + empty-string boundary) the two allocating-carrier decode
// surfaces MUST agree on membership AND on the Unknown carrier
// shape on rejection. Alignment against `parse_label` on the
// accept arm degenerates to
// `parse_index_of_label(s) == Ok(v.index_of())` when
// `parse_label(s) == Ok(v)`. Alignment against `parse_label` on
// the reject arm demands the SAME `Self::Unknown` carrier
// Display — the carrier renders through the substrate-wide
// `unknown {SET_LABEL}: {input}` shape at both return-type
// columns, so the two Displays MUST match byte-for-byte on
// every reject payload.
for &v in T::ALL {
let label = v.label();
let index_decode = T::parse_index_of_label(label);
let carrier_decode = T::parse_label(label);
match (index_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.index_of(),
"{type_name}: parse_index_of_label({label:?}) accepted at decl slot {idx} but parse_label({label:?}) accepted at variant {w:?} whose index_of() == {} — the two allocating-carrier decode surfaces bifurcated on the accept arm's typed decl slot",
w.index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_index_of_label({label:?}) rejected a canonical variant label — the accept arm on both allocating-carrier decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_index_of_label({label:?}) and parse_label({label:?}) disagreed on the (accept, reject) partition — the allocating-carrier decode surface bifurcated across the (return-type) axis",
),
}
}
match (T::parse_index_of_label(probe), T::parse_label(probe)) {
(Err(carrier_a), Err(carrier_b)) => assert_eq!(
carrier_a.to_string(),
carrier_b.to_string(),
"{type_name}: parse_index_of_label(reserved probe) and parse_label(reserved probe) disagreed on the `Self::Unknown` carrier's Display rendering — the allocating-carrier decode surface bifurcated on the Unknown carrier shape across the (return-type) axis",
),
_ => panic!(
"{type_name}: parse_index_of_label / parse_label accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (85) — `T::parse_sorted_index_of_label` composes `parse_label` +
// `sorted_index_of` verbatim on the Ok arm AND preserves the
// `Self::Unknown` carrier shape on the Err arm. Every variant
// decodes to `Ok(v.sorted_index_of())` through the structured
// surface; the reserved probe rejects with the SAME substrate-
// wide `unknown {SET_LABEL}: {input}` carrier `parse_label` emits
// — all three allocating-carrier decoders route through
// `make_unknown(probe)` on the reject arm, so the Display of the
// rejected carrier MUST render identically across the three
// return-type columns (`Self`, `usize`-decl, `usize`-lex). The
// default trait body satisfies the clause for free; the
// assertion catches an override that drifts the composition
// (accepts the probe as Ok through a permissive lex-index
// return, fabricates a different Unknown carrier shape than
// `parse_label` surfaces, OR emits the wrong lex-order slot on a
// canonical variant). Sibling posture to clauses (2) + (7) +
// (21) + (82) + (83) + (84) on the (return-type × side-effect ×
// ordering × hint) 4-axis surface — clause (84) at
// `parse_index_of_label` on the (allocating, no-hint, decl)
// corner, this clause at `parse_sorted_index_of_label` on the
// (allocating, no-hint, lex) corner. Together (2) + (84) + (85)
// close the allocating-carrier no-hint face across ALL THREE
// return-type columns (`Self`, `usize`-decl, `usize`-lex),
// completing the (return-type × ordering) 3×2 partition of the
// structured no-hint carrier-decode surface at every populated
// corner. The (`Self`-typed, lex-ordering) corner collapses onto
// (2) because the carrier decode's typed variant carries no
// ordering-axis distinction. The remaining unopened siblings —
// (`usize`-decl, allocating, with-hint) at a future
// `parse_index_of_label_with_hint` and (`usize`-lex, allocating,
// with-hint) at a future `parse_sorted_index_of_label_with_hint`
// — sit one axis further along the (hint) column.
for &v in T::ALL {
let label = v.label();
match T::parse_sorted_index_of_label(label) {
Ok(decoded) => assert_eq!(
decoded, v.sorted_index_of(),
"{type_name}: parse_sorted_index_of_label round-trip {label:?} → variant decoded to lex-order slot {decoded} but v.sorted_index_of() == {} — the allocating-carrier (`&str → usize` lex-order) decode drifted from the natural `parse_label(s).map(sorted_index_of)` composition on the accept arm",
v.sorted_index_of(),
),
Err(_) => panic!(
"{type_name}: parse_sorted_index_of_label round-trip {label:?} → canonical variant rejected by the allocating-carrier (`&str → usize` lex-order) decode",
),
}
}
match T::parse_sorted_index_of_label(probe) {
Ok(_) => panic!(
"{type_name}: parse_sorted_index_of_label accepted the reserved probe input — the allocating-carrier `usize`-typed lex-order decode MUST reject every input outside the closed set",
),
Err(carrier) => assert_eq!(
carrier.to_string(),
expected,
"{type_name}: parse_sorted_index_of_label's Err carrier drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the override emits a different carrier than `parse_label` would",
),
}
assert!(
T::parse_sorted_index_of_label("").is_err(),
"{type_name}: parse_sorted_index_of_label accepted the empty string — the empty-string boundary is structurally reserved outside the closed set at every allocating-carrier decode column",
);
// Cross-column alignment with clause (2)'s sibling primitive on the
// (return-type) axis AND cross-ordering alignment with clause (84)
// one ordering-axis over — on EVERY probe (canonical labels +
// reserved probe) the three allocating-carrier decode surfaces
// (Self via parse_label, usize-decl via parse_index_of_label,
// usize-lex via parse_sorted_index_of_label) MUST agree on
// membership AND on the Unknown carrier Display on rejection.
// Alignment against `parse_label` on the accept arm degenerates
// to `parse_sorted_index_of_label(s) == Ok(v.sorted_index_of())`
// when `parse_label(s) == Ok(v)`. Alignment against
// `parse_index_of_label` on the reject arm demands the SAME
// `Self::Unknown` carrier Display — the carrier renders through
// the substrate-wide `unknown {SET_LABEL}: {input}` shape at
// both `usize`-typed return-type columns, so the two Displays
// MUST match byte-for-byte on every reject payload.
for &v in T::ALL {
let label = v.label();
let lex_decode = T::parse_sorted_index_of_label(label);
let carrier_decode = T::parse_label(label);
match (lex_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.sorted_index_of(),
"{type_name}: parse_sorted_index_of_label({label:?}) accepted at lex slot {idx} but parse_label({label:?}) accepted at variant {w:?} whose sorted_index_of() == {} — the two allocating-carrier decode surfaces bifurcated on the accept arm's typed lex slot",
w.sorted_index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_sorted_index_of_label({label:?}) rejected a canonical variant label — the accept arm on both allocating-carrier decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_sorted_index_of_label({label:?}) and parse_label({label:?}) disagreed on the (accept, reject) partition — the allocating-carrier decode surface bifurcated across the (return-type × ordering) axis",
),
}
}
match (
T::parse_sorted_index_of_label(probe),
T::parse_index_of_label(probe),
) {
(Err(carrier_a), Err(carrier_b)) => assert_eq!(
carrier_a.to_string(),
carrier_b.to_string(),
"{type_name}: parse_sorted_index_of_label(reserved probe) and parse_index_of_label(reserved probe) disagreed on the `Self::Unknown` carrier's Display rendering — the two `usize`-typed allocating-carrier decode surfaces bifurcated on the Unknown carrier shape across the (ordering) axis",
),
_ => panic!(
"{type_name}: parse_sorted_index_of_label / parse_index_of_label accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (86) — `T::parse_index_of_label_with_hint` composes
// `parse_label_with_hint` + `index_of` verbatim on the Ok arm AND
// preserves the `(Self::Unknown, Option<Self>)` tuple carrier shape
// on the Err arm. Every variant decodes to `Ok(v.index_of())` through
// the structured surface; the reserved probe rejects with the SAME
// substrate-wide `unknown {SET_LABEL}: {input}` carrier
// `parse_label_with_hint` emits AND with a `None` hint slot (the
// 38-char probe sits beyond `suggest_closest`'s bounded edit
// distance by construction — the same reservation clauses (7) +
// (82) + (83) key off). The default trait body satisfies the clause
// for free; the assertion catches an override that drifts the
// composition (accepts the probe as Ok through a permissive index
// return, fabricates a different Unknown carrier shape than
// `parse_label_with_hint` surfaces, emits the wrong declaration-
// order slot on a canonical variant, OR fabricates a hint slot the
// sibling `parse_label_with_hint` doesn't surface). Sibling posture
// to clauses (7) + (82) + (84) + (85) on the (return-type × side-
// effect × ordering × hint) 4-axis surface — clause (7) pins the
// `Self`-typed allocating-carrier with-hint arm, clause (82) pins
// the `usize`-typed decl-order non-allocating with-hint arm, clause
// (84) pins the `usize`-typed decl-order allocating-carrier no-hint
// arm, this clause pins the `usize`-typed decl-order allocating-
// carrier WITH-hint arm's alignment with
// `parse_label_with_hint + index_of`. Together (7) + (84) + (86)
// close the allocating-carrier column on the (return-type × hint)
// 2×2 face at the (`Self`, `usize`-decl) rows across BOTH (no-hint,
// with-hint) columns — the remaining (`usize`-lex, allocating,
// with-hint) corner at a future `parse_sorted_index_of_label_with_hint`
// sits one ordering-axis further along the (ordering) column, the
// sibling posture this clause's (`usize`-decl, allocating, with-hint)
// corner opens.
for &v in T::ALL {
let label = v.label();
match T::parse_index_of_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v.index_of(),
"{type_name}: parse_index_of_label_with_hint round-trip {label:?} → variant decoded to declaration-order slot {decoded} but v.index_of() == {} — the allocating-carrier (`&str → usize` decl-order with hint) decode drifted from the natural `parse_label_with_hint(s).map(index_of)` composition on the accept arm",
v.index_of(),
),
Err(_) => panic!(
"{type_name}: parse_index_of_label_with_hint round-trip {label:?} → canonical variant rejected by the allocating-carrier (`&str → usize` decl-order with hint) decode",
),
}
}
match T::parse_index_of_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: parse_index_of_label_with_hint accepted the reserved probe input — the allocating-carrier `usize`-typed decl-order with-hint decode MUST reject every input outside the closed set",
),
Err((carrier, hint)) => {
assert_eq!(
carrier.to_string(),
expected,
"{type_name}: parse_index_of_label_with_hint's Err carrier drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the override emits a different carrier than `parse_label_with_hint` would",
);
assert!(
hint.is_none(),
"{type_name}: parse_index_of_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
);
}
}
assert!(
T::parse_index_of_label_with_hint("").is_err(),
"{type_name}: parse_index_of_label_with_hint accepted the empty string — the empty-string boundary is structurally reserved outside the closed set at every allocating-carrier decode column",
);
// Cross-column alignment with clause (7)'s sibling primitive on the
// (return-type) axis — on EVERY probe (canonical labels + reserved
// probe + empty-string boundary) the two allocating-carrier with-
// hint decode surfaces MUST agree on membership, on the Unknown
// carrier Display, AND on the typed hint variant. Alignment against
// `parse_label_with_hint` on the accept arm degenerates to
// `parse_index_of_label_with_hint(s) == Ok(v.index_of())` when
// `parse_label_with_hint(s) == Ok(v)`. Alignment against
// `parse_label_with_hint` on the reject arm demands the SAME
// `(Self::Unknown, Option<Self>)` tuple shape — both carriers
// render through the substrate-wide `unknown {SET_LABEL}: {input}`
// shape at both return-type columns, and both hints route through
// the same `suggest_closest` projection, so the two Displays MUST
// match byte-for-byte AND the two hint variants MUST match on
// every reject payload.
for &v in T::ALL {
let label = v.label();
let index_decode = T::parse_index_of_label_with_hint(label);
let carrier_decode = T::parse_label_with_hint(label);
match (index_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.index_of(),
"{type_name}: parse_index_of_label_with_hint({label:?}) accepted at decl slot {idx} but parse_label_with_hint({label:?}) accepted at variant {w:?} whose index_of() == {} — the two allocating-carrier with-hint decode surfaces bifurcated on the accept arm's typed decl slot",
w.index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both allocating-carrier with-hint decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_index_of_label_with_hint({label:?}) and parse_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the allocating-carrier with-hint decode surface bifurcated across the (return-type) axis",
),
}
}
match (
T::parse_index_of_label_with_hint(probe),
T::parse_label_with_hint(probe),
) {
(Err((carrier_a, hint_a)), Err((carrier_b, hint_b))) => {
assert_eq!(
carrier_a.to_string(),
carrier_b.to_string(),
"{type_name}: parse_index_of_label_with_hint(reserved probe) and parse_label_with_hint(reserved probe) disagreed on the `Self::Unknown` carrier's Display rendering — the allocating-carrier with-hint decode surface bifurcated on the Unknown carrier shape across the (return-type) axis",
);
assert_eq!(
hint_a, hint_b,
"{type_name}: parse_index_of_label_with_hint(reserved probe) and parse_label_with_hint(reserved probe) disagreed on the typed hint slot — the allocating-carrier with-hint decode surface bifurcated on the (hint) axis's Option<Self> variant across the (return-type) axis",
);
}
_ => panic!(
"{type_name}: parse_index_of_label_with_hint / parse_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// Cross-column alignment with clause (82)'s sibling primitive on the
// (side-effect) axis — on EVERY probe (canonical labels + reserved
// probe) the (`usize`-decl) with-hint decode surfaces on BOTH
// side-effect columns (non-allocating `index_of_label_with_hint`,
// allocating `parse_index_of_label_with_hint`) MUST agree on
// membership AND on the typed hint variant. The (side-effect) axis
// doesn't touch the hint shape (both route through the same
// `suggest_closest` projection), so the two typed hints MUST match
// on every reject payload.
for &v in T::ALL {
let label = v.label();
let alloc_decode = T::parse_index_of_label_with_hint(label);
let bare_decode = T::index_of_label_with_hint(label);
match (alloc_decode, bare_decode) {
(Ok(idx_a), Ok(idx_b)) => assert_eq!(
idx_a, idx_b,
"{type_name}: parse_index_of_label_with_hint({label:?}) accepted at decl slot {idx_a} but index_of_label_with_hint({label:?}) accepted at slot {idx_b} — the two (`usize`-decl) with-hint decode surfaces bifurcated on the accept arm's typed decl slot across the (side-effect) axis",
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both (`usize`-decl) with-hint decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_index_of_label_with_hint({label:?}) and index_of_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the (`usize`-decl) with-hint decode surface bifurcated across the (side-effect) axis",
),
}
}
match (
T::parse_index_of_label_with_hint(probe),
T::index_of_label_with_hint(probe),
) {
(Err((_, hint_a)), Err(hint_b)) => assert_eq!(
hint_a, hint_b,
"{type_name}: parse_index_of_label_with_hint(reserved probe) and index_of_label_with_hint(reserved probe) disagreed on the typed hint slot — the two (`usize`-decl) with-hint decode surfaces bifurcated on the (hint) axis's Option<Self> variant across the (side-effect) axis",
),
_ => panic!(
"{type_name}: parse_index_of_label_with_hint / index_of_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (87) — `T::parse_sorted_index_of_label_with_hint` composes
// `parse_label_with_hint` + `sorted_index_of` verbatim on the Ok
// arm AND preserves the `(Self::Unknown, Option<Self>)` tuple
// carrier shape on the Err arm. Every variant decodes to
// `Ok(v.sorted_index_of())` through the structured surface; the
// reserved probe rejects with the SAME substrate-wide `unknown
// {SET_LABEL}: {input}` carrier `parse_label_with_hint` emits AND
// with a `None` hint slot (the 38-char probe sits beyond
// `suggest_closest`'s bounded edit distance by construction — the
// same reservation clauses (7) + (82) + (83) + (86) key off). The
// default trait body satisfies the clause for free; the assertion
// catches an override that drifts the composition (accepts the
// probe as Ok through a permissive lex-index return, fabricates a
// different Unknown carrier shape than `parse_label_with_hint`
// surfaces, emits the wrong lex-order slot on a canonical
// variant, OR fabricates a hint slot the sibling
// `parse_label_with_hint` doesn't surface). Sibling posture to
// clauses (7) + (83) + (85) + (86) on the (return-type × side-
// effect × ordering × hint) 4-axis surface — clause (7) pins the
// `Self`-typed allocating-carrier with-hint arm, clause (83) pins
// the `usize`-typed lex-order non-allocating with-hint arm,
// clause (85) pins the `usize`-typed lex-order allocating-carrier
// no-hint arm, clause (86) pins the `usize`-typed decl-order
// allocating-carrier with-hint arm, this clause pins the `usize`-
// typed lex-order allocating-carrier WITH-hint arm's alignment
// with `parse_label_with_hint + sorted_index_of`. Together (7) +
// (83) + (86) + (87) close the with-hint face across BOTH
// ordering columns at BOTH side-effect columns on the `usize`-
// typed return-type row of the 4-axis surface — the (`Self`-typed,
// lex-ordering) corner collapses onto (7) because the carrier
// decode's typed variant carries no ordering-axis distinction, so
// the with-hint face of the 4-axis surface CLOSES at ALL its
// populated corners.
for &v in T::ALL {
let label = v.label();
match T::parse_sorted_index_of_label_with_hint(label) {
Ok(decoded) => assert_eq!(
decoded, v.sorted_index_of(),
"{type_name}: parse_sorted_index_of_label_with_hint round-trip {label:?} → variant decoded to lex-order slot {decoded} but v.sorted_index_of() == {} — the allocating-carrier (`&str → usize` lex-order with hint) decode drifted from the natural `parse_label_with_hint(s).map(sorted_index_of)` composition on the accept arm",
v.sorted_index_of(),
),
Err(_) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint round-trip {label:?} → canonical variant rejected by the allocating-carrier (`&str → usize` lex-order with hint) decode",
),
}
}
match T::parse_sorted_index_of_label_with_hint(probe) {
Ok(_) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint accepted the reserved probe input — the allocating-carrier `usize`-typed lex-order with-hint decode MUST reject every input outside the closed set",
),
Err((carrier, hint)) => {
assert_eq!(
carrier.to_string(),
expected,
"{type_name}: parse_sorted_index_of_label_with_hint's Err carrier drifted from the substrate-wide `unknown {{SET_LABEL}}: {{input}}` shape — the override emits a different carrier than `parse_label_with_hint` would",
);
assert!(
hint.is_none(),
"{type_name}: parse_sorted_index_of_label_with_hint fabricated a `did you mean ...?` hint for the unrecognizable probe — the conservative-suggestion contract demands `None` for inputs beyond the bounded edit distance",
);
}
}
assert!(
T::parse_sorted_index_of_label_with_hint("").is_err(),
"{type_name}: parse_sorted_index_of_label_with_hint accepted the empty string — the empty-string boundary is structurally reserved outside the closed set at every allocating-carrier decode column",
);
// Cross-column alignment with clause (7)'s sibling primitive on the
// (return-type) axis — on EVERY probe (canonical labels + reserved
// probe + empty-string boundary) the two allocating-carrier with-
// hint decode surfaces MUST agree on membership, on the Unknown
// carrier Display, AND on the typed hint variant. Alignment against
// `parse_label_with_hint` on the accept arm degenerates to
// `parse_sorted_index_of_label_with_hint(s) == Ok(v.sorted_index_of())`
// when `parse_label_with_hint(s) == Ok(v)`. Alignment against
// `parse_label_with_hint` on the reject arm demands the SAME
// `(Self::Unknown, Option<Self>)` tuple shape — both carriers
// render through the substrate-wide `unknown {SET_LABEL}: {input}`
// shape at both return-type columns, and both hints route through
// the same `suggest_closest` projection, so the two Displays MUST
// match byte-for-byte AND the two hint variants MUST match on
// every reject payload.
for &v in T::ALL {
let label = v.label();
let lex_decode = T::parse_sorted_index_of_label_with_hint(label);
let carrier_decode = T::parse_label_with_hint(label);
match (lex_decode, carrier_decode) {
(Ok(idx), Ok(w)) => assert_eq!(
idx, w.sorted_index_of(),
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) accepted at lex slot {idx} but parse_label_with_hint({label:?}) accepted at variant {w:?} whose sorted_index_of() == {} — the two allocating-carrier with-hint decode surfaces bifurcated on the accept arm's typed lex slot",
w.sorted_index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both allocating-carrier with-hint decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) and parse_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the allocating-carrier with-hint decode surface bifurcated across the (return-type × ordering) axis",
),
}
}
match (
T::parse_sorted_index_of_label_with_hint(probe),
T::parse_label_with_hint(probe),
) {
(Err((carrier_a, hint_a)), Err((carrier_b, hint_b))) => {
assert_eq!(
carrier_a.to_string(),
carrier_b.to_string(),
"{type_name}: parse_sorted_index_of_label_with_hint(reserved probe) and parse_label_with_hint(reserved probe) disagreed on the `Self::Unknown` carrier's Display rendering — the allocating-carrier with-hint decode surface bifurcated on the Unknown carrier shape across the (return-type × ordering) axis",
);
assert_eq!(
hint_a, hint_b,
"{type_name}: parse_sorted_index_of_label_with_hint(reserved probe) and parse_label_with_hint(reserved probe) disagreed on the typed hint slot — the allocating-carrier with-hint decode surface bifurcated on the (hint) axis's Option<Self> variant across the (return-type × ordering) axis",
);
}
_ => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint / parse_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// Cross-column alignment with clause (86)'s sibling primitive on
// the (ordering) axis — on EVERY probe (canonical labels + reserved
// probe) the (`usize`-typed allocating-carrier with-hint) decode
// surfaces on BOTH ordering columns (decl-order
// `parse_index_of_label_with_hint`, lex-order
// `parse_sorted_index_of_label_with_hint`) MUST agree on
// membership AND on the Unknown carrier Display AND on the typed
// hint variant. The (ordering) axis doesn't touch the reject-arm
// tuple shape (both route through the same `parse_label_with_hint`
// carrier + `suggest_closest` hint), so the two Unknown Displays
// AND the two typed hints MUST match on every reject payload.
for &v in T::ALL {
let label = v.label();
let lex_decode = T::parse_sorted_index_of_label_with_hint(label);
let decl_decode = T::parse_index_of_label_with_hint(label);
match (lex_decode, decl_decode) {
(Ok(lex_idx), Ok(decl_idx)) => assert_eq!(
lex_idx, v.sorted_index_of(),
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) accepted at lex slot {lex_idx} but v.sorted_index_of() == {} (parse_index_of_label_with_hint accepted at decl slot {decl_idx}) — the two `usize`-typed allocating-carrier with-hint decode surfaces bifurcated on the accept arm's typed lex slot across the (ordering) axis",
v.sorted_index_of(),
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both `usize`-typed allocating-carrier with-hint decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) and parse_index_of_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the `usize`-typed allocating-carrier with-hint decode surface bifurcated across the (ordering) axis",
),
}
}
match (
T::parse_sorted_index_of_label_with_hint(probe),
T::parse_index_of_label_with_hint(probe),
) {
(Err((carrier_a, hint_a)), Err((carrier_b, hint_b))) => {
assert_eq!(
carrier_a.to_string(),
carrier_b.to_string(),
"{type_name}: parse_sorted_index_of_label_with_hint(reserved probe) and parse_index_of_label_with_hint(reserved probe) disagreed on the `Self::Unknown` carrier's Display rendering — the two `usize`-typed allocating-carrier with-hint decode surfaces bifurcated on the Unknown carrier shape across the (ordering) axis",
);
assert_eq!(
hint_a, hint_b,
"{type_name}: parse_sorted_index_of_label_with_hint(reserved probe) and parse_index_of_label_with_hint(reserved probe) disagreed on the typed hint slot — the two `usize`-typed allocating-carrier with-hint decode surfaces bifurcated on the (hint) axis's Option<Self> variant across the (ordering) axis",
);
}
_ => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint / parse_index_of_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// Cross-column alignment with clause (83)'s sibling primitive on
// the (side-effect) axis — on EVERY probe (canonical labels +
// reserved probe) the (`usize`-lex) with-hint decode surfaces on
// BOTH side-effect columns (non-allocating
// `sorted_index_of_label_with_hint`, allocating
// `parse_sorted_index_of_label_with_hint`) MUST agree on
// membership AND on the typed hint variant. The (side-effect)
// axis doesn't touch the hint shape (both route through the same
// `suggest_closest` projection), so the two typed hints MUST match
// on every reject payload.
for &v in T::ALL {
let label = v.label();
let alloc_decode = T::parse_sorted_index_of_label_with_hint(label);
let bare_decode = T::sorted_index_of_label_with_hint(label);
match (alloc_decode, bare_decode) {
(Ok(idx_a), Ok(idx_b)) => assert_eq!(
idx_a, idx_b,
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) accepted at lex slot {idx_a} but sorted_index_of_label_with_hint({label:?}) accepted at slot {idx_b} — the two (`usize`-lex) with-hint decode surfaces bifurcated on the accept arm's typed lex slot across the (side-effect) axis",
),
(Err(_), Err(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) rejected a canonical variant label — the accept arm on both (`usize`-lex) with-hint decode surfaces MUST agree",
),
(Ok(_), Err(_)) | (Err(_), Ok(_)) => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint({label:?}) and sorted_index_of_label_with_hint({label:?}) disagreed on the (accept, reject) partition — the (`usize`-lex) with-hint decode surface bifurcated across the (side-effect) axis",
),
}
}
match (
T::parse_sorted_index_of_label_with_hint(probe),
T::sorted_index_of_label_with_hint(probe),
) {
(Err((_, hint_a)), Err(hint_b)) => assert_eq!(
hint_a, hint_b,
"{type_name}: parse_sorted_index_of_label_with_hint(reserved probe) and sorted_index_of_label_with_hint(reserved probe) disagreed on the typed hint slot — the two (`usize`-lex) with-hint decode surfaces bifurcated on the (hint) axis's Option<Self> variant across the (side-effect) axis",
),
_ => panic!(
"{type_name}: parse_sorted_index_of_label_with_hint / sorted_index_of_label_with_hint accepted the reserved probe or disagreed on the (accept, reject) partition",
),
}
// (88) — `T::first_index()` MUST equal `T::first().index_of()`
// AND MUST equal the literal `0` — the singular declaration-order
// head-endpoint decl-slot projection on the declaration-axis
// singular endpoint-anchor `usize`-return-shape column composes
// the (declaration head anchor) primitive with the (per-slot
// decl-index) projection AND lands at the structural `0` fixpoint
// of the `<[Self]>::iter().position(...)` decl-slot semantics
// (`T::first() == T::ALL[0]` by clause (18), so
// `T::first().index_of() == 0` by the `index_of` well-formedness
// pin on clause (17)). The default trait body composes
// `T::index_of(T::first())` verbatim and satisfies both alignments
// for free; the assertion catches a future implementor whose
// override drifts the singular head-decl-slot projection (a stale
// override that hard-codes a non-zero literal detached from
// [`Self::first`] AND [`Self::index_of`] — silently forking the
// head-anchor decl-slot rendering from the index-projection
// primitive every downstream head-decl-slot consumer routes
// through; a permissive override that returns
// `T::CARDINALITY - 1` — silently swapping the singular head-slot
// projection with the tail-slot; a fold override that returns
// [`Self::first`]'s `sorted_index_of` instead — silently
// bifurcating the (declaration, lex) ordering axis at the
// singular head-endpoint-index return-shape slot on any
// implementor whose declaration order diverges from its lex order;
// an override that returns a strictly-interior variant's decl-slot
// — silently routing an interior slot into the head-endpoint-
// decl-slot projection; a fabricated override that returns
// `usize::MAX` — silently detaching the head-decl-slot rendering
// from every canonical slot in [`T::ALL`]) loudly rather than
// silently bifurcating the singular head-endpoint-decl-slot
// projection surface every downstream head-decl-slot consumer
// routes through. Sibling posture to clauses (18) + (34) + (36)
// + (46) — clause (18) pins the individual (declaration head)
// scalar endpoint-anchor projection against `T::ALL[0]`, clause
// (34) pins the (typed variant, typed variant) pair-aggregation
// projection on the declaration axis, clause (36) pins the
// (label, label) pair-aggregation projection on the declaration
// axis, clause (46) pins the singular `&'static str` head-label
// projection against the composition of the declaration head-
// endpoint-anchor primitive with the per-slot label projection,
// this clause pins the singular `usize` head-decl-slot projection
// against the composition of the declaration head-endpoint-anchor
// primitive with the per-slot decl-index projection. Clauses (18)
// + (46) + (88) together OPEN the (return-type × head-endpoint-
// direction) 3×1 matrix over the declaration-axis singular head-
// endpoint-anchor return-shape column at ALL THREE return-type
// corners (typed-variant `Self`, canonical-label `&'static str`,
// decl-slot `usize`) — every generic consumer that binds any of
// the three singular head-anchor projection methods sees the SAME
// head-endpoint answer at every crate boundary regardless of
// which return-type axis / aggregation-shape corner it walks.
assert_eq!(
T::first_index(),
T::first().index_of(),
"{type_name}: T::first_index() drifted from T::first().index_of() — the singular declaration-order head-endpoint decl-slot projection no longer agrees with the natural `T::first().index_of()` two-primitive composition, so a downstream head-slot cursor / head-slot completion / head-slot coherence probe consumer that binds `T::first_index()` as its singular head-anchor decl-slot query surface would render the wrong `usize`",
);
assert_eq!(
T::first_index(),
0,
"{type_name}: T::first_index() drifted from the literal `0` fixpoint — `T::first() == T::ALL[0]` by clause (18) and `T::ALL[0].index_of() == 0` by the `index_of` well-formedness pin, so the composition MUST land at slot 0 on every implementor; a downstream head-slot consumer that binds `T::first_index()` as its singular head-anchor decl-slot query surface would read a non-zero head slot when the substrate's `<[Self]>::iter().position(...)` decl-slot semantics anchor the head at slot 0",
);
// (89) — `T::last_index()` MUST equal `T::last().index_of()` AND
// MUST equal `T::CARDINALITY - 1` — the singular declaration-order
// tail-endpoint decl-slot projection on the declaration-axis singular
// endpoint-anchor `usize`-return-shape column composes the
// (declaration tail anchor) primitive with the (per-slot decl-index)
// projection AND lands at the structural `T::CARDINALITY - 1`
// fixpoint of the `<[Self]>::iter().position(...)` decl-slot
// semantics (`T::last() == T::ALL[T::CARDINALITY - 1]` by clause
// (18), so `T::last().index_of() == T::CARDINALITY - 1` by the
// `index_of` well-formedness pin on clause (17)). The default trait
// body composes `T::index_of(T::last())` verbatim and satisfies both
// alignments for free; the assertion catches a future implementor
// whose override drifts the singular tail-decl-slot projection (a
// stale override that hard-codes a literal detached from
// [`Self::last`] AND [`Self::index_of`] — silently forking the
// tail-anchor decl-slot rendering from the index-projection
// primitive every downstream tail-decl-slot consumer routes through;
// a permissive override that returns `0` — silently swapping the
// singular tail-slot projection with the head-slot; a fold override
// that returns [`Self::last`]'s `sorted_index_of` instead —
// silently bifurcating the (declaration, lex) ordering axis at the
// singular tail-endpoint-index return-shape slot on any implementor
// whose declaration order diverges from its lex order; an override
// that returns a strictly-interior variant's decl-slot — silently
// routing an interior slot into the tail-endpoint-decl-slot
// projection; a fabricated override that returns `usize::MAX` —
// silently detaching the tail-decl-slot rendering from every
// canonical slot in [`T::ALL`]) loudly rather than silently
// bifurcating the singular tail-endpoint-decl-slot projection
// surface every downstream tail-decl-slot consumer routes through.
// Sibling posture to clauses (18) + (34) + (36) + (47) + (88) —
// clause (18) pins the individual (declaration tail) scalar
// endpoint-anchor projection against `T::ALL[T::CARDINALITY - 1]`,
// clause (34) pins the (typed variant, typed variant) pair-
// aggregation projection on the declaration axis, clause (36) pins
// the (label, label) pair-aggregation projection on the declaration
// axis, clause (47) pins the singular `&'static str` tail-label
// projection against the composition of the declaration tail-
// endpoint-anchor primitive with the per-slot label projection,
// clause (88) pins the singular `usize` head-decl-slot projection
// against the composition of the declaration head-endpoint-anchor
// primitive with the per-slot decl-index projection, this clause
// pins the singular `usize` tail-decl-slot projection against the
// composition of the declaration tail-endpoint-anchor primitive
// with the per-slot decl-index projection. Clauses (18) + (46) +
// (47) + (88) + (89) together CLOSE the (return-type ×
// endpoint-direction) 3×2 = 6-corner declaration-axis singular
// endpoint-anchor return-shape matrix at ALL SIX corners — every
// generic consumer that binds any of the six singular endpoint-
// anchor projection methods sees the SAME endpoint-anchor answer
// at every crate boundary regardless of which return-type axis /
// endpoint-direction corner it walks.
assert_eq!(
T::last_index(),
T::last().index_of(),
"{type_name}: T::last_index() drifted from T::last().index_of() — the singular declaration-order tail-endpoint decl-slot projection no longer agrees with the natural `T::last().index_of()` two-primitive composition, so a downstream tail-slot cursor / tail-slot completion / tail-slot coherence probe consumer that binds `T::last_index()` as its singular tail-anchor decl-slot query surface would render the wrong `usize`",
);
assert_eq!(
T::last_index() + 1,
T::CARDINALITY,
"{type_name}: T::last_index() drifted from the `T::CARDINALITY - 1` structural fixpoint — `T::last() == T::ALL[T::CARDINALITY - 1]` by clause (18) and `T::ALL[T::CARDINALITY - 1].index_of() == T::CARDINALITY - 1` by the `index_of` well-formedness pin, so the composition MUST land at slot `T::CARDINALITY - 1` on every implementor; a downstream tail-slot consumer that binds `T::last_index()` as its singular tail-anchor decl-slot query surface would read a non-`CARDINALITY - 1` tail slot when the substrate's `<[Self]>::iter().position(...)` decl-slot semantics anchor the tail at slot `T::CARDINALITY - 1`",
);
// (90) — `T::sorted_first_index()` MUST equal
// `T::sorted_first().index_of()` AND
// `T::from_index(T::sorted_first_index())` MUST equal
// `Some(T::sorted_first())` — the singular lex-order head-endpoint
// decl-slot projection on the lex-axis singular endpoint-anchor
// `usize`-return-shape column composes the (lex head anchor)
// primitive with the (per-slot decl-index) projection AND round-
// trips through the (decl-slot → typed variant) reverse projection
// back onto the lex-head anchor. The default trait body composes
// `T::index_of(T::sorted_first())` verbatim and satisfies both
// alignments for free; the assertion catches a future implementor
// whose override drifts the singular lex-head-decl-slot projection
// (a stale override that hard-codes a literal detached from
// [`Self::sorted_first`] AND [`Self::index_of`] — silently forking
// the lex-head-anchor decl-slot rendering from the index-projection
// primitive; a fold override that returns [`Self::first_index`]
// instead — silently bifurcating the (declaration, lex) ordering
// axis at the singular head-endpoint decl-slot return-shape corner
// on any implementor whose declaration order diverges from its lex
// order; an override that routes a non-lex-head decl-slot into the
// lex-head-endpoint slot — silently detaching the lex-head decl-slot
// rendering from the lex-min anchor's canonical decl-slot in
// [`T::ALL`]; a fabricated override that returns `usize::MAX` —
// silently detaching the lex-head decl-slot rendering from every
// canonical slot in [`T::ALL`]) loudly rather than silently
// bifurcating the singular lex-head-endpoint-decl-slot projection
// surface every downstream lex-head-decl-slot consumer routes
// through. Sibling posture to clauses (48) + (88) — clause (48)
// pins the singular `&'static str` lex-head-label projection
// against the composition of the lex head-endpoint-anchor primitive
// with the per-slot label projection, clause (88) pins the singular
// `usize` DECLARATION-head decl-slot projection against the
// composition of the declaration head-endpoint-anchor primitive
// with the per-slot decl-index projection, this clause pins the
// singular `usize` LEX-head decl-slot projection against the
// composition of the LEX head-endpoint-anchor primitive with the
// per-slot decl-index projection.
assert_eq!(
T::sorted_first_index(),
T::sorted_first().index_of(),
"{type_name}: T::sorted_first_index() drifted from T::sorted_first().index_of() — the singular lex-order head-endpoint decl-slot projection no longer agrees with the natural `T::sorted_first().index_of()` two-primitive composition, so a downstream lex-head-slot cursor / lex-head-slot completion / lex-head-slot coherence probe consumer that binds `T::sorted_first_index()` as its singular lex-head-anchor decl-slot query surface would render the wrong `usize`",
);
assert_eq!(
T::from_index(T::sorted_first_index()),
Some(T::sorted_first()),
"{type_name}: T::sorted_first_index() drifted from the `T::from_index(_)` reverse round-trip pin — `T::from_index(T::sorted_first().index_of())` MUST equal `Some(T::sorted_first())` by the (index_of, from_index) reverse round-trip clause (17), so the composition MUST land at a decl-slot that decodes back to the lex-head anchor on every implementor; a downstream lex-head consumer that binds `T::sorted_first_index()` as its lex-head decl-slot query surface would read a slot that decodes to some OTHER variant when the substrate's (decl-slot → typed variant) reverse projection routes through the drifted decl-slot",
);
// (91) — `T::sorted_last_index()` MUST equal
// `T::sorted_last().index_of()` AND
// `T::from_index(T::sorted_last_index())` MUST equal
// `Some(T::sorted_last())` — the singular lex-order tail-endpoint
// decl-slot projection on the lex-axis singular endpoint-anchor
// `usize`-return-shape column composes the (lex tail anchor)
// primitive with the (per-slot decl-index) projection AND round-
// trips through the (decl-slot → typed variant) reverse projection
// back onto the lex-tail anchor. Sibling posture to clauses (49) +
// (89) + (90) — clause (49) pins the singular `&'static str`
// lex-tail-label projection against the composition of the lex
// tail-endpoint-anchor primitive with the per-slot label projection,
// clause (89) pins the singular `usize` DECLARATION-tail decl-slot
// projection against the composition of the declaration tail-
// endpoint-anchor primitive with the per-slot decl-index projection,
// clause (90) pins the singular `usize` LEX-head decl-slot
// projection against the composition of the lex head-endpoint-anchor
// primitive with the per-slot decl-index projection, this clause
// pins the singular `usize` LEX-tail decl-slot projection against
// the composition of the LEX tail-endpoint-anchor primitive with
// the per-slot decl-index projection. Clauses (88) + (89) + (90) +
// (91) together CLOSE the (return-type × ordering × endpoint-
// direction) 3×2×2 = 12-corner singular endpoint-anchor return-shape
// hypercube at ALL FOUR `usize`-typed decl-slot corners — every
// generic consumer that binds any of the twelve singular endpoint-
// anchor projection methods sees the SAME endpoint-anchor answer at
// every crate boundary regardless of which return-type axis /
// ordering-axis / endpoint-direction corner it walks.
assert_eq!(
T::sorted_last_index(),
T::sorted_last().index_of(),
"{type_name}: T::sorted_last_index() drifted from T::sorted_last().index_of() — the singular lex-order tail-endpoint decl-slot projection no longer agrees with the natural `T::sorted_last().index_of()` two-primitive composition, so a downstream lex-tail-slot cursor / lex-tail-slot completion / lex-tail-slot coherence probe consumer that binds `T::sorted_last_index()` as its singular lex-tail-anchor decl-slot query surface would render the wrong `usize`",
);
assert_eq!(
T::from_index(T::sorted_last_index()),
Some(T::sorted_last()),
"{type_name}: T::sorted_last_index() drifted from the `T::from_index(_)` reverse round-trip pin — `T::from_index(T::sorted_last().index_of())` MUST equal `Some(T::sorted_last())` by the (index_of, from_index) reverse round-trip clause (17), so the composition MUST land at a decl-slot that decodes back to the lex-tail anchor on every implementor; a downstream lex-tail consumer that binds `T::sorted_last_index()` as its lex-tail decl-slot query surface would read a slot that decodes to some OTHER variant when the substrate's (decl-slot → typed variant) reverse projection routes through the drifted decl-slot",
);
// (92) — `T::endpoint_indices()` MUST equal
// `(T::first().index_of(), T::last().index_of())` AND
// `T::endpoint_indices()` MUST equal `(0, T::CARDINALITY - 1)` —
// the `(usize, usize)` declaration-order pair-endpoint aggregation
// composes the (declaration pair-endpoint anchor) primitive with
// per-slot decl-index projection AND lands at the structural
// `(0, CARDINALITY - 1)` fixpoint. The default trait body
// destructures `T::endpoints()` and projects each slot under
// `T::index_of` verbatim and satisfies both alignments for free;
// the assertion catches a future implementor whose override drifts
// the `(usize, usize)` declaration-order pair-endpoint projection
// (a stale override that hard-codes `(0, 0)` or swaps the slots
// to `(N - 1, 0)` — silently transposing the head- and tail-slot
// integer coordinates; a fold override that folds the pair onto
// `(0, T::CARDINALITY - 2)` — silently detaching the tail slot
// from `T::last().index_of()`; an override that routes a non-
// canonical decl-slot into either tuple position — silently
// detaching the decl-slot pair rendering from the endpoint anchors'
// canonical decl-slots in `T::ALL`) loudly rather than silently
// bifurcating the `(usize, usize)` declaration-axis pair-endpoint-
// aggregation projection surface every downstream decl-slot-pair
// consumer routes through. Sibling posture to clauses (34) + (36)
// + (88) + (89) — clause (34) pins the `(Self, Self)` declaration-
// order pair-endpoint aggregation, clause (36) pins the
// `(&'static str, &'static str)` declaration-order pair-endpoint
// aggregation, clauses (88) + (89) pin the `usize` singular
// declaration-order head + tail endpoint decl-slot projections,
// this clause pins the `(usize, usize)` declaration-order pair-
// endpoint aggregation against the composition of the declaration
// pair-endpoint anchor primitive with the per-slot decl-index
// projection AND against the `(0, CARDINALITY - 1)` structural
// fixpoint.
assert_eq!(
T::endpoint_indices(),
(T::first().index_of(), T::last().index_of()),
"{type_name}: T::endpoint_indices() drifted from (T::first().index_of(), T::last().index_of()) — the declaration-order pair-endpoint decl-slot aggregation no longer agrees with the natural (T::first().index_of(), T::last().index_of()) four-primitive composition, so a downstream range walker / audit event / parallel-vector boundary-badge consumer that binds `T::endpoint_indices()` as its `(usize, usize)` declaration-order pair-endpoint query surface would render the wrong tuple",
);
assert_eq!(
T::endpoint_indices(),
(0, T::CARDINALITY - 1),
"{type_name}: T::endpoint_indices() drifted from the `(0, T::CARDINALITY - 1)` structural fixpoint — `T::first() == T::ALL[0]` + `T::last() == T::ALL[T::CARDINALITY - 1]` by clauses (18) + (19) and `T::ALL[i].index_of() == i` by the `index_of` well-formedness pin, so the composition MUST land at the `(0, T::CARDINALITY - 1)` tuple on every implementor; a downstream declaration-axis range walker that binds `T::endpoint_indices()` as its `(head_idx, tail_idx)` range destructure would iterate the WRONG slot range when the substrate's `<[Self]>::iter().position(...)` decl-slot semantics anchor the endpoint pair at `(0, T::CARDINALITY - 1)`",
);
// (93) — `T::sorted_endpoint_indices()` MUST equal
// `(T::sorted_first().index_of(), T::sorted_last().index_of())` AND
// `(T::from_index(T::sorted_endpoint_indices().0), T::from_index(T::sorted_endpoint_indices().1))`
// MUST equal `(Some(T::sorted_first()), Some(T::sorted_last()))` —
// the `(usize, usize)` lex-order pair-endpoint aggregation composes
// the (lex pair-endpoint anchor) primitive with per-slot decl-index
// projection AND round-trips both slots through the (decl-slot →
// typed variant) reverse projection back onto the lex-endpoint
// typed anchors. The default trait body destructures
// `T::sorted_endpoints()` and projects each slot under
// `T::index_of` verbatim and satisfies both alignments for free;
// the assertion catches a future implementor whose override drifts
// the `(usize, usize)` lex-order pair-endpoint projection (a stale
// override that folds the pair onto `T::endpoint_indices()` —
// silently bifurcating the (declaration, lex) ordering axis at the
// `(usize, usize)` pair-endpoint-aggregation corner on any
// implementor whose declaration order diverges from its lex order;
// a swap override that transposes the lex-head and lex-tail slots
// — silently swapping the two anchor decl-slots; an override that
// routes a non-lex-endpoint decl-slot into either tuple position —
// silently detaching the lex-endpoint decl-slot rendering from the
// lex anchors' canonical decl-slots in `T::ALL`) loudly rather
// than silently bifurcating the lex-axis `(usize, usize)` pair-
// endpoint-aggregation projection surface every downstream lex-
// decl-slot-pair consumer routes through. Sibling posture to clauses
// (35) + (37) + (90) + (91) + (92) — clause (35) pins the
// `(Self, Self)` lex-order pair-endpoint aggregation, clause (37)
// pins the `(&'static str, &'static str)` lex-order pair-endpoint
// aggregation, clauses (90) + (91) pin the `usize` singular lex-
// order head + tail endpoint decl-slot projections, clause (92)
// pins the `(usize, usize)` DECLARATION-order pair-endpoint
// aggregation, this clause pins the `(usize, usize)` LEX-order
// pair-endpoint aggregation against the composition of the lex
// pair-endpoint anchor primitive with the per-slot decl-index
// projection. Clauses (34) + (35) + (36) + (37) + (92) + (93)
// together CLOSE the (return-type × ordering) 3×2 = 6-corner
// pair-endpoint aggregation matrix at ALL SIX corners — every
// generic consumer that binds any of the six pair-endpoint
// aggregation projection methods sees the SAME tuple shape at
// every crate boundary regardless of which return-type axis /
// ordering-axis corner it walks.
assert_eq!(
T::sorted_endpoint_indices(),
(T::sorted_first().index_of(), T::sorted_last().index_of()),
"{type_name}: T::sorted_endpoint_indices() drifted from (T::sorted_first().index_of(), T::sorted_last().index_of()) — the lex-order pair-endpoint decl-slot aggregation no longer agrees with the natural (T::sorted_first().index_of(), T::sorted_last().index_of()) four-primitive composition, so a downstream lex-range walker / lex-audit event / lex-parallel-vector boundary-badge consumer that binds `T::sorted_endpoint_indices()` as its `(usize, usize)` lex-order pair-endpoint query surface would render the wrong tuple",
);
let (sorted_head_slot, sorted_tail_slot) = T::sorted_endpoint_indices();
assert_eq!(
(T::from_index(sorted_head_slot), T::from_index(sorted_tail_slot)),
(Some(T::sorted_first()), Some(T::sorted_last())),
"{type_name}: T::sorted_endpoint_indices() drifted from the `T::from_index(_)` reverse round-trip pin — `(T::from_index(T::sorted_first().index_of()), T::from_index(T::sorted_last().index_of()))` MUST equal `(Some(T::sorted_first()), Some(T::sorted_last()))` by clauses (17) + (90) + (91), so the composition MUST land at a decl-slot pair that decodes back to the (lex-head, lex-tail) anchor pair on every implementor; a downstream lex-endpoint consumer that binds `T::sorted_endpoint_indices()` as its `(usize, usize)` lex-order pair-endpoint query surface would read a tuple that decodes to some OTHER variant pair when the substrate's (decl-slot → typed variant) reverse projection routes through a drifted tuple slot",
);
// (94) — `T::interior_indices()` MUST equal
// `T::interior().into_iter().map(T::index_of).collect::<Vec<_>>()`
// AND every element `i` in the returned vector MUST satisfy
// `T::is_interior_index(i) == true` — the decl-order strictly-
// interior decl-slot collection composes the (declaration-axis
// strictly-interior variant collection) primitive with the per-
// slot decl-index projection AND every element MUST sit outside
// the endpoint slots by the boundary-partition predicate. The
// default trait body threads `T::interior()` through
// `.map(T::index_of).collect()` verbatim and satisfies both
// alignments for free; the assertion catches a future implementor
// whose override drifts the projection (a stale override that
// folds the interior decl-slot collection onto the full-set
// `(0..T::CARDINALITY).collect()` — silently including the
// endpoint slots and bifurcating from the partition contract; a
// swap override that transposes lex-order decl-slots into a
// declaration-order return surface — silently bifurcating from the
// (declaration, lex) ordering axis; an override that routes an
// endpoint decl-slot into any tuple position — silently detaching
// the strictly-interior partition rendering from
// [`Self::interior`]'s canonical partition of `T::ALL`) loudly
// rather than silently bifurcating the strictly-interior decl-
// slot-collection projection surface every downstream interior-
// decl-slot consumer routes through. Sibling posture to clauses
// (38) + (40) + (92) — clause (38) pins the `Vec<Self>`
// declaration-order strictly-interior variant collection, clause
// (40) pins the `Vec<&'static str>` declaration-order strictly-
// interior label collection, clause (92) pins the `(usize, usize)`
// declaration-order PAIR-endpoint aggregation, this clause pins
// the `Vec<usize>` declaration-order strictly-INTERIOR decl-slot
// collection — the (return-shape) partition of the interior-
// aggregation surface opens its (`Vec<usize>`, decl) corner
// alongside the pre-existing (`Vec<Self>`, decl) + (`Vec<str>`,
// decl) corners, and the (partition-flavor) axis stays partitioned
// cleanly against the boundary-aggregation `(usize, usize)`
// pair-endpoint corner one arity level over.
let expected_interior_indices: Vec<usize> = T::interior()
.into_iter()
.map(<T as ClosedSet>::index_of)
.collect();
assert_eq!(
T::interior_indices(),
expected_interior_indices,
"{type_name}: T::interior_indices() drifted from T::interior().into_iter().map(T::index_of).collect() — the declaration-order strictly-interior decl-slot collection no longer agrees with the natural interior().map(index_of) two-primitive composition, so a downstream bounded interior loop / interior-arm parallel-vector renderer / interior-partition metrics counter / interior-observed bitset renderer that binds `T::interior_indices()` as its `Vec<usize>` strictly-interior decl-slot query surface would render the wrong slot list",
);
for &i in &T::interior_indices() {
assert!(
T::is_interior_index(i),
"{type_name}: T::interior_indices() emitted decl-slot {i} that fails T::is_interior_index({i}) — the strictly-interior decl-slot collection admitted an endpoint slot, bifurcating the boundary-partition contract clauses (74) + (75) pin at the `usize`-arg predicate axis. Every slot in T::interior_indices() MUST satisfy T::is_interior_index(_) by the interior()+index_of composition contract",
);
}
// (95) — `T::sorted_interior_indices()` MUST equal
// `T::sorted_interior().into_iter().map(T::index_of).collect::<Vec<_>>()`
// AND every element `i` in the returned vector MUST satisfy
// `T::is_sorted_interior_index(T::sorted_index_of(T::from_index(i).unwrap())) == true`
// (equivalently: the DECLARATION slot `i` names a variant whose LEX
// slot sits strictly inside the lex-endpoint pair). The default
// trait body threads `T::sorted_interior()` through
// `.map(T::index_of).collect()` verbatim and satisfies both
// alignments for free; the assertion catches a future implementor
// whose override drifts the projection (a stale override that folds
// the lex-interior decl-slot collection onto the full-set
// `(0..T::CARDINALITY).collect()` — silently including both
// lex-endpoint slots and bifurcating from the lex-boundary-partition
// contract; a swap override that returns declaration-order interior
// slots instead of lex-order interior slots — silently bifurcating
// from the (declaration, lex) ordering axis and collapsing the
// (return-shape × ordering) 3×2 matrix's sixth (`Vec<usize>`, lex)
// corner onto its (`Vec<usize>`, decl) peer; an override that
// routes a lex-endpoint decl-slot into any tuple position —
// silently detaching the strictly-lex-interior partition rendering
// from [`Self::sorted_interior`]'s canonical partition of
// `T::sorted_variants()`) loudly rather than silently bifurcating
// the strictly-lex-interior decl-slot-collection projection surface
// every downstream lex-interior-decl-slot consumer routes through.
// Sibling posture to clauses (39) + (41) + (93) + (94) — clause
// (39) pins the `Vec<Self>` lex-order strictly-interior variant
// collection, clause (41) pins the `Vec<&'static str>` lex-order
// strictly-interior label collection, clause (93) pins the
// `(usize, usize)` lex-order PAIR-endpoint aggregation, clause (94)
// pins the `Vec<usize>` DECLARATION-order strictly-interior decl-
// slot collection, this clause pins the `Vec<usize>` LEX-order
// strictly-interior decl-slot collection — the (return-shape ×
// ordering) 3×2 = 6-corner interior-aggregation matrix now closes
// at all six corners with matching well-formedness clauses, and
// the (partition-flavor) axis stays partitioned cleanly against
// the boundary-aggregation `(usize, usize)` pair-endpoint corners
// one arity level over.
let expected_sorted_interior_indices: Vec<usize> = T::sorted_interior()
.into_iter()
.map(<T as ClosedSet>::index_of)
.collect();
assert_eq!(
T::sorted_interior_indices(),
expected_sorted_interior_indices,
"{type_name}: T::sorted_interior_indices() drifted from T::sorted_interior().into_iter().map(T::index_of).collect() — the lex-order strictly-interior decl-slot collection no longer agrees with the natural sorted_interior().map(index_of) two-primitive composition, so a downstream alphabetized interior-only completion bar / lex-interior-arm parallel-vector renderer / lex-interior-partition metrics counter / lex-interior-observed bitset renderer that binds `T::sorted_interior_indices()` as its `Vec<usize>` strictly-lex-interior decl-slot query surface would render the wrong slot list",
);
for &i in &T::sorted_interior_indices() {
// The lex-order decl-slot list carries DECLARATION indices `i`
// whose LEX indices sit strictly inside the (sorted_first,
// sorted_last) endpoints. Round-trip the decl-slot through the
// (usize → typed variant → lex index) two-step composition and
// pin the resulting lex index against the boundary-partition
// predicate on the lex axis.
let variant = T::from_index(i).unwrap_or_else(|| panic!("{type_name}: T::sorted_interior_indices() emitted decl-slot {i} that fails T::from_index({i}).is_some() — the strictly-lex-interior decl-slot collection admitted an out-of-range slot, breaking clauses (17) + (94) + this clause's shared bounds invariant"));
let lex_slot = T::sorted_index_of(variant);
assert!(
T::is_sorted_interior_index(lex_slot),
"{type_name}: T::sorted_interior_indices() emitted decl-slot {i} (lex slot {lex_slot}) that fails T::is_sorted_interior_index({lex_slot}) — the strictly-lex-interior decl-slot collection admitted a lex-endpoint slot, bifurcating the lex-boundary-partition contract clauses (76) + (77) pin at the `usize`-arg predicate axis. Every decl-slot in T::sorted_interior_indices() MUST decode through T::from_index + T::sorted_index_of to a lex slot satisfying T::is_sorted_interior_index(_) by the sorted_interior()+index_of composition contract",
);
}
// (96) — `T::sorted_indices()` MUST equal
// `T::sorted_variants().into_iter().map(T::index_of).collect::<Vec<_>>()`
// AND the returned vector MUST be a PERMUTATION of `0..T::CARDINALITY`
// (every decl-slot appears exactly once, length matches CARDINALITY,
// every element is in-range and unique). The default trait body
// threads `T::sorted_variants()` through `.map(T::index_of).collect()`
// verbatim and satisfies both alignments for free; the assertion
// catches a future implementor whose override drifts the projection
// (a stale override that folds the lex-order full-set decl-slot
// collection onto the identity range `(0..T::CARDINALITY).collect()`
// — silently collapsing the (decl, lex) ordering axis on any
// implementor whose lex order diverges from declaration order and
// silently bifurcating the lex-to-decl permutation from
// `T::sorted_variants()`'s canonical lex-order variant list; a swap
// override that returns declaration-order decl-slots
// `(0..T::CARDINALITY).collect()` instead of the lex-order
// permutation — silently bifurcating from the sorted-* row of the
// (decl, lex) partition and collapsing the (return-shape × ordering)
// 3×2 full-set aggregation matrix's (`Vec<usize>`, lex) corner onto
// its implicit `(0..CARDINALITY).collect()` peer at the
// (`Vec<usize>`, decl) corner; an override that emits a multiset
// with duplicate slots — silently detaching the full-set rendering
// from the CARDINALITY-anchored permutation contract, bifurcating
// the (variant → decl-slot) injectivity clause (16) at the lex-
// aggregation projection surface) loudly rather than silently
// bifurcating the full-set lex-order decl-slot projection surface
// every downstream lex-order-decl-slot consumer routes through.
// Sibling posture to clauses (17) + (94) + (95) — clause (17) pins
// the `Vec<Self>` lex-order full-set variant collection through
// sorted_variants alignment, clauses (94) + (95) pin the
// (`Vec<usize>`, decl/lex) strictly-interior arms of the same
// (return-shape × ordering × partition-flavor) 3×2×3 aggregation
// cube, this clause pins the (`Vec<usize>`, lex, full-set) corner —
// the (`Vec<usize>`) return-shape row now closes at the
// (full-set × lex), (endpoint × decl/lex), (interior × decl/lex)
// corners with a single implicit `(0..CARDINALITY).collect()` at the
// trivially-derivable (full-set × decl) corner.
let expected_sorted_indices: Vec<usize> = T::sorted_variants()
.into_iter()
.map(<T as ClosedSet>::index_of)
.collect();
assert_eq!(
T::sorted_indices(),
expected_sorted_indices,
"{type_name}: T::sorted_indices() drifted from T::sorted_variants().into_iter().map(T::index_of).collect() — the lex-order full-set decl-slot collection no longer agrees with the natural sorted_variants().map(index_of) two-primitive composition, so a downstream alphabetized full-set loop / lex-permutation payload-table renderer / lex-order metrics counter / alphabetized full-set-observed bitset renderer that binds `T::sorted_indices()` as its `Vec<usize>` lex-order full-set decl-slot query surface would render the wrong slot list",
);
let sorted_indices_len = T::sorted_indices().len();
assert_eq!(
sorted_indices_len,
T::CARDINALITY,
"{type_name}: T::sorted_indices() length {sorted_indices_len} != T::CARDINALITY {} — the lex-order full-set decl-slot collection MUST enumerate every decl-slot exactly once by the sorted_variants().map(index_of) composition contract; a shorter vector silently drops variants, a longer vector silently duplicates them, either bifurcates the CARDINALITY-anchored permutation contract",
T::CARDINALITY,
);
let mut seen_sorted_indices = vec![false; T::CARDINALITY];
for &i in &T::sorted_indices() {
assert!(
i < T::CARDINALITY,
"{type_name}: T::sorted_indices() emitted out-of-range decl-slot {i} (T::CARDINALITY = {}) — the lex-order full-set decl-slot collection admitted a slot outside `0..T::CARDINALITY`, breaking clauses (10) + (17)'s shared bounds invariant",
T::CARDINALITY,
);
assert!(
!seen_sorted_indices[i],
"{type_name}: T::sorted_indices() emitted duplicate decl-slot {i} — the lex-order full-set decl-slot collection MUST enumerate every decl-slot exactly once (permutation of `0..T::CARDINALITY`); a duplicate breaks the (variant → decl-slot) injectivity clause (16) at the lex-aggregation projection surface",
);
seen_sorted_indices[i] = true;
}
// (97) — `T::count_occurrences_of(target, T::ALL)` MUST equal `1`
// for every `target` in `T::ALL`, AND `T::count_occurrences_of(target,
// &[])` MUST equal `0` for every `target` in `T::ALL`. The default
// trait body threads `items.iter().filter(|&&v| T::index_of(v) ==
// T::index_of(target)).count()` verbatim and satisfies both
// fixpoint arms for free; the assertion catches a future
// implementor whose override drifts the projection (a stale
// override that returns `items.len()` regardless of target —
// silently collapsing the per-target multiplicity axis onto the
// slice-length constant and bifurcating the sum-over-targets
// partition identity; a swap override that returns `0`
// unconditionally — silently detaching the multiplicity projection
// from the pinned per-target hit-count and folding every downstream
// "how many times did we hit THIS variant?" query onto the empty-
// slice fixpoint) loudly rather than silently bifurcating the per-
// target multiplicity projection surface every downstream per-
// target occurrence-count consumer routes through. Sibling posture
// to clauses (16) + (17) — clause (16) pins the (variant → decl-
// slot) injectivity `T::index_of` funnels through, clause (17)
// pins the `Vec<Self>` lex-order full-set variant collection
// through sorted_variants alignment, this clause pins the (per-
// target × usize) multiplicity corner — the (per-target × return-
// shape) column of the equivalence-partition surface now opens at
// the (`usize`, per-target) corner with a `Vec<usize>` per-slot
// histogram peer trivially derivable from `T::ALL` iteration on
// this method as a future lift.
for target in T::ALL.iter().copied() {
let full_set_count = T::count_occurrences_of(target, T::ALL);
assert_eq!(
full_set_count,
1,
"{type_name}: T::count_occurrences_of({target_label:?}, T::ALL) == {full_set_count} != 1 — the per-target multiplicity projection MUST report exactly one occurrence of every target on the full set by clause (3)'s pairwise-distinctness invariant; a full-set count != 1 silently bifurcates the (variant → decl-slot) injectivity clause (16) at the per-target multiplicity projection surface, breaking every downstream per-variant occurrence-count consumer",
target_label = <T as ClosedSet>::label(target),
);
let empty_count = T::count_occurrences_of(target, &[]);
assert_eq!(
empty_count,
0,
"{type_name}: T::count_occurrences_of({target_label:?}, &[]) == {empty_count} != 0 — the per-target multiplicity projection MUST report zero occurrences on the empty slice because the filter accepts no position on a zero-position slice; a non-zero empty-slice count silently bifurcates the empty-slice fixpoint contract every downstream per-target occurrence-count consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
}
// (98) — `T::variant_counts(items)` MUST return a `Vec<usize>` of
// length `T::CARDINALITY` AND MUST agree POSITIONWISE with the
// decl-order per-target multiplicity projection on every slice.
// Pinned at both the empty-slice fixpoint (all zeros) AND the
// full-set fixpoint (all ones) — the two arms partition the
// failure modes at the (length-anchored × per-slot value) corner
// simultaneously so an override that returns the wrong LENGTH fires
// on the length arm loudly (a shorter vec silently drops variants,
// a longer vec silently duplicates them, either bifurcates the
// CARDINALITY-anchored histogram contract) AND an override that
// returns the wrong PER-SLOT VALUE fires on the composition-
// equality arm loudly (a per-slot value that folds onto
// `items.len()` regardless of slot returns `T::CARDINALITY` at
// every slot on the full set — silently collapsing the per-slot
// histogram onto the slice-length constant; a per-slot value that
// returns `0` unconditionally silently detaches the histogram from
// the pinned per-target hit-count). The default trait body threads
// `T::ALL.iter().copied().map(|v| T::count_occurrences_of(v, items)).collect()`
// verbatim and satisfies both fixpoint arms + the composition-
// equality arm for free; the assertion catches a future implementor
// whose override drifts the projection loudly rather than silently
// bifurcating the per-slot histogram projection surface every
// downstream per-slot histogram consumer routes through. Sibling
// posture to clause (97) — clause (97) pins the (`usize`, per-
// target) multiplicity corner on the equivalence-partition
// surface; this clause pins the (`Vec<usize>`, per-slot) histogram
// corner peer to it one arity axis over, and pins its composition
// through the per-target primitive so any drift in the underlying
// primitive that clause (97) misses at the per-target × (empty,
// full) 2-corner face still bifurcates loudly at the per-slot
// composition-equality arm here.
let empty_histogram = T::variant_counts(&[]);
assert_eq!(
empty_histogram.len(),
T::CARDINALITY,
"{type_name}: T::variant_counts(&[]).len() == {empty_histogram_len} != T::CARDINALITY {} — the per-slot histogram projection MUST return a `Vec<usize>` of length `T::CARDINALITY` on every slice; a shorter vec silently drops variants, a longer vec silently duplicates them, either bifurcates the CARDINALITY-anchored histogram contract every downstream per-slot histogram consumer routes through",
T::CARDINALITY,
empty_histogram_len = empty_histogram.len(),
);
for (slot, &count) in empty_histogram.iter().enumerate() {
assert_eq!(
count,
0,
"{type_name}: T::variant_counts(&[])[{slot}] == {count} != 0 — the per-slot histogram projection MUST report zero occurrences at every slot on the empty slice because the empty slice hits zero positions; a non-zero empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-slot histogram consumer routes through",
);
}
let full_set_histogram = T::variant_counts(T::ALL);
assert_eq!(
full_set_histogram.len(),
T::CARDINALITY,
"{type_name}: T::variant_counts(T::ALL).len() == {full_set_histogram_len} != T::CARDINALITY {} — the per-slot histogram projection MUST return a `Vec<usize>` of length `T::CARDINALITY` on every slice; a shorter vec silently drops variants, a longer vec silently duplicates them, either bifurcates the CARDINALITY-anchored histogram contract every downstream per-slot histogram consumer routes through",
T::CARDINALITY,
full_set_histogram_len = full_set_histogram.len(),
);
for (slot, &count) in full_set_histogram.iter().enumerate() {
assert_eq!(
count,
1,
"{type_name}: T::variant_counts(T::ALL)[{slot}] == {count} != 1 — the per-slot histogram projection MUST report exactly one occurrence at every slot on the full set by clause (3)'s pairwise-distinctness invariant; a per-slot count != 1 on the full set silently bifurcates the (variant → decl-slot) injectivity clause (16) at the per-slot histogram projection surface, breaking every downstream per-variant histogram consumer",
);
}
let expected_full_set_histogram: Vec<usize> = T::ALL
.iter()
.copied()
.map(|v| T::count_occurrences_of(v, T::ALL))
.collect();
assert_eq!(
full_set_histogram,
expected_full_set_histogram,
"{type_name}: T::variant_counts(T::ALL) drifted from T::ALL.iter().map(|v| T::count_occurrences_of(v, T::ALL)).collect() — the per-slot histogram projection no longer agrees with the natural per-target multiplicity composition on the full-set fixpoint, so a downstream histogram renderer / per-slot budget consumer / per-variant occurrence-count sweep that binds `T::variant_counts` as its `Vec<usize>` per-slot query surface would render the wrong histogram",
);
// (99) — `T::sorted_variant_counts(items)` MUST return a `Vec<usize>`
// of length `T::CARDINALITY` AND MUST agree POSITIONWISE with the
// lex-order per-target multiplicity projection (i.e.
// `T::sorted_variants().into_iter().map(|v|
// T::count_occurrences_of(v, items)).collect()`) on every slice.
// Pinned at BOTH the empty-slice fixpoint (all zeros) AND the
// full-set fixpoint (all ones) — the two arms partition the failure
// modes at the (length-anchored × per-slot value) corner
// simultaneously so an override that returns the wrong LENGTH fires
// on the length arm loudly (a shorter vec silently drops variants,
// a longer vec silently duplicates them, either bifurcates the
// CARDINALITY-anchored histogram contract) AND an override that
// returns the wrong PER-SLOT VALUE fires on the composition-
// equality arm loudly. Sibling posture to clause (98) — clause
// (98) pins the (`Vec<usize>`, per-slot, decl) histogram corner on
// the equivalence-partition surface; this clause pins the
// (`Vec<usize>`, per-slot, lex) histogram corner peer to it one
// ordering axis over, and pins its composition through the per-
// target primitive so any drift in the underlying primitive that
// clause (97) misses at the per-target × (empty, full) 2-corner
// face still bifurcates loudly at the per-slot lex-order
// composition-equality arm here. Sibling posture to clause (96) —
// clause (96) pins the (`Vec<usize>`, sorted-indices, lex) full-set
// decl-slot listing at the composition-equality corner via the
// (decl-slot → variant → decl-slot) round-trip; this clause pins
// the (`Vec<usize>`, sorted-variant-counts, lex) full-set slot
// histogram at the same composition-equality corner via the
// (decl-slot → variant → count) mapping. Every implementor whose
// declaration order aligns with lex order (like `StubKind` and the
// majority of typed closed sets) sees this clause coincide byte-
// for-byte with clause (98); the extra clause fires only on
// implementors whose declaration order DIFFERS from lex order
// (`ReverseLabelStubKind` and any similar out-of-order kind), which
// is exactly where a per-slot histogram drift on the lex axis
// silently bifurcates from the decl axis.
let empty_sorted_histogram = T::sorted_variant_counts(&[]);
assert_eq!(
empty_sorted_histogram.len(),
T::CARDINALITY,
"{type_name}: T::sorted_variant_counts(&[]).len() == {empty_sorted_histogram_len} != T::CARDINALITY {} — the lex-order per-slot histogram projection MUST return a `Vec<usize>` of length `T::CARDINALITY` on every slice; a shorter vec silently drops variants, a longer vec silently duplicates them, either bifurcates the CARDINALITY-anchored histogram contract every downstream lex-order per-slot histogram consumer routes through",
T::CARDINALITY,
empty_sorted_histogram_len = empty_sorted_histogram.len(),
);
for (slot, &count) in empty_sorted_histogram.iter().enumerate() {
assert_eq!(
count,
0,
"{type_name}: T::sorted_variant_counts(&[])[{slot}] == {count} != 0 — the lex-order per-slot histogram projection MUST report zero occurrences at every slot on the empty slice because the empty slice hits zero positions; a non-zero empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order per-slot histogram consumer routes through",
);
}
let full_set_sorted_histogram = T::sorted_variant_counts(T::ALL);
assert_eq!(
full_set_sorted_histogram.len(),
T::CARDINALITY,
"{type_name}: T::sorted_variant_counts(T::ALL).len() == {full_set_sorted_histogram_len} != T::CARDINALITY {} — the lex-order per-slot histogram projection MUST return a `Vec<usize>` of length `T::CARDINALITY` on every slice; a shorter vec silently drops variants, a longer vec silently duplicates them, either bifurcates the CARDINALITY-anchored histogram contract every downstream lex-order per-slot histogram consumer routes through",
T::CARDINALITY,
full_set_sorted_histogram_len = full_set_sorted_histogram.len(),
);
for (slot, &count) in full_set_sorted_histogram.iter().enumerate() {
assert_eq!(
count,
1,
"{type_name}: T::sorted_variant_counts(T::ALL)[{slot}] == {count} != 1 — the lex-order per-slot histogram projection MUST report exactly one occurrence at every slot on the full set by clause (3)'s pairwise-distinctness invariant; a per-slot count != 1 on the full set silently bifurcates the (variant → decl-slot) injectivity clause (16) at the lex-order per-slot histogram projection surface, breaking every downstream lex-order per-variant histogram consumer",
);
}
let expected_full_set_sorted_histogram: Vec<usize> = T::sorted_variants()
.into_iter()
.map(|v| T::count_occurrences_of(v, T::ALL))
.collect();
assert_eq!(
full_set_sorted_histogram,
expected_full_set_sorted_histogram,
"{type_name}: T::sorted_variant_counts(T::ALL) drifted from T::sorted_variants().into_iter().map(|v| T::count_occurrences_of(v, T::ALL)).collect() — the lex-order per-slot histogram projection no longer agrees with the natural per-target multiplicity composition mapped over the sorted variants list on the full-set fixpoint, so a downstream histogram renderer / per-slot budget consumer / per-variant occurrence-count sweep that binds `T::sorted_variant_counts` as its `Vec<usize>` lex-order per-slot query surface would render the wrong histogram",
);
// (100) — `T::max_variant_count(items)` MUST agree with the max-
// reduction over `T::variant_counts(items)` on every slice AND MUST
// land on its three canonical fixpoints (`0` on the empty slice,
// `1` on the full set, `2` on the doubled full set). The three
// fixpoints partition the failure modes at the (scalar-value ×
// slice-shape) corner simultaneously so an override that folds
// onto `items.len()` unconditionally fires on the full-set arm
// (returns `T::CARDINALITY` at every non-singleton full set rather
// than `1`); an override that returns `0` unconditionally fires
// on the full-set arm (returns `0` rather than `1`) AND the
// doubled-full-set arm (returns `0` rather than `2`); an override
// that returns the WRONG max-bar on a non-fixpoint slice
// bifurcates loudly at the composition-equality arm (against
// `T::variant_counts(items).into_iter().max().unwrap_or(0)`) on the
// full-set fixpoint (which folds through the histogram exactly).
// The default trait body threads
// `T::ALL.iter().copied().map(|v| T::count_occurrences_of(v, items)).max().unwrap_or(0)`
// verbatim and satisfies all three fixpoint arms + the
// composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the scalar modal-count aggregate
// projection surface every downstream max-bar consumer routes
// through. Sibling posture to clause (98) — clause (98) pins the
// (`Vec<usize>`, per-slot, decl) histogram corner on the
// equivalence-partition surface; this clause pins the (`usize`,
// set-level, statistical-aggregate) modal-count corner peer to it
// one return-shape axis over (Vec-return → scalar-return via
// max-reduction), and pins its composition through the per-slot
// histogram primitive so any drift in the underlying primitive that
// clauses (97) + (98) miss at the per-target / per-slot ×
// (empty, full) 4-corner face still bifurcates loudly at the
// set-level max-reduction composition-equality arm here. The
// scalar-return column carries no ordering to permute on the
// output side, so the (decl, lex) ordering axis collapses on this
// clause; the composition-equality identity binds equivalently
// against `T::sorted_variant_counts` (permutation-invariance of
// max-reduction).
assert_eq!(
T::max_variant_count(&[]),
0,
"{type_name}: T::max_variant_count(&[]) != 0 — the N-ary scalar modal-count aggregate MUST report `0` on the empty slice because every per-variant occurrence count is `0` on a zero-position slice and the max-bar collapses to `0`; a non-zero empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream max-bar consumer routes through",
);
assert_eq!(
T::max_variant_count(T::ALL),
1,
"{type_name}: T::max_variant_count(T::ALL) != 1 — the N-ary scalar modal-count aggregate MUST report `1` on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position and the max-bar collapses to `1`; a full-set max-bar != 1 silently bifurcates the (variant → decl-slot) injectivity clause (16) at the scalar modal-count aggregate projection surface, breaking every downstream max-bar consumer",
);
let doubled_full_set: Vec<T> = T::ALL
.iter()
.copied()
.chain(T::ALL.iter().copied())
.collect();
assert_eq!(
T::max_variant_count(&doubled_full_set),
2,
"{type_name}: T::max_variant_count(&doubled_full_set) != 2 — the N-ary scalar modal-count aggregate MUST report `2` on the doubled full set because every variant appears at exactly two positions in the doubled slice and the max-bar collapses to `2`; a doubled-full-set max-bar != 2 silently detaches the scalar aggregate from the pinned per-variant occurrence count on the doubled-slice fixpoint, breaking every downstream max-bar consumer",
);
let full_set_max_bar_expected = T::variant_counts(T::ALL).into_iter().max().unwrap_or(0);
assert_eq!(
T::max_variant_count(T::ALL),
full_set_max_bar_expected,
"{type_name}: T::max_variant_count(T::ALL) drifted from T::variant_counts(T::ALL).into_iter().max().unwrap_or(0) — the N-ary scalar modal-count aggregate no longer agrees with the max-reduction over the decl-order per-slot histogram on the full-set fixpoint, so a downstream statistical-aggregate consumer that binds `T::max_variant_count` as its scalar modal-count query surface would report the wrong bar-height",
);
// (101) — `T::min_variant_count(items)` MUST agree with the min-
// reduction over `T::variant_counts(items)` on every slice AND MUST
// land on its three canonical fixpoints (`0` on the empty slice,
// `1` on the full set, `2` on the doubled full set). The three
// fixpoints partition the failure modes at the (scalar-value ×
// slice-shape) corner simultaneously so an override that folds
// onto `items.len()` unconditionally fires on the full-set arm
// (returns `T::CARDINALITY` at every non-singleton full set rather
// than `1`); an override that returns `1` unconditionally fires
// on the empty-slice arm (returns `1` rather than `0`); an override
// that returns the WRONG min-bar on a non-fixpoint slice
// bifurcates loudly at the composition-equality arm (against
// `T::variant_counts(items).into_iter().min().unwrap_or(0)`) on the
// full-set fixpoint (which folds through the histogram exactly).
// The default trait body threads
// `T::ALL.iter().copied().map(|v| T::count_occurrences_of(v, items)).min().unwrap_or(0)`
// verbatim and satisfies all three fixpoint arms + the
// composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the scalar least-common-
// multiplicity aggregate projection surface every downstream min-
// bar consumer routes through. Sibling posture to clause (100) —
// clause (100) pins the (max-bar) direction corner of the
// (set-level × usize × statistical-aggregate) column; this clause
// pins the (min-bar) direction corner peer to it one direction-
// axis over (max-reduction → min-reduction), and pins its
// composition through the per-slot histogram primitive so any
// drift in the underlying primitive that clauses (97) + (98) miss
// at the per-target / per-slot × (empty, full) 4-corner face still
// bifurcates loudly at the set-level min-reduction composition-
// equality arm here. The scalar-return column carries no ordering
// to permute on the output side, so the (decl, lex) ordering axis
// collapses on this clause; the composition-equality identity
// binds equivalently against `T::sorted_variant_counts`
// (permutation-invariance of min-reduction).
assert_eq!(
T::min_variant_count(&[]),
0,
"{type_name}: T::min_variant_count(&[]) != 0 — the N-ary scalar least-common-multiplicity aggregate MUST report `0` on the empty slice because every per-variant occurrence count is `0` on a zero-position slice and the min-bar collapses to `0`; a non-zero empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream min-bar consumer routes through",
);
assert_eq!(
T::min_variant_count(T::ALL),
1,
"{type_name}: T::min_variant_count(T::ALL) != 1 — the N-ary scalar least-common-multiplicity aggregate MUST report `1` on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position and the min-bar collapses to `1`; a full-set min-bar != 1 silently bifurcates the (variant → decl-slot) injectivity clause (16) at the scalar least-common-multiplicity aggregate projection surface, breaking every downstream min-bar consumer",
);
assert_eq!(
T::min_variant_count(&doubled_full_set),
2,
"{type_name}: T::min_variant_count(&doubled_full_set) != 2 — the N-ary scalar least-common-multiplicity aggregate MUST report `2` on the doubled full set because every variant appears at exactly two positions in the doubled slice and the min-bar collapses to `2`; a doubled-full-set min-bar != 2 silently detaches the scalar aggregate from the pinned per-variant occurrence count on the doubled-slice fixpoint, breaking every downstream min-bar consumer",
);
let full_set_min_bar_expected = T::variant_counts(T::ALL).into_iter().min().unwrap_or(0);
assert_eq!(
T::min_variant_count(T::ALL),
full_set_min_bar_expected,
"{type_name}: T::min_variant_count(T::ALL) drifted from T::variant_counts(T::ALL).into_iter().min().unwrap_or(0) — the N-ary scalar least-common-multiplicity aggregate no longer agrees with the min-reduction over the decl-order per-slot histogram on the full-set fixpoint, so a downstream statistical-aggregate consumer that binds `T::min_variant_count` as its scalar min-bar query surface would report the wrong bar-height",
);
// (102) — `T::variant_count_range(items)` MUST agree with the
// `(min_variant_count, max_variant_count)` pair on every slice AND
// MUST land on its three canonical degenerate-tuple fixpoints
// (`(0, 0)` on the empty slice, `(1, 1)` on the full set, `(2, 2)`
// on the doubled full set). The three fixpoints partition the
// failure modes at the (scalar-value × slice-shape × tuple-slot)
// corner simultaneously so an override that folds onto
// `(items.len(), items.len())` unconditionally fires on the full-
// set arm (returns `(T::CARDINALITY, T::CARDINALITY)` rather than
// `(1, 1)` at every T::CARDINALITY >= 2); an override that
// returns `(0, 0)` unconditionally fires on the full-set arm
// (returns `(0, 0)` rather than `(1, 1)`) AND the doubled-full-
// set arm (returns `(0, 0)` rather than `(2, 2)`); an override
// that swaps the tuple slots (returns `(max_variant_count,
// min_variant_count)` instead of `(min_variant_count,
// max_variant_count)`) survives every constant-histogram fixpoint
// (all three are degenerate tuples where the swap is invisible)
// but bifurcates loudly at the composition-equality arm against
// the pinned `(T::min_variant_count(T::ALL), T::max_variant_count
// (T::ALL))` pair on any non-degenerate slice — the full-set arm
// is degenerate at `(1, 1)` so the swap survives there, but any
// real closed-set implementor with a non-fixpoint sweep at the
// downstream test surface catches the swap. The default trait body
// threads `(T::min_variant_count(items), T::max_variant_count
// (items))` verbatim and satisfies all three fixpoint arms + the
// composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the pair-return endpoint-
// anchor projection surface every downstream range consumer routes
// through. Sibling posture to clauses (100) + (101) — clauses (100)
// + (101) pin the two scalar direction corners of the (set-level ×
// usize × statistical-aggregate) column; this clause pins the
// pair-return endpoint-anchor corner peer to them one return-shape
// axis over (scalar-return → pair-return via `(min, max)`
// packaging), and pins its composition through both direction
// corners simultaneously so any drift in either underlying
// primitive that clauses (100) or (101) miss at their respective
// scalar-return corner still bifurcates loudly at the pair-return
// composition-equality arm here. The pair-return column carries
// no ordering to permute on the output side (the `(min, max)`
// convention pins slot roles by direction, not by input order), so
// the (decl, lex) ordering axis collapses on this clause.
assert_eq!(
T::variant_count_range(&[]),
(0, 0),
"{type_name}: T::variant_count_range(&[]) != (0, 0) — the N-ary pair-return endpoint-anchor projection MUST report the `(0, 0)` degenerate tuple on the empty slice because every per-variant occurrence count is `0` on a zero-position slice and BOTH direction endpoints collapse to `0`; a non-(0, 0) empty-slice value silently bifurcates the empty-slice degenerate-tuple fixpoint contract every downstream histogram-range consumer routes through",
);
assert_eq!(
T::variant_count_range(T::ALL),
(1, 1),
"{type_name}: T::variant_count_range(T::ALL) != (1, 1) — the N-ary pair-return endpoint-anchor projection MUST report the `(1, 1)` degenerate tuple on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position and BOTH direction endpoints collapse to `1`; a full-set pair != (1, 1) silently bifurcates the (variant → decl-slot) injectivity clause (16) at the pair-return endpoint-anchor projection surface, breaking every downstream histogram-range consumer",
);
assert_eq!(
T::variant_count_range(&doubled_full_set),
(2, 2),
"{type_name}: T::variant_count_range(&doubled_full_set) != (2, 2) — the N-ary pair-return endpoint-anchor projection MUST report the `(2, 2)` degenerate tuple on the doubled full set because every variant appears at exactly two positions in the doubled slice and BOTH direction endpoints collapse to `2`; a doubled-full-set pair != (2, 2) silently detaches the pair-return endpoint anchors from the pinned per-variant occurrence count on the doubled-slice fixpoint, breaking every downstream histogram-range consumer",
);
let full_set_range_expected = (T::min_variant_count(T::ALL), T::max_variant_count(T::ALL));
assert_eq!(
T::variant_count_range(T::ALL),
full_set_range_expected,
"{type_name}: T::variant_count_range(T::ALL) drifted from (T::min_variant_count(T::ALL), T::max_variant_count(T::ALL)) — the N-ary pair-return endpoint-anchor projection no longer agrees with the (min-bar, max-bar) direction-corner pair on the full-set fixpoint, so a downstream range consumer that binds `T::variant_count_range` as its pair-return histogram-endpoint query surface would report the wrong endpoint pair; the composition-equality arm catches an override that swaps the tuple slots on any non-degenerate slice AND catches any override whose direction-corner composition drifts loudly",
);
let (range_min, range_max) = T::variant_count_range(&doubled_full_set);
assert!(
range_min <= range_max,
"{type_name}: T::variant_count_range(&doubled_full_set) == ({range_min}, {range_max}) violates the (slot-0 <= slot-1) direction-axis order — the (min-bar) endpoint MUST be bounded above by the (max-bar) endpoint on every slice because `min(xs) <= max(xs)` on every non-empty carrier `xs`; a slot-0 > slot-1 tuple at the doubled-full-set fixpoint indicates the pair-return projection swapped its slot roles or drifted the composition through a non-monotone reduction",
);
// (103) — `T::is_uniform(items)` MUST agree with the pair-return
// endpoint-anchor projection's slot-equality on every slice AND
// MUST land on its three canonical TRUE fixpoints (empty slice,
// full set, doubled full set — all three canonical constant-
// histogram fixpoints yield uniform histograms). The three TRUE
// fixpoints alone cannot catch a `_ => true` unconditional
// override because all three yield `true` under the correct
// projection too. The composition-equality arm against the pair-
// return corner on the doubled full set catches drift where the
// uniformity predicate detaches from the pair-endpoint-equality
// composition. The (T::CARDINALITY >= 2) singleton arm catches
// a `_ => true` unconditional override where the correct
// projection would return `false` on the strictly-non-uniform
// singleton histogram `(0, …, 0, 1, 0, …, 0)`. At T::CARDINALITY
// == 1 every histogram is trivially uniform so the singleton
// catcher is gated behind the cardinality guard. The default
// trait body threads `min_bar == max_bar` from the pair-return
// corner verbatim and satisfies all four arms for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// bool-return uniformity projection surface every downstream
// uniformity consumer routes through. Sibling posture to clauses
// (100) + (101) + (102) — clauses (100) + (101) pin the two
// scalar direction corners of the (set-level × usize ×
// statistical-aggregate) column; clause (102) pins the pair-
// return endpoint-anchor corner one return-shape axis over;
// this clause pins the bool-return uniformity corner peer to
// them one further return-shape axis over (scalar-return →
// pair-return → bool-return via slot-equality reduction) and
// pins its composition through the pair-return corner so any
// drift in that underlying primitive that clause (102) misses
// at its own composition-equality arm still bifurcates loudly
// at the bool-return composition-equality arm here. The bool-
// return column carries no ordering to permute on the output
// side (the projection is a scalar reduction of a slot-equality
// check), so the (decl, lex) ordering axis collapses on this
// clause.
assert!(
T::is_uniform(&[]),
"{type_name}: T::is_uniform(&[]) == false — the N-ary bool-return uniformity predicate MUST report `true` on the empty slice because every per-variant occurrence count is `0` on a zero-position slice and a constant-`0` histogram is trivially uniform (min-bar == max-bar == 0); a `false` empty-slice value silently bifurcates the empty-slice TRUE-fixpoint contract every downstream uniformity consumer routes through",
);
assert!(
T::is_uniform(T::ALL),
"{type_name}: T::is_uniform(T::ALL) == false — the N-ary bool-return uniformity predicate MUST report `true` on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position and the histogram collapses to a constant-`1` bar (min-bar == max-bar == 1); a `false` full-set value silently bifurcates the (variant → decl-slot) injectivity clause (16) at the bool-return uniformity projection surface, breaking every downstream uniformity consumer",
);
assert!(
T::is_uniform(&doubled_full_set),
"{type_name}: T::is_uniform(&doubled_full_set) == false — the N-ary bool-return uniformity predicate MUST report `true` on the doubled full set because every variant appears at exactly two positions in the doubled slice and the histogram collapses to a constant-`2` bar (min-bar == max-bar == 2); a `false` doubled-full-set value silently detaches the bool-return uniformity projection from the pinned per-variant occurrence count on the doubled-slice fixpoint, breaking every downstream uniformity consumer",
);
let (doubled_min_bar, doubled_max_bar) = T::variant_count_range(&doubled_full_set);
assert_eq!(
T::is_uniform(&doubled_full_set),
doubled_min_bar == doubled_max_bar,
"{type_name}: T::is_uniform(&doubled_full_set) drifted from T::variant_count_range(&doubled_full_set).0 == T::variant_count_range(&doubled_full_set).1 — the N-ary bool-return uniformity projection no longer agrees with the pair-return endpoint-anchor projection's slot-equality on the doubled-full-set fixpoint, so a downstream uniformity consumer that binds `T::is_uniform` as its bool-return histogram-flatness query surface would report the wrong bit; the composition-equality arm catches an override that detaches the bool from the pair-endpoint composition on any slice",
);
if T::CARDINALITY >= 2 {
let singleton = [T::ALL[0]];
assert!(
!T::is_uniform(&singleton),
"{type_name}: T::is_uniform(&[T::ALL[0]]) == true on a cardinality-{cardinality} closed set — the N-ary bool-return uniformity predicate MUST report `false` on every singleton slice when T::CARDINALITY >= 2 because a singleton histogram is `(0, …, 0, 1, 0, …, 0)` with a strictly-positive (max == 1) bar at the hit variant and a strictly-zero (min == 0) bar at every other variant, so min-bar != max-bar; a `true` singleton value silently bifurcates the strictly-non-uniform singleton fixpoint contract every downstream uniformity consumer routes through, and catches a `_ => true` unconditional override that the three constant-histogram TRUE fixpoints (empty, full, doubled) cannot see",
cardinality = T::CARDINALITY,
);
}
// (104) — `T::variant_count_span(items)` MUST agree with the
// pair-return endpoint-anchor projection's slot-subtraction on
// every slice AND MUST land on its three canonical ZERO fixpoints
// (empty slice, full set, doubled full set — all three canonical
// constant-histogram fixpoints yield uniform histograms with span
// 0). The three ZERO fixpoints alone cannot catch a `_ => 0`
// unconditional override because all three yield `0` under the
// correct projection too. The composition-equality arm against
// the pair-return corner on the doubled full set catches drift
// where the scalar-difference projection detaches from the pair-
// endpoint-subtraction composition. The (T::CARDINALITY >= 2)
// singleton arm catches a `_ => 0` unconditional override where
// the correct projection would return `1` on the strictly-non-
// uniform singleton histogram `(0, 1)` at the pair-return
// corner. At T::CARDINALITY == 1 every histogram is trivially
// uniform (span == 0) so the singleton catcher is gated behind
// the cardinality guard. The default trait body threads
// `max_bar - min_bar` from the pair-return corner verbatim and
// satisfies all four arms for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the scalar-difference range-
// width projection surface every downstream span consumer routes
// through. Sibling posture to clauses (100) + (101) + (102) +
// (103) — clauses (100) + (101) pin the two scalar direction
// corners of the (set-level × usize × statistical-aggregate)
// column; clause (102) pins the pair-return endpoint-anchor
// corner one return-shape axis over; clause (103) pins the
// bool-return uniformity corner peer to them via slot-EQUALITY;
// this clause pins the usize-return SCALAR-DIFFERENCE corner
// peer to them via slot-SUBTRACTION and pins its composition
// through the pair-return corner so any drift in that
// underlying primitive that clauses (102) + (103) miss at their
// own composition-equality arms still bifurcates loudly at the
// scalar-difference composition-equality arm here. The usize-
// return column carries no ordering to permute on the output
// side (the projection is a scalar reduction of a slot-
// subtraction), so the (decl, lex) ordering axis collapses on
// this clause.
assert_eq!(
T::variant_count_span(&[]),
0,
"{type_name}: T::variant_count_span(&[]) != 0 — the N-ary scalar-difference range-width projection MUST report `0` on the empty slice because every per-variant occurrence count is `0` on a zero-position slice, the pair-return corner collapses to `(0, 0)`, and the difference collapses to `0 - 0 == 0`; a non-zero empty-slice value silently bifurcates the empty-slice ZERO-fixpoint contract every downstream span consumer routes through",
);
assert_eq!(
T::variant_count_span(T::ALL),
0,
"{type_name}: T::variant_count_span(T::ALL) != 0 — the N-ary scalar-difference range-width projection MUST report `0` on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position, the pair-return corner collapses to `(1, 1)`, and the difference collapses to `1 - 1 == 0`; a non-zero full-set value silently bifurcates the (variant → decl-slot) injectivity clause (16) at the scalar-difference range-width projection surface, breaking every downstream span consumer",
);
assert_eq!(
T::variant_count_span(&doubled_full_set),
0,
"{type_name}: T::variant_count_span(&doubled_full_set) != 0 — the N-ary scalar-difference range-width projection MUST report `0` on the doubled full set because every variant appears at exactly two positions in the doubled slice, the pair-return corner collapses to `(2, 2)`, and the difference collapses to `2 - 2 == 0`; a non-zero doubled-full-set value silently detaches the scalar-difference range-width projection from the pinned per-variant occurrence count on the doubled-slice fixpoint, breaking every downstream span consumer",
);
assert_eq!(
T::variant_count_span(&doubled_full_set),
doubled_max_bar - doubled_min_bar,
"{type_name}: T::variant_count_span(&doubled_full_set) drifted from T::variant_count_range(&doubled_full_set).1 - T::variant_count_range(&doubled_full_set).0 — the N-ary scalar-difference range-width projection no longer agrees with the pair-return endpoint-anchor projection's slot-subtraction on the doubled-full-set fixpoint, so a downstream span consumer that binds `T::variant_count_span` as its scalar-return histogram-spread query surface would report the wrong scalar; the composition-equality arm catches an override that detaches the usize-return scalar-difference from the pair-endpoint subtraction on any slice",
);
if T::CARDINALITY >= 2 {
let singleton = [T::ALL[0]];
assert_eq!(
T::variant_count_span(&singleton),
1,
"{type_name}: T::variant_count_span(&[T::ALL[0]]) != 1 on a cardinality-{cardinality} closed set — the N-ary scalar-difference range-width projection MUST report `1` on every singleton slice when T::CARDINALITY >= 2 because a singleton histogram is `(0, …, 0, 1, 0, …, 0)`, the pair-return corner collapses to `(0, 1)`, and the difference collapses to `1 - 0 == 1`; a non-`1` singleton value silently bifurcates the strictly-non-uniform singleton fixpoint contract every downstream span consumer routes through, and catches a `_ => 0` unconditional override that the three constant-histogram ZERO fixpoints (empty, full, doubled) cannot see",
cardinality = T::CARDINALITY,
);
}
// (105) — `T::occurs_in(target, items)` MUST agree with the per-
// target multiplicity projection's strictly-positive fixpoint on
// every (target, slice) pair AND MUST land on its two canonical
// fixpoints (`false` at every target on the empty slice, `true` at
// every target on the full set). The two fixpoints partition the
// failure modes at the (bool-value × slice-shape) corner
// simultaneously so an override that folds onto `true`
// unconditionally fires on the empty-slice arm (returns `true` at
// every target rather than `false`); an override that returns
// `false` unconditionally fires on the full-set arm (returns
// `false` at every target rather than `true`); an override that
// swaps the bool value on any non-fixpoint slice bifurcates loudly
// at the composition-equality arm against
// `T::count_occurrences_of(target, items) > 0` on the full-set
// fixpoint (which folds through the multiplicity projection
// exactly). The default trait body threads
// `<Self as ClosedSet>::count_occurrences_of(target, items) > 0`
// verbatim and satisfies both fixpoint arms + the composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target membership predicate
// projection surface every downstream membership consumer routes
// through. Sibling posture to clause (97) — clause (97) pins the
// (`usize`, per-target) multiplicity corner on the equivalence-
// partition surface; this clause pins the (`bool`, per-target)
// membership corner peer to it one return-shape axis over
// (usize-return → bool-return via strictly-positive fixpoint),
// and pins its composition through the per-target multiplicity
// primitive so any drift in that underlying primitive that
// clause (97) misses at the per-target × (empty, full) 2-corner
// face still bifurcates loudly at the per-target membership
// composition-equality arm here. The bool-return column carries
// no ordering to permute on the output side (a single bit has no
// permutation), so the (decl, lex) ordering axis collapses on
// this clause.
for target in T::ALL.iter().copied() {
let empty_membership = T::occurs_in(target, &[]);
assert!(
!empty_membership,
"{type_name}: T::occurs_in({target_label:?}, &[]) == true != false — the per-target membership predicate MUST report `false` on the empty slice because the filter accepts no position on a zero-position slice, the multiplicity collapses to `0`, and `0 > 0` folds to `false`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-target membership consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let full_set_membership = T::occurs_in(target, T::ALL);
assert!(
full_set_membership,
"{type_name}: T::occurs_in({target_label:?}, T::ALL) == false != true — the per-target membership predicate MUST report `true` at every target on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position in T::ALL, the multiplicity collapses to `1`, and `1 > 0` folds to `true`; a `false` full-set value silently bifurcates the (variant → decl-slot) injectivity clause (16) at the per-target membership projection surface, breaking every downstream membership consumer",
target_label = <T as ClosedSet>::label(target),
);
let expected_full_set_membership = T::count_occurrences_of(target, T::ALL) > 0;
assert_eq!(
full_set_membership,
expected_full_set_membership,
"{type_name}: T::occurs_in({target_label:?}, T::ALL) drifted from (T::count_occurrences_of({target_label:?}, T::ALL) > 0) — the per-target membership predicate no longer agrees with the strictly-positive fixpoint of the per-target multiplicity projection on the full-set fixpoint, so a downstream membership consumer that binds `T::occurs_in` as its per-target bool query surface would report the wrong bit; the composition-equality arm catches an override that detaches the bool-return per-target membership from the usize-return per-target multiplicity's `> 0` comparison on any slice",
target_label = <T as ClosedSet>::label(target),
);
}
// (106) — `T::first_occurrence_of(target, items)` MUST agree with
// the per-target head-position projection on every (target, slice)
// pair AND MUST land on its two canonical fixpoints (`None` at
// every target on the empty slice, `Some(T::index_of(target))` at
// every target on the full set). The two fixpoints partition the
// failure modes at the (Option-discriminant × slice-shape) corner
// simultaneously so an override that folds onto `None` regardless
// of `target` fires on the full-set arm (returns `None` at every
// target rather than `Some(T::index_of(target))`); an override
// that shifts the returned position by a constant offset from
// `T::index_of(target)` fires on the full-set position-equality
// arm; an override that swaps the endpoint direction (returning
// the LAST hit instead of the FIRST) is undetectable on the full
// set alone (each variant appears at exactly ONE position of the
// full set, so first == last there), but bifurcates loudly at the
// presence-composition arm against `T::occurs_in(target, items)`
// on the doubled-full-set slice (where first == index_of and
// last == CARDINALITY + index_of are DISTINCT). Sibling posture to
// clauses (97) + (105) — clause (97) pins the (`usize`, per-
// target) multiplicity corner on the equivalence-partition
// surface; clause (105) pins the (`bool`, per-target) membership
// corner peer to it one return-shape axis over; this clause pins
// the (`Option<usize>`, per-target, head) corner peer to them two
// return-shape axes over. The `Option<usize>`-return column
// carries no set-level ordering to permute on the output side
// (the Option's `Some` payload is a slice index, not a variant
// slot), so the (decl, lex) ordering axis on `T::ALL` collapses
// on this clause; the per-slot ordering axis on the SLICE side
// is pinned by the head-direction (position) arm of this clause
// and the tail-direction (rposition) arm of clause (107).
for target in T::ALL.iter().copied() {
let empty_head = T::first_occurrence_of(target, &[]);
assert!(
empty_head.is_none(),
"{type_name}: T::first_occurrence_of({target_label:?}, &[]) == {empty_head:?} != None — the per-target head-position projection MUST report `None` on the empty slice because the position sweep finds no match on a zero-position slice, so `Iterator::position` yields `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream head-position consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let full_set_head = T::first_occurrence_of(target, T::ALL);
let target_index = <T as ClosedSet>::index_of(target);
assert_eq!(
full_set_head,
Some(target_index),
"{type_name}: T::first_occurrence_of({target_label:?}, T::ALL) drifted from Some(T::index_of({target_label:?})) — the per-target head-position projection MUST report `Some(T::index_of(target))` at every target on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position in T::ALL at slot `T::index_of(target)`, so the smallest matching position collapses to that slot; a drifted full-set head position silently detaches the head-position projection from the (variant → decl-slot) injectivity clause (16) at the head-position projection surface, breaking every downstream head-position consumer",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
full_set_head.is_some(),
T::occurs_in(target, T::ALL),
"{type_name}: T::first_occurrence_of({target_label:?}, T::ALL).is_some() drifted from T::occurs_in({target_label:?}, T::ALL) — the per-target head-position projection's Option discriminant no longer agrees with the per-target bool membership predicate on the full-set fixpoint, so a downstream head-position consumer that binds `T::first_occurrence_of(_, _).is_some()` as its presence query surface would disagree with the per-target bool predicate; the composition-equality arm catches an override that detaches the Option discriminant from the strictly-positive fixpoint of the per-target multiplicity primitive on any slice",
target_label = <T as ClosedSet>::label(target),
);
}
// (107) — `T::last_occurrence_of(target, items)` MUST agree with
// the per-target tail-position projection on every (target, slice)
// pair AND MUST land on its three canonical fixpoints (`None` at
// every target on the empty slice, `Some(T::index_of(target))` at
// every target on the full set, `Some(T::CARDINALITY +
// T::index_of(target))` at every target on the doubled full set).
// The three fixpoints partition the failure modes at the
// (Option-discriminant × slice-shape × endpoint-direction) corner
// simultaneously so an override that folds onto `None` regardless
// of `target` fires on the full-set arm; an override that returns
// `Some(0)` unconditionally fires on the doubled-full-set arm at
// every target with `T::index_of(target) > 0` (which is guaranteed
// at cardinality >= 2 and at least one such target); an override
// that swaps the endpoint direction (returning the FIRST hit
// instead of the LAST) is undetectable on the full set alone (each
// variant appears at exactly ONE position of the full set, so
// first == last there), but fires loudly on the doubled-full-set
// arm at every target because the second occurrence at
// `T::CARDINALITY + T::index_of(target)` distinguishes it from the
// first at `T::index_of(target)` (a `first_occurrence_of` swap
// returns `T::index_of(target)` at the first slot, mismatching the
// pinned second-hit `T::CARDINALITY + T::index_of(target)`).
// Sibling posture to clauses (97) + (105) + (106) — clause (97)
// pins the (`usize`, per-target) multiplicity corner on the
// equivalence-partition surface; clause (105) pins the (`bool`,
// per-target) membership corner peer to it one return-shape axis
// over; clause (106) pins the (`Option<usize>`, per-target, head)
// corner peer to them two return-shape axes over; this clause
// pins the (`Option<usize>`, per-target, tail) corner peer to
// clause (106) one endpoint-direction axis over on the SLICE side.
// The `Option<usize>`-return column carries no set-level ordering
// to permute on the output side, so the (decl, lex) ordering axis
// on `T::ALL` collapses on this clause; the per-slot ordering axis
// on the SLICE side is pinned by the tail-direction (rposition)
// arm of this clause and the head-direction (position) arm of
// clause (106), which together CLOSE the (Option<usize>, per-
// target, endpoint-direction) 2-corner face at both endpoints.
for target in T::ALL.iter().copied() {
let empty_tail = T::last_occurrence_of(target, &[]);
assert!(
empty_tail.is_none(),
"{type_name}: T::last_occurrence_of({target_label:?}, &[]) == {empty_tail:?} != None — the per-target tail-position projection MUST report `None` on the empty slice because the reverse position sweep finds no match on a zero-position slice, so `Iterator::rposition` yields `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream tail-position consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let target_index = <T as ClosedSet>::index_of(target);
let full_set_tail = T::last_occurrence_of(target, T::ALL);
assert_eq!(
full_set_tail,
Some(target_index),
"{type_name}: T::last_occurrence_of({target_label:?}, T::ALL) drifted from Some(T::index_of({target_label:?})) — the per-target tail-position projection MUST report `Some(T::index_of(target))` at every target on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position in T::ALL at slot `T::index_of(target)`, so the largest matching position coincides with the smallest and both collapse to that slot; a drifted full-set tail position silently detaches the tail-position projection from the (variant → decl-slot) injectivity clause (16) at the tail-position projection surface, breaking every downstream tail-position consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_tail = T::last_occurrence_of(target, &doubled_full_set);
assert_eq!(
doubled_tail,
Some(T::CARDINALITY + target_index),
"{type_name}: T::last_occurrence_of({target_label:?}, &doubled_full_set) drifted from Some(T::CARDINALITY + T::index_of({target_label:?})) — the per-target tail-position projection MUST report `Some(T::CARDINALITY + T::index_of(target))` at every target on the doubled full set because every variant appears at TWO positions (T::index_of(target) and T::CARDINALITY + T::index_of(target)) and the tail-position projection binds the SECOND occurrence at the doubled-slice fixpoint; a drifted doubled-tail value silently detaches the tail-position projection from the endpoint-direction axis, and in particular catches an override that swaps the endpoint direction (returns `Some(T::index_of(target))` instead of `Some(T::CARDINALITY + T::index_of(target))`) that clause (106)'s head-position full-set arm cannot see",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
doubled_tail.is_some(),
T::occurs_in(target, &doubled_full_set),
"{type_name}: T::last_occurrence_of({target_label:?}, &doubled_full_set).is_some() drifted from T::occurs_in({target_label:?}, &doubled_full_set) — the per-target tail-position projection's Option discriminant no longer agrees with the per-target bool membership predicate on the doubled-full-set fixpoint, so a downstream tail-position consumer that binds `T::last_occurrence_of(_, _).is_some()` as its presence query surface would disagree with the per-target bool predicate",
target_label = <T as ClosedSet>::label(target),
);
}
// (108) — `T::all_occurrences_of(target, items)` MUST agree with
// the per-target every-position projection on every (target, slice)
// pair AND MUST land on its three canonical fixpoints (empty vec
// at every target on the empty slice, `vec![T::index_of(target)]`
// at every target on the full set, `vec![T::index_of(target),
// T::CARDINALITY + T::index_of(target)]` at every target on the
// doubled full set). The three fixpoints partition the failure
// modes at the (return-length × per-element value × slice-shape)
// corner simultaneously so an override that folds onto the empty
// vec regardless of `target` fires on the full-set arm (returns
// `vec![]` at every target rather than the pinned singleton
// `vec![T::index_of(target)]`); an override that returns
// `vec![T::index_of(target)]` regardless of slice-arity fires on
// the doubled-full-set arm (returns length-1 vec rather than the
// pinned length-2 vec `vec![T::index_of(target), T::CARDINALITY +
// T::index_of(target)]`); an override that returns an ascending-
// shifted vec on the doubled slice bifurcates loudly at either
// the head-composition arm (against `T::first_occurrence_of` on
// `first().copied()`) or the tail-composition arm (against
// `T::last_occurrence_of` on `last().copied()`); an override that
// scrambles the returned indices on the doubled slice bifurcates
// loudly at the strictly-increasing contract embedded in the
// doubled-full-set arm's slot-equality check. Sibling posture to
// clauses (97) + (105) + (106) + (107) — clause (97) pins the
// (`usize`, per-target) multiplicity corner; clause (105) pins
// the (`bool`, per-target) membership corner; clauses (106) +
// (107) pin the (`Option<usize>`, per-target, head) + (…, tail)
// endpoint-anchor corners; this clause pins the (`Vec<usize>`,
// per-target) every-position corner peer to them one return-shape
// axis over on the (per-target) arity axis. Together, clauses
// (97) + (105) + (106) + (107) + (108) close the (per-target ×
// return-shape) row at FIVE typed corners — usize, bool,
// Option<usize> head, Option<usize> tail, Vec<usize> — closing the
// per-target arity axis exhaustively at every return-shape column
// opened on the equivalence-partition surface. The `Vec<usize>`-
// return column carries an INTRINSIC slice-position ordering
// (ascending indices from `Iterator::enumerate`), so the
// (decl, lex) ordering axis on `T::ALL` collapses on this clause
// (the returned indices are slice indices, not variant decl-
// slots) and no `sorted_all_occurrences_of` peer is needed.
for target in T::ALL.iter().copied() {
let empty_positions = T::all_occurrences_of(target, &[]);
assert!(
empty_positions.is_empty(),
"{type_name}: T::all_occurrences_of({target_label:?}, &[]) == {empty_positions:?} != vec![] — the per-target every-position projection MUST report an empty vec on the empty slice because the position sweep finds no match on a zero-position slice; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream every-position consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let target_index = <T as ClosedSet>::index_of(target);
let full_set_positions = T::all_occurrences_of(target, T::ALL);
assert_eq!(
full_set_positions,
vec![target_index],
"{type_name}: T::all_occurrences_of({target_label:?}, T::ALL) drifted from vec![T::index_of({target_label:?})] — the per-target every-position projection MUST report `vec![T::index_of(target)]` at every target on the full set by clause (3)'s pairwise-distinctness invariant because every variant appears at exactly one position in T::ALL at slot `T::index_of(target)`, so the every-position vec collapses to the singleton at that slot; a drifted full-set position vec silently detaches the every-position projection from the (variant → decl-slot) injectivity clause (16) at the every-position projection surface, breaking every downstream every-position consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_positions = T::all_occurrences_of(target, &doubled_full_set);
assert_eq!(
doubled_positions,
vec![target_index, T::CARDINALITY + target_index],
"{type_name}: T::all_occurrences_of({target_label:?}, &doubled_full_set) drifted from vec![T::index_of({target_label:?}), T::CARDINALITY + T::index_of({target_label:?})] — the per-target every-position projection MUST report `vec![T::index_of(target), T::CARDINALITY + T::index_of(target)]` at every target on the doubled full set because every variant appears at EXACTLY TWO positions (T::index_of(target) and T::CARDINALITY + T::index_of(target)) and the ascending-order contract pins the head hit at the first-copy slot and the tail hit at the second-copy slot; a drifted doubled-position vec silently detaches the every-position projection from the endpoint-anchor pair on the doubled-slice fixpoint, and in particular catches an override that returns only the head hit (dropping the tail) or reorders the vec descending",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
full_set_positions.len(),
T::count_occurrences_of(target, T::ALL),
"{type_name}: T::all_occurrences_of({target_label:?}, T::ALL).len() drifted from T::count_occurrences_of({target_label:?}, T::ALL) — the per-target every-position projection's length no longer agrees with the per-target multiplicity primitive on the full-set fixpoint, so a downstream every-position consumer that binds `T::all_occurrences_of(_, _).len()` as its per-target multiplicity query surface would report the wrong count; the length-composition arm catches an override that detaches the vec's length from the per-target multiplicity on any slice",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
doubled_positions.first().copied(),
T::first_occurrence_of(target, &doubled_full_set),
"{type_name}: T::all_occurrences_of({target_label:?}, &doubled_full_set).first().copied() drifted from T::first_occurrence_of({target_label:?}, &doubled_full_set) — the per-target every-position projection's head element no longer agrees with the per-target head-position primitive on the doubled-full-set fixpoint, so a downstream every-position consumer that binds `T::all_occurrences_of(_, _).first().copied()` as its per-target head-position query surface would disagree with the pinned head-endpoint projection",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
doubled_positions.last().copied(),
T::last_occurrence_of(target, &doubled_full_set),
"{type_name}: T::all_occurrences_of({target_label:?}, &doubled_full_set).last().copied() drifted from T::last_occurrence_of({target_label:?}, &doubled_full_set) — the per-target every-position projection's tail element no longer agrees with the per-target tail-position primitive on the doubled-full-set fixpoint, so a downstream every-position consumer that binds `T::all_occurrences_of(_, _).last().copied()` as its per-target tail-position query surface would disagree with the pinned tail-endpoint projection",
target_label = <T as ClosedSet>::label(target),
);
}
// (109) — `T::occurrence_endpoints_of(target, items)` MUST agree
// with the per-target endpoint-pair projection on every (target,
// slice) pair AND MUST land on its three canonical fixpoints
// (`None` at every target on the empty slice, `Some((i, i))`
// where `i == T::index_of(target)` at every target on the full
// set, `Some((i, T::CARDINALITY + i))` at every target on the
// doubled full set) AND on THREE composition-equality arms
// against the endpoint-anchor pair on the doubled-slice fixpoint:
// (a) `Option::zip` composition against
// `T::first_occurrence_of(target, items).zip(T::last_occurrence_of(target, items))`,
// (b) head-projection against `T::first_occurrence_of` on the
// `map(|(f, _)| f)` arm, (c) tail-projection against
// `T::last_occurrence_of` on the `map(|(_, l)| l)` arm. The three
// fixpoints + three composition arms partition failure modes at
// the (discriminant × pair-value × slice-shape × composition-
// equality) corner simultaneously: an override that folds onto
// `None` unconditionally fires on the full-set arm (returns
// `None` at every target rather than `Some((i, i))`); an
// override that returns `Some((i, i))` regardless of slice arity
// fires on the doubled-full-set arm (returns the length-1
// singleton pair rather than the pinned length-2 spread
// `Some((i, T::CARDINALITY + i))`); an override that swaps the
// (first, last) pair on the doubled slice bifurcates loudly at
// either the head-composition arm (against
// `T::first_occurrence_of`) or the tail-composition arm (against
// `T::last_occurrence_of`); an override that returns descending
// pairs (first > second) on the doubled slice bifurcates loudly
// at the first ≤ second contract embedded in the doubled-full-
// set arm's exact-equality check. Sibling posture to clauses
// (97) + (105) + (106) + (107) + (108): closes the
// (`Option<(usize, usize)>`, per-target) endpoint-pair corner
// peer to them one return-shape axis over on the (per-target)
// arity axis. Together, clauses (97) + (105) + (106) + (107) +
// (108) + (109) close the (per-target × return-shape) row at SIX
// typed corners — usize, bool, Option<usize> head, Option<usize>
// tail, Vec<usize>, Option<(usize, usize)> — closing the per-
// target arity axis exhaustively at every return-shape column
// opened on the equivalence-partition surface. The
// `Option<(usize, usize)>`-return column carries an INTRINSIC
// (head, tail) direction ordering inherited from
// `Iterator::position` / `Iterator::rposition`, so the
// (decl, lex) ordering axis on `T::ALL` collapses on this
// clause (the returned pair carries slice indices, not variant
// decl-slots) and no `sorted_occurrence_endpoints_of` peer is
// needed. The default trait body threads
// `<Self as ClosedSet>::first_occurrence_of(target, items).zip(<Self as ClosedSet>::last_occurrence_of(target, items))`
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target endpoint-pair
// projection surface every downstream endpoint-pair consumer
// routes through.
for target in T::ALL.iter().copied() {
let empty_pair = T::occurrence_endpoints_of(target, &[]);
assert_eq!(
empty_pair, None,
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &[]) == {empty_pair:?} != None — the per-target endpoint-pair projection MUST report `None` on the empty slice because both endpoint-anchor primitives yield `None` on the zero-position slice and `Option::zip` collapses to `None` iff EITHER input is `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-target endpoint-pair consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let target_index = <T as ClosedSet>::index_of(target);
let full_set_pair = T::occurrence_endpoints_of(target, T::ALL);
assert_eq!(
full_set_pair,
Some((target_index, target_index)),
"{type_name}: T::occurrence_endpoints_of({target_label:?}, T::ALL) drifted from Some((T::index_of({target_label:?}), T::index_of({target_label:?}))) — clause (3)'s pairwise-distinctness invariant forces every variant to appear at exactly ONE position of the full-set slice, so both endpoint-anchor primitives yield `Some(T::index_of(target))` and `Option::zip` packages the pair with coincident components; a drifted full-set pair silently detaches the endpoint-pair projection from the (variant → decl-slot) injectivity clause (16), breaking every downstream endpoint-pair consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_pair = T::occurrence_endpoints_of(target, &doubled_full_set);
assert_eq!(
doubled_pair,
Some((target_index, T::CARDINALITY + target_index)),
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &doubled_full_set) drifted from Some((T::index_of({target_label:?}), T::CARDINALITY + T::index_of({target_label:?}))) — the doubled full set hits every variant at EXACTLY TWO positions (T::index_of(target) and T::CARDINALITY + T::index_of(target)) and the (head, tail) endpoint pair spans the two copies; a drifted doubled pair silently detaches the endpoint-pair projection from the endpoint-anchor pair on the doubled-slice fixpoint, and in particular catches an override that swaps the pair components or drops one of them",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_zip = T::first_occurrence_of(target, &doubled_full_set)
.zip(T::last_occurrence_of(target, &doubled_full_set));
assert_eq!(
doubled_pair, expected_via_zip,
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &doubled_full_set) drifted from T::first_occurrence_of({target_label:?}, &doubled_full_set).zip(T::last_occurrence_of({target_label:?}, &doubled_full_set)) — the endpoint-pair projection MUST equal the direct `Option::zip` of the two endpoint-anchor projections on every slice, so a downstream endpoint-pair consumer that binds `T::first_occurrence_of(_, _).zip(T::last_occurrence_of(_, _))` as its endpoint-pair query surface would disagree with the pinned pair projection",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
doubled_pair.map(|(f, _)| f),
T::first_occurrence_of(target, &doubled_full_set),
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &doubled_full_set).map(|(f,_)|f) drifted from T::first_occurrence_of({target_label:?}, &doubled_full_set) — the head-projection arm bifurcates: the pair's first component MUST equal the head-endpoint primitive on every slice, so a downstream head-position consumer that binds `T::occurrence_endpoints_of(_, _).map(|(f,_)|f)` would disagree with the pinned head-endpoint projection",
target_label = <T as ClosedSet>::label(target),
);
assert_eq!(
doubled_pair.map(|(_, l)| l),
T::last_occurrence_of(target, &doubled_full_set),
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &doubled_full_set).map(|(_,l)|l) drifted from T::last_occurrence_of({target_label:?}, &doubled_full_set) — the tail-projection arm bifurcates: the pair's second component MUST equal the tail-endpoint primitive on every slice, so a downstream tail-position consumer that binds `T::occurrence_endpoints_of(_, _).map(|(_,l)|l)` would disagree with the pinned tail-endpoint projection",
target_label = <T as ClosedSet>::label(target),
);
if let Some((f, l)) = doubled_pair {
assert!(
f <= l,
"{type_name}: T::occurrence_endpoints_of({target_label:?}, &doubled_full_set) returned Some(({f}, {l})) with f > l — the per-target endpoint-pair projection MUST satisfy `first <= second` on the `Some((first, second))` arm because `Iterator::position` always precedes `Iterator::rposition` on the same slice; a descending pair silently bifurcates the endpoint-direction contract every downstream endpoint-pair consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
}
}
// (110) — `T::occurrence_span_of(target, items)` MUST agree with
// the per-target scalar-difference reduction of the endpoint-pair
// corner on every (target, slice) pair AND MUST land on its three
// canonical fixpoints (`None` at every target on the empty slice,
// `Some(0)` at every target on the full set, `Some(T::CARDINALITY)`
// at every target on the doubled full set) AND on TWO composition-
// equality arms on the doubled-slice fixpoint: (a) `Option::map`
// composition against `T::occurrence_endpoints_of(target, items).map(|(f, l)| l - f)`,
// (b) endpoint-anchor composition against
// `T::first_occurrence_of(target, items).zip(T::last_occurrence_of(target, items)).map(|(f, l)| l - f)`.
// The three fixpoints + two composition arms partition failure
// modes at the (discriminant × scalar-value × slice-shape ×
// composition-equality) corner simultaneously: an override that
// folds onto `None` unconditionally fires on the full-set arm
// (returns `None` at every target rather than `Some(0)`); an
// override that folds the payload onto `0` unconditionally (e.g.
// `_.map(|_| 0)` — correct discriminant, drifted payload) fires
// on the doubled-full-set arm (returns `Some(0)` rather than the
// pinned `Some(T::CARDINALITY)`); an override that detaches the
// scalar-difference from the pair-endpoint slot-subtraction on
// any slice bifurcates loudly at either composition-equality arm.
// Sibling posture to clauses (97) + (105) + (106) + (107) + (108)
// + (109): closes the (`Option<usize>`, per-target, scalar-
// difference) corner peer to them one return-shape axis over on
// the (per-target) arity axis. Together, clauses (97) + (105) +
// (106) + (107) + (108) + (109) + (110) close the (per-target ×
// return-shape) row at SEVEN typed corners — usize, bool,
// Option<usize> head, Option<usize> tail, Vec<usize>,
// Option<(usize, usize)>, Option<usize> scalar-difference —
// closing the per-target arity axis exhaustively at every return-
// shape column opened on the equivalence-partition surface. The
// `Option<usize>`-return scalar-difference column carries an
// INTRINSIC (slot-subtraction) reduction inherited from
// `Option::map` on the pair-return corner underneath, so the
// (decl, lex) ordering axis on `T::ALL` collapses on this clause
// (the returned scalar carries a slot difference, not a variant
// decl-slot) and no `sorted_occurrence_span_of` peer is needed.
// The default trait body threads
// `<Self as ClosedSet>::occurrence_endpoints_of(target, items).map(|(f, l)| l - f)`
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target scalar-difference
// projection surface every downstream endpoint-span consumer
// routes through.
for target in T::ALL.iter().copied() {
let empty_span = T::occurrence_span_of(target, &[]);
assert_eq!(
empty_span, None,
"{type_name}: T::occurrence_span_of({target_label:?}, &[]) == {empty_span:?} != None — the per-target endpoint-span projection MUST report `None` on the empty slice because the endpoint-pair corner yields `None` on the zero-position slice and `Option::map` on `None` collapses to `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-target endpoint-span consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let full_set_span = T::occurrence_span_of(target, T::ALL);
assert_eq!(
full_set_span,
Some(0),
"{type_name}: T::occurrence_span_of({target_label:?}, T::ALL) drifted from Some(0) — clause (3)'s pairwise-distinctness invariant forces every variant to appear at exactly ONE position of the full-set slice, so the endpoint-pair corner yields `Some((i, i))` and the slot-subtraction reduction collapses to `Some(0)`; a drifted full-set span silently detaches the endpoint-span projection from the (variant → decl-slot) injectivity clause (16), breaking every downstream endpoint-span consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_span = T::occurrence_span_of(target, &doubled_full_set);
assert_eq!(
doubled_span,
Some(T::CARDINALITY),
"{type_name}: T::occurrence_span_of({target_label:?}, &doubled_full_set) drifted from Some(T::CARDINALITY) — the doubled full set hits every variant at EXACTLY TWO positions (T::index_of(target) and T::CARDINALITY + T::index_of(target)) and the slot-subtraction reduction of the (head, tail) endpoint pair collapses to Some((T::CARDINALITY + i) - i) == Some(T::CARDINALITY); the doubled-full-set arm is LOAD-BEARING — it is the ONLY canonical fixpoint arm that separates the scalar-difference reduction from a `_ => Some(0)` degenerate override (empty, full, matching-singleton fixpoints all yield `Some(0)` / `None` in both the correct and the drifted-payload override)",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_pair_map =
T::occurrence_endpoints_of(target, &doubled_full_set).map(|(f, l)| l - f);
assert_eq!(
doubled_span, expected_via_pair_map,
"{type_name}: T::occurrence_span_of({target_label:?}, &doubled_full_set) drifted from T::occurrence_endpoints_of({target_label:?}, &doubled_full_set).map(|(f, l)| l - f) — the endpoint-span projection MUST equal the direct `Option::map` of the pair-return corner through slot-subtraction on every slice, so a downstream endpoint-span consumer that binds `T::occurrence_endpoints_of(_, _).map(|(f, l)| l - f)` as its endpoint-span query surface would disagree with the pinned span projection",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_zip_map = T::first_occurrence_of(target, &doubled_full_set)
.zip(T::last_occurrence_of(target, &doubled_full_set))
.map(|(f, l)| l - f);
assert_eq!(
doubled_span, expected_via_zip_map,
"{type_name}: T::occurrence_span_of({target_label:?}, &doubled_full_set) drifted from T::first_occurrence_of({target_label:?}, &doubled_full_set).zip(T::last_occurrence_of({target_label:?}, &doubled_full_set)).map(|(f, l)| l - f) — the endpoint-span projection MUST equal the direct slot-subtraction of the `Option::zip` of the two endpoint-anchor projections on every slice, so a downstream endpoint-span consumer that binds the endpoint-anchor pair's slot-subtraction as its endpoint-span query surface would disagree with the pinned span projection",
target_label = <T as ClosedSet>::label(target),
);
}
// (111) — `T::is_unique_occurrence_of(target, items)` MUST agree
// with the strict-equality test of the per-target multiplicity
// primitive against `1` on every (target, slice) pair AND MUST
// land on its three canonical fixpoints (`false` at every target
// on the empty slice, `true` at every target on the full set,
// `false` at every target on the doubled full set) AND on TWO
// composition-equality arms on the doubled-slice fixpoint:
// (a) count-composition against `T::count_occurrences_of(target,
// items) == 1`, (b) presence-and-non-repeat composition against
// `T::occurs_in(target, items) && T::count_occurrences_of(target,
// items) < 2`. The three fixpoints + two composition arms
// partition failure modes at the (discriminant × slice-shape ×
// composition-equality) corner simultaneously: an override that
// folds onto `false` unconditionally fires on the full-set arm
// (returns `false` at every target rather than `true`); an
// override that folds onto `true` unconditionally fires on the
// empty-slice AND doubled-full-set arms; an override that folds
// onto the WEAKER (multiplicity `> 0`) membership predicate
// (correct on empty, matching-singleton, non-matching-singleton,
// full-set — bifurcates only at multiplicities `>= 2`) fires on
// the doubled-full-set arm (returns `true` rather than `false`
// at every target). Sibling posture to clauses (97) + (105-110):
// closes the (bool, per-target, `== 1`) corner peer to the (bool,
// per-target, `> 0`) corner [`Self::occurs_in`] one MULTIPLICITY-
// BAND axis over on the (per-target × bool × multiplicity-band)
// face. The default trait body threads
// `<Self as ClosedSet>::count_occurrences_of(target, items) == 1`
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target multiplicity-1
// predicate surface every downstream unique-occurrence consumer
// routes through.
for target in T::ALL.iter().copied() {
let empty_unique = T::is_unique_occurrence_of(target, &[]);
assert!(
!empty_unique,
"{type_name}: T::is_unique_occurrence_of({target_label:?}, &[]) == true != false — the per-target multiplicity-1 predicate MUST report `false` on the empty slice because the multiplicity primitive returns `0` and the strict-equality test against `1` fails; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-target unique-occurrence consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let full_set_unique = T::is_unique_occurrence_of(target, T::ALL);
assert!(
full_set_unique,
"{type_name}: T::is_unique_occurrence_of({target_label:?}, T::ALL) == false != true — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so the multiplicity primitive returns `1` and the strict-equality test against `1` holds; a drifted full-set unique-occurrence value silently detaches the multiplicity-1 predicate from the (variant → decl-slot) injectivity clause (16), breaking every downstream unique-occurrence consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_unique = T::is_unique_occurrence_of(target, &doubled_full_set);
assert!(
!doubled_unique,
"{type_name}: T::is_unique_occurrence_of({target_label:?}, &doubled_full_set) == true != false — the doubled full set hits every variant at EXACTLY TWO positions, so the multiplicity primitive returns `2` and the strict-equality test against `1` fails; the doubled-full-set arm is LOAD-BEARING — it is the ONLY canonical fixpoint arm that separates the strict-equality-against-1 test from the weaker (multiplicity `> 0`) membership predicate (empty, matching-singleton, non-matching-singleton, full-set all coincide)",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_count_eq_one = T::count_occurrences_of(target, &doubled_full_set) == 1;
assert_eq!(
doubled_unique, expected_via_count_eq_one,
"{type_name}: T::is_unique_occurrence_of({target_label:?}, &doubled_full_set) drifted from (T::count_occurrences_of({target_label:?}, &doubled_full_set) == 1) — the multiplicity-1 predicate MUST equal the strict-equality test of the per-target multiplicity primitive against `1` on every slice, so a downstream unique-occurrence consumer that binds `T::count_occurrences_of(_, _) == 1` as its uniqueness query surface would disagree with the pinned predicate",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_occurs_and_lt_two = T::occurs_in(target, &doubled_full_set)
&& T::count_occurrences_of(target, &doubled_full_set) < 2;
assert_eq!(
doubled_unique, expected_via_occurs_and_lt_two,
"{type_name}: T::is_unique_occurrence_of({target_label:?}, &doubled_full_set) drifted from (T::occurs_in({target_label:?}, &doubled_full_set) && T::count_occurrences_of({target_label:?}, &doubled_full_set) < 2) — the multiplicity-1 predicate MUST factor through the (multiplicity `> 0`) membership predicate conjoined with the (multiplicity `< 2`) non-repeat predicate, so a downstream unique-occurrence consumer that binds this presence-and-non-repeat composition would disagree with the pinned predicate",
target_label = <T as ClosedSet>::label(target),
);
}
// (112) — `T::is_repeated_occurrence_of(target, items)` MUST agree
// with the lower-bound test of the per-target multiplicity
// primitive against `2` on every (target, slice) pair AND MUST
// land on its three canonical fixpoints (`false` at every target
// on the empty slice, `false` at every target on the full set,
// `true` at every target on the doubled full set) AND on TWO
// composition-equality arms on the doubled-slice fixpoint:
// (a) count-composition against `T::count_occurrences_of(target,
// items) >= 2`, (b) presence-and-repeat composition against
// `T::occurs_in(target, items) && !T::is_unique_occurrence_of(target,
// items)`. The three fixpoints + two composition arms partition
// failure modes at the (discriminant × slice-shape × composition-
// equality) corner simultaneously: an override that folds onto
// `true` unconditionally fires on the empty-slice AND full-set
// arms (returns `true` at every target rather than `false`); an
// override that folds onto `false` unconditionally fires on the
// doubled-full-set arm; an override that folds onto the WEAKER
// (multiplicity `> 0`) membership predicate (bifurcates at
// multiplicity `== 1`) fires on the full-set arm (returns `true`
// rather than `false` at every target); an override that folds
// onto the (multiplicity `== 1`) uniqueness predicate (bifurcates
// at multiplicity `>= 2`) fires on the doubled-full-set arm
// (returns `false` rather than `true`). Sibling posture to clause
// (111): closes the third band on the (per-target × bool ×
// multiplicity-band) face at the (bool, per-target, `>= 2`) corner
// peer to (bool, per-target, `== 1`) and (bool, per-target, `> 0`)
// corners already opened; together clauses (97) + (111) + (112)
// partition the per-target multiplicity axis into three PAIRWISE
// DISJOINT typed predicates (`!occurs_in`, `is_unique_occurrence_of`,
// `is_repeated_occurrence_of`) that exhaustively cover the axis.
// The default trait body threads
// `<Self as ClosedSet>::count_occurrences_of(target, items) >= 2`
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target multiplicity-≥2
// predicate surface every downstream repetition consumer routes
// through.
for target in T::ALL.iter().copied() {
let empty_repeated = T::is_repeated_occurrence_of(target, &[]);
assert!(
!empty_repeated,
"{type_name}: T::is_repeated_occurrence_of({target_label:?}, &[]) == true != false — the per-target multiplicity-≥2 predicate MUST report `false` on the empty slice because the multiplicity primitive returns `0` and the lower-bound test against `2` fails; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream per-target repetition consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let full_set_repeated = T::is_repeated_occurrence_of(target, T::ALL);
assert!(
!full_set_repeated,
"{type_name}: T::is_repeated_occurrence_of({target_label:?}, T::ALL) == true != false — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so the multiplicity primitive returns `1` and the lower-bound test against `2` fails; a `true` full-set repetition value silently detaches the multiplicity-≥2 predicate from the (variant → decl-slot) injectivity clause (16), breaking every downstream repetition consumer",
target_label = <T as ClosedSet>::label(target),
);
let doubled_repeated = T::is_repeated_occurrence_of(target, &doubled_full_set);
assert!(
doubled_repeated,
"{type_name}: T::is_repeated_occurrence_of({target_label:?}, &doubled_full_set) == false != true — the doubled full set hits every variant at EXACTLY TWO positions, so the multiplicity primitive returns `2` and the lower-bound test against `2` holds; the doubled-full-set arm is LOAD-BEARING — it is the ONLY canonical fixpoint arm that separates the (multiplicity `>= 2`) band from the (multiplicity `== 0`) absence band (empty, matching-singleton, non-matching-singleton, full-set all coincide on `false`)",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_count_ge_two = T::count_occurrences_of(target, &doubled_full_set) >= 2;
assert_eq!(
doubled_repeated, expected_via_count_ge_two,
"{type_name}: T::is_repeated_occurrence_of({target_label:?}, &doubled_full_set) drifted from (T::count_occurrences_of({target_label:?}, &doubled_full_set) >= 2) — the multiplicity-≥2 predicate MUST equal the lower-bound test of the per-target multiplicity primitive against `2` on every slice, so a downstream repetition consumer that binds `T::count_occurrences_of(_, _) >= 2` as its repetition query surface would disagree with the pinned predicate",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_occurs_and_not_unique = T::occurs_in(target, &doubled_full_set)
&& !T::is_unique_occurrence_of(target, &doubled_full_set);
assert_eq!(
doubled_repeated, expected_via_occurs_and_not_unique,
"{type_name}: T::is_repeated_occurrence_of({target_label:?}, &doubled_full_set) drifted from (T::occurs_in({target_label:?}, &doubled_full_set) && !T::is_unique_occurrence_of({target_label:?}, &doubled_full_set)) — the multiplicity-≥2 predicate MUST factor through the (multiplicity `> 0`) membership predicate conjoined with the NEGATION of the (multiplicity `== 1`) uniqueness predicate; the trichotomy on the per-target multiplicity axis (`!occurs_in` XOR `is_unique_occurrence_of` XOR `is_repeated_occurrence_of`) demands this composition-equality identity",
target_label = <T as ClosedSet>::label(target),
);
}
// (113) — `T::is_repeating_any(items)` MUST agree with the lower-
// bound test of the modal-count aggregate against `2` on every
// slice AND MUST land on its three canonical fixpoints (`false` on
// the empty slice UNCONDITIONALLY, `false` on the full set
// UNCONDITIONALLY, `true` on the doubled full set gated on
// `T::CARDINALITY >= 1`) AND on THREE composition-equality arms on
// the doubled-slice fixpoint: (a) max-composition against
// `T::max_variant_count(items) >= 2`, (b) distinct-count composition
// against `T::count_distinct(items) < items.len()`, (c) De Morgan
// composition against `!T::is_pairwise_distinct(items)`. The three
// fixpoints + three composition arms partition failure modes at the
// (discriminant × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice AND full-set arms (returns `true` rather
// than `false`); an override that folds onto `false` unconditionally
// fires on the doubled-full-set arm at cardinality `>= 1` (returns
// `false` rather than `true`); an override that detaches from the
// modal-count composition on any slice bifurcates loudly at the
// max-composition arm; an override that detaches from the distinct-
// count arithmetic bifurcates at the distinct-count arm; an
// override that detaches from the pairwise-distinct De Morgan
// pairing bifurcates at the De Morgan arm. Sibling posture to
// clauses (111) + (112): those clauses close the (per-target × bool
// × multiplicity-band) face at BOTH the `== 1` and `>= 2` corners
// one arity axis under; this clause opens the SET-LEVEL EXISTENTIAL
// LIFT of the `>= 2` corner via `max_variant_count >= 2` — the
// set-level ARITY axis' `>= 2` slot peer to the per-target ARITY
// axis' `>= 2` slot one arity axis over. The (arity × mult-band)
// face now carries typed set-level bool predicates at BOTH the
// (mult `== 0`) corner ([`Self::is_missing_any`]) AND the (mult
// `>= 2`) corner (this predicate), with the (mult `<= 1`) corner
// covered by [`Self::is_pairwise_distinct`] as this predicate's
// De Morgan dual. The default trait body threads
// `<Self as ClosedSet>::max_variant_count(items) >= 2` verbatim and
// satisfies every fixpoint arm + every composition-equality arm for
// free; the assertion catches a future implementor whose override
// drifts the projection loudly rather than silently bifurcating the
// set-level any-repeat predicate surface every downstream any-
// repeat consumer routes through.
assert!(
!T::is_repeating_any(&[]),
"{type_name}: T::is_repeating_any(&[]) == true != false — the set-level any-repeat predicate MUST report `false` on the empty slice because the modal-count aggregate returns `0` and the lower-bound test against `2` fails; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream any-repeat consumer routes through",
);
assert!(
!T::is_repeating_any(T::ALL),
"{type_name}: T::is_repeating_any(T::ALL) == true != false — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so the modal-count aggregate returns `1` and the lower-bound test against `2` fails; a `true` full-set any-repeat value silently detaches the set-level any-repeat predicate from the (variant → decl-slot) injectivity clause (16), breaking every downstream any-repeat consumer",
);
if T::CARDINALITY >= 1 {
let doubled_repeating = T::is_repeating_any(&doubled_full_set);
assert!(
doubled_repeating,
"{type_name}: T::is_repeating_any(&doubled_full_set) == false != true on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so the modal-count aggregate returns `2` and the lower-bound test against `2` holds; the doubled-full-set arm at cardinality `>= 1` is LOAD-BEARING — it is the ONLY canonical fixpoint arm that separates the (mult `>= 2`) band from the (mult `<= 1`) pairwise-distinctness band (empty, full-set both coincide on `false`; only the doubled-full-set distinguishes them under any non-degenerate cardinality)",
cardinality = T::CARDINALITY,
);
let expected_via_max_ge_two = T::max_variant_count(&doubled_full_set) >= 2;
assert_eq!(
doubled_repeating, expected_via_max_ge_two,
"{type_name}: T::is_repeating_any(&doubled_full_set) drifted from (T::max_variant_count(&doubled_full_set) >= 2) — the set-level any-repeat predicate MUST equal the lower-bound test of the modal-count aggregate against `2` on every slice, so a downstream any-repeat consumer that binds `T::max_variant_count(_) >= 2` as its any-repeat query surface would disagree with the pinned predicate",
);
let expected_via_count_distinct_lt_len =
T::count_distinct(&doubled_full_set) < doubled_full_set.len();
assert_eq!(
doubled_repeating, expected_via_count_distinct_lt_len,
"{type_name}: T::is_repeating_any(&doubled_full_set) drifted from (T::count_distinct(&doubled_full_set) < doubled_full_set.len()) — the set-level any-repeat predicate MUST equal the (distinct-count strictly less than slice-length) arithmetic on every slice, so a downstream any-repeat consumer that binds this distinct-count composition would disagree with the pinned predicate; the identity captures that a slice is repetition-free iff its distinct-count reaches its slice-length upper bound, so the strictly-lesser case is EXACTLY the existential-repeat predicate",
);
let expected_via_not_pairwise_distinct = !T::is_pairwise_distinct(&doubled_full_set);
assert_eq!(
doubled_repeating, expected_via_not_pairwise_distinct,
"{type_name}: T::is_repeating_any(&doubled_full_set) drifted from !T::is_pairwise_distinct(&doubled_full_set) — the set-level any-repeat predicate MUST be the EXACT logical NEGATION of the pairwise-distinctness predicate on every slice, so a downstream any-repeat consumer that binds `!T::is_pairwise_distinct(_)` as its any-repeat query surface would disagree with the pinned predicate; the De Morgan pairing packages (`is_repeating_any`, `is_pairwise_distinct`) as the (mult `>= 2`, mult `<= 1`) dual pair peer to (`is_missing_any`, `is_covering`) on the (mult `== 0`, mult `>= 1`) split",
);
}
// (114) — `T::is_unique_any(items)` MUST agree with the existential
// quantification over `T::ALL` of the per-target multiplicity-`== 1`
// predicate on every slice AND MUST land on its three canonical
// fixpoints (`false` on the empty slice UNCONDITIONALLY, `true` on
// the full set gated on `T::CARDINALITY >= 1`, `false` on the
// doubled full set gated on `T::CARDINALITY >= 1`) AND on TWO
// composition-equality arms on the full-set fixpoint: (a)
// existential-lift against
// `T::ALL.iter().any(|&v| T::is_unique_occurrence_of(v, T::ALL))`,
// (b) histogram-arm against
// `T::variant_counts(T::ALL).contains(&1)`. The three
// fixpoints + two composition arms partition failure modes at the
// (discriminant × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice AND doubled-full-set arms (returns
// `true` rather than `false`); an override that folds onto `false`
// unconditionally fires on the full-set arm at cardinality `>= 1`
// (returns `false` rather than `true`); an override that detaches
// from the existential-lift composition on any slice bifurcates
// loudly at the existential-lift arm; an override that detaches
// from the histogram-arm bifurcates at the histogram-arm. Sibling
// posture to clause (113): that clause closes the set-level
// existential lift of the (per-target × bool × multiplicity-band
// `>= 2`) corner one MULTIPLICITY-BAND axis over; this clause
// closes the set-level existential lift of the (per-target × bool
// × multiplicity-band `== 1`) corner at the MIDDLE band of the
// trichotomy. The (arity × mult-band) face now carries typed set-
// level bool existential-lift predicates at ALL THREE multiplicity-
// band corners — `is_missing_any` (mult `== 0`), THIS PREDICATE
// (mult `== 1`), and `is_repeating_any` (mult `>= 2`) — closing
// the set-level existential-lift trichotomy exhaustively. The
// default trait body threads the existential quantifier verbatim
// and satisfies every fixpoint arm + every composition-equality arm
// for free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the set-level any-unique predicate surface every
// downstream any-unique consumer routes through.
assert!(
!T::is_unique_any(&[]),
"{type_name}: T::is_unique_any(&[]) == true != false — the set-level any-unique predicate MUST report `false` on the empty slice because every per-variant multiplicity is `0` and the per-target `== 1` test fails at every target; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream any-unique consumer routes through",
);
if T::CARDINALITY >= 1 {
let full_unique = T::is_unique_any(T::ALL);
assert!(
full_unique,
"{type_name}: T::is_unique_any(T::ALL) == false != true on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the existential disjunction fires at the first variant; a `false` full-set any-unique value silently detaches the set-level any-unique predicate from the (variant → decl-slot) injectivity clause (16), breaking every downstream any-unique consumer",
cardinality = T::CARDINALITY,
);
let expected_via_existential = T::ALL
.iter()
.copied()
.any(|v| T::is_unique_occurrence_of(v, T::ALL));
assert_eq!(
full_unique, expected_via_existential,
"{type_name}: T::is_unique_any(T::ALL) drifted from T::ALL.iter().any(|v| T::is_unique_occurrence_of(v, T::ALL)) — the set-level any-unique predicate MUST equal the existential quantification of the per-target multiplicity-`== 1` predicate over T::ALL on every slice, so a downstream any-unique consumer that binds this existential composition as its any-unique query surface would disagree with the pinned predicate",
);
let expected_via_histogram = T::variant_counts(T::ALL).contains(&1);
assert_eq!(
full_unique, expected_via_histogram,
"{type_name}: T::is_unique_any(T::ALL) drifted from T::variant_counts(T::ALL).contains(&1) — the set-level any-unique predicate MUST equal the containment test of the scalar `1` in the per-slot histogram vector on every slice, so a downstream any-unique consumer that binds this histogram-arm composition as its any-unique query surface would disagree with the pinned predicate",
);
let doubled_unique = T::is_unique_any(&doubled_full_set);
assert!(
!doubled_unique,
"{type_name}: T::is_unique_any(&doubled_full_set) == true != false on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the per-target `== 1` test fails at every target; the doubled-full-set arm at cardinality `>= 1` pins the projection as a STRICT `== 1` predicate rather than the weaker `>= 1` membership predicate — an override that folds onto `T::is_covering(items)` (which reports `true` on the doubled full set) would silently drift the projection past the strict-band boundary the trichotomy partitions",
cardinality = T::CARDINALITY,
);
}
// (115) — `T::count_unique_variants(items)` MUST agree with the
// filter-count reduction over `T::ALL` of the per-target
// multiplicity-`== 1` predicate on every slice AND MUST land on
// its three canonical fixpoints (`0` on the empty slice
// UNCONDITIONALLY, `T::CARDINALITY` on the full set
// UNCONDITIONALLY, `0` on the doubled full set UNCONDITIONALLY)
// AND on TWO composition-equality arms on the full-set fixpoint:
// (a) filter-count against
// `T::ALL.iter().filter(|&&v| T::is_unique_occurrence_of(v, T::ALL)).count()`,
// (b) histogram-arm against
// `T::variant_counts(T::ALL).iter().filter(|&&c| c == 1).count()`.
// The three fixpoints + two composition arms partition failure
// modes at the (scalar × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto
// `T::CARDINALITY` unconditionally fires on the empty-slice AND
// doubled-full-set arms (returns `T::CARDINALITY` rather than
// `0`); an override that folds onto `0` unconditionally fires on
// the full-set arm (returns `0` rather than `T::CARDINALITY`);
// an override that detaches from the filter-count composition
// on any slice bifurcates loudly at the filter-count arm; an
// override that detaches from the histogram-arm bifurcates at
// the histogram-arm. Sibling posture to clause (114) — clause
// (114) pins the (`bool`, set-level, mult `== 1`) any-unique
// predicate corner on the equivalence-partition surface; this
// clause pins the (`usize`, set-level, mult `== 1`)
// cardinality-count corner peer to it one return-shape axis over
// (bool-return → usize-return via cardinality sharpening).
// Sibling posture to clause (85) [count_missing on the mult
// `== 0` band] one MULTIPLICITY-BAND axis over: that clause
// pins the (`usize`, set-level, mult `== 0`) absent-count corner
// on the trichotomy face; this clause pins the (`usize`, set-
// level, mult `== 1`) unique-count corner at the middle band.
// The default trait body threads the filter-count reduction
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level unique-variant count
// surface every downstream unique-count consumer routes through.
assert_eq!(
T::count_unique_variants(&[]),
0,
"{type_name}: T::count_unique_variants(&[]) != 0 — the set-level unique-variant count MUST report `0` on the empty slice because every per-variant multiplicity is `0` and the per-target `== 1` test fails at every target; a non-`0` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-count consumer routes through",
);
let full_unique_count = T::count_unique_variants(T::ALL);
assert_eq!(
full_unique_count,
T::CARDINALITY,
"{type_name}: T::count_unique_variants(T::ALL) != T::CARDINALITY on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and every variant contributes to the count; a full-set value diverging from `T::CARDINALITY` silently detaches the set-level unique-variant count from the (variant → decl-slot) injectivity clause (16), breaking every downstream unique-count consumer",
cardinality = T::CARDINALITY,
);
let expected_via_filter = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_occurrence_of(v, T::ALL))
.count();
assert_eq!(
full_unique_count, expected_via_filter,
"{type_name}: T::count_unique_variants(T::ALL) drifted from T::ALL.iter().filter(|&v| T::is_unique_occurrence_of(v, T::ALL)).count() — the set-level unique-variant count MUST equal the filter-count reduction of the per-target multiplicity-`== 1` predicate over T::ALL on every slice, so a downstream unique-count consumer that binds this filter-count composition as its unique-cardinality query surface would disagree with the pinned count",
);
let expected_via_histogram = T::variant_counts(T::ALL)
.iter()
.filter(|&&c| c == 1)
.count();
assert_eq!(
full_unique_count, expected_via_histogram,
"{type_name}: T::count_unique_variants(T::ALL) drifted from T::variant_counts(T::ALL).iter().filter(|&&c| c == 1).count() — the set-level unique-variant count MUST equal the count of per-slot histogram bars equal to `1` on every slice, so a downstream unique-count consumer that binds this histogram-arm composition as its unique-cardinality query surface would disagree with the pinned count",
);
let doubled_unique_count = T::count_unique_variants(&doubled_full_set);
assert_eq!(
doubled_unique_count,
0,
"{type_name}: T::count_unique_variants(&doubled_full_set) != 0 on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the per-target `== 1` test fails at every target; the doubled-full-set arm pins the projection as a STRICT `== 1` count rather than the weaker `>= 1` presence count [`T::count_distinct`] which reports `T::CARDINALITY` on the doubled full set — a non-`0` doubled-full-set value silently drifts the projection past the strict-band boundary the trichotomy partitions",
cardinality = T::CARDINALITY,
);
// (116) — `T::count_repeating_variants(items)` MUST agree with
// the filter-count reduction over `T::ALL` of the per-target
// multiplicity-`>= 2` predicate on every slice AND MUST land on
// its three canonical fixpoints (`0` on the empty slice
// UNCONDITIONALLY, `0` on the full set UNCONDITIONALLY,
// `T::CARDINALITY` on the doubled full set UNCONDITIONALLY) AND
// on TWO composition-equality arms on the doubled-full-set
// fixpoint: (a) filter-count against
// `T::ALL.iter().filter(|&&v| T::is_repeated_occurrence_of(v, doubled)).count()`,
// (b) histogram-arm against
// `T::variant_counts(doubled).iter().filter(|&&c| c >= 2).count()`.
// AND the LOAD-BEARING trichotomy-partition identity
// `T::count_missing(s) + T::count_unique_variants(s) + T::count_repeating_variants(s) == T::CARDINALITY`
// is pinned at all three canonical slice fixpoints (empty, full,
// doubled-full) — the arithmetic witness that the three set-level
// cardinality-count corners of the (multiplicity-band) trichotomy
// PARTITION the `T::CARDINALITY`-many variants of the ambient
// closed set EXACTLY at every slice.
//
// The three fixpoints + two composition arms + one partition arm
// partition failure modes at the (scalar × slice-shape ×
// composition-equality × partition-arithmetic) corner
// simultaneously: an override that folds onto `T::CARDINALITY`
// unconditionally fires on the empty-slice AND full-set arms
// (returns `T::CARDINALITY` rather than `0`); an override that
// folds onto `0` unconditionally fires on the doubled-full-set
// arm at cardinality `>= 1` (returns `0` rather than
// `T::CARDINALITY`); an override that detaches from the filter-
// count composition on any slice bifurcates loudly at the
// filter-count arm; an override that detaches from the histogram-
// arm bifurcates at the histogram-arm; an override that inflates
// or deflates the count at ANY slice bifurcates the trichotomy-
// partition identity at the partition-arithmetic arm. Sibling
// posture to clause (115) — clause (115) pins the (`usize`, set-
// level, mult `== 1`) unique-cardinality corner at the middle
// band; this clause pins the (`usize`, set-level, mult `>= 2`)
// repeat-cardinality corner peer to it one MULTIPLICITY-BAND axis
// over, CLOSING the (set-level × usize × mult-band) trichotomy
// exhaustively at three typed cardinality-count primitives.
// Sibling posture to clause (85) [count_missing on the mult
// `== 0` band] one MULTIPLICITY-BAND axis over: that clause pins
// the (`usize`, set-level, mult `== 0`) absent-count corner AT
// the low band; this clause pins the (`usize`, set-level, mult
// `>= 2`) repeat-count corner AT the high band. Sibling posture
// to clause (113) [is_repeating_any on the (`bool`, set-level,
// mult `>= 2`) corner] one return-shape axis over: that clause
// pins the bool-existence corner at the strict-repeat band; this
// clause pins the usize-cardinality sharpening corner at the
// SAME band one return-shape axis over (bool-return → usize-
// return via cardinality sharpening). The default trait body
// threads the filter-count reduction verbatim and satisfies every
// fixpoint arm + every composition-equality arm + the partition-
// arithmetic arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level repeat-variant count
// surface every downstream repeat-count consumer routes through.
assert_eq!(
T::count_repeating_variants(&[]),
0,
"{type_name}: T::count_repeating_variants(&[]) != 0 — the set-level repeat-variant count MUST report `0` on the empty slice because every per-variant multiplicity is `0` and the per-target `>= 2` test fails at every target; a non-`0` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream repeat-count consumer routes through",
);
let full_repeating_count = T::count_repeating_variants(T::ALL);
assert_eq!(
full_repeating_count,
0,
"{type_name}: T::count_repeating_variants(T::ALL) != 0 on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the per-target `>= 2` test fails at every target; a non-`0` full-set value silently detaches the set-level repeat-variant count from the (variant → decl-slot) injectivity clause (16), breaking every downstream repeat-count consumer",
cardinality = T::CARDINALITY,
);
let doubled_repeating_count = T::count_repeating_variants(&doubled_full_set);
assert_eq!(
doubled_repeating_count,
T::CARDINALITY,
"{type_name}: T::count_repeating_variants(&doubled_full_set) != T::CARDINALITY on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and every variant contributes to the count; a doubled-full-set value diverging from `T::CARDINALITY` silently drifts the projection past the strict-band boundary the trichotomy partitions — the doubled-full-set arm pins the projection as a STRICT `>= 2` count rather than the weaker `>= 1` presence count [`T::count_distinct`] which reports `T::CARDINALITY` on BOTH the full set and the doubled full set",
cardinality = T::CARDINALITY,
);
let expected_repeat_via_filter = T::ALL
.iter()
.copied()
.filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set))
.count();
assert_eq!(
doubled_repeating_count, expected_repeat_via_filter,
"{type_name}: T::count_repeating_variants(&doubled_full_set) drifted from T::ALL.iter().filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set)).count() — the set-level repeat-variant count MUST equal the filter-count reduction of the per-target multiplicity-`>= 2` predicate over T::ALL on every slice, so a downstream repeat-count consumer that binds this filter-count composition as its repeat-cardinality query surface would disagree with the pinned count",
);
let expected_repeat_via_histogram = T::variant_counts(&doubled_full_set)
.iter()
.filter(|&&c| c >= 2)
.count();
assert_eq!(
doubled_repeating_count, expected_repeat_via_histogram,
"{type_name}: T::count_repeating_variants(&doubled_full_set) drifted from T::variant_counts(&doubled_full_set).iter().filter(|&&c| c >= 2).count() — the set-level repeat-variant count MUST equal the count of per-slot histogram bars greater than or equal to `2` on every slice, so a downstream repeat-count consumer that binds this histogram-arm composition as its repeat-cardinality query surface would disagree with the pinned count",
);
// LOAD-BEARING trichotomy-partition identity: pin it at all three
// canonical slice fixpoints (empty, full, doubled-full). The
// identity is the arithmetic witness that the three set-level
// cardinality-count corners of the (multiplicity-band) trichotomy
// PARTITION the `T::CARDINALITY`-many variants of the ambient
// closed set EXACTLY at every slice. Any override on any of the
// three corners that inflates or deflates the count at any of
// these three canonical slices bifurcates the identity loudly.
let empty_partition =
T::count_missing(&[]) + T::count_unique_variants(&[]) + T::count_repeating_variants(&[]);
assert_eq!(
empty_partition,
T::CARDINALITY,
"{type_name}: T::count_missing(&[]) + T::count_unique_variants(&[]) + T::count_repeating_variants(&[]) = {empty_partition} != T::CARDINALITY = {cardinality} — the LOAD-BEARING trichotomy-partition identity was violated on the empty slice; the three set-level cardinality-count corners of the (multiplicity-band) trichotomy MUST partition the `T::CARDINALITY`-many variants of the ambient closed set EXACTLY at every slice",
cardinality = T::CARDINALITY,
);
let full_partition = T::count_missing(T::ALL)
+ T::count_unique_variants(T::ALL)
+ T::count_repeating_variants(T::ALL);
assert_eq!(
full_partition,
T::CARDINALITY,
"{type_name}: T::count_missing(T::ALL) + T::count_unique_variants(T::ALL) + T::count_repeating_variants(T::ALL) = {full_partition} != T::CARDINALITY = {cardinality} — the LOAD-BEARING trichotomy-partition identity was violated on the full set; the three set-level cardinality-count corners of the (multiplicity-band) trichotomy MUST partition the `T::CARDINALITY`-many variants of the ambient closed set EXACTLY at every slice",
cardinality = T::CARDINALITY,
);
let doubled_partition = T::count_missing(&doubled_full_set)
+ T::count_unique_variants(&doubled_full_set)
+ T::count_repeating_variants(&doubled_full_set);
assert_eq!(
doubled_partition,
T::CARDINALITY,
"{type_name}: T::count_missing(&doubled_full_set) + T::count_unique_variants(&doubled_full_set) + T::count_repeating_variants(&doubled_full_set) = {doubled_partition} != T::CARDINALITY = {cardinality} — the LOAD-BEARING trichotomy-partition identity was violated on the doubled full set; the three set-level cardinality-count corners of the (multiplicity-band) trichotomy MUST partition the `T::CARDINALITY`-many variants of the ambient closed set EXACTLY at every slice",
cardinality = T::CARDINALITY,
);
// (117) — `T::repeating_variants(items)` MUST agree with the
// filter of the per-target multiplicity-`>= 2` predicate over
// `T::ALL` on every slice AND MUST land on its three canonical
// fixpoints (`[]` on the empty slice UNCONDITIONALLY, `[]` on
// the full set UNCONDITIONALLY, `T::ALL.to_vec()` on the doubled
// full set UNCONDITIONALLY) AND on the length-vs-count identity
// `T::repeating_variants(items).len() ==
// T::count_repeating_variants(items)` pinned at both the full-
// set and doubled-full-set fixpoints.
//
// The three fixpoints + composition-equality arm + length-vs-
// count arm partition failure modes at the (Vec-return × slice-
// shape × composition-equality × cross-projection) corner
// simultaneously: an override that folds onto `T::ALL.to_vec()`
// unconditionally fires on the empty-slice AND full-set arms
// (returns the full ambient set rather than `[]`); an override
// that folds onto `[]` unconditionally fires on the doubled-
// full-set arm at cardinality `>= 1` (returns `[]` rather than
// `T::ALL.to_vec()`); an override that detaches from the
// filter-composition on any slice bifurcates loudly at the
// filter-composition arm; an override that inflates or deflates
// the returned `Vec`'s length at ANY slice bifurcates the
// length-vs-count identity against
// [`Self::count_repeating_variants`] (already pinned by clause
// (116)).
//
// Sibling posture to clause (116) — clause (116) pins the
// (`usize`, set-level, multiplicity-band `>= 2`) repeat-
// cardinality corner; this clause pins the (`Vec<Self>`, set-
// level, multiplicity-band `>= 2`) repeat-WITNESS corner peer
// to it one RETURN-SHAPE axis over, CLOSING the (bool, usize,
// `Vec<Self>`) return-shape column at the strict-repeat band
// exhaustively at three typed peer projections
// ([`Self::is_repeating_any`],
// [`Self::count_repeating_variants`], THIS). Sibling posture
// to clause (77) — that clause pins the (`Vec<Self>`, set-
// level, multiplicity-band `== 0`) miss-witness corner AT the
// low band; this clause pins the (`Vec<Self>`, set-level,
// multiplicity-band `>= 2`) repeat-witness corner AT the high
// band peer to it one MULTIPLICITY-BAND axis over. The default
// trait body threads the filter over the substrate's per-
// target strict-repeat primitive
// ([`Self::is_repeated_occurrence_of`]) verbatim and satisfies
// every fixpoint arm + composition-equality arm + length-vs-
// count arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly
// rather than silently bifurcating the set-level strict-
// repeat-witness surface every downstream duplication-witness
// consumer routes through.
assert!(
T::repeating_variants(&[]).is_empty(),
"{type_name}: T::repeating_variants(&[]) != [] — the set-level strict-repeat witness MUST report `[]` on the empty slice because every per-variant multiplicity is `0` and the per-target `>= 2` test fails at every target; a non-`[]` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream strict-repeat-witness consumer routes through",
);
let full_repeating = T::repeating_variants(T::ALL);
assert!(
full_repeating.is_empty(),
"{type_name}: T::repeating_variants(T::ALL) != [] on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the per-target `>= 2` test fails at every target; a non-`[]` full-set value silently detaches the set-level strict-repeat witness from the (variant → decl-slot) injectivity clause (16), breaking every downstream duplication-witness consumer",
cardinality = T::CARDINALITY,
);
let doubled_repeating = T::repeating_variants(&doubled_full_set);
assert_eq!(
doubled_repeating,
T::ALL.to_vec(),
"{type_name}: T::repeating_variants(&doubled_full_set) != T::ALL.to_vec() on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the projection MUST return each variant of T::ALL exactly once in declaration order; a doubled-full-set value diverging from T::ALL.to_vec() silently drifts the projection past the strict-band boundary the trichotomy partitions — the doubled-full-set arm pins the projection as a STRICT `>= 2` witness rather than the weaker `>= 1` presence witness [`T::present_variants`] which reports T::ALL.to_vec() on BOTH the full set and the doubled full set",
cardinality = T::CARDINALITY,
);
let expected_via_filter: Vec<T> = T::ALL
.iter()
.copied()
.filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set))
.collect();
assert_eq!(
doubled_repeating, expected_via_filter,
"{type_name}: T::repeating_variants(&doubled_full_set) drifted from T::ALL.iter().filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set)).collect() — the set-level strict-repeat witness MUST equal the filter of the per-target multiplicity-`>= 2` predicate over T::ALL on every slice, so a downstream strict-repeat-witness consumer that binds this filter-composition as its duplication-witness query surface would disagree with the pinned projection",
);
assert_eq!(
full_repeating.len(),
T::count_repeating_variants(T::ALL),
"{type_name}: T::repeating_variants(T::ALL).len() drifted from T::count_repeating_variants(T::ALL) — the (Vec-return, usize-return) strict-repeat-band cardinality identity was violated on the full set; the two peer projections MUST agree on their multiset-cardinality projection at every slice",
);
assert_eq!(
doubled_repeating.len(),
T::count_repeating_variants(&doubled_full_set),
"{type_name}: T::repeating_variants(&doubled_full_set).len() drifted from T::count_repeating_variants(&doubled_full_set) — the (Vec-return, usize-return) strict-repeat-band cardinality identity was violated on the doubled full set; the two peer projections MUST agree on their multiset-cardinality projection at every slice",
);
// (118) — `T::sorted_repeating_variants(items)` MUST agree with
// the filter of the per-target multiplicity-`>= 2` predicate
// over `T::sorted_variants()` on every slice AND MUST land on
// its three canonical fixpoints (`[]` on the empty slice
// UNCONDITIONALLY, `[]` on the full set UNCONDITIONALLY,
// `T::sorted_variants()` on the doubled full set
// UNCONDITIONALLY) AND on the length-vs-count identity
// `T::sorted_repeating_variants(items).len() ==
// T::count_repeating_variants(items)` pinned at both the full-
// set and doubled-full-set fixpoints AND on the cross-arm
// permutation identity against the declaration-arm sibling
// [`Self::repeating_variants`] at the doubled-full-set fixpoint.
//
// The three fixpoints + composition-equality arm + length-vs-
// count arm + cross-arm permutation arm partition failure modes
// at the (Vec-return × slice-shape × composition-equality ×
// cross-projection × cross-arm) corner simultaneously: an
// override that folds onto `T::sorted_variants()` unconditionally
// fires on the empty-slice AND full-set arms (returns the full
// ambient set rather than `[]`); an override that folds onto
// `[]` unconditionally fires on the doubled-full-set arm at
// cardinality `>= 1` (returns `[]` rather than
// `T::sorted_variants()`); an override that detaches from the
// sorted-then-filter composition on any slice bifurcates loudly
// at the filter-composition arm; an override that inflates or
// deflates the returned `Vec`'s length at ANY slice bifurcates
// the length-vs-count identity against
// [`Self::count_repeating_variants`] (already pinned by clause
// (116)); an override that returns the correct multiset but
// silently reverts to declaration order (e.g. `T::ALL.iter()
// .filter(…).collect()` instead of `T::sorted_variants()
// .into_iter().filter(…).collect()`) bifurcates loudly against
// [`Self::repeating_variants`] byte-for-byte on any implementor
// whose declaration order differs from lex order.
//
// Sibling posture to clause (117) — clause (117) pins the
// (`Vec<Self>`, set-level, multiplicity-band `>= 2`,
// declaration-order) strict-repeat-WITNESS corner; this clause
// pins the (`Vec<Self>`, set-level, multiplicity-band `>= 2`,
// lex-order) strict-repeat-witness corner peer to it one
// ORDERING axis over, CLOSING the (partition-arm × ordering)
// 3×2 = 6-corner `Vec<Self>`-return face on the equivalence-
// partition surface at its SIXTH (strict-repeat, lex) corner
// exhaustively — peer to
// [`Self::sorted_present_variants`] (present × lex) and
// [`Self::sorted_missing_variants`] (absent × lex) one PARTITION-
// ARM axis over on the same lex column. The default trait body
// threads the filter over the substrate's
// [`Self::sorted_variants`] canonical lex-order listing surface
// composed with the substrate's per-target strict-repeat
// primitive [`Self::is_repeated_occurrence_of`] verbatim and
// satisfies every fixpoint arm + composition-equality arm +
// length-vs-count arm + cross-arm permutation arm for free;
// the assertion catches a future implementor whose override
// drifts the projection loudly rather than silently bifurcating
// the set-level lex-order strict-repeat-witness surface every
// downstream lex-order duplication-witness consumer routes
// through.
assert!(
T::sorted_repeating_variants(&[]).is_empty(),
"{type_name}: T::sorted_repeating_variants(&[]) != [] — the set-level lex-order strict-repeat witness MUST report `[]` on the empty slice because every per-variant multiplicity is `0` and the per-target `>= 2` test fails at every target; a non-`[]` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order strict-repeat-witness consumer routes through",
);
let full_sorted_repeating = T::sorted_repeating_variants(T::ALL);
assert!(
full_sorted_repeating.is_empty(),
"{type_name}: T::sorted_repeating_variants(T::ALL) != [] on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the per-target `>= 2` test fails at every target; a non-`[]` full-set value silently detaches the set-level lex-order strict-repeat witness from the (variant → decl-slot) injectivity clause (16), breaking every downstream lex-order duplication-witness consumer",
cardinality = T::CARDINALITY,
);
let doubled_sorted_repeating = T::sorted_repeating_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_repeating,
T::sorted_variants(),
"{type_name}: T::sorted_repeating_variants(&doubled_full_set) != T::sorted_variants() on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the projection MUST return each variant of T::sorted_variants() exactly once in lex order; a doubled-full-set value diverging from T::sorted_variants() silently drifts the projection past the strict-band boundary the trichotomy partitions — the doubled-full-set arm pins the projection as a STRICT `>= 2` witness rather than the weaker `>= 1` presence witness [`T::sorted_present_variants`] which reports T::sorted_variants() on BOTH the full set and the doubled full set",
cardinality = T::CARDINALITY,
);
let expected_sorted_via_filter: Vec<T> = T::sorted_variants()
.into_iter()
.filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set))
.collect();
assert_eq!(
doubled_sorted_repeating, expected_sorted_via_filter,
"{type_name}: T::sorted_repeating_variants(&doubled_full_set) drifted from T::sorted_variants().into_iter().filter(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set)).collect() — the set-level lex-order strict-repeat witness MUST equal the filter of the per-target multiplicity-`>= 2` predicate over T::sorted_variants() on every slice, so a downstream lex-order strict-repeat-witness consumer that binds this filter-composition as its duplication-witness query surface would disagree with the pinned projection",
);
assert_eq!(
full_sorted_repeating.len(),
T::count_repeating_variants(T::ALL),
"{type_name}: T::sorted_repeating_variants(T::ALL).len() drifted from T::count_repeating_variants(T::ALL) — the (Vec-return, usize-return) strict-repeat-band cardinality identity was violated on the full set on the lex arm; the two peer projections MUST agree on their multiset-cardinality projection at every slice regardless of ordering",
);
assert_eq!(
doubled_sorted_repeating.len(),
T::count_repeating_variants(&doubled_full_set),
"{type_name}: T::sorted_repeating_variants(&doubled_full_set).len() drifted from T::count_repeating_variants(&doubled_full_set) — the (Vec-return, usize-return) strict-repeat-band cardinality identity was violated on the doubled full set on the lex arm; the two peer projections MUST agree on their multiset-cardinality projection at every slice regardless of ordering",
);
let mut doubled_decl_sorted = doubled_repeating.clone();
let mut doubled_lex_sorted = doubled_sorted_repeating.clone();
doubled_decl_sorted.sort_unstable_by_key(|v| T::index_of(*v));
doubled_lex_sorted.sort_unstable_by_key(|v| T::index_of(*v));
assert_eq!(
doubled_decl_sorted, doubled_lex_sorted,
"{type_name}: T::sorted_repeating_variants(&doubled_full_set) is not a permutation of T::repeating_variants(&doubled_full_set) — the (declaration, lex) arms MUST filter the SAME strict-repeat set from the equivalence-partition surface's `Vec<Self>`-return column, so a downstream consumer that treats one arm's multiset as an authoritative substitute for the other's would disagree with the pinned projection",
);
// (119) — `T::unique_variants(items)` MUST agree with the filter
// of the per-target multiplicity-`== 1` predicate over `T::ALL`
// on every slice AND MUST land on its three canonical fixpoints
// (`[]` on the empty slice UNCONDITIONALLY, `T::ALL.to_vec()` on
// the full set UNCONDITIONALLY, `[]` on the doubled full set
// UNCONDITIONALLY) AND on the length-vs-count identity
// `T::unique_variants(items).len() ==
// T::count_unique_variants(items)` pinned at BOTH the full-set
// and doubled-full-set fixpoints.
//
// The three fixpoints + composition-equality arm + length-vs-
// count arm partition failure modes at the (Vec-return × slice-
// shape × composition-equality × cross-projection) corner
// simultaneously: an override that folds onto `T::ALL.to_vec()`
// unconditionally fires on the empty-slice AND doubled-full-set
// arms (returns the full ambient set rather than `[]`); an
// override that folds onto `[]` unconditionally fires on the
// full-set arm at cardinality `>= 1` (returns `[]` rather than
// `T::ALL.to_vec()`); an override that detaches from the filter-
// composition on any slice bifurcates loudly at the filter-
// composition arm; an override that inflates or deflates the
// returned `Vec`'s length at ANY slice bifurcates the length-vs-
// count identity against [`Self::count_unique_variants`] (already
// pinned by clause (114)).
//
// Sibling posture to clause (117) — clause (117) pins the
// (`Vec<Self>`, set-level, multiplicity-band `>= 2`) repeat-
// witness corner; this clause pins the (`Vec<Self>`, set-level,
// multiplicity-band `== 1`) unique-witness corner peer to it one
// MULTIPLICITY-BAND axis over, opening the (mult `== 1`) column
// on the Vec-return row of the equivalence-partition surface at
// its canonical filter-composition-then-fixpoint-witness shape.
// Sibling posture to clause (77) — that clause pins the
// (`Vec<Self>`, set-level, mult `== 0`) miss-witness corner at
// the low band; this clause pins the (`Vec<Self>`, set-level,
// mult `== 1`) unique-witness corner at the middle band peer to
// it one MULTIPLICITY-BAND axis over. The default trait body
// threads the filter over the substrate's per-target strict-
// uniqueness primitive ([`Self::is_unique_occurrence_of`])
// verbatim and satisfies every fixpoint arm + composition-
// equality arm + length-vs-count arm for free; the assertion
// catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-
// level strict-uniqueness-witness surface every downstream
// uniqueness-witness consumer routes through.
assert!(
T::unique_variants(&[]).is_empty(),
"{type_name}: T::unique_variants(&[]) != [] — the set-level strict-uniqueness witness MUST report `[]` on the empty slice because every per-variant multiplicity is `0` and the per-target `== 1` test fails at every target; a non-`[]` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream strict-uniqueness-witness consumer routes through",
);
let full_unique = T::unique_variants(T::ALL);
assert_eq!(
full_unique,
T::ALL.to_vec(),
"{type_name}: T::unique_variants(T::ALL) != T::ALL.to_vec() on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the per-target `== 1` test succeeds at every target; a full-set value diverging from T::ALL.to_vec() silently detaches the set-level strict-uniqueness witness from the (variant → decl-slot) injectivity clause (16), breaking every downstream uniqueness-witness consumer — the full-set arm is LOAD-BEARING as the boundary that separates the (mult `== 1`) band from the (mult `== 0`) absence band (empty-slice arm) AND from the (mult `>= 2`) repetition band (doubled-full-set arm)",
cardinality = T::CARDINALITY,
);
let doubled_unique = T::unique_variants(&doubled_full_set);
assert!(
doubled_unique.is_empty(),
"{type_name}: T::unique_variants(&doubled_full_set) != [] on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the per-target `== 1` test fails at every target; a non-`[]` doubled-full-set value silently drifts the projection past the strict-uniqueness boundary the trichotomy partitions — the doubled-full-set arm pins the projection as a STRICT `== 1` witness rather than the weaker `>= 1` presence witness [`T::present_variants`] which reports T::ALL.to_vec() on BOTH the full set and the doubled full set",
cardinality = T::CARDINALITY,
);
let expected_unique_via_filter: Vec<T> = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_occurrence_of(v, T::ALL))
.collect();
assert_eq!(
full_unique, expected_unique_via_filter,
"{type_name}: T::unique_variants(T::ALL) drifted from T::ALL.iter().filter(|&v| T::is_unique_occurrence_of(v, T::ALL)).collect() — the set-level strict-uniqueness witness MUST equal the filter of the per-target multiplicity-`== 1` predicate over T::ALL on every slice, so a downstream strict-uniqueness-witness consumer that binds this filter-composition as its uniqueness-witness query surface would disagree with the pinned projection",
);
assert_eq!(
full_unique.len(),
T::count_unique_variants(T::ALL),
"{type_name}: T::unique_variants(T::ALL).len() drifted from T::count_unique_variants(T::ALL) — the (Vec-return, usize-return) strict-uniqueness-band cardinality identity was violated on the full set; the two peer projections MUST agree on their multiset-cardinality projection at every slice",
);
assert_eq!(
doubled_unique.len(),
T::count_unique_variants(&doubled_full_set),
"{type_name}: T::unique_variants(&doubled_full_set).len() drifted from T::count_unique_variants(&doubled_full_set) — the (Vec-return, usize-return) strict-uniqueness-band cardinality identity was violated on the doubled full set; the two peer projections MUST agree on their multiset-cardinality projection at every slice",
);
// Trichotomy partition arm — `T::missing_variants.len() +
// T::unique_variants.len() + T::repeating_variants.len() ==
// T::CARDINALITY` on the full-set fixpoint. Pins the Vec-return
// lift of the (`count_missing + count_unique_variants +
// count_repeating_variants == T::CARDINALITY`) trichotomy
// partition identity on the peer usize-return column at the load-
// bearing full-set fixpoint arm.
assert_eq!(
T::missing_variants(T::ALL).len()
+ full_unique.len()
+ T::repeating_variants(T::ALL).len(),
T::CARDINALITY,
"{type_name}: T::missing_variants(T::ALL).len() + T::unique_variants(T::ALL).len() + T::repeating_variants(T::ALL).len() != T::CARDINALITY on a cardinality-{cardinality} closed set — the three Vec-return witnesses on the multiplicity-band trichotomy MUST partition T::ALL exactly, mirroring the (`count_missing + count_unique_variants + count_repeating_variants == T::CARDINALITY`) trichotomy partition identity on the peer usize-return column",
cardinality = T::CARDINALITY,
);
// (120) — `T::sorted_unique_variants(items)` MUST agree with the
// filter of the per-target multiplicity-`== 1` predicate over
// `T::sorted_variants()` on every slice AND MUST land on its
// three canonical fixpoints (`[]` on the empty slice
// UNCONDITIONALLY, `T::sorted_variants()` on the full set
// UNCONDITIONALLY, `[]` on the doubled full set UNCONDITIONALLY)
// AND on the length-vs-count identity
// `T::sorted_unique_variants(items).len() ==
// T::count_unique_variants(items)` pinned at BOTH the full-set
// and doubled-full-set fixpoints AND on the cross-arm
// permutation identity against the declaration-arm sibling
// [`Self::unique_variants`] at the full-set fixpoint.
//
// Sibling posture to clause (118) — clause (118) pins the
// (`Vec<Self>`, set-level, multiplicity-band `>= 2`, lex-order)
// strict-repeat-witness corner; this clause pins the (`Vec<Self>`,
// set-level, multiplicity-band `== 1`, lex-order) strict-
// uniqueness-witness corner peer to it one MULTIPLICITY-BAND
// axis over, EXHAUSTIVELY closing the (`Vec<Self>`-return ×
// (mult `== 0`, mult `== 1`, mult `>= 2`) × (declaration, lex))
// 3×2 = 6-corner face at all six corners across the three-band
// trichotomy on both ordering arms — peer to
// [`Self::sorted_missing_variants`] (mult `== 0` × lex),
// [`Self::sorted_repeating_variants`] (mult `>= 2` × lex) one
// MULTIPLICITY-BAND axis over on the same lex column. The
// default trait body threads the filter over the substrate's
// [`Self::sorted_variants`] canonical lex-order listing surface
// composed with the substrate's per-target strict-uniqueness
// primitive [`Self::is_unique_occurrence_of`] verbatim and
// satisfies every fixpoint arm + composition-equality arm +
// length-vs-count arm + cross-arm permutation arm for free.
assert!(
T::sorted_unique_variants(&[]).is_empty(),
"{type_name}: T::sorted_unique_variants(&[]) != [] — the set-level lex-order strict-uniqueness witness MUST report `[]` on the empty slice because every per-variant multiplicity is `0` and the per-target `== 1` test fails at every target; a non-`[]` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order strict-uniqueness-witness consumer routes through",
);
let full_sorted_unique = T::sorted_unique_variants(T::ALL);
assert_eq!(
full_sorted_unique,
T::sorted_variants(),
"{type_name}: T::sorted_unique_variants(T::ALL) != T::sorted_variants() on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so every per-target multiplicity is `1` and the projection MUST return each variant of T::sorted_variants() exactly once in lex order; a full-set value diverging from T::sorted_variants() silently detaches the set-level lex-order strict-uniqueness witness from the (variant → decl-slot) injectivity clause (16), breaking every downstream lex-order uniqueness-witness consumer",
cardinality = T::CARDINALITY,
);
let doubled_sorted_unique = T::sorted_unique_variants(&doubled_full_set);
assert!(
doubled_sorted_unique.is_empty(),
"{type_name}: T::sorted_unique_variants(&doubled_full_set) != [] on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so every per-target multiplicity is `2` and the per-target `== 1` test fails at every target; a non-`[]` doubled-full-set value silently drifts the projection past the strict-uniqueness boundary the trichotomy partitions",
cardinality = T::CARDINALITY,
);
let expected_sorted_unique_via_filter: Vec<T> = T::sorted_variants()
.into_iter()
.filter(|&v| T::is_unique_occurrence_of(v, T::ALL))
.collect();
assert_eq!(
full_sorted_unique, expected_sorted_unique_via_filter,
"{type_name}: T::sorted_unique_variants(T::ALL) drifted from T::sorted_variants().into_iter().filter(|&v| T::is_unique_occurrence_of(v, T::ALL)).collect() — the set-level lex-order strict-uniqueness witness MUST equal the filter of the per-target multiplicity-`== 1` predicate over T::sorted_variants() on every slice, so a downstream lex-order strict-uniqueness-witness consumer that binds this filter-composition as its uniqueness-witness query surface would disagree with the pinned projection",
);
assert_eq!(
full_sorted_unique.len(),
T::count_unique_variants(T::ALL),
"{type_name}: T::sorted_unique_variants(T::ALL).len() drifted from T::count_unique_variants(T::ALL) — the (Vec-return, usize-return) strict-uniqueness-band cardinality identity was violated on the full set on the lex arm; the two peer projections MUST agree on their multiset-cardinality projection at every slice regardless of ordering",
);
assert_eq!(
doubled_sorted_unique.len(),
T::count_unique_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_variants(&doubled_full_set).len() drifted from T::count_unique_variants(&doubled_full_set) — the (Vec-return, usize-return) strict-uniqueness-band cardinality identity was violated on the doubled full set on the lex arm; the two peer projections MUST agree on their multiset-cardinality projection at every slice regardless of ordering",
);
let mut full_decl_unique_sorted = full_unique.clone();
let mut full_lex_unique_sorted = full_sorted_unique.clone();
full_decl_unique_sorted.sort_unstable_by_key(|v| T::index_of(*v));
full_lex_unique_sorted.sort_unstable_by_key(|v| T::index_of(*v));
assert_eq!(
full_decl_unique_sorted, full_lex_unique_sorted,
"{type_name}: T::sorted_unique_variants(T::ALL) is not a permutation of T::unique_variants(T::ALL) — the (declaration, lex) arms MUST filter the SAME strict-uniqueness set from the equivalence-partition surface's `Vec<Self>`-return column, so a downstream consumer that treats one arm's multiset as an authoritative substitute for the other's would disagree with the pinned projection",
);
// (121) — `T::is_uniformly_repeating(items)` MUST agree with the
// lower-bound test of the set-level least-common-multiplicity
// aggregate against `2` on every slice AND MUST land on its three
// canonical fixpoints (`false` on the empty slice UNCONDITIONALLY,
// `false` on the full set UNCONDITIONALLY, `true` on the doubled
// full set gated on `T::CARDINALITY >= 1`) AND on THREE
// composition-equality arms on the doubled-slice fixpoint: (a)
// min-composition against `T::min_variant_count(items) >= 2`, (b)
// histogram universal against `T::variant_counts(items).iter()
// .all(|&c| c >= 2)`, (c) De Morgan decomposition against
// `T::is_covering(items) && !T::is_unique_any(items)`. The three
// fixpoints + three composition arms partition failure modes at the
// (discriminant × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice AND full-set arms (returns `true` rather
// than `false`); an override that folds onto `false` unconditionally
// fires on the doubled-full-set arm at cardinality `>= 1` (returns
// `false` rather than `true`); an override that detaches from the
// min-composition on any slice bifurcates loudly at the min-arm; an
// override that detaches from the histogram universal bifurcates
// at the histogram arm; an override that detaches from the De Morgan
// decomposition bifurcates at the covering-vs-any-unique conjunction.
//
// Sibling posture to clauses (113) + (114) + (116): those clauses
// close the (set-level × bool × EXISTENTIAL-lift × multiplicity-
// band) trichotomy at (mult `>= 2`, mult `== 1`, mult `>= 2`
// sharpening) via [`Self::is_repeating_any`], [`Self::is_unique_any`],
// [`Self::count_repeating_variants`] one QUANTIFIER-and-return-shape
// axis under; this clause opens the SET-LEVEL UNIVERSAL LIFT peer
// to (113) at the (mult `>= 2`) band via `min_variant_count >= 2`
// — the ∀-arm of the ∀/∃ duality on the multiplicity-band axis.
// Together with the pre-existing (set-level × bool × UNIVERSAL-lift
// × mult `>= 1`) [`Self::is_covering`] corner and (set-level × bool
// × UNIVERSAL-lift × mult `<= 1`) [`Self::is_pairwise_distinct`]
// corner, the (set-level × bool × universal × mult-band) face now
// closes at three peer universal-lift bool corners across the
// (mult `<= 1`, mult `>= 1`, mult `>= 2`) partition — the mirror
// of the (mult `== 0`, mult `== 1`, mult `>= 2`) existential-lift
// trichotomy one quantifier axis over. The default trait body
// threads `<Self as ClosedSet>::min_variant_count(items) >= 2`
// verbatim and satisfies every fixpoint arm + every composition-
// equality arm for free; the assertion catches a future implementor
// whose override drifts the projection loudly rather than silently
// bifurcating the set-level uniform-repeat predicate surface every
// downstream uniform-repeat consumer routes through.
assert!(
!T::is_uniformly_repeating(&[]),
"{type_name}: T::is_uniformly_repeating(&[]) == true != false — the set-level universal-lift uniform-repeat predicate MUST report `false` on the empty slice because the least-common-multiplicity aggregate returns `0` and the lower-bound test against `2` fails; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream uniform-repeat consumer routes through",
);
assert!(
!T::is_uniformly_repeating(T::ALL),
"{type_name}: T::is_uniformly_repeating(T::ALL) == true != false — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so the least-common-multiplicity aggregate returns `1` and the lower-bound test against `2` fails; a `true` full-set uniform-repeat value silently detaches the set-level uniform-repeat predicate from the (variant → decl-slot) injectivity clause (16), breaking every downstream uniform-repeat consumer — the full-set arm is LOAD-BEARING as the boundary that separates this strict (mult `>= 2`) universal-lift predicate from the weaker (mult `>= 1`) universal-lift predicate [`T::is_covering`], which is `true` on the full set",
);
if T::CARDINALITY >= 1 {
let doubled_uniformly_repeating = T::is_uniformly_repeating(&doubled_full_set);
assert!(
doubled_uniformly_repeating,
"{type_name}: T::is_uniformly_repeating(&doubled_full_set) == false != true on a cardinality-{cardinality} closed set — the doubled full set hits every variant at EXACTLY TWO positions, so the least-common-multiplicity aggregate returns `2` and the lower-bound test against `2` holds; the doubled-full-set arm at cardinality `>= 1` is LOAD-BEARING — it is the ONLY canonical fixpoint arm that separates the (mult `>= 2`) universal band from a `_ => false` degenerate override (empty, full-set both coincide on `false`; only the doubled-full-set distinguishes them under any non-degenerate cardinality)",
cardinality = T::CARDINALITY,
);
let expected_via_min_ge_two = T::min_variant_count(&doubled_full_set) >= 2;
assert_eq!(
doubled_uniformly_repeating, expected_via_min_ge_two,
"{type_name}: T::is_uniformly_repeating(&doubled_full_set) drifted from (T::min_variant_count(&doubled_full_set) >= 2) — the set-level uniform-repeat predicate MUST equal the lower-bound test of the least-common-multiplicity aggregate against `2` on every slice, so a downstream uniform-repeat consumer that binds `T::min_variant_count(_) >= 2` as its uniform-repeat query surface would disagree with the pinned predicate",
);
let expected_via_variant_counts_all_ge_two =
T::variant_counts(&doubled_full_set).iter().all(|&c| c >= 2);
assert_eq!(
doubled_uniformly_repeating, expected_via_variant_counts_all_ge_two,
"{type_name}: T::is_uniformly_repeating(&doubled_full_set) drifted from T::variant_counts(&doubled_full_set).iter().all(|&c| c >= 2) — the set-level uniform-repeat predicate MUST equal the histogram-vector universal `>= 2` test on every slice, so a downstream uniform-repeat consumer that binds this histogram-arm composition would disagree with the pinned predicate; the identity captures that a slice's per-variant multiplicity histogram lies entirely in the (mult `>= 2`) band iff every bar clears the `>= 2` threshold",
);
let expected_via_covering_and_not_unique_any =
T::is_covering(&doubled_full_set) && !T::is_unique_any(&doubled_full_set);
assert_eq!(
doubled_uniformly_repeating, expected_via_covering_and_not_unique_any,
"{type_name}: T::is_uniformly_repeating(&doubled_full_set) drifted from (T::is_covering(&doubled_full_set) && !T::is_unique_any(&doubled_full_set)) — the set-level uniform-repeat predicate MUST equal the De Morgan decomposition (covering ∧ ¬any-unique) on every slice, so a downstream uniform-repeat consumer that binds this covering-and-not-any-unique conjunction as its uniform-repeat query surface would disagree with the pinned predicate; the identity captures that a slice's per-variant multiplicity histogram lies entirely in the (mult `>= 2`) band iff (i) every variant appears at least once (covering rules out mult `== 0`) AND (ii) no variant appears exactly once (¬any-unique rules out mult `== 1`), together forcing every variant into the (mult `>= 2`) band",
);
}
// (122) — `T::is_saturated_by(target, items)` MUST agree with the
// strict-equality test of the per-target multiplicity primitive
// against the slice arity `items.len()` on every (target, slice)
// pair AND MUST land on its four canonical fixpoints (`true` at
// every target on the empty slice UNCONDITIONALLY, `false` at every
// target on the full set gated on `T::CARDINALITY >= 2`, `true` at
// every target on the doubled-matching-singleton `[target, target]`
// slice UNCONDITIONALLY, `false` at every non-matching (target,
// slice-element) pair on a singleton) AND on TWO composition-
// equality arms on the doubled-matching-singleton fixpoint: (a)
// count-composition against `T::count_occurrences_of(target,
// items) == items.len()`, (b) empty-or-covering-degenerate
// composition against
// `items.is_empty() || (T::occurs_in(target, items) &&
// T::count_distinct(items) == 1)`. The four fixpoints + two
// composition arms partition failure modes at the (discriminant ×
// slice-shape × composition-equality) corner simultaneously: an
// override that folds onto `true` unconditionally fires on the
// non-matching-singleton arm AND the full-set arm at cardinality
// `>= 2` (returns `true` rather than `false`); an override that
// folds onto `false` unconditionally fires on the empty-slice AND
// matching-singleton AND doubled-matching-singleton arms (returns
// `false` rather than `true`); an override that folds onto the
// (multiplicity `> 0`) membership predicate [`T::occurs_in`]
// bifurcates at the doubled-matching-singleton arm at cardinality
// `>= 2` (still `true` there — fine) BUT fires on the full-set arm
// at cardinality `>= 2` (returns `true` rather than `false`); an
// override that folds onto the (multiplicity `== 1`) uniqueness
// predicate [`T::is_unique_occurrence_of`] fires on the doubled-
// matching-singleton arm (returns `false` rather than `true`); an
// override that detaches from the count-composition on any slice
// bifurcates loudly at the count-arm; an override that detaches
// from the empty-or-covering-degenerate composition bifurcates at
// the composition arm.
//
// Sibling posture to clauses (97) + (111) + (112): those clauses
// close the (per-target × bool × MULTIPLICITY-band) trichotomy at
// (mult `> 0`, mult `== 1`, mult `>= 2`) via [`T::occurs_in`],
// [`T::is_unique_occurrence_of`], [`T::is_repeated_occurrence_of`]
// one QUANTIFIER-axis under; this clause opens the (per-target ×
// bool × PER-POSITION-quantifier) 2-corner face at the ∀-arm peer
// to [`T::occurs_in`] one PER-POSITION QUANTIFIER-axis over on the
// SAME per-target arity. Together with the pre-existing (per-target
// × bool × per-position-EXISTENTIAL) [`T::occurs_in`] ∃-arm, the
// (per-target × bool × per-position-quantifier) face now closes
// exhaustively at two peer per-position-quantifier bool corners
// across the (∃, ∀) partition — the mirror of the (mult `> 0`,
// mult `== 1`, mult `>= 2`) multiplicity-band trichotomy one
// quantifier axis over. The default trait body threads
// `<Self as ClosedSet>::count_occurrences_of(target, items) ==
// items.len()` verbatim and satisfies every fixpoint arm + every
// composition-equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target saturation predicate
// surface every downstream saturation consumer routes through.
let empty: &[T] = &[];
for target in T::ALL.iter().copied() {
assert!(
T::is_saturated_by(target, empty),
"{type_name}: T::is_saturated_by({target_label:?}, &[]) == false != true — the per-target ∀-position saturation predicate MUST report `true` on the empty slice because the multiplicity primitive returns `0`, the slice arity is `0`, and the strict-equality test `0 == 0` holds VACUOUSLY; a `false` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream saturation consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let matching_singleton = [target];
assert!(
T::is_saturated_by(target, &matching_singleton),
"{type_name}: T::is_saturated_by({target_label:?}, [{target_label:?}]) == false != true — the sole position hits the target, the per-target multiplicity is `1`, the slice arity is `1`, and the strict-equality test `1 == 1` holds; a `false` matching-singleton value silently bifurcates the matching-singleton fixpoint contract every downstream saturation consumer routes through",
target_label = <T as ClosedSet>::label(target),
);
let doubled_matching = [target, target];
let doubled_matching_saturated = T::is_saturated_by(target, &doubled_matching);
assert!(
doubled_matching_saturated,
"{type_name}: T::is_saturated_by({target_label:?}, [{target_label:?}, {target_label:?}]) == false != true — both positions hit the target, the per-target multiplicity is `2`, the slice arity is `2`, and the strict-equality test `2 == 2` holds; the doubled-matching-singleton arm is LOAD-BEARING as the drift catch for an override that folds onto the (multiplicity `== 1`) uniqueness predicate [`T::is_unique_occurrence_of`] (which returns `false` on this slice while THIS predicate returns `true`)",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_count_eq_len =
T::count_occurrences_of(target, &doubled_matching) == doubled_matching.len();
assert_eq!(
doubled_matching_saturated, expected_via_count_eq_len,
"{type_name}: T::is_saturated_by({target_label:?}, [{target_label:?}, {target_label:?}]) drifted from (T::count_occurrences_of({target_label:?}, [{target_label:?}, {target_label:?}]) == 2) — the saturation predicate MUST equal the strict-equality test of the per-target multiplicity primitive against the slice arity on every slice, so a downstream saturation consumer that binds `T::count_occurrences_of(_, items) == items.len()` as its saturation query surface would disagree with the pinned predicate",
target_label = <T as ClosedSet>::label(target),
);
let expected_via_empty_or_occurs_and_count_distinct_one = doubled_matching.is_empty()
|| (T::occurs_in(target, &doubled_matching)
&& T::count_distinct(&doubled_matching) == 1);
assert_eq!(
doubled_matching_saturated, expected_via_empty_or_occurs_and_count_distinct_one,
"{type_name}: T::is_saturated_by({target_label:?}, [{target_label:?}, {target_label:?}]) drifted from (items.is_empty() || (T::occurs_in(_, items) && T::count_distinct(items) == 1)) — the saturation predicate MUST factor through the disjunction of (i) the empty-slice trivial-holds arm AND (ii) the conjunction of (a) target-presence via `T::occurs_in` AND (b) singleton-distinct-count `T::count_distinct == 1`; the identity captures that a slice is saturated by a target iff EITHER it is empty (vacuously) OR the target appears AND the slice hits only ONE variant",
target_label = <T as ClosedSet>::label(target),
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
assert!(
!T::is_saturated_by(target, T::ALL),
"{type_name}: T::is_saturated_by({target_label:?}, T::ALL) == true != false on a cardinality-{cardinality} closed set — clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, so the per-target multiplicity is `1`, the slice arity is `T::CARDINALITY == {cardinality} >= 2`, and the strict-equality test `1 == {cardinality}` fails; the full-set arm at cardinality `>= 2` is LOAD-BEARING as the boundary that separates saturation (per-target × ∀-position) from covering ([`T::is_covering`], which is `true` on the full set at every cardinality)",
target_label = <T as ClosedSet>::label(target),
cardinality = T::CARDINALITY,
);
}
for target in T::ALL.iter().copied() {
for other in T::ALL.iter().copied() {
if T::index_of(target) != T::index_of(other) {
let non_matching_singleton = [other];
assert!(
!T::is_saturated_by(target, &non_matching_singleton),
"{type_name}: T::is_saturated_by({target_label:?}, [{other_label:?}]) == true != false — the per-target multiplicity is `0` at the target because the sole position sits at a DISTINCT variant, the slice arity is `1`, and the strict-equality test `0 == 1` fails; the non-matching-singleton arm is LOAD-BEARING as the drift catch for an override that folds onto `true` unconditionally",
target_label = <T as ClosedSet>::label(target),
other_label = <T as ClosedSet>::label(other),
);
}
}
}
}
// (123) — `T::modal_variant(items)` MUST agree with the
// DECLARATION-ORDER-FIRST argmax over the [`T::variant_counts`]
// histogram on every slice AND MUST land on its FOUR canonical
// fixpoints (`None` on the empty slice UNCONDITIONALLY,
// `Some(target)` on every matching-singleton `[target]` slice,
// `Some(T::first())` on the full-set slice UNCONDITIONALLY,
// `Some(T::first())` on the doubled-full-set slice
// UNCONDITIONALLY) AND on TWO composition-equality arms on the
// matching-singleton fixpoint: (a) count-composition against
// `Some(T::max_variant_count([target])) ==
// Some(T::count_occurrences_of(T::modal_variant([target]).unwrap(),
// [target]))`, (b) present-membership against
// `T::present_variants([target]).contains(&T::modal_variant([target])
// .unwrap())`. The four fixpoints + two composition arms partition
// failure modes at the (discriminant × slice-shape × composition-
// equality) corner simultaneously: an override that omits the
// empty-slice guard fires on the empty-slice arm (returns
// `Some(T::ALL[0])` rather than `None` past the (max == 0, every-
// count == 0) degenerate arm); an override that walks
// [`T::sorted_variants`] instead of [`T::ALL`] fires on the full-
// set arm when `T::first() != T::sorted_first()` (returns
// `Some(T::sorted_first())` rather than `Some(T::first())`); an
// override that folds onto `None` unconditionally fires on the
// matching-singleton + full-set + doubled-full-set TRUE-fixpoint
// arms; an override that detaches from the count-composition on
// any slice bifurcates loudly at the count-arm; an override that
// detaches from the present-membership arm bifurcates on the
// matching-singleton fixpoint.
//
// Sibling posture to clauses (101) + (102) + (109) + (110): those
// clauses close the (set-level × `usize` × statistical-aggregate)
// direction column, the (set-level × `(usize, usize)` ×
// statistical-aggregate) pair column, the (set-level × `bool` ×
// statistical-aggregate) uniformity column, and the (set-level ×
// `usize` × scalar-difference) span column via
// [`T::max_variant_count`], [`T::min_variant_count`],
// [`T::variant_count_range`], [`T::is_uniform`], and
// [`T::variant_count_span`]; this clause opens the (set-level ×
// `Option<Self>` × statistical-aggregate) argument column past
// those four scalar / pair / bool corners on the equivalence-
// partition surface. The default trait body threads the
// `is_empty()`-guarded `T::ALL.iter().copied().find(|&v|
// T::count_occurrences_of(v, items) == T::max_variant_count(items))`
// sweep verbatim and satisfies every fixpoint arm + every
// composition-equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the modal-variant surface every
// downstream argmax consumer routes through.
let empty: &[T] = &[];
assert_eq!(
T::modal_variant(empty),
None,
"{type_name}: T::modal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because every per-variant occurrence count collapses to 0 and an UNGUARDED find(|v| count(v) == 0) sweep would silently return Some(T::ALL[0]) past the (max == 0, every-count == 0) degenerate arm; a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream argmax consumer routes through",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let modal = T::modal_variant(&matching_singleton);
assert_eq!(
modal,
Some(target),
"{type_name}: T::modal_variant([{target_label:?}]) drifted from Some({target_label:?}) — the sole position hits the target, the modal multiplicity is 1, and the target is the SOLE variant with a strictly-positive count on a singleton; a divergent value silently bifurcates the matching-singleton fixpoint contract",
);
let modal_variant_value = modal.expect("matching-singleton modal must be Some");
let expected_via_count_eq_max =
T::count_occurrences_of(modal_variant_value, &matching_singleton)
== T::max_variant_count(&matching_singleton);
assert!(
expected_via_count_eq_max,
"{type_name}: T::modal_variant([{target_label:?}]) yielded {modal_variant_label:?} but T::count_occurrences_of({modal_variant_label:?}, [{target_label:?}]) != T::max_variant_count([{target_label:?}]) — the argmax variant MUST achieve the modal multiplicity exactly on every non-empty slice, so a downstream argmax consumer that binds `T::count_occurrences_of(argmax, items) == T::max_variant_count(items)` as its query surface would disagree with the pinned projection",
modal_variant_label = <T as ClosedSet>::label(modal_variant_value),
);
let expected_via_present_variants =
T::present_variants(&matching_singleton).contains(&modal_variant_value);
assert!(
expected_via_present_variants,
"{type_name}: T::modal_variant([{target_label:?}]) yielded {modal_variant_label:?} but T::present_variants([{target_label:?}]) does NOT contain that variant — the argmax variant MUST sit in the substrate's typed present-witness list on every non-empty slice, so a downstream argmax consumer that intersects the argmax against present-variants would disagree with the pinned projection",
modal_variant_label = <T as ClosedSet>::label(modal_variant_value),
);
}
let first_label = <T as ClosedSet>::label(T::first());
assert_eq!(
T::modal_variant(T::ALL),
Some(T::first()),
"{type_name}: T::modal_variant(T::ALL) drifted from Some({first_label:?}) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and the DECLARATION-ORDER-FIRST argmax sweep hits T::ALL[0] == T::first() immediately; a Some(other) full-set value is the drift catch for an override that walks T::sorted_variants instead of T::ALL",
);
let doubled_full_set: Vec<T> = T::ALL
.iter()
.copied()
.chain(T::ALL.iter().copied())
.collect();
assert_eq!(
T::modal_variant(&doubled_full_set),
Some(T::first()),
"{type_name}: T::modal_variant(&doubled_full_set) drifted from Some({first_label:?}) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::max_variant_count(doubled) == 2, and the DECLARATION-ORDER-FIRST argmax sweep hits T::ALL[0] == T::first() immediately",
);
// (124) — `T::sorted_modal_variant(items)` MUST agree with the
// LEX-ORDER-FIRST argmax over the [`T::variant_counts`] histogram
// on every slice AND MUST land on its FOUR canonical fixpoints
// (`None` on the empty slice UNCONDITIONALLY, `Some(target)` on
// every matching-singleton `[target]` slice, `Some(T::sorted_first())`
// on the full-set slice UNCONDITIONALLY, `Some(T::sorted_first())`
// on the doubled-full-set slice UNCONDITIONALLY) AND on TWO
// composition-equality arms on the matching-singleton fixpoint:
// (a) count-composition against
// `Some(T::max_variant_count([target])) ==
// Some(T::count_occurrences_of(T::sorted_modal_variant([target]).unwrap(),
// [target]))`, (b) present-membership against
// `T::present_variants([target]).contains(&T::sorted_modal_variant(
// [target]).unwrap())`. The four fixpoints + two composition arms
// partition failure modes at the (discriminant × slice-shape ×
// composition-equality) corner simultaneously: an override that
// omits the empty-slice guard fires on the empty-slice arm
// (returns `Some(T::sorted_first())` rather than `None` past the
// (max == 0, every-count == 0) degenerate arm); an override that
// walks [`T::ALL`] instead of [`T::sorted_variants`] fires on the
// full-set arm when `T::first() != T::sorted_first()` (returns
// `Some(T::first())` rather than `Some(T::sorted_first())`); an
// override that folds onto `None` unconditionally fires on the
// matching-singleton + full-set + doubled-full-set TRUE-fixpoint
// arms; an override that detaches from the count-composition on
// any slice bifurcates loudly at the count-arm; an override that
// detaches from the present-membership arm bifurcates on the
// matching-singleton fixpoint.
//
// Sibling posture to clause (123) one ordering-axis over: clause
// (123) opens the (set-level × `Option<Self>` × statistical-
// aggregate × declaration-order) argmax corner via
// [`T::modal_variant`]; this clause closes the ordering-axis at
// the LEX-order-first argmax corner via [`T::sorted_modal_variant`],
// completing the (set-level × `Option<Self>` × statistical-
// aggregate × ordering) 2-corner face at both corners. The
// default trait body threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().find(|&v|
// T::count_occurrences_of(v, items) == T::max_variant_count(items))`
// sweep verbatim and satisfies every fixpoint arm + every
// composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the lex-order argmax surface
// every downstream tie-break consumer routes through.
let sorted_first_label = <T as ClosedSet>::label(T::sorted_first());
assert_eq!(
T::sorted_modal_variant(empty),
None,
"{type_name}: T::sorted_modal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because every per-variant occurrence count collapses to 0 and an UNGUARDED sorted_variants().into_iter().find(|v| count(v) == 0) sweep would silently return Some(T::sorted_first()) past the (max == 0, every-count == 0) degenerate arm; a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order argmax consumer routes through",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let sorted_modal = T::sorted_modal_variant(&matching_singleton);
assert_eq!(
sorted_modal,
Some(target),
"{type_name}: T::sorted_modal_variant([{target_label:?}]) drifted from Some({target_label:?}) — the sole position hits the target, the modal multiplicity is 1, and the target is the SOLE variant with a strictly-positive count on a singleton regardless of walk order; a divergent value silently bifurcates the matching-singleton fixpoint contract",
);
let sorted_modal_value =
sorted_modal.expect("matching-singleton sorted modal must be Some");
let expected_via_count_eq_max =
T::count_occurrences_of(sorted_modal_value, &matching_singleton)
== T::max_variant_count(&matching_singleton);
assert!(
expected_via_count_eq_max,
"{type_name}: T::sorted_modal_variant([{target_label:?}]) yielded {sorted_modal_label:?} but T::count_occurrences_of({sorted_modal_label:?}, [{target_label:?}]) != T::max_variant_count([{target_label:?}]) — the argmax variant MUST achieve the modal multiplicity exactly on every non-empty slice, so a downstream lex-order argmax consumer that binds `T::count_occurrences_of(argmax, items) == T::max_variant_count(items)` as its query surface would disagree with the pinned projection",
sorted_modal_label = <T as ClosedSet>::label(sorted_modal_value),
);
let expected_via_present_variants =
T::present_variants(&matching_singleton).contains(&sorted_modal_value);
assert!(
expected_via_present_variants,
"{type_name}: T::sorted_modal_variant([{target_label:?}]) yielded {sorted_modal_label:?} but T::present_variants([{target_label:?}]) does NOT contain that variant — the argmax variant MUST sit in the substrate's typed present-witness list on every non-empty slice, so a downstream lex-order argmax consumer that intersects the argmax against present-variants would disagree with the pinned projection",
sorted_modal_label = <T as ClosedSet>::label(sorted_modal_value),
);
}
assert_eq!(
T::sorted_modal_variant(T::ALL),
Some(T::sorted_first()),
"{type_name}: T::sorted_modal_variant(T::ALL) drifted from Some({sorted_first_label:?}) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and the LEX-ORDER-FIRST argmax sweep hits T::sorted_variants()[0] == T::sorted_first() immediately; a Some(other) full-set value is the drift catch for an override that walks T::ALL instead of T::sorted_variants",
);
assert_eq!(
T::sorted_modal_variant(&doubled_full_set),
Some(T::sorted_first()),
"{type_name}: T::sorted_modal_variant(&doubled_full_set) drifted from Some({sorted_first_label:?}) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::max_variant_count(doubled) == 2, and the LEX-ORDER-FIRST argmax sweep hits T::sorted_variants()[0] == T::sorted_first() immediately",
);
// (125) — `T::antimodal_variant(items)` MUST agree with the
// DECLARATION-ORDER-FIRST argmin over the [`T::variant_counts`]
// histogram on every slice AND MUST land on its FOUR canonical
// fixpoints (`None` on the empty slice UNCONDITIONALLY,
// count-composition-equality on every matching-singleton `[target]`
// slice against `Some(T::min_variant_count([target]))`,
// `Some(T::first())` on the full-set slice UNCONDITIONALLY,
// `Some(T::first())` on the doubled-full-set slice
// UNCONDITIONALLY). The four fixpoints + count-composition arm
// partition failure modes at the (discriminant × slice-shape ×
// composition-equality) corner simultaneously: an override that
// omits the empty-slice guard fires on the empty-slice arm (returns
// `Some(T::ALL[0])` rather than `None` past the (min == 0, every-
// count == 0) degenerate arm); an override that folds onto `None`
// unconditionally fires on the matching-singleton + full-set +
// doubled-full-set SOME-fixpoint arms; an override that
// accidentally reuses [`T::modal_variant`]'s argmax body fires on
// the count-composition arm at every non-flat-histogram slice
// (matching-singleton at cardinality `>= 2`: argmax hits the target
// with count `1 = max`, argmin should hit a missing variant with
// count `0 = min`, so the count-composition arm bifurcates `1 !=
// 0`); an override that detaches from the count-composition on any
// slice bifurcates loudly at the count-arm.
//
// Sibling posture to clause (123) one DIRECTION-axis over: clause
// (123) opens the (set-level × `Option<Self>` × statistical-
// aggregate × declaration-order × argmax) corner via
// [`T::modal_variant`]; this clause opens the (set-level ×
// `Option<Self>` × statistical-aggregate × declaration-order ×
// argmin) corner via [`T::antimodal_variant`], opening the
// (direction × ordering) 4-corner face at its argmin arm past the
// argmax arm on the declaration column. The default trait body
// threads the `is_empty()`-guarded `T::ALL.iter().copied().find(|&v|
// T::count_occurrences_of(v, items) == T::min_variant_count(items))`
// sweep verbatim and satisfies every fixpoint arm + the
// composition-equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the argmin surface every downstream
// trough-witness consumer routes through.
assert_eq!(
T::antimodal_variant(empty),
None,
"{type_name}: T::antimodal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because every per-variant occurrence count collapses to 0 and an UNGUARDED find(|v| count(v) == 0) sweep would silently return Some(T::first()) past the (min == 0, every-count == 0) degenerate arm; a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream argmin consumer routes through",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let antimodal = T::antimodal_variant(&matching_singleton);
let antimodal_value = antimodal.unwrap_or_else(|| {
panic!(
"{type_name}: T::antimodal_variant([{target_label:?}]) drifted from Some(_) — every non-empty slice MUST yield Some(argmin) because the finite histogram achieves its min at at least one bin; a None value silently bifurcates the matching-singleton fixpoint contract",
)
});
let expected_via_count_eq_min =
T::count_occurrences_of(antimodal_value, &matching_singleton)
== T::min_variant_count(&matching_singleton);
assert!(
expected_via_count_eq_min,
"{type_name}: T::antimodal_variant([{target_label:?}]) yielded {antimodal_label:?} but T::count_occurrences_of({antimodal_label:?}, [{target_label:?}]) != T::min_variant_count([{target_label:?}]) — the argmin variant MUST achieve the least-common multiplicity exactly on every non-empty slice, so a downstream argmin consumer that binds `T::count_occurrences_of(argmin, items) == T::min_variant_count(items)` as its query surface would disagree with the pinned projection",
antimodal_label = <T as ClosedSet>::label(antimodal_value),
);
}
assert_eq!(
T::antimodal_variant(T::ALL),
Some(T::first()),
"{type_name}: T::antimodal_variant(T::ALL) drifted from Some({first_label:?}) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and the DECLARATION-ORDER-FIRST argmin sweep hits T::ALL[0] == T::first() immediately (the flat-histogram fixpoint pins argmax and argmin at the SAME witness at both corners of the direction axis)",
);
assert_eq!(
T::antimodal_variant(&doubled_full_set),
Some(T::first()),
"{type_name}: T::antimodal_variant(&doubled_full_set) drifted from Some({first_label:?}) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::min_variant_count(doubled) == 2, and the DECLARATION-ORDER-FIRST argmin sweep hits T::ALL[0] == T::first() immediately",
);
// (126) — `T::sorted_antimodal_variant(items)` MUST agree with the
// LEX-ORDER-FIRST argmin over the [`T::variant_counts`] histogram
// on every slice AND MUST land on its FOUR canonical fixpoints
// (`None` on the empty slice UNCONDITIONALLY,
// count-composition-equality on every matching-singleton `[target]`
// slice against `Some(T::min_variant_count([target]))`,
// `Some(T::sorted_first())` on the full-set slice UNCONDITIONALLY,
// `Some(T::sorted_first())` on the doubled-full-set slice
// UNCONDITIONALLY). The four fixpoints + count-composition arm
// partition failure modes at the (discriminant × slice-shape ×
// composition-equality) corner simultaneously: an override that
// omits the empty-slice guard fires on the empty-slice arm (returns
// `Some(T::sorted_first())` rather than `None` past the (min == 0,
// every-count == 0) degenerate arm); an override that walks
// [`T::ALL`] instead of [`T::sorted_variants`] fires on the full-
// set arm when `T::first() != T::sorted_first()` (returns
// `Some(T::first())` rather than `Some(T::sorted_first())`); an
// override that folds onto `None` unconditionally fires on the
// matching-singleton + full-set + doubled-full-set SOME-fixpoint
// arms; an override that accidentally reuses
// [`T::sorted_modal_variant`]'s argmax body fires on the count-
// composition arm at every non-flat-histogram slice (matching-
// singleton at cardinality `>= 2`: argmax hits the target with
// count `1 = max`, argmin should hit a missing variant with count
// `0 = min`, so the count-composition arm bifurcates `1 != 0`); an
// override that detaches from the count-composition on any slice
// bifurcates loudly at the count-arm.
//
// Sibling posture to clauses (123) + (124) + (125): clause (123)
// opens the (set-level × `Option<Self>` × statistical-aggregate ×
// declaration-order × argmax) corner via [`T::modal_variant`]; clause
// (124) closes the ordering axis at the (set-level × `Option<Self>`
// × statistical-aggregate × lex-order × argmax) corner via
// [`T::sorted_modal_variant`]; clause (125) opens the argmin arm on
// the (declaration-order × argmin) corner via
// [`T::antimodal_variant`]; this clause CLOSES the (direction ×
// ordering) 2×2 = 4-corner face at its final (lex-order × argmin)
// corner via [`T::sorted_antimodal_variant`]. The default trait body
// threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().find(|&v|
// T::count_occurrences_of(v, items) == T::min_variant_count(items))`
// sweep verbatim and satisfies every fixpoint arm + the composition-
// equality arm for free; the assertion catches a future implementor
// whose override drifts the projection loudly rather than silently
// bifurcating the lex-order argmin surface every downstream
// trough-witness consumer routes through.
assert_eq!(
T::sorted_antimodal_variant(empty),
None,
"{type_name}: T::sorted_antimodal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because every per-variant occurrence count collapses to 0 and an UNGUARDED T::sorted_variants().into_iter().find(|v| count(v) == 0) sweep would silently return Some(T::sorted_first()) past the (min == 0, every-count == 0) degenerate arm; a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order argmin consumer routes through",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let sorted_antimodal = T::sorted_antimodal_variant(&matching_singleton);
let sorted_antimodal_value = sorted_antimodal.unwrap_or_else(|| {
panic!(
"{type_name}: T::sorted_antimodal_variant([{target_label:?}]) drifted from Some(_) — every non-empty slice MUST yield Some(argmin) because the finite histogram achieves its min at at least one bin; a None value silently bifurcates the matching-singleton fixpoint contract",
)
});
let expected_via_count_eq_min =
T::count_occurrences_of(sorted_antimodal_value, &matching_singleton)
== T::min_variant_count(&matching_singleton);
assert!(
expected_via_count_eq_min,
"{type_name}: T::sorted_antimodal_variant([{target_label:?}]) yielded {sorted_antimodal_label:?} but T::count_occurrences_of({sorted_antimodal_label:?}, [{target_label:?}]) != T::min_variant_count([{target_label:?}]) — the argmin variant MUST achieve the least-common multiplicity exactly on every non-empty slice, so a downstream lex-order argmin consumer that binds `T::count_occurrences_of(argmin, items) == T::min_variant_count(items)` as its query surface would disagree with the pinned projection",
sorted_antimodal_label = <T as ClosedSet>::label(sorted_antimodal_value),
);
}
assert_eq!(
T::sorted_antimodal_variant(T::ALL),
Some(T::sorted_first()),
"{type_name}: T::sorted_antimodal_variant(T::ALL) drifted from Some({sorted_first_label:?}) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and the LEX-ORDER-FIRST argmin sweep hits T::sorted_variants()[0] == T::sorted_first() immediately (the flat-histogram fixpoint pins argmax and argmin at the SAME witness at both corners of the direction axis at the LEX arm); a Some(other) full-set value is the drift catch for an override that walks T::ALL instead of T::sorted_variants",
);
assert_eq!(
T::sorted_antimodal_variant(&doubled_full_set),
Some(T::sorted_first()),
"{type_name}: T::sorted_antimodal_variant(&doubled_full_set) drifted from Some({sorted_first_label:?}) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::min_variant_count(doubled) == 2, and the LEX-ORDER-FIRST argmin sweep hits T::sorted_variants()[0] == T::sorted_first() immediately",
);
// (127) — `T::modal_variants(items)` MUST agree with the
// declaration-order-preserving argmax witness-collection over the
// [`T::variant_counts`] histogram on every slice AND MUST land on
// its THREE canonical fixpoints (empty vector on the empty slice
// UNCONDITIONALLY, `T::ALL.to_vec()` on the full-set slice
// UNCONDITIONALLY, `T::ALL.to_vec()` on the doubled-full-set slice
// UNCONDITIONALLY). The three fixpoints partition the failure
// modes at the (Vec-shape × slice-shape) corner simultaneously:
// an override that omits the empty-slice guard fires on the
// empty-slice arm (returns `T::ALL.to_vec()` rather than the
// empty vector past the (max == 0, every-count == 0) degenerate
// arm where every variant hits `count == 0 == max`); an override
// that folds onto the empty vector unconditionally fires on the
// full-set + doubled-full-set arms (both flat-histogram fixpoints
// hit every variant); an override that returns a proper subset of
// T::ALL on the full set (e.g. only the first variant) fires on
// the full-set arm because clause (3)'s pairwise-distinctness pins
// every variant at count `1 == max`; an override that returns a
// Vec of the wrong length on any flat-histogram slice bifurcates
// loudly at the length arm; an override that returns a Vec whose
// FIRST element disagrees with [`T::modal_variant`] on the full-
// set slice fires at the composition-equality arm against
// `T::modal_variant(T::ALL) == Some(T::first())`.
//
// Sibling posture to clause (123): clause (123) opens the (set-
// level × `Option<Self>` × statistical-aggregate × declaration-
// order × argmax) FIRST-WITNESS corner via [`T::modal_variant`];
// this clause opens the (set-level × `Vec<Self>` × statistical-
// aggregate × declaration-order × argmax) COMPLETE-WITNESS
// corner one RETURN-SHAPE axis over via [`T::modal_variants`]. The
// (return-shape × direction × ordering) 2×2×2 = 8-corner cube on
// the direction-anchor face now opens its (Vec<Self>, argmax,
// declaration-order) corner past the (Option<Self>, argmax,
// declaration-order) corner clause (123) opened; the next lifts
// close (Vec<Self>, argmax, lex), (Vec<Self>, argmin, declaration),
// and (Vec<Self>, argmin, lex) — three remaining Vec-return
// corners. The default trait body threads the `is_empty()`-guarded
// `T::ALL.iter().copied().filter(|&v|
// T::count_occurrences_of(v, items) == T::max_variant_count(items))
// .collect()` sweep verbatim and satisfies every fixpoint arm +
// the composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the declaration-order argmax
// witness-collection surface every downstream complete-mode
// consumer routes through.
assert_eq!(
T::modal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::modal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because every per-variant occurrence count collapses to 0 and an UNGUARDED T::ALL.iter().copied().filter(|v| count(v) == 0).collect() sweep would silently return T::ALL.to_vec() past the (max == 0, every-count == 0) degenerate arm where every variant satisfies `count == max == 0`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream declaration-order argmax witness-collection consumer routes through",
);
let full_modal_variants = T::modal_variants(T::ALL);
assert_eq!(
full_modal_variants.len(),
T::CARDINALITY,
"{type_name}: T::modal_variants(T::ALL).len() == {actual_len} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and the argmax witness-collection filter hits EVERY variant of T::ALL (the flat-histogram fixpoint pins the direction-axis degeneracy at every corner); a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR that returns a proper subset of T::ALL on the full set",
actual_len = full_modal_variants.len(),
cardinality = T::CARDINALITY,
);
assert_eq!(
full_modal_variants.as_slice(),
T::ALL,
"{type_name}: T::modal_variants(T::ALL) drifted from T::ALL element-for-element — the declaration-order-preserving argmax witness-collection MUST equal T::ALL on the full-set slice because every variant hits count == max == 1 and the filter walks T::ALL in declaration order; an ordering divergence is the drift catch for an override that reorders the witnesses via `T::sorted_variants` or via any other non-declaration walk",
);
let doubled_modal_variants = T::modal_variants(&doubled_full_set);
assert_eq!(
doubled_modal_variants.as_slice(),
T::ALL,
"{type_name}: T::modal_variants(&doubled_full_set) drifted from T::ALL element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::max_variant_count(doubled) == 2, and the filter hits EVERY variant of T::ALL in declaration order; a divergent doubled-full-set value silently bifurcates the declaration-order flat-histogram fixpoint contract every downstream complete-mode consumer routes through",
);
if let Some(head) = full_modal_variants.first().copied() {
let expected_head = T::modal_variant(T::ALL);
assert_eq!(
Some(head),
expected_head,
"{type_name}: T::modal_variants(T::ALL).first() drifted from T::modal_variant(T::ALL) — the plural's HEAD MUST equal the singular's first-witness commit because both walk T::ALL in declaration order and commit at the first tied argmax; a divergence catches an override that reorders the witnesses on the plural side without threading through the same declaration-order argmax walk the singular pins",
);
}
// (128) — `T::sorted_modal_variants(items)` MUST agree with the
// lex-order-preserving argmax witness-collection over the
// [`T::variant_counts`] histogram on every slice AND MUST land on
// its THREE canonical fixpoints (empty vector on the empty slice
// UNCONDITIONALLY, `T::sorted_variants()` on the full-set slice
// UNCONDITIONALLY, `T::sorted_variants()` on the doubled-full-set
// slice UNCONDITIONALLY). The three fixpoints partition the
// failure modes at the (Vec-shape × ordering × slice-shape) corner
// simultaneously: an override that omits the empty-slice guard
// fires on the empty-slice arm (returns `T::sorted_variants()`
// rather than the empty vector past the (max == 0, every-count ==
// 0) degenerate arm where every variant hits `count == 0 == max`);
// an override that folds onto the empty vector unconditionally
// fires on the full-set + doubled-full-set arms; an override that
// walks [`T::ALL`] instead of [`T::sorted_variants`] fires on the
// full-set + doubled-full-set arms when `T::first() !=
// T::sorted_first()` (returns `T::ALL.to_vec()` rather than
// `T::sorted_variants()`, bifurcating the lex-order walk); an
// override that returns a Vec whose FIRST element disagrees with
// [`T::sorted_modal_variant`] on the full-set slice fires at the
// composition-equality arm against
// `T::sorted_modal_variant(T::ALL) == Some(T::sorted_first())`.
//
// Sibling posture to clause (127) one ORDERING axis over: clause
// (127) opens the (set-level × `Vec<Self>` × statistical-aggregate
// × declaration-order × argmax) COMPLETE-WITNESS corner via
// [`T::modal_variants`]; this clause CLOSES the (set-level ×
// `Vec<Self>` × statistical-aggregate × ordering × argmax)
// 2-corner face at its lex-arm via [`T::sorted_modal_variants`].
// Combined with the sibling (clause (123), clause (124)) closure
// one RETURN-SHAPE axis over on the (set-level × `Option<Self>` ×
// statistical-aggregate × argmax × ordering) 2-corner face, the
// (set-level × {`Option<Self>`, `Vec<Self>`} × statistical-
// aggregate × argmax × ordering) 2×2 = 4-corner face on the
// direction-anchor argmax arm now closes at every corner. The
// default trait body threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().filter(|&v|
// T::count_occurrences_of(v, items) == T::max_variant_count(items))
// .collect()` sweep verbatim and satisfies every fixpoint arm +
// the composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the lex-order argmax witness-
// collection surface every downstream alphabetic-mode consumer
// routes through.
let sorted_all = T::sorted_variants();
assert_eq!(
T::sorted_modal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_modal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because every per-variant occurrence count collapses to 0 and an UNGUARDED T::sorted_variants().into_iter().filter(|v| count(v) == 0).collect() sweep would silently return T::sorted_variants() past the (max == 0, every-count == 0) degenerate arm where every variant satisfies `count == max == 0`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order argmax witness-collection consumer routes through",
);
let full_sorted_modal_variants = T::sorted_modal_variants(T::ALL);
assert_eq!(
full_sorted_modal_variants.len(),
T::CARDINALITY,
"{type_name}: T::sorted_modal_variants(T::ALL).len() == {actual_len} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and the argmax witness-collection filter over T::sorted_variants() hits EVERY variant (the flat-histogram fixpoint pins the direction-axis degeneracy at every corner); a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR that returns a proper subset of T::sorted_variants() on the full set",
actual_len = full_sorted_modal_variants.len(),
cardinality = T::CARDINALITY,
);
assert_eq!(
full_sorted_modal_variants,
sorted_all,
"{type_name}: T::sorted_modal_variants(T::ALL) drifted from T::sorted_variants() element-for-element — the lex-order-preserving argmax witness-collection MUST equal T::sorted_variants() on the full-set slice because every variant hits count == max == 1 and the filter walks T::sorted_variants() in lex order; a divergence is the drift catch for an override that walks T::ALL instead of T::sorted_variants (declaration-order-canonical would return T::ALL.to_vec(), bifurcating the lex-order walk when T::first() != T::sorted_first())",
);
let doubled_sorted_modal_variants = T::sorted_modal_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_modal_variants,
sorted_all,
"{type_name}: T::sorted_modal_variants(&doubled_full_set) drifted from T::sorted_variants() element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::max_variant_count(doubled) == 2, and the filter hits EVERY variant walked in lex order; a divergent doubled-full-set value silently bifurcates the lex-order flat-histogram fixpoint contract every downstream complete-mode consumer routes through",
);
if let Some(head) = full_sorted_modal_variants.first().copied() {
let expected_head = T::sorted_modal_variant(T::ALL);
assert_eq!(
Some(head),
expected_head,
"{type_name}: T::sorted_modal_variants(T::ALL).first() drifted from T::sorted_modal_variant(T::ALL) — the plural's HEAD MUST equal the singular's first-witness commit because both walk T::sorted_variants() in lex order and commit at the first tied argmax; a divergence catches an override that reorders the witnesses on the plural side without threading through the same lex-order argmax walk the singular pins",
);
}
// (129) — `T::antimodal_variants(items)` MUST agree with the
// declaration-order-preserving argmin witness-collection over the
// [`T::variant_counts`] histogram on every slice AND MUST land on
// its THREE canonical fixpoints (empty vector on the empty slice
// UNCONDITIONALLY, `T::ALL.to_vec()` on the full-set slice
// UNCONDITIONALLY, `T::ALL.to_vec()` on the doubled-full-set slice
// UNCONDITIONALLY — the last two anchored by the flat-histogram
// fixpoint's direction-axis degeneracy where argmin == argmax at
// every corner). The three fixpoints partition the failure modes
// at the (Vec-shape × slice-shape) corner simultaneously: an
// override that omits the empty-slice guard fires on the empty-
// slice arm (returns `T::ALL.to_vec()` rather than the empty
// vector past the (min == 0, every-count == 0) degenerate arm
// where every variant hits `count == 0 == min`); an override that
// folds onto the empty vector unconditionally fires on the
// full-set + doubled-full-set arms (both flat-histogram fixpoints
// hit every variant); an override that returns a proper subset of
// T::ALL on the full set (e.g. only the first variant) fires on
// the full-set arm because clause (3)'s pairwise-distinctness pins
// every variant at count `1 == min`; an override that returns a
// Vec of the wrong length on any flat-histogram slice bifurcates
// loudly at the length arm; an override that returns a Vec whose
// FIRST element disagrees with [`T::antimodal_variant`] on the
// full-set slice fires at the composition-equality arm against
// `T::antimodal_variant(T::ALL) == Some(T::first())` (on the flat-
// histogram fixpoint the direction axis collapses so argmin and
// argmax agree at the same first-witness).
//
// Sibling posture to clause (127) one DIRECTION axis over: clause
// (127) opens the (set-level × `Vec<Self>` × statistical-aggregate
// × declaration-order × argmax) COMPLETE-WITNESS corner via
// [`T::modal_variants`]; this clause opens the (set-level ×
// `Vec<Self>` × statistical-aggregate × declaration-order ×
// argmin) COMPLETE-WITNESS corner one DIRECTION axis over via
// [`T::antimodal_variants`]. The (return-shape × direction ×
// ordering) 2×2×2 = 8-corner cube on the direction-anchor face
// now opens THREE of its FOUR remaining corners (argmax
// declaration, argmax lex, argmin declaration); the final corner
// — sorted_antimodal_variants (Vec<Self>, argmin, lex) — closes
// the entire cube at its final corner. Sibling posture to clause
// (125) one RETURN-SHAPE axis over: clause (125) pins the
// (`Option<Self>`, argmin, declaration) first-witness corner via
// [`T::antimodal_variant`]; this clause pins the (`Vec<Self>`,
// argmin, declaration) complete-witness corner one RETURN-SHAPE
// axis over via [`T::antimodal_variants`], and pins its head-
// composition-equality arm through the singular's first-witness
// commit on the full-set fixpoint. The default trait body threads
// the `is_empty()`-guarded
// `T::ALL.iter().copied().filter(|&v|
// T::count_occurrences_of(v, items) == T::min_variant_count(items))
// .collect()` sweep verbatim and satisfies every fixpoint arm +
// the composition-equality arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the declaration-order argmin
// witness-collection surface every downstream complete-antimode
// consumer routes through.
assert_eq!(
T::antimodal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::antimodal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because every per-variant occurrence count collapses to 0 and an UNGUARDED T::ALL.iter().copied().filter(|v| count(v) == 0).collect() sweep would silently return T::ALL.to_vec() past the (min == 0, every-count == 0) degenerate arm where every variant satisfies `count == min == 0`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream declaration-order argmin witness-collection consumer routes through",
);
let full_antimodal_variants = T::antimodal_variants(T::ALL);
assert_eq!(
full_antimodal_variants.len(),
T::CARDINALITY,
"{type_name}: T::antimodal_variants(T::ALL).len() == {actual_len} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and the argmin witness-collection filter hits EVERY variant of T::ALL (the flat-histogram fixpoint pins the direction-axis degeneracy at every corner — argmin and argmax coincide); a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR that returns a proper subset of T::ALL on the full set",
actual_len = full_antimodal_variants.len(),
cardinality = T::CARDINALITY,
);
assert_eq!(
full_antimodal_variants.as_slice(),
T::ALL,
"{type_name}: T::antimodal_variants(T::ALL) drifted from T::ALL element-for-element — the declaration-order-preserving argmin witness-collection MUST equal T::ALL on the full-set slice because every variant hits count == min == 1 and the filter walks T::ALL in declaration order; an ordering divergence is the drift catch for an override that reorders the witnesses via `T::sorted_variants` or via any other non-declaration walk",
);
let doubled_antimodal_variants = T::antimodal_variants(&doubled_full_set);
assert_eq!(
doubled_antimodal_variants.as_slice(),
T::ALL,
"{type_name}: T::antimodal_variants(&doubled_full_set) drifted from T::ALL element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::min_variant_count(doubled) == 2, and the filter hits EVERY variant of T::ALL in declaration order; a divergent doubled-full-set value silently bifurcates the declaration-order flat-histogram fixpoint contract every downstream complete-antimode consumer routes through",
);
if let Some(head) = full_antimodal_variants.first().copied() {
let expected_head = T::antimodal_variant(T::ALL);
assert_eq!(
Some(head),
expected_head,
"{type_name}: T::antimodal_variants(T::ALL).first() drifted from T::antimodal_variant(T::ALL) — the plural's HEAD MUST equal the singular's first-witness commit because both walk T::ALL in declaration order and commit at the first tied argmin; a divergence catches an override that reorders the witnesses on the plural side without threading through the same declaration-order argmin walk the singular pins",
);
}
// (130) — `T::sorted_antimodal_variants(items)` MUST agree with the
// lex-order-preserving argmin witness-collection over the
// [`T::variant_counts`] histogram on every slice AND MUST land on
// its THREE canonical fixpoints (empty vector on the empty slice
// UNCONDITIONALLY, `T::sorted_variants()` on the full-set slice
// UNCONDITIONALLY, `T::sorted_variants()` on the doubled-full-set
// slice UNCONDITIONALLY — the last two anchored by the flat-
// histogram fixpoint's direction-axis degeneracy where argmin ==
// argmax at every corner at the lex-ordering arm). The three
// fixpoints partition the failure modes at the (Vec-shape × ordering
// × slice-shape) corner simultaneously: an override that omits the
// empty-slice guard fires on the empty-slice arm (returns
// `T::sorted_variants()` rather than the empty vector past the (min
// == 0, every-count == 0) degenerate arm where every variant hits
// `count == 0 == min`); an override that folds onto the empty vector
// unconditionally fires on the full-set + doubled-full-set arms
// (both flat-histogram fixpoints hit every variant); an override
// that walks [`T::ALL`] instead of [`T::sorted_variants`] fires on
// the full-set + doubled-full-set arms when `T::first() !=
// T::sorted_first()` (returns `T::ALL.to_vec()` rather than
// `T::sorted_variants()`, bifurcating the lex-order walk); an
// override that returns a Vec whose FIRST element disagrees with
// [`T::sorted_antimodal_variant`] on the full-set slice fires at the
// composition-equality arm against
// `T::sorted_antimodal_variant(T::ALL) == Some(T::sorted_first())`
// (on the flat-histogram fixpoint the direction axis collapses so
// argmin and argmax agree at the same lex-order-first witness).
//
// Sibling posture to clause (128) one DIRECTION axis over: clause
// (128) closes the (set-level × `Vec<Self>` × statistical-aggregate
// × ordering × argmax) 2-corner face at its lex-arm via
// [`T::sorted_modal_variants`]; this clause CLOSES the (set-level ×
// `Vec<Self>` × statistical-aggregate × ordering × argmin) 2-corner
// face at its lex-arm one DIRECTION axis over via
// [`T::sorted_antimodal_variants`]. Sibling posture to clause (129)
// one ORDERING axis over: clause (129) opens the (set-level ×
// `Vec<Self>` × statistical-aggregate × declaration-order × argmin)
// COMPLETE-WITNESS corner via [`T::antimodal_variants`]; this clause
// CLOSES the (set-level × `Vec<Self>` × statistical-aggregate ×
// ordering × argmin) 2-corner face at its lex-arm one ORDERING axis
// over via [`T::sorted_antimodal_variants`]. Combined with the four
// Vec-return corners already pinned by clauses (127), (128), (129),
// this lift CLOSES the (return-shape × direction × ordering) 2×2×2
// = 8-corner Vec-return cube on the direction-anchor face at its
// final (Vec<Self>, argmin, lex) corner; PARALLELING the four
// (Option<Self>, {argmax, argmin}, {declaration, lex}) corners
// pinned by clauses (123), (124), (125), (126). The default trait
// body threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().filter(|&v|
// T::count_occurrences_of(v, items) == T::min_variant_count(items))
// .collect()` sweep verbatim and satisfies every fixpoint arm + the
// composition-equality arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order argmin witness-collection
// surface every downstream alphabetic-antimode consumer routes
// through.
assert_eq!(
T::sorted_antimodal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_antimodal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because every per-variant occurrence count collapses to 0 and an UNGUARDED T::sorted_variants().into_iter().filter(|v| count(v) == 0).collect() sweep would silently return T::sorted_variants() past the (min == 0, every-count == 0) degenerate arm where every variant satisfies `count == min == 0`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order argmin witness-collection consumer routes through",
);
let full_sorted_antimodal_variants = T::sorted_antimodal_variants(T::ALL);
assert_eq!(
full_sorted_antimodal_variants.len(),
T::CARDINALITY,
"{type_name}: T::sorted_antimodal_variants(T::ALL).len() == {actual_len} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and the argmin witness-collection filter over T::sorted_variants() hits EVERY variant (the flat-histogram fixpoint pins the direction-axis degeneracy at the lex-ordering arm — argmin and argmax coincide); a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR that returns a proper subset of T::sorted_variants() on the full set",
actual_len = full_sorted_antimodal_variants.len(),
cardinality = T::CARDINALITY,
);
assert_eq!(
full_sorted_antimodal_variants,
sorted_all,
"{type_name}: T::sorted_antimodal_variants(T::ALL) drifted from T::sorted_variants() element-for-element — the lex-order-preserving argmin witness-collection MUST equal T::sorted_variants() on the full-set slice because every variant hits count == min == 1 and the filter walks T::sorted_variants() in lex order; a divergence is the drift catch for an override that walks T::ALL instead of T::sorted_variants (declaration-order-canonical would return T::ALL.to_vec(), bifurcating the lex-order walk when T::first() != T::sorted_first())",
);
let doubled_sorted_antimodal_variants = T::sorted_antimodal_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_antimodal_variants,
sorted_all,
"{type_name}: T::sorted_antimodal_variants(&doubled_full_set) drifted from T::sorted_variants() element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, T::min_variant_count(doubled) == 2, and the filter hits EVERY variant walked in lex order; a divergent doubled-full-set value silently bifurcates the lex-order flat-histogram fixpoint contract every downstream complete-antimode consumer routes through",
);
if let Some(head) = full_sorted_antimodal_variants.first().copied() {
let expected_head = T::sorted_antimodal_variant(T::ALL);
assert_eq!(
Some(head),
expected_head,
"{type_name}: T::sorted_antimodal_variants(T::ALL).first() drifted from T::sorted_antimodal_variant(T::ALL) — the plural's HEAD MUST equal the singular's first-witness commit because both walk T::sorted_variants() in lex order and commit at the first tied argmin; a divergence catches an override that reorders the witnesses on the plural side without threading through the same lex-order argmin walk the singular pins",
);
}
// (131) — `T::count_modal_variants(items)` MUST agree with the
// filter-count reduction over `T::ALL` of the (`count(v) ==
// T::max_variant_count(items)`) direction-anchor predicate on every
// slice AND MUST land on its FOUR canonical fixpoints (`0` on the
// empty slice UNCONDITIONALLY, `T::CARDINALITY` on the full-set
// slice UNCONDITIONALLY, `T::CARDINALITY` on the doubled-full-set
// slice UNCONDITIONALLY — the last two anchored by the flat-
// histogram fixpoint's uniform per-variant multiplicity where every
// variant contributes to the argmax filter, `1` on every matching-
// singleton `[target]` slice — the sole variant with a strictly-
// positive count on a singleton) AND on ONE composition-equality
// arm on the full-set fixpoint: length-composition against
// `T::modal_variants(T::ALL).len()`.
//
// The four fixpoints + one composition arm partition failure modes
// at the (scalar × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `T::CARDINALITY`
// unconditionally fires on the empty-slice arm (returns
// `T::CARDINALITY` rather than `0` past the (max == 0, every-count
// == 0) degenerate arm where an unguarded sweep would silently
// return `T::CARDINALITY` because every variant satisfies the
// vacuous `0 == 0` predicate); an override that folds onto `0`
// unconditionally fires on the full-set + doubled-full-set arms
// (both flat-histogram fixpoints pin the modal-set at full
// cardinality); an override that returns `0` on a matching-singleton
// fires on the singleton arm (the sole variant satisfies `count ==
// max == 1`); an override that detaches from the length-composition
// on the full-set slice bifurcates loudly at the composition-arm
// against `T::modal_variants(T::ALL).len() == T::CARDINALITY`.
//
// Sibling posture to clause (127) one RETURN-SHAPE axis over:
// clause (127) pins the (set-level × `Vec<Self>` × statistical-
// aggregate × direction × argmax) COMPLETE-WITNESS corner via
// [`T::modal_variants`]; this clause pins the (set-level × `usize`
// × statistical-aggregate × direction × argmax) CARDINALITY-COUNT
// corner one RETURN-SHAPE axis over via [`T::count_modal_variants`]
// (`Vec<Self>` witness → `usize` cardinality via the trivial
// `.len()` sharpening). Sibling posture to clauses (85), (115),
// (116) [count_missing, count_unique_variants,
// count_repeating_variants on the multiplicity-band trichotomy] one
// AGGREGATION-KIND axis over: those clauses pin the (`usize`, set-
// level, mult == 0 / == 1 / >= 2) cardinality-count corners at each
// multiplicity band; this clause pins the (`usize`, set-level,
// direction-anchor `argmax`) cardinality-count corner ONE AGGREGATION
// -KIND axis over (multiplicity-band → direction-anchor
// bifurcation). The default trait body threads the `is_empty()`-
// guarded `T::ALL.iter().copied().filter(|&v|
// T::count_occurrences_of(v, items) == T::max_variant_count(items))
// .count()` sweep verbatim and satisfies every fixpoint arm + the
// length-composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the direction-anchor cardinality-count
// surface every downstream mode-tie-count consumer routes through.
assert_eq!(
T::count_modal_variants(empty),
0,
"{type_name}: T::count_modal_variants(&[]) != 0 — the set-level modal-tie count MUST report `0` on the empty slice because T::max_variant_count(&[]) == 0 and an UNGUARDED T::ALL.iter().filter(|v| count(v) == 0).count() sweep would silently return T::CARDINALITY past the (max == 0, every-count == 0) degenerate arm where every variant satisfies the vacuous `0 == 0` predicate; a non-`0` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream mode-tie-count consumer routes through",
);
let full_modal_count = T::count_modal_variants(T::ALL);
assert_eq!(
full_modal_count,
T::CARDINALITY,
"{type_name}: T::count_modal_variants(T::ALL) == {full_modal_count} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and every variant satisfies `count == max`; a shorter count is the drift catch for an override that folds onto `0` unconditionally OR that under-counts on the flat-histogram fixpoint where the direction-axis degeneracy pins the modal-set at full cardinality",
cardinality = T::CARDINALITY,
);
let doubled_modal_count = T::count_modal_variants(&doubled_full_set);
assert_eq!(
doubled_modal_count,
T::CARDINALITY,
"{type_name}: T::count_modal_variants(&doubled_full_set) == {doubled_modal_count} != T::CARDINALITY == {cardinality} — the doubled full set hits every variant at EXACTLY TWO positions, every per-variant count is 2, T::max_variant_count(doubled) == 2, and every variant satisfies `count == max`; together with the full-set arm, the doubled-full-set arm pins the projection as INVARIANT under uniform slice-multiplication on flat-histogram slices — a MODAL-TIE cardinality rather than the modal-multiplicity scalar T::max_variant_count which TRANSITIONS from 1 to 2 between the two flat-histogram fixpoints",
cardinality = T::CARDINALITY,
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_modal_count = T::count_modal_variants(&matching_singleton);
assert_eq!(
singleton_modal_count,
1,
"{type_name}: T::count_modal_variants([{target_label:?}]) == {singleton_modal_count} != 1 — the sole position hits the target, T::max_variant_count([{target_label:?}]) == 1, and only the target satisfies `count == max` (the other variants have count `0`, failing the predicate); a divergent value silently bifurcates the matching-singleton fixpoint contract every downstream mode-tie-count consumer routes through",
);
}
let expected_full_modal_count_via_len = T::modal_variants(T::ALL).len();
assert_eq!(
full_modal_count, expected_full_modal_count_via_len,
"{type_name}: T::count_modal_variants(T::ALL) drifted from T::modal_variants(T::ALL).len() — the set-level modal-tie count MUST equal the length of the declaration-order-preserving argmax witness-collection on every slice, so a downstream mode-tie-count consumer that binds `T::modal_variants(items).len()` as its scalar cardinality query surface would disagree with the pinned count",
);
// (132) — `T::count_antimodal_variants(items)` MUST agree with the
// filter-count reduction over `T::ALL` of the (`count(v) ==
// T::min_variant_count(items)`) direction-anchor predicate on every
// slice AND MUST land on its FOUR canonical fixpoints (`0` on the
// empty slice UNCONDITIONALLY, `T::CARDINALITY` on the full-set
// slice UNCONDITIONALLY, `T::CARDINALITY` on the doubled-full-set
// slice UNCONDITIONALLY — the last two anchored by the flat-
// histogram fixpoint's uniform per-variant multiplicity where every
// variant contributes to the argmin filter, `T::CARDINALITY - 1` on
// every matching-singleton `[target]` slice AT CARDINALITY `>= 2`
// — the target hits `count == 1 == max` and every non-target
// variant hits `count == 0 == min`, so the argmin filter hits every
// non-target variant) AND on ONE composition-equality arm on the
// full-set fixpoint: length-composition against
// `T::antimodal_variants(T::ALL).len()`.
//
// The four fixpoints + one composition arm partition failure modes
// at the (scalar × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `T::CARDINALITY`
// unconditionally fires on the empty-slice arm (returns
// `T::CARDINALITY` rather than `0` past the (min == 0, every-count
// == 0) degenerate arm where an unguarded sweep would silently
// return `T::CARDINALITY` because every variant satisfies the
// vacuous `0 == 0` predicate); an override that folds onto `0`
// unconditionally fires on the full-set + doubled-full-set arms
// (both flat-histogram fixpoints pin the antimodal-set at full
// cardinality); an override that MIRRORS the argmax singleton
// fixpoint (`1` on every singleton) onto the argmin corner
// BIFURCATES loudly on the (min-arm × singleton) endpoint at
// cardinality `>= 2` — the argmax singleton contract yields `1`
// (only the target hits `count == max == 1`) but the argmin
// singleton contract yields `T::CARDINALITY - 1` (every non-target
// hits `count == 0 == min`), a load-bearing asymmetry the singleton
// arm catches; an override that detaches from the length-composition
// on the full-set slice bifurcates loudly at the composition-arm
// against `T::antimodal_variants(T::ALL).len() == T::CARDINALITY`.
//
// Sibling posture to clause (131) one DIRECTION axis over: clause
// (131) pins the (set-level × `usize` × statistical-aggregate ×
// direction × argmax) CARDINALITY-COUNT corner via
// [`T::count_modal_variants`]; this clause CLOSES the (set-level ×
// `usize` × statistical-aggregate × direction) 2-corner
// cardinality-count face at its argmin arm via
// [`T::count_antimodal_variants`]. Combined with the sibling closure
// one RETURN-SHAPE axis over on the (set-level × `Vec<Self>` ×
// statistical-aggregate × direction) 2-corner complete-witness face
// via clauses (127) + (129) ([`T::modal_variants`],
// [`T::antimodal_variants`]), the (set-level × {`usize`,
// `Vec<Self>`} × statistical-aggregate × direction) 2×2 = 4-corner
// (return-shape × direction) face on the declaration-order arm now
// closes at every corner. The default trait body threads the
// `is_empty()`-guarded `T::ALL.iter().copied().filter(|&v|
// T::count_occurrences_of(v, items) == T::min_variant_count(items))
// .count()` sweep verbatim and satisfies every fixpoint arm + the
// length-composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the direction-anchor cardinality-count
// surface every downstream antimode-tie-count consumer routes
// through.
assert_eq!(
T::count_antimodal_variants(empty),
0,
"{type_name}: T::count_antimodal_variants(&[]) != 0 — the set-level antimodal-tie count MUST report `0` on the empty slice because T::min_variant_count(&[]) == 0 and an UNGUARDED T::ALL.iter().filter(|v| count(v) == 0).count() sweep would silently return T::CARDINALITY past the (min == 0, every-count == 0) degenerate arm where every variant satisfies the vacuous `0 == 0` predicate; a non-`0` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream antimode-tie-count consumer routes through",
);
let full_antimodal_count = T::count_antimodal_variants(T::ALL);
assert_eq!(
full_antimodal_count,
T::CARDINALITY,
"{type_name}: T::count_antimodal_variants(T::ALL) == {full_antimodal_count} != T::CARDINALITY == {cardinality} — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and every variant satisfies `count == min`; a shorter count is the drift catch for an override that folds onto `0` unconditionally OR that under-counts on the flat-histogram fixpoint where the direction-axis degeneracy pins the antimodal-set at full cardinality",
cardinality = T::CARDINALITY,
);
let doubled_antimodal_count = T::count_antimodal_variants(&doubled_full_set);
assert_eq!(
doubled_antimodal_count,
T::CARDINALITY,
"{type_name}: T::count_antimodal_variants(&doubled_full_set) == {doubled_antimodal_count} != T::CARDINALITY == {cardinality} — the doubled full set hits every variant at EXACTLY TWO positions, every per-variant count is 2, T::min_variant_count(doubled) == 2, and every variant satisfies `count == min`; together with the full-set arm, the doubled-full-set arm pins the projection as INVARIANT under uniform slice-multiplication on flat-histogram slices — an ANTIMODAL-TIE cardinality rather than the antimodal-multiplicity scalar T::min_variant_count which TRANSITIONS from 1 to 2 between the two flat-histogram fixpoints",
cardinality = T::CARDINALITY,
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_antimodal_count = T::count_antimodal_variants(&matching_singleton);
assert_eq!(
singleton_antimodal_count,
T::CARDINALITY - 1,
"{type_name}: T::count_antimodal_variants([{target_label:?}]) == {singleton_antimodal_count} != T::CARDINALITY - 1 == {expected} — the sole position hits the target with count `1`, every non-target variant has count `0 == min`, and the (`count == min`) filter hits every non-target variant (the LOAD-BEARING ASYMMETRY against T::count_modal_variants which returns `1` on the same singleton because only the target hits `count == max == 1`); a value of `1` is the drift catch for an override that mirrors the argmax singleton fixpoint onto the argmin corner",
expected = T::CARDINALITY - 1,
);
}
}
let expected_full_antimodal_count_via_len = T::antimodal_variants(T::ALL).len();
assert_eq!(
full_antimodal_count, expected_full_antimodal_count_via_len,
"{type_name}: T::count_antimodal_variants(T::ALL) drifted from T::antimodal_variants(T::ALL).len() — the set-level antimodal-tie count MUST equal the length of the declaration-order-preserving argmin witness-collection on every slice, so a downstream antimode-tie-count consumer that binds `T::antimodal_variants(items).len()` as its scalar cardinality query surface would disagree with the pinned count",
);
// (133) — `T::is_modal_variant_of(target, items)` MUST agree with the
// non-emptiness-guarded strict-equality test of
// `T::count_occurrences_of(target, items)` against
// `T::max_variant_count(items)` on every (target, slice) pair AND MUST
// land on its FOUR canonical fixpoints (`false` on the empty slice at
// EVERY target UNCONDITIONALLY, `true` on the matching singleton `[v]`
// at target `v`, `true` on the full-set slice at EVERY target
// UNCONDITIONALLY, `true` on the doubled-full-set slice at EVERY target
// UNCONDITIONALLY — the last two anchored by the flat-histogram
// fixpoint's uniform per-variant multiplicity where every target
// satisfies `count == max`) AND on ONE composition-equality arm on the
// full-set fixpoint: cardinality-count against
// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_modal_variant_of(v, T::ALL)).count() == T::count_modal_variants(T::ALL) == T::CARDINALITY`.
//
// The four fixpoints + one composition arm partition failure modes at
// the (per-target × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice arm (returns `true` rather than `false` past
// the (max == 0, every-count == 0) degenerate arm where an unguarded
// strict-equality test against `0` would silently return `true` at
// every target); an override that folds onto `false` unconditionally
// fires on the matching-singleton arm (returns `false` rather than
// `true` at the target's sole hit) AND on both flat-histogram fixpoint
// arms (which pin the projection at `true` for every target); an
// override that detaches from the cardinality-count on the full-set
// slice bifurcates loudly at the composition-arm against
// `T::count_modal_variants(T::ALL) == T::CARDINALITY`.
//
// Sibling posture to clauses (131) + (132) one ARITY axis over: those
// clauses pin the (set-level × usize × statistical-aggregate ×
// direction × {argmax, argmin}) cardinality-count corners via
// [`T::count_modal_variants`] + [`T::count_antimodal_variants`]; this
// clause OPENS the (per-target × bool × statistical-aggregate ×
// direction × argmax) corner via [`T::is_modal_variant_of`] one arity
// axis over on the (arity × statistical-aggregate) face — a per-
// target atomic bool contribution to the set-level cardinality-count
// aggregate. The default trait body threads the non-emptiness-guarded
// `T::count_occurrences_of(target, items) == T::max_variant_count(items)`
// test verbatim and satisfies every fixpoint arm + the cardinality-
// count composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather than
// silently bifurcating the per-target modal-membership surface every
// downstream mode-membership consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_modal_variant_of(target, empty),
"{type_name}: T::is_modal_variant_of({target_label:?}, &[]) != false — the per-target modal-membership predicate MUST report `false` on the empty slice at every target because T::max_variant_count(&[]) == 0 and an UNGUARDED strict-equality test against `0` would silently return `true` for every target past the (max == 0, every-count == 0) degenerate arm; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream mode-membership consumer routes through",
);
let matching_singleton = [target];
assert!(
T::is_modal_variant_of(target, &matching_singleton),
"{type_name}: T::is_modal_variant_of({target_label:?}, [{target_label:?}]) != true — the sole position hits the target, T::max_variant_count([{target_label:?}]) == 1, and the target satisfies `count == max == 1`; a `false` singleton-arm value silently bifurcates the matching-singleton fixpoint contract every downstream mode-membership consumer routes through",
);
assert!(
T::is_modal_variant_of(target, T::ALL),
"{type_name}: T::is_modal_variant_of({target_label:?}, T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == 1, and every target satisfies `count == max`; a `false` full-set arm silently bifurcates the flat-histogram fixpoint contract",
);
assert!(
T::is_modal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_modal_variant_of({target_label:?}, &doubled_full_set) != true — the doubled full set hits every variant at EXACTLY TWO positions, every per-variant count is 2, T::max_variant_count(doubled) == 2, and every target satisfies `count == max`; together with the full-set arm, the doubled-full-set arm pins the projection as INVARIANT under uniform slice-multiplication on flat-histogram slices — a `false` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
let full_modal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_modal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_modal_membership_count,
T::count_modal_variants(T::ALL),
"{type_name}: T::ALL.iter().filter(|v| T::is_modal_variant_of(*v, T::ALL)).count() == {full_modal_membership_count} drifted from T::count_modal_variants(T::ALL) — the per-target modal-membership predicate's set-level cardinality-count MUST equal the just-lifted set-level modal-tie count aggregate; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_modal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level cardinality-count would disagree with the pinned aggregate",
);
// (134) — `T::is_antimodal_variant_of(target, items)` MUST agree with
// the non-emptiness-guarded strict-equality test of
// `T::count_occurrences_of(target, items)` against
// `T::min_variant_count(items)` on every (target, slice) pair AND MUST
// land on its FOUR canonical fixpoints (`false` on the empty slice at
// EVERY target UNCONDITIONALLY, `false` on the matching singleton
// `[v]` at target `v` at cardinality `>= 2`, `true` on the full-set
// slice at EVERY target UNCONDITIONALLY, `true` on the doubled-full-
// set slice at EVERY target UNCONDITIONALLY — the last two anchored
// by the flat-histogram fixpoint's uniform per-variant multiplicity
// where every target satisfies `count == min == max` under the
// direction-axis degeneracy on flat histograms) AND on ONE
// composition-equality arm on the full-set fixpoint: cardinality-
// count against
// `<T as ClosedSet>::ALL.iter().copied().filter(|&v| T::is_antimodal_variant_of(v, T::ALL)).count() == T::count_antimodal_variants(T::ALL) == T::CARDINALITY`.
//
// The four fixpoints + one composition arm partition failure modes at
// the (per-target × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice arm (returns `true` rather than `false`
// past the (min == 0, every-count == 0) degenerate arm where an
// unguarded strict-equality test against `0` would silently return
// `true` at every target) AND on the matching-singleton arm at
// cardinality `>= 2` (returns `true` at the target rather than
// `false`, mirroring the argmax singleton onto the argmin arm and
// silently bifurcating the LOAD-BEARING asymmetry the per-target
// antimodal-membership predicate carries against its argmax peer);
// an override that folds onto `false` unconditionally fires on both
// flat-histogram fixpoint arms (which pin the projection at `true`
// for every target); an override that detaches from the cardinality-
// count on the full-set slice bifurcates loudly at the composition-
// arm against `T::count_antimodal_variants(T::ALL) == T::CARDINALITY`.
//
// Sibling posture to clauses (132) + (133) one DIRECTION axis over:
// clause (132) pins the (set-level × usize × statistical-aggregate ×
// direction × argmin) cardinality-count corner via
// [`T::count_antimodal_variants`]; clause (133) opens the (per-target
// × bool × statistical-aggregate × direction × argmax) corner via
// [`T::is_modal_variant_of`]; this clause CLOSES the (per-target ×
// bool × statistical-aggregate × direction) 2-corner face at its
// argmin arm past the argmax corner via [`T::is_antimodal_variant_of`]
// one DIRECTION axis over on the (arity × statistical-aggregate ×
// direction) face — a per-target atomic bool contribution to the
// set-level cardinality-count aggregate on the argmin arm. The
// default trait body threads the non-emptiness-guarded
// `T::count_occurrences_of(target, items) == T::min_variant_count(items)`
// test verbatim and satisfies every fixpoint arm + the cardinality-
// count composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather than
// silently bifurcating the per-target antimodal-membership surface
// every downstream antimode-membership consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_antimodal_variant_of(target, empty),
"{type_name}: T::is_antimodal_variant_of({target_label:?}, &[]) != false — the per-target antimodal-membership predicate MUST report `false` on the empty slice at every target because T::min_variant_count(&[]) == 0 and an UNGUARDED strict-equality test against `0` would silently return `true` for every target past the (min == 0, every-count == 0) degenerate arm; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream antimode-membership consumer routes through",
);
assert!(
T::is_antimodal_variant_of(target, T::ALL),
"{type_name}: T::is_antimodal_variant_of({target_label:?}, T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::min_variant_count(T::ALL) == 1, and every target satisfies `count == min`; a `false` full-set arm silently bifurcates the flat-histogram fixpoint contract where the direction-axis degeneracy pins the argmin and argmax arms coincident",
);
assert!(
T::is_antimodal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_antimodal_variant_of({target_label:?}, &doubled_full_set) != true — the doubled full set hits every variant at EXACTLY TWO positions, every per-variant count is 2, T::min_variant_count(doubled) == 2, and every target satisfies `count == min`; together with the full-set arm, the doubled-full-set arm pins the projection as INVARIANT under uniform slice-multiplication on flat-histogram slices — a `false` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_antimodal_variant_of(target, &matching_singleton),
"{type_name}: T::is_antimodal_variant_of({target_label:?}, [{target_label:?}]) != false — the sole position hits the target with count `1`, every non-target variant has count `0`, and T::min_variant_count([{target_label:?}]) == 0 at cardinality >= 2; the target's count `1 != 0 == min` fails the predicate (the LOAD-BEARING ASYMMETRY against T::is_modal_variant_of which returns `true` on the same (target, singleton) pair because only the target hits `count == max == 1`); a `true` singleton-arm value at the target silently bifurcates the matching-singleton fixpoint and mirrors the argmax singleton onto the argmin corner",
);
}
}
let full_antimodal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_antimodal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_antimodal_membership_count,
T::count_antimodal_variants(T::ALL),
"{type_name}: T::ALL.iter().filter(|v| T::is_antimodal_variant_of(*v, T::ALL)).count() == {full_antimodal_membership_count} drifted from T::count_antimodal_variants(T::ALL) — the per-target antimodal-membership predicate's set-level cardinality-count MUST equal the just-lifted set-level antimodal-tie count aggregate; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_antimodal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level cardinality-count would disagree with the pinned aggregate",
);
// (135) — `T::has_unique_mode(items)` MUST agree with the strict-
// equality test of `T::count_modal_variants(items)` against `1` on
// every slice AND MUST land on its FOUR canonical fixpoints (`false`
// on the empty slice UNCONDITIONALLY, `true` on every matching
// singleton `[v]` UNCONDITIONALLY, `false` on the full-set slice at
// cardinality `>= 2`, `false` on the doubled-full-set slice at
// cardinality `>= 2` — the last two anchored by the flat-histogram
// fixpoint where every variant ties for the mode, so the modal-tie
// count reaches `T::CARDINALITY >= 2 != 1`) AND on ONE composition-
// equality arm on the full-set fixpoint: modal-witness length
// against `T::has_unique_mode(items) == (T::modal_variants(items).len() == 1)`.
//
// The four fixpoints + one composition arm partition failure modes
// at the (set-level × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `true` unconditionally
// fires on the empty-slice arm (returns `true` past the (count == 0
// != 1) fixpoint) AND on both flat-histogram fixpoint arms at
// cardinality `>= 2` (which pin the projection at `false` because
// every variant ties); an override that folds onto `false`
// unconditionally fires on every matching-singleton arm (returns
// `false` past the (count == 1) fixpoint where the sole target is
// the unique mode); an override that detaches from the modal-
// witness length on the full-set slice bifurcates loudly at the
// composition-arm against `T::modal_variants(T::ALL).len() ==
// T::CARDINALITY != 1` at cardinality `>= 2`.
//
// Sibling posture to clause (131) one RETURN-SHAPE axis over: clause
// (131) pins the (set-level × usize × statistical-aggregate ×
// direction × argmax) cardinality-count corner via
// [`T::count_modal_variants`]; this clause SHARPENS the same corner
// through the scalar-equality threshold against `1`, pinning the
// (set-level × bool × statistical-aggregate × direction × argmax ×
// unique-tie) predicate corner. The default trait body threads the
// `T::count_modal_variants(items) == 1` test verbatim and satisfies
// every fixpoint arm + the composition arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level modal-
// uniqueness surface every downstream mode-uniqueness consumer
// routes through.
assert!(
!T::has_unique_mode(empty),
"{type_name}: T::has_unique_mode(&[]) != false — the set-level modal-uniqueness predicate MUST report `false` on the empty slice because T::count_modal_variants(&[]) == 0 != 1; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream mode-uniqueness consumer routes through",
);
if T::CARDINALITY >= 2 {
assert!(
!T::has_unique_mode(T::ALL),
"{type_name}: T::has_unique_mode(T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, so every variant ties for the mode and T::count_modal_variants(T::ALL) == T::CARDINALITY >= 2 != 1; a `true` full-set arm silently bifurcates the flat-histogram fixpoint",
);
assert!(
!T::has_unique_mode(&doubled_full_set),
"{type_name}: T::has_unique_mode(&doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, every variant ties for the mode at count `2`, and T::count_modal_variants(doubled) == T::CARDINALITY >= 2 != 1; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
T::has_unique_mode(&matching_singleton),
"{type_name}: T::has_unique_mode([{target_label:?}]) != true — the sole position hits the target with count `1`, every non-target variant has count `0`, only the target satisfies `count == max == 1`, and T::count_modal_variants([{target_label:?}]) == 1; a `false` singleton arm silently bifurcates the matching-singleton fixpoint where every singleton has a unique mode",
);
}
let full_modal_witness_len = T::modal_variants(T::ALL).len();
assert_eq!(
T::has_unique_mode(T::ALL),
full_modal_witness_len == 1,
"{type_name}: T::has_unique_mode(T::ALL) drifted from (T::modal_variants(T::ALL).len() == 1) — the set-level modal-uniqueness predicate MUST equal the length-equality test of the declaration-order argmax witness-collection against `1`; a downstream consumer that binds `T::modal_variants(items).len() == 1` as its Vec-length surface for uniqueness would disagree with the pinned scalar test",
);
// (136) — `T::has_unique_antimode(items)` MUST agree with the strict-
// equality test of `T::count_antimodal_variants(items)` against `1`
// on every slice AND MUST land on its canonical fixpoints (`false`
// on the empty slice UNCONDITIONALLY, `false` on every matching
// singleton `[v]` at cardinality `>= 3` because
// `count_antimodal_variants([v]) == T::CARDINALITY - 1 >= 2 != 1`,
// `false` on the full-set slice at cardinality `>= 2`, `false` on
// the doubled-full-set slice at cardinality `>= 2` — the last two
// anchored by the flat-histogram fixpoint where every variant ties
// for the antimode, so the antimodal-tie count reaches
// `T::CARDINALITY >= 2 != 1`; `true` on the single-missing slice
// `T::ALL[..T::CARDINALITY - 1]` at cardinality `>= 2` — the omit-
// last fixture pins the argmin sweep at a UNIQUE antimode: every
// present variant hits count `1`, the omitted variant hits count
// `0 == min`, so ONLY the omitted variant lies on the argmin band
// and `count_antimodal_variants == 1`) AND on ONE composition-
// equality arm on the full-set fixpoint: antimodal-witness length
// against `T::has_unique_antimode(items) == (T::antimodal_variants(items).len() == 1)`.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (set-level × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm (returns `true` past
// the (count == 0 != 1) fixpoint) AND on both flat-histogram
// fixpoint arms at cardinality `>= 2` (which pin the projection at
// `false` because every variant ties); an override that folds onto
// `false` unconditionally fires on the single-missing arm at
// cardinality `>= 2` (returns `false` past the (only-omitted-
// variant, count == 1) fixpoint where exactly one variant lies on
// the argmin band); an override that mirrors the argmax singleton
// fixpoint onto the argmin corner fires at cardinality `>= 3` on
// every matching singleton (returns `true` past
// `count_antimodal_variants([v]) == CARDINALITY - 1 >= 2 != 1`); an
// override that detaches from the antimodal-witness length on the
// full-set slice bifurcates loudly at the composition arm against
// `T::antimodal_variants(T::ALL).len() == T::CARDINALITY != 1` at
// cardinality `>= 2`.
//
// Sibling posture to clause (135) one DIRECTION axis over: clause
// (135) pins the (set-level × bool × statistical-aggregate ×
// direction × argmax × unique-tie) corner via
// [`T::has_unique_mode`]; this clause CLOSES the (set-level × bool ×
// statistical-aggregate × direction × unique-tie) 2-corner face at
// the argmin arm past the argmax corner. Sibling posture to clause
// (132) one RETURN-SHAPE axis over: clause (132) pins the (set-level
// × usize × statistical-aggregate × direction × argmin) cardinality-
// count corner via [`T::count_antimodal_variants`]; this clause
// SHARPENS the same corner through the scalar-equality threshold
// against `1`, pinning the (set-level × bool × statistical-aggregate
// × direction × argmin × unique-tie) predicate corner. The default
// trait body threads the `T::count_antimodal_variants(items) == 1`
// test verbatim and satisfies every fixpoint arm + the composition
// arm for free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the set-level antimodal-uniqueness surface every
// downstream antimode-uniqueness consumer routes through.
assert!(
!T::has_unique_antimode(empty),
"{type_name}: T::has_unique_antimode(&[]) != false — the set-level antimodal-uniqueness predicate MUST report `false` on the empty slice because T::count_antimodal_variants(&[]) == 0 != 1; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream antimode-uniqueness consumer routes through",
);
if T::CARDINALITY >= 2 {
assert!(
!T::has_unique_antimode(T::ALL),
"{type_name}: T::has_unique_antimode(T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, so every variant ties for the antimode and T::count_antimodal_variants(T::ALL) == T::CARDINALITY >= 2 != 1; a `true` full-set arm silently bifurcates the flat-histogram fixpoint",
);
assert!(
!T::has_unique_antimode(&doubled_full_set),
"{type_name}: T::has_unique_antimode(&doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, every variant ties for the antimode at count `2`, and T::count_antimodal_variants(doubled) == T::CARDINALITY >= 2 != 1; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
let single_missing_slice: Vec<T> = T::ALL[..T::CARDINALITY - 1].to_vec();
assert!(
T::has_unique_antimode(&single_missing_slice),
"{type_name}: T::has_unique_antimode(&T::ALL[..T::CARDINALITY - 1]) != true — the single-missing (omit-last) fixture hits every present variant at count `1`, the omitted last variant at count `0`, T::min_variant_count collapses to `0`, and ONLY the omitted variant satisfies `count == min`, so T::count_antimodal_variants(&single_missing) == 1; a `false` single-missing arm silently bifurcates the LOAD-BEARING `true`-arm catch on the argmin uniqueness corner (every OTHER fixpoint at cardinality >= 2 pins the projection at `false`)",
);
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::has_unique_antimode(&matching_singleton),
"{type_name}: T::has_unique_antimode([{target_label:?}]) != false — the sole position hits the target at count `1`, every non-target variant has count `0`, T::min_variant_count([{target_label:?}]) == 0 at cardinality >= 3, and EVERY non-target variant satisfies `count == min`, so T::count_antimodal_variants([{target_label:?}]) == T::CARDINALITY - 1 >= 2 != 1; a `true` singleton-arm value at cardinality >= 3 silently mirrors the argmax singleton fixpoint onto the argmin uniqueness corner (the LOAD-BEARING asymmetry against T::has_unique_mode which returns `true` on the same singleton)",
);
}
}
}
let full_antimodal_witness_len = T::antimodal_variants(T::ALL).len();
assert_eq!(
T::has_unique_antimode(T::ALL),
full_antimodal_witness_len == 1,
"{type_name}: T::has_unique_antimode(T::ALL) drifted from (T::antimodal_variants(T::ALL).len() == 1) — the set-level antimodal-uniqueness predicate MUST equal the length-equality test of the declaration-order argmin witness-collection against `1`; a downstream consumer that binds `T::antimodal_variants(items).len() == 1` as its Vec-length surface for antimodal uniqueness would disagree with the pinned scalar test",
);
// (137) — `T::is_unique_modal_variant_of(target, items)` MUST agree
// with the conjunction of `T::is_modal_variant_of(target, items)` and
// `T::has_unique_mode(items)` on every (target, slice) pair AND MUST
// land on its canonical fixpoints (`false` at every target on the
// empty slice UNCONDITIONALLY via [`T::is_modal_variant_of`]'s
// empty-slice guard, `true` at the sole matching target on every
// matching singleton `[v]` UNCONDITIONALLY, `false` at every non-
// matching target on every non-matching singleton `[w]` with
// `T::index_of(v) != T::index_of(w)` via [`T::is_modal_variant_of`]'s
// non-matching-singleton arm, `false` at every target on the full-
// set slice at cardinality `>= 2` via [`T::has_unique_mode`]'s flat-
// histogram fixpoint, `false` at every target on the doubled-full-
// set slice at cardinality `>= 2` via the same flat-histogram
// fixpoint) AND on ONE composition-equality arm on the full-set
// fixpoint at cardinality `>= 2`: the set-level filter-count
// reduction over [`T::ALL`] of THIS per-target predicate MUST equal
// `T::has_unique_mode(T::ALL) as usize == 0` at cardinality `>= 2`,
// pinning the at-most-one-target contract as a TYPED CONSEQUENCE of
// the set-level modal-uniqueness bit.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past [`T::is_modal_variant_of`]'s `false` at the
// empty slice) AND on the non-matching-singleton arm (returns `true`
// past [`T::is_modal_variant_of`]'s `false` at the non-matching
// target) AND on both flat-histogram fixpoint arms at cardinality
// `>= 2` (which pin the projection at `false` because
// [`T::has_unique_mode`] falsifies universally at the flat
// histogram); an override that folds onto `false` unconditionally
// fires on every matching-singleton arm at the sole matching target
// (returns `false` past the (count == 1, count_modal_variants == 1)
// fixpoint where the sole target is the unique mode); an override
// that detaches from the set-level uniqueness bit on the full-set
// slice bifurcates loudly at the composition arm against
// `T::ALL.iter().filter(|v| T::is_unique_modal_variant_of(*v, T::ALL)).count() == 0`
// at cardinality `>= 2` (the LHS reports > 0 under a drift that
// returns `T::is_modal_variant_of(v, T::ALL)` verbatim without the
// uniqueness conjunct).
//
// Sibling posture to clause (133) one UNIQUE-TIE-SHARPENING axis
// over: clause (133) pins the (per-target × bool × statistical-
// aggregate × direction × argmax) membership corner via
// [`T::is_modal_variant_of`]; this clause SHARPENS the same corner
// through conjunction with the set-level uniqueness bit, pinning
// the (per-target × bool × statistical-aggregate × direction ×
// argmax × unique-tie) sharpened predicate corner. Sibling posture
// to clause (135) one ARITY axis over: clause (135) pins the set-
// level uniqueness bit; this clause LIFTS the same uniqueness
// predicate to the per-target arity axis under conjunction with the
// per-target argmax membership predicate. The default trait body
// threads the `is_modal_variant_of(target, items) &&
// has_unique_mode(items)` conjunction verbatim and satisfies every
// fixpoint arm + the composition arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the per-target unique-
// mode surface every downstream unique-plurality consumer routes
// through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_modal_variant_of(target, empty),
"{type_name}: T::is_unique_modal_variant_of({target_label:?}, &[]) != false — the per-target unique-mode predicate MUST report `false` on the empty slice at every target because T::is_modal_variant_of(v, &[]) collapses to `false` via its empty-slice guard; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-plurality consumer routes through",
);
let matching_singleton = [target];
assert!(
T::is_unique_modal_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_modal_variant_of({target_label:?}, [{target_label:?}]) != true — the sole position hits the target with count `1`, T::is_modal_variant_of(v, [v]) == true at count == max == 1, T::has_unique_mode([v]) == true at count_modal_variants == 1, and the conjunction lands on `true`; a `false` matching-singleton arm silently bifurcates the fixpoint every downstream unique-plurality consumer routes through",
);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_unique_modal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_unique_modal_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0`, T::max_variant_count == 1, T::is_modal_variant_of({target_label:?}, [{other_label:?}]) == false at count == 0 != max == 1, and the conjunction lands on `false` through the membership arm regardless of the uniqueness arm's `true` fixpoint on the singleton; a `true` non-matching-singleton arm silently bifurcates the fixpoint",
);
}
if T::CARDINALITY >= 2 {
assert!(
!T::is_unique_modal_variant_of(target, T::ALL),
"{type_name}: T::is_unique_modal_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::is_modal_variant_of reports `true` at every target on the flat-histogram fixpoint, but T::has_unique_mode(T::ALL) == false at count_modal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::is_modal_variant_of which reports `true` on the same slice",
);
assert!(
!T::is_unique_modal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_modal_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_modal_variant_of reports `true` at every target on the flat-histogram fixpoint, but T::has_unique_mode(doubled) == false at count_modal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
}
if T::CARDINALITY >= 2 {
let full_unique_modal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_modal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_modal_membership_count,
usize::from(T::has_unique_mode(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_modal_variant_of(*v, T::ALL)).count() == {full_unique_modal_membership_count} drifted from usize::from(T::has_unique_mode(T::ALL)) == 0 — the per-target unique-mode predicate's set-level filter-count MUST equal the set-level modal-uniqueness bit cast to usize; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_modal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
}
// (138) — `T::is_unique_antimodal_variant_of(target, items)` MUST
// agree with the conjunction of `T::is_antimodal_variant_of(target,
// items)` and `T::has_unique_antimode(items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false` at
// every target on the empty slice UNCONDITIONALLY via
// [`T::is_antimodal_variant_of`]'s empty-slice guard, `false` at
// every target on every matching singleton `[v]` at cardinality
// `>= 2` because `T::is_antimodal_variant_of(v, [v]) == false` at
// `count(v) == 1 != min == 0`, `false` at every non-matching target
// on every non-matching singleton `[w]` with `T::index_of(v) !=
// T::index_of(w)` at cardinality `>= 3` via [`T::has_unique_antimode`]'s
// `count_antimodal_variants([w]) == T::CARDINALITY - 1 >= 2 != 1`
// fixpoint, `false` at every target on the full-set slice at
// cardinality `>= 2` via [`T::has_unique_antimode`]'s flat-histogram
// fixpoint, `false` at every target on the doubled-full-set slice
// at cardinality `>= 2` via the same flat-histogram fixpoint, `true`
// at EXACTLY the omitted last variant on the single-missing slice
// `T::ALL[..T::CARDINALITY - 1]` at cardinality `>= 2` — the omit-
// last fixture pins the argmin sweep at a UNIQUE antimode, every
// present variant hits count `1`, the omitted variant hits count
// `0 == min`, [`T::is_antimodal_variant_of`] reports `true` at
// EXACTLY the omitted variant on the argmin band, [`T::has_unique_antimode`]
// reports `true` at `count_antimodal_variants == 1`, and the
// conjunction lands on `true` at the omitted variant and `false`
// at every present variant) AND on ONE composition-equality arm on
// the full-set fixpoint at cardinality `>= 2`: the set-level filter-
// count reduction over [`T::ALL`] of THIS per-target predicate MUST
// equal `T::has_unique_antimode(T::ALL) as usize == 0` at cardinality
// `>= 2`, pinning the at-most-one-target contract as a TYPED
// CONSEQUENCE of the set-level antimodal-uniqueness bit.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past [`T::is_antimodal_variant_of`]'s `false` at
// the empty slice) AND on the matching-singleton arm at cardinality
// `>= 2` at every target (returns `true` past the `count(v) == 1
// != min == 0` fixpoint) AND on both flat-histogram fixpoint arms
// at cardinality `>= 2` (which pin the projection at `false` because
// [`T::has_unique_antimode`] falsifies universally at the flat
// histogram); an override that folds onto `false` unconditionally
// fires on the single-missing arm at cardinality `>= 2` at the
// omitted last variant (returns `false` past the (only-omitted
// variant, unique argmin) fixpoint); an override that detaches
// from the set-level uniqueness bit on the full-set slice
// bifurcates loudly at the composition arm against
// `T::ALL.iter().filter(|v| T::is_unique_antimodal_variant_of(*v, T::ALL)).count() == 0`
// at cardinality `>= 2` (the LHS reports > 0 under a drift that
// returns `T::is_antimodal_variant_of(v, T::ALL)` verbatim without
// the uniqueness conjunct).
//
// Sibling posture to clause (137) one DIRECTION axis over: clause
// (137) pins the (per-target × bool × statistical-aggregate ×
// direction × argmax × unique-tie) corner via
// [`T::is_unique_modal_variant_of`]; this clause CLOSES the
// (per-target × bool × statistical-aggregate × direction × unique-
// tie) 2-corner face at the argmin arm past the argmax corner.
// Sibling posture to clause (136) one ARITY axis over: clause (136)
// pins the set-level antimodal-uniqueness bit; this clause LIFTS
// the same uniqueness predicate to the per-target arity axis under
// conjunction with the per-target argmin membership predicate. The
// default trait body threads the `is_antimodal_variant_of(target,
// items) && has_unique_antimode(items)` conjunction verbatim and
// satisfies every fixpoint arm + the composition arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the per-target
// unique-antimode surface every downstream unique-minority consumer
// routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_antimodal_variant_of(target, empty),
"{type_name}: T::is_unique_antimodal_variant_of({target_label:?}, &[]) != false — the per-target unique-antimode predicate MUST report `false` on the empty slice at every target because T::is_antimodal_variant_of(v, &[]) collapses to `false` via its empty-slice guard; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-minority consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_antimodal_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_antimodal_variant_of({target_label:?}, [{target_label:?}]) != false — the sole position hits the target with count `1`, every non-target variant has count `0`, T::min_variant_count([{target_label:?}]) == 0 at cardinality >= 2, T::is_antimodal_variant_of({target_label:?}, [{target_label:?}]) == false at count == 1 != min == 0, and the conjunction lands on `false` through the membership arm regardless of the uniqueness arm; a `true` matching-singleton arm silently mirrors the argmax matching-singleton fixpoint onto the argmin uniqueness corner (the LOAD-BEARING asymmetry against T::is_unique_modal_variant_of which returns `true` on the same slice at the same target)",
);
assert!(
!T::is_unique_antimodal_variant_of(target, T::ALL),
"{type_name}: T::is_unique_antimodal_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::is_antimodal_variant_of reports `true` at every target on the flat-histogram fixpoint, but T::has_unique_antimode(T::ALL) == false at count_antimodal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::is_antimodal_variant_of which reports `true` on the same slice",
);
assert!(
!T::is_unique_antimodal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_antimodal_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_antimodal_variant_of reports `true` at every target on the flat-histogram fixpoint, but T::has_unique_antimode(doubled) == false at count_antimodal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_unique_antimodal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_unique_antimodal_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0`, T::min_variant_count == 0, T::is_antimodal_variant_of({target_label:?}, [{other_label:?}]) == true on the argmin band, but T::has_unique_antimode([{other_label:?}]) == false at count_antimodal_variants == T::CARDINALITY - 1 >= 2 != 1 at cardinality >= 3, so the conjunction lands on `false` through the uniqueness arm; a `true` non-matching-singleton arm at cardinality >= 3 silently bifurcates the LOAD-BEARING asymmetry against T::is_antimodal_variant_of which reports `true` on the same slice",
);
}
}
}
// Single-missing (omit-last) fixture — the LOAD-BEARING `true`-
// arm catch on the argmin unique-tie corner. Every present
// variant hits count `1`, the omitted last variant hits count
// `0 == min`, so ONLY the omitted variant satisfies both the
// argmin membership arm AND the uniqueness arm at
// `count_antimodal_variants == 1`.
let single_missing_slice: Vec<T> = T::ALL[..T::CARDINALITY - 1].to_vec();
let missing_target = T::ALL[T::CARDINALITY - 1];
let missing_target_label = <T as ClosedSet>::label(missing_target);
assert!(
T::is_unique_antimodal_variant_of(missing_target, &single_missing_slice),
"{type_name}: T::is_unique_antimodal_variant_of({missing_target_label:?}, &T::ALL[..T::CARDINALITY - 1]) != true — the single-missing (omit-last) fixture hits every present variant at count `1`, the omitted last variant at count `0 == min`, T::is_antimodal_variant_of at the omitted variant is `true` on the argmin band, T::has_unique_antimode is `true` at count_antimodal_variants == 1, and the conjunction lands on `true` at the omitted variant; a `false` single-missing arm at the omitted target silently bifurcates the LOAD-BEARING `true`-arm catch on the argmin uniqueness corner (every OTHER fixpoint at cardinality >= 2 pins the projection at `false`)",
);
for present in T::ALL[..T::CARDINALITY - 1].iter().copied() {
let present_label = <T as ClosedSet>::label(present);
assert!(
!T::is_unique_antimodal_variant_of(present, &single_missing_slice),
"{type_name}: T::is_unique_antimodal_variant_of({present_label:?}, &T::ALL[..T::CARDINALITY - 1]) != false — the present variant hits count `1 != min == 0`, T::is_antimodal_variant_of reports `false` at the present target, and the conjunction lands on `false` through the membership arm; a `true` present-target arm on the single-missing fixture silently bifurcates the (only-omitted-variant satisfies the argmin band) contract",
);
}
let full_unique_antimodal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_antimodal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_antimodal_membership_count,
usize::from(T::has_unique_antimode(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_antimodal_variant_of(*v, T::ALL)).count() == {full_unique_antimodal_membership_count} drifted from usize::from(T::has_unique_antimode(T::ALL)) == 0 — the per-target unique-antimode predicate's set-level filter-count MUST equal the set-level antimodal-uniqueness bit cast to usize; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_antimodal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
}
// (139) — `T::unique_modal_variant(items)` MUST agree with the
// guarded lift of `T::modal_variant(items)` under `T::has_unique_mode(items)`
// on every slice AND MUST land on its canonical fixpoints (`None` on
// the empty slice UNCONDITIONALLY via [`T::has_unique_mode`]'s
// `false`-at-empty fixpoint, `Some(v)` at the sole variant on every
// matching singleton `[v]` UNCONDITIONALLY at every cardinality via
// the (count == max == 1, count_modal_variants == 1) fixpoint,
// `None` at every slice on the full-set fixpoint at cardinality
// `>= 2` via [`T::has_unique_mode`]'s flat-histogram fixpoint,
// `None` on the doubled-full-set fixpoint at cardinality `>= 2` via
// the same flat-histogram fixpoint) AND on TWO composition-equality
// arms on the full-set fixpoint: `T::unique_modal_variant(T::ALL).is_some()
// == T::has_unique_mode(T::ALL)` at every cardinality (the `is_some`
// bit COINCIDES with the set-level uniqueness bit); AND for every
// target `v`, `(T::unique_modal_variant(T::ALL) == Some(v)) ==
// T::is_unique_modal_variant_of(v, T::ALL)` at every cardinality (the
// strict-Option-equality against `Some(v)` coincides with the per-
// target unique-mode predicate).
//
// The canonical fixpoints + two composition arms partition failure
// modes at the (set-level × Option<Self> × slice-shape × composition-
// equality) corner simultaneously: an override that folds onto
// `Some(T::first())` unconditionally fires on the empty-slice arm
// (`Some(T::first()) != None`) AND on both flat-histogram fixpoint
// arms at cardinality `>= 2` (which pin the projection at `None`
// because [`T::has_unique_mode`] falsifies universally at the flat
// histogram); an override that folds onto `None` unconditionally
// fires on every matching-singleton arm at every variant (returns
// `None` past the (count == max == 1, count_modal_variants == 1)
// fixpoint where the sole target is the unique mode); an override
// that detaches from the set-level uniqueness bit on the full-set
// slice bifurcates loudly at the is_some-coincidence arm against
// `T::has_unique_mode(T::ALL) == false` at cardinality `>= 2`.
//
// Sibling posture to clause (135) one RETURN-SHAPE axis over: clause
// (135) pins the set-level modal-uniqueness `bool` bit; this clause
// LIFTS the same uniqueness predicate to the `Option<Self>` witness-
// when-unique surface. Sibling posture to clause (128) one UNIQUE-
// TIE-SHARPENING axis over: clause (128) pins the (set-level ×
// Option<Self> × statistical-aggregate × argmax) declaration-order
// first-witness [`T::modal_variant`]; this clause SHARPENS the same
// corner through the uniqueness guard, pinning the (set-level ×
// Option<Self> × statistical-aggregate × argmax × unique-tie) witness-
// if-unique corner. The default trait body threads the `if has_unique_mode
// { modal_variant } else { None }` guarded lift verbatim and
// satisfies every fixpoint arm + both composition arms for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// unique-mode witness surface every downstream (uniqueness-guarded
// argmax) consumer routes through.
let empty: &[T] = &[];
assert_eq!(
T::unique_modal_variant(empty),
None,
"{type_name}: T::unique_modal_variant(&[]) != None — the set-level unique-mode witness MUST report `None` on the empty slice UNCONDITIONALLY because T::has_unique_mode(&[]) == false at count_modal_variants == 0 != 1, and the guard-arm collapses the projection to `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream witness-if-unique consumer routes through",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_modal_variant(&matching_singleton),
Some(target),
"{type_name}: T::unique_modal_variant([{target_label:?}]) != Some({target_label:?}) — the sole position hits the target with count `1`, T::max_variant_count == 1, T::count_modal_variants == 1, T::has_unique_mode == true, T::modal_variant returns Some({target_label:?}), and the guarded lift threads through unchanged; a `None` matching-singleton arm silently bifurcates the LOAD-BEARING `Some`-arm catch every downstream witness-if-unique consumer routes through",
);
}
if T::CARDINALITY >= 2 {
assert_eq!(
T::unique_modal_variant(T::ALL),
None,
"{type_name}: T::unique_modal_variant(T::ALL) != None — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, every per-variant count is `1`, T::count_modal_variants == T::CARDINALITY >= 2, T::has_unique_mode == false, and the guard collapses the projection to `None`; a `Some(_)` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::modal_variant which returns Some(T::first()) on the same slice",
);
assert_eq!(
T::unique_modal_variant(&doubled_full_set),
None,
"{type_name}: T::unique_modal_variant(&doubled_full_set) != None — the doubled full set hits every variant at exactly two positions, T::count_modal_variants == T::CARDINALITY >= 2, T::has_unique_mode == false, and the guard collapses the projection to `None`; a `Some(_)` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
let full_is_some = T::unique_modal_variant(T::ALL).is_some();
assert_eq!(
full_is_some,
T::has_unique_mode(T::ALL),
"{type_name}: T::unique_modal_variant(T::ALL).is_some() drifted from T::has_unique_mode(T::ALL) — the Option<Self>-return's is_some bit MUST coincide with the set-level modal-uniqueness bit; a downstream consumer that binds `T::unique_modal_variant(items).is_some()` as its uniqueness surface would disagree with the pinned scalar",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let via_option_eq = T::unique_modal_variant(T::ALL) == Some(target);
let via_predicate = T::is_unique_modal_variant_of(target, T::ALL);
assert_eq!(
via_option_eq, via_predicate,
"{type_name}: (T::unique_modal_variant(T::ALL) == Some({target_label:?})) drifted from T::is_unique_modal_variant_of({target_label:?}, T::ALL) — the set-level Option<Self> witness's strict-equality test against Some(target) MUST coincide with the per-target unique-mode membership predicate; a downstream consumer that binds `T::unique_modal_variant(items) == Some(v)` as its per-target uniqueness surface would disagree with the per-target predicate",
);
}
}
// (140) — `T::unique_antimodal_variant(items)` MUST agree with the
// guarded lift of `T::antimodal_variant(items)` under
// `T::has_unique_antimode(items)` on every slice AND MUST land on its
// canonical fixpoints (`None` on the empty slice UNCONDITIONALLY via
// [`T::has_unique_antimode`]'s `false`-at-empty fixpoint, `None` at
// every matching singleton `[v]` at cardinality `>= 3` via
// [`T::has_unique_antimode`]'s `count_antimodal_variants([v]) ==
// T::CARDINALITY - 1 >= 2 != 1` fixpoint, `None` on the full-set
// fixpoint at cardinality `>= 2` via [`T::has_unique_antimode`]'s
// flat-histogram fixpoint, `None` on the doubled-full-set fixpoint at
// cardinality `>= 2` via the same flat-histogram fixpoint,
// `Some(T::ALL[T::CARDINALITY - 1])` on the single-missing (omit-
// last) fixture `T::ALL[..T::CARDINALITY - 1]` at cardinality `>= 2`
// — the omit-last fixture pins the argmin sweep at a UNIQUE antimode,
// every present variant hits count `1`, the omitted last variant
// hits count `0 == min`, [`T::antimodal_variant`] returns
// `Some(T::ALL[T::CARDINALITY - 1])` on the argmin band,
// [`T::has_unique_antimode`] reports `true` at
// `count_antimodal_variants == 1`, and the guarded lift threads
// through with the omitted witness) AND on TWO composition-equality
// arms on the single-missing fixture:
// `T::unique_antimodal_variant(single_missing).is_some() ==
// T::has_unique_antimode(single_missing) == true` (the `is_some` bit
// COINCIDES with the set-level uniqueness bit); AND for every target
// `v`, `(T::unique_antimodal_variant(single_missing) == Some(v)) ==
// T::is_unique_antimodal_variant_of(v, single_missing)` (the strict-
// Option-equality against `Some(v)` coincides with the per-target
// unique-antimode predicate).
//
// The canonical fixpoints + two composition arms partition failure
// modes at the (set-level × Option<Self> × slice-shape × composition-
// equality) corner simultaneously: an override that folds onto
// `Some(T::first())` unconditionally fires on the empty-slice arm
// (`Some(T::first()) != None`) AND on both flat-histogram fixpoint
// arms at cardinality `>= 2` (which pin the projection at `None`
// because [`T::has_unique_antimode`] falsifies universally at the
// flat histogram) AND on the matching-singleton arm at cardinality
// `>= 3` (where `count_antimodal_variants([v]) == T::CARDINALITY - 1
// >= 2` pins the projection at `None`); an override that folds onto
// `None` unconditionally fires on the single-missing arm at
// cardinality `>= 2` at the omitted-last-variant witness (returns
// `None` past the (only-omitted-variant, unique argmin, count == 0
// == min) fixpoint); an override that detaches from the set-level
// uniqueness bit on the single-missing slice bifurcates loudly at
// the is_some-coincidence arm against
// `T::has_unique_antimode(single_missing) == true` at cardinality
// `>= 2`.
//
// Sibling posture to clause (139) one DIRECTION axis over: clause
// (139) OPENS the (set-level × Option<Self> × statistical-aggregate
// × direction × argmax × unique-tie) corner via
// [`T::unique_modal_variant`]; this clause CLOSES the (set-level ×
// Option<Self> × statistical-aggregate × direction × unique-tie)
// 2-corner face at the argmin arm past the argmax corner. Sibling
// posture to clause (136) one RETURN-SHAPE axis over: clause (136)
// pins the set-level antimodal-uniqueness `bool` bit; this clause
// LIFTS the same uniqueness predicate to the `Option<Self>` witness-
// when-unique surface. Sibling posture to clause (129) one UNIQUE-
// TIE-SHARPENING axis over: clause (129) pins the (set-level ×
// Option<Self> × statistical-aggregate × argmin) declaration-order
// first-witness [`T::antimodal_variant`]; this clause SHARPENS the
// same corner through the uniqueness guard, pinning the (set-level ×
// Option<Self> × statistical-aggregate × argmin × unique-tie) witness-
// if-unique corner. Sibling posture to clause (138) one ARITY axis
// over: clause (138) pins the per-target unique-antimode predicate
// [`T::is_unique_antimodal_variant_of`]; this clause LIFTS the same
// uniqueness predicate to the set-level `Option<Self>` witness surface
// — the per-target predicate's set-level filter-count reduces to the
// set-level `Option<Self>` witness through the shared per-target
// Option-equality composition arm. The default trait body threads the
// `if has_unique_antimode { antimodal_variant } else { None }`
// guarded lift verbatim and satisfies every fixpoint arm + both
// composition arms for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather than
// silently bifurcating the set-level unique-antimode witness surface
// every downstream (uniqueness-guarded argmin) consumer routes
// through.
assert_eq!(
T::unique_antimodal_variant(empty),
None,
"{type_name}: T::unique_antimodal_variant(&[]) != None — the set-level unique-antimode witness MUST report `None` on the empty slice UNCONDITIONALLY because T::has_unique_antimode(&[]) == false at count_antimodal_variants == 0 != 1, and the guard-arm collapses the projection to `None`; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream witness-if-unique consumer routes through",
);
if T::CARDINALITY >= 2 {
assert_eq!(
T::unique_antimodal_variant(T::ALL),
None,
"{type_name}: T::unique_antimodal_variant(T::ALL) != None — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, every per-variant count is `1`, T::count_antimodal_variants == T::CARDINALITY >= 2, T::has_unique_antimode == false, and the guard collapses the projection to `None`; a `Some(_)` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::antimodal_variant which returns Some(T::first()) on the same slice",
);
assert_eq!(
T::unique_antimodal_variant(&doubled_full_set),
None,
"{type_name}: T::unique_antimodal_variant(&doubled_full_set) != None — the doubled full set hits every variant at exactly two positions, T::count_antimodal_variants == T::CARDINALITY >= 2, T::has_unique_antimode == false, and the guard collapses the projection to `None`; a `Some(_)` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_antimodal_variant(&matching_singleton),
None,
"{type_name}: T::unique_antimodal_variant([{target_label:?}]) != None — the sole position hits the target with count `1`, every non-target variant has count `0`, T::min_variant_count == 0, EVERY non-target variant ties at count == min, T::count_antimodal_variants == T::CARDINALITY - 1 >= 2 != 1 at cardinality >= 3, T::has_unique_antimode == false, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton arm at cardinality >= 3 silently mirrors the argmax matching-singleton fixpoint (where T::unique_modal_variant returns Some({target_label:?})) onto the argmin uniqueness-witness corner (the LOAD-BEARING asymmetry against T::unique_modal_variant)",
);
}
}
// Single-missing (omit-last) fixture — the LOAD-BEARING `Some`-
// arm catch on the argmin unique-tie corner. Every present
// variant hits count `1`, the omitted last variant hits count
// `0 == min`, so ONLY the omitted variant satisfies the argmin
// uniqueness at `count_antimodal_variants == 1`, and the
// guarded lift threads through with the omitted witness.
let single_missing_slice: Vec<T> = T::ALL[..T::CARDINALITY - 1].to_vec();
let missing_target = T::ALL[T::CARDINALITY - 1];
let missing_target_label = <T as ClosedSet>::label(missing_target);
assert_eq!(
T::unique_antimodal_variant(&single_missing_slice),
Some(missing_target),
"{type_name}: T::unique_antimodal_variant(&T::ALL[..T::CARDINALITY - 1]) != Some({missing_target_label:?}) — the single-missing (omit-last) fixture hits every present variant at count `1`, the omitted last variant at count `0 == min`, T::count_antimodal_variants == 1, T::has_unique_antimode == true, T::antimodal_variant returns Some({missing_target_label:?}) on the argmin band, and the guarded lift threads through; a `None` or wrong-`Some` single-missing arm silently bifurcates the LOAD-BEARING `Some`-arm catch on the argmin uniqueness-witness corner (every OTHER fixpoint at cardinality >= 2 pins the projection at `None`)",
);
let single_missing_is_some = T::unique_antimodal_variant(&single_missing_slice).is_some();
assert_eq!(
single_missing_is_some,
T::has_unique_antimode(&single_missing_slice),
"{type_name}: T::unique_antimodal_variant(&single_missing).is_some() drifted from T::has_unique_antimode(&single_missing) — the Option<Self>-return's is_some bit MUST coincide with the set-level antimodal-uniqueness bit on the single-missing fixture; a downstream consumer that binds `T::unique_antimodal_variant(items).is_some()` as its uniqueness surface would disagree with the pinned scalar",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let via_option_eq = T::unique_antimodal_variant(&single_missing_slice) == Some(target);
let via_predicate = T::is_unique_antimodal_variant_of(target, &single_missing_slice);
assert_eq!(
via_option_eq, via_predicate,
"{type_name}: (T::unique_antimodal_variant(&single_missing) == Some({target_label:?})) drifted from T::is_unique_antimodal_variant_of({target_label:?}, &single_missing) — the set-level Option<Self> witness's strict-equality test against Some(target) MUST coincide with the per-target unique-antimode membership predicate on the single-missing fixture; a downstream consumer that binds `T::unique_antimodal_variant(items) == Some(v)` as its per-target uniqueness surface would disagree with the per-target predicate",
);
}
}
// (141) — `T::is_extremal_variant_of(target, items)` MUST agree with
// the boolean disjunction of `T::is_modal_variant_of(target, items)`
// and `T::is_antimodal_variant_of(target, items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false` at
// every target on the empty slice UNCONDITIONALLY via the shared
// non-emptiness guards on both direction siblings, `true` at every
// target on every singleton at cardinality `>= 2` because a
// singleton's histogram has only two bands — max `1` and min `0` —
// with no middle inhabitant, so every target satisfies one direction
// arm, `true` at every target on the full-set slice at cardinality
// `>= 2` via the flat-histogram fixpoint of both direction siblings
// (max == min == 1), `true` at every target on the doubled-full-set
// slice at cardinality `>= 2` via the same flat-histogram fixpoint
// (max == min == 2), `false` at EXACTLY the middle-band target
// `T::ALL[1]` on the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — the
// fixture hits `T::ALL[0]` at count `2 == max`, `T::ALL[1]` at count
// `1` (MIDDLE), `T::ALL[2]` at count `0 == min`; the disjunction
// lands on `true` at both direction endpoints and `false` at the
// strictly-interior middle target) AND on ONE composition-equality
// arm on the middle-band fixture at cardinality `>= 3`: for every
// target `v`, `T::is_extremal_variant_of(v, &bimodal_triple) ==
// (T::is_modal_variant_of(v, &bimodal_triple) ||
// T::is_antimodal_variant_of(v, &bimodal_triple))` MUST hold on
// every target, pinning the direction-union identity as a TYPED
// CONSEQUENCE of the two direction siblings on a load-bearing non-
// flat fixture.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past the shared non-emptiness guard's `false`
// fixpoint) AND on the middle-band arm at cardinality `>= 3` at the
// middle target (returns `true` past the (count `1`, max `2`, min
// `0`) strictly-interior fixpoint); an override that folds onto
// `false` unconditionally fires on every singleton arm at
// cardinality `>= 2` at every target (returns `false` past the
// (count `1 == max` at matching target, count `0 == min` at every
// non-matching target) two-band fixpoint) AND on both flat-histogram
// fixpoint arms at cardinality `>= 2` (which pin the projection at
// `true` at every target because both direction siblings coincide
// at `true` on the flat histogram) AND on the middle-band arm at
// the two direction-endpoint targets `T::ALL[0]` and `T::ALL[2]`
// (returns `false` past the direction-anchored `true`-arm catches);
// an override that detaches from one of the two direction siblings
// on the middle-band fixture bifurcates loudly at the composition-
// equality arm against `T::is_modal_variant_of(v, &bimodal_triple)
// || T::is_antimodal_variant_of(v, &bimodal_triple)` at every
// target (a drift that returns only the argmax arm reports `false`
// at `T::ALL[2]` where the LHS reports `true` via argmin, and vice
// versa).
//
// Sibling posture to clauses (133) and (134) one DIRECTION-
// COMPOSITION axis over: clauses (133) and (134) pin the two
// direction-anchored per-target argmax/argmin membership predicates
// via [`T::is_modal_variant_of`] and [`T::is_antimodal_variant_of`];
// this clause LIFTS both direction siblings under a boolean
// disjunction to the direction-agnostic union predicate, pinning
// the (per-target × bool × direction-agnostic × union) corner. The
// default trait body threads the `is_modal_variant_of(target,
// items) || is_antimodal_variant_of(target, items)` disjunction
// verbatim and satisfies every fixpoint arm + the composition arm
// for free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the per-target direction-agnostic extremity surface
// every downstream union consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_extremal_variant_of(target, empty),
"{type_name}: T::is_extremal_variant_of({target_label:?}, &[]) != false — the per-target direction-agnostic extremity predicate MUST report `false` on the empty slice at every target because both T::is_modal_variant_of and T::is_antimodal_variant_of collapse to `false` via their shared non-emptiness guards; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream union consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
T::is_extremal_variant_of(target, &matching_singleton),
"{type_name}: T::is_extremal_variant_of({target_label:?}, [{target_label:?}]) != true — the sole position hits the target at count `1 == max`, T::is_modal_variant_of reports `true` on the argmax band, and the disjunction lands on `true` through the argmax arm; a `false` matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `true`-arm catch on the union corner (the singleton's histogram has only two bands with no middle inhabitant)",
);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
T::is_extremal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_extremal_variant_of({target_label:?}, [{other_label:?}]) != true — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0 == min`, T::is_antimodal_variant_of reports `true` on the argmin band, and the disjunction lands on `true` through the argmin arm; a `false` non-matching-singleton arm at cardinality >= 2 silently bifurcates the second two-band fixpoint (target sits at min, not max)",
);
}
assert!(
T::is_extremal_variant_of(target, T::ALL),
"{type_name}: T::is_extremal_variant_of({target_label:?}, T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::max_variant_count and T::min_variant_count both collapse to `1`, both direction siblings report `true` at every target on the flat-histogram fixpoint, and the disjunction inherits `true` verbatim; a `false` full-set arm silently bifurcates the uniformity-collapse identity where the direction axis collapses",
);
assert!(
T::is_extremal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_extremal_variant_of({target_label:?}, &doubled_full_set) != true — the doubled full set hits every variant at exactly two positions, T::max_variant_count and T::min_variant_count both collapse to `2`, both direction siblings report `true` at every target on the flat-histogram fixpoint, and the disjunction inherits `true` verbatim; a `false` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// `false`-arm catch on the union corner. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2] at
// count `0 == min`; only the middle-band target lands on
// `false` at cardinality >= 3.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let modal_target = T::ALL[0];
let modal_target_label = <T as ClosedSet>::label(modal_target);
let middle_target = T::ALL[1];
let middle_target_label = <T as ClosedSet>::label(middle_target);
let antimodal_target = T::ALL[2];
let antimodal_target_label = <T as ClosedSet>::label(antimodal_target);
assert!(
T::is_extremal_variant_of(modal_target, &bimodal_triple),
"{type_name}: T::is_extremal_variant_of({modal_target_label:?}, &bimodal_triple) != true — the bimodal-triple fixture hits {modal_target_label:?} at count `2 == max`, T::is_modal_variant_of reports `true` on the argmax band, and the disjunction lands on `true` through the argmax arm; a `false` modal-target arm on the middle-band fixture silently bifurcates the LOAD-BEARING direction-endpoint `true`-arm catch (the argmax endpoint sits ABOVE the middle band)",
);
assert!(
!T::is_extremal_variant_of(middle_target, &bimodal_triple),
"{type_name}: T::is_extremal_variant_of({middle_target_label:?}, &bimodal_triple) != false — the bimodal-triple fixture hits {middle_target_label:?} at count `1` strictly between max `2` and min `0` (MIDDLE band), both T::is_modal_variant_of and T::is_antimodal_variant_of report `false` at the middle target, and the disjunction lands on `false` through both arms; a `true` middle-band arm silently bifurcates the LOAD-BEARING `false`-arm catch on the union corner — the ONLY non-empty fixpoint where THIS predicate reports `false` at cardinality >= 3, catching an override that folds onto `true` unconditionally past every OTHER non-empty fixpoint",
);
assert!(
T::is_extremal_variant_of(antimodal_target, &bimodal_triple),
"{type_name}: T::is_extremal_variant_of({antimodal_target_label:?}, &bimodal_triple) != true — the bimodal-triple fixture hits {antimodal_target_label:?} at count `0 == min`, T::is_antimodal_variant_of reports `true` on the argmin band, and the disjunction lands on `true` through the argmin arm; a `false` antimodal-target arm on the middle-band fixture silently bifurcates the LOAD-BEARING direction-endpoint `true`-arm catch (the argmin endpoint sits BELOW the middle band)",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let via_predicate = T::is_extremal_variant_of(target, &bimodal_triple);
let via_disjunction = T::is_modal_variant_of(target, &bimodal_triple)
|| T::is_antimodal_variant_of(target, &bimodal_triple);
assert_eq!(
via_predicate, via_disjunction,
"{type_name}: T::is_extremal_variant_of({target_label:?}, &bimodal_triple) drifted from (T::is_modal_variant_of({target_label:?}, &bimodal_triple) || T::is_antimodal_variant_of({target_label:?}, &bimodal_triple)) — the direction-union identity MUST hold on every (target, slice) pair; a drift that returns only one direction arm bifurcates loudly on the middle-band fixture where the two direction siblings surface distinct `true`-arms at the two direction-endpoint targets",
);
}
}
// (142) — `T::is_bimodal_variant_of(target, items)` MUST agree with
// the boolean CONJUNCTION of `T::is_modal_variant_of(target, items)`
// and `T::is_antimodal_variant_of(target, items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false` at
// every target on the empty slice UNCONDITIONALLY via the shared
// non-emptiness guards on both direction siblings, `false` at every
// target on every matching singleton at cardinality `>= 2` because
// the sole-position target sits at count `1 == max` while every
// non-target variant sits at count `0 == min`, so
// T::is_antimodal_variant_of reports `false` at the target and the
// conjunction collapses through the argmin arm; symmetrically
// `false` at every target on every non-matching singleton because
// the target's count is `0 == min` but the sole-slice-element hits
// count `1 == max`, so T::is_modal_variant_of reports `false` at
// the target; `true` at every target on the full-set slice at
// cardinality `>= 1` via the flat-histogram fixpoint of both
// direction siblings (max == min == 1), `true` at every target on
// the doubled-full-set slice via the same flat-histogram fixpoint
// (max == min == 2), `false` at EVERY target on the bimodal-triple
// fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3`
// — the histogram bands are `max == 2`, MIDDLE `== 1`, `min == 0`,
// and NO target sits at BOTH `2` and `0` simultaneously) AND on ONE
// composition-equality arm on the middle-band fixture at cardinality
// `>= 3`: for every target `v`, `T::is_bimodal_variant_of(v,
// &bimodal_triple) == (T::is_modal_variant_of(v, &bimodal_triple)
// && T::is_antimodal_variant_of(v, &bimodal_triple))` MUST hold on
// every target, pinning the direction-conjunction identity as a
// TYPED CONSEQUENCE of the two direction siblings on a load-bearing
// non-flat fixture.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past the shared non-emptiness guard's `false`
// fixpoint) AND on every singleton arm at cardinality `>= 2` at
// every target (returns `true` past the (count `1 == max` at
// matching target OR count `0 == min` at non-matching target) two-
// band fixpoint where the OTHER direction sibling reports `false`)
// AND on the bimodal-triple arm at every target at cardinality
// `>= 3` (returns `true` past the non-flat three-band fixpoint
// where no target satisfies both direction arms); an override that
// folds onto `false` unconditionally fires on both flat-histogram
// fixpoint arms at cardinality `>= 1` (which pin the projection at
// `true` at every target because both direction siblings coincide
// at `true` on the flat histogram); an override that detaches from
// one of the two direction siblings on the middle-band fixture
// bifurcates loudly at the composition-equality arm against
// `T::is_modal_variant_of(v, &bimodal_triple) &&
// T::is_antimodal_variant_of(v, &bimodal_triple)` at every target
// (a drift that folds through the disjunction rather than the
// conjunction reports `true` at the direction-endpoint targets
// where the LHS reports `false`).
//
// Sibling posture to clause (141) one COMBINATOR axis over: clause
// (141) pins the direction-agnostic UNION predicate via
// [`T::is_extremal_variant_of`] under boolean disjunction; THIS
// clause LIFTS both direction siblings under boolean CONJUNCTION to
// the direction-agnostic INTERSECTION predicate, closing the (per-
// target × bool × direction-composition × combinator) 2-corner face
// at its `&&` arm past the `||` arm. The default trait body threads
// the `is_modal_variant_of(target, items) &&
// is_antimodal_variant_of(target, items)` conjunction verbatim and
// satisfies every fixpoint arm + the composition arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the per-target
// direction-agnostic flat-diagonal surface every downstream
// intersection consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_bimodal_variant_of(target, empty),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, &[]) != false — the per-target direction-agnostic flat-diagonal predicate MUST report `false` on the empty slice at every target because both T::is_modal_variant_of and T::is_antimodal_variant_of collapse to `false` via their shared non-emptiness guards; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream intersection consumer routes through",
);
assert!(
T::is_bimodal_variant_of(target, T::ALL),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::max_variant_count and T::min_variant_count both collapse to `1`, both direction siblings report `true` at every target on the flat-histogram fixpoint, and the conjunction inherits `true` verbatim; a `false` full-set arm silently bifurcates the LOAD-BEARING `true`-arm catch on the intersection corner",
);
assert!(
T::is_bimodal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, &doubled_full_set) != true — the doubled full set hits every variant at exactly two positions, T::max_variant_count and T::min_variant_count both collapse to `2`, both direction siblings report `true` at every target on the flat-histogram fixpoint, and the conjunction inherits `true` verbatim; a `false` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_bimodal_variant_of(target, &matching_singleton),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, [{target_label:?}]) != false — the sole position hits the target at count `1 == max`, but at cardinality >= 2 at least one non-target variant sits at count `0 == min`, so T::is_antimodal_variant_of reports `false` at the target on the argmin band, and the conjunction lands on `false` through the argmin arm; a `true` matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `false`-arm catch on the intersection corner (a witness the projection is a STRICT refinement of T::is_extremal_variant_of which reports `true` on the same fixture through the argmax arm)",
);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_bimodal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0 == min`, but {other_label:?}'s count is `1 == max`, so T::is_modal_variant_of reports `false` at the target on the argmax band, and the conjunction lands on `false` through the argmax arm; a `true` non-matching-singleton arm at cardinality >= 2 silently bifurcates the second two-band fixpoint (target sits at min, not max, so the conjunction cannot commit)",
);
}
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// all-`false`-arm catch on the intersection corner. The bimodal
// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at
// count `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2]
// at count `0 == min`; no target satisfies BOTH direction arms
// simultaneously (max != min on the non-flat histogram), so
// the conjunction collapses to `false` at EVERY target.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_bimodal_variant_of(target, &bimodal_triple),
"{type_name}: T::is_bimodal_variant_of({target_label:?}, &bimodal_triple) != false — the bimodal-triple fixture is non-flat (max `2` != min `0`), so no target satisfies BOTH direction arms simultaneously, and the conjunction collapses to `false` at every target; a `true` bimodal-triple arm at any target silently bifurcates the LOAD-BEARING all-`false`-arm catch that separates the intersection corner from T::is_extremal_variant_of (which reports `true` at both direction endpoints on the same fixture) one COMBINATOR axis over",
);
let via_predicate = T::is_bimodal_variant_of(target, &bimodal_triple);
let via_conjunction = T::is_modal_variant_of(target, &bimodal_triple)
&& T::is_antimodal_variant_of(target, &bimodal_triple);
assert_eq!(
via_predicate, via_conjunction,
"{type_name}: T::is_bimodal_variant_of({target_label:?}, &bimodal_triple) drifted from (T::is_modal_variant_of({target_label:?}, &bimodal_triple) && T::is_antimodal_variant_of({target_label:?}, &bimodal_triple)) — the direction-conjunction identity MUST hold on every (target, slice) pair; a drift that folds through the disjunction rather than the conjunction reports `true` at the direction-endpoint targets where the LHS reports `false`",
);
}
}
// (143) — `T::count_bimodal_variants(items)` MUST agree with the
// uniformity-collapse SHARPENING `if items.is_empty() { 0 } else if
// T::is_uniform(items) { T::CARDINALITY } else { 0 }` on every slice
// AND MUST agree with the naive filter-count reduction
// `T::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v,
// items)).count()` on every slice AND MUST land on its canonical
// fixpoints (`0` on the empty slice UNCONDITIONALLY past the vacuous
// (min == max == 0) flat-histogram collapse of T::is_uniform via the
// LOAD-BEARING empty-slice guard, `T::CARDINALITY` on the full-set
// slice at cardinality `>= 1` via the flat-histogram fixpoint
// (max == min == 1) of T::is_uniform, `T::CARDINALITY` on the doubled-
// full-set slice via the same flat-histogram fixpoint (max == min ==
// 2), `0` on every matching singleton at cardinality `>= 2` because
// the sole-position target sits at count `1 == max` while every non-
// target variant sits at count `0 == min`, so the histogram is non-
// flat (max `1` != min `0`), T::is_uniform reports `false`, and the
// scalar branch lands on `0`; `0` on the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — the
// histogram is non-flat (max `2` != min `0`), so T::is_uniform reports
// `false` and the scalar branch lands on `0`) AND on ONE filter-count
// composition-equality arm on the bimodal-triple fixture at
// cardinality `>= 3`: `T::count_bimodal_variants(&bimodal_triple) ==
// T::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v,
// &bimodal_triple)).count()` MUST hold, pinning the sharpened scalar-
// branch body against the naive per-target filter-count sweep on a
// load-bearing non-flat fixture where BOTH sides collapse to `0` for
// distinct reasons (LHS via T::is_uniform reporting `false`, RHS via
// every per-target T::is_bimodal_variant_of call reporting `false`).
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (set-level × usize × slice-shape × composition-
// equality) corner simultaneously: an override that folds onto `0`
// unconditionally fires on BOTH flat-histogram fixpoint arms (full-
// set and doubled-full-set) at `0 != T::CARDINALITY`; an override
// that folds onto `T::CARDINALITY` unconditionally fires on the
// empty-slice arm at `T::CARDINALITY != 0` AND on every matching-
// singleton arm at cardinality `>= 2` at `T::CARDINALITY != 0` AND
// on the bimodal-triple arm at cardinality `>= 3` at
// `T::CARDINALITY != 0`; an override that omits the empty-slice guard
// and returns `T::CARDINALITY` on `&[]` past the vacuous (min == max
// == 0) flat-histogram collapse of T::is_uniform bifurcates loudly at
// the empty-slice fixpoint at `T::CARDINALITY != 0`; an override that
// detaches from the sharpened scalar-branch body on the middle-band
// fixture (returning e.g. `1` on the bimodal-triple where the argmax-
// endpoint sits alone at max) bifurcates loudly at the filter-count
// composition-equality arm against `T::ALL.iter().copied().filter(
// |&v| T::is_bimodal_variant_of(v, &bimodal_triple)).count() == 0`.
//
// Sibling posture to clause (142) one ARITY axis over: clause (142)
// pins the (per-target × bool × intersection) flat-diagonal predicate
// via [`T::is_bimodal_variant_of`]; THIS clause LIFTS it to the
// (set-level × usize × intersection) cardinality-count aggregate via
// the uniformity-collapse SHARPENING (which cuts one algorithmic
// factor of `T::CARDINALITY` off the naive filter-count sweep). The
// default trait body threads the `is_empty() || !is_uniform(items)`
// scalar branch verbatim and satisfies every fixpoint arm + the
// filter-count composition arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the set-level intersection
// cardinality surface every downstream flat-diagonal-count consumer
// routes through.
let empty: &[T] = &[];
assert_eq!(
T::count_bimodal_variants(empty),
0,
"{type_name}: T::count_bimodal_variants(&[]) != 0 — the set-level intersection cardinality MUST report `0` on the empty slice UNCONDITIONALLY because the empty-slice guard MUST short-circuit past the vacuous (min == max == 0) flat-histogram collapse of T::is_uniform where an unguarded branch would silently return T::CARDINALITY; a non-zero empty-slice value bifurcates the empty-slice fixpoint contract every downstream flat-diagonal-count consumer routes through",
);
assert_eq!(
T::count_bimodal_variants(T::ALL),
T::CARDINALITY,
"{type_name}: T::count_bimodal_variants(T::ALL) != T::CARDINALITY — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::max_variant_count and T::min_variant_count both collapse to `1`, T::is_uniform reports `true` on the flat-histogram fixpoint, and the scalar branch MUST land on T::CARDINALITY; a value distinct from T::CARDINALITY on the full-set arm silently bifurcates the LOAD-BEARING flat-histogram fixpoint catch on the intersection cardinality-count corner",
);
assert_eq!(
T::count_bimodal_variants(&doubled_full_set),
T::CARDINALITY,
"{type_name}: T::count_bimodal_variants(&doubled_full_set) != T::CARDINALITY — the doubled full set hits every variant at exactly two positions, T::max_variant_count and T::min_variant_count both collapse to `2`, T::is_uniform reports `true` on the second flat-histogram fixpoint, and the scalar branch MUST land on T::CARDINALITY; a value distinct from T::CARDINALITY on the doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::count_bimodal_variants(&matching_singleton),
0,
"{type_name}: T::count_bimodal_variants([{target_label:?}]) != 0 at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` but every non-target variant sits at count `0 == min`, so the histogram is non-flat (max `1` != min `0`), T::is_uniform reports `false`, and the scalar branch MUST land on `0`; a non-zero matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `0`-arm catch on the intersection cardinality-count corner (a witness that the projection is a STRICT sharpening of T::count_modal_variants which reports `1` on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// `0`-arm catch on the intersection cardinality-count corner. The
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0]
// at count `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2]
// at count `0 == min`; the histogram is non-flat (max `2` != min
// `0`), so T::is_uniform reports `false` and the scalar branch
// lands on `0` at every target of the arity-lift's filter sweep.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::count_bimodal_variants(&bimodal_triple),
0,
"{type_name}: T::count_bimodal_variants(&bimodal_triple) != 0 — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::is_uniform reports `false`, and the scalar branch MUST land on `0`; a non-zero bimodal-triple arm silently bifurcates the LOAD-BEARING `0`-arm catch that separates the intersection cardinality from a prospective count_extremal_variants sibling (which would report `2` on the same fixture — the argmax and argmin endpoints)",
);
let via_sharpened = T::count_bimodal_variants(&bimodal_triple);
let via_filter = T::ALL
.iter()
.copied()
.filter(|&v| T::is_bimodal_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
via_sharpened, via_filter,
"{type_name}: T::count_bimodal_variants(&bimodal_triple) drifted from T::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v, &bimodal_triple)).count() — the filter-count composition identity MUST hold on every slice; a sharpening that detaches from the naive per-target filter-count sweep bifurcates loudly on the non-flat middle-band fixture where BOTH sides collapse to `0` for distinct reasons (LHS via T::is_uniform reporting `false`, RHS via every per-target predicate call reporting `false`)",
);
}
// (144) — `T::count_extremal_variants(items)` MUST agree with the
// inclusion-exclusion SHARPENING
// `if items.is_empty() { 0 } else { T::count_modal_variants(items) + T::count_antimodal_variants(items) - T::count_bimodal_variants(items) }`
// on every slice AND MUST agree with the naive filter-count reduction
// `T::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v, items)).count()`
// on every slice AND MUST land on its canonical fixpoints (`0` on the
// empty slice UNCONDITIONALLY through the empty-slice guard; `T::CARDINALITY`
// on the full-set slice via the flat-histogram fixpoint (max == min == 1)
// where every variant satisfies BOTH direction arms; `T::CARDINALITY` on
// the doubled-full-set slice via the same flat-histogram fixpoint
// (max == min == 2); `T::CARDINALITY` on every matching singleton at
// cardinality `>= 2` because the target sits alone at count `1 == max`
// (contributing `1` to count_modal_variants) while every non-target
// variant sits at count `0 == min` (contributing `T::CARDINALITY - 1` to
// count_antimodal_variants), with count_bimodal_variants collapsing to
// `0` on the non-flat histogram, so `1 + (T::CARDINALITY - 1) - 0 ==
// T::CARDINALITY`; `T::CARDINALITY - 1` on the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — the
// MIDDLE-band target `T::ALL[1]` at count `1` is the SOLE non-extremal
// target and the union count lands one below the ceiling) AND on ONE
// filter-count composition-equality arm on the bimodal-triple fixture at
// cardinality `>= 3`: `T::count_extremal_variants(&bimodal_triple) ==
// T::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v,
// &bimodal_triple)).count()` MUST hold, pinning the sharpened
// inclusion-exclusion body against the naive per-target filter-count
// sweep on the load-bearing non-flat fixture where BOTH sides collapse
// to `T::CARDINALITY - 1` for distinct reasons (LHS via
// `1 + (T::CARDINALITY - 2) - 0` arithmetic, RHS via every per-target
// T::is_extremal_variant_of call reporting `true` except at the middle-
// band target `T::ALL[1]`).
//
// The canonical fixpoints + one composition arm partition failure modes
// at the (set-level × usize × slice-shape × composition-equality) corner
// simultaneously: an override that folds onto `0` unconditionally fires
// on every non-empty fixpoint arm at `0 != T::CARDINALITY` (full-set,
// doubled-full-set, matching-singleton) AND at
// `0 != T::CARDINALITY - 1` on the bimodal-triple arm; an override that
// folds onto `T::CARDINALITY` unconditionally fires on the empty-slice
// arm at `T::CARDINALITY != 0` AND on the bimodal-triple arm at
// `T::CARDINALITY != T::CARDINALITY - 1`; an override that detaches
// from the sharpened inclusion-exclusion body on the middle-band fixture
// (returning e.g. `T::CARDINALITY` on the bimodal-triple where the
// middle-band target sits alone in the non-extremal slot) bifurcates
// loudly at the filter-count composition-equality arm against
// `T::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v, &bimodal_triple)).count() == T::CARDINALITY - 1`.
//
// Sibling posture to clause (143) one COMBINATOR axis over: clause (143)
// pins the (set-level × usize × intersection) flat-diagonal cardinality
// via [`T::count_bimodal_variants`] under the uniformity-collapse
// sharpening; THIS clause LIFTS the (per-target × bool × union) predicate
// to the (set-level × usize × union) cardinality-count aggregate via the
// inclusion-exclusion SHARPENING (which cuts one algorithmic factor of
// `T::CARDINALITY` off the naive filter-count sweep). The default trait
// body threads the `count_modal + count_antimodal - count_bimodal`
// arithmetic verbatim and satisfies every fixpoint arm + the filter-
// count composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather than
// silently bifurcating the set-level union cardinality surface every
// downstream extremity-count consumer routes through.
assert_eq!(
T::count_extremal_variants(empty),
0,
"{type_name}: T::count_extremal_variants(&[]) != 0 — the set-level union cardinality MUST report `0` on the empty slice UNCONDITIONALLY because every direction sibling AND the intersection sibling collapse to `0` on the empty slice via their shared non-emptiness guards, and `0 + 0 - 0 == 0`; a non-zero empty-slice value bifurcates the empty-slice fixpoint contract every downstream union-count consumer routes through",
);
assert_eq!(
T::count_extremal_variants(T::ALL),
T::CARDINALITY,
"{type_name}: T::count_extremal_variants(T::ALL) != T::CARDINALITY — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::max_variant_count and T::min_variant_count both collapse to `1`, T::count_modal_variants and T::count_antimodal_variants both report T::CARDINALITY, T::count_bimodal_variants reports T::CARDINALITY, and the arithmetic MUST land on T::CARDINALITY + T::CARDINALITY - T::CARDINALITY == T::CARDINALITY; a value distinct from T::CARDINALITY on the full-set arm silently bifurcates the LOAD-BEARING flat-histogram fixpoint catch on the union cardinality-count corner",
);
assert_eq!(
T::count_extremal_variants(&doubled_full_set),
T::CARDINALITY,
"{type_name}: T::count_extremal_variants(&doubled_full_set) != T::CARDINALITY — the doubled full set hits every variant at exactly two positions, T::max_variant_count and T::min_variant_count both collapse to `2`, T::count_modal_variants and T::count_antimodal_variants both report T::CARDINALITY, T::count_bimodal_variants reports T::CARDINALITY, and the arithmetic MUST land on T::CARDINALITY; a value distinct from T::CARDINALITY on the doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::count_extremal_variants(&matching_singleton),
T::CARDINALITY,
"{type_name}: T::count_extremal_variants([{target_label:?}]) != T::CARDINALITY at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` (contributing `1` to count_modal_variants) while every non-target variant sits at count `0 == min` (contributing T::CARDINALITY - 1 to count_antimodal_variants), count_bimodal_variants collapses to `0` on the non-flat histogram, and the arithmetic MUST land on `1 + (T::CARDINALITY - 1) - 0 == T::CARDINALITY`; a value distinct from T::CARDINALITY on the matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING T::CARDINALITY-arm catch on the union cardinality-count corner (a witness that the projection is a STRICT sharpening of T::count_bimodal_variants which reports `0` on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// `T::CARDINALITY - 1`-arm catch on the union cardinality-count
// corner. The bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// hits T::ALL[0] at count `2 == max` (contributing `1` to
// count_modal_variants), T::ALL[1] at count `1` (MIDDLE — the
// sole non-extremal target), T::ALL[2..] at count `0 == min`
// (contributing T::CARDINALITY - 2 to count_antimodal_variants),
// count_bimodal_variants collapses to `0` on the non-flat
// histogram, and the arithmetic lands on
// `1 + (T::CARDINALITY - 2) - 0 == T::CARDINALITY - 1`.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::count_extremal_variants(&bimodal_triple),
T::CARDINALITY - 1,
"{type_name}: T::count_extremal_variants(&bimodal_triple) != T::CARDINALITY - 1 — the bimodal-triple fixture is non-flat (max `2` != min `0`) and the middle-band target T::ALL[1] at count `1` is the SOLE non-extremal target, so count_modal_variants reports `1`, count_antimodal_variants reports T::CARDINALITY - 2, count_bimodal_variants reports `0`, and the arithmetic MUST land on `1 + (T::CARDINALITY - 2) - 0 == T::CARDINALITY - 1`; a value distinct from T::CARDINALITY - 1 on the bimodal-triple arm silently bifurcates the LOAD-BEARING one-below-ceiling catch that separates the union cardinality from a prospective count_extremal_variants sibling that folds onto T::CARDINALITY (which would report the ceiling on the same fixture — falsely including the middle-band target)",
);
let via_sharpened = T::count_extremal_variants(&bimodal_triple);
let via_filter = T::ALL
.iter()
.copied()
.filter(|&v| T::is_extremal_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
via_sharpened, via_filter,
"{type_name}: T::count_extremal_variants(&bimodal_triple) drifted from T::ALL.iter().copied().filter(|&v| T::is_extremal_variant_of(v, &bimodal_triple)).count() — the filter-count composition identity MUST hold on every slice; a sharpening that detaches from the naive per-target filter-count sweep bifurcates loudly on the non-flat middle-band fixture where BOTH sides collapse to `T::CARDINALITY - 1` for distinct reasons (LHS via inclusion-exclusion arithmetic on the three direction cardinality aggregates, RHS via every per-target T::is_extremal_variant_of call reporting `true` except at the middle-band target T::ALL[1])",
);
}
// (145) — `T::is_middle_band_variant_of(target, items)` MUST agree
// with the De Morgan complement identity `!items.is_empty() &&
// !T::is_extremal_variant_of(target, items)` on every (target, slice)
// pair AND MUST land on its canonical fixpoints (`false` on the
// empty slice UNCONDITIONALLY at every target through the non-empty
// guard past the vacuous `!T::is_extremal_variant_of(v, &[])` which
// would otherwise flip to `true`; `false` on every matching
// singleton at cardinality `>= 2` because the target sits at count
// `1 == max`, sits on the argmax band, is extremal, and the
// complement lands on `false`; `false` on every non-matching
// singleton at cardinality `>= 2` because the target sits at count
// `0 == min`, sits on the argmin band, is extremal, and the
// complement lands on `false`; `false` on the full-set slice at
// every target UNCONDITIONALLY at cardinality `>= 1` because clause
// (3)'s pairwise-distinctness pins the flat-histogram fixpoint
// (max == min == 1), every target is extremal on flat histograms,
// and the complement collapses to `false`; `false` on the doubled-
// full-set slice at every target via the same flat-histogram
// fixpoint (max == min == 2); `true` at the SOLE middle-band target
// `T::ALL[1]` of the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — the
// histogram is non-flat (max `2`, `T::ALL[1]` at `1` (MIDDLE), min
// `0`), so `T::ALL[1]` is NEITHER at max NOR at min,
// T::is_extremal_variant_of reports `false` at `T::ALL[1]`, the
// complement flips to `true`, and the non-empty guard preserves it;
// `false` at BOTH direction-endpoint targets `T::ALL[0]` (argmax)
// AND `T::ALL[2]` (argmin) on the same fixture at cardinality `>= 3`)
// AND on ONE partition composition-equality arm on the bimodal-
// triple fixture at cardinality `>= 3`:
// `T::is_middle_band_variant_of(target, &bimodal_triple) !=
// T::is_extremal_variant_of(target, &bimodal_triple)` MUST hold at
// every target — the (extreme / middle) partition surface MUST
// partition every non-empty slice at every target into disjoint
// arms (one holds, the other doesn't, never both, never neither).
//
// The canonical fixpoints + one partition composition arm partition
// failure modes at the (per-target × bool × direction-composition ×
// complement × partition-equality) corner simultaneously: an
// override that folds onto `true` unconditionally fires on the
// empty-slice arm at every target at `true != false` AND on every
// non-empty fixpoint arm at every target at cardinality `>= 2`
// (matching-singleton, non-matching-singleton, full-set, doubled-
// full-set, both direction-endpoint targets on the bimodal-triple)
// at `true != false`; an override that folds onto `false`
// unconditionally fires on the bimodal-triple arm at the sole
// middle-band target `T::ALL[1]` at cardinality `>= 3` at
// `false != true`; an override that drops the non-empty guard and
// folds onto `!T::is_extremal_variant_of(v, &[]) == true` on the
// empty slice bifurcates loudly at the empty-slice fixpoint at
// every target at `true != false`; an override that detaches from
// the De Morgan complement body on the middle-band fixture
// (returning e.g. `false` at `T::ALL[1]` on the bimodal-triple)
// bifurcates loudly at the partition composition-equality arm
// against T::is_extremal_variant_of at `T::ALL[1]` (where extremal
// reports `false` and the partition demands the two disagree).
//
// Sibling posture to clause (141) one COMPLEMENT axis over: clause
// (141) pins the direction-agnostic UNION predicate via
// [`T::is_extremal_variant_of`] under boolean disjunction; THIS
// clause LIFTS its NEGATION (past a non-empty guard) to the
// direction-agnostic strict-MIDDLE predicate, opening the (per-
// target × bool × direction-composition × complement) middle-band
// corner past the (per-target × bool × direction-composition ×
// combinator) 2-corner union/intersection face. The default trait
// body threads the `!items.is_empty() && !is_extremal_variant_of`
// conjunction verbatim and satisfies every fixpoint arm + the
// partition composition arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the (extreme / middle) partition
// surface every downstream strict-middle-membership consumer routes
// through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_middle_band_variant_of(target, empty),
"{type_name}: T::is_middle_band_variant_of({target_label:?}, &[]) != false — the per-target direction-agnostic strict-middle predicate MUST report `false` on the empty slice at every target through the non-empty guard, past the vacuous `!T::is_extremal_variant_of({target_label:?}, &[])` which would otherwise flip to `true` because T::is_extremal_variant_of reports `false` on the empty slice; a `true` empty-slice value silently bifurcates the LOAD-BEARING non-empty-guard catch every downstream strict-middle consumer routes through, silently folding the (extreme / middle) partition through the extremes at cardinality `>= 1`",
);
assert!(
!T::is_middle_band_variant_of(target, T::ALL),
"{type_name}: T::is_middle_band_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::max_variant_count and T::min_variant_count both collapse to `1`, T::is_extremal_variant_of reports `true` at every target on the flat-histogram fixpoint, and the complement MUST collapse to `false` at every target; a `true` full-set arm silently bifurcates the LOAD-BEARING flat-histogram-diagonal catch (there is NO strict-middle inhabitant on any uniform slice)",
);
assert!(
!T::is_middle_band_variant_of(target, &doubled_full_set),
"{type_name}: T::is_middle_band_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, both extremes collapse to `2`, T::is_extremal_variant_of reports `true` at every target on the second flat-histogram fixpoint, and the complement MUST collapse to `false` at every target; a `true` doubled-full-set arm silently bifurcates the second flat-histogram-diagonal catch",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_middle_band_variant_of(target, &matching_singleton),
"{type_name}: T::is_middle_band_variant_of({target_label:?}, [{target_label:?}]) != false — the sole position hits the target at count `1 == max`, the target sits on the argmax band, T::is_extremal_variant_of reports `true` at the target, and the complement MUST collapse to `false`; a `true` matching-singleton arm at cardinality `>= 2` silently bifurcates the LOAD-BEARING `false`-arm catch on the argmax band (a witness that the strict-middle band excludes every target sitting AT max)",
);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_middle_band_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_middle_band_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0 == min`, the target sits on the argmin band, T::is_extremal_variant_of reports `true` at the target, and the complement MUST collapse to `false`; a `true` non-matching-singleton arm at cardinality `>= 2` silently bifurcates the LOAD-BEARING `false`-arm catch on the argmin band (a witness that the strict-middle band excludes every target sitting AT min)",
);
}
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// `true`-arm catch on the strict-middle corner AND the sole
// fixpoint witness the middle-band corner carries a `true` arm.
// The bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits
// T::ALL[0] at count `2 == max` (extremal on argmax band,
// complement reports `false`), T::ALL[1] at count `1` (MIDDLE
// — neither at max nor at min, T::is_extremal_variant_of reports
// `false`, complement flips to `true`), T::ALL[2] at count
// `0 == min` (extremal on argmin band, complement reports
// `false`). The DUAL fixture of T::is_extremal_variant_of's
// middle-band `false`-arm catch one COMPLEMENT axis over:
// extremal reports `false` ONLY at T::ALL[1]; THIS reports
// `true` ONLY at T::ALL[1].
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let modal_target = T::ALL[0];
let middle_target = T::ALL[1];
let antimodal_target = T::ALL[2];
let modal_label = <T as ClosedSet>::label(modal_target);
let middle_label = <T as ClosedSet>::label(middle_target);
let antimodal_label = <T as ClosedSet>::label(antimodal_target);
assert!(
!T::is_middle_band_variant_of(modal_target, &bimodal_triple),
"{type_name}: T::is_middle_band_variant_of({modal_label:?}, &bimodal_triple) != false — the argmax-endpoint target sits at count `2 == max`, T::is_extremal_variant_of reports `true` on the argmax band, the complement MUST collapse to `false`; a `true` argmax-endpoint arm silently bifurcates the LOAD-BEARING `false`-arm catch on the direction endpoint",
);
assert!(
T::is_middle_band_variant_of(middle_target, &bimodal_triple),
"{type_name}: T::is_middle_band_variant_of({middle_label:?}, &bimodal_triple) != true — the sole middle-band target sits at count `1` (STRICTLY between `min == 0` and `max == 2`), T::is_extremal_variant_of reports `false` at the target on the non-flat histogram, the complement MUST flip to `true`, and the non-empty guard MUST preserve it; a `false` middle-band arm silently bifurcates the LOAD-BEARING `true`-arm catch on the strict-middle corner (the SOLE canonical fixture witness the middle-band corner carries a `true` arm — WITHOUT this the projection is indistinguishable from `_ => false`)",
);
assert!(
!T::is_middle_band_variant_of(antimodal_target, &bimodal_triple),
"{type_name}: T::is_middle_band_variant_of({antimodal_label:?}, &bimodal_triple) != false — the argmin-endpoint target sits at count `0 == min`, T::is_extremal_variant_of reports `true` on the argmin band, the complement MUST collapse to `false`; a `true` argmin-endpoint arm silently bifurcates the LOAD-BEARING `false`-arm catch on the direction endpoint",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let via_predicate = T::is_middle_band_variant_of(target, &bimodal_triple);
let via_complement =
!bimodal_triple.is_empty() && !T::is_extremal_variant_of(target, &bimodal_triple);
assert_eq!(
via_predicate, via_complement,
"{type_name}: T::is_middle_band_variant_of({target_label:?}, &bimodal_triple) drifted from (!bimodal_triple.is_empty() && !T::is_extremal_variant_of({target_label:?}, &bimodal_triple)) — the De Morgan complement identity MUST hold on every (target, slice) pair; a drift silently bifurcates the (extreme / middle) partition surface every downstream strict-middle-membership consumer routes through",
);
let via_extremal = T::is_extremal_variant_of(target, &bimodal_triple);
assert_ne!(
via_predicate, via_extremal,
"{type_name}: T::is_middle_band_variant_of({target_label:?}, &bimodal_triple) == T::is_extremal_variant_of({target_label:?}, &bimodal_triple) — the (extreme / middle) partition identity MUST hold on every NON-EMPTY slice at every target (exactly one of the two corners holds, never both, never neither); a coincident value silently bifurcates the partition of T::ALL per-target predicate surface into extremal + middle-band arms",
);
}
}
// (146) — `T::count_middle_band_variants(items)` MUST agree with the
// De Morgan complement SHARPENING
// `if items.is_empty() { 0 } else { T::CARDINALITY - T::count_extremal_variants(items) }`
// on every slice AND MUST agree with the naive filter-count reduction
// `T::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, items)).count()`
// on every slice AND MUST land on its canonical fixpoints (`0` on the
// empty slice UNCONDITIONALLY through the empty-slice guard past the
// vacuous `T::CARDINALITY - 0 == T::CARDINALITY` an unguarded branch
// would silently return; `0` on the full-set slice via the flat-
// histogram fixpoint (max == min == 1) where T::count_extremal_variants
// reports T::CARDINALITY and the subtraction lands on `0`; `0` on the
// doubled-full-set slice via the second flat-histogram fixpoint
// (max == min == 2); `0` on every matching singleton at cardinality
// `>= 2` because the target sits at count `1 == max` while every non-
// target variant sits at count `0 == min`, T::count_extremal_variants
// reports T::CARDINALITY (every variant is extremal), and the
// arithmetic lands on `T::CARDINALITY - T::CARDINALITY == 0`; `1` on
// the bimodal-triple fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at
// cardinality `>= 3` — the MIDDLE-band target T::ALL[1] at count `1`
// is the SOLE middle-band inhabitant, T::count_extremal_variants
// reports T::CARDINALITY - 1, and the arithmetic lands on
// `T::CARDINALITY - (T::CARDINALITY - 1) == 1`) AND on ONE partition-
// sum composition-equality arm on the bimodal-triple fixture at
// cardinality `>= 3`: `T::count_middle_band_variants(&bimodal_triple)
// + T::count_extremal_variants(&bimodal_triple) == T::CARDINALITY`
// MUST hold, pinning the partition-sum identity between the (extreme /
// middle) arms against the full carrier cardinality on the load-
// bearing non-flat fixture where the two cardinalities land on
// `1 + (T::CARDINALITY - 1) == T::CARDINALITY`.
//
// The canonical fixpoints + one partition-sum composition arm partition
// failure modes at the (set-level × usize × direction-composition ×
// complement × partition-sum) corner simultaneously: an override that
// folds onto `0` unconditionally fires on the bimodal-triple arm at
// `0 != 1` at cardinality `>= 3`, silently collapsing the middle-
// band cardinality to `0` on every slice (losing the sole `1`-arm
// witness); an override that folds onto `T::CARDINALITY` unconditionally
// fires on the empty-slice arm at `T::CARDINALITY != 0` AND on every
// non-empty fixpoint arm at cardinality `>= 2` (matching-singleton,
// full-set, doubled-full-set) at `T::CARDINALITY != 0` AND on the
// bimodal-triple arm at `T::CARDINALITY != 1`; an override that drops
// the empty-slice guard and folds onto
// `T::CARDINALITY - T::count_extremal_variants(&[]) == T::CARDINALITY`
// on the empty slice bifurcates loudly at the empty-slice fixpoint at
// `T::CARDINALITY != 0`; an override that detaches from the De Morgan
// complement body on the bimodal-triple fixture (returning e.g. `0`
// on the bimodal-triple where the middle-band target sits alone in
// the non-extremal slot) bifurcates loudly at the partition-sum
// composition-equality arm against T::count_extremal_variants at
// `0 + (T::CARDINALITY - 1) == T::CARDINALITY - 1 != T::CARDINALITY`.
//
// Sibling posture to clause (144) one COMPLEMENT axis over: clause
// (144) pins the (set-level × usize × direction-composition × union)
// extremal cardinality via [`T::count_extremal_variants`] under the
// inclusion-exclusion SHARPENING; THIS clause LIFTS its DE MORGAN
// COMPLEMENT (past an empty-slice guard) to the (set-level × usize ×
// direction-composition × complement) middle-band cardinality corner,
// closing the (extreme / middle) partition of T::ALL on the set-
// level usize row. The default trait body threads the
// `if items.is_empty() { 0 } else { T::CARDINALITY - count_extremal }`
// scalar branch verbatim and satisfies every fixpoint arm + the
// partition-sum composition arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the set-level middle-band
// cardinality surface every downstream middle-band-count consumer
// routes through.
assert_eq!(
T::count_middle_band_variants(empty),
0,
"{type_name}: T::count_middle_band_variants(&[]) != 0 — the set-level middle-band cardinality MUST report `0` on the empty slice UNCONDITIONALLY through the empty-slice guard past the vacuous `T::CARDINALITY - T::count_extremal_variants(&[]) == T::CARDINALITY - 0 == T::CARDINALITY` an unguarded branch would silently return; a non-zero empty-slice value bifurcates the empty-slice fixpoint contract every downstream middle-band-count consumer routes through",
);
assert_eq!(
T::count_middle_band_variants(T::ALL),
0,
"{type_name}: T::count_middle_band_variants(T::ALL) != 0 — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::count_extremal_variants reports T::CARDINALITY on the flat-histogram fixpoint (max == min == 1), and the arithmetic MUST land on `T::CARDINALITY - T::CARDINALITY == 0`; a non-zero full-set arm silently bifurcates the LOAD-BEARING flat-histogram-diagonal catch on the middle-band cardinality corner (a witness that the strict-middle band is EMPTY on every uniform slice)",
);
assert_eq!(
T::count_middle_band_variants(&doubled_full_set),
0,
"{type_name}: T::count_middle_band_variants(&doubled_full_set) != 0 — the doubled full set hits every variant at exactly two positions, T::count_extremal_variants reports T::CARDINALITY on the second flat-histogram fixpoint (max == min == 2), and the arithmetic MUST land on `0`; a non-zero doubled-full-set arm silently bifurcates the second flat-histogram-diagonal catch",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::count_middle_band_variants(&matching_singleton),
0,
"{type_name}: T::count_middle_band_variants([{target_label:?}]) != 0 at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, T::count_extremal_variants reports T::CARDINALITY (every variant is extremal on the singleton fixture), and the arithmetic MUST land on `T::CARDINALITY - T::CARDINALITY == 0`; a non-zero matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `0`-arm catch on the middle-band cardinality corner (a witness that no target sits STRICTLY between max and min when only one target hits max and every other target hits min simultaneously)",
);
}
}
if T::CARDINALITY >= 3 {
// Middle-band (min < count < max) fixture — the LOAD-BEARING
// `1`-arm catch on the middle-band cardinality corner AND the
// sole fixpoint witness the middle-band cardinality corner
// carries a strictly-positive arm. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (MIDDLE — the sole non-
// extremal target), T::ALL[2..] at count `0 == min`;
// T::count_extremal_variants reports T::CARDINALITY - 1 (every
// variant except T::ALL[1] is extremal), and the arithmetic
// lands on `T::CARDINALITY - (T::CARDINALITY - 1) == 1`. DUAL
// fixture of T::count_extremal_variants's
// `T::CARDINALITY - 1`-arm catch on the same fixture one
// COMPLEMENT axis over.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::count_middle_band_variants(&bimodal_triple),
1,
"{type_name}: T::count_middle_band_variants(&bimodal_triple) != 1 — the bimodal-triple fixture is non-flat (max `2` != min `0`) and the middle-band target T::ALL[1] at count `1` is the SOLE non-extremal target, so T::count_extremal_variants reports T::CARDINALITY - 1, and the arithmetic MUST land on `T::CARDINALITY - (T::CARDINALITY - 1) == 1`; a value distinct from `1` on the bimodal-triple arm silently bifurcates the LOAD-BEARING `1`-arm catch that carries the SOLE canonical fixture witness the middle-band cardinality corner has a strictly-positive arm (WITHOUT this the projection is indistinguishable from `_ => 0`)",
);
let via_sharpened = T::count_middle_band_variants(&bimodal_triple);
let via_filter = T::ALL
.iter()
.copied()
.filter(|&v| T::is_middle_band_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
via_sharpened, via_filter,
"{type_name}: T::count_middle_band_variants(&bimodal_triple) drifted from T::ALL.iter().copied().filter(|&v| T::is_middle_band_variant_of(v, &bimodal_triple)).count() — the filter-count composition identity MUST hold on every slice; a sharpening that detaches from the naive per-target filter-count sweep bifurcates loudly on the non-flat middle-band fixture where BOTH sides collapse to `1` for distinct reasons (LHS via `T::CARDINALITY - (T::CARDINALITY - 1)` subtraction, RHS via every per-target T::is_middle_band_variant_of call reporting `false` except at the middle-band target T::ALL[1])",
);
let extremal = T::count_extremal_variants(&bimodal_triple);
assert_eq!(
via_sharpened + extremal,
T::CARDINALITY,
"{type_name}: T::count_middle_band_variants(&bimodal_triple) + T::count_extremal_variants(&bimodal_triple) != T::CARDINALITY — the (extreme / middle) partition-sum identity MUST hold on every NON-EMPTY slice; the two arms partition T::ALL exactly once, so their cardinalities MUST sum to T::CARDINALITY on non-empty slices; a drift silently bifurcates the partition of T::ALL into overlapping or gap-carrying arms",
);
}
// (147) — `T::has_middle_band_variant(items)` MUST agree with the
// strict-lower-bound test of `T::count_middle_band_variants(items)`
// against `1` on every slice AND MUST land on its canonical fixpoints
// (`false` on the empty slice UNCONDITIONALLY because
// T::count_middle_band_variants(&[]) == 0 < 1; `false` on the full-set
// slice via the flat-histogram fixpoint (max == min == 1) where
// T::count_middle_band_variants reports `0`; `false` on the doubled-
// full-set slice via the second flat-histogram fixpoint
// (max == min == 2); `false` on every matching singleton at cardinality
// `>= 2` because the sole target sits at count `1 == max` while every
// non-target variant sits at count `0 == min` and every variant sits at
// some extreme so T::count_middle_band_variants reports `0`; `true` on
// the bimodal-triple fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at
// cardinality `>= 3` — the MIDDLE-band target T::ALL[1] at count `1`
// is the SOLE middle-band inhabitant, T::count_middle_band_variants
// reports `1`, and `1 >= 1`) AND on ONE existential-lift composition-
// equality arm on the bimodal-triple fixture at cardinality `>= 3`:
// `T::has_middle_band_variant(&bimodal_triple) == T::ALL.iter().copied().any(|v| T::is_middle_band_variant_of(v, &bimodal_triple))`
// MUST hold, pinning the existential-lift identity between the set-
// level bool aggregate against the per-target predicate on the load-
// bearing non-flat fixture where BOTH sides collapse to `true` for
// distinct reasons (LHS via `count_middle_band_variants >= 1`, RHS
// via a per-target sweep hitting the middle-band target T::ALL[1]).
//
// The canonical fixpoints + one existential-lift composition arm
// partition failure modes at the (set-level × bool × direction-
// composition × complement × existential) corner simultaneously: an
// override that folds onto `true` unconditionally fires on the empty-
// slice arm at `true != false` AND on every non-empty flat-histogram
// fixpoint arm (full-set, doubled-full-set) AND on every matching-
// singleton arm at cardinality `>= 2` (all landing on `false`
// naturally, so a `_ => true` override bifurcates on all of them);
// an override that folds onto `false` unconditionally fires on the
// bimodal-triple arm at `false != true` at cardinality `>= 3` — the
// SOLE canonical fixture witness the middle-band existence corner
// carries a `true` arm — AND on the existential-lift arm at
// `false != true` where the per-target sweep hits T::ALL[1]; an
// override that detaches from the count-composition body on the
// bimodal-triple (returning e.g. `false` past the count-`1` fixpoint)
// bifurcates loudly at the existential-lift arm.
//
// Sibling posture to clause (146) one RETURN-SHAPE axis over: clause
// (146) pins the (set-level × usize × direction-composition ×
// complement) middle-band cardinality via
// [`T::count_middle_band_variants`] under the De Morgan complement
// SHARPENING; THIS clause LIFTS its strict-lower-bound test against
// the scalar threshold `1` to the (set-level × bool × direction-
// composition × complement × existential) middle-band existence
// corner, opening the existential bit peer to the cardinality-count
// gauge on the RETURN-SHAPE axis. The default trait body threads the
// `T::count_middle_band_variants(items) >= 1` test verbatim and
// satisfies every fixpoint arm + the existential-lift composition arm
// for free; the assertion catches a future implementor whose override
// drifts the projection loudly rather than silently bifurcating the
// set-level middle-band existence surface every downstream middle-
// band-existence consumer routes through.
assert!(
!T::has_middle_band_variant(empty),
"{type_name}: T::has_middle_band_variant(&[]) != false — the set-level middle-band existence predicate MUST report `false` on the empty slice because T::count_middle_band_variants(&[]) == 0 < 1; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream middle-band-existence consumer routes through",
);
assert!(
!T::has_middle_band_variant(T::ALL),
"{type_name}: T::has_middle_band_variant(T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::count_middle_band_variants reports `0` on the flat-histogram fixpoint, and `0 < 1`; a `true` full-set arm silently bifurcates the flat-histogram-diagonal catch on the middle-band existence corner",
);
assert!(
!T::has_middle_band_variant(&doubled_full_set),
"{type_name}: T::has_middle_band_variant(&doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::count_middle_band_variants reports `0` on the second flat-histogram fixpoint, and `0 < 1`; a `true` doubled-full-set arm silently bifurcates the second flat-histogram-diagonal catch",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::has_middle_band_variant(&matching_singleton),
"{type_name}: T::has_middle_band_variant([{target_label:?}]) != false at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, T::count_middle_band_variants reports `0` (every variant sits at some extreme), and `0 < 1`; a `true` matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `false`-arm catch on the middle-band existence corner",
);
}
}
if T::CARDINALITY >= 3 {
// Middle-band existence fixture — the LOAD-BEARING `true`-arm
// catch on the middle-band existence corner AND the SOLE fixpoint
// witness the corner carries a `true` arm. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2..] at
// count `0 == min`; T::count_middle_band_variants reports `1` (the
// sole middle-band target T::ALL[1]), and `1 >= 1`. DUAL fixture
// of T::count_middle_band_variants's `1`-arm catch on the same
// fixture one RETURN-SHAPE axis over.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert!(
T::has_middle_band_variant(&bimodal_triple),
"{type_name}: T::has_middle_band_variant(&bimodal_triple) != true — the bimodal-triple fixture is non-flat (max `2` != min `0`) and the middle-band target T::ALL[1] at count `1` is the SOLE non-extremal target, so T::count_middle_band_variants reports `1`, and `1 >= 1`; a `false` bimodal-triple arm silently bifurcates the LOAD-BEARING `true`-arm catch that carries the SOLE canonical fixture witness the middle-band existence corner has a positive arm (WITHOUT this the projection is indistinguishable from `_ => false`)",
);
let via_bit = T::has_middle_band_variant(&bimodal_triple);
let via_any = T::ALL
.iter()
.copied()
.any(|v| T::is_middle_band_variant_of(v, &bimodal_triple));
assert_eq!(
via_bit, via_any,
"{type_name}: T::has_middle_band_variant(&bimodal_triple) drifted from T::ALL.iter().copied().any(|v| T::is_middle_band_variant_of(v, &bimodal_triple)) — the existential-lift identity MUST hold on every slice; a projection that detaches from the naive per-target existential sweep bifurcates loudly on the non-flat middle-band fixture where BOTH sides collapse to `true` for distinct reasons (LHS via `count_middle_band_variants >= 1` on the sharpened De Morgan aggregate, RHS via the per-target `is_middle_band_variant_of` sweep hitting the middle-band target T::ALL[1])",
);
}
// (148) — `T::has_bimodal_variant(items)` MUST agree with the
// strict-lower-bound test of `T::count_bimodal_variants(items)`
// against `1` on every slice AND MUST land on its canonical
// fixpoints (`false` on the empty slice UNCONDITIONALLY because
// T::count_bimodal_variants(&[]) == 0 < 1; `true` on the full-set
// slice via the flat-histogram fixpoint (max == min == 1) where
// T::count_bimodal_variants reports T::CARDINALITY >= 1; `true` on
// the doubled-full-set slice via the second flat-histogram fixpoint
// (max == min == 2); `false` on every matching singleton at
// cardinality `>= 2` because the sole target sits at count `1 == max`
// while every non-target variant sits at count `0 == min`, the
// histogram is non-flat, and T::count_bimodal_variants reports `0`;
// `false` on the bimodal-triple fixture at cardinality `>= 3` because
// the histogram is non-flat (max `2` != min `0`) and
// T::count_bimodal_variants reports `0`) AND on ONE existential-lift
// composition-equality arm on the full-set fixture:
// `T::has_bimodal_variant(T::ALL) == T::ALL.iter().copied().any(|v| T::is_bimodal_variant_of(v, T::ALL))`
// MUST hold, pinning the existential-lift identity between the set-
// level bool aggregate against the per-target predicate on the load-
// bearing flat-histogram fixture where BOTH sides collapse to `true`
// for distinct reasons (LHS via `count_bimodal_variants >= 1`, RHS
// via a per-target sweep hitting every variant on the flat diagonal).
//
// The canonical fixpoints + one existential-lift composition arm
// partition failure modes at the (set-level × bool × direction-
// composition × intersection × existential) corner simultaneously:
// an override that folds onto `true` unconditionally fires on the
// empty-slice arm at `true != false` AND on every matching-singleton
// arm at cardinality `>= 2` AND on the bimodal-triple arm at
// cardinality `>= 3`; an override that folds onto `false`
// unconditionally fires on the full-set + doubled-full-set arms at
// `false != true` — the LOAD-BEARING flat-histogram fixpoint arms
// that carry the sole canonical `true`-arm witnesses the bimodal
// existence corner has a positive image — AND on the existential-lift
// arm at `false != true` where the per-target sweep hits every
// variant on the flat-diagonal full-set fixture; an override that
// detaches from the count-composition body on the bimodal-triple
// (returning e.g. `true` past the count-`0` fixpoint) bifurcates
// loudly at the bimodal-triple arm.
//
// Sibling posture to clause (143) one RETURN-SHAPE axis over: clause
// (143) pins the (set-level × usize × direction-composition ×
// intersection) bimodal cardinality via
// [`T::count_bimodal_variants`] under the uniformity-collapse
// SHARPENING; THIS clause LIFTS its strict-lower-bound test against
// the scalar threshold `1` to the (set-level × bool × direction-
// composition × intersection × existential) bimodal existence
// corner, closing the intersection-arm existential bit peer to the
// cardinality-count gauge on the RETURN-SHAPE axis AND peer to
// clause (147)'s middle-band existence bit one DIRECTION-COMPOSITION
// axis over. The default trait body threads the
// `T::count_bimodal_variants(items) >= 1` test verbatim and
// satisfies every fixpoint arm + the existential-lift composition
// arm for free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the set-level bimodal existence surface every
// downstream flat-diagonal-existence consumer routes through.
assert!(
!T::has_bimodal_variant(empty),
"{type_name}: T::has_bimodal_variant(&[]) != false — the set-level bimodal existence predicate MUST report `false` on the empty slice because T::count_bimodal_variants(&[]) == 0 < 1; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream flat-diagonal-existence consumer routes through",
);
assert!(
T::has_bimodal_variant(T::ALL),
"{type_name}: T::has_bimodal_variant(T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::is_uniform reports `true` on the flat-histogram fixpoint (max == min == 1), T::count_bimodal_variants reports T::CARDINALITY >= 1, and T::CARDINALITY >= 1; a `false` full-set arm silently bifurcates the LOAD-BEARING flat-histogram-diagonal `true`-arm catch on the bimodal existence corner",
);
assert!(
T::has_bimodal_variant(&doubled_full_set),
"{type_name}: T::has_bimodal_variant(&doubled_full_set) != true — the doubled full set hits every variant at exactly two positions, T::count_bimodal_variants reports T::CARDINALITY >= 1 on the second flat-histogram fixpoint, and T::CARDINALITY >= 1; a `false` doubled-full-set arm silently bifurcates the second flat-histogram-diagonal `true`-arm catch",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::has_bimodal_variant(&matching_singleton),
"{type_name}: T::has_bimodal_variant([{target_label:?}]) != false at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, the histogram is non-flat, T::count_bimodal_variants reports `0`, and `0 < 1`; a `true` matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `false`-arm catch on the bimodal existence corner separating it from the (prospective) union-arm `has_extremal_variant` which reports `true` on the same fixture",
);
}
// Existential-lift composition-equality arm on the full-set
// fixture: `T::has_bimodal_variant(T::ALL) ==
// T::ALL.iter().any(|v| T::is_bimodal_variant_of(v, T::ALL))`.
// Both sides collapse to `true` because every variant of T::ALL
// sits on the flat diagonal (count `1 == max == min`), and any
// one hit witnesses the existential.
let via_bit = T::has_bimodal_variant(T::ALL);
let via_any = T::ALL
.iter()
.copied()
.any(|v| T::is_bimodal_variant_of(v, T::ALL));
assert_eq!(
via_bit, via_any,
"{type_name}: T::has_bimodal_variant(T::ALL) drifted from T::ALL.iter().copied().any(|v| T::is_bimodal_variant_of(v, T::ALL)) — the existential-lift identity MUST hold on every slice; a projection that detaches from the naive per-target existential sweep bifurcates loudly on the flat-histogram full-set fixture where BOTH sides collapse to `true` for distinct reasons (LHS via `count_bimodal_variants >= 1` on the uniformity-collapse aggregate, RHS via the per-target `is_bimodal_variant_of` sweep hitting every variant on the flat diagonal)",
);
}
if T::CARDINALITY >= 3 {
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert!(
!T::has_bimodal_variant(&bimodal_triple),
"{type_name}: T::has_bimodal_variant(&bimodal_triple) != false — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::count_bimodal_variants reports `0`, and `0 < 1`; a `true` bimodal-triple arm silently bifurcates the LOAD-BEARING `false`-arm catch on the non-flat middle-band fixture that distinguishes the intersection existence corner from the (prospective) union existence corner `has_extremal_variant` (which reports `true` on the same fixture)",
);
}
// (149) — `T::has_extremal_variant(items)` MUST agree with the
// non-emptiness collapse identity `!items.is_empty()` on every
// slice AND MUST land on its canonical fixpoints (`false` on the
// empty slice UNCONDITIONALLY because the argmax and argmin bands
// are both uninhabited past the shared non-emptiness guards of the
// two direction-anchored membership predicates; `true` on the
// full-set slice via the flat-histogram fixpoint (max == min == 1)
// where every variant is extremal; `true` on the doubled-full-set
// slice via the second flat-histogram fixpoint (max == min == 2);
// `true` on every matching singleton at cardinality `>= 2` because
// the sole target sits at count `1 == max` under
// T::is_modal_variant_of so T::is_extremal_variant_of holds on it
// via the disjunction arm; `true` on the bimodal-triple fixture at
// cardinality `>= 3` because T::ALL[0] sits at the argmax band and
// is extremal) AND on ONE existential-lift composition-equality
// arm on the bimodal-triple fixture at cardinality `>= 3`:
// `T::has_extremal_variant(&bimodal_triple) == T::ALL.iter().copied().any(|v| T::is_extremal_variant_of(v, &bimodal_triple))`
// MUST hold, pinning the existential-lift identity between the
// set-level bool aggregate against the per-target predicate on the
// load-bearing non-flat fixture where BOTH sides collapse to
// `true` for distinct reasons (LHS via `!items.is_empty()` past
// the non-emptiness collapse SHARPENING, RHS via a per-target
// sweep hitting the argmax target T::ALL[0]).
//
// The canonical fixpoints + one existential-lift composition arm
// partition failure modes at the (set-level × bool × direction-
// composition × union × existential) corner simultaneously: an
// override that folds onto `true` unconditionally fires on the
// empty-slice arm at `true != false` — the SOLE canonical fixture
// witness the union existence corner carries a `false` arm; an
// override that folds onto `false` unconditionally fires on every
// non-empty flat-histogram fixpoint arm (full-set, doubled-full-
// set) AND on every matching-singleton arm at cardinality `>= 2`
// AND on the bimodal-triple arm at cardinality `>= 3` — the
// LOAD-BEARING `true`-arm witnesses the union existence corner
// has a positive image on every non-empty slice past the non-
// emptiness collapse — AND on the existential-lift arm at
// `false != true` where the per-target sweep hits T::ALL[0]; an
// override that detaches from the non-emptiness collapse body on
// the bimodal-triple (returning e.g. `false` past the non-
// emptiness fixpoint) bifurcates loudly at the existential-lift
// arm.
//
// Sibling posture to clauses (147) + (148) one DIRECTION-
// COMPOSITION axis over: clauses (147) + (148) pin the (set-
// level × bool × direction-composition × complement × existential)
// + (set-level × bool × direction-composition × intersection ×
// existential) middle-band + bimodal existence bits via
// [`T::has_middle_band_variant`] + [`T::has_bimodal_variant`]
// under the De Morgan complement + uniformity-collapse
// SHARPENINGS respectively; THIS clause LIFTS the (set-level ×
// bool × direction-composition × union × existential) extremal
// existence bit via [`T::has_extremal_variant`] under the NON-
// EMPTINESS COLLAPSE SHARPENING — the union-arm existence bit
// SATURATES the non-empty domain (every non-empty slice carries
// an argmax target, so the union arm always fires on non-empty),
// closing the (set-level × bool × direction-composition ×
// existential) TRICHOTOMY (union / intersection / complement) on
// the modal-aggregation matrix with sharpened bodies at every
// corner (`!items.is_empty()`, `count_bimodal_variants >= 1`,
// `count_middle_band_variants >= 1`). The default trait body
// threads the `!items.is_empty()` bit verbatim and satisfies
// every fixpoint arm + the existential-lift composition arm for
// free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the set-level extremal existence surface every
// downstream extremal-existence consumer routes through.
assert!(
!T::has_extremal_variant(empty),
"{type_name}: T::has_extremal_variant(&[]) != false — the set-level extremal existence predicate MUST report `false` on the empty slice because both direction-anchored membership predicates report `false` at every target on their shared non-emptiness guards, equivalently T::count_extremal_variants(&[]) == 0 < 1, equivalently `!(&[]).is_empty() == false`; a `true` empty-slice value silently bifurcates the SOLE canonical fixture witness the union existence corner carries a `false` arm — every non-empty slice witnesses the `true` arm past the non-emptiness collapse SHARPENING, so an always-`true` drift would silently detach the projection from the empty-slice endpoint every downstream extremal-existence consumer routes through",
);
assert!(
T::has_extremal_variant(T::ALL),
"{type_name}: T::has_extremal_variant(T::ALL) != true — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::is_uniform reports `true` on the flat-histogram fixpoint (max == min == 1), every variant sits at BOTH extremes simultaneously and is therefore extremal, T::count_extremal_variants reports T::CARDINALITY >= 1, and `!T::ALL.is_empty()` (T::CARDINALITY >= 1 pins T::ALL non-empty); a `false` full-set arm silently bifurcates the LOAD-BEARING flat-histogram `true`-arm catch on the extremal existence corner",
);
assert!(
T::has_extremal_variant(&doubled_full_set),
"{type_name}: T::has_extremal_variant(&doubled_full_set) != true — the doubled full set hits every variant at exactly two positions, the flat-histogram fixpoint at count `2` makes every variant extremal via the (max == min == 2) collapse, T::count_extremal_variants reports T::CARDINALITY >= 1, and `!(&doubled_full_set).is_empty()`; a `false` doubled-full-set arm silently bifurcates the second flat-histogram `true`-arm catch",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
T::has_extremal_variant(&matching_singleton),
"{type_name}: T::has_extremal_variant([{target_label:?}]) != true at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` under T::is_modal_variant_of so T::is_extremal_variant_of holds on it via the disjunction arm, T::count_extremal_variants reports T::CARDINALITY >= 1, and `!(&[{target_label:?}]).is_empty()`; a `false` matching-singleton arm at cardinality >= 2 silently bifurcates the LOAD-BEARING `true`-arm catch DISCRIMINATING this union existence corner from `has_bimodal_variant` which reports `false` on the same fixture (the non-flat sparse histogram has no flat-diagonal inhabitant even though every variant is extremal)",
);
}
}
if T::CARDINALITY >= 3 {
// Extremal existence fixture — the LOAD-BEARING `true`-arm
// catch DISCRIMINATING this union existence corner from
// [`Self::has_bimodal_variant`]'s `false`-arm on the SAME
// fixture at cardinality `>= 3`. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2..] at
// count `0 == min`; T::ALL[0] is at the argmax band under
// T::is_modal_variant_of so T::is_extremal_variant_of holds
// on it via the disjunction arm, T::count_extremal_variants
// reports `T::CARDINALITY - 1` (all but the middle-band
// T::ALL[1]), and `!(&bimodal_triple).is_empty()`.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert!(
T::has_extremal_variant(&bimodal_triple),
"{type_name}: T::has_extremal_variant(&bimodal_triple) != true — T::ALL[0] sits at count `2 == max` and is extremal via the union arm, T::count_extremal_variants reports T::CARDINALITY - 1 (>= 1), and `!(&bimodal_triple).is_empty()`; a `false` bimodal-triple arm silently bifurcates the LOAD-BEARING `true`-arm catch DISCRIMINATING this union existence corner from `has_bimodal_variant` which reports `false` on the same fixture (the non-flat histogram has no flat-diagonal inhabitant)",
);
let via_bit = T::has_extremal_variant(&bimodal_triple);
let via_any = T::ALL
.iter()
.copied()
.any(|v| T::is_extremal_variant_of(v, &bimodal_triple));
assert_eq!(
via_bit, via_any,
"{type_name}: T::has_extremal_variant(&bimodal_triple) drifted from T::ALL.iter().copied().any(|v| T::is_extremal_variant_of(v, &bimodal_triple)) — the existential-lift identity MUST hold on every slice; a projection that detaches from the naive per-target existential sweep bifurcates loudly on the non-flat middle-band fixture where BOTH sides collapse to `true` for distinct reasons (LHS via `!items.is_empty()` past the non-emptiness collapse SHARPENING, RHS via the per-target `is_extremal_variant_of` sweep hitting the argmax target T::ALL[0])",
);
}
// (150) — `T::extremal_variants(items)` MUST agree with the
// declaration-order-preserving union witness-collection over the
// [`T::variant_counts`] histogram on every slice AND MUST land on
// its FOUR canonical fixpoints (empty vector on the empty slice
// UNCONDITIONALLY past the (max == min == 0, every-count == 0)
// degenerate arm where an unguarded sweep would silently return
// `T::ALL.to_vec()`; `T::ALL.to_vec()` on the full-set slice
// UNCONDITIONALLY via the flat-histogram fixpoint (max == min ==
// 1) where every variant sits at BOTH extremes and is extremal;
// `T::ALL.to_vec()` on the doubled-full-set slice UNCONDITIONALLY
// via the second flat-histogram fixpoint at count `2`;
// `T::ALL.to_vec()` on every matching-singleton slice at
// cardinality `>= 2` because the sole position hits the target at
// count `1 == max` under [`T::is_modal_variant_of`] while every
// non-target variant sits at count `0 == min` under
// [`T::is_antimodal_variant_of`], and the union arm collects every
// variant of [`T::ALL`]) AND on ONE length-composition arm against
// [`T::count_extremal_variants`] on the bimodal-triple fixture at
// cardinality `>= 3`:
// `T::extremal_variants(&bimodal_triple).len() == T::count_extremal_variants(&bimodal_triple)`
// MUST hold, pinning the plural-vs-cardinality identity on the
// load-bearing non-flat fixture where BOTH sides collapse to
// `T::CARDINALITY - 1` (the middle-band `T::ALL[1]` is excluded).
//
// The canonical fixpoints + one length-composition arm partition
// failure modes at the (set-level × Vec<Self> × direction-
// composition × union) corner simultaneously: an override that
// omits the empty-slice guard fires on the empty-slice arm
// (returns `T::ALL.to_vec()` rather than the empty vector past
// the (max == min == 0, every-count == 0) degenerate arm where
// every variant satisfies `count == max == min == 0`); an
// override that folds onto `Vec::new()` unconditionally fires on
// every non-empty flat-histogram fixpoint arm (full-set, doubled-
// full-set, matching-singleton) AND on the bimodal-triple arm
// where the union arm inhabits `T::CARDINALITY - 1` variants; an
// override that walks a non-declaration order fires on the full-
// set + doubled-full-set arms via the element-for-element
// equality against `T::ALL`; an override that detaches the
// plural's LEN from [`T::count_extremal_variants`] on the bimodal
// triple bifurcates loudly at the length-composition arm.
//
// Sibling posture to clauses (127) + (129) one DIRECTION-
// COMPOSITION axis over: clauses (127) + (129) pin the (set-level
// × Vec<Self> × direction-anchored declaration-order) argmax +
// argmin witness-collection corners via [`T::modal_variants`] +
// [`T::antimodal_variants`]; THIS clause LIFTS the (set-level ×
// Vec<Self> × direction-composition × union) corner via
// [`T::extremal_variants`] under the max/min-fold-guarded
// filter, opening the (set-level × Vec<Self> × direction-
// composition) row past the direction-anchored pair. The default
// trait body threads the `is_empty()`-guarded max/min-fold-pair
// filter sweep verbatim and satisfies every fixpoint arm + the
// length-composition arm for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the declaration-order
// direction-composition union witness-collection surface every
// downstream extremal-witness consumer routes through.
assert_eq!(
T::extremal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::extremal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because every per-variant occurrence count collapses to 0 and an UNGUARDED T::ALL.iter().copied().filter(|v| count(v) == max || count(v) == min).collect() sweep would silently return T::ALL.to_vec() past the (max == min == 0, every-count == 0) degenerate arm where every variant satisfies `count == max == min == 0`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition union witness-collection consumer routes through",
);
let full_extremal_variants = T::extremal_variants(T::ALL);
assert_eq!(
full_extremal_variants.as_slice(),
T::ALL,
"{type_name}: T::extremal_variants(T::ALL) drifted from T::ALL element-for-element — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), every variant satisfies `count == max || count == min`, and the filter walks T::ALL in declaration order; an ordering divergence is the drift catch for an override that reorders the witnesses via `T::sorted_variants` or via any other non-declaration walk; a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR returns a proper subset of T::ALL on the flat-histogram fixpoint",
);
let doubled_extremal_variants = T::extremal_variants(&doubled_full_set);
assert_eq!(
doubled_extremal_variants.as_slice(),
T::ALL,
"{type_name}: T::extremal_variants(&doubled_full_set) drifted from T::ALL element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, max == min == 2, every variant is extremal via the flat-histogram fixpoint, and the filter hits every variant walked in declaration order; a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint contract",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_extremal = T::extremal_variants(&matching_singleton);
assert_eq!(
singleton_extremal.as_slice(),
T::ALL,
"{type_name}: T::extremal_variants([{target_label:?}]) drifted from T::ALL at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` under T::is_modal_variant_of AND every non-target variant sits at count `0 == min` under T::is_antimodal_variant_of, so every variant of T::ALL satisfies `count == max || count == min` via one of the two arms and the union collects every variant walked in declaration order; a shorter Vec at cardinality >= 2 silently bifurcates the LOAD-BEARING full-carrier arm DISCRIMINATING this UNION projection from T::modal_variants (which reports only `[{target_label:?}]` on the same fixture) and T::antimodal_variants (which reports every non-target variant)",
);
}
}
if T::CARDINALITY >= 3 {
// Length-composition arm on the bimodal-triple fixture: the
// plural's LEN MUST equal the just-lifted cardinality-count
// aggregate [`T::count_extremal_variants`] because both
// projections filter T::ALL under the same direction-
// composition predicate — the load-bearing non-flat middle-
// band fixture where BOTH sides collapse to `T::CARDINALITY
// - 1` (the middle-band T::ALL[1] is excluded), the SOLE
// canonical fixture where this projection returns a PROPER
// subset of T::ALL rather than the full carrier.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_extremal = T::extremal_variants(&bimodal_triple);
let bimodal_extremal_count = T::count_extremal_variants(&bimodal_triple);
assert_eq!(
bimodal_extremal.len(),
bimodal_extremal_count,
"{type_name}: T::extremal_variants(&bimodal_triple).len() drifted from T::count_extremal_variants(&bimodal_triple) — the plural's LEN MUST equal the just-lifted cardinality-count aggregate because both projections filter T::ALL under the same direction-composition predicate; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat middle-band fixture where BOTH sides collapse to T::CARDINALITY - 1 (the middle-band T::ALL[1] is excluded), the SOLE canonical fixture where this projection returns a PROPER subset of T::ALL rather than the full carrier",
);
assert_eq!(
bimodal_extremal.len(),
T::CARDINALITY - 1,
"{type_name}: T::extremal_variants(&bimodal_triple).len() != T::CARDINALITY - 1 — on the bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is (T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] -> 0 == min); the middle-band target T::ALL[1] is EXCLUDED and every other variant is included via one of the two extreme arms, so the union projection MUST return a Vec of length T::CARDINALITY - 1; a divergent bimodal-triple length silently bifurcates the SOLE canonical fixture witness this projection returns a PROPER subset of T::ALL",
);
}
// (151) — `T::middle_band_variants(items)` MUST agree with the
// declaration-order-preserving strict-interior witness-collection
// over the [`T::variant_counts`] histogram on every slice AND MUST
// land on its FOUR canonical `Vec::new()` fixpoints (empty vector
// on the empty slice UNCONDITIONALLY via the load-bearing empty-
// slice guard past the (max == min == 0, every-count == 0)
// degenerate arm where an unguarded sweep would still return
// `Vec::new()` but for the WRONG structural reason — every variant
// sits AT the collapsed max/min band, not strictly between; empty
// vector on the full-set slice UNCONDITIONALLY via the flat-
// histogram fixpoint (max == min == 1) where every variant sits at
// BOTH extremes and no variant is strictly between; empty vector
// on the doubled-full-set slice UNCONDITIONALLY via the second flat-
// histogram fixpoint at count `2`; empty vector on every matching-
// singleton slice at cardinality `>= 2` because the sole position
// hits the target at count `1 == max` under [`T::is_modal_variant_of`]
// while every non-target variant sits at count `0 == min` under
// [`T::is_antimodal_variant_of`], and no variant is strictly
// between the two extremes) AND on ONE bimodal-triple arm at
// cardinality `>= 3`:
// `T::middle_band_variants(&bimodal_triple) == vec![T::ALL[1]]`
// MUST hold, pinning the SOLE canonical non-empty fixture where
// this projection populates a proper subset of T::ALL — the middle-
// band inhabitant T::ALL[1] whose count `1` sits strictly between
// max `2` and min `0`, DUAL to clause (150)'s extremal bimodal-
// triple arm that returns T::CARDINALITY - 1 variants EXCEPT
// T::ALL[1].
//
// The canonical fixpoints + one bimodal-triple arm partition
// failure modes at the (set-level × Vec<Self> × direction-
// composition × complement) corner simultaneously: an override
// that omits the empty-slice guard fires nowhere on `&[]` (both
// arms of the strict-interior conjunction reduce to `0 != 0`
// false at every target so the strict-interior filter still
// returns `Vec::new()` on the empty slice) — the guard is LOAD-
// BEARING for STRUCTURAL correctness (the empty answer is a
// TYPED CONSEQUENCE of [`T::is_middle_band_variant_of`]'s non-
// emptiness precondition, not an accidental collision with the
// strict-interior filter arm on the (max == min == 0) degenerate
// histogram); an override that folds onto `T::ALL.to_vec()`
// unconditionally fires on EVERY canonical fixpoint arm (empty,
// full-set, doubled-full-set, matching-singleton, bimodal-triple)
// via the element-for-element inequality against the empty vector
// OR the single-inhabitant expected result; an override that
// detaches the plural's LEN from [`T::count_middle_band_variants`]
// on the bimodal triple bifurcates loudly at the length-composition
// arm (bimodal LEN MUST equal `1`, the just-lifted middle-band
// cardinality-count aggregate); an override that walks a non-
// declaration order fires nowhere on the canonical fixpoints (each
// yields either `Vec::new()` or a singleton whose order is trivial)
// but the assertion also pins the plural-vs-cardinality identity
// on the bimodal fixture as a length probe distinct from element
// equality.
//
// Sibling posture to clause (150) one COMBINATOR axis over:
// clause (150) pins the (set-level × Vec<Self> × direction-
// composition × union) argmax + argmin witness-collection corner
// via [`T::extremal_variants`] under the max/min-fold-guarded
// filter; THIS clause LIFTS the (set-level × Vec<Self> × direction-
// composition × complement) middle-band witness-collection corner
// via [`T::middle_band_variants`] under the SAME max/min-fold pair
// filtered by the STRICT interior conjunction `c != max && c != min`,
// closing the (set-level × Vec<Self> × direction-composition) row
// past the direction-anchored pair AND the union arm. The default
// trait body threads the `is_empty()`-guarded max/min-fold-pair
// strict-interior filter sweep verbatim and satisfies every
// fixpoint arm + the bimodal-triple arm for free; the assertion
// catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the
// declaration-order direction-composition complement witness-
// collection surface every downstream middle-band-witness consumer
// routes through.
assert_eq!(
T::middle_band_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::middle_band_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because [`T::is_middle_band_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to `Vec::new()`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition complement witness-collection consumer routes through",
);
let full_middle_band = T::middle_band_variants(T::ALL);
assert_eq!(
full_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::middle_band_variants(T::ALL) drifted from Vec::new() — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and NO variant sits strictly between the two extremes; a non-empty full-set value silently bifurcates the LOAD-BEARING flat-histogram empty-collection arm DISCRIMINATING this COMPLEMENT projection from T::extremal_variants (which reports T::ALL.to_vec() on the same fixture)",
);
let doubled_middle_band = T::middle_band_variants(&doubled_full_set);
assert_eq!(
doubled_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::middle_band_variants(&doubled_full_set) drifted from Vec::new() — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the flat-histogram fixpoint, and NO variant is strictly between; a non-empty doubled-full-set value silently bifurcates the second flat-histogram empty-collection arm",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_middle_band = T::middle_band_variants(&matching_singleton);
assert_eq!(
singleton_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::middle_band_variants([{target_label:?}]) drifted from Vec::new() at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` under T::is_modal_variant_of AND every non-target variant sits at count `0 == min` under T::is_antimodal_variant_of, so every variant is extremal via one of the two arms and none sits strictly between; a non-empty matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING empty-collection arm DISCRIMINATING this COMPLEMENT projection from T::extremal_variants (which reports T::ALL.to_vec() on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the SOLE canonical NON-EMPTY
// witness of the middle-band Vec-return projection — the
// middle-band inhabitant T::ALL[1] sits at count `1` strictly
// between max `2` and min `0`, and every other variant sits
// at some extreme. DUAL of clause (150)'s bimodal-triple arm
// one COMBINATOR axis over (which returns T::CARDINALITY - 1
// variants EXCEPT T::ALL[1]).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_middle_band = T::middle_band_variants(&bimodal_triple);
let bimodal_middle_band_count = T::count_middle_band_variants(&bimodal_triple);
assert_eq!(
bimodal_middle_band.len(),
bimodal_middle_band_count,
"{type_name}: T::middle_band_variants(&bimodal_triple).len() drifted from T::count_middle_band_variants(&bimodal_triple) — the plural's LEN MUST equal the just-lifted cardinality-count aggregate because both projections filter T::ALL under the same direction-composition predicate; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat middle-band fixture where BOTH sides collapse to `1` (only T::ALL[1] sits strictly between the two extremes)",
);
assert_eq!(
bimodal_middle_band.as_slice(),
&[T::ALL[1]],
"{type_name}: T::middle_band_variants(&bimodal_triple) != vec![T::ALL[1]] — on the bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` the histogram is (T::ALL[0] -> 2 == max, T::ALL[1] -> 1 == MIDDLE, T::ALL[2..] -> 0 == min); T::ALL[1] is the SOLE inhabitant sitting strictly between max `2` and min `0`, so the complement projection MUST return the singleton `vec![T::ALL[1]]`; a divergent bimodal-triple value silently bifurcates the SOLE canonical fixture where this projection populates a proper subset of T::ALL — every other canonical fixpoint pins it to `Vec::new()`",
);
}
// (152) — `T::sorted_middle_band_variants(items)` MUST agree with
// the lex-order-preserving direction-composition complement witness-
// collection over the [`T::variant_counts`] histogram on every slice
// AND MUST land on its FIVE canonical fixpoints (empty vector on the
// empty slice UNCONDITIONALLY, empty vector on the full-set slice
// UNCONDITIONALLY, empty vector on the doubled-full-set slice
// UNCONDITIONALLY, empty vector on every matching singleton at
// cardinality `>= 2` UNCONDITIONALLY, `vec![T::ALL[1]]` on the
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality
// `>= 3` UNCONDITIONALLY). The bimodal-triple arm is the SOLE
// canonical NON-EMPTY fixture; the other four arms are the four
// FLAT-HISTOGRAM (or (max == min == 0) empty) fixpoints where every
// variant sits at some extreme.
//
// Sibling posture to clause (151) one ORDERING axis over: clause
// (151) pins the (set-level × `Vec<Self>` × direction-composition ×
// complement × declaration-order) middle-band witness-collection
// corner via [`T::middle_band_variants`] under the `T::ALL.iter()
// .copied()` walk; THIS clause LIFTS the (set-level × `Vec<Self>` ×
// direction-composition × complement × lex-order) middle-band
// witness-collection corner via [`T::sorted_middle_band_variants`]
// under the SAME max/min-fold-guarded strict-interior filter but
// walked over [`T::sorted_variants`] instead — CLOSING the (set-
// level × `Vec<Self>` × direction-composition × complement ×
// ordering) 2-corner face at its lex-arm past the declaration-arm
// clause (151) opened. Aligned with clauses (128) + (130) one
// COMBINATOR axis over (which close the same lex-arm on the argmax
// + argmin direction-anchored corners): together with clauses (127),
// (128), (129), (130), (150), (151), (152), the (set-level ×
// `Vec<Self>` × direction-composition × ordering) 5×2 grid at the
// (declaration-anchor × ordering) full 2-corner width now closes
// for every direction-composition inhabitant (argmax, argmin,
// union, complement) — the intersection arm (bimodal_variants)
// remains the sole remaining Vec-return direction-composition
// corner.
//
// The default trait body threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().filter(|&v|
// { let c = T::count_occurrences_of(v, items); c != max && c !=
// min }).collect()` sweep verbatim and satisfies every fixpoint arm
// + the bimodal-triple non-empty arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the lex-order direction-
// composition complement witness-collection surface every downstream
// alphabetic-middle-band consumer routes through. An override that
// omits the empty-slice guard bifurcates on the empty-slice arm
// (returns `Vec::new()` too but for the WRONG structural reason —
// every variant sits AT the collapsed max == min == 0 band, not
// strictly between; the guard makes the empty-slice answer a TYPED
// CONSEQUENCE of the non-emptiness precondition
// [`T::is_middle_band_variant_of`] carries at every target); an
// override that folds onto `Vec::new()` unconditionally bifurcates
// on the bimodal-triple arm (returns empty rather than the
// singleton `vec![T::ALL[1]]`); an override that folds onto
// `T::sorted_variants()` (or `T::ALL.to_vec()`) unconditionally
// fires on EVERY canonical fixpoint arm via the element-for-element
// inequality against the empty vector OR the single-inhabitant
// expected result; an override that detaches the plural's LEN from
// [`T::count_middle_band_variants`] on the bimodal triple bifurcates
// loudly at the length-composition arm (bimodal LEN MUST equal `1`,
// the just-lifted middle-band cardinality-count aggregate); an
// override that returns a lex-order permutation of anything other
// than the strict-interior filter fires nowhere on the canonical
// fixpoints (each yields either `Vec::new()` or a singleton whose
// order is trivial) but the assertion also pins the plural-vs-
// cardinality identity on the bimodal fixture as a length probe
// distinct from element equality.
assert_eq!(
T::sorted_middle_band_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_middle_band_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because [`T::is_middle_band_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to `Vec::new()`; a non-empty empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition complement witness-collection consumer routes through",
);
let full_sorted_middle_band = T::sorted_middle_band_variants(T::ALL);
assert_eq!(
full_sorted_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_middle_band_variants(T::ALL) drifted from Vec::new() — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner at the LEX arm), every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and NO variant sits strictly between the two extremes; a non-empty full-set value silently bifurcates the LOAD-BEARING flat-histogram empty-collection arm DISCRIMINATING this LEX-ORDER COMPLEMENT projection from T::sorted_variants (which the drift catch for an override that folds onto `T::sorted_variants()` unconditionally hits at this arm)",
);
let doubled_sorted_middle_band = T::sorted_middle_band_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_middle_band_variants(&doubled_full_set) drifted from Vec::new() — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the flat-histogram fixpoint, and NO variant is strictly between; a non-empty doubled-full-set value silently bifurcates the second flat-histogram empty-collection arm at the lex-order arm",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_middle_band = T::sorted_middle_band_variants(&matching_singleton);
assert_eq!(
singleton_sorted_middle_band,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_middle_band_variants([{target_label:?}]) drifted from Vec::new() at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` under T::is_modal_variant_of AND every non-target variant sits at count `0 == min` under T::is_antimodal_variant_of, so every variant is extremal via one of the two arms and none sits strictly between; a non-empty matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING empty-collection arm at the lex-order arm DISCRIMINATING this COMPLEMENT projection from T::extremal_variants (which reports T::ALL.to_vec() on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the SOLE canonical NON-EMPTY witness
// of the sorted middle-band Vec-return projection — the middle-
// band inhabitant T::ALL[1] sits at count `1` strictly between
// max `2` and min `0`, and every other variant sits at some
// extreme. On this fixture the (declaration vs lex) ordering
// axis DEGENERATES (there is only one middle-band inhabitant,
// so any walk order yields the same singleton), so the value
// agrees with clause (151)'s middle_band_variants arm at the
// same fixture — the LENGTH probe distinguishes the two
// projections' cardinality-composition identity independently
// of walk order.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_sorted_middle_band = T::sorted_middle_band_variants(&bimodal_triple);
let bimodal_sorted_middle_band_count = T::count_middle_band_variants(&bimodal_triple);
assert_eq!(
bimodal_sorted_middle_band.len(),
bimodal_sorted_middle_band_count,
"{type_name}: T::sorted_middle_band_variants(&bimodal_triple).len() drifted from T::count_middle_band_variants(&bimodal_triple) — the plural's LEN MUST equal the just-lifted cardinality-count aggregate because both projections filter under the same direction-composition predicate and ordering does NOT affect cardinality; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat middle-band fixture where BOTH sides collapse to `1`",
);
assert_eq!(
bimodal_sorted_middle_band.as_slice(),
&[T::ALL[1]],
"{type_name}: T::sorted_middle_band_variants(&bimodal_triple) != vec![T::ALL[1]] — on the bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` T::ALL[1] is the SOLE inhabitant sitting strictly between max `2` and min `0`, so the lex-order complement projection MUST return the singleton `vec![T::ALL[1]]` regardless of walk order (the ordering axis DEGENERATES on the single-inhabitant middle band); a divergent bimodal-triple value silently bifurcates the SOLE canonical fixture where this projection populates a proper subset of T::sorted_variants — every other canonical fixpoint pins it to `Vec::new()`",
);
}
// (153) — `T::sorted_extremal_variants(items)` MUST agree with the
// lex-order-preserving direction-composition union witness-
// collection over the [`T::variant_counts`] histogram on every
// slice AND MUST land on its FIVE canonical fixpoints (empty
// vector on the empty slice UNCONDITIONALLY via the load-bearing
// empty-slice guard past the (max == min == 0, every-count == 0)
// degenerate arm where an unguarded sweep would collapse the
// union predicate `c == max || c == min` onto `true` at every
// variant and return `T::sorted_variants()` — the WRONG
// structural answer; `T::sorted_variants()` on the full-set slice
// UNCONDITIONALLY via the flat-histogram fixpoint (max == min ==
// 1) where every variant sits at BOTH extremes simultaneously and
// the union filter matches everything walked in lex order;
// `T::sorted_variants()` on the doubled-full-set slice
// UNCONDITIONALLY via the second flat-histogram fixpoint at
// count `2`; `T::sorted_variants()` on every matching singleton at
// cardinality `>= 2` UNCONDITIONALLY via the (target -> 1 == max,
// non-target -> 0 == min) split where every variant is extremal
// via one of the two arms; a Vec of length `T::CARDINALITY - 1`
// on the bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` at
// cardinality `>= 3` via the (T::ALL[0] -> max, T::ALL[1] ->
// MIDDLE-EXCLUDED, T::ALL[2..] -> min) split where every non-
// middle-band variant is included via one of the two arms).
//
// Sibling posture to clause (150) one ORDERING axis over: clause
// (150) pins the (set-level × `Vec<Self>` × direction-composition
// × union × declaration-order) extremal witness-collection corner
// via [`T::extremal_variants`] under the `T::ALL.iter().copied()`
// walk; THIS clause LIFTS the (set-level × `Vec<Self>` ×
// direction-composition × union × lex-order) extremal witness-
// collection corner via [`T::sorted_extremal_variants`] under the
// SAME max/min-fold-guarded union filter but walked over
// [`T::sorted_variants`] instead — CLOSING the (set-level ×
// `Vec<Self>` × direction-composition × union × ordering) 2-corner
// face at its lex-arm past the declaration-arm clause (150) opened.
// Aligned with clauses (128) + (130) + (152) one COMBINATOR axis
// over (which close the same lex-arm on the argmax + argmin +
// complement direction-composition corners): together with clauses
// (127), (128), (129), (130), (150), (151), (152), (153), the
// (set-level × `Vec<Self>` × direction-composition × ordering)
// 4×2 grid at the (argmax, argmin, union, complement) inhabitants
// now closes for every direction-composition inhabitant at BOTH
// ordering arms — the intersection arm (bimodal_variants,
// sorted_bimodal_variants) is the sole pair of Vec-return
// direction-composition corners still open on the row.
//
// The default trait body threads the `is_empty()`-guarded
// `T::sorted_variants().into_iter().filter(|&v|
// { let c = T::count_occurrences_of(v, items); c == max || c ==
// min }).collect()` sweep verbatim and satisfies every fixpoint
// arm + the bimodal-triple non-empty arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the lex-order direction-
// composition union witness-collection surface every downstream
// alphabetic-extremal consumer routes through. An override that
// omits the empty-slice guard bifurcates on the empty-slice arm
// (returns `T::sorted_variants()` because `c == 0 == max == min`
// collapses the union predicate onto `true` everywhere); an
// override that folds onto `Vec::new()` unconditionally bifurcates
// on the full-set + doubled-full-set + matching-singleton +
// bimodal-triple arms (returns the empty vector rather than a
// non-empty result); an override that folds onto
// `T::sorted_variants()` unconditionally bifurcates on the
// bimodal-triple arm at cardinality >= 3 (returns the full sorted
// list of length T::CARDINALITY rather than the middle-band-
// excluded subset of length T::CARDINALITY - 1); an override that
// detaches the plural's LEN from [`T::count_extremal_variants`] on
// the bimodal triple bifurcates loudly at the length-composition
// arm (bimodal LEN MUST equal T::CARDINALITY - 1, the just-lifted
// extremal cardinality-count aggregate); an override that returns
// a lex-order permutation of anything other than the union filter
// fires nowhere on the flat-histogram fixpoints (each yields the
// full sorted list whose order matches T::sorted_variants) but
// the assertion also pins the plural-vs-cardinality identity on
// the bimodal fixture as a length probe distinct from element
// equality.
assert_eq!(
T::sorted_extremal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_extremal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because [`T::is_extremal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to `Vec::new()`; a non-empty empty-slice value (in particular `T::sorted_variants()` from an unguarded sweep where `c == 0 == max == min` collapses the union predicate onto `true` everywhere) silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition union witness-collection consumer routes through",
);
let full_sorted_extremal = T::sorted_extremal_variants(T::ALL);
let sorted_variants = T::sorted_variants();
assert_eq!(
full_sorted_extremal,
sorted_variants,
"{type_name}: T::sorted_extremal_variants(T::ALL) drifted from T::sorted_variants() — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner at the LEX arm), every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and EVERY variant is extremal; a value that omits any variant of T::sorted_variants silently bifurcates the LOAD-BEARING flat-histogram full-coverage arm DISCRIMINATING this LEX-ORDER UNION projection from T::sorted_middle_band_variants (which reports Vec::new() on the same fixture)",
);
let doubled_sorted_extremal = T::sorted_extremal_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_extremal,
sorted_variants,
"{type_name}: T::sorted_extremal_variants(&doubled_full_set) drifted from T::sorted_variants() — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the flat-histogram fixpoint at the lex-order arm, and every variant is extremal; a value that omits any variant silently bifurcates the second flat-histogram full-coverage arm at the lex-order arm",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_extremal = T::sorted_extremal_variants(&matching_singleton);
assert_eq!(
singleton_sorted_extremal,
sorted_variants,
"{type_name}: T::sorted_extremal_variants([{target_label:?}]) drifted from T::sorted_variants() at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` under T::is_modal_variant_of AND every non-target variant sits at count `0 == min` under T::is_antimodal_variant_of, so every variant is extremal via one of the two arms walked in lex order; a value that omits any variant of T::sorted_variants silently bifurcates the LOAD-BEARING full-coverage arm at the lex-order arm DISCRIMINATING this UNION projection from T::sorted_middle_band_variants (which reports Vec::new() on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the SOLE canonical PROPER-SUBSET
// witness of the sorted extremal Vec-return projection — the
// middle-band inhabitant T::ALL[1] sits at count `1` strictly
// between max `2` and min `0` and is EXCLUDED from the union
// arm, while T::ALL[0] (at max) and T::ALL[2..] (at min) are
// INCLUDED via one of the two arms. On this fixture the
// (declaration vs lex) ordering axis DIVERGES for T::CARDINALITY
// >= 4 (the max-arm inhabitant T::ALL[0] sits at index 0 under
// both walks by coincidence of the canonical label ordering,
// but the min-arm inhabitants T::ALL[2..] may reorder under
// lex sort); the LENGTH probe binds the plural-vs-cardinality
// identity independently of walk order via
// T::count_extremal_variants.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_sorted_extremal = T::sorted_extremal_variants(&bimodal_triple);
let bimodal_sorted_extremal_count = T::count_extremal_variants(&bimodal_triple);
assert_eq!(
bimodal_sorted_extremal.len(),
bimodal_sorted_extremal_count,
"{type_name}: T::sorted_extremal_variants(&bimodal_triple).len() drifted from T::count_extremal_variants(&bimodal_triple) — the plural's LEN MUST equal the just-lifted cardinality-count aggregate because both projections filter under the same direction-composition predicate and ordering does NOT affect cardinality; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat extremal fixture where BOTH sides collapse to `T::CARDINALITY - 1`",
);
assert_eq!(
bimodal_sorted_extremal.len(),
T::CARDINALITY - 1,
"{type_name}: T::sorted_extremal_variants(&bimodal_triple).len() != T::CARDINALITY - 1 — on the bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` T::ALL[1] is the SOLE middle-band inhabitant and every other variant is extremal via one of the two arms, so the lex-order union projection MUST return a Vec of length T::CARDINALITY - 1; a divergent bimodal-triple length silently bifurcates the SOLE canonical fixture witness this projection returns a PROPER subset of T::sorted_variants",
);
// The bimodal_triple result is a lex-order slice of
// T::sorted_variants with the middle-band inhabitant T::ALL[1]
// filtered out. Pin the value against the lex-order set-
// difference of T::sorted_variants and vec![T::ALL[1]] to
// catch overrides that agree on cardinality but drift on
// element identity (e.g. an override that returns
// T::sorted_variants intact — the drift would slip past a
// pure length probe on cardinality >= 3 only if the length
// arm is also drifted; both arms together pin the projection
// to its unique inhabitant on the canonical bimodal fixture).
let expected_bimodal_lex: ::std::vec::Vec<T> = T::sorted_variants()
.into_iter()
.filter(|&v| <T as ClosedSet>::index_of(v) != <T as ClosedSet>::index_of(T::ALL[1]))
.collect();
assert_eq!(
bimodal_sorted_extremal,
expected_bimodal_lex,
"{type_name}: T::sorted_extremal_variants(&bimodal_triple) != T::sorted_variants() minus T::ALL[1] — on the bimodal triple the lex-order union projection MUST return T::sorted_variants() with T::ALL[1] (the SOLE middle-band inhabitant) filtered out; a divergent value silently bifurcates the SOLE canonical fixture where this projection populates a strict-proper subset of T::sorted_variants at a cardinality distinct from `Vec::new()` and `T::sorted_variants()`",
);
}
// (154) — `T::bimodal_variants(items)` MUST agree with the
// uniformity-collapse SHARPENING `if items.is_empty() ||
// !T::is_uniform(items) { Vec::new() } else { T::ALL.to_vec() }`
// on every slice AND MUST agree with the naive filter reduction
// `T::ALL.iter().copied().filter(|&v| T::is_bimodal_variant_of(v,
// items)).collect()` on every slice AND MUST land on its canonical
// fixpoints (`Vec::new()` on the empty slice UNCONDITIONALLY past
// the vacuous (min == max == 0) flat-histogram collapse of
// T::is_uniform via the LOAD-BEARING empty-slice guard where an
// unguarded branch would silently return T::ALL.to_vec();
// `T::ALL.to_vec()` on the full-set slice via the flat-histogram
// fixpoint (max == min == 1) of T::is_uniform where every variant
// sits at BOTH extremes simultaneously; `T::ALL.to_vec()` on the
// doubled-full-set slice via the second flat-histogram fixpoint
// (max == min == 2); `Vec::new()` on every matching singleton at
// cardinality `>= 2` because the sole-position target sits at
// count `1 == max` while every non-target variant sits at count
// `0 == min`, so the histogram is non-flat (max `1` != min `0`),
// T::is_uniform reports `false`, and the dichotomy lands on
// `Vec::new()`; `Vec::new()` on the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — the
// histogram is non-flat (max `2` != min `0`), so T::is_uniform
// reports `false` and the dichotomy lands on `Vec::new()`) AND on
// ONE length-composition arm against [`T::count_bimodal_variants`]
// on the bimodal-triple fixture at cardinality `>= 3`:
// `T::bimodal_variants(&bimodal_triple).len() ==
// T::count_bimodal_variants(&bimodal_triple)` MUST hold, pinning
// the plural-vs-cardinality identity independently.
//
// Sibling posture to clause (143) one RETURN-SHAPE axis over:
// clause (143) pins the (set-level × usize × intersection)
// uniformity-collapse cardinality via [`T::count_bimodal_variants`]
// under the SAME `is_empty() || !is_uniform(items)` dichotomy;
// THIS clause LIFTS it to the (set-level × `Vec<Self>` ×
// intersection) witness-collection via
// [`T::bimodal_variants`] under the SAME dichotomy but returning
// the collected variants rather than the count. Aligned with
// clause (150) one COMBINATOR axis over (which pins the
// declaration-order union arm via [`T::extremal_variants`]) and
// clause (151) one COMBINATOR axis over (which pins the
// declaration-order complement arm via
// [`T::middle_band_variants`]): together with clauses (127) +
// (129) + (150) + (151), the (set-level × `Vec<Self>` ×
// direction-composition × declaration-order) row now closes for
// every direction-composition inhabitant — the argmax
// ([`T::modal_variants`]), argmin ([`T::antimodal_variants`]),
// union ([`T::extremal_variants`]), complement
// ([`T::middle_band_variants`]), AND intersection
// ([`T::bimodal_variants`]) corners are all pinned at the
// declaration-order arm on the modal-aggregation matrix.
//
// The default trait body threads the `is_empty() ||
// !is_uniform(items)` dichotomy verbatim and satisfies every
// fixpoint arm + the length-composition arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level intersection
// witness-collection surface every downstream flat-diagonal
// consumer routes through. An override that folds onto `Vec::new()`
// unconditionally bifurcates on BOTH flat-histogram fixpoint arms
// (full-set and doubled-full-set) at `Vec::new() != T::ALL.to_vec()`;
// an override that folds onto `T::ALL.to_vec()` unconditionally
// bifurcates on the empty-slice arm at `T::ALL.to_vec() !=
// Vec::new()` AND on every matching-singleton arm at cardinality
// `>= 2` AND on the bimodal-triple arm at cardinality `>= 3`; an
// override that omits the empty-slice guard and returns
// `T::ALL.to_vec()` on `&[]` past the vacuous (min == max == 0)
// flat-histogram collapse of T::is_uniform bifurcates loudly at
// the empty-slice fixpoint; an override that detaches the plural's
// LEN from [`T::count_bimodal_variants`] on the bimodal triple
// bifurcates loudly at the length-composition arm (bimodal LEN
// MUST equal `0`, the just-pinned intersection cardinality-count
// aggregate on the non-flat fixture).
assert_eq!(
T::bimodal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::bimodal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because [`T::is_bimodal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to `Vec::new()`; a non-empty empty-slice value (in particular `T::ALL.to_vec()` from an unguarded branch where the vacuous (max == min == 0) flat-histogram collapse of T::is_uniform silently reports `true`) silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition intersection witness-collection consumer routes through",
);
let full_bimodal_variants = T::bimodal_variants(T::ALL);
let full_all: ::std::vec::Vec<T> = T::ALL.to_vec();
assert_eq!(
full_bimodal_variants,
full_all,
"{type_name}: T::bimodal_variants(T::ALL) drifted from T::ALL element-for-element — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), T::is_uniform reports `true`, every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and the dichotomy MUST land on T::ALL.to_vec(); an ordering divergence is the drift catch for an override that reorders the witnesses via `T::sorted_variants` or via any other non-declaration walk; a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR returns a proper subset of T::ALL on the flat-histogram fixpoint",
);
let doubled_bimodal_variants = T::bimodal_variants(&doubled_full_set);
assert_eq!(
doubled_bimodal_variants,
full_all,
"{type_name}: T::bimodal_variants(&doubled_full_set) drifted from T::ALL element-for-element — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, max == min == 2, T::is_uniform reports `true`, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and the dichotomy MUST land on T::ALL.to_vec(); a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint contract",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_bimodal = T::bimodal_variants(&matching_singleton);
assert_eq!(
singleton_bimodal,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::bimodal_variants([{target_label:?}]) drifted from Vec::new() at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so the histogram is non-flat (max `1` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on Vec::new(); a non-empty matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING empty-collection arm DISCRIMINATING this INTERSECTION projection from T::extremal_variants (which reports T::ALL.to_vec() on the same fixture via the (max ∨ min) union covering every variant through one of the two arms)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `Vec::new()`-arm
// catch on the intersection witness-collection corner. The
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits
// T::ALL[0] at count `2 == max`, T::ALL[1] at count `1`
// (MIDDLE), T::ALL[2] at count `0 == min`; the histogram is
// non-flat (max `2` != min `0`), so T::is_uniform reports
// `false` and the dichotomy lands on Vec::new(). The LOAD-
// BEARING catch that separates the intersection witness-
// collection from [`T::extremal_variants`] (which reports
// `T::CARDINALITY - 1` variants on the same fixture).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_intersection = T::bimodal_variants(&bimodal_triple);
assert_eq!(
bimodal_intersection,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::bimodal_variants(&bimodal_triple) drifted from Vec::new() — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on Vec::new(); a non-empty bimodal-triple value silently bifurcates the LOAD-BEARING Vec::new()-arm catch that separates the intersection witness-collection from T::extremal_variants (which reports T::CARDINALITY - 1 variants on the same fixture — the argmax and argmin endpoints minus the middle-band inhabitant)",
);
assert_eq!(
bimodal_intersection.len(),
T::count_bimodal_variants(&bimodal_triple),
"{type_name}: T::bimodal_variants(&bimodal_triple).len() drifted from T::count_bimodal_variants(&bimodal_triple) — the plural's LEN MUST equal the just-lifted cardinality-count aggregate because both projections filter T::ALL under the same intersection dichotomy; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat middle-band fixture where BOTH sides collapse to `0` (LHS via the empty Vec's length, RHS via the sharpened scalar branch reporting `0` on the non-uniform arm)",
);
}
// (155) — `T::sorted_bimodal_variants(items)` MUST agree with the
// uniformity-collapse SHARPENING `if items.is_empty() ||
// !T::is_uniform(items) { Vec::new() } else { T::sorted_variants() }`
// on every slice AND MUST agree with the naive filter reduction
// `T::sorted_variants().into_iter().filter(|&v|
// T::is_bimodal_variant_of(v, items)).collect()` on every slice AND
// MUST land on its canonical fixpoints (`Vec::new()` on the empty
// slice UNCONDITIONALLY past the vacuous (min == max == 0) flat-
// histogram collapse of T::is_uniform via the LOAD-BEARING empty-
// slice guard where an unguarded branch would silently return
// T::sorted_variants(); `T::sorted_variants()` on the full-set slice
// via the flat-histogram fixpoint (max == min == 1) of T::is_uniform
// where every variant sits at BOTH extremes simultaneously walked
// in lex order; `T::sorted_variants()` on the doubled-full-set slice
// via the second flat-histogram fixpoint (max == min == 2);
// `Vec::new()` on every matching singleton at cardinality `>= 2`
// because the sole-position target sits at count `1 == max` while
// every non-target variant sits at count `0 == min`, so the
// histogram is non-flat (max `1` != min `0`), T::is_uniform reports
// `false`, and the dichotomy lands on `Vec::new()`; `Vec::new()` on
// the bimodal-triple fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at
// cardinality `>= 3` — the histogram is non-flat (max `2` != min
// `0`), so T::is_uniform reports `false` and the dichotomy lands on
// `Vec::new()`) AND on ONE length-composition arm against
// [`T::count_bimodal_variants`] on the bimodal-triple fixture at
// cardinality `>= 3`: `T::sorted_bimodal_variants(&bimodal_triple).len()
// == T::count_bimodal_variants(&bimodal_triple)` MUST hold, pinning
// the plural-vs-cardinality identity independently of walk order.
//
// Sibling posture to clause (154) one ORDERING axis over: clause
// (154) pins the (set-level × `Vec<Self>` × direction-composition
// × intersection × declaration-order) bimodal witness-collection
// corner via [`T::bimodal_variants`] under the `T::ALL.to_vec()`
// walk on the uniform arm; THIS clause LIFTS the (set-level ×
// `Vec<Self>` × direction-composition × intersection × lex-order)
// bimodal witness-collection corner via
// [`T::sorted_bimodal_variants`] under the SAME uniformity-collapse
// dichotomy but returning [`T::sorted_variants`] instead of
// `T::ALL.to_vec()` on the non-empty uniform arm — CLOSING the
// (set-level × `Vec<Self>` × direction-composition × intersection
// × ordering) 2-corner face at its lex-arm past the declaration-arm
// clause (154) opened. Aligned with clauses (128) + (130) + (152)
// + (153) one COMBINATOR axis over (which close the same lex-arm
// on the argmax + argmin + complement + union direction-composition
// corners): together with clauses (127), (128), (129), (130), (150),
// (151), (152), (153), (154), the (set-level × `Vec<Self>` ×
// direction-composition × ordering) 5×2 grid at the (argmax, argmin,
// union, complement, intersection) inhabitants NOW CLOSES FOR EVERY
// direction-composition inhabitant at BOTH ordering arms — the
// Vec-return direction-composition row of the modal-aggregation
// matrix is fully populated.
//
// The default trait body threads the `is_empty() ||
// !is_uniform(items)` dichotomy verbatim (returning
// T::sorted_variants() on the uniform non-empty arm and Vec::new()
// elsewhere) and satisfies every fixpoint arm + the length-
// composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order direction-composition
// intersection witness-collection surface every downstream
// alphabetic-flat-diagonal consumer routes through. An override
// that folds onto `Vec::new()` unconditionally bifurcates on BOTH
// flat-histogram fixpoint arms (full-set and doubled-full-set) at
// `Vec::new() != T::sorted_variants()`; an override that folds onto
// `T::sorted_variants()` unconditionally bifurcates on the empty-
// slice arm at `T::sorted_variants() != Vec::new()` AND on every
// matching-singleton arm at cardinality `>= 2` AND on the bimodal-
// triple arm at cardinality `>= 3`; an override that omits the
// empty-slice guard and returns `T::sorted_variants()` on `&[]`
// past the vacuous (min == max == 0) flat-histogram collapse of
// T::is_uniform bifurcates loudly at the empty-slice fixpoint; an
// override that detaches the plural's LEN from
// [`T::count_bimodal_variants`] on the bimodal triple bifurcates
// loudly at the length-composition arm (bimodal LEN MUST equal
// `0`, the intersection cardinality-count aggregate on the non-
// flat fixture); an override that returns a NON-LEX permutation
// on the uniform arms (e.g. `T::ALL.to_vec()` — the declaration-
// order sibling) bifurcates loudly whenever
// T::sorted_variants() diverges from T::ALL.to_vec() element-for-
// element.
assert_eq!(
T::sorted_bimodal_variants(empty),
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_bimodal_variants(&[]) drifted from Vec::new() — the empty-slice fixpoint MUST return the empty vector because [`T::is_bimodal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to `Vec::new()`; a non-empty empty-slice value (in particular `T::sorted_variants()` from an unguarded branch where the vacuous (max == min == 0) flat-histogram collapse of T::is_uniform silently reports `true`) silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition intersection witness-collection consumer routes through",
);
let full_sorted_bimodal = T::sorted_bimodal_variants(T::ALL);
assert_eq!(
full_sorted_bimodal,
sorted_variants,
"{type_name}: T::sorted_bimodal_variants(T::ALL) drifted from T::sorted_variants() — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner at the LEX arm), T::is_uniform reports `true`, every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and the dichotomy MUST land on T::sorted_variants(); an ordering divergence is the drift catch for an override that walks the witnesses via T::ALL (the declaration-order sibling one ORDERING axis over) rather than T::sorted_variants() — the drift fires whenever the enum's declaration order diverges from the ASCII-lex order of its labels; a shorter Vec is the drift catch for an override that folds onto `Vec::new()` unconditionally OR returns a proper subset of T::sorted_variants on the flat-histogram fixpoint",
);
let doubled_sorted_bimodal = T::sorted_bimodal_variants(&doubled_full_set);
assert_eq!(
doubled_sorted_bimodal,
sorted_variants,
"{type_name}: T::sorted_bimodal_variants(&doubled_full_set) drifted from T::sorted_variants() — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, max == min == 2, T::is_uniform reports `true`, every variant sits at BOTH extremes via the second flat-histogram fixpoint at the lex arm, and the dichotomy MUST land on T::sorted_variants(); a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint contract at the lex-order arm",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_bimodal = T::sorted_bimodal_variants(&matching_singleton);
assert_eq!(
singleton_sorted_bimodal,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_bimodal_variants([{target_label:?}]) drifted from Vec::new() at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so the histogram is non-flat (max `1` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on Vec::new(); a non-empty matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING empty-collection arm at the lex-order arm DISCRIMINATING this LEX-ORDER INTERSECTION projection from T::sorted_extremal_variants (which reports T::sorted_variants() on the same fixture via the (max ∨ min) union covering every variant through one of the two arms)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `Vec::new()`-arm
// catch on the LEX-ORDER intersection witness-collection
// corner. The bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// hits T::ALL[0] at count `2 == max`, T::ALL[1] at count `1`
// (MIDDLE), T::ALL[2] at count `0 == min`; the histogram is
// non-flat (max `2` != min `0`), so T::is_uniform reports
// `false` and the dichotomy lands on Vec::new(). The LOAD-
// BEARING catch that separates the LEX-ORDER intersection
// witness-collection from [`T::sorted_extremal_variants`]
// (which reports `T::CARDINALITY - 1` variants on the same
// fixture walked in lex order — the argmax and argmin
// endpoints minus the middle-band inhabitant).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_sorted_intersection = T::sorted_bimodal_variants(&bimodal_triple);
assert_eq!(
bimodal_sorted_intersection,
<::std::vec::Vec<T>>::new(),
"{type_name}: T::sorted_bimodal_variants(&bimodal_triple) drifted from Vec::new() — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on Vec::new(); a non-empty bimodal-triple value silently bifurcates the LOAD-BEARING Vec::new()-arm catch that separates the lex-order intersection witness-collection from T::sorted_extremal_variants (which reports T::CARDINALITY - 1 variants on the same fixture walked in lex order — the argmax and argmin endpoints minus the middle-band inhabitant)",
);
assert_eq!(
bimodal_sorted_intersection.len(),
T::count_bimodal_variants(&bimodal_triple),
"{type_name}: T::sorted_bimodal_variants(&bimodal_triple).len() drifted from T::count_bimodal_variants(&bimodal_triple) — the plural's LEN MUST equal the intersection cardinality-count aggregate because both projections filter under the same intersection dichotomy AND ordering does NOT affect cardinality; a divergent length silently bifurcates the plural-vs-cardinality identity on the load-bearing non-flat middle-band fixture where BOTH sides collapse to `0` (LHS via the empty Vec's length, RHS via the sharpened scalar branch reporting `0` on the non-uniform arm)",
);
}
// (156) — `T::extremal_variant(items)` MUST agree with the
// declaration-order-first-witness sweep `if items.is_empty() { None }
// else { T::ALL.iter().copied().find(|&v| { let c =
// T::count_occurrences_of(v, items); c == T::max_variant_count(items)
// || c == T::min_variant_count(items) }) }` on every slice AND MUST
// land on its canonical fixpoints (`None` on the empty slice
// UNCONDITIONALLY past the vacuous (max == min == 0, every-count ==
// 0) degenerate arm where an unguarded `find` sweep would silently
// return `Some(T::first())` — every variant satisfies the vacuous
// union predicate `c == 0 == max == min`; `Some(T::first())` on the
// full-set slice via the flat-histogram fixpoint (max == min == 1)
// where every variant is extremal and the declaration-order `find`
// sweep hits T::first() immediately; `Some(T::first())` on the
// doubled-full-set slice via the second flat-histogram fixpoint
// (max == min == 2); `Some(T::first())` on every matching singleton
// at cardinality `>= 1` because the sole-position target sits at
// count `1 == max` while every non-target variant sits at count
// `0 == min` — every variant of T::ALL satisfies `c == max || c ==
// min` and the declaration-order sweep hits T::first() immediately;
// `Some(T::ALL[0])` on the bimodal-triple fixture `[T::ALL[0],
// T::ALL[0], T::ALL[1]]` at cardinality `>= 3` — T::ALL[0] hits
// count `2 == max`, so the declaration-order sweep hits it
// immediately at the argmax band) AND on ONE first-witness-of-
// plural composition arm against `T::extremal_variants(items).first()`
// AND on ONE is-some-composition arm against
// [`T::has_extremal_variant`]: `T::extremal_variant(items).is_some()
// == T::has_extremal_variant(items)` MUST hold, pinning the
// Option-vs-bool return-shape identity independently of the first-
// witness value.
//
// Sibling posture to clauses (127), (129), (149) one DIRECTION-
// COMPOSITION axis over: clauses (127) + (129) pin the
// (set-level × `Option<Self>` × statistical-aggregate × direction ×
// declaration-order) argmax + argmin first-witness corners via
// [`T::modal_variant`] + [`T::antimodal_variant`]; clause (149)
// pins the (set-level × bool × statistical-aggregate × direction-
// composition × union × existential) union existence corner via
// [`T::has_extremal_variant`]; THIS clause LIFTS the (set-level ×
// `Option<Self>` × statistical-aggregate × direction-composition ×
// union) union declaration-order first-witness corner via
// [`T::extremal_variant`] one DIRECTION-COMPOSITION axis over from
// the argmax + argmin peers via the disjunctive predicate `c == max
// || c == min`. Together with clauses (127), (129), (149), (150),
// (152), the DIRECTION-COMPOSITION axis's UNION arm now carries typed
// projections at FIVE return-shapes: `usize` cardinality-count via
// [`T::count_extremal_variants`] (clause (152)), `Vec<Self>`
// witness-collection via [`T::extremal_variants`] (clause (150)),
// `bool` existence via [`T::has_extremal_variant`] (clause (149)),
// AND `Option<Self>` first-witness via [`T::extremal_variant`] (this
// clause) — the union corner on the modal-aggregation matrix now
// carries the FIRST-WITNESS projection complementing the plural
// collection, the existence bit, the cardinality count, and the
// per-target predicate at ONE canonical return-shape corner.
//
// The default trait body threads the `is_empty()` guard + max/min-
// fold + declaration-order `find` verbatim and satisfies every
// fixpoint arm + the first-witness-of-plural composition arm + the
// is-some-composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level direction-composition
// union first-witness surface every downstream one-outlier-name
// consumer routes through. An override that folds onto `None`
// unconditionally bifurcates on the full-set + doubled-full-set +
// matching-singleton + bimodal-triple fixpoint arms at `None !=
// Some(T::first())` / `Some(T::ALL[0])`; an override that folds
// onto `Some(T::first())` unconditionally bifurcates on the empty-
// slice arm at `Some(T::first()) != None`; an override that omits
// the empty-slice guard and returns `Some(T::first())` on `&[]`
// past the vacuous (max == min == 0) degenerate arm bifurcates
// loudly at the empty-slice fixpoint; an override that walks the
// witnesses via T::sorted_variants (the lex-order sibling one
// ORDERING axis over) bifurcates loudly whenever T::sorted_variants
// diverges from T::ALL element-for-element on the (or later) any
// matching-singleton arm where the sole target sits STRICTLY
// between T::first() and T::sorted_first() in the union band; an
// override that detaches the singular from the plural's `.first()`
// bifurcates loudly on the bimodal-triple fixture where LHS ==
// Some(T::ALL[0]) and RHS == extremal_variants[0] == T::ALL[0].
assert_eq!(
T::extremal_variant(empty),
None,
"{type_name}: T::extremal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because [`T::is_extremal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to None; a Some empty-slice value (in particular `Some(T::first())` from an unguarded `find` sweep where `c == 0 == max == min` vacuously satisfies the union predicate at every variant) silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition union first-witness consumer routes through",
);
let full_extremal_variant = T::extremal_variant(T::ALL);
let first = T::first();
assert_eq!(
full_extremal_variant,
Some(first),
"{type_name}: T::extremal_variant(T::ALL) drifted from Some(T::first()) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and the declaration-order `find` sweep MUST land on T::first(); a divergent full-set value silently bifurcates the LOAD-BEARING flat-histogram declaration-order-first arm DISCRIMINATING this projection from the lex-order sibling (which would land on T::sorted_first() whenever the declaration order diverges from the ASCII-lex order of the labels)",
);
assert_eq!(
T::extremal_variant(&doubled_full_set),
Some(first),
"{type_name}: T::extremal_variant(&doubled_full_set) drifted from Some(T::first()) — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and the declaration-order `find` sweep MUST land on T::first(); a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint",
);
let extremal_variants_full = T::extremal_variants(T::ALL);
assert_eq!(
full_extremal_variant,
extremal_variants_full.first().copied(),
"{type_name}: T::extremal_variant(T::ALL) drifted from T::extremal_variants(T::ALL).first().copied() — the singular Option-return direction-composition union first-witness MUST agree with the FIRST element of the plural Vec-return direction-composition union witness-collection walked in the same declaration-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture",
);
let has_extremal_full = T::has_extremal_variant(T::ALL);
assert_eq!(
full_extremal_variant.is_some(),
has_extremal_full,
"{type_name}: T::extremal_variant(T::ALL).is_some() drifted from T::has_extremal_variant(T::ALL) — the Option-return first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_extremal = T::extremal_variant(&matching_singleton);
assert_eq!(
singleton_extremal,
Some(first),
"{type_name}: T::extremal_variant([{target_label:?}]) drifted from Some(T::first()) at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so EVERY variant of T::ALL satisfies `c == max || c == min` under the union predicate, and the declaration-order `find` sweep MUST land on T::first(); a divergent matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING declaration-order-first-witness arm DISCRIMINATING this UNION projection from T::antimodal_variant (which also lands on T::first() only when T::first() != target, but bifurcates whenever `target == T::first()` because then the argmin band excludes T::first() and the argmin's first-witness slides to T::ALL[1])",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `Some(T::ALL[0])`-arm
// catch on the declaration-order direction-composition union
// first-witness corner. The bimodal triple `[T::ALL[0],
// T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count `2 == max`,
// T::ALL[1] at count `1` (MIDDLE), T::ALL[2] at count `0 ==
// min`; the declaration-order sweep hits T::ALL[0] immediately
// at the argmax band. The LOAD-BEARING catch that pins the
// union-band first-witness to T::ALL[0] rather than T::ALL[2]
// (the argmin) on this specific non-flat fixture where the
// declaration walk hits the argmax first past the middle-band
// T::ALL[1] sits at.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_extremal = T::extremal_variant(&bimodal_triple);
assert_eq!(
bimodal_extremal,
Some(T::ALL[0]),
"{type_name}: T::extremal_variant(&bimodal_triple) drifted from Some(T::ALL[0]) — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::ALL[0] sits at count `2 == max` (satisfying the union predicate at the argmax band), the declaration-order sweep hits T::ALL[0] immediately, and the projection MUST land on Some(T::ALL[0]); a divergent bimodal-triple value silently bifurcates the LOAD-BEARING declaration-order-first-witness arm on the non-flat middle-band fixture where the argmin (T::ALL[2]) is walked LATER in declaration order than the argmax (T::ALL[0]) so a naive `find(v => c == min)` sweep would return Some(T::ALL[0]) IF T::ALL[0]'s count `2` were incorrectly compared against `0 == min` — a bifurcation against the correct union projection",
);
let extremal_variants_triple = T::extremal_variants(&bimodal_triple);
assert_eq!(
bimodal_extremal,
extremal_variants_triple.first().copied(),
"{type_name}: T::extremal_variant(&bimodal_triple) drifted from T::extremal_variants(&bimodal_triple).first().copied() — the singular Option-return direction-composition union first-witness MUST agree with the FIRST element of the plural Vec-return direction-composition union witness-collection walked in the same declaration-order canonical order; a divergent bimodal-triple first-witness silently bifurcates the plural-vs-singular return-shape identity on the non-flat middle-band fixture",
);
assert_eq!(
bimodal_extremal.is_some(),
T::has_extremal_variant(&bimodal_triple),
"{type_name}: T::extremal_variant(&bimodal_triple).is_some() drifted from T::has_extremal_variant(&bimodal_triple) — the Option-return first-witness is Some iff the bool-return existential predicate holds; a divergent bimodal-triple is-some value silently bifurcates the Option-vs-bool return-shape identity on the non-flat middle-band fixture",
);
}
// (157) — `T::sorted_extremal_variant(items)` MUST agree with the
// LEX-ORDER-first-witness sweep `if items.is_empty() { None } else
// { T::sorted_variants().into_iter().find(|&v| { let c =
// T::count_occurrences_of(v, items); c == T::max_variant_count(items)
// || c == T::min_variant_count(items) }) }` on every slice AND MUST
// land on its canonical fixpoints (`None` on the empty slice
// UNCONDITIONALLY past the vacuous (max == min == 0, every-count ==
// 0) degenerate arm where an unguarded `find` sweep would silently
// return `Some(T::sorted_first())`; `Some(T::sorted_first())` on
// the full-set slice via the flat-histogram fixpoint (max == min
// == 1) where every variant is extremal and the LEX-order `find`
// sweep hits T::sorted_first() immediately — the LOAD-BEARING full-
// set fixpoint DISCRIMINATING this LEX-order projection from the
// DECLARATION-order sibling [`T::extremal_variant`] (which lands on
// T::first()) on any implementor whose declaration order diverges
// from lex order; `Some(T::sorted_first())` on the doubled-full-set
// slice via the second flat-histogram fixpoint (max == min == 2);
// `Some(T::sorted_first())` on every matching singleton at
// cardinality `>= 2` because the sole-position target sits at
// count `1 == max` while every non-target variant sits at count
// `0 == min` — every variant of T::ALL satisfies `c == max || c ==
// min` under the union predicate, and the LEX-order sweep hits
// T::sorted_first() immediately) AND on ONE first-witness-of-
// plural composition arm against
// `T::sorted_extremal_variants(items).first().copied()` AND on ONE
// is-some-composition arm against [`T::has_extremal_variant`]:
// `T::sorted_extremal_variant(items).is_some() ==
// T::has_extremal_variant(items)` MUST hold, pinning the Option-vs-
// bool return-shape identity on the lex arm AND on ONE sibling-
// composition arm against [`T::extremal_variant`]:
// `T::sorted_extremal_variant(items).is_some() ==
// T::extremal_variant(items).is_some()` MUST hold, pinning the
// (Some, None) partition alignment between the LEX-order and
// DECLARATION-order first-witness projections independently of the
// Some-arm value they report.
//
// Sibling posture to clause (156) one ORDERING axis over: clause
// (156) opens the (set-level × `Option<Self>` × statistical-
// aggregate × direction-composition × union × declaration) DECL-
// arm; THIS clause CLOSES the (set-level × `Option<Self>` ×
// statistical-aggregate × direction-composition × union ×
// ordering) 2-corner face at its LEX arm past the DECL arm the
// sibling opened, exhausting the 2-corner face on the ordering
// axis. Together with clauses (127)–(130) (the (`Vec<Self>` ×
// direction × ordering) 8-corner cube of the plural argmax +
// argmin witness-collection corners), clauses (150), (152)–(155)
// (the (`Vec<Self>` × direction-composition × combinator ×
// ordering) union + complement + intersection plural collection
// corners), clauses (149), (163)–(164) (the (`bool` × direction-
// composition × combinator) union + complement + intersection
// existence-bit corners), clauses (152), (154) (the (`usize` ×
// direction-composition × combinator) union + complement +
// intersection cardinality-count corners), clause (156) (the
// (`Option<Self>` × direction-composition × union × declaration)
// union DECL first-witness corner), and clauses (123)–(126) (the
// (`Option<Self>` × direction × ordering) 4-corner argmax + argmin
// first-witness corners), the direction-composition axis's UNION
// arm now carries typed projections at SIX return-shapes: `usize`
// cardinality-count via [`T::count_extremal_variants`], `Vec<Self>`
// witness-collection via [`T::extremal_variants`] +
// [`T::sorted_extremal_variants`] (declaration + lex), `bool`
// existence via [`T::has_extremal_variant`], AND `Option<Self>`
// first-witness via [`T::extremal_variant`] +
// [`T::sorted_extremal_variant`] (declaration + lex) — the union
// corner on the modal-aggregation matrix now carries the LEX-order
// FIRST-WITNESS projection complementing the plural collections,
// the existence bit, the cardinality count, the declaration-order
// first-witness, and the per-target predicate at ONE canonical
// return-shape corner. The (set-level × `Option<Self>` × direction-
// composition × union × ordering) 2-corner face is now EXHAUSTIVELY
// closed.
//
// The default trait body threads the `is_empty()` guard + max/min-
// fold pair + LEX-order `find` verbatim and satisfies every
// fixpoint arm + the first-witness-of-plural composition arm + the
// two is-some-composition arms for free; the assertion catches a
// future implementor whose override drifts the projection loudly
// rather than silently bifurcating the set-level LEX-order
// direction-composition union first-witness surface every
// downstream one-alphabetical-outlier-name consumer routes
// through. An override that folds onto `None` unconditionally
// bifurcates on the full-set + doubled-full-set + matching-
// singleton fixpoint arms at `None != Some(T::sorted_first())`; an
// override that folds onto `Some(T::sorted_first())` unconditionally
// bifurcates on the empty-slice arm at `Some(T::sorted_first())
// != None`; an override that omits the empty-slice guard past the
// vacuous (max == min == 0) degenerate arm bifurcates loudly at
// the empty-slice fixpoint; an override that accidentally walks
// [`T::ALL`] (the declaration-order sibling's walk surface) instead
// of [`T::sorted_variants`] bifurcates loudly on any implementor
// whose full-set fixpoint sits at (T::first() != T::sorted_first())
// — the full-set fixpoint returns `Some(T::first())` under the
// decl walk vs `Some(T::sorted_first())` under the LEX walk; an
// override that detaches the singular from the plural's `.first()`
// bifurcates loudly on the composition arm against
// [`T::sorted_extremal_variants`]; an override that detaches the
// (Some, None) partition from [`T::extremal_variant`] bifurcates
// loudly on the sibling-composition arm.
assert_eq!(
T::sorted_extremal_variant(empty),
None,
"{type_name}: T::sorted_extremal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because the vacuous (max == min == 0, every-count == 0) degenerate arm satisfies the union predicate at every variant, and an unguarded lex-order `find` sweep would silently return Some(T::sorted_first()); a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition union first-witness consumer routes through",
);
let full_sorted_extremal_variant = T::sorted_extremal_variant(T::ALL);
let sorted_first = T::sorted_first();
assert_eq!(
full_sorted_extremal_variant,
Some(sorted_first),
"{type_name}: T::sorted_extremal_variant(T::ALL) drifted from Some(T::sorted_first()) == Some({sorted_first_label:?}) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1, every variant sits at BOTH extremes simultaneously via the (max == min == 1) flat-histogram collapse, and the LEX-order sweep MUST land on T::sorted_first(); a divergent full-set value silently bifurcates the LOAD-BEARING flat-histogram lex-order-first arm DISCRIMINATING this projection from the declaration-order sibling [`T::extremal_variant`] (which lands on T::first() whenever the declaration order diverges from the ASCII-lex order of the labels)",
sorted_first_label = <T as ClosedSet>::label(sorted_first),
);
assert_eq!(
T::sorted_extremal_variant(&doubled_full_set),
Some(sorted_first),
"{type_name}: T::sorted_extremal_variant(&doubled_full_set) drifted from Some(T::sorted_first()) — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and the LEX-order `find` sweep MUST land on T::sorted_first(); a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint",
);
let sorted_extremal_variants_full = T::sorted_extremal_variants(T::ALL);
assert_eq!(
full_sorted_extremal_variant,
sorted_extremal_variants_full.first().copied(),
"{type_name}: T::sorted_extremal_variant(T::ALL) drifted from T::sorted_extremal_variants(T::ALL).first().copied() — the singular Option-return LEX-order direction-composition union first-witness MUST agree with the FIRST element of the plural Vec-return LEX-order direction-composition union witness-collection walked in the same lex-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture",
);
assert_eq!(
full_sorted_extremal_variant.is_some(),
T::has_extremal_variant(T::ALL),
"{type_name}: T::sorted_extremal_variant(T::ALL).is_some() drifted from T::has_extremal_variant(T::ALL) — the Option-return LEX-first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture",
);
assert_eq!(
full_sorted_extremal_variant.is_some(),
T::extremal_variant(T::ALL).is_some(),
"{type_name}: T::sorted_extremal_variant(T::ALL).is_some() drifted from T::extremal_variant(T::ALL).is_some() — the (Some, None) partition of the LEX-order first-witness MUST AGREE with the (Some, None) partition of the declaration-order first-witness on every slice; the two projections may disagree on the VALUE they report but MUST agree on WHEN the Some arm fires; a divergent full-set is-some sibling value silently bifurcates the LEX-vs-DECL alignment of the (Some, None) partition on the flat-histogram fixture",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_extremal = T::sorted_extremal_variant(&matching_singleton);
assert_eq!(
singleton_sorted_extremal,
Some(sorted_first),
"{type_name}: T::sorted_extremal_variant([{target_label:?}]) drifted from Some(T::sorted_first()) at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so EVERY variant of T::ALL satisfies `c == max || c == min` under the union predicate, and the LEX-order `find` sweep MUST land on T::sorted_first(); a divergent matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING lex-order-first-witness arm DISCRIMINATING this LEX projection from the declaration-order sibling [`T::extremal_variant`] (which lands on T::first()) on any implementor whose declaration order diverges from lex order",
);
}
}
// (158) — `T::middle_band_variant(items)` MUST agree with the
// declaration-order-first-witness sweep `if items.is_empty()
// { None } else { T::ALL.iter().copied().find(|&v| { let c =
// T::count_occurrences_of(v, items); c != T::max_variant_count(items)
// && c != T::min_variant_count(items) }) }` on every slice AND
// MUST land on its canonical fixpoints (`None` on the empty slice
// UNCONDITIONALLY past the vacuous (max == min == 0, every-count
// == 0) degenerate arm where NO variant satisfies the STRICT
// interior conjunction; `None` on the full-set slice via the
// flat-histogram fixpoint (max == min == 1) where EVERY variant
// sits at BOTH extremes simultaneously and NO variant sits
// strictly between; `None` on the doubled-full-set slice via the
// second flat-histogram fixpoint (max == min == 2); `None` on
// every matching singleton at cardinality `>= 2` because every
// variant sits AT one of the two extremes (`1 == max` or
// `0 == min`); `Some(T::ALL[1])` on the bimodal-triple fixture
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` at cardinality `>= 3` —
// T::ALL[1] is the SOLE inhabitant of the strict interior with
// count `1` strictly between max `2` and min `0`, so the
// declaration-order sweep hits T::ALL[1] immediately) AND on ONE
// first-witness-of-plural composition arm against
// `T::middle_band_variants(items).first().copied()` AND on ONE
// is-some-composition arm against
// [`T::has_middle_band_variant`]: `T::middle_band_variant(items)
// .is_some() == T::has_middle_band_variant(items)` MUST hold,
// pinning the Option-vs-bool return-shape identity independently
// of the first-witness value.
//
// Sibling posture to clause (156) one COMBINATOR axis over:
// clause (156) pins the (set-level × `Option<Self>` ×
// direction-composition × union × declaration) union DECL first-
// witness corner via [`T::extremal_variant`]; THIS clause LIFTS
// the (set-level × `Option<Self>` × direction-composition ×
// complement × declaration) complement DECL first-witness corner
// via [`T::middle_band_variant`] one COMBINATOR axis over via
// the STRICT interior conjunction `c != max && c != min` (De
// Morgan complement of the union disjunction `c == max ||
// c == min` clause (156) pins). Together with clauses (151),
// (153), (162), (164) (the (`Vec<Self>` × complement × ordering)
// + (`bool` × complement × existential) + (`usize` × complement
// × cardinality-count) middle-band corners), THIS clause LIFTS
// the complement corner on the (`Option<Self>` × declaration)
// face at the DECLARATION arm — the natural next lift on the
// ORDERING axis is `sorted_middle_band_variant(items) ->
// Option<Self>` closing the LEX arm.
//
// The default trait body threads the `is_empty()` guard + max/
// min-fold pair + declaration-order `find` verbatim under the
// strict-interior conjunction and satisfies every fixpoint arm +
// the first-witness-of-plural composition arm + the is-some-
// composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level direction-composition
// complement first-witness surface every downstream one-middle-
// band-name consumer routes through. An override that folds onto
// `Some(T::first())` unconditionally bifurcates on the empty-
// slice + full-set + doubled-full-set + matching-singleton
// fixpoint arms at `Some(T::first()) != None`; an override that
// folds onto `None` unconditionally bifurcates on the bimodal-
// triple arm at `None != Some(T::ALL[1])`; an override that
// omits the empty-slice guard past the vacuous (max == min == 0)
// degenerate arm still lands on `None` because the strict-
// interior conjunction `0 != 0 && 0 != 0` is `false` at every
// variant — the empty guard is COSMETIC alignment with the union
// sibling's guard, not load-bearing on the empty-slice fixpoint;
// an override that flips the predicate to the union arm's
// disjunction bifurcates loudly on the bimodal-triple where LHS
// == Some(T::ALL[1]) but the disjunction arm hits T::ALL[0]
// first at the argmax band; an override that detaches the
// singular from the plural's `.first()` bifurcates loudly on the
// bimodal-triple fixture where LHS == Some(T::ALL[1]) and RHS
// == middle_band_variants[0] == T::ALL[1].
assert_eq!(
T::middle_band_variant(empty),
None,
"{type_name}: T::middle_band_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because [`T::is_middle_band_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to None; a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition complement first-witness consumer routes through",
);
let full_middle_band_variant = T::middle_band_variant(T::ALL);
assert_eq!(
full_middle_band_variant,
None,
"{type_name}: T::middle_band_variant(T::ALL) drifted from None — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), EVERY variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and NO variant satisfies the STRICT interior conjunction `c != max && c != min`; a Some full-set value silently bifurcates the LOAD-BEARING flat-histogram None-arm DISCRIMINATING this COMPLEMENT projection from [`T::extremal_variant`] (which lands on Some(T::first()) on the same fixture)",
);
assert_eq!(
T::middle_band_variant(&doubled_full_set),
None,
"{type_name}: T::middle_band_variant(&doubled_full_set) drifted from None — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and NO variant sits strictly between; a Some doubled-full-set value silently bifurcates the second flat-histogram None-arm",
);
let middle_band_variants_full = T::middle_band_variants(T::ALL);
assert_eq!(
full_middle_band_variant,
middle_band_variants_full.first().copied(),
"{type_name}: T::middle_band_variant(T::ALL) drifted from T::middle_band_variants(T::ALL).first().copied() — the singular Option-return direction-composition complement first-witness MUST agree with the FIRST element of the plural Vec-return direction-composition complement witness-collection walked in the same declaration-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture (both projections collapse to None here — the composition identity pins the empty-Vec `.first()` == None arm against the singular None arm)",
);
assert_eq!(
full_middle_band_variant.is_some(),
T::has_middle_band_variant(T::ALL),
"{type_name}: T::middle_band_variant(T::ALL).is_some() drifted from T::has_middle_band_variant(T::ALL) — the Option-return complement first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_middle_band = T::middle_band_variant(&matching_singleton);
assert_eq!(
singleton_middle_band,
None,
"{type_name}: T::middle_band_variant([{target_label:?}]) drifted from None at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so EVERY variant of T::ALL sits AT one of the two extremes and NO variant sits strictly between; a Some matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING complement None-arm DISCRIMINATING this COMPLEMENT projection from [`T::extremal_variant`] (which lands on Some(T::first()) on the same fixture)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING SOLE non-`None`-arm
// catch on the declaration-order direction-composition
// complement first-witness corner. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (the SOLE middle-band
// inhabitant), T::ALL[2] at count `0 == min`; the declaration-
// order sweep hits T::ALL[1] immediately at the strict
// interior. The LOAD-BEARING catch that pins the complement-
// band first-witness to T::ALL[1] rather than to T::ALL[0]
// (the argmax) or T::ALL[2] (the argmin) — the union arm's
// disjunction hits T::ALL[0] first while this complement
// arm's strict-interior conjunction hits T::ALL[1] first.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_middle_band = T::middle_band_variant(&bimodal_triple);
assert_eq!(
bimodal_middle_band,
Some(T::ALL[1]),
"{type_name}: T::middle_band_variant(&bimodal_triple) drifted from Some(T::ALL[1]) — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::ALL[1] sits at count `1` STRICTLY between max `2` and min `0` (satisfying the strict-interior conjunction `c != max && c != min`), the declaration-order sweep hits T::ALL[1] immediately, and the projection MUST land on Some(T::ALL[1]); a divergent bimodal-triple value silently bifurcates the LOAD-BEARING SOLE non-`None`-arm on the modal-aggregation matrix's canonical fixture window — this fixture is the ONLY canonical fixpoint where the complement projection returns a Some value across the (empty, full-set, doubled-full-set, matching-singleton, bimodal-triple) 5-arm fixture window",
);
let middle_band_variants_triple = T::middle_band_variants(&bimodal_triple);
assert_eq!(
bimodal_middle_band,
middle_band_variants_triple.first().copied(),
"{type_name}: T::middle_band_variant(&bimodal_triple) drifted from T::middle_band_variants(&bimodal_triple).first().copied() — the singular Option-return direction-composition complement first-witness MUST agree with the FIRST element of the plural Vec-return direction-composition complement witness-collection walked in the same declaration-order canonical order; a divergent bimodal-triple first-witness silently bifurcates the plural-vs-singular return-shape identity on the load-bearing non-flat middle-band fixture where BOTH sides land on T::ALL[1]",
);
assert_eq!(
bimodal_middle_band.is_some(),
T::has_middle_band_variant(&bimodal_triple),
"{type_name}: T::middle_band_variant(&bimodal_triple).is_some() drifted from T::has_middle_band_variant(&bimodal_triple) — the Option-return complement first-witness is Some iff the bool-return existential predicate holds; a divergent bimodal-triple is-some value silently bifurcates the Option-vs-bool return-shape identity on the load-bearing non-flat middle-band fixture where BOTH sides fire to `true`",
);
}
// (159) — `T::sorted_middle_band_variant(items)` MUST agree with
// the LEX-ORDER-first-witness sweep `if items.is_empty() { None }
// else { T::sorted_variants().into_iter().find(|&v| { let c =
// T::count_occurrences_of(v, items); c != T::max_variant_count(items)
// && c != T::min_variant_count(items) }) }` on every slice AND MUST
// land on its canonical fixpoints (`None` on the empty slice
// UNCONDITIONALLY past the vacuous (max == min == 0, every-count
// == 0) degenerate arm where NO variant satisfies the STRICT
// interior conjunction; `None` on the full-set slice via the
// flat-histogram fixpoint (max == min == 1) where EVERY variant
// sits at BOTH extremes simultaneously and NO variant sits
// strictly between; `None` on the doubled-full-set slice via the
// second flat-histogram fixpoint (max == min == 2); `None` on
// every matching singleton at cardinality `>= 2` because every
// variant sits AT one of the two extremes (`1 == max` or
// `0 == min`); `Some(T::sorted_variants()[1])` on the bimodal-
// triple fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]` at
// cardinality `>= 3` on any implementor where declaration and lex
// orders coincide on the first three positions — T::ALL[1] is the
// SOLE inhabitant of the strict interior with count `1` strictly
// between max `2` and min `0`, so the LEX-order sweep hits it at
// its lex-order position immediately) AND on ONE first-witness-of-
// plural composition arm against
// `T::sorted_middle_band_variants(items).first().copied()` AND on
// ONE is-some-composition arm against
// [`T::has_middle_band_variant`]: `T::sorted_middle_band_variant(
// items).is_some() == T::has_middle_band_variant(items)` MUST hold,
// pinning the Option-vs-bool return-shape identity on the lex arm
// AND on ONE sibling-composition arm against
// [`T::middle_band_variant`]:
// `T::sorted_middle_band_variant(items).is_some() ==
// T::middle_band_variant(items).is_some()` MUST hold, pinning the
// (Some, None) partition alignment between the LEX-order and
// DECLARATION-order complement first-witness projections
// independently of the Some-arm value they report.
//
// Sibling posture to clause (158) one ORDERING axis over: clause
// (158) opens the (set-level × `Option<Self>` × statistical-
// aggregate × direction-composition × complement × declaration)
// DECL arm; THIS clause CLOSES the (set-level × `Option<Self>` ×
// statistical-aggregate × direction-composition × complement ×
// ordering) 2-corner face at its LEX arm past the DECL arm the
// sibling opened, exhausting the 2-corner face on the ordering
// axis. Together with clauses (156) + (157) (the (`Option<Self>`
// × direction-composition × union × ordering) 2-corner face
// closed at BOTH corners via [`T::extremal_variant`] +
// [`T::sorted_extremal_variant`]) and clause (158) (the
// (`Option<Self>` × direction-composition × complement ×
// declaration) corner via [`T::middle_band_variant`]), the
// (set-level × `Option<Self>` × direction-composition ×
// combinator × ordering) 3×2 grid now closes at FOUR of its SIX
// tiles — union DECL, union LEX, complement DECL, complement
// LEX. The intersection arm at both ordering columns
// (`bimodal_variant` + `sorted_bimodal_variant`) remains as the
// natural next lifts on the same 3×2 grid.
//
// The default trait body threads the `is_empty()` guard + max/
// min-fold pair + LEX-order `find` verbatim under the strict-
// interior conjunction and satisfies every fixpoint arm + the
// first-witness-of-plural composition arm + the two is-some-
// composition arms for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level LEX-order direction-
// composition complement first-witness surface every downstream
// one-alphabetical-middle-band-name consumer routes through. An
// override that folds onto `Some(T::sorted_first())`
// unconditionally bifurcates on the empty-slice + full-set +
// doubled-full-set + matching-singleton fixpoint arms at
// `Some(T::sorted_first()) != None`; an override that folds onto
// `None` unconditionally bifurcates on the bimodal-triple arm
// (on implementors where declaration and lex orders coincide) at
// `None != Some(T::sorted_variants()[1])`; an override that omits
// the empty-slice guard past the vacuous (max == min == 0)
// degenerate arm still lands on `None` because the strict-
// interior conjunction `0 != 0 && 0 != 0` is `false` at every
// variant — the empty guard is COSMETIC alignment with the union
// sibling's guard, not load-bearing on the empty-slice fixpoint;
// an override that flips the predicate to the union arm's
// disjunction bifurcates loudly on the bimodal-triple where LHS
// == Some(T::sorted_variants()[1]) but the disjunction arm hits
// T::sorted_variants()[0] first at the argmax band; an override
// that accidentally walks [`T::ALL`] (the declaration-order
// sibling's walk surface) instead of [`T::sorted_variants`]
// bifurcates loudly on any implementor whose declaration order
// diverges from lex order and whose middle band contains a
// variant that sits at a lex-order position different from its
// declaration-order position; an override that detaches the
// singular from the plural's `.first()` bifurcates loudly on the
// bimodal-triple; an override that detaches the (Some, None)
// partition from [`T::middle_band_variant`] bifurcates loudly on
// the sibling-composition arm.
assert_eq!(
T::sorted_middle_band_variant(empty),
None,
"{type_name}: T::sorted_middle_band_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because the vacuous (max == min == 0, every-count == 0) degenerate arm satisfies `c != max && c != min` at NO variant (the strict-interior conjunction `0 != 0 && 0 != 0` is `false` at every variant); a Some empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition complement first-witness consumer routes through",
);
let full_sorted_middle_band_variant = T::sorted_middle_band_variant(T::ALL);
assert_eq!(
full_sorted_middle_band_variant,
None,
"{type_name}: T::sorted_middle_band_variant(T::ALL) drifted from None — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), EVERY variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and NO variant satisfies the STRICT interior conjunction `c != max && c != min`; a Some full-set value silently bifurcates the LOAD-BEARING flat-histogram None-arm DISCRIMINATING this COMPLEMENT projection from [`T::sorted_extremal_variant`] (which lands on Some(T::sorted_first()) on the same fixture)",
);
assert_eq!(
T::sorted_middle_band_variant(&doubled_full_set),
None,
"{type_name}: T::sorted_middle_band_variant(&doubled_full_set) drifted from None — the doubled full set hits every variant at exactly two positions, max == min == 2, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and NO variant sits strictly between; a Some doubled-full-set value silently bifurcates the second flat-histogram None-arm",
);
let sorted_middle_band_variants_full = T::sorted_middle_band_variants(T::ALL);
assert_eq!(
full_sorted_middle_band_variant,
sorted_middle_band_variants_full.first().copied(),
"{type_name}: T::sorted_middle_band_variant(T::ALL) drifted from T::sorted_middle_band_variants(T::ALL).first().copied() — the singular Option-return LEX-order direction-composition complement first-witness MUST agree with the FIRST element of the plural Vec-return LEX-order direction-composition complement witness-collection walked in the same lex-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture (both projections collapse to None here — the composition identity pins the empty-Vec `.first()` == None arm against the singular None arm)",
);
assert_eq!(
full_sorted_middle_band_variant.is_some(),
T::has_middle_band_variant(T::ALL),
"{type_name}: T::sorted_middle_band_variant(T::ALL).is_some() drifted from T::has_middle_band_variant(T::ALL) — the Option-return LEX-first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture",
);
assert_eq!(
full_sorted_middle_band_variant.is_some(),
T::middle_band_variant(T::ALL).is_some(),
"{type_name}: T::sorted_middle_band_variant(T::ALL).is_some() drifted from T::middle_band_variant(T::ALL).is_some() — the (Some, None) partition of the LEX-order complement first-witness MUST AGREE with the (Some, None) partition of the declaration-order complement first-witness on every slice; the two projections may disagree on the VALUE they report but MUST agree on WHEN the Some arm fires; a divergent full-set is-some sibling value silently bifurcates the LEX-vs-DECL alignment of the (Some, None) partition on the flat-histogram fixture",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_middle_band = T::sorted_middle_band_variant(&matching_singleton);
assert_eq!(
singleton_sorted_middle_band,
None,
"{type_name}: T::sorted_middle_band_variant([{target_label:?}]) drifted from None at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so EVERY variant of T::ALL sits AT one of the two extremes and NO variant sits strictly between; a Some matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING complement None-arm DISCRIMINATING this COMPLEMENT projection from [`T::sorted_extremal_variant`] (which lands on Some(T::sorted_first()) on the same fixture)",
);
}
}
// (160) — `T::bimodal_variant(items)` MUST agree with the
// uniformity-collapse SHARPENING `if items.is_empty() ||
// !T::is_uniform(items) { None } else { T::ALL.first().copied() }`
// on every slice AND MUST land on its canonical fixpoints (`None`
// on the empty slice UNCONDITIONALLY past the vacuous (max == min
// == 0) flat-histogram collapse of T::is_uniform via the LOAD-
// BEARING empty-slice guard where an unguarded branch would
// silently return `Some(T::first())`; `Some(T::first())` on the
// full-set slice via the flat-histogram fixpoint (max == min ==
// 1) of T::is_uniform where every variant sits at BOTH extremes
// simultaneously; `Some(T::first())` on the doubled-full-set
// slice via the second flat-histogram fixpoint (max == min == 2);
// `None` on every matching singleton at cardinality `>= 2`
// because the sole-position target sits at count `1 == max` while
// every non-target variant sits at count `0 == min`, so the
// histogram is non-flat (max `1` != min `0`), T::is_uniform
// reports `false`, and the dichotomy lands on `None`; `None` on
// the bimodal-triple fixture `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// at cardinality `>= 3` — the histogram is non-flat (max `2` !=
// min `0`), so T::is_uniform reports `false` and the dichotomy
// lands on `None`) AND on ONE first-witness-of-plural composition
// arm against [`T::bimodal_variants`]:
// `T::bimodal_variant(items) ==
// T::bimodal_variants(items).first().copied()` MUST hold, pinning
// the singular-vs-plural return-shape identity AND on ONE is-some-
// composition arm against [`T::has_bimodal_variant`]:
// `T::bimodal_variant(items).is_some() ==
// T::has_bimodal_variant(items)` MUST hold, pinning the
// Option-vs-bool return-shape identity on the declaration arm.
//
// Sibling posture to clause (158) one COMBINATOR axis over:
// clause (158) opens the (set-level × `Option<Self>` ×
// statistical-aggregate × direction-composition × COMPLEMENT ×
// declaration) COMPLEMENT-arm; THIS clause OPENS the (set-level ×
// `Option<Self>` × statistical-aggregate × direction-composition ×
// INTERSECTION × declaration) INTERSECTION-arm past the union arm
// clause (156) opened and past the complement arm clause (158)
// opened. Together with clauses (156) + (157) (the (`Option<Self>`
// × direction-composition × union × ordering) 2-corner face
// closed at BOTH corners via [`T::extremal_variant`] +
// [`T::sorted_extremal_variant`]) and clauses (158) + (159) (the
// (`Option<Self>` × direction-composition × complement × ordering)
// 2-corner face closed at BOTH corners via
// [`T::middle_band_variant`] + [`T::sorted_middle_band_variant`]),
// the (set-level × `Option<Self>` × direction-composition ×
// combinator × ordering) 3×2 grid now closes at FIVE of its SIX
// tiles — the intersection LEX arm (`sorted_bimodal_variant`)
// remains as the natural next lift closing the intersection
// ordering face.
//
// The default trait body threads the `is_empty() ||
// !is_uniform(items)` dichotomy verbatim and satisfies every
// fixpoint arm + the first-witness-of-plural composition arm + the
// is-some composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the set-level declaration-order
// direction-composition intersection first-witness surface every
// downstream flat-diagonal first-name consumer routes through. An
// override that folds onto `None` unconditionally bifurcates on
// BOTH flat-histogram fixpoint arms (full-set and doubled-full-
// set) at `None != Some(T::first())`; an override that folds onto
// `Some(T::first())` unconditionally bifurcates on the empty-slice
// arm at `Some(T::first()) != None` AND on every matching-singleton
// arm at cardinality `>= 2` AND on the bimodal-triple arm at
// cardinality `>= 3`; an override that omits the empty-slice guard
// and returns `Some(T::first())` on `&[]` past the vacuous (max ==
// min == 0) flat-histogram collapse of T::is_uniform bifurcates
// loudly at the empty-slice fixpoint; an override that flips the
// predicate to the union arm's disjunction bifurcates loudly on
// every matching singleton at cardinality `>= 2` at `Some(T::first())
// != None`; an override that detaches the singular from the
// plural's `.first()` bifurcates loudly on the full-set fixture
// where LHS != bimodal_variants[0] == T::first(); an override that
// detaches the (Some, None) partition from
// [`T::has_bimodal_variant`] bifurcates loudly on the is-some
// composition arm.
assert_eq!(
T::bimodal_variant(empty),
None,
"{type_name}: T::bimodal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because [`T::is_bimodal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to None; a Some empty-slice value (in particular `Some(T::first())` from an unguarded branch where the vacuous (max == min == 0) flat-histogram collapse of T::is_uniform silently reports `true`) silently bifurcates the empty-slice fixpoint contract every downstream declaration-order direction-composition intersection first-witness consumer routes through",
);
let full_bimodal_variant = T::bimodal_variant(T::ALL);
let expected_full_bimodal_variant = T::ALL.first().copied();
assert_eq!(
full_bimodal_variant,
expected_full_bimodal_variant,
"{type_name}: T::bimodal_variant(T::ALL) drifted from Some(T::first()) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), T::is_uniform reports `true`, every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and the declaration-order first-witness MUST land on Some(T::first()); a None full-set value is the drift catch for an override that folds onto `None` unconditionally OR omits the flat-histogram Some arm on the uniform dichotomy; a Some(other) full-set value is the drift catch for an override that walks T::sorted_variants instead of T::ALL",
);
assert_eq!(
T::bimodal_variant(&doubled_full_set),
expected_full_bimodal_variant,
"{type_name}: T::bimodal_variant(&doubled_full_set) drifted from Some(T::first()) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, max == min == 2, T::is_uniform reports `true`, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and the declaration-order first-witness MUST land on Some(T::first()); a divergent doubled-full-set value silently bifurcates the second flat-histogram Some-arm contract",
);
let bimodal_variants_full = T::bimodal_variants(T::ALL);
assert_eq!(
full_bimodal_variant,
bimodal_variants_full.first().copied(),
"{type_name}: T::bimodal_variant(T::ALL) drifted from T::bimodal_variants(T::ALL).first().copied() — the singular Option-return direction-composition intersection first-witness MUST agree with the FIRST element of the plural Vec-return direction-composition intersection witness-collection walked in the same declaration-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture (both projections land on Some(T::first()) here — the composition identity pins the plural's `.first()` == Some(T::first()) arm against the singular Some(T::first()) arm)",
);
assert_eq!(
full_bimodal_variant.is_some(),
T::has_bimodal_variant(T::ALL),
"{type_name}: T::bimodal_variant(T::ALL).is_some() drifted from T::has_bimodal_variant(T::ALL) — the Option-return declaration-order intersection first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture where BOTH sides fire to `true`",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_bimodal_variant = T::bimodal_variant(&matching_singleton);
assert_eq!(
singleton_bimodal_variant,
None,
"{type_name}: T::bimodal_variant([{target_label:?}]) drifted from None at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so the histogram is non-flat (max `1` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on None; a Some matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING intersection None-arm DISCRIMINATING this INTERSECTION projection from [`T::extremal_variant`] (which lands on Some(T::first()) on the same fixture via the (max ∨ min) union covering every variant through one of the two arms)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `None`-arm catch on
// the intersection first-witness corner. The bimodal triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at count
// `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2] at
// count `0 == min`; the histogram is non-flat (max `2` != min
// `0`), so T::is_uniform reports `false` and the dichotomy
// lands on None. The LOAD-BEARING catch that separates the
// intersection first-witness from [`T::middle_band_variant`]
// (which reports Some(T::ALL[1]) on the same fixture) and
// from [`T::extremal_variant`] (which reports Some(T::ALL[0])
// on the same fixture) — the three projections split the
// modal-aggregation matrix into its three direction-composition
// arms on the ONE canonical non-flat triple.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_intersection = T::bimodal_variant(&bimodal_triple);
assert_eq!(
bimodal_triple_intersection,
None,
"{type_name}: T::bimodal_variant(&bimodal_triple) drifted from None — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on None; a Some bimodal-triple value silently bifurcates the LOAD-BEARING None-arm catch that separates the intersection first-witness from T::middle_band_variant (which reports Some(T::ALL[1]) on the same fixture) and from T::extremal_variant (which reports Some(T::ALL[0]) on the same fixture)",
);
assert_eq!(
bimodal_triple_intersection.is_some(),
T::has_bimodal_variant(&bimodal_triple),
"{type_name}: T::bimodal_variant(&bimodal_triple).is_some() drifted from T::has_bimodal_variant(&bimodal_triple) — the Option-return declaration-order intersection first-witness is Some iff the bool-return existential predicate holds; a divergent bimodal-triple is-some value silently bifurcates the Option-vs-bool return-shape identity on the load-bearing non-flat middle-band fixture where BOTH sides fire to `false`",
);
}
// (161) — `T::sorted_bimodal_variant(items)` MUST agree with the
// uniformity-collapse SHARPENING `if items.is_empty() ||
// !T::is_uniform(items) { None } else {
// T::sorted_variants().first().copied() }` on every slice AND MUST
// land on its canonical fixpoints (`None` on the empty slice
// UNCONDITIONALLY past the vacuous (max == min == 0) flat-histogram
// collapse of T::is_uniform via the LOAD-BEARING empty-slice guard
// where an unguarded branch would silently return
// `Some(T::sorted_first())`; `Some(T::sorted_first())` on the
// full-set slice via the flat-histogram fixpoint (max == min == 1)
// of T::is_uniform where every variant sits at BOTH extremes
// simultaneously; `Some(T::sorted_first())` on the doubled-full-set
// slice via the second flat-histogram fixpoint (max == min == 2);
// `None` on every matching singleton at cardinality `>= 2` because
// the sole-position target sits at count `1 == max` while every
// non-target variant sits at count `0 == min`, so the histogram is
// non-flat (max `1` != min `0`), T::is_uniform reports `false`, and
// the dichotomy lands on `None`) AND on ONE first-witness-of-plural
// composition arm against [`T::sorted_bimodal_variants`]:
// `T::sorted_bimodal_variant(items) ==
// T::sorted_bimodal_variants(items).first().copied()` MUST hold,
// pinning the singular-vs-plural return-shape identity AND on ONE
// is-some-composition arm against [`T::has_bimodal_variant`]:
// `T::sorted_bimodal_variant(items).is_some() ==
// T::has_bimodal_variant(items)` MUST hold, pinning the Option-vs-
// bool return-shape identity on the lex arm AND on ONE sibling-
// composition arm against [`T::bimodal_variant`]:
// `T::sorted_bimodal_variant(items).is_some() ==
// T::bimodal_variant(items).is_some()` MUST hold, pinning the
// (Some, None) partition alignment between the lex arm and the
// declaration arm.
//
// Sibling posture to clause (160) one ORDERING axis over: clause
// (160) opens the (set-level × `Option<Self>` × statistical-
// aggregate × direction-composition × INTERSECTION × declaration)
// INTERSECTION-arm at its declaration-order corner; THIS clause
// CLOSES the (set-level × `Option<Self>` × statistical-aggregate ×
// direction-composition × INTERSECTION × ordering) 2-corner face at
// its lex-arm past the declaration-arm clause (160) opened.
// Together with clauses (156) + (157) (the (`Option<Self>` ×
// direction-composition × union × ordering) 2-corner face closed at
// BOTH corners via [`T::extremal_variant`] +
// [`T::sorted_extremal_variant`]) and clauses (158) + (159) (the
// (`Option<Self>` × direction-composition × complement × ordering)
// 2-corner face closed at BOTH corners via
// [`T::middle_band_variant`] + [`T::sorted_middle_band_variant`])
// and clause (160) (the intersection declaration corner via
// [`T::bimodal_variant`]), the (set-level × `Option<Self>` ×
// direction-composition × combinator × ordering) 3×2 grid now
// CLOSES EXHAUSTIVELY at all SIX tiles — the union pair (declaration
// + lex), the complement pair (declaration + lex), and now the
// intersection pair (declaration + lex).
//
// The default trait body threads the `is_empty() ||
// !is_uniform(items)` dichotomy verbatim and satisfies every
// fixpoint arm + the first-witness-of-plural composition arm + the
// is-some composition arm + the sibling-composition arm for free;
// the assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the set-
// level lex-order direction-composition intersection first-witness
// surface every downstream flat-diagonal lex-first-name consumer
// routes through. An override that folds onto `None` unconditionally
// bifurcates on BOTH flat-histogram fixpoint arms (full-set and
// doubled-full-set) at `None != Some(T::sorted_first())`; an
// override that folds onto `Some(T::sorted_first())` unconditionally
// bifurcates on the empty-slice arm at `Some(T::sorted_first()) !=
// None` AND on every matching-singleton arm at cardinality `>= 2`
// AND on the bimodal-triple arm at cardinality `>= 3`; an override
// that omits the empty-slice guard and returns
// `Some(T::sorted_first())` on `&[]` past the vacuous (max == min ==
// 0) flat-histogram collapse of T::is_uniform bifurcates loudly at
// the empty-slice fixpoint; an override that flips the predicate to
// the union arm's disjunction bifurcates loudly on every matching
// singleton at cardinality `>= 2` at `Some(T::sorted_first()) !=
// None`; an override that detaches the singular from the plural's
// `.first()` bifurcates loudly on the full-set fixture where LHS !=
// sorted_bimodal_variants[0] == T::sorted_first(); an override that
// detaches the (Some, None) partition from
// [`T::has_bimodal_variant`] bifurcates loudly on the is-some
// composition arm; an override that detaches the (Some, None)
// partition from [`T::bimodal_variant`] bifurcates loudly on the
// sibling-composition arm (both projections gate through the SAME
// uniformity dichotomy, so their Some-vs-None fires MUST coincide).
assert_eq!(
T::sorted_bimodal_variant(empty),
None,
"{type_name}: T::sorted_bimodal_variant(&[]) drifted from None — the empty-slice fixpoint MUST return None because [`T::is_bimodal_variant_of`] carries a non-emptiness precondition at every target that pins the empty-slice answer to None; a Some empty-slice value (in particular `Some(T::sorted_first())` from an unguarded branch where the vacuous (max == min == 0) flat-histogram collapse of T::is_uniform silently reports `true`) silently bifurcates the empty-slice fixpoint contract every downstream lex-order direction-composition intersection first-witness consumer routes through",
);
let full_sorted_bimodal_variant = T::sorted_bimodal_variant(T::ALL);
let expected_full_sorted_bimodal_variant = T::sorted_variants().first().copied();
assert_eq!(
full_sorted_bimodal_variant,
expected_full_sorted_bimodal_variant,
"{type_name}: T::sorted_bimodal_variant(T::ALL) drifted from Some(T::sorted_first()) — clause (3)'s pairwise-distinctness invariant pins every variant of T::ALL at exactly one position on the full-set slice, every per-variant count is 1, T::max_variant_count(T::ALL) == T::min_variant_count(T::ALL) == 1 (the flat-histogram fixpoint pins the direction axis degeneracy at every corner), T::is_uniform reports `true`, every variant sits at BOTH extremes simultaneously via the (max == min == 1) collapse, and the lex-order first-witness MUST land on Some(T::sorted_first()); a None full-set value is the drift catch for an override that folds onto `None` unconditionally OR omits the flat-histogram Some arm on the uniform dichotomy; a Some(other) full-set value is the drift catch for an override that walks T::ALL instead of T::sorted_variants",
);
assert_eq!(
T::sorted_bimodal_variant(&doubled_full_set),
expected_full_sorted_bimodal_variant,
"{type_name}: T::sorted_bimodal_variant(&doubled_full_set) drifted from Some(T::sorted_first()) — every variant of T::ALL appears at exactly two positions of the doubled-full-set slice, every per-variant count is 2, max == min == 2, T::is_uniform reports `true`, every variant sits at BOTH extremes via the second flat-histogram fixpoint, and the lex-order first-witness MUST land on Some(T::sorted_first()); a divergent doubled-full-set value silently bifurcates the second flat-histogram Some-arm contract",
);
let sorted_bimodal_variants_full = T::sorted_bimodal_variants(T::ALL);
assert_eq!(
full_sorted_bimodal_variant,
sorted_bimodal_variants_full.first().copied(),
"{type_name}: T::sorted_bimodal_variant(T::ALL) drifted from T::sorted_bimodal_variants(T::ALL).first().copied() — the singular Option-return LEX-order direction-composition intersection first-witness MUST agree with the FIRST element of the plural Vec-return LEX-order direction-composition intersection witness-collection walked in the same lex-order canonical order; a divergent full-set first-witness silently bifurcates the LOAD-BEARING plural-vs-singular return-shape identity on the flat-histogram fixture (both projections land on Some(T::sorted_first()) here — the composition identity pins the plural's `.first()` == Some(T::sorted_first()) arm against the singular Some(T::sorted_first()) arm)",
);
assert_eq!(
full_sorted_bimodal_variant.is_some(),
T::has_bimodal_variant(T::ALL),
"{type_name}: T::sorted_bimodal_variant(T::ALL).is_some() drifted from T::has_bimodal_variant(T::ALL) — the Option-return lex-order intersection first-witness is Some iff the bool-return existential predicate holds; a divergent full-set is-some value silently bifurcates the Option-vs-bool return-shape identity on the flat-histogram fixture where BOTH sides fire to `true`",
);
assert_eq!(
full_sorted_bimodal_variant.is_some(),
T::bimodal_variant(T::ALL).is_some(),
"{type_name}: T::sorted_bimodal_variant(T::ALL).is_some() drifted from T::bimodal_variant(T::ALL).is_some() — the (Some, None) partition of the LEX-order intersection first-witness MUST AGREE with the (Some, None) partition of the declaration-order intersection first-witness on every slice; the two projections may disagree on the VALUE they report but MUST agree on WHEN the Some arm fires (both gate through the SAME uniformity dichotomy via T::is_uniform); a divergent full-set is-some sibling value silently bifurcates the LEX-vs-DECL alignment of the (Some, None) partition on the flat-histogram fixture",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_sorted_bimodal_variant = T::sorted_bimodal_variant(&matching_singleton);
assert_eq!(
singleton_sorted_bimodal_variant,
None,
"{type_name}: T::sorted_bimodal_variant([{target_label:?}]) drifted from None at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so the histogram is non-flat (max `1` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on None; a Some matching-singleton value at cardinality >= 2 silently bifurcates the LOAD-BEARING intersection None-arm DISCRIMINATING this LEX-order INTERSECTION projection from [`T::sorted_extremal_variant`] (which lands on Some(T::sorted_first()) on the same fixture via the (max ∨ min) union covering every variant through one of the two arms)",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `None`-arm catch on
// the lex-order intersection first-witness corner. The bimodal
// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` hits T::ALL[0] at
// count `2 == max`, T::ALL[1] at count `1` (MIDDLE), T::ALL[2]
// at count `0 == min`; the histogram is non-flat (max `2` !=
// min `0`), so T::is_uniform reports `false` and the dichotomy
// lands on None. The LOAD-BEARING catch that separates the
// lex-order intersection first-witness from
// [`T::sorted_middle_band_variant`] (which reports
// Some(T::sorted_variants()[1]) on the same fixture) and from
// [`T::sorted_extremal_variant`] (which reports
// Some(T::sorted_first()) on the same fixture) — the three
// lex-order projections split the modal-aggregation matrix into
// its three direction-composition arms on the ONE canonical
// non-flat triple, mirroring the declaration-order trichotomy
// one ORDERING axis over.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_sorted_intersection = T::sorted_bimodal_variant(&bimodal_triple);
assert_eq!(
bimodal_triple_sorted_intersection,
None,
"{type_name}: T::sorted_bimodal_variant(&bimodal_triple) drifted from None — the bimodal-triple fixture is non-flat (max `2` != min `0`), T::is_uniform reports `false`, and the dichotomy MUST land on None; a Some bimodal-triple value silently bifurcates the LOAD-BEARING None-arm catch that separates the lex-order intersection first-witness from T::sorted_middle_band_variant (which reports Some(T::sorted_variants()[1]) on the same fixture) and from T::sorted_extremal_variant (which reports Some(T::sorted_first()) on the same fixture)",
);
assert_eq!(
bimodal_triple_sorted_intersection.is_some(),
T::has_bimodal_variant(&bimodal_triple),
"{type_name}: T::sorted_bimodal_variant(&bimodal_triple).is_some() drifted from T::has_bimodal_variant(&bimodal_triple) — the Option-return lex-order intersection first-witness is Some iff the bool-return existential predicate holds; a divergent bimodal-triple is-some value silently bifurcates the Option-vs-bool return-shape identity on the load-bearing non-flat middle-band fixture where BOTH sides fire to `false`",
);
}
// (162) — `T::has_unique_middle_band_variant(items)` MUST agree with
// the count-composition body `T::count_middle_band_variants(items) ==
// 1` on every slice AND MUST land on its canonical fixpoints (`false`
// on the empty slice UNCONDITIONALLY via the empty-slice guard of
// `count_middle_band_variants` collapsing to `0`; `false` on the
// full-set + doubled-full-set flat-histogram fixpoints where
// `count_middle_band_variants` reports `0` because every variant
// sits at BOTH extremes simultaneously via the (max == min) collapse;
// `false` on every matching singleton at cardinality `>= 2` where
// the two-value dichotomy has NO strict interior; `true` on the
// bimodal-triple fixture at cardinality `>= 3` because the sole
// middle-band witness is T::ALL[1] at count `1` strictly between the
// argmax `2` and argmin `0`, so `count_middle_band_variants` reports
// `1` and `1 == 1` fires). The default trait body threads the
// scalar equality against `1` verbatim and satisfies every fixpoint
// arm for free; the assertion catches a future implementor whose
// override drifts the projection loudly rather than silently
// bifurcating the set-level direction-composition complement
// uniqueness surface. An override that folds onto `true`
// unconditionally bifurcates on the empty-slice arm at
// `true != false` AND on every flat-histogram fixpoint arm at
// `true != false`; an override that folds onto `false`
// unconditionally bifurcates on the bimodal-triple arm at
// cardinality `>= 3` at `false != true` — the SOLE canonical
// fixture witness the (direction-composition × complement ×
// unique-tie) corner has a positive arm.
//
// Sibling posture to clause (135) (the set-level modal-uniqueness
// bit `has_unique_mode == count_modal_variants == 1`) and clause
// (136) (the set-level antimodal-uniqueness bit `has_unique_antimode
// == count_antimodal_variants == 1`) one DIRECTION-COMPOSITION axis
// over: THIS clause OPENS the (set-level × bool × direction-
// composition × unique-tie) column at its COMPLEMENT arm past the
// direction-anchored argmax + argmin corners the two prior clauses
// opened. The natural next clauses will close the remaining
// direction-composition arms (union via `has_unique_extremal_variant`,
// intersection via `has_unique_bimodal_variant`) — both DEGENERATE
// openers at cardinality `>= 2` (false everywhere past the empty
// slice) that nevertheless pin the (direction-composition × unique-
// tie) 3-corner row on the modal-aggregation matrix.
let empty_middle_band_uniqueness = T::has_unique_middle_band_variant(empty);
assert!(
!empty_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant(&[]) drifted from `false` — the empty slice hits zero positions, T::count_middle_band_variants(&[]) collapses to `0` at its empty-slice guard, and `0 != 1`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition complement uniqueness consumer routes through",
);
let full_middle_band_uniqueness = T::has_unique_middle_band_variant(T::ALL);
let expected_full_middle_band_uniqueness = T::count_middle_band_variants(T::ALL) == 1;
assert_eq!(
full_middle_band_uniqueness, expected_full_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant(T::ALL) drifted from (T::count_middle_band_variants(T::ALL) == 1) — the count-composition identity `T::has_unique_middle_band_variant(items) == (T::count_middle_band_variants(items) == 1)` MUST hold on every slice; the flat-histogram full-set fixpoint pins the middle-band count at `0` (every variant sits at both extremes via max == min == 1), so the count-eq-one test lands on `false`; a divergent full-set value silently bifurcates the count-composition identity on the load-bearing flat-histogram fixture",
);
let doubled_middle_band_uniqueness = T::has_unique_middle_band_variant(&doubled_full_set);
let expected_doubled_middle_band_uniqueness =
T::count_middle_band_variants(&doubled_full_set) == 1;
assert_eq!(
doubled_middle_band_uniqueness, expected_doubled_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant(&doubled_full_set) drifted from (T::count_middle_band_variants(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins the middle-band count at `0` (every variant sits at both extremes via max == min == 2), so the count-eq-one test lands on `false`; a divergent doubled-full-set value silently bifurcates the second flat-histogram fixpoint contract",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_middle_band_uniqueness =
T::has_unique_middle_band_variant(&matching_singleton);
assert!(
!singleton_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant([{target_label:?}]) drifted from `false` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`, so the two-value dichotomy has NO strict interior, T::count_middle_band_variants reports `0`, and `0 != 1`; a `true` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (direction-composition × complement × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: the LOAD-BEARING `true`-arm catch on
// the (direction-composition × complement × unique-tie) corner.
// On `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is
// `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]` (count
// `0`), and the sole middle-band witness is T::ALL[1] at count
// `1` strictly between the two extremes; T::count_middle_band_variants
// reports `1`, `1 == 1` fires. The SOLE canonical fixture
// witness the corner has a positive arm — every OTHER canonical
// fixpoint (empty, matching-singleton, full-set, doubled-full-
// set) lands on `false`, so an override that folds onto `false`
// unconditionally passes every other arm silently but bifurcates
// HERE loudly.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_middle_band_uniqueness =
T::has_unique_middle_band_variant(&bimodal_triple);
assert!(
bimodal_triple_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant(&bimodal_triple) drifted from `true` at cardinality >= 3 — the bimodal-triple fixture has the sole middle-band witness T::ALL[1] at count `1` strictly between the argmax `2` and argmin `0`, so T::count_middle_band_variants reports `1` and `1 == 1` fires; a `false` bimodal-triple value silently bifurcates the LOAD-BEARING true-arm catch that separates the (direction-composition × complement × unique-tie) corner from the degenerate direction-anchored + direction-composition unique-tie peers",
);
let expected_bimodal_triple_middle_band_uniqueness =
T::count_middle_band_variants(&bimodal_triple) == 1;
assert_eq!(
bimodal_triple_middle_band_uniqueness,
expected_bimodal_triple_middle_band_uniqueness,
"{type_name}: T::has_unique_middle_band_variant(&bimodal_triple) drifted from (T::count_middle_band_variants(&bimodal_triple) == 1) — the count-composition identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `true`",
);
}
// (163) — `T::has_unique_extremal_variant(items)` MUST agree with the
// count-composition body `T::count_extremal_variants(items) == 1` on
// every slice AND MUST land on its canonical fixpoints. The corner is
// the DEGENERATE OPENER on the union arm of the (set-level × bool ×
// direction-composition × unique-tie) row: at `T::CARDINALITY >= 2`
// the union carries at least one modal variant AND at least one
// antimodal variant (disjoint at non-flat, coincident-through-both-
// extremes at flat), so `count_extremal_variants` is either `0`
// (empty slice) or `>= 2` (non-empty at `T::CARDINALITY >= 2`); the
// equality against `1` fails everywhere past the empty slice. The
// SOLE positive arm sits at `T::CARDINALITY == 1` where the single
// variant's max-and-min-collapse-through-uniformity pins the count
// at `1` on every non-empty slice; the assertion's count-composition
// form catches that arm through the count aggregate itself without
// gating on cardinality.
//
// The default trait body threads the scalar equality against `1`
// verbatim and satisfies every fixpoint arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level direction-
// composition union uniqueness surface. An override that folds onto
// `true` unconditionally bifurcates on the empty-slice arm at `true
// != false` AND on every flat-histogram + matching-singleton +
// bimodal-triple fixpoint arm at cardinality `>= 2` at `true !=
// false`; an override that folds onto `false` unconditionally
// bifurcates ONLY at `T::CARDINALITY == 1` (where the count-
// composition arm at the full-set fixpoint reports `false != true`
// — the SOLE structural catch the degeneracy admits at cardinality
// `>= 2`).
//
// Sibling posture to clause (162) (the direction-composition ×
// complement × unique-tie corner opener via
// [`T::has_unique_middle_band_variant`]) one COMBINATOR axis over:
// THIS clause CLOSES the union arm of the (direction-composition ×
// unique-tie) row past the complement arm the prior clause opened.
// Together with clauses (135) + (136) (the direction-anchored
// argmax + argmin `has_unique_mode` / `has_unique_antimode` peers)
// one DIRECTION-COMPOSITION axis over, the (set-level × bool ×
// direction × unique-tie) 4-corner column now closes at three
// inhabitants; the remaining tile is the intersection arm via
// `has_unique_bimodal_variant == count_bimodal_variants == 1`.
let empty_extremal_uniqueness = T::has_unique_extremal_variant(empty);
let expected_empty_extremal_uniqueness = T::count_extremal_variants(empty) == 1;
assert_eq!(
empty_extremal_uniqueness, expected_empty_extremal_uniqueness,
"{type_name}: T::has_unique_extremal_variant(&[]) drifted from (T::count_extremal_variants(&[]) == 1) — the count-composition identity MUST hold on the empty slice; the empty-slice guard of `count_extremal_variants` collapses the count to `0`, so the equality against `1` fails and the predicate lands on `false`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition union uniqueness consumer routes through",
);
let full_extremal_uniqueness = T::has_unique_extremal_variant(T::ALL);
let expected_full_extremal_uniqueness = T::count_extremal_variants(T::ALL) == 1;
assert_eq!(
full_extremal_uniqueness, expected_full_extremal_uniqueness,
"{type_name}: T::has_unique_extremal_variant(T::ALL) drifted from (T::count_extremal_variants(T::ALL) == 1) — the count-composition identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `count_extremal_variants` reports `T::CARDINALITY >= 2`, and the equality against `1` fails; at `T::CARDINALITY == 1` the single variant sits at count `1 == max == min`, `count_extremal_variants` reports `1`, and the equality against `1` holds — the SOLE positive arm of the degenerate opener; a divergent full-set value silently bifurcates the load-bearing structural catch for a `false`-drifting override on cardinality-1 implementors",
);
let doubled_extremal_uniqueness = T::has_unique_extremal_variant(&doubled_full_set);
let expected_doubled_extremal_uniqueness = T::count_extremal_variants(&doubled_full_set) == 1;
assert_eq!(
doubled_extremal_uniqueness, expected_doubled_extremal_uniqueness,
"{type_name}: T::has_unique_extremal_variant(&doubled_full_set) drifted from (T::count_extremal_variants(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `count_extremal_variants` reports `T::CARDINALITY`, and the equality against `1` fails at cardinality `>= 2` (holds at cardinality `== 1` where the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2)",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_extremal_uniqueness = T::has_unique_extremal_variant(&matching_singleton);
assert!(
!singleton_extremal_uniqueness,
"{type_name}: T::has_unique_extremal_variant([{target_label:?}]) drifted from `false` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; the argmax band {{{target_label:?}}} (size 1) and the argmin band `T::ALL \\ {{{target_label:?}}}` (size `T::CARDINALITY - 1 >= 1`) are disjoint, so `count_extremal_variants` reports `T::CARDINALITY >= 2`, and `T::CARDINALITY != 1`; a `true` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (direction-composition × union × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `false`-arm catch on the
// (direction-composition × union × unique-tie) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is `{T::ALL[0]}`
// (count `2`), the argmin is `T::ALL[2..]` (count `0`), the
// union carries the two disjoint bands, `count_extremal_variants`
// reports `T::CARDINALITY - 1 >= 2`, and the equality against
// `1` fails. DISCRIMINATES this uniqueness corner from
// [`T::has_unique_middle_band_variant`]'s SOLE positive arm on
// the same fixture — the union-arm degenerate opener and the
// complement-arm strict-interior positive arm split the
// direction-composition axis on the canonical bimodal fixture.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_extremal_uniqueness = T::has_unique_extremal_variant(&bimodal_triple);
let expected_bimodal_triple_extremal_uniqueness =
T::count_extremal_variants(&bimodal_triple) == 1;
assert_eq!(
bimodal_triple_extremal_uniqueness, expected_bimodal_triple_extremal_uniqueness,
"{type_name}: T::has_unique_extremal_variant(&bimodal_triple) drifted from (T::count_extremal_variants(&bimodal_triple) == 1) — the count-composition identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `false` (T::count_extremal_variants reports `T::CARDINALITY - 1 >= 2`, the union of the argmax band and the argmin band on the canonical non-flat triple)",
);
}
// (164) — `T::has_unique_bimodal_variant(items)` MUST agree with the
// count-composition body `T::count_bimodal_variants(items) == 1` on
// every slice AND MUST land on its canonical fixpoints. The corner is
// the DEGENERATE OPENER on the intersection arm of the (set-level ×
// bool × direction-composition × unique-tie) row: the just-lifted
// `count_bimodal_variants` folds into the two-value dichotomy `{0,
// T::CARDINALITY}` on every slice (empty / non-flat → `0` via the
// disjoint argmax/argmin bands; flat → `T::CARDINALITY` via the
// `max == min` collapse that pins every variant at both extremes
// simultaneously). Neither `0` nor `T::CARDINALITY` equals `1` at
// `T::CARDINALITY >= 2`, so the equality against `1` fails
// everywhere past the empty slice. The SOLE positive arm sits at
// `T::CARDINALITY == 1` where the single variant's max-and-min-
// collapse-through-uniformity pins the count at `1` on every non-
// empty slice; the assertion's count-composition form catches that
// arm through the count aggregate itself without gating on
// cardinality.
//
// The default trait body threads the scalar equality against `1`
// verbatim and satisfies every fixpoint arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level direction-
// composition intersection uniqueness surface. An override that
// folds onto `true` unconditionally bifurcates on the empty-slice
// arm at `true != false` AND on every flat-histogram +
// matching-singleton + bimodal-triple fixpoint arm at cardinality
// `>= 2` at `true != false`; an override that folds onto `false`
// unconditionally bifurcates ONLY at `T::CARDINALITY == 1` (where
// the count-composition arm at the full-set fixpoint reports
// `false != true` — the SOLE structural catch the degeneracy
// admits at cardinality `>= 2`).
//
// Sibling posture to clause (163) (the direction-composition ×
// union × unique-tie corner via
// [`T::has_unique_extremal_variant`]) one COMBINATOR axis over:
// THIS clause CLOSES the intersection arm of the (direction-
// composition × unique-tie) row past the union arm the prior
// clause opened AND EXHAUSTIVELY closes the (direction-composition
// × combinator × unique-tie) 3-corner row at its FINAL THIRD tile
// past the UNION arm and the COMPLEMENT arm. Together with clauses
// (135) + (136) (the direction-anchored argmax + argmin
// `has_unique_mode` / `has_unique_antimode` peers) one DIRECTION-
// COMPOSITION axis over, the (set-level × bool × direction ×
// unique-tie) 4-column landscape now closes at ALL FOUR
// inhabitants (argmax, argmin, union, complement, intersection).
let empty_bimodal_uniqueness = T::has_unique_bimodal_variant(empty);
let expected_empty_bimodal_uniqueness = T::count_bimodal_variants(empty) == 1;
assert_eq!(
empty_bimodal_uniqueness, expected_empty_bimodal_uniqueness,
"{type_name}: T::has_unique_bimodal_variant(&[]) drifted from (T::count_bimodal_variants(&[]) == 1) — the count-composition identity MUST hold on the empty slice; the empty-slice guard of `count_bimodal_variants` collapses the count to `0`, so the equality against `1` fails and the predicate lands on `false`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition intersection uniqueness consumer routes through",
);
let full_bimodal_uniqueness = T::has_unique_bimodal_variant(T::ALL);
let expected_full_bimodal_uniqueness = T::count_bimodal_variants(T::ALL) == 1;
assert_eq!(
full_bimodal_uniqueness, expected_full_bimodal_uniqueness,
"{type_name}: T::has_unique_bimodal_variant(T::ALL) drifted from (T::count_bimodal_variants(T::ALL) == 1) — the count-composition identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `count_bimodal_variants` reports `T::CARDINALITY >= 2`, and the equality against `1` fails; at `T::CARDINALITY == 1` the single variant sits at count `1 == max == min`, `count_bimodal_variants` reports `1`, and the equality against `1` holds — the SOLE positive arm of the degenerate opener; a divergent full-set value silently bifurcates the load-bearing structural catch for a `false`-drifting override on cardinality-1 implementors",
);
let doubled_bimodal_uniqueness = T::has_unique_bimodal_variant(&doubled_full_set);
let expected_doubled_bimodal_uniqueness = T::count_bimodal_variants(&doubled_full_set) == 1;
assert_eq!(
doubled_bimodal_uniqueness, expected_doubled_bimodal_uniqueness,
"{type_name}: T::has_unique_bimodal_variant(&doubled_full_set) drifted from (T::count_bimodal_variants(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `count_bimodal_variants` reports `T::CARDINALITY`, and the equality against `1` fails at cardinality `>= 2` (holds at cardinality `== 1` where the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2)",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_bimodal_uniqueness = T::has_unique_bimodal_variant(&matching_singleton);
assert!(
!singleton_bimodal_uniqueness,
"{type_name}: T::has_unique_bimodal_variant([{target_label:?}]) drifted from `false` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; `max != min`, no variant sits at BOTH extremes simultaneously, `count_bimodal_variants` reports `0`, and `0 != 1`; a `true` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (direction-composition × intersection × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `false`-arm catch on the
// (direction-composition × intersection × unique-tie) corner.
// On `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is
// `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]`
// (count `0`), `max != min`, so no variant sits in the
// intersection and `count_bimodal_variants` reports `0`.
// DISCRIMINATES this uniqueness corner from
// [`T::has_unique_middle_band_variant`]'s SOLE positive arm on
// the same fixture — the intersection-arm degenerate opener
// and the complement-arm strict-interior positive arm split
// the direction-composition axis on the canonical bimodal
// fixture. Peer discriminator to clause (163)'s bimodal-triple
// arm one COMBINATOR axis over: the union aggregate reports
// `T::CARDINALITY - 1 >= 2`; this intersection aggregate
// reports `0`. Both arms of the row fold onto `false` past the
// empty slice at cardinality `>= 2`, but through
// complementary aggregate numerators.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_bimodal_uniqueness = T::has_unique_bimodal_variant(&bimodal_triple);
let expected_bimodal_triple_bimodal_uniqueness =
T::count_bimodal_variants(&bimodal_triple) == 1;
assert_eq!(
bimodal_triple_bimodal_uniqueness, expected_bimodal_triple_bimodal_uniqueness,
"{type_name}: T::has_unique_bimodal_variant(&bimodal_triple) drifted from (T::count_bimodal_variants(&bimodal_triple) == 1) — the count-composition identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `false` (T::count_bimodal_variants reports `0`, the disjoint argmax band intersect argmin band on the canonical non-flat triple)",
);
}
// (165) — `T::unique_extremal_variant(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_extremal_variant(items) { T::extremal_variant(items) } else { None }`
// on every slice AND MUST land on its canonical fixpoints. The corner
// is the DEGENERATE OPENER on the (set-level × `Option<Self>` ×
// direction-composition × union × unique-tie) column: the just-lifted
// `has_unique_extremal_variant` is `false` on the empty slice AND on
// every non-empty slice at `T::CARDINALITY >= 2` (the inclusion-
// exclusion identity pins the union count at either `0` or `>= 2`
// past the empty slice), so the guarded lift collapses to `None`
// everywhere past the empty slice at cardinality `>= 2`. The SOLE
// `Some(_)` arm sits at `T::CARDINALITY == 1` where the single
// variant's max-and-min-collapse-through-uniformity pins the count
// at `1` on every non-empty slice and the extremal witness is the
// unique variant; the assertion's guarded-lift form catches that arm
// through the guarded lift itself without gating on cardinality.
//
// The default trait body threads the boolean-guarded `Option`-
// collapse verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// direction-composition union witness-if-unique surface. An override
// that folds onto `Some(T::first())` unconditionally bifurcates on
// the empty-slice arm at `Some(_) != None` AND on every flat-
// histogram + matching-singleton + bimodal-triple fixpoint arm at
// cardinality `>= 2` at `Some(_) != None`; an override that folds
// onto `None` unconditionally bifurcates ONLY at `T::CARDINALITY ==
// 1` (where the guarded-lift arm at the full-set fixpoint reports
// `None != Some(T::ALL[0])` — the SOLE structural catch the
// degeneracy admits at cardinality `>= 2`).
//
// Sibling posture to clause (139) (the direction × `Option<Self>` ×
// argmax × unique-tie corner opener via [`T::unique_modal_variant`])
// one DIRECTION-COMPOSITION axis over: THIS clause OPENS the union
// arm of the (set-level × `Option<Self>` × direction-composition ×
// unique-tie) row past the argmax + argmin peers one DIRECTION-
// COMPOSITION axis over. Together with clauses (163) + (164) (the
// (set-level × bool × direction-composition × union / intersection
// × unique-tie) counterparts) one RETURN-SHAPE axis over, the
// (`Option<Self>` × direction-composition × union × unique-tie)
// corner now closes the RETURN-SHAPE axis at the boolean-guarded-
// Option-collapse layer above the pre-existing bool-return uniqueness
// bit.
let empty_unique_extremal = T::unique_extremal_variant(empty);
let expected_empty_unique_extremal = if T::has_unique_extremal_variant(empty) {
T::extremal_variant(empty)
} else {
None
};
assert_eq!(
empty_unique_extremal, expected_empty_unique_extremal,
"{type_name}: T::unique_extremal_variant(&[]) drifted from the guarded lift `if T::has_unique_extremal_variant(&[]) {{ T::extremal_variant(&[]) }} else {{ None }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_extremal_variant` collapses to `false`, the guarded lift short-circuits to `None`, and `T::extremal_variant(&[])`'s own `None`-at-empty branch is not consulted; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition union witness-if-unique consumer routes through",
);
let full_unique_extremal = T::unique_extremal_variant(T::ALL);
let expected_full_unique_extremal = if T::has_unique_extremal_variant(T::ALL) {
T::extremal_variant(T::ALL)
} else {
None
};
assert_eq!(
full_unique_extremal, expected_full_unique_extremal,
"{type_name}: T::unique_extremal_variant(T::ALL) drifted from the guarded lift `if T::has_unique_extremal_variant(T::ALL) {{ T::extremal_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `has_unique_extremal_variant` returns `false`, and the guarded lift collapses to `None`; at `T::CARDINALITY == 1` the single variant sits at count `1 == max == min`, `has_unique_extremal_variant` returns `true`, and the guarded lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the degenerate opener; a divergent full-set value silently bifurcates the load-bearing structural catch for a `None`-drifting override on cardinality-1 implementors",
);
let doubled_unique_extremal = T::unique_extremal_variant(&doubled_full_set);
let expected_doubled_unique_extremal = if T::has_unique_extremal_variant(&doubled_full_set) {
T::extremal_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_unique_extremal, expected_doubled_unique_extremal,
"{type_name}: T::unique_extremal_variant(&doubled_full_set) drifted from the guarded lift `if T::has_unique_extremal_variant(&doubled_full_set) {{ T::extremal_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `has_unique_extremal_variant` returns `false` at cardinality `>= 2`, and the guarded lift collapses to `None` (at cardinality `== 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2, so the guarded lift reports `Some(T::ALL[0])`)",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_unique_extremal = T::unique_extremal_variant(&matching_singleton);
assert_eq!(
singleton_unique_extremal, None,
"{type_name}: T::unique_extremal_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; the argmax band {{{target_label:?}}} (size 1) and the argmin band `T::ALL \\ {{{target_label:?}}}` (size `T::CARDINALITY - 1 >= 1`) are disjoint, so `count_extremal_variants` reports `T::CARDINALITY >= 2`, `has_unique_extremal_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (Option<Self> × direction-composition × union × unique-tie) corner — LOAD-BEARING ASYMMETRY against T::unique_modal_variant which returns Some({target_label:?}) on the same slice at any cardinality",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `None`-arm catch on the
// (`Option<Self>` × direction-composition × union × unique-tie)
// corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]` the argmax is
// `{T::ALL[0]}` (count `2`), the argmin is `T::ALL[2..]` (count
// `0`), the union carries the two disjoint bands,
// `count_extremal_variants` reports `T::CARDINALITY - 1 >= 2`,
// `has_unique_extremal_variant` returns `false`, and the guard
// collapses the projection to `None`.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_extremal = T::unique_extremal_variant(&bimodal_triple);
let expected_bimodal_triple_unique_extremal =
if T::has_unique_extremal_variant(&bimodal_triple) {
T::extremal_variant(&bimodal_triple)
} else {
None
};
assert_eq!(
bimodal_triple_unique_extremal, expected_bimodal_triple_unique_extremal,
"{type_name}: T::unique_extremal_variant(&bimodal_triple) drifted from the guarded lift `if T::has_unique_extremal_variant(&bimodal_triple) {{ T::extremal_variant(&bimodal_triple) }} else {{ None }}` — the guarded-lift identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `None` (T::has_unique_extremal_variant reports `false` via T::count_extremal_variants == T::CARDINALITY - 1 >= 2)",
);
}
// (166) — `T::unique_middle_band_variant(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_middle_band_variant(items) { T::middle_band_variant(items) } else { None }`
// on every slice AND MUST land on its canonical fixpoints. The corner
// is the LOAD-BEARING POSITIVE OPENER on the (set-level ×
// `Option<Self>` × direction-composition × complement × unique-tie)
// column: the just-lifted `has_unique_middle_band_variant` is `false`
// on the empty slice AND on every FLAT-histogram fixpoint (max == min
// pins every count at both extremes, no variant sits strictly
// between, `count_middle_band_variants` reports `0`), so the guarded
// lift collapses to `None` at empty + full-set + doubled-full-set +
// matching-singleton. The SOLE `Some(_)` arm on the canonical fixture
// window sits at the bimodal-triple at cardinality `>= 3` where
// `T::ALL[1]` is the sole strict-interior inhabitant with count `1`
// strictly between max `2` and min `0`; the assertion's guarded-lift
// form catches BOTH the None-arms AND the SOLE Some-arm through the
// guarded lift itself.
//
// The default trait body threads the boolean-guarded `Option`-
// collapse verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// direction-composition complement witness-if-unique surface. An
// override that folds onto `Some(T::first())` unconditionally
// bifurcates on the empty-slice arm at `Some(_) != None` AND on
// every flat-histogram + matching-singleton fixpoint arm at
// `Some(T::first()) != None`. An override that folds onto `None`
// unconditionally bifurcates ONLY on the bimodal-triple arm at
// cardinality `>= 3` at `None != Some(T::ALL[1])` — the SOLE
// structural catch the (Option<Self> × complement × unique-tie)
// corner's positive arm carries on the canonical fixture window,
// sibling posture to clause (158)'s bimodal-triple positive arm one
// UNIQUE-TIE-SHARPENING axis over.
//
// Sibling posture to clause (165) (the direction-composition × union
// × unique-tie corner opener via [`T::unique_extremal_variant`]) one
// COMBINATOR axis over: THIS clause CLOSES the complement arm of the
// (set-level × `Option<Self>` × direction-composition × unique-tie)
// row past the just-opened UNION arm one COMBINATOR axis over.
// Together with clauses (162) + (163) + (164) (the (set-level × bool
// × direction-composition × complement / union / intersection ×
// unique-tie) counterparts) one RETURN-SHAPE axis over, the
// (`Option<Self>` × direction-composition × complement × unique-tie)
// corner now closes the RETURN-SHAPE axis at the boolean-guarded-
// Option-collapse layer above the pre-existing bool-return
// uniqueness bit. LOAD-BEARING DISCRIMINATOR from clause (165) on
// the bimodal-triple: the union arm's guarded lift collapses to
// `None` (both extremes carry a full band); THIS complement arm's
// guarded lift lands on `Some(T::ALL[1])` (the strict-interior
// singleton). The two arms of the row split the direction-
// composition axis on the canonical bimodal fixture at cardinality
// `>= 3`.
let empty_unique_middle_band = T::unique_middle_band_variant(empty);
let expected_empty_unique_middle_band = if T::has_unique_middle_band_variant(empty) {
T::middle_band_variant(empty)
} else {
None
};
assert_eq!(
empty_unique_middle_band, expected_empty_unique_middle_band,
"{type_name}: T::unique_middle_band_variant(&[]) drifted from the guarded lift `if T::has_unique_middle_band_variant(&[]) {{ T::middle_band_variant(&[]) }} else {{ None }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_middle_band_variant` collapses to `false` via `count_middle_band_variants(&[]) == 0 != 1`, the guarded lift short-circuits to `None`, and `T::middle_band_variant(&[])`'s own `None`-at-empty branch is not consulted; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition complement witness-if-unique consumer routes through",
);
let full_unique_middle_band = T::unique_middle_band_variant(T::ALL);
let expected_full_unique_middle_band = if T::has_unique_middle_band_variant(T::ALL) {
T::middle_band_variant(T::ALL)
} else {
None
};
assert_eq!(
full_unique_middle_band, expected_full_unique_middle_band,
"{type_name}: T::unique_middle_band_variant(T::ALL) drifted from the guarded lift `if T::has_unique_middle_band_variant(T::ALL) {{ T::middle_band_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `count_middle_band_variants` reports `0`, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `None`; at `T::CARDINALITY == 1` the single variant sits at count `1 == max == min`, `count_middle_band_variants` reports `0` (no strict interior on the (max == min) collapse), `has_unique_middle_band_variant` returns `false`, and the guarded lift stays at `None`",
);
let doubled_unique_middle_band = T::unique_middle_band_variant(&doubled_full_set);
let expected_doubled_unique_middle_band =
if T::has_unique_middle_band_variant(&doubled_full_set) {
T::middle_band_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_unique_middle_band, expected_doubled_unique_middle_band,
"{type_name}: T::unique_middle_band_variant(&doubled_full_set) drifted from the guarded lift `if T::has_unique_middle_band_variant(&doubled_full_set) {{ T::middle_band_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `count_middle_band_variants` reports `0`, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `None`",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_unique_middle_band = T::unique_middle_band_variant(&matching_singleton);
assert_eq!(
singleton_unique_middle_band, None,
"{type_name}: T::unique_middle_band_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; EVERY variant of T::ALL sits AT one of the two extremes, NO variant sits strictly between, `count_middle_band_variants` reports `0`, `has_unique_middle_band_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (Option<Self> × direction-composition × complement × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[1])`-arm
// catch on the (`Option<Self>` × direction-composition ×
// complement × unique-tie) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at count
// `2 == max`, `T::ALL[1]` at count `1` STRICTLY between max `2`
// and min `0` (the SOLE strict-interior inhabitant), `T::ALL[2..]`
// at count `0 == min`; `count_middle_band_variants` reports `1`,
// `has_unique_middle_band_variant` returns `true`, the guard
// fires, and `T::middle_band_variant`'s declaration-order sweep
// hits `T::ALL[1]` immediately. LOAD-BEARING DISCRIMINATOR from
// clause (165)'s bimodal-triple arm one COMBINATOR axis over:
// the union arm's guarded lift collapses to `None` on the same
// fixture; THIS complement arm's guarded lift lands on
// `Some(T::ALL[1])` — the direction-composition axis SEPARATES
// the DEGENERATE union opener from THIS POSITIVE complement
// opener on the canonical bimodal fixture.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_middle_band = T::unique_middle_band_variant(&bimodal_triple);
let expected_bimodal_triple_unique_middle_band =
if T::has_unique_middle_band_variant(&bimodal_triple) {
T::middle_band_variant(&bimodal_triple)
} else {
None
};
assert_eq!(
bimodal_triple_unique_middle_band, expected_bimodal_triple_unique_middle_band,
"{type_name}: T::unique_middle_band_variant(&bimodal_triple) drifted from the guarded lift `if T::has_unique_middle_band_variant(&bimodal_triple) {{ T::middle_band_variant(&bimodal_triple) }} else {{ None }}` — the guarded-lift identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `Some(T::ALL[1])` (T::has_unique_middle_band_variant reports `true` via T::count_middle_band_variants == 1, and T::middle_band_variant's declaration-order sweep hits T::ALL[1] as the SOLE strict-interior inhabitant); this fixture is the ONLY canonical fixpoint where THIS projection returns a Some value across the (empty, full-set, doubled-full-set, matching-singleton, bimodal-triple) 5-arm fixture window",
);
assert_eq!(
bimodal_triple_unique_middle_band,
Some(T::ALL[1]),
"{type_name}: T::unique_middle_band_variant(&bimodal_triple) drifted from Some(T::ALL[1]) — the LOAD-BEARING SOLE `Some(_)`-arm on the canonical fixture window; T::ALL[1] is the SOLE strict-interior inhabitant with count `1` strictly between max `2` and min `0`, so `count_middle_band_variants` reports `1` (uniqueness holds), `has_unique_middle_band_variant` returns `true` (the guard fires), `T::middle_band_variant` hits T::ALL[1] immediately (declaration-order sweep at strict interior), and the guarded lift lands on Some(T::ALL[1]); LOAD-BEARING DISCRIMINATOR from T::unique_extremal_variant which returns `None` on the same fixture (the direction-composition axis SEPARATES the union DEGENERATE opener from THIS complement POSITIVE opener at cardinality >= 3)",
);
}
// (167) — `T::unique_bimodal_variant(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_bimodal_variant(items) { T::bimodal_variant(items) } else { None }`
// on every slice AND MUST land on its canonical fixpoints. The corner
// is the DEGENERATE OPENER on the intersection arm of the (set-level
// × `Option<Self>` × direction-composition × unique-tie) row: the
// just-lifted `has_unique_bimodal_variant` folds through the
// two-value dichotomy `count_bimodal_variants ∈ {0, T::CARDINALITY}`
// (empty / non-flat → `0`; flat → `T::CARDINALITY` via the max ==
// min collapse), so at cardinality `>= 2` neither branch matches the
// required `1`, `has_unique_bimodal_variant` returns `false`
// everywhere, and the guarded lift collapses to `None` on every
// fixpoint. The SOLE `Some(_)` arm sits at `T::CARDINALITY == 1`
// where every non-empty slice is trivially uniform, the count
// collapses to `1`, and the intersection witness is the unique
// variant; the assertion's guarded-lift form catches that arm
// through the guarded lift itself without gating on cardinality.
//
// The default trait body threads the boolean-guarded `Option`-
// collapse verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// direction-composition intersection witness-if-unique surface. An
// override that folds onto `Some(T::first())` unconditionally
// bifurcates on the empty-slice arm at `Some(_) != None` AND on every
// non-empty fixpoint at cardinality `>= 2` at `Some(_) != None`; an
// override that folds onto `None` unconditionally bifurcates ONLY at
// `T::CARDINALITY == 1` (where the guarded-lift arm at the full-set
// fixpoint reports `None != Some(T::ALL[0])` — the SOLE structural
// catch the degeneracy admits at cardinality `>= 2`).
//
// Sibling posture to clauses (165) + (166) (the direction-composition
// × union + complement × unique-tie corners via
// [`T::unique_extremal_variant`] + [`T::unique_middle_band_variant`])
// one COMBINATOR axis over: THIS clause CLOSES the intersection arm
// of the (set-level × `Option<Self>` × direction-composition ×
// unique-tie) row past the just-opened UNION arm AND the just-closed
// COMPLEMENT arm AND EXHAUSTIVELY CLOSES the (`Option<Self>` ×
// direction-composition × combinator × unique-tie) 3-corner row at
// its FINAL THIRD tile. Together with clauses (162) + (163) + (164)
// (the (set-level × bool × direction-composition × complement / union
// / intersection × unique-tie) counterparts) one RETURN-SHAPE axis
// over, the (direction-composition × combinator × unique-tie) 2×3 =
// 6-corner (bool × Option) × (union × complement × intersection)
// landscape now closes at ALL SIX inhabitants at the boolean-guarded-
// Option-collapse layer above the pre-existing bool-return
// uniqueness bits. LOAD-BEARING DISCRIMINATOR from clause (166) on
// the bimodal-triple: the complement arm's guarded lift lands on
// `Some(T::ALL[1])` (the strict-interior singleton); THIS
// intersection arm's guarded lift collapses to `None` (no variant
// hits both extremes simultaneously on the non-flat triple). The two
// arms of the row split the direction-composition axis on the
// canonical bimodal fixture at cardinality `>= 3`.
let empty_unique_bimodal = T::unique_bimodal_variant(empty);
let expected_empty_unique_bimodal = if T::has_unique_bimodal_variant(empty) {
T::bimodal_variant(empty)
} else {
None
};
assert_eq!(
empty_unique_bimodal, expected_empty_unique_bimodal,
"{type_name}: T::unique_bimodal_variant(&[]) drifted from the guarded lift `if T::has_unique_bimodal_variant(&[]) {{ T::bimodal_variant(&[]) }} else {{ None }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_bimodal_variant` collapses to `false` via `count_bimodal_variants(&[]) == 0 != 1`, the guarded lift short-circuits to `None`, and `T::bimodal_variant(&[])`'s own `None`-at-empty branch is not consulted; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream direction-composition intersection witness-if-unique consumer routes through",
);
let full_unique_bimodal = T::unique_bimodal_variant(T::ALL);
let expected_full_unique_bimodal = if T::has_unique_bimodal_variant(T::ALL) {
T::bimodal_variant(T::ALL)
} else {
None
};
assert_eq!(
full_unique_bimodal, expected_full_unique_bimodal,
"{type_name}: T::unique_bimodal_variant(T::ALL) drifted from the guarded lift `if T::has_unique_bimodal_variant(T::ALL) {{ T::bimodal_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `count_bimodal_variants` reports `T::CARDINALITY >= 2`, `has_unique_bimodal_variant` returns `false`, and the guarded lift collapses to `None`; at `T::CARDINALITY == 1` the single variant sits at count `1 == max == min`, `count_bimodal_variants` reports `1`, `has_unique_bimodal_variant` returns `true`, and the guarded lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the degenerate opener; a divergent full-set value silently bifurcates the load-bearing structural catch for a `None`-drifting override on cardinality-1 implementors",
);
let doubled_unique_bimodal = T::unique_bimodal_variant(&doubled_full_set);
let expected_doubled_unique_bimodal = if T::has_unique_bimodal_variant(&doubled_full_set) {
T::bimodal_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_unique_bimodal, expected_doubled_unique_bimodal,
"{type_name}: T::unique_bimodal_variant(&doubled_full_set) drifted from the guarded lift `if T::has_unique_bimodal_variant(&doubled_full_set) {{ T::bimodal_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `count_bimodal_variants` reports `T::CARDINALITY`, `has_unique_bimodal_variant` returns `false` at cardinality `>= 2`, and the guarded lift collapses to `None` (at cardinality `== 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2, so the guarded lift reports `Some(T::ALL[0])`)",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_unique_bimodal = T::unique_bimodal_variant(&matching_singleton);
assert_eq!(
singleton_unique_bimodal, None,
"{type_name}: T::unique_bimodal_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; `max != min` pins a strict direction split, NO variant hits both extremes simultaneously, `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (Option<Self> × direction-composition × intersection × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `None`-arm catch on the
// (`Option<Self>` × direction-composition × intersection ×
// unique-tie) corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at count `1`,
// `T::ALL[2..]` at count `0 == min`; `max != min` pins a strict
// direction split, NO variant hits both extremes,
// `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant`
// returns `false`, and the guard collapses the projection to
// `None`. LOAD-BEARING DISCRIMINATOR from clause (166)'s
// bimodal-triple arm one COMBINATOR axis over: the complement
// arm's guarded lift lands on `Some(T::ALL[1])`; THIS
// intersection arm's guarded lift collapses to `None` — the
// direction-composition axis SEPARATES the POSITIVE complement
// arm from THIS DEGENERATE intersection arm on the canonical
// bimodal fixture at cardinality `>= 3`.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_bimodal = T::unique_bimodal_variant(&bimodal_triple);
let expected_bimodal_triple_unique_bimodal =
if T::has_unique_bimodal_variant(&bimodal_triple) {
T::bimodal_variant(&bimodal_triple)
} else {
None
};
assert_eq!(
bimodal_triple_unique_bimodal, expected_bimodal_triple_unique_bimodal,
"{type_name}: T::unique_bimodal_variant(&bimodal_triple) drifted from the guarded lift `if T::has_unique_bimodal_variant(&bimodal_triple) {{ T::bimodal_variant(&bimodal_triple) }} else {{ None }}` — the guarded-lift identity MUST hold on the bimodal-triple fixture where BOTH sides fire to `None` (T::has_unique_bimodal_variant reports `false` via T::count_bimodal_variants == 0 on the disjoint argmax/argmin split)",
);
}
// (168) — `T::is_unique_extremal_variant_of(target, items)` MUST agree
// with the conjunction of `T::is_extremal_variant_of(target, items)` and
// `T::has_unique_extremal_variant(items)` on every (target, slice) pair
// AND MUST land on its canonical fixpoints (`false` at every target on
// the empty slice UNCONDITIONALLY via [`T::is_extremal_variant_of`]'s
// empty-slice guard, `false` at every target on every matching
// singleton `[v]` at cardinality `>= 2` because
// [`T::has_unique_extremal_variant`] reports `false` at
// `count_extremal_variants([v]) == T::CARDINALITY >= 2 != 1`, `false`
// at every non-matching target on every non-matching singleton `[w]`
// with `T::index_of(v) != T::index_of(w)` at cardinality `>= 3` via
// the same `count_extremal_variants([w]) == T::CARDINALITY >= 3 != 1`
// fixpoint, `false` at every target on the full-set slice at
// cardinality `>= 2` via [`T::has_unique_extremal_variant`]'s flat-
// histogram fixpoint, `false` at every target on the doubled-full-set
// slice at cardinality `>= 2` via the same flat-histogram fixpoint,
// `false` at every target on the bimodal-triple fixture at cardinality
// `>= 3` via the disjoint-band fixpoint `count_extremal_variants ==
// T::CARDINALITY - 1 >= 2 != 1`) AND on ONE composition-equality arm
// on the full-set fixpoint at cardinality `>= 2`: the set-level filter-
// count reduction over [`T::ALL`] of THIS per-target predicate MUST
// equal `T::has_unique_extremal_variant(T::ALL) as usize == 0` at
// cardinality `>= 2`, pinning the at-most-one-target contract as a
// TYPED CONSEQUENCE of the set-level extremal-uniqueness bit.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past [`T::is_extremal_variant_of`]'s `false` at the
// empty slice) AND on the matching-singleton arm at every target at
// cardinality `>= 2` (returns `true` past the `count_extremal_variants
// == T::CARDINALITY >= 2` fixpoint that pins the uniqueness arm at
// `false`) AND on both flat-histogram fixpoint arms at cardinality
// `>= 2` (which pin the projection at `false` because
// [`T::has_unique_extremal_variant`] falsifies universally at the flat
// histogram) AND on the bimodal-triple arm at cardinality `>= 3` (the
// `count_extremal_variants == T::CARDINALITY - 1 >= 2` fixpoint).
//
// No `false` drift-catch arm is available on a cardinality-`>= 2`
// multi-variant implementor — every canonical fixture pins the
// projection at `false`, mirroring the degenerate-opener property
// clauses (163) + (165) document one ARITY axis over via
// [`T::has_unique_extremal_variant`] + [`T::unique_extremal_variant`].
// The SOLE `true` arm sits at `T::CARDINALITY == 1` where a non-empty
// slice trivially collapses the union band to a single variant, out of
// reach of the multi-variant test-module fixtures.
//
// Sibling posture to clause (137) one DIRECTION-COMPOSITION axis over:
// clause (137) pins the (per-target × bool × direction × argmax ×
// unique-tie) corner via [`T::is_unique_modal_variant_of`]; this
// clause OPENS the (per-target × bool × direction-composition × union
// × unique-tie) corner via [`T::is_extremal_variant_of`]
// conjoined with [`T::has_unique_extremal_variant`], collapsing the
// direction-anchored argmax/argmin unique-tie pair into a union
// direction-composition unique-tie corner one DIRECTION-COMPOSITION
// axis over. Sibling posture to clause (163) one ARITY axis over:
// clause (163) pins the set-level extremal-uniqueness bit; this clause
// LIFTS the same uniqueness predicate to the per-target arity axis
// under conjunction with the per-target union membership predicate.
// Sibling posture to clause (165) one RETURN-SHAPE axis over: clause
// (165) pins the set-level `Option<Self>` union witness-if-unique
// projection; this clause pins the per-target `bool` union membership-
// if-unique predicate. The default trait body threads the
// `is_extremal_variant_of(target, items) && has_unique_extremal_variant(items)`
// conjunction verbatim and satisfies every fixpoint arm + the
// composition arm for free; the assertion catches a future implementor
// whose override drifts the projection loudly rather than silently
// bifurcating the per-target unique-boundary surface every downstream
// unique-boundary consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_extremal_variant_of(target, empty),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, &[]) != false — the per-target unique-extremum predicate MUST report `false` on the empty slice at every target because T::is_extremal_variant_of(v, &[]) collapses to `false` via its empty-slice guard; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-boundary consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_extremal_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, [{target_label:?}]) != false — at cardinality >= 2 the sole target hits count `1 == max`, every non-target sits at count `0 == min`, T::is_extremal_variant_of reports `true` at every target on the union band, but T::has_unique_extremal_variant([{target_label:?}]) == false at count_extremal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` matching-singleton arm at cardinality >= 2 silently bifurcates the degenerate-opener property clause (163) documents",
);
assert!(
!T::is_unique_extremal_variant_of(target, T::ALL),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, T::is_extremal_variant_of reports `true` at every target on the flat-histogram fixpoint (max == min == 1), but T::has_unique_extremal_variant(T::ALL) == false at count_extremal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::is_extremal_variant_of which reports `true` on the same slice",
);
assert!(
!T::is_unique_extremal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_extremal_variant_of reports `true` at every target on the flat-histogram fixpoint (max == min == 2), but T::has_unique_extremal_variant(doubled) == false at count_extremal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_unique_extremal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the target's count is `0 == min`, T::is_extremal_variant_of reports `true` at the target on the argmin band, but T::has_unique_extremal_variant([{other_label:?}]) == false at count_extremal_variants == T::CARDINALITY >= 3 != 1 at cardinality >= 3 (one argmax witness + T::CARDINALITY - 1 argmin witnesses), so the conjunction lands on `false` through the uniqueness arm; a `true` non-matching-singleton arm at cardinality >= 3 silently bifurcates the LOAD-BEARING asymmetry against T::is_extremal_variant_of which reports `true` on the same slice",
);
}
}
// Bimodal-triple fixture — LOAD-BEARING `false`-arm catch on
// the (per-target × bool × direction-composition × union ×
// unique-tie) corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at count
// `1` (strictly interior — off the union band), `T::ALL[2..]`
// at count `0 == min`; T::is_extremal_variant_of reports
// `true` at `T::ALL[0]` + at every `T::ALL[i]` for `i >= 2`
// (union band = 1 argmax + T::CARDINALITY - 2 argmin
// witnesses), but T::has_unique_extremal_variant reports
// `false` at count_extremal_variants == T::CARDINALITY - 1
// >= 2, so the conjunction lands on `false` at every target.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_extremal_variant_of(target, &bimodal_triple),
"{type_name}: T::is_unique_extremal_variant_of({target_label:?}, &bimodal_triple) != false — on the canonical non-flat triple T::ALL[0] sits at count 2 == max, T::ALL[1] at count 1 (strictly interior — off the union band), T::ALL[2..] at count 0 == min; T::is_extremal_variant_of reports `true` at T::ALL[0] AND at every T::ALL[i] for i >= 2 (union band), but T::has_unique_extremal_variant reports `false` at count_extremal_variants == T::CARDINALITY - 1 >= 2 != 1, so the conjunction lands on `false` at every target; a `true` bimodal-triple arm silently bifurcates the disjoint-band uniqueness catch on the direction-composition union unique-tie corner",
);
}
}
let full_unique_extremal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_extremal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_extremal_membership_count,
usize::from(T::has_unique_extremal_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_extremal_variant_of(*v, T::ALL)).count() == {full_unique_extremal_membership_count} drifted from usize::from(T::has_unique_extremal_variant(T::ALL)) == 0 — the per-target unique-extremum predicate's set-level filter-count MUST equal the set-level extremal-uniqueness bit cast to usize; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_extremal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
}
// (169) — `T::is_unique_middle_band_variant_of(target, items)` MUST
// agree with the conjunction of
// `T::is_middle_band_variant_of(target, items)` and
// `T::has_unique_middle_band_variant(items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false` at
// every target on the empty slice via
// [`T::is_middle_band_variant_of`]'s empty-slice guard, `false` at
// every target on every singleton at cardinality `>= 2` because
// max == 1 & min == 0 leaves the strict-interior band EMPTY,
// `false` at every target on the full-set slice at cardinality
// `>= 2` via the flat-histogram fixpoint that collapses the
// strict-interior band to empty, `false` at every target on the
// doubled-full-set slice at cardinality `>= 2` via the same flat-
// histogram fixpoint, `true` at EXACTLY `T::ALL[1]` and `false`
// at every other target on the bimodal-triple fixture at
// cardinality `>= 3` via the LOAD-BEARING strict-interior
// positive arm) AND on ONE composition-equality arm on every
// canonical fixture: the set-level filter-count reduction over
// [`T::ALL`] of THIS per-target predicate MUST equal
// `usize::from(T::has_unique_middle_band_variant(items))` on the
// full-set, doubled-full-set, AND bimodal-triple slices, pinning
// the at-most-one-target contract as a TYPED CONSEQUENCE of the
// set-level middle-band-uniqueness bit across BOTH the negative
// (flat-histogram) AND positive (bimodal-triple) arms.
//
// The canonical fixpoints + composition arms partition failure
// modes at the (per-target × slice-shape × combinator ×
// composition-equality) corner simultaneously: an override that
// folds onto `true` unconditionally fires on the empty-slice arm
// at every target AND on every singleton arm AND on both flat-
// histogram fixpoint arms (each pins the projection at `false`
// because [`T::is_middle_band_variant_of`] falsifies universally
// at max == min AND at singletons); an override that folds onto
// `false` unconditionally fires on the bimodal-triple arm at
// `T::ALL[1]` (the SOLE positive arm on the canonical fixture
// window at cardinality `>= 3`) AND on the composition-equality
// arm at the bimodal-triple slice (where the filter-count is
// `1` but the drifted override reduces the filter-count to `0`).
//
// Sibling posture to clause (168) one COMBINATOR axis over:
// clause (168) pins the (per-target × bool × direction-composition
// × union × unique-tie) corner — degenerate on every multi-variant
// fixture; this clause pins the (per-target × bool × direction-
// composition × complement × unique-tie) corner — NON-DEGENERATE
// on the bimodal-triple at cardinality `>= 3` where `T::ALL[1]`
// is the SOLE strict-interior witness. Sibling posture to clause
// (162) one ARITY axis over: clause (162) pins the set-level
// complement-uniqueness bit; this clause LIFTS the same
// uniqueness predicate to the per-target arity axis under
// conjunction with the per-target complement membership
// predicate. Sibling posture to clause (166) one RETURN-SHAPE
// axis over: clause (166) pins the set-level `Option<Self>`
// complement witness-if-unique projection; this clause pins the
// per-target `bool` complement membership-if-unique predicate.
// The default trait body threads the
// `is_middle_band_variant_of(target, items) &&
// has_unique_middle_band_variant(items)` conjunction verbatim and
// satisfies every fixpoint arm + composition arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// per-target unique-strict-interior surface every downstream
// consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_middle_band_variant_of(target, empty),
"{type_name}: T::is_unique_middle_band_variant_of({target_label:?}, &[]) != false — the per-target unique-strict-interior predicate MUST report `false` on the empty slice at every target because T::is_middle_band_variant_of(v, &[]) collapses to `false` via its empty-slice guard; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-strict-interior consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_middle_band_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_middle_band_variant_of({target_label:?}, [{target_label:?}]) != false — at cardinality >= 2 the singleton has max == 1 and min == 0, leaving the strict-interior band EMPTY; T::is_middle_band_variant_of reports `false` at every target, and the conjunction lands on `false`; a `true` matching-singleton arm silently bifurcates the empty-strict-interior-band fixpoint",
);
assert!(
!T::is_unique_middle_band_variant_of(target, T::ALL),
"{type_name}: T::is_unique_middle_band_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice; the flat histogram (max == min == 1) collapses the strict-interior band to empty, T::is_middle_band_variant_of reports `false` at every target, and the conjunction lands on `false`; a `true` full-set arm silently bifurcates the flat-histogram fixpoint",
);
assert!(
!T::is_unique_middle_band_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_middle_band_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions; the flat histogram (max == min == 2) collapses the strict-interior band to empty, T::is_middle_band_variant_of reports `false` at every target, and the conjunction lands on `false`; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
let full_unique_middle_band_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_middle_band_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_middle_band_membership_count,
usize::from(T::has_unique_middle_band_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_middle_band_variant_of(*v, T::ALL)).count() == {full_unique_middle_band_membership_count} drifted from usize::from(T::has_unique_middle_band_variant(T::ALL)) == 0 — the per-target unique-strict-interior predicate's set-level filter-count MUST equal the set-level middle-band-uniqueness bit cast to usize on the flat-histogram fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_middle_band_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture — LOAD-BEARING `true`-arm catch on
// the (per-target × bool × direction-composition × complement
// × unique-tie) corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]` at count
// `1` (STRICTLY INTERIOR — the SOLE middle-band witness),
// `T::ALL[2..]` at count `0 == min`;
// T::is_middle_band_variant_of reports `true` only at
// `T::ALL[1]`, T::has_unique_middle_band_variant reports
// `true`, and the conjunction lands on `true` at `T::ALL[1]`
// and `false` at every other target. Distinguishes the
// complement corner from the union sibling clause (168)
// which stays universally `false` on the same fixture.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for (target_slot, target) in T::ALL.iter().copied().enumerate() {
let target_label = <T as ClosedSet>::label(target);
let expected = target_slot == 1;
assert_eq!(
T::is_unique_middle_band_variant_of(target, &bimodal_triple),
expected,
"{type_name}: T::is_unique_middle_band_variant_of({target_label:?}, &bimodal_triple) drifted from expected == {expected} — on the canonical non-flat triple T::ALL[0] sits at count 2 == max, T::ALL[1] at count 1 (STRICTLY INTERIOR — the SOLE middle-band witness), T::ALL[2..] at count 0 == min; the SOLE positive arm sits at T::ALL[1] via T::is_middle_band_variant_of(T::ALL[1], triple) && T::has_unique_middle_band_variant(triple), every other target lands on `false`; a drifted value silently bifurcates the LOAD-BEARING strict-interior positive arm on the direction-composition complement unique-tie corner",
);
}
let bimodal_unique_middle_band_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_middle_band_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
bimodal_unique_middle_band_membership_count,
usize::from(T::has_unique_middle_band_variant(&bimodal_triple)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_middle_band_variant_of(*v, &bimodal_triple)).count() == {bimodal_unique_middle_band_membership_count} drifted from usize::from(T::has_unique_middle_band_variant(&bimodal_triple)) == 1 — the per-target unique-strict-interior predicate's set-level filter-count MUST equal the set-level middle-band-uniqueness bit cast to usize on the LOAD-BEARING bimodal-triple positive fixture; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_middle_band_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar on the sole positive canonical fixture",
);
}
}
// (170) — `T::is_unique_bimodal_variant_of(target, items)` MUST
// agree with the conjunction of
// `T::is_bimodal_variant_of(target, items)` and
// `T::has_unique_bimodal_variant(items)` on every (target, slice)
// pair AND MUST land on its canonical fixpoints (`false` at every
// target on the empty slice UNCONDITIONALLY via
// [`T::is_bimodal_variant_of`]'s empty-slice guard through
// [`T::is_modal_variant_of`], `false` at every target on every
// matching singleton `[v]` at cardinality `>= 2` because the sole
// target sits on the argmax band but not the argmin band —
// [`T::is_bimodal_variant_of`] falsifies through its argmin arm,
// `false` at every non-matching target on every non-matching
// singleton `[w]` with `T::index_of(v) != T::index_of(w)` at
// cardinality `>= 3` via the empty-intersection-band fixpoint
// (max != min so no variant sits on both bands simultaneously),
// `false` at every target on the full-set slice at cardinality
// `>= 2` via [`T::has_unique_bimodal_variant`]'s flat-histogram
// fixpoint (count_bimodal_variants == T::CARDINALITY >= 2 != 1),
// `false` at every target on the doubled-full-set slice at
// cardinality `>= 2` via the same flat-histogram fixpoint, `false`
// at every target on the bimodal-triple fixture at cardinality
// `>= 3` via the empty-intersection-band fixpoint —
// [`T::is_bimodal_variant_of`] falsifies at every target because
// max != min, count_bimodal_variants == 0, so the conjunction
// lands on `false` through the membership arm) AND on ONE
// composition-equality arm on the full-set fixpoint at cardinality
// `>= 2`: the set-level filter-count reduction over [`T::ALL`] of
// THIS per-target predicate MUST equal
// `T::has_unique_bimodal_variant(T::ALL) as usize == 0` at
// cardinality `>= 2`, pinning the at-most-one-target contract as a
// TYPED CONSEQUENCE of the set-level bimodal-uniqueness bit.
//
// The canonical fixpoints + one composition arm partition failure
// modes at the (per-target × slice-shape × composition-equality)
// corner simultaneously: an override that folds onto `true`
// unconditionally fires on the empty-slice arm at every target
// (returns `true` past [`T::is_bimodal_variant_of`]'s `false` at
// the empty slice) AND on the matching-singleton arm at every
// target at cardinality `>= 2` (returns `true` past the empty-
// intersection-band fixpoint — the singleton has max == 1 and
// min == 0 so the target sits on argmax but not argmin) AND on
// both flat-histogram fixpoint arms at cardinality `>= 2` (which
// pin the projection at `false` because
// [`T::has_unique_bimodal_variant`] falsifies at the flat
// histogram where count_bimodal_variants == T::CARDINALITY >= 2)
// AND on the bimodal-triple arm at cardinality `>= 3` (the empty-
// intersection-band fixpoint where max != min pins
// count_bimodal_variants at 0).
//
// No `false` drift-catch arm is available on a cardinality-`>= 2`
// multi-variant implementor — every canonical fixture pins the
// projection at `false` UNIVERSALLY, mirroring the degenerate-
// opener property clauses (164) + (166) document one ARITY axis
// over via [`T::has_unique_bimodal_variant`] +
// [`T::unique_bimodal_variant`]. THIS intersection corner is
// DOUBLY DEGENERATE at cardinality `>= 2` past the union sibling
// clause (168) which is SINGLY degenerate: the union band pulls
// at least two witnesses on every multi-variant slice pinning
// uniqueness at `false`; the intersection band is EMPTY on every
// non-flat multi-variant slice (via the membership arm) AND pulls
// the ENTIRE set on every non-empty flat-histogram multi-variant
// slice (via the uniqueness arm) — BOTH arms independently
// collapse the conjunction to `false`. The SOLE `true` arm sits
// at `T::CARDINALITY == 1` where the sole variant is trivially
// the sole flat-diagonal witness, out of reach of a multi-variant
// stub.
//
// Sibling posture to clause (169) one COMBINATOR axis over:
// clause (169) pins the (per-target × bool × direction-composition
// × complement × unique-tie) corner — NON-DEGENERATE on the
// bimodal-triple at cardinality `>= 3` where `T::ALL[1]` is the
// SOLE strict-interior witness; THIS clause pins the (per-target
// × bool × direction-composition × intersection × unique-tie)
// corner — DEGENERATE at cardinality `>= 2` on every canonical
// multi-variant fixture, CLOSING the (per-target × bool ×
// direction-composition × combinator × unique-tie) 3-corner row
// at its FINAL THIRD tile past the just-opened union arm clause
// (168) AND the just-closed complement arm clause (169). Sibling
// posture to clause (164) one ARITY axis over: clause (164) pins
// the set-level intersection-uniqueness bit; this clause LIFTS
// the same uniqueness predicate to the per-target arity axis
// under conjunction with the per-target intersection membership
// predicate. Sibling posture to clause (167) one RETURN-SHAPE
// axis over: clause (167) pins the set-level `Option<Self>`
// intersection witness-if-unique projection; this clause pins
// the per-target `bool` intersection membership-if-unique
// predicate. The default trait body threads the
// `is_bimodal_variant_of(target, items) &&
// has_unique_bimodal_variant(items)` conjunction verbatim and
// satisfies every fixpoint arm + the composition arm for free;
// the assertion catches a future implementor whose override
// drifts the projection loudly rather than silently bifurcating
// the per-target unique-flat-diagonal surface every downstream
// consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_bimodal_variant_of(target, empty),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, &[]) != false — the per-target unique-flat-diagonal predicate MUST report `false` on the empty slice at every target because T::is_bimodal_variant_of(v, &[]) collapses to `false` via its empty-slice guard through T::is_modal_variant_of; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-flat-diagonal consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_bimodal_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, [{target_label:?}]) != false — at cardinality >= 2 the singleton has max == 1 at {target_label:?} and min == 0 at every non-target; {target_label:?} sits on the argmax band but NOT on the argmin band (its count 1 != 0 == min), T::is_bimodal_variant_of falsifies at {target_label:?} via its argmin arm, and the conjunction lands on `false` through the membership arm; a `true` matching-singleton arm at cardinality >= 2 silently bifurcates the degenerate-opener property clauses (164) + (166) document",
);
assert!(
!T::is_unique_bimodal_variant_of(target, T::ALL),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice; T::is_bimodal_variant_of reports `true` at every target on the flat-histogram fixpoint (max == min == 1) so every variant sits on the intersection band, but T::has_unique_bimodal_variant(T::ALL) == false at count_bimodal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target via the uniqueness arm; a `true` full-set arm silently bifurcates the LOAD-BEARING asymmetry against T::is_bimodal_variant_of which reports `true` on the same slice",
);
assert!(
!T::is_unique_bimodal_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_bimodal_variant_of reports `true` at every target on the flat-histogram fixpoint (max == min == 2), but T::has_unique_bimodal_variant(doubled) == false at count_bimodal_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target via the uniqueness arm; a `true` doubled-full-set arm silently bifurcates the second flat-histogram fixpoint",
);
}
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
for other in T::ALL.iter().copied() {
if <T as ClosedSet>::index_of(other) == <T as ClosedSet>::index_of(target) {
continue;
}
let non_matching_singleton = [other];
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_unique_bimodal_variant_of(target, &non_matching_singleton),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, [{other_label:?}]) != false — the sole position hits {other_label:?} not {target_label:?}; the histogram has max == 1 at {other_label:?} and min == 0 at every non-{other_label:?}, so max != min collapses the intersection band to empty and T::is_bimodal_variant_of falsifies at every target; a `true` non-matching-singleton arm at cardinality >= 3 silently bifurcates the empty-intersection-band fixpoint on the direction-composition intersection unique-tie corner",
);
}
}
// Bimodal-triple fixture — LOAD-BEARING `false`-arm catch on
// the (per-target × bool × direction-composition ×
// intersection × unique-tie) corner. On `[T::ALL[0],
// T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at count `2 == max`,
// `T::ALL[1]` at count `1` (strictly interior), `T::ALL[2..]`
// at count `0 == min`; the intersection band is empty (max
// != min so no variant sits on both bands simultaneously),
// T::is_bimodal_variant_of reports `false` at every target,
// and the conjunction lands on `false` through the
// membership arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_bimodal_variant_of(target, &bimodal_triple),
"{type_name}: T::is_unique_bimodal_variant_of({target_label:?}, &bimodal_triple) != false — on the canonical non-flat triple T::ALL[0] sits at count 2 == max, T::ALL[1] at count 1 (strictly interior), T::ALL[2..] at count 0 == min; max != min collapses the intersection band to empty, T::is_bimodal_variant_of falsifies at every target, count_bimodal_variants == 0, and the conjunction lands on `false` at every target via the membership arm; a `true` bimodal-triple arm silently bifurcates the empty-intersection-band fixpoint on the direction-composition intersection unique-tie corner AND its LOAD-BEARING distinction from the complement sibling clause (169) which reports `true` at T::ALL[1] on the same fixture",
);
}
}
let full_unique_bimodal_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_bimodal_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_bimodal_membership_count,
usize::from(T::has_unique_bimodal_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_bimodal_variant_of(*v, T::ALL)).count() == {full_unique_bimodal_membership_count} drifted from usize::from(T::has_unique_bimodal_variant(T::ALL)) == 0 — the per-target unique-flat-diagonal predicate's set-level filter-count MUST equal the set-level bimodal-uniqueness bit cast to usize; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_bimodal_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
}
// (171) — `T::has_unique_repeating_variant(items)` MUST agree with
// the count-composition body `T::count_repeating_variants(items) == 1`
// on every slice AND MUST land on its canonical fixpoints. The corner
// OPENS the (set-level × bool × equivalence-partition × multiplicity-
// band × unique-tie) row on the equivalence-partition surface at its
// (mult `>= 2`) band, peer to clauses (162) + (163) + (164) one
// SURFACE axis over which pin the same unique-tie sharpening on the
// modal-aggregation surface (direction-composition × combinator).
//
// Empty-slice arm: `T::count_repeating_variants(&[])` collapses to
// `0` via the empty-slice guard on
// [`T::is_repeated_occurrence_of`], so the equality against `1`
// fails and the predicate lands on `false`.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant pins
// every variant at exactly one position of the full-set slice; every
// per-target multiplicity is `1`, the per-target `>= 2` test fails at
// every target, `T::count_repeating_variants(T::ALL)` reports `0`,
// and the equality against `1` fails.
//
// Doubled-full-set arm at cardinality `>= 2`: the doubled full set
// hits every variant at exactly two positions, every per-target
// multiplicity is `2 >= 2`, every variant contributes to the count,
// `T::count_repeating_variants(doubled)` reports `T::CARDINALITY`,
// and `T::CARDINALITY >= 2 != 1`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING `true`-arm
// catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2 >= 2` (the SOLE strict-repeat witness), `T::ALL[1]` at
// count `1`, `T::ALL[2..]` at count `0`;
// `T::count_repeating_variants` reports `1` and the equality against
// `1` HOLDS. This positive fixpoint DISCRIMINATES the equivalence-
// partition (mult `>= 2`) uniqueness corner from the modal-
// aggregation direction-composition union + intersection unique-tie
// corners (clauses (163) + (164)) which BOTH fold to `false` on the
// same fixture via the `count >= 2` inclusion-exclusion collapse —
// the substrate SURFACE axis discriminates the two uniqueness bands
// on this canonical fixture.
//
// The default trait body threads the scalar equality against `1`
// verbatim and satisfies every fixpoint arm for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level strict-
// repeat uniqueness surface. An override that folds onto `true`
// unconditionally bifurcates on the empty-slice + full-set arms
// (both correct `false`); an override that folds onto `false`
// unconditionally bifurcates on the bimodal-triple arm at
// cardinality `>= 3` (correct `true`).
let empty_repeating_uniqueness = T::has_unique_repeating_variant(empty);
let expected_empty_repeating_uniqueness = T::count_repeating_variants(empty) == 1;
assert_eq!(
empty_repeating_uniqueness, expected_empty_repeating_uniqueness,
"{type_name}: T::has_unique_repeating_variant(&[]) drifted from (T::count_repeating_variants(&[]) == 1) — the count-composition identity MUST hold on the empty slice; the empty-slice guard of `count_repeating_variants` collapses the count to `0`, so the equality against `1` fails and the predicate lands on `false`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream strict-repeat uniqueness consumer routes through",
);
let full_repeating_uniqueness = T::has_unique_repeating_variant(T::ALL);
let expected_full_repeating_uniqueness = T::count_repeating_variants(T::ALL) == 1;
assert_eq!(
full_repeating_uniqueness, expected_full_repeating_uniqueness,
"{type_name}: T::has_unique_repeating_variant(T::ALL) drifted from (T::count_repeating_variants(T::ALL) == 1) — the count-composition identity MUST hold on the full-set slice; clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, every per-target multiplicity is `1`, the per-target `>= 2` test fails at every target, `count_repeating_variants` reports `0`, and the equality against `1` fails",
);
let doubled_repeating_uniqueness = T::has_unique_repeating_variant(&doubled_full_set);
let expected_doubled_repeating_uniqueness = T::count_repeating_variants(&doubled_full_set) == 1;
assert_eq!(
doubled_repeating_uniqueness, expected_doubled_repeating_uniqueness,
"{type_name}: T::has_unique_repeating_variant(&doubled_full_set) drifted from (T::count_repeating_variants(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; at `T::CARDINALITY >= 2` the doubled full set hits every variant at exactly two positions, `count_repeating_variants` reports `T::CARDINALITY`, and `T::CARDINALITY != 1`; at `T::CARDINALITY == 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still hits the sole variant at count 2, `count_repeating_variants` reports `1`, and the equality holds",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `true`-arm catch on the
// (equivalence-partition × mult `>= 2` × unique-tie) corner.
// On `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2` (the SOLE strict-repeat witness), `T::ALL[1]` at
// count `1`, `T::ALL[2..]` at count `0`;
// `count_repeating_variants` reports `1` and the equality
// against `1` HOLDS. DISCRIMINATES this equivalence-partition
// uniqueness corner from clauses (163) + (164) which BOTH fold
// to `false` on the same fixture — the equivalence-partition
// and modal-aggregation surfaces split on the canonical bimodal
// triple.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_repeating_uniqueness = T::has_unique_repeating_variant(&bimodal_triple);
let expected_bimodal_triple_repeating_uniqueness =
T::count_repeating_variants(&bimodal_triple) == 1;
assert_eq!(
bimodal_triple_repeating_uniqueness, expected_bimodal_triple_repeating_uniqueness,
"{type_name}: T::has_unique_repeating_variant(&bimodal_triple) drifted from (T::count_repeating_variants(&bimodal_triple) == 1) — the count-composition identity MUST hold on the bimodal-triple fixture where the LOAD-BEARING `true`-arm fires (T::count_repeating_variants reports `1`, T::ALL[0] is the SOLE strict-repeat witness at count 2)",
);
assert!(
bimodal_triple_repeating_uniqueness,
"{type_name}: T::has_unique_repeating_variant(&bimodal_triple) drifted from `true` at cardinality >= 3 — on the canonical non-flat triple T::ALL[0] sits at count 2 (the SOLE strict-repeat witness), T::ALL[1] at count 1, T::ALL[2..] at count 0, so `count_repeating_variants` reports `1` and the equality against `1` HOLDS; a `false` bimodal-triple value silently bifurcates the LOAD-BEARING `true`-arm catch DISCRIMINATING this equivalence-partition uniqueness corner from the modal-aggregation direction-composition union + intersection unique-tie peers which BOTH fold to `false` on the same fixture",
);
}
// Set-level existence-implication cross-check: for every canonical
// slice, `T::has_unique_repeating_variant(s) ==>
// T::is_repeating_any(s)` — a unique strict-repeat witness entails
// the existence of a strict-repeat witness. Sweeps the four
// canonical fixtures at once (empty, full-set, doubled-full-set,
// bimodal-triple-if-available).
assert!(
!T::has_unique_repeating_variant(empty) || T::is_repeating_any(empty),
"{type_name}: T::has_unique_repeating_variant(&[]) drifted from the existence-implication contract on the empty slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_repeating_variant(T::ALL) || T::is_repeating_any(T::ALL),
"{type_name}: T::has_unique_repeating_variant(T::ALL) drifted from the existence-implication contract on the full-set slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_repeating_variant(&doubled_full_set)
|| T::is_repeating_any(&doubled_full_set),
"{type_name}: T::has_unique_repeating_variant(&doubled_full_set) drifted from the existence-implication contract on the doubled-full-set slice — uniqueness `true` MUST imply existence `true`",
);
// (172) — `T::unique_repeating_variant(items)` MUST agree with the
// guarded-first-witness body
// `if T::has_unique_repeating_variant(items) { T::ALL.iter().copied().find(|&v| T::is_repeated_occurrence_of(v, items)) } else { None }`
// on every slice AND MUST land on its canonical fixpoints. The
// corner OPENS the (set-level × `Option<Self>` × equivalence-
// partition × multiplicity-band `>= 2` × unique-tie) column on the
// EQUIVALENCE-PARTITION surface at its (mult `>= 2`) band, peer to
// clauses (165) + (166) + (167) one SURFACE axis over which pin the
// same `Option<Self>` uniqueness-guarded witness on the modal-
// aggregation surface (direction-composition × combinator), AND
// peer to clause (171) one RETURN-SHAPE axis over which pins the
// set-level strict-repeat uniqueness bit that gates THIS projection.
//
// Empty-slice arm: `T::has_unique_repeating_variant(&[])` collapses
// to `false` via `count_repeating_variants(&[]) == 0 != 1`, the
// guard short-circuits, and the projection reports `None` before
// the per-target strict-repeat sweep runs.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant pins
// every variant at exactly one position of the full-set slice,
// `count_repeating_variants(T::ALL)` reports `0`,
// `has_unique_repeating_variant(T::ALL)` returns `false`, and the
// guard collapses the projection to `None`.
//
// Doubled-full-set arm at cardinality `>= 2`: the doubled full set
// hits every variant at exactly two positions, EVERY per-target
// multiplicity is `2 >= 2`, `count_repeating_variants` reports
// `T::CARDINALITY >= 2`, `has_unique_repeating_variant` returns
// `false` (multiple witnesses, no unique one), and the guard
// collapses the projection to `None`. At cardinality `== 1` the
// doubled slice `[T::ALL[0], T::ALL[0]]` collapses the strict-
// repeat count to `1`, `has_unique_repeating_variant` returns
// `true`, and the guarded find lands on `Some(T::ALL[0])`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING `Some(_)`-
// arm catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]`
// sits at count `2 >= 2` (the SOLE strict-repeat witness),
// `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
// `count_repeating_variants` reports `1`,
// `has_unique_repeating_variant` returns `true`, and the
// declaration-order find sweep hits `T::ALL[0]` immediately.
// LOAD-BEARING DISCRIMINATOR from clauses (165) + (167) on the same
// fixture: both fold to `None` (the union band pulls two disjoint
// extremes; the intersection band collapses to empty on the non-
// flat triple) — the surface axis SPLITS the equivalence-partition
// strict-repeat witness from the modal-aggregation union +
// intersection witnesses. LOAD-BEARING DISCRIMINATOR from clause
// (166) on the same fixture: the complement arm's guarded lift
// lands on `Some(T::ALL[1])` (strict-interior singleton); THIS
// equivalence-partition arm's guarded find lands on
// `Some(T::ALL[0])` (strict-repeat singleton) — the two POSITIVE
// `Some(_)` corners report DIFFERENT witnesses (`T::ALL[1]` vs
// `T::ALL[0]`) on the same slice, pinning the two surfaces as
// orthogonal uniqueness axes with disjoint witness projections.
//
// The default trait body threads the boolean-guarded find sweep
// verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// strict-repeat witness-if-unique surface. An override that folds
// onto `Some(T::first())` unconditionally bifurcates on the empty-
// slice + full-set + doubled-full-set fixpoint arms at cardinality
// `>= 2` at `Some(_) != None`; an override that folds onto `None`
// unconditionally bifurcates on the bimodal-triple arm at
// cardinality `>= 3` at `None != Some(T::ALL[0])`.
let empty_unique_repeating = T::unique_repeating_variant(empty);
let expected_empty_unique_repeating = if T::has_unique_repeating_variant(empty) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_repeated_occurrence_of(v, empty))
} else {
None
};
assert_eq!(
empty_unique_repeating, expected_empty_unique_repeating,
"{type_name}: T::unique_repeating_variant(&[]) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the empty slice; the empty-slice guard of `has_unique_repeating_variant` collapses to `false` via `count_repeating_variants(&[]) == 0 != 1`, the guard short-circuits to `None`, and the per-target strict-repeat sweep is not consulted; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream equivalence-partition strict-repeat witness-if-unique consumer routes through",
);
let full_unique_repeating = T::unique_repeating_variant(T::ALL);
let expected_full_unique_repeating = if T::has_unique_repeating_variant(T::ALL) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_repeated_occurrence_of(v, T::ALL))
} else {
None
};
assert_eq!(
full_unique_repeating, expected_full_unique_repeating,
"{type_name}: T::unique_repeating_variant(T::ALL) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the full-set slice; clause (3)'s pairwise-distinctness invariant forces every variant to occur at EXACTLY ONE position, `count_repeating_variants(T::ALL)` reports `0`, `has_unique_repeating_variant(T::ALL)` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` full-set value silently bifurcates the full-set fixpoint contract",
);
let doubled_unique_repeating = T::unique_repeating_variant(&doubled_full_set);
let expected_doubled_unique_repeating = if T::has_unique_repeating_variant(&doubled_full_set) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_repeated_occurrence_of(v, &doubled_full_set))
} else {
None
};
assert_eq!(
doubled_unique_repeating, expected_doubled_unique_repeating,
"{type_name}: T::unique_repeating_variant(&doubled_full_set) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the doubled-full-set slice; at `T::CARDINALITY >= 2` the doubled full set hits every variant at exactly two positions, `count_repeating_variants` reports `T::CARDINALITY`, `has_unique_repeating_variant` returns `false`, and the guard collapses to `None`; at `T::CARDINALITY == 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses the strict-repeat count to `1`, `has_unique_repeating_variant` returns `true`, and the guarded find lands on `Some(T::ALL[0])`",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let singleton_unique_repeating = T::unique_repeating_variant(&matching_singleton);
assert_eq!(
singleton_unique_repeating, None,
"{type_name}: T::unique_repeating_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1` (not strictly repeating), every non-target variant sits at count `0` (also not strictly repeating), `count_repeating_variants` reports `0`, `has_unique_repeating_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (`Option<Self>` × equivalence-partition × mult `>= 2` × unique-tie) corner",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[0])`-arm
// catch on the (`Option<Self>` × equivalence-partition × mult
// `>= 2` × unique-tie) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2` (the SOLE strict-repeat witness), `T::ALL[1]` at
// count `1`, `T::ALL[2..]` at count `0`;
// `count_repeating_variants` reports `1`,
// `has_unique_repeating_variant` returns `true`, the guard
// fires, and the declaration-order sweep of `T::ALL` through
// `T::is_repeated_occurrence_of` hits `T::ALL[0]` immediately.
// LOAD-BEARING DISCRIMINATOR from clauses (165) + (167) which
// both fold to `None` on the same fixture; LOAD-BEARING
// DISCRIMINATOR from clause (166) which lands on
// `Some(T::ALL[1])` — the surface axis SPLITS the equivalence-
// partition (mult `>= 2`) unique-witness column from the modal-
// aggregation direction-composition unique-witness columns
// on the canonical bimodal triple at cardinality `>= 3`.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_repeating = T::unique_repeating_variant(&bimodal_triple);
let expected_bimodal_triple_unique_repeating =
if T::has_unique_repeating_variant(&bimodal_triple) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_repeated_occurrence_of(v, &bimodal_triple))
} else {
None
};
assert_eq!(
bimodal_triple_unique_repeating, expected_bimodal_triple_unique_repeating,
"{type_name}: T::unique_repeating_variant(&bimodal_triple) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the bimodal-triple fixture where the LOAD-BEARING `Some(T::ALL[0])`-arm fires",
);
assert_eq!(
bimodal_triple_unique_repeating,
Some(T::ALL[0]),
"{type_name}: T::unique_repeating_variant(&bimodal_triple) drifted from `Some(T::ALL[0])` at cardinality >= 3 — on the canonical non-flat triple T::ALL[0] sits at count 2 (the SOLE strict-repeat witness), T::ALL[1] at count 1, T::ALL[2..] at count 0, `count_repeating_variants` reports `1`, `has_unique_repeating_variant` returns `true`, and the declaration-order find sweep of T::ALL through T::is_repeated_occurrence_of hits T::ALL[0] immediately; a divergent value silently bifurcates the LOAD-BEARING `Some(_)`-arm catch DISCRIMINATING this equivalence-partition strict-repeat witness corner from the modal-aggregation direction-composition union + intersection witness peers (clauses (165) + (167)) which BOTH fold to `None` on the same fixture, AND from the complement peer (clause (166)) which lands on `Some(T::ALL[1])` — the two POSITIVE `Some(_)` corners report DIFFERENT witnesses on the same slice",
);
}
// Set-level is-some coincidence cross-check: for every canonical
// slice, `T::unique_repeating_variant(s).is_some() ==
// T::has_unique_repeating_variant(s)` — the `Option<Self>` return's
// `is_some` bit COINCIDES with the set-level strict-repeat
// uniqueness bit. Sweeps the four canonical fixtures at once
// (empty, full-set, doubled-full-set, bimodal-triple-if-available).
assert_eq!(
T::unique_repeating_variant(empty).is_some(),
T::has_unique_repeating_variant(empty),
"{type_name}: T::unique_repeating_variant(&[]).is_some() drifted from T::has_unique_repeating_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_variant(T::ALL).is_some(),
T::has_unique_repeating_variant(T::ALL),
"{type_name}: T::unique_repeating_variant(T::ALL).is_some() drifted from T::has_unique_repeating_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_repeating_variant(&doubled_full_set).is_some(),
T::has_unique_repeating_variant(&doubled_full_set),
"{type_name}: T::unique_repeating_variant(&doubled_full_set).is_some() drifted from T::has_unique_repeating_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
// (173) — `T::is_unique_repeating_variant_of(target, items)` MUST
// agree with the conjunction of
// `T::is_repeated_occurrence_of(target, items)` and
// `T::has_unique_repeating_variant(items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false`
// at every target on the empty slice via
// [`T::is_repeated_occurrence_of`]'s empty-slice guard, `false`
// at every target on every singleton at cardinality `>= 2`
// because every variant sits at count `0` or `1` (not strictly
// repeating), `false` at every target on the full-set slice at
// cardinality `>= 2` via clause (3)'s pairwise-distinctness
// invariant that pins every count at `1`, `false` at every target
// on the doubled-full-set slice at cardinality `>= 2` via the
// `has_unique_repeating_variant` uniqueness arm that falsifies
// when EVERY variant is a strict-repeat witness, `true` at
// EXACTLY `T::ALL[0]` and `false` at every other target on the
// bimodal-triple fixture at cardinality `>= 3` via the LOAD-
// BEARING strict-repeat positive arm) AND on ONE composition-
// equality arm on every canonical fixture: the set-level filter-
// count reduction over [`T::ALL`] of THIS per-target predicate
// MUST equal `usize::from(T::has_unique_repeating_variant(items))`
// on the full-set, doubled-full-set, AND bimodal-triple slices,
// pinning the at-most-one-target contract as a TYPED CONSEQUENCE
// of the set-level strict-repeat uniqueness bit across BOTH the
// negative (flat-histogram) AND positive (bimodal-triple) arms.
//
// The canonical fixpoints + composition arms partition failure
// modes at the (per-target × slice-shape × combinator ×
// composition-equality) corner simultaneously: an override that
// folds onto `true` unconditionally fires on the empty-slice arm
// at every target AND on every singleton arm AND on both flat-
// histogram fixpoint arms (each pins the projection at `false`
// because [`T::is_repeated_occurrence_of`] falsifies at count
// `< 2` OR [`T::has_unique_repeating_variant`] falsifies on the
// doubled-full set); an override that folds onto `false`
// unconditionally fires on the bimodal-triple arm at `T::ALL[0]`
// (the SOLE positive arm on the canonical fixture window at
// cardinality `>= 3`) AND on the composition-equality arm at
// the bimodal-triple slice (where the filter-count is `1` but
// the drifted override reduces the filter-count to `0`).
//
// Sibling posture to clauses (168) + (169) + (170) one SURFACE
// axis over: those three pin the per-target × bool × unique-tie
// corner on the MODAL-AGGREGATION surface (direction-composition
// × combinator); THIS clause pins the same per-target × bool ×
// unique-tie corner on the EQUIVALENCE-PARTITION surface
// (multiplicity-band). Sibling posture to clause (171) one
// ARITY axis over: clause (171) pins the set-level strict-repeat
// uniqueness bit; this clause LIFTS the same uniqueness
// predicate to the per-target arity axis under conjunction with
// the per-target strict-repeat membership predicate. Sibling
// posture to clause (172) one RETURN-SHAPE axis over: clause
// (172) pins the set-level `Option<Self>` strict-repeat witness-
// if-unique projection; this clause pins the per-target `bool`
// strict-repeat membership-if-unique predicate. LOAD-BEARING
// ASYMMETRY against clause (169) which pins its bimodal-triple
// positive arm at `T::ALL[1]` (strict-interior singleton); THIS
// clause pins its bimodal-triple positive arm at `T::ALL[0]`
// (strict-repeat singleton) — the two SURFACES pin uniqueness
// at DIFFERENT witnesses on the same slice, witnessing their
// orthogonality.
//
// The default trait body threads the
// `is_repeated_occurrence_of(target, items) &&
// has_unique_repeating_variant(items)` conjunction verbatim and
// satisfies every fixpoint arm + composition arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// per-target unique-strict-repeat surface every downstream
// consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_repeating_variant_of(target, empty),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, &[]) != false — the per-target unique-strict-repeat predicate MUST report `false` on the empty slice at every target because T::is_repeated_occurrence_of(v, &[]) collapses to `false` via its empty-slice guard (count `0 < 2`); a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-strict-repeat consumer routes through",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_repeating_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, [{target_label:?}]) != false — at cardinality >= 2 the singleton hits {target_label:?} at count `1` (not strictly repeating), every non-target at count `0`; T::is_repeated_occurrence_of falsifies at every target, and the conjunction lands on `false`; a `true` matching-singleton arm silently bifurcates the count-`1`-not-repeating fixpoint",
);
assert!(
!T::is_unique_repeating_variant_of(target, T::ALL),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice; every per-target count is `1` (not strictly repeating), T::is_repeated_occurrence_of falsifies at every target, and the conjunction lands on `false`; a `true` full-set arm silently bifurcates the pairwise-distinct fixpoint",
);
assert!(
!T::is_unique_repeating_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_repeated_occurrence_of reports `true` at every target, but T::has_unique_repeating_variant returns `false` at count_repeating_variants == T::CARDINALITY >= 2 != 1, so the conjunction lands on `false` at every target via the uniqueness arm; a `true` doubled-full-set arm silently bifurcates the every-variant-repeats non-uniqueness fixpoint",
);
}
let full_unique_repeating_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_repeating_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_repeating_membership_count,
usize::from(T::has_unique_repeating_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, T::ALL)).count() == {full_unique_repeating_membership_count} drifted from usize::from(T::has_unique_repeating_variant(T::ALL)) == 0 — the per-target unique-strict-repeat predicate's set-level filter-count MUST equal the set-level strict-repeat uniqueness bit cast to usize on the flat-histogram fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
let doubled_unique_repeating_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_repeating_variant_of(v, &doubled_full_set))
.count();
assert_eq!(
doubled_unique_repeating_membership_count,
usize::from(T::has_unique_repeating_variant(&doubled_full_set)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, &doubled_full_set)).count() == {doubled_unique_repeating_membership_count} drifted from usize::from(T::has_unique_repeating_variant(&doubled_full_set)) == 0 — the per-target unique-strict-repeat predicate's set-level filter-count MUST equal the set-level strict-repeat uniqueness bit cast to usize on the doubled-full-set flat-histogram fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture — LOAD-BEARING `true`-arm catch on
// the (per-target × bool × equivalence-partition × mult
// `>= 2` × unique-tie) corner. On `[T::ALL[0], T::ALL[0],
// T::ALL[1]]` `T::ALL[0]` sits at count `2 >= 2` (the SOLE
// strict-repeat witness), `T::ALL[1]` at count `1`,
// `T::ALL[2..]` at count `0`; T::is_repeated_occurrence_of
// reports `true` only at `T::ALL[0]`,
// T::has_unique_repeating_variant reports `true`, and the
// conjunction lands on `true` at `T::ALL[0]` and `false` at
// every other target. LOAD-BEARING DISCRIMINATOR from
// clause (169) which pins its bimodal-triple positive arm
// at `T::ALL[1]` (strict-interior singleton) on the same
// fixture — the two SURFACES report `true` at DIFFERENT
// witnesses.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for (target_slot, target) in T::ALL.iter().copied().enumerate() {
let target_label = <T as ClosedSet>::label(target);
let expected = target_slot == 0;
assert_eq!(
T::is_unique_repeating_variant_of(target, &bimodal_triple),
expected,
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, &bimodal_triple) drifted from expected == {expected} — on the canonical non-flat triple T::ALL[0] sits at count 2 >= 2 (the SOLE strict-repeat witness), T::ALL[1] at count 1, T::ALL[2..] at count 0; the SOLE positive arm sits at T::ALL[0] via T::is_repeated_occurrence_of(T::ALL[0], triple) && T::has_unique_repeating_variant(triple), every other target lands on `false`; a drifted value silently bifurcates the LOAD-BEARING strict-repeat positive arm on the equivalence-partition unique-tie corner AND its LOAD-BEARING distinction from the complement peer clause (169) which pins its positive arm at T::ALL[1] (strict-interior singleton) on the same fixture",
);
}
let bimodal_unique_repeating_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_repeating_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
bimodal_unique_repeating_membership_count,
usize::from(T::has_unique_repeating_variant(&bimodal_triple)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, &bimodal_triple)).count() == {bimodal_unique_repeating_membership_count} drifted from usize::from(T::has_unique_repeating_variant(&bimodal_triple)) == 1 — the per-target unique-strict-repeat predicate's set-level filter-count MUST equal the set-level strict-repeat uniqueness bit cast to usize on the LOAD-BEARING bimodal-triple positive fixture; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_repeating_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar on the sole positive canonical fixture",
);
}
}
// Set-level option-equality coincidence cross-check: for every
// canonical slice and every target, T::is_unique_repeating_variant_of(v, s)
// == (T::unique_repeating_variant(s) == Some(v)) — the per-target
// bool predicate coincides with the equality test between the
// set-level `Option<Self>` witness projection and `Some(v)`.
// Independent cross-check on the return-shape axis distinct from
// the composition-conjunction body.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert_eq!(
T::is_unique_repeating_variant_of(target, empty),
T::unique_repeating_variant(empty) == Some(target),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, &[]) drifted from (T::unique_repeating_variant(&[]) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::is_unique_repeating_variant_of(target, T::ALL),
T::unique_repeating_variant(T::ALL) == Some(target),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, T::ALL) drifted from (T::unique_repeating_variant(T::ALL) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::is_unique_repeating_variant_of(target, &doubled_full_set),
T::unique_repeating_variant(&doubled_full_set) == Some(target),
"{type_name}: T::is_unique_repeating_variant_of({target_label:?}, &doubled_full_set) drifted from (T::unique_repeating_variant(&doubled_full_set) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the doubled-full-set slice",
);
}
// (174) — `T::has_unique_missing_variant(items)` MUST agree with
// the count-composition body `T::count_missing(items) == 1` on
// every slice AND MUST land on its canonical fixpoints. The
// corner CLOSES the miss-band arm of the (set-level × bool ×
// equivalence-partition × multiplicity-band × unique-tie) row on
// the equivalence-partition surface at its (mult `== 0`) band,
// peer to clause (171) which pins the same unique-tie sharpening
// on the strict-repeat (mult `>= 2`) band one MULTIPLICITY-BAND
// axis over — the two together bracket the mult-band trichotomy's
// unique-tie sharpening at its TWO EXTREMAL bands.
//
// Empty-slice arm: `T::count_missing(&[])` collapses to
// [`T::CARDINALITY`] via the
// `CARDINALITY - count_distinct(&[]) == CARDINALITY - 0`
// identity, so the equality against `1` holds EXACTLY when
// `T::CARDINALITY == 1` (the degenerate cardinality-1 arm) and
// falsifies at `T::CARDINALITY >= 2`.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant
// pins `T::count_distinct(T::ALL) == T::CARDINALITY`,
// `T::count_missing(T::ALL)` folds to `0`, and `0 != 1`.
//
// Doubled-full-set arm: appending positions to a covering slice
// cannot introduce a missing variant;
// `T::count_missing(&doubled_full_set)` reports `0`, and
// `0 != 1`.
//
// All-but-first arm at cardinality `>= 2` (LOAD-BEARING
// `true`-arm catch): on the canonical fixture
// `T::ALL[1..].to_vec()`, `T::ALL[0]` is the SOLE variant absent
// from `items`; every other variant of [`T::ALL`] hits at least
// one position, `T::count_missing` reports `1` and the equality
// against `1` HOLDS. LOAD-BEARING positive fixture bracketing
// the miss-band unique-tie sharpening's non-triviality.
//
// The default trait body threads the scalar equality against
// `1` verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// set-level miss-uniqueness surface. An override that folds
// onto `true` unconditionally bifurcates on the full-set +
// doubled-full-set arms (both correct `false`); an override
// that folds onto `false` unconditionally bifurcates on the
// all-but-first arm at cardinality `>= 2` (correct `true`).
let empty_missing_uniqueness = T::has_unique_missing_variant(empty);
let expected_empty_missing_uniqueness = T::count_missing(empty) == 1;
assert_eq!(
empty_missing_uniqueness, expected_empty_missing_uniqueness,
"{type_name}: T::has_unique_missing_variant(&[]) drifted from (T::count_missing(&[]) == 1) — the count-composition identity MUST hold on the empty slice; the empty-slice guard of `count_missing` collapses to `T::CARDINALITY`, so the equality against `1` holds exactly at `T::CARDINALITY == 1` and falsifies at `T::CARDINALITY >= 2`",
);
let full_missing_uniqueness = T::has_unique_missing_variant(T::ALL);
let expected_full_missing_uniqueness = T::count_missing(T::ALL) == 1;
assert_eq!(
full_missing_uniqueness, expected_full_missing_uniqueness,
"{type_name}: T::has_unique_missing_variant(T::ALL) drifted from (T::count_missing(T::ALL) == 1) — the count-composition identity MUST hold on the full-set slice; clause (3)'s pairwise-distinctness invariant pins `count_distinct(T::ALL) == T::CARDINALITY`, `count_missing(T::ALL)` folds to `0`, and `0 != 1`",
);
let doubled_missing_uniqueness = T::has_unique_missing_variant(&doubled_full_set);
let expected_doubled_missing_uniqueness = T::count_missing(&doubled_full_set) == 1;
assert_eq!(
doubled_missing_uniqueness, expected_doubled_missing_uniqueness,
"{type_name}: T::has_unique_missing_variant(&doubled_full_set) drifted from (T::count_missing(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; the doubled full set hits every variant, `count_missing` reports `0`, and `0 != 1`",
);
if T::CARDINALITY >= 2 {
// All-but-first fixture: LOAD-BEARING `true`-arm catch on
// the (equivalence-partition × mult `== 0` × unique-tie)
// corner. On `T::ALL[1..].to_vec()` `T::ALL[0]` is the
// SOLE absent variant, every other variant hits at least
// one position, `count_missing` reports `1` and the
// equality against `1` HOLDS. LOAD-BEARING positive
// fixture bracketing the miss-band unique-tie sharpening's
// non-triviality; mirror of the bimodal-triple positive
// fixture at clause (171) one MULTIPLICITY-BAND axis over
// (the strict-repeat arm's positive fixture at
// `T::ALL[0]` witnesses the (mult `>= 2`) unique-tie at
// count 2 on `[T::ALL[0], T::ALL[0], T::ALL[1]]`; THIS
// arm's positive fixture at `T::ALL[0]` witnesses the
// (mult `== 0`) unique-tie at count 0 on `T::ALL[1..]`).
let all_but_first: Vec<T> = T::ALL.iter().copied().skip(1).collect();
let all_but_first_missing_uniqueness = T::has_unique_missing_variant(&all_but_first);
let expected_all_but_first_missing_uniqueness = T::count_missing(&all_but_first) == 1;
assert_eq!(
all_but_first_missing_uniqueness, expected_all_but_first_missing_uniqueness,
"{type_name}: T::has_unique_missing_variant(T::ALL[1..]) drifted from (T::count_missing(T::ALL[1..]) == 1) — the count-composition identity MUST hold on the all-but-first fixture where the LOAD-BEARING `true`-arm fires (T::count_missing reports `1`, T::ALL[0] is the SOLE absent variant)",
);
assert!(
all_but_first_missing_uniqueness,
"{type_name}: T::has_unique_missing_variant(T::ALL[1..]) drifted from `true` at cardinality >= 2 — on the all-but-first fixture T::ALL[0] is the SOLE absent variant, every other variant hits at least one position, `count_missing` reports `1` and the equality against `1` HOLDS; a `false` all-but-first value silently bifurcates the LOAD-BEARING `true`-arm catch bracketing the miss-band unique-tie sharpening's non-triviality",
);
}
// Set-level existence-implication cross-check: for every
// canonical slice, `T::has_unique_missing_variant(s) ==>
// T::is_missing_any(s)` — a unique missing witness entails the
// existence of a missing witness. Sweeps the three multi-
// implementor canonical fixtures at once (empty, full-set,
// doubled-full-set); the all-but-first fixture is folded into
// its own `assert!(all_but_first_missing_uniqueness, …)` arm
// above where the LOAD-BEARING `true` value is pinned
// structurally.
assert!(
!T::has_unique_missing_variant(empty) || T::is_missing_any(empty),
"{type_name}: T::has_unique_missing_variant(&[]) drifted from the existence-implication contract on the empty slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_missing_variant(T::ALL) || T::is_missing_any(T::ALL),
"{type_name}: T::has_unique_missing_variant(T::ALL) drifted from the existence-implication contract on the full-set slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_missing_variant(&doubled_full_set)
|| T::is_missing_any(&doubled_full_set),
"{type_name}: T::has_unique_missing_variant(&doubled_full_set) drifted from the existence-implication contract on the doubled-full-set slice — uniqueness `true` MUST imply existence `true`",
);
// (175) — `T::has_unique_unique_variant(items)` MUST agree with
// the count-composition body
// `T::count_unique_variants(items) == 1` on every slice AND MUST
// land on its canonical fixpoints. The corner EXHAUSTIVELY
// CLOSES the middle-band arm of the (set-level × bool ×
// equivalence-partition × multiplicity-band × unique-tie) row
// on the equivalence-partition surface at its (mult `== 1`)
// band — the row's FINAL THIRD tile past clause (171)
// [`T::has_unique_repeating_variant`] (mult `>= 2`) and
// clause (174) [`T::has_unique_missing_variant`] (mult `== 0`)
// one MULTIPLICITY-BAND axis over. The three together bracket
// the mult-band trichotomy's unique-tie sharpening across ALL
// THREE bands, mirroring the count-aggregate trichotomy
// ([`T::count_missing`], [`T::count_unique_variants`],
// [`T::count_repeating_variants`]) one RETURN-SHAPE axis over
// AND the existential-lift trichotomy ([`T::is_missing_any`],
// [`T::is_unique_any`], [`T::is_repeating_any`]) one UNIQUE-TIE-
// SHARPENING axis over.
//
// Empty-slice arm: `T::count_unique_variants(&[])` collapses
// to `0` via the empty-slice guard on
// [`T::is_unique_occurrence_of`], so the equality against `1`
// fails UNCONDITIONALLY and the predicate lands on `false`.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant
// pins every variant at exactly one position of the full-set
// slice, every per-target multiplicity is `1`, every variant
// contributes to the count, `T::count_unique_variants(T::ALL)`
// reports `T::CARDINALITY`, and the equality against `1` holds
// EXACTLY when `T::CARDINALITY == 1` (the degenerate
// cardinality-1 arm) and falsifies at `T::CARDINALITY >= 2`.
//
// Doubled-full-set arm: the doubled full set hits every
// variant at exactly two positions, every per-target
// multiplicity is `2` (not `1`), the per-target `== 1` test
// fails at every target, `T::count_unique_variants(&doubled)`
// reports `0`, and `0 != 1`. Sibling posture to clause (171):
// both TWO PER-VARIANT-POSITIVE bands (mult `== 1` at THIS,
// mult `>= 2` at clause (171)) falsify at UNIFORM doubled-full-
// set fixpoints via opposite mechanisms (unique-band arm: no
// variant sits at count 1; strict-repeat arm: every variant
// sits at count 2 → count reports T::CARDINALITY, not 1).
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING
// `true`-arm catch): on the canonical non-flat triple
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2` (the (mult `>= 2`) witness), `T::ALL[1]` at
// count `1` (the SOLE (mult `== 1`) witness), `T::ALL[2..]` at
// count `0`; `T::count_unique_variants` reports `1` and the
// equality against `1` HOLDS. LOAD-BEARING positive fixture at
// `T::ALL[1]` — DISJOINT from clause (171)'s positive fixture
// at `T::ALL[0]` on the SAME slice: the bimodal triple is the
// CANONICAL WITNESS of the mult-band trichotomy's positive-
// band split, and the two arms fire on the same fixture at
// TYPED ORTHOGONAL witnesses riding DIFFERENT variants.
//
// The default trait body threads the scalar equality against
// `1` verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// set-level unique-band uniqueness surface. An override that
// folds onto `true` unconditionally bifurcates on the empty-
// slice + doubled-full-set arms (both correct `false`); an
// override that folds onto `false` unconditionally bifurcates
// on the bimodal-triple arm at cardinality `>= 3` (correct
// `true`).
let empty_unique_uniqueness = T::has_unique_unique_variant(empty);
let expected_empty_unique_uniqueness = T::count_unique_variants(empty) == 1;
assert_eq!(
empty_unique_uniqueness, expected_empty_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(&[]) drifted from (T::count_unique_variants(&[]) == 1) — the count-composition identity MUST hold on the empty slice; the empty-slice guard of `count_unique_variants` collapses the count to `0`, so the equality against `1` fails and the predicate lands on `false`; a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-band uniqueness consumer routes through",
);
let full_unique_uniqueness = T::has_unique_unique_variant(T::ALL);
let expected_full_unique_uniqueness = T::count_unique_variants(T::ALL) == 1;
assert_eq!(
full_unique_uniqueness, expected_full_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(T::ALL) drifted from (T::count_unique_variants(T::ALL) == 1) — the count-composition identity MUST hold on the full-set slice; clause (3)'s pairwise-distinctness invariant forces every variant to appear at EXACTLY ONE position of the full-set slice, every per-target multiplicity is `1`, every variant contributes to the count, `count_unique_variants` reports `T::CARDINALITY`, and the equality against `1` holds EXACTLY at T::CARDINALITY == 1 and falsifies at T::CARDINALITY >= 2",
);
let doubled_unique_uniqueness = T::has_unique_unique_variant(&doubled_full_set);
let expected_doubled_unique_uniqueness = T::count_unique_variants(&doubled_full_set) == 1;
assert_eq!(
doubled_unique_uniqueness, expected_doubled_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(&doubled_full_set) drifted from (T::count_unique_variants(&doubled_full_set) == 1) — the count-composition identity MUST hold on the doubled-full-set slice; the doubled full set hits every variant at exactly two positions, every per-target `== 1` test fails, `count_unique_variants` reports `0`, and `0 != 1`",
);
assert!(
!doubled_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(&doubled_full_set) drifted from `false` — appending a full-set copy to the full-set slice hits every variant at count 2, no variant sits at the singleton-multiplicity band, count_unique_variants reports 0, and the equality against 1 fails; a `true` doubled-full-set value silently bifurcates the doubled-full-set fixpoint contract pinning unique-uniqueness as UNIFORM-REPEAT-INCOMPATIBLE",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `true`-arm catch on
// the (equivalence-partition × mult `== 1` × unique-tie)
// corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]`
// sits at count `2` (the (mult `>= 2`) witness), `T::ALL[1]`
// at count `1` (the SOLE (mult `== 1`) witness),
// `T::ALL[2..]` at count `0`; `count_unique_variants`
// reports `1` and the equality against `1` HOLDS.
// DISJOINT-witness mirror of clause (171)'s positive
// fixture at the same slice (`T::ALL[0]` is the strict-
// repeat witness there; `T::ALL[1]` is the unique-band
// witness here) — the bimodal triple is the CANONICAL
// TYPED WITNESS of the mult-band trichotomy's positive-band
// split.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_uniqueness = T::has_unique_unique_variant(&bimodal_triple);
let expected_bimodal_triple_unique_uniqueness =
T::count_unique_variants(&bimodal_triple) == 1;
assert_eq!(
bimodal_triple_unique_uniqueness, expected_bimodal_triple_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(&bimodal_triple) drifted from (T::count_unique_variants(&bimodal_triple) == 1) — the count-composition identity MUST hold on the bimodal-triple fixture where the LOAD-BEARING `true`-arm fires (T::count_unique_variants reports `1`, T::ALL[1] is the SOLE (mult == 1) witness at count 1)",
);
assert!(
bimodal_triple_unique_uniqueness,
"{type_name}: T::has_unique_unique_variant(&bimodal_triple) drifted from `true` at cardinality >= 3 — on the canonical non-flat triple T::ALL[0] sits at count 2, T::ALL[1] at count 1 (the SOLE (mult == 1) witness), T::ALL[2..] at count 0, so `count_unique_variants` reports `1` and the equality against `1` HOLDS; a `false` bimodal-triple value silently bifurcates the LOAD-BEARING `true`-arm catch EXHAUSTIVELY CLOSING the (set-level × bool × equivalence-partition × mult-band × unique-tie) trichotomy row at its FINAL middle-band tile",
);
}
// Set-level existence-implication cross-check: for every
// canonical slice, `T::has_unique_unique_variant(s) ==>
// T::is_unique_any(s)` — a unique unique-multiplicity witness
// entails the existence of a unique-multiplicity witness.
// Sweeps the three multi-implementor canonical fixtures at
// once (empty, full-set, doubled-full-set); the bimodal-triple
// fixture is folded into its own
// `assert!(bimodal_triple_unique_uniqueness, …)` arm above
// where the LOAD-BEARING `true` value is pinned structurally.
assert!(
!T::has_unique_unique_variant(empty) || T::is_unique_any(empty),
"{type_name}: T::has_unique_unique_variant(&[]) drifted from the existence-implication contract on the empty slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_unique_variant(T::ALL) || T::is_unique_any(T::ALL),
"{type_name}: T::has_unique_unique_variant(T::ALL) drifted from the existence-implication contract on the full-set slice — uniqueness `true` MUST imply existence `true`",
);
assert!(
!T::has_unique_unique_variant(&doubled_full_set)
|| T::is_unique_any(&doubled_full_set),
"{type_name}: T::has_unique_unique_variant(&doubled_full_set) drifted from the existence-implication contract on the doubled-full-set slice — uniqueness `true` MUST imply existence `true`",
);
// (176) — `T::unique_unique_variant(items)` MUST agree with the
// guarded-first-witness body
// `if T::has_unique_unique_variant(items) { T::ALL.iter().copied().find(|&v| T::is_unique_occurrence_of(v, items)) } else { None }`
// on every slice AND MUST land on its canonical fixpoints. The
// corner EXHAUSTIVELY CLOSES the (set-level × `Option<Self>` ×
// equivalence-partition × multiplicity-band × unique-tie) row on
// the EQUIVALENCE-PARTITION surface at its MIDDLE (mult `== 1`)
// band — the row's FINAL THIRD tile past clause (172)
// [`T::unique_repeating_variant`] (mult `>= 2`) one MULTIPLICITY-
// BAND axis over. Sibling posture to clause (175) one RETURN-
// SHAPE axis over: clause (175) pins the set-level `bool` unique-
// band uniqueness bit; this clause LIFTS the same predicate to
// the `Option<Self>` witness-if-unique projection under a
// declaration-order find sweep of [`T::ALL`] through
// [`T::is_unique_occurrence_of`] gated on the uniqueness bit.
//
// Empty-slice arm: `T::has_unique_unique_variant(&[])` collapses
// to `false` via `count_unique_variants(&[]) == 0 != 1`, the
// guard short-circuits, and the projection reports `None` before
// the per-target singleton-multiplicity sweep runs.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant
// pins every variant at exactly one position of the full-set
// slice, every per-target multiplicity is `1`,
// `count_unique_variants(T::ALL)` reports `T::CARDINALITY`, and
// `has_unique_unique_variant(T::ALL)` holds EXACTLY when
// `T::CARDINALITY == 1` — at cardinality `>= 2` the guard falsifies
// and the projection collapses to `None`; at cardinality `== 1`
// the guarded find lands on `Some(T::ALL[0])`.
//
// Doubled-full-set arm: the doubled full set hits every variant
// at exactly two positions, every per-target multiplicity is `2`
// (not `1`), `count_unique_variants(&doubled)` reports `0`,
// `has_unique_unique_variant(&doubled)` returns `false`, and the
// guard collapses the projection to `None`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING
// `Some(_)`-arm catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[0]` sits at count `2 >= 2`, `T::ALL[1]` at count `1`
// (the SOLE (mult `== 1`) witness), `T::ALL[2..]` at count `0`;
// `count_unique_variants` reports `1`,
// `has_unique_unique_variant` returns `true`, and the
// declaration-order find sweep of `T::ALL` through
// `T::is_unique_occurrence_of` bypasses `T::ALL[0]` (count `2
// != 1`) and hits `T::ALL[1]` at slot 1. LOAD-BEARING
// DISCRIMINATOR from clause (172) on the same fixture: the
// strict-repeat arm's guarded find lands on `Some(T::ALL[0])`;
// THIS unique-band arm's guarded find lands on `Some(T::ALL[1])`
// — the two `Option<Self>` positive corners of the equivalence-
// partition (mult `>= 2`, mult `== 1`) uniqueness columns
// report DIFFERENT witnesses on the SAME slice, pinning the two
// multiplicity-bands as ORTHOGONAL uniqueness axes with disjoint
// witness projections riding DIFFERENT variants of the CANONICAL
// bimodal triple.
//
// The default trait body threads the boolean-guarded find sweep
// verbatim and satisfies every fixpoint arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// set-level unique-band witness-if-unique surface. An override
// that folds onto `Some(T::first())` unconditionally bifurcates
// on the empty-slice + doubled-full-set fixpoint arms at
// `Some(_) != None`; an override that folds onto `None`
// unconditionally bifurcates on the bimodal-triple arm at
// cardinality `>= 3` at `None != Some(T::ALL[1])`.
let empty_unique_unique = T::unique_unique_variant(empty);
let expected_empty_unique_unique = if T::has_unique_unique_variant(empty) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_unique_occurrence_of(v, empty))
} else {
None
};
assert_eq!(
empty_unique_unique, expected_empty_unique_unique,
"{type_name}: T::unique_unique_variant(&[]) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the empty slice; the empty-slice guard of `has_unique_unique_variant` collapses to `false` via `count_unique_variants(&[]) == 0 != 1`, the guard short-circuits to `None`, and the per-target singleton-multiplicity sweep is not consulted; a `Some(_)` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream equivalence-partition unique-band witness-if-unique consumer routes through",
);
let full_unique_unique = T::unique_unique_variant(T::ALL);
let expected_full_unique_unique = if T::has_unique_unique_variant(T::ALL) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_unique_occurrence_of(v, T::ALL))
} else {
None
};
assert_eq!(
full_unique_unique, expected_full_unique_unique,
"{type_name}: T::unique_unique_variant(T::ALL) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` clause (3)'s pairwise-distinctness invariant pins every variant at count 1, count_unique_variants reports T::CARDINALITY, has_unique_unique_variant returns `false`, and the guard collapses to `None`; at `T::CARDINALITY == 1` count_unique_variants reports `1`, has_unique_unique_variant returns `true`, and the guarded find lands on Some(T::ALL[0])",
);
let doubled_unique_unique = T::unique_unique_variant(&doubled_full_set);
let expected_doubled_unique_unique = if T::has_unique_unique_variant(&doubled_full_set) {
T::ALL
.iter()
.copied()
.find(|&v| T::is_unique_occurrence_of(v, &doubled_full_set))
} else {
None
};
assert_eq!(
doubled_unique_unique, expected_doubled_unique_unique,
"{type_name}: T::unique_unique_variant(&doubled_full_set) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the doubled-full-set slice; the doubled full set hits every variant at count 2, no variant sits at the singleton-multiplicity band, count_unique_variants reports 0, has_unique_unique_variant returns `false`, and the guard collapses the projection to `None`; a `Some(_)` doubled-full-set value silently bifurcates the doubled-full-set fixpoint contract",
);
assert_eq!(
doubled_unique_unique, None,
"{type_name}: T::unique_unique_variant(&doubled_full_set) drifted from `None` — appending a full-set copy to the full-set slice hits every variant at count 2, no variant sits at the singleton-multiplicity band, has_unique_unique_variant returns `false`, and the guard collapses to `None`; a `Some(_)` doubled-full-set value silently bifurcates the doubled-full-set fixpoint contract pinning unique-band uniqueness-witness as UNIFORM-REPEAT-INCOMPATIBLE",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[1])`-arm
// catch on the (`Option<Self>` × equivalence-partition ×
// mult `== 1` × unique-tie) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2` (the (mult `>= 2`) witness), `T::ALL[1]` at
// count `1` (the SOLE (mult `== 1`) witness), `T::ALL[2..]`
// at count `0`; `count_unique_variants` reports `1`,
// `has_unique_unique_variant` returns `true`, and the
// declaration-order find sweep bypasses `T::ALL[0]` (count
// `2 != 1`) and lands on `T::ALL[1]` at slot 1.
// DISJOINT-WITNESS mirror of clause (172)'s bimodal-triple
// positive arm at `Some(T::ALL[0])` one MULTIPLICITY-BAND
// axis over — the two POSITIVE `Some(_)` arms of the
// equivalence-partition (mult `>= 2`, mult `== 1`)
// uniqueness columns report DIFFERENT witnesses on the SAME
// slice, pinning the bimodal triple as the CANONICAL TYPED
// WITNESS of the mult-band trichotomy's positive-band split
// at the `Option<Self>` return-shape column.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_triple_unique_unique = T::unique_unique_variant(&bimodal_triple);
let expected_bimodal_triple_unique_unique = if T::has_unique_unique_variant(&bimodal_triple)
{
T::ALL
.iter()
.copied()
.find(|&v| T::is_unique_occurrence_of(v, &bimodal_triple))
} else {
None
};
assert_eq!(
bimodal_triple_unique_unique, expected_bimodal_triple_unique_unique,
"{type_name}: T::unique_unique_variant(&bimodal_triple) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the bimodal-triple fixture where the LOAD-BEARING `Some(T::ALL[1])`-arm fires",
);
assert_eq!(
bimodal_triple_unique_unique,
Some(T::ALL[1]),
"{type_name}: T::unique_unique_variant(&bimodal_triple) drifted from `Some(T::ALL[1])` at cardinality >= 3 — on the canonical non-flat triple T::ALL[0] sits at count 2, T::ALL[1] at count 1 (the SOLE (mult == 1) witness), T::ALL[2..] at count 0, so `count_unique_variants` reports `1`, `has_unique_unique_variant` returns `true`, and the declaration-order find sweep of T::ALL through T::is_unique_occurrence_of bypasses T::ALL[0] (count 2 != 1) and hits T::ALL[1] at slot 1; a divergent value silently bifurcates the LOAD-BEARING `Some(_)`-arm catch EXHAUSTIVELY CLOSING the (set-level × `Option<Self>` × equivalence-partition × mult-band × unique-tie) trichotomy row at its FINAL middle-band tile AND its LOAD-BEARING DISCRIMINATION from clause (172)'s positive arm which lands on Some(T::ALL[0]) on the SAME fixture — the two POSITIVE Some(_) corners report DIFFERENT witnesses on the same slice",
);
}
// Set-level is-some coincidence cross-check: for every canonical
// slice, `T::unique_unique_variant(s).is_some() ==
// T::has_unique_unique_variant(s)` — the `Option<Self>` return's
// `is_some` bit COINCIDES with the set-level unique-band
// uniqueness bit. Sweeps the three multi-implementor canonical
// fixtures at once (empty, full-set, doubled-full-set); the
// bimodal-triple fixture is folded into its own
// `assert_eq!(bimodal_triple_unique_unique, Some(T::ALL[1]), …)`
// arm above where the LOAD-BEARING `Some(_)` value is pinned
// structurally.
assert_eq!(
T::unique_unique_variant(empty).is_some(),
T::has_unique_unique_variant(empty),
"{type_name}: T::unique_unique_variant(&[]).is_some() drifted from T::has_unique_unique_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_variant(T::ALL).is_some(),
T::has_unique_unique_variant(T::ALL),
"{type_name}: T::unique_unique_variant(T::ALL).is_some() drifted from T::has_unique_unique_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_unique_variant(&doubled_full_set).is_some(),
T::has_unique_unique_variant(&doubled_full_set),
"{type_name}: T::unique_unique_variant(&doubled_full_set).is_some() drifted from T::has_unique_unique_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
// (177) — `T::unique_missing_variant(items)` MUST agree with the
// guarded-first-witness body
// `if T::has_unique_missing_variant(items) { ALL.find(!occurs_in) }
// else { None }` on every canonical slice AND its `is_some` bit
// MUST coincide with `T::has_unique_missing_variant(items)`. The
// corner EXHAUSTIVELY CLOSES the miss-band arm of the (set-level ×
// `Option<Self>` × equivalence-partition × multiplicity-band ×
// unique-tie) trichotomy row on the equivalence-partition surface
// at its FINAL third tile past clause (172)
// [`T::unique_repeating_variant`] (mult `>= 2`) strict-repeat arm
// AND clause (176) [`T::unique_unique_variant`] (mult `== 1`)
// unique-band arm one MULTIPLICITY-BAND axis over. Sibling posture
// to clause (174) one RETURN-SHAPE axis over: clause (174) pins
// the set-level `bool` miss-band uniqueness bit,
// this clause pins the set-level `Option<Self>` miss-band witness-
// when-unique projection.
//
// Empty-slice arm at cardinality `>= 2`:
// `T::count_missing(&[])` reports `T::CARDINALITY >= 2`,
// `T::has_unique_missing_variant(&[])` returns `false`, the guard
// short-circuits, and the projection lands on `None`.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant pins
// every variant at exactly one position, no variant is missing,
// `T::has_unique_missing_variant(T::ALL)` returns `false`, and the
// guard collapses to `None`.
//
// Doubled-full-set arm: the doubled full set hits every variant at
// exactly two positions, no variant is missing,
// `T::has_unique_missing_variant(&doubled_full_set)` returns
// `false`, and the guard collapses to `None`.
//
// Single-missing arm at cardinality `>= 2` (LOAD-BEARING `Some`-arm
// catch): on `T::ALL[..T::CARDINALITY - 1]` (the full set minus its
// declaration-order last variant) `T::ALL[T::CARDINALITY - 1]` is
// the SOLE missing witness at multiplicity `0`,
// `T::has_unique_missing_variant` returns `true`, the guard fires,
// and the declaration-order sweep of T::ALL bypasses every present
// variant and hits `T::ALL[T::CARDINALITY - 1]` at its miss entry.
// This positive fixpoint DISCRIMINATES a `None`-drift override
// from the canonical body.
//
// Is-some coincidence: on every fixture the projection's `is_some`
// bit MUST equal `T::has_unique_missing_variant`.
let empty_unique_missing = T::unique_missing_variant(empty);
let expected_empty_unique_missing: Option<T> = if T::has_unique_missing_variant(empty) {
T::ALL.iter().copied().find(|&v| !T::occurs_in(v, empty))
} else {
None
};
assert_eq!(
empty_unique_missing, expected_empty_unique_missing,
"{type_name}: T::unique_missing_variant(&[]) drifted from the guarded-first-witness body — at cardinality `>= 2` `T::has_unique_missing_variant(&[])` returns `false` and the projection MUST collapse to `None`; at cardinality `1` the singleton closed set's SOLE variant is trivially missing and the sweep lands on `Some(T::ALL[0])`",
);
assert_eq!(
empty_unique_missing.is_some(),
T::has_unique_missing_variant(empty),
"{type_name}: T::unique_missing_variant(&[]).is_some() drifted from T::has_unique_missing_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
let full_unique_missing = T::unique_missing_variant(T::ALL);
let expected_full_unique_missing: Option<T> = if T::has_unique_missing_variant(T::ALL) {
T::ALL.iter().copied().find(|&v| !T::occurs_in(v, T::ALL))
} else {
None
};
assert_eq!(
full_unique_missing, expected_full_unique_missing,
"{type_name}: T::unique_missing_variant(T::ALL) drifted from the guarded-first-witness body — clause (3)'s pairwise-distinctness invariant forces every variant to appear at exactly one position, no variant is missing, `T::has_unique_missing_variant(T::ALL)` returns `false`, and the projection MUST collapse to `None`",
);
assert_eq!(
full_unique_missing.is_some(),
T::has_unique_missing_variant(T::ALL),
"{type_name}: T::unique_missing_variant(T::ALL).is_some() drifted from T::has_unique_missing_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
let doubled_unique_missing = T::unique_missing_variant(&doubled_full_set);
let expected_doubled_unique_missing: Option<T> =
if T::has_unique_missing_variant(&doubled_full_set) {
T::ALL
.iter()
.copied()
.find(|&v| !T::occurs_in(v, &doubled_full_set))
} else {
None
};
assert_eq!(
doubled_unique_missing, expected_doubled_unique_missing,
"{type_name}: T::unique_missing_variant(&doubled_full_set) drifted from the guarded-first-witness body — the doubled full set hits every variant at exactly two positions, no variant is missing, and the projection MUST collapse to `None`",
);
assert_eq!(
doubled_unique_missing.is_some(),
T::has_unique_missing_variant(&doubled_full_set),
"{type_name}: T::unique_missing_variant(&doubled_full_set).is_some() drifted from T::has_unique_missing_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
// Single-missing fixture: LOAD-BEARING `Some(T::ALL[T::CARDINALITY - 1])`-arm
// catch on the (equivalence-partition × mult `== 0` × unique-
// tie × `Option<Self>`) corner at cardinality `>= 2`. On
// `T::ALL[..T::CARDINALITY - 1]` `T::ALL[T::CARDINALITY - 1]`
// sits at count `0` (the SOLE missing witness), every other
// variant sits at count `1`, `count_missing` reports `1`,
// `has_unique_missing_variant` returns `true`, the guard
// fires, and the declaration-order sweep of T::ALL bypasses
// every present variant and hits
// `T::ALL[T::CARDINALITY - 1]` at its miss entry. A `None`-
// drift override bifurcates here at
// `None != Some(T::ALL[T::CARDINALITY - 1])`.
let single_missing: ::std::vec::Vec<T> =
T::ALL[..T::CARDINALITY - 1].iter().copied().collect();
let single_missing_unique_missing = T::unique_missing_variant(&single_missing);
let expected_single_missing_unique_missing: Option<T> =
if T::has_unique_missing_variant(&single_missing) {
T::ALL
.iter()
.copied()
.find(|&v| !T::occurs_in(v, &single_missing))
} else {
None
};
assert_eq!(
single_missing_unique_missing, expected_single_missing_unique_missing,
"{type_name}: T::unique_missing_variant(&single_missing) drifted from the guarded-first-witness body — the guarded-first-witness identity MUST hold on the single-missing fixture where the LOAD-BEARING `Some(T::ALL[T::CARDINALITY - 1])`-arm fires",
);
assert_eq!(
single_missing_unique_missing,
Some(T::ALL[T::CARDINALITY - 1]),
"{type_name}: T::unique_missing_variant(&single_missing) drifted from `Some(T::ALL[T::CARDINALITY - 1])` at cardinality >= 2 — on `T::ALL[..T::CARDINALITY - 1]` the last-declaration-slot variant is the SOLE missing witness, `count_missing` reports `1`, `has_unique_missing_variant` returns `true`, and the declaration-order find sweep of T::ALL through `!T::occurs_in` bypasses every present variant and lands at slot `T::CARDINALITY - 1`; a divergent value silently bifurcates the LOAD-BEARING `Some(_)`-arm catch EXHAUSTIVELY CLOSING the miss-band arm of the (set-level × `Option<Self>` × equivalence-partition × mult-band × unique-tie) trichotomy row at its FINAL third tile",
);
assert_eq!(
single_missing_unique_missing.is_some(),
T::has_unique_missing_variant(&single_missing),
"{type_name}: T::unique_missing_variant(&single_missing).is_some() drifted from T::has_unique_missing_variant(&single_missing) — the is-some coincidence identity MUST hold on the single-missing fixture",
);
}
// (178) — `T::is_unique_missing_variant_of(target, items)` MUST
// agree with the conjunction of `!T::occurs_in(target, items)`
// and `T::has_unique_missing_variant(items)` on every (target,
// slice) pair AND MUST land on its canonical fixpoints (`false`
// at every target on every singleton at cardinality `>= 2` via
// the negated-membership arm on the matching-target and the
// uniqueness arm on the non-matching-target when
// `T::CARDINALITY == 2` — actually the matching-singleton
// uniformly falsifies via the negated-membership arm regardless
// of cardinality — `false` at every target on the full-set slice
// via clause (3)'s pairwise-distinctness invariant that pins
// every variant as present, `false` at every target on the
// doubled-full-set slice via the same pairwise-distinctness
// invariant lifted through the doubled slice, `true` at EXACTLY
// `T::ALL[T::CARDINALITY - 1]` and `false` at every other target
// on the single-missing fixture `T::ALL[..T::CARDINALITY - 1]`
// at cardinality `>= 2` via the LOAD-BEARING miss-band positive
// arm) AND on ONE composition-equality arm on every canonical
// fixture: the set-level filter-count reduction over [`T::ALL`]
// of THIS per-target predicate MUST equal
// `usize::from(T::has_unique_missing_variant(items))` on the
// full-set, doubled-full-set, AND single-missing slices, pinning
// the at-most-one-target contract as a TYPED CONSEQUENCE of the
// set-level miss-band uniqueness bit across BOTH the negative
// (covering) AND positive (single-missing) arms.
//
// The canonical fixpoints + composition arms partition failure
// modes at the (per-target × slice-shape × combinator ×
// composition-equality) corner simultaneously: an override that
// folds onto `true` unconditionally fires on the matching-
// singleton arm at every target (each variant occurs so
// `!occurs_in` is `false` and the conjunction MUST land on
// `false`) AND on the full-set arm at every target AND on the
// doubled-full-set arm at every target AND on the composition-
// equality arms at those flat fixtures (each pins the filter-
// count at `0` because the set-level uniqueness bit falsifies);
// an override that folds onto `false` unconditionally fires on
// the single-missing arm at `T::ALL[T::CARDINALITY - 1]` at
// cardinality `>= 2` (the SOLE positive arm on the canonical
// fixture window) AND on the composition-equality arm at the
// single-missing slice (where the filter-count is `1` but the
// drifted override reduces the filter-count to `0`).
//
// Sibling posture to clause (173) one MULTIPLICITY-BAND axis
// over: clause (173) pins the per-target × bool × unique-tie
// corner on the (mult `>= 2`) STRICT-REPEAT arm of the
// equivalence-partition surface; THIS clause pins the same per-
// target × bool × unique-tie corner on the (mult `== 0`) MISS-
// BAND arm. Sibling posture to clause (174) one ARITY axis over:
// clause (174) pins the set-level miss-band uniqueness bit; this
// clause LIFTS the same uniqueness predicate to the per-target
// arity axis under conjunction with the NEGATED per-target
// membership predicate. Sibling posture to clause (177) one
// RETURN-SHAPE axis over: clause (177) pins the set-level
// `Option<Self>` miss-band witness-if-unique projection; this
// clause pins the per-target `bool` miss-band membership-if-
// unique predicate. LOAD-BEARING ASYMMETRY against clause (173)
// which stays UNIVERSALLY `false` on the single-missing fixture
// `T::ALL[..T::CARDINALITY - 1]` (every present variant sits at
// count `1`, `count_repeating_variants == 0`, and the strict-
// repeat uniqueness bit falsifies at every target); THIS clause
// stays UNIVERSALLY `false` on the strict-repeat arm's
// bimodal-triple positive fixture at cardinality `>= 3` (no
// variant is uniquely missing when `T::CARDINALITY - 2 >= 1`
// variants are simultaneously missing). The two SURFACES pin
// uniqueness on ORTHOGONAL fixtures, witnessing their
// orthogonality across the mult-band trichotomy's two extremal
// bands.
//
// The default trait body threads the
// `!occurs_in(target, items) && has_unique_missing_variant(items)`
// conjunction verbatim and satisfies every fixpoint arm +
// composition arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the per-target unique-miss surface
// every downstream consumer routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert_eq!(
T::is_unique_missing_variant_of(target, T::ALL),
!T::occurs_in(target, T::ALL) && T::has_unique_missing_variant(T::ALL),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, T::ALL) drifted from `!T::occurs_in && T::has_unique_missing_variant` on the full-set slice — the composition-conjunction identity was violated",
);
assert!(
!T::is_unique_missing_variant_of(target, T::ALL),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, T::ALL) != false — clause (3)'s pairwise-distinctness invariant pins every variant at exactly one position of the full-set slice, `!T::occurs_in` is `false` at every target, and the conjunction lands on `false`; a `true` full-set arm silently bifurcates the pairwise-distinct fixpoint via the negated-membership arm",
);
assert!(
!T::is_unique_missing_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, `!T::occurs_in` is `false` at every target, and the conjunction lands on `false`; a `true` doubled-full-set arm silently bifurcates the covering-slice fixpoint via the negated-membership arm",
);
}
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
!T::is_unique_missing_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, [{target_label:?}]) != false — the target occurs at count `1`, `!T::occurs_in({target_label:?}, [{target_label:?}])` is `false`, and the conjunction lands on `false` at the negated-membership arm regardless of the uniqueness arm; a `true` matching-singleton arm silently bifurcates the target-present fixpoint",
);
}
let full_unique_missing_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_missing_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_missing_membership_count,
usize::from(T::has_unique_missing_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, T::ALL)).count() == {full_unique_missing_membership_count} drifted from usize::from(T::has_unique_missing_variant(T::ALL)) == 0 — the per-target unique-miss predicate's set-level filter-count MUST equal the set-level miss-band uniqueness bit cast to usize on the full-set covering fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
let doubled_unique_missing_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_missing_variant_of(v, &doubled_full_set))
.count();
assert_eq!(
doubled_unique_missing_membership_count,
usize::from(T::has_unique_missing_variant(&doubled_full_set)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, &doubled_full_set)).count() == {doubled_unique_missing_membership_count} drifted from usize::from(T::has_unique_missing_variant(&doubled_full_set)) == 0 — the per-target unique-miss predicate's set-level filter-count MUST equal the set-level miss-band uniqueness bit cast to usize on the doubled-full-set covering fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
// Single-missing fixture — LOAD-BEARING `true`-arm catch on
// the (per-target × bool × equivalence-partition × mult
// `== 0` × unique-tie) corner at cardinality `>= 2`. On
// `T::ALL[..T::CARDINALITY - 1]` the last-declaration-slot
// variant `T::ALL[T::CARDINALITY - 1]` is the SOLE absent
// variant, every other variant sits at count `1`,
// `count_missing` reports `1`, `has_unique_missing_variant`
// returns `true`, and the conjunction lands on `true` at
// `T::ALL[T::CARDINALITY - 1]` and `false` at every other
// target. LOAD-BEARING DISCRIMINATOR from clause (173) which
// stays UNIVERSALLY `false` on the SAME fixture (the strict-
// repeat arm's uniqueness bit falsifies at
// `count_repeating_variants == 0`) — the two SURFACES pin
// uniqueness at DIFFERENT fixtures on the mult-band
// trichotomy's two extremal bands.
let single_missing_isuniq: ::std::vec::Vec<T> =
T::ALL[..T::CARDINALITY - 1].iter().copied().collect();
for (target_slot, target) in T::ALL.iter().copied().enumerate() {
let target_label = <T as ClosedSet>::label(target);
let expected = target_slot == T::CARDINALITY - 1;
assert_eq!(
T::is_unique_missing_variant_of(target, &single_missing_isuniq),
expected,
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, &single_missing) drifted from expected == {expected} — on `T::ALL[..T::CARDINALITY - 1]` the last-declaration-slot variant is the SOLE absent variant, every other variant sits at count 1; the SOLE positive arm sits at T::ALL[T::CARDINALITY - 1] via `!T::occurs_in(T::ALL[T::CARDINALITY - 1], slice) && T::has_unique_missing_variant(slice)`, every other target lands on `false`; a drifted value silently bifurcates the LOAD-BEARING miss-band positive arm on the equivalence-partition unique-tie corner AND its LOAD-BEARING DISCRIMINATION from clause (173) which stays UNIVERSALLY `false` on the same fixture",
);
}
let single_missing_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_missing_variant_of(v, &single_missing_isuniq))
.count();
assert_eq!(
single_missing_membership_count,
usize::from(T::has_unique_missing_variant(&single_missing_isuniq)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, &single_missing)).count() == {single_missing_membership_count} drifted from usize::from(T::has_unique_missing_variant(&single_missing)) == 1 — the per-target unique-miss predicate's set-level filter-count MUST equal the set-level miss-band uniqueness bit cast to usize on the LOAD-BEARING single-missing positive fixture; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_missing_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar on the sole positive canonical fixture",
);
}
// Set-level option-equality coincidence cross-check: for every
// canonical slice and every target, T::is_unique_missing_variant_of(v, s)
// == (T::unique_missing_variant(s) == Some(v)) — the per-target
// bool predicate coincides with the equality test between the
// set-level `Option<Self>` witness projection and `Some(v)`.
// Independent cross-check on the return-shape axis distinct from
// the composition-conjunction body.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert_eq!(
T::is_unique_missing_variant_of(target, T::ALL),
T::unique_missing_variant(T::ALL) == Some(target),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, T::ALL) drifted from (T::unique_missing_variant(T::ALL) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::is_unique_missing_variant_of(target, &doubled_full_set),
T::unique_missing_variant(&doubled_full_set) == Some(target),
"{type_name}: T::is_unique_missing_variant_of({target_label:?}, &doubled_full_set) drifted from (T::unique_missing_variant(&doubled_full_set) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the doubled-full-set slice",
);
}
// (179) — `T::is_unique_unique_variant_of(target, items)` MUST
// agree with the conjunction of
// `T::is_unique_occurrence_of(target, items)` and
// `T::has_unique_unique_variant(items)` on every (target, slice)
// pair AND MUST land on its canonical fixpoints (`false` at every
// target on the empty slice via
// [`T::is_unique_occurrence_of`]'s empty-slice guard, `true` at
// EXACTLY the matching-singleton target `v` and `false` at every
// non-matching target on every singleton `&[v]` at cardinality
// `>= 2` via the LOAD-BEARING singleton-multiplicity positive arm,
// `false` at every target on the full-set slice at cardinality
// `>= 2` via the uniqueness arm that falsifies when EVERY variant
// sits at count `1`, `false` at every target on the doubled-full-
// set slice at cardinality `>= 1` via the singleton-multiplicity
// membership arm that falsifies when EVERY variant sits at count
// `2`, `true` at EXACTLY `T::ALL[1]` and `false` at every other
// target on the bimodal-triple fixture at cardinality `>= 3` via
// the LOAD-BEARING singleton-multiplicity positive arm) AND on ONE
// composition-equality arm on every canonical fixture: the set-
// level filter-count reduction over [`T::ALL`] of THIS per-target
// predicate MUST equal
// `usize::from(T::has_unique_unique_variant(items))` on the full-
// set, doubled-full-set, AND bimodal-triple slices, pinning the
// at-most-one-target contract as a TYPED CONSEQUENCE of the set-
// level unique-band uniqueness bit across BOTH the negative
// (flat-histogram) AND positive (bimodal-triple) arms.
//
// The canonical fixpoints + composition arms partition failure
// modes at the (per-target × slice-shape × combinator ×
// composition-equality) corner simultaneously: an override that
// folds onto `true` unconditionally fires on the empty-slice arm
// at every target AND on the full-set arm at cardinality `>= 2`
// AND on the doubled-full-set arm at every target (each pins the
// projection at `false` because
// [`T::is_unique_occurrence_of`] falsifies at count `!= 1` OR
// [`T::has_unique_unique_variant`] falsifies at
// `count_unique_variants != 1`); an override that folds onto
// `false` unconditionally fires on the matching-singleton arm at
// every target at cardinality `>= 2` (each singleton pins its own
// matching target as the SOLE positive arm) AND on the bimodal-
// triple arm at `T::ALL[1]` at cardinality `>= 3` (the SOLE
// positive arm on the canonical non-flat triple fixture) AND on
// the composition-equality arm at the bimodal-triple slice (where
// the filter-count is `1` but the drifted override reduces the
// filter-count to `0`).
//
// Sibling posture to clauses (173) + (178) one MULTIPLICITY-BAND
// axis over: clause (173) pins the per-target × bool × unique-tie
// corner on the (mult `>= 2`) STRICT-REPEAT arm of the
// equivalence-partition surface; clause (178) pins the same corner
// on the (mult `== 0`) MISS-BAND arm; THIS clause pins the same
// corner on the (mult `== 1`) MIDDLE arm — the three together
// EXHAUSTIVELY CLOSE the per-target unique-tie sharpening across
// the equivalence-partition mult-band trichotomy, mirroring the
// set-level bool and set-level `Option<Self>` exhaustive closures
// one ARITY axis over. Sibling posture to clause (175) one ARITY
// axis over: clause (175) pins the set-level unique-band
// uniqueness bit; THIS clause LIFTS the same uniqueness predicate
// to the per-target arity axis under conjunction with the per-
// target singleton-multiplicity membership predicate. Sibling
// posture to clause (176) one RETURN-SHAPE axis over: clause
// (176) pins the set-level `Option<Self>` unique-band witness-if-
// unique projection; THIS clause pins the per-target `bool`
// singleton-multiplicity membership-if-unique predicate. LOAD-
// BEARING DISJOINT-WITNESS mirror of clause (173) on the same
// bimodal-triple fixture: clause (173) pins its positive arm at
// `T::ALL[0]` (the SOLE strict-repeat witness); THIS clause pins
// its positive arm at `T::ALL[1]` (the SOLE singleton-multiplicity
// witness) — the two per-target POSITIVE `true` corners of the
// equivalence-partition (mult `>= 2`, mult `== 1`) uniqueness
// columns report `true` at DIFFERENT targets on the same slice,
// witnessing the two bands as ORTHOGONAL uniqueness projections.
//
// The default trait body threads the
// `is_unique_occurrence_of(target, items) &&
// has_unique_unique_variant(items)` conjunction verbatim and
// satisfies every fixpoint arm + composition arm for free; the
// assertion catches a future implementor whose override drifts
// the projection loudly rather than silently bifurcating the
// per-target unique-singleton surface every downstream consumer
// routes through.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_unique_variant_of(target, empty),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, &[]) != false — the per-target unique-singleton predicate MUST report `false` on the empty slice at every target because T::is_unique_occurrence_of(v, &[]) collapses to `false` via its empty-slice guard (count `0 != 1`); a `true` empty-slice value silently bifurcates the empty-slice fixpoint contract every downstream unique-singleton consumer routes through",
);
assert_eq!(
T::is_unique_unique_variant_of(target, T::ALL),
T::is_unique_occurrence_of(target, T::ALL) && T::has_unique_unique_variant(T::ALL),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, T::ALL) drifted from `T::is_unique_occurrence_of && T::has_unique_unique_variant` on the full-set slice — the composition-conjunction identity was violated",
);
assert!(
!T::is_unique_unique_variant_of(target, &doubled_full_set),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, &doubled_full_set) != false — the doubled full set hits every variant at exactly two positions, T::is_unique_occurrence_of falsifies at every target via count `2 != 1`, and the conjunction lands on `false` through the membership arm; a `true` doubled-full-set arm silently bifurcates the every-variant-repeats non-singleton fixpoint",
);
}
if T::CARDINALITY >= 2 {
// Matching-singleton POSITIVE arm at cardinality `>= 2` (LOAD-
// BEARING `true`-arm catch on a compact fixture). On `&[v]`
// the target sits at count `1` (the SOLE singleton-
// multiplicity witness), every non-target at count `0`;
// T::is_unique_occurrence_of reports `true` at the matching
// target and `false` at every non-matching target,
// T::has_unique_unique_variant reports `true` via
// count_unique_variants == 1, and the conjunction lands on
// `true` at the matching target and `false` at every non-
// matching target. LOAD-BEARING DISCRIMINATOR from clauses
// (173) + (178) which BOTH stay UNIVERSALLY `false` on the
// same matching-singleton fixture at every target — clause
// (173) falsifies via `count 1 < 2`; clause (178) falsifies
// via the negated-membership arm at the matching target AND
// via the uniqueness arm on non-matching targets at
// cardinality `>= 3`.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert!(
T::is_unique_unique_variant_of(target, &matching_singleton),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, [{target_label:?}]) != true — at cardinality >= 2 the singleton hits {target_label:?} at count `1` (the SOLE singleton-multiplicity witness), every non-target at count `0`; T::is_unique_occurrence_of reports `true` at the matching target, T::has_unique_unique_variant reports `true` via count_unique_variants == 1, and the conjunction lands on `true`; a `false` matching-singleton POSITIVE arm silently bifurcates the LOAD-BEARING singleton-multiplicity positive fixture AND its LOAD-BEARING DISCRIMINATION from clauses (173) + (178) which BOTH stay UNIVERSALLY `false` on the same fixture",
);
for other in T::ALL.iter().copied() {
if other == target {
continue;
}
let other_label = <T as ClosedSet>::label(other);
assert!(
!T::is_unique_unique_variant_of(other, &matching_singleton),
"{type_name}: T::is_unique_unique_variant_of({other_label:?}, [{target_label:?}]) != false — at cardinality >= 2 the non-matching target sits at count `0` in `[{target_label:?}]`, T::is_unique_occurrence_of falsifies at count `0 != 1`, and the conjunction lands on `false` through the membership arm; a `true` non-matching-singleton arm silently bifurcates the target-absent fixpoint",
);
}
}
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert!(
!T::is_unique_unique_variant_of(target, T::ALL),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, T::ALL) != false — at cardinality >= 2 clause (3)'s pairwise-distinctness invariant pins every variant at count 1, count_unique_variants reports T::CARDINALITY >= 2, T::has_unique_unique_variant returns `false` via the uniqueness arm, and the conjunction lands on `false` at every target; a `true` full-set arm at cardinality >= 2 silently bifurcates the pairwise-distinct-implies-every-variant-is-singleton fixpoint",
);
}
let full_unique_unique_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_unique_variant_of(v, T::ALL))
.count();
assert_eq!(
full_unique_unique_membership_count,
usize::from(T::has_unique_unique_variant(T::ALL)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, T::ALL)).count() == {full_unique_unique_membership_count} drifted from usize::from(T::has_unique_unique_variant(T::ALL)) — the per-target unique-singleton predicate's set-level filter-count MUST equal the set-level unique-band uniqueness bit cast to usize on the flat-histogram fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
let doubled_unique_unique_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_unique_variant_of(v, &doubled_full_set))
.count();
assert_eq!(
doubled_unique_unique_membership_count,
usize::from(T::has_unique_unique_variant(&doubled_full_set)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, &doubled_full_set)).count() == {doubled_unique_unique_membership_count} drifted from usize::from(T::has_unique_unique_variant(&doubled_full_set)) == 0 — the per-target unique-singleton predicate's set-level filter-count MUST equal the set-level unique-band uniqueness bit cast to usize on the doubled-full-set flat-histogram fixpoint; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture — LOAD-BEARING `true`-arm catch
// on the (per-target × bool × equivalence-partition × mult
// `== 1` × unique-tie) corner. On `[T::ALL[0], T::ALL[0],
// T::ALL[1]]` `T::ALL[0]` sits at count `2 >= 2`,
// `T::ALL[1]` at count `1` (the SOLE singleton-
// multiplicity witness), `T::ALL[2..]` at count `0`;
// T::is_unique_occurrence_of reports `true` only at
// `T::ALL[1]`, T::has_unique_unique_variant reports `true`,
// and the conjunction lands on `true` at `T::ALL[1]` and
// `false` at every other target. LOAD-BEARING
// DISCRIMINATOR from clause (173) which pins its bimodal-
// triple positive arm at `T::ALL[0]` (the SOLE strict-
// repeat witness) on the same fixture — the two per-target
// POSITIVE `true` corners of the equivalence-partition
// (mult `>= 2`, mult `== 1`) uniqueness columns report
// `true` at DIFFERENT targets on the same slice.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
for (target_slot, target) in T::ALL.iter().copied().enumerate() {
let target_label = <T as ClosedSet>::label(target);
let expected = target_slot == 1;
assert_eq!(
T::is_unique_unique_variant_of(target, &bimodal_triple),
expected,
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, &bimodal_triple) drifted from expected == {expected} — on the canonical non-flat triple T::ALL[0] sits at count 2 >= 2, T::ALL[1] at count 1 (the SOLE singleton-multiplicity witness), T::ALL[2..] at count 0; the SOLE positive arm sits at T::ALL[1] via T::is_unique_occurrence_of(T::ALL[1], triple) && T::has_unique_unique_variant(triple), every other target lands on `false`; a drifted value silently bifurcates the LOAD-BEARING singleton-multiplicity positive arm on the equivalence-partition unique-tie corner AND its LOAD-BEARING DISCRIMINATION from clause (173) which pins its positive arm at T::ALL[0] (strict-repeat witness) on the same fixture",
);
}
let bimodal_unique_unique_membership_count = T::ALL
.iter()
.copied()
.filter(|&v| T::is_unique_unique_variant_of(v, &bimodal_triple))
.count();
assert_eq!(
bimodal_unique_unique_membership_count,
usize::from(T::has_unique_unique_variant(&bimodal_triple)),
"{type_name}: T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, &bimodal_triple)).count() == {bimodal_unique_unique_membership_count} drifted from usize::from(T::has_unique_unique_variant(&bimodal_triple)) == 1 — the per-target unique-singleton predicate's set-level filter-count MUST equal the set-level unique-band uniqueness bit cast to usize on the LOAD-BEARING bimodal-triple positive fixture; a downstream consumer that binds `T::ALL.iter().filter(|v| T::is_unique_unique_variant_of(*v, items)).count()` as its atomic per-target arity-lift of the set-level uniqueness bit would disagree with the pinned scalar on the sole positive canonical fixture",
);
}
}
// Set-level option-equality coincidence cross-check: for every
// canonical slice and every target,
// T::is_unique_unique_variant_of(v, s) == (T::unique_unique_variant(s)
// == Some(v)) — the per-target bool predicate coincides with the
// equality test between the set-level `Option<Self>` witness
// projection and `Some(v)`. Independent cross-check on the return-
// shape axis distinct from the composition-conjunction body.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
assert_eq!(
T::is_unique_unique_variant_of(target, empty),
T::unique_unique_variant(empty) == Some(target),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, &[]) drifted from (T::unique_unique_variant(&[]) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::is_unique_unique_variant_of(target, T::ALL),
T::unique_unique_variant(T::ALL) == Some(target),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, T::ALL) drifted from (T::unique_unique_variant(T::ALL) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::is_unique_unique_variant_of(target, &doubled_full_set),
T::unique_unique_variant(&doubled_full_set) == Some(target),
"{type_name}: T::is_unique_unique_variant_of({target_label:?}, &doubled_full_set) drifted from (T::unique_unique_variant(&doubled_full_set) == Some({target_label:?})) — the option-equality coincidence identity MUST hold on the doubled-full-set slice",
);
}
// (180) — `T::sorted_unique_missing_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_missing_variant(items)
// { T::sorted_variants().into_iter().find(|&v| !T::occurs_in(v, items)) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_missing_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the miss-band uniqueness bit holds
// the SOLE missing witness is unambiguous, so declaration-order
// and lex-order first-witness sweeps land on THE SAME variant.
// Sibling posture to clause (177) one ORDERING axis over: clause
// (177) pins the declaration-order `Option<Self>` miss-band
// witness-if-unique projection; THIS clause pins the lex-order
// peer AND its coincidence with the declaration-order sibling as
// a TYPED THEOREM the substrate proves once. Sibling posture to
// clause (174) one RETURN-SHAPE axis over: clause (174) pins the
// set-level `bool` miss-band uniqueness bit; this clause pins the
// set-level `Option<Self>` lex-order miss-band witness-when-
// unique projection whose `is_some` bit coincides with that bit
// by the guard construction.
//
// Empty-slice arm at cardinality `>= 2`: `count_missing(&[])`
// reports `T::CARDINALITY >= 2`, `has_unique_missing_variant`
// returns `false`, the guard short-circuits, and the projection
// lands on `None`.
//
// Full-set + doubled-full-set arms: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `>= 1` on
// both fixtures, no variant is missing,
// `has_unique_missing_variant` returns `false`, and the guard
// collapses to `None`.
//
// Single-missing arm at cardinality `>= 2` (LOAD-BEARING `Some`-
// arm catch): on `T::ALL[..T::CARDINALITY - 1]`
// `T::ALL[T::CARDINALITY - 1]` is the SOLE missing witness at
// multiplicity `0`, `has_unique_missing_variant` returns `true`,
// the guard fires, and the lex-order sweep of
// `T::sorted_variants` bypasses every present variant and hits
// `T::ALL[T::CARDINALITY - 1]` at its sole missing entry — the
// SAME variant `T::unique_missing_variant` lands on via the
// declaration-order sweep. The identity
// `sorted_unique_missing_variant == unique_missing_variant` holds
// on this positive fixture BY UNIQUENESS: the sole missing
// witness is the ONLY variant either sweep can find.
//
// Is-some coincidence: on every fixture the projection's
// `is_some` bit MUST equal `T::has_unique_missing_variant`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order miss-band uniqueness-
// gated witness surface every downstream consumer routes through.
assert_eq!(
T::sorted_unique_missing_variant(empty),
T::unique_missing_variant(empty),
"{type_name}: T::sorted_unique_missing_variant(&[]) drifted from T::unique_missing_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; when the miss-band uniqueness bit holds the SOLE missing witness is unambiguous and both sweeps land on THE SAME variant, when the bit falsifies both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_missing_variant(empty).is_some(),
T::has_unique_missing_variant(empty),
"{type_name}: T::sorted_unique_missing_variant(&[]).is_some() drifted from T::has_unique_missing_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_missing_variant(T::ALL),
T::unique_missing_variant(T::ALL),
"{type_name}: T::sorted_unique_missing_variant(T::ALL) drifted from T::unique_missing_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_missing_variant(T::ALL).is_some(),
T::has_unique_missing_variant(T::ALL),
"{type_name}: T::sorted_unique_missing_variant(T::ALL).is_some() drifted from T::has_unique_missing_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_missing_variant(&doubled_full_set),
T::unique_missing_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_missing_variant(&doubled_full_set) drifted from T::unique_missing_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_missing_variant(&doubled_full_set).is_some(),
T::has_unique_missing_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_missing_variant(&doubled_full_set).is_some() drifted from T::has_unique_missing_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
// Single-missing fixture: LOAD-BEARING `Some(T::ALL[T::CARDINALITY - 1])`-
// arm catch on the (equivalence-partition × mult `== 0` ×
// unique-tie × lex-order × `Option<Self>`) corner. On
// `T::ALL[..T::CARDINALITY - 1]` `T::ALL[T::CARDINALITY - 1]`
// sits at count `0` (the SOLE missing witness), every other
// variant sits at count `1`, `has_unique_missing_variant`
// returns `true`, the guard fires, and the lex-order sweep
// of `T::sorted_variants` bypasses every present variant and
// hits `T::ALL[T::CARDINALITY - 1]` at its sole missing
// entry — the SAME variant the declaration-order sweep at
// `T::unique_missing_variant` lands on. The two projections
// return the SAME `Some(T::ALL[T::CARDINALITY - 1])` on this
// positive fixture BY UNIQUENESS of the missing witness.
let sorted_single_missing: ::std::vec::Vec<T> =
T::ALL[..T::CARDINALITY - 1].iter().copied().collect();
assert_eq!(
T::sorted_unique_missing_variant(&sorted_single_missing),
T::unique_missing_variant(&sorted_single_missing),
"{type_name}: T::sorted_unique_missing_variant(&single_missing) drifted from T::unique_missing_variant(&single_missing) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING single-missing positive fixture; when the sole missing witness is unique, declaration-order and lex-order sweeps BOTH land on `Some(T::ALL[T::CARDINALITY - 1])`",
);
assert_eq!(
T::sorted_unique_missing_variant(&sorted_single_missing),
Some(T::ALL[T::CARDINALITY - 1]),
"{type_name}: T::sorted_unique_missing_variant(&single_missing) drifted from `Some(T::ALL[T::CARDINALITY - 1])` at cardinality >= 2 — on `T::ALL[..T::CARDINALITY - 1]` the last-declaration-slot variant is the SOLE missing witness, `count_missing` reports `1`, `has_unique_missing_variant` returns `true`, and the lex-order sweep of T::sorted_variants through `!T::occurs_in` bypasses every present variant and lands at THE unique missing variant",
);
assert_eq!(
T::sorted_unique_missing_variant(&sorted_single_missing).is_some(),
T::has_unique_missing_variant(&sorted_single_missing),
"{type_name}: T::sorted_unique_missing_variant(&single_missing).is_some() drifted from T::has_unique_missing_variant(&single_missing) — the is-some coincidence identity MUST hold on the single-missing fixture",
);
}
// (181) — `T::sorted_unique_repeating_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_repeating_variant(items)
// { T::sorted_variants().into_iter().find(|&v| T::is_repeated_occurrence_of(v, items)) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_repeating_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the strict-repeat uniqueness bit
// holds the SOLE strictly-repeating witness is unambiguous, so
// declaration-order and lex-order first-witness sweeps land on THE
// SAME variant. Sibling posture to clause (172) one ORDERING axis
// over: clause (172) pins the declaration-order `Option<Self>`
// strict-repeat witness-if-unique projection; THIS clause pins the
// lex-order peer AND its coincidence with the declaration-order
// sibling as a TYPED THEOREM the substrate proves once. Sibling
// posture to clause (180) one MULTIPLICITY-BAND axis over: clause
// (180) pins the LEX-ORDER `Option<Self>` miss-band witness-if-
// unique projection (mult `== 0`); THIS clause pins the LEX-ORDER
// `Option<Self>` strict-repeat witness-if-unique projection (mult
// `>= 2`) — the two together bracket the LEX-ORDER `Option<Self>`
// unique-tie sharpening at BOTH EXTREMAL bands of the mult-band
// trichotomy on the equivalence-partition surface.
//
// Empty-slice arm: `T::has_unique_repeating_variant(&[])` collapses
// to `false` via `count_repeating_variants(&[]) == 0 != 1`, the
// guard short-circuits, and the projection lands on `None` before
// the `T::sorted_variants` sweep is consulted.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant pins
// every variant at exactly one position, `count_repeating_variants(T::ALL)`
// reports `0`, `has_unique_repeating_variant(T::ALL)` returns
// `false`, and the guard collapses to `None`.
//
// Doubled-full-set arm at cardinality `>= 2`: the doubled full set
// hits every variant at exactly two positions, EVERY per-target
// multiplicity is `2 >= 2`, `count_repeating_variants` reports
// `T::CARDINALITY >= 2`, `has_unique_repeating_variant` returns
// `false` (multiple witnesses, no unique one), and the guard
// collapses to `None`. At cardinality `== 1` the doubled slice
// `[T::ALL[0], T::ALL[0]]` collapses the strict-repeat count to
// `1`, `has_unique_repeating_variant` returns `true`, and the
// guarded lex-sweep lands on `Some(T::ALL[0])` — the SAME variant
// clause (172)'s declaration-order sweep hits.
//
// Bimodal-triple arm at cardinality `>= 2` (LOAD-BEARING `Some(_)`-
// arm catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]`
// sits at count `2 >= 2` (the SOLE strict-repeat witness),
// `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
// `count_repeating_variants` reports `1`,
// `has_unique_repeating_variant` returns `true`, the guard fires,
// and the lex-order sweep of `T::sorted_variants` bypasses every
// non-repeating variant and hits `T::ALL[0]` at its sole strict-
// repeat entry — the SAME variant clause (172)'s declaration-order
// sweep at `T::unique_repeating_variant` lands on. The identity
// `sorted_unique_repeating_variant == unique_repeating_variant`
// holds on this positive fixture BY UNIQUENESS: the sole strict-
// repeat witness is the ONLY variant either sweep can find.
//
// Is-some coincidence: on every fixture the projection's `is_some`
// bit MUST equal `T::has_unique_repeating_variant`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order strict-repeat uniqueness-
// gated witness surface every downstream consumer routes through.
assert_eq!(
T::sorted_unique_repeating_variant(empty),
T::unique_repeating_variant(empty),
"{type_name}: T::sorted_unique_repeating_variant(&[]) drifted from T::unique_repeating_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; when the strict-repeat uniqueness bit falsifies both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_repeating_variant(empty).is_some(),
T::has_unique_repeating_variant(empty),
"{type_name}: T::sorted_unique_repeating_variant(&[]).is_some() drifted from T::has_unique_repeating_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_repeating_variant(T::ALL),
T::unique_repeating_variant(T::ALL),
"{type_name}: T::sorted_unique_repeating_variant(T::ALL) drifted from T::unique_repeating_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_repeating_variant(T::ALL).is_some(),
T::has_unique_repeating_variant(T::ALL),
"{type_name}: T::sorted_unique_repeating_variant(T::ALL).is_some() drifted from T::has_unique_repeating_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_repeating_variant(&doubled_full_set),
T::unique_repeating_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_repeating_variant(&doubled_full_set) drifted from T::unique_repeating_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice",
);
assert_eq!(
T::sorted_unique_repeating_variant(&doubled_full_set).is_some(),
T::has_unique_repeating_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_repeating_variant(&doubled_full_set).is_some() drifted from T::has_unique_repeating_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[0])`-arm
// catch on the (equivalence-partition × mult `>= 2` ×
// unique-tie × lex-order × `Option<Self>`) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at count
// `2` (the SOLE strict-repeat witness), `T::ALL[1]` at count
// `1`, `T::ALL[2..]` (when present) at count `0`;
// `has_unique_repeating_variant` returns `true`, the guard
// fires, and the lex-order sweep of `T::sorted_variants` finds
// `T::ALL[0]` as the sole strict-repeat entry — the SAME
// variant the declaration-order sweep at
// `T::unique_repeating_variant` lands on. The two projections
// return the SAME `Some(T::ALL[0])` on this positive fixture
// BY UNIQUENESS of the strict-repeat witness.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_repeating_variant(&bimodal_triple),
T::unique_repeating_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_repeating_variant(&bimodal_triple) drifted from T::unique_repeating_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING bimodal-triple positive fixture; when the sole strict-repeat witness is unique, declaration-order and lex-order sweeps BOTH land on `Some(T::ALL[0])`",
);
assert_eq!(
T::sorted_unique_repeating_variant(&bimodal_triple),
Some(T::ALL[0]),
"{type_name}: T::sorted_unique_repeating_variant(&bimodal_triple) drifted from `Some(T::ALL[0])` at cardinality >= 2 — on `[T::ALL[0], T::ALL[0], T::ALL[1]]` T::ALL[0] is the SOLE strict-repeat witness, `count_repeating_variants` reports `1`, `has_unique_repeating_variant` returns `true`, and the lex-order sweep of T::sorted_variants through T::is_repeated_occurrence_of bypasses every non-repeating variant and lands at THE unique strict-repeat witness",
);
assert_eq!(
T::sorted_unique_repeating_variant(&bimodal_triple).is_some(),
T::has_unique_repeating_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_repeating_variant(&bimodal_triple).is_some() drifted from T::has_unique_repeating_variant(&bimodal_triple) — the is-some coincidence identity MUST hold on the bimodal-triple fixture",
);
}
// (182) — `T::sorted_unique_unique_variant(items)` MUST agree with
// the guarded-lex-first-witness body
// `if T::has_unique_unique_variant(items)
// { T::sorted_variants().into_iter().find(|&v| T::is_unique_occurrence_of(v, items)) }
// else { None }` on every canonical slice AND MUST IDENTICALLY EQUAL
// its declaration-order sibling `T::unique_unique_variant` on every
// canonical slice — the ordering-choice-irrelevance identity witnesses
// that WHEN the unique-band uniqueness bit holds the SOLE singleton-
// multiplicity witness is unambiguous, so declaration-order and lex-
// order first-witness sweeps land on THE SAME variant. Sibling posture
// to clauses (180) and (181) one MULTIPLICITY-BAND axis over: (180)
// pins the LEX-ORDER `Option<Self>` miss-band witness-if-unique
// projection (mult `== 0`); (181) pins the LEX-ORDER `Option<Self>`
// strict-repeat witness-if-unique projection (mult `>= 2`); THIS
// clause pins the LEX-ORDER `Option<Self>` unique-band witness-if-
// unique projection (mult `== 1`) — the three together EXHAUSTIVELY
// CLOSE the (set-level × `Option<Self>` × sorted × equivalence-
// partition × mult-band × unique-tie) trichotomy on the LEX-ORDER
// equivalence-partition surface.
//
// Empty-slice arm: `T::has_unique_unique_variant(&[])` collapses to
// `false` via `count_unique_variants(&[]) == 0 != 1`, the guard
// short-circuits, and the projection lands on `None` before the
// `T::sorted_variants` sweep is consulted.
//
// Full-set arm: clause (3)'s pairwise-distinctness invariant pins
// every variant at exactly one position, `count_unique_variants(T::ALL)`
// reports `T::CARDINALITY`, `has_unique_unique_variant(T::ALL)` returns
// `true` iff `T::CARDINALITY == 1` and `false` otherwise; at
// `T::CARDINALITY >= 2` the guard collapses to `None`.
//
// Doubled-full-set arm: the doubled full set hits every variant at
// exactly two positions, no variant sits at multiplicity `1`,
// `count_unique_variants` reports `0`,
// `has_unique_unique_variant` returns `false`, and the guard collapses
// to `None`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING `Some(_)`-arm
// catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2 >= 2`, `T::ALL[1]` at count `1` (the SOLE singleton-
// multiplicity witness), `T::ALL[2..]` at count `0`;
// `count_unique_variants` reports `1`,
// `has_unique_unique_variant` returns `true`, the guard fires, and
// the lex-order sweep of `T::sorted_variants` bypasses every non-
// singleton variant and hits `T::ALL[1]` at its sole singleton entry
// — the SAME variant clause `unique_unique_variant` (declaration-
// order sibling) lands on. The identity
// `sorted_unique_unique_variant == unique_unique_variant` holds on
// this positive fixture BY UNIQUENESS: the sole singleton-multiplicity
// witness is the ONLY variant either sweep can find.
//
// Is-some coincidence: on every fixture the projection's `is_some`
// bit MUST equal `T::has_unique_unique_variant`.
//
// The default trait body threads the guarded-lex-first-witness sweep
// verbatim and satisfies every fixpoint arm + the ordering-choice-
// irrelevance arm for free; the assertion catches a future implementor
// whose override drifts the projection loudly rather than silently
// bifurcating the lex-order unique-band uniqueness-gated witness
// surface every downstream consumer routes through.
assert_eq!(
T::sorted_unique_unique_variant(empty),
T::unique_unique_variant(empty),
"{type_name}: T::sorted_unique_unique_variant(&[]) drifted from T::unique_unique_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_unique_variant(empty).is_some(),
T::has_unique_unique_variant(empty),
"{type_name}: T::sorted_unique_unique_variant(&[]).is_some() drifted from T::has_unique_unique_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_unique_variant(T::ALL),
T::unique_unique_variant(T::ALL),
"{type_name}: T::sorted_unique_unique_variant(T::ALL) drifted from T::unique_unique_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice",
);
assert_eq!(
T::sorted_unique_unique_variant(T::ALL).is_some(),
T::has_unique_unique_variant(T::ALL),
"{type_name}: T::sorted_unique_unique_variant(T::ALL).is_some() drifted from T::has_unique_unique_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_unique_variant(&doubled_full_set),
T::unique_unique_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_unique_variant(&doubled_full_set) drifted from T::unique_unique_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_unique_variant(&doubled_full_set).is_some(),
T::has_unique_unique_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_unique_variant(&doubled_full_set).is_some() drifted from T::has_unique_unique_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[1])`-arm
// catch on the (equivalence-partition × mult `== 1` × unique-
// tie × lex-order × `Option<Self>`) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at count
// `2`, `T::ALL[1]` at count `1` (the SOLE singleton-multiplicity
// witness), `T::ALL[2..]` at count `0`;
// `has_unique_unique_variant` returns `true`, the guard fires,
// and the lex-order sweep of `T::sorted_variants` hits
// `T::ALL[1]` as the sole singleton-multiplicity entry — the
// SAME variant the declaration-order sweep at
// `T::unique_unique_variant` lands on. The two projections
// return the SAME `Some(T::ALL[1])` on this positive fixture BY
// UNIQUENESS of the singleton-multiplicity witness. LOAD-BEARING
// DISJOINT-WITNESS mirror of the sibling clause (181) at the
// SAME fixture: the LEX-ORDER strict-repeat arm lands on
// `Some(T::ALL[0])`; THIS LEX-ORDER unique-band arm lands on
// `Some(T::ALL[1])` — the two POSITIVE `Some(_)` arms of the
// LEX-ORDER equivalence-partition (mult `>= 2`, mult `== 1`)
// uniqueness columns report DIFFERENT witnesses on the same
// slice, pinning the two multiplicity-bands as ORTHOGONAL
// uniqueness axes with disjoint witness projections riding
// DIFFERENT variants of the CANONICAL bimodal triple.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_unique_variant(&bimodal_triple),
T::unique_unique_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_unique_variant(&bimodal_triple) drifted from T::unique_unique_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING bimodal-triple positive fixture; when the sole singleton-multiplicity witness is unique, declaration-order and lex-order sweeps BOTH land on `Some(T::ALL[1])`",
);
assert_eq!(
T::sorted_unique_unique_variant(&bimodal_triple),
Some(T::ALL[1]),
"{type_name}: T::sorted_unique_unique_variant(&bimodal_triple) drifted from `Some(T::ALL[1])` at cardinality >= 3 — on `[T::ALL[0], T::ALL[0], T::ALL[1]]` T::ALL[1] is the SOLE singleton-multiplicity witness, `count_unique_variants` reports `1`, `has_unique_unique_variant` returns `true`, and the lex-order sweep of T::sorted_variants through T::is_unique_occurrence_of bypasses every non-singleton variant and lands at THE unique singleton-multiplicity witness",
);
assert_eq!(
T::sorted_unique_unique_variant(&bimodal_triple).is_some(),
T::has_unique_unique_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_unique_variant(&bimodal_triple).is_some() drifted from T::has_unique_unique_variant(&bimodal_triple) — the is-some coincidence identity MUST hold on the bimodal-triple fixture",
);
}
// (183) — `T::sorted_unique_modal_variant(items)` MUST agree with
// the guarded-lex-first-witness body
// `if T::has_unique_mode(items) { T::sorted_modal_variant(items) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_modal_variant` on
// every canonical slice — the ordering-choice-irrelevance identity
// witnesses that WHEN the modal-uniqueness bit holds the SOLE
// argmax witness is unambiguous, so declaration-order and lex-
// order first-witness sweeps land on THE SAME variant. Sibling
// posture to clauses (180), (181), (182) one SURFACE axis over:
// those three EXHAUSTIVELY CLOSE the LEX-ORDER (Option<Self> ×
// equivalence-partition × mult-band × unique-tie) trichotomy on
// the equivalence-partition surface; THIS clause OPENS the LEX-
// ORDER (Option<Self> × direction × argmax × unique-tie) arm on
// the MODAL-AGGREGATION surface — the peer of clause (182) one
// SURFACE axis over, mirroring the ordering-choice-irrelevance
// identity substrate-proven for the equivalence-partition surface
// onto the modal-aggregation surface's argmax direction anchor.
//
// Empty-slice arm: `count_modal_variants(&[])` reports `0` via
// the empty-slice short-circuit, `has_unique_mode` returns
// `false`, the guard short-circuits, and the projection lands on
// `None` before `sorted_modal_variant`'s own None-at-empty branch
// is consulted.
//
// Full-set arm at cardinality `>= 2`: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `1`,
// `max_variant_count` collapses to `1`, `count_modal_variants`
// reports `T::CARDINALITY >= 2`, `has_unique_mode` returns
// `false`, and the guard collapses to `None`. LOAD-BEARING
// ASYMMETRY against `sorted_modal_variant` which returns
// `Some(T::sorted_first())` on the same slice — the unique-tie
// sharpening SEPARATES the unsharpened lex-order argmax first-
// witness from THIS uniqueness-gated projection at the flat-
// histogram fixpoint.
//
// Doubled-full-set arm at cardinality `>= 2`: every variant is at
// count `2`, `has_unique_mode` returns `false`, and the guard
// collapses to `None`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING
// `Some(_)`-arm catch): on `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[0]` sits at count `2` (the SOLE argmax witness),
// `T::ALL[1]` at count `1`, `T::ALL[2..]` at count `0`;
// `count_modal_variants` reports `1`, `has_unique_mode` returns
// `true`, the guard fires, and the lex-order sweep of
// `T::sorted_variants` hits `T::ALL[0]` at its sole count-`2`
// entry — the SAME variant `T::unique_modal_variant` lands on
// (ordering-choice-irrelevance BY UNIQUENESS). LOAD-BEARING
// DISJOINT-WITNESS mirror of clause (182) at the SAME fixture:
// clause (182) reports `Some(T::ALL[1])` on the LEX-ORDER
// equivalence-partition (mult `== 1`) surface; THIS clause
// reports `Some(T::ALL[0])` on the LEX-ORDER modal-aggregation
// argmax surface — the two POSITIVE `Some(_)` arms of the LEX-
// ORDER uniqueness column on the two orthogonal surfaces report
// DIFFERENT witnesses on the same slice, pinning the two
// surfaces as ORTHOGONAL uniqueness axes.
//
// Is-some coincidence: on every fixture the projection's
// `is_some` bit MUST equal `T::has_unique_mode`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order modal-uniqueness-gated
// witness surface every downstream consumer routes through.
assert_eq!(
T::sorted_unique_modal_variant(empty),
T::unique_modal_variant(empty),
"{type_name}: T::sorted_unique_modal_variant(&[]) drifted from T::unique_modal_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_modal_variant(empty).is_some(),
T::has_unique_mode(empty),
"{type_name}: T::sorted_unique_modal_variant(&[]).is_some() drifted from T::has_unique_mode(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_modal_variant(T::ALL),
T::unique_modal_variant(T::ALL),
"{type_name}: T::sorted_unique_modal_variant(T::ALL) drifted from T::unique_modal_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice",
);
assert_eq!(
T::sorted_unique_modal_variant(T::ALL).is_some(),
T::has_unique_mode(T::ALL),
"{type_name}: T::sorted_unique_modal_variant(T::ALL).is_some() drifted from T::has_unique_mode(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_modal_variant(&doubled_full_set),
T::unique_modal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_modal_variant(&doubled_full_set) drifted from T::unique_modal_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_modal_variant(&doubled_full_set).is_some(),
T::has_unique_mode(&doubled_full_set),
"{type_name}: T::sorted_unique_modal_variant(&doubled_full_set).is_some() drifted from T::has_unique_mode(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `Some(T::ALL[0])`-arm
// catch on the (modal-aggregation × direction × argmax ×
// unique-tie × lex-order × `Option<Self>`) corner. On
// `[T::ALL[0], T::ALL[0], T::ALL[1]]` `T::ALL[0]` sits at
// count `2` (the SOLE argmax witness), `T::ALL[1]` at count
// `1`, `T::ALL[2..]` at count `0`; `has_unique_mode` returns
// `true`, the guard fires, and the lex-order sweep of
// `T::sorted_variants` hits `T::ALL[0]` as the sole argmax
// entry — the SAME variant `T::unique_modal_variant` lands
// on. The two projections return the SAME `Some(T::ALL[0])`
// on this positive fixture BY UNIQUENESS. LOAD-BEARING
// DISJOINT-WITNESS mirror of clause (182) at the SAME
// fixture: clause (182)'s LEX-ORDER unique-band arm lands on
// `Some(T::ALL[1])`; THIS LEX-ORDER argmax arm lands on
// `Some(T::ALL[0])` — the two POSITIVE `Some(_)` arms of
// the LEX-ORDER uniqueness column on the two orthogonal
// surfaces report DIFFERENT witnesses on the same slice.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_modal_variant(&bimodal_triple),
T::unique_modal_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_modal_variant(&bimodal_triple) drifted from T::unique_modal_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING bimodal-triple positive fixture; when the sole argmax witness is unique, declaration-order and lex-order sweeps BOTH land on `Some(T::ALL[0])`",
);
assert_eq!(
T::sorted_unique_modal_variant(&bimodal_triple),
Some(T::ALL[0]),
"{type_name}: T::sorted_unique_modal_variant(&bimodal_triple) drifted from `Some(T::ALL[0])` at cardinality >= 3 — on `[T::ALL[0], T::ALL[0], T::ALL[1]]` T::ALL[0] is the SOLE argmax witness at count 2, `count_modal_variants` reports `1`, `has_unique_mode` returns `true`, and the lex-order sweep of T::sorted_variants through `count == max` bypasses every non-argmax variant and lands at THE unique argmax witness",
);
assert_eq!(
T::sorted_unique_modal_variant(&bimodal_triple).is_some(),
T::has_unique_mode(&bimodal_triple),
"{type_name}: T::sorted_unique_modal_variant(&bimodal_triple).is_some() drifted from T::has_unique_mode(&bimodal_triple) — the is-some coincidence identity MUST hold on the bimodal-triple fixture",
);
}
// (184) — `T::sorted_unique_antimodal_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_antimode(items) { T::sorted_antimodal_variant(items) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_antimodal_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the antimodal-uniqueness bit holds
// the SOLE argmin witness is unambiguous, so declaration-order and
// lex-order first-witness sweeps land on THE SAME variant. Sibling
// posture to clause (183) one DIRECTION axis over: clause (183)
// OPENED the LEX-ORDER (Option<Self> × direction × argmax × unique-
// tie) arm on the MODAL-AGGREGATION surface; THIS clause EXHAUSTIVELY
// CLOSES the (set-level × Option<Self> × statistical-aggregate ×
// direction × ordering × unique-tie) 2×2×2 = 8-corner cube at its
// FINAL corner past the three prior uniqueness-gated arms — the
// argmin-lex peer one DIRECTION axis over from clause (183).
//
// Empty-slice arm: `count_antimodal_variants(&[])` reports `0` via
// the empty-slice short-circuit, `has_unique_antimode` returns
// `false`, the guard short-circuits, and the projection lands on
// `None` before `sorted_antimodal_variant`'s own None-at-empty
// branch is consulted.
//
// Full-set arm at cardinality `>= 2`: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `1`,
// `min_variant_count` collapses to `1`, `count_antimodal_variants`
// reports `T::CARDINALITY >= 2`, `has_unique_antimode` returns
// `false`, and the guard collapses to `None`. LOAD-BEARING ASYMMETRY
// against `sorted_antimodal_variant` which returns
// `Some(T::sorted_first())` on the same slice — the unique-tie
// sharpening SEPARATES the unsharpened lex-order argmin first-
// witness from THIS uniqueness-gated projection at the flat-
// histogram fixpoint.
//
// Doubled-full-set arm at cardinality `>= 2`: every variant is at
// count `2`, `has_unique_antimode` returns `false`, and the guard
// collapses to `None`.
//
// Single-missing arm at cardinality `>= 2` (LOAD-BEARING
// `Some(_)`-arm catch): on `T::ALL[..T::CARDINALITY - 1]`
// `T::ALL[T::CARDINALITY - 1]` sits at count `0` (the SOLE argmin
// witness), every other variant sits at count `1`;
// `count_antimodal_variants` reports `1`, `has_unique_antimode`
// returns `true`, the guard fires, and the lex-order sweep of
// `T::sorted_variants` hits `T::ALL[T::CARDINALITY - 1]` at its
// sole count-`0` entry — the SAME variant `T::unique_antimodal_variant`
// lands on (ordering-choice-irrelevance BY UNIQUENESS). LOAD-BEARING
// DISJOINT-WITNESS mirror of clause (180) at the SAME fixture: the
// LEX-ORDER (mult `== 0`) miss-band arm ALSO lands on
// `Some(T::ALL[T::CARDINALITY - 1])`; the two POSITIVE `Some(_)`
// arms of the LEX-ORDER uniqueness column on the two orthogonal
// surfaces UNIFY at the single-missing witness because argmin-
// count-`0` and missing-multiplicity-`0` COINCIDE on slices where
// `min_variant_count == 0`. The single-missing arm is the LOAD-
// BEARING `Some(_)` catch — every other canonical fixpoint reports
// `None`, so an override that folds onto `None` unconditionally
// passes every other arm silently but bifurcates HERE loudly.
//
// Is-some coincidence: on every fixture the projection's `is_some`
// bit MUST equal `T::has_unique_antimode`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order antimodal-uniqueness-
// gated witness surface every downstream consumer routes through.
assert_eq!(
T::sorted_unique_antimodal_variant(empty),
T::unique_antimodal_variant(empty),
"{type_name}: T::sorted_unique_antimodal_variant(&[]) drifted from T::unique_antimodal_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_antimodal_variant(empty).is_some(),
T::has_unique_antimode(empty),
"{type_name}: T::sorted_unique_antimodal_variant(&[]).is_some() drifted from T::has_unique_antimode(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_antimodal_variant(T::ALL),
T::unique_antimodal_variant(T::ALL),
"{type_name}: T::sorted_unique_antimodal_variant(T::ALL) drifted from T::unique_antimodal_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice",
);
assert_eq!(
T::sorted_unique_antimodal_variant(T::ALL).is_some(),
T::has_unique_antimode(T::ALL),
"{type_name}: T::sorted_unique_antimodal_variant(T::ALL).is_some() drifted from T::has_unique_antimode(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_antimodal_variant(&doubled_full_set),
T::unique_antimodal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_antimodal_variant(&doubled_full_set) drifted from T::unique_antimodal_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice where both projections collapse to `None`",
);
assert_eq!(
T::sorted_unique_antimodal_variant(&doubled_full_set).is_some(),
T::has_unique_antimode(&doubled_full_set),
"{type_name}: T::sorted_unique_antimodal_variant(&doubled_full_set).is_some() drifted from T::has_unique_antimode(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
// Single-missing fixture at cardinality `>= 2`: LOAD-BEARING
// `Some(T::ALL[T::CARDINALITY - 1])`-arm catch on the (modal-
// aggregation × direction × argmin × unique-tie × lex-order ×
// `Option<Self>`) corner. On `T::ALL[..T::CARDINALITY - 1]`
// the omitted last variant sits at count `0` (the SOLE argmin
// witness), every present variant sits at count `1`;
// `count_antimodal_variants` reports `1`, `has_unique_antimode`
// returns `true`, the guard fires, and the lex-order sweep of
// `T::sorted_variants` hits `T::ALL[T::CARDINALITY - 1]` as the
// sole count-`0` entry — the SAME variant the declaration-order
// sweep at `T::unique_antimodal_variant` lands on. The two
// projections return the SAME `Some(T::ALL[T::CARDINALITY -
// 1])` on this positive fixture BY UNIQUENESS. LOAD-BEARING
// DISJOINT-WITNESS mirror of clause (180) at the SAME fixture:
// clause (180)'s LEX-ORDER (mult `== 0`) miss-band arm ALSO
// lands on `Some(T::ALL[T::CARDINALITY - 1])` because argmin-
// count-`0` and missing-multiplicity-`0` UNIFY at exactly the
// omitted variant on slices where `min_variant_count == 0`.
let single_missing: ::std::vec::Vec<T> = T::ALL[..T::CARDINALITY - 1].to_vec();
assert_eq!(
T::sorted_unique_antimodal_variant(&single_missing),
T::unique_antimodal_variant(&single_missing),
"{type_name}: T::sorted_unique_antimodal_variant(&single_missing) drifted from T::unique_antimodal_variant(&single_missing) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING single-missing positive fixture; when the sole argmin witness is unique, declaration-order and lex-order sweeps BOTH land on `Some(T::ALL[T::CARDINALITY - 1])`",
);
assert_eq!(
T::sorted_unique_antimodal_variant(&single_missing),
Some(T::ALL[T::CARDINALITY - 1]),
"{type_name}: T::sorted_unique_antimodal_variant(&single_missing) drifted from `Some(T::ALL[T::CARDINALITY - 1])` at cardinality >= 2 — on `T::ALL[..T::CARDINALITY - 1]` the omitted last variant is the SOLE argmin witness at count 0, `count_antimodal_variants` reports `1`, `has_unique_antimode` returns `true`, and the lex-order sweep of T::sorted_variants through `count == min` bypasses every present variant and lands at THE unique argmin witness",
);
assert_eq!(
T::sorted_unique_antimodal_variant(&single_missing).is_some(),
T::has_unique_antimode(&single_missing),
"{type_name}: T::sorted_unique_antimodal_variant(&single_missing).is_some() drifted from T::has_unique_antimode(&single_missing) — the is-some coincidence identity MUST hold on the single-missing fixture",
);
}
// (185) — `T::sorted_unique_extremal_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_extremal_variant(items) { T::sorted_extremal_variant(items) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_extremal_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the extremal-union uniqueness bit
// holds the SOLE extremal witness is unambiguous, so declaration-
// order and lex-order first-witness sweeps land on THE SAME
// variant. Sibling posture to clause (184) one COMBINATOR axis
// over: clause (184) EXHAUSTIVELY CLOSED the direction-anchored
// (Option<Self> × direction × ordering × unique-tie) 8-corner
// cube at the (argmin, lex) FINAL corner; THIS clause OPENS the
// direction-composition LEX row past the just-closed direction-
// anchored arms at the (union, lex) corner — one COMBINATOR axis
// over from clause (184) AND one ORDERING axis over from clause
// (165) which pinned the (union, declaration) opener.
//
// Empty-slice arm: `count_extremal_variants(&[])` reports `0` via
// the empty-slice short-circuit, `has_unique_extremal_variant`
// returns `false`, the guard short-circuits, and the projection
// lands on `None` before `sorted_extremal_variant`'s own None-at-
// empty branch is consulted.
//
// Full-set arm at cardinality `>= 2`: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `1`, max ==
// min == 1, the union covers all of T::ALL,
// `count_extremal_variants` reports `T::CARDINALITY >= 2`,
// `has_unique_extremal_variant` returns `false`, and the guard
// collapses to `None`. At `T::CARDINALITY == 1` the full-set
// slice collapses to a single variant at max == min == 1,
// `count_extremal_variants` reports `1`,
// `has_unique_extremal_variant` returns `true`, and the guarded
// lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the
// degenerate opener, out of reach of the cardinality-3 stub.
// LOAD-BEARING ASYMMETRY at cardinality `>= 2` against
// `sorted_extremal_variant` which returns `Some(T::sorted_first())`
// on the same slice — the unique-tie sharpening SEPARATES the
// unsharpened lex-order union first-witness from THIS uniqueness-
// gated projection at the flat-histogram fixpoint.
//
// Doubled-full-set arm at cardinality `>= 2`: every variant is at
// count `2`, max == min == 2, `count_extremal_variants` reports
// `T::CARDINALITY >= 2`, `has_unique_extremal_variant` returns
// `false`, and the guard collapses to `None`.
//
// Matching-singleton arm at cardinality `>= 2`: the target hits
// count `1 == max`, every non-target sits at count `0 == min`,
// the argmax band `{v}` (size 1) and the argmin band `T::ALL \
// {v}` (size `T::CARDINALITY - 1 >= 1`) are disjoint, so
// `count_extremal_variants` reports `T::CARDINALITY >= 2`,
// `has_unique_extremal_variant` returns `false`, and the guard
// collapses to `None`. LOAD-BEARING ASYMMETRY against
// `sorted_unique_modal_variant` which returns `Some(v)` on the
// same slice at any cardinality — the direction-composition axis
// SEPARATES the argmax uniqueness-witness corner from THIS union
// uniqueness-witness corner on the matching-singleton fixpoint.
//
// Bimodal-triple arm at cardinality `>= 3`: `T::ALL[0]` at count
// `2 == max`, `T::ALL[1]` at count `1` (strictly interior),
// `T::ALL[2..]` at count `0 == min`, the union carries
// `{T::ALL[0]} ∪ T::ALL[2..]` (disjoint bands),
// `count_extremal_variants` reports `T::CARDINALITY - 1 >= 2`,
// `has_unique_extremal_variant` returns `false`, and the guard
// collapses to `None`.
//
// Is-some coincidence: on every fixture the projection's
// `is_some` bit MUST equal `T::has_unique_extremal_variant`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order extremal-union
// uniqueness-gated witness surface every downstream consumer
// routes through. Note: at cardinality `>= 2` the correct
// answer is `None` on EVERY canonical fixture (the degenerate-
// opener property inherited from clause (165)), so an always-
// `None` override matches truth structurally on the multi-variant
// stub — the structural catch for `None`-drifting overrides sits
// at `T::CARDINALITY == 1` on the full-set arm above. The
// always-`Some(first)` drift catch on the test module reaches
// the `Some(_) != None` bifurcation on every fixture arm.
assert_eq!(
T::sorted_unique_extremal_variant(empty),
T::unique_extremal_variant(empty),
"{type_name}: T::sorted_unique_extremal_variant(&[]) drifted from T::unique_extremal_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_extremal_variant(empty),
None,
"{type_name}: T::sorted_unique_extremal_variant(&[]) drifted from the empty-slice fixpoint None — `has_unique_extremal_variant(&[])` collapses to `false` via `count_extremal_variants(&[]) == 0 != 1`, the guard short-circuits, and the projection lands on `None` before `sorted_extremal_variant`'s own None-at-empty branch is consulted",
);
assert_eq!(
T::sorted_unique_extremal_variant(empty).is_some(),
T::has_unique_extremal_variant(empty),
"{type_name}: T::sorted_unique_extremal_variant(&[]).is_some() drifted from T::has_unique_extremal_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_extremal = T::sorted_unique_extremal_variant(T::ALL);
let expected_full_sorted_unique_extremal = if T::has_unique_extremal_variant(T::ALL) {
T::sorted_extremal_variant(T::ALL)
} else {
None
};
assert_eq!(
full_sorted_unique_extremal, expected_full_sorted_unique_extremal,
"{type_name}: T::sorted_unique_extremal_variant(T::ALL) drifted from the guarded lex-lift `if T::has_unique_extremal_variant(T::ALL) {{ T::sorted_extremal_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `has_unique_extremal_variant` returns `false`, and the guarded lift collapses to `None`; at `T::CARDINALITY == 1` the full-set slice collapses to a single variant at max == min == 1, `has_unique_extremal_variant` returns `true`, and the guarded lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the degenerate opener; a divergent full-set value silently bifurcates the load-bearing structural catch for a `None`-drifting override on cardinality-1 implementors",
);
assert_eq!(
T::sorted_unique_extremal_variant(T::ALL),
T::unique_extremal_variant(T::ALL),
"{type_name}: T::sorted_unique_extremal_variant(T::ALL) drifted from T::unique_extremal_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice",
);
assert_eq!(
T::sorted_unique_extremal_variant(T::ALL).is_some(),
T::has_unique_extremal_variant(T::ALL),
"{type_name}: T::sorted_unique_extremal_variant(T::ALL).is_some() drifted from T::has_unique_extremal_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_extremal = T::sorted_unique_extremal_variant(&doubled_full_set);
let expected_doubled_sorted_unique_extremal =
if T::has_unique_extremal_variant(&doubled_full_set) {
T::sorted_extremal_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_sorted_unique_extremal, expected_doubled_sorted_unique_extremal,
"{type_name}: T::sorted_unique_extremal_variant(&doubled_full_set) drifted from the guarded lex-lift `if T::has_unique_extremal_variant(&doubled_full_set) {{ T::sorted_extremal_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `has_unique_extremal_variant` returns `false` at cardinality `>= 2`, and the guarded lift collapses to `None` (at cardinality `== 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2, so the guarded lift reports `Some(T::ALL[0])`)",
);
assert_eq!(
T::sorted_unique_extremal_variant(&doubled_full_set),
T::unique_extremal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_extremal_variant(&doubled_full_set) drifted from T::unique_extremal_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice",
);
assert_eq!(
T::sorted_unique_extremal_variant(&doubled_full_set).is_some(),
T::has_unique_extremal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_extremal_variant(&doubled_full_set).is_some() drifted from T::has_unique_extremal_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_extremal_variant(&matching_singleton),
None,
"{type_name}: T::sorted_unique_extremal_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; the argmax band {{{target_label:?}}} (size 1) and the argmin band `T::ALL \\ {{{target_label:?}}}` (size `T::CARDINALITY - 1 >= 1`) are disjoint, so `count_extremal_variants` reports `T::CARDINALITY >= 2`, `has_unique_extremal_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (LEX × Option<Self> × direction-composition × union × unique-tie) corner — LOAD-BEARING ASYMMETRY against T::sorted_unique_modal_variant which returns Some({target_label:?}) on the same slice at any cardinality",
target_label = target.label(),
);
assert_eq!(
T::sorted_unique_extremal_variant(&matching_singleton),
T::unique_extremal_variant(&matching_singleton),
"{type_name}: T::sorted_unique_extremal_variant([{target_label:?}]) drifted from T::unique_extremal_variant([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both projections collapse to `None`)",
target_label = target.label(),
);
}
}
if T::CARDINALITY >= 3 {
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_extremal_variant(&bimodal_triple),
None,
"{type_name}: T::sorted_unique_extremal_variant(&bimodal_triple) drifted from `None` — argmax {{T::ALL[0]}} (count 2) disjoint from argmin T::ALL[2..] (count 0), the union carries the two disjoint bands, `count_extremal_variants` reports `T::CARDINALITY - 1 >= 2`, `has_unique_extremal_variant` returns `false`, and the guard collapses to `None`; a `Some(_)` bimodal-triple arm silently bifurcates the disjoint-band uniqueness catch on the LEX-ORDER (Option<Self> × direction-composition × union × unique-tie) corner",
);
assert_eq!(
T::sorted_unique_extremal_variant(&bimodal_triple),
T::unique_extremal_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_extremal_variant(&bimodal_triple) drifted from T::unique_extremal_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture (both projections collapse to `None`)",
);
}
// (186) — `T::sorted_unique_middle_band_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variant(items) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_middle_band_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the middle-band uniqueness bit holds
// the SOLE strict-interior witness is unambiguous, so declaration-
// order and lex-order first-witness sweeps land on THE SAME
// variant. Sibling posture to clause (185) one COMBINATOR axis
// over: clause (185) OPENED the LEX-ORDER direction-composition
// row at the (union, lex) corner; THIS clause CLOSES the complement
// arm past the union arm — one COMBINATOR axis over from clause
// (185) AND one ORDERING axis over from clause (166) which pinned
// the (complement, declaration) opener.
//
// Empty-slice arm: `count_middle_band_variants(&[])` reports `0`
// via the empty-slice short-circuit,
// `has_unique_middle_band_variant` returns `false` (0 != 1), the
// guard short-circuits, and the projection lands on `None` before
// `sorted_middle_band_variant`'s own None-at-empty branch is
// consulted.
//
// Full-set arm at cardinality `>= 2`: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `1`, max ==
// min == 1, NO variant sits strictly between the collapsed
// extremes, `count_middle_band_variants` reports `0`,
// `has_unique_middle_band_variant` returns `false`, and the guard
// collapses to `None`.
//
// Doubled-full-set arm at cardinality `>= 2`: every variant is at
// count `2`, max == min == 2, NO variant sits strictly between,
// `count_middle_band_variants` reports `0`,
// `has_unique_middle_band_variant` returns `false`, and the guard
// collapses to `None`.
//
// Matching-singleton arm at cardinality `>= 2`: the target hits
// count `1 == max`, every non-target sits at count `0 == min`;
// EVERY variant of T::ALL sits AT one of the two extremes, NO
// variant sits strictly between, `count_middle_band_variants`
// reports `0`, `has_unique_middle_band_variant` returns `false`,
// and the guard collapses to `None`.
//
// Bimodal-triple arm at cardinality `>= 3` (LOAD-BEARING
// `Some(T::ALL[1])`-arm catch): on `[T::ALL[0], T::ALL[0],
// T::ALL[1]]` `T::ALL[0]` sits at count `2 == max`, `T::ALL[1]`
// at count `1` STRICTLY between max `2` and min `0` (the SOLE
// strict-interior inhabitant), `T::ALL[2..]` at count `0 == min`;
// `count_middle_band_variants` reports `1`,
// `has_unique_middle_band_variant` returns `true`, the guard
// fires, and `sorted_middle_band_variant`'s lex-order sweep hits
// `T::ALL[1]` on the sole middle-band member. This positive
// fixpoint is the SOLE `Some(_)`-arm on the canonical fixture
// window and LOAD-BEARING SYMMETRY with clause (166) which
// returns the SAME `Some(T::ALL[1])` on the same fixture — the
// ordering-choice axis is provably irrelevant on the LOAD-BEARING
// Some arm.
//
// Is-some coincidence: on every fixture the projection's
// `is_some` bit MUST equal `T::has_unique_middle_band_variant`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order middle-band uniqueness-
// gated witness surface. An override that folds onto `Some(first)`
// unconditionally bifurcates on the empty-slice + full-set +
// doubled-full-set + matching-singleton arms (all correct `None`)
// AND on the bimodal-triple arm whenever `first != T::ALL[1]`
// (correct `Some(T::ALL[1])`); an override that folds onto `None`
// unconditionally bifurcates on the bimodal-triple arm at
// cardinality `>= 3`.
assert_eq!(
T::sorted_unique_middle_band_variant(empty),
T::unique_middle_band_variant(empty),
"{type_name}: T::sorted_unique_middle_band_variant(&[]) drifted from T::unique_middle_band_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_middle_band_variant(empty),
None,
"{type_name}: T::sorted_unique_middle_band_variant(&[]) drifted from the empty-slice fixpoint None — `has_unique_middle_band_variant(&[])` collapses to `false` via `count_middle_band_variants(&[]) == 0 != 1`, the guard short-circuits, and the projection lands on `None` before `sorted_middle_band_variant`'s own None-at-empty branch is consulted",
);
assert_eq!(
T::sorted_unique_middle_band_variant(empty).is_some(),
T::has_unique_middle_band_variant(empty),
"{type_name}: T::sorted_unique_middle_band_variant(&[]).is_some() drifted from T::has_unique_middle_band_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_middle_band = T::sorted_unique_middle_band_variant(T::ALL);
let expected_full_sorted_unique_middle_band = if T::has_unique_middle_band_variant(T::ALL) {
T::sorted_middle_band_variant(T::ALL)
} else {
None
};
assert_eq!(
full_sorted_unique_middle_band, expected_full_sorted_unique_middle_band,
"{type_name}: T::sorted_unique_middle_band_variant(T::ALL) drifted from the guarded lex-lift `if T::has_unique_middle_band_variant(T::ALL) {{ T::sorted_middle_band_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; the flat histogram pins every variant at both extremes via max == min, no strict interior exists, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `None`",
);
assert_eq!(
T::sorted_unique_middle_band_variant(T::ALL),
T::unique_middle_band_variant(T::ALL),
"{type_name}: T::sorted_unique_middle_band_variant(T::ALL) drifted from T::unique_middle_band_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice (both projections collapse to `None`)",
);
assert_eq!(
T::sorted_unique_middle_band_variant(T::ALL).is_some(),
T::has_unique_middle_band_variant(T::ALL),
"{type_name}: T::sorted_unique_middle_band_variant(T::ALL).is_some() drifted from T::has_unique_middle_band_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_middle_band = T::sorted_unique_middle_band_variant(&doubled_full_set);
let expected_doubled_sorted_unique_middle_band =
if T::has_unique_middle_band_variant(&doubled_full_set) {
T::sorted_middle_band_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_sorted_unique_middle_band, expected_doubled_sorted_unique_middle_band,
"{type_name}: T::sorted_unique_middle_band_variant(&doubled_full_set) drifted from the guarded lex-lift `if T::has_unique_middle_band_variant(&doubled_full_set) {{ T::sorted_middle_band_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min, no strict interior exists, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `None`",
);
assert_eq!(
T::sorted_unique_middle_band_variant(&doubled_full_set),
T::unique_middle_band_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_middle_band_variant(&doubled_full_set) drifted from T::unique_middle_band_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice (both projections collapse to `None`)",
);
assert_eq!(
T::sorted_unique_middle_band_variant(&doubled_full_set).is_some(),
T::has_unique_middle_band_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_middle_band_variant(&doubled_full_set).is_some() drifted from T::has_unique_middle_band_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_middle_band_variant(&matching_singleton),
None,
"{type_name}: T::sorted_unique_middle_band_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; EVERY variant of T::ALL sits AT one of the two extremes, NO variant sits strictly between, `count_middle_band_variants` reports `0`, `has_unique_middle_band_variant` returns `false`, and the guard collapses the projection to `None`; a `Some(_)` matching-singleton value at cardinality >= 2 silently bifurcates the matching-singleton fixpoint contract on the (LEX × Option<Self> × direction-composition × complement × unique-tie) corner",
target_label = target.label(),
);
assert_eq!(
T::sorted_unique_middle_band_variant(&matching_singleton),
T::unique_middle_band_variant(&matching_singleton),
"{type_name}: T::sorted_unique_middle_band_variant([{target_label:?}]) drifted from T::unique_middle_band_variant([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both projections collapse to `None`)",
target_label = target.label(),
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE `Some(_)`-arm on
// the (LEX × Option<Self> × direction-composition × complement
// × unique-tie) corner. On `[T::ALL[0], T::ALL[0], T::ALL[1]]`
// `T::ALL[1]` is the SOLE strict-interior witness at count 1
// strictly between max 2 and min 0;
// `has_unique_middle_band_variant` returns `true`, and the
// lex-order first-witness sweep hits `T::ALL[1]`. LOAD-BEARING
// SYMMETRY with clause (166) which returns the SAME
// `Some(T::ALL[1])` on the same fixture — the ordering-choice
// axis is provably irrelevant on the Some arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_middle_band_variant(&bimodal_triple),
Some(T::ALL[1]),
"{type_name}: T::sorted_unique_middle_band_variant(&bimodal_triple) drifted from `Some(T::ALL[1])` — the LOAD-BEARING sole Some-arm on the canonical fixture window; T::ALL[1] is the SOLE strict-interior witness at count 1 strictly between max 2 and min 0, `count_middle_band_variants` reports `1`, `has_unique_middle_band_variant` returns `true`, and the lex-order sweep hits T::ALL[1] on the sole middle-band member",
);
assert_eq!(
T::sorted_unique_middle_band_variant(&bimodal_triple),
T::unique_middle_band_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_middle_band_variant(&bimodal_triple) drifted from T::unique_middle_band_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the LOAD-BEARING bimodal-triple positive fixture (both projections report Some(T::ALL[1]) on a singleton middle-band whose lex- and declaration-order witnesses coincide)",
);
}
// (187) — `T::sorted_unique_bimodal_variant(items)` MUST agree
// with the guarded-lex-first-witness body
// `if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variant(items) }
// else { None }` on every canonical slice AND MUST IDENTICALLY
// EQUAL its declaration-order sibling `T::unique_bimodal_variant`
// on every canonical slice — the ordering-choice-irrelevance
// identity witnesses that WHEN the intersection uniqueness bit
// holds the SOLE bimodal witness is unambiguous, so declaration-
// order and lex-order first-witness sweeps land on THE SAME
// variant. Sibling posture to clause (186) one COMBINATOR axis
// over: clause (186) CLOSED the LEX-ORDER complement arm; THIS
// clause CLOSES the intersection arm past the (union, lex) opener
// clause (185) AND the (complement, lex) closer clause (186) —
// one COMBINATOR axis over from clause (186) AND one ORDERING
// axis over from clause (167) which pinned the (intersection,
// declaration) closer. Together with clauses (165)-(166)-(167)-
// (185)-(186)-(187) this EXHAUSTIVELY CLOSES the (set-level ×
// `Option<Self>` × direction-composition × combinator × ordering
// × unique-tie) 3×2 face at its FINAL SIXTH TILE.
//
// Empty-slice arm: `count_bimodal_variants(&[])` reports `0` via
// the empty-slice short-circuit, `has_unique_bimodal_variant`
// returns `false` (0 != 1), the guard short-circuits, and the
// projection lands on `None` before `sorted_bimodal_variant`'s
// own None-at-empty branch is consulted.
//
// Full-set arm at cardinality `>= 2`: clause (3)'s pairwise-
// distinctness invariant pins every variant at count `1`, max ==
// min == 1, EVERY variant of T::ALL sits at BOTH extremes
// simultaneously via the (max == min) collapse, the intersection
// covers all of T::ALL, `count_bimodal_variants` reports
// `T::CARDINALITY >= 2`, `has_unique_bimodal_variant` returns
// `false`, and the guard collapses to `None`. LOAD-BEARING
// ASYMMETRY at cardinality `>= 2` against `sorted_bimodal_variant`
// which returns `Some(T::sorted_first())` on the same slice — the
// unique-tie sharpening SEPARATES the unsharpened lex-order
// intersection first-witness from THIS uniqueness-gated projection
// at the flat-histogram fixpoint. At `T::CARDINALITY == 1` the
// full-set slice collapses to a single variant at max == min ==
// 1, `count_bimodal_variants` reports `1`,
// `has_unique_bimodal_variant` returns `true`, and the guarded
// lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the
// degenerate closer, out of reach of the cardinality-3 stub.
//
// Doubled-full-set arm at cardinality `>= 2`: every variant is at
// count `2`, max == min == 2, EVERY variant sits at both extremes
// simultaneously, `count_bimodal_variants` reports `T::CARDINALITY
// >= 2`, `has_unique_bimodal_variant` returns `false`, and the
// guard collapses to `None`.
//
// Matching-singleton arm at cardinality `>= 2`: the target hits
// count `1 == max`, every non-target sits at count `0 == min`,
// max != min pins a strict direction split, NO variant hits both
// extremes simultaneously, `count_bimodal_variants` reports `0`,
// `has_unique_bimodal_variant` returns `false`, and the guard
// collapses to `None`.
//
// Bimodal-triple arm at cardinality `>= 3`: `T::ALL[0]` at count
// `2 == max`, `T::ALL[1]` at count `1`, `T::ALL[2..]` at count
// `0 == min`, max != min pins a strict direction split, NO
// variant hits both extremes, `count_bimodal_variants` reports
// `0`, `has_unique_bimodal_variant` returns `false`, and the
// guard collapses to `None`. LOAD-BEARING DISCRIMINATOR from
// clause (186) which reports `Some(T::ALL[1])` on the same
// fixture — the direction-composition axis SEPARATES this
// INTERSECTION degenerate arm from the COMPLEMENT positive arm
// on the shared canonical fixture window at cardinality >= 3.
//
// Is-some coincidence: on every fixture the projection's
// `is_some` bit MUST equal `T::has_unique_bimodal_variant`.
//
// The default trait body threads the guarded-lex-first-witness
// sweep verbatim and satisfies every fixpoint arm + the ordering-
// choice-irrelevance arm for free; the assertion catches a future
// implementor whose override drifts the projection loudly rather
// than silently bifurcating the lex-order intersection uniqueness-
// gated witness surface every downstream consumer routes through.
// Note: at cardinality `>= 2` the correct answer is `None` on
// EVERY canonical fixture (the degenerate-closer property
// inherited from clause (167) via clause (187)'s ordering-choice-
// irrelevance identity), so an always-`None` override matches
// truth structurally on the multi-variant stub — the structural
// catch for `None`-drifting overrides sits at `T::CARDINALITY ==
// 1` on the full-set + doubled-full-set arms above. The always-
// `Some(first)` drift catch on the test module reaches the
// `Some(_) != None` bifurcation on every fixture arm.
assert_eq!(
T::sorted_unique_bimodal_variant(empty),
T::unique_bimodal_variant(empty),
"{type_name}: T::sorted_unique_bimodal_variant(&[]) drifted from T::unique_bimodal_variant(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice; both projections collapse to `None` through the same guard arm",
);
assert_eq!(
T::sorted_unique_bimodal_variant(empty),
None,
"{type_name}: T::sorted_unique_bimodal_variant(&[]) drifted from the empty-slice fixpoint None — `has_unique_bimodal_variant(&[])` collapses to `false` via `count_bimodal_variants(&[]) == 0 != 1`, the guard short-circuits, and the projection lands on `None` before `sorted_bimodal_variant`'s own None-at-empty branch is consulted",
);
assert_eq!(
T::sorted_unique_bimodal_variant(empty).is_some(),
T::has_unique_bimodal_variant(empty),
"{type_name}: T::sorted_unique_bimodal_variant(&[]).is_some() drifted from T::has_unique_bimodal_variant(&[]) — the is-some coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_bimodal = T::sorted_unique_bimodal_variant(T::ALL);
let expected_full_sorted_unique_bimodal = if T::has_unique_bimodal_variant(T::ALL) {
T::sorted_bimodal_variant(T::ALL)
} else {
None
};
assert_eq!(
full_sorted_unique_bimodal, expected_full_sorted_unique_bimodal,
"{type_name}: T::sorted_unique_bimodal_variant(T::ALL) drifted from the guarded lex-lift `if T::has_unique_bimodal_variant(T::ALL) {{ T::sorted_bimodal_variant(T::ALL) }} else {{ None }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY >= 2` the flat histogram pins every variant at both extremes via max == min == 1, `has_unique_bimodal_variant` returns `false`, and the guarded lift collapses to `None`; at `T::CARDINALITY == 1` the full-set slice collapses to a single variant at max == min == 1, `has_unique_bimodal_variant` returns `true`, and the guarded lift reports `Some(T::ALL[0])` — the SOLE `Some(_)` arm of the degenerate closer; a divergent full-set value silently bifurcates the load-bearing structural catch for a `None`-drifting override on cardinality-1 implementors",
);
assert_eq!(
T::sorted_unique_bimodal_variant(T::ALL),
T::unique_bimodal_variant(T::ALL),
"{type_name}: T::sorted_unique_bimodal_variant(T::ALL) drifted from T::unique_bimodal_variant(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set covering slice",
);
assert_eq!(
T::sorted_unique_bimodal_variant(T::ALL).is_some(),
T::has_unique_bimodal_variant(T::ALL),
"{type_name}: T::sorted_unique_bimodal_variant(T::ALL).is_some() drifted from T::has_unique_bimodal_variant(T::ALL) — the is-some coincidence identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_bimodal = T::sorted_unique_bimodal_variant(&doubled_full_set);
let expected_doubled_sorted_unique_bimodal = if T::has_unique_bimodal_variant(&doubled_full_set)
{
T::sorted_bimodal_variant(&doubled_full_set)
} else {
None
};
assert_eq!(
doubled_sorted_unique_bimodal, expected_doubled_sorted_unique_bimodal,
"{type_name}: T::sorted_unique_bimodal_variant(&doubled_full_set) drifted from the guarded lex-lift `if T::has_unique_bimodal_variant(&doubled_full_set) {{ T::sorted_bimodal_variant(&doubled_full_set) }} else {{ None }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint pins every variant at both extremes via max == min == 2, `has_unique_bimodal_variant` returns `false` at cardinality `>= 2`, and the guarded lift collapses to `None` (at cardinality `== 1` the doubled slice `[T::ALL[0], T::ALL[0]]` still collapses to a single variant at max == min == 2, so the guarded lift reports `Some(T::ALL[0])`)",
);
assert_eq!(
T::sorted_unique_bimodal_variant(&doubled_full_set),
T::unique_bimodal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_bimodal_variant(&doubled_full_set) drifted from T::unique_bimodal_variant(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set covering slice",
);
assert_eq!(
T::sorted_unique_bimodal_variant(&doubled_full_set).is_some(),
T::has_unique_bimodal_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_bimodal_variant(&doubled_full_set).is_some() drifted from T::has_unique_bimodal_variant(&doubled_full_set) — the is-some coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_bimodal_variant(&matching_singleton),
None,
"{type_name}: T::sorted_unique_bimodal_variant([{target_label:?}]) drifted from `None` at cardinality >= 2 — the sole position hits {target_label:?} at count `1 == max` while every non-target variant sits at count `0 == min`; max != min pins a strict direction split, NO variant hits both extremes simultaneously, `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant` returns `false`, and the guard collapses the projection to `None`",
target_label = target.label(),
);
assert_eq!(
T::sorted_unique_bimodal_variant(&matching_singleton),
T::unique_bimodal_variant(&matching_singleton),
"{type_name}: T::sorted_unique_bimodal_variant([{target_label:?}]) drifted from T::unique_bimodal_variant([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both projections collapse to `None`)",
target_label = target.label(),
);
}
}
if T::CARDINALITY >= 3 {
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_bimodal_variant(&bimodal_triple),
None,
"{type_name}: T::sorted_unique_bimodal_variant(&bimodal_triple) drifted from `None` — T::ALL[0] at count 2 == max, T::ALL[1] at count 1, T::ALL[2..] at count 0 == min, max != min pins a strict direction split, NO variant hits both extremes, `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant` returns `false`, and the guard collapses to `None`; a `Some(_)` bimodal-triple arm silently bifurcates the disjoint-band uniqueness catch on the LEX-ORDER (Option<Self> × direction-composition × intersection × unique-tie) corner AND the LOAD-BEARING DISCRIMINATION from clause (186) which reports Some(T::ALL[1]) on the SAME fixture",
);
assert_eq!(
T::sorted_unique_bimodal_variant(&bimodal_triple),
T::unique_bimodal_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_bimodal_variant(&bimodal_triple) drifted from T::unique_bimodal_variant(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture (both projections collapse to `None`)",
);
}
// (188) — `T::unique_extremal_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_extremal_variant(items) { T::extremal_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling
// (`bool`, `Option<Self>`) unique-tie union corners one RETURN-SHAPE
// axis over. THIS clause OPENS the (set-level × `Vec<Self>` ×
// direction-composition × union × unique-tie) column past the six
// unsharpened (declaration/lex × union/complement/intersection)
// witness-collection peers one UNIQUE-TIE-SHARPENING axis over on
// the modal-aggregation matrix AND peer to clause (165)
// ([`T::unique_extremal_variant`]) one RETURN-SHAPE axis over.
//
// Degenerate-opener discipline (inherited from clause (165)): at
// `T::CARDINALITY >= 2` the inclusion-exclusion identity pins
// `count_extremal_variants` at either `0` or `>= 2` past the empty
// slice, so `has_unique_extremal_variant` returns `false` and the
// guarded lift collapses to `vec![]` on EVERY canonical fixture.
// The SOLE non-empty arm sits at `T::CARDINALITY == 1` on the full-
// set / doubled-full-set / matching-singleton fixpoints where the
// uniformity-collapse pins the union count at `1`.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length +
// Option-equality + is-empty coincidence identities for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// direction-composition union singleton-or-empty witness surface.
// An override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates the empty-slice arm at `[T::ALL[0]] != []` AND every
// flat-histogram + matching-singleton + bimodal-triple fixpoint arm
// at cardinality `>= 2` at `[T::ALL[0]] != []`.
let empty_unique_extremals = T::unique_extremal_variants(empty);
let expected_empty_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(empty) {
T::extremal_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_extremals, expected_empty_unique_extremals,
"{type_name}: T::unique_extremal_variants(&[]) drifted from the guarded lift `if T::has_unique_extremal_variant(&[]) {{ T::extremal_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_extremal_variant` collapses to `false`, the guarded lift short-circuits to the empty Vec, and `T::extremal_variants(&[])`'s own empty-Vec-at-empty branch is not consulted",
);
assert_eq!(
T::unique_extremal_variants(empty).len(),
usize::from(T::has_unique_extremal_variant(empty)),
"{type_name}: T::unique_extremal_variants(&[]).len() drifted from `T::has_unique_extremal_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_extremal_variants(empty).first().copied(),
T::unique_extremal_variant(empty),
"{type_name}: T::unique_extremal_variants(&[]).first() drifted from T::unique_extremal_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_extremal_variants(empty).is_empty(),
!T::has_unique_extremal_variant(empty),
"{type_name}: T::unique_extremal_variants(&[]).is_empty() drifted from `!T::has_unique_extremal_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_extremals = T::unique_extremal_variants(T::ALL);
let expected_full_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(T::ALL) {
T::extremal_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_extremals, expected_full_unique_extremals,
"{type_name}: T::unique_extremal_variants(T::ALL) drifted from the guarded lift `if T::has_unique_extremal_variant(T::ALL) {{ T::extremal_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; at cardinality >= 2 the flat histogram pins every variant at both extremes, `has_unique_extremal_variant` returns `false`, and the guarded lift collapses to `vec![]`; at `T::CARDINALITY == 1` the single-variant slice pins the union count at `1`, `has_unique_extremal_variant` returns `true`, and the guarded lift reports `vec![T::ALL[0]]` — the SOLE non-empty arm of the degenerate opener",
);
assert_eq!(
T::unique_extremal_variants(T::ALL).len(),
usize::from(T::has_unique_extremal_variant(T::ALL)),
"{type_name}: T::unique_extremal_variants(T::ALL).len() drifted from `T::has_unique_extremal_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_extremal_variants(T::ALL).first().copied(),
T::unique_extremal_variant(T::ALL),
"{type_name}: T::unique_extremal_variants(T::ALL).first() drifted from T::unique_extremal_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_extremals = T::unique_extremal_variants(&doubled_full_set);
let expected_doubled_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(&doubled_full_set) {
T::extremal_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_extremals, expected_doubled_unique_extremals,
"{type_name}: T::unique_extremal_variants(&doubled_full_set) drifted from the guarded lift `if T::has_unique_extremal_variant(&doubled_full_set) {{ T::extremal_variants(&doubled_full_set) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_extremal_variants(&doubled_full_set).len(),
usize::from(T::has_unique_extremal_variant(&doubled_full_set)),
"{type_name}: T::unique_extremal_variants(&doubled_full_set).len() drifted from `T::has_unique_extremal_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_extremal_variants(&doubled_full_set).first().copied(),
T::unique_extremal_variant(&doubled_full_set),
"{type_name}: T::unique_extremal_variants(&doubled_full_set).first() drifted from T::unique_extremal_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_extremal_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_extremal_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — argmax `{{{target_label:?}}}` and argmin `T::ALL \\ {{{target_label:?}}}` are disjoint, `count_extremal_variants` reports `T::CARDINALITY >= 2`, `has_unique_extremal_variant` returns `false`, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::unique_extremal_variants(&matching_singleton).first().copied(),
T::unique_extremal_variant(&matching_singleton),
"{type_name}: T::unique_extremal_variants([{target_label:?}]).first() drifted from T::unique_extremal_variant([{target_label:?}]) — the Option-equality identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both project to None/vec[].first())",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING empty-Vec arm on the
// (`Vec<Self>` × direction-composition × union × unique-tie)
// corner. count_extremal_variants reports T::CARDINALITY - 1 >= 2
// via disjoint argmax + argmin bands, has_unique_extremal_variant
// returns false, and the guard collapses the projection to vec[].
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_extremal_variants(&bimodal_triple),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_extremal_variants(&bimodal_triple) drifted from `vec![]` — count_extremal_variants reports T::CARDINALITY - 1 >= 2, has_unique_extremal_variant returns false, and the guard collapses to vec![]",
);
assert_eq!(
T::unique_extremal_variants(&bimodal_triple).first().copied(),
T::unique_extremal_variant(&bimodal_triple),
"{type_name}: T::unique_extremal_variants(&bimodal_triple).first() drifted from T::unique_extremal_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture (both project to None)",
);
}
// (189) — `T::unique_middle_band_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_middle_band_variant(items) { T::middle_band_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling
// (`bool`, `Option<Self>`) unique-tie complement corners one RETURN-
// SHAPE axis over. THIS clause CLOSES the complement arm of the
// (set-level × `Vec<Self>` × direction-composition × combinator ×
// unique-tie) row past the just-opened UNION arm clause (188)
// ([`T::unique_extremal_variants`]) one COMBINATOR axis over on the
// modal-aggregation matrix, peer to clause (166)
// ([`T::unique_middle_band_variant`]) one RETURN-SHAPE axis over.
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING DISCRIMINATOR
// from clause (188)): at `T::CARDINALITY >= 3` on the canonical
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_middle_band_variants` reports `1` (T::ALL[1] at count 1
// STRICTLY between max 2 and min 0), `has_unique_middle_band_variant`
// returns `true`, and the guarded lift reports `vec![T::ALL[1]]` —
// the SOLE non-empty arm on the multi-variant test-module fixture.
// Clause (188)'s union counterpart collapses to `vec![]` on the same
// fixture; the direction-composition axis SEPARATES the COMPLEMENT
// positive arm from the UNION degenerate arm.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level direction-
// composition complement singleton-or-empty witness surface. An
// override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates the empty-slice + flat-histogram + matching-singleton
// arms at `[T::ALL[0]] != []` AND the bimodal-triple positive arm at
// `[T::ALL[0]] != [T::ALL[1]]` (via LOAD-BEARING mismatch at slot
// `0`). An override that folds onto `vec![]` unconditionally
// bifurcates the bimodal-triple positive arm at `[] != [T::ALL[1]]`.
let empty_unique_middle_bands = T::unique_middle_band_variants(empty);
let expected_empty_unique_middle_bands: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(empty) {
T::middle_band_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_middle_bands, expected_empty_unique_middle_bands,
"{type_name}: T::unique_middle_band_variants(&[]) drifted from the guarded lift `if T::has_unique_middle_band_variant(&[]) {{ T::middle_band_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_middle_band_variant` collapses to `false`, the guarded lift short-circuits to the empty Vec, and `T::middle_band_variants(&[])`'s own empty-Vec-at-empty branch is not consulted",
);
assert_eq!(
T::unique_middle_band_variants(empty).len(),
usize::from(T::has_unique_middle_band_variant(empty)),
"{type_name}: T::unique_middle_band_variants(&[]).len() drifted from `T::has_unique_middle_band_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_middle_band_variants(empty).first().copied(),
T::unique_middle_band_variant(empty),
"{type_name}: T::unique_middle_band_variants(&[]).first() drifted from T::unique_middle_band_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_middle_band_variants(empty).is_empty(),
!T::has_unique_middle_band_variant(empty),
"{type_name}: T::unique_middle_band_variants(&[]).is_empty() drifted from `!T::has_unique_middle_band_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_middle_bands = T::unique_middle_band_variants(T::ALL);
let expected_full_unique_middle_bands: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(T::ALL) {
T::middle_band_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_middle_bands, expected_full_unique_middle_bands,
"{type_name}: T::unique_middle_band_variants(T::ALL) drifted from the guarded lift `if T::has_unique_middle_band_variant(T::ALL) {{ T::middle_band_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; at cardinality >= 2 the flat histogram pins max == min, no strict interior exists, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `vec![]`; at `T::CARDINALITY == 1` the single-variant slice still has NO strict interior (max == min), so the guarded lift STILL collapses to `vec![]` — clause (189)'s strict-interior projection has NO non-empty arm on any flat-histogram fixture",
);
assert_eq!(
T::unique_middle_band_variants(T::ALL).len(),
usize::from(T::has_unique_middle_band_variant(T::ALL)),
"{type_name}: T::unique_middle_band_variants(T::ALL).len() drifted from `T::has_unique_middle_band_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_middle_band_variants(T::ALL).first().copied(),
T::unique_middle_band_variant(T::ALL),
"{type_name}: T::unique_middle_band_variants(T::ALL).first() drifted from T::unique_middle_band_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_middle_bands = T::unique_middle_band_variants(&doubled_full_set);
let expected_doubled_unique_middle_bands: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(&doubled_full_set) {
T::middle_band_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_middle_bands, expected_doubled_unique_middle_bands,
"{type_name}: T::unique_middle_band_variants(&doubled_full_set) drifted from the guarded lift `if T::has_unique_middle_band_variant(&doubled_full_set) {{ T::middle_band_variants(&doubled_full_set) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; the second flat-histogram fixpoint has NO strict interior, `has_unique_middle_band_variant` returns `false`, and the guarded lift collapses to `vec![]`",
);
assert_eq!(
T::unique_middle_band_variants(&doubled_full_set).len(),
usize::from(T::has_unique_middle_band_variant(&doubled_full_set)),
"{type_name}: T::unique_middle_band_variants(&doubled_full_set).len() drifted from `T::has_unique_middle_band_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_middle_band_variants(&doubled_full_set).first().copied(),
T::unique_middle_band_variant(&doubled_full_set),
"{type_name}: T::unique_middle_band_variants(&doubled_full_set).first() drifted from T::unique_middle_band_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_middle_band_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_middle_band_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — the target hits count 1 == max, every non-target sits at count 0 == min, EVERY variant sits AT one of the two extremes, NO variant sits strictly between, `count_middle_band_variants` reports `0`, `has_unique_middle_band_variant` returns `false`, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::unique_middle_band_variants(&matching_singleton).first().copied(),
T::unique_middle_band_variant(&matching_singleton),
"{type_name}: T::unique_middle_band_variants([{target_label:?}]).first() drifted from T::unique_middle_band_variant([{target_label:?}]) — the Option-equality identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both project to None/vec[].first())",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty arm on the
// (`Vec<Self>` × direction-composition × complement × unique-tie)
// corner. count_middle_band_variants reports 1 (T::ALL[1] at
// count 1 STRICTLY between max 2 and min 0),
// has_unique_middle_band_variant returns true, guard fires, and
// the guarded lift reports vec![T::ALL[1]]. LOAD-BEARING
// DISCRIMINATOR from clause (188) which reports vec![] on the
// same fixture — the direction-composition axis SEPARATES the
// COMPLEMENT positive arm from the UNION degenerate arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_positive_witness = [T::ALL[1]];
assert_eq!(
T::unique_middle_band_variants(&bimodal_triple),
bimodal_positive_witness.to_vec(),
"{type_name}: T::unique_middle_band_variants(&bimodal_triple) drifted from `vec![T::ALL[1]]` — count_middle_band_variants reports 1 (T::ALL[1] at count 1 STRICTLY between max 2 and min 0), has_unique_middle_band_variant returns true, guard fires, and the guarded lift lifts middle_band_variants verbatim; a `vec![]` bimodal-triple arm silently bifurcates the SOLE non-empty structural catch on the (Vec<Self> × direction-composition × complement × unique-tie) corner AND the LOAD-BEARING DISCRIMINATION from clause (188) which reports vec![] on the SAME fixture",
);
assert_eq!(
T::unique_middle_band_variants(&bimodal_triple).first().copied(),
T::unique_middle_band_variant(&bimodal_triple),
"{type_name}: T::unique_middle_band_variants(&bimodal_triple).first() drifted from T::unique_middle_band_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture (both project to Some(T::ALL[1]))",
);
}
// (190) — `T::unique_bimodal_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_bimodal_variant(items) { T::bimodal_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling
// (`bool`, `Option<Self>`) unique-tie intersection corners one RETURN-
// SHAPE axis over. THIS clause CLOSES the intersection arm of the
// (set-level × `Vec<Self>` × direction-composition × combinator ×
// unique-tie) row past the just-opened UNION arm clause (188)
// ([`T::unique_extremal_variants`]) AND the just-closed COMPLEMENT
// arm clause (189) ([`T::unique_middle_band_variants`]) one
// COMBINATOR axis over AND EXHAUSTIVELY CLOSES the (`Vec<Self>` ×
// direction-composition × combinator × unique-tie) 3-corner row at
// its FINAL THIRD tile, peer to clause (167)
// ([`T::unique_bimodal_variant`]) one RETURN-SHAPE axis over.
//
// Degenerate-arm discipline (LOAD-BEARING DISCRIMINATOR from clause
// (189)): at `T::CARDINALITY >= 2` the intersection band collapses to
// `vec![]` on EVERY canonical fixture — `has_unique_bimodal_variant`
// holds only when `count_bimodal_variants == 1`, which requires a
// flat histogram AND `T::CARDINALITY == 1` (since a flat histogram on
// `T::CARDINALITY >= 2` variants yields
// `count_bimodal_variants == T::CARDINALITY >= 2 != 1`). Clause
// (189)'s complement counterpart lands a positive arm on the bimodal-
// triple at cardinality `>= 3` (`vec![T::ALL[1]]`); THIS intersection
// arm stays degenerate. The direction-composition axis SEPARATES the
// INTERSECTION degenerate arm from the COMPLEMENT positive arm on the
// shared canonical fixture window.
//
// Singleton-carrier positive fixpoint (LOAD-BEARING `true`-arm catch
// at cardinality `1`): on `T::ALL` at `T::CARDINALITY == 1` the
// single-variant slice sits at count `1`, the histogram is flat
// (max == min == 1), `is_uniform` returns `true`, `bimodal_variants`
// reports `T::ALL.to_vec()` (a length-`1` Vec),
// `count_bimodal_variants` reports `1`, `has_unique_bimodal_variant`
// returns `true`, guard fires, and the guarded lift returns
// `T::ALL.to_vec()` — the SOLE positive arm on THIS corner across
// any test-module carrier. On `doubled_full_set` at
// `T::CARDINALITY == 1` the same collapse fires (flat histogram at
// count `2`), yielding another positive arm at the same cardinality.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level direction-
// composition intersection singleton-or-empty witness surface. An
// override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates every `T::CARDINALITY >= 2` arm at `[T::ALL[0]] != []`.
// An override that folds onto `vec![]` unconditionally bifurcates
// the `T::CARDINALITY == 1` full-set + doubled-full-set positive
// arms at `[] != T::ALL.to_vec()`.
let empty_unique_bimodals = T::unique_bimodal_variants(empty);
let expected_empty_unique_bimodals: ::std::vec::Vec<T> = if T::has_unique_bimodal_variant(empty)
{
T::bimodal_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_bimodals, expected_empty_unique_bimodals,
"{type_name}: T::unique_bimodal_variants(&[]) drifted from the guarded lift `if T::has_unique_bimodal_variant(&[]) {{ T::bimodal_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; the empty-slice guard of `has_unique_bimodal_variant` collapses to `false` via `count_bimodal_variants(&[]) == 0 != 1` (the empty-slice short-circuit on `bimodal_variants` fires BEFORE the vacuous `is_uniform(&[]) == true` collapse leaks into the count), the guarded lift short-circuits to the empty Vec, and `T::bimodal_variants(&[])`'s own empty-Vec-at-empty branch is not consulted",
);
assert_eq!(
T::unique_bimodal_variants(empty).len(),
usize::from(T::has_unique_bimodal_variant(empty)),
"{type_name}: T::unique_bimodal_variants(&[]).len() drifted from `T::has_unique_bimodal_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_bimodal_variants(empty).first().copied(),
T::unique_bimodal_variant(empty),
"{type_name}: T::unique_bimodal_variants(&[]).first() drifted from T::unique_bimodal_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_bimodal_variants(empty).is_empty(),
!T::has_unique_bimodal_variant(empty),
"{type_name}: T::unique_bimodal_variants(&[]).is_empty() drifted from `!T::has_unique_bimodal_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_bimodals = T::unique_bimodal_variants(T::ALL);
let expected_full_unique_bimodals: ::std::vec::Vec<T> = if T::has_unique_bimodal_variant(T::ALL)
{
T::bimodal_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_bimodals, expected_full_unique_bimodals,
"{type_name}: T::unique_bimodal_variants(T::ALL) drifted from the guarded lift `if T::has_unique_bimodal_variant(T::ALL) {{ T::bimodal_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY == 1` the flat histogram at count `1` fires the guard and the lift returns `T::ALL.to_vec()` (the SOLE positive arm at cardinality 1); at `T::CARDINALITY >= 2` the flat histogram at count `1` yields `count_bimodal_variants == T::CARDINALITY >= 2 != 1`, `has_unique_bimodal_variant` returns `false`, and the guarded lift collapses to `vec![]`",
);
assert_eq!(
T::unique_bimodal_variants(T::ALL).len(),
usize::from(T::has_unique_bimodal_variant(T::ALL)),
"{type_name}: T::unique_bimodal_variants(T::ALL).len() drifted from `T::has_unique_bimodal_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_bimodal_variants(T::ALL).first().copied(),
T::unique_bimodal_variant(T::ALL),
"{type_name}: T::unique_bimodal_variants(T::ALL).first() drifted from T::unique_bimodal_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_bimodals = T::unique_bimodal_variants(&doubled_full_set);
let expected_doubled_unique_bimodals: ::std::vec::Vec<T> =
if T::has_unique_bimodal_variant(&doubled_full_set) {
T::bimodal_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_bimodals, expected_doubled_unique_bimodals,
"{type_name}: T::unique_bimodal_variants(&doubled_full_set) drifted from the guarded lift `if T::has_unique_bimodal_variant(&doubled_full_set) {{ T::bimodal_variants(&doubled_full_set) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the doubled-full-set slice; at `T::CARDINALITY == 1` the flat histogram at count `2` fires the guard and the lift returns `T::ALL.to_vec()`; at `T::CARDINALITY >= 2` the flat histogram at count `2` yields `count_bimodal_variants == T::CARDINALITY >= 2 != 1`, the guarded lift collapses to `vec![]`",
);
assert_eq!(
T::unique_bimodal_variants(&doubled_full_set).len(),
usize::from(T::has_unique_bimodal_variant(&doubled_full_set)),
"{type_name}: T::unique_bimodal_variants(&doubled_full_set).len() drifted from `T::has_unique_bimodal_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_bimodal_variants(&doubled_full_set).first().copied(),
T::unique_bimodal_variant(&doubled_full_set),
"{type_name}: T::unique_bimodal_variants(&doubled_full_set).first() drifted from T::unique_bimodal_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_bimodal_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_bimodal_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — the target hits count 1 == max, every non-target sits at count 0 == min, max != min so the histogram is non-flat, `is_uniform` returns `false`, `bimodal_variants` collapses to `Vec::new()`, `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant` returns `false`, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::unique_bimodal_variants(&matching_singleton).first().copied(),
T::unique_bimodal_variant(&matching_singleton),
"{type_name}: T::unique_bimodal_variants([{target_label:?}]).first() drifted from T::unique_bimodal_variant([{target_label:?}]) — the Option-equality identity MUST hold on the matching-singleton fixture at cardinality >= 2 (both project to None/vec[].first())",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `vec![]` arm on the
// (`Vec<Self>` × direction-composition × intersection × unique-
// tie) corner. count_bimodal_variants reports 0 (max 2 != min 0
// collapses the intersection to empty), has_unique_bimodal_variant
// returns false, guard falsifies, and the guarded lift lands on
// `vec![]`. LOAD-BEARING DISCRIMINATOR from clause (189) which
// reports `vec![T::ALL[1]]` on the SAME fixture — the direction-
// composition axis SEPARATES the INTERSECTION degenerate arm from
// the COMPLEMENT positive arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_bimodal_variants(&bimodal_triple),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_bimodal_variants(&bimodal_triple) drifted from `vec![]` — count_bimodal_variants reports 0 (max 2 != min 0 collapses the intersection to empty), has_unique_bimodal_variant returns false, guard falsifies, and the guarded lift lands on `vec![]`; a non-empty bimodal-triple arm silently bifurcates the LOAD-BEARING degenerate catch on the (Vec<Self> × direction-composition × intersection × unique-tie) corner AND its LOAD-BEARING DISCRIMINATION from clause (189) which reports vec![T::ALL[1]] on the SAME fixture",
);
assert_eq!(
T::unique_bimodal_variants(&bimodal_triple).first().copied(),
T::unique_bimodal_variant(&bimodal_triple),
"{type_name}: T::unique_bimodal_variants(&bimodal_triple).first() drifted from T::unique_bimodal_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture (both project to None/vec[].first())",
);
}
// (191) — `T::sorted_unique_extremal_variants(items)` MUST agree with
// both the guarded-lift body
// `if T::has_unique_extremal_variant(items) { T::sorted_extremal_variants(items) } else { vec![] }`
// AND with its declaration-order sibling
// `T::unique_extremal_variants(items)` on every canonical slice — the
// ordering-choice-irrelevance identity holds because the underlying
// uniqueness gate collapses the union band to a length-`1` Vec whose
// sole member is independent of any traversal order. THIS clause OPENS
// the LEX-ORDER (`Vec<Self>` × direction-composition × combinator ×
// unique-tie) row past the just-closed declaration-order trio clauses
// (188) + (189) + (190) one ORDERING axis over on the modal-
// aggregation matrix, peer to clause (188)
// ([`T::unique_extremal_variants`]) one ORDERING axis over.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty + ordering-choice-irrelevance identities for
// free; the assertion catches a future implementor whose override
// drifts the projection loudly rather than silently bifurcating the
// set-level lex-order direction-composition union singleton-or-empty
// witness surface. An override that folds onto `vec![T::ALL[0]]`
// unconditionally bifurcates every canonical fixture arm at
// `[T::ALL[0]] != []` (every fixture at `T::CARDINALITY >= 2` collapses
// the union band to the empty Vec).
let empty_sorted_unique_extremals = T::sorted_unique_extremal_variants(empty);
let expected_empty_sorted_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(empty) {
T::sorted_extremal_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_extremals, expected_empty_sorted_unique_extremals,
"{type_name}: T::sorted_unique_extremal_variants(&[]) drifted from the guarded lift `if T::has_unique_extremal_variant(&[]) {{ T::sorted_extremal_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_extremal_variants(empty),
T::unique_extremal_variants(empty),
"{type_name}: T::sorted_unique_extremal_variants(&[]) drifted from T::unique_extremal_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice (both collapse through the guard arm to vec![])",
);
assert_eq!(
T::sorted_unique_extremal_variants(empty).len(),
usize::from(T::has_unique_extremal_variant(empty)),
"{type_name}: T::sorted_unique_extremal_variants(&[]).len() drifted from `T::has_unique_extremal_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_extremal_variants(empty).first().copied(),
T::sorted_unique_extremal_variant(empty),
"{type_name}: T::sorted_unique_extremal_variants(&[]).first() drifted from T::sorted_unique_extremal_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_extremal_variants(empty).is_empty(),
!T::has_unique_extremal_variant(empty),
"{type_name}: T::sorted_unique_extremal_variants(&[]).is_empty() drifted from `!T::has_unique_extremal_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_extremals = T::sorted_unique_extremal_variants(T::ALL);
let expected_full_sorted_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(T::ALL) {
T::sorted_extremal_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_extremals, expected_full_sorted_unique_extremals,
"{type_name}: T::sorted_unique_extremal_variants(T::ALL) drifted from the guarded lift on the full-set slice",
);
assert_eq!(
T::sorted_unique_extremal_variants(T::ALL),
T::unique_extremal_variants(T::ALL),
"{type_name}: T::sorted_unique_extremal_variants(T::ALL) drifted from T::unique_extremal_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_extremals = T::sorted_unique_extremal_variants(&doubled_full_set);
let expected_doubled_sorted_unique_extremals: ::std::vec::Vec<T> =
if T::has_unique_extremal_variant(&doubled_full_set) {
T::sorted_extremal_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_extremals, expected_doubled_sorted_unique_extremals,
"{type_name}: T::sorted_unique_extremal_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_extremal_variants(&doubled_full_set),
T::unique_extremal_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_extremal_variants(&doubled_full_set) drifted from T::unique_extremal_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_extremal_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_extremal_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — argmax `{{{target_label:?}}}` and argmin `T::ALL \\ {{{target_label:?}}}` are disjoint, count_extremal_variants reports T::CARDINALITY >= 2, has_unique_extremal_variant returns false, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::sorted_unique_extremal_variants(&matching_singleton),
T::unique_extremal_variants(&matching_singleton),
"{type_name}: T::sorted_unique_extremal_variants([{target_label:?}]) drifted from T::unique_extremal_variants([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING empty-Vec arm on the
// (LEX × `Vec<Self>` × direction-composition × union × unique-tie)
// corner. count_extremal_variants reports T::CARDINALITY - 1 >= 2
// via disjoint argmax + argmin bands, has_unique_extremal_variant
// returns false, and the guard collapses the projection to vec[].
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_extremal_variants(&bimodal_triple),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_extremal_variants(&bimodal_triple) drifted from `vec![]` — count_extremal_variants reports T::CARDINALITY - 1 >= 2, has_unique_extremal_variant returns false, and the guard collapses to vec![]",
);
assert_eq!(
T::sorted_unique_extremal_variants(&bimodal_triple),
T::unique_extremal_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_extremal_variants(&bimodal_triple) drifted from T::unique_extremal_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture",
);
}
// (192) — `T::sorted_unique_middle_band_variants(items)` MUST agree with
// both the guarded-lift body
// `if T::has_unique_middle_band_variant(items) { T::sorted_middle_band_variants(items) } else { vec![] }`
// AND with its declaration-order sibling
// `T::unique_middle_band_variants(items)` on every canonical slice — the
// ordering-choice-irrelevance identity holds because the underlying
// uniqueness gate collapses the complement band to a length-`1` Vec whose
// sole member is independent of any traversal order. THIS clause CLOSES
// the complement arm of the LEX-ORDER (`Vec<Self>` × direction-composition
// × combinator × unique-tie) row past the just-opened UNION arm clause
// (191) ([`T::sorted_unique_extremal_variants`]) one COMBINATOR axis over
// on the modal-aggregation matrix, peer to clause (189)
// ([`T::unique_middle_band_variants`]) one ORDERING axis over.
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING DISCRIMINATOR
// from clause (191)): at `T::CARDINALITY >= 3` on the canonical bimodal
// triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`, `count_middle_band_variants`
// reports `1` (T::ALL[1] at count 1 STRICTLY between max 2 and min 0),
// `has_unique_middle_band_variant` returns `true`, and the guarded lift
// reports `vec![T::ALL[1]]` — the SOLE non-empty arm on the multi-variant
// test-module fixture. Clause (191)'s union counterpart collapses to
// `vec![]` on the same fixture; the direction-composition axis SEPARATES
// the COMPLEMENT positive arm from the UNION degenerate arm.
//
// The default trait body threads the boolean-guarded Vec-select verbatim
// and satisfies every fixpoint arm + the length + Option-equality + is-
// empty + ordering-choice-irrelevance identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level lex-order
// direction-composition complement singleton-or-empty witness surface.
// An override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates every empty-slice + flat-histogram + matching-singleton arm
// at `[T::ALL[0]] != []` AND the bimodal-triple positive arm at
// `[T::ALL[0]] != [T::ALL[1]]`. An override that folds onto `vec![]`
// unconditionally bifurcates the bimodal-triple positive arm at
// `[] != [T::ALL[1]]`.
let empty_sorted_unique_middles = T::sorted_unique_middle_band_variants(empty);
let expected_empty_sorted_unique_middles: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(empty) {
T::sorted_middle_band_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_middles, expected_empty_sorted_unique_middles,
"{type_name}: T::sorted_unique_middle_band_variants(&[]) drifted from the guarded lift `if T::has_unique_middle_band_variant(&[]) {{ T::sorted_middle_band_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_middle_band_variants(empty),
T::unique_middle_band_variants(empty),
"{type_name}: T::sorted_unique_middle_band_variants(&[]) drifted from T::unique_middle_band_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice (both collapse through the guard arm to vec![])",
);
assert_eq!(
T::sorted_unique_middle_band_variants(empty).len(),
usize::from(T::has_unique_middle_band_variant(empty)),
"{type_name}: T::sorted_unique_middle_band_variants(&[]).len() drifted from `T::has_unique_middle_band_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_middle_band_variants(empty).first().copied(),
T::sorted_unique_middle_band_variant(empty),
"{type_name}: T::sorted_unique_middle_band_variants(&[]).first() drifted from T::sorted_unique_middle_band_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_middle_band_variants(empty).is_empty(),
!T::has_unique_middle_band_variant(empty),
"{type_name}: T::sorted_unique_middle_band_variants(&[]).is_empty() drifted from `!T::has_unique_middle_band_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_middles = T::sorted_unique_middle_band_variants(T::ALL);
let expected_full_sorted_unique_middles: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(T::ALL) {
T::sorted_middle_band_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_middles, expected_full_sorted_unique_middles,
"{type_name}: T::sorted_unique_middle_band_variants(T::ALL) drifted from the guarded lift on the full-set slice",
);
assert_eq!(
T::sorted_unique_middle_band_variants(T::ALL),
T::unique_middle_band_variants(T::ALL),
"{type_name}: T::sorted_unique_middle_band_variants(T::ALL) drifted from T::unique_middle_band_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_middles = T::sorted_unique_middle_band_variants(&doubled_full_set);
let expected_doubled_sorted_unique_middles: ::std::vec::Vec<T> =
if T::has_unique_middle_band_variant(&doubled_full_set) {
T::sorted_middle_band_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_middles, expected_doubled_sorted_unique_middles,
"{type_name}: T::sorted_unique_middle_band_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_middle_band_variants(&doubled_full_set),
T::unique_middle_band_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_middle_band_variants(&doubled_full_set) drifted from T::unique_middle_band_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_middle_band_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_middle_band_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — the target hits count 1 == max, every non-target sits at count 0 == min, EVERY variant sits AT one of the two extremes, NO variant sits strictly between, count_middle_band_variants reports 0, has_unique_middle_band_variant returns false, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::sorted_unique_middle_band_variants(&matching_singleton),
T::unique_middle_band_variants(&matching_singleton),
"{type_name}: T::sorted_unique_middle_band_variants([{target_label:?}]) drifted from T::unique_middle_band_variants([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty arm on the
// (LEX × `Vec<Self>` × direction-composition × complement × unique-
// tie) corner. count_middle_band_variants reports 1 (T::ALL[1] at
// count 1 STRICTLY between max 2 and min 0),
// has_unique_middle_band_variant returns true, guard fires, and the
// guarded lift lifts sorted_middle_band_variants verbatim. LOAD-
// BEARING DISCRIMINATOR from clause (191) which reports vec![] on
// the SAME fixture — the direction-composition axis SEPARATES the
// COMPLEMENT positive arm from the UNION degenerate arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let bimodal_positive_witness = [T::ALL[1]];
assert_eq!(
T::sorted_unique_middle_band_variants(&bimodal_triple),
bimodal_positive_witness.to_vec(),
"{type_name}: T::sorted_unique_middle_band_variants(&bimodal_triple) drifted from `vec![T::ALL[1]]` — count_middle_band_variants reports 1 (T::ALL[1] at count 1 STRICTLY between max 2 and min 0), has_unique_middle_band_variant returns true, guard fires, and the guarded lift lifts sorted_middle_band_variants verbatim; a `vec![]` bimodal-triple arm silently bifurcates the SOLE non-empty structural catch on the (LEX × Vec<Self> × direction-composition × complement × unique-tie) corner AND the LOAD-BEARING DISCRIMINATION from clause (191) which reports vec![] on the SAME fixture",
);
assert_eq!(
T::sorted_unique_middle_band_variants(&bimodal_triple),
T::unique_middle_band_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_middle_band_variants(&bimodal_triple) drifted from T::unique_middle_band_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture",
);
}
// (193) — `T::sorted_unique_bimodal_variants(items)` MUST agree with both
// the guarded-lift body
// `if T::has_unique_bimodal_variant(items) { T::sorted_bimodal_variants(items) } else { vec![] }`
// AND with its declaration-order sibling
// `T::unique_bimodal_variants(items)` on every canonical slice — the
// ordering-choice-irrelevance identity holds because the underlying
// uniqueness gate collapses the intersection band to a length-`1` Vec
// whose sole member (`T::CARDINALITY == 1` implies a one-element carrier)
// is independent of any traversal order. THIS clause CLOSES the
// intersection arm of the LEX-ORDER (`Vec<Self>` × direction-composition
// × combinator × unique-tie) row past the just-opened UNION arm clause
// (191) ([`T::sorted_unique_extremal_variants`]) AND the just-closed
// COMPLEMENT arm clause (192) ([`T::sorted_unique_middle_band_variants`])
// one COMBINATOR axis over AND EXHAUSTIVELY CLOSES the (set-level ×
// `Vec<Self>` × direction-composition × combinator × ordering × unique-
// tie) 3×2 face at its FINAL SIXTH TILE, peer to clause (190)
// ([`T::unique_bimodal_variants`]) one ORDERING axis over.
//
// Degenerate-arm discipline (LOAD-BEARING DISCRIMINATOR from clause
// (192)): at `T::CARDINALITY >= 2` the intersection band collapses to
// `vec![]` on EVERY canonical fixture — `has_unique_bimodal_variant`
// holds only when `count_bimodal_variants == 1`, which requires a flat
// histogram AND `T::CARDINALITY == 1` (since a flat histogram on
// `T::CARDINALITY >= 2` variants yields `count_bimodal_variants ==
// T::CARDINALITY >= 2 != 1`). Clause (192)'s complement counterpart
// lands a positive arm on the bimodal-triple at cardinality `>= 3`
// (`vec![T::ALL[1]]`); THIS intersection arm stays degenerate. The
// direction-composition axis SEPARATES the INTERSECTION degenerate arm
// from the COMPLEMENT positive arm on the shared canonical fixture
// window.
//
// Singleton-carrier positive fixpoint (LOAD-BEARING `true`-arm catch at
// cardinality `1`): on `T::ALL` at `T::CARDINALITY == 1` the single-
// variant slice sits at count `1`, the histogram is flat
// (max == min == 1), `is_uniform` returns `true`, `sorted_bimodal_variants`
// reports `T::sorted_variants()` (a length-`1` Vec),
// `count_bimodal_variants` reports `1`, `has_unique_bimodal_variant`
// returns `true`, guard fires, and the guarded lift returns
// `T::sorted_variants()` — the SOLE positive arm on THIS corner across
// any test-module carrier. On `doubled_full_set` at `T::CARDINALITY == 1`
// the same collapse fires (flat histogram at count `2`), yielding
// another positive arm at the same cardinality.
//
// The default trait body threads the boolean-guarded Vec-select verbatim
// and satisfies every fixpoint arm + the length + Option-equality + is-
// empty + ordering-choice-irrelevance identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level lex-order
// direction-composition intersection singleton-or-empty witness surface.
// An override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates every `T::CARDINALITY >= 2` arm at `[T::ALL[0]] != []`. An
// override that folds onto `vec![]` unconditionally bifurcates the
// `T::CARDINALITY == 1` full-set + doubled-full-set positive arms at
// `[] != T::sorted_variants()`.
let empty_sorted_unique_bimodals = T::sorted_unique_bimodal_variants(empty);
let expected_empty_sorted_unique_bimodals: ::std::vec::Vec<T> =
if T::has_unique_bimodal_variant(empty) {
T::sorted_bimodal_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_bimodals, expected_empty_sorted_unique_bimodals,
"{type_name}: T::sorted_unique_bimodal_variants(&[]) drifted from the guarded lift `if T::has_unique_bimodal_variant(&[]) {{ T::sorted_bimodal_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(empty),
T::unique_bimodal_variants(empty),
"{type_name}: T::sorted_unique_bimodal_variants(&[]) drifted from T::unique_bimodal_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice (both collapse through the guard arm to vec![])",
);
assert_eq!(
T::sorted_unique_bimodal_variants(empty).len(),
usize::from(T::has_unique_bimodal_variant(empty)),
"{type_name}: T::sorted_unique_bimodal_variants(&[]).len() drifted from `T::has_unique_bimodal_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(empty).first().copied(),
T::sorted_unique_bimodal_variant(empty),
"{type_name}: T::sorted_unique_bimodal_variants(&[]).first() drifted from T::sorted_unique_bimodal_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(empty).is_empty(),
!T::has_unique_bimodal_variant(empty),
"{type_name}: T::sorted_unique_bimodal_variants(&[]).is_empty() drifted from `!T::has_unique_bimodal_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_bimodals = T::sorted_unique_bimodal_variants(T::ALL);
let expected_full_sorted_unique_bimodals: ::std::vec::Vec<T> =
if T::has_unique_bimodal_variant(T::ALL) {
T::sorted_bimodal_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_bimodals, expected_full_sorted_unique_bimodals,
"{type_name}: T::sorted_unique_bimodal_variants(T::ALL) drifted from the guarded lift `if T::has_unique_bimodal_variant(T::ALL) {{ T::sorted_bimodal_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; at `T::CARDINALITY == 1` the flat histogram at count `1` fires the guard and the lift returns `T::sorted_variants()` (the SOLE positive arm at cardinality 1); at `T::CARDINALITY >= 2` the flat histogram at count `1` yields `count_bimodal_variants == T::CARDINALITY >= 2 != 1`, `has_unique_bimodal_variant` returns `false`, and the guarded lift collapses to `vec![]`",
);
assert_eq!(
T::sorted_unique_bimodal_variants(T::ALL),
T::unique_bimodal_variants(T::ALL),
"{type_name}: T::sorted_unique_bimodal_variants(T::ALL) drifted from T::unique_bimodal_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(T::ALL).len(),
usize::from(T::has_unique_bimodal_variant(T::ALL)),
"{type_name}: T::sorted_unique_bimodal_variants(T::ALL).len() drifted from `T::has_unique_bimodal_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(T::ALL).first().copied(),
T::sorted_unique_bimodal_variant(T::ALL),
"{type_name}: T::sorted_unique_bimodal_variants(T::ALL).first() drifted from T::sorted_unique_bimodal_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_bimodals = T::sorted_unique_bimodal_variants(&doubled_full_set);
let expected_doubled_sorted_unique_bimodals: ::std::vec::Vec<T> =
if T::has_unique_bimodal_variant(&doubled_full_set) {
T::sorted_bimodal_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_bimodals, expected_doubled_sorted_unique_bimodals,
"{type_name}: T::sorted_unique_bimodal_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_bimodal_variants(&doubled_full_set),
T::unique_bimodal_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_bimodal_variants(&doubled_full_set) drifted from T::unique_bimodal_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 2 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_bimodal_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_bimodal_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 2 — the target hits count 1 == max, every non-target sits at count 0 == min, max != min so the histogram is non-flat, `is_uniform` returns `false`, `sorted_bimodal_variants` collapses to `Vec::new()`, `count_bimodal_variants` reports `0`, `has_unique_bimodal_variant` returns `false`, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::sorted_unique_bimodal_variants(&matching_singleton),
T::unique_bimodal_variants(&matching_singleton),
"{type_name}: T::sorted_unique_bimodal_variants([{target_label:?}]) drifted from T::unique_bimodal_variants([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on the matching-singleton fixture at cardinality >= 2",
);
}
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING `vec![]` arm on the (LEX ×
// `Vec<Self>` × direction-composition × intersection × unique-tie)
// corner. count_bimodal_variants reports 0 (max 2 != min 0 collapses
// the intersection to empty), has_unique_bimodal_variant returns
// false, guard falsifies, and the guarded lift lands on `vec![]`.
// LOAD-BEARING DISCRIMINATOR from clause (192) which reports
// `vec![T::ALL[1]]` on the SAME fixture — the direction-composition
// axis SEPARATES the INTERSECTION degenerate arm from the COMPLEMENT
// positive arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_bimodal_variants(&bimodal_triple),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_bimodal_variants(&bimodal_triple) drifted from `vec![]` — count_bimodal_variants reports 0 (max 2 != min 0 collapses the intersection to empty), has_unique_bimodal_variant returns false, guard falsifies, and the guarded lift lands on `vec![]`; a non-empty bimodal-triple arm silently bifurcates the LOAD-BEARING degenerate catch on the (LEX × Vec<Self> × direction-composition × intersection × unique-tie) corner AND its LOAD-BEARING DISCRIMINATION from clause (192) which reports vec![T::ALL[1]] on the SAME fixture",
);
assert_eq!(
T::sorted_unique_bimodal_variants(&bimodal_triple),
T::unique_bimodal_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_bimodal_variants(&bimodal_triple) drifted from T::unique_bimodal_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture",
);
}
// (194) — `T::unique_missing_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_missing_variant(items) { T::missing_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling (`bool`, `Option<Self>`)
// unique-tie miss-band corners one RETURN-SHAPE axis over. THIS
// clause OPENS the (set-level × `Vec<Self>` × equivalence-partition ×
// mult-band × unique-tie) column on the EQUIVALENCE-PARTITION surface
// at its (mult `== 0`) miss-band arm — the NEW UNIQUE-TIE-SHARPENING
// axis on the equivalence-partition Vec surface, peer to clause (163)
// ([`T::unique_missing_variant`]) one RETURN-SHAPE axis over AND
// peer to clause (188) ([`T::unique_extremal_variants`]) one SURFACE
// axis over on the modal-aggregation matrix.
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING DISCRIMINATOR
// from clause (188)): at `T::CARDINALITY == 3` on the canonical
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_missing` reports `1` (T::ALL[2] is the sole absent variant
// — `T::ALL[0]` at count 2, `T::ALL[1]` at count 1),
// `has_unique_missing_variant` returns `true`, and the guarded lift
// reports `vec![T::ALL[2]]` — the SOLE non-empty arm on the multi-
// variant test-module fixture at the canonical bimodal cardinality.
// At `T::CARDINALITY >= 4` the miss-band cardinality
// `T::CARDINALITY - 2 >= 2` falsifies the guard and the projection
// collapses to `vec![]`. Clause (188)'s modal-aggregation union
// counterpart collapses to `vec![]` on the same fixture at every
// cardinality; the SURFACE axis SEPARATES this EQUIVALENCE-PARTITION
// miss-band positive arm from the modal-aggregation union degenerate
// arm on the shared canonical fixture window.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level equivalence-
// partition miss-band singleton-or-empty witness surface. An override
// that folds onto `vec![T::ALL[0]]` unconditionally bifurcates the
// empty-slice + full-set + doubled-full-set + matching-singleton arms
// at `[T::ALL[0]] != []` AND the bimodal-triple positive arm at
// `[T::ALL[0]] != [T::ALL[2]]` (via LOAD-BEARING mismatch at slot
// `0`). An override that folds onto `vec![]` unconditionally
// bifurcates the bimodal-triple positive arm at `[] != [T::ALL[2]]`.
let empty_unique_missings = T::unique_missing_variants(empty);
let expected_empty_unique_missings: ::std::vec::Vec<T> = if T::has_unique_missing_variant(empty)
{
T::missing_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_missings, expected_empty_unique_missings,
"{type_name}: T::unique_missing_variants(&[]) drifted from the guarded lift `if T::has_unique_missing_variant(&[]) {{ T::missing_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; at cardinality >= 2 the empty-slice guard reports count_missing == T::CARDINALITY >= 2 so has_unique_missing_variant collapses to false and the guarded lift short-circuits to the empty Vec; at T::CARDINALITY == 1 count_missing reports 1 so the guard holds and the guarded lift returns T::missing_variants(&[]) == T::ALL.to_vec()",
);
assert_eq!(
T::unique_missing_variants(empty).len(),
usize::from(T::has_unique_missing_variant(empty)),
"{type_name}: T::unique_missing_variants(&[]).len() drifted from `T::has_unique_missing_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_missing_variants(empty).first().copied(),
T::unique_missing_variant(empty),
"{type_name}: T::unique_missing_variants(&[]).first() drifted from T::unique_missing_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_missing_variants(empty).is_empty(),
!T::has_unique_missing_variant(empty),
"{type_name}: T::unique_missing_variants(&[]).is_empty() drifted from `!T::has_unique_missing_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_missings = T::unique_missing_variants(T::ALL);
let expected_full_unique_missings: ::std::vec::Vec<T> = if T::has_unique_missing_variant(T::ALL)
{
T::missing_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_missings, expected_full_unique_missings,
"{type_name}: T::unique_missing_variants(T::ALL) drifted from the guarded lift `if T::has_unique_missing_variant(T::ALL) {{ T::missing_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; pairwise-distinctness pins every variant at exactly one position, `count_missing` reports 0, `has_unique_missing_variant` returns false via `0 != 1`, and the guarded lift collapses to `vec![]` UNCONDITIONALLY",
);
assert_eq!(
T::unique_missing_variants(T::ALL).len(),
usize::from(T::has_unique_missing_variant(T::ALL)),
"{type_name}: T::unique_missing_variants(T::ALL).len() drifted from `T::has_unique_missing_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_missing_variants(T::ALL).first().copied(),
T::unique_missing_variant(T::ALL),
"{type_name}: T::unique_missing_variants(T::ALL).first() drifted from T::unique_missing_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_missings = T::unique_missing_variants(&doubled_full_set);
let expected_doubled_unique_missings: ::std::vec::Vec<T> =
if T::has_unique_missing_variant(&doubled_full_set) {
T::missing_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_missings, expected_doubled_unique_missings,
"{type_name}: T::unique_missing_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice — every variant hit twice pins `count_missing == 0`, `has_unique_missing_variant` returns false, and the guarded lift collapses to `vec![]` UNCONDITIONALLY",
);
assert_eq!(
T::unique_missing_variants(&doubled_full_set).len(),
usize::from(T::has_unique_missing_variant(&doubled_full_set)),
"{type_name}: T::unique_missing_variants(&doubled_full_set).len() drifted from `T::has_unique_missing_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY >= 3 {
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_missing_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_missing_variants([{target_label:?}]) drifted from `vec![]` at cardinality >= 3 — the target hits count 1, every non-target sits at count 0, `count_missing` reports T::CARDINALITY - 1 >= 2, `has_unique_missing_variant` returns false, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::unique_missing_variants(&matching_singleton).first().copied(),
T::unique_missing_variant(&matching_singleton),
"{type_name}: T::unique_missing_variants([{target_label:?}]).first() drifted from T::unique_missing_variant([{target_label:?}]) — the Option-equality identity MUST hold on the matching-singleton fixture at cardinality >= 3 (both project to None/vec[].first())",
);
}
}
if T::CARDINALITY == 2 {
// Matching-singleton positive arm at cardinality == 2: the target
// hits count 1, the sole non-target sits at count 0, so
// count_missing reports 1 (EXACTLY), has_unique_missing_variant
// holds, guard fires, and the guarded lift returns
// vec![the-non-target] — the SOLE positive arm on the cardinality-
// 2 test-module carriers (UnquoteForm, ReturnPolicy, …) at the
// matching-singleton fixture. Load-bearing drift catch against an
// override that folds onto `vec![]` on every matching singleton.
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
let expected: ::std::vec::Vec<T> = T::ALL
.iter()
.copied()
.filter(|&v| <T as ClosedSet>::index_of(v) != <T as ClosedSet>::index_of(target))
.collect();
assert_eq!(
T::unique_missing_variants(&matching_singleton),
expected,
"{type_name}: T::unique_missing_variants([{target_label:?}]) drifted from the sole non-target singleton at cardinality == 2 — the target hits count 1, the sole non-target sits at count 0, count_missing reports 1, has_unique_missing_variant holds, and the guarded lift returns vec![the-non-target]; a `vec![]` fold silently bifurcates the LOAD-BEARING positive arm on the cardinality-2 carriers",
);
assert_eq!(
T::unique_missing_variants(&matching_singleton).first().copied(),
T::unique_missing_variant(&matching_singleton),
"{type_name}: T::unique_missing_variants([{target_label:?}]).first() drifted from T::unique_missing_variant([{target_label:?}]) — the Option-equality identity MUST hold on the matching-singleton fixture at cardinality == 2 (both project to Some(the-non-target)/vec![the-non-target].first())",
);
}
}
if T::CARDINALITY == 1 {
// Empty-slice positive arm at cardinality == 1: count_missing
// reports 1 (the sole variant is absent), has_unique_missing_variant
// holds, guard fires, and the guarded lift returns T::ALL.to_vec()
// — the SOLE positive arm on the degenerate cardinality-1 corner.
assert_eq!(
T::unique_missing_variants(empty),
T::ALL.to_vec(),
"{type_name}: T::unique_missing_variants(&[]) drifted from T::ALL.to_vec() at cardinality == 1 — the empty slice pins count_missing at 1, has_unique_missing_variant holds, and the guarded lift returns the singleton vec containing the sole variant",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive arm
// on the (`Vec<Self>` × equivalence-partition × mult `== 0` ×
// unique-tie) corner at the canonical cardinality-3 test-module
// window. count_missing reports 1 (T::ALL[2] absent — T::ALL[0]
// at count 2, T::ALL[1] at count 1), has_unique_missing_variant
// returns true, guard holds, and the guarded lift reports
// vec![T::ALL[2]]. LOAD-BEARING DISCRIMINATOR from clause (188)
// which reports vec![] on the SAME fixture — the SURFACE axis
// SEPARATES the EQUIVALENCE-PARTITION miss-band positive arm
// from the MODAL-AGGREGATION union degenerate arm.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_missing_variants(&bimodal_triple),
::std::vec![T::ALL[2]],
"{type_name}: T::unique_missing_variants(&bimodal_triple) drifted from `vec![T::ALL[2]]` at cardinality == 3 — count_missing reports 1 (T::ALL[2] sole absent), has_unique_missing_variant holds, guard fires, and the guarded lift returns vec![T::ALL[2]]. A `vec![]` fold silently bifurcates the LOAD-BEARING positive arm AND its LOAD-BEARING DISCRIMINATION from clause (188) which reports vec![] on the SAME fixture",
);
assert_eq!(
T::unique_missing_variants(&bimodal_triple).first().copied(),
T::unique_missing_variant(&bimodal_triple),
"{type_name}: T::unique_missing_variants(&bimodal_triple).first() drifted from T::unique_missing_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both project to Some(T::ALL[2]))",
);
}
// (195) — `T::unique_repeating_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_repeating_variant(items) { T::repeating_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling (`bool`, `Option<Self>`)
// unique-tie strict-repeat corners one RETURN-SHAPE axis over. THIS
// clause CLOSES the strict-repeat arm of the (set-level × `Vec<Self>`
// × equivalence-partition × mult-band × unique-tie) row on the
// EQUIVALENCE-PARTITION surface past the just-opened (mult `== 0`)
// miss-band arm clause (194) ([`T::unique_missing_variants`]) one
// MULTIPLICITY-BAND axis over, peer to clause (172)
// ([`T::unique_repeating_variant`]) one RETURN-SHAPE axis over AND
// peer to clause (171) ([`T::has_unique_repeating_variant`]) one
// RETURN-SHAPE axis over.
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING DISCRIMINATOR
// from clause (194)): at `T::CARDINALITY == 3` on the canonical
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_repeating_variants` reports `1` (T::ALL[0] is the SOLE
// strict-repeat witness — `T::ALL[0]` at count 2, `T::ALL[1]` at
// count 1, `T::ALL[2]` at count 0), `has_unique_repeating_variant`
// returns `true`, and the guarded lift reports `vec![T::ALL[0]]` —
// the SOLE non-empty arm on the multi-variant test-module fixture at
// the canonical bimodal cardinality. Clause (194)'s miss-band
// counterpart reports `vec![T::ALL[2]]` on the SAME fixture at the
// SAME cardinality; the MULTIPLICITY-BAND axis SEPARATES this strict-
// repeat positive arm (WITNESS `T::ALL[0]`) from the miss-band
// positive arm (WITNESS `T::ALL[2]`) on the shared canonical fixture
// window — the two POSITIVE arms report DIFFERENT witnesses on the
// same slice, pinning the (mult `>= 2`) and (mult `== 0`) bands as
// orthogonal uniqueness axes with disjoint witness projections.
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level equivalence-
// partition strict-repeat singleton-or-empty witness surface. An
// override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates the empty-slice + full-set + doubled-full-set (at
// cardinality >= 2) + matching-singleton arms at `[T::ALL[0]] != []`;
// an override that folds onto `vec![]` unconditionally bifurcates
// the bimodal-triple positive arm at cardinality `== 3` at
// `[] != [T::ALL[0]]` AND the doubled-full-set arm at cardinality
// `== 1` at `[] != [T::ALL[0]]`.
let empty_unique_repeatings = T::unique_repeating_variants(empty);
let expected_empty_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(empty) {
T::repeating_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_repeatings, expected_empty_unique_repeatings,
"{type_name}: T::unique_repeating_variants(&[]) drifted from the guarded lift `if T::has_unique_repeating_variant(&[]) {{ T::repeating_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; the empty slice hits zero positions, `count_repeating_variants` reports `0`, `has_unique_repeating_variant` collapses to `false` via `0 != 1`, and the guarded lift short-circuits to the empty Vec",
);
assert_eq!(
T::unique_repeating_variants(empty).len(),
usize::from(T::has_unique_repeating_variant(empty)),
"{type_name}: T::unique_repeating_variants(&[]).len() drifted from `T::has_unique_repeating_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_variants(empty).first().copied(),
T::unique_repeating_variant(empty),
"{type_name}: T::unique_repeating_variants(&[]).first() drifted from T::unique_repeating_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_variants(empty).is_empty(),
!T::has_unique_repeating_variant(empty),
"{type_name}: T::unique_repeating_variants(&[]).is_empty() drifted from `!T::has_unique_repeating_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_repeatings = T::unique_repeating_variants(T::ALL);
let expected_full_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(T::ALL) {
T::repeating_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_repeatings, expected_full_unique_repeatings,
"{type_name}: T::unique_repeating_variants(T::ALL) drifted from the guarded lift `if T::has_unique_repeating_variant(T::ALL) {{ T::repeating_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; pairwise-distinctness pins every variant at exactly one position, `count_repeating_variants` reports 0, `has_unique_repeating_variant` returns false via `0 != 1`, and the guarded lift collapses to `vec![]` UNCONDITIONALLY",
);
assert_eq!(
T::unique_repeating_variants(T::ALL).len(),
usize::from(T::has_unique_repeating_variant(T::ALL)),
"{type_name}: T::unique_repeating_variants(T::ALL).len() drifted from `T::has_unique_repeating_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_repeating_variants(T::ALL).first().copied(),
T::unique_repeating_variant(T::ALL),
"{type_name}: T::unique_repeating_variants(T::ALL).first() drifted from T::unique_repeating_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_repeatings = T::unique_repeating_variants(&doubled_full_set);
let expected_doubled_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(&doubled_full_set) {
T::repeating_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_repeatings, expected_doubled_unique_repeatings,
"{type_name}: T::unique_repeating_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice — at cardinality >= 2 every variant hits two positions, `count_repeating_variants` reports `T::CARDINALITY >= 2`, `has_unique_repeating_variant` returns `false`, and the guarded lift collapses to `vec![]`; at cardinality == 1 the doubled slice `[T::ALL[0], T::ALL[0]]` collapses the strict-repeat count to 1, `has_unique_repeating_variant` returns true, and the guarded lift returns vec![T::ALL[0]]",
);
assert_eq!(
T::unique_repeating_variants(&doubled_full_set).len(),
usize::from(T::has_unique_repeating_variant(&doubled_full_set)),
"{type_name}: T::unique_repeating_variants(&doubled_full_set).len() drifted from `T::has_unique_repeating_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_repeating_variants(&doubled_full_set).first().copied(),
T::unique_repeating_variant(&doubled_full_set),
"{type_name}: T::unique_repeating_variants(&doubled_full_set).first() drifted from T::unique_repeating_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::unique_repeating_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::unique_repeating_variants([{target_label:?}]) drifted from `vec![]` on every matching singleton — the target hits count 1, every non-target sits at count 0, `count_repeating_variants` reports 0, `has_unique_repeating_variant` returns false, and the guard collapses the projection to `vec![]`",
);
assert_eq!(
T::unique_repeating_variants(&matching_singleton).first().copied(),
T::unique_repeating_variant(&matching_singleton),
"{type_name}: T::unique_repeating_variants([{target_label:?}]).first() drifted from T::unique_repeating_variant([{target_label:?}]) — the Option-equality identity MUST hold on every matching singleton (both project to None/vec[].first())",
);
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive arm
// on the (`Vec<Self>` × equivalence-partition × mult `>= 2` ×
// unique-tie) corner at the canonical cardinality-3 test-module
// window. `count_repeating_variants` reports 1 (T::ALL[0] the
// SOLE strict-repeat witness — T::ALL[0] at count 2, T::ALL[1]
// at count 1, T::ALL[2..] at count 0),
// `has_unique_repeating_variant` returns true, guard holds, and
// the guarded lift reports vec![T::ALL[0]]. LOAD-BEARING
// DISCRIMINATOR from clause (194) which reports vec![T::ALL[2]]
// on the SAME fixture — the MULTIPLICITY-BAND axis SEPARATES the
// (mult `>= 2`) strict-repeat positive arm (WITNESS T::ALL[0])
// from the (mult `== 0`) miss-band positive arm (WITNESS
// T::ALL[2]): the two POSITIVE arms report DIFFERENT witnesses,
// pinning the strict-repeat and miss bands as orthogonal
// uniqueness axes on the equivalence-partition surface.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_repeating_variants(&bimodal_triple),
::std::vec![T::ALL[0]],
"{type_name}: T::unique_repeating_variants(&bimodal_triple) drifted from `vec![T::ALL[0]]` at cardinality >= 3 — count_repeating_variants reports 1 (T::ALL[0] the SOLE strict-repeat witness), has_unique_repeating_variant holds, guard fires, and the guarded lift returns vec![T::ALL[0]]. A `vec![]` fold silently bifurcates the LOAD-BEARING positive arm AND its LOAD-BEARING DISCRIMINATION from clause (194) which reports vec![T::ALL[2]] on the SAME fixture — the two POSITIVE arms report DIFFERENT witnesses on the same slice",
);
assert_eq!(
T::unique_repeating_variants(&bimodal_triple).first().copied(),
T::unique_repeating_variant(&bimodal_triple),
"{type_name}: T::unique_repeating_variants(&bimodal_triple).first() drifted from T::unique_repeating_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality >= 3 (both project to Some(T::ALL[0]))",
);
}
if T::CARDINALITY == 1 {
// Doubled-full-set positive arm at cardinality == 1: the doubled
// slice `[T::ALL[0], T::ALL[0]]` puts T::ALL[0] at count 2,
// `count_repeating_variants` reports 1, has_unique_repeating_variant
// holds, guard fires, and the guarded lift returns
// vec![T::ALL[0]] — the SOLE positive arm on the degenerate
// cardinality-1 corner of the doubled-full-set fixture.
assert_eq!(
T::unique_repeating_variants(&doubled_full_set),
T::ALL.to_vec(),
"{type_name}: T::unique_repeating_variants(&doubled_full_set) drifted from T::ALL.to_vec() at cardinality == 1 — the doubled slice puts the sole variant at count 2, count_repeating_variants reports 1, has_unique_repeating_variant holds, and the guarded lift returns the singleton vec containing the sole variant",
);
}
// (196) — `T::unique_unique_variants(items)` MUST agree with the
// guarded-lift body
// `if T::has_unique_unique_variant(items) { T::unique_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin length + first-element +
// is-empty coincidences against the sibling (`bool`, `Option<Self>`)
// unique-tie unique-band corners one RETURN-SHAPE axis over. THIS
// clause EXHAUSTIVELY CLOSES the (mult `== 1`) middle arm of the
// (set-level × `Vec<Self>` × equivalence-partition × mult-band ×
// unique-tie) 3-corner row on the EQUIVALENCE-PARTITION surface AT
// ITS FINAL THIRD TILE past clause (194) ([`T::unique_missing_variants`],
// mult `== 0`) AND clause (195) ([`T::unique_repeating_variants`],
// mult `>= 2`) one MULTIPLICITY-BAND axis over, peer to
// [`T::unique_unique_variant`] (`Option<Self>`) AND
// [`T::has_unique_unique_variant`] (`bool`) one RETURN-SHAPE axis
// over.
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING TRICHOTOMY
// DISCRIMINATOR from clauses (194) + (195)): at `T::CARDINALITY == 3`
// on the canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_unique_variants` reports `1` (T::ALL[1] is the SOLE unique-
// band witness — T::ALL[0] at count 2, T::ALL[1] at count 1,
// T::ALL[2] at count 0), `has_unique_unique_variant` returns `true`,
// and the guarded lift reports `vec![T::ALL[1]]` — the LOAD-BEARING
// SOLE non-empty positive arm on the multi-variant fixture.
// Clauses (194) + (195) + THIS clause report THREE DIFFERENT
// witnesses on the SAME fixture (`T::ALL[2]`, `T::ALL[0]`,
// `T::ALL[1]` respectively); the MULTIPLICITY-BAND axis
// EXHAUSTIVELY PARTITIONS the three positive arms as orthogonal
// uniqueness corners with disjoint witness projections riding
// DIFFERENT variants of the canonical bimodal triple.
//
// Matching-singleton positive-arm discipline (LOAD-BEARING NON-EMPTY
// DEGENERATE ARM distinct from clauses (194) + (195)): on every
// matching singleton `[v]`, the target hits count 1 (the SOLE unique-
// band witness), every non-target sits at count 0, `count_unique_variants`
// reports 1, `has_unique_unique_variant` holds, and the guarded lift
// reports `vec![v]` — distinct from clause (195) which collapses to
// `vec![]` on every matching singleton AND from clause (194) whose
// singleton behavior is CARDINALITY-dependent (vec![] at
// CARDINALITY != 2; vec![the sole absent variant] at CARDINALITY
// == 2).
//
// The default trait body threads the boolean-guarded Vec-select
// verbatim and satisfies every fixpoint arm + the length + Option-
// equality + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level equivalence-
// partition unique-band singleton-or-empty witness surface. An
// override that folds onto `vec![]` unconditionally bifurcates the
// matching-singleton positive arms at `[] != [v]` AND the bimodal-
// triple positive arm at cardinality >= 3 at `[] != [T::ALL[1]]`
// AND the full-set positive arm at cardinality == 1 at
// `[] != [T::ALL[0]]`; an override that folds onto `vec![T::ALL[0]]`
// unconditionally bifurcates the empty-slice + doubled-full-set (at
// cardinality >= 2) + full-set (at cardinality >= 2) arms at
// `[T::ALL[0]] != []`.
let empty_unique_uniques = T::unique_unique_variants(empty);
let expected_empty_unique_uniques: ::std::vec::Vec<T> = if T::has_unique_unique_variant(empty) {
T::unique_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_unique_uniques, expected_empty_unique_uniques,
"{type_name}: T::unique_unique_variants(&[]) drifted from the guarded lift `if T::has_unique_unique_variant(&[]) {{ T::unique_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice; the empty slice hits zero positions, `count_unique_variants` reports 0, `has_unique_unique_variant` collapses to false via `0 != 1`, and the guarded lift short-circuits to the empty Vec",
);
assert_eq!(
T::unique_unique_variants(empty).len(),
usize::from(T::has_unique_unique_variant(empty)),
"{type_name}: T::unique_unique_variants(&[]).len() drifted from `T::has_unique_unique_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_variants(empty).first().copied(),
T::unique_unique_variant(empty),
"{type_name}: T::unique_unique_variants(&[]).first() drifted from T::unique_unique_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_variants(empty).is_empty(),
!T::has_unique_unique_variant(empty),
"{type_name}: T::unique_unique_variants(&[]).is_empty() drifted from `!T::has_unique_unique_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_uniques = T::unique_unique_variants(T::ALL);
let expected_full_unique_uniques: ::std::vec::Vec<T> = if T::has_unique_unique_variant(T::ALL) {
T::unique_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_unique_uniques, expected_full_unique_uniques,
"{type_name}: T::unique_unique_variants(T::ALL) drifted from the guarded lift `if T::has_unique_unique_variant(T::ALL) {{ T::unique_variants(T::ALL) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the full-set slice; pairwise-distinctness pins every variant at exactly one position, count_unique_variants reports T::CARDINALITY, has_unique_unique_variant holds EXACTLY when T::CARDINALITY == 1 (guarded lift returns vec![T::ALL[0]]) else falsifies (guarded lift collapses to vec![])",
);
assert_eq!(
T::unique_unique_variants(T::ALL).len(),
usize::from(T::has_unique_unique_variant(T::ALL)),
"{type_name}: T::unique_unique_variants(T::ALL).len() drifted from `T::has_unique_unique_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::unique_unique_variants(T::ALL).first().copied(),
T::unique_unique_variant(T::ALL),
"{type_name}: T::unique_unique_variants(T::ALL).first() drifted from T::unique_unique_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_unique_uniques = T::unique_unique_variants(&doubled_full_set);
let expected_doubled_unique_uniques: ::std::vec::Vec<T> =
if T::has_unique_unique_variant(&doubled_full_set) {
T::unique_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_unique_uniques, expected_doubled_unique_uniques,
"{type_name}: T::unique_unique_variants(&doubled_full_set) drifted from the guarded lift on the doubled-full-set slice — every variant hits two positions, count_unique_variants reports 0, has_unique_unique_variant returns false via `0 != 1`, and the guarded lift collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::unique_unique_variants(&doubled_full_set).len(),
usize::from(T::has_unique_unique_variant(&doubled_full_set)),
"{type_name}: T::unique_unique_variants(&doubled_full_set).len() drifted from `T::has_unique_unique_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_unique_variants(&doubled_full_set).first().copied(),
T::unique_unique_variant(&doubled_full_set),
"{type_name}: T::unique_unique_variants(&doubled_full_set).first() drifted from T::unique_unique_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
// Matching-singleton POSITIVE arm: the target hits count 1 (the
// SOLE unique-band witness), every non-target sits at count 0,
// count_unique_variants reports 1, has_unique_unique_variant
// holds, and the guarded lift returns vec![target]. LOAD-BEARING
// NON-EMPTY DEGENERATE arm — distinct from clause (195) which
// collapses to vec![] on every matching singleton.
assert_eq!(
T::unique_unique_variants(&matching_singleton),
::std::vec![target],
"{type_name}: T::unique_unique_variants([{target_label:?}]) drifted from vec![{target_label:?}] on every matching singleton — the target hits count 1 (SOLE unique-band witness), count_unique_variants reports 1, has_unique_unique_variant holds, and the guarded lift returns the singleton vec containing the target",
);
assert_eq!(
T::unique_unique_variants(&matching_singleton).first().copied(),
T::unique_unique_variant(&matching_singleton),
"{type_name}: T::unique_unique_variants([{target_label:?}]).first() drifted from T::unique_unique_variant([{target_label:?}]) — the Option-equality identity MUST hold on every matching singleton",
);
}
if T::CARDINALITY >= 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty positive
// arm on the (`Vec<Self>` × equivalence-partition × mult `== 1`
// × unique-tie) corner at the canonical cardinality-3 test-
// module window. count_unique_variants reports 1 (T::ALL[1] the
// SOLE unique-band witness — T::ALL[0] at count 2, T::ALL[1] at
// count 1, T::ALL[2..] at count 0), has_unique_unique_variant
// returns true, guard holds, and the guarded lift reports
// vec![T::ALL[1]]. LOAD-BEARING TRICHOTOMY DISCRIMINATOR from
// clauses (194) + (195) which report vec![T::ALL[2]] +
// vec![T::ALL[0]] on the SAME fixture — the MULTIPLICITY-BAND
// axis EXHAUSTIVELY PARTITIONS the three positive arms at
// THREE DIFFERENT witnesses.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_unique_variants(&bimodal_triple),
::std::vec![T::ALL[1]],
"{type_name}: T::unique_unique_variants(&bimodal_triple) drifted from `vec![T::ALL[1]]` at cardinality >= 3 — count_unique_variants reports 1 (T::ALL[1] the SOLE unique-band witness), has_unique_unique_variant holds, guard fires, and the guarded lift returns vec![T::ALL[1]]. A `vec![]` fold silently bifurcates the LOAD-BEARING positive arm AND its LOAD-BEARING TRICHOTOMY DISCRIMINATION from clauses (194) + (195) which report vec![T::ALL[2]] + vec![T::ALL[0]] on the SAME fixture",
);
assert_eq!(
T::unique_unique_variants(&bimodal_triple).first().copied(),
T::unique_unique_variant(&bimodal_triple),
"{type_name}: T::unique_unique_variants(&bimodal_triple).first() drifted from T::unique_unique_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality >= 3 (both project to Some(T::ALL[1]))",
);
}
// (197) — `T::sorted_unique_missing_variants(items)` MUST agree
// with the guarded-lift body
// `if T::has_unique_missing_variant(items) { T::sorted_missing_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin the ORDERING-CHOICE-
// IRRELEVANCE identity
// `T::sorted_unique_missing_variants(items) == T::unique_missing_variants(items)`
// (the sole absent variant, if unique, is the SAME across
// declaration and lex sweep-orders — uniqueness pins the witness
// before any ordering choice is consulted). THIS clause OPENS the
// LEX-ORDER (`Vec<Self>` × equivalence-partition × mult-band ×
// unique-tie) row past the just-closed declaration-order trio
// (clauses (194) + (195) + (196)) one ORDERING axis over on the
// EQUIVALENCE-PARTITION surface at its (mult `== 0`) miss-band arm,
// peer to clause (194) ([`T::unique_missing_variants`]) one
// ORDERING axis over AND peer to
// [`T::sorted_unique_missing_variant`] one RETURN-SHAPE axis over.
//
// Bimodal-triple positive-arm discipline: at `T::CARDINALITY == 3`
// on the canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_missing_variants` reports `1` (T::ALL[2] the SOLE absent
// witness — T::ALL[0] at count 2, T::ALL[1] at count 1, T::ALL[2]
// at count 0), `has_unique_missing_variant` returns `true`, guard
// fires, and the guarded lex-lift reports `vec![T::ALL[2]]` — the
// SAME sole absent witness that clause (194)'s declaration-order
// sibling reports on the SAME fixture, pinning the ordering-choice-
// irrelevance identity as a TYPED THEOREM at the canonical
// bimodal-triple window.
//
// The default trait body threads the boolean-guarded Vec-select
// over [`Self::sorted_missing_variants`] verbatim and satisfies
// every fixpoint arm + the length + Option-equality + is-empty +
// ordering-choice-irrelevance coincidence identities for free; the
// assertion catches a future implementor whose override drifts the
// projection loudly rather than silently bifurcating the set-level
// equivalence-partition miss-band lex-order singleton-or-empty
// witness surface. An override that folds onto `vec![T::ALL[0]]`
// unconditionally bifurcates the empty-slice (at cardinality != 2)
// + full-set + doubled-full-set arms at `[T::ALL[0]] != []`; an
// override that folds onto `vec![]` unconditionally bifurcates the
// bimodal-triple positive arm at cardinality == 3 at
// `[] != [T::ALL[2]]`.
let empty_sorted_unique_missings = T::sorted_unique_missing_variants(empty);
let expected_empty_sorted_unique_missings: ::std::vec::Vec<T> =
if T::has_unique_missing_variant(empty) {
T::sorted_missing_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_missings, expected_empty_sorted_unique_missings,
"{type_name}: T::sorted_unique_missing_variants(&[]) drifted from the guarded lex-lift `if T::has_unique_missing_variant(&[]) {{ T::sorted_missing_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_missing_variants(empty),
T::unique_missing_variants(empty),
"{type_name}: T::sorted_unique_missing_variants(&[]) drifted from T::unique_missing_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_missing_variants(empty).len(),
usize::from(T::has_unique_missing_variant(empty)),
"{type_name}: T::sorted_unique_missing_variants(&[]).len() drifted from `T::has_unique_missing_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_missing_variants(empty).first().copied(),
T::sorted_unique_missing_variant(empty),
"{type_name}: T::sorted_unique_missing_variants(&[]).first() drifted from T::sorted_unique_missing_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_missing_variants(empty).is_empty(),
!T::has_unique_missing_variant(empty),
"{type_name}: T::sorted_unique_missing_variants(&[]).is_empty() drifted from `!T::has_unique_missing_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_missings = T::sorted_unique_missing_variants(T::ALL);
let expected_full_sorted_unique_missings: ::std::vec::Vec<T> =
if T::has_unique_missing_variant(T::ALL) {
T::sorted_missing_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_missings, expected_full_sorted_unique_missings,
"{type_name}: T::sorted_unique_missing_variants(T::ALL) drifted from the guarded lex-lift on the full-set slice — pairwise-distinctness pins every variant at exactly one position, count_missing_variants reports 0, has_unique_missing_variant returns false via `0 != 1`, and the guarded lex-lift collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::sorted_unique_missing_variants(T::ALL),
T::unique_missing_variants(T::ALL),
"{type_name}: T::sorted_unique_missing_variants(T::ALL) drifted from T::unique_missing_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_missing_variants(T::ALL).len(),
usize::from(T::has_unique_missing_variant(T::ALL)),
"{type_name}: T::sorted_unique_missing_variants(T::ALL).len() drifted from `T::has_unique_missing_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_missing_variants(T::ALL).first().copied(),
T::sorted_unique_missing_variant(T::ALL),
"{type_name}: T::sorted_unique_missing_variants(T::ALL).first() drifted from T::sorted_unique_missing_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_missings = T::sorted_unique_missing_variants(&doubled_full_set);
let expected_doubled_sorted_unique_missings: ::std::vec::Vec<T> =
if T::has_unique_missing_variant(&doubled_full_set) {
T::sorted_missing_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_missings, expected_doubled_sorted_unique_missings,
"{type_name}: T::sorted_unique_missing_variants(&doubled_full_set) drifted from the guarded lex-lift on the doubled-full-set slice — every variant hits at least one position, count_missing_variants reports 0, has_unique_missing_variant returns false, and the guarded lex-lift collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::sorted_unique_missing_variants(&doubled_full_set),
T::unique_missing_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_missing_variants(&doubled_full_set) drifted from T::unique_missing_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_missing_variants(&doubled_full_set).len(),
usize::from(T::has_unique_missing_variant(&doubled_full_set)),
"{type_name}: T::sorted_unique_missing_variants(&doubled_full_set).len() drifted from `T::has_unique_missing_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_missing_variants(&doubled_full_set).first().copied(),
T::sorted_unique_missing_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_missing_variants(&doubled_full_set).first() drifted from T::sorted_unique_missing_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty positive
// arm on the (`Vec<Self>` × sorted × equivalence-partition ×
// mult `== 0` × unique-tie) corner at the canonical
// cardinality-3 test-module window. count_missing_variants
// reports 1 (T::ALL[2] the SOLE absent witness — T::ALL[0] at
// count 2, T::ALL[1] at count 1, T::ALL[2] at count 0),
// has_unique_missing_variant returns true, guard fires, and
// the guarded lex-lift returns vec![T::ALL[2]] — the SAME
// witness clause (194)'s declaration-order sibling reports on
// the SAME fixture (ordering-choice-irrelevance in action).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_missing_variants(&bimodal_triple),
::std::vec![T::ALL[2]],
"{type_name}: T::sorted_unique_missing_variants(&bimodal_triple) drifted from `vec![T::ALL[2]]` at cardinality == 3 — count_missing_variants reports 1 (T::ALL[2] the SOLE absent witness), has_unique_missing_variant holds, guard fires, and the guarded lex-lift returns vec![T::ALL[2]]",
);
assert_eq!(
T::sorted_unique_missing_variants(&bimodal_triple),
T::unique_missing_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_missing_variants(&bimodal_triple) drifted from T::unique_missing_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both report vec![T::ALL[2]])",
);
assert_eq!(
T::sorted_unique_missing_variants(&bimodal_triple).first().copied(),
T::sorted_unique_missing_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_missing_variants(&bimodal_triple).first() drifted from T::sorted_unique_missing_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both project to Some(T::ALL[2]))",
);
}
// (198) — `T::sorted_unique_repeating_variants(items)` MUST agree
// with the guarded-lift body
// `if T::has_unique_repeating_variant(items) { T::sorted_repeating_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin the ORDERING-CHOICE-
// IRRELEVANCE identity
// `T::sorted_unique_repeating_variants(items) == T::unique_repeating_variants(items)`
// (the sole strict-repeat variant, if unique, is the SAME across
// declaration and lex sweep-orders — uniqueness pins the witness
// before any ordering choice is consulted). THIS clause CLOSES the
// strict-repeat arm of the LEX-ORDER (`Vec<Self>` × equivalence-
// partition × mult-band × unique-tie) row past the just-opened
// (mult `== 0`) miss-band arm clause (197)
// ([`T::sorted_unique_missing_variants`]) one MULTIPLICITY-BAND axis
// over on the EQUIVALENCE-PARTITION surface, peer to clause (195)
// ([`T::unique_repeating_variants`]) one ORDERING axis over AND peer
// to [`T::sorted_unique_repeating_variant`] one RETURN-SHAPE axis
// over.
//
// Bimodal-triple positive-arm discipline: at `T::CARDINALITY == 3`
// on the canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_repeating_variants` reports `1` (T::ALL[0] the SOLE strict-
// repeat witness — T::ALL[0] at count 2, T::ALL[1] at count 1,
// T::ALL[2] at count 0), `has_unique_repeating_variant` returns
// `true`, guard fires, and the guarded lex-lift reports
// `vec![T::ALL[0]]` — the SAME sole strict-repeat witness that
// clause (195)'s declaration-order sibling reports on the SAME
// fixture, pinning the ordering-choice-irrelevance identity as a
// TYPED THEOREM at the canonical bimodal-triple window. LOAD-BEARING
// DISCRIMINATOR from clause (197)'s just-opened lex miss-band peer
// which reports `vec![T::ALL[2]]` on the SAME fixture (the
// MULTIPLICITY-BAND axis SEPARATES the two lex positive arms at
// DIFFERENT witnesses of the same canonical bimodal triple).
//
// The default trait body threads the boolean-guarded Vec-select over
// [`Self::sorted_repeating_variants`] verbatim and satisfies every
// fixpoint arm + the length + Option-equality + is-empty + ordering-
// choice-irrelevance coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level equivalence-
// partition strict-repeat lex-order singleton-or-empty witness
// surface. An override that folds onto `vec![T::ALL[0]]`
// unconditionally bifurcates the empty-slice + full-set + doubled-
// full-set (at cardinality >= 2) + matching-singleton arms at
// `[T::ALL[0]] != []`; an override that folds onto `vec![]`
// unconditionally bifurcates the bimodal-triple positive arm at
// cardinality `== 3` at `[] != [T::ALL[0]]` AND the doubled-full-set
// arm at cardinality `== 1` at `[] != [T::ALL[0]]`.
let empty_sorted_unique_repeatings = T::sorted_unique_repeating_variants(empty);
let expected_empty_sorted_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(empty) {
T::sorted_repeating_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_repeatings, expected_empty_sorted_unique_repeatings,
"{type_name}: T::sorted_unique_repeating_variants(&[]) drifted from the guarded lex-lift `if T::has_unique_repeating_variant(&[]) {{ T::sorted_repeating_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(empty),
T::unique_repeating_variants(empty),
"{type_name}: T::sorted_unique_repeating_variants(&[]) drifted from T::unique_repeating_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(empty).len(),
usize::from(T::has_unique_repeating_variant(empty)),
"{type_name}: T::sorted_unique_repeating_variants(&[]).len() drifted from `T::has_unique_repeating_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(empty).first().copied(),
T::sorted_unique_repeating_variant(empty),
"{type_name}: T::sorted_unique_repeating_variants(&[]).first() drifted from T::sorted_unique_repeating_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(empty).is_empty(),
!T::has_unique_repeating_variant(empty),
"{type_name}: T::sorted_unique_repeating_variants(&[]).is_empty() drifted from `!T::has_unique_repeating_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_repeatings = T::sorted_unique_repeating_variants(T::ALL);
let expected_full_sorted_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(T::ALL) {
T::sorted_repeating_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_repeatings, expected_full_sorted_unique_repeatings,
"{type_name}: T::sorted_unique_repeating_variants(T::ALL) drifted from the guarded lex-lift on the full-set slice — pairwise-distinctness pins every variant at exactly one position, count_repeating_variants reports 0, has_unique_repeating_variant returns false via `0 != 1`, and the guarded lex-lift collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::sorted_unique_repeating_variants(T::ALL),
T::unique_repeating_variants(T::ALL),
"{type_name}: T::sorted_unique_repeating_variants(T::ALL) drifted from T::unique_repeating_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(T::ALL).len(),
usize::from(T::has_unique_repeating_variant(T::ALL)),
"{type_name}: T::sorted_unique_repeating_variants(T::ALL).len() drifted from `T::has_unique_repeating_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(T::ALL).first().copied(),
T::sorted_unique_repeating_variant(T::ALL),
"{type_name}: T::sorted_unique_repeating_variants(T::ALL).first() drifted from T::sorted_unique_repeating_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_repeatings = T::sorted_unique_repeating_variants(&doubled_full_set);
let expected_doubled_sorted_unique_repeatings: ::std::vec::Vec<T> =
if T::has_unique_repeating_variant(&doubled_full_set) {
T::sorted_repeating_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_repeatings, expected_doubled_sorted_unique_repeatings,
"{type_name}: T::sorted_unique_repeating_variants(&doubled_full_set) drifted from the guarded lex-lift on the doubled-full-set slice — at cardinality >= 2 every variant hits two positions, count_repeating_variants reports T::CARDINALITY >= 2, has_unique_repeating_variant returns false, and the guarded lex-lift collapses to vec![]; at cardinality == 1 the doubled slice `[T::ALL[0], T::ALL[0]]` collapses count_repeating_variants to 1, has_unique_repeating_variant returns true, and the guarded lex-lift returns vec![T::ALL[0]]",
);
assert_eq!(
T::sorted_unique_repeating_variants(&doubled_full_set),
T::unique_repeating_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_repeating_variants(&doubled_full_set) drifted from T::unique_repeating_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(&doubled_full_set).len(),
usize::from(T::has_unique_repeating_variant(&doubled_full_set)),
"{type_name}: T::sorted_unique_repeating_variants(&doubled_full_set).len() drifted from `T::has_unique_repeating_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_repeating_variants(&doubled_full_set).first().copied(),
T::sorted_unique_repeating_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_repeating_variants(&doubled_full_set).first() drifted from T::sorted_unique_repeating_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
assert_eq!(
T::sorted_unique_repeating_variants(&matching_singleton),
::std::vec::Vec::<T>::new(),
"{type_name}: T::sorted_unique_repeating_variants([{target_label:?}]) drifted from `vec![]` on every matching singleton — the target hits count 1, every non-target sits at count 0, count_repeating_variants reports 0, has_unique_repeating_variant returns false, and the guard collapses the projection to vec![]",
);
assert_eq!(
T::sorted_unique_repeating_variants(&matching_singleton),
T::unique_repeating_variants(&matching_singleton),
"{type_name}: T::sorted_unique_repeating_variants([{target_label:?}]) drifted from T::unique_repeating_variants([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on every matching singleton (both collapse to vec![])",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty positive
// arm on the (`Vec<Self>` × sorted × equivalence-partition × mult
// `>= 2` × unique-tie) corner at the canonical cardinality-3
// test-module window. count_repeating_variants reports 1
// (T::ALL[0] the SOLE strict-repeat witness — T::ALL[0] at count
// 2, T::ALL[1] at count 1, T::ALL[2] at count 0),
// has_unique_repeating_variant returns true, guard fires, and
// the guarded lex-lift returns vec![T::ALL[0]] — the SAME
// witness clause (195)'s declaration-order sibling reports on
// the SAME fixture (ordering-choice-irrelevance in action).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_repeating_variants(&bimodal_triple),
::std::vec![T::ALL[0]],
"{type_name}: T::sorted_unique_repeating_variants(&bimodal_triple) drifted from `vec![T::ALL[0]]` at cardinality == 3 — count_repeating_variants reports 1 (T::ALL[0] the SOLE strict-repeat witness), has_unique_repeating_variant holds, guard fires, and the guarded lex-lift returns vec![T::ALL[0]]",
);
assert_eq!(
T::sorted_unique_repeating_variants(&bimodal_triple),
T::unique_repeating_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_repeating_variants(&bimodal_triple) drifted from T::unique_repeating_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both report vec![T::ALL[0]])",
);
assert_eq!(
T::sorted_unique_repeating_variants(&bimodal_triple).first().copied(),
T::sorted_unique_repeating_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_repeating_variants(&bimodal_triple).first() drifted from T::sorted_unique_repeating_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both project to Some(T::ALL[0]))",
);
}
if T::CARDINALITY == 1 {
// Doubled-full-set positive arm at cardinality == 1: the doubled
// slice `[T::ALL[0], T::ALL[0]]` puts T::ALL[0] at count 2,
// count_repeating_variants reports 1, has_unique_repeating_variant
// holds, guard fires, and the guarded lex-lift returns
// vec![T::ALL[0]] — the SOLE positive arm on the degenerate
// cardinality-1 corner of the doubled-full-set fixture.
assert_eq!(
T::sorted_unique_repeating_variants(&doubled_full_set),
T::ALL.to_vec(),
"{type_name}: T::sorted_unique_repeating_variants(&doubled_full_set) drifted from T::ALL.to_vec() at cardinality == 1 — the doubled slice puts the sole variant at count 2, count_repeating_variants reports 1, has_unique_repeating_variant holds, and the guarded lex-lift returns the singleton vec containing the sole variant",
);
}
// (199) — `T::sorted_unique_unique_variants(items)` MUST agree with
// the guarded-lift body
// `if T::has_unique_unique_variant(items) { T::sorted_unique_variants(items) } else { vec![] }`
// on every canonical slice AND MUST pin the ORDERING-CHOICE-
// IRRELEVANCE identity
// `T::sorted_unique_unique_variants(items) == T::unique_unique_variants(items)`
// (the sole unique-band variant, if unique, is the SAME across
// declaration and lex sweep-orders — uniqueness pins the witness
// before any ordering choice is consulted). THIS clause EXHAUSTIVELY
// CLOSES the LEX-ORDER (`Vec<Self>` × equivalence-partition × mult-
// band × unique-tie) row AT ITS FINAL THIRD TILE past the (mult
// `== 0`) miss-band arm clause (197)
// ([`T::sorted_unique_missing_variants`]) AND the (mult `>= 2`)
// strict-repeat arm clause (198)
// ([`T::sorted_unique_repeating_variants`]) one MULTIPLICITY-BAND
// axis over on the EQUIVALENCE-PARTITION surface AND EXHAUSTIVELY
// CLOSES the (`Vec<Self>` × equivalence-partition × mult-band ×
// ordering × unique-tie) 3×2 face at its SIXTH tile, peer to clause
// (196) ([`T::unique_unique_variants`]) one ORDERING axis over AND
// peer to [`T::sorted_unique_unique_variant`] one RETURN-SHAPE axis
// over.
//
// Bimodal-triple positive-arm discipline: at `T::CARDINALITY == 3`
// on the canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_unique_variants` reports `1` (T::ALL[1] the SOLE unique-
// band witness — T::ALL[0] at count 2, T::ALL[1] at count 1,
// T::ALL[2] at count 0), `has_unique_unique_variant` returns `true`,
// guard fires, and the guarded lex-lift reports `vec![T::ALL[1]]` —
// the SAME sole unique-band witness that clause (196)'s declaration-
// order sibling reports on the SAME fixture, pinning the ordering-
// choice-irrelevance identity as a TYPED THEOREM at the canonical
// bimodal-triple window. LOAD-BEARING DISCRIMINATOR from clauses
// (197) + (198) which report `vec![T::ALL[2]]` + `vec![T::ALL[0]]`
// on the SAME fixture (the MULTIPLICITY-BAND axis EXHAUSTIVELY
// SEPARATES the three lex positive arms at DIFFERENT witnesses of
// the same canonical bimodal triple).
//
// The default trait body threads the boolean-guarded Vec-select over
// [`Self::sorted_unique_variants`] verbatim and satisfies every
// fixpoint arm + the length + Option-equality + is-empty + ordering-
// choice-irrelevance coincidence identities for free; the assertion
// catches a future implementor whose override drifts the projection
// loudly rather than silently bifurcating the set-level equivalence-
// partition unique-band lex-order singleton-or-empty witness surface.
// An override that folds onto `vec![T::ALL[0]]` unconditionally
// bifurcates the empty-slice + full-set (at cardinality >= 2) +
// doubled-full-set + non-target matching-singleton + bimodal-triple
// positive arms at `[T::ALL[0]] != vec![]` or `[T::ALL[0]] !=
// vec![T::ALL[1]]`; an override that folds onto `vec![]`
// unconditionally bifurcates the matching-singleton arms at `[] !=
// [target]` AND the bimodal-triple positive arm at cardinality
// `== 3` at `[] != [T::ALL[1]]`.
let empty_sorted_unique_uniques = T::sorted_unique_unique_variants(empty);
let expected_empty_sorted_unique_uniques: ::std::vec::Vec<T> =
if T::has_unique_unique_variant(empty) {
T::sorted_unique_variants(empty)
} else {
::std::vec::Vec::new()
};
assert_eq!(
empty_sorted_unique_uniques, expected_empty_sorted_unique_uniques,
"{type_name}: T::sorted_unique_unique_variants(&[]) drifted from the guarded lex-lift `if T::has_unique_unique_variant(&[]) {{ T::sorted_unique_variants(&[]) }} else {{ vec![] }}` — the guarded-lift identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_unique_variants(empty),
T::unique_unique_variants(empty),
"{type_name}: T::sorted_unique_unique_variants(&[]) drifted from T::unique_unique_variants(&[]) — the ordering-choice-irrelevance identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_unique_variants(empty).len(),
usize::from(T::has_unique_unique_variant(empty)),
"{type_name}: T::sorted_unique_unique_variants(&[]).len() drifted from `T::has_unique_unique_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_unique_variants(empty).first().copied(),
T::sorted_unique_unique_variant(empty),
"{type_name}: T::sorted_unique_unique_variants(&[]).first() drifted from T::sorted_unique_unique_variant(&[]) — the Option-equality identity MUST hold on the empty slice",
);
assert_eq!(
T::sorted_unique_unique_variants(empty).is_empty(),
!T::has_unique_unique_variant(empty),
"{type_name}: T::sorted_unique_unique_variants(&[]).is_empty() drifted from `!T::has_unique_unique_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_sorted_unique_uniques = T::sorted_unique_unique_variants(T::ALL);
let expected_full_sorted_unique_uniques: ::std::vec::Vec<T> =
if T::has_unique_unique_variant(T::ALL) {
T::sorted_unique_variants(T::ALL)
} else {
::std::vec::Vec::new()
};
assert_eq!(
full_sorted_unique_uniques, expected_full_sorted_unique_uniques,
"{type_name}: T::sorted_unique_unique_variants(T::ALL) drifted from the guarded lex-lift on the full-set slice — pairwise-distinctness pins every variant at exactly one position; at CARDINALITY >= 2 count_unique_variants reports CARDINALITY, has_unique_unique_variant returns false, and the guarded lex-lift collapses to vec![]; at CARDINALITY == 1 count_unique_variants reports 1, has_unique_unique_variant holds, and the guarded lex-lift returns vec![T::ALL[0]]",
);
assert_eq!(
T::sorted_unique_unique_variants(T::ALL),
T::unique_unique_variants(T::ALL),
"{type_name}: T::sorted_unique_unique_variants(T::ALL) drifted from T::unique_unique_variants(T::ALL) — the ordering-choice-irrelevance identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_unique_variants(T::ALL).len(),
usize::from(T::has_unique_unique_variant(T::ALL)),
"{type_name}: T::sorted_unique_unique_variants(T::ALL).len() drifted from `T::has_unique_unique_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
assert_eq!(
T::sorted_unique_unique_variants(T::ALL).first().copied(),
T::sorted_unique_unique_variant(T::ALL),
"{type_name}: T::sorted_unique_unique_variants(T::ALL).first() drifted from T::sorted_unique_unique_variant(T::ALL) — the Option-equality identity MUST hold on the full-set slice",
);
let doubled_sorted_unique_uniques = T::sorted_unique_unique_variants(&doubled_full_set);
let expected_doubled_sorted_unique_uniques: ::std::vec::Vec<T> =
if T::has_unique_unique_variant(&doubled_full_set) {
T::sorted_unique_variants(&doubled_full_set)
} else {
::std::vec::Vec::new()
};
assert_eq!(
doubled_sorted_unique_uniques, expected_doubled_sorted_unique_uniques,
"{type_name}: T::sorted_unique_unique_variants(&doubled_full_set) drifted from the guarded lex-lift on the doubled-full-set slice — every variant hits multiplicity 2, count_unique_variants reports 0, has_unique_unique_variant returns false, and the guarded lex-lift collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::sorted_unique_unique_variants(&doubled_full_set),
T::unique_unique_variants(&doubled_full_set),
"{type_name}: T::sorted_unique_unique_variants(&doubled_full_set) drifted from T::unique_unique_variants(&doubled_full_set) — the ordering-choice-irrelevance identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_unique_variants(&doubled_full_set).len(),
usize::from(T::has_unique_unique_variant(&doubled_full_set)),
"{type_name}: T::sorted_unique_unique_variants(&doubled_full_set).len() drifted from `T::has_unique_unique_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::sorted_unique_unique_variants(&doubled_full_set).first().copied(),
T::sorted_unique_unique_variant(&doubled_full_set),
"{type_name}: T::sorted_unique_unique_variants(&doubled_full_set).first() drifted from T::sorted_unique_unique_variant(&doubled_full_set) — the Option-equality identity MUST hold on the doubled-full-set slice",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
// Matching-singleton POSITIVE arm: the target hits count 1
// (SOLE unique-band witness), every non-target sits at count 0
// (miss-band, not unique-band), count_unique_variants reports 1,
// has_unique_unique_variant holds, and the guarded lex-lift
// returns vec![target] — LOAD-BEARING NON-EMPTY DEGENERATE ARM
// at the singleton fixture. Ordering-choice-irrelevance holds
// because uniqueness pins the sole witness before either sweep-
// order kicks in.
assert_eq!(
T::sorted_unique_unique_variants(&matching_singleton),
::std::vec![target],
"{type_name}: T::sorted_unique_unique_variants([{target_label:?}]) drifted from `vec![target]` on every matching singleton — the target hits count 1, count_unique_variants reports 1, has_unique_unique_variant holds, and the guarded lex-lift returns vec![target]",
);
assert_eq!(
T::sorted_unique_unique_variants(&matching_singleton),
T::unique_unique_variants(&matching_singleton),
"{type_name}: T::sorted_unique_unique_variants([{target_label:?}]) drifted from T::unique_unique_variants([{target_label:?}]) — the ordering-choice-irrelevance identity MUST hold on every matching singleton (both report vec![target])",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING SOLE non-empty positive
// arm on the (`Vec<Self>` × sorted × equivalence-partition × mult
// `== 1` × unique-tie) corner at the canonical cardinality-3
// test-module window. count_unique_variants reports 1 (T::ALL[1]
// the SOLE unique-band witness — T::ALL[0] at count 2, T::ALL[1]
// at count 1, T::ALL[2] at count 0), has_unique_unique_variant
// returns true, guard fires, and the guarded lex-lift returns
// vec![T::ALL[1]] — the SAME witness clause (196)'s declaration-
// order sibling reports on the SAME fixture (ordering-choice-
// irrelevance in action).
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::sorted_unique_unique_variants(&bimodal_triple),
::std::vec![T::ALL[1]],
"{type_name}: T::sorted_unique_unique_variants(&bimodal_triple) drifted from `vec![T::ALL[1]]` at cardinality == 3 — count_unique_variants reports 1 (T::ALL[1] the SOLE unique-band witness), has_unique_unique_variant holds, guard fires, and the guarded lex-lift returns vec![T::ALL[1]]",
);
assert_eq!(
T::sorted_unique_unique_variants(&bimodal_triple),
T::unique_unique_variants(&bimodal_triple),
"{type_name}: T::sorted_unique_unique_variants(&bimodal_triple) drifted from T::unique_unique_variants(&bimodal_triple) — the ordering-choice-irrelevance identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both report vec![T::ALL[1]])",
);
assert_eq!(
T::sorted_unique_unique_variants(&bimodal_triple).first().copied(),
T::sorted_unique_unique_variant(&bimodal_triple),
"{type_name}: T::sorted_unique_unique_variants(&bimodal_triple).first() drifted from T::sorted_unique_unique_variant(&bimodal_triple) — the Option-equality identity MUST hold on the bimodal-triple fixture at cardinality == 3 (both project to Some(T::ALL[1]))",
);
}
// (200) — `T::unique_missing_labels(items)` MUST agree with the
// composition body
// `T::unique_missing_variants(items).into_iter().map(T::label).collect()`
// on every canonical slice AND MUST pin length + is-empty +
// guarded-lift coincidences against the sibling (`bool`,
// `Vec<Self>`) unique-tie miss-band corners one RETURN-SHAPE axis
// over. THIS clause OPENS the LABEL-return column of the (set-
// level × `Vec<&'static str>` × equivalence-partition × mult-band ×
// unique-tie) row on the EQUIVALENCE-PARTITION surface at its
// (mult `== 0`) miss-band arm past the just-closed variant-return
// trio clauses (194) + (195) + (196) one RETURN-SHAPE axis over.
// Peer to clause (194) ([`T::unique_missing_variants`]) one
// RETURN-SHAPE axis over (variant-Vec witness → label-Vec witness
// of the same singleton-or-empty binding).
//
// The default trait body threads the two-primitive
// `unique_missing_variants + label + map + collect` composition
// verbatim and satisfies every fixpoint arm + the composition +
// length + is-empty coincidence identities for free; the
// assertion catches a future implementor whose override drifts
// the label projection loudly rather than silently bifurcating
// the set-level equivalence-partition miss-band singleton-or-
// empty LABEL witness surface. An override that folds onto
// `vec![T::ALL[0].label()]` unconditionally bifurcates the
// empty-slice (at cardinality >= 2) + full-set + doubled-full-set
// arms at `[T::ALL[0].label()] != []`. An override that folds
// onto `vec![]` unconditionally bifurcates the bimodal-triple
// positive arm at cardinality `== 3` at `[] != [T::ALL[2].label()]`.
let empty_unique_missing_labels = T::unique_missing_labels(empty);
let expected_empty_unique_missing_labels: ::std::vec::Vec<&'static str> =
T::unique_missing_variants(empty)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
empty_unique_missing_labels, expected_empty_unique_missing_labels,
"{type_name}: T::unique_missing_labels(&[]) drifted from `T::unique_missing_variants(&[]).into_iter().map(T::label).collect()` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_missing_labels(empty).len(),
usize::from(T::has_unique_missing_variant(empty)),
"{type_name}: T::unique_missing_labels(&[]).len() drifted from `T::has_unique_missing_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_missing_labels(empty).is_empty(),
!T::has_unique_missing_variant(empty),
"{type_name}: T::unique_missing_labels(&[]).is_empty() drifted from `!T::has_unique_missing_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_missing_labels = T::unique_missing_labels(T::ALL);
let expected_full_unique_missing_labels: ::std::vec::Vec<&'static str> =
T::unique_missing_variants(T::ALL)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
full_unique_missing_labels, expected_full_unique_missing_labels,
"{type_name}: T::unique_missing_labels(T::ALL) drifted from the composition body on the full-set slice — pairwise-distinctness pins count_missing at 0, has_unique_missing_variant returns false, and the projection collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::unique_missing_labels(T::ALL).len(),
usize::from(T::has_unique_missing_variant(T::ALL)),
"{type_name}: T::unique_missing_labels(T::ALL).len() drifted from `T::has_unique_missing_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
let doubled_unique_missing_labels = T::unique_missing_labels(&doubled_full_set);
let expected_doubled_unique_missing_labels: ::std::vec::Vec<&'static str> =
T::unique_missing_variants(&doubled_full_set)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
doubled_unique_missing_labels, expected_doubled_unique_missing_labels,
"{type_name}: T::unique_missing_labels(&doubled_full_set) drifted from the composition body on the doubled-full-set slice — every variant hit twice pins count_missing == 0, has_unique_missing_variant returns false, and the projection collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::unique_missing_labels(&doubled_full_set).len(),
usize::from(T::has_unique_missing_variant(&doubled_full_set)),
"{type_name}: T::unique_missing_labels(&doubled_full_set).len() drifted from `T::has_unique_missing_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`Vec<&'static str>` × equivalence-partition ×
// mult `== 0` × unique-tie) corner at the canonical
// cardinality-3 test-module window. count_missing reports 1
// (T::ALL[2] absent), has_unique_missing_variant holds, guard
// fires, and the composition body reports
// vec![T::ALL[2].label()] — the SAME sole absent variant that
// clause (194)'s variant-Vec sibling reports on the SAME
// fixture one RETURN-SHAPE axis over, under the injective per-
// slot T::label projection.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_missing_labels(&bimodal_triple),
::std::vec![<T as ClosedSet>::label(T::ALL[2])],
"{type_name}: T::unique_missing_labels(&bimodal_triple) drifted from `vec![T::ALL[2].label()]` at cardinality == 3 — count_missing reports 1 (T::ALL[2] sole absent), has_unique_missing_variant holds, guard fires, and the composition body reports vec![T::ALL[2].label()]",
);
}
// (201) — `T::unique_repeating_labels(items)` MUST agree with the
// composition body
// `T::unique_repeating_variants(items).into_iter().map(T::label).collect()`
// on every canonical slice AND MUST pin length + is-empty +
// guarded-lift coincidences against the sibling (`bool`,
// `Vec<Self>`) unique-tie strict-repeat corners one RETURN-SHAPE
// axis over. THIS clause CLOSES the strict-repeat arm of the (set-
// level × `Vec<&'static str>` × equivalence-partition × mult-band ×
// unique-tie) row on the EQUIVALENCE-PARTITION surface past the
// just-opened (mult `== 0`) miss-band clause (200) one
// MULTIPLICITY-BAND axis over. Peer to clause (195)
// ([`T::unique_repeating_variants`]) one RETURN-SHAPE axis over
// (variant-Vec witness → label-Vec witness of the same singleton-
// or-empty binding).
//
// The default trait body threads the two-primitive
// `unique_repeating_variants + label + map + collect` composition
// verbatim and satisfies every fixpoint arm + the composition +
// length + is-empty coincidence identities for free; the
// assertion catches a future implementor whose override drifts
// the label projection loudly rather than silently bifurcating
// the set-level equivalence-partition strict-repeat singleton-or-
// empty LABEL witness surface. An override that folds onto
// `vec![T::ALL[0].label()]` unconditionally bifurcates the
// empty-slice + full-set arms at `[T::ALL[0].label()] != []`. An
// override that folds onto `vec![]` unconditionally bifurcates the
// bimodal-triple positive arm at cardinality `== 3` at
// `[] != [T::ALL[0].label()]`.
let empty_unique_repeating_labels = T::unique_repeating_labels(empty);
let expected_empty_unique_repeating_labels: ::std::vec::Vec<&'static str> =
T::unique_repeating_variants(empty)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
empty_unique_repeating_labels, expected_empty_unique_repeating_labels,
"{type_name}: T::unique_repeating_labels(&[]) drifted from `T::unique_repeating_variants(&[]).into_iter().map(T::label).collect()` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_labels(empty).len(),
usize::from(T::has_unique_repeating_variant(empty)),
"{type_name}: T::unique_repeating_labels(&[]).len() drifted from `T::has_unique_repeating_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_labels(empty).is_empty(),
!T::has_unique_repeating_variant(empty),
"{type_name}: T::unique_repeating_labels(&[]).is_empty() drifted from `!T::has_unique_repeating_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_repeating_labels = T::unique_repeating_labels(T::ALL);
let expected_full_unique_repeating_labels: ::std::vec::Vec<&'static str> =
T::unique_repeating_variants(T::ALL)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
full_unique_repeating_labels, expected_full_unique_repeating_labels,
"{type_name}: T::unique_repeating_labels(T::ALL) drifted from the composition body on the full-set slice — pairwise-distinctness pins count_repeating_variants at 0, has_unique_repeating_variant returns false, and the projection collapses to vec![] UNCONDITIONALLY",
);
assert_eq!(
T::unique_repeating_labels(T::ALL).len(),
usize::from(T::has_unique_repeating_variant(T::ALL)),
"{type_name}: T::unique_repeating_labels(T::ALL).len() drifted from `T::has_unique_repeating_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
let doubled_unique_repeating_labels = T::unique_repeating_labels(&doubled_full_set);
let expected_doubled_unique_repeating_labels: ::std::vec::Vec<&'static str> =
T::unique_repeating_variants(&doubled_full_set)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
doubled_unique_repeating_labels, expected_doubled_unique_repeating_labels,
"{type_name}: T::unique_repeating_labels(&doubled_full_set) drifted from the composition body on the doubled-full-set slice — every variant hit twice pins count_repeating_variants == T::CARDINALITY, has_unique_repeating_variant holds iff T::CARDINALITY == 1, and the projection collapses to vec![] at T::CARDINALITY >= 2",
);
assert_eq!(
T::unique_repeating_labels(&doubled_full_set).len(),
usize::from(T::has_unique_repeating_variant(&doubled_full_set)),
"{type_name}: T::unique_repeating_labels(&doubled_full_set).len() drifted from `T::has_unique_repeating_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`Vec<&'static str>` × equivalence-partition ×
// mult `>= 2` × unique-tie) corner at the canonical
// cardinality-3 test-module window. count_repeating_variants
// reports 1 (T::ALL[0] sole strict-repeat at count 2),
// has_unique_repeating_variant holds, guard fires, and the
// composition body reports vec![T::ALL[0].label()] — the SAME
// sole strict-repeat variant that clause (195)'s variant-Vec
// sibling reports on the SAME fixture one RETURN-SHAPE axis
// over, under the injective per-slot T::label projection.
// LOAD-BEARING DISJOINT-WITNESS mirror of clause (200)'s
// bimodal-triple arm (which reports vec![T::ALL[2].label()])
// one MULTIPLICITY-BAND axis over on the LABEL-return column —
// the two positive label arms report TWO DIFFERENT witnesses
// (T::ALL[0].label() vs T::ALL[2].label()) on the SAME
// fixture, pinning the miss-band / strict-repeat band
// separation under the injective per-slot T::label projection.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_repeating_labels(&bimodal_triple),
::std::vec![<T as ClosedSet>::label(T::ALL[0])],
"{type_name}: T::unique_repeating_labels(&bimodal_triple) drifted from `vec![T::ALL[0].label()]` at cardinality == 3 — count_repeating_variants reports 1 (T::ALL[0] sole strict-repeat), has_unique_repeating_variant holds, guard fires, and the composition body reports vec![T::ALL[0].label()]",
);
}
// (202) — `T::unique_unique_labels(items)` MUST agree with the
// composition body
// `T::unique_unique_variants(items).into_iter().map(T::label).collect()`
// on every canonical slice AND MUST pin length + is-empty
// coincidences against the sibling (`bool`, `Vec<Self>`) unique-tie
// unique-band corners one RETURN-SHAPE axis over. THIS clause
// EXHAUSTIVELY CLOSES the (mult `== 1`) middle arm of the (set-
// level × `Vec<&'static str>` × equivalence-partition × mult-band ×
// unique-tie) 3-corner row on the EQUIVALENCE-PARTITION surface AT
// ITS FINAL THIRD TILE past clauses (200) + (201) one MULTIPLICITY-
// BAND axis over AND CLOSES the (mult-band × return-shape) 3×2 face
// on the unique-tie subsurface at 6/6. Peer to clause (196)
// ([`T::unique_unique_variants`]) one RETURN-SHAPE axis over
// (variant-Vec witness → label-Vec witness of the same
// singleton-or-empty binding).
//
// Bimodal-triple positive-arm discipline (LOAD-BEARING TRICHOTOMY
// DISCRIMINATOR from clauses (200) + (201)): at `T::CARDINALITY == 3`
// on the canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]`,
// `count_unique_variants` reports `1` (T::ALL[1] the SOLE unique-band
// witness — T::ALL[0] at count 2, T::ALL[1] at count 1, T::ALL[2] at
// count 0), `has_unique_unique_variant` holds, and the composition
// body reports `vec![T::ALL[1].label()]`. Clauses (200) + (201) +
// THIS clause report THREE DIFFERENT label witnesses on the SAME
// fixture (`T::ALL[2].label()`, `T::ALL[0].label()`,
// `T::ALL[1].label()` respectively); the MULTIPLICITY-BAND axis
// EXHAUSTIVELY PARTITIONS the three positive label arms as
// orthogonal uniqueness corners with disjoint witness projections
// riding DIFFERENT variants of the canonical bimodal triple under
// the injective per-slot T::label projection.
//
// Matching-singleton positive-arm discipline (LOAD-BEARING NON-EMPTY
// DEGENERATE ARM distinct from clauses (200) + (201)): on every
// matching singleton `[v]`, the target hits count 1 (the SOLE
// unique-band witness), every non-target sits at count 0,
// `count_unique_variants` reports 1, `has_unique_unique_variant`
// holds, and the composition body reports `vec![v.label()]` —
// distinct from clause (201) which collapses to `vec![]` on every
// matching singleton AND from clause (200) whose singleton behavior
// is CARDINALITY-dependent (vec![] at CARDINALITY != 2;
// vec![the sole absent label] at CARDINALITY == 2).
//
// The default trait body threads the two-primitive
// `unique_unique_variants + label + map + collect` composition
// verbatim and satisfies every fixpoint arm + the composition +
// length + is-empty coincidence identities for free; the assertion
// catches a future implementor whose override drifts the label
// projection loudly rather than silently bifurcating the set-level
// equivalence-partition unique-band singleton-or-empty LABEL
// witness surface. An override that folds onto `vec![]`
// unconditionally bifurcates the matching-singleton positive arms
// at `[] != [v.label()]` AND the bimodal-triple positive arm at
// cardinality >= 3 at `[] != [T::ALL[1].label()]` AND the full-set
// positive arm at cardinality == 1 at `[] != [T::ALL[0].label()]`.
// An override that folds onto `vec![T::ALL[0].label()]`
// unconditionally bifurcates the empty-slice + doubled-full-set
// arms (both expect vec![]) at `[T::ALL[0].label()] != []`.
let empty_unique_unique_labels = T::unique_unique_labels(empty);
let expected_empty_unique_unique_labels: ::std::vec::Vec<&'static str> =
T::unique_unique_variants(empty)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
empty_unique_unique_labels, expected_empty_unique_unique_labels,
"{type_name}: T::unique_unique_labels(&[]) drifted from `T::unique_unique_variants(&[]).into_iter().map(T::label).collect()` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_labels(empty).len(),
usize::from(T::has_unique_unique_variant(empty)),
"{type_name}: T::unique_unique_labels(&[]).len() drifted from `T::has_unique_unique_variant(&[]) as usize` — the length-coincidence identity MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_labels(empty).is_empty(),
!T::has_unique_unique_variant(empty),
"{type_name}: T::unique_unique_labels(&[]).is_empty() drifted from `!T::has_unique_unique_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let full_unique_unique_labels = T::unique_unique_labels(T::ALL);
let expected_full_unique_unique_labels: ::std::vec::Vec<&'static str> =
T::unique_unique_variants(T::ALL)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
full_unique_unique_labels, expected_full_unique_unique_labels,
"{type_name}: T::unique_unique_labels(T::ALL) drifted from the composition body on the full-set slice — pairwise-distinctness pins count_unique_variants at T::CARDINALITY, has_unique_unique_variant holds iff T::CARDINALITY == 1, and the projection returns vec![T::ALL[0].label()] at CARDINALITY == 1 else vec![]",
);
assert_eq!(
T::unique_unique_labels(T::ALL).len(),
usize::from(T::has_unique_unique_variant(T::ALL)),
"{type_name}: T::unique_unique_labels(T::ALL).len() drifted from `T::has_unique_unique_variant(T::ALL) as usize` — the length-coincidence identity MUST hold on the full-set slice",
);
let doubled_unique_unique_labels = T::unique_unique_labels(&doubled_full_set);
let expected_doubled_unique_unique_labels: ::std::vec::Vec<&'static str> =
T::unique_unique_variants(&doubled_full_set)
.into_iter()
.map(<T as ClosedSet>::label)
.collect();
assert_eq!(
doubled_unique_unique_labels, expected_doubled_unique_unique_labels,
"{type_name}: T::unique_unique_labels(&doubled_full_set) drifted from the composition body on the doubled-full-set slice — every variant hit twice pins count_unique_variants == 0 (strict-repeat, NOT unique-band), has_unique_unique_variant returns false via `0 != 1`, and the projection collapses to vec![] UNCONDITIONALLY at every cardinality",
);
assert_eq!(
T::unique_unique_labels(&doubled_full_set).len(),
usize::from(T::has_unique_unique_variant(&doubled_full_set)),
"{type_name}: T::unique_unique_labels(&doubled_full_set).len() drifted from `T::has_unique_unique_variant(&doubled_full_set) as usize` — the length-coincidence identity MUST hold on the doubled-full-set slice",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
// Matching-singleton POSITIVE arm: the target hits count 1
// (the SOLE unique-band witness), every non-target sits at
// count 0, count_unique_variants reports 1,
// has_unique_unique_variant holds, and the composition body
// reports vec![target.label()]. LOAD-BEARING NON-EMPTY
// DEGENERATE arm — distinct from clause (201) which collapses
// to vec![] on every matching singleton.
assert_eq!(
T::unique_unique_labels(&matching_singleton),
::std::vec![target_label],
"{type_name}: T::unique_unique_labels([{target_label:?}]) drifted from vec![{target_label:?}] on every matching singleton — the target hits count 1 (SOLE unique-band witness), count_unique_variants reports 1, has_unique_unique_variant holds, and the composition body reports the singleton label vec of the target",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`Vec<&'static str>` × equivalence-partition ×
// mult `== 1` × unique-tie) corner at the canonical
// cardinality-3 test-module window. count_unique_variants
// reports 1 (T::ALL[1] the SOLE unique-band witness),
// has_unique_unique_variant holds, guard fires, and the
// composition body reports vec![T::ALL[1].label()] — the SAME
// sole unique-band variant that clause (196)'s variant-Vec
// sibling reports on the SAME fixture one RETURN-SHAPE axis
// over, under the injective per-slot T::label projection.
// LOAD-BEARING TRICHOTOMY DISCRIMINATOR from clauses (200) +
// (201) which report vec![T::ALL[2].label()] +
// vec![T::ALL[0].label()] on the SAME fixture — the three
// positive label arms report THREE DIFFERENT witnesses one
// MULTIPLICITY-BAND axis apart, pinning the miss-band /
// strict-repeat / unique-band separation under the injective
// per-slot T::label projection.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
assert_eq!(
T::unique_unique_labels(&bimodal_triple),
::std::vec![<T as ClosedSet>::label(T::ALL[1])],
"{type_name}: T::unique_unique_labels(&bimodal_triple) drifted from `vec![T::ALL[1].label()]` at cardinality == 3 — count_unique_variants reports 1 (T::ALL[1] the SOLE unique-band witness), has_unique_unique_variant holds, guard fires, and the composition body reports vec![T::ALL[1].label()]. A `vec![]` fold silently bifurcates the LOAD-BEARING positive arm AND its LOAD-BEARING TRICHOTOMY DISCRIMINATION from clauses (200) + (201) which report vec![T::ALL[2].label()] + vec![T::ALL[0].label()] on the SAME fixture",
);
}
// (203) — `T::unique_missing_labels_joined(items, sep)` MUST agree
// with the composition body `T::unique_missing_labels(items).join(sep)`
// on every canonical slice AND MUST pin fixpoint arms against the
// sibling label-Vec projection one RETURN-SHAPE axis over. THIS
// clause OPENS the JOIN-STRING return column of the (set-level ×
// `String` × equivalence-partition × mult-band × unique-tie) row on
// the EQUIVALENCE-PARTITION surface at its (mult `== 0`) miss-band
// arm past the just-closed label-Vec trio clauses (200) + (201) +
// (202) one RETURN-SHAPE axis over. Peer to clause (200)
// ([`T::unique_missing_labels`]) one RETURN-SHAPE axis over
// (label-Vec witness → joined-String witness of the same
// singleton-or-empty binding).
//
// Bimodal-triple positive-arm discipline (SEPARATOR-AGNOSTIC on the
// singleton positive arm): at `T::CARDINALITY == 3` on the canonical
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` for every `sep`
// in `["/", ", ", "|"]`, `T::ALL[2]` sits at count `0` (the SOLE
// absent variant), `count_missing` reports `1`,
// `has_unique_missing_variant` holds, guard fires, the label-Vec
// collapses to `vec![T::ALL[2].label()]`, and `slice::join` on the
// singleton returns `T::ALL[2].label().to_string()` UNCONDITIONALLY
// — the separator NEVER surfaces in the output because the joined
// slice is a singleton. Sweep three representative separators (the
// slash, comma-space, and pipe shapes clauses (8) + (10) already
// route through) so a drift in any rendering surface fails.
//
// The default trait body threads the two-primitive
// `unique_missing_labels + join` composition verbatim and satisfies
// every fixpoint arm + the composition + is-empty coincidence
// identities for free; the assertion catches a future implementor
// whose override drifts the join-String projection loudly rather
// than silently bifurcating the set-level equivalence-partition
// miss-band singleton-or-empty JOIN-STRING witness surface. An
// override that folds onto `String::new()` unconditionally
// bifurcates the bimodal-triple positive arm at cardinality == 3
// at `"" != "gamma"` under every sep. An override that folds onto
// `T::ALL[0].label().to_string()` unconditionally bifurcates the
// empty-slice + full-set + doubled-full-set arms at CARDINALITY
// >= 2 (each expects `""`) at `"alpha" != ""`.
for sep in ["/", ", ", "|"] {
let lifted_empty = T::unique_missing_labels_joined(empty, sep);
let natural_empty = T::unique_missing_labels(empty).join(sep);
assert_eq!(
lifted_empty, natural_empty,
"{type_name}: T::unique_missing_labels_joined(&[], {sep:?}) drifted from `T::unique_missing_labels(&[]).join({sep:?})` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_missing_labels_joined(empty, sep).is_empty(),
!T::has_unique_missing_variant(empty),
"{type_name}: T::unique_missing_labels_joined(&[], {sep:?}).is_empty() drifted from `!T::has_unique_missing_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let lifted_full = T::unique_missing_labels_joined(T::ALL, sep);
let natural_full = T::unique_missing_labels(T::ALL).join(sep);
assert_eq!(
lifted_full, natural_full,
"{type_name}: T::unique_missing_labels_joined(T::ALL, {sep:?}) drifted from `T::unique_missing_labels(T::ALL).join({sep:?})` — the composition law MUST hold on the full-set slice",
);
assert_eq!(
T::unique_missing_labels_joined(T::ALL, sep),
::std::string::String::new(),
"{type_name}: T::unique_missing_labels_joined(T::ALL, {sep:?}) drifted from the empty-String fixpoint — pairwise-distinctness pins count_missing == 0, has_unique_missing_variant is false, the label-Vec collapses to vec![], and slice::join on [] is the empty String",
);
let lifted_doubled = T::unique_missing_labels_joined(&doubled_full_set, sep);
let natural_doubled = T::unique_missing_labels(&doubled_full_set).join(sep);
assert_eq!(
lifted_doubled, natural_doubled,
"{type_name}: T::unique_missing_labels_joined(&doubled_full_set, {sep:?}) drifted from `T::unique_missing_labels(&doubled_full_set).join({sep:?})` — the composition law MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_missing_labels_joined(&doubled_full_set, sep),
::std::string::String::new(),
"{type_name}: T::unique_missing_labels_joined(&doubled_full_set, {sep:?}) drifted from the empty-String fixpoint — every variant hits count 2 (strict-repeat, NOT miss-band), count_missing == 0, has_unique_missing_variant is false, and the projection collapses to the empty String at every cardinality",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`String` × equivalence-partition × mult `== 0` ×
// unique-tie) corner at the canonical cardinality-3 test-module
// window. count_missing reports 1 (T::ALL[2] the SOLE absent
// witness), has_unique_missing_variant holds, guard fires, the
// label-Vec collapses to vec![T::ALL[2].label()], and
// slice::join on the singleton returns T::ALL[2].label() as a
// bare String — SEPARATOR-AGNOSTIC because the joined slice is
// a singleton. Sweep three representative separators so a
// drift on any rendering surface fails. LOAD-BEARING mirror of
// clause (200)'s bimodal-triple label-Vec positive arm one
// RETURN-SHAPE axis over on the miss-band unique-tie corner.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let expected_bimodal =
::std::string::ToString::to_string(<T as ClosedSet>::label(T::ALL[2]));
for sep in ["/", ", ", "|"] {
assert_eq!(
T::unique_missing_labels_joined(&bimodal_triple, sep),
expected_bimodal,
"{type_name}: T::unique_missing_labels_joined(&bimodal_triple, {sep:?}) drifted from T::ALL[2].label() as String at cardinality == 3 — count_missing reports 1 (T::ALL[2] the SOLE absent witness), has_unique_missing_variant holds, guard fires, the label-Vec collapses to vec![T::ALL[2].label()], and slice::join on the singleton returns T::ALL[2].label() as a bare String (the separator NEVER surfaces because the joined slice is a singleton)",
);
}
}
// (204) — `T::unique_repeating_labels_joined(items, sep)` MUST agree
// with the composition body `T::unique_repeating_labels(items).join(sep)`
// on every canonical slice AND MUST pin fixpoint arms against the
// sibling label-Vec projection one RETURN-SHAPE axis over. THIS
// clause CLOSES the strict-repeat arm of the JOIN-STRING return
// column of the (set-level × `String` × equivalence-partition ×
// mult-band × unique-tie) row on the EQUIVALENCE-PARTITION surface
// past the just-opened (mult `== 0`) miss-band clause (203) one
// MULTIPLICITY-BAND axis over. Peer to clause (201)
// ([`T::unique_repeating_labels`]) one RETURN-SHAPE axis over
// (label-Vec witness → joined-String witness of the same singleton-
// or-empty binding).
//
// Bimodal-triple positive-arm discipline (SEPARATOR-AGNOSTIC on the
// singleton positive arm): at `T::CARDINALITY == 3` on the canonical
// bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` for every `sep`
// in `["/", ", ", "|"]`, `T::ALL[0]` sits at count `2` (the SOLE
// strict-repeat variant), `count_repeating_variants` reports `1`,
// `has_unique_repeating_variant` holds, guard fires, the label-Vec
// collapses to `vec![T::ALL[0].label()]`, and `slice::join` on the
// singleton returns `T::ALL[0].label().to_string()` UNCONDITIONALLY
// — the separator NEVER surfaces in the output because the joined
// slice is a singleton. LOAD-BEARING DISJOINT-WITNESS mirror of
// clause (203)'s bimodal-triple arm (which reports
// `T::ALL[2].label()`) one MULTIPLICITY-BAND axis over on the
// JOIN-STRING return column — the two positive join-String arms
// report TWO DIFFERENT witnesses on the SAME fixture, pinning the
// strict-repeat / miss-band band separation under the injective
// per-slot T::label projection composed with `slice::join`.
//
// The default trait body threads the two-primitive
// `unique_repeating_labels + join` composition verbatim and
// satisfies every fixpoint arm + the composition + is-empty
// coincidence identities for free; the assertion catches a future
// implementor whose override drifts the join-String projection
// loudly rather than silently bifurcating the set-level
// equivalence-partition strict-repeat singleton-or-empty
// JOIN-STRING witness surface. An override that folds onto
// `String::new()` unconditionally bifurcates the bimodal-triple
// positive arm at cardinality == 3 at `"" != "alpha"` under every
// sep. An override that folds onto `T::ALL[0].label().to_string()`
// unconditionally bifurcates the empty-slice + full-set arms at
// every cardinality (each expects `""`) at `"alpha" != ""`.
for sep in ["/", ", ", "|"] {
let lifted_empty = T::unique_repeating_labels_joined(empty, sep);
let natural_empty = T::unique_repeating_labels(empty).join(sep);
assert_eq!(
lifted_empty, natural_empty,
"{type_name}: T::unique_repeating_labels_joined(&[], {sep:?}) drifted from `T::unique_repeating_labels(&[]).join({sep:?})` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_repeating_labels_joined(empty, sep),
::std::string::String::new(),
"{type_name}: T::unique_repeating_labels_joined(&[], {sep:?}) drifted from the empty-String fixpoint — the empty slice hits zero positions, count_repeating_variants == 0, has_unique_repeating_variant is false, the label-Vec collapses to vec![], and slice::join on [] is the empty String UNCONDITIONALLY",
);
assert_eq!(
T::unique_repeating_labels_joined(empty, sep).is_empty(),
!T::has_unique_repeating_variant(empty),
"{type_name}: T::unique_repeating_labels_joined(&[], {sep:?}).is_empty() drifted from `!T::has_unique_repeating_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let lifted_full = T::unique_repeating_labels_joined(T::ALL, sep);
let natural_full = T::unique_repeating_labels(T::ALL).join(sep);
assert_eq!(
lifted_full, natural_full,
"{type_name}: T::unique_repeating_labels_joined(T::ALL, {sep:?}) drifted from `T::unique_repeating_labels(T::ALL).join({sep:?})` — the composition law MUST hold on the full-set slice",
);
assert_eq!(
T::unique_repeating_labels_joined(T::ALL, sep),
::std::string::String::new(),
"{type_name}: T::unique_repeating_labels_joined(T::ALL, {sep:?}) drifted from the empty-String fixpoint — pairwise-distinctness pins count_repeating_variants == 0, has_unique_repeating_variant is false, the label-Vec collapses to vec![], and slice::join on [] is the empty String",
);
let lifted_doubled = T::unique_repeating_labels_joined(&doubled_full_set, sep);
let natural_doubled = T::unique_repeating_labels(&doubled_full_set).join(sep);
assert_eq!(
lifted_doubled, natural_doubled,
"{type_name}: T::unique_repeating_labels_joined(&doubled_full_set, {sep:?}) drifted from `T::unique_repeating_labels(&doubled_full_set).join({sep:?})` — the composition law MUST hold on the doubled-full-set slice",
);
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`String` × equivalence-partition × mult `>= 2` ×
// unique-tie) corner at the canonical cardinality-3 test-module
// window. count_repeating_variants reports 1 (T::ALL[0] the SOLE
// strict-repeat witness at count 2), has_unique_repeating_variant
// holds, guard fires, the label-Vec collapses to
// vec![T::ALL[0].label()], and slice::join on the singleton
// returns T::ALL[0].label() as a bare String —
// SEPARATOR-AGNOSTIC because the joined slice is a singleton.
// Sweep three representative separators so a drift on any
// rendering surface fails. LOAD-BEARING mirror of clause (201)'s
// bimodal-triple label-Vec positive arm one RETURN-SHAPE axis
// over on the strict-repeat unique-tie corner AND LOAD-BEARING
// DISJOINT-WITNESS mirror of clause (203)'s bimodal-triple
// join-String positive arm (which reports T::ALL[2].label()) one
// MULTIPLICITY-BAND axis over on the JOIN-STRING return column.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let expected_bimodal =
::std::string::ToString::to_string(<T as ClosedSet>::label(T::ALL[0]));
for sep in ["/", ", ", "|"] {
assert_eq!(
T::unique_repeating_labels_joined(&bimodal_triple, sep),
expected_bimodal,
"{type_name}: T::unique_repeating_labels_joined(&bimodal_triple, {sep:?}) drifted from T::ALL[0].label() as String at cardinality == 3 — count_repeating_variants reports 1 (T::ALL[0] the SOLE strict-repeat witness), has_unique_repeating_variant holds, guard fires, the label-Vec collapses to vec![T::ALL[0].label()], and slice::join on the singleton returns T::ALL[0].label() as a bare String (the separator NEVER surfaces because the joined slice is a singleton)",
);
}
}
// (205) — `T::unique_unique_labels_joined(items, sep)` MUST agree
// with the composition body
// `T::unique_unique_labels(items).join(sep)` on every canonical
// slice AND MUST pin fixpoint arms against the sibling label-Vec
// projection one RETURN-SHAPE axis over. THIS clause EXHAUSTIVELY
// CLOSES the (mult `== 1`) unique-band arm of the JOIN-STRING
// return column of the (set-level × `String` × equivalence-
// partition × mult-band × unique-tie) row on the EQUIVALENCE-
// PARTITION surface AT ITS FINAL THIRD TILE past the just-closed
// (mult `== 0`) miss-band clause (203) AND (mult `>= 2`)
// strict-repeat clause (204) one MULTIPLICITY-BAND axis over AND
// CLOSES the (mult-band × return-shape) 3×3 face on the unique-tie
// subsurface at 9/9. Peer to clause (202)
// ([`T::unique_unique_labels`]) one RETURN-SHAPE axis over
// (label-Vec witness → joined-String witness of the same
// singleton-or-empty binding).
//
// Bimodal-triple positive-arm discipline (SEPARATOR-AGNOSTIC on
// the singleton positive arm): at `T::CARDINALITY == 3` on the
// canonical bimodal triple `[T::ALL[0], T::ALL[0], T::ALL[1]]` for
// every `sep` in `["/", ", ", "|"]`, `T::ALL[1]` sits at count `1`
// (the SOLE unique-band variant), `count_unique_variants` reports
// `1`, `has_unique_unique_variant` holds, guard fires, the
// label-Vec collapses to `vec![T::ALL[1].label()]`, and
// `slice::join` on the singleton returns
// `T::ALL[1].label().to_string()` UNCONDITIONALLY — the separator
// NEVER surfaces in the output because the joined slice is a
// singleton. LOAD-BEARING TRICHOTOMY DISCRIMINATOR from clauses
// (203) + (204) which report `T::ALL[2].label().to_string()` +
// `T::ALL[0].label().to_string()` on the SAME fixture — the three
// positive join-String arms report THREE DIFFERENT witnesses one
// MULTIPLICITY-BAND axis apart, pinning the miss-band /
// strict-repeat / unique-band separation on the JOIN-STRING return
// column under the injective per-slot T::label projection composed
// with `slice::join`.
//
// Matching-singleton positive-arm discipline (LOAD-BEARING
// NON-EMPTY DEGENERATE ARM distinct from clauses (203) + (204)):
// on every matching singleton `[v]` for every `sep`, the target
// hits count `1` (the SOLE unique-band witness), every non-target
// sits at count `0`, `count_unique_variants` reports `1`,
// `has_unique_unique_variant` holds, the label-Vec collapses to
// `vec![v.label()]`, and `slice::join` on the singleton returns
// `v.label().to_string()` — the SEPARATOR-AGNOSTIC positive arm at
// every cardinality. DISTINCT from clause (204) which collapses to
// the empty `String` on every matching singleton AND from clause
// (203) whose singleton behavior is CARDINALITY-dependent
// (`String::new()` at CARDINALITY != 2; the sole absent variant's
// label as bare `String` at CARDINALITY == 2).
//
// The default trait body threads the two-primitive
// `unique_unique_labels + join` composition verbatim and satisfies
// every fixpoint arm + the composition + is-empty coincidence
// identities for free; the assertion catches a future implementor
// whose override drifts the join-String projection loudly rather
// than silently bifurcating the set-level equivalence-partition
// unique-band singleton-or-empty JOIN-STRING witness surface. An
// override that folds onto `String::new()` unconditionally
// bifurcates the matching-singleton positive arms at
// `"" != v.label()` under every sep AND the bimodal-triple
// positive arm at cardinality == 3 at `"" != "beta"` under every
// sep. An override that folds onto `T::ALL[0].label().to_string()`
// unconditionally bifurcates the empty-slice + doubled-full-set
// arms (both expect `""`) at `"alpha" != ""` under every sep AND
// the matching-singleton positive arm at every non-alpha target at
// `"alpha" != v.label()` under every sep.
for sep in ["/", ", ", "|"] {
let lifted_empty = T::unique_unique_labels_joined(empty, sep);
let natural_empty = T::unique_unique_labels(empty).join(sep);
assert_eq!(
lifted_empty, natural_empty,
"{type_name}: T::unique_unique_labels_joined(&[], {sep:?}) drifted from `T::unique_unique_labels(&[]).join({sep:?})` — the composition law MUST hold on the empty slice",
);
assert_eq!(
T::unique_unique_labels_joined(empty, sep),
::std::string::String::new(),
"{type_name}: T::unique_unique_labels_joined(&[], {sep:?}) drifted from the empty-String fixpoint — the empty slice hits zero positions, count_unique_variants == 0, has_unique_unique_variant is false, the label-Vec collapses to vec![], and slice::join on [] is the empty String UNCONDITIONALLY",
);
assert_eq!(
T::unique_unique_labels_joined(empty, sep).is_empty(),
!T::has_unique_unique_variant(empty),
"{type_name}: T::unique_unique_labels_joined(&[], {sep:?}).is_empty() drifted from `!T::has_unique_unique_variant(&[])` — the is-empty coincidence identity MUST hold on the empty slice",
);
let lifted_full = T::unique_unique_labels_joined(T::ALL, sep);
let natural_full = T::unique_unique_labels(T::ALL).join(sep);
assert_eq!(
lifted_full, natural_full,
"{type_name}: T::unique_unique_labels_joined(T::ALL, {sep:?}) drifted from `T::unique_unique_labels(T::ALL).join({sep:?})` — the composition law MUST hold on the full-set slice",
);
let lifted_doubled = T::unique_unique_labels_joined(&doubled_full_set, sep);
let natural_doubled = T::unique_unique_labels(&doubled_full_set).join(sep);
assert_eq!(
lifted_doubled, natural_doubled,
"{type_name}: T::unique_unique_labels_joined(&doubled_full_set, {sep:?}) drifted from `T::unique_unique_labels(&doubled_full_set).join({sep:?})` — the composition law MUST hold on the doubled-full-set slice",
);
assert_eq!(
T::unique_unique_labels_joined(&doubled_full_set, sep),
::std::string::String::new(),
"{type_name}: T::unique_unique_labels_joined(&doubled_full_set, {sep:?}) drifted from the empty-String fixpoint — every variant hits count 2 (strict-repeat, NOT unique-band), count_unique_variants == 0, has_unique_unique_variant is false, and the projection collapses to the empty String at every cardinality",
);
for target in T::ALL.iter().copied() {
let target_label = <T as ClosedSet>::label(target);
let matching_singleton = [target];
// Matching-singleton POSITIVE arm: the target hits count 1
// (the SOLE unique-band witness), every non-target sits at
// count 0, count_unique_variants reports 1,
// has_unique_unique_variant holds, the label-Vec collapses
// to vec![target.label()], and slice::join on the
// singleton returns target.label() as a bare String —
// SEPARATOR-AGNOSTIC because the joined slice is a
// singleton. LOAD-BEARING NON-EMPTY DEGENERATE arm —
// distinct from clause (204) which collapses to the empty
// String on every matching singleton.
assert_eq!(
T::unique_unique_labels_joined(&matching_singleton, sep),
::std::string::ToString::to_string(target_label),
"{type_name}: T::unique_unique_labels_joined([{target_label:?}], {sep:?}) drifted from {target_label:?}.to_string() on every matching singleton — the target hits count 1 (SOLE unique-band witness), count_unique_variants reports 1, has_unique_unique_variant holds, the label-Vec collapses to vec![target.label()], and slice::join on the singleton returns target.label() as a bare String (the separator NEVER surfaces because the joined slice is a singleton)",
);
}
}
if T::CARDINALITY == 3 {
// Bimodal-triple fixture: LOAD-BEARING sole-non-empty positive
// arm on the (`String` × equivalence-partition × mult `== 1` ×
// unique-tie) corner at the canonical cardinality-3 test-module
// window. count_unique_variants reports 1 (T::ALL[1] the SOLE
// unique-band witness at count 1), has_unique_unique_variant
// holds, guard fires, the label-Vec collapses to
// vec![T::ALL[1].label()], and slice::join on the singleton
// returns T::ALL[1].label() as a bare String — SEPARATOR-
// AGNOSTIC because the joined slice is a singleton. Sweep
// three representative separators so a drift on any rendering
// surface fails. LOAD-BEARING mirror of clause (202)'s
// bimodal-triple label-Vec positive arm one RETURN-SHAPE axis
// over on the unique-band unique-tie corner AND LOAD-BEARING
// TRICHOTOMY DISCRIMINATOR from clauses (203) + (204) which
// report T::ALL[2].label() + T::ALL[0].label() on the SAME
// fixture — the three positive join-String arms report THREE
// DIFFERENT witnesses one MULTIPLICITY-BAND axis apart.
let bimodal_triple = [T::ALL[0], T::ALL[0], T::ALL[1]];
let expected_bimodal =
::std::string::ToString::to_string(<T as ClosedSet>::label(T::ALL[1]));
for sep in ["/", ", ", "|"] {
assert_eq!(
T::unique_unique_labels_joined(&bimodal_triple, sep),
expected_bimodal,
"{type_name}: T::unique_unique_labels_joined(&bimodal_triple, {sep:?}) drifted from T::ALL[1].label() as String at cardinality == 3 — count_unique_variants reports 1 (T::ALL[1] the SOLE unique-band witness at count 1), has_unique_unique_variant holds, guard fires, the label-Vec collapses to vec![T::ALL[1].label()], and slice::join on the singleton returns T::ALL[1].label() as a bare String (the separator NEVER surfaces because the joined slice is a singleton). A `vec![]` fold silently bifurcates the LOAD-BEARING positive arm AND its LOAD-BEARING TRICHOTOMY DISCRIMINATION from clauses (203) + (204) which report T::ALL[2].label() + T::ALL[0].label() on the SAME fixture",
);
}
}
}