Documentation

Batteries.Data.List.Count

Counting in lists #

This file proves basic properties of List.countP and List.count, which count the number of elements of a list satisfying a predicate and equal to a given element respectively. Their definitions can be found in Batteries.Data.List.Basic.

count #

theorem List.count_singleton' {α : Type u_1} [DecidableEq α] (a b : α) :
count a [b] = if b = a then 1 else 0
theorem List.count_concat {α : Type u_1} [BEq α] [LawfulBEq α] (a : α) (l : List α) :
count a (l.concat a) = count a l + 1

idxToSigmaCount, sigmaCountToIdx #

def List.idxToSigmaCount {α : Type u_1} [BEq α] [ReflBEq α] (xs : List α) (i : Fin xs.length) :
(x : α) × Fin (count x xs)

idxToSigmaCount is essentially a Fin-to-Fin wrapper for countBefore that also includes the corresponding element.

For example:

idxToSigmaCount [5, 1, 3, 2, 4, 0, 1, 4] 5 = ⟨0, 0⟩
Equations
Instances For
    @[simp]
    theorem List.fst_idxToSigmaCount {α : Type u_1} [BEq α] [ReflBEq α] {xs : List α} {i : Fin xs.length} :
    (xs.idxToSigmaCount i).fst = xs[i]
    @[simp]
    theorem List.snd_idxToSigmaCount {α : Type u_1} [BEq α] [ReflBEq α] {xs : List α} {i : Fin xs.length} :
    (xs.idxToSigmaCount i).snd = countBefore xs[i] xs i,
    @[simp]
    theorem List.coe_snd_idxToSigmaCount {α : Type u_1} [BEq α] [ReflBEq α] {xs : List α} {i : Fin xs.length} :
    (xs.idxToSigmaCount i).snd = countBefore xs[i] xs i
    def List.sigmaCountToIdx {α : Type u_1} [BEq α] (xs : List α) (xc : (x : α) × Fin (count x xs)) :

    sigmaCountToIdx is a _ × Fin-to-Fin wrapper for countBefore.

    For example:

    sigmaCountToIdx [5, 1, 3, 2, 4, 0, 1, 4] ⟨0, 0⟩ = 5
    
    Equations
    Instances For
      @[simp]
      theorem List.coe_sigmaCountToIdx {α : Type u_1} [BEq α] {xs : List α} {xc : (x : α) × Fin (count x xs)} :
      (xs.sigmaCountToIdx xc) = idxOfNth xc.fst xs xc.snd
      @[simp]
      theorem List.sigmaCountToIdx_idxToSigmaCount {α : Type u_1} [BEq α] [ReflBEq α] {xs : List α} {i : Fin xs.length} :
      @[simp]
      theorem List.idxToSigmaCount_sigmaCountToIdx {α : Type u_1} [BEq α] [LawfulBEq α] {xs : List α} {xc : (x : α) × Fin (count x xs)} :