Behrend's construction on large 3-AP-free set 
Theorem (Behrend's construction)
There exists a constant $C>0$ such that for every positive integer
$N$, there exists a $3$-AP-free $A\subseteq[N]$ with $|A|\geq
 Ne^{-C\sqrt{\log N}}$.
Proof. Let $m$ and $d$ be two positive integers depending on $N$ to be
specified later. Consider the lattice points of $X=\{1,\dots, m\}^d$
that lie on a sphere of radius $\sqrt{L}$: $$X_L:=\{(x_1,\dots,x_d)\in
 X: x_1^2+\dots+x_d^2=L\}.$$ Then $X=\bigsqcup\limits_{i=1}^{dm^2}
 X_i$. So by pigeonhole principle, there exists an $L\in [dm^2]$ such
that $|X_L|\geq m^d/(dm^2)$. Define the base $2m$ digital expansion
$$\phi(x_1,\dots,x_d):=\sum_{i=1}^{d}x_i(2m)^{i-1}.$$ Then $\phi$ is
injective on $X$. Furthermore, $x,y,z\in [m]^d$ satisfy $x+z=2y$ if
and only if $\phi(x)+\phi(z)=2\phi(y)$. Since $X_L$ is a subset of a
sphere, it is $3$-AP-free. Thus $\phi(X)\subseteq [(2m)]^d$ is a
$3$-AP-free set of size $\geq m^d/(dm^2)$. We can optimize the
parameters and take $m=\lfloor e^{\sqrt{\log N}}/2\rfloor$ and
$d=\lfloor \sqrt{\log N}\rfloor$, thereby producing a $3$-AP-free
subset of $[N]$ with of size $\geq Ne^{-C\sqrt{\log N}}$, where $C$ is
some absolute constant.

I understood the proof very well and I don't have any question regarding the proof. But I am little confused about paramaeters $m$ and $d$. Can anyone explain in detail why do we choose these parameters $m$ and $d$ in such a way? Namely $m=\lfloor e^{\sqrt{\log N}}/2\rfloor$ and $d=\lfloor \sqrt{\log N}\rfloor$. What is the idea beyond that choice?
EDIT: I think that the statement of theorem has a small mistake. If you take $N=2$, then $d=0$ but $d$ should be natural. I believe that this construction is true for sufficiently large $N$. Am I right?
 A: The proof as written is for sufficiently large $N$, yes, but the result trivially holds for small $N$ (if we choose $C$ suitably), so one gets the result for all $N$ 'for free'.
As for the choices of $m$ and $d$, we want to choose them to maximise (or at least approximately maximise) the quantity $1/2^ddm^2$ (since this is the density of your 3AP-free set), subject to the constraint that $N\approx(2m)^d$.
The $2^d$ term is much larger than the $d$ term, so we can ignore it (working heuristically), and just want to minimise $2^dm^2$. It's cleaner to take logs of everything, so (again working heuristically, so ignoring constants) we want to minimise $d+\log m$  subject to $d\log m\approx \log N$.
An elementary calculus exercise shows that minimising $x+y$ subject to $xy=C$ is achieved when $x=y=\sqrt{C}$, so we want $d\approx \log m\approx \sqrt{\log N}$.
This tells us that the choices of $d$ and $m$ you describe are at least approximately (up to only constant loss) the best possible choices.
