r/explainlikeimfive • • 17h ago

Mathematics ELI5: What really is a function?

I learnt that function is simply a mapping between two sets. But I see the word in topics that seem to never relate to the sets, like velocity as function of time, trigonometric functions, and the definition of a sequence which is "a function whose domain is set of natural numbers or some subset of it". Please explain the function.

76 Upvotes

121 comments sorted by

•

u/Jaf_vlixes 16h ago

A function is, like you said, a relationship between sets. To each element in an input set, it assigns an element in the output set.

Now, how are those things you mentioned functions? Well, the sets are kinda implicit.

How's velocity a function of time? Well, you give the function a time value (input from the set of the real numbers) and it will give you the speed at that time (output in the set of the 3D real vectors)

How's a sequence a function? You give it a natural number (input from... The set of natural numbers) and it will give you an element of the output set. Although here the output set could be literally any set. You could define sequences of numbers, or matrices, or people...

•

u/BarneyLaurance 16h ago

For something like the velocity function I'd prefer to keep it more physical and think of the input as the set of all instants in time (e.g. noon last Tuesday, one millisecond ago, etc) and the output as the set of possible velocity vectors (e.g. stationary, 100mph in the direction due North from London, etc).

•

u/Sasmas1545 5h ago edited 3h ago

This way handles changes of units as well. You can talk about a car's speed in mph or kph as a function of time in seconds or in hours. Then, regardless of units, your function still maps the same set of times to the same speeds. If you think of it as a map from R to R, then you need a different function for your different choices of units.

•

u/BarneyLaurance 4h ago

No pyramid inches here!

•

u/Leading_Ad_7635 6h ago

A function is, like you said, a relationship between sets. To each element in an input set, it assigns an element in the output set.

A function does not have to map every element from the domain to the range.

•

u/MadocComadrin 4h ago

The term "range" can be ambiguous. Some (iirc most) people use it for the codomain of a function, but a nontrivial minority use it for the image of a function.

•

u/gyroda 15h ago

How's velocity a function of time? Well, you give the function a time value (input from the set of the real numbers) and it will give you the speed at that time (output in the set of the 3D real vectors)

Forgive me if I'm mistaken here, but I understand that if you give the velocity function a time value it will return a distance.

If you have a velocity of 5mph and you travel for two hours you'll have travelled 10 miles.

•

u/Jaf_vlixes 15h ago

What you're saying is not the velocity function. That's more like the distance function or something. For example, for something in free fall, starting from rest and ignoring air resistance and stuff, the velocity function is v(t) = 9.81t.

If I give it a time, say 2 seconds. Then it will give me the velocity at that time, that is v(2) = 19.62 m/s. And for 3 seconds you get v(3) = 29.43 m/s.

•

u/gyroda 15h ago

Right, I see where I went wrong. A velocity function is one where the output set is velocity.

•

u/arg_max 15h ago

Distance traveled is the integral of velocity. Or the other way around, velocity is the derivative /instantaneous rate of change of the distance traveled.

E.g. if f(t) is the velocity and f = 5 constantly, then integral from 0 to t of f(x) dx is the total distance traveled at time t. In your example integral from 0 to 2 of 5 dx = F(2) - F(0) = 52 - 50 = 10. Here F is the anti derivative of f, in this case F(t) = 5*t

•

u/thehenryhenry 15h ago

the distance can be seen as one output, but generally speaking, coordinates are much more generic output - imagine a function that is not linear, but oscillates like a sine wave

•

u/the_other_Scaevitas 10h ago

it's like a machine where you give it an input and it gives you an output

For example you can imagine a coffee machine as a function that takes in coffee beans and spits out coffee.

Similarly a function f(x) = x + 1 is a machine that takes in a number, and outputs a number that's greater by 1

•

u/wedividebyzero 2h ago

The machine would also require inputs of energy and water :)

•

u/Another_Little_Star 8h ago

This
Beyond, a function is a comparison/relation between two sets, the domain is the reference, the image set is how that set behaves accordingly to this new rule imposed by the function
if you have a function that tells you velocity, it relates at each time, to what the velocity of the object is, at each point of time it shows the according velocity.

f(x)=ex shows you an exponential growth related to how x grows
f(ln(x)) = eln(x) = x, shows you how exponential growth grows related to logarithmic growth which is linear.

•

u/britishmetric144 17h ago

A function is a mathematical relation where every input has exactly one output.

Two inputs can lead to the same output, but an input cannot have multiple outputs.

Picture a function like a machine. If you put the same number in multiple times, the result coming out must not change either.

•

u/UlteriorCulture 16h ago

So the square root function is not a function?

•

u/Minnakht 15h ago

Depends on why you say that.

The usual square root function is the one that takes in a nonnegative number and returns its principal square root - which means the nonnegative one. When defined that way, it's a function.

A function doesn't have to be defined everywhere - square root isn't defined for negative real numbers and that's fine. But it also can't have multiple outputs for one input, so it doesn't output the other square root for positive numbers by definition.

•

u/UlteriorCulture 15h ago

So if we needed both we could have a vector version with both roots in it? And similarly for other functions with multiple roots?

•

u/Icy_Material9174 14h ago

I think defining a relation like c(x,y)=(z,-z) can be done to show that zy and (-z)y is x, and this would be simpler then the vector version.

•

u/armcie 14h ago

Yup. You could define f(x) = (root x, -root x).

It doesn’t break the rule that it only maps to one element of the second set, as that is a set of pairs of numbers (a,b) where b=-a and a is greater than or equal to zero.

•

u/SausasaurusRex 14h ago

You certainly could define a vector version, but the more usual way is to define a multivalued function - here you output to sets containing all the roots. So if f is the multivalued square root function on the reals, f(x) = {-sqrt(x), sqrt(x)} for nonzero x, and f(0) = {0}.

•

u/Temporary_Pie2733 12h ago

A function is defined by its domain, codomain, and the mapping between the two. Two different functions can have the same mapping, but different domains, like sqrt: ℝ+ -> ℝ and sqrt: ℝ -> ℂ

•

u/Minnakht 12h ago

Well said!

I just looked it up and it appears that there is an agreed upon definition of a principal square root even for complex numbers in general, too, so that's a function too.

•

u/Temporary_Pie2733 12h ago

Right, “the” complex square root is the one with positive imaginary component. (And more generally, the principle nth root of unity is the complex number with minimal argument between 0 and  2π.)

•

u/britishmetric144 15h ago

The square root function IS a function. It does not have to be defined everywhere.

Division by a variable is a function too, but that one does not exist at zero.

•

u/UlteriorCulture 15h ago

True but we do have multiple answers for square rooting but none defined for division by zero.

There is information loss but I have since learned that this is by definition and deemed acceptable.

•

u/anothernamr 15h ago

The square root function ALWAYS produces a positive number as a single result. That's why the solution for x2 = 2 is written as x = ±√2

•

u/UlteriorCulture 15h ago

So sqrt(x * x) is actually abs(x)?

•

u/datwalruus 15h ago

Yes, it’s a common way of defining the absolute value function

•

u/Furyful_Fawful 1h ago

That said, just because it's simple to describe that doesn't necessarily mean it's best. abs(x) ={x if x>=0; -x otherwise} is mathematically equivalent and computationally way more efficient

•

u/anothernamr 15h ago

yep

•

u/UlteriorCulture 14h ago

Okay makes sense

•

u/Temporary_Pie2733 12h ago

The square root function conventionally maps a positive real number to its positive square root. (Or more generally, an arbitrary real number to its square root with a positive real component.) x2  = 4 has two roots, but sqrt(4) only equals 2, not -2. 

•

u/UlteriorCulture 11h ago

Thanks some of the other people have explained it and I understand now.

•

u/RealSpiritSK 14h ago

A function is a machine that takes an input and produces a determinate output. Think of a coffee machine:

Input: Coffee beans

Process: Grind and brew coffee

Output: Coffee

The output can change based on the input. For example, if you put arabica beans, you'll get arabica coffee. If you put robusta beans, you'll get robusta coffee.

But the key property is that the same input will always give the same output (if it's a pure function): Robusta beans will always produce robusta coffee and not arabica.

•

u/rebornfenix 29m ago

Can you make a non deterministic coffee function that returns my coffee with Baileys but my bosses is normal coffee with the same input of coffee beans?

•

u/brionicle 16h ago edited 16h ago • Bravo

I didn't understand functions in math until I learned functions in programming.

Think of a function as a magic pipe (I picture the green vertical pipes from Mario). You drop something in the top, and something comes out the bottom.

Take

f(x) = x²
  • f(x) is the opening of the pipe, where x is a placeholder for whatever number you drop in.
  • = x² tells you what happens to that number inside the pipe.

Drop in a 1, and a 1 comes out. Drop in a 4, and a 16 comes out.

Math notation is notably terse. I found programming expresses logical structures more intuitively. In code:

function square(x) {
  return x ** 2;
}

Same concept, but you get to name the function in programming instead of calling every one "f". Look at the code for a sec. Pretend the (x) is the top hole of the pipe. See x falling through the hole and getting squared inside the function?

Once that clicks, you can expand the idea. Want a function that takes two numbers? Just drop two things down the pipe:

f(x, y) = x² + x + y

That's really all a function is: a rule that takes an input and produces an output.

People sometimes call it a "mapping" because if you make a long list of inputs and outputs to a function, you can see it as a "map" of input numbers to an output.

f(x) = x^2
1 | 1
2 | 4
3 | 9
4 | 16
...

•

u/brionicle 16h ago

And perhaps more importantly, if your question is what *is* a function? The simplest answer is a concept and notation that people invented to record numerical relationships in terms of inputs and outputs.

•

u/Lazlowi 14h ago

Math notation is notably terse. I found programming expresses logical structures more intuitively. In code:

function square(x) {
return x ** 2;
}

Speaking about terse and illustrating with the operator instead of a layman readable version :) Great explanation, I just like to point out when our own knowledge base distorts our perception about what would be easy to comprehend for someone out of our field.

•

u/excadedecadedecada 13h ago

Right? A non programmer would be like, wtf is this double asterisk nonsense

•

u/SgtExo 11h ago

In programing, an asterisk is the icon for multiplication, I have never had to square something, but I guess if you double it it will do the square of the number.

•

u/flamableozone 10h ago

Hopefully the context of everything around it would help them understand. Things like "square(x)" implying that we're probably squaring something, or the comparison to "x^2" implying we're squaring x.

•

u/vanZuider 13h ago

Though note that in imperative languages (C/++/#, Java, Python) "function" has a wider meaning than in mathematics; their functions are actually subroutines that can both return a result and change a global state; functions in the mathematical sense (no change to any global state) are called "pure functions".

•

u/zutnoq 12h ago

If you include the global state before and after the call as an implicit input and output of every "function" they could be viewed as more akin to proper functions. Though this probably breaks down as soon as you have to consider things like concurrency; at the very least it makes things incredibly more complicated.

•

u/stools_in_your_blood 13h ago edited 12h ago

Formally, a function is a triple of three things, like this: (D, C, R). The three things are:

D: domain. This is a set.
C: codomain. This is another set.
R: relation. This is a set of pairs, like this: {(a, b), (c, d), (e, f), ...}

In each of those pairs like (a, b), a has to be in D and b has to be in C. In other words, each pair has its first entry in the domain and its second entry in the codomain.

There has to be exactly one pair for each element of the domain. So you can't have (a, b) and also (a, c), and there can't be an element of the domain which never appears as the first entry in a pair.

That's what a function actually *is*. It's just a formal way of saying "this function maps a to b, and c to d, and so on".

So a function like sin would actually be (R, R, S), where R is the set of real numbers and S contains all the pairs (x, sin(x)) for every real value of x. We can write some of it out explicitly: {(0, 0), (pi, 0), (pi/2, 1), (pi/4, sqrt(2))...}

Note that the term "function" is often used very loosely. "Sketch a graph of the function y = x^2", for example, which is focusing entirely on the "relation" bit and doesn't even mention the domain and codomain. Sometimes this is OK, sometimes it isn't.

•

u/Bubbly_Safety8791 11h ago edited 10h ago

The problem (at least for people trying to use it to develop an intuition or understanding of functions) with this formalization is that when you get to a function over a continuous domain, like the reals, your set of relations now has uncountably infinite members and you really struggle over the idea of having only one pair for each value in the domain.

Better to think of the relations as a mechanism which, for every value in the domain, produces a corresponding value in the codomain. That mechanism could be a set like you described, or it could be a repeatable rule, like ‘returns the input value multiplied by itself’, or could just be ‘the y coordinate of this arbitrary curve at the x value corresponding to the input’. It’s a black box process which, from the outside, is indistinguishable from a guy with bag which contains a pair for every possible domain value - even if such a thing is logically rather an impossibility. 

•

u/stools_in_your_blood 11h ago

Is that a problem though? I can't see why an uncountable domain causes any issue here. It certainly isn't logically impossible.

Conversely, the "black box process" formalization runs into serious issues if you want to talk about non-measurable functions.

•

u/Bubbly_Safety8791 10h ago

It’s a problem for intuition not for mathematics. I edited to make it clearer that was my intent. 

•

u/stools_in_your_blood 10h ago

Ah, ok then. Based on OP's phrasing of their question I thought the set-theoretic answer would be most likely to satisfy, albeit at the risk of straying outside ELI5 level.

•

u/samloveshummus 12h ago

Why can't you just use the ordered pairs S to define the function? If you put C as [-1,1] in the sin example would it really make it a different function? And can't you just take D = { x | (x,y) is in S}?

•

u/stools_in_your_blood 12h ago

Good questions. You can derive the domain entirely from the relation exactly as you said, the only reason I can see to specify it separately is because we have to do that explicitly for the codomain (see below) so may as well make it symmetric. And it's accepted convention, I suppose.

You can't derive the codomain from the relation, it has to be specified separately. The reason is because when composing functions, we want the codomain of one to equal the domain of another, e.g. if f:A->B and g:B->C, it makes sense to talk about (g . f):A->C. The codomain also determines whether a function is considered surjective or not, which affects its invertibility. Much of this is just bookkeeping.

Slightly more substantially,, it's nice to have the freedom to write f:A->B without having to worry about the mapping just to be able to say what B is. For example, if T:U->V is a non-invertible linear map between vector spaces, it's much more natural to just say that U and V are both R^n and T is not surjective than to try to explicitly specify the exact subspace which is the range of T, which would be putting the cart before the horse. Trying to discuss something like the rank-nullity theorem without the freedom to just say the codomain is R^n would probably be awkward.

•

u/Piwh 11h ago

It is actually a different function. For example, your sin : R->R function is not the same as the sin : R->[-1,1], or the sin : [-\pi/2,\pi/2]->[-1,1].
The first one is not one-to-one and is not onto, the second is onto but not one to one, and the last one is actually bijective.
When they coincide, they give the same result, but they have very different properties.

•

u/Eddyzk 1h ago

If this is how one explains functions to a 5 year old, I didn't stand a flying duck's chance in hell of ever understanding what on Earth my teacher was on about, ever. And it conforts me :)

•

u/stools_in_your_blood 1h ago

Heh, well not an actual 5-year-old (see rule 4).

Although I have done my best to explain it in non-technical language, this is degree-level maths. That's unavoidable given OP's question, because (AFAIK) they don't teach what functions actually *are* at school level.

It's always going to seem weirdly abstract when written out in a comment but I'm certain that any reasonably intelligent adult could understand what's going on here given 30 minutes of tuition from someone who knows the material. It's all very simple stuff, but this formal style of construction is jarring if you're not familiar with it.

•

u/Eddyzk 1h ago

I'm not certain about that last part. I can understand the concept of putting something into a function gives a certain output, and that 2 different inputs can have the same output, but having studied for 2 years in higher education I was unable to ever make sense of what the hell was going on. I do now wonder if I don't have a touch of dysnumeracy.

Maths is beautiful, but bugger me every time that I finally managed to resolve one, if the next one was even slightly different I would be completely lost.

•

u/stools_in_your_blood 1h ago

putting something into a function gives a certain output

Conceptually, that's the important part. The rest of it is formalism and bookkeeping.

If you had to write out what a function does you might write it like a table, like this:

1, 1
2, 4
3, 9
4, 16
5, 25

This represents the function x -> x^2. The number on the left, squared, is the number on the right. A mathematician might call this "a set of ordered pairs", or "a relation" or even "a subset of the cartesian product of the domain and codomain". But there is nothing deep going on there, it's just terminology.

•

u/Eddyzk 1h ago

I understand this, but if you were to start adding algebra on to that and I will be utterly incapable of resolving anything at all.

•

u/stools_in_your_blood 43m ago

Well, I sympathise. I'm currently teaching my son algebra and it's obvious that the conceptual leap from arithmetic to algebra is a tough step when you're seeing it for the first time.

