Index

AAbsAllAlternativesAndAnyAnyNullSequenceAnySequenceApplyArcTanArgAttributes

BBinaryFormat

CCalculateCeilComplexComplexInfinityComplexOverflowComplexUnderflowCompoundConditionCosCosh

DDefinitionsDepthDigitBaseDirectedInfinityDivide

EEEndiannessEqualExpression

FFactorialFalseFlatFloorFunction

GGreaterGreaterEqual

HHead

IIIfIndeterminateInfinityInteger

JJoin

LLengthLessLessEqualListListableLockedLog

MMachinePrecisionMapMatchingMinusMod

NNotNull

OOptionalOptionsOrOrderOrderlessOutputOverflow

PPartPartitionPatternPiPlusPowerPrecisionPrintProtected

RRandomRationalRealReplaceRuleRuleDelayed

SSameScopeSelectSequenceSetSetDelayedSinSinhSlotSortSpanStringSubtractSymbol

TTableTimesToIntegerToRealToStringToSymbolTrueTrunc

UUnderflowUnequalUnset

XXor

Absfunction

Syntax

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

Details

Examples

Abs(-123) 123

Abs(1.2 + 3.4*I) 3.60555

Abs(3+4*I) 5

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

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

-Sin(4) // Calculate 0.756802

Simplifications are performed if possible.

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

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

See also

Arg

Allconstant

Syntax

All
specifies all elements of an expression at a particular level.

Details

Examples

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

See also

Part[…]

Alternatives|function

Syntax

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

Details

Examples

Matching( a, a|b ) True

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

f(?Rational|?Integer) = "exact"; { f(1), f(1.0), f(1/2) } {"exact", f(1.0), "exact"}

See also

Condition/?

And&&function

Syntax

And(bool1, bool2, … ) bool1 && bool2 &&
gives the logical AND of the expressions 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 && False False

12 && 7 4

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

And stops to evaluate its arguments if False occurs.

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

Expressions which are evaluated into True will be erased.

2==2 && a==5 && b==10 && True a == 5 && b == 10

See also

False  —  True  —  Or||  —  Xor!!  —  Not!

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*, multiple any will collapsed.

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

See also

AnySequence??

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(AnySequence(Symbol)) ) True

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

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

See also

Any?  —  AnySequence??

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) = "real"; { f(1), f(1.0), f(1.0, 2.0), f(1, 0.5) } {f(1), "real", "real", f(1, 0.5)}

See also

Any?

Applyfunction

Syntax

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

Details

Examples

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

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

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

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

Apply will process anonymous function as well:

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

See also

Map/@  —  Head

ArcTanfunction

Syntax

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

Details

Examples

ArcTan(2.0) 1.10715

Calculate(ArcTan(2), 70) 1.107148717794090503017065460178537040070047645401432646676539207433710

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

ArcTan(0) 0

ArcTan(1) 1/4*Pi

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

ArcTan(Infinity) 1/2*Pi

ArcTan with two arguments:

ArcTan(1, 1) 1/4*Pi

ArcTan(-1, 0) Pi

ArcTan(-1.0, -3.0) -1.89255

See also

Tan

Argfunction

Syntax

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

Details

Examples

Arg(1.2 + 3.4*I) 1.2315

Arg(-123) Pi

Arg(1+I) 1/4*Pi

Arg(2.5) 0

Simplifications are performed if possible.

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

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

Arg(Abs(z)) 0

See also

Abs

Attributesfunction

Syntax

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

Details

Examples

Attributes(Plus) {Flat, Listable, 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) ~ ">" Listable

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

See also

Flat  —  Orderless  —  Protected  —  Locked  —  Listable

BinaryFormatoption

Syntax

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

Details

Examples

Handling different number formats:

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

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

Handling different string formats:

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

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

Possible Issues

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

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

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

See also

ToString  —  ToInteger  —  ToReal  —  Endianness

Calculatefunction

Syntax

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

Details

Examples

Log(-5) Log(-5)

Log(-5) // Calculate 1.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 // Precision 21.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

Realx  —  Complexx+y*I

Ceilfunction

Syntax

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

Details

Examples

Ceil(2.1) 3

Ceil(-2.9) -2

Ceil(3/8) 1

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

Ceil(Log(10)) 3

Processing of Overflow and Underflow:

Ceil(Overflow) Overflow

Ceil(Underflow) 1

Ceil(-Underflow) 0

See also

Floor  —  Trunc

Complexx+y*Iobject

Syntax

x + y*I
is a complex number with a real part x and imaginary part y. Both parts can be integer, rational or real numbers.
Complex
is the head of a complex number.

Details

Examples

Head(1+2*I) Complex

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

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

See also

Integern  —  Rationala/b  —  Realx

ComplexInfinityconstant

Syntax

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

Details

Examples

Arithmetical and mathematical functions are able to process ComplexInfinity:

1 / ComplexInfinity 0

1 / 0 ComplexInfinity

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 + ComplexOverflow ComplexOverflow

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 + ComplexUnderflow 3.14+0.0*I

ComplexUnderflow * (-2) ComplexUnderflow

1 / ComplexUnderflow Indeterminate

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 + y 3

z = 10^10000;

Log(10, z) 10000

See also

Null  —  Print

Condition/?function

Syntax

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

Details

Examples

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

Using Condition in a single argument:

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

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

Using Condition for the whole definition:

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

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

Using Condition for a replacement rule:

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

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

See also

Pattern

Cosfunction

Syntax

Cos(z)
gives the cosine of z.

Details

Examples

Cos(2.0) -0.416147

Calculate(Cos(2), 70) -0.4161468365471423869975682295007621897660007710755448907551499737819649

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

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)

See also

Sin  —  Cosh

Coshfunction

Syntax

Cosh(z)
gives the hyperbolic cosine of z.

Details

Examples

Cosh(2.0) 3.7622

Calculate(Cosh(2), 70) 3.762195691083631459562213477773746108293973558230711602777643347588324

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

Cosh(0) 1

Pure imaginary arguments are converted into Cos:

Cosh(2*I) Cos(2)

See also

Sinh  —  Cos

Definitionsfunction

Syntax

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

Details

Examples

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

Define some assignments to f and print all definitions:

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

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

See also

Attributes  —  Set=  —  SetDelayed:=

Depthfunction

Syntax

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

Details

Examples

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

Depth( 123 ) 0

Depth works with any expressions, not only lists.

Depth( f(x^2) ) 2

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

Rational and complex numbers have a depth of 0.

Depth( 1/3 ) 0

Depth( 1+2*I ) 0

Possible Issues

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

a/b a/b

Depth( a/b ) 2

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

See also

Length  —  Part[…]

DigitBaseoption

Syntax

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

Details

Examples

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

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

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

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

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

See also

ToString  —  ToInteger  —  ToReal  —  BinaryFormat

DirectedInfinityfunction

Syntax

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

Details

Examples

Arithmetical and mathematical functions are able to process DirectedInfinity:

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

See also

Infinity  —  ComplexInfinity

Divide/function

Syntax

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

Details

Examples

4 / 2 2

x^5 / x^2 x^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 / 6 2/3 0.666667

See also

Times*  —  Power^

Econstant

Syntax

E
represents Euler's number e ≅ 2.71828.

Details

Examples

Calculate E:

Calculate(E) 2.71828

Calculate(E, 70) 2.718281828459045235360287471352662497757247093699959574966967627724077

Arithmetic with E:

2*E 2*E

2.0*E 5.43656

Some functions give exact results for terms with E.

Log(E) 1

See also

I  —  Pi  —  Calculate  —  Log

Endiannessoption

Syntax

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

Details

Examples

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

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

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

See also

ToString  —  ToInteger  —  BinaryFormat

Equal==function

Syntax

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

