1028 code_pred [inductify] inv_image . |
1021 code_pred [inductify] inv_image . |
1029 thm inv_image.equation |
1022 thm inv_image.equation |
1030 |
1023 |
1031 subsection {* Inverting list functions *} |
1024 subsection {* Inverting list functions *} |
1032 |
1025 |
1033 (*code_pred [inductify] length . |
1026 code_pred [inductify] size_list . |
1034 code_pred [random inductify] length . |
1027 code_pred [new_random_dseq inductify] size_list . |
1035 thm size_listP.equation |
1028 thm size_listP.equation |
1036 thm size_listP.random_equation |
1029 thm size_listP.new_random_dseq_equation |
1037 *) |
1030 |
1038 (*values [random] 1 "{xs. size_listP (xs::nat list) (5::nat)}"*) |
1031 values [new_random_dseq 2,3,10] 3 "{xs. size_listP (xs::nat list) (5::nat)}" |
1039 |
1032 |
1040 code_pred (expected_modes: i => o => bool, o => i => bool, i => i => bool) [inductify, skip_proof] List.concat . |
1033 code_pred (expected_modes: i => o => bool, o => i => bool, i => i => bool) [inductify, skip_proof] List.concat . |
1041 thm concatP.equation |
1034 thm concatP.equation |
1042 |
1035 |
1043 values "{ys. concatP [[1, 2], [3, (4::int)]] ys}" |
1036 values "{ys. concatP [[1, 2], [3, (4::int)]] ys}" |
1273 code_pred eval_var . |
1268 code_pred eval_var . |
1274 thm eval_var.equation |
1269 thm eval_var.equation |
1275 |
1270 |
1276 values "{val. eval_var (Add (IrConst 1) (IrConst 2)) (| Env = (\<lambda>x. 0)|) val}" |
1271 values "{val. eval_var (Add (IrConst 1) (IrConst 2)) (| Env = (\<lambda>x. 0)|) val}" |
1277 |
1272 |
|
1273 section {* Function predicate replacement *} |
|
1274 |
|
1275 text {* |
|
1276 If the mode analysis uses the functional mode, we |
|
1277 replace predicates that resulted from functions again by their functions. |
|
1278 *} |
|
1279 |
|
1280 inductive test_append |
|
1281 where |
|
1282 "List.append xs ys = zs ==> test_append xs ys zs" |
|
1283 |
|
1284 code_pred [inductify, skip_proof] test_append . |
|
1285 thm test_append.equation |
|
1286 |
|
1287 text {* If append is not turned into a predicate, then the mode |
|
1288 o => o => i => bool could not be inferred. *} |
|
1289 |
|
1290 values 4 "{(xs::int list, ys). test_append xs ys [1, 2, 3, 4]}" |
|
1291 |
|
1292 text {* If appendP is not reverted back to a function, then mode i => i => o => bool |
|
1293 fails after deleting the predicate equation. *} |
|
1294 |
|
1295 declare appendP.equation[code del] |
|
1296 |
|
1297 values "{xs::int list. test_append [1,2] [3,4] xs}" |
|
1298 values "{xs::int list. test_append (replicate 1000 1) (replicate 1000 2) xs}" |
|
1299 values "{xs::int list. test_append (replicate 2000 1) (replicate 2000 2) xs}" |
|
1300 |
|
1301 subsection {* Function with tuples *} |
|
1302 |
|
1303 fun append' |
|
1304 where |
|
1305 "append' ([], ys) = ys" |
|
1306 | "append' (x # xs, ys) = x # append' (xs, ys)" |
|
1307 |
|
1308 inductive test_append' |
|
1309 where |
|
1310 "append' (xs, ys) = zs ==> test_append' xs ys zs" |
|
1311 |
|
1312 code_pred [inductify, skip_proof] test_append' . |
|
1313 |
|
1314 thm test_append'.equation |
|
1315 |
|
1316 values "{(xs::int list, ys). test_append' xs ys [1, 2, 3, 4]}" |
|
1317 |
|
1318 declare append'P.equation[code del] |
|
1319 |
|
1320 values "{zs :: int list. test_append' [1,2,3] [4,5] zs}" |
|
1321 |
|
1322 section {* Arithmetic examples *} |
|
1323 |
|
1324 subsection {* Examples on nat *} |
|
1325 |
|
1326 inductive plus_nat_test :: "nat => nat => nat => bool" |
|
1327 where |
|
1328 "x + y = z ==> plus_nat_test x y z" |
|
1329 |
|
1330 code_pred [inductify, skip_proof] plus_nat_test . |
|
1331 code_pred [new_random_dseq inductify] plus_nat_test . |
|
1332 |
|
1333 thm plus_nat_test.equation |
|
1334 thm plus_nat_test.new_random_dseq_equation |
|
1335 |
|
1336 values [expected "{9::nat}"] "{z. plus_nat_test 4 5 z}" |
|
1337 values [expected "{9::nat}"] "{z. plus_nat_test 7 2 z}" |
|
1338 values [expected "{4::nat}"] "{y. plus_nat_test 5 y 9}" |
|
1339 values [expected "{}"] "{y. plus_nat_test 9 y 8}" |
|
1340 values [expected "{6::nat}"] "{y. plus_nat_test 1 y 7}" |
|
1341 values [expected "{2::nat}"] "{x. plus_nat_test x 7 9}" |
|
1342 values [expected "{}"] "{x. plus_nat_test x 9 7}" |
|
1343 values [expected "{(0::nat,0::nat)}"] "{(x, y). plus_nat_test x y 0}" |
|
1344 values [expected "{(0, Suc 0), (Suc 0, 0)}"] "{(x, y). plus_nat_test x y 1}" |
|
1345 values [expected "{(0, 5), (4, Suc 0), (3, 2), (2, 3), (Suc 0, 4), (5, 0)}"] |
|
1346 "{(x, y). plus_nat_test x y 5}" |
|
1347 |
|
1348 inductive minus_nat_test :: "nat => nat => nat => bool" |
|
1349 where |
|
1350 "x - y = z ==> minus_nat_test x y z" |
|
1351 |
|
1352 code_pred [inductify, skip_proof] minus_nat_test . |
|
1353 code_pred [new_random_dseq inductify] minus_nat_test . |
|
1354 |
|
1355 thm minus_nat_test.equation |
|
1356 thm minus_nat_test.new_random_dseq_equation |
|
1357 |
|
1358 values [expected "{0::nat}"] "{z. minus_nat_test 4 5 z}" |
|
1359 values [expected "{5::nat}"] "{z. minus_nat_test 7 2 z}" |
|
1360 values [expected "{16::nat}"] "{x. minus_nat_test x 7 9}" |
|
1361 values [expected "{16::nat}"] "{x. minus_nat_test x 9 7}" |
|
1362 values [expected "{0, Suc 0, 2, 3}"] "{x. minus_nat_test x 3 0}" |
|
1363 values [expected "{0::nat}"] "{x. minus_nat_test x 0 0}" |
|
1364 |
|
1365 subsection {* Examples on int *} |
|
1366 |
|
1367 inductive plus_int_test :: "int => int => int => bool" |
|
1368 where |
|
1369 "a + b = c ==> plus_int_test a b c" |
|
1370 |
|
1371 code_pred [inductify, skip_proof] plus_int_test . |
|
1372 code_pred [new_random_dseq inductify] plus_int_test . |
|
1373 |
|
1374 thm plus_int_test.equation |
|
1375 thm plus_int_test.new_random_dseq_equation |
|
1376 |
|
1377 values [expected "{1::int}"] "{a. plus_int_test a 6 7}" |
|
1378 values [expected "{1::int}"] "{b. plus_int_test 6 b 7}" |
|
1379 values [expected "{11::int}"] "{c. plus_int_test 5 6 c}" |
|
1380 |
|
1381 inductive minus_int_test :: "int => int => int => bool" |
|
1382 where |
|
1383 "a - b = c ==> minus_int_test a b c" |
|
1384 |
|
1385 code_pred [inductify, skip_proof] minus_int_test . |
|
1386 code_pred [new_random_dseq inductify] minus_int_test . |
|
1387 |
|
1388 thm minus_int_test.equation |
|
1389 thm minus_int_test.new_random_dseq_equation |
|
1390 |
|
1391 values [expected "{4::int}"] "{c. minus_int_test 9 5 c}" |
|
1392 values [expected "{9::int}"] "{a. minus_int_test a 4 5}" |
|
1393 values [expected "{- 1::int}"] "{b. minus_int_test 4 b 5}" |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
1278 end |
1398 end |