Introducing Functions

When you type 2+2, the Wolfram Language understands it as Plus[2,2]. Plus is a function. There are more than 5000 functions built into the Wolfram Language. Arithmetic uses just a very few of these.

Plus[3,4]

Plus[1,2,3]

Times[2,3]

Times[2,Plus[2,3]]

All functions in the Wolfram Language use square brackets, and have names that start with capital letters.

The function Max finds the maximum, or largest, of a collection of numbers.

Max[2,7,3]

The function RandomInteger picks a random integer (whole number) between 0 and whatever size you say.

RandomInteger[100]

RandomInteger[100]

Compute 7+6+5 using the function Plus. »

Compute 2×(3+4) using Times and Plus. »

Use Max to find the larger of 6×8 and 5×9. »

Use RandomInteger to generate a random number between 0 and 1000. »

Use Plus and RandomInteger to generate a number between 10 and 20. »

Compute 5×4×3×2 using Times. »

Compute 2−3 using Subtract. »

Compute (8+7)*(9+2) using Times and Plus. »

Compute (26−89)/9 using Subtract and Divide. »

Compute 100−5^2 using Subtract and Power. »

Find the larger of 3^5 and 5^3. »

Multiply 3 and the larger of 4^3 and 3^4. »

Add two random numbers each between 0 and 1000. »

Do I have to type the capital letters in Plus, RandomInteger, etc.?

Yes. In the Wolfram Language, plus is not the same as Plus. The capital letter in Plus signifies that you’re talking about the built-in (“official”) plus function.

Do I have to type square brackets [...] when I use functions?

Yes. Square brackets [...] are for functions; parentheses (...) are for grouping, as in 2*(3+4), not for functions.

How does one read Plus[2,3] out loud?

Usually “plus of 2 and 3”; sometimes “plus of 2 comma 3”. “[” can be read as “open bracket”; “]” as “close bracket”.

Why use Plus[2,3] instead of 2+3?

For Plus, it’s not necessary. But for the vast majority of functions—like Max or RandomInteger—there’s no special form like +, so you have to give their names.

Can I mix Plus[...] and +?

Yes. Things like Plus[4+5,2+3] or, for that matter, Plus[4,5]*5 are just fine.

What does it mean if the Wolfram Language colors some of my input red?

It means you’ve typed something that the Wolfram Language can’t understand. See Section 47 for more information. Start by checking that your open and close brackets are matched.

Tech Notes