Numeration and Computer Arithmetic 1/31 Numeration and Computer Arithmetic Some Examples JC Bajard LIRMM, CNRS UM2 161 rue Ada, 34392 Montpellier cedex 5, France April 2007
Numeration and Computer Arithmetic 2/31 Computer Arithmetic Compromise: Heart: Approaches: ◮ Speed ◮ Number ◮ Theory representations ◮ Accuracy ◮ Software ◮ Associated ◮ Cost ◮ Hardware algorithms
Numeration and Computer Arithmetic 3/31 Contents Function Evaluation Redundant Number Systems Number Systems for Modular Arithmetic Conclusion Annexes
Numeration and Computer Arithmetic 4/31 Function Evaluation Function Evaluation an example of numeration
Numeration and Computer Arithmetic 5/31 Function Evaluation Briggs Algorithm (1561-1630) ◮ Evaluation of the logarithm, constructions of the first tables (15 decimal digits, 1624). ◮ In radix 2: digits d k = − 1 , 0 , 1, such that for a given x we have n � (1 + d k 2 − k ) ≃ 1 x k =1 ◮ The logarithm of x is n � ln(1 + d k 2 − k ) ln( x ) ≃ − k =1
Numeration and Computer Arithmetic 6/31 Function Evaluation CORDIC Algorithm (COrdinate Rotation DIgital Computer, VOLDER 1959) Basic step d n ∈ {− 1 , 1 } (sign of z ). x n − d n y n 2 − n K sin θ x n +1 = y n + d n x n 2 − n = y n +1 θ z n − d n arctan(2 − n ) z n +1 = K cos θ For cosine and sine: n ≥ 0 d n arctan(2 − n )) x 0 = 1 , y 0 = 0 , z 0 = θ (= � Constant factor √ 1 + 2 − 2 n = 1 . 646760 ... K = � ∞ n =0
Numeration and Computer Arithmetic 7/31 Function Evaluation Complex algorithm (BKM 1993) Basic step of the complex algorithm: � E k +1 = E k (1 + d k 2 − k ) = L k − ln(1 + d k 2 − k ) L k +1 with d k = d r k + id i k , and d r k , d i k = − 1 , 0 , 1. Two evaluation modes → 1 ◮ L-mode : E n L n → L 1 + ln( E 1 ) L n → 0 ◮ E-mode : E 1 e L 1 E n → 26 12
Numeration and Computer Arithmetic 8/31 Function Evaluation n n 1 � � (1 + d i 2 − i ) → L n = − ln(1 + d i 2 − i ) = ln( E 1 ) = E 1 i =1 i =1
Numeration and Computer Arithmetic 9/31 Redundant Number Systems Redundant Number Systems
Numeration and Computer Arithmetic 10/31 Redundant Number Systems Avizienis (1961) ◮ Redundant Number Systems Signed digits: x i ∈ {− a , . . . , − 1 , 0 , 1 , . . . , a } Radix β with a ≤ β − 1. ◮ Properties ◮ If 2 a +1 ≥ β , then each integer has at least one representation. An integer X , with − a β n − 1 β − 1 ≤ X < a β n − 1 β − 1 , admits a unique representation n − 1 � x i β i X = with x i ∈ {− a , · · · − 1 , 0 , 1 , . . . , a } i =0 ◮ If 2 a ≥ β + 1, then we have a carry free algorithm. 25 ◮ Borrow-save (Duprat, Muller 1989): extension to radix 2.
Numeration and Computer Arithmetic 11/31 Redundant Number Systems Example: radix 10, a = 9 235942 (= − 164138) + 46167 (= 46047) 011110 (= t ) 271001 (= w ) 282111 (= s = − 118091)
Numeration and Computer Arithmetic 12/31 Redundant Number Systems Properties of the signed digits redundant systems ◮ Advantages: ◮ Constant time carry-free addition ◮ Large radix: parallelisation ◮ Small radix: fast circuits ◮ Increasing of the performances of the algorithms based on the addition 7 ◮ Drawbacks: comparisons, sign...
Numeration and Computer Arithmetic 13/31 Redundant Number Systems Non-Adjacent Form ◮ This representation is inspired from Booth recoding (1951) used in multipliers. ◮ Definition of NAF w recoding: (Reitwiesner 1960) Let k be an integer and w ≥ 2. The non-adjacent form of weight w of l − 1 k i 2 i where | k i | < 2 w − 1 , k l − 1 � = 0 and � k is given by k = i =0 each w -bit word contains at most one non-zero digit. 1. For a given k , NAF w ( k ) is unique. 2. For a given w ≥ 2, the length of NAF w ( k ) is at most equal to the length of k plus one. 3. The average density of non-zero digits is 1 / ( w + 1). 27 28
Numeration and Computer Arithmetic 14/31 Redundant Number Systems NAF w Examples We consider k = 31415592. k 2 = 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 0 1 0 0 1 0 1 0 0 0 NAF 2 ( k ) = 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 0 NAF 3 ( k ) = 1 0 0 0 1 0 0 0 0 1 0 0 3 0 0 0 1 0 0 3 0 0 3 0 0 0 NAF 4 ( k ) = 1 0 0 0 1 0 0 0 0 0 0 0 5 0 0 0 0 3 0 0 0 0 5 0 0 0 NAF 5 ( k ) = 15 0 0 0 0 0 0 0 5 0 0 0 0 3 0 0 0 0 5 0 0 0 NAF 6 ( k ) = 15 0 0 0 0 0 1 0 0 0 0 0 17 0 0 0 0 0 27 0 0 0
Numeration and Computer Arithmetic 15/31 Number Systems for Modular Arithmetic Number Systems for Modular Arithmetic
Numeration and Computer Arithmetic 16/31 Number Systems for Modular Arithmetic Lattices and Modular Systems ◮ Number system: radix β and a set of digits { 0 , ..., β − 1 } . n − 1 0 ≤ A < β n is expanded as: A = � a i β i . i =0 ◮ We denote by P the modulo, with P < β n , n − 1 β n (mod P ) = ǫ i β i with ǫ i ∈ { 0 , ..., β − 1 } � i =0 ◮ A modular operation (for example: a modular multiplication): 1. Polynomial operation: W ( X ) = A ( X ) � B ( X ) n − 1 2. Polynomial reduction : V ( X ) = W ( X ) mod ( X n − � ǫ i X i ) i =0 3. Coefficient reduction : M ( X ) = Reductcoeff( V ( X ))
Numeration and Computer Arithmetic 17/31 Number Systems for Modular Arithmetic Lattices and Modular Systems Lattice approach In a classical system ”Reductcoeff” is equivalent to a combination of the carry propagation and the modular reduction: − β 1 ... 0 0 − β 1 ... 0 0 0 − β ... 0 0 0 − β ... 0 0 ← lattice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sublattice → 0 0 ... − β 1 0 0 ... − β 1 P 0 ... 0 0 ǫ 0 ǫ 1 ... ǫ n − 2 ( ǫ n − 1 − β )
Numeration and Computer Arithmetic 18/31 Number Systems for Modular Arithmetic Lattices and Modular Systems Example For P = 97 and β = 10, we have 10 2 ≡ 3 (mod P ). We consider the lattice: � B 0 � − 10 � � 1 = B 1 3 − 10 Let V (25 , 12) = 25 + 12 β . For reducing V , we determine G (17 , 8) = − 2 B 0 − B 1 a vector of the lattice close to V . Thus , V (25 , 12) ≡ M (8 , 4) = V (25 , 12) − G (17 , 8). We verify that 25 + 120 = 145 ≡ 48 (mod 97)
Numeration and Computer Arithmetic 19/31 Number Systems for Modular Arithmetic Lattices and Modular Systems Example The reduction is equivalent with finding a close vector. Let G ( X ) be this vector, then M ( X ) = V ( x ) − G ( X ) q q q q V(25,12) ❛ G q q q q q q q M q ❛ q q q q q q q q q q P = 97 β = 10 q q
Numeration and Computer Arithmetic 20/31 Number Systems for Modular Arithmetic Lattices and Modular Systems A new system ◮ Polynomial reduction depends of the representation of β n (mod P ) ◮ In Thomas Plantard’s PhD (2005), β can be as large as P , but with a set of digits { 0 , ..., ρ − 1 } where ρ is small. Example: Let us consider a MNS defined with P = 17 , n = 3 , β = 7 , ρ = 2. Over this system, we represent the elements of Z 17 as polynomials in β , of degree at most 2, with coefficients in {− 1 , 0 , 1 }
Numeration and Computer Arithmetic 21/31 Number Systems for Modular Arithmetic Lattices and Modular Systems A new system 0 1 2 3 4 5 − β 2 1 − β 2 − 1 + β + β 2 β + β 2 0 1 6 7 8 9 10 11 − 1 + β β 1 + β − 1 − β − β 1 − β 12 13 14 15 16 − β − β 2 1 − β − β 2 − 1 + β 2 β 2 1 + β 2 The system is clearly redundant. For example: 6 = 1 + β + β 2 = − 1 + β , or 9 = 1 − β + β 2 = − 1 − β .
Numeration and Computer Arithmetic 22/31 Number Systems for Modular Arithmetic Lattices and Modular Systems Construction of Plantard Systems ◮ In a first approach, n and ρ = 2 k are fixed. The lattice is constructed from the representation of ρ in the number system. P and β are deduced. Efficient algorithm for finding a close vector. 31 ◮ In a general approach, where P , β and n are given, the determination of ρ is obtained by reducing with LLL (Lenstra Lenstra Lovasz, 1982). No efficient algorithm for finding a close vector. 29
Numeration and Computer Arithmetic 23/31 Conclusion Conclusion Thank you!
Numeration and Computer Arithmetic 24/31 Annexes Annexes
Numeration and Computer Arithmetic 25/31 Annexes Annexe: Avizienis Algorithm 10 ◮ We note S = X + Y with X = x n − 1 ... x 0 Y = y n − 1 ... y 0 S = s n ... s 0 ◮ Step 1: For i = 1 to n in parallel, t i +1 = 1 if, x i + y i < − a + 1 1 if, x i + y i > a − 1 0 if, − a + 1 ≤ x i + y i ≤ a − 1 and w i = x i + y i − β ∗ t i +1 with w n = t 0 = 0 ◮ Step 2: for i = 0 to n in parallel, s i = w i + t i
Numeration and Computer Arithmetic 26/31 Annexes Annexe: Functions computable using one mode of BKM 7 be a b 1 cos θ a c E x E x E x E x E x E x 1 n 1 n 1 n E-mode E-mode E-mode 0 0 0 sin θ b d E y E y E y E y E y E y 1 n 1 n 1 n a 0 0 0 0 0 L x L x L x L x L x L x 1 n 1 n 1 n 0 0 θ 0 θ 0 L y L y L y L y L y L y 1 n 1 n 1 n a 1 a 1 E x E x E x E x 1 n 1 n L-mode L-mode 0 0 b 0 E y E y E y E y 1 n 1 n √ a 2 + b 2 0 ln a 0 ln L x L x L x L x 1 n 1 n arctan b 0 0 0 L y L y L y L y a 1 n 1 n � cos θ − sin θ ( c ( a � d ) = b ) sin θ cos θ
Recommend
More recommend