tag:blogger.com,1999:blog-4364963529335620962014-10-03T05:07:28.088+01:00SympythyProgress of my 2007 Google Summer of Code projectRoberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-436496352933562096.post-45278570928681613552007-08-15T21:10:00.001+01:002007-08-15T21:20:30.073+01:00Faster arithmeticA quick proof-of-concept finite field arithmetic and factorization was done. And the factorization over the finite field was reasonably fast, too, but the big prime reconstruction of the integer factors took some more time. Also, the resulting complete algorithm spent a lot of time with square-free factorization and other preparations. So, it was quite disappointing.<br /><br />I still started over again, rewriting everything from scratch, now with tests. First the modular integers, with a custom class for each modulus. Then a generic light-weight polynomial class, for one variable, using Python dictionaries. Then some algorithms for polynomials with finite prime field coefficients, with complete factorization, which is also quite fast. Today, I've started to do some more integer polynomial arithmetic, with a gcd using a small primes modular approach. Should be one of the fastest, asymptotically, but probably needs some more tweaking in my implementations. I should now check in which cases these modular methods really are faster than working with rational numbers. All this won't be finished for the Summer of Code deadline, but can be further advanced, while I learn from my new bought book, "Modern Computer Algebra" (Gathen, Gerhard).Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com0tag:blogger.com,1999:blog-436496352933562096.post-36291304640235234192007-08-06T08:51:00.000+01:002007-08-06T09:01:48.621+01:00Finite field factorizationI've finished updating the documentation and have started to move to next point, faster univariate factorization. This is done modular, with factorization over a finite field first. Fortunately, this point is a major part of Garthen and Gerhard's "Modern Computer Algebra" and thus well explained. Unfortunately, I've also read there:<br /><blockquote>Computaionally, (fast) polynomial factorization over a finite field is a much more advanced task than, for example, multiplication or even gcd computation. Before implementing a particular algorithm, one has to implement carefully many other routines for basic polynomial arithmetic, and designing a polynomial factorization package usually requires several woman-years.</blockquote>I still hope to get something done this week, doesn't have to be optimal, then. Let's see if it is a lot if work to integrate modular (number) arithmetic, or if this is better done "inline".<br /><blockquote></blockquote>Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com0tag:blogger.com,1999:blog-436496352933562096.post-78470313845312619922007-08-01T15:06:00.000+01:002007-08-01T15:17:28.126+01:00RefactoringNow, that the planned features are roughly present and we have moved to a new core with SymPy, there were some suggestions concerning the structure of the polynomials class. Most of them about the wrapper functions and code duplication, or the internals of the Polynomials class.<br />The Polynomials class is now immutable, as are all Basic-inherited classes, and tries hard to pretend to be a Basic object itself. We'll see how that will turn out. The wrapper classes essentially only extract the underlying sympy expression of the resulting Polynomial.<br /><br />The plan for the next days includes:<br />Documentation (proper docstrings everywhere, algorithms explained)<br />Testing (more complete tests, with comments)<br /><br />Then there are some more important features, like fast univariate integer factorization with finite fields. We'll have to look at some number theoretic python package, probably nzmath. Also, the equation system solver could tell us, when we are missing some solutions, that can't be computed but still exist.Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com3tag:blogger.com,1999:blog-436496352933562096.post-60674958304790887772007-07-17T01:04:00.000+01:002007-07-17T01:12:24.379+01:00Finally, multivariate factorizationOk, I gave up with Wang's algorithm, for now. It is not <span style="font-style: italic;">that </span>hard, in general, but the article describing it left quite some questions open for me. So instead of procrastinating the implementation any further, I did another algorithm, just today. It is a lot simpler, also due to Kronecker (20th century!), and not too efficient, of course.<br /><br />The last feature I want to add now, is solving polynomial equations. It is already possible now to compute a Gröbner base in a convenient order, like lexicographic, to get eliminiation working. Then, for each variable, you have to solve the univariate polynomial in that variable with solve(). You could insert each of these roots in the rest of the equation and proceed with the next variable. The problem with that is, that this approach only works for equations with a finite number of solution, which has to be decided first.<br /><br />Then there is still some time left for polishing: Documentation and efficiency allow for improvement!Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com1tag:blogger.com,1999:blog-436496352933562096.post-79790907345958794932007-07-04T01:04:00.000+01:002007-07-04T01:17:36.157+01:00Rational factorization.Just committed the new factorization algorithm for polynomials in one variable with rational coefficients. In now factorizes completely, doesn't just look for roots. In theory, factorization of polynomials over the rationals and factorization over the integers are equivalent (by Gauss's lemma). This means, that you can get rational factorization by getting rid of the denominators, then the content (gcd of coefficients), factorize over integers and divide the denominator again. Nothing is lost or gained this way. But in the implementation this situation got me a lot of problems. I always had to assume that the coefficients are integer, checking would occur often and so is expensive. On the other hand, some algorithms, like gcd sometimes introduce non-integer rationals, that need to be corrected afterwards. It seems to be fixed now (all assertions run) but it doesn't look elegant, something simpler should do.<br /><br />I hoped that the Kronecker algorithm would be fast enough, so that we wouldn't need finite fields for that, but it looks like this is impossible, since the complexity is exponential in (the number of divisors of each of) the coefficients of the polynomials, working fine for simple examples, but probably no real-life problems.<br /><br />But the next direct step should be multivariate factorization, as a generalization of the univariate case, to complete more of my initial proposal, before worrying too much about efficiency.Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com1tag:blogger.com,1999:blog-436496352933562096.post-28659405160441107482007-06-26T20:09:00.000+01:002007-06-26T20:21:41.822+01:00Refactoring, Sturm, Sqare-freeSo, most of the refactoring is done, there are now wrapper functions for the common algorithms, that create Polynomial instances and call specialized functions in sub-modules. It's not perfect, the code-reusing and efficiency could be better, but I'm relatively happy with it.<br /><br />I also implemented Sturm sequences. These can be used for univariate polynomials, to count the real roots in a given interval. This could be extended to isolate the (existing) roots in rational intervals, to give some representation of algebraic numbers, together with an irreducible polynomial.<br /><br />For that, you need a square-free polynomial (multiple roots are likely to be ignored by the Sturm sequence), so I looked at (and fixed) the square-free decomposition algorithm.<br /><br />Next things to do include multivariate square-free decomposition, fast factorization with one variable over the integers (Zassenhaus or Berlekamp), some multivariate factorization (found a paper by Wang) and some faster multivariate gcd (using sub-resultants?). All this is needed, before I can attack elimination and finally equation systems.<br /><br />When looking for algorithms today, I've noticed that most books only treat the univariate cases, but the articles are not accessible for free/everybody. Where do you usually get the ideas/help?Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com0tag:blogger.com,1999:blog-436496352933562096.post-50196180732745520792007-06-13T21:53:00.000+01:002007-06-13T22:18:22.258+01:00Back to work - New polynomial representation.Sorry for the delay, folks, I am finally back in Heidelberg, Germany and have also got over last week's procrastination problems.<br /><br />I was about to refactor the function code, to write wrapper functions, looking for variables and coefficient type and then choosing the best specialized algorithm to do the job. But writing the functions, e.g. the division algorithm, I remarked the cumbersome way of using (and keeping in sync) two different representations, the sympy object and the coefficient list. Since the latter is necessary for the leading term computation, I thought it was best to stick with it for all arithmetic like addition and multiplication. This way, it should also be way faster, but we'll see about that.<br /><br />The way it is implemented does not satisfy me at all, the code that handles variables and order before adding two such objects is ugly and (perhaps) contra-intuitive. Also, much more code-reusing could be made. But I hope, that the use of this class will look cleaner in the basic algorithms.Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com1tag:blogger.com,1999:blog-436496352933562096.post-69143863449064027532007-05-30T22:51:00.000+01:002007-05-30T23:10:35.634+01:00class `Ideal', next stepsSo, the Summer of Code officially started this week. Unfortunately, I'm spending my last days in Paris right now and will have to spend some time on moving back to Germany this/next week.<br /><br />On the other hand, some functionality (especially the groebner() function) are already available, even if in some slow, unpolished way. I've also added a new class `Ideal' that represents polynomial ideals and supports simple compositions, like I+J, I*J, I**3 and I.intersect(J), can test for membership, as in f in I --> True, or equality, I == J (equality in terms of the set, not the attributes like variables or order). I hoped to add the functionality of computing the radical of an ideal (the multivariate, multipolynomial equivalent of square-free part) but this turns out to be rather difficult, and not of any practical use outside of (theoretic) algebraic geometry.<br /><br />The groebner() function also has a nice application in computing the lcm and gcd of two multivariate polynomials with real (and even symbolic) coefficients, which could be used for rational simplifications, if not for speed issues. I know that there are faster ways to compute the gcd and also the whole factorization of polynomials, using modular algorithms, that is, factorizing mod some prime number p, that trying to `lift' the result. Unfortunately these algorithms can only be applied to polynomials in integer (and thus rational) coefficients, but could never handle some factor sin(z) for an unrelated z, as the Gröbner bases can. Nevertheless, these modular algorithms are on the to-do list.<br /><br />Also on this list is a function generating the Sturm sequence (I'll write about that later) that can count real roots of a polynomial and than perhaps approximate them with rational intervals. Then there is room for those standard formulas to get the real and complex roots of polynomials of degree < style="font-weight: bold;">not</span> be such a formula for higher degree)<br /><br />These will be the requirements for the whole elimination process, which could be somewhat limited with approximated non-rational roots, but we'll see.Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com1tag:blogger.com,1999:blog-436496352933562096.post-22863292746974190722007-05-24T12:19:00.000+01:002007-08-06T09:01:15.763+01:00Nice literature<br /><p>I forgot to mention some interesting books I use.</p><p><br />The most important one is Cox, Little, O'Shea: <a href="http://www.cs.amherst.edu/~dac/iva.html">Ideals, Varieties, and Algorithms</a>, which is an introduction to algebraic geometry (and commutative algebra) using a relatively constructive approach. That is, for most of the objects, there are not only proofs of existence (and uniqueness) but also algorithms (or at least references). I like it very much and have learned a lot so far; it was already a plan for the summer to revise some algebraic geometry, this fits very well.</p><p><br />Yesterday, I found two other books in the university, more directly concerned with (general) computer algebra:</p><p><br />Davenport, Siret, Tournier: <a href="http://people.bath.ac.uk/masjhd/DSTeng.html">Computer Algebra</a> is a gentle introduction to different features of CAS, problems of data representation and some advanced algorithms. It could be a bit outdated on current implementation details and running times, but gives a quick overview and offers confrontation with problems otherwise ignored. (Already half-way through, not looking at all details)</p><p><br />Gathen, Gerhard: <a href="http://www-math.uni-paderborn.de/mca/">Modern Computer Algebra</a>. Have not looked at it in detail, but looks really nice. One of the authors is an employee of MapleSoft and all methods are presented with a huge list of applications and examples. The content is presented with some information on historic development and stuffed with nice quotations (also in the original language, way to go!)</p>Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com0tag:blogger.com,1999:blog-436496352933562096.post-13009748155810841482007-05-23T21:29:00.000+01:002007-08-06T09:01:15.769+01:00Gröbner basis<br /><p>Hey, my first blog entry so far.</p><p><br />My name is Robert Schwarz, I am a student of mathematics and computer science at the university of Heidelberg, Germany. For the next two weeks, I'll still be staying in Paris, where I passed a year with the Erasmus student exchange program.</p><p><br />The GSoC project is mostly about Gröbner bases and application. The euclidean algorithm for finding the gcd of 2 integers is one of the most popular examples in programming. The same thing also works for polynomials, but unfortunately only in one variable. The Gröbner basis is a set of polynomials that means to replace the role of the gcd.</p><p><br />When looking for the solutions of some system of polynomial equations f(x,y)=0, g(x,y)=0 it is clear that we could add more equations like f+g or f*h for some polynomial h without affecting the set of solutions. The set of such equations/polynomials is called the ideal I = <f, g>, generated by f and g. If I want to know if some polynomial h(x,y) lies in I, I have to check if it can be written as h = a*f + b*g, that is, I try to divide h by f and g and look at the remainder, similar to the division with integers. Unfortunately, the choice of f,g and even their order can influence the remainder here, and it is the special characterization of the Gröbner bases, that it works with them. Hope, it is a bit clearer for those who have never heard of them.</p><p><br />The natural application lies of course in the solving of polynomial equations, with simplification of the equations and systematic elimination of variables. I think I've read somewhere that Gröbner bases are also needed for some other feature in sympy, I'm very interested in that, please tell me, so that I can start to help.</p><p><br />Yesterday, I finished the implementation of Buchberger's algorithm that computes Gröbner bases, so in theory, it is already available, even if it's still a bit slow.</p><p><br />Items on my to-do list: Speed improvements in groebner(), real-life examples for polynomial equations, elimination, factorization of polynomials, solving for (real) roots.</p>Roberthttp://www.blogger.com/profile/10644674458756425098noreply@blogger.com1