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?
PossibleZeroQmight be of some help. – Spawn1701D Jun 05 '13 at 19:46MemberQ[{Sqrt[2], Sqrt[3], Sin[\[Pi]/5], GoldenRatio, Root[#^3 - 2 &, 1]}, x_ /; RootReduce[x - 2^(1/3)] == 0]... – J. M.'s missing motivation Jun 05 '13 at 19:47PossibleZeroQ[ # - 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 – Artes Jun 05 '13 at 21:42