The Jargon “Invariant” in Programing Language

By Xah Lee. Date: .

1, i don't know when did it happen, but the term “invariant” is beginning to pop up in programing language community.

2, “invariant” in programing language means, something assumed to be true. e.g. say power(n,m), it is assumed that n and m are number type.

3, programing language “invariant”, e.g. hashtable, access is assumed to be fast constant time for any key.

4, i first saw this use of “invariant” is in JavaScript spec es2015. e.g. ECMAScript 2015 §ECMAScript Language: Expressions#sec-equality-operators-runtime-semantics-evaluation

5, practically, “invariant” means something that's implicitly assumed, but now explicit just so its clear, e.g. in lang spec context.

6, today i saw “invariant” mentioned in esr's golang vs rust essay https://blog.ntpsec.org/2017/01/18/rust-vs-go.html

7, it's interesting because the jargon “invariant” is probably borrowed from math geometry, but math invariant is rather of different nature.

8, “invariant” in math is mostly from geometry, it means properties that never change under transformation.

9, #geometry, when a set X of properties never change under under transformation Y, the X is called INVARIANTs of Y.

10, so you see? math's “invariant” isn't programing language's “invariant”. It's not about something implicitly assumed to be true.