如何使用z3c++;API来证明基于输入参数的理论? 我尝试使用Z3C++ API来实现以下内容: (set-option :produce-proofs true) (declare-const Weight Int) (declare-const WeightLimit Int) (declare-const P1 Bool) (assert (= WeightLimit 10)) (assert (= P1 (>= Weight WeightLimit))) (assert (= P1 true)) ;Facts - Input (assert (= Weight 100)) (check-sat)
我最终完成了以下功能:如何使用z3c++;API来证明基于输入参数的理论? 我尝试使用Z3C++ API来实现以下内容: (set-option :produce-proofs true) (declare-const Weight Int) (declare-const WeightLimit Int) (declare-const P1 Bool) (assert (= WeightLimit 10)) (assert (= P1 (>= Weight WeightLimit))) (assert (= P1 true)) ;Facts - Input (assert (= Weight 100)) (check-sat),c++,z3,smt,C++,Z3,Smt,我最终完成了以下功能: void test() { try { context ctx; Z3_string str = "(declare-const Weight Int) (declare-const WeightLimit Int) (declare-const P1 Bool) (assert (= WeightLimit 10)) (assert (= P1 (>= Weight WeightLimit))
void test() {
try {
context ctx;
Z3_string str = "(declare-const Weight Int) (declare-const WeightLimit Int) (declare-const P1 Bool) (assert (= WeightLimit 10)) (assert (= P1 (>= Weight WeightLimit))) (assert (= P1 true)) (assert (= Weight 100)) (check-sat)"; //Generated by some other function
expr fs(ctx, Z3_parse_smtlib2_string(Z3_context(ctx), str, 0, 0, 0, 0, 0, 0));
solver s(ctx);
s.add(fs);
switch (s.check()) {
case unsat: std::cout << "not satisfied\n"; break;
case sat: std::cout << "satisfied\n"; break;
case unknown: std::cout << "unknown\n"; break;
}
model m = s.get_model();
std::cout << m << "\n";
}
catch (z3::exception e) {
std::cout << e.msg() << std::endl;
}
}
void测试(){
试试{
上下文ctx;
Z3_string str=“(declare const Weight Int)(declare const Weight limit Int)(declare const P1 Bool)(assert(=WeightLimit 10))(assert(=P1(>=Weight WeightLimit)))(assert(=P1 true))(assert(=Weight 100))(check sat)”;//由其他函数生成
expr fs(ctx,Z3_parse_smtlib2_字符串(Z3_上下文(ctx),str,0,0,0,0));
解算器s(ctx);
s、 添加(fs);
开关(s.check()){
case unsat:std::cout好吧,这需要由生成该字符串作为其输出的函数来处理,您注释为“/”的字符串是由其他函数生成的”
只需将权重作为参数传递给该函数,该函数在生成字符串时应使用正确的值
如果由于任何原因该函数不可用,则必须进行一些字符串处理;但这当然是非常脆弱和容易出错的
另一种选择是不传递字符串,而是使用API一次实际断言一个事实;但从您的描述来看,这似乎也不是您的选择。我期望如果Weight
以值9传递,(assert(=P1(>=Weight-WeightLimit))的理论
不应满足要求。