1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file facFactorize.h |
---|
5 | * |
---|
6 | * multivariate factorization over Q(a) |
---|
7 | * |
---|
8 | * @author Martin Lee |
---|
9 | * |
---|
10 | * @internal @version \$Id$ |
---|
11 | * |
---|
12 | **/ |
---|
13 | /*****************************************************************************/ |
---|
14 | |
---|
15 | #ifndef FAC_FACTORIZE_H |
---|
16 | #define FAC_FACTORIZE_H |
---|
17 | |
---|
18 | // #include "config.h" |
---|
19 | |
---|
20 | #include "facBivar.h" |
---|
21 | #include "facFqBivarUtil.h" |
---|
22 | |
---|
23 | /// Factorization over Q (a) |
---|
24 | /// |
---|
25 | /// @return @a multiFactorize returns a factorization of F |
---|
26 | CFList |
---|
27 | multiFactorize (const CanonicalForm& F, ///< [in] poly to be factored |
---|
28 | const Variable& v ///< [in] some algebraic variable |
---|
29 | ); |
---|
30 | |
---|
31 | /// factorize a squarefree multivariate polynomial over \f$ Q(\alpha) \f$ |
---|
32 | /// |
---|
33 | /// @return @a ratSqrfFactorize returns a list of monic factors, the first |
---|
34 | /// element is the leading coefficient. |
---|
35 | #ifdef HAVE_NTL |
---|
36 | inline |
---|
37 | CFList |
---|
38 | ratSqrfFactorize (const CanonicalForm & G, ///<[in] a multivariate poly |
---|
39 | const Variable& v ///<[in] algebraic variable |
---|
40 | ) |
---|
41 | { |
---|
42 | if (getNumVars (G) == 2) |
---|
43 | return ratBiSqrfFactorize (G, v); |
---|
44 | CanonicalForm F= G; |
---|
45 | if (isOn (SW_RATIONAL)) |
---|
46 | F *= bCommonDen (F); |
---|
47 | CFList result= multiFactorize (F, v); |
---|
48 | if (isOn (SW_RATIONAL)) |
---|
49 | { |
---|
50 | normalize (result); |
---|
51 | result.insert (Lc(F)); |
---|
52 | } |
---|
53 | return result; |
---|
54 | } |
---|
55 | |
---|
56 | /// factorize a multivariate polynomial over \f$ Q(\alpha) \f$ |
---|
57 | /// |
---|
58 | /// @return @a ratFactorize returns a list of monic factors with |
---|
59 | /// multiplicity, the first element is the leading coefficient. |
---|
60 | inline |
---|
61 | CFFList |
---|
62 | ratFactorize (const CanonicalForm& G, ///<[in] a multivariate poly |
---|
63 | const Variable& v, ///<[in] algebraic variable |
---|
64 | bool substCheck= true ///<[in] enables substitute check |
---|
65 | ) |
---|
66 | { |
---|
67 | if (getNumVars (G) == 2) |
---|
68 | { |
---|
69 | CFFList result= ratBiFactorize (G,v); |
---|
70 | return result; |
---|
71 | } |
---|
72 | CanonicalForm F= G; |
---|
73 | |
---|
74 | if (substCheck) |
---|
75 | { |
---|
76 | bool foundOne= false; |
---|
77 | int * substDegree= new int [F.level()]; |
---|
78 | for (int i= 1; i <= F.level(); i++) |
---|
79 | { |
---|
80 | if (degree (F, i) > 0) |
---|
81 | { |
---|
82 | substDegree[i-1]= substituteCheck (F, Variable (i)); |
---|
83 | if (substDegree [i-1] > 1) |
---|
84 | { |
---|
85 | foundOne= true; |
---|
86 | subst (F, F, substDegree[i-1], Variable (i)); |
---|
87 | } |
---|
88 | } |
---|
89 | else |
---|
90 | substDegree[i-1]= -1; |
---|
91 | } |
---|
92 | if (foundOne) |
---|
93 | { |
---|
94 | CFFList result= ratFactorize (F, v, false); |
---|
95 | CFFList newResult, tmp; |
---|
96 | CanonicalForm tmp2; |
---|
97 | newResult.insert (result.getFirst()); |
---|
98 | result.removeFirst(); |
---|
99 | for (CFFListIterator i= result; i.hasItem(); i++) |
---|
100 | { |
---|
101 | tmp2= i.getItem().factor(); |
---|
102 | for (int j= 1; j <= G.level(); j++) |
---|
103 | { |
---|
104 | if (substDegree[j-1] > 1) |
---|
105 | tmp2= reverseSubst (tmp2, substDegree[j-1], Variable (j)); |
---|
106 | } |
---|
107 | tmp= ratFactorize (tmp2, v, false); |
---|
108 | tmp.removeFirst(); |
---|
109 | for (CFFListIterator j= tmp; j.hasItem(); j++) |
---|
110 | newResult.append (CFFactor (j.getItem().factor(), |
---|
111 | j.getItem().exp()*i.getItem().exp())); |
---|
112 | } |
---|
113 | delete [] substDegree; |
---|
114 | return newResult; |
---|
115 | } |
---|
116 | delete [] substDegree; |
---|
117 | } |
---|
118 | |
---|
119 | CanonicalForm LcF= Lc (F); |
---|
120 | if (isOn (SW_RATIONAL)) |
---|
121 | F *= bCommonDen (F); |
---|
122 | |
---|
123 | CFFList result; |
---|
124 | CFFList sqrfFactors= sqrFree (F); |
---|
125 | for (CFFListIterator i= sqrfFactors; i.hasItem(); i++) |
---|
126 | { |
---|
127 | CFList tmp= ratSqrfFactorize (i.getItem().factor(), v); |
---|
128 | for (CFListIterator j= tmp; j.hasItem(); j++) |
---|
129 | { |
---|
130 | if (j.getItem().inCoeffDomain()) continue; |
---|
131 | result.append (CFFactor (j.getItem(), i.getItem().exp())); |
---|
132 | } |
---|
133 | } |
---|
134 | if (isOn (SW_RATIONAL)) |
---|
135 | { |
---|
136 | normalize (result); |
---|
137 | result.insert (CFFactor (LcF, 1)); |
---|
138 | } |
---|
139 | return result; |
---|
140 | } |
---|
141 | #endif |
---|
142 | |
---|
143 | #endif |
---|
144 | |
---|