-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
bugs in infinite polynomial ring #7580
Comments
comment:1
I am glad to see in various posts on sage-devel and sage-support that finally people are using Infinite Polynomial Rings. They are using it in a way that I did not think of when I worked on the code (but perhaps Mike Hansen had this in mind? After all, it started with his implementation). The fact that people seem not to use it for Symmetric Groebner Bases implies two things:
My impression is that the code needs a thorough overhaul. Can we use this ticket for it? |
comment:2
Here some words on the requirement that variable names must be single letters. The generators x,y,... of an Infinite Polynomial Ring R are, mathematically, generators of R as a free module over the group algebra of the symmetric group G of the natural numbers (starting with 1, while 0 is fixed). A variable in R can be thought of as a pair (x,n), where x is a generator of R and n is a natural number. G acts on the pair by acting on n. In a text book, one would write it x_n. In the implementation, such variable x_n is returned by x[n]. We refer to n as the "index" of x[n]. It has an underlying "classical" polynomial x[n]._p. The question is: To what classical polynomial ring should x[n]._p belong?
Of course, when doing algebraic operations in the sparse implementation, the underlying polynomial ring must be extended. In the dense implementation, this is only needed when G acts, or if one does a conversion, say, of a string 'x10000+2*y100001' into R. But that's the point: How can I find the maximal index of Infinite Polynomials when doing arithmetic, G-action or conversion? Note that by arithmetic operations the terms of maximal index may cancel, so, it is not easily possible to infer the maximal index of a sum, given the maximal indices of a summand. And how should one find out the maximal index in a given string? I thought that an easy solution is to infer the maximal index from a string representation of the underlying classical polynomial q._p, if q is an Infinite Polynomial. This is one place where regular expressions occur. In order to simplify the regular expressions, generator names should be as simple as possible. There is another point. I wanted to implement Aschenbrenner's and Hillar's algorithm for finding Symmetric Groebner Bases. This requires a monomial ordering on R. Of course, I am using monomial orderings of the underlying classical polynomial rings. But this means: If I construct the parent of q._p (again, q an Infinite Polynomial) then I must order the occurring variables. Usually, the variable names have to be sorted, first, by the name of the generator and, secondly, by the index. Again, I sought to do this operation as quick and easy as possible. And these are the reasons why I imposed the name restriction:
But what about just requiring that generator_name must not contain "". Then, one could say var_name = str(generator_name)+''+str(index), and process var_name by
Actually the approach using "" has one benefit: Suppose one is given the string representation of the underlying polynomial and wants to determine the maximal index. This can be found using a simple regular expression, since a sequence of digits defines an index if and only if it is preceded by "". Thus:
So, in the end of the day, using "_" could be faster. Would it be OK to say "generator names must be alphanumeric and must not contain underscore"? |
comment:3
Here is one example why I chose to use regular expressions. Often I have to find out what variables (i.e., generator and shift) occur in what power in the leading monomial of a polynomial. So:
The generic approach to get the exponents of the variables in the leading monomial is, of course, the method
It is a long list, and we still did not separate the generator name from the shift. Now, do essentially the same with regular expressions:
The list is much shorter, and moreover generator names and shifts are already told apart. This is actually the typical situation for elements of Infinite Polynomial Rings in dense implementation: Only few variables from the underlying finite polynomial ring appear in the leading monomial. And I guess this is why the regular expression is faster:
IIRC, in a very early stage of my implementation, I did use |
comment:4
I am now going through the bugs that you reported:
I found the reason: There is one attribute of My plan is to go through the whole code before posting a patch. I hope that's fine. |
comment:5
Concerning the erroneous result of I meanwhile have code that allows for any alphanumeric variable names. Only requirement: The reason for requiring a base field: It is needed for my original application, Symmetric Gröbner Bases. But as people now want other applications, it seems fair to allow any base ring that is also allowed for classical polynomial rings. So, the exception should only be raised in the |
comment:6
Hi! I implemented what I suggested above and fixed the reported bugs, but I found that changing the new variable naming scheme ( But if I remember correctly, Nathann was considering to remove the use of Infinite Polynomial Rings from mip.pyx. What is the status? Is there a ticket for it? Then the two tickets should be somehow coordinated. Does this mean "status needs-info"? I guess so... Cheers, |
comment:7
Here it is !! Perhaps you do not need fixing the docstrings in class mip as they should be changed by this patch soon : I'm mainly waiting for a answer from Martin and this ticket should be settled :-) Nathann |
comment:8
Replying to @nathanncohen:
Thanks for the info! I hope I will be able to post a patch today, without changing the mip.pyx doc tests. |
comment:9
While I started to comment my patch, I found that not all issues are resolved. For example, I can define an infinite polynomial ring whose base ring is another infinite polynomial ring -- but the computations with elements of such ring don't quite work yet. Sorry. Later, I'll provide another patch that fixes it. |
Changed keywords from none to infinite polynomial ring coercion |
comment:10
Hi! Cc to Nicolas, since it partially concerns categories/functors. We proudly present a major revision of Infinite Polynomial Rings; the patch bomb is relative to sage-4.3.alpha1. First of all, it fixes the bugs that William stated in the ticket description. Second, it is now possible to use any commutative base ring; the restriction of using fields is now moved to the Third, and that's the biggest change: It now uses the strength of Sage's coercion machinery in pushout.py. I hope I did not overdo my use of it... Bug fixes Answer to William's failing examples:
I think that error message is clearer, and it gives a good advice...
So, that bug is gone.
Extensions The variable names can be any alphanumeric string. The base ring can be any commutative ring. Note the rhyme...
1.1. Therefore I decided to just work around these bugs. One issue is to evaluate a string 'x_2*t', if 'x_2' is a variable in an infinite polynomial ring and 't' is a variable in the base ring. gens_dict() would at most know about 'x_2' --- but with the additional complication that there is no fixed finite list of variables for the infinite polynomial ring. Solution I introduced a dictionary-like class And I introduced a class I think that this class might be of general use, e.g., for fixing issues in Examples:
This is what I mean by "bug in
I think that
It is now possible to construct quotient rings of infinite polynomial rings by symmetric ideals. Here, of course, it is required to have a field as base ring (for Groebner bases)
Note that
By the second generator of G, variable x_n is equal to x_1 for any positive integer n.
Note that the one doc test in Coercion I discovered construction functors and pushout, and now I really appreciate Sage's coercion system. By consequence, I make extensive use of it --- hopefully not too much... I introduced a construction functor for infinite polynomial rings. This functor, together with a ring, is used as the unique key of an infinite polynomial ring (as unique parent structure. I don't know if the use of construction functors for providing unique parents is common --- but I can recommend it!
As you can see, the given base ring is generally not used in the unique key. The reason is explained in the next paragraph. In a way, an infinite polynomial ring X is just an upgrade of a usual polynomial ring P: The former has finitely many generators x, y and infinitely many variables x_0, x_1,..., y_0,y_1,..., while the latter may have finitely many variables x_0,x_1,x_2. Now, imagine what happens if you define In fact, this is what I do, still with unique parent structures:
However, one has to be cautious: Infinite Polynomial Rings are ordered rings. Therefore, we only merge P into X if it is not only isomorphic to a sub-ring of X, but isomorphic to an ordered sub-ring of X. If this is not the case, an error will be raised:
Note: We attempted to make y_* greater than x_* in X, but x_* is greater than y_* in P.
Note: In any infinite polynomial ring holds x_2>x_0, but the order in P is opposite. The 'magical merging' is based on the multiplication of construction functors, combined with the fact that functors are used as unique keys for parent structures. Remark What I do here could also be a model for polynomial rings. After all, I think it is a bug that the following does not raise an error:
The original purpose of the coercion machinery is probably to allow for flexible use of arithmetic with elements of different rings. There you are:
or
Note that the last example only works since P and X both have order 'degrevlex'; otherwise we couldn't fit both P and X into a common ring. Self-critical comments
Question to the Reviewer Can you please test on a 32 bit machine as well? I know that the hash code on 64 bit has changed, but I have no access to 32 bit and don't know what hash value to expect. I hope that you enjoy that patch bomb... Cheers, Simon |
Author: Simon King |
comment:11
"The variable names can be any alphanumeric string. The base ring can be any commutative ring. Note the rhyme..."
|
comment:12
Replying to @williamstein:
:) If there is a speed improvement then it is very likely due to the recent improvements of conversions in And if there are bugs -- well, of course there are (as in any non-trivial program), but I did my best to hide them. Cheers, |
comment:13
Here are the doctest failures on 32-bit Ubuntu:
|
comment:29
Replying to @JohnCremona:
What???? Even parts of the old patch would apply to sage-4.3.1.alpha1. Anyway. What I did to produce the patch was:
So, I am really puzzled. Can other people confirm that it fails to apply? Cheers, Simon |
comment:30
Has anybody tried yet whether the patch really fails to apply? |
comment:31
I'm building a new 4.3.1.alpha1 (for another reason) and when that's finished I'll try again. |
comment:32
The patch has DOS/Windows endlines, so maybe doing a
will make it apply cleanly. |
Attachment: 7580_fixes_and_extensions.patch.gz Major bug fixes and extensions for infinite polynomial rings |
comment:33
Replying to @wjp:
Thank you for your hint! I changed the attachment accordingly. The problem is that at home I only have a tiny little Eee PC that came with Windows. I thought that xemacs on Windows would be good enough, but apparently it isn't. The patch was made on sage.math, though. So, let us hope that it now works! Best regards, |
comment:34
The new patch applies fine to 4.3.1, and almost all tests pass. (I tested the whole Sage library):
If this pickling problem can be sorted out, this can pass! |
comment:35
Replying to @JohnCremona:
As I explained above, the "unique key" in the ring constructor has completely changed: It used to be a base ring plus the list of variable names plus a descriptor of the monomial order and of the implementation (dense vs. sparse); now, it is a ring plus a construction functor. I guess this explains the error. But there is a version number passed to the construction factory, in addition to the unique key. Probably that allows to transform old pickles into shiny new rings. I did not know that there existed old pickles. Thank you for pointing it out! Best regards, Simon |
comment:36
Replying to @simon-king-jena:
There is a very clear difference between new and old "unique keys" (which are used for pickling): New keys are pairs, old keys are longer tuples. I guess it is robuster to discriminate by the length of the key rather than by version number. I am now running Cheers, Simon |
Attachment: 7580_unpickling.patch.gz Allows to read old pickles of infinite polynomial rings |
comment:37
The patch 7580_unpickling.patch is to be applied after 7580_fixes_and_extensions.patc (disregard the third patch). With the patch, To summarize the content of the patch bomb, I refer to my comments 10 and 20. |
comment:38
Patch problem: I tried applying 7580_fixes_and_extensions.patch to both 4.3.1 and 4.3.2.alpha0 and in both cases there were many hunks which failed. Could you list by name which of the three patches should be applied and in which order? I seem to have this confused... |
comment:39
Replying to @JohnCremona:
Very strange. It should at least apply to 4.3.1, since this is what I started with. And according to your comment 34, you had been able to apply it once. Perhaps you did not revert it? Anyway. One should first apply 7580_fixes_and_extensions.patch, then 7580_unpickling.patch, and that's all. Cheers, Simon |
comment:40
I must have messed something up, since I made a new clone from the main branch in each case and applied the correct patch first, which I had previously applied with no problem. Perhaps I had made changes to the main branch by mistake. But that would not affect the attempt on 4.3.2.alpha0, since I had not made any clones or applied any patches to that before trying this. I am currently building 4.3.2.alpha1 from source; when that is done I'll have another go -- might as well, since that will be what these patches have to apply towhen merged in any case! |
comment:41
On a new clone of a new build of 4.3.2.alpha1, I cannot apply the first patch (i.e. 7580_fixes_and_extensions.patch). I think someone else had better try! |
comment:42
Replying to @JohnCremona:
OK, then I'll rebase it and post a single patch that unifies the two old patches. However, it'll take a few hours until 4.3.2.alpha1 will be available. |
comment:43
OK, so this is partly my fault: I had not realized that the patch named 7580_fixes_and_extensions.patch had been updated (the old one was 172079 bytes, the new one is 168016 bytes -- something about line-ends). I had been applying the older one. So I tried the new one and got this (fresh clone of 4.3.1.alpha1):
which still needs a little attention, but only a little! |
Stand-alone patch relative to sage-4.3.2.alpha1 |
comment:44
Attachment: 7580_fixes_and_extensions_total.patch.gz I produced a new patch relative to sage-4.3.2.alpha1, that summarizes all other patches. So, just apply 7580_fixes_and_extensions_total.patch. Note that I merged the code of sage-4.3.2.alpha1 with my new code on a Windows laptop. But I transferred it to a Linux PC, used dos2unix, and all further edits happened there. Then, I created a patch, copied it to my Windows laptop, and there you are. I hope that in that way I avoided Windows EOL. Note that there is one additional change. It seems that the "dir" mechanism has changed in sage-4.3.2: Before, the documentation of dir stated that it would use a method !dir! if available, but in fact it ignored such method. Instead, it used the attributes !members! and !methods! or so. This has now changed (as I noticed when a doc test failed), and by consequence I now provide a !dir! method in addition to the old form of tab completion. Concerning tests: I did not do sage -testall. But I did test the files that I have changed: pushout.py, symmetric_ideal.py, symmetric_reduction.pyx, infinite_polynomial_ring.py, and infinite_polynomial_element.py Hopefully it works now... |
comment:45
The latest patch applies fine to 4.3.2.alpha1, and all tests pass! I tested the whole library (but not with long). |
Reviewer: John Cremona |
Merged: sage-4.3.3.alpha0 |
Why do we get a TypeError doing x[100] after the overflow error?
then the following weird error.
which is made weirder because the same input again suddenly works!
Here's one that is weird, due to not validating input before passing it off to the libsingular coercion function:
It's also really weird that the variable names have to be a single letter and that the base ring has to be a field. Why?:
CC: @mwhansen @nathanncohen @nthiery
Component: algebra
Keywords: infinite polynomial ring coercion
Author: Simon King
Reviewer: John Cremona
Merged: sage-4.3.3.alpha0
Issue created by migration from https://trac.sagemath.org/ticket/7580
The text was updated successfully, but these errors were encountered: