Special Case Identified
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -37,8 +37,8 @@ def add_both_sides(equation, value):
|
|||||||
left_expr = parse_expr(left, transformations=transformations, evaluate=False)
|
left_expr = parse_expr(left, transformations=transformations, evaluate=False)
|
||||||
right_expr = parse_expr(right, transformations=transformations, evaluate=False)
|
right_expr = parse_expr(right, transformations=transformations, evaluate=False)
|
||||||
|
|
||||||
new_left_expr = left_expr + value
|
new_left_expr = clean(left_expr + value)
|
||||||
new_right_expr = right_expr + value
|
new_right_expr = clean(right_expr + value)
|
||||||
step["after"] = f"{sstr(new_left_expr)} = {sstr(new_right_expr)}"
|
step["after"] = f"{sstr(new_left_expr)} = {sstr(new_right_expr)}"
|
||||||
|
|
||||||
step["step"] = f"Add both sides by {sstr(value)}"
|
step["step"] = f"Add both sides by {sstr(value)}"
|
||||||
|
|||||||
@@ -208,10 +208,14 @@ def generate_binomial ():
|
|||||||
#a(x + b) + c(x + d) = e
|
#a(x + b) + c(x + d) = e
|
||||||
ans = random.choice([i for i in range(-15, 16)])
|
ans = random.choice([i for i in range(-15, 16)])
|
||||||
a = random.choice([i for i in range(-5, 6) if i != 0])
|
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 = 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 = 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 = random.choice([i for i in range(-5, 6)])
|
||||||
|
d = 5
|
||||||
|
|
||||||
e = a * (ans + b) + c * (ans + d)
|
e = a * (ans + b) + c * (ans + d)
|
||||||
|
|
||||||
|
|||||||
@@ -349,8 +349,10 @@ def generate_fraction_steps (problem):
|
|||||||
def generate_binomial_steps (problem):
|
def generate_binomial_steps (problem):
|
||||||
#a(x + b) + c(x + d) = e
|
#a(x + b) + c(x + d) = e
|
||||||
steps = []
|
steps = []
|
||||||
|
x = symbols('x')
|
||||||
current = problem["problem"]
|
current = problem["problem"]
|
||||||
|
|
||||||
|
## Distribute Terms
|
||||||
last_len = -1
|
last_len = -1
|
||||||
while last_len != len(steps):
|
while last_len != len(steps):
|
||||||
last_len = len(steps)
|
last_len = len(steps)
|
||||||
@@ -358,8 +360,29 @@ def generate_binomial_steps (problem):
|
|||||||
if len(steps):
|
if len(steps):
|
||||||
current = steps[-1]["after"]
|
current = steps[-1]["after"]
|
||||||
|
|
||||||
|
## Combine Like Terms
|
||||||
steps.append(algebraic_steps.combine_like_terms(current))
|
steps.append(algebraic_steps.combine_like_terms(current))
|
||||||
current = steps[-1]["after"]
|
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
|
return steps
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user