Type enumerate-boolean-functions/list.

This commit is contained in:
Sergiu Ivanov 2022-04-19 23:31:28 +02:00
parent a201e537e1
commit 52bf1b2f58
2 changed files with 25 additions and 23 deletions

View File

@ -24,7 +24,7 @@
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv)
enumerate-boolean-functions/pv enumerate-boolean-functions/list)
(module+ test
(require typed/rackunit))
@ -300,6 +300,17 @@
(check-false (bool-f1/pv #t))
(check-exn exn:fail? (λ () (bool-f1/pv #f #f)))))
(: enumerate-boolean-functions/list
(-> Integer (Sequenceof (-> (Listof Boolean) Boolean))))
(define (enumerate-boolean-functions/list n)
(stream-map (inst table->function/list Boolean) (enumerate-boolean-tables n)))
(module+ test
(test-case "enumerate-boolean-functions/list"
(define bool-f1/list (stream-first (enumerate-boolean-functions/list 1)))
(check-false (bool-f1/list '(#f)))
(check-false (bool-f1/list '(#t)))))
(module untyped racket
(module+ test
(require rackunit))
@ -383,7 +394,7 @@
tabulate*/pv/01 tabulate/pv/01
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv)
enumerate-boolean-functions/pv enumerate-boolean-functions/list)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]
@ -395,7 +406,6 @@
[struct tbf ((weights (vectorof number?)) (threshold number?))])
;; Functions
(contract-out
[enumerate-boolean-functions/list (-> number? (stream/c procedure?))]
[random-boolean-table (-> number? (listof (*list/c boolean? boolean?)))]
[random-boolean-function (-> number? procedure?)]
[random-boolean-function/list (-> number? procedure?)]
@ -421,26 +431,6 @@
(require rackunit))
;;; ======================
;;; Constructing functions
;;; ======================
;;; Returns the stream of all Boolean functions of a given arity. As
;;; different from the functions returned by
;;; enumerate-boolean-functions, the functions take lists of arguments
;;; instead of n arguments.
;;;
;;; There are 2^(2^n) Boolean functions of arity n.
(define (enumerate-boolean-functions/list n)
(stream-map table->function/list (enumerate-boolean-tables n)))
(module+ test
(test-case "enumerate-boolean-functions/list"
(define f1/list (stream-first (enumerate-boolean-functions/list 1)))
(check-false (f1/list '(#f)))
(check-false (f1/list '(#t)))))
;;; ================
;;; Random functions
;;; ================

View File

@ -326,6 +326,18 @@ Like @racket[enumerate-boolean-functions], but the returned functions are
(eval:error (bool-f1/pv #f))
]}
@defproc[(enumerate-boolean-functions/list
[n Integer])
(Sequenceof (-> (Listof Boolean) Boolean))]{
Like @racket[enumerate-boolean-functions], but the returned functions take
their arguments as a single list.
@examples[#:eval functions-evaluator
(define bool-f1/list (stream-first (enumerate-boolean-functions/list 2)))
(bool-f1/list '(#f #f))
]}
@section{Random functions}
@section{Threshold Boolean functions}