Error, attempting to assign to Pi which is protected. Try declaring local Pi; see ?protect for details. - Maple Help

Home : Support : Online Help : Error, attempting to assign to Pi which is protected. Try declaring local Pi; see ?protect for details.

Error, attempting to assign to ... which is protected.  Try declaring local ...; see ?protect for details.

Description

This error occurs when you assign a value to a protected name. Protection is used to prevent names from being modified by the user.

One way to solve this error is to use a name that is not protected. However, if you prefer to use the protected name, you can do one of the following to avoid this error.

 • use local to declare a local version of the name (see Example 1)
 • use unprotect to remove protection from the protected name (see Example 2)

Note: It is not recommended that you remove protection from Maple protected names. If you must use a Maple protected name, you should declare a local version of the name.

Examples

Example 1: Declaring a protected name as local

An error is generated when you assign a value to a Maple protected name.

 > $\mathrm{start}≔1.3982$
 ${\mathrm{start}}{≔}{1.3982}$ (1)
 > $\mathrm{finish}≔12.2315$
 ${\mathrm{finish}}{≔}{12.2315}$ (2)
 > $\mathrm{diff}≔\mathrm{finish}-\mathrm{start}$

The error is generated because diff is the Maple protected name for the differentiation command. To use a Maple protected name in your worksheet, declare the name using local.

 >
 ${\mathrm{diff}}{≔}{10.8333}$ (3)
 > $\mathrm{diff}$
 ${10.8333}$ (4)

To access the Maple diff command, call :-diff. The following command differentiates ln(x) with respect to x.

 > $:-\mathrm{diff}\left(\mathrm{ln}\left(x\right),x\right)$
 $\frac{{1}}{{x}}$ (5)

You can even declare a local version of a name you already declared. The global (that is, original) name is again accessed by adding :- before the name.

 > $\mathrm{myname}≔"global version of myname"$
 ${\mathrm{myname}}{≔}{"global version of myname"}$ (6)
 >
 ${\mathrm{myname}}{≔}{"local version of myname"}$ (7)
 > $\mathrm{myname}$
 ${"local version of myname"}$ (8)
 > $:-\mathrm{myname}$
 ${"global version of myname"}$ (9)

Example 2:  Using unprotect on a protected name

You can protect a name with the protect command. After protecting a name, an error is generated if you try to change the value stored in the protected name.

 > $\mathrm{myProtectedName}≔19$
 ${\mathrm{myProtectedName}}{≔}{19}$ (10)
 > $\mathrm{protect}\left('\mathrm{myProtectedName}'\right)$
 > $\mathrm{myProtectedName}≔23$

Use the unprotect command to remove protection from your name and change its value.

 > $\mathrm{unprotect}\left('\mathrm{myProtectedName}'\right)$
 > $\mathrm{myProtectedName}≔23$
 ${\mathrm{myProtectedName}}{≔}{23}$ (11)

Although you can use the unprotect command on a Maple protected name, this is not recommended because it alters the value of results. For example, consider the correct value of arctan(1).

 > $\mathrm{eval}\left(\mathrm{arctan}\left(1\right)\right)$
 $\frac{{\mathrm{\pi }}}{{4}}$ (12)

Changing the value of Pi affects this and any other result containing Pi.

 > $\mathrm{unprotect}\left(\mathrm{\pi }\right)$
 > $\mathrm{\pi }≔4$
 ${\mathrm{\pi }}{≔}{4}$ (13)
 > $\mathrm{eval}\left(\mathrm{arctan}\left(1\right)\right)$
 ${1}$ (14)
 >