From b38bebb67bff4a8e7171879574b8abc80c6e9aaa Mon Sep 17 00:00:00 2001 From: Sergiu Ivanov Date: Sun, 22 Mar 2020 20:38:32 +0100 Subject: [PATCH] example: Add some examples for random functions and networks. --- example/example.org | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/example/example.org b/example/example.org index 8b873ae..bde9c9a 100644 --- a/example/example.org +++ b/example/example.org @@ -523,6 +523,59 @@ tab | #t | #t | #t | #t | #f | #f | :END: +** Random functions and networks + To avoid having different results every time a code block in this + section is run, every code block seeds the random number generator + to 0. + + =dds/networks= can generate random functions, given a domain for + each of its arguments and for the function itself. Consider the + following domains: + #+NAME: simple-domains + | a | (#f #t) | + | b | (1 2) | + | c | (cold hot) | + + Here's a random function taking values in the codomain =(4 5 6)=: + #+BEGIN_SRC racket :results table drawer :var simple-domains=munch-sexp(simple-domains) +(random-seed 0) +(define rnd-func (random-function/state (unorg simple-domains) '(4 5 6))) +(tabulate-state rnd-func (unorg simple-domains)) + #+END_SRC + + #+RESULTS: + :RESULTS: + | a | b | c | f | + | #f | 1 | cold | 4 | + | #f | 1 | hot | 5 | + | #f | 2 | cold | 4 | + | #f | 2 | hot | 4 | + | #t | 1 | cold | 5 | + | #t | 1 | hot | 6 | + | #t | 2 | cold | 4 | + | #t | 2 | hot | 5 | + :END: + + We can build an entire random network over these domains: + #+BEGIN_SRC racket :results table drawer :var simple-domains=munch-sexp(simple-domains) +(random-seed 0) +(define n (random-network (unorg simple-domains))) +(tabulate-network n (unorg simple-domains)) + #+END_SRC + + #+RESULTS: + :RESULTS: + | a | b | c | f-a | f-b | f-c | + | #f | 1 | cold | #t | 2 | cold | + | #f | 1 | hot | #t | 1 | cold | + | #f | 2 | cold | #f | 1 | hot | + | #f | 2 | hot | #t | 2 | hot | + | #t | 1 | cold | #t | 1 | cold | + | #t | 1 | hot | #f | 1 | hot | + | #t | 2 | cold | #t | 2 | cold | + | #t | 2 | hot | #f | 1 | hot | + :END: + * Reaction systems :PROPERTIES: