Why is this displacement not creating a perfectly square cube?
I would like to point out :

I think your math is off
You can get the length of a vector with a Vector Math node set to &quot;Length&quot;
The UV map vector Z coordinate is 0 (I think)

The resulting node tree would be :

But since the &quot;Displacement&quot; node pushes geometry along the normals, you can get rid of your UV map setup like so :