0

I am sure that this is not the most elegant code you will have seen, but I am trying to loop through an expression to see if FultonHarrisn] produces any outputs that are equal to a prime squared.

My function FultonHarris is defined as follows:

FultonHarris[n_] := Product[(Sum[a[k], {k, i, j - 1}] + j - i)/(j - i), {j, 1, n}, {i, 1,
j - 1}]

and my for loop runs as follows, looping through n from 3 to 9, and j from 1 to n, and i from 1 to j-1:

numPoints = 10; For[n = 3, n < 10, n++,
 For[j = 1, j <= n, j++,
  For[i = 1, i < j, i++,
     a[i] := x; a[j] := y;  a[k_] /; k != {i, j} := 0;  
   dd[x_, y_, p_] := FultonHarris[n] - p^2; 
   FindInstance[
    dd[xx, yy, pp] == 0 && xx > 0 && yy > 0 && PrimeQ[pp], {xx, yy, 
     pp}, Integers, numPoints]
   ]
  ]
 ]

However, when I run this, it doesn't return anything, not even empty braces. Do I need to put a Print statement in there?

Moderat
  • 167
  • 5
  • 5
    For, Do, and While do not return anything, try Table, instead. – rcollyer Jun 18 '13 at 15:44
  • 1
    As @rcollyer suggests, this looks like a job for Table. But I suggest you simplify your example by making certain that each level of the iterations run properly starting from the innermost construct. Also look at Module[], it might help you deal in a clearer way with the functions you define in each level of iteration. – Jagra Jun 18 '13 at 16:07
  • what do you intend "xx", "yy",and "pp" to represent. You don't appear to define them. – Jagra Jun 18 '13 at 16:20
  • @Jagra they're parameters for FindInstance. – rcollyer Jun 18 '13 at 17:30
  • First of all, thanks everyone for the time you took to help me out. Secondly, @Jagra, I'm not sure what you mean by "simplify your example by making certain that each level of the iterations run properly starting from the innermost construct." Do you mean setting a[i] := x in the beginning of the i loop, and setting a[j] := y in the beginning of the j loop? Regards – Moderat Jun 19 '13 at 17:07

0 Answers0