# GAP:IsSubgroup

## Definition

### Function type

IsSubgroup is a GAP function that takes two arguments, both of which are meant to be groups, and returns an output of type bool.

### Behavior

The behavior is as follows:

• If the second group is a subgroup of the first, the function returns true.
• If the second group is not a subgroup of the first, the function returns false.
• If one or more of the arguments are not groups, the function returns false. It does not return an error.

Note that the function tests whether the second group, the way it is stored in GAP, is actually a subgroup of the first. It does not test whether the second group is isomorphic to a subgroup of the first, or can be naturally identified with a subgroup of the first.

## Examples of usage

Here are some examples:

```gap> IsSubgroup(CyclicGroup(2),CyclicGroup(3));
false
gap> IsSubgroup(CyclicGroup(2), 1);
false
gap> IsSubgroup(0,1);
false
gap> IsSubgroup(SymmetricGroup(3),SymmetricGroup(2));
true
gap> IsSubgroup(SymmetricGroup(2),SymmetricGroup(3));
false
gap> IsSubgroup(CyclicGroup(2),CyclicGroup(3));
false
gap> IsSubgroup(CyclicGroup(4),CyclicGroup(2));
false
gap> IsSubgroup(0,1);
false```

Here is a caveat that is worth noting:

```gap> IsSubgroup(DihedralGroup(8),DihedralGroup(8));
false
gap> IsSubgroup(SymmetricGroup(4),SymmetricGroup(4));
true
gap> G := DihedralGroup(8);
<pc group of size 8 with 3 generators>
gap> IsSubgroup(G,G);
true```

The first result is false, which appears surprising, since the dihedral group of order eight is clearly a subgroup of itself. The problem here is that when the same command is written twice, GAP does not realize that the two copies refer to the same thing. On the other hand, for the symmetric groups, as shown in the second command, GAP does realize that the two copies refer to the same thing. This is due to the different way in which GAP stores, computes and handles symmetric groups (see GAP:SymmetricGroup for more).

The last two commands show how to overcome the difficulty in general: store the group defined into a variable name, and then use that variable name as a handle to get correct results.