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

◆ TEST() [2/7]

TEST ( ARingRRi ,
axioms  )

Definition at line 211 of file ARingRRiTest.cpp.

212{
213 M2::ARingRRi R(100);
214 M2::ARingRRR S(100);
216 M2::ARingRRi::ElementType a, b, c, d, e;
217 R.init(a);
218 R.init(b);
219 R.init(c);
220 R.init(d);
221 R.init(e);
222
223 for (int i = 0; i < ntrials; i++)
224 {
225 gen.nextElement(a);
226 gen.nextElement(b);
227 gen.nextElement(c);
228 // Test commutativity
229 // test: a*b = b*a
230 // test: a+b == b+a
231 R.add(d, a, b);
232 R.add(e, b, a);
233 EXPECT_TRUE(R.is_equal(d,e));
234 R.mult(d, a, b);
235 R.mult(e, b, a);
236 EXPECT_TRUE(R.is_equal(d,e));
237
238 // Test associativity
239 // test: a+(b+c) == (a+b)+c
240 // test: a*(b*c) == (a*b)*c
241 R.add(e, b, c);
242 R.add(d, a, e); // a+(b+c)
243 R.add(e, a, b);
244 R.add(e, e, c); // (a+b)+c
245 EXPECT_TRUE(almostEqual(R,-94,d,e));
246
247 R.mult(e, b, c);
248 R.mult(d, a, e); // a*(b*c)
249 R.mult(e, a, b);
250 R.mult(e, e, c); // (a*b)*c
251
252 EXPECT_TRUE(almostEqual(R,-94,d,e));
253
254 // Test distributivity
255 // test: a*(b+c) == a*b + a*c
256 R.add(e, b, c);
257 R.mult(d, a, e); // a*(b+c)
258 R.mult(b, a, b);
259 R.mult(c, a, c);
260 R.add(e, b, c); // a*b + a*c
261
262 EXPECT_TRUE(almostEqual(R,-94,d,e));
263 }
264 R.clear(e);
265 R.clear(d);
266 R.clear(c);
267 R.clear(b);
268 R.clear(a);
269}
bool almostEqual(const M2::ARingRRi &R, int nbits, const M2::ARingRRi::ElementType &a, const M2::ARingRRi::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
aring-style adapter for arbitrary-precision real numbers, backed by MPFR.
Definition aring-RRR.hpp:70
aring-style adapter for arbitrary-precision real intervals, backed by MPFI.
Definition aring-RRi.hpp:69

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