# Is there a short way of writing (x==a || x==b || x==c)?

Something like x == (a|b|c) but that doesn't work.

• In certain cases MemberQ[{a,b,c}, x] could be used but it does pattern matching/SameQ rather than EqualQ. Depends of your use case.
– Kuba
May 26, 2021 at 4:39

AnyTrue[{a, b, c}, EqualTo[x]]


or

Or @@ Thread[x == {a, b, c}]

• Those give ways to do it but they're longer! I was hoping for a concise syntax for "x equals any of these discrete values"
– JLo
May 26, 2021 at 0:06
• @JLo Element[x, {a, b, c}]? May 26, 2021 at 0:10
• Works: Simplify[x == 5, x == 1 || x == 2 || x == 3] Doesn't work: Simplify[x == 5, x \[Element] {1, 2, 3}] It knows the 1st one is false but not the 2nd.
– JLo
May 26, 2021 at 0:18
• @JLo {1,2,3} is not a valid domain for Element, so of course not...
– ciao
May 26, 2021 at 0:25
• Isn't that what you suggested? I'm confused. That's the same thing as Element[x, {a, b, c}] with values substituted.
– JLo
May 26, 2021 at 0:27

You can make it work if you really want to! ;) (Though this would have to be re-evaluated every session—unless you put it in an init file or something.)

Unprotect[Or]

Or /: (x_ == HoldPattern[Or[ys__]]) := Thread[Unevaluated[x == Or[ys]], Or]

Protect[Or]

(* In:  *) x == (a || b || c)
(* Out: *) x == a || x == b || x == c


(Note that this uses Or (||), not Alternatives (|).)

Other possibilities (with a fresh Or):

(* Just use thread directly: *)

Thread[x == (a || b || c), Or]

(* Map the equality function: *)

x == # & /@ (a || b || c)

(* or equivalently: *)

EqualTo[x] /@ (a || b || c)

(* Define a new function: *)

OrEqual[x_][ys__] := Thread[x == Or[ys], Or]

OrEqual[x][a, b, c]

(* Use MemberQ, but this is pattern-based: *)

MemberQ[{a, b, c}, x]

MemberQ[x][{a, b, c}]