Bill Allombert on Sat, 11 Feb 2012 00:05:15 +0100


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

Re: experimental GP extensions


On Thu, Feb 09, 2012 at 04:47:24PM +0100, Bill Allombert wrote:
> Hello PARI developers,
> 
> I have created a GIT branch "bill-ranges" which add some experimental feature to GP
> that we discussed at the Ateliers.
> 
> This is example of what is implemented:
> 
> ranges: [a..b] -> [a,a+1,...,b]
> slices: V[a..b] -> [V[a],V[a+1],...,V[b]]
> comprehension: [x^2+1 | x<-[1..40], isprime(x)] = apply(x->x^2+1,select(isprime,[1..40]))

I just added some more slices to that branch:

V[^a] = [V[1],...,V[a-1],V[a+1],...V[#V]]
V[3..-1] = [V[3],...,V[#V]]
V[3..-3] = [V[3],...,V[#V-2]]

x[a..b,c..d] = [x[a,c],  x[a+1,c],  ...,x[b,c];
                x[a,c+1],x[a+1,c+1],...,x[b,c+1];
                    ...       ...          ...
                x[a,d],  x[a+1,d]  ,...,x[b,d]]
x[a..b,] = x[a..b,1..#x]
x[,a..b,] = x[1..#x~,a..b]
x[a..b,c] = [x[a,c],...,x[b,c]]
 
etc:

M=matrix(5,5,i,j,i+5*j-5);
M[2..3,2..3]
M[1..2,1]
M[1,1..4]
M[1..3,]
M[,1..3]
M[1..5,1..-2]
M[1..-2,1..-2]
M[-3..-1,-3..-1]
M[^3,2..3]
M[^2,1]
M[1,^4]
M[^3,]
M[,^3]
M[^5,1..-2]
M[1..-2,^-2]
M[-3..-1,-3..-1]

Cheers,
Bill.