Skip to content

[VFDLIBM] Prove log10's words in long lanes, the form Varka's kernel emits - #147

Merged
MaxGekk merged 4 commits into
mainfrom
varka-log10-long-words-r
Nov 23, 2026
Merged

MaxGekk merged 4 commits into
mainfrom
varka-log10-long-words-r

Conversation

@MaxGekk

@MaxGekk MaxGekk commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR adds lemma L17 to PROOFS.md, in the log10 section, and its tests in ProofsTest (l17LongWordsAreLog10sInts, l17RareComparesAreTheCs, l17NegativeLanesAreAnsweredEarly, l17NegativeLanesAreBlendedOver).
The library code does not change. Log10.java gets one comment pointer to L17.
Varka's emitted log10 kernel keeps the C's int words in long lanes, as Log does (L8).
L17 proves that these long words, and the kernel's tests on the raw bits, give the C's values on the lanes whose result is kept.

The paired Varka PR, the statement of L17 and the proof

The paired Varka pull request is vecbricks/varka#1645, "Emit fdlibm's log and log10 as kernel IR nodes, exact to StrictMath", which L17 cites.
Its kernel computes the operations of Log10.log10Blended in the same order.
The difference is where the words live: the C's int words hx, k and i are long lanes, and y = (double)(k+i) is L7's exact add and subtract of 0x1.8p52 instead of I2D.
Log10 here keeps int lanes, so the log10 section's sentence "needs no lemma of its own" still holds for this library. L17 is about Varka's kernel only, as L15's (a) to (c) are.

L17 states three facts.
(a) With the sign bit clear, the long K = (HX >>> 20) - 1023 (less 54 on a scaled lane), I = K >>> 63 and the new high word (HX & 0xfffff) | ((0x3ff - I) << 20) are the C's k, i and new hx, widened. The new word is below 2^31, so its shift into place is the C's __HI(x) = hx.
(b) For K in [-1077, 1024], the L7 conversion of K + I is the C's (double)(k+i).
(c) For every lane, either sign, the signed long compares b > 0x7ff00000_00000000 - 1 and b < 0 are the C's hx >= 0x7ff00000 and hx < 0.

The proof is range arithmetic.
With the sign clear, the high word is in [0, 2^31), so the logical and the arithmetic shift agree, and K is in [-1077, 1024].
Bit 63 of a long is its sign, so K >>> 63 is 1 exactly when K < 0.
The compares follow from b = hx * 2^32 + lo with 0 <= lo < 2^32 (L9's argument on the raw bits).

The hypothesis H18 is that the sign bit is clear on every kept lane.
A lane with the sign set is x < 0 or -0. The C answers it at line 79 or 78, and the kernel blends those answers over the general result.
H18 is needed: on a negative lane the long K is not the C's k.

The change is on main after #143. L12 to L16 and H17 are taken, so the lemma is L17 and the hypothesis H18.
On the old branch it was L13 with H17.

Why are the changes needed?

The Varka kernel writes log10 with long words and tests its rare lanes on the raw bits.
"Same result, proven" (AGENTS.md) asks for a numbered lemma for any form that departs from the C.
Without L17 the kernel's long words rest on an unwritten argument.

Does this PR introduce any user-facing change?

No.
Only PROOFS.md, tests and one code comment change.
No public method, result or requirement moves, so CHANGELOG.md has no line.

How was this patch tested?

mvn -B verify on the head (27bf8a4, with main at 7acd20d merged in): BUILD SUCCESS, 799 tests, 0 failures, 0 errors, 4 skipped, in 6 min 44 s.
ProofsTest runs 50 tests.
The four L17 tests are new.
Each hinge test is built to fail when its hinge is false.
l17NegativeLanesAreAnsweredEarly is a witness, not a hinge test: it checks only the oracle, that StrictMath.log10 gives a NaN, or -inf for -0, on every sign-set input.
l17NegativeLanesAreBlendedOver and Varka's suite are the checks of H18. l17NegativeLanesAreBlendedOver checks H18 on Log10's own masks: Log10.log10Blended at every width, with sign-set inputs beside their positive twins in one vector.
A dropped rare blend is caught: with Log10.log10Blended's blend for negative lanes commented out, l17NegativeLanesAreBlendedOver failed at all four widths (a sign-set input gave a finite result instead of a NaN). The mutation was made by hand and reverted.

Where the real check lives: that Varka's kernel uses these long words is checked only in Varka's VarkaMathPortSuite, in vecbricks/varka#1645.
l17LongWordsAreLog10sInts is a Java loop over every exponent field and every significand word, the values the proof's bound allows.
l17RareComparesAreTheCs checks the compares at their edges and on 2^20 samples, not over every word. A loop over every high word took 44 s, too long for a test.

Not run: dev/prove.sh, dev/jar-check.sh and any benchmark.
No .smt2 file changed, so prove.sh has nothing new to check.
Only a comment changed in the main sources, so jar-check.sh has nothing new to check.
Nothing here is a speed claim, so no benchmark.

/code-review high on d78a0d7 found no bug and 5 nits, fixed in 7828ab2 and 27bf8a4. The review of 7828ab2 found no bug and four nits; all four are addressed in 27bf8a4. 27bf8a4 itself has not been reviewed.

Test setup, the review items and the log1p lemma

The last run used origin/main at 7acd20d as base, JDK 25.0.5.1, Maven 3.9.16, on this laptop (not a timing).
An earlier run on d78a0d7, before the review fixes, also gave BUILD SUCCESS with 799 tests, 0 failures and 4 skipped, in 15 min 22 s. The reviewer's own Maven run overlapped part of it.

The nits:

  • Fixed: H18 now names a NaN with the sign bit set among the lanes the C answers early.
  • Fixed: a kept lane's K is in [-1074, 1023]. Field 0x7ff gives 1024, but that lane is +inf or a NaN and is always blended over.
  • Fixed: the significand loop ran over five exponent fields that both words mask away. It now loops over the significand and I only.
  • Fixed: the H18 witness asserted that K differs on some sign-set pattern. That assertion could never fail, so 27bf8a4 drops it and calls the test a witness.
  • Fixed in 27bf8a4: the Varka tie cited the branch varka-345d-log-r. It now cites [VARKA-345] Emit fdlibm's log and log10 as kernel IR nodes, exact to StrictMath varka#1645, as L15 cites a PR number.

The review of 7828ab2 (four nits, all addressed in 27bf8a4): a self-contradicting sentence in L17's hinge-test paragraph, reworded; the witness test's assertion that could not fail, dropped, with l17NegativeLanesAreBlendedOver and Varka's suite named as the checks of H18; the Varka branch cite, now vecbricks/varka#1645; and l17CK's Javadoc, now citing e_log10.c lines 80 and 84.

The log1p lemma (L14 on the old branch varka-log1p-long-words) is not in this PR.
AGENTS.md says each function comes in its own PR, paired with the Varka PR that emits it.
The Varka PR for log1p is a later part. That lemma will be renumbered then.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

Max Gekk added 2 commits November 23, 2026 02:00
Varka's PORT expansion of log10 (VarkaMathPort.log10, paired Varka branch
varka-345d-log-r) holds e_log10.c's int words in long lanes, as Log does
(L8), takes y = (double)(k+i) by L7 rather than I2D, and tests the rare
lanes on the raw bits. L17 proves these the C's on the lanes kept, under
H18 (the sign bit clear there). Its hinge tests loop over every exponent
field and every significand word, check the compares at their edges and
on samples, and check H18 on StrictMath, which fails if the C kept a
negative lane. Log10 itself keeps int lanes, so its own section stands.

Generated-by: Claude Code (Claude Opus 5.5)
The review's nits: H18 now names a NaN with the sign bit set among the
lanes the C answers early; a kept lane's K tops at 1023, since field
0x7ff is always blended over; the significand loop drops the exponent
fields it masked away; and the H18 witness asserts that K differs from
the C's k on every sign-set pattern, not on some.

Generated-by: Claude Code (Claude Opus 5.5)
@MaxGekk

MaxGekk commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Review at code-review high on head 7828ab2: no correctness bug, four nits. The four L17 tests match the statement, and the cited e_log10.c lines are right apart from nit 4.

  • PROOFS.md:952: one sentence in L17's hinge-test paragraph contradicts itself ("for some of those patterns K is not the C's k on every one of those patterns"). The test asserts every pattern. Fix: "and on every one of those patterns the long K is not the C's k, which shows H18 is needed", as the test's Javadoc says.
  • src/test/java/io/github/vecbricks/vfdlibm/ProofsTest.java:1134: the second half of l17NegativeLanesAreAnsweredEarly cannot fail. With the sign bit set the long K is at least 1025 and the C's k at most -1024, so k != l17CK(...) holds for every input; the first half checks only that StrictMath.log10 is NaN or -inf on a negative input, a property of the oracle, not of a kernel. AGENTS.md asks for a hinge test that fails if a hinge were false. Fix: call this test a witness and the oracle's own check in PROOFS.md, and name l17NegativeLanesAreBlendedOver and Varka's suite as the checks of H18; or drop the assertion that cannot fail.
  • PROOFS.md:960: L17's "Vector tie, in Varka" cites the branch varka-345d-log-r, not a pull request (L15 cites [VARKA-345] Emit fdlibm's expm1 as IR nodes in the kernel, exact to StrictMath varka#1629). Once the branch is merged and deleted, the lemma's only check of the kernel points at nothing. Fix: cite the Varka pull request number before merge.
  • ProofsTest.java:1041: l17CK's Javadoc cites e_log10.c lines 81 and 84; the k -= 54 is at line 80 (line 81 is hx = __HI(x)). Fix: "lines 80 and 84", or "80, 81 and 84" if the re-read high word is meant.

Generated-by: Claude Code (Opus 5.5)

Max Gekk added 2 commits November 23, 2026 05:52
Generated-by: Claude Code (Claude Opus 5.5)
…C line numbers

Reword L17's hinge-test paragraph so it no longer contradicts itself, call
l17NegativeLanesAreAnsweredEarly a witness and the oracle's own check and drop
its assertion that could not fail, name l17NegativeLanesAreBlendedOver and
Varka's suite as the checks of H18, cite vecbricks/varka#1645 instead of the
branch, and cite e_log10.c lines 80 and 84 in l17CK's Javadoc.

Generated-by: Claude Code (Claude Opus 5.5)
@MaxGekk

MaxGekk commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All four points are fixed in 27bf8a4 (main is merged in first, in b25d175).

  • PROOFS.md, the self-contradicting sentence: it now reads "On every one of those patterns the long K is not the C's k, which shows H18 is needed", with the reason (the long K is at least 1025, the C's k at most -1024).
  • l17NegativeLanesAreAnsweredEarly: the assertion that could not fail is dropped. PROOFS.md and the Javadoc now call the test a witness and the oracle's own check, not a hinge test. They name l17NegativeLanesAreBlendedOver and Varka's suite as the checks of H18.
  • L17's "Vector tie, in Varka" now cites [VARKA-345] Emit fdlibm's log and log10 as kernel IR nodes, exact to StrictMath varka#1645, not the branch.
  • l17CK's Javadoc now cites e_log10.c lines 80 and 84, with line 81's re-read high word for a scaled lane. I checked the lines in reference/fdlibm-5.3/e_log10.c.

Generated-by: Claude Code (Claude Opus 5.5)

@MaxGekk
MaxGekk merged commit 8caf0a3 into main Nov 23, 2026
14 checks passed
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