There is a curious example in Posamentier's book "Magnificent Mistakes in Mathematics" (p. 72): $$(7+3/7)*(4-3/13)= 7*4=28$$, where cancelling the fractions leads to correct result. If we generalize $$(a+b/c)*(x-y/z)=a*x$$, for which (integer) six-tuples does this "calculation" hold (in the range, for example, from 1 to 10 for each number)?

I can not imagine a brute force method, and I tried with pencil and paper with no success. Can you help me please to resolve this question from recreational mathematics.

• See Project Euler Problem 33 for an exercise in more curious fraction cancellations. Jan 21 '21 at 0:00

To just find examples use FindInstance

examples = FindInstance[{
(a + b/c) (x - y/z) == a x,
1 <= a <= 10, 1 <= b < c, 1 <= c <= 10, 1 <= x <= 10, 1 <= y < z,
1 <= z <= 10},
{a, b, c, x, y, z}, Integers, 5];

HoldForm[(a + b/c) (x - y/z) == a x] /. examples Verifying,

% // ReleaseHold

(* {True, True, True, True, True} *)

To find all solutions

sol = Solve[{
(a + b/c) (x - y/z) == a x,
1 <= a <= 10, 1 <= b <= 10, 1 <= c <= 10, 1 <= x <= 10, 1 <= y <= 10,
1 <= z <= 10,
b < c, y < z},
{a, b, c, x, y, z}, Integers];

The total number of solutions is

Length@sol

(* 1293 *)

Verifying,

And @@ ((a + b/c) (x - y/z) == a x /. sol)

(* True *)

You may creat a loop over the variables a,b,..z from 1 to 10 and check if the condition is fulfilled. If yes you keep the current values. Otherwise you discard them:

res = Reap[
Do[
If[(a + b/c) (x - y/z) == a  x, Sow@{a, b, c, x, y, z}]
, {a, 1, 10}, {b, 1, 10}, {c, 1, 10}, {x, 1, 10}, {y, 1, 10}, {z, 1, 10}]
][[2,1]]

There are 8856 possible six-tuples.

• For b/c and y/z to be proper fractions requires that c > b and z > y. This assumption would reduce the number of solutions to 1293. Jan 20 '21 at 21:10
• Hello Bob and Daniel, thanks for answer (it was night between in Europe :) ). I just like such problems, but my knowledge of Mathematica stopped around version 3.0 :(, so expect more questions, regards and respect to you - experts! Jan 21 '21 at 8:56

We want $$\left(a+\frac{b}{c}\right)\left(x-\frac{y}{z}\right)=a x$$ which means $$b y+a c y-b x z=0$$ which we can solve for $$x$$ as $$x=\frac{b y+ a c y}{b z}$$

The task now becomes finding set of five-tuples $$(a,b,c,y,z)$$ such that $$\frac{b y+ a c y}{b z}$$ is an integer number and we have the constraints $$b\le c-1$$ and $$y\le z-1$$ as any integer part of the fractions $$b/c$$ and $$y/z$$ can be absorbed into $$a$$ and $$x$$.

For $$a,b,c,y,z=1,\dots,20$$ we do have 32961 proper solutions, which my 2015 Macbook with 2 cores finds in 2.3 seconds. The code is

results = With[{k = 20},
Select[IntegerQ[#[]] &]@
Flatten[Table[{a, b, c, (b y + a c y)/(b z), y, z}, {a, k}, {c,
k}, {b, c - 1}, {z, k}, {y, z - 1}], 4]
]; // RepeatedTiming
(* {2.3, Null} *)

As examples:

HoldForm[(a + b/c) (x - y/z)] /. Table[
Thread[{a, b, c, x, y, z} -> results[[i]]], {i, {456, 4956, 32961}}
]
(* {(1+1/11) (6-4/8),(4+2/6) (12-12/13),(20+18/20) (22-18/19)} *)

where the results are integers as designed:

% // ReleaseHold
(* {6, 48, 440} *)

One can technically increase the efficiency by noting that the pairs $$(b,c)$$ and $$(y,z)$$ are defined only upto an overall scaling, i.e. $$(x,y)\sim (\lambda x,\lambda y)$$ for integer $$\lambda$$. Hence we can restrict the search for integers $$(b,c)$$ which are coprime, and similarly for $$(y,z)$$. In other words, we can first generate all coprimes within a certain range and then use them instead. For the integers in the range $$1\cdots 30$$, we run

results = With[{k = 30},
With[{
pairs =
Select[CoprimeQ @@ # &]@
Flatten[Table[{j, i}, {i, k}, {j, i - 1}], 1]
},
Select[IntegerQ[#[]] &]@Flatten[Table[
With[{b = p1[], c = p1[], y = p2[], z = p2[]},
{a, b, c, (b y + a c y)/(b z), y, z}
], {a, k}, {p1, pairs}, {p2, pairs}], 2]
]]; // RepeatedTiming
(* {35., Null} *)

results // Length
(* 34406 *)

As an example, we see that

HoldForm[(a + b/c) (x - y/z)] /. Thread[{a, b, c, x, y, z} -> results[[-1]]]
(* (30+1/30) (848-16/17) *)

which is

% // ReleaseHold
(* 25440 *)

One can also generate examples of larger numbers using FindInstance command, as suggested by others. In terms of our equations, it reads as

FindInstance[b y + a c y - b x z == 0 && c > b && z > y
&& a > 10000, {a, b, c, x, y, z}, PositiveIntegers, 3]
(* {{a -> 10247, b -> 1, c -> 42, x -> 11, y -> 1, z -> 39125}, {a -> 10247, b -> 1, c -> 42, x -> 11, y -> 71, z -> 2777875}, {a -> 11414, b -> 1, c -> 23, x -> 2, y -> 44, z -> 5775506}} *)

which gives

HoldForm[(a + b/c) (x - y/z)] /. %
(* {(10247+1/42) (11-1/39125),(10247+1/42) (11-71/2777875),(11414+1/23) (2-44/5775506)} *)

For example, $$\left(11414+\frac{1}{23}\right)\left(2-\frac{44}{5775506}\right)=11414\times 2$$