# Khan/khan-exercises

allowing free input for diff of squares 3, fixing factoring_polynomia…

`…ls_3, renaming factoring_simple_expresions into common_factors_of_a_polynamial`
1 parent e8263c5 commit f6df2fbb902f8bc89655deeb51ed962abdf547d6 mathiash committed Apr 12, 2012
33 exercises/common_factors_of_a_polynomial_1.html
 @@ -0,0 +1,33 @@ + + + + + Common factors of a polynomial 1 + + + +
+
+ {op:"var", args:["x"]} + {op:"var", args:["y"]} + {op:"var", args:["z"]} + genFactoringExercise([2, 3, 5, 7, X, Y, Z], 2, 3) + solveFactoringExercise(PROBLEM.question) +
+
+
+

Factor the following expression by finding the common factors of its terms:

+

format(PROBLEM.question)

+

format(SOLUTION.solution)

+ +
+
• format(value)
• +
+
+
+
+
value
+
+
+ +
34 exercises/common_factors_of_a_polynomial_2.html
 @@ -0,0 +1,34 @@ + + + + + Common factors of a polynomial 2 + + + +
+
+ {op:"var", args:["w"]} + {op:"var", args:["x"]} + {op:"var", args:["y"]} + {op:"var", args:["z"]} + genFactoringExercise([2, 3, 5, 7, W, X, Y, Z], 3, 4) + solveFactoringExercise(PROBLEM.question) +
+
+
+

Factor the following expression by finding the common factors of its terms:

+

format(PROBLEM.question)

+

format(SOLUTION.solution)

+ +
+
• format(value)
• +
+
+
+
+
value
+
+
+ +
102 exercises/factoring_difference_of_squares_3.html
 @@ -1,46 +1,68 @@ - + - - Factoring difference of squares 3 - - + + Factoring difference of squares 3 + -
-
-
-
- MathModel.init() - randFromArray([2,3,5]) - randRange( 2, 6 ) - randRange( 1, 6 ) - F * A * A - F * -B * B - MATH.parse(SQUARE + "x^2" + CONSTANT) - solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:true}) -
-
-

- Factor the following expression: -

-

- MATH.format(PROBLEM) -

-
-
-

F(Ax - B)(Ax + B)

-

enter a (possibly negative) integer for each input area.

-
-
-
-
-
value
-
-
+
+
+
+
+ randFromArray([2,3,5]) + randRange(2, 6) + randRange(1, 6) + F * A * A + F * -B * B + parse(SQUARE + "x^2" + CONSTANT) + solveFactoringExercise(PROBLEM, {factorDiffOfSquares:true}) + SOLUTION.solution.args[1].args[0].args[0].args[0] + SOLUTION.solution.args[1].args[1].args[1] + + parse(F + "(" + a + "x" + "-" + b + ")(" + a + "x" + "+" + b + ")") + parse(F + "(" + a + "x" + "+" + b + ")(" + a + "x" + "-" + b + ")") + parse(-F + "(" + -a + "x" + "+" + b + ")(" + a + "x" + "+" + b + ")") + parse(-F + "(" + a + "x" + "-" + b + ")(" + -a + "x" + "-" + b + ")") + parse(-F + "(" + a + "x" + "+" + b + ")(" + -a + "x" + "+" + b + ")") + parse(-F + "(" + -a + "x" + "-" + b + ")(" + a + "x" + "-" + b + ")") +
+
+

+ Factor the following expression: +

+

+ format(PROBLEM) +

+
+
+
+ +
+
\$( "div.instruction input" ).val()
+
+ var exprGuess = simplify(parse(guess), simplifyOptions.checkInput); + return (isEqual(exprGuess, SOL1) || isEqual(exprGuess, SOL2) || isEqual(exprGuess, SOL3) || + isEqual(exprGuess, SOL4) || isEqual(exprGuess, SOL5) || isEqual(exprGuess, SOL6)); +
+
+
+
+ \$( "div.instruction input" ).val( guess ); +
+
a factored expression, like (x+1)(x+3)
+
+ +
+
+
+
value
+
+
102 exercises/factoring_difference_of_squares_4.html
 @@ -1,61 +1,53 @@ - + - - Factoring difference of squares 4 - - + + Factoring difference of squares 4 + + -
