Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mathics/core/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,11 @@ def element_order(self) -> tuple:
if self.is_numeric()
else BASIC_EXPRESSION_ELT_ORDER
),
Monomial({self.name: 1}),
Monomial({str.lower(self.name): 1}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Monomial({str.lower(self.name): 1}),
Monomial({self.name.lower()+self.name.swapcase(): 1}),

# The canonical in for WL is to sort by lowercase first. Hence we must swap the case.
Monomial({str.swapcase(self.name): 1}),
Copy link
Contributor

@mmatera mmatera Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Monomial({str.swapcase(self.name): 1}),

0,
self.name,
str.lower(self.name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
str.lower(self.name),
self.name,

1,
)

Expand Down
4 changes: 4 additions & 0 deletions test/builtin/statistics/test_orderstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def test_canonical_sort():
"{ByteArray[<1>], F[2]}",
hold_expected=True,
)
check_evaluation(
"Sort[{Mathics,Math,ics,mathics}]",
"{ics, Math, mathics, Mathics}",
)
check_evaluation(
r"Sort[Table[IntegerDigits[2^n], {n, 10}]]",
r"{{2}, {4}, {8}, {1, 6}, {3, 2}, {6, 4}, {1, 2, 8}, {2, 5, 6}, {5, 1, 2}, {1, 0, 2, 4}}",
Expand Down
Loading