Skip to main content
Improve formatting
Source Link
Domen
  • 41.5k
  • 3
  • 58
  • 84

Way to assign Assigning restrictions to rational solutions from Solve/Reduce/FindInstance?

I want to restrict the outputs of Solve/Reduce/FindInstanceSolve/Reduce/FindInstance, etc. to "simple" rationals, which I define as rationals of the form:

$\pm \dfrac{a}{b}$, where a, b = {1, 2, 3, 4, 5, 6}$$\pm \dfrac{a}{b}\; \text{ where } \; a, b \in \{1, 2, 3, 4, 5, 6\},$$

e.g., $ \dfrac{3}{5}$$ \tfrac{3}{5}$, $5$, $- \dfrac{4}{3}$$-\tfrac{4}{3}$, etc.

...I I believe restrictions on rationals can be represented as follows:

However, SolveSolve, ReduceReduce, and FindInstanceFindInstance don't recognize this.

  For example:

exprA = p + \[Rho]ρ + \[Sigma]σ == 0 && -p + r + 2 \[Nu]ν - 3 \[Rho]ρ == 0 && -2 p - \[Nu]ν - 2 \[Sigma]σ == 1 
FindInstance[  exprA && -6 <= Numerator@\[Sigma]Numerator@σ <= 6 && 1 <= Denominator@\[Sigma]Denominator@σ <= 6  && -6 <= Numerator@\[Nu]Numerator@ν <= 6 && 1 <= Denominator@\[Nu]Denominator@ν <= 6  && -6 <= Numerator@r <= 6 && 1 <= Denominator@r <= 6  && -6 <= Numerator@p <= 6 && 1 <= Denominator@p <= 6  && -6 <= Numerator@\[Rho]Numerator@ρ <= 6 && 1 <= Denominator@\[Rho]Denominator@ρ <= 6,  {\[Sigma]σ, \[Nu]ν, r, p, \[Rho]ρ}, 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{r1}{r2}$$\frac{r_1}{r_2}$, where $-6 <= r1 <= 6$$-6 \leq r_1 \leq 6$, $1 <= r2<= 6$$1 \leq r_2 \leq 6$, $r1\in \mathbb{Z}$$r_1\in \mathbb{Z}$ and $r2\in \mathbb{Z}$$r_2\in \mathbb{Z}$. One can then use TableTable or MapMap to recombine the sub-variables in the output into rational solutions for the variables, and delete the duplicates. E.g.:

exprB = -((3 r1)/r2) - \[Nu]1ν1/\[Nu]2ν2 + \[Sigma]1σ1/\[Sigma]2σ2 == 0 && r1/r2 + \[Nu]1ν1/\[Nu]2ν2 == 0 && -((2 \[Nu]1ν1)/\[Nu]2ν2) == 1 
soln = Solve[ exprB && {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν2, r1, r2} \[Element]   Integers && And @@ Thread[-6 <= {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν2, r1, r2} <= 6], {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν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, {"\[Sigma]""σ", "\[Nu]""ν", "r"}}] 

However, this method doesn't work with exprAexprA, 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 /.  {\[Sigma]σ -> (\[Sigma]1σ1/\[Sigma]2σ2), \[Nu]ν -> (\[Nu]1ν1/\[Nu]2ν2), r -> (r1/r2), p -> (p1/p2), \[Rho]ρ -> (\[Rho]1ρ1/\[Rho]2ρ2)} 
soln = Solve[ exprC && And @@ Thread[-6 <= {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν2, r1, r2, p1, p2, \[Rho]1ρ1, \[Rho]2ρ2} <= 6] && {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν2, r1, r2, p1, p2, \[Rho]1ρ1, \[Rho]2ρ2} \[Element] Integers, {\[Sigma]1σ1, \[Sigma]2σ2, \[Nu]1ν1, \[Nu]2ν2, r1, r2, p1, p2, \[Rho]1ρ1, \[Rho]2ρ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, {"\[Sigma]""σ", "\[Nu]""ν", "r", "p", "\[Rho]""ρ"}}] 

Way to assign restrictions to rational solutions from Solve/Reduce/FindInstance?

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}$, where a, b = {1, 2, 3, 4, 5, 6}

e.g., $ \dfrac{3}{5}$, $5$, $- \dfrac{4}{3}$, etc

...I believe restrictions on rationals can be represented as follows:

However, Solve, Reduce, and FindInstance don't recognize this.

  For example:

exprA = p + \[Rho] + \[Sigma] == 0 && -p + r + 2 \[Nu] - 3 \[Rho] == 0 && -2 p - \[Nu] - 2 \[Sigma] == 1 
FindInstance[ exprA && -6 <= Numerator@\[Sigma] <= 6 && 1 <= Denominator@\[Sigma] <= 6 && -6 <= Numerator@\[Nu] <= 6 && 1 <= Denominator@\[Nu] <= 6 && -6 <= Numerator@r <= 6 && 1 <= Denominator@r <= 6 && -6 <= Numerator@p <= 6 && 1 <= Denominator@p <= 6 && -6 <= Numerator@\[Rho] <= 6 && 1 <= Denominator@\[Rho] <= 6, {\[Sigma], \[Nu], r, p, \[Rho]}, 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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) - \[Nu]1/\[Nu]2 + \[Sigma]1/\[Sigma]2 == 0 && r1/r2 + \[Nu]1/\[Nu]2 == 0 && -((2 \[Nu]1)/\[Nu]2) == 1 
soln = Solve[ exprB && {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]2, r1, r2} \[Element]   Integers && And @@ Thread[-6 <= {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]2, r1, r2} <= 6], {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]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, {"\[Sigma]", "\[Nu]", "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/.  {\[Sigma] -> (\[Sigma]1/\[Sigma]2), \[Nu] -> (\[Nu]1/\[Nu]2), r -> (r1/r2), p -> (p1/p2), \[Rho] -> (\[Rho]1/\[Rho]2)} 
soln = Solve[ exprC && And @@ Thread[-6 <= {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]2, r1, r2, p1, p2, \[Rho]1, \[Rho]2} <= 6] && {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]2, r1, r2, p1, p2, \[Rho]1, \[Rho]2} \[Element] Integers, {\[Sigma]1, \[Sigma]2, \[Nu]1, \[Nu]2, r1, r2, p1, p2, \[Rho]1, \[Rho]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, {"\[Sigma]", "\[Nu]", "r", "p", "\[Rho]"}}] 

Assigning restrictions to rational solutions from Solve/Reduce/FindInstance

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.

... I believe restrictions on rationals can be represented as follows:

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", "ρ"}}] 
added 239 characters in body
Source Link
theorist
  • 3.7k
  • 1
  • 16
  • 31

With fewer variables (say, 3 instead of 5), I cancould 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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.:

However, this method doesn't work with exprA, since its five variables become 10, making the calculation take too long (I. [I stopped thisthe following after running 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:

With fewer variables (say, 3 instead of 5), I can 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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.:

However, this method doesn't work with exprA, since its five variables become 10, making the calculation take too long (I stopped this after running it for 24 hours on my 2019 i9 iMac):

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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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.:

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:

deleted 2 characters in body
Source Link
theorist
  • 3.7k
  • 1
  • 16
  • 31

Suppose I want to restrict the outputs of Solve/Reduce/FindInstance, etc. to "simple" rationals, which I define as rationals of the form:

With fewer variables (say, you3 instead of 5), I can brute-force itthe 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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 deletingdelete the duplicates. E.g.:

Suppose I want to restrict the outputs of Solve/Reduce/FindInstance, etc. to "simple" rationals, which I define as rationals of the form:

With fewer variables, you can brute-force it 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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 deleting the duplicates. E.g.:

I want to restrict the outputs of Solve/Reduce/FindInstance, etc. to "simple" rationals, which I define as rationals of the form:

With fewer variables (say, 3 instead of 5), I can 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{r1}{r2}$, where $-6 <= r1 <= 6$, $1 <= r2<= 6$, $r1\in \mathbb{Z}$ and $r2\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.:

Source Link
theorist
  • 3.7k
  • 1
  • 16
  • 31
Loading