Re¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
Re[z]
gives the real part of numeric z; Re[Re[z]], Re[Im[z]], Re[Abs[z]], Re[Arg[z]] fold since those heads are real-valued.
Examples (16)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (7)¶
In[1]:= Re[1/(2 + 3 I)]
Out[1]= 2/13
In[2]:= Im[Log[-1]]
Out[2]= Pi
In[3]:= ReIm[(2 + I)^3]
Out[3]= {2, 11}
In[4]:= Abs[-9223372036854775807 - 1]
Out[4]= 9223372036854775808
In[5]:= Sign[3 + 4 I]
Out[5]= 3/5 + 4/5*I
In[6]:= Conjugate[(2 + I)/(1 - 3 I)]
Out[6]= -1/10 - 7/10*I
In[7]:= Arg[(-1)^(1/6)]
Out[7]= 1/6 Pi
Applications (9)¶
Listable
(1 + I)^10 = 32 I is purely imaginary
The exact real part of a quotient
A bignum is its own real part
Re, Im, Abs and Arg are real-valued by construction
A real Root object is returned unchanged
The NDArray projection kernel
Symbols are not assumed real: use ComplexExpand for that
Implementation notes¶
Algorithm. builtin_re tries the following cases in order. A call to a head that is real by construction (Re, Im, Abs, Arg) is returned unchanged, so Re[Re[z]] is Re[z]. A real AlgebraicNumber or Root (tested with FLINT qqbar, flint_qqbar_is_real) is returned as itself; a non-real one stays wrapped, as in Mathematica. A Complex[re, im] literal gives re. A real number leaf (is_real_number_leaf: an Integer, bigint, machine Real, MPFR, or Rational with int64 or bignum parts) gives itself. Otherwise complex_decompose walks the Plus/Times structure, multiplying Complex factors through. When both parts it finds are concretely numeric (is_numeric_real, judged by machine N), the real part is returned; this is what reduces Re[1/(2 + 3 I)] to 2/13. Anything else returns NULL and stays unevaluated.
Data structures. The decomposition builds and evaluates fresh re/im trees. No other state is kept. On the packed and NDArray surfaces Re is a projection kernel (UK_PROJ(Re, ar)): a complex buffer gives a real buffer, and real data passes through. In Compile[] it lowers at scalar and array shapes, and over integers it is the identity.
Complexity / limits. The leaf cases are O(1). The decomposition is linear in the size of the expression, plus one machine-N reality check per part. Symbols are not assumed real, so Re[x + I y] stays unevaluated (use ComplexExpand for that convention). A gap: an exact real constant with no Complex literal inside, such as Re[Pi], is not yet recognised and stays unevaluated (Mathematica gives Pi).
Attributes: Listable, NumericFunction, Protected.
References¶
See also: Im, ReIm, Abs, Sign, Conjugate, Arg, Real, Rational
- Source:
src/complex.c - Specification:
docs/spec/builtins/arithmetic.md - Tests:
tests/test_accuracygoal.c - Tests:
tests/test_airyai.c - Tests:
tests/test_airybi.c - Tests:
tests/test_algebraicnumber.c
Notes & additional examples¶
Notes¶
Re[z]is the real part of a numericz. A real number comes back unchanged.- Symbols are not assumed real, so
Re[x + I y]stays unevaluated;ComplexExpand[Re[x + I y]]givesx. A non-realRootorAlgebraicNumberalso stays wrapped, as in Mathematica. - Limitation: an exact real constant with no complex part written out, such as
Re[Pi], is not yet recognised and stays unevaluated (Mathematica givesPi). Listable,NumericFunction,Protected. There is a packed/NDArray projection kernel, andCompile[]lowersReat scalar and array shapes.- See also:
Im,ReIm,Conjugate,ComplexExpand.