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