File:  [CENS] / python / pyGiNaC / test / test_function.py
Revision 1.4: download - view: text, annotated - select for diffs - revision graph
Thu Apr 5 06:16:15 2001 UTC (16 years, 7 months ago) by pearu
Branches: MAIN
CVS tags: HEAD
Finished function

#!/usr/bin/env python

#import libwadpy

execfile('__startup__.py')

def foo_eval():
    return 73

def fun_eval(x,y):
    print '>>> fun_eval'
    return fun(x,y).hold()
def fun_evalf(x,y):
    print '>>> fun_evalf'
    return x+y+4
def fun_derivative(x,y,n=0):
    print '>>> fun_derivative n=%s'%n
    return x*y*fun(x,y).hold()
def fun_series(x,y,rel,order,opt):
    print '>>> fun_series rel,order,opt=%s,%s,%s'%(rel,order,opt)
    return order*fun(x,y).hold()

foo = build_function('foo',eval=foo_eval)
fun = build_function('fun',
                     eval=fun_eval,
                     evalf=fun_evalf,
                     derivative=fun_derivative,
                     series=fun_series,
                     nofargs = 2)

x = symbol('x')
z = symbol('z')

f=foo()
print 'Constant function>>%s, %s, %s<<'%(`f`,`ex(f)`,`ex(f).evalf(2)`)

f=fun(x,z)
print 'Function with 2 parameters>>%s, %s, %s<<'%(`f`,`ex(f)`,`ex(f).evalf(1)`)
print 'Function with 2 parameters>>%s, %s, %s<<'%(`f`,`ex(f)`,`ex(f).evalf(2)`)
print '>'*30,`x,ex(x),symbol(ex(x))`,'<'*10
print ex(ex(f).diff(ex(x)))
print ex(ex(f).series(ex(relational(x,z)),2,0))

#f=sin(z)
#print 'Builtin function>>%s, %s<<'%(`f`,`ex(f)`)

    


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