4

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.

  • Do you mean, like adecima$l^{another decimal}$? – Math Lover Jan 27 '19 at 15:07
  • I mean, you can always use logarithm and roots to find them, if you want :) – Math Lover Jan 27 '19 at 15:11
  • 1
    The wording of your question makes it very hard to understand, and the title is inexpressive. You can "check" the two numbers independently. –  Jan 27 '19 at 15:51
  • 1
    If $x=int(x)$ and $y=int(y)$ – J. W. Tanner Jan 27 '19 at 16:32
  • 1
    Are $x$ and $y$ still supposed to be unknown at the time of checking? If so, the answer will depend on what information you have about $x$ and $y$. – timtfj Jan 27 '19 at 16:34
  • Please see: https://math.stackexchange.com/questions/339510/mathematical-way-of-determining-whether-a-number-is-an-integer – Peter Chikov Feb 01 '19 at 17:47
  • @peter Chikov, thank you for sharing this link but I've already saw this and I'm not looking for a way such that the computer can check them I want a way to use in solving mathematical equations, that's what I've mentioned in my comments down below. – Anas Khaled Feb 02 '19 at 14:05

4 Answers4

3

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.

saulspatz
  • 53,131
  • 2
    Sorry, I didn't understand well. Did you mean checking that xy = x(x-n) = x^2-nx = m ? I think it is still the same. – Anas Khaled Jan 27 '19 at 15:39
3

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).

Todor Markov
  • 2,869
  • Thank you very much, but there is a problem, such functions doesn't help in solving equations the only one I thought it could help was no. 3 but unfortunately, it seems not working as I tried x=2 and y=3 : $ \sin^2 (2 \pi) + \sin^2 (3 \pi) \approx 0.3879 $. I know it's a very small value but it can make big difference in long equations. – Anas Khaled Feb 02 '19 at 13:59
  • @anaspcpro You must have miscalculated something. $\sin^2(2\pi) + \sin^2(3\pi)=0$: https://www.wolframalpha.com/input/?i=sin%5E2(2pi)+%2B+sin%5E2(3pi) – Todor Markov Feb 02 '19 at 14:34
  • I tried that many times trying different numbers on a CASIO fx-570ES Plus calculator and also on windows 7 calculator,however google calculator said it's equal to zero and Wolfarmalpha doesn't work for me, it gives blank result . – Anas Khaled Feb 02 '19 at 14:57
  • @anaspcpro Perhaps those calculators interpret the order of operations or something differently. Make sure it's $[\sin(\pi x)]^2 + [\sin(\pi y)]^2$. Since $\sin(n\pi) = 0$ for all integers $n$, so when you square it it will still be zero, and then you add up two zeros. – Todor Markov Feb 02 '19 at 15:25
  • I've mentioned above that I tried that many times on different calculators and I also tried to arrange the order of the operation $2 \pi$ then, $\sin^2 Ans$ and I always get 0.01197768421. I'd be grateful if you added a reference for what you said. I'd be so pleasant if that was right. – Anas Khaled Feb 02 '19 at 15:31
  • @anaspcpro Also, make sure your calculator is in radians. Or if it's in degrees, change the $\pi$ to 180. Here's a reference, the first two rows in particular: https://en.wikipedia.org/wiki/Sine#Special_values. – Todor Markov Feb 02 '19 at 15:38
  • You meant in radians !!!!, that changes everything and with having that reference, I'd like to say thank you !!! – Anas Khaled Feb 02 '19 at 16:06
  • After a day of thinking, I found out that it doesn't have to be $\sin^2$ it works with only $\sin$ and also it can be $\tan$. – Anas Khaled Feb 03 '19 at 16:53
  • 1
    @anaspcpro With just sin it will be 0 at all integers, but can be zero for non-integers too. For example $\sin(0.5\pi) + \sin(1.5\pi)$ is also 0 (because one part is positive the other negative). Squaring prevents that. – Todor Markov Feb 03 '19 at 17:07
  • Thank you so much you're a lifesaver !!! – Anas Khaled Feb 03 '19 at 17:48
1

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.

Alex Ravsky
  • 90,434
1

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.....

  • Thank you very much for all of this information, but I don't want to check them SEPARATELY, I want to check them both at the same time. – Anas Khaled Feb 02 '19 at 13:42