2020-11-29 17:43:20 +01:00
|
|
|
#lang scribble/manual
|
2022-03-05 21:37:24 +01:00
|
|
|
@(require scribble/example racket/sandbox
|
2022-03-06 19:54:05 +01:00
|
|
|
(for-label typed/racket/base "../functions.rkt" dds/utils))
|
2020-11-29 17:43:20 +01:00
|
|
|
|
|
|
|
@title[#:tag "functions"]{dds/functions: Formal Functions}
|
|
|
|
|
2020-11-29 21:45:33 +01:00
|
|
|
@defmodule[dds/functions]
|
|
|
|
|
|
|
|
This modules provides some definitions for working with functions: tabulating,
|
|
|
|
(re)constructing from tables, generating random functions, etc.
|
|
|
|
Some definitions of particular kinds of functions are also provided (threshold
|
|
|
|
Boolean functions, etc.).
|
|
|
|
|
2022-03-05 21:37:24 +01:00
|
|
|
@(define functions-evaluator
|
|
|
|
(parameterize ([sandbox-output 'string]
|
|
|
|
[sandbox-error-output 'string]
|
|
|
|
[sandbox-memory-limit 50])
|
|
|
|
(make-evaluator 'typed/racket #:requires '((submod "functions.rkt" typed)))))
|
|
|
|
|
2020-11-29 21:45:33 +01:00
|
|
|
@section{Tabulating functions}
|
|
|
|
|
2022-03-06 19:54:05 +01:00
|
|
|
@defproc[(tabulate* [funcs (Listof (-> a ... b))]
|
|
|
|
[doms (List (Listof a) ... a)])
|
|
|
|
(Listof (Listof (U Any b)))]{
|
|
|
|
|
|
|
|
Like @racket[tabulate], but @racket[funcs] is a list of functions taking the
|
|
|
|
same arguments over the same domains.
|
|
|
|
|
|
|
|
@examples[#:eval functions-evaluator
|
|
|
|
(tabulate* (list (λ (x y) (and x y))
|
|
|
|
(λ (x y) (or x y)))
|
|
|
|
'((#f #t) (#f #t)))
|
|
|
|
]}
|
|
|
|
|
|
|
|
@defproc[(tabulate*/strict [funcs (Listof (-> a ... b))]
|
|
|
|
[doms (List (Listof a) ... a)])
|
|
|
|
(Listof (List (List a ...) (Listof b)))]{
|
|
|
|
|
|
|
|
Like @racket[tabulate*], but the types of the arguments of the functions
|
|
|
|
explicitly appear in the return type.
|
|
|
|
|
|
|
|
As of 2022-03-06, I am not able to write the type of a list first containing
|
|
|
|
elements of types @racket[a ...], followed by a list of elements of type
|
|
|
|
@racket[b]. This is why this function returns a list of lists, each containing
|
|
|
|
first a list of inputs, and then the list of outputs of @racket[funcs].
|
|
|
|
|
|
|
|
@examples[#:eval functions-evaluator
|
|
|
|
(tabulate*/strict (list (λ (x y) (and x y))
|
|
|
|
(λ (x y) (or x y)))
|
|
|
|
'((#f #t) (#f #t)))
|
|
|
|
]
|
|
|
|
|
|
|
|
The result of @racket[tabulate*] can be obtained by applying
|
|
|
|
@racket[append-lists]:
|
|
|
|
|
|
|
|
@examples[#:eval functions-evaluator
|
|
|
|
(require (only-in "utils.rkt" append-lists))
|
|
|
|
(append-lists (tabulate*/strict (list (λ (x y) (and x y))
|
|
|
|
(λ (x y) (or x y)))
|
|
|
|
'((#f #t) (#f #t))))
|
|
|
|
]}
|
|
|
|
|
2020-11-29 21:45:33 +01:00
|
|
|
@section{Constructing functions}
|
|
|
|
|
|
|
|
@section{Random functions}
|
|
|
|
|
|
|
|
@section{Threshold Boolean functions}
|