Public Member Functions | |
def | __init__ |
def | add |
def | ev |
def | evh |
def | evmh |
def | int |
def | lindiv |
def | neg |
def | set |
def | simp |
Public Attributes | |
acc | |
coefficients |
Does basic manipulations with Taylor Series (centered at 0). An example call to ts: a = ts(7, 23, [1<<23, 2<<23, 3<<23]) -- now, a represents 1 + 2x + 3x^2. Here, computations will be done to degree 7, with accuracy 2^(-23). Input coefficients must be integers.
Definition at line 234 of file pyecm.py.
def pyecm::ts::__init__ | ( | self, | ||
degree, | ||||
acc, | ||||
p | ||||
) |
Definition at line 238 of file pyecm.py.
00238 : 00239 self.acc = acc 00240 self.coefficients = p[:degree + 1] 00241 while len(self.coefficients) <= degree: 00242 self.coefficients.append(0) 00243 def add(self, a, b):
def pyecm::ts::add | ( | self, | ||
a, | ||||
b | ||||
) |
Adds a and b
Definition at line 244 of file pyecm.py.
00244 : 00245 '''Adds a and b''' 00246 b_ = b.coefficients[:] 00247 a_ = a.coefficients[:] 00248 self.coefficients = [] 00249 00250 while len(b_) > len(a_): 00251 a_.append(0) 00252 while len(b_) < len(a_): 00253 b_.append(0) 00254 00255 for i in xrange(len(a_)): 00256 self.coefficients.append(a_[i] + b_[i]) 00257 00258 self.acc = a.acc 00259 def ev(self, x):
def pyecm::ts::ev | ( | self, | ||
x | ||||
) |
Returns a(x)
Definition at line 260 of file pyecm.py.
00260 : 00261 '''Returns a(x)''' 00262 answer = 0 00263 for i in xrange(len(self.coefficients) - 1, -1, -1): 00264 answer *= x 00265 answer += self.coefficients[i] 00266 return answer 00267 def evh(self):
def pyecm::ts::evh | ( | self | ) |
Returns a(1/2)
Definition at line 268 of file pyecm.py.
00268 : 00269 '''Returns a(1/2)''' 00270 answer = 0 00271 for i in xrange(len(self.coefficients) - 1, -1, -1): 00272 answer >>= 1 00273 answer += self.coefficients[i] 00274 return answer 00275 def evmh(self):
def pyecm::ts::evmh | ( | self | ) |
Returns a(-1/2)
Definition at line 276 of file pyecm.py.
00276 : 00277 '''Returns a(-1/2)''' 00278 answer = 0 00279 for i in xrange(len(self.coefficients) - 1, -1, -1): 00280 answer = - answer >> 1 00281 answer += self.coefficients[i] 00282 return answer 00283 def int(self):
def pyecm::ts::int | ( | self | ) |
Replaces a by an integral of a
Definition at line 284 of file pyecm.py.
00284 : 00285 '''Replaces a by an integral of a''' 00286 self.coefficients = [0] + self.coefficients 00287 for i in xrange(1, len(self.coefficients)): 00288 self.coefficients[i] /= i 00289 def lindiv(self, a):
def pyecm::ts::lindiv | ( | self, | ||
a | ||||
) |
a.lindiv(k) -- sets a/(x-k/2) for integer k
Definition at line 290 of file pyecm.py.
00290 : 00291 '''a.lindiv(k) -- sets a/(x-k/2) for integer k''' 00292 for i in xrange(len(self.coefficients) - 1): 00293 self.coefficients[i] <<= 1 00294 self.coefficients[i] /= a 00295 self.coefficients[i + 1] -= self.coefficients[i] 00296 self.coefficients[-1] <<= 1 00297 self.coefficients[-1] /= a 00298 def neg(self):
def pyecm::ts::neg | ( | self | ) |
Sets a to -a
Definition at line 299 of file pyecm.py.
00299 : 00300 '''Sets a to -a''' 00301 for i in xrange(len(self.coefficients)): 00302 self.coefficients[i] = - self.coefficients[i] 00303 def set(self, a):
def pyecm::ts::set | ( | self, | ||
a | ||||
) |
def pyecm::ts::simp | ( | self | ) |
Turns a into a type of Taylor series that can be fed into ev, but cannot be computed with further.
Definition at line 309 of file pyecm.py.
00309 : 00310 '''Turns a into a type of Taylor series that can be fed into ev, but cannot be computed with further.''' 00311 for i in xrange(len(self.coefficients)): 00312 shift = max(0, int(math.log(abs(self.coefficients[i]) + 1) / LOG_2) - 1000) 00313 self.coefficients[i] = float(self.coefficients[i] >> shift) 00314 shift = self.acc - shift 00315 for _ in xrange(shift >> 9): 00316 self.coefficients[i] /= BIG 00317 self.coefficients[i] /= 2.0**(shift & 511) 00318 if abs(self.coefficients[i] / self.coefficients[0]) <= SMALL: 00319 self.coefficients = self.coefficients[:i] 00320 break 00321 00322 # Functions are declared in alphabetical order except when dependencies force them to be at the end. 00323 def add(p1, p2, n):