Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PARI/GP function returns unique elements of a vector, tests vectors for uniqueness
/*
Returns a vector of the unique elements of v
Input
v: vector
Output
u: Vector of unique elements of v
Example:
v = [1,1,2,2];
u = unique(V)
[1,2]
Written by: John Peach 30-Dec-2020
*/
unique(v) =
{
u = Vec(Set(v));
}
/*
Determines if all elements of vector v are unique
Input
v: vector
Output
TF: 1 if unique, 0 otherwise
Example:
v = [1,1,2,2];
isunique(v) = 0
*/
isunique(v) =
{
length(v) == length(unique(v));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment