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