data types yukita/. 2 arithmetic funtions ans laws

28
Data Types http://cis.k.hosei.ac.jp/ ~yukita/

Upload: garey-simpson

Post on 18-Jan-2016

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Data Types yukita/. 2 Arithmetic funtions ans laws

Data Types

http://cis.k.hosei.ac.jp/~yukita/

Page 2: Data Types yukita/. 2 Arithmetic funtions ans laws

2

Arithmeticfuntions ans laws

law) ve(commutati

law) (inverse )(0)(

law) ve(associati )()(

law)(identity 00

:

:

:

xyyx

xxxx

zyxzyx

xxx

minus

Izero

add

Page 3: Data Types yukita/. 2 Arithmetic funtions ans laws

3

The Associative Law

add

add1 add

1add

Page 4: Data Types yukita/. 2 Arithmetic funtions ans laws

4

The Identity Law

.II 1zerozero1

add

1

1

Page 5: Data Types yukita/. 2 Arithmetic funtions ans laws

5

The Inverse Law

minus1

add

I! zero

Izero !

1minus

Page 6: Data Types yukita/. 2 Arithmetic funtions ans laws

6

The Commutative Law

add

twist

add

.

Page 7: Data Types yukita/. 2 Arithmetic funtions ans laws

7

Data Types

• Algebras such as groups, rings, etc. are familiar data types in mathematics.

• CS handles other data types other than those algebras.– stacks– queues– arrays– binary trees– other useful data structures

• A data type consists of various sets of data together with operations between them definable in a distributive category and equations expressible in a distributive category.

Page 8: Data Types yukita/. 2 Arithmetic funtions ans laws

8

Stacks (Rough View)

),()(

:

)(),(

:

2121

2121

nn

nn

xxxxxx

SSpop

xxxxxxxx

SSpush

Page 9: Data Types yukita/. 2 Arithmetic funtions ans laws

9

Pop revised to avoid stack underflow

. if ),(

if *

:

2121 nn xxxsxxx

oss

SISpop

Page 10: Data Types yukita/. 2 Arithmetic funtions ans laws

10

Push revised for symmetry

nn xxxxxxxx

xox

o

SSIpush

oSIo

2121 ),(

),(

*

:

.* :

Page 11: Data Types yukita/. 2 Arithmetic funtions ans laws

11

Axioms

.1

,1

:

:

S

SI

poppush

pushpop

SSIpush

SISpop

2. Axiom

1. Axiom

Page 12: Data Types yukita/. 2 Arithmetic funtions ans laws

12

Definition.

.1

,1

satisfying

.:

,:

:operations ith twotogether w

set a is , of aor , of A

S

SI

poppush

pushpop

SSIpush

SISpop

S

stacks ofspace stacktype

Page 13: Data Types yukita/. 2 Arithmetic funtions ans laws

13

Ex. 1. Infinite stacks

2121

2121

),(

),(

*

:

sequence infiniteor finite means

),(

*

:

xxxxxx

xox

o

SSIpush

xxxxxx

o

SISpop

Page 14: Data Types yukita/. 2 Arithmetic funtions ans laws

14

Note

• Just from the axioms, we do not know whether the stacks are finite.

Page 15: Data Types yukita/. 2 Arithmetic funtions ans laws

15

Definition. Stacks of X

.1

,1

satisfying

.:

,:

:operations ith twotogether w

set a is , of aor , of A

S

SXI

poppush

pushpop

SSXIpush

SXISpop

SXX

stacks ofspace stacktype

Page 16: Data Types yukita/. 2 Arithmetic funtions ans laws

16

Ex. 2.

another. one of inverses are and

1

0*

:

.0 if 1

0 if *

:

. and {*}Let

successorrpredecesso

nn

Isuccessor

nn

nn

IIIrpredecesso

SIX

Page 17: Data Types yukita/. 2 Arithmetic funtions ans laws

17

Notation

.by product theand

by 1 arrowidentity thedenote willWe

XYYX

XX

Page 18: Data Types yukita/. 2 Arithmetic funtions ans laws

18

Ex. 3. The usual operation of pushing an element on a stack

SSXII

xssxsx

SSXISX

pushi

pushi

I

SX

isstack empty The

),(),(

Page 19: Data Types yukita/. 2 Arithmetic funtions ans laws

19

Ex. 4. Imperative computing of the depth of a stack

)).(,(st idles program the),0,( state initial with theBeginning

.

)()()(

composite. following theisaction The

),(),(

)1,(),(

e.number typ a is

1

)()(

21

sdepthos

SRSRSRSRSR

RSSRSIRXSISR

roro

rxxrxx

RSRS

R

xSSR

RSoRprojIRpop

nn

Page 20: Data Types yukita/. 2 Arithmetic funtions ans laws

20

Ex. 5. Tests on stacks

.

)()(

.1)( if 1

1)( if 0

:

!!!

2

IIIIIIII

SXXIXSIXIXSIS

sdepth

sdepths

IIStest

ItwistI

popXIpop

Page 21: Data Types yukita/. 2 Arithmetic funtions ans laws

21

Arrays - the store function

.by dimplemente

]).[,],1[,],1[,],2[],1[(])[,],2[],1[,(

is oneth - The

. arrows need we, : define To

).),,((),,(

)(

have wecategory, vedistributi aIn

. if ][

, if ][ where),,(

:

21,1

1

11

1

npnswapn

nn

nnnn

nnn

nn

XXXXX

naiaxiaaanaaax

XX

i

XXnXXn

iaxaix

XnXXInXInX

ijja

ijxjaaaix

XXInXstore

i

Page 22: Data Types yukita/. 2 Arithmetic funtions ans laws

22

Arrays - the read function

].[),(),(

:

order.in projectionth - ],[),(

:

],[),(

:

iaiaai

XXnXInread

niaia

XXn

iaai

XXInread

nn

n

n

Page 23: Data Types yukita/. 2 Arithmetic funtions ans laws

23

Binary Treesx

y

p

z

q

u v

Page 24: Data Types yukita/. 2 Arithmetic funtions ans laws

24

Two operations make and break

*.

),,(

:

is inverse The

.:

asoperation singlein put themor

.),,( :

,empty tree the:

:operations with , of esbinary tre ofset thebe Let

2121

2121

o

txtxtt

TXTITbreak

TTXTImake

xtttxtTTXTmake

TIo

XT

Page 25: Data Types yukita/. 2 Arithmetic funtions ans laws

25

Def. Binary Tree

another. one toinverse arewhich

,: and :

operations with twoobject an is , of A type,

TXTITbreakTTXTImake

TX

treebinary

Page 26: Data Types yukita/. 2 Arithmetic funtions ans laws

26

Queues

Page 27: Data Types yukita/. 2 Arithmetic funtions ans laws

27

Pointers

Page 28: Data Types yukita/. 2 Arithmetic funtions ans laws

28

Turing Machines