Skip to content

Advance python Math Library which performs all the basic and scientific math operations such as cos, sin, tan etc. It also includes basic statistical functions such as mean, median, mode, standard deviation etc

License

Notifications You must be signed in to change notification settings

roshaan55/pythmath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 

Repository files navigation

pythmath 0.2

Advance Math Library which performs all the basic and scientific math operations such as cos, sin, tan etc. New functions included in pythmath 0.2 such as basic statistical functions(Mean, Median, Mode, Standard Deviation, Mean Absolute Deviation(MAD), Variance etc...), error functions(Percentage Error, Absolute Error, Relatable Error)

It is an advanced revised version of built-in math library which helps to perform math operations. It includes the area functions which calculates the area of square, area of triangle, area of circle and area of rectangle. pythmath 0.1 includes functions which are as follows:

New upadate pythmath 0.2 includes new functions such as statistical functions(mean, median, mode, variance) etc and other maths functions. New updates includes error functions such as percentage error, absolute error and relatable error.

New math functions and statistic functions added in recent revised version of pthmath 0.2 version pythmath 0.2.1 which are nth Root, Harmonic Mean, Geometric Mean, Median Absolute Deviation, Multiply a list, Covariance, List Prime Factors, List of Prime Numbers, List of Odd Numbers, List of Even Numbers.

New functions added in new update pythmath 0.2.2 which are Quadratic Equation, List of factors of a numbers, Angle Formula, Arc Lengnth(Radians), Arc Length(Degrees) and Average Rate of Change.

pythmath 0.2.3: New gemoetric functions added and it also includes line functions Slope, Distance of Line, Equation of Line, Midpoint and Y Intercept

pythmath 0.2.5: New updated version includes sales functions such as discount, gst_amount, gross_sales, net_sales, sales_tax, vat, revenue, profit, markup, commission and margin which may help you in calculating sales.

Installation:

pip install pythmath

For Upgradation(pythmath):

pip install --upgrade pythmath

Sales Functions:

  1. Discount
  2. GST Amount
  3. Gross Sales
  4. Net Sales
  5. Sales Tax
  6. VAT(Value Added Tax)
  7. Profit
  8. Markup
  9. Commission
  10. Margin

New Geometric Functions:

  1. Volume of Cone
  2. Surface Area of Cube
  3. Volume of cube
  4. Surface Area of Cuboid
  5. Volume of cuboid
  6. Perimeter of Square
  7. Surface Area of Sphere
  8. Volume of Sphere
  9. Perimeter of Parallelogram
  10. Area of Parallelogram
  11. Circumference of Circle
  12. Surface Area of Cylinder
  13. Volume of Cylinder
  14. Area of Trapezoid
  15. Perimeter of Right angle Triangle
  16. Perimeter of Triangle

Line Functions:

  1. Slope
  2. Distance of Line
  3. Equation of Line
  4. Midpoint
  5. Y Intercept

New Functions:

  1. Quadratic Equation
  2. List of Factors of a Number
  3. Angle Formula
  4. Arc Length(Radians)
  5. Arc Length(Degrees)
  6. Average Rate of Change

Fractions:

  1. Fraction
  2. Fraction Addition
  3. Fraction Subtraction
  4. Fraction Multiplication
  5. Fraction Division

New Math Functions:

  1. nth Root
  2. Multiply a list
  3. List of Prime Factors
  4. List of Prime Numbers
  5. List of Odd Numbers
  6. List of Even Numbers

New Statistics Functions:

  1. Harmonic Mean
  2. Geometric Mean
  3. Median Absolute Deviation
  4. Covariance

Basic Math Functions:

  1. Absolute Function
  2. Square Root Function
  3. Cube Root Function
  4. LCM Function
  5. GCD Function
  6. Factorial Function
  7. Integer Square Root Function
  8. Integer Cube Root Function
  9. Hypotenuse Function
  10. Floor Function
  11. Ceil Function
  12. Float Sum Function
  13. Float Absolute Function
  14. Remainder Function
  15. Euclidean Distance Function
  16. Exponential Function
  17. Is Even Function
  18. Is Integer Function
  19. Is Odd Function
  20. Is Prime Function
  21. Is Positive Function
  22. Is Negative Function
  23. Is Zero Function
  24. Is Sorted
  25. Percentage
  26. Array Sum
  27. Array 2d Sum
  28. nCr
  29. nPr
  30. Fibonacci Series Function
  31. Multiply Two List
  32. Square of List
  33. Powerd List
  34. Sort List
  35. Count List
  36. Minimum in List
  37. Maximum in List
  38. Is Float
  39. Positive or Negative

Geometric Functions

  1. Area of Rectangle Function
  2. Area of Triangle Function
  3. Area of Square Function
  4. Area of Circle Function
  5. Perimeter of Rectangle Function

