Type sbf?.

This commit is contained in:
Sergiu Ivanov 2022-04-25 00:24:32 +02:00
parent 297d455207
commit 6d37f180ba
2 changed files with 21 additions and 14 deletions

View file

@ -31,7 +31,7 @@
(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
tbf-tabulate*/boolean)
tbf-tabulate*/boolean sbf?)
(module+ test
(require typed/rackunit))
@ -539,6 +539,15 @@
(check-equal? (tbf-tabulate*/boolean (list (tbf #(1 2) 1)))
'((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t)))))
(: sbf? (-> tbf Boolean))
(define (sbf? t)
(= 0 (tbf-θ t)))
(module+ test
(test-case "sbf?"
(check-false (sbf? (tbf #(1 2) 3)))
(check-true (sbf? (tbf #(1 2) 0)))))
(module untyped racket
(module+ test
(require rackunit))
@ -629,7 +638,7 @@
(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
tbf-tabulate*/boolean)
tbf-tabulate*/boolean sbf?)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
@ -640,10 +649,7 @@
(contract-out
[sbf (-> (vectorof number?) tbf?)]
[list->sbf (-> (listof number?) sbf?)]
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))])
;; Predicates
(contract-out
[sbf? (-> any/c boolean?)]))
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))]))
(module+ test
(require rackunit))
@ -653,14 +659,6 @@
;;; Threshold Boolean functions
;;; ===========================
;;; A sign Boolean function (SBF) is a TBF whose threshold is 0.
(define sbf? (and/c tbf? (λ (x) (= 0 (tbf-θ x)))))
(module+ test
(test-case "sbf?"
(check-false (sbf? (tbf #(1 2) 3)))
(check-true (sbf? (tbf #(1 2) 0)))))
;;; Creates a TBF which is an SBF from a vector of weights.
(define (sbf w) (tbf w 0))

View file

@ -565,6 +565,15 @@ TBF in the list.
(tbf-tabulate*/boolean (list (tbf #(1 2) 1)))
]}
@defproc[(sbf? [t tbf]) Boolean]{
A sign Boolean function (SBF) is a TBF whose threshold is 0.
@ex[
(sbf? (tbf #(1 2) 3))
(sbf? (tbf #(1 2) 0))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)]