]> www.ginac.de Git - cln.git/blob - src/polynomial/misc/cl_UP_deriv.cc
* src/real/input/cl_R_read.cc, src/complex/input/cl_N_read.cc:
[cln.git] / src / polynomial / misc / cl_UP_deriv.cc
1 // deriv().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/univpoly.h"
8
9
10 // Implementation.
11
12 #include "cln/integer.h"
13
14 namespace cln {
15
16 const cl_UP deriv (const cl_UP& x)
17 {
18         // Method:
19         // Write x = a0 T^0 + ... + an T^n.
20         // Then deriv(x) = 1*a1 T^0 + ... + n*an T^(n-1)  (= 0 if n <= 0).
21         var cl_univpoly_ring UPR = x.ring();
22         var sintL n = degree(x);
23         if (n <= 0)
24                 return UPR->zero();
25         else {
26                 var cl_UP y = UPR->create(n-1);
27                 for ( ; n > 0; n--)
28                         y.set_coeff(n-1, n * coeff(x,n));
29                 y.finalize();
30                 return y;
31         }
32 }
33
34 }  // namespace cln