Add sbfs/state->lists+headers.

This commit is contained in:
Sergiu Ivanov 2023-05-25 15:19:25 +02:00
parent 76c6bb5745
commit cd8cada92e
2 changed files with 29 additions and 1 deletions

View file

@ -245,6 +245,17 @@ whether it is actually 0:
(sbfs/state->lists (list (tbf/state (hash 'a 1 'b 2) 3)))
]}
@defproc[(sbfs/state->lists+headers [sbfs (Listof TBF/State)])
(Pairof (Listof Variable) (Listof (Listof Real)))]{
Like @racket[sbfs/state->lists], but also shows the names of the
variables as column headers.
@ex[
(sbfs/state->lists+headers (list (tbf/state (hash 'a 1 'b 2) 0)
(tbf/state (hash 'a -2 'b 1) 0)))
]}
@section{Tabulating TBFs and SBFs}
@defproc[(tabulate-tbfs/state [tbfs (Listof TBF/State)]) (Listof (Listof Real))]{

19
tbn.rkt
View file

@ -29,7 +29,7 @@
lists+vars->sbfs/state lists+headers->sbfs/state lists->sbfs/state
read-org-tbfs/state read-org-tbfs/state+headers
tbfs/state->lists tbfs/state->lists+headers
sbfs/state->lists
sbfs/state->lists sbfs/state->lists+headers
tabulate-tbfs/state tabulate-tbfs/state+headers
tabulate-tbf/state tabulate-tbf/state+headers
@ -234,6 +234,23 @@
(tbf/state (hash 'a -2 'b 1) 0)))
'((1 2) (-2 1)))))
(: sbfs/state->lists+headers (-> (Listof TBF/State)
(Pairof (Listof Variable)
(Listof (Listof Real)))))
(define (sbfs/state->lists+headers tbfs)
(cons (hash-map (tbf/state-w (car tbfs))
(λ ([x : Symbol] _) x) #t)
(sbfs/state->lists tbfs)))
(module+ test
(test-case "sbfs/state->list+headers"
(check-equal?
(sbfs/state->lists+headers (list (tbf/state (hash 'a 1 'b 2) 0)
(tbf/state (hash 'a -2 'b 1) 0)))
'((a b)
(1 2)
(-2 1)))))
(: tabulate-tbfs/state (-> (Listof TBF/State) (Listof (Listof Real))))
(define (tabulate-tbfs/state tbfs)
(define vars (hash-map (tbf/state-w (car tbfs)) (λ ([x : Variable] _) x) #t))