我正在尝试将OpenJML与Z3结合起来,并试图对double或float值进行推理:
class Test {
//@ requires b > 0;
void a(double b) {
}
void b() {
a(2.4);
}
}我已经发现OpenJML使用AUFLIA作为默认逻辑,它不支持reals。我现在正在使用AUFNIRA。
不幸的是,该工具无法证明这个类:
→ java -jar openjml.jar -esc -prover z3_4_3 -exec ./z3 Test.java -noInternalSpecs -logic AUFNIRA
Test.java:8: warning: The prover cannot establish an assertion (Precondition: Test.java:3: ) in method b
a(2.4);
^
Test.java:3: warning: Associated declaration: Test.java:8:
//@ requires b > 0;
^
2 warnings为什么会这样呢?
发布于 2015-07-21 14:55:42
当涉及双倍时,SMT翻译(用作z3的输入)似乎是错误的。在下面的程序B中,它使用双倍而不是ints,调用或预条件的常量永远不会被转换为SMT。
这是openjml的错误,而不是z3的错误--因为z3需要使用某种形式的(define-fun _JML__tmp3 () Real 2345.0) (参见程序A的详细输出),但是openjml从不生成它。一般说来,floating point support seems to be buggy.
程序A (有ints):
class Test {
//@ requires b > 1234;
void a(int b) { }
void z() { a(2345); }
}输出(与-verbose | grep 234一起运行,以搜索详细输出中提到的1234或2345 ):
// requires b > 1234;
Pre_1 = b > 1234;
// requires b > 1234;
assume Assignment Pre_1_0_21___4 == b_55 > 1234;
(assert (= BL_58bodyBegin_2 (=> (= _JML___exception_49_49___1 NULL) (=> (= _JML___termination_49_49___2 0) (=> (distinct THIS NULL) (=> (or (= THIS NULL) (and (and (distinct THIS NULL) (javaSubType (javaTypeOf THIS) T_Test)) (jmlSubType (jmlTypeOf THIS) JMLT_Test))) (=> (and (<= (- 2147483648) b_55) (<= b_55 2147483647)) (=> (select _isalloc___0 THIS) (=> (= (select _alloc___0 THIS) 0) (=> (= Pre_1_0_21___3 false) (=> (= Pre_1_0_21___4 (> b_55 1234)) (=> Pre_1_0_21___4 BL_49_AfterLabel_3))))))))))))
a(2345);
// a(2345)
int _JML__tmp3 = 2345;
boolean _JML__tmp6 = _JML__tmp3 > 1234;
// a(2345)
int _JML__tmp3 = 2345
boolean _JML__tmp6 = _JML__tmp3 > 1234
(define-fun _JML__tmp3 () Int 2345)
(define-fun _JML__tmp6 () Bool (> _JML__tmp3 1234))结果:
EXECUTION
Proof result is unsat
Method checked OK
[total 427ms] 程序B (带双打):
class Test {
//@ requires b > 1234.0;
void a(double b) { }
void z() { a(2345.0); }
}输出(与-verbose | grep 234一起运行,以搜索详细输出中提到的1234.0或2345.0 ):
// requires b > 1234.0;
Pre_1 = b > 1234.0;
// requires b > 1234.0;
assume Assignment Pre_1_0_29___4 == b_72 > 1234.0;
a(2345.0);
// a(2345.0)
double _JML__tmp3 = 2345.0;
boolean _JML__tmp6 = _JML__tmp3 > 1234.0;
// a(2345.0)
double _JML__tmp3 = 2345.0
boolean _JML__tmp6 = _JML__tmp3 > 1234.0
void z() { a(2345.0); }
//@ requires b > 1234.0;
Test.java:4: a(2345.0)
VALUE: 2345.0 === 0.0结果:
EXECUTION
Proof result is sat
Some assertion is not valid
Test.java:4: warning: The prover cannot establish an assertion (Precondition: Test.java:2: ) in method z
void z() { a(2345.0); }
^
Test.java:2: warning: Associated declaration: Test.java:4:
//@ requires b > 1234.0;
^发布于 2015-07-21 13:25:03
在下面的链接中,您可以看到它们是如何解释规范不完整的。您的案例显示了与链接中的示例相同的行为。即使您尝试其他数字,它也会失败,因为您需要添加更多openjml子句。
在这里,链接:http://soft.vub.ac.be/~qstieven/sq/session8.html
https://stackoverflow.com/questions/31413679
复制相似问题