/* Commandline execution: * civl verify -inputnum_elements=5 derivative.cvl * */ #include #include $input double h; $input int num_elements = 5; $input double initial[num_elements]; double working[num_elements]; $abstract $contin(3) $real rho($real x); $assume(h > 0); void differentiate(double h, int n, double y[], double result[]){ int i; $assume($forall {m=0 .. n-1} y[m] == rho(m*h)); for(i = 1; i < n-1; i++) { result[i] = (y[i+1]-y[i-1])/(2*h); } result[0] = (y[1]-y[0])/h; result[n-1] = (y[n-1] - y[n-2])/h; $assert(($uniform {k=1 .. n-2} result[k]-$D[rho,{x,1}](k*h) == $O(h*h))); } void main() { differentiate(h, num_elements, initial, working); }