Wolfram Computation Meets Knowledge

The Wolfram Language:
Fast Introduction for Programmers

Show additional notes for:
All sections 
Get Started

Numbers

The Wolfram Language by default does exact computation whenever it can:

In[1]:=1
3/7 + 2/11
Out[1]=1

Notes for Java programmers:

Rational numbers are represented symbolically as reduced fractions in the Wolfram Language. Java does not have a built-in rational type, instead always returning numerical approximations by default.

Notes for Python programmers:

Rational numbers are represented symbolically as reduced fractions in the Wolfram Language. Similar functionality in Python requires importing the fractions module.


Use N to get (potentially faster) numerical results:

In[2]:=2
N[3/7+2/11]
Out[2]=2

The Wolfram Language can handle numbers of any precision:

In[1]:=1
N[Pi,50]
Out[1]=1

The language automatically tracks precision of results.


Use ` to explicitly indicate the precision to assume in a number:

In[2]:=2
1.234`50
Out[2]=2

Notes for Java programmers:

Java code must explicitly use the BigInteger and BigDecimal types for arbitrary-precision integers and decimals.

Notes for Python programmers:

Python integers can become arbitrarily large like numbers in the Wolfram Language. Floats in Python require importing a third-party library like mpmath.


I represents for complex numbers:

In[1]:=1
I^2
Out[1]=1

Notes for Java programmers:

Java has no internal representation for the imaginary number i. To compute with complex numbers in Java, you must import or create a package.

Notes for Python programmers:

Python uses the symbol j to represent the imaginary number. The Wolfram Language provides a number of different stylized forms such as I, [ImaginaryJ] and Sqrt[-1] for the imaginary number, and similarly for other constants, to maximize clarity.


Matrices are lists of lists:

In[1]:=1
Inverse[{{6,7},{4,a}}]
Out[1]=1

SparseArray gives sparse arrays.

Notes for Java programmers:

Sparse arrays are not provided by default in Java, typically requiring constructs from third-party libraries.

Notes for Python programmers:

Sparse arrays are not provided by default in Python, typically requiring constructs from third-party libraries and packages such as NumPy.


In the Wolfram Language, what do you get when you enter 14/12?


Using the Wolfram Language, how do you turn 1/2 into .5?


Which of these computes pi to 100 digits of precision?

© 2017 Wolfram. All rights reserved.