-
Notifications
You must be signed in to change notification settings - Fork 380
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
Control.Algebra contrib library? addition of VectorSpace (and related) unlawful versions and theorems/lemmas #2922
Comments
For your info, there is an external library not maintained by the Idris core team which tries to provide such verified "interfaces". Maybe this could be useful for you as well? Here's the link. |
Thank you. Of course I could also add the verified versions to your library (too). What I'm interested in is a 'place' where I could add unverified interfaces like So I rephrase my questions:
I'd rather contribute to some sort of 'central' library (or contrib) than create my own, to avoid unnecessary fragmentation. And I thought, that |
The plan is for |
Thanks for your answer. Edit: sorry, I confused nickdrozd with Sventimir |
I don't have any plans to maintain any libraries. So if nobody else picks the algebra stuff and it gets removed from the main repo, it will get scattered to the wind. Which would be a shame, both because the code is pretty cool on its own and also because it's a great stress test for the compiler. For example, AFAIK #1630 is still an issue. Incidentally, I am opposed to "unverified" interfaces. Currently the hierarchy mixes verified (real) and unverified (fake) interfaces, leading to unsolvable but completely avoidable problems like #72. I am not aware of any compelling technical reasons why it should be like this. (On the other hand, there are a variety of uncompelling social reasons.) It would be much simpler to make all the algebra interfaces verified and then just assert the laws to hold in cases where they can't be proved. See this post for more discussion. |
Sorry, I confused you with @Sventimir see this post Although reading that again now, calling a package
Exactly my thoughts. I'm willing to help or even maintain the package, if nobody else does.
That's fine by me too. I've just thought that unverified interfaces are the 'expected' way to do it for algebraic structures that are meant to be used by 'the public' and to not just 'turn them off' when they can't be proved (which you can't do for almost all uses of |
Reading the linked threads I'm now beginning to realize what this is all about. But ignoring the (IMHO unnecessary diamond hierarchy) for now: Taking a closer look at
This renders everything |
@Release-Candidate Yes, the current system has some flaws! A while back I worked out the details of fixing it; see yet another post. It would be great to get all that working, but unfortunately the "unverified" interfaces are an insurmountable obstacle. Oh well! But even if that issue were resolved, it turns out that it's very hard to work with fields anyway. This is because constant reference is made to the "nonzero elements", and that really complicates all the types. Maybe there is an ergonomic way to handle that, but I couldn't figure it out. As far as the ring definition, I think under certain circumstances it's possible to prove the commutativity of addition assuming the existence of a multiplicative identity. Or maybe I have the details wrong here, but in any case it's often possible to define the hierarchy of structures in alternative ways. Part of the fun is minimizing the the axioms required to prove something and figuring out what exactly follows from what. |
I once again invite you to have a look at idris2-algebra (if you haven't already done so). Personally, I think we should not write laws about interfaces but about sets (types) and their operations (functions). For instance, to proof the record LMonoid (a: Type) (p : a -> a -> a) (n : a) where
constructor MkMonoid
0 associative : Associative p
0 leftNeutral : LeftNeutral n p
0 rightNeutral : RightNeutral n p This solves the diamond issue and decouples proofs from interfaces. Of course we could still proof the correctness of an interface implementation. For instance: listMonoid : LMonoid (List a) (++) []
listMonoid = ... We can also show that (.semi) : LMonoid a p n -> LSemigroup a p
m.semi = MkLSemigroup m.associative This style is used throughout idris2-algebra, and I find it to be pretty convenient. |
@Release-Candidate, I am not actively working on Idris at the moment and also I cannot dedicate any amount of time consistently to maintaining an external library. So if you want to, please go ahead and extract algebraic interfaces from |
Sorry, this is going to be long. I hope it is (at least somewhat) comprehensible.
Interfaces for rings, fields and vector spaces. For practical and consistency reasons these have to be interfaces and be compatible with the existing interfaces - What are they for? Well, a ring is the structure of e.g. integer types, a Ring is an abstraction for all integer-like types - like the existing So why Ring and not just use Then
And finally a vector space over a These abstractions are mainly useful to integrate ‚external‘ types like the ones from GMP, MPFR for JS’ Decimal JS, in generic algorithms. To be usable, these interfaces have to be implemented in a sufficiently ‚central‘ place to avoid fragmentation and every math library using its own, incompatible, interfaces.
First of all, the big problem is proving that some type actually fulfills the laws of some algebraic structure. For an inductive type like the unary numbers,
The biggest one is the missing link to the interfaces
I don’t know what you mean (proofing in Idris is generally not very ergonomic).
Cool, now every x is 1 :)
Your definition of Ring is an error, it should be What you are thinking about is the proof that some ‚type‘ is commutative, for that you need to use the laws defined for your ‚type‘.
Yes, it would be very beneficial to actually explicitly state the binary operation to use, as to be able to ‚say‘ that a field over A has two abelian groups, (A, +) and (A, *). [^1] Definitions are often used in a way that are the least ‚work‘, so if you need e.g. natural numbers including/excluding zero, instead of always having to say ‚natural numbers including/excluding zero‘ you just define the natural numbers to be natural numbers including/excluding zero. |
You do realize that the complex numbers form a field without a total order? In addition, you can implement
We can have Edit: Actually, |
But ( Edit: Please note that the fixed precision integral types are implemented in such a way that in case of an over- or underflow, they automatically wrap around (using Euclidian division / modulo, as discussed in #1480). For example, for |
Sorry for the late response, I had been occupied by other stuff for a while.
Thanks, will do.
No, I totally ignored them, thanks for your correction.
Ignoring
But if you define the ring as being the ring modulo n, it is impossible to define a (total) ordering that is compatible with the addition of the ring (which means for example that |
True, the rings modulo n do not have a total order. But still they are commutative rings, so we should be able to treat them as such. And there is a total order for the fixed precision integers which is useful to have on its own right, for instance when implementing well-founded recursion. Just because this does not make About proving the ring laws: You can't prove them in Idris itself, but you can definitely proof them based on the representation of these integers as fixed precision sequences of bits and how the arithmetic operations are implemented. Thus, they do hold, so we might just as well tell Idris that they hold and use this knowledge to our advantage. |
I'd like to add some verified interfaces (VectorSpace and related) and also unverified versions of the existing ones (
Group
,Ring
,Field
, ...) as unverified versions would also be usable with types like Double, GMP's fractional type, MPFR floats, ... without needing constructing e.g. reals from cauchy sequences (like for example. Coq does).If I correctly understand, everything
Control.Algebra
(in contrib) is going to be put into a library. As this would break its usage anyway, I'd like to also rename some of the existing verified interfaces to get consistent naming of verified and unverified versions. As of now the verified versions ofSemigroup
andMonoid
are calledSemigroupV
andMonoidV
(for obvious reasons), but the verifiedGroup
,Ring
,Field
, ... don't have a suffixV
. I'd like to add theV
to the existing interfaces and add unverified versions of these.My questions is how to proceed? Should I add everything to contrib now (with unverified versions suffixed an
U
) or wait until it is extracted to a library (by @nickdrozd?)?Edit: sorry, this shouldn't be labeled 'Feature Request'.
The text was updated successfully, but these errors were encountered: