Can't retrieve a Key in an Association, but the key is listed in it

Hello,

I’ve encountered a strange behavior in Mathematica, and it is quickly reproducible

Table[q, {q, 0.01, 0.99, 0.01}]
Table[-Sqrt[2] InverseErfc[2 q],{q, 0.01, 0.99, 0.01}]
ndQuantile = AssociationThread[%% -> %] 

Calling ndQuantile[0.35] prints that this Key is missing, but I most definitely can see it listed in the Association dataset. Calling every other keys seem to work fine (0.4, 0.45 etc).

Using Table to make a list of every values in the Association lets me retrieve the desired value, so I’m lost.

Table[ndQuantile[x],{x,0.01,0.99,0.01}]
%[[35]]

Am I doing something wrong ?

Thank you.

Clarisse,

the problem becomes apparent when you look at your keys in FullForm or InputForm:

Keys[ndQuantile] // FullForm

I do not know about your needs here, but would Interpolation not be a better choice?

Regards – Henrik

Hello Henrik,

Thank you for your input.

Inspecting what you suggested, I came up with the solution to my problem :

Table[N[q/100], {q, 1, 99, 1}]
Table[-Sqrt[2] InverseErfc[2 q], {q, 0.01, 0.99, 0.01}]
ndQuantile = AssociationThread[%% -> %]

I suppose that it’s more robust to iterate inside a Table with integers.

As Henrik points out, it’s a bit hard to see why you would want to do this. Would it not be simpler to write a function:

ndQuantile[q_] := -Sqrt[2] InverseErfc[2 q]

So you can just do

ndQuantile[0.35]

Frankly, it is not the second-best idea to use Reals as keys.
.35 is not one of the keys,

Actually, it is 0.35000000000000003.