Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster (Revised 02/02/2009)

Similar documents
The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Divide: Paper & Pencil

A Comparative Analysis of Mark 1, Colossus and Zuse Z4. Chris Collins. 24 th September 2006

Chapter 3: Arithmetic for Computers

Computer Architecture and Organization

Floating Point Arithmetic

Principles of Computer Architecture. Chapter 3: Arithmetic

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Module 2: Computer Arithmetic

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

CHAPTER 1 Numerical Representation

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

ECE331: Hardware Organization and Design

Introduction to Computers and Programming. Numeric Values

COMPUTER ORGANIZATION AND ARCHITECTURE

perform. If more storage is required, more can be added without having to modify the processor (provided that the extra memory is still addressable).

Reconstruction of Konrad Zuse s Z3

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers Implementation

Organisasi Sistem Komputer

Lecture #15 March 3, 2004 A Worked Problem in Floating Point

Number Systems. Both numbers are positive

Objectives. Connecting with Computer Science 2

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

Introduction to Modular Arithmetic

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

MA 1128: Lecture 02 1/22/2018

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Chapter 2. Data Representation in Computer Systems

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Floating-Point Arithmetic

Floating Point. What can be represented in N bits? 0 to 2N-1. 9,349,398,989,787,762,244,859,087, x 1067

Introduction to Computer Systems Recitation 2 May 29, Marjorie Carlson Aditya Gupta Shailin Desai

CS321. Introduction to Numerical Methods

Timing for Ripple Carry Adder

Number Systems and Computer Arithmetic

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Arithmetic Circuits. Design of Digital Circuits 2014 Srdjan Capkun Frank K. Gürkaynak.

Floating-Point Numbers in Digital Computers

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

CS321 Introduction To Numerical Methods

Divisibility Rules and Their Explanations

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

3.1 DATA REPRESENTATION (PART C)

Floating Point Arithmetic

Slide 1 / 180. Radicals and Rational Exponents

COPYRIGHTED MATERIAL. Number Systems. 1.1 Analogue Versus Digital

Chapter Three. Arithmetic

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

1.2 Round-off Errors and Computer Arithmetic

Bits, Words, and Integers

2 Computation with Floating-Point Numbers

Mathematical preliminaries and error analysis

Topic Notes: Bits and Bytes and Numbers

Excerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.

COMP Overview of Tutorial #2

SAMLab Tip Sheet #1 Translating Mathematical Formulas Into Excel s Language

Review: MIPS Organization

