Question: how to remove duplicates from a set or list?

The set and list produced by map (see below) contain duplicates.  How to remove duplicates?
 

p := (1+5^(1/2))*(1/2)

1/2+(1/2)*5^(1/2)

(1)

with(Bits)

[And, FirstNonzeroBit, GetBits, Iff, Implies, Join, Nand, Nor, Not, Or, Settings, Split, String, Xor]

(2)

with(LinearAlgebra)

[`&x`, Add, Adjoint, BackwardSubstitute, BandMatrix, Basis, BezoutMatrix, BidiagonalForm, BilinearForm, CARE, CharacteristicMatrix, CharacteristicPolynomial, Column, ColumnDimension, ColumnOperation, ColumnSpace, CompanionMatrix, CompressedSparseForm, ConditionNumber, ConstantMatrix, ConstantVector, Copy, CreatePermutation, CrossProduct, DARE, DeleteColumn, DeleteRow, Determinant, Diagonal, DiagonalMatrix, Dimension, Dimensions, DotProduct, EigenConditionNumbers, Eigenvalues, Eigenvectors, Equal, ForwardSubstitute, FrobeniusForm, FromCompressedSparseForm, FromSplitForm, GaussianElimination, GenerateEquations, GenerateMatrix, Generic, GetResultDataType, GetResultShape, GivensRotationMatrix, GramSchmidt, HankelMatrix, HermiteForm, HermitianTranspose, HessenbergForm, HilbertMatrix, HouseholderMatrix, IdentityMatrix, IntersectionBasis, IsDefinite, IsOrthogonal, IsSimilar, IsUnitary, JordanBlockMatrix, JordanForm, KroneckerProduct, LA_Main, LUDecomposition, LeastSquares, LinearSolve, LyapunovSolve, Map, Map2, MatrixAdd, MatrixExponential, MatrixFunction, MatrixInverse, MatrixMatrixMultiply, MatrixNorm, MatrixPower, MatrixScalarMultiply, MatrixVectorMultiply, MinimalPolynomial, Minor, Modular, Multiply, NoUserValue, Norm, Normalize, NullSpace, OuterProductMatrix, Permanent, Pivot, PopovForm, ProjectionMatrix, QRDecomposition, RandomMatrix, RandomVector, Rank, RationalCanonicalForm, ReducedRowEchelonForm, Row, RowDimension, RowOperation, RowSpace, ScalarMatrix, ScalarMultiply, ScalarVector, SchurForm, SingularValues, SmithForm, SplitForm, StronglyConnectedBlocks, SubMatrix, SubVector, SumBasis, SylvesterMatrix, SylvesterSolve, ToeplitzMatrix, Trace, Transpose, TridiagonalForm, UnitVector, VandermondeMatrix, VectorAdd, VectorAngle, VectorMatrixMultiply, VectorNorm, VectorScalarMultiply, ZeroMatrix, ZeroVector, Zip]

(3)

with(VectorCalculus)

[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, About, AddCoordinates, ArcLength, BasisFormat, Binormal, Compatibility, ConvertVector, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProduct, Flux, GetCoordinateParameters, GetCoordinates, GetNames, GetPVDescription, GetRootPoint, GetSpace, Gradient, Hessian, IsPositionVector, IsRootedVector, IsVectorField, Jacobian, Laplacian, LineInt, MapToBasis, Nabla, Norm, Normalize, PathInt, PlotPositionVector, PlotVector, PositionVector, PrincipalNormal, RadiusOfCurvature, RootedVector, ScalarPotential, SetCoordinateParameters, SetCoordinates, SpaceCurve, SurfaceInt, TNBFrame, Tangent, TangentLine, TangentPlane, TangentVector, Torsion, Vector, VectorField, VectorPotential, VectorSpace, Wronskian, diff, eval, evalVF, int, limit, series]

(4)

b := proc (x, w) options operator, arrow; (-1)^GetBits(x, w, output = number) end proc

proc (x, w) options operator, arrow; (-1)^Bits:-GetBits(x, w, output = number) end proc

(5)

l := proc (x, t, u, v) options operator, arrow; frac(x)*Vector([b(floor(x), 0)*t, b(floor(x), 1)*u, b(floor(x), 2)*v])+(1-frac(x))*Vector([b(floor(x), 0)*v, b(floor(x), 1)*t, b(floor(x), 2)*u]) end proc

proc (x, t, u, v) options operator, arrow; VectorCalculus:-`+`(VectorCalculus:-`*`(frac(x), VectorCalculus:-Vector([VectorCalculus:-`*`(b(floor(x), 0), t), VectorCalculus:-`*`(b(floor(x), 1), u), VectorCalculus:-`*`(b(floor(x), 2), v)])), VectorCalculus:-`*`(VectorCalculus:-`+`(1, VectorCalculus:-`-`(frac(x))), VectorCalculus:-Vector([VectorCalculus:-`*`(b(floor(x), 0), v), VectorCalculus:-`*`(b(floor(x), 1), t), VectorCalculus:-`*`(b(floor(x), 2), u)]))) end proc

(6)

map(l, {0, 1, 2, 3, 4, 5, 6, 7, 8}, 0, 1, p)

{Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])}

(7)

map(l, [0, 1, 2, 3, 4, 5, 6, 7, 8], 0, 1, p)

[Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(8)

q := ListTools:-MakeUnique(%)

q := [Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(9)

Equal(q[1], q[9])

true

(10)

qq := [op({q[]})]

qq := [Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = -1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = -1/2-(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian]), Vector(3, {(1) = 1/2+(1/2)*5^(1/2), (2) = 0, (3) = 1}, attributes = [coords = cartesian])]

(11)

LinearAlgebra:-Equal(qq[1], qq[5])

true

(12)

NULL


 

Download cp.mw

Please Wait...