Skip to main content

Another simple mathematical package in the world

Project description

introduce

'wmath' is a simple mathematical package by a bored undergraduate who wants to review math and python at the same time.

It contains the following modules:

  • meta.py------introducing meta values
  • number_theory.py------handling number theory problems in math
  • fraction.py------the operation in fraction
  • polynomial.py------the related problems in rational polynomial

reference as below:

reference

functions defined in this library almost wouldn't change the value of pointer parameter

meta.py

PI

(const float)
3.141592653589793

E

(const float)
2.718281828459045

Meta

(class Enum)
define some common value in math.
    ERROR = "error"
    INFINITY = "infinity"
    INFINITESIMAL = "infinitesimal"
    Q = "all real numbers"
    Z = "all integers"
    N = "all natural numbers"
    N_positive = "all positive natural numbers"

number_theory.py

is_prime(x: int)

(function)
judge weather x is a prime.
if x <= 1, then return False. 
    :param x: (int)
    :return: (bool) True if x is a prime, while False if not

find_prime_until(x: int)

(function)
return all prime below int x.
    :param x: (int) x > 1
    :return: (list) all prime below int x

prime_factor_without_exp(x: int)

(function)
calc all prime factors of int x.
if x is zero or one, then return [].
if x < 0, then return the result of -x.
    :param x: (int)
    :return: (list) all prime factors of int x

prime_factor_with_exp(x: int)

(function)
calc all prime factors of int x.
if x is zero or one, then return {}.
if x < 0, then return the result of -x. 
    :param x: (int) x > 0
    :return: (dict) all prime factors as keys with each exp as value of int x

factor(x: int)

calc all factors of int x.
if x is zero, then return [].
if x < 0, then return the result of -x.
    :param x: (int)
    :return: (list) all factors of int x

greatest_common_divisor(a: int, b: int)

(function)
calc the greatest common divisor between a and b.
    :param a: (int)
    :param b: (int)
    :return: (int) the greatest common divisor between a and b

greatest_common_divisor_in_list(a: list)

calc the greatest common divisor among items in a.
    :param a: (list) integer
    :return: (int) the greatest common divisor

least_common_multiple(a: int, b: int)

calc the least common multiple between a and b.
    :param a: (int)
    :param b: (int)
    :return: (int) the least common multiple between a and b

least_common_multiple_in_list(a: list)

calc the least common multiple among items in a.
    :param a: (list) integer
    :return: (int) the least common multiple

greatest_common_divisor_with_exp(a: int, b: int)

(function)
calc the greatest common divisor between a and b, and find two numbers x, y to fit formula:
a * x + b * y = the greatest common divisor.
    :param a: (int)
    :param b: (int)
    :return: (tuple) the greatest common divisor, x, y

inverse(a: int, n: int)

calc the inverse of a in the case of module n, where a and n must be mutually prime.
a * x = 1 (mod n)
    :param a: (int)
    :param n: (int)
    :return: (int) x

fraction.py

Fraction

(class)
define the class of fraction in math and operation among them.
    __init__(self, molecule: int, denominator: int)
    __getattr__(self, item)
    __setattr__(self, key, value)
    __str__(self)
    __float__(self)
    __invert__(self)
    __pos__(self)
    __neg__(self)
    __abs__(self)
    __eq__(self, other)
    __add__(self, other)
    __sub__(self, other)
    __mul__(self, other)
    __truediv__(self, other)
    __pow__(self, power: int, modulo=None)
  • formula(self)
    :return: (string) the formula form string of the fraction 

number2fraction(x)

(function)
convert real number into fraction.
    :param x: (bool | int | float)
    :return: (Fraction) the fraction form of x

list2fraction(x: list)

(function)
convert list of real numbers into list of fractions. 
    :param x: (list of real numbers)
    :return: (list of fractions)

polynomial.py

Polynomial

(class)
define the class of polynomial and related operations among them.
    __init__(self, coefficient: list)
    __getattr__(self, item)
    __setattr__(self, key, value)
    __str__(self)
    __pos__(self)
    __neg__(self)
    __eq__(self)
    __add__(self, other)
    __sub__(self, other)
    __mul__(self, other)
    __truediv__(self, other)
    __floordiv__(self, other)
    __mod__(self, other)
    __pow__(self, power: int, modulo=None)
  • value(self, x: Fraction)
calc the value of the corresponding polynomial function where x is designated.
    :param x: (Fraction) independent variable
    :return: (Fraction) value
  • adjust(self)
manually adjust the polynomial after you changed the value 'in' the coefficient, 
while didn't fire the __setattr__() function since the coefficient is a pointer.
    :return: (Polynomial) self after adjust
  • monic(self)
make the polynomial monic.
pay attention! this function would influence the self polynomial.
    :return: (Polynomial) self after monic
  • primitive(self)
make the polynomial primitive.
pay attention! this function would influence the self polynomial.
    :return: (Polynomial) self after primitive
  • times(self, n: fraction.Fraction, degree: int = 0)
a new polynomial whose value is self * (n)x**(degree)
    :param n: (Fraction)
    :param degree: (int)
    :return: (Polynomial) the new polynomial
  • rational_roots(self)
calc all rational roots in the corresponding polynomial function.
    :return: (list of Fraction) all rational roots
  • formula(self)
    :return: (string) the formula form string of the fraction
  • is_irreducible_according_eisenstein(self):
judge whether the polynomial is irreducible according eisenstein discriminant method.
    :return: (bool) True for irreducible, and False for unclear rather than reducible

greatest_common_divisor_in_polynomial(a: Polynomial, b: Polynomial)

this function can figure out the greatest common divisor between a and b.
the result polynomial is monic.
(this function wouldn't influence the origin value of a or b although it looks like dangerous!
this characteristic is decided by python, i have no idea. ^_^)
    :param a: (Polynomial)
    :param b: (Polynomial)
    :return: (Polynomial)

greatest_common_divisor_with_exp_in_polynomial(a: Polynomial, b: Polynomial)

calc the greatest common divisor between a and b, and find two polynomials x, y to fit formula:
a * x + b * y = the greatest common divisor.
    :param a: (Polynomial)
    :param b: (Polynomial)
    :return: (tuple) the greatest common divisor, x, y

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

wmath-0.0.5.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

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

wmath-0.0.5-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file wmath-0.0.5.tar.gz.

File metadata

  • Download URL: wmath-0.0.5.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.6.4 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.7

File hashes

Hashes for wmath-0.0.5.tar.gz
Algorithm Hash digest
SHA256 97a63ee81b77c489a18431fa4d2598c5ba9dc847c445548f3c2340edf2a1e4c5
MD5 b9253a262b8b8bd17877e0d0b57787c3
BLAKE2b-256 cd7c94f3a4d3e6ab2858919f66f20fec2f5b62f14dacd2316cb62df882336189

See more details on using hashes here.

File details

Details for the file wmath-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: wmath-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.6.4 pkginfo/1.8.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.7

File hashes

Hashes for wmath-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 85fef1d7daa6fdefa5157732d6e7de87877e6ef581b52fc7a51c9ad74a5b43ec
MD5 bf2aa59b9dfee9251bebdc6f131c08f2
BLAKE2b-256 c0f6159a47a8ed22ad6c0fa28a338c101caa75862607c2539f93566b7d346505

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