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

Unrelated variable affects rsolve result

112 views
Skip to first unread message

Nils Kanning

unread,
Jan 30, 2012, 5:14:00 AM1/30/12
to
Hello,
I am using Mathematica 8.0.1.0 and I observed a strange behavior of the
function rsolve. The result rsolve produces is changed by a seemingly
unrelated variable, which I define before calling rsolve. Especially
rsolve seems to interfere with a variable called "K", whereas other
variables (for example "k") do not cause problems.

Here is some code, which illustrates this behavior:

In[1]:= k = {{1, 0}};
In[2]:= RSolve[ h[y] == 1 + h[y + 1], h[y], y]
Out[2]= {{h[y] -> -y + C[1]}}
In[3]:= K = {{1, 0}};
In[4]:= RSolve[ h[y] == 1 + h[y + 1], h[y], y]
During evaluation of In[4]:= Sum::write: Tag List in {{1,0}}[1] is
Protected. >>
Out[4]= {{h[y] -> C[1] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \({{1, 0}}[1] = 0\), \(\(-1\) +
y\)]\(-1\)\)}}

Is there a special meaning of "K" or does this variable just interfere
with some internals of rsolve?

Thanks,
Nils

Szabolcs

unread,
Jan 31, 2012, 5:40:08 AM1/31/12
to
Generally, it is best to avoid names starting with capital letters in Mathematica. This way you can make sure that none of your symbols will conflict with system symbols.

If you evaluate

?K

you will see that K is a system symbol. For some reason it is not protected, and I have never seen any use of it. But apparently it can cause trouble, as you show in your example.

Szabolcs

Bob Hanlon

unread,
Jan 31, 2012, 5:43:42 AM1/31/12
to
Evaluate

?? K

K is a default generic name for a summation index in a symbolic sum.

Hence the often repeated rule: To avoid naming conflicts with existing
or future internal Mathematica variable names, never start a
user-defined variable name with a capital letter.


Bob Hanlon

David Skulsky

unread,
Jan 31, 2012, 5:37:34 AM1/31/12
to
If you type ?K, you'll see the response "K is a default generic name for a summation index in a symbolic sum," which I suspect is causing the problem. It's generally a bad idea to use uppercase variable names...

Shizu

unread,
Jan 31, 2012, 5:38:05 AM1/31/12
to
?K
K is a default generic name for a summation index in a symbolic sum.

K is used internally by RSolve, etc. as an index for sums and products.

0 new messages