# Deduct by the rules for two schemes?

Posted 1 year ago
2532 Views
|
4 Replies
|
4 Total Likes
|
 Consider the following code: Input: rules = {a -> b, b -> c, c -> x, b -> d, d -> y};a//.rules; output:x In the above program, "b" respectively implies two variables "c" and "d", and the two branches respectively go to the two terminal results "x" and "y". But the program runs only one branch a->b->c->x,losing a->b->d->y. Is there any approach to run all elements of the set of rules, so that the output would be "x" and "y"? Answer
4 Replies
Sort By:
Posted 1 year ago
 Here is my not very elegant approach (I am curious to see other/better solutions): a //. Permutations[rules] // Union (* Out: {x,y} *) Answer
Posted 1 year ago
 So wonderful! Many thanks! Answer
Posted 1 year ago
 This solution is based on the contribution how to get all leaves from a graph : g = Graph[rules, VertexLabels -> Automatic]; vertices = VertexList[g]; leaves = Select[vertices, VertexOutDegree[g, #] === 0 &] Using Graph offers the possibility to display the result: HighlightGraph[g, Subgraph[g, leaves]] Answer
Posted 1 year ago
 Excellent! Many thanks! Answer