class LengthNode(with_metaclass(Singleton, Basic)): """Base class representing one length of an iterator""" pass
class Grid(with_metaclass(_BackendSelector, grid.Grid)): pass
class CacheManager(with_metaclass(_BackendSelector, caching.CacheManager)): pass
class Constant(with_metaclass(_BackendSelector, constant.Constant)): pass
class SparseTimeFunction( with_metaclass(_BackendSelector, sparse.SparseTimeFunction)): pass
class NativeOp(with_metaclass(Singleton, Basic)): """Base type for native operands.""" pass
class Scalar(with_metaclass(_BackendSelector, basic.Scalar)): pass
class ElementDomain(with_metaclass(Singleton, Basic)): pass
class Domain(with_metaclass(OptionType, Option)): """``domain`` option to polynomial manipulation functions. """ option = 'domain' requires = [] excludes = ['field', 'greedy', 'split', 'gaussian', 'extension'] after = ['gens'] _re_realfield = re.compile(r"^(R|RR)(_(\d+))?$") _re_complexfield = re.compile(r"^(C|CC)(_(\d+))?$") _re_finitefield = re.compile(r"^(FF|GF)\((\d+)\)$") _re_polynomial = re.compile(r"^(Z|ZZ|Q|QQ)\[(.+)\]$") _re_fraction = re.compile(r"^(Z|ZZ|Q|QQ)\((.+)\)$") _re_algebraic = re.compile(r"^(Q|QQ)\<(.+)\>$") @classmethod def preprocess(cls, domain): if isinstance(domain, sympy.polys.domains.Domain): return domain elif hasattr(domain, 'to_domain'): return domain.to_domain() elif isinstance(domain, string_types): if domain in ['Z', 'ZZ']: return sympy.polys.domains.ZZ if domain in ['Q', 'QQ']: return sympy.polys.domains.QQ if domain == 'EX': return sympy.polys.domains.EX r = cls._re_realfield.match(domain) if r is not None: _, _, prec = r.groups() if prec is None: return sympy.polys.domains.RR else: return sympy.polys.domains.RealField(int(prec)) r = cls._re_complexfield.match(domain) if r is not None: _, _, prec = r.groups() if prec is None: return sympy.polys.domains.CC else: return sympy.polys.domains.ComplexField(int(prec)) r = cls._re_finitefield.match(domain) if r is not None: return sympy.polys.domains.FF(int(r.groups()[1])) r = cls._re_polynomial.match(domain) if r is not None: ground, gens = r.groups() gens = list(map(sympify, gens.split(','))) if ground in ['Z', 'ZZ']: return sympy.polys.domains.ZZ.poly_ring(*gens) else: return sympy.polys.domains.QQ.poly_ring(*gens) r = cls._re_fraction.match(domain) if r is not None: ground, gens = r.groups() gens = list(map(sympify, gens.split(','))) if ground in ['Z', 'ZZ']: return sympy.polys.domains.ZZ.frac_field(*gens) else: return sympy.polys.domains.QQ.frac_field(*gens) r = cls._re_algebraic.match(domain) if r is not None: gens = list(map(sympify, r.groups()[1].split(','))) return sympy.polys.domains.QQ.algebraic_field(*gens) raise OptionError('expected a valid domain specification, got %s' % domain) @classmethod def postprocess(cls, options): if 'gens' in options and 'domain' in options and options['domain'].is_Composite and \ (set(options['domain'].symbols) & set(options['gens'])): raise GeneratorsError( "ground domain and generators interfere together") elif ('gens' not in options or not options['gens']) and \ 'domain' in options and options['domain'] == sympy.polys.domains.EX: raise GeneratorsError("you have to provide generators because EX domain was requested")
class Integers(with_metaclass(Singleton, Set)): """ Represents all integers: positive, negative and zero. This set is also available as the Singleton, S.Integers. Examples ======== >>> from sympy import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Integers) >>> next(iterable) 0 >>> next(iterable) 1 >>> next(iterable) -1 >>> next(iterable) 2 >>> pprint(S.Integers.intersect(Interval(-4, 4))) {-4, -3, ..., 4} See Also ======== Naturals0 : non-negative integers Integers : positive and negative integers and zero """ is_iterable = True is_empty = False is_finite_set = False def _contains(self, other): if not isinstance(other, Expr): return S.false return other.is_integer def __iter__(self): yield S.Zero i = S.One while True: yield i yield -i i = i + 1 @property def _inf(self): return S.NegativeInfinity @property def _sup(self): return S.Infinity @property def _boundary(self): return self def as_relational(self, x): from sympy.functions.elementary.integers import floor return And(Eq(floor(x), x), -oo < x, x < oo) def _eval_is_subset(self, other): return Range(-oo, oo).is_subset(other) def _eval_is_superset(self, other): return Range(-oo, oo).is_superset(other)
class Naturals(with_metaclass(Singleton, Set)): """ Represents the natural numbers (or counting numbers) which are all positive integers starting from 1. This set is also available as the Singleton, S.Naturals. Examples ======== >>> from sympy import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Naturals) >>> next(iterable) 1 >>> next(iterable) 2 >>> next(iterable) 3 >>> pprint(S.Naturals.intersect(Interval(0, 10))) {1, 2, ..., 10} See Also ======== Naturals0 : non-negative integers (i.e. includes 0, too) Integers : also includes negative integers """ is_iterable = True _inf = S.One _sup = S.Infinity is_empty = False is_finite_set = False def _contains(self, other): if not isinstance(other, Expr): return False elif other.is_positive and other.is_integer: return True elif other.is_integer is False or other.is_positive is False: return False def _eval_is_subset(self, other): return Range(1, oo).is_subset(other) def _eval_is_superset(self, other): return Range(1, oo).is_superset(other) def __iter__(self): i = self._inf while True: yield i i = i + 1 @property def _boundary(self): return self def as_relational(self, x): from sympy.functions.elementary.integers import floor return And(Eq(floor(x), x), x >= self.inf, x < oo)
class Reals(with_metaclass(Singleton, Interval)): def __new__(cls): return Interval.__new__(cls, -S.Infinity, S.Infinity)
class Integers(with_metaclass(Singleton, Set)): """ Represents all integers: positive, negative and zero. This set is also available as the Singleton, S.Integers. Examples ======== >>> from sympy import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Integers) >>> next(iterable) 0 >>> next(iterable) 1 >>> next(iterable) -1 >>> next(iterable) 2 >>> pprint(S.Integers.intersect(Interval(-4, 4))) {-4, -3, ..., 4} See Also ======== Naturals0 : non-negative integers Integers : positive and negative integers and zero """ is_iterable = True def _intersect(self, other): from sympy.functions.elementary.integers import floor, ceiling if other.is_Interval and other.measure < S.Infinity: s = Range(ceiling(other.left), floor(other.right) + 1) return s.intersect(other) # take out endpoints if open interval return None def _contains(self, other): from sympy.assumptions.ask import ask, Q if ask(Q.integer(other)): return True return False def __iter__(self): yield S.Zero i = S(1) while True: yield i yield -i i = i + 1 @property def _inf(self): return -S.Infinity @property def _sup(self): return S.Infinity @property def _boundary(self): return self
class SpaceType(with_metaclass(Singleton, Basic)): """Base class representing function space types""" pass
class CacheManager(with_metaclass(_BackendSelector, types.CacheManager)): pass
class Polys(with_metaclass(OptionType, BooleanOption, Flag)): """``polys`` flag to polynomial manipulation functions. """ option = 'polys'
class Integers(with_metaclass(Singleton, Set)): """ Represents all integers: positive, negative and zero. This set is also available as the Singleton, S.Integers. Examples ======== >>> from sympy import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Integers) >>> next(iterable) 0 >>> next(iterable) 1 >>> next(iterable) -1 >>> next(iterable) 2 >>> pprint(S.Integers.intersect(Interval(-4, 4))) {-4, -3, ..., 4} See Also ======== Naturals0 : non-negative integers Integers : positive and negative integers and zero """ is_iterable = True def _intersect(self, other): from sympy.functions.elementary.integers import floor, ceiling if other is Interval(S.NegativeInfinity, S.Infinity) or other is S.Reals: return self elif other.is_Interval: s = Range(ceiling(other.left), floor(other.right) + 1) return s.intersect(other) # take out endpoints if open interval return None def _contains(self, other): if other.is_integer: return S.true elif other.is_integer is False: return S.false def __iter__(self): yield S.Zero i = S.One while True: yield i yield -i i = i + 1 @property def _inf(self): return -S.Infinity @property def _sup(self): return S.Infinity @property def _boundary(self): return self def _eval_imageset(self, f): from sympy import Wild expr = f.expr if len(f.variables) > 1: return n = f.variables[0] a = Wild('a') b = Wild('b') match = expr.match(a * n + b) if match[a].is_negative: expr = -expr match = expr.match(a * n + b) if match[a] is S.One and match[b].is_integer: expr = expr - match[b] return ImageSet(Lambda(n, expr), S.Integers)
class MySingleton(with_metaclass(Singleton, Basic)): def __new__(cls): global instantiated instantiated += 1 return Basic.__new__(cls)
class DataType(with_metaclass(Singleton, Basic)): """Base class representing native datatypes""" pass
class Scalar(with_metaclass(_BackendSelector, types.Scalar)): pass
class Array(with_metaclass(_BackendSelector, array.Array)): pass
class Array(with_metaclass(_BackendSelector, types.Array)): pass
class TimeFunction(with_metaclass(_BackendSelector, dense.TimeFunction)): pass
class Constant(with_metaclass(_BackendSelector, function.Constant)): pass
class PrecomputedSparseTimeFunction( with_metaclass(_BackendSelector, sparse.PrecomputedSparseTimeFunction)): # noqa pass
class Function(with_metaclass(_BackendSelector, function.Function)): pass
class Operator(with_metaclass(_BackendSelector, operator.Operator)): pass
class SparseFunction(with_metaclass(_BackendSelector, function.SparseFunction)): pass
class Integers(with_metaclass(Singleton, Set)): """ Represents all integers: positive, negative and zero. This set is also available as the Singleton, S.Integers. Examples ======== >>> from sympy import S, Interval, pprint >>> 5 in S.Naturals True >>> iterable = iter(S.Integers) >>> next(iterable) 0 >>> next(iterable) 1 >>> next(iterable) -1 >>> next(iterable) 2 >>> pprint(S.Integers.intersect(Interval(-4, 4))) {-4, -3, ..., 4} See Also ======== Naturals0 : non-negative integers Integers : positive and negative integers and zero """ is_iterable = True def _intersect(self, other): from sympy.functions.elementary.integers import floor, ceiling if other is Interval(S.NegativeInfinity, S.Infinity) or other is S.Reals: return self elif other.is_Interval: s = Range(ceiling(other.left), floor(other.right) + 1) return s.intersect(other) # take out endpoints if open interval return None def _contains(self, other): if other.is_integer: return S.true elif other.is_integer is False: return S.false def _union(self, other): intersect = Intersection(self, other) if intersect == self: return other elif intersect == other: return self def __iter__(self): yield S.Zero i = S.One while True: yield i yield -i i = i + 1 @property def _inf(self): return -S.Infinity @property def _sup(self): return S.Infinity @property def _boundary(self): return self def _eval_imageset(self, f): expr = f.expr if not isinstance(expr, Expr): return if len(f.variables) > 1: return n = f.variables[0] # f(x) + c and f(-x) + c cover the same integers # so choose the form that has the fewest negatives c = f(0) fx = f(n) - c f_x = f(-n) - c neg_count = lambda e: sum(_coeff_isneg(_) for _ in Add.make_args(e)) if neg_count(f_x) < neg_count(fx): expr = f_x + c a = Wild('a', exclude=[n]) b = Wild('b', exclude=[n]) match = expr.match(a*n + b) if match and match[a]: # canonical shift expr = match[a]*n + match[b] % match[a] if expr != f.expr: return ImageSet(Lambda(n, expr), S.Integers)
class IndexNode(with_metaclass(Singleton, Basic)): """Base class representing one index of an iterator""" pass