-
Notifications
You must be signed in to change notification settings - Fork 247
Setoid parameter in algebra records #1238
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
Comments
The problem here is one of sharing: there is a One way to deal with it is via having both bundled and unbundled versions of some structures. That way the sharing can be expressed via parameters instead of fields. The drawback is that even though the bundled and unbundled versions are semantically equivalent, Agda doesn't know that, and so 'work' needs to be done to go back and forth. [In theory, cubical solves this, but I am not convinced if this is yet true in practice.] Note that the Arend theorem prover has solved this problem really nicely already. And its solution seems very Agda-compatible to me. The Agda developers are aware of this, but they may not yet be aware of the impact it has on the current library development. |
A simple and natural solution is needed. |
For any occasion: if the approach occurs all right, I do not pretend for authorship. Probably the approach is well-known, besides, the idea is evident to everyone. The matter is that the library needs to be fixed in somewhat a natural and sensible way. And I doubt about what can be this way. |
This is a recurring problem in most proof assistants and has been studied extensively in the past, for example by Gontier et al. (https://hal.inria.fr/inria-00368403v2) for their formalization of the Feit-Thompson Theorem in Coq. This paper gives a rather nuanced view on the tradeoffs between the bundled and unbundled representation of algebraic structures. Their recommendation is to define structures as small components ('mixins') that can be composed freely in record types. They also rely heavily on type-classes in Coq to fill in missing parts of those record types. In Agda the equivalent would be to use instance search (though the standard library has thus far -- quite understandably -- refrained from using those). They also rely quite a lot on implicit coercions, which does not (yet) have an equivalent in Agda. |
Before considering wise theories it has sense to check the simplest way out. |
Your design looks reasonable to me, but the problem is that there are many possible designs that all look reasonable, and the disadvantages of a certain approach do not appear until one is 9 levels deep in a hierarchy of algebraic structures (this is the point made in the paper). One concrete problem that could happen with your proposal is that later on you have a similar problem, not for My point is not that these problems are impossible to solve, but rather that there are many choices to be made and their effects are not apparent until much later. So if we do not want to waste a lot of time trying out these possibilities, we might want to look at what others have learned about the problem. |
Sounds reasonable.
I have a hope that this would not happen. Because IsCommutativeSemiring has to be parameterized by Semiring rather than Setoid or Group To test the approach, one needs, may be, to set these 9 levels of definitions, and to provide a program that checks all places where such a uniqueness is needed, and to see whether it is type-checked. May be indeed, it is needed to study the works like the paper you refer. |
I wrote
Jesper (and anyone), |
For any occasion: |
As @jespercockx says, it's impossible to know where the downsides of your approach would lie without trying it out in large scale developments. In order to make this change, I'd want to see a significant proof of concept. Translating the standard library to use it would be the absolute minimum. However, there's also a cost-benefit analysis to consider. This is not a minor change you're proposing, but will require everyone to entirely rewrite all of their algebra related code. I 100% agree with you that the current situation is not ideal but currently as I understand it your main argument for the change is that:
Unfortunately we would need a better reason than that to break everyone's code so completely. Is there anything you can't do with the current design? |
This problem is really hard: think of being able to easily express that a field is a 1-dimensional vector space over itself, fully sharing the underlying Setoid (and more). Vector spaces are naturally 'very' 2-sorted, but sometimes you need to know things definitionally. The current library design has its flaws, for sure. But there is no point going to another, potentially somewhat better, design if we already know that it too won't scale. You don't want to massively break people code's twice. A proper library contains hundreds of 'diamonds' - see Library/mathscheme.tog in https://github.com/ysharoda/tog. [For the curious, those 315 lines of code actually mean 22000 lines in raw tog, which is basically a cut-down Agda, see Library/mathscheme-generated.tog]. |
This example is easy. I have 3-4 page program presenting an approach to fix standard library.
Then the goal is declared as I do not believe that people would agree to essentially refactor the library. |
Everything algorithmic can be expressed in almost any language. Still I do not think that the above my note about the two setoids is sufficient to immediately start to change the library. |
Vector spaces are not in standard library. This is a subject of applied libraries. For any occasion: there is another area where (Agda + standard library) is tested: |
'substructures' are a very set-theoretic notion. They do not mesh very well with type theory. This is why in Coq (in mathcomp) and I think now Lean too, 'sub' structures per se do not exist. What you do have are structures also injective homomorphisms (usual substructures assume the underlying function of the homomorphism is the identity function; this is an over-constraint inherited from set-thinking). Some known algebraic constructs turn out to 'bake in' stuff from foundations that people had not realized until they tried to formalize them in other foundations. George Gonthier (and many co-authors) have written multiple times about this. There was a long twitter thread with Andrej Bauer and Kevin Buzzard 'unraveling' these ideas too. Expressing 'substructure' via a membership predicate (that is the forgotten at point of use) works, but turns out to be a hack, that ports set-thinking over to type theory. This is not stable under various natural operations. So it should not be regarded as a good encoding of the mathematical notion. |
Consider a simple example. One has to implement in Agda the following discourse.
Then it is easy to define the equality Well, one can define this as an injective homomorphism from M' to M (agreed with the two equality relations). And the above lemma also is easy to prove.
But the main question for me is: what precisely is evil in the approach with a predicate? If you are going to explain the subject, then it is probably better to open another issue. For example, |
I completely agree that it is not as close to the original definition! The point is that maybe the original definition was sub-optimal. The approach with the predicate is not 'evil'. It seems to not scale: later theorems will want a Group, not a Subgroup, as input (for example). The other thing is that "change of variables" (representation, etc) doesn't necessarily transport the predicate the way you want it to. To insure that it does, you need various preservation lemmas. [That's the whole point of They're having difficulties in Lean with certain things having to do with localization (of groups) because of that. |
If
For example, integer numbers are represented in unary system ( |
The carrier is whatever you want, as long as it's isomorphic to the even integers. The problem with nesting records has been well-documented - See Type Classes for Mathematics in Type Theory as a particularly lucid explanation. It's not that it doesn't work, it's that it only works in simple cases. Again, for transport, the problem is not that it doesn't work - it works quite well for simple cases. You can see some examples of this breakdown in the (very recent) preprint Formalizing functional analysis structures in dependent type theory. |
@mechvel I'm going to close this and similar issues as the consensus of people far more informed than I appears to be that this is a language design problem, not a library design problem. |
May be it is better for standard library to improve the record design for algebra?
We wrote about this recently in the Agda list.
in Semiring. The same is for decSetoid. I do not find any better way out as introducing
+-setoid and *-setoid in the application. And this does not look nice, it misleads the user.
of code.
Breaking backwards compatibility is not so bad at the current stage.
Because
a) so far, each new lib version still breaks almost all the user's application modules,
b) it is not difficult to port the application to a new version,
c) each application specifies the needed Agda version (and hence the lib version),
install this version and enjoy,
Probably, we need to continue this way until it becomes stable in somewhat a natural way.
The text was updated successfully, but these errors were encountered: