File:  [CENS] / python / pyGiNaC / test4 / test_pseries.py
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Sat Dec 22 14:07:23 2001 UTC (15 years, 11 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

#!/usr/bin/env python
"""
  test_pseries - run ginac.pseries tests.
  Usage:
    python test_pseries.py [-v]
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.2 $
  $Id: test_pseries.py,v 1.2 2001-12-22 14:07:23 pearu Exp $
 
  Copyright 2001 Pearu Peterson all rights reserved,
  Pearu Peterson <pearu@cens.ioc.ee>
  Permission to use, modify, and distribute this software is given under the
  terms of the LGPL.  See http://www.fsf.org
 
  NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
"""

import test_all
import ginac

class test_pseries(ginac.pseries):
    """
    >>> x=symbol ('x')
    >>> expr = 3*x**5 - x**2 + x
    >>> s = expr.series(x==2,3)
    >>> test_save (x=x,expr=expr,s=s,p=(x**5+x).series(x==0,3),q=(2*x**3++3*x).series (x==0,4),o=(x**5).series(x==0,3))
    """
    def __init__ (self):
        """
        >>> pseries ()
        Traceback (most recent call last):
        ...
        RuntimeError: use series(var==point,order) method to construct power series
        """
    def __str__ (self):
        """
        >>> str (s)
        '94+237*(-2+x)+239*(-2+x)**2+Order((-2+x)**3)'
        >>> print p
        1*x+Order(x**3)
        >>> print q
        3*x+2*x**3
        >>> print o
        Order(x**3)
        """
    def __repr__ (self):
        """
        >>> s
        pseries(relational(symbol('x'),numeric('2')),[(numeric('94'),numeric('0')),(numeric('237'),numeric('1')),(numeric('239'),numeric('2')),(Order(numeric('1')),numeric('3'))])
        """
    def get_var(self):
        """
        >>> s.get_var ()
        symbol('x')
        >>> s.get_var ().is_equal (x)
        1
        """
    def get_point (self):
        """
        >>> s.get_point()
        numeric('2')
        """
    def get_order(selg):
        """
        >>> s.get_order ()
        3
        >>> q.get_order ()
        3
        """
    def __add__ (self):
        """
        >>> p+q
        pseries(relational(symbol('x'),numeric('0')),[(numeric('4'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        >>> print p+q
        4*x+Order(x**3)
        >>> print p+2
        2+1*x+Order(x**3)
        >>> print p+2*x**2+x**6
        1*x+2*x**2+Order(x**3)
        """
    def __radd__ (self):
        """
        >>> print 1+p
        1+1*x+Order(x**3)
        >>> print x+p
        2*x+Order(x**3)
        """
    def __sub__ (self):
        """
        >>> p-q
        pseries(relational(symbol('x'),numeric('0')),[(numeric('-2'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        >>> print p-q
        (-2)*x+Order(x**3)
        """
    def __rsub__(self):
        """
        >>> print 2-p
        2+(-1)*x+Order(x**3)
        >>> print 5*x-p
        4*x+Order(x**3)
        """
    def __coerce__(self):
        """
##         >>> coerce(o,1)
##         (pseries(relational(symbol('x'),numeric('0')),[(Order(numeric('1')),numeric('3'))]), pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('0'))]))
##         >>> coerce(o,x*x)
##         (pseries(relational(symbol('x'),numeric('0')),[(Order(numeric('1')),numeric('3'))]), pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('2'))]))
##         >>> coerce(o,x*x+x**6)
##         (pseries(relational(symbol('x'),numeric('0')),[(Order(numeric('1')),numeric('3'))]), pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('2')),(Order(numeric('1')),numeric('3'))]))
##         >>> coerce(1,o)
##         (pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('0'))]), pseries(relational(symbol('x'),numeric('0')),[(Order(numeric('1')),numeric('3'))]))
        """
    def __mul__(self):
        """
        >>> p*q
        pseries(relational(symbol('x'),numeric('0')),[(numeric('3'),numeric('2')),(Order(numeric('1')),numeric('4'))])
        >>> print p*q
        3*x**2+Order(x**4)
        >>> print p*x
        1*x**2+Order(x**4)
        >>> print p*2
        2*x+Order(x**3)
        """
    def __rmul__ (self):
        """
        >>> print 2*p
        2*x+Order(x**3)
        """
    def __pow__ (self):
        """
        >>> p**2
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('2')),(Order(numeric('1')),numeric('4'))])
        >>> print p**2
        1*x**2+Order(x**4)
        >>> print p**5
        1*x**5+Order(x**7)
        >>> print p**-1
        1*x**(-1)+Order(x)
        >>> print p**-2
        1*x**(-2)+Order(1)
        >>> print p**-3
        1*x**(-3)+Order(x**(-1))
        >>> print p**-4
        1*x**(-4)+Order(x**(-2))
        >>> print p**-5
        1*x**(-5)+Order(x**(-3))
        >>> print p**-6
        1*x**(-6)+Order(x**(-4))
        >>> print pow(p**-1,2)
        1*x**(-2)+Order(1)
        >>> print pow(p**-2,1)
        1*x**(-2)+Order(1)
        >>> print pow(p**-1,1)
        1*x**(-1)+Order(x)
        >>> print pow(p**-2,2)
        1*x**(-4)+Order(x**(-2))
        >>> print pow(p**-2,3)
        1*x**(-6)+Order(x**(-4))
        >>> print pow(p**-3,6)
        1*x**(-18)+Order(x**(-16))
        >>> print p**-18
        1*x**(-18)+Order(x**(-16))
        >>> print p**18
        1*x**18+Order(x**20)
        >>> print (p**-6)**-3
        1*x**18+Order(x**20)
        """
    def __div__ (self):
        """
        >>> p/x
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('0')),(Order(numeric('1')),numeric('2'))])
        >>> print p/x
        1+Order(x**2)
        """
    def __neg__ (self):
        """
        >>> -p
        pseries(relational(symbol('x'),numeric('0')),[(numeric('-1'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        >>> print -p
        (-1)*x+Order(x**3)
        """
    def __pos__ (self):
        """
        >>> +p
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        >>> print +p
        1*x+Order(x**3)
        """
    def __rdiv__ (self):
        """
        >>> 2/p
        pseries(relational(symbol('x'),numeric('0')),[(numeric('2'),numeric('-1')),(Order(numeric('1')),numeric('1'))])
        >>> print 2/p
        2*x**(-1)+Order(x)
        """
    def convert_to_poly (self):
        """
        >>> p.convert_to_poly ().is_equal (add(Order(power(symbol('x'),numeric('3'))),symbol('x')))
        1
        >>> p.convert_to_poly (1)
        symbol('x')
        """
    def get_lorder (self):
        """
        >>> p.get_lorder ()
        1
        """
    def get_order (self):
        """
        >>> p.get_order ()
        3
        """
    def is_compatible_to (self):
        """
        >>> p.is_compatible_to (p)
        1
        >>> p.is_compatible_to (q)
        1
        >>> p.is_compatible_to (p.series (x==2,5))
        0
        """
    def is_terminating (self):
        """
        >>> p.is_terminating ()
        0
        >>> (x**3).series (x==2,10).is_terminating ()
        1
        """
    def shift_exponents (self):
        """
        >>> print p.shift_exponents (4)
        1*x**5+Order(x**7)
        >>> print p.shift_exponents (-5)
        1*x**(-4)+Order(x**(-2))
        """
    def __nonzero__ (self):
        """
        >>> not p
        0
        >>> numeric (0).series (x==0,2)
        pseries(relational(symbol('x'),numeric('0')),[])
        >>> not numeric (0).series (x==0,2)
        0
        """
    def is_equal (self):
        """
        >>> p.is_equal (p+0)
        1
        >>> p.is_equal (q)
        0
        """
    def eval (self):
        """
        >>> p.eval ()
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        """
    def evalm (self):
        """
        >>> p.evalm ()
        Traceback (most recent call last):
        ...
        RuntimeError: let_op not defined for pseries
        """
    def evalf (self):
        """
        >>> p.evalf ()
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1.0'),numeric('1')),(Order(numeric('1.0')),numeric('3'))])
        """
    def extract_archived (self):
        """
        >>> p.extract_archived ()
        {'point': [{'number': '0', 'class': 'numeric'}], 'power': [{'number': '1', 'class': 'numeric'}, {'number': '3', 'class': 'numeric'}], 'class': 'pseries', 'coeff': [{'number': '1', 'class': 'numeric'}, {'seq': [{'number': '1', 'class': 'numeric'}], 'class': 'function', 'name': 'Order'}], 'var': [{'class': 'symbol', 'name': 'x'}]}
        """
    def get_class_name (self):
        """
        >>> p.get_class_name ()
        'pseries'
        """
    def get_hash (self):
        """
        >>> type ( p.get_hash ()) is type (0)
        1
        """
    def get_precedence (self):
        """
        >>> p.get_precedence ()
        38
        """
    def is_function (self):
        """
        >>> p.is_function ()
        0
        """
    def has (self):
        """
        >>> p.has (p)
        1
        >>> p.has (x)
        1
        >>> p.has (symbol ('a'))
        0
        """
    def is_zero (self):
        """
        >>> p.is_zero ()
        0
        >>> e=numeric (0).series (x==0,2)
        >>> e.is_zero ()
        1
        """
    def nops (self):
        """
        >>> p.nops ()
        2
        """
    def op (self):
        """
        >>> p.op (0)
        symbol('x')
        >>> p.op (1).is_equal (mul(Order(numeric('1')),power(symbol('x'),numeric('3'))))
        1
        """
    def to_context (self):
        """
        >>> p.to_context ()
        '1*x+Order(x**3)'
        >>> p.to_context ('latex')
        '1 x+\\\\mathcal{O}(x^{3})'
        """
    def to_list (self):
        """
        >>> p.to_list ()==[symbol('x'), mul(Order(numeric('1')),power(symbol('x'),numeric('3')))]
        1
        """
    def coeff (self):
        """
        >>> p.coeff (x)
        numeric('1')
        >>> p.coeff (x,2)
        numeric('0')
        >>> p.coeff (x,3)
        Order(numeric('1'))
        """
    def lcoeff (self):
        """
        >>> p.lcoeff (x)
        Order(numeric('1'))
        """
    def tcoeff (self):
        """
        >>> p.tcoeff (x)
        numeric('1')
        """
    def degree (self):
        """
        >>> p.degree (x)
        3
        """
    def ldegree (self):
        """
        >>> p.ldegree (x)
        1
        """
    def numer (self):
        """
        >>> p.numer ()
        pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('1')),(Order(numeric('1')),numeric('3'))])
        """
    def denom (self):
        """
        >>> p.denom ()
        numeric('1')
        """
    def numer_denom (self):
        """
        >>> (p/3).numer_denom ()
        (pseries(relational(symbol('x'),numeric('0')),[(numeric('1/3'),numeric('1')),(Order(numeric('1')),numeric('3'))]), numeric('1'))
        """
    def __abs__ (self):
        """
        >>> abs (p)
        abs(pseries(relational(symbol('x'),numeric('0')),[(numeric('1'),numeric('1')),(Order(numeric('1')),numeric('3'))]))
        """
    def swap (self):
        """
        >>> q.swap (p)
        >>> print q,p
        1*x+Order(x**3) 3*x+2*x**3
        >>> q.swap (p)
        >>> print q,p
        3*x+2*x**3 1*x+Order(x**3)
        """

def _test():
    import test_pseries
    return test_all.test(test_pseries)

if __name__ == "__main__":
    _test()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>