class v3(list):
def __init__(self, x=0, y=0, z=0):
self += [x,y,z]
def __add__(self, other):
l = len(self)
o = len(other)
if l==3 and o==3:
addition = []
for i in range(l):
addition.append(other[i] + self[i])
return addition
else:
raise ValueError("Addition is Illegal!")
def __mul__(self, other):
l = len(self)
o = len(other)
if l==3 and o==3:
v = v3()
v[0] = self[1]*other[2] - self[2]*other[1]
v[1] = self[2]*other[0] - self[0]*other[2]
v[2] = self[0]*other[1] - self[1]*other[0]
return v
else:
raise ValueError("Inner Product is Illegal!")
def __matmul__(self, other):
l = len(self)
o = len(other)
if l==3 and o==3:
sum = 0
for i in range(l):
sum += other[i] * self[i]
return sum
else:
raise ValueError("Dot Product is Illegal!")
>>> v1 = v3(1,2,3)
>>> v2 = v3(9,8,7)
>>> v1+v2
[10, 10, 10]
>>> v2+v1
[10, 10, 10]
>>> v1*v2
[-10, 20, -10]
>>> v2*v1
[10, -20, 10]
>>> v1@v2
30
>>> v2@v1
30
More tools in mathematics can be introduced. For example, we can transfer every concept like Group, Ring, Field, etc. in Abstract Algebra. Also, we can build everything in Functional Analysis by using specific Structured Data.