Skip to main content
1 of 4
Ymareth
  • 4.8k
  • 22
  • 29

The conflated two uses of SameTest within Intersection

Intersection works as expected in this case...

a = Range[1,5];b=Range[3,7]; Intersection[a,b] 

giving...

{3,4,5} 

However if I expand the concept of sameness using SameTest to this...

Intersection[a,b, SameTest->(Abs[#1-#1]<=2&)] 

I get the slightly puzzling result of...

{5} 

I was expecting to see something like {2,3,4,5,6}.

I thought this might be Union running within Intersection but...

Union[{2,3,4,5,6},SameTest->(Abs[#1-#2]<=1&)] 

gives...

{2,4,6} 

So I am at something of a loss.

Ymareth
  • 4.8k
  • 22
  • 29