from typing import Sequence
from typing import Tuple


def hamilton_product(quat1: Sequence[float], quat2: Sequence[float]) -> Tuple[float,float,float,float]:
	"""
	Perform the mathematical "hamilton product", effectively adds two quaternions. However the order of the inputs does matter.
	Returns the equivalent of rotation quat2 followed by rotation quat1.
	Result is another quaternion.
	
	:param quat1: 4x float, W X Y Z quaternion
	:param quat2: 4x float, W X Y Z quaternion
	:return: 4x float, W X Y Z quaternion
	"""
	# thank you stackexchange and thank you wikipedia
	(a1, b1, c1, d1) = quat1
	(a2, b2, c2, d2) = quat2
	
	a3 = (a1 * a2) - (b1 * b2) - (c1 * c2) - (d1 * d2)
	b3 = (a1 * b2) + (b1 * a2) + (c1 * d2) - (d1 * c2)
	c3 = (a1 * c2) - (b1 * d2) + (c1 * a2) + (d1 * b2)
	d3 = (a1 * d2) + (b1 * c2) - (c1 * b2) + (d1 * a2)
	
	return a3, b3, c3, d3