This algorithm tries to rewrite a network with majority gates for depth optimization using the associativity and distributivity rule in majority-of-3 logic.
It can be applied to networks other than MIGs, but only considers pairs of nodes which both implement the majority-of-3 function.