A theory of optimal motor-sensory primitives