From b9eb692091e04a2151bb8c483fafd8194c313a58 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Tue, 25 Apr 2023 23:52:57 +0200 Subject: [PATCH] Add tabulate-tbf/state and tabulate-tbf/state+headers. --- scribblings/tbn.scrbl | 13 +++++++++++++ tbn.rkt | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index cfeaf79..1e575d6 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -263,3 +263,16 @@ the list. (list (tbf/state (hash 'a 1 'b 2) 2) (tbf/state (hash 'a -2 'b 2) 1))) ]} + +@deftogether[(@defproc[(tabulate-tbf/state [tbf TBF/State]) + (Listof (Listof Real))] + @defproc[(tabulate-tbf/state+headers [tbf TBF/State]) + (Pairof (Listof Variable) (Listof (Listof Real)))])]{ + +Like @racket[tabulate-tbfs/state] and +@racket[tabulate-tbfs/state+headers], but only tabulate single TBFs. + +@ex[ +(tabulate-tbf/state (tbf/state (hash 'a 1 'b 2) 2)) +(tabulate-tbf/state+headers (tbf/state (hash 'a 1 'b 2) 2)) +]} diff --git a/tbn.rkt b/tbn.rkt index 026c6a8..f8a782f 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -31,6 +31,7 @@ tbfs/state->lists tbfs/state->lists+headers tabulate-tbfs/state tabulate-tbfs/state+headers + tabulate-tbf/state tabulate-tbf/state+headers ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -262,6 +263,32 @@ (0 1 0 1) (1 0 0 0) (1 1 1 0))))) + + (: tabulate-tbf/state (-> TBF/State (Listof (Listof Real)))) + (define (tabulate-tbf/state tbf) + (tabulate-tbfs/state (list tbf))) + + (module+ test + (test-case "tabulate-tbf/state" + (check-equal? (tabulate-tbf/state (tbf/state (hash 'a 1 'b 2) 2)) + '((0 0 0) + (0 1 0) + (1 0 0) + (1 1 1))))) + + (: tabulate-tbf/state+headers (-> TBF/State (Pairof (Listof Variable) + (Listof (Listof Real))))) + (define (tabulate-tbf/state+headers tbf) + (tabulate-tbfs/state+headers (list tbf))) + + (module+ test + (test-case "tabulate-tbf/state+headers" + (check-equal? (tabulate-tbf/state+headers (tbf/state (hash 'a 1 'b 2) 2)) + '((a b f1) + (0 0 0) + (0 1 0) + (1 0 0) + (1 1 1))))) ) (module+ test