Exemple #1
0
 def fdiff(self, argindex=1):
     if len(self.args) == 3:
         n, z, m = self.args
         fm, fn = sqrt(1 - m * sin(z)**2), 1 - n * sin(z)**2
         if argindex == 1:
             return (elliptic_e(z, m) + (m - n) * elliptic_f(z, m) / n +
                     (n**2 - m) * elliptic_pi(n, z, m) / n -
                     n * fm * sin(2 * z) / (2 * fn)) / (2 * (m - n) *
                                                        (n - 1))
         elif argindex == 2:
             return 1 / (fm * fn)
         elif argindex == 3:
             return (elliptic_e(z, m) /
                     (m - 1) + elliptic_pi(n, z, m) - m * sin(2 * z) /
                     (2 * (m - 1) * fm)) / (2 * (n - m))
     else:
         n, m = self.args
         if argindex == 1:
             return (elliptic_e(m) + (m - n) * elliptic_k(m) / n +
                     (n**2 - m) * elliptic_pi(n, m) / n) / (2 * (m - n) *
                                                            (n - 1))
         elif argindex == 2:
             return (elliptic_e(m) /
                     (m - 1) + elliptic_pi(n, m)) / (2 * (n - m))
     raise ArgumentIndexError(self, argindex)
Exemple #2
0
 def fdiff(self, argindex=1):
     z, m = self.args
     fm = sqrt(1 - m * sin(z)**2)
     if argindex == 1:
         return 1 / fm
     elif argindex == 2:
         return (elliptic_e(z, m) / (2 * m * (1 - m)) - elliptic_f(z, m) /
                 (2 * m) - sin(2 * z) / (4 * (1 - m) * fm))
     raise ArgumentIndexError(self, argindex)
Exemple #3
0
 def _eval_rewrite_as_cos(self, n, m, theta, phi):
     # This method can be expensive due to extensive use of simplification!
     from diofant.simplify import simplify, trigsimp
     # TODO: Make sure n \in N
     # TODO: Assert |m| <= n ortherwise we should return 0
     term = simplify(self.expand(func=True))
     # We can do this because of the range of theta
     term = term.xreplace({Abs(sin(theta)): sin(theta)})
     return simplify(trigsimp(term))
Exemple #4
0
def test_sympyissue_6068():
    assert sqrt(sin(x)).series(x, 0, 8) == \
        sqrt(x) - x**Rational(5, 2)/12 + x**Rational(9, 2)/1440 - \
        x**Rational(13, 2)/24192 + O(x**8)
    assert sqrt(sin(x)).series(x, 0, 10) == \
        sqrt(x) - x**Rational(5, 2)/12 + x**Rational(9, 2)/1440 - \
        x**Rational(13, 2)/24192 - 67*x**Rational(17, 2)/29030400 + O(x**10)
    assert sqrt(sin(x**3)).series(x, 0, 19) == \
        x**Rational(3, 2) - x**Rational(15, 2)/12 + x**Rational(27, 2)/1440 + O(x**19)
    assert sqrt(sin(x**3)).series(x, 0, 20) == \
        x**Rational(3, 2) - x**Rational(15, 2)/12 + x**Rational(27, 2)/1440 - \
        x**Rational(39, 2)/24192 + O(x**20)
def test_sympyissue_6068():
    assert sqrt(sin(x)).series(x, 0, 8) == \
        sqrt(x) - x**Rational(5, 2)/12 + x**Rational(9, 2)/1440 - \
        x**Rational(13, 2)/24192 + O(x**8)
    assert sqrt(sin(x)).series(x, 0, 10) == \
        sqrt(x) - x**Rational(5, 2)/12 + x**Rational(9, 2)/1440 - \
        x**Rational(13, 2)/24192 - 67*x**Rational(17, 2)/29030400 + O(x**10)
    assert sqrt(sin(x**3)).series(x, 0, 19) == \
        x**Rational(3, 2) - x**Rational(15, 2)/12 + x**Rational(27, 2)/1440 + O(x**19)
    assert sqrt(sin(x**3)).series(x, 0, 20) == \
        x**Rational(3, 2) - x**Rational(15, 2)/12 + x**Rational(27, 2)/1440 - \
        x**Rational(39, 2)/24192 + O(x**20)
