Opened 3 years ago

# Systematic doctest for function return type

Reported by: Owned by: zimmerma major sage-8.2 symbolics jdemeyer Ralf Stephan Paul Zimmermann N/A u/rws/24299 0b52ecd01cd3c8aa28f10ef9627276b674aadda6 #24318, #24329, #24604

```sage: sinh(CIF(1))
[1.1752011936438013 .. 1.1752011936438017]
sage: asinh(CIF(1))
0.881373587019543
```

The second command should return a (complex) interval.

Also:

```sage: asin(CIF(0.6))
...
TypeError: unable to convert '0.59999999999999998?' to a real number
```

### comment:2 Changed 3 years ago by rws

• Component changed from basic arithmetic to symbolics

That's a symbolic function evaluation issue, not the fault of CIF.

### comment:3 Changed 3 years ago by rws

As an explanation, the handling of inexact function arguments has several layers. The fallback layer (if the arg has no suitable member function and exact evaluation has no tricks) is to call the helper functions in `libs/pynac/pynac.pyx` which use member functions of RR and CC. There is in most cases no automatic back-conversion to the argument type so, as fallback, you at least get `Real/ComplexField` elements.

There is work ongoing in Pynac to use arb instead of `RR` and `CC` because of speed and ease of conversion to e.g. interval field elements. It's just that inverse hyperbolic functions are still waiting for it. Of course one could state it's the responsibility of CIF to implement inverse hyperbolic functions (and inverse trig functions, for that matter) but I'm not holding my breath. CIF is a math programming exercise, Pynac tries to solve real calculus problems, so we'll implement it in Pynac-0.7.14.

### comment:4 Changed 3 years ago by rws

• Description modified (diff)
• Milestone changed from sage-8.1 to sage-8.2
• Summary changed from asinh(CIF(1)) returns an element of CC instead of CIF to Bugs with inverse trig and hyperbolic functions of CIF argument

### comment:5 Changed 3 years ago by rws

• Dependencies set to #24317

### comment:6 Changed 3 years ago by rws

• Dependencies changed from #24317 to #24318, pynac-0.7.14

### comment:7 Changed 3 years ago by rws

• Branch set to u/rws/bugs_with_inverse_trig_and_hyperbolic_functions_of_cif_argument

### comment:8 Changed 3 years ago by rws

• Authors set to Ralf Stephan
• Dependencies changed from #24318, pynac-0.7.14 to #24318, #24329
• Status changed from new to needs_review
• Summary changed from Bugs with inverse trig and hyperbolic functions of CIF argument to Doctest: inverse trig and hyperbolic functions of CIF argument

New commits:

 ​0dad6ad `24299: Bugs with inverse trig and hyperbolic functions of CIF argument`

### comment:9 follow-up: ↓ 10 Changed 3 years ago by zimmerma

I'd like to review this, but I see only non-regression tests in commit ​0dad6ad, and no changes in the source code. How could the results change?

### comment:10 in reply to: ↑ 9 Changed 3 years ago by rws

I'd like to review this, but I see only non-regression tests in commit ​0dad6ad, and no changes in the source code. How could the results change?

Functions can be either coded in Python (`BuiltinFunction`) or C++ (`GinacFunction` in Pynac). FP evaluation first looks if CIF has a member for `asinh` and, as there isn't, the function's `evalf` member is called. As trig and hyperbolic functions are `GinacFunction`s the changes needed to be done in Pynac, and they became effect with #24329 which was introduced in beta0 I think. So, in order to see the doctests fail you need to go back to 8.1.

### comment:11 follow-up: ↓ 16 Changed 3 years ago by zimmerma

• Reviewers set to Paul Zimmermann
• Status changed from needs_review to needs_work

```sage: acoth(CIF(0.6))
0.693147180559945?
```

since we get with CC:

```sage: acoth(CC(0.6))
0.693147180559945 - 1.57079632679490*I
```

### comment:12 Changed 3 years ago by rws

Agreed, still buggy.

### comment:13 Changed 3 years ago by rws

I did a systematic search and found these additional issues:

```sage: log_gamma(complex(1.7))
-0.09580769740706588
sage: psi(complex(1.7))
0.2085478748734939
```

Also `dickman_rho` can't handle anything other than float.

The code I used will go into `tests/symbolic-functions.py`.

### comment:14 Changed 3 years ago by rws

• Branch changed from u/rws/bugs_with_inverse_trig_and_hyperbolic_functions_of_cif_argument to u/rws/24299

### comment:15 Changed 3 years ago by rws

• Dependencies changed from #24318, #24329 to #24318, #24329, #24604
• Summary changed from Doctest: inverse trig and hyperbolic functions of CIF argument to Systematic doctest for function return type

New commits:

 ​0b52ecd `24299: Systematic doctest for function return type`

### comment:16 in reply to: ↑ 11 Changed 3 years ago by rws

```sage: acoth(CIF(0.6))
0.693147180559945?
```

This one is now fixed in Pynac-0.7.16.

### comment:17 Changed 3 years ago by rws

Now with Pynac-0.7.16 still failing.

### comment:18 Changed 3 years ago by rws

Update: the correct `arccoth(RR(0.7))-->CC`, `elliptic_eu(7,CC(1.7))`, `jacobi_am(7,CC(1.7))` are flagged wrong. Still failing: `dickman_rho(all types)`.

Note: See TracTickets for help on using tickets.