UPI Study › Courses › Discrete Mathematics › Free lessons › Lesson 2.6 Free with a free account
Functions: Definitions and Terminology
Discrete Mathematics · Chapter 2: Set Theory and FunctionsSection 2.6 · lesson 14 of 878 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Discrete Mathematics.
Lesson complete
Earn the 4 college credits for Discrete Mathematics
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Injective Functions: One-to-One Mappings and Their Properties →← Partially Ordered Sets and LatticesNext lesson: Injective Functions: One-to-One Mappings and Their Properties →
In this lesson
Exactly one output for every input - and what happens when a rule falls short.
- Define a function as a special relation
- Distinguish domain, codomain, and range
- Decide whether a rule is well-defined
- Compose functions, and use the identity function
Transcript
Everything said in the video, section by section (1,214 words). Read along, or search it.
Set Theory and Functions
Functions: Definitions and Terminology
This section defines one of the most important ideas in mathematics and computing, the function. We'll see a function as a special kind of relation, and separate its domain, codomain, and range. We'll ask what it means for a rule to be well-defined. And we'll compose functions, and meet the identity function.
The Opening Problem
A Build Pipeline, Stage by Stage
A software build pipeline turns source files into a running service, in stages. A compile stage converts each source file into a compiled object. A deploy stage turns each compiled object into a running status. Each stage, examined closely, is just a rule assigning exactly one output to each input. That's precisely a function. Chaining the two stages into one pipeline, straight from source file to status, is what mathematicians call composing functions. And a build that isn't reproducible, where compiling the same source twice can produce two different objects, has failed to define a function at all.
Definition 2.6.1
A Function Is a Special Relation
Recall that a relation from A to B is any set of ordered pairs, with the first element from A and the second from B. A function f from A to B is a relation in which every element of A, is paired with exactly one element of B. We write f of a equals b, for that unique b. Exactly one packages two conditions. First, every element of A is paired with at least one element of B. No domain element is left unassigned. Second, every element of A is paired with at most one element of B. No domain element gets two different outputs. Take A to be three source files, auth, parser, and logger. The compile rule pairs each one with its compiled object, exactly once. So it's a function.
2 Failures
When a Relation Isn't a Function
Now two relations that fail. First, suppose a non-deterministic build sometimes produces a different object for the same source file. parser dot p y is paired with parser dot o, and also with parser v two dot o. That violates the second condition. parser dot p y doesn't have a single, unambiguous image. Second, suppose logger dot p y fails to compile at all. It appears in no pair whatsoever. That violates the first condition. logger dot p y is left without any output, so the relation isn't a function from A to B.
Definition 2.6.2
Domain, Codomain, and Range
For a function from A to B, the domain is A, the full set of legal inputs. The codomain is B, the declared target set, fixed as part of stating the function. And the range, or image, is the set of outputs the function actually produces. The range is always a subset of the codomain, but the two need not be equal. For the compile function, the codomain has four objects, including cache dot o. But the range has only three. cache dot o is a legitimate kind of object the build system can produce. No source file here ever compiles to it. The codomain describes every output the function is declared capable of. The range describes only what it actually produces, and finding it means checking every input.
A 2nd Example
A 4-Bit Hash
Here's a second example, a hashing function h, mapping three files to a four-bit digest. Its codomain is all sixteen possible four-bit strings, from zero zero zero zero to one one one one. Suppose report dot p d f hashes to zero one one zero, and notes dot t x t to one zero one one. And image dot p n g hashes to zero one zero one. Then the range is just those three strings, three of the sixteen in the codomain. That's why the codomain of a hash function is normally far larger, than any range a realistic set of files produces.
Notation and Well-Definedness
A Rule Must Give Exactly One Output
The notation f from A to B states the domain and codomain in one expression. And f of a equals b records that input a is assigned output b. A rule is called well-defined only if it assigns exactly one output to every input. That becomes a genuine question whenever the same input can be described in more than one way. Here's a classic failure. Try to define a function from the rationals to the integers by sending a over b to a, using whatever fraction is given. Take one-half. Written as one over two, the rule gives one. But two over four names exactly the same number, and the rule gives two. One input, two outputs, depending on the representation. The rule isn't well-defined, so it isn't a function on the rationals at all.
Back to the Pipeline
Reproducible Builds Are Well-Defined
The same discipline governs the build pipeline. Suppose compiling byte-identical auth dot p y on two different machines, or at two different times, could legitimately produce two different compiled objects. Then the assignment from source file to compiled object would fail to be well-defined, in exactly the same way as the fraction rule. And a content-addressed cache built on top of it could no longer guarantee that identical inputs resolve to a single, reusable result.
Definitions 2.6.3 and 2.6.4
Composition and the Identity
If f goes from A to B, and g goes from B to C, the composition g after f goes from A to C. It's defined by g after f, of a, equals g of f of a. First apply f, then apply g to the result. Extend the pipeline with a deploy function g. auth dot o and parser dot o map to deployed. logger dot o maps to failed. And cache dot o maps to skipped. Notice that g must be defined on the whole of B, including cache dot o, which f never actually produces. That's what makes the composition a function on all of A. The identity function on A, written i d sub A, sends every element to itself.
Figure 2.6.1 and Table 2.6.1
The Pipeline as Arrow Diagrams
This figure shows the pipeline as arrow diagrams. Every source file on the left has exactly one outgoing arrow, into the compiled objects. cache dot o sits in the codomain with no incoming arrow, so the range is a proper subset of B. The deploy function continues from each object to a status. And the dashed arc shows the composition. auth dot p y goes straight to deployed, without passing through auth dot o explicitly. Computed for every source file, auth and parser reach deployed, and logger reaches failed. That's exactly what a pipeline skipping the intermediate stage computes.
The Identity Function
A Do-Nothing Element
The identity function acts as a do-nothing element under composition. For any f from A to B, and any a, f after the identity on A gives f of the identity of a, which is f of a. So f after the identity is just f. On the output side, the identity on B after f gives the identity of f of a, which is also f of a. This argument doesn't depend on which f, A, or B is chosen. It holds for every function, just by unfolding the two definitions.
Table 2.6.2
Declared Up Front, or Discovered?
This table compares the three sets. The domain and codomain are both fixed as part of stating the function. The range can only be discovered, by checking what the function actually does for every input. Here's something to think about. A student claims that a function's codomain and range are basically the same thing. Using cache dot o, explain why that's false. And why might a system designer declare a codomain larger than any range they expect to see?
About Discrete Mathematics at UPI Study
Discrete Mathematics (Math 230) is a self-paced online course of 87 video lessons in 13 chapters, from logic and proof to counting, probability, graph theory and trees. It carries a NCCRS credit recommendation for 4 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus Every course with PRO →
Why take it here
Why students take Discrete Mathematics with UPI Study
Where the credit goes
Universities that work with NCCRS
Discrete Mathematics carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Functions: Definitions and Terminology
What is a function in discrete math, and how is it a special kind of relation?
What is the difference between the domain, codomain, and range of a function?
How do you tell whether a rule is well-defined?
How do you compose two functions, and what does the identity function do?
About the Discrete Mathematics course
How many college credits is Discrete Mathematics?
How much does Discrete Mathematics cost and what is included?
Which universities accept UPI Study credits?
How long does Discrete Mathematics take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 4 credits in Discrete Mathematics.
87 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
4 credits · NCCRSEnroll →