NumericQ¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
NumericQ[expr] gives True if expr is a numeric quantity, and False otherwise.
An expression is considered a numeric quantity if it is either an explicit number or a mathematical constant such as Pi, or is a function that has attribute NumericFunction and all of whose arguments are numeric quantities.
Examples¶
No verified examples yet for this function.
Implementation notes¶
builtin_numericq (1-arg) returns True/False by calling the recursive predicate is_numeric_quantity. That predicate returns true for EXPR_INTEGER/EXPR_REAL/EXPR_BIGINT/EXPR_MPFR; for the named numeric constants Pi, E, I, Infinity, ComplexInfinity, EulerGamma, GoldenRatio, Catalan, Degree; for Complex[...] and Rational[...] heads; and for any function whose head carries ATTR_NUMERICFUNCTION provided every argument is itself numeric (recursive check). Everything else — bare symbols, non-numeric heads — yields False. Unlike NumberQ, this resolves the "would evaluate to a number" question structurally via the attribute system rather than by numericalizing.
Attributes: Protected.
Implementation status¶
Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
References¶
- Source:
src/core.c - Specification:
docs/spec/builtins/expression-information.md
Notes & additional examples¶
Worked examples¶
A deep tree of constants and transcendental functions is recognised as numeric without any value being computed:
One non-numeric leaf is enough to spoil the whole expression:
The classification looks through NumericFunction heads recursively, so mixed
elementary and special functions of numeric arguments still qualify:
Notes¶
An expression is numeric if it is an explicit number, a constant such as Pi, or
a NumericFunction whose arguments are all numeric. The test is structural and
recursive — it never evaluates the expression to a number — so Gamma[1/2] +
Zeta[3] is reported numeric while a single symbolic leaf such as x makes the
whole expression non-numeric.