Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved real float modeling #192

Merged

Conversation

PascalDevenoge
Copy link
Contributor

@PascalDevenoge PascalDevenoge commented May 12, 2024

Add support for infinity and NaN values to the real number based float model.


This change is Reviewable

@PascalDevenoge
Copy link
Contributor Author

So, the model as written is unsound, as it allows me to coerce the verifier to prove false. I think the problem is about some parts of the __sub__, __mul__ and __eq__ spec, but I'm not entirely sure yet.

ensures (float___is_inf__(self, false) == true && float___is_inf__(other, false) == true) ||
(float___is_inf__(self, true) == true && float___is_inf__(other, true) == true) ==>
result == float___box_nan()
ensures (float___is_inf__(self, false) == true && float___is_inf__(other, false) == false && float___is_nan__(other)) == false ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing parenthesis is in the wrong place, should be after == false, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's definitely a typo. I'll get that fixed...

ensures (float___is_inf__(other, false) == true && float___is_inf__(self, false) == true) ||
(float___is_inf__(other, true) == true && float___is_inf__(self, true) == true) ==>
result == float___box_nan()
ensures (float___is_inf__(other, false) == true && float___is_inf__(self, false) == false && float___is_nan__(self)) == false ||
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

@PascalDevenoge
Copy link
Contributor Author

So it appears that the main issue was the way I've tested the changes together with the rounding error issue when translating float literals.

The verifier would encounter an assert such as assert 1.2 + 1.3 == 2.5, which due to imprecise representation when translating those floats to ratios will fail verification. When testing, I've had the back-end continue after a failure, so it considers the assertion to be true, and that allowed it to prove false.

I've tried removing the offending assertions and using values with exact representations while keeping all parts involving any special values and the issue goes away.

@marcoeilers
Copy link
Owner

I think it was the typo in the postcondition? Even if you remove the asserts that didn't pass you could still prove false in the end, or at least I could locally.

@PascalDevenoge
Copy link
Contributor Author

Oh yes, but I could still make it prove false thanks to the rounding issue (i think...) after fixing the typos.

@PascalDevenoge
Copy link
Contributor Author

Besides the bug, I've added a contract function isNaN() for convenience, for example to assert that a function parameter is not NaN in a precondition. (Commit 25f28f1) There's a test in float_real/test_float.py as an example.

The cleanest way would have been to model the existing isnan function from the math model. But I guess adding builtin descriptions of standard library functions is not really feasible. Any thoughts?

@marcoeilers
Copy link
Owner

I think we can merge this now, right?

@PascalDevenoge
Copy link
Contributor Author

I'd say so, yes.

@marcoeilers marcoeilers marked this pull request as ready for review May 28, 2024 13:00
@marcoeilers marcoeilers merged commit 5682954 into marcoeilers:master May 28, 2024
1 check passed
@PascalDevenoge PascalDevenoge deleted the improved_real_float_modeling branch May 29, 2024 08:19
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.

2 participants