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(_ex0())) // log(0) -> infinity
113 throw(std::domain_error("log_eval(): log(0)"));
114 if (x.info(info_flags::real) && x.info(info_flags::negative))
115 return (log(-x)+I*Pi);
116 if (x.is_equal(_ex1())) // log(1) -> 0
118 if (x.is_equal(I)) // log(I) -> Pi*I/2
119 return (Pi*I*_num1_2());
120 if (x.is_equal(-I)) // log(-I) -> -Pi*I/2
121 return (Pi*I*_num_1_2());
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);
157 } // on the branch cut:
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 seq.push_back(expair(-I*csgn(x*I)*Pi,_ex0()));
165 seq.push_back(expair(Order(_ex1()),order));
166 return series(replx - I*Pi + pseries(rel, seq),rel,order);
169 REGISTER_FUNCTION(log, eval_func(log_eval).
170 evalf_func(log_evalf).
171 derivative_func(log_deriv).
172 series_func(log_series));
175 // sine (trigonometric function)
178 static ex sin_evalf(const ex & x)
182 END_TYPECHECK(sin(x))
184 return sin(ex_to_numeric(x)); // -> numeric sin(numeric)
187 static ex sin_eval(const ex & x)
189 // sin(n/d*Pi) -> { all known non-nested radicals }
190 ex SixtyExOverPi = _ex60()*x/Pi;
192 if (SixtyExOverPi.info(info_flags::integer)) {
193 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
195 // wrap to interval [0, Pi)
200 // wrap to interval [0, Pi/2)
203 if (z.is_equal(_num0())) // sin(0) -> 0
205 if (z.is_equal(_num5())) // sin(Pi/12) -> sqrt(6)/4*(1-sqrt(3)/3)
206 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
207 if (z.is_equal(_num6())) // sin(Pi/10) -> sqrt(5)/4-1/4
208 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
209 if (z.is_equal(_num10())) // sin(Pi/6) -> 1/2
210 return sign*_ex1_2();
211 if (z.is_equal(_num15())) // sin(Pi/4) -> sqrt(2)/2
212 return sign*_ex1_2()*power(_ex2(),_ex1_2());
213 if (z.is_equal(_num18())) // sin(3/10*Pi) -> sqrt(5)/4+1/4
214 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
215 if (z.is_equal(_num20())) // sin(Pi/3) -> sqrt(3)/2
216 return sign*_ex1_2()*power(_ex3(),_ex1_2());
217 if (z.is_equal(_num25())) // sin(5/12*Pi) -> sqrt(6)/4*(1+sqrt(3)/3)
218 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
219 if (z.is_equal(_num30())) // sin(Pi/2) -> 1
223 if (is_ex_exactly_of_type(x, function)) {
226 if (is_ex_the_function(x, asin))
228 // sin(acos(x)) -> sqrt(1-x^2)
229 if (is_ex_the_function(x, acos))
230 return power(_ex1()-power(t,_ex2()),_ex1_2());
231 // sin(atan(x)) -> x*(1+x^2)^(-1/2)
232 if (is_ex_the_function(x, atan))
233 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
236 // sin(float) -> float
237 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
240 return sin(x).hold();
243 static ex sin_deriv(const ex & x, unsigned deriv_param)
245 GINAC_ASSERT(deriv_param==0);
247 // d/dx sin(x) -> cos(x)
251 REGISTER_FUNCTION(sin, eval_func(sin_eval).
252 evalf_func(sin_evalf).
253 derivative_func(sin_deriv));
256 // cosine (trigonometric function)
259 static ex cos_evalf(const ex & x)
263 END_TYPECHECK(cos(x))
265 return cos(ex_to_numeric(x)); // -> numeric cos(numeric)
268 static ex cos_eval(const ex & x)
270 // cos(n/d*Pi) -> { all known non-nested radicals }
271 ex SixtyExOverPi = _ex60()*x/Pi;
273 if (SixtyExOverPi.info(info_flags::integer)) {
274 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
276 // wrap to interval [0, Pi)
280 // wrap to interval [0, Pi/2)
284 if (z.is_equal(_num0())) // cos(0) -> 1
286 if (z.is_equal(_num5())) // cos(Pi/12) -> sqrt(6)/4*(1+sqrt(3)/3)
287 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
288 if (z.is_equal(_num10())) // cos(Pi/6) -> sqrt(3)/2
289 return sign*_ex1_2()*power(_ex3(),_ex1_2());
290 if (z.is_equal(_num12())) // cos(Pi/5) -> sqrt(5)/4+1/4
291 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
292 if (z.is_equal(_num15())) // cos(Pi/4) -> sqrt(2)/2
293 return sign*_ex1_2()*power(_ex2(),_ex1_2());
294 if (z.is_equal(_num20())) // cos(Pi/3) -> 1/2
295 return sign*_ex1_2();
296 if (z.is_equal(_num24())) // cos(2/5*Pi) -> sqrt(5)/4-1/4x
297 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
298 if (z.is_equal(_num25())) // cos(5/12*Pi) -> sqrt(6)/4*(1-sqrt(3)/3)
299 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
300 if (z.is_equal(_num30())) // cos(Pi/2) -> 0
304 if (is_ex_exactly_of_type(x, function)) {
307 if (is_ex_the_function(x, acos))
309 // cos(asin(x)) -> (1-x^2)^(1/2)
310 if (is_ex_the_function(x, asin))
311 return power(_ex1()-power(t,_ex2()),_ex1_2());
312 // cos(atan(x)) -> (1+x^2)^(-1/2)
313 if (is_ex_the_function(x, atan))
314 return power(_ex1()+power(t,_ex2()),_ex_1_2());
317 // cos(float) -> float
318 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
321 return cos(x).hold();
324 static ex cos_deriv(const ex & x, unsigned deriv_param)
326 GINAC_ASSERT(deriv_param==0);
328 // d/dx cos(x) -> -sin(x)
329 return _ex_1()*sin(x);
332 REGISTER_FUNCTION(cos, eval_func(cos_eval).
333 evalf_func(cos_evalf).
334 derivative_func(cos_deriv));
337 // tangent (trigonometric function)
340 static ex tan_evalf(const ex & x)
344 END_TYPECHECK(tan(x)) // -> numeric tan(numeric)
346 return tan(ex_to_numeric(x));
349 static ex tan_eval(const ex & x)
351 // tan(n/d*Pi) -> { all known non-nested radicals }
352 ex SixtyExOverPi = _ex60()*x/Pi;
354 if (SixtyExOverPi.info(info_flags::integer)) {
355 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num60());
357 // wrap to interval [0, Pi)
361 // wrap to interval [0, Pi/2)
365 if (z.is_equal(_num0())) // tan(0) -> 0
367 if (z.is_equal(_num5())) // tan(Pi/12) -> 2-sqrt(3)
368 return sign*(_ex2()-power(_ex3(),_ex1_2()));
369 if (z.is_equal(_num10())) // tan(Pi/6) -> sqrt(3)/3
370 return sign*_ex1_3()*power(_ex3(),_ex1_2());
371 if (z.is_equal(_num15())) // tan(Pi/4) -> 1
373 if (z.is_equal(_num20())) // tan(Pi/3) -> sqrt(3)
374 return sign*power(_ex3(),_ex1_2());
375 if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
376 return sign*(power(_ex3(),_ex1_2())+_ex2());
377 if (z.is_equal(_num30())) // tan(Pi/2) -> infinity
378 throw (std::domain_error("tan_eval(): simple pole"));
381 if (is_ex_exactly_of_type(x, function)) {
384 if (is_ex_the_function(x, atan))
386 // tan(asin(x)) -> x*(1+x^2)^(-1/2)
387 if (is_ex_the_function(x, asin))
388 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
389 // tan(acos(x)) -> (1-x^2)^(1/2)/x
390 if (is_ex_the_function(x, acos))
391 return power(t,_ex_1())*power(_ex1()-power(t,_ex2()),_ex1_2());
394 // tan(float) -> float
395 if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
399 return tan(x).hold();
402 static ex tan_deriv(const ex & x, unsigned deriv_param)
404 GINAC_ASSERT(deriv_param==0);
406 // d/dx tan(x) -> 1+tan(x)^2;
407 return (_ex1()+power(tan(x),_ex2()));
410 static ex tan_series(const ex &x, const relational &rel, int order)
413 // Taylor series where there is no pole falls back to tan_deriv.
414 // On a pole simply expand sin(x)/cos(x).
415 const ex x_pt = x.subs(rel);
416 if (!(2*x_pt/Pi).info(info_flags::odd))
417 throw do_taylor(); // caught by function::series()
418 // if we got here we have to care for a simple pole
419 return (sin(x)/cos(x)).series(rel, order+2);
422 REGISTER_FUNCTION(tan, eval_func(tan_eval).
423 evalf_func(tan_evalf).
424 derivative_func(tan_deriv).
425 series_func(tan_series));
428 // inverse sine (arc sine)
431 static ex asin_evalf(const ex & x)
435 END_TYPECHECK(asin(x))
437 return asin(ex_to_numeric(x)); // -> numeric asin(numeric)
440 static ex asin_eval(const ex & x)
442 if (x.info(info_flags::numeric)) {
447 if (x.is_equal(_ex1_2()))
448 return numeric(1,6)*Pi;
450 if (x.is_equal(_ex1()))
452 // asin(-1/2) -> -Pi/6
453 if (x.is_equal(_ex_1_2()))
454 return numeric(-1,6)*Pi;
456 if (x.is_equal(_ex_1()))
457 return _num_1_2()*Pi;
458 // asin(float) -> float
459 if (!x.info(info_flags::crational))
460 return asin_evalf(x);
463 return asin(x).hold();
466 static ex asin_deriv(const ex & x, unsigned deriv_param)
468 GINAC_ASSERT(deriv_param==0);
470 // d/dx asin(x) -> 1/sqrt(1-x^2)
471 return power(1-power(x,_ex2()),_ex_1_2());
474 REGISTER_FUNCTION(asin, eval_func(asin_eval).
475 evalf_func(asin_evalf).
476 derivative_func(asin_deriv));
479 // inverse cosine (arc cosine)
482 static ex acos_evalf(const ex & x)
486 END_TYPECHECK(acos(x))
488 return acos(ex_to_numeric(x)); // -> numeric acos(numeric)
491 static ex acos_eval(const ex & x)
493 if (x.info(info_flags::numeric)) {
495 if (x.is_equal(_ex1()))
498 if (x.is_equal(_ex1_2()))
503 // acos(-1/2) -> 2/3*Pi
504 if (x.is_equal(_ex_1_2()))
505 return numeric(2,3)*Pi;
507 if (x.is_equal(_ex_1()))
509 // acos(float) -> float
510 if (!x.info(info_flags::crational))
511 return acos_evalf(x);
514 return acos(x).hold();
517 static ex acos_deriv(const ex & x, unsigned deriv_param)
519 GINAC_ASSERT(deriv_param==0);
521 // d/dx acos(x) -> -1/sqrt(1-x^2)
522 return _ex_1()*power(1-power(x,_ex2()),_ex_1_2());
525 REGISTER_FUNCTION(acos, eval_func(acos_eval).
526 evalf_func(acos_evalf).
527 derivative_func(acos_deriv));
530 // inverse tangent (arc tangent)
533 static ex atan_evalf(const ex & x)
537 END_TYPECHECK(atan(x))
539 return atan(ex_to_numeric(x)); // -> numeric atan(numeric)
542 static ex atan_eval(const ex & x)
544 if (x.info(info_flags::numeric)) {
546 if (x.is_equal(_ex0()))
548 // atan(float) -> float
549 if (!x.info(info_flags::crational))
550 return atan_evalf(x);
553 return atan(x).hold();
556 static ex atan_deriv(const ex & x, unsigned deriv_param)
558 GINAC_ASSERT(deriv_param==0);
560 // d/dx atan(x) -> 1/(1+x^2)
561 return power(_ex1()+power(x,_ex2()), _ex_1());
564 REGISTER_FUNCTION(atan, eval_func(atan_eval).
565 evalf_func(atan_evalf).
566 derivative_func(atan_deriv));
569 // inverse tangent (atan2(y,x))
572 static ex atan2_evalf(const ex & y, const ex & x)
577 END_TYPECHECK(atan2(y,x))
579 return atan(ex_to_numeric(y),ex_to_numeric(x)); // -> numeric atan(numeric)
582 static ex atan2_eval(const ex & y, const ex & x)
584 if (y.info(info_flags::numeric) && !y.info(info_flags::crational) &&
585 x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
586 return atan2_evalf(y,x);
589 return atan2(y,x).hold();
592 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
594 GINAC_ASSERT(deriv_param<2);
596 if (deriv_param==0) {
598 return x*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
601 return -y*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
604 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
605 evalf_func(atan2_evalf).
606 derivative_func(atan2_deriv));
609 // hyperbolic sine (trigonometric function)
612 static ex sinh_evalf(const ex & x)
616 END_TYPECHECK(sinh(x))
618 return sinh(ex_to_numeric(x)); // -> numeric sinh(numeric)
621 static ex sinh_eval(const ex & x)
623 if (x.info(info_flags::numeric)) {
624 if (x.is_zero()) // sinh(0) -> 0
626 if (!x.info(info_flags::crational)) // sinh(float) -> float
627 return sinh_evalf(x);
630 if ((x/Pi).info(info_flags::numeric) &&
631 ex_to_numeric(x/Pi).real().is_zero()) // sinh(I*x) -> I*sin(x)
634 if (is_ex_exactly_of_type(x, function)) {
636 // sinh(asinh(x)) -> x
637 if (is_ex_the_function(x, asinh))
639 // sinh(acosh(x)) -> (x-1)^(1/2) * (x+1)^(1/2)
640 if (is_ex_the_function(x, acosh))
641 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2());
642 // sinh(atanh(x)) -> x*(1-x^2)^(-1/2)
643 if (is_ex_the_function(x, atanh))
644 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
647 return sinh(x).hold();
650 static ex sinh_deriv(const ex & x, unsigned deriv_param)
652 GINAC_ASSERT(deriv_param==0);
654 // d/dx sinh(x) -> cosh(x)
658 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
659 evalf_func(sinh_evalf).
660 derivative_func(sinh_deriv));
663 // hyperbolic cosine (trigonometric function)
666 static ex cosh_evalf(const ex & x)
670 END_TYPECHECK(cosh(x))
672 return cosh(ex_to_numeric(x)); // -> numeric cosh(numeric)
675 static ex cosh_eval(const ex & x)
677 if (x.info(info_flags::numeric)) {
678 if (x.is_zero()) // cosh(0) -> 1
680 if (!x.info(info_flags::crational)) // cosh(float) -> float
681 return cosh_evalf(x);
684 if ((x/Pi).info(info_flags::numeric) &&
685 ex_to_numeric(x/Pi).real().is_zero()) // cosh(I*x) -> cos(x)
688 if (is_ex_exactly_of_type(x, function)) {
690 // cosh(acosh(x)) -> x
691 if (is_ex_the_function(x, acosh))
693 // cosh(asinh(x)) -> (1+x^2)^(1/2)
694 if (is_ex_the_function(x, asinh))
695 return power(_ex1()+power(t,_ex2()),_ex1_2());
696 // cosh(atanh(x)) -> (1-x^2)^(-1/2)
697 if (is_ex_the_function(x, atanh))
698 return power(_ex1()-power(t,_ex2()),_ex_1_2());
701 return cosh(x).hold();
704 static ex cosh_deriv(const ex & x, unsigned deriv_param)
706 GINAC_ASSERT(deriv_param==0);
708 // d/dx cosh(x) -> sinh(x)
712 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
713 evalf_func(cosh_evalf).
714 derivative_func(cosh_deriv));
718 // hyperbolic tangent (trigonometric function)
721 static ex tanh_evalf(const ex & x)
725 END_TYPECHECK(tanh(x))
727 return tanh(ex_to_numeric(x)); // -> numeric tanh(numeric)
730 static ex tanh_eval(const ex & x)
732 if (x.info(info_flags::numeric)) {
733 if (x.is_zero()) // tanh(0) -> 0
735 if (!x.info(info_flags::crational)) // tanh(float) -> float
736 return tanh_evalf(x);
739 if ((x/Pi).info(info_flags::numeric) &&
740 ex_to_numeric(x/Pi).real().is_zero()) // tanh(I*x) -> I*tan(x);
743 if (is_ex_exactly_of_type(x, function)) {
745 // tanh(atanh(x)) -> x
746 if (is_ex_the_function(x, atanh))
748 // tanh(asinh(x)) -> x*(1+x^2)^(-1/2)
749 if (is_ex_the_function(x, asinh))
750 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
751 // tanh(acosh(x)) -> (x-1)^(1/2)*(x+1)^(1/2)/x
752 if (is_ex_the_function(x, acosh))
753 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2())*power(t,_ex_1());
756 return tanh(x).hold();
759 static ex tanh_deriv(const ex & x, unsigned deriv_param)
761 GINAC_ASSERT(deriv_param==0);
763 // d/dx tanh(x) -> 1-tanh(x)^2
764 return _ex1()-power(tanh(x),_ex2());
767 static ex tanh_series(const ex &x, const relational &rel, int order)
770 // Taylor series where there is no pole falls back to tanh_deriv.
771 // On a pole simply expand sinh(x)/cosh(x).
772 const ex x_pt = x.subs(rel);
773 if (!(2*I*x_pt/Pi).info(info_flags::odd))
774 throw do_taylor(); // caught by function::series()
775 // if we got here we have to care for a simple pole
776 return (sinh(x)/cosh(x)).series(rel, order+2);
779 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
780 evalf_func(tanh_evalf).
781 derivative_func(tanh_deriv).
782 series_func(tanh_series));
785 // inverse hyperbolic sine (trigonometric function)
788 static ex asinh_evalf(const ex & x)
792 END_TYPECHECK(asinh(x))
794 return asinh(ex_to_numeric(x)); // -> numeric asinh(numeric)
797 static ex asinh_eval(const ex & x)
799 if (x.info(info_flags::numeric)) {
803 // asinh(float) -> float
804 if (!x.info(info_flags::crational))
805 return asinh_evalf(x);
808 return asinh(x).hold();
811 static ex asinh_deriv(const ex & x, unsigned deriv_param)
813 GINAC_ASSERT(deriv_param==0);
815 // d/dx asinh(x) -> 1/sqrt(1+x^2)
816 return power(_ex1()+power(x,_ex2()),_ex_1_2());
819 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
820 evalf_func(asinh_evalf).
821 derivative_func(asinh_deriv));
824 // inverse hyperbolic cosine (trigonometric function)
827 static ex acosh_evalf(const ex & x)
831 END_TYPECHECK(acosh(x))
833 return acosh(ex_to_numeric(x)); // -> numeric acosh(numeric)
836 static ex acosh_eval(const ex & x)
838 if (x.info(info_flags::numeric)) {
839 // acosh(0) -> Pi*I/2
841 return Pi*I*numeric(1,2);
843 if (x.is_equal(_ex1()))
846 if (x.is_equal(_ex_1()))
848 // acosh(float) -> float
849 if (!x.info(info_flags::crational))
850 return acosh_evalf(x);
853 return acosh(x).hold();
856 static ex acosh_deriv(const ex & x, unsigned deriv_param)
858 GINAC_ASSERT(deriv_param==0);
860 // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
861 return power(x+_ex_1(),_ex_1_2())*power(x+_ex1(),_ex_1_2());
864 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
865 evalf_func(acosh_evalf).
866 derivative_func(acosh_deriv));
869 // inverse hyperbolic tangent (trigonometric function)
872 static ex atanh_evalf(const ex & x)
876 END_TYPECHECK(atanh(x))
878 return atanh(ex_to_numeric(x)); // -> numeric atanh(numeric)
881 static ex atanh_eval(const ex & x)
883 if (x.info(info_flags::numeric)) {
887 // atanh({+|-}1) -> throw
888 if (x.is_equal(_ex1()) || x.is_equal(_ex_1()))
889 throw (std::domain_error("atanh_eval(): logarithmic pole"));
890 // atanh(float) -> float
891 if (!x.info(info_flags::crational))
892 return atanh_evalf(x);
895 return atanh(x).hold();
898 static ex atanh_deriv(const ex & x, unsigned deriv_param)
900 GINAC_ASSERT(deriv_param==0);
902 // d/dx atanh(x) -> 1/(1-x^2)
903 return power(_ex1()-power(x,_ex2()),_ex_1());
906 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
907 evalf_func(atanh_evalf).
908 derivative_func(atanh_deriv));
910 #ifndef NO_NAMESPACE_GINAC
912 #endif // ndef NO_NAMESPACE_GINAC