File:  [CENS] / python / pyGiNaC / test4 / test_power.py
Revision 1.4: 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_power - run ginac.power tests.
  Usage:
    python test_power.py [-v]
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.4 $
  $Id: test_power.py,v 1.4 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_power(ginac.power):
    """
    >>> a=symbol ('a')
    >>> b=symbol ('b')
    >>> test_save (p=a**b,q=2**a,a=a,b=b,r=a**-2)
    """
    def __init__(self):
        """
        >>> power(2, 3)
        numeric('8')
        >>> power(symbol('a'), 2)
        power(symbol('a'),numeric('2'))
        >>> power(symbol('a'), 0)
        numeric('1')
        """
    def get_precedence(self):
        """
        >>> power(symbol('a'), 2).get_precedence()
        60
        """
    def get_class_name(self):
        """
        >>> power(symbol('a'), 2).get_class_name()
        'power'
        """
    def __repr__ (self):
        """
        >>> power (a,2)
        power(symbol('a'),numeric('2'))
        """
    def __str__ (self):
        """
        >>> p = power(symbol('a'),2)
        >>> str(p)
        'a**2'
        >>> str (power(2,p))
        '2**(a**2)'
        >>> str (power(numeric(2,3),numeric(5,4)))
        '2/3*(2/3)**(1/4)'
        >>> str (a**2)
        'a**2'
        >>> str (a**(a+1))
        'a**(1+a)'
        >>> str (a**a)
        'a**a'
        >>> str ((1+a)**a)
        '(1+a)**a'
        >>> str (a**-1)
        'a**(-1)'
        >>> str (a**-4)
        'a**(-4)'
        >>> str ((-2)**a)
        '(-2)**a'
        >>> str((-1)**a)
        '(-1)**a'
        """
    def __nonzero__ (self):
        """
        >>> not p
        0
        """
    def eval (self):
        """
        >>> q.eval ()
        power(numeric('2'),symbol('a'))
        """
    def evalm (self):
        """
        >>> q.evalm ()
        power(numeric('2'),symbol('a'))
        """
    def evalf (self):
        """
        >>> q.evalf ()
        power(numeric('2.0'),symbol('a'))
        """
    def extract_archived (self):
        """
        >>> q.extract_archived ()
        {'basis': [{'number': '2', 'class': 'numeric'}], 'class': 'power', 'exponent': [{'class': 'symbol', 'name': 'a'}]}
        """
    def get_hash (self):
        """
        >>> type ( p.get_hash ()) is type (0)
        1
        """
    def has (self):
        """
        >>> q.has (2)
        1
        >>> q.has (q)
        1
        >>> q.has (symbol ('a'))
        1
        >>> q.has (symbol ('b'))
        0
        >>> q.has (3)
        0
        >>> q.has (p)
        0
        """
    def is_equal (self):
        """
        >>> p.is_equal (p)
        1
        >>> p.is_equal (q)
        0
        >>> p.is_equal (a**b)
        1
        >>> p.is_equal (a)
        0
        >>> q.is_equal (2)
        0
        """
    def is_zero (self):
        """
        >>> p.is_zero ()
        0
        """
    def nops (self):
        """
        >>> q.nops ()
        2
        """
    def op (self):
        """
        >>> q.op (0)
        numeric('2')
        >>> q.op (1)
        symbol('a')
        >>> q.op (-1)
        Traceback (most recent call last):
        ...
        IndexError: op(): index out of range
        """
    def to_list (self):
        """
        >>> q.to_list ()
        [numeric('2'), symbol('a')]
        """
    def swap (self):
        """
        >>> q.swap (a)
        >>> q,a
        (symbol('a'), power(numeric('2'),symbol('a')))
        >>> q.swap (a)
        >>> q,a
        (power(numeric('2'),symbol('a')), symbol('a'))
        """
    def to_context (self):
        """
        >>> q.to_context ('context')
        '2^a'
        >>> q.to_context ('python')
        '2**a'
        >>> q.to_context ()
        '2**a'
        >>> q.to_context ('latex')
        '2^{a}'
        >>> q.to_context ('csrc')
        'pow(2.000000e+00,a)'
        >>> q.to_context ('csrc_float')
        'pow(2.000000e+00,a)'
        >>> q.to_context ('csrc_double')
        'pow(2.000000e+00,a)'
        >>> q.to_context ('csrc_cl_N')
        'expt(cln::cl_F("2.0"),a)'
        """
    def __add__ (self):
        """
        >>> p+1
        add(power(symbol('a'),symbol('b')),numeric('1'))
        """
    def __radd__ (self):
        """
        >>> 1+p
        add(power(symbol('a'),symbol('b')),numeric('1'))
        """
    def __sub__ (self):
        """
        >>> p-q
        add(mul(power(numeric('2'),symbol('a')),numeric('-1')),power(symbol('a'),symbol('b')))
        """
    def __rsub__ (self):
        """
        >>> 3-q
        add(mul(power(numeric('2'),symbol('a')),numeric('-1')),numeric('3'))
        """
    def __mul__ (self):
        """
        >>> q*3
        mul(power(numeric('2'),symbol('a')),numeric('3'))
        """
    def __rmul__ (self):
        """
        >>> 3*p
        mul(power(symbol('a'),symbol('b')),numeric('3'))
        """
    def __div__ (self):
        """
        >>> p/3
        mul(power(symbol('a'),symbol('b')),numeric('1/3'))
        """
    def __rdiv__ (self):
        """
        >>> 3/p
        mul(power(power(symbol('a'),symbol('b')),numeric('-1')),numeric('3'))
        """
    def __pow__ (self):
        """
        >>> q**3
        power(power(numeric('2'),symbol('a')),numeric('3'))
        """
    def __rpow__ (self):
        """
        >>> 3**q
        power(numeric('3'),power(numeric('2'),symbol('a')))
        """
    def __coerce__ (self):
        """
        >>> coerce (q,2)
        (power(numeric('2'),symbol('a')), numeric('2'))
        """
    def __lt__ (self):
        """
        >>> q<2
        relational(power(numeric('2'),symbol('a')),numeric('2'),'<')
        """
    def __le__ (self):
        """
        >>> q<=2
        relational(power(numeric('2'),symbol('a')),numeric('2'),'<=')
        """
    def __gt__ (self):
        """
        >>> q>2
        relational(numeric('2'),power(numeric('2'),symbol('a')),'<')
        >>> 2>q
        relational(power(numeric('2'),symbol('a')),numeric('2'),'<')
        """
    def __ge__ (self):
        """
        >>> q>=2
        relational(numeric('2'),power(numeric('2'),symbol('a')),'<=')
        """
    def __eq__ (self):
        """
        >>> q==2
        relational(power(numeric('2'),symbol('a')),numeric('2'),'==')
        """
    def __ne__ (self):
        """
        >>> q!=2
        relational(power(numeric('2'),symbol('a')),numeric('2'),'!=')
        """
    def __neg__ (self):
        """
        >>> -q
        mul(power(numeric('2'),symbol('a')),numeric('-1'))
        """
    def __pos__ (self):
        """
        >>> +p
        power(symbol('a'),symbol('b'))
        """
    def __abs__ (self):
        """
        >>> abs (q)
        abs(power(numeric('2'),symbol('a')))
        """
    def diff (self):
        """
        >>> p.diff (a)
        mul(symbol('b'),power(symbol('a'),symbol('b')),power(symbol('a'),numeric('-1')))
        >>> print p.diff (a)
        b*a**b*a**(-1)
        >>> print p.diff (b)
        a**b*log(a)
        >>> print q.diff (a)
        2**a*log(2)
        """
    def numer (self):
        """
        >>> q.numer ()
        power(numeric('2'),symbol('a'))
        """
    def denom (self):
        """
        >>> q.denom ()
        numeric('1')
        """
    def numer_denom (self):
        """
        >>> p.numer_denom ()
        (power(symbol('a'),symbol('b')), numeric('1'))
        """
    def is_function (self):
        """
        >>> p.is_function ()
        0
        """
    def coeff (self):
        """
        >>> p.coeff (a)
        numeric('0')
        >>> p.coeff (b)
        numeric('0')
        >>> p.coeff (a)
        numeric('0')
        """
    def lcoeff (self):
        """
        #>>> p.lcoeff (a)
        #power(symbol('a'),symbol('b'))
        >>> p.lcoeff (b)
        power(symbol('a'),symbol('b'))
        >>> r.lcoeff (a)
        numeric('1')
        
        #>>> (a**b*a).lcoeff (a)
        #power(symbol('a'),symbol('b'))
        """
    def tcoeff (self):
        """
        #>>> p.tcoeff (a)
        #power(symbol('a'),symbol('b'))
        >>> p.tcoeff (b)
        power(symbol('a'),symbol('b'))
        >>> r.tcoeff (a)
        numeric('1')
        """
    def ldegree (self):
        """
        #>>> p.ldegree (a)
        #0
        >>> p.ldegree (b)
        0
        >>> r.ldegree (a)
        -2
        """
    def degree (self):
        """
        #>>> p.degree (a)
        #0
        >>> p.degree (b)
        0
        >>> r.degree (a)
        -2
        """
    def integer_content (self):
        """
        >>> p.integer_content ()
        numeric('1')
        >>> r.integer_content ()
        numeric('1')
        """
    def max_coefficient (self):
        """
        >>> p.max_coefficient ()
        numeric('1')
        >>> r.max_coefficient ()
        numeric('1')
        """
    def unit (self):
        """
        >>> r.unit (a)
        numeric('1')
        
        #>>> p.unit (b)    #FIXME: this results SEGFAULT
        """
    def primpart (self):
        """
        >>> r.primpart (a)
        power(symbol('a'),numeric('-2'))
        """
    def content (self):
        """
        >>> r.content (a)
        numeric('1')
        """
    def smod (self):
        """
        >>> r.smod (1)
        power(symbol('a'),numeric('-2'))
        """
def _test():
    import test_power
    return test_all.test(test_power)

if __name__ == "__main__":
    _test()

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