Macaulay2 Engine
Loading...
Searching...
No Matches

◆ TEST() [2/7]

TEST ( ARingCCC ,
axioms  )

Definition at line 192 of file ARingCCCTest.cpp.

193{
194 M2::ARingCCC C(100);
196 M2::ARingCCC::ElementType a, b, c, d, e;
197 C.init(a);
198 C.init(b);
199 C.init(c);
200 C.init(d);
201 C.init(e);
202 for (int i = 0; i < ntrials; i++)
203 {
204 gen.nextElement(a);
205 gen.nextElement(b);
206 gen.nextElement(c);
207 // Test commutativity
208 // test: a*b = b*a
209 // test: a+b == b+a
210 C.add(d, a, b);
211 C.add(e, b, a);
212 EXPECT_TRUE(almostEqual(C, 98, d, e));
213 C.mult(d, a, b);
214 C.mult(e, b, a);
215 EXPECT_TRUE(almostEqual(C, 98, d, e));
216
217 // Test associativity
218 // test: a+(b+c) == (a+b)+c
219 // test: a*(b*c) == (a*b)*c
220 C.add(e, b, c);
221 C.add(d, a, e); // a+(b+c)
222 C.add(e, a, b);
223 C.add(e, e, c); // (a+b)+c
224 EXPECT_TRUE(almostEqual(C, 94, d, e));
225 C.mult(e, b, c);
226 C.mult(d, a, e); // a*(b*c)
227 C.mult(e, a, b);
228 C.mult(e, e, c); // (a*b)*c
229 EXPECT_TRUE(almostEqual(
230 C, 93, d, e)); // MES: I'm not sure how equal these should be.
231
232 // Test distributivity
233 // test: a*(b+c) == a*b + a*c
234 C.add(e, b, c);
235 C.mult(d, a, e); // a*(b+c)
236 C.mult(b, a, b);
237 C.mult(c, a, c);
238 C.add(e, b, c); // a*b + a*c
239 EXPECT_TRUE(almostEqual(C, 93, d, e));
240 }
241 C.clear(e);
242 C.clear(d);
243 C.clear(c);
244 C.clear(b);
245 C.clear(a);
246}
bool almostEqual(const M2::ARingCCC &C, int nbits, const M2::ARingCCC::ElementType &a, const M2::ARingCCC::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
aring-style adapter for arbitrary-precision complex numbers, stored as (MPFR, MPFR) pairs.
Definition aring-CCC.hpp:71

References M2::ARingCCC::add(), almostEqual(), M2::ARingCCC::clear(), M2::ARingCCC::init(), M2::ARingCCC::mult(), ARingElementGenerator< RingType >::nextElement(), and ntrials.