{"record":{"id":"0eede68e7b46fb33","repo":"TheAlgorithms/Python","slug":"speed-must-be-greater-than-or-equal-to-1","errorCode":null,"errorMessage":"Speed must be greater than or equal to 1!","messagePattern":"Speed must be greater than or equal to 1!","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/lorentz_transformation_four_vector.py","lineNumber":59,"sourceCode":"def beta(velocity: float) -> float:\n    \"\"\"\n    Calculates β = v/c, the given velocity as a fraction of c\n    >>> beta(c)\n    1.0\n    >>> beta(199792458)\n    0.666435904801848\n    >>> beta(1e5)\n    0.00033356409519815205\n    >>> beta(0.2)\n    Traceback (most recent call last):\n      ...\n    ValueError: Speed must be greater than or equal to 1!\n    \"\"\"\n    if velocity > c:\n        raise ValueError(\"Speed must not exceed light speed 299,792,458 [m/s]!\")\n    elif velocity < 1:\n        # Usually the speed should be much higher than 1 (c order of magnitude)\n        raise ValueError(\"Speed must be greater than or equal to 1!\")\n\n    return velocity / c\n\n\ndef gamma(velocity: float) -> float:\n    \"\"\"\n    Calculate the Lorentz factor y = 1 / √(1 - v²/c²) for a given velocity\n    >>> gamma(4)\n    1.0000000000000002\n    >>> gamma(1e5)\n    1.0000000556325075\n    >>> gamma(3e7)\n    1.005044845777813\n    >>> gamma(2.8e8)\n    2.7985595722318277\n    >>> gamma(299792451)\n    4627.49902669495\n    >>> gamma(0.3)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/lorentz_transformation_four_vector.py#L41-L77","documentation":"Raised by beta(velocity) when velocity < 1 (m/s). This is not a physical limit but a practical floor: the comment notes speeds should be of order c for the transformation to be meaningful, so sub-1 m/s inputs are treated as likely unit errors. Combined with the upper guard, valid input is the window [1, 299792458] m/s.","triggerScenarios":"beta(0.2) from the doctest — almost always a velocity passed in units of c (0.2c) or km/s instead of m/s. beta(0) for a rest frame is also rejected.","commonSituations":"Natural-unit confusion (passing beta instead of v); passing velocities in km/h or mph (all < 3e5-ish, most < 1 only for very slow objects — walking speed 1.4 m/s passes, 0.5 m/s fails); testing with 0.","solutions":["Convert to m/s: multiply fractions-of-c by 299792458, km/s by 1000, mph by 0.44704.","If you genuinely need v < 1 m/s, compute beta manually as v/299792458 instead of using this helper.","Validate 1 <= velocity <= 299792458 before calling."],"exampleFix":"# before\nbeta(0.2)  # ValueError: speed is 0.2 m/s, not 0.2c\n\n# after\nbeta(0.2 * 299_792_458)  # 0.2c expressed in m/s","handlingStrategy":"validation","validationCode":"C = 299_792_458.0\nv_mps = velocity_in_c_units * C  # if input is in units of c\nassert 1.0 <= v_mps <= C, f'v must be within [1, {C}] m/s'\nbeta(v_mps)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["beta() expects m/s in [1, 299792458]; values < 1 are usually unit errors (0.2c passed as 0.2).","If you need v < 1 m/s, compute v / 299792458 yourself.","Name variables with units (velocity_mps) to prevent natural-unit mixups."],"tags":["physics","relativity","units","range-check","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}