ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 07 Nov 2021 21:48:36 +0100Create group with custom set and operatorhttps://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/Hi, I know that we can use Sage to create an instance of a predefined group like so:
H = DihedralGroup(6)
But instead of using a predefined group, can I also create a group instance having a predefined set (for example a set of natural numbers) and a custom binary operator (such as multiplication modulo N) ?
What I'm looking for is something like this:
G = new Group({1, 2, 3, 4}, (a, b) -> a * b mod 10)
And then generate the group table for G.
If someone could provide me with an code example it'd be great, I wasn't able to derive it from the docs I read.Wed, 27 Oct 2021 09:27:07 +0200https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/Answer by Max Alekseyev for <p>Hi, I know that we can use Sage to create an instance of a predefined group like so:</p>
<pre><code>H = DihedralGroup(6)
</code></pre>
<p>But instead of using a predefined group, can I also create a group instance having a predefined set (for example a set of natural numbers) and a custom binary operator (such as multiplication modulo N) ? </p>
<p>What I'm looking for is something like this:</p>
<pre><code>G = new Group({1, 2, 3, 4}, (a, b) -> a * b mod 10)
</code></pre>
<p>And then generate the group table for G.</p>
<p>If someone could provide me with an code example it'd be great, I wasn't able to derive it from the docs I read.</p>
https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?answer=59557#post-id-59557In your example you rely on multiplication of integers modulo 10, so any group using this operation will be a subgroup of the unit group of $\mathbb{Z}/10\mathbb{Z}$. However, numbers 2 and 4 cannot be there as they are not invertible modulo 10. So, perhaps you mean semigroup (monoid) rather than a group.
Semigroup $G$ for your example can be constructed as follows:
mygens = [1,2,3,4]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
Then multiplication table can be constructed with `OperationTable`:
from sage.matrix.operation_table import OperationTable
print( OperationTable(G, operation=operator.mul, names='elements') )
which gives:
* 1 2 3 4 6 8 9 7
+----------------
1| 1 2 3 4 6 8 9 7
2| 2 4 6 8 2 6 8 4
3| 3 6 9 2 8 4 7 1
4| 4 8 2 6 4 2 6 8
6| 6 2 8 4 6 8 4 2
8| 8 6 4 2 8 4 2 6
9| 9 8 7 6 4 2 1 3
7| 7 4 1 8 2 6 3 9
----
**ADDED.** When $G$ represents a group, we can explicitly create its isomorphic permutation group $P$ (subgroup of $\mathrm{Sym}(G)$) as in the following example:
mygens = [1,3]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
P = PermutationGroup([[G(g)*b for b in G] for g in mygens], domain=G)
print("elements of P:",list(P))
M = {g:P([G(g)*b for b in G]) for g in G} # map from G to P
print("map G->P:",M)
which prints:
elements of P: [(), (1,9)(3,7), (1,7,9,3), (1,3,9,7)]
map G->P: {1: (), 3: (1,3,9,7), 9: (1,9)(3,7), 7: (1,7,9,3)}Sun, 31 Oct 2021 20:25:53 +0100https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?answer=59557#post-id-59557Comment by Max Alekseyev for <p>In your example you rely on multiplication of integers modulo 10, so any group using this operation will be a subgroup of the unit group of $\mathbb{Z}/10\mathbb{Z}$. However, numbers 2 and 4 cannot be there as they are not invertible modulo 10. So, perhaps you mean semigroup (monoid) rather than a group.</p>
<p>Semigroup $G$ for your example can be constructed as follows:</p>
<pre><code>mygens = [1,2,3,4]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
</code></pre>
<p>Then multiplication table can be constructed with <code>OperationTable</code>:</p>
<pre><code>from sage.matrix.operation_table import OperationTable
print( OperationTable(G, operation=operator.mul, names='elements') )
</code></pre>
<p>which gives:</p>
<pre><code>* 1 2 3 4 6 8 9 7
+----------------
1| 1 2 3 4 6 8 9 7
2| 2 4 6 8 2 6 8 4
3| 3 6 9 2 8 4 7 1
4| 4 8 2 6 4 2 6 8
6| 6 2 8 4 6 8 4 2
8| 8 6 4 2 8 4 2 6
9| 9 8 7 6 4 2 1 3
7| 7 4 1 8 2 6 3 9
</code></pre>
<hr>
<p><strong>ADDED.</strong> When $G$ represents a group, we can explicitly create its isomorphic permutation group $P$ (subgroup of $\mathrm{Sym}(G)$) as in the following example:</p>
<pre><code>mygens = [1,3]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
P = PermutationGroup([[G(g)*b for b in G] for g in mygens], domain=G)
print("elements of P:",list(P))
M = {g:P([G(g)*b for b in G]) for g in G} # map from G to P
print("map G->P:",M)
</code></pre>
<p>which prints:</p>
<pre><code>elements of P: [(), (1,9)(3,7), (1,7,9,3), (1,3,9,7)]
map G->P: {1: (), 3: (1,3,9,7), 9: (1,9)(3,7), 7: (1,7,9,3)}
</code></pre>
https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59630#post-id-59630I've added implementation of the (sort of) third approach.Sun, 07 Nov 2021 21:48:36 +0100https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59630#post-id-59630Comment by Max Alekseyev for <p>In your example you rely on multiplication of integers modulo 10, so any group using this operation will be a subgroup of the unit group of $\mathbb{Z}/10\mathbb{Z}$. However, numbers 2 and 4 cannot be there as they are not invertible modulo 10. So, perhaps you mean semigroup (monoid) rather than a group.</p>
<p>Semigroup $G$ for your example can be constructed as follows:</p>
<pre><code>mygens = [1,2,3,4]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
</code></pre>
<p>Then multiplication table can be constructed with <code>OperationTable</code>:</p>
<pre><code>from sage.matrix.operation_table import OperationTable
print( OperationTable(G, operation=operator.mul, names='elements') )
</code></pre>
<p>which gives:</p>
<pre><code>* 1 2 3 4 6 8 9 7
+----------------
1| 1 2 3 4 6 8 9 7
2| 2 4 6 8 2 6 8 4
3| 3 6 9 2 8 4 7 1
4| 4 8 2 6 4 2 6 8
6| 6 2 8 4 6 8 4 2
8| 8 6 4 2 8 4 2 6
9| 9 8 7 6 4 2 1 3
7| 7 4 1 8 2 6 3 9
</code></pre>
<hr>
<p><strong>ADDED.</strong> When $G$ represents a group, we can explicitly create its isomorphic permutation group $P$ (subgroup of $\mathrm{Sym}(G)$) as in the following example:</p>
<pre><code>mygens = [1,3]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
P = PermutationGroup([[G(g)*b for b in G] for g in mygens], domain=G)
print("elements of P:",list(P))
M = {g:P([G(g)*b for b in G]) for g in G} # map from G to P
print("map G->P:",M)
</code></pre>
<p>which prints:</p>
<pre><code>elements of P: [(), (1,9)(3,7), (1,7,9,3), (1,3,9,7)]
map G->P: {1: (), 3: (1,3,9,7), 9: (1,9)(3,7), 7: (1,7,9,3)}
</code></pre>
https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59612#post-id-59612I see two approaches here:
- define your group as a subgroup of some universe group, where all your elements and binary operation belong (e.g., the unit group $U(\mathbb{Z}_{10})$ in case of mod 10 operation); or
- define your group as a [finitely presented group](https://doc.sagemath.org/html/en/reference/groups/sage/groups/finitely_presented.html).
Your example with mod 10 suggests that you'd be better off with the first approach, but if operation is truly 'custom', the second approach may be preferable.
The third approach could be converting the semigroup defined as in my answer into a group (if it really is), but I don't know how to implement this in Sage.Sat, 06 Nov 2021 17:35:07 +0100https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59612#post-id-59612Comment by nash1212 for <p>In your example you rely on multiplication of integers modulo 10, so any group using this operation will be a subgroup of the unit group of $\mathbb{Z}/10\mathbb{Z}$. However, numbers 2 and 4 cannot be there as they are not invertible modulo 10. So, perhaps you mean semigroup (monoid) rather than a group.</p>
<p>Semigroup $G$ for your example can be constructed as follows:</p>
<pre><code>mygens = [1,2,3,4]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
</code></pre>
<p>Then multiplication table can be constructed with <code>OperationTable</code>:</p>
<pre><code>from sage.matrix.operation_table import OperationTable
print( OperationTable(G, operation=operator.mul, names='elements') )
</code></pre>
<p>which gives:</p>
<pre><code>* 1 2 3 4 6 8 9 7
+----------------
1| 1 2 3 4 6 8 9 7
2| 2 4 6 8 2 6 8 4
3| 3 6 9 2 8 4 7 1
4| 4 8 2 6 4 2 6 8
6| 6 2 8 4 6 8 4 2
8| 8 6 4 2 8 4 2 6
9| 9 8 7 6 4 2 1 3
7| 7 4 1 8 2 6 3 9
</code></pre>
<hr>
<p><strong>ADDED.</strong> When $G$ represents a group, we can explicitly create its isomorphic permutation group $P$ (subgroup of $\mathrm{Sym}(G)$) as in the following example:</p>
<pre><code>mygens = [1,3]
R = IntegerModRing(10)
G = R.subsemigroup( (R(g) for g in mygens), one=R(1) )
P = PermutationGroup([[G(g)*b for b in G] for g in mygens], domain=G)
print("elements of P:",list(P))
M = {g:P([G(g)*b for b in G]) for g in G} # map from G to P
print("map G->P:",M)
</code></pre>
<p>which prints:</p>
<pre><code>elements of P: [(), (1,9)(3,7), (1,7,9,3), (1,3,9,7)]
map G->P: {1: (), 3: (1,3,9,7), 9: (1,9)(3,7), 7: (1,7,9,3)}
</code></pre>
https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59611#post-id-59611Thanks for your reply, but I was actually indeed talking about groups. The example was just for illustrative purposes, I don't claim that these numbers really form a group under multiplication mod 10.
Would you have an example how to create a group table for a given set and a custom binary operation?Sat, 06 Nov 2021 16:46:30 +0100https://ask.sagemath.org/question/59493/create-group-with-custom-set-and-operator/?comment=59611#post-id-59611