Skip to content

Commit 291588c

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 6b973f9 commit 291588c

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

physics/relativistic_velocity_summation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
c = 299792458
22

33
"""
4-
The relativistic velocity summation formula calculates the combined velocity v2
5-
of an object moving at speed v1 relative to a frame that is itself moving at velocity v
4+
The relativistic velocity summation formula calculates the combined velocity v2
5+
of an object moving at speed v1 relative to a frame that is itself moving at velocity v
66
relative to an observer. I take the last one to be strictly lower than the speed of
77
light.
88
The formula is v2 = (v1 + v)/(1 + v1 * v / c^2)
99
"""
1010

11-
def relativistic_velocity_summation (v1: float, v: float) -> float:
11+
12+
def relativistic_velocity_summation(v1: float, v: float) -> float:
1213
"""
1314
>>> relativistic_velocity_summation(200000000, 200000000)
1415
276805111.0636436
@@ -20,8 +21,11 @@ def relativistic_velocity_summation (v1: float, v: float) -> float:
2021
ValueError: Speeds must not exceed light speed, and the frame speed must be lower than the light speed!
2122
"""
2223
if v1 > c or v >= c or v1 < -c or v <= -c:
23-
raise ValueError("Speeds must not exceed light speed, and the frame speed must be lower than the light speed!")
24-
return (v1 + v)/(1 + v1 * v / (c * c))
24+
raise ValueError(
25+
"Speeds must not exceed light speed, and the frame speed must be lower than the light speed!"
26+
)
27+
return (v1 + v) / (1 + v1 * v / (c * c))
28+
2529

2630
if __name__ == "__main__":
2731
from doctest import testmod

0 commit comments

Comments
 (0)