C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in...

25
C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: www.cs.aue.auc.dk/~av Email: [email protected]

Transcript of C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in...

Page 1: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

C-cardsUsing paper and scissors to understand Computer Science

Andrea Valente

Aalborg University in EsbjergDenmark

Home: www.cs.aue.auc.dk/~avEmail: [email protected]

Page 2: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

The problem

Define an educational tool for teaching Computer Science to young children (8 to 12 years old) and students without a solid mathematical background.

1! = 1n! = n * (n-1)!

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Page 3: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

A solution: c-cards

● Peg-source● Peg-pit● Peg

● Cross● East turn● West turn● Confluence

● Switch

Page 4: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Behaviour and circuitsCards can be connected to build circuits.

Pegs move across cards, from port to port, one at the time: sequential execution model.

Page 5: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Behaviour and circuits (cont.)

This is a time-reversible boolean not gate!

position = value

change positions =

computation

Page 6: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Behaviour and circuits (cont.)

In the shape (on the left) the In source card is defined by the pattern(white.black)*

which means: a white peg, then a black and so on.The implemented circuit (right) separates white pegs from black ones.

- Implementation -- Specification -

Page 7: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Behaviour and circuits (cont.)

The 2 states of a switch card.

NOTE: All pegs are identical!

Page 8: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Semantics

...

A card circuit is a graph of ports, each one possibly containing one peg.

Graph-rewriting rules are simple to explain and support our visual and physical metaphor for computation.

All rules work up-to card rotation and are deterministic: they are triggered by the presence of pegs, and depend upon the current state of cards.

Page 9: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 1

Suppose now we want to make a more complex exercise, working with a source defined by

(white.slashed.black)*

The resulting circuit will have three pits, in which pegs of the same color will accumulate: the first (western) pit will receive all white pegs, the second all the slashed ones and the black pegs will stop at the third.

The (white.black) circuit could be a starting point for the definition of this one!

Page 10: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 1: a little help

switch

switch switch1. white 2. slash

3. black

4. white (2)

?

1.3.

2.4.

Page 11: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 1: solution

a MACRO card!

ResultWe can count modulo n.

Page 12: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Macro & custom cards

We can map the whole circuit it into a single large card, a macro-card, preserving the circuit's behaviour.Source cards became input ports, while pits are turned into output ports; arrows (and some informal annotations about actions to be performed) will express the high-level behaviour of the large card.

It is also possible to define new custom cards behaving as a whole circuit; the geometry of the original circuit is hard to preserve. Students can easily define their own cards.

Page 13: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Let's make a new card!The random card

An extension to the basic deck is the random card: a peg entering this card will be sent out from the left or the right, with {1/2,1/2} probability distribution.

This is the non-deterministic version of the switch card.

Page 14: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 2

It is easy to build a circuit that divides white markers from black ones, with 50% probability of making an error. It is the random equivalent of the white.black circuit discussed before.

Is it possible to have a probability distribution of { 1/4 , 3/4 } ?

Page 15: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 2: solution

Result

Using two or more of these cards in cascade, we can have a peg-source implementing almost every probability distribution needed.

rnd

rnd rnd1/4 1/41/4 1/4

1/4 3/4

Page 16: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Exercise 2: the circuitNew custom cards!

Page 17: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Channels, errors and redundancy

- Shannon's binary symmetric channel

- Perfect channel

Page 18: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Work in progress● what is the computational power of c-cards ?

● what about a parallel semantics ?

● Turing Machines / Cellular Automata ?

● c-cards in LOGO / StarLogo ?

● a 3D version ?

● more exercises ?

● work with a class of children ...

Page 19: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Conclusions

Related work and bibliography➔ Fredkin, E. and Toffoli, T. (1982). Conservative logic. International Journal of Theoretical Physics, 21(3/4): 219–53.➔ Milner, R. (1989). Concurrency and Communication. Prentice Hall.➔ Gardner, P. (1999). Graphical presentations of interactive systems. Submitted for publication.➔ Helen Sharp, Mary Lynn Manns, Phil McLaughlin, Maximo Prieto and Mahesh Dodani (1996). Pedagogical patterns – successes in teaching object technology. ACM SIGPLAN Notices, Vol. 31(12), December 1996, pp. 18-21.➔ McNerney, T. (2000). Tangible Programming Bricks: An Approach to Making Programming Accessible to Everyone. Ph.D. Thesis.

C-cards is a card game with formal rules, and also an educational tool for teaching computer science to young students.

Students can create and manipulate their own computing machines, reason about design and implementation of card circuits.

Probability and information can be discussed on a concrete basis using a simple extension of the standard card deck. Experiments can be set up to understand redundancy and transmission errors.

Page 20: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Extras!

● Gaussian distribution

- For teachers mostly! -

Page 21: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Gaussian distribution

rnd rnd

1/2

1/4

1/4 2/4 1/4

rnd

Page 22: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Gaussian distribution (cont.)

rnd

rnd rnd

rnd

rnd

1/2

1/4

1/8

1/8 3/8 3/8 1/8

rnd

Page 23: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Gaussian distribution (cont.)

rnd

rnd rnd

rnd

rnd

4/16 6/16 4/16 1/16

rnd

rnd rnd rnd rnd

1/16

Page 24: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Gaussian distribution (cont.)

rnd

rnd rnd

rnd

rnd

5/32 10/32 10/32 5/32

rnd

rnd

rnd rnd

rnd

rnd

rnd

rnd

rnd

rnd

1/32 1/32

Page 25: C-cards Using paper and scissors to understand Computer Science Andrea Valente Aalborg University in Esbjerg Denmark Home: av Email:

Gaussian distribution (cont.)

/ 1 / 2 / 4 / 8 / 16 / 32 / 64

11 1

1 2 11 3 3 1

1 4 6 4 11 5 10 10 5 1

1 ... ... ... ... ... ... 1

...