Add built-in natural numbers to Subst category #101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 modulon
. It is illegal forn
to be0
because arithmetic modulo 0 is unboundedNat
, which a circuit can't implement. (Another interpretation would be asFin 0
, which is isomorphic toVoid
, but that would be redundant as well as uninhabited.) The Idris code carries around a lot of proofs ofNonZero
to ensure exhaustion. The Lisp doesn't need to do that; it just needs to typecheckSubstN n
terms coming from the client to ensuren != 0
.SubstContradiction
yet.)eval
/curry
and similar routines related to the natural numbers is to recall the isomorphism betweenFin (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.)eval
/curry
are the trickiest routines, and require a number of utility routines to be factored out to make them readable.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.SubstMorphToSubstTerm
might be useful references for the semantics of an interpreter on the Lisp side.