random() < 0.25 1 randRangeNonZero( -10, 10 ) 1 SQUARE ? B : randRangeNonZero( -10, 10 ) "x" "x^2" "\\left(" + plus( A+X, B ) + "\\right)" "\\left(" + plus( C+X, D ) + "\\right)"

LEFT + ( SQUARE ? "^2" : RIGHT ) = \ ?

plus( (A*C)+XX, (A*D+B*C)+X, B*D )

  • plus( XX, B*D )
  • plus( XX, B*D )
  • plus( (A+C)+XX, (A*D+B*C)+X, B*D )
  • plus( (A*C)+XX, (A*D+B*C)+X, B+D )
  • plus( (A+C)+XX, (A*D+B*C)+X, B+D )
  • plus( (A+C)+XX, (A*D-B*C)+X, B*D )
  • plus( (A*C)+XX, (A*D-B*C)+X, B+D )
  • plus( (A+C)+XX, (A*D-B*C)+X, B+D )
  • plus( (A+C)+XX, (A*B+C*D)+X, B*D )
  • plus( (A*C)+XX, (A*B+C*D)+X, B+D )
  • plus( (A+C)+XX, (A*B+C*D)+X, B+D )
  • plus( (A+C)+XX, (A*B-C*D)+X, B*D )
  • plus( (A*C)+XX, (A*B-C*D)+X, B+D )
  • plus( (A+C)+XX, (A*B-C*D)+X, B+D )

= LEFT + RIGHT

Start by distributing the parseFormat( "( #{x} " + signOp( B ) + "#{" + B + "})", [ BLUE, BLUE ] ):

\qquad = \quad parseFormat( "( #{x} " + signOp( B ) + "#{" + B + "})( #{x} " + signOp( D ) + "#{" + D + "})", [ BLUE, BLUE, PINK, PINK ] )

\qquad = \quad parseFormat( "#{x} ( #{x} " + signOp( D ) + "#{" + D + "})" + signOp( B ) + "#{" + B + "}( #{x} " + signOp( D ) + "#{" + D + "})", [ BLUE, PINK, PINK, BLUE, PINK, PINK ] )

Next, distribute the x and the B:

\qquad = \quad parseFormat( "(#{x} \\cdot #{x}) + (#{x} \\cdot #{" + D + "}) + (#{" + B + "} \\cdot #{x}) + (#{" + B + "} \\cdot #{" + D + "})", [ BLUE, PINK, BLUE, PINK, BLUE, PINK, BLUE, PINK ] )

Notice that by distributing you're really just multiplying each term in the first expression by each term in the second expression.

Simplify:

\qquad = \quad parseFormat( plus( "x^2", D + "x", B + "x", ( B * D ) ) )

Keep simplifying to get the final answer:

\qquad = \quad parseFormat( plus( "x^2", ( D + B ) + "x", ( B * D ) ) )