Start Common examples.
This commit is contained in:
parent
5da523d297
commit
70be49b957
1 changed files with 18 additions and 16 deletions
|
@ -62,6 +62,24 @@ their domains.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@section{Common examples}
|
||||||
|
|
||||||
|
The examples in this document often use the same definitions, which are
|
||||||
|
therefore grouped here to avoid duplicating them.
|
||||||
|
|
||||||
|
These are two functions calculating an @italic{AND} and an @italic{OR} between
|
||||||
|
the variables @racket[a] and @racket[b]:
|
||||||
|
|
||||||
|
@ex[
|
||||||
|
(: or-func (UpdateFunction Boolean))
|
||||||
|
(define (or-func s)
|
||||||
|
(or (hash-ref s 'a) (hash-ref s 'b)))
|
||||||
|
|
||||||
|
(: and-func (UpdateFunction Boolean))
|
||||||
|
(define (and-func s)
|
||||||
|
(and (hash-ref s 'a) (hash-ref s 'b)))
|
||||||
|
]
|
||||||
|
|
||||||
@section{Networks}
|
@section{Networks}
|
||||||
|
|
||||||
@defstruct*[network ([functions (VariableMapping (UpdateFunction a))]
|
@defstruct*[network ([functions (VariableMapping (UpdateFunction a))]
|
||||||
|
@ -79,14 +97,6 @@ Instances of @racket[network] have the type @racket[Network].
|
||||||
The type of the instances of @racket[Network].
|
The type of the instances of @racket[Network].
|
||||||
|
|
||||||
@ex[
|
@ex[
|
||||||
(: or-func (UpdateFunction Boolean))
|
|
||||||
(define (or-func s)
|
|
||||||
(or (hash-ref s 'a) (hash-ref s 'b)))
|
|
||||||
|
|
||||||
(: and-func (UpdateFunction Boolean))
|
|
||||||
(define (and-func s)
|
|
||||||
(and (hash-ref s 'a) (hash-ref s 'b)))
|
|
||||||
|
|
||||||
(network (hash 'a or-func
|
(network (hash 'a or-func
|
||||||
'b and-func)
|
'b and-func)
|
||||||
(hash 'a '(#f #t)
|
(hash 'a '(#f #t)
|
||||||
|
@ -119,14 +129,6 @@ Builds a Boolean network from a given hash table assigning functions to
|
||||||
variables by attributing Boolean domains to every variable.
|
variables by attributing Boolean domains to every variable.
|
||||||
|
|
||||||
@ex[
|
@ex[
|
||||||
(: or-func (UpdateFunction Boolean))
|
|
||||||
(define (or-func s)
|
|
||||||
(or (hash-ref s 'a) (hash-ref s 'b)))
|
|
||||||
|
|
||||||
(: and-func (UpdateFunction Boolean))
|
|
||||||
(define (and-func s)
|
|
||||||
(and (hash-ref s 'a) (hash-ref s 'b)))
|
|
||||||
|
|
||||||
(make-boolean-network (hash 'a or-func 'b and-func))
|
(make-boolean-network (hash 'a or-func 'b and-func))
|
||||||
]}
|
]}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue