Skip to content

Add a pslq implementation to Sage #853

Open

Description

@williamstein

David Bailey's ARPREC package http://crd.lbl.gov/~dhbailey/mpdist/
includes several implementations of PSLQ, written in C++, and is
licensed under BSD. However, ARPREC raw multi arithmetic timings
don't look too favorable http://pari.math.u-bordeaux.fr/benchs/timings-mpfr.html and one has the same fix-x86 issues as quad-double.
It looks like, however, one of the advantages of PSLQ is that it does
not require full-precision at many of the intermediate steps. (that's
what this two-level stuff is about in his package--most operations
are performed with machine-double arithmetic).

Zimmermann also has a GPL implementation, based on gmp, which is only 1000 lines long. No idea yet how speeds compare.

https://members.loria.fr/PZimmermann/software/pslq-1.1.c

CC: @burcin @robertwb

Component: number theory

Work Issues: need advice on interface

Author: Paul Zimmermann, Alex Ghitza

Reviewer: David Kirkby

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

Activity

  1. self-assigned this
    on Oct 12, 2007
  2. williamstein commented on Oct 12, 2007

    @williamstein
    Author
  3. zimmermann6 commented on Nov 16, 2007

    @zimmermann6
    Contributor
    comment:2

    Damien Stehle did some comparisons between the PSLQ implementation of Bailey and his FPLLL, and
    FPLLL was much faster. Of course it would be good to have an independent comparison, but it might
    be that PSLQ does not outperform LLL when searching for linear relations.

  4. wdjoyner commented on May 7, 2009

    @wdjoyner
    Contributor
    comment:3

    To be precise, Zimmerman's code is at http://www.loria.fr/~zimmerma/free/pslq-1.0.c and is licensed under the GPLv2+.

  5. williamstein commented on Aug 10, 2009

    @williamstein
    ContributorAuthor
    comment:4

    I've attached the code/paper that was attached to the following email.

    agnes.jany@googlemail.com>
    to	wstein@gmail.com
    date	Mon, Aug 10, 2009 at 2:16 PM
    subject	PSLQ implementation
    mailed-by	googlemail.com
    	
    hide details 2:16 PM (1 hour ago)
    	
    	
    Reply
    	
    	Follow up message
    Dear Mr Stein,
    
    I'm a mathematics student at the Johannes-Gutenberg University of Mainz, Germany.
    As a part of my diploma thesis, I have implemented PSLQ to SAGE. You can find
    the code, a worksheet and a documentation in the attachment of this email. Maybe
    you can use my work for your project.
    
    Yours sincerely,
    Agnes Jany
    
  6. aghitza commented on Nov 29, 2009

    @aghitza
    Contributor
    comment:5

    Attachment: pslqimplementation.zip

    Note that mpmath, which is now a standard Sage package, contains an implementation of pslq:

    ----------------------------------------------------------------------
    | Sage Version 4.2.1, Release Date: 2009-11-14                       |
    | Type notebook() for the GUI, and license() for information.        |
    ----------------------------------------------------------------------
    sage: import sage.libs.mpmath.all as mpmath
    sage: mpmath.mp.dps = 30
    sage: mpmath.pslq([sqrt(n) for n in range(2, 8+1)])
    [2, 0, 0, 0, 0, 0, -1]
    sage: mpmath.pslq([pi/4, acot(5), acot(239)])
    [1, -4, 1]
    

    The examples are from the mpmath documentation, see http://mpmath.googlecode.com/svn/trunk/doc/build/identification.html

    The first one says that the only integer relation between the square roots of 2,3,...,8 is 2\sqrt{2}-\sqrt{8}=0. The second is one of the cool formulas expressing pi as a combination of arccotangents.

  7. aghitza commented on Nov 29, 2009

    @aghitza
    Contributor
    comment:6

    It would still be worth it to wrap Paul Zimmermann's C implementation, since it's fast. I tried it together with the mpmath implementation on the real life example given at the top of http://www.cecm.sfu.ca/organics/papers/bailey/paper/html/node6.html

    Both give the right answer (yay!). According to timeit:

    Zimmermann's C implementation:

    25 loops, best of 3: 13.6 ms per loop
    

    mpmath's implementation:

    5 loops, best of 3: 267 ms per loop
    

    So the C code is 20 times faster in this example.

  8. fredrik-johansson commented on Nov 30, 2009

    @fredrik-johansson
    Contributor
    comment:7

    The mpmath implementation should be correct, but it doesn't implement all the stopping criteria, and sometimes the precision, tolerance and iteration settings need fiddling with to give the right result. So even ignoring speed, it would be desirable for Sage to use an implementation that gives good control over all the settings.

    The 20x difference actually sounds a bit high (though not unrealistic). I wonder if the number of iterations is the same for both implementations (it could be quite different depending just on small implementation details). Also, on my computer, PSLQ runs about twice as fast with mpmath+gmpy than mpmath+Sage.

    I don't know how the other implementations compare, but I would favor adding e.g. Paul Zimmermann's implementation to Sage. It should be trivial to wrap mpmath.pslq as well, so perhaps it could be provided as an optional algorithm.

  9. aghitza commented on Feb 21, 2010

    @aghitza
    Contributor

    Author: Paul Zimmermann, Alex Ghitza

  10. aghitza commented on Feb 21, 2010

    @aghitza
    Contributor
    comment:9

    I have created an spkg for Paul Zimmermann's C implementation of PSLQ, see

    http://sage.math.washington.edu/home/ghitza/pslq-1.0.spkg

    I have also started writing an interface for using this from Sage, see the attached patch trac_853.patch. This is obviously not done: for one, there should be way more docstrings and doctests. However, I would like some feedback on the interface before I put much more work into this. If somebody has a cleaner way of using PSLQ from Sage, I'm happy to listen and throw away what I've done so far.

    I'm about to ask for feedback on sage-devel.

  11. 16 remaining items

  12. aghitza commented on Feb 24, 2010

    @aghitza
    Contributor
    comment:18

    Just a note on ARPREC's license, since Paul brought it up: it is not BSD as stated in this ticket's description, rather BSD-LBNL. However, this is apparently compatible with both GPLv2 and GPLv3, according to the table "Good licenses" at

    http://fedoraproject.org/wiki/Licensing

    So there should be no legal obstacles to using ARPREC.

  13. aghitza commented on Sep 10, 2011

    @aghitza
  14. hivert commented on Jun 20, 2012

    @hivert
    Contributor
    comment:20

    Hi Paul,

    How much work would that be to interface your C code with Sage ? Do you have a proof of concept ?

    Florent

  15. zimmermann6 commented on Jun 20, 2012

    @zimmermann6
    Contributor
    comment:21

    Replying to @hivert:

    How much work would that be to interface your C code with Sage ? Do you have a proof of concept ?

    no idea. Why do you ask? See comment [comment:2]. I see no reason to interface PSLQ.

    Paul

  16. hivert commented on Jun 20, 2012

    @hivert
    Contributor
    comment:22

    Replying to @zimmermann6:

    Replying to @hivert:

    How much work would that be to interface your C code with Sage ? Do you have a proof of concept ?

    no idea. Why do you ask? See comment [comment:2]. I see no reason to interface PSLQ.

    I'm at a small workshop and there is someone which is currently using Maple and is considering to switch to Sage.. Maple has both LLL and PSLQ. He told me that, he has some stability problem with LLL, in the sense that removing some precision digits gives drastically different results. Apparently PSLQ doesn't. I've no idea if it's a problem with the algorithms or the implementation.

  17. zimmermann6 commented on Jun 20, 2012

    @zimmermann6
    Contributor
    comment:23

    I'm curious seeing an example with some stability problem with LLL.

    Paul

  18. aghitza commented on Jun 21, 2012

    @aghitza
    Contributor
    comment:24

    This past January, a student of mine and I have run some experiments comparing fpLLL and the PSLQ implementations from ARPREC (we wanted to take the best current implementations to get a realistic comparison). In the examples we ran, we found almost no reason to use PSLQ instead of fpLLL for finding integer relations. The only situation where PSLQ might be more appropriate is when it is extremely expensive to generate extra digits in the input floating point numbers. PSLQ has a slight edge here because it tends to require fewer digits of precision than fpLLL. Most of the time this is of no consequence because fpLLL is much faster. We'll try to write something up describing our experiments and results, but I don't know how soon I'll find time for that.

    In terms of "stability", our experiments indicate that PSLQ tends to stick with the correct answer once it finds it, as you add more digits of precision. With fpLLL, you sometimes hit the right answer with, say 190 digits, but then you get different answers for a short while (say, 191 to 197 digits), and then it stabilises on the right answer again. Paul, I can dig up an explicit example of this if you are interested. Again, I don't see this as an issue from a practical point of view -- I would run the algorithm until I get the exact same answer with 3 or 5 different precisions.

  19. zimmermann6 commented on Jun 21, 2012

    @zimmermann6
    Contributor
    comment:25

    Alex,

    I can dig up an explicit example of this if you are interested.

    yes please do! Such explicit examples are extremely useful.

    Paul

  20. kcrisman commented on Nov 19, 2014

    @kcrisman
    Member
    comment:26

    Any news on this ticket?

  21. zimmermann6 commented on Nov 19, 2014

    @zimmermann6
    Contributor
    comment:27

    Any news on this ticket?

    I don't know what information was missing in comment [comment:9], but the following reference might be useful: http://dl.acm.org/citation.cfm?id=2465936

    Paul

  22. kcrisman commented on Dec 19, 2014

    @kcrisman
    Member
    comment:28

    See also http://math.stackexchange.com/questions/853339/ which seems quite relevant.

    Do we actually have one in Sage currently, by the way? A new user implied we might, just not a very powerful one.

  23. fchapoton commented on May 13, 2020

    @fchapoton
  24. whoami730 commented on Jul 17, 2025

    @whoami730
    Contributor

    I think we still do need PSLQ in sagemath.

  25. added 2 commits that reference this issue on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions