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(pole_error("log_eval(): log(0)",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 &arg,
148 const relational &rel,
152 GINAC_ASSERT(is_ex_exactly_of_type(rel.lhs(),symbol));
154 bool must_expand_arg = false;
155 // maybe substitution of rel into arg fails because of a pole
157 arg_pt = arg.subs(rel);
158 } catch (pole_error) {
159 must_expand_arg = true;
161 // or we are at the branch cut anyways
162 if (arg_pt.is_zero())
163 must_expand_arg = true;
165 if (must_expand_arg) {
167 // This is the branch point: Series expand the argument first, then
168 // trivially factorize it to isolate that part which has constant
169 // leading coefficient in this fashion:
170 // x^n + Order(x^(n+m)) -> x^n * (1 + Order(x^m)).
171 // Return a plain n*log(x) for the x^n part and series expand the
172 // other part. Add them together and reexpand again in order to have
173 // one unnested pseries object. All this also works for negative n.
174 const pseries argser = ex_to_pseries(arg.series(rel, order, branchcut));
175 const symbol *s = static_cast<symbol *>(rel.lhs().bp);
176 const ex point = rel.rhs();
177 const int n = argser.ldegree(*s);
179 seq.push_back(expair(n*log(*s-point), _ex0()));
180 if (!argser.is_terminating() || argser.nops()!=1) {
181 // in this case n more terms are needed
182 ex newarg = ex_to_pseries(arg.series(rel, order+n, branchcut)).shift_exponents(-n).convert_to_poly(true);
183 return pseries(rel, seq).add_series(ex_to_pseries(log(newarg).series(rel, order, branchcut)));
184 } else // it was a monomial
185 return pseries(rel, seq);
187 if (branchcut && arg_pt.info(info_flags::negative)) {
189 // This is the branch cut: assemble the primitive series manually and
190 // then add the corresponding complex step function.
191 const symbol *s = static_cast<symbol *>(rel.lhs().bp);
192 const ex point = rel.rhs();
194 ex replarg = series(log(arg), *s==foo, order, false).subs(foo==point);
196 seq.push_back(expair(-I*csgn(arg*I)*Pi, _ex0()));
197 seq.push_back(expair(Order(_ex1()), order));
198 return series(replarg - I*Pi + pseries(rel, seq), rel, order);
200 throw do_taylor(); // caught by function::series()
203 REGISTER_FUNCTION(log, eval_func(log_eval).
204 evalf_func(log_evalf).
205 derivative_func(log_deriv).
206 series_func(log_series));
209 // sine (trigonometric function)
212 static ex sin_evalf(const ex & x)
216 END_TYPECHECK(sin(x))
218 return sin(ex_to_numeric(x)); // -> numeric sin(numeric)
221 static ex sin_eval(const ex & x)
223 // sin(n/d*Pi) -> { all known non-nested radicals }
224 ex SixtyExOverPi = _ex60()*x/Pi;
226 if (SixtyExOverPi.info(info_flags::integer)) {
227 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
229 // wrap to interval [0, Pi)
234 // wrap to interval [0, Pi/2)
237 if (z.is_equal(_num0())) // sin(0) -> 0
239 if (z.is_equal(_num5())) // sin(Pi/12) -> sqrt(6)/4*(1-sqrt(3)/3)
240 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
241 if (z.is_equal(_num6())) // sin(Pi/10) -> sqrt(5)/4-1/4
242 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
243 if (z.is_equal(_num10())) // sin(Pi/6) -> 1/2
244 return sign*_ex1_2();
245 if (z.is_equal(_num15())) // sin(Pi/4) -> sqrt(2)/2
246 return sign*_ex1_2()*power(_ex2(),_ex1_2());
247 if (z.is_equal(_num18())) // sin(3/10*Pi) -> sqrt(5)/4+1/4
248 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
249 if (z.is_equal(_num20())) // sin(Pi/3) -> sqrt(3)/2
250 return sign*_ex1_2()*power(_ex3(),_ex1_2());
251 if (z.is_equal(_num25())) // sin(5/12*Pi) -> sqrt(6)/4*(1+sqrt(3)/3)
252 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
253 if (z.is_equal(_num30())) // sin(Pi/2) -> 1
257 if (is_ex_exactly_of_type(x, function)) {
260 if (is_ex_the_function(x, asin))
262 // sin(acos(x)) -> sqrt(1-x^2)
263 if (is_ex_the_function(x, acos))
264 return power(_ex1()-power(t,_ex2()),_ex1_2());
265 // sin(atan(x)) -> x*(1+x^2)^(-1/2)
266 if (is_ex_the_function(x, atan))
267 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
270 // sin(float) -> float
271 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
274 return sin(x).hold();
277 static ex sin_deriv(const ex & x, unsigned deriv_param)
279 GINAC_ASSERT(deriv_param==0);
281 // d/dx sin(x) -> cos(x)
285 REGISTER_FUNCTION(sin, eval_func(sin_eval).
286 evalf_func(sin_evalf).
287 derivative_func(sin_deriv));
290 // cosine (trigonometric function)
293 static ex cos_evalf(const ex & x)
297 END_TYPECHECK(cos(x))
299 return cos(ex_to_numeric(x)); // -> numeric cos(numeric)
302 static ex cos_eval(const ex & x)
304 // cos(n/d*Pi) -> { all known non-nested radicals }
305 ex SixtyExOverPi = _ex60()*x/Pi;
307 if (SixtyExOverPi.info(info_flags::integer)) {
308 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num120());
310 // wrap to interval [0, Pi)
314 // wrap to interval [0, Pi/2)
318 if (z.is_equal(_num0())) // cos(0) -> 1
320 if (z.is_equal(_num5())) // cos(Pi/12) -> sqrt(6)/4*(1+sqrt(3)/3)
321 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex1_3()*power(_ex3(),_ex1_2()));
322 if (z.is_equal(_num10())) // cos(Pi/6) -> sqrt(3)/2
323 return sign*_ex1_2()*power(_ex3(),_ex1_2());
324 if (z.is_equal(_num12())) // cos(Pi/5) -> sqrt(5)/4+1/4
325 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex1_4());
326 if (z.is_equal(_num15())) // cos(Pi/4) -> sqrt(2)/2
327 return sign*_ex1_2()*power(_ex2(),_ex1_2());
328 if (z.is_equal(_num20())) // cos(Pi/3) -> 1/2
329 return sign*_ex1_2();
330 if (z.is_equal(_num24())) // cos(2/5*Pi) -> sqrt(5)/4-1/4x
331 return sign*(_ex1_4()*power(_ex5(),_ex1_2())+_ex_1_4());
332 if (z.is_equal(_num25())) // cos(5/12*Pi) -> sqrt(6)/4*(1-sqrt(3)/3)
333 return sign*_ex1_4()*power(_ex6(),_ex1_2())*(_ex1()+_ex_1_3()*power(_ex3(),_ex1_2()));
334 if (z.is_equal(_num30())) // cos(Pi/2) -> 0
338 if (is_ex_exactly_of_type(x, function)) {
341 if (is_ex_the_function(x, acos))
343 // cos(asin(x)) -> (1-x^2)^(1/2)
344 if (is_ex_the_function(x, asin))
345 return power(_ex1()-power(t,_ex2()),_ex1_2());
346 // cos(atan(x)) -> (1+x^2)^(-1/2)
347 if (is_ex_the_function(x, atan))
348 return power(_ex1()+power(t,_ex2()),_ex_1_2());
351 // cos(float) -> float
352 if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
355 return cos(x).hold();
358 static ex cos_deriv(const ex & x, unsigned deriv_param)
360 GINAC_ASSERT(deriv_param==0);
362 // d/dx cos(x) -> -sin(x)
363 return _ex_1()*sin(x);
366 REGISTER_FUNCTION(cos, eval_func(cos_eval).
367 evalf_func(cos_evalf).
368 derivative_func(cos_deriv));
371 // tangent (trigonometric function)
374 static ex tan_evalf(const ex & x)
378 END_TYPECHECK(tan(x)) // -> numeric tan(numeric)
380 return tan(ex_to_numeric(x));
383 static ex tan_eval(const ex & x)
385 // tan(n/d*Pi) -> { all known non-nested radicals }
386 ex SixtyExOverPi = _ex60()*x/Pi;
388 if (SixtyExOverPi.info(info_flags::integer)) {
389 numeric z = mod(ex_to_numeric(SixtyExOverPi),_num60());
391 // wrap to interval [0, Pi)
395 // wrap to interval [0, Pi/2)
399 if (z.is_equal(_num0())) // tan(0) -> 0
401 if (z.is_equal(_num5())) // tan(Pi/12) -> 2-sqrt(3)
402 return sign*(_ex2()-power(_ex3(),_ex1_2()));
403 if (z.is_equal(_num10())) // tan(Pi/6) -> sqrt(3)/3
404 return sign*_ex1_3()*power(_ex3(),_ex1_2());
405 if (z.is_equal(_num15())) // tan(Pi/4) -> 1
407 if (z.is_equal(_num20())) // tan(Pi/3) -> sqrt(3)
408 return sign*power(_ex3(),_ex1_2());
409 if (z.is_equal(_num25())) // tan(5/12*Pi) -> 2+sqrt(3)
410 return sign*(power(_ex3(),_ex1_2())+_ex2());
411 if (z.is_equal(_num30())) // tan(Pi/2) -> infinity
412 throw (pole_error("tan_eval(): simple pole",1));
415 if (is_ex_exactly_of_type(x, function)) {
418 if (is_ex_the_function(x, atan))
420 // tan(asin(x)) -> x*(1+x^2)^(-1/2)
421 if (is_ex_the_function(x, asin))
422 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
423 // tan(acos(x)) -> (1-x^2)^(1/2)/x
424 if (is_ex_the_function(x, acos))
425 return power(t,_ex_1())*power(_ex1()-power(t,_ex2()),_ex1_2());
428 // tan(float) -> float
429 if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
433 return tan(x).hold();
436 static ex tan_deriv(const ex & x, unsigned deriv_param)
438 GINAC_ASSERT(deriv_param==0);
440 // d/dx tan(x) -> 1+tan(x)^2;
441 return (_ex1()+power(tan(x),_ex2()));
444 static ex tan_series(const ex &x,
445 const relational &rel,
450 // Taylor series where there is no pole falls back to tan_deriv.
451 // On a pole simply expand sin(x)/cos(x).
452 const ex x_pt = x.subs(rel);
453 if (!(2*x_pt/Pi).info(info_flags::odd))
454 throw do_taylor(); // caught by function::series()
455 // if we got here we have to care for a simple pole
456 return (sin(x)/cos(x)).series(rel, order+2);
459 REGISTER_FUNCTION(tan, eval_func(tan_eval).
460 evalf_func(tan_evalf).
461 derivative_func(tan_deriv).
462 series_func(tan_series));
465 // inverse sine (arc sine)
468 static ex asin_evalf(const ex & x)
472 END_TYPECHECK(asin(x))
474 return asin(ex_to_numeric(x)); // -> numeric asin(numeric)
477 static ex asin_eval(const ex & x)
479 if (x.info(info_flags::numeric)) {
484 if (x.is_equal(_ex1_2()))
485 return numeric(1,6)*Pi;
487 if (x.is_equal(_ex1()))
489 // asin(-1/2) -> -Pi/6
490 if (x.is_equal(_ex_1_2()))
491 return numeric(-1,6)*Pi;
493 if (x.is_equal(_ex_1()))
494 return _num_1_2()*Pi;
495 // asin(float) -> float
496 if (!x.info(info_flags::crational))
497 return asin_evalf(x);
500 return asin(x).hold();
503 static ex asin_deriv(const ex & x, unsigned deriv_param)
505 GINAC_ASSERT(deriv_param==0);
507 // d/dx asin(x) -> 1/sqrt(1-x^2)
508 return power(1-power(x,_ex2()),_ex_1_2());
511 REGISTER_FUNCTION(asin, eval_func(asin_eval).
512 evalf_func(asin_evalf).
513 derivative_func(asin_deriv));
516 // inverse cosine (arc cosine)
519 static ex acos_evalf(const ex & x)
523 END_TYPECHECK(acos(x))
525 return acos(ex_to_numeric(x)); // -> numeric acos(numeric)
528 static ex acos_eval(const ex & x)
530 if (x.info(info_flags::numeric)) {
532 if (x.is_equal(_ex1()))
535 if (x.is_equal(_ex1_2()))
540 // acos(-1/2) -> 2/3*Pi
541 if (x.is_equal(_ex_1_2()))
542 return numeric(2,3)*Pi;
544 if (x.is_equal(_ex_1()))
546 // acos(float) -> float
547 if (!x.info(info_flags::crational))
548 return acos_evalf(x);
551 return acos(x).hold();
554 static ex acos_deriv(const ex & x, unsigned deriv_param)
556 GINAC_ASSERT(deriv_param==0);
558 // d/dx acos(x) -> -1/sqrt(1-x^2)
559 return _ex_1()*power(1-power(x,_ex2()),_ex_1_2());
562 REGISTER_FUNCTION(acos, eval_func(acos_eval).
563 evalf_func(acos_evalf).
564 derivative_func(acos_deriv));
567 // inverse tangent (arc tangent)
570 static ex atan_evalf(const ex & x)
574 END_TYPECHECK(atan(x))
576 return atan(ex_to_numeric(x)); // -> numeric atan(numeric)
579 static ex atan_eval(const ex & x)
581 if (x.info(info_flags::numeric)) {
583 if (x.is_equal(_ex0()))
585 // atan(float) -> float
586 if (!x.info(info_flags::crational))
587 return atan_evalf(x);
590 return atan(x).hold();
593 static ex atan_deriv(const ex & x, unsigned deriv_param)
595 GINAC_ASSERT(deriv_param==0);
597 // d/dx atan(x) -> 1/(1+x^2)
598 return power(_ex1()+power(x,_ex2()), _ex_1());
601 REGISTER_FUNCTION(atan, eval_func(atan_eval).
602 evalf_func(atan_evalf).
603 derivative_func(atan_deriv));
606 // inverse tangent (atan2(y,x))
609 static ex atan2_evalf(const ex & y, const ex & x)
614 END_TYPECHECK(atan2(y,x))
616 return atan(ex_to_numeric(y),ex_to_numeric(x)); // -> numeric atan(numeric)
619 static ex atan2_eval(const ex & y, const ex & x)
621 if (y.info(info_flags::numeric) && !y.info(info_flags::crational) &&
622 x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
623 return atan2_evalf(y,x);
626 return atan2(y,x).hold();
629 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
631 GINAC_ASSERT(deriv_param<2);
633 if (deriv_param==0) {
635 return x*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
638 return -y*power(power(x,_ex2())+power(y,_ex2()),_ex_1());
641 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
642 evalf_func(atan2_evalf).
643 derivative_func(atan2_deriv));
646 // hyperbolic sine (trigonometric function)
649 static ex sinh_evalf(const ex & x)
653 END_TYPECHECK(sinh(x))
655 return sinh(ex_to_numeric(x)); // -> numeric sinh(numeric)
658 static ex sinh_eval(const ex & x)
660 if (x.info(info_flags::numeric)) {
661 if (x.is_zero()) // sinh(0) -> 0
663 if (!x.info(info_flags::crational)) // sinh(float) -> float
664 return sinh_evalf(x);
667 if ((x/Pi).info(info_flags::numeric) &&
668 ex_to_numeric(x/Pi).real().is_zero()) // sinh(I*x) -> I*sin(x)
671 if (is_ex_exactly_of_type(x, function)) {
673 // sinh(asinh(x)) -> x
674 if (is_ex_the_function(x, asinh))
676 // sinh(acosh(x)) -> (x-1)^(1/2) * (x+1)^(1/2)
677 if (is_ex_the_function(x, acosh))
678 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2());
679 // sinh(atanh(x)) -> x*(1-x^2)^(-1/2)
680 if (is_ex_the_function(x, atanh))
681 return t*power(_ex1()-power(t,_ex2()),_ex_1_2());
684 return sinh(x).hold();
687 static ex sinh_deriv(const ex & x, unsigned deriv_param)
689 GINAC_ASSERT(deriv_param==0);
691 // d/dx sinh(x) -> cosh(x)
695 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
696 evalf_func(sinh_evalf).
697 derivative_func(sinh_deriv));
700 // hyperbolic cosine (trigonometric function)
703 static ex cosh_evalf(const ex & x)
707 END_TYPECHECK(cosh(x))
709 return cosh(ex_to_numeric(x)); // -> numeric cosh(numeric)
712 static ex cosh_eval(const ex & x)
714 if (x.info(info_flags::numeric)) {
715 if (x.is_zero()) // cosh(0) -> 1
717 if (!x.info(info_flags::crational)) // cosh(float) -> float
718 return cosh_evalf(x);
721 if ((x/Pi).info(info_flags::numeric) &&
722 ex_to_numeric(x/Pi).real().is_zero()) // cosh(I*x) -> cos(x)
725 if (is_ex_exactly_of_type(x, function)) {
727 // cosh(acosh(x)) -> x
728 if (is_ex_the_function(x, acosh))
730 // cosh(asinh(x)) -> (1+x^2)^(1/2)
731 if (is_ex_the_function(x, asinh))
732 return power(_ex1()+power(t,_ex2()),_ex1_2());
733 // cosh(atanh(x)) -> (1-x^2)^(-1/2)
734 if (is_ex_the_function(x, atanh))
735 return power(_ex1()-power(t,_ex2()),_ex_1_2());
738 return cosh(x).hold();
741 static ex cosh_deriv(const ex & x, unsigned deriv_param)
743 GINAC_ASSERT(deriv_param==0);
745 // d/dx cosh(x) -> sinh(x)
749 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
750 evalf_func(cosh_evalf).
751 derivative_func(cosh_deriv));
755 // hyperbolic tangent (trigonometric function)
758 static ex tanh_evalf(const ex & x)
762 END_TYPECHECK(tanh(x))
764 return tanh(ex_to_numeric(x)); // -> numeric tanh(numeric)
767 static ex tanh_eval(const ex & x)
769 if (x.info(info_flags::numeric)) {
770 if (x.is_zero()) // tanh(0) -> 0
772 if (!x.info(info_flags::crational)) // tanh(float) -> float
773 return tanh_evalf(x);
776 if ((x/Pi).info(info_flags::numeric) &&
777 ex_to_numeric(x/Pi).real().is_zero()) // tanh(I*x) -> I*tan(x);
780 if (is_ex_exactly_of_type(x, function)) {
782 // tanh(atanh(x)) -> x
783 if (is_ex_the_function(x, atanh))
785 // tanh(asinh(x)) -> x*(1+x^2)^(-1/2)
786 if (is_ex_the_function(x, asinh))
787 return t*power(_ex1()+power(t,_ex2()),_ex_1_2());
788 // tanh(acosh(x)) -> (x-1)^(1/2)*(x+1)^(1/2)/x
789 if (is_ex_the_function(x, acosh))
790 return power(t-_ex1(),_ex1_2())*power(t+_ex1(),_ex1_2())*power(t,_ex_1());
793 return tanh(x).hold();
796 static ex tanh_deriv(const ex & x, unsigned deriv_param)
798 GINAC_ASSERT(deriv_param==0);
800 // d/dx tanh(x) -> 1-tanh(x)^2
801 return _ex1()-power(tanh(x),_ex2());
804 static ex tanh_series(const ex &x,
805 const relational &rel,
810 // Taylor series where there is no pole falls back to tanh_deriv.
811 // On a pole simply expand sinh(x)/cosh(x).
812 const ex x_pt = x.subs(rel);
813 if (!(2*I*x_pt/Pi).info(info_flags::odd))
814 throw do_taylor(); // caught by function::series()
815 // if we got here we have to care for a simple pole
816 return (sinh(x)/cosh(x)).series(rel, order+2);
819 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
820 evalf_func(tanh_evalf).
821 derivative_func(tanh_deriv).
822 series_func(tanh_series));
825 // inverse hyperbolic sine (trigonometric function)
828 static ex asinh_evalf(const ex & x)
832 END_TYPECHECK(asinh(x))
834 return asinh(ex_to_numeric(x)); // -> numeric asinh(numeric)
837 static ex asinh_eval(const ex & x)
839 if (x.info(info_flags::numeric)) {
843 // asinh(float) -> float
844 if (!x.info(info_flags::crational))
845 return asinh_evalf(x);
848 return asinh(x).hold();
851 static ex asinh_deriv(const ex & x, unsigned deriv_param)
853 GINAC_ASSERT(deriv_param==0);
855 // d/dx asinh(x) -> 1/sqrt(1+x^2)
856 return power(_ex1()+power(x,_ex2()),_ex_1_2());
859 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
860 evalf_func(asinh_evalf).
861 derivative_func(asinh_deriv));
864 // inverse hyperbolic cosine (trigonometric function)
867 static ex acosh_evalf(const ex & x)
871 END_TYPECHECK(acosh(x))
873 return acosh(ex_to_numeric(x)); // -> numeric acosh(numeric)
876 static ex acosh_eval(const ex & x)
878 if (x.info(info_flags::numeric)) {
879 // acosh(0) -> Pi*I/2
881 return Pi*I*numeric(1,2);
883 if (x.is_equal(_ex1()))
886 if (x.is_equal(_ex_1()))
888 // acosh(float) -> float
889 if (!x.info(info_flags::crational))
890 return acosh_evalf(x);
893 return acosh(x).hold();
896 static ex acosh_deriv(const ex & x, unsigned deriv_param)
898 GINAC_ASSERT(deriv_param==0);
900 // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
901 return power(x+_ex_1(),_ex_1_2())*power(x+_ex1(),_ex_1_2());
904 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
905 evalf_func(acosh_evalf).
906 derivative_func(acosh_deriv));
909 // inverse hyperbolic tangent (trigonometric function)
912 static ex atanh_evalf(const ex & x)
916 END_TYPECHECK(atanh(x))
918 return atanh(ex_to_numeric(x)); // -> numeric atanh(numeric)
921 static ex atanh_eval(const ex & x)
923 if (x.info(info_flags::numeric)) {
927 // atanh({+|-}1) -> throw
928 if (x.is_equal(_ex1()) || x.is_equal(_ex_1()))
929 throw (pole_error("atanh_eval(): logarithmic pole",0));
930 // atanh(float) -> float
931 if (!x.info(info_flags::crational))
932 return atanh_evalf(x);
935 return atanh(x).hold();
938 static ex atanh_deriv(const ex & x, unsigned deriv_param)
940 GINAC_ASSERT(deriv_param==0);
942 // d/dx atanh(x) -> 1/(1-x^2)
943 return power(_ex1()-power(x,_ex2()),_ex_1());
946 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
947 evalf_func(atanh_evalf).
948 derivative_func(atanh_deriv));
950 #ifndef NO_NAMESPACE_GINAC
952 #endif // ndef NO_NAMESPACE_GINAC