# 2017q3 Homework1 (ternary) ### 平衡三進位(Balanced Ternary) 平衡三進位,是一種以3為基數以(T,0,1)為基本數位的進位。 `T`表示-1 `0`表示 0 `1`表示 1 - 轉10進位算式 * 其中a與c以小數點隔開 $$ (a_{n}a_{n-1}\cdots a_{1}a_{0}.c_{1}c_{2}c_{3}\cdots)=\sum_{k=0}^{n}a_{k}b^k+\sum_{k=1}^{\infty}c_{k}b^{-k} $$ - 轉10進位範例 * 整數 $$ 10_{bal3} = 1×3^1 + 0×3^0 = 3_{dec} $$ * 小數 $$ 10_{bal3} = 1×3^1 + 0×3^0 = 3_{dec} $$ * 不需要額外的符號就能直接表示負數。因此平衡三進位在加減法和乘法的效率要比二進位高。 * 美國著名電腦學家高德納在《編程的藝術》一書中指出,「也許最美的進位是平衡三進位」 ### Balanced Ternary基礎運算操作 * Addition | + | T | 0 | 1 | | - | - | - | - | | T | T1| T | 0 | | 0 | T | 0 | 1 | | 1 | 0 | 1 | 1T | * Subtraction | − | T | 0 | 1 | | - | - | - | - | | T | 0 | T | T1 | | 0 | 1 | 0 | T | | 1 | 1T| 1 | 0 | * Multiplication | × | T | 0 | 1 | | - | - | - | - | | T | 1 | 0 | T | | 0 | 0 | 0 | 0 | | 1 | T | 0 | 1 | * Division | ÷ | T | 0 | 1 | | - | - | - | - | | T | 1 | NAN | T | | 0 | 0 | NAN | 0 | | 1 | T | NAN | 1 | ### 使用Balanced Ternary多工器 * 多工器腳位介紹 ![](https://raw.githubusercontent.com/ssloy/tutorials/master/ternary/doc/multiplexer.png) * 由sel決定OUTPUT的電位 * 多工器實現半加法器 ![](https://raw.githubusercontent.com/ssloy/tutorials/master/ternary/doc/A%2BB.png) * 前半段先計算好結果,後半段再由B決定OUTPUT哪個結果 * 多工器實現全加法器(包含進位) ![](https://raw.githubusercontent.com/ssloy/tutorials/master/ternary/doc/A%2BB%2BCin.png) * 使用兩個半加法實現全加法 * 多工器實現Consensus * consensus=-1 , if A=B=-1. * consensus= 1 , if A=B= 1. * consensus= 0 , otherwise. ![](https://raw.githubusercontent.com/ssloy/tutorials/master/ternary/doc/cons(A%2CB).png) * 多工器實現Overflow ![](https://raw.githubusercontent.com/ssloy/tutorials/master/ternary/doc/overflow.png) * 跟前面的有點像,先配好正確的輸出再從SEL去做選擇,只是變成兩階式的 ### Reference [Wikipedia-Balanced ternary](https://en.wikipedia.org/wiki/Balanced_ternary) [Ternary computing: basics ](https://github.com/ssloy/tutorials/wiki/Ternary-computing:-basics)