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

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