That's one extreme example, bringing the 2014 salary all the way down to $1 million.
You could also do something in between, e.g., making the 2014 salary $3 million; that would move $10mm to bonus over the five years ($2mm per year) and create a 2014 cap number of $8mm but reduce the future year cap numbers to $18mm rather than $18.4.
You could also convert both 2014 and 2015 salaries to signing bonus, in part to reduce the 2015 cap hit - but doing so increases the dead money if he is cut prior to 2018, and also increases the cap number in 2016-18. If you make his base salary $1 million in both 2014 and 2015 and convert the remainder ($12 million from 2014 and $12 million from 2015) to a signing bonus, then the prorated signing bonus for each of those five years is now $4.8 million. That makes the cap hit in both 2014 and 2014 $8.8 million, but $20.8 million for years 3 through 5 (2016-17-18).
As far as the math goes, it's a case of whatever you take away in salary in any one year gets added in as a signing bonus. The signing bonus is then spread out evenly over the life of the contract - in this case five years. In Miguel's example he removed $12,000,000 of 2014 salary; divide that by five (length of contract) and you have $2,400,000 per year in the signing bonus row to figure out the appropriate salary cap figure.
Also, as AJ pointed out, the current (top section) cap numbers should be $16mm (13 + 1.5 + 1.5) rather than 13.5mm assuming that he is traded for. If he is released and becomes a free agent then the old contract becomes null and void, and do not effect whatever new contract is signed.