=Paper= {{Paper |id=Vol-3946/TGD_paper4 |storemode=property |title=Logica-TGD: Transforming Graph Databases Logically |pdfUrl=https://ceur-ws.org/Vol-3946/TGD-4.pdf |volume=Vol-3946 |authors=Evgeny Skvortsov,Yilin Xia,Shawn Bowers,Bertram Ludäscher }} ==Logica-TGD: Transforming Graph Databases Logically== https://ceur-ws.org/Vol-3946/TGD-4.pdf
                         Logica-TGD: Transforming Graph Databases Logically
                         Evgeny Skvortsov1 , Yilin Xia2 , Bertram Ludäscher2 and Shawn Bowers3
                         1
                           Google LLC, WA, USA
                         2
                           University of Illinois Urbana-Champaign, School of Information Sciences, IL, USA
                         3
                           Gonzaga University, Department of Computer Science, Spokane, WA, USA


                                          Abstract
                                          Graph transformations are a powerful computational model for manipulating complex networks, but handling temporal aspects
                                          and scalability remain significant challenges. We present a novel approach to implementing these transformations using Logica, an
                                          open-source logic programming language and system that operates on parallel databases like DuckDB and BigQuery. Leveraging
                                          the parallelism of these engines, our method enhances performance and accessibility, while also offering a practical way to handle
                                          time-varying graphs. We illustrate Logica’s graph querying and transformation capabilities with several examples, including the
                                          computation of the well-founded solution to the classic “Win-Move” game, a declarative program for pathfinding in a dynamic graph,
                                          and the application of Logica to the collection of all current facts of Wikidata for taxonomic relations analysis. We argue that clear
                                          declarative syntax, built-in visualization and powerful supported engines make Logica a convenient tool for graph transformations.

                                          Keywords
                                          Logic rules, graph queries, graph transformations



                         1. Introduction                                                                                          difficult in classical graph transformation approaches, such
                                                                                                                                  as temporal transformations and seamless scalability.
                         Graph transformations are a powerful and versatile method                                                   To illustrate the practical nature of our approach, we
                         for modeling and manipulating complex systems across di-                                                 introduce several example Logica programs implementing
                         verse fields, ranging from software engineering [1, 2] and                                               different types of graph transformations. Specifically, we
                         social network analysis [3] to biology and chemistry [4, 5, 6].                                          show how Logica can be used to define and perform basic
                         These transformations typically operate by applying rewrite                                              graph transformations including message passing, removing
                         rules to a graph, altering its structure and properties. While                                           transitively implied graph edges, and solving (i.e., labeling
                         these transformations are known for their expressiveness                                                 or coloring) win-move graphs. We also introduce a novel ap-
                         and flexibility, their implementation can often be complex,                                              proach to time-aware pathfinding (e.g., [10, 11, 12]), directly
                         especially when dealing with time-varying graphs or requir-                                              addressing the need for principled and tractable mechanisms
                         ing scalable solutions. Existing graph database systems of-                                              to handle evolving graph data, a notoriously difficult prob-
                         ten provide limited support for such evolution mechanisms,                                               lem in classical graph transformation approaches. These
                         creating a gap between theoretical models and practical                                                  examples serve both to show the expressiveness of our ap-
                         implementations.                                                                                         proach, and to illustrate its potential benefits.
                            Logic programming, on the other hand, provides a declar-                                                 The rest of this paper is structured as follows: Secion 2
                         ative approach to problem solving by expressing rules and                                                provides an overview of Logica. Section 3 demonstrates how
                         relationships rather than explicitly stating control-flow.                                               to express graph transformations in Logica. We conclude in
                         Logic-based systems (e.g., Prolog and Answer Set Program-                                                Section 4 with a discussion of the limitations and potential
                         ming [7]) are well-established in various areas, including                                               avenues for future research.
                         (symbolic) AI and knowledge representation and reason-
                         ing. More recently, Logica (Logic + Aggregation) [8, 9], an
                         open-source logic programming language and system, has                                                   2. Logica Overview
                         emerged, which employs parallel data processing environ-
                         ments such as DuckDB and BigQuery. Logica combines the                                                   Logica is a freely available, open-source variant of Datalog
                         declarative power of logic programming with the scalability                                              combining the declarative features of expressive rule-based
                         and efficiency of modern databases, offering a promising                                                 languages with aggregation. Logica is a descendant of Yeda-
                         new path for tackling graph transformation challenges.                                                   log [13] and inherits several of its features including support
                            This paper explores the application of Logica to the do-                                              for aggregators, functional predicates, user-defined func-
                         main of graph transformations, bridging the gap between                                                  tions, and complex data types. Logica also supports rules
                         these two paradigms. Our approach leverages Logica’s abil-                                               involving recursion and negation. A key feature of the im-
                         ity to process large datasets in a parallel and efficient man-                                           plementation is that it converts programs into SQL. This
                         ner, providing a novel means of implementing and execut-                                                 conversion can be configured by the user and rules can be
                         ing graph transformations at scale using logical rules. We                                               compiled into: (a) self-contained SQL scripts with fixed re-
                         demonstrate that with a graph transformation mindset, logic                                              cursion depth; or (b) Python-driven pipelines that chain
                         programming can provide a natural, powerful, and intuitive                                               together SQL queries when deep recursion is needed.
                         approach for defining transformations, opening new oppor-                                                   An overview of the Logica system is shown in Figure 1.
                         tunities within both communities. Crucially, Logica also                                                 Developers can work with Logica from the command line
                         enables a practical approach to addressing issues that are                                               or via a Jupyter notebook. Programs can import functions
                                                                                                                                  and other rules via a module system. Logica parses and
                          Published in the Proceedings of the Workshops of the EDBT/ICDT 2025                                     analyzes program files and produces a collection of SQL
                          Joint Conference (March 25-28, 2025), Barcelona, Spain                                                  queries in the dialect of the target database engine (cur-
                          $ evgenys@google.com (E. Skvortsov); yilinx2@illinois.edu (Y. Xia);
                                                                                                                                  rently SQLite, DuckDB, PostgreSQL, or BigQuery). To help
                          ludaesch@illinois.edu (B. Ludäscher); bowers@gonzaga.edu
                          (S. Bowers)                                                                                             manage differences among platforms, Logica employs a type
                                   Copyright © 2025 for this paper by its authors. Use permitted under Creative Commons License
                                   Attribution 4.0 International (CC BY 4.0).
                                                                                                                                  inference engine to create correct SQL for each underlying

CEUR
                  ceur-ws.org
Workshop      ISSN 1613-0073
Proceedings
                                                                                       Logica System
                                            Imported
                                             Imported
                                             Logica
                                                                 Logica                                                                       UI
                                              Logica




                       User’s File System
                                            Modules               Main                    Logica Parser            Type Inference Engine
                                             Modules
                                                                Program


                                                                shallow or non-                    Logica Program Compiler
                                              SQL               recursive rules
                                             Script
                                                                                             Rule Compiler             Expression Compiler
                                                                                                                                                   External DB Engines
                                                           Embedded DBs
                                                                                                  deep recursion

                                            DuckDB              SQLite                                                                                PostgreSQL
                                                                                          Logica Pipeline Object (SQL-query iteration)

                                                                                  Qi                                                         Qi
                                             CSV        JSON       Parquet
                                             File        File        File                       Logica Pipeline Driver (Python)                         BigQuery




              Figure 1: Logica System Architecture (from [9]): Logica supports a module system for importing libraries (top left); users write
              programs locally (top left) or from within Jupyter notebooks (top right); programs are parsed, type checked (top middle), and compiled to a
              self-contained SQL script (no/limited recursion) or to an iterative plan of pipelined SQL-queries passed to a pipeline driver (bottom middle).
              Logica executes and monitors queries as they run on underlying SQL engines, either locally (bottom left) or externally (bottom right).



system. If the set of rules to be evaluated is non-recursive                                                       must include rules to preserve edges not involved in the
(or if the user has indicated via a directive that a fixed-depth,                                                  transformation (line 2).
non-iterative recursion is sufficient), a self-contained SQL
script is generated that can be directly executed. For pro-                                                        3.1. Message Passing
grams requiring deep recursion, Logica generates a pipeline
script that iteratively executes the generated SQL queries                                                         Our first example involves the simple passing of a message
stage-by-stage until a fixpoint or a user-defined termination                                                      along the directed edges of a graph, as described in [14].
condition is reached.
   For long-running queries, users can monitor rule execu-                                                         1    M0(0); # start node
                                                                                                                   2    # Rule 1: Message initialization.
tion in the Logica UI: predicate results are rendered as they
                                                                                                                   3    M(x) :- M=nil, M0(x);
are being evaluated, so the user knows which (iterated) re-                                                        4    # Rule 2: Message passing.
lations are still running. This information can also be saved                                                      5    M(y) :- M(x), E(x, y);
and used for logging and profiling program execution.                                                              6    # Rule 3: Message retention.
                                                                                                                   7    M(x) :- M(x), ~E(x, y);


3. Transforming Graphs with Logica                                                                                 Fact M0(0) states that initially the message is at node 0.
In Logica, as in Prolog and Answer-Set Programming,                                                                Rule 1 initializes the message relation M. It states that node
graphs can be naturally represented: Nodes are denoted                                                             x has a message M if it was specified as the initial node
using unique identifiers and edges are represented as facts                                                        in M0(x). Condition M=nil makes the rule fire (trigger)
about the nodes. Graphs can be represented as predicates                                                           only at the start of the recursive iteration. The message
with two or more positional arguments. For example, a sim-                                                         propagates from node x to its neighbors y through the Rule
ple directed graph can be represented as a binary relation                                                         2. Finally, Rule 3 requires the message of a node x to be
E(source,target ), where source and target are nodes con-                                                          retained if x has no outgoing edges.
nected by a directed edge. Additional graph data, e.g., node
or edge attributes, can be expressed using separate predi-                                                         3.2. Computing Distances in a Graph
cates or extra positional (in Logica also named) arguments.
For instance, a graph whose edges are assigned colors can                                                          Logica has native support for aggregation. Predicate level
be represented using a ternary predicate and facts of the                                                          aggregation is computed over the specified values of the
form E(source,target ,color ).                                                                                     fields of the defined predicate. The following Logica pro-
   Graph transformations can be implemented by defining                                                            gram computes the minimum distance D(x) of a node x
new predicates that depend on the original graph: e.g., given                                                      from a given Start node.
a graph with edges E, a new graph E2 extending E by adding
                                                                                                                   1    # Rule 1: Distance from the Start node is 0.
new edges between nodes that are separated by two “hops”                                                           2    D(Start()) Min= 0;
can be derived as follows.1                                                                                        3    # Rule 2: Triangle inequality.
                                                                                                                   4    D(y) Min= D(x) + 1 :- E(x,y);
    1   E2(x, z) :- E(x, y), E(y, z);
    2   E2(x, y) :- E(x, y);
                                                                                                                   Start() is used as a functional predicate: All Logica
                                                                                                                   relations have an additional “special attribute” (named
This simple example demonstrates an important aspect of
                                                                                                                   logica_value) to store and access a relation’s functional
defining graph transformations with logic rules. In native
                                                                                                                   value, i.e., its value when used syntactically as a function.
graph transformation languages users define how the graph
                                                                                                                   Here, Start() simply returns (a predefined) starting value.
changes, and edges not involved in the change remain. How-
                                                                                                                   Rule 1 assigns the distance 0 to the starting node, where
ever, when defining graph transformations logically, we
                                                                                                                   D(x) is also a functional predicate that returns the (mini-
                                                                                                                   mum) distance of a node x. Rule 2 computes the distance to
1
    In Logica, variables are lowercase, predicates are uppercase, “∼” is                                           a node y as at most one more than the distance to its prede-
    used for negation, and semicolons denote the end of rules.
cessor x. The Min= aggregation operator specifies that the         E(x,y,t0,t1) stating that there exists an edge from node
minimum distance will be taken among all possible paths.           x to y added to the graph between time moments t0 and
                                                                   t1. For simplicity we assume that time starts at moment 0,
3.3. Solving Win-Move Games                                        edges are transitioned instantly, and the start node is given
                                                                   as Start(). The following Logica program computes the
Win-Move is a two-player combinatorial game played on              earliest possible arrival time for each node.
a finite directed graph (representing a board) where nodes
represent positions and edges represent moves [15, 16]. Af-        1   # Rule 1: Starting condition.
ter choosing a starting position (node), the two players take      2   Arrival(Start()) Min= 0;

turns moving a game pebble along the edges of the graph.           3   # Rule 2: Traversal of an edge when edge exists.
                                                                   4   Arrival(y) Min= Greatest(Arrival(x),t0) :-
A player who cannot move loses the game. We propose to             5    E(x,y,t0,t1), Arrival(x) <= t1;
compute the solution to Win-Move games in a new way,
inspired by graph transformations. A concise formulation
of the game is given by the logic rule:                               Rule 1 sets the arrival time of the start node to 0 (the
                                                                   assumed initial time). Rule 2 considers edge transitions: if
          Win(x) :- Move(x,y), ~Win(y).                            we arrive at the source x of an edge before the edge expires
                                                                   (given by t1) then the arrival time of the edge’s target y
   A solution to the game can be computed using the 3-             is set to the larger (latest) of x’s arrival time and the time
valued well-founded semantics [17]. The moves of the game          t0 that the edge was added to the graph. Once the arrival
are given by the predicate Move. A game starting at node x         times are computed, additional rules can be easily added
is objectively won if there exists a (winning) move to some        to select specific (time aware) paths of the graph. Figure 2
y that is lost. Then, no matter how an opponent (Player II)
                                                                   gives an example of path finding over an evolving graph.
moves from y (assuming there is an outgoing move to begin          An initial graph (with nodes A, B, etc., and colored blue) is
with), Player I can always force a win after the opponent          given with edges labeled by their start and end times. The
has moved. The well-founded model assigns Win(x) the               start node A is shown in green. The computed arrival times
value true, false, and undefined if and only if x is objectively   are displayed as additional nodes (in yellow). The graph
won, lost, and drawn, respectively. In contrast, the 2-valued      in Figure 2 was created within Logica as further described
stable model semantics does not compute the desired game           below in Section 3.6.
solution: There can be 0, 1, or more stable models, none of
which may agree with the correct, well-founded solution.
Similarly, in Logica, the above rule cannot be used as-is.         3.5. Transitive Reduction of DAGs
   Looking at the problem through a graph-transformation           The transitive reduction [18] of a directed graph is a graph
lens, however, we can define a new predicate W(x,y), indi-         with the fewest possible edges that has the same reacha-
cating that the move from x to y is a winning move. Com-           bility as the original graph. For directed acyclic graphs
putation of W, from a graph transformation perspective,            (DAGs), the transitive reduction coincides with finding the
amounts to selecting a collection of winning moves. In             (unique) minimum equivalent subgraph, i.e., a proper sub-
Logica this can be specified with a single rule:                   graph with the fewest possible edges needed to maintain the
                                                                   same reachability relation as the original graph. While find-
1   W(x,y) :- Move(x,y), (Move(y,z1) => W(z1,z2));
                                                                   ing a minimum equivalent subgraph for (arbitrary) graphs
                                                                   with cycles is NP-complete, for DAGs, the problem can be
The rule says: A move from x to y is winning iff for every         solved in PTIME. The following Logica program computes
opponent move from y to some z1 there exists a move from           the transitive reduction TR(x,y) of a DAG given by the
z1 to z2 for Player I that is again winning! The logical           edge relation E(x,y). The program first computes the tran-
implication Move(y,z1) => W(z1,z2) is a shorthand for              sitive closure and then uses the transitive closure to remove
the nested negation ~(Move(y,z1), ~W(z1,z2)).                      redundant edges.
  The position values can now be derived from the winning
moves W. The source and target nodes x and y of a winning          1   # Rule 1: Transitive closure base case.
move are won and lost positions, respectively. Positions           2   TC(x,y) distinct:- E(x,y);
                                                                   3   # Rule 2: Transitive closure inductive step.
that are neither won nor lost are drawn:                           4   TC(x,y) distinct:- TC(x,z), TC(z,y);
                                                                   5   # Rule 3: Transitive reduction.
1   Won(x), Lost(y) :- W(x,y);
                                                                   6   TR(x,y) :- E(x,y), ~(E(x,z), TC(z,y));
2   Drawn(x) :- Position(x), ~Won(x), ~Lost(x);



Here, the unary predicate position is defined as the union            Rules 1 and 2 compute the transitive closure. Rule 3
of the domain and range of the Move relation:                      identifies edges E(x,y) in the original graph that cannot
                                                                   be bypassed by going to some other node and taking a
1   Position(x) :- x in [a,b], Move(a,b);                          transitive path from there. These edges are the essential
                                                                   edges needed to maintain reachability and make up the
                                                                   edges of the resulting transitive reduction graph TR.
3.4. Finding Paths in Evolving Graphs
                                                                   3.6. Rendering Graphs with Logica
Graphs that change over time [10, 11, 12] can be naturally
modeled and computed over in Logica, where time can repre-         One of the benefits of Logica is the convenience of render-
sented using extra positional arguments, named arguments,          ing graphs directly from predicate definitions. With just a
or as functional values. As a simple example, assume a             few lines of Logica code and a minimal Python wrapper, it
graph that changes over time is represented by the relation        is possible to generate visually appealing and informative
          Figure 2: Visualizing the solution of pathfinding in a dynamic graph. The time of existence is shown as labels on edges; the
          earliest possible time of arrival is shown via yellow nodes. Section 3.6 shows how such visualizations can be created in Logica.



graph representations that highlight case-specific attributes.          different values from different rules. The Max= indicates
For example, consider the transitive reduction computed                 that if there are multiple rules that apply to the same edge,
in the previous section. Instead of exporting the TR and                the maximum value will be used. The actual rendering is
E predicates and configuring their rendering in a separate              then handled with a Python function call:
graphing library, Logica makes it possible to define a predi-
cate that directly specifies the visual attributes of the graph.         1   # from logica.common import graph
The following relations define graph visualization proper-               2   graph.SimpleGraph(
                                                                         3    R, extra_edges_columns=[
ties in Logica highlighting the edges in both the original               4      "arrows" ,"physics" ,"dashes" ,"smooth" ],
graph and its transitive reduction:                                      5    edge_color_column="color" ,
                                                                         6    edge_width_column="width" )
 1   R(x, y,
 2    arrows:"to" ,
 3    color?Max= "rgba (40, 40, 40, 0.5)",                                 This code leverages Logica’s graph module. The
 4    dashes?Min= true,                                                 SimpleGraph function takes the R predicate, speci-
 5    width?Max= 2,
                                                                        fies which columns in R represent edge attributes (us-
 6    physics?Max= false,
 7    smooth?Max= false)distinct:- E(x, y);
                                                                        ing extra_edges_columns, edge_color_column, and
 8   R(x, y,                                                            edge_width_column), and provides overall graph options.
 9    arrows:"to" ,                                                     The resulting visualization is shown in Figure 3 (where
10    color?Max= "rgba (90, 30, 30, 1.0)",                              the transitive reduction graph is overlaid over the original
11    dashes?Min= false,
                                                                        graph). The tight integration between logical definitions
12    width?Max= 4,
13    physics?Max= true,
                                                                        and graph rendering makes Logica a powerful tool for ana-
14    smooth?Max= true)distinct:- TR(x, y);                             lyzing and understanding complex relationships in graph
                                                                        data. The ability to define graph properties directly in Log-
                                                                        ica, rather than relying on external tools, can significantly
   The R(x,y,. . . ) relation defines the edges of the graph            streamline the data exploration and visualization process.
and their visual properties. The first rule draws the origi-
nal edges from E(x, y) in a light gray, dashed style with
a thin line. The second rule draws the transitive reduc-                3.7. Graph Condensation
tion edges from TR(x, y) in bold red, solid lines. The                  Graph condensation [19] is a technique for simplifying a
distinct keyword triggers aggregation, so that each edge                graph by collapsing strongly connected components (SCCs)
occurs only once and values of attributes such as color,                into single nodes. This can be useful for visualizing the
dashes, etc., are chosen based on whether this edge be-                 overall structure of a graph and for performing analyses
longs to the transitive reduction. The visual attributes, e.g.,         that are less sensitive to the details within SCCs. In the
arrows, color, dashes, width, physics, and smooth,                      condensed graph, each node represents an SCC, and an
are directly embedded within the Logica rules. The question             edge exists between two nodes if there is an edge in the
mark in “color? Max=” indicates that the color can have                 original graph between nodes in the corresponding SCCs.
           Figure 3: Visualizing a transitive reduction with Logica: Original edges are displayed with dashed lines, while edges present
           in the transitive reduction are highlighted with solid lines. This visualization, generated directly from Logica predicates, shows
           how the transitive reduction simplifies the graph while preserving reachability.



   The following Logica program computes the condensa-                    • Edges in the original graph (defined by E) are rendered
tion of a graph given by edges defined by the E(x,y) rela-                  as solid blue lines.
tion, and where all nodes are defined by a Node(x) predi-                 • Edges between components (defined by ECC) are also
cate. We assume that transitive closure is already computed                 rendered as solid blue lines.
as in Subsection 3.5.                                                     • Dashed gray lines connect each original node to its cor-
                                                                            responding component. The physics is disabled between
 1   # Minimal node ID of the component
 2   # ..is used as the component ID.
                                                                            nodes and their condensation components to help with
 3   CC(x) Min= x :- Node(x);                                               readability.
 4   CC(x) Min= y :- TC(x,y), TC(y,x);
 5   # Compute condensation graph edges.                                  Figure 4 shows the result of using the above Logica code
 6   ECC(CC(x),CC(y)) distinct:-                                          and the appropriate Python wrapper as described in Subsec-
 7    E(x,y), CC(x)!=CC(y);                                               tion 3.6 to view the original and corresponding condensed
                                                                          graph. By combining the power of Logica for defining graph
   Once the condensation is computed, it can be easily ren-               structures and relationships with its seamless graph render-
dered using Logica’s graph visualization capabilities. To                 ing capabilities, it is possible to gain valuable insights into
enhance readability, we use the following naming conven-                  complex systems through clear and concise visualizations.
tions: nodes in the original graph are named directly with
their IDs (e.g., “1”, “2”, “3”), while the condensed compo-               3.8. Inferring a Taxonomic Tree
nents are prefixed with “c-” (e.g., “c-1”, “c-2”). The predicate
definitions for rendering both the original and condensed                 Another application of Logica lies in its ability to infer
graphs simultaneously are as follows:                                     relationships from large datasets and represent them as
                                                                          graphs. Consider the problem of constructing a simplified
 1   NodeName(x) = ToString(ToInt64(x));                                  taxonomic tree for a set of species, showing their evolu-
 2   CompName(x) = "c-"++ ToString(ToInt64(x));                           tionary relationships leading back to common ancestors.
 3
                                                                          Logica can perform this task on massive amounts of data.
 4   # Edges of the original graph.
 5   Render(NodeName(a), NodeName(b),
                                                                          Here, we aim to build a taxonomic tree for Homo sapiens
 6        physics:true,arrows:"to" ,                                      (humans), Crocodylidae (crocodiles), Tyrannosaurus (T-Rex),
 7        dashes:false,smooth:true,                                       and Columbidae (pigeons). The input is a knowledge graph
 8        color:"#33e"):- E(a, b);                                        of triples T(𝑎,𝑏,𝑐) and a functional predicate L(𝑎) = ℓ
 9   # Edges of the condensation.
                                                                          that maps objects 𝑎 to human readable labels ℓ. We de-
10   Render(CompName(x), CompName(y),
11        physics:true,arrows:"to" ,
                                                                          fine SuperTaxon(item,parent) as the result of the query
12        dashes:false,smooth:true,                                       T(item,"P171",parent), which states that parent is a direct
13        color:"#33e"):- ECC(x, y);                                      supertaxon of item, and TaxonLabel(𝑥) = L(𝑥) to give la-
14   # Mapping from the graph to                                          bels restricted to taxons. The following Logica program
15   # the condensation.
                                                                          builds the taxonomic tree.
16   Render(NodeName(ToInt64(a)), CompName(CC(a)),
17        physics:false,arrows:"to" ,
                                                                           1   # Use unbounded depth (-1) to find ancestors.
18        dashes:true,smooth:false,
                                                                           2   @Recursive(E, -1, stop: FoundCommonAncestor);
19        color:"#888");
                                                                           3   E(x, item,
                                                                           4    TaxonLabel(x), TaxonLabel(item)) distinct:-
The NodeName and CompName functions convert node and                       5    SuperTaxon(item,x),
                                                                           6    ItemOfInterest(item) | E(item);
component IDs to strings with appropriate prefixes. The
Render predicate then defines the appearance of the graph:
              Figure 4: Graph Condensation visualized with Logica. This figure displays both the original graph and its condensed
              representation. Solid blue lines represent edges within the original graph and between condensed components. Dashed gray
              lines connect each node to its corresponding condensed component, illustrating how strongly connected components are
              collapsed into single nodes. This condensation simplifies the graph while preserving high-level connectivity information.




              Figure 5: Inferred Taxonomic Tree for humans, crocodiles, T-Rex, and pigeons, generated by a Logica program from a large
              Wikidata dump. Edges represent evolutionary relationships, leading from an ancestral species to descendant species. This
              demonstrates that Logica can operate on very large, real-world knowledge graphs.



    7   NumRoots() += 1 :- E(x,y), ~E(z,x);                             4. Conclusion
    8   # Stop when common ancestor is found.
    9   FoundCommonAncestor() :- NumRoots() = 1;                        We have presented a novel approach to implementing graph
                                                                        transformations using Logica, a free and open-source logic
   Figure 5 shows an example output from running the pro-               programming language designed for parallel databases.
gram, where the GraphViz2 library is used to render the                 While Logica is typically used for data processing and anal-
resulting tree. The input for the example consisted of the set          ysis, we have shown that it can also effectively be used for
of statements obtained by a dump of Wikidata, which con-                graph transformations. By leveraging Logica’s ability to pro-
tained 806M facts defined over 89M objects. When stored us-             cess large datasets in a parallel and efficient manner, graph
ing DuckDB, the entire input is 13GB in size. The full recur-           transformations can be performed efficiently. By showcas-
sive search was run on a Google Cloud c2d-standard-32                   ing several examples, including the Win-Move problem,
instance in under 7 seconds via DuckDB with no custom                   dynamic path finding, transitive reduction, graph conden-
index setup. The majority of the execution time was spent               sation, and graph querying, we demonstrated that graph
selecting the taxonomy edges from all possible relations in             transformation problems can be expressed in an intuitive
Wikidata. Note that the number of taxons returned by the                and efficient manner. The examples show how describing
original program is large. The result shown in Figure 5 is              graph transformations using logic rules can lead to con-
only a sample of the obtained taxonomic tree (where the                 cise declarative specifications that also improve readability.
sampling is also performed by Logica; not shown above).                 For example, our approach models time-varying graphs in
   By expressing the problem in Logica, we leverage its abil-           a principled manner, an issue that can be challenging in
ity to efficiently perform (recursive) query processing (e.g.,          classical graph transformation languages.
through its compilation to DuckDB). In this case, Logica is                In future work, we plan to explore more complex graph
used to quickly navigate the complex relationships within               transformation patterns, including rewritings that may re-
a large taxonomic database and generate output that can                 quire solving NP-hard problems. We also plan to bench-
then be displayed visually through its Python integration               mark our approach against other graph transformation tools,
(here, using the GraphViz library).                                     which would be valuable for demonstrating Logica’s perfor-
                                                                        mance advantages on real-world datasets.
                                                                           We hope that Logica, with its ability to leverage underly-
                                                                        ing SQL engines, can make graph transformations a more
                                                                        widely accessible and practical approach for managing com-
2
    https://graphviz.org/                                               plex and dynamic data.
References                                                          Reduction of a Directed Graph, SIAM Journal on Com-
                                                                    puting 1 (1972) 131–137.
 [1] F. de la Parra, T. Dean, Survey of graph rewriting        [19] R. Tarjan, Depth-First Search and Linear Graph Algo-
     applied to model transformations, in: International            rithms, SIAM Journal on Computing 1 (1972) 146–160.
     Conference on Model-Driven Engineering and Soft-
     ware Development, 2014, pp. 431–441.
 [2] T. Kräuter, A. Rutle, H. König, Y. Lamo, Formalization
     and Analysis of BPMN Using Graph Transformation
     Systems, in: International Conference on Graph Trans-
     formation, 2023, p. 204–222.
 [3] M. Fernández, H. Kirchner, B. Pinaud, J. Vallet, La-
     belled Graph Rewriting Meets Social Networks, in:
     International Workshop on Rewriting Logic and Its
     Applications, volume 9942 of LNCS, Springer, 2016, pp.
     1–25.
 [4] F. Rosselló, G. Valiente, Graph Transformation in
     Molecular Biology, Springer, 2005, pp. 116–133.
 [5] M. Nagl, Graph rewriting systems and their applica-
     tion in biology, in: Mathematical Models in Medicine,
     Springer, 1976, pp. 135–156.
 [6] F. Rosselló, G. Valiente, Chemical Graphs, Chemi-
     cal Reaction Graphs, and Chemical Graph Transfor-
     mation, Electronic Notes in Theoretical Computer
     Science 127 (2005) 157–166. Proceedings of the Inter-
     national Workshop on Graph-Based Tools.
 [7] M. Gelfond, Answer Sets, in: F. van Harmelen, V. Lif-
     schitz, B. W. Porter (Eds.), Handbook of Knowledge
     Representation, volume 3 of Foundations of Artificial
     Intelligence, Elsevier, 2008, pp. 285–316.
 [8] E. S. Skvortsov, Y. Xia, B. Ludäscher, Logica: Declara-
     tive Data Science for Mere Mortals, in: International
     Conference on Extending Database Technology, 2024,
     pp. 842–845.
 [9] E. S. Skvortsov, Y. Xia, S. Bowers, B. Ludäscher, The
     Logica System: Elevating SQL Databases to Declara-
     tive Data Science Engines, in: International Workshop
     on the Resurgence of Datalog in Academia and In-
     dustry (Datalog-2.0), volume 3801 of CEUR Workshop
     Proceedings, 2024, pp. 69–73.
[10] D. Kempe, J. Kleinberg, A. Kumar, Connectivity and
     inference problems for temporal networks, J. Comput.
     Syst. Sci. 64 (2002) 820–842.
[11] F. Rosselló, G. Valiente, Graph Transformation in
     Molecular Biology, Springer, 2005, pp. 116–133. URL:
     https://doi.org/10.1007/978-3-540-31847-7_7.
[12] A. Casteigts, A.-S. Himmel, H. Molter, P. Zschoche,
     Finding Temporal Paths Under Waiting Time Con-
     straints, Algorithmica 83 (2021) 2754–2802.
[13] B. Chin, D. von Dincklage, V. Ercegovac, P. Hawkins,
     M. Miller, et al., Yedalog: Exploring knowledge at
     scale, Summit on Advances in Programming Lan-
     guages (2015).
[14] B. König, Graph Transformation Meets Logic, GReTA -
     Graph Transformation Theory and Applications Sym-
     posium, 2020.
[15] C. A. Smith, Graphs and composite games, Journal of
     Combinatorial Theory 1 (1966) 51–81.
[16] J. Flum, M. Kubierschky, B. Ludäscher, Total and Par-
     tial Well-Founded Datalog Coincide, in: Intl. Conf. on
     Database Theory (ICDT), LNCS 1186, Springer, 1997,
     pp. 113–124.
[17] A. Van Gelder, K. A. Ross, J. S. Schlipf, The Well-
     founded Semantics for General Logic Programs, Jour-
     nal of the ACM 38 (1991) 619–649.
[18] A. V. Aho, M. R. Garey, J. D. Ullman, The Transitive