[mercury-users] pragma compiled_memo for compile-time tabled evaluation

Stefan Karrmann sk at mathematik.uni-ulm.de
Sat Sep 6 05:44:40 AEST 2003


André Platzer (Fri, Sep 05, 2003 at 04:03:42PM +0200):
> Hello Mercury users!
> 
> Is there any way to extend tabled evaluation to compile-time? As far as 
> I understand, normal tabled evaluation memorises values computed at 
> run-time. On an invocation with the same arguments, then mercury reuses 
> those values instead of a second computation. This is very cool.
> 
> However, I wonder if there is a way to extend this idea to compile-time. 
> So in case of a constant function like
> 
>    %% computes the number pi with a precision of 500 digits.
>    :- func pi_to_500_digits = string.
>    :- mode pi_to_500_digits = out is det.
>    :- pragma memo(pi_to_500_digits/0).
> 
> after compilation, the program will compute pi to 500 digits only at the 
> first time this constant is used, but repeat this computation for every 
> program run. An improvement in this situation of constant functions (or 
> at least functions depending upon arguments of a small finite domain) 
> would be to perform the respective computation only once, at 
> compile-time instead of repeatedly at each new program run. The compiler 
> would evaluate the function at compile-time and store its tabled value 
> instead of the machine code for performing the computation.

How could one balance compile-time computation against space
consumption? E.g. (in Haskell - sorry)

pi_s_500_digit = pi_to_500_digits !! 500

The space consumption of the result is small, but the computation is
expensive. This is a good case for compile-time computation. While

enumerate_123456 = [1..123456]

consumes much space and minimal time. To decide automatically about
compile-time computation we may need a pragma that sets a threshold:

:- pragma reductions_per_byte_at_compile_time(10).

Store the value in the library if the compiler needs 10 or more
reductions per byte of the value.

Sincerly,
-- 
Stefan
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list