def apply_actions_to_stack(
      self, stack: Tuple[nltk.Nonterminal],
      actions: Sequence[int]) -> Tuple[nltk.Nonterminal, ...]:
    """Expand `stack` with the rules corresponding to `actions`.

    Args:
      stack:  A sequence of `nltk.Nonterminal`s representing the current stack.
      actions:  A sequence of actions.

    Returns:
      A _new_ stack representing the result of applying all the productions
      corresponding to `actions` to the top of `stack` in order.  If this is
      invalid (because the top of `stack` != the lhs of production) at any
      point, raises an error.
    """
    for action in actions:
      stack = self.apply_action_to_stack(stack, action)
      # Completed a tree.  Need to seed the stack with a start symbol.
      if not stack:
        stack = (self.grammar.start(),)
    return stack
Expand `stack` with the rules corresponding to `actions`.

    Args:
      stack:  A sequence of `nltk.Nonterminal`s representing the current stack.
      actions:  A sequence of actions.

    Returns:
      A _new_ stack representing the result of applying all the productions
      corresponding to `actions` to the top of `stack` in order.  If this is
      invalid (because the top of `stack` != the lhs of production) at any
      point, raises an error.
    
language/search_agents/muzero/state_tree.py