Trignometric Functions:

  1. Degrees to Radians Function
  2. Radians to Degrees Function
  3. Sin(x) Function
  4. Sinh(x) Function
  5. Sind(x) Function
  6. Cos(x) Function
  7. Cosd(x) Function
  8. Cosh(x) Function
  9. Cosec(x) Function
  10. Cosecd(x) Function
  11. Cot(x) Function
  12. Cotd(x) Function
  13. Sec(x) Function
  14. Secd(x) Function
  15. Tan(x) Function
  16. Tand(x) Function
  17. Tanh(x) Function

Statistical Functions

  1. Mean
  2. Median
  3. Mode
  4. Standard Deviation
  5. Population Standard Deviation
  6. Mean Absolute Deviation(MAD)
  7. Variance
  8. Z Score
  9. Standard Error
  10. Sampling Error
  11. Statistical Range
  12. Mid Range

Error Functions:

  1. Percentage Error
  2. Absolute Error
  3. Relatable Error

Sales Functions:

Discount:

It is a function that calculates the discounted amount from given percent.

Example:

from pythmath.sales import discount

price = 3500
off = 10
tax = 6

# with tax=True
tax_pr, saved_amount = discount(price, off, tax_perc=tax, tax=True)
print(f"Price: Rs {price}")
print(f"Discount: {off}%")
print(f"Sales Tax: {tax}%")
print(f"Total: Rs {tax_pr}")
print(f"You're saving: Rs {saved_amount}")

Output with tax=True:

Price: Rs 3500 Discount: 10% Sales Tax: 6% Total: Rs 3339.0 You're saving: Rs 371.0

from pythmath.sales import discount

price = 3500
off = 10
tax = 6

# With Tax=False, by default it's false
dis, dis_price = discount(price, off)
print(f"Price: Rs {price}")
print(f"Discount: {off}%")
print(f"Total: Rs {dis_price}")
print(f"You're saving: Rs {dis}")

Output:

Price: Rs 3500 Discount: 10% Total: Rs 3150.0 You're saving: Rs 350.0

GST Amount:

It is a function that Helps you find out either net or gross price of your product based on a percentage-based GST (Goods and Services Tax) rate.

Example:

from pythmath.sales import gst_amount

price = 3500
off = 10
tax = 6

tax_amount = gst_amount(price, tax)
print(f"Price: Rs {price}")
print(f'Discount: {dis}')
print(f"Discounted Price: {dis_price}")
print(f"Amount inclusive tax: {tax_amount}")

Output: Price: Rs 3500 Discount: 350.0 Discounted Price: 3150.0 Amount inclusive tax: 3710.0

Gross Sales:

It is a fuction that calculates the gross sales.

Example:

from pythmath.sales import gross_sales

price = 3500
number_products_sale = 100

gro_sales = gross_sales(price, number_products_sale)
# Gross Sales
print(f"Price: Rs {price}")
print(f"Number of products sale: {number_products_sale}")
print(f"Gross Sales: Rs {gro_sales}")

Output: Price: Rs 3500 Number of products sale: 100 Gross Sales: Rs 350000

Net Sales:

It is a fuction that calculates the net sales.

Example:

from pythmath.sales import net_sales

price = 3500
number_products_sale = 100
allowances = 200

net_sales = net_sales(gro_sales, allowances=allowances)
print(f"Allowances: Rs {allowances}")
print(f"Net Sales: Rs {net_sales}")

Output: Allowances: Rs 200 Net Sales: Rs 349800

Sales Tax:

It is a fuction that calculates the sales tax.

Example:

from pythmath.sales import sales_tax

price = 3500
tax = 4

tax_amnt, tax_pr = sales_tax(price, tax)

print(f"Price: Rs {price}")
print(f"Tax: {tax}%")
print(f"Gross Price: Rs {tax_pr}")
print(f"Tax Amount: Rs {tax_amnt}")

Output: Price: Rs 3500 Tax: 4% Gross Price: Rs 3640.0 Tax Amount: Rs 140.0

VAT(Value Added Tax):

It is a fuction that calculates the value added tax.

Example:

from pythmath.sales import vat

price = 3500
tax = 4

vat_amnt, vat_pr = vat(price, tax)

print(f"Price: Rs {price}")
print(f"Tax: {tax}%")
print(f"Gross Price: Rs {vat_pr}")
print(f"Tax Amount: Rs {vat_amnt}")

Output: Price: Rs 3500 Tax: 4% Gross Price: Rs 3640.0 Tax Amount: Rs 140.0

Profit:

It is a fuction that calculates the profit.

Example:

from pythmath.sales import profit

cost = 40
rev_val = 50

profit = profit(rev_val, cost)

print(f"Cost: {cost}")
print(f"Revenue Value: {rev_val}")
print(f"Profit Value: {prof_val}")

Output: Cost: 40 Revenue Value: 50 Profit Value: 10

Markup:

It is a fuction that calculates the markup percentage.

Example:

from pythmath.sales import markup

cost = 40
rev_val = 50

markup = markup(cost, prof_val)

print(f"Cost: {cost}")
print(f"Markup: {mark_val}%")
print(f"Revenue: {rev_val}")
print(f"Profit: {prof_val}")

Output: Cost: 40 Markup: 25.0% Revenue: 50 Profit: 10

