# How to find the element with maximal length in a double coset of a Coxeter group?

Let $W$ be a finite Coxeter group. Denote by $W_I$ the subgroup of $W$ generated by $s_i$, $i \in I$, $I$ is a subset of the set of vertices of the Dynkin diagram of $W$. For every $w \in W$, and $I, J$ subsets of the set of vertices of the Dynkin diagram, I would like to write a function in Sagemath to find the element of maximal length in the double coset $W_I w W_J$. In type A, the case of symmetric group, I wrote the following program and it works.

```
def LongestPermInDoubleCoset(S1,w,S2): # longest element in S1 w S2, S1,S2 are subgroups of S_n
winner = W.identity()
for u1 in S1:
for u2 in S2:
t1=u1*w*u2
if t1.length()>winner.length():
winner=t1
r=winner
return r
W=SymmetricGroup(6)
[s1,s2,s3,s4,s5] = W.simple_reflections()
S1=[W.identity(), s1]
S2=[W.identity(),s2]
t1=LongestPermInDoubleCoset(S1,s1,S2)
t2=t1.reduced_word()
t2
```

One problem in the above program is that I have to give S1, S2 explicitly. I would like to revise the program such that when given S1, S2, I only need to give simple reflections. For example, when give S1=[W.identity(), s1], I would like to give S1 = <generated by="" s1="">.

Another problem in the above program is that it works only for symmetric group. How to revise it such that it works for any Coxeter group (or at least Weyl group)? Thank you very much.