I've recently discovered this problem that I find very interesting and useful. The existing question also has an insightful answer which was of great help. The problem can be summarized as: "How many times is each edge in a graph G included in a chosen motif M? (using matrix operations)".
I am trying to generalize the procedure to larger motifs (more than 3 nodes), for now only undirected. I am particularly interested in motifs of 4 and 5 nodes, but I expect the same principle would work for higher numbers.
The main idea seems to be establishing (all possible?) relations between two nodes i and j, although I admit that I do not fully understand how this leads to counting the desired property. For 3-node motifs, there aren't that many possibilities, as shown in the question. Let's consider however the 4-node path graph illustrated below, with missing/complement edges in blue color and dashed:
By enumerating the possible paths from i to j, a list like the following is obtained: https://pastebin.com/2HjZArGw. In the list, ${\raise.17ex\hbox{$\scriptstyle\mathtt{\sim}$}} A$ is the notation I use for $*A$ in the original question, and there is no distinction into $B$ and $U$ since the graph is undirected. Some per-node results are duplicated and the list can be condensed to the 6 sublists:
[('A',), ('~A', 'A'), ('~A', 'A', 'A'), ('~A', 'A', '~A'), ('~A', '~A')],
[('A', 'A'), ('A', '~A', 'A'), ('~A',), ('~A', 'A'), ('~A', '~A', 'A')],
[('A', 'A', 'A'), ('A', '~A'), ('~A',), ('~A', 'A'), ('~A', 'A', '~A')],
[('A',), ('A', '~A'), ('A', '~A', 'A'), ('~A', 'A'), ('~A', '~A', '~A')],
[('A', 'A'), ('A', '~A'), ('A', '~A', 'A'), ('A', '~A', '~A'), ('~A',)],
[('A',), ('A', 'A', '~A'), ('A', '~A'), ('~A', 'A', '~A'), ('~A', '~A')]
Some of which share common elements, again. My question is what is the next step from this? Applying the same algorithm as above yields the same solution as $W_{M_{13}}$ in the original question, namely:
[('A',), ('~A', 'A')],
[('A', 'A'), ('~A',)],
[('A',), ('A', '~A')]
For $W_{M_{13}}$, the 3 cases above capture different information and can be simply ORed (summed) together. For the 4-node situation above, some of the relations seem to count the same edge multiple times, even if using only the unique relations.
I am stuck on how to proceed and generalize this to arbitrary motifs. I'm glad to discuss any suggestions.
Edit 1: It looks like there are some constraints that apply to this particular 4-node graph: paths must be of length 3 (so no $A \cdot ({\raise.17ex\hbox{$\scriptstyle\mathtt{\sim}$}} A)$, for example) and must involve 2 "real" (not complementary) edges. The expression that I found by manual inspection and works for this 4-node graph is: $A^2 \cdot ({\raise.17ex\hbox{$\scriptstyle\mathtt{\sim}$}}A) + (A^2 \cdot ({\raise.17ex\hbox{$\scriptstyle\mathtt{\sim}$}}A))^T + A \cdot ({\raise.17ex\hbox{$\scriptstyle\mathtt{\sim}$}}A) \cdot A$, but I'd still like to see if there is something more general (applicable to all motifs).
