diff --git a/networks.rkt b/networks.rkt index a61e080..52cd037 100644 --- a/networks.rkt +++ b/networks.rkt @@ -72,8 +72,6 @@ [table->function (-> (listof (*list/c any/c any/c)) procedure?)] [table->function/list (-> (listof (*list/c any/c any/c)) procedure?)] [table->network (->* ((listof (*list/c any/c any/c))) (#:headers boolean?) network?)] - [boolean-power (-> number? (listof (listof boolean?)))] - [boolean-power/stream (-> number? (stream/c (listof boolean?)))] [enumerate-boolean-tables (-> number? (stream/c (listof (*list/c boolean? boolean?))))] [enumerate-boolean-functions (-> number? (stream/c procedure?))] [enumerate-boolean-functions/list (-> number? (stream/c procedure?))] @@ -908,21 +906,6 @@ (check-false (f2 (make-state '((x1 . #t) (x2 . #f))))) (check-true (f2 (make-state '((x1 . #t) (x2 . #t))))))) -;;; Returns the n-th Cartesian power of the Boolean domain: {0,1}^n. -(define (boolean-power n) (apply cartesian-product (make-list n '(#f #t)))) - -(module+ test - (test-case "boolean-power" - (check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t))))) - -;;; Like boolean-power, but returns a stream whose elements the -;;; elements of the Cartesian power. -(define (boolean-power/stream n) (apply cartesian-product/stream (make-list n '(#f #t)))) - -(module+ test - (test-case "boolean-power/stream" - (check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t))))) - ;;; Returns the stream of the truth tables of all Boolean functions of ;;; a given arity. ;;; diff --git a/utils.rkt b/utils.rkt index 40c2eb1..a25ce78 100644 --- a/utils.rkt +++ b/utils.rkt @@ -46,7 +46,9 @@ (-> (integer-in 1 4294967087) (stream/c exact-nonnegative-integer?)) (-> exact-integer? (integer-in 1 4294967087) (stream/c exact-nonnegative-integer?)))] - [cartesian-product/stream (->* () #:rest (listof stream?) stream?)]) + [cartesian-product/stream (->* () #:rest (listof stream?) stream?)] + [boolean-power (-> number? (listof (listof boolean?)))] + [boolean-power/stream (-> number? (stream/c (listof boolean?)))]) ;; Contracts (contract-out [variable-mapping? contract?] [string-variable-mapping? contract?] @@ -674,3 +676,23 @@ (2 4 b) (2 5 a) (2 5 b))))) + + +;;; ================== +;;; Boolean operations +;;; ================== + +;;; Returns the n-th Cartesian power of the Boolean domain: {0,1}^n. +(define (boolean-power n) (apply cartesian-product (make-list n '(#f #t)))) + +(module+ test + (test-case "boolean-power" + (check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t))))) + +;;; Like boolean-power, but returns a stream whose elements the +;;; elements of the Cartesian power. +(define (boolean-power/stream n) (apply cartesian-product/stream (make-list n '(#f #t)))) + +(module+ test + (test-case "boolean-power/stream" + (check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))))