This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Introduction  /

Discrete Mathematics Packages



Discrete mathematics is concerned with enumerable mathematical structures, such as are studied in combinatorics, graph theory, and computational geometry. The DiscreteMath packages include Combinatorica, which provides over 200 functions for the study of combinatorics and graph theory, and ComputationalGeometry, which provides several important geometric functions useful in nonparametric data analysis. Functions defined on the integers also fall under the heading of discrete mathematics, and there are packages for solving recurrence equations, finding

transforms, and defining the discrete step and Kronecker delta functions.

  • This causes each DiscreteMath package to load as needed.
  • In[1]:= <<DiscreteMath`

  • First load a function for visualizing discrete functions.
  • In[2]:= <<Graphics`MultipleListPlot`

    Star::shdw: Symbol Star appears in multiple contexts {Graphics`MultipleListPlot`, DiscreteMath`Combinatorica`}; definitions in context Graphics`MultipleListPlot` may shadow or be shadowed by other definitions.











  • Discrete piecewise functions can be defined using DiscreteStep. Here is a piecewise function that grows like for , grows like for , and has a delta at

    .
  • In[3]:= (piecewise[n_] := n (DiscreteStep[n-1] - DiscreteStep[n-5]) +
    n^2 DiscreteStep[n-5] + 10 KroneckerDelta[n-2];
    lineshape = {Line[{{First[#], 0},#}], Point[#]}&;
    MultipleListPlot[Table[piecewise[n], {n, 10}],
    SymbolShape -> lineshape])


    Out[3]=

  • You can sum functions involving DiscreteStep or KroneckerDelta.
  • In[4]:= (sum = Sum[piecewise[m], {m, 0, n}];
    MultipleListPlot[Table[sum, {n, 10}],
    SymbolShape -> lineshape])


    Out[4]=

  • You can solve recurrence equations directly using RSolve.
  • In[5]:= (de = r[n + 2] - 2 * r[n + 1] + r[n] == 2;
    Simplify[RSolve[{de, r[0] == 1, r[1] == m}, r[n], n]])

    Out[5]=



  • Or you can solve them using the

    transform.
  • In[6]:= ztrans = (ZTransform[de, n, z] /.
    {r[0] -> 1, r[1] -> m})

    Out[6]=

    In[7]:= (solve = Solve[ztrans, ZTransform[r[n], n, z]];
    Simplify[InverseZTransform[solve, z, n]])

    Out[7]=

  • The Combinatorica package provides definitions of many graph objects. The five-dimensional hypercube has a three-dimensional cube in each corner of the square.
  • In[8]:= ShowGraph[ Hypercube[5] ]




  • This reads a file of piezometric-head data for the Wolfcamp aquifer in the western United States. The triples give an

    location with respect to an arbitrary origin and the water level in feet above sea level.
  • In[9]:= data = ReadList["wolfcamp.aquifer.data",
    Number, RecordLists->True];

  • The Voronoi polygons are useful in spatial statistics because they define a "region of influence" for each data point. The aquifer water level throughout a polygonal region can be approximated by the measurement at the center of the polygon.
  • In[10]:= (data2D = Map[Drop[#, -1]&, data];
    triangulation = DelaunayTriangulation[data2D];
    {polygonVertices, polygonVal} =
    VoronoiDiagram[data2D, triangulation];
    DiagramPlot[data2D, polygonVertices, polygonVal,
    Axes -> True, AxesLabel -> {x, y},
    AxesOrigin -> {-150, -30},
    LabelPoints -> False, TrimPoints -> 6,
    Ticks -> {Automatic, {-50, 0, 50, 100, 150, 200}}])


  • This displays the surface formed by a linear interpolation between the data points in the original three-dimensional set.
  • In[11]:= TriangularSurfacePlot[data, triangulation,
    BoxRatios->{1, 1, .3}, Axes -> True,
    ViewPoint -> {1.3, 2.4, 2.}]