functions: Add tbf-tabulate.

This commit is contained in:
Sergiu Ivanov 2020-07-11 00:46:58 +02:00
parent 7d825d0a83
commit 47532e3905

View File

@ -36,7 +36,8 @@
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) 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 (-> tbf? (listof (listof (or/c 0 1))))]))
(module+ test
(require rackunit))
@ -317,3 +318,16 @@
(test-case "read-org-tbfs"
(check-equal? (read-org-tbfs "((1 2 1) (1 0 1))")
(list (tbf '#(1 2) 1) (tbf '#(1 0) 1)))))
;;; Tabulates a TBF.
(define (tbf-tabulate tbf)
(define ins (apply
cartesian-product
(make-list (vector-length (tbf-w tbf)) '(0 1))))
(for/list ([in ins])
(append in (list (apply-tbf tbf (list->vector in))))))
(module+ test
(test-case "tbf-tabulate"
(check-equal? (tbf-tabulate (tbf #(1 2) 1))
'((0 0 0) (0 1 1) (1 0 0) (1 1 1)))))