functions: Integer → Positive-Integer for arities.

This commit is contained in:
Sergiu Ivanov 2022-04-21 11:09:52 +02:00
parent 242ea9d31d
commit 9ad3a69c27
2 changed files with 20 additions and 20 deletions

View File

@ -155,7 +155,7 @@
(check-equal? (tabulate/pv (pvλ (x y) (and x y)) '((#f #t) (#f #t)))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
(: tabulate/pv/boolean (-> Integer (-> Boolean * Boolean) (Listof (Listof Boolean))))
(: tabulate/pv/boolean (-> Positive-Integer (-> Boolean * Boolean) (Listof (Listof Boolean))))
(define (tabulate/pv/boolean arity func)
(tabulate/pv func (make-list arity '(#f #t))))
@ -164,7 +164,7 @@
(check-equal? (tabulate/pv/boolean 2 (pvλ (x y) (and x y)))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
(: tabulate*/pv/boolean (-> Integer (Listof (-> Boolean * Boolean))
(: tabulate*/pv/boolean (-> Positive-Integer (Listof (-> Boolean * Boolean))
(Listof (Listof Boolean))))
(define (tabulate*/pv/boolean arity funcs)
(tabulate*/pv funcs (make-list arity '(#f #t))))
@ -175,7 +175,7 @@
(pvλ (x y) (or x y))))
'((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t)))))
(: tabulate/pv/01 (-> Integer (-> (U Zero One) * (U Zero One))
(: tabulate/pv/01 (-> Positive-Integer (-> (U Zero One) * (U Zero One))
(Listof (Listof (U Zero One)))))
(define (tabulate/pv/01 arity func)
(tabulate/pv func (make-list arity '(0 1))))
@ -186,7 +186,7 @@
(cast (modulo (+ x y) 2) (U Zero One))))
'((0 0 0) (0 1 1) (1 0 1) (1 1 0)))))
(: tabulate*/pv/01 (-> Integer (Listof (-> (U Zero One) * (U Zero One)))
(: tabulate*/pv/01 (-> Positive-Integer (Listof (-> (U Zero One) * (U Zero One)))
(Listof (Listof (U Zero One)))))
(define (tabulate*/pv/01 arity funcs)
(tabulate*/pv funcs (make-list arity '(0 1))))
@ -241,7 +241,7 @@
(check-false (negation #t))
(check-exn exn:fail? (λ () (negation #f #t)))))
(: enumerate-boolean-tables (-> Integer (Sequenceof (Listof (Listof Boolean)))))
(: enumerate-boolean-tables (-> Positive-Integer (Sequenceof (Listof (Listof Boolean)))))
(define (enumerate-boolean-tables n)
(define inputs (boolean-power n))
(define outputs (boolean-power/stream (cast (expt 2 n) Integer)))
@ -280,7 +280,7 @@
((#f #f #t) (#f #t #t) (#t #f #t) (#t #t #f))
((#f #f #t) (#f #t #t) (#t #f #t) (#t #t #t))))))
(: enumerate-boolean-functions (-> Integer (Sequenceof (-> Boolean * Boolean))))
(: enumerate-boolean-functions (-> Positive-Integer (Sequenceof (-> Boolean * Boolean))))
(define (enumerate-boolean-functions n)
(stream-map (inst table->function Boolean) (enumerate-boolean-tables n)))
@ -290,7 +290,7 @@
(check-false (bool-f1 #f))
(check-false (bool-f1 #t))))
(: enumerate-boolean-functions/pv (-> Integer (Sequenceof (-> Boolean * Boolean))))
(: enumerate-boolean-functions/pv (-> Positive-Integer (Sequenceof (-> Boolean * Boolean))))
(define (enumerate-boolean-functions/pv n)
(stream-map (inst table->function/pv Boolean) (enumerate-boolean-tables n)))
@ -302,7 +302,7 @@
(check-exn exn:fail? (λ () (bool-f1/pv #f #f)))))
(: enumerate-boolean-functions/list
(-> Integer (Sequenceof (-> (Listof Boolean) Boolean))))
(-> Positive-Integer (Sequenceof (-> (Listof Boolean) Boolean))))
(define (enumerate-boolean-functions/list n)
(stream-map (inst table->function/list Boolean) (enumerate-boolean-tables n)))
@ -312,7 +312,7 @@
(check-false (bool-f1/list '(#f)))
(check-false (bool-f1/list '(#t)))))
(: random-boolean-table (-> Integer (Listof (Listof Boolean))))
(: random-boolean-table (-> Positive-Integer (Listof (Listof Boolean))))
(define (random-boolean-table n)
(define ins (boolean-power n))
(define outs (stream-take (in-random 2) (cast (expt 2 n) Nonnegative-Integer)))
@ -328,7 +328,7 @@
(#t #f #f)
(#t #t #t)))))
(: random-boolean-function (-> Integer (-> Boolean * Boolean)))
(: random-boolean-function (-> Positive-Integer (-> Boolean * Boolean)))
(define (random-boolean-function n)
(table->function (random-boolean-table n)))

View File

@ -167,7 +167,7 @@ are @seclink["pseudovariadic"]{pseudovariadic}.
'((#f #t) (#f #t)))
]}
@defproc[(tabulate/pv/boolean [arity Integer] [func (-> Boolean * Boolean)])
@defproc[(tabulate/pv/boolean [arity Positive-Integer] [func (-> Boolean * Boolean)])
(Listof (Listof Boolean))]{
Like @racket[tabulate/pv], but assumes the domains of all variables of the
@ -198,7 +198,7 @@ this function.
}
@defproc[(tabulate*/pv/boolean [arity Integer]
@defproc[(tabulate*/pv/boolean [arity Positive-Integer]
[func (Listof (-> Boolean * Boolean))])
(Listof (Listof Boolean))]{
@ -210,7 +210,7 @@ same arity.
(pvλ (x y) (or x y))))
]}
@defproc[(tabulate/pv/01 [arity Integer] [func (-> (U Zero One) * (U Zero One))])
@defproc[(tabulate/pv/01 [arity Positive-Integer] [func (-> (U Zero One) * (U Zero One))])
(Listof (Listof (U Zero One)))]{
Like @racket[tabulate/pv], but assumes the domains of all variables of the
@ -228,7 +228,7 @@ See @racket[tabulate/pv/boolean] for an explanation of the explicit
}
@defproc[(tabulate*/pv/01 [arity Integer]
@defproc[(tabulate*/pv/01 [arity Positive-Integer]
[func (Listof (-> (U Zero One) * (U Zero One)))])
(Listof (Listof (U Zero One)))]{
@ -290,7 +290,7 @@ the returned by @racket[table->function/pv] is
(eval:error (my-and #f))
]}
@defproc[(enumerate-boolean-tables [n Integer])
@defproc[(enumerate-boolean-tables [n Positive-Integer])
(Sequenceof (Listof (Listof Boolean)))]{
Returns the stream of the truth tables of all Boolean functions of
@ -303,7 +303,7 @@ There are @tt{2^(2^n)} Boolean functions of arity @racket[n].
(stream->list (enumerate-boolean-tables 1))
]}
@defproc[(enumerate-boolean-functions [n Integer])
@defproc[(enumerate-boolean-functions [n Positive-Integer])
(Sequenceof (-> Boolean * Boolean))]{
Returns the stream of all Boolean functions of a given arity @racket[n].
@ -314,7 +314,7 @@ There are @tt{2^(2^n)} Boolean functions of arity @racket[n].
(length (stream->list (enumerate-boolean-functions 2)))
]}
@defproc[(enumerate-boolean-functions/pv [n Integer])
@defproc[(enumerate-boolean-functions/pv [n Positive-Integer])
(Sequenceof (-> Boolean * Boolean))]{
Like @racket[enumerate-boolean-functions], but the returned functions are
@ -327,7 +327,7 @@ Like @racket[enumerate-boolean-functions], but the returned functions are
]}
@defproc[(enumerate-boolean-functions/list
[n Integer])
[n Positive-Integer])
(Sequenceof (-> (Listof Boolean) Boolean))]{
Like @racket[enumerate-boolean-functions], but the returned functions take
@ -340,7 +340,7 @@ their arguments as a single list.
@section{Random functions}
@defproc[(random-boolean-table [n Integer]) (Listof (Listof Boolean))]{
@defproc[(random-boolean-table [n Positive-Integer]) (Listof (Listof Boolean))]{
Generates a random truth table for a Boolean function of arity @racket[n].
@ -348,7 +348,7 @@ Generates a random truth table for a Boolean function of arity @racket[n].
(random-boolean-table 2)
]}
@defproc[(random-boolean-function [n Integer]) (-> Boolean * Boolean)]{
@defproc[(random-boolean-function [n Positive-Integer]) (-> Boolean * Boolean)]{
Generates a random Boolean function of arity @racket[n].