Fri Aug 01 06:57:32Z 2025
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Tests summary
((ran 4) (failed 0))
In this document we report some tests about the following technique,
❝
The optimization of reification followed by (partial) flattening and reflection gives rise to the inference technique known as variable elimination [1]. Its benefit is demonstrated by the following example, computing the XOR of n coin tosses.
This trick transform a stochastic function a -> b
to a generally faster function:
let variable_elim f arg = reflect (exact_reify (fun () -> f arg))
According to the idea shown in [2], using symbolic manipulation, we show that the probability of XOR of 10 coin tosses to be tail is
provided that head has probability to appear in each toss. Moreover, the coefficients are the 10th row of a known sequence [3].
test/exponential
: pass(define (test/exponential _)
(define result
(probcc-reify/exact
(let loop ((p 'p) (n 10))
(cond ((equal? 1 n) (probcc-coin p))
(else
(let1 (r (loop p (sub1 n)))
(not (equal? (probcc-coin p) r))))))))
(⊦= expected result))
((eta 0.522) (memory #(6291456 1212504 1048576)) (stdout "") (stderr ""))
test/var-elimination
: pass(define (test/var-elimination _)
(define (flipxor-model p)
(letrec ((loop (probcc-variable-elimination
(λ (n)
(cond ((equal? 1 n) (probcc-coin p))
(else
(let1 (r (loop (sub1 n)))
(not (equal? (probcc-coin p) r)))))))))
loop))
(define res (probcc-reify/exact ((flipxor-model 'p) 10)))
(⊦= expanded-expected res))
((eta 0.03) (memory #(6291456 1208720 1048576)) (stdout "") (stderr ""))
test/bucket
: pass(define (test/bucket _)
(define (flipxor-model p)
(letrec ((loop (λ-probcc-bucket
(n)
(cond ((equal? 1 n) (probcc-coin p))
(else
(let1 (r (loop (sub1 n)))
(not (equal? (probcc-coin p) r))))))))
loop))
(define res (probcc-reify/exact ((flipxor-model 'p) 10)))
(⊦= expanded-expected res))
((eta 0.053) (memory #(6291456 1209488 1048576)) (stdout "") (stderr ""))
test/bucket/generic
: passThis test generalizes the previous one in the sense that each coin has a different probability for head; in particular, the exact inference for the XOR of 5 such coins yields that tail has probability:
provided that coin's heads have probabilities , , , and , respectively.
(define (test/bucket/generic _)
(define flipxor-model
(letrec ((loop (λ-probcc-bucket
(n)
(cond ((null? (cdr n)) (probcc-coin (car n)))
(else
(let1 (r (loop (cdr n)))
(not (equal? (probcc-coin (car n)) r))))))))
loop))
(define res (probcc-reify/exact (flipxor-model '(a b c d e))))
(⊦= '(((V #f)
(Plus 1
(Times -1 c)
(Times -1 d)
(Times 2 c d)
(Times -1 e)
(Times 2 c e)
(Times 2 d e)
(Times -4 c d e)
(Times b
(Plus -1 (Times 2 c))
(Plus -1 (Times 2 d))
(Plus -1 (Times 2 e)))
(Times -1
a
(Plus -1 (Times 2 b))
(Plus -1 (Times 2 c))
(Plus -1 (Times 2 d))
(Plus -1 (Times 2 e)))))
((V #t)
(Plus c
d
(Times -2 c d)
e
(Times -2 c e)
(Times -2 d e)
(Times 4 c d e)
(Times -1
b
(Plus -1 (Times 2 c))
(Plus -1 (Times 2 d))
(Plus -1 (Times 2 e)))
(Times a
(Plus -1 (Times 2 b))
(Plus -1 (Times 2 c))
(Plus -1 (Times 2 d))
(Plus -1 (Times 2 e))))))
res))
((eta 0.014) (memory #(6291456 1223000 1048576)) (stdout "") (stderr ""))