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

◆ testPower()

template<typename T>
void testPower ( const T & R,
int ntrials )

Definition at line 397 of file ARingTest.hpp.

398{
399 // test the following: (x=generator of the finite field, q = card of field)
400 // check: x^i != x, for 2 <= i <= characteristic-??
401 // x^q == x
402 // x^(q-1) == 1
403 // x^(-1) * x == 1
404 // x^(-2) * x^2 == 1
405
406 // a^2 == a*a, for various a
407 // a^3 == a*a*a
408 // a^0 == 1, what if a == 0?
409 // 1^n == 1, various n
411 typename T::ElementType a, b, c, d, one;
412 int q = static_cast<int>(R.cardinality());
413 R.init(one);
414 R.init(a);
415 R.init(b);
416 R.init(c);
417 R.init(d);
418 R.set_from_long(one, 1);
419 for (int i = 0; i < ntrials; i++)
420 {
421 gen.nextElement(a);
422 gen.nextElement(b);
423
424 R.power(c, a, q);
425 EXPECT_TRUE(R.is_equal(c, a)); // test a^q == a
426
427 if (R.is_zero(a)) continue;
428
429 R.power(c, a, q - 1);
430 EXPECT_TRUE(R.is_equal(c, one)); // test a^(q-1) == 1
431
432 R.power(c, a, -1); // test a^-1 * a == 1
433 R.mult(c, a, c);
434 EXPECT_TRUE(R.is_equal(c, one));
435
436 R.power(c, a, -2); // test a^-2 * a^3 == a
437 R.power(d, a, 3);
438 R.mult(d, c, d);
439 EXPECT_TRUE(R.is_equal(d, a));
440 }
441 R.clear(a);
442 R.clear(b);
443 R.clear(c);
444 R.clear(d);
445 R.clear(one);
446}
const int ntrials
Definition ARingTest.hpp:42

References ARingElementGenerator< RingType >::nextElement(), ntrials, and T.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and testFiniteField().