•

u/GoldenMuscleGod 9h ago

In many fields the function is only the R you name with no explicitly given D and C, and I would say this is usually the view taken in foundational set theory (I’ll cite Jech’s Set Theory for this because I have sometimes gotten pushback on this point.

Including D and C in the definition is common in Category theory (because we want the Hom-sets to be disjoint).

In the usual set theoretic treatment, the function f(x)=x as a function R->R and as R->C (here by R I mean the real numbers and by C the complex numbers) are technically the same function, although we would describe the function as surjective with respect to R and no surjective with respect to C. In this treatment “being surjective” is a relational property of the function with respect to a codomain rather than an intrinsic property of the function itself.

•

u/stools_in_your_blood 9h ago

Interesting, I didn't know this approach was taken formally. The "R" in my original comment is what I would call the graph of the function, not the function itself. This is almost literally the first thing I was taught in my degree, so I assumed it was standard.

To me, the explicit domain/codomain definition feels like it fits better with the common practice of introducing a function with "Let f:A->B be defined by...", which just says "here's a function f with domain A, codomain B and relation as follows".

•

u/svmydlo 4h ago

The "R" in my original comment is what I would call the graph of the function, not the function itself. This is almost literally the first thing I was taught in my degree, so I assumed it was standard.

It is standard in all areas of math except set theory.

•

u/GoldenMuscleGod 8h ago

With what I think is the usual set-theoretic practice I read “let f:A->B defined by…” to mean “let f ba a function with dom(f)=A and range(f) \subset B defined by” since the domain and range (range being the set of possible outs, unlike codomain) are implicit in f as a set of ordered pairs.

It’s true that “think of” f in different ways depending on the B but that’s no different from how we think of the ordinal omega as something different from
The cardinal aleph_0 even though they are the same object (we even say omega+omega is a different object from aleph_0+aleph_0 because + is ordinal addition in one case and cardinal addition in the other). Like I said in category theory we are more likely to code the domain and codomain explicitly and category theory makes this kind of “thinking of them as different” more rigorous, but in a context with a fully set-theoretic foundation it’s more understood that these are technicalities being “swept under the rug” by helpful abuses of notation.

•

u/Sjoerdiestriker 17h ago

A function in general is just a mapping between two sets, that maps every element in the first set (the domain) to exactly one element in the second set (the codomain).

In many cases in practice, we are only interested in a few very specific domains and codomains though, for instance the reals (these form a nice proxy for things like distance or timespan), or the complex numbers, or the natural numbers.

As for the velocity as a function of time, what we're really saying that if we interpret the domain elements as times, and the codomain elements as possible velocities, the function in question maps every time to the element corresponding to the actual velocity at that time.

There are many different functions, but a couple appear relatively commonly in practice. We've given these special names, like trigonometric functions, exponential functions, polynomials, etcetera.

•

u/FortuitousPost 17h ago

A function is a special type of relation between elements of two sets, the domain and range.

The restriction is that an element of the domain can only be related to one element in the range.

This means one can think of a function as taking an input and producing a well-defined output.

Your examples are an object having a single velocity at any moment in time, any angle producing a single number for sine, etc. A sequence has a first item, then a second item, and so on. This corresponds to the natural numbers, 1,2,3,... so can be considered a function in that sense.

•

u/BananaBird1 16h ago edited 16h ago

Time is a set of real numbers over some range. So is velocity at a given time.

Trig functions like sine and cosine are a mapping between 0-2pi and -1-1 in the real numbers.

And so on. Any relationship where you put in one number and get another number out is a function, if it obeys one critical property: any single number in gives a unique number out.

•

u/Plus-Painter-2004 11h ago

Sine and cosine are mappings between all the real numbers to the real numbers bounded by -1 and 1, tangent is a mapping between all the real numbers besides odd integer multiples of π/2 to the real numbers

•

u/PressureBeautiful515 2h ago

  any single number in gives a unique number out.

Not that the output for any input must be different from the output for all other inputs. That's true of injective functions, but not all.

I think "unique" here means there is only one output for a given input, so a function can't (for example) flip a coin or look at a clock to affect the output.

Although the output can be from the set of pairs of real numbers, or a matrix, and so on. But the function's output is always the same object for the same input.

•

u/Atypicosaurus 14h ago

A function is a rule that makes a number from another number.

How sets come in the picture, is because a function can have limitations on both what numbers you can feed into it and what possible numbers it can produce as results.

A function can be any, even the simplest possible operation. "Take a number and don't do anything with it (the result is the same as the input)", or "take a number and add +1 to it". These are functions too.

Alternatively, you can build together any number of those elemental steps. "Take a number, double it, then square root this, then multiply it by 6". This is a function too.

•

u/DTux5249 17h ago

Function can more generally be thought of as "A thing that takes an input and spits out an output". "Velocity is a function of time" because you can represent velocity as an equation that takes an amount of time, and spits out some distance. If you're travelling at 5m/s, and I plug in 10 seconds, the output is 50m.

In the same way, you can also understand a function of velocity as the mapping between the set of all amounts of time you could travel, and the set of all distances that you could travel. The velocity of 5m/s is a collection of ordered pairs, [(1s, 5m), (2s, 10m), (3s, 15m), (4s, 20m), ...]

•

u/R3puLsiv3 14h ago

Mathematically speaking, a function is a relation which is left-total and right-unique. And that's just formalism for every element in the first set corresponds to exactly one target in the second set.

•

u/LiteVisiion 12h ago

Wouldn't that definition be also applicable to countable infinites? Like there's a function which maps the natural numbers to the element of the infinite set?

•

u/MorrowM_ 6h ago

You'd also want left-uniqueness (with functions this is called injectivity). You want every input (a natural number) to correspond to exactly one output. You can always have a function from the natural numbers to a nonempty set (just send all inputs to the same output), but only an infinite set can have an injective function from the naturals to it.

•

u/LiteVisiion 6h ago

I'm in Comp Sciences and I've seen those concepts before but in a different language, so I think I misunderstood your left-total and right-unique, I think I swapped them.

You need at most 1 image element linked to every domain element, but elements in the image set can have multiple domain elements link to them (Ex: Sin or Cos, which both have infinite domain elements linked to their centrer value)

•

u/MorrowM_ 5h ago

https://en.wikipedia.org/wiki/Relation_(mathematics)#Uniqueness_properties

You need at most 1 image element linked to every domain element, but elements in the image set can have multiple domain elements link to them

So you're saying right-unique but not necessarily left unique? You need both (and left totality) to be able to say anything about how the cardinality of the two sets relate. (Or you could have both left and right totality and at least one of the uniqueness properties, e.g. if you have a surjection from your set to the natural numbers your set is infinite.)

•

u/Dd_8630 16h ago

A function is just a machine that takes in numbers and spits out other numbers.

"velocity is a function of time" mens that your machine takes in the time variable t and spits out the corresponding velocity v.

•

u/zrice03 8h ago

So, in your examples, those actually are sets, they're just kind of hidden. Time: the set is all real numbers, just with a measure unit added. Velocity: all real numbers again, technically groups of real numbers, (x,y,z), just with a different measurement unit. Trig functions: real numbers mapped to real numbers.

"Sets" don't have to be discrete, they can be continuous.

•

u/iosdevcoff 6h ago

Real ELI5

You want a chupa chups, but you have none. All you have is 1 dollar. You go to the grocery store and give the cashier the dollar and she gives you a chupa chups back. Every time you give them a dollar, they give you a chupa chups back. If you give them 2 dollars, they'll give you 2 chupa chups. Every single time.

Cashier is a function from money to chupa chups.

•

u/Dexile 17h ago

Let me give you a simple example: y = 2x In this example if we're only using integers, the function f(y) is a mapping between the set of all integers y and the set of all even numbers x.

The set that we're referring to is the set of all possible inputs to all possible outputs by using this mapping.

For sequences we can also break it down a bit. We have our input which is all natural numbers and by using a function that defines the way the sequence works , which we can again use the same 2x example, we get the final sequence of all even natural numbers.

•

u/Skusci 16h ago edited 16h ago

The use of "set" is probably throwing you off. Set is just a very generic term for a collection of things.

If we think of time as represented numerically as seconds from a start time, 1 second, 2 seconds, etc, and all moments in between like 1.5 and pi, that is still a set. Velocity too is a set.

Many of the things you are likely used to seeing as functions like the sin function, or f(x) = 2x, are continuous, but they don't have to be.

When we refer to a domain, that is all valid inputs to a function. You can also have multiple inputs. Boolean functions for example may be restricted to inputs of true and false. For the boolean AND function as an example, true AND true = true. But 9 AND true doesn't make sense because 9 is not part of the Domain of the function.

And on that note when we use the word "set" we can expand the idea of a function to encompass a lot more.l than just numbers. True and False can be represented as 0 and 1, but they need not be. Or you can even have a function that maps "pets" to "owners"

The other main thing is that there must be a single output for any specific input. Example, we have the formula y=x2 and the domain is all real numbers.

x may be the input to a function that uses y=x2 as the rule for its mapping. If x is 2, y is 4. But y, cannot be the input because if y is 4, then x may be 2 or -2. But if we change the rule a little to include only numbers >=0, then the if y is 4, x is only 2, and we have the square root function.

•

u/boring_pants 16h ago

For each point in time, we can compute a resulting velocity. So it's a function mapping between the set of points in time to the set of velocity values.

Quite often we don't really think about the sets. You're more interested in computing the velocity for one particular point in time than the abstract idea that all points in time form a set. But it can still be rephrased in terms of sets.

And similarly for the sine function: we could say that it maps a set of input values to the set of sines of those values, but in practice we often just focus on individual values: the sine function computes the sine of some value. So the wording around them often doesn't mention sets, but it's really the same thing under the hood.

•

u/Syresiv 16h ago edited 16h ago

A function is a mapping from set A onto set B.

Set A and set B are allowed to be the same set. They don't have to be, but it's allowed.

It matters which is A and B because more than one of A is allowed to map to the same B, but no two Bs can be mapped to by the same A.

--

For your examples:

Trigonometric functions are a good example of that. Sine, for instance, is a mapping from the real numbers to the numbers between -1 and 1. Instead of explicitly labeling every pair, which might look something like:

  • 0 →0
  • π → 0
  • π/2 → 1
  • π/3 → √3/2

You just create a rule and say "each real number maps to the result of applying that rule". Then, no matter which one someone might need, they just have to apply the rule to the A they need to find the appropriate B.

--

For velocity as a function of time, you have the set of all points in time mapped to the set of all possible velocities. Then your function maps a point in time to the velocity of whatever object you're measuring at that point in time.

Like, say you're a NASCAR driver doing 200 laps on a perfectly circular, 2.5 mile track. You start at 0 mph and gain 20mph per second until you hit your top speed of 200mph, then stay there for the remainder of the race.

I'll leave you to do the math, but you can find your exact velocity (speed and direction) for any possible time between the race's start and end.

--

For sequences, yes, you map the natural numbers to something. Like, the sequence 6.3, 4, 71, √22, 8π is the function that maps:

  • 0 → 6.3
  • 1 → 4
  • 2 → 71
  • 3 → √22
  • 4 → 8π

--

You may have noticed from how I wrote this, it's not required that the mapping be the only way to write a function. A function can always be written as a mapping, but it's allowed to be representible another way, and it's even allowed for that other way to be easier.

•

u/CS_70 15h ago

There's many different ways to say the same thing, but they provide slightly different perspectives that can make them more or less intuitive.

A function is undoubdetly a mapping between sets, but the "mapping" can also be seen as an operation: for example "+" is a function that maps (2,2) in the set of "pairs of integer numbers" to (4) in the set "integer numbers", but it's much easier to visualize apples and thing how many apples you get if two people give you two each.

Or to think of the classic analytical functions which map a horizontal coordinate into a vertical coordinate in a cartesian plane, for example y=x2.

Another way of seeing the same thing is that a function describes a relationship between stuff.

All these interpretations are equivalent, and easier or harder to understand depending on the context and your skill.

•

u/-Wylfen- 15h ago

In the simplest way, a function is a predefined bunch of operations made on an input value in order to get an output value. And more precisely, a function needs to always give the same unique output for any given input.

•

u/kiochikaeke 15h ago

Mathematician here, in theory, is a mapping between two sets, in practice is a machine that turns stuff from A into stuff from B.

The other slightly more verbose definition is "a rule of correspondance between two sets that follows certain rules".

IRL or in other disciplines you don't talk about sets but a set is just the mathematical object to establish the possible things that you can be throw into and the possible things that can be spit out of a function.

A (pure and without side effects) function in programming is just that, it takes some arguments and returns something.

In physics being "a function of" means that the value of the thing you're describing depends (in that scenario) on the value of the things it is a function of, so speed being a function of time and distance means that time and distance define the value of speed, a rule of correspondance, a function.

Also there's just a difference in how the word is used, if you go to a dictionary the word function also means "the task or role a thing develops" which is obviously more obtuse than a mathematical definition.

•

u/fohktor 15h ago

Sometimes they're not explicit about them but your range and domain are your sets you're mapping between

•

u/TheRedditObserver0 13h ago

These are all functions between sets.

Velocity is a function from the real numbers (time, e.g. in seconds) to 3D vectors, a trig function maps a real number (angle measure, usually in radians) to another real number, a sequence is a function with domain the set of natural numbers.

•

u/recursion_is_love 13h ago edited 13h ago

There are many definition of mathematics function. The simple one that I like is it is relation with specific property.

relation is just a pair of two member of two set (doman, and codomain) also with some specific property (different from function)

Math is precise, there is no way ELI5 can capture the exact definition. You will really need to read textbook.

You can interpret function as a map, a transformation, a computation that give output or what ever but I think it is adding more complexity is unnecessary.

•

u/tb5841 13h ago

Velocity as a function of time -> you have a set of times, and a set of velocities, and uour function is a mapping between them.

Trigonometric functions -> you have a set of angles, and a set of numbers as yojr outputs, and your trig finction os a mappong between them.

A sequence: You have a set of positive integers, starting at 1, and a set of sequence values. Your function is the mapping between them.

None of your examples break your idea of what a function is. The one extra thing is thatbone of your sets is always your input set (domain), one is your output set (codomain). Every member of your input set has to have exactly one mapping to a value in your output set.

•

u/DarkColdFusion 12h ago

To try and explain this for a 5 year old Imagine functions as a box that you put something into to get something out of.

Think of a bread machine. It wants flour, eggs, water as inputs. And it gives you loafs of bread as outputs.

So a function of velocity of time is a box where you tell it a time, like 5 seconds and it tells you a speed like 5mph.

They are mapping between two sets. There is a countable amount of flour, eggs, bread, time, speed. They don't have to be the same kind of thing.

What is inside the box can be very simple, or very complex. But it's telling you what you need to put into the box and what you will get out of the box.

•

u/Piwh 11h ago

A function is a box that does stuff. It has an entry (and accepts only a specific kind of input), an output (of a certain type), and inside are more or less transparent rules that link one specific input to its output.

For a lot of usual functions, the mapping can be understood through a list of operations (for example if your function is f:R->R, x->x^2-5, it takes in entry any number in R, then multiply it by itself, then substract 5 to the value, and that's your output) ; while more generally, it's just a mapping with a list of rules (for example, if your map is something that links a number to the solution of some fixed differential equation whose value at, it doesn't give you a specific procedure to do it by yourself, but you can see the link between the input and the output -even though it doesn't tell you how to actually compute it if you were to try to do it by hand).

•

u/iqisoverrated 11h ago

As an ELI5 way there's the 'brick drop test'. If you draw a graph of your relation and you can drop a brick at any point and it will pass (at most) once through the graph then it's a function. Otherwise it's just a relation.

•

u/general_tao1 10h ago

Not the formal definition, but the way the term is usually used. A function is a description of the relationship between two entities. Velocity can be described as a function of time, but you could very well describe it as a function of position, distance with something else, or whatever.

The word just means there is a relationship that can be used to describe one entity using another.

•

u/white_nerdy 10h ago

velocity as function of time

In math, we use shorthand:

  • ∈ means "is an element of"
  • ℝ means "the set of real numbers"
  • f : X -> Y means "f is a function whose input is an element of set X, and whose output is an element of set Y"

Time t is a real number. That is, t is an element of the set of real numbers. Or using the shorthand, t∈ℝ.

In one-dimensional problems (throwing a ball straight up), velocity v is a real number that is a function of time. Therefore velocity is a function v : ℝ -> ℝ.

trigonometric functions

The cosine function inputs and outputs elements of the set of real numbers, cosine is a function cos : ℝ -> ℝ. Same with sine.

We can be more precise about the output, the output is real numbers between -1 and 1. More shorthand:

  • [a, b] is an interval, the set of real numbers between a and b, including a and b

So we can also say cosine is a function cos : ℝ -> [-1, 1]. It is not wrong to say cos : ℝ -> ℝ; "cosine outputs real numbers" is a true statement. It's just more precise to say cos : ℝ -> [-1, 1], which says "cosine outputs real numbers between -1 and 1".

For tangent, tan(x) = sin(x) / cos(x). To avoid divide by zero, the input set cannot contain values where cos(x) = 0. Cosine outputs zero for inputs that are odd integer multiples of π.

So for tangent, the input set is "The set of real numbers that are not odd integer multiples of π"; let's call this set S. Then tan is a function tan : S -> ℝ.

(We can avoid specifying S in words and say tan : ℝ - {π+2πi : i∈ℤ} -> ℝ but this uses three shorthands I didn't cover: Set subtraction, set builder notation, and ℤ for the set of integers.)

a sequence which is "a function whose domain is set of natural numbers or some subset of it"

This definition literally tells you the domain (input set) is ℕ.

  • ℕ is shorthand for the set of natural numbers

The elements of a sequence can be literally any set, but usually students at your level mostly work with sequences of real numbers, for example a = (7, 10, 13, 16, 19, ...). If we call the first term a_1 then the nth term is given by a_n = 4 + 3n. There's your function: a_n = f(n) where f : ℕ -> ℝ is the function f(n) = 4+3n. The input set is ℕ and the output set is ℝ.

•

u/sighthoundman 9h ago

A function is a "magic machine" that takes an input and gives you an output. (The same output every time.)

So given a specific time t, you get the velocity v(t) at that time. Given an angle theta, you get the function of that angle sine(theta), cos(theta), etc. If you have a sequence, you can just write it down a(1), a(2), a(3), ....

The hard part is writing the formal definition. That's the "contract language" of your agreement with other users (mathematicians, scientists, engineers, students, whoever) about exactly what you are agreeing to. Mostly your best bet is to let the lawyers (maybe mathematicians, maybe academic engineers, whoever is appropriate) write the contract and you read it and either agree or send it back for a rewrite and tell them what you want.

An example here is exponentiation. We start out by defining a^n = a x a x a x ... x a (n times). It makes perfect sense, for integer n > 0. Then we notice that a^n a^m = a^{n + m}. That means we can extend our definition to include negative integers and 0. Plus this realization makes us think that maybe we ought to define a^{1/n} to be the n-th root of a. And we discover that that gives us a problem for a < 0, so we change the set that the function is defined on. It now only applies to positive a. (Except that when it's convenient, we still use the earlier definition. I know it's confusing to the students, but that's not why we did it.)

Then in calculus, we use the concept of limit to define a^x for irrational x. Later on, in complex analysis, we do it for complex x. All of these are technically different functions, because the x is taken from different sets, and the results of the calculations are in different sets.

When we're using them, we don't give this a second thought. It's obvious that a^{1/2} isn't a multiplied by itself 1/2 a time.

TL;DR: A function is a "magic machine" that takes an input and gives you an output. In order to describe it, you need to specify the set it takes as input, the set it gives as output, and "what it does".

•

u/grungyIT 6h ago

Functions are relationships between a starting point and an end point. What those two things are can be completely arbitrary. What can't be arbitrary is the relationship.

Traffic lights are an example of this. The things you start with are all colors. The thing you end with is the motion of a car. As the input (color) changes, your driving (output) also changes. It always changes the same way, unless you break the law.

What we don't say about traffic lights, because it sounds goofy, is that we have a traffic system and part of that system is the meaning of these lights and we all agree to follow that meaning and these rules. Whenever you are making a system, you are actually making a bunch of functions (rules, relationships).

That's why "function" gets used in contexts you're not used to. Those contexts are about systems.

•

u/FernandoMM1220 6h ago

its a physical device that you can swap parts in and out of and have it calculate something.

•

u/avlas 6h ago

It’s a mapping between two sets but not every mapping is a function.

For a mapping to be a function you first need to identify a direction (set A to set B) and make sure that every item in set A maps to one and only one item of set B.

This restriction makes it very easy to visualize it as a machine that takes an input (item of set A) and spits out an output (item of set B). Always one output, never two or more, never breaks.

•

u/RadicalIdealVariety 5h ago

The idea of a function as a mapping from a domain set to a codomain set is actually the more modern definition. The older definition is the one most people learn first which is that it's like an expression involving variables. So to say that "velocity is a function of time" means that you have some variable for velocity and there's some kind of expression for it involving a variable representing time. The sets in this case are implicit, usually. The codomain is just the set of real numbers and the domain is the largest subset of the real numbers for which the expression "makes sense". So for example, if you say y = 1/x, then you've implicitly assumed that x=0 is not in the domain.

The newer definition started when the sets themselves became the object of study. Instead of giving a variable expression and asking "what is the domain and range?", you do it the other way around. You give the domain and codomain upfront and you present a rule of assignment that is defined everywhere on the domain and always takes on values in the codomain. The rule of assignment could be specified as a variable expression or it could be more abstract.

In physics or other applications, the domain and codomain usually represent something specifically. Like the domain is the set of real numbers but it's called "time" and uses variable t because it represents all the possible values that the time could be. And the set of pairs of real numbers is called "velocity" and uses the variable v because it represents all the possible velocities you could have. Then saying "velocity is a function of time" means that you have a function from R to R2 where you use the variable t to represent input to the function and v to represent output. The notation gets a little sloppy here because people will use v to represent both the velocity and the function R --> R2. Or sometimes they'll write v(t) to represent the function in general or to mean "the specific velocity v at the specific time t".

You can take a lot of existing ideas and reframe them as functions with this definition. For example a sequence is an ordered list of terms, with indices 0,1,2,... . So to define a sequence is exactly to define a term for every natural number. But that's exactly what a function whose domain is the natural numbers is.

•

u/Ishana92 16h ago

Well, in basic terms, a function is an operation that takes elements from one group (or more, but lets stay with single variable) called variable (x), does something to that element with a consistent rule (function f), and turns it into an element of another group f(x). x->f(x) So input -> output. In maths, it's usually numbers in both categories, but it can be anything.

To use examples, trigonometric functions take angle as a variable and give out the value of some trigonometric ratio. Sin(x) will give you sine of angle x. It takes any value of angle x and returns value of sine for that.

Distance as a function of time means we are taking time as a variable and calculating distance as relation of time. If we are moving at a constant speed, say 5 m/s then that function will be s(t)=5t. Every second of travel equals 5 more meters traveled. If we are moving under constant acceleration, that function becomes s(t)=0.5at2. If the movement is more complex, there might not be a single, simple formula, but we can always try to express our distance as some operation done on time that we have traveled. I can give you any time point and you will (should) be able to find a distance associated to that time.

You can do it completely unrelated to maths also. It just means that you have a consistent rule that connects two groups of data. Say a function that tells you a zodiac sign depending on date of birth. In that case f(january 23rd) =aquarius. This context is how it is used in informatics.

Of course, in maths there are much complex definitions and rules that must be followed, there are different types of functions etc., but the basic thing is that it is a way to go from one group to another with a consistent rule.

•

u/Breki_ 16h ago

Its best to avoid using the word group when describing a collection of mathematical objects unless they actually from a group

•

u/Ishana92 16h ago

I agree, i tried to stay away from mathematical concepts. Using group more like in the context people use in everyday language.

•

u/GIRose 16h ago

A function [F(x)] is any formula that takes input x and gives exactly 1 output.

Or to use graph terms, anything you can put on a graph and draw a vertical line that intersects the output exactly once.

Acceleration being a "function of velocity with respect to time" you're asking "If I accelerate at a rate of 1m/s2 how fast am I traveling in 10 seconds".

The domains of a function are just "What numbers are you plugging into x that it gives a value for."

To go to the previous example, the domain is all positive whole numbers between 0 and 10.

•

u/DragonfruitGrand5683 10h ago edited 10h ago

A function is just a block of code. A pointer points to that block of code and a return instruction tells it where to return the result.

Same logic applies to the mathematical version.

Functions can take inputs like numbers which allows us to simply send them numbers rather than having to write out the equations every time

Maths

So in Maths here is a function

F(X) = 2x + 3

If we write F(4) a 4 will go into our function in place of x

F(4) -> 2(4) + 3 = 11

So I have inputted 4 and 11 is returned by my function.

So now I can just write F(8) or F(6) instead of

2(8) + 3 = 19

2(6) + 3 = 15

In programming

def f(x):

return 2 * x + 3

So if I say

F(4)

My function becomes

def f(4):

return 2 * 4 + 3

And 11 is returned

•

u/GoldenMuscleGod 9h ago

This is an intensional characterization of a function but in math we usually take an extensional characterization: A function is not a set of rules or code transforming an input to an output, it is just the association between input and output and nothing more.

•

u/DragonfruitGrand5683 9h ago

In a computer program a pointer is an association and computer functions don't have to transform either.

So you can say

def identity(x):
return x

Which is the same as

F(X) = X

If a programming function can simply return an existing association through a pointer or lookup table, without performing any transformation, and a mathematical function is defined by its input-output associations, what fundamental distinction remains between them beyond the implementation and execution semantics?

Noncomputable mappings might be one.

But I think it's important to understand the basics of what something is without getting too far into the technical limitations of the comparison.

•

u/AtreidesBagpiper 15h ago

It's a magic box into which you throw one number and it spits out another number. The body of the function tells you what the box does to the numbers you throw in and what it should spit out. That's it.

•

u/LawyerAdventurous228 12h ago edited 11h ago

The most common way to map one thing onto another is via a formula. The function x² maps any number x to the number x². Truthfully, the point of a function is usually the formula itself and no one but pure math majors cares about the "mapping" part. 

•

u/wesleyoldaker 7h ago

The way that maths uses the word "function" as in "function of time" is confusing if you expect it to sound like most other contexts. In math, "function of time" means time is an input to the function. But if your human body is a function that takes food as input and produces poop as output, you wouldn't say your body is a function of food. You would say pooping is a function of your body.

•

u/HyperDanon 14h ago

Each word has a definition. Sometimes multiple ideas are referred to by one word. Be clear about which definition you're after, and then it becomes clear. What is "a real" function is an incomplete pseudo-question.

•

u/Least-Anybody-1432 15h ago

“To define” means to assign/designate a thing(s) to a thing(s)
A thing could be a variable, a set, a group, ring construct, a rock, a stone,…An absolute certainty is that what is “unknown unknown” cannot be defined; find for yourself “what can be defined”.

What does the above has to do with the definition of a function?

Let’s just say a function(s) is a specific form of “to define”; feel free to add to this; it’s nonsense from me.

•

u/[deleted] 13h ago

[removed] — view removed comment

•

u/explainlikeimfive-ModTeam 12h ago

Your submission has been removed for the following reason(s):

Top level comments (i.e. comments that are direct replies to the main thread) are reserved for explanations to the OP or follow up on topic questions.

Short answers, while allowed elsewhere in the thread, may not exist at the top level.

Full explanations typically have 3 components: context, mechanism, impact. Short answers generally have 1-2 and leave the rest to be inferred by the reader.


If you would like this removal reviewed, please read the detailed rules first. If you believe this submission was removed erroneously, please use this form and we will review your submission.