Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
if ((x*x & 1) == 0)
good_code
else
мусор
(Not(x) != x) : is always True (((x + -x) & 1) == 0) : is always True (Convert(Not(x)) != ((Convert(x) * 4) >> 2)) : is always True ((-x & 1) == (x & 1)) : is always True (((-x ^ x) & 1) == 0) : is always True (((x * 128) & 86) == 0) : is always True (Not((-x * 64)) != (x << 6)) : is always True ((Not((x * 128)) & 61) == 61) : is always False
Наша реализация генератора, к сожалению, не совсем идеальна
*Main> prove $ forAll_ test1 Falsifiable. Counter-example: s0 = 420228064 :: SInt32 (0.02 secs, 1032876 bytes)
*Main> prove $ forAll_ test2 Q.E.D. (0.01 secs, 1151920 bytes)
*Main> prove $ forAll_ test3 Q.E.D. (0.01 secs, 1128176 bytes)
*Main> prove $ forAll_ test4 Q.E.D. (0.01 secs, 1092956 bytes)
"(x3 | x2 | !x0) & (x3 | x2 | x1) & (x3 | x2 | x4) & (x3 | !x0 | x1) & (x3 | !x0 | x4) & (x3 | x1 | x4) & (x2 | !x0 | x1) & (x2 | !x0 | x4) & (x2 | x1 | x4) & (!x0 | x1 | x4) & (!x2 | !x1 | !x4) & (!x2 | !x1 | !x3) & (!x2 | !x1 | x0) & (!x2 | !x4 | !x3) & (!x2 | !x4 | x0) & (!x2 | !x3 | x0) & (!x1 | !x4 | !x3) & (!x1 | !x4 | x0) & (!x1 | !x3 | x0) & (!x4 | !x3 | x0)",
"(x2 | x1 | x0) & (x2 | x1 | x4) & (x2 | x1 | x3) & (x2 | x0 | x4) & (x2 | x0 | x3) & (x2 | x4 | x3) & (x1 | x0 | x4) & (x1 | x0 | x3) & (x1 | x4 | x3) & (x0 | x4 | x3) & (!x2 | !x4 | !x0) & (!x2 | !x4 | !x1) & (!x2 | !x4 | !x3) & (!x2 | !x0 | !x1) & (!x2 | !x0 | !x3) & (!x2 | !x1 | !x3) & (!x4 | !x0 | !x1) & (!x4 | !x0 | !x3) & (!x4 | !x1 | !x3) & (!x0 | !x1 | !x3)",
"(x1 | !x0 | !x2) & (x1 | !x0 | x4) & (x1 | !x0 | x3) & (x1 | !x2 | x4) & (x1 | !x2 | x3) & (x1 | x4 | x3) & (!x0 | !x2 | x4) & (!x0 | !x2 | x3) & (!x0 | x4 | x3) & (!x2 | x4 | x3) & (x0 | !x1 | !x4) & (x0 | !x1 | x2) & (x0 | !x1 | !x3) & (x0 | !x4 | x2) & (x0 | !x4 | !x3) & (x0 | x2 | !x3) & (!x1 | !x4 | x2) & (!x1 | !x4 | !x3) & (!x1 | x2 | !x3) & (!x4 | x2 | !x3)",
"(x0 | !x3 | x4) & (x0 | !x3 | x1) & (x0 | !x3 | x2) & (x0 | x4 | x1) & (x0 | x4 | x2) & (x0 | x1 | x2) & (!x3 | x4 | x1) & (!x3 | x4 | x2) & (!x3 | x1 | x2) & (x4 | x1 | x2) & (!x0 | !x2 | x3) & (!x0 | !x2 | !x1) & (!x0 | !x2 | !x4) & (!x0 | x3 | !x1) & (!x0 | x3 | !x4) & (!x0 | !x1 | !x4) & (!x2 | x3 | !x1) & (!x2 | x3 | !x4) & (!x2 | !x1 | !x4) & (x3 | !x1 | !x4)",
"(!x0 | !x3 | x1) & (!x0 | !x3 | x4) & (!x0 | !x3 | !x2) & (!x0 | x1 | x4) & (!x0 | x1 | !x2) & (!x0 | x4 | !x2) & (!x3 | x1 | x4) & (!x3 | x1 | !x2) & (!x3 | x4 | !x2) & (x1 | x4 | !x2) & (x0 | x2 | !x1) & (x0 | x2 | !x4) & (x0 | x2 | x3) & (x0 | !x1 | !x4) & (x0 | !x1 | x3) & (x0 | !x4 | x3) & (x2 | !x1 | !x4) & (x2 | !x1 | x3) & (x2 | !x4 | x3) & (!x1 | !x4 | x3)",
"(!x0 | x1 | x3) & (!x0 | x1 | x4) & (!x0 | x1 | x2) & (!x0 | x3 | x4) & (!x0 | x3 | x2) & (!x0 | x4 | x2) & (x1 | x3 | x4) & (x1 | x3 | x2) & (x1 | x4 | x2) & (x3 | x4 | x2) & (x0 | !x4 | !x3) & (x0 | !x4 | !x1) & (x0 | !x4 | !x2) & (x0 | !x3 | !x1) & (x0 | !x3 | !x2) & (x0 | !x1 | !x2) & (!x4 | !x3 | !x1) & (!x4 | !x3 | !x2) & (!x4 | !x1 | !x2) & (!x3 | !x1 | !x2)"*Main> prove $ forAll_ (fermat :: SInt32 -> SInt32 -> SInt32 -> SBool) Falsifiable. Counter-example: s0 = -655189642 :: SInt32 s1 = 125895093 :: SInt32 s2 = 1609826051 :: SInt32 (3.12 secs, 1094592 bytes)
*Main> prove $ forAll_ (fermat :: SInt64 -> SInt64 -> SInt64 -> SBool) Falsifiable. Counter-example: s0 = -6515675963299228301 :: SInt64 s1 = 6034959013475051589 :: SInt64 s2 = 2466979131238012272 :: SInt64 (15.38 secs, 1939316 bytes)
*Main> prove $ forAll_ (fermat :: SWord32 -> SWord32 -> SWord32 -> SBool) Falsifiable. Counter-example: s0 = 3639777654 :: SWord32 s1 = 125895093 :: SWord32 s2 = 1609826051 :: SWord32 (3.75 secs, 1095380 bytes)
*Main> prove $ forAll_ (fermat :: SWord64 -> SWord64 -> SWord64 -> SBool) Falsifiable. Counter-example: s0 = 11931068110410323315 :: SWord64 s1 = 6034959013475051589 :: SWord64 s2 = 2466979131238012272 :: SWord64 (14.82 secs, 1159580 bytes)
Но не спешите. Диофантово уравнение – это вовсе не набор сумм и произведений интов со значениями от 0 до 4 млрд, а набор сумм и произведений целых чисел со значениями от 0 до бесконечности.
В коде таких предикатов сотни тысяч, 3-5 секунд на штуку — заведомо не приемлимое время (в случае реального применения).
Неразрешимость будет, если память бесконечна.
Я уверен, что подавляющее большинство случайных предикатов решается на ура.
Неявные предикаты