Math formula to check two integers

967 Views Asked by At

I was just wondering if there is a way to check that two unknowns are integers as follows:-
if x and y are two values, and I want to know if these two values are integers by using a formula,
I tried adding them and checking if the sum is an integer but I found out that two numbers can be decimal and give integer result (ex. 1.5 + 2.5 = 4), I also tried multiplying them and checking if the product is integer but I found out that two decimals can have an integer product (ex. 1.2 x 2.5 = 3). It's all about checking if x and y both belong to integers and not solving a specific equation.

Summary: "if formula (including x and y) gives a specific result then x and y are integers"
what is the formula ?

NOTE : I want a way that helps in solving equations, so avoid answers like $f(x) = 1 \ \ \ \ \ \ ( x \in \Bbb Z)$. In addition, I don't want to check x and y separately but both at the same time.

4

There are 4 best solutions below

10
On BEST ANSWER

There are a lot of functions that meet your criteria.

First, there is this function. It is boring, as it defeats the point of the question, but it is worth noting that it is a mathematically valid function:

1) $f(x, y) = \cases{1 & if $x$ and $y$ are integers \\ 0 & otherwise}$

Similarly, there's

2) $f(x, y) = \{x\} + \{y\}$ where $\{x\}$ denotes the fractional part of $x$. It is 0 iff both are integers.

So it would be a good idea to set some additional restrictions on our functions to have a meaningful question.

A typical restriction could be to ask for functions that are continuous and differentiable (smooth), as most functions and operation we use (addition, subtraction, multiplication, trig, etc.) have this property. Here is a continuous and differentiable (smooth) function that works:

3) $f(x, y) = \sin^2(\pi x) + \sin^2(\pi y)$

This is 0 iff both $x$ and $y$ are integers.

Let's consider continuous and differentiable functions with a bit more generality. Suppose $f(m, n) = k$ for some integers $m$ and $n$. Consider a contour plot line at height $k$. We can then then move slightly along the line, and make $m$ and/or $n$ not integer while preserving the value $k$... Unless $(m, n)$ is a maximum or a minimum, and so the contour line is actually just a point. This means, we need functions that have maxima or minima at every integer point.

This means, there aren't any such functions that can be expressed in terms of only elementary operations (addition, subtraction, multiplication, division, roots).

1
On

Yes, you have two equations $$\begin{align}x+y&=n\\xy&=m\end{align}$$ where $n$ and $m$ are known. From the first, $y=n-x$ Substitute this into the second, and use the quadratic formula to check if the solutions are integers.

EDIT The substitution gives $$x^2-nx+m=0$$ By the quadratic formula, $$x={n\pm\sqrt{n^2-4m}\over2}$$ So now you can check if this is an integer. You need $n^2-4m$ to be a perfect square, and the fraction to work out to a whole number. If $x$ is an integer, so is $y,$ since $n$ and $m$ have to be integers. (If $m$ and $m$ aren't integers, there's no possibility of integral solution.)

I overlooked the line beginning "So is there any exact way ..." before, and I'm afraid I don't understand what you mean.

2
On

Given a real value $t$, there is a well-known and widely used formula $\{t\}$, denoting the fractional part of $t$. Remark that $0\le \{t\}\le 1$ for each real $t$ and $t$ is integer if and only if $\{t\}=0$. Therefore, given real number $x$ and $y$ a formula

$$\{x\}+\{y\}$$

equals to zero if and only if both $x$ and $y$ are integers.

1
On

The problem of any real number $x$ being an integer can be approached by using three functions.

1.) {$x$}, the fractional part of $x$
2.) $\lfloor x \rfloor$, the floor function of $x$ which returns the greatest integer less than or equal to $x$

3.) $\lceil x \rceil$, the ceiling function of $x$ which returns the least integer greater than or equal to $x$

As already explained by @Alex Ravsky about the fractional part, you can get to know individually whether $x$ and $y$ are separately integers or not.

$$Input(x) \rightarrow \boxed{\left\{x\right\}} \rightarrow Output(y)$$ Here if $y$ = $0$, then the input is certainly an integer.

$Floor function$: $$Input(x) \rightarrow \boxed{\lfloor x \rfloor} \rightarrow Output(y)$$ Here the output $y$ is the greatest integer which is less than or equal to $x$ For e.x. if the input is $1.33$ he output will be the greatest integer which is less or equal $1.33$. Now the integers $-2, -1,0,1$ all are less than $1.33$ but the floor function will return $1$ since it is the greatest integer less or equal $1.33$.

$$Test: \lfloor x \rfloor =x;$$ (Output of the function - Input to the function = $0$) $$\space then\space x\space is\space an\space integer$$

Using programming you can run a loop which checks for all integers one by one and returns the (greatest)integer less or equal $x$.

$Ceiling Function:$ $$Input(x) \rightarrow \boxed{\lceil x \rceil} \rightarrow Output(y)$$ Here the output $y$ will be the smallest integer greater than or equal to $x$. Lets say the input is $3.5$ then there are many integers greater than or equal to $3.5$. But we will choose the least integer which is $4$.

$$Test: \lceil x \rceil =x;$$ (Output of the function - Input to the function = $0$) $$\space then\space x\space is\space an\space integer$$ Using programming you can run a loop which checks for all integers one by one and returns the (least)integer greater or equal $x$.

The concept of any real number being an integer is simple. Any real number can be expressed in a decimal representation(recurring or non recurring). So we just need to truncate the fractional part of the real number to get the integer. These three functions help to truncate the fractional part so that we are left with an integer.

Finally each of these things can be checked using programming. Now every real decimal number is stored as a data type float. If you try to change your type to integer the decimal part is truncated.

int x =3.5;

will actually store only $3$ in the variable $x$. So you can also return an integer from a decimal value. In C programming storing a real value in integer type or just typecasting the real number to integer type will return you an integer.

Combining all this : Checking $x$ and $y$ individually through both the floor and ceiling functions will tell you whether both of them are integers or not. No requirement to check whether the sum is an integer or the product is an integer or not.

Hope this helps.....