Skip to content

A python library which supports matrix, complex number, polynomial calculation.

License

Notifications You must be signed in to change notification settings

TsrmKumoko/Mathium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Mathium

Mathium is a python library which supports complex numbers, fractions, matrices, polynomials calculation.

Intro

There are 6 main classes in Mathium: Real, Complex, Matrix, Tensor, Fraction, Polynomial. They can be freely mixed up when you calculate a certain expression.

Basic operations like plus and times, derivation, determinant, etc. are supported.

Use the method display to view the output, which will be rendered by $\LaTeX$. Use the method LaTeX to get the LaTeX code of the output expression.

Main Methods in Classes

Operator Real Complex Matrix Tensor Fraction Polynomial
a + b
a - b
a * b
a / b
a ** b
a[n]
MathiumObject Real Complex Matrix Tensor Fraction Polynomial
sign(self)
LaTeX(self)
factors(self) Re(self)
Im(self)
conj(self)
norm(self)
I(int)
det(Matrix)
adjoint(Matrix)
inv(Matrix)
LineToCoor(self, idx)
PolyConv(ten0, ten1, map0, map1)
PolyPlus(ten0, ten1, map0, map1)
reduce(self)

Global Methods

Method Info
display(obj) Display an expression (MathiumObject) using $\LaTeX$.
D(obj, var) Calculate the derivative of obj.

Examples

Real

The Real class is used to unify the calculation, so it's not so meaningful to directly use it.

You can factorize a integer by using Real.factors():

>>> Real(36).factors()
[2, 2, 3, 3]

Complex

Give the real and imaginary part of a complex number to initialize a Complex object.

c = Complex(1, 1)
display(c * Complex(1, -2))

You can get a LaTeX object which should be viewed with Jupyter. That is:

$$ 3-\mathrm{i} $$

If you want to get the LaTeX code, do:

>>> LaTeX(Complex(1, 1))
'1-\\mathrm{i}'

Matrix

m1 = Matrix(
    [1, 2],
    [-1, Complex(1, 1)]
)
m2 = Matrix(
    [1, Complex(1, 1)],
    [3, Complex(1, -1)]
)
display(m1 * m2)

$$ \begin{bmatrix} 7 & 3-\mathrm{i} \\ 2+3\mathrm{i} & 1-\mathrm{i} \end{bmatrix} $$

Tensor

This class is temporarily made for Polynomial class. Using it directly is not suggested now because many features have not yet been implemented.

t = Tensor([
    [0, 1],
    [2, 3]
])
t[0][1]

$$ 1 $$

Fraction

Now float can be casted to fraction. Reduction is available and will be automatically done. Use auto_reduce = False to turn it off.

r1 = Fraction(0.128)
r2 = Fraction(25, 7)
display(r1 * r2)

$$ \frac{16}{35} $$

Polynomial

t = Polynomial([1, 1], 'w') / Polynomial([-1, 1], 'w')
display(D(t * t, 'w'))

f1 = Polynomial([
    [1, 1],
    [1, 1]
], ['x', 'y'])
f2 = Polynomial(
    [1, -1, 1],
    ['x']
)
display(f1 * f2)

$$ -\frac{4w^{2}-4}{w^{4}-4w^{3}+6w^{2}-4w+1} $$

$$ x^{3}y+x^{3}+y+1 $$

Future Version

There are a number of features undone which will be finished little by little. Updates will include:

  • Factorization in Polynomial class
  • Improved Matrix and Tensor class
  • Log / calculate step by step
  • Comments

About

A python library which supports matrix, complex number, polynomial calculation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published