diff --git a/networks.rkt b/networks.rkt index 4f0dc90..3965374 100644 --- a/networks.rkt +++ b/networks.rkt @@ -51,7 +51,7 @@ table+vars->network table->network table+headers->network random-function/state random-boolean-function/state random-network - random-boolean-network + random-boolean-network random-boolean-network/n ) (define-type (State a) (VariableMapping a)) @@ -1109,6 +1109,26 @@ (#t #f #t #f #t #f) (#t #t #f #f #f #t) (#t #t #t #t #t #f))))) + + (: random-boolean-network/n (-> Positive-Integer (Network Boolean))) + (define (random-boolean-network/n n) + (random-boolean-network (for/list : (Listof Variable) + ([i (in-range n)]) + (string->symbol (format "x~a" i))))) + + (module+ test + (test-case "random-boolean-network/n" + (check-equal? + (tabulate-network+headers (random-boolean-network/n 3)) + '((x0 x1 x2 f-x0 f-x1 f-x2) + (#f #f #f #f #t #f) + (#f #f #t #f #f #t) + (#f #t #f #t #f #f) + (#f #t #t #f #t #t) + (#t #f #f #t #t #t) + (#t #f #t #t #f #t) + (#t #t #f #t #t #f) + (#t #t #t #t #f #t))))) ) (require 'typed) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 15abf32..4c1530c 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -934,6 +934,17 @@ Generates a random Boolean network with the given variables. (tabulate-network+headers (random-boolean-network '(x y z))) ]} +@defproc[(random-boolean-network/n [n Positive-Integer]) + (Network Boolean)]{ + +Like @racket[random-boolean-network], but also generates the names of +the variables for the network. The variables have the names @tt{x0} +to @tt{xk}, where @italic{k = n - 1}. + +@ex[ +(tabulate-network+headers (random-boolean-network/n 3)) +]} + @section{TBF/TBN and SBF/SBN} This section defines threshold Boolean functions (TBF) and networks (TBN), as