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:

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

Replace( {1, 2, a, b, c, 3.14} , Pattern(x, a|b) :> x^3 ){1, 2, a^3, b^3, c, 3.14}

See also

Any? AnySequence??

Piconstant

Syntax

Pi
represents the constant π ≅ 3.14159.

Details

  • Pi is exact and is not evaluated unless it is combined with an inexact computation.
  • Pi can be calculated with arbitrary precision.
  • For calculations with an arbitrary precision the Bailey–Borwein–Plouffe formula is used.

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

References

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 is 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

  • Power is suitable for both symbolic and numerical manipulation.
  • Power has the attribute Listable.
  • In case of exact arguments, Power tries to evaluate an exact number.
  • For complex numbers and calculations with an arbitrary precision the identity x^y = Exp(y*Log(x)) is used.

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

Accuracy 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

  • If expn is a string, only its content is shown and control characters are taken into account.
  • If expi is Null no print is performed. Using Null in explast, the result is hidden from output.
  • Print can be used to trace calculations in a more complex evaluation.

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))5628802164249

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

  • All built-in symbols and functions are protected.
  • Attributes can be set and get with Attributes.

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 pseudo-random number between 0 and z.
Random(z, n)
gives a list of n pseudo-random numbers between 0 and z.
Random(str)
gives a pseudo-random character from the string str.
Random(str, n)
gives a string of length n with pseudo-random characters from the string str.
Random(list)
gives a pseudo-random element from the list list.
Random(list, n)
gives a list of n pseudo-random element from the list list.

Details and Options

  • Depending on the head of z (Integer, Rational, Real or Complex), Random gives either only integer numbers, rational numbers, real numbers, or complex numbers, respectively.
  • For a complex number z, Random is performed for the real part and imaginary part.
  • For a rational number z = a/b, the resulting numbers are in steps of 1/b.
  • By using an element in list or a character in str multiple times, this element/character can be weighted higher in the result.
  • Random('', n) gives a pseudo-random binary string of length n.

Examples

Single random numbers, characters or elements:

Random(7)2

Random(30!)131112539364443365627843747472343

Random(2/3)0

Random(2.0)1.65005

Random(1.0+2.0*I)0.0486851+0.787946*I

Random("abcdefgh")"a"

Random( {a, b, c} )b

List of random numbers or elements:

Random( 9, 10 ){7, 1, 1, 2, 5, 0, 2, 0, 0, 9}

Random( 1.0, 10 ){0.829788, 0.87827, 0.975789, 0.217687, 0.792255, 0.941381, 0.975834, 0.416979, 0.758154, 0.795138}

Random( {True, False}, 10 ){False, False, True, True, True, False, False, True, False, True}

Generate a string with random characters:

Random("ABC", 20)"ABAABAACBCBBBBBAAABB"

Random("---|", 40)"|--------------||--|-----|||-|------|---"

Generate a random binary string:

Random('', 32)'\x01müàóK3a·\x981Ò»dÞy\x1Dö\x19Ô"zICºõOSáï[¸'

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

  • The numerator a and denoninator b can be numbers of any size and are not limited to the word size of the processor.
  • Rational numbers are reduced as much as possible.
  • Rational numbers are always exact values.
  • a/b uses the same operator level as Divide/.

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

Rationalizeoption

Syntax

Rationalize -> FalseRationalize -> True
is an option to define whether integers are converted to rationals when shifting bits.

Details

Examples

ShiftRight(15) ShiftRight(15, Rationalize->False) ShiftRight(15, Rationalize->True)7 7 15/2

ShiftRight(4, 5) ShiftRight(4, 5, Rationalize->True)0 1/8

See also

ShiftLeft ShiftRight

Refunction

Syntax

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

Details

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

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

  • Real numbers can be of any precision and magnitude.
  • Real numbers are stored with machine precision (64-bit IEEE float pointing number) if possible.
  • Real numbers with machine precision displayed only with 6 precision digits, but full IEEE precision is tracked.
  • Real numbers are inexact values and the precision can be received with Precision.
  • Calculations with at least one inexact value lead to an inexact result.
  • Overflow and Underflow are two special real numbers representing a float pointing overflow or underflow.

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(exp, rule, depth)
applies the rule rule to the expression exp and its sub-expressions down to depth level depth.
Replace(str, a->b )str /: a->b
replaces all sub-strings a in the string str with b.
Replace(str, {a1->b1, a2->b2, … } )str /: {a1->b1, a2->b2, … }
replaces all sub-strings ai in the string str with bi.

Details

  • Replace applies the rules starting from the lowest depth to the deepest level.
  • Without specification of depth or if depth = Infinity, replacements are performed as deep as possible.
  • Rules can be defined as Rule-> as well as RuleDelayed:>.
  • Once a rule was applied to a sub-expression, no more replacements will be applied to this sub-expression.
  • Once a rule was applied to a string part, no more replacements will be applied to this part.
  • When one of the strings str, ai or bi is binary, the result is binary too.

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, with depth level specification:

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

Replace( {x, x, {x, x, {x, x}}, x} , x->0 , 2 ){0, 0, {0, 0, {x, x}}, 0}

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

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

The replacing rule can contain any kind of pattern:

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

{1, 2, Pi, 4, -5} /: Condition( x?, x>3) :> -x{1, 2, -Pi, -4, -5}

Replace a sub-string:

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

Exchange multiple characters:

"AB_AABB" /: {"A"->"B", "B"->"A"}"BA_BBAA"

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){6, 6, 6, 6, 6}

{x, x, x, x, x} /: x :> Random(10){5, 8, 0, 4, 7}

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

Roundfunction

Syntax

Round(x)
gives the integer closest to x.

Details

  • Round rounds .5 numbers towards the nearest even integer (bankers' rounding).
  • If x is an exact numerical expression, the numerical approximation of x is used to establish the result.
  • For a complex number x, Round is applied separately to the real and imaginary part.
  • Round has the attribute Listable.

Examples

Round(2.9)3

Round(2.1)2

{Round(0.5), Round(1.5)}{0, 2}

Round(-13/8)-2

Round(1.2 + 3.8*I)1+4*I

Round(Log(10))2

Processing of Overflow and Underflow:

Round(Overflow)Overflow

Round(Underflow)0

See also

Ceil Floor Trunc

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, 574, 2, 743, 3, 29}

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

  • Same is evaluated immediately and always gives False or True.
  • Same verify the expressions for exact correspondence and ignores the mathematical equality, unlike Equal==.

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

Symbol names are case sensitive!

A === aFalse

See also

Unsame=!= Equal== 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

  • sym can be either a single symbol or an assignment like Define= or DefineDelayed:=.
  • Scope replaces all symbols symi in body by unique symbols protected from the outer scope.
  • Unique symbols are specified by a $-character followed by an unique index.

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}

Define temporary symbols:

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

{z, w}{z, w}

Define temporary functions:

Scope(f(x?) := x^2, {f(5), f(y)} ){25, y^2}

f(5)f(5)

Possible Issues

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

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

See also

Function& Define= DefineDelayed:=

Selectfunction

Syntax

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

Details

  • list can be any expression, no necessarily a List{…}.
  • crit should be a function receiving an element ei from list as argument and returning True or False.
  • Usually, crit is a query or an anonymous function.

Examples

Select( {1,2,3,4,5,6,7} , IsEven ) Select( {1,2,3,4,5,6,7} , IsPrime ){2, 4, 6} {2, 3, 5, 7}

