0
$\begingroup$

I have a result comes from Reduce

a <= -2 || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2

it has a form that

(a cond && x cond) || (a cond && x cond) || etc.

Since cond && True gives out cond ,so True is being simplified.

how to rewrite it as

a <= -2&&True || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2&&True
$\endgroup$
  • 1
    $\begingroup$ Does PiecewiseExpand help? $\endgroup$ – mikado Jan 31 at 13:13
  • $\begingroup$ @mikado a <= -2 || (-2 < a <= -1 && (x <= 1/3 (-4 + 4 a) || x >= 4 + 4 a)) || a >= 2 // PiecewiseExpand seems doesn't work. $\endgroup$ – wuyudi Jan 31 at 16:41
3
$\begingroup$

How about this?

Replace[
  a <= -2 || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2,
  statement : Except[_And] :> Inactive[And][statement, True],
  {1}
]

Note the necessity to use Inactive[And], since otherwise the True in And[..., True] will disappear immediately again. Also note that BooleanConvert can be useful to ensure that the logical statement is always formulated as an Or.

| improve this answer | |
$\endgroup$
  • $\begingroup$ thx, now only a little question. Replace[a <= -2 || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2, statement : Except[_And] :> Defer@And[statement, True], {1}] /. (Or[a_ && b_]) :> {b, a} // Apply[Piecewise[{##}] &] I run this code. it return Piecewise[{{True, a <= -2}, {x >= 1/3 (4 + 4 a), 1 < a < 2}, {True, a >= 2}}] and a error. but I run Piecewise[{{True, a <= -2}, {x >= 1/3 (4 + 4 a), 1 < a < 2}, {True, a >= 2}}] , It will give out what I want. So , how can I directly get what i want? $\endgroup$ – wuyudi Feb 3 at 15:44
2
$\begingroup$

Someone in QQ group(QQ: 2636051698 ) give me two answer.

Replace[Unevaluated@
 Unevaluated[
  a <= -2 || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2], 
statement : Except[_And] :> 
 And[statement, True], {2}] /. (Or[a_ && b_]) :> {b, a} // 
List @@ # & // Piecewise

or

Replace[Hold[
 a <= -2 || (1 < a < 2 && (x >= 1/3 (4 + 4 a))) || a >= 2], 
statement : Except[_And] :> 
 And[statement, True], {2}] /. (Or[a_ && b_]) :> {b, a} // 
Apply[Piecewise[{##}] &, #, {1}] & // ReleaseHold

and some references

https://github.com/wuyudi/good-books/blob/master/UnevaluatedExpressions.nb

| 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.