/- Copyright 2026 The Formal Conjectures Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -/ module public import FormalConjecturesUtil public import FormalConjectures.OEIS.«105033» /-! # Conjectures associated with A102371 The sequence $a(n)$ is defined by the recurrence relation $a(1)=1$, and for $n>1$, $a(n) = a(n-1) \operatorname{XOR} (a(n-1) + n)$. The conjecture asks if $a(n) = 2^n - 1 - \operatorname{A105033}(n-1)$ for $n \ge 1$. *References:* - [A102371](https://oeis.org/A102371) -/ @[expose] public section namespace OeisA102371 open Nat open Int /-- The primary defining sequence `a`. $a(n)$ is defined by the recurrence relation $a(1)=1$, and for $n>1$, $a(n) = a(n-1) \operatorname{XOR} (a(n-1) + n)$, where $\operatorname{XOR}$ is the bitwise exclusive-or operator (`^^^`). -/ def a : ℕ → ℕ | 0 => 0 | 1 => 1 | (n' + 2) => let anMinus1 := a (n' + 1) anMinus1 ^^^ (anMinus1 + (n' + 2)) /-- Term theorems verifying the first few values of the sequence against the official OEIS b-file -/ @[category test, AMS 11] theorem a_1 : a 1 = 1 := by rfl @[category test, AMS 11] theorem a_2 : a 2 = 2 := by rfl @[category test, AMS 11] theorem a_3 : a 3 = 7 := by rfl @[category test, AMS 11] theorem a_4 : a 4 = 12 := by rfl @[category test, AMS 11] theorem a_5 : a 5 = 29 := by rfl set_option linter.style.formal_proof_palomar false in /-- Do we have $a(n) = 2^n - 1 - \operatorname{A105033}(n-1)$ for $n \ge 1$? Note: The OEIS comment suggests $n-1$ which means this applies at least for $n \ge 1$, as we assume $\operatorname{A105033}(\mathbb{N})$ is defined on $\mathbb{N}$. We include the case $n=1$ which relies on $A105033(0)$, which is 0. -/ @[category research solved, question, AMS 11, formal_proof using lean4 at "https://github.com/KitaKen1/oeis-a102371/blob/d80fba9/lean/OeisA102371FC.lean#L490-L497"] theorem conjecture : ∀ n : ℕ, 0 < n → a n = 2^n - 1 - OeisA105033.a (n - 1) := by sorry end OeisA102371