From e237e9e019e1c8610513c655f7df091015cf1a90 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Wed, 3 Jun 2020 22:51:06 +0200 Subject: [PATCH] functions: Add tbf. --- functions.rkt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/functions.rkt b/functions.rkt index 45d155b..b45b02e 100644 --- a/functions.rkt +++ b/functions.rkt @@ -10,6 +10,9 @@ (require "utils.rkt") (provide + ;; Structures + (contract-out + [struct tbf ((weights number?) (threshold (vectorof number?)))]) ;; Functions (contract-out [tabulate (-> procedure? (listof generic-set?) (listof list?))] @@ -23,7 +26,9 @@ [enumerate-boolean-functions/list (-> number? (stream/c procedure?))] [random-boolean-table (-> number? (listof (*list/c boolean? boolean?)))] [random-boolean-function (-> number? procedure?)] - [random-boolean-function/list (-> number? procedure?)])) + [random-boolean-function/list (-> number? procedure?)] + [tbf-w (-> tbf? (vectorof number?))] + [tbf-θ (-> tbf? number?)])) (module+ test (require rackunit)) @@ -197,3 +202,16 @@ (define f (random-boolean-function/list 2)) (check-false (f '(#f #f))) (check-true (f '(#f #t))) (check-true (f '(#t #f))) (check-false (f '(#t #t))))) + + +;;; =========================== +;;; Threshold Boolean functions +;;; =========================== + +;;; A threshold Boolean function (TBF) is a pair (w, θ), where w is a +;;; vector of weights and θ is the threshold. +(struct tbf (weights threshold) #:transparent) + +;;; Unicode shortcuts for accessing the elements of a TBF. +(define tbf-w tbf-weights) +(define tbf-θ tbf-threshold)