Really fixed the atan2(-Pi, 0) bug.
[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-2010 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 "inifcns.h"
25 #include "ex.h"
26 #include "constant.h"
27 #include "numeric.h"
28 #include "power.h"
29 #include "operators.h"
30 #include "relational.h"
31 #include "symbol.h"
32 #include "pseries.h"
33 #include "utils.h"
34
35 #include <stdexcept>
36 #include <vector>
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                 // atan2(0, 0) -> 0
826                 if (x.is_zero())
827                         return _ex0;
828
829                 // atan2(0, x), x real and positive -> 0
830                 if (x.info(info_flags::positive))
831                         return _ex0;
832
833                 // atan2(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                 // atan2(y, 0), y real and positive -> Pi/2
841                 if (y.info(info_flags::positive))
842                         return _ex1_2*Pi;
843
844                 // atan2(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                 // atan2(y, y), y real and positive -> Pi/4
852                 if (y.info(info_flags::positive))
853                         return _ex1_4*Pi;
854
855                 // atan2(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                 // atan2(y, -y), y real and positive -> 3*Pi/4
863                 if (y.info(info_flags::positive))
864                         return numeric(3, 4)*Pi;
865
866                 // atan2(y, -y), y real and negative -> -Pi/4
867                 if (y.info(info_flags::negative))
868                         return _ex_1_4*Pi;
869         }
870
871         // atan2(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         // atan2(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
881                 if (x.info(info_flags::negative)) {
882                         if (y.info(info_flags::positive))
883                                 return atan(y/x)+Pi;
884                         if (y.info(info_flags::negative))
885                                 return atan(y/x)-Pi;
886                 }
887         }
888
889         return atan2(y, x).hold();
890 }    
891
892 static ex atan2_deriv(const ex & y, const ex & x, unsigned deriv_param)
893 {
894         GINAC_ASSERT(deriv_param<2);
895         
896         if (deriv_param==0) {
897                 // d/dy atan2(y,x)
898                 return x*power(power(x,_ex2)+power(y,_ex2),_ex_1);
899         }
900         // d/dx atan2(y,x)
901         return -y*power(power(x,_ex2)+power(y,_ex2),_ex_1);
902 }
903
904 REGISTER_FUNCTION(atan2, eval_func(atan2_eval).
905                          evalf_func(atan2_evalf).
906                          derivative_func(atan2_deriv));
907
908 //////////
909 // hyperbolic sine (trigonometric function)
910 //////////
911
912 static ex sinh_evalf(const ex & x)
913 {
914         if (is_exactly_a<numeric>(x))
915                 return sinh(ex_to<numeric>(x));
916         
917         return sinh(x).hold();
918 }
919
920 static ex sinh_eval(const ex & x)
921 {
922         if (x.info(info_flags::numeric)) {
923
924                 // sinh(0) -> 0
925                 if (x.is_zero())
926                         return _ex0;        
927
928                 // sinh(float) -> float
929                 if (!x.info(info_flags::crational))
930                         return sinh(ex_to<numeric>(x));
931
932                 // sinh() is odd
933                 if (x.info(info_flags::negative))
934                         return -sinh(-x);
935         }
936         
937         if ((x/Pi).info(info_flags::numeric) &&
938                 ex_to<numeric>(x/Pi).real().is_zero())  // sinh(I*x) -> I*sin(x)
939                 return I*sin(x/I);
940         
941         if (is_exactly_a<function>(x)) {
942                 const ex &t = x.op(0);
943
944                 // sinh(asinh(x)) -> x
945                 if (is_ex_the_function(x, asinh))
946                         return t;
947
948                 // sinh(acosh(x)) -> sqrt(x-1) * sqrt(x+1)
949                 if (is_ex_the_function(x, acosh))
950                         return sqrt(t-_ex1)*sqrt(t+_ex1);
951
952                 // sinh(atanh(x)) -> x/sqrt(1-x^2)
953                 if (is_ex_the_function(x, atanh))
954                         return t*power(_ex1-power(t,_ex2),_ex_1_2);
955         }
956         
957         return sinh(x).hold();
958 }
959
960 static ex sinh_deriv(const ex & x, unsigned deriv_param)
961 {
962         GINAC_ASSERT(deriv_param==0);
963         
964         // d/dx sinh(x) -> cosh(x)
965         return cosh(x);
966 }
967
968 static ex sinh_real_part(const ex & x)
969 {
970         return sinh(GiNaC::real_part(x))*cos(GiNaC::imag_part(x));
971 }
972
973 static ex sinh_imag_part(const ex & x)
974 {
975         return cosh(GiNaC::real_part(x))*sin(GiNaC::imag_part(x));
976 }
977
978 REGISTER_FUNCTION(sinh, eval_func(sinh_eval).
979                         evalf_func(sinh_evalf).
980                         derivative_func(sinh_deriv).
981                         real_part_func(sinh_real_part).
982                         imag_part_func(sinh_imag_part).
983                         latex_name("\\sinh"));
984
985 //////////
986 // hyperbolic cosine (trigonometric function)
987 //////////
988
989 static ex cosh_evalf(const ex & x)
990 {
991         if (is_exactly_a<numeric>(x))
992                 return cosh(ex_to<numeric>(x));
993         
994         return cosh(x).hold();
995 }
996
997 static ex cosh_eval(const ex & x)
998 {
999         if (x.info(info_flags::numeric)) {
1000
1001                 // cosh(0) -> 1
1002                 if (x.is_zero())
1003                         return _ex1;
1004
1005                 // cosh(float) -> float
1006                 if (!x.info(info_flags::crational))
1007                         return cosh(ex_to<numeric>(x));
1008
1009                 // cosh() is even
1010                 if (x.info(info_flags::negative))
1011                         return cosh(-x);
1012         }
1013         
1014         if ((x/Pi).info(info_flags::numeric) &&
1015                 ex_to<numeric>(x/Pi).real().is_zero())  // cosh(I*x) -> cos(x)
1016                 return cos(x/I);
1017         
1018         if (is_exactly_a<function>(x)) {
1019                 const ex &t = x.op(0);
1020
1021                 // cosh(acosh(x)) -> x
1022                 if (is_ex_the_function(x, acosh))
1023                         return t;
1024
1025                 // cosh(asinh(x)) -> sqrt(1+x^2)
1026                 if (is_ex_the_function(x, asinh))
1027                         return sqrt(_ex1+power(t,_ex2));
1028
1029                 // cosh(atanh(x)) -> 1/sqrt(1-x^2)
1030                 if (is_ex_the_function(x, atanh))
1031                         return power(_ex1-power(t,_ex2),_ex_1_2);
1032         }
1033         
1034         return cosh(x).hold();
1035 }
1036
1037 static ex cosh_deriv(const ex & x, unsigned deriv_param)
1038 {
1039         GINAC_ASSERT(deriv_param==0);
1040         
1041         // d/dx cosh(x) -> sinh(x)
1042         return sinh(x);
1043 }
1044
1045 static ex cosh_real_part(const ex & x)
1046 {
1047         return cosh(GiNaC::real_part(x))*cos(GiNaC::imag_part(x));
1048 }
1049
1050 static ex cosh_imag_part(const ex & x)
1051 {
1052         return sinh(GiNaC::real_part(x))*sin(GiNaC::imag_part(x));
1053 }
1054
1055 REGISTER_FUNCTION(cosh, eval_func(cosh_eval).
1056                         evalf_func(cosh_evalf).
1057                         derivative_func(cosh_deriv).
1058                         real_part_func(cosh_real_part).
1059                         imag_part_func(cosh_imag_part).
1060                         latex_name("\\cosh"));
1061
1062 //////////
1063 // hyperbolic tangent (trigonometric function)
1064 //////////
1065
1066 static ex tanh_evalf(const ex & x)
1067 {
1068         if (is_exactly_a<numeric>(x))
1069                 return tanh(ex_to<numeric>(x));
1070         
1071         return tanh(x).hold();
1072 }
1073
1074 static ex tanh_eval(const ex & x)
1075 {
1076         if (x.info(info_flags::numeric)) {
1077
1078                 // tanh(0) -> 0
1079                 if (x.is_zero())
1080                         return _ex0;
1081
1082                 // tanh(float) -> float
1083                 if (!x.info(info_flags::crational))
1084                         return tanh(ex_to<numeric>(x));
1085
1086                 // tanh() is odd
1087                 if (x.info(info_flags::negative))
1088                         return -tanh(-x);
1089         }
1090         
1091         if ((x/Pi).info(info_flags::numeric) &&
1092                 ex_to<numeric>(x/Pi).real().is_zero())  // tanh(I*x) -> I*tan(x);
1093                 return I*tan(x/I);
1094         
1095         if (is_exactly_a<function>(x)) {
1096                 const ex &t = x.op(0);
1097
1098                 // tanh(atanh(x)) -> x
1099                 if (is_ex_the_function(x, atanh))
1100                         return t;
1101
1102                 // tanh(asinh(x)) -> x/sqrt(1+x^2)
1103                 if (is_ex_the_function(x, asinh))
1104                         return t*power(_ex1+power(t,_ex2),_ex_1_2);
1105
1106                 // tanh(acosh(x)) -> sqrt(x-1)*sqrt(x+1)/x
1107                 if (is_ex_the_function(x, acosh))
1108                         return sqrt(t-_ex1)*sqrt(t+_ex1)*power(t,_ex_1);
1109         }
1110         
1111         return tanh(x).hold();
1112 }
1113
1114 static ex tanh_deriv(const ex & x, unsigned deriv_param)
1115 {
1116         GINAC_ASSERT(deriv_param==0);
1117         
1118         // d/dx tanh(x) -> 1-tanh(x)^2
1119         return _ex1-power(tanh(x),_ex2);
1120 }
1121
1122 static ex tanh_series(const ex &x,
1123                       const relational &rel,
1124                       int order,
1125                       unsigned options)
1126 {
1127         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
1128         // method:
1129         // Taylor series where there is no pole falls back to tanh_deriv.
1130         // On a pole simply expand sinh(x)/cosh(x).
1131         const ex x_pt = x.subs(rel, subs_options::no_pattern);
1132         if (!(2*I*x_pt/Pi).info(info_flags::odd))
1133                 throw do_taylor();  // caught by function::series()
1134         // if we got here we have to care for a simple pole
1135         return (sinh(x)/cosh(x)).series(rel, order, options);
1136 }
1137
1138 static ex tanh_real_part(const ex & x)
1139 {
1140         ex a = GiNaC::real_part(x);
1141         ex b = GiNaC::imag_part(x);
1142         return tanh(a)/(1+power(tanh(a),2)*power(tan(b),2));
1143 }
1144
1145 static ex tanh_imag_part(const ex & x)
1146 {
1147         ex a = GiNaC::real_part(x);
1148         ex b = GiNaC::imag_part(x);
1149         return tan(b)/(1+power(tanh(a),2)*power(tan(b),2));
1150 }
1151
1152 REGISTER_FUNCTION(tanh, eval_func(tanh_eval).
1153                         evalf_func(tanh_evalf).
1154                         derivative_func(tanh_deriv).
1155                         series_func(tanh_series).
1156                         real_part_func(tanh_real_part).
1157                         imag_part_func(tanh_imag_part).
1158                         latex_name("\\tanh"));
1159
1160 //////////
1161 // inverse hyperbolic sine (trigonometric function)
1162 //////////
1163
1164 static ex asinh_evalf(const ex & x)
1165 {
1166         if (is_exactly_a<numeric>(x))
1167                 return asinh(ex_to<numeric>(x));
1168         
1169         return asinh(x).hold();
1170 }
1171
1172 static ex asinh_eval(const ex & x)
1173 {
1174         if (x.info(info_flags::numeric)) {
1175
1176                 // asinh(0) -> 0
1177                 if (x.is_zero())
1178                         return _ex0;
1179
1180                 // asinh(float) -> float
1181                 if (!x.info(info_flags::crational))
1182                         return asinh(ex_to<numeric>(x));
1183
1184                 // asinh() is odd
1185                 if (x.info(info_flags::negative))
1186                         return -asinh(-x);
1187         }
1188         
1189         return asinh(x).hold();
1190 }
1191
1192 static ex asinh_deriv(const ex & x, unsigned deriv_param)
1193 {
1194         GINAC_ASSERT(deriv_param==0);
1195         
1196         // d/dx asinh(x) -> 1/sqrt(1+x^2)
1197         return power(_ex1+power(x,_ex2),_ex_1_2);
1198 }
1199
1200 REGISTER_FUNCTION(asinh, eval_func(asinh_eval).
1201                          evalf_func(asinh_evalf).
1202                          derivative_func(asinh_deriv));
1203
1204 //////////
1205 // inverse hyperbolic cosine (trigonometric function)
1206 //////////
1207
1208 static ex acosh_evalf(const ex & x)
1209 {
1210         if (is_exactly_a<numeric>(x))
1211                 return acosh(ex_to<numeric>(x));
1212         
1213         return acosh(x).hold();
1214 }
1215
1216 static ex acosh_eval(const ex & x)
1217 {
1218         if (x.info(info_flags::numeric)) {
1219
1220                 // acosh(0) -> Pi*I/2
1221                 if (x.is_zero())
1222                         return Pi*I*numeric(1,2);
1223
1224                 // acosh(1) -> 0
1225                 if (x.is_equal(_ex1))
1226                         return _ex0;
1227
1228                 // acosh(-1) -> Pi*I
1229                 if (x.is_equal(_ex_1))
1230                         return Pi*I;
1231
1232                 // acosh(float) -> float
1233                 if (!x.info(info_flags::crational))
1234                         return acosh(ex_to<numeric>(x));
1235
1236                 // acosh(-x) -> Pi*I-acosh(x)
1237                 if (x.info(info_flags::negative))
1238                         return Pi*I-acosh(-x);
1239         }
1240         
1241         return acosh(x).hold();
1242 }
1243
1244 static ex acosh_deriv(const ex & x, unsigned deriv_param)
1245 {
1246         GINAC_ASSERT(deriv_param==0);
1247         
1248         // d/dx acosh(x) -> 1/(sqrt(x-1)*sqrt(x+1))
1249         return power(x+_ex_1,_ex_1_2)*power(x+_ex1,_ex_1_2);
1250 }
1251
1252 REGISTER_FUNCTION(acosh, eval_func(acosh_eval).
1253                          evalf_func(acosh_evalf).
1254                          derivative_func(acosh_deriv));
1255
1256 //////////
1257 // inverse hyperbolic tangent (trigonometric function)
1258 //////////
1259
1260 static ex atanh_evalf(const ex & x)
1261 {
1262         if (is_exactly_a<numeric>(x))
1263                 return atanh(ex_to<numeric>(x));
1264         
1265         return atanh(x).hold();
1266 }
1267
1268 static ex atanh_eval(const ex & x)
1269 {
1270         if (x.info(info_flags::numeric)) {
1271
1272                 // atanh(0) -> 0
1273                 if (x.is_zero())
1274                         return _ex0;
1275
1276                 // atanh({+|-}1) -> throw
1277                 if (x.is_equal(_ex1) || x.is_equal(_ex_1))
1278                         throw (pole_error("atanh_eval(): logarithmic pole",0));
1279
1280                 // atanh(float) -> float
1281                 if (!x.info(info_flags::crational))
1282                         return atanh(ex_to<numeric>(x));
1283
1284                 // atanh() is odd
1285                 if (x.info(info_flags::negative))
1286                         return -atanh(-x);
1287         }
1288         
1289         return atanh(x).hold();
1290 }
1291
1292 static ex atanh_deriv(const ex & x, unsigned deriv_param)
1293 {
1294         GINAC_ASSERT(deriv_param==0);
1295         
1296         // d/dx atanh(x) -> 1/(1-x^2)
1297         return power(_ex1-power(x,_ex2),_ex_1);
1298 }
1299
1300 static ex atanh_series(const ex &arg,
1301                        const relational &rel,
1302                        int order,
1303                        unsigned options)
1304 {
1305         GINAC_ASSERT(is_a<symbol>(rel.lhs()));
1306         // method:
1307         // Taylor series where there is no pole or cut falls back to atanh_deriv.
1308         // There are two branch cuts, one runnig from 1 up the real axis and one
1309         // one running from -1 down the real axis.  The points 1 and -1 are poles
1310         // On the branch cuts and the poles series expand
1311         //     (log(1+x)-log(1-x))/2
1312         // instead.
1313         const ex arg_pt = arg.subs(rel, subs_options::no_pattern);
1314         if (!(arg_pt).info(info_flags::real))
1315                 throw do_taylor();     // Im(x) != 0
1316         if ((arg_pt).info(info_flags::real) && abs(arg_pt)<_ex1)
1317                 throw do_taylor();     // Im(x) == 0, but abs(x)<1
1318         // care for the poles, using the defining formula for atanh()...
1319         if (arg_pt.is_equal(_ex1) || arg_pt.is_equal(_ex_1))
1320                 return ((log(_ex1+arg)-log(_ex1-arg))*_ex1_2).series(rel, order, options);
1321         // ...and the branch cuts (the discontinuity at the cut being just I*Pi)
1322         if (!(options & series_options::suppress_branchcut)) {
1323                 // method:
1324                 // This is the branch cut: assemble the primitive series manually and
1325                 // then add the corresponding complex step function.
1326                 const symbol &s = ex_to<symbol>(rel.lhs());
1327                 const ex &point = rel.rhs();
1328                 const symbol foo;
1329                 const ex replarg = series(atanh(arg), s==foo, order).subs(foo==point, subs_options::no_pattern);
1330                 ex Order0correction = replarg.op(0)+csgn(I*arg)*Pi*I*_ex1_2;
1331                 if (arg_pt<_ex0)
1332                         Order0correction += log((arg_pt+_ex_1)/(arg_pt+_ex1))*_ex1_2;
1333                 else
1334                         Order0correction += log((arg_pt+_ex1)/(arg_pt+_ex_1))*_ex_1_2;
1335                 epvector seq;
1336                 seq.push_back(expair(Order0correction, _ex0));
1337                 seq.push_back(expair(Order(_ex1), order));
1338                 return series(replarg - pseries(rel, seq), rel, order);
1339         }
1340         throw do_taylor();
1341 }
1342
1343 REGISTER_FUNCTION(atanh, eval_func(atanh_eval).
1344                          evalf_func(atanh_evalf).
1345                          derivative_func(atanh_deriv).
1346                          series_func(atanh_series));
1347
1348
1349 } // namespace GiNaC