Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use latex as default output #402

Merged
merged 78 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
3bed5da
Improve combine_like_terms
lukew3 Dec 19, 2022
21e1160
Lint fix
lukew3 Dec 19, 2022
e6275d1
add some latex to readme
lukew3 Dec 19, 2022
40b0685
give compound_interest latex formatting
lukew3 Dec 19, 2022
26b48fc
fix compound interest readme
lukew3 Dec 19, 2022
4f7b04a
update combine_like_terms readme
lukew3 Dec 19, 2022
76103f2
combine_like_terms add delimiters
lukew3 Dec 19, 2022
68359e1
Convert some alebra output to latex
lukew3 Dec 20, 2022
9623478
Add missing right] to latex
lukew3 Dec 20, 2022
6bced97
Fix makeReadme script
lukew3 Dec 20, 2022
58d2cec
Correct det 2x2 latex
lukew3 Dec 20, 2022
65961ae
use bmatrix for det 2x2
lukew3 Dec 20, 2022
f26da5f
update readme and bump version
lukew3 Dec 20, 2022
ff6d307
Make latex matrix one line
lukew3 Dec 20, 2022
d763e5c
made latex for most of algebra
lukew3 Dec 20, 2022
f5204b9
more latex migrations
lukew3 Dec 21, 2022
23fad40
convert basic_math to latex
lukew3 Dec 21, 2022
fe9f103
re-generate readme
lukew3 Dec 21, 2022
5cca2ad
fix double exponent
lukew3 Dec 21, 2022
7357078
latex for most of calculus
lukew3 Dec 22, 2022
62e2ca6
Improved stationary points gen
lukew3 Dec 22, 2022
6680483
made cs latex
lukew3 Dec 22, 2022
98f16be
Transform geometry to latex
lukew3 Dec 22, 2022
4089b0c
texify misc outputs
lukew3 Dec 22, 2022
ef04cef
texify statistics
lukew3 Dec 22, 2022
80e8f18
regenerate readme
lukew3 Dec 22, 2022
823364f
Add tex markers to linear_equations
lukew3 Dec 22, 2022
5999b8c
add list_to_tex for mult_int_22
lukew3 Dec 22, 2022
693f861
upgrade readme
lukew3 Dec 22, 2022
cd3db66
update list_to_tex
lukew3 Dec 22, 2022
7fbc839
add end to list_to_tex
lukew3 Dec 22, 2022
d8072d9
tweak list_to_tex, update readme
lukew3 Dec 22, 2022
c49a505
Update README.md
lukew3 Dec 22, 2022
3d65c0d
Update README.md
lukew3 Dec 22, 2022
7186b67
lint fixes
lukew3 Dec 22, 2022
c49328b
Merge branch 'default-latex-output' of https://github.com/lukew3/math…
lukew3 Dec 22, 2022
3c02bf0
Merge branch 'main' into default-latex-output
lukew3 Dec 22, 2022
3e426ef
lint fix
lukew3 Dec 22, 2022
09f246f
Merge branch 'default-latex-output' of https://github.com/lukew3/math…
lukew3 Dec 22, 2022
f53573d
Remove tests
lukew3 Dec 22, 2022
dbc7a10
texify system_of_equations
lukew3 Dec 22, 2022
3f7ca8a
update system_of_equations tex
lukew3 Dec 22, 2022
3591849
regen readme
lukew3 Dec 22, 2022
5274e2f
texify complex_quadratic
lukew3 Dec 22, 2022
b58925a
update complex_quadratic
lukew3 Dec 22, 2022
f1b1ec7
regen readme
lukew3 Dec 22, 2022
6e6e8aa
sqrt to complex_quadratic
lukew3 Dec 22, 2022
a467516
complex_quadratic texify
lukew3 Dec 22, 2022
e86b385
Update README.md
lukew3 Dec 22, 2022
c590812
Update README.md
lukew3 Dec 22, 2022
6771a98
make latexbuilder
lukew3 Dec 23, 2022
8478463
regen readme
lukew3 Dec 23, 2022
b5dc9fe
fix bmatrix
lukew3 Dec 23, 2022
64f2fce
bmatrix conversions
lukew3 Dec 23, 2022
a1a62c7
update readme
lukew3 Dec 23, 2022
22819ca
use times symbol
lukew3 Dec 23, 2022
c008b0b
improve tex of prod_sci_notations
lukew3 Dec 23, 2022
758aadf
Add missing delim to prod of sci notations
lukew3 Dec 23, 2022
3f0b6eb
Add missing curly brack to prod-sci-not
lukew3 Dec 23, 2022
43fe35b
lint fixes
lukew3 Dec 23, 2022
ab4f609
texify differentiation
lukew3 Dec 23, 2022
20902b7
texify stationary points
lukew3 Dec 23, 2022
77ca11c
changed differentation to trig_differentiation
lukew3 Dec 23, 2022
a63762c
texify stationary points
lukew3 Dec 23, 2022
ece3d97
update readme
lukew3 Dec 23, 2022
448a4ac
Remove left right from stat_points
lukew3 Dec 23, 2022
954f9a3
texify angle_btw_vectors
lukew3 Dec 23, 2022
a3b49e9
update readme
lukew3 Dec 23, 2022
65136b4
add spaces to mod operator
lukew3 Dec 23, 2022
7ec1cd5
Swap \\% with \\percent
lukew3 Dec 23, 2022
6202e96
update readme
lukew3 Dec 23, 2022
7875c5f
Replace //percent with non-math %
lukew3 Dec 23, 2022
04f670f
fix leftover \\percent
lukew3 Dec 23, 2022
125c282
latexify vector_cross
lukew3 Dec 23, 2022
9ad62c7
change tex multiply to times
lukew3 Dec 23, 2022
7ce305b
update readme
lukew3 Dec 23, 2022
38a769a
lint fixes
lukew3 Dec 23, 2022
a48d4f3
lint fix
lukew3 Dec 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,3 @@ jobs:

