Skip to content

Cotangent producing incorrect real/imaginary parts. #29400

@TheFool5

Description

@TheFool5
mannequin

While doing some complex analysis, I encountered a bug when evaluating the cotangent function of a complex number when multiplied by a complex number. When p and q are complex, real(pcot(q)) or imag(pcot(q)) produces a wrong result, while real(p/tan(q)) or imag(p/tan(q)) produces the correct result.

For example:

sage: a=(1+2*i)/tan(3+4*i)                                                                                                                                                                                 
sage: b=(1+2*i)*cot(3+4*i)
sage: a.real().n()                                                                                                                                                                                         
2.00110119720514
sage: b.real().n()                                                                                                                                                                                         
-2.00147637268110
sage: a.imag().n()                                                                                                                                                                                         
-1.00101956794753
sage: b.imag().n()                                                                                                                                                                                         
1.00026921699559

Additionally, when trying to numerically evaluate b with cotangent, it simply returns an error. The numerical evaluation of a with tangent is returned without error.

sage: a.n()                                                                                                                                                                                                
2.00110119720513 - 1.00101956794753*I
sage: b.n()                                                                                                                                                                                                
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-97-d3276c847f4d> in <module>
----> 1 b.n()

/usr/lib/python3.8/site-packages/sage/structure/element.pyx in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8033)()
    857             0.666666666666667
    858         """
--> 859         return self.numerical_approx(prec, digits, algorithm)
    860 
    861     def _mpmath_(self, prec=53, rounding=None):

/usr/lib/python3.8/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:34713)()
   5998             res = x.pyobject()
   5999         else:
-> 6000             raise TypeError("cannot evaluate symbolic expression numerically")
   6001 
   6002         # Important -- the  we get might not be a valid output for numerical_approx in

TypeError: cannot evaluate symbolic expression numerically

I conducted this same test using both tangent and cotangent in Maxima. They are both correct, and agree with the results involving tangent in Sage. But for whatever reason in Sage, cotangent does not seem to work correctly when evaluating numerically or getting the real/imaginary part.

Upstream: Fixed upstream, in a later stable release.

Component: symbolics

Keywords: defect cotangent sympy

Author: Dave Morris

Branch/Commit: 275f5b9

Reviewer: Matthias Koeppe

Issue created by migration from https://trac.sagemath.org/ticket/29400

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions