Skip to content

Sign ​

The sign of x: -1, 0, or 1 for negative, zero, or positive x.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaSign functionMathWorldSignWikidataQ236813DLMFfront/introduction.common.t2.r18FungrimSign✓Fungrim entryFindStatSt000037via Permutation✓Wolfram LanguageSign!
Sign(x)-1, 0, or 1 for negative, zero, or positive real x; z/∣z∣z/|z| for complex z.
SageMathenumeratio_sign(x)SymPysign(x)mpmathsign(x)Oscarsign(x)Juliaenumeratio_sign(x)Rustsignum(x)
Sign(p)A permutation's sign: 1 when it has an even number of inversions, -1 when odd (FindStat St000037).
SageMathenumeratio_sign(p)SymPysign(p)mpmathsign(p)Oscarsign(p)Juliaenumeratio_sign(p)Rustsignum(p)
Typed signatures
TypePackageApplies
(complex | permutation | signed_infinity | ~oo) -> complex | numbercombinatoricsreplaces analyticalways
(complex | signed_infinity | ~oo) -> complexanalyticreplaces compute-engineon Around, CenteredInterval, Interval
(complex | signed_infinity | ~oo) -> complexcompute-enginealways

Domain: Arithmetic

Details
  • sign⁡(x)=−1,0,1\operatorname{sign}(x) = -1, 0, 1 for x<0x < 0, x=0x = 0, x>0x > 0 respectively.
  • For a complex number, sign⁡(z)=z/∣z∣\operatorname{sign}(z) = z/|z|, the unit complex number pointing toward z. See Abs.
  • Recovers the original magnitude: x=∣x∣ sign⁡(x)x = |x|\,\operatorname{sign}(x).
  • sign⁡(±∞)=±1\operatorname{sign}(\pm\infty) = \pm 1, but sign⁡(NaN)\operatorname{sign}(\mathrm{NaN}) propagates as NaN rather than 0.

Definition

Epsil, as the implementation runs it.

on Permutation, over _x

1 if Length(_x) < 2 else (-1) ^ Sum(Map(
                                         Function(Count(Filter(
                                                                Range(
                                                                       i + 1,
                                                                       Length(_x),
                                                                     ),
                                                                Function(_x[i] >
                                                                         _x[j], j),
                                                              )), i),
                                         Range(1, Length(_x)),
                                       ))

Examples

1 more kept as data, checked against the oracles
Basic #
live ↗
Insgn(−3)\mathrm{sgn}(-3)Out−1-1
live ↗
Insgn(3)\mathrm{sgn}(3)Out11

Zero is its own sign

live ↗
Insgn(0)\mathrm{sgn}(0)Out00
live ↗
Insgn(−12)\mathrm{sgn}(-\frac{1}{2})Out−1-1

The unit complex number pointing the same direction as 3+4i3+4i

live ↗
Insgn(3+4i)\mathrm{sgn}(3+4i)Out35+45i\frac{3}{5}+\frac{4}{5}i

Threads element-wise over a list

live ↗
Insgn([−3,0,7])\mathrm{sgn}(\bigl\lbrack-3, 0, 7\bigr\rbrack)Out[−1,0,1]\bigl\lbrack-1, 0, 1\bigr\rbrack
live ↗
Insgn(−2.5)\mathrm{sgn}(-2.5)Out−1-1
live ↗
Insgn(3.14)\mathrm{sgn}(3.14)Out11

A complex number with approximate parts

live ↗
Insgn(1.4+2.3i)\mathrm{sgn}(1.4+2.3i)Out0.519 946 946 895 745 216 810 2+0.854 198 555 614 438 5i0.519\,946\,946\,895\,745\,216\,810\,2+0.854\,198\,555\,614\,438\,5i
Scope #

An exact complex argument comes back exact: sign(1+i)=(1+i)/2\mathrm{sign}(1+i) = (1+i)/\sqrt{2}

live ↗
Insgn(1+i)\mathrm{sgn}(1+i)Out22+22i\frac{\sqrt{2}}{2}+\frac{\sqrt{2}}{2}i

