Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
@rokopt
Copy link
Member Author

rokopt commented Aug 23, 2025

These changes have been merged into the terence/develop branch and have also had to have some updates to reflect more recent changes in the Idris-2 standard library, so I'm just going to close this PR and this code (in its more recent form) will go in whenever my current development branch is merged.

@rokopt rokopt closed this Aug 23, 2025
@rokopt rokopt deleted the terence/built-in-nat branch August 23, 2025 23:34
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.

2 participants