Presentation 13: Functions

Abstract:

In this workshop we look at what functions are, why computers need them; what are the examples of functions in the world.

We then go into looking at different function types: number functions (that produce a number as a result), boolean functions (that produce true or false) and string functions (that produce words). 

We define a way to uniquely specify a function type by a visual shape. 

Finally, we "plug" functions into each other and try to produce the result.

This workshop was inspired by Emmanuel Schanzer's "Bootstrap" methodology that teachers programming to middle schoolers through the media of images and animations.

Preparation:

You'll need a big black board.

Presentation:

Function definition

Today we are going to talk about FUNCTIONS!

Who doesn't know what functions are? (most of the kids should raise their hands)

Great!

Function is like a car factory. You send their different parts: wheels, doors, seats, it does something and produces a new car.

Draw on the board a factory box that gets parts and outputs a car.

There are other examples of functions. 

1. Adding numbers is like a factory too it gets two numbers, adds them and gives you the result

2. Readers are leaders homework: you get a book and a sheet of paper, you read a book and fill out a sheet of paper, that's the result of the function

Function presentation

Let's try to draw a function. If it produces a number it will look like a square:

You can plug in functions into each other. Who can tell what the result of this function is?

To solve a function, try to find the smallest box and solve it, then replace it with the result

Here are some other examples of number functions:

Exercise. Everybody gets a sheet of paper and draws a function

123+482

(the numbers are big because otherwise children tend to add them instead of thinking about 

(I tried to give the kids a more complicated example: 6+9-4 and none of them were able to draw the correct representation, it was too premature to expect that)

Show the solution on the board

String functions

Did you know that you can add not only numbers but also words?

I use oval shapes to represent words and squares to represent numbers. 

Give several examples to kids where they have to add words or subtract substring from a string. Draw the functions in ovals

bulldog - dog = bull

mo + (father - fa) = mother

Make sure to have unique solutions. For example, banana - na is not unique, it can result in ba or bana.

Once kids familiarize with these problems enough try something harder:

(This should result in "fun")

Again, ask kids to use pencil to copy the problem to their sheet, then erase the inner functions and replace them with the result

Boolean functions

What is the result of this function?

As you noticed this shape is not oval and not number, because it results in either True or False. Everything that results in either true or false will have rhombus shape.

What are other examples of functions that result in true or false?

Pick a child name (Anna) and try to solve this problem: 

This is true for everybody in a class. Who can think of the case where it would be false - somebody not a boy and not a girl?

What if you use AND instead of or? Can somebody be a boy and a girl at the same time?

What about this one?

This is True. "Anna is a boy" is false, and NOT false is true.

What is not true? yes, it's false.

Composite functions.

We can combine different shaped functions. For example:

Go over the above example and solve it, from inner functions to outer ones, so that the kids understand.

If you still have time left, give kids assignments with more string manipulation functions.

You can also discuss the cases where the subtraction is not unique, and what to do there:

mapama - ma = mapa? pama? pa?

You can define different subtraction operators:

*- subtracts what's before the word

-* subtracts what's after the word

-*- subtracts inside a word