Special Case Identified
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user