Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to generate the cosets in this specific group (Zn*)

I see the answers to the multiplicative group of units (a class), in here, as well as the answer to how to generate cosets in here.

But I don't know how to blend them together into a chunk of code that illustrates the cosets when the group is partitioned by the subgroup generated, for example, by the element 5 in the multiplicative group mod 13:

Zn = Zmod(13)
G = Zn.unit_group()
H = G.subgroup(5)
H.cosets()

How to generate the cosets in this specific group (Zn*)

I see the answers to the multiplicative group of units (a class), in here, as well as the answer to how to generate cosets in here.

But I don't know how to blend them together into a chunk of code that illustrates the cosets when the group is partitioned by the subgroup generated, for example, by the element 5 in the multiplicative group mod 13:

Zn = Zmod(13)
G = Zn.unit_group()
H = G.subgroup(5)
H.cosets()

A possible workaround after the comment below could be as follows:

def cosets(p,g):
    R = Integers(p)
    a = R(g)
    sub = uniq([a^i for i in range(p - 1)])
    diff = list(set(R) - set(sub))
    m = []
    for k in range(1, len(diff)): m.append(sorted(set([diff[k] * i for i in sub])))
    costs = list(set(tuple(map(tuple, m))))
    print("The elements of the multiplicative subgroup generated by", g, "modulo", p, "are", sub, "and the cosets are", costs)

So the call cosets(13,5) would yield:

The elements of the multiplicative subgroup generated by 5 modulo 13 are [1, 5, 8, 12] and the cosets are [(2, 3, 10, 11), (4, 6, 7, 9)]

Would this work?