1 /** @file inifcns_trans.cpp
3 * Implementation of transcendental (and trigonometric and hyperbolic)
7 * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "relational.h"
37 #ifndef NO_NAMESPACE_GINAC
39 #endif // ndef NO_NAMESPACE_GINAC
42 // exponential function
45 static ex exp_evalf(const ex & x)
51 return exp(ex_to_numeric(x)); // -> numeric exp(numeric)
54 static ex exp_eval(const ex & x)
60 // exp(n*Pi*I/2) -> {+1|+I|-1|-I}
61 ex TwoExOverPiI=(_ex2()*x)/(Pi*I);
62 if (TwoExOverPiI.info(info_flags::integer)) {
63 numeric z=mod(ex_to_numeric(TwoExOverPiI),_num4());
64 if (z.is_equal(_num0()))
66 if (z.is_equal(_num1()))
68 if (z.is_equal(_num2()))
70 if (z.is_equal(_num3()))
74 if (is_ex_the_function(x, log))
78 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
84 static ex exp_deriv(const ex & x, unsigned deriv_param)
86 GINAC_ASSERT(deriv_param==0);
88 // d/dx exp(x) -> exp(x)
92 REGISTER_FUNCTION(exp, eval_func(exp_eval).
93 evalf_func(exp_evalf).
94 derivative_func(exp_deriv));
100 static ex log_evalf(const ex & x)
104 END_TYPECHECK(log(x))
106 return log(ex_to_numeric(x)); // -> numeric log(numeric)
109 static ex log_eval(const ex & x)
111 if (x.info(info_flags::numeric)) {
112 if (x.is_equal(_ex1())) // log(1) -> 0
114 if (x.is_equal(_ex_1())) // log(-1) -> I*Pi
116 if (x.is_equal(I)) // log(I) -> Pi*I/2
117 return (Pi*I*_num1_2());
118 if (x.is_equal(-I)) // log(-I) -> -Pi*I/2
119 return (Pi*I*_num_1_2());
120 if (x.is_equal(_ex0())) // log(0) -> infinity
121 throw(std::domain_error("log_eval(): log(0)"));
123 if (!x.info(info_flags::crational))
126 // log(exp(t)) -> t (if -Pi < t.imag() <= Pi):
127 if (is_ex_the_function(x, exp)) {
129 if (t.info(info_flags::numeric)) {
130 numeric nt = ex_to_numeric(t);
136 return log(x).hold();
139 static ex log_deriv(const ex & x, unsigned deriv_param)
141 GINAC_ASSERT(deriv_param==0);
143 // d/dx log(x) -> 1/x
144 return power(x, _ex_1());
147 /*static ex log_series(const ex &x, const relational &rel, int order)
149 const ex x_pt = x.subs(rel);
150 if (!x_pt.info(info_flags::negative) && !x_pt.is_zero())
151 throw do_taylor(); // caught by function::series()
152 // now we either have to care for the branch cut or the branch point:
153 if (x_pt.is_zero()) { // branch point: return a plain log(x).
155 seq.push_back(expair(log(x), _ex0()));
156 return pseries(rel, seq);
158 const ex point = rel.rhs();
159 const symbol *s = static_cast<symbol *>(rel.lhs().bp);
161 // compute the formal series:
162 ex replx = series(log(x),*s==foo,order).subs(foo==point);
164 // FIXME: this is probably off by 2 or so:
165 seq.push_back(expair(-I*csgn(x*I)*Pi,_ex0()));
166 seq.push_back(expair(Order(_ex1()),order));
167 return series(replx + pseries(rel, seq),rel,order);
170 static ex log_series(const ex &x, const relational &r, int order)
172 if (x.subs(r).is_zero()) {
174 seq.push_back(expair(log(x), _ex0()));
175 return pseries(r, seq);
180 REGISTER_FUNCTION(log, eval_func(log_eval).
181 evalf_func(log_evalf).
182 derivative_func(log_deriv).
183 series_func(log_series));
186 // sine (trigonometric function)
189 static ex sin_evalf(const ex & x)
193 END_TYPECHECK(sin(x))
195 return sin(ex_to_numeric(x)); // -> numeric sin(numeric)
198 static ex sin_eval(const ex & x)
200 // sin(n/d*Pi) -> { all known non-nested radicals }
201 ex SixtyExOverPi = _ex60()*x/Pi;
203 if (SixtyExOverPi.info(info_flags::integer)) {
204 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
206 // wrap to interval [0, Pi)
211 // wrap to interval [0, Pi/2)
214 if (z.is_equal(_num0())) // sin(0) -> 0
216 if (z.is_equal(_num5())) // sin(Pi/12) -> sqrt(6)/4*(1-sqrt(3)/3)
217 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
218 if (z.is_equal(_num6())) // sin(Pi/10) -> sqrt(5)/4-1/4
219 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
220 if (z.is_equal(_num10())) // sin(Pi/6) -> 1/2
221 return sign*_ex1_2();
222 if (z.is_equal(_num15())) // sin(Pi/4) -> sqrt(2)/2
223 return sign*_ex1_2()*power(_ex2(),_ex1_2());
224 if (z.is_equal(_num18())) // sin(3/10*Pi) -> sqrt(5)/4+1/4
225 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
226 if (z.is_equal(_num20())) // sin(Pi/3) -> sqrt(3)/2
227 return sign*_ex1_2()*power(_ex3(),_ex1_2());
228 if (z.is_equal(_num25())) // sin(5/12*Pi) -> sqrt(6)/4*(1+sqrt(3)/3)
229 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
230 if (z.is_equal(_num30())) // sin(Pi/2) -> 1
234 if (is_ex_exactly_of_type(x, function)) {
237 if (is_ex_the_function(x, asin))
239 // sin(acos(x)) -> sqrt(1-x^2)
240 if (is_ex_the_function(x, acos))
241 return power(_ex1()-power(t,_ex2()),_ex1_2());
242 // sin(atan(x)) -> x*(1+x^2)^(-1/2)
243 if (is_ex_the_function(x, atan))
244 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
247 // sin(float) -> float
248 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
251 return sin(x).hold();
254 static ex sin_deriv(const ex & x, unsigned deriv_param)
256 GINAC_ASSERT(deriv_param==0);
258 // d/dx sin(x) -> cos(x)
262 REGISTER_FUNCTION(sin, eval_func(sin_eval).
263 evalf_func(sin_evalf).
264 derivative_func(sin_deriv));
267 // cosine (trigonometric function)
270 static ex cos_evalf(const ex & x)
274 END_TYPECHECK(cos(x))
276 return cos(ex_to_numeric(x)); // -> numeric cos(numeric)
279 static ex cos_eval(const ex & x)
281 // cos(n/d*Pi) -> { all known non-nested radicals }
282 ex SixtyExOverPi = _ex60()*x/Pi;
284 if (SixtyExOverPi.info(info_flags::integer)) {
285 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
287 // wrap to interval [0, Pi)
291 // wrap to interval [0, Pi/2)
295 if (z.is_equal(_num0())) // cos(0) -> 1
297 if (z.is_equal(_num5())) // cos(Pi/12) -> sqrt(6)/4*(1+sqrt(3)/3)
298 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
299 if (z.is_equal(_num10())) // cos(Pi/6) -> sqrt(3)/2
300 return sign*_ex1_2()*power(_ex3(),_ex1_2());
301 if (z.is_equal(_num12())) // cos(Pi/5) -> sqrt(5)/4+1/4
302 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
303 if (z.is_equal(_num15())) // cos(Pi/4) -> sqrt(2)/2
304 return sign*_ex1_2()*power(_ex2(),_ex1_2());
305 if (z.is_equal(_num20())) // cos(Pi/3) -> 1/2
306 return sign*_ex1_2();
307 if (z.is_equal(_num24())) // cos(2/5*Pi) -> sqrt(5)/4-1/4x
308 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
309 if (z.is_equal(_num25())) // cos(5/12*Pi) -> sqrt(6)/4*(1-sqrt(3)/3)
310 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
311 if (z.is_equal(_num30())) // cos(Pi/2) -> 0
315 if (is_ex_exactly_of_type(x, function)) {
318 if (is_ex_the_function(x, acos))
320 // cos(asin(x)) -> (1-x^2)^(1/2)
321 if (is_ex_the_function(x, asin))
322 return power(_ex1()-power(t,_ex2()),_ex1_2());
323 // cos(atan(x)) -> (1+x^2)^(-1/2)
324 if (is_ex_the_function(x, atan))
325 return power(_ex1()+power(t,_ex2()),_ex_1_2());
328 // cos(float) -> float
329 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
332 return cos(x).hold();
335 static ex cos_deriv(const ex & x, unsigned deriv_param)
337 GINAC_ASSERT(deriv_param==0);
339 // d/dx cos(x) -> -sin(x)
340 return _ex_1()*sin(x);
343 REGISTER_FUNCTION(cos, eval_func(cos_eval).
344 evalf_func(cos_evalf).
345 derivative_func(cos_deriv));
348 // tangent (trigonometric function)
351 static ex tan_evalf(const ex & x)
355 END_TYPECHECK(tan(x)) // -> numeric tan(numeric)
357 return tan(ex_to_numeric(x));
360 static ex tan_eval(const ex & x)
362 // tan(n/d*Pi) -> { all known non-nested radicals }
363 ex SixtyExOverPi = _ex60()*x/Pi;
365 if (SixtyExOverPi.info(info_flags::integer)) {
366 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num60());
368 // wrap to interval [0, Pi)
372 // wrap to interval [0, Pi/2)
376 if (z.is_equal(_num0())) // tan(0) -> 0
378 if (z.is_equal(_num5())) // tan(Pi/12) -> 2-sqrt(3)
379 return sign*(_ex2()-power(_ex3(),_ex1_2()));
380 if (z.is_equal(_num10())) // tan(Pi/6) -> sqrt(3)/3
381 return sign*_ex1_3()*power(_ex3(),_ex1_2());
382 if (z.is_equal(_num15())) // tan(Pi/4) -> 1
384 if (z.is_equal(_num20())) // tan(Pi/3) -> sqrt(3)
385 return sign*power(_ex3(),_ex1_2());
386 if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
387 return sign*(power(_ex3(),_ex1_2())+_ex2());
388 if (z.is_equal(_num30())) // tan(Pi/2) -> infinity
389 throw (std::domain_error("tan_eval(): simple pole"));
392 if (is_ex_exactly_of_type(x, function)) {
395 if (is_ex_the_function(x, atan))
397 // tan(asin(x)) -> x*(1+x^2)^(-1/2)
398 if (is_ex_the_function(x, asin))
399 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
400 // tan(acos(x)) -> (1-x^2)^(1/2)/x
401 if (is_ex_the_function(x, acos))
402 return power(t,_ex_1())*power(_ex1()-power(t,_ex2()),_ex1_2());
405 // tan(float) -> float
406 if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
410 return tan(x).hold();
413 static ex tan_deriv(const ex & x, unsigned deriv_param)
415 GINAC_ASSERT(deriv_param==0);
417 // d/dx tan(x) -> 1+tan(x)^2;
418 return (_ex1()+power(tan(x),_ex2()));
421 static ex tan_series(const ex &x, const relational &rel, int order)
424 // Taylor series where there is no pole falls back to tan_deriv.
425 // On a pole simply expand sin(x)/cos(x).
426 const ex x_pt = x.subs(rel);
427 if (!(2*x_pt/Pi).info(info_flags::odd))
428 throw do_taylor(); // caught by function::series()
429 // if we got here we have to care for a simple pole
430 return (sin(x)/cos(x)).series(rel, order+2);
433 REGISTER_FUNCTION(tan, eval_func(tan_eval).
434 evalf_func(tan_evalf).
435 derivative_func(tan_deriv).
436 series_func(tan_series));
439 // inverse sine (arc sine)
442 static ex asin_evalf(const ex & x)
446 END_TYPECHECK(asin(x))
448 return asin(ex_to_numeric(x)); // -> numeric asin(numeric)
451 static ex asin_eval(const ex & x)
453 if (x.info(info_flags::numeric)) {
458 if (x.is_equal(_ex1_2()))
459 return numeric(1,6)*Pi;
461 if (x.is_equal(_ex1()))
463 // asin(-1/2) -> -Pi/6
464 if (x.is_equal(_ex_1_2()))
465 return numeric(-1,6)*Pi;
467 if (x.is_equal(_ex_1()))
468 return _num_1_2()*Pi;
469 // asin(float) -> float
470 if (!x.info(info_flags::crational))
471 return asin_evalf(x);
474 return asin(x).hold();
477 static ex asin_deriv(const ex & x, unsigned deriv_param)
479 GINAC_ASSERT(deriv_param==0);
481 // d/dx asin(x) -> 1/sqrt(1-x^2)
482 return power(1-power(x,_ex2()),_ex_1_2());
485 REGISTER_FUNCTION(asin, eval_func(asin_eval).
486 evalf_func(asin_evalf).
487 derivative_func(asin_deriv));
490 // inverse cosine (arc cosine)
493 static ex acos_evalf(const ex & x)
497 END_TYPECHECK(acos(x))
499 return acos(ex_to_numeric(x)); // -> numeric acos(numeric)
502 static ex acos_eval(const ex & x)
504 if (x.info(info_flags::numeric)) {
506 if (x.is_equal(_ex1()))
509 if (x.is_equal(_ex1_2()))
514 // acos(-1/2) -> 2/3*Pi
515 if (x.is_equal(_ex_1_2()))
516 return numeric(2,3)*Pi;
518 if (x.is_equal(_ex_1()))
520 // acos(float) -> float
521 if (!x.info(info_flags::crational))
522 return acos_evalf(x);
525 return acos(x).hold();
528 static ex acos_deriv(const ex & x, unsigned deriv_param)
530 GINAC_ASSERT(deriv_param==0);
532 // d/dx acos(x) -> -1/sqrt(1-x^2)
533 return _ex_1()*power(1-power(x,_ex2()),_ex_1_2());
536 REGISTER_FUNCTION(acos, eval_func(acos_eval).
537 evalf_func(acos_evalf).
538 derivative_func(acos_deriv));
541 // inverse tangent (arc tangent)
544 static ex atan_evalf(const ex & x)
548 END_TYPECHECK(atan(x))
550 return atan(ex_to_numeric(x)); // -> numeric atan(numeric)
553 static ex atan_eval(const ex & x)
555 if (x.info(info_flags::numeric)) {
557 if (x.is_equal(_ex0()))
559 // atan(float) -> float
560 if (!x.info(info_flags::crational))
561 return atan_evalf(x);
564 return atan(x).hold();
567 static ex atan_deriv(const ex & x, unsigned deriv_param)
569 GINAC_ASSERT(deriv_param==0);
571 // d/dx atan(x) -> 1/(1+x^2)
572 return power(_ex1()+power(x,_ex2()), _ex_1());
575 REGISTER_FUNCTION(atan, eval_func(atan_eval).
576 evalf_func(atan_evalf).
577 derivative_func(atan_deriv));
580 // inverse tangent (atan2(y,x))
583 static ex atan2_evalf(const ex & y, const ex & x)
588 END_TYPECHECK(atan2(y,x))
590 return atan(ex_to_numeric(y),ex_to_numeric(x)); // -> numeric atan(numeric)
593 static ex atan2_eval(const ex & y, const ex & x)
595 if (y.info(info_flags::numeric) && !y.info(info_flags::crational) &&
596 x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
597 return atan2_evalf(y,x);
600 return atan2(y,x).hold();
603 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
605 GINAC_ASSERT(deriv_param<2);
607 if (deriv_param==0) {
609 return x*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
612 return -y*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
615 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
616 evalf_func(atan2_evalf).
617 derivative_func(atan2_deriv));
620 // hyperbolic sine (trigonometric function)
623 static ex sinh_evalf(const ex & x)
627 END_TYPECHECK(sinh(x))
629 return sinh(ex_to_numeric(x)); // -> numeric sinh(numeric)
632 static ex sinh_eval(const ex & x)
634 if (x.info(info_flags::numeric)) {
635 if (x.is_zero()) // sinh(0) -> 0
637 if (!x.info(info_flags::crational)) // sinh(float) -> float
638 return sinh_evalf(x);
641 if ((x/Pi).info(info_flags::numeric) &&
642 ex_to_numeric(x/Pi).real().is_zero()) // sinh(I*x) -> I*sin(x)
645 if (is_ex_exactly_of_type(x, function)) {
647 // sinh(asinh(x)) -> x
648 if (is_ex_the_function(x, asinh))
650 // sinh(acosh(x)) -> (x-1)^(1/2) * (x+1)^(1/2)
651 if (is_ex_the_function(x, acosh))
652 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2());
653 // sinh(atanh(x)) -> x*(1-x^2)^(-1/2)
654 if (is_ex_the_function(x, atanh))
655 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
658 return sinh(x).hold();
661 static ex sinh_deriv(const ex & x, unsigned deriv_param)
663 GINAC_ASSERT(deriv_param==0);
665 // d/dx sinh(x) -> cosh(x)
669 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
670 evalf_func(sinh_evalf).
671 derivative_func(sinh_deriv));
674 // hyperbolic cosine (trigonometric function)
677 static ex cosh_evalf(const ex & x)
681 END_TYPECHECK(cosh(x))
683 return cosh(ex_to_numeric(x)); // -> numeric cosh(numeric)
686 static ex cosh_eval(const ex & x)
688 if (x.info(info_flags::numeric)) {
689 if (x.is_zero()) // cosh(0) -> 1
691 if (!x.info(info_flags::crational)) // cosh(float) -> float
692 return cosh_evalf(x);
695 if ((x/Pi).info(info_flags::numeric) &&
696 ex_to_numeric(x/Pi).real().is_zero()) // cosh(I*x) -> cos(x)
699 if (is_ex_exactly_of_type(x, function)) {
701 // cosh(acosh(x)) -> x
702 if (is_ex_the_function(x, acosh))
704 // cosh(asinh(x)) -> (1+x^2)^(1/2)
705 if (is_ex_the_function(x, asinh))
706 return power(_ex1()+power(t,_ex2()),_ex1_2());
707 // cosh(atanh(x)) -> (1-x^2)^(-1/2)
708 if (is_ex_the_function(x, atanh))
709 return power(_ex1()-power(t,_ex2()),_ex_1_2());
712 return cosh(x).hold();
715 static ex cosh_deriv(const ex & x, unsigned deriv_param)
717 GINAC_ASSERT(deriv_param==0);
719 // d/dx cosh(x) -> sinh(x)
723 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
724 evalf_func(cosh_evalf).
725 derivative_func(cosh_deriv));
729 // hyperbolic tangent (trigonometric function)
732 static ex tanh_evalf(const ex & x)
736 END_TYPECHECK(tanh(x))
738 return tanh(ex_to_numeric(x)); // -> numeric tanh(numeric)
741 static ex tanh_eval(const ex & x)
743 if (x.info(info_flags::numeric)) {
744 if (x.is_zero()) // tanh(0) -> 0
746 if (!x.info(info_flags::crational)) // tanh(float) -> float
747 return tanh_evalf(x);
750 if ((x/Pi).info(info_flags::numeric) &&
751 ex_to_numeric(x/Pi).real().is_zero()) // tanh(I*x) -> I*tan(x);
754 if (is_ex_exactly_of_type(x, function)) {
756 // tanh(atanh(x)) -> x
757 if (is_ex_the_function(x, atanh))
759 // tanh(asinh(x)) -> x*(1+x^2)^(-1/2)
760 if (is_ex_the_function(x, asinh))
761 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
762 // tanh(acosh(x)) -> (x-1)^(1/2)*(x+1)^(1/2)/x
763 if (is_ex_the_function(x, acosh))
764 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2())*power(t,_ex_1());
767 return tanh(x).hold();
770 static ex tanh_deriv(const ex & x, unsigned deriv_param)
772 GINAC_ASSERT(deriv_param==0);
774 // d/dx tanh(x) -> 1-tanh(x)^2
775 return _ex1()-power(tanh(x),_ex2());
778 static ex tanh_series(const ex &x, const relational &rel, int order)
781 // Taylor series where there is no pole falls back to tanh_deriv.
782 // On a pole simply expand sinh(x)/cosh(x).
783 const ex x_pt = x.subs(rel);
784 if (!(2*I*x_pt/Pi).info(info_flags::odd))
785 throw do_taylor(); // caught by function::series()
786 // if we got here we have to care for a simple pole
787 return (sinh(x)/cosh(x)).series(rel, order+2);
790 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
791 evalf_func(tanh_evalf).
792 derivative_func(tanh_deriv).
793 series_func(tanh_series));
796 // inverse hyperbolic sine (trigonometric function)
799 static ex asinh_evalf(const ex & x)
803 END_TYPECHECK(asinh(x))
805 return asinh(ex_to_numeric(x)); // -> numeric asinh(numeric)
808 static ex asinh_eval(const ex & x)
810 if (x.info(info_flags::numeric)) {
814 // asinh(float) -> float
815 if (!x.info(info_flags::crational))
816 return asinh_evalf(x);
819 return asinh(x).hold();
822 static ex asinh_deriv(const ex & x, unsigned deriv_param)
824 GINAC_ASSERT(deriv_param==0);
826 // d/dx asinh(x) -> 1/sqrt(1+x^2)
827 return power(_ex1()+power(x,_ex2()),_ex_1_2());
830 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
831 evalf_func(asinh_evalf).
832 derivative_func(asinh_deriv));
835 // inverse hyperbolic cosine (trigonometric function)
838 static ex acosh_evalf(const ex & x)
842 END_TYPECHECK(acosh(x))
844 return acosh(ex_to_numeric(x)); // -> numeric acosh(numeric)
847 static ex acosh_eval(const ex & x)
849 if (x.info(info_flags::numeric)) {
850 // acosh(0) -> Pi*I/2
852 return Pi*I*numeric(1,2);
854 if (x.is_equal(_ex1()))
857 if (x.is_equal(_ex_1()))
859 // acosh(float) -> float
860 if (!x.info(info_flags::crational))
861 return acosh_evalf(x);
864 return acosh(x).hold();
867 static ex acosh_deriv(const ex & x, unsigned deriv_param)
869 GINAC_ASSERT(deriv_param==0);
871 // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
872 return power(x+_ex_1(),_ex_1_2())*power(x+_ex1(),_ex_1_2());
875 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
876 evalf_func(acosh_evalf).
877 derivative_func(acosh_deriv));
880 // inverse hyperbolic tangent (trigonometric function)
883 static ex atanh_evalf(const ex & x)
887 END_TYPECHECK(atanh(x))
889 return atanh(ex_to_numeric(x)); // -> numeric atanh(numeric)
892 static ex atanh_eval(const ex & x)
894 if (x.info(info_flags::numeric)) {
898 // atanh({+|-}1) -> throw
899 if (x.is_equal(_ex1()) || x.is_equal(_ex_1()))
900 throw (std::domain_error("atanh_eval(): logarithmic pole"));
901 // atanh(float) -> float
902 if (!x.info(info_flags::crational))
903 return atanh_evalf(x);
906 return atanh(x).hold();
909 static ex atanh_deriv(const ex & x, unsigned deriv_param)
911 GINAC_ASSERT(deriv_param==0);
913 // d/dx atanh(x) -> 1/(1-x^2)
914 return power(_ex1()-power(x,_ex2()),_ex_1());
917 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
918 evalf_func(atanh_evalf).
919 derivative_func(atanh_deriv));
921 #ifndef NO_NAMESPACE_GINAC
923 #endif // ndef NO_NAMESPACE_GINAC