Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tag List Protected error

1,446 views
Skip to first unread message

niobe

unread,
Nov 7, 2010, 5:11:17 AM11/7/10
to
Hi,

I am trying to use ReplacePart in a function definition. The function
works using =, but not :=

newX= ReplacePart[x,{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2,
1]]]] - y[[2, 2]]]

.. works

update[x, y] := ReplacePart[
x,
{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
]
.. SetDelayed::write: Tag List in <snip> is Protected.

x and y are just integer lists. The problem seems to be Mathematica
trying to replace the head (List) of the rule in ReplacePart... even
though this is just correct syntax for replace part.

I tried using RuleDelayed but no change. Many functions use rules in
their syntax so this must be a general issue I haven't come across
yet.

cheers

B

Raffy

unread,
Nov 8, 2010, 3:37:46 AM11/8/10
to

The two arguments in the definition of update are not patterns:
update[x, y] := ...

Try: update[x_, y_] := ...

niobe

unread,
Nov 9, 2010, 3:54:09 AM11/9/10
to
Apologies, that was just a typo when copying to email and my function
arguments are correct

update[x_, y_] := ReplacePart[


x,
{y[[1, 1]], y[[2, 1]]} -> x[[y[[1, 1]], y[[2, 1]]]] - y[[2, 2]]
]
.. SetDelayed::write: Tag List in <snip> is Protected.

Has no-one else encountered this issue?


Raffy

unread,
Nov 10, 2010, 6:27:45 AM11/10/10
to

Could you provide a x, y pair that reproduce this error?

I would avoid using ReplacePart. If I understand your example
correctly...

y is a ragged array: {{row}, {col0, col1}}

And you're performing the following operation: x[[row, col0]] - x[[row, col1]]

update2[x_, {{row_}, {col0_, col1_}}] := Module[{temp = x},
temp[[row, col0]] -= temp[[row, col1]];
temp
];

niobe

unread,
Nov 11, 2010, 6:11:39 AM11/11/10
to
> Could you provide a x, y pair that reproduce this error?

x={{7, 9, 0, 0, 10}, {4, 0, 3, 10, 9}, {4, 9, 0, 5, 0}, {0, 2, 1, 8,
5}, {2, 5, 3, 4, 4}, {1, 0, 4, 0, 0}, {1, 10, 6, 8, 9}}
y={{4, 5}, {3, 1}, {2, 6}}

> I would avoid using ReplacePart. If I understand your example
> correctly...
>
> y is a ragged array: {{row}, {col0, col1}}

Think of x as a lists of quantities and y as rules for adjusting them.
So in this example of y, decrement x[[4,3]] by 2, increment x[[5,3]]
by 2, increment x[[4,1]] by 6, decrement x[[5,1]] by 6,
But the point is that the operation works when not delayed. It seems
like the way command is being parsed is the problem as Mathematica is
thinking that the ReplacePart syntax is actual an operation on one of
the arguments. I am hoping there is a way to force the correct
interpretation.

0 new messages