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

◆ elem_text_out()

void DPoly::elem_text_out ( buffer & o,
int level,
const TowerPolynomial f,
bool p_one,
bool p_plus,
bool p_parens,
M2_ArrayString names ) const

Definition at line 144 of file dpoly.cpp.

151{
152 // o << to_string(level, f);
153 if (f == nullptr)
154 {
155 o << "0";
156 return;
157 }
158
159 int nterms = n_nonzero_terms(level, f);
160 bool needs_parens = p_parens && (nterms >= 2);
161
162 if (needs_parens)
163 {
164 if (p_plus) o << '+';
165 o << '(';
166 p_plus = false;
167 }
168
169 bool one = is_one(level, f);
170
171 if (one)
172 {
173 if (p_plus) o << "+";
174 if (p_one) o << "1";
175 return;
176 }
177
178 M2_string this_varname = names->array[level];
179
180 if (level == 0)
181 {
182 bool firstterm = true;
183 for (int i = f->deg; i >= 0; i--)
184 if (f->arr.ints[i] != 0)
185 {
186 if (!firstterm || p_plus) o << "+";
187 firstterm = false;
188 if (i == 0 || f->arr.ints[i] != 1) o << f->arr.ints[i];
189 if (i > 0) o << this_varname;
190 if (i > 1) o << i;
191 }
192 if (needs_parens) o << ")";
193 }
194 else
195 {
196 bool firstterm = true;
197 for (int i = f->deg; i >= 0; i--)
198 if (f->arr.polys[i] != nullptr)
199 {
200 bool this_p_parens = p_parens || (i > 0);
201
202 if (i == 0 || !is_one(level - 1, f->arr.polys[i]))
204 level - 1,
205 f->arr.polys[i],
206 p_one,
207 p_plus || !firstterm,
208 this_p_parens,
209 names);
210 else if (p_plus || !firstterm)
211 o << "+";
212 if (i > 0) o << this_varname;
213 if (i > 1) o << i;
214
215 firstterm = false;
216 }
217 if (needs_parens) o << ")";
218 }
219}
void elem_text_out(buffer &o, int level, const TowerPolynomial f, bool p_one, bool p_plus, bool p_parens, M2_ArrayString names) const
Definition dpoly.cpp:144
static bool is_one(int level, const TowerPolynomial f)
Definition dpoly.cpp:595
static int n_nonzero_terms(int level, const TowerPolynomial f)
Definition dpoly.cpp:127

References elem_text_out(), is_one(), and n_nonzero_terms().

Referenced by elem_text_out(), and extensions_text_out().