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?
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... $\endgroup$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. $\endgroup$Solve[x + 2 y + z + m == 14 && And @@ Thread[2 <= {x, y, z, m} <= 4], Integers]
is pretty concise... $\endgroup$