\documentclass{article}

\input{util/packages}
\input{util/math_macros}
\input{util/styling_macros}

\begin{document}
\begin{cofactors}
$f_{p}$ \= $= r \lor(s \land \lnot r) \lor (\lnot s \land  r) \lor (\lnot r \land q)$ \\
\>$f_{pq}$ \= $= r\lor (s \land \lnot r) \lor (\lnot s \land  r)\lor \lnot r = \true $\\
\>$f_{p\lnot q}$ \= $= r\lor (s \land \lnot r)\lor (\lnot s \land  r) $\\
\>\>$f_{p\lnot qr}$ \= $= \true $\\
\>\>$f_{p\lnot q\lnot r}$ \= $= s $\\
\>\>\>$f_{p\lnot q\lnot rs}$ \= $= \true $\\
\>\>\>$f_{p\lnot q\lnot r\lnot s}$ \= $= \false $\\
$f_{\lnot p}$ \= $= \lnot r \lor (s \land \lnot r) \lor (\lnot s \land  r) \lor (\lnot r \land q)$ \\
\>$f_{\lnot pq}$ \= $= \lnot r \lor (s \land \lnot r) \lor (\lnot s \land  r) \lor \lnot r = \lnot r \lor (s \land \lnot r) \lor (\lnot s \land  r) $ \\
\>\>$f_{\lnot pqr}$ \= $= \lnot s = \lnot f_{p\lnot q\lnot r} $\\
\>\>$f_{\lnot pq\lnot r}$ \= $= \true $\\
\>$f_{\lnot p\lnot q}$ \= $= \lnot r \lor (s \land \lnot r) \lor (\lnot s \land  r) = f_{\lnot p\lnot q}$ \\
\end{cofactors}

\begin{minipage}{0.5\textwidth}
  1.\begin{center}
    \begin{bdd}[4em]
      \node[func node] (f)                      {$f$};

      \node[cofactor] (p1)  [below      of=f]   {$q$};

      \node[cofactor] (q1)  [below left of=p1]  {$q$};
      \node[cofactor] (q2)  [below right of=p1,yshift=1em,xshift=2em]  {$q$};
      \node[cofactor] (r1)  [below       of=q2] {$r$};

      \node[cofactor] (r2)  [below right of=q1] {$r$};
      \node[phantom]  (q1L) [below left of=q1]  {};

      \node[phantom]  (r1R) [below right of=r1] {};

      \node[cofactor] (s1)  [below right of=r2] {$s$};
      \node[phantom]  (r2L) [below left of=r2]  {};

      \node[phantom]  (s2L) [below left of=s1]  {};
      \node[phantom]  (s2R) [below right of=s1] {};

      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (f!p)[above of=q2]  {$f_{\lnot p}$};
      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (fp!q!r) [above of=s1,xshift=-1.5em,yshift=1em]  {$f_{p\lnot q \lnot r}$};

      \funcEdge{f}{p1}
      \funcEdge{fp}{q1}
      \funcEdge{f!p}{q2}
      \funcEdge{fp!q!r}{s1}

      \thenEdge{p1}{q1}
      \elseEdge{p1}{q2}

      \thenEdge{q1}{q1L}
      \elseEdge{q1}{r2}

      \thenEdge[bend right]{q2}{r1}
      \elseEdge[bend left]{q2}{r1}

      \thenEdge{r2}{r2L}
      \elseEdge{r2}{s1}

      \negatedEdge{r1}{s1}
      \elseEdge{r1}{r1R}

      \thenEdge{s1}{s2L}
      \negatedEdge{s1}{s2R}
    \end{bdd}
  \end{center}
\end{minipage}
\begin{minipage}{0.5\textwidth}
  2.\begin{center}
    \begin{bdd}[4em]
      \node[func node] (f)                      {$f$};

      \node[cofactor] (p1)  [below      of=f]   {$q$};

      \node[cofactor] (q1)  [below left of=p1]  {$q$};
      \node[cofactor] (r1)  [below       of=q2] {$r$};

      \node[cofactor] (r2)  [below right of=q1] {$r$};
      \node[phantom]  (q1L) [below left of=q1]  {};

      \node[phantom]  (r1R) [below right of=r1] {};

      \node[cofactor] (s1)  [below right of=r2] {$s$};
      \node[phantom]  (r2L) [below left of=r2]  {};

      \node[phantom]  (s2L) [below left of=s1]  {};
      \node[phantom]  (s2R) [below right of=s1] {};

      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (fp!q!r) [above of=s1,xshift=-1.5em,yshift=1em]  {$f_{p\lnot q \lnot r}$};

      \funcEdge{f}{p1}
      \funcEdge{fp}{q1}
      \funcEdge{fp!q!r}{s1}

      \thenEdge{p1}{q1}
      \elseEdge[bend left]{p1}{r1}

      \thenEdge{q1}{q1L}
      \elseEdge{q1}{r2}

      \thenEdge{r2}{r2L}
      \elseEdge{r2}{s1}

      \negatedEdge{r1}{s1}
      \elseEdge{r1}{r1R}

      \thenEdge{s1}{s2L}
      \negatedEdge{s1}{s2R}
    \end{bdd}
  \end{center}
\end{minipage}

\begin{minipage}{0.5\textwidth}
  3.\begin{center}
    \begin{bdd}[4em]
      \node[func node] (f)                      {$f$};

      \node[cofactor] (p1)  [below      of=f]   {$q$};

      \node[cofactor] (q1)  [below left of=p1]  {$q$};
      \node[cofactor] (r1)  [below       of=q2] {$r$};

      \node[cofactor] (r2)  [below right of=q1] {$r$};
      \node[phantom]  (q1L) [below left of=q1]  {};

      \node[phantom]  (r1R) [below right of=r1] {};

      \node[cofactor] (s1)  [below right of=r2] {$s$};
      \node[phantom]  (r2L) [below left of=r2]  {};

      \node[phantom]  (s2L) [below left of=s1]  {};
      \node[phantom]  (s2R) [below right of=s1] {};

      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (fp) [above of=q1]  {$f_{p}$};
      \node[func node] (fp!q!r) [above of=s1,xshift=-1.5em,yshift=1em]  {$f_{p\lnot q \lnot r}$};

      \funcEdge{f}{p1}
      \funcEdge{fp}{q1}
      \funcEdge{fp!q!r}{s1}

      \thenEdge{p1}{q1}
      \negatedEdge[bend left]{p1}{r1}

      \thenEdge{q1}{q1L}
      \elseEdge{q1}{r2}

      \thenEdge{r2}{r2L}
      \elseEdge{r2}{s1}

      \thenEdge{r1}{s1}
      \negatedEdge{r1}{r1R}

      \thenEdge{s1}{s2L}
      \negatedEdge{s1}{s2R}
    \end{bdd}
  \end{center}
\end{minipage}
\end{document}
\end{document}
