0

Well, I am trying to do the following: I have two functions $y(r,a)$ and $z(r,a)$ and I want to check of the division of both those functions leads to an integer. In order to do that I want to choose the value of $r$ run through $0\le a\le n$ and go to $r+1$ and test again $0\le a\le n$. And so on. How can I do that?

I also want to use the Monitor[] function to visually see what the current status is $r$ and $a$. I know that I can do that using Monitor[Parallelize[While[True,If[IntegerQ[...],Print[...]];...++];...],...]. But from that point on I do not know.


Example:

$y(r,a)$:

-34 + Sqrt[3] Sqrt[
  3 (-4 + r)^2 + 45 a^2 (-2 + r) - 2 a (-11 + r) (-2 + r) + 
   4 a^3 (-8 + r)^2] + 3 r

$z(r,a)$

9 (-a + r)

So it has to check when $\frac{y(r,a)}{z(r,a)}$ is an integer. For $3\le r\le10^3$ and $0\le a\le10^4$

Jan Eerland
  • 2,001
  • 10
  • 17

1 Answers1

3

I'm only addressing the question of how to do this calculation fast, not the progress indicator question.

y[r_, a_] = -34+Sqrt[3]Sqrt[3(-4+r)^2+45a^2(-2+r)-2a(-11+r)(-2+r)+4a^3(-8+r)^2]+3r;
z[r_, a_] = 9(-a+r);

Notice that a necessary condition for $y(r,a)/z(r,a)$ to be integer is that the number under the square root in $y(r,a)$ is a perfect square. With this superfast perfect-square detector

sQa = FractionalPart@Sqrt[# + 0``1] == 0 &;

we can find a list of candidate solutions in about one minute:

candidates = Reap[Do[If[sQa[3(3(-4+r)^2+45a^2(-2+r)-2a(-11+r)(-2+r)+4a^3(-8+r)^2)],
                        Sow[{r, a}]], {r, 3, 10^3}, {a, 0, 10^4}]][[2, 1]];

Among these, there is no solution for the full question:

Select[candidates, Divisible[y @@ #, z @@ #] &]
(*    {}    *)

Further speedups:

Roman
  • 47,322
  • 2
  • 55
  • 121