Given a set of objects S and a
transitive relation 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 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=\{A,B,C,D\} and R=\{(A,B),(A,C),(B,D),(A,D)\}. You can derive this relation directly:
A depends on
B and
C, because you can add two variables
if and only if 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 ==