Ticket #1891 (assigned bug)

Opened 4 years ago

Last modified 3 years ago

Problems with acosh, asech, atanh and acoth in Complex PMC

Reported by: fbrito Owned by: Util
Priority: normal Milestone: 2.11
Component: core Version: 2.10.0
Severity: medium Keywords: complex math trig
Cc: Language:
Patch status: Platform: all

Description

Hello,

While doing  this GCI task I had some problems with "acosh".

Here is the output of tests that I wrote:

not ok 529 - acosh of 0-1i
# Have: -0.881374+1.570796i
# Want: 0.881374-1.570796i

not ok 530 - acosh of 0-0.5i
# Have: -0.481212+1.570796i
# Want: 0.481212-1.570796i

not ok 535 - acosh of 2-3i
# Have: -1.983387+1.000144i
# Want: 1.983387-1.000144i

not ok 537 - acosh of -2-3i
# Have: -1.983387+2.141449i
# Want: 1.983387-2.141449i

The "want" values were taken from WolframAlpha (ex  http://www.wolframalpha.com/input/?i=acosh(2-3i)).

Some other methods that relies on "acosh" are also returning a wrong value, like "asech".

not ok 587 - asech of 0.5+0i
# Have: -1.316958+0.000000i
# Want: 1.316958+0.000000i

not ok 593 - asech of 0+0.5i
# Have: -1.443635+1.570796i
# Want: 1.443635-1.570796i

not ok 594 - asech of 0+1i
# Have: -0.881374+1.570796i
# Want: 0.881374-1.570796i

not ok 595 - asech of 0+2i
# Have: -0.481212+1.570796i
# Want: 0.481212-1.570796i

not ok 596 - asech of 2+3i
# Have: -0.231335+1.420411i
# Want: 0.231335-1.420411i

not ok 598 - asech of -2+3i
# Have: -0.231335+1.721182i
# Want: 0.231335-1.721182i

I also found some errors in "atanh" and "acoth":

not ok 538 - atanh of -2+0i
# Have: -0.549306-1.570796i
# Want: -0.549306+1.570796i

not ok 554 - acoth of -0.5+0i
# Have: -0.549306-1.570796i
# Want: -0.549306+1.570796i

The tests that I wrote can be found here:  https://github.com/fernandobrito/parrot/commits/gci_tests

Environment: Ubuntu 10.10, Parrot 2.10.1 (master branch), Perl 5.10.1 i686-linux-gnu-thread-multi, cc (gcc 4.4), i386, linux

Change History

Changed 3 years ago by Util

  • keywords complex math trig added
  • owner set to Util
  • component changed from none to core
  • platform set to all

acosh, asech, and atanh are implemented incorrectly.

I am working on the problem in branch Util/tt_1891_complex_trig :  https://github.com/parrot/parrot/tree/Util%2Ftt_1891_complex_trig

Changed 3 years ago by Util

  • status changed from new to assigned

Be advised, problems are turning up in other data sources:

I will rely on the standard C library as the "absolute truth", until counter-evidence arrives.

    #include <stdio.h>
    #include <complex.h>
    int main(void) {
        const double complex z = 2.0 - 3.0 * I;
        const double complex c = cacosh(z);
        printf(
            "cacosh(%lg%+lgi) is %lf%+lfi\n",
            creal(z), cimag(z),
            creal(c), cimag(c)
        );
        return 0;
    }

Outputs:

cacosh(2-3i) is 1.983387-1.000144i

 http://www.wolframalpha.com/input/?i=acosh(2-3i)

1.983387-1.00014354247i

More evidence that the C answer is correct.

perl -MMath::Complex -wle '$f=cplxe(2,-3); $g = acosh $f; print "$g"'

1.32074266859523-2.97863118461102i

Looks completely wrong to me. Also, when fed back into cosh(), does not even come close to (2,-3).

perl -MMath::Cephes::Complex=cmplx -wle '$f=cmplx(2,-3); $g = $f->cacosh; print $g->as_string'

-1.983387 + 1.000144 i

The signs are backwards, but cosh(z) == cosh(-z), so maybe this is just another form of "correct"?

Will pursue further tomorrow.

Note: See TracTickets for help on using tickets.