This is about the one thing where SQL is a badly designed language, and you should use a frontend that forces you to write your queries in the order (table, filter, columns) for consistency.
UPDATE table_name WHERE y = $3 SET w = $1, x = $2, z = $4 RETURNING *
FROM table_name SELECT w, x, y, z
Related, note that division is much slower than multiplication.
Instead of:
see if you can refactor it to:
where that inverse can then be hoisted out of loops.