From af7284f4862d0122e2b2f2b6fe148457617fb2dd Mon Sep 17 00:00:00 2001 From: 77reuben77 Date: Sat, 10 Jun 2023 15:31:05 +0200 Subject: [PATCH 1/5] I added a factoring function for complex quadratics in the form ax^2 + bx + c --- .idea/.gitignore | 3 + .idea/aws.xml | 17 ++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/mathgenerator.iml | 14 +++++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 6 ++ mathgenerator/algebra.py | 57 ++++++++++++++++++- 8 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/aws.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/mathgenerator.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/aws.xml b/.idea/aws.xml new file mode 100644 index 00000000..03f1bb6e --- /dev/null +++ b/.idea/aws.xml @@ -0,0 +1,17 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/mathgenerator.iml b/.idea/mathgenerator.iml new file mode 100644 index 00000000..8e5446ac --- /dev/null +++ b/.idea/mathgenerator.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..7821ea74 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..27d31bd1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/mathgenerator/algebra.py b/mathgenerator/algebra.py index ed56d5a5..f217a7b7 100644 --- a/mathgenerator/algebra.py +++ b/mathgenerator/algebra.py @@ -223,7 +223,7 @@ def intParser(z): return problem, solution -def factoring(range_x1=10, range_x2=10): +def factoring_quadratic(range_x1=10, range_x2=10): r"""Factoring Quadratic Given a quadratic equation in the form x^2 + bx + c, factor it into it's roots (x - x1)(x -x2) @@ -258,6 +258,60 @@ def intParser(z): return f"${problem}$", solution +def factoring_complex_quadratic(range_x1=10, range_x2=10, range_d=10, range_e = 10): + r"""Factoring Quadratic + Given a quadratic equation in the form ax^2 + bx + c, factor it into it's roots (dx - x1)(ex -x2) + + | Ex. Problem | Ex. Solution | + | --- | --- | + | $3x^2+2x-8$ | $(3x-4)(x+2)$ | + """ + x1 = random.randint(-range_x1, range_x1) + x2 = random.randint(-range_x2, range_x2) + + d = random.randint(-range_d, range_d) + while d==0: + d = random.randint(-range_d, range_d) + + e = random.randint(-range_e, range_e) + while e==0: + e = random.randint(-range_e, range_e) + + def intParser(z): + if (z > 0): + return f"+{z}" + elif (z < 0): + return f"-{abs(z)}" + else: + return "" + + a = d*e + b = intParser(e*x1 + d*x2) + c = intParser(x1 * x2) + + if b == "+1": + b = "+" + if a == 1: + a = "" + if b == "": + problem = f"{a}x^2{c}" + else: + problem = f"{a}x^2{b}x{c}" + + x1 = intParser(x1) + x2 = intParser(x2) + if d == -1: + d = "-" + if d == 1: + d = "" + if e == -1: + e = "-" + if e == 1: + e = "" + solution = f"$({d}x{x1})({e}x{x2})$" + return f"${problem}$", solution + + def int_matrix_22_determinant(max_matrix_val=100): r"""Determinant to 2x2 Matrix @@ -790,3 +844,4 @@ def orthogonal_projection(min_val=-10, max_val=10): problem = f'Find the orthogonal projection of ${v}$ onto ${u}$' solution = f'$[{y[0]}, {y[1]}]$' return problem, solution + From 66434c2e1af6018d53ee831399ff9b37dcc50ecf Mon Sep 17 00:00:00 2001 From: 77reuben77 Date: Sat, 10 Jun 2023 23:59:04 +0200 Subject: [PATCH 2/5] New function for factoring difference of two squares --- .idea/.name | 1 + mathgenerator/algebra.py | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..8b21ade2 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +algebra.py \ No newline at end of file diff --git a/mathgenerator/algebra.py b/mathgenerator/algebra.py index f217a7b7..6fa9fa1b 100644 --- a/mathgenerator/algebra.py +++ b/mathgenerator/algebra.py @@ -312,6 +312,57 @@ def intParser(z): return f"${problem}$", solution +def factoring_difference_of_squares(range_a = 12, range_b = 12, num_variables = 3, max_start_power = 2): + r"""Factoring the difference of two squares in the form (ax)^2 - (by)^2 + into the form (ax-by)(ax+by) + Where a and b are any integers in a given range passed as a parameter. x,y are any algebraic variables squared. + the number of algebraic variables to be included in the solution is also passed as parameter num_variables + (default = 3) + + | Ex. problem | Ex. solution | + | --- | --- | + | Factor 9x^2 - 36y^2z^2 | (3x - 6yz)(3x + 6yz) | + """ + def assign_power(max_start_power): + return random.randint(1,max_start_power) + + a = random.randint(range_a) + b = random.randint(range_b) + + alphabet_string = "abcdefghijklmnopqrstuvwxyz" + variable_int = random.randint(0, 25) + variable_list = [alphabet_string[variable_int], assign_power(max_start_power)] + for i in range(num_variables-1): + variable_int += 1 + if variable_int>25: + variable_int=0 + variable_list.append([alphabet_string[variable_int], assign_power(max_start_power)]) + + split_value = random.randint(0, num_variables) + a_variables = variable_list[0:split_value] + b_variables = variable_list[split_value] + + a_variable_strings = "" + for i in range(len(a_variables)): + a_variable_strings = a_variable_strings + f"{a_variables[i][0]}^{a_variables[i][1]}" + + b_variable_strings = "" + for i in range(len(b_variables)): + b_variable_strings = b_variable_strings + f"{b_variables[i][0]}^{b_variables[i][1]}" + + solution = f"({a}{a_variable_strings}+{b}{b_variable_strings})({a}{a_variable_strings}-{b}{b_variable_strings})" + + a_variable_strings_squared = "" + for i in range(len(a_variables)): + a_variable_strings = a_variable_strings + f"{a_variables[i][0]}^{a_variables[i][1]*2}" + + b_variable_strings_squared = "" + for i in range(len(b_variables)): + b_variable_strings = b_variable_strings + f"{b_variables[i][0]}^{b_variables[i][1]*2}" + + problem = f"{a**2}{a_variable_strings_squared}-{b**2}{b_variable_strings_squared}" + + def int_matrix_22_determinant(max_matrix_val=100): r"""Determinant to 2x2 Matrix From 153118ccd071ae69ec37bc0759e193eb03d8355b Mon Sep 17 00:00:00 2001 From: 77reuben77 Date: Sun, 11 Jun 2023 00:11:39 +0200 Subject: [PATCH 3/5] Fixed return value for factor_difference_of_squares functions --- mathgenerator/algebra.py | 60 ++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/mathgenerator/algebra.py b/mathgenerator/algebra.py index 6fa9fa1b..cbdd109c 100644 --- a/mathgenerator/algebra.py +++ b/mathgenerator/algebra.py @@ -312,7 +312,7 @@ def intParser(z): return f"${problem}$", solution -def factoring_difference_of_squares(range_a = 12, range_b = 12, num_variables = 3, max_start_power = 2): +def factoring_difference_of_squares(range_a=12, range_b=12, num_variables=1, max_start_power=2): r"""Factoring the difference of two squares in the form (ax)^2 - (by)^2 into the form (ax-by)(ax+by) Where a and b are any integers in a given range passed as a parameter. x,y are any algebraic variables squared. @@ -323,44 +323,62 @@ def factoring_difference_of_squares(range_a = 12, range_b = 12, num_variables = | --- | --- | | Factor 9x^2 - 36y^2z^2 | (3x - 6yz)(3x + 6yz) | """ - def assign_power(max_start_power): - return random.randint(1,max_start_power) - a = random.randint(range_a) - b = random.randint(range_b) + def assign_power(l_max_start_power): + return random.randint(1, l_max_start_power) + + a = random.randint(1, range_a) + b = random.randint(1, range_b) alphabet_string = "abcdefghijklmnopqrstuvwxyz" variable_int = random.randint(0, 25) - variable_list = [alphabet_string[variable_int], assign_power(max_start_power)] - for i in range(num_variables-1): + variable_list = [[alphabet_string[variable_int], assign_power(max_start_power)]] + for i in range(num_variables - 1): variable_int += 1 - if variable_int>25: - variable_int=0 + if variable_int > 25: + variable_int = 0 variable_list.append([alphabet_string[variable_int], assign_power(max_start_power)]) split_value = random.randint(0, num_variables) a_variables = variable_list[0:split_value] - b_variables = variable_list[split_value] + b_variables = variable_list[split_value:] a_variable_strings = "" - for i in range(len(a_variables)): - a_variable_strings = a_variable_strings + f"{a_variables[i][0]}^{a_variables[i][1]}" + for variable in a_variables: + a_variable_strings += f"{variable[0]}^{variable[1]}" b_variable_strings = "" - for i in range(len(b_variables)): - b_variable_strings = b_variable_strings + f"{b_variables[i][0]}^{b_variables[i][1]}" - - solution = f"({a}{a_variable_strings}+{b}{b_variable_strings})({a}{a_variable_strings}-{b}{b_variable_strings})" + for variable in b_variables: + b_variable_strings += f"{variable[0]}^{variable[1]}" + + if a == 1 and a_variable_strings != "" and b == 1 and b_variable_strings != "": + solution = f"({a_variable_strings}+{b_variable_strings})({a_variable_strings}-{b_variable_strings})" + elif a == 1 and a_variable_strings != "": + solution = f"({a_variable_strings}+{b}{b_variable_strings})({a_variable_strings}-{b}{b_variable_strings})" + elif b == 1 and b_variable_strings != "": + solution = f"({a}{a_variable_strings}+{b_variable_strings})({a}{a_variable_strings}-{b_variable_strings})" + else: + solution = f"({a}{a_variable_strings}+{b}{b_variable_strings})({a}{a_variable_strings}-{b}{b_variable_strings})" + solution = solution.replace("^1", "") a_variable_strings_squared = "" - for i in range(len(a_variables)): - a_variable_strings = a_variable_strings + f"{a_variables[i][0]}^{a_variables[i][1]*2}" + for variable in a_variables: + a_variable_strings_squared += f"{variable[0]}^{variable[1] * 2}" b_variable_strings_squared = "" - for i in range(len(b_variables)): - b_variable_strings = b_variable_strings + f"{b_variables[i][0]}^{b_variables[i][1]*2}" + for variable in b_variables: + b_variable_strings_squared += f"{variable[0]}^{variable[1] * 2}" + + if a == 1 and b == 1 and a_variable_strings_squared != "" and b_variable_strings_squared != "": + problem = f"{a_variable_strings_squared}-{b_variable_strings_squared}" + elif a == 1 and a_variable_strings_squared != "": + problem = f"{a_variable_strings_squared}-{b ** 2}{b_variable_strings_squared}" + elif b == 1 and b_variable_strings_squared != "": + problem = f"{a ** 2}{a_variable_strings_squared}-{b_variable_strings_squared}" + else: + problem = f"{a ** 2}{a_variable_strings_squared}-{b ** 2}{b_variable_strings_squared}" - problem = f"{a**2}{a_variable_strings_squared}-{b**2}{b_variable_strings_squared}" + return f"${problem}$", f"${solution}$" def int_matrix_22_determinant(max_matrix_val=100): From e880c7615fbce855d14541920d96d7d5fc92069c Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Sat, 10 Jun 2023 22:19:26 -0400 Subject: [PATCH 4/5] Gitignore .idea --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index bb46e296..7a3ee2d4 100644 --- a/.gitignore +++ b/.gitignore @@ -139,5 +139,6 @@ cython_debug/ # IDE files .vscode/ +.idea/ test.py From 8219f841811fdd73c7c34a09a620bc71727001e2 Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Sat, 10 Jun 2023 22:20:32 -0400 Subject: [PATCH 5/5] Delete .idea directory --- .idea/.gitignore | 3 --- .idea/.name | 1 - .idea/aws.xml | 17 ----------------- .idea/inspectionProfiles/profiles_settings.xml | 6 ------ .idea/mathgenerator.iml | 14 -------------- .idea/misc.xml | 4 ---- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 8 files changed, 59 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.name delete mode 100644 .idea/aws.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/mathgenerator.iml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 26d33521..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 8b21ade2..00000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -algebra.py \ No newline at end of file diff --git a/.idea/aws.xml b/.idea/aws.xml deleted file mode 100644 index 03f1bb6e..00000000 --- a/.idea/aws.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da..00000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/mathgenerator.iml b/.idea/mathgenerator.iml deleted file mode 100644 index 8e5446ac..00000000 --- a/.idea/mathgenerator.iml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 7821ea74..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 27d31bd1..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file