Skip to content

Prove AbsoluteMin#1

Open
Grover-c13 wants to merge 5 commits into
mainfrom
prove-absolute-min
Open

Prove AbsoluteMin#1
Grover-c13 wants to merge 5 commits into
mainfrom
prove-absolute-min

Conversation

@Grover-c13

Copy link
Copy Markdown
Contributor

maths/AbsoluteMin.getMinValue(int...) is documented to return the element with the smallest absolute value (the upstream AbsoluteMinTest asserts getMinValue(3, -10, -2) == -2). It doesn't.

This PR adds one plain @BmcProof asserting that contract over symbolic inputs: |result| must equal the minimum absolute value among the inputs. It REFUTES.

Counterexample

getMinValue(-3, -2) returns -3, but |-2| < |-3|, so the contract requires -2.
Witness: a = -3, b = -2, r = -3, minAbs = 2.

Root cause

After filtering to the abs-≤ candidates, the code updates the running winner with Math.min(value, number) — the arithmetic minimum — instead of the candidate itself. Between two negatives that keeps the more negative (larger-magnitude) value.

CI is therefore red on purpose: the asserted contract genuinely refutes, and the proof-results comment below shows the ❌ REFUTED row with the counterexample. That red check + the witness is the shareable artifact. Left open as the showcase; upstream is untouched.

Adds a plain @BmcProof asserting AbsoluteMin.getMinValue's documented
contract: the result must be the input element closest to zero. It REFUTES
with the two-element witness getMinValue(-3, -2) == -3 (should be -2, since
|-2| < |-3|). The bug: the filter keeps abs-<= candidates but then takes the
arithmetic Math.min, so the more-negative element wins.

CI goes red and the proof-report comment shows the counterexample row.
@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

bmc4j proof results

2 proofs → 1 matched expectation, 1 mismatched

Proof Expected Actual Why it fails Counterexample
AbsoluteMinProof.getMinValue_returns_element_with_minimal_absolute_value VERIFIED ❌ REFUTED assertion failed (Bmc.check) at AbsoluteMinProof.java:28 (AbsoluteMinProof.java:28) counterexample: a = -2L, b = 1L replay: // a: could not express integer value as a literal — inspect the counterexample above // b: could not express integer value as a literal — inspect the counterexampl… a = -2L, b = 1L
BaselineProof.increment_grows_below_int_max VERIFIED ✅ VERIFIED

The defect is specifically that, among two negatives, getMinValue keeps the
more-negative (larger-magnitude) value instead of the one closest to zero.
Constraining both symbolic inputs to be negative makes the refutation witness
land in that regime, matching the documented counterexample.
Reverts the negative-only pinning: keep both inputs symbolic over [-3, 3] so
the proof asserts the contract across positives and negatives alike. The
refutation witness the engine emits is reported faithfully in the PR comment.
@Grover-c13 Grover-c13 force-pushed the prove-absolute-min branch from a265028 to 9a8d94f Compare June 11, 2026 00:33
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.

1 participant