probmods / webchurch

A Church to Javascript compiler (DEPRECATED)
Other
140 stars 15 forks source link

Bugs with transform_equals_condition #53

Closed longouyang closed 10 years ago

longouyang commented 10 years ago

I've found three bugs in transform_equals_condition inside church_astify.js.

  1. In the inner function transform_erp, it assumes that all ERPs that can be conditioned on equality take exactly two parameters. This is wrong for flip.
  2. For flip, we want to condition using equal? rather than = (due to types and stuff), but the code currently doesn't do this.
  3. Conditioning on equality is considering uniform-draw to be the same as conditioning on uniform. Consider this simple model:
(define samps
  (mh-query
   1000 1 
   (define lst '(1 2 3))
   (define x (uniform-draw lst))
   x
   (= x 1)))

(mean samps)

This errors because the call to uniform_draw is mistakenly interpreted as a call to uniform. The generated JS is this:

var __pr = require('./probabilistic-js');
__pr.openModule(__pr);
var __ch = require('./church_builtins');
openModule(__ch);
enterfn(1);
var call1 = wrapped_mh_query(function () {
        var lst = [
                1,
                2,
                3,
                null
            ];
        enterfn(0);
        var call0 = wrapped_uniform_draw(lst, undefined, undefined, 1);
        leavefn();
        var x = call0;
        return x;
    }, 1000, 1);
leavefn();
var samps = call1;
enterfn(2);
var call2 = mean(samps);
leavefn();
call2;

The relevant line is var call0 = .... Note that wrapped_uniform_draw is being called with four parameters (which is appropriate for uniform but not uniform-draw).

I would fix this myself but I don't quite understand what is going on with define_table and so on inside try_transform.

longouyang commented 10 years ago

@juliusc This got fixed at some point, right?

juliusc commented 10 years ago

Oops, forgot to close. This was fixed in 1fcac20c3ddc3a8322db3078e45ba46741fc8990