I have a problem that's proven to be dramatically more complex than it at first seemed. I have a (long) list of equivalence relations of the form e = abe
. I need a function from string to string that produces the same output for any two equivalent input strings. Two input strings are considered equivalent when they can be reached from each other by a series of substitutions using the equivalence relations.
For instance, if we have e = abe
and c = aba
, then cbe
and e
are equivalent (cbe = ababe = abe = e
). For a more complex example, a = bc
b = bb
c = bbb
and cc = aa
when taken together imply that any sequence consisting of a, b, and c is equivalent to any other such sequence (e.g. abcabc = bcbcbcbc = bbbbbbbbbbbbbbbb = b
).
If it helps, my input strings will never be more than a given length (let's say 20).
Overall, I have a feeling this probably maps to a general problem that's been given academic attention, but I haven't been able to find anything useful.