def _factor_rhs(self, in_port):
        """With::

            n           := self.cdim
            in_im       := self.permutation[in_port]
            m_{k->l}    := map_signals_circuit({k:l}, n)

        solve the equation (I) containing ``self``::

            self << m_{(n-1) -> in_port}
                == m_{(n-1) -> in_im} << (red_self + cid(1))          (I)

        for the (n-1) channel CPermutation ``red_self``.
        Return in_im, red_self.

        This is useful when ``self`` is the RHS in a SeriesProduct Object that
        is within a Feedback loop as it allows to extract the feedback channel
        from the permutation and moving the remaining part of the permutation
        (``red_self``) outside of the feedback loop.

        :param int in_port: The index for which to factor.
        """
        n = self.cdim
        if not (0 <= in_port < n):
            raise Exception
        in_im = self.permutation[in_port]
        # (I) is equivalent to
        #       m_{in_im -> (n-1)} <<  self << m_{(n-1) -> in_port}
        #           == (red_self + cid(1))     (I')
        red_self_plus_cid1 = (map_channels({in_im: (n - 1)}, n) <<
                              self <<
                              map_channels({(n - 1): in_port}, n))
        if isinstance(red_self_plus_cid1, CPermutation):

            #make sure we can factor
            assert red_self_plus_cid1.permutation[(n - 1)] == (n - 1)

            #form reduced permutation object
            red_self = CPermutation.create(red_self_plus_cid1.permutation[:-1])

            return in_im, red_self
        else:
            # 'red_self_plus_cid1' must be the identity for n channels.
            # Actually, this case can only occur
            # when self == m_{in_port ->  in_im}

            return in_im, circuit_identity(n - 1)
def _factor_rhs ( self , in_port ) : n = self . cdim if not ( 0 <= in_port < n ) : raise Exception in_im = self . permutation [ in_port ] red_self_plus_cid1 = ( map_channels ( { in_im : ( n - 1 ) } , n ) << self << map_channels ( { ( n - 1 ) : in_port } , n ) ) if isinstance ( red_self_plus_cid1 , CPermutation ) : assert red_self_plus_cid1 . permutation [ ( n - 1 ) ] == ( n - 1 ) red_self = CPermutation . create ( red_self_plus_cid1 . permutation [ : - 1 ] ) return in_im , red_self else : return in_im , circuit_identity ( n - 1 )
With::

            n           := self.cdim
            in_im       := self.permutation[in_port]
            m_{k->l}    := map_signals_circuit({k:l}, n)

        solve the equation (I) containing ``self``::

            self << m_{(n-1) -> in_port}
                == m_{(n-1) -> in_im} << (red_self + cid(1))          (I)

        for the (n-1) channel CPermutation ``red_self``.
        Return in_im, red_self.

        This is useful when ``self`` is the RHS in a SeriesProduct Object that
        is within a Feedback loop as it allows to extract the feedback channel
        from the permutation and moving the remaining part of the permutation
        (``red_self``) outside of the feedback loop.

        :param int in_port: The index for which to factor.