221{
222
223 if (f == nullptr)
224 {
225 o << "0";
226 return;
227 }
228
230 bool needs_parens = p_parens && (nterms >= 2);
231
232 if (needs_parens)
233 {
234 if (p_plus) o << '+';
235 o << '(';
236 p_plus = false;
237 }
238
239 bool one =
is_one(level, f);
240
241 if (one)
242 {
243 if (p_plus) o << "+";
244 if (p_one) o << "1";
245 return;
246 }
247
248 const std::string &this_varname =
varNames()[level];
249
250 if (level == 0)
251 {
252 bool firstterm = true;
253 for (int i = f->deg; i >= 0; i--)
254 if (f->coeffs[i] != 0)
255 {
256 if (!firstterm || p_plus) o << "+";
257 firstterm = false;
258 if (i == 0 || f->coeffs[i] != 1)
259 mBaseRing.elem_text_out(o, f->coeffs[i], p_one, p_plus, p_parens);
260 if (i > 0) o << this_varname;
261 if (i > 1) o << i;
262 }
263 if (needs_parens) o << ")";
264 }
265 else
266 {
267 bool firstterm = true;
268 for (int i = f->deg; i >= 0; i--)
269 if (f->polys[i] != nullptr)
270 {
271 bool this_p_parens = p_parens || (i > 0);
272
273 if (i == 0 || !
is_one(level - 1, f->polys[i]))
275 level - 1,
276 f->polys[i],
277 p_one,
278 p_plus || !firstterm,
279 this_p_parens);
280 else if (p_plus || !firstterm)
281 o << "+";
282 if (i > 0) o << this_varname;
283 if (i > 1) o << i;
284
285 firstterm = false;
286 }
287 if (needs_parens) o << ")";
288 }
289}
const std::vector< std::string > & varNames() const
bool is_one(int level, const ARingPolynomial f) const
const ARingZZpFFPACK & mBaseRing
void elem_text_out(buffer &o, ElementType a, bool p_one=true, bool p_plus=false, bool p_parens=false) const
static int n_nonzero_terms(int level, const TowerPolynomial f)