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

perfect_power for integers #12116

Closed
roed314 opened this issue Dec 4, 2011 · 46 comments
Closed

perfect_power for integers #12116

roed314 opened this issue Dec 4, 2011 · 46 comments

Comments

@roed314
Copy link
Contributor

roed314 commented Dec 4, 2011

Currently there are two functions for testing whether an integer is a perfect power:

sage: 8.is_power()
True
sage: 8.is_perfect_power()
True
  • This patch deprecates is_power.
  • It implements a new function, perfect_power, wrapping PARI's ispower function, expressing an integer in the form ab with b maximal.
  • It adds cross references between is_perfect_power, is_power_of, is_prime_power and perfect_power.

This revealed three bugs in PARI's ispower() function:

  1. Two issues reported and fixed at http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1259
  2. One more issue reported and fixed at http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1302 (duplicate: http://pari.math.u-bordeaux.fr/cgi-bin/bugreport.cgi?bug=1303)

Apply attachment: trac_12116-rebase4.patch

Depends on #10596
Depends on #12363
Depends on #12638

Upstream: Fixed upstream, but not in a stable release.

CC: @jpflori

Component: basic arithmetic

Author: David Roe

Reviewer: David Loeffler, Aly Deines, Simon Spicer

Merged: sage-5.8.beta3

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

@roed314 roed314 added this to the sage-5.8 milestone Dec 4, 2011
@roed314
Copy link
Contributor Author

roed314 commented Dec 4, 2011

comment:1

The bug is being tracked by Pari: their ticket number is 1259.

@roed314
Copy link
Contributor Author

roed314 commented Dec 4, 2011

Changed upstream from Not yet reported upstream; Will do shortly. to Reported upstream. Little or no feedback.

@roed314
Copy link
Contributor Author

roed314 commented Dec 5, 2011

comment:3

Here's the response from the Pari developers:

The 2 problems turned out to be independant. They are now fixed in the
'testing' branch, in the following 2 commits:

commit f53eb2a7c79922ac51423e75044722628893159e
Author: Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr>
Date:   Sun Dec 4 17:43:19 2011 +0100

   46- ispower(1 / n) return a wrong result [#1259]

commit 74aef498d380979211b99d64f4f4c92b8bac853f
Author: Karim Belabas <Karim.Belabas@math.u-bordeaux1.fr>
Date:   Sun Dec 4 17:28:14 2011 +0100

   45- ispower(x < 0) could return an even value ! [#1259]

That was quick. :-)

@roed314
Copy link
Contributor Author

roed314 commented Dec 5, 2011

Changed upstream from Reported upstream. Little or no feedback. to Fixed upstream, but not in a stable release.

@jasongrout
Copy link
Member

comment:4

I'm curious why you didn't use the Sphinx seealso directive: http://sphinx.pocoo.org/markup/para.html#directive-seealso

@roed314
Copy link
Contributor Author

roed314 commented Dec 15, 2011

comment:5

No good reason.

Apply 12116.2.patch only.

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 11, 2012

comment:6

Sadly roed's patch conflicts with #10596 and thus doesn't apply to the current Sage beta. I've just uploaded a rebased patch based on 5.0.beta7. This makes no changes to roed's code other than some minor sphinx reformatting (including using the new :trac: directive to point to this ticket). David: if you're happy with my reworking of your patch, you can set this to positive review.

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 11, 2012

Dependencies: 10596

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 11, 2012

Reviewer: David Loeffler

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 11, 2012

Changed dependencies from 10596 to #10596

@roed314
Copy link
Contributor Author

roed314 commented Mar 11, 2012

comment:8

Thanks for rebasing! I looked it over and it looks good to me.

@jdemeyer

This comment has been minimized.

@jdemeyer
Copy link

Changed upstream from Fixed upstream, but not in a stable release. to Completely fixed; Fix reported upstream

@jdemeyer
Copy link

comment:9

The upstream fix is in Sage now (#12363). Could you remove the workaround code from the patch?

@jdemeyer
Copy link

Changed dependencies from #10596 to #10596, #12363

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

Changed upstream from Completely fixed; Fix reported upstream to None of the above - read trac for reasoning.

@loefflerd
Copy link
Mannequin

loefflerd mannequin commented Mar 12, 2012

comment:10

Can we have a new option for the "Report Upstream" menu, "upstream claim to have fixed it but they apparently haven't"? PARI apparently believes that 2^3 = -8:

                                      GP/PARI CALCULATOR Version 2.5.1 (development git-5c5e253)
                                     amd64 running linux (x86-64/GMP-5.0.1 kernel) 64-bit version
                                       compiled: Mar  5 2012, gcc-4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
                                            (readline v6.2 enabled, extended help enabled)

                                                Copyright (C) 2000-2011 The PARI Group

PARI/GP is free software, covered by the GNU General Public License, and comes WITHOUT ANY WARRANTY WHATSOEVER.

Type ? for help, \q to quit.
Type ?12 for how to get moral (and possibly technical) support.

parisize = 8000000, primelimit = 500509
? ispower(-8, , &n)
%1 = 3
? n
%2 = 2

So I suggest we merge this patch as it is, and send another bug report to PARI -- roed, can you do the honours?

@loefflerd loefflerd mannequin added s: needs review and removed s: needs work labels Mar 12, 2012
@jdemeyer
Copy link

comment:11

I reported the new issue upstream. I would postpone merging this patch until we hear from upstream. I prefer to have the issue fixed upstream and not apply a work-around in Sage.

@roed314
Copy link
Contributor Author

roed314 commented Feb 27, 2013

Attachment: trac_12116-rebase.patch.gz

Rebased against 5.8.beta0

@roed314
Copy link
Contributor Author

roed314 commented Feb 27, 2013

comment:24

Alright, fixed.

@adeines
Copy link
Mannequin

adeines mannequin commented Feb 28, 2013

Changed reviewer from David Loeffler to David Loeffler, Aly Deines

@haikona
Copy link
Mannequin

haikona mannequin commented Feb 28, 2013

Attachment: trac_12116_rebase2.patch.gz

Flips order of returned pair in self.perfect_power()

@haikona
Copy link
Mannequin

haikona mannequin commented Feb 28, 2013

comment:26

Everything checks out. Patch applies, tests pass. However:

def perfect_power(self): 
    r""" 	         
    Returns ``(a, b)``, where this integer is `b^a` and `a` is maximal.
    ...

So

sage: a = 11^14
sage: a.perfect_power()
(14, 11)

I know the code just wraps PARI which returns the integers in this order, but this seems an unnatural way to order the returned pair.

I've uploaded a modified version of the patch so that we get

sage: a = 11^14
sage: a.perfect_power()
(11, 14)

which feels a lot more natural.

The new patch also fixes a possible formatting error in the documentation of self.is_perfect_power():

Returns ``True`` if self is a perfect power, ie if there exist integers
a and b, `b > 1` with `\texttt{self} = a^b`.

becomes

Returns ``True`` if ``self`` is a perfect power, ie if there exist integers
`a` and `b`, `b > 1` with ``self`` `= a^b`.

@haikona haikona mannequin added s: needs work and removed s: positive review labels Feb 28, 2013
@haikona
Copy link
Mannequin

haikona mannequin commented Feb 28, 2013

Changed reviewer from David Loeffler, Aly Deines to David Loeffler, Aly Deines, Simon Spicer

@roed314
Copy link
Contributor Author

roed314 commented Mar 1, 2013

Attachment: trac_12116-rebase3.patch.gz

@roed314
Copy link
Contributor Author

roed314 commented Mar 1, 2013

comment:29

Looks fine to me. I just updated the deprecated_function_alias.

@haikona
Copy link
Mannequin

haikona mannequin commented Mar 1, 2013

Attachment: trac_12116-rebase4.patch.gz

Changed a line to unbreak factor_aurifeuillian() in factorint.pyx

@haikona
Copy link
Mannequin

haikona mannequin commented Mar 1, 2013

comment:30

We missed another line. In self.factor_aurifeuillian() in factorint.pyx, we have

...
b = n + x
exp, b = b.perfect_power()
if exp > 1:
...

This must now become

...
b = n + x
b, exp = b.perfect_power()
if exp > 1:
...

otherwise this method breaks with the new ordering of values returned by perfect_power(). I've uploaded a new patch that fixes this.

Hopefully that should be it.

@roed314

This comment has been minimized.

@roed314
Copy link
Contributor Author

roed314 commented Mar 1, 2013

comment:31

Looks good to me.

@roed314
Copy link
Contributor Author

roed314 commented Mar 2, 2013

comment:32

For patchbot:

Apply trac_12116-rebase4.patch

@jdemeyer
Copy link

jdemeyer commented Mar 4, 2013

Merged: sage-5.8.beta3

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

6 participants