public override string ToString() { var result = new StringBuilder(8 * GetDegree()); for (var degree = GetDegree(); degree >= 0; degree--) { var coefficient = GetCoefficient(degree); if (coefficient != 0) { if (coefficient < 0) { result.Append(" - "); coefficient = -coefficient; } else { if (result.Length > 0) { result.Append(" + "); } } if (degree == 0 || coefficient != 1) { var alphaPower = field.Log(coefficient); if (alphaPower == 0) { result.Append('1'); } else if (alphaPower == 1) { result.Append('a'); } else { result.Append("a^"); result.Append(alphaPower); } } if (degree != 0) { if (degree == 1) { result.Append('x'); } else { result.Append("x^"); result.Append(degree); } } } } return(result.ToString()); }