Check whether an undirected graph contains a simple cycle of length four using the "Squares" method
Square $M$, to get $M^2$.  Write $M^2 = D + P$, where $D$ is the diagonal part (all non-diagonal entries are zero) and $P$ is the non-diagonal part (all diagonal entries are zero).
Compute $Q=P^2$.  Note that $Q_{aa}$ counts the number of ways to start at $a$ and end at $a$, excluding cycles of the form $ababa$ and $abaca$ etc., but not avoiding cycles of the form $abcba$.
Now compute $R = MDM - D$.  Note that $R_{aa}$ counts the number of cycles of the form $abcba$ where $c \ne a$.
Let $S = Q-R$.  We find that $S_{aa}$ counts the number of simple 4-cycles that start and end at $a$.  Thus, the graph has a simple 4-cycle if and only if one or more of the diagonal entries of $S$ are non-zero.