- Hello,

I have what seems a strange result. Maybe I am overlooking

something obvious. I am using the CuDD library via Ocaml in

the following function:

let rec create_vars = function

| [] -> []

| h::t -> begin

match h with

| Var(i,_) -> Printf.printf "New var = %d\n" i ;

(*(Bdd.newvar_at_level man i) :: create_vars t*)

let v = Bdd.newvar_at_level man i

in v :: create_vars t

| _ -> raise_source_pos_exception "Expected a variable." pos

end

The function "Bdd.newvar_at_level man i" holds "state"

in that it increments the number of variables in the BDD.

When I use:

(Bdd.newvar_at_level man i) :: create_vars t

or

Bdd.newvar_at_level man i :: create_vars t

Two additional variables in a list of three are created.

If I use:

let v = Bdd.newvar_at_level man i

in v :: create_vars t

then the number of variables is correct.

I therefore conclude that in the first 2 version

the function is executed a second time, supposedly

when recursion is terminating.

What am I doing wrong here?

TIA,

Hugo F. - On Fri, 1 Aug 2008, hmf@... wrote:

> Hello,

Without looking deeply at your code, I suspect that your problem is in:

>

> I have what seems a strange result. Maybe I am overlooking

> something obvious. I am using the CuDD library via Ocaml in

> the following function:

>

> let rec create_vars = function

> | [] -> []

> | h::t -> begin

> match h with

> | Var(i,_) -> Printf.printf "New var = %d\n" i ;

> (*(Bdd.newvar_at_level man i) :: create_vars t*)

> let v = Bdd.newvar_at_level man i

> in v :: create_vars t

> | _ -> raise_source_pos_exception "Expected a variable." pos

> end

>

> The function "Bdd.newvar_at_level man i" holds "state"

> in that it increments the number of variables in the BDD.

> When I use:

> (Bdd.newvar_at_level man i) :: create_vars t

> or

> Bdd.newvar_at_level man i :: create_vars t

>

> Two additional variables in a list of three are created.

> If I use:

> let v = Bdd.newvar_at_level man i

> in v :: create_vars t

> then the number of variables is correct.

>

> I therefore conclude that in the first 2 version

> the function is executed a second time, supposedly

> when recursion is terminating.

>

> What am I doing wrong here?

expr1 :: expr2

You can't assume that expr1 will be evaluated before expr2.

Always do:

let x = expr1 in

x :: expr2

And sorry if it's not the cause of your problem...

Martin

--

http://mjambon.com/ - Martin,

Martin Jambon wrote:> On Fri, 1 Aug 2008, hmf@... wrote:

..

>

>> Hello,

>>

>

Which I did in fact.

> Without looking deeply at your code, I suspect that your problem is in:

>

> expr1 :: expr2

>

> You can't assume that expr1 will be evaluated before expr2.

> Always do:

That's it! I was already thinking of race-conditions and what not.

>

> let x = expr1 in

> x :: expr2

>

> And sorry if it's not the cause of your problem...

>

I was not understanding why the similar functions:

Bdd.ithvar man i in

Bdd.newvar_at_level man i in

Bdd.newvar man in

which create variables did not generate the same results.

The problem is "Bdd.newvar_at_level man i" shifts the variables

for a given level "i" to make room for new ones. I had assumed

I was going through the levels in order, hence expected no

"shifting".

A quick test shows that a call "Bdd.newvar_at_level man i"

with "i" in inverse order generates those extra variables.

Merci beaucoup,

Hugo F.

>

http://www.connettivo.net/cntprojects/ocaml_beginners/

> Martin

>

> --

> http://mjambon.com/

>

> ------------------------------------

>

> Archives up to December 31, 2007 are also downloadable at

> The archives of the very official ocaml list (the seniors' one) can be found

at http://caml.inria.fr

> Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo!

Groups Links

>

>

>

>