Skip to content

fresh_const (and friends) are broken #2

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

Closed
badboy opened this issue Nov 21, 2018 · 11 comments
Closed

fresh_const (and friends) are broken #2

badboy opened this issue Nov 21, 2018 · 11 comments

Comments

@badboy
Copy link
Contributor

badboy commented Nov 21, 2018

Currently the semver test fails due to a version mismatch in the result.

I rewrote the test using ctx.numbered_int_const instead of ctx.fresh_int_const and it now passes (changes in https://gist.github.com/badboy/e126802b474d7de60d5d73e47531b01c/revisions)

I had a similar problem in my own code and also used numbered_int_const there.

@badboy
Copy link
Contributor Author

badboy commented Nov 21, 2018

Simplified failing test:

#[test]
fn test_fresh_int_const() {
    let _ = env_logger::try_init();
    let cfg = Config::new();
    let ctx = Context::new(&cfg);
    let x = ctx.fresh_int_const("x");
    let zero = ctx.from_i64(0);
    let solver = Solver::new(&ctx);
    solver.assert(&x.gt(&zero));
    assert!(solver.check());

    let model = solver.get_model();
    let xv = model.eval(&x).unwrap().as_i64().unwrap();
    assert_eq!(xv, 1);
}

Output:

thread 'test_fresh_int_const' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', z3/tests/lib.rs:106:5

@badboy
Copy link
Contributor Author

badboy commented Nov 21, 2018

This C code example has the same problem.

@badboy
Copy link
Contributor Author

badboy commented Nov 21, 2018

As can be seen in this example the fresh const is not even part of the model, so I guess that's not how fresh_const should be used anymore?

Output from the example:

% ./z3-example 
result: 1
Model:
k!2 -> 1
y -> 1

@waywardmonkeys
Copy link
Contributor

I'll try to look at this some today as well! Thanks!

@waywardmonkeys
Copy link
Contributor

It is interesting to look at Z3_solver_to_string output from your C example:

(declare-fun k!1 () Bool)
(declare-fun x!0 () Int)
(declare-fun k!2 () Bool)
(declare-fun y () Int)
(declare-fun k!3 () Bool)
(declare-fun k!2 () Int)
(declare-fun k!4 () Bool)
(declare-fun k!5 () Bool)
(declare-fun k!6 () Bool)
(assert (> x!0 0))
(assert (> y 0))
(assert (> k!2 0))
(model-del k!1)
(model-add x!0 () Int (ite k!1 0 (+ 0 1)))
(model-del k!2)
(model-add y () Int (ite k!2 0 (+ 0 1)))
(model-del k!3)
(model-add k!2 () Int (ite k!3 0 (+ 0 1)))
(model-del k!4)
(model-add k!1 () Bool (not k!4))
(model-del k!5)
(model-add k!2 () Bool (not k!5))
(model-del k!6)
(model-add k!3 () Bool (not k!6))
(pb2bv-model-converter)
(model-add k!4 () Bool true)
(model-add k!5 () Bool true)
(model-add k!6 () Bool true)

@waywardmonkeys
Copy link
Contributor

@jrakow and @cdisselkoen : Do either of you have any idea about this?

@djrenren
Copy link

This is also fixed on master. Somewhere in the AST refactoring it probably got fixed.

@djrenren
Copy link

Nevermind! Updated my z3 from 4.5 to 4.8 and now it's broken again. Seems like something changed in the API. I'll do some digging.

@djrenren
Copy link

Filed an issue with the z3 folks: Z3Prover/z3#2489

@djrenren
Copy link

As per the Z3 issue above, the problem has been confirmed to be a Z3 bug, and has been fixed on master. This is definitively not a bug in the bindings but in Z3 itself so I think we should close this issue.

@badboy
Copy link
Contributor Author

badboy commented Aug 16, 2019

Sounds good to me. Thanks for looking into that!

@badboy badboy closed this as completed Aug 16, 2019
tyleretzel pushed a commit to tyleretzel/z3.rs that referenced this issue Sep 15, 2021
cvick32 added a commit to cvick32/z3.rs that referenced this issue Dec 11, 2024
Add Let simplification in smt2utils
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

No branches or pull requests

3 participants