Skip to content

Instantly share code, notes, and snippets.

@aburousan
Created August 5, 2022 10:47
Show Gist options
  • Save aburousan/6662efee6e0e0428c3b32c467f6e35d7 to your computer and use it in GitHub Desktop.
Save aburousan/6662efee6e0e0428c3b32c467f6e35d7 to your computer and use it in GitHub Desktop.
check irrationality for any number using integral root theorem (IRT)
from sympy import minimal_polynomial, Poly, root, divisors, pi
def check_irrational(m):
result = True
p = minimal_polynomial(m)
print("Minimal Polynomial of ",m , " is = ",p)
pol = Poly(p)
a_0 = pol.all_coeffs()[-1]
print(" The a_0 is = ", a_0)
div_p = divisors(a_0)
div_n = [-1*i for i in div_p]
all_div = div_p + div_n
print(" All possible integer roots = ", all_div)
for j in all_div:
val = pol.eval(j)
if val == 0:
result = False
break
if result:
print(m, " is an Irrational Number.")
else:
print(m, "is a Integer.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment