def connect(H, G, Gout=None, Hin=None):
    """
    Connect outputs Gout of G to inputs Hin of H. The outputs and inputs of
    the connected system are arranged as follows:

        - remaining outputs of G get lower, the outputs of H the higher indices
        - inputs of G get the lower, remaining inputs of H the higher indices

    connect(H, G) is equivalent to H * G.
    """

    if issubclass(type(H), type(G)):
        try:
            connection = H.__connect__(G, Gout, Hin)
        except AttributeError:
            connection = G.__rconnect__(H, Gout, Hin)
    else:
        try:
            connection = G.__rconnect__(H, Gout, Hin)
        except AttributeError:
            connection = H.__connect__(G, Gout, Hin)

    return(connection)