Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created June 3, 2023 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hermann-SW/362858051f7b7a850c163cd5144256c3 to your computer and use it in GitHub Desktop.
Save Hermann-SW/362858051f7b7a850c163cd5144256c3 to your computer and use it in GitHub Desktop.
Determinine percentages of "is_prime(f_x(p))" with "f_x(p) = round_to_odd(p * x)"
# pylint:disable=C0103, C0114, C0116, W0611
from math import sqrt, floor, pi, e
from sympy import nextprime, isprime
def digits(n):
return len(str(n))
phi = (sqrt(5) + 1) / 2
def f(n):
assert isprime(n)
x = floor(phi * n) # * e # * pi
return x if x % 2 else x + 1
def out(b):
print(b[0] + b[1], b, b[1] / (b[0] + b[1]))
def doit(end):
l = 1
b = [0, 0]
p = 2
while p <= end:
y = int(isprime(f(p)))
b[y] = b[y] + 1
l = p
p = nextprime(p)
if digits(p) > digits(l):
out(b)
out(b)
doit(100000000)
@Hermann-SW
Copy link
Author

Hermann-SW commented Jun 3, 2023

Followup of:
https://twitter.com/HermannSW/status/1664928016407953408

"multiplicative twin primes" wrt "round_to_odd()" occur quite often for irrational numbers phi/e/pi:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment