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

◆ elem_text_out()

void FreeAlgebra::elem_text_out ( buffer & o,
const Poly & f,
bool p_one,
bool p_plus,
bool p_parens ) const

Definition at line 780 of file FreeAlgebra.cpp.

785{
786 if (f.numTerms() == 0)
787 {
788 o << "0";
789 return;
790 }
791
792 bool two_terms = (f.numTerms() > 1);
793 bool needs_parens = p_parens && two_terms;
794 if (needs_parens)
795 {
796 if (p_plus) o << '+';
797 o << '(';
798 p_plus = false;
799 }
800
801 for (auto i = f.cbegin(); i != f.cend(); i++)
802 {
803 bool is_one = monoid().is_one(i.monom());
804 p_parens = !is_one;
805 bool p_one_this = (is_one && needs_parens) || (is_one && p_one);
806 coefficientRing()->elem_text_out(o, i.coeff(), p_one_this, p_plus, p_parens);
807 if (!is_one)
808 monoid().elem_text_out(o, i.monom());
809 p_plus = true;
810 }
811
812 if (needs_parens) o << ')';
813}
const Ring * coefficientRing() const
const FreeMonoid & monoid() const
void elem_text_out(buffer &o, const Monom &m1) const
bool is_one(const Monom &m) const
virtual void elem_text_out(buffer &o, const ring_elem f, bool p_one=true, bool p_plus=false, bool p_parens=false) const =0

References coefficientRing(), FreeMonoid::elem_text_out(), Ring::elem_text_out(), FreeMonoid::is_one(), and monoid().

Referenced by M2FreeAlgebra::elem_text_out(), operator<<(), TEST(), and TEST().