Programmable purification of type-I polarization-entanglement