Add tabulate*/list/boolean tabulate/list/boolean tabulate*/list/01 tabulate/list/01.

This commit is contained in:
Sergiu Ivanov 2022-04-22 16:20:25 +02:00
parent 0196ab5800
commit 0e9a974965
2 changed files with 98 additions and 0 deletions

View File

@ -23,6 +23,7 @@
tabulate* tabulate*/strict tabulate*/pv tabulate tabulate/strict tabulate/pv
tabulate*/pv/boolean tabulate/pv/boolean tabulate*/pv/01 tabulate/pv/01
tabulate*/list tabulate/list
tabulate*/list/boolean tabulate/list/boolean tabulate*/list/01 tabulate/list/01
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv enumerate-boolean-functions/list
@ -229,6 +230,53 @@
,(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)))))
(: tabulate/list/boolean (-> Positive-Integer (-> (Listof Boolean) Boolean)
(Listof (Listof Boolean))))
(define (tabulate/list/boolean arity func)
(tabulate/list func (make-list arity '(#f #t))))
(module+ test
(test-case "tabulate/list/boolean"
(check-equal? (tabulate/list/boolean 2 (λ (xs) (and (car xs) (cadr xs))))
'((#f #f #f) (#f #t #f) (#t #f #f) (#t #t #t)))))
(: tabulate*/list/boolean (-> Positive-Integer (Listof (-> (Listof Boolean) Boolean))
(Listof (Listof Boolean))))
(define (tabulate*/list/boolean arity funcs)
(tabulate*/list funcs (make-list arity '(#f #t))))
(module+ test
(test-case "tabulate*/list/boolean"
(check-equal?
(tabulate*/list/boolean 2 (list (λ (xs) (and (car xs) (cadr xs)))
(λ (xs) (or (car xs) (cadr xs)))))
'((#f #f #f #f) (#f #t #f #t) (#t #f #f #t) (#t #t #t #t)))))
(: tabulate/list/01 (-> Positive-Integer (-> (Listof (U Zero One)) (U Zero One))
(Listof (Listof (U Zero One)))))
(define (tabulate/list/01 arity func)
(tabulate/list func (make-list arity '(0 1))))
(module+ test
(test-case "tabulate/list/01"
(check-equal?
(tabulate/list/01 2 (λ (xs)
(cast (modulo (+ (car xs) (cadr xs)) 2) (U Zero One))))
'((0 0 0) (0 1 1) (1 0 1) (1 1 0)))))
(: tabulate*/list/01 (-> Positive-Integer (Listof (-> (Listof (U Zero One)) (U Zero One)))
(Listof (Listof (U Zero One)))))
(define (tabulate*/list/01 arity funcs)
(tabulate*/list funcs (make-list arity '(0 1))))
(module+ test
(test-case "tabulate*/list/01"
(check-equal? (tabulate*/list/01
2
`(,(λ (xs) (cast (min (car xs) (cadr xs)) (U Zero One)))
,(λ (xs) (cast (max (car xs) (cadr xs)) (U Zero One)))))
'((0 0 0 0) (0 1 0 1) (1 0 0 1) (1 1 1 1)))))
(: table->function/list (All (a) (-> (Listof (Listof a))
(-> (Listof a) a))))
(define (table->function/list table)
@ -535,6 +583,7 @@
tabulate*/pv/boolean tabulate/pv/boolean
tabulate*/pv/01 tabulate/pv/01
tabulate*/list tabulate/list
tabulate*/list/boolean tabulate/list/boolean tabulate*/list/01 tabulate/list/01
table->function/list table->function table->function/pv
enumerate-boolean-tables enumerate-boolean-functions
enumerate-boolean-functions/pv enumerate-boolean-functions/list

View File

@ -266,6 +266,55 @@ Like @racket[tabulate/pv/01], but takes a list of functions of the same arity.
,(pvλ (x y) (cast (max x y) (U Zero One)))))
]}
@defproc[(tabulate/list/boolean [arity Positive-Integer]
[func (-> (Listof Boolean) Boolean)])
(Listof (Listof Boolean))]{
Like @racket[tabulate/list], but assumes the domains of all variables of the
function are Boolean.
@examples[#:eval functions-evaluator
(tabulate/list/boolean 2 (λ (xs) (and (car xs) (cadr xs))))
]}
@defproc[(tabulate*/list/boolean [arity Positive-Integer]
[funcs (Listof (-> (Listof Boolean) Boolean))])
(Listof (Listof Boolean))]{
Like @racket[tabulate*/list], but assumes the domains of all variables of the
function are Boolean.
@examples[#:eval functions-evaluator
(tabulate*/list/boolean 2 (list (λ (xs) (and (car xs) (cadr xs)))
(λ (xs) (or (car xs) (cadr xs)))))
]}
@defproc[(tabulate/list/01 [arity Positive-Integer]
[func (-> (Listof (U Zero One)) (U Zero One))])
(Listof (Listof (U Zero One)))]{
Like @racket[tabulate/list], but assumes the domains of all variables of the
function are @tt{{0,1}}.
@examples[#:eval functions-evaluator
(tabulate/list/01 2 (λ (xs)
(cast (modulo (+ (car xs) (cadr xs)) 2) (U Zero One))))
]}
@defproc[(tabulate*/list/01 [arity Positive-Integer]
[funcs (Listof (-> (Listof (U Zero One)) (U Zero One)))])
(Listof (Listof (U Zero One)))]{
Like @racket[tabulate*/list], but assumes the domains of all variables of the
function are @tt{{0,1}}.
@examples[#:eval functions-evaluator
(tabulate*/list/01
2
`(,(λ (xs) (cast (min (car xs) (cadr xs)) (U Zero One)))
,(λ (xs) (cast (max (car xs) (cadr xs)) (U Zero One)))))
]}
@section{Constructing functions}
@defproc[(table->function/list [table (Listof (Listof a))])