1 // check/inifcns_consist.cpp
3 /* This test routine applies assorted tests on initially known higher level
8 /* Simple tests on the sine trigonometric function. */
9 static unsigned inifcns_consist_sin(void)
16 for (int n=-10; n<=10; ++n) {
17 if ( sin(n*Pi).eval() != numeric(0) ||
18 !sin(n*Pi).eval().info(info_flags::integer) )
22 clog << "sin(n*Pi) with integer n does not always return exact 0"
27 // sin((n+1/2)*Pi) == {+|-}1?
29 for (int n=-10; n<=10; ++n) {
30 if ( ! sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
31 !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
32 sin((n+numeric(1,2))*Pi).eval() == numeric(-1)) )
36 clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
44 /* Simple tests on the cosine trigonometric function. */
45 static unsigned inifcns_consist_cos(void)
50 // cos((n+1/2)*Pi) == 0?
52 for (int n=-10; n<=10; ++n) {
53 if ( cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
54 !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer) )
58 clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
65 for (int n=-10; n<=10; ++n) {
66 if ( ! cos(n*Pi).eval().info(info_flags::integer) ||
67 !(cos(n*Pi).eval() == numeric(1) ||
68 cos(n*Pi).eval() == numeric(-1)) )
72 clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
80 /* Assorted tests on other transcendental functions. */
81 static unsigned inifcns_consist_trans(void)
87 chk = asin(1)-acos(0);
89 clog << "asin(1)-acos(0) erroneously returned " << chk
90 << " instead of 0" << endl;
94 // arbitrary check of type sin(f(x)):
95 chk = pow(sin(acos(x)),2) + pow(sin(asin(x)),2)
96 - (1+pow(x,2))*pow(sin(atan(x)),2);
97 if (chk != 1-pow(x,2)) {
98 clog << "sin(acos(x))^2 + sin(asin(x))^2 - (1+x^2)*sin(atan(x))^2 "
99 << "erroneously returned " << chk << " instead of 1-x^2" << endl;
103 // arbitrary check of type cos(f(x)):
104 chk = pow(cos(acos(x)),2) + pow(cos(asin(x)),2)
105 - (1+pow(x,2))*pow(cos(atan(x)),2);
106 if (!chk.is_zero()) {
107 clog << "cos(acos(x))^2 + cos(asin(x))^2 - (1+x^2)*cos(atan(x))^2 "
108 << "erroneously returned " << chk << " instead of 0" << endl;
112 // arbitrary check of type tan(f(x)):
113 chk = tan(acos(x))*tan(asin(x)) - tan(atan(x));
115 clog << "tan(acos(x))*tan(asin(x)) - tan(atan(x)) "
116 << "erroneously returned " << chk << " instead of -x+1" << endl;
120 // arbitrary check of type sinh(f(x)):
121 chk = -pow(sinh(acosh(x)),2).expand()*pow(sinh(atanh(x)),2)
122 - pow(sinh(asinh(x)),2);
123 if (!chk.is_zero()) {
124 clog << "expand(-(sinh(acosh(x)))^2)*(sinh(atanh(x))^2) - sinh(asinh(x))^2 "
125 << "erroneously returned " << chk << " instead of 0" << endl;
129 // arbitrary check of type cosh(f(x)):
130 chk = (pow(cosh(asinh(x)),2) - 2*pow(cosh(acosh(x)),2))
131 * pow(cosh(atanh(x)),2);
133 clog << "(cosh(asinh(x))^2 - 2*cosh(acosh(x))^2) * cosh(atanh(x))^2 "
134 << "erroneously returned " << chk << " instead of 1" << endl;
138 // arbitrary check of type tanh(f(x)):
139 chk = (pow(tanh(asinh(x)),-2) - pow(tanh(acosh(x)),2)).expand()
140 * pow(tanh(atanh(x)),2);
142 clog << "expand(tanh(acosh(x))^2 - tanh(asinh(x))^(-2)) * tanh(atanh(x))^2 "
143 << "erroneously returned " << chk << " instead of 2" << endl;
150 /* Simple tests on the Gamma combinatorial function. We stuff in arguments
151 * where the result exists in closed form and check if it's ok. */
152 static unsigned inifcns_consist_gamma(void)
158 for (int i=2; i<8; ++i) {
161 if ( e != numeric(874) ) {
162 clog << "gamma(1)+...+gamma(7) erroneously returned "
163 << e << " instead of 874" << endl;
168 for (int i=2; i<8; ++i) {
171 if ( e != numeric(24883200) ) {
172 clog << "gamma(1)*...*gamma(7) erroneously returned "
173 << e << " instead of 24883200" << endl;
177 e = gamma(ex(numeric(5, 2)))*gamma(ex(numeric(9, 2)))*64;
179 clog << "64*gamma(5/2)*gamma(9/2) erroneously returned "
180 << e << " instead of 315*Pi" << endl;
184 e = gamma(ex(numeric(-13, 2)));
185 for (int i=-13; i<7; i=i+2) {
186 e += gamma(ex(numeric(i, 2)));
188 e = (e*gamma(ex(numeric(15, 2)))*numeric(512));
189 if ( e != numeric(633935)*Pi ) {
190 clog << "512*(gamma(-13/2)+...+gamma(5/2))*gamma(15/2) erroneously returned "
191 << e << " instead of 633935*Pi" << endl;
198 unsigned inifcns_consist(void)
202 cout << "checking consistency of symbolic functions..." << flush;
203 clog << "---------consistency of symbolic functions:" << endl;
205 result += inifcns_consist_sin();
206 result += inifcns_consist_cos();
207 result += inifcns_consist_trans();
208 result += inifcns_consist_gamma();
212 clog << "(no output)" << endl;