A couple of problems.
1. Inside the if(), the first line modifies the value of x, then the second line uses the value of x (which has been modified already). So x, y, z are not updated synchronously. To work around this, assign the expressions to new variables (e.g. x1, y1, z1) and then add more lines afterward to assign x, y, z = x1, y1, z1. This ensures the histories are updated after all new values have been computed.
2. The expressions need extra parentheses around them to make sure that the whole result is scaled by dt, instead of just the last term.
So this GenExpr works for me: