Whiley / WhileyTheoremProver

The Whiley Theorem Prover (WyTP) is an automatic and interactive theorem prover designed to discharge verification conditions generated by the Whiley Compiler. WyTP operates over a variant of first-order logic which includes integer arithmetic, arrays and quantification.
Apache License 2.0
8 stars 2 forks source link

Unknown Assertion Failure #89

Open DavePearce opened 7 years ago

DavePearce commented 7 years ago

The following fails for reasons unknown:

define invertByte_loopinvariant_51(bool[] bits, int i, bool[] ret) is:
    forall(int j).(((0 <= j) && (j < i)) ==> (ret[j] == !bits[j]))

assert "loop invariant not restored":
    forall(bool[] bits, bool[] before, bool[] after, int i):
        if:
            invertByte_loopinvariant_51(bits, i, before)
            after == before[i:=!bits[i]]
        then:
            invertByte_loopinvariant_51(bits, i+1, after)

The (somewhat ridiculous) proof for this is:

 128. exists(bool[] bits, bool[] before, bool[] after, int i).(((invertByte_ () 
 139. exists(bool[] bits, bool[] before, bool[] after, int i).((inve (Simp 128) 
 138. (invertByte_loopinvariant_51(bits, i, before) && (after == (Exists-E 139) 
 134. invertByte_loopinvariant_51(bits, i, before) && (after == bef (And-E 138) 
 137. !invertByte_loopinvariant_51(bits, 1 + i, after)              (And-E 138) 
 114. invertByte_loopinvariant_51(bits, i, before)                  (And-E 134) 
 133. after == before[i:=true != bits[i]]                           (And-E 134) 
 157. exists(int j).(((((j + 1) >= (0 + 1)) && (((1 + i) + 1) >=  (Macro-I 137) 
 172. forall(int j).((((0 >= (j + 1)) || ((j + 1) >= (i + 1))) || (Macro-I 114) 
 174. !invertByte_loopinvariant_51(bits, 1 + i, before[i:=true ! (Eq-S 137,133) 
 181. exists(int j).(((j >= 0) && (i >= j)) && ((true != bits[j]) != (Simp 157) 
 189. forall(int j).(((0 >= (1 + j)) || (j >= i)) || ((true != bits[ (Simp 172) 
 205. exists(int j).(((((j + 1) >= (0 + 1)) && (((1 + i) + 1) >=  (Macro-I 174) 
 209. exists(int j).(((j >= 0) && (i >= j)) && ((true != bits[j] (Eq-S 181,133) 
 216. exists(int j).(((j >= 0) && (i >= j)) && ((true != bits[j]) != (Simp 205) 
 208. ((j >= 0) && (i >= j)) && ((true != bits[j]) != before[i:= (Exists-E 209) 
 215. ((j >= 0) && (i >= j)) && ((true != bits[j]) != before[i:= (Exists-E 216) 
 177. (j >= 0) && (i >= j)                                          (And-E 208) 
 207. (true != bits[j]) != before[i:=true != bits[i]][j]            (And-E 208) 
 212. (j >= 0) && (i >= j)                                          (And-E 215) 
 214. (true != bits[j]) != before[i:=true != bits[i]][j]            (And-E 215) 
 175. j >= 0                                                        (And-E 177) 
 176. i >= j                                                        (And-E 177) 
 224. ((i == j) && ((true != bits[j]) != (true != bits[i]))) ||  (ArrInd-C 207) 
 210. j >= 0                                                        (And-E 212) 
 211. i >= j                                                        (And-E 212) 
 232. ((i == j) && ((true != bits[j]) != (true != bits[i]))) ||  (ArrInd-C 214) 
 233. i >= 0                                                    (Ieq-I 176,175) 
 236. ((i == j) && ((true != bits[i]) != (true != bits[j]))) || ((i  (Simp 224) 
 239. ((i == j) && ((true != bits[i]) != (true != bits[j]))) || ((i  (Simp 232) 
┌──────────────────────────────────────────────────────────────────────────────┐
│ 235. (i == j) && ((true != bits[i]) != (true != bits[j]))         (Or-E 236) │
│ 217. i == j                                                      (And-E 235) │
│ 234. (true != bits[i]) != (true != bits[j])                      (And-E 235) │
│ 251. (true != bits[j]) != (true != bits[j])                   (Eq-S 234,217) │
│ 104. false                                                        (Simp 251) │
├──────────────────────────────────────────────────────────────────────────────┤
│ 223. (i != j) && ((true != bits[j]) != before[j])                 (Or-E 236) │
│┌─────────────────────────────────────────────────────────────────────────────┤
││ 238. (i == j) && ((true != bits[i]) != (true != bits[j]))        (Or-E 239) │
││ 225. i == j                                                     (And-E 238) │
││ 237. (true != bits[i]) != (true != bits[j])                     (And-E 238) │
││ 252. (true != bits[j]) != (true != bits[j])                  (Eq-S 237,225) │
││ 104. false                                                       (Simp 252) │
│├─────────────────────────────────────────────────────────────────────────────┤
││ 231. (i != j) && ((true != bits[j]) != before[j])                (Or-E 239) │
││ 220. i != j                                                     (And-E 223) │
││ 222. (true != bits[j]) != before[j]                             (And-E 223) │
││ 228. i != j                                                     (And-E 231) │
││ 230. (true != bits[j]) != before[j]                             (And-E 231) │
││ 255. (j >= (i + 1)) || (i >= (j + 1))                           (Neq-C 220) │
││ 261. ((true == bits[j]) && (before[j] == true)) || ((true != bi (Neq-C 222) │
││ 285. (j >= (i + 1)) || (i >= (j + 1))                           (Neq-C 228) │
││ 291. ((true == bits[j]) && (before[j] == true)) || ((true != bi (Neq-C 230) │
││ 274. (j >= (1 + i)) || (i >= (1 + j))                            (Simp 255) │
││ 279. ((true == bits[j]) && (true == before[j])) || ((true != bit (Simp 261) │
││ 295. (j >= (1 + i)) || (i >= (1 + j))                            (Simp 285) │
││ 300. ((true == bits[j]) && (true == before[j])) || ((true != bit (Simp 291) │
││┌────────────────────────────────────────────────────────────────────────────┤
│││ 271. j >= (1 + i)                                               (Or-E 274) │
│││ 304. (-1 + j) >= j                                         (Ieq-I 271,176) │
│││ 104. false                                                      (Simp 304) │
││├────────────────────────────────────────────────────────────────────────────┤
│││ 273. i >= (1 + j)                                               (Or-E 274) │
│││┌───────────────────────────────────────────────────────────────────────────┤
││││ 276. (true == bits[j]) && (true == before[j])                  (Or-E 279) │
││││┌──────────────────────────────────────────────────────────────────────────┤
│││││ 292. j >= (1 + i)                                             (Or-E 295) │
│││││ 310. (-1 + j) >= j                                       (Ieq-I 292,211) │
│││││ 104. false                                                    (Simp 310) │
││││├──────────────────────────────────────────────────────────────────────────┤
│││││ 294. i >= (1 + j)                                             (Or-E 295) │
│││││┌─────────────────────────────────────────────────────────────────────────┤
││││││ 297. (true == bits[j]) && (true == before[j])                (Or-E 300) │
││││││ 313. (-1 + i) >= 0                                      (Ieq-I 273,175) │
││││││ 256. true == bits[j]                                        (And-E 276) │
││││││ 275. true == before[j]                                      (And-E 276) │
││││││ 286. true == bits[j]                                        (And-E 297) │
││││││ 296. true == before[j]                                      (And-E 297) │
││││││ 315. i >= 1                                                  (Simp 313) │
││││││ 317. (true != true) != before[j]                         (Eq-S 222,256) │
││││││ 322. (true && (bits[j] == true)) || (false && (bits[j] != t (Neq-C 256) │
││││││ 323. (true != bits[j]) != true                           (Eq-S 222,275) │
││││││ 326. (true && (before[j] == true)) || (false && (before[j]  (Neq-C 275) │
││││││ 328. (true != true) != before[j]                         (Eq-S 230,286) │
││││││ 333. (true && (bits[j] == true)) || (false && (bits[j] != t (Neq-C 286) │
││││││ 334. (true != bits[j]) != true                           (Eq-S 230,296) │
││││││ 337. (true && (before[j] == true)) || (false && (before[j]  (Neq-C 296) │
││││││ 338. false != before[j]                                      (Simp 317) │
││││││ 341. (true && (true == bits[j])) || (false && (true != bits[ (Simp 322) │
││││││ 342. true != (true != bits[j])                               (Simp 323) │
││││││ 345. (true && (true == before[j])) || (false && (true != bef (Simp 326) │
││││││ 346. false != before[j]                                      (Simp 328) │
││││││ 349. (true && (true == bits[j])) || (false && (true != bits[ (Simp 333) │
││││││ 350. true != (true != bits[j])                               (Simp 334) │
││││││ 353. (true && (true == before[j])) || (false && (true != bef (Simp 337) │
││││││┌────────────────────────────────────────────────────────────────────────┤
│││││││ 339. true && (true == bits[j])                              (Or-E 341) │
│││││││ 354. (false && (true != bits[j])) || (true && (true == bit (Neq-C 342) │
│││││││┌───────────────────────────────────────────────────────────────────────┤
││││││││ 343. true && (true == before[j])                           (Or-E 345) │
││││││││┌──────────────────────────────────────────────────────────────────────┤
│││││││││ 347. true && (true == bits[j])                            (Or-E 349) │
│││││││││ 355. (false && (true != bits[j])) || (true && (true == b (Neq-C 350) │
│││││││││┌─────────────────────────────────────────────────────────────────────┤
││││││││││ 351. true && (true == before[j])                         (Or-E 353) │
││││││││││ 130. true                                               (And-E 339) │
││││││││││┌────────────────────────────────────────────────────────────────────┤
│││││││││││ 340. false && (true != bits[j])                         (Or-E 354) │
│││││││││││ 104. false                                             (And-E 340) │
││││││││││├────────────────────────────────────────────────────────────────────┤
│││││││││││┌───────────────────────────────────────────────────────────────────┤
││││││││││││ 348. false && (true != bits[j])                        (Or-E 355) │
││││││││││││ 104. false                                            (And-E 348) │
│││││││││││├───────────────────────────────────────────────────────────────────┤
│││││││││││└───────────────────────────────────────────────────────────────────┤
││││││││││└────────────────────────────────────────────────────────────────────┤
│││││││││├─────────────────────────────────────────────────────────────────────┤
││││││││││ 352. false && (true != before[j])                        (Or-E 353) │
│││││││││└─────────────────────────────────────────────────────────────────────┤
││││││││├──────────────────────────────────────────────────────────────────────┤
│││││││││ 348. false && (true != bits[j])                           (Or-E 349) │
││││││││└──────────────────────────────────────────────────────────────────────┤
│││││││├───────────────────────────────────────────────────────────────────────┤
││││││││ 344. false && (true != before[j])                          (Or-E 345) │
│││││││└───────────────────────────────────────────────────────────────────────┤
││││││├────────────────────────────────────────────────────────────────────────┤
│││││││ 340. false && (true != bits[j])                             (Or-E 341) │
││││││└────────────────────────────────────────────────────────────────────────┤
│││││├─────────────────────────────────────────────────────────────────────────┤
││││││ 299. (true != bits[j]) && (true != before[j])                (Or-E 300) │
│││││└─────────────────────────────────────────────────────────────────────────┤
││││└──────────────────────────────────────────────────────────────────────────┤
│││├───────────────────────────────────────────────────────────────────────────┤
││││ 278. (true != bits[j]) && (true != before[j])                  (Or-E 279) │
│││└───────────────────────────────────────────────────────────────────────────┤
││└────────────────────────────────────────────────────────────────────────────┤
│└─────────────────────────────────────────────────────────────────────────────┤
└──────────────────────────────────────────────────────────────────────────────┘

The generation of 207. (true != bits[j]) != before[i:=true != bits[i]][j] is somewhat suspect.

DavePearce commented 7 years ago

UPDATE: this version where I've replaced bool with int does indeed verify:

define invertByte_loopinvariant_51(int[] bits, int i, int[] ret) is:
    forall(int j):
        if:
            (0 <= j) && (j < i)
        then:
            ret[j] == -(bits[j])

assert "loop invariant not restored":
    forall(int[] bits, int[] before, int[] after, int i):
        if:
            invertByte_loopinvariant_51(bits, i, before)
            after == before[i:=-(bits[i])]
        then:
            invertByte_loopinvariant_51(bits, i+1, after)

The generated proof is also quite large:

 130. exists(int[] bits, int[] before, int[] after, int i).(((invertByte_loo () 
 141. exists(int[] bits, int[] before, int[] after, int i).((invertB (Simp 130) 
 140. (invertByte_loopinvariant_51(bits, i, before) && (after == (Exists-E 141) 
 136. invertByte_loopinvariant_51(bits, i, before) && (after == bef (And-E 140) 
 139. !invertByte_loopinvariant_51(bits, 1 + i, after)              (And-E 140) 
 116. invertByte_loopinvariant_51(bits, i, before)                  (And-E 136) 
 135. after == before[i:=-1 * bits[i]]                              (And-E 136) 
 178. forall(int j).(((((0 >= (j + 1)) || ((j + 1) >= (i + 1))))  (Macro-I 116) 
 180. !invertByte_loopinvariant_51(bits, 1 + i, before[i:=-1 * b (Eq-S 139,135) 
 195. forall(int j).(((0 >= (1 + j)) || (j >= i)) || (0 == (before[j (Simp 178) 
 213. exists(int j).((((((j + 1) >= (0 + 1)) && (((1 + i) + 1) >= (Macro-I 180) 
 225. exists(int j).(((j >= 0) && (i >= j)) && (0 != (bits[j] + befo (Simp 213) 
 224. ((j >= 0) && (i >= j)) && (0 != (bits[j] + before[i:=-1 *  (Exists-E 225) 
 221. (j >= 0) && (i >= j)                                          (And-E 224) 
 223. 0 != (bits[j] + before[i:=-1 * bits[i]][j])                   (And-E 224) 
 219. j >= 0                                                        (And-E 221) 
 220. i >= j                                                        (And-E 221) 
 239. ((i == j) && (0 != (bits[j] + (-1 * bits[i])))) || ((i !=  (ArrInd-C 223) 
 256. ((i == j) && (bits[i] != bits[j])) || ((i != j) && (0 != (befo (Simp 239) 
┌──────────────────────────────────────────────────────────────────────────────┐
│ 252. (i == j) && (bits[i] != bits[j])                             (Or-E 256) │
│ 230. i == j                                                      (And-E 252) │
│ 251. bits[i] != bits[j]                                          (And-E 252) │
│ 275. bits[j] != bits[j]                                       (Eq-S 251,230) │
│ 106. false                                                        (Simp 275) │
├──────────────────────────────────────────────────────────────────────────────┤
│ 255. (i != j) && (0 != (before[j] + bits[j]))                     (Or-E 256) │
│ 234. i != j                                                      (And-E 255) │
│ 254. 0 != (before[j] + bits[j])                                  (And-E 255) │
│ 281. (j >= (i + 1)) || (i >= (j + 1))                            (Neq-C 234) │
│ 285. ((before[j] + bits[j]) >= (0 + 1)) || (0 >= ((before[j] + b (Neq-C 254) │
│ 299. (j >= (1 + i)) || (i >= (1 + j))                             (Simp 281) │
│ 303. ((before[j] + bits[j]) >= 1) || (0 >= (1 + before[j] + bits[ (Simp 285) │
│┌─────────────────────────────────────────────────────────────────────────────┤
││ 296. j >= (1 + i)                                                (Or-E 299) │
││ 323. (-1 + j) >= j                                          (Ieq-I 296,220) │
││ 106. false                                                       (Simp 323) │
│├─────────────────────────────────────────────────────────────────────────────┤
││ 298. i >= (1 + j)                                                (Or-E 299) │
││┌────────────────────────────────────────────────────────────────────────────┤
│││ 300. (before[j] + bits[j]) >= 1                                 (Or-E 303) │
│││ 331. ((0 >= (1 + j)) || (j >= i)) || (0 == (before[j] + (Forall-I 195,300) │
│││┌───────────────────────────────────────────────────────────────────────────┤
││││ 329. (0 >= (1 + j)) || (j >= i)                                (Or-E 331) │
││││┌──────────────────────────────────────────────────────────────────────────┤
│││││ 327. 0 >= (1 + j)                                             (Or-E 329) │
│││││ 346. -1 >= 0                                             (Ieq-I 327,219) │
│││││ 106. false                                                    (Simp 346) │
││││├──────────────────────────────────────────────────────────────────────────┤
│││││ 328. j >= i                                                   (Or-E 329) │
│││││ 348. j >= (1 + j)                                        (Ieq-I 328,298) │
│││││ 106. false                                                    (Simp 348) │
││││└──────────────────────────────────────────────────────────────────────────┤
│││├───────────────────────────────────────────────────────────────────────────┤
││││ 330. 0 == (before[j] + bits[j])                                (Or-E 331) │
││││ 355. (before[j] + (-1 * before[j])) >= 1                   (Eq-S 300,330) │
││││ 106. false                                                     (Simp 355) │
│││└───────────────────────────────────────────────────────────────────────────┤
││├────────────────────────────────────────────────────────────────────────────┤
│││ 302. 0 >= (1 + before[j] + bits[j])                             (Or-E 303) │
│││ 331. ((0 >= (1 + j)) || (j >= i)) || (0 == (before[j] + (Forall-I 195,302) │
│││┌───────────────────────────────────────────────────────────────────────────┤
││││ 329. (0 >= (1 + j)) || (j >= i)                                (Or-E 331) │
││││┌──────────────────────────────────────────────────────────────────────────┤
│││││ 327. 0 >= (1 + j)                                             (Or-E 329) │
│││││ 346. -1 >= 0                                             (Ieq-I 327,219) │
│││││ 106. false                                                    (Simp 346) │
││││├──────────────────────────────────────────────────────────────────────────┤
│││││ 328. j >= i                                                   (Or-E 329) │
│││││ 348. j >= (1 + j)                                        (Ieq-I 328,298) │
│││││ 106. false                                                    (Simp 348) │
││││└──────────────────────────────────────────────────────────────────────────┤
│││├───────────────────────────────────────────────────────────────────────────┤
││││ 330. 0 == (before[j] + bits[j])                                (Or-E 331) │
││││ 357. 0 >= (1 + before[j] + (-1 * before[j]))               (Eq-S 302,330) │
││││ 106. false                                                     (Simp 357) │
│││└───────────────────────────────────────────────────────────────────────────┤
││└────────────────────────────────────────────────────────────────────────────┤
│└─────────────────────────────────────────────────────────────────────────────┤
└──────────────────────────────────────────────────────────────────────────────┘

Why is this proof so large?