Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Following is the equation:

enter image description here

Need to solve for integer values of x,y when a,b lies between -1000 and 1000. Problem is to find the number of integer values of pair (x,y) that satisfy it.

share|improve this question
1  
Have you tried searching the documentation centre ? –  Sektor Feb 15 at 18:51
    
Assuming a and b are integers then the solutions are (a+1,b+1) or (a-1,b-1) for any a,b. This can be seen by rearranging (x-a)(y-b)=1. The factors must either both be 1 or both be -1. Noting when a=b=1 only (2,2) applies and similarly a=b= -1 the (-2,-2). Mathematica is not required. –  ubpdqn Feb 16 at 10:32

3 Answers 3

up vote 2 down vote accepted

Reduce works in general. First, multiply both sides of the equation by x y to simplify, and then:

Reduce[a b - b x - a y + x y == 1, {x, y, a, b}, Integers]
((C[1] | C[2]) ∈ Integers && x == C[1] && y == C[2] &&  
   a == -1 + C[1] && b == -1 + C[2]) || 
((C[1] | C[2]) ∈ Integers && x == C[1] && y == C[2] && 
   a == 1 + C[1] && b == 1 + C[2])

This answer says, in words, to pick any two integers C[1] and C[2], set them equal to x and y. Corresponding values for a and b are then a=-1+x and b=-1+y. A second solution is given by a=1+x and b=1+y.

Accordingly, there are as many integer answers to this problem as there are integer pairs in the range you wish to consider.

share|improve this answer

For each pair (a,b) you can use Reduce,

a=1;b=10;
Reduce[(a/x - 1) (b/y - 1) == 1/(x y) , {x, y}, Integers]

Then, use ToRules to convert to proper solutions.

However, this is probably quite inefficient and may take some time for all combinations of $a,b$.

share|improve this answer

Problem is to find the number of integer values of pair (x,y) that satisfy it

Here is a way to proceed:

We'll use Tuples to generate the pairs (a, b) of Integers in the range we're interested. I'm just going to do this for the range [-2, 2]

Tuples[Range[-2, 2], 2]

{{-2, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-2, 
  2}, {-1, -2}, {-1, -1}, {-1, 0}, {-1, 1}, {-1, 
  2}, {0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {1, -2}, {1, -1}, {1, 
  0}, {1, 1}, {1, 2}, {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2}}

Now we use FindInstance with the 4th argument (This tells Mathematica how many solutions you want found). Below I've requested a maximum of 3

 sol = FindInstance[(#1/x - 1) (#2/y - 1) == 1/(x y), {x, y}, Integers, 3] &
 @@@ Tuples[Range[-2, 2], 2]

Mathematica graphics

You can then use Length to find how many solutions were found for each pair:

Length /@ sol

{2, 1, 2, 1, 2, 1, 1, 1, 0, 1, 2, 1, 2, 1, 2, 1, 0, 1, 1, 1, 2, 1, 2, 1, 2}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.