# how to rewrite conditions as conditions&& True

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

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

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.

• 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? – wuyudi Feb 3 at 15:44

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