Wolfram: Arithmetic Basics

By Xah Lee. Date: . Last updated: .

Addition

(* short syntax *)
3+2

(* FullForm syntax *)
Plus[3, 2]

Substraction

3-2

(* FullForm syntax *)
Plus[3,-2]

Multiplication

3 * 2

(* FullForm syntax *)
Times[3, 2]

Multiplication can also be done with a space between numbers.

3 2
(* 6 *)

Division

3/2.
(* 1.5 *)

(* FullForm syntax *)
Times[3, Power[2., -1]]
(* 1.5 *)

(* 3/2 return as is. when integer is divided by another integer, result is an exact fraction. *)
3/2
(* 3/2 *)

(* to get approximate number, wrap it with N[] *)
N[3/2]
(* 1.5 *)

Power

3^2
(* 9 *)

(* FullForm syntax *)
Power[3, 2]

Remainder, modular arithmetic

(* remainder, or modular arithmetic *)
Mod[11, 3]
(* 2 *)

Celing, Floor, to Integer

Ceiling[4.2]
(* 5 *)

Floor[4.2]
(* 4 *)

(* HHHH------------------------------ *)

Round[4.5]
(* 4 *)

IntegerPart[4.2]
(* 4 *)

Replace by Zero

Chop[0.0000000000001]
(* 0 *)

Chop[0.00002]
0.00002

(* replace by 0 if smaller than 0.01 *)
Chop[0.00002, 0.01]
(* 0 *)

Testing even/odd

EvenQ[4]
(* True *)

OddQ[3]
(* True *)

Wolfram. Number