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"
36 #ifndef NO_NAMESPACE_GINAC
38 #endif // ndef NO_NAMESPACE_GINAC
41 // exponential function
44 static ex exp_evalf(const ex & x)
50 return exp(ex_to_numeric(x)); // -> numeric exp(numeric)
53 static ex exp_eval(const ex & x)
59 // exp(n*Pi*I/2) -> {+1|+I|-1|-I}
60 ex TwoExOverPiI=(_ex2()*x)/(Pi*I);
61 if (TwoExOverPiI.info(info_flags::integer)) {
62 numeric z=mod(ex_to_numeric(TwoExOverPiI),_num4());
63 if (z.is_equal(_num0()))
65 if (z.is_equal(_num1()))
67 if (z.is_equal(_num2()))
69 if (z.is_equal(_num3()))
73 if (is_ex_the_function(x, log))
77 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
83 static ex exp_deriv(const ex & x, unsigned deriv_param)
85 GINAC_ASSERT(deriv_param==0);
87 // d/dx exp(x) -> exp(x)
91 REGISTER_FUNCTION(exp, eval_func(exp_eval).
92 evalf_func(exp_evalf).
93 derivative_func(exp_deriv));
99 static ex log_evalf(const ex & x)
103 END_TYPECHECK(log(x))
105 return log(ex_to_numeric(x)); // -> numeric log(numeric)
108 static ex log_eval(const ex & x)
110 if (x.info(info_flags::numeric)) {
111 if (x.is_equal(_ex1())) // log(1) -> 0
113 if (x.is_equal(_ex_1())) // log(-1) -> I*Pi
115 if (x.is_equal(I)) // log(I) -> Pi*I/2
116 return (Pi*I*_num1_2());
117 if (x.is_equal(-I)) // log(-I) -> -Pi*I/2
118 return (Pi*I*_num_1_2());
119 if (x.is_equal(_ex0())) // log(0) -> infinity
120 throw(std::domain_error("log_eval(): log(0)"));
122 if (!x.info(info_flags::crational))
125 // log(exp(t)) -> t (if -Pi < t.imag() <= Pi):
126 if (is_ex_the_function(x, exp)) {
128 if (t.info(info_flags::numeric)) {
129 numeric nt = ex_to_numeric(t);
135 return log(x).hold();
138 static ex log_deriv(const ex & x, unsigned deriv_param)
140 GINAC_ASSERT(deriv_param==0);
142 // d/dx log(x) -> 1/x
143 return power(x, _ex_1());
146 REGISTER_FUNCTION(log, eval_func(log_eval).
147 evalf_func(log_evalf).
148 derivative_func(log_deriv));
151 // sine (trigonometric function)
154 static ex sin_evalf(const ex & x)
158 END_TYPECHECK(sin(x))
160 return sin(ex_to_numeric(x)); // -> numeric sin(numeric)
163 static ex sin_eval(const ex & x)
165 // sin(n/d*Pi) -> { all known non-nested radicals }
166 ex SixtyExOverPi = _ex60()*x/Pi;
168 if (SixtyExOverPi.info(info_flags::integer)) {
169 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
171 // wrap to interval [0, Pi)
176 // wrap to interval [0, Pi/2)
179 if (z.is_equal(_num0())) // sin(0) -> 0
181 if (z.is_equal(_num5())) // sin(Pi/12) -> sqrt(6)/4*(1-sqrt(3)/3)
182 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
183 if (z.is_equal(_num6())) // sin(Pi/10) -> sqrt(5)/4-1/4
184 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
185 if (z.is_equal(_num10())) // sin(Pi/6) -> 1/2
186 return sign*_ex1_2();
187 if (z.is_equal(_num15())) // sin(Pi/4) -> sqrt(2)/2
188 return sign*_ex1_2()*power(_ex2(),_ex1_2());
189 if (z.is_equal(_num18())) // sin(3/10*Pi) -> sqrt(5)/4+1/4
190 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
191 if (z.is_equal(_num20())) // sin(Pi/3) -> sqrt(3)/2
192 return sign*_ex1_2()*power(_ex3(),_ex1_2());
193 if (z.is_equal(_num25())) // sin(5/12*Pi) -> sqrt(6)/4*(1+sqrt(3)/3)
194 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
195 if (z.is_equal(_num30())) // sin(Pi/2) -> 1
199 if (is_ex_exactly_of_type(x, function)) {
202 if (is_ex_the_function(x, asin))
204 // sin(acos(x)) -> sqrt(1-x^2)
205 if (is_ex_the_function(x, acos))
206 return power(_ex1()-power(t,_ex2()),_ex1_2());
207 // sin(atan(x)) -> x*(1+x^2)^(-1/2)
208 if (is_ex_the_function(x, atan))
209 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
212 // sin(float) -> float
213 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
216 return sin(x).hold();
219 static ex sin_deriv(const ex & x, unsigned deriv_param)
221 GINAC_ASSERT(deriv_param==0);
223 // d/dx sin(x) -> cos(x)
227 REGISTER_FUNCTION(sin, eval_func(sin_eval).
228 evalf_func(sin_evalf).
229 derivative_func(sin_deriv));
232 // cosine (trigonometric function)
235 static ex cos_evalf(const ex & x)
239 END_TYPECHECK(cos(x))
241 return cos(ex_to_numeric(x)); // -> numeric cos(numeric)
244 static ex cos_eval(const ex & x)
246 // cos(n/d*Pi) -> { all known non-nested radicals }
247 ex SixtyExOverPi = _ex60()*x/Pi;
249 if (SixtyExOverPi.info(info_flags::integer)) {
250 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
252 // wrap to interval [0, Pi)
256 // wrap to interval [0, Pi/2)
260 if (z.is_equal(_num0())) // cos(0) -> 1
262 if (z.is_equal(_num5())) // cos(Pi/12) -> sqrt(6)/4*(1+sqrt(3)/3)
263 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
264 if (z.is_equal(_num10())) // cos(Pi/6) -> sqrt(3)/2
265 return sign*_ex1_2()*power(_ex3(),_ex1_2());
266 if (z.is_equal(_num12())) // cos(Pi/5) -> sqrt(5)/4+1/4
267 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
268 if (z.is_equal(_num15())) // cos(Pi/4) -> sqrt(2)/2
269 return sign*_ex1_2()*power(_ex2(),_ex1_2());
270 if (z.is_equal(_num20())) // cos(Pi/3) -> 1/2
271 return sign*_ex1_2();
272 if (z.is_equal(_num24())) // cos(2/5*Pi) -> sqrt(5)/4-1/4x
273 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
274 if (z.is_equal(_num25())) // cos(5/12*Pi) -> sqrt(6)/4*(1-sqrt(3)/3)
275 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
276 if (z.is_equal(_num30())) // cos(Pi/2) -> 0
280 if (is_ex_exactly_of_type(x, function)) {
283 if (is_ex_the_function(x, acos))
285 // cos(asin(x)) -> (1-x^2)^(1/2)
286 if (is_ex_the_function(x, asin))
287 return power(_ex1()-power(t,_ex2()),_ex1_2());
288 // cos(atan(x)) -> (1+x^2)^(-1/2)
289 if (is_ex_the_function(x, atan))
290 return power(_ex1()+power(t,_ex2()),_ex_1_2());
293 // cos(float) -> float
294 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
297 return cos(x).hold();
300 static ex cos_deriv(const ex & x, unsigned deriv_param)
302 GINAC_ASSERT(deriv_param==0);
304 // d/dx cos(x) -> -sin(x)
305 return _ex_1()*sin(x);
308 REGISTER_FUNCTION(cos, eval_func(cos_eval).
309 evalf_func(cos_evalf).
310 derivative_func(cos_deriv));
313 // tangent (trigonometric function)
316 static ex tan_evalf(const ex & x)
320 END_TYPECHECK(tan(x)) // -> numeric tan(numeric)
322 return tan(ex_to_numeric(x));
325 static ex tan_eval(const ex & x)
327 // tan(n/d*Pi) -> { all known non-nested radicals }
328 ex SixtyExOverPi = _ex60()*x/Pi;
330 if (SixtyExOverPi.info(info_flags::integer)) {
331 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num60());
333 // wrap to interval [0, Pi)
337 // wrap to interval [0, Pi/2)
341 if (z.is_equal(_num0())) // tan(0) -> 0
343 if (z.is_equal(_num5())) // tan(Pi/12) -> 2-sqrt(3)
344 return sign*(_ex2()-power(_ex3(),_ex1_2()));
345 if (z.is_equal(_num10())) // tan(Pi/6) -> sqrt(3)/3
346 return sign*_ex1_3()*power(_ex3(),_ex1_2());
347 if (z.is_equal(_num15())) // tan(Pi/4) -> 1
349 if (z.is_equal(_num20())) // tan(Pi/3) -> sqrt(3)
350 return sign*power(_ex3(),_ex1_2());
351 if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
352 return sign*(power(_ex3(),_ex1_2())+_ex2());
353 if (z.is_equal(_num30())) // tan(Pi/2) -> infinity
354 throw (std::domain_error("tan_eval(): infinity"));
357 if (is_ex_exactly_of_type(x, function)) {
360 if (is_ex_the_function(x, atan))
362 // tan(asin(x)) -> x*(1+x^2)^(-1/2)
363 if (is_ex_the_function(x, asin))
364 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
365 // tan(acos(x)) -> (1-x^2)^(1/2)/x
366 if (is_ex_the_function(x, acos))
367 return power(t,_ex_1())*power(_ex1()-power(t,_ex2()),_ex1_2());
370 // tan(float) -> float
371 if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
375 return tan(x).hold();
378 static ex tan_deriv(const ex & x, unsigned deriv_param)
380 GINAC_ASSERT(deriv_param==0);
382 // d/dx tan(x) -> 1+tan(x)^2;
383 return (_ex1()+power(tan(x),_ex2()));
386 static ex tan_series(const ex & x, const symbol & s, const ex & pt, int order)
389 // Taylor series where there is no pole falls back to tan_deriv.
390 // On a pole simply expand sin(x)/cos(x).
391 const ex x_pt = x.subs(s==pt);
392 if (!(2*x_pt/Pi).info(info_flags::odd))
393 throw do_taylor(); // caught by function::series()
394 // if we got here we have to care for a simple pole
395 return (sin(x)/cos(x)).series(s, pt, order+2);
398 REGISTER_FUNCTION(tan, eval_func(tan_eval).
399 evalf_func(tan_evalf).
400 derivative_func(tan_deriv).
401 series_func(tan_series));
404 // inverse sine (arc sine)
407 static ex asin_evalf(const ex & x)
411 END_TYPECHECK(asin(x))
413 return asin(ex_to_numeric(x)); // -> numeric asin(numeric)
416 static ex asin_eval(const ex & x)
418 if (x.info(info_flags::numeric)) {
423 if (x.is_equal(_ex1_2()))
424 return numeric(1,6)*Pi;
426 if (x.is_equal(_ex1()))
428 // asin(-1/2) -> -Pi/6
429 if (x.is_equal(_ex_1_2()))
430 return numeric(-1,6)*Pi;
432 if (x.is_equal(_ex_1()))
433 return _num_1_2()*Pi;
434 // asin(float) -> float
435 if (!x.info(info_flags::crational))
436 return asin_evalf(x);
439 return asin(x).hold();
442 static ex asin_deriv(const ex & x, unsigned deriv_param)
444 GINAC_ASSERT(deriv_param==0);
446 // d/dx asin(x) -> 1/sqrt(1-x^2)
447 return power(1-power(x,_ex2()),_ex_1_2());
450 REGISTER_FUNCTION(asin, eval_func(asin_eval).
451 evalf_func(asin_evalf).
452 derivative_func(asin_deriv));
455 // inverse cosine (arc cosine)
458 static ex acos_evalf(const ex & x)
462 END_TYPECHECK(acos(x))
464 return acos(ex_to_numeric(x)); // -> numeric acos(numeric)
467 static ex acos_eval(const ex & x)
469 if (x.info(info_flags::numeric)) {
471 if (x.is_equal(_ex1()))
474 if (x.is_equal(_ex1_2()))
479 // acos(-1/2) -> 2/3*Pi
480 if (x.is_equal(_ex_1_2()))
481 return numeric(2,3)*Pi;
483 if (x.is_equal(_ex_1()))
485 // acos(float) -> float
486 if (!x.info(info_flags::crational))
487 return acos_evalf(x);
490 return acos(x).hold();
493 static ex acos_deriv(const ex & x, unsigned deriv_param)
495 GINAC_ASSERT(deriv_param==0);
497 // d/dx acos(x) -> -1/sqrt(1-x^2)
498 return _ex_1()*power(1-power(x,_ex2()),_ex_1_2());
501 REGISTER_FUNCTION(acos, eval_func(acos_eval).
502 evalf_func(acos_evalf).
503 derivative_func(acos_deriv));
506 // inverse tangent (arc tangent)
509 static ex atan_evalf(const ex & x)
513 END_TYPECHECK(atan(x))
515 return atan(ex_to_numeric(x)); // -> numeric atan(numeric)
518 static ex atan_eval(const ex & x)
520 if (x.info(info_flags::numeric)) {
522 if (x.is_equal(_ex0()))
524 // atan(float) -> float
525 if (!x.info(info_flags::crational))
526 return atan_evalf(x);
529 return atan(x).hold();
532 static ex atan_deriv(const ex & x, unsigned deriv_param)
534 GINAC_ASSERT(deriv_param==0);
536 // d/dx atan(x) -> 1/(1+x^2)
537 return power(_ex1()+power(x,_ex2()), _ex_1());
540 REGISTER_FUNCTION(atan, eval_func(atan_eval).
541 evalf_func(atan_evalf).
542 derivative_func(atan_deriv));
545 // inverse tangent (atan2(y,x))
548 static ex atan2_evalf(const ex & y, const ex & x)
553 END_TYPECHECK(atan2(y,x))
555 return atan(ex_to_numeric(y),ex_to_numeric(x)); // -> numeric atan(numeric)
558 static ex atan2_eval(const ex & y, const ex & x)
560 if (y.info(info_flags::numeric) && !y.info(info_flags::crational) &&
561 x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
562 return atan2_evalf(y,x);
565 return atan2(y,x).hold();
568 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
570 GINAC_ASSERT(deriv_param<2);
572 if (deriv_param==0) {
574 return x*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
577 return -y*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
580 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
581 evalf_func(atan2_evalf).
582 derivative_func(atan2_deriv));
585 // hyperbolic sine (trigonometric function)
588 static ex sinh_evalf(const ex & x)
592 END_TYPECHECK(sinh(x))
594 return sinh(ex_to_numeric(x)); // -> numeric sinh(numeric)
597 static ex sinh_eval(const ex & x)
599 if (x.info(info_flags::numeric)) {
600 if (x.is_zero()) // sinh(0) -> 0
602 if (!x.info(info_flags::crational)) // sinh(float) -> float
603 return sinh_evalf(x);
606 if ((x/Pi).info(info_flags::numeric) &&
607 ex_to_numeric(x/Pi).real().is_zero()) // sinh(I*x) -> I*sin(x)
610 if (is_ex_exactly_of_type(x, function)) {
612 // sinh(asinh(x)) -> x
613 if (is_ex_the_function(x, asinh))
615 // sinh(acosh(x)) -> (x-1)^(1/2) * (x+1)^(1/2)
616 if (is_ex_the_function(x, acosh))
617 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2());
618 // sinh(atanh(x)) -> x*(1-x^2)^(-1/2)
619 if (is_ex_the_function(x, atanh))
620 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
623 return sinh(x).hold();
626 static ex sinh_deriv(const ex & x, unsigned deriv_param)
628 GINAC_ASSERT(deriv_param==0);
630 // d/dx sinh(x) -> cosh(x)
634 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
635 evalf_func(sinh_evalf).
636 derivative_func(sinh_deriv));
639 // hyperbolic cosine (trigonometric function)
642 static ex cosh_evalf(const ex & x)
646 END_TYPECHECK(cosh(x))
648 return cosh(ex_to_numeric(x)); // -> numeric cosh(numeric)
651 static ex cosh_eval(const ex & x)
653 if (x.info(info_flags::numeric)) {
654 if (x.is_zero()) // cosh(0) -> 1
656 if (!x.info(info_flags::crational)) // cosh(float) -> float
657 return cosh_evalf(x);
660 if ((x/Pi).info(info_flags::numeric) &&
661 ex_to_numeric(x/Pi).real().is_zero()) // cosh(I*x) -> cos(x)
664 if (is_ex_exactly_of_type(x, function)) {
666 // cosh(acosh(x)) -> x
667 if (is_ex_the_function(x, acosh))
669 // cosh(asinh(x)) -> (1+x^2)^(1/2)
670 if (is_ex_the_function(x, asinh))
671 return power(_ex1()+power(t,_ex2()),_ex1_2());
672 // cosh(atanh(x)) -> (1-x^2)^(-1/2)
673 if (is_ex_the_function(x, atanh))
674 return power(_ex1()-power(t,_ex2()),_ex_1_2());
677 return cosh(x).hold();
680 static ex cosh_deriv(const ex & x, unsigned deriv_param)
682 GINAC_ASSERT(deriv_param==0);
684 // d/dx cosh(x) -> sinh(x)
688 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
689 evalf_func(cosh_evalf).
690 derivative_func(cosh_deriv));
694 // hyperbolic tangent (trigonometric function)
697 static ex tanh_evalf(const ex & x)
701 END_TYPECHECK(tanh(x))
703 return tanh(ex_to_numeric(x)); // -> numeric tanh(numeric)
706 static ex tanh_eval(const ex & x)
708 if (x.info(info_flags::numeric)) {
709 if (x.is_zero()) // tanh(0) -> 0
711 if (!x.info(info_flags::crational)) // tanh(float) -> float
712 return tanh_evalf(x);
715 if ((x/Pi).info(info_flags::numeric) &&
716 ex_to_numeric(x/Pi).real().is_zero()) // tanh(I*x) -> I*tan(x);
719 if (is_ex_exactly_of_type(x, function)) {
721 // tanh(atanh(x)) -> x
722 if (is_ex_the_function(x, atanh))
724 // tanh(asinh(x)) -> x*(1+x^2)^(-1/2)
725 if (is_ex_the_function(x, asinh))
726 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
727 // tanh(acosh(x)) -> (x-1)^(1/2)*(x+1)^(1/2)/x
728 if (is_ex_the_function(x, acosh))
729 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2())*power(t,_ex_1());
732 return tanh(x).hold();
735 static ex tanh_deriv(const ex & x, unsigned deriv_param)
737 GINAC_ASSERT(deriv_param==0);
739 // d/dx tanh(x) -> 1-tanh(x)^2
740 return _ex1()-power(tanh(x),_ex2());
743 static ex tanh_series(const ex & x, const symbol & s, const ex & pt, int order)
746 // Taylor series where there is no pole falls back to tanh_deriv.
747 // On a pole simply expand sinh(x)/cosh(x).
748 const ex x_pt = x.subs(s==pt);
749 if (!(2*I*x_pt/Pi).info(info_flags::odd))
750 throw do_taylor(); // caught by function::series()
751 // if we got here we have to care for a simple pole
752 return (sinh(x)/cosh(x)).series(s, pt, order+2);
755 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
756 evalf_func(tanh_evalf).
757 derivative_func(tanh_deriv).
758 series_func(tanh_series));
761 // inverse hyperbolic sine (trigonometric function)
764 static ex asinh_evalf(const ex & x)
768 END_TYPECHECK(asinh(x))
770 return asinh(ex_to_numeric(x)); // -> numeric asinh(numeric)
773 static ex asinh_eval(const ex & x)
775 if (x.info(info_flags::numeric)) {
779 // asinh(float) -> float
780 if (!x.info(info_flags::crational))
781 return asinh_evalf(x);
784 return asinh(x).hold();
787 static ex asinh_deriv(const ex & x, unsigned deriv_param)
789 GINAC_ASSERT(deriv_param==0);
791 // d/dx asinh(x) -> 1/sqrt(1+x^2)
792 return power(_ex1()+power(x,_ex2()),_ex_1_2());
795 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
796 evalf_func(asinh_evalf).
797 derivative_func(asinh_deriv));
800 // inverse hyperbolic cosine (trigonometric function)
803 static ex acosh_evalf(const ex & x)
807 END_TYPECHECK(acosh(x))
809 return acosh(ex_to_numeric(x)); // -> numeric acosh(numeric)
812 static ex acosh_eval(const ex & x)
814 if (x.info(info_flags::numeric)) {
815 // acosh(0) -> Pi*I/2
817 return Pi*I*numeric(1,2);
819 if (x.is_equal(_ex1()))
822 if (x.is_equal(_ex_1()))
824 // acosh(float) -> float
825 if (!x.info(info_flags::crational))
826 return acosh_evalf(x);
829 return acosh(x).hold();
832 static ex acosh_deriv(const ex & x, unsigned deriv_param)
834 GINAC_ASSERT(deriv_param==0);
836 // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
837 return power(x+_ex_1(),_ex_1_2())*power(x+_ex1(),_ex_1_2());
840 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
841 evalf_func(acosh_evalf).
842 derivative_func(acosh_deriv));
845 // inverse hyperbolic tangent (trigonometric function)
848 static ex atanh_evalf(const ex & x)
852 END_TYPECHECK(atanh(x))
854 return atanh(ex_to_numeric(x)); // -> numeric atanh(numeric)
857 static ex atanh_eval(const ex & x)
859 if (x.info(info_flags::numeric)) {
863 // atanh({+|-}1) -> throw
864 if (x.is_equal(_ex1()) || x.is_equal(_ex1()))
865 throw (std::domain_error("atanh_eval(): infinity"));
866 // atanh(float) -> float
867 if (!x.info(info_flags::crational))
868 return atanh_evalf(x);
871 return atanh(x).hold();
874 static ex atanh_deriv(const ex & x, unsigned deriv_param)
876 GINAC_ASSERT(deriv_param==0);
878 // d/dx atanh(x) -> 1/(1-x^2)
879 return power(_ex1()-power(x,_ex2()),_ex_1());
882 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
883 evalf_func(atanh_evalf).
884 derivative_func(atanh_deriv));
886 #ifndef NO_NAMESPACE_GINAC
888 #endif // ndef NO_NAMESPACE_GINAC