mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
Typhoons01 main (#415)
* Create simplify_square_roots_generator * Adopt simplify_square_root to standards * lint fixes * lint fix * standardize line_equation_from_2_points * Fix some lint issues * Fix formatting/lint errors * update docs Co-authored-by: Hardik Gupta <96004638+typhoons01@users.noreply.github.com>
This commit is contained in:
@@ -201,7 +201,8 @@
|
|||||||
</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> <span class="p">(</span><span class="s2">"is_composite"</span><span class="p">,</span> <span class="s2">"basic_math"</span><span class="p">),</span>
|
</span><span id="L-126"><a href="#L-126"><span class="linenos">126</span></a> <span class="p">(</span><span class="s2">"is_composite"</span><span class="p">,</span> <span class="s2">"basic_math"</span><span class="p">),</span>
|
||||||
</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> <span class="p">(</span><span class="s2">"complementary_and_supplementary_angle"</span><span class="p">,</span> <span class="s2">"geometry"</span><span class="p">),</span>
|
</span><span id="L-127"><a href="#L-127"><span class="linenos">127</span></a> <span class="p">(</span><span class="s2">"complementary_and_supplementary_angle"</span><span class="p">,</span> <span class="s2">"geometry"</span><span class="p">),</span>
|
||||||
</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a> <span class="p">(</span><span class="s2">"simplify_square_root"</span><span class="p">,</span> <span class="s2">"basic_math"</span><span class="p">),</span>
|
</span><span id="L-128"><a href="#L-128"><span class="linenos">128</span></a> <span class="p">(</span><span class="s2">"simplify_square_root"</span><span class="p">,</span> <span class="s2">"basic_math"</span><span class="p">),</span>
|
||||||
</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a><span class="p">]</span>
|
</span><span id="L-129"><a href="#L-129"><span class="linenos">129</span></a> <span class="p">(</span><span class="s2">"line_equation_from_2_points"</span><span class="p">,</span> <span class="s2">"algebra"</span><span class="p">),</span>
|
||||||
|
</span><span id="L-130"><a href="#L-130"><span class="linenos">130</span></a><span class="p">]</span>
|
||||||
</span></pre></div>
|
</span></pre></div>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -126,4 +126,5 @@ gen_list = [
|
|||||||
("is_composite", "basic_math"),
|
("is_composite", "basic_math"),
|
||||||
("complementary_and_supplementary_angle", "geometry"),
|
("complementary_and_supplementary_angle", "geometry"),
|
||||||
("simplify_square_root", "basic_math"),
|
("simplify_square_root", "basic_math"),
|
||||||
|
("line_equation_from_2_points", "algebra"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -487,6 +487,48 @@ def linear_equations(n=2, var_range=20, coeff_range=20):
|
|||||||
return f'Given the equations ${problem}$, solve for $x$ and $y$', f'${solution}$'
|
return f'Given the equations ${problem}$, solve for $x$ and $y$', f'${solution}$'
|
||||||
|
|
||||||
|
|
||||||
|
def line_equation_from_2_points(max_val=20):
|
||||||
|
r"""Equation of Line from Two Points
|
||||||
|
|
||||||
|
| Ex. Problem | Ex. Solution |
|
||||||
|
| --- | --- |
|
||||||
|
| Find the equation of the line passing through the points $(-19,-8)$ and $(-2,0)$. | $y=\frac{8}{17}x+\frac{16}{17}$ |
|
||||||
|
"""
|
||||||
|
x1 = random.randint(-max_val, max_val)
|
||||||
|
x2 = random.randint(-max_val, max_val)
|
||||||
|
if x1 == x2:
|
||||||
|
return line_equation_from_2_points(max_val=max_val)
|
||||||
|
y1 = random.randint(-max_val, max_val)
|
||||||
|
y2 = random.randint(-max_val, max_val)
|
||||||
|
m1 = (y2 - y1) // math.gcd(y2 - y1, x2 - x1)
|
||||||
|
m2 = (x2 - x1) // math.gcd(y2 - y1, x2 - x1)
|
||||||
|
c1 = (y1 * (x2 - x1) - (y2 - y1) * x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1))
|
||||||
|
c2 = (x2 - x1) // math.gcd(y1 * (x2 - x1) - (y2 - y1) * x1, (x2 - x1))
|
||||||
|
c = rf"{'+' if c1 >= 0 else '-'}\frac{{{abs(c1)}}}{{{c2}}}" if c1 != 0 else ""
|
||||||
|
if c2 < 0:
|
||||||
|
c2 = -c2
|
||||||
|
c1 = -c1
|
||||||
|
c = rf"{'+' if c1 >= 0 else '-'}\frac{{{abs(c1)}}}{{{c2}}}"
|
||||||
|
if c2 == 1:
|
||||||
|
c = f"{c1:+}"
|
||||||
|
|
||||||
|
problem = f'Find the equation of the line passing through the points $({x1},{y1})$ and $({x2},{y2})$.'
|
||||||
|
|
||||||
|
if m1 == 0:
|
||||||
|
return problem, f"$y={c}$"
|
||||||
|
if m2 < 0:
|
||||||
|
m1 = -m1
|
||||||
|
m2 = -m2
|
||||||
|
if m2 == 1:
|
||||||
|
if m1 == 1:
|
||||||
|
return problem, f"$y=x{c}$"
|
||||||
|
if m1 == -1:
|
||||||
|
return problem, f"$y=-x{c}$"
|
||||||
|
return problem, f"y={m1}x{c}"
|
||||||
|
|
||||||
|
return problem, rf"$y=\frac{{{m1}}}{{{m2}}}x{c}$"
|
||||||
|
|
||||||
|
|
||||||
def log(max_base=3, max_val=8):
|
def log(max_base=3, max_val=8):
|
||||||
r"""Logarithm
|
r"""Logarithm
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user