Skip to content

Element

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

Element[x, dom]

returns True if x is provably an element of the domain dom under the current $Assumptions, False if it is provably not, and stays unevaluated otherwise.

Element[{x1, ..., xN}, dom] and Element[x1 | ... | xN, dom] are shorthand for the conjunction Element[x1, dom] && ... && Element[xN, dom]: True/False if every component decides, otherwise unevaluated and treated as a joint per-variable fact by Simplify.

Notes Supported domains: Integers, Rationals, Reals, Algebraics, Complexes, Booleans, Primes, Composites. Numeric and structural literals decide directly: Element\[5, Integers\] -\> True, Element\[5/2, Integers\] -\> False, Element\[1+I, Reals\] -\> False, Element\[2.5, Integers\] -\> False. Element consults $Assumptions for symbolic queries, so under Assuming\[Element\[x, Integers\], ...\] a query Element\[x, Reals\] returns True via the Integer =\> Real lattice.

Examples (10)

Every input below was run against the current Mathilda build and its output recorded.

Basic examples (4)

In[1]:= Element[7, Primes]
Out[1]= True

In[2]:= Element[5/2, Integers]
Out[2]= False

In[3]:= Element[1 + I, Reals]
Out[3]= False

In[4]:= Element[x, Reals]
Out[4]= Element[x, Reals]

Applications (6)

In[5]:= Element[5, Integers]
Out[5]= True

In[6]:= Element[5/2, Integers]
Out[6]= False

In[7]:= Element[7, Primes]
Out[7]= True

In[8]:= Element[1 + I, Algebraics]
Out[8]= True

In[9]:= Element[{2, 3, 5, 7}, Primes]
Out[9]= True

In[10]:= Assuming[Element[x, Integers], Element[x, Reals]]
Out[10]= True

Implementation notes

Algorithm. builtin_element decides domain membership Element[x, dom], returning True/False, or staying unevaluated (NULL) when undetermined. Element[{x1,...}, dom] and Element[x1|x2|..., dom] are treated as the conjunction over components: collapse to True/False only when every component decides, otherwise leave the original in place so the assumption framework (ctx_walk in simp_assume.c) can still split it into per-variable facts.

For a symbol domain, it reads the current $Assumptions (read_dollar_assumptions), builds an AssumeCtx, and calls element_decide, which returns 1/0/-1. The decision first checks the fact set directly (fact_in_domain), then applies literal rules per domain: Integers (Integer/BigInt yes, integer-valued Real yes, Rational/Complex no), Rationals/Algebraics/Reals/Complexes (with canonical Complex always carrying a non-zero imaginary part, so Element[I, Reals] is False), Booleans (only literal True/False), and Primes/Composites (delegating to PrimeQ). Provable facts from assumptions are consulted via prov_int/prov_re. Unknown or symbolic cases return -1 → the call stays unevaluated.

Data structures. AssumeCtx (flat fact array) built per call from $Assumptions; element_decide is a strcmp-dispatched cascade with no persistent state.

  • Protected.
  • Supported domains: Integers, Rationals, Reals, Algebraics, Complexes, Booleans, Primes, Composites.
  • Numeric and structural literals decide directly. Symbolic queries consult $Assumptions, honouring the Integer ⊆ Rational ⊆ Algebraic ⊆ Real ⊆ Complex lattice.
  • Element[{x1, ..., xN}, dom] and Element[x1 | ... | xN, dom] are shorthand for the conjunction Element[x1, dom] && ... && Element[xN, dom]: True / False if every component decides, otherwise unevaluated (and treated as a joint per-variable fact by Simplify).

Attributes: Protected.

References

See also: $Assumptions, Simplify

Notes & additional examples

Notes

Element[x, dom] returns True if x is provably in the domain, False if provably not, and stays unevaluated otherwise. Supported domains are Integers, Rationals, Reals, Algebraics, Complexes, Booleans, Primes, and Composites. Numeric and structural literals decide directly — including membership in Primes and in Algebraics (e.g. the Gaussian integer 1 + I). A list or Alternatives of variables is shorthand for the conjunction over the components. For symbolic queries Element consults $Assumptions, so under Assuming[Element[x, Integers], ...] it climbs the domain lattice and reports that an integer is also real.