# Shortest presentation of a permutation using generators

A question in sagemath:

Let $S$ be a set of generators of a permutation group $H\subseteq S_n$ and let $\pi$ be an element in $H$.

Is there a way in sage to find the shortest words in the letters $S$ equal to $\pi$?

The word_problem method can help with that.

From the SageMath word-problem documentation:

sage: G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]], canonicalize=False)
sage: g1, g2 = G.gens()
sage: h = g1^2*g2*g1
sage: h.word_problem([g1,g2], False)
('x1^2*x2^-1*x1', '(1,2,3)(4,5)^2*(3,4)^-1*(1,2,3)(4,5)')
sage: h.word_problem([g1,g2])
x1^2*x2^-1*x1
[['(1,2,3)(4,5)', 2], ['(3,4)', -1], ['(1,2,3)(4,5)', 1]]
('x1^2*x2^-1*x1', '(1,2,3)(4,5)^2*(3,4)^-1*(1,2,3)(4,5)')


To read the documentation or source code of this function:

sage: h.word_problem?
sage: h.word_problem??