Commission:

It is a fuction that calculates the commission.

Example:

from pythmath.sales import commission

cost = 40
commission_percent = 10

commission = commission(cost, 10)

print(f"Cost: {cost}")
print(f"Commission Percentage: {commission_percent}%")
print(f"Commission: {commission}")

Output: Cost: 40 Commission Percentage: 10% Commission: 4.0

Margin:

It is a fuction that calculates the margin from revenue and cost.

Example:

from pythmath.sales import margin

cost = 40
rev_val = 50

margin_val = margin(rev_val, cost)

print(f"Cost: {cost}")
print(f"Revenue: {rev_val}")
print(f"Margin: {margin_val}")
print(f"Profit: {prof_val}")

Output: Cost: 40 Revenue: 50 Margin: 20.0 Profit: 10

New Geometric Functions:

Volume of Cone:

It is a function that calculates the volume of a cone from values of radius and height.

Example:

from pythmath.geometry import *

r = 12
h = 5

print(volume_cone(r, h))

Output: 753.9822368615504

Surface Area of Cube:

It is a function that calculates the surface area of a cube.

Example:

from pythmath.geometry import *

a = 12

print(surf_area_cube(a))

Output: 864

Volume of Cube:

It is a function that calculates the volume of a cube.

Example:

from pythmath.geometry import *

a = 12

print(volume_cube(a))

Output: 1728

Surface Area of Cuboid:

It is a function that calculates the surface area of a cuboid from values of length, base and height.

Example:

from pythmath.geometry import *

l = 5
b = 6
h = 7

print(surf_area_cuboid(l, b, h))

Output: 214

Volume of Cuboid:

It is a function that calculates the volume of a cuboid from values of length, base and height.

Example:

from pythmath.geometry import *

l = 4
b = 5
h = 6

print(volume_cuboid(l, b, h))

Output: 120

Perimeter of Square:

It is a function that calculates the perimeter of square from a side of square.

Example:

fromt pythmath.geometry import *

a = 12

print(perimeter_square(a))

Output: 48

Surface Area of Sphere:

It is a function that calculates the surface area of sphere from value of radius.

Example:

from pythmath.geometry import *

r = 12

print(surf_area_sphere(r))

Output: 1809.5573684677208

Volume of Sphere:

It is a function that calculates volume of a sphere from value of radius.

Example:

import pythmath.geometry import *

r = 12

print(volume_sphere(r))

Output: 7238.229473870882

Perimeter of Parallelogram:

It is a function that calculates the perimeter of a parallelogram.

Example:

from pythmath.geometry import *

a = 12
b = 14

print(perimeter_parallelo(a, b))

Output: 52

Area of Parallelogram:

It is a function that calculates the area of a parallelogram.

Example:

from pythmath.geometry import *

b = 12
h = 14

print(area_parallelo(b, h))

Output: 168

Circumference of Circle:

It is a function that calculates the circumference of a circle from given radius.

Example:

from pythmath.geometry import *

r = 12

print(circle_circum(r))

Output: 75.39822368615503

Surface Area of Cylinder:

It is a function that calculates the surface area of a cylinder from values of radius and height.

Example:

from pythmath.geometry import *

r = 10
h = 12

print(surf_area_cylinder(r, h))

Output: 1382.300767579509

Volume of Cylinder:

It is a function that calculates the volume of a cylinder from values of radius and height.

Example:

from pythmath.geometry import *

r = 10
h = 12

print(volume_cylinder(r, h))

Output: 3769.9111843077517

Area of Trapezoid:

It is a function that calculates the area of trapezoid.

Example:

from pythmath.geometry import *

a = 4
b = 5
h = 10

print(area_trapezoid(a, b, h))

Output: 45.0

Perimeter of Right Angle Triangle:

It is a function that calculates the perimeter of a right angle triangle.

Example:

from pythmath.geometry import *

a = 3
b = 4

print(p_right_triangle(a, b))

Output: 12.0

Perimeter of Triangle:

It is a function that calculates the perimeter of a triangle.

Example:

from pythmath.geometry import *

a = 12
b = 13
c = 14

print(perimeter_triangle(12, 13, 14))

Output: 39

Line Functions:

Slope:

It is a function that calculates the slope of a line from x and y coordinates.

Slope of Line: The slope of a line is defined as the change in y coordinate with respect to the change in xcoordinate of that line. The net change in y coordinate is Δy, while the net change in the x coordinate is Δx.

Example:

from pythmath.lines import *

x = [4, 8]  # x1, x2
y = [5, 10]  # y1, y2

print(slope(x, y))

Output: 1.25

Distance of Line:

It is a function that calculates the distance from a point to a line from x and y coordinates.

Distance of Line: In Euclidean geometry, the distance from a point to a line is the shortest distance from a given point to any point on an infinite straight line. It is the perpendicular distance of the point to the line, the length of the line segment which joins the point to nearest point on the line.

Example:

from pythmath.lines import *

x = [4, 8]  # x1, x2
y = [5, 10]  # y1, y2

print(line_dist(x, y))