-
-
-
- MathModel.init() - randFromArray([2,3,5]) - randRange( 2, 6 ) - randRange( 1, 6 ) - randRange( 2, 3 ) - F * A * A - F * -B * B - MATH.parse(SQUARE + "x^" + (2*P) + CONSTANT) - solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:true}) - [ - MATH.format(solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:false}).solution), - MATH.format(solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:"a^2-b^2=(a-b)^2"}).solution), - MATH.format(solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:"a^2-b^2=(a-b)(b-a)"}).solution), - MATH.format(solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:"a^2-b^2 = (a^2-b^2)(a^2+b^2)"}).solution), - MATH.format(solveFactoringExercise(MATH, PROBLEM, {factorDiffOfSquares:true, factorWithDiffOfSquares:"a(b^2-c^2)=(ab-ac)(a+c))"}).solution), - ] -
-
-

- Factor the following expression: -

-

- MATH.format(PROBLEM) -

-
-

MATH.format(SOLUTION.solution)

- -
-
• value
• -
- -
-
-
-
value
-
-
+
+
+
+
+ randFromArray([2,3,5]) + randRange( 2, 6 ) + randRange( 1, 6 ) + randRange( 2, 3 ) + F * A * A + F * -B * B + parse(SQUARE + "x^" + (2*P) + CONSTANT) + solveFactoringExercise(PROBLEM, {factorDiffOfSquares:true}) + [ + format(solveFactoringExercise(PROBLEM, {factorDiffOfSquares:false}).solution), + format(solveFactoringExercise(PROBLEM, {factorDiffOfSquares:"a^2-b^2=(a-b)^2"}).solution), + format(solveFactoringExercise(PROBLEM, {factorDiffOfSquares:"a^2-b^2=(a-b)(b-a)"}).solution), + format(solveFactoringExercise(PROBLEM, {factorDiffOfSquares:"a^2-b^2 = (a^2-b^2)(a^2+b^2)"}).solution), + format(solveFactoringExercise(PROBLEM, {factorDiffOfSquares:true, factorWithDiffOfSquares:"a(b^2-c^2)=(ab-ac)(a+c))"}).solution), + ] +
+
+

+ Factor the following expression: +

+

+ format(PROBLEM) +

+
+

format(SOLUTION.solution)

+
+
• value
• +
+
+
+
+
value
+
+
189 exercises/factoring_polynomials_3.html
 @@ -1,100 +1,103 @@ - + - - Factoring polynomials 3 - + + Factoring polynomials 3 + -
-
-
-
- MathModel.init() - randRange( 2, 9 ) - randFromArray([ -1, 1 ]) - randFromArrayExclude( [ 3, 5, 7, 9 ], [ a ] ) - b_sign*b_abs - randFromArrayExclude( getFactors( a * b_abs ), [ 1 ] ) - a + b - a * b / A - getGCD( A, a ) - b_sign * getGCD( b_abs, C ) - simplify(MATH.polynomial([A, B, C], "x"), simplifyOptions.basic) - - MATH.parse( "#{(" + F1 + "x+" + F2 + ")(" + A / F1 + "x+" + a / F1 + ")}", [ORANGE] ) - MATH.parse("#{" + F1 + "x(" + A / F1 + "x+" + a / F1 + ")+" + F2 + "(" + b / F2 + "x+" + C / F2 + ")}", [BLUE] ) - [MATH.parse("#{ab &=& A*C}#{ &=& " + (A*C) + "}", [BLUE,BLUE]), MATH.parse("#{a+b &=& B}#{ &=& " + B + "}", [BLUE, BLUE])] +
+
+
+
+ randRange(2, 9) + randFromArray([-1, 1]) + randFromArrayExclude([3, 5, 7, 9], [a]) + b_sign*b_abs + randFromArrayExclude(getFactors(a * b_abs), [1]) + a + b + a * b / A + getGCD(A, a) + b_sign * getGCD(b_abs, C) + simplify(polynomial([A, B, C], "x"), simplifyOptions.basic) + + parse("(" + F1 + "x+" + F2 + ")(" + A / F1 + "x+" + a / F1 + ")") + parse(F1 + "x(" + A / F1 + "x+" + a / F1 + ")+" + F2 + "(" + b / F2 + "x+" + C / F2 + ")}") + [parse("#{ab} &=& #{A}*#{C} &=& " + (A*C), [GREEN, BLUE, ORANGE]), + parse("#{a}+#{b} &=& #{B} &=& #{" + B, [GREEN, GREEN, PINK])] -
-
-

