def reverse_gate(wordlen, input='x', output='rev(x)'):
    circ = identity_gate(wordlen, input, output)
    output_map = frozenset(
        (k, tuple(reversed(vs))) for k, vs in circ.output_map
    )
    return attr.evolve(circ, output_map=output_map)