-
-
Notifications
You must be signed in to change notification settings - Fork 510
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
Should not allow coercion from polynomials to symbolic ring #13360
Comments
This comment has been minimized.
This comment has been minimized.
comment:3
Even though there is an explicit conversion asked, I think the system uses coercion on the coefficients of f, which are elements of the polynomial ring A. The same thing applies even more essentially to evaluating f at a symbolic expression.
It's always one level further down where coercions are really useful. For your other examples: 1), 2) That should really be an error already. Nothing useful will even come from defining polynomials over the symbolic ring. [EDIT: As shown below, people DO find uses for them.] SR is not a fully implemented ring. For instance, equality testing is spotty at best. It's not really an integral domain either:
|
comment:4
Replying to @nbruin:
Thanks for commenting, nbruin! Yes I agree (I actually mention that in italics right at the top).
I would suggest replacing this with
Which relates to ...
I'm glad you mention this example. For me, this is not the same thing. In a way, it is exactly the distinction I'm trying to make with this ticket. I think your example should be allowed whereas coercion shouldn't.
The sage documentation explicitly states that this is supported (at least in the case of the As for it not being useful, I strongly disagree with that. As soon as you need coefficients like pi or sin(3), this is the only way to go. For example, to come back to your code:
Or, for a more specialized example: I'm doing calculations with Lax matrices in integrable systems. Then you want to calculate Laurent series in the spectral parameter, whereas all other variables are manipulated symbolically (i.e. functions can be applied to them). Just doing those calculations in the symbolic ring is much slower, you would need to collect and expand all the time, and the symbolic ring cannot keep track of big ohs. Of course, this ticket is exactly about inconsistencies arising from polynomial rings over SR. If you believe those should raise an error already, than it is logical to say that that is the source of the inconsistency. If, like me, you believe that it is very useful, then you open a ticket like this one. :-)
I think this is unfortunate, but I agree that the philosophy is in line with this. |
comment:5
As an afterthought: the symbolic ring offers |
comment:6
OK, you seem to have some use cases where polynomials over SR do have some use. Indeed, basic arithmetic (but not division!) should be OK. I think what you need is that elements from polynomial rings over SR are not coercible into SR. A solution like this would need an expert in the coercion system to implement correctly, because the coercion system is one area of sage where a small and seemingly innocuous change can easily have huge consequences (for performance, correctness or both) for the entire system. Roughly: if R.coerce_map_from(SR) is not None then SR.coerce_map_from(R['a',...]) should be None. I think that would remove most of the unexpected results. |
comment:7
Polynomials with coefficients in SR are very useful and it is a pity that their support is not ideal - hopefully it will improve. I do not agree that construction in 1) should give errors: as it is written, it is explicit conversion of a polynomial to the symbolic ring and I was annoyed by |
comment:8
Replying to @novoselt:
How about
It's much better if
No reason to convert to strings. Polynomial rings should really not be coercible to their base rings, and probably also not generally convertible to them (apart from constants). Sage's concept of coercion really relies on there not being "loops" in the coercion graph. They wreak havoc with finding common covering structures. |
comment:9
I think it is completely unambiguous what do I mean by
I understand that loopy rings may cause difficulties in the framework, yet it is not a reason to cripple the symbolic ring. I think that pretty much anything has to be convertible to it. A possible solution for the situation in question may be "symbolic ring with black-listed names", so that if I want to consider a polynomial ring in |
comment:10
Replying to @novoselt:
Even though I wrote this patch, I'm not too familiar with the coercion/conversion system. You may be right that it is easy to support For me, however, point 2) is so important that I would accept losing I'll see what happens if I revert the modifications to |
comment:11
Replying to @nbruin:
This is actually a really good example. On second thought, I'm inclined to stand by my initial argument for removal of these conversions, too. I'm open to other views, though. |
comment:12
Replying to @nbruin:
From the code, I think that is exactly what's happening now. However, that is what leads to point 2). If an expert in the coercion system can make it such that I'm sorry for spamming you guys by saying all this in three messages instead of one. |
comment:13
Replying to @tkluck:
I expect most people would find that undesirable. The most "economic" way of constructing |
comment:14
Replying to @nbruin:
Are you sure? How about this example:
Are you referring to any specific policy when saying "remember, polynomial rings over SR should be avoided"? Because I think they don't have to be and I'm trying to make their use as unsurprising as possible. |
comment:15
Replying to @tkluck:
Exactly.
There is a transcendental in For your application, it seems that you would like to restrict That's where |
comment:16
Replying to @nbruin:
This is a nice way of viewing it, and I cannot say that you are totally wrong. Still, someone who actually wants this can easily easily convert to the For that user, however, it really makes no big difference whether the result is in
No, definitely not, that's just the simple examples I've been giving. In my use case, the coefficients are all functions of symbolic variables.
I'm not sure what difference that makes from the point of view of adding a transcendental not in
Let me just give one more example.
will be the identity for all polynomials over any base ring, except for the symbolic ring. This map may not seem useful in practise, but imagine applying some map to the coefficients, or anything more interesting. The point is that the above may be a special case of some complicated transformation you're doing on polynomials. I know that one could probably work around this by
instead, but since we're talking about the coercion system, I'm trying to show examples where I think it doesn't work as expected. I'm also thinking of the case where a library algorithm I didn't write would work excellently on |
comment:17
Well, it is about as anomalous as the set of all sets: it is the only ring with canonical coersions into it from arbitrarily construction that uses it as a base ring. I am really starting to think that my previous idea of introducing white/black-listed symbolic rings would be a good solution and it should not be too hard to implement (although I don't know much about how SR is done). SR is similar to
it would definitely suit my purposes and I think it would allow adjusting coercion in such a way, that treating polynomials in t over this R or adding a polynomial over integers and elements of R behaves consistently with regular rings. By the way, I think that this is a bug:
Nobody in mathematics uses the same variable in the same expression with the same meaning, so there is no reason to support it. Moreover, this may indicate a logical error and a user would appreciate catching it. So I think that constructions that "add names" should check that they are absent in the base ring. This way it would be prohibited to create I suppose adding such a check is also not extremely difficult, but care should be taken when constructing polynomials "for internal purposes". There should be some standard way to get from a ring a name that can work as a "new name". And it should raise an exception for SR. I also think that for any element of any ring we should have |
comment:18
Replying to @tkluck:
That example doesn't work because sage refuses in a lot of cases to construct a suitable parent. Try:
If it did work, it would only work for base rings that don't have a generator named
this would give a different answer than the functorial one I think you're expecting. The fact that sage attaches meaning to print names of variables really does have some profound effects.
Indeed. It's much better to be explicit than making the system guess where you want your answer to live. I would probably do
in order to avoid introducing new (hard coded) names unnecessarily. |
comment:20
One problem with your solution 3) is that the symbolic polynomial is not given in expanded form. I'm wondering if there is a proper way to evaluate a polynomial at a symbolic argument and get the symbolic polynomial in expanded form. I don't want to use |
This comment has been minimized.
This comment has been minimized.
Work Issues: address review |
I've been struggling with some unexpected results in my computations with polynomials over the symbolic ring. Eventually, I came to the conclusion that it should not be possible to coerce polynomials to the symbolic ring. (Note: I'm not saying that you can't convert to the symbolic ring!) Here's some reasons for disallowing it.
I've also attached an initial patch implementing this. It needs more work though, because the same thing holds for
LaurentSeries
andPowerSeries
.Reasons for not allowing PolynomialRing -> SR coercion:
I think the first one should raise a TypeError, too.
It is not hard to imagine that this gives all kinds of unexpected results when trying to manipulate these kind of rings programmatically. This must have cost me days and days.
namely just substituting a symbolic variable:
This has the advantage that the conversion is explicit.
Component: algebra
Work Issues: address review
Issue created by migration from https://trac.sagemath.org/ticket/13360
The text was updated successfully, but these errors were encountered: