Index

AAbsAllAlternativesAndAnyAnyNullSequenceAnySequenceApplyArCoshArSinhArTanhArcCosArcSinArcTanArgAttributes

BBinaryFormatBinomialBoole

CCalculateCeilClearComplementComplexComplexInfinityComplexOverflowComplexUnderflowCompoundConditionConjugateCosCosh

DDefineDefineDelayedDefinitionsDepthDigitBaseDirectedInfinityDivide

EEEndiannessEqualEulerMascheroniExpExpandExpression

FFactorialFalseFibonacciFlatFloorFunction

GGoldenAngleGoldenRatioGreaterGreaterEqual

HHead

IIIfImIndeterminateInfinityIntegerInternalFormIntersectionIterate

JJoin

LLengthLessLessEqualListListableLockedLog

MMachinePrecisionMapMatchingMaxMinMinusMod

NNotNull

OOptionalOptionsOrOrderOrderlessOutputOverflow

PPartPartitionPatternPiPlusPowerPrecisionPrintProtected

RRandomRationalReRealReplaceRuleRuleDelayed

SSameScopeSelectSequenceSignSinSinhSlotSortSpanSqrtStringSubDefineSubDefineDelayedSubtractSymbol

TTanTanhTimesToIntegerToRealToStringToSymbolTrueTrunc

UUnderflowUnequalUnion

XXor

Absfunction

Syntax

Abs(z)
gives the absolute value of the (complex) number z.

Details

Examples

Abs(-123)123

Abs(1.2 + 3.4*I)3.60555

Abs(3+4*I)5

Abs uses the numerical estimation of an expression to decide about the sign of the result.

Abs(Sin(4))-Sin(4)

-Sin(4) // Calculate0.756802

Simplifications are performed if possible.

Abs(-2*x)2*Abs(x)

Abs(x^3)Abs(x)^3

See also

Arg Sign

Allconstant

Syntax

All
can be used to specifies all elements.

Details

Examples

Part( {{a1,a2}, {b1,b2}, {c1,c2}} , All, 1 ){a1, b1, c1}

{"Hello", "World!"}[All, 1]{"H", "W"}

See also

Part[…]

Alternatives|function

Syntax

Alternatives(pat1, pat2, … )pat1 | pat2 |
is a pattern object that represents any pattern pati during a pattern matching.

Details

Examples

Matching( b, a|b )True

Alternatives can be used for replacements:

Replace( {a, b, c, a, b, c} , a|b -> 0 ){0, 0, c, 0, 0, c}

A definition of a function which excapts only integer and rational numbers.

f( x?Rational | x?Integer ) := x^2; { f(2), f(1.0), f(1/2) }{4, f(1.0), 1/4}

See also

Pattern Condition/? Optional:

And&&function

Syntax

And(bool1, bool2, … )bool1 && bool2 &&
gives the logical AND of booli.
And(int1, int2, … )int1 && int2 &&
gives the binary AND of the integers inti.
And(str1, str2, … )str1 && str2 &&
gives the binary AND of the strings stri.

Details

Examples

True && FalseFalse

12 && 74

'BINARY' && 'abc''@@B'

And stops to evaluate its arguments if False occurs. In the following case the second Print is not evaluated.

(Print(1);True) && False && (Print(2);True)1False

Expressions which are evaluated into True will be erased.

2==2 && a==5 && b==10 && Truea == 5 && b == 10

See also

Or|| Xor!! Not! False True

Any?function

Syntax

Any?
is a pattern object that matches to any object.
Any(head)?head
matches to any object having the head head.

Details

Examples

Matching( f(123), Any )True

Matching( f(123), Any(f) )True

Any can used in rules for replacements.

Replace( { 1, 1.0, 1/2, 4 } , ?Integer -> x ){x, 1.0, 1/2, x}

Any can used in an assignment as a pattern for an argument.

f(?Real) = "real"; { f(1), f(1.0), f(2^0.5) }{f(1), "real", "real"}

Possible Issues

In functions like Plus+ and Times*, Any does not differ from other symbols and is transformed.

? + ? Matching( a + b, ? + ? ) Matching( a + b, x? + y? )2*? False True

See also

AnySequence?? AnyNullSequence??? Pattern Head

AnyNullSequence???function

Syntax

AnyNullSequence???
is a pattern object that matches to a sequence of any objects, even an empty sequence of no object.
AnyNullSequence(head)???head
matches to a sequence of objects all having the head head, or an empty sequence.

Details

Examples

Matching( f(), f(AnyNullSequence) )True

Matching( f(x, y), f(AnyNullSequence(Symbol)) )True

Matching( f(), f(AnyNullSequence(Symbol)) )True

AnyNullSequence can used in an assignment as a pattern for a sequence of arguments.

f(???Real) = "reals or nothing"; { f(), f(1.0), f(1.0, 2.0), f(1) }{"reals or nothing", "reals or nothing", "reals or nothing", f(1)}

See also

Any? AnySequence?? Pattern Head

AnySequence??function

Syntax

AnySequence??
is a pattern object that matches to a sequence of any objects.
AnySequence(head)??head
matches to a sequence of objects all having the head head.

Details

Examples

Matching( f(1, 2, 3), f(AnySequence) )True

Matching( f(x, y), f(AnySequence(Symbol)) )True

AnySequence can used in an assignment as a pattern for a sequence of arguments.

f(??Real) = "reals"; { f(1), f(1.0), f(1.0, 2.0), f(1, 0.5) }{f(1), "reals", "reals", f(1, 0.5)}

See also

Any? AnyNullSequence??? Pattern Head

Applyfunction

Syntax

Apply(h, exp)
replaces the head of expression exp with h.

Details

Examples

Apply(g, f(1, a, x))g(1, a, x)

Apply(Plus, {2, 3, 4})9

Apply(Times, a+b+c)a*b*c

Apply(f, a+b)f(a, b)

Apply will process anonymous function as well:

Apply( {#1^#2, #2^#1} & , {3, 2} ){9, 8}

See also

Map/@ Head

ArcCosfunction

Syntax

ArcCos(z)
gives the arcus cosine of z.

Details

Examples

ArcCos(0.5)1.0472

Calculate(ArcCos(1/2), 70)1.047197551196597746154214461093167628065723133125035273658314864102605

ArcCos(1.2)0.622363*I

ArcCos(2.0+3.0*I)1.00014-1.98339*I

Particular arguments and their result:

ArcCos(-1)Pi

ArcCos(0)1/2*Pi

ArcCos(1/2)1/3*Pi

ArcCos(1)0

See also

Cos ArcSin ArcTan ArCosh

ArCoshfunction

Syntax

ArCosh(z)
gives the area hyperbolic cosine of z.

Details

Examples

ArCosh(1.5)0.962424

Calculate(ArCosh(3/2), 70)0.9624236501192068949955178268487368462703686687713210393220363376803277

ArCosh(0.2)1.36944*I

ArCosh(2.0+3.0*I)1.98339+1.00014*I

Particular arguments and their result:

ArCosh(1)0

ArCosh(-1)I*Pi

ArCosh(0)1/2*I*Pi

ArCosh(1/2)1/3*I*Pi

See also

Cosh ArSinh ArTanh ArcCos

ArcSinfunction

Syntax

ArcSin(z)
gives the arcus sine of z.

Details

Examples

ArcSin(0.5)0.523599

Calculate(ArcSin(1/2), 70)0.5235987755982988730771072305465838140328615665625176368291574320513027

ArcSin(1.2)1.5708-0.622363*I

ArcSin(2.0+3.0*I)0.570653+1.98339*I

Particular arguments and their result:

ArcSin(-1)-1/2*Pi

ArcSin(0)0

ArcSin(1/2)1/6*Pi

ArcSin(1)1/2*Pi

See also

Sin ArcCos ArcTan ArSinh

ArcTanfunction

Syntax

ArcTan(z)
gives the arcus tangent of z.
ArcTan(x,y)
gives the arcus tangent of y/x, taking into account the quadrant of the point (x, y).

Details

Examples

ArcTan(2.0)1.10715

Calculate(ArcTan(2), 70)1.107148717794090503017065460178537040070047645401432646676539207433710

ArcTan(2.0+3.0*I)1.40992+0.229073*I

Particular arguments and their result:

ArcTan(0)0

ArcTan(1)1/4*Pi

ArcTan(3^(1/2))1/3*Pi

ArcTan(Infinity)1/2*Pi

ArcTan with two arguments:

ArcTan(1, 1)1/4*Pi

ArcTan(-1, 0)Pi

ArcTan(-1.0, -3.0)-1.89255

See also

Tan ArcCos ArcSin ArTanh

Argfunction

Syntax

Arg(z)
gives the argument of the (complex) number z.

Details

Examples

Arg(1.2 + 3.4*I)1.2315

Arg(-123)Pi

Arg(1+I)1/4*Pi

Arg(2.5)0

Simplifications are performed if possible.

Arg(-2*x)Arg(-x)

Arg(x^(1/3))1/3*Arg(x)

Arg(Abs(z))0

See also

Abs Sign

ArSinhfunction

Syntax

ArSinh(z)
gives the area hyperbolic sine of z.

Details

Examples

ArSinh(1.5)1.19476

Calculate(ArSinh(3/2), 70)1.194763217287109304111930828519090523536162075153005429270680299461324

ArSinh(2.0+3.0*I)1.96864+0.964659*I

Particular arguments and their result:

ArSinh(0)0

ArSinh(1*I)1/2*I*Pi

ArSinh(1/2*I)1/6*I*Pi

See also

Sinh ArCosh ArTanh ArcSin

ArTanhfunction

Syntax

ArTanh(z)
gives the area hyperbolic tangent of z.

Details

Examples

ArTanh(0.5)0.549306

Calculate(ArTanh(1/2), 70)0.5493061443340548456976226184612628523237452789113747258673471668187471

ArTanh(1.5)0.804719-1.5708*I

ArTanh(2.0+3.0*I)0.146947+1.33897*I

Particular arguments and their result:

ArTanh(0)0

ArTanh(1)-Infinity

ArTanh(I)1/4*I*Pi

ArTanh(-Infinity)1/2*I*Pi

See also

Tanh ArCosh ArTanh ArcTan

Attributesfunction

Syntax

Attributes(s)
gives a list of all set attributes for symbol s.
Attributes(s) = attr
sets the attribute attr for symbol s.
Attributes(s) = {attr1, attr2, …}
sets the attributes attri for symbol s.

Details

Examples

Attributes(Plus){Flat, Listable, Locked, NumericFunction, OneIdentity, Orderless, Protected}

Define an orderless and flat expression:

f(1, z, f(a, 2))f(1, z, f(a, 2))

Attributes(f) = {Orderless, Flat}{Orderless, Flat}

f(1, z, f(a, 2))f(1, 2, a, z)

Define a function that threads over lists:

Attributes(g) = Listable; g(x?) := "<" ~ ToString(x) ~ ">"

g(7)"<7>"

g({-1,2,a}){"<-1>", "<2>", "<a>"}

See also

Flat Orderless Protected Locked Listable

BinaryFormatoption

Syntax

BinaryFormat -> type
is an option to define the binary format for numeric and string representations.

Details

Examples

Handling different number formats:

ToString(12345, BinaryFormat->"Integer16") ToString(3.1415, BinaryFormat->"double")'90' 'o\x12\x83ÀÊ!\t@'

ToInteger('ÿ', BinaryFormat->"Integer8") ToInteger('ÿ', BinaryFormat->"UnsignedInteger8")-1 255

Handling different string formats:

ToString("yä€𝄞", BinaryFormat->"ANSI") ToString("yä€𝄞", BinaryFormat->"UTF8") ToString("yä€𝄞", BinaryFormat->"UTF16", Endianness->-1) ToString("yä€𝄞", BinaryFormat->"UTF16", Endianness->1) ToString("yä€𝄞", BinaryFormat->"UTF32")'yä\x80?' 'yäâ\x82¬ð\x9D\x84\x9E' 'y\0ä\0¬ 4Ø\x1EÝ' '\0y\0ä ¬Ø4Ý\x1E' 'y\0\0\0ä\0\0\0¬ \0\0\x1EÑ\x01\0'

ToString('yäâ\x82¬ð\x9D\x84\x9E', BinaryFormat->"UTF8") ToString('\0y\0ä ¬Ø4Ý\x1E', BinaryFormat->"UTF16", Endianness->1)"yä€𝄞" "yä€𝄞"

Possible Issues

An error is given, if the format is insufficient for the whole number or its precision.

ToString(12345, BinaryFormat->"Integer8") ToString(12345, BinaryFormat->"float16")ToString.InsufficientBinaryFormat: Specified format Integer8 is insufficient to represent the whole number 12345 or its precision.ToString.InsufficientBinaryFormat: Specified format float16 is insufficient to represent the whole number 12345 or its precision.'9' '\ar'

ToReal('\ar', BinaryFormat->"float16")12344.0

See also

ToString ToInteger ToReal Endianness

Binomialfunction

Syntax

Binomial(n, k)
gives the binomial coefficient n choose k.

Details

Examples

Binomial(49, 6)13983816

Binomial(365, 31)884481797664650696626118102000059032909354320

Binomial(7/2, 3/2)35/8

Binomial(3.5, 2.1)4.26099

Binomial keeps partial products as small as possible to avoid overflows.

(10^20)!Integer.Overflow: Integer overflow during computation with integers detected.Overflow

Binomial(10^20, 3)166666666666666666661666666666666666666700000000000000000000

See also

Factorial!

Boolefunction

Syntax

Boole(bool)
gives 0 if bool is True and 1 if bool is False.

Details

Examples

Boole(False)0

Boole(32 > 30)1

Boole(a<b)Boole(a < b)

See also

False True If

Calculatefunction

Syntax

Calculate(exp)
evaluates the expression exp to a real or complex number with machine precision.
Calculate(exp, n)
evaluates the expression exp to a real or complex number with precision n.

Details

Examples

Log(-5)I*Pi + Log(5)

Log(-5) // Calculate1.60944+3.14159*I

Calculate a set of expressions:

x = { 4/6 , Cos(3) , Cos(Pi/6) }{2/3, Cos(3), 1/2*3^(1/2)}

Calculate(x){0.666667, -0.989992, 0.866025}

Calculate any exact expressions with a specified precision:

Calculate(Log(-5), 25)1.609437912434100374600759+3.141592653589793238462643*I

Calculate(Cos(2^10), 50)0.98735361821984829524651338092244419111051208085007

Possible Issues

It is not possible to increase the precision of an inexact number:

x = Calculate(Pi, 15)3.14159265358979

Calculate(x, 30)3.14159265358979

In some cases the internally higher precision is not enough to ensure the required precision of the result:

y = Calculate(Sin(10^40), 30)Calculate.ExtraPrecisionLimit: Internal extra precision limit (32) reached during calculation.-0.569633400953636327308

y // Precision21.6803

A subtraction of almost equal numbers can can lead to strong loss of precision.

Calculate(Exp(1/10^100)-1, 30)Calculate.ExtraPrecisionLimit: Internal extra precision limit (32) reached during calculation.0.e-61

See also

Precision MachinePrecision Realx Complexx+y*I

Ceilfunction

Syntax

Ceil(x)
gives the smallest integer greater than or equal to x.

Details

Examples

Ceil(2.1)3

Ceil(-2.9)-2

Ceil(3/8)1

Ceil(1.2 + 3.8*I)2+4*I

Ceil(Log(10))3

Processing of Overflow and Underflow:

Ceil(Overflow)Overflow

Ceil(Underflow)1

Ceil(-Underflow)0

See also

Floor Trunc

Clearfunction

Syntax

Clear(s)
removes all assignment rule defined to symbol s.

Details

Examples

Remove an assignment from a single symbols:

x = 123123

x^215129

Clear(x)

x^2x^2

Remove all assignments:

f(10) = 0 f(z?Integer) := 2*z f(z?) * w? @:= -w*z0

Definitions(f)f(10) = 0f(Pattern(z, ?Integer)) := 2*zf(Pattern(z, ?))*Pattern(w, ?) := Minus(w*z)

Clear(f)

Definitions(f)/* no definitions */

See also

Define= DefineDelayed:= SubDefine@= SubDefineDelayed@:=

Complementfunction

Syntax

Complement(list, list1, list2, … )
gives a sorted list of all distinct elements that appear in list but not in any of listi.

Details

Examples

Complement( {4,2,3,2,1} , {1,4} ){2, 3}

Complement( {x, y, z} , {y} ){x, z}

Complement( {1,2,3,4} , {1,2} , {2,3} ){4}

Complement works with any expressions, not only lists, as long as they have the same head.

Complement( a + b + c + d , a + c )b + d

Complement( f(1, 4, 2), f(2, 3) )f(1, 4)

Possible Issues

Heads have to be the same when Complement is applied on expressions.

Complement( f(1, 4, 2), g(2, 3) )Complement.Heads: Heads f and g are not the same.Complement(f(1, 4, 2), g(2, 3))

See also

Union Intersection Join~

Complexx+y*Iobject

Syntax

x + y*I
is a complex number with a real part x and imaginary part y multiplied with the imaginary unit I.
Complex
is the head of a complex number.

Details

Examples

Head(1+2*I)Complex

(1-I)^3-2-2*I

1/2 + 0.4*I1/2+0.4*I

Sqrt(-4)2*I

Log(-0.5)-0.693147+3.14159*I

Possible Issues

Combinations of ComplexOverflow and ComplexUnderflow can result in Indeterminate.

ComplexOverflow * ComplexUnderflowIndeterminate

See also

Integern Rationala/b Realx

ComplexInfinityconstant

Syntax

ComplexInfinity
represents the mathematical infinite quantity with an undetermined complex phase.

Details

Examples

Abs(ComplexInfinity) > Abs(ComplexOverflow)True

Arithmetical and mathematical functions are able to process ComplexInfinity:

1 / ComplexInfinity0

1 / 0ComplexInfinity

Log(ComplexInfinity)Infinity

See also

DirectedInfinity Infinity ComplexOverflow

ComplexOverflowconstant

Syntax

ComplexOverflow
represents an overflow in float-pointing arithmetic with complex numbers.

Details

Examples

(7.0+4.0*I) ^ Exp(100.0)ComplexOverflow

Arithmetical and mathematical functions are able to process ComplexOverflow:

3.14 + ComplexOverflowComplexOverflow

ComplexOverflow * (-2)ComplexOverflow

Abs( ComplexOverflow )Overflow

Arg( ComplexOverflow )Indeterminate

See also

ComplexUnderflow Overflow ComplexInfinity

ComplexUnderflowconstant

Syntax

ComplexUnderflow
represents an underflow in float-pointing arithmetic with complex numbers.

Details

Examples

(7.0+4.0*I) ^ (-Exp(100.0))ComplexUnderflow

Arithmetical and mathematical functions are able to process ComplexUnderflow:

3.14 + ComplexUnderflow3.14+0.0*I

ComplexUnderflow * (-2)ComplexUnderflow

1 / ComplexUnderflowIndeterminate

Abs( ComplexUnderflow )Underflow

Arg( ComplexUnderflow )Indeterminate

See also

ComplexOverflow Underflow

Compound;function

Syntax

Compound(exp1, exp2, … )exp1 ; exp2 ;
evaluates all expressions expi in turn and gives the last one as result.
exp;
evaluates exp but gives Null as result.

Details

Examples

x = 1 ; y = 2 ; x + y3

z = 10^10000;

Log(10, z)10000

See also

Null Print

Condition/?function

Syntax

Condition(pat, cond)pat /? cond
is a pattern object that matches only if the evaluation of cond yields True.

Details

Examples

Matching( 1, x? /? x>0 ) Matching( -1, x? /? x>0 )True False

Using Condition in a single argument:

f(x? /? x!=0) := 1/x

f(2) f(1/2) f(0)1/2 2 f(0)

Using Condition for the whole definition:

g(x?, y?) /? x>y := x^y

g(10, 2) g(2, 4) g(x, 3)100 g(2, 4) g(x, 3)

Using Condition for a replacement rule:

Replace( {-1,2,-3,4,-5,6} , x?Integer /? x<0 -> 0 ){0, 2, 0, 4, 0, 6}

The difference between a definition with Condition/? instead of a definition with If:

g( x? /? x!=1 ) := (x^2-1)/(x-1) /* general definition with exception */ h(x?) := If( x!=1 , (x^2-1)/(x-1) , "problem" ) /* definition with If */

{ g(0.0) , g(1.0) , g(2.0) } { h(0.0) , h(1.0) , h(2.0) }{1.0, g(1.0), 3.0} {1.0, "problem", 3.0}

See also

Pattern Alternatives| Optional: If

Conjugatefunction

Syntax

Conjugate(z)
gives the complex conjugate of the complex number z.

Details

Examples

Conjugate(1+I)1-I

Conjugate(1.2 - 3.4*I)1.2+3.4*I

Conjugate(-123)-123

Conjugate(I*Infinity)DirectedInfinity(-I)

Simplifications are performed if possible.

Conjugate(-2*x)-2*Conjugate(x)

Conjugate(Log(3+I))Log(3-I)

Conjugate((-2)^(1/2))-I*2^(1/2)

See also

Abs Arg Re Im

Cosfunction

Syntax

Cos(z)
gives the cosine of z.

Details

Examples

Cos(2.0)-0.416147

Calculate(Cos(2), 70)-0.4161468365471423869975682295007621897660007710755448907551499737819649

Cos(2.0+3.0*I)-4.18963-9.10923*I

Particular arguments and their result:

Cos(0)1

Cos(Pi/2)0

Cos(Pi/3)1/2

Cos(Pi/4)1/2^(1/2)

Pure imaginary arguments are converted into Cosh:

Cos(2*I)Cosh(2)

The cosine of the arcus cosine is identity:

Cos(ArcCos(z))z

See also

ArcCos Sin Tan Cosh

Coshfunction

Syntax

Cosh(z)
gives the hyperbolic cosine of z.

Details

Examples

Cosh(2.0)3.7622

Calculate(Cosh(2), 70)3.762195691083631459562213477773746108293973558230711602777643347588324

Cosh(2.0+3.0*I)-3.72455+0.511823*I

Particular arguments and their result:

Cosh(0)1

Cosh(I*Pi)Cosh(I*Pi)

Pure imaginary arguments are converted into Cos:

Cosh(2*I)Cos(2)

The hyperbolic cosine of the area hyperbolic cosine is identity:

Cosh(ArCosh(z))z

See also

ArCosh Sinh Tanh Cos

Define=function

Syntax

Define(lhs, rhs)lhs = rhs
evaluates the expression rhs and assign the result as a replacement for the expression lhs whenever it appears.

Details

Examples

Assign expressions to single symbols:

x = 123123

x*2246

y = a^2 + b^2a^2 + b^2

2*y2*(a^2 + b^2)

Multiple assignments via list:

{a, b, c} = {123, 3.14, "Test"};

a b c123 3.14 "Test"

Assign expressions to an expression with a pattern:

f(z?) = z^2 + zz + z^2

f(9) f(a+b)90 16037.4

Polytypism allows multiple definitions to the same expression head:

f(z?, n?) = z^n + zz + z^n

f(w) f(w, 5)w + w^2 w + w^5

Possible Issues

Define evaluates the expression rhs on the right hand side before assignment, DefineDelayed:= not.

x = 3.143.14

h(x?) = 2*x6.28

k(x?) := 2*x

x is already known and will be replaced in Define= but not in DefineDelayed:=.

h(123) k(123)6.28 246

See also

DefineDelayed:= SubDefine@= Clear Pattern Expressionf(…) Symbols

DefineDelayed:=function

Syntax

DefineDelayed(lhs, rhs)lhs := rhs
assigns the unevaluated expression rhs as a replacement for the expression lhs whenever it appears.

Details

Examples

Assign expressions to single symbols:

x := 123

x*2246

y := a^2 + b^2

2*y2*(a^2 + b^2)

Multiple assignments via list:

{a, b, c} := {123, 3.14, "Test"}

a b c123 3.14 "Test"

Assign expressions to an expression with a pattern:

f(z?) := z^2 + z

f(9) f(a+b)90 16037.4

Polytypism allows multiple definitions to the same expression head:

f(z?, n?) := z^n + z

f(w) f(w, 5)w + w^2 w + w^5

Possible Issues

DefineDelayed does not evaluates the expression rhs on the right hand side before assignment, Define= does.

m = 22

k(q?) := m*q

h(q?) = m*q2*q

m is already known and will be replaced within Define= during the assignment but for DefineDelayed:= after replacement.

h(a) k(a)246 246

The result of h(a) changes when m is changed, but not the result of k(a)

m = 55

h(123) k(123)246 615

See also

Define= SubDefineDelayed@:= Clear Pattern Expressionf(…) Symbols

Definitionsfunction

Syntax

Definitions(s)
prints all assignments defined to symbol s.

Details

Examples

Definitions(Plus)Plus(???) /* built-in function */

Define some assignments to f and print all definitions:

f(1) = 1; f(x?) := f(x-1)+f(x-2); f(2) = 1; f(x? /? x <= 0) = 0;

Definitions(f)f(1) = 1f(2) = 1f(Condition(Pattern(x, ?), x <= 0)) = 0f(Pattern(x, ?)) := f(x - 1) + f(x - 2)

See also

Attributes Define= DefineDelayed:= SubDefine@= SubDefineDelayed@:=

Depthfunction

Syntax

Depth(exp)
gives the maximum nesting depth of exp.

Details

Examples

Depth( { {1,2}, 3, {4,{5,6}} } )3

Depth( 123 )0

Depth works with any expressions, not only lists.

Depth( f(x^2) )2

Depth( a + 2*b^2 + 3*c )3

Rational and complex numbers have a depth of 0.

Depth( 1/3 )0

Depth( 1+2*I )0

Possible Issues

Depth operates on the internal evaluated form, not on the displayed form.

a/ba/b

Depth( a/b )2

InternalForm( a/b )Times(a, Power(b, -1))

See also

Length Part[…]

DigitBaseoption

Syntax

DigitBase -> int
is an option to define the digit base for number representations.

Details

Examples

ToString(12345, DigitBase->2)"11000000111001"

ToString(10^100, DigitBase->36)"2HQBCZU2OW52BALA8LGC3S5Y9MM5TIY0VO9TKE25466GFI6AX8GS22X7KUU8L1TDS"

ToInteger("FF", DigitBase->16)255

ToInteger("5yc1s", DigitBase->36)10000000

ToReal("0.C4", DigitBase->16)0.765625

See also

ToString ToInteger ToReal BinaryFormat

DirectedInfinityfunction

Syntax

DirectedInfinity()
represents the mathematical infinite quantity with an unknown direction in the complex plane.
DirectedInfinity(z)
represents the mathematical infinite quantity with its direction in the complex plane along z.

Details

Examples

Arithmetical and mathematical functions are able to process DirectedInfinity:

DirectedInfinity(1.0+I) * DirectedInfinity(I)DirectedInfinity(-0.707107+0.707107*I)

DirectedInfinity(I) ^ 4Infinity

Tan(DirectedInfinity(1+I))I

ArcCos(Infinity)DirectedInfinity(I)

ArTanh(DirectedInfinity(I))1/2*I*Pi

See also

Infinity ComplexInfinity

Divide/function

Syntax

Divide(exp1, exp2)exp1 / exp2
divides expression exp1 by exp2.

Details

Examples

4 / 22

x^5 / x^2x^3

Possible Issues

A division of two exact numbers keeps exact. Use at least one real number to force a real result.

4 / 6 4.0 / 62/3 0.666667

See also

Times* Mod Power^

Econstant

Syntax

E
represents Euler's number e ≅ 2.71828.

Details

Examples

Calculate E:

Calculate(E)2.71828

Calculate(E, 70)2.718281828459045235360287471352662497757247093699959574966967627724077

Arithmetic with E:

2*E2*E

2.0*E5.43656

Some functions give exact results for terms with E.

Log(E)1

See also

I Pi Calculate Log

Endiannessoption

Syntax

Endianness -> -1Endianness -> 1
is an option to define the endianness (order of bytes) as little-endian (-1) or big-endian (1).

Details

Examples

ToString(1023, BinaryFormat->"Integer32") ToString(1023, BinaryFormat->"Integer32", Endianness->-1) ToString(1023, BinaryFormat->"Integer32", Endianness->1)'ÿ\x03\0\0' 'ÿ\x03\0\0' '\0\0\x03ÿ'

ToString("yä€𝄞", BinaryFormat->"UTF16", Endianness->-1) ToString("yä€𝄞", BinaryFormat->"UTF16", Endianness->1)'y\0ä\0¬ 4Ø\x1EÝ' '\0y\0ä ¬Ø4Ý\x1E'

ToInteger('ÿ\x01\0\0', BinaryFormat->"Integer32") ToInteger('ÿ\x01\0\0', BinaryFormat->"Integer32", Endianness->-1) ToInteger('ÿ\x01\0\0', BinaryFormat->"Integer32", Endianness->1)511 511 -16711680

See also

ToString ToInteger BinaryFormat

Equal==function

Syntax

Equal(exp1, exp2, … )exp1 == exp2 ==
gives True if all expressions expi are mathematically equal, and False if they are unequal.

Details

Examples

1 == 1True

3.0 == 3True

0.2 == 1/5True

The integer 1 and the real number 1.0 are mathematically equal, but not identical.

1 == 1.0 1 === 1.0True False

The equality of Overflows is unknown, but they are identical.

Overflow == Overflow Overflow === OverflowOverflow == Overflow True

Equal stays unevaluated if equality is unknown.

a == ba == b

Possible Issues

Inexact numbers are considered as equal if just the last one or two decimal digits are different. This allows an easier handling with floating point numbers.

1.0000000000000000002 == 1.0000000000000000001True

1.00000000000000000020 == 1.00000000000000000010False

See also

Same=== Unequal!=

EulerMascheroniconstant

Syntax

EulerMascheroni
represents the Euler–Mascheroni constant γ ≅ 0.577216.

Details

Examples

Calculate EulerMascheroni:

Calculate(EulerMascheroni)0.577216

Calculate(EulerMascheroni, 70)0.5772156649015328606065120900824024310421593359399235988057672348848677

Arithmetic with EulerMascheroni:

2*EulerMascheroni2*EulerMascheroni

2.0*EulerMascheroni1.15443

See also

E Calculate

Expfunction

Syntax

Exp(z)
gives the exponential of z.

Details

Examples

Exp(-2.5)0.082085

Exp(1000.0)1.970071114017e434

Exp(3.0+2.0*I)-8.35853+18.2637*I

Calculate(Exp(10), 70)22026.46579480671651695790064528424436635351261855678107423542635522520

Particular arguments and their result:

Exp(0)1

Exp(1)E

Exp(-Infinity)0

See also

Power^ Log

Expandfunction

Syntax

Expand(exp)
expands out products and positive integer powers in exp.

Details

Examples

Expand( 3*(a+b) )3*a + 3*b

Expand( (a+b)^2 )a^2 + 2*a*b + b^2

Expand( (Pi+1)^3 * (E-2) )-2 + E - 6*Pi + 3*E*Pi - 6*Pi^2 + 3*E*Pi^2 - 2*Pi^3 + E*Pi^3

Expand( (a+b)^2 + (a-b)^2 )2*a^2 + 2*b^2

Possible Issues

Expand is not applied to deeper expression levels:

Expand( f((1+a)^2) )f((1 + a)^2)

See also

Plus+ Times* Power^

Expressionf(…)object

Syntax

head(arg1, arg2, … )
is an expression with a head head and any number of arguments argi.
head @ arg
is the prefix notation of an expression head(arg).
arg // head
is the postfix notation of an expression head(arg).

Details

Examples

Head( func(a, b) )func

Head( h(y)(a, b) )h(y)

func @ 123func(123)

123 // funcfunc(123)

Define assignments for specific arguments:

f(1) = 2 f(foo) = 3 f("bar") = 42 3 4

{ f(), f(0), f(1) } { f(foo), f(bar), f("bar"), f("foo") }{f(), f(0), 2} {3, f(bar), 4, f("foo")}

Define a function:

g(x?) := x^2

{ g(7) , g(a) , g(2+b) }{49, a^2, (2 + b)^2}

See also

Symbols Head Define= DefineDelayed:= SubDefine@= SubDefineDelayed@:=

Factorial!function

Syntax

Factorial(n)n!
gives the factorial of n.

Details

Examples

Factorial(10)3628800

50!30414093201713378043612608166064768844377641568960512000000000000

(-5)!ComplexInfinity

6.32!1321.18

1000.0!4.02387260077e2567

Calculate(Factorial(22/7), 70)7.199869288735633700776845665344668943490127819531077381591855761162949

(-1/2)!Pi^(1/2)

(2.1+0.4*I)!1.97507+0.802929*I

See also

Not! Calculate

Falseconstant

Syntax

False
represents the boolean value false.

Details

Examples

1 == 2False

Not(False)True

See also

True Boole Not! Equal==

Fibonaccifunction

Syntax

Fibonacci(n)
gives the Fibonacci number Fn.

Details

Examples

Calculate Fibonacci numbers based on the recursion rule:

Fibonacci(10)55

Fibonacci(350)6254449428820551641549772190170184190608177514674331726439961915653414425

Fibonacci(-10)-55

Calculate Fibonacci numbers based on the general formula:

Fibonacci(10.0)55.0

Fibonacci(16.32)1151.31

Fibonacci(10000.0)3.36447648764e2089

Calculate(Fibonacci(22/7), 70)2.118038120159998741207512266041453547560232382534595267287508988177487

Fibonacci(2.1+0.4*I)0.932786+0.370984*I

See also

Factorial! GoldenRatio

Flatattribute

Syntax

Flat
is an attribute for symbols to indicate that their arguments can be flatted or sub expressions can be created during pattern matching.

Details

Examples

Summands in Plus+ are flattened during evaluation:

a + (b + c)a + b + c

By default expressions with the same head are not flattened or nested.

f(1, f(2, 3))f(1, f(2, 3))

Matching( f(1, 2, 3) , f(x?, y?) )False

After setting the attribute Flat, expressions will flattened and pattern matching tries all sub expressions.

Attributes(f) = FlatFlat

f(1, f(2, 3))f(1, 2, 3)

f(1, 2, 3) /: f(x?, y?) :> {x, y}{1, f(2, 3)}

See also

Attributes Orderless

Floorfunction

Syntax

Floor(x)
gives the greatest integer less than or equal to x.

Details

Examples

Floor(-2.1)-3

Floor(2.9)2

Floor(7/8)0

Floor(1.2 + 3.8*I)1+3*I

Floor(Log(10))2

Processing of Overflow and Underflow:

Floor(Overflow)Overflow

Floor(Underflow)0

Floor(-Underflow)-1

See also

Ceil Trunc

Function&function

Syntax

Function(body)body&
is an anonymous function with the body body.

Details

Examples

f = Function( 2*#+1 )Function(2*#1 + 1)

f(x) f(5)1 + 2*x 11

g = #1^#2 + #2^#1 &Function(#1^#2 + #2^#1)

g(x, y) g(4,3)x^y + y^x 145

Select( {1,2,3,4} , #<3 & ){1, 2}

Possible Issues

Too many arguments are ignored. Too few arguments will result in an error.

f = {#1, #2} &Function({#1, #2})

f(a,b,c){a, b}

f(a,b){a, b}

f(a)Function.Slot: Slot number 2 cannot be filled.{a, #2}

See also

Slot#

GoldenAngleconstant

Syntax

GoldenAngle
represents the golden angle
2 π
φ2
≅ 2.39996 ≅ 137.5°, with the golden ratio φ.

Details

Examples

Calculate GoldenAngle:

Calculate(GoldenAngle)2.39996

Calculate(GoldenAngle, 70)2.399963229728653322231555506633613853124999011058115042935112750731307

Calculate(GoldenAngle*180/Pi)137.508

See also

GoldenRatio E Pi Calculate

GoldenRatioconstant

Syntax

GoldenRatio
represents the golden ratio φ ≅ 1.61803.

Details

Examples

Calculate GoldenRatio:

Calculate(GoldenRatio)1.61803

Calculate(GoldenRatio, 70)1.618033988749894848204586834365638117720309179805762862135448622705260

See also

GoldenAngle E Pi Calculate

Greater>function

Syntax

Greater(x1, x2, … )x1 > x2 >
gives True if xi is greater than xi + 1 for all arguments, and False if xi is less than or equal to xi + 1 for at least one pair.

Details

Examples

2 > 1True

1/3 > 0 > -0.5True

x > 2 > 2False

The comparison will be simplified if possible.

2 > 1 > x1 > x

The value of an exact expression is approximated for comparison.

Sin(2) > 0True

See also

GreaterEqual>= Less< LessEqual<= Equal== Unequal!= Max

GreaterEqual>=function

Syntax

GreaterEqual(x1, x2, … )x1 >= x2 >=
gives True if xi is greater than or equal to xi + 1 for all arguments, and False if xi is less than xi + 1 for at least one pair.

Details

Examples

2 >= 1True

3/2 >= 1.5 >= -0.5True

x >= 1 >= 2False

The comparison will be simplified if possible.

2 >= 1 >= x1 >= x

The value of an exact expression is approximated for comparison.

Sin(2) >= 0True

See also

Greater> Less< LessEqual<= Equal== Unequal!= Max

Iconstant

Syntax

I
represents the imaginary unit i−1.

Details

Examples

I // HeadComplex

I * I-1

(-4)^(1/2)2*I

See also

E Pi Complexx+y*I Power^

Iffunction

Syntax

If(con, t, f)
gives t if con is True and f if con is False.
If(con, t, f, u)
gives u if con is neither True nor False.
If(con, t)
gives Null if con is False.

Details

Examples

If(True, 123, -10) If(False, 123, -10)123 -10

x = 3; If(x!=0, 1.0/x, "Div 0") x = 0; If(x!=0, 1.0/x, "Div 0")0.333333 "Div 0"

If remains unevaluated if the condition is neither True nor False.

If(a==b, 1, 2)If(a == b, 1, 2)

Force a result for indefinite expressions with the fourth argument:

If(a==b, 1, 2, 3)3

See also

True False

Imfunction

Syntax

Im(z)
gives the imaginary part of the complex number z.

Details

Examples

Im(1+I)1

Im(1.2 - 3.4*I)-3.4

Im(-123)0

Im(Log(-6))Pi

Im(I*Infinity)Infinity

Simplifications are performed if possible.

Im(-2*x)-2*Im(x)

Im(3+Pi+z)Im(z)

Im(Abs(z))0

Im(Exp(2+3*I))E^2*Sin(3)

See also

Re Conjugate Abs Arg

Indeterminateconstant

Syntax

Indeterminate
represents a mathematical quantity whose magnitude is undetermined.

Details

Examples

0 / 0Indeterminate

0 ^ 0Indeterminate

Infinity - InfinityIndeterminate

See also

Infinity ComplexInfinity

Infinityconstant

Syntax

Infinity
represents the mathematical positive infinite quantity.

Details

Examples

Infinity > OverflowTrue

Arithmetical and mathematical functions are able to process Infinity:

1 / Infinity0

Log(0)-Infinity

E^(-Infinity)0

Tanh(Infinity)1

Exact evaluation is not possible with Overflow:

Tanh(Overflow)1.0

Log(0.0)Indeterminate

See also

DirectedInfinity ComplexInfinity Overflow

Integernobject

Syntax

n
with an arbitrary number of digits represents an integer number.
Integer
is the head of an integer number.

Details

Examples

Head(123)Integer

12 + 3446

Working with large numbers:

32845723658234756 * 34659487645645654611384159533448787206618577180912776

11384159533448787206618577180912776 / 34659487645645654632845723658234756

3^200265613988875874769338781322035779626829233452653394495974574961739092490901302182994384699044001

See also

ToInteger Rationala/b Realx Complexx+y*I

InternalFormfunction

Syntax

InternalForm(exp)
gives the internal representation of exp without operator signs.

Details

Examples

InternalForm(4+2*I)Complex(4, 2)

InternalForm(1/5)Rational(1, 5)

InternalForm(1+2*x)Plus(1, Times(2, x))

InternalForm(x?Integer)Pattern(x, Any(Integer))

Possible Issues

InternalForm visualizes the internal used expression structure, not the input structure.

InternalForm(a-b)Plus(a, Times(-1, b))

InternalForm(1/x)Power(x, -1)

InternalForm(Exp(z))Power(E, z)

See also

Output Print

Intersectionfunction

Syntax

Intersection(list1, list2, … )
gives a sorted list of all distinct elements that appear in all of listi.

Details

Examples

Intersection( {4,3,3,1} , {1,4,4,5} ){1, 4}

Intersection( {x, y} , {u, v} ){}

Intersection( {1,2,3} , {1,10,100} , {1,2,4,8} ){1}

Intersection works with any expressions, not only lists, as long as they have the same head.

Intersection( a + b + d , a + c + d )a + d

Intersection( f(1, 4, 2), f(2, 3, 4) )f(2, 4)

Possible Issues

Heads have to be the same when Intersection is applied on expressions.

Intersection( f(1, 2), g(2, 3) )Intersection.Heads: Heads f and g are not the same.Intersection(f(1, 2), g(2, 3))

See also

Union Complement Join~

Iteratefunction

Syntax

Iterate(exp, n)
gives a list of n evaluated copies of exp.
Iterate(exp, {i, imax} )
generates a list by iterating i from 1 to imax.
Iterate(exp, {i, imin, imax} )
generates a list by iterating i from imin to imax.
Iterate(exp, {x, xmin, xmax, xstep} )
generates a list by iterating x from xmin to xmax using steps xstep.
Iterate(exp, {e, {e1, e2, …, en } } )
generates a list by iterating e though the values e1, e2, …, en.
Iterate(exp, spec1, spec2, … )
is evaluated as Iterate(Iterate(exp, spec1), spec2, … ).

Details and Options

Examples

Iterations without iterator:

Iterate(0, 8){0, 0, 0, 0, 0, 0, 0, 0}

Iterate("Text", 4){"Text", "Text", "Text", "Text"}

Iteration with an iterator:

Iterate(i, {i, 10} ){1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

Iterate(i^2, {i, -3, 3} ){9, 4, 1, 0, 1, 4, 9}

Iterate(x, {x, 0.5, 0.9, 0.1} ){0.5, 0.6, 0.7, 0.8, 0.9}

Iteration with an iterator and specific elements:

Iterate(w*2, {w, {1,0.7,t,1/3} } ){2, 1.4, 2*t, 2/3}

Nested iteration with two iterators m and n:

Iterate(m+n*10, {m, 1, 4}, {n, 1, 4}){{11, 12, 13, 14}, {21, 22, 23, 24}, {31, 32, 33, 34}, {41, 42, 43, 44}}

The outer iterator n can be used in the inner iteration range.

Iterate(m+n*10, {m, 1, n}, {n, 1, 4}){{11}, {21, 22}, {31, 32, 33}, {41, 42, 43, 44}}

Possible Issues

The expression to iterate is just evaluated during the iteration, not before. In the following, this leads to different random numbers instead of ten identically numbers.

Iterate(Random(9), 10){8, 5, 3, 2, 7, 5, 3, 2, 6, 9}

See also

List{…} Part[…]

Join~function

Syntax

Join(exp1, exp2, … )exp1 ~ exp1 ~
joins all expressions expi that have the same head, e.g. List{…}.
Join(str1, str2, … )str1 ~ str1 ~
joins all strings stri.

Examples

Join( {1,2} , {3,4,5} ){1, 2, 3, 4, 5}

Join( "Hello ", "World!" )"Hello World!"

Join works with any expressions, not only lists, as long as they have the same head.

Join( a + b , c + d )a + b + c + d

Join( f(1, 2), f(x) )f(1, 2, x)

See also

Depth Length Part[…]

Lengthfunction

Syntax

Length(exp)
gives the number of elements in expression exp.
Length(str)
gives the number of characters in string str.

Details

Examples

Length( {1,2,3,4,5} )5

Length( "Hello World!" )12

Length( '\0\x80ÿ\n' )4

Length works with any expressions, not only lists or strings.

Length( a + 2*b + c )3

Length( f(a, b) )2

Rational and complex numbers have a length of 0.

Length( 1/3 )0

Length( 1+2*I )0

Possible Issues

Length operates on the internal evaluated form, not on the displayed form.

Minus(x)-x

Length( -x )2

InternalForm( -x )Times(-1, x)

See also

Depth Part[…]

Less<function

Syntax

Less(x1, x2, … )x1 < x2 <
gives True if xi is less than xi + 1 for all arguments, and False if xi is greater than or equal to xi + 1 for at least one pair.

Details

Examples

1 < 2True

-0.5 < 0 < 1/3True

x < 2 < 2False

The comparison will be simplified if possible.

1 < 2 < x2 < x

The value of an exact expression is approximated for comparison.

Sin(4) < 0True

See also

LessEqual<= Greater> GreaterEqual>= Equal== Unequal!= Min

LessEqual<=function

Syntax

LessEqual(x1, x2, … )x1 <= x2 <=
gives True if xi is less than or equal to xi + 1 for all arguments, and False if xi is greater than xi + 1 for at least one pair.

Details

Examples

1 <= 2True

-0.5 <= 1.5 <= 3/2True

x <= 2 <= 1False

The comparison will be simplified if possible.

1 <= 2 <= x2 <= x

The value of an exact expression is approximated for comparison.

Sin(4) <= 0True

See also

Less< Greater> GreaterEqual>= Equal== Unequal!= Min

List{…}function

Syntax

List(e1, e2, … ){ e1, e2, … }
represents a list of elements ei.

Details

Examples

List( 1, 2, 3 ){1, 2, 3}

{{a1,a2}, {b1,b2}}{{a1, a2}, {b1, b2}}

Most built-in functions thread into lists:

Sqrt({1, 4, 9}){1, 2, 3}

Exp({0.0, 1.0, 10.0}){1.0, 2.71828, 22026.5}

See also

Length Depth Part[…]

Listableattribute

Syntax

Listable
is an attribute for symbols to indicate that the symbol will threaded into lists occurring in arguments.

Details

Examples

{a, b} + {c, d}{a + c, b + d}

Sin({x, 2, 0.5}){Sin(x), Sin(2), 0.479426}

By default the head of an expression is not threaded into the list.

f({1, 2, 3})f({1, 2, 3})

After setting the attribute Listable, f will threaded into the list.

Attributes(f) = ListableListable

f({1, 2, 3}){f(1), f(2), f(3)}

f({1, 2, 3}, {a, b, c}){f(1, a), f(2, b), f(3, c)}

See also

Attributes Flat Orderless

Lockedattribute

Syntax

Locked
is an attribute for symbols to indicate that they are locked against changes in their attributes.

Details

Examples

Attributes(Plus) = FlatAttributes.Locked: Plus is locked!Flat

After setting the attribute Locked, no more changes in attributes can be made.

Attributes(f) = {Flat, Locked}{Flat, Locked}

Attributes(f) = {Orderless}Attributes.Locked: f is locked!{Orderless}

Attributes(f){Flat, Locked}

See also

Attributes Protected

Logfunction

Syntax

Log(z)
gives the natural logarithm of z.
Log(b, z)
gives the logarithm of z to base b.

Details

Examples

Log(1000.0)6.90776

Log(-3.14)1.14422+3.14159*I

Log(3.0+2.0*I)1.28247+0.588003*I

Calculate(Log(100), 70)4.605170185988091368035982909368728415202202977257545952066655801935145

Particular arguments and their result:

Log(E)1

Log(0)-Infinity

Log(-1)I*Pi

Logarithm with specified base:

Log(10, 1000)3

Log(4.5, 4.5^100000)1.0e5

Log(2/3, 16/81)4

Log(1/4, 8)-3/2

Possible Issues

If an exact solution does not exist, just a conversion is performed.

Log(2, 100)Log(100)/Log(2)

See also

Power^

MachinePrecisionconstant

Syntax

MachinePrecision
indicates the usage of machine precision in float pointing numbers like reals.

Details

Examples

Calculate MachinePrecision on current system:

Calculate(MachinePrecision)15.9546

Small real numbers with low precision stored with machine precision:

Precision(3.1415)MachinePrecision

Precision(789.456e123)MachinePrecision

Large real numbers stored with an arbitrary precision with at least machine precision:

Precision(123.4e5678)15.9546

See also

Realx Precision

Map/@function

Syntax

Map(f, exp)f /@ exp
applies f to each element in expression exp.

Details

Examples

Map(f, g(1, a, x))g(f(1), f(a), f(x))

Map(Cos, Pi+b+c)-1 + Cos(b) + Cos(c)

Map will process anonymous function as well:

#^2 & /@ {4, 9, a, 0.4}{16, 81, a^2, 0.16}

See also

Apply Function& Head

Matchingfunction

Syntax

Matching(exp, pat)
performs a pattern matching of pattern pat on expression exp.

Details

Examples

Matching(123, ?Integer) Matching(123.0, ?Integer)True False

Matching({a, b, c}, {??Symbol}) Matching({a, 2, b}, {??Symbol})True False

Matching({10, 11}, {x?, x?}) Matching({10, 10}, {x?, x?})False True

Matching({2, 1}, {x?, y?} /? x>y ) Matching({1, 2}, {x?, y?} /? x>y )True False

See also

Same=== Equal==

Maxfunction

Syntax

Max(x1, x2, … )Max( {x1, x2, … }, {xn + 1, xn + 2, … }, … )
gives the numerically largest value of xi.

Details

Examples

Max(3, -2, 1.0)3

Max(E, Pi)Pi

Max({4,2,-4}, {9, 0, 4})9

Possible Issues

Max remains unevaluated, but simplified, when non-comparable values are included.

Max(3, "test", -5, 2+I, 4)Max("test", 2+I, 4)

See also

Min Greater>

Minfunction

Syntax

Min(x1, x2, … )Min( {x1, x2, … }, {xn + 1, xn + 2, … }, … )
gives the numerically smallest value of xi.

Details

Examples

Min(3, -2, 1.0)-2

Min(E, Pi)E

Min({4,2,-4}, {9, 0, 4})-4

Possible Issues

Min remains unevaluated, but simplified, when non-comparable values are included.

Min(3, "test", -5, 2+I, 4)Min("test", 2+I, -5)

See also

Max Less<

Minus-function

Syntax

Minus(exp)-exp
gives the arithmetic negation of exp.

Details

Examples

Minus(123)-123

Minus(a+b+c)-a - b - c

Minus(3+2*I)-3-2*I

Double negation of an expression is the expression itself.

Minus(Minus(exp))exp

See also

Subtract- Times* Not!

Modfunction

Syntax

Mod(m, n)
gives the remainder on devision of m by n.

Details

Examples

Mod(7, 3)1

Mod(4.0, 1.2)0.4

Mod(5/9, 1/2)1/18

Mod also performs on expressions.

Mod(Pi, 2)-2 + Pi

Mod(8*Pi, 3*Pi)2*Pi

Mod(10, 5^(1/2))10 - 4*5^(1/2)

Mod(14*a^2, 3*a^2)2*a^2

Possible Issues

The result of Mod(m, n) is always in the range 0 to n, and negative when n is negative.
This behavior differs from other languages, where the result becomes negative when m is negative, instead of n.

Mod(7, 3)1

Mod(-7, 3)2

Mod(7, -3)-2

Mod(-7, -3)-1

See also

Divide/ Floor

Not!function

Syntax

Not(bool)!bool
gives the logical NOT of bool.
Not(int)!int
gives the binary NOT of the integer int.
Not(str)!str
gives the binary NOT of the string str.

Details

Examples

! FalseTrue

! 15-16

! 'BINARY''½¶±¾­¦'

Negation of comparisons are simplified if possible.

Not( x < 3 )x >= 3

Not( x == 3 )x != 3

Double negation of an expression is the expression itself.

Not( Not( exp ) )exp

See also

And&& Or|| Xor!! False True Factorial!

Nullconstant

Syntax

Null
represents the absence of any kind of object.

Details

Examples

Null

x := 1

z = 3;

{1, Print(2), z}2{1, 2, 3}

See also

Compound; Print

Optional:function

Syntax

Optional(pat, exp )pat : exp
is a pattern object that is replaced by exp if pat is not matched.

Details

Examples

Matching( {1, 2}, {x?, y?:0} ) Matching( {1}, {x?, y?:0} )True True

f(x?, y?:2) := x^y

f(a, b) f(a)a^b a^2

g(n?Integer:0, str?String) := {n, str}

g("Text") g(10, "Text"){0, "Text"} {10, "Text"}

See also

Condition/? Alternatives| Pattern

Optionsfunction

Syntax

Options(sym1 -> val1, sym2 -> val2, … )Options(sym1 :> val1, sym2 :> val2, … )
is a pattern object that matches a collection of rules for symbols symn and their default value valn.

Details

Examples

f(Options(x->1, y->2)) := {x, y}

f() f(x->100) f(y->100) f(y->100, x->99){1, 2} {100, 2} {1, 100} {99, 100}

Arguments defined with RuleDelayed are evaluated each time again they will be used:

f(Options(x->0)) := {x, x, x, x, x}

f() f(x->Random(10)) f(x:>Random(10)){0, 0, 0, 0, 0} {10, 10, 10, 10, 10} {7, 2, 8, 9, 9}

See also

Condition/? Pattern Rule-> RuleDelayed:>

Or||function

Syntax

Or(bool1, bool2, … )bool1 || bool2 ||
gives the logical OR of booli.
Or(int1, int2, … )int1 || int2 ||
gives the binary OR of the integers inti.
Or(str1, str2, … )str1 || str2 ||
gives the binary OR of the strings stri.

Details

Examples

True || FalseTrue

12 || 715

'BINARY' || 'abc''ckoARY'

Or stops to evaluate its arguments if True occurs. In the following case the second Print is not evaluated.

(Print(1);False) || True || (Print(2);False)1True

Expressions which are evaluated into False will be erased.

1==2 || a==5 || b==10 || Falsea == 5 || b == 10

See also

And&& Xor!! Not! False True

Orderfunction

Syntax

Order(exp1, exp2)
gives 1 if exp1 and exp2 are in order, gives -1 if exp1 and exp2 are out of order, and gives 0 if both expression are identical.

Details

Examples

Order(123, var)1

Order(1, 1+I)1

Order("b", "a")-1

Order(x^2, x^2)0

Possible Issues

Constants are ordered by their name and not by their numerical value.

Order(Pi, 4)-1

See also

Same=== Sort

Orderlessattribute

Syntax

Orderless
is an attribute for symbols to indicate that their arguments can be sorted and rearranged in pattern matching.

Details

Examples

Summands in Plus+ are sorted during evaluation:

a + c + ba + b + c

By default expressions keep their order of arguments.

f(1, b, 2, a)f(1, b, 2, a)

Matching( f(x, 2) , f(?Integer, x) )False

After setting the attribute Orderless, expressions will sorted and pattern matching tries all combinations.

Attributes(f) = OrderlessOrderless

f(1, b, 2, a)f(1, 2, a, b)

Matching( f(x, 2) , f(?Integer, x) )True

See also

Attributes Flat

Outputfunction

Syntax

Output(exp1, exp2, … ) exp1 exp2
evaluates all expressions expi in turn.

Details

Examples

Output(1+2, 3*4, 5^6)3 12 15625

1+2 3*4 5^63 12 15625

f(Output(1,2,3))f(Output(1, 2, 3))

See also

Compound;

Overflowconstant

Syntax

Overflow
represents an overflow in float-pointing or integer arithmetic.

Details

Examples

Exp(10.0^20.0)Overflow

Arithmetical and mathematical functions are able to process Overflow:

3.14 + OverflowOverflow

Overflow * (-2)-Overflow

3.14 / OverflowUnderflow

ArcTan(Overflow)1.5708

See also

Underflow ComplexOverflow Infinity

Part[…]function

Syntax

Part(exp, level1, level2, … )exp[level1, level2, … ]
gives a part of the expression exp specified by leveli for the different nesting levels.
Part(str, part)str[part]
gives a part of the string str specified by part.

Details

The part and level specifications can have the following forms:
[n] gives the nth element of an expression or the nth character of a string.
[-n] counts from the end of the expression or the string.
[0] gives the head of an expression or the string.
[{n1, n2, … }] gives the expression with elements specified by ni or the string with characters specified by ni.
[m..n] gives the expression with a span of elements or the string with characters from m until n.
[m..n..s] gives a span of elements or characters from m until n in steps of s, where s can also be negative.
[All] gives the expression with all elements in this level or the string with all characters.

Examples

Pick an element or a character:

Part( {a,b,c,d,e} , 3 )c

"Hello World!"[-1]"!"

Pick multiple elements or characters:

{a,b,c,d,e}[{-1,3,3}]{e, c, c}

"Hello World!"[{1,8,3,-2}]"Hold"

Pick a span of elements or characters:

{a,b,c,d,e}[2..-2]{b, c, d}

{a,b,c,d,e}[-1..1..-1]{e, d, c, b, a}

Part( "Hello World!" , 1..7..2 )"HloW"

Pick all 2nd elements from the second level:

{{a1,a2}, {b1,b2}, {c1,c2}}[All, 2]{a2, b2, c2}

Part works on any expression.

Part( a+b*x+x^2 , 2, 1)b

f(1, 2, x, 4, y)[3..5]f(x, 4, y)

Possible Issues

Rationala/b numbers or Complexx+y*I numbers are atomic objects. Part cannot extract the numerator/denominator or real/imaginary part. In such cases you have to use Numerator, Denominator, Re, or Im.

Part( 3/4 , 1 )Part.Depth: Part specification (3/4)[1] is longer than depth of object.(3/4)[1]

Part( 2+3*I , 1 ) Re( 2+3*I )Part.Depth: Part specification (2+3*I)[1] is longer than depth of object.(2+3*I)[1] 2

Expressions like Plus+ and Times* are ordered and flattened before Part is executed.

Part( a+c+b , 2) a+c+b // InternalFormb Plus(a, b, c)

Part( (a*b)*(c*d) , 2) (a*b)*(c*d) // InternalFormb Times(a, b, c, d)

See also

Depth Length Span..

Partitionfunction

Syntax

Partition(str, n)
partitions the string str into a list of sub-strings of length n.
Partition(exp, n)
partitions the expression exp into sub-expressions of length n.

Details

Examples

Partition( {1, 2, 3, 4, 5, 6} , 3 ){{1, 2, 3}, {4, 5, 6}}

Partition( {1, 2, 3, 4, 5, 6} , 4 ){{1, 2, 3, 4}}

Partition( "Hello World!" , 3 ){"Hel", "lo ", "Wor", "ld!"}

Partition( "Hello World!" , 5 ){"Hello", " Worl"}

Partition( f(1,2,3,4) , 2 )f(f(1, 2), f(3, 4))

See also

Part[…] Join~

Patternfunction

Syntax

Pattern(sym, pat)
represents the pattern pat and assigns a matching object to the symbol sym.
sym? sym?? sym???
is the short form for Pattern(sym, ?), Pattern(sym, ??) or Pattern(sym, ???).
sym?head sym??head sym???head
is the short form for Pattern(sym, ?head), Pattern(sym, ??head) or Pattern(sym, ???head).

Details

Examples

f(x?, y?) := x ^ y f(a, b)a^b

g(x??) := Times(x)

g(3) g(4, 5) g(a, 6, x^2)3 20 6*a*x^2

g(Pattern(x, ?Integer|Infinity)) := x^2

{ g(1), g(-5), g(Infinity), g(3.14) }{1, 25, Infinity, 3.14}

See also

Any? AnySequence??

Piconstant

Syntax

Pi
represents the constant π ≅ 3.14159.

Details

Examples

Calculate Pi:

Calculate(Pi)3.14159

Calculate(Pi, 70)3.141592653589793238462643383279502884197169399375105820974944592307816

Arithmetic with Pi:

2*Pi2*Pi

2.0*Pi6.28319

Some functions give exact results for terms with Pi.

Cos(Pi)-1

Expressions with Pi are returned from some functions.

Log(-1)I*Pi

ArcTan(Infinity)1/2*Pi

See also

E I Calculate Cos

Plus+function

Syntax

Plus(exp1, exp2, … )exp1 + exp2 +
gives the sum of all expressions expi.

Details

Examples

1 + 2 + 36

2*x + 3*x5*x

2 + 1/4 2 + 0.259/4 2.25

Plus are flattened and the arguments are sorted.

(a + c) + (b + 4)4 + a + b + c

Plus threads over List{…}:

{1, 2, 3} + 10{11, 12, 13}

{1, 2, x} + {5, 10, y}{6, 12, x + y}

See also

Subtract- Times*

Power^function

Syntax

Power(exp1, exp2)exp1 ^ exp2
gives expression exp1 to the power of exp2.

Details

Examples

2 ^ 1001267650600228229401496703205376

5 ^ (-2)1/25

27 ^ (1/3) 10 ^ (1/3)3 10^(1/3)

10 ^ (1/3) // Calculate 10.0 ^ (1/3)2.15443 2.15443

2.5 ^ 10008.709809816217e397

Power threads over List{…}:

{2, 3, 4} ^ 2{4, 9, 16}

{2, 10} ^ {4, 3}{16, 1000}

Possible Issues

Some evaluations give Indeterminate or ComplexInfinity:

0^0Indeterminate

0^(-1)ComplexInfinity

If the result of Power is to large or near zero, it gives Overflow or Underflow.

10.0 ^ (10.0^20.0)Overflow

0.5 ^ (10.0^20.0)Underflow

See also

Times* Plus+ Sqrt

Precisionfunction

Syntax

Precision( z )
gives the number of precise decimal digits of the number z.

Details

Examples

Determine the number's precision:

Precision(123)Infinity

Precision(3/7)Infinity

Precision(3.14)MachinePrecision

Precision(Overflow)0.0

Precision(123456.78901234567890)20.0915

Precision(4.0 + 3*I)MachinePrecision

See also

Realx MachinePrecision

Printfunction

Syntax

Print(exp1, exp2, …, explast )
evaluates and prints all expressions expi in turn, and gives the last one explast as result.

Details

Examples

Print(1, 2, 3)1233

Print("String are shown\r\nwith line breaks\tand tabs.")String are shown with line breaks and tabs."String are shown\r\nwith line breaks\tand tabs."

Print(Hello, World, Null)HelloWorld

Trace a large calculation:

Print(Log(10, Print(2^10)-24 // Print)) * 2110241000363

Apply(Plus, Iterate(Print(Random(100)), 5))9780896834368

See also

Compound; String"…",'…' Null

Protectedattribute

Syntax

Protected
is an attribute for symbols to indicate that they are protected against changes by assignments or Clear.

Details

Examples

Pi = 3Define.Protected: Pi is protected!3

After setting the attribute Protected, no more definitions can be made.

x = 123123

Attributes(x) = ProtectedProtected

x = 0Define.Protected: x is protected!0

x123

See also

Attributes Locked

Randomfunction

Syntax

Random(z)
gives a pseudorandom number between 0 and z.
Random(list)
gives a pseudorandom element from the list list.

Details and Options

Examples

Random(7)6

Random(2/3)2/3

Random(2.0)1.5129

Random(1.0+2.0*I)0.752581+1.27174*I

Random( {a, b, c} )b

Generate a list of random numbers:

Iterate( Random(9), 10 ){3, 0, 4, 3, 0, 2, 5, 7, 8, 1}

See also

Integern Realx Complexx+y*I List{…}

Rationala/bobject

Syntax

a/b
is a rational number, represented as a fraction of two integer numbers with numerator a and denominator b.
Rational
is the head of a rational number.

Details

Examples

Head(1/2)Rational

4/121/3

5 + 1/316/3

1/123456 + 1/678901802357/83814401856

Working with large numers:

(2/3)^1001267650600228229401496703205376/515377520732011331036461129765621272702107522001

See also

Integern Realx Complexx+y*I

Refunction

Syntax

Re(z)
gives the real part of the complex number z.

Details

Examples

Re(1+I)1

Re(1.2-3.4*I)1.2

Re(-123)-123

Re(Log(-6*I))Log(6)

Re(ArcCos(2))0

Re(Infinity)Infinity

Simplifications are performed if possible.

Re(-2*x)-2*Re(x)

Re(3+Pi+z)3 + Pi + Re(z)

Re(Abs(z))Abs(z)

Re(Exp(2+3*I))E^2*Cos(3)

See also

Im Conjugate Abs Arg

Realxobject

Syntax

x
with an arbitrary number of digits and a decimal point represents a real number.
Real
is the head of a real number.

Details

Examples

Head(1.0)Real

4.0 * 0.72.8

1 + 2.03.0

1/3 + 1.01.33333

1.0000000000000000000000000000000000000000123 + 1011.0000000000000000000000000000000000000000123

The magnitude of real numbers can be larger then typical 64-bit IEEE float pointing numbers can handle.

123.456 ^ 1000.03.25238259113e2091

0.012 ^ 1000.01.517910089172e-1921

Small real numbers with low precision are stored always with machine precision:

Precision(123.456)MachinePrecision

Precision(789.456e123)MachinePrecision

The precision of larger real numbers or numbers with higher precision is tracked:

x = 123.456 ^ 1000.0 y = 123.000000000000000000004567893.25238259113e2091 123.00000000000000000000456789

{ Precision(x) , Precision(y) }{12.4798, 29.0899}

x ^ y1.0018442638e257256

Precision(x^y)10.3898

Overflow and Underflow are real numbers.

123.456 ^ (10^100)Overflow

Head(Overflow)Real

123.456 ^ (-10^100)Underflow

Head(Underflow)Real

Possible Issues

Combinations of Overflow and Underflow can result in Indeterminate or complex numbers.

Overflow * UnderflowIndeterminate

Underflow - UnderflowComplexUnderflow

See also

ToReal Integern Rationala/b Complexx+y*I

Replace/:function

Syntax

Replace(exp, rule)exp /: rule
applies the rule rule to the expression exp and its sub-expressions as a substitution.
Replace(exp, {r1, r2, … })exp /: {r1, r2, … }
applies the rules ri to the expression exp and its sub-expressions as a substitution.
Replace(str, a->b )str /: a->b
replaces all sub-strings a in the string str with b.

Details

Examples

Replace a symbol with a value:

x^2 + x /: x->420

{x+y, x*y, x^y} /: {x->2, y->3}{5, 6, 8}

Swapping elements:

x^2 /: {2->x, x->2}2^x

Replace uses the Flat and Orderless attributes to find a match:

a+b+c+d /: a+d -> xb + c + x

Replace a special type of elements:

{a, b, 1, 2, 3.0, 0.4, "Hello", "World"} /: ?Real -> 0{a, b, 1, 2, 0, 0, "Hello", "World"}

Replace a sub-string:

"Hello World!" /: "World" -> "User""Hello User!"

Possible Issues

Once a rule is matching a sub-expression, no more rules will tried for this sub-expression.

{x, y, z} /: {x->y, y->z, z->0}{y, z, 0}

RuleDelayed:> is evaluated each time of replacement, while Rule-> is evaluated before all replacements:

{x, x, x, x, x} /: x -> Random(10){0, 0, 0, 0, 0}

{x, x, x, x, x} /: x :> Random(10){7, 9, 1, 1, 5}

Patterns that are too general replace the entire expression

f(2, 3, 4) /: x? -> x^2f(2, 3, 4)^2

f(2, 3, 4) /: x?Integer -> x^2f(4, 9, 16)

See also

Rule-> RuleDelayed:> Pattern Expressionf(…) Symbols

Rule->function

Syntax

Rule(lhs, rhs)lhs -> rhs
represents a rule that transforms lhs by rhs.

Details

Examples

Replace(x+y, { x->2, y->4 } )6

Replace(a+b+c+d, b+c -> 4 )4 + a + d

Replace({1, 2.0, 3, 4.0, 5}, ?Integer -> Null ){Null, 2.0, Null, 4.0, Null}

Replace({1, 2.0, 3, 4.0, 5}, x?Integer -> x^2 ){1, 2.0, 9, 4.0, 25}

Possible Issues

x = 44

Rule is evaluated immediately:

x?Integer -> x^2Pattern(x, ?Integer) -> 16

Replace({2, 3, 4}, x?Integer -> x^2 ){16, 16, 16}

RuleDelayed holds the right hand side and is evaluated after the appliement:

x?Integer :> x^2Pattern(x, ?Integer) :> x^2

Replace({2, 3, 4}, x?Integer :> x^2 ){4, 9, 16}

See also

RuleDelayed:> Replace/: Options Pattern

RuleDelayed:>function

Syntax

RuleDelayed(lhs, rhs)lhs :> rhs
represents a rule that transforms lhs by rhs and then evaluate it.

Details

Examples

rhs of RuleDelayed will evaluated during each replacement.

Replace({1, x, 2, x, 3, x}, x :> Random(1000) ){1, 337, 2, 986, 3, 384}

RuleDelayed is typically used in combination with patterns:

Replace({2, 3, 4}, x?Integer :> x^3 ){8, 27, 64}

See also

Rule-> Replace/: Options Pattern

Same===function

Syntax

Same(exp1, exp2, … )exp1 === exp2 ===
gives True if all expressions expi are identical, and False otherwise.

Details

Examples

123 === "text"False

x === yFalse

f(5) === f(5)True

The integer 1 and the real number 1.0 are not identical, but mathematically equal.

1 === 1.0 1 == 1.0False True

Overflows are identical, but the equality is unknown.

Overflow === Overflow Overflow == OverflowTrue Overflow == Overflow

Possible Issues

Same=== is evaluated immediately, while Equal== is keep unevaluated until a decision is possible.

x === 2 Replace( x === 2 , x->2 )False False

x == 2 Replace( x == 2 , x->2 )x == 2 True

See also

Equal== Unequal!= Matching

Scopefunction

Syntax

Scope(sym, body)
evaluates body with the local symbol sym.
Scope({sym1, sym2, … }, body)
evaluates body with the local symbols symi.

Details

Examples

Scope keeps x and y unchanges in the outer scope.

x = 123; a=3; b=44

Scope({x, y}, x=a+b; y=a-b; x/y )-7

{x, y, a, b}{123, y, 3, 4}

Defines temporary symbols:

Scope({z=2, w=3}, z*w )6

{z, w}{z, w}

Possible Issues

Temporary symbols used in the scope will become a unique symbol if they are returned.

Scope(x, x+y )x$3 + y

See also

Function& Define= DefineDelayed:=

Selectfunction

Syntax

Select(list, crit)
gives all elements ei of list for which crit(ei) is True.

Details

Examples

Select( {"Hello", x+y, 4, 3+I, "World!", z} , Head(#)===String & ){"Hello", "World!"}

check(x?) := x^2 < 6

Select( {1, 2, 3, 4, y, 2.2}, check ){1, 2, 2.2}

Select works with any kind of expression.

Select( 1 + w - Pi + x^2 + E, Head(Calculate(#))===Real & )1 + E - Pi

See also

Function& Head

Sequencefunction

Syntax

Sequence(arg1, arg2, … )
is equivalent to a sequence of arguments argi in an expression or in pattern matching.

Details

Examples

func(Sequence(a, b, c), d)func(a, b, c, d)

arg = Sequence(2,4,6) Plus(arg) Times(arg)Sequence(2, 4, 6) 12 48

f(1, 2, 3) /: f(x??) :> xSequence(1, 2, 3)

See also

AnySequence?? AnyNullSequence???

Signfunction

Syntax

Sign(z)
gives the sign of the (complex) number z.

Details

Examples

Sign(-123)-1

Sign(2.5)1

Sign(1.2 + 3.4*I)0.33282+0.94299*I

Sign(1+I)(1+I)/2^(1/2)

Sign uses the numerical estimation of an expression to decide about the sign of the result.

Sign(Pi-E)1

Sign(Sin(4))-1

Sin(4) // Calculate-0.756802

Simplifications are performed if possible.

Sign(-2*x)-Sign(x)

See also

Abs Arg

Sinfunction

Syntax

Sin(z)
gives the sine of z.

Details

Examples

Sin(2.0)0.909297

Calculate(Sin(2), 70)0.9092974268256816953960198659117448427022549714478902683789730115309673

Sin(2.0+3.0*I)9.1545-4.16891*I

Particular arguments and their result:

Sin(0)0

Sin(Pi/2)1

Sin(Pi/3)1/2*3^(1/2)

Sin(Pi/4)1/2^(1/2)

The sine of the arcus sine is identity:

Sin(ArcSin(z))z

See also

ArcSin Cos Tan Sinh

Sinhfunction

Syntax

Sinh(z)
gives the hyperbolic sine of z.

Details

Examples

Sinh(2.0)3.62686

Calculate(Sinh(2), 70)3.626860407847018767668213982801261704886342012321135721309484474934250

Sinh(2.0+3.0*I)-3.59056+0.530921*I

Particular arguments and their result:

Sinh(0)0

Sinh(I*Pi)Sinh(I*Pi)

The hyperbolic sine of the area hyperbolic sine is identity:

Sinh(ArSinh(z))z

See also

ArSinh Cosh Tanh Sin

Slot#function

Syntax

Slot(n)#n
represents nth argument of an anonymous function (Function&).
#
represents the first argument of an anonymous function.

Details

Examples

Select( {0,1,2,3,4,5,6,7,8,9} , #<5 & ){0, 1, 2, 3, 4}

f = Function(#1^#2) f(a, b) f(3, 4)Function(#1^#2) a^b 81

See also

Function&

Sortfunction

Syntax

Sort(list)
sorts the elements of list into canonical order.
Sort(list, cmp)
uses the comparison function cmp for ordering.

Details

Examples

Sort({ "Hello", x+y, 4, 3+I, z}){3+I, 4, "Hello", z, x + y}

Sort( f(3,1,2) )f(1, 2, 3)

Use a comparison function for custom sorting.

Sort( {-3, 2, -1, 0, Pi, 4} ){-3, -1, 0, 2, 4, Pi}

Sort( {-3, 2, -1, 0, Pi, 4}, GreaterEqual ){4, Pi, 2, 0, -1, -3}

Sort( {-3, 2, -1, 0, Pi, 4}, Abs(#1) <= Abs(#2) & ){0, -1, 2, -3, Pi, 4}

During the sort of strings the unicode collation algorithm is used.

Sort({"NINO", "Nina", "Nino", "Ninu", "Niño"}){"Nina", "Nino", "NINO", "Niño", "Ninu"}

Sorting strings by their length:

Sort({"Hello", "Foo", "Baa", "World", "!"}, Length(#1) <= Length(#2) & ){"!", "Foo", "Baa", "Hello", "World"}

See also

Function& Order Orderless

Span..function

Syntax

Span(m, n)m .. n
represents a span between the integers m and n.
Span(m, n, s)m .. n .. s
represents a span between the integers m and n in steps of s.

Details

Examples

"Hello World!"[7..-1]"World!"

"Hello World!"[-1..-6..-1]"!dlroW"

{a, b, c, d, e}[1..5..2]{a, c, e}

See also

Part[…]

Sqrtfunction

Syntax

Sqrt(z)
gives the square root of z.

Details

Examples

Sqrt(16)4

Sqrt(2.0)1.41421

Sqrt(-0.5)0.0+0.707107*I

Particular arguments and their result:

Sqrt(0)0

Sqrt(-1)I

Sqrt(Infinity)Infinity

See also

Power^

String"…",'…'object

Syntax

""
is a text string, a sequence of unicode characters in double quote marks.
''
is a binary string, a sequence of bytes in single quote marks.
String
is the head of a string.

Details and Options

Examples

Text strings with unicode characters:

"abc αβγ \t ♦♥♠♣ \0 fl""abc αβγ \t ♦♥♠♣ \0 fl"

Head("abc αβγ \t ♦♥♠♣ \0 fl")String

Binary strings with bytes are shown as ASCII characters:

'\0\0ÿ7)<''\0\0ÿ7)<'

Head('\0\0ÿ7)<')String

Possible Issues

Strings are not added with Plus+. They must be concatenated with Join~.

"Hello " + "World!""Hello " + "World!"

"Hello " ~ "World!""Hello World!"

Text strings will be converted into binary strings, if they are joined with a binary string.

'Cost: ' ~ "10 €"'Cost: 10 â\x82¬'

See also

ToString Length Part[…]

SubDefine@=function

Syntax

SubDefine(lhs, rhs)lhs @= rhs
evaluates the expression rhs, assign the result as a replacement for the expression lhs, and associates it with symbols occur in the first level of lhs.

Details

Examples

An assignment with SubDefine is associate with the arguments of the expression:

f(beta) @= 22

Definitions(f)/* no definitions */

Definitions(beta)f(beta) = 2

{ f(alpha), f(beta), f(123) }{f(alpha), 2, f(123)}

Assign a special addition for special symbols:

off + off @= off; off + on @= on; on + on @= off;

on + off on + off + onon off

Similar definitions are not always possible with Define= due to protected symbols.

off + on = on;Define.Protected: Plus is protected!

Possible Issues

An assignment with SubDefine@= has a higher priority than an assignment with Define=.

f(alpha) = 1 f(alpha) @= 21 2

f(alpha)2

See also

SubDefineDelayed@:= Define= Clear Pattern Expressionf(…) Symbols

SubDefineDelayed@:=function

Syntax

SubDefineDelayed(lhs, rhs)lhs @:= rhs
assigns the unevaluated expression rhs as a replacement for the expression lhs and associates it with symbols occur in the first level of lhs.

Details

Examples

An assignment with SubDefineDelayed is associate with the arguments of the expression:

f(a(x?)) @:= x^2

Definitions(f)/* no definitions */

Definitions(a)f(a(Pattern(x, ?))) := x^2

{ f(7), f(a(7)), f(a) }{f(7), 49, f(a)}

Assign a special addition for angles:

angle(x?) + angle(y?) @:= angle( Mod(x+y, 360) )

angle(270) + angle(180)angle(90)

Similar definitions are not always possible with DefineDelayed:= due to protected symbols.

angle(x?) + angle(y?) := angle( Mod(x+y, 360) )DefineDelayed.Protected: Plus is protected!

Possible Issues

An assignment with SubDefineDelayed@:= has a higher priority than an assignment with DefineDelayed:=.

f(g(x?)) := x^2 f(g(x?)) @:= x*2

f(g(10))20

See also

SubDefine@= DefineDelayed:= Clear Pattern Expressionf(…) Symbols

Subtract-function

Syntax

Subtract(exp1, exp2)exp1 - exp2
subtracts expression exp2 from exp1.

Details

Examples

3 - 21

2*x - 3*x-x

2 - 1/4 2 - 0.257/4 1.75

See also

Plus+ Minus- Times*

Symbolsobject

Syntax

s
with a sequence of any kind of unicode characters is a symbol, usually called variable.
Symbol
is the head of a symbol.

Details

Examples

Head(var)Symbol

foo + foo2*foo

Assign numbers to a symbol:

x = 123 y = 4123 4

{ x+y, x*y, x^y }{127, 492, 228886641}

Assign expressions to a greek symbol:

φ = a*b^2a*b^2

{ φ , φ/b }{a*b^2, a*b}

Convert a string to a symbol:

ToSymbol("world")world

Possible Issues

Symbol names are case sensitive!

Var = 123123

{Var, var}{123, var}

Built-in symbols are protected against re-definitions.

True := 123 ; 2*TrueDefineDelayed.Protected: True is protected!2*True

See also

ToSymbol Expressionf(…) Define= DefineDelayed:=

Tanfunction

Syntax

Tan(z)
gives the tangent of z.

Details

Examples

Tan(2.0)-2.18504

Calculate(Tan(2), 70)-2.185039863261518991643306102313682543432017746227663164562955869966774

Tan(2.0+3.0*I)-0.00376403+1.00324*I

Particular arguments and their result:

Tan(0)0

Tan(Pi/2)ComplexInfinity

Tan(Pi/3)3^(1/2)

Tan(Pi/4)1

The tangent of the arcus tangent is identity:

Tan(ArcTan(z))z

See also

ArcTan Sin Cos Tanh

Tanhfunction

Syntax

Tanh(z)
gives the hyperbolic tangent of z.

Details

Examples

Tanh(1.0)0.761594

Calculate(Tanh(1), 70)0.7615941559557648881194582826047935904127685972579365515968105001219532

Tanh(2.0+0.5*I)0.979941+0.030216*I

Particular arguments and their result:

Tanh(0)0

Tanh(I*Pi)Tanh(I*Pi)

Tanh(Infinity)1

The hyperbolic tangent of the area hyperbolic tangent is identity:

Tanh(ArTanh(z))z

See also

ArTanh Cosh Sinh Tan

Times*function

Syntax

Times(exp1, exp2, … )exp1 * exp2 *
gives the product of all expressions expi.

Details

Examples

2 * 3 * 424

x^2 * x^3x^5

2 * 1/4 2 * 0.251/2 0.5

Times is flattened and the arguments are sorted.

(a * c) * (b * 4)4*a*b*c

Times threads over List{…}:

{1, 2, 3} * 10{10, 20, 30}

{1, 2, x} * {5, 10, y}{5, 20, x*y}

See also

Divide/ Plus+ Power^

ToIntegerfunction

Syntax

ToInteger(exp)
converts the expression exp to an integer number, if possible.

Details and Options

Examples

Convert any object or expressions to an integer:

ToInteger(3/2)1

ToInteger(-3.1415)-3

ToInteger(5+2*I)5

ToInteger(E)2

ToInteger(Pi^2)9

Convert strings to an integer:

ToInteger("12345")12345

ToInteger("FF", DigitBase->16)255

ToInteger('Oa¼\0', BinaryFormat->"Integer32")12345679

Without specifying BinaryFormat, the whole binary string is interpreted as bytes of an integer:

ToInteger('\0\0\0@êítFÐ\x9C,\x9F\f')1000000000000000000000000000000

Possible Issues

Some expressions or numbers cannot be converted in an integer:

ToInteger(Overflow)ToInteger(Overflow)

ToInteger({1,2,3})ToInteger({1, 2, 3})

See also

Integern ToReal

ToRealfunction

Syntax

ToReal(exp)
converts the expression exp to a real number, if possible.

Details and Options

Examples

Convert any object or expressions to a real number:

ToReal(123)123.0

ToReal(3/5)0.6

ToReal(5+2*I)5.0

ToReal(E)2.71828

ToReal(Pi^2)9.8696

Convert strings to a real number:

ToReal("123.45")123.45

ToReal("FF.8", DigitBase->16)255.5

ToReal('yéöB', BinaryFormat->"float32")123.456

Possible Issues

Some expressions or numbers cannot be converted into a real number:

ToReal(ComplexOverflow)Indeterminate

ToReal({1,2,3})ToReal({1, 2, 3})

See also

Realx Calculate ToInteger

ToStringfunction

Syntax

ToString(str)
gives the text string from a binary string str or vice versa.
ToString(exp)
gives the string representation of the expression exp.

Details and Options

Examples

Convert any object or expressions to a string:

ToString(123)"123"

ToString(3/2)"3/2"

ToString(-3.1415)"-3.141500000000000"

ToString(123.45678901234567890123456789e12345)"1.2345678901234567890123456789e12347"

ToString(5+2*I)"5+2i"

ToString(E)"E"

ToString(Pi^2)"Power(Pi, 2)"

Convert a text string into a binary string and vice versa with the specified format:

ToString("yä€𝄞", BinaryFormat->"UTF16")'y\0ä\0¬ 4Ø\x1EÝ'

ToString('y\0\0\0ä\0\0\0¬ \0\0\x1EÑ\x01\0', BinaryFormat->"UTF32")"yä€𝄞"

Convert a number to a text string with the specified base:

ToString(10000, DigitBase->2)"10011100010000"

ToString(10^100, DigitBase->36)"2HQBCZU2OW52BALA8LGC3S5Y9MM5TIY0VO9TKE25466GFI6AX8GS22X7KUU8L1TDS"

ToString(1024.0625, DigitBase->16)"400.1000000000"

Convert a number to a binary string with the specified format:

ToString(123456, BinaryFormat->"Integer32")'@â\x01\0'

ToString(3.1415, BinaryFormat->"Real64")'o\x12\x83ÀÊ!\t@'

See also

String"…",'…' ToInteger ToReal ToSymbol

ToSymbolfunction

Syntax

ToSymbol(str)
converts the string str to a symbol, if possible.

Details and Options

Examples

ToSymbol("var")var

a = 123;

ToSymbol("a")123

b = "al"; c = "pha"; alpha = 456;

b~c"alpha"

ToSymbol(b~c)456

Possible Issues

An error occurs, when the string does not meet the rules for symbol names:

ToSymbol("3a")ToSymbol.Name: "3a" contains invalid characters for a symbol name.ToSymbol("3a")

ToSymbol("no-var")ToSymbol.Name: "no-var" contains invalid characters for a symbol name.ToSymbol("no-var")

See also

Symbols ToString

Trueconstant

Syntax

True
represents the boolean value true.

Details

Examples

1 == 1True

Not(True)False

See also

False Boole Not! Equal==

Truncfunction

Syntax

Trunc(x)
gives the integer part of x.

Details

Examples

Trunc(-2.1)-2

Trunc(2.9)2

Trunc(-13/8)-1

Trunc(1.2 + 3.8*I)1+3*I

Trunc(Log(10))2

Processing of Overflow and Underflow:

Trunc(Overflow)Overflow

Trunc(Underflow)0

Trunc(-Underflow)0

See also

Ceil Floor

Underflowconstant

Syntax

Underflow
represents an underflow in float-pointing arithmetic.

Details

Examples

Exp(-10.0^20.0)Underflow

Arithmetical and mathematical functions are able to process Underflow:

3.14 + Underflow3.14

Underflow * (-2)-Underflow

3.14 / UnderflowOverflow

Log(Underflow)-Overflow

See also

Overflow ComplexUnderflow

Unequal!=function

Syntax

Unequal(exp1, exp2, … )exp1 != exp2 !=
gives True if all expressions expi are mathematically unequal, and False if they are equal.

Details

Examples

1 != 2True

1 != Pi != 3.0True

The integer 1 and the real number 1.0 are mathematically not unequal, but also not identical.

1 != 1.0 1 === 1.0False False

All argument combination pairs must be unequal.

1 != 2 != 1False

Unequal stays unevaluated if inequality is unknown.

a != ba != b

Possible Issues

Inexact numbers are considered as unequal if more the last one or two decimal digits are different. This allows an easier handling with floating point numbers.

1.0000000000000000002 != 1.0000000000000000001False

1.00000000000000000020 != 1.00000000000000000010True

See also

Same=== Equal==

Unionfunction

Syntax

Union(list)
gives a sorted version of list without duplicates.
Union(list1, list2, … )
gives a sorted list of all distinct elements that appear in any of listi.

Details

Examples

Union( {4,3,3,1} ){1, 3, 4}

Union( {4,3,3,1} , {2,4,4,5} ){1, 2, 3, 4, 5}

Union( {4,3,3,1} , {2,3.0} , {x} ){1, 2, 3, 3.0, 4, x}

Union works with any expressions, not only lists, as long as they have the same head.

Union( a + b , a + c + d )a + b + c + d

Union( f(1, 2), f(2, 3) )f(1, 2, 3)

Possible Issues

Heads have to be the same when Union is applied on expressions.

Union( f(1, 2), g(2, 3) )Union.Heads: Heads f and g are not the same.Union(f(1, 2), g(2, 3))

See also

Join~ Intersection Complement

Xor!!function

Syntax

Xor(bool1, bool2, … )bool1 !! bool2 !!
gives the logical XOR (exclusive OR) booli.
Xor(int1, int2, … )int1 !! int2 !!
gives the binary XOR (exclusive OR) of the integers inti.
Xor(str1, str2, … )str1 !! str2 !!
gives the binary XOR (exclusive OR) of the strings stri.

Details

Examples

True !! True True !! True !! TrueFalse True

12 !! 711

'BINARY' !! 'abc''#+-ARY'

Xor is simplified depending on the number of True occurs in the arguments.

True !! a > 0a <= 0

True !! a > 0 !! Truea > 0

See also

Or|| And&& Not! False True

Assignment and Pattern Matchingoverview

Assignment rules

Define= DefineDelayed:= Clear definition of replacement rules
SubDefine@= SubDefineDelayed@:= subordinate definition of replacement rules
Rule-> RuleDelayed:> definition of transformation rules

Patterns

Any? AnySequence?? AnyNullSequence??? placeholder patterns
Pattern Options assignment pattern
Alternatives| Condition/? Optional: Extension or restriction patterns

Symbol properties

Attributes Definitions properties of a symbol assignment

Assignment attributes

Protected Locked restriction of assignments
HoldAll HoldFirst HoldRest SequenceHold evaluation of arguments

Evaluation attributes

Flat Orderless Listable reconstruction of arguments
NumericFunction NumericConstant OneIdentity numerical evaluation
Temporary storage type

Comparison and Logicoverview

Comparison

Same=== Order canonical comparison
Equal== Unequal!= numerial comparison
Greater> GreaterEqual>= Less< LessEqual<= numerical inequalities
Matching pattern matching
If decision for evaluation flow

Boolean Algebra

False True boolean constants
Boole converts a boolean value into an integer
Not! And&& Or|| Xor!! boolean operators

Core Languageoverview

Object Types

Expressionf(…) expressions with a head and arguments
Symbols named variables, constants or symbols
String"…",'…' character strings or binary data
Integern Rationala/b Realx Complexx+y*I number formats

Object Conversion

ToSymbol ToInteger ToReal ToString convert into other objects
DigitBase BinaryFormat Endianness formatting rules

Evaluation Structures

Compound; Sequence List{…} sequence of expressions
If Scope evaluation flow and scope
Function& Slot# anonymous functions

Output Forms

Output Print InternalForm output formats

Introduction

Getting started

Highlighted features

Lists and Expressionsoverview

Properties

Head Depth Length shape and dimension of lists and expressions
Flat Orderless Listable reconstruction of elements

Handling

Construction and combination

Expressionf(…) List{…} Iterate constucting lists or expressions
Join~ Union Intersection Complement combining lists or expressions

Reshape

Partition subdividing elements
Sort re-order elements
Apply Map/@ replacing heads

Extraction and exchange

Part[…] Span.. Select extracting elements
Replace/: exchange elements

Mathematicsoverview

Objects, Constants and Boundaries

Numbers Types

Integern integer numbers
Rationala/b rational numbers
Realx real numbers
Complexx+y*I complex numbers

Numerical Constants

Pi π ≅ 3.14159
E Euler's number e ≅ 2.71828
EulerMascheroni Euler–Mascheroni constant γ ≅ 0.577216
GoldenRatio golden ratio φ ≅ 1.61803
GoldenAngle golden angle ≅ 137.5°

Numerical Boundaries

Underflow Overflow boundaries of real numbers
ComplexUnderflow ComplexOverflow boundaries of complex numbers
Infinity ComplexInfinity DirectedInfinity mathematical limits
Indeterminate numerical indeterminate

Mathematical Functions

Arithmetic Functions

Plus+ Subtract- first level of arithmetic
Times* Divide/ Mod second level of arithmetic
Power^ Exp Log Sqrt third level of arithmetic

Numerical Functions

Minus- Abs Sign properties of real numbers
Ceil Floor Trunc convert real numbers into integer numbers
Min Max Sort order of numbers

Complex Functions

I imaginary unit
Abs Arg properties of complex numbers
Conjugate Re Im convert complex numbers

Trigonometric Functions

Sin Cos Tan trigonometric functions
ArcSin ArcCos ArcTan inverse trigonometric functions

Hyperbolic Functions

Sinh Cosh Tanh hyperbolic functions
ArSinh ArCosh ArTanh inverse hyperbolic functions

Special Functions

Factorial! Binomial combinatoric functions
Fibonacci Prime number series
Random random numbers

Syntax

Brackets

Expressions

f(x) f(x) Expressionf(…)
f(x)(y) (f(x))(y) Expressionf(…)

Part

x[y] Part(x, y)
x[y][z] Part(Part(x, y), z)
x[y,z,…] Part(x, y, z, …)

Lists

{x, y, …} List(x, y, …)

Strings

"x" String"…",'…'
'x' String"…",'…'

Operators and Separators

Level 20 (high)

?h Any(h)
??h AnySequence(h)
???h AnyNullSequence(h)
s?h Pattern(s, Any(h))
s??h Pattern(s, AnySequence(h))
s???h Pattern(s, AnyNullSequence(h))

Level 19

f @ g @ x f(g(x)) Expressionf(…)

Level 18

x! Factorial(x)

Level 17

x ~ y ~ Join(x, y, …)

Level 16

x ^ y ^ z Power(x, Power(y, z))

Level 15

x * y * Times(x, y, …)
x / y / z Divide(Divide(x, y), z)

Level 14

-x Minus(x)
x + y + Plus(x, y, …)
x - y - z Subtract(Subtract(x, y), z)

Level 13

x == y == Equal(x, y, …)
x != y != Unequal(x, y, …)
x < y < Less(x, y, …)
x <= y <= LessEqual(x, y, …)
x > y > Greater(x, y, …)
x >= y >= GreaterEqual(x, y, …)

Level 12

x === y === Same(x, y, …)
x .. y .. Span(x, y, …)

Level 11

!b Not(b)

Level 10

x || y || Or(x, y, …)
x && y && And(x, y, …)
x !! y !! Xor(x, y, …)

Level 9

x | y | Alternatives(x, y, …)

Level 8

x /? y /? f Condition(x, Condition(y, f))

Level 7

x : y : z Optional(Optional(x, y), z)

Level 6

x -> y -> z Rule(x, Rule(y, z))
x :> y :> z RuleDelayed(x, RuleDelayed(y, z))

Level 5

x /: y /: z Replace(Replace(x, y), z))

Level 4

x // f // g f(g(x)) Expressionf(…)
f /@ g /@ x Map(f, Map(g, x))

Level 3

f & Function(f)

Level 2

x = y = z Define(x, Define(y, z))
x := y := z DefineDelayed(x, DefineDelayed(y, z))
x @= y @= z SubDefine(x, SubDefine(y, z))
x @:= y @:= z SubDefineDelayed(x, SubDefineDelayed(y, z))

Level 1

x ; y ; Compound(x, y, …)

Level 0 (low)

x , y , Sequence(x, y, …)

Lizard – DocumentationKernel Version 0.4.2-0001

Core Language »

Object types Expressionf(…) String"…",'…' Integern
Object conversion ToString ToInteger
Evaluation structures Compound; If List{…}
Output forms Print InternalForm

Assignment and Pattern Matching »

Assignments rules Define= Rule-> Clear
Symbol properties Definitions Attributes Orderless
Pattern types Any? Alternatives| Optional:

Lists and Expressions »

List and expression properties Head Depth Length
Construction and combination Iterate Apply Join~ Union
Extraction and exchange Part[…] Select Replace/:

Comparison and Logic »

Comparison functions Equal== Less< Matching
Boolean algebra And&& Or|| True

Mathematics »

Numerical constants Pi E EulerMascheroni
Numerical boundaries Overflow ComplexUnderflow Infinity
Arithmetic functions Plus+ Times* Power^
Numerical functions Abs Floor Max
Complex functions Arg Conjugate Re
Trigonometric functions Sin ArcCos
Hyperbolic functions Cosh ArSinh
Special functions Factorial! Fibonacci Random