9

There is a kernel function Internal`ToEquivalenceClass.I don't know how to use it.There are some right example right to run

Internal`ToEquivalenceClass[{1, 2, 3}]

(* {1, 2, 3} *)

Internal`ToEquivalenceClass[9]
(* 9 *)

Internal`ToEquivalenceClass[{1, 2., 3}, 9]
(* {1, 2., 3} *)

But the Internal`ToEquivalenceClass[{1, 2., 3}, {5, 6}] will give a error information

And we can find a option of it.

Internal`ToEquivalenceClass // Options

{Heads -> True}

Can anybody the usage and the intention about this function?

Karsten7
  • 27,448
  • 5
  • 73
  • 134
yode
  • 26,686
  • 4
  • 62
  • 167
  • 4
    Umm...it is in `Internal`` context. – Daniel Lichtblau Jul 09 '17 at 14:39
  • 1
    You demonstrate that you are clueless about what the function does, so why do you want to use it? And if you don't want to use it, but are just curious about it, why should we spend our time trying to find out for you? As Daniel Lichtblau points out, it is the Internal context; not meant for users. – m_goldberg Jul 09 '17 at 15:20
  • 1
    @m_goldberg,Daniel Lichtblau I have opened a discuss in Meta.SE here.If most people think I should not take such topic.I will delete it and stop to talk these undocumented question. – yode Jul 09 '17 at 15:54
  • 8
    @m_goldberg This question is like one my earlier questions about an undocumented function, driven purely out of curiosity. My opinion is that this is a perfectly fine question, should not be closed, and that others can benefit from it in the future. – QuantumDot Jul 09 '17 at 17:40
  • @QuantumDot. That's a perfectly valid opinion, but mine happens to be different. – m_goldberg Jul 09 '17 at 17:53

1 Answers1

17

Internal`ToEquivalenceClass[expr, tol] is used to replace floating point numbers in an expression with their equivalence class representatives according to the specified tolerance.

For an example, using machine precision, consider

nums = {0.33000000000000004, 0.33000000000000007, 0.33000000000000010};

The first two numbers are equivalent under the default tolerance which allows a difference in the last binary digit

Gather[nums, Function[Abs[#1 - #2] < 2^-53]] // InputForm

(* {{0.33, 0.33000000000000007}, {0.3300000000000001}} *)

so Internal`ToEquivalenceClass[nums] which is the same as

Internal`ToEquivalenceClass[nums, N[Log[10, 2]]]

returns

(* {0.33000000000000007, 0.33000000000000007, 0.3300000000000002} *)

As the tolerance increases, the equivalence classes become larger: if another bit of tolerance is allowed, all three numbers are considered equivalent

Internal`ToEquivalenceClass[nums, N[Log[10, 2^2]]] // InputForm

(* {0.33000000000000007, 0.33000000000000007, 0.33000000000000007} *)
ilian
  • 25,474
  • 4
  • 117
  • 186