# How can I delete duplicates with Abs?

I have this list with some duplicate elements and I want to delete duplicate ones.

mylist = {ConditionalExpression[1, -1 <= x <= 0],
ConditionalExpression[-x, x <= -1],
ConditionalExpression[-x, x <= -1],
ConditionalExpression[Abs[x], x <= -1]};


Now I tried to delete duplicate elements with this.

DeleteDuplicates[mylist]


This doesn't work. I expected that two of these three elements {ConditionalExpression[-x, x <= -1], ConditionalExpression[-x, x <= -1], ConditionalExpression[Abs[x], x <= -1]} should be deleted.

Then I thought probably that was due to Mathematica thinking that x is complex, so I added the assumption that x is real, but this didn't work either.

Assuming[x \[Element] Reals, DeleteDuplicates[mylist]]


How can I delete duplicate elements so the three elements above are considered duplicate?

DeleteDuplicates[Refine[mylist, Assumptions -> x ∈ Reals]]


gives what you want

Try this:

DeleteDuplicates[Refine[Map[LogicalExpand, mylist], Assumptions -> x \[Element] Reals]]


• This one is a bit longer than bmf's answer. I wonder if there is any case this works but bmf's answer or vice versa.
– hana
Apr 18, 2022 at 15:55

Assuming you do want to keep one of the equivalent ConditionalExpressions

DeleteDuplicatesBy[mylist, Refine[#, #[[2]]] &]


{ConditionalExpression[1, -1 <= x <= 0], ConditionalExpression[-x, x <= -1]}

• I think this would consider {ConditionalExpression[1 - x, 0 <= x <= 1/2], ConditionalExpression[1 - x, x <= 1/2]} duplicates while they aren't.
– hana
Apr 17, 2022 at 23:08
• DeleteDuplicatesBy[mylist, Refine] seems sufficient. May 3 at 19:51
list =
{ConditionalExpression[1, -1 <= x <= 0],
ConditionalExpression[-x, x <= -1],
ConditionalExpression[-x, x <= -1],
ConditionalExpression[Abs[x], x <= -1]};


In this case we only need

DeleteDuplicates @ Refine @ list


From the documentation:

"Refine[expr] uses default assumptions ..."