0
|
3446 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# 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.
3 Replies
Sort By:
Posted 9 years ago
 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 9 years ago
 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 9 years ago
 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]