human
Complete this python program:
def doppler_optical(rest):
assistant
#Here is the Python program you requested.

    """Return the equivalency pairs for the optical convention for velocity.
    The optical convention for the relation between velocity and frequency is:
    :math:`V = c \frac{f_0 - f}{f  }  ;  f(V) = f_0 ( 1 + V/c )^{-1}`
    Parameters
    rest : `~astropy.units.Quantity`
    Any quantity supported by the standard spectral equivalencies
    (wavelength, energy, frequency, wave number).
    References
    `NRAO site defining the conventions <http://www.gb.nrao.edu/~fghigo/gbtdoc/doppler.html>`_
    Examples
    >>> import astropy.units as u
    >>> CO_restfreq = 115.27120*u.GHz  # rest frequency of 12 CO 1-0 in GHz
    >>> optical_CO_equiv = u.doppler_optical(CO_restfreq)
    >>> measured_freq = 115.2832*u.GHz
    >>> optical_velocity = measured_freq.to(u.km/u.s, equivalencies=optical_CO_equiv)
    >>> optical_velocity  # doctest: +FLOAT_CMP
    <Quantity -31.20584348799674 km / s>
    """
    assert_is_spectral_unit(rest)
    ckms = _si.c.to_value(u'km/s')
    def to_vel_freq(x):
        restfreq = rest.to_value(si.Hz, equivalencies=spectral())
        return ((ckms * (restfreq - x)) / x)
    def from_vel_freq(x):
        restfreq = rest.to_value(si.Hz, equivalencies=spectral())
        voverc = (x / ckms)
        return (restfreq / (1 + voverc))
    def to_vel_wav(x):
        restwav = rest.to_value(si.AA, spectral())
        return (ckms * ((x / restwav) - 1))
    def from_vel_wav(x):
        restwav = rest.to_value(si.AA, spectral())
        voverc = (x / ckms)
        return (restwav * (1 + voverc))
    def to_vel_en(x):
        resten = rest.to_value(si.eV, equivalencies=spectral())
        return ((ckms * (resten - x)) / x)
    def from_vel_en(x):
        resten = rest.to_value(si.eV, equivalencies=spectral())
        voverc = (x / ckms)
        return (resten / (1 + voverc))
    return [(si.Hz, (si.km / si.s), to_vel_freq, from_vel_freq), (si.AA, (si.km / si.s), to_vel_wav, from_vel_wav), (si.eV, (si.km / si.s), to_vel_en, from_vel_en)]