HOME

TheInfoList



OR:

In
mathematics Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
,
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
and
digital electronics Digital electronics is a field of electronics involving the study of digital signals and the engineering of devices that use or produce them. It deals with the relationship between Binary number, binary inputs and outputs by passing electrical s ...
, a dependency graph is a directed graph representing dependencies of several objects towards each other. It is possible to derive an evaluation order or the absence of an evaluation order that respects the given dependencies from the dependency graph.


Definition

Given a set of objects S and a
transitive relation In mathematics, a binary relation on a set (mathematics), set is transitive if, for all elements , , in , whenever relates to and to , then also relates to . Every partial order and every equivalence relation is transitive. For example ...
R \subseteq S \times S with (a,b) \in R modeling a dependency "''a'' depends on ''b''" ("''a'' needs ''b'' evaluated first"), the dependency graph is a graph G = (S, T) with T \subseteq R the
transitive reduction In the mathematical field of graph theory, a transitive reduction of a directed graph is another directed graph with the same vertices and as few edges as possible, such that for all pairs of vertices , a (directed) path from to in exists ...
of ''R''. For example, assume a simple calculator. This calculator supports assignment of constant values to variables and assigning the sum of exactly two variables to a third variable. Given several equations like "''A'' = ''B''+''C''; ''B'' = 5+''D''; ''C''=4; ''D''=2;", then S=\ and R=\. You can derive this relation directly: ''A'' depends on ''B'' and ''C'', because you can add two variables
if and only if In logic and related fields such as mathematics and philosophy, "if and only if" (often shortened as "iff") is paraphrased by the biconditional, a logical connective between statements. The biconditional is true in two cases, where either bo ...
you know the values of both variables. Thus, ''B'' must be calculated before ''A'' can be calculated. Since ''B'' depends on ''D'' to be calculated, ''A'' must also depend on ''D'' to be calculated before it (hence the transitive property stated above). On the other hand, the values of ''C'' and ''D'' are known immediately, because they are number literals.


Recognizing impossible evaluations

In a dependency graph, cycles of dependencies (also called circular dependencies) lead to a situation in which no valid evaluation order exists, because none of the objects in the cycle may be evaluated first. If a dependency graph does not have any circular dependencies, it forms a
directed acyclic graph In mathematics, particularly graph theory, and computer science, a directed acyclic graph (DAG) is a directed graph with no directed cycles. That is, it consists of vertices and edges (also called ''arcs''), with each edge directed from one ...
, and an evaluation order may be found by topological sorting. Most topological sorting algorithms are also capable of detecting cycles in their inputs; however, it may be desirable to perform
cycle detection In computer science, cycle detection or cycle finding is the algorithmic problem of finding a cycle in a sequence of iterated function values. For any function that maps a finite set to itself, and any initial value in , the sequence of ite ...
separately from topological sorting in order to provide appropriate handling for the detected cycles. Assume the simple calculator from before. The equation system "''A''=''B''; ''B''=''D''+''C''; ''C''=''D''+''A''; ''D''=12;" contains a
circular dependency In software engineering, a circular dependency is a relation between two or more modules which either directly or indirectly depend on each other to function properly. Such modules are also known as mutually recursive. Overview Circular depend ...
formed by ''A'', ''B'' and ''C'', as ''B'' must be evaluated before ''A'', ''C'' must be evaluated before ''B'', and ''A'' must be evaluated before ''C''.


Deriving an evaluation order

A correct evaluation order is a numbering n : S \rightarrow \mathbb of the objects that form the nodes of the dependency graph so that the following equation holds: n(a) < n(b) \Rightarrow (a, b) \notin R with a, b \in S. This means, if the numbering orders two elements a and b so that a will be evaluated before b, then a must not depend on b. There can be more than one correct evaluation order. In fact, a correct numbering is a
topological order In physics, topological order describes a state or phase of matter that arises system with non-local interactions, such as entanglement in quantum mechanics, and floppy modes in elastic systems. Whereas classical phases of matter such as gases an ...
, and any topological order is a correct numbering. Thus, any algorithm that derives a correct topological order derives a correct evaluation order. Assume the simple calculator from above once more. Given the equation system "''A'' = ''B''+''C''; ''B'' = 5+''D''; ''C''=4; ''D''=2;", a correct evaluation order would be (''D'', ''C'', ''B'', ''A''). However, (''C'', ''D'', ''B'', ''A'') is a correct evaluation order as well.


Monoid structure

An acyclic dependency graph corresponds to a trace of a
trace monoid In computer science, a trace is an equivalence class of strings, wherein certain letters in the string are allowed to commute, but others are not. Traces generalize the concept of strings by relaxing the requirement for all the letters to have a d ...
as follows: * A function \phi : S \to \Sigma labels each vertex with a symbol from the alphabet \Sigma * There is an edge a \to b or b \to a if and only if (\phi(a),\phi(b)) is in the
dependency relation In computer science, in particular in concurrency theory, a dependency relation is a binary relation on a finite domain \Sigma, symmetric, and reflexive; i.e. a finite tolerance relation. That is, it is a finite set of ordered pairs D, such t ...
D. * Two graphs are considered to be equal if their labels and edges correspond. Then the string consisting of the vertex labels ordered by a correct evaluation order corresponds to a string of a trace. The
monoid In abstract algebra, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being . Monoids are semigroups with identity ...
al operation (S_,R_)=(S_1,R_1)\bullet (S_2,R_2) takes the
disjoint union In mathematics, the disjoint union (or discriminated union) A \sqcup B of the sets and is the set formed from the elements of and labelled (indexed) with the name of the set from which they come. So, an element belonging to both and appe ...
S_=S_1 \sqcup S_2 of two graphs' vertex sets, preserves the existing edges in each graph, and draws new edges from the first to the second where the dependency relation allows, :R_ = R_1 \sqcup R_2 \sqcup \ The identity is the empty graph.


Examples

Dependency graphs are used in: * Automated software
installer Installation (or setup) of a computer program (including device drivers and plugins), is the act of making the program ready for execution. Installation refers to the particular configuration of software or hardware with a view to making it usabl ...
s: They walk the graph looking for software packages that are required but not yet installed. The dependency is given by the
coupling A coupling is a device used to connect two shafts together at their ends for the purpose of transmitting power. The primary purpose of couplings is to join two pieces of rotating equipment while permitting some degree of misalignment or end mo ...
of the packages. * Software build scripts such as
Unix Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
Make,
Node In general, a node is a localized swelling (a "knot") or a point of intersection (a vertex). Node may refer to: In mathematics * Vertex (graph theory), a vertex in a mathematical graph *Vertex (geometry), a point where two or more curves, lines ...
npm install, php composer,
Twitter Twitter, officially known as X since 2023, is an American microblogging and social networking service. It is one of the world's largest social media platforms and one of the most-visited websites. Users can share short text messages, image ...
bower install, or
Apache Ant Apache Ant is a software tool for automating software build processes for Java applications which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implement ...
. They need to know what files have changed so only the correct files need to be recompiled. * In
compiler In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
technology and
formal language In logic, mathematics, computer science, and linguistics, a formal language is a set of strings whose symbols are taken from a set called "alphabet". The alphabet of a formal language consists of symbols that concatenate into strings (also c ...
implementation: **
Instruction scheduling In computer science, instruction scheduling is a compiler optimization used to improve instruction-level parallelism, which improves performance on machines with instruction pipelines. Put more simply, it tries to do the following without changing ...
: Dependency graphs are computed for the operands of assembly or intermediate instructions and used to determine an optimal order for the instructions. **
Dead code elimination In compiler theory, dead-code elimination (DCE, dead-code removal, dead-code stripping, or dead-code strip) is a compiler optimization to remove dead code (code that does not affect the program results). Removing such code has several benefits: i ...
: If no side effected operation depends on a variable, this variable is considered dead and can be removed. * Dynamic graph analytics: GraphBolt and KickStarter capture value dependencies for
incremental computing Incremental computing, also known as incremental computation, is a software feature which, whenever a piece of data changes, attempts to save time by only recomputing those outputs which depend on the changed data. When incremental computing is su ...
when graph structure changes. *
Spreadsheet A spreadsheet is a computer application for computation, organization, analysis and storage of data in tabular form. Spreadsheets were developed as computerized analogs of paper accounting worksheets. The program operates on data entered in c ...
calculators. They need to derive a correct calculation order similar to that one in the example used in this article. * Web Forms standards such as
XForms XForms is an XML format used for collecting inputs from web forms. XForms was designed to be the next generation of HTML / XHTML forms, but is generic enough that it can also be used in a standalone manner or with presentation languages other tha ...
to know what visual elements to update if data in the model changes. * Video games, especially
puzzle A puzzle is a game, problem, or toy that tests a person's ingenuity or knowledge. In a puzzle, the solver is expected to put pieces together ( or take them apart) in a logical way, in order to find the solution of the puzzle. There are differe ...
and adventure video games, which are frequently designed as a graph of dependent relationships between in-game actions. Dependency graphs are one aspect of: * Manufacturing plant types: Raw materials are processed into products via several dependent stages. *
Job shop scheduling Job-shop scheduling, the job-shop problem (JSP) or job-shop scheduling problem (JSSP) is an optimization problem in computer science and operations research. It is a variant of optimal job scheduling. In a general job scheduling problem, we are gi ...
: A collection of related theoretical problems in computer science.


See also

*
Call graph A call graph (also known as a call multigraph) is a control-flow graph, which represents calling relationships between subroutines in a computer program. Each node represents a procedure and each edge ''(f, g)'' indicates that procedure ''f'' c ...
*
Precedence graph A precedence graph, also named conflict graph and serializability graph, is used in the context of concurrency control in databases. It is the directed graph representing precedence of transactions in the schedule, as reflected by precedence of con ...
* Topological sort *
Data dependency A data dependency in computer science is a situation in which a program statement (instruction) refers to the data of a preceding statement. In compiler theory, the technique used to discover data dependencies among statements (or instructions) i ...


References


Further reading

*Balmas, Francoise (2001)
Displaying dependence graphs: a hierarchical approach
{{Webarchive, url=https://web.archive.org/web/20120211074416/http://www.ai.univ-paris8.fr/~fb/version-ps/pdep.ps , date=2012-02-11 ,'

wcre, p. 261, Eighth Working Conference on Reverse Engineering (WCRE'01) Directed graphs Application-specific graphs