[7bf145] | 1 | /*****************************************************************************\ |
---|
| 2 | * Computer Algebra System SINGULAR |
---|
| 3 | \*****************************************************************************/ |
---|
| 4 | /** @file DegreePattern.cc |
---|
| 5 | * |
---|
| 6 | * This file provides functions for manipulating DegreePatterns |
---|
| 7 | * |
---|
| 8 | * @author Martin Lee |
---|
| 9 | * |
---|
| 10 | * @internal @version \$Id$ |
---|
| 11 | * |
---|
| 12 | **/ |
---|
| 13 | /*****************************************************************************/ |
---|
| 14 | |
---|
| 15 | #include <config.h> |
---|
| 16 | |
---|
| 17 | #include "DegreePattern.h" |
---|
| 18 | #include "cf_iter.h" |
---|
| 19 | #include "ftmpl_functions.h" |
---|
| 20 | #include "gfops.h" |
---|
| 21 | |
---|
[d52c12] | 22 | |
---|
[7bf145] | 23 | DegreePattern::DegreePattern (const CFList& l) |
---|
| 24 | { |
---|
| 25 | m_data = NULL; |
---|
| 26 | |
---|
| 27 | if (l.length() == 0) |
---|
| 28 | m_data = new Pattern(); |
---|
| 29 | else |
---|
| 30 | { |
---|
| 31 | |
---|
| 32 | Variable x= Variable (1); |
---|
| 33 | int p= getCharacteristic(); |
---|
| 34 | int d= getGFDegree(); |
---|
| 35 | char cGFName= gf_name; |
---|
| 36 | setCharacteristic(0); |
---|
| 37 | CanonicalForm buf= 1; |
---|
| 38 | CFListIterator k= l; |
---|
| 39 | for (int i= 0; i < l.length(); i++, k++) |
---|
| 40 | buf *= (power (x, degree (k.getItem(), x)) + 1); |
---|
| 41 | |
---|
| 42 | int j= 0; |
---|
| 43 | for (CFIterator i= buf; i.hasTerms(); i++, j++) |
---|
| 44 | ; |
---|
| 45 | |
---|
| 46 | ASSERT ( j > 1, "j > 1 expected" ); |
---|
| 47 | |
---|
| 48 | m_data = new Pattern( j - 1 ); |
---|
| 49 | |
---|
| 50 | int i= 0; |
---|
| 51 | for (CFIterator m = buf; i < getLength(); i++, m++) |
---|
| 52 | (*this) [i]= m.exp(); |
---|
| 53 | |
---|
| 54 | if (d > 1) |
---|
| 55 | setCharacteristic (p, d, cGFName); |
---|
| 56 | else |
---|
| 57 | setCharacteristic (p); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | |
---|
[d52c12] | 62 | void DegreePattern::intersect (const DegreePattern& degPat) |
---|
[7bf145] | 63 | { |
---|
| 64 | if (degPat.getLength() < getLength()) |
---|
| 65 | { |
---|
| 66 | DegreePattern bufDeg= *this; |
---|
| 67 | *this= degPat; |
---|
| 68 | return (*this).intersect (bufDeg); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | int count= 0; |
---|
| 72 | int length= tmin (getLength(), degPat.getLength()); |
---|
| 73 | int* buf= new int [length]; |
---|
| 74 | for (int i= 0; i < length; i++) |
---|
| 75 | { |
---|
| 76 | if (degPat.find ((*this)[i])) |
---|
| 77 | { |
---|
| 78 | buf[i]= (*this)[i]; |
---|
| 79 | count++; |
---|
| 80 | } |
---|
| 81 | else |
---|
| 82 | buf[i]= -1; |
---|
| 83 | } |
---|
| 84 | ASSERT ( count > 0, "count > 0 expected" ); |
---|
| 85 | |
---|
| 86 | init (count); |
---|
| 87 | count= 0; |
---|
| 88 | for (int i= 0; i < length; i++) |
---|
| 89 | { |
---|
| 90 | if (buf[i] != -1) |
---|
| 91 | { |
---|
| 92 | (*this) [count]= buf[i]; |
---|
| 93 | count++; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | delete[] buf; |
---|
| 97 | } |
---|
| 98 | |
---|
[d52c12] | 99 | void DegreePattern::refine () |
---|
[7bf145] | 100 | { |
---|
| 101 | if (getLength() <= 1) |
---|
| 102 | return; |
---|
| 103 | int count= 0; |
---|
| 104 | int* buf= new int [getLength()]; |
---|
| 105 | int d= (*this) [0]; |
---|
| 106 | int pos; |
---|
| 107 | for (int i= 0; i < getLength(); i++) |
---|
| 108 | buf[i]= -1; |
---|
| 109 | for (int i= 1; i < getLength(); i++) |
---|
| 110 | { |
---|
| 111 | pos= (*this).find (d - (*this)[i]); |
---|
| 112 | if (pos) |
---|
| 113 | { |
---|
| 114 | buf[i]= (*this)[i]; |
---|
| 115 | count++; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | buf[0]= d; |
---|
| 119 | count++; |
---|
| 120 | if (count == getLength()) |
---|
| 121 | { |
---|
| 122 | return; |
---|
| 123 | } |
---|
| 124 | int length= getLength(); |
---|
| 125 | |
---|
| 126 | ASSERT ( count > 0, "count > 0 expected" ); |
---|
| 127 | init (count); |
---|
| 128 | count= 0; |
---|
| 129 | for (int i= 0; i < length; i++) |
---|
| 130 | { |
---|
| 131 | if (buf[i] != -1) |
---|
| 132 | { |
---|
| 133 | (*this)[count]= buf[i]; |
---|
| 134 | count++; |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | delete[] buf; |
---|
| 139 | return; |
---|
| 140 | } |
---|
| 141 | |
---|