As the title says. I'm actually writing a program and a part of it has to do these mappings. I just wish to do something like 2 functions f(x) and g(x), where the first maps $[0, \infty[ $ to $[- \infty, \infty]$ and g(x) does the opposite, preferably in an uncomplicated way. It does not have to be continuous.
- 31
- 4
-
2There is a map from any set to any other set. :-) – Kavi Rama Murthy Jan 12 '21 at 11:54
-
A bijective function $g$ from $\Bbb R$ to $[0, \infty)$ has infinitely many discontinuities, compare https://math.stackexchange.com/q/8149. – Martin R Jan 12 '21 at 12:13
-
@Kavi Rama Murthy: $[\cdots]$ to any other set --- except when the first set is empty and the second set is not empty? (I'm not sure whether the empty function qualifies as a map from the empty set to a nonempty set -- I'd need to look at a standard set theory text for precise definitions for something like this.) – Dave L. Renfro Jan 12 '21 at 12:23
-
@DaveL.Renfro I think that one does qualify, but there are no maps from non-empty sets to the empty set. – user3482749 Jan 12 '21 at 13:10
-
So what is it in this case @KaviRamaMurthy ? – topkek Jan 12 '21 at 15:17
-
Why is my question downvoted? – topkek Jan 12 '21 at 18:01
-
Do you know the Mathematical definition of a function from one set to another? This questioin is simply absurd in the present form so I have downvoted it. – Kavi Rama Murthy Jan 13 '21 at 06:18
-
Instead of correcting it? Or explaining what's wrong? That's not really nice of you... – topkek Jan 13 '21 at 07:24
-
1Or explaining what's wrong? --- Kavi's first comment does this. Your question is like asking if a living person has a head. Possibly you meant "onto $[- \infty, \infty]$" instead of "to $[- \infty, \infty]$" (i.e. you want every element in the target set to "be used"). (BTW, I didn't downvote.) – Dave L. Renfro Jan 13 '21 at 08:11
-
Well, YOUR comment makes things clear and now I know how I should edit my question. Kavi's doesn't help a bit in this regard. – topkek Jan 13 '21 at 10:10
4 Answers
Take $$f(x) = \begin{cases} \ln(x) & \text{if } x \in (0,+\infty)\\ 0 & x = 0 \end{cases}.$$
- 3,978
-
-
-
From where comes your definition of map ? A map is not just a synonym of function ? – Falcon Jan 12 '21 at 12:05
-
-
Ok, but the question strongly suggest this should be the case, you need to anticipate OP desires :-) – zwim Jan 12 '21 at 12:21
-
There should be plenty of ways, but here's mine: Given a number $x$ write this value as $n + q$ where $n$ is the integer part. Then define $ f(n+q) = -n -2q$ for $q \in (0,0.5]$ and f(n + q) = n + 2q for $n\in (0.5,1]$. Just make sure that if say you had $f(6)$ this needs to be written as $f(5 + 1)$. It's quite easy from this to work out your other function $g$, and also the inverses of these functions.
- 1
I propose $f(x)=\begin{cases}\frac x{x-1}&x\in[0,\infty)\setminus\{1\}\\1& x=1\end{cases}$ for $f:[0,+\infty)\to\mathbb R$
Unfortunately for the other direction, this is not as simple as Martin R's comment pointed out.
We have to proceed in two steps $\mathbb R\overset{g_1}{\mapsto}(0,+\infty)\overset{g_2}{\mapsto}[0,+\infty)$
For instance $g_1(x)=e^x$ and $g_2(x)=\begin{cases}x-1&x\in\mathbb N\\x& \text{otherwise}\end{cases}$
Note: we do not have $f^{-1}=g_2\circ g_1$, but if you need a proper reciprocal, you can proceed the same way with $f_1(x)=\ln(x)$, can you see what $f_2$ should be in this case.
- 28,563
Speaking of digital programming, there is a maximum and minimum in any signed or unsigned data type. Some data types support the representation of infinity, but not all of them. It is practical to think of a linear mapping such as $f:[0,M) \rightarrow (m,M)$ defined by $$f(x) = \frac{M - m}{M}x + m$$ where $m$ and $M$ is the smallest and the largest number the data type can represent. It has good properties to handle; linear, continuous, and bijective. Furthermore, it is efficient in the sense of computational overhead.
- 2,597
-
There is something not quite right. Take
-5and 8 bits as maximum storage as example:f(-5)=((128--127)/128)*(-5)+(-127) = -137. – topkek Jan 12 '21 at 15:29 -
@topkek For integer type data, you should not write that equation directly. I suggest
(int8_t)((M - m)*x/M + m). Meanwhile, your example is not a counterexample because -5 is not an element in the domain. Note that standard integer ranges from -128 to 127. – Hermis14 Jan 12 '21 at 16:53 -