# Khan/khan-exercises

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Fetching contributors…

Cannot retrieve contributors at this time

749 lines (681 sloc) 44.348 kb
 Multistep equations with distribution
randVar() [2, 3, 4, 5] rand(2) randRangeNonZero(-8, 8) randRangeNonZero(-8, 8) SOL_NUM / SOL_DEN
randRangeWeightedExclude(-4, 4, -1, 0.4, [0, 1]) randRangeNonZero(-10, 10) randRangeNonZero(-4, 4) rand(2) ? [randFromArray(DENOMS), 1, 1]: [1, randFromArray(DENOMS), randFromArray(DENOMS)] C_DENOM * E_DENOM C_DENOM * D_DENOM A_DENOM * SOL_NUM + C * E B_DENOM * SOL_DEN - C * D getGCD(A, A_DENOM) getGCD(B, B_DENOM) getGCD(C * D, B_DENOM) getGCD(C * E, A_DENOM) fractionReduce(A, A_DENOM) fractionVariable(B, B_DENOM, X) fractionReduce(C, C_DENOM) fractionVariable(D, D_DENOM, X) fractionReduce(E, E_DENOM) fractionVariable(C * D, B_DENOM, X) fractionReduce(C * E, A_DENOM) fractionReduce(B + C * D, B_DENOM) fractionReduce(A - C * E, A_DENOM)

Solve for X:

\qquad A1 = B1 + coefficient(C1)\left(D1 + E1\right) B1 + coefficient(C1)\left(E1 + D1\right) = A1

X = SOLUTION

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{fractionReduce(C, C_DENOM)}:

\qquad\begin{eqnarray} A1 &=& B1 + \pink{C1} \blue{\left(D1 + E1\right)} \\ \\ A1 &=& B1 + \pink{\left(C1\right)}\blue{\left(D1\right)} + \pink{\left(C1\right)}\blue{\left(E1\right)} \\ \\ A1 &=& B1 + CD + CE \end{eqnarray}

\qquad\begin{eqnarray} B1 + \pink{C1} \blue{\left(E1 + D1\right)} &=& A1 \\ \\ B1 + \pink{\left(C1\right)}\blue{\left(E1\right)} + \pink{\left(C1\right)}\blue{\left(D1\right)} &=& A1 \\ \\ B1 + CE + CD &=& A1 \end{eqnarray}

Combine the X terms:

\qquad\begin{eqnarray} A1 &=& \blue{B1 + CD} + CE \\ \\ A1 &=& \blue{\dfrac{coefficient(B / B_GCD)X + coefficient((C * D) / D_GCD)X} {B_DENOM / D_GCD}} + CE \\ \\ A1 &=& \blue{\dfrac{coefficient((B / B_GCD) + (C * D) / D_GCD)X} {B_DENOM / D_GCD}} + CE \\ \\ A1 &=& \blue{coefficient(BD)X} + CE \end{eqnarray}

\qquad\begin{eqnarray} \blue{B1} + CE + \blue{CD} &=& A1 \\ \\ \blue{\dfrac{coefficient(B / B_GCD)X + coefficient((C * D) / D_GCD)X} {B_DENOM / D_GCD}} + CE &=& A1 \\ \\ \blue{\dfrac{coefficient((B / B_GCD) + (C * D) / D_GCD)X} {B_DENOM / D_GCD}} + CE &=& A1 \\ \\ \blue{coefficient(BD)X} + CE &=& A1 \end{eqnarray}

Add \purple{fractionReduce(-C * E, A_DENOM)} to both sides:

Subtract \purple{CE} from both sides:

\qquad\begin{eqnarray} A1 + \purple{fractionReduce(-C * E, A_DENOM)} &=& coefficient(BD)X \\ \\ \dfrac{A / A_GCD + \purple{(-C * E) / E_GCD}} {A_DENOM / E_GCD} &=& coefficient(BD)X \\ \\ \dfrac{(A - C * E) / E_GCD}{A_DENOM / E_GCD} &=& coefficient(BD)X \\ \\ AE &=& coefficient(BD)X \end{eqnarray}

