Synthesis of P-circuits for logic restructuring