def polynomial_function_find_negative(): max_coeff_abs = 144 min_degree = 2 max_degree = 5 degree = randint(min_degree, max_degree) coeffs = around(random.rand(6) * (max_coeff_abs * 2)) - max_coeff_abs x = symbols('x') # f(x) expr = 0 # f(-x) neg_expr = 0 # arange is half open; it doesn't include the top value, so we add 1 for i in arange(degree - 1) + 1: coeff = Rational(coeffs[int(i)]) power = Rational(degree - i) expr += coeff * (x)**power neg_expr += coeff * (-x)**power question = fmath("f(x) = " + latex(expr)) answer = fmath("f(-x) = " + latex(neg_expr)) return create_full_text_problem([question], [answer])
def geom_parabola_given_v_aos_p_find_eq_and_lr( env: Environment = Environment.prod): problem_instruction = f"Find the equation of a parabola, and find the two points that define the latus rectum." a = choice([randint(-5, 0), randint(1, 6)]) a_abs = abs(a) axis = choice([Axis.x, Axis.y]) d = -a shift = (0, 0) if bool(getrandbits(1)) else (randint(-5, 6), randint(-5, 6)) shifted_d = d + (shift[0] if axis == Axis.x else shift[1]) d_str = f"x={shifted_d}" if axis == Axis.x else f"y={shifted_d}" problem_text = f"Directrix the line {fmath(d_str, env)}; vertex at {fmath(str(shift), env)}" expr = f_expr_str_parabola(a, shift[0], shift[1], axis) solution_text = fmath(expr, env) problem = create_full_text_problem([problem_instruction, problem_text], [solution_text]) if env.is_debug(): debug_info = [{'a_abs': a_abs}, {"d": d}] return DebugProblemWrapper(debug_info, problem) return problem
def geom_parabola_given_f_v_find_eq_and_lr( env: Environment = Environment.prod): problem_instruction = f"Find the equation of a parabola, and find the two points that define the latus rectum." a = choice([randint(-5, 0), randint(1, 6)]) a_abs = abs(a) axis = choice([Axis.x, Axis.y]) f = (0, a) if axis == Axis.y else (a, 0) shift = (0, 0) if bool(getrandbits(1)) else (randint(-5, 6), randint(-5, 6)) shifted_f = tuple(map(sum, zip(f, shift))) problem_text = f"Focus at {fmath(str(shifted_f), env)}; vertex at {fmath(str(shift), env)}" expr = f_expr_str_parabola(a, shift[0], shift[1], axis) # lr_abs = 4* solution_text = fmath(expr, env) problem = create_full_text_problem([problem_instruction, problem_text], [solution_text]) if env.is_debug(): debug_info = [{'a_abs': a_abs}, {"f": f}] return DebugProblemWrapper(debug_info, problem) return problem
def compound_interest_discrete_find_effective_roi(): compounding_choices = {1: "annually", 4: "quarterly", 12: "monthly", 356: "daily"} n_choices = list(compounding_choices.keys()) n = choice(n_choices) r = randint(1, 15) / 100 r_str = rf"{int(r*100)}\%" r_e = ((1 + r / n) ** (n)) - 1 r_e_str = rf"{round(r_e*100,3)}\%" problem_instruction = "Find the effective return on investment for this investment (round to 3 decimal points):" problem_text = rf"For {fmath(r_str)} compounded {compounding_choices[n]}" solution_text = fmath(r_e_str) content = [ Widget(TextWidgetOptions(problem_instruction)), Widget(TextWidgetOptions(problem_text)), ] solution = Widget(TextWidgetOptions(solution_text)) return Problem(content, [solution])
def quadratic_function_find_vertex_intercept_form(): # We may want to include fractions for more difficult problems in the future min_c = 1 max_c = 6 min_n = 1 max_n = 30 min_a = 1 max_a = 5 c = randint(min_c, max_c) n = randint(min_n, max_n) a = randint(min_a, max_a) c = -c if rand() < 0.5 else c x = symbols('x') expr = a * (x + c)**2 # Expand into standard form expr = expand(expr) # Remove c^2 expr = expr - a * c**2 # Add n expr = expr + n eval_expr = a * (x + c)**2 + n - (a * (c**2)) problem_content = fmath(latex(expr) + ' = 0') problem_solution = fmath(latex(eval_expr) + ' = 0') return create_full_text_problem([problem_content], [problem_solution])
def compound_interest_continuous_find_effective_roi(): r = randint(1, 15) / 100 r_str = rf"{int(r*100)}\%" r_e = (e ** r) - 1 r_e_str = rf"{round(r_e*100,3)}\%" problem_instruction = "Find the effective return on investment for this investment (round to 3 decimal points):" problem_text = rf"For {fmath(r_str)} compounded continuously" solution_text = fmath(r_e_str) content = [ Widget(TextWidgetOptions(problem_instruction)), Widget(TextWidgetOptions(problem_text)), ] solution = Widget(TextWidgetOptions(solution_text)) return Problem(content, [solution])