34#include <gtest/gtest.h>
59 for (
size_t i = 0; i < 1000; ++i)
61 size_t sz = 4 + (32343 * i) % 10;
63 for (
int j = 0; j < sz; j++)
64 range.first[j] = 100 * i + j;
68 for (
int j = 0; j < 4; j++)
69 range.first[j] = 100 * i + j;
71 if ((range.second - range.first != sz) and (range.second - range.first != 4))
94std::vector<int>
word {2, 0, 1, 2, 2, 1, 0, 1, 0};
119 H->addPolynomial(*f);
120 H->addPolynomial(*g);
121 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
122 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
125 EXPECT_FALSE(H->isZero());
128 EXPECT_FALSE(H->isZero());
131 EXPECT_TRUE(H->isZero());
132 EXPECT_TRUE(A->
is_zero(* H->value()));
155 F = y*z*
x*z - y*z*y*y - y*z*z*
x - z*
x*y*z + z*
x*z*y - z*y*y*y - z*z*
x*y - z*z*y*
x - z*z*z*z;
156 G = -y*z*
x*z - y*z*y*y - y*z*z*
x;
159 std::cout << H->getName() << std::endl;
160 H->addPolynomial(*f);
161 H->addPolynomial(*g);
164 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
165 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
168 EXPECT_FALSE(H->isZero());
171 EXPECT_FALSE(H->isZero());
174 EXPECT_TRUE(H->isZero());
175 EXPECT_TRUE(A->
is_zero(* H->value()));
176 H->addPolynomial(*h);
177 H->addPolynomial(*mh);
178 EXPECT_TRUE(H->isZero());
179 EXPECT_TRUE(A->
is_zero(* H->value()));
181 H->addPolynomial(*F);
182 H->addPolynomial(*
G);
185 std::cout << o.
str() << std::endl;
208 F = y*z*
x*z - y*z*y*y - y*z*z*
x - z*
x*y*z + z*
x*z*y - z*y*y*y - z*z*
x*y - z*z*y*
x - z*z*z*z;
209 G = -y*z*
x*z - y*z*y*y - y*z*z*
x;
212 std::cout << H->getName() << std::endl;
213 H->addPolynomial(*f);
215 H->addPolynomial(*g);
217 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
218 EXPECT_TRUE(A->
is_equal(* H->value(), *h));
220 std::cout <<
"about to call removeLeadTerm" << std::endl;
223 EXPECT_FALSE(H->isZero());
226 EXPECT_FALSE(H->isZero());
229 EXPECT_TRUE(H->isZero());
230 EXPECT_TRUE(A->
is_zero(* H->value()));
231 H->addPolynomial(*h);
232 H->addPolynomial(*mh);
233 EXPECT_TRUE(H->isZero());
234 EXPECT_TRUE(A->
is_zero(* H->value()));
236 H->addPolynomial(*F);
237 H->addPolynomial(*
G);
240 std::cout << o.
str() << std::endl;
248 std::string answer3 {
"MonomialOrder => {\n Lex => 5,\n GroupLex => 4\n }" };
284 EXPECT_TRUE(A !=
nullptr);
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));
309 EXPECT_TRUE(h == y * z * y *
x * y);
313 EXPECT_TRUE(f == (
x - y));
318 std::vector<int> gdata {};
323 EXPECT_TRUE((h^0) == f);
331 EXPECT_TRUE(h == f*g);
334 EXPECT_TRUE(h == f*g);
344 EXPECT_TRUE(f == (
x + y + z));
353 EXPECT_TRUE(g == z*z*f);
356 EXPECT_TRUE(g == f*y*
x*y*
x);
359 EXPECT_TRUE(g == z*z*f*y*
x*y*
x);
368 EXPECT_TRUE(h ==
x + y);
388 auto GB = std::unique_ptr<ConstPolyList> (
new ConstPolyList);
393 EXPECT_TRUE(GB->size() == 3);
448 EXPECT_TRUE((*f).cbegin().monom().begin() + 2 == leadWord.
begin() && (*f).cbegin().monom().begin() + 5 == leadWord.
end());
449 EXPECT_TRUE((*f).cbegin().monom().begin() + 2 == leadWordPrefix.
begin() && (*f).cbegin().monom().begin() + 4 == leadWordPrefix.
end());
450 EXPECT_TRUE((*f).cbegin().monom().begin() + 3 == leadWordSuffix.
begin() && (*f).cbegin().monom().begin() + 5 == leadWordSuffix.
end());
461 overlapTable.
insert(3,
false,std::make_tuple(1,2,3,
true));
462 overlapTable.
insert(3,
false,std::make_tuple(1,2,1,
true));
463 overlapTable.
insert(2,
false,std::make_tuple(1,1,1,
true));
467 EXPECT_TRUE(overlapTable.
size() == 3);
472 auto key1 = std::make_pair(1,
false);
473 auto key2 = std::make_pair(1,
true);
474 auto key3 = std::make_pair(2,
false);
475 auto key4 = std::make_pair(2,
true);
476 std::map<std::pair<int,bool>,
int> myMap;
477 myMap.insert(std::make_pair(key1,0));
478 myMap.insert(std::make_pair(key2,0));
479 myMap.insert(std::make_pair(key3,0));
480 myMap.insert(std::make_pair(key4,0));
484 std::cout <<
"[" << i.first.first <<
"," << i.first.second <<
"]" << std::endl;
492 EXPECT_EQ(
monom1.size(), 3);
493 EXPECT_EQ(
monom2.size(), 2);
506 EXPECT_EQ(
monom1.size(), 3);
507 EXPECT_EQ(
monom2.size(), 2);
513 std::vector<std::pair<int,int>> matches;
516 EXPECT_EQ(matches.size(), 3);
517 EXPECT_EQ(matches[0], std::make_pair(0, 0));
518 EXPECT_EQ(matches[1], std::make_pair(1, 3));
519 EXPECT_EQ(matches[2], std::make_pair(2, 5));
529 std::cout << c << std::endl;
535 std::vector<int>
monom1 {1, 1};
536 std::vector<int>
word {1};
541 std::vector<std::pair<int,int>> matches;
544 EXPECT_EQ(matches.size(), 0);
549 std::vector<int>
monom1 {1, 0, 1, 2};
550 std::vector<int>
monom2 {1, 0, 2, 2};
551 std::vector<int>
monom3 {1, 0, 1, 0};
552 std::vector<int> monom4 {1, 0};
553 std::vector<int>
word {1, 0, 1, 0, 2, 2, 1, 0, 1, 2};
557 EXPECT_EQ(
monom1.size(), 4);
558 EXPECT_EQ(
monom2.size(), 4);
559 EXPECT_EQ(
monom3.size(), 4);
560 EXPECT_EQ(monom4.size(), 2);
561 EXPECT_EQ(
word.size(), 10);
568 std::vector<std::pair<int,int>> matches;
571 EXPECT_EQ(matches.size(), 6);
572 EXPECT_EQ(matches[0], std::make_pair(0, 6));
573 EXPECT_EQ(matches[1], std::make_pair(1, 2));
574 EXPECT_EQ(matches[2], std::make_pair(2, 0));
575 EXPECT_EQ(matches[3], std::make_pair(3, 0));
576 EXPECT_EQ(matches[4], std::make_pair(3, 2));
577 EXPECT_EQ(matches[5], std::make_pair(3, 6));
582 std::vector<int>
monom1 {1, 0, 1, 2};
583 std::vector<int>
monom2 {1, 0, 2, 2};
584 std::vector<int>
monom3 {1, 0, 1, 0};
585 std::vector<int>
word {1, 0, 1, 0, 2, 2, 1, 0, 1, 2};
586 std::vector<int> word2 {1, 0, 1, 1, 2, 2, 1, 1, 1, 2};
590 EXPECT_EQ(
monom1.size(), 4);
591 EXPECT_EQ(
monom2.size(), 4);
592 EXPECT_EQ(
monom3.size(), 4);
593 EXPECT_EQ(
word.size(), 10);
604 EXPECT_TRUE(isprefix);
605 EXPECT_TRUE(issuffix);
613 EXPECT_TRUE(isprefix);
615 EXPECT_TRUE(issuffix);
624 EXPECT_FALSE(isprefix);
625 EXPECT_FALSE(issuffix);
628std::ostream&
operator<<(std::ostream& o,
const std::vector<Overlap>& val)
633 o <<
"[" << std::get<0>(a) <<
","
634 << std::get<1>(a) <<
","
635 << std::get<2>(a) <<
"]";
638 if (count % 10 == 0) o << std::endl;
644std::ostream&
operator<<(std::ostream& o,
const std::vector<std::pair<int,int>>& val)
649 o <<
"[" << std::get<0>(a) <<
","
650 << std::get<1>(a) <<
"]";
653 if (count % 10 == 0) o << std::endl;
661std::ostream&
operator<<(std::ostream& o,
const std::vector<T>& val)
667 int sz = std::tuple_size<T>::value;
668 for (
auto i=0; i<sz; ++i)
670 o << std::get<i>(a) <<
",";
675 if (count % 10 == 0) o << std::endl;
686 mons = {{Z, X}, {Z, Y}, {Z, Z}, {Y, Y, X}, {Y, Y, Z},
687 {Y, X, Y, Y}, {Y, Y, Y, Y}, {Y, X, Y, X, X},
688 {Y, X, Y, X, Y}, {Y, X, Y, X, Z},
689 {Y, X, X, Y, X, X}, {Y, X, X, Y, X, Z},
693 std::vector<int> m0 {2,0};
694 std::vector<int> m1 {2,1};
695 std::vector<int> m2 {2,2};
696 std::vector<int> m3 {1,1,0};
697 std::vector<int> m4 {1,1,2};
698 std::vector<int> m5 {1,0,1,1};
699 std::vector<int> m6 {1,1,1,1};
700 std::vector<int> m7 {1,0,1,0,0};
701 std::vector<int> m8 {1,0,1,0,1};
702 std::vector<int> m9 {1,0,1,0,2};
703 std::vector<int> m10 {1,0,0,1,0,0};
704 std::vector<int> m11 {1,0,0,1,0,2};
705 std::vector<int> m12 {1,0,0,1,1,1};
707 std::vector<Overlap> overlaps;
708 std::vector<std::pair<int,int>> matches;
712 EXPECT_EQ(0, overlaps.size());
715 EXPECT_EQ(0, overlaps.size());
718 std::vector<Overlap> ans {
719 std::make_tuple(2,1,0,
true),
720 std::make_tuple(2,1,1,
true),
721 std::make_tuple(2,1,2,
true)
723 std::sort(ans.begin(),ans.end());
724 std::sort(overlaps.begin(),overlaps.end());
726 EXPECT_EQ(overlaps, ans);
729 EXPECT_EQ(0, overlaps.size());
744 std::vector<std::pair<int,int>> ans2
752 std::make_pair(12,3),
755 std::sort(ans2.begin(),ans2.end());
756 std::sort(matches.begin(),matches.end());
757 EXPECT_EQ(ans2, matches);
761 EXPECT_TRUE(W.
isNontrivialSuperword(
Word(std::vector<int> {1,1,2,1,1,2,1,1,2}), 4, 4));
764 W.
subwords(
Word(std::vector<int> {2,2,0,1,1,0,1,0,1,1}), matches);
765 std::vector<std::pair<int,int>> ans3
773 std::sort(ans3.begin(),ans3.end());
774 std::sort(matches.begin(),matches.end());
775 EXPECT_EQ(ans3, matches);
Free associative algebra k<x_1,...,x_n> over an arbitrary coefficient ring.
A FreeAlgebra modulo a two-sided ideal carried by an embedded NCGroebner.
Bump-pointer arena allocator for transient inner-loop allocations.
NCGroebner — Buchberger-style two-sided Gröbner basis driver over a FreeAlgebra.
std::vector< int > monom1
std::vector< int > monom2
std::ostream & operator<<(std::ostream &o, const std::vector< Overlap > &val)
std::vector< int > monom3
std::unique_ptr< PolynomialHeap > makePolynomialHeap(HeapType type, const FreeAlgebra &F)
PolynomialHeap abstract interface — batched-subtraction heap for non-commutative reduction.
OverlapTable — degree-sorted queue of pending word overlaps for non-commutative GB drivers.
gc_vector< const Poly * > ConstPolyList
gc_vector< Poly * > PolyList
SuffixTree / SuffixTreeNode — experimental generalised suffix tree for non-commutative leading-word l...
WordTable / WordWithDataTable — leading-word indices for non-commutative Gröbner basis lookup.
ConcreteRing<RingType> — the templated bridge between aring and the legacy Ring API.
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
Word lead_word_prefix(const Poly &f, int endIndex) const
Word lead_word(const Poly &f) 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 > °rees, 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 elem_text_out(buffer &o, const Poly &f, bool p_one, bool p_plus, bool p_parens) const
bool is_equal(const Poly &f, const Poly &g) const
int compare_elems(const Poly &f, const Poly &g) const
Word lead_word_suffix(const Poly &f, int beginIndex) 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.
void setZero(Poly &f) const
void var(Poly &result, int v) const
void negate(Poly &result, const Poly &f) const
Owned Poly value paired with its FreeAlgebraQuotient*, providing operator-overloaded arithmetic for d...
Quotient of a FreeAlgebra by a Groebner basis up to a fixed degree bound.
std::pair< T *, T * > shrinkLastAllocate(T *begin, T *end, T *newtop)
std::pair< T *, T * > allocateArray(size_t nelems)
Thin RAII wrapper around memtailor::Arena providing bump-pointer array allocation with optional mutex...
static MonomialOrdering * GRevLex2(int nvars)
static MonomialOrdering * GRevLex(int nvars)
static MonomialOrdering * GRevLex4(int nvars)
static MonomialOrdering * GroupLex(int nvars)
static MonomialOrdering * Lex(int nvars)
static std::string toString(const MonomialOrdering *mo)
static MonomialOrdering * join(const std::vector< MonomialOrdering * > &M)
static auto createOverlapPoly(const FreeAlgebra &A, const PolyList &polyList, int polyIndex1, int polyIndex2, int overlapIndex) -> Poly *
One-overlap-at-a-time Groebner basis driver for the free associative algebra (the "Naive" companion t...
auto insert(int deg, bool isGenerator, Overlap o) -> void
auto isFinished() const -> bool
auto size() const -> size_t
Per-degree FIFO queue of pending overlaps for the NC Groebner basis driver to process.
virtual ring_elem from_long(long n) const =0
Baseline PolynomialHeap implementation that simply accumulates the pending sum in a single Poly and w...
const int * begin() const
Non-owning view of a non-commutative word: [begin, end) of int variable indices.
size_t monomialCount() const
void superwords(Word word, std::vector< std::pair< int, int > > &output) const
bool isPrefix(Word word, int &output) const
bool isSuffix(Word word, int &output) const
void subwords(Word word, std::vector< std::pair< int, int > > &output) const
auto isNontrivialSuperword(Word word, int index1, int index2) const -> bool
void leftOverlaps(std::vector< Overlap > &newLeftOverlaps) const
Index of Words (non-commutative monomials) with subword, prefix/suffix, and overlap lookup used by th...
const char * error_message()
Monoid — variable count, naming, grading, and monomial order of a polynomial ring.
int moIsLex(const MonomialOrdering *mo)
int moIsGRevLex(const MonomialOrdering *mo)
int rawNumberOfVariables(const MonomialOrdering *mo)
MonomialOrderings — C++ factories for the declarative MonomialOrdering blocks.
Concrete commutative PolyRing — standard polynomial ring inheriting from PolyRingFlat.
Engine-boundary C API for the legacy Ring hierarchy — coefficient, polynomial, and composite rings.
Front-end-side description of a monomial ordering as a list of mon_part blocks.
const PolynomialRing * degreeRing(const std::vector< std::string > &names)
One-line helpers for building degree monoids and polynomial rings inside gtest cases.