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

◆ TEST() [2/7]

TEST ( ARingRRR ,
axioms  )

Definition at line 198 of file ARingRRRTest.cpp.

199{
200 M2::ARingRRR R(100);
202 M2::ARingRRR::ElementType a, b, c, d, e;
203 R.init(a);
204 R.init(b);
205 R.init(c);
206 R.init(d);
207 R.init(e);
208 for (int i = 0; i < ntrials; i++)
209 {
210 gen.nextElement(a);
211 gen.nextElement(b);
212 gen.nextElement(c);
213 // Test commutativity
214 // test: a*b = b*a
215 // test: a+b == b+a
216 R.add(d, a, b);
217 R.add(e, b, a);
218 EXPECT_TRUE(almostEqual(R, 98, d, e));
219 R.mult(d, a, b);
220 R.mult(e, b, a);
221 EXPECT_TRUE(almostEqual(R, 98, d, e));
222
223 // Test associativity
224 // test: a+(b+c) == (a+b)+c
225 // test: a*(b*c) == (a*b)*c
226 R.add(e, b, c);
227 R.add(d, a, e); // a+(b+c)
228 R.add(e, a, b);
229 R.add(e, e, c); // (a+b)+c
230 EXPECT_TRUE(almostEqual(R, 94, d, e));
231 R.mult(e, b, c);
232 R.mult(d, a, e); // a*(b*c)
233 R.mult(e, a, b);
234 R.mult(e, e, c); // (a*b)*c
235 EXPECT_TRUE(almostEqual(R, 94, d, e));
236
237 // Test distributivity
238 // test: a*(b+c) == a*b + a*c
239 R.add(e, b, c);
240 R.mult(d, a, e); // a*(b+c)
241 R.mult(b, a, b);
242 R.mult(c, a, c);
243 R.add(e, b, c); // a*b + a*c
244 EXPECT_TRUE(almostEqual(R, 94, d, e));
245 }
246 R.clear(e);
247 R.clear(d);
248 R.clear(c);
249 R.clear(b);
250 R.clear(a);
251}
bool almostEqual(const M2::ARingRRR &R, int nbits, const M2::ARingRRR::ElementType &a, const M2::ARingRRR::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

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