private static ISymbolicExpressionTreeNode LowestCommonAncestor(ISymbolicExpressionTreeNode root, List <ISymbolicExpressionTreeNode> nodes)
        {
            if (nodes.Count == 0)
            {
                throw new ArgumentException("The nodes list should contain at least one element.");
            }

            if (nodes.Count == 1)
            {
                return(nodes[0]);
            }

            int minLevel = nodes.Min(x => root.GetBranchLevel(x));

            // bring the nodes in the nodes to the same level (relative to the root)
            for (int i = 0; i < nodes.Count; ++i)
            {
                var node  = nodes[i];
                var level = root.GetBranchLevel(node);
                for (int j = minLevel; j < level; ++j)
                {
                    node = node.Parent;
                }
                nodes[i] = node;
            }

            // while not all the elements in the nodes are equal, go one level up
            while (nodes.Any(x => x != nodes[0]))
            {
                for (int i = 0; i < nodes.Count; ++i)
                {
                    nodes[i] = nodes[i].Parent;
                }
            }

            return(nodes[0]);
        }
    private static ISymbolicExpressionTreeNode LowestCommonAncestor(ISymbolicExpressionTreeNode root, List<ISymbolicExpressionTreeNode> nodes) {
      if (nodes.Count == 0)
        throw new ArgumentException("The nodes list should contain at least one element.");

      if (nodes.Count == 1)
        return nodes[0];

      int minLevel = nodes.Min(x => root.GetBranchLevel(x));

      // bring the nodes in the nodes to the same level (relative to the root)
      for (int i = 0; i < nodes.Count; ++i) {
        var node = nodes[i];
        var level = root.GetBranchLevel(node);
        for (int j = minLevel; j < level; ++j)
          node = node.Parent;
        nodes[i] = node;
      }

      // while not all the elements in the nodes are equal, go one level up
      while (nodes.Any(x => x != nodes[0])) {
        for (int i = 0; i < nodes.Count; ++i)
          nodes[i] = nodes[i].Parent;
      }

      return nodes[0];
    }