Example A coffee house menu (Fig. 1.11)
Exercise 1.2.1 Come up with two more everyday examples of functions. Briefly explain what makes each example a function.
Some examples given by you
gas: money --> amount of gas (at a pump) student ID: students ---> student IDs password: lognames ----> passwords
Some more examples:
father: people --> people mother: people --> people
Note that in general
a movie will have several showtimes a day. So, movie ---> showtime is in general not a function.
Exercise 1.2.2 Modify the menu in Figure 1.11 so it no longer depicts a function.
Ans to Exercise 1.2.2 For example, A beverage may have different prices for staff and non-staff or have different prices for a certain days of the week.
Functions with a finite set of inputs can be defined by tables.
Example Figure 1.14 Margarine consumption per person in the US (lbs) vs number of lawyers in New Jersey.
(Not necessary have any casual relationship)
It’s important to note that functions are not causal; there is no reason to think there is a causal relationship between the input and output of a function.
The lawyers–margarine graph is an example of a function without a causal relationship.
Some functions can be described by formulas (c.f. computer programs)
The output that corresponds to a particular input to a function is written as
$$ \text{FunctionName(input) = output} $$A common name for functions is $f$ , so we might write $f (X) = Y$.
For example, $f(3) =5$ and $f(4) = 6$ is the function given by the table
x | y |
---|---|
3 | 5 |
4 | 6 |
Exercise 1.2.3 Write the function $g$ given by $g(3)=2$, $g(4)=3$ using a table.
Exercise 1.2.4 Write the functions $f$ and $g$ in function notation using formulas.
Note that
not every equation relating $X$ and $Y$ defines $Y$ as a function of $X$ or vice versa. E.g. $X^2 = Y^2$.
Some functions can be computed by simple algorithms (formulas) but most functions the we encountered in this course do not have any simple formulas.
Exercise 1.2.5 Give three possible domains for a function defined by the formula
$$g(X) = \dfrac{2}{X-5}$$Exercise 1.2.6 Describe the everyday function examples you came up with in Exercise 1.2.1 on page 9 in
"function name : domain → codomain”
notation.
Transcribing DNA to RNA
transcription : $\{$A, C, G, T$\}$ $\to$ $\{$A,C,G,U$\}$
X $\mapsto$ X where X is either A, C or G and T $\mapsto$ U.
This extends to a function (still called transcription) from DNA codons (base triples) to RNA codons.
transcription : DNA codons $\to$ RNA codons
e.g. ATC $\mapsto$ AUC
There is another function translating RNA codons to amino acids.
translation: RNA codons $\to$ amino acids
e.g. translation(AUC) = isoleucine
So their composition is a function (called gene expression) from DNA codons to amino acids.
gene expression : DNA codons $\to$ amino acids
so ge(ATC) = isoleucine
How many RNA codons are there?
Also, check this table out.
A more algebra-oriented example.
If $f(X) = 2X+1$ and $g(Y)= \sqrt{Y}$, then
$g \circ f(X) = g(f(X)) = \sqrt{2X+1}$
$f \circ g(Y) = f(g(Y)) = 2\sqrt{Y}+1$
Exercise 1.2.7 Suppose life is discovered on Mars. The Martians’ genetic code is remarkably similar to ours, but the RNA codon AUC is translated to serine 60% of the time and histidine 40% of the time. Is Martian gene expression a function?
Exercise 1.2.8 As we saw earlier, a coffee shop menu is a function. Suppose that when you buy a drink, you have to pay 10% sales tax in addition to the price of the drink, so the total cost (price and tax) of a drink is 1.1 times the price on the menu.
a) Refer to Figure 1.11 on page 9. What is the total cost of a mocha? A latte?
b) Describe the process of finding the total cost in terms of function composition.
Question 8
import sympy
from sympy import *
x = Symbol('x')
simplify(sqrt(x**2))
x = Symbol('x', positive=True, real=True)
simplify(sqrt(x**2))