# Bound/free variables in $\sum_{k=1}^{10}f(k,n)$

I'm looking at this treatment of bound and free variables. Down a bit is this

$$\sum_{k=1}^{10}f(k,n)$$

but then the cryptic explanation

$$n$$ is a free variable and $$k$$ is a bound variable; consequently the value of this expression depends on the value of $$n$$, but there is nothing called $$k$$ on which it could depend.

Can anyone tell me what they're saying here? If $$f(k,n) = (k + n)$$, i.e.,

\begin{align} \sum_{k=1}^{3}(k+n) &= (1+n) + (2+n) + (3+n) \\ &= (1+2+3) + (n+n+n) \\ &= 6 + 3n \end{align}

It's obvious that $$n$$ is an unknown variable from elsewhere throughout summing over $$k$$, but I don't get the wording of the above quote.

• Yeah, that wording isn't the greatest. What is means is that $k$ is a placeholder, and restricted to a specific range, in this case $\{k \in \mathbb{N} \mid 1 \le k \le 10\}$. Essentially there's no value of $k$ given outside the expression itself, so $k$ only exists within the expression. Hence it's bound to the expression. Commented Jun 4, 2022 at 5:32
• I think this is an intuitive concept that's not often rigorously explained well until one has studied some basic formal logic and had to deal with the minutia of syntax with strings.
– Alex
Commented Jun 4, 2022 at 5:44
• @EricSnyder: I fully understand (mainly from programming) what is meant by a bound and free variable -- which is why this was so maddening. I think the "...on which it could depend" simply means the $k$ is not part of $n$'s definition, has no connection to $n$'s definition term. Commented Jun 4, 2022 at 15:15

It's obvious that $$n$$ is an unknown variable from elsewhere throughout summing over $$k$$, but I don't get the wording of the above quote.

That's it.

In the expression, $$n$$ is free to take on values from elsewhere. The expression is thus dependent on what value is assigned to $$n$$ there.

However, $$k$$ is bound to take the values designated by the series. The term following the series quantifier is to be evaluated for each value of $$k$$, and these values are then added together. Further, any $$k$$ referrenced inside this scope is only this bound variable, and not any mention of $$k$$ outside the expression.

In programming terminology, $$k$$ would be called a local variable or loop iterator, if that helps, while $$n$$ would be a global variable.

• Thanks for firming up what I already thought I knew. Long short: $k$ is just a local iterator that yes, contributes to the final answer, but is not in any way associated with $n$. Commented Jun 4, 2022 at 15:25

It seems quite confusing in this context because, as you've identified, $$f(k,n)$$ does depend on the first variable, which we seem to have represented by $$k$$. The distinction is, intuitively, that although the input associated to $$k$$ "matters", $$k$$ just encodes the directions "if we choose some $$n$$, then add $$f(1,n)$$, $$f(2,n)$$, and $$f(3,n)$$", that we represent by a sum that happens to use the variable $$k$$ for indexing. More precisely, it is being "quantified over", such that $$\sum^3_{k=1}f(k,n)$$ says "add $$f(k,n)$$, for all $$1\leq k \leq 3$$". We are not free to "choose a specific value for $$k$$", as $$k$$ is already bound, rather "assigned", to vary over the values $$k=1$$, $$k=2$$, and $$k=3$$.

Instead, imagine that we have another function, $$g:\mathbb{N}\rightarrow \mathbb{R}$$, defined such that $$g(n)=\sum^3_{k=1}f(k,n)$$. This gives our original operation but only depends on $$n$$. Note, if we chose instead $$g(n)=\sum^3_{m=1}f(m,n)$$, it would be the exact same operation, as the variable $$m$$ or $$k$$ is not important, as its directions are the same either way, "sum over all values $$m/k=1$$, $$m/k=2$$, and $$m/k=3$$".

Perhaps the distinction is easier to understand in a computer programming context.

def f(x, y):
return x + y

def sum_f(n):
return sum(f(k, n) for k in range(1, 11))


Within sum_f, n is a parameter passed to the function, but $$k$$ is just a local variable that has meaning only within the sequence being summed. Unless you're looking at the source code for sum_f, you'd have no idea what k is. Its name is just an implementation detail. You can say that it's bound to that one expression, whereas the caller is free to specify a value for n.

• Yes, this is your basic lexical binding lesson -- and it should be the go-to explanation. But the wording made me panic . . . that I was missing some deep hidden truth, when actually it was only what you're saying about local variables. Commented Jun 4, 2022 at 15:23

I fully understand (mainly from programming) what is meant by a bound and free variable -- which is why this was so maddening. I think the it "...on which it could depend" simply means the $$k$$ is not part of $$n$$'s definition, has no connection to $$n$$'s definition term, wherever it may be defined extra-summation. Hence, I'm overreacting. Alas, still working through math panic issues....

• I think it is anxiety inducing for many as they understand the concept informally, but it seems much ado about nothing when it is stressed formally. The common examples are always "obvious" in some way, but do not provide a rigorous enough classification to put thorough students at ease. As I commented above, I think that your intuition will carry you through any "ordinary/not overly formal use case". Further, if you do study formal proofs, you will be relieved to learn a more explicit and mechanical definition of free and bound variables in terms of quantifiers.
– Alex
Commented Jun 4, 2022 at 15:32