John Cremona on Fri, 03 Nov 2023 12:42:54 +0100


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

Re: asking for a new GP-Pari command




On Fri, 3 Nov 2023 at 08:53, Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> wrote:
On Thu, Nov 02, 2023 at 04:28:04PM -0700, American Citizen wrote:
> To all:
>
> Recently I had to remove duplicate entries from a vector.
>
> Can GP-Pari create a command which will work with both lists and vectors to
> output duplicate entries?
>
> I am aware that vecsort has flag=8 in vecsort(V,,8) and listsort has flag =
> 1 in listsort(L,1) to remove duplicates, but I need to find them, not erase
> them.
>
> Suppose v = [1,2,3,4,5,3,6]
>
> Then I would like a GP-Pari command called "duplicates(v)" to produce the
> following output.
>
> duplicates(v) = [3]

You can do that:

duplicates(v) =  [x[1]|x<-matreduce(v)~,x[2]>1];


That's interesting, I did not know that matreduce() could do that.  I suggest that its documentation "reduce the factorization matrix m to canonical form (sorted first row with unique elements) matrix." is incomplete, it certainly suggests that the input must be a matrix.  As far as I can see, given a list (or vector) it returns a matrix with two columns, the unique entries in the first column (sorted) and their multiplicities in the second.  And the entries don't have to be numbers, I just tried with a random list of letters (i.e. variables).
 
Please can the documentation for matreduce be revised?

John

? v = [1,2,3,4,5,3,6]
? duplicates(v)
%6 = [3]

Cheers,
Bill