Esempio n. 1
0
from sympy.interactive import printing
from sympy import Limit, limit, Symbol, S

printing.init_printing(use_latex='mathjax')

x = Symbol('x')  # Creando el simbolo x.
print(Limit(x**2 - x + 2, x, 2))

res = Limit(x**2 - x + 2, x, 2).doit()
print(res)
Esempio n. 2
0
def test_issue_17325():
    assert Limit(sin(x) / x, x, 0, dir="+-").doit() == 1
    assert Limit(x**2, x, 0, dir="+-").doit() == 0
    assert Limit(1 / x**2, x, 0, dir="+-").doit() is oo
    assert Limit(1 / x, x, 0, dir="+-").doit() is zoo
Esempio n. 3
0
def test_Limit():
    assert str(Limit(sin(x) / x, x, y)) == "Limit(sin(x)/x, x, y)"
    assert str(Limit(1 / x, x, 0)) == "Limit(1/x, x, 0)"
    assert str(Limit(sin(x) / x, x, y,
                     dir="-")) == "Limit(sin(x)/x, x, y, dir='-')"
Esempio n. 4
0
def test_doit2():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    # limit() breaks on the contained Integral.
    assert l.doit(deep=False) == l
Esempio n. 5
0
def test_issue_9205():
    x, y, a = symbols('x, y, a')
    assert Limit(x, x, a).free_symbols == {a}
    assert Limit(x, x, a, '-').free_symbols == {a}
    assert Limit(x + y, x + y, a).free_symbols == {a}
    assert Limit(-x**2 + y, x**2, a).free_symbols == {y, a}
import sympy
import math

from sympy import Symbol, solve, sin, Limit, S, oo

theta = Symbol('theta')
# math.sin(theta)

print(sympy.sin(theta) * sympy.sin(theta))

u = Symbol('u')
t = Symbol('t')
g = Symbol('g')

print(solve(u * sin(theta) - g * t, t))

x = Symbol('x')
l = Limit(1 / x, x, oo)
print(l.doit())

st = 5 * t**2 + 2 * t + 8
t1 = Symbol('t1')
delta_t = Symbol('delta_t')

st1 = st.subs({t: t1})

st1_delta = (st.subs({t: t1 + delta_t}))
f_d = Limit(((st1_delta - st1) / delta_t), delta_t, 0)

print(f_d.doit())
Esempio n. 7
0
def test_Limit():
    assert Limit(sin(x) / x, x, 0) != 1
    assert Limit(sin(x) / x, x, 0).doit() == 1
    assert Limit(x, x, 0, dir='+-').args == (x, x, 0, Symbol('+-'))
Esempio n. 8
0
from math import pi  # Importa a constante pi da biblioteca math.


# Define uma nova função.
def calcula_f(x):
    return sin(2 * x) / x


# Limpa a área de console para facilitar a visualização do resultado.
print('\n' * 100)

# Define x como uma variável.
x = Symbol('x')

# Calcula limite da função quando x -> 0.
resultado = Limit(calcula_f(x), x, 0).doit()

print(u'\n Limite da função calcula_f para x -> 0.')
print(resultado)

# Calcula limite da função quando x -> pi/6.
resultado = Limit(calcula_f(x), x, pi / 6).doit()

print(u'\n Limite da função calcula_f para x -> pi/6.')
print(resultado)

# Calcula limite da função quando x -> oo.
resultado = Limit(calcula_f(x), x, S.Infinity).doit()

print(u'\n Limite da função calcula_f para x -> oo.')
print(resultado)
Esempio n. 9
0
 ("a / b", a / b),
 ("a \\div b", a / b),
 ("a + b", a + b),
 ("a + b - a", _Add(a + b, -a)),
 ("a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)),
 ("\\sin \\theta", sin(theta)),
 ("\\sin(\\theta)", sin(theta)),
 ("\\sin^{-1} a", asin(a)),
 ("\\sin a \\cos b", _Mul(sin(a), cos(b))),
 ("\\sin \\cos \\theta", sin(cos(theta))),
 ("\\sin(\\cos \\theta)", sin(cos(theta))),
 ("\\frac{a}{b}", a / b),
 ("\\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))),
 ("\\frac{7}{3}", _Mul(7, _Pow(3, -1))),
 ("(\\csc x)(\\sec y)", csc(x) * sec(y)),
 ("\\lim_{x \\to 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\rightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\Rightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\longrightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\Longrightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\to 3^{+}} a", Limit(a, x, 3, dir="+")),
 ("\\lim_{x \\to 3^{-}} a", Limit(a, x, 3, dir="-")),
 ("\\infty", oo),
 ("\\lim_{x \\to \\infty} \\frac{1}{x}", Limit(_Mul(1, _Pow(x, -1)), x,
                                               oo)),
 ("\\frac{d}{dx} x", Derivative(x, x)),
 ("\\frac{d}{dt} x", Derivative(x, t)),
 ("f(x)", f(x)),
 ("f(x, y)", f(x, y)),
 ("f(x, y, z)", f(x, y, z)),
 ("\\frac{d f(x)}{dx}", Derivative(f(x), x)),
Esempio n. 10
0
    def is_convergent(self):
        r"""Checks for the convergence of a Sum.

        We divide the study of convergence of infinite sums and products in
        two parts.

        First Part:
        One part is the question whether all the terms are well defined, i.e.,
        they are finite in a sum and also non-zero in a product. Zero
        is the analogy of (minus) infinity in products as
        :math:`e^{-\infty} = 0`.

        Second Part:
        The second part is the question of convergence after infinities,
        and zeros in products, have been omitted assuming that their number
        is finite. This means that we only consider the tail of the sum or
        product, starting from some point after which all terms are well
        defined.

        For example, in a sum of the form:

        .. math::

            \sum_{1 \leq i < \infty} \frac{1}{n^2 + an + b}

        where a and b are numbers. The routine will return true, even if there
        are infinities in the term sequence (at most two). An analogous
        product would be:

        .. math::

            \prod_{1 \leq i < \infty} e^{\frac{1}{n^2 + an + b}}

        This is how convergence is interpreted. It is concerned with what
        happens at the limit. Finding the bad terms is another independent
        matter.

        Note: It is responsibility of user to see that the sum or product
        is well defined.

        There are various tests employed to check the convergence like
        divergence test, root test, integral test, alternating series test,
        comparison tests, Dirichlet tests. It returns true if Sum is convergent
        and false if divergent and NotImplementedError if it can not be checked.

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Convergence_tests

        Examples
        ========

        >>> from sympy import factorial, S, Sum, Symbol, oo
        >>> n = Symbol('n', integer=True)
        >>> Sum(n/(n - 1), (n, 4, 7)).is_convergent()
        True
        >>> Sum(n/(2*n + 1), (n, 1, oo)).is_convergent()
        False
        >>> Sum(factorial(n)/5**n, (n, 1, oo)).is_convergent()
        False
        >>> Sum(1/n**(S(6)/5), (n, 1, oo)).is_convergent()
        True

        See Also
        ========

        Sum.is_absolutely_convergent()

        Product.is_convergent()
        """
        from sympy import Interval, Integral, Limit, log, symbols, Ge, Gt, simplify
        p, q, r = symbols('p q r', cls=Wild)

        sym = self.limits[0][0]
        lower_limit = self.limits[0][1]
        upper_limit = self.limits[0][2]
        sequence_term = self.function

        if len(sequence_term.free_symbols) > 1:
            raise NotImplementedError(
                "convergence checking for more than one symbol "
                "containing series is not handled")

        if lower_limit.is_finite and upper_limit.is_finite:
            return S.true

        # transform sym -> -sym and swap the upper_limit = S.Infinity
        # and lower_limit = - upper_limit
        if lower_limit is S.NegativeInfinity:
            if upper_limit is S.Infinity:
                return Sum(sequence_term, (sym, 0, S.Infinity)).is_convergent() and \
                        Sum(sequence_term, (sym, S.NegativeInfinity, 0)).is_convergent()
            sequence_term = simplify(sequence_term.xreplace({sym: -sym}))
            lower_limit = -upper_limit
            upper_limit = S.Infinity

        sym_ = Dummy(sym.name, integer=True, positive=True)
        sequence_term = sequence_term.xreplace({sym: sym_})
        sym = sym_

        interval = Interval(lower_limit, upper_limit)

        # Piecewise function handle
        if sequence_term.is_Piecewise:
            for func, cond in sequence_term.args:
                # see if it represents something going to oo
                if cond == True or cond.as_set().sup is S.Infinity:
                    s = Sum(func, (sym, lower_limit, upper_limit))
                    return s.is_convergent()
            return S.true

        ###  -------- Divergence test ----------- ###
        try:
            lim_val = limit(sequence_term, sym, upper_limit)
            if lim_val.is_number and lim_val is not S.Zero:
                return S.false
        except NotImplementedError:
            pass

        try:
            lim_val_abs = limit(abs(sequence_term), sym, upper_limit)
            if lim_val_abs.is_number and lim_val_abs is not S.Zero:
                return S.false
        except NotImplementedError:
            pass

        order = O(sequence_term, (sym, S.Infinity))

        ### --------- p-series test (1/n**p) ---------- ###
        p1_series_test = order.expr.match(sym**p)
        if p1_series_test is not None:
            if p1_series_test[p] < -1:
                return S.true
            if p1_series_test[p] >= -1:
                return S.false

        p2_series_test = order.expr.match((1 / sym)**p)
        if p2_series_test is not None:
            if p2_series_test[p] > 1:
                return S.true
            if p2_series_test[p] <= 1:
                return S.false

        ### ------------- comparison test ------------- ###
        # 1/(n**p*log(n)**q*log(log(n))**r) comparison
        n_log_test = order.expr.match(
            1 / (sym**p * log(sym)**q * log(log(sym))**r))
        if n_log_test is not None:
            if (n_log_test[p] > 1 or (n_log_test[p] == 1 and n_log_test[q] > 1)
                    or
                (n_log_test[p] == n_log_test[q] == 1 and n_log_test[r] > 1)):
                return S.true
            return S.false

        ### ------------- Limit comparison test -----------###
        # (1/n) comparison
        try:
            lim_comp = limit(sym * sequence_term, sym, S.Infinity)
            if lim_comp.is_number and lim_comp > 0:
                return S.false
        except NotImplementedError:
            pass

        ### ----------- ratio test ---------------- ###
        next_sequence_term = sequence_term.xreplace({sym: sym + 1})
        ratio = combsimp(powsimp(next_sequence_term / sequence_term))
        try:
            lim_ratio = limit(ratio, sym, upper_limit)
            if lim_ratio.is_number:
                if abs(lim_ratio) > 1:
                    return S.false
                if abs(lim_ratio) < 1:
                    return S.true
        except NotImplementedError:
            pass

        ### ----------- root test ---------------- ###
        lim = Limit(abs(sequence_term)**(1 / sym), sym, S.Infinity)
        try:
            lim_evaluated = lim.doit()
            if lim_evaluated.is_number:
                if lim_evaluated < 1:
                    return S.true
                if lim_evaluated > 1:
                    return S.false
        except NotImplementedError:
            pass

        ### ------------- alternating series test ----------- ###
        dict_val = sequence_term.match((-1)**(sym + p) * q)
        if not dict_val[p].has(sym) and is_decreasing(dict_val[q], interval):
            return S.true

        ### ------------- integral test -------------- ###
        check_interval = None
        maxima = solveset(sequence_term.diff(sym), sym, interval)
        if not maxima:
            check_interval = interval
        elif isinstance(maxima, FiniteSet) and maxima.sup.is_number:
            check_interval = Interval(maxima.sup, interval.sup)
        if (check_interval is not None
                and (is_decreasing(sequence_term, check_interval)
                     or is_decreasing(-sequence_term, check_interval))):
            integral_val = Integral(sequence_term,
                                    (sym, lower_limit, upper_limit))
            try:
                integral_val_evaluated = integral_val.doit()
                if integral_val_evaluated.is_number:
                    return S(integral_val_evaluated.is_finite)
            except NotImplementedError:
                pass

        ### ----- Dirichlet and bounded times convergent tests ----- ###
        # TODO
        #
        # Dirichlet_test
        # https://en.wikipedia.org/wiki/Dirichlet%27s_test
        #
        # Bounded times convergent test
        # It is based on comparison theorems for series.
        # In particular, if the general term of a series can
        # be written as a product of two terms a_n and b_n
        # and if a_n is bounded and if Sum(b_n) is absolutely
        # convergent, then the original series Sum(a_n * b_n)
        # is absolutely convergent and so convergent.
        #
        # The following code can grows like 2**n where n is the
        # number of args in order.expr
        # Possibly combined with the potentially slow checks
        # inside the loop, could make this test extremely slow
        # for larger summation expressions.

        if order.expr.is_Mul:
            args = order.expr.args
            argset = set(args)

            ### -------------- Dirichlet tests -------------- ###
            m = Dummy('m', integer=True)

            def _dirichlet_test(g_n):
                try:
                    ing_val = limit(
                        Sum(g_n, (sym, interval.inf, m)).doit(), m, S.Infinity)
                    if ing_val.is_finite:
                        return S.true
                except NotImplementedError:
                    pass

            ### -------- bounded times convergent test ---------###
            def _bounded_convergent_test(g1_n, g2_n):
                try:
                    lim_val = limit(g1_n, sym, upper_limit)
                    if lim_val.is_finite or (
                            isinstance(lim_val, AccumulationBounds) and
                        (lim_val.max - lim_val.min).is_finite):
                        if Sum(g2_n, (sym, lower_limit,
                                      upper_limit)).is_absolutely_convergent():
                            return S.true
                except NotImplementedError:
                    pass

            for n in range(1, len(argset)):
                for a_tuple in itertools.combinations(args, n):
                    b_set = argset - set(a_tuple)
                    a_n = Mul(*a_tuple)
                    b_n = Mul(*b_set)

                    if is_decreasing(a_n, interval):
                        dirich = _dirichlet_test(b_n)
                        if dirich is not None:
                            return dirich

                    bc_test = _bounded_convergent_test(a_n, b_n)
                    if bc_test is not None:
                        return bc_test

        _sym = self.limits[0][0]
        sequence_term = sequence_term.xreplace({sym: _sym})
        raise NotImplementedError(
            "The algorithm to find the Sum convergence of %s "
            "is not yet implemented" % (sequence_term))
Esempio n. 11
0
#!/usr/bin/env python
#continuity of a function at a point
from sympy import Symbol, exp, sin, tan, Limit
x = Symbol('x')
y = Symbol('y')
h = Symbol('h')
#continuity
y = 1 / x
a = 0
y1 = y.subs({x: a})
#The value of the function at a, ie  f(a)
print(y1)
q1 = y.subs({x: a + h}).evalf()
q2 = y.subs({x: a - h}).evalf()
#Left Hand Limit
t1 = Limit(q1, h, 0).doit()
#Right Hand Limit
t2 = Limit(q2, h, 0).doit()
print(t1, t2)
if (t1 == y1 and t2 == y1):
    print("Continous")
else:
    print("Not Continous")
Esempio n. 12
0
from sympy import Symbol
import math
theta=Symbol('theta')
u=Symbol('u')
t=Symbol('t')
g=Symbol('g')

theta=Symbol('theta')

x=Symbol('x')

from sympy import Limit,S

l=Limit(1/x,x,S,dir='-')     #limit,s burada sonsuzluk belirtir.
print(l)

t=Symbol('t')
t1=Symbol('t1')
delta_t=Symbol('delta_t')

st=5t**2+2t+8

st1=st.subs({t:t1})

st1_delta=(st.subs({t:t+delta_t}))

f_d=Limit((st1_delta-st1)/delta_t),0)

print(f_d)
Esempio n. 13
0
def test_pretty_limits():
    expr = Limit(x, x, oo)
    ascii_str = \
"""\
 lim x\n\
x->oo \
"""
    ucode_str = \
u"""\
lim x\n\
x->∞ \
"""
    assert pretty(expr) == ascii_str
    assert upretty(expr) == ucode_str

    expr = Limit(x**2, x, 0)
    ascii_str = \
"""\
     2\n\
lim x \n\
x->0  \
"""
    ucode_str = \
u"""\
     2\n\
lim x \n\
x->0  \
"""
    assert pretty(expr) == ascii_str
    assert upretty(expr) == ucode_str

    expr = Limit(1 / x, x, 0)
    ascii_str = \
"""\
    1\n\
lim -\n\
x->0x\
"""
    ucode_str = \
u"""\
    1\n\
lim ─\n\
x->0x\
"""
    assert pretty(expr) == ascii_str
    assert upretty(expr) == ucode_str

    expr = Limit(sin(x) / x, x, 0)
    ascii_str = \
"""\
    sin(x)\n\
lim ------\n\
x->0  x   \
"""
    ucode_str = \
u"""\
    sin(x)\n\
lim ──────\n\
x->0  x   \
"""
    assert pretty(expr) == ascii_str
    assert upretty(expr) == ucode_str
Esempio n. 14
0
#세트 - 중복 , 순서 X
# my_set = {1,2,2,3,3,3} #{1,2,3}

# java = {"김", "이", "박"}
# python = {"김", "최"} #set(["김", "최"])
# #교집합
# print(java & python)
# print(java.intersection(python))
# #합집합
# print(java | python) 
# print(java.union(python))
# #차집합
# print(java - python)
# print(java.difference(python))
# #세트에 추가 
# python.add("이")#하나만 추가 가능
# print(python)
# pkython.remove("최") #세트에서 제거
# print(python)

# a, b = input().split(':') # :를 기준으로 나눔

from sympy import Limit, symbols
from sympy import *
x, h = symbols('x, h')    # Symbol 정의
f_x = 3*x**3 - 5*x + exp(x) + (sin(x))**2    # f(x)를 설정
f_xPlush = f_x.subs({x:x+h})    # f(x+h) 구하기
meanRatioOfChange = (f_xPlush - f_x)/h    # 평균변화율 구하기
f_primeX = Limit(meanRatioOfChange, h, 0).doit()    # 도함수 구하기
print(f_primeX)
Esempio n. 15
0
    def is_convergent(self):
        r"""Checks for the convergence of a Sum.

        We divide the study of convergence of infinite sums and products in
        two parts.

        First Part:
        One part is the question whether all the terms are well defined, i.e.,
        they are finite in a sum and also non-zero in a product. Zero
        is the analogy of (minus) infinity in products as :math:`e^{-\infty} = 0`.

        Second Part:
        The second part is the question of convergence after infinities,
        and zeros in products, have been omitted assuming that their number
        is finite. This means that we only consider the tail of the sum or
        product, starting from some point after which all terms are well
        defined.

        For example, in a sum of the form:

        .. math::

            \sum_{1 \leq i < \infty} \frac{1}{n^2 + an + b}

        where a and b are numbers. The routine will return true, even if there
        are infinities in the term sequence (at most two). An analogous
        product would be:

        .. math::

            \prod_{1 \leq i < \infty} e^{\frac{1}{n^2 + an + b}}

        This is how convergence is interpreted. It is concerned with what
        happens at the limit. Finding the bad terms is another independent
        matter.

        Note: It is responsibility of user to see that the sum or product
        is well defined.

        There are various tests employed to check the convergence like
        divergence test, root test, integral test, alternating series test,
        comparison tests, Dirichlet tests. It returns true if Sum is convergent
        and false if divergent and NotImplementedError if it can not be checked.

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Convergence_tests

        Examples
        ========

        >>> from sympy import factorial, S, Sum, Symbol, oo
        >>> n = Symbol('n', integer=True)
        >>> Sum(n/(n - 1), (n, 4, 7)).is_convergent()
        True
        >>> Sum(n/(2*n + 1), (n, 1, oo)).is_convergent()
        False
        >>> Sum(factorial(n)/5**n, (n, 1, oo)).is_convergent()
        False
        >>> Sum(1/n**(S(6)/5), (n, 1, oo)).is_convergent()
        True

        See Also
        ========

        Sum.is_absolutely_convergent()

        Product.is_convergent()
        """
        from sympy import Interval, Integral, Limit, log, symbols, Ge, Gt, simplify
        p, q = symbols('p q', cls=Wild)

        sym = self.limits[0][0]
        lower_limit = self.limits[0][1]
        upper_limit = self.limits[0][2]
        sequence_term = self.function

        if len(sequence_term.free_symbols) > 1:
            raise NotImplementedError(
                "convergence checking for more than one symbol "
                "containing series is not handled")

        if lower_limit.is_finite and upper_limit.is_finite:
            return S.true

        # transform sym -> -sym and swap the upper_limit = S.Infinity
        # and lower_limit = - upper_limit
        if lower_limit is S.NegativeInfinity:
            if upper_limit is S.Infinity:
                return Sum(sequence_term, (sym, 0, S.Infinity)).is_convergent() and \
                        Sum(sequence_term, (sym, S.NegativeInfinity, 0)).is_convergent()
            sequence_term = simplify(sequence_term.xreplace({sym: -sym}))
            lower_limit = -upper_limit
            upper_limit = S.Infinity

        interval = Interval(lower_limit, upper_limit)

        # Piecewise function handle
        if sequence_term.is_Piecewise:
            for func_cond in sequence_term.args:
                if func_cond[1].func is Ge or func_cond[
                        1].func is Gt or func_cond[1] == True:
                    return Sum(
                        func_cond[0],
                        (sym, lower_limit, upper_limit)).is_convergent()
            return S.true

        ###  -------- Divergence test ----------- ###
        try:
            lim_val = limit(sequence_term, sym, upper_limit)
            if lim_val.is_number and lim_val is not S.Zero:
                return S.false
        except NotImplementedError:
            pass

        try:
            lim_val_abs = limit(abs(sequence_term), sym, upper_limit)
            if lim_val_abs.is_number and lim_val_abs is not S.Zero:
                return S.false
        except NotImplementedError:
            pass

        order = O(sequence_term, (sym, S.Infinity))

        ### --------- p-series test (1/n**p) ---------- ###
        p1_series_test = order.expr.match(sym**p)
        if p1_series_test is not None:
            if p1_series_test[p] < -1:
                return S.true
            if p1_series_test[p] > -1:
                return S.false

        p2_series_test = order.expr.match((1 / sym)**p)
        if p2_series_test is not None:
            if p2_series_test[p] > 1:
                return S.true
            if p2_series_test[p] < 1:
                return S.false

        ### ----------- root test ---------------- ###
        lim = Limit(abs(sequence_term)**(1 / sym), sym, S.Infinity)
        lim_evaluated = lim.doit()
        if lim_evaluated.is_number:
            if lim_evaluated < 1:
                return S.true
            if lim_evaluated > 1:
                return S.false

        ### ------------- alternating series test ----------- ###
        dict_val = sequence_term.match((-1)**(sym + p) * q)
        if not dict_val[p].has(sym) and is_decreasing(dict_val[q], interval):
            return S.true

        ### ------------- comparison test ------------- ###
        # (1/log(n)**p) comparison
        log_test = order.expr.match(1 / (log(sym)**p))
        if log_test is not None:
            return S.false

        # (1/(n*log(n)**p)) comparison
        log_n_test = order.expr.match(1 / (sym * (log(sym))**p))
        if log_n_test is not None:
            if log_n_test[p] > 1:
                return S.true
            return S.false

        # (1/(n*log(n)*log(log(n))*p)) comparison
        log_log_n_test = order.expr.match(1 / (sym *
                                               (log(sym) * log(log(sym))**p)))
        if log_log_n_test is not None:
            if log_log_n_test[p] > 1:
                return S.true
            return S.false

        # (1/(n**p*log(n))) comparison
        n_log_test = order.expr.match(1 / (sym**p * log(sym)))
        if n_log_test is not None:
            if n_log_test[p] > 1:
                return S.true
            return S.false

        ### ------------- integral test -------------- ###
        if is_decreasing(sequence_term, interval):
            integral_val = Integral(sequence_term,
                                    (sym, lower_limit, upper_limit))
            try:
                integral_val_evaluated = integral_val.doit()
                if integral_val_evaluated.is_number:
                    return S(integral_val_evaluated.is_finite)
            except NotImplementedError:
                pass

        ### -------------- Dirichlet tests -------------- ###
        if order.expr.is_Mul:
            a_n, b_n = order.expr.args[0], order.expr.args[1]
            m = Dummy('m', integer=True)

            def _dirichlet_test(g_n):
                try:
                    ing_val = limit(
                        Sum(g_n, (sym, interval.inf, m)).doit(), m, S.Infinity)
                    if ing_val.is_finite:
                        return S.true
                except NotImplementedError:
                    pass

            if is_decreasing(a_n, interval):
                dirich1 = _dirichlet_test(b_n)
                if dirich1 is not None:
                    return dirich1

            if is_decreasing(b_n, interval):
                dirich2 = _dirichlet_test(a_n)
                if dirich2 is not None:
                    return dirich2

        raise NotImplementedError(
            "The algorithm to find the Sum convergence of %s "
            "is not yet implemented" % (sequence_term))
Esempio n. 16
0
def test_extended_real_line():
    assert limit(x - oo, x, oo) == Limit(x - oo, x, oo)
    assert limit(1 / (x + sin(x)) - oo, x, 0) == Limit(1 / (x + sin(x)) - oo,
                                                       x, 0)
    assert limit(oo / x, x, oo) == Limit(oo / x, x, oo)
    assert limit(x - oo + 1 / x, x, oo) == Limit(x - oo + 1 / x, x, oo)
Esempio n. 17
0
def test_latex_limits():
    assert latex(Limit(x, x, oo)) == r"\lim_{x \to \infty} x"
Esempio n. 18
0
#!/usr/bin/python3

from sympy import Symbol, Limit, sqrt, pprint

x = Symbol('x')

for i, t in enumerate([
    ((x**2 + 3 * x - 4) / (x - 1), x, 1),
    ((x**2 + -5 * x + 6) / (x**2 - (3 + 1 / 2) * x + 3 * 1 / 2), x, 3),
    ((x**2 - x - 2) / (x**3 - 3 * x - 2), x, 2),
    ((4 * sqrt(x + 1) - 4 * sqrt(2)) / (x - 1), x, 1)
]):
    print('({})'.format(i + 1))
    pprint(Limit(*t).doit())
Esempio n. 19
0
def test_issue_17325():
    assert Limit(sin(x) / x, x, 0, dir="+-").doit() == 1
    assert Limit(x**2, x, 0, dir="+-").doit() == 0
    assert Limit(1 / x**2, x, 0, dir="+-").doit() is oo
    raises(ValueError, lambda: Limit(1 / x, x, 0, dir="+-").doit())
Esempio n. 20
0
'''
    Finding the Limit of Functions
'''

from sympy import Limit, Symbol, S

# Unevaluated
x = Symbol('x')

# Find the value of the limit
l = Limit(1/x, x, S.Infinity)
print(Limit(1/x, x, S.Infinity), '=', l.doit())

Esempio n. 21
0
def test_doit():
    f = Integral(2 * x, x)
    l = Limit(f, x, oo)
    assert l.doit() is oo
Esempio n. 22
0
def lens_formula(focal_length=None, u=None, v=None):
    """
    This function provides one of the three parameters
    when two of them are supplied.
    This is valid only for paraxial rays.

    Parameters
    ==========

    focal_length : sympifiable
        Focal length of the mirror.
    u : sympifiable
        Distance of object from the optical center on
        the principal axis.
    v : sympifiable
        Distance of the image from the optical center
        on the principal axis.

    Examples
    ========

    >>> from sympy.physics.optics import lens_formula
    >>> from sympy.abc import f, u, v
    >>> lens_formula(focal_length=f, u=u)
    f*u/(f + u)
    >>> lens_formula(focal_length=f, v=v)
    f*v/(f - v)
    >>> lens_formula(u=u, v=v)
    u*v/(u - v)

    """
    if focal_length and u and v:
        raise ValueError("Please provide only two parameters")

    focal_length = sympify(focal_length)
    u = sympify(u)
    v = sympify(v)
    if u == oo:
        _u = Symbol('u')
    if v == oo:
        _v = Symbol('v')
    if focal_length == oo:
        _f = Symbol('f')
    if focal_length is None:
        if u == oo and v == oo:
            return Limit(Limit(_v * _u / (_u - _v), _u, oo), _v, oo).doit()
        if u == oo:
            return Limit(v * _u / (_u - v), _u, oo).doit()
        if v == oo:
            return Limit(_v * u / (u - _v), _v, oo).doit()
        return v * u / (u - v)
    if u is None:
        if v == oo and focal_length == oo:
            return Limit(Limit(_v * _f / (_f - _v), _v, oo), _f, oo).doit()
        if v == oo:
            return Limit(_v * focal_length / (focal_length - _v), _v,
                         oo).doit()
        if focal_length == oo:
            return Limit(v * _f / (_f - v), _f, oo).doit()
        return v * focal_length / (focal_length - v)
    if v is None:
        if u == oo and focal_length == oo:
            return Limit(Limit(_u * _f / (_u + _f), _u, oo), _f, oo).doit()
        if u == oo:
            return Limit(_u * focal_length / (_u + focal_length), _u,
                         oo).doit()
        if focal_length == oo:
            return Limit(u * _f / (u + _f), _f, oo).doit()
        return u * focal_length / (u + focal_length)
Esempio n. 23
0
def test_Limit_dir():
    raises(TypeError, lambda: Limit(x, x, 0, dir=0))
    raises(ValueError, lambda: Limit(x, x, 0, dir='0'))
Esempio n. 24
0
def test_basic1():
    assert limit(x, x, oo) is oo
    assert limit(x, x, -oo) is -oo
    assert limit(-x, x, oo) is -oo
    assert limit(x**2, x, -oo) is oo
    assert limit(-x**2, x, oo) is -oo
    assert limit(x * log(x), x, 0, dir="+") == 0
    assert limit(1 / x, x, oo) == 0
    assert limit(exp(x), x, oo) is oo
    assert limit(-exp(x), x, oo) is -oo
    assert limit(exp(x) / x, x, oo) is oo
    assert limit(1 / x - exp(-x), x, oo) == 0
    assert limit(x + 1 / x, x, oo) is oo
    assert limit(x - x**2, x, oo) is -oo
    assert limit((1 + x)**(1 + sqrt(2)), x, 0) == 1
    assert limit((1 + x)**oo, x, 0) == Limit((x + 1)**oo, x, 0)
    assert limit((1 + x)**oo, x, 0, dir='-') == Limit((x + 1)**oo,
                                                      x,
                                                      0,
                                                      dir='-')
    assert limit((1 + x + y)**oo, x, 0, dir='-') == Limit((x + y + 1)**oo,
                                                          x,
                                                          0,
                                                          dir='-')
    assert limit(y / x / log(x), x, 0) == -oo * sign(y)
    assert limit(cos(x + y) / x, x, 0) == sign(cos(y)) * oo
    assert limit(gamma(1 / x + 3), x, oo) == 2
    assert limit(S.NaN, x, -oo) is S.NaN
    assert limit(Order(2) * x, x, S.NaN) is S.NaN
    assert limit(1 / (x - 1), x, 1, dir="+") is oo
    assert limit(1 / (x - 1), x, 1, dir="-") is -oo
    assert limit(1 / (5 - x)**3, x, 5, dir="+") is -oo
    assert limit(1 / (5 - x)**3, x, 5, dir="-") is oo
    assert limit(1 / sin(x), x, pi, dir="+") is -oo
    assert limit(1 / sin(x), x, pi, dir="-") is oo
    assert limit(1 / cos(x), x, pi / 2, dir="+") is -oo
    assert limit(1 / cos(x), x, pi / 2, dir="-") is oo
    assert limit(1 / tan(x**3), x, (2 * pi)**Rational(1, 3), dir="+") is oo
    assert limit(1 / tan(x**3), x, (2 * pi)**Rational(1, 3), dir="-") is -oo
    assert limit(1 / cot(x)**3, x, (pi * Rational(3, 2)), dir="+") is -oo
    assert limit(1 / cot(x)**3, x, (pi * Rational(3, 2)), dir="-") is oo

    # test bi-directional limits
    assert limit(sin(x) / x, x, 0, dir="+-") == 1
    assert limit(x**2, x, 0, dir="+-") == 0
    assert limit(1 / x**2, x, 0, dir="+-") is oo

    # test failing bi-directional limits
    assert limit(1 / x, x, 0, dir="+-") is zoo
    # approaching 0
    # from dir="+"
    assert limit(1 + 1 / x, x, 0) is oo
    # from dir='-'
    # Add
    assert limit(1 + 1 / x, x, 0, dir='-') is -oo
    # Pow
    assert limit(x**(-2), x, 0, dir='-') is oo
    assert limit(x**(-3), x, 0, dir='-') is -oo
    assert limit(1 / sqrt(x), x, 0, dir='-') == (-oo) * I
    assert limit(x**2, x, 0, dir='-') == 0
    assert limit(sqrt(x), x, 0, dir='-') == 0
    assert limit(x**-pi, x, 0, dir='-') == oo * sign((-1)**(-pi))
    assert limit((1 + cos(x))**oo, x, 0) == Limit((cos(x) + 1)**oo, x, 0)
Esempio n. 25
0
def test_issue_14456():
    raises(NotImplementedError, lambda: Limit(exp(x), x, zoo).doit())
    raises(NotImplementedError, lambda: Limit(x**2 / (x + 1), x, zoo).doit())
Esempio n. 26
0
def test_Limit():
    assert Limit(sin(x) / x, x, 0) != 1
    assert Limit(sin(x) / x, x, 0).doit() == 1
Esempio n. 27
0
def test_issue_18442():
    assert limit(tan(x)**(2**(sqrt(pi))), x, oo,
                 dir='-') == Limit(tan(x)**(2**(sqrt(pi))), x, oo, dir='-')
Esempio n. 28
0
 ("(-7.13)(1.5)", _Mul(_Mul(-1, 7.13), 1.5)), ("x", x),
 ("2x", 2 * x), ("x^2", x**2), ("x^{3 + 1}", x**_Add(3, 1)),
 ("-c", -c), ("a \\cdot b", a * b), ("a / b", a / b),
 ("a \\div b", a / b), ("a + b", a + b),
 ("a + b - a", _Add(a + b, -a)),
 ("a^2 + b^2 = c^2", Eq(a**2 + b**2, c**2)),
 ("\\sin \\theta", sin(theta)), ("\\sin(\\theta)", sin(theta)),
 ("\\sin^{-1} a", asin(a)),
 ("\\sin a \\cos b", _Mul(sin(a), cos(b))),
 ("\\sin \\cos \\theta", sin(cos(theta))),
 ("\\sin(\\cos \\theta)", sin(cos(theta))),
 ("\\frac{a}{b}", a / b),
 ("\\frac{a + b}{c}", _Mul(a + b, _Pow(c, -1))),
 ("\\frac{7}{3}", _Mul(7, _Pow(3, -1))),
 ("(\\csc x)(\\sec y)", csc(x) * sec(y)),
 ("\\lim_{x \\to 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\rightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\Rightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\longrightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\Longrightarrow 3} a", Limit(a, x, 3)),
 ("\\lim_{x \\to 3^{+}} a", Limit(a, x, 3, dir='+')),
 ("\\lim_{x \\to 3^{-}} a", Limit(a, x, 3, dir='-')),
 ("\\infty", oo),
 ("\\lim_{x \\to \\infty} \\frac{1}{x}",
  Limit(_Mul(1, _Pow(x, -1)), x, oo)),
 ("\\frac{d}{dx} x", Derivative(x, x)),
 ("\\frac{d}{dt} x", Derivative(x, t)), ("f(x)", f(x)),
 ("f(x, y)", f(x, y)), ("f(x, y, z)", f(x, y, z)),
 ("\\frac{d f(x)}{dx}", Derivative(f(x), x)),
 ("\\frac{d\\theta(x)}{dx}", Derivative(theta(x), x)),
 ("|x|", _Abs(x)), ("||x||", _Abs(Abs(x))),
Esempio n. 29
0
from sympy import Symbol, Limit

t = Symbol('t')
St = 5 * t**2 + 2 * t + 8

t1 = Symbol('t1')
delta_t = Symbol('delta_t')
St1 = St.subs({t: t1})
St1_delta = St.subs({t: t1 + delta_t})
Limit((St1_delta - St1) / delta_t, delta_t, 0).doit()

#output=10t1+2
Esempio n. 30
0
# Importa operação Limit (limite) da biblioteca sympy
# Importa Symbol - possibilidade de operações com símbolos
# Importa função sympy S que transforma texto em algumas constantes padrão
# limite sin 2x / x com x -> pi/6
#

from sympy import Limit, Symbol, S, sin
from math import pi

# Define uma função


def calcula_f(x):
    return sin(2 * x) / x


x = Symbol('x')
resultado = Limit(calcula_f(x), x, pi / 6).doit()
print(resultado)