【发布时间】:2021-08-23 19:09:54
【问题描述】:
我相信我可以使用Why3 和不同的证明者生成证明,
frama-c -wp -wp-prover cvc4 -wp-rte -wp-out proof swap.cframa-c -wp -wp-prover z3-ce -wp-rte -wp-out proof swap.cframa-c -wp -wp-prover alt-ergo -wp-rte -wp-out proof swap.c
这会生成不同的“为什么”文件。我想通过外部程序验证证明义务。似乎每个证明义务的格式都不同; LispClojure 和 OCaml?格式到底是什么?这些是证据并且足以证明合同/证明是正确的,而不证明 Z3、alt-ergo 等是正确的,这是否正确?
swap.c
对于wp tutorial,
int h = 42;
/*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures *a == \old(*b) && *b == \old(*a);
*/
void swap(int* a, int* b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
int main()
{
int a = 24;
int b = 37;
//@ assert h == 42;
swap(&a, &b);
//@ assert a == 37 && b == 24;
//@ assert h == 42;
return 0;
}
这很好用,frama-c-gui 向我展示了如何开发合同和注释。
Alter-ergo
(* WP Task for Prover Alt-Ergo,2.4.1 *) (* this is the prelude for Alt-Ergo, version >= 2.4.0 *) (* this is a prelude for Alt-Ergo integer arithmetic *) (* this is a prelude for Alt-Ergo real arithmetic *) type string
logic match_bool : bool, 'a, 'a -> 'a
axiom match_bool_True : (forall z:'a. forall z1:'a. (match_bool(true, z, z1) = z))
为简洁起见,完整的证明被截断。
z3-ce
(* WP Task for Prover Z3,4.8.11,counterexamples *) ;;; generated by SMT-LIB2 driver ;;; SMT-LIB2 driver: bit-vectors, common part ;;; generated by SMT-LIB strings ;;; generated by SMT-LIB strings (set-option :produce-models true) ;;; SMT-LIB2: integer arithmetic ;;; SMT-LIB2: real arithmetic (declare-sort uni 0)
(declare-sort ty 0)
(declare-fun sort (ty uni) Bool)
(declare-fun witness (ty) uni)
为简洁起见,完整的证明被截断。
【问题讨论】:
-
ZMT-LIB 位于 URL smtlib.cs.uiowa.edu。看起来 Z3 和 CVC4 都使用这种格式作为输出。仍然不确定 Alt-Ergo。
-
删除第一行
(* WP Task for Prover...),我可以使用cvc4 --lang smt2 file.why和z3 -smt2 file.why处理文件,其中'file.why' 是使用该证明者生成的。例如,我无法使用 cvc4 验证 z3 输出...smtlib grammar in flex/bison