- Factor the following expression: -

-

- MATH.format( PROBLEM, "large" ) -

-
-
-
- -
-
jQuery( "div.instruction input" ).val()
-
- return isEqual( MATH.parse( guess ), SOLUTION ); -
-
-
-
- jQuery( "div.instruction input" ).val( guess ); -
-
a factored expression, like (x+1)(x+2)
-
-
-

- The expression is of the form - MATH.parseFormat("#{Ax^2+Bx+C}", [BLUE], false, "normalsize"). - You can factor this trinomial by grouping. -

-
-

To do this, the first step is to find two values - MATH.parseFormat("#a", [BLUE]) and - MATH.parseFormat("#b", [BLUE]), such that - MATH.parseFormat("#{ab = A*C}", [BLUE]), and - MATH.parseFormat("#{a+b = B}", [BLUE]). The next step is to rewrite the - expression as MATH.parseFormat("Ax^2 + ax + bx + C", [BLUE]) or - MATH.parseFormat("(Ax^2 + ax) + (bx + C)"), and factor each term, to - find a common factor.

-
-
-

To apply the first step, you need to find - MATH.parseFormat("#a", [BLUE]) and - MATH.parseFormat("#b", [BLUE]) such that:

-

MATH.formatGroup(GROUP1, [0,1])

-
-
-

The following values can be used:

-

MATH.parseFormat("#{a="+a+"}", [BLUE])
- MATH.parseFormat("#{b="+b+"}", [BLUE])

-
-
-

For the second step, rewrite the expression as:

-

MATH.parseFormat("#{" + A + "x^2+" + a + "x+" + b + "x+" + C + "}", [BLUE], false, "normalsize")

-

or

MATH.parseFormat("#{(" + A + "x^2+" + a + "x)+(" + b + "x+" + C + ")}", [BLUE], false, "normalsize")

-

The next step is to factor both terms of the above expression

-
-

- MATH.format(simplify(HINT1, {del1factors:true, evalBasicNumOps:true})) -

-

- Redistribute the common term to get the answer. -

-

- MATH.format(simplify(SOLUTION, simplifyOptions.basic), false, "large") -

-
-
-
-
+
+
+

+ Factor the following expression: +

+

+ format(PROBLEM, "large") +

+
+
+
+ +
+
jQuery("div.instruction input").val()
+
+ return isEqual(parse(guess), SOLUTION); +
+
+
+
+ jQuery("div.instruction input").val(guess); +
+
a factored expression, like (x+1)(x+2)
+
+
+
+

The expression is of the form + parseFormat("#{A}x^2+#{B}x+#{C}}", [BLUE, PINK, ORANGE]). + You can factor this trinomial by grouping. In this case, + \blue{A}=\blue{A}, \green{B}=\green{B}, + \orange{C}=\orange{C} +

+
+
+

To do this, the first step is to find two values + \green{a} and + \green{b}, such that:

+

parseFormat("#{ab} = #{A}*#{C}", [GREEN, BLUE, ORANGE])

+

parseFormat("#{a}+#{b} = #{B}", [GREEN, GREEN, PINK])

+

The next step is to rewrite the + expression as parseFormat("#{A}x^2 + #{a}x + #{b}x + #{C}", [BLUE, GREEN, GREEN, ORANGE]) or + parseFormat("(#{A}x^2 + #{a}x) + (#{b}x + #{C})", [BLUE, GREEN, GREEN, ORANGE]), and factor each term, to + find a common factor.

+
+
+

To apply the first step, you need to find + \green{a} and \green{b} such that:

+

