Type normalized-tbn?.

This commit is contained in:
Sergiu Ivanov 2023-07-14 16:21:20 +02:00
parent f05024e61e
commit f0a20646ef
2 changed files with 31 additions and 1 deletions

View file

@ -453,6 +453,21 @@ and pretty-prints the node labels.
'b (tbf/state (hash 'a -1 'b 1) 1)))) 'b (tbf/state (hash 'a -1 'b 1) 1))))
]} ]}
@defproc[(normalized-tbn? [tbn TBN]) Boolean]{
Checks whether @racket[tbn] is normalized: whether all of the
functions have the same inputs, and whether these inputs are exactly
the variables of @racket[tbn].
@ex[
(normalized-tbn?
(hash 'x (tbf/state (hash 'x 0 'y -1) -1)
'y (tbf/state (hash 'x -1 'y 0) -1)))
(normalized-tbn?
(hash 'x (tbf/state (hash 'x 0 ) -1)
'y (tbf/state (hash 'y 0) -1)))
]}
@section{Miscellaneous utilities} @section{Miscellaneous utilities}
@defproc[(group-truth-table-by-nai [tt (Listof (Listof Integer))]) @defproc[(group-truth-table-by-nai [tt (Listof (Listof Integer))])

17
tbn.rkt
View file

@ -38,7 +38,7 @@
TBN sbn? tbn->network TBN sbn? tbn->network
parse-org-tbn read-org-tbn read-org-sbn parse-org-tbn read-org-tbn read-org-sbn
build-tbn-state-graph build-tbn-state-graph normalized-tbn?
) )
(: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One)))
@ -514,6 +514,21 @@
(hash 'a (tbf/state (hash 'a -1 'b 1) 0) (hash 'a (tbf/state (hash 'a -1 'b 1) 0)
'b (tbf/state (hash 'a -1 'b 1) 1)))) 'b (tbf/state (hash 'a -1 'b 1) 1))))
"digraph G {\n\tnode0 [label=\"a:0 b:0\"];\n\tnode1 [label=\"a:1 b:1\"];\n\tnode2 [label=\"a:0 b:1\"];\n\tnode3 [label=\"a:1 b:0\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [];\n\t}\n\tsubgraph D {\n\t\tnode1 -> node0 [];\n\t\tnode2 -> node3 [];\n\t\tnode3 -> node0 [];\n\t}\n}\n"))) "digraph G {\n\tnode0 [label=\"a:0 b:0\"];\n\tnode1 [label=\"a:1 b:1\"];\n\tnode2 [label=\"a:0 b:1\"];\n\tnode3 [label=\"a:1 b:0\"];\n\tsubgraph U {\n\t\tedge [dir=none];\n\t\tnode0 -> node0 [];\n\t}\n\tsubgraph D {\n\t\tnode1 -> node0 [];\n\t\tnode2 -> node3 [];\n\t\tnode3 -> node0 [];\n\t}\n}\n")))
(: normalized-tbn? (-> TBN Boolean))
(define (normalized-tbn? tbn)
(define tbn-vars (hash-keys tbn))
(for/and ([tbf (in-list (hash-values tbn))])
(set=? tbn-vars (hash-keys (tbf/state-w tbf)))))
(module+ test
(test-case "normalized-tbn?"
(check-true (normalized-tbn?
(hash 'x (tbf/state (hash 'x 0 'y -1) -1)
'y (tbf/state (hash 'x -1 'y 0) -1))))
(check-false (normalized-tbn?
(hash 'x (tbf/state (hash 'x 0 ) -1)
'y (tbf/state (hash 'y 0) -1))))))
) )
(module+ test (module+ test