There are a lot of LINQ-based implementations of the Composite Specification Pattern. I have not seen one that used Subsumption.
Are there any such examples that have been documented (blogs, etc.) or published as open source? I have an idea and proof of concept for how this could work by having an ExpressionVisitor translate every specification into a canonical logical form (CNF/DNF), but I am concerned that this is overly complicated. Is there a better way?
I am concerned that this is overly complicated. Is there a better way?
The short answer is "No, there isn't" 1
The long answer: The "overly complicated" captures the essence of the problem: it is NP-hard. Here is a short informal proof relying upon the fact that the satisfiability problem is NP-complete:
A
and B
A
implies B
, or equivalently ¬A | B
for all assignments of variables upon which A
and B
depend. In other words, you need a proof that F = ¬A | B
is a tautology.¬F
, the inverse of F
. F
is satisfiable if and only if ¬F
is not a tautology¬F
for being a tautologyF
satisfiable" is the inverse of the answer to "is ¬F
a tautology"P
, and that P=NP
.Of course the fact that the problem is NP-hard does not mean that there would be no solutions for practical cases: in fact, your approach with the conversion to a canonical form may produce OK results in many real-world situations. However, an absence of a known "good" algorithm often discourages active development of practical solutions2.
P=NP
" disclaimer.
2 Unless a "reasonably good" solution would do, which may very well be the case for your problem, if you allow for "false negatives".