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

◆ TEST() [2/7]

TEST ( ARingRR ,
axioms  )

Definition at line 203 of file ARingRRTest.cpp.

204{
205 M2::ARingRR R;
206 auto nbits = R.get_precision();
208 M2::ARingRR::ElementType a, b, c, d, e;
209 R.init(a);
210 R.init(b);
211 R.init(c);
212 R.init(d);
213 R.init(e);
214 for (int i = 0; i < ntrials; i++)
215 {
216 gen.nextElement(a);
217 gen.nextElement(b);
218 gen.nextElement(c);
219 // Test commutativity
220 // test: a*b = b*a
221 // test: a+b == b+a
222 R.add(d, a, b);
223 R.add(e, b, a);
224 EXPECT_TRUE(almostEqual(R, nbits - 2, d, e));
225 R.mult(d, a, b);
226 R.mult(e, b, a);
227 EXPECT_TRUE(almostEqual(R, nbits - 2, d, e));
228
229 // Test associativity
230 // test: a+(b+c) == (a+b)+c
231 // test: a*(b*c) == (a*b)*c
232 R.add(e, b, c);
233 R.add(d, a, e); // a+(b+c)
234 R.add(e, a, b);
235 R.add(e, e, c); // (a+b)+c
236 EXPECT_TRUE(almostEqual(R, nbits - 6, d, e));
237 R.mult(e, b, c);
238 R.mult(d, a, e); // a*(b*c)
239 R.mult(e, a, b);
240 R.mult(e, e, c); // (a*b)*c
241 EXPECT_TRUE(almostEqual(R, nbits - 6, d, e));
242
243 // Test distributivity
244 // test: a*(b+c) == a*b + a*c
245 R.add(e, b, c);
246 R.mult(d, a, e); // a*(b+c)
247 R.mult(b, a, b);
248 R.mult(c, a, c);
249 R.add(e, b, c); // a*b + a*c
250 EXPECT_TRUE(almostEqual(R, nbits - 6, d, e));
251 }
252 R.clear(e);
253 R.clear(d);
254 R.clear(c);
255 R.clear(b);
256 R.clear(a);
257}
bool almostEqual(const M2::ARingRR &R, unsigned long nbits, const M2::ARingRR::ElementType &a, const M2::ARingRR::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
void init(ElementType &result) const
Definition aring-RR.hpp:124
void mult(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:203
elem ElementType
Definition aring-RR.hpp:68
static void clear(ElementType &result)
Definition aring-RR.hpp:128
unsigned long get_precision() const
Definition aring-RR.hpp:73
void add(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:175
aring-style adapter for double-precision real numbers.
Definition aring-RR.hpp:62

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