| 1 | #include <complex.h>
|
|---|
| 2 | #include <math.h>
|
|---|
| 3 | typedef double _Complex dc;
|
|---|
| 4 | $input dc X, Y;
|
|---|
| 5 | $input double R;
|
|---|
| 6 |
|
|---|
| 7 | int main(void) {
|
|---|
| 8 | $print("X=", X, ", Y=", Y, ", R=", R, "\n");
|
|---|
| 9 |
|
|---|
| 10 | $assert(sqrt(R*R) == R);
|
|---|
| 11 |
|
|---|
| 12 | $print("cabs(X) = ", cabs(X), "\n");
|
|---|
| 13 | $assert(cabs(X) >= 0);
|
|---|
| 14 |
|
|---|
| 15 | $print("R*X = ", R*X, "\n");
|
|---|
| 16 | $print("cabs(R*X) = ", cabs(R*X), "\n");
|
|---|
| 17 | $print("fabs(R) = ", fabs(R), "\n");
|
|---|
| 18 | $print("cabs(X) = ", cabs(X), "\n");
|
|---|
| 19 | $print("fabs(R) * cabs(X) = ", fabs(R)*cabs(X), "\n");
|
|---|
| 20 |
|
|---|
| 21 | // commenting out for now due to bug in simplification of reals.
|
|---|
| 22 | // CIVL simplifies sqrt(x*x) to x, not |x|.
|
|---|
| 23 | //$assert(cabs(R*X) == fabs(R) * cabs(X));
|
|---|
| 24 |
|
|---|
| 25 | dc z = X*Y;
|
|---|
| 26 | $print("X*Y = ", z, "\n");
|
|---|
| 27 | $assert(creal(z) == creal(X)*creal(Y) - cimag(X)*cimag(Y));
|
|---|
| 28 | $assert(cimag(z) == creal(X)*cimag(Y) + cimag(X)*creal(Y));
|
|---|
| 29 |
|
|---|
| 30 | z = R*X;
|
|---|
| 31 | $print("R*X = ", z, "\n");
|
|---|
| 32 | $assert(creal(z) == R*creal(X));
|
|---|
| 33 | $assert(cimag(z) == R*cimag(X));
|
|---|
| 34 |
|
|---|
| 35 | $assume(R != 0);
|
|---|
| 36 | z = X/R;
|
|---|
| 37 | $print("X/R = ", z, "\n");
|
|---|
| 38 | $assert(creal(z) == creal(X)/R);
|
|---|
| 39 | $assert(cimag(z) == cimag(X)/R);
|
|---|
| 40 |
|
|---|
| 41 | z = X - Y;
|
|---|
| 42 | $print("X - Y = ", z, "\n");
|
|---|
| 43 | $assert(creal(z) == creal(X)-creal(Y));
|
|---|
| 44 | $assert(cimag(z) == cimag(X)-cimag(Y));
|
|---|
| 45 |
|
|---|
| 46 | $print("cacos(X)=", cacos(X), ", cacos(Y)=", cacos(Y), "\n");
|
|---|
| 47 | if (cacos(X) != cacos(Y))
|
|---|
| 48 | $assert(X != Y);
|
|---|
| 49 |
|
|---|
| 50 | $assume(Y != 0);
|
|---|
| 51 | $assert((X/Y)*Y == X);
|
|---|
| 52 |
|
|---|
| 53 | $assert(cabs(Y/cabs(Y)) == 1);
|
|---|
| 54 |
|
|---|
| 55 | $assume(X != 0);
|
|---|
| 56 | $assert((X/Y)*(Y/X) == 1.0);
|
|---|
| 57 | }
|
|---|