\qquad\begin{eqnarray} coefficient(BD)X &=& A1 + \purple{fractionReduce(-C * E, A_DENOM)} \\ \\ coefficient(BD)X &=& \dfrac{A / A_GCD + \purple{(-C * E) / E_GCD}}{A_DENOM / E_GCD} \\ \\ coefficient(BD)X &=& \dfrac{(A - C * E) / E_GCD}{A_DENOM / E_GCD} \\ \\ coefficient(BD)X &=& AE \end{eqnarray}

Divide both sides by \green{BD} to isolate X:

\qquad A1 - B1 = coefficient(C1)\left(D1 + E1\right) coefficient(C1)\left(E1 + D1\right) = A1 - B1

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{fractionReduce(C, C_DENOM)}:

\qquad\begin{eqnarray} A1 - B1 &=& \pink{C1} \blue{\left(D1 + E1\right)} \\ \\ A1 - B1 &=& \pink{\left(C1\right)}\blue{\left(D1\right)} + \pink{\left(C1\right)}\blue{\left(E1\right)} \\ \\ A1 - B1 &=& CD + CE \end{eqnarray}

\qquad\begin{eqnarray} \pink{C1} \blue{\left(E1 + D1\right)} &=& A1 - B1 \\ \\ \pink{\left(C1\right)}\blue{\left(E1\right)} + \pink{\left(C1\right)}\blue{\left(D1\right)} &=& A1 - B1 \\ \\ CE + CD &=& A1 - B1 \end{eqnarray}

Subtract \blue{fractionVariable(-B, B_DENOM, X)} from both sides:

\qquad\begin{eqnarray} A1 &=& \blue{B1} + CD + CE \\ \\ A1 &=& \dfrac{\blue{coefficient(B / B_GCD)X} + coefficient((C * D) / D_GCD)X} {B_DENOM / D_GCD} + CE \\ \\ A1 &=& \dfrac{coefficient((B / B_GCD) + (C * D) / D_GCD)X} {B_DENOM / D_GCD} + CE \\ \\ A1 &=& coefficient(BD)X + CE \end{eqnarray}

\qquad\begin{eqnarray} \blue{B1} + CE + CD &=& A1 \\ \\ \dfrac{\blue{coefficient(B / B_GCD)X} + coefficient((C * D) / D_GCD)X} {B_DENOM / D_GCD} + CE &=& A1 \\ \\ \dfrac{coefficient((B / B_GCD) + (C * D) / D_GCD)X} {B_DENOM / D_GCD} + CE &=& A1 \\ \\ \blue{coefficient(BD)X} + CE &=& A1 \end{eqnarray}

Add \purple{fractionReduce(-C * E, A_DENOM)} to both sides:

Subtract \purple{CE} from both sides:

\qquad\begin{eqnarray} A1 + \purple{fractionReduce(-C * E, A_DENOM)} &=& coefficient(BD)X \\ \\ \dfrac{A / A_GCD + \purple{(-C * E) / E_GCD}} {A_DENOM / E_GCD} &=& coefficient(BD)X \\ \\ \dfrac{(A - C * E) / E_GCD}{A_DENOM / E_GCD} &=& coefficient(BD)X \\ \\ AE &=& coefficient(BD)X \end{eqnarray}

\qquad\begin{eqnarray} coefficient(BD)X &=& A1 + \purple{fractionReduce(-C * E, A_DENOM)} \\ \\ coefficient(BD)X &=& \dfrac{A / A_GCD + \purple{(-C * E) / E_GCD}}{A_DENOM / E_GCD} \\ \\ coefficient(BD)X &=& \dfrac{(A - C * E) / E_GCD}{A_DENOM / E_GCD} \\ \\ coefficient(BD)X &=& AE \end{eqnarray}

Divide both sides by \green{BD} to isolate X:

rand(2) ? [rand(3) ? 1 : 10, 1, 1]: [1, rand(2) ? 1 : 10, rand(2) ? 1 : 10] randRangeWeightedExclude(-4 * C_DENOM, 4 * C_DENOM, -1 * C_DENOM, 0.4, [0, 1]) / C_DENOM randRangeNonZero(-10 * D_DENOM, 10 * D_DENOM) / D_DENOM randRangeNonZero(-4 * E_DENOM, 4 * E_DENOM) / E_DENOM randFromArray([0.1, 0.2, 0.5, 1, 2, 3, 4]) roundTo(2, MULTIPLE * SOL_NUM + C * E) roundTo(2, MULTIPLE * SOL_DEN - C * D) coefficient(B) + X coefficient(D) + X coefficient(C) roundTo(2, C * E) coefficient(roundTo(2, C * D)) + X roundTo(2, B + C * D) coefficient(BD) + X

Solve for X:

\qquad A = BX + CC(DX + E) BX + CC(E + DX) = A

X = SOLUTION

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{C}:

\qquad\begin{eqnarray} A &=& BX + \pink{C}\blue{(DX + E)} \\ \\ A &=& BX + \pink{(C)}\blue{(DX)} + \pink{(C)}\blue{(E)} \\ \\ A &=& BX + CDX + CE \end{eqnarray}

\qquad\begin{eqnarray} BX + \pink{C} \blue{(E + DX)} &=& A \\ \\ BX + \pink{(C)}\blue{(E)} + \pink{(C)}\blue{(DX)} &=& A \\ \\ BX + CE + CDX &=& A \end{eqnarray}

Combine the X terms:

\qquad\begin{eqnarray} A &=& \blue{BX + CDX} + CE \\ \\ A &=& \blue{BDX} + CE \end{eqnarray}

\qquad\begin{eqnarray} \blue{BX} + CE + \blue{CDX} &=& A \\ \\ \blue{BDX} + CE &=& A \end{eqnarray}

Add \purple{roundTo(2, -C * E)} to both sides:

Subtract \purple{CE} from both sides:

\qquad\begin{eqnarray} A + \purple{roundTo(2, -C * E)} &=& BDX \\ \\ roundTo(4, SOL_NUM * MULTIPLE) &=& BDX \end{eqnarray}

\qquad\begin{eqnarray} BDX &=& A + \purple{roundTo(2, -C * E)} \\ \\ BDX &=& roundTo(4, SOL_NUM * MULTIPLE) \end{eqnarray}

Divide both sides by \green{BD} to isolate X:

\qquad \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BD}} = \dfrac{\green{\cancel{BD}}X}{\green{\cancel{BD}}}

\qquad \dfrac{\green{\cancel{BD}}X}{\green{\cancel{BD}}} = \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BD}}

Solve for X:

\qquad A - BX = CC(DX + E) CC(E + DX) = A - BX

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{C}:

\qquad\begin{eqnarray} A - BX &=& \pink{C}\blue{(DX + E)} \\ \\ A - BX &=& \pink{(C)}\blue{(DX)} + \pink{(C)}\blue{(E)} \\ \\ A - BX &=& CDX + CE \end{eqnarray}

\qquad\begin{eqnarray} \pink{C} \blue{(E + DX)} &=& A \\ \\ \pink{(C)}\blue{(E)} + \pink{(C)}\blue{(DX)} &=& A - BX \\ \\ CE + CDX &=& A - BX \end{eqnarray}

Subtract \purple{coefficient(-B) + X} from both sides:

\qquad\begin{eqnarray} A &=& CDX + CE + \purple{BX} \\ \\ A &=& BDX + CE \end{eqnarray}

\qquad\begin{eqnarray} CE + CDX + \purple{BX} &=& A\\ \\ CE + BDX &=& A \end{eqnarray}

Add \purple{roundTo(2, -C * E)} to both sides:

Subtract \purple{CE} from both sides:

\qquad\begin{eqnarray} A + \purple{roundTo(2, -C * E)} &=& BDX \\ \\ roundTo(4, SOL_NUM * MULTIPLE) &=& BDX \end{eqnarray}

