예제 #1
0
def isqrt(c):
  if not isinstance(c,pol): return 1/math.sqrt(c)
  a0,p=c.separate(); p/=a0
  lst=[1/math.sqrt(a0)]
  for n in range(1,c.order+1):
    lst.append(-lst[-1]/a0/2/n*(2*n-1))
  return phorner(lst,p)
예제 #2
0
def sinh(c):
  """Compute Sinh using a Taylor expansion
  """
  if not isinstance(c,pol): return math.sinh(c)
  a0,p=c.separate();
  lst=[math.sinh(a0),math.cosh(a0)]
  for n in range(2,c.order+1):
    lst.append( lst[-2]/n/(n-1))
  return phorner(lst,p)
예제 #3
0
def cos(c):
  """
  cos(a+x)= cos(a) sin(x) - sin(a) cos(x)
  """
  if not isinstance(c,pol): return math.cos(c)
  a0,p=c.separate();
  lst=[math.cos(a0),-math.sin(a0)]
  for n in range(2,c.order+1):
    lst.append( -lst[-2]/n/(n-1))
  return phorner(lst,p)
예제 #4
0
def log(c):
  """Logarithm of a polynomial
    log(a+x)=log(a)-log(1+x/a)
    >>> from pol import *
    >>> print log(exp(pol('1+x')))
    1.0 + x
  """
  if not isinstance(c,pol): return math.log(c)
  a0,p=c.separate(); p/=a0
  lst=[log(a0),1.]
  for n in range(2,c.order+1):
    lst.append( -lst[-1]/n*(n-1)   )
  return phorner(lst,p)
예제 #5
0
def exp(c):
  """Exponential of a polynomial
    exp(a+x) = exp(a)exp(x)
    >>> from pol import *
    >>> print log(exp(pol('1+x')))
    1.0 + x
  """
  if not isinstance(c,pol): return math.exp(c)
  a0,p=c.separate();
  lst=[exp(a0)]
  for n in range(1,c.order+1):
    lst.append(lst[-1]/n)
  return phorner(lst,p)
예제 #6
0
def sqrt(c):
  """Square root of a polynomial
    >>> from pol import *
    >>> print sqrt(pol('1+x'))**2
    1.0 + x
    >>> print sqrt(pol('1j+x'))**2
    1j -1j*x
  """
  if not isinstance(c,pol): return math.sqrt(c)
  a0,p=c.separate(); p/=a0
  lst=[math.sqrt(a0)]
  for n in range(1,c.order+1):
    lst.append(-lst[-1]/2/n*(2*n-3))
  return phorner(lst,p)