Coverage for /usr/lib/python3/dist-packages/sympy/series/series_class.py: 42%
53 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1"""
2Contains the base class for series
3Made using sequences in mind
4"""
6from sympy.core.expr import Expr
7from sympy.core.singleton import S
8from sympy.core.cache import cacheit
11class SeriesBase(Expr):
12 """Base Class for series"""
14 @property
15 def interval(self):
16 """The interval on which the series is defined"""
17 raise NotImplementedError("(%s).interval" % self)
19 @property
20 def start(self):
21 """The starting point of the series. This point is included"""
22 raise NotImplementedError("(%s).start" % self)
24 @property
25 def stop(self):
26 """The ending point of the series. This point is included"""
27 raise NotImplementedError("(%s).stop" % self)
29 @property
30 def length(self):
31 """Length of the series expansion"""
32 raise NotImplementedError("(%s).length" % self)
34 @property
35 def variables(self):
36 """Returns a tuple of variables that are bounded"""
37 return ()
39 @property
40 def free_symbols(self):
41 """
42 This method returns the symbols in the object, excluding those
43 that take on a specific value (i.e. the dummy symbols).
44 """
45 return ({j for i in self.args for j in i.free_symbols}
46 .difference(self.variables))
48 @cacheit
49 def term(self, pt):
50 """Term at point pt of a series"""
51 if pt < self.start or pt > self.stop:
52 raise IndexError("Index %s out of bounds %s" % (pt, self.interval))
53 return self._eval_term(pt)
55 def _eval_term(self, pt):
56 raise NotImplementedError("The _eval_term method should be added to"
57 "%s to return series term so it is available"
58 "when 'term' calls it."
59 % self.func)
61 def _ith_point(self, i):
62 """
63 Returns the i'th point of a series
64 If start point is negative infinity, point is returned from the end.
65 Assumes the first point to be indexed zero.
67 Examples
68 ========
70 TODO
71 """
72 if self.start is S.NegativeInfinity:
73 initial = self.stop
74 step = -1
75 else:
76 initial = self.start
77 step = 1
79 return initial + i*step
81 def __iter__(self):
82 i = 0
83 while i < self.length:
84 pt = self._ith_point(i)
85 yield self.term(pt)
86 i += 1
88 def __getitem__(self, index):
89 if isinstance(index, int):
90 index = self._ith_point(index)
91 return self.term(index)
92 elif isinstance(index, slice):
93 start, stop = index.start, index.stop
94 if start is None:
95 start = 0
96 if stop is None:
97 stop = self.length
98 return [self.term(self._ith_point(i)) for i in
99 range(start, stop, index.step or 1)]