Another simple math 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
preface
- 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 some specific 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 weather 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
Release history Release notifications | RSS feed
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.4.tar.gz
(9.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
wmath-0.0.4-py3-none-any.whl
(9.8 kB
view details)
File details
Details for the file wmath-0.0.4.tar.gz.
File metadata
- Download URL: wmath-0.0.4.tar.gz
- Upload date:
- Size: 9.1 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e508c245dd43c21eecc57df497291d7fb90792cab9f2e826e5ef1591132f31a7
|
|
| MD5 |
fe751edf3898c7a7c4340c76fba801c2
|
|
| BLAKE2b-256 |
8f88af4858de874702ea8e6a86ed9b7cc66443967f14c4502b51d6eaa355d3c2
|
File details
Details for the file wmath-0.0.4-py3-none-any.whl.
File metadata
- Download URL: wmath-0.0.4-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dacefc9ba36f97b073df3f3fbd0624bba3031ba0d6d8f7092a0ecdeaf0fee7e
|
|
| MD5 |
074480ec31d984c75810969f72baa5ef
|
|
| BLAKE2b-256 |
15a78a2a4e3ce4f87fd6f23dc454d18c5b280253253230e0e9275ef9230c03e9
|