2
$\begingroup$

I have a list T which contains 3 + 4*E^(2*Pi*I/3). Yet MemberQ[ T , 3 + 4*(-1)^(2/3) ] returns false.

One can check for themselves with MemberQ[{3 + 4*E^(2*Pi*I/3)}, 3 + 4*(-1)^(2/3)]. It will return False.

How can I tweak this so that the above returns True? Am I fumbling some detail regarding the principal branch?

$\endgroup$
6
  • 2
    $\begingroup$ From the docs Possible Issues section for MemberQ: MemberQ tests for structural matches, not numerical equality . You could try this instead: ContainsAny[T, {3 + 4*(-1)^(2/3)}, SameTest -> Equal] $\endgroup$
    – flinty
    Aug 9, 2020 at 22:16
  • 1
    $\begingroup$ ^ or alternatively, because ContainsAny is a bit slow, you could ComplexExpand your list T and the item before using MemberQ which (fingers crossed) will put them in the same structural form. $\endgroup$
    – flinty
    Aug 9, 2020 at 22:18
  • 1
    $\begingroup$ Following the suggestion above: lis = {E^(2*Pi*I/3), (-1)^(2/3 )} //ComplexExpand //InputForm (* {-1/2 + (I/2)*Sqrt[3], -1/2 + (I/2)*Sqrt[3]} *) $\endgroup$ Aug 9, 2020 at 22:32
  • 1
    $\begingroup$ Or @@ (Equal[#, 3 + 4*(-1)^(2/3)] & /@ T) $\endgroup$
    – Bob Hanlon
    Aug 9, 2020 at 23:41
  • 1
    $\begingroup$ I find that ExpToTrig[] is faster than ComplexExpand[] for this sort of thing. $\endgroup$ Aug 10, 2020 at 4:52

0

Your Answer

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

Browse other questions tagged or ask your own question.