Skip to main content

A package for advanced mathematical calculations including interest, custom math, and geometry.

Project description

Advanced Math Utilities

A comprehensive Python package for various mathematical and financial calculations. This package includes modules for compound interest, number theory (prime checking, factorial, permutation, combination), string manipulation, matrix operations, and basic statistics (mean, median, mode).

Installation

You can install this package using pip:

pip install advanced_math

Usage

Here are some examples of how to use the functions provided in this package:

Finance Module (finance.py)

This module provides a function to calculate compound interest.

interest(prime_amount, time_duration_str, number_of_times_interest_will_compound_per_year, rate_of_interest)

Calculates the compound interest.

  • prime_amount (float or int): The initial principal amount (P).

  • time_duration_str (str): The duration for which the interest is calculated, must be in specific short-hand formats:

    • "XyYm" (e.g., "5y6m", "1y8m" for 1 year 8 months)

    • "Xm" (e.g., "15m", "6m" for 15 months, 6 months)

    • "Xy" (e.g., "5y", "1y" for 5 years, 1 year) Where X and Y are whole numbers.

  • number_of_times_interest_will_compound_per_year (float or int): The number of times interest is compounded per year (n) (e.g., 2 for half-yearly, 4 for quarterly, 12 for monthly, 365 for daily).

  • rate_of_interest (float or int): The annual nominal interest rate (as a percentage, e.g., 5 for 5%).

Returns:

  • float: The compound interest amount earned, rounded to 3 decimal places.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import finance

# Calculate interest for $1000 at 5% compounded monthly for 1 year
interest_earned = finance.interest(1000, "1y", 12, 5)
print(f"Compound interest: ${interest_earned}")

AdCustom Module (adcustom.py)

This module contains various utility functions for number theory, string manipulation, matrix operations, and statistics.

Number Theory

check_prime(inp)

Checks if the input integer is a Prime number.

  • inp (int): The non-negative integer to check.

Returns:

  • 1: If the input integer is Prime.

  • 0: If the input integer is not Prime.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

print(f"Is 17 prime? {adcustom.check_prime(17)}")
print(f"Is 10 prime? {adcustom.check_prime(10)}")

factorial(inp)

Calculates the factorial of a given non-negative integer.

  • inp (int): A non-negative integer.

Returns:

  • int: The factorial of the non-negative integer.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

print(f"Factorial of 5: {adcustom.factorial(5)}")

permutation(total_item, chosen_item)

Calculates the number of permutations P(n, k).

  • total_item (int): The total number of distinct items in the set (n).

  • chosen_item (int): The number of items to be arranged or chosen from the set at a time (k).

Returns:

  • int: The number of permutations.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

print(f"Permutations of 5 items taken 2 at a time: {adcustom.permutation(5, 2)}")

combination(total_item, chosen_item)

Calculates the number of combinations C(n, k).

  • total_item (int): The total number of distinct items in the set (n).

  • chosen_item (int): The number of items to be arranged or chosen from the set at a time (k).

Returns:

  • int: The number of combinations.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

print(f"Combinations of 5 items taken 2 at a time: {adcustom.combination(5, 2)}")

String Manipulation

string_reverse(string)

Reverses the given string.

  • string (str): The input string.

Returns:

  • str: The reversed string.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

print(f"Reversed string 'hello': {adcustom.string_reverse('hello')}")

Matrix Operations

matrix_addition(matrix1, matrix2)

Adds two input matrices.

  • matrix1 (list of lists): The first matrix.

  • matrix2 (list of lists): The second matrix.

Returns:

  • str: A string representation of the resulting matrix.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

mat1 = [[1, 2], [3, 4]]
mat2 = [[5, 6], [7, 8]]
print("Matrix Addition:")
print(adcustom.matrix_addition(mat1, mat2))

matrix_multiplication(matrix1, matrix2)

Multiplies one input matrix with another input matrix.

  • matrix1 (list of lists): The first matrix.

  • matrix2 (list of lists): The second matrix.

Returns:

  • str: A string representation of the resulting matrix.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

