4
$\begingroup$

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?

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

2 Answers 2

8
$\begingroup$
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.

$\endgroup$
5
  • 4
    $\begingroup$ 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. $\endgroup$ Mar 6, 2018 at 0:07
  • $\begingroup$ @J.M. Thank you - do you have a better solution? If so, I would be happy to accept it. $\endgroup$
    – Klangen
    Mar 6, 2018 at 8:35
  • $\begingroup$ @Pickle, I do not; that is why I was giving it as a cautionary tale. $\endgroup$ Mar 6, 2018 at 8:37
  • $\begingroup$ Then it looks like the free Alpha has a feature that its expensive brother does not have? $\endgroup$
    – Klangen
    Mar 6, 2018 at 9:42
  • 1
    $\begingroup$ @Pickle wolframalpha.com/input/… Wolfram|Alpha doesn't know that one either. $\endgroup$
    – eyorble
    Mar 6, 2018 at 9:46
9
$\begingroup$

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[2]]
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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.