formatGroup(GROUP1, [0,1])

+
+
+

The following values can be used:

+

parseFormat("#{a}=#{" + a + "}", [GREEN, GREEN])
+ parseFormat("#{b}=#{" + b + "}", [GREEN, GREEN])

+
+
+

For the second step, rewrite the expression as:

+

parseFormat("#{" + A + "}x^2+#{" + a + "}x+#{" + b + "}x+#{" + C + "}}", [BLUE, GREEN, GREEN, ORANGE])

+

or

parseFormat("(#{" + A + "}x^2+#{" + a + "}x)+(#{" + b + "}x+#{" + C + "})", [BLUE, GREEN, GREEN, ORANGE])

+

The next step is to factor both terms of the above expression:

+
+

+ format(HINT1, {del1factors:true, evalBasicNumOps:true}) +

+

+ Redistribute the common term to get the answer: +

+

+ format(SOLUTION, simplifyOptions.basic, false, "large") +

+
+
+
+
34 exercises/factoring_simple_expressions_1.html
 @@ -1,34 +0,0 @@ - - - - - Factoring simple expressions 1 - - - -
-
- MathModel.init() - {op:"var", args:["x"]} - {op:"var", args:["y"]} - {op:"var", args:["z"]} - genFactoringExercise(MATH, [2, 3, 5, 7, X, Y, Z], 2, 3) - solveFactoringExercise(MATH, PROBLEM.question) -
-
-
-

Factor the following expression by finding the common factors of its terms:

-

MATH.format(PROBLEM.question)

-

MATH.format(SOLUTION.solution)

- -
-
• MATH.format(value)
• -
-
-
-
-
value
-
-
- -
35 exercises/factoring_simple_expressions_2.html
 @@ -1,35 +0,0 @@ - - - - - Factoring simple expressions 2 - - - -
-
- MathModel.init() - {op:"var", args:["w"]} - {op:"var", args:["x"]} - {op:"var", args:["y"]} - {op:"var", args:["z"]} - genFactoringExercise(MATH, [2, 3, 5, 7, W, X, Y, Z], 3, 4) - solveFactoringExercise(MATH, PROBLEM.question) -
-
-
-

Factor the following expression by finding the common factors of its terms:

-

MATH.format(PROBLEM.question)

-

MATH.format(SOLUTION.solution)

- -
-
• MATH.format(value)
• -
-
-
-
-
value
-
-
- -
54 exercises/simplifying_rational_expressions_1.html
 @@ -1,36 +1,34 @@ - - Simplifying rational expressions 1 - + + Simplifying rational expressions 1 + -
-
- MathModel.init() - {op:"var", args:["w"]} - {op:"var", args:["x"]} - {op:"var", args:["y"]} - {op:"var", args:["z"]} - genSimplifyingExpressionsExercise(MATH, 4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3]) - solveSimplifyingExpressionsExercise(MATH, PROBLEM)--> -
-
-
-

Simplify the following expression:

-

MATH.format(PROBLEM)

-

MATH.format(SOLUTION.solution)

+
+
+ {op:"var", args:["w"]} + {op:"var", args:["x"]} + {op:"var", args:["y"]} + {op:"var", args:["z"]} + genSimplifyingExpressionsExercise(4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3]) + solveSimplifyingExpressionsExercise(PROBLEM)--> +
+
+
+

Simplify the following expression:

+

format(PROBLEM)

+

format(SOLUTION.solution)

-
-
• MATH.format(value)
• -
- -
-
-
-
value
-
-
+
+
• format(value)
• +
+
+
+
+
value
+
+
56 exercises/simplifying_rational_expressions_2.html
 @@ -1,36 +1,34 @@ - + - - Simplifying rational expressions 2 - + + Simplifying rational expressions 2 + -
-
- MathModel.init() - {op:"var", args:["w"]} - {op:"var", args:["x"]} - {op:"var", args:["y"]} - {op:"var", args:["z"]} - genSimplifyingExpressionsExercise(MATH, 4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3], true) - solveSimplifyingExpressionsExercise(MATH, PROBLEM)--> -
-
-
-

Simplify the following expression:

-

