Opened 10 years ago

Closed 13 months ago

#5574 closed defect (fixed)

Implement QQbar^QQ as action

Reported by: burcin Owned by:
Priority: major Milestone: sage-8.2
Component: algebra Keywords:
Cc: vdelecroix Merged in:
Authors: Jeroen Demeyer Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: f65afd0 (Commits) Commit: f65afd020ae53bccda63e19e76939dd844e161b4
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

This ticket implements powering in QQbar and AA by QQ exponents as an action.

This will fix the following two bugs:

Reported by Alex Raichev on sage-support:

sage: n = SR.var('n'); QQbar(2)^n
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-01e1c4db05c9> in <module>()
----> 1 n = SR.var('n'); QQbar(Integer(2))**n

/usr/local/src/sage-config/local/lib/python2.7/site-packages/sage/rings/qqbar.pyc in __pow__(self, e)
   4106         if self == self.parent().one():
   4107             return self.parent().one()
-> 4108         e = QQ._coerce_(e)
   4109         n = e.numerator()
   4110         d = e.denominator()

/usr/local/src/sage-config/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent._coerce_ (build/cythonized/sage/structure/parent_old.c:5673)()
    227     def _coerce_(self, x):            # Call this from Python (do not override!)
    228         if self._element_constructor is not None:
--> 229             return self.coerce(x)
    230         check_old_coerce(self)
    231         return self._coerce_c(x)

/usr/local/src/sage-config/src/sage/structure/parent.pyx in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:10829)()
   1157                 except Exception:
   1158                     _record_exception()
-> 1159             raise TypeError("no canonical coercion from %s to %s" % (parent(x), self))
   1160         else:
   1161             return (<map.Map>mor)._call_(x)

TypeError: no canonical coercion from Symbolic Ring to Rational Field
sage: QQbar(2)^1.0
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-aba7adf5dc93> in <module>()
----> 1 QQbar(Integer(2))**RealNumber('1.0')

/usr/local/src/sage-config/local/lib/python2.7/site-packages/sage/rings/qqbar.pyc in __pow__(self, e)
   4106         if self == self.parent().one():
   4107             return self.parent().one()
-> 4108         e = QQ._coerce_(e)
   4109         n = e.numerator()
   4110         d = e.denominator()

/usr/local/src/sage-config/src/sage/structure/parent_old.pyx in sage.structure.parent_old.Parent._coerce_ (build/cythonized/sage/structure/parent_old.c:5673)()
    227     def _coerce_(self, x):            # Call this from Python (do not override!)
    228         if self._element_constructor is not None:
--> 229             return self.coerce(x)
    230         check_old_coerce(self)
    231         return self._coerce_c(x)

/usr/local/src/sage-config/src/sage/structure/parent.pyx in sage.structure.parent.Parent.coerce (build/cythonized/sage/structure/parent.c:10829)()
   1157                 except Exception:
   1158                     _record_exception()
-> 1159             raise TypeError("no canonical coercion from %s to %s" % (parent(x), self))
   1160         else:
   1161             return (<map.Map>mor)._call_(x)

TypeError: no canonical coercion from Real Field with 53 bits of precision to Rational Field

Change History (37)

comment:1 Changed 10 years ago by burcin

From sage-support @freenode today:

<base3___> raising a matrix to a variable power fails with 
NotImplementedError: non-integral exponents not supported,
even if i do assume(n, 'integer')
<base3___> am i missing something or should i file this as a bug?
<burcin> base3___, it's a bug

comment:2 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:3 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:4 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:5 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:6 Changed 3 years ago by rws

  • Component changed from symbolics to algebra
  • Description modified (diff)
  • Milestone changed from sage-6.4 to sage-6.10
  • Report Upstream set to N/A
  • Summary changed from taking symbolic powers should coerce objects to symbolic expressions to AlgebraicNumber.__pow__() does only rational exponents

This is a general shortcoming of AlgebraicNumber.__pow__():

