Code Monkey home page Code Monkey logo

math-lib's Introduction

Mathematics Library

Home-made Mathematics library using the Python programming language. It will emulate the math - Mathematical functions library in Python, although it will be a much less complete version.

The math library will be rudimentary but fully functional, including all elementary arithmetic operations (i.e., addition, subtraction, multiplication, and division) and some more advanced topics (i.e., exponents and logarithms) and two special functions (absolute value and division and modulus operation).

LIMITATION

The only limitation is that only the Python + and - operators are allowed to be utilized. Every other function MUST use these. That is, no operational code is allowed to use 3rd party libraries or the operators exceptions + and -.

$$3 * 3 = 3 + 3 + 3$$ $$-3 * 3 = -3 + -3 + -3 = -3 - 3 - 3$$

For example

The mult function uses the fact that multiplication is a series of additions or subtractions in compute the multiplication of two numbers. So 3 * 2 is

sum = 0
for _ in range(2):
    sum = sum + 3
Operation Python Code
$$3 * 2$$ sum = 0; for _ in range(2): sum = sum + 3
$$-3 * 2$$ sum = 0; for _ in range(2): sum = sum - 3

Once created, the math_lib will have the ability do multiplications.

mult(3, 2)

Library Functions

  1. Elementary Operations
    1. Addition (add, +)
    2. Subtraction (sub, -)
    3. Multiplication (mult)
    4. Division (div)
  2. Advanced Functions
    1. Square Root (sqrt)
    2. Exponentiation (exp)
    3. Logarithm (log)
  3. Special Functions
    1. Absolute Value (abs)
    2. Division and Modulus (divmod)

Elementary Operations

  1. Addition (add, +)
  2. Subtraction (sub, -)
  3. Multiplication (mult) ** 2
  4. Division (div)

Note

Only the Python + and - operators are allowed to be utilized in this library.

add

This is a binary function that takes in two numbers (augend and addend) and returns the sum of two numbers.

def add(augend: float, addend: float) -> float:
    """Addition function.

    Args:
        augend (float): The augend of the addition.
        addend (float): The addend of the addition.

    Returns:
        float: The sum of augend and addend.
    """
    return augend + addend

sub

This is a binary function that takes in two numbers (minuend and subtrahend) and returns the difference of two numbers.

def sub(minuend: float, subtrahend: float) -> float:
    """Subtraction function.

    Args:
        minuend (float): The number being subtracted from.
        subtrahend (float): The number being subtracted from another.

    Returns:
        float: The difference of minuend and subtrahend.
    """
    return minuend - subtrahend

mult

This is a binary function that takes in two numbers (multiplier and multiplicand) and returns the product of the two numbers.

def mult(multiplier: float, multiplicand: float) -> float:
    """Multiplication function.

    Args:
        multiplier (float): Multiplier.
        multiplicand (float): Multiplicand.

    Returns:
        float: Product of multiplier and multiplicand.
    """
    value = range(multiplicand)
    func = add
    if multiplicand < 0:
        value = range(0, multiplicand, -1)
        func = sub

    sum = 0
    for _ in value:
        sum = func(sum, multiplier)

    return sum

Advanced Functions

  1. Square Root (sqrt)
  2. Exponentiation (exp) ** 4
  3. Logarithm (log)

Special Function

  1. Absolute Value (abs) ** 1
  2. Division and Modulus (divmod) ** 3

abs

This function returns the absolute value of a number.

def abs(number: float) -> float:
    """Absolute function.

    Args:
        number (float): Real number.

    Returns:
        float: Absolute value of number.
    """
    if number < 0:
        number = -1 * number

    return number

math-lib's People

Contributors

arianna1o avatar codenamejupiterx avatar knwachuk avatar

Watchers

 avatar  avatar  avatar

math-lib's Issues

`exp`

Exponential Function (exp)

The exp(#11) function is being implemented by @dsilva743.

Contribution

Contribution

Please note that we don't have a CONTRIBUTION.md file, but the below list summarizes the restrictions on satisfactory contribution:

  1. Use black for code formatting
  2. The docstring style is Google Style Python Docstring
  3. Use GitHub Flow for our workflow meaning that every change should be encapsulated in a branch before it is merged into main (and this includes me)
  4. Use Flake8 for style guide enforcement (this should really be automated)
  5. All feature implementation should have an accompanying test (see image below)

Test Driven Development PM

Working on a Task

You can make a fork and a pull request! We are glad to have you participate! If you have a function you want to work on, we can convert that task into an issue so that everyone knows someone is already working on that function.

Note that multiple people can work on the same function and this is a collaborative environment and we encourage this level of participation!

`divmod`

Division and Modulus Function (divmod)

The divmod function is being implemented by @HoldW.

Mathematics Library Functionality

Mathematics Library

Home-made Mathematics library using the Python programming language. It will emulate the math - Mathematical functions library in Python, although it will be a much less complete version.

The math library will be rudimentary but fully functional, including all elementary arithmetic operations (i.e., addition, subtraction, multiplication, and division) and some more advanced topics (i.e., exponents and logarithms) and two special functions (absolute value and division and modulus operation).

LIMITATION

The only limitation is that only the Python + and - operators are allowed to be utilized. Every other function MUST use these. That is, no operational code is allowed to use 3rd party libraries or the operators exceptions + and -.

For example

$$3 * 3 = 3 + 3 + 3$$ $$-3 * 3 = -3 + -3 + -3 = -3 - 3 - 3$$

The mult function uses the fact that multiplication is a series of additions or subtractions to compute the multiplication of two numbers. So 3 * 2 is

sum = 0
for _ in range(2):
    sum = sum + 3
Operation Python Code
$$3 * 2$$ sum = 0; for _ in range(2): sum = sum + 3
$$-3 * 2$$ sum = 0; for _ in range(2): sum = sum - 3

Once created, the math_lib will have the ability do multiplications.

def mult(a, b):
    sum = 0
    for _ in range(b):
        sum = sum + a

mult(3, 2)

Function Completion Matrix

math_lib Function Completion PR Creator
add #3 @Arianna1o
sub #4 @codenamejupiterx
mult #6 @knwachuk
exp WIP @dsilva743
divmod WIP @HoldW

Completion State

Elementary Operations

  • add
  • sub
  • mult
  • div

Advanced Functions

Special Functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.