[mercury-users] Better way of writing this?

Ralph Becket rafe at cs.mu.OZ.AU
Thu Jun 30 16:26:06 AEST 2005


Peter Hawkins, Thursday, 30 June 2005:
> Hi...
> 
> I brought this up with people earlier today, but the verdict was I 
> should send email to mercury-users (like this one). I'm trying to write 
> code to find maximal weighted Hamming codes using the new set solver, 
> and I can't think of a better way of writing a particular piece of code 
> than an exceedingly ugly method. The problem is described on pages 30 
> and 31 of http://www.hawkins.emu.id.au/papers/hons_thesis.pdf.
> 
> Here is the relevant predicate:
> [...]
> 
> Note that create new variables is not 'free', and we want to reuse 
> constraint variables if at all possible. (Here new variables are created 
> by n_bit_cset/1).

This last paragraph explains the horridness.  Your program is using
sneaky tricks because it attempts to minimise the number of BDD
variables that are constructed.

Two potential solutions occur to me:

(1) bite the bullet and simply pre-initialise the largest set of BDD
variables you are prepared to consume and just use those to construct
your constraints;

(2) use something like the lazy list module in extras to lazily
construct BDD variables (the lazy list module overwrites a thunk with
its result when evaluation is forced the first time; this is not undone
on backtracking).

-- Ralph
--------------------------------------------------------------------------
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