fix: route the last three transcendentals through libm, and enforce it
CLAUDE.md requires transcendentals to go through libm rather than std, because std delegates to the system math library and the two disagree by one ULP often enough to change an iteration count in a fixed point. Three production sites did not: factor/margin.rs:84 cavity.sigma().hypot(sigma) 12.136% of 1e6 inputs factor/margin.rs:92 f64::MIN_POSITIVE.ln() 3.437% factor/trunc.rs:98 f64::MIN_POSITIVE.ln() same `hypot` is the material one: it is on the path of every scored event, and its divergence rate is HIGHER than the 9.7% the rule cites for `exp` as its own justification. The two `ln` calls happen to agree bit-for-bit on this host, which is exactly the platform dependence the rule exists to remove. The `hypot` choice itself was right and stays — the comment above it explains why, and it is measured: naive sqrt(a^2 + b^2) overflows to inf at 1e200 and flushes to zero at 1e-200 where hypot does neither. Only the implementation moves. tests/libm_rule.rs enforces it. The rule was stated plainly in CLAUDE.md and still violated three times, so prose is evidently not sufficient. The test strips `#[cfg(test)]` items by brace matching, plus comments and string literals so prose is not mistaken for a call, then scans for std method spellings. `sqrt` is exempt: IEEE 754 specifies it, so std and libm cannot disagree. Confirmed non-vacuous by reintroducing the `hypot` violation and watching it fail with the offending line, then pass again on restore. Two further tests pin the stripper itself, since a stripper that removed everything would make the guard pass on anything. Closes #63 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011hcFjNDmHXZF8URGLku5zZ
This commit is contained in:
+2
-2
@@ -95,7 +95,7 @@ fn cavity_log_evidence(diff: Gaussian, margin: f64, tie: bool) -> f64 {
|
||||
if value.is_finite() {
|
||||
value
|
||||
} else {
|
||||
f64::MIN_POSITIVE.ln()
|
||||
libm::log(f64::MIN_POSITIVE)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ mod tests {
|
||||
let approx = -0.5 * z * z - z.ln() - (2.0 * std::f64::consts::PI).sqrt().ln();
|
||||
|
||||
assert!(
|
||||
got < f64::MIN_POSITIVE.ln(),
|
||||
got < libm::log(f64::MIN_POSITIVE),
|
||||
"mu={mu}: {got} is still stuck on the old clamp floor"
|
||||
);
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user