Type tbf-tabulate*/boolean.
This commit is contained in:
parent
9db0fcbdb4
commit
297d455207
2 changed files with 31 additions and 20 deletions
|
@ -30,7 +30,8 @@
|
|||
random-boolean-table random-boolean-function random-boolean-function/list
|
||||
|
||||
(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)
|
||||
|
||||
(module+ test
|
||||
(require typed/rackunit))
|
||||
|
@ -524,6 +525,20 @@
|
|||
(check-equal? (tbf-tabulate (tbf #(1 2) 1))
|
||||
'((0 0 0) (0 1 1) (1 0 0) (1 1 1)))))
|
||||
|
||||
(: tbf-tabulate*/boolean (-> (Listof tbf) (Listof (Listof Boolean))))
|
||||
(define (tbf-tabulate*/boolean tbfs)
|
||||
(define funcs (for/list ([tbf tbfs])
|
||||
: (Listof (-> (Listof Boolean) Boolean))
|
||||
(λ ([in : (Listof Boolean)])
|
||||
(apply-tbf/boolean tbf (list->vector in)))))
|
||||
(define nvars (vector-length (tbf-w (car tbfs))))
|
||||
(tabulate*/list funcs (make-list nvars '(#f #t))))
|
||||
|
||||
(module+ test
|
||||
(test-case "tbf-tabulate*/boolean"
|
||||
(check-equal? (tbf-tabulate*/boolean (list (tbf #(1 2) 1)))
|
||||
'((#f #f #f) (#f #t #t) (#t #f #f) (#t #t #t)))))
|
||||
|
||||
(module untyped racket
|
||||
(module+ test
|
||||
(require rackunit))
|
||||
|
@ -613,7 +628,8 @@
|
|||
random-boolean-table random-boolean-function random-boolean-function/list
|
||||
|
||||
(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)
|
||||
|
||||
(require (rename-in (submod 'typed untyped)
|
||||
[tabulate tabulate/untyped]
|
||||
|
@ -622,7 +638,6 @@
|
|||
(provide
|
||||
;; Functions
|
||||
(contract-out
|
||||
[tbf-tabulate*/boolean (-> (listof tbf?) (listof (listof boolean?)))]
|
||||
[sbf (-> (vectorof number?) tbf?)]
|
||||
[list->sbf (-> (listof number?) sbf?)]
|
||||
[read-org-sbfs (->* (string?) (#:headers boolean?) (listof sbf?))])
|
||||
|
@ -638,23 +653,6 @@
|
|||
;;; Threshold Boolean functions
|
||||
;;; ===========================
|
||||
|
||||
;;; Tabulates a list of TBFs like tbf-boolean*, but uses Boolean
|
||||
;;; values #f and #t instead of 0 and 1.
|
||||
;;;
|
||||
;;; All the TBFs in tbfs must have the same number of inputs as the
|
||||
;;; first TBF in the list. This function does not check this
|
||||
;;; condition.
|
||||
(define (tbf-tabulate*/boolean tbfs)
|
||||
(define funcs (for/list ([tbf tbfs])
|
||||
(λ in (apply-tbf/boolean tbf (list->vector in)))))
|
||||
(define nvars (vector-length (tbf-w (car tbfs))))
|
||||
(tabulate*/untyped funcs (make-list nvars '(#f #t))))
|
||||
|
||||
(module+ test
|
||||
(test-case "tbf-tabulate*/boolean"
|
||||
(check-equal? (tbf-tabulate*/boolean `(,(tbf #(1 2) 1)))
|
||||
'((#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)))))
|
||||
|
||||
|
|
|
@ -552,6 +552,19 @@ Tabulates a single TBF.
|
|||
(tbf-tabulate (tbf #(1 2) 1))
|
||||
]}
|
||||
|
||||
@defproc[(tbf-tabulate*/boolean [tbfs (Listof tbf)])
|
||||
(Listof (Listof Boolean))]{
|
||||
|
||||
Tabulates a list of TBFs like @racket[tbf-tabulate*], but uses Boolean values
|
||||
@racket[#f] and @racket[#t] instead of 0 and 1.
|
||||
|
||||
All the TBFs in @racket[tbfs] must have the same number of inputs as the first
|
||||
TBF in the list.
|
||||
|
||||
@ex[
|
||||
(tbf-tabulate*/boolean (list (tbf #(1 2) 1)))
|
||||
]}
|
||||
|
||||
@section[#:tag "fuctions/untyped"]{Untyped definitions}
|
||||
|
||||
@defmodule[(submod dds/functions typed untyped)]
|
||||
|
|
Loading…
Reference in a new issue