0
$\begingroup$

Given the set A={x|-5<x^3<5} and the set B={-3,-1,0,2,3}, how to find the intersection of sets A and B?

I tried the following method myself, but how come it doesn't achieve the goal?

A = {Reduce[{-5 < x^3 < 5}, x, Reals]} B = {-3, -1, 0, 2, 3} Intersection[A, B] 

enter image description here

$\endgroup$
1
  • 4
    $\begingroup$ Once again, please read document of Intersection carefully, don't guess its usage, it's just not for the task you're imagining. (-1) $\endgroup$ Commented Jun 12, 2024 at 12:15

6 Answers 6

5
$\begingroup$

If I understand Intersection it works on discrete lists (typically List, but any head it seems). My best guess is that you want an Interval.

intervalA = Interval[{A[[1, 1]], A[[1, -1]]}]; Select[B, IntervalMemberQ[intervalA]] (* {-1, 0} *) 
$\endgroup$
5
$\begingroup$

@lericr already explained this very nicely and gave a proper answer. I just want to provide an answer with minimal modification of the original question for pedagogical reasons.

Create a list with the output of Reduce (PROPERLY) and then use Intersection

It works in the following manner

A = x /. List@ToRules@Reduce[{-5 < x^3 < 5}, x, Integers]; B = {-3, -1, 0, 2, 3}; Intersection[A, B] 
$\endgroup$
2
  • $\begingroup$ Solving for integers does make the most sense. $\endgroup$ Commented Jun 12, 2024 at 1:14
  • $\begingroup$ @lericr Well, not really. Only in the case that Intersection has to be used. Frankly your solution is the proper one in my opinion. $\endgroup$ Commented Jun 12, 2024 at 1:17
3
$\begingroup$
f[u_] := Reduce[RealAbs[x^3] < 5, x] /. x -> u; b = {-3, -1, 0, 2, 3} Select[f@# == True &][b] 

yields {-1,0}

NumberLinePlot[{f[x], b}, {x, -4, 4}]

enter image description here

$\endgroup$
3
$\begingroup$
set = Range[-10, 10]; A = Pick[set, -5 < #^3 < 5 & /@ set] B = {-3, -1, 0, 2, 3}; Intersection[A, B] 

{-1, 0, 1}

{-1, 0}

$\endgroup$
2
$\begingroup$

Direct result from Reduce:

Reduce[-5 < x^3 < 5 && AnyTrue[{-3, -1, 0, 2, 3}, x == # &], x] 

x == -1 || x == 0

$\endgroup$
1
$\begingroup$
B = {-3, -1, 0, 2, 3} Select[B, -5 < #^3 < 5 &] 

enter image description here

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.