I have some numerical code involving complex numbers representing points on a plane. Some of these are equal but not identical, ie

{Exp[2 Pi I (-1./10)], ..., Exp[2 Pi I (9./10)]}

I want to make (the equivalent of) a dictionary mapping each to its coordinate in the list (because using Position repeatedly would take too long). But both Downvalues and matching rules (with a Dispatch table) match based on the form of the expression rather than its value (and Hash hashes based on the form of the expression as well).
Eg, if

{a == b, a===b}
==> {True, False}

f[a] = 1; {f[a], f[b]}
{1, f[b]}

Is there some way to associate the points with their position (with faster than O(n) lookup) based on their value? I feel like there should also be some way to do it using rounding, but I haven't gotten it to work.

  • 1
    $\begingroup$ Hello Zaq. I believe a similar question has been asked before. (I shall look for it.) One possibility is to use Round (with a second parameter) to quantize your data. $\endgroup$ – Mr.Wizard May 16 '14 at 20:17
  • 1
    $\begingroup$ Not a duplicate, but related: (15907). And this is the one I think I was remembering: (1072) -- also not an exact duplicate, but quite close. $\endgroup$ – Mr.Wizard May 16 '14 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.