Uhm, I concluded that math is not too useful, neither in-game nor in real life - my math lessons are just terrifying me, and I need help. I don't want to think about algebra for my castle's level.
I think one clear answer is that guards at the door should be APL-4 or lower. It takes a lot of manpower to cover a whole building, so most of your guards are there more to raise the alarm than serve as a credible defense. Then you have more elite defenses to handle the threats themselves (APL+4 or higher).
In my imagination, a heist target would have many different infiltration angles, including more than one that would bypass guards entirely.