It seems that for characteristic 0, Maxima is quite a bit faster than
Singular, but there's some overhead in talking to Maxima over the
pexpect interface. In any case, it is still _way_ slower than what we
need. For example, Maxima takes around 10 seconds to do the bivariate
gcd of degree 100 listed here (
http://magma.maths.usyd.edu.au/users/allan/gcdcomp.html ). Magma on
the other hand takes 0.06 seconds.
--Mike
Even with the overhead Maxima is totally and completely unacceptable.
To take Joel Mohler's example of
t=-p10^170*X1^10*X2^10+p10^130*X1^10*X2^5+p10^130*X1^5*X2^10-p10^90*X1^5*X2^5+p10^80*X1^5*X2^5-p10^40*X1^5-p10^40*X2^5+1
I just tried this in Maxima, and it's been sitting there for about
*FIFTEEN MINUTES*:
sage: time maxima.eval('factor(-p10^170*X1^10*X2^10+p10^130*X1^10*X2^5+p10^130*X1^5*X2^10-p10^90*X1^5*X2^5+p10^80*X1^5*X2^5-p10^40*X1^5-p10^40*X2^5+1)')
... fifteen minutes and still going ...
Magma, on the other hand is instant!
sage: R.<p10,g0,g1,g2,g3,g4,X1,X2>=ZZ[]
sage: t=-p10^170*X1^10*X2^10+p10^130*X1^10*X2^5+p10^130*X1^5*X2^10-p10^90*X1^5*X2^5+p10^80*X1^5*X2^5-p10^40*X1^5-p10^40*X2^5+1
sage: s = magma(t)
sage: print magma.eval('time Factorization(%s)'%s.name())
[
<p10^8*X2 - 1, 1>,
<p10^8*X1 - 1, 1>,
<p10^18*X1*X2 - 1, 1>,
<p10^32*X2^4 + p10^24*X2^3 + p10^16*X2^2 + p10^8*X2 + 1, 1>,
<p10^32*X1^4 + p10^24*X1^3 + p10^16*X1^2 + p10^8*X1 + 1, 1>,
<p10^72*X1^4*X2^4 + p10^54*X1^3*X2^3 + p10^36*X1^2*X2^2 + p10^18*X1*X2 + 1, 1>
]
Time: 0.000
Since the goal of Sage is to be a viable alternative to Maple,Magma,Matlab,
and Mathematica, and Maxima just doesn't hack it speed wise, the only choice
is to implement something ourselves. E.g., the code Joel posted at
http://trac.sagemath.org/sage_trac/ticket/2179 does the above example in
about 0.10 seconds. That's a good start.
The important thing isn't what algorithm is implemented, but that the result
is fast(er than Magma).
-- William
> --Mike
>
>
>
> On Mon, Mar 31, 2008 at 3:39 PM, Roman Pearce <rpea...@gmail.com> wrote:
> >
> > Please excuse a (possibly naive) suggestion, but why not use Maxima
> > for multivariate gcds and factorization ? I looked at the source code
> > and it appears to do Hensel lifting for both. That is the correct
> > algorithm that Sage appears to need. I'm not sure how to run it mod p
> > or over GF(p^q), but it must be possible.
> >
> > >
> >
>
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
I'm amazed maxima is so bad at that example -- it's really about as easy as it
gets actually (there are 3 factors, one does not contain X1 and one does not
contain X2 -- you really don't have to factor at all, just gcd a couple of
times; then each of these 3 factors split again as a difference of 5th
powers).
I've been working very hard at this factoring for the last little bit as it's
really caught my imagination. There's a bivariate factorization scheme by
Gao using differential equations which seems like it might be a really good
tool. The simple application of specializing to a prime to reduce the number
of variable results in humongous coefficients and leads to a very slow
univariate factoring problem. It also has other technical difficulties like
spurious factors which are hard to resolve quickly.
I think there are 2 parts left to solving the factoring riddle for ZZ (and
possibly other bases, but I've been focusing on ZZ):
1) Fast basic arithmetic with a polydict -- I'm making headway
2) *Super-duper Fast* gcd algorithms -- this is going to be much harder than
#1 and the factoring bit. It's utterly crucial to the factoring methods --
crucial for finding squarefree decompositions, crucial for picking off easy
factors like my "hard" example has ... We need to implement every algorithm
we can find for this, benchmark them every way we can, and develop good
heuristics to choose amongst them. It can't be stressed enough that gcd is
central to the entire undertaking.
I'm hoping to have a first stab at industrial strength mpoly factoring over ZZ
in time for 3.0. It won't have industrial strength speed because of the gcd
going to singular, but a drop-in gcd replacement will make a world of
difference. Singular manages to suck in utterly grand fashion for both gcd
and factoring. I'm absolutely certain that we can beat them handily (but
probably not in the next month :-).
--
Joel
Just out of curiosity, is Magma vastly faster
than everything else in every single benchmark? I'm having
some trouble matching up what's at the above website with
the corresponding (?) timings on the Magma website. The
Magma timings are *all* < 0.65 seconds, whereas timings
on the above page are often many seconds to minutes.
By the way, Richard Fateman pointed out to me offlist that
Maxima running on top of clisp _might_ be much
slower than Maxima on gcl. This could be relevant to
our benchmarking.
-- William
--
Just because an algorithm is probabilistic
doesn't mean it necessarily gives wrong answers. By the way, see
http://www-fourier.ujf-grenoble.fr/~parisse/publi/gcdheu.pdf
which is I think a paper that proves correctness of the algorithm
we're talking about. (I've not carefully read the above short
paper, so I'm not vouching for it though.)
> There's no point in being
> fast if you're wrong, and developing good routines will take months.
In some cases being fast but possibly wrong is very useful. I think
this is not the situation here for mpoly gcd. It is the case for many
interesting computations with algebraic number fields, and people just
have to live with it. By the way, for factoring and gcd there are
double checks.
> I simply wanted to point out the existence of what appears to be
> correct routines, even if they are slow.
I do greatly appreciate that, and I think I misunderstood your comment
to suggest that we should forget about implementing our own code
and just use Maxima and be done with it. I apologize. I was responding
off list to a lot of "use lisp/Maxima or else" emails from somebody,
and was perhaps short tempered as a result. Hopefully you understand.
> Also, to Joel Mohler:
> You need "Algorithms for Computer Algebra" by Geddes, Czapor, and
> Labahn:
> Chapter 5: Chinese Remainder Theorem
> Chapter 6: Newton's Iteration and Hensel Lifting
> Chapter 7: Polynomial GCD
> Chapter 8: Polynomial Factorization
>
> What you are trying to do is not a "weeks long" project, it is one
> of the central achievements of the entire field. It took a
> decade
> to do the first time, so don't expect to have "industrial strength"
> routines soon. It will realistically take months of full time work.
> There's about 100 pages of material in that book, when you take out
> the exercises, etc. You need it all.
We'll see. By the way, who "did it"? Does *any* program doing
multivariate polynomial gcd and factorization well except Magma?
I'm not being rhetorical -- I just don't know the answer. If only
Magma does well, we should just find out what algorithms they
use, and if they aren't just copying from the above book, then we
*need* to be more clever than whatever is in that book. Allan
Steel did it -- by himself -- and so can we.
By the way, the book you suggest above was published in 1992.
Allan Steel implemented all the fast gcd/factoring code in Magma
many years later. It's perhaps highly likely he made great progress over
what's in that book. Maybe we can appeal to his vanity and
ask him.
> The people on this list seem to hilariously underestimate the depth
> of this problem, and that concerns me. I want Sage to succeed, and
> you can't with that attitude. This is a massive undertaking, and
> if you treat it like it's not it is ultimately very discouraging.
>
> I'd spell it all out: the things you need to do, the problems and
> subproblems, but it's easier and better if you just read the book.
I'm curious -- have you actually implemented multivariate gcd and/or
multivariate factorization? You talk as if you have.
-- William
Wait, actually Allan says what Magma does on this page:
http://magma.maths.usyd.edu.au/magma/htmlhelp/text314.htm#1994
And he says in each case that he uses algorithms that he made
that are based on those from the book you cite. For example
he writes: "... (3) a recursive multivariate evaluation-interpolation
algorithm (similar to that in [GCL92, section 7.4]), which in fact
works generically
over {Z} or most fields."
William
>By the way, Richard Fateman pointed out to me offlist that
>Maxima running on top of clisp _might_ be much
>slower than Maxima on gcl. This could be relevant to
>our benchmarking.
Not to start an implementation war but GCL compiles to C which
compiles to machine code whereas clisp is interpreted. Both Axiom
and Maxima have implementations on top of GCL. GCL includes a
routine that will output the lisp type declarations and if these
are loaded into the image with a recompile the resulting code is
even faster. So if you use Maxima, use the GCL version.
CMUCL/SBCL are capable of slightly tighter optimizations because
they grew out of the SPICE Lisp project (under Scott Fahlman)
and concentrated on code optimizations. Under CMUCL I managed to
optimize a function down to a single machine instruction so it IS
possible to get maximal optimizations. But GCL also lays down some
very tight code since proper declarations can usually eliminate
type dispatch, which is important in the inner loops.
You can see the generated code by calling (disassemble ....)
On the other hand you're likely to get small factors of improvements
by changing to compiled lisps (but certainly much faster than python).
My experience shows that its the algorithm changes that matter most.
On a related note, I found it odd that someone commented that
they wish to remove Lisp from Sage. Do you have any idea what
might motivate that?
Tim Daly
Axiom
Not at all. Many thanks for your helpful remarks below...!
> Both Axiom
> and Maxima have implementations on top of GCL. GCL includes a
> routine that will output the lisp type declarations and if these
> are loaded into the image with a recompile the resulting code is
> even faster. So if you use Maxima, use the GCL version.
Unfortunately we've had a lot of problems building GCL on all
our target platforms and have worries since it hasn't had a single
official release in about 3 years. GCL's fine on Linux, but not
elsewhere. I would have very very much liked to use GCL
for Sage originally, but for the life of me I couldn't get it to build
on the Sage platforms, unfortunately. We've tried several times
in the subsequent years, but always failed. Maybe it is time to
try yet again...
> CMUCL/SBCL are capable of slightly tighter optimizations because
> they grew out of the SPICE Lisp project (under Scott Fahlman)
> and concentrated on code optimizations. Under CMUCL I managed to
> optimize a function down to a single machine instruction so it IS
> possible to get maximal optimizations. But GCL also lays down some
> very tight code since proper declarations can usually eliminate
> type dispatch, which is important in the inner loops.
>
> You can see the generated code by calling (disassemble ....)
>
> On the other hand you're likely to get small factors of improvements
> by changing to compiled lisps (but certainly much faster than python).
> My experience shows that its the algorithm changes that matter most.
Very interesting. I wouldn't what the differences are in
speed between gcl and clisp maxima... A factor of 2 or 10,
or maybe it varies a lot depending on the operation...
>
>
>
>
> On a related note, I found it odd that someone commented that
> they wish to remove Lisp from Sage. Do you have any idea what
> might motivate that?
Michael Abshoff made that comment. He's motivated by wanting
to port Sage to a wide range of architectures and keep everything
maintainable, since he works incredibly hard on that. He suffers
a huge amount trying to deal with build issues on various platforms
such as solaris, Linux PPC, etc. I'm sure you understand well
how hard building complicated math software is on a range of platforms!
By the way, his comment was not an "official opinion" of the
Sage project or anything, and packages don't leave Sage without
a lot of discussion, voting, etc.
-- William
I understand. I have ported Axiom from Maclisp/VMLisp on mainframes to
workstations to PCs under a dozen lisps and a dozen opsys versions,
including Dos so I understand his pain. In fact, I think that porting
Sage is going to absorb a very large portion of your available time
and energy. The port to the next version of Python should be fun.
Trust me, you're underpaying Michael :-)
Tim Daly
Axiom
Wow, you should volunteer to help us :-). (Just kidding; I'm sure you're
very busy with Axiom, etc.)
> In fact, I think that porting
> Sage is going to absorb a very large portion of your available time
> and energy.
Not *my* time. But you're right that will absorb a lot of time. It
is very much worth the effort though.
> The port to the next version of Python should be fun.
Fortunately we can leave that mostly to the Python community.
Or, do you mean porting Sage to run under Python 3.0? Yep,
that's going to be a whopper. Our plan is to wait until
the many Python components of Sage transition forward,
and when that is done, then we will too. We won't until that
happens. I think it won't be too bad for us *after* that happens,
since many of the changes in Python 3.0 are things we
really want; trying to transition before all the 3rd party
packages transiiton would be insanely hard.
Fortunately, we've been careful only to include very well
supported active 3rd party Python modules in Sage (I hope! Knock
on wood.).
Here are the 3rd party Python modules we use in Sage:
* matplotlib -- plotting
* mercurial -- revision control
* moinmoin -- wiki
* networkx -- graph theory
* numpy -- numerical linear algebra
* pexpect -- pseudo tty
* pycrypto
* scipy -- numerics
* scons
* sqlalcheymy
* sympy
* twisted
* weave
* zodb3
> Trust me, you're underpaying Michael :-)
Michael is amazing. He's a hero.
-- William
sage: load /home/tabbott/fermat_gcd_1var.py
sage: time a = p1.gcd(p2, algorithm='ezgcd')
Wall time: 0.03 s (compare with 0.02)
sage: mp1 = maxima(p1)
sage: mp2 = maxima(p2)
sage: time a = mp1.gcd(mp2)
Wall time: 0.07 s (compare with 0.20)
sage: load /home/tabbott/fermat_gcd_4var.py
sage: time a = p1.gcd(p2, algorithm='ezgcd')
Wall time: 0.12 s (compare with 0.13)
sage: mp1 = maxima(p1)
sage: mp2 = maxima(p2)
sage: time a = mp1.gcd(mp2)
Wall time: 0.51 (compare with 1.04)
So, it looks like one's getting a 2-3x speedup by using Maxima with GCL
lisp on this particular test.
Of course, the fact that I'm running with GCL lisp also means that my SAGE
fails all the Maxima doctests involving real numbers due to roundoff
differences.
-Tim Abbott
I think that comparison with Magma is a little optimistic, especially
in the modular case.
http://www-fourier.ujf-grenoble.fr/~parisse/giac/benchmarks/gcd_timings
http://magma.maths.usyd.edu.au/users/allan/gcdcomp.html
--Mike
Now, it's true that we don't want to re-invent the wheel. However, it seems
to me that there aren't any opensource packages that manage the range of base
rings that we'd want sage to handle for multivariate polynomial rings.
Singular is probably the closest, but ZZ is only experimental.
So, while I may be reinventing the wheel for mpoly factoring over ZZ (although
it appears somewhat feasible that the wheel will be re-invented better), it
has already had a number of positive changes in the generic multivariate
polydict polynomial implementation in sage. I think the generic-ness of the
code is something worth pushing forward and seeing how fast we could be with
a generic base ring. I (and Martin, too) am interested in this generic
approach. Indeed, even the factoring algorithm has a large "prefix"
(square-free decomposition and the like) which is largely independent of the
base-ring.
So, my bottom line is this, there might be special purpose implementations for
specific base-rings, but I don't think that is reason to abandon pushing our
own implementation because I think our implementation can handle base rings
that nobody else can. Of course, it is likely that this generic-ness will
cost us some speed. But, it is not obvious to me that that cost is
necessarily prohibitive.
--
Joel
Hi,
sorry for joining in so late. Generally speaking, it is no necessarily easy to
determine what the "Sage developers" want, since we are all scattered across
the globe and all have different agendas/preferences/ideas. Also, all one
needs is one Sage developer (oneself can be that developer) to start working
on something. Thus, the lack of response doesn't mean that "the Sage
developers" don't want to collaborate. Each one of us might just have too
much on her plate right now.
To the topic: I don't really get the timings you posted, i.e. I cannot really
relate them to the timings posted on the Sage Wiki, could you try to provide
data that is easier to relate, or maybe I'm missing something.
I would say the best way to cooporate (since both projects aim to be a
frontend and IIRC you also ship Pari etc.) is to help each other out on the
C(++) library level. Especially for multivariate factoring, it would make
sense to colaborate on C/C++ library all projects could you. This way
everybody wins.
I don't really know the area but the "Factory" might be a good starting point.
Factory is the stand-alone (!) library used by Singular to do multivariate
factoring. Of course the defects of Factory started this thread in the first
place, but it might still have some sort of framework such that one can start
developing the missing algorithms. I would like to hear from people with more
experience in that area what they think about Factory's data structures
(Roman?). Another big plus for contributing to Factory is that it is somehow
widely used: Singular, Macaulay2 and Sage. Btw. Michael, what is the status
of multivariate factoring in CoCoALib?
To put some code where my mouth is, I can provide the following: We had a
direct interface to the factory once and I could revive it: I.e. I could
provide a Python interface to Factory that looks as much as possible like the
C++ interface in terms of class names, methods, etc. Then, people can start
going crazy and implement their favorite factoring algorithms, heuristics,
tricks in the Sage interpreter rather than on C level and make use of all the
Sage library (I guess linear algebra could be relevant). As a crucial second
step -- if the result doesn't totally suck -- this all gets ported down to
C++. I can't do the "creative" steps, where one has to write new algorithms
etc., but I can certainly help for the first (to Python) and the last (from
Python) step. But maybe this whole idea is just bollocks, I don't know.
Thoughts?
Martin
PS: In any case, If anyone wants to work on an optional GIAC spkg, please
speak up!
--
name: Martin Albrecht
_pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99
_www: http://www.informatik.uni-bremen.de/~malb
_jab: martinr...@jabber.ccc.de
I tried to build GIAC and it didn't go so well. The seemingly obvious way to
have it pick up sage pre-installed components (--prefix=...) allowed
configure to go through fine, but the compile did not. I manually fixed this
in one directory, but another failed then. I know that this is way to vague
to be a real bug report.
Another thing is that I think giac should be separated out from xcas so as to
not introduce an X dependency. This too, I'm not sure that I did my own
research adequately.
Nevertheless, I say all that to say that I did (quickly) attempt to try out
giac and when I get another bit of time to return to these pursuits that is
near the top of the list of things to try.
But, I'm also interested in making the sage sparse multivariate a very fast
alternative for simple arithmetic since we can offer a breadth of choices for
base rings that appears unparalleled. But, indeed, I'm simply enjoying
learning about mpoly factorization myself ... and one way (the best way?) to
learn it is to try and *do* it for oneself.
--
Joel