Skip to content

7 Exercises on factoring and simplifying expressions #19229

Merged
merged 9 commits into from Apr 13, 2012
+460 −86
View
33 exercises/common_factors_of_a_polynomial_1.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html data-require="math graphie math-model factoring-expressions simplify subhints">
+<head>
+ <meta charset="UTF-8" />
+ <title>Common factors of a polynomial 1</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="vars">
+ <var id="X">{op:"var", args:["x"]}</var>
+ <var id="Y">{op:"var", args:["y"]}</var>
+ <var id="Z">{op:"var", args:["z"]}</var>
+ <var id="PROBLEM">genFactoringExercise([2, 3, 5, 7, X, Y, Z], 2, 3)</var>
+ <var id="SOLUTION">solveFactoringExercise(PROBLEM.question)</var>
+ </div>
+ <div class="problems">
+ <div>
+ <p class="problem">Factor the following expression by finding the common factors of its terms:</p>
+ <p class="question"><code><var>format(PROBLEM.question)</var></code></p>
+ <p class="solution"><code><var>format(SOLUTION.solution)</var></code></p>
+
+ <ul class="choices" data-none="true" data-show="5">
+ <li data-each="PROBLEM.choices as key, value"><code><var>format(value)</var></code></li>
+ </ul>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
34 exercises/common_factors_of_a_polynomial_2.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html data-require="math graphie math-model factoring-expressions simplify">
+<head>
+ <meta charset="UTF-8" />
+ <title>Common factors of a polynomial 2</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="vars">
+ <var id="W">{op:"var", args:["w"]}</var>
+ <var id="X">{op:"var", args:["x"]}</var>
+ <var id="Y">{op:"var", args:["y"]}</var>
+ <var id="Z">{op:"var", args:["z"]}</var>
+ <var id="PROBLEM">genFactoringExercise([2, 3, 5, 7, W, X, Y, Z], 3, 4)</var>
+ <var id="SOLUTION">solveFactoringExercise(PROBLEM.question)</var>
+ </div>
+ <div class="problems">
+ <div>
+ <p class="problem">Factor the following expression by finding the common factors of its terms:</p>
+ <p class="question"><code><var>format(PROBLEM.question)</var></code></p>
+ <p class="solution"><code><var>format(SOLUTION.solution)</var></code></p>
+
+ <ul class="choices" data-none="true" data-show="5">
+ <li data-each="PROBLEM.choices as key, value"><code><var>format(value)</var></code></li>
+ </ul>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
62 exercises/factoring_difference_of_squares_3.html
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html data-require="math math-model factoring-expressions simplify subhints">
+<head>
+ <meta charset="UTF-8" />
+ <title>Factoring difference of squares 3</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="problems">
+ <div>
+ <div class="vars" data-ensure="getGCD( A, B ) === 1">
+ <var id="F">randFromArray([2,3,5])</var>
+ <var id="A">randRange(2, 6)</var>
+ <var id="B">randRange(1, 6)</var>
+ <var id="SQUARE">F * A * A</var>
+ <var id="CONSTANT">F * -B * B</var>
+ <var id="PROBLEM">parse(SQUARE + "x^2" + CONSTANT)</var>
+ <var id="SOLUTION">solveFactoringExercise(PROBLEM, {factorDiffOfSquares:true})</var>
+ <var id="a">SOLUTION.solution.args[1].args[0].args[0].args[0]</var>
+ <var id="b">SOLUTION.solution.args[1].args[1].args[1]</var>
+ <!-- isEqual doesn't have options to deal with this automatically yet -->
+ <var id="SOL1">parse(F + "(" + a + "x" + "-" + b + ")(" + a + "x" + "+" + b + ")")</var>
+ <var id="SOL2">parse(F + "(" + a + "x" + "+" + b + ")(" + a + "x" + "-" + b + ")")</var>
+ <var id="SOL3">parse(-F + "(" + -a + "x" + "+" + b + ")(" + a + "x" + "+" + b + ")")</var>
+ <var id="SOL4">parse(-F + "(" + a + "x" + "-" + b + ")(" + -a + "x" + "-" + b + ")")</var>
+ <var id="SOL5">parse(-F + "(" + a + "x" + "+" + b + ")(" + -a + "x" + "+" + b + ")")</var>
+ <var id="SOL6">parse(-F + "(" + -a + "x" + "-" + b + ")(" + a + "x" + "-" + b + ")")</var>
+ </div>
+ <div>
+ <p class="question">
+ Factor the following expression:
+ </p>
+ <p>
+ <code><var>format(PROBLEM)</var></code>
+ </p>
+ </div>
+ <div class="solution" data-type="custom">
+ <div class="instruction">
+ <input name="response" type="text">
+ </div>
+ <div class="guess">$( "div.instruction input" ).val()</div>
+ <div class="validator-function">
+ 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>
+ <div class="show-guess">
+ </div>
+ <div class="show-guess-solutionarea">
+ $( "div.instruction input" ).val( guess );
+ </div>
+ <div class="example">a factored expression, like <b>(x+1)(x+3)</b></div>
+ </div>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
53 exercises/factoring_difference_of_squares_4.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html data-require="math math-model factoring-expressions simplify subhints">
+<head>
+ <meta charset="UTF-8" />
+ <title>Factoring difference of squares 4</title>
+ <script src="../khan-exercise.js"></script>
+ <style type="text/css">
+ #answer_area input[type=text] {
+ width: 20px;
+ }
+ </style>
+</head>
+<body>
+ <div class="exercise">
+ <div class="problems">
+ <div>
+ <div class="vars" data-ensure="getGCD( A, B ) === 1">
+ <var id="F">randFromArray([2,3,5])</var>
+ <var id="A">randRange( 2, 6 )</var>
+ <var id="B">randRange( 1, 6 )</var>
+ <var id="P">randRange( 2, 3 )</var>
+ <var id="SQUARE">F * A * A</var>
+ <var id="CONSTANT">F * -B * B</var>
+ <var id="PROBLEM">parse(SQUARE + "x^" + (2*P) + CONSTANT)</var>
+ <var id="SOLUTION">solveFactoringExercise(PROBLEM, {factorDiffOfSquares:true})</var>
+ <var id="ERRORS">[
+ 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),
+ ]</var>
+ </div>
+ <div>
+ <p class="question">
+ Factor the following expression:
+ </p>
+ <p>
+ <code><var>format(PROBLEM)</var></code>
+ </p>
+ </div>
+ <p class="solution"><code><var>format(SOLUTION.solution)</var></code></p>
+ <ul class="choices" data-none="true" data-show="5">
+ <li data-each="ERRORS as key, value"><code><var>value</var></code></li>
+ </ul>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
107 exercises/factoring_polynomials_3.html
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html data-require="math graphie math-model simplify">
+<head>
+ <meta charset="UTF-8" />
+ <title>Factoring polynomials 3</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="problems">
+ <div>
+ <div class="vars">
+ <var id="a">randRange(2, 9)</var>
+ <var id="b_sign">randFromArray([-1, 1])</var>
+ <var id="b_abs">randFromArrayExclude([3, 5, 7, 9], [a])</var>
+ <var id="b">b_sign*b_abs</var>
+ <var id="A">randFromArrayExclude(getFactors(a * b_abs), [1])</var>
+ <var id="B">a + b</var>
+ <var id="C">a * b / A</var>
+ <var id="F1">getGCD(A, a)</var>
+ <var id="F2">b_sign * getGCD(b_abs, C)</var>
+ <var id="PROBLEM">simplify(polynomial([A, B, C], "x"), simplifyOptions.basic)</var>
+ <!-- use parse so that the ast matches the parsed user input -->
+ <var id="SOLUTION">parse("(" + F1 + "x+" + F2 + ")(" + A / F1 + "x+" + a / F1 + ")")</var>
+ <var id="HINT1">parse(F1 + "x(" + A / F1 + "x+" + a / F1 + ")+" + F2 + "(" + b / F2 + "x+" + C / F2 + ")}")</var>
+ <var id="GROUP1">[parse("#{ab} &=& #{A}*#{C} &=& " + (A*C), [GREEN, BLUE, ORANGE]),
+ parse("#{a}+#{b} &=& #{B} &=& #{" + B, [GREEN, GREEN, PINK])]</var>
+
+ </div>
+ <div>
+ <p class="question">
+ Factor the following expression:
+ </p>
+ <p>
+ <code><var>format(PROBLEM, "large")</var></code>
+ </p>
+ </div>
+ <div class="solution" data-type="custom">
+ <div class="instruction">
+ <input name="response" type="text">
+ </div>
+ <div class="guess">jQuery("div.instruction input").val()</div>
+ <div class="validator-function">
+ return isEqual(parse(guess), SOLUTION);
+ </div>
+ <div class="show-guess">
+ </div>
+ <div class="show-guess-solutionarea">
+ jQuery("div.instruction input").val(guess);
+ </div>
+ <div class="example">a factored expression, like <b>(x+1)(x+2)</b></div>
+ </div>
+ <div class="hints">
+ <div>
+ <p>The expression is of the form
+ <code><var>parseFormat("#{A}x^2+#{B}x+#{C}}", [BLUE, PINK, ORANGE])</var></code>.
+ You can factor this trinomial by grouping. In this case,
+ <code>\blue{A}=\blue{<var>A</var>}</code>, <code>\pink{B}=\pink{<var>B</var>}</code>,
+ <code>\orange{C}=\orange{<var>C</var>}</code>
+ </p>
+ </div>
+ <div>
+ <p>To do this, the first step is to find two values
+ <code>\green{a}</code> and
+ <code>\green{b}</code>, such that:</p>
+ <p><code><var>parseFormat("#{ab} = #{A}*#{C}", [GREEN, BLUE, ORANGE])</var></code></p>
+ <p><code><var>parseFormat("#{a}+#{b} = #{B}", [GREEN, GREEN, PINK])</var></code></p>
+ <p>The next step is to rewrite the
+ expression as <code><var>parseFormat("#{A}x^2 + #{a}x + #{b}x + #{C}", [BLUE, GREEN, GREEN, ORANGE])</var></code> or
+ <code><var>parseFormat("(#{A}x^2 + #{a}x) + (#{b}x + #{C})", [BLUE, GREEN, GREEN, ORANGE])</var></code>, and factor each term, to
+ find a common factor.</p>
+ </div>
+ <div>
+ <p>To apply the first step, you need to find
+ <code>\green{a}</code> and <code>\green{b}</code> such that:</p>
+ <p><code><var>formatGroup(GROUP1, [0,1])</var></code></p>
+ </div>
+ <div>
+ <p>The following values can be used:</p>
+ <p><code><var>parseFormat("#{a}=#{" + a + "}", [GREEN, GREEN])</var></code><br>
+ <code><var>parseFormat("#{b}=#{" + b + "}", [GREEN, GREEN])</var></code></p>
+ </div>
+ <div>
+ <p>For the second step, rewrite the expression as:</p>
+ <p><code><var>parseFormat("#{" + A + "}x^2+#{" + a + "}x+#{" + b + "}x+#{" + C + "}}", [BLUE, GREEN, GREEN, ORANGE])</var></code></p>
+ <p>or</p><p><code><var>parseFormat("(#{" + A + "}x^2+#{" + a + "}x)+(#{" + b + "}x+#{" + C + "})", [BLUE, GREEN, GREEN, ORANGE])</var></code></p>
+ <p>The next step is to factor both terms of the above expression:</p>
+ </div>
+ <div>
+ <p>
+ <code><var>format(HINT1, {del1factors:true, evalBasicNumOps:true})</var></code>
+ </p>
+ </div>
+ <div class="final_answer">
+ <p>
+ Redistribute the common term to get the answer:
+ </p>
+ <p>
+ <code><var>format(SOLUTION, simplifyOptions.basic, false, "large")</var></code>
+ </p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+</body>
+</html>
View
34 exercises/simplifying_rational_expressions_1.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html data-require="math graphie ast math-model simplifying-expressions expr-helpers expr-normal-form simplify steps-helpers factoring-expressions subhints">
+<head>
+ <meta charset="UTF-8" />
+ <title>Simplifying rational expressions 1</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="vars">
+ <var id="W">{op:"var", args:["w"]}</var>
+ <var id="X">{op:"var", args:["x"]}</var>
+ <var id="Y">{op:"var", args:["y"]}</var>
+ <var id="Z">{op:"var", args:["z"]}</var>
+ <var id="PROBLEM">genSimplifyingExpressionsExercise(4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3])</var>
+ <var id="SOLUTION">solveSimplifyingExpressionsExercise(PROBLEM)</var>-->
+ </div>
+ <div class="problems">
+ <div>
+ <p class="problem">Simplify the following expression:</p>
+ <p class="question"><code><var>format(PROBLEM)</var></code></p>
+ <p class="solution"><code><var>format(SOLUTION.solution)</var></code></p>
+
+ <ul class="choices" data-none="true" data-show="5">
+ <li data-each="SOLUTION.choices as key, value"><code><var>format(value)</var></code></li>
+ </ul>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
34 exercises/simplifying_rational_expressions_2.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html data-require="math graphie math-model simplifying-expressions simplify factoring-expressions subhints">
+<head>
+ <meta charset="UTF-8" />
+ <title>Simplifying rational expressions 2</title>
+ <script src="../khan-exercise.js"></script>
+</head>
+<body>
+ <div class="exercise">
+ <div class="vars">
+ <var id="W">{op:"var", args:["w"]}</var>
+ <var id="X">{op:"var", args:["x"]}</var>
+ <var id="Y">{op:"var", args:["y"]}</var>
+ <var id="Z">{op:"var", args:["z"]}</var>
+ <var id="PROBLEM">genSimplifyingExpressionsExercise(4, 2, [2, 3, 5, 7], [X, Y], [0, 1, 2, 3], true)</var>
+ <var id="SOLUTION">solveSimplifyingExpressionsExercise(PROBLEM)</var>
+ </div>
+ <div class="problems">
+ <div>
+ <p class="problem">Simplify the following expression:</p>
+ <p class="question"><code><var>format(PROBLEM)</var></code></p>
+ <p class="solution"><code><var>format(SOLUTION.solution)</var></code></p>
+
+ <ul class="choices" data-none="true" data-show="5">
+ <li data-each="SOLUTION.choices as key, value"><code><var>format(value)</var></code></li>
+ </ul>
+ </div>
+ </div>
+ <div class="hints">
+ <div data-each="SOLUTION.hints as key, value"><var>value</var></div>
+ </div>
+ </div>
+</body>
+</html>
View
155 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("<p><code>" + MATH.format(coloredExpr) + "</code></p><p>The expression is of the form <code>" + 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("<p><code>" + KhanUtil.format(coloredExpr) + "</code></p><p>The expression is of the form <code>" + initialForm +
"</code> which is a difference of two squares so we can factor it as <code>" + factoredForm + "</code></p>");
- 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("<p>What are the values of <code>" + strA + "</code> and <code>" + strB + "</code>?</p>");
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("<p><code>" + MATH.format(exprA) + "</code><p><code>" + MATH.format(exprB) + "</code></p>");
+ hints.push("<p><code>" + KhanUtil.format(exprA) + "</code><p><code>" + KhanUtil.format(exprB) + "</code></p>");
hints.push("<p>Use the values we found for <code>" + strA + "</code> and <code>" + strB + "</code> to complete the factored expression, <code>" + factoredForm + "</code></p>");
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("<p><b>So we can factor the expression as:</b><code>" + MATH.format(coloredFactored) + "</code>");
+ hints.push("<p><b>So we can factor the expression as:</b><code>" + KhanUtil.format(coloredFactored) + "</code>");
}
return {solution: solution, hints: hints};
};
@@ -219,13 +219,16 @@
return terms;
};
- var genFullExpr = function(factors, foundOccFactors, termsOccFactors) {
- var remainingTerms = {op: "+", args: genAllTerms(factors, KhanUtil.initOccArray(factors.length), termsOccFactors)};
- var sharedPart = KhanUtil.genExprFromExpFactors(factors, foundOccFactors);
- if (sharedPart === 1) {
- return remainingTerms;
- }
- return {op: "*", args: [sharedPart, remainingTerms]};
+ var genFullExpr = function(factors, foundOccFactors, termsOccFactors, markShared) {
+ var remainingTerms = {op: "+", args: genAllTerms(factors, KhanUtil.initOccArray(factors.length), termsOccFactors)};
+ var sharedPart = KhanUtil.genExprFromExpFactors(factors, foundOccFactors);
+ if (sharedPart === 1) {
+ return remainingTerms;
+ }
+ if (markShared) {
+ sharedPart = KhanUtil.exprSetStyle(sharedPart, {color: KhanUtil.BLUE});
+ }
+ return {op: "*", args: [sharedPart, remainingTerms]};
};
@@ -261,8 +264,8 @@
return numTotal;
};
- var genCdotFactors = function(factors, occFactors) {
- var args = genListFactors(factors, occFactors);
+ var genCdotFactors = function(factors, occFactors, sharedOccFactors, sharedStyle) {
+ var args = genListFactors(factors, occFactors, sharedOccFactors, sharedStyle);
var expr;
if (args.length === 1) {
return args[0];
@@ -275,23 +278,27 @@
}
}
- var genDecomposition = function(factors, occFactors) {
- var exprLeft = KhanUtil.genExprFromExpFactors(factors, occFactors);
- var exprRight = genCdotFactors(factors, occFactors);
- return {op: "=", args: [exprLeft, exprRight]};
+ var genDecomposition = function(factors, occFactors, sharedOccFactors, sharedStyle) {
+ var exprLeft = KhanUtil.genExprFromExpFactors(factors, occFactors);
+ var exprRight = genCdotFactors(factors, occFactors, sharedOccFactors, sharedStyle);
+ return {op: "=", args: [exprLeft, exprRight]};
};
- var genListFactors = function(factors, occFactors) {
- var listFactors = [];
- for (var iFactor = 0; iFactor < factors.length; iFactor++) {
- for (var iOcc = 0; iOcc < occFactors[iFactor]; iOcc++) {
- listFactors.push(factors[iFactor]);
- }
- }
- return listFactors;
+ var genListFactors = function(factors, occFactors, sharedOccFactors, sharedStyle) {
+ var listFactors = [];
+ for (var iFactor = 0; iFactor < factors.length; iFactor++) {
+ for (var iOcc = 0; iOcc < occFactors[iFactor]; iOcc++) {
+ var factor = KhanUtil.exprClone(factors[iFactor]);
+ if ((sharedOccFactors !== undefined) && (iOcc < sharedOccFactors[iFactor])) {
+ factor = KhanUtil.exprSetStyle(factor, sharedStyle);
+ }
+ listFactors.push(factor);
+ }
+ }
+ 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,45 +309,48 @@
strListFactors += ", ";
}
}
- strListFactors += "<code>" + MATH.format(KhanUtil.exprSetStyle(listFactors[iListedFactor], KhanUtil.BLUE)) + "</code>";
+ strListFactors += "<code>" + KhanUtil.format(KhanUtil.exprSetStyle(listFactors[iListedFactor], {color: KhanUtil.BLUE})) + "</code>";
}
+ var hint = "<span class='factoring-expressions'></span>";
if (listFactors.length === 1) {
- return "<p>The terms have one common factor: " + strListFactors + ".</p>";
+ return hint + "<p>The terms have one common factor: " + strListFactors + ".</p>";
} else {
- var gcf = MATH.format(KhanUtil.exprSetStyle(KhanUtil.genExprFromExpFactors(factors, occFactors), KhanUtil.BLUE));
- return "<p>The terms have these common factors: " + strListFactors + ", so the greatest common factor is <code>" + gcf + "</code>.</p>";
+ var gcf = KhanUtil.format(KhanUtil.exprSetStyle(KhanUtil.genExprFromExpFactors(factors, occFactors), KhanUtil.BLUE));
+ return hint + "<p>The terms have these common factors: " + strListFactors + ", so the greatest common factor is <code>" + gcf + "</code>.</p>";
}
};
- var genHintsDecomposeAllFactors = function(MATH, factors, sharedOccFactors, termsOccFactors) {
- var colors = [KhanUtil.PINK, KhanUtil.ORANGE, KhanUtil.GREEN];
- var nbTerms = termsOccFactors.length;
- var hints = [];
- var expr = {op: "+", args: genAllTerms(factors, sharedOccFactors, termsOccFactors)};
- for (var iTerm = 0; iTerm < nbTerms; iTerm++) {
- expr.args[iTerm] = KhanUtil.exprSetStyle(expr.args[iTerm], colors[iTerm]);
- }
- expr = KhanUtil.simplify(expr, KhanUtil.simplifyOptions.checkInput);
+ var genHintsDecomposeAllFactors = function(factors, sharedOccFactors, termsOccFactors) {
+ var colors = [KhanUtil.PINK, KhanUtil.ORANGE, KhanUtil.GREEN];
+ var nbTerms = termsOccFactors.length;
+ var hints = [];
+ var expr = {op: "+", args: genAllTerms(factors, sharedOccFactors, termsOccFactors)};
+ for (var iTerm = 0; iTerm < nbTerms; iTerm++) {
+ expr.args[iTerm] = KhanUtil.exprSetStyle(expr.args[iTerm], colors[iTerm]);
+ }
+ expr = KhanUtil.simplify(expr, KhanUtil.simplifyOptions.checkInput);
- hints.push("<p><code>" + MATH.format(expr) + "</code></p><p>We start by decomposing each term into a product of its most simple factors.</p>");
+ hints.push("<p><code>" + KhanUtil.format(expr) + "</code></p><p>We start by decomposing each term into a product of its most simple factors.</p>");
- for (var iTerm = 0; iTerm < nbTerms; iTerm++) {
- var mergedOccFactors = mergeOccFactors(sharedOccFactors, termsOccFactors[iTerm]);
- hints.push("<p><code>" + MATH.format(KhanUtil.exprSetStyle(genDecomposition(factors, mergedOccFactors), {color: colors[iTerm]})) + "</code></p>");
- }
- hints.push(genHintListFactors(MATH, factors, sharedOccFactors));
+ for (var iTerm = 0; iTerm < nbTerms; iTerm++) {
+ var mergedOccFactors = mergeOccFactors(sharedOccFactors, termsOccFactors[iTerm]);
+ var hint = "<p class='orig-hint'><code>" + KhanUtil.format(KhanUtil.exprSetStyle(genDecomposition(factors, mergedOccFactors), {color: colors[iTerm]})) + "</code></p>";
+ hint += "<p class='new-hint' style='display:none'><code>" + KhanUtil.format(KhanUtil.exprSetStyle(genDecomposition(factors, mergedOccFactors, sharedOccFactors, {color: KhanUtil.BLUE}), {color: colors[iTerm]})) + "</code></p>";
+ hints.push(hint);
+ }
+ hints.push(genHintListFactors(factors, sharedOccFactors));
- hints.push("<p>We can rewrite the expression as: <code>" + MATH.format({op: "+", args: genAllTermsMarkShared(factors, sharedOccFactors, termsOccFactors, colors)}) + "</code>.</p>");
- hints.push("<p>We now rewrite the expression as a product: <code>" + MATH.format(genFullExpr(factors, sharedOccFactors, termsOccFactors)) + "</code>.</p>");
- return hints;
+ hints.push("<p>We can rewrite the expression as: <code>" + KhanUtil.format({op: "+", args: genAllTermsMarkShared(factors, sharedOccFactors, termsOccFactors, colors)}) + "</code>.</p>");
+ hints.push("<p>We now rewrite the expression as a product: <code>" + KhanUtil.format(genFullExpr(factors, sharedOccFactors, termsOccFactors, true)) + "</code>.</p>");
+ return hints;
};
var mergeOccFactors = function(occFactors1, occFactors2) {
- var mergedOccFactors = KhanUtil.initOccArray(occFactors1.length);
- for (var iFactor = 0; iFactor < occFactors1.length; iFactor++) {
- mergedOccFactors[iFactor] = occFactors1[iFactor] + occFactors2[iFactor];
- }
- return mergedOccFactors;
+ var mergedOccFactors = KhanUtil.initOccArray(occFactors1.length);
+ for (var iFactor = 0; iFactor < occFactors1.length; iFactor++) {
+ mergedOccFactors[iFactor] = occFactors1[iFactor] + occFactors2[iFactor];
+ }
+ return mergedOccFactors;
};
var removeSharedFactors = function(sharedOccFactors, termsOccFactors) {
@@ -352,18 +362,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 = {};
}
@@ -373,26 +383,26 @@
var sharedOccFactors = exprFactors.sharedOccFactors;
var termsOccFactors = exprFactors.termsOccFactors;
- var hints = ["<p>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.</p>"];
+ var hints = ["<p>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.</p>"];
- var detailedHints = genHintsDecomposeAllFactors(MATH, factors, sharedOccFactors, termsOccFactors);
+ var detailedHints = genHintsDecomposeAllFactors(factors, sharedOccFactors, termsOccFactors);
var solution = genFullExpr(factors, sharedOccFactors, termsOccFactors);
if (options.factorDiffOfSquares) {
var hint = "<p>We obtain the following expression: " + KhanUtil.getSubHints("common-factors", "Show explanation", detailedHints);
- hint += "<p><code>" + MATH.format(solution) + "</code></p>";
+ hint += "<p><code>" + KhanUtil.format(solution) + "</code></p>";
hints.push(hint);
hints.push("<p>Can we factor this expression even more?</p>");
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("<p>This part of the expression can be factored: <code>" + MATH.format(arg) + "</code></p>");
+ hints.push("<p>This part of the expression can be factored: <code>" + KhanUtil.format(arg) + "</code></p>");
var hint = "<p>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 += "<p><code>" + MATH.format(solution);
+ hint += "<p><code>" + KhanUtil.format(solution);
hints.push(hint);
}
} else {
@@ -409,7 +419,7 @@
} else if (options.factorWithDiffOfSquares === "(ab^2-cd^2)=a(b - d)(b + d)") {
}
- hints.push("<p>There is nothing left to factor using this approach. The answer is : <code>" + MATH.format(solution) + "</code></p>");
+ hints.push("<p class='final_answer'>There is nothing left to factor using this approach. The answer is : <code>" + KhanUtil.format(solution) + "</code></p>");
return {hints: hints, solution: solution};
};
@@ -486,7 +496,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);
@@ -509,5 +519,12 @@
factorSum: factorSum,
genFullExpr: genFullExpr
});
+
+ $.fn["factoring-expressions"] = function(problem) {
+ return this.find(".factoring-expressions").andSelf().filter(".factoring-expressions").each(function() {
+ $(".orig-hint").hide();
+ $(".new-hint").show();
+ });
+ };
})();
View
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("<p>To simplify this type of expression, we need to look for factors that are shared by both the numerator and the denominator.</p>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.</p>");
- var subHints = ["<p>Why can we simplify an expression this way? Let's look at the detailed steps that we imply when we write <code>" + MATH.format(exampleExprStep) + "</code> :</p><p><code>" + MATH.format(exampleExprInit) + "</code> can be rewritten as <code>" +
- MATH.parseFormat("\\dfrac{3}{5} \\cdot #{\\dfrac{a^2}{a}} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "</code></p><p><code>" +
- MATH.formatGroup(exampleGroup) + "</code></p><p>So we get <code>" +
- MATH.parseFormat("\\dfrac{3}{5} \\cdot #{a} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "</code>, or <code>" +
- MATH.parseFormat("\\dfrac{3ab}{5c}") + "</code>"];
- steps.add("<p>For example, if we had this expression: <code>" + MATH.format(exampleExprInit) + "</code>, we would see that the factor <code>" + MATH.format(aExpr) + "</code> is present in both the numerator and the denominator.</p><p>We would then simplify it like this: <code>" + MATH.format(exampleExprStep) + "</code> and obtain: <code>" + MATH.format(exampleExprEnd) + "</code> " + KhanUtil.getSubHints("factoring", "Show explanation", subHints) + "</p><p>Can you apply this technique to this exercise?</p>");
+ var subHints = ["<p>Why can we simplify an expression this way? Let's look at the detailed steps that we imply when we write <code>" + KhanUtil.format(exampleExprStep) + "</code> :</p><p><code>" + KhanUtil.format(exampleExprInit) + "</code> can be rewritten as <code>" +
+ KhanUtil.parseFormat("\\dfrac{3}{5} \\cdot #{\\dfrac{a^2}{a}} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "</code></p><p><code>" +
+ KhanUtil.formatGroup(exampleGroup) + "</code></p><p>So we get <code>" +
+ KhanUtil.parseFormat("\\dfrac{3}{5} \\cdot #{a} \\cdot b \\cdot \\dfrac{1}{c}", [KhanUtil.BLUE]) + "</code>, or <code>" +
+ KhanUtil.parseFormat("\\dfrac{3ab}{5c}") + "</code>"];
+ steps.add("<p>For example, if we had this expression: <code>" + KhanUtil.format(exampleExprInit) + "</code>, we would see that the factor <code>" + KhanUtil.format(aExpr) + "</code> is present in both the numerator and the denominator.</p><p>We would then simplify it like this: <code>" + KhanUtil.format(exampleExprStep) + "</code> and obtain: <code>" + KhanUtil.format(exampleExprEnd) + "</code> " + KhanUtil.getSubHints("factoring", "Show explanation", subHints) + "</p><p>Can you apply this technique to this exercise?</p>");
};
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("<p>There are no factors that can be simplified in this expression, so the answer is: <code>" + MATH.format(solExpr) + "</code>");
+ steps.add("<p class='final_answer'>There are no factors that can be simplified in this expression, so the answer is: <code>" + KhanUtil.format(solExpr) + "</code>");
} else {
- steps.add("<p>Applying the approach described above gives in this case:</p><p><code>" + MATH.format(hintExpr) + "</code></p>");
- steps.add("<p>We obtain the following expression:</p><p><code>" + MATH.format(solExpr) + "</code></p>");
+ steps.add("<p>Applying the approach described above gives in this case:</p><p><code>" + KhanUtil.format(hintExpr) + "</code></p>");
+ steps.add("<p class='final_answer'>We obtain the following expression:</p><p><code>" + KhanUtil.format(solExpr) + "</code></p>");
}
var hints = KhanUtil.genHints(steps);
return {solution: solExpr, hints: hints, choices: choices};
@@ -206,7 +206,7 @@
return listIFactors;
};
- var genSimplifyingExpressionsExercise = function(MATH, nbTerms, maxPower, numFactors, variables, types, withInnerFactor) {
+ var genSimplifyingExpressionsExercise = function(nbTerms, maxPower, numFactors, variables, types, withInnerFactor) {
var factors = [];
for (var iTerm = 0; iTerm < nbTerms; iTerm++) {
var term;
Something went wrong with that request. Please try again.