MATH.format(PROBLEM)

-

MATH.format(SOLUTION.solution)

+
+
+ {op:"var", args:["w"]} + {op:"var", args:["x"]} + {op:"var", args:["y"]} + {op:"var", args:["z"]} + genSimplifyingExpressionsExercise(4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3], true) + solveSimplifyingExpressionsExercise(PROBLEM) +
+
+
+

Simplify the following expression:

+

format(PROBLEM)

+

format(SOLUTION.solution)

-
-
• MATH.format(value)
• -
- -
-
-
-
value
-
-
+
+
• format(value)
• +
+
+
+
+
value
+
+
56 utils/factoring-expressions.js
 @@ -21,7 +21,7 @@ return 1; }; - var factorDiffOfSquares = function(MATH, expr, options) { + var factorDiffOfSquares = function(expr, options) { var terms = []; for (var iArg = 0; iArg < 2; iArg++) { var term = {factors: [], occFactors: []}; @@ -61,18 +61,18 @@ } else { var coloredExpr = {op: "-", args: [KhanUtil.exprSetStyle(termA.initial, KhanUtil.PINK), KhanUtil.exprSetStyle(termB.initial, KhanUtil.BLUE)]}; - var initialForm = MATH.parseFormat("#{a^2} - #{b^2}", [KhanUtil.PINK, KhanUtil.BLUE]); - var factoredForm = MATH.parseFormat("(#a + #b)(#a - #b)", [KhanUtil.PINK, KhanUtil.BLUE, KhanUtil.PINK, KhanUtil.BLUE]); - hints.push("

" + MATH.format(coloredExpr) + "

The expression is of the form " + initialForm + + var initialForm = KhanUtil.parseFormat("#{a^2} - #{b^2}", [KhanUtil.PINK, KhanUtil.BLUE]); + var factoredForm = KhanUtil.parseFormat("(#a + #b)(#a - #b)", [KhanUtil.PINK, KhanUtil.BLUE, KhanUtil.PINK, KhanUtil.BLUE]); + hints.push("

" + KhanUtil.format(coloredExpr) + "

The expression is of the form " + initialForm + " which is a difference of two squares so we can factor it as " + factoredForm + "

"); - var strA = MATH.parseFormat("#a", [KhanUtil.PINK]); - var strB = MATH.parseFormat("#b", [KhanUtil.BLUE]); + var strA = KhanUtil.parseFormat("#a", [KhanUtil.PINK]); + var strB = KhanUtil.parseFormat("#b", [KhanUtil.BLUE]); hints.push("

What are the values of " + strA + " and " + strB + "?

"); var varA = {op: "var", args: ["a"]}; var varB = {op: "var", args: ["b"]}; var exprA = {op: "=", args: [varA, {op: "sqrt", args: [termA.initial]}, termA.sqrt], style: KhanUtil.PINK}; var exprB = {op: "=", args: [varB, {op: "sqrt", args: [termB.initial]}, termB.sqrt], style: KhanUtil.BLUE}; - hints.push("

" + MATH.format(exprA) + "

" + MATH.format(exprB) + "

"); + hints.push("

" + KhanUtil.format(exprA) + "

" + KhanUtil.format(exprB) + "

"); hints.push("

Use the values we found for " + strA + " and " + strB + " to complete the factored expression, " + factoredForm + "

"); var coloredFactored = KhanUtil.exprClone(solution); for (var iArg1 = 0; iArg1 < 2; iArg1++) { @@ -81,7 +81,7 @@ coloredFactored.args[iArg1].args[iArg2] = KhanUtil.exprSetStyle(coloredFactored.args[iArg1].args[iArg2], colors[iArg2]); } } - hints.push("

So we can factor the expression as:" + MATH.format(coloredFactored) + ""); + hints.push("

So we can factor the expression as:" + KhanUtil.format(coloredFactored) + ""); } return {solution: solution, hints: hints}; }; @@ -291,7 +291,7 @@ return listFactors; } - var genHintListFactors = function(MATH, factors, occFactors) { + var genHintListFactors = function(factors, occFactors) { var listFactors = genListFactors(factors, occFactors); var strListFactors = ""; for (var iListedFactor = 0; iListedFactor < listFactors.length; iListedFactor++) { @@ -302,17 +302,17 @@ strListFactors += ", "; } } - strListFactors += "" + MATH.format(KhanUtil.exprSetStyle(listFactors[iListedFactor], KhanUtil.BLUE)) + ""; + strListFactors += "" + KhanUtil.format(KhanUtil.exprSetStyle(listFactors[iListedFactor], KhanUtil.BLUE)) + ""; } if (listFactors.length === 1) { return "

The terms have one common factor: " + strListFactors + ".

"; } else { - var gcf = MATH.format(KhanUtil.exprSetStyle(KhanUtil.genExprFromExpFactors(factors, occFactors), KhanUtil.BLUE)); + var gcf = KhanUtil.format(KhanUtil.exprSetStyle(KhanUtil.genExprFromExpFactors(factors, occFactors), KhanUtil.BLUE)); return "

The terms have these common factors: " + strListFactors + ", so the greatest common factor is " + gcf + ".

"; } }; - var genHintsDecomposeAllFactors = function(MATH, factors, sharedOccFactors, termsOccFactors) { + var genHintsDecomposeAllFactors = function(factors, sharedOccFactors, termsOccFactors) { var colors = [KhanUtil.PINK, KhanUtil.ORANGE, KhanUtil.GREEN]; var nbTerms = termsOccFactors.length; var hints = []; @@ -322,16 +322,16 @@ } expr = KhanUtil.simplify(expr, KhanUtil.simplifyOptions.checkInput); - hints.push("

" + MATH.format(expr) + "

We start by decomposing each term into a product of its most simple factors.

"); + hints.push("

" + KhanUtil.format(expr) + "

We start by decomposing each term into a product of its most simple factors.

"); for (var iTerm = 0; iTerm < nbTerms; iTerm++) { var mergedOccFactors = mergeOccFactors(sharedOccFactors, termsOccFactors[iTerm]); - hints.push("

" + MATH.format(KhanUtil.exprSetStyle(genDecomposition(factors, mergedOccFactors), {color: colors[iTerm]})) + "

"); + hints.push("

" + KhanUtil.format(KhanUtil.exprSetStyle(genDecomposition(factors, mergedOccFactors), {color: colors[iTerm]})) + "

"); } - hints.push(genHintListFactors(MATH, factors, sharedOccFactors)); + hints.push(genHintListFactors(factors, sharedOccFactors)); - hints.push("

We can rewrite the expression as: " + MATH.format({op: "+", args: genAllTermsMarkShared(factors, sharedOccFactors, termsOccFactors, colors)}) + ".

"); - hints.push("

We now rewrite the expression as a product: " + MATH.format(genFullExpr(factors, sharedOccFactors, termsOccFactors)) + ".

"); + hints.push("

We can rewrite the expression as: " + KhanUtil.format({op: "+", args: genAllTermsMarkShared(factors, sharedOccFactors, termsOccFactors, colors)}) + ".

"); + hints.push("

We now rewrite the expression as a product: " + KhanUtil.format(genFullExpr(factors, sharedOccFactors, termsOccFactors)) + ".

"); return hints; }; @@ -352,18 +352,18 @@ } }; - var solveDiffOfSquaresExercise = function(MATH, expr, options) { + var solveDiffOfSquaresExercise = function(expr, options) { if (KhanUtil.exprIsNumber(expr) || (expr.args.length != 2)) { return undefined; } if (expr.op === "-") { var sumExpr = {op: "+", args: [expr.args[0], {op: "-", args: [expr.args[1]]}]}; - return solveDiffOfSquaresExercise(MATH, sumExpr, options); + return solveDiffOfSquaresExercise(sumExpr, options); } - return factorDiffOfSquares(MATH, expr, options); + return factorDiffOfSquares(expr, options); }; - var solveFactoringExercise = function(MATH, expr, options) { + var solveFactoringExercise = function(expr, options) { if (options === undefined) { options = {}; } @@ -375,24 +375,24 @@ var hints = ["

To factor this expression, we start by looking at the different terms of the sum, and find all of their common factors. We can then rewrite the expression as a product between these common factors, and what's left of the different terms once we remove these factors.

"]; - var detailedHints = genHintsDecomposeAllFactors(MATH, factors, sharedOccFactors, termsOccFactors); + var detailedHints = genHintsDecomposeAllFactors(factors, sharedOccFactors, termsOccFactors); var solution = genFullExpr(factors, sharedOccFactors, termsOccFactors); if (options.factorDiffOfSquares) { var hint = "

We obtain the following expression: " + KhanUtil.getSubHints("common-factors", "Show explanation", detailedHints); - hint += "

" + MATH.format(solution) + "

"; + hint += "

" + KhanUtil.format(solution) + "

"; hints.push(hint); hints.push("

Can we factor this expression even more?

"); for (var iArg = 0; iArg < solution.args.length; iArg++) { var arg = solution.args[iArg]; - var solvedArg = solveDiffOfSquaresExercise(MATH, arg, options); + var solvedArg = solveDiffOfSquaresExercise(arg, options); if (solvedArg === undefined) { continue; } - hints.push("

This part of the expression can be factored: " + MATH.format(arg) + "

"); + hints.push("

This part of the expression can be factored: " + KhanUtil.format(arg) + "

"); var hint = "

We recognize and factor a difference of squares, and obtain the following expression: " + KhanUtil.getSubHints("diff-squares-" + iArg, "Show explanation", solvedArg.hints); solution.args[iArg] = solvedArg.solution; - hint += "

" + MATH.format(solution); + hint += "

" + KhanUtil.format(solution); hints.push(hint); } } else { @@ -409,7 +409,7 @@ } else if (options.factorWithDiffOfSquares === "(ab^2-cd^2)=a(b - d)(b + d)") { } - hints.push("

There is nothing left to factor using this approach. The answer is : " + MATH.format(solution) + "

"); + hints.push("

There is nothing left to factor using this approach. The answer is : " + KhanUtil.format(solution) + "

"); return {hints: hints, solution: solution}; }; @@ -486,7 +486,7 @@ return choices; }; - var genFactoringExercise = function(MATH, factors, nbTerms, factorsPerTerm) { + var genFactoringExercise = function(factors, nbTerms, factorsPerTerm) { var sharedFactors = []; var sharedOccFactors = KhanUtil.initOccArray(factors.length); var numTotal = genSharedFactors(factors, sharedFactors, sharedOccFactors, factorsPerTerm);
34 utils/simplifying-expressions.js
 @@ -79,24 +79,24 @@ return {op: "dfrac", args: newArgs}; }; - var addInitialSteps = function(MATH, steps) { + var addInitialSteps = function(steps) { var aExpr = {op: "var", args: ["a"]}; var exampleFactors = [3, 5, aExpr, {op: "var", args: ["b"]}, {op: "var", args: ["c"]}]; var exampleOldOccs = [[1, 0, 2, 1, 0], [0, 1, 1, 0, 1]]; var exampleNewOccs = [[1, 0, 1, 1, 0], [0, 1, 0, 0, 1]]; var exampleExprInit = getFractionFromOccFactors(exampleFactors, exampleOldOccs); var exampleExprStep = getFractionFromOccFactors(exampleFactors, exampleNewOccs, exampleOldOccs); var exampleExprEnd = getFractionFromOccFactors(exampleFactors, exampleNewOccs); - var exampleGroup = [MATH.parse("#{\\dfrac{a^2}{a}} &= #{\\dfrac{#{a} \\cdot a}{#{a}}}", [KhanUtil.BLUE, KhanUtil.BLUE, {cancel: true}, {cancel: true}]), - MATH.parse("&= #{\\dfrac{a}{1}}", [KhanUtil.BLUE]), - MATH.parse("&= #{a}", [KhanUtil.BLUE])]; + var exampleGroup = [KhanUtil.parse("#{\\dfrac{a^2}{a}} &= #{\\dfrac{#{a} \\cdot a}{#{a}}}", [KhanUtil.BLUE, KhanUtil.BLUE, {cancel: true}, {cancel: true}]), + KhanUtil.parse("&= #{\\dfrac{a}{1}}", [KhanUtil.BLUE]), + KhanUtil.parse("&= #{a}", [KhanUtil.BLUE])]; steps.add("

To simplify this type of expression, we need to look for factors that are shared by both the numerator and the denominator.

For each such factor, if it is present with the same exponent both at the numerator and the denominator, then we can remove that factor completely. If the exponent is different, then we remove the one with the lowest exponent, and substract it from the one with the higher exponent.

"); - var subHints = ["

Why can we simplify an expression this way? Let's look at the detailed steps that we imply when we write " + MATH.format(exampleExprStep) + " :

" + MATH.format(exampleExprInit) + " can be rewritten as " + - MATH.parseFormat("\\dfrac{3}{5} \\cdot #{\\dfrac{a^2}{a}} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "

" + - MATH.formatGroup(exampleGroup) + "

So we get " + - MATH.parseFormat("\\dfrac{3}{5} \\cdot #{a} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + ", or " + - MATH.parseFormat("\\dfrac{3ab}{5c}") + ""]; - steps.add("

For example, if we had this expression: " + MATH.format(exampleExprInit) + ", we would see that the factor " + MATH.format(aExpr) + " is present in both the numerator and the denominator.

We would then simplify it like this: " + MATH.format(exampleExprStep) + " and obtain: " + MATH.format(exampleExprEnd) + " " + KhanUtil.getSubHints("factoring", "Show explanation", subHints) + "

Can you apply this technique to this exercise?

"); + var subHints = ["

Why can we simplify an expression this way? Let's look at the detailed steps that we imply when we write " + KhanUtil.format(exampleExprStep) + " :

" + KhanUtil.format(exampleExprInit) + " can be rewritten as " + + KhanUtil.parseFormat("\\dfrac{3}{5} \\cdot #{\\dfrac{a^2}{a}} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "

" + + KhanUtil.formatGroup(exampleGroup) + "

So we get " + + KhanUtil.parseFormat("\\dfrac{3}{5} \\cdot #{a} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + ", or " + + KhanUtil.parseFormat("\\dfrac{3ab}{5c}") + ""]; + steps.add("

For example, if we had this expression: " + KhanUtil.format(exampleExprInit) + ", we would see that the factor " + KhanUtil.format(aExpr) + " is present in both the numerator and the denominator.

We would then simplify it like this: " + KhanUtil.format(exampleExprStep) + " and obtain: " + KhanUtil.format(exampleExprEnd) + " " + KhanUtil.getSubHints("factoring", "Show explanation", subHints) + "

Can you apply this technique to this exercise?

"); }; var factorNumeratorDenominator = function(expr, options, steps) { @@ -129,11 +129,11 @@ } return newExpr; }; - var solveSimplifyingExpressionsExercise = function(MATH, expr) { + var solveSimplifyingExpressionsExercise = function(expr) { var steps = new KhanUtil.StepsProblem([], expr, "simplify by factoring"); - addInitialSteps(MATH, steps); + addInitialSteps(steps); var subSteps = new KhanUtil.StepsProblem([], expr, "factor numerator and denominator"); - var options = {evalBasicNumOps: true, simplifyMode: "factor"}; + var options = KhanUtil.simplifyOptions.factor; var newExpr = factorNumeratorDenominator(expr, options, subSteps); if (KhanUtil.stepIsUsed(subSteps)) { steps.add("The first step is to factor the numerator and denominator, if possible : " + @@ -178,10 +178,10 @@ var hintExpr = getFractionFromOccFactors(factors, newOccFactors, argsOccFactors); if (KhanUtil.exprIdentical(newExpr, solExpr)) { - steps.add("

There are no factors that can be simplified in this expression, so the answer is: " + MATH.format(solExpr) + ""); + steps.add("

There are no factors that can be simplified in this expression, so the answer is: " + KhanUtil.format(solExpr) + ""); } else { - steps.add("

Applying the approach described above gives in this case:

" + MATH.format(hintExpr) + "

We obtain the following expression:

" + MATH.format(solExpr) + "

Applying the approach described above gives in this case:

" + KhanUtil.format(hintExpr) + "