# Solving integer equation with an oddness (or related) constraint

Consider this problem:

Find all $$x,y \in \mathbb{N}$$ with $$\{ x,y \} \leq 100$$, $$y$$ is odd, and

$$\frac{1}{x} + \frac{4}{y} = \frac{1}{12} .$$

One can convert the condition on $$y$$ to be $$y = 2 z + 1$$ for $$0 \leq z \leq 49$$ and get the answer indirectly:

Solve[{0 <= x <= 100, 0 <= z <= 49,
1/x + 4/(2 z + 1) == 1/12},{x,z},
Integers]


{{x -> 76, z -> 28}}

and then convert $$z$$ back to find $$y$$. (There is a unique solution given the constraint.)

My question, though, is how to solve the equation directly with that oddness constraint. The obvious approach:

Solve[{0<x<=100, 0<=y<=100, OddQ[y],
1/x + 4/y == 1/12},{x,y},
Integers]


and straightforward variations do not work.

The closest I could get was

Assuming[OddQ[y],
Solve[{0<x<=100, 0<=y<=100,
1/x + 4/y == 1/12},{x,y},
Integers
]]


which gives many answers plus a warning that some of the solutions do not obey the assumption. (Indeed, all but one of the solutions so violate the assumption.)

I hope there is a direct method, not one which relies on numerous intermediate solutions, of which I computationally select the one(s) that satisfy the constraint.

This works, but is not quite what I seek:

Solve[{0<x<=100, 0<=y<=100,Mod[y,2]==1,
1/x + 4/y == 1/12},{x,y},
Integers
]


My full question involves several such constraints, e.g., some variables are even, some variables are odd...

• FindInstance[ 1/x + 4/y == 1/12 && Mod[y, 2] == 1 && x <= 100 && y <= 100, {x, y}, PositiveIntegers, 10^10] You can't use OddQ and must use Mod because 'Q' style functions don't work with symbolic arguments like that e.g OddQ[y] is False if y is a symbol with no value. Jul 13, 2021 at 21:06
• In your Assuming[OddQ[y],... above, for the reasons I stated, this is first changed to Assuming[False,... which would explain the warnings. Jul 13, 2021 at 21:08
• @GeorgeVarnavides: Thanks. The constraints I will impose in my true problem are generated elsewhere and come in long lists of OddQ, EvenQ, PositiveQ, and conjunctions and disjunctions thereof. I suppose I could try to express all these in standard equation form, but I was hoping to avoid that. Jul 13, 2021 at 21:09
• @flinty: Thanks, but FindInstance isn't quite right because my full (large) equation may have multiple solutions (obeying the constraints). Your explanation about how OddQ won't work with symbolic arguments is a big help... thanks for that insight. Jul 13, 2021 at 21:11
• FindInstance returns multiple solutions so I don't see why that's a problem (see the last argument). You cannot use 'Q' functions. Another way to express without using Mod is FractionalPart[y/2] > 0 but that's just more long winded. Jul 13, 2021 at 21:12

Here is one way. Admittedly, would like to understand better why this works, and surely there must be a more elegent way.

p = Solve[{0 < x <= 100, 0 <= y <= 100, 1/x + 4/y == 1/12}, {x, y}, Integers];
q = OddQ[y /. p];
p[[Flatten[Position[q, True]]]]

• Weird and inelegant... but helpful ($+1$). It would be truly ugly in my full problem where my constraints are of the form OddQ[y] OR (EvenQ[x] AND NonNegative[y])... Jul 13, 2021 at 21:34
• This is just filtering out the odd $y$ solutions. You could do both those lines in a single Select[p, OddQ[y /. #] &] Jul 13, 2021 at 21:35