0% found this document useful (0 votes)
28 views

R Computer Arithmetic

Uploaded by

Novsagi TM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

R Computer Arithmetic

Uploaded by

Novsagi TM
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Computer Arithmic

for

Languages have
Types Integers
-

-Machines work with faith


words of
length
-

Define Bases 1 Base 1: 5 11(


=

6 ((((1)
=

numbers
-write as seq. of
digits
Base B is
means
digits
30, B" 13 (Xn-n,...,x0]
-

is
ne . .

.,
a
seq
↑ -
Digits
written as
turn u-z..- to

Ex: (1,2,3) with as 123


-

Unsigned Interpretation:

↳: SO, ..., B-13+-> IN (xn--. xo):= Eti


Sequences 011 11
*

Digits
of
(01172 (1172
=

(123) 10 1.102
=

2.10
+
+
3.100 123
=

1.82 2.81 3.80 =...


(12338
+
+
=

(10272 1.23
=

0.22
+
1.21
+
1-20
+

41710
=
Lemma

Let and B bun bo


c
an..... do =
=

...

then
(B)=()B. Bm (B)+

i
2=an -...Gobn-...bo
Proof
n - 1
Example:
()b 2iBl
=

(1234710 (12):102 + 2347


=

i0
=

x -
1

(B)
B EBibl
=

i0 =

(p.B (kb +

(xii).Br (ii)
=
+

=(ii) t U
Lemma Injective by
pigeon hole principle
LetB >1 and so
190, ...,
B4-11 BY =

For each natural number KE90, ..., B"-17 we


also have
there is of
a
seq digits a
Bu sea of
such that
()B k
=

length u

of B
Proof
-
digits
Induction over u

n 1:=

Let k=90. . .

.,
B- 13
-

-- 1
I
(kYB

Then 4. B
24.B
= =

= Here I made a mistake in

~the
lecture. Maximal is correct.
A has to be
such that r B"!!

hte benal 30.


Consider some k t . .

.,
Bhtr_1].
number such that

B4 k q. r.
90, B-13 length
q
+
=
. . u
,
.

[ADB =(p)B
(k) B [qP7 =
r 30,...," 13
=
-

[P)B
=
&

Binary Numbers

B =
90,13
=

C1011 ↳2 G1)
=

no

Bits
⑮ 2.20 +
--1

:1 b
↳2:bur obizl
= -

... bo
Complement I A
most least
and or for
significant"

I I
a b adbalb a
-
b
bit
0 ⑧ O
00
0
8
O


1
1
I 1011G1) =
no

I 0111
(z)no
7
=(18710
1 1 ⑧

Arithmetic =

↓ Bitof
i-th a 168421

a b i-th Bitof b
/
+

L ↓ carry from less sign pos


Si a:
:=
b: cit 1

citz: =
(ai&bi)((ai2(i)((biz(i)
Bitstigs
Lemma ath is sound. Add &1,1
--
*
-


defined by

Add 2, 1,
2

[.
(a b) (a) (b)
+

=
+

+ Co
4 ↑ --
Add &, 1in Add IN Add IN

Roof Induction over u (length bit str)


Si a: =

bi ci
-Base Cast u 1:
=

Cit= (ai2bill(biD(i)
lanfe.)
bo 20 (a0)+/bo) co
+

C1 so
(so)z
a O

·
⑧ 0 0 O
O 1 1

- =
O

I I

:
8
I
2
O

=
O
!
⑧ 3 I
O
1
-
-
-
Induction Step:n-1-n
IH: (Cu-nSu-2 . . . So) =
Lan -2...ap) + 4bn -z ...bot

(a) (b) +

c
+

= (a.n...an (bu-1 ...bo) +


+ co

=an-12" + an-z... 40)


+bun zur + (bn-z ...bob() Sass e
1103
[234
=

=(a+
cur) 2n-1
(uSn-1)
(Sn-2
=

-> ... so)

=(anSu-n . . .

so) B

carry out of most

sign, position (If (n 1


=

then the
Resultmay be nt1 bits long; result cannot
62 acc. repr.
a tr b =
Su-n So

↳bits
. . .
=
Subtraction
of
Assume we have Base to digit sequences

Length
---
3 -2 3 -2
= + 1000 mod 103 =

1000

a b
=

mod m
=3 998 +

if a -
b k-m
=

=
Noon
1
=

mod 1000
complement b
of
Two's
(a b) (a)
-
=
(b)
+

22 -(b) 5)
=

1
+

=(a) -

(b) mod zY
Example
201032=407 10

24 -(107072 6
=

+ (970) =
207017
5 1
= +
Det a -

b: a =

5 1a
+ b
+
with co 1
=

M
subtr. On

Bitstigs
subtraction is sound
Lena
(a -

b) (a) 2"
=
+ -

(b)
Proof
-
(a b) (a 5 1)
-
=

+ +

5 1
=
-
b

=(a) (5) +

1
+

sigte
bit

=(a) +

((1 bi)zi)
=
i0 e
-

1
+

Er
(a)
(zi) -(Ebizi)+
+

e
subtraction (b7
accurate if [11132
carry
(cn) 1
=
=(a) -

(b) A (2:)
+

i8 =
142 4
=
+

8
+

15
=

ne
else not
=(a) (b) 2Y - +

2"
=

=(1000072
-
7
Signed interpretation
[.]:B" + 2 [bu-1bu-z...boy=-bu-2"-1
+

(bu -z...bo)
=(b) -
bu-n2"
Example n 3
=

000 001 on on 100 101 110 111


(i) 0 1 23 ↳
III 21
5- 6 I mod
IC[ IC)

7 2 3 -4 3 -
2 123
[.]
- -

(02) +
(140) =
↳700172 F(01 110) 1
+3
=

2
3 6 I

[01] +[1103 [01 3110] 1


=

1
= = +

3 -
2
4
(om2) [04 30013 =

L003
-

4
+
+
I

3
7
iff
Lemma [a] [b] [anb] (n cur
= =
+

--
A
Add Z Add 2, 1, 2

Def
Prof (a) [b]
(a), (b) (an bin).2" []
+ =

- +

-n

soundh.
=(a b) +
-
4 ofAdd.

,
[a-nb] is accurate
=(Sn 1) 22
1
(Sn-2 ...so)
-

u
the
+ -

ouder same -

1
(an S--n)2
n -

condition +

=Cn?" +Sunth-1

=Sn-1
22
-
1
+ (Sn-2 ...
sob +
LanSura)=Aunburnt dur n
zYn-a- *n):

-

2"sn-1-2se-1
Zan+Sn i

[s4
=

zsan+ ---so] +(cu-an--b?"


Su-1 =n -2c =
--

=(Suntn-an-burn)2"+ [atub]
-

=(cn -n
-
(u)2" (a+ub]
+
-

Eln. School addition on


bit
stigs is

sound

When untested the


we are
only
-

least
sig. the
digits, result
W

of is accurate if

W
addu (a b)
+

cn 0
=
Carry bit

subu (a-b) G 1 =

Overflow bit
~[a b] +

Cu
-
Cu-1 0 =

"[a -b]

Not every op. compatible


is with []

(001) 1
=

6 =
(110) sitch
20013: 14-2=[110] Sit

You might also like