Necessary and sufficient conditions on $as+b$ so that $f \circ f$ = $i_s$ I recently started my first course in abstract algebra and I came across the following problem:
Let $f: S \to S$, where $S$ is the set of all integers, be defined by $f(s) =
as + b$, where $a$, $b$ are integers. Find the necessary and sufficient conditions
on $a$, $b$ in order that $f \circ f = i_s$.
My understanding is that $i_s$ is the identity mapping such that $f(s) = s$ for all $s \in S$. Based on this, I think that I need to find conditions on $a,b$ such that $f(f(s)) = s$. I began trying to express $f \circ f$ as a single function and got that $(f \circ f)(s) = a(as + b) + b$. From here, it seems clear to me that if $a=1$ and $b=0$, $(f \circ f)(s) = s$ for all $s$. I thought there might be other conditions where this might be true, however, so I tried to do some algebra and this is what I got:
$$
a(as+b)+b=s\\
a^2s+ab+b=s\\
ab+b=s-a^2s\\
ab+b=s(1-a^2)\\
\frac{ab+b}{1-a^2} = s
$$
From this equation, it seems to me that $a^2$ cannot equal $1$, so $a=1$ cannot be a good choice, which contradicts the conclusion that seems to make sense. What is wrong with my thinking? Is it "necessary and sufficient" to say that $a=1,b=0$, or is there something more that I need to show? I was thinking that I might need to show that if $a \neq 1, b \neq 0$, then $f \circ f$ cannot be $i_s$, but I'm not sure.
 A: $\left[\forall s,s(a^2-1)+b(a+1)=0\right]$ is true iff $(a^2-1)=0$ and $b(a+1)=0$, which in turn admits the following solutions:


*

*$a=1$ and $b=0$

*$a=-1$ and $b$ is arbitrary

A: Note that you are trying to find out when $f \circ f = i_S$, which is an equality of functions. When are two functions equal? Two functions $S \to S$ are equal when they have the same value at each element in their domain.
You are correct that you end up with the equation $a^2s + ab+b \equiv s$, where we use $\equiv$ to mean an equality of functions. Therefore you need $a^2s+ab +b = s$ for all $s\in S$. Both $f\circ f$ and $i_S$ are affine functions, and we know that affine functions are equal if and only if they have the same slope and constant term.
What you actually have done in your calculation is to try to solve for $s$, but this is not what you want to be doing. You are actually solving for $a$ and $b$.
Hint: You get infinitely many such $f$.
The upside is that what you actually have shown is that if $a^2$ is anything else than $1$, then there is only one $s$ which makes the above equality true but it is supposed to be true for all $s \in S$, so you can conclude that $a^2 = 1$.
A: Note $f(0)=b\implies 0=f(f(0))=ab+b=(a+1)b$. So, either:


*

*$a = -1$. One can easily check that any such $f$ satisfies the desired equation. Or ...

*$b=0$. In this case, $f(x)=ax$ for some $a$.


*

*Note now that $f(1)=a \implies 1 = f(f(a)) = a^2$, so $a=\pm 1,$ i.e. your function is either $f(x)=x$ or $f(x)=-x$. It is even easier to show that these both satisfy the desired equation.



So, the set of all such functions is $\{f(x)=x\} \cup \{f(x) = b -x\text{ for some integer }b \}$.
