From 15034343067bb45183f17c1c5875573c0f08221c Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 10 Apr 2022 22:37:50 +0200 Subject: [PATCH] Add tabulate*/pv/01 and tabulate/pv/01. --- functions.rkt | 27 +++++++++++++++++++++++++-- scribblings/functions.scrbl | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/functions.rkt b/functions.rkt index 4db4433..a95c27b 100644 --- a/functions.rkt +++ b/functions.rkt @@ -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] diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index 05463c0..1f993fc 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -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}