~dinko-metalac/calculus-app2/trunk

« back to all changes in this revision

Viewing changes to lib/py/sympy/series/tests/test_series.py

  • Committer: dinko.metalac at gmail
  • Date: 2015-04-14 13:28:14 UTC
  • Revision ID: dinko.metalac@gmail.com-20150414132814-j25k3qd7sq3warup
new sympy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from sympy import sin, cos, exp, E, series, oo, S, Derivative, O, Integral, \
2
 
    Function, log, sqrt, Symbol, Subs
 
2
    Function, log, sqrt, Symbol, Subs, pi, symbols
3
3
from sympy.abc import x, y, n, k
4
4
from sympy.utilities.pytest import raises
5
5
from sympy.series.gruntz import calculate_series
29
29
    assert e1 == e2
30
30
 
31
31
 
32
 
def test_2124():
 
32
def test_issue_5223():
33
33
    assert series(1, x) == 1
34
34
    assert next(S(0).lseries(x)) == 0
35
35
    assert cos(x).series() == cos(x).series(x)
36
36
    raises(ValueError, lambda: cos(x + y).series())
37
37
    raises(ValueError, lambda: x.series(dir=""))
38
38
 
39
 
    assert (cos(x).series(x, 1).removeO().subs(x, x - 1) -
40
 
            cos(x + 1).series(x).removeO().subs(x, x - 1)).expand() == 0
 
39
    assert (cos(x).series(x, 1) -
 
40
            cos(x + 1).series(x).subs(x, x - 1)).removeO() == 0
41
41
    e = cos(x).series(x, 1, n=None)
42
42
    assert [next(e) for i in range(2)] == [cos(1), -((x - 1)*sin(1))]
43
43
    e = cos(x).series(x, 1, n=None, dir='-')
44
44
    assert [next(e) for i in range(2)] == [cos(1), (1 - x)*sin(1)]
45
45
    # the following test is exact so no need for x -> x - 1 replacement
46
46
    assert abs(x).series(x, 1, dir='-') == x
47
 
    assert exp(x).series(x, 1, dir='-', n=3).removeO().subs(x, x - 1) == \
48
 
        E + E*(x - 1) + E*(x - 1)**2/2
 
47
    assert exp(x).series(x, 1, dir='-', n=3).removeO() == \
 
48
        E - E*(-x + 1) + E*(-x + 1)**2/2
49
49
 
50
50
    D = Derivative
51
51
    assert D(x**2 + x**3*y**2, x, 2, y, 1).series(x).doit() == 12*x*y
63
63
    assert ((sin(x))**y).nseries(x, n=1, logx=logx) == \
64
64
        exp(y*logx) + O(x*exp(y*logx), x)
65
65
 
66
 
    assert sin(1/x).series(x, oo, n=5) == 1/x - 1/(6*x**3)
 
66
    assert sin(1/x).series(x, oo, n=5) == 1/x - 1/(6*x**3) + O(x**(-5), (x, oo))
67
67
    assert abs(x).series(x, oo, n=5, dir='+') == x
68
68
    assert abs(x).series(x, -oo, n=5, dir='-') == -x
69
69
    assert abs(-x).series(x, oo, n=5, dir='+') == x
78
78
 
79
79
    assert exp(sin(x)*log(x)).series(n=2) == 1 + x*log(x) + O(x**2*log(x)**2)
80
80
 
81
 
def test_879():
 
81
def test_issue_3978():
82
82
    f = Function('f')
83
83
    assert f(x).series(x, 0, 3, dir='-') == \
84
84
            f(0) + x*Subs(Derivative(f(x), x), (x,), (0,)) + \
111
111
    assert round(shanks(A, n, 25, 5).evalf(), 10) == round(log(2).evalf(), 10)
112
112
 
113
113
 
114
 
def test_1484():
 
114
def test_issue_5852():
 
115
    assert series(1/cos(x/log(x)), x, 0) == 1 + x**2/(2*log(x)**2) + \
 
116
        5*x**4/(24*log(x)**4) + O(x**6)
 
117
 
 
118
 
 
119
def test_issue_4583():
115
120
    assert cos(1 + x + x**2).series(x, 0, 5) == cos(1) - x*sin(1) + \
116
121
        x**2*(-sin(1) - cos(1)/2) + x**3*(-cos(1) + sin(1)/6) + \
117
122
        x**4*(-11*cos(1)/24 + sin(1)/2) + O(x**5)
118
123
 
119
124
 
120
 
def test_issue_3219():
 
125
def test_issue_6318():
121
126
    eq = (1/x)**(S(2)/3)
122
127
    assert (eq + 1).as_leading_term(x) == eq
123
128
 
124
129
 
125
130
def test_x_is_base_detection():
126
131
    eq = (x**2)**(S(2)/3)
127
 
    assert eq.series() == eq
 
132
    assert eq.series() == x**(S(4)/3)
 
133
 
128
134
 
129
135
def test_sin_power():
130
136
    e = sin(x)**1.2
131
137
    assert calculate_series(e, x) == x**1.2
 
138
 
 
139
 
 
140
def test_issue_7203():
 
141
    assert series(cos(x), x, pi, 3) == \
 
142
        -1 + (x - pi)**2/2 + O((x - pi)**3, (x, pi))
 
143
 
 
144
 
 
145
def test_exp_product_positive_factors():
 
146
    a, b = symbols('a, b', positive=True)
 
147
    x = a * b
 
148
    assert series(exp(x), x, n=8) == 1 + a*b + a**2*b**2/2 + \
 
149
        a**3*b**3/6 + a**4*b**4/24 + a**5*b**5/120 + a**6*b**6/720 + \
 
150
        a**7*b**7/5040 + O(a**8*b**8, a, b)