When sqrt(-7) exists but sqrt(2) does not
The 32-bit hex numbers 0x9c98c0b5
and 0x63673f4b
are special because, in a well-defined sense, they are values of \(sqrt(-7)\).
See for yourself!
% cat main.cpp
#include <cstdio>
int main(int argc, char **argv) {
int a = 0x9c98c0b5;
printf("a * a + 7 = %d\n", a * a + 7);
return 0;
}
%
% clang++ main.cpp
% ./a.out
a * a + 7 = 0
%
If you square a number then add 7 and get 0 as the result, then that number must be a value of \(sqrt(-7)\), right?
Well, when viewed as real numbers, these are obviously not solutions to \(x^2 + 7 = 0\), but when viewed as 2-adic numbers, they are solutions.
Eric Rowland has a great video introduction to the p-adic numbers:
1 Billion is Tiny in an Alternate Universe: Introduction to p-adic Numbers
It is a great video and talks about how there is no solution for \(x^2 + 1 = 0\) in the 2-adics and also talks about when \(x^2 + 7 = 0\) is true.
The crazy thing is that there is also no solution for \(x^2 - 2 = 0\) in the 2-adics.
So, in a well-defined-sense, \(sqrt(-7)\) exists for the 2-adics, but \(sqrt(2)\) does not.
P.S. These numbers can be extended to 64-bits as 0x19b4bb639c98c0b5
and 0xe64b449c63673f4b
.