Type boolean-power/stream.
This commit is contained in:
parent
347e17158d
commit
83b293e3e4
2 changed files with 20 additions and 13 deletions
|
@ -477,4 +477,13 @@ Returns the @racket[n]-th Cartesian power of the Boolean domain.
|
|||
|
||||
@examples[#:eval utils-evaluator
|
||||
(boolean-power 2)
|
||||
]}
|
||||
]}
|
||||
|
||||
@defproc[(boolean-power/stream [n Integer])
|
||||
(Sequenceof (Listof Boolean))]{
|
||||
|
||||
Like @racket[boolean-power], but returns a stream.
|
||||
|
||||
@examples[#:eval utils-evaluator
|
||||
(stream->list (boolean-power/stream 2))
|
||||
]}
|
||||
|
|
22
utils.rkt
22
utils.rkt
|
@ -25,7 +25,7 @@
|
|||
update-vertices/unweighted update-graph dotit collect-by-key
|
||||
collect-by-key/sets ht-values/list->set hash->list/ordered
|
||||
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
||||
cartesian-product/stream boolean-power)
|
||||
cartesian-product/stream boolean-power boolean-power/stream)
|
||||
|
||||
(define-type Variable Symbol)
|
||||
(define-type (VariableMapping A) (Immutable-HashTable Variable A))
|
||||
|
@ -534,6 +534,13 @@
|
|||
(module+ test
|
||||
(test-case "boolean-power"
|
||||
(check-equal? (boolean-power 2) '((#f #f) (#f #t) (#t #f) (#t #t)))))
|
||||
|
||||
(: boolean-power/stream (-> Integer (Sequenceof (Listof Boolean))))
|
||||
(define (boolean-power/stream n) (cartesian-product/stream (make-list n '(#f #t))))
|
||||
|
||||
(module+ test
|
||||
(test-case "boolean-power/stream"
|
||||
(check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))))
|
||||
)
|
||||
|
||||
(require 'typed)
|
||||
|
@ -545,14 +552,13 @@
|
|||
update-vertices/unweighted update-graph dotit collect-by-key
|
||||
collect-by-key/sets ht-values/list->set hash->list/ordered
|
||||
multi-split-at lists-transpose in-random cartesian-product-2/stream
|
||||
cartesian-product/stream boolean-power)
|
||||
cartesian-product/stream boolean-power boolean-power/stream)
|
||||
|
||||
;;; Untyped section.
|
||||
|
||||
(provide
|
||||
;; Functions
|
||||
(contract-out [boolean-power/stream (-> number? (stream/c (listof boolean?)))]
|
||||
[any->01 (-> any/c (or/c 0 1))]
|
||||
(contract-out [any->01 (-> any/c (or/c 0 1))]
|
||||
[01->boolean (-> (or/c 0 1) boolean?)])
|
||||
;; Contracts
|
||||
(contract-out [variable-mapping? contract?]
|
||||
|
@ -578,14 +584,6 @@
|
|||
;;; Boolean operations
|
||||
;;; ==================
|
||||
|
||||
;;; Like boolean-power, but returns a stream whose elements the
|
||||
;;; elements of the Cartesian power.
|
||||
(define (boolean-power/stream n) (cartesian-product/stream (make-list n '(#f #t))))
|
||||
|
||||
(module+ test
|
||||
(test-case "boolean-power/stream"
|
||||
(check-equal? (stream->list (boolean-power/stream 2)) '((#f #f) (#f #t) (#t #f) (#t #t)))))
|
||||
|
||||
;;; Converts any non-#f value to 1 and #f to 0.
|
||||
(define (any->01 x) (if x 1 0))
|
||||
|
||||
|
|
Loading…
Reference in a new issue