Mathium is a python library which supports complex numbers, fractions, matrices, polynomials calculation.
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
to get the LaTeX code of the output expression.
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) |
Method | Info |
---|---|
display(obj) |
Display an expression (MathiumObject ) using |
D(obj, var) |
Calculate the derivative of obj . |
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]
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:
If you want to get the LaTeX code, do:
>>> LaTeX(Complex(1, 1))
'1-\\mathrm{i}'
m1 = Matrix(
[1, 2],
[-1, Complex(1, 1)]
)
m2 = Matrix(
[1, Complex(1, 1)],
[3, Complex(1, -1)]
)
display(m1 * m2)
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]
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)
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)
There are a number of features undone which will be finished little by little. Updates will include:
- Factorization in
Polynomial
class - Improved
Matrix
andTensor
class - Log / calculate step by step
- Comments