Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uunet!mstan!amull From: amull@Morgan.COM (Andrew P. Mullhaupt) Newsgroups: comp.lang.pascal Subject: Re: Problem in Turbo Pascal 4.0 Summary: Reduction of Strength is probably available Message-ID: <632@s5.Morgan.COM> Date: 31 Dec 89 18:37:11 GMT References: <4658@ur-cc.UUCP> <4660@ur-cc.UUCP> <1989Dec31.145504.2373@cs.dal.ca> Organization: Morgan Stanley & Co. NY, NY Lines: 32 In article <1989Dec31.145504.2373@cs.dal.ca>, silvert@cs.dal.ca (Bill Silvert) writes: > In article <4660@ur-cc.UUCP> lowj_ltd@uhura.cc.rochester.edu (John Alan Low, aka "Travis" Low) writes: > > The best solution in terms of speed was: > > Make x an integer (start at 10) and increment by 1 each time. Where > > x is used in the loop, subsitute x/100. Terminate when x = 30. > > Just for the record, if you substitute 0.01*x it will run faster. This is a case where the program transformation called 'Reduction of Strength' will improve the speed of your program. The idea is that when an arithmetic progression of numbers is required in a loop, that it is faster to generate the progression by the recurrence x(k) = x(k-1) + d where d is the common difference, than by the multiplicative formula x(k) = x(1) + d * (k-1) which requires multiplication. There are many machines, (Especially the Cray computers or the newer RISC machines on which integer multiplies are considerably slower than other instructions. It is one of the advantages of the loop invariant - monotone function style of loop construction that these optimizations often suggest themselves when the code is written in this way. Later, Andrew Mullhaupt