1 # This test file tests the SymPy function interface, that people use to create
2 # their own new functions. It should be as easy as possible.
4 from sympy import Function, sympify, sin, cos, limit, tanh
5 from sympy.abc import x
7 def test_function_series1():
8 """Create our new "sin" function."""
10 class my_function(Function):
13 def fdiff(self, argindex = 1):
14 return cos(self.args[0])
17 def canonize(cls, arg):
22 #Test that the taylor series is correct
23 assert my_function(x).series(x, 0, 10) == sin(x).series(x, 0, 10)
24 assert limit(my_function(x)/x, x, 0) == 1
26 def test_function_series2():
27 """Create our new "cos" function."""
29 class my_function2(Function):
32 def fdiff(self, argindex = 1):
33 return -sin(self.args[0])
36 def canonize(cls, arg):
41 #Test that the taylor series is correct
42 assert my_function2(x).series(x, 0, 10) == cos(x).series(x, 0, 10)
44 def test_function_series3():
46 Test our easy "tanh" function.
48 This test tests two things:
49 * that the Function interface works as expected and it's easy to use
50 * that the general algorithm for the series expansion works even when the
51 derivative is defined recursively in terms of the original function,
52 since tanh(x).diff(x) == 1-tanh(x)**2
55 class mytanh(Function):
58 def fdiff(self, argindex = 1):
59 return 1-mytanh(self.args[0])**2
62 def canonize(cls, arg):
69 assert tanh(x).series(x, 0, 6) == mytanh(x).series(x, 0, 6)