Multiply elements of the dihedral group This is a copy cat question of Simplify ijk string applied to the other nonabelian group of order 8. See also Dihedral group composition with custom labels.
Challenge
Given a string made of r and s interpret it as the product of elements of the dihedral group \$D_8\$ and simplify it into one of the eight possible values &quot;&quot;, &quot;r&quot;, &quot;rr&quot;, &quot;rrr&quot;, &quot;s&quot;, &quot;rs&quot;, &quot;rrs&quot;, and &quot;rrrs&quot;. The empty string denotes the identity element \$1\$.
The evaluation rules are as follows:
$$
rrrr = 1\\
ss = 1\\
sr = rrrs
$$
The multiplication on the dihedral group is associative but not commutative. This means that you may do the simplification in any order, but you cannot reorder the items.
For the I/O format, function parameter and return from a function should be done as a string or list. You may output any amount of leading and trailing whitespace (spaces, tabs, newlines). You may use any other pair of distinct characters for r and s except for a tab, space, or newline. (If you really want to you can pick r or s to be whitespace, you can as long as you don't have leading or trailing whitespace.) It's also fine to use numbers for r and s, for example if you take 0 for r and 1 for s, it would be okay to do I/O like [1, 0] ==&gt; [0, 0, 0, 1].
Test cases
&quot;&quot; -&gt; &quot;&quot;
&quot;r&quot; -&gt; &quot;r&quot;
&quot;rrr&quot; -&gt; &quot;rrr&quot;
&quot;s&quot; -&gt; &quot;s&quot;
&quot;rs&quot; -&gt; &quot;rs&quot;
&quot;rrs&quot; -&gt; &quot;rrs&quot;
&quot;rrrr&quot; -&gt; &quot;&quot;
&quot;rrrrrr&quot; -&gt; &quot;rr&quot;
&quot;sr&quot; -&gt; &quot;rrrs&quot;
&quot;rsr&quot; -&gt; &quot;s&quot;
&quot;srsr&quot; -&gt; &quot;&quot;
&quot;srr&quot; -&gt; &quot;rrs&quot;
&quot;srs&quot; -&gt; &quot;rrr&quot;
&quot;rsrsr&quot; -&gt; &quot;r&quot;
&quot;rrsss&quot; -&gt; &quot;rrs&quot;
&quot;sssrrr&quot; -&gt; &quot;rs&quot;

Reference implementation
Here is a Javascript reference implementation.
function f(x) {
  let lastx;
  while(lastx !== x){
    lastx = x;
    x = x.replace(&quot;rrrr&quot;, &quot;&quot;);
    x = x.replace(&quot;sr&quot;, &quot;rrrs&quot;);
    x = x.replace(&quot;ss&quot;, &quot;&quot;);
  }
  return x;
}
J, 23 bytes
~:/I.@,~4|[:-/1#;._1@,]

Try it online!
Takes a boolean vector where 0 represents r and 1 represents s, and returns the result in the same encoding.
How it works
Imagine evaluating the chunks of \$r^n s r^m s\$ from the start. If we evaluate \$sr\$ in the middle \$m\$ times, we get \$r^{n+3m}s^2 = r^{n+3m}\$. We can repeat the process to the end. Let's represent the input as a sequence of integers which represent the number of \$r\$'s when separated by \$s\$'s, like sssrrr -&gt; [0, 0, 0, 3]. Then the following holds:

The alternating sum ([a, b, c, d, ...] -&gt; a - b + c - d + ...) modulo 4 is the final number of \$r\$'s.
The length plus 1 modulo 2 is the final number of \$s\$'s.

~:/I.@,~4|[:-/1#;._1@,]  NB. Input: a boolean vector
              1#;._1@,]  NB. Get the lengths of runs of r's between s's
        4|[:-/  NB. Alternating sum modulo 4 = the number of final r's
~:/             NB. Reduction by unequal on the original input,
                NB. i.e. the number of s's in the input mod 2
                NB. = the number of final s's
   I.@,~        NB. Reverse concat and generate that many 0's and 1's

Jelly, 15 bytes
ṣ1ẈṚḅ3%4,SḂ$Ø.x

Try it online!
Same algorithm as above. Doesn't feel well golfed to me though; maybe I missed some good alternative built-ins.
ṣ1ẈṚḅ3%4,SḂ$Ø.x  Input: a list of zeros and ones
s1Ẉ              Split at ones, then get length of each chunk
   Ṛḅ3%4         Reverse, evaluate in base 3, modulo 4
        ,        Pair with...
         SḂ$     Sum % 2
            Ø.x  Generate that many zeros and ones respectively