1 | /*****************************************************************************\ |
---|
2 | * Computer Algebra System SINGULAR |
---|
3 | \*****************************************************************************/ |
---|
4 | /** @file facFqFactorizeUtil.cc |
---|
5 | * |
---|
6 | * This file provides utility functions for multivariate factorization |
---|
7 | * |
---|
8 | * @author Martin Lee |
---|
9 | * |
---|
10 | **/ |
---|
11 | /*****************************************************************************/ |
---|
12 | |
---|
13 | #include "config.h" |
---|
14 | |
---|
15 | #include "canonicalform.h" |
---|
16 | #include "cf_map.h" |
---|
17 | |
---|
18 | static inline |
---|
19 | void appendSwap (CFList& factors1, const CFList& factors2, const int |
---|
20 | swapLevel1, const int swapLevel2, const Variable& x) |
---|
21 | { |
---|
22 | for (CFListIterator i= factors2; i.hasItem(); i++) |
---|
23 | { |
---|
24 | if (swapLevel1) |
---|
25 | { |
---|
26 | if (swapLevel2) |
---|
27 | factors1.append (swapvar (swapvar (i.getItem(), x, |
---|
28 | Variable (swapLevel2)), Variable (swapLevel1), x)); |
---|
29 | else |
---|
30 | factors1.append (swapvar (i.getItem(), Variable (swapLevel1), x)); |
---|
31 | } |
---|
32 | else |
---|
33 | { |
---|
34 | if (swapLevel2) |
---|
35 | factors1.append (swapvar (i.getItem(), x, Variable (swapLevel2))); |
---|
36 | else |
---|
37 | factors1.append (i.getItem()); |
---|
38 | } |
---|
39 | } |
---|
40 | return; |
---|
41 | } |
---|
42 | |
---|
43 | |
---|
44 | void swap (CFList& factors, const int swapLevel1, const int swapLevel2, const |
---|
45 | Variable& x) |
---|
46 | { |
---|
47 | for (CFListIterator i= factors; i.hasItem(); i++) |
---|
48 | { |
---|
49 | if (swapLevel1) |
---|
50 | { |
---|
51 | if (swapLevel2) |
---|
52 | i.getItem()= swapvar (swapvar (i.getItem(), x, Variable (swapLevel2)), |
---|
53 | Variable (swapLevel1), x); |
---|
54 | else |
---|
55 | i.getItem()= swapvar (i.getItem(), Variable (swapLevel1), x); |
---|
56 | } |
---|
57 | else |
---|
58 | { |
---|
59 | if (swapLevel2) |
---|
60 | i.getItem()= swapvar (i.getItem(), x, Variable (swapLevel2)); |
---|
61 | } |
---|
62 | } |
---|
63 | return; |
---|
64 | } |
---|
65 | |
---|
66 | void appendSwapDecompress (CFList& factors1, const CFList& factors2, |
---|
67 | const CFMap& N, const int swapLevel, const |
---|
68 | Variable& x) |
---|
69 | { |
---|
70 | for (CFListIterator i= factors1; i.hasItem(); i++) |
---|
71 | { |
---|
72 | if (swapLevel) |
---|
73 | i.getItem()= swapvar (i.getItem(), Variable (swapLevel), x); |
---|
74 | i.getItem()= N(i.getItem()); |
---|
75 | } |
---|
76 | for (CFListIterator i= factors2; i.hasItem(); i++) |
---|
77 | { |
---|
78 | if (!i.getItem().inCoeffDomain()) |
---|
79 | factors1.append (N (i.getItem())); |
---|
80 | } |
---|
81 | return; |
---|
82 | } |
---|
83 | |
---|
84 | void appendSwapDecompress (CFList& factors1, const CFList& factors2, |
---|
85 | const CFMap& N, const int swapLevel1, |
---|
86 | const int swapLevel2, const Variable& x) |
---|
87 | { |
---|
88 | for (CFListIterator i= factors1; i.hasItem(); i++) |
---|
89 | { |
---|
90 | if (swapLevel1) |
---|
91 | { |
---|
92 | if (swapLevel2) |
---|
93 | i.getItem()= |
---|
94 | N (swapvar (swapvar (i.getItem(), Variable (swapLevel2), x), x, |
---|
95 | Variable (swapLevel1))); |
---|
96 | else |
---|
97 | i.getItem()= N (swapvar (i.getItem(), x, Variable (swapLevel1))); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | if (swapLevel2) |
---|
102 | i.getItem()= N (swapvar (i.getItem(), Variable (swapLevel2), x)); |
---|
103 | else |
---|
104 | i.getItem()= N (i.getItem()); |
---|
105 | } |
---|
106 | } |
---|
107 | for (CFListIterator i= factors2; i.hasItem(); i++) |
---|
108 | { |
---|
109 | if (!i.getItem().inCoeffDomain()) |
---|
110 | factors1.append (N (i.getItem())); |
---|
111 | } |
---|
112 | return; |
---|
113 | } |
---|
114 | |
---|
115 | int* liftingBounds (const CanonicalForm& A, const int& bivarLiftBound) |
---|
116 | { |
---|
117 | int j= A.level() - 1; |
---|
118 | int* liftBounds= new int [j]; |
---|
119 | liftBounds[0]= bivarLiftBound; |
---|
120 | for (int i= 1; i < j; i++) |
---|
121 | { |
---|
122 | liftBounds[i]= degree (A, Variable (i + 2)) + 1 + |
---|
123 | degree (LC (A, 1), Variable (i + 2)); |
---|
124 | } |
---|
125 | return liftBounds; |
---|
126 | } |
---|
127 | |
---|
128 | CanonicalForm shift2Zero (const CanonicalForm& F, CFList& Feval, const CFList& evaluation, int l) |
---|
129 | { |
---|
130 | CanonicalForm A= F; |
---|
131 | int k= evaluation.length() + l - 1; |
---|
132 | for (CFListIterator i= evaluation; i.hasItem(); i++, k--) |
---|
133 | A= A (Variable (k) + i.getItem(), k); |
---|
134 | CanonicalForm buf= A; |
---|
135 | Feval= CFList(); |
---|
136 | Feval.append (buf); |
---|
137 | for (k= A.level(); k > 2; k--) |
---|
138 | { |
---|
139 | buf= mod (buf, Variable (k)); |
---|
140 | Feval.insert (buf); |
---|
141 | } |
---|
142 | return A; |
---|
143 | } |
---|
144 | |
---|
145 | CanonicalForm reverseShift (const CanonicalForm& F, const CFList& evaluation, int l) |
---|
146 | { |
---|
147 | int k= evaluation.length() + l - 1; |
---|
148 | CanonicalForm result= F; |
---|
149 | CFListIterator j= evaluation; |
---|
150 | for (int i= k; j.hasItem() && (i > l - 1); i--, j++) |
---|
151 | { |
---|
152 | if (F.level() < i) |
---|
153 | continue; |
---|
154 | result= result (Variable (i) - j.getItem(), i); |
---|
155 | } |
---|
156 | return result; |
---|
157 | } |
---|
158 | |
---|
159 | |
---|