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

introduce zero_expr() and one_expr() for number types #8441

Merged
merged 1 commit into from
Sep 5, 2024
Merged

Conversation

kroening
Copy link
Member

@kroening kroening commented Sep 5, 2024

This adds .zero_expr() and .one_expr() for integers, natural numbers, rationals and reals.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening kroening marked this pull request as ready for review September 5, 2024 09:26
This adds ::zero_expr() and ::one_expr() for integers, natural numbers,
rationals and reals.
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Should we take this opportunity to deprecate exprt::is_zero and exprt::is_one? I'd like to think that e.is_zero() would better be written as e == e.type().zero_expr() (with some extra type cast of e.type() to something more specific than typet).

@kroening
Copy link
Member Author

kroening commented Sep 5, 2024

Should we take this opportunity to deprecate exprt::is_zero and exprt::is_one? I'd like to think that e.is_zero() would better be written as e == e.type().zero_expr() (with some extra type cast of e.type() to something more specific than typet).

I considered this, but that will only work when there is a canonical representation for the respective number.

This works for integers and naturals, but, for instance, not for floats, rationals and reals.

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Project coverage is 78.27%. Comparing base (dd54106) to head (9fba581).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
src/util/mathematical_types.cpp 0.00% 16 Missing ⚠️
src/util/mathematical_types.h 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8441      +/-   ##
===========================================
+ Coverage    78.19%   78.27%   +0.07%     
===========================================
  Files         1726     1726              
  Lines       189068   188879     -189     
  Branches     18273    18322      +49     
===========================================
  Hits        147841   147841              
+ Misses       41227    41038     -189     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kroening kroening merged commit 71ee177 into develop Sep 5, 2024
40 of 41 checks passed
@tautschnig tautschnig deleted the zero_expr branch September 6, 2024 09:25
@tautschnig
Copy link
Collaborator

Should we take this opportunity to deprecate exprt::is_zero and exprt::is_one? I'd like to think that e.is_zero() would better be written as e == e.type().zero_expr() (with some extra type cast of e.type() to something more specific than typet).

I considered this, but that will only work when there is a canonical representation for the respective number.

This works for integers and naturals, but, for instance, not for floats, rationals and reals.

But then exprt::is_zero and exprt::is_one perhaps are also a bit questionable for those cases?

@kroening
Copy link
Member Author

kroening commented Sep 6, 2024

But then exprt::is_zero and exprt::is_one perhaps are also a bit questionable for those cases?

They are fine -- they do handle the multiple representations.

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