Invariant is a term used in computing which refers to an element that does not change over time or in response to outside influences. It is a concept used in software engineering, data modeling, and algorithm design, to describe and prove certain properties of a system or a subsystem within a system.
Invariants provide important ways to effectively reason about the behavior of a system, as they indicate objects that will stay the same regardless of the independent behavior of other objects or external influences. Invariants are used in a variety of programming languages, models, and approaches, from predicate logic to object-oriented programming.
Invariants provide a useful way to verify correctness of software or system design. They can also be used to find bugs that could cause problems in the execution of a program. In debugging a system, for example, invariants can help isolate a bug, as if the invariant is not satisfied, then the bug must be caused by the part of the system that is affected by it.
Invariants are also important in formal system specification, as they can be used to prove that a given system has certain desirable properties such as correctness, safety, security, or reliability. Invariants are used to describe any aspect of a system where a particular property is constant, including the function of a program or the color of an entity in a graphical user interface.
Invariants are often used in combination with other techniques for checking the correctness and reliability of software, including those involving assertion checking and theorem proving. Invariant checking is widely used in compilers, as it can help to statically verify the program code before runtime. It is also used in the development of more reliable systems, as it is possible to state some invariants of the system and then verify that these properties are preserved.