I want to restrict the outputs of Solve/Reduce/FindInstance, etc. to "simple" rationals, which I define as rationals of the form:
$$\pm \dfrac{a}{b}\; \text{ where } \; a, b \in \{1, 2, 3, 4, 5, 6\},$$
e.g., $ \tfrac{3}{5}$, $5$, $-\tfrac{4}{3}$, etc.
Since MMA associates the sign with the numerator, e.g.:
g = -3/4; Numerator@g Denominator@g -3
4
... I believe restrictions on rationals can be represented as follows:
g = -3/4; h = 5; -6 <= Numerator@g <= 6 && 1 <= Denominator@g <= 6 0 <= Numerator@g <= 6 && 1 <= Denominator@g <= 6 0 <= Numerator@h <= 6 && Denominator@h == 1 -6 <= Numerator@h <= 6 && 2 <= Denominator@h <= 6 True
False
True
False
However, Solve, Reduce, and FindInstance don't recognize this. For example:
exprA = p + ρ + σ == 0 && -p + r + 2 ν - 3 ρ == 0 && -2 p - ν - 2 σ == 1 FindInstance[ exprA && -6 <= Numerator@σ <= 6 && 1 <= Denominator@σ <= 6 && -6 <= Numerator@ν <= 6 && 1 <= Denominator@ν <= 6 && -6 <= Numerator@r <= 6 && 1 <= Denominator@r <= 6 && -6 <= Numerator@p <= 6 && 1 <= Denominator@p <= 6 && -6 <= Numerator@ρ <= 6 && 1 <= Denominator@ρ <= 6, {σ, ν, r, p, ρ}, Rationals, 2] With fewer variables (say, 3 instead of 5), I could instead brute-force the restriction by explicitly reformatting each variable as the ratio of sub-variables, applying value and domain restrictions to each—e.g., replacing the variable $r$ with $\frac{r_1}{r_2}$, where $-6 \leq r_1 \leq 6$, $1 \leq r_2 \leq 6$, $r_1\in \mathbb{Z}$ and $r_2\in \mathbb{Z}$. One can then use Table or Map to recombine the sub-variables in the output into rational solutions for the variables, and delete the duplicates. E.g.:
exprB = -((3 r1)/r2) - ν1/ν2 + σ1/σ2 == 0 && r1/r2 + ν1/ν2 == 0 && -((2 ν1)/ν2) == 1 soln = Solve[ exprB && {σ1, σ2, ν1, ν2, r1, r2} ∈ Integers && And @@ Thread[-6 <= {σ1, σ2, ν1, ν2, r1, r2} <= 6], {σ1, σ2, ν1, ν2, r1, r2}]; tab = DeleteDuplicates@ Table[soln[[j, i, 2]]/soln[[j, i + 1, 2]], {j, 1, Length@soln}, {i, 1, Length@soln[[1]] - 1, 2}]; TableForm[tab, TableHeadings -> {None, {"σ", "ν", "r"}}] However, this method doesn't work with exprA, since its five variables become 10, making the calculation take too long. [I stopped the following after it ran for 24 hours on my 2019 i9 iMac without producing a result.] Thus it would be nice if there were a way to apply the restrictions directly to the original rational-valued variables, rather than transforming them to ratios of integer-valued variables and thus doubling their number:
exprC = exprA /. {σ -> (σ1/σ2), ν -> (ν1/ν2), r -> (r1/r2), p -> (p1/p2), ρ -> (ρ1/ρ2)} soln = Solve[ exprC && And @@ Thread[-6 <= {σ1, σ2, ν1, ν2, r1, r2, p1, p2, ρ1, ρ2} <= 6] && {σ1, σ2, ν1, ν2, r1, r2, p1, p2, ρ1, ρ2} ∈ Integers, {σ1, σ2, ν1, ν2, r1, r2, p1, p2, ρ1, ρ2}] tab = DeleteDuplicates@ Table[soln[[j, i, 2]]/soln[[j, i + 1, 2]], {j, 1, Length@soln}, {i, 1, Length@soln[[1]] - 1, 2}]; TableForm[tab, TableHeadings -> {None, {"σ", "ν", "r", "p", "ρ"}}] 




FindInstance[exprA, {\[Sigma], \[Nu], r, p, \[Rho]}, Rationals, 2]and then pick the solutions you want? $\endgroup$FindInstance[exprA, {\[Sigma], \[Nu], r, p, \[Rho]}, Rationals, 2], you'll see it gives two solutions, neither of which satisfy my constraints: {{[Sigma] -> -(67/29), [Nu] -> 6, r -> -(78/29), p -> -(69/58), [Rho] -> 7/2}, {[Sigma] -> 101/34, [Nu] -> 137/34, r -> -6, p -> -(373/68), [Rho] -> 171/68}} $\endgroup$