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

◆ TEST() [2/7]

TEST ( ARingCC ,
axioms  )

Definition at line 188 of file ARingCCTest.cpp.

189{
190 M2::ARingCC C;
191 auto nbits = C.get_precision();
193 M2::ARingCC::ElementType a, b, c, d, e;
194 C.init(a);
195 C.init(b);
196 C.init(c);
197 C.init(d);
198 C.init(e);
199 for (int i = 0; i < ntrials; i++)
200 {
201 gen.nextElement(a);
202 gen.nextElement(b);
203 gen.nextElement(c);
204 // Test commutativity
205 // test: a*b = b*a
206 // test: a+b == b+a
207 C.add(d, a, b);
208 C.add(e, b, a);
209 EXPECT_TRUE(almostEqual(C, nbits - 2, d, e));
210 C.mult(d, a, b);
211 C.mult(e, b, a);
212 EXPECT_TRUE(almostEqual(C, nbits - 2, d, e));
213
214 // Test associativity
215 // test: a+(b+c) == (a+b)+c
216 // test: a*(b*c) == (a*b)*c
217 C.add(e, b, c);
218 C.add(d, a, e); // a+(b+c)
219 C.add(e, a, b);
220 C.add(e, e, c); // (a+b)+c
221 EXPECT_TRUE(almostEqual(C, nbits - 6, d, e));
222 C.mult(e, b, c);
223 C.mult(d, a, e); // a*(b*c)
224 C.mult(e, a, b);
225 C.mult(e, e, c); // (a*b)*c
226 EXPECT_TRUE(almostEqual(C, nbits - 6, d, e));
227
228 // Test distributivity
229 // test: a*(b+c) == a*b + a*c
230 C.add(e, b, c);
231 C.mult(d, a, e); // a*(b+c)
232 C.mult(b, a, b);
233 C.mult(c, a, c);
234 C.add(e, b, c); // a*b + a*c
235 EXPECT_TRUE(almostEqual(C, nbits - 6, d, e));
236 }
237 C.clear(e);
238 C.clear(d);
239 C.clear(c);
240 C.clear(b);
241 C.clear(a);
242}
bool almostEqual(const M2::ARingCC &C, unsigned long nbits, const M2::ARingCC::ElementType &a, const M2::ARingCC::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
void mult(ElementType &res, const ElementType &a, const RealElementType &b) const
Definition aring-CC.hpp:303
elem ElementType
Definition aring-CC.hpp:81
void add(ElementType &res, const ElementType &a, const ElementType &b) const
Definition aring-CC.hpp:255
void init(ElementType &result) const
Definition aring-CC.hpp:150
unsigned long get_precision() const
Definition aring-CC.hpp:88
static void clear(ElementType &result)
Definition aring-CC.hpp:164
aring-style adapter for double-precision complex numbers, stored as (double, double) pairs.
Definition aring-CC.hpp:72

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