Exemple #1
0
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])
Exemple #2
0
def compound_interest_compare_discrete_vs_discrete():
    n_1, n_2 = sample(compounding_n_choices, 2)

    # The way this works is that we come up with an interest rate for the highest compounding rate
    # then we come up with an interest rate that is some amount higher for the lower compounding rate
    # this way it's not dead easy to tell which is the better deal--and that's the point

    base_rate = randint(1, 15) / 100

    higher_rate = base_rate + choice(linspace(0.1, 0.3, 9)) / 100

    # The lower interest rate with the higher compounding rate should be fractional as
    # often as the other interest rate

    if bool(getrandbits(1)):
        old_base_rate = base_rate
        base_rate -= higher_rate - base_rate
        higher_rate = old_base_rate

    if n_1 > n_2:
        r_1 = base_rate
        r_2 = higher_rate
    else:
        r_1 = higher_rate
        r_2 = base_rate

    r_e_1 = f_effective_rate_of_interest_discrete(r_1, n_1)

    r_e_2 = f_effective_rate_of_interest_discrete(r_1, n_1)

    r_n_description_1 = f"{fmath(fper(r_1,))} compounded {compounding_choices[n_1]}"

    r_n_description_2 = f"{fmath(fper(r_2,))} compounded {compounding_choices[n_2]}"

    solution_description = r_n_description_1 if r_e_1 > r_e_2 else r_n_description_2

    problem_instruction = "Which of the following is a better investment?"

    description_set = [r_n_description_1, r_n_description_2]

    # Randomize the order
    if bool(getrandbits(1)):
        description_set = description_set.reverse()

    problem_text = f"{r_n_description_1} or {r_n_description_2}"

    solution_text = solution_description

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
Exemple #3
0
def compound_interest_continuous_find_effective_roi():
    r = randint(1, 15) / 100

    r_e = f_effective_rate_of_interest_continuous(r)

    problem_instruction = "Find the effective return on investment for this investment (round to 3 decimal points):"

    problem_text = f"For {fmath(fper(r))} compounded continuously"

    solution_text = fmath(fper(r_e))

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
Exemple #4
0
def compound_interest_discrete_find_effective_roi():
    n = choice(compounding_n_choices)

    r = randint(1, 15) / 100

    r_e = f_effective_rate_of_interest_discrete(r, n)

    problem_instruction = "Find the effective return on investment for this investment (round to 3 decimal points):"

    problem_text = f"For {fmath(fper(r))} compounded {compounding_choices[n]}"

    solution_text = fmath(fper(r_e))

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
Exemple #5
0
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_instruction = "Find vertex "

    problem_expr = fmath(latex(expr) + ' = 0')

    problem_solution = fmath(latex(eval_expr) + ' = 0')

    return create_full_text_problem([problem_expr], [problem_solution])
Exemple #6
0
def compound_interest_continuous_find_p():

    a = 50 * randint(1, 21)

    t = randint(1, 3) + choice([0, 0.5])

    r = randint(1, 15) / 100

    p = round(f_present_value_continuous(a, r, t), 2)

    plural_end = "s" if t != 1 else ""

    problem_instruction = "Find the present value of this investment:"

    problem_text = f"To get {fmath(fcur(a))} after {fmath(ffrac(t))} year{plural_end} at {fmath(fper(r))} compounded continuously"

    solution_text = fmath(fcur(p))

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
Exemple #7
0
def compound_interest_discrete_find_p():
    a = 50 * randint(1, 21)

    n = choice(compounding_n_choices)

    t = randint(1, 3) + choice([0, 0.5])

    r = randint(1, 15) / 100

    p = round(f_present_value_discrete(a, r, n, t), 2)

    year_word = fplural("year", "years", t)

    problem_instruction = "Find the present value of this investment:"

    problem_text = f"To get {fmath(fcur(a))} after {fmath(ffrac(t))} {year_word} at {fmath(fper(r))} compounded {compounding_choices[n]}"

    solution_text = fmath(fcur(p))

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
Exemple #8
0
def compound_interest_discrete_find_a():
    p = 50 * randint(1, 21)

    n = choice(compounding_n_choices)

    t = randint(1, 3) + choice([0, 0.5])

    r = randint(1, 15) / 100

    a = f_compound_interest_discrete(p, r, n, t)

    year_word = fplural("year", "years", t)

    problem_instruction = "Find the amount that results from this following investment:"

    problem_text = f"{fmath(fcur(p))} invested at {fmath(fcur(r))} compounded {compounding_choices[n]} after a period of {fmath(ffrac(t))} {year_word}"

    solution_text = fmath(fcur(a))

    return create_full_text_problem(
        [problem_instruction, problem_text], [solution_text]
    )
def sum_consecutive_integers(integer_count: bool = None, max_initial_integer: int = 50) -> Problem:
    if integer_count is not None and integer_count < 2:
        raise ValueError('parameter integer_count on sum_consecutive_integers must be greater than or equal to 2')

    integer_count = integer_count if integer_count is not None else Random().randint(3, 5)

    base_integer = Random().randrange(0, max_initial_integer)

    final_integer = 0

    for i in range(integer_count):
        final_integer += base_integer + i

    nth_integer_to_find = Random().randint(1, integer_count)

    ordinal_number = ford(nth_integer_to_find)

    question_label = f"The number {fmath(final_integer)} is the sum of {fmath(integer_count)} consecutive integers. What is the {ordinal_number}?"

    solution_integer = base_integer + (nth_integer_to_find - 1)

    solution = fmath(solution_integer)

    return create_full_text_problem([question_label], [solution])