diff --git a/__pycache__/algebraic_steps.cpython-313.pyc b/__pycache__/algebraic_steps.cpython-313.pyc index b9b1f14..a498a06 100644 Binary files a/__pycache__/algebraic_steps.cpython-313.pyc and b/__pycache__/algebraic_steps.cpython-313.pyc differ diff --git a/__pycache__/problem_generator.cpython-313.pyc b/__pycache__/problem_generator.cpython-313.pyc index a9cd479..8b4d849 100644 Binary files a/__pycache__/problem_generator.cpython-313.pyc and b/__pycache__/problem_generator.cpython-313.pyc differ diff --git a/__pycache__/steps_generator.cpython-313.pyc b/__pycache__/steps_generator.cpython-313.pyc index 2449d1e..ca800d9 100644 Binary files a/__pycache__/steps_generator.cpython-313.pyc and b/__pycache__/steps_generator.cpython-313.pyc differ diff --git a/algebraic_steps.py b/algebraic_steps.py index da05906..221708d 100644 --- a/algebraic_steps.py +++ b/algebraic_steps.py @@ -37,8 +37,8 @@ def add_both_sides(equation, value): left_expr = parse_expr(left, transformations=transformations, evaluate=False) right_expr = parse_expr(right, transformations=transformations, evaluate=False) - new_left_expr = left_expr + value - new_right_expr = right_expr + value + new_left_expr = clean(left_expr + value) + new_right_expr = clean(right_expr + value) step["after"] = f"{sstr(new_left_expr)} = {sstr(new_right_expr)}" step["step"] = f"Add both sides by {sstr(value)}" diff --git a/problem_generator.py b/problem_generator.py index 50fdc25..b65fb91 100644 --- a/problem_generator.py +++ b/problem_generator.py @@ -208,10 +208,14 @@ def generate_binomial (): #a(x + b) + c(x + d) = e ans = random.choice([i for i in range(-15, 16)]) a = random.choice([i for i in range(-5, 6) if i != 0]) + a = 4 b = random.choice([i for i in range(-5, 6)]) + b = 4 c = random.choice([i for i in range(-5, 6) if i != 0 and i != -a]) + c = 1 d = random.choice([i for i in range(-5, 6)]) + d = 5 e = a * (ans + b) + c * (ans + d) diff --git a/steps_generator.py b/steps_generator.py index 2ac1647..c1c3ac7 100644 --- a/steps_generator.py +++ b/steps_generator.py @@ -349,8 +349,10 @@ def generate_fraction_steps (problem): def generate_binomial_steps (problem): #a(x + b) + c(x + d) = e steps = [] + x = symbols('x') current = problem["problem"] + ## Distribute Terms last_len = -1 while last_len != len(steps): last_len = len(steps) @@ -358,8 +360,29 @@ def generate_binomial_steps (problem): if len(steps): current = steps[-1]["after"] + ## Combine Like Terms steps.append(algebraic_steps.combine_like_terms(current)) current = steps[-1]["after"] + left, right = current.split("=") + left_expr = parse_expr(left, transformations=transformations) + + ## Subtract constant + b = left_expr.subs(x, 0) + if b.is_zero == False: + if b.is_negative: + steps.append(algebraic_steps.add_both_sides(current, -b)) + elif b.is_positive: + steps.append(algebraic_steps.subtract_both_sides(current, b)) + current = steps[-1]["after"] + left, right = current.split("=") + left_expr = parse_expr(left, transformations=transformations) + + ## Divide by coefficient + a = left_expr.coeff(x) + if a != 1 and a != -1: + steps.append(algebraic_steps.divide_both_sides(current, a)) + elif a == -1: + steps.append(algebraic_steps.multiply_both_sides(current, a)) return steps