Distributive Categories yukita

31
Distributive Categories http:// cis.k.hosei.ac.jp/ ~yukita/

Transcript of Distributive Categories yukita

Page 1: Distributive Categories yukita

Distributive Categories

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

Page 2: Distributive Categories yukita

2

Products and Sums

• Products are concerned with operations on the data.

• Sums are concerned with control.– Decisions on which operation to perform

• How do they interact when both products and sums are involved?

Page 3: Distributive Categories yukita

3

The Distributive Law

.explicitly misomorphis thegive should We

.isomorphic are objects somesay just toenough not isIt

00 (ii)

)()()( (i)

saysit in Roughly,

X

ZXYXZYX

Sets

Page 4: Distributive Categories yukita

4

ZX YX ZXYX 2i1i

YX i1

ZX i1

)( ZYX

below. diagram in the as

definedy canonicall is )( ZYXZXYX

Page 5: Distributive Categories yukita

5

Axiom 1 [abstracted from Rule (i)]

• The arrow is an isomorphism.

• Rule (i) is not automatic in categories other than Sets.

Page 6: Distributive Categories yukita

6

Axiom 2 [abstracted from Rule (ii)]

object. initialan is since

,00:

arrow oneexactly always is There

m.isomorphisan is 00:

X

X

Remark.

Page 7: Distributive Categories yukita

7

)).1,(,()1),,((

))0,(,()0),,((

by defined is

,|))1,(,(,|))0,(,()(

,|)1),,((,|)0),,(()()(

zxzx

yxyx

ZzXxzxYyXxyxZYX

ZzXxzxYyXxyxZXYX

Sets 1. Ex.

Page 8: Distributive Categories yukita

8

Def. Distributive Categories

Sets

. a called is

2, and 1 Axiom satisfies which and exist, pairs of sums and products

in which objects, terminaland initial hashich category wA

Ex.2

category vedistributi

Page 9: Distributive Categories yukita

9

Ex. 3 Category 2X is distributive.

).()()(

thatnot true isit sincedifferent issituation the,In

).()()( that truealso isIt

. that says 2 Axiom

).()()( that says 1 Axiom

ZXYXZYX

WUVUWVU

U

WUVUWVU

Sets

Note.

Page 10: Distributive Categories yukita

10

. of examplefirst theis This

:

. , functions all Give

*. )1(*,

)0(*, *

are sum theof Injections

}.1,0{set or the },{set with theidentify often We

)}.1(*,),0{(*, and {*}Let

2

21

BB

BBBBQuestion.

B

B

BEx.4.

IIII

II

truefalse

III

twist

ii

Page 11: Distributive Categories yukita

11

.

consider tosufficient isit , arrowsconstruct To

.)()(

)()()()(

ms.isomorphis of sequence following heconsider t thissee To

. category, vedistributi aIn

2

2 1

B

BB

B

BB

IIII

IIIIIIII

IIIIIIIIII

IIII

Page 12: Distributive Categories yukita

12

In Sets

)3(*,))1(*,),1((*,)1,1(

)2(*,))1(*,),0((*,)1,0(

)1(*,))0(*,),1((*,)0,1(

)0(*,))0(*,),0((*,)0,0(

takes to from misomorphis The 2

IIIIB

Page 13: Distributive Categories yukita

13

The & function

)1(*,))1(*,),1((*,)1,1(

)0(*,))1(*,),0((*,)1,0(

)0(*,))0(*,),1((*,)0,1(

)0(*,))0(*,),0((*,)0,0(

takes to from misomorphis The 2

BB

Page 14: Distributive Categories yukita

14

Sets as a Distributive Category

• Using– sums– products– composition– distributive law– and some additional primitive functions,

• we can construct various functions.

Page 15: Distributive Categories yukita

15

Some Primitives in the category of Sets

if

if ),(

:

*

:

),(

:

),(

:

yxtrue

yxfalseyx

test

r

Ir

yxyx

multiply

yxyx

add

yx

BRR

R

RRR

RRR

Page 16: Distributive Categories yukita

16

Divide

0. if ,1)(

0 if false*,0)(

),(

:

yy

x

y

yx

Idivide

RRR

Page 17: Distributive Categories yukita

17

Ex. 5. Realization of testx>0  

.0 if )1,(

0 if )0,(

:0

xx

xxx

testx

RRR

Page 18: Distributive Categories yukita

18

0 if )1,( 0 if )1,*),((

0 if )0,( 0 if )0,*),((

)()(

0 if )1,*),(( 0 if ),(

0 if )0,*),(( 0 if ),(

)()(

0 if ),(

0 if ),(),0,()0,,(

)0,,( ,*)( 1313

0

xxxx

xxxx

II

xxxtruex

xxxfalsex

II

xtruex

xfalsexxxxx

xxxx

I

yxtesttwist

RRRR

RRR

RRR

RRRRR

B

B

Page 19: Distributive Categories yukita

19

Imperative Programming

?)?,,!()0,,1(

gives eventuallywhich

)()(:

Factorial

program. theof called is

. called is function aSuch

,:,:

as dinterprete isiteration

,: function aGiven

xxf

IIIIf

X

f

XXfffXXff

XXf

n

RRRR

spacestate the

program imperative an

10 Ex.

Page 20: Distributive Categories yukita

20

Construction of factorial as an imperative program

.1 allfor )1,0,!()0,,1( Check that

.1or 1 if )1,,(

0 and 1 if )0,1,(),,(

:

)(

as dinterprete isiteration

,: function aGiven

xnxxf

tddp

tdddptdp

XXf

IIX

XXf

n

RR

Page 21: Distributive Categories yukita

21

Implementation of factorial in a distributive category

).1,,(),( clear that isIt

1. is flag that thecase in thefunction theis

0. is flag that thecase in thefunction theis

.: and :

functions twoconstruct tosafficesit Thus

.)(

have wecategory, vedistributi aIn

1

1

0

10

dpdpf

tf

tf

XfXf

IIX

RR

RRR

Page 22: Distributive Categories yukita

22

Construction of f0

.

composite theas :

. 1 if )1,,(

1 if )0,1,(),(

)(:

12110

1

220

B

B

xtest

xtest

ddp

dddpdp

IIf

RRRR

RR

R

R

Page 23: Distributive Categories yukita

23

Construction of h and f0

).(

composite theis

.

composite theas )1,(),(

:

2221222

21312

0

241102

22

1

II

f

ddpdp

h

h

test

addmult

x

RRRRRR

RRR

RRRRRR

RR

R

RR

R

B

B

Page 24: Distributive Categories yukita

24

Def. Imperative program

. of ),(),(,

sequence a is program imperative theof A

program.

imperative theof thecalled is function The

category. vedistributi ain available onsconstructi the

using functionsgiven ofset a from dconstructe

:

function a is program imperativeAn

2 Xxfxfx

f

XXf

behavior

action

Page 25: Distributive Categories yukita

25

Ex. 11. while t(y) is true do …

idling. toscorrespond 0 valueflag The

.)( and 1 if )1),((

)(or 0 if )0,(),(

)()(:

idle."then

),( to of value thechange true,is )( while"

:does which program imperativean Construct

.: test a and :function aGiven

t

trueytesttyg

falseytesttyty

IIYIIYf

ygyyt

YtYYg

B

Page 26: Distributive Categories yukita

26

Implementation of Ex. 11

.)(

.)( if )1),((

)( if )0,(

follows. asgiven is :

injection.first theis

. to from

. and construct tosufficesit ,)( Since

.: test a and :function aGiven

112

1

0

10

Y YYYYIIYYY

trueytestyg

falseytestyy

YYYf

f

YYY

ffYYIIY

YtYYg

gtest Y

B

Page 27: Distributive Categories yukita

27

Ex. 12. A Circuit with Feedback

nor

x

y

nor

u

v

Page 28: Distributive Categories yukita

28

unstable. isbehavior the(0,0,0,0), with Starting

point. fixed a is )0,1,1,0( with Starting

))or (),or (,,(),,,(

:

}1or 0,,,|),,,{(

is states possible all ofset The

44

4

uyvxyxvuyx

f

vuyxvuyx

BB

B

Page 29: Distributive Categories yukita

29

Ex. 13. Flow chart

4xtest

false

true

0 12x

2x2 3

Page 30: Distributive Categories yukita

30).3,()3,(

)3,()2,(

4 if )0,(

4 if )2,()1,(

)1,2()0,(

:

)}.3,{()}2,{()}1,{()}0,{(

4

is space state The

2

ww

zz

yy

yyy

xx

f

wzyx

X

Page 31: Distributive Categories yukita

31

Term Paper

• Implement the function in example 13.

• Use only – add– multiply– constants– constructions in a distributive category.