Skip to content

Instantly share code, notes, and snippets.

@Upliner
Last active December 25, 2015 02:29
Show Gist options
  • Save Upliner/6903334 to your computer and use it in GitHub Desktop.
Save Upliner/6903334 to your computer and use it in GitHub Desktop.
My googologic researches :)
import ub_int;
/* ub_int stands for Ultra-Big Integer for operating on numbers far
larger than Graham's number and any other known numbers. */
pure ub_int iterate(ub_int n, ub_int a, ub_int function(ub_int) f) {
ub_int result = a;
for (ub_int i = 0; i < n; i++)
result = f(result);
return result;
}
pure ub_int pow(ub_int a, ub_int b) {
assert(b >= 0);
return iterate(b, 1, (ub_int x) => x * a);
}
pure ub_int hyper(ub_int n, ub_int a, ub_int b) {
assert(n >= 0);
switch (n) {
case 0: return 1 + b;
case 1: return a + b;
case 2: return a * b;
case 3: return pow(a, b);
default: return iterate(b, 1, (ub_int x) => hyper(n-1, a, x));
}
}
pure ub_int recursive_fn(ub_int n, ub_int a, ub_int function(ub_int) f) {
ub_int result = iterate(a, a, f);
if (n <= 0) return result;
return iterate(result, result, (ub_int x) => recursive_fn(n-1, x, f));
}
pure ub_int recursive_hyper(ub_int n, ub_int a) {
return recursive_fn(n, a, (ub_int x) => hyper(x, x, x));
}
pure ub_int function(ub_int) pultiquize(ub_int n, ub_int function(ub_int) f, ub_int function(ub_int) function(ub_int function(ub_int)) pqzer) {
auto result = f;
for (ub_int i = 0; i < n; i++)
result = pqzer(result);
return result;
}
pure ub_int multipultiquize(ub_int a, ub_int function(ub_int) startfunc, ub_int function(ub_int) function(ub_int function(ub_int)) startpqzer) {
auto pqzer = startpqzer;
auto iterfunc = pultiquize(a, startfunc, pqzer);
ub_int cnt = iterfunc(a);
ub_int result = cnt;
for (ub_int i = 0; i < cnt; i++) {
pqzer = (auto f) => pultiquize(result, f, pqzer);
iterfunc = pultiquize(result, iterfunc, pqzer);
result = iterfunc(result);
}
return result;
}
pure ub_int ultra_hyper(ub_int n, ub_int a) {
auto iterfunc = (ub_int x) => recursive_hyper(x, x);
ub_int y = iterfunc(a);
if (n <= 0) return iterfunc(y);
return multipultiquize(y, iterfunc, (auto f) => ((ub_int x) => iterate(ultra_hyper(n-1, f(x)), x, f)));
}
pure ub_int up_hyper(ub_int n, ub_int a, ub_int function(ub_int) startfunc) {
auto iterfunc = startfunc;
ub_int y = iterfunc(a);
if (n <= 0) return y;
return multipultiquize(y, iterfunc, (auto f) => ((ub_int x) => iterate(up_hyper(n-1, f(x), f), x, f)));
}
void main() {
ub_int googol = pow(10,100);
ub_int googolplex = pow(10, googol);
ub_int vps = hyper(4, 10, 600);
ub_int graham = iterate(64, 4, (ub_int x) => hyper(x + 2, 3, 3));
ub_int corporal = iterate(100, 10, (ub_int x) => hyper(x + 2, 10, 10));
ub_int pkvd = iterate(corporal, corporal, (ub_int x) => hyper(x, x, x));
ub_int mpkvd = recursive_hyper(pkvd, pkvd);
ub_int umpkvd = ultra_hyper(mpkvd, mpkvd);
ub_int upmpkvd = up_hyper(umpkvd, umpkvd, (ub_int x) => iterate(umpkvd, x, (ub_int x) => ultra_hyper(x, x)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment