Quikarit documentation

Go to the changelogs

The QuikArit library adds miscellaneous/QoL functions to Python.

Jump to

Misc. math functions

GetxthRoot(x: float, y: float) -> float

Returns the xth root of y.

Added in v0.1.0

Deprecated in v0.2.0

Example usage:


            > print(GetxthRoot(3, 8))
            
            Output:
            2.0
            

GetDivisors(x: int) -> list

Returns the divisors of x.

Added in v0.1.0

Example usage:


            > print(GetDivisors(8))
            
            Output:
            [1, 2, 4, 8]
            

Magnitude(x: float, y: float, z: None) -> int

Returns the magnitude of the x, y, z vector. (z is optional).

Added in v0.1.0

Example usage:


            > print(Magnitude(3, -4, 12))
            
            Output:
            13.0
            

pythsTheorem(x: float, y: float) -> int

Returns the hypotenuse of the right triangle whose cathetuses are x and y.

Added in v0.1.0

Example usage:


            > print(pythsTheorem(1, 1))
            
            Output:
            1.4142135623730951
            

isPrime(x: int) -> bool

Returns True if x is prime, False if not.

Added in v0.1.0

Example usage:


            > print(isPrime(7))
            
            Output:
            True
            

GetElementFromPeriodicTable(x: int) -> str

Returns the xth element from the periodic table.

Added in v0.1.0

Example usage:


            > print(GetElementFromPeriodicTable(10))
            
            Output:
            "Ne"
            

isPerfectSquare(n: int) -> bool

Checks if the number n is a perfect square, returns True if so, False otherwise.

Added in v0.1.0

Example usage:


        > print(isPerfectSquare(25))
        
        Output:
        True
        

fib(reps: int) -> list

Generates a fibonacci sequence of length reps.

Added in v0.1.0

Example usage:


        > print(fib(5))
        
        Output:
        [1, 1, 2, 3, 5]
        

modulo(x: float) -> float

Gets the modulo of x.

Added in v0.1.0

Deprecated in v0.2.0

Example usage:


        > print(modulo(-4))
        
        Output:
        4.0
        

Percent(x: float, y: float) -> float

Returns x% of y.

Added in v0.1.0

Deprecated in v0.2.0

Example usage:


        > print(Percent(2, 100))
        
        Output:
        2.0
        

hexArea(x: float) -> float

Returns the area of a regular hexagon using x as the side.

Added in v0.1.0

Example usage:


        > print(hexArea(10))
        
        Output:
        259.8076211353316
        

hexcolorRandom(hasAlpha: bool) -> str

Returns a pseudorandom color. hasAlpha determines if the color has the alpha channel (transparency).

Added in v0.1.0

Example usage:


        > print(hexcolorRandom(True))
        
        Output:
        "#6E6F0500"
        

termial(x: int) -> int

Calculates the termial of x.

$$\sum_{n=1}^{x} n$$

Added in v0.3.0

Example usage:


        > print(termial(3))
        
        Output:
        6
        

factorial(x: int) -> int

Calculates the factorial of x.

$$\prod_{n=1}^{x} n$$

Added in v0.3.0

Example usage:


        > print(factorial(4))
        
        Output:
        24
        

Statistic functions

mean(x: list) -> float

Returns the mean of a list.

Added in v0.1.0

Example usage:


        > print(mean([8, 5, 2, 3]))
        
        Output:
        6.25
        

median(x: list) -> float

Returns the median of a list.

Added in v0.1.0

Example usage:


        > print(median([8, 5, 2, 3]))
        
        Output:
        3.5
        

geoMean(x: list) -> float

Returns the geometric mean of a list.

Added in v0.1.0

Example usage:


        > print(geoMean([2, 4, 5, 6]))
        
        Output:
        3.9359793425308607
        

standardDeviation(x: list) -> float

Calculates the standard deviation of list x.

Added in v0.3.0

Example usage:


        > print(standardDeviation([1, 2, 3]))
        
        Output:
        1.0
        

Logic Gates

xor(x: bool, y: bool) -> bool

Logic gate XOR.

XOR truth table:

Added in v0.1.0

Example usage:


        > print(xor(True, False))
        
        Output:
        True
        

xnor(x: bool, y: bool) -> bool

Logic gate XOR.

XNOR truth table:

Added in v0.1.0

Example usage:


        > print(xnor(True, False))
        
        Output:
        True
        

nor(x: bool, y: bool) -> bool

Logic gate NOR.

NOR truth table:

Added in v0.2.0

Example usage:


        > print(nor(True, False))
        
        Output:
        False
        

nand(x: bool, y: bool) -> bool

Logic gate NAND.

NAND truth table:

Added in v0.2.0

Example usage:


        > print(nand(True, False))
        
        Output:
        True
        

Complex/Imaginary Operations

ComplexAdd(x: str, y: str) -> str

Takes two inputs x and y in the format "a+bi" and adds them.

Added in v0.1.0

Example usage:


        > print(ComplexAdd("1+2i", "1+2i"))
        
        Output:
        "2+4i"
        

ComplexSub(x: str, y: str) -> str

Takes two inputs x and y in the format "a+bi" and subtracts them.

Added in v0.1.0

Example usage:


        > print(ComplexSub("1+2i", "2+2i"))
        
        Output:
        "-1+0i"
        

ComplexMult(x: str, y: str) -> str

Takes two inputs x and y in the format "a+bi" and multiplies them.

Added in v0.1.0

Example usage:


        > print(ComplexMult("1+2i", "2+2i"))
        
        Output:
        "-2+6i"
        

ComplexDiv(x: str, y: str) -> str

Takes two inputs x and y in the format "a+bi" and divides them.

Added in v0.2.0

Example usage:


        > print(ComplexDiv("1+2i", "2+4i"))
        
        Output:
        "0.5+0i"
        

imaginaryMult(x: str, y: str) -> str

Takes two inputs x and y in the format "bi" and multiplies them.

Added in v0.1.0

Example usage:


        > print(imaginaryMult("4i", "2i"))
        
        Output:
        "8i"
        

imaginaryDiv(x: str, y: str) -> str

Takes two inputs x and y in the format "bi" and divides them.

Added in v0.1.0

Example usage:


        > print(imaginaryDiv("4i", "2i"))
        
        Output:
        "2i"
        

Matrix Operations

matrixsum(x: list, y: list) -> list

Takes two inputs x and y and adds their numbers.

Added in v0.1.0

Patched in v0.2.0

Example usage:


        > print(matrixsum([1, 2], [3, 4]))
        
        Output:
        [4, 6]
        

matrixsub(x: list, y: list) -> list

Takes two inputs x and y and subtracts their numbers.

Added in v0.1.0

Patched in v0.2.0

Example usage:


        > print(matrixsub([1, 2], [3, 4]))
        
        Output:
        [-2, -2]
        

matrixmult(x: list, y: list) -> list

Takes two inputs x and y and multiplies them.

Added in v0.2.0

Example usage:


            > print(matrixmult([[1, 2], [1, 2]], [[1, 2, 3], 
            [1, 2, 3]]))
        
            Output:
            [[3, 6, 9], [3, 6, 9]]
            

matrixdet(x: list) -> int

Takes a matrix x and calculates its determinant (up to 4x4).

Added in v0.2.0

Example usage:


            > print(matrixdet([[1, 2], [1, 2]]))
        
            Output:
            0
            

flipMatrixSideways(x: list) -> list

Flips the matrix sideways.

Added in v0.2.0

Example usage:


            > print(flipMatrixSideways([[1, 2, 3], [1, 2, 3]]))
        
            Output:
            [[1, 1], [2, 2], [3, 3]]
            

Conversion functions

rad2deg(x: float) -> float

Converts radians to degrees.

Added in v0.1.0

Example usage:


        > print(rad2deg(2*3.14))
        
        Output:
        360.0
        

deg2rad(x: float) -> float

Converts degrees to radians.

Added in v0.1.0

Example usage:


        > print(deg2rad(360))
        
        Output:
        6.28318530718
        

bin2dec(x: str) -> int

Converts binary to decimal.

Added in v0.1.0

Example usage:


        > print(bin2dec("1010"))
        
        Output:
        10
        

dec2bin(x: str) -> str

Converts decimal to binary.

Added in v0.1.0

Example usage:


        > print(dec2bin(10))
        
        Output:
        "1010"
        

hex2dec(x: str) -> int

Converts hexadecimal to decimal.

Added in v0.1.0

Example usage:


        > print(hex2dec("1A"))
        
        Output:
        26
        

hex2bin(x: str) -> str

Converts hexadecimal to binary.

Added in v0.1.0

Example usage:


        > print(hex2bin("0A"))
        
        Output:
        "1010"
        

oct2bin(x: int) -> str

Converts octal to binary.

Added in v0.2.0

Example usage:


            > print(oct2bin(7))
        
            Output:
            '111'
            

oct2dec(x: int) -> int

Converts octal to decimal.

Added in v0.2.0

Example usage:


            > print(oct2dec(7))
        
            Output:
            7
            

hex2bin(x: str) -> str

Converts hexadecimal to binary.

Added in v0.3.0

Example usage:


        > print(hex2bin('FF'))
        
        Output:
        '11111111'
        

dec2hex(x: int) -> str

Converts decimal to hexadecimal

Added in v0.3.0

Example usage:


        > print(dec2hex(10))
        
        Output:
        'A'
        

bin2hex(x: str) -> float

Converts binary to hexadecimal.

Added in v0.3.0

Example usage:


        > print(bin2hex('11111111'))
        
        Output:
        'FF'
        

Array sorting functions

isSorted(x: list, orient: None)

Checks if the list x is sorted. Returns True if so, False otherwise.

The orient parameter determines if the checking will occur from the smallest to the biggest (None/True), or the opposite (False)

Added in v0.1.0

Example usage:


        > print(isSorted([1, 2, 3], None))
        
        Output:
        True
        

flipList(x: list)

Flips the order of elements in a list.

Added in v0.1.0

Example usage:


        > print(flipList([0, 1, 2]))
        
        Output:
        [2, 1, 0]
        

bogoSort(x: list)

Sorts the list x by shuffling it randomly until it is sorted.

Added in v0.1.0

Avg.

$$n \cdot n!$$

Example usage:


        > print(bogoSort([0, 1, -1]))
        
        Output:
        [-1, 0, 1]
        

selectionSort(x: list)

Sorts the list x by getting the smallest number in the list and moving it to the first index of the list and so on.

Added in v0.1.0

Avg.

$$n^2$$

Example usage:


        > print(selectionSort([1, 2, -1]))
        
        Output:
        [-1, 1, 2]
        

stalinSort(x: list)

"Sorts" the list by removing every number out of order.

Added in v0.1.0

Example usage:


        > print(stalinSort([1, 2, -1]))
        
        Output:
        [1, 2]
        

bubbleSort(x: list) -> list

Sorts the list x by switching the numbers out of order until they are sorted.

Added in v0.2.0

Example usage:


            > print(bubbleSort([3, 4, 2, 1]))
        
            Output:
            [1, 2, 3, 4]
            

Calculus (module)

solveQuadratic(x: str) -> list

Solves quadratic equations strictly in the form of ax^2+bx+c(=0).

Don't put the '=0' part.

Added in v0.3.0

Example usage:


        > print(solveQuadratic('2x^2+2x+3'))
        
        Output:
        [(-0.49999999999999994+1.118033988749895j), (-0.5...
        

summation(upperLimit: int, variable: str, startingValue: int, expr: str) -> float

Calculates the summation of expression expr.

$$\sum_{variable=startingValue}^{upperLimit} expr$$

Added in v0.3.0

Example usage:


        > print(summation(3, 'x', 1, '2x'))
        
        Output:
        12.0
        

product(upperLimit: int, variable: str, startingValue: int, expr: str) -> float

Calculates the product of expression expr.

$$\prod_{variable=startingValue}^{upperLimit} expr$$

Added in v0.3.0

Example usage:


        > print(product(3, 'x', 1, '2x'))
        
        Output:
        48.0
        

sin(x: float, accuracy=None) -> float

Calculates the sine of x (in radians) with accuracy tune.

Added in v0.3.0

Example usage:


        > print(sin(3.14159, accuracy=25))
        
        Output:
        2.653589793297756e-06
        

cos(x: float, accuracy=None) -> float

Calculates the cosine of x (in radians) with accuracy tune.

Added in v0.3.0

Example usage:


        > print(cos(3.14159, accuracy=25))
        
        Output:
        -0.999999999996479
        

tan(x: float, acc=None) -> float

Calculates the tangent of x (in radians) with accuracy tune.

Added in v0.3.0

Example usage:


        > print(tan(3.14159, acc=25))
        
        Output:
        -2.653589793307099e-06
        

arctan(x: float, acc=None) -> float

Calculates the arctangent of x (in radians) with accuracy tune.

Added in v0.3.0

Example usage:


        > print(arctan(1, acc=25))
        
        Output:
        0.7757863282215032
        

slopeAngle(x: str) -> float

Calculates the angle (in radians) of linear function x in the form of y=mx+b.

Added in v0.3.0

Example usage:


        > print(slopeAngle('x'))
        
        Output:
        0.7934605842976876
        

findSlopebyAngle(x: float) -> float

Calculates the m in the y=mx+b formula.

! Attention -- x is in radians.

Added in v0.3.0

Example usage:


        > print(findSlopebyAngle(0.7757863282215032))
        
        Output:
        0.981