Consider a sentence like
If $x \in \mathcal A$, then we define $f(x) = 0$.
Is it legetimate to replace "If" in that statement by "when", say, for the purpose of linguistic varietiy, such as in
When $x \in \mathcal A$, then we define $f(x) = 0$.
or is that considered bad style?
"If/then" is a common English construct, but "When/then" is not. When one uses "when," they shouldn't start the next clause with "then." (c.f. "If one uses "when," then they shouldn't start the next clause with "then.")
In most cases, the two formations ("if x then y" and "when x, y") are equivalent.