Abstract Vector Space

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值