Documentation

CslibFrontier.Tactic.FinsetCard

Presburger cardinality, quorum-intersection, and pigeonhole solver for Finset #

Distributed consensus, quorum-system, and combinatorial proofs repeatedly combine Finset cardinalities with Boolean set algebra (∅, Finset.univ, ∪, ∩, \, ᶜ), point operations ({x}, insert, erase), set relations (⊆, =, ≠, Disjoint, Finset.Nonempty), membership (∈, ∉), Finset.filter subset and disjoint-fiber partitions, embedding/image size bounds (Finset.map, Finset.image), and pigeonhole witness goals (∃ x ∈ S, x ∉ F, S.Nonempty).

finset_card decides this quantifier-free Boolean Algebra with Presburger Arithmetic (BAPA) fragment over each carrier type α present in the goal and hypotheses:

  1. Optional bracket arguments finset_card [d₁, h₁, …] unfold named definitions d₁ in the goal and relevant hypotheses, rewrite with quantified =/↔ lemmas, and add proof hints h₁.
  2. Existential nonemptiness and pigeonhole targets (S.Nonempty, ∃ x ∈ S, x ∉ T, ∃ x, x ∈ S, and ∃ x, x ∉ T under [Fintype α]) reduce to strict positivity of the corresponding Finset.card.
  3. Pre-pass size bridges record (S.map emb).card = S.card, (S.image f).card ≤ S.card, and Fintype.card (Fin n) = n, connecting multiple carrier types when an embedding maps between them.
  4. For each carrier type α, atomic finsets are collected up to a hard cap (maxAtoms = 5, at most 32 Venn cells; points involved only in ∈/∉ without ≠ or {·}/insert/erase contribute zero-atom nonemptiness bounds instead of Venn atoms). Every compound Boolean expression and set relation reduces over a verified Venn-partition tree (vennSum, working both with [Fintype α] via Finset.univ and without [Fintype α] via unionAll) into nonnegative ℕ cell counts, harvested Finset.filter constraints (filter_subset, distinct-value fiber disjointness, and Bool/negation partitions) add zero new atoms, and omega closes the resulting linear system.

Main definitions #

Syntax of compound Boolean Finset expressions over indexed atomic finsets and a bounding ambient finset top.

Truth value of SetExpr under an atomic membership bit-vector bs.

Concrete Finset α denoted by a SetExpr inside ambient finset U over atoms as.

def Cslib.Tactic.FinsetCard.vennSum {α : Type u} [DecidableEq α] (f : List Bool → Bool) (U : Finset α) :
List (Finset α) → ℕ

Sum of Venn-cell cardinalities selected by Boolean valuation f under ambient finset U and atomic finsets as. Uses cond so concrete SetExpr valuations iota-reduce cleanly.

inductive Cslib.Tactic.FinsetCard.AllSubset {α : Type u} (U : Finset α) :
List (Finset α) → Prop

Predicate asserting every atom in as is a subset of ambient finset U.

Finite bounding union of a list of finsets (used when [Fintype α] is unavailable).

Every list of finsets is contained in Finset.univ.

Every list of finsets is contained in unionAll as.

Reflection equation expressing (e.denote U as).card as a Venn-cell sum.

theorem Cslib.Tactic.FinsetCard.card_univ_eq_vennSum {α : Type u} (ft₁ ft₂ : Fintype α) [DecidableEq α] (as : List (Finset α)) :

Reflection equation expressing Fintype.card α as the sum of Venn cells of Finset.univ.

theorem Cslib.Tactic.FinsetCard.subset_denote_mp {α : Type u} [DecidableEq α] {U : Finset α} {as : List (Finset α)} (hU : FinsetCard.AllSubset U as) {e₁ e₂ : FinsetCard.SetExpr} {s t : Finset α} (hs : s = SetExpr.denote U as e₁) (ht : t = SetExpr.denote U as e₂) (h : s ⊆ t) :
FinsetCard.vennSum (fun (bs : List Bool) => e₁.evalBool bs && !e₂.evalBool bs) U as = 0

Translate s ⊆ t into vennSum (s \ t) = 0.

theorem Cslib.Tactic.FinsetCard.disjoint_denote_mp {α : Type u} [DecidableEq α] {U : Finset α} {as : List (Finset α)} (hU : FinsetCard.AllSubset U as) {e₁ e₂ : FinsetCard.SetExpr} {s t : Finset α} (hs : s = SetExpr.denote U as e₁) (ht : t = SetExpr.denote U as e₂) (h : Disjoint s t) :
FinsetCard.vennSum (fun (bs : List Bool) => e₁.evalBool bs && e₂.evalBool bs) U as = 0

Translate Disjoint s t into vennSum (s ∩ t) = 0.

theorem Cslib.Tactic.FinsetCard.not_disjoint_denote_mp {α : Type u} [DecidableEq α] {U : Finset α} {as : List (Finset α)} (hU : FinsetCard.AllSubset U as) {e₁ e₂ : FinsetCard.SetExpr} {s t : Finset α} (hs : s = SetExpr.denote U as e₁) (ht : t = SetExpr.denote U as e₂) (h : ¬Disjoint s t) :
0 < FinsetCard.vennSum (fun (bs : List Bool) => e₁.evalBool bs && e₂.evalBool bs) U as

Translate ¬ Disjoint s t into 0 < vennSum (s ∩ t).

theorem Cslib.Tactic.FinsetCard.eq_denote_mp {α : Type u} [DecidableEq α] {U : Finset α} {as : List (Finset α)} (hU : FinsetCard.AllSubset U as) {e₁ e₂ : FinsetCard.SetExpr} {s t : Finset α} (hs : s = SetExpr.denote U as e₁) (ht : t = SetExpr.denote U as e₂) (h : s = t) :
FinsetCard.vennSum (fun (bs : List Bool) => e₁.evalBool bs != e₂.evalBool bs) U as = 0

