[mercury-users] Mercury in academic teaching?

Peter Schachte schachte at csse.unimelb.edu.au
Wed Oct 11 14:11:19 AEST 2006


On Wed, Oct 11, 2006 at 01:42:44PM +1000, Ralph Becket wrote:
> Peter Schachte, Wednesday, 11 October 2006:
> > But, AFAIK (correct me if I'm wrong), these optimizations only improve
> > the constant factors -- significantly, but still only constant
> > factors.
> 
> Not entirely: the accumulator introduction optimisation can turn a quadratic
> algorithm into a linear one; so can memoisation.

Ah, I didn't realize accumulator introduction was actually in the
compiler and working (and I forgot about memoization).  Does this mean
I can stop using difference pairs and start write simpler code that
uses append to piece lists together?  That would make some code much
simpler and more readable.

> > The user must still optimize the code.
> 
> I disagree: the user should only ever optimise code if performance is
> inadequate.

I agree in principle, although sometimes you just *know* that the
naive way is not going to be efficient enough.

> If it is, hand optimization must be guided by profiling
> data.  And note that hand optimisation requires a fair understanding of the
> underlying execution algorithm (so it's something we should positively
> discourage beginners from doing!)

I was thinking of high-level optimization, which doesn't really need
any deep understanding of execution model.  Eg, the difference between
permutation sort and bubblesort and mergesort, or the difference
between doing 8 queens by trying all 2^64 possible placements of
queens on the board vs. the 64!/(56!*8!)  placements of 8 queens on
the board vs. the 8! placements of one queen in each row and each
column.  I think it is important for students to understand that sort
of optimization.  And at that level, optimization of Prolog or Mercury
(or C, for that matter) code are not very different.

-- 
Peter Schachte              Fools ignore complexity. Pragmatists suffer it.
schachte at cs.mu.OZ.AU        Some can avoid it. Geniuses remove it.
www.cs.mu.oz.au/~schachte/      -- Alan Perlis 
Phone: +61 3 8344 1338      
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list