PARI/GP function returns unique elements of a vector, tests vectors for uniqueness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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