if (x >= 0) {
x += 10
if (x =< 9) {
// unreachable
}
}
By maintaining an interval of possible values of x, you can detect the unreachable branch, because the interval becomes empty: initial: [-oo, oo]
x >= 0 : [0, oo]
x += 10: [10, oo]
x =< 9 : [10, 9] (empty)The police measure the distance my car travelled [ 99.9, 100.1 ] m and the time it took [ 3.3, 3.4 ] s - how fast was my car going? [29.38, 30.33] m/s according to the interval calculator.
Physics students learn exactly this method before they move on to more sophisticated analysis with error distributions.
The interval abstract domain works under interval analysis with an algebra that’s the same of this calculator. It’s funny to implement something like that on source/binary level :)