The Practical Use of the Bemer Method for Exponentials Update Version: September 5, 2006 Ron Doerfler (

Digital Computers and Machine Representation of Data

Floating Point. EE 109 Unit 20. Floating Point Representation. Fixed Point

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

Chapter 9: A Closer Look at System Hardware

Topic Notes: Bits and Bytes and Numbers

Machine Arithmetic 8/31/2007

ECE232: Hardware Organization and Design

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

Chapter 9: A Closer Look at System Hardware 4

Approximating Square Roots

In this article, we present and analyze

A Multiple-Precision Division Algorithm

CS 5803 Introduction to High Performance Computer Architecture: Arithmetic Logic Unit. A.R. Hurson 323 CS Building, Missouri S&T

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

A Multiple -Precision Division Algorithm. By David M. Smith

Floating-Point Numbers in Digital Computers

2 Computation with Floating-Point Numbers

Chapter 5. Radicals. Lesson 1: More Exponent Practice. Lesson 2: Square Root Functions. Lesson 3: Solving Radical Equations

Numerical computing. How computers store real numbers and the problems that result

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

ECE260: Fundamentals of Computer Engineering

Computer Sc. & IT. Digital Logic. Computer Sciencee & Information Technology. 20 Rank under AIR 100. Postal Correspondence

College Prep Algebra II Summer Packet

Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

By, Ajinkya Karande Adarsh Yoga

EE 109 Unit 20. IEEE 754 Floating Point Representation Floating Point Arithmetic

UNIT-III COMPUTER ARTHIMETIC

6.1 Evaluate Roots and Rational Exponents

Chapter 3 Data Representation

Chapter 10 - Computer Arithmetic

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Introduction to Scientific Computing Lecture 1

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

VHDL IMPLEMENTATION OF IEEE 754 FLOATING POINT UNIT

IEEE Standard for Floating-Point Arithmetic: 754

FPGA Implementation of Multiplier for Floating- Point Numbers Based on IEEE Standard

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Chapter 4. Operations on Data

Transcription:

Zuse's Z3 Square Root Algorithm Tal given at Fall meeting of the Ohio Section of the MAA October 999 - College of Wooster (Revised 0/0/009 Abstract Brian J. Shelburne Dept of Math and Comp Sci Wittenberg University In 94 Konrad Zuse completed the Z3 sequence controlled calculator. The Z3 was a binary machine (numbers were stored internally in floating point binary with a 64 by bit memory which could perform the four standard arithmetic operations as well as tae square roots. This tal examinations the algorithm Zuse used for his square root instruction and how it was implemented on the Z3. Zuse's Z3 Square Root Algorithm- The Tal Konrad Zuse (90-995 born 90 in Berlin, Germany studied civil engineering at Technische Hochschule Berlin-Charlottenburg wored as design engineer in aircraft industry needed calculations for design and analysis of structures his first attempt at automating calculation process was to design a form to trac intermediate results of calculations not familiar with design of mechanical calculators His Early Machines: The Z - Z3 Z: begun in 936 floating-point binary representation 4 bit word length - sign bit, 7 bit exponent, 6 bit mantissa (fraction 4 decimal digit precision completely mechanical (memory, arithmetic unit and control 6 word prototype memory completed 937 controlled by tape (used discarded 35 mm film - hand punched! four functions : + - mechanical arithmetic unit unreliable Z: 938-940 (smaller hybrid machine relay based ALU and control; mechanical memory "proof of concept" for relay based calculator demonstration led to funding for Z3 by Deutsche Versuchsanstalt fur Luftfahrt Z3: 939-94 (relay based machine same design as Z except included square root operation

An Overview of the Z3 Tape Reader Control Unit Numeric Keypad Light Display Arithmetic Unit Memory 64 Words Exponent ALU Fraction ALU Memory : 64 by bits - normalized floating point binary _ _ ± exponent fraction a 6 a 0 b -... b -4 Numeric Keyboard input: 4 columns of 0 eys for digits row of exponent eys labeled: -8, -7... 7, 8 Display Output - row of 5 lights for fraction plus exponent lights labeled: -8, -7...7, 8 Tape Control: nine 8 bit instructions 0 0000 - read eyboard 0 00000 - add 0 000 - display result 0 0000 - subtract 0 00000 - multiply z z z 3 z 4 z 5 z 6 - load address 0 00000 - divide 0 z z z 3 z 4 z 5 z 6 - store address 0 0000 - square root Arithmetic Unit: separate ALU's for exponents and fractions Control Unit: instructions were implemented as a sequence of micro-operations which controlled movement of data through machine.

How Do You Tae A Square Root?. Use a calculator. Use a slide rule 3. Use a table of logarithms 4 Use Newton's Iteration Formula to solve f ( x = x a by using the iteration f ( xn a formula xn+ = xn = ( xn where x 0 equals some initial "guess" ( x 0 = a wors f '( xn xn well for a >. Note this requires one division per iteration (expensive!. 5. Use the binomial expansion of x x = 3 5...( 3 x = x! = 3 3 3 5 4 x x x x.. 3 4! 3! 4! We can calculate the a for x = since b a by finding some value a b a b b b close to a and using the above series expansion a = + = ( b 6. Complete the Square: This technique is based on the simple idea that if x is a good approximation to a where a x = e > 0 is the error, then find a small value b such that ( x b + is a better approximation; that is ( ( another way, find a value b such that e b( x b a x a x b a x bx b > + = 0 or to put + 0. The inequality is not linear in b but is it not difficult to questimate a value. Generally this is done digit by digit. Completing the Square (details Without loss of generality assume a < 00 and suppose x = Q is an approximation to ( a accurate to 0 (i.e. the st digit below the decimal point. That is 0 Q = d + d 0 i= i i where di is a digit between 0 and 9 3

Letting b = d 0, find the largest digit d such that ( ( ( ( ( a x + b = a Q + d 0 = a Q Q d 0 d 0 0 To find the largest such digit d factor out d 0 to obtain ( a Q d ( Q d 0 + 0 0 Scaling (multiply by 0 does not change the sign of the expression but it maes all values integers. ( a Q d ( Q d 0 0 + 0 To find the largest digit d use the following guess and chec method.. Guess the largest digit d such that d 0 Q. Chec that d ( 0 Q d try again. is less than 0 e = 0 ( a Q + is still less than the scaled error. If not reduce by and i If successful then Q = d0 + di0 is a better approximation with a smaller scaled error now equal to i= ( a Q d ( Q + d = ( a Q < ( a Q 0 0 0 0 4

Finding the largest d which maintains this inequality is the theory behind the following well-nown algorithm (well-nown before the advent of cheap calculators used to compute a square root by hand. To demonstrate we tae the square root of 0.375. d 0 d d d 3 4. 5 3 0. 37 50 00 <- a 6 00 <- 0 Q 0 ----- 4 0+d -> 85 4 37 <- 0 (a - Q 0 4 5 <- d (Q 0 0 + d ------ 45 0+d -> 90 50 <- 0 4 (a - Q 9 0 <- d (Q 0 + d ----- 3 49 00 <- 0 6 (a - Q 45 0+d 3 -> 903 70 69 <- d 3 (Q 0 3 + d 3 -------- 78 3 00 First - find the largest integer d0 = Q0 whose square is less than or equal to the integer part of the number a. Square Q0 and subtract it from the integer part. Bring down the next two digits. Second. - Find the largest integer d such that Q0 0 + d times d is less than the previous remainder. Subtract it and bring down the next two digits. Q Q d = + 0 0 Third - Find the largest integer d such that Q 0 + d times d is less than the previous remainder. Subtract it and bring down the next two integers. Q Q d = + 0 th Step - Find the largest integer d such that Q 0 + d times d is less than the previous 0 remainder. Subtract it and bring down the next two integers. Q = Q + d Repeat. ( 5

The Binary Version of the "Completing the Square" Square Root Algorithm The same algorithm can be easily done in binary. By way of demonstration, we find the square root of the binary value 000.0 which is 0.375 decimal. The floating point representation is.0000 x 00 (note the even exponent. Therefore the square root of 000.0 is the square root of.0000 times 0 (or 4. Remember that multiplication by in binary is equivalent to a left shift. Furthermore scaling by powers of 0 (binary is scaling by powers of.. 0 0 0 0 0 0 0. 0 00 0 0 00 00 00 00 00 00-0 0 <- (a - Q 0 00 0 00 <- b ( Q 0 + b ------ 00<- 4 (a - Q 000 0 00<- b ( Q + b ---- 00 0 <- etc... 000 00 0 ------- 0 0 0000 0 00 ---- 0 00 00000 00 00 ----- 0 00 00 000000 00 00 00 ---------- 0 00 00 00 0000000 00 00 00 00 ----------- 0 00 00 00 00 00000000 00 00 00 00 00 -------------- 0 00 00 00 00 00 00000000 00 0 00 00 0 ----------------- 0 00 00000000 0 0 00 00 00 whew!!! So therefore the square root of 000.0 is approximately.0000000 x 0 = 00.00000 = 4.57875 which is "close" to 4.538675 6

The Z3 Square Root Implementation - Completing the Square in Binary The Z3 used a variant of the above algorithm to compute a square root. Given a < 00 ( values are in binary if Q is an approximation to 0 a accurate to Q b b = + i= i i (, that is where each bi is either 0 or, then find the largest binary digit b (0 or such that ( ( ( ( a Q + b = a Q Q b b 0 Because there are only two possible choices for b, either 0 or, this algorithm is easy to implement. Moreover since b = b these are some trics to mae iteration efficient. Begin by scaling (multiplying the above inequality by (instead of. If we have then b is ; otherwise b = 0. In any case since expression ( a Q ( Q ( a Q ( Q + 0 b = b it follows that the above + equals ( ( a Q b ( a Q be used in the calculation for the next step. If we multiply ( a Q + ( a Q machine using a left shift. + = which can by we obtain for use in the next iteration step. Multiplication by is easily done on a binary The algorithm is given below. Assume a 00 where e ( a =. 0 < and let e ( a Q. let Q[0] =. let e[0] = a - 3. for =,, 3,... 3. Compute e[-] - ( Q[-] + - 3. If positive or zero (i.e. b[] = 3.. Q[] = Q[-] + - 3.. e[] = e[-] - ( Q[-] + - 3.3 Otherwise (i.e. b[] = 0 3.3. Q[] = Q[-] 3.3. e[] = e[-] = (a scaled error value 7

Example - Compute the square root of.0000 e[-] - ( Q[-] + - e[]= a Q[] Q[] 0 0.0000. 0.000-0. negative 0.000.0.000-0.0 negative.000.00 3 0.00-0.00 positive 0.000.00 4. 0.00-0.00 negative 0.00.000 5. 0.0-0.000 negative 0.0.0000 6 0. - 0.00000 negative 0..00000 7.0-0.00000 negative.0.000000 8 0.0-0.000000 negative 0.0.0000000 9 00.0-0.0000000 positive.0.0000000 0.0-0.000000 positive.000.0000000 This agrees with the example given above. 8

A Closer Loo at the Architecture of the Z3 Arithmetic Unit Bf Register Shift -.. Shift -6..5 Ba Register Bb Register Adder/Subtractor Be Register Z3 had separate ALU's to handle the exponent and fractional parts of a number Basic data path of the fraction ALU consisted of four registers (Bf, Ba, Bb, and Be an addition/subtraction unit and two shifter units connected by data lines. A number of gates controlled the follow of data around the data path Hardware operations included addition and subtraction, pre-shifting input to the Ba and Bb registers, detecting a positive or zero result and setting individual bits in a register. A micro-operation consisted of a timed sequence of gates openings that allowed the contents of registers to flow through the pre-shifters and addition/subtraction unit. Detecting a positive or zero result could conditionally alter the flow of data. Instructions were implemented as sequences of micro-operations. 9

Note Bf[-] refers to bit - in register Bf Micro-operation Implementation of Z3 Square Root 0. Bf := a // Load Bf with a Ba := Bf (or Bf if exponent is odd // Ba = a Bb[0] := // Q 0 =. if Ba - Bb 0 then // test Be := Ba - Bb Bf[0] := // set bit else Be := Ba // set up next comparison Ba = Be // r 0 Bb = Bf; Bb[-] := // Q 0 + - if Ba - Bb 0 then // test Be := Ba - Bb Bf[-] := // set bit else Be := Ba // set up next comparison Ba := Be // r Bb := Bf; Bb[-] := // Q + - and in general if Ba - Bb 0 then // if r - - ( Q - + - 0 then else Be := Ba - Bb // r = r - - ( Q - + - Bf[-] := // Q = Q - + - Be := Ba // r = r - // Q = Q - // set up next comparison Ba := Be // r Bb := Bf; Bb[-(+] := // Q + -(+ At the end the exponent which was even was divided by (a right shift yielding the square root. The thing to notice was the economy of operations needed to compute a square root - shifts, subtractions, comparisons and setting individual bits within a word. 0

Summary. The square root algorithm used by the Z3 was the binary analog of the "completing the square" algorithm, a widely nown (? manual technique for obtaining a square root one digit at a time.. For a < 00 and Q an approximation of if ( a Q + b 0 a accurate to (, set bit b equal to otherwise set bit b equal to 0. It was shown that this is the same as checing if ( a Q ( Q + 0 and leads to the iteration algorithm Repeat until tired Compute e[-] - ( Q[-] + - If positive or zero Q[] = Q[-] + - e[] = e[-] - ( Q[-] + - Otherwise Q[] = Q[-] e[] = e[-] where e[] = (a Q[] and initial condition Q 0 = and e[0] = (a - 3. A close examination of this algorithm reveals that it requires only the operations of subtraction, left shift (multiplication by, set bit, and test if positive or zero. - all of which are easy to implement in binary logic. 4. The Z3 had a data path that could easily implement these operations and a micro-operation sequencer that could iterate each step of the algorithm the requisite number of times. Use of floating point binary notation helped. 5. Binary representation is used in computers because for economic reasons computer hardware is built out of bi-stable components. However, many complicated arithmetic operations lie multiplication, division and square root are easy to implement in binary. Even though we humans find binary notation complicated to use (even moderately sized numbers tae a lot of bits, because of the ease in implementing complicated algorithms in binary, there is something to be said for the advantages of binary notation in and of itself. Any sufficiently advanced civilization uses a number system based on a power of two.

Epilog: A Follow Up on the Z3 - the Z4 The Z3 was really a "proof of concept" for the more ambitious Z4, a 3 bit machine begun after the Z3 was completed. Unlie the Z3, the Z4 used a mechanical memory of 000 words (which too up a cubic meter of space!. Before it was completed it was moved to Gottingen to avoid the Berlin air raids which had destroyed the Z3. Just before Gottingen was "liberated" at the end of WWII, the Z4 was moved to Hinterstein, Bavaria. In 950 the refurbished Z4 with some additional features that gave it a conditional jump was moved to ETH Zurich. In 955 it was moved to Basel where it gave "acceptable service" until 960. After the war Zuse founded Zuse Kommandit Gesellschaft (Zuse KG which produced for the Leitz Optical Company a relay based, punch-tape controlled "computer" called the Z5 which was based on the Z4 design. This led to the production of a number of relay-based calculators, called the Z. In 956 Zuse began wor on a vacuum-tube based computer called the Z with a transistor version following. A series of mergers and taeovers finally lead to Zuse KG becoming part of Siemens. References R. Rojas, "Konrad Zuses' Legacy: The Architecture of the Z and Z3", Annals of the History of Computing, vol. 9, no., pp. 5-6, 997 I. Koran, Computer Arithmetic Algorithms, Englewood Cliff, N.J.: Prentice-Hall, 993 M. Williams, A History of Computing Technology, Los Alamitos, CA: IEEE Computer Society Press, 997