= Solution
The coefficient type is not assumed to be ordered, so do not require a sign or absolute-value operation beyond the supplied output routine. Parenthesize coefficients to keep negative or compound values unambiguous:
``
OutPoly(p):
first = true
while p != NIL:
if p.coeff != 0:
if not first: Out.String("+")
Out.String("("); OutT(p.coeff); Out.String(")")
if p.power != 0:
Out.String("*x")
if p.power != 1:
Out.String("^"); Out.Int(p.power)
first = false
p = p.next
if first: OutT(0)
``
For example, the representation in the question can print \b[`(-1)+(1)*x^2`], which denotes the same polynomial. If $T$ additionally provides ordered-real sign operations, cosmetic suppression of `+(-...)` and unit coefficients can produce `-1+x^2`. The generic routine already handles the zero polynomial and preserves the represented value without introducing those extra assumptions.
Back to article page