Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

simplify trigonometric and hyperbolic functions with argument I*something #162

Merged
merged 5 commits into from Aug 28, 2017

Conversation

behackl
Copy link
Contributor

@behackl behackl commented Mar 6, 2016

The code here currently implements the simplifications sin(I*something) --> I*sinh(something) and cos(I*something) --> cosh(something).

Performance probably is a bit worse (a call to real_part is needed, which is python/cython).

This should only be considered mergeable after the following TODOs are done:

@rwst
Copy link
Member

rwst commented Mar 6, 2016

This is pretty optimal, hard to see how to make it faster.

@behackl
Copy link
Contributor Author

behackl commented Mar 6, 2016

You are right; I've overestimated the cost of the additional real_part call.

The following behavior seems inconsistent to me:

sage: coth(0)
Infinity
sage: cot(0)
Traceback (most recent call last):
...
RuntimeError: cotan_eval(): cot(0) encountered

We should probably stop raising errors at poles and simply return UnsignedInfinity instead.

@rwst
Copy link
Member

rwst commented Mar 7, 2016

**********************************************************************
File "src/sage/symbolic/pynac.pyx", line 1426, in sage.symbolic.pynac.py_sin
Failed example:
    sin(QQbar(I))
Exception raised:
    Traceback (most recent call last):
      File "/home/ralf/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/ralf/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.symbolic.pynac.py_sin[3]>", line 1, in <module>
        sin(QQbar(I))
      File "sage/symbolic/function.pyx", line 841, in sage.symbolic.function.GinacFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:9757)
        res = super(GinacFunction, self).__call__(*args, **kwds)
      File "sage/symbolic/function.pyx", line 988, in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11320)
        res = super(BuiltinFunction, self).__call__(
      File "sage/symbolic/function.pyx", line 505, in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:7132)
        res = g_function_eval1(self._serial,
      File "sage/structure/element.pyx", line 1798, in sage.structure.element.RingElement.__mul__ (build/cythonized/sage/structure/element.c:16400)
        return coercion_model.bin_op(left, right, mul)
      File "sage/structure/coerce.pyx", line 1069, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/home/ralf/sage/src/build/cythonized/sage/structure/coerce.c:9736)
        raise TypeError(arith_error_message(x,y,op))
    TypeError: unsupported operand parent(s) for '*': 'Algebraic Field' and 'Number Field in I with defining polynomial x^2 + 1'
**********************************************************************
File "src/sage/symbolic/pynac.pyx", line 1448, in sage.symbolic.pynac.py_cos
Failed example:
    cos(QQbar(I))
Exception raised:
    Traceback (most recent call last):
      File "/home/ralf/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 496, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/home/ralf/sage/local/lib/python2.7/site-packages/sage/doctest/forker.py", line 858, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.symbolic.pynac.py_cos[3]>", line 1, in <module>
        cos(QQbar(I))
      File "sage/symbolic/function.pyx", line 841, in sage.symbolic.function.GinacFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:9757)
        res = super(GinacFunction, self).__call__(*args, **kwds)
      File "sage/symbolic/function.pyx", line 988, in sage.symbolic.function.BuiltinFunction.__call__ (build/cythonized/sage/symbolic/function.cpp:11320)
        res = super(BuiltinFunction, self).__call__(
      File "sage/symbolic/function.pyx", line 505, in sage.symbolic.function.Function.__call__ (build/cythonized/sage/symbolic/function.cpp:7132)
        res = g_function_eval1(self._serial,
      File "sage/structure/element.pyx", line 1798, in sage.structure.element.RingElement.__mul__ (build/cythonized/sage/structure/element.c:16400)
        return coercion_model.bin_op(left, right, mul)
      File "sage/structure/coerce.pyx", line 1069, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (/home/ralf/sage/src/build/cythonized/sage/structure/coerce.c:9736)
        raise TypeError(arith_error_message(x,y,op))
    TypeError: unsupported operand parent(s) for '*': 'Algebraic Field' and 'Number Field in I with defining polynomial x^2 + 1'
**********************************************************************

@behackl
Copy link
Contributor Author

behackl commented Mar 7, 2016

I'm a bit irritated where the Number Field in I with defining polynomial x^2 + 1 actually comes from; pynac's I should be from SR, and QQbar(I) is from Algebraic Field.

Nevertheless, related to #164?

@behackl
Copy link
Contributor Author

behackl commented Mar 7, 2016

Nevermind, just found out that this is in fact pynac's I.

@rwst
Copy link
Member

rwst commented Mar 7, 2016

Yes, I is special 8) Yes #164 is related but not the cause. If you set catch throw in sage -gdb you will find it's a coercion problem.

@rwst
Copy link
Member

rwst commented Aug 28, 2017

I'm very sorry that I haven't looked at this for so long. I have now fixed the conflict, I get a funny fail:

File "src/sage/functions/log.py", line 83, in sage.functions.log.Function_exp.__init__
Failed example:
    exp(log(2) + 2*k*pi*I)
Expected:
    2
Got:
    cosh(-log(2)) - sinh(-log(2))

@rwst
Copy link
Member

rwst commented Aug 28, 2017

I'll implement sinh/cosh(log(x)) then merge the PR on top of it.

@rwst rwst merged commit 3f56066 into pynac:master Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants