Solution (source code)

= Solution

Choose the <Hopf map> $\eta$ and orientations so its <Hopf invariant> is one. The <cellular cohomology> of $Y_d$ is $\mathbb Z$ in degrees $0,2,4$ and zero otherwise. Let $x,z$ be generators in degrees two and four. Precomposing $\eta$ with a degree-$d$ self-map of $S^3$ represents $d\eta$. The induced map of mapping cones is the identity on the two-cell and has degree $d$ on the four-cell. Since the Hopf mapping cone has cup square equal to its top generator, naturality of the <cup product> gives $x^2=dz$. Equivalently, <precomposition scales the Hopf invariant by degree>. Hence
$$
\boxed{H^*(Y_d;\mathbb Z)=\mathbb Z[x,z]/(x^2-dz,xz,z^2),
\qquad |x|=2,\quad |z|=4}.
$$
The coefficient is $d$, not $d^2$: multiplication in $\pi_3(S^2)$ is being used, rather than postcomposition by a degree-$d$ map of the target sphere.

For $X=X_{d,f}$, the only nonzero cellular boundary is $C_4\to C_3$, multiplication by $f$. Thus its <cellular cohomology> gives
$$
H^q(X;\mathbb Z)=
\begin{cases}
\mathbb Z,&q=0,2,\\
\ker(f:\mathbb Z\to\mathbb Z),&q=3,\\
\mathbb Z/f\mathbb Z,&q=4,\\
0,&\text{otherwise}.
\end{cases}
$$
Let $x$ again generate $H^2$, and let $z$ be the class of the four-cell cochain. Collapsing the three-sphere gives a map $X\to Y_d$ which pulls the degree-two generator back to $x$ and the degree-four generator back to $z$. Hence $x^2=dz$, now interpreted modulo $f$. Every other product of positive-degree classes vanishes by dimension. This is the <cohomology ring of a Hopf attachment with a sphere summand>. More explicitly, if $f\ne0$,
$$
\boxed{H^*(X;\mathbb Z)=\mathbb Z[x,z]/(fz,x^2-dz,xz,z^2)}.
$$
If $f=0$, there is additionally a generator $y$ of degree three, with $xy=y^2=yz=0$. The displayed description of the groups uses $\mathbb Z/0\mathbb Z=\mathbb Z$, so the zero case is included. In particular, a nonzero $f$ kills the degree-three cohomology but can leave torsion in degree four.

There are no one-cells, and attaching cells of dimension at least three does not change $\pi_1$. Thus $X$ is <simply connected>. The <Hurewicz theorem> in degree two gives
$$
\boxed{\pi_1(X)=0,\qquad\pi_2(X)\cong H_2(X;\mathbb Z)\cong\mathbb Z}.
$$

To compute $\pi_3$, choose a map $g:X\to\mathbb{CP}^\infty=K(\mathbb Z,2)$ representing $x$. This <Eilenberg–MacLane space> can be realized by the <classifying space> of $S^1$. On $S^2$ the map is the standard inclusion; on $S^3$ it is constant, and it extends over the four-cell since $\pi_3(K(\mathbb Z,2))=0$. Its <homotopy fibre> $T$ is the pullback of the universal <circle bundle> $S^\infty\to\mathbb{CP}^\infty$. The map on $\pi_2$ is an isomorphism, so the <long exact sequence of homotopy groups of a fibration> gives $\pi_1(T)=\pi_2(T)=0$ and $\pi_3(T)\cong\pi_3(X)$. Therefore the <Hurewicz theorem> identifies the latter with $H_3(T;\mathbb Z)$.

Over $W=S^2\vee S^3$, the circle-bundle total space is
$$
P=S^3\cup_{S^1}(S^1\times S^3).
$$
The first summand is the <Hopf fibration> total space over $S^2$, and the second is the trivial bundle over $S^3$. Their intersection is the fibre over the wedge point. The <Mayer–Vietoris sequence> gives $H_3(P)=\mathbb Z A\oplus\mathbb Z B$, with generators from the two three-spheres. These are the lifts of $\eta_1$ and $i_2$. The circle bundle over $W$ also has a 2-connected total space, so lifting and the <Hurewicz theorem> identify $d\eta_1+f i_2$ with $dA+fB$.

Over the attached four-disc the bundle is trivial. The resulting relative pair has the homology of $(S^1\times D^4,S^1\times S^3)$, so $H_4(T,P)=\mathbb Z$ and $H_3(T,P)=0$. Its boundary map sends a generator to the lift of the attaching map, namely $dA+fB$. The <long exact sequence in relative homology> now gives
$$
H_3(T)=\frac{\mathbb Z A\oplus\mathbb Z B}{\langle dA+fB\rangle}.
$$
Applying <Smith normal form> to this one relation proves the <third homotopy group of a Hopf attachment with a sphere summand>:
$$
\boxed{\pi_3(X_{d,f})\cong\mathbb Z\oplus\mathbb Z/\gcd(d,f)\mathbb Z}.
$$
Since $d>0$, the greatest common divisor is positive even when $f=0$. This derivation uses the required map to an <Eilenberg–MacLane space> and determines the extension, rather than merely the orders of its pieces.