Exemple #1
0
def contour_rotation_classes(cardinality):
    """Returns all rotation related contour classes of a given
    cardinality. Each cseg is rotation class representative.

    >>> contour_rotation_classes(4)
    [< 0 1 2 3 >, < 0 1 3 2 >, < 0 2 1 3 >]
    """

    # sets universe set with all csegs with a given cardinality
    universe = set([tuple(x) for x in auxiliary.permut_csegs(cardinality)])
    s = set()

    for el in universe:
        cseg = Contour(el)
        all = set([tuple(x) for x in cseg.rotated_representatives()])
        r = 0
        # tests if an operation in cseg's all operation is already in
        # s set
        for op in all:
            if op in s:
                r += 1
        if r == 0:
            s.update([el])

    # sets the first contour of each class for function return
    result = []

    for el in s:
        cseg = Contour(el)
        all = [Contour(x) for x in cseg.rotated_representatives()]
        result.append(sorted(all)[0])

    return sorted(result)
Exemple #2
0
def prime_form_algorithm_test(card, prime_form_algorithm="prime_form_sampaio"):
    """Returns contour classes with two prime forms from a given
    cardinality and prime form algorithm.

    >>> prime_form_algorithm_test(5, 'prime_form_marvin_laprade')
    [< 0 1 3 2 4 >, < 0 2 1 3 4 >, < 0 2 3 1 4 >, < 0 3 1 2 4 >,
    < 1 0 4 2 3 >, < 1 2 0 4 3 >, < 1 2 4 0 3 >, < 1 4 0 2 3 >,
    < 3 0 4 2 1 >, < 3 2 0 4 1 >, < 3 2 4 0 1 >, < 3 4 0 2 1 >,
    < 4 1 3 2 0 >, < 4 2 1 3 0 >, < 4 2 3 1 0 >, < 4 3 1 2 0 >]
    """

    # creates a list of all possible lists
    lists = [auxiliary.permut_csegs(c) for c in range(2, card + 1)]
    lists = utils.flatten(lists)

    coll = set()

    for lst in lists:
        cseg = Contour(lst)
        if cseg.unique_prime_form_test(prime_form_algorithm) == False:
            c_class, n_class, x, ri = cseg.segment_class()
            coll.add((c_class, n_class))

    classes = sorted(list(coll))
    result = []

    if classes != []:
        for cls in classes:
            cseg = auxiliary.cseg_from_class_number(*cls)
            ri = cseg.retrograde().inversion()
            result.append([cls, cseg, ri])

    return result
Exemple #3
0
def build_classes_card(card, prime_algorithm="prime_form_marvin_laprade"):
    """Generates contour classes like Marvin and Laprade (1987) table
    for one cardinality. Accepts more than one algorithm of prime
    form. Marvin and Laprade algorithm is default.
    Returns (card, number, contour class).

    >>> build_classes_card(3, 'prime_form_sampaio')
    [(3, 1, (0, 1, 2), True), (3, 2, (0, 2, 1), False)]
    """

    def __tuple_prime(lst, prime_algorithm):
        """Returns a tuple with a cseg from a list of c-pitches.

        >>> __tuple_prime([2, 1, 0])
        (0, 1, 2)
        """

        return tuple(auxiliary.apply_fn(Contour(lst), prime_algorithm))

    def __single_class_build(card, class_n, cseg):
        """Returns a single contour class from cardinality, class
        number, and cseg.

        >>> __single_class_build(4, 1, (0, 1, 3, 2))
        (4, 2, (0, 1, 3, 2), False)
        """

        return card, class_n + 1, cseg, Contour(list(cseg)).ri_identity_test()

    permut = auxiliary.permut_csegs(card)
    primes_repeats = [__tuple_prime(el, prime_algorithm) for el in permut]
    primes = enumerate(sorted(list(set(primes_repeats))))

    return [__single_class_build(card, n, x) for n, x in primes]
Exemple #4
0
    def csegs(self, d=1):
        """Returns all csegs in normal form that have the given
        internal diagonal. Default diagonal is 1.

        >>> InternalDiagonal([-1, 1, 1]).csegs
        [[1, 0, 2, 3], [2, 0, 1, 3], [3, 0, 1, 2]]
        """

        def __cseg(original, x, d):
            """Returns a list with cseg internal diagonals and cseg
            from a given tuple and diagonal number.
            """

            cseg = contour.Contour(list(x))
            int_d = cseg.internal_diagonals(d)
            if int_d == original:
                return cseg

        size = len(self) + d
        permut = auxiliary.permut_csegs(size)
        r = []
        [r.append(__cseg(self, x, d)) for x in permut if __cseg(self, x, d)]

        return r