1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | #include <civlc.cvh>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 |
|
|---|
| 4 | $input int A_BOUND=4;
|
|---|
| 5 | $input int B_BOUND=6;
|
|---|
| 6 | $input int A;
|
|---|
| 7 | $input int B;
|
|---|
| 8 | // assume the bound of A and B
|
|---|
| 9 | $assume (A>0 && B>0 && A<A_BOUND && B<B_BOUND);
|
|---|
| 10 |
|
|---|
| 11 | /*
|
|---|
| 12 | NOTE: CVC4 ERROR
|
|---|
| 13 |
|
|---|
| 14 | problem description:
|
|---|
| 15 | Various parallel GCD algorithms exist. In this challenge, we consider a
|
|---|
| 16 | simple Euclid-like algorithm with two parallel threads. One thread
|
|---|
| 17 | subtracts in one direction, the other thread subtracts in the other
|
|---|
| 18 | direction, and eventually this procedure converges on GCD.
|
|---|
| 19 |
|
|---|
| 20 | command: civl verify -inputA_BOUND=6 -inputB_BOUND=4 ParallelGCD_2015_2.c
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | int myGCD(int a, int b){
|
|---|
| 24 | $proc proc_a;
|
|---|
| 25 | $proc proc_b;
|
|---|
| 26 |
|
|---|
| 27 | void worker1() {
|
|---|
| 28 | while(a != b){
|
|---|
| 29 | if(a>b){
|
|---|
| 30 | int t1 = b;
|
|---|
| 31 | int t2 = a-t1;
|
|---|
| 32 | a = t2;
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | void worker2(){
|
|---|
| 37 | while(a != b){
|
|---|
| 38 | if(b>a){
|
|---|
| 39 | int t1 = a;
|
|---|
| 40 | int t2 = b-t1;
|
|---|
| 41 | b = t2;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | proc_a= $spawn worker1();
|
|---|
| 46 | proc_b= $spawn worker2();
|
|---|
| 47 | $wait(proc_a);
|
|---|
| 48 | $wait(proc_b);
|
|---|
| 49 | return a;
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | int seqGCD(int a, int b){
|
|---|
| 53 | while(a != b){
|
|---|
| 54 | if(a > b)
|
|---|
| 55 | a = a-b;
|
|---|
| 56 | if(b > a)
|
|---|
| 57 | b = b-a;
|
|---|
| 58 | }
|
|---|
| 59 | return a;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | void main(){
|
|---|
| 63 | int result1 = myGCD(A, B);
|
|---|
| 64 | int minAB = A < B ? A : B;
|
|---|
| 65 | $assert($forall {i = (result1+1) .. (minAB)} (A%i != 0 || B%i != 0));
|
|---|
| 66 | $assert( A%result1 == 0 && B%result1 == 0);
|
|---|
| 67 |
|
|---|
| 68 | // $assert($forall {int i | i >=(result1+1) && i < minAB} (A%i != 0 || B%i != 0));
|
|---|
| 69 | // $assert( A%result1 == 0 && B%result1 == 0);
|
|---|
| 70 | //$assert(!($exists {int i | i > result1 && i <= minAB} (A%i==0 && B%i==0)));
|
|---|
| 71 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.