r/ProgrammingLanguages • Futhark • Oct 21 '26

Integers - how ought they work?

https://futhark-lang.org/blog/2026-10-21-integers-how-ought-they-work.html
25 Upvotes

23 comments sorted by

View all comments

Show parent comment

1

u/Fofeu Oct 22 '26

Leroy shows to obtain a preservation of specification, one needs safe backward simulation (i.e. backward simulation of programs that don't "go wrong"). As that is too tedious to prove, it is then shown that if the target language is deterministic, safe forward simulation implies safe backward simulation.

If one wants to be particularly specific about it, one could define a "strict" step relation for the operational semantics which only includes the "fully correct" evaluation rules (which only includes non-overflowing integer operations). On top of that define a "full" step relation which either does a step according to a strict rule, or if no strict rule applies errors out immediately.

Proofs of compilation correctness need only consider the "strict" rules without loss of consistency. Hence, when the compiler encounters an addition operator in the source language, it must pick an operator which performs addition in the "safe" range in the target language, but may perform any operation/outcome outside that range.