← Back to challenges

Four Vectors Part 2: Multiplication and Lengthes

PythonHardphysicsmathclasses

Instructions

In this challenge, we extend the FourVector class we created in the first installment of the FourVector collection.

So, please add the following features to the class FourVector:

  • Support multiplication of Four Vectors (FV). This should include multiplication of two FVs as well as multiplications 'scalar times FV' and 'FV times scalar'. Think about magic methods like __mul__...
  • A method GetLength which returns the length of the FV. The length is the square root of the absolute value of the product of the FV with itself. Attention: contrasting to 'normal' vectors the product of a FV with itself may be negative! For details refer to the Wiki article.
  • A method GetCausalStructure. Let p the product of the FV with itself. The method then returns "lightlike" if p=0, "spacelike" if p<0 and "timelike" if p>0. The causal structure has an important meaning in special relativity: a lightlike FV can be connected to the origin (0, 0, 0, 0) by a ray a light, a timelike FV is connected to the origin by 'more time than space' which means there can be a causal connection (cause and effect) between the origin and the event represented by the FV. In contrast, for a spacelike FV there is 'more space than time' and there can't be a causal connection without violating the 'speed limit' of special relativity.

Examples

v1 = FourVector([1, 2, 3, 4])
v2 = FourVector([1, 0, 0, 1])
2 * v1 ➞ FourVector([2, 4, 6, 8])
v2 * 3 ➞ FourVector([3, 0, 0, 3])
v1 * v3 ➞ -3
v1.GetLength() ➞ 5.291502622129181
v1.GetCausalStructure() ➞ "spacelike"

Notes

Please save your FourVector class for later use, we will add new methods in upcoming challenges in this series!

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.