I've found three bugs in transform_equals_condition inside church_astify.js.
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.
For flip, we want to condition using equal? rather than = (due to types and stuff), but the code currently doesn't do this.
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.
I've found three bugs in
transform_equals_condition
insidechurch_astify.js
.transform_erp
, it assumes that all ERPs that can be conditioned on equality take exactly two parameters. This is wrong forflip
.flip
, we want to condition usingequal?
rather than=
(due to types and stuff), but the code currently doesn't do this.uniform-draw
to be the same as conditioning onuniform
. Consider this simple model:This errors because the call to
uniform_draw
is mistakenly interpreted as a call touniform
. The generated JS is this:The relevant line is
var call0 = ...
. Note thatwrapped_uniform_draw
is being called with four parameters (which is appropriate foruniform
but notuniform-draw
).I would fix this myself but I don't quite understand what is going on with
define_table
and so on insidetry_transform
.