Semidefinite Representations in Semialgebraic Optimization and Dynamics-Oriented Learning