Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement QQbar^QQ as action #5574

Closed
burcin opened this issue Mar 20, 2009 · 38 comments
Closed

Implement QQbar^QQ as action #5574

burcin opened this issue Mar 20, 2009 · 38 comments

Comments

@burcin
Copy link

burcin commented Mar 20, 2009

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

CC: @videlec

Component: algebra

Author: Jeroen Demeyer

Branch/Commit: f65afd0

Reviewer: Vincent Delecroix

Issue created by migration from https://trac.sagemath.org/ticket/5574

@burcin burcin added this to the sage-5.11 milestone Mar 20, 2009
@burcin
Copy link
Author

burcin commented Apr 9, 2009

comment:1

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

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.3, sage-6.4 Aug 10, 2014
@rwst

This comment has been minimized.

@rwst
Copy link

rwst commented Oct 19, 2015

comment:6

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

@rwst rwst modified the milestones: sage-6.4, sage-6.10 Oct 19, 2015
@rwst rwst changed the title taking symbolic powers should coerce objects to symbolic expressions AlgebraicNumber.__pow__() does only rational exponents Oct 19, 2015
@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

jdemeyer commented Jan 8, 2018

Dependencies: #24247

@jdemeyer jdemeyer changed the title AlgebraicNumber.__pow__() does only rational exponents Fix AlgebraicNumber.__pow__ Jan 8, 2018
@jdemeyer

This comment has been minimized.

@jdemeyer jdemeyer changed the title Fix AlgebraicNumber.__pow__ Implement QQbar^QQ as action Jan 8, 2018
@jdemeyer jdemeyer modified the milestones: sage-6.10, sage-8.2 Jan 8, 2018
@videlec
Copy link
Contributor

videlec commented Jan 8, 2018

comment:10

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?

@jdemeyer
Copy link

jdemeyer commented Jan 8, 2018

Changed dependencies from #24247 to #24247, #24490

@jdemeyer
Copy link

jdemeyer commented Jan 8, 2018

comment:12

Replying to @videlec:

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 9, 2018

Changed commit from 6b880d2 to 2591b72

@jdemeyer
Copy link

jdemeyer commented Jan 9, 2018

Changed dependencies from #24247, #24490 to #24247

@jdemeyer
Copy link

Changed dependencies from #24247 to none

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2018

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

5bfd169Implement QQbar^QQ as action

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 18, 2018

Changed commit from 2591b72 to 5bfd169

@jdemeyer
Copy link

comment:23

Rebased to 8.2.beta3

@jdemeyer
Copy link

comment:24

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

@videlec
Copy link
Contributor

videlec commented Jan 25, 2018

comment:25

Is that complient with Sage documentation?

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

Why not

EXAMPLES:

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

@videlec
Copy link
Contributor

videlec commented Jan 25, 2018

comment:26

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

@jdemeyer
Copy link

comment:27

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

@jdemeyer
Copy link

comment:28

Replying to @videlec:

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.

@videlec
Copy link
Contributor

videlec commented Jan 25, 2018

comment:29

Replying to @jdemeyer:

Replying to @videlec:

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).

@jdemeyer
Copy link

comment:30

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

@jdemeyer
Copy link

comment:31

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

@videlec
Copy link
Contributor

videlec commented Jan 25, 2018

comment:32

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).

@jdemeyer
Copy link

comment:33

Replying to @videlec:

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.

@videlec
Copy link
Contributor

videlec commented Jan 26, 2018

comment:34

Replying to @jdemeyer:

Replying to @videlec:

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.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 29, 2018

Changed commit from 5bfd169 to f65afd0

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Jan 29, 2018

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

f65afd0Change docstring formatting

@videlec
Copy link
Contributor

videlec commented Jan 29, 2018

Reviewer: Vincent Delecroix

@vbraun
Copy link
Member

vbraun commented Feb 2, 2018

Changed branch from u/jdemeyer/implement_qqbar_qq_as_action to f65afd0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants