FlexRiLoG – A SageMath Package for Motions of Graphs

by   Georg Grasegger, et al.

In this paper we present the SageMath package FlexRiLoG (short for flexible and rigid labelings of graphs). Based on recent results the software generates motions of graphs using special edge colorings. The package computes and illustrates the colorings and the motions. We present the structure and usage of the package.



There are no comments yet.


page 1

page 2

page 3

page 4


Gasper: GrAph Signal ProcEssing in R

We present a short tutorial on to the use of the R gasper package. Gaspe...

The R Package stagedtrees for Structural Learning of Stratified Staged Trees

stagedtrees is an R package which includes several algorithms for learni...

DiscreteZOO: a Fingerprint Database of Discrete Objects

In this paper, we present DiscreteZOO, a project which illustrates some ...

A Computer Algebra Package for Polynomial Sequence Recognition

The software package developed in the MS thesis research implements func...

Studying Wythoff and Zometool Constructions using Maple

We describe a Maple package that serves at least four purposes. First, o...

Variational B-rep Model Analysis for Direct Modeling using Geometric Perturbation

The very recent CAD paradigm of direct modeling gives rise to the need o...

Good distribution modelling with the R package good

Although models for count data with over-dispersion have been widely con...

Code Repositories


SageMath package for studying Flexible and Rigid Labelings of Graphs

view repo
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

A graph with a placement of its vertices in the plane is considered to be flexible if the placement can be continuously deformed by an edge length preserving motion into a non-congruent placement. The study of such graphs and their motions has a long history (see for instance [1, 4, 10, 11, 13, 14, 15, 16]). Recently we provided a series of results [7, 8] with a deeper analysis of the existence of flexible placements. This is done via special edge colorings called NAC-colorings (“No Almost Cycles”, see [7]

). These colorings classify the existence of a flexible placement in the plane and give a construction of the motion.

Basic definitions. We briefly give a more precise definition of flexibility of a graph. A framework is a pair where is a graph and is a placement of in . The placement might be possibly non-injective but for all edges we require .

Two frameworks and are equivalent if for all ,


Two placements of are said to be congruent if (1) holds for all pairs of vertices . Equivalently, and are congruent if there exists a Euclidean isometry  of such that for all .

A flex of the framework is a continuous path , , in the space of placements of such that and each is equivalent to . The flex is called trivial if is congruent to for all .

We define a framework to be flexible if there is a non-trivial flex in . Otherwise is is called rigid. We say that a labeling of a graph  is flexible if there is a flexible framework such that induces , namely, for all . On the other hand, is rigid if is rigid for all placements inducing . A flexible labeling of a graph is proper if there exists a framework such that induces and it has a non-trivial flex with all but finitely many placements being injective. We call a graph movable if it has a proper flexible labeling.

Outline of the paper. We have given the necessary definitions. Section 2 describes the main functionality of the FlexRiLoG dealing with colorings and motions. In this paper we do not provide the algorithms themselves but refer to the respective theorems and literature. In Section 3 we describe how to use the package to ask for movable graphs.

2 The Package

FlexRiLoG [5] is a package for SageMath running in versions 8.9 and 9.0 [12]. The latest release of the package can be installed by executing: sage -pip install –upgrade flexrilog The development version of FlexRiLoG can be found in the repository [6], where also other options of installation are described.

A convenient way of using the package instead of the sage console is a Jupyter notebook (coming with SageMath, launch by sage -n jupyter). The Jupyter notebook examples/flexrilog_Motions_of_Graphs.ipynb in [6] provides an interactive version of this paper.

The package allows to check whether a graph has a NAC-coloring, in particular to list all of them. A motion or flex obtained from a NAC-coloring can be constructed and displayed. Moreover, it implements the results of [8] regarding the existence of proper flexible labelings, namely, the check of a necessary condition and construction of a proper flex from a pair of NAC-colorings. There is also functionality providing tools for classification of all proper flexible labeling, which is out of the scope of this paper (see [9] for details).

2.1 Data Types

The package provides data types in different classes for dealing with graphs, colorings and motions. In order to use the data types provided by the package, they have to be loaded. from flexrilog import FlexRiGraph, GraphMotion The main object will always be of type FlexRiGraph. This class inherits properties of the standard Graph from SageMath and adds specific properties for investigations of flexibility and rigidity. In this paper we focus on the flexibility part. A FlexRiGraph can be constructed by the following command. FlexRiGraph([[0,1],[1,2],[0,2]]) *FlexRiGraph with the vertices [0, 1, 2] and edges [(0, 1), (0, 2), (1, 2)] Further constructions can be made via integer encoding described in [2] and via objects of the standard Graph class. FlexRiGraph(graphs.CompleteBipartiteGraph(2,3)) *Complete bipartite graph of order 2+3: FlexRiGraph with the vertices [0, 1, 2, 3, 4] *and edges [(0, 2), (0, 3), (0, 4), (1, 2), (1, 3), (1, 4)]

Besides the class for graphs there is a class for colorings (NACcoloring). We do not discuss the class itself here but rather show how to compute colorings of graphs (see Section 2.2). Furthermore, motions are stored in a third class, GraphMotion. They are discussed in Section 2.3. The GraphGenerator class stores the code for some important graphs from the area of rigidity and flexibility theory. We do not go into detail but some of the graphs are used in the paper.

2.2 NAC-Colorings

NAC-colorings are a special type of edge colorings using two colors. Unlike proper edge colorings in Graph Theory we do not require incident edges to have different colors.

Definition 1.

Let  be a graph. A coloring of edges is called a NAC-coloring, if it is surjective and for every cycle in , either all edges have the same color, or there are at least 2 edges in each color.

FlexRiLoG contains functionality for computing and showing NAC-colorings of a given graph. The standard output is a textual list but the colorings can be shown in figures as well. C4 = FlexRiGraph([[0,1],[1,2],[2,3],[0,3]]) C4.NAC_colorings() *[NAC-coloring with red edges [[0, 1], [0, 3]] and blue edges [[1, 2], [2, 3]], * NAC-coloring with red edges [[0, 1], [1, 2]] and blue edges [[0, 3], [2, 3]], * NAC-coloring with red edges [[0, 1], [2, 3]] and blue edges [[0, 3], [1, 2]]] C4.show_all_NAC_colorings()
In order to compute all NAC-colorings, lists of edges that necessarily have the same color due to being in 3-cycles (so called -connected components, see [7]) are determined. So far, we then test all possible combinations how to color them by red and blue [7, Lemma 2.4]. The edges colored the same in the following picture must have the same color in any NAC-coloring, but no combination satisfies the conditions of NAC-coloring. from flexrilog import GraphGenerator N = GraphGenerator.NoNACGraph() N.has_NAC_coloring() *False N.plot(show_triangle_components=True)

For graphs with symmetries we get many similar colorings, in a sense that after applying the symmetry one NAC-coloring yields the other. We call such NAC-colorings isomorphic. In order to visualize this, NAC-colorings can be named so that isomorphic ones have the same Greek letter but differ by their index. C4.set_NAC_colorings_names() C4.NAC_colorings_isomorphism_classes() *[[alpha1: NAC-coloring with red edges [[0, 1], [0, 3]] and blue edges [[1, 2], [2, 3]], * alpha2: NAC-coloring with red edges [[0, 1], [1, 2]] and blue edges [[0, 3], [2, 3]]], * [beta: NAC-coloring with red edges [[0, 1], [2, 3]] and blue edges [[0, 3], [1, 2]]]]

2.3 Constructing Motions

Given a NAC-coloring we are able to construct a motion. The following result from [7] describes the relation.

Theorem 2.

A connected non-trivial graph has a flexible labeling if and only if it has a NAC-coloring.

The main idea to construct a flex is to place the vertices on a grid in such a way that all the edges lie on grid lines. This can be achieved by placing vertices according to the color component of the graph. For color components we remove all edges of the other color and then take connected components of the remaining graph. Then all vertices which lie in the same red component are placed in the same column of the grid and all vertices from the same blue component are placed in the same row of the grid. By this procedure each vertex is assigned a unique grid point and all edges of the graph lie on the grid lines. In FlexRiLoG this can be done with the classmethod GraphMotion.GridConstruction. from flexrilog import GraphMotion, GraphGenerator P = GraphGenerator.ThreePrismGraph() delta = P.NAC_colorings()[0] motion_P = GraphMotion.GridConstruction(P, delta) motion_P.parametrization() *0: (0, 0), * 1: (sin(alpha) + 1, cos(alpha)), * 2: (2*sin(alpha) + 1, 2*cos(alpha)), * 3: (2*sin(alpha), 2*cos(alpha)), * 4: (sin(alpha), cos(alpha)), * 5: (1, 0) There is also the option to generate an animated SVG showing the NAC-coloring, which is automatically displayed when used in a Jupyter notebook (the picture below is a screenshot). If the fileName is specified, the SVG animation is stored and a web browser can be used to view it. Note that not all web browsers support SVG animations. It can be chosen, whether the edges are colored according to the NAC-coloring in use. The package also distinguishes the vertex layout depending on whether it is drawing a graph having no specific placement properties (dark vertices), or drawing a motion, in which edge lengths are fixed (light vertices). motion_P.animation_SVG(edge_partition="NAC", . fileName="3-prism_grid")
More generally the base points of the grid can be chosen arbitrarily to get a zig-zag grid. This can be used to avoid degenerate subgraphs. Base points consist of two lists. The standard values consists of lists with points and respectively. Using them we get a rectangular initial grid. A zig-zag grid in general does not need to be initially rectangular. It is uniquely determined by the base points and drawing parallel lines. Doing so the grid consists of parallelograms. Usually the grid itself is not easily visible from the output motion. motion_P = GraphMotion.GridConstruction(P, delta, . zigzag=[[[0,0], [3/4,1/2], [2,0]], . [[0,0], [1,0]]]) motion_P.animation_SVG(edge_partition="NAC")

3 Movable graphs

Using the grid construction, non-adjacent vertices might overlap, i.e., the constructed framework is not proper. Note, that this cannot be avoided by zig-zag constructions either but depends solely on the NAC-coloring in use. For some graphs all NAC-colorings result in overlapping vertices. In FlexRiLoG it can be checked whether this is the case. P.has_injective_grid_construction() *True Q1 = GraphGenerator.Q1Graph() # see the picture below Q1.has_injective_grid_construction() *False For some graphs, a proper flexible labeling exists due to the following lemma [8], which relates movability to spatial embeddings.

Lemma 1.

Let be a graph with an injective embedding such that for every edge

, the vector

is parallel to one of the four vectors , , , , and all four directions are present. Then is movable. Moreover, there exist two NAC-colorings of such that two edges are parallel in the embedding if and only if they receive the same pair of colors.

The package tries to construct such a spatial embedding for all pairs of NAC-colorings. inj, nacs = Q1.has_injective_spatial_embedding( . certificate=True); inj *True graphics_array([d.plot() for d in nacs])

From the spatial embedding we can construct a motion of the graph. The motion can be transformed in such a way that a particular edge is fixed. motion_Q1 = GraphMotion.SpatialEmbeddingConstruction(Q1, nacs) motion_Q1.fix_edge([5,6]) motion_Q1.parametrization() *1: ((3*t^2 - 3)/(t^2 + 1), -6*t/(t^2 + 1)), * 2: ((t^4 + 23*t^2 + 4)/(t^4 + 5*t^2 + 4), (6*t^3 - 12*t)/(t^4 + 5*t^2 + 4)), * 3: ((4*t^2 - 2)/(t^2 + 1), -6*t/(t^2 + 1)), * 4: (18*t^2/(t^4 + 5*t^2 + 4), (6*t^3 - 12*t)/(t^4 + 5*t^2 + 4)), * 5: (0, 0), * 6: (2, 0), * 7: (1, 0) motion_Q1.animation_SVG()

Besides the sufficient condition on movability above, there is also a necessary condition given in [8]. For this condition we consider all NAC-colorings and look for monochromatic paths. Adding certain edges according to these paths we get a bigger graph with similar movability properties.

For a graph , let denote the set of all pairs such that and there exists a path from to which is monochromatic for all NAC-colorings  of . If there exists a sequence of graphs such that , for , and , then the graph is called the constant distance closure of , denoted by .

Theorem 3.

A graph is movable if and only if is movable. Particularly, if is the complete graph, then is not movable.

We can see that the following graph is not movable ( has no NAC-coloring since , hence, are all non-edges of ). G = GraphGenerator.MaxEmbeddingsLamanGraph(7) G.show_all_NAC_colorings()
G.constant_distance_closure().is_complete() *True


We gave a brief overview of the package and therefore did not cover all functionality. The package contains a documentation. As research in the field of flexible and movable graphs is going on the package is further developed, both regarding improvements as well as new functionality (for instance -fold rotationally symmetric frameworks, see [3]). The most current version of FlexRiLoG can be found in [6].


This project was supported by the Austrian Science Fund (FWF): P31061, P31888 and W1214-N15, and by the Ministry of Education, Youth and Sports of the Czech Republic, project no. CZ.02.1.01/0.0/0.0/16_019/0000778. The project has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement No 675789.