Mathematics - Augustin007/usefulpy GitHub Wiki

Usefulpy Mathematics

At Usefulpy's core is... a lot of math.

Who knew? - oh wait, I guess anyone who knows either me (a math enthusiast) or anything about programming (which is mostly math), would know.

I take that back, programming is not mostly about math, it's mostly about spending hours doing nothing but going mad about a bug that will simply not get fixed only to realize it's a tiny insignificant detail you hadn't been bothered to think about.

Mathematics hundreds of mathematical constants

Quaternions

This math section includes a quaternion system, almost fully outfitted with adding, subtracting, exponentiating, trigonometric, and logarithmic functions.

>>> from usefulpy.mathematics import quaternion
>>>

Quaternion takes four arguments, (a, b, c, and d) which default to zero, these can be integers, floats, complex numbers, or even more quaternions, it takes the form a+bi+cj+dk and expands it if a non-real number is an argument. (for example quaternion(1+1j, 2, 0, 3) returns 1+2i+1j+3k)

Supports addition, subtraction, multiplication, and exponentiation between quaternions.

Division can only be done between a real and a quaternion. A complex or quaternion divided by a quaternion (or quaternion divided by a complex or another quaternion) will cause an error, this is to prevent bugs due to the non-commutativity of quaternion multiplication, division must be done as multiplying the inverse.

Quick explanation in quaternions, pq != qp, at least, not necessarily, sometimes it does, sometimes it doesn't. More importantly pq(p^-1) != q but (p^-1)pq = q. Essentially, I can't tell which 'side' you're dividing off of.

Basenum

Basenum stores a string representing a number in a base system, and can perform a full range of functions with the number.

>>> from usefulpy.mathematics import basenum
>>> x = basenum('3a2', 16)
>>> x
3a2₁₆
>>> y=x/2
>>> y
1d1₁₆
>>> float(x)
930.0
>>> int(y)
465
>>> y/2
e8.8₁₆
>>> x+y/2
48a.8₁₆
>>> float(_)
1162.5
>>> x.convert(2) # can convert to other base systems
1110100010₂
>>>