Details

Examples

1 == 1 True

3.0 == 3 == 9/3 True

1.0000000000000000002 == 1.0000000000000000001 True

1.000000000000000000200 == 1.000000000000000000100 False

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

1 == 1.0 1 === 1.0 True 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 == b a == b

See also

Same===  —  Unequal!=

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 with head head and an argument arg.
arg // head
is the postfix notation of an expression with head head and an argument arg.

Details

Examples

Head( func(a, b) ) func

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

func @ 123 func(123)

123 // func func(123)

Define assignments for specific arguments:

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

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

Define a function:

g(x?) := x^2

{ g(7) , g(a) , g(I) } {49, a^2, -1}

See also

Symbols  —  Head  —  Set=  —  SetDelayed:=  —  Length  —  Part[…]

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 == 2 False

Not(False) True

See also

True  —  Not!  —  Equal==

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

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) = Flat Flat

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

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

See also

Attributes  —  Orderless

Floorfunction

Syntax

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

Details

Examples

Floor(-2.1) -3

Floor(2.9) 2

Floor(7/8) 0

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

Floor(Log(10)) 2

Processing of Overflow and Underflow:

Floor(Overflow) Overflow

Floor(Underflow) 0

Floor(-Underflow) -1

See also

Ceil  —  Trunc

Function&function

Syntax

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

Details

Examples

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

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

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

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

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

Possible Issues

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

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

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

f(a,b) {a, b}

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

See also

Slot#

Greater>function

Syntax

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

Details

Examples

2 > 1 True

1/3 > 0 > -0.5 True

x > 2 > 2 False

The comparison will be simplified if possible.

2 > 1 > x 1 > x

The value of an exact expression is approximated for comparison.

Sin(2) > 0 True

See also

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

GreaterEqual>=function

Syntax

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

Details

Examples

2 >= 1 True

3/2 >= 1.5 >= -0.5 True

x >= 1 >= 2 False

The comparison will be simplified if possible.

2 >= 1 >= x 1 >= x

The value of an exact expression is approximated for comparison.

Sin(2) >= 0 True

See also

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

Iconstant

Syntax

I
represents the imaginary unit i−1.

Details

Examples

I // Head Complex

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

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

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

If keeps 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

Indeterminateconstant

Syntax

Indeterminate
represents a mathematical quantity whose magnitude is undetermined.

Details

Examples

0 / 0 Indeterminate

0 ^ 0 Indeterminate

Infinity - Infinity Indeterminate

See also

Infinity  —  ComplexInfinity

Infinityconstant

Syntax

Infinity
represents the mathematical positive infinite quantity.

Details

Examples

Arithmetical and mathematical functions are able to process Infinity:

1 / Infinity 0

Log(0) -Infinity

E^(-Infinity) 0

See also

DirectedInfinity  —  ComplexInfinity  —  Overflow

Integernobject

Syntax

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

Details

Examples

Head(123) Integer

32845723658234756 * 346594876456456546 11384159533448787206618577180912776

11384159533448787206618577180912776 / 346594876456456546 32845723658234756

3^200 265613988875874769338781322035779626829233452653394495974574961739092490901302182994384699044001

See also

Rationala/b  —  Realx  —  Complexx+y*I  —  ToInteger

Join~function

Syntax

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

Examples

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

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

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

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

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

See also

Depth  —  Length  —  Part[…]

Lengthfunction

Syntax

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

Details

Examples

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

Length( "Hello World!" ) 12

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

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

Length( a + 2*b + c ) 3

Length( f(a, b) ) 2

Rational and complex numbers have a length of 0.

Length( 1/3 ) 0

Length( 1+2*I ) 0

Possible Issues

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

Minus(x) -x

Length( -x ) 2

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

See also

Depth  —  Part[…]

Less<function

Syntax

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

Details

Examples

1 < 2 True

-0.5 < 0 < 1/3 True

x < 2 < 2 False

The comparison will be simplified if possible.

1 < 2 < x 2 < x

The value of an exact expression is approximated for comparison.

Sin(4) < 0 True

See also

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

LessEqual<=function

Syntax

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

Details

Examples

1 <= 2 True

-0.5 <= 1.5 <= 3/2 True

x <= 2 <= 1 False

The comparison will be simplified if possible.

1 <= 2 <= x 2 <= x

The value of an exact expression is approximated for comparison.

Sin(4) <= 0 True

See also

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

List{…}function

Syntax

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

Examples

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

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

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}

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) = Listable Listable

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

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

See also

Attributes  —  Flat  —  Orderless

Lockedattribute

Syntax

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

Details

Examples

Attributes(Plus) = Flat 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

Log(E) 1

Log(0) -Infinity

Log(10, 1000) 3

Log(4.5, 4.5^100000) 1.0e5

Log(2/3, 16/81) 4

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

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

See also

Power^

MachinePrecisionconstant

Syntax

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

Details

Examples

Calculate MachinePrecision on current system:

Calculate(MachinePrecision) 15.9546

Small real numbers with low precision stored with machine precision:

Precision(3.1415) MachinePrecision

Precision(789.456e123) MachinePrecision

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

Precision(123.4e5678) 15.9546

See also

Realx  —  Precision

Map/@function

Syntax

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

Details

Examples

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

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

Map will process anonymous function as well:

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

See also

Apply  —  Function&  —  Head

Matchingfunction

Syntax

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

Details

Examples

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

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

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

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

See also

Same===  —  Any?  —  AnySequence??  —  Condition/?

Minus-function

Syntax

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

Details

Examples

Minus(123) -123

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

See also

Subtract-  —  Not!

Modfunction

Syntax

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

Details

Examples

Mod(7, 3) 1

Mod(-7, 3) 2

Mod(4.0, -1.2) -0.8

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

Mod also performs on expressions.

Mod(Pi, 2) -2 + Pi

Mod(7*Pi, 2*Pi) Pi

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

See also

Divide/

Not!function

Syntax

Not(bool) !bool
gives the logical NOT of the expression 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

! False True

! 15 -16

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

Negation of comparisons are simplified if possible.

Not( x < 3 ) x >= 3

Double negation of an expression is the expression itself.

Not( Not( exp ) ) exp

See also

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

Nullconstant

Syntax

Null
represents the absence of any kind of object.

Details

Examples

Null

x := 1

z = 3;

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

See also

Compound;  —  Print

Optional:function

Syntax

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

Details

Examples

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

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

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

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

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

See also

Condition/?

Optionsfunction

Syntax

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

Details

Examples

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

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

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

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

f() f(x->Random(10)) f(x:>Random(10)) {0, 0, 0, 0, 0} {3, 3, 3, 3, 3} {7, 10, 1, 10, 0}

See also

Condition/?

Or||function

Syntax

Or(bool1, bool2, … ) bool1 || bool2 ||
gives the logical OR of the expressions 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 || False True

12 || 7 15

'BINARY' || 'abc' 'ckoARY'

Or stops to evaluate its arguments if True occurs.

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

Expressions which are evaluated into False will be erased.

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

See also

False  —  True  —  And&&  —  Xor!!  —  Not!

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("b", "a") -1

Order(x^2, x^2) 0

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

a + c + b a + 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) = Orderless Orderless

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.

Examples

1+2 3*4 5^6 3 12 15625

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

See also

Compound;

Overflowconstant

Syntax

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

Details

Examples

Exp(10.0^20.0) Overflow

Arithmetical and mathematical functions are able to process Overflow:

3.14 + Overflow Overflow

Overflow * (-2) -Overflow

3.14 / Overflow Underflow

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

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

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

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

See also

Depth  —  Length  —  Span..

Partitionfunction

Syntax

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

Details

Examples

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

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

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

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

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

See also

Part[…]  —  Join~

Patternfunction

Syntax

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

Details

Examples

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

f(a, b) a^b

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

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

See also

Any?  —  AnySequence??

Piconstant

Syntax

Pi
represents the constant π ≅ 3.14159.

Details

Examples

Calculate Pi:

Calculate(Pi) 3.14159

Calculate(Pi, 70) 3.141592653589793238462643383279502884197169399375105820974944592307816

Arithmetic with Pi:

2*Pi 2*Pi

2.0*Pi 6.28319

Some functions give exact results for terms with Pi.

Cos(Pi) -1

Expressions with Pi are returned from some functions.

Log(-1) I*Pi

ArcTan(Infinity) 1/2*Pi

See also

E  —  I  —  Calculate  —  Cos

Plus+function

Syntax

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

Details

Examples

1 + 2 + 3 6

2*x + 3*x 5*x

2 + 1/4 2 + 0.25 9/4 2.25

Plus will flattened and the arguments sorted.

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

Plus threads over List{…}:

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

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

See also

Subtract-  —  Times*

Power^function

Syntax

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

Details

Examples

2 ^ 100 1267650600228229401496703205376

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 ^ 1000 8.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^0 Indeterminate

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+

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(123456.78901234567890) 20.0915

Precision(4.0 + 3*I) MachinePrecision

See also

Realx  —  MachinePrecision

Printfunction

Syntax

Print(exp1, exp2, … )
evaluates and prints all expressions expi in turn, and gives Null as result.

Details

Examples

Print(1, 2, 3) 1 2 3

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

See also

Compound;  —  String"…",'…'  —  Null

Protectedattribute

Syntax

Protected
is an attribute for symbols to indicate that they are protected against changes by Set= or SetDelayed:=.

Details

Examples

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

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

x = 123 123

Attributes(x) = Protected Protected

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

x 123

See also

Attributes  —  Locked

Randomfunction

Syntax

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

Details and Options

Examples

Random(7) 3

Random(2/3) 2/3

Random(2.0) 1.84223

Random(1.0+2.0*I) 0.447681+1.13909*I

Random( {a, b, c} ) a

Generate a list of random numbers:

Table( Random(9), 10 ) {2, 3, 8, 7, 3, 1, 8, 1, 3, 6}

See also

Integern  —  Realx  —  Complexx+y*I  —  List{…}

Rationala/bobject

Syntax

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

Details

Examples

Head(1/2) Rational

4/12 1/3

1/123456 + 1/678901 802357/83814401856

See also

Integern  —  Realx  —  Complexx+y*I

Realxobject

Syntax

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

Details

Examples

Head(1.0) Real

4.0 * 0.7 2.8

1 + 2.0 3.0

1/3 + 1.0 1.33333

1.0000000000000000000000000000000000000000123 + 10 11.0000000000000000000000000000000000000000123

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

123.456 ^ 1000.0 3.25238259113e2091

0.012 ^ 1000.0 1.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.00000000000000000000456789 3.25238259113e2091 123.00000000000000000000456789

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

x ^ y 1.0018442638e257256

Precision(x^y) 10.3862

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 * Underflow Indeterminate

Underflow - Underflow ComplexUnderflow

See also

Integern  —  Rationala/b  —  Complexx+y*I

Replace/:function

Syntax

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

Details

Examples

Replace a symbol with a value:

x^2 + x /: x->4 20

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

Swapping elements:

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

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

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

Replace a special type of elements:

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

Replace a sub-string:

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

Possible Issues

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

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

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

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

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

Patterns that are too general replace the entire expression

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

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

See also

Rule->  —  Pattern  —  Expressionf(…)  —  Symbols

Rule->function

Syntax

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

Details

Examples

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

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

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

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

Possible Issues

x = 4 4

Rule is evaluated immediately:

x?Integer -> x^2 Pattern(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^2 Pattern(x, ?Integer) :> x^2

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

See also

RuleDelayed:>  —  Pattern  —  Expressionf(…)  —  Symbols

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, 611, 2, 738, 3, 178}

RuleDelayed is typically used in combination with patterns:

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

See also

Rule->  —  Pattern  —  Expressionf(…)  —  Symbols

Same===function

Syntax

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

Details

Examples

x === y False

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

1 === 1.0 1 == 1.0 False True

Overflows are identical, but the equality is unknown.

Overflow === Overflow Overflow == Overflow True Overflow == Overflow

See also

Equal==  —  Unequal!=

Scopefunction

Syntax

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

Details

Examples

Scope keeps x and y unchanges in the outer scope.

x = 123; a=3; b=4 4

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

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

Defines temporary symbols:

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

{z, w} {z, w}

Possible Issues

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

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

See also

Function&  —  Set=

Selectfunction

Syntax

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

Details

Examples

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

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

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

Select works with any kind of expression.

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

See also

Function&  —  Head

Sequencefunction

Syntax

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

Details

Examples

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

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

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

See also

AnySequence??  —  AnyNullSequence???

Set=function

Syntax

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

Details

Examples

Assign expressions to single symbols:

x = 123 123

x*2 246

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

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

Multiple assignments via list:

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

a b c 123 3.14 "Test"

Assign expressions to an expression with a pattern:

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

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

Polytypism allows multiple definitions to the same expression head:

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

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

Possible Issues

Set evaluates the expression rhs on the right hand side before assignment, SetDelayed:= not.

x = 3.14 3.14

h(x?) = 2*x 6.28

k(x?) := 2*x

x is already known and will be replaced in Set= but not in SetDelayed:=.

h(a) k(a) 6.28 246

See also

SetDelayed:=  —  Unset  —  Pattern  —  Expressionf(…)  —  Symbols

SetDelayed:=function

Syntax

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

Details

Examples

Assign expressions to single symbols:

x := 123

x*2 246

y := a^2 + b^2

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

Multiple assignments via list:

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

a b c 123 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

SetDelayed does not evaluates the expression rhs on the right hand side before assignment, Set= does.

m = 2 2

k(q?) := m*q

h(q?) = m*q 2*q

m is already known and will be replaced within Set= during the assignment but for SetDelayed:= 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 = 5 5

h(a) k(a) 246 615

See also

Set=  —  Unset  —  Pattern  —  Expressionf(…)  —  Symbols

Sinfunction

Syntax

Sin(z)
gives the sine of z.

Details

Examples

Sin(2.0) 0.909297

Calculate(Sin(2), 70) 0.9092974268256816953960198659117448427022549714478902683789730115309673

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

Sin(0) 0

Sin(Pi/2) 1

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

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

See also

Cos  —  Sinh

Sinhfunction

Syntax

Sinh(z)
gives the hyperbolic sine of z.

Details

Examples

Sinh(2.0) 3.62686

Calculate(Sinh(2), 70) 3.626860407847018767668213982801261704886342012321135721309484474934250

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

Sinh(0) 0

See also

Cosh  —  Sin

Slot#function

Syntax

Slot(n) #n
represents nth argument of an anonymous 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(exp)
sorts the arguments of expression exp into canonical order.
Sort(exp, cmp)
uses the comparison function cmp for ordering.

Details

Examples

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

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

Use a comparison function for custom sorting.

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

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

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

During the sort of string 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  —  LessEqual<=

Span..function

Syntax

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

Details

Examples

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

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

See also

Part[…]

String"…",'…'object

Syntax

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

Details and Options

Examples

Text strings with unicode characters:

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

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

Binary strings with bytes show 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

Length  —  Part[…]  —  ToString

Subtract-function

Syntax

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

Details

Examples

3 - 2 1

2*x - 3*x -x

2 - 1/4 2 - 0.25 7/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

Assign numbers to a symbol:

x = 123 y = 4 123 4

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

Assign expressions to a greek symbol:

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

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

Possible Issues

Symbol names are case sensitive!

Var = 123 123

{Var, var} {123, var}

See also

String"…",'…'  —  Expressionf(…)  —  Set=  —  SetDelayed:=

Tablefunction

Syntax

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

Details and Options

Examples

Tables without iterator:

Table(1, 5) {1, 1, 1, 1, 1}

Table(Random(9), 10) {2, 3, 9, 2, 7, 3, 8, 4, 3, 7}

Tables with iterator:

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

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

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

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

Nested tables:

Table(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}}

See also

Random  —  List{…}

Times*function

Syntax

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

Details

Examples

2 * 3 * 4 24

x^2 * x^3 x^5

2 * 1/4 2 * 0.25 1/2 0.5

Times will flattened and the arguments 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 into an integer number, if possible.

Details and Options

Examples

Convert any object or expressions to an integer:

ToInteger(3/2) 1

ToInteger(-3.1415) -3

ToInteger(5+2*I) 5

ToInteger(E) 2

ToInteger(Pi^2) 9

Convert strings to an integer:

ToInteger("12345") 12345

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

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

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

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

Possible Issues

Some expressions or numbers cannot be converted in an integer:

ToInteger(Overflow) ToInteger(Overflow)

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

See also

Integern  —  ToReal

ToRealfunction

Syntax

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

Details and Options

Examples

Convert any object or expressions to a real number:

ToReal(123) 123.0

ToReal(3/5) 0.6

ToReal(5+2*I) 5.0

ToReal(E) 2.71828

ToReal(Pi^2) 9.8696

Convert strings to a real number:

ToReal("123.45") 123.45

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

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

Possible Issues

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

ToReal(ComplexOverflow) Indeterminate

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

See also

Realx  —  Calculate  —  ToInteger

ToStringfunction

Syntax

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

Details and Options

Examples

Convert any object or expressions to a string:

ToString(123) "123"

ToString(3/2) "3/2"

ToString(-3.1415) "-3.141500000000000"

ToString(123.45678901234567890123456789e12345) "1.2345678901234567890123456789e12347"

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

ToString(E) "E"

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

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

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

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

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

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

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

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

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

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

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

See also

String"…",'…'  —  ToInteger  —  ToReal  —  ToSymbol

ToSymbolfunction

Syntax

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

Details and Options

Examples

ToSymbol("var") var

a = 123;

ToSymbol("a") 123

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

b~c "alpha"

ToSymbol(b~c) 456

Possible Issues

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

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

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

See also

Symbols

Trueconstant

Syntax

True
represents the boolean value true.

Details

Examples

1 == 1 True

Not(True) False

See also

False  —  Not!  —  Equal==

Truncfunction

Syntax

Trunc(x)
gives the integer part of x.

Details

Examples

Trunc(-2.1) -2

Trunc(2.9) 2

Trunc(-13/8) -1

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

Trunc(Log(10)) 2

See also

Ceil  —  Floor

Underflowconstant

Syntax

Underflow
represents an underflow in float-pointing arithmetic.

Details

Examples

Exp(-10.0^20.0) Underflow

Arithmetical and mathematical functions are able to process Underflow:

3.14 + Underflow 3.14

Underflow * (-2) -Underflow

3.14 / Underflow Overflow

Log(Underflow) -Overflow

See also

Overflow  —  ComplexUnderflow

Unequal!=function

Syntax

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

Details

Examples

1 != 2 True

1 != Pi != 3.0 True

1.0000000000000000002 != 1.0000000000000000001 False

1.000000000000000000200 != 1.000000000000000000100 True

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

1 != 1.0 1 === 1.0 False False

All argument combination pairs must be unequal.

1 != 2 != 1 False

Unequal stays unevaluated if inequality is unknown.

a != b a != b

See also

Same===  —  Equal==

Unsetfunction

Syntax

Unset(pat)
removes an assignment rule defined by the pattern pat.

Details

Examples

Remove an assignment from a single symbols:

x = 123 123

x^2 15129

Unset(x)

x^2 x^2

Remove an assignments from an expression with a pattern:

f(10) = 0 f(z?Integer) = 2*z f(z?) = z^2 0 2*z z^2

Definitions(f) f(10) = 0 f(Pattern(z, ?Integer)) = 2*z f(Pattern(z, ?)) = z^2

Unset(f(z?))

Definitions(f) f(10) = 0 f(Pattern(z, ?Integer)) = 2*z

See also

Set=  —  SetDelayed:=  —  Pattern  —  Expressionf(…)  —  Symbols

Xor!!function

Syntax

Xor(bool1, bool2, … ) bool1 !! bool2 !!
gives the logical XOR (exclusive OR) of the expressions 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 !! 7 11

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

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

True !! exp !exp

True !! exp !! True exp

See also

False  —  True  —  And&&  —  Or||  —  Not!

Introduction

Getting started

Highlighted features

Syntax

Brackets

Expressions

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

Part

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

Lists

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

Strings

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

Operators and Separators

Level 20 (high)

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

Level 19

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

Level 18

x! Factorial(x)

Level 17

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

Level 16

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

Level 15

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

Level 14

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

Level 13

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

Level 12

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

Level 11

!b Not(b)

Level 10

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

Level 9

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

Level 8

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

Level 7

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

Level 6

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

Level 5

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

Level 4

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

Level 3

f & Function(f)

Level 2

x = y = z Set(x, Set(y, z))
x := y := z SetDelayed(x, SetDelayed(y, z))

Level 1

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

Level 0 (low)

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

Lizard – DocumentationKernel Version 0.4.0-0001

Core language

Object types

Expressionf(…)  —  Symbols  —  String"…",'…'
Integern  —  Rationala/b  —  Realx  —  Complexx+y*I

Prominent expressions

Compound;  —  If  —  Scope
Sequence  —  List{…}  —  Function&  —  Slot#

Conversions

ToSymbol  —  ToInteger  —  ToReal  —  ToString

Others

Print

Assignment & Pattern matching

Assignments

Set=  —  SetDelayed:=  —  Rule->  —  RuleDelayed:>  —  Unset
Attributes  —  Definitions

Patterns

Pattern  —  Any?  —  AnySequence??  —  AnyNullSequence???
Alternatives|  —  Condition/?  —  Optional:  —  Options

Lists & Expressions

Properties

Head  —  Depth  —  Length  —  InternalForm

Extraction and modification

Part[…]  —  Span..  —  Join~  —  Partition  —  Select  —  Sort
Table  —  Apply  —  Map/@  —  Replace/:

Arithmetic & Logic

Mathematical functions

Plus+  —  Subtract-  —  Times*  —  Divide/  —  Power^
Abs  —  Arg  —  Ceil  —  Floor  —  Trunc  —  Minus-
Factorial!  —  Mod  —  Log
Cos  —  Sin  —  Cosh  —  Sinh  —  ArcTan
Calculate  —  DirectedInfinity  —  Random

Logical and bit operation

Not!  —  And&&  —  Or||  —  Xor!!

Comparison

Equal==  —  Unequal!=  —  Greater>  —  GreaterEqual>=  —  Less<  —  LessEqual<=
Same===  —  Matching  —  Order

Reserved symbols

Options in functions

DigitBase  —  BinaryFormat  —  Endianness

Attributes for symbols

Protected  —  Locked  —  Hold  —  HoldAll  —  HoldFirst  —  HoldRest  —  SequenceHold
Flat  —  Orderless  —  Listable  —  NumericFunction  —  NumericConstant  —  OneIdentity  —  Temporary

Occupied symbols and constants

True  —  False  —  All  —  Null
E  —  I  —  Pi  —  MachinePrecision
Underflow  —  Overflow  —  ComplexUnderflow  —  ComplexOverflow
Infinity  —  ComplexInfinity  —  Indeterminate