/- 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. -/ import FormalConjecturesUtil

Existence of integers $k$ with $k^2 \operatorname{XOR} (k+1)^2 = (2n+1)^2$

a: $a(n) = \text{least } k \text{ such that } \sqrt{k^2 \operatorname{XOR} (k+1)^2} = 2n+1$, $a(n) = -1 \text{ if there is no such } k$. This is equivalent to finding the smallest $k \in \mathbb{N}$ such that $k^2 \oplus (k+1)^2 = (2n+1)^2$. We use the set infimum ($\operatorname{sInf}$) to denote the least element of the set of natural numbers satisfying the condition. Since Mathlib's sInf on a subset of gives a result in , this definition is only completely faithful to the OEIS when the set is non-empty. The OEIS definition implies that the set of k's is non-empty for all n.

References:

    A224515

    arxiv/2605.22763 Advancing Mathematics Research with AI-Driven Formal Proof Search by George Tsoukalas et al.

namespace OeisA224515open Nat Set

a: $a(n) = \text{least } k \text{ such that } \sqrt{k^2 \operatorname{XOR} (k+1)^2} = 2n+1$, $a(n) = -1 \text{ if there is no such } k$. This is equivalent to finding the smallest $k \in \mathbb{N}$ such that $k^2 \oplus (k+1)^2 = (2n+1)^2$. We use the set infimum ($\operatorname{sInf}$) to denote the least element of the set of natural numbers satisfying the condition. Since Mathlib's sInf on a subset of gives a result in , this definition is only completely faithful to the OEIS when the set is non-empty. The OEIS definition implies that the set of k's is non-empty for all n, which is legitimate as shown by the theorem exists_xor_sq_eq below.

