hakaru-dev / hakaru

A probabilistic programming language
BSD 3-Clause "New" or "Revised" License
310 stars 30 forks source link

Expect transformation lost a binder #203

Open ccshan opened 5 years ago

ccshan commented 5 years ago
$ cat try.hk
expect
  _ <~
    x <~ y <~ lebesgue(-inf,inf)
         if 0<y: dirac(y) else: reject.measure(real)
    dirac(x)
  : 1
$ pretty try.hk 
x3 = -prob2real(∞)
x4 = prob2real(∞)
if nat2real(0) < x5: nat2prob(1) else: 0/1

The variable x5 produced above is unbound.

zaxtax commented 5 years ago

The correct output should be the following right?

x3 = -prob2real(∞)
x4 = prob2real(∞)
integrate x5 from x3 to x4:
    if nat2real(0) < x5: nat2prob(1) else: 0/1
ccshan commented 5 years ago

That output is correct!

zaxtax commented 5 years ago

Ok I think my recent change fixed the problem, but I'm not entirely confident if my change is the correct thing to do. I'm looking over Preserving Sharing in the Partial Evaluation of Lazy Functional Programs to see if I should have residualized the heap somewhere else instead.