Remy Cano on Thu, 04 Sep 2014 17:03:20 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Featuring: vecbinariesums(x,y,z)


Description:

takes a vector "x", and generates all the possible sums among pairs of different elements (binary combinations) divided by "y" (having assumed that such sums are 0 Mod "y"), excluding those sums where the position of at least one of the operands is listed in "z". 

GP Source code:

 vecbinariesums(x,y=2,z=[1])={my(p,t,v=vector(binomial(#x-#z,2)));if(y,forvec(u=vector(2,j,[1,#x]),p=1;if(#z,p*=prod(l=1,#z,(u[1]!=z[l])&&(u[2]!=z[l])));if(p,v[t++]=(x[u[1]]+x[u[2]])\y),2));v}

Note: As presented here by default, is intended to be used with lists of odd numbers like when studying the Goldbach's conjecture.

Contribution from: R. J. Cano (reemmmyyyy at GMail dot com)