Exemple #6
0
def test_sympyissue_7638():
    f = pi/log(sqrt(2))
    assert ((1 + I)**(I*f/2))**0.3 == (1 + I)**(0.15*I*f)
    # if 1/3 -> 1.0/3 this should fail since it cannot be shown that the
    # sign will be +/-1; for the previous "small arg" case, it didn't matter
    # that this could not be proved
    assert (1 + I)**(4*I*f) == ((1 + I)**(12*I*f))**Rational(1, 3)

    assert (((1 + I)**(I*(1 + 7*f)))**Rational(1, 3)).exp == Rational(1, 3)
    r = symbols('r', extended_real=True)
    assert sqrt(r**2) == abs(r)
    assert cbrt(r**3) != r
    assert sqrt(Pow(2*I, 5*S.Half)) != (2*I)**(5/Integer(4))
    p = symbols('p', positive=True)
    assert cbrt(p**2) == p**(2/Integer(3))
    assert NS(((0.2 + 0.7*I)**(0.7 + 1.0*I))**(0.5 - 0.1*I), 1) == '0.4 + 0.2*I'
    assert sqrt(1/(1 + I)) == sqrt((1 - I)/2)  # or 1/sqrt(1 + I)
    e = 1/(1 - sqrt(2))
    assert sqrt(e) == I/sqrt(-1 + sqrt(2))
    assert e**-S.Half == -I*sqrt(-1 + sqrt(2))
    assert sqrt((cos(1)**2 + sin(1)**2 - 1)**(3 + I)).exp == S.Half
    assert sqrt(r**(4/Integer(3))) != r**(2/Integer(3))
    assert sqrt((p + I)**(4/Integer(3))) == (p + I)**(2/Integer(3))
    assert sqrt((p - p**2*I)**2) == p - p**2*I
    assert sqrt((p + r*I)**2) != p + r*I
    e = (1 + I/5)
    assert sqrt(e**5) == e**(5*S.Half)
    assert sqrt(e**6) == e**3
    assert sqrt((1 + I*r)**6) != (1 + I*r)**3
def test_sympyissue_7638():
    f = pi/log(sqrt(2))
    assert ((1 + I)**(I*f/2))**0.3 == (1 + I)**(0.15*I*f)
    # if 1/3 -> 1.0/3 this should fail since it cannot be shown that the
    # sign will be +/-1; for the previous "small arg" case, it didn't matter
    # that this could not be proved
    assert (1 + I)**(4*I*f) == cbrt((1 + I)**(12*I*f))

    assert cbrt((1 + I)**(I*(1 + 7*f))).exp == Rational(1, 3)
    r = symbols('r', extended_real=True)
    assert sqrt(r**2) == abs(r)
    assert cbrt(r**3) != r
    assert sqrt(Pow(2*I, Rational(5, 2))) != (2*I)**Rational(5, 4)
    p = symbols('p', positive=True)
    assert cbrt(p**2) == p**Rational(2, 3)
    assert NS(((0.2 + 0.7*I)**(0.7 + 1.0*I))**(0.5 - 0.1*I), 1) == '0.4 + 0.2*I'
    assert sqrt(1/(1 + I)) == sqrt((1 - I)/2)  # or 1/sqrt(1 + I)
    e = 1/(1 - sqrt(2))
    assert sqrt(e) == I/sqrt(-1 + sqrt(2))
    assert e**Rational(-1, 2) == -I*sqrt(-1 + sqrt(2))
    assert sqrt((cos(1)**2 + sin(1)**2 - 1)**(3 + I)).exp == Rational(1, 2)
    assert sqrt(r**Rational(4, 3)) != r**Rational(2, 3)
    assert sqrt((p + I)**Rational(4, 3)) == (p + I)**Rational(2, 3)
    assert sqrt((p - p**2*I)**2) == p - p**2*I
    assert sqrt((p + r*I)**2) != p + r*I
    e = (1 + I/5)
    assert sqrt(e**5) == e**Rational(5, 2)
    assert sqrt(e**6) == e**3
    assert sqrt((1 + I*r)**6) != (1 + I*r)**3
