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 | |
---|
22 | inline |
---|
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 | |
---|
62 | inline int |
---|
63 | DegreePattern::find (const int x) const |
---|
64 | { |
---|
65 | if (getLength() == 0) return 0; |
---|
66 | for (int i= 0; i < getLength(); i++) |
---|
67 | if ((*this)[i] == x) return i + 1; |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | inline void |
---|
72 | DegreePattern::intersect (const DegreePattern& degPat) |
---|
73 | { |
---|
74 | if (degPat.getLength() < getLength()) |
---|
75 | { |
---|
76 | DegreePattern bufDeg= *this; |
---|
77 | *this= degPat; |
---|
78 | return (*this).intersect (bufDeg); |
---|
79 | } |
---|
80 | |
---|
81 | int count= 0; |
---|
82 | int length= tmin (getLength(), degPat.getLength()); |
---|
83 | int* buf= new int [length]; |
---|
84 | for (int i= 0; i < length; i++) |
---|
85 | { |
---|
86 | if (degPat.find ((*this)[i])) |
---|
87 | { |
---|
88 | buf[i]= (*this)[i]; |
---|
89 | count++; |
---|
90 | } |
---|
91 | else |
---|
92 | buf[i]= -1; |
---|
93 | } |
---|
94 | ASSERT ( count > 0, "count > 0 expected" ); |
---|
95 | |
---|
96 | init (count); |
---|
97 | count= 0; |
---|
98 | for (int i= 0; i < length; i++) |
---|
99 | { |
---|
100 | if (buf[i] != -1) |
---|
101 | { |
---|
102 | (*this) [count]= buf[i]; |
---|
103 | count++; |
---|
104 | } |
---|
105 | } |
---|
106 | delete[] buf; |
---|
107 | } |
---|
108 | |
---|
109 | inline void |
---|
110 | DegreePattern::refine () |
---|
111 | { |
---|
112 | if (getLength() <= 1) |
---|
113 | return; |
---|
114 | int count= 0; |
---|
115 | int* buf= new int [getLength()]; |
---|
116 | int d= (*this) [0]; |
---|
117 | int pos; |
---|
118 | for (int i= 0; i < getLength(); i++) |
---|
119 | buf[i]= -1; |
---|
120 | for (int i= 1; i < getLength(); i++) |
---|
121 | { |
---|
122 | pos= (*this).find (d - (*this)[i]); |
---|
123 | if (pos) |
---|
124 | { |
---|
125 | buf[i]= (*this)[i]; |
---|
126 | count++; |
---|
127 | } |
---|
128 | } |
---|
129 | buf[0]= d; |
---|
130 | count++; |
---|
131 | if (count == getLength()) |
---|
132 | { |
---|
133 | return; |
---|
134 | } |
---|
135 | int length= getLength(); |
---|
136 | |
---|
137 | ASSERT ( count > 0, "count > 0 expected" ); |
---|
138 | init (count); |
---|
139 | count= 0; |
---|
140 | for (int i= 0; i < length; i++) |
---|
141 | { |
---|
142 | if (buf[i] != -1) |
---|
143 | { |
---|
144 | (*this)[count]= buf[i]; |
---|
145 | count++; |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | delete[] buf; |
---|
150 | return; |
---|
151 | } |
---|
152 | |
---|