1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /* Commandline execution:
|
|---|
| 2 | * civl verify -inputnum_elements=5 derivative.cvl
|
|---|
| 3 | * */
|
|---|
| 4 | #include<civlc.h>
|
|---|
| 5 | #include<stdio.h>
|
|---|
| 6 |
|
|---|
| 7 | $input double h;
|
|---|
| 8 | $input int num_elements = 5;
|
|---|
| 9 | $input double initial[num_elements];
|
|---|
| 10 | double working[num_elements];
|
|---|
| 11 | $abstract $contin(3) $real rho($real x);
|
|---|
| 12 | $assume h > 0;
|
|---|
| 13 |
|
|---|
| 14 | void differentiate(double h, int n, double y[], double result[]){
|
|---|
| 15 | int i;
|
|---|
| 16 |
|
|---|
| 17 | $assume $forall {m=0 .. n-1} y[m] == rho(m*h);
|
|---|
| 18 | for(i = 1; i < n-1; i++)
|
|---|
| 19 | {
|
|---|
| 20 | result[i] = (y[i+1]-y[i-1])/(2*h);
|
|---|
| 21 | }
|
|---|
| 22 | result[0] = (y[1]-y[0])/h;
|
|---|
| 23 | result[n-1] = (y[n-1] - y[n-2])/h;
|
|---|
| 24 | $assert($uniform {k=1 .. n-2} result[k]-$D[rho,{x,1}](k*h) == $O(h*h));
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | void main() {
|
|---|
| 28 | differentiate(h, num_elements, initial, working);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.