Translate s = t into vennSum (s ∆ t) = 0.

theorem Cslib.Tactic.FinsetCard.ne_denote_mp {α : Type u} [DecidableEq α] {U : Finset α} {as : List (Finset α)} (hU : FinsetCard.AllSubset U as) {e₁ e₂ : FinsetCard.SetExpr} {s t : Finset α} (hs : s = SetExpr.denote U as e₁) (ht : t = SetExpr.denote U as e₂) (h : s ≠ t) :
0 < FinsetCard.vennSum (fun (bs : List Bool) => e₁.evalBool bs != e₂.evalBool bs) U as

Translate s ≠ t into 0 < vennSum (s ∆ t).

Instance-insensitive SetExpr normalization bridges #

Coherence of Finset.univ across any two Fintype α instances.

theorem Cslib.Tactic.FinsetCard.union_eq_of_eq {α : Type u} (d₁ d₂ : DecidableEq α) {s₁ s₂ t₁ t₂ : Finset α} (hs : s₁ = t₁) (ht : s₂ = t₂) :
s₁ ∪ s₂ = t₁ ∪ t₂

Coherence of ∪ (Max.max) across any two DecidableEq α instances.

theorem Cslib.Tactic.FinsetCard.inter_eq_of_eq {α : Type u} (d₁ d₂ : DecidableEq α) {s₁ s₂ t₁ t₂ : Finset α} (hs : s₁ = t₁) (ht : s₂ = t₂) :
s₁ ∩ s₂ = t₁ ∩ t₂

Coherence of ∩ (Min.min) across any two DecidableEq α instances.

theorem Cslib.Tactic.FinsetCard.sdiff_eq_of_eq {α : Type u} (d₁ d₂ : DecidableEq α) {s₁ s₂ t₁ t₂ : Finset α} (hs : s₁ = t₁) (ht : s₂ = t₂) :
s₁ \ s₂ = t₁ \ t₂

Coherence of \ (SDiff.sdiff) across any two DecidableEq α instances.

theorem Cslib.Tactic.FinsetCard.compl_eq_sdiff_univ_of_eq {α : Type u} (ft₁ ft₂ : Fintype α) (d₁ d₂ : DecidableEq α) {s t : Finset α} (hs : s = t) :

Rewrite sᶜ to Finset.univ \ t across any Fintype and DecidableEq instances.

theorem Cslib.Tactic.FinsetCard.insert_eq_union_of_eq {α : Type u} (d₁ d₂ : DecidableEq α) (x : α) {s t : Finset α} (hs : s = t) :
insert x s = {x} ∪ t

Rewrite insert x s to {x} ∪ t across any two DecidableEq α instances.

theorem Cslib.Tactic.FinsetCard.erase_eq_sdiff_of_eq {α : Type u} (d₁ d₂ : DecidableEq α) {s t : Finset α} (x : α) (hs : s = t) :
s.erase x = t \ {x}

Rewrite s.erase x to t \ {x} across any two DecidableEq α instances.

Pigeonhole and Finset.filter structural lemmas #

theorem Cslib.Tactic.FinsetCard.exists_mem_notMem_of_card_sdiff_pos {α : Type u} [DecidableEq α] {s t : Finset α} (h : 0 < (s \ t).card) :
∃ x ∈ s, x ∉ t

Witness ∃ x ∈ s, x ∉ t from 0 < (s \ t).card.

theorem Cslib.Tactic.FinsetCard.exists_notMem_of_card_sdiff_univ_pos {α : Type u} [Fintype α] [DecidableEq α] {t : Finset α} (h : 0 < (Finset.univ \ t).card) :
∃ (x : α), x ∉ t

Witness ∃ x, x ∉ t from 0 < (Finset.univ \ t).card.

theorem Cslib.Tactic.FinsetCard.disjoint_filter_eq_of_ne {α : Type u} {β : Type v} {s₁ s₂ : Finset α} (f : α → β) {v₁ v₂ : β} [d₁ : DecidablePred fun (x : α) => f x = v₁] [d₂ : DecidablePred fun (x : α) => f x = v₂] (hne : v₁ ≠ v₂) :
Disjoint ({x ∈ s₁ | f x = v₁}) ({x ∈ s₂ | f x = v₂})

Distinct fibers s₁.filter (f · = v₁) and s₂.filter (f · = v₂) are disjoint when v₁ ≠ v₂.

theorem Cslib.Tactic.FinsetCard.filter_eq_true_union_filter_eq_false {α : Type u} [DecidableEq α] (s : Finset α) (f : α → Bool) [d₁ : DecidablePred fun (x : α) => f x = true] [d₂ : DecidablePred fun (x : α) => f x = false] :
{x ∈ s | f x = true} ∪ {x ∈ s | f x = false} = s

Boolean fibers f x = true and f x = false partition s.

Prove a quantifier-free Finset cardinality, quorum-intersection, set-relation (⊆, =, ≠, Disjoint, Finset.Nonempty), membership (∈, ∉), or pigeonhole (∃ x ∈ S, x ∉ F) goal by Venn-region decomposition (up to 5 atomic finsets per carrier type) followed by omega.

  • finset_card inspects the goal and all local hypotheses across every carrier type α.
  • finset_card [d₁, h₁, …] additionally unfolds named definitions d₁, rewrites with quantified =/↔ lemmas, and supplies extra proof terms h₁ (such as product bounds or list-nodup cardinalities).