# How to get the long logic expression with a terse method

I have a long logic expression

(x==2||x==3||x==4)&&(y==2||y==3||y==4)&&(z==2||z==3||z==4)&&(m==2||m==3||m==4)


How to get it by a terse express? This is current method

Or@@@(Thread[#=={2,3,4}]&/@And[x,y,z,m])


(x==2||x==3||x==4)&&(y==2||y==3||y==4)&&(z==2||z==3||z==4)&&(m==2||m==3||m==4)

But I'm very dissatisfy that /@ and that ().I think there must are terse method can do this.Anybody can give a try?

• Your equations vary in time ... Commented Apr 9, 2016 at 18:57
• @yarchik I'm very sorry for the serious typo.But everyone have that time.:)
– yode
Commented Apr 9, 2016 at 19:03
• Am I missing something? Is the construct that you have some set of variables, and you want to test if all of them are contained in some set of values? If so, then ConstainsAll[values,vars] will suffice, and for really big examples (I'm assuming since the example is not really long, it's just an example) it will be vastly faster (as in thousands of times for big cases) than solutions so far...
– ciao
Commented Apr 10, 2016 at 4:38
• @ciao Thanks for your concern this post.The question drived from this post.My solution is var={x,y,z,m}; Solve[x+2y+z+m==24&&(x==2||x==7||x==4)&&(y==2||y==7||y==4)&&(z==2||z==7||z==4)&&(m==2||m==7||m==4),var].So I want to get (x==2||x==7||x==4)&&(y==2||y==7||y==4)&&(z==2||z==7||z==4)&&(m==2||m==7||m==4) by a concise code.
– yode
Commented Apr 10, 2016 at 6:13
• @yode : ah, well for the referenced post (the goal of this question I take it?), seems to me Solve[x + 2 y + z + m == 14 && And @@ Thread[2 <= {x, y, z, m} <= 4], Integers] is pretty concise...
– ciao
Commented Apr 10, 2016 at 6:37

My offering:

And @@ Or @@@ Outer[Equal, {x, y, z, m}, {2, 3, 4}]

• Thanks, I've swapped the logical functions around to your new requirements. Commented Apr 9, 2016 at 18:55
• I think Distribute[Equal[And[x,y,z,m],Or[2,3,4]],And] should have a same output.But actually not.
– yode
Commented Apr 10, 2016 at 4:03
• I see what you mean, it doesn't quite work does it! If it did And @@ Thread[{x, y, z} == Or[2, 3, 4]] would be a fraction terser Commented Apr 10, 2016 at 9:19

A set solution.

cond = {{x}, {y}, {z}, {m}} ∈ Interval[{2, 4}] && {x, y, z, m} ∈ Integers


Set x, y, z, and m to be Integers on the Interval 2 to 4. We can use cond to be certain it is defined as expected.

Solve[x + y + z + m == 8 && cond, {x, y, z, m}]
(* {{x -> 2, y -> 2, z -> 2, m -> 2}} *)


This gives the expected result.

Hope this helps.

And @@ Thread@Table[Or @@ Thread@Table[j == i, {i, {2, 3, 4}}], {j, {x, y, z, m}}]

• With just one Table: And @@ Or @@@ Table[j == i, {j, {x, y, z, m}}, {i, {2, 3, 4}}] Commented Apr 9, 2016 at 18:53
• yes that's much better. I now realize that the my Table is essentially doing what your Outer does. But your solution is so much prettier! Commented Apr 9, 2016 at 19:00