Skip to content

fix(data): a divisor or an exponent that a case makes 0 is read as 0 - #2097

Open
FBumann wants to merge 5 commits into
mainfrom
fix/cased-divisor
Open

FBumann wants to merge 5 commits into
mainfrom
fix/cased-divisor

Conversation

@FBumann

@FBumann FBumann commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Prompt: Fix the open specsolve bugs

Note

The following content was generated by AI.

A divisor that a cases: region makes 0 is refused as a zero divisor. The refusal no longer asks for missing rows of d, which has every row. An exponent that a case makes 0 now raises to 1.

parameters:  { d: { dims: [g] } }        # a row at a and at b
expressions:
  e: { dims: [g], cases: { on: { when: "d > 0", expression: "0" } }, otherwise: d }
constraints: { k: { dims: [g], expression: "x / e <= 1" } }
# before
DataError: constraint 'k': parameter 'd' is used as a divisor but covers 2 fewer coordinates than it is indexed over. […]
  Supply the missing rows, or declare the parameter `missing: absent` to drop those rows.
# after
DataError: constraint 'k': 2 value(s) are not finite where the model divides by 'd': a divisor is zero there, or a value is infinite, and the model needs a finite number.
  Supply finite, non-zero values, or mask the coordinates out with a where.
Cause, the second bug, gates, mutation table
  • Re-ran the issue on mathspec 0.4.0. 1 - 1 in a case no longer shows the bug: it already reads "not finite where the model divides by 'd'". The literal 0 still shows it.
  • Cause: a case worth the literal 0 builds no term (cases in compiler.py). When one term is left under a region, _added_up returned it as it was, so the coordinates the zero region claims read null. A null divisor is refused as a missing row.
  • Fix: a lone term under a region is added up like several (summed_onto), so outside its region it reads 0. One condition in _added_up.
  • Second bug, same cause, no issue filed: 2 ** e read null where e is that zero. That bounds x <= 2 ** e by 0 there, and drops the row of x * 2 ** e <= 10 there. A silent wrong answer: relational 4.0 vs linopy 5.0, and 102.5 vs 12.5. My first fix kept powers on the old path (absent != 'spreads' or …). The suite survived deleting that clause, and a probe showed the clause only kept this bug. So the clause is gone, and the power has its own strict-xfail-first test.
  • Message: names d, the parameter the divisor reads, as for x / (d - 2). Not e: every divisor message names parameters, and naming the expression would change both lanes' messages for every divisor.
  • Tests, in tests/test_arithmetic_laws.py, beside the zero-divisor cases:
    • a-case-worth-zero in test_a_zero_divisor_under_a_variable_is_refused_on_both_lanes, which also asserts that missing rows is absent from the message
    • a-case-worth-zero in test_a_zero_divisor_on_a_constant_side_is_refused_on_both_lanes
    • test_an_exponent_a_case_makes_zero_raises_to_one, parametrized for the constant side and beside a variable
    • Each was committed as a strict xfail, or watched to fail on the broken tree, before the fix.
  • Gates, run through uv because pixi is not installed. They stand in for pixi run check:
    • uv run pytest: 5884 passed, 574 skipped, 4 xfailed
    • uv run ruff check .: all checks passed
    • uv run ruff format --check .: 437 files already formatted
    • uv run pyrefly check: 0 errors
  • Not run: docs-build, docs-test, test-via-pyarrow, test-floors, test-pyodide.
  • Not done: a read (result.evaluate('x / e')) of the same zero case is still refused with the missing-rows wording, reported_divisor_message. A read adds up with hole semantics, and the code relies on that in test_a_read_through_a_cased_divisor_is_refused_where_the_case_that_applies_has_no_row.

Mutation table, taken by hand because tools/mutate.py deletes lines and cannot drop half a condition. Clean tree, git checkout -- restore, __pycache__ dropped on both sides, full suite each time:

mutation result
len(terms) == 1 and terms[0].region is None → len(terms) == 1 caught: 4 failed, the 2 divisor and 2 exponent cases
(earlier draft) absent != 'spreads' or dropped still green, so the clause was removed

Fixes #2064


Generated by Claude Code

… missing rows

Strict xfail on #2064.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1SdobWD7mq3V7guXh
A cases: region worth the literal 0 builds no term, so a divisor left with
one term under a region read the coordinates that region claims as null,
and was refused as missing rows of a parameter that has every row. A lone
divisor term under a region is now added up like several, reading zero
outside its region, and refused as a zero divisor.

Fixes #2064.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1SdobWD7mq3V7guXh
Strict xfail: the relational lane drops or zeroes the row instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1SdobWD7mq3V7guXh
A lone term under a cases: region is added up for a power's operand too, so
the coordinates a region worth the literal 0 claims read 0 rather than null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018B3nA1SdobWD7mq3V7guXh
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 23 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e70c0e06-ef9b-41a6-be6c-e371932bbb25
Commits

Reviewing files that changed from the base of the PR and between 4a3dc84 and 6e7e762.

Files selected for processing: 3

  • CHANGELOG.md
  • src/specsolve/_engine/compiler.py
  • tests/test_arithmetic_laws.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 specsolve | 🛠️ Build #35995451 | 📁 Comparing 6e7e762 against latest (4a3dc84)

  🔍 Preview build  

1 file changed
± reference/changelog/index.html

@codspeed

codspeed Bot commented Nov 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 114 untouched benchmarks
⏩ 307 skipped benchmarks1


Comparing fix/cased-divisor (6e7e762) with main (4a3dc84)

Open in CodSpeed

Footnotes

  1. 307 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

a divisor that a case makes 0 is refused as a parameter with missing rows, though the parameter has every row

2 participants