Function Repository Resource:

RandomCombinator

Source Notebook

Generate a pseudorandom combinator

Contributed by: Robert Nachbar

ResourceFunction["RandomCombinator"][k]

gives a pseudorandom combinator with k symbols.

ResourceFunction["RandomCombinator"][k,syms]

uses symbols from the list syms.

ResourceFunction["RandomCombinator"][k,syms,n]

gives a list of n pseudorandom combinators.

ResourceFunction["RandomCombinator"][k,syms,{n1,n2,}]

gives an n1×n2× array of pseudorandom combinators.

Details and Options

ResourceFunction["RandomCombinator"][k,syms] chooses combinators from the set of all possible combinators with k symbols from the list syms with equal probability.
ResourceFunction["RandomCombinator"] gives a different sequence of pseudorandom combinators whenever you run the Wolfram Language. You can start with a particular seed using SeedRandom.
ResourceFunction["RandomCombinator"][n] is equivalent to ResourceFunction["RandomCombinator"][n,{CombinatorS,CombinatorK}].
ResourceFunction["RandomCombinator"] has the following options:
CombinerFunctionConstructfunction to use for combining symbols

Examples

Basic Examples (3) 

A random combinator with 5 symbols:

In[1]:=
ResourceFunction["RandomCombinator"][5]
Out[1]=

Ten random combinators with 5 symbols:

In[2]:=
ResourceFunction["RandomCombinator"][5, 10]
Out[2]=

A 3×4 array of random combinators with 5 symbols:

In[3]:=
ResourceFunction["RandomCombinator"][5, {3, 4}]
Out[3]=

Scope (2) 

Generate random combinators with any list of symbols:

In[4]:=
ResourceFunction[
 "RandomCombinator"][5, {\[FormalF], \[FormalG], \[FormalH]}]
Out[4]=

Generate random combinators of any size:

In[5]:=
ResourceFunction["RandomCombinator"][50]
Out[5]=

Options (1) 

CombinerFunction (1) 

Use CombinerFunctionApplication to combine the symbols:

In[6]:=
ResourceFunction["RandomCombinator"][15, CombinerFunction -> Application]
Out[6]=

Properties and Relations (2) 

Use SeedRandom to get repeatable random combinators:

In[7]:=
{ResourceFunction["RandomCombinator"][5], ResourceFunction["RandomCombinator"][5]}
Out[7]=
In[8]:=
{SeedRandom[1234]; ResourceFunction["RandomCombinator"][5], SeedRandom[1234]; ResourceFunction["RandomCombinator"][5]}
Out[8]=

RandomCombinator generates a uniform distribution. The set of combinators with n symbols from an alphabet of k symbols has cardinality kn×CatalanNumber[n-1]. First compute the cardinality:

In[9]:=
n = 5;
nc = 2^n CatalanNumber[n - 1]
Out[9]=

Generate 1000 times that number of random combinators and check for a uniform distribution:

In[10]:=
ListPlot[Values[
  Counts[ResourceFunction["RandomCombinator"][n, 1000 nc]]], Sequence[
 Filling -> Axis, Frame -> True, PlotRange -> {All, {0, 1200}}, AspectRatio -> Rational[1, 3], ImageSize -> Large, PlotMarkers -> Automatic]]
Out[10]=

Publisher

Robert Nachbar

Version History

  • 1.0.0 – 15 November 2021

Related Resources

License Information