Vector math nodes in Blender 2.82 simplifies this node tree. Using vector math nodes for the modulus, absolute value, subtraction, and scaling accomplishes these tasks with one node. The rotation of the second gradient can be accomplished by the cross product function. The product is with (0, 1, -1).