From e89163d0446f1cc0a5a4991760e57f8ca15a7cd0 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 20 Mar 2020 16:40:15 +0100 Subject: [PATCH] networks: Add boolean-power-n/stream. --- networks-tests.rkt | 1 + networks.rkt | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/networks-tests.rkt b/networks-tests.rkt index 4c1c285..62e0202 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -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)) diff --git a/networks.rkt b/networks.rkt index 2977ddd..32770f8 100644 --- a/networks.rkt +++ b/networks.rkt @@ -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. ;;;