Wolfram Language Fast Introduction for Math Students
Get Started »

Discrete Mathematics

Perform basic number theory operations such as factoring:

In[1]:=
Click for copyable input
FactorInteger[30]
Out[1]=

Find the GCD (or LCM) of any two integers:

In[2]:=
Click for copyable input
GCD[24, 60]
Out[2]=

Display the 4th prime number:

In[1]:=
Click for copyable input
Prime[4]
Out[1]=

Test the primality of a number:

In[2]:=
Click for copyable input
PrimeQ[%]
Out[2]=

This works with coprime numbers as well:

In[3]:=
Click for copyable input
CoprimeQ[51, 15]
Out[3]=

Use the Mod function for the remainder:

In[1]:=
Click for copyable input
Mod[17, 5]
Out[1]=

Get all possible permutations of a list:

In[1]:=
Click for copyable input
Permutations[{a, b, c}]
Out[1]=

Apply Permute to a list using disjoint Cycles:

(Cycles takes a list of lists as an argument.)
In[2]:=
Click for copyable input
Permute[{a, b, c, d}, Cycles[{{2, 4}, {1, 3}}]]
Out[2]=

Find the permutation order:

In[3]:=
Click for copyable input
PermutationOrder[Cycles[{{2, 4}, {1, 3}}]]
Out[3]=

Generate a Graph from a list of edges:

(Use ESCueESC for an UndirectedEdge or ESCdeESC for a DirectedEdge.)
In[1]:=
Click for copyable input
Graph[{1 <-> 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4, 4 <-> 1, 
  3 \[DirectedEdge] 1, 2 \[DirectedEdge] 2}, VertexLabels -> All]
Out[1]=

Find the shortest path between two vertices:

In[2]:=
Click for copyable input
FindShortestPath[%, 3, 2]
Out[2]=

Explore well-known graphs using natural-language input:

In[3]:=
X
pappus graph image
Out[3]=

The Wolfram Language also includes functions for combinatorics, probability, integer sequences and much more.

QUICK REFERENCE: Number Theoretic Functions »

QUICK REFERENCE: Discrete Mathematics »