internal static Set IntersectFiniteSetAndSet(FiniteSet finite, Set set)
        {
            if (set is FiniteSet another)
            {
                return(FiniteSet.Intersect(finite, another));
            }
            var fsb = new FiniteSetBuilder();
            var amb = new FiniteSetBuilder();

            foreach (var elem in finite)
            {
                if (!set.TryContains(elem, out var contains))
                {
                    amb.Add(elem);
                }
                else if (contains)
                {
                    fsb.Add(elem);
                }
            }
            return(amb.IsEmpty ? fsb.ToFiniteSet() : amb.ToFiniteSet().Unite(fsb.ToFiniteSet()));
        }
Beispiel #2
0
        internal static Set SetSubtractSetAndFiniteSet(Set set, FiniteSet finite)
        {
            if (set is FiniteSet another)
            {
                return(FiniteSet.Subtract(another, finite));
            }
            var fsb = new FiniteSetBuilder(finite);

            foreach (var el in finite)
            {
                if (set.TryContains(el, out var contains) && !contains)
                {
                    fsb.Remove(el);
                }
            }
            return(fsb.IsEmpty ? set : set.SetSubtract(fsb.ToFiniteSet()));
        }