Output: 6.4031242374328485

Equation of Line:

It is a function that makes the equation of line from x and y coordinates.

Formula: y = mx + c

Equation of Line: The general equation of a straight line is y = mx + c, where m is the slope of the line and c is the y-intercept. It is the most common form of the equation of a straight line that is used in geometry. The equation of a straight line can be written in different forms such as point-slope form, slope-intercept form, general form, standard form, etc. A straight line is a two-dimensional geometrical entity that extends on both its ends till infinity.

Example:

from pythmath.lines import *

x = [4, 8]  # x1, x2
y = [5, 10]  # y1, y2

print(line_eqn(x, y))

Output: y = 1.25x + 0.0

Midpoint:

It is a function that calculates the midpoint or middle point of a line from x and y coordinates.

Midpoint: In geometry, the midpoint is the middle point of a line segment. It is equidistant from both endpoints, and it is the centroid both of the segment and of the endpoints. It bisects the segment.

Example:

from pythmath.lines import *

x = [4, 8]  # x1, x2
y = [5, 10]  # y1, y2

print(midpoint(x, y))

Output: (6.0, 7.5)

Y Intercept:

It is a function that gets the y intercept from x and y coordinates.

Y Intercept: The y-intercept is the point where the graph intersects the y-axis. To graph, any function that is of the form y = f(x) finding the intercepts is really important. There are two types of intercepts that a function can have. They are the x-intercept and the y-intercept. An intercept of a function is a point where the graph of the function cuts the axis.

Example:

from pythmath.lines import *

x = [4, 8]  # x1, x2
y = [5, 10]  # y1, y2

print(y_intercept(x, y))

Output: 0.0

New Functions:

Quadratic Equation:

It is a function that solves the quadratic equation and gets the roots of a quadratic equation.

Quadratic Equation: In algebra, a quadratic equation is any equation that can be rearranged in standard form as where x represents an unknown, and a, b, and c represent known numbers, where a ≠ 0. If a = 0, then the equation is linear, not quadratic, as there is no ax^2 term.

Example:

import pythmath

# One Double Root
a = 1
b = 4
c = 4

# Two Distinct Real Roots
a1 = 1.5
b1 = -2
c1 = -8.6

# Two Complex roots
a2 = -1
b2 = -1
c2 = -1

print(pythmath.quad_eqn(a, b, c))
print(pythmath.quad_eqn(a1, b1, c1))
print(pythmath.quad_eqn(a2, b2, c2))

Output: The function has one double root: -2.0

Output: The function has two distinct real roots: 7.092405564692173 and -4.092405564692174

Output: The function has two complex (conjugate) roots: (-0.5-0.8660254037844386j) and (-0.5+0.8660254037844386j)

List of Factors of a Number:

It is a function that factorise a number 'x' and returns the list of factors of 'x'.

Example:

import pythmath

num = 100

print(pythmath.num_factors(num))

Output: [1, 2, 4, 5, 10, 20, 25, 50, 100]

Angle Formula:

It is a function that calculates the angle from arc length and radius, it basically uses central angle formula.

Arc Length: Arc length is the distance between two points along a section of a curve. Determining the length of an irregular arc segment by approximating the arc segment as connected line segments is also called rectification of a curve.

Example:

from pythmath.geometry import *
from pythmath import pi


arc_len = 5 * pi
radius = 6

print(angle(arc_len, radius))

Output: 150

Arc Length(Radians):

It is a function that calculates the arc length from angle (in radians) and radius.

Arc Length: Arc length is the distance between two points along a section of a curve. Determining the length of an irregular arc segment by approximating the arc segment as connected line segments is also called rectification of a curve.

Example:

from pythmath.geometry import *

angle = 0.698132
radius = 8

print(arc_length(angle, radius))

Output: 5.585056

Arc Length(Degrees):

It is a function that calculates the arc length from angle (in degrees) and radius.

Arc Length: Arc length is the distance between two points along a section of a curve. Determining the length of an irregular arc segment by approximating the arc segment as connected line segments is also called rectification of a curve.

Example:

from pythmath.geometry import *

angle = 40
radius = 8

print(arc_length_deg(angle, radius))

Output: 5.585053606381854

Average Rate of Change:

It is a function that calculates the average rate of change from f(a) and f(b) calculated from a general function f(x).

Average Rate of Change: The Average Rate of Change function is defined as the average rate at which one quantity is changing with respect to something else changing. In simple terms, an average rate of change function is a process that calculates the amount of change in one item divided by the corresponding amount of change in another.

Example:

import pythmath

def f(x):
    return 3 * x - 12

a = 5
b = 8
funct_a = f(a)
funct_b = f(b)

print(pythmath.avg_rate_change(funct_a, funct_b, a, b))

Output: 3.0

Fractions:

Fraction:

It is a Class that takes numerator and denominator as input and returns proper fraction or improper fraction or a simplified fraction.

Proper Fraction: A fraction where the numerator is less than the denominator, then it is known as a proper fraction.

Improper Fraction: A fraction where the numerator is greater than the denominator, then it is known as an improper fraction.

Example:

from pythmath.fractions import Fraction

numer = 25
denom = 100

print(Fraction(numer, denom))

Output: 1/4

Fraction to Float: It takes fraction string as a parameter and returns fraction value to float.

Example:

from pythmath.fractions import Fraction

print(Fraction.frac_to_float("1/4"))
print(Fraction.frac_to_float("1 1/4"))

Output: 0.25

Output: 1.25

Float to Fraction: It takes float value as a parameter and returns float value to fraction.

Example:

from pythmath.fractions import Fraction

print(Fraction.float_to_frac(0.25))

Output: 1/4

Fraction Addition:

Example:

from pythmath.fractions import Fraction

print(Fraction(1, 4) + Fraction(1, 4))

Output: 1/2

Fraction Subtraction:

Example:

from pythmath.fractions import Fraction

print(Fraction(1, 2) - Fraction(1, 3))

Output: 1/6

Fraction Multiplication:

Example:

from pythmath.fractions import Fraction

print(Fraction(1, 2) * Fraction(1, 3))

Output: 1/6

Fraction Division:

Example:

from pythmath.fractions import Fraction

print(Fraction(1, 2) / Fraction(1, 3))

Output: 3/2

New Math Functions:

nth Root:

It is a function that calculates the n under root or root of nth number.

Example:

import pythmath

num = 81
n = 4

print(pythmath.nth_root(num, n))

Output: 3.0

Multiply a List:

It is a function that multiplies numbers of a list.

Example:

import pythmath

list1 = [1, 2, 3]
list2 = [3, 2, 4]

print(pythmath.multiply_lst(list1))
print(pythmath.multiply_lst(list2))

Output of list1: 6

Output of list2: 24

List of Prime Factors:

It is a function that gets the prime factors of a number, if a number is 100 it will get [2, 2, 5, 5].

Prime Factors: prime factor is finding which prime numbers multiply together to make the original number.

Example:

import pythmath

num = 100

print(pythmath.prime_factors(num))

Output: [2, 2, 5, 5]

List of Prime Numbers:

It is a function that generates a list of prime numbers from starting range to ending range.

Example:

import pythmath

start = 1
end = 20

print(pythmath.prime_numbers(start, end))

Output: [1, 2, 3, 5, 7, 11, 13, 17, 19]

List of Even Numbers:

It is a function that generates a list of even numbers from starting range to ending range.

Example:

import pythmath

start = 1
end = 20

print(pythmath.even_numbers(start, end))

Output: [1, 2, 4, 6, 8, 10, 12, 14, 16, 18]

List of Odd Numbers:

It is a function that generates a list of odd numbers from starting range to ending range.

Example:

import pythmath

start = 1
end = 20

print(pythmath.odd_numbers(start, end))

Output: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]

New Statistics Functions:

Harmonic Mean:

It is a function that calculates the harmonic mean from given dataset, list of numbers or tuple of numbers.

Harmonic Mean: In mathematics, the harmonic mean is one of several kinds of average, and in particular, one of the Pythagorean means. It is sometimes appropriate for situations when the average rate is desired.

Example:

from pythmath.statistics import *

data = [6, 7, 3, 9, 10, 15]

print(harmonic_mean(data))

Output: 6.517241379310345

Geometric Mean:

It is a function that calculates the geometric mean from given dataset, list of numbers or tuple of numbers.

Geometric Mean: In statistics, the geometric mean is calculated by raising the product of a series of numbers to the inverse of the total length of the series. The geometric mean is most useful when numbers in the series are not independent of each other or if numbers tend to make large fluctuations.

Example:

from pythmath.statistics import *

data = [1, 2, 3, 4, 5]

print(geometric_mean(data))

Output: 2.605171084697352

Median Absolute Deviation:

It is a function that calculates the median absolute deviation from a given dataset, list of numbers or tuple of numbers.

Median Absolute Deviation: In statistics, the median absolute deviation is a robust measure of the variability of a univariate sample of quantitative data. It can also refer to the population parameter that is estimated by the MAD calculated from a sample.

Example:

from pythmath.statistics import *

data = [1, 2, 3, 4, 5]

print(median_abs_dev([1, 2, 3, 4, 5]))

Output: 1.0

Covariance:

It is a function that calculates the covariance from two datasets or lists of numbers x and y. It takes three parameters: x: values of dataset x, y: values of dataset y and cov_mode: mode of covariance either sample(samp) or population(pop), by default it is sample

Covariance: In probability theory and statistics, covariance is a measure of the joint variability of two random variables. If the greater values of one variable mainly correspond with the greater values of the other variable, and the same holds for the lesser values, the covariance is positive.

Example:

With cov_mode=samp

from pythmath.statistics import *

x = [1, 2, 3, 4]
y = [5, 6, 7, 8]

print(covariance(x, y, cov_mode="samp"))

Output: 1.6666666666666667

With cov_mode=pop

import pythmath

x = [1, 2, 3, 4]
y = [5, 6, 7, 8]

print(covariance(x, y, cov_mode="pop"))

Output: 1.25

Basic Math Function Implementation:

Absolute Function:

It is the function that gets the absolute value of x, if negative value it will be positive value.

Example:

import pythmath

num = -7

print(pythmath.absolute(num))

Output: 7

Square Root Function:

It is a function that finds the square root of any number.

Example:

import pythmath

num = 25

print(pythmath.square_root(num))

Output: 5

Cube Root Function:

It is a function that finds the cube root of a number.

Example:

import pythmath

num = 27

print(pythmath.cube_root(num))

Output: 3

LCM Function:

It is a function that calculates the least common multiple of two numbers

Example:

import pythmath

a = 10
b = 18

print(pythmath.lcm(a, b))

Output: 90.0

GCD Function:

It is a function that calculates the greatest common divisor of two numbers.

Example

import pythmath

a = 20
b = 18

print(pythmath.gcd(a, b))

Output: 2.0

Factorial Function:

It is a function that calculates the factorial of number.

Example:

import pythmath

num = 4

print(pythmath.fact(num))

Output: 24.0

Integer Square Root Function:

It is a function to get the integer part of square root of a number.

Examples:

import pythmath

a = 20

print(pythmath.intsqrt(a))

Output: 4

Integer Cube Root Function:

It is a function to get the integer part of cube root of a number

Example

import pythmath

a = 20

print(pythmath.intcbrt(a))

Output: 2

Hypotenuse Function:

It is function that calculates the hypotenuse of two numbers.

Example:

import pythmath

a = 3
b = 4

print(pythmath.hypotenuse(a, b))

Output: 5.0

Floor Function:

It is the function that gets the exact floored value, for example the number is 3.4 it will get 3

Example:

import pythmath

a = 3.7

print(pythmath.floor(a))

Output: 3

Ceil Function

It is function that ceil the number.

Example:

import pythmath

a = 3.7

print(pythmath.ceil(a))

Output: 4

Is Sorted:

It is the function to check whether the list is sorted or not, if a list is sorted it will return True otherwise False.

Example:

import pythmath

lst1 = [2, 8, 15, 3, 5]
lst2 = [1, 2, 3, 4, 5]

print(pythmath.is_sorted(lst1))
print(pythmath.is_sorted(lst2))

Output 1: False

Output 2: True

Percentage:

It is a function to calculate percentage

Example:

import pythmath

print(pythmath.percentage(20, 50))

Output: 40.0

Array Sum:

It is a function that calculates the sum of numbers in a 1d Array.

Example:

import pythmath

array = {12, 3, 4, 15}

print(pythmath.arr_sum(array))

Output: 34

Array 2d Sum:

It is a function to calculates the sum of numbers in a 2d Array.

Example:

import pythmath

array_2d = [[1, 2],
            [3, 4],
            [5, 6]
            ]

print(pythmath.arr_2d_sum(array_2d))

Output: 21

nCr:

It is a function that calculates the Combinations nCr from n a r values.

Example:

import pythmath

n = 10
r = 5

print(pythmath.nCr(n, r))

Output: 252.0

nPr:

It is a function that calculates Permutations nPr from n and r values.

Example:

import pythmath

n = 5
r = 2

print(pythmath.nCr(n, r))

Output: 20.0

Fibonacci Series:

It is a function that generates the fibonacci series from n_terms. It takes three parameters first, second and n_terms. n_terms: Number of terms to generate fibonacci series, by default its value is 5 and it is optional. If you leave it by default it generates fibonacci series to 5 terms.

Example:

import pythmath

print(pythmath.fibonacci(0, 2))

Output: [0, 2, 2, 4, 6]

Multiply Two List:

It is a function that multiplies each number in two list List 1 and List 2 and returns a new multiplied list of these numbers.

Example:

import pythmath

x = [1, 2, 3, 4]
y = [5, 2, 4, 1]

print(pythmath.mult_two_lst(x, y))

Output: [5, 4, 12, 4]

Square of Two List:

It is a function that squares each number in a list and returns a new squared list of these numbers.

Example:

import pythmath

x = [1, 2, 3, 4]

print(pythmath.square_lst(x))

Output: [1, 4, 9, 16]

Powered List:

It is a function that calculates the power of each number in a list and returns a new powered list of these numbers. It takes two parameters: lst: List and pow_val pow_val: Value of power to calculate the power of each number in a list, it is optional and by default its value is 2.

Example:

import pythmath

x = [1, 2, 3, 4]

print(pythmath.pow_lst(x, 3))

Output: [1, 8, 27, 64]

Sort List:

It is function that sorts the elements in a list in ascending order. If the list is sorted it will print the message: The list is already sorted!

Example:

import pythmath

my_list = [5, 10, 4, 3, 2, 17]
lst = [1, 2, 3, 4, 5]

print(pythmath.sort(my_list))
print(pythmath.sort(lst))

Output of my_list: [2, 3, 4, 5, 10, 17]

Output of lst: The list is already sorted!

Count List:

It is a function that counts how many numbers in a list.

Example:

import pythmath

results = [1, 2, 3, 4, 5]

print(pythmath.count(results))

Output: 5

Minimum in List:

It is a function that finds the minimum value in a list.

Example:

import pythmath

lst = [1, 2, 3, 4, 5]

print(pythmath.minimum(lst))

Output: 1

Maximum in a List:

It is a function that finds the maximum value in a list.

Example:

import pythmath

lst = [1, 2, 3, 4, 5]

print(pythmath.maximum(lst))

Output: 5

Is Float:

It is a function that checks whether the number is float or not and returns True if the number is float otherwise False.

import pythmath

num1 = 7.5
num2 = 7

print(pythmath.isfloat(num1))
print(pythmath.isfloat(num2))

Output of num1: True Output of num2: False

Positive or Negative Number:

It is a function that returns the positive number if the inputted number is negative and returns negative number if the inputted number is positive.

import pythmath

num1 = -7
num2 = 7
num3 = 7.5
num4 = -7.5

print(pythmath.pos_neg(num1))
print(pythmath.pos_neg(num2))
print(pythmath.pos_neg(num3))
print(pythmath.pos_neg(num4))

Output of num1: 7

Output of num2: -7

Output of num3: -7.5

Output of num4: 7.5

For more basic math functions see Examples/Basic Math Functions.

Gemoetric Functions:

Area of Rectangle Function:

It is a function that calculates the area of rectangle.

Example:

import pythmath

x = 5
y = 6

print(pythmath.area_rect(x, y))

Output: 30.0

Perimeter of Rectangle Function:

It is a function to calculate the perimeter of rectangle.

Example:

import pythmath

x = 5
y = 6

print(pythmath.perimeter_rect(x, y))

Output: 22.0

Area of Triangle Function:

It is a function that calculates the area of triangle.

Example:

import pythmath

a = 5
b = 6
c = 7

print(pythmath.area_triangle(a, b, c))

Output: 14.696938456699069

Area of Square Function:

It is a function that calculates the area of square.

Example:

import pythmath

x = 5

print(pythmath.area_square(x))

Output: 25.0

Area of Circle Function:

It is a function to calculate the area of circle.

Example:

import pythmath

radius = 5

print(pythmath.area_circle(radius))

Output: 78.53981633974483

Trignometric Functions:

Sin(x) Function:

It is function to calculate sine of x or any number in radians.

Example:

import pythmath

angle = 25

print(pythmath.sin(angle))

Output: -0.13235175009777303

Sind(x) Function:

It is a function to calculate sine of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.sind(angle))

Output: 0.42261826174069944

Sinh(x) Function:

It is a function to calculate hyperbolic sine of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.sinh(angle))

Output: 36002449668.69289

Cos(x) Function:

It is a function to calculate cosine of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.cos(angle))

Output: 0.9912028118634736

Cosd(x) Function:

It is a function to calculate cosine of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.cosd(angle))

Output: 0.9063077870366499

Cosh(x) Function:

It is a function to calculate hyperbolic cosine of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.cosh(angle))

Output: 36002449668.69289

Cosec(x) Function:

It is a function to calculate cosec of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.cosec(angle))

Output: -7.555623550585948

Cosecd(x) Function:

It is a function to calculate cosec of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.cosecd(angle))

Output: 2.3662015831524985

Cot(x) Function:

It is a function to calculate cotangent of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.cot(angle))

Output: -7.489155308722674

Cotd(x) Function:

It is a function to calculate cotangent of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.cotd(angle))

Output: 2.1445069205095586

Sec(x) Function:

It is a function to calculate secant of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.sec(angle))

Output: 1.0088752655170414

Secd(x) Function:

It is a function to calculate secant of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.secd(angle))

Output: 1.1033779189624917

Tan(x) Function:

It is a function to calculate tangent of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.tan(angle))

Output: -0.13352640702153587

Tand(x) Function:

It is a function to calculate tangent of a number in degrees.

Example:

import pythmath

angle = 25

print(pythmath.tand(angle))

Output: 0.46630765815499864

Tanh(x) Function:

It is a function to calculate hyperbolic tangent of a number in radians.

Example:

import pythmath

angle = 25

print(pythmath.tanh(angle))

Output: 1.0

Statistical Functions:

Mean:

It is a function to calculate the mean of given dataset or list. Mean: In mathematics and statistics, the arithmetic mean or arithmetic average, or simply just the mean or the average, is the sum of a collection of numbers divided by the count of numbers in the collection.

Example:

from pythmath.statistics import *

numbers = [1, 2, 3, 4, 5]

print(mean(numbers))

Output: 3.0

Median:

It is function that calculates median of given dataset or list. Median: In statistics and probability theory, the median is the value separating the higher half from the lower half of a data sample, a population, or a probability distribution. For a data set, it may be thought of as "the middle" value.

Example:

from pythmath.statistics import *

numbers = [1, 2, 3, 4, 5]

print(median(numbers))

Output: 3

Mode:

It is a function that gets the mode of given datasets or list. Mode: The mode is the value that appears most often in a set of data values. If X is a discrete random variable, the mode is the value x at which the probability mass function takes its maximum value. In other words, it is the value that is most likely to be sampled.

