Does a function exist that will take arguments of $0,1,2,3$ and map to only values $0$ and $1$.

63 Views Asked by At

To be clear:

$0\rightarrow0$,

$1\rightarrow1$,

$2\rightarrow1$,

$3\rightarrow1$

I know how to achieve it programmatically, as it is quite simple, but is there a purely mathematical way?

I have been pondering this for a few days, my basic understanding of set theory says it should be possible but I can't seem to figure out how to do it.

edit

Thanks to fleablood for the simple and easy to understand solution.

I was trying to create a way (for my own curiosity) to find whether a year is a leap year without using if statements. It was an assignment but I was supposed to use IF statements for it. I just wondered if it can be done any other way. I'm sure I will make use of Fermat's little theorem in future.

in python return (year % 4) ** 4) % 5 - ((year % 100) ** 100) % 101 + ((year % 400) ** 400) % 401

3

There are 3 best solutions below

6
On

Um; yes. the function:

$f(x) =\begin{cases} 0 & \text{if }x = 0 \\ 1 & \text{if } x\ne 0\end{cases}$

=====

$f(x) = x^4 \% 5$ where $\%$ is the remainder function will do it (it's Fermat's little theorem). But you don't need it.

If you can say $f$ maps $0$ to $0$ and $1,2,3$ to $1$, then that IS a function. You don't need to do anything else.

"In mathematics, a function is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output."

So the sentence: $f$ maps $0$ to $0$ and $1,2,3$ to $1$ satisfies EVERYTHING you need to define a function.

Having some mathematical formula is NOT a requirement.

3
On

$f(x)=\big\arrowvert\mu(x+4)\big\arrowvert$ seems to work

1
On

There are many ways depending on what you allow yourself to use. One easy way is to use the polynomial function $f(x) := 1 + (x-1)(x-2)(x-3)/6.$