Skip to content

Abs ​

The absolute value or magnitude of x: ∣x∣|x|, its distance from 0.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaAbsolute valueAbsolute value of a complex numberMathWorldAbsoluteValueComplexModulusWikidataQ3317982Britannicatopic/absolute-valueDLMF1.9.E7FungrimAbs✓Fungrim entryWolfram LanguageAbs!
Abs(x)the absolute value ∣x∣|x| of a real x, or the modulus of a complex number.
SageMathenumeratio_abs(x)SymPyAbs(x)mpmathfabs(x)Oscarabs(x)Juliaenumeratio_ball(abs, x)Rustabs(x)
Typed signatures
TypePackageApplies
(complex | infinity | quantity) -> numberanalyticreplaces compute-engineon Around, CenteredInterval, Interval
(complex | infinity | quantity) -> numbercompute-enginealways

Domain: Arithmetic

Details
  • For a real number, ∣x∣=x|x| = x if x≥0x \ge 0 and ∣x∣=−x|x| = -x if x<0x < 0.
  • For a complex number a+bia+bi, ∣a+bi∣=a2+b2|a+bi| = \sqrt{a^2+b^2}, its distance from the origin.
  • Always non-negative, with ∣x∣=0|x| = 0 exactly at x=0x = 0.
  • Satisfies the triangle inequality ∣a+b∣≤∣a∣+∣b∣|a+b| \le |a| + |b|.
  • compute-engine doesn't factor constants out of a symbolic argument -- ∣−3x∣|-3x| stays as written rather than simplifying to 3∣x∣3|x|.

Examples

2 more kept as data, checked against the oracles
Basic #
live ↗
In∣−5∣\vert-5\vertOut55
live ↗
In∣5∣\vert5\vertOut55

0 is the only value with ∣x∣=0|x| = 0

live ↗
In∣0∣\vert0\vertOut00
live ↗
In∣−72∣\vert-\frac{7}{2}\vertOut72\frac{7}{2}

The modulus of a complex number: ∣3+4i∣=32+42|3+4i| = \sqrt{3^2+4^2}

live ↗
In∣3+4i∣\vert3+4i\vertOut55

Threads element-wise over a list

live ↗
In∣[−1,2,−3]∣\vert\bigl\lbrack-1, 2, -3\bigr\rbrack\vertOut[1,2,3]\bigl\lbrack1, 2, 3\bigr\rbrack
live ↗
In∣−2.5∣\vert-2.5\vertOut2.52.5

The modulus of a complex number with approximate parts

live ↗
In∣1.4+2.3i∣\vert1.4+2.3i\vertOut2.692 582 403 567 252 015 632.692\,582\,403\,567\,252\,015\,63
Scope #

Threads over a matrix, entry by entry

live ↗
In∣[[12,−1],[−53,12]]∣\vert\bigl\lbrack\bigl\lbrack\frac{1}{2}, -1\bigr\rbrack, \bigl\lbrack-\frac{5}{3}, \frac{1}{2}\bigr\rbrack\bigr\rbrack\vertOut[[12,1],[53,12]]\bigl\lbrack\bigl\lbrack\frac{1}{2}, 1\bigr\rbrack, \bigl\lbrack\frac{5}{3}, \frac{1}{2}\bigr\rbrack\bigr\rbrack

Exact numeric constants

live ↗
In∣−π∣\vert-π\vertOutππ

An exact complex number gives an exact radical

live ↗
In∣1+i∣\vert1+i\vertOut2\sqrt{2}
live ↗
In∣i∣\vert i\vertOut11

eiπ/3e^{i\pi/3} lies on the unit circle

live ↗
In∣eiπ3∣\vert e^{\frac{i π}{3}}\vertOut11
live ↗
In∣−∞∣\vert-∞\vertOut∞∞

Complex infinity has infinite magnitude in every direction

live ↗
In∣∞~∣\vert\tilde∞\vertOut∞∞

An Interval maps to the interval of absolute values, [0,5][0, 5]

live ↗
In∣Interval(−3,5)∣\vert\mathrm{Interval}(-3, 5)\vertOutInterval(0,5)\mathrm{Interval}(0, 5)

Decides the sign of an exact numeric expression and gives 2−22-\sqrt{2}

live ↗
In∣2−2∣\vert\sqrt{2}-2\vertOut2−22-\sqrt{2}

Twenty-five digits of the modulus of a complex constant

live ↗
InN(∣π+iG⁡∣,25)N(\vert π+i\operatorname{G}\vert, 25)Out3.272 399 329 361 528 960 349 0143.272\,399\,329\,361\,528\,960\,349\,014

Applied to a matrix as a matrix function, not entry by entry

live ↗
InFullSimplify(MatrixFunction(Abs,[[1/2,−1],[−5/3,1/2]]))\mathrm{FullSimplify}(\mathrm{MatrixFunction}(\mathrm{Abs}, \bigl\lbrack\bigl\lbrack1/2, -1\bigr\rbrack, \bigl\lbrack-5/3, 1/2\bigr\rbrack\bigr\rbrack))Out[[153,−151/210],[−151/26,153]]\bigl\lbrack\bigl\lbrack\frac{\sqrt{15}}{3}, -\frac{15^{1/2}}{10}\bigr\rbrack, \bigl\lbrack-\frac{15^{1/2}}{6}, \frac{\sqrt{15}}{3}\bigr\rbrack\bigr\rbrack

The modulus of an infinite real is infinite

live ↗
In∣∞∣\vert∞\vertOut∞∞

A directed infinity still has infinite modulus

live ↗
In∣∞i∣\vert∞i\vertOut∞∞

With the assumption on xx, the call still stays unexpanded

live ↗
InPiecewiseExpand(∣ix∣,−2<x<2)\mathrm{PiecewiseExpand}(\vert i x\vert, -2\lt x\lt2)Out∣ix∣\vert i x\vert

Treating xx as real, ∣x∣=x2|x| = \sqrt{x^2}

live ↗
InComplexExpand(∣x∣)\mathrm{ComplexExpand}(\vert x\vert)Outx2\sqrt{x^2}

Real and imaginary parts give ∣x+iy∣=x2+y2|x+iy| = \sqrt{x^2+y^2}

live ↗
InComplexExpand(∣x+iy∣)\mathrm{ComplexExpand}(\vert x+i y\vert)Outx2+y2\sqrt{x^2+y^2}
live ↗
InAbs′(x)\mathrm{Abs}^{\prime}(x)Outsgn(x)\mathrm{sgn}(x)
Applications #

The gap between two temperatures, 70° and 95°, regardless of which is higher

live ↗
In∣70−95∣\vert70-95\vertOut2525

The distance between the points 1+i1+i and 4+5i4+5i of the complex plane

live ↗
In∣(1+i)−(4+5i)∣\vert(1+i)-(4+5i)\vertOut55
Properties #

Even function: ∣−x∣=∣x∣|-x| = |x|

live ↗
In∣−8∣=∣8∣\vert-8\vert=\vert8\vertOutTrue\mathrm{True}

Triangle inequality: ∣a+b∣≤∣a∣+∣b∣|a+b| \le |a| + |b|

live ↗
In∣3−8∣≤∣3∣+∣−8∣\vert3-8\vert≤\vert3\vert+\vert-8\vertOutTrue\mathrm{True}

∣z∣2=zzˉ|z|^2 = z\bar{z}

live ↗
In∣3+4i∣2=(3+4i)3+4i‾\vert3+4i\vert^2=(3+4i)\overline{3+4i}OutTrue\mathrm{True}

Multiplicative: ∣ab∣=∣a∣ ∣b∣|ab| = |a|\,|b|

live ↗
In∣(1+2i)(3−i)∣=∣1+2i∣∣3−i∣\vert(1+2i)(3-i)\vert=\vert1+2i\vert\vert3-i\vertOutTrue\mathrm{True}

A positive real is its own modulus

live ↗
In∣1∣\vert1\vertOut11

Known value · Wolfram MathematicalFunctionData, Abs

A negative real flips sign

live ↗
In∣−1∣\vert-1\vertOut11

Known value · Wolfram MathematicalFunctionData, Abs

A pure imaginary unit has modulus 1

live ↗
In∣−i∣\vert-i\vertOut11

Known value · Wolfram MathematicalFunctionData, Abs

The Gaussian integer −1+i-1+i has modulus 2\sqrt2

live ↗
In∣−1+i∣\vert-1+i\vertOut2\sqrt{2}

Known value · Wolfram MathematicalFunctionData, Abs

Same modulus in the third quadrant

live ↗
In∣−1−i∣\vert-1-i\vertOut2\sqrt{2}

Known value · Wolfram MathematicalFunctionData, Abs

Same modulus in the fourth quadrant

live ↗
In∣1−i∣\vert1-i\vertOut2\sqrt{2}

Known value · Wolfram MathematicalFunctionData, Abs

The 30∘30^\circ right triangle gives exact modulus 2

live ↗
In∣3+i∣\vert\sqrt{3}+i\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Swapping the legs still gives 2

live ↗
In∣1+3i∣\vert1+\sqrt{3}i\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Second quadrant, still 2

live ↗
In∣3i−1∣\vert\sqrt{3}i-1\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Second quadrant with the legs swapped

live ↗
In∣i−3∣\vert i-\sqrt{3}\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Third quadrant, still 2

live ↗
In∣−i−3∣\vert-i-\sqrt{3}\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Written with nested negations, still exactly 2

live ↗
In∣−3i−1∣\vert-\sqrt{3}i-1\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Fourth quadrant with a negated imaginary part, still 2

live ↗
In∣1−3i∣\vert1-\sqrt{3}i\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

Fourth quadrant with the legs swapped

live ↗
In∣3−i∣\vert\sqrt{3}-i\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

A positive integer is its own modulus

live ↗
In∣2∣\vert2\vertOut22

Known value · Wolfram MathematicalFunctionData, Abs

live ↗
In∣12∣2\vert\frac{1}{2}\vert^2Out14\frac{1}{4}

Known value · Wolfram MathematicalFunctionData, Abs, Absolute square

live ↗
In∣2∣2\vert2\vert^2Out44

Known value · Wolfram MathematicalFunctionData, Abs, Absolute square

Possible issues #

Doesn't factor constants out of a symbolic argument: ∣−3x∣|-3x| stays as written rather than reducing to 3∣x∣3|x|

live ↗
In∣−3x∣\vert-3x\vertOut∣−3x∣\vert-3x\vert
About
Examples51
Checked againstWolfram Language 48 agree2 differ1 unevaluatedSageMath 40 agree2 differSymPy 46 agree1 differmpmath 23 agree1 differOscar 20 agreeJulia 37 agree3 errorRust 17 agree1 error
CrosswalkWikipedia ×2MathWorld ×2WikidataBritannicaDLMFFungrimFungrim entry ×57Wolfram LanguageSageMathSymPympmathOscarJuliaRust

Implementation

mappedoscarpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts

See also: Sign, Chop