MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Algorithm Analysis Course: Should I use Mathematica for projects?


On 14 Jul 2012, at 22:44, Richard Fateman wrote:

>> B = Table[i, {i, 0, 1000}];
>> B[[5]] = j; Timing[Do[B[[50]]++, {i, 0, 100000}]]
>>
>> This sort of thing can certainly change the length of a list. A simple example:
>>
>> Clear[B]
>>
>>  j /: {a___, j, b__} := {a, 1, 1, b}
>>
>> B = Table[i, {i, 0, 5}];
>> Length[B]
>> 6
>>
>> B[[5]] = j;
>> Length[B]
>> 7
>>
>> It would seem to me that this alone should force re-evaluation of the list.
> The activity which is being timed is  B[[50]]    or B[[50]]++
> neither of which changes the length of the list/ size of the array.

Yes, but this can also trigger a change in the length if the list contains a symbol with and UpValue. For example:



j /: {a___, j, 3, b__} := {a, 1, 1, 2, b}

B = Table[i, {i, 0, 5}];

B[[2]] = j;

B[[2]] = j;

Do[B[[3]]++, {3}]

B

{0,1,1,2,3,4,5}

The length of the list has changed. As long as the list contains a symbol that might have an UpValue any change of any index can change the length of the list. I still think that makes re-evaluation necessary.

Andrzej




  • Prev by Date: Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • Next by Date: Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • Previous by thread: Re: Algorithm Analysis Course: Should I use Mathematica for projects?
  • Next by thread: Re: Algorithm Analysis Course: Should I use Mathematica for projects?