From c767d09ac806521309088872c15f3134f1954161 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Thu, 15 Oct 2020 23:23:24 -0400 Subject: [PATCH 1/8] Simplify Radical, Issue #68 This adds the simplifyRadical generator, which simplifies a radical to its simplest form --- mathgenerator/mathgen.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..a23a761 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,26 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def simplifyRadicalFunc(range_x = 100): + x = random.randint(0, range_x) + if x == 1 or x == 0: + return f"sqrt({x})", str(x) + inside = x + outside = 1 + factor = 2 + while factor * factor <= inside: + if inside % (factor * factor) == 0: + # move factor^2 from inside to outside + inside //= (factor * factor) + outside *= factor + else: + factor += 1 + problem = f"sqrt({x})" + # exclude redundant multiplications by 1 + solution = str(outside if outside != 1 else '') + \ + (f"sqrt({inside})" if inside != 1 else "") + return problem, solution + # || Class Instances #Format is: @@ -301,4 +321,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) \ No newline at end of file From 4505fc897431c874c5dff1d0d6190d19b7d019b4 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Fri, 16 Oct 2020 01:27:03 -0400 Subject: [PATCH 2/8] Solves a system of equations Issue #67. Solves a system of equations of two variables (R^2) --- mathgenerator/mathgen.py | 49 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index a23a761..81e95ff 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -296,6 +296,51 @@ def simplifyRadicalFunc(range_x = 100): (f"sqrt({inside})" if inside != 1 else "") return problem, solution +def systemOfEquationsFunc(range_x = 10, range_y = 10, coeff_mult_range=10): + # Generate solution point first + x = random.randint(-range_x, range_x) + y = random.randint(-range_y, range_y) + # Start from reduced echelon form (coeffs 1) + c1 = [1, 0, x] + c2 = [0, 1, y] + + def randNonZero(): + return random.choice([i for i in range(-coeff_mult_range, coeff_mult_range) + if i != 0]) + # Add random (non-zero) multiple of equations (rows) to each other + c1_mult = randNonZero() + c2_mult = randNonZero() + new_c1 = [c1[i] + c1_mult * c2[i] for i in range(len(c1))] + new_c2 = [c2[i] + c2_mult * c1[i] for i in range(len(c2))] + + # For extra randomness, now add random (non-zero) multiples of original rows + # to themselves + c1_mult = randNonZero() + c2_mult = randNonZero() + new_c1 = [new_c1[i] + c1_mult * c1[i] for i in range(len(c1))] + new_c2 = [new_c2[i] + c2_mult * c2[i] for i in range(len(c2))] + + def coeffToFuncString(coeffs): + # lots of edge cases for perfect formatting! + x_sign = '-' if coeffs[0] < 0 else '' + # No redundant 1s + x_coeff = str(abs(coeffs[0])) if abs(coeffs[0]) != 1 else '' + # If x coeff is 0, dont include x + x_str = f'{x_sign}{x_coeff}x' if coeffs[0] != 0 else '' + # if x isn't included and y is positive, dont include operator + op = ' - ' if coeffs[1] < 0 else (' + ' if x_str != '' else '') + # No redundant 1s + y_coeff = abs(coeffs[1]) if abs(coeffs[1]) != 1 else '' + # Don't include if 0, unless x is also 0 (probably never happens) + y_str = f'{y_coeff}y' if coeffs[1] != 0 else ('' if x_str != '' else '0') + return f'{x_str}{op}{y_str} = {coeffs[2]}' + + problem = f"{coeffToFuncString(new_c1)}, {coeffToFuncString(new_c2)}" + solution = f"x = {x}, y = {y}" + return problem, solution + + # Add random (non-zero) multiple of equations to each other + # || Class Instances #Format is: @@ -322,4 +367,6 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) -simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) \ No newline at end of file +simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) +systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", + systemOfEquationsFunc) \ No newline at end of file From 642574148653ff1d743b339791e6281ce3092e55 Mon Sep 17 00:00:00 2001 From: ElRoberto13 Date: Fri, 16 Oct 2020 01:32:46 -0400 Subject: [PATCH 3/8] Remove radical function from branch --- mathgenerator/mathgen.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 81e95ff..e7ca613 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,26 +276,6 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def simplifyRadicalFunc(range_x = 100): - x = random.randint(0, range_x) - if x == 1 or x == 0: - return f"sqrt({x})", str(x) - inside = x - outside = 1 - factor = 2 - while factor * factor <= inside: - if inside % (factor * factor) == 0: - # move factor^2 from inside to outside - inside //= (factor * factor) - outside *= factor - else: - factor += 1 - problem = f"sqrt({x})" - # exclude redundant multiplications by 1 - solution = str(outside if outside != 1 else '') + \ - (f"sqrt({inside})" if inside != 1 else "") - return problem, solution - def systemOfEquationsFunc(range_x = 10, range_y = 10, coeff_mult_range=10): # Generate solution point first x = random.randint(-range_x, range_x) @@ -367,6 +347,5 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) -simplifyRadical = Generator("Simplify a Radical", 22, "sqrt(72)", "6sqrt(2)", simplifyRadicalFunc) systemOfEquations = Generator("Solve a System of Equations in R^2", 23, "2x + 5y = 13, -3x - 3y = -6", "x = -1, y = 3", systemOfEquationsFunc) \ No newline at end of file From 6ccb1a9bc7fa3bad872947be65f853136ba84928 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 11:11:42 +0530 Subject: [PATCH 4/8] Update mathgen.py --- mathgenerator/mathgen.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..7a7205e 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,13 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def thirdAngleOfTriangle(maxAngle=180): + angle1 = random.randint(1, maxAngle) + x1 = random.randint(1, maxAngle) + angle3 = 180 - (angle1 + angle2) + problem = "Third angle = " + + # || Class Instances #Format is: @@ -301,4 +308,4 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) From f73df71c23adc3de39674b04b79e614dad42bde1 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 11:56:03 +0530 Subject: [PATCH 5/8] Update mathgen.py --- mathgenerator/mathgen.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 7a7205e..e74000a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,12 +276,13 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def thirdAngleOfTriangle(maxAngle=180): +def thirdAngleOfTriangleFunc(maxAngle=180): angle1 = random.randint(1, maxAngle) x1 = random.randint(1, maxAngle) angle3 = 180 - (angle1 + angle2) problem = "Third angle = " - + solution = angle3 + return problem, solution # || Class Instances @@ -309,3 +310,4 @@ areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side l doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +thirdAngleOfTriangle = Generator("Third Angle of Triangle", 22, "Third Angle of the triangle = ", "angle3", thirdAngleOfTriangleFunc) From 6248336226d4297aa68452a3f154d3ff958c39f5 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Fri, 16 Oct 2020 12:06:50 +0530 Subject: [PATCH 6/8] Update mathgen.py --- mathgenerator/mathgen.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e74000a..226d8a9 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,11 +276,11 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution -def thirdAngleOfTriangleFunc(maxAngle=180): +def thirdAngleOfTriangleFunc(maxAngle=89): angle1 = random.randint(1, maxAngle) - x1 = random.randint(1, maxAngle) + angle2 = random.randint(1, maxAngle) angle3 = 180 - (angle1 + angle2) - problem = "Third angle = " + problem = "Third angle of triangle = " solution = angle3 return problem, solution From 1bedf32949e0e378533b12dc30ea3d47b4fef4fd Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Fri, 16 Oct 2020 12:24:30 +0530 Subject: [PATCH 7/8] Two Point distance --- mathgenerator/mathgen.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..e6b529a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,16 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def distanceTwoPoints(maxValXY = 20, minValXY=-20): + point1X = random.randint(minValXY, maxValXY+1) + point1Y = random.randint(minValXY, maxValXY+1) + point2X = random.randint(minValXY, maxValXY+1) + point2Y = random.randint(minValXY, maxValXY+1) + distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2 + solution = f"sqrt({distanceSq})" + problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})" + return problem, solution + # || Class Instances #Format is: @@ -301,4 +311,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +distance2Point = Generator("Distance between 2 points", 22, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPoints) \ No newline at end of file From 887cedda9f7d5cf8ce8292bdc44e5f2972165993 Mon Sep 17 00:00:00 2001 From: Ananya Kaushik Date: Fri, 16 Oct 2020 05:46:44 -0700 Subject: [PATCH 8/8] add Pythagorean theorem --- mathgenerator/mathgen.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..df35240 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,14 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def pythagoreanTheoremFunc(maxLength = 20): + a = random.randint(1, maxLength) + b = random.randint(1, maxLength) + c = (a**2 + b**2)**0.5 + problem = f"The hypotenuse of a right triangle given the other two lengths {a} and {b} = " + solution = f"{c:.0f}" if c.is_integer() else f"{c:.2f}" + return problem, solution + # || Class Instances #Format is: @@ -301,4 +309,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +pythagoreanTheorem = Generator("Pythagorean Theorem", 22, "The hypotenuse of a right triangle given the other two lengths a and b = ", "hypotenuse", pythagoreanTheoremFunc) \ No newline at end of file