Skip to content

fix: whole-number Float literal emitted as Python int (F34)#33

Merged
emeryberger merged 1 commit into
mainfrom
fix-float-ofnat-literal
Jul 7, 2026
Merged

fix: whole-number Float literal emitted as Python int (F34)#33
emeryberger merged 1 commit into
mainfrom
fix-float-ofnat-literal

Conversation

@emeryberger

Copy link
Copy Markdown
Owner

Summary

A whole-number Float literal — e.g. the 0 in if m1 == 0 || m2 == 0 then 0 else … (elaborated to (0 : Float) via instOfNatFloatproj OfNat.0) — was emitted as the Python int 0, so a Float-returning branch yielded an int where Lean has 0.0. Under the exact-IEEE-bits Float oracle, 0 != 0.0, a silent wrong-value divergence.

Found by a 3000-seed cloudnew corpus sweep (Geometry.angleBetween on a zero-magnitude vector: python=0 lean=0.0), surfaced while verifying the Int → Bool predicate feature from #32.

Fix

When the OfNat instance is instOfNatFloat (or the projection's type is Float), record the fvar in a new floatLiteralVars set. Every literal-emission site (emitArg, .return, expression render) runs the value through floatize, which appends .0 to a bare integer literal so it stays a Python float.

Verification

  • Regression case (19) added; RegressionFixes (all cases), Comprehensions, TailCalls green.
  • All 44 Geometry functions now differentially agree with the Lean oracle (was 1 mismatch).
  • lake build + lake build Corpus green.

A whole-number `Float` literal (`(0 : Float)`, via `instOfNatFloat` → `proj
OfNat.0`) emitted the Python `int` 0, so a Float-returning `if … then 0 else …`
yielded an `int` where Lean has `0.0` — failing the exact-bits Float oracle.
Found by a 3000-seed cloudnew corpus sweep (Geometry.angleBetween on a
zero-magnitude vector: python=0 lean=0.0), surfaced while verifying the Int→Bool
predicate feature.

Fix: when the OfNat instance is `instOfNatFloat` (or the projected type is
`Float`), record the fvar in `floatLiteralVars`; literal-emission sites
(emitArg / .return / expression render) run the value through `floatize`, which
appends `.0` to a bare integer literal. Regression case (19); all 44 Geometry
functions now differentially agree.
@emeryberger emeryberger merged commit deb70f8 into main Jul 7, 2026
1 check passed
@emeryberger emeryberger deleted the fix-float-ofnat-literal branch July 7, 2026 20:02
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