networks,enumerate-boolean-tables: Use boolean-power/stream.

This commit is contained in:
Sergiu Ivanov 2020-03-20 16:43:14 +01:00
parent 59d5b040f4
commit 519f3759ea

View file

@ -453,10 +453,10 @@
;;; ;;;
;;; There are 2^(2^n) Boolean functions of arity n. ;;; There are 2^(2^n) Boolean functions of arity n.
(define (enumerate-boolean-tables n) (define (enumerate-boolean-tables n)
(let ([inputs (boolean-power n)] (let ([inputs (boolean-power/stream n)]
[outputs (boolean-power (expt 2 n))]) [outputs (boolean-power/stream (expt 2 n))])
(for/stream ([out outputs]) (for/stream ([out (in-stream outputs)])
(for/list ([in inputs] [o out]) (for/list ([in (in-stream inputs)] [o out])
(append in (list o)))))) (append in (list o))))))
;;; Returns the stream of all Boolean functions of a given arity. ;;; 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. ;;; There are 2^(2^n) Boolean functions of arity n.
(define (enumerate-boolean-functions/list n) (define (enumerate-boolean-functions/list n)
(stream-map table->function/list (enumerate-boolean-tables 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)])
))