## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Functions 35
Functions
I thought we'd talk
and their related
concepts next.
It's a prey
abstract, but you'
be fine as long as
each new idea.
Got it.
Let's start by
defining the
co nce pt its elf.
Sounds
gd.
Functions
36 Chapter 2 The Fundamentals
Imagine the
foowing
scenario:
Captain Ichinose, in
a pleasant md,
decides to treat us
freshmen to lunch.
So we foow him
torestaurant A.
This is the
resta urant
Udon 500 yen Cuy 700 yen
1000 yen
Broiled l
1500 yen
But there is
a catch,
ofcourse.
What
do you
mean?
Since he's the one paying,
he gets a say in any and
a orders.
Kind of
like this:
Foow
me!
?
Functions 37
We wouldn't reay be able to say no if he
told us to order the cheapest dish, right?
Or say, if he just told us a to order
dierent things.
Yurino
Yoshida
Yajima
Tomiyama
Udon
Cuy
Broiled l
Udon for
everyone!
Yurino
Yoshida
Yajima
Tomiyama
Udon
Cuy
Broiled l
Order
dierent
stu!
38 Chapter 2 The Fundamentals
Even if he told us to order our favorites,
we wouldn't reay have a choice. This might
make us the most hay, but that doesn't
change the fact that we have to obey him.
You could say that the captain's ordering
guidelines are like a “rule” that binds
elements of X to elements of Y.
Yurino
Yoshida
Yajima
Tomiyama
Udon
Cuy
Broiled l
Order what
you want!
Yurino
Yoshida
Yajima
Tomiyama
Udon
Cuy
pork
Broiled l
Rule!
?
?
?
?
X
Y
Functions 39
And that
is why...
We define a “function from
X to Y ” as the rule
that binds elements in X to elements in Y,
justlike the captain’s rules for how we
orderlunch!
This is how
wewrite it:
f is completely
arbitrary. g or h
would do just
aswe.
Gotcha.
Functions
A rule that binds elements of the set X to elements of the set Y is called “a
function from X to Y.X is usually called the domain and Y the co-domain or
target set of the function.
function!
or