Add enumerate-boolean-functions/pv.
This commit is contained in:
parent
a4a6604ecd
commit
a201e537e1
2 changed files with 28 additions and 3 deletions
|
@ -23,7 +23,8 @@
|
||||||
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
|
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
|
||||||
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
|
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
|
||||||
table->function/list table->function table->function/pv
|
table->function/list table->function table->function/pv
|
||||||
enumerate-boolean-tables enumerate-boolean-functions)
|
enumerate-boolean-tables enumerate-boolean-functions
|
||||||
|
enumerate-boolean-functions/pv)
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require typed/rackunit))
|
(require typed/rackunit))
|
||||||
|
@ -288,6 +289,17 @@
|
||||||
(check-false (bool-f1 #f))
|
(check-false (bool-f1 #f))
|
||||||
(check-false (bool-f1 #t))))
|
(check-false (bool-f1 #t))))
|
||||||
|
|
||||||
|
(: enumerate-boolean-functions/pv (-> Integer (Sequenceof (-> Boolean * Boolean))))
|
||||||
|
(define (enumerate-boolean-functions/pv n)
|
||||||
|
(stream-map (inst table->function/pv Boolean) (enumerate-boolean-tables n)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "enumerate-boolean-functions/pv"
|
||||||
|
(define bool-f1/pv (stream-first (enumerate-boolean-functions/pv 1)))
|
||||||
|
(check-false (bool-f1/pv #f))
|
||||||
|
(check-false (bool-f1/pv #t))
|
||||||
|
(check-exn exn:fail? (λ () (bool-f1/pv #f #f)))))
|
||||||
|
|
||||||
(module untyped racket
|
(module untyped racket
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit))
|
(require rackunit))
|
||||||
|
@ -370,7 +382,8 @@
|
||||||
tabulate*/pv/boolean tabulate/pv/boolean
|
tabulate*/pv/boolean tabulate/pv/boolean
|
||||||
tabulate*/pv/01 tabulate/pv/01
|
tabulate*/pv/01 tabulate/pv/01
|
||||||
table->function/list table->function table->function/pv
|
table->function/list table->function table->function/pv
|
||||||
enumerate-boolean-tables enumerate-boolean-functions)
|
enumerate-boolean-tables enumerate-boolean-functions
|
||||||
|
enumerate-boolean-functions/pv)
|
||||||
|
|
||||||
(require (rename-in (submod 'typed untyped)
|
(require (rename-in (submod 'typed untyped)
|
||||||
[tabulate tabulate/untyped]
|
[tabulate tabulate/untyped]
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
@(require scribble/example racket/sandbox
|
@(require scribble/example racket/sandbox
|
||||||
(for-label typed/racket/base "../functions.rkt" dds/utils
|
(for-label typed/racket/base "../functions.rkt" dds/utils
|
||||||
typed/racket/unsafe
|
typed/racket/unsafe
|
||||||
(only-in racket stream->list)))
|
(only-in racket stream->list stream-first)))
|
||||||
|
|
||||||
@title[#:tag "functions"]{dds/functions: Formal Functions}
|
@title[#:tag "functions"]{dds/functions: Formal Functions}
|
||||||
|
|
||||||
|
@ -314,6 +314,18 @@ There are @tt{2^(2^n)} Boolean functions of arity @racket[n].
|
||||||
(length (stream->list (enumerate-boolean-functions 2)))
|
(length (stream->list (enumerate-boolean-functions 2)))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
@defproc[(enumerate-boolean-functions/pv [n Integer])
|
||||||
|
(Sequenceof (-> Boolean * Boolean))]{
|
||||||
|
|
||||||
|
Like @racket[enumerate-boolean-functions], but the returned functions are
|
||||||
|
@seclink["pseudovariadic"]{pseudovariadic}.
|
||||||
|
|
||||||
|
@examples[#:eval functions-evaluator
|
||||||
|
(define bool-f1/pv (stream-first (enumerate-boolean-functions/pv 2)))
|
||||||
|
(bool-f1/pv #f #f)
|
||||||
|
(eval:error (bool-f1/pv #f))
|
||||||
|
]}
|
||||||
|
|
||||||
@section{Random functions}
|
@section{Random functions}
|
||||||
|
|
||||||
@section{Threshold Boolean functions}
|
@section{Threshold Boolean functions}
|
||||||
|
|
Loading…
Reference in a new issue