Type sbf.

This commit is contained in:
Sergiu Ivanov 2022-04-25 00:31:00 +02:00
parent 6d37f180ba
commit 945dfe1490
2 changed files with 18 additions and 10 deletions

View file

@ -31,7 +31,7 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean (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 sbf?) tbf-tabulate*/boolean sbf? sbf)
(module+ test (module+ test
(require typed/rackunit)) (require typed/rackunit))
@ -548,6 +548,14 @@
(check-false (sbf? (tbf #(1 2) 3))) (check-false (sbf? (tbf #(1 2) 3)))
(check-true (sbf? (tbf #(1 2) 0))))) (check-true (sbf? (tbf #(1 2) 0)))))
(: sbf (-> (Vectorof Real) tbf))
(define (sbf w)
(tbf w 0))
(module+ test
(test-case "sbf"
(check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0))))
(module untyped racket (module untyped racket
(module+ test (module+ test
(require rackunit)) (require rackunit))
@ -638,7 +646,7 @@
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean (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 sbf?) tbf-tabulate*/boolean sbf? sbf)
(require (rename-in (submod 'typed untyped) (require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped] [tabulate tabulate/untyped]
@ -647,7 +655,6 @@
(provide (provide
;; Functions ;; Functions
(contract-out (contract-out
[sbf (-> (vectorof number?) tbf?)]
[list->sbf (-> (listof number?) sbf?)] [list->sbf (-> (listof number?) sbf?)]
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))])) [read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))]))
@ -659,13 +666,6 @@
;;; Threshold Boolean functions ;;; Threshold Boolean functions
;;; =========================== ;;; ===========================
;;; Creates a TBF which is an SBF from a vector of weights.
(define (sbf w) (tbf w 0))
(module+ test
(test-case "sbf"
(check-equal? (sbf #(1 -1)) (tbf '#(1 -1) 0))))
;;; Converts a list of numbers to an SBF. The elements of the list ;;; Converts a list of numbers to an SBF. The elements of the list
;;; are taken to be the weights of the SBF. ;;; are taken to be the weights of the SBF.
(define list->sbf (compose sbf list->vector)) (define list->sbf (compose sbf list->vector))

View file

@ -574,6 +574,14 @@ A sign Boolean function (SBF) is a TBF whose threshold is 0.
(sbf? (tbf #(1 2) 0)) (sbf? (tbf #(1 2) 0))
]} ]}
@defproc[(sbf [w (Vectorof Real)]) tbf]{
Creates a TBF which is an SBF from a vector of weights.
@ex[
(sbf #(1 -1))
]}
@section[#:tag "fuctions/untyped"]{Untyped definitions} @section[#:tag "fuctions/untyped"]{Untyped definitions}
@defmodule[(submod dds/functions typed untyped)] @defmodule[(submod dds/functions typed untyped)]