I'm using the Z3 C++ API of the SMT Solver and I'd like to change parameters of the "ctx-solver-simplify". I don't know how to input them to the tactic. I tried:
z3::context c;
c.set("arith_lhs",false);
c.set("eq2ineq",true);
And
z3::params params(c);
params.set("arith_lhs",true);
params.set("eq2ineq",true);
Example code:
z3::expr x = c.int_const("x");
z3::expr cond1 = !(x==4);
z3::goal g(c);
g.add(cond1);
z3::tactic t(c, "ctx-solver-simplify");
z3::apply_result r = t(g);
The result is
(goal (not (= x 4)))
And not
(goal and (< x 4) (> x 4)
Same applies for arith_lhs. Any help?
Thanks!
Change:
z3::tactic t(c, "ctx-solver-simplify");
to
z3::tactic t = with(z3::tactic(c, "simplify"), params);
This will instruct Z3 to apply the simplify tactic with the selected parameters. In the SMT-LIB API this is accomplished with the "using-params" combinator. I got the above C++ equivalent from example.cpp shipped with the Z3 source.
So there were two problems: (1) You need to tell Z3 to apply the given tactic with the selected parameters. (2) the ctx-solver-simplify tactic does not have an eq2ineq option. Other tactics do, though, including simplify.
Related
I've got large matrix of parameters.
The point is that among many parameters some parameters with arbitrary indexes induce value errors and I'd like to fix them.
The toy example is as follows:
foo[3, 2] <- mu[3, 2] # mu is some (4,4) matrix from data input
for (r in 1:4) {
for (c in 1:4) {
foo[r, c] ~ dnorm( mu[r, c], .01 )
}
}
I see some examples like 15414303 and 46730232, but I cannot wrap my head around the problem how to apply those tricks (or similar) in my case.
Is there a simple way to implement such a logic in JAGS / BUGS?
The simplest way would be to supply foo in the data where all entries beside foo[3,2] are missing and foo[3,2] is mu[3,2]. Then, the code you have above should work fine (if you remove the definition of foo[3,2] in your code). The alternative would be to define the loops around the fixed cell. For example:
for(r in c(1,2,4)){
for(c in 1:4){
foo[r, c] ~ dnorm( mu[r, c], .01 )
}
}
for(c in c(1,3,4)){
foo[3, c] ~ dnorm( mu[r, c], .01 )
}
I am new to Standard ML. I am trying to compute x squared i, where x is a real and i is an non-negative integer. The function should take two parameters, x and i
Here is what I have so far:
fun square x i = if (i<0) then 1 else x*i;
The error that I am getting is that the case object and rules do not agree
The unary negation operator in SML is not - as it is in most languages, but instead ~. That is likely what is causing the specific error you cite.
That said, there are some other issues with this code. L is not bound in the example you post for instance.
I think you may want your function to look more like
fun square (x : real) 0 = 1
| square x i = x * (square x (i - 1))
You'll want to recurse in order to compute the square.
Is there anything similar in C++ like Z3py interface's as_expr(). I'm trying to get the result of applying the tactics as a z3 expression, exp, not as type apply_result.
For example, in the below code
context c;
expr x = c.bool_const("x");
expr y = c.bool_const("y");
expr f = ( (x || y) && (x && y) );
solver s(c);
goal g(c);
g.add( f );
tactic t1(c, "simplify");
apply_result r = t1(g);
std::cout << r << "\n";
Also, is there any way to convert the apply_result into z3 expr?
In general, the result of a tactic application is a set of goals. Most tactics produce only one goal, but some produce more than one. For each of those subgoals, you can use as_expr() and then logical-or them together. We can add an as_expr(...) to class apply_result if that helps. (I'm busy with other stuff at the moment; if you add it yourself, submit a pull request, contributions very welcome!)
I'm starting in Ocaml and one of the questions that i have is: How to simplify this segment of code
if f (x) < h then f (x) else h
You can write this
min (f x) h
(I hope this isn't a school assignment. Better to figure those out yourself.)
I am playing around with z3 and other SMT solvers and want to examine the cases where other solvers like boolector triumph over z3 and vice-versa. For this purpose, I need a way to convert declarations and assertions to the SMT-LIB2 format that other SMT solvers can recognize.
For example, for this example
void print_as_smtlib2_string() {
context c;
expr x = c.int_const("x");
expr y = c.int_const("y");
solver s(c);
s.add(x >= 1);
s.add(y < x + 3);
std::cout << s.check() << "\n";
Z3_set_ast_print_mode(c, Z3_PRINT_SMTLIB_COMPLIANT);
std::cout << "\nSolver is:\n";
std::cout << s << "\n";
}
I get something like:
sat
Solver is:
(solver
(>= x 1)
(< y (+ x 3)))
What I want instead is something like this (rise4fun link: http://rise4fun.com/Z3/aznC8):
(declare-const x Int)
(declare-const y Int)
(assert (>= x 1))
(assert (< y (+ x 3)))
(check-sat)
I have tried C API functions such as Z3_set_ast_print_mode, Z3_ast_to_string but haven't been successful. I looked at Z3_benchmark_to_smtlib_string but this post Input arguments of Z3_benchmark_to_smtlib_string() suggests that it only supports SMTLIB 1.0.
Z3_benchmark_to_smtlib_string is the only function Z3 has for this purpose. Like the post you refer to mentions, it has been extended to SMTLIB2. As Leo says in his reply to that post, it is an old function that is rarely used, and it may not support dumping all the features (e.g., parameters on solvers). Recently, there was also another post relating to this function and problems/bugs in older versions of Z3 (see here).