randVar() 7 [BLUE, RED, GREEN, PURPLE] 2 + (random() < 0.25 ? 1 : 0) [randFromArray(["-", "+"]), randFromArray(["-", "+"])].slice(0, N - 1) _.any(SIGNS, function(s) { return s === "-"; }) _(N).times(function(term) { return randRange(2, 5 - N); }) randRangeUnique(1, MAX_DEGREE, 4) sortNumbers(NON_ZERO_INDICES).reverse() tabulate(function(p) { var coefs = []; var terms = shuffle(NON_ZERO_INDICES).slice(0, TERMS[p]); for (var i = 0; i <= MAX_DEGREE; i++) { if (terms.indexOf(i) !== -1) { coefs[i] = randRangeNonZero(-7, 7); } else { coefs[i] = 0; } } return new Polynomial(0, MAX_DEGREE, coefs, X); }, N) (function() { var sol = POLYNOMIALS[0]; for (var i = 1; i < N; i++) { sol = sol.add(POLYNOMIALS[i]); } return sol; })() (function() { var coeffs = [[], [], [], []]; var toRemove = []; for (var j = 0; j < 4; j++) { for (var i = 0; i < POLYNOMIALS.length; i++) { var coefficient = POLYNOMIALS[i].coefs[SORTED_INDICES[j]]; if (coefficient !== 0) { coeffs[j].push(coefficient); } } if (coeffs[j].length === 0) { toRemove.push(j); } } toRemove = sortNumbers(toRemove); for (var i = 0; i < toRemove.length; i++) { coeffs.splice(toRemove[i], 1); SORTED_INDICES.splice(toRemove[i], 1); } return coeffs; })()

Simplify the expression.

(POLYNOMIALS[0]) SIGNS[0] (POLYNOMIALS[1] POLYNOMIALS[1].multiply(-1)) SIGNS[1] (POLYNOMIALS[2] POLYNOMIALS[2].multiply(-1))

SOLUTION.parsableText()

Distribute any negative signs.

(POLYNOMIALS[0]) + (POLYNOMIALS[1]) + (POLYNOMIALS[2])

Since we are adding polynomials, we can simply remove the parentheses.

POLYNOMIALS[0] + POLYNOMIALS[1] + POLYNOMIALS[2]

Identify like terms.

(POL.coefs[index] < 0) ? "-" : (n === 0 && POL === POLYNOMIALS[0]) ? "" : "+" \color{COLORS[ n ]}{abs(POL.coefs[index]) === 1 ? "" : abs(POL.coefs[index]) X^index}

Combine like terms.

+ \color{COLORS[index1]}{ coeff[0] ( + TERM ) X^SORTED_INDICES[index1]}

Add the coefficients.

SOLUTION