Opened 2 years ago

Closed 18 months ago

#22155 closed enhancement (fixed)

Doctest: Add more logic flags to more functions

Reported by: rws Owned by:
Priority: major Milestone: sage-8.1
Component: symbolics Keywords:
Cc: vdelecroix Merged in:
Authors: Ralf Stephan Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: 350580a (Commits) Commit: 350580aa70a39f1227df71b00d976a2ebfdd6dff
Dependencies: #22219 Stopgaps:

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

Change History (23)

comment:1 Changed 2 years ago by rws

  • Cc vdelecroix added

comment:2 Changed 2 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 2 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 2 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: Changed 2 years ago by vdelecroix

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

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

Replying to vdelecroix:

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: Changed 2 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 2 years ago by rws

Replying to dimpase:

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

See #22162.

comment:10 Changed 2 years ago by rws

  • Branch set to u/rws/add_more_logic_flags_to_more_functions

comment:11 follow-up: Changed 2 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:

4a7499b22155: doctest the improved domain logic

comment:12 Changed 2 years ago by git

  • Commit changed from 4a7499bc3f8ef392d47f26fa8d2636856ce01a51 to 6e1c056b5e39f6dece3f9c94a620c7fc2564e99f

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

6e1c05622155: address reviewer's comments

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

Replying to vdelecroix:

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 2 years ago by vdelecroix

What does mean "dependencies pynac-0.7.4"?

comment:15 Changed 2 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 21 months ago by git

  • Commit changed from 6e1c056b5e39f6dece3f9c94a620c7fc2564e99f to fc0c64d7e7034121a3df09783c2773e5ea01033b

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

fc0c64dMerge branch 'develop' into t/22155/add_more_logic_flags_to_more_functions

comment:17 Changed 21 months 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 18 months ago by rws

  • Status changed from needs_review to needs_work

Two failing doctests.

comment:19 Changed 18 months ago by rws

Actually the doctests were wrong: realpositive is not real but positvepositive 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 18 months ago by git

  • Commit changed from fc0c64d7e7034121a3df09783c2773e5ea01033b to 350580aa70a39f1227df71b00d976a2ebfdd6dff

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

39f0336Merge branch 'develop' into t/22155/add_more_logic_flags_to_more_functions
350580a22155: fixes

comment:21 Changed 18 months ago by rws

  • Status changed from needs_work to needs_review

comment:22 Changed 18 months ago by vdelecroix

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

comment:23 Changed 18 months 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.