sage: (QQbar(2)^3)^1.
...
TypeError: no canonical coercion from Real Field with 53 bits of precision to Rational Field

comment:7 Changed 14 months ago by jdemeyer

  • Dependencies set to #24247
  • Description modified (diff)

comment:8 Changed 14 months ago by jdemeyer

  • Summary changed from AlgebraicNumber.__pow__() does only rational exponents to Fix AlgebraicNumber.__pow__

comment:9 Changed 14 months ago by jdemeyer

  • Cc vdelecroix added
  • Description modified (diff)
  • Milestone changed from sage-6.10 to sage-8.2
  • Summary changed from Fix AlgebraicNumber.__pow__ to Implement QQbar^QQ as action

comment:10 follow-up: Changed 14 months ago by vdelecroix

Note that this is not a group action (because of the choice of an n-th root)

((-1)^(1/3))^2 != ((-1)^2)^(1/3).

Isn't that a requirement that g.(h.x) = (gh).x for an action in Sage?

comment:11 Changed 14 months ago by jdemeyer

  • Dependencies changed from #24247 to #24247, #24490

comment:12 in reply to: ↑ 10 Changed 14 months ago by jdemeyer

Replying to vdelecroix:

Note that this is not a group action (because of the choice of an n-th root)

((-1)^(1/3))^2 != ((-1)^2)^(1/3).

So what? I don't plan to change any arithmetic, just the underlying implementation. Since we have an operation between 2 different parents (QQbar and QQ), an action is the right way to implement this.

Isn't that a requirement that g.(h.x) = (gh).x for an action in Sage?

Why should there be such a requirement? I see an action purely as a technical way to implement a certain operation.

comment:13 Changed 14 months ago by jdemeyer

  • Branch set to u/jdemeyer/implement_qqbar_qq_as_action

comment:14 Changed 14 months ago by git

  • Commit set to 6b880d2471a484fd61379b74d000a9777e54ee50

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

bd408abDo not allow QQbar(1) ^ anything
1d0c236Merge commit 'bd408ab8657c08cba5c5a1d74800aa65a3b65c13' into t/5574/implement_qqbar_qq_as_action
6b880d2Implement QQbar^QQ as action

comment:15 Changed 14 months ago by jdemeyer

  • Authors set to Jeroen Demeyer
  • Status changed from new to needs_review

comment:16 Changed 14 months ago by jdemeyer

  • Description modified (diff)
  • Status changed from needs_review to needs_work
  • Summary changed from Implement QQbar^QQ as action to Fix powering in AA and QQbar

comment:17 Changed 14 months ago by jdemeyer

  • Description modified (diff)

comment:18 Changed 14 months ago by jdemeyer

  • Description modified (diff)
  • Summary changed from Fix powering in AA and QQbar to Implement QQbar^QQ as action

comment:19 Changed 14 months ago by git

  • Commit changed from 6b880d2471a484fd61379b74d000a9777e54ee50 to 2591b72f4d1c350253cebae4cfde02892b68232b

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

2591b72Implement QQbar^QQ as action

comment:20 Changed 14 months ago by jdemeyer

  • Dependencies changed from #24247, #24490 to #24247
  • Status changed from needs_work to needs_review

comment:21 Changed 13 months ago by jdemeyer

  • Dependencies #24247 deleted

comment:22 Changed 13 months ago by git

  • Commit changed from 2591b72f4d1c350253cebae4cfde02892b68232b to 5bfd1698795bc83fe838d36039a13c253f99e5ef

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

5bfd169Implement QQbar^QQ as action

comment:23 Changed 13 months ago by jdemeyer

Rebased to 8.2.beta3

comment:24 Changed 13 months ago by jdemeyer

This is a dependency for both #24256 and #24500, so it would be good to get this ticket done.

comment:25 follow-up: Changed 13 months ago by vdelecroix

Is that complient with Sage documentation?