- name: Linter
run: make lint

- name: Test
run: make test
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,3 @@ format:

lint:
$(PYTHON) -m flake8 --ignore=$(IGNORE_ERRORS) $(PKG)

test:
$(PYTHON) -m pytest --verbose -s tests
252 changes: 126 additions & 126 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pytest
hypothesis
flake8
autopep8
sympy
Expand Down
15 changes: 4 additions & 11 deletions mathgenerator/funcs/algebra/basic_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random


def gen_func(maxVariable=10, format='string'):
def gen_func(maxVariable=10):
a = random.randint(1, maxVariable)
b = random.randint(1, maxVariable)
c = random.randint(b, maxVariable)
Expand All @@ -21,16 +21,9 @@ def calculate_gcd(x, y):
elif a == 1 or a == i:
x = f"{c - b}"

if format == 'string':
problem = f"{a}x + {b} = {c}"
solution = x
return problem, solution
elif format == 'latex':
problem = f"\\({a}x + {b} = {c}\\)"
solution = "\\(" + x + "\\)"
return problem, solution
else:
return a, b, c, x
problem = f"${a}x + {b} = {c}$"
solution = f"${x}$"
return problem, solution


basic_algebra = Generator("Basic Algebra", 11, gen_func,
Expand Down
49 changes: 11 additions & 38 deletions mathgenerator/funcs/algebra/combine_like_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,22 @@
import random


def gen_func(maxCoef=10, maxExp=20, maxTerms=10, format='string'):
def gen_func(maxCoef=10, maxExp=20, maxTerms=10):
numTerms = random.randint(1, maxTerms)
problem = ""
solution = ""

for i in range(numTerms):
if i > 0:
problem += " + "
solution += " + "
coefficient = random.randint(1, maxCoef)
exponent = random.randint(1, max(numTerms - 1, 2))

problem += str(coefficient) + "x^" + str(exponent)

solution = combineTerms(problem)
if format == 'string':
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return problem, solution
coefs = [random.randint(1, maxCoef) for _ in range(numTerms)]
exponents = [random.randint(1, max(maxExp - 1, 2)) for _ in range(numTerms)]


def combineTerms(string):
each_terms = string.split("+")
dict_power_wise_terms = {}
for i in range(11):
dict_power_wise_terms[i] = []
for term in each_terms:
term = term.split("^")
appendee = term[0].split("x")[0]
if len(term) == 1:
dict_power_wise_terms[1].append(int(appendee))
problem = " + ".join([f"{coefs[i]}x^{{{exponents[i]}}}" for i in range(numTerms)])
d = {}
for i in range(numTerms):
if exponents[i] in d:
d[exponents[i]] += coefs[i]
else:
dict_power_wise_terms[int(term[1])].append(int(appendee))
d[exponents[i]] = coefs[i]
solution = " + ".join([f"{d[k]}x^{{{k}}}" for k in sorted(d)])

final_string = ''
for i in range(11):
if len(dict_power_wise_terms[i]) != 0:
total = sum(dict_power_wise_terms[i])
final_string += str(total) + "x^" + str(i) + " + "
final_string = '+'.join(final_string.split("+")[:-1])
return final_string
return f'${problem}$', f'${solution}$'


combine_like_terms = Generator("Combine Like terms", 105, gen_func,
Expand Down
12 changes: 6 additions & 6 deletions mathgenerator/funcs/algebra/complex_quadratic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def gen_func(prob_type=0, max_range=10, format='string'):

eq += str(c) + ' = 0'

problem = 'Find the roots of given Quadratic Equation ' + eq
problem = f'Find the roots of given Quadratic Equation ${eq}$'

if d < 0:
sqrt_d = (-d)**0.5

if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
solution = f'(({-b} + {sqrt_d}i)/2*{a}, ({-b} - {sqrt_d}i)/2*{a})'
solution = f'(\\frac{{{-b} + {sqrt_d}i}}{{2*{a}}}, \\frac{{{-b} - {sqrt_d}i}}{{2*{a}}})'
else:
solution = f'(({-b} + sqrt({-d})i)/2*{a}, ({-b} - sqrt({-d})i)/2*{a})'
solution = f'(\\frac{{{-b} + \\sqrt{{{-d}}}i}}{{2*{a}}}, \\frac{{{-b} - \\sqrt{{{-d}}}i}}{{2*{a}}})'

return problem, solution

Expand All @@ -60,11 +60,11 @@ def gen_func(prob_type=0, max_range=10, format='string'):

if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
g_sol = f'(({-b} + {sqrt_d})/2*{a}, ({-b} - {sqrt_d})/2*{a})'
g_sol = f'(\\frac{{{-b} + {sqrt_d}}}{{2*{a}}}, \\frac{{{-b} - {sqrt_d}}}{{2*{a}}})'
else:
g_sol = f'(({-b} + sqrt({d}))/2*{a}, ({-b} - sqrt({d}))/2*{a})'
g_sol = f'(\\frac{{{-b} + \\sqrt{{{d}}}}}{{2*{a}}}, (\\frac{{{-b} - \\sqrt{{{d}}}}}{{2*{a}}})'

solution = f'simplified solution : ({s_root1, s_root2}), generalized solution : ' + g_sol
solution = f'$({s_root1, s_root2}) = {g_sol}$'

return problem, solution

Expand Down
15 changes: 3 additions & 12 deletions mathgenerator/funcs/algebra/compound_interest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@

def gen_func(maxPrinciple=10000,
maxRate=10,
maxTime=10,
format='string'):
maxTime=10):
p = random.randint(1000, maxPrinciple)
r = random.randint(1, maxRate)
n = random.randint(1, maxTime)
a = round(p * (1 + r / 100)**n, 2)

if format == 'string':
problem = "Compound interest for a principle amount of " + \
str(p) + " dollars, " + str(r) + \
"% rate of interest and for a time period of " + \
str(n) + " year is = "
return problem, str(a)
elif format == 'latex':
return "Latex unavailable"
else:
return p, r, n, a
problem = f"Compound interest for a principle amount of ${p}$ dollars, ${r}$% rate of interest and for a time period of ${n}$ years is $=$"
return problem, f'${a}$'


compound_interest = Generator(
Expand Down
15 changes: 5 additions & 10 deletions mathgenerator/funcs/algebra/distance_two_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@
import random


def gen_func(maxValXY=20, minValXY=-20, format='string'):
def gen_func(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
distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2

if format == 'string':
solution = f"sqrt({distanceSq})"
problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})"
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return point1X, point1Y, point2X, point2Y, distanceSq
solution = f"$\\sqrt{{{distanceSq}}}$"
problem = f"Find the distance between $({point1X}, {point1Y})$ and $({point2X}, {point2Y})$"
return problem, solution


distance_two_points = Generator("Distance between 2 points", 24,
Expand Down
26 changes: 10 additions & 16 deletions mathgenerator/funcs/algebra/expanding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
def gen_func(range_x1=10,
range_x2=10,
range_a=10,
range_b=10,
format='string'):
range_b=10):
x1 = random.randint(-range_x1, range_x1)
x2 = random.randint(-range_x2, range_x2)
a = random.randint(-range_a, range_a)
b = random.randint(-range_b, range_b)

def intParser(z):
if (z == 0):
return ""
if (z > 0):
return "+" + str(z)
if (z < 0):
return "-" + str(abs(z))
return f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""

c1 = intParser(a * b)
c2 = intParser((a * x2) + (b * x1))
Expand All @@ -35,7 +34,7 @@ def intParser(z):
p1 = p1[1:]
if p3 == "+1":
p3 = ""
elif p3 == "+":
elif p3[0] == "+":
p3 = p3[1:]

if c1 == "+1":
Expand All @@ -45,14 +44,9 @@ def intParser(z):
if c2 == "+1":
c2 = ""

if format == 'string':
problem = f"({p1}x{p2})({p3}x{p4})"
solution = f"{c1}*x^2{c2}*x{c3}"
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return p1, p2, p3, p4, c1, c2, c3
problem = f"$({p1}x{p2})({p3}x{p4})$"
solution = f"${c1}x^2{c2}x{c3}$"
return problem, solution


expanding = Generator(
Expand Down
26 changes: 11 additions & 15 deletions mathgenerator/funcs/algebra/factoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
import random


def gen_func(range_x1=10, range_x2=10, format='string'):
def gen_func(range_x1=10, range_x2=10):
"""Given a quadratic equation in the form x^2 + bx + c, factor it into it's roots (x - x1)(x -x2)"""
x1 = random.randint(-range_x1, range_x1)
x2 = random.randint(-range_x2, range_x2)

def intParser(z):
if (z == 0):
return ""
if (z > 0):
return "+" + str(z)
if (z < 0):
return "-" + str(abs(z))
return f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""

b = intParser(x1 + x2)
c = intParser(x1 * x2)
Expand All @@ -24,15 +25,10 @@ def intParser(z):
else:
problem = f"x^2{b}x{c}"

if format == 'string':
x1 = intParser(x1)
x2 = intParser(x2)
solution = f"(x{x1})(x{x2})"
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return b, c, x1, x2
x1 = intParser(x1)
x2 = intParser(x2)
solution = f"$(x{x1})(x{x2})$"
return f"${problem}$", solution


factoring = Generator("Factoring Quadratic", 21, gen_func,
Expand Down
15 changes: 6 additions & 9 deletions mathgenerator/funcs/algebra/int_matrix_22_determinant.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from ...generator import Generator
from ...latexBuilder import bmatrix
import random


def gen_func(maxMatrixVal=100, format='string'):
def gen_func(maxMatrixVal=100):
a = random.randint(0, maxMatrixVal)
b = random.randint(0, maxMatrixVal)
c = random.randint(0, maxMatrixVal)
d = random.randint(0, maxMatrixVal)

determinant = a * d - b * c
lst = [[a, b], [c, d]]

if format == 'string':
problem = f"Det([[{a}, {b}], [{c}, {d}]]) = "
solution = f" {determinant}"
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return a, b, c, d, determinant
problem = f"$\\det {bmatrix(lst)}= $"
solution = f"${determinant}$"
return problem, solution


int_matrix_22_determinant = Generator("Determinant to 2x2 Matrix", 77,
Expand Down
19 changes: 6 additions & 13 deletions mathgenerator/funcs/algebra/intersection_of_two_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ def gen_func(minM=-10,
minB=-10,
maxB=10,
minDenominator=1,
maxDenominator=6,
format='string'):
maxDenominator=6):
def generateEquationString(m, b):
"""
Generates an equation given the slope and intercept.
Expand Down Expand Up @@ -66,11 +65,10 @@ def fractionToString(x):
b1 = random.randint(minB, maxB)
b2 = random.randint(minB, maxB)

equation1 = generateEquationString(m1, b1)
equation2 = generateEquationString(m2, b2)
eq1 = generateEquationString(m1, b1)
eq2 = generateEquationString(m2, b2)

problem = "Find the point of intersection of the two lines: "
problem += f"{equation1} and {equation2}"
problem = f"Find the point of intersection of the two lines: ${eq1}$ and ${eq2}$"

m1 = fractions.Fraction(*m1)
m2 = fractions.Fraction(*m2)
Expand All @@ -84,14 +82,9 @@ def fractionToString(x):
else:
intersection_x = (b1 - b2) / (m2 - m1)
intersection_y = ((m2 * b1) - (m1 * b2)) / (m2 - m1)
solution = f"({fractionToString(intersection_x)}, {fractionToString(intersection_y)})"
solution = f"$({fractionToString(intersection_x)}, {fractionToString(intersection_y)})$"

if format == 'string':
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return equation1, equation2, solution
return problem, solution


intersection_of_two_lines = Generator(
Expand Down
Loading