def rewrite(C, alpha, w):
 v = C._schreier_free_group.identity
 for i in range(len(w)):
  x_i = w[i]
  v = (v * C.P[alpha][C.A_dict[x_i]])
  alpha = C.table[alpha][C.A_dict[x_i]]
 return v

def rewrite ( C , alpha , w ) : v = C . _schreier_free_group . identity for i in range ( len ( w ) ) : x_i = w [ i ] v = ( v * C . P [ alpha ] [ C . A_dict [ x_i ] ] ) alpha = C . table [ alpha ] [ C . A_dict [ x_i ] ] return v
parameters c: cosettable α: a live coset w: a word in a* returns ρ(τ .