mat1 = [[1, 2], [3, 4]]
mat2 = [[5, 6], [7, 8]]
print("Matrix Multiplication:")
print(adcustom.matrix_multiplication(mat1, mat2))

matrix_transpose(matrix)

Transposes a matrix (row becomes column, column becomes row).

  • matrix (list of lists): The input matrix.

Returns:

  • str: A string representation of the transposed matrix.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

mat = [[1, 2, 3], [4, 5, 6]]
print("Matrix Transpose:")
print(adcustom.matrix_transpose(mat))

determinant_value(matrix)

Calculates the determinant value of a given matrix. Currently supports matrices up to 3x3.

  • matrix (list of lists): The input matrix.

Returns:

  • int or float: Determinant value of the given matrix.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

mat_2x2 = [[1, 2], [3, 4]]
print(f"Determinant of 2x2 matrix: {adcustom.determinant_value(mat_2x2)}")

mat_3x3 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(f"Determinant of 3x3 matrix: {adcustom.determinant_value(mat_3x3)}")

Statistics

mean(inp_set)

Calculates the mean value of a set.

  • inp_set (list or tuple): The input set of numbers.

Returns:

  • float: Mean value of the input set.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

data = [1, 2, 3, 4, 5]
print(f"Mean of {data}: {adcustom.mean(data)}")

median(inp_set)

Calculates the median value of a set.

  • inp_set (list or tuple): The input set of numbers.

Returns:

  • float: Median value of the input set.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

data_odd = [1, 3, 2, 5, 4]
print(f"Median of {data_odd}: {adcustom.median(data_odd)}")

data_even = [1, 2, 3, 4]
print(f"Median of {data_even}: {adcustom.median(data_even)}")

mode(inp_set)

Calculates the mode value(s) and their count(s) of a set.

  • inp_set (list or tuple): The input set.

Returns:

  • tuple: A tuple containing a list of mode(s) and the highest count.

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import adcustom

data_mode = [1, 2, 2, 3, 4, 4, 4, 5]
mode_values, count = adcustom.mode(data_mode)
print(f"Mode(s) of {data_mode}: {mode_values} (occurred {count} times)")

Triangle Module (triangle.py)

This module calculates the area of a triangle using Heron's formula.

areaoftriangle(len_a, len_b, len_c, unit='')

Calculates the area of a triangle using Heron's formula: $\sqrt{s(s-a)(s-b)(s-c)}$

  • len_a (float or int): A positive number as length of side 'a'.

  • len_b (float or int): A positive number as length of side 'b'.

  • len_c (float or int): A positive number as length of side 'c'.

  • unit (str, optional): Unit of the area (e.g., "sq cm", "m^2"). Defaults to "".

Returns:

  • float: Area of the triangle, rounded to 3 decimal places (if no unit is provided).

  • str: Area of the triangle with the specified unit (e.g., "12.345 sq cm").

  • None: If the input is not valid or any error occurs.

Example:

from advanced_math import triangle

# Calculate area of a 3-4-5 right triangle
area = triangle.areaoftriangle(3, 4, 5, unit="sq cm")
print(f"Area of triangle: {area}")

Contributing

If you'd like to contribute to this project, please feel free to fork the repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adpkg-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

adpkg-0.1.0-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file adpkg-0.1.0.tar.gz.

File metadata

  • Download URL: adpkg-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for adpkg-0.1.0.tar.gz
Algorithm Hash digest
SHA256 649548a060430523ce5fd564232f98bcc9bd5c09316d976586d31a606e84825b
MD5 083d2d0a7ec10cdb6b07524e2fcc3c27
BLAKE2b-256 8577880442bf077bbd978c08c31066e04f93821c4befabe11086e79ef50ee7dd

See more details on using hashes here.

File details

Details for the file adpkg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: adpkg-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for adpkg-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94273597184a2ec7f203dbc33c4caf6694da6c1e45f0273e756ecca3e6874f62
MD5 dbfb374d76196c90ae0f1643fe877f9e
BLAKE2b-256 3cf3b7b9ac4b0b159b8ecc2068be1dabc559f510f307e0d1cd9472b518baa3ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page