3
$\begingroup$

I want

Abs[x] + Abs[y] <= 1

to be convert to

x + y <= 1 && x + y >= -1 && x - y <= 1 && x - y >= -1  

How could I get it with Mathematica?

$\endgroup$
  • 3
    $\begingroup$ Reduce[Abs[x] + Abs[y] <= 1, {x, y}, Reals] already does a pretty good job--and incidentally shows that all solutions lie in the interval $[-1,1]$. $\endgroup$ – whuber Jan 30 '13 at 19:22
5
$\begingroup$
expandAbs[eq_] := And @@ Flatten@Module[{case},
eq //. 
 x_?((case = Cases[#, Abs[_], Infinity, 1]) =!= {} &) :> (case = 
    First[case]; {x /. case -> First[case], 
    x /. case -> -First[case]})]
expandAbs[Abs[x] + Abs[y] <= 1]
| improve this answer | |
$\endgroup$
  • $\begingroup$ This isn't always algebraically correct, but this is: expandAbs[eq_] := Module[{case}, eq //. x_?((case = Cases[#, Abs[_], Infinity, 1]) =!= {} &) :> (case = First[case]; Or[(x /. case -> First[case]) && First@case >= 0, (x /. case -> -First[case]) && First@case < 0])] $\endgroup$ – VF1 Aug 30 '13 at 5:06
2
$\begingroup$

In case you want to visualize the answer:

RegionPlot[Evaluate@Reduce[Abs[x] + Abs[y] <= 1, {x, y}, Reals], {x,-2,2}, {y,-2,2}]

enter image description here

| improve this answer | |
$\endgroup$
1
$\begingroup$
Abs[x] + Abs[y] //. (k_: 1) Abs[x_] + y_ :> {k x + y, -k x + y} /.
 t_ :> And @@ Thread[Flatten[t] <= 1]

x + y <= 1 && x - y <= 1 && -x + y <= 1 && -x - y <= 1

Abs[x] + 2 Abs[y] + 3 Abs[z] //. (k_: 1) Abs[x_] + y_ :> {k x + y, -k x + y} /.
 t_ :> And @@ Thread[Flatten[t] <= 1]

x + 2 y + 3 z <= 1 && x + 2 y - 3 z <= 1 && x - 2 y + 3 z <= 1 && x - 2 y - 3 z <= 1 && -x + 2 y + 3 z <= 1 && -x + 2 y - 3 z <= 1 && -x - 2 y + 3 z <= 1 && -x - 2 y - 3 z <= 1

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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