No Generator class (#405)

* Create ids list

* rm Genimprt, rm inst in algebra + basic_math

* computer science and calculus no inst

* Remove instances from geometry

* remove instances from misc

* remove instances from permutations

* fix under indentations

* improve binary_complement_1s

* Remove generator.py

* initial docs setup

* move modules out of funcs, regen docs

* Move subjects to single files

* pdoc docs

* add make docs

* Remove mid-file imports, delete templates

* lint fixes

* Use math in docs

* remove format string from complex_quad

* regen docs

* Lint fix

* Hide non-generator modules from docs

* Hide utility methods from docs

* Created _gen_list.py

* Remove docs from readme

* replace tabs with 4 spaces

* lint fixes

* little docs changes

* docstrings for half of subjects

* Added example docs for remaining generators

* update docs

* Update intersection of two lines #408

* Snake case variables; for #406

* update docs

* Remove escaped backslashes; for #407

* autopep8

* lint fix

* lint fix

* remove gcd duplicates; for  #401

* Add missing delimiter for fraction_multiplication

* rebuild docs
This commit is contained in:
Luke Weiler
2022-12-27 14:31:58 -05:00
committed by GitHub
parent 868cb9d614
commit a2d2a1b0e9
166 changed files with 16245 additions and 3378 deletions

View File

@@ -10,3 +10,6 @@ format:
lint:
$(PYTHON) -m flake8 --ignore=$(IGNORE_ERRORS) $(PKG)
docs:
pdoc mathgenerator --math -o docs

160
README.md
View File

@@ -9,14 +9,7 @@ See [CONTRIBUTING.md](https://github.com/lukew3/mathgenerator/blob/main/CONTRIBU
## Table of Contents
* [Installation](#installation)
* [Usage](#usage)
* [List of Generators](#list-of-generators)
* [algebra](#algebra)
* [basic_math](#basic_math)
* [calculus](#calculus)
* [computer_science](#computer_science)
* [geometry](#geometry)
* [misc](#misc)
* [statistics](#statistics)
* [Documentation](#documentation)
## Installation
@@ -70,152 +63,5 @@ You can also use `getGenList()` to return a list of all generators included in t
[id, title, gen_func, funcname, subjectname, kwargs]
```
## List of Generators
## algebra
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 11 | [Basic Algebra](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/basic_algebra.py) | $9x + 9 = 9$ | $0$ | basic_algebra | `maxVariable=10` |
| 12 | [Logarithm](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/log.py) | $log_{2}(256)=$ | $8$ | log | `maxBase=3` `maxVal=8` |
| 17 | [Integer Multiplication with 2x2 Matrix](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/multiply_int_to_22_matrix.py) | $2 * \begin{bmatrix} 8 & 0 \\ 10 & 10 \end{bmatrix} =$ | $\begin{bmatrix} 16 & 0 \\ 20 & 20 \end{bmatrix}$ | multiply_int_to_22_matrix | `maxMatrixVal=10` `maxRes=100` |
| 20 | [Midpoint of the two point](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/midpoint_of_two_points.py) | The midpoint of $(7,5)$ and $(-17,14) = $ | $(-5.0,9.5)$ | midpoint_of_two_points | `maxValue=20` |
| 21 | [Factoring Quadratic](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/factoring.py) | $x^2-2x$ | $(x)(x-2)$ | factoring | `range_x1=10` `range_x2=10` |
| 23 | [Solve a System of Equations in R^2](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/system_of_equations.py) | Given $4x - 6y = 36$ and $9x - 2y = 12$, solve for $x$ and $y$. | $x = 0$, $y = -6$ | system_of_equations | `range_x=10` `range_y=10` `coeff_mult_range=10` |
| 24 | [Distance between 2 points](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/distance_two_points.py) | Find the distance between $(7, -15)$ and $(0, -1)$ | $\sqrt{245}$ | distance_two_points | `maxValXY=20` `minValXY=-20` |
| 26 | [Linear Equations](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/linear_equations.py) | Given the equations $-3x + 10y = -140$ and $-3x + -4y = -28$, solve for $x$ and $y$ | $x = 20$, $y = -8$ | linear_equations | `n=2` `varRange=20` `coeffRange=20` |
| 41 | [Intersection of Two Lines](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/intersection_of_two_lines.py) | Find the point of intersection of the two lines: $y = 9/3x - 6$ and $y = 1/3x + 6$ | $(9/2, 15/2)$ | intersection_of_two_lines | `minM=-10` `maxM=10` `minB=-10` `maxB=10` `minDenominator=1` `maxDenominator=6` |
| 43 | [Cross Product of 2 Vectors](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/vector_cross.py) | $[-18, 0, 20] \times [-16, -5, 0] = $ | $[100, -320, 90]$ | vector_cross | `minVal=-20` `maxVal=20` |
| 45 | [Simple Interest](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/simple_interest.py) | Simple interest for a principle amount of $9080$ dollars, $3$% rate of interest and for a time period of $6$ years is $=$ | $1634.4$ | simple_interest | `maxPrinciple=10000` `maxRate=10` `maxTime=10` |
| 46 | [Multiplication of two matrices](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/matrix_multiplication.py) | Multiply$\begin{bmatrix}0&-1&-9&1\\-10&4&3&-10\end{bmatrix}$and$\begin{bmatrix}-4&-2&-4\\8&-1&2\\-2&6&-5\\-10&7&5\end{bmatrix}$ | $\begin{bmatrix}0&-46&48\\166&-36&-17\end{bmatrix}$ | matrix_multiplication | `maxVal=100` `max_dim=10` |
| 50 | [Quadratic Equation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/quadratic_equation.py) | What are the zeros of the quadratic equation $24x^2+103x+26=0$ | ${-0.27, -4.02}$ | quadratic_equation | `maxVal=100` |
| 65 | [Multiplication of 2 complex numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/multiply_complex_numbers.py) | $(17+1j) * (17-1j) = $ | $(290+0j)$ | multiply_complex_numbers | `minRealImaginaryNum=-20` `maxRealImaginaryNum=20` |
| 72 | [Dot Product of 2 Vectors](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/vector_dot.py) | $[9, 14, -19]\cdot[-8, -9, 10]=$ | $-388$ | vector_dot | `minVal=-20` `maxVal=20` |
| 74 | [Inverse of a Matrix](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/invert_matrix.py) | Inverse of Matrix $\begin{bmatrix} 0 & 0 & 1 \\ 1 & 3 & 3 \\ 1 & 2 & 2 \end{bmatrix}$ is: | \begin{bmatrix} 0 & -2 & 3 \\ -1 & 1 & -1 \\ 1 & 0 & 0 \end{bmatrix} | invert_matrix | `SquareMatrixDimension=3` `MaxMatrixElement=99` `OnlyIntegerElementsInInvertedMatrix=True` |
| 77 | [Determinant to 2x2 Matrix](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/int_matrix_22_determinant.py) | $\det \begin{bmatrix} 24 & 94 \\ 21 & 29 \end{bmatrix}= $ | $-1278$ | int_matrix_22_determinant | `maxMatrixVal=100` |
| 78 | [Compound Interest](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/compound_interest.py) | Compound interest for a principle amount of $2004$ dollars, $1$% rate of interest and for a time period of $5$ years is $=$ | $2106.22$ | compound_interest | `maxPrinciple=10000` `maxRate=10` `maxTime=10` |
| 100 | [complex Quadratic Equation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/complex_quadratic.py) | Find the roots of given Quadratic Equation $7x^2 + 7x + 1 = 0$ | $((-0.173, -0.827)) = (\frac{-7 + \sqrt{21}}{2*7}, (\frac{-7 - \sqrt{21}}{2*7})$ | complex_quadratic | `prob_type=0` `max_range=10` |
| 105 | [Combine Like terms](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/combine_like_terms.py) | $4x^{13} + 1x^{16}$ | $4x^{13} + 1x^{16}$ | combine_like_terms | `maxCoef=10` `maxExp=20` `maxTerms=10` |
| 111 | [Expanding Factored Binomial](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/algebra/expanding.py) | $(-10x-2)(-1x+6)$ | $10x^2-58x-12$ | expanding | `range_x1=10` `range_x2=10` `range_a=10` `range_b=10` |
## basic_math
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 0 | [Addition](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/addition.py) | $40+14=$ | $54$ | addition | `maxSum=99` `maxAddend=50` |
| 1 | [Subtraction](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/subtraction.py) | $12-2=$ | $10$ | subtraction | `maxMinuend=99` `maxDiff=99` |
| 2 | [Multiplication](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/multiplication.py) | $7\cdot8$ | $56$ | multiplication | `maxMulti=12` |
| 3 | [Division](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/division.py) | $92\div23=$ | $4$ | division | `maxA=25` `maxB=25` |
| 6 | [Square Root](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/square_root.py) | $\sqrt{1}=$ | $1$ | square_root | `minNo=1` `maxNo=12` |
| 8 | [Square](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/square.py) | $9^2=$ | $81$ | square | `maxSquareNum=20` |
| 13 | [Fraction to Decimal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/fraction_to_decimal.py) | $84\div6=$ | $14.0$ | fraction_to_decimal | `maxRes=99` `maxDivid=99` |
| 16 | [Fraction Division](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/divide_fractions.py) | $\frac{6}{7}\div\frac{9}{5}=$ | $\frac{10}{21}$ | divide_fractions | `maxVal=10` |
| 28 | [Fraction Multiplication](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/fraction_multiplication.py) | $\frac{3}{9}\cdot\frac{7}{6}=$ | $\frac{7}{18}$ | fraction_multiplication | `maxVal=10` |
| 31 | [Factorial](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/factorial.py) | $5! =$ | $120$ | factorial | `maxInput=6` |
| 44 | [Compare Fractions](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/compare_fractions.py) | Which symbol represents the comparison between $\frac{3}{5}$ and $\frac{3}{9}$? | > | compare_fractions | `maxVal=10` |
| 47 | [Cube Root](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/cube_root.py) | What is the cube root of: $\sqrt[3]{30}=$ to 2 decimal places? | $3.11$ | cube_root | `minNo=1` `maxNo=1000` |
| 53 | [Exponentiation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/exponentiation.py) | $4^1 =$ | $4$ | exponentiation | `maxBase=20` `maxExpo=10` |
| 71 | [Absolute difference between two numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/absolute_difference.py) | $|22--59|=$ | $81$ | absolute_difference | `maxA=100` `maxB=100` |
| 80 | [Percentage of a number](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/percentage.py) | What is $5$% of $18$? | $0.90$ | percentage | `maxValue=99` `maxpercentage=99` |
| 90 | [isprime](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/is_prime.py) | Is $73$ prime? | Yes | is_prime | `max_num=100` |
| 97 | [Power of Powers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/power_of_powers.py) | Simplify $31^{8^{2}}$ | $31^{16}$ | power_of_powers | `maxBase=50` `maxPower=10` |
| 118 | [Percentage difference](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/percentage_difference.py) | What is the percentage difference between $66$ and $7$? | $161.64$% | percentage_difference | `maxValue=200` `minValue=0` |
| 119 | [Percentage error](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/percentage_error.py) | Find the percentage error when observed value equals $-44$ and exact value equals $-26$. | $69.23\%$ | percentage_error | `maxValue=100` `minValue=-100` |
| 120 | [Greatest Common Divisor of N Numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/greatest_common_divisor.py) | $GCD(860597057,541815762)=$ | $1$ | greatest_common_divisor | `numbersCount=2` `maximalNumberLimit=10**9` |
| 124 | [Is Composite](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/basic_math/is_composite.py) | Is $144$ composite? | Yes | is_composite | `maxNum=250` |
## calculus
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 7 | [Power Rule Differentiation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/calculus/power_rule_differentiation.py) | $2x^{6} + 5x^{4} + 6x^{4} + 9x^{4}$ | $12x^{5} + 20x^{3} + 24x^{3} + 36x^{3}$ | power_rule_differentiation | `maxCoef=10` `maxExp=10` `maxTerms=5` |
| 48 | [Power Rule Integration](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/calculus/power_rule_integration.py) | $8x^{1} + 1x^{9} + 5x^{1}$ | $\frac{8}{1}x^{2} + \frac{1}{9}x^{10} + \frac{5}{1}x^{2} + C$ | power_rule_integration | `maxCoef=10` `maxExp=10` `maxTerms=5` |
| 88 | [Trigonometric Differentiation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/calculus/trig_differentiation.py) | $\frac{d}{dx}(\sin)=$ | $\cos$ | trig_differentiation | |
| 89 | [Definite Integral of Quadratic Equation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/calculus/definite_integral.py) | The definite integral within limits $0$ to $1$ of the equation $24x^2 + 93x + 13 = $ | $67.5$ | definite_integral | `max_coeff=100` |
| 110 | [Stationary Points](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/calculus/stationary_points.py) | $f(x)=10*x^3 + 8*x^2 + 2*x + 5$ | ${- \frac{1}{3}, - \frac{1}{5}}$ | stationary_points | `maxExp=3` `maxCoef=10` |
## computer_science
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 4 | [Binary Complement 1s](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/binary_complement_1s.py) | $010 = $ | $101$ | binary_complement_1s | `maxDigits=10` |
| 5 | [Modulo Division](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/modulo_division.py) | $84$ % $20 = $ | $4$ | modulo_division | `maxRes=99` `maxModulo=99` |
| 14 | [Decimal to Binary](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/decimal_to_binary.py) | Binary of $49 = $ | $110001$ | decimal_to_binary | `max_dec=99` |
| 15 | [Binary to Decimal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/binary_to_decimal.py) | $00$ | $0$ | binary_to_decimal | `max_dig=10` |
| 56 | [Fibonacci Series](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/fibonacci_series.py) | The Fibonacci Series of the first ${n}$ numbers is ? | $0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89$ | fibonacci_series | `minNo=1` |
| 62 | [nth Fibonacci number](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/nth_fibonacci_number.py) | What is the 74th Fibonacci number? | $1304969544928660$ | nth_fibonacci_number | `maxN=100` |
| 64 | [Binary to Hexidecimal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/binary_to_hex.py) | $11010100$ | $0xd4$ | binary_to_hex | `max_dig=10` |
| 73 | [Binary 2's Complement](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/binary_2s_complement.py) | 2's complement of $1 = $ | $1$ | binary_2s_complement | `maxDigits=10` |
| 79 | [Decimal to Hexadecimal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/decimal_to_hexadeci.py) | Binary of $639 = $ | $0x27f$ | decimal_to_hexadeci | `max_dec=1000` |
| 84 | [Converts decimal to octal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/decimal_to_octal.py) | The decimal number ${x}$ in Octal is: | $0o5206$ | decimal_to_octal | `maxDecimal=4096` |
| 91 | [Binary Coded Decimal to Integer](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/bcd_to_decimal.py) | Integer of Binary Coded Decimal $3$ is $=$ | $12440$ | bcd_to_decimal | `maxNumber=10000` |
| 103 | [Decimal to Binary Coded Decimal](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/computer_science/decimal_to_bcd.py) | BCD of Decimal Number $6981 = $ | $11145$ | decimal_to_bcd | `maxNumber=10000` |
## geometry
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 18 | [Area of Triangle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/area_of_triangle.py) | Area of triangle with side lengths: $5, 15 11 = $ | $19.14$ | area_of_triangle | `maxA=20` `maxB=20` |
| 19 | [Triangle exists check](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/valid_triangle.py) | Does triangle with sides $20, 17$ and $29$ exist? | $Yes$ | valid_triangle | `maxSideLength=50` |
| 22 | [Third Angle of Triangle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/third_angle_of_triangle.py) | Third angle of triangle with angles $1$ and $86 = $ | $93$ | third_angle_of_triangle | `maxAngle=89` |
| 25 | [Pythagorean Theorem](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/pythagorean_theorem.py) | What is the hypotenuse of a right triangle given the other two sides have lengths $18$ and $9$? | $20.12$ | pythagorean_theorem | `maxLength=20` |
| 29 | [Angle of a Regular Polygon](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/angle_regular_polygon.py) | Find the angle of a regular polygon with $7$ sides | $128.57$ | angle_regular_polygon | `minVal=3` `maxVal=20` |
| 32 | [Surface Area of Cube](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_cube.py) | Surface area of cube with side $= 17m$ is | $1734 m^2$ | surface_area_cube | `maxSide=20` `unit='m'` |
| 33 | [Surface Area of Cuboid](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_cuboid.py) | Surface area of cuboid with sides of lengths: $9m, 11m, 20m$ is | $998 m^2$ | surface_area_cuboid | `maxSide=20` `unit='m'` |
| 34 | [Surface Area of Cylinder](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_cylinder.py) | Surface area of cylinder with height $= 25m$ and radius $= 18m$ is | $4863 m^2$ | surface_area_cylinder | `maxRadius=20` `maxHeight=50` `unit='m'` |
| 35 | [Volume of Cube](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_cube.py) | Volume of cube with a side length of $13m$ is | $2197 m^3$ | volume_cube | `maxSide=20` `unit='m'` |
| 36 | [Volume of Cuboid](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_cuboid.py) | Volume of cuboid with sides = $2m, 6m, 18m$ is | $216 m^3$ | volume_cuboid | `maxSide=20` `unit='m'` |
| 37 | [Volume of cylinder](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_cylinder.py) | Volume of cylinder with height $= 28m$ and radius $= 5m$ is | $2199 m^3$ | volume_cylinder | `maxRadius=20` `maxHeight=50` `unit='m'` |
| 38 | [Surface Area of cone](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_cone.py) | Surface area of cone with height $= 37m$ and radius $= 15m$ is | $2588 m^2$ | surface_area_cone | `maxRadius=20` `maxHeight=50` `unit='m'` |
| 39 | [Volume of cone](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_cone.py) | Volume of cone with height $= 17m$ and radius $= 1m$ is | $17 m^3$ | volume_cone | `maxRadius=20` `maxHeight=50` `unit='m'` |
| 49 | [Fourth Angle of Quadrilateral](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/fourth_angle_of_quadrilateral.py) | Fourth angle of quadrilateral with angles $108 , 35, 117 =$ | $100$ | fourth_angle_of_quadrilateral | `maxAngle=180` |
| 57 | [Trigonometric Values](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/basic_trigonometry.py) | $\tan(0) = $ | $0$ | basic_trigonometry | `angles=[0, 30, 45, 60, 90]` `functions=['sin', 'cos', 'tan']` |
| 58 | [Sum of Angles of Polygon](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/sum_of_polygon_angles.py) | What is the sum of interior angles of a polygon with $5$ sides? | $540$ | sum_of_polygon_angles | `maxSides=12` |
| 60 | [Surface Area of Sphere](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_sphere.py) | Surface area of Sphere with radius $= 14m$ is | $2463.0086404143976 m^2$ | surface_area_sphere | `maxSide=20` `unit='m'` |
| 61 | [Volume of Sphere](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_sphere.py) | Volume of sphere with radius $12 m = $ | $7238.229473870882 m^3$ | volume_sphere | `maxRadius=100` |
| 70 | [Angle between 2 vectors](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/angle_btw_vectors.py) | angle between the vectors $[90.18, 778.39, 6.95, 189.4, 402.86]$ and $[937.62, 966.01, 986.87, 311.51, 725.29]$ is: | $0.77$ radians | angle_btw_vectors | `maxEltAmt=20` |
| 75 | [Area of a Sector](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/sector_area.py) | What is the area of a sector with radius $27$ and angle $340$ degrees? | $2162.99$ | sector_area | `maxRadius=49` `maxAngle=359` |
| 86 | [Degrees to Radians](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/degree_to_rad.py) | Angle $50$ degrees in radians is: | $0.87$ | degree_to_rad | `max_deg=360` |
| 87 | [Radians to Degrees](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/radian_to_deg.py) | Angle $1.14$ radians in degrees is: | $65.32$ | radian_to_deg | `max_rad=6.28` |
| 95 | [Curved surface area of a cylinder](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/curved_surface_area_cylinder.py) | What is the curved surface area of a cylinder of radius, $42$ and height, $28$? | $7389.03$ | curved_surface_area_cylinder | `maxRadius=49` `maxHeight=99` |
| 96 | [Perimeter of Polygons](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/perimeter_of_polygons.py) | The perimeter of a $11$ sided polygon with lengths of $16, 109, 106, 37, 3, 59, 49, 1, 88, 43, 42$cm is: | $553$ | perimeter_of_polygons | `maxSides=12` `maxLength=120` |
| 104 | [Circumference](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/circumference.py) | Circumference of circle with radius $37 = $ | $232.48$ | circumference | `maxRadius=100` |
| 108 | [Arc length of Angle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/arc_length.py) | Given radius, $49$ and angle, $13$. Find the arc length of the angle. | Arc length of the angle $= 11.11775$ | arc_length | `maxRadius=49` `maxAngle=359` |
| 112 | [Area of Circle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/area_of_circle.py) | Area of circle with radius $92=$ | $26590.44$ | area_of_circle | `maxRadius=100` |
| 113 | [Volume of frustum](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_frustum.py) | Volume of frustum with height $= 33m$ and $r1 = 7m$ is and $r2 = 7m$ is | $6669.0 m^3$ | volume_frustum | `maxR1=20` `maxR2=20` `maxHeight=50` `unit='m'` |
| 114 | [Equation of line from two points](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/equation_of_line_from_two_points.py) | What is the equation of the line between points $(20,7)$ and $(-12,12)$ in slope-intercept form? | $32y = -5x + 324$ | equation_of_line_from_two_points | `maxCoordinate=20` `minCoordinate=-20` |
| 115 | [Area of Circle given center and a point on circle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/area_of_circle_given_center_and_point.py) | Area of circle with center $(-8,9)$ and passing through $(-4.0, 9.0)$ is | $50.27$ | area_of_circle_given_center_and_point | `maxCoordinate = 10` `maxRadius=10` |
| 117 | [Volume of Hemisphere](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_hemisphere.py) | Volume of hemisphere with radius $25 m =$ | $32724.923 m^3$ | volume_hemisphere | `maxRadius=100` |
| 122 | [Volume of pyramid](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/volume_pyramid.py) | Volume of pyramid with base length $= 3 m$, base width $= 1 m$ and height $= 2 m$ is | $2.0 m^3$ | volume_pyramid | `maxLength=20` `maxWidth=20` `maxHeight=50` `unit='m'` |
| 123 | [Surface area of pyramid](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/surface_area_pyramid.py) | Surface area of pyramid with base length $= 6m$, base width $= 6m$, and height $= 4m$ is | $96 m^2$ | surface_area_pyramid | `unit='m'` |
| 125 | [Complementary and Supplementary Angle](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/geometry/complementary_and_supplementary_angle.py) | The supplementary angle of 48 = | 132 | complementary_and_supplementary_angle | `maxSupp=180` `maxComp=90` |
## misc
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 9 | [LCM (Least Common Multiple)](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/lcm.py) | LCM of $11$ and $12 =$ | $132$ | lcm | `maxVal=20` |
| 10 | [GCD (Greatest Common Denominator)](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/gcd.py) | GCD of $20$ and $9 = $ | $1$ | gcd | `maxVal=20` |
| 27 | [Prime Factorisation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/prime_factors.py) | Find prime factors of $84$ | $2, 2, 3, 7$ | prime_factors | `minVal=1` `maxVal=200` |
| 40 | [Common Factors](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/common_factors.py) | Common Factors of $7$ and $44 = $ | $[1]$ | common_factors | `maxVal=100` |
| 51 | [HCF (Highest Common Factor)](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/hcf.py) | HCF of $13$ and $5 = $ | $1$ | hcf | `maxVal=20` |
| 55 | [Comparing surds](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/surds_comparison.py) | Fill in the blanks $23^{\frac{1}{9}}$ _ $63^{\frac{1}{2}}$ | $<$ | surds_comparison | `maxValue=100` `maxRoot=10` |
| 63 | [Profit or Loss Percent](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/profit_loss_percent.py) | Profit percent when $CP = 145$ and $SP = 782$ is: | $439.31$ | profit_loss_percent | `maxCP=1000` `maxSP=1000` |
| 66 | [Geometric Progression](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/geometric_progression.py) | For the given GP $[3, 36, 432, 5184, 62208, 746496]$. Find the value of a common ratio, 10th term value, sum upto 10th term | The value of a is $3$, common ratio is $12$ , 10th term is $15479341056$, sum upto 10th term is $16886553879.0$ | geometric_progression | `number_values=6` `min_value=2` `max_value=12` `n_term=7` `sum_term=5` |
| 67 | [Geometric Mean of N Numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/geometric_mean.py) | Geometric mean of $3$ numbers $[15, 90, 74] = $ | $46.4$ | geometric_mean | `maxValue=100` `maxCount=4` |
| 68 | [Harmonic Mean of N Numbers](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/harmonic_mean.py) | Harmonic mean of $4$ numbers $4, 94, 70, 14 = $ | $40.42123738481791$ | harmonic_mean | `maxValue=100` `maxNum=4` |
| 69 | [Euclidian norm or L2 norm of a vector](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/euclidian_norm.py) | Euclidian norm or L2 norm of the vector $[667.6348977529038, 679.4272834518646, 255.59424823283462, 642.7158651607829, 619.0578738657584, 693.3434890856785, 107.39417747607006]$ is: | $1503.75$ | euclidian_norm | `maxEltAmt=20` |
| 81 | [Celsius To Fahrenheit](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/celsius_to_fahrenheit.py) | Convert $2$ degrees Celsius to degrees Fahrenheit | $35.6$ | celsius_to_fahrenheit | `maxTemp=100` |
| 82 | [AP Term Calculation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/arithmetic_progression_term.py) | Find term number $67$ of the AP series: $56, 133, 210 ... $ | $5138$ | arithmetic_progression_term | `maxd=100` `maxa=100` `maxn=100` |
| 83 | [AP Sum Calculation](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/arithmetic_progression_sum.py) | Find the sum of first $54$ terms of the AP series: $83, 42, 1 ... $ | $-54189.0$ | arithmetic_progression_sum | `maxd=100` `maxa=100` `maxn=100` |
| 85 | [Converts decimal to Roman Numerals](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/decimal_to_roman_numerals.py) | The number $0$ in Roman Numerals is: | $MMCCCLVI$ | decimal_to_roman_numerals | `maxDecimal=4000` |
| 92 | [Complex To Polar Form](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/complex_to_polar.py) | $17.12(2.0\theta + i17.0\theta)$ | $1.45$ | complex_to_polar | `minRealImaginaryNum=-20, maxRealImaginaryNum=20` |
| 93 | [Union,Intersection,Difference of Two Sets](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/set_operation.py) | Given the two sets $a={2, 6, 8, 9, 10}$, $b={8, 10, 4}. Find the Union, intersection, a-b, b-a, and symmetric difference | Union is ${2, 4, 6, 8, 9, 10}$. Intersection is ${8, 10}$, a-b is ${9, 2, 6}$, b-a is ${4}$. Symmetric difference is ${2, 4, 6, 9}$. | set_operation | `minval=3` `maxval=7` `n_a=4` `n_b=5` |
| 94 | [Base Conversion](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/base_conversion.py) | Convert $56371$ from base $10$ to base $5$. | $3300441$ | base_conversion | `maxNum=60000` `maxBase=16` |
| 98 | [Quotient of Powers with Same Base](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/quotient_of_power_same_base.py) | The Quotient of $17^{1}$ and $17^{9} = $17^{1-9} = 17^{-8}$ | $1.4335360832968505e-10$ | quotient_of_power_same_base | `maxBase=50` `maxPower=10` |
| 99 | [Quotient of Powers with Same Power](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/quotient_of_power_same_power.py) | The Quotient of $33^{4}$ and $23^{4} = (33/23)^4 = 1.434782608695652^{4}$ | $4.237838629793346$ | quotient_of_power_same_power | `maxBase=50` `maxPower=10` |
| 101 | [Leap Year or Not](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/is_leap_year.py) | Is 1906 a leap year? | 1906 is not a leap year | is_leap_year | `minNumber=1900` `maxNumber=2099` |
| 102 | [Minute to Hour conversion](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/minutes_to_hours.py) | Convert $381$ minutes to hours & minutes | $6$ hours and $21$ minutes | minutes_to_hours | `maxMinutes=999` |
| 106 | [signum function](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/signum_function.py) | signum of 985 is = | $1$ | signum_function | `min=-999` `max=999` |
| 109 | [Binomial distribution](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/binomial_distribution.py) | A manufacturer of metal pistons finds that, on average, $34.46$% of the pistons they manufacture are rejected because they are incorrectly sized. What is the probability that a batch of $10$ pistons will contain no more than $8$ rejected pistons? | $99.95$ | binomial_distribution | `` |
| 116 | [Factors of a number](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/factors.py) | Factors of $949 = $ | $[1, 13, 73, 949]$ | factors | `maxVal=1000` |
| 121 | [Product of scientific notations](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/misc/product_of_scientific_notations.py) | Product of scientific notations $7.83 \times 10^{-39}$ and $6.12 \times 10^{-95} = $ | $4.79 \times 10^{-133}$ | product_of_scientific_notations | `minExpVal=-100` `maxExpVal=100` |
## statistics
| Id | Skill | Example problem | Example Solution | Function Name | Kwargs |
|------|-------|-----------------|------------------|---------------|--------|
| 30 | [Combinations of Objects](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/combinations.py) | Find the number of combinations from $14$ objects picked $6$ at a time. | $3003$ | combinations | `maxlength=20` |
| 42 | [Permutations](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/permutation.py) | Number of Permutations from $17$ objects picked $6$ at a time is: | $8910720$ | permutation | `maxlength=20` |
| 52 | [Probability of a certain sum appearing on faces of dice](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/dice_sum_probability.py) | If $3$ dice are rolled at the same time, the probability of getting a sum of $3 =$ | \frac{1}{216} | dice_sum_probability | `maxDice=3` |
| 54 | [Confidence interval For sample S](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/confidence_interval.py) | The confidence interval for sample $[226, 260, 221, 245, 282, 274, 207, 299, 257, 211, 233, 239, 206, 208, 242, 224, 265, 287, 230, 276, 256, 237, 215, 291, 216, 251, 255, 229, 279, 275, 210, 203, 220, 292]$ with $95$% confidence is | $(254.41804694839914, 235.052541286895)$ | confidence_interval | `` |
| 59 | [Mean,Standard Deviation,Variance](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/data_summary.py) | Find the mean,standard deviation and variance for the data $48, 38, 10, 5, 24, 46, 50, 17, 20, 13, 17, 14, 5, 20, 34$ | The Mean is $24.066666666666666$, Standard Deviation is $220.0622222222222$, Variance is $14.834494336586678$ | data_summary | `number_values=15` `minval=5` `maxval=50` |
| 76 | [Mean and Median](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/mean_median.py) | Given the series of numbers $[6, 30, 32, 39, 42, 65, 72, 80, 84, 85]$. Find the arithmatic mean and mdian of the series | Arithmetic mean of the series is $53.5$ and Arithmetic median of this series is $53.5$ | mean_median | `maxlen=10` |
| 107 | [Conditional Probability](https://github.com/lukew3/mathgenerator/blob/main/mathgenerator/funcs/statistics/conditional_probability.py) | Someone tested positive for a nasty disease which only $1.26\%$ of the population have. Test sensitivity (true positive) is equal to $SN=93.71$% whereas test specificity (true negative) $SP=90.62\%$. What is the probability that this guy really has that disease? | $11.31$% | conditional_probability | `` |
## Documentation
Documentation can be found at https://lukew3.github.io/mathgenerator

View File

@@ -3,4 +3,4 @@ flake8
autopep8
sympy
scipy
worksheetgen
pdoc

7
docs/index.html Normal file
View File

@@ -0,0 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./mathgenerator.html"/>
</head>
</html>

484
docs/mathgenerator.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2218
docs/mathgenerator/misc.html Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

46
docs/search.js Normal file

File diff suppressed because one or more lines are too long

2
makedocs.sh Executable file
View File

@@ -0,0 +1,2 @@
pdoc mathgenerator !mathgenerator.mathgen --math -o docs
python -m http.server -d docs

View File

@@ -1,9 +1,31 @@
from .funcs import *
from .generator import getGenList
"""
.. include:: ../README.md
"""
genList = getGenList()
from .algebra import *
from .basic_math import *
from .calculus import *
from .computer_science import *
from .geometry import *
from .misc import *
from .statistics import *
from ._gen_list import gen_list
# [funcname, subjectname]
def get_gen_list():
return gen_list
def gen_by_id(id, *args, **kwargs):
return globals()[gen_list[id][0]](*args, **kwargs)
# Legacy Functions
def getGenList():
return gen_list
def genById(id, *args, **kwargs):
generator = genList[id][2]
return (generator(*args, **kwargs))
return globals()[gen_list[id][0]](*args, **kwargs)

128
mathgenerator/_gen_list.py Normal file
View File

@@ -0,0 +1,128 @@
gen_list = [
("addition", "basic_math"),
("subtraction", "basic_math"),
("multiplication", "basic_math"),
("division", "basic_math"),
("binary_complement_1s", "computer_science"),
("modulo_division", "computer_science"),
("square_root", "basic_math"),
("power_rule_differentiation", "calculus"),
("square", "basic_math"),
("lcm", "misc"),
("DELETED", "DELETED"),
("basic_algebra", "algebra"),
("log", "algebra"),
("fraction_to_decimal", "basic_math"),
("decimal_to_binary", "computer_science"),
("binary_to_decimal", "computer_science"),
("divide_fractions", "basic_math"),
("multiply_int_to_22_matrix", "algebra"),
("area_of_triangle", "geometry"),
("valid_triangle", "geometry"),
("midpoint_of_two_points", "algebra"),
("factoring", "algebra"),
("third_angle_of_triangle", "geometry"),
("system_of_equations", "algebra"),
("distance_two_points", "algebra"),
("pythagorean_theorem", "geometry"),
("linear_equations", "algebra"),
("prime_factors", "misc"),
("fraction_multiplication", "basic_math"),
("angle_regular_polygon", "geometry"),
("combinations", "statistics"),
("factorial", "basic_math"),
("surface_area_cube", "geometry"),
("surface_area_cuboid", "geometry"),
("surface_area_cylinder", "geometry"),
("volume_cube", "geometry"),
("volume_cuboid", "geometry"),
("volume_cylinder", "geometry"),
("surface_area_cone", "geometry"),
("volume_cone", "geometry"),
("common_factors", "misc"),
("intersection_of_two_lines", "algebra"),
("permutation", "statistics"),
("vector_cross", "algebra"),
("compare_fractions", "basic_math"),
("simple_interest", "algebra"),
("matrix_multiplication", "algebra"),
("cube_root", "basic_math"),
("power_rule_integration", "calculus"),
("fourth_angle_of_quadrilateral", "geometry"),
("quadratic_equation", "algebra"),
("DELETED", "DELETED"),
("dice_sum_probability", "statistics"),
("exponentiation", "basic_math"),
("confidence_interval", "statistics"),
("surds_comparison", "misc"),
("fibonacci_series", "computer_science"),
("basic_trigonometry", "geometry"),
("sum_of_polygon_angles", "geometry"),
("data_summary", "statistics"),
("surface_area_sphere", "geometry"),
("volume_sphere", "geometry"),
("nth_fibonacci_number", "computer_science"),
("profit_loss_percent", "misc"),
("binary_to_hex", "computer_science"),
("multiply_complex_numbers", "algebra"),
("geometric_progression", "misc"),
("geometric_mean", "misc"),
("harmonic_mean", "misc"),
("euclidian_norm", "misc"),
("angle_btw_vectors", "geometry"),
("absolute_difference", "basic_math"),
("vector_dot", "algebra"),
("binary_2s_complement", "computer_science"),
("invert_matrix", "algebra"),
("sector_area", "geometry"),
("mean_median", "statistics"),
("int_matrix_22_determinant", "algebra"),
("compound_interest", "algebra"),
("decimal_to_hexadeci", "computer_science"),
("percentage", "basic_math"),
("celsius_to_fahrenheit", "misc"),
("arithmetic_progression_term", "misc"),
("arithmetic_progression_sum", "misc"),
("decimal_to_octal", "computer_science"),
("decimal_to_roman_numerals", "misc"),
("degree_to_rad", "geometry"),
("radian_to_deg", "geometry"),
("trig_differentiation", "calculus"),
("definite_integral", "calculus"),
("is_prime", "basic_math"),
("bcd_to_decimal", "computer_science"),
("complex_to_polar", "misc"),
("set_operation", "misc"),
("base_conversion", "misc"),
("curved_surface_area_cylinder", "geometry"),
("perimeter_of_polygons", "geometry"),
("power_of_powers", "basic_math"),
("quotient_of_power_same_base", "misc"),
("quotient_of_power_same_power", "misc"),
("complex_quadratic", "algebra"),
("is_leap_year", "misc"),
("minutes_to_hours", "misc"),
("decimal_to_bcd", "computer_science"),
("circumference", "geometry"),
("combine_like_terms", "algebra"),
("signum_function", "misc"),
("conditional_probability", "statistics"),
("arc_length", "geometry"),
("binomial_distribution", "misc"),
("stationary_points", "calculus"),
("expanding", "algebra"),
("area_of_circle", "geometry"),
("volume_cone_frustum", "geometry"),
("equation_of_line_from_two_points", "geometry"),
("area_of_circle_given_center_and_point", "geometry"),
("factors", "misc"),
("volume_hemisphere", "geometry"),
("percentage_difference", "basic_math"),
("percentage_error", "basic_math"),
("greatest_common_divisor", "basic_math"),
("product_of_scientific_notations", "misc"),
("volume_pyramid", "geometry"),
("surface_area_pyramid", "geometry"),
("is_composite", "basic_math"),
("complementary_and_supplementary_angle", "geometry"),
]

View File

@@ -1,13 +1,13 @@
def frac(num, den):
return f'\\frac{{{num}}}{{{den}}}'
return rf'\frac{{{num}}}{{{den}}}'
def bmatrix(lst):
"""Turns 2d matrix into a bmatrix"""
out = '\\begin{bmatrix} '
out = r'\begin{bmatrix} '
lst = [' & '.join(map(str, row)) for row in lst]
out += ' \\\\ '.join(lst)
return out + ' \\end{bmatrix}'
out += r' \\\ '.join(lst)
return out + r' \end{bmatrix}'
def exp(base, exp):

725
mathgenerator/algebra.py Normal file
View File

@@ -0,0 +1,725 @@
from ._latexBuilder import bmatrix
import random
import math
import fractions
import sympy
def basic_algebra(max_variable=10):
r"""Basic Algebra
| Ex. Problem | Ex. Solution |
| --- | --- |
| $1x + 5 = 5$ | $0$ |
"""
a = random.randint(1, max_variable)
b = random.randint(1, max_variable)
c = random.randint(b, max_variable)
# calculate gcd
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
i = calculate_gcd((c - b), a)
x = f"{(c - b)//i}/{a//i}"
if (c - b == 0):
x = "0"
elif a == 1 or a == i:
x = f"{c - b}"
problem = f"${a}x + {b} = {c}$"
solution = f"${x}$"
return problem, solution
def combine_like_terms(max_coef=10, max_exp=20, max_terms=10):
r"""Combine Like Terms
| Ex. Problem | Ex. Solution |
| --- | --- |
| $6x^{9} + 3x^{2} + 5x^{19} + 3x^{17}$ | $3x^{2} + 6x^{9} + 3x^{17} + 5x^{19}$ |
"""
numTerms = random.randint(1, max_terms)
coefs = [random.randint(1, max_coef) for _ in range(numTerms)]
exponents = [random.randint(1, max(max_exp - 1, 2))
for _ in range(numTerms)]
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:
d[exponents[i]] = coefs[i]
solution = " + ".join([f"{d[k]}x^{{{k}}}" for k in sorted(d)])
return f'${problem}$', f'${solution}$'
def complex_quadratic(prob_type=0, max_range=10):
r"""Complex Quadratic Equation
| Ex. Problem | Ex. Solution |
| --- | --- |
| Find the roots of given Quadratic Equation $x^2 + 8x + 8 = 0$ | $((-1.172, -6.828)) = (\frac{-8 + \sqrt{32}}{2*1}, (\frac{-8 - \sqrt{32}}{2*1})$ |
"""
if prob_type < 0 or prob_type > 1:
print("prob_type not supported")
print("prob_type = 0 for real roots problems ")
print("prob_tpye = 1 for imaginary roots problems")
return None
if prob_type == 0:
d = -1
while d < 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
else:
d = 0
while d >= 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
eq = ''
if a == 1:
eq += 'x^2 + '
else:
eq += str(a) + 'x^2 + '
if b == 1:
eq += 'x + '
else:
eq += str(b) + 'x + '
eq += str(c) + ' = 0'
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 = rf'(\frac{{{-b} + {sqrt_d}i}}{{2*{a}}}, \frac{{{-b} - {sqrt_d}i}}{{2*{a}}})'
else:
solution = rf'(\frac{{{-b} + \sqrt{{{-d}}}i}}{{2*{a}}}, \frac{{{-b} - \sqrt{{{-d}}}i}}{{2*{a}}})'
return problem, solution
else:
s_root1 = round((-b + (d)**0.5) / (2 * a), 3)
s_root2 = round((-b - (d)**0.5) / (2 * a), 3)
sqrt_d = (d)**0.5
if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
g_sol = rf'(\frac{{{-b} + {sqrt_d}}}{{2*{a}}}, \frac{{{-b} - {sqrt_d}}}{{2*{a}}})'
else:
g_sol = rf'(\frac{{{-b} + \sqrt{{{d}}}}}{{2*{a}}}, (\frac{{{-b} - \sqrt{{{d}}}}}{{2*{a}}})'
solution = f'$({s_root1, s_root2}) = {g_sol}$'
return problem, solution
def compound_interest(max_principle=10000,
max_rate=10,
max_time=10):
r"""Compound Interest
| Ex. Problem | Ex. Solution |
| --- | --- |
| Compound interest for a principle amount of $2679$ dollars, $9$% rate of interest and for a time period of $3$ years is $=$ | $3469.38$ |
"""
p = random.randint(1000, max_principle)
r = random.randint(1, max_rate)
n = random.randint(1, max_time)
a = round(p * (1 + r / 100)**n, 2)
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}$'
def distance_two_points(max_val_xy=20, min_val_xy=-20):
r"""Distance between 2 points
| Ex. Problem | Ex. Solution |
| --- | --- |
| Find the distance between $(-19, -6)$ and $(15, -16)$ | $\sqrt{1256}$ |
"""
point1X = random.randint(min_val_xy, max_val_xy + 1)
point1Y = random.randint(min_val_xy, max_val_xy + 1)
point2X = random.randint(min_val_xy, max_val_xy + 1)
point2Y = random.randint(min_val_xy, max_val_xy + 1)
distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2
solution = rf"$\sqrt{{{distanceSq}}}$"
problem = f"Find the distance between $({point1X}, {point1Y})$ and $({point2X}, {point2Y})$"
return problem, solution
def expanding(range_x1=10,
range_x2=10,
range_a=10,
range_b=10):
r"""Expanding Factored Binomial
| Ex. Problem | Ex. Solution |
| --- | --- |
|$(x-6)(-3x-3)$ | $x^2+18x+18$ |
"""
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 f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""
c1 = intParser(a * b)
c2 = intParser((a * x2) + (b * x1))
c3 = intParser(x1 * x2)
p1 = intParser(a)
p2 = intParser(x1)
p3 = intParser(b)
p4 = intParser(x2)
if p1 == "+1":
p1 = ""
elif len(p1) > 0 and p1[0] == "+":
p1 = p1[1:]
if p3 == "+1":
p3 = ""
elif p3[0] == "+":
p3 = p3[1:]
if c1 == "+1":
c1 = ""
elif len(c1) > 0 and c1[0] == "+":
c1 = c1[1:] # Cuts off the plus for readability
if c2 == "+1":
c2 = ""
problem = f"$({p1}x{p2})({p3}x{p4})$"
solution = f"${c1}x^2{c2}x{c3}$"
return problem, solution
def factoring(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)
| Ex. Problem | Ex. Solution |
| --- | --- |
| $x^2+2x-24$ | $(x-4)(x+6)$ |
"""
x1 = random.randint(-range_x1, range_x1)
x2 = random.randint(-range_x2, range_x2)
def intParser(z):
if (z > 0):
return f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""
b = intParser(x1 + x2)
c = intParser(x1 * x2)
if b == "+1":
b = "+"
if b == "":
problem = f"x^2{c}"
else:
problem = f"x^2{b}x{c}"
x1 = intParser(x1)
x2 = intParser(x2)
solution = f"$(x{x1})(x{x2})$"
return f"${problem}$", solution
def int_matrix_22_determinant(max_matrix_val=100):
r"""Determinant to 2x2 Matrix
| Ex. Problem | Ex. Solution |
| --- | --- |
| $\det \begin{bmatrix} 88 & 40 \\\ 9 & 91 \end{bmatrix}= $ | $7648$ |
"""
a = random.randint(0, max_matrix_val)
b = random.randint(0, max_matrix_val)
c = random.randint(0, max_matrix_val)
d = random.randint(0, max_matrix_val)
determinant = a * d - b * c
lst = [[a, b], [c, d]]
problem = rf"$\det {bmatrix(lst)}= $"
solution = f"${determinant}$"
return problem, solution
def intersection_of_two_lines(min_m=-10,
max_m=10,
min_b=-10,
max_b=10,
min_denominator=1,
max_denominator=6):
r"""Intersection of two lines
| Ex. Problem | Ex. Solution |
| --- | --- |
| Find the point of intersection of the two lines: $y = \frac{-2}{6}x + 3$ and $y = \frac{3}{6}x - 8$ | $(\frac{66}{5}, \frac{-7}{5})$ |
"""
def generateEquationString(m, b):
"""
Generates an equation given the slope and intercept.
It handles cases where m is fractional.
It also ensures that we don't have weird signs such as y = mx + -b.
"""
if m[0] == 0:
m = 0
elif abs(m[0]) == abs(m[1]):
m = m[0] // m[1]
elif m[1] == 1:
m = m[0]
else:
m = rf"\frac{{{m[0]}}}{{{m[1]}}}"
base = "y ="
if m != 0:
if m == 1:
base = f"{base} x"
elif m == -1:
base = f"{base} -x"
else:
base = f"{base} {m}x"
if b > 0:
if m == 0:
return f"{base} {b}"
else:
return f"{base} + {b}"
elif b < 0:
if m == 0:
return f"{base} -{b * -1}"
else:
return f"{base} - {b * -1}"
else:
if m == 0:
return f"{base} 0"
else:
return base
def fractionToString(x):
"""
Converts the given fractions.Fraction into a string.
"""
if x.denominator == 1:
x = x.numerator
else:
x = rf"\frac{{{x.numerator}}}{{{x.denominator}}}"
return x
m1 = (random.randint(min_m,
max_m), random.randint(min_denominator, max_denominator))
m2 = (random.randint(min_m,
max_m), random.randint(min_denominator, max_denominator))
b1 = random.randint(min_b, max_b)
b2 = random.randint(min_b, max_b)
eq1 = generateEquationString(m1, b1)
eq2 = generateEquationString(m2, b2)
problem = f"Find the point of intersection of the two lines: ${eq1}$ and ${eq2}$"
m1 = fractions.Fraction(*m1)
m2 = fractions.Fraction(*m2)
# if m1 == m2 then the slopes are equal
# This can happen if both line are the same
# Or if they are parallel
# In either case there is no intersection
if m1 == m2:
solution = "No Solution"
else:
intersection_x = (b1 - b2) / (m2 - m1)
intersection_y = ((m2 * b1) - (m1 * b2)) / (m2 - m1)
solution = f"$({fractionToString(intersection_x)}, {fractionToString(intersection_y)})$"
return problem, solution
def invert_matrix(square_matrix_dimension=3,
max_matrix_element=99,
only_integer_elements_in_inverted_matrixe=True):
r"""Invert Matrix
| Ex. Problem | Ex. Solution |
| --- | --- |
| Inverse of Matrix $\begin{bmatrix} 4 & 1 & 4 \\\ 5 & 1 & 5 \\\ 12 & 3 & 13 \end{bmatrix}$ is: | $\begin{bmatrix} 2 & 1 & -1 \\\ 5 & -4 & 0 \\\ -3 & 0 & 1 \end{bmatrix}$ |
"""
if only_integer_elements_in_inverted_matrixe is True:
isItOk = False
Mat = list()
while (isItOk is False):
Mat = list()
for i in range(0, square_matrix_dimension):
z = list()
for j in range(0, square_matrix_dimension):
z.append(0)
z[i] = 1
Mat.append(z)
MaxAllowedMatrixElement = math.ceil(
pow(max_matrix_element, 1 / (square_matrix_dimension)))
randomlist = random.sample(range(0, MaxAllowedMatrixElement + 1),
square_matrix_dimension)
for i in range(0, square_matrix_dimension):
if i == square_matrix_dimension - 1:
Mat[0] = [
j + (k * randomlist[i])
for j, k in zip(Mat[0], Mat[i])
]
else:
Mat[i + 1] = [
j + (k * randomlist[i])
for j, k in zip(Mat[i + 1], Mat[i])
]
for i in range(1, square_matrix_dimension - 1):
Mat[i] = [
sum(i) for i in zip(Mat[square_matrix_dimension - 1], Mat[i])
]
isItOk = True
for i in Mat:
for j in i:
if j > max_matrix_element:
isItOk = False
break
if isItOk is False:
break
random.shuffle(Mat)
Mat = sympy.Matrix(Mat)
Mat = sympy.Matrix.transpose(Mat)
Mat = Mat.tolist()
random.shuffle(Mat)
Mat = sympy.Matrix(Mat)
Mat = sympy.Matrix.transpose(Mat)
else:
randomlist = list(sympy.primerange(0, max_matrix_element + 1))
plist = random.sample(randomlist, square_matrix_dimension)
randomlist = random.sample(
range(0, max_matrix_element + 1),
square_matrix_dimension * square_matrix_dimension)
randomlist = list(set(randomlist) - set(plist))
n_list = random.sample(
randomlist, square_matrix_dimension * (square_matrix_dimension - 1))
Mat = list()
for i in range(0, square_matrix_dimension):
z = list()
z.append(plist[i])
for j in range(0, square_matrix_dimension - 1):
z.append(n_list[(i * square_matrix_dimension) + j - i])
random.shuffle(z)
Mat.append(z)
Mat = sympy.Matrix(Mat)
problem = 'Inverse of Matrix $' + bmatrix(Mat.tolist()) + '$ is:'
solution = f'${bmatrix(sympy.Matrix.inv(Mat).tolist())}$'
return problem, solution
def linear_equations(n=2, var_range=20, coeff_range=20):
r"""Linear Equations
| Ex. Problem | Ex. Solution |
| --- | --- |
| Given the equations $10x + -20y = 310$ and $-16x + -17y = 141$, solve for $x$ and $y$ | $x = 5$, $y = -13$ |
"""
if n > 10:
print("[!] n cannot be greater than 10")
return None, None
vars = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'][:n]
soln = [random.randint(-var_range, var_range) for i in range(n)]
problem = list()
solution = "$, $".join(
["{} = {}".format(vars[i], soln[i]) for i in range(n)])
for _ in range(n):
coeff = [random.randint(-coeff_range, coeff_range) for i in range(n)]
res = sum([coeff[i] * soln[i] for i in range(n)])
prob = [
"{}{}".format(coeff[i], vars[i]) if coeff[i] != 0 else ""
for i in range(n)
]
while "" in prob:
prob.remove("")
prob = " + ".join(prob) + " = " + str(res)
problem.append(prob)
# problem = "\n".join(problem)
problem = "$ and $".join(problem)
return f'Given the equations ${problem}$, solve for $x$ and $y$', f'${solution}$'
def log(max_base=3, max_val=8):
r"""Logarithm
| Ex. Problem | Ex. Solution |
| --- | --- |
| $log_{3}(243)=$ | $5$ |
"""
a = random.randint(1, max_val)
b = random.randint(2, max_base)
c = pow(b, a)
problem = f'$log_{{{b}}}({c})=$'
solution = f'${a}$'
return problem, solution
def matrix_multiplication(max_val=100, max_dim=10):
r"""Multiply Two Matrices
| Ex. Problem | Ex. Solution |
| --- | --- |
| Multiply $\begin{bmatrix} 15 & 72 \\\ 64 & -20 \\\ 18 & 59 \\\ -21 & -55 \\\ 20 & -12 \\\ -75 & -42 \\\ 47 & 89 \\\ -53 & 27 \\\ -56 & 44 \end{bmatrix}$ and $\begin{bmatrix} 49 & -2 & 68 & -28 \\\ 49 & 6 & 83 & 42 \end{bmatrix}$ | $\begin{bmatrix} 4263 & 402 & 6996 & 2604 \\\ 2156 & -248 & 2692 & -2632 \\\ 3773 & 318 & 6121 & 1974 \\\ -3724 & -288 & -5993 & -1722 \\\ 392 & -112 & 364 & -1064 \\\ -5733 & -102 & -8586 & 336 \\\ 6664 & 440 & 10583 & 2422 \\\ -1274 & 268 & -1363 & 2618 \\\ -588 & 376 & -156 & 3416 \end{bmatrix}$ |
"""
m = random.randint(2, max_dim)
n = random.randint(2, max_dim)
k = random.randint(2, max_dim)
# generate matrices a and b
a = [[random.randint(-max_val, max_val) for _ in range(n)]
for _ in range(m)]
b = [[random.randint(-max_val, max_val) for _ in range(k)]
for _ in range(n)]
res = []
for r in range(m):
res.append([])
for c in range(k):
temp = 0
for t in range(n):
temp += a[r][t] * b[t][c]
res[r].append(temp)
problem = f"Multiply ${bmatrix(a)}$ and ${bmatrix(b)}$"
solution = f'${bmatrix(res)}$'
return problem, solution
def midpoint_of_two_points(max_value=20):
r"""Midpoint of two points
| Ex. Problem | Ex. Solution |
| --- | --- |
| The midpoint of $(-8,10)$ and $(18,0) = $ | $(5.0,5.0)$ |
"""
x1 = random.randint(-20, max_value)
y1 = random.randint(-20, max_value)
x2 = random.randint(-20, max_value)
y2 = random.randint(-20, max_value)
xm = (x1 + x2) / 2
ym = (y1 + y2) / 2
problem = f"The midpoint of $({x1},{y1})$ and $({x2},{y2}) = $"
solution = f"$({xm},{ym})$"
return problem, solution
def multiply_complex_numbers(min_real_imaginary_num=-20,
max_real_imaginary_num=20):
r"""Multiplication of 2 complex numbers
| Ex. Problem | Ex. Solution |
| --- | --- |
| $(14+18j) * (14+15j) = $ | $(-74+462j)$ |
"""
num1 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num),
random.randint(min_real_imaginary_num, max_real_imaginary_num))
num2 = complex(random.randint(min_real_imaginary_num, max_real_imaginary_num),
random.randint(min_real_imaginary_num, max_real_imaginary_num))
product = num1 * num2
problem = f"${num1} * {num2} = $"
solution = f'${product}$'
return problem, solution
def multiply_int_to_22_matrix(max_matrix_val=10, max_res=100):
r"""Multiply Integer to 2x2 Matrix
| Ex. Problem | Ex. Solution |
| --- | --- |
| $5 * \begin{bmatrix} 1 & 0 \\\ 2 & 9 \end{bmatrix} =$ | $\begin{bmatrix} 5 & 0 \\\ 10 & 45 \end{bmatrix}$ |
"""
a = random.randint(0, max_matrix_val)
b = random.randint(0, max_matrix_val)
c = random.randint(0, max_matrix_val)
d = random.randint(0, max_matrix_val)
constant = random.randint(0, int(max_res / max(a, b, c, d)))
a1 = a * constant
b1 = b * constant
c1 = c * constant
d1 = d * constant
lst = [[a, b], [c, d]]
lst1 = [[a1, b1], [c1, d1]]
problem = f'${constant} * {bmatrix(lst)} =$'
solution = f'${bmatrix(lst1)}$'
return problem, solution
def quadratic_equation(max_val=100):
r"""Quadratic Equation
| Ex. Problem | Ex. Solution |
| --- | --- |
| What are the zeros of the quadratic equation $22x^2+137x+25=0$ | ${-0.19, -6.04}$ |
"""
a = random.randint(1, max_val)
c = random.randint(1, max_val)
b = random.randint(
round(math.sqrt(4 * a * c)) + 1, round(math.sqrt(4 * max_val * max_val)))
D = math.sqrt(b * b - 4 * a * c)
res = {round((-b + D) / (2 * a), 2), round((-b - D) / (2 * a), 2)}
problem = f"What are the zeros of the quadratic equation ${a}x^2+{b}x+{c}=0$"
solution = f'${res}$'
return problem, solution
def simple_interest(max_principle=10000,
max_rate=10,
max_time=10):
r"""Simple Interest
| Ex. Problem | Ex. Solution |
| --- | --- |
| Simple interest for a principle amount of $7217$ dollars, $3$% rate of interest and for a time period of $10$ years is $=$ | $2165.1$ |
"""
p = random.randint(1000, max_principle)
r = random.randint(1, max_rate)
t = random.randint(1, max_time)
s = round((p * r * t) / 100, 2)
problem = f"Simple interest for a principle amount of ${p}$ dollars, ${r}$% rate of interest and for a time period of ${t}$ years is $=$ "
solution = f'${s}$'
return problem, solution
def system_of_equations(range_x=10,
range_y=10,
coeff_mult_range=10):
r"""Solve a System of Equations in R^2
| Ex. Problem | Ex. Solution |
| --- | --- |
| Given $-x + 5y = -28$ and $9x + 2y = 64$, solve for $x$ and $y$. | $x = 8$, $y = -4$ |
"""
# 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"Given ${coeffToFuncString(new_c1)}$ and ${coeffToFuncString(new_c2)}$, solve for $x$ and $y$."
solution = f"$x = {x}$, $y = {y}$"
return problem, solution
# Add random (non-zero) multiple of equations to each other
def vector_cross(min_val=-20, max_val=20):
r"""Cross product of 2 vectors
| Ex. Problem | Ex. Solution |
| --- | --- |
| $[-1, -4, 10] \times [-11, 1, -16] = $ | $[54, -126, -45]$ |
"""
a = [random.randint(min_val, max_val) for _ in range(3)]
b = [random.randint(min_val, max_val) for _ in range(3)]
c = [
a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]
]
problem = rf"${a} \times {b} = $"
solution = f"${c}$"
return problem, solution
def vector_dot(min_val=-20, max_val=20):
r"""Dot product of 2 vectors
| Ex. Problem | Ex. Solution |
| --- | --- |
| $[12, -9, -8]\cdot[-9, 8, 1]=$ | $-188$ |
"""
a = [random.randint(min_val, max_val) for i in range(3)]
b = [random.randint(min_val, max_val) for i in range(3)]
c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
problem = rf'${a}\cdot{b}=$'
solution = f'${c}$'
return problem, solution

405
mathgenerator/basic_math.py Normal file
View File

@@ -0,0 +1,405 @@
import random
def absolute_difference(max_a=100, max_b=100):
r"""Absolute difference between two numbers
| Ex. Problem | Ex. Solution |
| --- | --- |
| $|22-34|=$ | $12$ |
"""
a = random.randint(-1 * max_a, max_a)
b = random.randint(-1 * max_b, max_b)
absDiff = abs(a - b)
return f'$|{a}-{b}|=$', f"${absDiff}$"
def addition(max_sum=99, max_addend=50):
r"""Addition of two numbers
| Ex. Problem | Ex. Solution |
| --- | --- |
| $22+34=$ | $56$ |
"""
if max_addend > max_sum:
max_addend = max_sum
a = random.randint(0, max_addend)
# The highest value of b will be no higher than the max_sum minus the first number and no higher than the max_addend as well
b = random.randint(0, min((max_sum - a), max_addend))
c = a + b
problem = f'${a}+{b}=$'
solution = f'${c}$'
return problem, solution
def compare_fractions(max_val=10):
r"""Compare Fractions
| Ex. Problem | Ex. Solution |
| --- | --- |
| Which symbol represents the comparison between $\frac{1}{2}$ and $\frac{3}{4}$? | $>$ |
"""
a = random.randint(1, max_val)
b = random.randint(1, max_val)
c = random.randint(1, max_val)
d = random.randint(1, max_val)
while (a == b):
b = random.randint(1, max_val)
while (c == d):
d = random.randint(1, max_val)
first = a / b
second = c / d
if (first > second):
solution = ">"
elif (first < second):
solution = "<"
else:
solution = "="
problem = rf"Which symbol represents the comparison between $\frac{{{a}}}{{{b}}}$ and $\frac{{{c}}}{{{d}}}$?"
return problem, solution
def cube_root(min_no=1, max_no=1000):
r"""Cube Root
| Ex. Problem | Ex. Solution |
| --- | --- |
| What is the cube root of: $\sqrt[3]{125}=$ to 2 decimal places? | $5$ |
"""
b = random.randint(min_no, max_no)
a = b**(1 / 3)
return (rf"What is the cube root of: $\sqrt[3]{{{b}}}=$ to 2 decimal places?", f"${round(a, 2)}$")
def divide_fractions(max_val=10):
r"""Divide Fractions
| Ex. Problem | Ex. Solution |
| --- | --- |
| $\frac{7}{9}\div\frac{4}{1}=$ | $\frac{7}{36}$ |
"""
a = random.randint(1, max_val)
b = random.randint(1, max_val)
while (a == b):
b = random.randint(1, max_val)
c = random.randint(1, max_val)
d = random.randint(1, max_val)
while (c == d):
d = random.randint(1, max_val)
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
tmp_n = a * d
tmp_d = b * c
gcd = calculate_gcd(tmp_n, tmp_d)
sol_numerator = tmp_n // gcd
sol_denominator = tmp_d // gcd
return rf'$\frac{{{a}}}{{{b}}}\div\frac{{{c}}}{{{d}}}=$', f'$\frac{{{sol_numerator}}}{{{sol_denominator}}}$'
def division(max_a=25, max_b=25):
r"""Division
| Ex. Problem | Ex. Solution |
| --- | --- |
| $216\div24=$ | $9$ |
"""
a = random.randint(1, max_a)
b = random.randint(1, max_b)
divisor = a * b
dividend = random.choice([a, b])
quotient = int(divisor / dividend)
return rf'${divisor}\div{dividend}=$', f'${quotient}$'
def exponentiation(max_base=20, max_expo=10):
r"""Exponentiation
| Ex. Problem | Ex. Solution |
| --- | --- |
| $9^{5}=$ | $8$ |
"""
base = random.randint(1, max_base)
expo = random.randint(1, max_expo)
return f'${base}^{{{expo}}}=$', f'${base**expo}$'
def factorial(max_input=6):
r"""Factorial
| Ex. Problem | Ex. Solution |
| --- | --- |
| $4! =$ | $24$ |
"""
a = random.randint(0, max_input)
n = a
b = 1
while a != 1 and n > 0:
b *= n
n -= 1
return f'${a}! =$', f'${b}$'
def fraction_multiplication(max_val=10):
r"""Fraction Multiplication
| Ex. Problem | Ex. Solution |
| --- | --- |
| $\frac{3}{10}\cdot\frac{6}{7}=$ | $\frac{9}{35}$ |
"""
a = random.randint(1, max_val)
b = random.randint(1, max_val)
c = random.randint(1, max_val)
d = random.randint(1, max_val)
while (a == b):
b = random.randint(1, max_val)
while (c == d):
d = random.randint(1, max_val)
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
tmp_n = a * c
tmp_d = b * d
gcd = calculate_gcd(tmp_n, tmp_d)
problem = rf"$\frac{{{a}}}{{{b}}}\cdot\frac{{{c}}}{{{d}}}=$"
if (tmp_d == 1 or tmp_d == gcd):
solution = rf"$\frac{{{tmp_n}}}{{{gcd}}}$"
else:
solution = rf"$\frac{{{tmp_n//gcd}}}{{{tmp_d//gcd}}}$"
return problem, solution
def fraction_to_decimal(max_res=99, max_divid=99):
r"""Fraction to Decimal
| Ex. Problem | Ex. Solution |
| --- | --- |
| $83\div80=$ | $1.04$ |
"""
a = random.randint(0, max_divid)
b = random.randint(1, min(max_res, max_divid))
c = round(a / b, 2)
return rf'${a}\div{b}=$', f'${c}$'
def greatest_common_divisor(numbers_count=2, max_num=10**3):
r"""Greatest Common Divisor of N Numbers ( GCD / HCF )
| Ex. Problem | Ex. Solution |
| --- | --- |
| $GCD(488075608, 75348096)=$ | $8$ |
"""
def greatestCommonDivisorOfTwoNumbers(number1, number2):
number1 = abs(number1)
number2 = abs(number2)
while number2 > 0:
number1, number2 = number2, number1 % number2
return number1
numbers_count = max(numbers_count, 2)
numbers = [random.randint(0, max_num)
for _ in range(numbers_count)]
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[0], numbers[1])
for index in range(1, numbers_count):
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[index], greatestCommonDivisor)
return f'$GCD({",".join(map(str, numbers))})=$', f"${greatestCommonDivisor}$"
def is_composite(max_num=250):
r"""Is Composite
| Ex. Problem | Ex. Solution |
| --- | --- |
| Is $171$ composite? | Yes |
"""
a = random.randint(2, max_num)
problem = f"Is ${a}$ composite?"
if a == 0 or a == 1:
return problem, "No"
for i in range(2, a):
if a % i == 0:
return problem, "Yes"
solution = "No"
return problem, solution
def is_prime(max_num=100):
r"""Is Prime
| Ex. Problem | Ex. Solution |
| --- | --- |
| Is $37$ prime? | Yes |
"""
a = random.randint(2, max_num)
problem = f"Is ${a}$ prime?"
if a == 2:
return problem, "Yes"
if a % 2 == 0:
return problem, "No"
for i in range(3, a // 2 + 1, 2):
if a % i == 0:
return problem, "No"
solution = "Yes"
return problem, solution
def multiplication(max_multi=12):
r"""Multiplication
| Ex. Problem | Ex. Solution |
| --- | --- |
| $10\cdot9=$ | $90$ |
"""
a = random.randint(0, max_multi)
b = random.randint(0, max_multi)
c = a * b
return rf'${a}\cdot{b}=$', f'${c}$'
def percentage(max_value=99, max_percentage=99):
r"""Percentage of a number
| Ex. Problem | Ex. Solution |
| --- | --- |
| What is $45$% of $39$? | $17.55$ |
"""
a = random.randint(1, max_percentage)
b = random.randint(1, max_value)
problem = f"What is ${a}$% of ${b}$?"
percentage = a / 100 * b
formatted_float = "{:.2f}".format(percentage)
solution = f"${formatted_float}$"
return problem, solution
def percentage_difference(max_value=200, min_value=0):
r"""Percentage difference between two numbers
| Ex. Problem | Ex. Solution |
| --- | --- |
| What is the percentage difference between $2$ and $10$? | $133.33$ |
"""
value_a = random.randint(min_value, max_value)
value_b = random.randint(min_value, max_value)
diff = 2 * (abs(value_a - value_b) / abs(value_a + value_b)) * 100
diff = round(diff, 2)
problem = f"What is the percentage difference between ${value_a}$ and ${value_b}$?"
solution = f'${diff}$%'
return problem, solution
def percentage_error(max_value=100, min_value=-100):
r"""Percentage error
| Ex. Problem | Ex. Solution |
| --- | --- |
| Find the percentage error when observed value equals $32$ and exact value equals $81$. | $60.49$% |
"""
observed_value = random.randint(min_value, max_value)
exact_value = random.randint(min_value, max_value)
if observed_value * exact_value < 0:
observed_value *= -1
error = (abs(observed_value - exact_value) / abs(exact_value)) * 100
error = round(error, 2)
problem = f"Find the percentage error when observed value equals ${observed_value}$ and exact value equals ${exact_value}$."
solution = f'${error}$%'
return problem, solution
def power_of_powers(max_base=50, max_power=10):
r"""Power of Powers
| Ex. Problem | Ex. Solution |
| --- | --- |
| Simplify $18^{10^{8}}$ | $18^{80}$ |
"""
base = random.randint(1, max_base)
power1 = random.randint(1, max_power)
power2 = random.randint(1, max_power)
step = power1 * power2
problem = f"Simplify ${base}^{{{power1}^{{{power2}}}}}$"
solution = f"${base}^{{{step}}}$"
return problem, solution
def square(max_square_num=20):
r"""Square
| Ex. Problem | Ex. Solution |
| --- | --- |
| $17^2=$ | $289$ |
"""
a = random.randint(1, max_square_num)
b = a ** 2
return f'${a}^2=$', f'${b}$'
def square_root(min_no=1, max_no=12):
r"""Square Root
| Ex. Problem | Ex. Solution |
| --- | --- |
| $\sqrt{64}=$ | $8$ |
"""
b = random.randint(min_no, max_no)
a = b ** 2
return rf'$\sqrt{{{a}}}=$', f'${b}$'
def subtraction(max_minuend=99, max_diff=99):
r"""Subtraction of two numbers
| Ex. Problem | Ex. Solution |
| --- | --- |
| $54-22=$ | $32$ |
"""
a = random.randint(0, max_minuend)
b = random.randint(max(0, (a - max_diff)), a)
c = a - b
return f'${a}-{b}=$', f'${c}$'

120
mathgenerator/calculus.py Normal file
View File

@@ -0,0 +1,120 @@
import random
from scipy.integrate import quad
import sympy
def definite_integral(max_coef=100):
r"""Definite Integral of Quadratic Equation
| Ex. Problem | Ex. Solution |
| --- | --- |
| The definite integral within limits $0$ to $1$ of the equation $28x^2 + 32x + 66 = $ | $91.33$ |
"""
def integrand(x, a, b, c):
return a * x**2 + b * x + c
a = random.randint(0, max_coef)
b = random.randint(0, max_coef)
c = random.randint(0, max_coef)
result = quad(integrand, 0, 1, args=(a, b, c))[0]
solution = round(result, 2)
problem = f"The definite integral within limits $0$ to $1$ of the equation ${a}x^2 + {b}x + {c} = $"
return problem, f'${solution}$'
def power_rule_differentiation(max_coef=10,
max_exp=10,
max_terms=5):
r"""Power Rule Differentiation
| Ex. Problem | Ex. Solution |
| --- | --- |
| Differentiate $1x^{5} + 4x^{7} + 4x^{4}$ | $5x^{4} + 28x^{6} + 16x^{3}$ |
"""
numTerms = random.randint(1, max_terms)
problem = "Differentiate $"
solution = "$"
for i in range(numTerms):
if i > 0:
problem += " + "
solution += " + "
coefficient = random.randint(1, max_coef)
exponent = random.randint(1, max_exp)
problem += f'{coefficient}x^{{{exponent}}}'
solution += f'{coefficient * exponent}x^{{{exponent - 1}}}'
return problem + '$', solution + '$'
def power_rule_integration(max_coef=10,
max_exp=10,
max_terms=5):
r"""Power Rule Integration
| Ex. Problem | Ex. Solution |
| --- | --- |
| Integrate $9x^{6} + 2x^{6} + 4x^{3}$ | $\frac{9}{6}x^{7} + \frac{2}{6}x^{7} + \frac{4}{3}x^{4} + C$ |
"""
numTerms = random.randint(1, max_terms)
problem = "Integrate $"
solution = "$"
for i in range(numTerms):
if i > 0:
problem += " + "
solution += " + "
coefficient = random.randint(1, max_coef)
exponent = random.randint(1, max_exp)
problem += f'{coefficient}x^{{{exponent}}}'
solution += rf'\frac{{{coefficient}}}{{{exponent}}}x^{{{exponent + 1}}}'
solution += " + C"
return problem + '$', solution + '$'
def stationary_points(max_exp=3, max_coef=10):
r"""Stationary Points
| Ex. Problem | Ex. Solution |
| --- | --- |
| $f(x)=6*x^3 + 6*x^2 + x + 8$ | ${- \frac{1}{3} - \frac{\sqrt{2}}{6}, - \frac{1}{3} + \frac{\sqrt{2}}{6}}$ |
"""
solution = ''
while len(solution) == 0:
x = sympy.symbols('x')
problem = 0
for exp in range(max_exp + 1):
coefficient = random.randint(0, max_coef)
problem += coefficient * pow(x, exp)
solution = sympy.stationary_points(problem, x)
problem = 'f(x)=' + str(problem).replace('**', '^')
return f'${problem}$', f'${sympy.latex(solution)[6:-8]}}}$'
def trig_differentiation():
r"""Trigonometric Differentiation
| Ex. Problem | Ex. Solution |
| --- | --- |
| $\frac{d}{dx}(\csc)=$ | $-\csc \cdot \cot$ |
"""
pairs = {
r'\sin': r'\cos',
r'\cos': r'-\sin',
r'\tan': r'\sec^{{2}}',
r'\cot': r'-\csc^{{2}}',
r'\sec': r'\sec \cdot \tan',
r'\csc': r'-\csc \cdot \cot'
}
problem = random.choice(list(pairs.keys()))
solution = f'${pairs[problem]}$'
problem = rf'$\frac{{d}}{{dx}}({problem})=$'
return problem, solution

View File

@@ -0,0 +1,225 @@
import random
import math
def bcd_to_decimal(max_number=10000):
r"""Binary Coded Decimal to Integer
| Ex. Problem | Ex. Solution |
| --- | --- |
| Integer of Binary Coded Decimal $4 =$ | $17801$ |
"""
n = random.randint(1000, max_number)
binstring = ''
while True:
q, r = divmod(n, 10)
nibble = bin(r).replace('0b', "")
while len(nibble) < 4:
nibble = '0' + nibble
binstring = nibble + binstring
if q == 0:
break
else:
n = q
problem = f"Integer of Binary Coded Decimal ${n} =$ "
solution = f'${int(binstring, 2)}$'
return problem, solution
def binary_2s_complement(maxDigits=10):
r"""Binary 2's Complement
| Ex. Problem | Ex. Solution |
| --- | --- |
| 2's complement of $1011 = $ | $101$ |
"""
digits = random.randint(1, maxDigits)
question = ''.join([str(random.randint(0, 1))
for i in range(digits)]).lstrip('0')
answer = []
for i in question:
answer.append(str(int(not bool(int(i)))))
carry = True
j = len(answer) - 1
while j >= 0:
if answer[j] == '0':
answer[j] = '1'
carry = False
break
answer[j] = '0'
j -= 1
if j == 0 and carry is True:
answer.insert(0, '1')
problem = f"2's complement of ${question} = $"
solution = ''.join(answer).lstrip('0')
return problem, f'${solution}$'
def binary_complement_1s(maxDigits=10):
r"""Binary Complement 1s
| Ex. Problem | Ex. Solution |
| --- | --- |
| $1111001 = $ | $0000110$ |
"""
question = ''.join([str(random.randint(0, 1))
for _ in range(random.randint(1, maxDigits))])
answer = ''.join(["0" if digit == "1" else "1" for digit in question])
problem = f'${question} = $'
return problem, f'${answer}$'
def binary_to_decimal(max_dig=10):
r"""Binary to Decimal
| Ex. Problem | Ex. Solution |
| --- | --- |
| $000110$ | $6$ |
"""
problem = ''.join([str(random.randint(0, 1))
for _ in range(random.randint(1, max_dig))])
solution = f'${int(problem, 2)}$'
return f'${problem}$', solution
def binary_to_hex(max_dig=10):
r"""Binary to Hexidecimal
| Ex. Problem | Ex. Solution |
| --- | --- |
| $010101$ | $0x15$ |
"""
problem = ''.join([str(random.randint(0, 1))
for _ in range(random.randint(1, max_dig))])
solution = f'${hex(int(problem, 2))}$'
return f'${problem}$', solution
def decimal_to_bcd(max_number=10000):
r"""Decimal to Binary Coded Decimal
| Ex. Problem | Ex. Solution |
| --- | --- |
| BCD of Decimal Number $6575 = $ | $191015$ |
"""
n = random.randint(1000, max_number)
x = n
# binstring = ''
bcdstring = ''
while x > 0:
nibble = x % 16
bcdstring = str(nibble) + bcdstring
x >>= 4
problem = f"BCD of Decimal Number ${n} = $"
return problem, f'${bcdstring}$'
def decimal_to_binary(max_dec=99):
r"""Decimal to Binary
| Ex. Problem | Ex. Solution |
| --- | --- |
| Binary of $4 = $ | $100$ |
"""
a = random.randint(1, max_dec)
b = bin(a).replace("0b", "")
problem = f'Binary of ${a} = $'
solution = f'${b}$'
return problem, solution
def decimal_to_hexadeci(max_dec=1000):
r"""Decimal to Hexadecimal
| Ex. Problem | Ex. Solution |
| --- | --- |
| Hexadecimal of $410 = $ | $0x19a$ |
"""
a = random.randint(0, max_dec)
b = hex(a)
problem = f"Hexadecimal of ${a} = $"
solution = f"${b}$"
return problem, solution
def decimal_to_octal(max_decimal=4096):
r"""Decimal to Octal
| Ex. Problem | Ex. Solution |
| --- | --- |
| The decimal number $3698$ in octal is: | $0o7162$ |
"""
x = random.randint(0, max_decimal)
problem = f"The decimal number ${x}$ in octal is: "
solution = f'${oct(x)}$'
return problem, solution
def fibonacci_series(min_no=1):
r"""Fibonacci Series
| Ex. Problem | Ex. Solution |
| --- | --- |
| The Fibonacci Series of the first ${n}$ numbers is ? | $0, 1, 1, 2, 3, 5, 8, 13, 21$ |
"""
n = random.randint(min_no, 20)
def createFibList(n):
list = []
for i in range(n):
if i < 2:
list.append(i)
else:
val = list[i - 1] + list[i - 2]
list.append(val)
return list
fibList = createFibList(n)
problem = "The Fibonacci Series of the first ${n}$ numbers is ?"
solution = ', '.join(map(str, fibList))
return problem, f'${solution}$'
def modulo_division(max_res=99, max_modulo=99):
r"""Modulo Division
| Ex. Problem | Ex. Solution |
| --- | --- |
| $43$ % $33 = $ | $10$ |
"""
a = random.randint(0, max_modulo)
b = random.randint(0, min(max_res, max_modulo))
c = a % b if b != 0 else 0
problem = f'${a}$ % ${b} = $'
solution = f'${c}$'
return problem, solution
def nth_fibonacci_number(max_n=100):
r"""nth Fibonacci number
| Ex. Problem | Ex. Solution |
| --- | --- |
| What is the 85th Fibonacci number? | $259695496911123328$ |
"""
gratio = (1 + math.sqrt(5)) / 2
n = random.randint(1, max_n)
problem = f"What is the {n}th Fibonacci number?"
solution = int(
(math.pow(gratio, n) - math.pow(-gratio, -n)) / (math.sqrt(5)))
return problem, f'${solution}$'

View File

@@ -1,7 +0,0 @@
from .algebra import *
from .basic_math import *
from .calculus import *
from .computer_science import *
from .geometry import *
from .misc import *
from .statistics import *

View File

@@ -1,21 +0,0 @@
from .basic_algebra import basic_algebra
from .combine_like_terms import combine_like_terms
from .complex_quadratic import complex_quadratic
from .compound_interest import compound_interest
from .distance_two_points import distance_two_points
from .expanding import expanding
from .factoring import factoring
from .int_matrix_22_determinant import int_matrix_22_determinant
from .intersection_of_two_lines import intersection_of_two_lines
from .invert_matrix import invert_matrix
from .linear_equations import linear_equations
from .log import log
from .matrix_multiplication import matrix_multiplication
from .midpoint_of_two_points import midpoint_of_two_points
from .multiply_complex_numbers import multiply_complex_numbers
from .multiply_int_to_22_matrix import multiply_int_to_22_matrix
from .quadratic_equation import quadratic_equation
from .simple_interest import simple_interest
from .system_of_equations import system_of_equations
from .vector_cross import vector_cross
from .vector_dot import vector_dot

View File

@@ -1,30 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxVariable=10):
a = random.randint(1, maxVariable)
b = random.randint(1, maxVariable)
c = random.randint(b, maxVariable)
# calculate gcd
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
i = calculate_gcd((c - b), a)
x = f"{(c - b)//i}/{a//i}"
if (c - b == 0):
x = "0"
elif a == 1 or a == i:
x = f"{c - b}"
problem = f"${a}x + {b} = {c}$"
solution = f"${x}$"
return problem, solution
basic_algebra = Generator("Basic Algebra", 11, gen_func,
["maxVariable=10"])

View File

@@ -1,24 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxCoef=10, maxExp=20, maxTerms=10):
numTerms = random.randint(1, maxTerms)
coefs = [random.randint(1, maxCoef) for _ in range(numTerms)]
exponents = [random.randint(1, max(maxExp - 1, 2)) for _ in range(numTerms)]
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:
d[exponents[i]] = coefs[i]
solution = " + ".join([f"{d[k]}x^{{{k}}}" for k in sorted(d)])
return f'${problem}$', f'${solution}$'
combine_like_terms = Generator("Combine Like terms", 105, gen_func,
["maxCoef=10", "maxExp=20", "maxTerms=10"])

View File

@@ -1,74 +0,0 @@
from ...generator import Generator
import random
def gen_func(prob_type=0, max_range=10, format='string'):
if prob_type < 0 or prob_type > 1:
print("prob_type not supported")
print("prob_type = 0 for real roots problems ")
print("prob_tpye = 1 for imaginary roots problems")
return None
if prob_type == 0:
d = -1
while d < 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
else:
d = 0
while d >= 0:
a = random.randrange(1, max_range)
b = random.randrange(1, max_range)
c = random.randrange(1, max_range)
d = (b**2 - 4 * a * c)
eq = ''
if a == 1:
eq += 'x^2 + '
else:
eq += str(a) + 'x^2 + '
if b == 1:
eq += 'x + '
else:
eq += str(b) + 'x + '
eq += str(c) + ' = 0'
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'(\\frac{{{-b} + {sqrt_d}i}}{{2*{a}}}, \\frac{{{-b} - {sqrt_d}i}}{{2*{a}}})'
else:
solution = f'(\\frac{{{-b} + \\sqrt{{{-d}}}i}}{{2*{a}}}, \\frac{{{-b} - \\sqrt{{{-d}}}i}}{{2*{a}}})'
return problem, solution
else:
s_root1 = round((-b + (d)**0.5) / (2 * a), 3)
s_root2 = round((-b - (d)**0.5) / (2 * a), 3)
sqrt_d = (d)**0.5
if sqrt_d - int(sqrt_d) == 0:
sqrt_d = int(sqrt_d)
g_sol = f'(\\frac{{{-b} + {sqrt_d}}}{{2*{a}}}, \\frac{{{-b} - {sqrt_d}}}{{2*{a}}})'
else:
g_sol = f'(\\frac{{{-b} + \\sqrt{{{d}}}}}{{2*{a}}}, (\\frac{{{-b} - \\sqrt{{{d}}}}}{{2*{a}}})'
solution = f'$({s_root1, s_root2}) = {g_sol}$'
return problem, solution
complex_quadratic = Generator("complex Quadratic Equation", 100,
gen_func,
["prob_type=0", "max_range=10"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxPrinciple=10000,
maxRate=10,
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)
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(
"Compound Interest", 78, gen_func,
["maxPrinciple=10000", "maxRate=10", "maxTime=10"])

View File

@@ -1,20 +0,0 @@
from ...generator import Generator
import random
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
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,
gen_func,
["maxValXY=20", "minValXY=-20"])

View File

@@ -1,54 +0,0 @@
from ...generator import Generator
import random
def gen_func(range_x1=10,
range_x2=10,
range_a=10,
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 f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""
c1 = intParser(a * b)
c2 = intParser((a * x2) + (b * x1))
c3 = intParser(x1 * x2)
p1 = intParser(a)
p2 = intParser(x1)
p3 = intParser(b)
p4 = intParser(x2)
if p1 == "+1":
p1 = ""
elif len(p1) > 0 and p1[0] == "+":
p1 = p1[1:]
if p3 == "+1":
p3 = ""
elif p3[0] == "+":
p3 = p3[1:]
if c1 == "+1":
c1 = ""
elif len(c1) > 0 and c1[0] == "+":
c1 = c1[1:] # Cuts off the plus for readability
if c2 == "+1":
c2 = ""
problem = f"$({p1}x{p2})({p3}x{p4})$"
solution = f"${c1}x^2{c2}x{c3}$"
return problem, solution
expanding = Generator(
"Expanding Factored Binomial", 111, gen_func,
["range_x1=10", "range_x2=10", "range_a=10", "range_b=10"])

View File

@@ -1,35 +0,0 @@
from ...generator import Generator
import random
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 f"+{z}"
elif (z < 0):
return f"-{abs(z)}"
else:
return ""
b = intParser(x1 + x2)
c = intParser(x1 * x2)
if b == "+1":
b = "+"
if b == "":
problem = f"x^2{c}"
else:
problem = f"x^2{b}x{c}"
x1 = intParser(x1)
x2 = intParser(x2)
solution = f"$(x{x1})(x{x2})$"
return f"${problem}$", solution
factoring = Generator("Factoring Quadratic", 21, gen_func,
["range_x1=10", "range_x2=10"])

View File

@@ -1,22 +0,0 @@
from ...generator import Generator
from ...latexBuilder import bmatrix
import random
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]]
problem = f"$\\det {bmatrix(lst)}= $"
solution = f"${determinant}$"
return problem, solution
int_matrix_22_determinant = Generator("Determinant to 2x2 Matrix", 77,
gen_func,
["maxMatrixVal=100"])

View File

@@ -1,94 +0,0 @@
from ...generator import Generator
import random
import fractions
def gen_func(minM=-10,
maxM=10,
minB=-10,
maxB=10,
minDenominator=1,
maxDenominator=6):
def generateEquationString(m, b):
"""
Generates an equation given the slope and intercept.
It handles cases where m is fractional.
It also ensures that we don't have weird signs such as y = mx + -b.
"""
if m[0] == 0:
m = 0
elif abs(m[0]) == abs(m[1]):
m = m[0] // m[1]
elif m[1] == 1:
m = m[0]
else:
m = f"{m[0]}/{m[1]}"
base = "y ="
if m != 0:
if m == 1:
base = f"{base} x"
elif m == -1:
base = f"{base} -x"
else:
base = f"{base} {m}x"
if b > 0:
if m == 0:
return f"{base} {b}"
else:
return f"{base} + {b}"
elif b < 0:
if m == 0:
return f"{base} -{b * -1}"
else:
return f"{base} - {b * -1}"
else:
if m == 0:
return f"{base} 0"
else:
return base
def fractionToString(x):
"""
Converts the given fractions.Fraction into a string.
"""
if x.denominator == 1:
x = x.numerator
else:
x = f"{x.numerator}/{x.denominator}"
return x
m1 = (random.randint(minM,
maxM), random.randint(minDenominator, maxDenominator))
m2 = (random.randint(minM,
maxM), random.randint(minDenominator, maxDenominator))
b1 = random.randint(minB, maxB)
b2 = random.randint(minB, maxB)
eq1 = generateEquationString(m1, b1)
eq2 = generateEquationString(m2, b2)
problem = f"Find the point of intersection of the two lines: ${eq1}$ and ${eq2}$"
m1 = fractions.Fraction(*m1)
m2 = fractions.Fraction(*m2)
# if m1 == m2 then the slopes are equal
# This can happen if both line are the same
# Or if they are parallel
# In either case there is no intersection
if m1 == m2:
solution = "No Solution"
else:
intersection_x = (b1 - b2) / (m2 - m1)
intersection_y = ((m2 * b1) - (m1 * b2)) / (m2 - m1)
solution = f"$({fractionToString(intersection_x)}, {fractionToString(intersection_y)})$"
return problem, solution
intersection_of_two_lines = Generator(
"Intersection of Two Lines", 41, gen_func, [
"minM=-10", "maxM=10", "minB=-10", "maxB=10", "minDenominator=1",
"maxDenominator=6"
])

View File

@@ -1,88 +0,0 @@
from ...generator import Generator
from ...latexBuilder import bmatrix
import random
import math
import sympy
def gen_func(SquareMatrixDimension=3,
MaxMatrixElement=99,
OnlyIntegerElementsInInvertedMatrix=True):
if OnlyIntegerElementsInInvertedMatrix is True:
isItOk = False
Mat = list()
while (isItOk is False):
Mat = list()
for i in range(0, SquareMatrixDimension):
z = list()
for j in range(0, SquareMatrixDimension):
z.append(0)
z[i] = 1
Mat.append(z)
MaxAllowedMatrixElement = math.ceil(
pow(MaxMatrixElement, 1 / (SquareMatrixDimension)))
randomlist = random.sample(range(0, MaxAllowedMatrixElement + 1),
SquareMatrixDimension)
for i in range(0, SquareMatrixDimension):
if i == SquareMatrixDimension - 1:
Mat[0] = [
j + (k * randomlist[i])
for j, k in zip(Mat[0], Mat[i])
]
else:
Mat[i + 1] = [
j + (k * randomlist[i])
for j, k in zip(Mat[i + 1], Mat[i])
]
for i in range(1, SquareMatrixDimension - 1):
Mat[i] = [
sum(i) for i in zip(Mat[SquareMatrixDimension - 1], Mat[i])
]
isItOk = True
for i in Mat:
for j in i:
if j > MaxMatrixElement:
isItOk = False
break
if isItOk is False:
break
random.shuffle(Mat)
Mat = sympy.Matrix(Mat)
Mat = sympy.Matrix.transpose(Mat)
Mat = Mat.tolist()
random.shuffle(Mat)
Mat = sympy.Matrix(Mat)
Mat = sympy.Matrix.transpose(Mat)
else:
randomlist = list(sympy.primerange(0, MaxMatrixElement + 1))
plist = random.sample(randomlist, SquareMatrixDimension)
randomlist = random.sample(
range(0, MaxMatrixElement + 1),
SquareMatrixDimension * SquareMatrixDimension)
randomlist = list(set(randomlist) - set(plist))
n_list = random.sample(
randomlist, SquareMatrixDimension * (SquareMatrixDimension - 1))
Mat = list()
for i in range(0, SquareMatrixDimension):
z = list()
z.append(plist[i])
for j in range(0, SquareMatrixDimension - 1):
z.append(n_list[(i * SquareMatrixDimension) + j - i])
random.shuffle(z)
Mat.append(z)
Mat = sympy.Matrix(Mat)
problem = 'Inverse of Matrix $' + bmatrix(Mat.tolist()) + '$ is:'
solution = bmatrix(sympy.Matrix.inv(Mat).tolist())
return problem, solution
invert_matrix = Generator("Inverse of a Matrix", 74, gen_func, [
"SquareMatrixDimension=3", "MaxMatrixElement=99",
"OnlyIntegerElementsInInvertedMatrix=True"
])

View File

@@ -1,36 +0,0 @@
from ...generator import Generator
import random
def gen_func(n=2, varRange=20, coeffRange=20):
if n > 10:
print("[!] n cannot be greater than 10")
return None, None
vars = ['x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g'][:n]
soln = [random.randint(-varRange, varRange) for i in range(n)]
problem = list()
solution = "$, $".join(
["{} = {}".format(vars[i], soln[i]) for i in range(n)])
for _ in range(n):
coeff = [random.randint(-coeffRange, coeffRange) for i in range(n)]
res = sum([coeff[i] * soln[i] for i in range(n)])
prob = [
"{}{}".format(coeff[i], vars[i]) if coeff[i] != 0 else ""
for i in range(n)
]
while "" in prob:
prob.remove("")
prob = " + ".join(prob) + " = " + str(res)
problem.append(prob)
# problem = "\n".join(problem)
problem = "$ and $".join(problem)
return f'Given the equations ${problem}$, solve for $x$ and $y$', f'${solution}$'
linear_equations = Generator("Linear Equations", 26, gen_func,
["n=2", "varRange=20", "coeffRange=20"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxBase=3, maxVal=8, format='string'):
a = random.randint(1, maxVal)
b = random.randint(2, maxBase)
c = pow(b, a)
problem = f'$log_{{{b}}}({c})=$'
solution = f'${a}$'
return problem, solution
log = Generator("Logarithm", 12, gen_func, ["maxBase=3", "maxVal=8"])

View File

@@ -1,31 +0,0 @@
from ...generator import Generator
from ...latexBuilder import bmatrix
import random
def gen_func(maxVal=100, max_dim=10):
m = random.randint(2, max_dim)
n = random.randint(2, max_dim)
k = random.randint(2, max_dim)
# generate matrices a and b
a = [[random.randint(-maxVal, maxVal) for _ in range(n)] for _ in range(m)]
b = [[random.randint(-maxVal, maxVal) for _ in range(k)] for _ in range(n)]
res = []
for r in range(m):
res.append([])
for c in range(k):
temp = 0
for t in range(n):
temp += a[r][t] * b[t][c]
res[r].append(temp)
problem = f"Multiply ${bmatrix(a)}$ and ${bmatrix(b)}$"
solution = f'${bmatrix(res)}$'
return problem, solution
matrix_multiplication = Generator("Multiplication of two matrices", 46,
gen_func,
["maxVal=100", "max_dim=10"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxValue=20):
x1 = random.randint(-20, maxValue)
y1 = random.randint(-20, maxValue)
x2 = random.randint(-20, maxValue)
y2 = random.randint(-20, maxValue)
xm = (x1 + x2) / 2
ym = (y1 + y2) / 2
problem = f"The midpoint of $({x1},{y1})$ and $({x2},{y2}) = $"
solution = f"$({xm},{ym})$"
return problem, solution
midpoint_of_two_points = Generator("Midpoint of the two point", 20,
gen_func, ["maxValue=20"])

View File

@@ -1,20 +0,0 @@
from ...generator import Generator
import random
def gen_func(minRealImaginaryNum=-20,
maxRealImaginaryNum=20):
num1 = complex(random.randint(minRealImaginaryNum, maxRealImaginaryNum),
random.randint(minRealImaginaryNum, maxRealImaginaryNum))
num2 = complex(random.randint(minRealImaginaryNum, maxRealImaginaryNum),
random.randint(minRealImaginaryNum, maxRealImaginaryNum))
product = num1 * num2
problem = f"${num1} * {num2} = $"
solution = f'${product}$'
return problem, solution
multiply_complex_numbers = Generator(
"Multiplication of 2 complex numbers", 65, gen_func,
["minRealImaginaryNum=-20", "maxRealImaginaryNum=20"])

View File

@@ -1,28 +0,0 @@
from ...generator import Generator
from ...latexBuilder import bmatrix
import random
def gen_func(maxMatrixVal=10, maxRes=100, format='string'):
a = random.randint(0, maxMatrixVal)
b = random.randint(0, maxMatrixVal)
c = random.randint(0, maxMatrixVal)
d = random.randint(0, maxMatrixVal)
constant = random.randint(0, int(maxRes / max(a, b, c, d)))
a1 = a * constant
b1 = b * constant
c1 = c * constant
d1 = d * constant
lst = [[a, b], [c, d]]
lst1 = [[a1, b1], [c1, d1]]
problem = f'${constant} * {bmatrix(lst)} =$'
solution = f'${bmatrix(lst1)}$'
return problem, solution
multiply_int_to_22_matrix = Generator("Integer Multiplication with 2x2 Matrix",
17, gen_func,
["maxMatrixVal=10", "maxRes=100"])

View File

@@ -1,20 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxVal=100):
a = random.randint(1, maxVal)
c = random.randint(1, maxVal)
b = random.randint(
round(math.sqrt(4 * a * c)) + 1, round(math.sqrt(4 * maxVal * maxVal)))
D = math.sqrt(b * b - 4 * a * c)
res = {round((-b + D) / (2 * a), 2), round((-b - D) / (2 * a), 2)}
problem = f"What are the zeros of the quadratic equation ${a}x^2+{b}x+{c}=0$"
solution = f'${res}$'
return problem, solution
quadratic_equation = Generator("Quadratic Equation", 50, gen_func,
["maxVal=100"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxPrinciple=10000,
maxRate=10,
maxTime=10):
p = random.randint(1000, maxPrinciple)
r = random.randint(1, maxRate)
t = random.randint(1, maxTime)
s = round((p * r * t) / 100, 2)
problem = f"Simple interest for a principle amount of ${p}$ dollars, ${r}$% rate of interest and for a time period of ${t}$ years is $=$ "
solution = f'${s}$'
return problem, solution
simple_interest = Generator("Simple Interest", 45, gen_func,
["maxPrinciple=10000", "maxRate=10", "maxTime=10"])

View File

@@ -1,56 +0,0 @@
from ...generator import Generator
import random
def gen_func(range_x=10,
range_y=10,
coeff_mult_range=10,
format='string'):
# 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"Given ${coeffToFuncString(new_c1)}$ and ${coeffToFuncString(new_c2)}$, solve for $x$ and $y$."
solution = f"$x = {x}$, $y = {y}$"
return problem, solution
# Add random (non-zero) multiple of equations to each other
system_of_equations = Generator(
"Solve a System of Equations in R^2", 23, gen_func,
["range_x=10", "range_y=10", "coeff_mult_range=10"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(minVal=-20, maxVal=20):
a = [random.randint(minVal, maxVal) for _ in range(3)]
b = [random.randint(minVal, maxVal) for _ in range(3)]
c = [
a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]
]
problem = f"${a} \\times {b} = $"
solution = f"${c}$"
return problem, solution
vector_cross = Generator("Cross Product of 2 Vectors", 43, gen_func,
["minVal=-20", "maxVal=20"])

View File

@@ -1,16 +0,0 @@
from ...generator import Generator
import random
def gen_func(minVal=-20, maxVal=20):
a = [random.randint(minVal, maxVal) for i in range(3)]
b = [random.randint(minVal, maxVal) for i in range(3)]
c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
problem = f'${a}\\cdot{b}=$'
solution = f'${c}$'
return problem, solution
vector_dot = Generator("Dot Product of 2 Vectors", 72, gen_func,
["minVal=-20", "maxVal=20"])

View File

@@ -1,21 +0,0 @@
from .absolute_difference import absolute_difference
from .addition import addition
from .compare_fractions import compare_fractions
from .cube_root import cube_root
from .divide_fractions import divide_fractions
from .division import division
from .exponentiation import exponentiation
from .factorial import factorial
from .fraction_multiplication import fraction_multiplication
from .fraction_to_decimal import fraction_to_decimal
from .greatest_common_divisor import greatest_common_divisor
from .is_composite import is_composite
from .is_prime import is_prime
from .multiplication import multiplication
from .percentage import percentage
from .percentage_difference import percentage_difference
from .percentage_error import percentage_error
from .power_of_powers import power_of_powers
from .square import square
from .square_root import square_root
from .subtraction import subtraction

View File

@@ -1,14 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxA=100, maxB=100):
a = random.randint(-1 * maxA, maxA)
b = random.randint(-1 * maxB, maxB)
absDiff = abs(a - b)
return f'$|{a}-{b}|=$', f"${absDiff}$"
absolute_difference = Generator("Absolute difference between two numbers", 71,
gen_func, ["maxA=100", "maxB=100"])

View File

@@ -1,18 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxSum=99, maxAddend=50):
if maxAddend > maxSum:
maxAddend = maxSum
a = random.randint(0, maxAddend)
# The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
b = random.randint(0, min((maxSum - a), maxAddend))
c = a + b
problem = f'${a}+{b}=$'
solution = f'${c}$'
return problem, solution
addition = Generator("Addition", 0, gen_func, ["maxSum=99", "maxAddend=50"])

View File

@@ -1,31 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxVal=10):
a = random.randint(1, maxVal)
b = random.randint(1, maxVal)
c = random.randint(1, maxVal)
d = random.randint(1, maxVal)
while (a == b):
b = random.randint(1, maxVal)
while (c == d):
d = random.randint(1, maxVal)
first = a / b
second = c / d
if (first > second):
solution = ">"
elif (first < second):
solution = "<"
else:
solution = "="
problem = f"Which symbol represents the comparison between $\\frac{{{a}}}{{{b}}}$ and $\\frac{{{c}}}{{{d}}}$?"
return problem, solution
compare_fractions = Generator("Compare Fractions", 44, gen_func,
["maxVal=10"])

View File

@@ -1,12 +0,0 @@
from ...generator import Generator
import random
def gen_func(minNo=1, maxNo=1000):
b = random.randint(minNo, maxNo)
a = b**(1 / 3)
return (f"What is the cube root of: $\\sqrt[3]{{{b}}}=$ to 2 decimal places?", f"${round(a, 2)}$")
cube_root = Generator("Cube Root", 47, gen_func, ["minNo=1", "maxNo=1000"])

View File

@@ -1,33 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxVal=10):
a = random.randint(1, maxVal)
b = random.randint(1, maxVal)
while (a == b):
b = random.randint(1, maxVal)
c = random.randint(1, maxVal)
d = random.randint(1, maxVal)
while (c == d):
d = random.randint(1, maxVal)
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
tmp_n = a * d
tmp_d = b * c
gcd = calculate_gcd(tmp_n, tmp_d)
sol_numerator = tmp_n // gcd
sol_denominator = tmp_d // gcd
return f'$\\frac{{{a}}}{{{b}}}\\div\\frac{{{c}}}{{{d}}}=$', f'$\\frac{{{sol_numerator}}}{{{sol_denominator}}}$'
divide_fractions = Generator("Fraction Division", 16, gen_func,
["maxVal=10"])

View File

@@ -1,16 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxA=25, maxB=25):
a = random.randint(1, maxA)
b = random.randint(1, maxB)
divisor = a * b
dividend = random.choice([a, b])
quotient = int(divisor / dividend)
return f'${divisor}\\div{dividend}=$', f'${quotient}$'
division = Generator("Division", 3, gen_func, ["maxA=25", "maxB=25"])

View File

@@ -1,13 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxBase=20, maxExpo=10):
base = random.randint(1, maxBase)
expo = random.randint(1, maxExpo)
return f'${base}^{expo} =$', f'${base**expo}$'
exponentiation = Generator("Exponentiation", 53, gen_func,
["maxBase=20", "maxExpo=10"])

View File

@@ -1,16 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxInput=6):
a = random.randint(0, maxInput)
n = a
b = 1
while a != 1 and n > 0:
b *= n
n -= 1
return f'${a}! =$', f'${b}$'
factorial = Generator("Factorial", 31, gen_func, ["maxInput=6"])

View File

@@ -1,36 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxVal=10):
a = random.randint(1, maxVal)
b = random.randint(1, maxVal)
c = random.randint(1, maxVal)
d = random.randint(1, maxVal)
while (a == b):
b = random.randint(1, maxVal)
while (c == d):
d = random.randint(1, maxVal)
def calculate_gcd(x, y):
while (y):
x, y = y, x % y
return x
tmp_n = a * c
tmp_d = b * d
gcd = calculate_gcd(tmp_n, tmp_d)
problem = f"$\\frac{{{a}}}{{{b}}}\\cdot\\frac{{{c}}}{{{d}}}=$"
if (tmp_d == 1 or tmp_d == gcd):
solution = f"$\\frac{{{tmp_n}}}{{{gcd}}}$"
else:
solution = f"$\\frac{{{tmp_n//gcd}}}{{{tmp_d//gcd}}}$"
return problem, solution
fraction_multiplication = Generator("Fraction Multiplication", 28,
gen_func, ["maxVal=10"])

View File

@@ -1,14 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxRes=99, maxDivid=99):
a = random.randint(0, maxDivid)
b = random.randint(1, min(maxRes, maxDivid))
c = round(a / b, 2)
return f'${a}\\div{b}=$', f'${c}$'
fraction_to_decimal = Generator("Fraction to Decimal", 13, gen_func,
["maxRes=99", "maxDivid=99"])

View File

@@ -1,29 +0,0 @@
from ...generator import Generator
import random
def greatestCommonDivisorOfTwoNumbers(number1, number2):
number1 = abs(number1)
number2 = abs(number2)
while number2 > 0:
number1, number2 = number2, number1 % number2
return number1
def gen_func(numbersCount=2, maximalNumberLimit=10**9):
numbersCount = max(numbersCount, 2)
numbers = [random.randint(0, maximalNumberLimit)
for number in range(numbersCount)]
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[0], numbers[1])
for index in range(1, numbersCount):
greatestCommonDivisor = greatestCommonDivisorOfTwoNumbers(
numbers[index], greatestCommonDivisor)
return f'$GCD({",".join(map(str, numbers))})=$', f"${greatestCommonDivisor}$"
greatest_common_divisor = Generator("Greatest Common Divisor of N Numbers", 120, gen_func, [
"numbersCount=2", "maximalNumberLimit=10**9"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxNum=250):
a = random.randint(2, maxNum)
problem = f"Is ${a}$ composite?"
if a == 0 or a == 1:
return problem, "No"
for i in range(2, a):
if a % i == 0:
return problem, "Yes"
solution = "No"
return problem, solution
is_composite = Generator('Is Composite', 124, gen_func, ["maxNum=250"])

View File

@@ -1,20 +0,0 @@
from ...generator import Generator
import random
def gen_func(max_num=100):
a = random.randint(2, max_num)
problem = f"Is ${a}$ prime?"
if a == 2:
return problem, "Yes"
if a % 2 == 0:
return problem, "No"
for i in range(3, a // 2 + 1, 2):
if a % i == 0:
return problem, "No"
solution = "Yes"
return problem, solution
is_prime = Generator('isprime', 90, gen_func, ["max_num=100"])

View File

@@ -1,14 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxMulti=12):
a = random.randint(0, maxMulti)
b = random.randint(0, maxMulti)
c = a * b
return f'${a}\\cdot{b}$', f'${c}$'
multiplication = Generator("Multiplication", 2, gen_func,
["maxMulti=12"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxValue=99, maxpercentage=99):
a = random.randint(1, maxpercentage)
b = random.randint(1, maxValue)
problem = f"What is ${a}$% of ${b}$?"
percentage = a / 100 * b
formatted_float = "{:.2f}".format(percentage)
solution = f"${formatted_float}$"
return problem, solution
percentage = Generator("Percentage of a number", 80, gen_func,
["maxValue=99", "maxpercentage=99"])

View File

@@ -1,18 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxValue=200, minValue=0):
value_a = random.randint(minValue, maxValue)
value_b = random.randint(minValue, maxValue)
diff = 2 * (abs(value_a - value_b) / abs(value_a + value_b)) * 100
diff = round(diff, 2)
problem = f"What is the percentage difference between ${value_a}$ and ${value_b}$?"
solution = f'${diff}$%'
return problem, solution
percentage_difference = Generator("Percentage difference", 118, gen_func,
["maxValue=200", "minValue=0"])

View File

@@ -1,22 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxValue=100, minValue=-100):
observed_value = random.randint(minValue, maxValue)
exact_value = random.randint(minValue, maxValue)
if observed_value * exact_value < 0:
observed_value *= -1
error = (abs(observed_value - exact_value) / abs(exact_value)) * 100
error = round(error, 2)
problem = f"Find the percentage error when observed value equals ${observed_value}$ and exact value equals ${exact_value}$."
solution = f'${error}\\%$'
return problem, solution
percentage_error = Generator(
"Percentage error", 119, gen_func,
["maxValue=100", "minValue=-100"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxBase=50, maxPower=10):
base = random.randint(1, maxBase)
power1 = random.randint(1, maxPower)
power2 = random.randint(1, maxPower)
step = power1 * power2
problem = f"Simplify ${base}^{{{power1}^{{{power2}}}}}$"
solution = f"${base}^{{{step}}}$"
return problem, solution
power_of_powers = Generator("Power of Powers", 97, gen_func,
["maxBase=50", "maxPower=10"])

View File

@@ -1,12 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxSquareNum=20):
a = random.randint(1, maxSquareNum)
b = a ** 2
return f'${a}^2=$', f'${b}$'
square = Generator("Square", 8, gen_func, ["maxSquareNum=20"])

View File

@@ -1,13 +0,0 @@
from ...generator import Generator
import random
def gen_func(minNo=1, maxNo=12):
b = random.randint(minNo, maxNo)
a = b ** 2
return f'$\\sqrt{{{a}}}=$', f'${b}$'
square_root = Generator("Square Root", 6, gen_func,
["minNo=1", "maxNo=12"])

View File

@@ -1,14 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxMinuend=99, maxDiff=99):
a = random.randint(0, maxMinuend)
b = random.randint(max(0, (a - maxDiff)), a)
c = a - b
return f'${a}-{b}=$', f'${c}$'
subtraction = Generator("Subtraction", 1, gen_func,
["maxMinuend=99", "maxDiff=99"])

View File

@@ -1,5 +0,0 @@
from .definite_integral import definite_integral
from .power_rule_differentiation import power_rule_differentiation
from .power_rule_integration import power_rule_integration
from .stationary_points import stationary_points
from .trig_differentiation import trig_differentiation

View File

@@ -1,23 +0,0 @@
from ...generator import Generator
import random
from scipy.integrate import quad
def gen_func(max_coeff=100):
def integrand(x, a, b, c):
return a * x**2 + b * x + c
a = random.randint(0, max_coeff)
b = random.randint(0, max_coeff)
c = random.randint(0, max_coeff)
result = quad(integrand, 0, 1, args=(a, b, c))[0]
S = round(result, 4)
problem = f"The definite integral within limits $0$ to $1$ of the equation ${a}x^2 + {b}x + {c} = $"
solution = f'${S}$'
return problem, solution
definite_integral = Generator("Definite Integral of Quadratic Equation", 89,
gen_func, ["max_coeff=100"])

View File

@@ -1,27 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxCoef=10,
maxExp=10,
maxTerms=5):
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, maxExp)
problem += f'{coefficient}x^{{{exponent}}}'
solution += f'{coefficient * exponent}x^{{{exponent - 1}}}'
return problem + '$', solution + '$'
power_rule_differentiation = Generator(
"Power Rule Differentiation", 7, gen_func,
["maxCoef=10", "maxExp=10", "maxTerms=5"])

View File

@@ -1,29 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxCoef=10,
maxExp=10,
maxTerms=5):
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, maxExp)
problem += f'{coefficient}x^{{{exponent}}}'
solution += f'\\frac{{{coefficient}}}{{{exponent}}}x^{{{exponent + 1}}}'
solution += " + C"
return problem + '$', solution + '$'
power_rule_integration = Generator("Power Rule Integration", 48,
gen_func,
["maxCoef=10", "maxExp=10", "maxTerms=5"])

View File

@@ -1,21 +0,0 @@
from ...generator import Generator
import random
import sympy
def gen_func(maxExp=3, maxCoef=10):
solution = ''
while len(solution) == 0:
x = sympy.symbols('x')
problem = 0
for exp in range(maxExp + 1):
coefficient = random.randint(0, maxCoef)
problem += coefficient * pow(x, exp)
solution = sympy.stationary_points(problem, x)
problem = 'f(x)=' + str(problem).replace('**', '^')
return f'${problem}$', f'${sympy.latex(solution)[6:-8]}}}$'
stationary_points = Generator("Stationary Points", 110, gen_func,
["maxExp=3", "maxCoef=10"])

View File

@@ -1,22 +0,0 @@
from ...generator import Generator
import random
def gen_func():
pairs = {
'\\sin': '\\cos',
'\\cos': '-\\sin',
'\\tan': '\\sec^{{2}}',
'\\cot': '-\\csc^{{2}}',
'\\sec': '\\sec \\cdot \\tan',
'\\csc': '-\\csc \\cdot \\cot'
}
problem = random.choice(list(pairs.keys()))
solution = f'${pairs[problem]}$'
problem = f'$\\frac{{d}}{{dx}}({problem})=$'
return problem, solution
trig_differentiation = Generator("Trigonometric Differentiation", 88, gen_func,
[])

View File

@@ -1,12 +0,0 @@
from .bcd_to_decimal import bcd_to_decimal
from .binary_2s_complement import binary_2s_complement
from .binary_complement_1s import binary_complement_1s
from .binary_to_decimal import binary_to_decimal
from .binary_to_hex import binary_to_hex
from .decimal_to_bcd import decimal_to_bcd
from .decimal_to_binary import decimal_to_binary
from .decimal_to_hexadeci import decimal_to_hexadeci
from .decimal_to_octal import decimal_to_octal
from .fibonacci_series import fibonacci_series
from .modulo_division import modulo_division
from .nth_fibonacci_number import nth_fibonacci_number

View File

@@ -1,25 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxNumber=10000):
n = random.randint(1000, maxNumber)
binstring = ''
while True:
q, r = divmod(n, 10)
nibble = bin(r).replace('0b', "")
while len(nibble) < 4:
nibble = '0' + nibble
binstring = nibble + binstring
if q == 0:
break
else:
n = q
problem = f"Integer of Binary Coded Decimal ${n}$ is $=$ "
solution = f'${int(binstring, 2)}$'
return problem, solution
bcd_to_decimal = Generator("Binary Coded Decimal to Integer", 91,
gen_func, ["maxNumber=10000"])

View File

@@ -1,33 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxDigits=10):
digits = random.randint(1, maxDigits)
question = ''.join([str(random.randint(0, 1))
for i in range(digits)]).lstrip('0')
answer = []
for i in question:
answer.append(str(int(not bool(int(i)))))
carry = True
j = len(answer) - 1
while j >= 0:
if answer[j] == '0':
answer[j] = '1'
carry = False
break
answer[j] = '0'
j -= 1
if j == 0 and carry is True:
answer.insert(0, '1')
problem = f"2's complement of ${question} = $"
solution = ''.join(answer).lstrip('0')
return problem, f'${solution}$'
binary_2s_complement = Generator("Binary 2's Complement", 73,
gen_func, ["maxDigits=10"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxDigits=10):
question = ''
answer = ''
for _ in range(random.randint(1, maxDigits)):
temp = str(random.randint(0, 1))
question += temp
answer += "0" if temp == "1" else "1"
problem = f'${question} = $'
return problem, f'${answer}$'
binary_complement_1s = Generator("Binary Complement 1s", 4,
gen_func, ["maxDigits=10"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
def gen_func(max_dig=10):
problem = ''
for _ in range(random.randint(1, max_dig)):
temp = str(random.randint(0, 1))
problem += temp
solution = f'${int(problem, 2)}$'
return f'${problem}$', solution
binary_to_decimal = Generator("Binary to Decimal", 15, gen_func,
["max_dig=10"])

View File

@@ -1,16 +0,0 @@
from ...generator import Generator
import random
def gen_func(max_dig=10):
problem = ''
for _ in range(random.randint(1, max_dig)):
temp = str(random.randint(0, 1))
problem += temp
solution = f'${hex(int(problem, 2))}$'
return f'${problem}$', solution
binary_to_hex = Generator("Binary to Hexidecimal", 64, gen_func,
["max_dig=10"])

View File

@@ -1,20 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxNumber=10000):
n = random.randint(1000, maxNumber)
x = n
# binstring = ''
bcdstring = ''
while x > 0:
nibble = x % 16
bcdstring = str(nibble) + bcdstring
x >>= 4
problem = f"BCD of Decimal Number ${n} = $"
return problem, f'${bcdstring}$'
decimal_to_bcd = Generator("Decimal to Binary Coded Decimal", 103,
gen_func, ["maxNumber=10000"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
def gen_func(max_dec=99):
a = random.randint(1, max_dec)
b = bin(a).replace("0b", "")
problem = f'Binary of ${a} = $'
solution = f'${b}$'
return problem, solution
decimal_to_binary = Generator("Decimal to Binary", 14, gen_func,
["max_dec=99"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
def gen_func(max_dec=1000):
a = random.randint(0, max_dec)
b = hex(a)
problem = f"Binary of ${a} = $"
solution = f"${b}$"
return problem, solution
decimal_to_hexadeci = Generator("Decimal to Hexadecimal", 79, gen_func,
["max_dec=1000"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxDecimal=4096):
x = random.randint(0, maxDecimal)
problem = "The decimal number ${x}$ in Octal is: "
solution = f'${oct(x)}$'
return problem, solution
decimal_to_octal = Generator("Converts decimal to octal", 84,
gen_func, ["maxDecimal=4096"])

View File

@@ -1,26 +0,0 @@
from ...generator import Generator
import random
def gen_func(minNo=1):
n = random.randint(minNo, 20)
def createFibList(n):
list = []
for i in range(n):
if i < 2:
list.append(i)
else:
val = list[i - 1] + list[i - 2]
list.append(val)
return list
fibList = createFibList(n)
problem = "The Fibonacci Series of the first ${n}$ numbers is ?"
solution = ', '.join(map(str, fibList))
return problem, f'${solution}$'
fibonacci_series = Generator("Fibonacci Series", 56, gen_func,
["minNo=1"])

View File

@@ -1,16 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxRes=99, maxModulo=99):
a = random.randint(0, maxModulo)
b = random.randint(0, min(maxRes, maxModulo))
c = a % b if b != 0 else 0
problem = f'${a}$ % ${b} = $'
solution = f'${c}$'
return problem, solution
modulo_division = Generator("Modulo Division", 5, gen_func,
["maxRes=99", "maxModulo=99"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxN=100):
gratio = (1 + math.sqrt(5)) / 2
n = random.randint(1, maxN)
problem = f"What is the {n}th Fibonacci number?"
solution = int((math.pow(gratio, n) - math.pow(-gratio, -n)) / (math.sqrt(5)))
return problem, f'${solution}$'
nth_fibonacci_number = Generator("nth Fibonacci number", 62,
gen_func, ["maxN=100"])

View File

@@ -1,34 +0,0 @@
from .angle_btw_vectors import angle_btw_vectors
from .angle_regular_polygon import angle_regular_polygon
from .arc_length import arc_length
from .area_of_circle import area_of_circle
from .area_of_circle_given_center_and_point import area_of_circle_given_center_and_point
from .area_of_triangle import area_of_triangle
from .basic_trigonometry import basic_trigonometry
from .circumference import circumference
from .complementary_and_supplementary_angle import complementary_and_supplementary_angle
from .curved_surface_area_cylinder import curved_surface_area_cylinder
from .degree_to_rad import degree_to_rad
from .equation_of_line_from_two_points import equation_of_line_from_two_points
from .fourth_angle_of_quadrilateral import fourth_angle_of_quadrilateral
from .perimeter_of_polygons import perimeter_of_polygons
from .pythagorean_theorem import pythagorean_theorem
from .radian_to_deg import radian_to_deg
from .sector_area import sector_area
from .sum_of_polygon_angles import sum_of_polygon_angles
from .surface_area_cone import surface_area_cone
from .surface_area_cube import surface_area_cube
from .surface_area_cuboid import surface_area_cuboid
from .surface_area_cylinder import surface_area_cylinder
from .surface_area_pyramid import surface_area_pyramid
from .surface_area_sphere import surface_area_sphere
from .third_angle_of_triangle import third_angle_of_triangle
from .valid_triangle import valid_triangle
from .volume_cone import volume_cone
from .volume_cube import volume_cube
from .volume_cuboid import volume_cuboid
from .volume_cylinder import volume_cylinder
from .volume_frustum import volume_frustum
from .volume_hemisphere import volume_hemisphere
from .volume_pyramid import volume_pyramid
from .volume_sphere import volume_sphere

View File

@@ -1,33 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxEltAmt=20):
s = 0
v1 = [
round(random.uniform(0, 1000), 2)
for i in range(random.randint(2, maxEltAmt))
]
v2 = [round(random.uniform(0, 1000), 2) for i in v1]
for i in range(len(v1)):
s += v1[i] * v2[i]
mags = math.sqrt(sum([i**2
for i in v1])) * math.sqrt(sum([i**2 for i in v2]))
solution = ''
ans = 0
try:
ans = round(math.acos(s / mags), 2)
solution = f"${ans}$ radians"
except ValueError:
print('angleBtwVectorsFunc has some issues with math module, line 16')
solution = 'NaN'
ans = 'NaN'
# would return the answer in radians
problem = f"angle between the vectors ${v1}$ and ${v2}$ is:"
return problem, solution
angle_btw_vectors = Generator("Angle between 2 vectors", 70,
gen_func, ["maxEltAmt=20"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
def gen_func(minVal=3, maxVal=20, format='string'):
sideNum = random.randint(minVal, maxVal)
problem = f"Find the angle of a regular polygon with ${sideNum}$ sides"
exteriorAngle = round((360 / sideNum), 2)
solution = f'${180 - exteriorAngle}$'
return problem, solution
angle_regular_polygon = Generator("Angle of a Regular Polygon", 29,
gen_func,
["minVal=3", "maxVal=20"])

View File

@@ -1,18 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxRadius=49, maxAngle=359):
radius = random.randint(1, maxRadius)
angle = random.randint(1, maxAngle)
angle_arc_length = float((angle / 360) * 2 * math.pi * radius)
formatted_float = "{:.5f}".format(angle_arc_length)
problem = f"Given radius, ${radius}$ and angle, ${angle}$. Find the arc length of the angle."
solution = f"Arc length of the angle $= {formatted_float}$"
return problem, solution
arc_length = Generator("Arc length of Angle", 108, gen_func,
["maxRadius=49", "maxAngle=359"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
from math import pi
def gen_func(maxRadius=100):
r = random.randint(0, maxRadius)
area = round(pi * r * r, 2)
problem = f'Area of circle with radius ${r}=$'
return problem, f'${area}$'
area_of_circle = Generator("Area of Circle", 112, gen_func,
["maxRadius=100"])

View File

@@ -1,23 +0,0 @@
from ...generator import Generator
import random
from math import cos, sin, pi
def gen_func(maxCoordinate=10, maxRadius=10):
r = random.randint(0, maxRadius)
center_x = random.randint(-maxCoordinate, maxCoordinate)
center_y = random.randint(-maxCoordinate, maxCoordinate)
angle = random.choice([0, pi // 6, pi // 2, pi, pi + pi // 6, 3 * pi // 2])
point_x = center_x + round(r * cos(angle), 2)
point_y = center_y + round(r * sin(angle), 2)
area = round(pi * r * r, 2)
problem = f"Area of circle with center $({center_x},{center_y})$ and passing through $({point_x}, {point_y})$ is"
return problem, f'${area}$'
area_of_circle_given_center_and_point = Generator("Area of Circle given center and a point on circle", 115, gen_func,
["maxCoordinate = 10", "maxRadius=10"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxA=20, maxB=20):
a = random.randint(1, maxA)
b = random.randint(1, maxB)
c = random.randint(abs(b - a) + 1, abs(a + b) - 1)
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c))**0.5
problem = f"Area of triangle with side lengths: ${a}, {b} {c} = $"
solution = f'${round(area, 2)}$'
return problem, solution
area_of_triangle = Generator("Area of Triangle", 18, gen_func,
["maxA=20", "maxB=20"])

View File

@@ -1,33 +0,0 @@
from ...generator import Generator
import random
import math
# Handles degrees in quadrant one
def gen_func(angles=[0, 30, 45, 60, 90],
functions=["sin", "cos", "tan"]):
angle = random.choice(angles)
function = random.choice(functions)
problem = f"$\\{function}({angle}) = $"
expression = 'math.' + function + '(math.radians(angle))'
result_fraction_map = {
0.0: "0",
0.5: "\\frac{1}{2}",
0.71: "\\frac{1}{\\sqrt{2}}",
0.87: "\\frac{\\sqrt{3}}{2}",
1.0: "1",
0.58: "\\frac{1}{\\sqrt{3}}",
1.73: "\\sqrt{3}",
}
solution = result_fraction_map[round(eval(expression), 2)] if round(
eval(expression), 2) <= 99999 else "\\infty" # for handling the ∞ condition
return problem, f'${solution}$'
basic_trigonometry = Generator(
"Trigonometric Values", 57, gen_func,
["angles=[0, 30, 45, 60, 90]", "functions=['sin', 'cos', 'tan']"])

View File

@@ -1,15 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxRadius=100):
r = random.randint(0, maxRadius)
circumference = round(2 * math.pi * r, 2)
problem = f"Circumference of circle with radius ${r} = $"
return problem, f'${circumference}$'
circumference = Generator("Circumference", 104, gen_func,
["maxRadius=100"])

View File

@@ -1,26 +0,0 @@
from ...generator import Generator
import random
def gen_func(maxSupp=180, maxComp=90, format='string'):
angleType = random.choice(["supplementary", "complementary"])
if angleType == "supplementary":
angle = random.randint(1, maxSupp)
angleAns = 180 - angle
else:
angle = random.randint(1, maxComp)
angleAns = 90 - angle
if format == 'string':
problem = f"The {angleType} angle of {angle} ="
solution = angleAns
return problem, solution
elif format == 'latex':
return "Latex unavailable"
else:
return angleType, angle, angleAns
complementary_and_supplementary_angle = Generator("Complementary and Supplementary Angle", 125,
gen_func, ["maxSupp=180", "maxComp=90"])

View File

@@ -1,19 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxRadius=49, maxHeight=99):
r = random.randint(1, maxRadius)
h = random.randint(1, maxHeight)
csa = float(2 * math.pi * r * h)
formatted_float = round(csa, 2) # "{:.5f}".format(csa)
problem = f"What is the curved surface area of a cylinder of radius, ${r}$ and height, ${h}$?"
solution = f"${formatted_float}$"
return problem, solution
curved_surface_area_cylinder = Generator("Curved surface area of a cylinder",
95, gen_func,
["maxRadius=49", "maxHeight=99"])

View File

@@ -1,17 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(max_deg=360):
a = random.randint(0, max_deg)
b = (math.pi * a) / 180
b = round(b, 2)
problem = f"Angle ${a}$ degrees in radians is: "
solution = f'${b}$'
return problem, solution
degree_to_rad = Generator("Degrees to Radians", 86, gen_func,
["max_deg=360"])

View File

@@ -1,62 +0,0 @@
from ...generator import Generator
import random
import math
def gen_func(maxCoordinate=20, minCoordinate=-20):
x1 = random.randint(minCoordinate, maxCoordinate)
x2 = random.randint(minCoordinate, maxCoordinate)
y1 = random.randint(minCoordinate, maxCoordinate)
y2 = random.randint(minCoordinate, maxCoordinate)
coeff_y = (x2 - x1)
coeff_x = (y2 - y1)
constant = y2 * coeff_y - x2 * coeff_x
gcd = math.gcd(abs(coeff_x), abs(coeff_y))
if gcd != 1:
if coeff_y > 0:
coeff_y //= gcd
if coeff_x > 0:
coeff_x //= gcd
if constant > 0:
constant //= gcd
if coeff_y < 0:
coeff_y = -(-coeff_y // gcd)
if coeff_x < 0:
coeff_x = -(-coeff_x // gcd)
if constant < 0:
constant = -(-constant // gcd)
if coeff_y < 0:
coeff_y = -(coeff_y)
coeff_x = -(coeff_x)
constant = -(constant)
if coeff_x in [1, -1]:
if coeff_x == 1:
coeff_x = ''
else:
coeff_x = '-'
if coeff_y in [1, -1]:
if coeff_y == 1:
coeff_y = ''
else:
coeff_y = '-'
problem = f"What is the equation of the line between points $({x1},{y1})$ and $({x2},{y2})$ in slope-intercept form?"
if coeff_x == 0:
solution = str(coeff_y) + "y = " + str(constant)
elif coeff_y == 0:
solution = str(coeff_x) + "x = " + str(-constant)
else:
if constant > 0:
solution = str(coeff_y) + "y = " + str(coeff_x) + "x + " + str(constant)
else:
solution = str(coeff_y) + "y = " + str(coeff_x) + "x " + str(constant)
return problem, f'${solution}$'
equation_of_line_from_two_points = Generator(
"Equation of line from two points", 114, gen_func,
["maxCoordinate=20", "minCoordinate=-20"])

Some files were not shown because too many files have changed in this diff Show More