hakaru-dev / hakaru

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

Expect generates code with non-existent out-of-scope variable #208

Open Programmerino opened 1 year ago

Programmerino commented 1 year ago

The following code:

expect x <~ categorical([0.5, 0.5]):
    x

generates

(summate x4
 from 0
 to size
      (array x3 of size(x1):
       x1[x3]
       * (x1 = [1/2, 1/2]
          x2 = summate x0 from 0 to size(x1): x1[x0]
          if 0/1 < x2: nat2prob(x3) else: 0/1)):
   (array x3 of size(x1):
    x1[x3]
    * (x1 = [1/2, 1/2]
       x2 = summate x0 from 0 to size(x1): x1[x0]
       if 0/1 < x2: nat2prob(x3) else: 0/1))
     [x4])
/ x2

which is incorrect because:

Name not in scope: x1

4|       (array x3 of size(x1):