A Mathematical Framework for Transformer Circuits