Render inverse functions in prose, without ^(-1) #109
Merged
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 rendering logic for inverse function applications.
When translating EL/IL to AL, we sometimes introduce inverse functions. For example when translating the dynamic semantics of
VBITMASK
instruction, AL introduces an inverse function$ibits_1^-1(32, $ilt($lsize(Jnn), S, ci_1, 0)*)
. In AL AST, it corresponds to the expression nodeInvCallE
.When rendering AL's
InvCallE
to EL'sCallE
, EL expects the function id to be of typestring
. So, the previous implementation passes stringibits^{-1}_{1}
to the EL renderer. This breaks the correspondence between what is seen in the prose and the formal mathematical rules.To properly render inverse functions newly introduced in AL, I can think of two solutions, where this PR implements the second one.
(1) Define the inverse function signatures in the spec watsup file and let display hints take care of the inverse signs.
For example, we can define
Then in the AL renderer, translate AL
InvCallE
onibits
to ELCallE
oninvibits
.This is easy to implement and the logic is clear, but the downside is that spec writers must be aware of the fact that when they are using functions that will turn out to be inversed after translation, they should define the inversed signature with proper display hints.
(2) Elaborate inverse function in prose
Or we can elaborate inverse function application in prose (English), for it is essentially solving an equation.
As in the actual prose, the renderer elaborates "Let ... be the result for which ... = ...".
Sometimes, inverse function application appears without a let binding, where the prose renderer introduces a fresh variable. For example the second premise in rule
Step_read/vload-splat-val
is rendered as:This is a more general solution than the first, but not sure if we all like the how the inverse function is elaborated prose.
I haven't implemented this in
al/print.ml
yet, it is only inbackend-prose/render.ml
now.