Esempio n. 1
0
        internal static Set UniteFiniteSetAndSet(FiniteSet finite, Set set)
        {
            if (set is FiniteSet another)
            {
                return(FiniteSet.Unite(finite, another));
            }
            var sb = new FiniteSetBuilder();

            if (set is Interval(var left, var leftClosed, var right, var rightClosed) inter)
            {
                var newLeftClosed  = leftClosed;
                var newRightClosed = rightClosed;
                foreach (var el in finite)
                {
                    if (!set.TryContains(el, out var contains) || !contains)
                    {
                        if (el == left)
                        {
                            newLeftClosed = true;
                        }
                        else if (el == right)
                        {
                            newRightClosed = true;
                        }
                        else
                        {
                            sb.Add(el);
                        }
                    }
                }
                set = inter.New(left, newLeftClosed, right, newRightClosed);
            }
        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()));
        }