Opened 4 years ago

Closed 4 years ago

# Doctest: Add more logic flags to more functions

Reported by: Owned by: rws major sage-8.1 symbolics vdelecroix Ralf Stephan Vincent Delecroix N/A 350580a 350580aa70a39f1227df71b00d976a2ebfdd6dff #22219

### Description

Some functions are handled with some flags in https://github.com/pynac/pynac/blob/master/ginac/function.cpp#L1581

This should be extended (in Pynac) and doctests added (here). This ticket should list which questions can be answered definitely to the positive. To start:

• f(real).is_real() for f in sin/cos/tan/cot/sec/csc

### comment:2 Changed 4 years ago by vdelecroix

The gamma function

```sage: gamma(pi).is_real()
False
```

You might also want to deal with `is_positive` which would be easily handled for analytic functions whose power series have non-negative coefficients.

Are there flags in ginac for properties like: "power series with non-negative coefficients", "power series with integer coefficients", etc?

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

Hyperbolic trigonometric functions `cosh/sinh/tanh` and inverses `arccosh/arcsinh/arctanh`

```sage: cosh(-3).is_real()
False
sage: cosh(-3).is_positive()
False
```

### comment:4 Changed 4 years ago by vdelecroix

But instead of hardcoding all these informations in functions, it would be better to actually deduce it from some other properties (like Taylor series as I suggested before).

### comment:5 follow-up: ↓ 6 Changed 4 years ago by vdelecroix

Will this approach be recursive, namely `cos(exp(-3) + log(2)).is_real()`?

### comment:6 in reply to: ↑ 5 Changed 4 years ago by rws

it would be better to actually deduce it from some other properties (like Taylor series as I suggested before).

Not possible. Taylor series are determined in general by differentiation. There is no builtin formula which we can inspect.

Will this approach be recursive, namely `cos(exp(-3) + log(2)).is_real()`?

Yes.

### comment:7 follow-up: ↓ 8 Changed 4 years ago by dimpase

as discussed on sage-develop, the best way IMHO would be to be able to return "Unknown" instead of false "False"...

### comment:8 in reply to: ↑ 7 Changed 4 years ago by rws

as discussed on sage-develop, the best way IMHO would be to be able to return "Unknown" instead of false "False"...

See #22162.

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

• Dependencies set to pynac-0.7.4

### comment:11 follow-up: ↓ 13 Changed 4 years ago by vdelecroix

• Commit set to 4a7499bc3f8ef392d47f26fa8d2636856ce01a51

Nice! Could you add doctest to check

1) compatibility with assumptions

```sage: x = SR.var('x')
sage: assume(x, 'real')
sage: cos(x).is_real()
```

2) complex stuff is actually `False`

```cos(I).is_real()
sin(2 - I).is_real()
etc
```

3) What is the current status of?

```sage: x = SR.var('x')
sage: assume(x, 'real')
sage: (cos(x) + 1).is_positive()
```

New commits:

 ​4a7499b `22155: doctest the improved domain logic`

### comment:12 Changed 4 years ago by git

• Commit changed from 4a7499bc3f8ef392d47f26fa8d2636856ce01a51 to 6e1c056b5e39f6dece3f9c94a620c7fc2564e99f

Branch pushed to git repo; I updated commit sha1. New commits:

 ​6e1c056 `22155: address reviewer's comments`

### comment:13 in reply to: ↑ 11 Changed 4 years ago by rws

3) What is the current status of?

```sage: x = SR.var('x')
sage: assume(x, 'real')
sage: (cos(x) + 1).is_positive()
```

Not possible using current machinery. Note the information kept is boolean (or maybe tri-state in the future) for speed reasons, as it is routinely used with manipulation of expressions. Any slowdown like numeric computations that are potentially calling Python/Cython code from C++ should be avoided.

### comment:14 Changed 4 years ago by vdelecroix

What does mean "dependencies pynac-0.7.4"?

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

There is no ticket atm for the 0.7.4 upgrade. When there is I'll replace that with the ticket number.

### comment:16 Changed 4 years ago by git

• Commit changed from 6e1c056b5e39f6dece3f9c94a620c7fc2564e99f to fc0c64d7e7034121a3df09783c2773e5ea01033b

Branch pushed to git repo; I updated commit sha1. New commits:

 ​fc0c64d `Merge branch 'develop' into t/22155/add_more_logic_flags_to_more_functions`

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

• Authors set to Ralf Stephan
• Dependencies changed from pynac-0.7.4 to #22219
• Milestone changed from sage-7.6 to sage-8.1
• Status changed from new to needs_review
• Summary changed from Add more logic flags to more functions to Doctest: Add more logic flags to more functions

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

• Status changed from needs_review to needs_work

Two failing doctests.

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

Actually the doctests were wrong: `real``positive` is not real but `positve``positive` is. Also `(cos(exp(real) + log(pos))^pos^)` is not real if the log argument is less than one. I replace the second pos with `8`. Sage teaches me math!

### comment:20 Changed 4 years ago by git

• Commit changed from fc0c64d7e7034121a3df09783c2773e5ea01033b to 350580aa70a39f1227df71b00d976a2ebfdd6dff

Branch pushed to git repo; I updated commit sha1. New commits:

 ​39f0336 `Merge branch 'develop' into t/22155/add_more_logic_flags_to_more_functions` ​350580a `22155: fixes`

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

• Status changed from needs_work to needs_review

### comment:22 Changed 4 years ago by vdelecroix

• Reviewers set to Vincent Delecroix
• Status changed from needs_review to positive_review

### comment:23 Changed 4 years ago by vbraun

• Branch changed from u/rws/add_more_logic_flags_to_more_functions to 350580aa70a39f1227df71b00d976a2ebfdd6dff
• Resolution set to fixed
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.