Demo_proof.v 34.2 KB
 charguer committed Jan 08, 2016 1 ``````Set Implicit Arguments. `````` charguer committed Apr 20, 2016 2 3 4 5 ``````(* LibInt LibWf *) Require Import CFLib. Require Import Demo_ml. Require Import Stdlib. `````` charguer committed Feb 13, 2015 6 `````` `````` charguer committed Apr 26, 2016 7 ``````(* Open Scope tag_scope.*) `````` charguer committed Apr 20, 2016 8 9 `````` `````` charguer committed Apr 26, 2016 10 11 12 13 14 15 16 17 ``````(* let compare_int () = (1 <> 0 && 1 <= 2) || (0 = 1 && 1 >= 2 && 1 < 2 && 2 > 1) let compare_min () = (min 0 1) `````` charguer committed Apr 26, 2016 18 `````` `````` charguer committed Apr 26, 2016 19 ``````(********************************************************************) `````` charguer committed Apr 26, 2016 20 21 22 23 24 25 26 27 28 ``````(* ** List operators *) let list_ops () = let x = [1] in List.length (List.rev (List.concat (List.append [x] [x; x]))) *) `````` charguer committed Apr 26, 2016 29 30 31 32 `````` `````` charguer committed Apr 26, 2016 33 34 35 36 37 38 ``````(********************************************************************) (********************************************************************) (********************************************************************) `````` charguer committed Apr 26, 2016 39 40 41 42 43 `````` (* `````` charguer committed Apr 26, 2016 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 ``````let match_term_when () = let f x = x + 1 in match f 3 with | 0 -> 1 | n when n > 0 -> 2 | _ -> 3 (* captures (Some x, _) or (_, Some x) with x > 0 *) let match_or_clauses p = match p with | (None, None) -> false | ((Some x, _) | (_, Some x)) when x > 0 -> true | (Some x, _) | (_, Some x) -> false *) `````` charguer committed Apr 26, 2016 60 61 62 63 64 65 66 67 68 `````` (********************************************************************) (********************************************************************) (********************************************************************) `````` charguer committed Apr 26, 2016 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 ``````(********************************************************************) (* ** Encoding of names *) Lemma renaming_types : True. Proof using. pose renaming_t'_. pose renaming_t2_. pose C'. pose renaming_t3_. pose renaming_t4_. auto. Qed. Lemma renaming_demo_spec : app renaming_demo [tt] \[] \[= tt]. Proof using. xcf. xval. xval. xval. xval. xval. xrets. auto. Qed. `````` charguer committed Apr 26, 2016 93 94 `````` `````` charguer committed Apr 26, 2016 95 96 97 ``````(********************************************************************) (* ** Polymorphic let bindings and value restriction *) `````` charguer committed Apr 26, 2016 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 ``````Lemma let_poly_p0_spec : app let_poly_p0 [tt] \[] \[= tt]. Proof using. xcf. xlet_poly_keep (= true). xapp_skip. intro_subst. xrets~. Qed. Lemma let_poly_p1_spec : app let_poly_p1 [tt] \[] \[= tt]. Proof using. xcf. xfun. xlet_poly_keep (fun B (r:option B) => r = None). { xapps. xrets. } { intros Hr. xrets~. } Qed. Lemma let_poly_p2_spec : app let_poly_p2 [tt] \[] \[= tt]. Proof using. xcf. xfun. xlet. { xlet_poly_keep (fun B (r:option B) => r = None). { xapps. xrets. } { intros Hr. xrets~. } } { xrets~. } Qed. Lemma let_poly_p3_spec : app let_poly_p3 [tt] \[] \[= tt]. Proof using. xcf. xlet_poly_keep (= true). { xapp_skip. } intro_subst. xapp_skip. xlet_poly_keep (= false). { xapp_skip. } intro_subst. xapp_skip. xrets~. Qed. Lemma let_poly_f0_spec : forall A, app let_poly_f0 [tt] \[] \[= @nil A]. Proof using. xcf. xapps. xapps. xsimpl~. Qed. Lemma let_poly_f1_spec : forall A, app let_poly_f1 [tt] \[] \[= @nil A]. Proof using. xcf. xapps. xapps. xsimpl~. Qed. Lemma let_poly_f2_spec : forall A, app let_poly_f2 [tt] \[] \[= @nil A]. Proof using. xcf. xapps. xapps. xsimpl~. Qed. Lemma let_poly_f3_spec : app let_poly_f3 [tt] \[] \[= @nil int]. Proof using. xcf. xapps. xapps. xsimpl~. Qed. Lemma let_poly_f4_spec : app let_poly_f4 [tt] \[] \[= @nil int]. Proof using. xcf. xapps. xapps. xsimpl~. Qed. Lemma let_poly_g1_spec : app let_poly_g1 [tt] \[] \[= 5::nil]. Proof using. xcf. xapps. xapps. xapps. xsimpl~. Qed. Lemma let_poly_g2_spec : app let_poly_g2 [tt] \[] \[= 4::nil]. Proof using. xcf. xapps. xapps. xapps. xsimpl~. Qed. `````` charguer committed Apr 26, 2016 175 176 ``````Lemma let_poly_h0_spec : forall A, app let_poly_h0 [tt] \[] (fun (r:loc) => r ~~> (@nil A)). `````` charguer committed Apr 26, 2016 177 ``````Proof using. `````` charguer committed Apr 26, 2016 178 `````` xcf. xapps. xret~. `````` charguer committed Apr 26, 2016 179 180 ``````Qed. `````` charguer committed Apr 26, 2016 181 182 183 184 185 186 187 188 ``````Lemma let_poly_h1_spec : forall A, app let_poly_h1 [tt] \[] (fun (f:func) => \[ app f [tt] \[] (fun (r:loc) => r ~~> (@nil A)) ]). Proof using. xcf. xlet (fun g => \[ app g [tt] \[] (fun (r:loc) => r ~~> (@nil A)) ]). { xfun. xrets. xapps. xapps. } intros Hg. xrets. xapps. Qed. `````` charguer committed Apr 19, 2016 189 `````` `````` charguer committed Apr 26, 2016 190 191 192 193 194 195 ``````Lemma let_poly_h2_spec : forall A, app let_poly_h2 [tt] \[] (fun (f:func) => \[ app f [tt] \[] (fun (r:loc) => r ~~> (@nil A)) ]). Proof using. xcf. xfun. xrets. xapps. xapps. Qed. `````` charguer committed Apr 15, 2016 196 `````` `````` charguer committed Apr 26, 2016 197 198 199 200 201 ``````Lemma let_poly_h3_spec : forall A, app let_poly_h3 [tt] \[] (fun (r:loc) => r ~~> (@nil A)). Proof using. xcf. xfun. xapps. xapps. Qed. `````` charguer committed Apr 11, 2016 202 `````` `````` charguer committed Apr 26, 2016 203 204 205 206 207 ``````Lemma let_poly_k1_spec : forall A, app let_poly_k1 [tt] \[] \[= @nil A]. Proof using. xcf. xrets~. Qed. `````` charguer committed Apr 11, 2016 208 `````` `````` charguer committed Apr 26, 2016 209 210 211 212 213 ``````Lemma let_poly_k2_spec : forall A, app let_poly_k2 [tt] \[] (fun (r:loc) => r ~~> (@nil A)). Proof using. xcf. xapps. Qed. `````` charguer committed Apr 21, 2016 214 `````` `````` charguer committed Apr 26, 2016 215 216 217 218 219 220 ``````Lemma let_poly_r1_spec : app let_poly_r1 [tt] \[] \[= tt]. Proof using. xcf. xapps. xrets~. Unshelve. solve_type. Qed. `````` charguer committed Apr 21, 2016 221 `````` `````` charguer committed Apr 26, 2016 222 223 ``````Lemma let_poly_r2_spec : forall A, app let_poly_r2 [tt] \[] \[= @nil A]. `````` charguer committed Apr 21, 2016 224 ``````Proof using. `````` charguer committed Apr 26, 2016 225 226 227 228 229 `````` xcf. xapps. dup 2. { xval. xrets~. } { xvals. xrets~. } Unshelve. solve_type. Qed. `````` charguer committed Apr 21, 2016 230 `````` `````` charguer committed Apr 26, 2016 231 232 233 `````` Lemma let_poly_r3_spec : forall A, app let_poly_r3 [tt] \[] \[= @nil A]. `````` charguer committed Apr 21, 2016 234 ``````Proof using. `````` charguer committed Apr 26, 2016 235 236 237 `````` xcf. xlet_poly_keep (fun A (r:list A) => r = nil). { xapps. xrets~. } intros Hr. xrets. auto. `````` charguer committed Apr 21, 2016 238 239 240 ``````Qed. `````` charguer committed Apr 26, 2016 241 `````` `````` charguer committed Apr 11, 2016 242 243 ``````(********************************************************************) (* ** Top-level values *) `````` charguer committed Feb 13, 2015 244 `````` `````` charguer committed Apr 11, 2016 245 246 247 248 249 250 251 252 ``````Lemma top_val_int_spec : top_val_int = 5. Proof using. dup 5. xcf. auto. (* demos: *) xcf_show. skip. xcf_show top_val_int. skip. `````` charguer committed Apr 18, 2016 253 `````` xcf_show top_val_int as M. skip. `````` charguer committed Apr 11, 2016 254 255 `````` xcf. skip. Qed. `````` charguer committed Feb 13, 2015 256 `````` `````` charguer committed Apr 11, 2016 257 258 259 260 261 ``````Lemma top_val_int_list_spec : top_val_int_list = @nil int. Proof using. xcf. auto. Qed. `````` charguer committed Feb 13, 2015 262 `````` `````` charguer committed Apr 11, 2016 263 264 265 ``````Lemma top_val_poly_list_spec : forall A, top_val_poly_list = @nil A. Proof using. xcf*. Qed. `````` charguer committed Nov 05, 2014 266 `````` `````` charguer committed Apr 11, 2016 267 268 269 ``````Lemma top_val_poly_list_pair_spec : forall A B, top_val_poly_list_pair = (@nil A, @nil B). Proof using. xcf*. Qed. `````` charguer committed Feb 13, 2015 270 `````` `````` charguer committed Nov 05, 2014 271 `````` `````` charguer committed Apr 11, 2016 272 `````` `````` charguer committed Apr 11, 2016 273 ``````(********************************************************************) `````` charguer committed Apr 11, 2016 274 ``````(* ** Return *) `````` charguer committed Nov 05, 2014 275 `````` `````` charguer committed Apr 11, 2016 276 277 ``````Lemma ret_unit_spec : app ret_unit [tt] \[] \[= tt]. (* (fun (_:unit) => \[]).*) (* same as (# \[]). *) `````` charguer committed Apr 11, 2016 278 ``````Proof using. `````` charguer committed Apr 20, 2016 279 `````` xcf. dup 5. (* TODO : accolade *) `````` charguer committed Apr 11, 2016 280 281 282 283 284 285 `````` xret. xsimpl. auto. (* demos *) xrets. auto. xrets*. xret_no_gc. xsimpl. auto. xret_no_clean. xsimpl*. `````` charguer committed Apr 11, 2016 286 ``````Qed. `````` charguer committed Feb 13, 2015 287 `````` `````` charguer committed Apr 11, 2016 288 289 290 ``````Lemma ret_int_spec : app ret_int [tt] \[] \[= 3]. Proof using. xcf. xrets*. Qed. `````` charguer committed Feb 13, 2015 291 `````` `````` charguer committed Apr 11, 2016 292 293 ``````Lemma ret_int_pair_spec : app ret_int_pair [tt] \[] \[= (3,4)]. `````` charguer committed Apr 20, 2016 294 ``````Proof using. xcf_go*. Qed. `````` charguer committed Feb 13, 2015 295 `````` `````` charguer committed Apr 11, 2016 296 297 ``````Lemma ret_poly_spec : forall A, app ret_poly [tt] \[] \[= @nil A]. `````` charguer committed Apr 20, 2016 298 ``````Proof using. xcf. xgo*. Qed. `````` charguer committed Feb 13, 2015 299 300 `````` `````` charguer committed Apr 12, 2016 301 302 303 304 305 306 307 308 ``````(********************************************************************) (* ** Sequence *) Axiom ret_unit_spec' : forall A (x:A), app ret_unit [x] \[] \[= tt]. (* (fun (_:unit) => \[]).*) (* same as (# \[]). *) Hint Extern 1 (RegisterSpec ret_unit) => Provide ret_unit_spec'. `````` charguer committed Apr 18, 2016 309 `````` `````` charguer committed Apr 12, 2016 310 311 312 313 314 315 316 317 318 319 320 321 322 ``````Lemma seq_ret_unit_spec : app seq_ret_unit [tt] \[] \[= tt]. Proof using. xcf. (* xlet. -- make sure we get a good error here *) xseq. xapp1. xapp2. dup 3. { xapp3_no_apply. apply S. } { xapp3_no_simpl. } { xapp3. } dup 4. `````` charguer committed Apr 18, 2016 323 `````` { xseq. xapp. xapp. xsimpl. auto. } `````` charguer committed Apr 15, 2016 324 325 `````` { xapp. intro_subst. xapp. } { xapps. xapps. } `````` charguer committed Apr 12, 2016 326 327 328 329 `````` { xapps. xapps~. } Qed. `````` charguer committed Feb 13, 2015 330 `````` `````` charguer committed Apr 11, 2016 331 ``````(********************************************************************) `````` charguer committed Apr 11, 2016 332 ``````(* ** Let-value *) `````` charguer committed Nov 05, 2014 333 `````` `````` charguer committed Apr 11, 2016 334 335 ``````Lemma let_val_int_spec : app let_val_int [tt] \[] \[= 3]. `````` charguer committed Apr 11, 2016 336 ``````Proof using. `````` charguer committed Apr 11, 2016 337 338 339 340 341 342 343 344 345 `````` xcf. dup 7. xval. xrets~. (* demos *) xval as r. xrets~. xval as r Er. xrets~. xvals. xrets~. xval_st (= 3). auto. xrets~. xval_st (= 3) as r. auto. xrets~. xval_st (= 3) as r Er. auto. xrets~. `````` charguer committed Nov 05, 2014 346 347 ``````Qed. `````` charguer committed Apr 11, 2016 348 349 350 351 352 353 ``````Lemma let_val_pair_int_spec : app let_val_pair_int [tt] \[] \[= (3,4)]. Proof using. xcf. xvals. xrets*. Qed. Lemma let_val_poly_spec : app let_val_poly [tt] \[] \[= 3]. `````` charguer committed Apr 11, 2016 354 ``````Proof using. `````` charguer committed Apr 11, 2016 355 `````` xcf. dup 3. `````` charguer committed Apr 15, 2016 356 357 358 `````` { xval. xret. xsimpl. auto. } { xval as r. xrets~. } { xvals. xrets~. } `````` charguer committed Apr 11, 2016 359 ``````Qed. `````` charguer committed Nov 05, 2014 360 361 `````` `````` charguer committed Apr 12, 2016 362 363 364 365 366 367 ``````(********************************************************************) (* ** Let-function *) Lemma let_fun_const_spec : app let_fun_const [tt] \[] \[= 3]. Proof using. `````` charguer committed Apr 18, 2016 368 369 `````` xcf. dup 10. { xfun. apply Sf. xtag_goal. xrets~. } `````` charguer committed Apr 12, 2016 370 `````` { xfun as g. apply Sg. skip. } `````` charguer committed Apr 18, 2016 371 `````` { xfun as g. xapp. xret. skip. } `````` charguer committed Apr 12, 2016 372 373 `````` { xfun as g G. apply G. skip. } { xfun_no_simpl (fun g => app g [tt] \[] \[=3]). `````` charguer committed Apr 18, 2016 374 `````` { xapp. skip. } `````` charguer committed Apr 12, 2016 375 376 377 378 379 `````` { apply Sf. } } { xfun_no_simpl (fun g => app g [tt] \[] \[=3]) as h. { apply Sh. skip. } { apply Sh. } } { xfun_no_simpl (fun g => app g [tt] \[] \[=3]) as h H. `````` charguer committed Apr 18, 2016 380 381 `````` { xapp. skip. } { xapp. } } `````` charguer committed Apr 12, 2016 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 `````` { xfun (fun g => app g [tt] \[] \[=3]). { xrets~. } { apply Sf. } } { xfun (fun g => app g [tt] \[] \[=3]) as h. { skip. } { skip. } } { xfun (fun g => app g [tt] \[] \[=3]) as h H. { skip. } { skip. } } Qed. Lemma let_fun_poly_id_spec : app let_fun_poly_id [tt] \[] \[= 3]. Proof using. xcf. xfun. dup 2. { xapp. xret. xsimpl~. } { xapp1. xapp2. dup 5. `````` charguer committed Apr 15, 2016 401 402 403 404 405 `````` { apply Spec. xrets. auto. } { xapp3_no_apply. Focus 2. apply S. xrets. auto. } { xapp3_no_simpl. xrets~. } { xapp3. xrets~. } { xapp. xret. xsimpl~. } } `````` charguer committed Apr 12, 2016 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 ``````Qed. Lemma let_fun_poly_pair_homogeneous_spec : app let_fun_poly_pair_homogeneous [tt] \[] \[= (3,3)]. Proof using. xcf. xfun. xapp. xret. xsimpl~. Qed. Lemma let_fun_on_the_fly_spec : app let_fun_on_the_fly [tt] \[] \[= 4]. Proof using. xcf. xfun. xfun. xapp. xapp. xret. xsimpl~. Qed. `````` charguer committed Apr 15, 2016 430 431 432 433 434 435 436 437 438 439 ``````Lemma let_fun_in_let_spec : app let_fun_in_let [tt] \[] (fun g => \[ forall A (x:A), app g [x] \[] \[= x] ]). Proof using. xcf. xlet (fun g => \[ forall A (x:A), app g [x] \[] \[= x] ]). (* TODO: could we get away by typing just [xlet] above? *) { xassert. { xret. } xfun. xrets. =>>. xapp. xrets~. } { =>> M. xrets~. } Qed. `````` charguer committed Apr 14, 2016 440 `````` `````` charguer committed Apr 18, 2016 441 442 443 444 445 446 447 ``````Lemma let_fun_in_let_spec' : app let_fun_in_let [tt] PRE \[] RET g ST \[ forall A (x:A), app g [x] \[] \[= x] ]. Proof using. Abort. `````` charguer committed Apr 20, 2016 448 449 450 451 452 453 454 455 456 ``````Lemma let_fun_in_let_spec'' : app let_fun_in_let [tt] PRE \[] POST (fun g => \[ forall A (x:A), app g [x] \[] \[= x] ]). Proof using. xcf. Abort. `````` charguer committed Apr 12, 2016 457 458 459 460 461 462 463 464 `````` (********************************************************************) (* ** Let-term *) Lemma let_term_nested_id_calls_spec : app let_term_nested_id_calls [tt] \[] \[= 2]. Proof using. xcf. `````` charguer committed Apr 15, 2016 465 `````` xfun (fun f => forall (x:int), app f [x] \[] \[= x]). { xrets~. } `````` charguer committed Apr 12, 2016 466 467 468 469 470 471 472 473 474 475 `````` xapps. xapps. xapps. xrets~. Qed. Lemma let_term_nested_pairs_calls_spec : app let_term_nested_pairs_calls [tt] \[] \[= ((1,2),(3,(4,5))) ]. Proof using. xcf. `````` charguer committed Apr 15, 2016 476 `````` xfun (fun f => forall A B (x:A) (y:B), app f [x y] \[] \[= (x,y)]). { xrets~. } `````` charguer committed Apr 12, 2016 477 478 479 480 481 482 483 `````` xapps. xapps. xapps. xapps. xrets~. Qed. `````` charguer committed Apr 11, 2016 484 ``````(********************************************************************) `````` charguer committed Apr 11, 2016 485 ``````(* ** Pattern-matching *) `````` charguer committed Nov 05, 2014 486 `````` `````` charguer committed Apr 11, 2016 487 488 489 490 491 492 493 ``````Lemma match_pair_as_spec : app match_pair_as [tt] \[] \[= (4,(3,4))]. Proof using. xcf. dup 8. { xmatch. xrets*. } { xmatch_subst_alias. xrets*. } { xmatch_no_alias. xalias. xalias as L. skip. } `````` charguer committed Apr 12, 2016 494 495 `````` { xmatch_no_cases. dup 6. { xmatch_case. `````` charguer committed Apr 15, 2016 496 `````` { xrets*. } `````` charguer committed Apr 12, 2016 497 `````` { xmatch_case. } } `````` charguer committed Apr 11, 2016 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 `````` { xcase_no_simpl. { dup 3. { xalias. xalias. xret. xsimpl. xauto*. } { xalias as u U. xalias as v. skip. } { xalias_subst. xalias_subst. skip. } } { xdone. } } { xcase_no_simpl as E. skip. skip. } { xcase_no_intros. intros x y E. skip. intros F. skip. } { xcase. skip. skip. } { xcase as C. skip. skip. (* note: inversion got rid of C *) } } { xmatch_no_simpl_no_alias. skip. } { xmatch_no_simpl_subst_alias. skip. } `````` charguer committed Apr 12, 2016 513 `````` { xmatch_no_intros. skip. } `````` charguer committed Apr 11, 2016 514 515 516 517 518 519 520 521 `````` { xmatch_no_simpl. inverts C. skip. } Qed. Lemma match_nested_spec : app match_nested [tt] \[] \[= (2,2)::nil]. Proof using. xcf. xval. dup 3. { xmatch_no_simpl. `````` charguer committed Apr 15, 2016 522 `````` { xrets*. } `````` charguer committed Apr 11, 2016 523 524 525 `````` { false. (* note: [xrets] would produce a ununified [hprop]. caused by [tryfalse] in [hextract_cleanup]. TODO: avoid this. *) } } { xmatch. `````` charguer committed Apr 15, 2016 526 `````` xrets*. `````` charguer committed Apr 11, 2016 527 528 `````` (* second case is killed by [xcase_post] *) } { xmatch_no_intros. skip. skip. } `````` charguer committed Apr 11, 2016 529 ``````Qed. `````` charguer committed Nov 05, 2014 530 `````` `````` charguer committed Feb 16, 2015 531 `````` `````` charguer committed Apr 11, 2016 532 533 534 535 536 537 538 539 540 541 542 543 ``````(********************************************************************) (* ** Let-pattern *) Lemma let_pattern_pair_int_spec : app let_pattern_pair_int [tt] \[] \[= 3]. Proof using. xcf. xmatch. xrets~. Qed. Lemma let_pattern_pair_int_wildcard_spec : app let_pattern_pair_int_wildcard [tt] \[] \[= 3]. Proof using. xcf. xmatch. xrets~. Qed. `````` charguer committed Apr 12, 2016 544 545 546 ``````(********************************************************************) (* ** Infix functions *) `````` charguer committed Apr 21, 2016 547 548 ``````Lemma infix_plus_plus_plus_spec : forall x y, app infix_plus_plus_plus__ [x y] \[] \[= x + y]. `````` charguer committed Apr 12, 2016 549 ``````Proof using. `````` charguer committed Apr 20, 2016 550 `````` xcf_go~. `````` charguer committed Apr 12, 2016 551 552 ``````Qed. `````` charguer committed Apr 21, 2016 553 ``````Hint Extern 1 (RegisterSpec infix_plus_plus_plus__) => Provide infix_plus_plus_plus_spec. `````` charguer committed Apr 12, 2016 554 555 556 557 558 559 560 561 562 `````` Lemma infix_aux_spec : forall x y, app infix_aux [x y] \[] \[= x + y]. Proof using. xcf. xapps~. Qed. Hint Extern 1 (RegisterSpec infix_aux) => Provide infix_aux_spec. `````` charguer committed Apr 21, 2016 563 564 ``````Lemma infix_minus_minus_minus_spec : forall x y, app infix_minus_minus_minus__ [x y] \[] \[= x + y]. `````` charguer committed Apr 12, 2016 565 566 567 ``````Proof using. intros. xcf_show as S. rewrite S. xapps~. Qed. `````` charguer committed Apr 11, 2016 568 569 `````` `````` charguer committed Apr 26, 2016 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 `````` (********************************************************************) (* ** Comparison operators *) Lemma compare_poly_spec : app compare_poly [tt] \[] \[= tt]. Proof using. xcf. xlet_poly_keep (= true). { xapps. typeclass. xsimpl. subst r. logics~. } intro_subst. xapp. typeclass. intro_subst. xlet_poly_keep (= true). { xapps. typeclass. xsimpl. subst r. logics~. } intro_subst. xapp. typeclass. intro_subst. xrets~. Qed. Lemma compare_physical_loc_func_spec : app compare_physical_loc_func [tt] \[] \[= tt]. Proof using. xcf. xapps. xapps. xapp. intro_subst. xapp. intro_subst. xfun. xapp_spec infix_eq_eq_gen_spec. intros. xlet (\[=1]). xif. xapps. xrets~. xrets~. intro_subst. xrets~. Qed. Fixpoint list_update (k:int) (v:int) (l:list (int*int)) := match l with | nil => nil | (k2,v2)::t2 => let t := (list_update k v t2) in let v' := (If k = k2 then v else v2) in (k2,v')::t end. Lemma compare_physical_algebraic_spec : app compare_physical_algebraic [tt] \[] \[= (1,9)::(4,2)::(2,5)::nil ]. Proof using. xcf. xfun_ind (@list_sub (int*int)) (fun f => forall (l:list (int*int)) (k:int) (v:int), app f [k v l] \[] \[= list_update k v l ]). { xmatch. { xrets~. } `````` charguer committed Apr 26, 2016 617 `````` { xapps~. xret. xpulls. xif. `````` charguer committed Apr 26, 2016 618 619 620 621 622 623 624 625 626 `````` { xrets. case_if. auto. } { xapp_spec infix_emark_eq_gen_spec. intros M. xif. { xrets. case_if~. } { xrets. case_if~. rewrite~ M. } } } } { xapps. xsimpl. subst r. simpl. do 3 case_if. auto. } Qed. `````` charguer committed Apr 12, 2016 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 ``````(********************************************************************) (* ** Inlined total functions *) Lemma inlined_fun_arith_spec : app inlined_fun_arith [tt] \[] \[= 3]. Proof using. xcf. xval. xlet. (* note: division by a possibly-null constant is not inlined *) xapp_skip. xrets. skip. Qed. Lemma inlined_fun_other_spec : forall (n:int), app inlined_fun_others [n] \[] \[= n+1]. Proof using. xcf. xret. xsimpl. simpl. auto. Qed. `````` charguer committed Apr 15, 2016 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 ``````(********************************************************************) (* ** Type annotations *) Lemma annot_let_spec : app annot_let [tt] \[] \[= 3]. Proof using. xcf_show. xcf. xval. xrets~. Qed. Lemma annot_tuple_arg_spec : app annot_tuple_arg [tt] \[] \[= (3, @nil int)]. Proof using. xcf_show. xcf. xrets~. Qed. Lemma annot_pattern_var_spec : forall (x:list int), app annot_pattern_var [x] \[] \[= If x = nil then 1 else 0]. Proof using. xcf_show. xcf. xmatch; xrets; case_if~. Qed. Lemma annot_pattern_constr_spec : app annot_pattern_constr [tt] \[] \[= 1]. Proof using. xcf_show. xcf. xmatch; xrets~. Qed. (********************************************************************) (* ** Polymorphic functions *) Lemma top_fun_poly_id_spec : forall A (x:A), app top_fun_poly_id [x] \[] \[= x]. (* (fun r => \[r = x]). *) Proof using. xcf. xrets~. Qed. Lemma top_fun_poly_proj1_spec : forall A B (x:A) (y:B), app top_fun_poly_proj1 [(x,y)] \[] \[= x]. Proof using. xcf. xmatch. xrets~. Qed. Lemma top_fun_poly_proj1' : forall A B (p:A*B), app top_fun_poly_proj1 [p] \[] \[= Datatypes.fst p]. (* TODO: maybe it's better if [fst] remains the one from Datatypes rather than the one from Pervasives? *) Proof using. xcf. xmatch. xrets~. Qed. Lemma top_fun_poly_pair_homogeneous_spec : forall A (x y : A), app top_fun_poly_pair_homogeneous [x y] \[] \[= (x,y)]. Proof using. xcf. xrets~. Qed. (********************************************************************) (* ** Polymorphic let bindings *) Lemma let_poly_nil_spec : forall A, app let_poly_nil [tt] \[] \[= @nil A]. Proof using. xcf. dup 2. { xval. xrets. subst x. auto. } { xvals. xrets~. } Qed. Lemma let_poly_nil_pair_spec : forall A B, app let_poly_nil_pair [tt] \[] \[= (@nil A, @nil B)]. Proof using. xcf. xvals. xrets~. Qed. Lemma let_poly_nil_pair_homogeneous_spec : forall A, app let_poly_nil_pair_homogeneous [tt] \[] \[= (@nil A, @nil A)]. Proof using. xcf. xvals. xrets~. Qed. Lemma let_poly_nil_pair_heterogeneous_spec : forall A, app let_poly_nil_pair_heterogeneous [tt] \[] \[= (@nil A, @nil int)]. Proof using. xcf. xvals. xrets~. Qed. `````` charguer committed Apr 15, 2016 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 ``````(********************************************************************) (* ** Fatal Exceptions *) Lemma exn_assert_false_spec : False -> app exn_assert_false [tt] \[] \[= tt]. Proof using. xcf. xfail. auto. Qed. Lemma exn_failwith_spec : False -> app exn_failwith [tt] \[] \[= tt]. Proof using. xcf. xfail. auto. Qed. Lemma exn_raise_spec : False -> app exn_raise [tt] \[] \[= tt]. Proof using. xcf. xfail. auto. Qed. (********************************************************************) (* ** Assertions *) Lemma assert_true_spec : app assert_true [tt] \[] \[= 3]. Proof using. dup 2. { xcf. xassert. { xrets~. } xrets~. } { xcf_go~. } Qed. Lemma assert_pos_spec : forall (x:int), x > 0 -> app assert_pos [x] \[] \[= 3]. Proof using. dup 2. { xcf. xassert. { xrets~. } xrets~. } { xcf_go~. } Qed. Lemma assert_same_spec : forall (x:int), app assert_same [x x] \[] \[= 3]. Proof using. dup 2. { xcf. xassert. { xrets~. } xrets~. } { xcf_go~. } Qed. Lemma assert_let_spec : app assert_let [tt] \[] \[= 3]. Proof using. dup 2. { xcf. xassert. { xvals. xrets~. } xrets~. } { xcf_go~. } Qed. Lemma assert_seq_spec : app assert_seq [tt] \[] \[= 1]. Proof using. xcf. xapp. xassert. xapp. xrets. (* assert cannot do visible side effects, otherwise the semantics could change with -noassert *) Abort. Lemma assert_in_seq_spec : app assert_in_seq [tt] \[] \[= 4]. Proof using. `````` charguer committed Apr 18, 2016 812 `````` xcf. xlet. xassert. { xrets. } xrets. `````` charguer committed Apr 26, 2016 813 `````` xpulls. xrets~. `````` charguer committed Apr 15, 2016 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 ``````Qed. (********************************************************************) (* ** Conditionals *) Lemma if_true_spec : app if_true [tt] \[] \[= 1]. Proof using. xcf. xif. xret. xsimpl. auto. Qed. Lemma if_term_spec : app if_term [tt] \[] \[= 1]. Proof using. `````` charguer committed Apr 26, 2016 829 `````` xcf. xfun. xapp. xret. xpulls. `````` charguer committed Apr 15, 2016 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 `````` xif. xrets~. Qed. Lemma if_else_if_spec : app if_else_if [tt] \[] \[= 0]. Proof using. xcf. xfun (fun f => forall (x:int), app f [x] \[] \[= false]). { xrets~. } xapps. xif. xapps. xif. xrets~. Qed. Lemma if_then_no_else_spec : forall (b:bool), app if_then_no_else [b] \[] (fun x => \[ x >= 0]). Proof using. xcf. xapp. xseq. xif (Hexists n, \[n >= 0] \* r ~~> n). { xapp. xsimpl. math. } { xrets. math. } `````` charguer committed Apr 26, 2016 848 `````` { (*xclean.*) xpull ;=>> P. xapp. xpulls. xsimpl. math. } `````` charguer committed Apr 15, 2016 849 850 851 ``````Qed. `````` charguer committed Apr 21, 2016 852 853 854 855 856 857 858 859 860 861 862 863 864 865 ``````(********************************************************************) (* ** While loops *) Lemma while_decr_spec : app while_decr [tt] \[] \[= 3]. Proof using. xcf. xapps. xapps. dup 9. { xwhile. intros R LR HR. cuts PR: (forall k, k >= 0 -> R (n ~~> k \* c ~~> (3-k)) (# n ~~> 0 \* c ~~> 3)). { xapplys PR. math. } intros k. induction_wf IH: (downto 0) k; intros Hk. applys (rm HR). xlet. { xapps. xrets. } `````` charguer committed Apr 26, 2016 866 `````` { xpulls. xif. `````` charguer committed Apr 21, 2016 867 868 869 870 871 872 873 `````` { xseq. xapps. xapps. simpl. xapplys IH. hnf. skip. skip. skip. } (* TODO math. *) { xrets. math. skip. } } (* TODO math. *) xapps. xsimpl~. } { xwhile as R. skip. skip. } { xwhile_inv (fun b k => \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)) (downto 0). { xsimpl*. math. } `````` charguer committed Apr 26, 2016 874 `````` { intros S LS b k FS. xpull. intros. xlet. `````` charguer committed Apr 21, 2016 875 `````` { xapps. xrets. } `````` charguer committed Apr 26, 2016 876 `````` { xpulls. xif. `````` charguer committed Apr 21, 2016 877 878 879 880 881 882 883 `````` { xseq. xapps. xapps. simpl. xapplys FS. hnf. skip. skip. eauto. skip. eauto. eauto. } (* TODO math. *) { xret. xsimpl. math. math. } } } { intros. xapps. xsimpl. skip. (* math. *) } } { xwhile_inv_basic (fun b k => \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)) (downto 0). { xsimpl*. math. } `````` charguer committed Apr 26, 2016 884 885 `````` { intros b k. xpull ;=> Hk Hb. xapps. xrets. xauto*. math. } { intros k. xpull ;=> Hk Hb. xapps. xapps. xsimpl. skip. eauto. skip. hnf. skip. } `````` charguer committed Apr 21, 2016 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 `````` { => k Hk Hb. xapp. xsimpl. skip. (* math.*) } } { (* using a measure [fun k => abs k] *) xwhile_inv_basic (fun b k => \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)) (abs). skip. skip. skip. skip. } { (* defining the measure externally *) xwhile_inv_basic_measure (fun b m => Hexists k, \[m = k] \* \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)). skip. skip. skip. skip. } { (* defining the measure externally, downwards *) xwhile_inv_basic_measure (fun b m => Hexists i, \[m = 3-i] \* \[i <= 3] \* \[b = isTrue (i <= 3)] \* n ~~> (3-i) \* c ~~> i). skip. skip. skip. skip. } { xwhile_inv_skip (fun b => Hexists k, \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)). skip. skip. skip. } { xwhile_inv_basic_skip (fun b => Hexists k, \[k >= 0] \* \[b = isTrue (k > 0)] \* n ~~> k \* c ~~> (3-k)). skip. skip. skip. skip. } Abort. Lemma while_false_spec : app while_false [tt] \[] \[= tt]. Proof using. xcf. dup 2. { xwhile_inv_skip (fun (b:bool) => \[b = false]). skip. skip. skip. } { xwhile_inv_basic (fun (b:bool) (_:unit) => \[b = false]) (fun (_ _:unit) => False). { intros_all. constructor. auto_false. } { xsimpl*. } `````` charguer committed Apr 26, 2016 918 919 `````` { intros. xpulls. xrets~. } { intros. xpull. auto_false. } `````` charguer committed Apr 21, 2016 920 921 922 923 924 925 `````` { xsimpl~. } } Qed. `````` charguer committed Apr 25, 2016 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 ``````(********************************************************************) (* ** For loops *) Lemma for_to_incr_spec : forall (r:int), r >= 0 -> app for_to_incr [r] \[] \[= r]. Proof using. xcf. xapps. dup 7. { xfor. intros S LS HS. cuts PS: (forall i, (i <= r) -> S i (n ~~> i) (# n ~~> r)). { applys PS. math. } { intros i. induction_wf IH: (upto r) i. intros Li. applys (rm HS). xif. { xapps. applys IH. hnf. math. math. } { xrets. math. } } xapps. xsimpl~. } { xfor as S. skip. skip. } { xfor_inv (fun (i:int) => n ~~> i). { math. } { xsimpl. } { introv L. xapps. } xapps. xsimpl. math. } { xseq (# n ~~> r). xfor_inv (fun (i:int) => n ~~> i). skip. skip. skip. skip. skip. } { xseq (# n ~~> r). xfor_inv_void. skip. skip. skip. } { xfor_inv_void. skip. skip. } { try xfor_inv_case (fun (i:int) => n ~~> i). (* fails because no post condition *) xseq (# n ~~> r). { xfor_inv_case (fun (i:int) => n ~~> i). { xsimpl. } { introv L. xapps. } { xsimpl. math. } { math_rewrite (r = 0). xsimpl. } } { xapps. xsimpl~. } } Abort. Lemma for_downto_spec : forall (r:int), r >= 0 -> app for_downto [r] \[] \[= r]. Proof using. xcf. xapps. dup 7. { xfor_down. intros S LS HS. cuts PS: (forall i, (i >= -1) -> S i (n ~~> (r-1-i)) (# n ~~> r)). { xapplys PS. math. math. } { intros i. induction_wf IH: (downto (-1)) i. intros Li. applys (rm HS). xif. { xapps. xapplys IH. hnf. math. math. math. } { xrets. math. } } xapps. xsimpl~. } { xfor_down as S. skip. skip. } { xfor_down_inv (fun (i:int) => n ~~> (r-1-i)). { math. } { xsimpl. math. } { introv L. xapps. xsimpl. math. } xapps. xsimpl. math. } { xseq (# n ~~> r). xfor_down_inv (fun (i:int) => n ~~> (r-1-i)). skip. skip. skip. skip. skip. } { xseq (# n ~~> r). xfor_down_inv_void. skip. skip. skip. } { xfor_down_inv_void. skip. skip. } { try xfor_down_inv_case (fun (i:int) => n ~~> (r-1-i)). (* fails because no post condition *) xseq (# n ~~> r). { xfor_down_inv_case (fun (i:int) => n ~~> (r-1-i)). { xsimpl. math. } { introv L. xapps. xsimpl. math. } { xsimpl. math. } { math_rewrite (r = 0). xsimpl. } } { xapps. xsimpl~. } } Abort. `````` charguer committed Apr 15, 2016 997 998 999 1000 1001 1002 1003 1004 1005 ``````(********************************************************************) (* ** Lazy binary operators *) Lemma lazyop_val_spec : app lazyop_val [tt] \[] \[= 1]. Proof using. xcf. xif. xrets~. Qed. `````` charguer committed Apr 21, 2016 1006 1007 1008 1009 ``````(* Ltac xauto_tilde ::= xauto_tilde_default ltac:(fun _ => auto_tilde). *) `````` charguer committed Apr 15, 2016 1010 1011 1012 1013 1014 ``````Lemma lazyop_term_spec : app lazyop_term [tt] \[] \[= 1]. Proof using. xcf. xfun (fun f => forall (x:int), app f [x] \[] \[= isTrue (x = 0)]). `````` charguer committed Apr 21, 2016 1015 `````` { xrets*. } `````` charguer committed Apr 15, 2016 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 `````` xapps. xlet. { dup 3. { xif_no_simpl \[= true]. { xclean. false. } { xapps. xrets~. } } { xif. xapps. xrets~. } { xgo*. subst. xclean. auto. } (* todo: maybe extend [xauto_common] with [logics]? or would it be too slow? *) } `````` charguer committed Apr 26, 2016 1026 `````` xpulls. xif. xrets~. `````` charguer committed Apr 15, 2016 1027 1028 1029 1030 1031 1032 1033 ``````Qed. Lemma lazyop_mixex_spec : app lazyop_mixed [tt] \[] \[= 1]. Proof using. xcf. xfun (fun f => forall (x:int), app f [x] \[] \[= isTrue (x = 0)]). `````` charguer committed Apr 21, 2016 1034 `````` { xrets*. } `````` charguer committed Apr 15, 2016 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 `````` xlet \[= true]. { xif. xapps. xlet \[= true]. { xif. xapps. xlet \[= true]. { xif. xrets~. } { intro_subst. xrets~. } } { intro_subst. xrets~. } } { intro_subst. xif. xrets~. } Qed. (********************************************************************) (* ** Evaluation order *) Lemma order_app_spec : app order_app [tt] \[] \[= 2]. Proof using. `````` charguer committed Apr 20, 2016 1052 1053 1054 `````` dup 2. { xcf. xapps. xfun. xfun. xfun. `````` charguer committed Apr 26, 2016 1055 1056 `````` xapps. { xapps. xrets~. } xpulls. xapps. { xassert. xapps. xrets~. xapps. xrets~. } xpulls. `````` charguer committed Apr 20, 2016 1057 1058 `````` xapps. { xassert. xapps. xrets~. xfun. xrets~ (fun f => \[AppCurried f [a b] := (Ret (a + b)%I)] \* r ~~> 2). eauto. } `````` charguer committed Apr 26, 2016 1059 `````` xpull ;=> Hf. `````` charguer committed Apr 20, 2016 1060 1061 1062 1063 1064 1065 1066 `````` xapp. xrets~. (* TODO: can we make xret guess the post? The idea is to have [(Ret f) H ?Q] where [f:func] and [f] has a spec in hyps to instantiate Q with [fun f => H \* \[spec of f]]. Then, the proof should just be [xgo~]. *) } { xcf_go*. skip. (* TODO *) } `````` charguer committed Apr 15, 2016 1067 1068 1069 1070 1071 1072 1073 1074 1075 ``````Qed. Lemma order_constr_spec : app order_constr [tt] \[] \[= 1::1::nil]. Proof using. xcf_go*. Qed. (* Details: xcf. xapps. xfun. xfun. `````` charguer committed Apr 26, 2016 1076 1077 `````` xapps. { xapps. xrets~. } xpulls. xapps. { xassert. xapps. xrets~. xrets~. } xpulls. `````` charguer committed Apr 15, 2016 1078 1079 1080 1081 1082 1083 1084 1085 1086 `````` xrets~. *) Lemma order_list_spec : app order_list [tt] \[] \[= 1::1::nil]. Proof using. xcf_go*. Qed. Lemma order_tuple_spec : `````` charguer committed Apr 16, 2016 1087 `````` app order_tuple [tt] \[] \[= (1,1)]. `````` charguer committed Apr 15, 2016 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 ``````Proof using. xcf_go*. Qed. (* TODO: let order_array () = let order_record () = let r = ref 0 in let g () = incr r; [] in let f () = assert (!r = 1); 1 in { nb = f(); items = g() } *) `````` charguer committed Apr 15, 2016 1101 1102 1103 1104 1105 ``````(********************************************************************) (* ** Recursive function *) Require Import LibInt. `````` charguer committed Apr 18, 2016 1106 1107 1108 ``````Lemma rec_partial_half_spec : forall k n, n = 2 * k -> app rec_partial_half [n] \[] \[= k]. `````` charguer committed Apr 15, 2016 1109 ``````Proof using. `````` charguer committed Apr 18, 2016 1110 1111 1112 `````` dup 2. { => k. induction_wf IH: (downto 0) k. xcf. xif. `````` charguer committed Apr 21, 2016 1113 `````` { xrets. math. } `````` charguer committed Apr 18, 2016 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 `````` { xif. { xfail. math. } { xapps (k-1). { unfolds. skip. (* TODO Anomaly: Z.sub is not an evaluable constant. => maybe because I made it opaque? *) } { skip. } { xrets. skip. } } } } { xind_skip as IH. xcf. x. { xgo~. } { x. { x. math. } { xapps (k-1). skip. x. x. skip. } } } `````` charguer committed Apr 15, 2016 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 ``````Qed. Lemma rec_mutual_f_and_g_spec : (forall (x:int), x >= 0 -> app rec_mutual_f [x] \[] \[= x]) /\ (forall (x:int), x >= -1 -> app rec_mutual_g [x] \[] \[= x+1]). Proof using. intros. cuts G: (forall (m:int), (forall x, x <= m -> x >= 0 -> app rec_mutual_f [x] \[] \[= x]) /\ (forall x, x+1 <= m -> x >= -1 -> app rec_mutual_g [x] \[] \[= x+1])). `````` charguer committed Apr 21, 2016 1136 `````` { split; intros x P; specializes G (x+1); destruct G as [G1 G2]; xapp; try math. } `````` charguer committed Apr 15, 2016 1137 1138 1139 1140 1141 1142 1143 1144 1145 `````` => m. induction_wf IH: (downto 0) m. split; intros x Lx Px. { xcf. xif. xrets~. xapp (x-1). unfolds. skip. (* TODO *) skip. skip. intro_subst. xrets. skip. } { xcf. xapp x. unfolds. skip. (* TODO *) skip. skip. } Qed. `````` charguer committed Apr 19, 2016 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 ``````(********************************************************************) (* ** Reference and garbage collection *) Lemma ref_gc_spec : app ref_gc [tt] \[] \[= 3]. Proof using. xcf. xapp. xapp. xapp. xapp. dup 4. { xgc (r3 ~~> 1). skip. } { xgc r3. skip. } { xgc_but r1. skip. } { xlet (fun x => \[x = 2] \* r1 ~~> 1). { xapp. xapp. xsimpl~. } (* auto GC on r5 *) { intro_subst. xapps. xrets~. } (* auto GC on r1 *) } Qed. `````` charguer committed Apr 19, 2016 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 ``````(********************************************************************) (* ** Records *) Lemma sitems_build_spec : forall (A:Type) (n:int), app sitems_build [n] \[] (fun r => r ~> `{ nb' := n; items' := @nil A }). Proof using. xcf_go~. Qed. Lemma sitems_get_nb_spec : forall (A:Type) (r:loc) (n:int), app_keep sitems_get_nb [r] (r ~> `{ nb' := n; items' := @nil A }) \[= n]. Proof using. dup 3. { intros A. xcf_show as R. applys (R A). xgo~. } { xcf_show as R. unfold sitems_ in R. specializes R unit. xgo~. } { xcf_go~. Unshelve. solve_type. } Qed. (* TODO: can we do better than a manual unshelve for dealing with unused type vars? *) `````` charguer committed Apr 20, 2016 1186 1187 1188 1189 1190 1191 1192 1193 ``````Lemma sitems_get_nb_spec' : forall (A:Type) (r:sitems_ A) (n:int), app_keep sitems_get_nb [r] (r ~> `{ nb' := n; items' := @nil A }) \[= n]. Proof using. { xcf_go~. } Qed. (* TODO: can we do better than a manual unshelve for dealing with unused type vars? *) `````` charguer committed Apr 19, 2016 1194 1195 1196 ``````Lemma sitems_incr_nb_spec : forall (A:Type) (L:list A) (r:loc) (n:int), app sitems_incr_nb [r] (r ~> `{ nb' := n; items' := L }) `````` charguer committed Apr 20, 2016 1197 `````` (# (r ~> `{ nb' := n+1; items' := L })). `````` charguer committed Apr 19, 2016 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 ``````Proof using. dup 2. { xcf. xapps. xapp. Unshelve. solve_type. } { xcf_go*. Grab Existential Variables. solve_type. } Qed. Lemma sitems_length_item_spec : forall (A:Type) (r:loc) (L:list A) (n:int), app_keep sitems_length_items [r] (r ~> `{ nb' := n; items' := L }) \[= LibListZ.length L ]. Proof using. dup 2. { xcf. xapps. xrets. } { xcf_go*. } Qed. Definition Sitems A (L:list A) r := Hexists n, r ~> `{ nb' := n; items' := L } \* \[ n = LibListZ.length L ]. `````` charguer committed Apr 27, 2016 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 ``````(* Section ProjLemma. Variables (B:Type) (A1 : Type). Variables (A2 : forall (x1 : A1), Type). Variables (A3 : forall (x1 : A1) (x2 : A2 x1), Type). Lemma proj_lemma_2 : forall (R:forall (x1:A1) (x2:A2 x1) (t:B), hprop), (forall x1 x2 t, R x1 x2 t = t ~> R x1 x2). Proof using. auto. Qed. End ProjLemma. Lemma Sitems_open_gen : True. Proof. pose (@proj_lemma_2 Sitems). Qed. *) `````` charguer committed Apr 19, 2016 1237 1238 1239 ``````Lemma sitems_push_spec : forall (A:Type) (r:loc) (L:list A) (x:A), app sitems_push [x r] (r ~> Sitems L) (# r ~> Sitems (x::L)). Proof using. `````` charguer committed Apr 26, 2016 1240 `````` xcf. xunfold Sitems. xpull ;=> n E. `````` charguer committed Apr 19, 2016 1241 1242 1243 `````` xapps. xapps. xapps. xapp. xsimpl. rew_list; math. Qed. `````` charguer committed Apr 20, 2016 1244 1245 1246 1247 1248 ``````(* TODO: enéoncé spec dérivée pour App' r`.nb' en terme de Sitems xapp_spec .. *) `````` charguer committed Apr 19, 2016 1249 `````` `````` charguer committed Apr 20, 2016 1250 1251 1252 ``````(** Demo of [xopen] and [xclose] *) Lemma Sitems_open : forall r A (L:list A), `````` charguer committed Apr 19, 2016 1253 1254 1255 1256 `````` r ~> Sitems L ==> Hexists n, r ~> `{ nb' := n; items' := L } \* \[ n = LibListZ.length L ]. Proof using. intros. xunfolds~ Sitems. Qed. `````` charguer committed Apr 20, 2016 1257 ``````Lemma Sitems_close : forall r A (L:list A) (n:int), `````` charguer committed Apr 19, 2016 1258 1259 1260 1261 1262 `````` n = LibListZ.length L -> r ~> `{ nb' := n; items' := L } ==> r ~> Sitems L. Proof using. intros. xunfolds~ Sitems. Qed. `````` charguer committed Apr 20, 2016 1263 1264 1265 1266 1267 1268 ``````Implicit Arguments Sitems_close []. (* TODO comment r ~> Sitems _ xopen r xchange (Sitems_open r). *) `````` charguer committed Apr 19, 2016 1269 `````` `````` charguer committed Apr 21, 2016 1270 ``````Hint Extern 1 (RegisterOpen (Sitems _)) => `````` charguer committed Apr 20, 2016 1271 `````` Provide Sitems_open. `````` charguer committed Apr 27, 2016 1272 ``````Hint Extern 1 (RegisterClose (record_repr _)) => `````` charguer committed Apr 20, 2016 1273 `````` Provide Sitems_close. `````` charguer committed Apr 19, 2016 1274 1275 1276 1277 1278 `````` Lemma sitems_push_spec' : forall (A:Type) (r:loc) (L:list A) (x:A), app sitems_push [x r] (r ~> Sitems L) (# r ~> Sitems (x::L)). Proof using. xcf. dup 2. `````` charguer committed Apr 26, 2016 1279 `````` { xopen r. xpull ;=> n E. skip. } `````` charguer committed Apr 20, 2016 1280 1281 `````` { xopenx r ;=> n E. xapps. xapps. xapps. xapp. xclose r. rew_list; math. xsimpl~. } `````` charguer committed Apr 19, 2016 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 ``````Qed. (********************************************************************) (* ** Arrays *) Require Import Array_ml Array_proof. Section Array. Hint Extern 1 (@index _ (list _) _ _ _) => apply index_bounds_impl : maths. Hint Extern 1 (_ < length (?l[?i:=?v])) => rewrite length_update : maths. Ltac auto_tilde ::= auto with maths. Lemma array_ops_spec : app array_ops [tt] \[] \[= 3]. Proof using. xcf. xapp. math. => L EL. asserts LL: (length L = 3). subst. rewrite length_make; math. xapps. { apply index_bounds_impl; math. } xapp~. xapps~. xapps~. xapps~. xsimpl. subst. rew_arr~. Qed. End Array. `````` charguer committed Apr 15, 2016 1312 `````` `````` charguer committed Apr 12, 2016 1313 `````` `````` charguer committed Apr 27, 2016 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 ``````(********************************************************************) (* ** Integer arithmetics *) (* land *) Goal Z.land 7 28 = 4. Proof. reflexivity. Qed. Goal Z.land (-7) 28 = 24. Proof. reflexivity. Qed. Goal Z.land 7 (-28) = 4. Proof. reflexivity. Qed. Goal Z.land (-7) (-28) = -32. Proof. reflexivity. Qed. (* lor *) Goal Z.lor 7 28 = 31. Proof. reflexivity. Qed. Goal Z.lor (-7) 28 = -3. Proof. reflexivity. Qed. Goal Z.lor 7 (-28) = -25. Proof. reflexivity. Qed. Goal Z.lor (-7) (-28) = -3. Proof. reflexivity. Qed. (* lxor *) Goal Z.lxor 7 28 = 27. Proof. reflexivity. Qed. Goal Z.lxor (-7) 28 = -27. Proof. reflexivity. Qed. Goal Z.lxor 7 (-28) = -29. Proof. reflexivity. Qed. Goal Z.lxor (-7) (-28) = 29. Proof. reflexivity. Qed. (* lnot *) Goal lnot 44 = -45. Proof. reflexivity. Qed. Goal lnot (-44) = 43. Proof. reflexivity. Qed. (* shiftl *) Goal Z.shiftl 7 2 = 28. Proof. reflexivity. Qed. Goal Z.shiftl (-7) 2 = -28. Proof. reflexivity. Qed. (* shiftr *) `````` charguer committed Nov 05, 2014 1376 `````` `````` charguer committed Apr 27, 2016 1377 1378 ``````Goal Z.shiftr 7 2 = 1. Proof. reflexivity. Qed. `````` charguer committed Nov 05, 2014 1379 `````` `````` charguer committed Apr 27, 2016 1380 1381 ``````Goal Z.shiftr 7 2 = 1. Proof. reflexivity. Qed. `````` charguer committed Nov 05, 2014 1382 `````` `````` charguer committed Apr 27, 2016 1383 1384 ``````Goal Z.shiftr (-7) 2 = -2. Proof. reflexivity. Qed. `````` charguer committed Nov 05, 2014 1385 1386 `````` `````` charguer committed Apr 27, 2016 1387 `````` `````` charguer committed Nov 05, 2014 1388 `````` `````` charguer committed Apr 11, 2016 1389 ``````(********************************************************************) `````` charguer committed Apr 11, 2016 1390 1391 ``````(********************************************************************) (********************************************************************) `````` charguer committed Nov 05, 2014 1392 `````` `````` charguer committed Apr 11, 2016 1393 ``````(* `````` charguer committed Nov 05, 2014 1394 1395 `````` `````` charguer committed Apr 11, 2016 1396 1397 ``````(********************************************************************) (* ** Partial applications *) `````` charguer committed Nov 05, 2014 1398 `````` `````` charguer committed Apr 11, 2016 1399 1400 1401 1402 1403 1404 ``````Lemma app_partial_2_1 () = let f x y = (x,y) in f 3 Proof using. xcf. Qed. `````` charguer committed Nov 05, 2014 1405 `````` `````` charguer committed Apr 11, 2016 1406 1407 1408 1409 1410 1411 ``````Lemma app_partial_3_2 () = let f x y z = (x,z) in f 2 4 Proof using. xcf. Qed. `````` charguer committed Nov 05, 2014 1412 `````` `````` charguer committed Apr 11, 2016 1413 1414 1415 1416 1417 1418 ``````Lemma app_partial_add () = let add x y = x + y in let g = add 1 in g 2 Proof using. xcf. Qed. `````` charguer committed Nov 05, 2014 1419 `````` `````` charguer committed Apr 11, 2016 1420 1421 1422 1423 1424 1425 1426 ``````Lemma app_partial_appto () = let appto x f = f x in let _r = appto 3 ((+) 1) in appto 3 (fun x -> x + 1) Proof using. xcf. Qed. `````` charguer committed Nov 05, 2014 1427 `````` `````` charguer committed Apr 11, 2016 1428 1429 1430 1431 1432 1433 1434 1435 1436 ``````Lemma test_partial_app_arities () = let func4 a b c d = a + b + c + d in let f1 = func4 1 in let f2 = func4 1 2 in let f3 = func4 1 2 3 in f1 2 3 4 + f2 3 4 + f3 4 Proof using. xcf. Qed. `````` charguer committed Nov 05, 2014 1437 `````` `````` charguer committed Apr 11, 2016 1438 1439 1440 1441 1442 ``````Lemma app_partial_builtin () = let f = (+) 1 in f 2 Proof using. xcf. `````` charguer committed Nov 05, 2014 1443 1444 1445 ``````Qed. `````` charguer committed Apr 14, 2016 1446 1447 1448 1449 1450 1451 1452 ``````let app_partial_builtin_and () = let f = (&&) true in f false `````` charguer committed Apr 11, 2016 1453 1454 1455 1456 1457 1458 1459 1460 ``````(********************************************************************) (* ** Over applications *) Lemma app_over_id () = let f x = x in f f 3 Proof using. xcf. `````` charguer committed Nov 05, 2014 1461 1462 1463 1464 ``````Qed. `````` charguer committed Apr 11, 2016 1465 `````` `````` charguer committed Feb 13, 2015 1466 `````` `````` charguer committed Feb 16, 2015 1467 ``*)``