functions: Add tbf-tabulate*/boolean.

This commit is contained in:
Sergiu Ivanov 2020-07-12 20:48:36 +02:00
parent b1d9b5193e
commit c7c50e7152

View file

@ -38,7 +38,8 @@
[read-tbfs (-> (listof (listof number?)) (listof tbf?))] [read-tbfs (-> (listof (listof number?)) (listof tbf?))]
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))] [read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
[tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))] [tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))]
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))])) [tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]
[tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))]))
(module+ test (module+ test
(require rackunit)) (require rackunit))
@ -348,3 +349,20 @@
(test-case "tbf-tabulate" (test-case "tbf-tabulate"
(check-equal? (tbf-tabulate (tbf #(1 2) 1)) (check-equal? (tbf-tabulate (tbf #(1 2) 1))
'((0 0 0) (0 1 1) (1 0 0) (1 1 1))))) '((0 0 0) (0 1 1) (1 0 0) (1 1 1)))))
;;; Tabulates a list of TBFs like tbf-boolean*, but uses Boolean
;;; values #f and #t instead of 0 and 1.
;;;
;;; All the TBFs in tbfs must have the same number of inputs as the
;;; first TBF in the list. This function does not check this
;;; condition.
(define (tbf-tabulate*/boolean tbfs)
(define funcs (for/list ([tbf tbfs])
(λ in (apply-tbf/boolean tbf (list->vector in)))))
(define nvars (vector-length (tbf-w (car tbfs))))
(tabulate* funcs (make-list nvars '(#f #t))))
(module+ test
(test-case "tbf-tabulate*/boolean"
(check-equal? (tbf-tabulate*/boolean `(,(tbf #(1 2) 1)))
'((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t)))))