theorem proof example program

Theorem. If and are finite sets and has larger Cardinality than , then for any function there exist distinct with . In other words, is not injective.

Source: Kittenlab Lecture 2.

Proof. Suppose no such pair exists. Writing with the distinct, the values are all distinct, so has at least distinct elements — contradicting that is smaller.

Example. Any five points on the unit sphere have four lying in a common closed hemisphere: pick two, they determine a great circle; at least two of the remaining three lie on one of the hemispheres it bounds.

Docs: Kittenlab Lecture 2

Builds on: Function (𝔽Mor) — run that note’s Julia code first.

# Kittenlab Lecture 2: find the collision
function pigeonhole(f::𝔽Mor)
  @assert length(unique!([f.dom...])) > length(unique!([f.codom...]))
  holes = Dict(y => Any[] for y in f.codom)
  for pigeon in f.dom
    push!(holes[f(pigeon)], pigeon)
  end
  for hole in values(holes)
    length(hole) > 1 && return hole
  end
end
#check @Fintype.exists_ne_map_eq_of_card_lt
-- (f : α → β) (h : Fintype.card β < Fintype.card α) : ∃ x y, x ≠ y ∧ f x = f y
import qualified Data.Map as M
pigeonhole :: Ord b => [a] -> (a -> b) -> Maybe [a]
pigeonhole xs f =
  let holes = M.fromListWith (++) [(f x, [x]) | x <- xs]
  in case filter ((> 1) . length) (M.elems holes) of
       (h:_) -> Just h
       []    -> Nothing