networks: Add boolean-power-n/stream.

This commit is contained in:
Sergiu Ivanov 2020-03-20 16:40:15 +01:00
parent 36c26d2a1f
commit e89163d044
2 changed files with 6 additions and 0 deletions

View File

@ -216,6 +216,7 @@
(check-equal? (tabulate/boolean (lambda (x y) (and x y)))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))
(check-equal? (boolean-power-n 2) '((#f #f) (#f #t) (#t #f) (#t #t)))
(check-equal? (stream->list (boolean-power-n/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))
(let ([negation (table->function '((#t #f) (#f #t)))]
[negation/list (table->function/list '((#t #f) (#f #t)))])
(check-true (negation #f)) (check-false (negation #t))

View File

@ -62,6 +62,7 @@
[table->function (-> (listof (*list/c any/c any/c)) procedure?)]
[table->function/list (-> (listof (*list/c any/c any/c)) procedure?)]
[boolean-power-n (-> number? (listof (listof boolean?)))]
[boolean-power-n/stream (-> number? (stream/c (listof boolean?)))]
[enumerate-boolean-tables (-> number? (stream/c (listof (*list/c any/c any/c))))]
[enumerate-boolean-functions (-> number? (stream/c procedure?))]
[enumerate-boolean-functions/list (-> number? (stream/c procedure?))])
@ -443,6 +444,10 @@
;;; Returns the n-th Cartesian power of the Boolean domain: {0,1}^n.
(define (boolean-power-n n) (apply cartesian-product (make-list n '(#f #t))))
;;; Like boolean-power-n, but returns a stream whose elements the
;;; elements of the Cartesian power.
(define (boolean-power-n/stream n) (apply cartesian-product/stream (make-list n '(#f #t))))
;;; Returns the stream of the truth tables of all Boolean functions of
;;; a given arity.
;;;