from common import register D = 'algebra' def add(n, c, t, s, e, **kw): register(D, n, c, t, s, e, **kw) add('linear_equation', [['Solve the equation {a}*x + {b} = {c}.', 'The unknown x satisfies {a}*x + {b} = {c}.', 'A real number x obeys {a}*x + {b} = {c}.']], ['What is x?', 'Find x.', 'Determine the value of x.'], lambda r: dict(a=r.randint(2, 19), b=r.randint(3, 40), c=r.randint(50, 250)), [('residual', 'c-b'), ('answer', 'residual/a')], level='easy', depth=2) add('absolute_value', [['The equation is |{a}*x - {b}| = {c}.', 'A real number x satisfies |{a}*x - {b}| = {c}.', 'Consider all real solutions of |{a}*x - {b}| = {c}.']], ['What is the larger solution?', 'Find the greater solution.', 'Determine the largest possible x.'], lambda r: dict(a=r.randint(2, 15), b=r.randint(3, 80), c=r.randint(2, 60)), [('positive_branch', 'b+c'), ('answer', 'positive_branch/a')], level='easy') add('rational_equation', [['The equation is ({a}*x + {b})/(x - {h}) = {c}, with x different from {h}.', 'For x not equal to {h}, ({a}*x + {b})/(x - {h}) = {c}.', 'A real x, excluding {h}, obeys ({a}*x + {b})/(x - {h}) = {c}.']], ['What is x?', 'Solve for x.', 'Determine x exactly.'], lambda r: dict(a=r.randint(2, 9), b=r.randint(2, 40), h=r.randint(2, 15), c=r.randint(11, 25)), [('numerator', 'b+c*h'), ('answer', 'numerator/(c-a)')], level='medium', depth=3) add('polynomial_remainder', [['Let P(x) = x^3 + {a}*x^2 - {b}*x + {c}.', 'The polynomial is P(x) = x^3 + {a}*x^2 - {b}*x + {c}.', 'Define P by P(x) = x^3 + {a}*x^2 - {b}*x + {c}.'], ['Divide P(x) by x - {h}.', 'The divisor is x - {h}.', 'Use x - {h} as the divisor.']], ['What is the remainder?', 'Find the constant remainder.', 'Determine the remainder of this division.'], lambda r: dict(a=r.randint(2, 15), b=r.randint(2, 30), c=r.randint(2, 40), h=r.randint(2, 12)), [('cubic_term', 'h**3'), ('answer', 'cubic_term+a*h*h-b*h+c')], level='medium', depth=3) add('rational_identity_coefficient', [['The identity ({a}*x + {b})*(x + {c}) = {a}*x^2 + k*x + {v} holds for every real x.', 'For all real x, ({a}*x + {b})*(x + {c}) equals {a}*x^2 + k*x + {v}.', 'A polynomial identity valid for all real x is ({a}*x + {b})*(x + {c}) = {a}*x^2 + k*x + {v}.']], ['What is k?', 'Find the coefficient k.', 'Determine k.'], lambda r: (lambda a, b, c: dict(a=a, b=b, c=c, v=b * c))(r.randint(2, 15), r.randint(2, 30), r.randint(2, 20)), [('cross_term', 'a*c'), ('answer', 'cross_term+b')], level='hard', depth=2, concepts=3) add('linear_fraction_chain', [['Real x satisfies (x - {a})/{b} + (x - {c})/{d} = {e}.', 'The equation for x is (x - {a})/{b} + (x - {c})/{d} = {e}.', 'Consider (x - {a})/{b} + (x - {c})/{d} = {e}, over the real numbers.']], ['What is x?', 'Solve the equation for x.', 'Find x exactly.'], lambda r: dict(a=r.randint(2, 30), b=r.randint(2, 17), c=r.randint(2, 30), d=r.randint(18, 31), e=r.randint(3, 30)), [('weighted_constant', 'a*d+c*b+e*b*d'), ('answer', 'weighted_constant/(b+d)')], level='hard', depth=3, concepts=3)