Please take a look at the following code:
Sort[{1, y, x}, Greater]
Max[{1, x, y}]
x = 1
y = 2
Sort[{1, y, x}, Greater]
Max[{1, x, y}]
It is interesting to note that the first Sort always produce a definite result while the first Max does not, even when Greater is specified. Note I have not given any numerical values for x and y. Why is this and how can I have a Sort function behave the same way as the Max (or Min) function?
Thanks!
BTW, I am using Mma 7.0
From the help:
So, what you want is another function, not Sort[] …
Edit
Here is a way to force only numerical sort under your premises:
Usage:
Please be aware that
Each Symbol in the list are going to be evaluated twice, once for checking if it’s numeric, and then for sorting. That could be circumvented by storing the intermediate result before taking the NumericQ. Edit Thinking again, I’m not quite sure … perhaps someone else can clarify on this one.
An expression is considered a numeric quantity if it is either an explicit number or a mathematical constant such as Pi, or is a function that has attribute NumericFunction and all of whose arguments are numeric quantities. In most cases, NumericQ[expr] gives True whenever N[expr] would yield an explicit number.
By changing NumericQ for StringQ or whatever you want (or adding it as a parameter for sortN[], you may select the Type you want to force and sort.