Add tabulate*/pv/01 and tabulate/pv/01.

This commit is contained in:
Sergiu Ivanov 2022-04-10 22:37:50 +02:00
parent 6102a2b8f3
commit 1503434306
2 changed files with 54 additions and 2 deletions

View file

@ -18,7 +18,7 @@
(provide
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean)
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01)
(module+ test
(require typed/rackunit))
@ -168,6 +168,28 @@
(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))
(Listof (Listof (U Zero One)))))
(define (tabulate/pv/01 arity func)
(tabulate/pv func (make-list arity '(0 1))))
(module+ test
(test-case "tabulate/pv/01"
(check-equal? (tabulate/pv/01 2 (pvλ (x y)
(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)))
(Listof (Listof (U Zero One)))))
(define (tabulate*/pv/01 arity funcs)
(tabulate*/pv funcs (make-list arity '(0 1))))
(module+ test
(test-case "tabulate*/pv/01"
(check-equal? (tabulate*/pv/01 2 `(,(pvλ (x y) (cast (min x y) (U Zero One)))
,(pvλ (x y) (cast (max x y) (U Zero One)))))
'((0 0 0 0) (0 1 0 1) (1 0 0 1) (1 1 1 1)))))
(module untyped racket
(module+ test
(require rackunit))
@ -247,7 +269,8 @@
pseudovariadic-lambda pvλ pseudovariadic-define pvdefine
tabulate* tabulate*/strict tabulate*/pv
tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean)
tabulate*/pv/boolean tabulate/pv/boolean
tabulate*/pv/01 tabulate/pv/01)
(require (rename-in (submod 'typed untyped)
[tabulate tabulate/untyped]

View file

@ -209,6 +209,35 @@ same arity.
(pvλ (x y) (or x y))))
]}
@defproc[(tabulate/pv/01 [arity 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
function are @tt{{0,1}}. The arity of @racket[func] must be
explicitly supplied.
@examples[#:eval functions-evaluator
(tabulate/pv/01 2 (pvλ (x y)
(cast (modulo (+ x y) 2)
(U Zero One))))
]
See @racket[tabulate/pv/boolean] for an explanation of the explicit
@racket[arity] argument.
}
@defproc[(tabulate*/pv/01 [arity Integer]
[func (Listof (-> (U Zero One) * (U Zero One)))])
(Listof (Listof (U Zero One)))]{
Like @racket[tabulate/pv/01], but takes a list of functions of the same arity.
@examples[#:eval functions-evaluator
(tabulate*/pv/01 2 `(,(pvλ (x y) (cast (min x y) (U Zero One)))
,(pvλ (x y) (cast (max x y) (U Zero One)))))
]}
@section{Constructing functions}
@section{Random functions}