networks,enumerate-boolean-tables: Use boolean-power/stream.
This commit is contained in:
parent
59d5b040f4
commit
519f3759ea
1 changed files with 10 additions and 4 deletions
14
networks.rkt
14
networks.rkt
|
@ -453,10 +453,10 @@
|
|||
;;;
|
||||
;;; There are 2^(2^n) Boolean functions of arity n.
|
||||
(define (enumerate-boolean-tables n)
|
||||
(let ([inputs (boolean-power n)]
|
||||
[outputs (boolean-power (expt 2 n))])
|
||||
(for/stream ([out outputs])
|
||||
(for/list ([in inputs] [o out])
|
||||
(let ([inputs (boolean-power/stream n)]
|
||||
[outputs (boolean-power/stream (expt 2 n))])
|
||||
(for/stream ([out (in-stream outputs)])
|
||||
(for/list ([in (in-stream inputs)] [o out])
|
||||
(append in (list o))))))
|
||||
|
||||
;;; Returns the stream of all Boolean functions of a given arity.
|
||||
|
@ -473,3 +473,9 @@
|
|||
;;; There are 2^(2^n) Boolean functions of arity n.
|
||||
(define (enumerate-boolean-functions/list n)
|
||||
(stream-map table->function/list (enumerate-boolean-tables n)))
|
||||
|
||||
;;; Generates a random truth table for a Boolean function of arity n.
|
||||
#;
|
||||
(define (random-boolean-function n)
|
||||
(let ([inputs (boolean-power-n n)])
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue