From 59d5b040f418035ebdeab155ce2cd7e04c28fed5 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Fri, 20 Mar 2020 16:41:26 +0100 Subject: [PATCH] networks: Remove n from boolean-power-n and boolean-power-n/stream. --- networks-tests.rkt | 4 ++-- networks.rkt | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/networks-tests.rkt b/networks-tests.rkt index 62e0202..1bc11b0 100644 --- a/networks-tests.rkt +++ b/networks-tests.rkt @@ -215,8 +215,8 @@ '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))) (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))) + (check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t))) + (check-equal? (stream->list (boolean-power/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 32770f8..4692f74 100644 --- a/networks.rkt +++ b/networks.rkt @@ -61,8 +61,8 @@ [tabulate/boolean (-> procedure-fixed-arity? (listof (listof boolean?)))] [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?)))] + [boolean-power (-> number? (listof (listof boolean?)))] + [boolean-power/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?))]) @@ -442,19 +442,19 @@ (values x (car fx)))))) ;;; 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)))) +(define (boolean-power n) (apply cartesian-product (make-list n '(#f #t)))) -;;; Like boolean-power-n, but returns a stream whose elements the +;;; Like boolean-power, 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)))) +(define (boolean-power/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. ;;; ;;; There are 2^(2^n) Boolean functions of arity n. (define (enumerate-boolean-tables n) - (let ([inputs (boolean-power-n n)] - [outputs (boolean-power-n (expt 2 n))]) + (let ([inputs (boolean-power n)] + [outputs (boolean-power (expt 2 n))]) (for/stream ([out outputs]) (for/list ([in inputs] [o out]) (append in (list o))))))