]> www.ginac.de Git - ginac.git/blob - ginac/inifcns_trans.cpp
configure: run important checks first (and bail out if something is missing).
[ginac.git] / ginac / inifcns_trans.cpp
1 /** @file inifcns_trans.cpp
2  *
3  *  Implementation of transcendental (and trigonometric and hyperbolic)
4  *  functions. */
5
6 /*
7  *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
8  *
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.
13  *
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.
18  *
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22  */
23
24 #include <vector>
25 #include <stdexcept>
26
27 #include "inifcns.h"
28 #include "ex.h"
29 #include "constant.h"
30 #include "numeric.h"
31 #include "power.h"
32 #include "operators.h"
33 #include "relational.h"
34 #include "symbol.h"
35 #include "pseries.h"
36 #include "utils.h"
37
38 namespace GiNaC {
39
40 //////////
41 // exponential function
42 //////////
43
44 static ex exp_evalf(const ex & x)
45 {
46         if (is_exactly_a<numeric>(x))
47                 return exp(ex_to<numeric>(x));
48         
49         return exp(x).hold();
50 }
51
52 static ex exp_eval(const ex & x)
53 {
54         // exp(0) -> 1
55         if (x.is_zero()) {
56                 return _ex1;
57         }
58
59         // exp(n*Pi*I/2) -> {+1|+I|-1|-I}
60         const ex TwoExOverPiI=(_ex2*x)/(Pi*I);
61         if (TwoExOverPiI.info(info_flags::integer)) {
62                 const numeric z = mod(ex_to<numeric>(TwoExOverPiI),*_num4_p);
63                 if (z.is_equal(*_num0_p))
64                         return _ex1;
65                 if (z.is_equal(*_num1_p))
66                         return ex(I);
67                 if (z.is_equal(*_num2_p))
68                         return _ex_1;
69                 if (z.is_equal(*_num3_p))
70                         return ex(-I);
71         }
72
73         // exp(log(x)) -> x
74         if (is_ex_the_function(x, log))
75                 return x.op(0);
76         
77         // exp(float) -> float
78         if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
79                 return exp(ex_to<numeric>(x));
80         
81         return exp(x).hold();
82 }
83
84 static ex exp_deriv(const ex & x, unsigned deriv_param)
85 {
86         GINAC_ASSERT(deriv_param==0);
87
88         // d/dx exp(x) -> exp(x)
89         return exp(x);
90 }
91
92 static ex exp_real_part(const ex & x)
93 {
94         return exp(GiNaC::real_part(x))*cos(GiNaC::imag_part(x));
95 }
96
97 static ex exp_imag_part(const ex & x)
98 {
99         return exp(GiNaC::real_part(x))*sin(GiNaC::imag_part(x));
100 }
101
102 REGISTER_FUNCTION(exp, eval_func(exp_eval).
103                        evalf_func(exp_evalf).
104                        derivative_func(exp_deriv).
105                        real_part_func(exp_real_part).
106                        imag_part_func(exp_imag_part).
107                        latex_name("\\exp"));
108
109 //////////
110 // natural logarithm
111 //////////
112
113 static ex log_evalf(const ex & x)
114 {
115         if (is_exactly_a<numeric>(x))
116                 return log(ex_to<numeric>(x));
117         
118         return log(x).hold();
119 }
120
121 static ex log_eval(const ex & x)
122 {
123         if (x.info(info_flags::numeric)) {
124                 if (x.is_zero())         // log(0) -> infinity
125                         throw(pole_error("log_eval(): log(0)",0));
126                 if (x.info(info_flags::rational) && x.info(info_flags::negative))
127                         return (log(-x)+I*Pi);
128                 if (x.is_equal(_ex1))  // log(1) -> 0
129                         return _ex0;
130                 if (x.is_equal(I))       // log(I) -> Pi*I/2
131                         return (Pi*I*_ex1_2);
132                 if (x.is_equal(-I))      // log(-I) -> -Pi*I/2
133                         return (Pi*I*_ex_1_2);
134
135                 // log(float) -> float
136                 if (!x.info(info_flags::crational))
137                         return log(ex_to<numeric>(x));
138         }
139
140         // log(exp(t)) -> t (if -Pi < t.imag() <= Pi):
141         if (is_ex_the_function(x, exp)) {
142                 const ex &t = x.op(0);
143                 if (t.info(info_flags::real))
144                         return t;
145         }
146         
147         return log(x).hold();
148 }
149
150 static ex log_deriv(const ex & x, unsigned deriv_param)
151 {
152         GINAC_ASSERT(deriv_param==0);
153         
154         // d/dx log(x) -> 1/x
155         return power(x, _ex_1);
156 }
157
158 static ex log_series(const ex &arg,
159                      const relational &rel,
160                      int order,
161                      unsigned options)
162 {
163         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
164         ex arg_pt;
165         bool must_expand_arg = false;
166         // maybe substitution of rel into arg fails because of a pole
167         try {
168                 arg_pt = arg.subs(rel, subs_options::no_pattern);
169         } catch (pole_error) {
170                 must_expand_arg = true;
171         }
172         // or we are at the branch point anyways
173         if (arg_pt.is_zero())
174                 must_expand_arg = true;
175         
176         if (must_expand_arg) {
177                 // method:
178                 // This is the branch point: Series expand the argument first, then
179                 // trivially factorize it to isolate that part which has constant
180                 // leading coefficient in this fashion:
181                 //   x^n + x^(n+1) +...+ Order(x^(n+m))  ->  x^n * (1 + x +...+ Order(x^m)).
182                 // Return a plain n*log(x) for the x^n part and series expand the
183                 // other part.  Add them together and reexpand again in order to have
184                 // one unnested pseries object.  All this also works for negative n.
185                 pseries argser;          // series expansion of log's argument
186                 unsigned extra_ord = 0;  // extra expansion order
187                 do {
188                         // oops, the argument expanded to a pure Order(x^something)...
189                         argser = ex_to<pseries>(arg.series(rel, order+extra_ord, options));
190                         ++extra_ord;
191                 } while (!argser.is_terminating() && argser.nops()==1);
192
193                 const symbol &s = ex_to<symbol>(rel.lhs());
194                 const ex &point = rel.rhs();
195                 const int n = argser.ldegree(s);
196                 epvector seq;
197                 // construct what we carelessly called the n*log(x) term above
198                 const ex coeff = argser.coeff(s, n);
199                 // expand the log, but only if coeff is real and > 0, since otherwise
200                 // it would make the branch cut run into the wrong direction
201                 if (coeff.info(info_flags::positive))
202                         seq.push_back(expair(n*log(s-point)+log(coeff), _ex0));
203                 else
204                         seq.push_back(expair(log(coeff*pow(s-point, n)), _ex0));
205
206                 if (!argser.is_terminating() || argser.nops()!=1) {
207                         // in this case n more (or less) terms are needed
208                         // (sadly, to generate them, we have to start from the beginning)
209                         if (n == 0 && coeff == 1) {
210                                 epvector epv;
211                                 ex acc = (new pseries(rel, epv))->setflag(status_flags::dynallocated);
212                                 epv.reserve(2);
213                                 epv.push_back(expair(-1, _ex0));
214                                 epv.push_back(expair(Order(_ex1), order));
215                                 ex rest = pseries(rel, epv).add_series(argser);
216                                 for (int i = order-1; i>0; --i) {
217                                         epvector cterm;
218                                         cterm.reserve(1);
219                                         cterm.push_back(expair(i%2 ? _ex1/i : _ex_1/i, _ex0));
220                                         acc = pseries(rel, cterm).add_series(ex_to<pseries>(acc));
221                                         acc = (ex_to<pseries>(rest)).mul_series(ex_to<pseries>(acc));
222                                 }
223                                 return acc;
224                         }
225                         const ex newarg = ex_to<pseries>((arg/coeff).series(rel, order+n, options)).shift_exponents(-n).convert_to_poly(true);
226                         return pseries(rel, seq).add_series(ex_to<pseries>(log(newarg).series(rel, order, options)));
227                 } else  // it was a monomial
228                         return pseries(rel, seq);
229         }
230         if (!(options & series_options::suppress_branchcut) &&
231              arg_pt.info(info_flags::negative)) {
232                 // method:
233                 // This is the branch cut: assemble the primitive series manually and
234                 // then add the corresponding complex step function.
235                 const symbol &s = ex_to<symbol>(rel.lhs());
236                 const ex &point = rel.rhs();
237                 const symbol foo;
238                 const ex replarg = series(log(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
239                 epvector seq;
240                 seq.push_back(expair(-I*csgn(arg*I)*Pi, _ex0));
241                 seq.push_back(expair(Order(_ex1), order));
242                 return series(replarg - I*Pi + pseries(rel, seq), rel, order);
243         }
244         throw do_taylor();  // caught by function::series()
245 }
246
247 static ex log_real_part(const ex & x)
248 {
249         if (x.info(info_flags::nonnegative))
250                 return log(x).hold();
251         return log(abs(x));
252 }
253
254 static ex log_imag_part(const ex & x)
255 {
256         if (x.info(info_flags::nonnegative))
257                 return 0;
258         return atan2(GiNaC::imag_part(x), GiNaC::real_part(x));
259 }
260
261 REGISTER_FUNCTION(log, eval_func(log_eval).
262                        evalf_func(log_evalf).
263                        derivative_func(log_deriv).
264                        series_func(log_series).
265                        real_part_func(log_real_part).
266                        imag_part_func(log_imag_part).
267                        latex_name("\\ln"));
268
269 //////////
270 // sine (trigonometric function)
271 //////////
272
273 static ex sin_evalf(const ex & x)
274 {
275         if (is_exactly_a<numeric>(x))
276                 return sin(ex_to<numeric>(x));
277         
278         return sin(x).hold();
279 }
280
281 static ex sin_eval(const ex & x)
282 {
283         // sin(n/d*Pi) -> { all known non-nested radicals }
284         const ex SixtyExOverPi = _ex60*x/Pi;
285         ex sign = _ex1;
286         if (SixtyExOverPi.info(info_flags::integer)) {
287                 numeric z = mod(ex_to<numeric>(SixtyExOverPi),*_num120_p);
288                 if (z>=*_num60_p) {
289                         // wrap to interval [0, Pi)
290                         z -= *_num60_p;
291                         sign = _ex_1;
292                 }
293                 if (z>*_num30_p) {
294                         // wrap to interval [0, Pi/2)
295                         z = *_num60_p-z;
296                 }
297                 if (z.is_equal(*_num0_p))  // sin(0)       -> 0
298                         return _ex0;
299                 if (z.is_equal(*_num5_p))  // sin(Pi/12)   -> sqrt(6)/4*(1-sqrt(3)/3)
300                         return sign*_ex1_4*sqrt(_ex6)*(_ex1+_ex_1_3*sqrt(_ex3));
301                 if (z.is_equal(*_num6_p))  // sin(Pi/10)   -> sqrt(5)/4-1/4
302                         return sign*(_ex1_4*sqrt(_ex5)+_ex_1_4);
303                 if (z.is_equal(*_num10_p)) // sin(Pi/6)    -> 1/2
304                         return sign*_ex1_2;
305                 if (z.is_equal(*_num15_p)) // sin(Pi/4)    -> sqrt(2)/2
306                         return sign*_ex1_2*sqrt(_ex2);
307                 if (z.is_equal(*_num18_p)) // sin(3/10*Pi) -> sqrt(5)/4+1/4
308                         return sign*(_ex1_4*sqrt(_ex5)+_ex1_4);
309                 if (z.is_equal(*_num20_p)) // sin(Pi/3)    -> sqrt(3)/2
310                         return sign*_ex1_2*sqrt(_ex3);
311                 if (z.is_equal(*_num25_p)) // sin(5/12*Pi) -> sqrt(6)/4*(1+sqrt(3)/3)
312                         return sign*_ex1_4*sqrt(_ex6)*(_ex1+_ex1_3*sqrt(_ex3));
313                 if (z.is_equal(*_num30_p)) // sin(Pi/2)    -> 1
314                         return sign;
315         }
316
317         if (is_exactly_a<function>(x)) {
318                 const ex &t = x.op(0);
319
320                 // sin(asin(x)) -> x
321                 if (is_ex_the_function(x, asin))
322                         return t;
323
324                 // sin(acos(x)) -> sqrt(1-x^2)
325                 if (is_ex_the_function(x, acos))
326                         return sqrt(_ex1-power(t,_ex2));
327
328                 // sin(atan(x)) -> x/sqrt(1+x^2)
329                 if (is_ex_the_function(x, atan))
330                         return t*power(_ex1+power(t,_ex2),_ex_1_2);
331         }
332         
333         // sin(float) -> float
334         if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
335                 return sin(ex_to<numeric>(x));
336
337         // sin() is odd
338         if (x.info(info_flags::negative))
339                 return -sin(-x);
340         
341         return sin(x).hold();
342 }
343
344 static ex sin_deriv(const ex & x, unsigned deriv_param)
345 {
346         GINAC_ASSERT(deriv_param==0);
347         
348         // d/dx sin(x) -> cos(x)
349         return cos(x);
350 }
351
352 static ex sin_real_part(const ex & x)
353 {
354         return cosh(GiNaC::imag_part(x))*sin(GiNaC::real_part(x));
355 }
356
357 static ex sin_imag_part(const ex & x)
358 {
359         return sinh(GiNaC::imag_part(x))*cos(GiNaC::real_part(x));
360 }
361
362 REGISTER_FUNCTION(sin, eval_func(sin_eval).
363                        evalf_func(sin_evalf).
364                        derivative_func(sin_deriv).
365                        real_part_func(sin_real_part).
366                        imag_part_func(sin_imag_part).
367                        latex_name("\\sin"));
368
369 //////////
370 // cosine (trigonometric function)
371 //////////
372
373 static ex cos_evalf(const ex & x)
374 {
375         if (is_exactly_a<numeric>(x))
376                 return cos(ex_to<numeric>(x));
377         
378         return cos(x).hold();
379 }
380
381 static ex cos_eval(const ex & x)
382 {
383         // cos(n/d*Pi) -> { all known non-nested radicals }
384         const ex SixtyExOverPi = _ex60*x/Pi;
385         ex sign = _ex1;
386         if (SixtyExOverPi.info(info_flags::integer)) {
387                 numeric z = mod(ex_to<numeric>(SixtyExOverPi),*_num120_p);
388                 if (z>=*_num60_p) {
389                         // wrap to interval [0, Pi)
390                         z = *_num120_p-z;
391                 }
392                 if (z>=*_num30_p) {
393                         // wrap to interval [0, Pi/2)
394                         z = *_num60_p-z;
395                         sign = _ex_1;
396                 }
397                 if (z.is_equal(*_num0_p))  // cos(0)       -> 1
398                         return sign;
399                 if (z.is_equal(*_num5_p))  // cos(Pi/12)   -> sqrt(6)/4*(1+sqrt(3)/3)
400                         return sign*_ex1_4*sqrt(_ex6)*(_ex1+_ex1_3*sqrt(_ex3));
401                 if (z.is_equal(*_num10_p)) // cos(Pi/6)    -> sqrt(3)/2
402                         return sign*_ex1_2*sqrt(_ex3);
403                 if (z.is_equal(*_num12_p)) // cos(Pi/5)    -> sqrt(5)/4+1/4
404                         return sign*(_ex1_4*sqrt(_ex5)+_ex1_4);
405                 if (z.is_equal(*_num15_p)) // cos(Pi/4)    -> sqrt(2)/2
406                         return sign*_ex1_2*sqrt(_ex2);
407                 if (z.is_equal(*_num20_p)) // cos(Pi/3)    -> 1/2
408                         return sign*_ex1_2;
409                 if (z.is_equal(*_num24_p)) // cos(2/5*Pi)  -> sqrt(5)/4-1/4x
410                         return sign*(_ex1_4*sqrt(_ex5)+_ex_1_4);
411                 if (z.is_equal(*_num25_p)) // cos(5/12*Pi) -> sqrt(6)/4*(1-sqrt(3)/3)
412                         return sign*_ex1_4*sqrt(_ex6)*(_ex1+_ex_1_3*sqrt(_ex3));
413                 if (z.is_equal(*_num30_p)) // cos(Pi/2)    -> 0
414                         return _ex0;
415         }
416
417         if (is_exactly_a<function>(x)) {
418                 const ex &t = x.op(0);
419
420                 // cos(acos(x)) -> x
421                 if (is_ex_the_function(x, acos))
422                         return t;
423
424                 // cos(asin(x)) -> sqrt(1-x^2)
425                 if (is_ex_the_function(x, asin))
426                         return sqrt(_ex1-power(t,_ex2));
427
428                 // cos(atan(x)) -> 1/sqrt(1+x^2)
429                 if (is_ex_the_function(x, atan))
430                         return power(_ex1+power(t,_ex2),_ex_1_2);
431         }
432         
433         // cos(float) -> float
434         if (x.info(info_flags::numeric) && !x.info(info_flags::crational))
435                 return cos(ex_to<numeric>(x));
436         
437         // cos() is even
438         if (x.info(info_flags::negative))
439                 return cos(-x);
440         
441         return cos(x).hold();
442 }
443
444 static ex cos_deriv(const ex & x, unsigned deriv_param)
445 {
446         GINAC_ASSERT(deriv_param==0);
447
448         // d/dx cos(x) -> -sin(x)
449         return -sin(x);
450 }
451
452 static ex cos_real_part(const ex & x)
453 {
454         return cosh(GiNaC::imag_part(x))*cos(GiNaC::real_part(x));
455 }
456
457 static ex cos_imag_part(const ex & x)
458 {
459         return -sinh(GiNaC::imag_part(x))*sin(GiNaC::real_part(x));
460 }
461
462 REGISTER_FUNCTION(cos, eval_func(cos_eval).
463                        evalf_func(cos_evalf).
464                        derivative_func(cos_deriv).
465                        real_part_func(cos_real_part).
466                        imag_part_func(cos_imag_part).
467                        latex_name("\\cos"));
468
469 //////////
470 // tangent (trigonometric function)
471 //////////
472
473 static ex tan_evalf(const ex & x)
474 {
475         if (is_exactly_a<numeric>(x))
476                 return tan(ex_to<numeric>(x));
477         
478         return tan(x).hold();
479 }
480
481 static ex tan_eval(const ex & x)
482 {
483         // tan(n/d*Pi) -> { all known non-nested radicals }
484         const ex SixtyExOverPi = _ex60*x/Pi;
485         ex sign = _ex1;
486         if (SixtyExOverPi.info(info_flags::integer)) {
487                 numeric z = mod(ex_to<numeric>(SixtyExOverPi),*_num60_p);
488                 if (z>=*_num60_p) {
489                         // wrap to interval [0, Pi)
490                         z -= *_num60_p;
491                 }
492                 if (z>=*_num30_p) {
493                         // wrap to interval [0, Pi/2)
494                         z = *_num60_p-z;
495                         sign = _ex_1;
496                 }
497                 if (z.is_equal(*_num0_p))  // tan(0)       -> 0
498                         return _ex0;
499                 if (z.is_equal(*_num5_p))  // tan(Pi/12)   -> 2-sqrt(3)
500                         return sign*(_ex2-sqrt(_ex3));
501                 if (z.is_equal(*_num10_p)) // tan(Pi/6)    -> sqrt(3)/3
502                         return sign*_ex1_3*sqrt(_ex3);
503                 if (z.is_equal(*_num15_p)) // tan(Pi/4)    -> 1
504                         return sign;
505                 if (z.is_equal(*_num20_p)) // tan(Pi/3)    -> sqrt(3)
506                         return sign*sqrt(_ex3);
507                 if (z.is_equal(*_num25_p)) // tan(5/12*Pi) -> 2+sqrt(3)
508                         return sign*(sqrt(_ex3)+_ex2);
509                 if (z.is_equal(*_num30_p)) // tan(Pi/2)    -> infinity
510                         throw (pole_error("tan_eval(): simple pole",1));
511         }
512
513         if (is_exactly_a<function>(x)) {
514                 const ex &t = x.op(0);
515
516                 // tan(atan(x)) -> x
517                 if (is_ex_the_function(x, atan))
518                         return t;
519
520                 // tan(asin(x)) -> x/sqrt(1+x^2)
521                 if (is_ex_the_function(x, asin))
522                         return t*power(_ex1-power(t,_ex2),_ex_1_2);
523
524                 // tan(acos(x)) -> sqrt(1-x^2)/x
525                 if (is_ex_the_function(x, acos))
526                         return power(t,_ex_1)*sqrt(_ex1-power(t,_ex2));
527         }
528         
529         // tan(float) -> float
530         if (x.info(info_flags::numeric) && !x.info(info_flags::crational)) {
531                 return tan(ex_to<numeric>(x));
532         }
533         
534         // tan() is odd
535         if (x.info(info_flags::negative))
536                 return -tan(-x);
537         
538         return tan(x).hold();
539 }
540
541 static ex tan_deriv(const ex & x, unsigned deriv_param)
542 {
543         GINAC_ASSERT(deriv_param==0);
544         
545         // d/dx tan(x) -> 1+tan(x)^2;
546         return (_ex1+power(tan(x),_ex2));
547 }
548
549 static ex tan_real_part(const ex & x)
550 {
551         ex a = GiNaC::real_part(x);
552         ex b = GiNaC::imag_part(x);
553         return tan(a)/(1+power(tan(a),2)*power(tan(b),2));
554 }
555
556 static ex tan_imag_part(const ex & x)
557 {
558         ex a = GiNaC::real_part(x);
559         ex b = GiNaC::imag_part(x);
560         return tanh(b)/(1+power(tan(a),2)*power(tan(b),2));
561 }
562
563 static ex tan_series(const ex &x,
564                      const relational &rel,
565                      int order,
566                      unsigned options)
567 {
568         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
569         // method:
570         // Taylor series where there is no pole falls back to tan_deriv.
571         // On a pole simply expand sin(x)/cos(x).
572         const ex x_pt = x.subs(rel, subs_options::no_pattern);
573         if (!(2*x_pt/Pi).info(info_flags::odd))
574                 throw do_taylor();  // caught by function::series()
575         // if we got here we have to care for a simple pole
576         return (sin(x)/cos(x)).series(rel, order, options);
577 }
578
579 REGISTER_FUNCTION(tan, eval_func(tan_eval).
580                        evalf_func(tan_evalf).
581                        derivative_func(tan_deriv).
582                        series_func(tan_series).
583                        real_part_func(tan_real_part).
584                        imag_part_func(tan_imag_part).
585                        latex_name("\\tan"));
586
587 //////////
588 // inverse sine (arc sine)
589 //////////
590
591 static ex asin_evalf(const ex & x)
592 {
593         if (is_exactly_a<numeric>(x))
594                 return asin(ex_to<numeric>(x));
595         
596         return asin(x).hold();
597 }
598
599 static ex asin_eval(const ex & x)
600 {
601         if (x.info(info_flags::numeric)) {
602
603                 // asin(0) -> 0
604                 if (x.is_zero())
605                         return x;
606
607                 // asin(1/2) -> Pi/6
608                 if (x.is_equal(_ex1_2))
609                         return numeric(1,6)*Pi;
610
611                 // asin(1) -> Pi/2
612                 if (x.is_equal(_ex1))
613                         return _ex1_2*Pi;
614
615                 // asin(-1/2) -> -Pi/6
616                 if (x.is_equal(_ex_1_2))
617                         return numeric(-1,6)*Pi;
618
619                 // asin(-1) -> -Pi/2
620                 if (x.is_equal(_ex_1))
621                         return _ex_1_2*Pi;
622
623                 // asin(float) -> float
624                 if (!x.info(info_flags::crational))
625                         return asin(ex_to<numeric>(x));
626
627                 // asin() is odd
628                 if (x.info(info_flags::negative))
629                         return -asin(-x);
630         }
631         
632         return asin(x).hold();
633 }
634
635 static ex asin_deriv(const ex & x, unsigned deriv_param)
636 {
637         GINAC_ASSERT(deriv_param==0);
638         
639         // d/dx asin(x) -> 1/sqrt(1-x^2)
640         return power(1-power(x,_ex2),_ex_1_2);
641 }
642
643 REGISTER_FUNCTION(asin, eval_func(asin_eval).
644                         evalf_func(asin_evalf).
645                         derivative_func(asin_deriv).
646                         latex_name("\\arcsin"));
647
648 //////////
649 // inverse cosine (arc cosine)
650 //////////
651
652 static ex acos_evalf(const ex & x)
653 {
654         if (is_exactly_a<numeric>(x))
655                 return acos(ex_to<numeric>(x));
656         
657         return acos(x).hold();
658 }
659
660 static ex acos_eval(const ex & x)
661 {
662         if (x.info(info_flags::numeric)) {
663
664                 // acos(1) -> 0
665                 if (x.is_equal(_ex1))
666                         return _ex0;
667
668                 // acos(1/2) -> Pi/3
669                 if (x.is_equal(_ex1_2))
670                         return _ex1_3*Pi;
671
672                 // acos(0) -> Pi/2
673                 if (x.is_zero())
674                         return _ex1_2*Pi;
675
676                 // acos(-1/2) -> 2/3*Pi
677                 if (x.is_equal(_ex_1_2))
678                         return numeric(2,3)*Pi;
679
680                 // acos(-1) -> Pi
681                 if (x.is_equal(_ex_1))
682                         return Pi;
683
684                 // acos(float) -> float
685                 if (!x.info(info_flags::crational))
686                         return acos(ex_to<numeric>(x));
687
688                 // acos(-x) -> Pi-acos(x)
689                 if (x.info(info_flags::negative))
690                         return Pi-acos(-x);
691         }
692         
693         return acos(x).hold();
694 }
695
696 static ex acos_deriv(const ex & x, unsigned deriv_param)
697 {
698         GINAC_ASSERT(deriv_param==0);
699         
700         // d/dx acos(x) -> -1/sqrt(1-x^2)
701         return -power(1-power(x,_ex2),_ex_1_2);
702 }
703
704 REGISTER_FUNCTION(acos, eval_func(acos_eval).
705                         evalf_func(acos_evalf).
706                         derivative_func(acos_deriv).
707                         latex_name("\\arccos"));
708
709 //////////
710 // inverse tangent (arc tangent)
711 //////////
712
713 static ex atan_evalf(const ex & x)
714 {
715         if (is_exactly_a<numeric>(x))
716                 return atan(ex_to<numeric>(x));
717         
718         return atan(x).hold();
719 }
720
721 static ex atan_eval(const ex & x)
722 {
723         if (x.info(info_flags::numeric)) {
724
725                 // atan(0) -> 0
726                 if (x.is_zero())
727                         return _ex0;
728
729                 // atan(1) -> Pi/4
730                 if (x.is_equal(_ex1))
731                         return _ex1_4*Pi;
732
733                 // atan(-1) -> -Pi/4
734                 if (x.is_equal(_ex_1))
735                         return _ex_1_4*Pi;
736
737                 if (x.is_equal(I) || x.is_equal(-I))
738                         throw (pole_error("atan_eval(): logarithmic pole",0));
739
740                 // atan(float) -> float
741                 if (!x.info(info_flags::crational))
742                         return atan(ex_to<numeric>(x));
743
744                 // atan() is odd
745                 if (x.info(info_flags::negative))
746                         return -atan(-x);
747         }
748         
749         return atan(x).hold();
750 }
751
752 static ex atan_deriv(const ex & x, unsigned deriv_param)
753 {
754         GINAC_ASSERT(deriv_param==0);
755
756         // d/dx atan(x) -> 1/(1+x^2)
757         return power(_ex1+power(x,_ex2), _ex_1);
758 }
759
760 static ex atan_series(const ex &arg,
761                       const relational &rel,
762                       int order,
763                       unsigned options)
764 {
765         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
766         // method:
767         // Taylor series where there is no pole or cut falls back to atan_deriv.
768         // There are two branch cuts, one runnig from I up the imaginary axis and
769         // one running from -I down the imaginary axis.  The points I and -I are
770         // poles.
771         // On the branch cuts and the poles series expand
772         //     (log(1+I*x)-log(1-I*x))/(2*I)
773         // instead.
774         const ex arg_pt = arg.subs(rel, subs_options::no_pattern);
775         if (!(I*arg_pt).info(info_flags::real))
776                 throw do_taylor();     // Re(x) != 0
777         if ((I*arg_pt).info(info_flags::real) && abs(I*arg_pt)<_ex1)
778                 throw do_taylor();     // Re(x) == 0, but abs(x)<1
779         // care for the poles, using the defining formula for atan()...
780         if (arg_pt.is_equal(I) || arg_pt.is_equal(-I))
781                 return ((log(1+I*arg)-log(1-I*arg))/(2*I)).series(rel, order, options);
782         if (!(options & series_options::suppress_branchcut)) {
783                 // method:
784                 // This is the branch cut: assemble the primitive series manually and
785                 // then add the corresponding complex step function.
786                 const symbol &s = ex_to<symbol>(rel.lhs());
787                 const ex &point = rel.rhs();
788                 const symbol foo;
789                 const ex replarg = series(atan(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
790                 ex Order0correction = replarg.op(0)+csgn(arg)*Pi*_ex_1_2;
791                 if ((I*arg_pt)<_ex0)
792                         Order0correction += log((I*arg_pt+_ex_1)/(I*arg_pt+_ex1))*I*_ex_1_2;
793                 else
794                         Order0correction += log((I*arg_pt+_ex1)/(I*arg_pt+_ex_1))*I*_ex1_2;
795                 epvector seq;
796                 seq.push_back(expair(Order0correction, _ex0));
797                 seq.push_back(expair(Order(_ex1), order));
798                 return series(replarg - pseries(rel, seq), rel, order);
799         }
800         throw do_taylor();
801 }
802
803 REGISTER_FUNCTION(atan, eval_func(atan_eval).
804                         evalf_func(atan_evalf).
805                         derivative_func(atan_deriv).
806                         series_func(atan_series).
807                         latex_name("\\arctan"));
808
809 //////////
810 // inverse tangent (atan2(y,x))
811 //////////
812
813 static ex atan2_evalf(const ex &y, const ex &x)
814 {
815         if (is_exactly_a<numeric>(y) && is_exactly_a<numeric>(x))
816                 return atan(ex_to<numeric>(y), ex_to<numeric>(x));
817         
818         return atan2(y, x).hold();
819 }
820
821 static ex atan2_eval(const ex & y, const ex & x)
822 {
823         if (y.is_zero()) {
824
825                 // atan(0, 0) -> 0
826                 if (x.is_zero())
827                         return _ex0;
828
829                 // atan(0, x), x real and positive -> 0
830                 if (x.info(info_flags::positive))
831                         return _ex0;
832
833                 // atan(0, x), x real and negative -> Pi
834                 if (x.info(info_flags::negative))
835                         return Pi;
836         }
837
838         if (x.is_zero()) {
839
840                 // atan(y, 0), y real and positive -> Pi/2
841                 if (y.info(info_flags::positive))
842                         return _ex1_2*Pi;
843
844                 // atan(y, 0), y real and negative -> -Pi/2
845                 if (y.info(info_flags::negative))
846                         return _ex_1_2*Pi;
847         }
848
849         if (y.is_equal(x)) {
850
851                 // atan(y, y), y real and positive -> Pi/4
852                 if (y.info(info_flags::positive))
853                         return _ex1_4*Pi;
854
855                 // atan(y, y), y real and negative -> -3/4*Pi
856                 if (y.info(info_flags::negative))
857                         return numeric(-3, 4)*Pi;
858         }
859
860         if (y.is_equal(-x)) {
861
862                 // atan(y, -y), y real and positive -> 3*Pi/4
863                 if (y.info(info_flags::positive))
864                         return numeric(3, 4)*Pi;
865
866                 // atan(y, -y), y real and negative -> -Pi/4
867                 if (y.info(info_flags::negative))
868                         return _ex_1_4*Pi;
869         }
870
871         // atan(float, float) -> float
872         if (is_a<numeric>(y) && !y.info(info_flags::crational) &&
873             is_a<numeric>(x) && !x.info(info_flags::crational))
874                 return atan(ex_to<numeric>(y), ex_to<numeric>(x));
875
876         // atan(real, real) -> atan(y/x) +/- Pi
877         if (y.info(info_flags::real) && x.info(info_flags::real)) {
878                 if (x.info(info_flags::positive))
879                         return atan(y/x);
880                 else if (y.info(info_flags::positive))
881                         return atan(y/x)+Pi;
882                 else
883                         return atan(y/x)-Pi;
884         }
885
886         return atan2(y, x).hold();
887 }    
888
889 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
890 {
891         GINAC_ASSERT(deriv_param<2);
892         
893         if (deriv_param==0) {
894                 // d/dy atan(y,x)
895                 return x*power(power(x,_ex2)+power(y,_ex2),_ex_1);
896         }
897         // d/dx atan(y,x)
898         return -y*power(power(x,_ex2)+power(y,_ex2),_ex_1);
899 }
900
901 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
902                          evalf_func(atan2_evalf).
903                          derivative_func(atan2_deriv));
904
905 //////////
906 // hyperbolic sine (trigonometric function)
907 //////////
908
909 static ex sinh_evalf(const ex & x)
910 {
911         if (is_exactly_a<numeric>(x))
912                 return sinh(ex_to<numeric>(x));
913         
914         return sinh(x).hold();
915 }
916
917 static ex sinh_eval(const ex & x)
918 {
919         if (x.info(info_flags::numeric)) {
920
921                 // sinh(0) -> 0
922                 if (x.is_zero())
923                         return _ex0;        
924
925                 // sinh(float) -> float
926                 if (!x.info(info_flags::crational))
927                         return sinh(ex_to<numeric>(x));
928
929                 // sinh() is odd
930                 if (x.info(info_flags::negative))
931                         return -sinh(-x);
932         }
933         
934         if ((x/Pi).info(info_flags::numeric) &&
935                 ex_to<numeric>(x/Pi).real().is_zero())  // sinh(I*x) -> I*sin(x)
936                 return I*sin(x/I);
937         
938         if (is_exactly_a<function>(x)) {
939                 const ex &t = x.op(0);
940
941                 // sinh(asinh(x)) -> x
942                 if (is_ex_the_function(x, asinh))
943                         return t;
944
945                 // sinh(acosh(x)) -> sqrt(x-1) * sqrt(x+1)
946                 if (is_ex_the_function(x, acosh))
947                         return sqrt(t-_ex1)*sqrt(t+_ex1);
948
949                 // sinh(atanh(x)) -> x/sqrt(1-x^2)
950                 if (is_ex_the_function(x, atanh))
951                         return t*power(_ex1-power(t,_ex2),_ex_1_2);
952         }
953         
954         return sinh(x).hold();
955 }
956
957 static ex sinh_deriv(const ex & x, unsigned deriv_param)
958 {
959         GINAC_ASSERT(deriv_param==0);
960         
961         // d/dx sinh(x) -> cosh(x)
962         return cosh(x);
963 }
964
965 static ex sinh_real_part(const ex & x)
966 {
967         return sinh(GiNaC::real_part(x))*cos(GiNaC::imag_part(x));
968 }
969
970 static ex sinh_imag_part(const ex & x)
971 {
972         return cosh(GiNaC::real_part(x))*sin(GiNaC::imag_part(x));
973 }
974
975 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
976                         evalf_func(sinh_evalf).
977                         derivative_func(sinh_deriv).
978                         real_part_func(sinh_real_part).
979                         imag_part_func(sinh_imag_part).
980                         latex_name("\\sinh"));
981
982 //////////
983 // hyperbolic cosine (trigonometric function)
984 //////////
985
986 static ex cosh_evalf(const ex & x)
987 {
988         if (is_exactly_a<numeric>(x))
989                 return cosh(ex_to<numeric>(x));
990         
991         return cosh(x).hold();
992 }
993
994 static ex cosh_eval(const ex & x)
995 {
996         if (x.info(info_flags::numeric)) {
997
998                 // cosh(0) -> 1
999                 if (x.is_zero())
1000                         return _ex1;
1001
1002                 // cosh(float) -> float
1003                 if (!x.info(info_flags::crational))
1004                         return cosh(ex_to<numeric>(x));
1005
1006                 // cosh() is even
1007                 if (x.info(info_flags::negative))
1008                         return cosh(-x);
1009         }
1010         
1011         if ((x/Pi).info(info_flags::numeric) &&
1012                 ex_to<numeric>(x/Pi).real().is_zero())  // cosh(I*x) -> cos(x)
1013                 return cos(x/I);
1014         
1015         if (is_exactly_a<function>(x)) {
1016                 const ex &t = x.op(0);
1017
1018                 // cosh(acosh(x)) -> x
1019                 if (is_ex_the_function(x, acosh))
1020                         return t;
1021
1022                 // cosh(asinh(x)) -> sqrt(1+x^2)
1023                 if (is_ex_the_function(x, asinh))
1024                         return sqrt(_ex1+power(t,_ex2));
1025
1026                 // cosh(atanh(x)) -> 1/sqrt(1-x^2)
1027                 if (is_ex_the_function(x, atanh))
1028                         return power(_ex1-power(t,_ex2),_ex_1_2);
1029         }
1030         
1031         return cosh(x).hold();
1032 }
1033
1034 static ex cosh_deriv(const ex & x, unsigned deriv_param)
1035 {
1036         GINAC_ASSERT(deriv_param==0);
1037         
1038         // d/dx cosh(x) -> sinh(x)
1039         return sinh(x);
1040 }
1041
1042 static ex cosh_real_part(const ex & x)
1043 {
1044         return cosh(GiNaC::real_part(x))*cos(GiNaC::imag_part(x));
1045 }
1046
1047 static ex cosh_imag_part(const ex & x)
1048 {
1049         return sinh(GiNaC::real_part(x))*sin(GiNaC::imag_part(x));
1050 }
1051
1052 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
1053                         evalf_func(cosh_evalf).
1054                         derivative_func(cosh_deriv).
1055                         real_part_func(cosh_real_part).
1056                         imag_part_func(cosh_imag_part).
1057                         latex_name("\\cosh"));
1058
1059 //////////
1060 // hyperbolic tangent (trigonometric function)
1061 //////////
1062
1063 static ex tanh_evalf(const ex & x)
1064 {
1065         if (is_exactly_a<numeric>(x))
1066                 return tanh(ex_to<numeric>(x));
1067         
1068         return tanh(x).hold();
1069 }
1070
1071 static ex tanh_eval(const ex & x)
1072 {
1073         if (x.info(info_flags::numeric)) {
1074
1075                 // tanh(0) -> 0
1076                 if (x.is_zero())
1077                         return _ex0;
1078
1079                 // tanh(float) -> float
1080                 if (!x.info(info_flags::crational))
1081                         return tanh(ex_to<numeric>(x));
1082
1083                 // tanh() is odd
1084                 if (x.info(info_flags::negative))
1085                         return -tanh(-x);
1086         }
1087         
1088         if ((x/Pi).info(info_flags::numeric) &&
1089                 ex_to<numeric>(x/Pi).real().is_zero())  // tanh(I*x) -> I*tan(x);
1090                 return I*tan(x/I);
1091         
1092         if (is_exactly_a<function>(x)) {
1093                 const ex &t = x.op(0);
1094
1095                 // tanh(atanh(x)) -> x
1096                 if (is_ex_the_function(x, atanh))
1097                         return t;
1098
1099                 // tanh(asinh(x)) -> x/sqrt(1+x^2)
1100                 if (is_ex_the_function(x, asinh))
1101                         return t*power(_ex1+power(t,_ex2),_ex_1_2);
1102
1103                 // tanh(acosh(x)) -> sqrt(x-1)*sqrt(x+1)/x
1104                 if (is_ex_the_function(x, acosh))
1105                         return sqrt(t-_ex1)*sqrt(t+_ex1)*power(t,_ex_1);
1106         }
1107         
1108         return tanh(x).hold();
1109 }
1110
1111 static ex tanh_deriv(const ex & x, unsigned deriv_param)
1112 {
1113         GINAC_ASSERT(deriv_param==0);
1114         
1115         // d/dx tanh(x) -> 1-tanh(x)^2
1116         return _ex1-power(tanh(x),_ex2);
1117 }
1118
1119 static ex tanh_series(const ex &x,
1120                       const relational &rel,
1121                       int order,
1122                       unsigned options)
1123 {
1124         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
1125         // method:
1126         // Taylor series where there is no pole falls back to tanh_deriv.
1127         // On a pole simply expand sinh(x)/cosh(x).
1128         const ex x_pt = x.subs(rel, subs_options::no_pattern);
1129         if (!(2*I*x_pt/Pi).info(info_flags::odd))
1130                 throw do_taylor();  // caught by function::series()
1131         // if we got here we have to care for a simple pole
1132         return (sinh(x)/cosh(x)).series(rel, order, options);
1133 }
1134
1135 static ex tanh_real_part(const ex & x)
1136 {
1137         ex a = GiNaC::real_part(x);
1138         ex b = GiNaC::imag_part(x);
1139         return tanh(a)/(1+power(tanh(a),2)*power(tan(b),2));
1140 }
1141
1142 static ex tanh_imag_part(const ex & x)
1143 {
1144         ex a = GiNaC::real_part(x);
1145         ex b = GiNaC::imag_part(x);
1146         return tan(b)/(1+power(tanh(a),2)*power(tan(b),2));
1147 }
1148
1149 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
1150                         evalf_func(tanh_evalf).
1151                         derivative_func(tanh_deriv).
1152                         series_func(tanh_series).
1153                         real_part_func(tanh_real_part).
1154                         imag_part_func(tanh_imag_part).
1155                         latex_name("\\tanh"));
1156
1157 //////////
1158 // inverse hyperbolic sine (trigonometric function)
1159 //////////
1160
1161 static ex asinh_evalf(const ex & x)
1162 {
1163         if (is_exactly_a<numeric>(x))
1164                 return asinh(ex_to<numeric>(x));
1165         
1166         return asinh(x).hold();
1167 }
1168
1169 static ex asinh_eval(const ex & x)
1170 {
1171         if (x.info(info_flags::numeric)) {
1172
1173                 // asinh(0) -> 0
1174                 if (x.is_zero())
1175                         return _ex0;
1176
1177                 // asinh(float) -> float
1178                 if (!x.info(info_flags::crational))
1179                         return asinh(ex_to<numeric>(x));
1180
1181                 // asinh() is odd
1182                 if (x.info(info_flags::negative))
1183                         return -asinh(-x);
1184         }
1185         
1186         return asinh(x).hold();
1187 }
1188
1189 static ex asinh_deriv(const ex & x, unsigned deriv_param)
1190 {
1191         GINAC_ASSERT(deriv_param==0);
1192         
1193         // d/dx asinh(x) -> 1/sqrt(1+x^2)
1194         return power(_ex1+power(x,_ex2),_ex_1_2);
1195 }
1196
1197 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
1198                          evalf_func(asinh_evalf).
1199                          derivative_func(asinh_deriv));
1200
1201 //////////
1202 // inverse hyperbolic cosine (trigonometric function)
1203 //////////
1204
1205 static ex acosh_evalf(const ex & x)
1206 {
1207         if (is_exactly_a<numeric>(x))
1208                 return acosh(ex_to<numeric>(x));
1209         
1210         return acosh(x).hold();
1211 }
1212
1213 static ex acosh_eval(const ex & x)
1214 {
1215         if (x.info(info_flags::numeric)) {
1216
1217                 // acosh(0) -> Pi*I/2
1218                 if (x.is_zero())
1219                         return Pi*I*numeric(1,2);
1220
1221                 // acosh(1) -> 0
1222                 if (x.is_equal(_ex1))
1223                         return _ex0;
1224
1225                 // acosh(-1) -> Pi*I
1226                 if (x.is_equal(_ex_1))
1227                         return Pi*I;
1228
1229                 // acosh(float) -> float
1230                 if (!x.info(info_flags::crational))
1231                         return acosh(ex_to<numeric>(x));
1232
1233                 // acosh(-x) -> Pi*I-acosh(x)
1234                 if (x.info(info_flags::negative))
1235                         return Pi*I-acosh(-x);
1236         }
1237         
1238         return acosh(x).hold();
1239 }
1240
1241 static ex acosh_deriv(const ex & x, unsigned deriv_param)
1242 {
1243         GINAC_ASSERT(deriv_param==0);
1244         
1245         // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
1246         return power(x+_ex_1,_ex_1_2)*power(x+_ex1,_ex_1_2);
1247 }
1248
1249 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
1250                          evalf_func(acosh_evalf).
1251                          derivative_func(acosh_deriv));
1252
1253 //////////
1254 // inverse hyperbolic tangent (trigonometric function)
1255 //////////
1256
1257 static ex atanh_evalf(const ex & x)
1258 {
1259         if (is_exactly_a<numeric>(x))
1260                 return atanh(ex_to<numeric>(x));
1261         
1262         return atanh(x).hold();
1263 }
1264
1265 static ex atanh_eval(const ex & x)
1266 {
1267         if (x.info(info_flags::numeric)) {
1268
1269                 // atanh(0) -> 0
1270                 if (x.is_zero())
1271                         return _ex0;
1272
1273                 // atanh({+|-}1) -> throw
1274                 if (x.is_equal(_ex1) || x.is_equal(_ex_1))
1275                         throw (pole_error("atanh_eval(): logarithmic pole",0));
1276
1277                 // atanh(float) -> float
1278                 if (!x.info(info_flags::crational))
1279                         return atanh(ex_to<numeric>(x));
1280
1281                 // atanh() is odd
1282                 if (x.info(info_flags::negative))
1283                         return -atanh(-x);
1284         }
1285         
1286         return atanh(x).hold();
1287 }
1288
1289 static ex atanh_deriv(const ex & x, unsigned deriv_param)
1290 {
1291         GINAC_ASSERT(deriv_param==0);
1292         
1293         // d/dx atanh(x) -> 1/(1-x^2)
1294         return power(_ex1-power(x,_ex2),_ex_1);
1295 }
1296
1297 static ex atanh_series(const ex &arg,
1298                        const relational &rel,
1299                        int order,
1300                        unsigned options)
1301 {
1302         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
1303         // method:
1304         // Taylor series where there is no pole or cut falls back to atanh_deriv.
1305         // There are two branch cuts, one runnig from 1 up the real axis and one
1306         // one running from -1 down the real axis.  The points 1 and -1 are poles
1307         // On the branch cuts and the poles series expand
1308         //     (log(1+x)-log(1-x))/2
1309         // instead.
1310         const ex arg_pt = arg.subs(rel, subs_options::no_pattern);
1311         if (!(arg_pt).info(info_flags::real))
1312                 throw do_taylor();     // Im(x) != 0
1313         if ((arg_pt).info(info_flags::real) && abs(arg_pt)<_ex1)
1314                 throw do_taylor();     // Im(x) == 0, but abs(x)<1
1315         // care for the poles, using the defining formula for atanh()...
1316         if (arg_pt.is_equal(_ex1) || arg_pt.is_equal(_ex_1))
1317                 return ((log(_ex1+arg)-log(_ex1-arg))*_ex1_2).series(rel, order, options);
1318         // ...and the branch cuts (the discontinuity at the cut being just I*Pi)
1319         if (!(options & series_options::suppress_branchcut)) {
1320                 // method:
1321                 // This is the branch cut: assemble the primitive series manually and
1322                 // then add the corresponding complex step function.
1323                 const symbol &s = ex_to<symbol>(rel.lhs());
1324                 const ex &point = rel.rhs();
1325                 const symbol foo;
1326                 const ex replarg = series(atanh(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
1327                 ex Order0correction = replarg.op(0)+csgn(I*arg)*Pi*I*_ex1_2;
1328                 if (arg_pt<_ex0)
1329                         Order0correction += log((arg_pt+_ex_1)/(arg_pt+_ex1))*_ex1_2;
1330                 else
1331                         Order0correction += log((arg_pt+_ex1)/(arg_pt+_ex_1))*_ex_1_2;
1332                 epvector seq;
1333                 seq.push_back(expair(Order0correction, _ex0));
1334                 seq.push_back(expair(Order(_ex1), order));
1335                 return series(replarg - pseries(rel, seq), rel, order);
1336         }
1337         throw do_taylor();
1338 }
1339
1340 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
1341                          evalf_func(atanh_evalf).
1342                          derivative_func(atanh_deriv).
1343                          series_func(atanh_series));
1344
1345
1346 } // namespace GiNaC