-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
Inexact zeros #35319
Comments
I have only thought about power series and p-adic numbers. So this only applies to these: I think that We have
What do you mean? How do we test that an element is an exact zero? (There might not be one in the ring.) How do we test that the element is indistinguishable from I don't understand what you mean with "Python compatibly". We cannot use
A matrix should be falsy if each of its entries is falsy. A polynomial should be falsy if the length of its coefficients is 0. (Everything else is just too surprising I think.) When coefficients should be dropped is a complicated issue. I don't know what's the latest thinking about this. |
Thanks for your comments.
(actually, I don't think there is any problem with ball/intervals. I just put it there as a matter of comparison and to be sure to include them in "rings that handle inexact zeros")
Could you elaborate a bit on this? I am starting thinking that making them behave differently might actually help a bit.
As far as I understand, this is the same behavior as power series sage: R.<t> = PowerSeriesRing(QQ)
sage: t == O(t)
True And this is furthermore compatible with the ideal reduction sage: 42 == Zmod(5)(2)
True The latter being analogous to
By "Python compatibly" I meant something that would apply to Python types I would precisely like to use
Which is annoying for sparse matrices that store a list of nonzero coefficients. Here you would like
Then for polynomials with power series coefficients |
I would not make
I don't know. I don't do sparse matrices usually so I am not sure what I would expect.
True. The notions of |
I think my intuition is a bit different from Julian's for polynomials (or matrices) I think the right approach in the long term is to implement different algorithms for inexact rings that use inequalities on distance and aim for good numerical stability properties. |
It seems to me that it is possible to write generic algorithms that behave properly in the presence of inexact zeros (and other things like that) in a computer algebra system, but one needs at least three different notions of equality:
I really don't see how one could get around distinguishing at least the first three. For example, to decide which coefficients of a polynomial should be printed, what matters is whether they are syntactically zero or not. That is not the same as certifying that the polynomial is mathematically zero (the coefficients may be un-normalized symbolic expressions or algebraic numbers, or they may be intervals), yet one may want to do both in the same code. Each of the four relations listed above is typically weaker than the previous ones, but not always. For instance, for intervals or NaNs, syntactic equality does not imply semantic equality. (I can't think on the top of my head of a case where one may want objects be semantically equal without being approximately equal. Maybe approximate equality is best thought of as coercion to a different algebraic structure followed by comparison in that structure.) Also, generally speaking:
Now some languages (e.g., Julia) provide standard operators that map pretty well to this typology. Unfortunately, this is not the case of Python. Equality in Python most closely corresponds to syntactic equality (cf. its compatibility requirements with hashing), and Sage tries to use it to give the impression of something closer to semantic equality, which leads to all sorts of problems with comparisons between objects that do not have the same parent. I think the broader question is how close we can get to a model which properly distinguishes between the various kinds of equality starting from the current state of things. It was under the impression that, except maybe in the p-adics code, there was a weak consensus to (ab)use the distinction between From the same point of view, having And to conclude these ramblings: I have of course no solution to these issues. I do think we need to write down what |
This is true for real "algorithms". But there are lots of almost trivial methods that can often be implemented to work for all rings (if we could just be specific about the notion of equality) and that saves lots of boilerplate in say p-adic specific polynomial classes. I find it frustrating that in generic methods I have to protect lots of things in
We'd still keep |
As an example of a "non true" algorithms, I would like to mention generic multivariate polynomial arithmetic (or sparse implementation of univariate) where you store pairs sage: sqrt(2) * sqrt(3) - sqrt(6)
sqrt(3)*sqrt(2) - sqrt(6) (I hope I understood Marc terminology correctly) In my proposal, both |
I really don't like having I'd be fine creating another method at the level of elements that could be used instead. For p-adics there's
Maybe we want to think about a non-underscore name that we can use more broadly (or we could just use an underscore method and promote |
Referring to the same Python documentation the default behavior of A global function |
Thanks to your input I updated the description. Feel free to edit or suggest modifications. |
The Pythonic way to test for inexact zeroness is to use |
Note that Attempting to define "syntactic equality" that goes beyond that is likely problematic. |
You probably misunderstood the issue at hand. Floating points are behaving perfectly well : they have a unique zero (though |
Would you call that a specification ? It is certainly useful for end users and certainly useless when considering polynomials over the symbolic ring that behave in a deterministic way. I rather care about the second point.
What do you mean by "that" ? If you refer to the symbolic ring I do not think that any of us seriously care about the semantic of the zeroness in the sage Could you point us to the problematic points rather than saying that it will be problematic ? What is wrong with the different proposals that have emerged from the discussion ? |
@mkoeppe I tried to clarified the issue. Tell me if it makes more sense. I totally agree that symbolic expressions are more delicate than power series/p-adics which are my main concern at the moment. But still, it makes sense to try to have a general framework for all of them. |
Thanks for the clarifications. Taking a closer look at the example in the issue description with the In particular, it's intransitive
... and therefore whatever may be intended there should not be expressed using |
I agree with this; I don't think this can be negotiable. |
The fundamental problem is that syntactic features such as sparsity of matrices and distinguishing "different representations" of an object contradicts the declared mathematical category and leads too easily to inconsistent behavior. An example question – what is the neutral element in the "additive group" of sparse matrices? (Answer: it's a trick question – sparse matrices don't form an additive group.) If the syntactically refined structure is really useful, then it should be analyzed and defined properly, separately from the original structure, and the original structure should become a quotient. (@mezzarobba expressed a similar point in an example in #35319 (comment)) |
It would indeed make sense in the power series ring to set What about adopting the same convention for power series? |
Yes, in a sense, but to be clear, I do support the idea of adding better-specified comparison operators to address the issue discussed here. |
I completely disagree that we should require radii to be the same for equality in power series rings. It's absolutely a good idea for
The real field has lots of different precision models, as do p-adics. There's only one version of power series at the moment. I'm completely supportive of implementing additional precision models for power series rings, and if you want to implement a new one that uses equality of balls, go for it. But don't break everyone's existing code with this change. |
For the original issue about how to test for whether to keep entries in a sparse representation (or trim leading zeros), I think a new function or method that handles the different cases is a reasonable solution. If you're worried about speed you could also have a method on the parent like |
<!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description Fixes #34000 (and more complete version of the proposition at #35020). A discussion about the general problem of inexact zeros has been opened at #35319 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [x] I have linked an issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. URL: #35174 Reported by: Vincent Delecroix Reviewer(s): Frédéric Chapoton, Travis Scrimshaw, Vincent Delecroix
Just for the record : PARI does comparison of power series in the sage style but MAGMA does not. From their documentation
Their documentation is still unclear about the meaning of "identical". |
Let me try to recap.
So the remaining questions are
|
Are you all talking only about power series, or in general? What do you think of the cases where
(and similarly for
|
I would say both. That is, ideally, I think we need “operator style” comparisons for all the variants of equality listed in #35319 (comment), but each parent can have some freedom to define what equality means for its elements. How much freedom it can have depends mainly
|
This issue aims to discuss the problem of comparison, and in particular comparison to zero, of ambient structures that provide exact computations which involve inexact objects or objects with multiple representations. It covers
O(t)
O(p)
sqrt(6) - sqrt(3) * sqrt(2)
RBF(0.3, 1e-18)
RIF(0.3 - 1e-18, 0.3 + 2e-18)
One of the goal is to come up with conventions that allows to manipulate accurately algebraic constructions on them such as (sparse) polynomials and (sparse) matrices. This is currently completely broken
Where the result here should have been
[[O(t^2) 0] [0 O(t^2)]]
andO(t)
. Note that generic dense matrices are better behavedIn order to solve the above algebraic construction, it is desirable to have finer distinction between different notions of being zero in order to distinguish "exact zero" that we can drop from a sparse data structure and "zero up to some precision" that should be kept. More generally, this issue is about about making specifications for comparisons of elements. For that purpose, it might be convenient to distinguish different notions of equalities
eg for power series, same precision and same polynomial
eg for power series, infinite precision and same polynomial
(note that "semantic" difference is not the contrary of equality : two power series are semantically different if at their common precision their polynomial differ)
(note "semantic" equality does not specify whether
x == x
should hold)eg for power series, equality of polynomials up to their common precision
Power series currently use approximate equality while balls use semantic equality.
What we would like to use for sparse polynomials and sparse matrices over power series/p-adic are "semantic" equality. Though it is not clear what is the best option for symbolic expressions. Something in between "syntactic" and "semantic" is probably what should be used so that "trivial" simplification could be made to keep reasonable arithmetic speed.
The main questions that are in need for specifications are
The text was updated successfully, but these errors were encountered: