Opened 2 years ago

Closed 2 years ago

#21940 closed defect (fixed)

Doctest for: Positive raised by a positive power is not known to be real

Reported by: pelegm Owned by:
Priority: major Milestone: sage-7.5
Component: symbolics Keywords: is_real, days79
Cc: rws Merged in:
Authors: Peleg Michaeli, Ralf Stephan Reviewers: Ralf Stephan, Peleg Michaeli
Report Upstream: N/A Work issues:
Branch: c883299 (Commits) Commit: c88329909934b9561314344347a7bd7c3c0ec755
Dependencies: #21963 Stopgaps:

Description (last modified by pelegm)

But it is known to be positive...

See the following code:

sage: assume(x>0)
sage: x.is_real()
True
sage: x.is_positive()
True
sage: (x**x).is_positive()
True
sage: (x**x).is_real()
False

For comparison, this is how SymPy handles this:

In [2]: x = Symbol('x', positive=True)

In [3]: x.is_positive
Out[3]: True

In [4]: x.is_real
Out[4]: True

In [5]: (x**x).is_positive
Out[5]: True

In [6]: (x**x).is_real
Out[6]: True

Change History (14)

comment:1 Changed 2 years ago by pelegm

  • Cc rsw added

comment:2 Changed 2 years ago by pelegm

  • Cc rws added; rsw removed

comment:3 follow-up: Changed 2 years ago by rws

What Sage version is this? With Sage-7.5beta3 I get:

sage: assume(x>0)
sage: x.is_real()
True
sage: (x*x).is_real()
True

comment:4 in reply to: ↑ 3 Changed 2 years ago by pelegm

Replying to rws:

What Sage version is this? With Sage-7.5beta3 I get:

sage: assume(x>0)
sage: x.is_real()
True
sage: (x*x).is_real()
True

Hi,

This was tested on 7.5beta3. You've checked x*x, and I have checked x**x.

comment:5 Changed 2 years ago by rws

  • Dependencies set to pynac-0.7.2

Fixed in pynac git master, see https://github.com/pynac/pynac/commit/e5c6cd261e2652b7c4e7b4ca5f1bac9565ab0ef8

Please add a doctest to Expression.is_real() in symbolic/expression.pyx

comment:6 Changed 2 years ago by pelegm

  • Authors set to Peleg Michaeli
  • Branch set to u/pelegm/21940
  • Commit set to 65e6c10c2da5e4d20bbc6f7f225ade3f4778fc0c
  • Status changed from new to needs_review

New commits:

65e6c10positive ** positive = real (doctest only) #21940

comment:7 Changed 2 years ago by rws

Maybe interesting in this regard that fixing this allows Sage to simplify some apparently complex expressions, e.g.

Before:
sqrt(abs(1/25*(3*(2*sqrt(3)*sqrt(2) - 3)*(sqrt(6) - 2) + 16*sqrt(3)*sqrt(2) +
5*sqrt(6) - 54)^2 + 1/25*(3*(sqrt(6) - 2)*(sqrt(6) - 4) + 14*sqrt(3)*sqrt(2) +
4*sqrt(6) - 42)^2 + 144/25*(sqrt(3)*sqrt(2) - sqrt(6))^2))

After:
sqrt(1/25*(3*(2*sqrt(3)*sqrt(2) - 3)*(sqrt(6) - 2) + 16*sqrt(3)*sqrt(2) +
5*sqrt(6) - 54)^2 + 1/25*(3*(sqrt(6) - 2)*(sqrt(6) - 4) + 14*sqrt(3)*sqrt(2) +
4*sqrt(6) - 42)^2 + 144/25*(sqrt(3)*sqrt(2) - sqrt(6))^2)

(from a doctest in matrix_symbolic_dense.pyx)

comment:8 Changed 2 years ago by pelegm

  • Description modified (diff)

comment:9 follow-up: Changed 2 years ago by pelegm

Is this solving the case

sage: assume(x, 'real')
sage: (2**x).is_positive()
True
sage: (2**x).is_real()
False

as well?

comment:10 Changed 2 years ago by rws

  • Dependencies changed from pynac-0.7.2 to #21963

Right, now that works too.

comment:11 Changed 2 years ago by rws

  • Branch changed from u/pelegm/21940 to u/rws/21940

comment:12 in reply to: ↑ 9 Changed 2 years ago by rws

  • Authors changed from Peleg Michaeli to Peleg Michaeli, Ralf Stephan
  • Commit changed from 65e6c10c2da5e4d20bbc6f7f225ade3f4778fc0c to c88329909934b9561314344347a7bd7c3c0ec755
  • Reviewers set to Ralf Stephan
  • Summary changed from Positive raised by a positive power is not known to be real to Doctest for: Positive raised by a positive power is not known to be real

Replying to pelegm:

Is this solving the case

sage: assume(x, 'real')
sage: (2**x).is_positive()
True
sage: (2**x).is_real()
False

as well?

I added this as doctest. Could you review it please?


New commits:

23c987eMerge branch 'develop' into t/21940/21940
c88329921940: add one doctest

comment:13 Changed 2 years ago by pelegm

  • Reviewers changed from Ralf Stephan to Ralf Stephan, Peleg Michaeli
  • Status changed from needs_review to positive_review

Looks great.

comment:14 Changed 2 years ago by vbraun

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