Function Repository Resource:

PointsToRules

Source Notebook

Convert a list of points into a list of substitution rules

Contributed by: Dennis M Schneider

ResourceFunction["PointsToRules"][pts,vars]

converts the list of pts into a list of substitution rules in vars.

Examples

Basic Examples (4) 

Convert a list of numbers into a list of substitution rules:

In[1]:=
ResourceFunction["PointsToRules"][{1, 2, 3, 4, 5}, x]
Out[1]=

This is the same as:

In[2]:=
Map[Thread[{x -> #}] &, {1, 2, 3, 4, 5}]
Out[2]=

Convert a list of n-tuples into a list of substitution rules in n variables:

In[3]:=
ResourceFunction["PointsToRules"][{{1, a}, {2, b}, {3, c}}, {x, y}]
Out[3]=

This is the same as:

In[4]:=
Map[Thread[{x, y} -> #] &, {{1, a}, {2, b}, {3, c}}]
Out[4]=

Convert an n-tuples into a list of substitution rules in n variables:

In[5]:=
ResourceFunction["PointsToRules"][{1, 2, 3}, {x, y, z}]
Out[5]=

This is the same as:

In[6]:=
Map[Thread[{x, y, z} -> #] &, {{1, 2, 3}}]
Out[6]=

Convert a list of n-tuples into a list of associations using the resource function ToAssociations:

In[7]:=
ResourceFunction["ToAssociations"][
 ResourceFunction["PointsToRules"][{{1, 2}, {3, 4}, {5, 6}}, {a, b}]]
Out[7]=

Scope (3) 

The number of variables must be compatible with the size of each point:

In[8]:=
ResourceFunction["PointsToRules"][{{1, 2}, {3, a}}, x]
In[9]:=
ResourceFunction["PointsToRules"][{{1, 2, 3}, {3, a, 4}}, {x, y}]

The first argument must be a vector or a matrix:

In[10]:=
ResourceFunction["PointsToRules"][{{1, 2}, {3, a, 4}}, {x, y}]

The second argument must be a symbol or a list of symbols:

In[11]:=
ResourceFunction[
 "PointsToRules"][{{a, u, 1, 1}, {b, v, c, c}}, {{x, y}, {z, w}}]

Publisher

Dennis M Schneider

Version History

  • 3.0.0 – 04 November 2019
  • 2.0.0 – 11 October 2019
  • 1.0.0 – 08 August 2019

Related Resources

License Information