Example:

from pythmath.statistics import *

numbers = [1, 2, 3, 4, 5, 5]

print(mode(numbers))

Output: 5

Standard Deviation:

It calculates the standard deviation from given dataset or list of numbers. Standard Deviation: In statistics, the standard deviation is a measure of the amount of variation or dispersion of a set of values. A low standard deviation indicates that the values tend to be close to the mean of the set, while a high standard deviation indicates that the values are spread out over a wider range.

Example:

from pythmath.statistics import *

data = [1, 2, 3, 4, 5]

print(stdev(data))

Output: 1.5811388300841898

Population Standard Deviation:

It is a function that calculates population standard deviation from given dataset or list of numbers.

Example:

from pythmath.statistics import *

data = [1, 2, 3, 4, 5]

print(pstdev(data))

Output: 1.4142135623730951

Mean Absolute Deviation(MAD):

It is a function that calculates the mean absolute deviation from given dataset or list of numbers. Mean Absolute Deviation: The mean absolute deviation (MAD) is a measure of variability that indicates the average distance between observations and their mean. MAD uses the original units of the data, which simplifies interpretation. Larger values signify that the data points spread out further from the average. Conversely, lower values correspond to data points bunching closer to it. The mean absolute deviation is also known as the mean deviation and average absolute deviation.

Example:

from pythmath.statistics import *

data = [1, 2, 3, 4, 5]

print(mean_abs_dev(data))

Output: 1.2

Variance:

It is a function that calculates the variance from given dataset or list of values. it takes two parameters: data: values of dataset and v_mode. v_mode: Mode of variance either standard(std) or population(pop), it is optional and by default its mode is standard(std) Note: pop does not equivalent to stack pop.

Example:

With v_mode="std"

from pythmath.statistics import *

data = [2, 4, 6, 8, 10]

print(variance(data))

Output: 10.0

With v_mode="pop"

import pythmath

data = [2, 4, 6, 8, 10]

print(pythmath.variance(data, v_mode="pop"))

Output: 8.0

Z Score:

It is a function that calculates the z score value from x, mean value and from value of standard deviation. Z Score: In statistics, the standard score is the number of standard deviations by which the value of a raw score is above or below the mean value of what is being observed or measured. Raw scores above the mean have positive standard scores, while those below the mean have negative standard scores.

Example:

from pythmath.statistics import *

x = 70
mean_val = 60
st_dev = 15

print(zscore(x, mean_val, st_dev))

Output: 0.6666666666666666

Standard Error:

It is a function that calculates standard error from given dataset or from list of numbers. Standard Error: The standard error of a statistic is the standard deviation of its sampling distribution or an estimate of that standard deviation. If the statistic is the sample mean, it is called the standard error of the mean.

Example:

from pythmath.statistics import *

data = [10, 12, 16, 21, 25]

print(stderr(data))

Output: 2.782085548648711

Sampling Error:

It is a function that calculates the sampling error. It takes three parameters: n, pst_dev and conf n: Size of sampling. pst_dev: Population Standard Deviation conf: Confidence level approx 1.96, it is optional and by default its value is set 1.96

Example:

from pythmath.statistics import *

n = 2500
pst_dev = 0.40

print(samp_err(n, pst_dev))

Output: 0.01568

Statistical Range:

It is a function that calculates the statistical range from given dataset or set of integer values. Statistical Range: In statistics, the range of a set of data is the difference between the largest and smallest values. Difference here is specific, the range of a set of data is the result of subtracting the sample maximum and minimum. However, in descriptive statistics, this concept of range has a more complex meaning.

Example:

from pythmath.statistics import *

lst = [1, 2, 3, 4, 5]

print(stats_range(lst))

Output: 4

Mid Range:

It is a function that calculates the midpoint range from given dataset or set of integer values. Mid Range: In statistics, the mid-range or mid-extreme is a measure of central tendency of a sample defined as the arithmetic mean of the maximum and minimum values of the data set.

Example:

from pythmath.statistics import *

lst = [1, 2, 3, 4, 5]

print(midrange(lst))

Output: 3.0

Error Functions:

Percentage Error:

It is a funcion that calculates the percentage error from measured value and true or real value.

Example:

from pythmath.errors import *

measured_val = 8
true_val = 10

print(perc_err(measured_val, true_val))

Output: 20.0

Absolute Error:

It is a function that calculates the absolute error from measured value and true or real value.

Example:

from pythmath.errors import *

measured_val = 8
true_val = 10

print(abs_err(measured_val, true_val))

Output: 2

Relatable Error:

It is a function that calculates the relatable error from measured value and true or real value.

Example:

from pythmath.errors import *

measured_val = 8
true_val = 10

print(rel_error(measured_val, true_val))

Output: 0.2

For more examples see Examples.

About

Advance python Math Library which performs all the basic and scientific math operations such as cos, sin, tan etc. It also includes basic statistical functions such as mean, median, mode, standard deviation etc

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published