Skip to content

Conversation

tautschnig
Copy link
Collaborator

We were missing front-end support for reals and did not consistently support all of integers, naturals, rationals, reals but instead would only handle varying subsets in each place.

  • 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.
  • 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.

@tautschnig tautschnig self-assigned this Jun 11, 2024
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch from 34b8cbe to e5a11d2 Compare June 11, 2024 19:53
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch from e5a11d2 to 19a8310 Compare September 22, 2025 20:02
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch 2 times, most recently from cebcc43 to 9cd88b5 Compare September 23, 2025 15:33
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch 3 times, most recently from 5a6f0b8 to 9d13355 Compare September 23, 2025 18:54
@tautschnig tautschnig marked this pull request as ready for review September 23, 2025 19:15
@tautschnig tautschnig assigned kroening and unassigned tautschnig Sep 23, 2025
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 54.62555% with 103 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.47%. Comparing base (5f4c82d) to head (dcb2725).

Files with missing lines Patch % Lines
src/solvers/smt2/smt2_conv.cpp 56.98% 40 Missing ⚠️
src/ansi-c/c_typecast.cpp 57.69% 22 Missing ⚠️
src/util/algebraic_number.cpp 21.42% 22 Missing ⚠️
src/util/rational_tools.cpp 57.14% 6 Missing ⚠️
src/util/simplify_expr.cpp 28.57% 5 Missing ⚠️
src/solvers/flattening/boolbv_width.cpp 0.00% 4 Missing ⚠️
src/ansi-c/c_typecheck_type.cpp 75.00% 1 Missing ⚠️
src/util/algebraic_number.h 88.88% 1 Missing ⚠️
src/util/arith_tools.cpp 50.00% 1 Missing ⚠️
src/util/pointer_offset_size.cpp 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8324      +/-   ##
===========================================
+ Coverage    80.43%   80.47%   +0.04%     
===========================================
  Files         1695     1697       +2     
  Lines       208285   208427     +142     
  Branches        73       73              
===========================================
+ Hits        167524   167735     +211     
+ Misses       40761    40692      -69     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

src/util/real.h Outdated
class realt
{
protected:
mp_integer integral, fractional;
Copy link
Collaborator

@kroening kroening Sep 24, 2025

Choose a reason for hiding this comment

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

Representing real numbers like floating-point numbers will at the very least irritate. Please add a comment why this is the right choice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, which approach would you have chosen instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

E.g., you could have represented the algebraic numbers via the root of a polynomial; I'd be curious what the various SMT solvers output as models.

Copy link
Contributor

@polgreen polgreen Sep 24, 2025

Choose a reason for hiding this comment

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

z3 and cvc5 seem to output Reals as fractions, unless the denominator is 1, when they just output a singular decimal.

Whilst they use decimals, I've not managed to make it produce a number that isn't an integer as the nominator or denominator, or as a singular decimal.

(set-logic ALL)
(declare-fun x () Real)
(declare-fun y () Real)
(declare-fun z () Real)
(assert (= y (/ 100 30)))
(assert (= x 0.111111))
(assert (= z 7))
(check-sat)
(get-model)

z3 says:

(
  (define-fun z () Real
    7.0)
  (define-fun y () Real
    (/ 10.0 3.0))
  (define-fun x () Real
    (/ 111111.0 1000000.0))
)

cvc5 says

(
(define-fun x () Real (/ 111111 1000000))
(define-fun y () Real (/ 10 3))
(define-fun z () Real 7.0)
)

For irrational numbers, they output the root of a polynomial.

(set-logic ALL)
(declare-fun y () Real)
(assert (= (* y y) 2 ))
(check-sat)
(get-model)

z3 says

(
  (define-fun y () Real
    (root-obj (+ (^ x 2) (- 2)) 1))
)

cvc5 segfaults...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we'll eventually want the algebraic numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll try to address this (even when I'd argue that the current PR already addresses a number of CBMC invariant failures that the included regression tests cause when attempted without the code changes).

Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to implement this right now; my suggestion is to add a comment, then merge this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added a comment and a KNOWNBUG regression test (amounting to the example that @polgreen gave).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have now added a further commit that removes realt and introduces algebraic_numbert while also fixing that KNOWNBUG test introduced in the prior commit.

@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch from 9d13355 to fb0495e Compare September 29, 2025 05:14
We were missing front-end support for reals and did not consistently
support all of integers, naturals, rationals, reals but instead would
only handle varying subsets in each place.
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch 3 times, most recently from d5014d5 to 611573c Compare October 7, 2025 12:52
This representation is used by Z3 for it covers a subset of irrational
numbers in addition to rational numbers.
@tautschnig tautschnig force-pushed the bugfixes/mathematical-types branch from 611573c to dcb2725 Compare October 7, 2025 13:38
--trace --smt2
^EXIT=10$
^SIGNAL=0$
^ b=100
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this meant to test constant propagation?

}
else if(
src.get_sub().size() == 3 &&
src.get_sub()[0].id() == "root-obj") // (root-obj (+ ...) 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which solvers emit these? I suppose these are solver-specific, or does the SMT-LIB standard talk about these?

src.get_sub().size() == 3 &&
src.get_sub()[0].id() == "root-obj") // (root-obj (+ ...) 1)
{
DATA_INVARIANT_WITH_DIAGNOSTICS(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that a DATA_INVARIANT is the right choice here. This is a property of the output of another tool, which we have very little control over. I'd make this a proper exception.

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.

3 participants