From b1cc242c7bcf469d8dcd516544dc37dd4f45c207 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 19 Sep 2022 00:10:42 +0200 Subject: [PATCH] Type pretty-print-boolean-state. --- networks.rkt | 11 +++++++++++ scribblings/networks.scrbl | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/networks.rkt b/networks.rkt index 5f672bf..f679f1e 100644 --- a/networks.rkt +++ b/networks.rkt @@ -35,6 +35,7 @@ Modality Mode dynamics% Dynamics% make-syn make-asyn make-asyn-dynamics make-syn-dynamics pretty-print-state + pretty-print-boolean-state ) (define-type (State a) (VariableMapping a)) @@ -664,6 +665,16 @@ (test-case "pretty-print-state" (check-equal? (pretty-print-state (hash 'a #f 'b 3 'c 4)) "a:#f b:3 c:4"))) + + (: pretty-print-boolean-state (All (a) (-> (State a) String))) + (define (pretty-print-boolean-state s) + (string-join (hash-map s (λ (key val) (format "~a:~a" key (any->01 val))) #t))) + + (module+ test + (test-case "pretty-print-boolean-state" + (check-equal? + (pretty-print-boolean-state (hash 'a #f 'b #t 'c #t)) + "a:0 b:1 c:1"))) ) (require 'typed) diff --git a/scribblings/networks.scrbl b/scribblings/networks.scrbl index 31dc50a..8ff3883 100644 --- a/scribblings/networks.scrbl +++ b/scribblings/networks.scrbl @@ -476,6 +476,15 @@ Pretty-prints a state of a network. } +@defproc[(pretty-print-boolean-state [s (State a)]) String]{ + +Pretty-prints a state of a network, replacing all @racket[#f] values with 0 and +all other values with 1. + +@ex[(pretty-print-boolean-state (hash 'a #f 'b 3 'c '() 'd #t))] + +} + @section{Inferring interaction graphs} This section provides inference of both unsigned and signed interaction graphs.