Exemple #8
0
    def _eval_expand_func(self, **hints):
        from diofant import Sum
        n = self.args[0]
        m = self.args[1] if len(self.args) == 2 else 1

        if m == S.One:
            if n.is_Add:
                off = n.args[0]
                nnew = n - off
                if off.is_Integer and off.is_positive:
                    result = [S.One / (nnew + i)
                              for i in range(off, 0, -1)] + [harmonic(nnew)]
                    return Add(*result)
                elif off.is_Integer and off.is_negative:
                    result = [-S.One / (nnew + i)
                              for i in range(0, off, -1)] + [harmonic(nnew)]
                    return Add(*result)

            if n.is_Rational:
                # Expansions for harmonic numbers at general rational arguments (u + p/q)
                # Split n as u + p/q with p < q
                p, q = n.as_numer_denom()
                u = p // q
                p = p - u * q
                if u.is_nonnegative and p.is_positive and q.is_positive and p < q:
                    k = Dummy("k")
                    t1 = q * Sum(1 / (q * k + p), (k, 0, u))
                    t2 = 2 * Sum(
                        cos((2 * pi * p * k) / q) * log(sin((pi * k) / q)),
                        (k, 1, floor((q - 1) / Integer(2))))
                    t3 = (pi / 2) * cot((pi * p) / q) + log(2 * q)
                    return t1 + t2 - t3

        return self
Exemple #9
0
 def as_real_imag(self, deep=True, **hints):
     # TODO: Handle deep and hints
     n, m, theta, phi = self.args
     re = (sqrt((2*n + 1)/(4*pi) * factorial(n - m)/factorial(n + m)) *
           cos(m*phi) * assoc_legendre(n, m, cos(theta)))
     im = (sqrt((2*n + 1)/(4*pi) * factorial(n - m)/factorial(n + m)) *
           sin(m*phi) * assoc_legendre(n, m, cos(theta)))
     return re, im
Exemple #10
0
 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return ((3**Rational(1, 3) * x)**(-n) *
                     (3**Rational(1, 3) * x)**(n + 1) *
                     sin(pi * (2 * n / 3 + Rational(4, 3))) * factorial(n) *
                     gamma(n / 3 + Rational(2, 3)) /
                     (sin(pi * (2 * n / 3 + Rational(2, 3))) *
                      factorial(n + 1) * gamma(n / 3 + Rational(1, 3))) * p)
         else:
             return (S.One / (3**Rational(2, 3) * pi) * gamma(
                 (n + S.One) / Integer(3)) * sin(2 * pi *
                                                 (n + S.One) / Integer(3)) /
                     factorial(n) * (root(3, 3) * x)**n)
Exemple #11
0
 def taylor_term(n, x, *previous_terms):
     if n < 0:
         return S.Zero
     else:
         x = sympify(x)
         if len(previous_terms) > 1:
             p = previous_terms[-1]
             return (3**Rational(1, 3) * x *
                     Abs(sin(2 * pi *
                             (n + S.One) / Integer(3))) * factorial(
                                 (n - S.One) / Integer(3)) /
                     ((n + S.One) *
                      Abs(cos(2 * pi *
                              (n + S.Half) / Integer(3))) * factorial(
                                  (n - 2) / Integer(3))) * p)
         else:
             return (S.One / (root(3, 6) * pi) * gamma(
                 (n + S.One) / Integer(3)) *
                     Abs(sin(2 * pi * (n + S.One) / Integer(3))) /
                     factorial(n) * (root(3, 3) * x)**n)
Exemple #12
0
 def fdiff(self, argindex=1):
     if len(self.args) == 2:
         z, m = self.args
         if argindex == 1:
             return sqrt(1 - m * sin(z)**2)
         elif argindex == 2:
             return (elliptic_e(z, m) - elliptic_f(z, m)) / (2 * m)
     else:
         z = self.args[0]
         if argindex == 1:
             return (elliptic_e(z) - elliptic_k(z)) / (2 * z)
     raise ArgumentIndexError(self, argindex)