\qquad\begin{eqnarray} BDX &=& A + \purple{roundTo(2, -C * E)} \\ \\ BDX &=& roundTo(4, SOL_NUM * MULTIPLE) \end{eqnarray}

Divide both sides by \green{BD} to isolate X:

\qquad \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BD}} = \dfrac{\green{\cancel{BD}}X}{\green{\cancel{BD}}}

\qquad \dfrac{\green{\cancel{BD}}X}{\green{\cancel{BD}}} = \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BD}}

randRangeWeightedExclude(-4, 4, -1, 0.4, [0, 1]) randRangeNonZero(-10, 10) randRangeNonZero(-4, 4) randRangeNonZero(-8, 8) rand(2) ? [randFromArray(DENOMS), 1, 1]: [1, randFromArray(DENOMS), randFromArray(DENOMS)] C_DENOM * E_DENOM C_DENOM * D_DENOM A_DENOM * SOL_NUM + C * E B_DENOM * SOL_DEN - C * D - F getGCD(A, A_DENOM) getGCD(B, B_DENOM) getGCD(C * D, B_DENOM) getGCD(C * E, A_DENOM) getLCM( A_DENOM / A_GCD, B_DENOM / B_GCD, B_DENOM / D_GCD, A_DENOM / E_GCD ) fractionReduce(A, A_DENOM) fractionVariable(B, B_DENOM, X) fractionReduce(C, C_DENOM) fractionVariable(D, D_DENOM, X) fractionReduce(E, E_DENOM) fractionVariable(F, B_DENOM, X) fractionVariable(C * D, B_DENOM, X) fractionReduce(C * E, A_DENOM) A * COMMON_DENOM / A_DENOM coefficient(B * COMMON_DENOM / B_DENOM) + X coefficient(C * D * COMMON_DENOM / B_DENOM) + X C * E * COMMON_DENOM / A_DENOM coefficient(F * COMMON_DENOM / B_DENOM) + X (A - C * E) * COMMON_DENOM / A_DENOM (B + C * D + F) * COMMON_DENOM / B_DENOM coefficient(FBD) + X

Solve for X:

\qquad A1 - B1 = F1 + coefficient(C1)\left(D1 + E1\right) F1 + coefficient(C1)\left(E1 + D1\right) = A1 - B1

X = SOLUTION

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{fractionReduce(C, C_DENOM)}:

\qquad\begin{eqnarray} A1 - B1 &=& F1 + \pink{C1} \blue{\left(D1 + E1\right)} \\ \\ A1 - B1 &=& F1 + \pink{\left(C1\right)}\blue{\left(D1\right)} + \pink{\left(C1\right)}\blue{\left(E1\right)} \\ \\ A1 - B1 &=& F1 + fractionVariable(C * D, B_DENOM, X) + fractionReduce(C * E, A_DENOM) \end{eqnarray}

\qquad\begin{eqnarray} F1 + \pink{C1} \blue{\left(E1 + D1\right)} &=& A1 - B1 \\ \\ F1 + \pink{\left(C1\right)}\blue{\left(E1\right)} + \pink{\left(C1\right)}\blue{\left(D1\right)} &=& A1 - B1 \\ \\ F1 + fractionReduce(C * E, A_DENOM) + fractionVariable(C * D, B_DENOM, X) &=& A1 - B1 \end{eqnarray}

Multiply each term by a common denominator of COMMON_DENOM

\qquad A2 - B2 = F2 + CD2 + CE2

\qquad F2 + CE2 + CD2 = A2 - B2

Subtract \blue{fractionVariable(-B * COMMON_DENOM, B_DENOM, X)} from both sides:

\qquad A2 = F2 + CD2 + CE2 + \blue{B2}

\qquad F2 + CE2 + CD2 + \blue{B2} = A2

Combine the X terms:

\qquad\begin{eqnarray} A2 &=& \blue{F2 + CD2} + CE2 + \blue{B2} \\ \\ A2 &=& \blue{FBDX} + CE2 \end{eqnarray}

