|
6
|
|
edited Apr 27 2011 at 14:44
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what letter is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult. The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
in:
A1[0,x_]:=1
A2[0,x_]:=1
A1[n_,x_]:=Sum[A1[-1 - j + n, x]*Sum[A1[j, k], {k, 0, -1 + x}], {j, 0, -1 + n}
n}]
A2[n_,x_]:=Sum[Sum[A2[j, k]*A2[-1 - j + n, x], {k, 0, -1 + x}], {j, 0, -1 + n}]
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|
|
5
|
|
edited Apr 27 2011 at 11:40
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what variable letter is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult. The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
in:
A1[0,x_]:=1
A2[0,x_]:=1
A1[n_,x_]:=Sum[A1[-1 - j + n, x]*Sum[A1[j, k], {k, 0, -1 + x}], {j, 0, -1 + n}
A2[n_,x_]:=Sum[Sum[A2[j, k]*A2[-1 - j + n, x], {k, 0, -1 + x}], {j, 0, -1 + n}]
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|
|
4
|
|
edited Apr 27 2011 at 11:27
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what variable is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult., difficult. The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
in:
A1[0,x_]:=1
A2[0,x_]:=1
Sum[A1[-1 A1[n_,x_]:=Sum[A1[-1 - j + n, x]*Sum[A1[j, k], {k, 0, -1 + x}], {j, 0, -1 + n}
Sum[Sum[A2[jA2[n_,x_]:=Sum[Sum[A2[j, k]*A2[-1 - j + n, x], {k, 0, -1 + x}], {j, 0, -1 + n}]
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|
|
3
|
|
edited Apr 27 2011 at 10:53
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what variable is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult., The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
in:
A1[0,x_]:=1
A2[0,x_]:=1
$\text{A1}[\text{n_},\text{x_}]\text{:=} \sum _{j=0}^{n-1} \left( \text{A1}[n-j-1,x]\sum _{k=0}^{x-1} \text{A1}[j,k]\right)$
$\text{A2}[\text{n_},\text{x_}]\text{:=}\sum _{j=0}^{n-1} \left(\text{ Sum[A1[-1 - j + n, x]*Sum[A1[j, k], {k, 0, -1 + x}], {j, 0, -1 + n}
\sum _{k=0}^{x-1} A2\left[ n-j-1,x \right] (A2[j,k])\right)$Sum[Sum[A2[j, k]*A2[-1 - j + n, x], {k, 0, -1 + x}], {j, 0, -1 + n}]
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|
|
2
|
|
edited Apr 27 2011 at 10:36
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what variable is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult., The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
in:
A1[0,x_]:=1
A2[0,x_]:=1
$\text{A1}[\text{n_},\text{x_}]\text{:=} \sum _{j=0}^{n-1} \left( \text{A1}[n-j-1,x]\sum _{k=0}^{x-1} \text{A1}[j,k]\right)$
$\text{A2}[\text{n_},\text{x_}]\text{:=}\sum _{j=0}^{n-1} \left(\text{ }\sum _{k=0}^{x-1} A2\left[ n-j-1,x \right] (A2[j,k])\right)$
out:
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|
|
1
|
|
answered Apr 27 2011 at 10:31
|
This error affects all versions of Mathematica from 6 to 8. The result of a function depends on what variable is chosen for argument when calling it. In the simplest case it can be illustrated as follows:
in:
$A[\text{x_}]\text{:=}\sum _{k=0}^{x-1} x $
$A[k]$
$A[z]$
out:
$1/2 (-1 + k) k$
$z^2$
The correct answer is evidently, the later. This behavior affects not only sums but also integrals, so one have to check so that the letter user for the argument not to coincide with the index variable used for definition. In the case of recursion this becomes very difficult., The following example shows that moving a factor not dependent on the index variable out of the sum sign changes the result:
A1[0,x_]:=1
A2[0,x_]:=1
$\text{A1}[\text{n_},\text{x_}]\text{:=} \sum _{j=0}^{n-1} \left( \text{A1}[n-j-1,x]\sum _{k=0}^{x-1} \text{A1}[j,k]\right)$
$\text{A2}[\text{n_},\text{x_}]\text{:=}\sum _{j=0}^{n-1} \left(\text{ }\sum _{k=0}^{x-1} A2\left[ n-j-1,x \right] (A2[j,k])\right)$
out:
A1[1,x]/.x->2
A1[2,x]/.x->2
A1[3,x]/.x->2
A2[1,x]/.x->2
A2[2,x]/.x->2
A2[3,x]/.x->2
A2[1,2]
A2[2,2]
A2[3,2]
out:
2
5
13
2
5
12
2
5
13
|
|
|