{
  "verdict": "pass",
  "decl": "LambekMoser.inverse_iff_partition",
  "author_status": "proved",
  "lean_source": "import Mathlib.Data.Nat.Count\nimport Mathlib.Data.Nat.Nth\nimport Mathlib.Tactic\n\n/-!\n# Lambek–Moser theorem (Wikidata Q6481192)\n\nFor monotone `f, g : ℕ → ℕ`, `f i ≤ j ↔ i < g j` for all `i, j` if and only if the\nranges of `i ↦ i + f i` and `j ↦ j + g j` are disjoint and have union `ℕ`.\nMoreover, every pair of infinite complementary subsets of `ℕ` is the pair of ranges of\nexactly one such pair of monotone functions.\n\nThe traditional one-based formulation is `f(m) < n ↔ g(n) ≥ m`, with the two shifted\nranges partitioning the positive integers. The change of indexing gives the zero-based\nform above.\n-/\n\nnamespace LambekMoser\n\nopen Nat\n\ndef Partition (s t : Set ℕ) : Prop := Disjoint s t ∧ s ∪ t = Set.univ\n\ndef Inverse (f g : ℕ → ℕ) : Prop := ∀ i j, f i ≤ j ↔ i < g j\n\ndef RangePartition (f g : ℕ → ℕ) : Prop :=\n  Partition (Set.range fun i => i + f i) (Set.range fun j => j + g j)\n\ndef PairRanges (s t : Set ℕ) (f g : ℕ → ℕ) : Prop :=\n  Monotone f ∧ Monotone g ∧ Set.range (fun i => i + f i) = s ∧\n    Set.range (fun j => j + g j) = t\n\ntheorem shifted_strictMono (f : ℕ → ℕ) (hf : Monotone f) :\n    StrictMono (fun i => i + f i) := by\n  intro i j hij\n  have hfj : f i ≤ f j := hf (Nat.le_of_lt hij)\n  change i + f i < j + f j\n  exact (Nat.add_lt_add_right hij (f i)).trans_le (Nat.add_le_add_left hfj j)\n\ntheorem shifted_ge_index (f : ℕ → ℕ) (i : ℕ) : i ≤ i + f i := by omega\n\ntheorem inverse_cutoff (f g : ℕ → ℕ) (h : Inverse f g) (i j : ℕ) :\n    i + f i ≤ i + j ↔ i + j < j + g j := by\n  constructor\n  · intro hi\n    have hf : f i ≤ j := by omega\n    have hg : i < g j := (h i j).mp hf\n    omega\n  · intro hb\n    have hg : i < g j := by omega\n    have hf : f i ≤ j := (h i j).mpr hg\n    omega\n\ntheorem inverse_ranges_disjoint (f g : ℕ → ℕ) (h : Inverse f g) :\n    Disjoint (Set.range fun i => i + f i) (Set.range fun j => j + g j) := by\n  rw [Set.disjoint_left]\n  rintro n ⟨i, hi⟩ ⟨j, hj⟩\n  change i + f i = n at hi\n  change j + g j = n at hj\n  have heq : i + f i = j + g j := hi.trans hj.symm\n  by_cases hfi : f i ≤ j\n  · have hig : i < g j := (h i j).mp hfi\n    omega\n  · have hgi : g j ≤ i := Nat.not_lt.mp (fun hh => hfi ((h i j).mpr hh))\n    omega\n\n/-- Counting a strictly increasing enumeration below a cutoff is the same as counting its range. -/\ntheorem count_range_eq_count_index (a : ℕ → ℕ) (ha : StrictMono a)\n    (hlower : ∀ i, i ≤ a i) (n : ℕ)\n    [DecidablePred (fun x => x ∈ Set.range a)] :\n    Nat.count (fun x => x ∈ Set.range a) n = Nat.count (fun i => a i < n) n := by\n  classical\n  rw [Nat.count_eq_card_filter_range, Nat.count_eq_card_filter_range]\n  symm\n  apply Finset.card_bij (fun i _ => a i)\n  · intro i hi\n    simp only [Finset.mem_filter, Finset.mem_range] at hi ⊢\n    exact ⟨hi.2, ⟨i, rfl⟩⟩\n  · intro i hi j hj heq\n    exact ha.injective heq\n  · intro y hy\n    simp only [Finset.mem_filter, Finset.mem_range, Set.mem_range] at hy\n    obtain ⟨x, rfl⟩ := hy.2\n    refine ⟨x, ?_, rfl⟩\n    simp only [Finset.mem_filter, Finset.mem_range]\n    exact ⟨lt_of_le_of_lt (hlower x) hy.1, hy.1⟩\n\ntheorem count_reverse (p : ℕ → Prop) [DecidablePred p] (n : ℕ) :\n    Nat.count (fun i => p (n - 1 - i)) n = Nat.count p n := by\n  classical\n  rw [Nat.count_eq_card_filter_range, Nat.count_eq_card_filter_range]\n  apply Finset.card_bij (fun i _ => n - 1 - i)\n  · intro i hi\n    simp only [Finset.mem_filter, Finset.mem_range] at hi ⊢\n    rcases hi with ⟨hi, hpi⟩\n    have hpos : 0 < n := by omega\n    have hbound : n - 1 - i ≤ n - 1 := Nat.sub_le _ _\n    exact ⟨by omega, hpi⟩\n  · intro i hi j hj heq\n    simp only [Finset.mem_filter, Finset.mem_range] at hi hj\n    have hi' : i ≤ n - 1 := by omega\n    have hj' : j ≤ n - 1 := by omega\n    have h1 : n - 1 - i + i = n - 1 := Nat.sub_add_cancel hi'\n    have h2 : n - 1 - j + j = n - 1 := Nat.sub_add_cancel hj'\n    omega\n  · intro y hy\n    simp only [Finset.mem_filter, Finset.mem_range] at hy ⊢\n    rcases hy with ⟨hylt, hpy⟩\n    have hyle : y ≤ n - 1 := by omega\n    have hxle : n - 1 - y ≤ n - 1 := Nat.sub_le _ _\n    have hxlt : n - 1 - y < n := by omega\n    have hinv : n - 1 - (n - 1 - y) = y := by omega\n    refine ⟨n - 1 - y, ⟨hxlt, ?_⟩, ?_⟩\n    · simpa [hinv] using hpy\n    · exact hinv\n\ntheorem nth_eq_strict_enumeration (a : ℕ → ℕ) (ha : StrictMono a)\n    (hlower : ∀ i, i ≤ a i) (i : ℕ) :\n    Nat.nth (fun x => x ∈ Set.range a) i = a i := by\n  classical\n  have hmem : a i ∈ Set.range a := ⟨i, rfl⟩\n  have hidx : Nat.count (fun k => a k < a i) (a i) = i := by\n    rw [Nat.count_eq_card_filter_range]\n    have hset : {k ∈ Finset.range (a i) | a k < a i} = Finset.range i := by\n      ext k\n      simp only [Finset.mem_filter, Finset.mem_range]\n      constructor\n      · rintro ⟨_, hki⟩\n        exact (ha.lt_iff_lt).mp hki\n      · intro hki\n        have hli := hlower i\n        exact ⟨by omega, (ha.lt_iff_lt).2 hki⟩\n    rw [hset, Finset.card_range]\n  have hcount := count_range_eq_count_index a ha hlower (a i)\n  rw [hidx] at hcount\n  calc\n    Nat.nth (fun x => x ∈ Set.range a) i =\n        Nat.nth (fun x => x ∈ Set.range a)\n          (Nat.count (fun x => x ∈ Set.range a) (a i)) := by rw [hcount]\n    _ = a i := Nat.nth_count hmem\ntheorem count_compl_of_partition {p q : ℕ → Prop} [DecidablePred p] [DecidablePred q]\n    (h : ∀ n, q n ↔ ¬ p n) :\n    ∀ n, Nat.count p n + Nat.count q n = n := by\n  intro n\n  induction n with\n  | zero => simp\n  | succ n ih =>\n      rw [Nat.count_succ, Nat.count_succ]\n      have hn : (if p n then 1 else 0) + (if q n then 1 else 0) = 1 := by\n        by_cases hp : p n\n        · have hq : ¬ q n := fun hq => (h n).mp hq hp\n          simp [hp, hq]\n        · have hq : q n := (h n).2 hp\n          simp [hp, hq]\n      omega\n\ntheorem count_compl_below {p q : ℕ → Prop} [DecidablePred p] [DecidablePred q]\n    {n : ℕ} (h : ∀ i < n, q i ↔ ¬ p i) :\n    Nat.count p n + Nat.count q n = n := by\n  have aux : ∀ k ≤ n, Nat.count p k + Nat.count q k = k := by\n    intro k\n    induction k with\n    | zero => intro; simp\n    | succ k ih =>\n        intro hk\n        have ih' := ih (by omega)\n        rw [Nat.count_succ, Nat.count_succ]\n        have hkn := h k (by omega)\n        by_cases hp : p k\n        · have hq : ¬ q k := fun hq => (hkn.mp hq) hp\n          simp [hp, hq]\n          omega\n        · have hq : q k := (hkn.mpr hp)\n          simp [hp, hq]\n          omega\n  exact aux n le_rfl\n\ntheorem inverse_range_count (f g : ℕ → ℕ) (hf : Monotone f) (hg : Monotone g)\n    (hinv : Inverse f g) (n : ℕ)\n    [DecidablePred (fun x => x ∈ Set.range fun i => i + f i)]\n    [DecidablePred (fun x => x ∈ Set.range fun j => j + g j)] :\n    Nat.count (fun x => x ∈ Set.range fun i => i + f i) n +\n      Nat.count (fun x => x ∈ Set.range fun j => j + g j) n = n := by\n  classical\n  let a : ℕ → ℕ := fun i => i + f i\n  let b : ℕ → ℕ := fun j => j + g j\n  have ha : StrictMono a := by\n    exact shifted_strictMono f hf\n  have hb : StrictMono b := by\n    exact shifted_strictMono g hg\n  have halower : ∀ i, i ≤ a i := by intro i; exact shifted_ge_index f i\n  have hblower : ∀ j, j ≤ b j := by intro j; exact shifted_ge_index g j\n  have hcomp : ∀ i < n, (b (n - 1 - i) < n) ↔ ¬ a i < n := by\n    intro i hin\n    have hsum : i + (n - 1 - i) = n - 1 := by omega\n    have hcut := inverse_cutoff f g hinv i (n - 1 - i)\n    change a i ≤ i + (n - 1 - i) ↔ i + (n - 1 - i) < b (n - 1 - i) at hcut\n    rw [hsum] at hcut\n    omega\n  have hc := count_compl_below (p := fun i => a i < n)\n    (q := fun i => b (n - 1 - i) < n) hcomp\n  rw [count_reverse (fun i => b i < n) n] at hc\n  have hca := count_range_eq_count_index a ha halower n\n  have hcb := count_range_eq_count_index b hb hblower n\n  calc\n    Nat.count (fun x => x ∈ Set.range fun i => i + f i) n +\n        Nat.count (fun x => x ∈ Set.range fun j => j + g j) n =\n        Nat.count (fun x => x ∈ Set.range a) n + Nat.count (fun x => x ∈ Set.range b) n := by\n          rfl\n    _ = Nat.count (fun i => a i < n) n + Nat.count (fun j => b j < n) n := by\n          rw [hca, hcb]\n    _ = n := hc\n\ntheorem inverse_implies_partition (f g : ℕ → ℕ) (hf : Monotone f) (hg : Monotone g)\n    (hinv : Inverse f g) : RangePartition f g := by\n  classical\n  constructor\n  · exact inverse_ranges_disjoint f g hinv\n  · apply Set.eq_univ_iff_forall.mpr\n    intro x\n    have hcount := inverse_range_count f g hf hg hinv\n    have h0 := hcount x\n    have h1 := hcount (x + 1)\n    rw [Nat.count_succ, Nat.count_succ] at h1\n    have hone :\n        (if x ∈ Set.range (fun i => i + f i) then 1 else 0) +\n          (if x ∈ Set.range (fun j => j + g j) then 1 else 0) = 1 := by\n      omega\n    have hmem : x ∈ Set.range (fun i => i + f i) ∨\n        x ∈ Set.range (fun j => j + g j) := by\n      by_cases hp : x ∈ Set.range (fun i => i + f i)\n      · exact Or.inl hp\n      · right\n        by_contra hq\n        simp [hp, hq] at hone\n    simpa [Partition, Set.mem_union] using hmem\n\ntheorem partition_implies_inverse (f g : ℕ → ℕ) (hf : Monotone f) (hg : Monotone g)\n    (hpart : RangePartition f g) : Inverse f g := by\n  classical\n  let a : ℕ → ℕ := fun i => i + f i\n  let b : ℕ → ℕ := fun j => j + g j\n  let p : ℕ → Prop := fun x => x ∈ Set.range a\n  let q : ℕ → Prop := fun x => x ∈ Set.range b\n  have ha : StrictMono a := shifted_strictMono f hf\n  have hb : StrictMono b := shifted_strictMono g hg\n  have halower : ∀ i, i ≤ a i := by intro i; exact shifted_ge_index f i\n  have hblower : ∀ j, j ≤ b j := by intro j; exact shifted_ge_index g j\n  have hpinf : (Set.ofPred p).Infinite := Set.infinite_range_of_injective ha.injective\n  have hqinf : (Set.ofPred q).Infinite := Set.infinite_range_of_injective hb.injective\n  have hcomp : ∀ x, q x ↔ ¬ p x := by\n    intro x\n    constructor\n    · intro hxq hxp\n      have hdis : Disjoint (Set.range a) (Set.range b) := by\n        simpa [RangePartition, Partition, a, b] using hpart.1\n      exact (Set.disjoint_left.mp hdis) hxp hxq\n    · intro hnp\n      have hunion : Set.range a ∪ Set.range b = Set.univ := by\n        simpa [RangePartition, Partition, a, b] using hpart.2\n      have hcov : x ∈ Set.range a ∪ Set.range b := by rw [hunion]; exact Set.mem_univ x\n      rcases hcov with hxa | hxb\n      · exact (hnp hxa).elim\n      · exact hxb\n  have hcounts : ∀ n, Nat.count p n + Nat.count q n = n :=\n    count_compl_of_partition hcomp\n  intro i j\n  let N := i + j\n  have hna : Nat.nth p i = a i := nth_eq_strict_enumeration a ha halower i\n  have hnb : Nat.nth q j = b j := nth_eq_strict_enumeration b hb hblower j\n  have hleft : f i ≤ j ↔ i < Nat.count p (N + 1) := by\n    have hnth := Nat.lt_nth_iff_count_lt hpinf (a := i) (b := N + 1)\n    rw [hna] at hnth\n    change f i ≤ j ↔ i < Nat.count p (N + 1)\n    rw [hnth]\n    dsimp [N, a]\n    omega\n  have hright : i < g j ↔ Nat.count q (N + 1) ≤ j := by\n    have hnth := Nat.count_le_iff_le_nth hqinf (a := N + 1) (b := j)\n    rw [hnb] at hnth\n    change i < g j ↔ Nat.count q (N + 1) ≤ j\n    rw [hnth]\n    dsimp [N, b]\n    omega\n  have hsum := hcounts (N + 1)\n  dsimp [N] at hsum hleft hright ⊢\n  rw [hleft, hright]\n  omega\n\ntheorem inverse_iff_partition (f g : ℕ → ℕ) (hf : Monotone f) (hg : Monotone g) :\n    Inverse f g ↔ RangePartition f g := by\n  constructor\n  · exact inverse_implies_partition f g hf hg\n  · exact partition_implies_inverse f g hf hg\n\ntheorem existsUnique_monotone_pair {s t : Set ℕ} (hs : s.Infinite) (ht : t.Infinite)\n    (hpart : Partition s t) :\n    ∃! fg : (ℕ → ℕ) × (ℕ → ℕ), PairRanges s t fg.1 fg.2 := by\n  classical\n  let p : ℕ → Prop := fun x => x ∈ s\n  let q : ℕ → Prop := fun x => x ∈ t\n  have hpinf : (Set.ofPred p).Infinite := by simpa [p] using hs\n  have hqinf : (Set.ofPred q).Infinite := by simpa [q] using ht\n  have hcomp : ∀ x, q x ↔ ¬ p x := by\n    intro x\n    constructor\n    · intro hq hp\n      exact (Set.disjoint_left.mp hpart.1) hp hq\n    · intro hp\n      have hx : x ∈ s ∪ t := by rw [hpart.2]; exact Set.mem_univ x\n      rcases hx with hsx | htx\n      · exact (hp hsx).elim\n      · exact htx\n  have hcounts : ∀ n, Nat.count p n + Nat.count q n = n :=\n    count_compl_of_partition hcomp\n  let f : ℕ → ℕ := fun i => Nat.count q (Nat.nth p i)\n  let g : ℕ → ℕ := fun j => Nat.count p (Nat.nth q j)\n  have hshiftf : ∀ i, i + f i = Nat.nth p i := by\n    intro i\n    have hcountp := Nat.count_nth_of_infinite hpinf i\n    have hc := hcounts (Nat.nth p i)\n    dsimp [f]\n    omega\n  have hshiftg : ∀ j, j + g j = Nat.nth q j := by\n    intro j\n    have hcountq := Nat.count_nth_of_infinite hqinf j\n    have hc := hcounts (Nat.nth q j)\n    dsimp [g]\n    omega\n  have hf : Monotone f := by\n    dsimp [f]\n    exact (Nat.count_monotone q).comp (Nat.nth_monotone hpinf)\n  have hg : Monotone g := by\n    dsimp [g]\n    exact (Nat.count_monotone p).comp (Nat.nth_monotone hqinf)\n  have hrangef : Set.range (fun i => i + f i) = s := by\n    rw [show (fun i => i + f i) = Nat.nth p from funext hshiftf]\n    rw [Nat.range_nth_of_infinite hpinf]\n    ext x\n    simp [p]\n  have hrangeg : Set.range (fun j => j + g j) = t := by\n    rw [show (fun j => j + g j) = Nat.nth q from funext hshiftg]\n    rw [Nat.range_nth_of_infinite hqinf]\n    ext x\n    simp [q]\n  refine ⟨(f, g), ⟨hf, hg, hrangef, hrangeg⟩, ?_⟩\n  intro fg hfg\n  rcases hfg with ⟨hmonoF, hmonoG, hrangeF, hrangeG⟩\n  apply Prod.ext\n  · funext i\n    have ha : StrictMono (fun k => k + fg.1 k) := shifted_strictMono fg.1 hmonoF\n    have hlower : ∀ k, k ≤ k + fg.1 k := by intro k; omega\n    have hpred : (fun x => x ∈ Set.range (fun k => k + fg.1 k)) = p := by\n      funext x\n      apply propext\n      change x ∈ Set.range (fun k => k + fg.1 k) ↔ x ∈ s\n      rw [hrangeF]\n    have henum := nth_eq_strict_enumeration (fun k => k + fg.1 k) ha hlower i\n    rw [hpred] at henum\n    have hsame := hshiftf i\n    dsimp [f] at hsame\n    change Nat.nth p i = i + fg.1 i at henum\n    dsimp [f]\n    omega\n  · funext j\n    have hb : StrictMono (fun k => k + fg.2 k) := shifted_strictMono fg.2 hmonoG\n    have hlower : ∀ k, k ≤ k + fg.2 k := by intro k; omega\n    have hpred : (fun x => x ∈ Set.range (fun k => k + fg.2 k)) = q := by\n      funext x\n      apply propext\n      change x ∈ Set.range (fun k => k + fg.2 k) ↔ x ∈ t\n      rw [hrangeG]\n    have henum := nth_eq_strict_enumeration (fun k => k + fg.2 k) hb hlower j\n    rw [hpred] at henum\n    have hsame := hshiftg j\n    dsimp [g] at hsame\n    change Nat.nth q j = j + fg.2 j at henum\n    dsimp [g]\n    omega\n\n#print axioms inverse_ranges_disjoint\n#print axioms inverse_iff_partition\n#print axioms existsUnique_monotone_pair\n\nend LambekMoser\n",
  "source_sha256": "0cbf6a40a48464ad96acfe824cc3c38a11e5a19a48c7883c7df866bfa310bd9b",
  "build_output": "Verified both archive SHA-256 digests against fetch.json before extraction. Built the unchanged file in a fresh folder containing only LambekMoser.lean, using the prebuilt packages bundle for Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842 and Lean 4.36.0 (611c117bfaf7b7ae1cfcf246ce6fba31e8f509e9). lean -DautoImplicit=false LambekMoser.lean exited 0. No warnings or errors. The forbidden-token scan found no matches. The source itself prints the following axiom dependencies.\n'LambekMoser.inverse_ranges_disjoint' depends on axioms: [propext, Classical.choice, Quot.sound]\n'LambekMoser.inverse_iff_partition' depends on axioms: [propext, Classical.choice, Quot.sound]\n'LambekMoser.existsUnique_monotone_pair' depends on axioms: [propext, Classical.choice, Quot.sound]\n",
  "fidelity_review": {
    "main": "For arbitrary f and g from ℕ to ℕ, the two hypotheses are exactly weak monotonicity, one for each function. Inverse expands to ∀ i j, f i ≤ j ↔ i < g j. RangePartition applies Partition to the two specified shifted ranges. Partition expands to Disjoint s t ∧ s ∪ t = Set.univ. The outer iff proves both directions, with every natural number included in the coverage claim.",
    "companion": "LambekMoser.existsUnique_monotone_pair quantifies over arbitrary infinite sets S and T of naturals with the same disjointness and coverage condition. It gives an ExistsUnique over ordered pairs of total natural-valued functions. PairRanges expands to monotonicity of each component and the two separately oriented equalities of ranges with S and T, so uniqueness is of the functions themselves. The main iff also gives the inverse relation for the pair.",
    "check": "Two separate scratch examples typechecked by applying the submitted declarations directly at the fully expanded vetted statements. The claims have substantive content, for instance f(i) = i and g(j) = j + 1 give the even and odd parts.",
    "one_based": "The module docstring states both versions and identifies reindexing. In detail, put F(m) = f(m − 1) and G(n) = g(n − 1) for positive m and n. With m = i + 1 and n = j + 1, f(i) ≤ j becomes F(m) < n and i < g(j) becomes m ≤ G(n). The shifted ranges are each translated by +1. This verifies the requested natural-valued, two-infinite-part form."
  },
  "prior_work": {
    "summary": "No earlier proof of both vetted claims was found in the checked public sources. Global priority is UNVERIFIED.",
    "mathlib": {
      "snapshot": "55b1401a3a21c8aebb70df9d5f815fd75828fa90",
      "finding": "Searched the Mathlib master source snapshot for the theorem name and variants, Wikidata ID, and declaration names. The only target-specific hit was the title-only entry in docs/1000.yaml. The rendered missing list names the theorem and the finished list has no matching entry. Reviewed the adjacent Nat.nth/Nat.count Galois connection and the Rayleigh/Beatty partition results. These cover enumeration and special sequence families, respectively.",
      "sources": [
        "https://api.github.com/repos/leanprover-community/mathlib4/commits/55b1401a3a21c8aebb70df9d5f815fd75828fa90",
        "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/docs/1000.yaml",
        "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/Mathlib/Data/Nat/Nth.lean",
        "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/Mathlib/NumberTheory/Rayleigh.lean",
        "https://leanprover-community.github.io/1000-missing.html",
        "https://leanprover-community.github.io/1000.html"
      ]
    },
    "pull_requests": {
      "finding": "GitHub issue search returned zero open Mathlib PRs for Lambek Moser and zero Mathlib PRs for Q6481192, including closed PRs in the latter query.",
      "sources": [
        "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Lambek+Moser",
        "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+Q6481192"
      ]
    },
    "github": {
      "finding": "Searched the lean-genius main snapshot, including proofs/Proofs, for name variants, the Wikidata ID and both declaration names. Inspected nearby complementary-set and Beatty references in the proof directory. No matching theorem was found. Broad public web searches and GitHub repository and issue searches found no earlier Lean proof. GitHub-wide code search is UNVERIFIED because its API returned HTTP 401 and requires authentication.",
      "lean_genius_snapshot": "d8540c5a48f69a9f57b87c549c6e09dad63a0670",
      "sources": [
        "https://github.com/rjwalters/lean-genius/tree/main/proofs/Proofs",
        "https://api.github.com/repos/rjwalters/lean-genius/git/trees/d8540c5a48f69a9f57b87c549c6e09dad63a0670",
        "https://api.github.com/search/issues?q=%22Lambek-Moser%22+Lean",
        "https://api.github.com/search/repositories?q=Lambek-Moser+Lean"
      ],
      "unverified_code_search_url": "https://api.github.com/search/code?q=LambekMoser+language%3ALean"
    },
    "zulip": {
      "finding": "Searched 98 public stream topic indexes for Lambek, Moser, the Wikidata ID and complementary sequences, including two indexes recovered by retrying with corrected URLs. Read the matching maths topic from September 2019. It discusses complementary enumeration, denumerability of infinite subsets and Figure-Figure sequences. No proof of the stated inverse/partition equivalence appeared there. Other message bodies and unarchived discussions are UNVERIFIED.",
      "sources": [
        "https://leanprover-community.github.io/archive/",
        "https://leanprover-community.github.io/archive/stream/116395-maths/topic/complementary.20sequences.html"
      ]
    }
  },
  "explanation": "Adding the index makes each nondecreasing sequence strictly increasing. Under the inverse relation, the two shifted terms at indices i and j lie on opposite sides of the cutoff i + j, which rules out equality. Below any positive cutoff n, match index i with n − 1 − i. Exactly one of the corresponding shifted terms lies below n. Strict increase lets the proof turn those index counts into range counts, so together the ranges contain n entries below n. Comparing cutoffs x and x + 1 gives coverage at x. Conversely, for complementary ranges, the counts below i + j + 1 add to i + j + 1. The ranks of the two shifted terms give the desired inverse inequalities from that count identity. For the companion, enumerate each set in increasing order and define each function by counting how many terms of the other set precede that enumerated value. These counts are monotone and add to the enumeration index to give the enumerated value. Any competing shifted sequence is a strictly increasing enumeration of the same set, so each shifted value agrees at its index. Canceling the index gives pointwise equality of both functions.",
  "database_entry": {
    "wikidata_id": "Q6481192",
    "title": "Lambek–Moser theorem",
    "decl": "LambekMoser.inverse_iff_partition",
    "file": "LambekMoser.lean",
    "yaml": "Q6481192:\n  title: Lambek–Moser theorem\n  decls:\n    - LambekMoser.inverse_iff_partition\n    - LambekMoser.existsUnique_monotone_pair\n  url: https://api.imd.fun/artifacts/2f7f10d81a993b3eb438d1efce5fe35cda18eb438b215670fdeca028bc94c4cb\n"
  },
  "stuck": null,
  "repairs": [],
  "sources": [
    "https://api.imd.fun/artifacts/2f7f10d81a993b3eb438d1efce5fe35cda18eb438b215670fdeca028bc94c4cb",
    "https://github.com/Identity-md/lean-bundles/releases/download/pequalnp-e125f04d0dc6/fetch.json",
    "https://leanprover-community.github.io/1000-missing.html",
    "https://leanprover-community.github.io/1000.html",
    "https://api.github.com/repos/leanprover-community/mathlib4/commits/55b1401a3a21c8aebb70df9d5f815fd75828fa90",
    "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/docs/1000.yaml",
    "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/Mathlib/Data/Nat/Nth.lean",
    "https://raw.githubusercontent.com/leanprover-community/mathlib4/55b1401a3a21c8aebb70df9d5f815fd75828fa90/Mathlib/NumberTheory/Rayleigh.lean",
    "https://api.github.com/repos/rjwalters/lean-genius/git/trees/d8540c5a48f69a9f57b87c549c6e09dad63a0670",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+is%3Aopen+Lambek+Moser",
    "https://api.github.com/search/issues?q=repo%3Aleanprover-community%2Fmathlib4+is%3Apr+Q6481192",
    "https://api.github.com/search/issues?q=%22Lambek-Moser%22+Lean",
    "https://api.github.com/search/repositories?q=Lambek-Moser+Lean",
    "https://leanprover-community.github.io/archive/",
    "https://leanprover-community.github.io/archive/stream/116395-maths/topic/complementary.20sequences.html",
    "https://www.cambridge.org/core/journals/canadian-mathematical-bulletin/article/partitions-of-the-natural-numbers/3FB4F6EC03277DE87281A1C673527337"
  ]
}