Exemple #13
0
 def eval(cls, n, m, z=None):
     if z is not None:
         n, z, m = n, m, z
         k = 2 * z / pi
         if n == S.Zero:
             return elliptic_f(z, m)
         elif n == S.One:
             return (elliptic_f(z, m) +
                     (sqrt(1 - m * sin(z)**2) * tan(z) - elliptic_e(z, m)) /
                     (1 - m))
         elif k.is_integer:
             return k * elliptic_pi(n, m)
         elif m == S.Zero:
             return atanh(sqrt(n - 1) * tan(z)) / sqrt(n - 1)
         elif n == m:
             return (elliptic_f(z, n) - elliptic_pi(1, z, n) +
                     tan(z) / sqrt(1 - n * sin(z)**2))
         elif n in (S.Infinity, S.NegativeInfinity):
             return S.Zero
         elif m in (S.Infinity, S.NegativeInfinity):
             return S.Zero
         elif z.could_extract_minus_sign():
             return -elliptic_pi(n, -z, m)
     else:
         if n == S.Zero:
             return elliptic_k(m)
         elif n == S.One:
             return S.ComplexInfinity
         elif m == S.Zero:
             return pi / (2 * sqrt(1 - n))
         elif m == S.One:
             return -S.Infinity / sign(n - 1)
         elif n == m:
             return elliptic_e(n) / (1 - n)
         elif n in (S.Infinity, S.NegativeInfinity):
             return S.Zero
         elif m in (S.Infinity, S.NegativeInfinity):
             return S.Zero
Exemple #14
0
def test_Max():
    from diofant.abc import x, y, z
    n = Symbol('n', negative=True)
    n_ = Symbol('n_', negative=True)
    nn = Symbol('nn', nonnegative=True)
    nn_ = Symbol('nn_', nonnegative=True)
    p = Symbol('p', positive=True)
    p_ = Symbol('p_', positive=True)
    np = Symbol('np', nonpositive=True)
    np_ = Symbol('np_', nonpositive=True)
    r = Symbol('r', extended_real=True)

    assert Max(5, 4) == 5

    # lists

    pytest.raises(ValueError, lambda: Max())
    assert Max(x, y) == Max(y, x)
    assert Max(x, y, z) == Max(z, y, x)
    assert Max(x, Max(y, z)) == Max(z, y, x)
    assert Max(x, Min(y, oo)) == Max(x, y)
    assert Max(n, -oo, n_, p, 2) == Max(p, 2)
    assert Max(n, -oo, n_, p) == p
    assert Max(2, x, p, n, -oo, S.NegativeInfinity, n_, p, 2) == Max(2, x, p)
    assert Max(0, x, 1, y) == Max(1, x, y)
    assert Max(r, r + 1, r - 1) == 1 + r
    assert Max(1000, 100, -100, x, p, n) == Max(p, x, 1000)
    assert Max(cos(x), sin(x)) == Max(sin(x), cos(x))
    assert Max(cos(x), sin(x)).subs(x, 1) == sin(1)
    assert Max(cos(x), sin(x)).subs(x, Rational(1, 2)) == cos(Rational(1, 2))
    pytest.raises(ValueError, lambda: Max(cos(x), sin(x)).subs(x, I))
    pytest.raises(ValueError, lambda: Max(I))
    pytest.raises(ValueError, lambda: Max(I, x))
    pytest.raises(ValueError, lambda: Max(S.ComplexInfinity, 1))
    # interesting:
    # Max(n, -oo, n_,  p, 2) == Max(p, 2)
    # True
    # Max(n, -oo, n_,  p, 1000) == Max(p, 1000)
    # False

    assert Max(1, x).diff(x) == Heaviside(x - 1)
    assert Max(x, 1).diff(x) == Heaviside(x - 1)
    assert Max(x**2, 1 + x, 1).diff(x) == \
        2*x*Heaviside(x**2 - Max(1, x + 1)) \
        + Heaviside(x - Max(1, x**2) + 1)

    a, b = Symbol('a', extended_real=True), Symbol('b', extended_real=True)
    # a and b are both real, Max(a, b) should be real
    assert Max(a, b).is_extended_real

    # issue 7233
    e = Max(0, x)
    assert e.evalf == e.n
    assert e.n().args == (0, x)
Exemple #15
0
    def arbitrary_point(self, parameter='t'):
        """A parameterized point on the ellipse.

        Parameters
        ==========

        parameter : str, optional
            Default value is 't'.

        Returns
        =======

        arbitrary_point : Point

        Raises
        ======

        ValueError
            When `parameter` already appears in the functions.

        See Also
        ========

        diofant.geometry.point.Point

        Examples
        ========

        >>> from diofant import Point, Ellipse
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.arbitrary_point()
        Point2D(3*cos(t), 2*sin(t))

        """
        t = _symbol(parameter)
        if t.name in (f.name for f in self.free_symbols):
            raise ValueError(
                filldedent('Symbol %s already appears in object '
                           'and cannot be used as a parameter.' % t.name))
        return Point(self.center.x + self.hradius * cos(t),
                     self.center.y + self.vradius * sin(t))
Exemple #16
0
def rot_axis1(theta):
    """Returns a rotation matrix for a rotation of theta (in radians) about
    the 1-axis.

    Examples
    ========

    >>> from diofant import pi
    >>> from diofant.matrices import rot_axis1

    A rotation of pi/3 (60 degrees):

    >>> theta = pi/3
    >>> rot_axis1(theta)
    Matrix([
    [1,          0,         0],
    [0,        1/2, sqrt(3)/2],
    [0, -sqrt(3)/2,       1/2]])

    If we rotate by pi/2 (90 degrees):

    >>> rot_axis1(pi/2)
    Matrix([
    [1,  0, 0],
    [0,  0, 1],
    [0, -1, 0]])

    See Also
    ========

    diofant.matrices.dense.rot_axis2: Returns a rotation matrix for a rotation of theta (in radians)
        about the 2-axis
    diofant.matrices.dense.rot_axis3: Returns a rotation matrix for a rotation of theta (in radians)
        about the 3-axis
    """
    ct = cos(theta)
    st = sin(theta)
    lil = ((1, 0, 0), (0, ct, st), (0, -st, ct))
    return Matrix(lil)
Exemple #17
0
def test_input_format():
    pytest.raises(TypeError, lambda: diophantine(sin(x)))
    pytest.raises(TypeError, lambda: diophantine(3))
    pytest.raises(TypeError, lambda: diophantine(x / pi - 3))
Exemple #18
0
def test_TableForm_latex():
    s = latex(
        TableForm(
            [[0, x**3], ["c", Rational(1, 4)], [sqrt(x), sin(x**2)]],
            wipe_zeros=True,
            headings=("automatic", "automatic")))
    assert s == ('\\begin{tabular}{r l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 &   & $x^{3}$ \\\\\n'
                 '2 & $c$ & $\\frac{1}{4}$ \\\\\n'
                 '3 & $\\sqrt{x}$ & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')
    s = latex(
        TableForm(
            [[0, x**3], ["c", Rational(1, 4)], [sqrt(x), sin(x**2)]],
            wipe_zeros=True,
            headings=("automatic", "automatic"),
            alignments='l'))
    assert s == ('\\begin{tabular}{r l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 &   & $x^{3}$ \\\\\n'
                 '2 & $c$ & $\\frac{1}{4}$ \\\\\n'
                 '3 & $\\sqrt{x}$ & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')
    s = latex(
        TableForm(
            [[0, x**3], ["c", Rational(1, 4)], [sqrt(x), sin(x**2)]],
            wipe_zeros=True,
            headings=("automatic", "automatic"),
            alignments='l' * 3))
    assert s == ('\\begin{tabular}{l l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 &   & $x^{3}$ \\\\\n'
                 '2 & $c$ & $\\frac{1}{4}$ \\\\\n'
                 '3 & $\\sqrt{x}$ & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')
    s = latex(
        TableForm(
            [["a", x**3], ["c", Rational(1, 4)], [sqrt(x), sin(x**2)]],
            headings=("automatic", "automatic")))
    assert s == ('\\begin{tabular}{r l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 & $a$ & $x^{3}$ \\\\\n'
                 '2 & $c$ & $\\frac{1}{4}$ \\\\\n'
                 '3 & $\\sqrt{x}$ & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')
    s = latex(
        TableForm(
            [["a", x**3], ["c", Rational(1, 4)], [sqrt(x), sin(x**2)]],
            formats=['(%s)', None],
            headings=("automatic", "automatic")))
    assert s == ('\\begin{tabular}{r l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 & (a) & $x^{3}$ \\\\\n'
                 '2 & (c) & $\\frac{1}{4}$ \\\\\n'
                 '3 & (sqrt(x)) & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')

    def neg_in_paren(x, i, j):
        if i % 2:
            return ('(%s)' if x < 0 else '%s') % x
        else:
            pass  # use default print

    s = latex(
        TableForm([[-1, 2], [-3, 4]],
                  formats=[neg_in_paren] * 2,
                  headings=("automatic", "automatic")))
    assert s == ('\\begin{tabular}{r l l}\n'
                 ' & 1 & 2 \\\\\n'
                 '\\hline\n'
                 '1 & -1 & 2 \\\\\n'
                 '2 & (-3) & 4 \\\\\n'
                 '\\end{tabular}')
    s = latex(
        TableForm([["a", x**3], ["c", Rational(1, 4)], [sqrt(x),
                                                        sin(x**2)]]))
    assert s == ('\\begin{tabular}{l l}\n'
                 '$a$ & $x^{3}$ \\\\\n'
                 '$c$ & $\\frac{1}{4}$ \\\\\n'
                 '$\\sqrt{x}$ & $\\sin{\\left (x^{2} \\right )}$ \\\\\n'
                 '\\end{tabular}')
