Index

AAbsAccuracyAllAlternativesAndAnyAnyNullSequenceAnySequenceApplyArCoshArSinhArTanhArcCosArcSinArcTanArgAttributes

BBernoulliBinaryFormatBinomialBoole

CCalculateCeilClearClearAttributesComplementComplexComplexInfinityComplexOverflowComplexUnderflowCompoundConditionConjugateContainCosCoshCount

DDefineDefineDelayedDefinitionsDenominatorDepthDigitBaseDirectedInfinityDivide

EEEndiannessEqualEulerMascheroniExpExpandExpression

FFactorialFalseFibonacciFlatFlattenFloorFunction

GGoldenAngleGoldenRatioGreaterGreaterEqual

HHeadHoldAllHoldFirstHoldRest

IIIfImIndeterminateInfinityIntegerInternalFormIntersectionIsEvenIsNumericIsOddIsPrimeIterate

JJoin

LLengthLessLessEqualListListableLockedLog

MMachinePrecisionMapMatchingMaxMinMinusMod

NNestNotNullNumerator

OOptionalOptionsOrOrderOrderlessOutputOverflow

PPartPartitionPatternPiPlusPowerPrecisionPrintProtected

RRandomRationalRationalizeReRealReplaceRoundRuleRuleDelayed

SSameScopeSelectSequenceSequenceHoldSetAttributesShiftLeftShiftRightSignSinSinhSlotSortSpanSplitSqrtStringSubDefineSubDefineDelayedSubtractSymbolSymbols

TTanTanhTimesToIntegerToRealToStringToSymbolTrueTrunc

UUnderflowUnequalUnionUnsame

XXor

Absfunction

Syntax

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

Details

  • Abs is suitable for both symbolic and numerical manipulation.
  • If z is an exact numerical expression, the numerical estimation of z is used to decide about the sign.
  • For special cases of z, some simplifications are performed.
  • Abs has the attribute Listable.

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

Accuracyfunction

Syntax

Accuracy(z)
gives the number of precise decimal digits right of the decimal point of the number z.

Details

Examples

Determine the number's accuracy:

Accuracy(123)Infinity

Accuracy(3/7)Infinity

Accuracy(3.14)14.4577

Accuracy(2.0e24)-9.34644

Accuracy(Overflow)-Infinity

Accuracy(1234567890123456.7890)4.0

Accuracy(4.0 + 3*I)14.3525

See also

Precision Realx MachinePrecision

Allconstant

Syntax

All
can be used to specifies all elements.

Details

  • All can usually be used in Part[…] to pick all element from a particular level.

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

  • Alternatives can be understand as an OR operation for pattern objects, similar to Or|| for logical and binary expressions.

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 excepts 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*Any
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

Apply@@function

Syntax

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

Details

  • After the new head is set, the whole expression is evaluated.

Examples

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

Plus @@ {2, 3, 4}9

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

f @@ (a+b)f(a, b)

Apply will process anonymous function as well:

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

See also

Map/@ Nest Function& Head

ArcCosfunction

Syntax

ArcCos(z)
gives the arcus cosine of z.

Details

  • ArcCos gives an exact result when possible.
  • If z is an exact numerical value, ArcCos remains unevaluated if no exact solution was found.
  • ArcCos gives complex results when z is not real or |z| > 1.
  • ArcCos has the attribute Listable.

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

  • ArCosh gives an exact result when possible.
  • If z is an exact numerical value, ArCosh remains unevaluated if no exact solution was found.
  • ArCosh gives complex results when z is not real or |z| < 1.
  • ArCosh has the attribute Listable.

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

  • ArcSin gives an exact result when possible.
  • If z is an exact numerical value, ArcSin remains unevaluated if no exact solution was found.
  • ArcSin gives complex results when z is not real or |z| > 1.
  • ArcSin has the attribute Listable.

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

  • ArcTan gives an exact result when possible.
  • If z is an exact numerical value, ArcTan remains unevaluated if no exact solution was found.
  • ArcTan has the attribute Listable.

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

ArcTan(-2, 1)Pi - ArcTan(1/2)

See also

Tan ArcCos ArcSin ArTanh

Argfunction

Syntax

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