Select( {"Hello", x+y, 4, 3+I, "World!", z} , Matching(#, ?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, IsNumeric )1 + E - Pi

See also

Function& Matching 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??? SequenceHold

SequenceHoldattribute

Syntax

SequenceHold
is an attribute for symbols to indicate that a Sequence is not expanded during the evaluation of the arguments.

Details

Examples

Functions like Define= and Output have the attribute SequenceHold to prevent sequence expansion.

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

Prevent the expansion of a Sequence before it is passed:

Attributes(h) = {SequenceHold}{SequenceHold}

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

h(Sequence(1, 2)) /* Sequence(1, 2) holds and is passed as x */ f(Sequence(1, 2)) /* Sequence(1, 2) is expanded and is passed as x and y */{{1, 2}, {0}} {{1}, {2}}

See also

Attributes Sequence HoldAll

SetAttributesfunction

Syntax

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

Details

Examples

Add the attribute Flat to f:

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

SetAttributes(f, Flat){Flat}

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

See also

Attributes ClearAttributes

ShiftLeftfunction

Syntax

ShiftLeft(z)
shifts the bits in z one bit to the left.
ShiftLeft(z, k)
shifts the bits in z by k bits to the left.

Details and Options

  • z is handled on its binary form and can be numerical as well as a string.
  • For a complex number z, ShiftLeft is applied separately to the real and imaginary part.
  • Negative values of k shift to the right.
  • The following option can used:
    Rationalize Handling of integers when bits would be dropped. The default value is False.

Examples

ShiftLeft(32)64

ShiftLeft(32, 4)512

ShiftLeft(32, -2)8

ShiftLeft(2.5, 2)10.0

ShiftLeft(2/7, 3)16/7

ShiftLeft('ABC', 4)'\x10$4'

The option Rationalize can be used to convert integers into rationals:

ShiftLeft(6, -2)1

ShiftLeft(6, -2, Rationalize->True)3/2

Possible Issues

On memory level, ShiftLeft shifts the bits to higher positions, effectively to the right:

ShiftLeft('ABCDEFGH', 32)'\0\0\0\0ABCD'

See also

ShiftRight

ShiftRightfunction

Syntax

ShiftRight(z)
shifts the bits in z one bit to the right.
ShiftRight(z, k)
shifts the bits in z by k bits to the right.

Details and Options

  • z is handled on its binary form and can be numerical as well as a string.
  • For a complex number z, ShiftRight is applied separately to the real and imaginary part.
  • Negative values of k shift to the left.
  • The following option can used:
    Rationalize Handling of integers when bits would be dropped. The default value is False.

Examples

ShiftRight(32)16

ShiftRight(32, 4)2

ShiftRight(32, -2)128

ShiftRight(2.5, 2)0.625

ShiftRight(2/7, 3)1/28

ShiftRight('ABC', 4)'$4\x04'

The option Rationalize can be used to convert integers into rationals:

ShiftRight(6, 2)1

ShiftRight(6, 2, Rationalize->True)3/2

Possible Issues

On memory level, ShiftRight shifts the bits to lower positions, effectively to the left:

ShiftRight('ABCDEFGH', 32)'EFGH\0\0\0\0'

See also

ShiftLeft

Signfunction

Syntax

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

Details

  • Sign is suitable for both symbolic and numerical manipulation.
  • In case of real numbers, Sign gives -1, 0, or +1, if z is negative, zero, or positive, respectively.
  • In case of complex numbers, Sign(z) is defined as z/Abs(z).
  • If z is an exact numerical expression, the numerical estimation of z is used to decide about the sign.
  • Sign has the attribute Listable.
  • For special cases of z, some simplifications are performed.

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

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

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

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

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", x + y, z}

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

  • Negative integers for m or n count from the end in the respective scope.
  • A negative integer for s count backwards.
  • Span is typically used in Part[…].

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[…]

Splitfunction

Syntax

Split(str, del)
splits the string str into a list of sub-strings separated by the delimiter del.
Split(exp, el)
splits the expression exp into sub-expressions separated by the element el.

Details

  • If del is an empty string ("" or ''), str is splitted into single characters.
  • If str or del is a binary string, the result is a list of binary strings.
  • Split can work with any kind of expressions, not only lists.

Examples

Split( "Grumpy wizards make toxic brew for the evil Queen and Jack" , " " ){"Grumpy", "wizards", "make", "toxic", "brew", "for", "the", "evil", "Queen", "and", "Jack"}

Split( "Hello\r\nWorld!" , "\r\n" ){"Hello", "World!"}

Split( {1, 2, 0, 3, 4, 0, 5, 6} , 0 ){{1, 2}, {3, 4}, {5, 6}}

Split( h(a,x,b,c,x,d,e,f) , x )h(h(a), h(b, c), h(d, e, f))

See also

Partition Part[…] Join~

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

Sqrt({16, 100, -4}){4, 10, 2*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

  • Text strings are stored in UTF-8 format.
  • In the sequence the \-character is used to mask the following special and unprintable characters:
    \0 NUL \f FF
    \a BEL \r CR
    \b BS \" "
    \t TAB \' '
    \n LF \\ \
    \v VT \x00\xFF Two-digit hexadecimal code
  • Strings can be contain the null-character.
  • Strings can be converted with ToString between text form and binary form or any kind of object.

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

  • lhs is typically an expression with pattern objects.
  • For SubDefine the assignment f(g) @= rhs is associate with g, while f(g) = rhs (Define=) is associate with f.
  • The expression rhs will evaluated before assignment.
  • 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

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

  • lhs is typically an expression with pattern objects.
  • For SubDefineDelayed the assignment f(g(x)) @:= rhs is associate with g, while f(g(x)) := rhs (DefineDelayed:=) is associate with f.
  • The expression rhs will assigned unevaluated and is always evaluated when lhs is called.
  • 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

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, Any))) @:= 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:=

Symbolsfunction

Syntax

Symbols()
gives a list of all defined symbols.
Symbols(str)
gives a list of defined symbols matching string str.

Details

  • Symbols gives all built-in symbols and all self-defined symbols.
  • The search string str can contain the wildcard characters ? (one character) und * (no or multiple characters).

Examples

Symbols(){Abs, Accuracy, All, Alternatives, And, Any, AnyNullSequence, AnySequence, Apply, ArCosh, ArSinh, ArTanh, ArcCos, ArcSin, ArcTan, Arg, Attributes, Bernoulli, BinaryFormat, Binomial, Boole, Calculate, Ceil, Clear, ClearAttributes, Complement, Complex, ComplexInfinity, ComplexOverflow, ComplexUnderflow, Compound, Condition, Conjugate, Contain, Cos, Cosh, Count, Define, DefineDelayed, Definitions, Denominator, Depth, DigitBase, DirectedInfinity, Divide, E, Endianness, Equal, EulerMascheroni, Exp, Expand, Factorial, False, Fibonacci, Flat, Flatten, Floor, Function, GCD, GoldenAngle, GoldenRatio, Greater, GreaterEqual, GreatestCommonDivisor, Head, Hold, HoldAll, HoldFirst, HoldRest, I, If, Im, Indeterminate, Infinity, Integer, InternalForm, Intersection, IsEven, IsNumeric, IsOdd, IsPrime, Iterate, Join, Kernel, Length, Less, LessEqual, List, Listable, Locked, Log, MachinePrecision, Map, Matching, Max, Min, Minus, Mod, Nest, None, Not, Null, Numerator, NumericConstant, NumericFunction, OneIdentity, Optional, Options, Or, Order, Orderless, Output, Overflow, Part, Partition, Pattern, Pi, Plus, Power, Precision, Print, Protected, Random, Rational, Rationalize, Re, Real, Replace, Round, Rule, RuleDelayed, Same, Scope, Select, Sequence, SequenceHold, SetAttributes, ShiftLeft, ShiftRight, Sign, Sin, Sinh, Slot, Sort, Span, Split, Sqrt, String, SubDefine, SubDefineDelayed, Subtract, Symbol, Symbols, Tan, Tanh, Temporary, Times, ToInteger, ToReal, ToString, ToSymbol, True, Trunc, Underflow, Unequal, Union, Unsame, Xor}

All symbols beginning with Complex:

Symbols("Complex*"){Complex, ComplexInfinity, ComplexOverflow, ComplexUnderflow}

All symbols containing Sin:

Symbols("*Sin*"){ArSinh, ArcSin, Sin, Sinh}

All symbols with two characters:

Symbols("??"){If, Im, Or, Pi, Re}

See also

Attributes Definitions Define= Symbols

Tanfunction

Syntax

Tan(z)
gives the tangent of z.

Details

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

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

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

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

  • exp can be any expression or object like a number, a string or a symbol.
  • ToInteger removes the fractional part of a rational or real number, similar to Trunc.
  • ToInteger clears the imaginary part of a complex number, unlike Trunc.
  • The following options can be used if exp is a string:
    DigitBase Base of the digits to parse from a text string. The default base is 10.
    BinaryFormat Format, how to parse a binary string.
    Endianness Byte order in a binary string.

Examples

Convert any object or expressions to an integer:

ToInteger(5/3)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 unsigned integer:

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

Possible Issues

Some expressions or numbers cannot be converted in an integer:

ToInteger(Overflow)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

  • exp can be any expression or object like a number or a symbol.
  • Expressions are converted into strings via the internal format.
  • The following option can used:
    BinaryFormat Format of the string encoding.
    DigitBase Base of the digits in a text string. The default base is 10.
    Endianness Byte order in a binary string.

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+2*I"

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

  • str must respect the rules for symbol names, see Symbols.

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

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

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 Round

Underflowconstant

Syntax

Underflow
represents an underflow in float-pointing arithmetic.

Details

Examples

Exp(-10.0^20.0)Underflow

0.0 < UnderflowTrue

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 any of them are equal.

Details

  • Unequal verify the expressions for mathematical inequality, unlike Unsame=!=.
  • Inexact numbers are considered as unequal if they differ in more then their last five binary digits.

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

Equal== Unsame=!=

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

  • If the lists listi are considered as sets, Union gives their union list1list2.
  • Union works with any kind of expressions as long as they have the same head.

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

Intersection Complement Join~

Unsame=!=function

Syntax

Unsame(exp1, exp2, … )exp1 =!= exp2 =!=
gives True if all expressions expi are non-identical to each other, and False otherwise.

Details

  • Unsame is evaluated immediately and always gives False or True.
  • Unsame verify the expressions for exact correspondence and ignores the mathematical unequality, unlike Unequal!=.

Examples

123 =!= "text"True

x =!= yTrue

f(5) =!= f(5)False

All argument combination pairs must be non-identical.

x =!= y =!= xFalse

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

1 =!= 1.0 1 != 1.0True
False

Possible Issues

Unsame=!= is evaluated immediately, while Unequal!= is keep unevaluated until a decision is possible.

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

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

Symbol names are case sensitive!

A =!= aTrue

See also

Same=== Unequal!= Matching

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 !! True
False
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

Arithmetic Functionsoverview

Fundamental Functions

Plus+ gives the sum of all arguments
Minus- gives the arithmetic negation of a number
Subtract- subtracts subsequent arguments from the first argument
Times* gives the product of all arguments
Divide/ divides the first argument by the second argument

Advanced Functions

Mod gives the remainder on a devision
Power^ gives the power of two numbers
Sqrt gives the square root of a number
Exp gives the exponential of a number
Log gives the logarithm of a number

Assemblingoverview

Construction

Expressionf(…) object with a head and sub-objects as elements
List{…} represents a list of elements
Iterate gives a list of results of an iteration

Combination

Join~ gives a joined expression or string
Union gives the union set between lists
Intersection gives the intersection set between lists
Complement gives the complement set between lists

Assignment and Pattern Matchingoverview

Assignments

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

Symbols list of symbols with assignments
Attributes Definitions properties of a symbol assignment
SetAttributes ClearAttributes changing properties of a symbol

Assignment attributes

Protected Locked restriction of assignments

Evaluation attributes

HoldAll HoldFirst HoldRest SequenceHold evaluation of arguments
Flat Orderless Listable reconstruction of arguments
NumericFunction NumericConstant OneIdentity numerical evaluation
Temporary storage type

Assignmentsoverview

Direct Assignments

Clear removes all assignment rules
Define= assigns an expression to an other expression
DefineDelayed:= assigns an expression to an other expression with delayed evaluation
SubDefine@= assigns subordinated an expression to an other expression
SubDefineDelayed@:= assigns subordinated an expression to an other expression with delayed evaluation

Transformations

Rule-> defines a transformation rule between expressions
RuleDelayed:> defines a transformation rule between expressions with delayed evaluation

Binary Functionsoverview

Bit Shift

ShiftRight performs a bit shift to the right
ShiftLeft performs a bit shift to the left

Bit Operations

And&& performs a locical or binary AND operation
Not! performs a locical or binary NOT operation
Or|| performs a locical or binary OR operation
Xor!! performs a locical or binary XOR operation

Boolean Algebraoverview

Constants

False represents the boolean value false
True represents the boolean value true

Functions

Boole converts a boolean value to an integer
Not! performs a locical or binary NOT operation
And&& performs a locical or binary AND operation
Or|| performs a locical or binary OR operation
Xor!! performs a locical or binary XOR operation

Comparisonoverview

Numerical Comparison

Equal== compares for mathematical equality
Unequal!= compares for mathematical unequality
Greater> compares regarding strictly greater
GreaterEqual>= compares regarding greater or equal
Less< compares regarding strictly less
LessEqual<= compares regarding less or equal

Canonical Comparison

Same=== compares in terms of strictly identical
Unsame=!= compares in terms of strictly non-identical
Order gives the canonical order two objects or expressions

Topological Comparison

Matching performs a pattern matching

Comparison and Logicoverview

Comparison

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

Queries

Contain expressional queries
IsNumeric IsPrime IsEven IsOdd numerical queries

Boolean Algebra

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

Complex Functionsoverview

Abs gives the absolute value of a number
Arg gives the argument of a number
Sign gives the sign of a number
Conjugate gives the complex conjugate of a number
Im gives the imaginary part of a complex number
Re gives the real part of a complex number

Core Languageoverview

Object Types

Expressionf(…) object with a head and sub-objects as elements
Symbols placeholder for any kind of objects
String"…",'…' sequence of unicode characters or binary bytes
Integern Rationala/b Realx Complexx+y*I number formats

Object Properties

Head Depth Length general structural properties
Contain Count composition of expression
Accuracy Precision numerial properties

Object Conversion

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

Evaluation Constructs

Compound; Sequence List{…} sequence of expressions
If Scope procedural programming
Apply@@ Map/@ Nest functional programming
Function& Slot# anonymous functions

Output Forms

Output Print InternalForm output formats

Evaluation Constructsoverview

Expression Sequences

Sequence represents a sequence of arguments
Expressionf(…) object with a head and sub-objects as elements
List{…} represents a list of elements
Compound; evaluates all expressions in turn

Procedural Programming

If evaluates a specified expression depending of the condition
Scope evaluation using symbols in a local scope

Functional Programming

Function& represents anonymous function
Slot# represents an argument of an anonymous function
Apply@@ replaces the head of an expression
Map/@ applies a head to each element in an expression
Nest gives a nested expression

Extraction and Exchangeoverview

Part[…] gives a part of an expression or a string
All specifies all elements
Span.. represents a span between two integers
Select gives all elements fitting the criteria
Flatten flattens a list or expression and reduces the depth
Partition partitions an expression or string
Split splits an expression or a string
Replace/: applies replacement rules to an expression or a string

History

0.4.3

0.4.3-0001 (Jun 5, 2022)

0.4.2

0.4.2-0001 (Sep 18, 2021)

0.4.0

0.4.0-0005 (Mar 20, 2021)

  • ADDED: support for Linux OS
  • FIXES: small bug-fixes

0.4.0-0001 (Mar 13, 2021)

0.3.8

0.3.8-0012 (Nov 21, 2020)

  • ADDED: x86 support
  • ADDED: two more examples for pure basic implementation
  • ADDED: Floor, Ceil, Trunc, Order
  • FIXES: small bug-fixes

0.3.8-0002 (Nov 15, 2020)

  • First publication

Hyperbolic Functionsoverview

Sinh gives the hyperbolic sine of a number
Cosh gives the hyperbolic cosine of a number
Tanh gives the hyperbolic tangent of a number

ArSinh gives the area hyperbolic sine of a number
ArCosh gives the area hyperbolic cosine of a number
ArTanh gives the area hyperbolic tangent of a number

Introduction

Getting started

  • The syntax of Lizard is organized in six different types of input tokens:
    Numbers 123 , 3.14 a sequence of decimal digits with an optional decimal point
    Operators + , !=, -> individual defined character groups
    Symbols x , φ, var a sequence of any unicode characters which are not defined as operator
    Strings "yä€𝄞" , '\0\0\0ÿ' a sequence of unicode or binary characters
    Expressions head(arg1, arg2) a function with a head and arguments
    Comments /* no code */ not interpreted code blocks
  • In Lizard all operators are just the short form of their functional definition.
    This means, you can either enter calculations in operator form like 2 + 3 ^ 5 or in functional form like Plus(2, Power(3, 5)).
  • Lizard is a symbolic computation scripting language.
    This means, you can either perform a numerical calculation like 1 + 2 * 3 which will give 7,
    or a symbolic evaluation like 2*a - 3*a which will give -a.
    Everything which can not evaluated into a simple object type will be kept and handled as a general symbolic expression.
    Most of the built-in functions of Lizard working also with such general symbolic expressions.
  • Lizard uses polymorphic functions.
    This means, functions like Random() give different results depending on parameter type and count.
  • Many functions in Lizard use optional arguments or named parameters in form like option -> value.
    This allows a specification of functions without a restricted sequence of arguments.
  • Lizard keeps calculation exact as long as exact inputs are given.
    This means, an input like Cos(Pi/6) gives 1/2*3^(1/2), while an input like Cos(Pi/6.0) gives 0.866025.
    To perform fast numerical calculations it is advised to use floating point numbers.
  • Lizard performs calculations first of all with fast processor word sized (64-bit) integers as well as floating point numbers.
    Only if larger integers or floating point numbers with huge magnitudes or higher precisions are needed, slower arbitrary size and arbitrary precision arithmetic is performed.

Highlighted features

  • Full support of symbolic expression.
  • Support of arbitrary size integers.
  • Support of real numbers with arbitrary precision.
  • Support of rational and complex numbers.
  • Full unicode character string and binary string support.
  • Support of polymorphic or anonymous functions.
  • Powerful pattern matching engine for assignments and replacements.
  • Overloading of built-in functions for custom definitions.
  • Support of named parameters in functions.
  • High flexibility in work with subparts of strings, lists or general expressions.
  • Numerous conversion functions, supporting different number formats and string formats under consideration of endianness and digit base.

Lists and Expressionsoverview

Assembling

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

Extraction and Exchange

Part[…] Span.. All Select extracting elements
Partition Split subdividing elements
Replace/: exchange elements

Mathematicsoverview

Objects, Constants and Boundaries

Numbers Types

Integern exact integer number
Rationala/b fractional number with numerator and denominator
Realx inexact real number with arbitrary precision
Complexx+y*I complex number with real and imaginary part

Numerical Constants

I represents the imaginary unit
Pi E EulerMascheroni fundamental constants
GoldenRatio GoldenAngle other constants

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- Minus- first level of arithmetic
Times* Divide/ Mod second level of arithmetic
Power^ Exp Log Sqrt third level of arithmetic

Numerical Functions

Calculate numerial evaluation of an expression
Abs Sign properties of real numbers
Ceil Floor Trunc Round convert real numbers into integer numbers
Min Max 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

Binary Functions

ShiftLeft ShiftRight bit shift
And&& Not! Or|| Xor!! bit operations

Special Functions

Factorial! Binomial combinatoric functions
Fibonacci Bernoulli number series
Random random numbers
Expand expands out products and integer powers

Numerical Boundariesoverview

Indeterminate represents a mathematical quantity whose magnitude is undetermined

Real Boundaries

Underflow represents an numerical underflow
Overflow represents an numerical overflow

Complex Boundaries

ComplexUnderflow represents an underflow in complex numbers
ComplexOverflow represents an overflow in complex numbers

Infinities

Infinity mathematical positive infinite quantity
ComplexInfinity mathematical infinite quantity with an undetermined complex phase
DirectedInfinity mathematical infinite quantity with an known complex phase

Numerical Constantsoverview

I represents the imaginary unit
E represents the constant e ≅ 2.71828
Pi represents the constant π ≅ 3.14159
EulerMascheroni represents the constant γ ≅ 0.577216
GoldenRatio represents the golden ratio φ ≅ 1.61803
GoldenAngle represents the golden angle ≅ 137.5°

Numerical Functionsoverview

Calculate gives an approximate numerical value
Sign gives the sign of a number
Abs gives the absolute value of a number
Min gives the smallest number
Max gives the largest number

Rounding Functions

Ceil rounds toward positive infinity
Floor rounds toward negative infinity
Trunc rounds toward zero
Round rounds toward the nearest integer

Bit Functions

ShiftRight performs a bit shift to the right
ShiftLeft performs a bit shift to the left

Rational Functions

Numerator gives the numerator of an expression
Denominator gives the denominator of an expression

Object Conversionoverview

Functions

ToInteger converts an expression to an integer number
ToReal converts an expression to a real number
ToString gives the string representation of an expression
ToSymbol converts a string to a symbol

Option Rules

DigitBase is an option to define the digit base for number representations
BinaryFormat is an option to define the binary format for numeric and string representations
Endianness is an option to define the endianness

Object Propertiesoverview

Head gives the head of an expression
Depth gives nesting depth of an expression
Length gives the length of an expression or a string
Contain query for containing elements
Count count for matching elements or strings

Numerical properties

Precision gives the number of precise decimal digits of the number
Accuracy gives the number of precise decimal digits right of the decimal point

Object Typesoverview

Expressionf(…) object with a head and sub-objects as elements
Symbols placeholder for any kind of objects
String"…",'…' sequence of unicode characters or binary bytes

Numerical types

Integern exact integer number
Rationala/b fractional number with numerator and denominator
Realx inexact real number with arbitrary precision
Complexx+y*I complex number with real and imaginary part

Output Formsoverview

Output evaluates all expressions in turn and pass them to the output stream
Print evaluates all expressions in turn and pass them to the print stream
InternalForm gives the internal representation of an expression without operator signs

Patternsoverview

Placeholders

Any? matches to any object
AnySequence?? matches to a sequence of any objects
AnyNullSequence??? matches to a sequence of any or no objects

Assignments

Pattern assigns a matching object to a symbol
Options matches a sequence of rules for symbols

Supplements

Alternatives| matches to all specified patterns
Condition/? only matches if the condition mets
Optional: is a pattern object and represents an optional argument

Queriesoverview

Contain query for containing elements

Numerical Queries

IsNumeric query for numeric quantity
IsPrime query for a prime number
IsEven query for an even number
IsOdd query for an odd number

Special Functionsoverview

Factorial! gives the factorial of a number
Binomial gives the binomial coefficient of two numbers
Bernoulli gives a Bernoulli number
Zeta
Fibonacci gives a Fibonacci number
Prime
Random gives a pseudo-random number, string or element from a list

Expand expands out products and positive integer powers

Stringsoverview

Construction

String"…",'…' sequence of unicode characters or binary bytes
Join~ gives a joined expression or string

Properties

Length gives the length of an expression or a string
Count count for matching elements or strings

Extraction and Exchange

Part[…] gives a part of an expression or a string
Replace/: applies replacement rules to an expression or a string
Split splits an expression or a string

Symbol Propertiesoverview

Symbols gives a list of all defined symbols
Definitions prints all assignments defined to a symbol
Attributes gives or sets attributes for a symbol
SetAttributes adds attributes for a symbol
ClearAttributes removes attributes for a symbol

Assignment attributes

Protected indicate that a symbol is protected against changes by assignments or clearing
Locked indicate that a symbol is locked against changes in its attributes

Evaluation attributes

Flat indicate that arguments can be flatted or sub expressions can be created during pattern matching
Orderless indicate that arguments can be sorted and rearranged in pattern matching
Listable indicate that a symbol threads into lists occurring in arguments.
HoldAll indicate that all symbol's arguments maintain unevaluated
HoldFirst indicate that the first symbol's argument maintain unevaluated
HoldRest indicate that the all, except the first, symbol's argument maintain unevaluated
SequenceHold indicate that a sequence is not expanded during evaluation of arguments

Syntax

Brackets

Expressions

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

Part

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

Lists

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

Strings

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

Precedence of Operators and Separators

Level 21 (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 20

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

Level 19

f @@ g @@ x Apply(f, Apply(g, x))
f /@ g /@ x Map(f, Map(g, x))

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(…)

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, …)

Trigonometric Functionsoverview

Sin gives the sine of a number
Cos gives the cosine of a number
Tan gives the tangent of a number

ArcSin gives the arcus sine of a number
ArcCos gives the arcus cosine of a number
ArcTan gives the arcus tangent of a number

Lizard – DocumentationKernel Version 0.4.3-0001

Core Language

Object Types Expressionf(…) String"…",'…' Integern
Object Properties Head Depth Length
Object Conversion ToString ToInteger BinaryFormat
Evaluation Constructs 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 »

Assembling Iterate Join~ Union
Extraction and Exchange Part[…] Select Replace/:

Comparison and Logic »

Queries IsNumeric IsPrime
Comparison 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
Binary Functions And&& ShiftLeft
Special Functions Factorial! Fibonacci Random