Text this: Optimal synthesis of the Fredkin gate in a multilevel system