next_inactive up previous







Computational Logic
Efficiency Issues in Prolog

Efficiency

Data structures

Data structures (Contd.)

Let Unification Do the Work

Let Unification Do the Work (Contd.)

Database

Database (Contd.)

Determinism (I)

Determinism (II)

Search order

Indexing

Indexing (Contd.)

Iteration vs. Recursion

Iteration vs. Recursion (Contd.)

Cuts


Delaying Work


  • Example:
        x2x3([], []). 
        x2x3([X|Xs], [NX|NXs]):- 
                NX is -X * 2, 
                X < 0, 
                x2x3(Xs, NXs). 
        x2x3([X|Xs], [NX|NXs]):- 
                NX is X * 3, 
                X >= 0, 
                x2x3(Xs, NXs).
    

    100000 elements: 1.05 sec.
  • Delaying the arithmetic operations


        x2x3_1([], []). 
        x2x3_1([X|Xs], [NX|NXs]):- 
                X < 0, 
                NX is -X * 2, 
                x2x3_1(Xs, NXs). 
        x2x3_1([X|Xs], [NX|NXs]):- 
                X >= 0, 
                NX is X * 3, 
                x2x3_1(Xs, NXs).
    

    100000 elements: 0.9 sec.

Delaying Work


Conclusions



next_inactive up previous
Last modification: Wed Nov 22 23:29:06 CET 2006 <webmaster@clip.dia.fi.upm.es>[CLIP] [FIM] [UNM]