From 88160d086cd6fe30b2026ee48521bee7304310d4 Mon Sep 17 00:00:00 2001 From: Accusedbold Date: Thu, 30 Apr 2026 00:56:21 -0400 Subject: [PATCH] Special Case Identified --- __pycache__/algebraic_steps.cpython-313.pyc | Bin 20669 -> 20715 bytes __pycache__/problem_generator.cpython-313.pyc | Bin 13516 -> 13566 bytes __pycache__/steps_generator.cpython-313.pyc | Bin 16155 -> 17227 bytes algebraic_steps.py | 4 +-- problem_generator.py | 4 +++ steps_generator.py | 23 ++++++++++++++++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/__pycache__/algebraic_steps.cpython-313.pyc b/__pycache__/algebraic_steps.cpython-313.pyc index b9b1f14d1ac089c1e8f72d3a7677073eed7ad55c..a498a0656ecfd3ad166e100a7a9473e929b6fc61 100644 GIT binary patch delta 247 zcmdnHkn#0GM!wIyyj%=G@b~_wOa_mQe9SD9H?z%VWSH#FE(s(v*?T7Iv${_f=1`hk z&05B)1ym|KIg6uba|KWpdyxu|U!*pyF-$J7@|ygF*J$%$w%LqKE7>L=P!r{4P0mS8%qtQH zDk)N#oX9J+xt=4JiA@W}m)y+F9m>S0vN@60g_%taB&-fpCb{{DKmik@_GD9GJ*epB zOyNmPFgByu9vB;}`i{ghkm_b>S4OqTjA9a-A4+rbFsf~St$vIPD89)^jZtIsO(PX{ sp!7dW14i}D`c?;7fC@g^@`DK zg4y#}z?}V>rcA*clRs%{GjdLr)6!(-3g({drKJm|tF)v!fqYBmJg#7#$@8?txp_m` z_!x|tLm7klCLho;XW{oNN}haCR9x^S3()=|5g_rB6~q#qEUCSQD;vl>2gJo?lli&) znQw4#PL|P80n>Im1}OYKo&I1$21%2jx5O-eJ`&Ua`H77|+>H^$EY=4aF`wJjlH(vh zr>h;uK^Zn6d5DwSjhW++HK!W~$6*c@5GlY0B5k?dcsXvdl@w(rXID-xR1w?UtSiRE zm^0ZyS$Xna{aDs~pmFav%Nx99lrI7@i%LL5A&4l36JW8D$=XJC{2)(gvfN@VsVqn> zE-IZ|VPwo&4HRRWyuoOu5lFTOWMUCWtcVvx@PG(TAaRSsCO1E&G$+-rs20d&1ma?^ e&DF+=i~@3uY@eAKm^3~x0a+g%7$>hbQ3L>0Kz5M; delta 426 zcmeyDc_x$hGcPX}0}wP_`;^JPk@uoHqsZj@>Q^TVuxL-t*N~XJK~;9LJV*HCsUjMT zERzl8A)*1QGLxCLv?kvX;F@f%rNGP)%sDwqOBYOcX-RVe`IgLiT)|wE*J+7!bBD6= zF&Hz4G6wTZzMy5!!s}O*Jo%!i3{#QFWMl0$T$w=o&jE39{A7ME|H=QQ1tb9Spu>C&qrdeAi7u|sB1pAt0Biheoj|2j)O96K=Kef zx2rYBA#+YQ29ColEFhAH4MduAyRmZIVk;@iOwO*HT&N295%W6DWy57c16`dE+Y^Zdv0E1tjNeO#mM%V SnSn{;0~3(-(PHvl6GZ@{JajYw diff --git a/__pycache__/steps_generator.cpython-313.pyc b/__pycache__/steps_generator.cpython-313.pyc index 2449d1e3e69fc5eada7a3c573d98f131033e6e07..ca800d9276cdb390c8aaaeb2b5606ff5490bf984 100644 GIT binary patch delta 568 zcmbPTce;&{?=vqi7XuK)-}{s~-FPG4DT~STm^m3=O}?n4$q~$)#}djC%{=+9g|s9y zNErx(GMX|%SU_3EAlAtf<%PM~AR-J5K^&7ON{CIimla|HYOJ(Woa`pg#|$wj`4m6x2NMiC@5$VYZVr-0HYZ%!k*Ko;CKEon4 z`ID*e$2{NySgzRBAaR5fmK;EgYhzlRDj3Fk2d zGvzUdGDkB`K4>W}63M_24O9aGp^T;=_T#5IA$ zEsmVT;*$8B)VyLAAb0W_TOG!!lLPd`nfL`K|FsQa;fsvn|QSdV}1C!bZCLrsh(qt`XMF2a=KPmtK diff --git a/algebraic_steps.py b/algebraic_steps.py index da05906..221708d 100644 --- a/algebraic_steps.py +++ b/algebraic_steps.py @@ -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)}" diff --git a/problem_generator.py b/problem_generator.py index 50fdc25..b65fb91 100644 --- a/problem_generator.py +++ b/problem_generator.py @@ -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) diff --git a/steps_generator.py b/steps_generator.py index 2ac1647..c1c3ac7 100644 --- a/steps_generator.py +++ b/steps_generator.py @@ -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