Details

  • Arg is suitable for both symbolic and numerical manipulation.
  • Arg gives the phase angle in radians between -Pi and Pi.
  • Arg is 0 for positive non-complex numbers, and Pi for negative non-complex numbers.
  • Arg(0) is 0.
  • For special cases of z, some simplifications are performed.

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

  • ArSinh gives an exact result when possible.
  • If z is an exact numerical value, ArSinh remains unevaluated if no exact solution was found.
  • ArSinh gives complex results when z is not real.
  • ArSinh has the attribute Listable.

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

  • ArTanh gives an exact result when possible.
  • If z is an exact numerical value, ArTanh remains unevaluated if no exact solution was found.
  • ArTanh gives complex results when z is not real or |z| > 1.
  • ArTanh has the attribute Listable.

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

  • During the set of attributes all old attributes are removed.
  • The following set of attributes can be used for a symbol f:
    Flat f is associative.
    Orderless f is commutative.
    Listable f is automatically threaded over List{…}.
    Protected Definitions of f cannot be changed.
    Locked Attributes of f cannot be changed.
    HoldAll All argument of f maintain unevaluated.
    HoldFirst The first argument of f maintains unevaluated.
    HoldRest All argument of f, except the first one, maintain unevaluated.
    SequenceHold An expicit Sequence as an argument of f maintains unevaluated.

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

Bernoullifunction

Syntax

Bernoulli(n)
gives the Bernoulli number Bn.

Details

  • The evaluation of Bn uses a summation series by Braun–Romberger–Bentz.
  • Bernoulli has the attribute Listable.

Examples

Bernoulli(2)1/6

Bernoulli(10)5/66

Bernoulli(60)-1215233140483755572040304994079820246041491/56786730

Possible Issues

Bernoulli is left unevaluated for non-integer or negative numbers.

Bernoulli(-2)Bernoulli(-2)

Bernoulli(3.5)Bernoulli(3.5)

See also

Binomial

Reference

BinaryFormatoption

Syntax

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

Details

  • BinaryFormat can be used in ToString, ToInteger, and ToReal.
  • type is a string and can be one of the following formats:
    Integer formats:
    "Integer8", "int8" 8-bit signed integer
    "Integer16", "int16" 16-bit signed integer 1)
    "Integer32", "int32" 32-bit signed integer 1)
    "Integer64", "int64" 64-bit signed integer 1)
    "IntegerN", "intn" n-bit signed integer 1) 2)
    "UnsignedInteger8", "uint8" 8-bit unsigned integer
    "UnsignedInteger16", "uint16" 16-bit unsigned integer 1)
    "UnsignedInteger32", "uint32" 32-bit unsigned integer 1)
    "UnsignedInteger64", "uint64" 64-bit unsigned integer 1)
    "UnsignedIntegerN", "uintn" n-bit unsigned integer 1) 2)
    Floating-point formats:
    "Real16", "float16", "half" 16-bit IEEE 754 floating point number
    "Real32", "float32", "single" 32-bit IEEE 754 floating point number
    "Real64", "float64", "double" 64-bit IEEE 754 floating point number
    "Complex32" Two 16-bit IEEE 754 floating point numbers
    "Complex64" Two 32-bit IEEE 754 floating point numbers
    "Complex128" Two 64-bit IEEE 754 floating point numbers
    String formats:
    "ANSI" Windows codepage 1252 - latin 1 encoded string
    "UTF8" UTF-8 encoded string
    "UTF16" UTF-16 encoded string 1)
    "UTF32" UTF-32 encoded string 1)
    1) By default the order of bytes are handled as little-endian. Use Endianness to change it.
    2) The size depends on the most significant bit and is rounded to a full byte.

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)

Boole({True, False, False}){1, 0, 0}

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

  • Usually, expressions with exclusively exact values, will keep exact results.
    Use Calculate to receive an approximate numerical value of them.
  • Calculate, with a specified precision n, uses internally a higher precision to ensure the required precision of the result.

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

  • If x is an exact numerical expression, the numerical approximation of x is used to establish the result.
  • For a complex number x, Ceil is applied separately to the real and imaginary part.
  • Ceil has the attribute Listable.

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 Round

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, Any))*Pattern(w, Any) @:= Minus(w*z)

Clear(f)

Definitions(f)/* no definitions */

See also

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

ClearAttributesfunction

Syntax

ClearAttributes(s, attr)
removes the attribute attr for symbol s.
ClearAttributes(s, {attr1, attr2, … } )
removes the attributes attri for symbol s.

Details

Examples

Remove the attribute Listable of Boole:

Boole({True, False, True}){1, 0, 1}

ClearAttributes(Boole, Listable){Protected}

Boole({True, False, True})Boole({True, False, True})

See also

Attributes SetAttributes

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

  • If the lists list and listi are considered as sets, Complement gives their complement list \ list1.
  • Complement works with any kind of expressions as long as they have the same head.

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

  • Both parts x and y can be of the type Integern, Rationala/b or Realx.
  • Complex numbers are exact numbers as long as both parts are exact numbers.
  • If either the real part or the imaginary part is an inexact number, the other part is not effected by this inaccuracy.
  • ComplexOverflow and ComplexUnderflow are two special complex numbers representing a float pointing overflow or underflow, respectively.

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 / ComplexUnderflowComplexOverflow

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

  • The condition is only evaluated if the pattern pat matches at all.
  • Condition can be applied to a single pattern object or to a whole expression.
  • In a collection of definitions, the next definition is tried if cond yields not True.
    That distinguishes the use of Condition/? instead of If.

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

  • Conjugate flips the sign of the imaginary part.
  • Conjugate has the attribute Listable.
  • For special cases of z, some simplifications are performed.

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

Containfunction

Syntax

Contain(exp, el)
gives True if exp contains el at any level, and False otherwise.

Details

Examples

Working with lists:

Contain( {1,2,3,4,5} , 3 ) Contain( {1,2,3,4,5} , 6 )True
False

Contain( {1, 2, {31, 32}, 4} , 31 )True

Contain( {1, Pi, 4.5, f()} , ?Real)True

Working with expressions:

Contain( 3+4*x^2, x)True

Contain( 2 + 2*x + 3*x^2 , Condition(x^y?, y>3) ) Contain( 2 + 2*x + 3*x^2 - 5*x^4 , Condition(x^y?, y>3) )False
True

See also

Count Matching Pattern Condition/?

Cosfunction

Syntax

Cos(z)
gives the cosine of z.

Details

  • Cos gives an exact result when possible.
  • If z is an exact numerical value, Cos remains unevaluated if no exact solution was found.
  • z is assumed to be in radians.
  • Cos has the attribute Listable.

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

  • Cosh gives an exact result when possible.
  • If z is an exact numerical value, Cosh remains unevaluated if no exact solution was found.
  • Cosh has the attribute Listable.

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

Countfunction

Syntax

Count(exp, el)
gives the number of elements in exp that match el.
Count(str, sr)
gives the number of sr occurring in str.

Details

  • Usually, exp is a List{…} and Count gives the nummer of members matching el.
  • However, exp can any kind of expression and el can be a pattern object as well.
  • If only the presence have to be checked, instead of exact number of ocurres, Contain is faster than Count.

Examples

Working with lists:

Count( {1, 0, 0, 1, 0} , 1 )2

Count( {a, x, {b, x}, x, c} , x )3

Count( {1, Pi, 4.5, f(), 2.0} , ?Real)2

Working with expressions:

Count( 3+3*x+4*x^2, x)2

Count( 2 + 2*x + 3*x^2 , x^y?)1

Working with strings:

Count( "foobaabaabaafoofoobaa", "baa")4

Count( 'ABAABABAA', 'A')6

Possible Issues

Count uses Matching for comparison and no mathematically equallity.

Count( {2.0, 2.0, 3.0} , 2 ) Count( {2.0, 2.0, 3.0} , 2.0 )0 2

See also

Contain Matching Pattern

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

  • lhs is typically a symbol or an expression with pattern objects.
  • For Define the assignment f(g) = rhs is associate with f, while f(g) @= rhs (SubDefine@=) is associate with g.
  • The expression rhs will evaluated before assignment.
  • Multiple assignments to the same expression head are ordered by their specialization.
  • If lhs and rhs are lists with same length, the assignment is done with corresponding elements.
  • lhs can contain Condition/? to specialize the definition.
  • Clear can be used to remove all assignment rules from a symbol.

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

  • lhs is typically a symbol or an expression with pattern objects.
  • For DefineDelayed the assignment f(g) := rhs is associate with f, while f(g) @:= rhs (SubDefineDelayed@:=) is associate with g.
  • The expression rhs will assigned unevaluated and is always evaluated when lhs is called.
  • Multiple assignments to the same expression head are ordered by their specialization.
  • If lhs and rhs are lists with same length, the assignment is done with corresponding elements.
  • lhs can contain Condition/? to specialize the definition.
  • Clear can be used to remove all assignment rules from a symbol.

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

  • For built-in functions just the assignment pattern is printed.
  • The definitions are printed in order of their specialization, started with the most specialized one.

Examples

Definitions(Plus)Plus(AnyNullSequence) /* 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, Any), x <= 0)) = 0f(Pattern(x, Any)) := f(x - 1) + f(x - 2)

See also

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

Denominatorfunction

Syntax

Denominator(z)
gives the denominator of the number z.

Details

Examples

Denominator(3/7)7

Denominator(-8/3)3

Denominator(123)1

Denominator(3.4)1

Denominator(1/2 + 1/3*I)6

Denominator(f/g)g

Denominator(a^2*b^(-3)*c^4)b^3

See also

Numerator Rationala/b

Depthfunction

Syntax

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

Details

  • For a non-expression objects, Depth is 0.

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

  • DigitBase can be used in ToString, ToInteger, and ToReal.
  • int has to be an integer between 2 and 36.
  • If DigitBase is not explicitly specified, the base 10 is used.
  • For bases larger than ten, the capital letters from A until Z are used.
  • During parsing also the small letters from a until z are valid.

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

  • E is exact and is not evaluated unless it is combined with an inexact computation.
  • E can be calculated with arbitrary precision.
  • For calculations with an arbitrary precision the factorial series is used.

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

  • Equal verify the expressions for mathematical equality, unlike Same===.
  • Inexact numbers are considered as equal if they differ in at most their last five binary digits.

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 === Overflow
Overflow == 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

Unequal!= Same===

EulerMascheroniconstant

Syntax

EulerMascheroni
represents the Euler–Mascheroni constant γ ≅ 0.577216.

Details

  • EulerMascheroni is exact and is not evaluated unless it is combined with an inexact computation.
  • EulerMascheroni can be calculated with arbitrary precision.
  • For calculations with an arbitrary precision the Bessel function method by Brent–McMillan is used.

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

Reference

  • Brent R P, McMillan E M (1979), "Some New Algorithms for High-Precision Computation of Euler’s constant", Math. Comput. 34: 305–312
  • Gourdon X, Sebah P (2004), "The Euler constant : γ", Young 1: 2n

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

  • Expand uses the distributive law and the binomial theorem to expand out exp.

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 using a pattern like Any?:

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

Flatten Attributes Orderless

Flattenfunction

Syntax

Flatten(exp)
flattens out all nested expressions having the same head as exp.
Flatten(exp, n)
flattens only down to depth level n.

Details

Examples

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

Flatten( { a, {b1, b2}, {c1, c2, {c3x, c3y}} } ){a, b1, b2, c1, c2, c3x, c3y}

Using the depth specification:

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

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

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

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

See also

Flat Partition Depth

Floorfunction

Syntax

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

Details

  • If x is an exact numerical expression, the numerical approximation of x is used to establish the result.
  • For a complex number x, Floor is applied separately to the real and imaginary part.
  • Floor has the attribute Listable.

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 Round

Function&function

Syntax

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

Details

  • body usually contains an expression with Slot# elements representing the arguments of this function.
  • body is not evaluated as long as the function receives no arguments.
  • Anonymous functions usually are used in functions like Map/@, Sort or Select.

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

  • GoldenAngle is exact and is not evaluated unless it is combined with an inexact computation.
  • GoldenAngle is defined as
    2 π
    φ2
    = (3 − 5) π.
  • GoldenAngle can be calculated with arbitrary precision.

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

  • GoldenRatio is exact and is not evaluated unless it is combined with an inexact computation.
  • GoldenRatio is defined as φ =
    1+5
    2
    .
  • GoldenRatio can be calculated with arbitrary precision.

Examples

Calculate GoldenRatio:

Calculate(GoldenRatio)1.61803

Calculate(GoldenRatio, 70)1.618033988749894848204586834365638117720309179805762862135448622705260

Arithmetic with GoldenRatio:

GoldenRatio - 1.0/GoldenRatio1.0

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

  • For exact expressions in xi, Greater compares the approximated value.

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

  • For exact expressions in xi, GreaterEqual compares the approximated value.

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

HoldAllattribute

Syntax

HoldAll
is an attribute for symbols to indicate that all arguments maintain unevaluated.

Details

  • HoldAll can be used to prevent the evaluation of all arguments before they are passed to the function.
  • Attributes can be set and get with Attributes.

Examples

Functions like And&& and Iterate have the attribute HoldAll to prevent argument evaluation.

Attributes(And){Flat, HoldAll, Protected}

Prevent the evaluation of all arguments before they are passed, to match the definition pattern:

Attributes(h) = {HoldAll}{HoldAll}

h(x?+y?) := {x, y} /* h has the attribute HoldAll */ f(x?+y?) := {x, y} /* f hasn't the attribute HoldAll */

h(3+7) /* 3+7 holds and matches x?+y? */ f(3+7) /* 3+7 is evaluated to 10 and does not matching */{3, 7} f(10)

See also

Attributes HoldFirst HoldRest

HoldFirstattribute

Syntax

HoldFirst
is an attribute for symbols to indicate that the first arguments maintain unevaluated.

Details

  • HoldFirst can be used to prevent the evaluation of the first argument before it is passed to the function.
  • Attributes can be set and get with Attributes.

Examples

Functions like Define= and SubDefine@= have the attribute HoldFirst to prevent the evaluation of the symbol.

Attributes(Define){HoldFirst, Locked, Protected, SequenceHold}

Prevent the evaluation of the first argument before it is passed, to match the definition pattern:

Attributes(h) = {HoldFirst}{HoldFirst}

h(x?+y?) := {x, y} /* h has the attribute HoldFirst */ f(x?+y?) := {x, y} /* f hasn't the attribute HoldFirst */

h(3+7) /* 3+7 holds and matches x?+y? */ f(3+7) /* 3+7 is evaluated to 10 and does not matching */{3, 7} f(10)

See also

Attributes HoldAll HoldRest

HoldRestattribute

Syntax

HoldRest
is an attribute for symbols to indicate that all arguments except the first one maintain unevaluated.

Details

  • HoldRest can be used to prevent the evaluation of all arguments except the first one before they are passed to the function.
  • Attributes can be set and get with Attributes.

Examples

Functions like If have the attribute HoldRest to prevent argument evaluation, except the first one.

Attributes(If){HoldRest, Protected}

See also

Attributes HoldFirst HoldAll

Iconstant

Syntax

I
represents the imaginary unit i−1.

Details

  • The imaginary part of complex numbers are represented with I.
  • A single I is equivalent to a complex number with a real part of 0 and an imaginary part of 1.

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

  • If z is a real number, Im(z) is 0.
  • Im has the attribute Listable.
  • For special cases of z, some simplifications are performed.

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

Overflow * UnderflowIndeterminate

Infinity - InfinityIndeterminate

See also

Infinity ComplexInfinity

Infinityconstant

Syntax

Infinity
represents the mathematical positive infinite quantity.

Details

Examples

Log(0)-Infinity

Infinity > OverflowTrue

Arithmetical and mathematical functions are able to process Infinity:

1 / Infinity0

Exp(-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

  • Integer numbers can be of any size and are not limited to the word size of the processor.
  • Integer numbers are always exact values.

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~

IsEvenfunction

Syntax

IsEven(n)
gives True if n is an integer and even, and False otherwise.

Details

Examples

IsEven(128)True

IsEven(-5)False

IsEven(4.0)False

IsEven(x)False

IsEven({1,2,3,4}){False, True, False, True}

See also

IsOdd IsNumeric

IsNumericfunction

Syntax

IsNumeric(exp)
gives True if exp is a numeric quantity, and False otherwise.

Details

Examples

Numeric expressions:

IsNumeric(3/7)True

IsNumeric(3+I)True

IsNumeric(Log(Sqrt(2)))True

IsNumeric(Pi)True

Non-numeric expressions:

IsNumeric(a+b)False

IsNumeric({1, 2, 3})False

Results in case of numerical boundaries:

IsNumeric(Underflow)True

IsNumeric(ComplexOverflow)True

IsNumeric(Infinity)False

See also

Object Types

IsOddfunction

Syntax

IsOdd(n)
gives True if n is an integer and odd, and False otherwise.

Details

Examples

IsOdd(127)True

IsOdd(-4)False

IsOdd(3.0)False

IsOdd(x)False

IsOdd({1,2,3,4}){True, False, True, False}

See also

IsEven IsNumeric

IsPrimefunction

Syntax

IsPrime(n)
gives True if n is prime, and False otherwise.

Details

  • IsPrime uses a deterministic variant of the Miller–Rabin primality test.
  • IsPrime becomes slow for n > 3×1023.
  • IsPrime has the attribute Listable.

Examples

IsPrime(127)True

IsPrime(117)False

IsPrime(6549620699)True

IsPrime(79857529916387089718377)True

IsPrime({1,2,3,4,5}){False, True, True, False, True}

See also

IsNumeric

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

  • The expression exp is just evaluated during the iteration, not before.
  • The iterator symbol (i, x or e) is used in a local scope and protected from outer scope.

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){7, 9, 3, 0, 0, 7, 5, 8, 4, 6}

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

  • For neither expression nor string, Length is 0.

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

  • For exact expressions in xi, Less compares the approximated value.

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

  • For exact expressions in xi, LessEqual compares the approximated value.

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

  • Some fundamental built-in symbols and functions are locked.
  • Attributes can be set and get with Attributes.

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

  • After f is applied, the whole expression is evaluated.

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@@ Nest 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== Contain

Maxfunction

Syntax

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

Details

  • Max gives only in case of exclusively real numerical values xi the largest value.
  • For exact expressions in xi, Max compares the approximated value.
  • Max() gives -Infinity.
  • Max(exp) gives exp.

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(4, "test", 2+I)

See also

Min Greater>

Minfunction

Syntax

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

Details

  • Min gives only in case of exclusively real numerical values xi the smallest value.
  • For exact expressions in xi, Min compares the approximated value.
  • Min() gives Infinity.
  • Min(exp) gives exp.

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(-5, "test", 2+I)

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- Plus+ Times* Not!

Modfunction

Syntax

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

Details

  • The sign of n is used as the sign of the remainder.
  • Mod is suitable for both symbolic and numerical manipulation.
  • Mod works also with rational, real, and complex numbers.
  • Mod has the attribute Listable.
  • In cases of general expressions in m and n simplifications are tried.

Examples

Mod(7, 3)1

Mod(4.0, 1.2)0.4

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

Mod(7+8*I, 3+3*I)1+2*I

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

Nestfunction

Syntax

Nest(f, exp, n)
gives an expression with f applied n times to exp.

Details and Options

Examples

Nest(f, x, 4)f(f(f(f(x))))

Nest(Function((#+1)^2), x, 3)(1 + (1 + (1 + x)^2)^2)^2

Searching for fix-points:

Nest(Cos, 0.0, 100)0.739085

Cos(0.739085)0.739085

Imitate exponential growth:

Nest(Function(1.02*#), 100.0, 10)121.899

100.0 * 1.02^10121.899

See also

Function& Iterate Map/@ Apply@@

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

Numeratorfunction

Syntax

Numerator(z)
gives the numerator of the number z.

Details

Examples

Numerator(3/7)3

Numerator(-8/3)-8

Numerator(123)123

Numerator(3.4)3.4

Numerator(1/2 + 1/3*I)3+2*I

Numerator(f/g)f

Numerator(a^2*b^(-3)*c^4)a^2*c^4

See also

Denominator Rationala/b

Optional:function

Syntax

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

Details

  • Optional can be used to define a default value in function's arguments.
  • Optional can be used at any position, not only at the end of arguments.

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

  • Options is typically used in definition of functions for additional arguments attributed by their names.
  • Arguments and default values in Options can either by defined with Rule-> or RuleDelayed:>.

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} {1, 1, 1, 1, 1} {6, 2, 8, 0, 10}

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

  • Output generates a newline (carriage return and line feed) only on top level.
  • In in deeper levels Output remains to avoid syntax errors.

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

Infinity > OverflowTrue

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 ) Numerator( 3/4 )Part.Depth: Part specification (3/4)[1] is longer than depth of object.(3/4)[1] 3

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

  • If the length of exp is no multiple of n, some elements will be disregarded.

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

Split Flatten 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

Using the short form of Pattern in functional definitions:

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

g(x??) := Times(x) g(3) g(4, 5) g(a, 6, x^2)3 20 6*a*x^2

h(Pattern(x, ?Integer|Infinity)) := x^2 { h(1), h(-5), h(Infinity), h(3.14) }{1, 25, Infinity, h(3.14)}

Using Pattern during a replacement: