A sufficient condition for a maximum is the concavity of the Hamiltonian evaluated at the solution, i.e. where formula_17 is the optimal control, and formula_18 is resulting optimal trajectory for the state variable. Alternatively, by a result due to Olvi L. Mangasarian, the necessary conditions are sufficient if the functions formula_14 and formula_34 are both concave in formula_10 and formula_6. A constrained optimization problem as the one stated above usually suggests a Lagrangian expression, specifically  where the formula_16 compare to the Lagrange multiplier in a static optimization problem but are now, as noted above, a function of time. Proceeding with a Legendre transformation, the last term on the right-hand side can be rewritten using integration by parts, such that which can be substituted back into the Lagrangian expression to give To derive the first-order conditions for an optimum, assume that the solution has been found and the Lagrangian is maximized. Then any change to formula_10 or formula_6 must cause the value of the Lagrangian to decline. Specifically, the total derivative of formula_43 obeys For this expression to equal zero necessitates the following optimization conditions: If both the initial value formula_46 and terminal value formula_47 are fixed, i.e. formula_48, no conditions on formula_49 and formula_50 are needed. If the terminal value is free, as is often the case, the additional condition formula_28 is necessary for optimality. The latter is called a transversality condition for a fixed horizon problem. It can be seen that the necessary conditions are identical to the ones stated above for the Hamiltonian. Thus the Hamiltonian can be understood as a device to generate the first-order necessary conditions. When the problem is formulated in discrete time, the Hamiltonian is defined as:  and the costate equations are  (Note that the discrete time Hamiltonian at time formula_54 involves the costate variable at time formula_55 This small detail is essential so that when we differentiate with respect to formula_56 we get a term involving formula_57 on the right hand side of the costate equations. Using a wrong convention here can lead to incorrect results, i.e. a costate equation which is not a backwards difference equation). From Pontryagin's maximum principle, special conditions for the Hamiltonian can be derived. When the final time formula_58 is fixed and the Hamiltonian does not depend explicitly on time formula_59, then: or if the terminal time is free, then: Further, if the terminal time tends to infinity, a transversality condition on the Hamiltonian applies.