Skip to main content
added 30 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
termsgroupByVariables = ListKeySort @ GroupBy[List @@ myEq[x1#, x2Variables @ Level[#, x3{-1}] &, x4];Total] &;

groups = KeySortgroupByVariables @ GroupBy[termsmyEq[x1, Variables[Level[#x2, {-1}]] &x3, Total]x4]
<|{} -> 5,
 {x1} -> Cos[x1] + Sin[x1/2], 
 {x2} -> Tan[x2], 
 {x3} -> -Cos[x3], 
 {x1, x2} -> Cot[x1 x2], 
 {x1, x3} -> -Tan[x1/x3],
 {x2, x4} -> -Tan[x2 - x4], 
 {x1, x2, x3} -> Sin[x1 x2 x3], 
 {x2, x3, x4} -> Sin[x2 + x3/x4], 
 {x1, x2, x3, x4} -> Cot[x1 + x2 + x3 + x4] - Sin[x1 - x2 - x3/x4]|> 
Graph[Join[Keys @ groups, Values @ groups], 
 KeyValueMap[DirectedEdge] @ groups, 
 ImageSize -> Large, 
 VertexCoordinates ->  Join @@ 
    (Thread[{#, Rescale @ Range @ Length @ Keys @ groups}]& /@ {1, 2}), 
 VertexLabels -> {v_ :> Placed["Name", If[MemberQ[Keys @ groups, v], Before, After]]}] 

enter image description here

terms = List @@ myEq[x1, x2, x3, x4]; 

groups = KeySort @ GroupBy[terms, Variables[Level[#, {-1}]] &, Total]
<|{} -> 5,
 {x1} -> Cos[x1] + Sin[x1/2], 
 {x2} -> Tan[x2], 
 {x3} -> -Cos[x3], 
 {x1, x2} -> Cot[x1 x2], 
 {x1, x3} -> -Tan[x1/x3],
 {x2, x4} -> -Tan[x2 - x4], 
 {x1, x2, x3} -> Sin[x1 x2 x3], 
 {x2, x3, x4} -> Sin[x2 + x3/x4], 
 {x1, x2, x3, x4} -> Cot[x1 + x2 + x3 + x4] - Sin[x1 - x2 - x3/x4]|> 
Graph[Join[Keys @ groups, Values @ groups], 
 KeyValueMap[DirectedEdge] @ groups, 
 ImageSize -> Large, 
 VertexCoordinates ->  Join @@ 
    (Thread[{#, Rescale @ Range @ Length @ Keys @ groups}]& /@ {1, 2}), 
 VertexLabels -> {v_ :> Placed["Name", If[MemberQ[Keys @ groups, v], Before, After]]}] 

enter image description here

groupByVariables = KeySort @ GroupBy[List @@ #, Variables @ Level[#, {-1}] &, Total] &;

groups = groupByVariables @ myEq[x1, x2, x3, x4]
<|{} -> 5,
 {x1} -> Cos[x1] + Sin[x1/2], 
 {x2} -> Tan[x2], 
 {x3} -> -Cos[x3], 
 {x1, x2} -> Cot[x1 x2], 
 {x1, x3} -> -Tan[x1/x3],
 {x2, x4} -> -Tan[x2 - x4], 
 {x1, x2, x3} -> Sin[x1 x2 x3], 
 {x2, x3, x4} -> Sin[x2 + x3/x4], 
 {x1, x2, x3, x4} -> Cot[x1 + x2 + x3 + x4] - Sin[x1 - x2 - x3/x4]|> 
Graph[Join[Keys @ groups, Values @ groups], 
 KeyValueMap[DirectedEdge] @ groups, 
 ImageSize -> Large, 
 VertexCoordinates ->  Join @@ 
    (Thread[{#, Rescale @ Range @ Length @ Keys @ groups}]& /@ {1, 2}), 
 VertexLabels -> {v_ :> Placed["Name", If[MemberQ[Keys @ groups, v], Before, After]]}] 

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

terms = List @@ myEq[x1, x2, x3, x4]; 

groups = KeySort @ GroupBy[terms, Variables[Level[#, {-1}]] &, Total]
<|{} -> 5,
 {x1} -> Cos[x1] + Sin[x1/2], 
 {x2} -> Tan[x2], 
 {x3} -> -Cos[x3], 
 {x1, x2} -> Cot[x1 x2], 
 {x1, x3} -> -Tan[x1/x3],
 {x2, x4} -> -Tan[x2 - x4], 
 {x1, x2, x3} -> Sin[x1 x2 x3], 
 {x2, x3, x4} -> Sin[x2 + x3/x4], 
 {x1, x2, x3, x4} -> Cot[x1 + x2 + x3 + x4] - Sin[x1 - x2 - x3/x4]|> 
Graph[Join[Keys @ groups, Values @ groups], 
 KeyValueMap[DirectedEdge] @ groups, 
 ImageSize -> Large, 
 VertexCoordinates ->  Join @@ 
    (Thread[{#, Rescale @ Range @ Length @ Keys @ groups}]& /@ {1, 2}), 
 VertexLabels -> {v_ :> Placed["Name", If[MemberQ[Keys @ groups, v], Before, After]]}] 

enter image description here