4
$\begingroup$

I want to sort some exponential numbers like {2^2,3^3,4^2} and i want The result {2^2,4^2,3^3}. But Mathematica Sort function apply's the powers in the result and return's {4,16,27}. How can i get the result in the same form as input?

$\endgroup$
  • 8
    $\begingroup$ Something like SortBy[Inactivate[{2^2, 3^3, 4^2}, Power], Activate]? $\endgroup$ – J. M.'s discontentment May 12 at 13:43
  • $\begingroup$ @J. M.: Exactly,Thank you. $\endgroup$ – Arman May 12 at 14:06
  • $\begingroup$ If you understand how that snippet works, please consider answering your own question. $\endgroup$ – J. M.'s discontentment May 12 at 17:07
5
$\begingroup$

All credits goes to J. M.'s technical difficulties♦

The trick is to use the Inactivate function to prevent Mathematica to apply the powers.

Inactivate[{2^2, 3^3, 4^2}, Power]

Then use SortBy function to compare the Active forms of the elements.

SortBy[Inactivate[{2^2, 3^3, 4^2}, Power], Activate]

Result:

{2^2,4^2,3^3}
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.