From 43d782f1496d10936a9b262a6d517ddf8f6798b0 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 3 Apr 2023 16:36:08 +0200 Subject: [PATCH] Add lists->tbfs/state. --- scribblings/tbn.scrbl | 11 +++++++++++ tbn.rkt | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index c69eedb..5732a09 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -144,3 +144,14 @@ line (the threshold column) is discarded. @ex[ (lists+headers->tbfs/state '((x y f) (1 2 3) (1 1 2))) ]} + +@defproc[(lists->tbfs/state [lsts (Listof (Liostf Real))]) + (Listof TBF/State)]{ + +Like @racket[lists+vars->tbfs/state], but the names of the variables +are generated as @tt{xi}, where @italic{i} is the index of the +variable, starting from 0. + +@ex[ +(lists->tbfs/state '((1 2 3) (1 1 2))) +]} diff --git a/tbn.rkt b/tbn.rkt index c61d40a..1e3236f 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -25,7 +25,7 @@ (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state sbf/state? apply-tbf/state - lists+vars->tbfs/state lists+headers->tbfs/state + lists+vars->tbfs/state lists+headers->tbfs/state lists->tbfs/state ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -105,6 +105,19 @@ (check-equal? (lists+headers->tbfs/state '((x y f) (1 2 3) (1 1 2))) (list (tbf/state '#hash((x . 1) (y . 2)) 3) (tbf/state '#hash((x . 1) (y . 1)) 2))))) + + (: lists->tbfs/state (-> (Listof (Listof Real)) (Listof TBF/State))) + (define (lists->tbfs/state lsts) + (lists+vars->tbfs/state + (for/list ([i (in-range (length (car lsts)))]) + (string->symbol (format "x~a" i))) + lsts)) + + (module+ test + (test-case "lists->tbfs/state" + (check-equal? (lists->tbfs/state '((1 2 3) (1 1 2))) + (list (tbf/state '#hash((x0 . 1) (x1 . 2)) 3) + (tbf/state '#hash((x0 . 1) (x1 . 1)) 2))))) ) (module+ test