2
$\begingroup$

Given the following two sets of reals:

-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2
x <= -1 || -1 < x < 0

how can I calculate their union? The expected answer is:

0 > x > -1/4
$\endgroup$
1
  • 1
    $\begingroup$ The union is all real numbers. The intersection gives the expected answer, but it's not the only way to get the expected answer. Please clarify the question. $\endgroup$
    – Michael E2
    Commented Aug 16, 2023 at 13:07

5 Answers 5

12
$\begingroup$

You can try

Reduce[{-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2}, x]

x > -(1/4)

Reduce[{x <= -1 || -1 < x < 0}, x]

x < 0

set1 = Reduce[{-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2}]
set2 = Reduce[{x <= -1 || -1 < x < 0}]
Reduce[set1 && set2, x]

-(1/4) < x < 0

$\endgroup$
3
  • $\begingroup$ In[534]:= Clear["Global`*"] f[x_] := Piecewise[{{2^-x, x <= 0}, {1, x > 0}}] Reduce@Reduce[f[x + 1] < f[2 x], x, Reals] Out[536]= x < 0The results not merged above come from the solution set of inequalities $\endgroup$
    – csn899
    Commented Aug 15, 2023 at 5:59
  • $\begingroup$ Is it still nested with a layer of reduce? $\endgroup$
    – csn899
    Commented Aug 15, 2023 at 5:59
  • $\begingroup$ See updated. Some thing like that? $\endgroup$
    – Laurenso
    Commented Aug 15, 2023 at 6:06
6
$\begingroup$
Simplify[(-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2) && (( x <= -1 || -1 < x < 0))]

(*  -(1/4) < x < 0 *) 
$\endgroup$
6
$\begingroup$

Laurenso's answer is how I'd normally do it, but let me also offer the following:

RegionIntersection[ImplicitRegion[-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2, {x}],
                   ImplicitRegion[x <= -1 || -1 < x < 0, {x}]]
   ImplicitRegion[-(1/4) < x < 0, {x}]
$\endgroup$
0
5
$\begingroup$

You can just combine (as @Laurenso, which I have voted for)

w = (-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2) &&
   (x <= -1 || -1 < x < 0);
Reduce[w, x]

yields: 1/4 < x < 0

Interval[]: is closed intervals but for illustrative purposes:

i1 = Interval[{-1/4, 0}];
i2 = Interval[{0, 1/2}];
i3 = Interval[{1/2, Infinity}];
i4 = Interval[{-Infinity, -1}];
i5 = Interval[{-1, 0}];
i8 = IntervalIntersection[i6 = IntervalUnion[i1, i2, i3], 
   i7 = IntervalUnion[i4, i5]];
NumberLinePlot[{i1, i2, i3, i4, i5, i6, i7, i8}, 
 PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
2
  • $\begingroup$ What is differrent between '-1/4 <x<0' and -1/4<=x<=0 when I use 'NumLinePlot'? $\endgroup$ Commented Aug 16, 2023 at 23:38
  • $\begingroup$ I just wanted illustrate Interval functions. I think NumberLinePlot uses open circles for open interval but am not near computer at present $\endgroup$
    – ubpdqn
    Commented Aug 17, 2023 at 1:01
4
$\begingroup$
Simplify[-(1/4) < x <= 0 || 0 < x <= 1/2 || x > 1/2]

1 + 4 x > 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.