Exemple #19
0
    def random_point(self, seed=None):
        """A random point on the ellipse.

        Returns
        =======

        point : Point

        See Also
        ========

        diofant.geometry.point.Point
        arbitrary_point : Returns parameterized point on ellipse

        Notes
        -----

        A random point may not appear to be on the ellipse, ie, `p in e` may
        return False. This is because the coordinates of the point will be
        floating point values, and when these values are substituted into the
        equation for the ellipse the result may not be zero because of floating
        point rounding error.

        Examples
        ========

        >>> from diofant import Point, Ellipse, Segment
        >>> e1 = Ellipse(Point(0, 0), 3, 2)
        >>> e1.random_point() # gives some random point
        Point2D(...)
        >>> p1 = e1.random_point(seed=0); p1.n(2)
        Point2D(2.1, 1.4)

        The random_point method assures that the point will test as being
        in the ellipse:

        >>> p1 in e1
        True

        Notes
        =====

        An arbitrary_point with a random value of t substituted into it may
        not test as being on the ellipse because the expression tested that
        a point is on the ellipse doesn't simplify to zero and doesn't evaluate
        exactly to zero:

        >>> from diofant.abc import t
        >>> e1.arbitrary_point(t)
        Point2D(3*cos(t), 2*sin(t))
        >>> p2 = _.subs(t, 0.1)
        >>> p2 in e1
        False

        Note that arbitrary_point routine does not take this approach. A value
        for cos(t) and sin(t) (not t) is substituted into the arbitrary point.
        There is a small chance that this will give a point that will not
        test as being in the ellipse, so the process is repeated (up to 10
        times) until a valid point is obtained.

        """
        from diofant import sin, cos, Rational
        t = _symbol('t')
        x, y = self.arbitrary_point(t).args
        # get a random value in [-1, 1) corresponding to cos(t)
        # and confirm that it will test as being in the ellipse
        if seed is not None:
            rng = random.Random(seed)
        else:
            rng = random
        for i in range(10):  # should be enough?
            # simplify this now or else the Float will turn s into a Float
            c = 2 * Rational(rng.random()) - 1
            s = sqrt(1 - c**2)
            p1 = Point(x.subs(cos(t), c), y.subs(sin(t), s))
            if p1 in self:
                return p1
        raise GeometryError(
            'Having problems generating a point in the ellipse.')
Exemple #20
0
def test_sympyissue_6782():
    assert sqrt(sin(x**3)).series(x, 0, 7) == x**Rational(3, 2) + O(x**7)
    assert sqrt(sin(x**4)).series(x, 0, 3) == x**2 + O(x**3)
Exemple #21
0
def test_sympyissue_6653():
    assert (1 / sqrt(1 + sin(x**2))).series(x, 0, 3) == 1 - x**2/2 + O(x**3)
Exemple #22
0
 def _eval_expand_func(self, **hints):
     n, m, theta, phi = self.args
     rv = (sqrt((2*n + 1)/(4*pi) * factorial(n - m)/factorial(n + m)) *
             exp(I*m*phi) * assoc_legendre(n, m, cos(theta)))
     # We can do this because of the range of theta
     return rv.subs(sqrt(-cos(theta)**2 + 1), sin(theta))
Exemple #23
0
def test_sympyissue_6653():
    x = Symbol('x')
    assert (1 / sqrt(1 + sin(x**2))).series(x, 0, 3) == 1 - x**2/2 + O(x**3)
Exemple #24
0
def test_sympyissue_6782():
    x = Symbol('x')
    assert sqrt(sin(x**3)).series(x, 0, 7) == x**Rational(3, 2) + O(x**7)
    assert sqrt(sin(x**4)).series(x, 0, 3) == x**2 + O(x**3)
Exemple #25
0
def gauss_chebyshev_u(n, n_digits):
    r"""
    Computes the Gauss-Chebyshev quadrature [1]_ points and weights of
    the second kind.

    The Gauss-Chebyshev quadrature of the second kind approximates the integral:

    .. math::
        \int_{-1}^{1} \sqrt{1-x^2} f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)

    The nodes `x_i` of an order `n` quadrature rule are the roots of `U_n`
    and the weights `w_i` are given by:

    .. math::
        w_i = \frac{\pi}{n+1} \sin^2 \left(\frac{i}{n+1}\pi\right)

    Parameters
    ==========

    n : the order of quadrature

    n_digits : number of significant digits of the points and weights to return

    Returns
    =======

    (x, w) : the ``x`` and ``w`` are lists of points and weights as Floats.
             The points `x_i` and weights `w_i` are returned as ``(x, w)``
             tuple of lists.

    Examples
    ========

    >>> from diofant import S, pprint
    >>> from diofant.integrals.quadrature import gauss_chebyshev_u
    >>> x, w = gauss_chebyshev_u(3, 5)
    >>> x
    [0.70711, 0, -0.70711]
    >>> pprint(w)
    [0.3927, 0.7854, 0.3927]

    >>> x, w = gauss_chebyshev_u(6, 5)
    >>> x
    [0.90097, 0.62349, 0.22252, -0.22252, -0.62349, -0.90097]
    >>> w
    [0.084489, 0.27433, 0.42658, 0.42658, 0.27433, 0.084489]

    See Also
    ========

    diofant.integrals.quadrature.gauss_legendre
    diofant.integrals.quadrature.gauss_laguerre
    diofant.integrals.quadrature.gauss_hermite
    diofant.integrals.quadrature.gauss_gen_laguerre
    diofant.integrals.quadrature.gauss_chebyshev_t
    diofant.integrals.quadrature.gauss_jacobi

    References
    ==========

    .. [1] http://en.wikipedia.org/wiki/Chebyshev%E2%80%93Gauss_quadrature
    .. [2] http://people.sc.fsu.edu/~jburkardt/cpp_src/chebyshev2_rule/chebyshev2_rule.html
    """
    x = Dummy("x")
    xi = []
    w = []
    for i in range(1, n + 1):
        xi.append((cos(i / (n + S.One) * S.Pi)).n(n_digits))
        w.append(
            (S.Pi / (n + S.One) * sin(i * S.Pi / (n + S.One))**2).n(n_digits))
    return xi, w
Exemple #26
0
 def _expand(self, **hints):
     n = self.order
     z = self.argument
     return (-1)**(n + 1) * \
            (fn(-n - 1, z) * sin(z) + (-1)**(-n) * fn(n, z) * cos(z))
Exemple #27
0
def test_Min():
    from diofant.abc import x, y, z
    n = Symbol('n', negative=True)
    n_ = Symbol('n_', negative=True)
    nn = Symbol('nn', nonnegative=True)
    nn_ = Symbol('nn_', nonnegative=True)
    p = Symbol('p', positive=True)
    p_ = Symbol('p_', positive=True)
    np = Symbol('np', nonpositive=True)
    np_ = Symbol('np_', nonpositive=True)

    assert Min(5, 4) == 4
    assert Min(-oo, -oo) == -oo
    assert Min(-oo, n) == -oo
    assert Min(n, -oo) == -oo
    assert Min(-oo, np) == -oo
    assert Min(np, -oo) == -oo
    assert Min(-oo, 0) == -oo
    assert Min(0, -oo) == -oo
    assert Min(-oo, nn) == -oo
    assert Min(nn, -oo) == -oo
    assert Min(-oo, p) == -oo
    assert Min(p, -oo) == -oo
    assert Min(-oo, oo) == -oo
    assert Min(oo, -oo) == -oo
    assert Min(n, n) == n
    assert Min(n, np) == Min(n, np)
    assert Min(np, n) == Min(np, n)
    assert Min(n, 0) == n
    assert Min(0, n) == n
    assert Min(n, nn) == n
    assert Min(nn, n) == n
    assert Min(n, p) == n
    assert Min(p, n) == n
    assert Min(n, oo) == n
    assert Min(oo, n) == n
    assert Min(np, np) == np
    assert Min(np, 0) == np
    assert Min(0, np) == np
    assert Min(np, nn) == np
    assert Min(nn, np) == np
    assert Min(np, p) == np
    assert Min(p, np) == np
    assert Min(np, oo) == np
    assert Min(oo, np) == np
    assert Min(0, 0) == 0
    assert Min(0, nn) == 0
    assert Min(nn, 0) == 0
    assert Min(0, p) == 0
    assert Min(p, 0) == 0
    assert Min(0, oo) == 0
    assert Min(oo, 0) == 0
    assert Min(nn, nn) == nn
    assert Min(nn, p) == Min(nn, p)
    assert Min(p, nn) == Min(p, nn)
    assert Min(nn, oo) == nn
    assert Min(oo, nn) == nn
    assert Min(p, p) == p
    assert Min(p, oo) == p
    assert Min(oo, p) == p
    assert Min(oo, oo) == oo

    assert Min(n, n_).func is Min
    assert Min(nn, nn_).func is Min
    assert Min(np, np_).func is Min
    assert Min(p, p_).func is Min

    # lists
    pytest.raises(ValueError, lambda: Min())
    assert Min(x, y) == Min(y, x)
    assert Min(x, y, z) == Min(z, y, x)
    assert Min(x, Min(y, z)) == Min(z, y, x)
    assert Min(x, Max(y, -oo)) == Min(x, y)
    assert Min(p, oo, n, p, p, p_) == n
    assert Min(p_, n_, p) == n_
    assert Min(n, oo, -7, p, p, 2) == Min(n, -7)
    assert Min(2, x, p, n, oo, n_, p, 2, -2, -2) == Min(-2, x, n, n_)
    assert Min(0, x, 1, y) == Min(0, x, y)
    assert Min(1000, 100, -100, x, p, n) == Min(n, x, -100)
    assert Min(cos(x), sin(x)) == Min(cos(x), sin(x))
    assert Min(cos(x), sin(x)).subs(x, 1) == cos(1)
    assert Min(cos(x), sin(x)).subs(x, Rational(1, 2)) == sin(Rational(1, 2))
    pytest.raises(ValueError, lambda: Min(cos(x), sin(x)).subs(x, I))
    pytest.raises(ValueError, lambda: Min(I))
    pytest.raises(ValueError, lambda: Min(I, x))
    pytest.raises(ValueError, lambda: Min(S.ComplexInfinity, x))

    assert Min(1, x).diff(x) == Heaviside(1 - x)
    assert Min(x, 1).diff(x) == Heaviside(1 - x)
    assert Min(0, -x, 1 - 2*x).diff(x) == -Heaviside(x + Min(0, -2*x + 1)) \
        - 2*Heaviside(2*x + Min(0, -x) - 1)

    a, b = Symbol('a', extended_real=True), Symbol('b', extended_real=True)
    # a and b are both real, Min(a, b) should be real
    assert Min(a, b).is_extended_real

    # issue 7619
    f = Function('f')
    assert Min(1, 2 * Min(f(1), 2))  # doesn't fail

    # issue 7233
    e = Min(0, x)
    assert e.evalf == e.n
    assert e.n().args == (0, x)
def test_input_format():
    pytest.raises(TypeError, lambda: diophantine(sin(x)))
    pytest.raises(TypeError, lambda: diophantine(3))
    pytest.raises(TypeError, lambda: diophantine(x/pi - 3))