I would like to try some different proofs, specifically in proving equivalence of the implementation of some feature in two different programming languages (C and JS in this question).
This is about proving that replacing one character in a string is equivalent in C and JS.
In JS, for example, strings are immutable, while in C, strings are mutable. So in JS you might have to do this:
functioni replaceAt(string, index, replacement) {
return string.substr(0, index) + replacement + string.substr(index + replacement.length)
}
While in C you might just do something like this:
#include<stdio.h>
int
main() {
char string[11] = "hello world";
string[1] = 'i';
printf("%s", string);
return 0;
}
Basically, I am trying to come up with an example where, the perceived effect or desired outcome is for all intents and purposes the same. That is, the end result is that the character was replaced at a specific position (the same position in each language). Even though in one language the string was mutable, while in the other, it was immutable. What needs to be taken into account here to make a proof saying these are equivalent? How do we capture the notion of "partial equivalence" or "perceived equivalence"? (By that I mean, the outcome is roughly the same, so we want to make a proof statement that these are the same with regard to some spec).
char string[12]
orchar string[]
to account for the null terminator. Note thatchar *string
would also be undefined behavior. $\endgroup$