Special Case Identified

This commit is contained in:
2026-04-30 00:56:21 -04:00
parent 4e4440673b
commit 88160d086c
6 changed files with 29 additions and 2 deletions

View File

@@ -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)}"

View File

@@ -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)

View File

@@ -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