copy - Maple Programming Help

copy

create a duplicate table, rtable, or module

 Calling Sequence copy( a ); copy( a , deep);

Parameters

 a - any expression

Description

 • The purpose of the copy function is to create a duplicate table, rtable, or record which can be altered without changing the original table, rtable, or record.  If a is not a table, rtable, or record, and a deep copy is not requested, a is returned.
 • This functionality is necessary since the statements s := table(); t := s; leave both names s and t evaluating to the same table structure.  Hence, unlike other Maple data structures, assignments made via one of the names affect the values associated with the other name as well.
 • Note that copy is not recursive.  This means that if a is a table of tables, the table data structure for a is copied but the table structures for the entries of a are not copied. To obtain a full recursive copy where all contents that are also mutable structures are copied, or to obtain a copy of a module, use the deep option.
 • For an rtable, copy preserves rtable options and indexing functions, except for the readonly option which is not set.

Examples

 > ${s}_{1}≔x$
 ${{s}}_{{1}}{≔}{x}$ (1)
 > $t≔s$
 ${t}{≔}{s}$ (2)
 > ${t}_{1}≔y$
 ${{t}}_{{1}}{≔}{y}$ (3)
 > ${s}_{1}$
 ${y}$ (4)
 > $u≔\mathrm{copy}\left(s\right)$
 ${u}{≔}{table}{}\left(\left[{1}{=}{y}\right]\right)$ (5)
 > ${u}_{1}≔z$
 ${{u}}_{{1}}{≔}{z}$ (6)
 > ${s}_{1}$
 ${y}$ (7)
 > $m≔\mathrm{Matrix}\left(1,\mathrm{shape}=\mathrm{symmetric},\left[a\right],\mathrm{readonly}\right)$
 ${m}{≔}\left[\begin{array}{c}{a}\end{array}\right]$ (8)
 > $\mathrm{MatrixOptions}\left(m\right)$
 ${\mathrm{shape}}{=}\left[{\mathrm{symmetric}}\right]{,}{\mathrm{datatype}}{=}{\mathrm{anything}}{,}{\mathrm{storage}}{=}{{\mathrm{triangular}}}_{{\mathrm{upper}}}{,}{\mathrm{order}}{=}{\mathrm{Fortran_order}}{,}{\mathrm{readonly}}$ (9)
 > $n≔\mathrm{copy}\left(m\right)$
 ${n}{≔}\left[\begin{array}{c}{a}\end{array}\right]$ (10)
 > $\mathrm{MatrixOptions}\left(n\right)$
 ${\mathrm{shape}}{=}\left[{\mathrm{symmetric}}\right]{,}{\mathrm{datatype}}{=}{\mathrm{anything}}{,}{\mathrm{storage}}{=}{{\mathrm{triangular}}}_{{\mathrm{upper}}}{,}{\mathrm{order}}{=}{\mathrm{Fortran_order}}$ (11)

For a table 'a' that contains another table 'b'; when copy is done on 'a' an entirely new copy of 'a' is created.  However the objects contained in the table are not duplicated; so both 'a' and the copy of 'a' contain the table 'b'. Thus, if a change is made to the table 'b' in 'a', that change will show up in the copy of 'a' as well, and vice versa.

 > $S≔\mathrm{table}\left(\left[45,\mathrm{table}\left(\mathrm{symmetric},\left[\left(1,2\right)=3\right]\right)\right]\right)$
 ${S}{≔}{table}{}\left(\left[{1}{=}{45}{,}{2}{=}{table}{}\left({\mathrm{symmetric}}{,}\left[\left({1}{,}{2}\right){=}{3}\right]\right)\right]\right)$ (12)
 > ${S}_{1}$
 ${45}$ (13)
 > $T≔\mathrm{copy}\left(S\right)$
 ${T}{≔}{table}{}\left(\left[{1}{=}{45}{,}{2}{=}{table}{}\left({\mathrm{symmetric}}{,}\left[\left({1}{,}{2}\right){=}{3}\right]\right)\right]\right)$ (14)
 > ${T}_{1}$
 ${45}$ (15)
 > ${T}_{1}≔50$
 ${{T}}_{{1}}{≔}{50}$ (16)
 > ${S}_{1}$
 ${45}$ (17)
 > ${{S}_{2}}_{2,1}$
 ${3}$ (18)
 > ${{T}_{2}}_{2,1}≔5$
 ${\left({{T}}_{{2}}\right)}_{{2}{,}{1}}{≔}{5}$ (19)
 > ${{S}_{2}}_{2,1}$
 ${5}$ (20)

For a list of records, deep must be used to obtain unique instances of the records.

 > $\mathrm{rl}≔\left[\mathrm{Record}\left(a=1,b=2\right),\mathrm{Record}\left(a=3,b=4\right)\right]$
 ${\mathrm{rl}}{≔}\left[{\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right){,}{\mathrm{Record}}{}\left({a}{=}{3}{,}{b}{=}{4}\right)\right]$ (21)
 > $\mathrm{rl_copy}≔\mathrm{copy}\left(\mathrm{rl}\right)$
 ${\mathrm{rl_copy}}{≔}\left[{\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right){,}{\mathrm{Record}}{}\left({a}{=}{3}{,}{b}{=}{4}\right)\right]$ (22)
 > $\mathrm{rl_deep}≔\mathrm{copy}\left(\mathrm{rl},'\mathrm{deep}'\right)$
 ${\mathrm{rl_deep}}{≔}\left[{\mathrm{Record}}{}\left({a}{=}{1}{,}{b}{=}{2}\right){,}{\mathrm{Record}}{}\left({a}{=}{3}{,}{b}{=}{4}\right)\right]$ (23)
 > ${{\mathrm{rl}}_{1}}_{a}≔7$
 ${\left({{\mathrm{rl}}}_{{1}}\right)}_{{a}}{≔}{7}$ (24)
 > ${{\mathrm{rl_copy}}_{1}}_{a}$
 ${7}$ (25)
 > ${{\mathrm{rl_deep}}_{1}}_{a}$
 ${1}$ (26)