diff --git a/__pycache__/algebraic_steps.cpython-313.pyc b/__pycache__/algebraic_steps.cpython-313.pyc index a498a06..a54cb75 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 8b4d849..09722cd 100644 Binary files a/__pycache__/problem_generator.cpython-313.pyc and b/__pycache__/problem_generator.cpython-313.pyc differ diff --git a/algebraic_steps.py b/algebraic_steps.py index 221708d..9e532fa 100644 --- a/algebraic_steps.py +++ b/algebraic_steps.py @@ -410,7 +410,7 @@ def distribute_step(equation): left_expr = parse_expr(left, transformations=transformations, evaluate=False) right_expr = parse_expr(right, transformations=transformations, evaluate=False) - print(f"calling distribute_once with expression: {sstr(left_expr)}") + #print(f"calling distribute_once with expression: {sstr(left_expr)}") new_left_expr, distributed = distribute_once(left_expr) if distributed != None: @@ -423,10 +423,15 @@ def distribute_step(equation): return steps def build_ordered_add(args): - expr = args[0] - for a in args[1:]: - expr = Add(expr, a, evaluate=False) - return expr + flat_args = [] + + for arg in args: + if arg.is_Add: + flat_args.extend(arg.args) + else: + flat_args.append(arg) + + return Add(*flat_args, evaluate=False) def distribute_once(expr): expr = flatten_mul(expr) @@ -437,14 +442,14 @@ def distribute_once(expr): # ------------------------------------------------------------ if expr.is_Mul: - print(f"expr: {sstr(expr)}") + #print(f"expr: {sstr(expr)}") add_part = None other_parts = [] # extract Add factor + everything else for arg in expr.args: - print(f"arg: {sstr(arg)}") + #print(f"arg: {sstr(arg)}") if arg.is_Add and add_part is None: add_part = arg @@ -455,7 +460,7 @@ def distribute_once(expr): # DISTRIBUTION RULE # -------------------------------------------------------- if add_part is not None: - print(f"expr used: {sstr(expr)}, add used: {sstr(add_part)}") + #print(f"expr used: {sstr(expr)}, add used: {sstr(add_part)}") distributed_value = Mul(*other_parts) @@ -472,7 +477,7 @@ def distribute_once(expr): # STEP 2: PRIORITY-BASED RECURSION (IMPORTANT FIX) # ------------------------------------------------------------ if expr.args: - print(f"step2 args:{expr.args}") + #print(f"step2 args:{expr.args}") # PASS 1: ONLY distributable Mul(Add(...)) for i, arg in enumerate(expr.args): if arg.is_Mul and arg.has(Add): diff --git a/problem_generator.py b/problem_generator.py index b65fb91..50fdc25 100644 --- a/problem_generator.py +++ b/problem_generator.py @@ -208,14 +208,10 @@ 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)