|
|
|
|
@ -63,14 +63,14 @@ Create an actual lisp function from the gate list |
|
|
|
|
(update-function gates) |
|
|
|
|
#+end_src |
|
|
|
|
According to the following check, the code is symmetric in x and y |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(defun check-symmetry (gates) |
|
|
|
|
(--every (eq (-elem-index (car (-intersection it used-xxx)) used-xxx) |
|
|
|
|
(-elem-index (car (-intersection it used-yyy)) used-yyy)) |
|
|
|
|
(-elem-index (car (-intersection it used-yyy)) used-yyy)) |
|
|
|
|
(-map #'car |
|
|
|
|
(--filter (or (-intersection (car it) used-xxx) |
|
|
|
|
(-intersection (car it) used-yyy)) gates))) |
|
|
|
|
) |
|
|
|
|
(--filter (or (-intersection (car it) used-xxx) |
|
|
|
|
(-intersection (car it) used-yyy)) |
|
|
|
|
gates)))) |
|
|
|
|
|
|
|
|
|
(check-symmetry gates) |
|
|
|
|
#+end_src |
|
|
|
|
@ -78,42 +78,149 @@ According to the following check, the code is symmetric in x and y |
|
|
|
|
#+RESULTS: |
|
|
|
|
: t |
|
|
|
|
|
|
|
|
|
Create a list of all x, y and z bits |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(setq |
|
|
|
|
used-xxx (--filter |
|
|
|
|
(string-match-p "^x.*" (symbol-name it)) wires) |
|
|
|
|
used-yyy (--filter |
|
|
|
|
(string-match-p "^y.*" (symbol-name it)) wires) |
|
|
|
|
used-zzz (--filter |
|
|
|
|
(string-match-p "^z.*" (symbol-name it)) wires)) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now we rename the wires in some more meaningful sense |
|
|
|
|
first create a bunch of aux variables |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
Now we rename the wires in some more meaningful way |
|
|
|
|
First create a bunch of aux labels for the wires |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(let ((bits (-iterate #'1+ 0 (length used-zzz)))) |
|
|
|
|
(setq X-wires (--map (intern (format "X%02d" it)) bits) |
|
|
|
|
A-wires (--map (intern (format "A%02d" it)) bits) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
A-wires |
|
|
|
|
(check-symmetry gates) |
|
|
|
|
A-wires (--map (intern (format "A%02d" it)) bits))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(defun rename-gate (gate) |
|
|
|
|
(if (-contains? used-zzz (caddr gate)) |
|
|
|
|
gate |
|
|
|
|
(concat (symbol-name (cadr gate)) |
|
|
|
|
(symbol-name (caar gate)) |
|
|
|
|
(symbol-name (cadar gate)) |
|
|
|
|
"→" |
|
|
|
|
(symbol-name (caddr gate)) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
(defun rename-gates (gates) |
|
|
|
|
(-map #'rename-gate (--filter (-intersection (car it) used-xxx) gates) |
|
|
|
|
)) |
|
|
|
|
|
|
|
|
|
(rename-gates gates) |
|
|
|
|
Then we begin by renaming the input layer XOR gates and the AND gates |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(defun rename-gate-1 (gate) |
|
|
|
|
(unless (-contains? used-zzz (caddr gate)) |
|
|
|
|
(when (-intersection (car gate) used-xxx) |
|
|
|
|
(let ((index (-elem-index (car (-intersection (car gate) used-xxx)) used-xxx)) |
|
|
|
|
(aux-list (if (eq (cadr gate) 'XOR) X-wires A-wires))) |
|
|
|
|
(cons (caddr gate) (nth index aux-list)))))) |
|
|
|
|
|
|
|
|
|
(defun create-list-rename-wires-1 (gates) |
|
|
|
|
(-non-nil (-map #'rename-gate-1 gates))) |
|
|
|
|
|
|
|
|
|
(defun replace-in-list (al li) |
|
|
|
|
"replace an element of list with the corresponding element listed in al" |
|
|
|
|
(--map (let ((to (assoc it al))) (if to (cdr to) it)) li)) |
|
|
|
|
|
|
|
|
|
(defun replace-wire (al gate) |
|
|
|
|
(let ((gate (replace-in-list al gate))) |
|
|
|
|
(list (replace-in-list al (car gate)) (cadr gate) (caddr gate)))) |
|
|
|
|
|
|
|
|
|
(defun replace-wires (al gates) |
|
|
|
|
(--map (replace-wire al it) gates)) |
|
|
|
|
|
|
|
|
|
;(setq gates (swap-output '(z11 . wpd) gates)) |
|
|
|
|
|
|
|
|
|
(setq gates-1 |
|
|
|
|
(replace-wires (create-list-rename-wires gates) gates)) |
|
|
|
|
|
|
|
|
|
(--filter (eq (cadr it) 'XOR) gates-1) |
|
|
|
|
(update-function gates) |
|
|
|
|
|
|
|
|
|
(run-function 1024 1024) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
| ANDy33x33→bfn | XORy32x32→rck | ANDx30y30→gns | XORy36x36→hbh | ((x00 y00) XOR z00) | XORy26x26→wkb | ANDx31y31→hjq | XORy43x43→fhk | ANDx27y27→kbf | XORy17x17→hbw | XORx01y01→kjs | XORx05y05→fds | ANDx07y07→jbw | ANDy32x32→wnt | XORx14y14→cgg | XORy41x41→jhg | XORy21x21→csw | XORy20x20→bvw | ANDx13y13→rbg | ANDx01y01→fqg | ANDy36x36→jdc | ANDx08y08→gdd | ((y19 x19) AND z19) | XORx31y31→rms | XORx23y23→mcp | ANDy38x38→jhv | XORy16x16→rvn | XORy25x25→prp | ANDy26x26→tjq | XORy12x12→htn | ANDx42y42→hnh | ANDy05x05→hpn | ANDx14y14→ttv | XORy08x08→rjs | XORy42x42→cng | ANDx35y35→qtv | XORy02x02→rvm | ANDy28x28→rsv | XORx06y06→jtg | XORy09x09→kbb | ANDy23x23→fnc | XORy29x29→hvc | XORx44y44→jsg | ANDx40y40→bdn | ANDx41y41→ncf | XORy27x27→tvf | ANDy34x34→bnw | ANDy21x21→nrg | XORx38y38→sqj | ANDy18x18→wfm | XORx19y19→cmp | XORy24x24→gww | XORy39x39→vqf | ANDx12y12→bnn | XORx10y10→rmb | XORy33x33→wmq | XORx18y18→hns | ANDy25x25→cqg | ANDy00x00→hjp | XORx35y35→djt | ANDy24x24→tcq | ANDx02y02→nhp | XORy04x04→jvf | XORy03x03→sbt | ANDy29x29→bsw | ANDx03y03→gfk | XORx15y15→jqf | XORy30x30→nnn | ANDy43x43→dbj | ANDx17y17→cwn | ANDy20x20→jgg | ANDx04y04→gwv | ANDx16y16→rhd | ANDx06y06→hhw | XORx28y28→kdd | ANDy39x39→ppk | ANDy11x11→dpf | XORx40y40→nns | ANDy09x09→csb | XORy37x37→wpp | XORx34y34→nss | ANDy37x37→rhh | XORy11x11→gkc | XORx07y07→qpc | ANDx15y15→skh | XORy22x22→wwp | XORx13y13→dmp | ANDy10x10→gvj | ANDx44y44→jsp | ANDy22x22→gmf | |
|
|
|
|
| (qqw X11) | XOR | z11 | |
|
|
|
|
| (y32 x32) | XOR | X32 | |
|
|
|
|
| (y36 x36) | XOR | X36 | |
|
|
|
|
| (X42 mwt) | XOR | z42 | |
|
|
|
|
| (x00 y00) | XOR | z00 | |
|
|
|
|
| (y26 x26) | XOR | X26 | |
|
|
|
|
| (y43 x43) | XOR | X43 | |
|
|
|
|
| (wrc X17) | XOR | z17 | |
|
|
|
|
| (A15 rkt) | XOR | z15 | |
|
|
|
|
| (y17 x17) | XOR | X17 | |
|
|
|
|
| (X31 sgf) | XOR | z31 | |
|
|
|
|
| (X24 jmf) | XOR | z24 | |
|
|
|
|
| (x01 y01) | XOR | X01 | |
|
|
|
|
| (x05 y05) | XOR | X05 | |
|
|
|
|
| (x14 y14) | XOR | X14 | |
|
|
|
|
| (X35 khf) | XOR | z35 | |
|
|
|
|
| (y41 x41) | XOR | X41 | |
|
|
|
|
| (y21 x21) | XOR | X21 | |
|
|
|
|
| (jkm X13) | XOR | z13 | |
|
|
|
|
| (y20 x20) | XOR | X20 | |
|
|
|
|
| (wvt X03) | XOR | z03 | |
|
|
|
|
| (X41 gfd) | XOR | z41 | |
|
|
|
|
| (wfc X19) | XOR | mdd | |
|
|
|
|
| (X14 rhf) | XOR | z14 | |
|
|
|
|
| (X26 jkr) | XOR | z26 | |
|
|
|
|
| (x31 y31) | XOR | X31 | |
|
|
|
|
| (pwp X30) | XOR | z30 | |
|
|
|
|
| (x23 y23) | XOR | X23 | |
|
|
|
|
| (X04 jth) | XOR | z04 | |
|
|
|
|
| (y16 x16) | XOR | X16 | |
|
|
|
|
| (y25 x25) | XOR | X25 | |
|
|
|
|
| (y12 x12) | XOR | X12 | |
|
|
|
|
| (X23 mkf) | XOR | z23 | |
|
|
|
|
| (dts X33) | XOR | z33 | |
|
|
|
|
| (rfq X36) | XOR | z36 | |
|
|
|
|
| (X40 jbd) | XOR | z40 | |
|
|
|
|
| (jmv X34) | XOR | z34 | |
|
|
|
|
| (y08 x08) | XOR | X08 | |
|
|
|
|
| (y42 x42) | XOR | X42 | |
|
|
|
|
| (y02 x02) | XOR | X02 | |
|
|
|
|
| (wpb X09) | XOR | z09 | |
|
|
|
|
| (x06 y06) | XOR | X06 | |
|
|
|
|
| (kmr X10) | XOR | z10 | |
|
|
|
|
| (X16 kbq) | XOR | z16 | |
|
|
|
|
| (y09 x09) | XOR | X09 | |
|
|
|
|
| (gsk X43) | XOR | z43 | |
|
|
|
|
| (y29 x29) | XOR | X29 | |
|
|
|
|
| (X27 cmb) | XOR | z27 | |
|
|
|
|
| (X20 hvn) | XOR | z20 | |
|
|
|
|
| (x44 y44) | XOR | X44 | |
|
|
|
|
| (X38 wts) | XOR | z38 | |
|
|
|
|
| (qvq X18) | XOR | z18 | |
|
|
|
|
| (y27 x27) | XOR | X27 | |
|
|
|
|
| (X02 vdq) | XOR | z02 | |
|
|
|
|
| (whf X05) | XOR | z05 | |
|
|
|
|
| (x38 y38) | XOR | X38 | |
|
|
|
|
| (x19 y19) | XOR | X19 | |
|
|
|
|
| (y24 x24) | XOR | X24 | |
|
|
|
|
| (y39 x39) | XOR | X39 | |
|
|
|
|
| (qpm X21) | XOR | z21 | |
|
|
|
|
| (smt X37) | XOR | wts | |
|
|
|
|
| (x10 y10) | XOR | X10 | |
|
|
|
|
| (y33 x33) | XOR | X33 | |
|
|
|
|
| (x18 y18) | XOR | X18 | |
|
|
|
|
| (A00 X01) | XOR | z01 | |
|
|
|
|
| (x35 y35) | XOR | X35 | |
|
|
|
|
| (tsk X29) | XOR | z29 | |
|
|
|
|
| (y04 x04) | XOR | X04 | |
|
|
|
|
| (pfc X25) | XOR | z25 | |
|
|
|
|
| (y03 x03) | XOR | X03 | |
|
|
|
|
| (X39 fkq) | XOR | z39 | |
|
|
|
|
| (x15 y15) | XOR | X15 | |
|
|
|
|
| (y30 x30) | XOR | X30 | |
|
|
|
|
| (X12 dtq) | XOR | z12 | |
|
|
|
|
| (X44 hks) | XOR | z44 | |
|
|
|
|
| (msf X28) | XOR | z28 | |
|
|
|
|
| (X08 tmg) | XOR | z08 | |
|
|
|
|
| (x28 y28) | XOR | X28 | |
|
|
|
|
| (x40 y40) | XOR | X40 | |
|
|
|
|
| (y37 x37) | XOR | X37 | |
|
|
|
|
| (x34 y34) | XOR | X34 | |
|
|
|
|
| (X32 ftq) | XOR | z32 | |
|
|
|
|
| (y11 x11) | XOR | X11 | |
|
|
|
|
| (x07 y07) | XOR | X07 | |
|
|
|
|
| (y22 x22) | XOR | X22 | |
|
|
|
|
| (x13 y13) | XOR | X13 | |
|
|
|
|
| (qmb X07) | XOR | z07 | |
|
|
|
|
| (X06 cfn) | XOR | z06 | |
|
|
|
|
| (X22 bvr) | XOR | z22 | |
|
|
|
|
|
|
|
|
|
; dpf gck |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
@ -122,7 +229,7 @@ first create a bunch of aux variables |
|
|
|
|
(run-function (car it) (cdr it))) |
|
|
|
|
(-zip-pair (-iterate #'1+ 0 1024) |
|
|
|
|
(-iterate #'1- 2048 1024))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(run-function 4096 0) |
|
|
|
|
;(run-function 32 32) |
|
|
|
|
#+end_src |
|
|
|
|
@ -224,16 +331,7 @@ first create a bunch of aux variables |
|
|
|
|
|
|
|
|
|
(run-function 2048 0) |
|
|
|
|
|
|
|
|
|
Create a list of all x, y and z bits |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(setq |
|
|
|
|
used-xxx (--filter |
|
|
|
|
(string-match-p "^x.*" (symbol-name it)) wires) |
|
|
|
|
used-yyy (--filter |
|
|
|
|
(string-match-p "^y.*" (symbol-name it)) wires) |
|
|
|
|
used-zzz (--filter |
|
|
|
|
(string-match-p "^z.*" (symbol-name it)) wires)) |
|
|
|
|
#+end_src |
|
|
|
|
(setq depth 0) |
|
|
|
|
|
|
|
|
|
Define the functions that implement the code on the wires |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
@ -248,7 +346,7 @@ Define the functions that implement the code on the wires |
|
|
|
|
output wires are set and nil otherwise" |
|
|
|
|
(let* ((ew (eval-wires)) |
|
|
|
|
(old-ew)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(while (not (equal old-ew ew)) |
|
|
|
|
(funcall fn) |
|
|
|
|
(setq old-ew ew |
|
|
|
|
@ -423,7 +521,7 @@ We can "propagate" this information |
|
|
|
|
(update-function (swap-output it gates)) |
|
|
|
|
(lsb-works)) |
|
|
|
|
(tentative-substitutions)) |
|
|
|
|
(let ((gates (swap-output '(z11 . z12) gates))) |
|
|
|
|
(let ((gates (swap-output '(z11 . wpd) gates))) |
|
|
|
|
(tentative-substitutions)) |
|
|
|
|
|
|
|
|
|
(run-function 1 1) |
|
|
|
|
|