1 | // -*- c++ -*- |
---|
2 | //***************************************************************************** |
---|
3 | /** @file facAlgExt.cc |
---|
4 | * |
---|
5 | * @author Martin Lee |
---|
6 | * @date |
---|
7 | * |
---|
8 | * Univariate factorization over algebraic extension of Q using Trager's |
---|
9 | * algorithm |
---|
10 | * |
---|
11 | * @par Copyright: |
---|
12 | * (c) by The SINGULAR Team, see LICENSE file |
---|
13 | * |
---|
14 | * @internal |
---|
15 | * @version \$Id$ |
---|
16 | * |
---|
17 | **/ |
---|
18 | //***************************************************************************** |
---|
19 | |
---|
20 | #include <config.h> |
---|
21 | |
---|
22 | #include "assert.h" |
---|
23 | #include "debug.h" |
---|
24 | #include "timing.h" |
---|
25 | |
---|
26 | #include "canonicalform.h" |
---|
27 | #include "cf_random.h" |
---|
28 | #include "cf_algorithm.h" |
---|
29 | #include "facFqBivarUtil.h" |
---|
30 | #include "facAlgExt.h" |
---|
31 | #include "cfModResultant.h" |
---|
32 | |
---|
33 | // squarefree part of F |
---|
34 | CanonicalForm |
---|
35 | uniSqrfPart (const CanonicalForm& F) |
---|
36 | { |
---|
37 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
38 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
39 | CanonicalForm G= deriv (F, F.mvar()); |
---|
40 | G= gcd (F, G); |
---|
41 | return F/G; |
---|
42 | } |
---|
43 | |
---|
44 | // i is an integer such that Norm (F (x-i*alpha)) is squarefree |
---|
45 | CanonicalForm sqrfNorm (const CanonicalForm& F, const Variable& alpha, int& i) |
---|
46 | { |
---|
47 | Variable x= Variable (F.level() + 1); |
---|
48 | Variable y= F.mvar(); |
---|
49 | CanonicalForm g= F (x, alpha); |
---|
50 | CanonicalForm mipo= getMipo (alpha); |
---|
51 | mipo= mipo (x, alpha); |
---|
52 | |
---|
53 | int degg= degree (g); |
---|
54 | int degmipo= degree (mipo); |
---|
55 | CanonicalForm norm; |
---|
56 | if (degg >= 8 || degmipo >= 8) |
---|
57 | norm= resultantZ (g, mipo, x); |
---|
58 | else |
---|
59 | norm= resultant (g, mipo, x); |
---|
60 | |
---|
61 | i= 0; |
---|
62 | int k; |
---|
63 | if (degree (gcd (deriv (norm, y), norm)) <= 0) |
---|
64 | return norm; |
---|
65 | i= 1; |
---|
66 | do |
---|
67 | { |
---|
68 | k= 1; |
---|
69 | while (k < 3) |
---|
70 | { |
---|
71 | if (k == 1) |
---|
72 | { |
---|
73 | g= F (y - i*alpha, y); |
---|
74 | if (degg >= 8 || degmipo >= 8) |
---|
75 | norm= resultantZ (g (x, alpha), mipo, x); |
---|
76 | else |
---|
77 | norm= resultant (g (x, alpha), mipo, x); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | g= F (y + i*alpha, y); |
---|
82 | if (degg >= 8 || degmipo >= 8) |
---|
83 | norm= resultantZ (g (x, alpha), mipo, x); |
---|
84 | else |
---|
85 | norm= resultant (g (x, alpha), mipo, x); |
---|
86 | } |
---|
87 | if (degree (gcd (deriv (norm, y), norm)) <= 0) |
---|
88 | { |
---|
89 | if (k == 2) |
---|
90 | i= -i; |
---|
91 | return norm; |
---|
92 | } |
---|
93 | k++; |
---|
94 | } |
---|
95 | i++; |
---|
96 | } while (1); |
---|
97 | } |
---|
98 | |
---|
99 | CFList |
---|
100 | AlgExtSqrfFactorize (const CanonicalForm& F, const Variable& alpha) |
---|
101 | { |
---|
102 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
103 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
104 | |
---|
105 | bool save_rat=!isOn (SW_RATIONAL); |
---|
106 | On (SW_RATIONAL); |
---|
107 | CanonicalForm f= F*bCommonDen (F); |
---|
108 | int shift; |
---|
109 | CanonicalForm norm= sqrfNorm (f, alpha, shift); |
---|
110 | ASSERT (degree (norm, alpha) <= 0, "wrong norm computed"); |
---|
111 | CFFList normFactors= factorize (norm); //maybe compute norm (not necessarily squarefree), split f and procede recursively |
---|
112 | CFList factors; |
---|
113 | if (normFactors.length() <= 2) |
---|
114 | { |
---|
115 | if (save_rat) Off(SW_RATIONAL); |
---|
116 | return CFList (F); |
---|
117 | } |
---|
118 | |
---|
119 | normFactors.removeFirst(); |
---|
120 | CanonicalForm buf; |
---|
121 | if (shift != 0) |
---|
122 | buf= f (f.mvar() - shift*alpha, f.mvar()); |
---|
123 | else |
---|
124 | buf= f; |
---|
125 | CanonicalForm factor; |
---|
126 | for (CFFListIterator i= normFactors; i.hasItem(); i++) |
---|
127 | { |
---|
128 | ASSERT (i.getItem().exp() == 1, "norm not squarefree"); |
---|
129 | factor= gcd (buf, i.getItem().factor()); |
---|
130 | buf /= factor; |
---|
131 | if (shift != 0) |
---|
132 | factor= factor (f.mvar() + shift*alpha, f.mvar()); |
---|
133 | factors.append (factor); |
---|
134 | } |
---|
135 | ASSERT (degree (buf) <= 0, "incomplete factorization"); |
---|
136 | if (save_rat) Off(SW_RATIONAL); |
---|
137 | return factors; |
---|
138 | } |
---|
139 | |
---|
140 | CFFList |
---|
141 | AlgExtFactorize (const CanonicalForm& F, const Variable& alpha) |
---|
142 | { |
---|
143 | ASSERT (F.isUnivariate(), "univariate input expected"); |
---|
144 | ASSERT (getCharacteristic() == 0, "characteristic 0 expected"); |
---|
145 | |
---|
146 | |
---|
147 | if (F.inCoeffDomain()) |
---|
148 | return CFFList (CFFactor (F, 1)); |
---|
149 | |
---|
150 | CanonicalForm sqrf= uniSqrfPart (F); |
---|
151 | CFList sqrfFactors= AlgExtSqrfFactorize (sqrf, alpha); |
---|
152 | |
---|
153 | if (!isOn (SW_RATIONAL)) |
---|
154 | On (SW_RATIONAL); |
---|
155 | CanonicalForm buf= F/Lc (F); |
---|
156 | CFFList factors; |
---|
157 | int multi; |
---|
158 | for (CFListIterator i= sqrfFactors; i.hasItem(); i++) |
---|
159 | { |
---|
160 | multi= 0; |
---|
161 | i.getItem() /= Lc (i.getItem()); //make factors monic |
---|
162 | while (fdivides (i.getItem(), buf)) |
---|
163 | { |
---|
164 | buf /= i.getItem(); |
---|
165 | multi++; |
---|
166 | } |
---|
167 | factors.append (CFFactor (i.getItem(), multi)); |
---|
168 | } |
---|
169 | factors.insert (CFFactor (Lc(F), 1)); |
---|
170 | ASSERT (degree (buf) <= 0, "bug in AlgExtFactorize"); |
---|
171 | return factors; |
---|
172 | } |
---|
173 | |
---|