Message Boards Message Boards

0
|
1326 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

The usage of DuplicateFreeQ

Posted 1 year ago

See my following example:

In[347]:= x=Tuples[{0,1},3]
Select[x,! #[[1]]==#[[2]]==#[[3]]&]
Select[x,DuplicateFreeQ]

Out[347]= {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 
  0, 1}, {1, 1, 0}, {1, 1, 1}}

Out[348]= {{0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 
  1, 0}}

Out[349]= {}

I want to obtain the similar result as the second command by using the DuplicateFreeQ in the last command shown above. Why doesn't my usage return any results?

Regards,
Zhao

POSTED BY: Hongyi Zhao
2 Replies
Posted 1 year ago

Nice. It does the trick:

In[12]:= xx=Tuples[{0,1},3]
Select[xx,! #[[1]]==#[[2]]==#[[3]]&]
%==Select[xx, ! SameQ @@ # &]==Select[xx, ! Equal @@ # &]

Out[12]= {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 
  0, 1}, {1, 1, 0}, {1, 1, 1}}

Out[13]= {{0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 
  1, 0}}

Out[14]= True

P.S. It seems that in this case, both SameQ and Equal work.

POSTED BY: Hongyi Zhao
Posted 1 year ago

Why doesn't my usage return any results?

That is because all matrix rows contains duplicates.

SameQ could be used:

Select[x, ! SameQ @@ # &]
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract