0
$\begingroup$

This problem is extrapolated from a problem that was solved on how to manipulate lists of set outputs as a union ( Equation Autogeneration ), where the concern now is how to mine for (or attain from the beginning without as much fuss if possible) certain information describing the nature and position of matching quotients between sets of different origin of generation (in that problem, that variable is 'p') but the same divisor ('x').

Lastly I just need certain information on equal elements belonging to sets with the same X dividing into any given set, the specifics of which I explained below. Firstly I modified the equation slightly so something would crop up but it’s pretty straightforward. Moving on with that code and the changed equation we now have input:

Block[{p = #}, (((Binomial[Reverse[Range[((p + 1)/2), (p - 3)]], 
          Range[(p - 3) - ((p + 1)/2) + 1]]))/(Range[
         2, ((p - 3)/2)]))/x /. 
    Solve[4 + x <= p && 1 + p <= 2 x, Integers]] & /@ 
 Prime@Range[5, 6]

Resulting in output:

{{{2/3, 7/6, 5/6}, {4/7, 1, 5/7}}, {{5/7, 12/7, 2, 1}, {5/8, 3/2, 7/4,
    7/8}, {5/9, 4/3, 14/9, 7/9}}}

Sometimes two sets made from different subject-primes p but with the same divisor x will result in the same quotient q (an equivalent element of each set), but with a different order r in either. In this output we are combining as output the sets generated by the 5th and 6th primes, 11 and 13 being divided by the appropriate corresponding x allowed by its domain restriction for all integers therein, resulting in 2 sets possible for 11 (3 elements each) and 3 sets possible for 13 (4 elements each). Between these two sets of sets, which may need to be separated in the calculation despite our combining their output here - instead of doing so is fine - to ease comparison (I’m not sure), we need to compare all elements of sets belonging to different p but with the same divisor x to check for equality.

Assume that such equality can only happen once for a given divisor x (resulting in a pair); there should not be three sets, each of a different p but with the same divisor x, that result in the same quotient present in each set. Since there is always only one set divided by x resulting from any p there shouldn’t be possible any error in matching quotients because they wouldn’t be considered even if present between different sets of the same p, because only those with the same divisor x would be considered. Anyway, the output would look like:

x   ( p_1 , r_1 )   ~   ( p_2 , r_2 )   q   s

where x is the divisor, p_1 and p_2 are the two subject-primes whose sets contained the matching quotient and (p_2) > (p_1), r_1 and r_2 are the order of the matching quotient in its corresponding (_1 or _2 p set) where the first possible value from left-to-right is 2, q is the matching quotient and element of each set triggering the output, and s = ( r2 – ( r1 + ( ( r2 – r1 ) / 2 ) ) ).

Thus for our above example we would have an output of

7   ( 11 , 3 )  ~   ( 13 , 5 )  1   

Note that multiple different quotient-matches with the same divisor x may be possible even though multiple matches of the same quotient (like 1 here) should not be possible. List any new matches in the format of the above line in a new line downwards in order of increasing divisor x, so it would look like the below (where 7 in this case would be the first x, (x_1):

7   ( 11 , 3 )  ~   ( 13 , 5 )  1   

x_2 ...

x_3 ...

x_4 ...
$\endgroup$

1 Answer 1

1
$\begingroup$

I've jiggered the earlier result to pull some items out for later use, I believe this is what you're after. Note output is in form that makes sense - yours does not, unless you intend it to be a string/print output, in that case I'll leave it to you to do conversion.

ps = Prime@Range[5, 8];
divs = x /. Solve[4 + x <= # && 1 + # <= 2 x, Integers] & /@ ps;
sets = MapThread[Thread[{#1, #2}] &, {ps, divs}];
results = 
  Map[With[{p = #[[1]], 
      x = #[[2]]}, (((Binomial[Reverse[Range[((p + 1)/2), (p - 3)]], 
           Range[(p - 3) - ((p + 1)/2) + 1]]))/(Range[
          2, ((p - 3)/2)]))/x] &, sets, {2}];

matches=ReplaceList[
 Flatten[MapThread[Transpose[{##}] &, {sets, results}], 
  1], {___, {{p1_, d1_}, {pre1___, val1_, ___}}, ___, {{p2_, 
      d2_}, {pre2___, val2_, ___}}, ___} /; 
   d1 == d2 && val1 == val2 && Length@{pre1} < Length@{pre2} :> 
  With[{r1 = Length@{pre1} + 2, 
    r2 = Length@{pre2} + 2}, {d1, {p1, r1}, {p2, r2}, 
    val1*(r2 - (r1 + ((r2 - r1)/2)))}]]

(*
{{7,{11,3},{13,5},1},{9,{13,3},{17,7},8/3},{10,{17,5},{19,7},33/5},
 {11,{17,5},{19,7},6},{12,{17,5},{19,7},11/2},{13,{17,5},{19,7},66/13}}
*)

As an aside, this can be accomplished more elegantly I think by restructuring the generation and using Reap/Sow operations with post-filtering... an exercise perhaps.

$\endgroup$
10
  • $\begingroup$ okay I played with the code you just gave and it's close, the formatting's fine and two of the sets match what I've done by hand but the rest are wrong because I wanted to restrict answers to only -integer- quotients, not fractional as here shown, though they match as equal (8/3, 33/5, etc.). I increased the prime range and interestingly found other integer quotient answers I didn't know about (might be wrong, I'll verify) but am worried because others I did find and verify aren't on the list for some divisors. Also the 's' variable I mentioned is missing (forgot to show in my example). $\endgroup$ Jun 15, 2015 at 4:32
  • $\begingroup$ To simplify results, and since what I did by hand was with primes I changed Solve[4 + x <= # && 1 + # <= 2 x, Integers] to Solve[4 + x <= # && 1 + # <= 2 x, Primes] Here is the data from what I did by hand to check answers against; it should mostly match. I'll check my math again to make sure I'm not hallucinating. Typing the data in the next comment now... $\endgroup$ Jun 15, 2015 at 4:34
  • $\begingroup$ The missing S = ( r2 - ( r1 + ( ( r2 - r1 ) / 2 ) ) ), I haven't done it by hand but should be easy to automate to include with matching sets at its end. Your formatting was sensible. { X , P_1 , R_1 ) , ( P_2 , R_2 ) , Q , S } becomes { 7 , ( 11 , 3 ) , ( 13 , 7 ) , 1 , S } , { 11 , ( 17 , 5 ) , ( 19 , 7 ) , 6 , S } , { 13 , ( 19 , 5 ) , ( 23 , 9 ) , 11 , S } , { 17 , ( 23 , 5 ) , ( 31 , 13 ) , 28 , S } , { 19 , ( 23 , 3 ) , ( 37 , 17 ) , 3 , S } , { 19 , ( 29 , 9 ) , ( 31 , 11 ) , 442 , S } , { 23 , ( 29 , 5 ) , ( 43 , 19 ) , 77 , S } , { 29 , ( 37 , 7 ) , ( 53 , 23 ) , 2340 , S } $\endgroup$ Jun 15, 2015 at 4:45
  • $\begingroup$ { 23 , ( 31 , 7 ) , ( 41 , 17 ) , 627 , S } , { 29 , ( 43 , 13 ) , ( 47 , 17 ) , 137655 , S } , { 31 , ( 37 , 5 ) , ( 59 , 27 ) , 203 , S } , { 37 , ( 41 , 3 ) , ( 73 , 35 ) , 6 , S } , { 37 , ( 43 , 5 ) , ( 71 , 33 ) , 357 , S } , { 41 , ( 47 , 5 ) , ( 79 , 37 ) , 494 , S } $\endgroup$ Jun 15, 2015 at 4:53
  • $\begingroup$ I also don't get why some of the input from your equation come out in set form while others are just in parentheses; maybe I'm confused about what the output means but it should be all in parentheses or sets right, other than the two ( p , r ) inside. I'll keep looking at it and tweaking $\endgroup$ Jun 15, 2015 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.