#20086: ZZ[X], QQ[X]: allow arbitrary powers of constant polynomials
-------------------------------------+-------------------------------------
       Reporter:  cheuberg           |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-7.1
      Component:  basic arithmetic   |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Clemens Heuberger  |    Reviewers:  Benjamin Hackl
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/cheuberg/polynomials/power       |  14f7efaaf5be81405d1954473b4dc3f47100e486
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by vdelecroix):

 Replying to [comment:17 cheuberg]:
 > Replying to [comment:16 vdelecroix]:
 > > Why doing something that complicated for dealing with strange
 exponents? Why not simply
 > > {{{
 > > if input is not an integer:
 > >   convert to an integer
 > > do the exponentiation
 > > }}}
 >
 > I do not understand this comment. Which input? Base or Exponent? Where
 should this code be?

 Let me be more precise then
 {{{
 def __pow__(self, exp):
     cdef long n
     try:
         n = exp
         # old code for integer exponent
     except TypeError:
         n = QQ.coerce(exp)
         # new code for rational exponent
 }}}
 What I do not understand is why are you testing if the exponent is a
 polynomial...

 The following is currently a `TypeError`
 {{{
 sage: 1^(ZZ['x'].one())
 Traceback (most recent call last):
 ...
 TypeError:
 
'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'
 object cannot be interpreted as an index
 }}}
 The same should happen when the integer `1` is replaced by the polynomial
 `1`.

 > > Why are you special casing degree 0 polynomial? If I understand
 correctly these examples won't behave similarly
 > > {{{
 > > sage: R.<x> = QQ[]
 > > sage: ((x+1)^2)^(1/2)
 > > -> TypeError
 > > sage: ((R(2))^2)^(1/2)
 > > -> 2
 > > }}}
 > > Which is weird.
 >
 > I need a quick fix for `R(1)^(1/2)`. If somebody has time to implement
 `((x+1)^2)^(1/2)` very soon, I'd be happy. I do not have time soon.
 However, I want to have the code associated with a recently submitted
 paper in 7.1.

 Are you sure there was a bug? In Sage the integer 1 is *not* the 1 from
 ZZ[x] (though they are equal through coercion). Some softwares behave
 differently to that respect (e.g. GAP) where there is only one 1 which is
 an integer and not anything else. In Sage (but not in GAP) it is already
 the case that operations change with respect to the parents even if the
 objects are equal
 {{{
 sage: Zmod(10)(3) == 3
 sage: Zmod(10)(5) == 5
 sage: log(Zmod(10)(3))
 3
 sage: log(Zmod(10)(5))
 Traceback (most recent call last):
 ...
 ZeroDivisionError: Inverse does not exist.
 }}}

 > Basically, this fix here simply branches to existing code.
 > Computing `((x+1)^2)^(1/2)` needs new mathematical code (involving
 square free decomposition).

 Indeed. Your modifications obfuscate the code for only a very trivial case
 and a discutable behavior of powering with polynomials.

 > Therefore, I propose to include this now on the basis that while this is
 not a perfect and definitive solution, it is better than the previous
 behaviour.

 Not sure it is better. Sage used to consider operations based on parents.
 Powers are of course a special type of operation and with some respect
 might be treated appart. But "(polynomial)^(polynomial)" is not well
 defined. And "(polynomial)^(rational)" is well defined in some situations
 (and to that respect, your code improves the current situation a little).

 Moreover, the current "power promotion" for ZZ is very bad
 {{{
 sage: 3^(1/2)
 sqrt(3)
 sage: parent(_)
 Symbolic Ring
 sage: 4^(1/2)
 2
 sage: parent(_)
 Rational Field
 }}}
 Making it available for constant polynomial is not that much of an
 improvement.

--
Ticket URL: <http://trac.sagemath.org/ticket/20086#comment:18>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to