It is not particularly useful to think of "free" versus "bound" as an absolute distinction where every variable is either one or the other.
Rather, "free" or "bound" is something a variable can be in relation to a certain amount of context. The classification is really a function of both the variable and how much context you're looking at, and if you switch to looking and a larger context, the variable might change from free to bound.
The real concept is not "$x$ is a free variable", but "$x$ is free in (some text or formula hat has the name $x$ in it)". Sometimes we omit stating what the context is, if we trust the reader can figure out which context we're talking about, but the technical concept is not complete without it.
For example, suppose we say:
Let $b=5$.
Does $x^2=b+3$ have a solution for $x$?
If we take the equation "$x^2=b+3$" as our context, both $x$ and $b$ are free in that context.
If the context is just the second line in the example, the $x$ in $x^2$ is now bound -- namely, the phrasing "solution for $x$" binds it in the sense of telling us what the point of that variable is. (It does not make sense to ask "does $x^2=b+3$ have a solution for $x$ if $x=2$?" because speaking about a "solution for $x$" assumes that $x$ we're free to vary the value of $x$ -- that is why "solution for $x$" binds the variable). But $b$ is still free when that line is our context.
When the entire example is our context, both variables in $x^2=b+3$ are bound.
Another way to say this is, the actual question is not whether a occurrence of a variable is bound, but where it is bound -- and in particular whether the binding happens within some particular context we're interested in.
Identities such as $(x+1)^2 = x^2 + 2x + 1$ are an interesting case.
Strictly speaking, the question "is $(x+1)^2$ the same number as $x^2+2x+1$?" does not get an answer before $x$ is a number such that we can compute the two sides and compare them. However, we do know that when we get an answer, that answer is sure to be "yes".
When we're doing actual calculations, the expectation is always that every variable will eventually be bound by something if we look far enough for context -- if nothing else, then the entire book we find the text in always comes with an implicit convention that every variable that is not bound explicitly can have an arbitrary value and what the book claims about those variables is supposed to be true no matter which actual value we give them. And that convention itself then counts as a binding for the variable. (In practice this convention almost always really applies to smaller pieces of text than an entire book: chapters, sections, individual proofs or paragraphs).
So given that we're expecting the $x$ in $(x+1)^2 = x^2 + 2x + 1$ is bound somewhere, that expectation is what allows us to rewrite the entire thing to "true" -- because it will be true when we view he rewriting in the broadest possible context.
x = c
) than "checking for equality" (oftenx == c
). – Joe Jun 30 '21 at 12:39