Hey, that is quite simple algebra, I guess. You are the professorbob wrote: Actually I think one slits one's own wrists as a pre-emptive strike to prevent one's own head from exploding when thinking about this stuff.

Academic or math guys usually write it in much more elegant and shorter form of algebra, may be you understand that better than my naive expressions.
You have 8 direction sets (eg. from hanging pieces and king) and there are 7+6+5+4+3+2+1 = (n*n - n)/2 = 28 combinations for distinct intersections of all pairs of eight sets. So the union of all those intersections, where for instance a queen may fork two hanging pieces (including checking the king), requires 28 ands and 27 ors at the first glance, which can be reduced to 7+12 ops as mentioned.
Still some work, not to mention the eight kogge-stone fills...