From 848d53f97a7bfc5fc7d35023711f3623a6118c34 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 12 Oct 2020 00:53:56 +0200 Subject: [PATCH] networks: Add tbf/state-tabulate. --- networks.rkt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/networks.rkt b/networks.rkt index fa1025e..fde16b8 100644 --- a/networks.rkt +++ b/networks.rkt @@ -91,7 +91,9 @@ [print-org-tbfs/state (->* ((non-empty-listof tbf/state?)) (#:headers boolean?) (listof (listof (or/c number? symbol?))))] [tbf/state-tabulate* (->* ((non-empty-listof tbf/state?)) (#:headers boolean?) - (listof (listof (or/c symbol? number?))))]) + (listof (listof (or/c symbol? number?))))] + [tbf/state-tabulate (->* (tbf/state?) (#:headers boolean?) + (listof (listof (or/c symbol? number?))))]) ;; Predicates (contract-out [variable? (-> any/c boolean?)] [state? (-> any/c boolean?)] @@ -1117,5 +1119,19 @@ (1 0 0 0) (1 1 1 0))))) +;;; Like tbf/state-tabulate*, but only tabulates a single TBF. +(define (tbf/state-tabulate tbf #:headers [headers #t]) + (tbf/state-tabulate* (list tbf) #:headers headers)) + +(module+ test + (test-case "tbf/state-tabulate" + (define tbf (make-tbf/state '((a . -2) (b . 3)) 1)) + (check-equal? (tbf/state-tabulate tbf) + '((a b f1) + (0 0 0) + (0 1 1) + (1 0 0) + (1 1 0))))) + ;;; A TBN is a network form mapping TBFs to variables. (define tbn? (hash/c variable? tbf?))