Macaulay2 / Macaulay2/M2

ModuleMonomLessThan is not a strict comparator for std::sort

Open Beginner friendly
#4,713 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Engine
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

`ModuleMonomLessThan::operator()` in `M2/Macaulay2/e/monomials/monomial-collection.hpp` returns `ModuleMonom::compare(a,b) <= EQ`. `IntsSet::sort` passes it to `std::sort`, which requires a strict weak ordering.

```cpp
int raw[] = {3, 1, 0}; // x
int first[6], second[6];
auto a = monomToModuleMonom(Monom(raw), 1, {first, first+6});
auto b = monomToModuleMonom(Monom(raw), 1, {second, second+6});
ModuleMonomLessThan less;
// Each must be false; each is currently true:
less(a,a);
less(a,b);
less(b,a);
```
This fails irreflexivity even without duplicate entries in a set. Expected comparison should be strict for equal keys.

Reproduced with direct GoogleTest assertions, Debug engine build at c156fdcba4 (Apple Clang 21). No production changes.

### Failing unit-test blocks

- `TEST(MonomialCollections, DISABLED_comparatorIsStrict)` in `M2/Macaulay2/e/unit-tests/MonomialCollectionsTest.cpp`.

These regressions were explicitly run and confirmed to fail against the current implementation. They assert the intended corrected behavior and remain disabled in normal runs until the defect is fixed.

Run from the CMake build directory after building `M2-unit-tests`:

```sh
./Macaulay2/e/M2-unit-tests \
--gtest_also_run_disabled_tests \
--gtest_filter='MonomialCollections.DISABLED_comparatorIsStrict'
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect ModuleMonomLessThan::operator() in M2/Macaulay2/e/monomials/monomial-collection.hpp, then run the disabled MonomialCollections.DISABLED_comparatorIsStrict test from the CMake build directory. The work is done when the comparator satisfies the strict comparisons asserted by that test and the filtered GoogleTest command passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.