(args)
Simplify a :class:`Union` using known rules

        We first start with global rules like
        'Merge all FiniteSets'

        Then we iterate through all pairs and ask the constituent sets if they
        can simplify themselves with any other constituent
Simplify a :class:`Union` using known rules
Simplify a : class : Union using known rules
def reduce(args):
        """
        Simplify a :class:`Union` using known rules

        We first start with global rules like
        'Merge all FiniteSets'

        Then we iterate through all pairs and ask the constituent sets if they
        can simplify themselves with any other constituent
        """

        # ===== Global Rules =====
        # Merge all finite sets
        finite_sets = [x for x in args if x.is_FiniteSet]
        if len(finite_sets) > 1:
            finite_set = FiniteSet(x for set in finite_sets for x in set)
            args = [finite_set] + [x for x in args if not x.is_FiniteSet]

        # ===== Pair-wise Rules =====
        # Here we depend on rules built into the constituent sets
        args = set(args)
        new_args = True
        while(new_args):
            for s in args:
                new_args = False
                for t in args - set((s,)):
                    new_set = s._union(t)
                    # This returns None if s does not know how to intersect
                    # with t. Returns the newly intersected set otherwise
                    if new_set is not None:
                        if not isinstance(new_set, set):
                            new_set = set((new_set, ))
                        new_args = (args - set((s, t))).union(new_set)
                        break
                if new_args:
                    args = new_args
                    break

        if len(args) == 1:
            return args.pop()
        else:
            return Union(args, evaluate=False)
def reduce ( args ) : # ===== Global Rules ===== # Merge all finite sets finite_sets = [ x for x in args if x . is_FiniteSet ] if len ( finite_sets ) > 1 : finite_set = FiniteSet ( x for set in finite_sets for x in set ) args = [ finite_set ] + [ x for x in args if not x . is_FiniteSet ] # ===== Pair-wise Rules ===== # Here we depend on rules built into the constituent sets args = set ( args ) new_args = True while ( new_args ) : for s in args : new_args = False for t in args - set ( ( s , ) ) : new_set = s . _union ( t ) # This returns None if s does not know how to intersect # with t. Returns the newly intersected set otherwise if new_set is not None : if not isinstance ( new_set , set ) : new_set = set ( ( new_set , ) ) new_args = ( args - set ( ( s , t ) ) ) . union ( new_set ) break if new_args : args = new_args break if len ( args ) == 1 : return args . pop ( ) else : return Union ( args , evaluate = False )