def test_geometric(self): G = (1 - x) * y - 1 S = newton_iteration(G, 9).truncate(x, 10) z = var('z') series = taylor(1 / (1 - z), z, 0, 9) series = R(series.subs({z: x})) self.assertEqual(S, series)
def test_geometric(self): G = (1-x)*y - 1 S = newton_iteration(G,9).truncate(x,10) z = var('z') series = taylor(1/(1-z),z,0,9) series = R(series.subs({z:x})) self.assertEqual(S,series)
def test_cuberoot(self): # recenter cuberoot(x) at x+1 G = (y + 1)**3 - (x + 1) S = newton_iteration(G, 9).truncate(x, 10) + 1 z = var('z') series = taylor(z**(QQ(1) / QQ(3)), z, 1, 9) series = R(series.subs({z: x + 1})) self.assertEqual(S, series)
def test_sqrt(self): # recenter sqrt(x) at x+1 G = (y + 1)**2 - (x + 1) S = newton_iteration(G, 9).truncate(x, 10) + 1 z = var('z') series = taylor(sqrt(z), z, 1, 9) series = R(series.subs({z: x + 1})) self.assertEqual(S, series)
def test_cuberoot(self): # recenter cuberoot(x) at x+1 G = (y+1)**3 - (x+1) S = newton_iteration(G,9).truncate(x,10) + 1 z = var('z') series = taylor(z**(QQ(1)/QQ(3)),z,1,9) series = R(series.subs({z:x+1})) self.assertEqual(S,series)
def test_sqrt(self): # recenter sqrt(x) at x+1 G = (y+1)**2 - (x+1) S = newton_iteration(G,9).truncate(x,10) + 1 z = var('z') series = taylor(sqrt(z),z,1,9) series = R(series.subs({z:x+1})) self.assertEqual(S,series)
def _extend1(self): "Increases the matrix size by 1" #save current self self.iv0 = copy(self) self.iv0.abel_raw0 = lambda z: self.iv0.abel0poly(z-self.iv0.x0) N = self.N A = self.A #Carleman matrix without 0-th row: Ct = A + identity_matrix(self.R,N).submatrix(1,0,N-1,N-1) AI = self.AI #assert AI*self.A == identity_matrix(N-1) if isinstance(self.f,FormalPowerSeries): coeffs = [ self.f[n] for n in xrange(0,N) ] else: x = self.f.args()[0] coeffs = taylor(self.f.substitute({x:x+self.x0sym})-self.x0sym,x,0,N).polynomial(self.R) self.Ct = matrix(self.R,N,N) self.Ct.set_block(0,0,Ct) self.Ct[0,N-1] = coeffs[N-1] for m in range(1,N-1): self.Ct[m,N-1] = psmul_at(self.Ct[0],self.Ct[m-1],N-1) self.Ct[N-1] = psmul(self.Ct[0],self.Ct[N-2]) print "C extended" self.A = self.Ct - identity_matrix(self.R,N+1).submatrix(1,0,N,N) av=self.A.column(N-1)[:N-1] ah=self.A.row(N-1)[:N-1] a_n=self.A[N-1,N-1] # print 'A:';print A # print 'A\''; print self.A # print 'ah:',ah # print 'av:',av # print 'a_n:',a_n AI0 = matrix(self.R,N,N) AI0.set_block(0,0,self.AI) horiz = matrix(self.R,1,N) horiz.set_block(0,0,(ah*AI).transpose().transpose()) horiz[0,N-1] = -1 vert = matrix(self.R,N,1) vert.set_block(0,0,(AI*av).transpose()) vert[N-1,0] = -1 self.N += 1 self.AI = AI0 + vert*horiz/(a_n-ah*AI*av)
def __init__(self,f,N,iprec=512,u=None,x0=0,fname=None,extendable=True): """ x0 is the development point for the Carleman matrix for the abel function u is the initial value such that abel(u)=0 or equivalently super(0)=u if no u is specified we have abel(x0)=0 iprec=None means try to work with the rational numbers if it is extendable then you can increase N without recomputing everything. """ self.fps = None if isinstance(f,sage.symbolic.expression.Expression): x = f.variables()[0] f = f.function(x) if isinstance(f,FormalPowerSeries): self.fps = f f = f.polynomial(N-1) self.f = f self.N = N self.iprec = iprec x0sym = x0 self.x0sym = x0sym self.prec = None self.extendable = extendable self.u = u x0name = repr(x0sym) if x0name.find('.') > -1: if x0.is_real(): x0name = repr(float(x0sym)).strip('0').replace('.',',') else: x0name = repr(complex(x0sym)).strip('0').replace('.',',') # by some reason save does not work with additional . inside the path if iprec==None: iprec_part = 'QQ' else: iprec_part = '%05d'%iprec self.path = "savings/iabel_%s"%fname + "_N%04d"%N + "_iprec" + iprec_part + "_a%s"%x0name if iprec != None: x0 = num(x0sym,iprec) if x0.is_real(): R = RealField(iprec) else: R = ComplexField(iprec) else: R = QQ self.x0 = x0 self.R = R #Carleman matrix #too slow #C = Matrix([ [ln(b)**n/factorial(n)*sum([binomial(m,k)*k**n*(b**x0)**k*(-x0)**(m-k) for k in range(m+1)]) for n in range(N)] for m in range(N)]) if self.fps == None: x = self.f.args()[0] coeffs = taylor(self.f.substitute({x:x+x0sym})-x0sym,x,0,N-1).polynomial(self.R) coeffs = [coeffs[n] for n in xrange(N-1)] else: coeffs = [ self.fps[n] for n in xrange(0,N) ] print "taylor computed" C = self.fast_carleman_matrix(coeffs) self.A = C.submatrix(1,0,N-1,N-1) - identity_matrix(R,N).submatrix(1,0,N-1,N-1) print "A computed." self._init_abel()