My textbook attempts to take the big O of $\log(x^2 +1)$. It proceeds by saying $x^2 + 1 \le 2x^2$ when $x \ge 1$. But I don't know how it came up with this idea.
Question:
Why set $x^2+1$ to a random value to be $2x^2$? Why $2$ of all numbers? Why not $x^2$ or $x^3$?
We’re not setting $x^2+1$ to anything. We want to find an upper bound on $\log(x^2+1)$ that can be expressed as a fairly simple function of $x$. Provided that $x\ge 1$, we know that $x^2+1\le 2x^2$, so $\log(x^2+1)\le\log(2x^2)$, and $\log(2x^2)$ can be expressed as a simple function of $\log x$:
$$\log(2x^2)=\log 2+2\log x\;.$$
If $x\ge 2$, we know that $\log x\ge\log 2$, and therefore
$$\log(x^2+1)\le\log 2+2\log x\le 3\log x\;.$$
This is exactly the kind of thing that’s needed in order for us to conclude that $\log(x^2+1)$ is $O(\log x)$: we have constants $M$ and $c>0$ such that
$$\log(x^2+1)\le c\log x$$
for all $x\ge M$. Specifically, we can use $M=2$ and $c=3$.
We couldn’t have used $x^2$, because $x^2+1$ isn’t less than or equal to $x^2$. We could have used $x^3$: $x^2+1\le x^3$ for $x\ge 2$, say, so
$$\log(x^2+1)\le\log x^3=3\log x$$
for $x\ge 2$, and again we’ve shown that $\log(x^2+1)$ is $O(\log x)$.
We could have used $5x^2$: $x^2+1\le 5x^2$ for $x\ge 1$, so
$$\log(x^2+1)\le\log(5x^2)=\log 5+2\log x\;.$$
And $\log 5+2\log x\le3\log x$ for $x\ge 5$, so $\log(x^2+1)\le3\log x$ for $x\ge 5$, and again we’ve shown that $\log(x^2+1)$ is in $O(\log x)$.