functions: Add sbf?.

This commit is contained in:
Sergiu Ivanov 2020-07-12 23:50:51 +02:00
parent c7c50e7152
commit e5d07b2f13

View file

@ -39,7 +39,10 @@
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))] [read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
[tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))] [tbf-tabulate* (-> (listof tbf?) (listof (listof (or/c 0 1))))]
[tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))] [tbf-tabulate (-> tbf? (listof (listof (or/c 0 1))))]
[tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))])) [tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))])
;; Predicates
(contract-out
[sbf? (-> any/c boolean?)]))
(module+ test (module+ test
(require rackunit)) (require rackunit))
@ -366,3 +369,10 @@
(test-case "tbf-tabulate*/boolean" (test-case "tbf-tabulate*/boolean"
(check-equal? (tbf-tabulate*/boolean `(,(tbf #(1 2) 1))) (check-equal? (tbf-tabulate*/boolean `(,(tbf #(1 2) 1)))
'((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t))))) '((#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)))))
(module+ test
(check-false (sbf? (tbf #(1 2) 3)))
(check-true (sbf? (tbf #(1 2) 0))))