Group Abstract Group Abstract

Message Boards Message Boards

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

The usage of DuplicateFreeQ

Posted 2 years 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 2 years 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 2 years 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