Skip to content

Integrate the squared jerk in closed form rather than sampling it - #1

Open
Eelis03 wants to merge 1 commit into
mainfrom
feat/exact-jerk-cost
Open

Integrate the squared jerk in closed form rather than sampling it#1
Eelis03 wants to merge 1 commit into
mainfrom
feat/exact-jerk-cost

Conversation

@Eelis03

@Eelis03 Eelis03 commented Aug 4, 2026

Copy link
Copy Markdown
Owner

The jerk cost was only ever a Simpson quadrature of a sampled trace, and the design notes recorded that as a known limitation with its own remedy: integrate the coefficient table segment by segment. On one segment the jerk of one joint is a polynomial, so its square is a polynomial too and the integral over that segment is a quadratic form in the jerk coefficients, which makes the objective exact for every trajectory this package produces. The S-curve of the README costs 240.0 analytically; the quadrature reported 240.3600 at 4001 samples and the integral reports 239.99999999999994 at any sample count, because it reads none.

  • PiecewisePolynomialTrajectory.jerk_cost sums the quadratic form over every segment and joint, and IntegrableTrajectory is the protocol that names the capability, alongside CertifiedTrajectory.
  • certify_jerk_cost is the analysis-layer entry point, next to certify_limits, and refuses with a TypeError that points at compute_metrics when the trajectory cannot be integrated.
  • TimeScaledTrajectory forwards by dividing by the fifth power of its scale and SynchronisedTrajectory by adding its components, both raising TypeError when what they wrap cannot answer.
  • tests/test_jerk_cost.py pins the value against a hand-computed integral, against 720 d^2 / T^5 and 400 * 4 * 0.15, against the quadrature at 4001, 40001 and 400001 samples, and against the claim that the natural quintic spline is the minimum-jerk interpolant of its via points. Opaque moves to conftest.py so both suites share it.
  • The design notes move the limitation into "Closed limitations" with what it cost and what remains; the README gains the exact figure beside the quadrature it explains, and its test count and statement count are updated.

Local gates: 218 tests pass, coverage 97.15 percent of 1230 statements against the 95 percent gate, ruff check . and mypy clean.

🤖 Generated with Claude Code

The jerk cost was a Simpson quadrature of a sampled trace, whose error falls
only as the reciprocal of the sample count when the integrand is discontinuous:
the S-curve of the README costs 240.0 analytically and the quadrature reported
240.3600 at 4001 samples. The design notes named the remedy and this is it.

On one segment the jerk of one joint is a polynomial, so its square is a
polynomial too and the integral over the segment is a quadratic form in the jerk
coefficients. PiecewisePolynomialTrajectory.jerk_cost sums that form over every
segment and joint, certify_jerk_cost is the analysis-layer entry point, and the
scaling and synchronisation wrappers forward it: scaling divides by the fifth
power of its factor, synchronisation adds its components. Both raise TypeError
when what they wrap cannot answer, as they already do for the peaks.

The same S-curve now reports 239.99999999999994 at any sample count, and the
time-optimal minimum-jerk move reports its closed form 720 d^2 / T^5 to fourteen
digits. Opaque moves to conftest so both tiers of the fallback path share it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant