We consider the problem of optimal entrainment of a spiking neuron to a periodic external stimulation using the mean absolute value of the stimulating current as a performance measure to be minimized. We denote this functional $\mathcal{J}^*$. The choice of such a performance measure is motivated by the desire to minimize the damage to neural tissue under stimulation. We refer to this problem as a minimum-current control problem. We take into account the clinically relevant charge-balance condition $(\int_0^T I(\omega t) dt = 0)$ and the amplitude limitation of the stimulating current $(I_- < I < I_+)$. Using phase reduction theory [1] and Pontryagin's maximum principle [2], we derived an algorithm for constructing the optimal waveform that provides the entrainment of a spiking neuron to the stimulating current with the conditions mentioned above.
The optimal waveform is of the bang-off-bang type:
$$I^*(\vartheta) = I_+ H[z(\vartheta) - z_2] + I_{\pm} H[z_1 - z(\vartheta)]. \tag{1}$$Here $I^*(\vartheta)$ is the optimal current, $H(\cdot)$ is the Heaviside step function, $z(\vartheta)$ is the phase response curve (PRC) and $\vartheta$ is the phase. The optimal current depends on the sign of the frequency mismatch $\Delta\omega$ between the natural frequency of the neuron and the external stimulation. The upper and the lower subscripts correspond, respectively, to $\Delta\omega > 0$ and $\Delta\omega < 0$. $z_1$ and $z_2$ ($z_1 < z_2$) are parameters determined from the equations
$$I_{\pm}M_{+}(z_{2}) + I_{\mp}M_{-}(z_{1}) = \Delta\omega,$$$$I_{\pm}N_{+}(z_{2}) + I_{\mp}N_{-}(z_{1}) = 0, \tag{3}$$where $M_{\pm}(\xi)$ and $N_{\pm}(\xi)$ are auxiliary functions. Then the value of the functional computed on the optimal trajectory (1) is
$$\mathcal{J}^* \equiv \mathcal{J}[I^*] = |I_{\pm}|N_{+}(z_2) + |I_{\mp}|N_{-}(z_1). \tag{4}$$Along with the minimization of tissue damage, the minimum-current control algorithm has another practical advantage. For small $\Delta\omega$, the minimum-current waveform does not require the knowledge of the whole PRC. On the contrary, it is determined only by the distance between the absolute extrema of the PRC and the PRC amplitude. It can thus be written as:
$$I^{*}(\vartheta) = I_{\pm} \Pi \left( \frac{\vartheta - \vartheta_{max}}{\Delta \vartheta_{+}} \right) + I_{\mp} \Pi \left( \frac{\vartheta - \vartheta_{min}}{\Delta \vartheta_{-}} \right), \tag{5}$$where $\Pi(x)$ is the rectangular function that satisfies $\Pi(x) = 1$ for $|x| < 1/2$ and $\Pi(x) = 0$ for $|x| > 1/2$, $\vartheta_{max}$ and $\vartheta_{min}$ are the extrema of the PRC and $\Delta\vartheta_+$ and $\Delta\vartheta_-$ are the respective widths of the positive and negative pulse.

In a real experiment, the parameters of the optimal bang-off-bang waveform can hopefully be estimated empirically, without recourse to the neuron model and phase reduction theory.