So I've come across the term invariants while reading the Assertions Java API. After I read the other articles on the net in my understanding invariants are tautologies. Did I misunderstand it?
Are invariants, tautologies?
227 views Asked by jantristanmilan At
3
There are 3 answers
0
On
Tautologies are statements that are always true. Invariants are statements that are intended to be true within a specific context.
Some invariants are not tautologies. For instance, in a programmed loop that adds 1 to i
each iteration and terminates when i=max
, you might declare an invariant like i < max
at the top of the loop. That is not a tautology because the condition is not universally true: there is no logical necessity about i
being less than max
. The intention is that it will be true each time a specific point is reached in the context of a specific computation.
Consider the difference between what a program ought to do, and what it actually does. If the program is correct, all the assertions are tautologies. If the program is faulty, they are not.