Skip to content
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

Add built-in natural numbers to Subst category #101

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rokopt
Copy link
Member

@rokopt rokopt commented Apr 26, 2023

This PR adds to Idris-2's model SubstObjMu/SubstMorph category an implementation of built-in natural numbers, which could be ported to Lisp for the real implementation; I've tried to spell out implicit parameters and avoid inferring parameters to make that easier. Some notes:

  • SubstN n is arithmetic modulo n. It is illegal for n to be 0 because arithmetic modulo 0 is unbounded Nat, which a circuit can't implement. (Another interpretation would be as Fin 0, which is isomorphic to Void, but that would be redundant as well as uninhabited.) The Idris code carries around a lot of proofs of NonZero to ensure exhaustion. The Lisp doesn't need to do that; it just needs to typecheck SubstN n terms coming from the client to ensure n != 0.
  • There are many utility functions implemented in the Idris that I've updated for this checkin but that don't exist in the Lisp yet. Unless they're specifically referred to by changes to functions that are implemented in the Lisp, we don't need to bring them over (at least not yet), but they're there to refer to if and when we do. (For example, I don't think that we use the cardinality- and depth-calculating utility functions in Lisp yet, though I might be wrong. I'm pretty sure we don't use, or need, notions such as SubstContradiction yet.)
  • A guideline when implementing eval/curry and similar routines related to the natural numbers is to recall the isomorphism between Fin (S n) and (coprod so1 (Fin n)). The details will be different (using built-in natural-number equality statements instead of case decomposition, for example), but this can guide the semantics. (This should all be figured out in the Idris -- I'm not saying that this is left to figure out when porting to Lisp, just that this might help understanding what the code is doing.)
  • As usual, eval/curry are the trickiest routines, and require a number of utility routines to be factored out to make them readable.
  • I don't think that we're using soSubst/soReduce in the Lisp yet, and for that matter I'm not yet using them anywhere else even in the Idris, but some parts of them might be useful as guides to writing reductions.
  • Similarly, routines such as SubstMorphToSubstTerm might be useful references for the semantics of an interpreter on the Lisp side.

@rokopt rokopt requested review from agureev and mariari April 26, 2023 06:14
@rokopt
Copy link
Member Author

rokopt commented Apr 27, 2023

Note: this is the Idris-2 model intended to be ported to Lisp to address #61 .

@rokopt
Copy link
Member Author

rokopt commented Apr 28, 2023

Should we merge this so that there's a model for the Lisp natural number implementation in the main branch?

@mariari mariari force-pushed the terence/built-in-nat branch from dd0501d to 1853dd9 Compare May 7, 2023 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant