Wolfram: Force Numerical Result

By Xah Lee. Date: . Last updated: .

Symbolic Result vs Numerical Result

All computation are done symbolically by default, returning symbolic (exact) result. For example, 3/2 return just itself (does not become 1.5).

3/2
(* return itself *)

6/4
(* 3/2 *)
(* become simplified *)

1/2 + 1/3
(* 5/6 *)

If parts of expression contains machine number, then the result is approximate.

1/2 + 1/3
(* 5/6 *)

(* If parts of expression contains machine number, then the result is approximate. *)
1/2 + 1/3.
(* 0.8333333333333333 *)

Convert Exact Number to Approximate (Machine Number)

N[expr]

convert numbers in expr to machine precision numbers.

๐Ÿ’ก TIP: in Java and other languages, similar idea is โ€œcastingโ€.

N[3/2]
(* return 1.5 *)

๐Ÿ’ก TIP: A common way to use N is via postfix notation, That is, N[expr] is the same as expr//N

x = ((1/2)^5 + (3/2)^2)^3
(* 389017/32768 *)

x //N
(* 11.871856689453125 *)

Wolfram. Number