Tue May 20 10:56:40+0200 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 1.606) (memory #(6291456 1203288 1048576)) (stdout "") (stderr ""))
test/var-elimination
: pass(define (test/var-elimination _)
(define (flipxor-model p)
(letrec ((loop (λ (n)
(cond ((equal? 1 n) (probcc-coin p))
(else
(let1 (r ((probcc-variable-elimination loop) (sub1 n)))
(not (equal? (probcc-coin p) r))))))))
loop))
(define res (probcc-reify/exact ((flipxor-model 'p) 10)))
(⊦= expanded-expected res))
((eta 0.059) (memory #(6291456 1200640 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.068) (memory #(6291456 1200720 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.04) (memory #(6291456 1337360 1048576)) (stdout "") (stderr ""))