fix: whole-number Float literal emitted as Python int (F34)#33
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A whole-number
Floatliteral — e.g. the0inif m1 == 0 || m2 == 0 then 0 else …(elaborated to(0 : Float)viainstOfNatFloat→proj OfNat.0) — was emitted as the Pythonint0, so a Float-returning branch yielded anintwhere Lean has0.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.angleBetweenon a zero-magnitude vector:python=0 lean=0.0), surfaced while verifying theInt → Boolpredicate feature from #32.Fix
When the
OfNatinstance isinstOfNatFloat(or the projection's type isFloat), record the fvar in a newfloatLiteralVarsset. Every literal-emission site (emitArg,.return, expression render) runs the value throughfloatize, which appends.0to a bare integer literal so it stays a Pythonfloat.Verification
RegressionFixes(all cases),Comprehensions,TailCallsgreen.Geometryfunctions now differentially agree with the Lean oracle (was 1 mismatch).lake build+lake build Corpusgreen.