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

◆ TEST() [3/19]

TEST ( FreeAlgebra ,
polyarithmetic  )

Definition at line 287 of file NCGroebnerTest.cpp.

288{
290 { "x", "y", "z" },
291 degreeRing(1),
292 {1,2,3},
293 {},
294 {1}
295 );
296 FreeAlgebraElement x(A), y(A), z(A), f(A), g(A), h(A);
297 A->var(*x, 0);
298 A->var(*y, 1);
299 A->var(*z, 2);
300 f = x + y;
301 g = y + z;
302 EXPECT_TRUE(x + y == y + x);
303 EXPECT_FALSE(f == g);
304 EXPECT_TRUE(x * (y + z) == x * y + x * z);
305 EXPECT_TRUE((f * g) * f == f * (g * f));
306 EXPECT_TRUE((f^2) == (f * f));
307
308 A->from_word(*h, {1,2,1,0,1});
309 EXPECT_TRUE(h == y * z * y * x * y);
310
311 A->setZero(*f);
312 A->subtract(*f,*x,*y);
313 EXPECT_TRUE(f == (x - y));
314
315 A->setZero(*f);
316 A->setZero(*g);
317 A->from_long(*f,1);
318 std::vector<int> gdata {};
319 A->from_word(*g, gdata);
320 // from_rational test? How to create an mpq_ptr?
321 EXPECT_TRUE(f == g);
322 EXPECT_TRUE(A->is_unit(*f));
323 EXPECT_TRUE((h^0) == f);
324
325 A->setZero(*f);
326 A->setZero(*g);
327 A->setZero(*h);
328 f = x + y;
329 A->from_long(*g,-1);
330 A->negate(*h,*f);
331 EXPECT_TRUE(h == f*g);
332 A->setZero(*h);
333 A->mult_by_coeff(*h,*f,A->coefficientRing()->from_long(-1));
334 EXPECT_TRUE(h == f*g);
335
336 A->setZero(*f);
337 A->setZero(*g);
338 A->setZero(*h);
339 EXPECT_TRUE(A->is_zero(*h));
340 f = x + y;
341 A->lead_term_as_poly(*g,*f);
342 EXPECT_TRUE(g == x);
343 A->add_to_end(*f,*z);
344 EXPECT_TRUE(f == (x + y + z));
345
346 A->subtract(*h,*f,*(x+y+z));
347 EXPECT_TRUE(A->is_zero(*h));
348
349 A->setZero(*f);
350 A->setZero(*g);
351 f = x + y;
353 EXPECT_TRUE(g == z*z*f);
354 A->setZero(*g);
356 EXPECT_TRUE(g == f*y*x*y*x);
357 A->setZero(*g);
359 EXPECT_TRUE(g == z*z*f*y*x*y*x);
360
361 // making polynomial monic test
362 A->setZero(*f);
363 A->setZero(*g);
364 A->setZero(*h);
365 A->from_long(*f,-1);
366 g = f*(x + y);
367 A->makeMonic(*h,*g);
368 EXPECT_TRUE(h == x + y);
369}
std::vector< int > monom2
std::vector< int > monom3
const RingQQ * globalQQ
Definition aring.cpp:24
const Ring * coefficientRing() const
void negate(Poly &result, const Poly &f) const
bool is_unit(const Poly &f) const
void subtract(Poly &result, const Poly &f, const Poly &g) const
void mult_by_term_right(Poly &result, const Poly &f, const ring_elem c, const Monom m) const
void add_to_end(Poly &f, const Poly &g) const
void from_long(Poly &result, long n) const
void mult_by_term_left(Poly &result, const Poly &f, const ring_elem c, const Monom m) const
void mult_by_coeff(Poly &result, const Poly &f, const ring_elem c) const
void var(Poly &result, int v) const
void lead_term_as_poly(Poly &result, const Poly &f) const
bool is_zero(const Poly &f) const
static FreeAlgebra * create(const Ring *K, const std::vector< std::string > &names, const PolynomialRing *degreeRing, const std::vector< int > &degrees, const std::vector< int > &wtvecs, const std::vector< int > &heftVector)
void makeMonic(Poly &result, Poly &f) const
void mult_by_term_left_and_right(Poly &result, const Poly &f, const ring_elem c, const Monom leftM, const Monom rightM) const
void from_word(Poly &result, const Word &word) const
void setZero(Poly &f) const
Owned Poly value paired with its FreeAlgebra*, providing natural operator-overloaded arithmetic.
Free associative algebra over a coefficient ring: the non-commutative analogue of PolynomialRing.
virtual ring_elem from_long(long n) const =0
Non-owning view of a non-commutative word: [begin, end) of int variable indices.
Definition Word.hpp:56
volatile int x
const PolynomialRing * degreeRing(const std::vector< std::string > &names)

References FreeAlgebra::add_to_end(), FreeAlgebra::coefficientRing(), FreeAlgebra::create(), degreeRing(), FreeAlgebra::from_long(), Ring::from_long(), FreeAlgebra::from_word(), globalQQ, FreeAlgebra::is_unit(), FreeAlgebra::is_zero(), FreeAlgebra::lead_term_as_poly(), FreeAlgebra::makeMonic(), monom2, monom3, FreeAlgebra::mult_by_coeff(), FreeAlgebra::mult_by_term_left(), FreeAlgebra::mult_by_term_left_and_right(), FreeAlgebra::mult_by_term_right(), FreeAlgebra::negate(), FreeAlgebra::setZero(), FreeAlgebra::subtract(), FreeAlgebra::var(), and x.