Type normalized-tbn?.
This commit is contained in:
parent
f05024e61e
commit
f0a20646ef
2 changed files with 31 additions and 1 deletions
|
@ -453,6 +453,21 @@ and pretty-prints the node labels.
|
|||
'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}
|
||||
|
||||
@defproc[(group-truth-table-by-nai [tt (Listof (Listof Integer))])
|
||||
|
|
17
tbn.rkt
17
tbn.rkt
|
@ -38,7 +38,7 @@
|
|||
|
||||
TBN sbn? tbn->network
|
||||
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)))
|
||||
|
@ -514,6 +514,21 @@
|
|||
(hash 'a (tbf/state (hash 'a -1 'b 1) 0)
|
||||
'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")))
|
||||
|
||||
(: 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
|
||||
|
|
Loading…
Reference in a new issue