# Check if number is irrational/transcendental

Mathematica provides functions to test whether a number is an integer, even or odd, prime, rational, real or complex. However, I could not find any explicit way to determine whether a number is irrational, or more precisely transcendental.

For instance, Alpha provides a means of determining such properties by simply asking:

is pi transcendental?


which will return "true" or "false". However, I could not find any matching function in Mathematica. Any suggestions?

• So do you want this function to return unevaluated for EulerGamma, as an example? – J. M. is away Mar 5 '18 at 15:28
• @J.M. Yes, or something along the lines of "unknown" – Klangen Mar 5 '18 at 15:56
• A related question. – J. M. is away Mar 6 '18 at 0:28
• Irrational is not the same as transcendental: $\sqrt{2}$ is irrational, but it's not transcendental. – corey979 Jun 22 '18 at 15:35

## 2 Answers

istranscendental[x_] := ! Element[x, Algebraics]


To the extent that Mathematica is aware of the algebraic numbers, this should work. EulerGamma, for example, is returned unevaluated, while Pi returns True and 2 returns False.

• This works for simple cases, but is not completely foolproof. As an example, the expression HypergeometricPFQ[{1/5, 2/5, 3/5, 4/5}, {1/2, 3/4, 5/4}, 3125/256] is a root of the polynomial $$x^5-x+1$$ but feeding this expression into this test will yield an unevaluated result. – J. M. is away Mar 6 '18 at 0:07
• @J.M. Thank you - do you have a better solution? If so, I would be happy to accept it. – Klangen Mar 6 '18 at 8:35
• @Pickle, I do not; that is why I was giving it as a cautionary tale. – J. M. is away Mar 6 '18 at 8:37
• Then it looks like the free Alpha has a feature that its expensive brother does not have? – Klangen Mar 6 '18 at 9:42
• @Pickle wolframalpha.com/input/… Wolfram|Alpha doesn't know that one either. – eyorble Mar 6 '18 at 9:46

We can use RootApproximant and PossibleZeroQ to guess if a number is algebraic or not.

PossibleAlgebraic[x_] :=
With[{res = Element[x, Algebraics]},
res /; BooleanQ[res]
]

PossibleAlgebraic[x_?NumericQ] /; !InexactNumberQ[x] :=
With[{guess = RootApproximant[x]},
Quiet[PossibleZeroQ[x - guess]] /; Element[guess, Algebraics]
]

PossibleAlgebraic[_?NumericQ] = False;


Some tests:

PossibleAlgebraic[Sqrt]

True

PossibleAlgebraic[HypergeometricPFQ[{1/5, 2/5, 3/5, 4/5}, {1/2, 3/4, 5/4}, 3125/256]]

True

PossibleAlgebraic[π]

False

PossibleAlgebraic[EulerGamma]

False