How to reverse this mathematical formula I am using the following function to compute a "Y" value from a Latitude
var LAT = latitude

// convert Lat to Radians
var latRad = LAT * Math.PI / 180;

var merc = Math.log(Math.tan((Math.PI / 4) + (latRad / 2)));

// compute to y value
var y = (8192 / 2) - (8192 * merc / (2 * Math.PI));

I need to be able to reverse this formula to compute the variable LAT only knowing the value for the variable y
 A: According to Wolfram Alpha, with $x=\text{LAT}$....

A: It's all a matter of doing things backwards. Let's start from your snippet:
var LAT = latitude

// convert Lat to Radians
var latRad = LAT * Math.PI / 180;

var merc = Math.log(Math.tan((Math.PI / 4) + (latRad / 2)));

// compute to y value
var y = (8192 / 2) - (8192 * merc / (2 * Math.PI));

Reverse the order of the lines:
// compute to y value
var y = (8192 / 2) - (8192 * merc / (2 * Math.PI));
var merc = Math.log(Math.tan((Math.PI / 4) + (latRad / 2)));
// convert Lat to Radians
var latRad = LAT * Math.PI / 180;

and peel things off gradually. Let's do the first line explicitly:
y = (8192 / 2) - (8192 * merc / (2 * Math.PI));

(8192 * merc / (2 * Math.PI)) = (8192 / 2) - y;
8192 * merc = ((8192 / 2) - y) * (2 * Math.PI);
var merc = ((8192 / 2) - y) * (2 * Math.PI) / 8192;

I'll skip the details for the second line, but you should end up with
var latRad = 2 * Math.atan(Math.exp(merc)) - Math.PI / 2

and finally,
var LAT = latrad * 180 / Math.PI;

thus:
var merc = ((8192 / 2) - y) * (2 * Math.PI) / 8192;
var latRad = 2 * Math.atan(Math.exp(merc)) - Math.PI / 2
var LAT = latrad * 180 / Math.PI;

Since $8192/2=4096$, your code could stand to be simplified a bit... ;)
