"""Velocity-based 1RM: estimates the one-rep max from the load and the mean concentric velocity of one rep, by the published group load-velocity equations for the full back squat (Sanchez-Medina et al. 2017, eq. 2) and the bench press (Gonzalez-Badillo and Sanchez-Medina 2010, MV equation). Inputs: bar_speed_m_per_s (mean concentric velocity, 0.05 to 2, default 0.5; refused where the equation gives a load outside the range the paper fitted: 40 to 100% of 1RM for the squat, about 0.323 to 1.228 m/s, and 30 to 100% for the bench, about 0.175 to 1.251 m/s), weight_kg (1 to 500, default 100), lift_type (squat or bench, default squat). Returns: predictedPctOf1Rm (percent), estimated1Rm (kg), ci95Low, ci95High (kg: the load over the percentage plus and minus 2 standard errors of the estimate, the low end at most 100%). mysi, Velocity-based 1RM, mysi.dev/velocity-based-1rm, version 1, changed 2026-12-04. MIT. """ import math def _velocity_based_1rm_num(name, value, low, high): if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high: raise ValueError(f"{name} must be a number from {low} to {high}") return float(value) def _velocity_based_1rm_speed(a, b, c, pct): # the speed at which a v^2 + b v + c equals pct, on the falling branch of the curve return (-b - math.sqrt(b * b - 4 * a * (c - pct))) / (2 * a) def velocity_based_1rm(bar_speed_m_per_s=0.5, weight_kg=100, lift_type="squat"): if lift_type not in ("squat", "bench"): raise ValueError("lift_type must be one of: squat, bench") v = _velocity_based_1rm_num("bar_speed_m_per_s", bar_speed_m_per_s, 0.05, 2) load = _velocity_based_1rm_num("weight_kg", weight_kg, 1, 500) if lift_type == "squat": # Sanchez-Medina et al. 2017, eq. 2 on MV: R2 0.948, SEE 4.31%, a, b, c, see, lowest = -12.87, -46.31, 116.3, 4.31, 40 # fitted on 40 to 100% 1RM else: # Gonzalez-Badillo and Sanchez-Medina 2010, eq. on MV: R2 0.979, SEE 3.77%, a, b, c, see, lowest = 7.5786, -75.865, 113.02, 3.77, 30 # fitted on 30 to 100% 1RM pct = a * v * v + b * v + c # range: pct +/- 2 SEE, the normal approximation (1.96 rounded) for ~95%; a convention, the # papers give only the SEE if not lowest <= pct <= 100: fast = _velocity_based_1rm_speed(a, b, c, lowest) slow = _velocity_based_1rm_speed(a, b, c, 100) raise ValueError(f"bar_speed_m_per_s must be from {slow:.3f} to {fast:.3f} m/s for " f"{lift_type}: the equation was fitted on {lowest} to 100% of 1RM") return {"predictedPctOf1Rm": pct, "estimated1Rm": load / (pct / 100), "ci95Low": load / (min(100.0, pct + 2 * see) / 100), "ci95High": load / ((pct - 2 * see) / 100)} VELOCITY_BASED_1RM_CASES = [ ({"bar_speed_m_per_s": 0.62, "weight_kg": 140, "lift_type": "squat"}, {"predictedPctOf1Rm": 82.6406, "estimated1Rm": 169.408, "ci95Low": 153.407}), ({"bar_speed_m_per_s": 0.38, "weight_kg": 85, "lift_type": "bench"}, {"predictedPctOf1Rm": 85.2856, "estimated1Rm": 99.6651, "ci95Low": 91.5695}), ({"bar_speed_m_per_s": 1.0, "weight_kg": 60, "lift_type": "squat"}, {"predictedPctOf1Rm": 57.12, "estimated1Rm": 105.042}), ] def velocity_based_1rm_check(tolerance=1e-3): for given, want in VELOCITY_BASED_1RM_CASES: got = velocity_based_1rm(**given) for name, value in want.items(): close = abs(got[name] - value) <= tolerance * max(1, abs(value)) assert close, (name, got[name], value) return "ok" if __name__ == "__main__": import json, sys velocity_based_1rm_check() given = dict(a.split("=", 1) for a in sys.argv[1:] if "=" in a) js = lambda v: v.lstrip("-")[:1].isdigit() or v[:1] in '[{".' or v in ("true", "false", "null") given = {k: json.loads(v) if js(v) else v for k, v in given.items()} if given: print(json.dumps(velocity_based_1rm(**given)))