Repository: sagemath/sage

Issue:
Graph.relabel() misinterprets elements of .automorphism_group()
### Steps To Reproduce

Each element of automorphism group acts on the graph vertices by permuting (relabeling) them. It is therefore very natural for `.relabel()` to support automorphism group's elements. 

```
sage: G = graphs.CycleGraph(5)
sage: A = G.automorphism_group()
sage: H = G.random_orientation()
sage: a = A.random_element()
sage: print(a)
(0,3,1,4,2)
sage: H.relabel(a,inplace=False).show()
```

### Expected Behavior

For a given automorphism `a`, each graph vertex `v` should be relabeled into `a(v)`.

### Actual Behavior

At the moment `.relabel()` misunderstands a given graph's automorphism by issuing an wrongful error message `NotImplementedError: Non injective relabeling`. Elements of automorphism group **do** define injective labeling.

### Additional Information

A workaround is to call `H.relabel(lambda v: a(v),...)` instead of `H.relabel(a,...)`.



### Environment

```markdown
- **OS**: Ubuntu 22.04.3 LTS
- **Sage Version**: 10.3.beta7
```


### Checklist

- [X] I have searched the existing issues for a bug report that matches the one I want to file, without success.
- [X] I have read the documentation and troubleshoot guide


Discussion:

Resolving patch:
diff --git a/src/sage/graphs/generic_graph.py b/src/sage/graphs/generic_graph.py
--- a/src/sage/graphs/generic_graph.py
+++ b/src/sage/graphs/generic_graph.py
@@ -22999,10 +22999,7 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c
         is relabeled to ``l[0]``, the second to ``l[1]``, ...
 
         If ``perm`` is a permutation, then each vertex ``v`` is
-        relabeled to ``perm(v)``. Caveat: this assumes that the
-        vertices are labelled `\{0,1,...,n-1\}`; since permutations
-        act by default on the set `\{1,2,...,n\}`, this is achieved by
-        identifying `n` and `0`.
+        relabeled to ``perm(v)``.
 
         If ``perm`` is ``None``, the graph is relabeled to be on the
         vertices `\{0,1,...,n-1\}`. This is *not* any kind of canonical
@@ -23068,6 +23065,15 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c
             [0 0 1]
             [1 1 0]
 
+            sage: # needs sage.groups
+            sage: C5 = graphs.CycleGraph(5)
+            sage: C5.relabel({u: str(u) for u in C5}, inplace=True)
+            sage: ar = C5.automorphism_group().random_element()
+            sage: R = C5.relabel(ar, inplace=False)
+            sage: perm = C5.is_isomorphic(R, certificate=True)[1]
+            sage: perm == {u: ar(u) for u in C5}
+            True
+
         A way to get a random relabeling::
 
             sage: set_random_seed(0)  # Results are reproducible
@@ -23225,13 +23231,8 @@ def relabel(self, perm=None, inplace=True, return_map=False, check_input=True, c
             perm = dict(perm)
 
         elif isinstance(perm, PermutationGroupElement):
-            n = self.order()
-            ddict = {}
-            for i in range(1, n):
-                ddict[i] = perm(i) % n
-            if n > 0:
-                ddict[0] = perm(n) % n
-            perm = ddict
+            # Each vertex is relabeled according to the permutation group
+            perm = {u: perm(u) for u in self}
 
         else:
             # Check for generic iterable/callable


Test patch: