public class Triangle
extends java.lang.Object
The circuit itself is described in Triangle.IsValidTriangle
.
It is interesting to examine the lineage graphs one can obtain, depending on
the input vector. This is done in the program by changing the contents of
variable vector
that is given to the function.
The first graph corresponds to the execution of the program on the vector [1, 2] (click on the graph to see it full size):
The function that is mentioned in the graph is GetSize
; the other
parts of the circuit are not present. Therefore, the graph correctly
"explains" that the issue with the input vector is related to its size.
The second graph corresponds to the execution of the program on the vector [1, 2, "foo"]:
This time, the function that appears in the lineage graph is
InstanceOf
. Moreover, one can observe that the only part of the
input vector that is mentioned is its third element ([2]). This correctly
reveals that this element, and only this one, is of an invalid type.
The third graph corresponds to the execution of the program on the vector [1, 2, -1]:
The function that appears in the explanation is ">0"; again this time, the only part of the input involved in the explanation is the third element of the vector ([2]). Therefore, this graph contains all the pieces to explain that the element is not positive.
The fourth graph corresponds to the execution of the program on the vector [1, 2, 1]:
Triangle.TriangleInequality
is the function that appears in the graph. Since
the inequality involves all three elements of the vector, it is normal to
see all three as leaves of the graph. However, the graph also reveals that,
among the three possible ways of grouping sides to form the inequality, only
one of them is invalid. The leaves corresponding to the first and third
element ([0] and [2]) are grouped under the addition, while the second [1]
is compared to them. Indeed, we see that 1+1 is not greater than 2. The
other two inequalities are satisfied, and therefore are not present in the
graph.
The last graph corresponds to the execution of the program on the vector [2, 3, 4], which corresponds to a valid triangle:
This time, one can see that all parts of the circuit are present. Indeed, all conditions must be true for the circuit to produce the value true.
This small example shows that a lineage graph can not only identify the parts of the inputs that explain a result, but also the parts of the circuit that are relevant for this result.
Modifier and Type | Class and Description |
---|---|
protected static class |
Triangle.AllNumbers
Determines if all three elements of of vector are positive numbers.
|
protected static class |
Triangle.AllPositive
Determines if the first three elements of a vector are positive.
|
protected static class |
Triangle.IsPositive
Function that determines if a number is positive.
|
static class |
Triangle.IsValidTriangle
Determines if a vector contains the lengths of sides of a valid triangle.
|
protected static class |
Triangle.TriangleInequality
Verifies the triangle inequality on a vector of three numbers.
|
Constructor and Description |
---|
Triangle() |
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args) |
Copyright © Sylvain Hallé. All Rights Reserved.