public override PathCond Or(PathCond other) { if (other is CachedAtom && conds.Contains(((CachedAtom)other).Negate())) { // Reduce Or(OR(...,e,...), NOT(e)) and Or(OR(...,NOT(e),...), e) to TRUE return TRUE; } else if (other is Disj) { HashList<PathCond> result = new HashList<PathCond>(); result.AddAll(conds); foreach (PathCond cond in ((Disj)other).conds) { if (cond is CachedAtom && conds.Contains((cond as CachedAtom).Negate())) { // Reduce Or(OR(...,e,...),OR(...,NOT(e),...)) to TRUE // and Or(OR(...,NOT(e),...),OR(...,e,...)) to TRUE return TRUE; } result.Add(cond); } return Disj.Make(result.ToArray()); } else if (other is Conj) { if (((Conj)other).conds.Contains(this)) { // Reduce (pi | (p1 & ... & pn)) to pi return this; } else { if (((Conj)other).conds.Any(cond => conds.Contains(cond))) { return this; } } return Disj.Make(AddItem(this.conds, other)); } else { return Disj.Make(AddItem(this.conds, other)); } }
protected static PathCond[] AddItem(IEnumerable <PathCond> set, PathCond item) { HashList <PathCond> result = new HashList <PathCond>(); result.AddAll(set); result.Add(item); return(result.ToArray()); }
public override PathCond Or(PathCond other) { if (other is CachedAtom && conds.Contains(((CachedAtom)other).Negate())) { // Reduce Or(OR(...,e,...), NOT(e)) and Or(OR(...,NOT(e),...), e) to TRUE return(TRUE); } else if (other is Disj) { HashList <PathCond> result = new HashList <PathCond>(); result.AddAll(conds); foreach (PathCond cond in ((Disj)other).conds) { if (cond is CachedAtom && conds.Contains((cond as CachedAtom).Negate())) { // Reduce Or(OR(...,e,...),OR(...,NOT(e),...)) to TRUE // and Or(OR(...,NOT(e),...),OR(...,e,...)) to TRUE return(TRUE); } result.Add(cond); } return(Disj.Make(result.ToArray())); } else if (other is Conj) { if (((Conj)other).conds.Contains(this)) { // Reduce (pi | (p1 & ... & pn)) to pi return(this); } else { if (((Conj)other).conds.Any(cond => conds.Contains(cond))) { return(this); } } return(Disj.Make(AddItem(this.conds, other))); } else { return(Disj.Make(AddItem(this.conds, other))); } }