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