networks: Remove n from boolean-power-n and boolean-power-n/stream.

This commit is contained in:
Sergiu Ivanov 2020-03-20 16:41:26 +01:00
parent e89163d044
commit 59d5b040f4
2 changed files with 9 additions and 9 deletions

View file

@ -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))

View file

@ -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))))))