({{, (RefLink[Sign, paclet:ref/Sign])[x]
gives -1, 0, or 1 depending on whether x is negative, zero, or positive. }})

OpenersNotesSection(Spacer1)Details

Mathematical function, suitable for both symbolic and numerical manipulation.

For non-zero complex numbers z, (RefLink[Sign, paclet:ref/Sign])[z] is defined as z/(RefLink[Abs, paclet:ref/Abs])[z].

(RefLink[Sign, paclet:ref/Sign]) tries various transformations in trying to determine the sign of symbolic expressions.

For exact numeric quantities, (RefLink[Sign, paclet:ref/Sign]) internally uses numerical approximations to establish its result. This process can be affected by the setting of the global variable (RefLink[$MaxExtraPrecision, paclet:ref/$MaxExtraPrecision]).

(RefLink[Sign, paclet:ref/Sign]) automatically threads over lists.

OpenersPrimaryExamplesSection(Spacer1)Examples  (44)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

Sign[-2.5]

Sign[2.5]

Sign[0]

(RefLink[Sign, paclet:ref/Sign]) threads element-wise over lists:

Sign[{-2,-1,0,1,2}]

Plot the (RefLink[Sign, paclet:ref/Sign]) function:

Plot[Sign[x],{x,-3,3}]

OpenersExampleSection1(Spacer1)Scope  (19)

OpenersExampleSubsection0(Spacer1)Numerical Evaluation  (4)

Evaluate numerically:

Sign[0.7]

Sign[Pi-E]

Complex number inputs:

Sign[1+I]

Sign[57.23-5I]

Evaluate to high precision:

N[Sign[E+Pi I],20]

Sign[123`20-456`20I]

For real inputs, the result is exact:

Sign[123`20]

Evaluate efficiently at high precision:

Sign[-7230`100+I]//Timing

Sign[-745453`100000+123456I];//Timing

OpenersExampleSubsection1(Spacer1)Specific Values   (5)

Values of (RefLink[Sign, paclet:ref/Sign]) at fixed points:

Table[Sign[n ],{n,{-2,-1/3,7/2,3}}]

Value at zero:

Sign[0]

Values at infinity:

Sign[{Infinity,-Infinity,ComplexInfinity, I Infinity}]

Evaluate symbolically:

PiecewiseExpand[Sign[x],-2<x<2]

Find a value of x for which the (Sign[x])==0:

xval=x/.First@Solve[Sign[x]==0,x]//Quiet

Plot[Sign[x],{x,-5,5},Epilog->{PointSize[Large],Red,Point[{xval,Sign[xval]}]},ExclusionsStyle->Dotted]

OpenersExampleSubsection2(Spacer1)Visualization  (5)

Plot (Abs[1+x]) on the real axis:

Plot[Sign[1+x],{x,-3,3}]

Plot the real and imaginary parts of the sgn(x+i) function:

ReImPlot[Sign[x+I],{x,-3,3},PlotTheme->"Detailed"]

Plot (RefLink[Sign, paclet:ref/Sign]) in the complex plane:

ComplexPlot[Sign[z],{z,-2-2I,2+2I}]

Visualize (RefLink[Sign, paclet:ref/Sign]) in three dimensions:

ComplexPlot3D[Sign[z],{z,-2-2I,2+2I},RegionFunction->Function[{z},Abs[z]≤2]]

Plot the real part of the sgn(x+i y) function:

ContourPlot[Re[Sign[x+I y]],{x,-3,3},{y,-3,3},Contours->24]

Plot the imaginary part of the sgn(x+i y) function:

ContourPlot[Im[Sign[x+I y]],{x,-3,3},{y,-3,3},Contours->24]

OpenersExampleSubsection3(Spacer1)Function Properties  (5)

Function domain of (RefLink[Sign, paclet:ref/Sign]):

FunctionDomain[Sign[x],x]

Domain for complex values:

FunctionDomain[Sign[x],x,Complexes]

Function range of (RefLink[Sign, paclet:ref/Sign]):

FunctionRange[Sign[x],x,y]

(RefLink[Sign, paclet:ref/Sign]) is an odd function:

Sign[-z]

(RefLink[Sign, paclet:ref/Sign]) has mirror symmetry (Sign[(Conjugate[z])])==(Conjugate[(Sign[z])]):

Sign[Conjugate[1+2I]]==Conjugate[Sign[1+2I]]

(RefLink[TraditionalForm, paclet:ref/TraditionalForm]) formatting:

Sign[x]//TraditionalForm

OpenersExampleSection2(Spacer1)Generalizations & Extensions  (3)

(RefLink[Sign, paclet:ref/Sign]) returns exact answers for exact numerical arguments:

Sign[Tan[10^9]]

(RefLink[Sign, paclet:ref/Sign]) threads element-wise over sparse arrays:

SparseArray[ {{1,1}->-6,{1,3}->I Pi,{3,3}->2,{4, 2}->u}]

Sign[%]

% // MatrixForm

Series expansions for real arguments:

Series[Sign[x],{x,0, 5}, Assumptions -> x∈Reals]

OpenersExampleSection3(Spacer1)Applications  (2)

Plot the real and imaginary parts of (RefLink[Sign, paclet:ref/Sign]) over the complex plane:

{Plot3D[Re[Sign[x+I y]],{x,-1,1},{y,-1,1}],Plot3D[Im[Sign[x+I y]],{x,-1,1},{y,-1,1}]}

Define Rademacher functions:

r[n_,x_]:=Sign[Sin[2^n Pi x]]

Plot (vertically shifted) Rademacher functions:

Plot[Evaluate[Table[r[n,x]+n/5,{n,5}]],{x,-Pi,Pi},Exclusions->Sin[2^5 Pi x]==0]

Check orthogonality over the unit interval:

Table[Integrate[r[n1,x]r[n2,x],{x,0,1}],{n1,3},{n2,3}]//FullSimplify

OpenersExampleSection4(Spacer1)Properties & Relations  (10)

(RefLink[Sign, paclet:ref/Sign]) with simple arguments automatically evaluates to simpler form:

Sign[1/z]

Sign[z ^2]

Sign[Exp[z]]

(RefLink[Sign, paclet:ref/Sign]) is idempotent:

Sign[Sign[z]]

Use (RefLink[FullSimplify, paclet:ref/FullSimplify]) to simplify expressions involving (RefLink[Sign, paclet:ref/Sign]):

FullSimplify[Sign[a b]-Sign[a] Sign[b]+Sign[a]-Abs[a]/a]

Simplify under additional assumptions:

Simplify[Sign[z]+z/Abs[z],z>0]

Assume real-valued variables:

ComplexExpand[Sign[(z^a)],{z}]

Use (RefLink[Sign, paclet:ref/Sign]) as a target function for (RefLink[ComplexExpand, paclet:ref/ComplexExpand]):

ComplexExpand[Re[ArcSin[x+I y]],TargetFunctions->Sign]

Use (RefLink[Sign, paclet:ref/Sign]) in definite integration:

Integrate[Sign[Sin[x]],{x,0,2}]

Integrate along a line in the complex plane, symbolically and numerically:

Integrate[Sign[x^2],{x,-2+I,Pi+I}]

N[%]

NIntegrate[Sign[x^2],{x,-2+I,Pi+I}]

For complex values, the indefinite integral is path dependent:

Integrate[Sign[x],x]

The indefinite integral for real values:

Integrate[Sign[x],x,Assumptions->x∈Reals]

Use in integral transforms:

FourierTransform[Sign[y],y,x]

LaplaceTransform[Sign[y],y,x]

Obtain (RefLink[Sign, paclet:ref/Sign]) from integrals and limits:

Integrate[Sin[a x]/x,{x,-Infinity,Infinity},Assumptions->a∈Reals]

Limit[2ArcTan[a x],a->Infinity,Assumptions->x∈Reals]

FullSimplify[%,Assumptions->x∈Reals]

Convert to (RefLink[Piecewise, paclet:ref/Piecewise]):

PiecewiseExpand[Sign[x]Sign[1-x],x∈Reals]

De-nest:

PiecewiseExpand[Sign[2-x+Sign[2-x^3]^3],x∈Reals]

OpenersExampleSection5(Spacer1)Possible Issues  (4)

For purely real or imaginary approximate arguments, (RefLink[Sign, paclet:ref/Sign]) returns exact answers:

Sign[1.3]

Sign[1.3 I]

For general complex arguments, (RefLink[Sign, paclet:ref/Sign]) tracks the precision of the input:

Sign[1.5+I]

(RefLink[Sign, paclet:ref/Sign]) can stay unevaluated for numeric arguments:

Sign[(-1-2 E-E^2+(1+E)^2)]

Simplify[%]

Machine-precision numerical evaluation of (RefLink[Sign, paclet:ref/Sign]) can give wrong results:

Sign[(-1-2 E-E^2+(1+E)^2)+10^-100]

N[%]

Arbitrary-precision evaluation gives the correct result:

N[%%,250]

A larger setting for (RefLink[$MaxExtraPrecision, paclet:ref/$MaxExtraPrecision]) can be needed:

Block[{$MaxExtraPrecision=10000},N[Sign[(-1-2 E-E^2+(1+E)^2)+10^-100],20]]

(RefLink[Sign, paclet:ref/Sign]) applied to a matrix does not give the matrix sign function:

Sign[{{1,2},{-2,1}}]

OpenersExampleSection6(Spacer1)Neat Examples  (3)

Form repeated convolution integrals starting with a symmetric product of three sign functions:

Convolution[f_,g_,x_]:=Module[{y},Simplify[Integrate[(f/.x->x-y)(g/.x->y),{y,-1,1},Assumptions->x∈Reals],x∈Reals]]

NestList[Convolution[#,Sign[x]Sign[x+1]Sign[1-x],x]&,Sign[x]Sign[x+1]Sign[1-x],3]

Plot[Evaluate[%],{x,-3,3}]

Approximate (RefLink[Sign, paclet:ref/Sign]) through a generalized Fourier series:

sign[n_,x_]:=Sum[(-1)^k HermiteH[2k+1,x]/(2^(2k)(2k+1)k!),{k,0,n}]/Pi

Plot[Evaluate[Table[sign[n,x],{n,20}]],{x,-2,2}]

Calculate rational approximations of (RefLink[Sign, paclet:ref/Sign]):

Table[Tanh[2 n ArcTanh[1/x]],{n,4}]//FunctionExpand//Together//Factor

Plot[Evaluate[%],{x,-10,10}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RealSign, paclet:ref/RealSign])  ▪  (RefLink[RealAbs, paclet:ref/RealAbs])  ▪  (RefLink[Abs, paclet:ref/Abs])  ▪  (RefLink[Arg, paclet:ref/Arg])  ▪  (RefLink[UnitStep, paclet:ref/UnitStep])  ▪  (RefLink[Piecewise, paclet:ref/Piecewise])  ▪  (RefLink[Clip, paclet:ref/Clip])  ▪  (RefLink[Positive, paclet:ref/Positive])  ▪  (RefLink[Negative, paclet:ref/Negative])  ▪  (RefLink[NonNegative, paclet:ref/NonNegative])  ▪  (RefLink[Greater, paclet:ref/Greater])  ▪  (RefLink[Simplify, paclet:ref/Simplify])  ▪  (RefLink[Assumptions, paclet:ref/Assumptions])  ▪  (RefLink[Normalize, paclet:ref/Normalize])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Numerical Functions, paclet:tutorial/NumericalFunctions])}, {▪(RefLinkPlain[Piecewise Functions, paclet:tutorial/PiecewiseFunctions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Complex Numbers, paclet:guide/ComplexNumbers])}, {▪(RefLinkPlain[Numerical Functions, paclet:guide/NumericalFunctions])}, {▪(RefLinkPlain[Conditionals, paclet:guide/Conditionals])}, {▪(RefLinkPlain[Representation of Numbers, paclet:guide/RepresentationOfNumbers])}, {▪(RefLinkPlain[Angles and Polar Coordinates, paclet:guide/AnglesAndPolarCoordinates])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-MathWorld.png(Spacer1)MathWorld, http://mathworld.wolfram.com/Sign.html])}, {DocumentationFooterIconsRelatedLinks-Functions.png(Spacer1)The Wolfram Functions Site}})}})