A function whose domain is all reals, and which maps all rational numbers to 1 and all irrational

numbers to 0.

not much to do except define at described. There are several functions which work with this kind of condition:

Thomae's function, which is 1/q when x=p/q (rational), and 0 when x is irrational

Dirichlet function is just as you describe

To create a function that maps rational numbers to 1 and irrational numbers to 0, you can use the properties of rational and irrational numbers to determine which value to assign to each input.

First, let's recall the definitions of rational and irrational numbers:

- Rational numbers are numbers that can be expressed as a ratio of two integers, where the denominator is not zero. They include integers, fractions, and terminating or repeating decimals.

- Irrational numbers, on the other hand, cannot be expressed as a ratio of two integers. They include numbers such as square roots (e.g., √2, √3), cube roots (e.g., ∛5), and pi (π).

Based on these definitions, we can construct the desired function:

1. Start by defining the function:
f(x) = 1, if x is rational
f(x) = 0, if x is irrational

2. To determine if a number x is rational or irrational, you can apply a logical test. One way to check for rationality is to see if the number can be expressed as a fraction (i.e., whether it can be written as a ratio of two integers).

- If x is an integer, it is a rational number.
- If x is a fraction (e.g., 1/2, 3/4), it is a rational number.
- If x is a terminating decimal (e.g., 0.25, 0.75), it is a rational number.
- If x is a repeating decimal (e.g., 0.333..., 0.121212...), it is a rational number.

3. If x passes any of the above tests, assign the value 1 to f(x) since it is a rational number.

4. If x does not pass any of the tests (i.e., it is not an integer, fraction, or a terminating/repeating decimal), then it is an irrational number. In this case, assign the value 0 to f(x).

By following these steps, you can create a function that maps rational numbers to 1 and irrational numbers to 0 for any real number input.