Example #1
0
 def __new__(cls, *args, **kwargs):
     from diofant.geometry.point import Point
     args = [
         Tuple(*a)
         if is_sequence(a) and not isinstance(a, Point) else sympify(a)
         for a in args
     ]
     return Basic.__new__(cls, *args)
Example #2
0
    def __new__(cls, *args):
        from diofant.functions.elementary.integers import ceiling
        # expand range
        slc = slice(*args)
        start, stop, step = slc.start or 0, slc.stop, slc.step or 1
        try:
            start, stop, step = [
                w if w in [S.NegativeInfinity, S.Infinity] else Integer(
                    as_int(w)) for w in (start, stop, step)
            ]
        except ValueError:
            raise ValueError("Inputs to Range must be Integer Valued\n" +
                             "Use ImageSets of Ranges for other cases")

        if not step.is_finite:
            raise ValueError("Infinite step is not allowed")
        if start == stop:
            return S.EmptySet

        n = ceiling((stop - start) / step)
        if n <= 0:
            return S.EmptySet

        # normalize args: regardless of how they are entered they will show
        # canonically as Range(inf, sup, step) with step > 0
        if n.is_finite:
            start, stop = sorted((start, start + (n - 1) * step))
        else:
            start, stop = sorted((start, stop - step))

        step = abs(step)
        if (start, stop) == (S.NegativeInfinity, S.Infinity):
            raise ValueError("Both the start and end value of "
                             "Range cannot be unbounded")
        else:
            return Basic.__new__(cls, start, stop + step, step)
Example #3
0
 def eval(cls, *args):
     try:
         newargs = []
         for x in args:
             if isinstance(x, Number) or x in (0, 1):
                 newargs.append(True if x else False)
             else:
                 newargs.append(x)
         A, B = newargs
     except ValueError:
         raise ValueError("%d operand(s) used for an Implies "
                          "(pairs are required): %s" %
                          (len(args), str(args)))
     if A == S.true or A == S.false or B == S.true or B == S.false:
         return Or(Not(A), B)
     elif A == B:
         return S.true
     elif A.is_Relational and B.is_Relational:
         if A.canonical == B.canonical:
             return S.true
         if (~A).canonical == B.canonical:
             return B
     else:
         return Basic.__new__(cls, *args)
Example #4
0
 def __new__(cls):
     global instantiated
     instantiated += 1
     return Basic.__new__(cls)
Example #5
0
 def __new__(cls):
     global instantiated
     instantiated += 1
     return Basic.__new__(cls)
Example #6
0
 def __new__(cls, lamda, base_set):
     return Basic.__new__(cls, lamda, base_set)