 tablemerge - Maple Help

tablemerge

merge tables Calling Sequence tablemerge(t1, t2, options) tablemerge(t1, t2, f, b1, ..., bn, options) Parameters

 t1, t2 - tables or list/sets of equations f - optional combiner function b1, ..., bn - (optional) extra arguments options - (optional) optional argument inplace Options

 • inplace = truefalse
 Indicates that t1 should be modified in memory instead of allocating a new table. Summary

 • Returns a table which is the result of merging tables t1 and t2 subject to optional combiner f. Description

 • tablemerge(t1,t2) returns a table t whose keys are all of the keys occurring in either of the tables t1 or t2. The entries in the merged table corresponding to these keys are determined as follows:
 – When a key k appears in exactly one of t1 or t2, the entry is unchanged from its original value in t1 or t2.
 – When a key appears in both t1 and t2 and a combiner f was not provided, the entry from t2 is used.
 – When a key k appears in both t1 and t2 and a combiner f was provided, the entry for k is f(t1[k],t2[k]).
 • Additional arguments b1, ..., bn are passed to f.
 • Each input t1 and t2 may also be a list or set of equations, in which case the merging is performed as though they were tables whose key/value pairs correspond to the equations. The object returned matches that of t1; if t1 is a list, the result is a list.
 • If t1 is a list, its key order is respected in the result. Similarly if both t1 and t2 are lists, any keys appearing in the result which were not present in t1 are ordered in the manner they appear in t2. Details

 • The indexing function for the table returned by tablemerge is identical to the indexing function for t1. Any indexing function used in t2 will be ignored in the merge. Examples

Merge a table with entries for "lunch" and "dessert", overriding the latter.

 > $\mathrm{tablemerge}\left(\mathrm{table}\left(\left["lunch"="sandwich","dessert"="apple"\right]\right),\mathrm{table}\left(\left["dessert"="orange"\right]\right)\right)$
 ${table}{}\left(\left[{"lunch"}{=}{"sandwich"}{,}{"dessert"}{=}{"orange"}\right]\right)$ (1)

Merge using union as the merge operation.

 > $\mathrm{tablemerge}\left(\mathrm{table}\left(\left[1=\left\{2,3,5\right\},2=\left\{6,10,15\right\}\right]\right),\mathrm{table}\left(\left[1=\left\{7,11,13\right\}\right]\right),\mathrm{union}\right)$
 ${table}{}\left(\left[{1}{=}\left\{{2}{,}{3}{,}{5}{,}{7}{,}{11}{,}{13}\right\}{,}{2}{=}\left\{{6}{,}{10}{,}{15}\right\}\right]\right)$ (2)

Merge using concatenation as the merge operation.

 > $\mathrm{tablemerge}\left(\mathrm{table}\left(\left["Message"="Hello"\right]\right),\mathrm{table}\left(\left["Message"="World!"\right]\right),\mathrm{cat}\right)$
 ${table}{}\left(\left[{"Message"}{=}{"Hello World!"}\right]\right)$ (3)

Merge using concatenation, but using a custom delimiter as a 4th argument.

 > cat_delim := proc(x,y,delim) cat(x, delim, y) end proc:
 > $\mathrm{tablemerge}\left(\mathrm{table}\left(\left["pet"="dog","vehicle"="bike"\right]\right),\mathrm{table}\left(\left["pet"="cat","vehicle"="car"\right]\right),\mathrm{cat_delim},","\right)$
 ${table}{}\left(\left[{"vehicle"}{=}{"bike,car"}{,}{"pet"}{=}{"dog,cat"}\right]\right)$ (4)

Merge a table with symmetric indexing with one with ordinary indexing.

 > $A≔\mathrm{table}\left(\mathrm{symmetric},\left[\left(1,2\right)="A"\right]\right)$
 ${A}{≔}{table}{}\left({\mathrm{symmetric}}{,}\left[\left({1}{,}{2}\right){=}{"A"}\right]\right)$ (5)
 > $B≔\mathrm{table}\left(\left[\left(1,2,3\right)="B"\right]\right)$
 ${B}{≔}{table}{}\left(\left[\left({1}{,}{2}{,}{3}\right){=}{"B"}\right]\right)$ (6)
 > $C≔\mathrm{tablemerge}\left(A,B\right)$
 ${C}{≔}{table}{}\left({\mathrm{symmetric}}{,}\left[\left({1}{,}{2}\right){=}{"A"}{,}\left({1}{,}{2}{,}{3}\right){=}{"B"}\right]\right)$ (7)
 > ${C}_{3,1,2}$
 ${"B"}$ (8)

Merge a list of equations with another list of equations.

 > $\mathrm{L1}≔\left[A=1,B=3,C=5,E=9\right]$
 ${\mathrm{L1}}{≔}\left[{A}{=}{1}{,}{B}{=}{3}{,}{C}{=}{5}{,}{E}{=}{9}\right]$ (9)
 > $\mathrm{L2}≔\left[B=8,\mathrm{D}=7,Z=52\right]$
 ${\mathrm{L2}}{≔}\left[{B}{=}{8}{,}{\mathrm{D}}{=}{7}{,}{Z}{=}{52}\right]$ (10)
 > $\mathrm{tablemerge}\left(\mathrm{L1},\mathrm{L2}\right)$
 $\left[{A}{=}{1}{,}{B}{=}{8}{,}{C}{=}{5}{,}{E}{=}{9}{,}{\mathrm{D}}{=}{7}{,}{Z}{=}{52}\right]$ (11) Compatibility

 • The tablemerge command was introduced in Maple 2015.