diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index 6d96ac1..4474b59 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -286,6 +286,21 @@ a @racket[TBF/State]. } +@defproc[(sbn? [tbn TBN]) Boolean]{ + +A SBN is a @racket[TBN] in which all @racket[TBF/State]s satisfy +@racket[sbf/state?]. + +All functions in @racket[tbn] must only reference variables appearing +in the network. This function does not check this condition. + +@ex[ +(let ([f1 (tbf/state (hash 'a -1 'b 1) 0)] + [f2 (tbf/state (hash 'a -1 'b 1) 1)]) + (values (sbn? (hash 'a f1 'b f1)) + (sbn? (hash 'a f1 'b f2)))) +]} + @section{Miscellaneous utilities} @defproc[(group-truth-table-by-nai [tt (Listof (Listof Integer))]) diff --git a/tbn.rkt b/tbn.rkt index 0ba0288..ceb4120 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -35,7 +35,7 @@ group-truth-table-by-nai - TBN + TBN sbn? ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -321,6 +321,17 @@ ((1 1 1 0)))))) (define-type TBN (HashTable Variable TBF/State)) + + (: sbn? (-> TBN Boolean)) + (define (sbn? tbn) (andmap sbf/state? (hash-values tbn))) + + (module+ test + (test-case "sbn?" + (define f1 (tbf/state (hash 'a -1 'b 1) 0)) + (define f2 (tbf/state (hash 'a -1 'b 1) 1)) + (check-true (sbn? (hash 'a f1 'b f1))) + (check-false (sbn? (hash 'a f1 'b f2)))) + ) ) (module+ test