MakeUnique - Maple Help

ListTools

 MakeUnique
 remove copies of elements from a list

 Calling Sequence MakeUnique(L, N, f, opt1, opt2, ...)

Parameters

 L - list N - (optional) non-negative integer or infinity f - (optional) procedure opt1, opt2 - (optional) extra arguments to procedure f

Description

 • The MakeUnique(L) function removes all repeated elements from the list L.
 The elements are reviewed in order from left to right. If an element matches a previous element, it is removed from the list.
 The order of the elements in the returned list matches the order in the list L.
 • The MakeUnique(L, N) function retains N copies of matching elements in list L. If greater than N matching elements exist in L, they are removed.
 • By default, the elements in the list are compared by using boolean comparison. If argument f is specified, then f(x, y, opt1, opt2, ...) is called to check if element x and element y should be considered equal. This function should implement an equivalence relation (i.e. it should be reflexive, commutative, and transitive).  If it is not, then the result may not be valid.

Examples

 > $\mathrm{with}\left(\mathrm{ListTools}\right):$
 > $L≔\left[1,2,3,4,3,2,3,4,5,4,3,4,5,6\right]$
 ${L}{≔}\left[{1}{,}{2}{,}{3}{,}{4}{,}{3}{,}{2}{,}{3}{,}{4}{,}{5}{,}{4}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (1)
 > $\mathrm{MakeUnique}\left(L\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (2)
 > $\mathrm{MakeUnique}\left(L,0\right)$
 $\left[\right]$ (3)
 > $\mathrm{MakeUnique}\left(L,2\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{3}{,}{2}{,}{4}{,}{5}{,}{5}{,}{6}\right]$ (4)
 > $\mathrm{MakeUnique}\left(L,'\mathrm{∞}'\right)$
 $\left[{1}{,}{2}{,}{3}{,}{4}{,}{3}{,}{2}{,}{3}{,}{4}{,}{5}{,}{4}{,}{3}{,}{4}{,}{5}{,}{6}\right]$ (5)
 > $L≔\left[0.,\left(x-1\right)\left(x+1\right),-0.,{x}^{2}-1,0,-\left(1-x\right)\left(x+1\right)\right]$
 ${L}{≔}\left[{0.}{,}\left({x}{-}{1}\right){}\left({x}{+}{1}\right){,}{-0.}{,}{{x}}^{{2}}{-}{1}{,}{0}{,}{-}\left({1}{-}{x}\right){}\left({x}{+}{1}\right)\right]$ (6)
 > $\mathrm{MakeUnique}\left(L\right)$
 $\left[{0.}{,}\left({x}{-}{1}\right){}\left({x}{+}{1}\right){,}{-0.}{,}{{x}}^{{2}}{-}{1}{,}{0}{,}{-}\left({1}{-}{x}\right){}\left({x}{+}{1}\right)\right]$ (7)
 > $\mathrm{MakeUnique}\left(L,1,\mathrm{verify},\mathrm{expand}\right)$
 $\left[{0.}{,}\left({x}{-}{1}\right){}\left({x}{+}{1}\right)\right]$ (8)
 > ListTools:-MakeUnique([1,2,6,5,10,9,7,3,11],                       2,                       proc(a,b)                           evalb(a-b mod 4 = 0);                       end proc                      );
 $\left[{1}{,}{2}{,}{6}{,}{5}{,}{7}{,}{3}\right]$ (9)