-
Notifications
You must be signed in to change notification settings - Fork 0
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
Program equivalence for Core.Main #2
Draft
lukaszcz
wants to merge
32
commits into
main
Choose a base branch
from
program-equivalence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lukaszcz
force-pushed
the
main
branch
2 times, most recently
from
January 15, 2025 10:03
6a6cb47
to
2a00051
Compare
lukaszcz
force-pushed
the
program-equivalence
branch
from
January 15, 2025 10:07
fb63d0c
to
a58da50
Compare
lukaszcz
changed the title
Program equivalence for Juvix.Core.Main
Program equivalence for Core.Main
Jan 15, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Defines step-indexed approximation and equivalence relations, sound for contextual approximation and equivalence, respectively. The steps count the nesting of executed function/constructor applications and recursion (letrec) unfoldings.
Work in progress. The current definitions are not yet correct, but I've worked out a plan to proceed with basic definitions and high-level proofs checked on paper.
Background
First of all, with functions as values represented syntactically (by a closure: expression + environment), the desired equivalence relation on values cannot simply compare them for exact equality. We would like two closures (function values) to be equivalent when they behave in the same way for all admissible arguments, not only when their concrete representations are literally equal.
A correct way to define program equivalence is by contextual equivalence. A context is an expression with exactly one hole. By$C[e]$ we denote the expression obtained by substituting the hole in the context $C$ with the expression $e$ . An expression $e_1$ contextually approximates an expression $e_2$ , denoted $e_1 \lesssim^c e_2$ , if for every context $C$ and environment $E$ such that $E \vdash C[e_1] \downarrow$ (i.e. $C[e_1]$ evaluates to a value in environment $E$ ), we have $E \vdash C[e_2] \downarrow$ . Intuitively, $e_1 \lesssim^c e_2$ means that $e_1$ may always be replaced by $e_2$ preserving the evaluation result (program meaning). Two expressions $e_1, e_2$ are contextually equivalent if $e_1 \lesssim^c e_2$ and $e_2 \lesssim^c e_1$ .
Contextual equivalence essentially states that the programs (expressions) cannot be distinguished by any other program (context). This is the desired notion of program equivalence, but it is hard to work with because the definition requires reasoning about arbitrary contexts.
To prove equivalence of concrete expressions, we would like to have a more "structural" version of program equivalence, defined along the following lines. An expression$e_1$ is an approximation of $e_2$ , denoted $e_1 \lesssim e_2$ , if for every environment $E$ and value $v_1$ such that $E \vdash e_1 \mapsto v_1$ (i.e. $e_1$ evaluates to $v_1$ in environment $E$ ), there exists a value $v_2$ such that $E \vdash e_2 \mapsto v_2$ and $v_1 \lesssim_v v_2$ (value approximation). A value $v_1$ approximates value $v_2$ , denoted $v_1 \lesssim_v v_2$ , if:
With such a definition, proving program equivalence for concrete expressions is more manageable.
However, the "definition" as stated above is not well-founded:$\lesssim_v$ occurs negatively in $a_1 \lesssim_v a_2$ . We cannot replace $a_1 \lesssim_v a_2$ by $a_1 = a_2$ , because then we would not be able to prove that our approximation implies contextual approximation. A solution is to index $\lesssim_v$ by an appropriately defined number of execution steps: $v_1 \lesssim_v^k v_2$ means that $v_1$ approximates $v_2$ in no more than $k$ program execution steps. We ensure the step index $k$ decreases when referring to $\lesssim_v^k$ recursively in its definition.
The general technique of step-indexing is well-established [1, 2], but it needs to be adapted to the particular case of JuvixCore and its evaluation semantics. This adaptation is not straightforward.
Checklist
letrec
. Replace global identifiers withletrec
.References