private BindingSet Simplify(IList <IExpression> allLhs, int lhsIndex) { if (set.Count == 0) { return(this); } if (lhsIndex >= allLhs.Count) { return(this); } IExpression lhs = allLhs[lhsIndex]; var groups = GroupBy(lhs); bool allMatch = true; BindingSet bindingSet1 = null; BindingSet newBindingSet = new BindingSet(); BindingSet missing = null; int count = 0; foreach (var entry in groups) { var bindingSet2 = entry.Value.Simplify(allLhs, lhsIndex + 1); if (IsMissingExpr(entry.Key)) { if (bindingSet2.set.Count > 0) { missing = bindingSet2; } } else { count++; if (bindingSet1 == null) { bindingSet1 = bindingSet2; } else if (!BindingSet.AreEqual(bindingSet1, bindingSet2, allLhs, lhsIndex + 1)) { allMatch = false; } } newBindingSet.set.AddRange(bindingSet2.set); } if (count == 2 && allMatch) { newBindingSet.set.Clear(); foreach (Dictionary <IExpression, IExpression> dict in bindingSet1.set) { var dict2 = Remove(dict, lhs); if (dict2.Count > 0) { newBindingSet.set.Add(dict2); } } if (missing != null) { newBindingSet.set.AddRange(missing.set); } } return(newBindingSet); }