-
Notifications
You must be signed in to change notification settings - Fork 6
/
nondeterministic-stochastic-memoization.ss
68 lines (59 loc) · 2.64 KB
/
nondeterministic-stochastic-memoization.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!r6rs
(library
(nondeterministic-stochastic-memoization)
(export memoize-nondeterministic-stochastic
memoize-nondeterministic-removing-duplicates-stochastic
memoize-nondeterministic-stochastic-coalescing-duplicates
memoize-nondeterministic-removing-duplicates-stochastic-coalescing-duplicates
memoize-stochastic-nondeterministic
memoize-stochastic-coalescing-duplicates-nondeterministic
memoize-stochastic-nondeterministic-removing-duplicates
memoize-stochastic-coalescing-duplicates-nondeterministic-removing-duplicates)
(import (rnrs)
(nondeterministic-scheme)
(stochastic-scheme)
(deterministic-memoization))
(define (memoize-nondeterministic-stochastic f)
(let ((f (memoize
(lambda arguments (distribution (domain (apply f arguments)))))))
(lambda arguments (a-member-of (draw (apply f arguments))))))
(define (memoize-nondeterministic-removing-duplicates-stochastic f)
(let ((f (memoize
(lambda arguments
(distribution (remove-duplicates (domain (apply f arguments))))))))
(lambda arguments (a-member-of (draw (apply f arguments))))))
(define (memoize-nondeterministic-stochastic-coalescing-duplicates f)
(let ((f (memoize
(lambda arguments
(coalesce-duplicates
(distribution (domain (apply f arguments))))))))
(lambda arguments (a-member-of (draw (apply f arguments))))))
(define (memoize-nondeterministic-removing-duplicates-stochastic-coalescing-duplicates f)
(let ((f (memoize
(lambda arguments
(coalesce-duplicates
(distribution
(remove-duplicates (domain (apply f arguments)))))))))
(lambda arguments (a-member-of (draw (apply f arguments))))))
(define (memoize-stochastic-nondeterministic f)
(let ((f (memoize
(lambda arguments (domain (distribution (apply f arguments)))))))
(lambda arguments (draw (a-member-of (apply f arguments))))))
(define (memoize-stochastic-coalescing-duplicates-nondeterministic f)
(let ((f (memoize
(lambda arguments
(domain
(coalesce-duplicates (distribution (apply f arguments))))))))
(lambda arguments (draw (a-member-of (apply f arguments))))))
(define (memoize-stochastic-nondeterministic-removing-duplicates f)
(let ((f (memoize
(lambda arguments
(remove-duplicates (domain (distribution (apply f arguments))))))))
(lambda arguments (draw (a-member-of (apply f arguments))))))
(define (memoize-stochastic-coalescing-duplicates-nondeterministic-removing-duplicates f)
(let ((f (memoize
(lambda arguments
(remove-duplicates
(domain
(coalesce-duplicates (distribution (apply f arguments)))))))))
(lambda arguments (draw (a-member-of (apply f arguments)))))))