Type apply-tbf/boolean.
This commit is contained in:
parent
1863b0829c
commit
cbede999df
2 changed files with 22 additions and 14 deletions
|
@ -27,7 +27,7 @@
|
|||
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
||||
random-boolean-table random-boolean-function random-boolean-function/list
|
||||
|
||||
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf)
|
||||
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean)
|
||||
|
||||
(module+ test
|
||||
(require typed/rackunit))
|
||||
|
@ -384,6 +384,16 @@
|
|||
(check-equal? (tabulate/pv/01 2 (pvλ (x y) (apply-tbf f1 (vector x y))))
|
||||
'((0 0 0) (0 1 0) (1 0 1) (1 1 0)))))
|
||||
|
||||
(: apply-tbf/boolean (-> tbf (Vectorof Boolean) Boolean))
|
||||
(define (apply-tbf/boolean tbf inputs)
|
||||
(01->boolean (apply-tbf tbf (boolean->01/vector inputs))))
|
||||
|
||||
(module+ test
|
||||
(test-case "apply-tbf/boolean"
|
||||
(define f1 (tbf #(2 -2) 1))
|
||||
(check-equal? (tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean f1 (vector x y))))
|
||||
'((#f #f #f) (#f #t #f) (#t #f #t) (#t #t #f)))))
|
||||
|
||||
(module untyped racket
|
||||
(module+ test
|
||||
(require rackunit))
|
||||
|
@ -470,7 +480,7 @@
|
|||
enumerate-boolean-functions/pv enumerate-boolean-functions/list
|
||||
random-boolean-table random-boolean-function random-boolean-function/list
|
||||
|
||||
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf)
|
||||
(struct-out tbf) tbf-w tbf-θ boolean->01/vector apply-tbf apply-tbf/boolean)
|
||||
|
||||
(require (rename-in (submod 'typed untyped)
|
||||
[tabulate tabulate/untyped]
|
||||
|
@ -479,7 +489,6 @@
|
|||
(provide
|
||||
;; Functions
|
||||
(contract-out
|
||||
[apply-tbf/boolean (-> tbf? (vectorof boolean?) boolean?)]
|
||||
[list->tbf (-> (cons/c number? (cons/c number? (listof number?))) tbf?)]
|
||||
[lists->tbfs (-> (listof (listof number?)) (listof tbf?))]
|
||||
[read-org-tbfs (->* (string?) (#:headers boolean?) (listof tbf?))]
|
||||
|
@ -501,17 +510,6 @@
|
|||
;;; Threshold Boolean functions
|
||||
;;; ===========================
|
||||
|
||||
;;; Like apply-tbf, but takes Boolean values as inputs and outputs a
|
||||
;;; boolean value.
|
||||
(define (apply-tbf/boolean tbf inputs)
|
||||
(01->boolean (apply-tbf tbf (vector-map any->01 inputs))))
|
||||
|
||||
(module+ test
|
||||
(test-case "apply-tbf/boolean"
|
||||
(define f1 (tbf #(2 -2) 1))
|
||||
(check-equal? (tabulate/boolean (λ (x y) (apply-tbf/boolean f1 (vector x y))))
|
||||
'((#f #f #f) (#f #t #f) (#t #f #t) (#t #t #f)))))
|
||||
|
||||
;;; Converts a list of numbers to a TBF. The last element of the list
|
||||
;;; is taken to be the threshold, while the other elements are taken
|
||||
;;; to be the weights.
|
||||
|
|
|
@ -405,6 +405,16 @@ above the threshold, the function is 1, otherwise it is 0.
|
|||
(tabulate/pv/01 2 (pvλ (x y) (apply-tbf simple-tbf (vector x y))))
|
||||
]}
|
||||
|
||||
@defproc[(apply-tbf/boolean [t tbf] [inputs (Vectorof Boolean)]) Boolean]{
|
||||
|
||||
Like @racket[apply-tbf], but takes Boolean values as inputs and outputs
|
||||
a Boolean value.
|
||||
|
||||
@examples[#:eval functions-evaluator
|
||||
(define simple-tbf (tbf #(2 -2) 1))
|
||||
(tabulate/pv/boolean 2 (pvλ (x y) (apply-tbf/boolean simple-tbf (vector x y))))
|
||||
]}
|
||||
|
||||
@section[#:tag "fuctions/untyped"]{Untyped definitions}
|
||||
|
||||
@defmodule[(submod dds/functions typed untyped)]
|
||||
|
|
Loading…
Reference in a new issue