1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 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 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 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 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
|
;; Copyright (C) 2017, Regents of the University of Texas
;; Written by Cuong Chau (derived from the FM9001 work of Brock and Hunt)
;; License: A 3-clause BSD license. See the LICENSE file distributed with
;; ACL2.
;; The ACL2 source code for the FM9001 work is available at
;; https://github.com/acl2/acl2/tree/master/books/projects/fm9001.
;; Cuong Chau <ckcuong@cs.utexas.edu>
;; May 2019
(in-package "ADE")
(include-book "misc/defopener" :dir :system)
(include-book "std/util/bstar" :dir :system)
(include-book "std/util/define" :dir :system)
;; ======================================================================
(defmacro strings-to-symbol (&rest strs)
`(intern$ (concatenate 'string ,@strs)
"ADE"))
(defun var-to-const (x)
(declare (xargs :guard (symbolp x)))
(intern$ (concatenate 'string "*" (symbol-name x) "*")
"ADE"))
(defun state-accessors-gen (module st idx)
(declare (xargs :guard (and (symbolp module)
(symbol-listp st)
(natp idx))))
(if (atom st)
nil
(b* ((sub-st (car st))
(name (strings-to-symbol "*"
(symbol-name module)
"$"
(symbol-name sub-st)
"*")))
(cons `(defconst ,name ,idx)
(state-accessors-gen module (cdr st) (1+ idx))))))
(defmacro not-primp-lemma (fn)
(b* ((thm-name (strings-to-symbol "NOT-PRIMP-" (symbol-name fn))))
`(local
(defthm ,thm-name
(not (primp (si ',fn n)))
:hints (("Goal" :in-theory (enable primp)))))))
;; ======================================================================
;; DESTRUCTURING-LEMMA generator
;; Because of quirks in equality reasoning, it "doesn't work" to simply let
;; module definitions open up. Instead, we use a lemma that explicitly states
;; how to destructure a module definition.
(defmacro destructuring-lemma (fn args declare-form bindings
name ins outs st occs)
(b* ((destructure (strings-to-symbol (symbol-name fn) "$DESTRUCTURE"))
(prefix-name (strings-to-symbol
(coerce (butlast (coerce (symbol-name fn) 'list)
1)
'string)))
(form `(,fn ,@args)))
`(progn
(defun ,fn ,args
,declare-form
(let ,bindings
(list ,name ,ins ,outs ,st ,occs)))
(defthmd ,destructure
(let ,bindings
(AND
(EQUAL (CAR ,form) ,name)
(EQUAL (CADR ,form) ,ins)
(EQUAL (CADDR ,form) ,outs)
(EQUAL (CADDDR ,form) ,st)
(EQUAL (CAR (CDDDDR ,form)) ,occs))))
;; Prove that this module is not a DE primitive.
(not-primp-lemma ,prefix-name)
(in-theory (disable ,fn)))))
;; MODULE-GENERATOR generator args name inputs outputs body state.
(defmacro module-generator (generator args name inputs outputs st body
&optional declare-form)
(let ((destructuring-lemma (strings-to-symbol (symbol-name generator)
"$DESTRUCTURE"))
(prefix-name (strings-to-symbol
(coerce (butlast (coerce (symbol-name generator) 'list)
1)
'string)))
(form `(,generator ,@args)))
`(progn
(defun ,generator ,args
,declare-form
(LIST ,name ,inputs ,outputs ,st ,body))
(defthmd ,destructuring-lemma
(AND
(EQUAL (CAR ,form) ,name)
(EQUAL (CADR ,form) ,inputs)
(EQUAL (CADDR ,form) ,outputs)
(EQUAL (CADDDR ,form) ,st)
(EQUAL (CAR (CDDDDR ,form)) ,body)))
;; Prove that this module is not a DE primitive.
(not-primp-lemma ,prefix-name)
(in-theory (disable ,generator)))))
;; Generating value or state lemmas for primitives
(defun primitives-lemmas-gen (eval primitives)
;; @eval is either 'se (for value lemmas) or 'de (for state lemmas)
(if (atom primitives)
nil
(b* ((prim (car primitives))
(fn (car prim))
(expr (cadr prim))
(value/state (if (equal eval 'se) "$VALUE" "$STATE"))
(thm-name (strings-to-symbol (symbol-name fn) value/state))
(eval-primp-apply (strings-to-symbol (symbol-name eval)
"-PRIMP-APPLY")))
(cons `(defthm ,thm-name
(equal (,eval ',fn ins st netlist)
,expr)
:hints (("Goal" :in-theory (enable ,eval-primp-apply))))
(primitives-lemmas-gen eval (cdr primitives))))))
;; ======================================================================
(define outputs/step-gen (state name
&key
(type ''outputs)
(inputs '())
(input-signals '())
(hyps 't)
(enable 'nil)
(disable 'nil))
:mode :program
(b* ((fn-name (strings-to-symbol (symbol-name name)
(if (equal type 'outputs)
"$OUTPUTS-GEN"
"$STEP")))
;; (lemma-name (strings-to-symbol (symbol-name name)
;; (if (equal type 'value)
;; "$VALUE"
;; "$STATE")))
(recognizer (strings-to-symbol (symbol-name name)
"&"))
(destructure (strings-to-symbol (symbol-name name)
"*$DESTRUCTURE"))
(eval (if (equal type 'outputs) 'se 'de))
(hints
`(("Goal"
:do-not-induct t
:expand (:free (inputs data-size)
(,eval (si ',name data-size) inputs st netlist))
:in-theory (e/d (de-rules
,recognizer
,destructure
,@enable)
(de-module-disabled-rules
,@disable)))))
((mv & lemma state)
(bash-fn `(b* ((inputs ,inputs))
(implies ,hyps
(equal (,eval (si ',name data-size)
inputs st netlist)
?)))
hints nil 'bash state))
(fn-body (cadr (caddar lemma))))
(mv nil
`(defun ,fn-name (inputs st data-size)
(b* ,input-signals
,fn-body))
;; `(progn
;; (defun ,fn-name (inputs st data-size)
;; (b* ,input-signals
;; ,fn-body))
;; (defthm ,lemma-name
;; (b* ((inputs ,inputs))
;; (implies ,hyps
;; (equal (,eval (si ',name data-size)
;; inputs st netlist)
;; (,fn-name inputs st data-size))))
;; :hints ,hints)
;; (in-theory (disable ,fn-name))
;; )
state)))
(defmacro run-gen (name &rest sizes)
(declare (xargs :guard (and (symbolp name)
(symbol-listp sizes))))
(b* ((step (strings-to-symbol (symbol-name name)
"$STEP"))
(run (strings-to-symbol (symbol-name name)
"$RUN"))
(open-run-zp (strings-to-symbol "OPEN-"
(symbol-name name)
"$RUN-ZP"))
(open-run (strings-to-symbol "OPEN-"
(symbol-name name)
"$RUN"))
(run-plus (strings-to-symbol (symbol-name name)
"$RUN-PLUS"))
(inputs-seq 'inputs-seq))
(if sizes
`(progn
(defun ,run (,inputs-seq st ,@sizes n)
(if (zp n)
st
(,run (cdr ,inputs-seq)
(,step (car ,inputs-seq) st ,@sizes)
,@sizes
(1- n))))
(defopener ,open-run-zp
(,run ,inputs-seq st ,@sizes n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,run ,inputs-seq st ,@sizes n))))
(defopener ,open-run
(,run ,inputs-seq st ,@sizes n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,run ,inputs-seq st ,@sizes n))))
(defthm ,run-plus
(implies
(and (natp m)
(natp n))
(equal (,run ,inputs-seq st ,@sizes (+ m n))
(,run
(nthcdr m ,inputs-seq)
(,run ,inputs-seq st ,@sizes m)
,@sizes
n)))
:hints (("Goal"
:induct (,run ,inputs-seq st ,@sizes m))))
(in-theory (disable ,run)))
`(progn
(defun ,run (,inputs-seq st n)
(if (zp n)
st
(,run (cdr ,inputs-seq)
(,step (car ,inputs-seq) st)
(1- n))))
(defopener ,open-run-zp
(,run ,inputs-seq st n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,run ,inputs-seq st n))))
(defopener ,open-run
(,run ,inputs-seq st n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,run ,inputs-seq st n))))
(defthm ,run-plus
(implies (and (natp m)
(natp n))
(equal (,run ,inputs-seq st (+ m n))
(,run
(nthcdr m ,inputs-seq)
(,run ,inputs-seq st m)
n)))
:hints (("Goal"
:induct (,run ,inputs-seq st m))))
(in-theory (disable ,run)))
)))
(defmacro input-format-n-gen (name &optional data-size)
(declare (xargs :guard (symbolp name)))
(b* ((input-format (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT"))
(input-format-n (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-N"))
(open-input-format-n-zp (strings-to-symbol "OPEN-"
(symbol-name name)
"$INPUT-FORMAT-N-ZP"))
(open-input-format-n (strings-to-symbol "OPEN-"
(symbol-name name)
"$INPUT-FORMAT-N"))
(input-format-plus (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-PLUS"))
(inputs-seq 'inputs-seq))
(if data-size
`(progn
(defun ,input-format-n (,inputs-seq ,data-size n)
(declare (xargs :guard (and (true-list-listp ,inputs-seq)
(natp ,data-size)
(natp n))
:measure (acl2-count n)))
(if (zp n)
t
(and (,input-format (car ,inputs-seq) ,data-size)
(,input-format-n (cdr ,inputs-seq)
,data-size
(1- n)))))
(defopener ,open-input-format-n-zp
(,input-format-n ,inputs-seq ,data-size n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq ,data-size n))))
(defopener ,open-input-format-n
(,input-format-n ,inputs-seq ,data-size n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq ,data-size n))))
(defthm ,input-format-plus
(implies
(and (natp m)
(natp n))
(equal (,input-format-n ,inputs-seq ,data-size (+ m n))
(and (,input-format-n ,inputs-seq ,data-size m)
(,input-format-n (nthcdr m ,inputs-seq)
,data-size
n))))
:hints (("Goal"
:induct (,input-format-n ,inputs-seq ,data-size m))))
(in-theory (disable ,input-format-n)))
`(progn
(defun ,input-format-n (,inputs-seq n)
(declare (xargs :guard (and (true-list-listp ,inputs-seq)
(natp n))))
(if (zp n)
t
(and (,input-format (car ,inputs-seq))
(,input-format-n (cdr ,inputs-seq) (1- n)))))
(defopener ,open-input-format-n-zp
(,input-format-n ,inputs-seq n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq n))))
(defopener ,open-input-format-n
(,input-format-n ,inputs-seq n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq n))))
(defthm ,input-format-plus
(implies (and (natp m)
(natp n))
(equal (,input-format-n ,inputs-seq (+ m n))
(and (,input-format-n ,inputs-seq m)
(,input-format-n (nthcdr m ,inputs-seq) n)))))
(in-theory (disable ,input-format-n)))
)))
(defmacro input-format-n-with-state-gen (name &optional data-size)
(declare (xargs :guard (symbolp name)))
(b* ((input-format (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT"))
(input-format-n (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-N"))
(open-input-format-n-zp (strings-to-symbol "OPEN-"
(symbol-name name)
"$INPUT-FORMAT-N-ZP"))
(open-input-format-n (strings-to-symbol "OPEN-"
(symbol-name name)
"$INPUT-FORMAT-N"))
(input-format-plus (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-PLUS"))
(step (strings-to-symbol (symbol-name name)
"$STEP"))
(run (strings-to-symbol (symbol-name name)
"$RUN"))
(inputs-seq 'inputs-seq))
(if data-size
`(progn
(defun ,input-format-n (,inputs-seq st ,data-size n)
(declare (xargs :measure (acl2-count n)))
(if (zp n)
t
(and (,input-format (car ,inputs-seq) st ,data-size)
(,input-format-n
(cdr ,inputs-seq)
(,step (car ,inputs-seq) st ,data-size)
,data-size
(1- n)))))
(defopener ,open-input-format-n-zp
(,input-format-n ,inputs-seq st ,data-size n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq st ,data-size n))))
(defopener ,open-input-format-n
(,input-format-n ,inputs-seq st ,data-size n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq st ,data-size n))))
(defthm ,input-format-plus
(implies
(and (natp m)
(natp n))
(equal (,input-format-n ,inputs-seq st ,data-size (+ m n))
(and (,input-format-n ,inputs-seq st ,data-size m)
(,input-format-n
(nthcdr m ,inputs-seq)
(,run ,inputs-seq st ,data-size m)
,data-size
n))))
:hints
(("Goal"
:induct (,input-format-n ,inputs-seq st ,data-size m))))
(in-theory (disable ,input-format-n)))
`(progn
(defun ,input-format-n (,inputs-seq st n)
(declare (xargs :measure (acl2-count n)))
(if (zp n)
t
(and (,input-format (car ,inputs-seq) st)
(,input-format-n (cdr ,inputs-seq)
(,step (car ,inputs-seq) st)
(1- n)))))
(defopener ,open-input-format-n-zp
(,input-format-n ,inputs-seq st n)
:hyp (zp n)
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq st n))))
(defopener ,open-input-format-n
(,input-format-n ,inputs-seq st n)
:hyp (not (zp n))
:hints (("Goal"
:in-theory (theory 'minimal-theory)
:expand (,input-format-n ,inputs-seq st n))))
(defthm ,input-format-plus
(implies (and (natp m)
(natp n))
(equal (,input-format-n ,inputs-seq st (+ m n))
(and (,input-format-n ,inputs-seq st m)
(,input-format-n
(nthcdr m ,inputs-seq)
(,run ,inputs-seq st m)
n))))
:hints (("Goal"
:induct (,input-format-n ,inputs-seq st m))))
(in-theory (disable ,input-format-n)))
)))
;; Proving the correspondence between simulating a DE module and its
;; "hardware" run function.
(defmacro simulate-lemma (name &key
(sizes '(data-size))
(clink 'nil))
(declare (xargs :guard (and (symbolp name)
(symbol-listp sizes)
(booleanp clink))))
(b* ((recognizer (strings-to-symbol (symbol-name name)
"&"))
(outputs (strings-to-symbol (symbol-name name)
"$OUTPUTS"))
(step (strings-to-symbol (symbol-name name)
"$STEP"))
(run (strings-to-symbol (symbol-name name)
"$RUN"))
(input-format (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT"))
(input-format-n (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-N"))
(st-format (strings-to-symbol (symbol-name name)
"$ST-FORMAT"))
(st-format-preserved (strings-to-symbol (symbol-name name)
"$ST-FORMAT-PRESERVED"))
(value-alt (strings-to-symbol (symbol-name name)
"$VALUE-ALT"))
(state-alt (strings-to-symbol (symbol-name name)
"$STATE-ALT"))
(simulate (strings-to-symbol (symbol-name name)
"$DE-N")))
`(progn
(defthm ,st-format-preserved
(implies (,st-format st ,@sizes)
(,st-format (,step inputs st ,@sizes)
,@sizes))
:hints (("Goal"
:in-theory (enable ,step
,st-format))))
(defthmd ,value-alt
(implies (and (,recognizer netlist ,@sizes)
,(if clink
`(,input-format inputs st ,(car sizes))
`(,input-format inputs ,(car sizes)))
(,st-format st ,@sizes))
(equal (se (si ',name ,(car sizes)) inputs st netlist)
(,outputs inputs st ,(car sizes))))
:hints (("Goal"
:in-theory (enable ,input-format))))
(defthmd ,state-alt
(implies (and (,recognizer netlist ,@sizes)
,(if clink
`(,input-format inputs st ,(car sizes))
`(,input-format inputs ,(car sizes)))
(,st-format st ,@sizes))
(equal (de (si ',name ,(car sizes)) inputs st netlist)
(,step inputs st ,@sizes)))
:hints (("Goal"
:in-theory (enable ,input-format))))
(run-gen ,name ,@sizes)
,(if clink
`(input-format-n-with-state-gen ,name ,(car sizes))
`(input-format-n-gen ,name ,(car sizes)))
(defthmd ,simulate
(implies (and (,recognizer netlist ,@sizes)
,(if clink
`(,input-format-n inputs-seq st ,(car sizes) n)
`(,input-format-n inputs-seq ,(car sizes) n))
(,st-format st ,@sizes))
(equal (de-n (si ',name ,(car sizes))
inputs-seq st netlist
n)
(,run inputs-seq st ,@sizes n)))
:hints (("Goal" :in-theory (enable ,run ,state-alt)))))))
;; Data sequence generator
(defmacro seq-gen (name in-out act-name act-idx data
&key
(sizes '(data-size))
(netlist-data 'nil)
(clink 'nil)
(partial-clink 'nil))
(declare (xargs :guard (and (symbolp name)
(symbolp in-out)
(symbolp act-name)
(integerp act-idx)
(symbol-listp sizes)
(booleanp clink)
(booleanp partial-clink))))
(b* ((recognizer (strings-to-symbol (symbol-name name)
"&"))
(input-format-n (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-N"))
(st-format (strings-to-symbol (symbol-name name)
"$ST-FORMAT"))
(act-fn (strings-to-symbol (symbol-name name)
"$"
(symbol-name act-name)))
(act (if clink
`(,act-fn inputs)
`(,act-fn inputs st ,(car sizes))))
(step (strings-to-symbol (symbol-name name)
"$STEP"))
(seq (strings-to-symbol (symbol-name name)
"$"
(symbol-name in-out)
"-SEQ"))
(seq-netlist (strings-to-symbol (symbol-name name)
"$"
(symbol-name in-out)
"-SEQ-NETLIST"))
(seq-lemma (strings-to-symbol (symbol-name name)
"$"
(symbol-name in-out)
"-SEQ-LEMMA"))
(value-alt (strings-to-symbol (symbol-name name)
"$VALUE-ALT"))
(state-alt (strings-to-symbol (symbol-name name)
"$STATE-ALT")))
`(progn
(defun ,seq (inputs-seq st ,@sizes n)
(declare (ignorable st)
(xargs :measure (acl2-count n)))
(if (zp n)
nil
(b* ((inputs (car inputs-seq))
(,act-name ,act)
(data ,data)
(seq (,seq (cdr inputs-seq)
(,step inputs st ,@sizes)
,@sizes
(1- n))))
(if (equal ,act-name t)
(append seq (list data))
seq))))
(defun ,seq-netlist (inputs-seq st netlist ,(car sizes) n)
(declare (ignorable st netlist)
(xargs :measure (acl2-count n)))
(if (zp n)
nil
(b* ((inputs (car inputs-seq))
(?outputs (se (si ',name ,(car sizes))
inputs st netlist))
(,act-name ,(if (natp act-idx)
`(nth ,act-idx outputs)
act))
(data ,(if netlist-data netlist-data data))
(seq (,seq-netlist (cdr inputs-seq)
(de (si ',name ,(car sizes))
inputs st netlist)
netlist
,(car sizes)
(1- n))))
(if (equal ,act-name t)
(append seq (list data))
seq))))
(defthm ,seq-lemma
(implies (and (,recognizer netlist ,@sizes)
,(if (or clink partial-clink)
`(,input-format-n inputs-seq st ,(car sizes) n)
`(,input-format-n inputs-seq ,(car sizes) n))
(,st-format st ,@sizes))
(equal (,seq-netlist inputs-seq st netlist ,(car sizes) n)
(,seq inputs-seq st ,@sizes n)))
:hints (("Goal" :in-theory (enable ,value-alt
,state-alt
,act-fn))))
)
))
;; Formalizing the relationship between input and output sequences
(defmacro in-out-stream-lemma (name &key
(op 'nil)
(inv 'nil)
(clink 'nil))
(declare (xargs :guard (and (symbolp name)
(symbolp op)
(booleanp inv)
(booleanp clink))))
(b* ((recognizer (strings-to-symbol (symbol-name name)
"&"))
(extract (strings-to-symbol (symbol-name name)
"$EXTRACT"))
(extracted-step (strings-to-symbol (symbol-name name)
"$EXTRACTED-STEP"))
(run (strings-to-symbol (symbol-name name)
"$RUN"))
(de-n-lemma (strings-to-symbol (symbol-name name)
"$DE-N"))
(input-format-n (strings-to-symbol (symbol-name name)
"$INPUT-FORMAT-N"))
(valid-st (strings-to-symbol (symbol-name name)
"$VALID-ST"))
(valid-st=>st-format (strings-to-symbol (symbol-name name)
"$VALID-ST=>ST-FORMAT"))
(st-inv (strings-to-symbol (symbol-name name)
"$INV"))
(in-seq (strings-to-symbol (symbol-name name)
"$IN-SEQ"))
(in-seq-netlist (strings-to-symbol (symbol-name name)
"$IN-SEQ-NETLIST"))
(out-seq (strings-to-symbol (symbol-name name)
"$OUT-SEQ"))
(out-seq-netlist (strings-to-symbol (symbol-name name)
"$OUT-SEQ-NETLIST"))
(op-map (strings-to-symbol (symbol-name op) "-MAP"))
(seq (if op
`(,op-map seq)
`(,in-seq inputs-seq st data-size n)))
(hyps (if inv
`(and ,(if clink
`(,input-format-n inputs-seq st data-size n)
`(,input-format-n inputs-seq data-size n))
(,valid-st st data-size)
(,st-inv st))
`(and ,(if clink
`(,input-format-n inputs-seq st data-size n)
`(,input-format-n inputs-seq data-size n))
(,valid-st st data-size))))
(netlist-hyps
(if inv
`(and (,recognizer netlist data-size)
,(if clink
`(,input-format-n inputs-seq st data-size n)
`(,input-format-n inputs-seq data-size n))
(,valid-st st data-size)
(,st-inv st))
`(and (,recognizer netlist data-size)
,(if clink
`(,input-format-n inputs-seq st data-size n)
`(,input-format-n inputs-seq data-size n))
(,valid-st st data-size))))
(concl (if op
`(equal (append final-extracted-st
(,out-seq inputs-seq st data-size n))
(append (,op-map
(,in-seq inputs-seq st data-size n))
extracted-st))
`(equal (append final-extracted-st
(,out-seq inputs-seq st data-size n))
(append (,in-seq inputs-seq st data-size n)
extracted-st))))
(netlist-concl
(if op
`(equal (append final-extracted-st
(,out-seq-netlist
inputs-seq st netlist data-size n))
(append (,op-map
(,in-seq-netlist
inputs-seq st netlist data-size n))
extracted-st))
`(equal (append final-extracted-st
(,out-seq-netlist
inputs-seq st netlist data-size n))
(append (,in-seq-netlist
inputs-seq st netlist data-size n)
extracted-st))))
(dataflow-correct-aux (strings-to-symbol (symbol-name name)
"$DATAFLOW-CORRECT-AUX"))
(dataflow-correct (strings-to-symbol (symbol-name name)
"$DATAFLOW-CORRECT"))
(functionally-correct (strings-to-symbol (symbol-name name)
"$FUNCTIONALLY-CORRECT")))
`(encapsulate
()
(local
(defthm ,dataflow-correct-aux
(implies (equal (append x y1)
(append ,seq y2))
(equal (append x y1 z)
(append ,seq y2 z)))
:hints (("Goal" :in-theory (e/d (left-associativity-of-append)
(associativity-of-append))))))
(defthmd ,dataflow-correct
(b* ((extracted-st (,extract st))
(final-st (,run inputs-seq st data-size n))
(final-extracted-st (,extract final-st)))
(implies ,hyps ,concl))
:hints (("Goal" :in-theory (enable ,extracted-step))))
(defthmd ,functionally-correct
(b* ((extracted-st (,extract st))
(final-st (de-n (si ',name data-size)
inputs-seq st netlist n))
(final-extracted-st (,extract final-st)))
(implies ,netlist-hyps ,netlist-concl))
:hints (("Goal"
:use ,dataflow-correct
:in-theory (enable ,valid-st=>st-format
,de-n-lemma))))
)))
|