noncomputable def a (n : ) : := -- The term (2*n + 1)^2 is the target value. let target_sq : := (2 * n + 1) ^ 2 -- Define the set of candidate k's. sInf { k : | Nat.xor (k ^ 2) ((k + 1) ^ 2) = target_sq }@[category API, AMS 11] lemma A224515_eq (n val : ) (h_in : Nat.xor (val ^ 2) ((val + 1) ^ 2) = (2 * n + 1) ^ 2) (h_min : k < val, Nat.xor (k ^ 2) ((k + 1) ^ 2) (2 * n + 1) ^ 2) : a n = val := n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2a n = val n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2(have target_sq := (2 * n + 1) ^ 2; sInf {k | (k ^ 2).xor ((k + 1) ^ 2) = target_sq}) = val n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2sInf {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2} = val n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2 a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}, val an:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2 (w : ), val < w a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}, a < w n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2 a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}, val a n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2a:ha:a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}val a n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2a:ha:a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}h:¬val aFalse exact h_min a (n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2a:ha:a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}h:¬val aa < val All goals completed! 🐙) ha n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2 (w : ), val < w a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}, a < w n:val:h_in:(val ^ 2).xor ((val + 1) ^ 2) = (2 * n + 1) ^ 2h_min: k < val, (k ^ 2).xor ((k + 1) ^ 2) (2 * n + 1) ^ 2w:hw:val < w a {k | (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2}, a < w All goals completed! 🐙@[category test, AMS 11] lemma a_0 : a 0 = 0 := a 0 = 0 apply A224515_eq 0 0 ((0 ^ 2).xor ((0 + 1) ^ 2) = (2 * 0 + 1) ^ 2 All goals completed! 🐙) k:hk:k < 0(k ^ 2).xor ((k + 1) ^ 2) (2 * 0 + 1) ^ 2; All goals completed! 🐙@[category test, AMS 11] lemma a_1 : a 1 = 4 := a 1 = 4 apply A224515_eq 1 4 ((4 ^ 2).xor ((4 + 1) ^ 2) = (2 * 1 + 1) ^ 2 All goals completed! 🐙) k:hk:k < 4(k ^ 2).xor ((k + 1) ^ 2) (2 * 1 + 1) ^ 2; k:hk:0 < 4(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:1 < 4(1 ^ 2).xor ((1 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:2 < 4(2 ^ 2).xor ((2 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:3 < 4(3 ^ 2).xor ((3 + 1) ^ 2) (2 * 1 + 1) ^ 2 k:hk:0 < 4(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:1 < 4(1 ^ 2).xor ((1 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:2 < 4(2 ^ 2).xor ((2 + 1) ^ 2) (2 * 1 + 1) ^ 2k:hk:3 < 4(3 ^ 2).xor ((3 + 1) ^ 2) (2 * 1 + 1) ^ 2 All goals completed! 🐙@[category test, AMS 11] lemma a_2 : a 2 = 3 := a 2 = 3 apply A224515_eq 2 3 ((3 ^ 2).xor ((3 + 1) ^ 2) = (2 * 2 + 1) ^ 2 All goals completed! 🐙) k:hk:k < 3(k ^ 2).xor ((k + 1) ^ 2) (2 * 2 + 1) ^ 2; k:hk:0 < 3(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 2 + 1) ^ 2k:hk:1 < 3(1 ^ 2).xor ((1 + 1) ^ 2) (2 * 2 + 1) ^ 2k:hk:2 < 3(2 ^ 2).xor ((2 + 1) ^ 2) (2 * 2 + 1) ^ 2 k:hk:0 < 3(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 2 + 1) ^ 2k:hk:1 < 3(1 ^ 2).xor ((1 + 1) ^ 2) (2 * 2 + 1) ^ 2k:hk:2 < 3(2 ^ 2).xor ((2 + 1) ^ 2) (2 * 2 + 1) ^ 2 All goals completed! 🐙@[category test, AMS 11] lemma a_3 : a 3 = 24 := a 3 = 24 apply A224515_eq 3 24 ((24 ^ 2).xor ((24 + 1) ^ 2) = (2 * 3 + 1) ^ 2 All goals completed! 🐙) k:hk:k < 24(k ^ 2).xor ((k + 1) ^ 2) (2 * 3 + 1) ^ 2; k:hk:0 < 24(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:1 < 24(1 ^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((17 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:18 < 24(18 ^ 2).xor ((18 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:19 < 24(19 ^ 2).xor ((19 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:20 < 24(20 ^ 2).xor ((20 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:21 < 24(21 ^ 2).xor ((21 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:22 < 24(22 ^ 2).xor ((22 + 1) ^ 2) (2 * 3 + 1) ^ 2k:hk:23 < 24(23 ^ 2).xor ((23 + 1) ^ 2) (2 * 3 + 1) ^ 2 All goals completed! 🐙@[category test, AMS 11] lemma a_4 : a 4 = 23 := a 4 = 23 apply A224515_eq 4 23 ((23 ^ 2).xor ((23 + 1) ^ 2) = (2 * 4 + 1) ^ 2 All goals completed! 🐙) k:hk:k < 23(k ^ 2).xor ((k + 1) ^ 2) (2 * 4 + 1) ^ 2; k:hk:0 < 23(0 ^ 2).xor ((0 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:1 < 23(1 ^ 2).xor ((1 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:2 < 23(2 ^ 2).xor ((2 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:3 < 23(3 ^ 2).xor ((3 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:4 < 23(4 ^ 2).xor ((4 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:5 < 23(5 ^ 2).xor ((5 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:6 < 23(6 ^ 2).xor ((6 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:7 < 23(7 ^ 2).xor ((7 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:8 < 23(8 ^ 2).xor ((8 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:9 < 23(9 ^ 2).xor ((9 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:10 < 23(10 ^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).xor ((7 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:8 < 23(8 ^ 2).xor ((8 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:9 < 23(9 ^ 2).xor ((9 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:10 < 23(10 ^ 2).xor ((10 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:11 < 23(11 ^ 2).xor ((11 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:12 < 23(12 ^ 2).xor ((12 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:13 < 23(13 ^ 2).xor ((13 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:14 < 23(14 ^ 2).xor ((14 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:15 < 23(15 ^ 2).xor ((15 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:16 < 23(16 ^ 2).xor ((16 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:17 < 23(17 ^ 2).xor ((17 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:18 < 23(18 ^ 2).xor ((18 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:19 < 23(19 ^ 2).xor ((19 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:20 < 23(20 ^ 2).xor ((20 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:21 < 23(21 ^ 2).xor ((21 + 1) ^ 2) (2 * 4 + 1) ^ 2k:hk:22 < 23(22 ^ 2).xor ((22 + 1) ^ 2) (2 * 4 + 1) ^ 2 All goals completed! 🐙

Conjecture: $a(n) \ge 0$, i.e., for every $n$ there exists $k$ such that $\sqrt{k^2 \oplus (k+1)^2} = 2n+1$.

A formal proof has been found with the methods described in arxiv/2605.22763.

@[category research solved, AMS 11, formal_proof using formal_conjectures at "https://github.com/mo271/formal-conjectures/blob/a32396489dcb8f86c3549b93aa358ac6a10a3a1f/FormalConjectures/OEIS/224515.wip.lean#L268"] theorem exists_xor_sq_eq (n : ) : k : , Nat.xor (k ^ 2) ((k + 1) ^ 2) = (2 * n + 1) ^ 2 := n: k, (k ^ 2).xor ((k + 1) ^ 2) = (2 * n + 1) ^ 2 All goals completed! 🐙end OeisA224515