Confusion between “where” and “with”

When I am reading some articles related to engineering or mathematics, I see many times the usage of "where" and "with" interchangeably. For example,

• f is the utility function mapping from S to R, with S=blahblahblah.

• f is the utility function mapping from S to R, where S=blahblahblah.

• ~~~~~~~~~~~~~~~, where i != j.

• ~~~~~~~~~~~~~~~, with i != j.

Are both correct?

"With" and "where" are being used here as clauses. This is common in English, but in several fields such as mathematics, engineering and computer programming these are sometimes used in a non-grammatical way too. The examples you quote seem to make grammatical sense, but you should consider whether they have further meaning specific to your field of study, especially as they contain the equals symbol which suggests that they are not intended to be wholly grammatical but representative of some logic.

"With" literally means "accompanied by". So using the example of UK traffic lights:

The red light with the amber light indicates that the lights are about to change to green.

This groups the first two conditions together using "with" to show the conditions for the second part of the statement to be true.

The same thing could be expressed this way...

Where the red light is still lit, the amber light indicates that the lights are about to change to green.

...however there is a difference. This is saying that the amber light can indicate the subsequent statement to be true, but only where another condition exists, namely the red light still being lit. It allows for the possibility that the amber light could mean something else too where the red light is not lit.

In a mathematical context I think that there is a difference. In the "with" example, I would have expected to have seen S referred to earlier in the text, so that the word with would show that in the statement about f, S is taking the particular form blahblahblah. So we might have read earlier that S is a measurable set, and now find that in this case f is mapping from S to R with S convex.

In the "where" example, I would read that as introducing S for the first time in the text, defining what is meant by S (...where S = ...) so that S can be used later in the document.