# Creating a boolean expression of assumptions between variables

I'm trying to create a boolean expression from a list of lists of variables such that the elements of one list are not equal to the elements of all other lists. I thought this might work:

list = {{a, b}, {c}, {d}};
Outer[Unequal, list]
(*{{True, True}, {True}, {True}} *)



I was hoping to generate: {{a!=c,b!=c},{c!=d}}

The larger problem I'm trying to solve is to generate a list of expressions where elements in the same list are set equal and elements in different lists are set not equal: {a==b,c==c,d==d,a!=c,b!=c,a!=d,b!=d,c!=d}

Is there a way to use Unequal so that it does not evaluate the expression when used with outer?

• Do these give you any ideas? x={a,b,c};y={d,e,f,g};List@@LogicalExpand[Equal@@x] and Flatten[Outer[Unequal,x,y]]
– Bill
Sep 3, 2023 at 4:37
• Try: Outer[Unequal, Sequence @@ list] Sep 3, 2023 at 8:23

Let's augment list to help us verify:

list = {{a, b}, {c}, {d}, {e, f, g}}


In two steps:

equalities = Equal @@@ list
(* {a == b, True, True, e == f == g} *)


You can figure out what to do with the Trues. They might not hurt anything at all.

inequalities = Flatten[Outer[Unequal, Sequence @@ list]]
(* {a != c != d != e, a != c != d != f, a != c != d != g, b != c != d != e, b != c != d != f, b != c != d != g} *)


This is close to what you tried. Outer expects a sequence of lists, but you packed your separate lists together into a single list.

You can join them:

Join[equalities, inequalities]


Or join and remove the True:

DeleteCases[Join[equalities, inequalities], True]