diff --git a/networks.rkt b/networks.rkt index db65417..3617d83 100644 --- a/networks.rkt +++ b/networks.rkt @@ -39,7 +39,7 @@ pretty-print-state pretty-print-state/01 pretty-print-state-graph-with pretty-print-state-graph ppsg pretty-print-state-graph/01 ppsg01 - tabulate-state* + tabulate-state* tabulate-state*/boolean ) (define-type (State a) (VariableMapping a)) @@ -756,6 +756,24 @@ (1 3 4 -2) (2 2 4 0) (2 3 5 -1))))) + + (: tabulate-state*/boolean + (-> (Listof (-> (State Boolean) Boolean)) (Listof Variable) + (Listof (Listof Boolean)))) + (define (tabulate-state*/boolean funcs args) + (tabulate-state* funcs (make-boolean-domains args))) + + (module+ test + (test-case "tabulate-state*/boolean" + (define (f1 [st : (State Boolean)]) + (auto-hash-ref/: st (and :a :b))) + (define (f2 [st : (State Boolean)]) + (auto-hash-ref/: st (or :a :b))) + (check-equal? (tabulate-state*/boolean (list f1 f2) '(a b)) + '((#f #f #f #f) + (#f #t #f #t) + (#t #f #f #t) + (#t #t #t #t))))) ) (require 'typed) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 0c0fd04..35c0eff 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -735,6 +735,22 @@ the states. (tabulate-state* (list f1 f2) (hash 'a '(1 2) 'b '(2 3)))) ]} +@defproc[(tabulate-state*/boolean [funcs (Listof (-> State Boolean) Boolean)] + [args (Listof Variable)]) + (Listof (Listof Boolean))]{ + +Like @racket[tabulate-state*], but the functions operate on Boolean states. +The list @racket[args] is used to generate all possible Boolean states +containing the variables appearing on this list. + +@ex[ +(let ([f1 (λ ([st : (State Boolean)]) + (auto-hash-ref/: st (and :a :b)))] + [f2 (λ ([st : (State Boolean)]) + (auto-hash-ref/: st (or :a :b)))]) + (tabulate-state*/boolean (list f1 f2) '(a b))) +]} + @section{Constructing functions and networks} @section{Random functions and networks}