Opened 12 years ago
Closed 3 years ago
#5574 closed defect (fixed)
Implement QQbar^QQ as action
Reported by:  burcin  Owned by:  

Priority:  major  Milestone:  sage8.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 )
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 sagesupport:
sage: n = SR.var('n'); QQbar(2)^n  TypeError Traceback (most recent call last) <ipythoninput601e1c4db05c9> in <module>() > 1 n = SR.var('n'); QQbar(Integer(2))**n /usr/local/src/sageconfig/local/lib/python2.7/sitepackages/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/sageconfig/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/sageconfig/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) <ipythoninput7aba7adf5dc93> in <module>() > 1 QQbar(Integer(2))**RealNumber('1.0') /usr/local/src/sageconfig/local/lib/python2.7/sitepackages/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/sageconfig/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/sageconfig/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 12 years ago by
comment:2 Changed 7 years ago by
 Milestone changed from sage5.11 to sage5.12
comment:3 Changed 7 years ago by
 Milestone changed from sage6.1 to sage6.2
comment:4 Changed 7 years ago by
 Milestone changed from sage6.2 to sage6.3
comment:5 Changed 6 years ago by
 Milestone changed from sage6.3 to sage6.4
comment:6 Changed 5 years ago by
 Component changed from symbolics to algebra
 Description modified (diff)
 Milestone changed from sage6.4 to sage6.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 3 years ago by
 Dependencies set to #24247
 Description modified (diff)
comment:8 Changed 3 years ago by
 Summary changed from AlgebraicNumber.__pow__() does only rational exponents to Fix AlgebraicNumber.__pow__
comment:9 Changed 3 years ago by
 Cc vdelecroix added
 Description modified (diff)
 Milestone changed from sage6.10 to sage8.2
 Summary changed from Fix AlgebraicNumber.__pow__ to Implement QQbar^QQ as action
comment:10 followup: ↓ 12 Changed 3 years ago by
Note that this is not a group action (because of the choice of an nth 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 3 years ago by
 Dependencies changed from #24247 to #24247, #24490
comment:12 in reply to: ↑ 10 Changed 3 years ago by
Replying to vdelecroix:
Note that this is not a group action (because of the choice of an nth 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 3 years ago by
 Branch set to u/jdemeyer/implement_qqbar_qq_as_action
comment:14 Changed 3 years ago by
 Commit set to 6b880d2471a484fd61379b74d000a9777e54ee50
comment:15 Changed 3 years ago by
 Status changed from new to needs_review
comment:16 Changed 3 years ago by
 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 3 years ago by
 Description modified (diff)
comment:18 Changed 3 years ago by
 Description modified (diff)
 Summary changed from Fix powering in AA and QQbar to Implement QQbar^QQ as action
comment:19 Changed 3 years ago by
 Commit changed from 6b880d2471a484fd61379b74d000a9777e54ee50 to 2591b72f4d1c350253cebae4cfde02892b68232b
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
2591b72  Implement QQbar^QQ as action

comment:20 Changed 3 years ago by
 Dependencies changed from #24247, #24490 to #24247
 Status changed from needs_work to needs_review
comment:21 Changed 3 years ago by
 Dependencies #24247 deleted
comment:22 Changed 3 years ago by
 Commit changed from 2591b72f4d1c350253cebae4cfde02892b68232b to 5bfd1698795bc83fe838d36039a13c253f99e5ef
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
5bfd169  Implement QQbar^QQ as action

comment:23 Changed 3 years ago by
Rebased to 8.2.beta3
comment:24 Changed 3 years ago by
comment:25 followup: ↓ 28 Changed 3 years ago by
Is that complient with Sage documentation?
EXAMPLES in ``QQbar``:: ... EXAMPLES in ``AA``:: ...
Why not
EXAMPLES: powering in ``QQbar``:: ... powering in ``AA``:: ...
comment:26 Changed 3 years ago by
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 3 years ago by
Timings should improve in #24500 but I obviously cannot promise that it will be as fast as before.
comment:28 in reply to: ↑ 25 ; followup: ↓ 29 Changed 3 years ago by
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 3 years ago by
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#documentationstrings (and not the rest of Sage).
comment:30 Changed 3 years ago by
I don't see anything in the docs saying that an EXAMPLES
block should start exactly with the line EXAMPLES::
comment:31 followup: ↓ 32 Changed 3 years ago by
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 ; followup: ↓ 33 Changed 3 years ago by
Replying to jdemeyer:
This is different from Sphinx blocks like
.. WARNING::
because those are handled specially. But there is nothing special aboutEXAMPLES
.
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 ; followup: ↓ 34 Changed 3 years ago by
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 3 years ago by
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 recognizeEXAMPLES in ``QQbar``
asEXAMPLES
block.Anyway, if you really want me to change it, just say so.
Please do.
comment:35 Changed 3 years ago by
 Commit changed from 5bfd1698795bc83fe838d36039a13c253f99e5ef to f65afd020ae53bccda63e19e76939dd844e161b4
Branch pushed to git repo; I updated commit sha1. New commits:
f65afd0  Change docstring formatting

comment:36 Changed 3 years ago by
 Reviewers set to Vincent Delecroix
 Status changed from needs_review to positive_review
comment:37 Changed 3 years ago by
 Branch changed from u/jdemeyer/implement_qqbar_qq_as_action to f65afd020ae53bccda63e19e76939dd844e161b4
 Resolution set to fixed
 Status changed from positive_review to closed
From sagesupport @freenode today: