Repository navigation
[VFDLIBM] Prove expm1's words in long lanes, the form Varka's kernel emits - #133
Conversation
Varka's PORT expansion of expm1 (VarkaMathPort.expm1) holds s_expm1.c's int words in long lanes, as Log does (L8). L15 proves the long words and tests are the C's ints on the lanes that read them, and ProofsTest.l15LongWordsAreExpm1sInts checks every k from -1100 to 1100. Generated-by: Claude Code (Claude Opus 5.5)
Generated-by: Claude Code (Claude Sonnet 5.5)
|
Review at Important
Nits
Generated-by: Claude Code (Opus 5.5) |
Address the review of 4162621. L15's new vector test runs Expm1.expm1Blended against StrictMath at every k from -56 to 1024, forms mixed in a vector, so a mask that keeps a word on a lane whose form does not read it fails. The scalar loop now takes the C's literal 56 and 20, checks each word's double against 1-2^-k or 2^-k, and a separate test pins K_FAR and K_SPLIT. L15 gains part (d), the C's __HI(y) += (k<<20) as the long add of k << 52, with its own test, and H17, the bounds on k from L10's domain. L15 now says it covers Varka's emitted kernel, checked in Varka's VarkaMathPortSuite, and Expm1 and Lanes point to it. Generated-by: Claude Code (Claude Opus 5.5)
|
Addressed in 8432563. Only comments change in the library code. Important: H16 is now tested.
There is one known gap. Nits
Generated-by: Claude Code (Claude Opus 5.5) |
What changes were proposed in this pull request?
This PR adds lemma L15 to
PROOFS.mdand its tests inProofsTest(l15ThresholdsAreTheCs,l15LongWordsAreExpm1sInts,l15ExponentAddIsTheCsHighWordAdd,l15MasksKeepEachWordOnItsLanes).The library code does not change, except for comment pointers to L15 in
Expm1.javaandLanes.java.Varka's emitted
expm1kernel keeps the C'sintwords in long lanes, asLogdoes (L8).L15 proves that these long words equal the C's
intwords on the lanes that read them.The paired Varka PR, the statement of L15 and the proof
The paired Varka pull request is vecbricks/varka "Emit fdlibm's expm1 as IR nodes in the kernel, exact to StrictMath".
Its kernel computes the operations of
Expm1.expm1Blendedwith the C'sintwords held in long lanes, the wayLogdoes (L8).A kernel's high-word tests are L3's compares of the bits of
|x|, and itskis a long widened from anint.The doubles are the same operations in the same order, so L15 covers only the words.
L15 states five facts about a lane whose form reads the words.
The long
0x3ff00000 - (0x200000 >>> k)(for2 <= k < 20) is the C'sintword widened.The long
(0x3ff - k) << 20(for20 <= k <= 56) is the C'sintword widened.w << 32is the bits of the double whose high word is the C's word and whose low word is 0.The compares of
kare the C's.bits(y) + (k << 52)is the C's__HI(y) += (k<<20): the low word kept, the high word theintsum modulo 2^32.This last fact is
Expm1's own code too.The proof is range arithmetic.
0x200000 >> kis positive and below 2^20 for2 <= k < 20, so the arithmetic and the logical shift agree.(0x3ff - k) << 20stays in[0x3c700000, 0x3eb00000], below 2^31, so nointoverflows.A word on a lane that does not read it is never kept (hypothesis H16).
The two shifts do differ there, at
k = 40, so the hypothesis is needed.l15MasksKeepEachWordOnItsLaneschecks H16 onExpm1's own masks:Expm1.expm1BlendedagainstStrictMathat everykfrom -56 to 1024, with the forms mixed in a vector.H17 bounds
kto -56..1024 from L10's domain, and the test asserts the two end doubles.That Varka's kernel uses these masks with long words is checked in Varka's
VarkaMathPortSuite(vecbricks/varka PR #1629, 2^24 sampled inputs).The change is rebased on
mainafter the 0.2.0 release.L12,L13andL14were taken since the branch was cut, so the lemma is L15.Why are the changes needed?
The Varka kernel writes
expm1with long words."Same result, proven" (
AGENTS.md) asks for a numbered lemma for any form that departs from the C's int words.Without L15 the kernel's long words rest on an unwritten argument.
Does this PR introduce any user-facing change?
No.
Only
PROOFS.md, tests and code comments (three in two files) change.No public method, result or requirement moves, so
CHANGELOG.mdhas no line.How was this patch tested?
mvn -B verifyon the head (8432563): BUILD SUCCESS, 701 tests, 0 failures, 0 errors, 0 skipped, in 4 min 28 s.ProofsTestruns 43 tests, the four L15 tests among them.A wrong mask is caught: blending the mid word over
k == 40failedl15MasksKeepEachWordOnItsLanesat every width (7 of 7569 inputs), and so did keeping the high word on the far lanes (7163 of 7569); both mutations were made by hand and reverted.Not run:
dev/prove.sh,dev/jar-check.shand any benchmark.No
.smt2file changed and z3 is not installed here, soprove.shhas nothing to check.Only comments changed in the main sources, so
jar-check.shhas nothing new to check.Nothing here is a speed claim, so no benchmark.
/code-review highbefore 4162621 found 7 items: 2 important, 5 nits.I fixed 3 and stated one limit of the test in
PROOFS.md.I left 3 nits open.
The
/code-review highcomment on 4162621 (1 important, 4 nits) is addressed in 8432563: a vector test checks H16 onExpm1's masks, L15 names Varka'sVarkaMathPortSuiteas its kernel check, the loop uses the C's 56 and 20, L15 adds the__HI(y) += (k<<20)step with a test, and the Encoding now calls the check a Java loop and takes the bounds onkfrom L10's domain (H17).8432563 itself has not been reviewed.
Test setup, the review items and what changed
The
mvn -B verifyrun usedorigin/mainat 71c7b9e as base, vfdlibm 0.2.1-SNAPSHOT, JDK 25.0.5.1, on this laptop.Earlier runs gave BUILD SUCCESS with 695 tests, 0 failures, 0 errors, 0 skipped: on 699a011 in 8 min 20 s, on 4162621 in 4 min 26 s.
The two important items:
PROOFS.md, after the atan2 section. I deleted it.Expm1's code changed a mask. The second review raised this again;l15MasksKeepEachWordOnItsLanesnow checks it.The nits:
(0x3ff - k) << 20had the wrong low end. The right range is[0x3c7, 0x3eb]and[0x3c700000, 0x3eb00000].k. It now gives-56 <= k <= 1024as H17, from L10's domain.VarkaMathPortSuite, and a reflection lookup in its static initializers.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Sonnet 5.5, Claude Opus 5.5)