Macaulay2 Engine
Loading...
Searching...
No Matches
franzi-brp-test.cpp
Go to the documentation of this file.
1/* This code written by Franziska Hinkelmann is in the public domain */
2
3#include "franzi-brp.hpp"
4#include <vector>
5// g++ franzi-brp.cpp franzi-brp-test.cpp -o franzi-brp-test
6
8{
9 BRP bar = BRP();
10 if (bar != 0)
11 {
12 cout << "Testing equality = 0: " << (bar == 0 ? "is 0" : "not 0") << endl;
13 }
14 if (bar == 1)
15 {
16 cout << "Testing equality = 0: " << (bar == 0 ? "is 0" : "not 0") << endl;
17 }
18 if ((bar == 0) == false)
19 {
20 cout << "Testing equality = 0: " << (bar == 0 ? "is 0" : "not 0") << endl;
21 }
22}
23
24// this is testing that we're using correct lex order
26{
27 BRP lex = BRP(9) + BRP(7);
28 lex = BRP(7) + BRP(9);
29 monomials control;
30 control.push_back(9);
31 control.push_back(7);
32 BRP c = BRP(control);
33 if (lex != c)
34 {
35 cout << "Testing something that should have a different order failed"
36 << endl;
37 }
38}
39
41{
42 monomials foo;
43 foo.push_back(0);
44 BRP bar = BRP(foo);
45 if (bar != 1)
46 {
47 cout << "Testing equality = 1: " << (bar == 1 ? "is 1" : "not 1") << endl;
48 }
49 if (bar == 0)
50 {
51 cout << "Testing equality = 0: " << (bar == 0 ? "is 1" : "not 1") << endl;
52 }
53 if ((bar == 1) == false)
54 {
55 cout << "Testing equality = 1: " << (bar == 1 ? "is 1" : "not 1") << endl;
56 }
57}
58
60{
61 monomials foo;
62 foo.push_back(8);
63 foo.push_back(3);
64 foo.push_back(0);
65 BRP bar = BRP(foo);
66 if (bar != bar)
67 {
68 cout << "Testing same BRP for equality failed" << endl;
69 }
70
72 foo1.push_back(8);
73 foo1.push_back(3);
74 foo1.push_back(0);
75 BRP bar1 = BRP(foo1);
76 if (bar1 != bar)
77 {
78 cout << "Testing equal BRPs for equality failed" << endl;
79 }
80
82 foo2.push_back(8);
83 foo2.push_back(3);
84 foo2.push_back(1);
85 BRP bar2 = BRP(foo2);
86 if ((bar2 != bar) == false)
87 {
88 cout << "Testing different BRPs for equality failed" << endl;
89 }
90 if (bar2 == bar)
91 {
92 cout << "Testing different BRPs for equality failed" << endl;
93 }
94}
95
97{
98 monomials foo;
99 foo.push_back(3);
100 foo.push_back(2);
101 foo.push_back(1);
103 foo2.push_back(5);
104 foo2.push_back(4);
105 foo2.push_back(3);
106 BRP bar = BRP(foo);
107 // cout << bar << endl;
108 BRP bar2 = BRP(foo2);
109 // cout << bar2 << endl;
110
111 BRP bar3 = bar + bar2;
112 // cout << bar3 << endl;
113
114 monomials foo3;
115 foo3.push_back(5);
116 foo3.push_back(4);
117 foo3.push_back(2);
118 foo3.push_back(1);
119
120 BRP bar4 = BRP(foo3);
121
122 if (bar3 != bar4)
123 {
124 cout << "Testing addition: " << (bar3 == bar4 ? "is good" : "is bad")
125 << endl;
126 }
127 BRP a = BRP(16) + BRP(15) + BRP(5) + BRP(2);
128 BRP b = BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
129 BRP c = a + b;
130 BRP correct =
131 BRP(16) + BRP(15) + BRP(13) + BRP(12) + BRP(6) + BRP(5) + BRP(4) + BRP(1);
132
133 if (c != correct)
134 {
135 cout << "Addition failed" << endl;
136 }
137}
138
140{
141 BRP a = BRP(35) + BRP(16) + BRP(15) + BRP(5) + BRP(2);
142 BRP b = BRP(38) + BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
143 BRP c = a + b;
144 BRP correct = BRP(38) + BRP(35) + BRP(16) + BRP(15) + BRP(13) + BRP(12) +
145 BRP(6) + BRP(5) + BRP(4) + BRP(1);
146
147 if (c != correct)
148 {
149 cout << "Addition failed" << endl;
150 }
151}
152
154{
155 BRP a = BRP(35) + BRP(16) + BRP(15) + BRP(5) + BRP(2) + BRP(0);
156 BRP b = BRP(38) + BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
157 BRP c = a + b;
158 BRP correct = BRP(38) + BRP(35) + BRP(16) + BRP(15) + BRP(13) + BRP(12) +
159 BRP(6) + BRP(5) + BRP(4) + BRP(1) + BRP(0);
160
161 if (c != correct)
162 {
163 cout << "Addition failed" << endl;
164 }
165}
166
168{
169 BRP a = BRP(35) + BRP(16) + BRP(15) + BRP(5) + BRP(2) + BRP(0);
170 BRP b = BRP(35) + BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
171 BRP c = a + b;
172 BRP correct = BRP(16) + BRP(15) + BRP(13) + BRP(12) + BRP(6) + BRP(5) +
173 BRP(4) + BRP(1) + BRP(0);
174
175 if (c != correct)
176 {
177 cout << "Addition failed" << endl;
178 }
179}
180
182{
183 monomials foo;
184 foo.push_back(14);
185 foo.push_back(1);
186 BRP bar = BRP(foo);
187 // cout << bar << endl;
188
190 foo2.push_back(8);
191 BRP bar2 = BRP(foo2);
192 // cout << bar2 << endl;
193
194 BRP barMultiply = bar * bar2;
195 // cout << barMultiply << endl;
196
197 monomials foo3;
198 foo3.push_back(14);
199 foo3.push_back(9);
200
201 BRP bar3 = BRP(foo3);
202 if (barMultiply != bar3)
203 {
204 cout << "Testing multiplication: "
205 << (barMultiply == bar3 ? "is good" : "is bad") << endl;
206 }
207
208 BRP a = BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
209 BRP b = BRP(13);
210 BRP c = a * b;
211 // 13 + 13 + 15 + 13 + 15 + 13
212 BRP correct = BRP();
213
214 if (c != correct)
215 {
216 cout << "Multiplication not correct. Is " << c << endl;
217 }
218
219 a = BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
220 int d = 13;
221 c = a * d;
222 // 13 + 13 + 15 + 13 + 15 + 13
223 correct = BRP();
224
225 if (c != correct)
226 {
227 cout << "Multiplication not correct. Is " << c << endl;
228 }
229
230 a = BRP(16) + BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
231 b = BRP(13);
232 c = a * b;
233 // 29 + 13 + 13 + 15 + 13 + 15 + 13
234 correct = BRP(29);
235 if (c != correct)
236 {
237 cout << "Multiplication not correct. Is " << c << endl;
238 }
239
240 a = BRP(16) + BRP(13) + BRP(12) + BRP(6) + BRP(4) + BRP(2) + BRP(1);
241 d = 13;
242 c = a * d;
243 // 29 + 13 + 13 + 15 + 13 + 15 + 13
244 correct = BRP(29);
245 if (c != correct)
246 {
247 cout << "Multiplication not correct. Is " << c << endl;
248 }
249
250 a = BRP(16) + BRP(13) + BRP(12) + BRP(6) + BRP(4);
251 d = 220;
252 c = a * d;
253 // 220 + 221 + 220 + 222 + 220
254 correct = BRP(222) + BRP(221) + BRP(220);
255 if (c != correct)
256 {
257 cout << "Multiplication not correct. Is " << c << endl;
258 }
259}
260
262{
263 if (BRP::isDivisibleBy(14, 1))
264 {
265 cout << "Testing isDivisibleBy is bad" << endl;
266 }
267 if (!BRP::isDivisibleBy(1, 0))
268 {
269 cout << "Testing isDivisibleBy is bad" << endl;
270 }
271 int barDivide = 14 ^ 8;
272 if (barDivide != 6)
273 {
274 cout << "Testing divide: " << (barDivide == 6 ? "is good" : "is bad")
275 << endl;
276 }
277}
278
279void testLT()
280{
281 monomials foo;
282 foo.push_back(8);
283 foo.push_back(3);
284 BRP bar = BRP(foo);
285
286 if (bar.LT() != 8)
287 {
288 cout << "Testing LT(): " << (bar.LT() == 8 ? "is good" : "is bad")
289 << endl;
290 }
291
293 foo1.push_back(0); // foo1 == 1
294 BRP bar1 = BRP(foo1);
295 if (bar1.LT() != 0)
296 {
297 cout << "Testing LT(): " << (bar.LT() == 8 ? "is good" : "is bad")
298 << endl;
299 }
300 if (BRP(bar1.LT()) != bar1)
301 {
302 cout << "Testing LT(): " << (bar.LT() == 8 ? "is good" : "is bad")
303 << endl;
304 }
305}
306
308{
309 BRP f = BRP(2) * BRP(8) + BRP(7);
310 if (!f.isLeadingReducibleBy(BRP(8)))
311 {
312 cout << "error" << endl;
313 }
314 if (!f.isLeadingReducibleBy(BRP(2)))
315 {
316 cout << "error" << endl;
317 }
318 if (f.isLeadingReducibleBy(BRP(1)))
319 {
320 cout << "error" << endl;
321 }
322}
323
325{ // f = ax+g
326 BRP f = BRP(2) * BRP(8) + BRP(7);
327 if ((BRP(7)) != f.remainder(BRP(8)))
328 {
329 cout << "error" << endl;
330 }
331 if ((BRP(2)) == f.remainder(BRP(8)))
332 {
333 cout << "error" << endl;
334 }
335
336 BRP a = BRP(8) * BRP(2);
337 if (a != f.remainder(BRP(7)))
338 {
339 cout << "error" << endl;
340 }
341}
342
344{
345 BRP f = BRP(2) * BRP(8) + BRP(7);
346 if (BRP::isRelativelyPrime(f.LT(), BRP(8).LT()))
347 {
348 cout << "error" << endl;
349 }
350 if (BRP::isRelativelyPrime(BRP(8).LT(), f.LT()))
351 {
352 cout << "error" << endl;
353 }
354 if (BRP::isRelativelyPrime(BRP(2).LT(), f.LT()))
355 {
356 cout << "error" << endl;
357 }
358 if (!BRP::isRelativelyPrime(f.LT(), BRP(1).LT()))
359 {
360 cout << "error" << endl;
361 }
362 if (!BRP::isRelativelyPrime(BRP(1).LT(), f.LT()))
363 {
364 cout << "error" << endl;
365 }
366 if (!BRP::isRelativelyPrime(BRP(1).LT(), BRP(0).LT()))
367 { // x, 1
368 cout << "error" << endl;
369 }
370 if (!BRP::isRelativelyPrime(f.LT(), BRP(0).LT()))
371 { // f, 1
372 cout << "error" << endl;
373 }
374}
375
376int main()
377{
378 cout << "Hello Testing Friends!" << endl;
379
382 testEquality();
383 testAddition();
388 testDivide();
389 testLT();
393 testOrder();
394}
static bool isDivisibleBy(const brMonomial &a, const brMonomial &b)
bool isLeadingReducibleBy(const BRP &other) const
brMonomial LT() const
BRP remainder(const BRP &x) const
static bool isRelativelyPrime(const brMonomial &a, const brMonomial &b)
Boolean (F_2-coefficient) polynomial stored as an ordered list of square-free monomials.
static struct enter_factory foo2
Definition factory.cpp:310
static struct enter_factory foo1
Definition factory.cpp:287
void testAddition3()
void testMultiplication()
void testAddition4()
void testLT()
void testIsRelativelyPrime()
void testOrder()
void testEquality0()
void testRemainder()
void testEquality()
void testEquality1()
void testIsLeadingReducibleBy()
void testAddition()
int main()
void testAddition2()
void testDivide()
std::list< brMonomial > monomials
brMonomial — bit-packed Boolean-ring monomials for the Hinkelmann GB engine.
const int LT
Definition style.hpp:39