Prefix Notation conversion into a tree is usually done like this:
Create a binary tree from an algebraic expression
However, I need to support so called chainable operations that have more than two operands. If that operation is splittable i.e
(+ a b c) = (+(+ a b) c)
there is no problem.
+
/ \
+ c
/ \
a b
However if an operator is not splittable this does not work. One example is the pairwise distinct operator.
(distinct a b c) != (distinct (distinct a b) c)
the left side implies a != b, a != c and b != c, while the right side implies only a != b and b != c. Trying to build an n-ary tree would probably lead to not being able to traverse the tree very well:
distinct
/ | \
a b c
Does somebody have experience with this kind of problem and has an idea on how to solve the issue?