Message Boards Message Boards

3 Replies
0 Total Likes
View groups...
Share this post:

Conversion of symbolic formulae to numbers; function Ordering

Posted 9 years ago
In[84]:= angles = {\[Pi] - ArcTan[7/26], \[Pi] - 
   ArcTan[37/50], \[Pi] + ArcTan[65/28], \[Pi]/2, ArcTan[45/74], 
  2 \[Pi] - ArcTan[93/82]}

Out[84]= {\[Pi] - ArcTan[7/26], \[Pi] - ArcTan[37/50], \[Pi] + 
  ArcTan[65/28], \[Pi]/2, ArcTan[45/74], 2 \[Pi] - ArcTan[93/82]}

In[85]:= Ordering[angles]

Out[85]= {4, 1, 5, 2, 6, 3}

In[87]:= Ordering[1.0*angles]

Out[87]= {5, 4, 2, 1, 3, 6}

Why is Out[87] and Out[85] different? I thought Out[87] is the correct result.

Thank you for any guidance.

POSTED BY: Dale Bent
3 Replies

The angles are exact symbolic expressions. Ordering uses by default a lexicographic order, or something like that. When you write Ordering[1.0*angles] you multiply the angles by a machine precisione number, that converts everything to machine numbers, for which the default order is numeric. Try giving the ordering function explicitly:

angles = {\[Pi] - ArcTan[7/26], \[Pi] - ArcTan[37/50], \[Pi] + 
   ArcTan[65/28], \[Pi]/2, ArcTan[45/74], 
  2 \[Pi] - ArcTan[93/82]}; Ordering[angles, All, Less]
POSTED BY: Gianluca Gorni

You might wonder "but why would it have this behavior?"

Sort will try to sort "most" numbers by their value. It does this for floating point values, Integers, and Rationals.

In the general case, sorting numbers is impossible. If you have two symbolic numbers, there is no algorithm that you can use which will detemine which number is larger than the other. There is no algorithm which can determine whether two symbolic numbers are equal. So strictly speaking, there is no algorithm which implements ordering the way you want for any set of symbolic numbers.

POSTED BY: Sean Clarke

Thank you, Gianluca and Sean, for explaining this surprising result. I understand what happened, and why, but I don't fully grasp the underlying point about symbolic numbers. I spent quite a lot of time trying to figure out what was going wrong, but was unable to do so from the online documentation. Thanks again.

POSTED BY: Dale Bent
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract