我相信我可以使用带有不同证明者的Why3来生成证明,
frama-c -wp -wp-prover cvc4 -wp-rte -wp-out proof swap.c
frama-c -wp -wp-prover z3-ce -wp-rte -wp-out proof swap.c
frama-c -wp -wp-prover alt-ergo -wp-rte -wp-out proof swap.c
这会生成不同的“为什么”文件。我想通过外部程序验证证明义务。似乎每个证明义务的格式都不同;Lisp Clojure 和 OCaml?格式到底是什么?这些是证据并且足以证明合同/证明是正确的,而无需证明 Z3、alt-ergo 等是否正确,这是否正确?
交换文件
对于wp 教程,
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向我展示了如何开发合同和注释。
变体
(* 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)
为简洁起见,完整的证明被截断。