\qquad\begin{eqnarray} \blue{F2} + CE2 + \blue{CD2 + B2} &=& A2 \\ \\ \blue{FBDX} + CE2 &=& A2 \end{eqnarray}

Subtract \purple{CE2} from both sides:

\qquad\begin{eqnarray} A2 + \purple{-CE2} &=& FBDX \\ \\ AE &=& FBDX \end{eqnarray}

\qquad\begin{eqnarray} FBDX &=& A2 + \purple{-CE2} \\ \\ FBDX &=& AE \end{eqnarray}

Divide both sides by \green{FBD} to isolate X:

rand(2) ? [rand(3) ? 1 : 10, 1, 1]: [1, rand(2) ? 1 : 10, rand(2) ? 1 : 10] randRangeWeightedExclude(-4 * C_DENOM, 4 * C_DENOM, -1 * C_DENOM, 0.4, [0, 1]) / C_DENOM randRangeNonZero(-10 * D_DENOM, 10 * D_DENOM) / D_DENOM randRangeNonZero(-4 * E_DENOM, 4 * E_DENOM) / E_DENOM rand(2) ? 1 : 10 randRangeNonZero(-8 * F_DENOM, 8 * F_DENOM) / F_DENOM randFromArray([0.1, 0.2, 0.5, 1, 2, 3, 4]) roundTo(2, MULTIPLE * SOL_NUM + C * E) roundTo(2, MULTIPLE * SOL_DEN - C * D - F) coefficient(B) + X coefficient(D) + X coefficient(F) + X coefficient(C) roundTo(2, C * E) coefficient(roundTo(2, C * D)) + X roundTo(2, B + F + C * D) coefficient(BDF) + X

Solve for X:

\qquad A - BX = FX + CC(DX + E) FX + CC(E + DX) = A - BX

X = SOLUTION

Distribute the negative in front of the parentheses. Be careful! The negative sign in front of the parentheses means we're multiplying by \pink{-1}:

Distribute the \pink{C}:

\qquad\begin{eqnarray} A - BX &=& FX + \pink{C}\blue{(DX + E)} \\ \\ A - BX &=& FX + \pink{(C)}\blue{(DX)} + \pink{(C)}\blue{(E)} \\ \\ A - BX &=& FX + CDX + CE \end{eqnarray}

\qquad\begin{eqnarray} FX + \pink{C} \blue{(E + DX)} &=& A - BX \\ \\ FX + \pink{(C)}\blue{(E)} + \pink{(C)}\blue{(DX)} &=& A - BX \\ \\ FX + CE + CDX &=& A - BX \end{eqnarray}

Subtract \blue{coefficient(-B) + X} from both sides:

\qquad A = FX + CDX + CE + \blue{BX}

\qquad FX + CE + CDX + \blue{BX} = A

Combine the X terms:

\qquad\begin{eqnarray} A &=& \blue{FX + CDX} + CE + \blue{BX} \\ \\ A &=& \blue{BDFX} + CE \end{eqnarray}

\qquad\begin{eqnarray} \blue{FX} + CE + \blue{CDX + BX} &=& A \\ \\ \blue{BDFX} + CE &=& A \end{eqnarray}

Subtract \purple{CE} from both sides:

\qquad\begin{eqnarray} A + \purple{-CE} &=& BDFX \\ \\ roundTo(4, SOL_NUM * MULTIPLE) &=& BDFX \end{eqnarray}

\qquad\begin{eqnarray} BDFX &=& A + \purple{-CE} \\ \\ BDFX &=& roundTo(4, SOL_NUM * MULTIPLE) \end{eqnarray}

Divide both sides by \green{BDF} to isolate X:

\qquad \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BDF}} = \dfrac{\green{\cancel{BDF}}X}{\green{\cancel{BDF}}}

\qquad \dfrac{\green{\cancel{BDF}}X}{\green{\cancel{BDF}}} = \dfrac{roundTo(4, SOL_NUM * MULTIPLE)}{\green{BDF}}