I need to check an algebraic number for membership in a list of algebraic numbers. The numbers can be expressed in different forms (combinations of radicals, Root
objects, trig functions), but the check should be exact. Now I use the following code:
ContainsAlgebraicQ[list_, a_] :=
MatchQ[Intersection[ list, {a}, SameTest -> (MinimalPolynomial[#1 - #2] === (#&) &)], {_}]
but in some cases evaluation of MinimalPolynomial
takes significant time, although I only want to check the difference for zero. Is there a better approach for my task?
PossibleZeroQ
might be of some help. $\endgroup$MemberQ[{Sqrt[2], Sqrt[3], Sin[\[Pi]/5], GoldenRatio, Root[#^3 - 2 &, 1]}, x_ /; RootReduce[x - 2^(1/3)] == 0]
... $\endgroup$PossibleZeroQ[ # - a, "ExactAlgebraics"]@list
, or justMemberQ[PossibleZeroQ[ #, Method -> "ExactAlgebraics"]& @ list, True]
. This post is closely related: Most efficient way to determine conclusively whether an algebraic number is zero $\endgroup$