EXAMPLES in ``QQbar``::
...
EXAMPLES in ``AA``::
...

Why not

EXAMPLES:

powering in ``QQbar``::
...
powering in ``AA``::
...

comment:26 Changed 13 months ago by vdelecroix

Timings look like it will be a bit slower. Before

sage: a = AA(5)
sage: %timeit a^(1/3)
1000 loops, best of 3: 327 µs per loop
sage: a = AA(8)
sage: %timeit a^(1/3)
100000 loops, best of 3: 7.78 µs per loop

After

sage: a = AA(5)
sage: %timeit a^(1/3)
1000 loops, best of 3: 369 µs per loop
sage: a = AA(8)
sage: %timeit a^(1/3)
100000 loops, best of 3: 9.64 µs per loop

comment:27 Changed 13 months ago by jdemeyer

Timings should improve in #24500 but I obviously cannot promise that it will be as fast as before.

comment:28 in reply to: ↑ 25 ; follow-up: Changed 13 months ago by jdemeyer

Replying to vdelecroix:

Is that complient with Sage documentation?

EXAMPLES in ``QQbar``::
...
EXAMPLES in ``AA``::
...

There are some cases like that already in Sage. I don't see the problem, but if you insist, then I will change it.

comment:29 in reply to: ↑ 28 Changed 13 months ago by vdelecroix

Replying to jdemeyer:

Replying to vdelecroix:

Is that complient with Sage documentation?

EXAMPLES in ``QQbar``::
...
EXAMPLES in ``AA``::
...

There are some cases like that already in Sage. I don't see the problem, but if you insist, then I will change it.

My reference is http://doc.sagemath.org/html/en/developer/coding_basics.html#documentation-strings (and not the rest of Sage).

comment:30 Changed 13 months ago by jdemeyer

I don't see anything in the docs saying that an EXAMPLES block should start exactly with the line EXAMPLES::

comment:31 follow-up: Changed 13 months ago by jdemeyer

This is different from Sphinx blocks like .. WARNING:: because those are handled specially. But there is nothing special about EXAMPLES.

comment:32 in reply to: ↑ 31 ; follow-up: Changed 13 months ago by vdelecroix

Replying to jdemeyer:

This is different from Sphinx blocks like .. WARNING:: because those are handled specially. But there is nothing special about EXAMPLES.

TESTS is also handled specially (hided in the doc). And EXAMPLES might in the future (e.g. interactive execution in Jupyter).

comment:33 in reply to: ↑ 32 ; follow-up: Changed 13 months ago by jdemeyer

Replying to vdelecroix:

And EXAMPLES might in the future (e.g. interactive execution in Jupyter).

That would be a bad idea. Executable commands should be limited to the EXAMPLES block.

And if some software really wants to treat EXAMPLES blocks specially, it should still recognize EXAMPLES in ``QQbar`` as EXAMPLES block.

Anyway, if you really want me to change it, just say so.

comment:34 in reply to: ↑ 33 Changed 13 months ago by vdelecroix

Replying to jdemeyer:

Replying to vdelecroix:

And EXAMPLES might in the future (e.g. interactive execution in Jupyter).

That would be a bad idea. Executable commands should be limited to the EXAMPLES block.

And if some software really wants to treat EXAMPLES blocks specially, it should still recognize EXAMPLES in ``QQbar`` as EXAMPLES block.

Anyway, if you really want me to change it, just say so.

Please do.

comment:35 Changed 13 months ago by git

  • Commit changed from 5bfd1698795bc83fe838d36039a13c253f99e5ef to f65afd020ae53bccda63e19e76939dd844e161b4

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

f65afd0Change docstring formatting

comment:36 Changed 13 months ago by vdelecroix

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

comment:37 Changed 13 months ago by vbraun

  • Branch changed from u/jdemeyer/implement_qqbar_qq_as_action to f65afd020ae53bccda63e19e76939dd844e161b4
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.