1-- Least members of inhabited sets of natural numbers, in ZF.2-- Part of Cumulus, the Grace17 mathematics library.3-- Copyright (c) 2026 Grant Passmore.4-- Released under the Apache License 2.0. See LICENSE in the repository root.5-- Authors: Grant Passmore67-- Copyright (c) 2026 Grant Passmore. Apache License 2.0.8module Grace.Cumulus.Nat.Least9import Order10import Set.Core1112-- Minimality is expressed by membership here; the public order law below13-- hides the von Neumann representation. No arbitrary choice is involved.14defunique leastNatural (S : Set) (n ∈ ℕ) :=15 n ∈ S ∧ (∀ m ∈ n, ¬m ∈ S)16requires inhabited : Nonempty(S)17requires naturals : S ⊆ ℕ18proof19have nonempty := Nonempty.ne_empty at S with inhabited20obtain⟨n, member, minimal⟩:=set.foundation at S with nonempty21unfold Subset at naturals22have natural := naturals with n, member23witness n24refine⟨natural, member, minimal⟩25uniqueness26intros n nNatural nData k kNatural kData27rcases nData with⟨nMember, nMinimal⟩28rcases kData with⟨kMember, kMinimal⟩29have nNat := nat.omega.backward at n with nNatural30have kNat := nat.omega.backward at k with kNatural31have comparison := Less.trichotomy at n, k with*32cases comparison with before | rest33 . have inside := membership.of_Less at n, k with*, before34exfalso35exact kMinimal with n, inside, nMember36 . cases rest with same | after37 . exact same38 . have inside := membership.of_Less at k, n with*, after39exfalso40exact nMinimal with k, inside, kMember4142theorem leastNatural.member (S : Set)43requires inhabited : Nonempty(S)44requires naturals : S ⊆ ℕ45shows leastNatural(S) ∈ S46proof47simp [leastNatural.selected]4849theorem leastNatural.least (S : Set, m : Nat)50requires inhabited : Nonempty(S)51requires naturals : S ⊆ ℕ52requires member : m ∈ S53shows leastNatural(S) ≤ m54proof55have selected := leastNatural.selected at S with*56rcases selected with⟨natural, chosen, minimal⟩57have chosenNat := nat.omega.backward with natural58by_contra notLeast59have before := Less.of_not_LessEqual with*60have inside := membership.of_Less with*, before61exact minimal with m, inside, member62