Three-sample run detector (source code)

= Three-sample run detector
{title2=$w_t=a_t\land a_{t-1}\land a_{t-2}$}

Store the two previous input <bits> in $p,q$. At the next <clock edge>, use $w=a\land p\land q$ and update $(p,q)'=(a,p)$. The output is high exactly when the present input and previous two samples are all high. Replacing each input by its <negation> detects a three-sample low run. Both detectors can share the same two history <bits>, using $a\land p\land q$ and $\neg a\land\neg p\land\neg q$. With initial history zero, the high detector cannot trigger before three actual high samples have occurred.