3.1.9.1. rule/Composition¶
This page contains the core functionality for composing rules and creating rules from graphs. Note that there is both a lowlevel interface for constructing expressions, and an embedded minilanguage for defining the expressions using normal Python operators.
3.1.9.1.1. The Embedded Rule Composition Expression Language¶
The embedded language is really a collection of proxy classes with a lot of operator overloading, thus the normal syntax and semantics of Python applies.
A rule composition expression always returns a list of rules when evaluated. The following is the grammar for the expressions.
rcExp ::=rcExp
op
rcExp
"rcBind("graphs
")" "rcUnbind("graphs
")" "rcId("graphs
")"rules
op ::= "*"opObject
"*" opObject ::= "rcParallel" "rcSuper(allowPartial=False)" "rcSuper" "rcSub(allowPartial=False)" "rcSub" "rcCommon"
Here a graphs
is any Python expression that is either a single Graph
or an iterable of graphs.
Similarly, a rules
must be either a Rule
or an iterable of rules.
An rcExp
may additionally be an iterable of expressions.
See the API below for more details on the semantics of each expression, and the corresponding C++ page.
3.1.9.1.2. Expression Evaluator¶

class
mod.
RCEvaluator
¶ This class can evaluate rule composition expressions. During evaluation an expression graph is recorded.
The expression graph is a directed hypergraph \((V, E)\), with each vertex representing a rule. Each edge represent all compositions calculated for a unique input. That is every edge \(e\in E\) is on the form \(((u, v), R_e)\) with \((u, v)\in V\times V\) as an ordered pair of rules and \(R_e\subseteq V\) is the set of all resulting rules found.
The graph is visualised as a bipartite graph with pointshaped vertices representing the hyperedges. The inedges to these hyperedge vertices are labelled with 1 and 2.

ruleDatabase
¶ (Readonly) The list of unique rules known by the evaluator.
Type: list of

products
¶ (Readonly) The list of unique rules this evaluator has constructed.
Type: list of

eval
(exp)¶ Evaluates a rule composition expression. Any created rule is replaced by a rule in the database if they are isomorphic.
Returns: the resulting list of rules of the expression. Parameters: exp ( RCExpExp
) – the expression to evaluate.

print
()¶ Print the graph representing all expressions evaluated so far.


mod.
rcEvaluator
(database, labelSettings)¶ Parameters:  database (list of
Rule
) – a list of isomorphic rules the evaluator will compare against.  labelSettings (
LabelSettings
) – the settings to use for morphisms.
Returns: a rule composition expression evaluator.
Return type: Note
The caller is responsible for ensuring the given rules are unique.
 database (list of
3.1.9.1.3. Rule Composition Expressions¶
An expression, RCExpExp
, can be evaluated through the method RCEvaluator.eval()
.
The result of an expression is a list of rules.
3.1.9.1.3.1. Class RCExpUnion
¶

class
mod.
RCExpUnion
¶ Return the union of the subexpressions. I.e., flatten the subresult lists into a single list.
3.1.9.1.3.2. Class RCExpBind
¶

class
mod.
RCExpBind
¶ Return the singleton list with the rule \((\emptyset, \emptyset, G)\) for the given graph \(G\).
3.1.9.1.3.3. Class RCExpId
¶

class
mod.
RCExpId
¶ Return the singleton list with the rule \((G, G, G)\) for the given graph \(G\).
3.1.9.1.3.4. Class RCExpUnbind
¶

class
mod.
RCExpUnbind
¶ Return the singleton list with the rule \((G, \emptyset, \emptyset)\) for the given graph \(G\).
3.1.9.1.3.6. Class RCExpComposeCommon
¶

class
mod.
RCExpComposeCommon
¶ The base class for the composition of two rule \((L_1, K_1, R_1)\) and \((L_2, K_2, R_2)\).
3.1.9.1.3.7. Class RCExpComposeParallel
¶

class
mod.
RCExpComposeParallel
¶ Compose the rules by all common subgraphs of \(R_1\) and \(L_2\), possibly limited to connected subgraphs or to the subgraphs of maximum size.
3.1.9.1.3.8. Class RCExpComposeSub
¶

class
mod.
RCExpComposeSub
¶ Compose the rules by the empty graph, i.e., create a rule representing the parallel application of two input rules.
3.1.9.1.3.9. Class RCExpComposeSuper
¶

class
mod.
RCExpComposeSuper
¶ Compose the rules such that overlapping connected components of \(R_1\) and \(L_2\) have the \(L_2\) component as a subgraph of \(R_1\). The overlap is partial if not every connected component of \(L_2\) is participating in the common subgraph.