From c19d18122cb03496edc0c012233a059af17ae0c5 Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sat, 9 Apr 2022 01:32:54 +0200 Subject: [PATCH] Move tabulate/boolean and tabulate*/boolean to typed/untyped. --- functions.rkt | 51 +++++++++++++++++-------------------- scribblings/functions.scrbl | 21 +++++++++++++++ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/functions.rkt b/functions.rkt index c5a4d5d..e4ab726 100644 --- a/functions.rkt +++ b/functions.rkt @@ -155,7 +155,10 @@ (contract-out [tabulate* (-> (listof procedure?) (listof (listof any/c)) (listof (listof any/c)))] [tabulate (-> procedure? (listof (listof any/c)) - (listof (listof any/c)))])) + (listof (listof any/c)))] + [tabulate/boolean (-> procedure? (listof (listof boolean?)))] + [tabulate*/boolean (-> (non-empty-listof procedure?) + (listof (listof boolean?)))])) (define (tabulate* funcs doms) (for/list ([xs (in-list (apply cartesian-product doms))]) @@ -178,7 +181,26 @@ (module+ test (test-case "tabulate" (check-equal? (tabulate (λ (x y) (and x y)) '((#f #t) (#f #t))) - '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))) + '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))))) + + (define (tabulate/boolean func) + (tabulate func (make-list (procedure-arity func) '(#f #t)))) + + (module+ test + (test-case "tabulate/boolean" + (check-equal? (tabulate/boolean (lambda (x y) (and x y))) + '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))))) + + (define (tabulate*/boolean funcs) + (define doms (make-list (procedure-arity (car funcs)) '(#f #t))) + (tabulate* funcs doms)) + + (module+ test + (test-case "tabulate*/boolean" + (check-equal? (tabulate*/boolean `(,(λ (x y) (and x y)) + ,(λ (x y) (or x y)))) + '((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t))))) + ) ) (require 'typed) @@ -197,8 +219,6 @@ [struct tbf ((weights (vectorof number?)) (threshold number?))]) ;; Functions (contract-out - [tabulate/boolean (-> procedure? (listof (listof boolean?)))] - [tabulate*/boolean (-> (non-empty-listof procedure?) (listof (listof boolean?)))] [tabulate/01 (-> procedure? (listof (listof (or/c 0 1))))] [tabulate*/01 (-> (non-empty-listof procedure?) (listof (listof (or/c 0 1))))] [table->function (-> (listof (*list/c any/c any/c)) procedure?)] @@ -235,29 +255,6 @@ ;;; Tabulating ;;; ========== -;;; Like tabulate, but assumes the domains of all variables of the -;;; function are Boolean. func must have a fixed arity. It is an -;;; error to supply a function of variable arity. -(define (tabulate/boolean func) - (tabulate/untyped func (make-list (procedure-arity func) '(#f #t)))) - -(module+ test - (test-case "tabulate/boolean" - (check-equal? (tabulate/boolean (lambda (x y) (and x y))) - '((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t))))) - -;;; Like tabulate/boolean, but takes a list of functions of the same -;;; arity. -(define (tabulate*/boolean funcs) - (define doms (make-list (procedure-arity (car funcs)) '(#f #t))) - (tabulate*/untyped funcs doms)) - -(module+ test - (test-case "tabulate*/boolean" - (check-equal? (tabulate*/boolean `(,(λ (x y) (and x y)) - ,(λ (x y) (or x y)))) - '((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t))))) - ;;; Like tabulate, but assumes the domains of all variables of the ;;; function are {0, 1}. func must have a fixed arity. It is an ;;; error to supply a function of variable arity. diff --git a/scribblings/functions.scrbl b/scribblings/functions.scrbl index 9b53c61..4f4b750 100644 --- a/scribblings/functions.scrbl +++ b/scribblings/functions.scrbl @@ -213,3 +213,24 @@ same arguments over the same domains. (λ (x y) (or x y))) '((#f #t) (#f #t))) ]} + +@defproc[(tabulate/boolean [func procedure?]) (listof (listof boolean?))]{ + +Like @racket[tabulate], but assumes the domains of all variables of the +function are Boolean. @racket[func] must have a fixed arity. It is an error +to supply a function of variable arity. + +@examples[#:eval functions-evaluator/untyped +(tabulate/boolean (lambda (x y) (and x y))) +]} + +@defproc[(tabulate*/boolean [funcs (non-empty-listof procedure?)]) + (listof (listof boolean?))]{ + +Like @racket[tabulate/boolean], but takes a list of functions of the +same arity. + +@examples[#:eval functions-evaluator/untyped +(tabulate*/boolean `(,(λ (x y) (and x y)) + ,(λ (x y) (or x y)))) +]}