Avoiding Light Duplication in Custom Light Path Expressions

When you make your own LPEs and you plan to composite them additively, it is important not to miss any light contribution, but also important not to have any double contribution of light.

There is a trick to make sure this does not happen: If you have a set of LPEs, make a new LPE that concatenates these using the & operator. The result should be black. If some light is incorrectly present in more than one of these LPEs, it will show up in this concatenated LPE. So if we assume three LPEs we call a, b, and c, you can write a group of test LPEs:
(a) & ((b) | (c))
(b) & ((a) | (c))
(c) & ((a) | (b))

… to find out if they have any light in common. The results of each test should be black. If a result is not black, compositing the elements will not sum up to the correct result.

Don't forget to use parentheses to ensure the proper order of evaluation.

Similarly, you can find the "left over" light contribution by combining all your LPEs using the | operator, inverting that, and &-ing it with all possible light. So for our example, the combined LPE would be:
L.*E & ^((a) | (b) | (c))

... this takes all possible light paths (L.*E) and from those chooses only the ones not present in any of the LPEs a, b, or c.