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

Bug in power series sqrt #3354

Open
robertwb opened this issue Jun 3, 2008 · 7 comments
Open

Bug in power series sqrt #3354

robertwb opened this issue Jun 3, 2008 · 7 comments

Comments

@robertwb
Copy link
Contributor

robertwb commented Jun 3, 2008

sage: t = QQ[['t']].0
sage: sqrt(1+t)
1 + 1/2*t - 1/8*t^2 + 1/16*t^3 - 5/128*t^4 + 7/256*t^5 - 21/1024*t^6 + 33/2048*t^7 - 429/32768*t^8 + 715/65536*t^9 - 2431/262144*t^10 + 4199/524288*t^11 - 29393/4194304*t^12 + 52003/8388608*t^13 - 185725/33554432*t^14 + 334305/67108864*t^15 - 9694845/2147483648*t^16 + 17678835/4294967296*t^17 - 64822395/17179869184*t^18 + 119409675/34359738368*t^19 + O(t^20)
sage: sqrt(2+t)
------------------------------------------------------------
Traceback (most recent call last):

Now this error is expected because sqrt() has an extend keyword that allows to extend the base ring, and to give the name of the generator of the quadratic field, but this does not work:

sage: K.<t> = PowerSeriesRing(QQ, 5)
sage: (t+2).sqrt(extend=True, name='sqrt2')
sqrt2

The expected output would be sqrt2 + sqrt2*x/4 + sqrt2*x^2/32 +...

However, more convenient would be to make the default of extend to be True and for square roots of integers N the name sqrtN provided. Only raise an error for nonintegers if no name is given.

Component: commutative algebra

Keywords: power series

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

@robertwb robertwb added this to the sage-5.11 milestone Jun 3, 2008
@jasongrout
Copy link
Member

comment:1

Related:

[00:12] <jason--> sage: t = QQ[['t']].0
[00:12] <jason--> sage: 1/(1-t)
[00:12] <jason--> 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + t^10 + t^11 + t^12 + t^13 + t^14 + t^15 + t^16 + t^17 + t^18 + t^19 + O(t^20)
[00:12] <jason--> but log(1+t) doesn't work, for example
[00:12] <jason--> should it?
[00:12] <craigcitro> in principle, yes. :)
[00:13] <craigcitro> see if (1+t) has a log method ...
[00:13] <jason--> and sin(t), cos(t), etc.
[00:13] <jason--> so maybe a fallback method that calls for a taylor series?

@fchapoton
Copy link
Contributor

Changed keywords from none to power series

@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
@mezzarobba
Copy link
Member

comment:7

Message fixed in #6998.

@mezzarobba mezzarobba removed this from the sage-6.4 milestone Apr 13, 2015
@videlec
Copy link
Contributor

videlec commented Apr 24, 2015

comment:8

In the description there is

Perhaps the error is just bad, but it should be able
to compute this by extending to a field with sqrt(2).

Note that the following works, but it is not very direct

sage: (2+t).change_ring(QuadraticField(2)).sqrt()
a + 1/4*a*t - 1/32*a*t^2 + 1/128*a*t^3 - ... + O(t^20)

@rwst
Copy link

rwst commented Dec 25, 2015

comment:10

In the meantime the error changed to:

/home/ralf/sage/src/sage/rings/power_series_ring_element.pyx in sage.rings.power_series_ring_element.PowerSeries.sqrt (build/cythonized/sage/rings/power_series_ring_element.c:13321)()
   1295                     return a
   1296             elif formal_sqrt:
-> 1297                 raise ValueError, "unable to take the square root of %s"%u[0]
   1298             else:
   1299                 raise ValueError, "power series does not have a square root since it has odd valuation."

ValueError: unable to take the square root of 3

There are also these keywords to consider. However extend=True returns not a square root of the series but the square root of the extension ring, and I am not sure what use it is, I think it's simply a bug:

          - ``extend`` - bool (default: False); if True, return a square
            root in an extension ring, if necessary. Otherwise, raise
            a ValueError if the square root is not in the base power series
            ring. For example, if ``extend`` is True the square root of a
            power series with odd degree leading coefficient is
            defined as an element of a formal extension ring.

          - ``name`` - string; if ``extend`` is True, you must also specify the     print
            name of the formal square root.

sage: K.<t> = PowerSeriesRing(QQ, 5)
sage: two = K(2)
sage: sqrt2 = two.sqrt(extend=True, name='sqrt2')       
sage: (t+sqrt2^2).sqrt()
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-9-0401d4729a88> in <module>()
----> 1 (t+sqrt2**Integer(2)).sqrt()

/home/ralf/sage/src/sage/structure/element.pyx in sage.structure.element.CommutativeRingElement.sqrt (build/cythonized/sage/structure/element.c:19922)()
   2424         from sage.rings.integral_domain import is_IntegralDomain
   2425         P=self._parent
-> 2426         is_sqr, sq_rt = self.is_square( root = True )
   2427         if is_sqr:
   2428             if all:

/home/ralf/sage/src/sage/structure/element.pyx in sage.structure.element.CommutativeRingElement.is_square (build/cythonized/sage/structure/element.c:19744)()
   2328             framework.
   2329         """
-> 2330         raise NotImplementedError("is_square() not implemented for elements of %s" % self.parent())
   2331
   2332     def sqrt(self, extend=True, all=False, name=None):

NotImplementedError: is_square() not implemented for elements of Univariate Quotient Polynomial Ring in sqrt2 over Power Series Ring in t over Rational Field with modulus x^2 - 2

So effectively the original issue (giving a correct result for (2+t).sqrt() regardless of whether automagically or by giving the extend keyword) is not fixed.

@rwst rwst added this to the sage-7.0 milestone Dec 25, 2015
@rwst
Copy link

rwst commented Dec 25, 2015

comment:11

I also think the default of extend should be true and for square roots of integers N the name sqrtN provided. Only raise an error for nonintegers if no name is given.

EDIT: typos

@rwst

This comment has been minimized.

@mkoeppe mkoeppe removed this from the sage-7.0 milestone Dec 29, 2022
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

8 participants