From 297d4552077b09879b721227983bdd0147ae7fcd Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Mon, 25 Apr 2022 00:17:03 +0200 Subject: [PATCH] Type tbf-tabulate*/boolean. --- functions.rkt | 38 ++++++++++++++++++------------------- scribblings/functions.scrbl | 13 +++++++++++++ 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/functions.rkt b/functions.rkt index b38d1d6..3a1b5d2 100644 --- a/functions.rkt +++ b/functions.rkt @@ -30,7 +30,8 @@ random-boolean-table random-boolean-function random-boolean-function/list (struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean - list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate) + list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate + tbf-tabulate*/boolean) (module+ test (require typed/rackunit)) @@ -524,6 +525,20 @@ (check-equal? (tbf-tabulate (tbf #(1 2) 1)) '((0 0 0) (0 1 1) (1 0 0) (1 1 1))))) + (: tbf-tabulate*/boolean (-> (Listof tbf) (Listof (Listof Boolean)))) + (define (tbf-tabulate*/boolean tbfs) + (define funcs (for/list ([tbf tbfs]) + : (Listof (-> (Listof Boolean) Boolean)) + (λ ([in : (Listof Boolean)]) + (apply-tbf/boolean tbf (list->vector in))))) + (define nvars (vector-length (tbf-w (car tbfs)))) + (tabulate*/list funcs (make-list nvars '(#f #t)))) + + (module+ test + (test-case "tbf-tabulate*/boolean" + (check-equal? (tbf-tabulate*/boolean (list (tbf #(1 2) 1))) + '((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t))))) + (module untyped racket (module+ test (require rackunit)) @@ -613,7 +628,8 @@ random-boolean-table random-boolean-function random-boolean-function/list (struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean - list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate) + list->tbf lists->tbfs read-org-tbfs tbf-tabulate* tbf-tabulate + tbf-tabulate*/boolean) (require (rename-in (submod 'typed untyped) [tabulate tabulate/untyped] @@ -622,7 +638,6 @@ (provide ;; Functions (contract-out - [tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))] [sbf (-> (vectorof number?) tbf?)] [list->sbf (-> (listof number?) sbf?)] [read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))]) @@ -638,23 +653,6 @@ ;;; Threshold Boolean functions ;;; =========================== -;;; Tabulates a list of TBFs like tbf-boolean*, but uses Boolean -;;; values #f and #t instead of 0 and 1. -;;; -;;; All the TBFs in tbfs must have the same number of inputs as the -;;; first TBF in the list. This function does not check this -;;; condition. -(define (tbf-tabulate*/boolean tbfs) - (define funcs (for/list ([tbf tbfs]) - (λ in (apply-tbf/boolean tbf (list->vector in))))) - (define nvars (vector-length (tbf-w (car tbfs)))) - (tabulate*/untyped funcs (make-list nvars '(#f #t)))) - -(module+ test - (test-case "tbf-tabulate*/boolean" - (check-equal? (tbf-tabulate*/boolean `(,(tbf #(1 2) 1))) - '((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t))))) - ;;; A sign Boolean function (SBF) is a TBF whose threshold is 0. (define sbf? (and/c tbf? (λ (x) (= 0 (tbf-θ x))))) diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index 790d5f2..a12d149 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -552,6 +552,19 @@ Tabulates a single TBF. (tbf-tabulate (tbf #(1 2) 1)) ]} +@defproc[(tbf-tabulate*/boolean [tbfs (Listof tbf)]) + (Listof (Listof Boolean))]{ + +Tabulates a list of TBFs like @racket[tbf-tabulate*], but uses Boolean values +@racket[#f] and @racket[#t] instead of 0 and 1. + +All the TBFs in @racket[tbfs] must have the same number of inputs as the first +TBF in the list. + +@ex[ +(tbf-tabulate*/boolean (list (tbf #(1 2) 1))) +]} + @section[#:tag "fuctions/untyped"]{Untyped definitions} @defmodule[(submod dds/functions typed untyped)]