Saturday, April 26, 2025

My Mersenne Primality Testing Algorithm

I'm not sure how fast it is compared to GIMPS, but it is acurate for all Mersenne or Fermat primes. See my article Value-Counting Up to N for why.

import sys
import time

# Remove the limit
sys.set_int_max_str_digits(0)

i = 0

def signal_handler(sig, frame):
	global i
	if sig == signal.SIGINT:
		print("index = %i" % (i))
	sys.exit(0)

def int_sqrt(n):
	"""
	Calculate the integer square root of a non-negative integer n.
	This function returns the largest integer whose square is less than or equal to n.
	"""
	if n < 0:
		raise ValueError("Cannot calculate square root of a negative number.")
	if n == 0:
		return 0
	x = n
	y = 1
	i = 0
	while x > y:
		x = (x + y) // 2
		y = n // x
	return x

def prime_power(n):
	signal.signal(signal.SIGINT, signal_handler)
	total = 0
	half_n = (n + 1) // 2
#	limit = half_n
#	limit = math.ceil((half_n*(half_n + 1) // 2 + 1) / n)
	limit = (n + 13)//8
	start_time = time.perf_counter()
	end_time = start_time

	global i
	for i in range(2, limit):
		# border_value represents the number that ends on the last
		# column when all numbers up to it are added and wrapped.
		border_value = int((int_sqrt(8 * i * n + 1) - 1)/2)
		total = (border_value * (border_value + 1)//2)
		elapsed_time = end_time - start_time
		if (total == (i * n)):# or (total + (border_value + 1)//2 == (i * n)):
			print("%i" % (border_value))
			return
		end_time = time.perf_counter()
		elapsed_time = end_time - start_time
		if elapsed_time > WAIT_TIME:
			start_time = end_time
			end_time = time.perf_counter()
	print("\tprime_power")

print("p\tborder\tprime power")

prime_power(2**89-1)

Saturday, April 05, 2025

Busy Beaver Number 5 is Alive!

In theoretical computer science, the objective of the busy beaver is to find a terminating program of a given size that (depending on definition) either produces the most output possible, denoted by BB(n), or runs for the longest number of steps.

The latest value for n = 5 was recently discovered.

The known values are BB(1) = 1, BB(2) = 6, BB(3) = 21, BB(4) = 107, BB(5) = 47,176,870.

Click here for more information.

Monday, March 31, 2025

An Amazing Approximation to e

An amazing pandigital approximation to e that is correct to 18,457,734,525,360,901,453,873,570 decimal places is given by:

`e\approx(1+9^(−4^(6⋅7)))^(3^(2^85))`

It was discovered by Richard Sabey in 2004.

Proof:

`(1+9^(−4^(6⋅7)))^(3^(2^85))=(1+9^(−4^42))^(3^(2^85))`

`=(1+9^(−4^42))^(3^(2*2^84))`

`=(1+9^(−4^42))^(3^(2*2^84))`

`=(1+9^(−4^42))^(9^(2^(84)))`

`=(1+9^(−4^42))^(9^(4^42))`

`=(1+\frac{1}{9^(4^42)})^(9^(4^42))`

`=(1+\frac{1}{n})^n`.

Monday, March 24, 2025

Permutation Rotations

In this paper, we discuss certain properties of permutation rotations on each other.

Click here to read my paper.