Threads over a matrix, entry by entry

live ↗
Insgn([[12,−1],[−53,12]])\mathrm{sgn}(\bigl\lbrack\bigl\lbrack\frac{1}{2}, -1\bigr\rbrack, \bigl\lbrack-\frac{5}{3}, \frac{1}{2}\bigr\rbrack\bigr\rbrack)Out[[1,−1],[−1,1]]\bigl\lbrack\bigl\lbrack1, -1\bigr\rbrack, \bigl\lbrack-1, 1\bigr\rbrack\bigr\rbrack

Exact numeric constants

live ↗
Insgn(π)\mathrm{sgn}(π)Out11
live ↗
Insgn(−e)\mathrm{sgn}(-e)Out−1-1
live ↗
Insgn(i)\mathrm{sgn}(i)Outii
live ↗
Insgn(∞)\mathrm{sgn}(∞)Out11

An Interval entirely above 0 has sign 1

live ↗
Insgn(Interval(1,3))\mathrm{sgn}(\mathrm{Interval}(1, 3))Out11

Decides the sign of the exact number 2−2\sqrt{2}-2 by certified bignum evaluation at increasing precision

live ↗
Insgn(2−2)\mathrm{sgn}(\sqrt{2}-2)Out−1-1

2−22-\sqrt{2} is the same certified decision, the other way

live ↗
Insgn(2−2)\mathrm{sgn}(2-\sqrt{2})Out11

A positive number has sign 1

live ↗
Insgn(123)\mathrm{sgn}(123)Out11

For a complex number it is z/∣z∣z/|z|, here with a radical

live ↗
Insgn(123−456i)\mathrm{sgn}(123-456i)Out4124 78524 785−15224 78524 785i\frac{41\sqrt{24\,785}}{24\,785}-\frac{152\sqrt{24\,785}}{24\,785}i

A matrix function with exact eigenvalues, giving a zero diagonal

live ↗
InFullSimplify(MatrixFunction(Sign,[[1/2,−1],[−5/3,1/2]]))\mathrm{FullSimplify}(\mathrm{MatrixFunction}(\mathrm{Sign}, \bigl\lbrack\bigl\lbrack1/2, -1\bigr\rbrack, \bigl\lbrack-5/3, 1/2\bigr\rbrack\bigr\rbrack))Out[[0,−151/25],[−151/23,0]]\bigl\lbrack\bigl\lbrack0, -\frac{15^{1/2}}{5}\bigr\rbrack, \bigl\lbrack-\frac{15^{1/2}}{3}, 0\bigr\rbrack\bigr\rbrack

On (−2,2)(-2,2) it is a piecewise function with 0 at the origin

live ↗
InPiecewiseExpand(sgn(x),−2<x<2)\mathrm{PiecewiseExpand}(\mathrm{sgn}(x), -2\lt x\lt2)OutPiecewise([[−1,x<0],[1,0<x]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack-1, x\lt0\bigr\rbrack, \bigl\lbrack1, 0\lt x\bigr\rbrack\bigr\rbrack, 0)

Sign commutes with conjugation

live ↗
Insgn(1+2i‾)=sgn(1+2i)‾\mathrm{sgn}(\overline{1+2i})=\overline{\mathrm{sgn}(1+2i)}OutTrue\mathrm{True}
live ↗
Indsgn(x)dx\frac{\mathrm{d}\mathrm{sgn}(x)}{\mathrm{d}x}Out00
live ↗
Insgn(∞i)\mathrm{sgn}(∞i)OutIndeterminate⁡\operatorname{Indeterminate}
live ↗
InN(sgn(e+iπ),20)N(\mathrm{sgn}(e+i π), 20)Out0.654 321 120 736 689 028 19+0.756 216 814 781 239 322 47i0.654\,321\,120\,736\,689\,028\,19+0.756\,216\,814\,781\,239\,322\,47i
Applications #

Tells you the temperature dropped, but not by how much -- for that, see Abs

live ↗
Insgn(70−95)\mathrm{sgn}(70-95)Out−1-1
Properties #

sign⁡(z)=z/∣z∣\operatorname{sign}(z) = z/|z|. See Abs

live ↗
Insgn(3+4i)=3+4i∣3+4i∣\mathrm{sgn}(3+4i)=\frac{3+4i}{\vert3+4i\vert}OutTrue\mathrm{True}

x⋅sign⁡(x)=∣x∣x \cdot \operatorname{sign}(x) = |x|, here at x=−5x = -5

live ↗
In−5sgn(−5)=∣−5∣-5\mathrm{sgn}(-5)=\vert-5\vertOutTrue\mathrm{True}

The sign of a nonzero complex number lies on the unit circle

live ↗
In∣sgn(3+4i)∣=1\vert\mathrm{sgn}(3+4i)\vert=1OutTrue\mathrm{True}

Positive 1 has sign 1

live ↗
Insgn(1)\mathrm{sgn}(1)Out11

Known value · Wolfram MathematicalFunctionData, Sign

Negative 1 gives −1-1

live ↗
Insgn(−1)\mathrm{sgn}(-1)Out−1-1

Known value · Wolfram MathematicalFunctionData, Sign

A unit imaginary stays −i-i

live ↗
Insgn(−i)\mathrm{sgn}(-i)Out−i-i

Known value · Wolfram MathematicalFunctionData, Sign

The second quadrant gives (−1+i)/2(-1+i)/\sqrt2

live ↗
Insgn(−1+i)\mathrm{sgn}(-1+i)Out−22+22i-\frac{\sqrt{2}}{2}+\frac{\sqrt{2}}{2}i

Known value · Wolfram MathematicalFunctionData, Sign

The third quadrant gives the unit vector at 225∘225^\circ

live ↗
Insgn(−1−i)\mathrm{sgn}(-1-i)Out−22−22i-\frac{\sqrt{2}}{2}-\frac{\sqrt{2}}{2}i

Known value · Wolfram MathematicalFunctionData, Sign

The fourth quadrant, (1−i)/2(1-i)/\sqrt2

live ↗
Insgn(1−i)\mathrm{sgn}(1-i)Out22−22i\frac{\sqrt{2}}{2}-\frac{\sqrt{2}}{2}i

Known value · Wolfram MathematicalFunctionData, Sign

Positive integers always map to 1

live ↗
Insgn(2)\mathrm{sgn}(2)Out11

Known value · Wolfram MathematicalFunctionData, Sign

FindStat's value for [1]

live ↗
InCombinatorialStat(Permutation⁡([1]),Sign)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1]), \text{Sign})Out11

Known value · FindStat St000037

FindStat's value for [1,2]

live ↗
InCombinatorialStat(Permutation⁡([1,2]),Sign)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([1, 2]), \text{Sign})Out11

Known value · FindStat St000037

FindStat's value for [2,1]

live ↗
InCombinatorialStat(Permutation⁡([2,1]),Sign)\mathrm{CombinatorialStat}({\operatorname{Permutation}}([2, 1]), \text{Sign})Out−1-1

Known value · FindStat St000037

Possible issues #

NaN propagates rather than being treated as 0

live ↗
Insgn(NaN⁡)\mathrm{sgn}(\operatorname{NaN})OutNaN⁡\operatorname{NaN}

Sign(ComplexInfinity) is Indeterminate: z/|z| needs a direction, and the undirected infinity has none

live ↗
Insgn(∞~)\mathrm{sgn}(\tilde∞)OutIndeterminate⁡\operatorname{Indeterminate}

Known value · Wolfram Sign[ComplexInfinity]

About
Examples43
Checked againstWolfram Language 38 agree2 differSageMath 36 agree2 differ2 unevaluatedSymPy 35 agree2 differ2 unevaluatedmpmath 35 agreeOscar 22 agreeJulia 33 agree2 errorRust 18 agree
CrosswalkWikipediaMathWorldWikidataDLMFFungrimFungrim entry ×23FindStatWolfram LanguageSageMathSymPympmathOscarJuliaRust

Implementation

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

See also: Abs, Negate