Skip to main content

Democritus functions for working with math.

Project description

Democritus Math

PyPI CI Lint codecov The Democritus Project uses semver version 2.0.0 The Democritus Project uses black to format code License: LGPL v3

Democritus functions[1] for working with math.

[1] Democritus functions are simple, effective, modular, well-tested, and well-documented Python functions.

We use d8s (pronounced "dee-eights") as an abbreviation for democritus (you can read more about this here).

Installation

pip install d8s-math

Usage

You import the library like:

from d8s_math import *

Once imported, you can use any of the functions listed below.

Functions

  • def fibonacci_sequence(n: int) -> List[int]:
        """Return the first n digits of the fibonacci sequence."""
    
  • def fibonacci(n: int) -> int:
        """Return the value of the Fibonacci sequence at index n."""
    
  • def number_closest(a, b, target):
        """Return a or b, whichever is closest to the target."""
    
  • def number_furthest(a, b, target):
        """Return a or b, whichever is furthest to the target."""
    
  • def cartesian_product(a: Any, *args: Any, repeat: int = 1):
        """."""
    
  • def sympy_symbol(symbol_name: str):
        """."""
    
  • def equation_solve(equation: str, symbols: List[str]):
        """."""
    
  • def expression_explore(expression: str, symbol: str, start: int, end: int, step: int):
        """."""
    
  • def one_cold_encode(items: list, *, reverse: bool = False) -> List[list]:
        """."""
    
  • def one_hot_encode(items: list, *, reverse: bool = False) -> List[list]:
        """."""
    
  • def is_integer_tuple(possible_integer_tuple: Any) -> bool:
        """."""
    
  • def string_to_number(string: str) -> Union[int, float]:
        """Convert a number as a string into either an integer or float."""
    
  • def first_arg_as_decimal(func):
        """Convert the first argument to a number (either integer or float)."""
    
  • def arguments_as_decimals(func):
        """Convert all arguments to numbers (either integers or floats)."""
    
  • def decimal_to_gray_code(num: Union[str, int, float]) -> integerTupleType:
        """Convert the given number to a gray code. This function was inspired by the code here: https://en.wikipedia.org/wiki/Gray_code#Converting_to_and_from_Gray_code."""
    
  • def gray_code_to_decimal(num: integerTupleType) -> int:
        """Convert the given number to a gray code. This function was inspired by the code here: https://en.wikipedia.org/wiki/Gray_code#Converting_to_and_from_Gray_code."""
    
  • def decimal_to_hex(decimal_number):
        """."""
    
  • def hex_to_decimal(hex):
        """."""
    
  • def roman_numeral_to_decimal(roman_numeral: str) -> int:
        """."""
    
  • def decimal_to_roman_numeral(decimal_number) -> str:
        """."""
    
  • def integer_tuple_to_decimal(integer_tuple: integerTupleType) -> int:
        """Return the decimal form of the given number (represented as an integer tuple)."""
    
  • def integer_to_decimal(num: Union[str, int, float], base: int) -> int:
        """Convert the number of the given base to a decimal number."""
    
  • def decimal_to_base(decimal_number: Union[str, int, float], base: int):
        """Convert the decimal_number to the given base."""
    
  • def outer_division():
        """."""
    
  • def outer_product(a: int, b: int, a_start: int = 1, b_start: int = 1):
        """Return a two-dimensional array with the results of range(a_start, a+1) multiplied by range(b_start, b+1)."""
    
  • def multiplication_table(a: int, b: int, a_start: int = 1, b_start: int = 1):
        """."""
    
  • def number_evenly_divides(a, b):
        """Return True if a evenly divides b. Otherwise, return False."""
    
  • def number_evenly_divided_by(a, b):
        """Return True if a is evenly divided by b. Otherwise, return False."""
    
  • def fraction_examples(n=10, *, fractions_as_strings: bool = True):
        """Create n fractions."""
    
  • def iterable_differences(iterable):
        """Find all of the possible differences of all possible orders of the given iterable."""
    
  • def combinations(iterable, length=None):
        """Return all possible combinations of the given length which can be created from the given iterable. If no length is given, we will find all combinations of all lengths for the given iterable."""
    
  • def combinations_with_replacement(iterable, length=None):
        """Return all possible combinations of the given length which can be created from the given iterable. If no length is given, we will find all combinations of all lengths for the given iterable."""
    
  • def prod(iterable):
        """Get the product of the iterable."""
    
  • def permutations(iterable, length=None):
        """Return all possible permutations of the given iterable. If no length is given, we will find all permutations of all lengths for the given iterable"""
    
  • def fraction_simplify(fraction_string):
        """Simplify the fraction represented as a string."""
    
  • def remainder(dividend, divisor):
        """."""
    
  • def floor(number):
        """."""
    
  • def ceiling(number):
        """."""
    
  • def factorial(number):
        """."""
    
  • def fraction_complex_to_mixed_fraction(fraction_string):
        """Simplify the fraction represented as a string."""
    
  • def fraction_mixed_to_complex_fraction(fraction_string):
        """Simplify the fraction represented as a string."""
    
  • def dot_product(item_a, item_b):
        """Find the dot product for the two items. See https://en.wikipedia.org/wiki/Dot_product for more details."""
    
  • def percent(ratio):
        """Return the ratio as a percentage."""
    
  • def gcd(number1, number2):
        """Return the greatest common divisor."""
    
  • def ratio(number1, number2):
        """Return the ratio of the two numbers in the form 1:2. For example, if given 5 and 10, this function would return "1:2". If given 2 and 20, this function would return "1:10"."""
    
  • def transpose(matrix):
        """Transpose the given matrix. See https://en.wikipedia.org/wiki/Transpose."""
    
  • def number_line(value, min_, max_, interval: int = 1):
        """."""
    
  • def number_zero_pad(num: StrOrNumberType, length: StrOrNumberType) -> str:
        """."""
    
  • def is_number(item):
        """Return whether or not the item is a number."""
    
  • def number_is_even(number: StrOrNumberType):
        """."""
    
  • def number_is_odd(number: StrOrNumberType):
        """."""
    
  • def number_is_approx(number, approximate_value, *, relative_tolerance=1e-6):
        """."""
    
  • def enumerate_range(range_string, range_split_string: str = '-'):
        """Enumerate the range specified by the string. For example, `1-3` returns `[1, 2, 3]`."""
    
  • def hex_endiness_swap(hex_string):
        """Credit to: https://stackoverflow.com/questions/27506474/how-to-byte-swap-a-32-bit-integer-in-python."""
    
  • def number_to_words(number):
        """Convert a number to its English representation (e.g. 100 => "One Hundred")."""
    
  • def number_to_scientific_notation(number):
        """Convert the given number to scientific notation."""
    
  • def number_to_engineering_notation(number):
        """Convert the given number to engineering notation."""
    

Development

👋  If you want to get involved in this project, we have some short, helpful guides below:

If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.

Credits

This package was created with Cookiecutter and Floyd Hightower's Python project template.

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

d8s_math-0.6.0.tar.gz (39.4 kB view details)

Uploaded Source

Built Distribution

d8s_math-0.6.0-py2.py3-none-any.whl (30.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file d8s_math-0.6.0.tar.gz.

File metadata

  • Download URL: d8s_math-0.6.0.tar.gz
  • Upload date:
  • Size: 39.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for d8s_math-0.6.0.tar.gz
Algorithm Hash digest
SHA256 61772bdebd9ba0714a7cce8008704002a35d2f8cab3d00f15d314a0c1bde6827
MD5 4e70ca8cf5af3f1944dd2495b9379992
BLAKE2b-256 6988909c1d27cb490240e82a5d2d85a95cb9c2c4d75ea82779b20a7dc5c0ff49

See more details on using hashes here.

File details

Details for the file d8s_math-0.6.0-py2.py3-none-any.whl.

File metadata

  • Download URL: d8s_math-0.6.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for d8s_math-0.6.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ce3e55498200c02817d5123448459dbb4c642447143a151ab23de3cd8ab513f6
MD5 c8f1cfa72a87c24a335b801506c14fa9
BLAKE2b-256 ea8ebb571491fd8201144065184a51e4a81107e5a92138b140af9eacadb57fca

See more details on using hashes here.

Supported by

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