From marko at dimjasevic.net Sun Jan 5 23:52:35 2020 From: marko at dimjasevic.net (Marko =?UTF-8?Q?Dimja=C5=A1evi=C4=87?=) Date: Sun, 05 Jan 2020 23:52:35 +0100 Subject: [Agda-dev] Implementing a solver for universe levels Message-ID: <2f42b75db05971560650ae76b4dda5fe4f546c13.camel@dimjasevic.net> Dear Agda developers, The upcoming Agda 2.6.1 release features universe cumulativity [1]. In an email to the Agda users mailing list (agda at lists.chalmers.se), Jesper Cockx said the following about cumulativity [2]: "If anyone is interested in implementing a proper solver for universe levels, please get in touch!" I am interested to work on this! Would anyone be so kind to say a bit more about the problem, the current state of universe levels and of the cumulativity feature, which is marked experimental? Furthermore, how big an effort to implement a solver is considered to be? So far I made no coding contributions to Agda, though I've been a Haskell developer. [1] https://github.com/agda/agda/blob/release-2.6.1/CHANGELOG.md [2] https://lists.chalmers.se/pipermail/agda/2020/011486.html -- Regards, Marko Dimja?evi? https://dimjasevic.net/marko PGP key ID: 056E61A6F3B6C9323049DBF9565EE9641503F0AA Learn email self-defense! https://emailselfdefense.fsf.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: From Jesper at sikanda.be Mon Jan 6 10:26:22 2020 From: Jesper at sikanda.be (Jesper Cockx) Date: Mon, 6 Jan 2020 10:26:22 +0100 Subject: [Agda-dev] Implementing a solver for universe levels In-Reply-To: <2f42b75db05971560650ae76b4dda5fe4f546c13.camel@dimjasevic.net> References: <2f42b75db05971560650ae76b4dda5fe4f546c13.camel@dimjasevic.net> Message-ID: Hi Marko, It's great to hear that you want to contribute to the implementation of Agda! Universe polymorphism is a relatively stable feature of Agda, though there have been some recent changes due to issues found by the new internal double-checker. OTOH Cumulativity is really new and hasn't got much testing yet, so depending on its reception in the release it might stay relatively unchanged or it might be removed/replaced entirely. The current implementation of cumulativity makes use of a simple heuristic to instantiate unsolved levels (at https://github.com/agda/agda/blob/master/src/full/Agda/TypeChecking/Level/Solve.hs): if checking a signature or a definition produced unsolved level metas and they are no lower bounds on those metas, instantiate them to the lowest possible solution `lzero`. If you turn off this heuristic (e.g. by commenting the line `defaultLevelsToZero newMetas` and recompiling Agda), you can see some examples of the kind of constraints a solver would need to handle. For example, on the file `test/Succeed/Cumulativity.agda`, I get the following: ``` Failed to solve the following constraints: piSort (Set ?) (? x ? Set (? ? ?? ? _?_247 (n = n) (P = P) (x = x) ? _??_248 (n = n) (P = P) (x = x))) =< Set (? ? ??) ? ? _??_239 (n = (suc n)) = ? ? _??_239 (n = n) ? _?_247 lsuc ?? ? _??_240 (n = (suc n)) = lsuc ?? ? _??_240 (n = n) ? lsuc _??_248 A.? ? _?_218 = A.? ? _?_218 ? _A.?_226 A.? ? _??_216 = A.? ? _??_216 ? _A.?_226 B.? ? _??_217 = B.? ? _??_217 ? _B.?_227 B.? ? _??_191 ? _B.?_199 = B.? ? _??_191 A.? ? _??_190 ? _A.?_198 = A.? ? _??_190 A.? ? _?_189 ? _A.?_198 = A.? ? _?_189 lsuc (lsuc lzero) ? _?_120 (f = f) = lsuc (lsuc lzero) ? _?_74 (f = f) ? _A.?_127 lsuc lzero ? _?_108 (f = f) = lsuc lzero ? _?_74 (f = f) ? _A.?_115 lsuc lzero ? _?_75 (f = f) ? _B.?_103 = lsuc lzero ? _?_98 (f = f) A.? ? _?_74 (f = f) = A.? ? _?_74 (f = f) ? _A.?_80 B.? ? _?_75 (f = f) ? _B.?_81 = B.? ? _?_75 (f = f) _?_52 (?? = (lsuc (lsuc (lsuc lzero)))) ? _?_58 = lsuc lzero _?_58 =< lsuc (lsuc (lsuc lzero)) _?_55 =< ?? ? ? ?? ? _?_52 (?? = ?) ? _?_55 = ?? ? _?_52 (?? = ?) ``` I don't have a very clear idea yet how big of an effort the level solver would be, but I expect it could be quite considerable. It will also depend a lot on how powerful we want the solver to be. One point of reference is the current size solver at https://github.com/agda/agda/blob/master/src/full/Agda/TypeChecking/SizedTypes, which is about 2000 lines (about half for the actual solver in WarshallSolver.hs and half the interface with the rest of Agda in Solver.hs). I would expect a solver for universe levels to be of a similar size. Ideally, both levels and sizes would make use of the *same* solver and only the interface with Agda would be different. Since you're a new contributor to Agda, my recommendation would be to start on something smaller to get a feeling for the Agda codebase. If you want to do this, here are some issues related to universe levels that currently need help: https://github.com/agda/agda/issues/4345, https://github.com/agda/agda/issues/4119, https://github.com/agda/agda/issues/3143. If you're keen to work on the solver and understand that it might be a lot of work, a good point to start would be to construct a few test cases that produce level constraints currently not solved by Agda. Two such test cases (that don't even use --cumulativity) are https://github.com/agda/agda/issues/3098 and https://github.com/agda/agda/issues/2246. I'm very glad to answer any questions you have while working on Agda! -- Jesper On Sun, Jan 5, 2020 at 11:53 PM Marko Dimja?evi? wrote: > Dear Agda developers, > > The upcoming Agda 2.6.1 release features universe cumulativity [1]. In > an email to the Agda users mailing list (agda at lists.chalmers.se), > Jesper Cockx said the following about cumulativity [2]: "If anyone is > interested in implementing a proper solver for universe levels, please > get in touch!" > > I am interested to work on this! > > Would anyone be so kind to say a bit more about the problem, the > current state of universe levels and of the cumulativity feature, which > is marked experimental? Furthermore, how big an effort to implement a > solver is considered to be? > > So far I made no coding contributions to Agda, though I've been a > Haskell developer. > > > [1] https://github.com/agda/agda/blob/release-2.6.1/CHANGELOG.md > [2] https://lists.chalmers.se/pipermail/agda/2020/011486.html > > > -- > Regards, > Marko Dimja?evi? > https://dimjasevic.net/marko > PGP key ID: 056E61A6F3B6C9323049DBF9565EE9641503F0AA > Learn email self-defense! https://emailselfdefense.fsf.org > > _______________________________________________ > Agda-dev mailing list > Agda-dev at lists.chalmers.se > https://lists.chalmers.se/mailman/listinfo/agda-dev > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marko at dimjasevic.net Tue Jan 7 20:47:24 2020 From: marko at dimjasevic.net (Marko =?UTF-8?Q?Dimja=C5=A1evi=C4=87?=) Date: Tue, 07 Jan 2020 20:47:24 +0100 Subject: [Agda-dev] Implementing a solver for universe levels In-Reply-To: References: <2f42b75db05971560650ae76b4dda5fe4f546c13.camel@dimjasevic.net> Message-ID: Dear Jesper, On Mon, 2020-01-06 at 10:26 +0100, Jesper Cockx wrote: > Since you're a new contributor to Agda, my recommendation would be to > start on something smaller to get a feeling for the Agda codebase. If > you want to do this, here are some issues related to universe levels > that currently need help: https://github.com/agda/agda/issues/4345, > https://github.com/agda/agda/issues/4119, > https://github.com/agda/agda/issues/3143. Thank you a lot for your detail reply! I will take your suggestion and start with a smaller task. In particular, if you are OK with it, I'd start off with https://github.com/agda/agda/issues/4345. I suppose these are the first and general things to understand for me: - https://github.com/agda/agda/blob/master/HACKING.md - https://github.com/andreasabel/haskell-style-guide/blob/master/haskell-style.md Do you have anything to add that is specific to issue 4345? -- Regards, Marko Dimja?evi? https://dimjasevic.net/marko PGP key ID: 056E61A6F3B6C9323049DBF9565EE9641503F0AA Learn email self-defense! https://emailselfdefense.fsf.org -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: This is a digitally signed message part URL: From Jesper at sikanda.be Tue Jan 7 20:15:12 2020 From: Jesper at sikanda.be (Jesper Cockx) Date: Tue, 7 Jan 2020 20:15:12 +0100 Subject: [Agda-dev] Implementing a solver for universe levels In-Reply-To: References: <2f42b75db05971560650ae76b4dda5fe4f546c13.camel@dimjasevic.net> Message-ID: Hi Marko, That's great to hear! Let's continue the discussion on the github page for that issue. -- Jesper On Tue, Jan 7, 2020 at 8:48 PM Marko Dimja?evi? wrote: > Dear Jesper, > > On Mon, 2020-01-06 at 10:26 +0100, Jesper Cockx wrote: > > Since you're a new contributor to Agda, my recommendation would be to > > start on something smaller to get a feeling for the Agda codebase. If > > you want to do this, here are some issues related to universe levels > > that currently need help: https://github.com/agda/agda/issues/4345, > > https://github.com/agda/agda/issues/4119, > > https://github.com/agda/agda/issues/3143. > > > Thank you a lot for your detail reply! > > I will take your suggestion and start with a smaller task. In > particular, if you are OK with it, I'd start off with > https://github.com/agda/agda/issues/4345. > > I suppose these are the first and general things to understand for me: > > - https://github.com/agda/agda/blob/master/HACKING.md > - > > https://github.com/andreasabel/haskell-style-guide/blob/master/haskell-style.md > > Do you have anything to add that is specific to issue 4345? > > > -- > Regards, > Marko Dimja?evi? > https://dimjasevic.net/marko > PGP key ID: 056E61A6F3B6C9323049DBF9565EE9641503F0AA > Learn email self-defense! https://emailselfdefense.fsf.org > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From guillaume.allais at ens-lyon.org Tue Jan 14 13:33:56 2020 From: guillaume.allais at ens-lyon.org (Guillaume Allais) Date: Tue, 14 Jan 2020 12:33:56 +0000 Subject: [Agda-dev] Fwd: [coqdev] Tabled typeclass resolution In-Reply-To: References: Message-ID: <04adddbb-7ed6-714d-b648-4b5d0d08511e@ens-lyon.org> This may be of interest to us too! -------- Forwarded Message -------- Subject: [coqdev] Tabled typeclass resolution Date: Tue, 14 Jan 2020 12:48:08 +0100 From: Gabriel Scherer Reply-To: Gabriel Scherer To: Coqdev Dear coqdev, The Lean implementers have a new arXiv submission on a "tabled" typeclass-resolution engine that avoids exponential blowups in cases of inheritance/implication diamonds. I thought this may be of interest to coqdev, as the approach could presumably also be applied to Coq's typeclasses. (See below for abstract.) The paper contains actual benchmarks that do exhibit bad behaviors of previous versions of Lean and Coq (Figure 4, page 15). One minor detail that I found interesting is that in the first "bad benchmark", the running times for Coq and Lean3 are extremely close together, which suggests that the Lean runtime is not noticeably faster by a not-1 constant factor (as one could maybe expect from the advertisement of a performance-focused C++ implementation). (In the second benchmark, Lean3 is noticeably faster than Coq.) Title: Tabled Typeclass Resolution Authors: Daniel Selsam, Sebastian Ullrich, Leonardo de Moura Categories: cs.PL cs.LO arXiv: https://arxiv.org/abs/2001.04301 PDF: https://arxiv.org/pdf/2001.04301 > > Typeclasses provide an elegant and effective way of managing ad-hoc > polymorphism in both programming languages and interactive proof > assistants. > However, the increasingly sophisticated uses of typeclasses within proof > assistants has exposed two critical problems with existing typeclass > resolution > procedures: the diamond problem, which causes exponential running times in > both > theory and practice, and the cycle problem, which causes loops in the > presence > of cycles and so thwarts many desired uses of typeclasses. We present a new > typeclass resolution procedure, called tabled typeclass resolution, that > solves > these problems. We have implemented our procedure for the upcoming version > (v4) > of the Lean Theorem Prover, and we confirm empirically that our > implementation > is exponentially faster than existing systems in the presence of diamonds. > Our > procedure is sufficiently lightweight that it could easily be implemented > in > other systems. We hope our new procedure facilitates even more > sophisticated > uses of typeclasses in both software development and interactive theorem > proving.