Package: d8s-math
Democritus MathDemocritus functions[1]for working with math.[1] Democritus functions aresimple, effective, modular, well-tested, and well-documentedPython functions.We used8s(pronounced "dee-eights") as an abbreviation fordemocritus(you can read more about thishere).Installationpip install d8s-mathUsageYou import the library like:fromd8s_mathimport*Once imported, you can use any of the functions listed below.Functionsdeffibonacci_sequence(n:int)->List[int]:"""Return the first n digits of the fibonacci sequence."""deffibonacci(n:int)->int:"""Return the value of the Fibonacci sequence at index n."""defnumber_closest(a,b,target):"""Return a or b, whichever is closest to the target."""defnumber_furthest(a,b,target):"""Return a or b, whichever is furthest to the target."""defcartesian_product(a:Any,*args:Any,repeat:int=1):"""."""defsympy_symbol(symbol_name:str):"""."""defequation_solve(equation:str,symbols:List[str]):"""."""defexpression_explore(expression:str,symbol:str,start:int,end:int,step:int):"""."""defone_cold_encode(items:list,*,reverse:bool=False)->List[list]:"""."""defone_hot_encode(items:list,*,reverse:bool=False)->List[list]:"""."""defis_integer_tuple(possible_integer_tuple:Any)->bool:"""."""defstring_to_number(string:str)->Union[int,float]:"""Convert a number as a string into either an integer or float."""deffirst_arg_as_decimal(func):"""Convert the first argument to a number (either integer or float)."""defarguments_as_decimals(func):"""Convert all arguments to numbers (either integers or floats)."""defdecimal_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."""defgray_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."""defdecimal_to_hex(decimal_number):"""."""defhex_to_decimal(hex):"""."""defroman_numeral_to_decimal(roman_numeral:str)->int:"""."""defdecimal_to_roman_numeral(decimal_number)->str:"""."""definteger_tuple_to_decimal(integer_tuple:integerTupleType)->int:"""Return the decimal form of the given number (represented as an integer tuple)."""definteger_to_decimal(num:Union[str,int,float],base:int)->int:"""Convert the number of the given base to a decimal number."""defdecimal_to_base(decimal_number:Union[str,int,float],base:int):"""Convert the decimal_number to the given base."""defouter_division():"""."""defouter_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)."""defmultiplication_table(a:int,b:int,a_start:int=1,b_start:int=1):"""."""defnumber_evenly_divides(a,b):"""Return True if a evenly divides b. Otherwise, return False."""defnumber_evenly_divided_by(a,b):"""Return True if a is evenly divided by b. Otherwise, return False."""deffraction_examples(n=10,*,fractions_as_strings:bool=True):"""Create n fractions."""defiterable_differences(iterable):"""Find all of the possible differences of all possible orders of the given iterable."""defcombinations(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."""defcombinations_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."""defprod(iterable):"""Get the product of the iterable."""defpermutations(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"""deffraction_simplify(fraction_string):"""Simplify the fraction represented as a string."""defremainder(dividend,divisor):"""."""deffloor(number):"""."""defceiling(number):"""."""deffactorial(number):"""."""deffraction_complex_to_mixed_fraction(fraction_string):"""Simplify the fraction represented as a string."""deffraction_mixed_to_complex_fraction(fraction_string):"""Simplify the fraction represented as a string."""defdot_product(item_a,item_b):"""Find the dot product for the two items. See https://en.wikipedia.org/wiki/Dot_product for more details."""defpercent(ratio):"""Return the ratio as a percentage."""defgcd(number1,number2):"""Return the greatest common divisor."""defratio(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"."""deftranspose(matrix):"""Transpose the given matrix. See https://en.wikipedia.org/wiki/Transpose."""defnumber_line(value,min_,max_,interval:int=1):"""."""defnumber_zero_pad(num:StrOrNumberType,length:StrOrNumberType)->str:"""."""defis_number(item):"""Return whether or not the item is a number."""defnumber_is_even(number:StrOrNumberType):"""."""defnumber_is_odd(number:StrOrNumberType):"""."""defnumber_is_approx(number,approximate_value,*,relative_tolerance=1e-6):"""."""defenumerate_range(range_string,range_split_string:str='-'):"""Enumerate the range specified by the string. For example, `1-3` returns `[1, 2, 3]`."""defhex_endiness_swap(hex_string):"""Credit to: https://stackoverflow.com/questions/27506474/how-to-byte-swap-a-32-bit-integer-in-python."""defnumber_to_words(number):"""Convert a number to its English representation (e.g. 100 => "One Hundred")."""defnumber_to_scientific_notation(number):"""Convert the given number to scientific notation."""defnumber_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:contribute to this project 🥇test it 🧪lint it 🧹explore it 🔭If you have any questions or there is anything we did not cover, please raise an issue and we'll be happy to help.CreditsThis package was created withCookiecutterand Floyd Hightower'sPython project template.