diff --git a/example/example.org b/example/example.org index 9e27e14..71f3bed 100644 --- a/example/example.org +++ b/example/example.org @@ -688,6 +688,84 @@ tab the - arcs in the graph, as it does not have access to the symbolic description of the function. +** Threshold Boolean functions (TBF) + =dds= includes some useful definitions for working with threshold + Boolean functions (TBF). A TBF is defined as a vector of weights + and a threshold. For example, the following defines a + TBF implementing the logical AND. + #+BEGIN_SRC racket :results output drawer +(tbf #(1 1) 1) + #+END_SRC + + #+RESULTS: + :RESULTS: + (tbf '#(1 1) 1) + :END: + + This TBF only returns 1 when both inputs are activated, which + brings their weighted some above 1: 1 \cdot 1 + 1 \cdot 1 = 2 > 1. + #+BEGIN_SRC racket :results output drawer +(apply-tbf (tbf #(1 1) 1) #(1 1)) + #+END_SRC + + #+RESULTS: + :RESULTS: + 1 + :END: + + Let's actually check out the truth table of this TBF. + #+BEGIN_SRC racket :results table drawer +(tbf-tabulate (tbf #(1 1) 1)) + #+END_SRC + + #+RESULTS: + :RESULTS: + | 0 | 0 | 0 | + | 0 | 1 | 0 | + | 1 | 0 | 0 | + | 1 | 1 | 1 | + :END: + + This truth table corresponds indeed to the logical AND. + + =dds= allows reading TBFs from Org tables. In this case, the last + column in each row is treated as the threshold, while the first + values are taken to be the weights. Consider, for example, the + following table: + #+NAME: simple-tbf + | 1 | 1 | 0 | + | 1 | 1 | 1 | + + You can read the two TBFs defined in this table in the following + way: + #+BEGIN_SRC racket :results output drawer :var simple-tbf=munch-sexp(simple-tbf) +(read-org-tbfs simple-tbf) + #+END_SRC + + #+RESULTS: + :RESULTS: + (list (tbf '#(1 1) 0) (tbf '#(1 1) 1)) + :END: + + The first TBF implements the logical OR of its inputs, while the + second TBF implements the logical AND. Let's check it by + tabulating both functions: + #+BEGIN_SRC racket :results table drawer :var simple-tbf=munch-sexp(simple-tbf) +(tbf-tabulate* (read-org-tbfs simple-tbf)) + #+END_SRC + + #+RESULTS: + :RESULTS: + | 0 | 0 | 0 | 0 | + | 0 | 1 | 1 | 0 | + | 1 | 0 | 1 | 0 | + | 1 | 1 | 1 | 1 | + :END: + + The first two columns of this table give the values of the two + inputs. The third column gives the values of the first TBF, and + the fourth column gives the values of the second TBF. + * Reaction systems :PROPERTIES: :header-args:racket: :prologue "#lang racket\n(require graph dds/rs dds/utils)"