]> www.ginac.de Git - cln.git/blob - src/rational/algebraic/cl_RA_rootp_I.cc
Initial revision
[cln.git] / src / rational / algebraic / cl_RA_rootp_I.cc
1 // rootp().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_rational.h"
8
9
10 // Implementation.
11
12 #include "cl_RA.h"
13 #include "cl_integer.h"
14
15 cl_boolean rootp (const cl_RA& x, const cl_I& n, cl_RA* w)
16 {
17 // Methode:
18 // Bei Integers: klar.
19 // Bei Brüchen a/b : muß a=c^n und b=d^n sein. Dann ist die Wurzel = c/d
20 // (mit ggT(c,d)=1 und d>1).
21         if (integerp(x)) {
22                 DeclareType(cl_I,x);
23                 return rootp(x,n,(cl_I*)w);
24         } else {
25         // x ist Ratio
26         DeclareType(cl_RT,x);
27         var const cl_I& b = denominator(x);
28         var cl_I d;
29         if (!rootp(b,n,&d)) // Nenner auf n-te Potenz testen
30                 return cl_false;
31         var const cl_I& a = numerator(x);
32         var cl_I c;
33         if (!rootp(a,n,&c)) // Zähler auf n-te Potenz testen
34                 return cl_false;
35         // beides n-te Potenzen -> Quotient der Wurzeln bilden
36         *w = I_I_to_RT(c,d); return cl_true;
37 }}