Minimal realization of machines in closed categories