Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions physics/relativistic_velocity_summation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
c = 299792458
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An error occurred while parsing the file: physics/relativistic_velocity_summation.py

Traceback (most recent call last):
  File "/opt/render/project/src/algorithms_keeper/parser/python_parser.py", line 146, in parse
    reports = lint_file(
              ^^^^^^^^^^
libcst._exceptions.ParserSyntaxError: Syntax Error @ 1:1.
tokenizer error: unterminated string literal

c = 299792458
^


"""
The relativistic velocity summation formula calculates the combined velocity v2

Check failure on line 4 in physics/relativistic_velocity_summation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W291)

physics/relativistic_velocity_summation.py:4:80: W291 Trailing whitespace help: Remove trailing whitespace
of an object moving at speed v1 relative to a frame that is itself moving at velocity v

Check failure on line 5 in physics/relativistic_velocity_summation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W291)

physics/relativistic_velocity_summation.py:5:88: W291 Trailing whitespace help: Remove trailing whitespace
relative to an observer. I take the last one to be strictly lower than the speed of
light.
The formula is v2 = (v1 + v)/(1 + v1 * v / c^2)
"""

def relativistic_velocity_summation (v1: float, v: float) -> float:
"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide descriptive name for the parameter: v

>>> relativistic_velocity_summation(200000000, 200000000)
276805111.0636436
>>> relativistic_velocity_summation(299792458, 100000000)
299792458.0
>>> relativistic_velocity_summation(100000000, 299792458)
Traceback (most recent call last):
...
ValueError: Speeds must not exceed light speed, and the frame speed must be lower than the light speed!

Check failure on line 20 in physics/relativistic_velocity_summation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E501)

physics/relativistic_velocity_summation.py:20:89: E501 Line too long (107 > 88)
"""
if v1 > c or v >= c or v1 < -c or v <= -c:
raise ValueError("Speeds must not exceed light speed, and the frame speed must be lower than the light speed!")

Check failure on line 23 in physics/relativistic_velocity_summation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (E501)

physics/relativistic_velocity_summation.py:23:89: E501 Line too long (119 > 88)
return (v1 + v)/(1 + v1 * v / (c * c))

Check failure on line 24 in physics/relativistic_velocity_summation.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W291)

physics/relativistic_velocity_summation.py:24:43: W291 Trailing whitespace help: Remove trailing whitespace

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

testmod()
Loading