example: Promote Reaction Systems to top-level heading.

This commit is contained in:
Sergiu Ivanov 2020-03-04 18:21:20 +01:00
parent 0cf05acb21
commit f8dc65df0a

View file

@ -467,144 +467,144 @@ tab
[[file:dots/examplehsuRqc.svg]] [[file:dots/examplehsuRqc.svg]]
:END: :END:
** Reaction systems * Reaction systems
:PROPERTIES: :PROPERTIES:
:header-args:racket: :prologue "#lang racket\n(require graph (file \"~/Candies/prj/racket/dds/rs.rkt\") (file \"~/Candies/prj/racket/dds/utils.rkt\"))" :header-args:racket: :prologue "#lang racket\n(require graph (file \"~/Candies/prj/racket/dds/rs.rkt\") (file \"~/Candies/prj/racket/dds/utils.rkt\"))"
:END: :END:
Consider the following reaction system: Consider the following reaction system:
#+NAME: rs1 #+NAME: rs1
| a | x t | y | z | | a | x t | y | z |
| b | x | q | z | | b | x | q | z |
Here is how we read this reaction into Racket code: Here is how we read this reaction into Racket code:
#+BEGIN_SRC racket :results output drawer :var input-rs=munch-sexp(rs1) #+BEGIN_SRC racket :results output drawer :var input-rs=munch-sexp(rs1)
(unorg-rs input-rs) (unorg-rs input-rs)
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
:RESULTS: :RESULTS:
(hash 'a (reaction (set 'x 't) (set 'y) (set 'z)) 'b (reaction (set 'x) (set 'q) (set 'z))) (hash 'a (reaction (set 'x 't) (set 'y) (set 'z)) 'b (reaction (set 'x) (set 'q) (set 'z)))
:END: :END:
Here is how we can put it back into an Org-mode table: Here is how we can put it back into an Org-mode table:
#+BEGIN_SRC racket :results table drawer :var input-rs=munch-sexp(rs1) #+BEGIN_SRC racket :results table drawer :var input-rs=munch-sexp(rs1)
(org-rs (unorg-rs input-rs)) (org-rs (unorg-rs input-rs))
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
:RESULTS: :RESULTS:
| a | "t x" | "y" | "z" | | a | "t x" | "y" | "z" |
| b | "x" | "q" | "z" | | b | "x" | "q" | "z" |
:END: :END:
Here is how we can apply this reaction system to a state: Here is how we can apply this reaction system to a state:
#+BEGIN_SRC racket :results output drawer :var input-rs=munch-sexp(rs1) #+BEGIN_SRC racket :results output drawer :var input-rs=munch-sexp(rs1)
(let ([rs (unorg-rs input-rs)]) (let ([rs (unorg-rs input-rs)])
(apply-rs rs (set 'x 't))) (apply-rs rs (set 'x 't)))
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
:RESULTS: :RESULTS:
(set 'z) (set 'z)
:END: :END:
Let's see which reactions got applied: Let's see which reactions got applied:
#+BEGIN_SRC racket :results list :var input-rs=munch-sexp(rs1) #+BEGIN_SRC racket :results list :var input-rs=munch-sexp(rs1)
(let ([rs (unorg-rs input-rs)]) (let ([rs (unorg-rs input-rs)])
(list-enabled rs (set 'x 't))) (list-enabled rs (set 'x 't)))
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
- a - a
- b - b
You can also give a name to a list and read it with =munch-sexp=: You can also give a name to a list and read it with =munch-sexp=:
#+NAME: ctx1 #+NAME: ctx1
- x y - x y
- z - z
- -
- t - t
#+BEGIN_SRC racket :results output drawer :var input-ctx=munch-sexp(ctx1) #+BEGIN_SRC racket :results output drawer :var input-ctx=munch-sexp(ctx1)
(read-ctx input-ctx) (read-ctx input-ctx)
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
:RESULTS: :RESULTS:
(list (set 'x 'y) (set 'z) (set) (set 't)) (list (set 'x 'y) (set 'z) (set) (set 't))
:END: :END:
Let's see what the evolution of =rs1= looks like with the context Let's see what the evolution of =rs1= looks like with the context
sequence =ctx1=. sequence =ctx1=.
#+NAME: rs1-sgr #+NAME: rs1-sgr
#+HEADER: :var input-rs=munch-sexp(rs1) :var input-ctx=munch-sexp(ctx1) #+HEADER: :var input-rs=munch-sexp(rs1) :var input-ctx=munch-sexp(ctx1)
#+BEGIN_SRC racket :results output drawer #+BEGIN_SRC racket :results output drawer
(dotit (ppsg (build-interactive-process-graph (unorg-rs input-rs) (read-ctx input-ctx)))) (dotit (ppsg (build-interactive-process-graph (unorg-rs input-rs) (read-ctx input-ctx))))
#+END_SRC #+END_SRC
#+RESULTS: rs1-sgr #+RESULTS: rs1-sgr
:RESULTS: :RESULTS:
digraph G { digraph G {
node0 [label="C:{}{t}\nD:{}"]; node0 [label="C:{}{t}\nD:{}"];
node1 [label="C:{z}{}{t}\nD:{z}"]; node1 [label="C:{z}{}{t}\nD:{z}"];
node2 [label="C:{t}\nD:{}"]; node2 [label="C:{t}\nD:{}"];
node3 [label="C:{x y}{z}{}{t}\nD:{}"]; node3 [label="C:{x y}{z}{}{t}\nD:{}"];
node4 [label="C:\nD:{}"]; node4 [label="C:\nD:{}"];
subgraph U { subgraph U {
edge [dir=none]; edge [dir=none];
node4 -> node4 [label="{}"]; node4 -> node4 [label="{}"];
} }
subgraph D { subgraph D {
node0 -> node2 [label="{}"]; node0 -> node2 [label="{}"];
node1 -> node0 [label="{}"]; node1 -> node0 [label="{}"];
node2 -> node4 [label="{}"]; node2 -> node4 [label="{}"];
node3 -> node1 [label="{b}"]; node3 -> node1 [label="{b}"];
} }
} }
:END: :END:
#+BEGIN_SRC dot :file dots/examplevvXFaI.svg :results raw drawer :cmd circo :noweb yes #+BEGIN_SRC dot :file dots/examplevvXFaI.svg :results raw drawer :cmd circo :noweb yes
<<rs1-sgr()>> <<rs1-sgr()>>
#+END_SRC #+END_SRC
#+RESULTS: #+RESULTS:
:RESULTS: :RESULTS:
[[file:dots/examplevvXFaI.svg]] [[file:dots/examplevvXFaI.svg]]
:END: :END:
Note that we need to keep the full context sequence in the name of Note that we need to keep the full context sequence in the name of
each state to avoid merging states with the same result and each state to avoid merging states with the same result and
contexts, but which occur at different steps of the evolution. contexts, but which occur at different steps of the evolution.
The graphical presentation for interactive processes is arguably The graphical presentation for interactive processes is arguably
less readable than just listing the contexts and the results less readable than just listing the contexts and the results
explicitly. Here is how you can do it. explicitly. Here is how you can do it.
#+NAME: rs1-ip #+NAME: rs1-ip
#+HEADER: :var input-rs=munch-sexp(rs1) :var input-ctx=munch-sexp(ctx1) #+HEADER: :var input-rs=munch-sexp(rs1) :var input-ctx=munch-sexp(ctx1)
#+BEGIN_SRC racket :results table drawer #+BEGIN_SRC racket :results table drawer
(build-interactive-process (unorg-rs input-rs) (read-ctx input-ctx)) (build-interactive-process (unorg-rs input-rs) (read-ctx input-ctx))
#+END_SRC #+END_SRC
#+RESULTS: rs1-ip #+RESULTS: rs1-ip
:RESULTS: :RESULTS:
| (y x) | nil | | (y x) | nil |
| (z) | (z) | | (z) | (z) |
| nil | nil | | nil | nil |
| (t) | nil | | (t) | nil |
| nil | nil | | nil | nil |
:END: :END:
The first column of this table shows the current context. The The first column of this table shows the current context. The
second column shows the result of application of the reactions to second column shows the result of application of the reactions to
the previous state. The interactive process contains one more step the previous state. The interactive process contains one more step
with respect to the context sequence. This is to show the effect with respect to the context sequence. This is to show the effect
of the last context. of the last context.
Note that empty sets are printed as =nil=. Note that empty sets are printed as =nil=.
* Local Variables :noexport: * Local Variables :noexport: