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$
  • 3
    $\begingroup$ So do you want this function to return unevaluated for EulerGamma, as an example? $\endgroup$ – J. M. will be back soon Mar 5 '18 at 15:28
  • $\begingroup$ @J.M. Yes, or something along the lines of "unknown" $\endgroup$ – Klangen Mar 5 '18 at 15:56
  • $\begingroup$ A related question. $\endgroup$ – J. M. will be back soon Mar 6 '18 at 0:28
  • $\begingroup$ Irrational is not the same as transcendental: $\sqrt{2}$ is irrational, but it's not transcendental. $\endgroup$ – corey979 Jun 22 '18 at 15:35
7
$\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$
  • 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$ – J. M. will be back soon Mar 6 '18 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 '18 at 8:35
  • $\begingroup$ @Pickle, I do not; that is why I was giving it as a cautionary tale. $\endgroup$ – J. M. will be back soon Mar 6 '18 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 '18 at 9:42
  • 1
    $\begingroup$ @Pickle wolframalpha.com/input/… Wolfram|Alpha doesn't know that one either. $\endgroup$ – eyorble Mar 6 '18 at 9:46
7
$\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, privacy policy and cookie policy

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