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
1 changed files with 104 additions and 104 deletions

View File

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