# Difference recurrrence in affine-gap alignment

$\begin{eqnarray} M(i,j) &=& \max \left[ \begin{array}{l} M(i-1,j-1) + s(a_i,b_j), \\ X(i-1,j-1) + s(a_i,b_j),\\ Y(i-1,j-1) + s(a_i,b_j), \end{array} \right. \hspace{0.5cm} X(i,j) &=& \max \left[ \begin{array}{l} M(i-1,j) – u – v, \\ X(i-1,j) – u,\\ \end{array} \right. \hspace{0.5cm} Y(i,j) &=& \max \left[ \begin{array}{l} M(i,j-1) – u – v, \\ Y(i,j-1) – u. \end{array} \right. \end{eqnarray} \tag{1}$
Let’s define the difference matrices for differential DP
$\begin{eqnarray} \Delta H(i,j) &=& M(i,j) – M(i-1,j) \\ \Delta V(i,j) &=& M(i,j) – M(i,j-1) \\ \Delta D(i,j) &=& M(i,j) – M(i-1,j-1) \\ \Delta X(i,j) &=& X(i,j) – M(i,j) \\ \Delta Y(i,j) &=& Y(i,j) – M(i,j) \end{eqnarray}$
Then the following recursive equations are derived from (1)
$\begin{eqnarray} \Delta D(i,j) &=& \max \left[ \begin{array}{l} s(a_i,b_j), \\ \Delta X(i-1,j-1) + s(a_i,b_j)\\ \Delta Y(i-1,j-1) + s(a_i,b_j) \end{array} \right.\\ \Delta H(i,j) &=& \Delta D(i,j) – \Delta V(i-1,j)\\ \Delta V(i,j) &=& \Delta D(i,j) – \Delta H(i,j-1)\\ \Delta X(i,j) &=& \max \left[ \begin{array}{l} -\Delta H(i,j) – u – v, \\ \Delta X(i-1,j) -\Delta H(i,j) – u. \end{array} \right.\\ \Delta X(i,j) &=& \max \left[ \begin{array}{l} -\Delta V(i,j) -u – v, \\ \Delta Y(i,j-1) -\Delta V(i,j) – u. \end{array} \right. \end{eqnarray} \tag{2}$