From b8b9fee9ceaf7ec0cd1b40f7908734cca89a3200 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 29 Mar 2023 17:46:53 +0200 Subject: [PATCH] Type sbf/state?. --- scribblings/tbn.scrbl | 10 ++++++++++ tbn.rkt | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/scribblings/tbn.scrbl b/scribblings/tbn.scrbl index 044e0da..88780be 100644 --- a/scribblings/tbn.scrbl +++ b/scribblings/tbn.scrbl @@ -81,3 +81,13 @@ and weights, as well as a threshold. @ex[ (make-tbf/state '((x1 . 1) (x2 . 1)) 1) ]} + +@defproc[(sbf/state? [tbfs TBF/State]) Boolean]{ + +A state sign Boolean function (SBF) is a @racket[TBF/State] whose +threshold is 0. + +@ex[ +(sbf/state? (tbf/state (hash 'a -1 'b 1) 0)) +(sbf/state? (tbf/state (hash 'a -1 'b 1) 1)) +]} diff --git a/tbn.rkt b/tbn.rkt index 116f805..4973b12 100644 --- a/tbn.rkt +++ b/tbn.rkt @@ -16,6 +16,7 @@ apply-tbf-to-state (struct-out tbf/state) TBF/State tbf/state-w tbf/state-θ make-tbf/state + sbf/state? ) (: apply-tbf-to-state (-> TBF (State (U Zero One)) (U Zero One))) @@ -45,6 +46,14 @@ (define f (make-tbf/state '((x1 . 1) (x2 . 1)) 1)) (check-equal? (tbf/state-w f) #hash((x1 . 1) (x2 . 1))) (check-equal? (tbf/state-θ f) 1))) + + (: sbf/state? (-> TBF/State Boolean)) + (define (sbf/state? tbfs) (zero? (tbf/state-θ tbfs))) + + (module+ test + (test-case "sbf/state?" + (check-true (sbf/state? (tbf/state (hash 'a -1 'b 1) 0))) + (check-false (sbf/state? (tbf/state (hash 'a -1 'b 1) 1))))) ) (module+ test